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.

252123 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 int unboundedMouseOffsetX = 0;
  31078. static int unboundedMouseOffsetY = 0;
  31079. static bool isUnboundedMouseModeOn = false;
  31080. static bool isCursorVisibleUntilOffscreen;
  31081. #define checkMessageManagerIsLocked jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  31082. static uint32 nextComponentUID = 0;
  31083. Component::Component() throw()
  31084. : parentComponent_ (0),
  31085. componentUID (++nextComponentUID),
  31086. numDeepMouseListeners (0),
  31087. lookAndFeel_ (0),
  31088. effect_ (0),
  31089. bufferedImage_ (0),
  31090. mouseListeners_ (0),
  31091. keyListeners_ (0),
  31092. componentListeners_ (0),
  31093. componentFlags_ (0)
  31094. {
  31095. }
  31096. Component::Component (const String& name) throw()
  31097. : componentName_ (name),
  31098. parentComponent_ (0),
  31099. componentUID (++nextComponentUID),
  31100. numDeepMouseListeners (0),
  31101. lookAndFeel_ (0),
  31102. effect_ (0),
  31103. bufferedImage_ (0),
  31104. mouseListeners_ (0),
  31105. keyListeners_ (0),
  31106. componentListeners_ (0),
  31107. componentFlags_ (0)
  31108. {
  31109. }
  31110. Component::~Component()
  31111. {
  31112. if (parentComponent_ != 0)
  31113. {
  31114. parentComponent_->removeChildComponent (this);
  31115. }
  31116. else if ((currentlyFocusedComponent == this)
  31117. || isParentOf (currentlyFocusedComponent))
  31118. {
  31119. giveAwayFocus();
  31120. }
  31121. if (componentUnderMouse == this)
  31122. componentUnderMouse = 0;
  31123. if (flags.hasHeavyweightPeerFlag)
  31124. removeFromDesktop();
  31125. modalComponentStack.removeValue (this);
  31126. for (int i = childComponentList_.size(); --i >= 0;)
  31127. childComponentList_.getUnchecked(i)->parentComponent_ = 0;
  31128. delete bufferedImage_;
  31129. delete mouseListeners_;
  31130. delete keyListeners_;
  31131. delete componentListeners_;
  31132. }
  31133. void Component::setName (const String& name)
  31134. {
  31135. // if component methods are being called from threads other than the message
  31136. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31137. checkMessageManagerIsLocked
  31138. if (componentName_ != name)
  31139. {
  31140. componentName_ = name;
  31141. if (flags.hasHeavyweightPeerFlag)
  31142. {
  31143. ComponentPeer* const peer = getPeer();
  31144. jassert (peer != 0);
  31145. if (peer != 0)
  31146. peer->setTitle (name);
  31147. }
  31148. if (componentListeners_ != 0)
  31149. {
  31150. const ComponentDeletionWatcher deletionChecker (this);
  31151. for (int i = componentListeners_->size(); --i >= 0;)
  31152. {
  31153. ((ComponentListener*) componentListeners_->getUnchecked (i))
  31154. ->componentNameChanged (*this);
  31155. if (deletionChecker.hasBeenDeleted())
  31156. return;
  31157. i = jmin (i, componentListeners_->size());
  31158. }
  31159. }
  31160. }
  31161. }
  31162. void Component::setVisible (bool shouldBeVisible)
  31163. {
  31164. if (flags.visibleFlag != shouldBeVisible)
  31165. {
  31166. // if component methods are being called from threads other than the message
  31167. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31168. checkMessageManagerIsLocked
  31169. const ComponentDeletionWatcher deletionChecker (this);
  31170. flags.visibleFlag = shouldBeVisible;
  31171. internalRepaint (0, 0, getWidth(), getHeight());
  31172. sendFakeMouseMove();
  31173. if (! shouldBeVisible)
  31174. {
  31175. if (currentlyFocusedComponent == this
  31176. || isParentOf (currentlyFocusedComponent))
  31177. {
  31178. if (parentComponent_ != 0)
  31179. parentComponent_->grabKeyboardFocus();
  31180. else
  31181. giveAwayFocus();
  31182. }
  31183. }
  31184. sendVisibilityChangeMessage();
  31185. if ((! deletionChecker.hasBeenDeleted()) && flags.hasHeavyweightPeerFlag)
  31186. {
  31187. ComponentPeer* const peer = getPeer();
  31188. jassert (peer != 0);
  31189. if (peer != 0)
  31190. {
  31191. peer->setVisible (shouldBeVisible);
  31192. internalHierarchyChanged();
  31193. }
  31194. }
  31195. }
  31196. }
  31197. void Component::visibilityChanged()
  31198. {
  31199. }
  31200. void Component::sendVisibilityChangeMessage()
  31201. {
  31202. const ComponentDeletionWatcher deletionChecker (this);
  31203. visibilityChanged();
  31204. if ((! deletionChecker.hasBeenDeleted()) && componentListeners_ != 0)
  31205. {
  31206. for (int i = componentListeners_->size(); --i >= 0;)
  31207. {
  31208. ((ComponentListener*) componentListeners_->getUnchecked (i))
  31209. ->componentVisibilityChanged (*this);
  31210. if (deletionChecker.hasBeenDeleted())
  31211. return;
  31212. i = jmin (i, componentListeners_->size());
  31213. }
  31214. }
  31215. }
  31216. bool Component::isShowing() const throw()
  31217. {
  31218. if (flags.visibleFlag)
  31219. {
  31220. if (parentComponent_ != 0)
  31221. {
  31222. return parentComponent_->isShowing();
  31223. }
  31224. else
  31225. {
  31226. const ComponentPeer* const peer = getPeer();
  31227. return peer != 0 && ! peer->isMinimised();
  31228. }
  31229. }
  31230. return false;
  31231. }
  31232. class FadeOutProxyComponent : public Component,
  31233. public Timer
  31234. {
  31235. public:
  31236. FadeOutProxyComponent (Component* comp,
  31237. const int fadeLengthMs,
  31238. const int deltaXToMove,
  31239. const int deltaYToMove,
  31240. const float scaleFactorAtEnd)
  31241. : lastTime (0),
  31242. alpha (1.0f),
  31243. scale (1.0f)
  31244. {
  31245. image = comp->createComponentSnapshot (Rectangle<int> (0, 0, comp->getWidth(), comp->getHeight()));
  31246. setBounds (comp->getBounds());
  31247. comp->getParentComponent()->addAndMakeVisible (this);
  31248. toBehind (comp);
  31249. alphaChangePerMs = -1.0f / (float)fadeLengthMs;
  31250. centreX = comp->getX() + comp->getWidth() * 0.5f;
  31251. xChangePerMs = deltaXToMove / (float)fadeLengthMs;
  31252. centreY = comp->getY() + comp->getHeight() * 0.5f;
  31253. yChangePerMs = deltaYToMove / (float)fadeLengthMs;
  31254. scaleChangePerMs = (scaleFactorAtEnd - 1.0f) / (float)fadeLengthMs;
  31255. setInterceptsMouseClicks (false, false);
  31256. // 30 fps is enough for a fade, but we need a higher rate if it's moving as well..
  31257. startTimer (1000 / ((deltaXToMove == 0 && deltaYToMove == 0) ? 30 : 50));
  31258. }
  31259. ~FadeOutProxyComponent()
  31260. {
  31261. delete image;
  31262. }
  31263. void paint (Graphics& g)
  31264. {
  31265. g.setOpacity (alpha);
  31266. g.drawImage (image,
  31267. 0, 0, getWidth(), getHeight(),
  31268. 0, 0, image->getWidth(), image->getHeight());
  31269. }
  31270. void timerCallback()
  31271. {
  31272. const uint32 now = Time::getMillisecondCounter();
  31273. if (lastTime == 0)
  31274. lastTime = now;
  31275. const int msPassed = (now > lastTime) ? now - lastTime : 0;
  31276. lastTime = now;
  31277. alpha += alphaChangePerMs * msPassed;
  31278. if (alpha > 0)
  31279. {
  31280. if (xChangePerMs != 0.0f || yChangePerMs != 0.0f || scaleChangePerMs != 0.0f)
  31281. {
  31282. centreX += xChangePerMs * msPassed;
  31283. centreY += yChangePerMs * msPassed;
  31284. scale += scaleChangePerMs * msPassed;
  31285. const int w = roundToInt (image->getWidth() * scale);
  31286. const int h = roundToInt (image->getHeight() * scale);
  31287. setBounds (roundToInt (centreX) - w / 2,
  31288. roundToInt (centreY) - h / 2,
  31289. w, h);
  31290. }
  31291. repaint();
  31292. }
  31293. else
  31294. {
  31295. delete this;
  31296. }
  31297. }
  31298. juce_UseDebuggingNewOperator
  31299. private:
  31300. Image* image;
  31301. uint32 lastTime;
  31302. float alpha, alphaChangePerMs;
  31303. float centreX, xChangePerMs;
  31304. float centreY, yChangePerMs;
  31305. float scale, scaleChangePerMs;
  31306. FadeOutProxyComponent (const FadeOutProxyComponent&);
  31307. const FadeOutProxyComponent& operator= (const FadeOutProxyComponent&);
  31308. };
  31309. void Component::fadeOutComponent (const int millisecondsToFade,
  31310. const int deltaXToMove,
  31311. const int deltaYToMove,
  31312. const float scaleFactorAtEnd)
  31313. {
  31314. //xxx won't work for comps without parents
  31315. if (isShowing() && millisecondsToFade > 0)
  31316. new FadeOutProxyComponent (this, millisecondsToFade,
  31317. deltaXToMove, deltaYToMove, scaleFactorAtEnd);
  31318. setVisible (false);
  31319. }
  31320. bool Component::isValidComponent() const throw()
  31321. {
  31322. return (this != 0) && isValidMessageListener();
  31323. }
  31324. void* Component::getWindowHandle() const throw()
  31325. {
  31326. const ComponentPeer* const peer = getPeer();
  31327. if (peer != 0)
  31328. return peer->getNativeHandle();
  31329. return 0;
  31330. }
  31331. void Component::addToDesktop (int styleWanted, void* nativeWindowToAttachTo)
  31332. {
  31333. // if component methods are being called from threads other than the message
  31334. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31335. checkMessageManagerIsLocked
  31336. if (isOpaque())
  31337. styleWanted &= ~ComponentPeer::windowIsSemiTransparent;
  31338. else
  31339. styleWanted |= ComponentPeer::windowIsSemiTransparent;
  31340. int currentStyleFlags = 0;
  31341. // don't use getPeer(), so that we only get the peer that's specifically
  31342. // for this comp, and not for one of its parents.
  31343. ComponentPeer* peer = ComponentPeer::getPeerFor (this);
  31344. if (peer != 0)
  31345. currentStyleFlags = peer->getStyleFlags();
  31346. if (styleWanted != currentStyleFlags || ! flags.hasHeavyweightPeerFlag)
  31347. {
  31348. const ComponentDeletionWatcher deletionChecker (this);
  31349. #if JUCE_LINUX
  31350. // it's wise to give the component a non-zero size before
  31351. // putting it on the desktop, as X windows get confused by this, and
  31352. // a (1, 1) minimum size is enforced here.
  31353. setSize (jmax (1, getWidth()),
  31354. jmax (1, getHeight()));
  31355. #endif
  31356. int x = 0, y = 0;
  31357. relativePositionToGlobal (x, y);
  31358. bool wasFullscreen = false;
  31359. bool wasMinimised = false;
  31360. ComponentBoundsConstrainer* currentConstainer = 0;
  31361. Rectangle<int> oldNonFullScreenBounds;
  31362. if (peer != 0)
  31363. {
  31364. wasFullscreen = peer->isFullScreen();
  31365. wasMinimised = peer->isMinimised();
  31366. currentConstainer = peer->getConstrainer();
  31367. oldNonFullScreenBounds = peer->getNonFullScreenBounds();
  31368. removeFromDesktop();
  31369. setTopLeftPosition (x, y);
  31370. }
  31371. if (parentComponent_ != 0)
  31372. parentComponent_->removeChildComponent (this);
  31373. if (! deletionChecker.hasBeenDeleted())
  31374. {
  31375. flags.hasHeavyweightPeerFlag = true;
  31376. peer = createNewPeer (styleWanted, nativeWindowToAttachTo);
  31377. Desktop::getInstance().addDesktopComponent (this);
  31378. bounds_.setPosition (x, y);
  31379. peer->setBounds (x, y, getWidth(), getHeight(), false);
  31380. peer->setVisible (isVisible());
  31381. if (wasFullscreen)
  31382. {
  31383. peer->setFullScreen (true);
  31384. peer->setNonFullScreenBounds (oldNonFullScreenBounds);
  31385. }
  31386. if (wasMinimised)
  31387. peer->setMinimised (true);
  31388. if (isAlwaysOnTop())
  31389. peer->setAlwaysOnTop (true);
  31390. peer->setConstrainer (currentConstainer);
  31391. repaint();
  31392. }
  31393. internalHierarchyChanged();
  31394. }
  31395. }
  31396. void Component::removeFromDesktop()
  31397. {
  31398. // if component methods are being called from threads other than the message
  31399. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31400. checkMessageManagerIsLocked
  31401. if (flags.hasHeavyweightPeerFlag)
  31402. {
  31403. ComponentPeer* const peer = ComponentPeer::getPeerFor (this);
  31404. flags.hasHeavyweightPeerFlag = false;
  31405. jassert (peer != 0);
  31406. delete peer;
  31407. Desktop::getInstance().removeDesktopComponent (this);
  31408. }
  31409. }
  31410. bool Component::isOnDesktop() const throw()
  31411. {
  31412. return flags.hasHeavyweightPeerFlag;
  31413. }
  31414. void Component::userTriedToCloseWindow()
  31415. {
  31416. /* This means that the user's trying to get rid of your window with the 'close window' system
  31417. menu option (on windows) or possibly the task manager - you should really handle this
  31418. and delete or hide your component in an appropriate way.
  31419. If you want to ignore the event and don't want to trigger this assertion, just override
  31420. this method and do nothing.
  31421. */
  31422. jassertfalse
  31423. }
  31424. void Component::minimisationStateChanged (bool)
  31425. {
  31426. }
  31427. void Component::setOpaque (const bool shouldBeOpaque) throw()
  31428. {
  31429. if (shouldBeOpaque != flags.opaqueFlag)
  31430. {
  31431. flags.opaqueFlag = shouldBeOpaque;
  31432. if (flags.hasHeavyweightPeerFlag)
  31433. {
  31434. const ComponentPeer* const peer = ComponentPeer::getPeerFor (this);
  31435. if (peer != 0)
  31436. {
  31437. // to make it recreate the heavyweight window
  31438. addToDesktop (peer->getStyleFlags());
  31439. }
  31440. }
  31441. repaint();
  31442. }
  31443. }
  31444. bool Component::isOpaque() const throw()
  31445. {
  31446. return flags.opaqueFlag;
  31447. }
  31448. void Component::setBufferedToImage (const bool shouldBeBuffered) throw()
  31449. {
  31450. if (shouldBeBuffered != flags.bufferToImageFlag)
  31451. {
  31452. deleteAndZero (bufferedImage_);
  31453. flags.bufferToImageFlag = shouldBeBuffered;
  31454. }
  31455. }
  31456. void Component::toFront (const bool setAsForeground)
  31457. {
  31458. // if component methods are being called from threads other than the message
  31459. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31460. checkMessageManagerIsLocked
  31461. if (flags.hasHeavyweightPeerFlag)
  31462. {
  31463. ComponentPeer* const peer = getPeer();
  31464. if (peer != 0)
  31465. {
  31466. peer->toFront (setAsForeground);
  31467. if (setAsForeground && ! hasKeyboardFocus (true))
  31468. grabKeyboardFocus();
  31469. }
  31470. }
  31471. else if (parentComponent_ != 0)
  31472. {
  31473. if (parentComponent_->childComponentList_.getLast() != this)
  31474. {
  31475. const int index = parentComponent_->childComponentList_.indexOf (this);
  31476. if (index >= 0)
  31477. {
  31478. int insertIndex = -1;
  31479. if (! flags.alwaysOnTopFlag)
  31480. {
  31481. insertIndex = parentComponent_->childComponentList_.size() - 1;
  31482. while (insertIndex > 0
  31483. && parentComponent_->childComponentList_.getUnchecked (insertIndex)->isAlwaysOnTop())
  31484. {
  31485. --insertIndex;
  31486. }
  31487. }
  31488. if (index != insertIndex)
  31489. {
  31490. parentComponent_->childComponentList_.move (index, insertIndex);
  31491. sendFakeMouseMove();
  31492. repaintParent();
  31493. }
  31494. }
  31495. }
  31496. if (setAsForeground)
  31497. {
  31498. internalBroughtToFront();
  31499. grabKeyboardFocus();
  31500. }
  31501. }
  31502. }
  31503. void Component::toBehind (Component* const other)
  31504. {
  31505. if (other != 0)
  31506. {
  31507. // the two components must belong to the same parent..
  31508. jassert (parentComponent_ == other->parentComponent_);
  31509. if (parentComponent_ != 0)
  31510. {
  31511. const int index = parentComponent_->childComponentList_.indexOf (this);
  31512. int otherIndex = parentComponent_->childComponentList_.indexOf (other);
  31513. if (index >= 0
  31514. && otherIndex >= 0
  31515. && index != otherIndex - 1
  31516. && other != this)
  31517. {
  31518. if (index < otherIndex)
  31519. --otherIndex;
  31520. parentComponent_->childComponentList_.move (index, otherIndex);
  31521. sendFakeMouseMove();
  31522. repaintParent();
  31523. }
  31524. }
  31525. else if (isOnDesktop())
  31526. {
  31527. jassert (other->isOnDesktop());
  31528. if (other->isOnDesktop())
  31529. {
  31530. ComponentPeer* const us = getPeer();
  31531. ComponentPeer* const them = other->getPeer();
  31532. jassert (us != 0 && them != 0);
  31533. if (us != 0 && them != 0)
  31534. us->toBehind (them);
  31535. }
  31536. }
  31537. }
  31538. }
  31539. void Component::toBack()
  31540. {
  31541. if (isOnDesktop())
  31542. {
  31543. jassertfalse //xxx need to add this to native window
  31544. }
  31545. else if (parentComponent_ != 0
  31546. && parentComponent_->childComponentList_.getFirst() != this)
  31547. {
  31548. const int index = parentComponent_->childComponentList_.indexOf (this);
  31549. if (index > 0)
  31550. {
  31551. int insertIndex = 0;
  31552. if (flags.alwaysOnTopFlag)
  31553. {
  31554. while (insertIndex < parentComponent_->childComponentList_.size()
  31555. && ! parentComponent_->childComponentList_.getUnchecked (insertIndex)->isAlwaysOnTop())
  31556. {
  31557. ++insertIndex;
  31558. }
  31559. }
  31560. if (index != insertIndex)
  31561. {
  31562. parentComponent_->childComponentList_.move (index, insertIndex);
  31563. sendFakeMouseMove();
  31564. repaintParent();
  31565. }
  31566. }
  31567. }
  31568. }
  31569. void Component::setAlwaysOnTop (const bool shouldStayOnTop)
  31570. {
  31571. if (shouldStayOnTop != flags.alwaysOnTopFlag)
  31572. {
  31573. flags.alwaysOnTopFlag = shouldStayOnTop;
  31574. if (isOnDesktop())
  31575. {
  31576. ComponentPeer* const peer = getPeer();
  31577. jassert (peer != 0);
  31578. if (peer != 0)
  31579. {
  31580. if (! peer->setAlwaysOnTop (shouldStayOnTop))
  31581. {
  31582. // some kinds of peer can't change their always-on-top status, so
  31583. // for these, we'll need to create a new window
  31584. const int oldFlags = peer->getStyleFlags();
  31585. removeFromDesktop();
  31586. addToDesktop (oldFlags);
  31587. }
  31588. }
  31589. }
  31590. if (shouldStayOnTop)
  31591. toFront (false);
  31592. internalHierarchyChanged();
  31593. }
  31594. }
  31595. bool Component::isAlwaysOnTop() const throw()
  31596. {
  31597. return flags.alwaysOnTopFlag;
  31598. }
  31599. int Component::proportionOfWidth (const float proportion) const throw()
  31600. {
  31601. return roundToInt (proportion * bounds_.getWidth());
  31602. }
  31603. int Component::proportionOfHeight (const float proportion) const throw()
  31604. {
  31605. return roundToInt (proportion * bounds_.getHeight());
  31606. }
  31607. int Component::getParentWidth() const throw()
  31608. {
  31609. return (parentComponent_ != 0) ? parentComponent_->getWidth()
  31610. : getParentMonitorArea().getWidth();
  31611. }
  31612. int Component::getParentHeight() const throw()
  31613. {
  31614. return (parentComponent_ != 0) ? parentComponent_->getHeight()
  31615. : getParentMonitorArea().getHeight();
  31616. }
  31617. int Component::getScreenX() const throw()
  31618. {
  31619. return (parentComponent_ != 0) ? parentComponent_->getScreenX() + getX()
  31620. : (flags.hasHeavyweightPeerFlag ? getPeer()->getScreenX()
  31621. : getX());
  31622. }
  31623. int Component::getScreenY() const throw()
  31624. {
  31625. return (parentComponent_ != 0) ? parentComponent_->getScreenY() + getY()
  31626. : (flags.hasHeavyweightPeerFlag ? getPeer()->getScreenY()
  31627. : getY());
  31628. }
  31629. void Component::relativePositionToGlobal (int& x, int& y) const throw()
  31630. {
  31631. const Component* c = this;
  31632. do
  31633. {
  31634. if (c->flags.hasHeavyweightPeerFlag)
  31635. {
  31636. c->getPeer()->relativePositionToGlobal (x, y);
  31637. break;
  31638. }
  31639. x += c->getX();
  31640. y += c->getY();
  31641. c = c->parentComponent_;
  31642. }
  31643. while (c != 0);
  31644. }
  31645. void Component::globalPositionToRelative (int& x, int& y) const throw()
  31646. {
  31647. if (flags.hasHeavyweightPeerFlag)
  31648. {
  31649. getPeer()->globalPositionToRelative (x, y);
  31650. }
  31651. else
  31652. {
  31653. if (parentComponent_ != 0)
  31654. parentComponent_->globalPositionToRelative (x, y);
  31655. x -= getX();
  31656. y -= getY();
  31657. }
  31658. }
  31659. void Component::relativePositionToOtherComponent (const Component* const targetComponent, int& x, int& y) const throw()
  31660. {
  31661. if (targetComponent != 0)
  31662. {
  31663. const Component* c = this;
  31664. do
  31665. {
  31666. if (c == targetComponent)
  31667. return;
  31668. if (c->flags.hasHeavyweightPeerFlag)
  31669. {
  31670. c->getPeer()->relativePositionToGlobal (x, y);
  31671. break;
  31672. }
  31673. x += c->getX();
  31674. y += c->getY();
  31675. c = c->parentComponent_;
  31676. }
  31677. while (c != 0);
  31678. targetComponent->globalPositionToRelative (x, y);
  31679. }
  31680. }
  31681. void Component::setBounds (int x, int y, int w, int h)
  31682. {
  31683. // if component methods are being called from threads other than the message
  31684. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31685. checkMessageManagerIsLocked
  31686. if (w < 0) w = 0;
  31687. if (h < 0) h = 0;
  31688. const bool wasResized = (getWidth() != w || getHeight() != h);
  31689. const bool wasMoved = (getX() != x || getY() != y);
  31690. #ifdef JUCE_DEBUG
  31691. // It's a very bad idea to try to resize a window during its paint() method!
  31692. jassert (! (flags.isInsidePaintCall && wasResized && isOnDesktop()));
  31693. #endif
  31694. if (wasMoved || wasResized)
  31695. {
  31696. if (flags.visibleFlag)
  31697. {
  31698. // send a fake mouse move to trigger enter/exit messages if needed..
  31699. sendFakeMouseMove();
  31700. if (! flags.hasHeavyweightPeerFlag)
  31701. repaintParent();
  31702. }
  31703. bounds_.setBounds (x, y, w, h);
  31704. if (wasResized)
  31705. repaint();
  31706. else if (! flags.hasHeavyweightPeerFlag)
  31707. repaintParent();
  31708. if (flags.hasHeavyweightPeerFlag)
  31709. {
  31710. ComponentPeer* const peer = getPeer();
  31711. if (peer != 0)
  31712. {
  31713. if (wasMoved && wasResized)
  31714. peer->setBounds (getX(), getY(), getWidth(), getHeight(), false);
  31715. else if (wasMoved)
  31716. peer->setPosition (getX(), getY());
  31717. else if (wasResized)
  31718. peer->setSize (getWidth(), getHeight());
  31719. }
  31720. }
  31721. sendMovedResizedMessages (wasMoved, wasResized);
  31722. }
  31723. }
  31724. void Component::sendMovedResizedMessages (const bool wasMoved, const bool wasResized)
  31725. {
  31726. JUCE_TRY
  31727. {
  31728. if (wasMoved)
  31729. moved();
  31730. if (wasResized)
  31731. {
  31732. resized();
  31733. for (int i = childComponentList_.size(); --i >= 0;)
  31734. {
  31735. childComponentList_.getUnchecked(i)->parentSizeChanged();
  31736. i = jmin (i, childComponentList_.size());
  31737. }
  31738. }
  31739. if (parentComponent_ != 0)
  31740. parentComponent_->childBoundsChanged (this);
  31741. if (componentListeners_ != 0)
  31742. {
  31743. const ComponentDeletionWatcher deletionChecker (this);
  31744. for (int i = componentListeners_->size(); --i >= 0;)
  31745. {
  31746. ((ComponentListener*) componentListeners_->getUnchecked (i))
  31747. ->componentMovedOrResized (*this, wasMoved, wasResized);
  31748. if (deletionChecker.hasBeenDeleted())
  31749. return;
  31750. i = jmin (i, componentListeners_->size());
  31751. }
  31752. }
  31753. }
  31754. JUCE_CATCH_EXCEPTION
  31755. }
  31756. void Component::setSize (const int w, const int h)
  31757. {
  31758. setBounds (getX(), getY(), w, h);
  31759. }
  31760. void Component::setTopLeftPosition (const int x, const int y)
  31761. {
  31762. setBounds (x, y, getWidth(), getHeight());
  31763. }
  31764. void Component::setTopRightPosition (const int x, const int y)
  31765. {
  31766. setTopLeftPosition (x - getWidth(), y);
  31767. }
  31768. void Component::setBounds (const Rectangle<int>& r)
  31769. {
  31770. setBounds (r.getX(),
  31771. r.getY(),
  31772. r.getWidth(),
  31773. r.getHeight());
  31774. }
  31775. void Component::setBoundsRelative (const float x, const float y,
  31776. const float w, const float h)
  31777. {
  31778. const int pw = getParentWidth();
  31779. const int ph = getParentHeight();
  31780. setBounds (roundToInt (x * pw),
  31781. roundToInt (y * ph),
  31782. roundToInt (w * pw),
  31783. roundToInt (h * ph));
  31784. }
  31785. void Component::setCentrePosition (const int x, const int y)
  31786. {
  31787. setTopLeftPosition (x - getWidth() / 2,
  31788. y - getHeight() / 2);
  31789. }
  31790. void Component::setCentreRelative (const float x, const float y)
  31791. {
  31792. setCentrePosition (roundToInt (getParentWidth() * x),
  31793. roundToInt (getParentHeight() * y));
  31794. }
  31795. void Component::centreWithSize (const int width, const int height)
  31796. {
  31797. setBounds ((getParentWidth() - width) / 2,
  31798. (getParentHeight() - height) / 2,
  31799. width,
  31800. height);
  31801. }
  31802. void Component::setBoundsInset (const BorderSize& borders)
  31803. {
  31804. setBounds (borders.getLeft(),
  31805. borders.getTop(),
  31806. getParentWidth() - (borders.getLeftAndRight()),
  31807. getParentHeight() - (borders.getTopAndBottom()));
  31808. }
  31809. void Component::setBoundsToFit (int x, int y, int width, int height,
  31810. const Justification& justification,
  31811. const bool onlyReduceInSize)
  31812. {
  31813. // it's no good calling this method unless both the component and
  31814. // target rectangle have a finite size.
  31815. jassert (getWidth() > 0 && getHeight() > 0 && width > 0 && height > 0);
  31816. if (getWidth() > 0 && getHeight() > 0
  31817. && width > 0 && height > 0)
  31818. {
  31819. int newW, newH;
  31820. if (onlyReduceInSize && getWidth() <= width && getHeight() <= height)
  31821. {
  31822. newW = getWidth();
  31823. newH = getHeight();
  31824. }
  31825. else
  31826. {
  31827. const double imageRatio = getHeight() / (double) getWidth();
  31828. const double targetRatio = height / (double) width;
  31829. if (imageRatio <= targetRatio)
  31830. {
  31831. newW = width;
  31832. newH = jmin (height, roundToInt (newW * imageRatio));
  31833. }
  31834. else
  31835. {
  31836. newH = height;
  31837. newW = jmin (width, roundToInt (newH / imageRatio));
  31838. }
  31839. }
  31840. if (newW > 0 && newH > 0)
  31841. {
  31842. int newX, newY;
  31843. justification.applyToRectangle (newX, newY, newW, newH,
  31844. x, y, width, height);
  31845. setBounds (newX, newY, newW, newH);
  31846. }
  31847. }
  31848. }
  31849. bool Component::hitTest (int x, int y)
  31850. {
  31851. if (! flags.ignoresMouseClicksFlag)
  31852. return true;
  31853. if (flags.allowChildMouseClicksFlag)
  31854. {
  31855. for (int i = getNumChildComponents(); --i >= 0;)
  31856. {
  31857. Component* const c = getChildComponent (i);
  31858. if (c->isVisible()
  31859. && c->bounds_.contains (x, y)
  31860. && c->hitTest (x - c->getX(),
  31861. y - c->getY()))
  31862. {
  31863. return true;
  31864. }
  31865. }
  31866. }
  31867. return false;
  31868. }
  31869. void Component::setInterceptsMouseClicks (const bool allowClicks,
  31870. const bool allowClicksOnChildComponents) throw()
  31871. {
  31872. flags.ignoresMouseClicksFlag = ! allowClicks;
  31873. flags.allowChildMouseClicksFlag = allowClicksOnChildComponents;
  31874. }
  31875. void Component::getInterceptsMouseClicks (bool& allowsClicksOnThisComponent,
  31876. bool& allowsClicksOnChildComponents) const throw()
  31877. {
  31878. allowsClicksOnThisComponent = ! flags.ignoresMouseClicksFlag;
  31879. allowsClicksOnChildComponents = flags.allowChildMouseClicksFlag;
  31880. }
  31881. bool Component::contains (const int x, const int y)
  31882. {
  31883. if (((unsigned int) x) < (unsigned int) getWidth()
  31884. && ((unsigned int) y) < (unsigned int) getHeight()
  31885. && hitTest (x, y))
  31886. {
  31887. if (parentComponent_ != 0)
  31888. {
  31889. return parentComponent_->contains (x + getX(),
  31890. y + getY());
  31891. }
  31892. else if (flags.hasHeavyweightPeerFlag)
  31893. {
  31894. const ComponentPeer* const peer = getPeer();
  31895. if (peer != 0)
  31896. return peer->contains (x, y, true);
  31897. }
  31898. }
  31899. return false;
  31900. }
  31901. bool Component::reallyContains (int x, int y, const bool returnTrueIfWithinAChild)
  31902. {
  31903. if (! contains (x, y))
  31904. return false;
  31905. Component* p = this;
  31906. while (p->parentComponent_ != 0)
  31907. {
  31908. x += p->getX();
  31909. y += p->getY();
  31910. p = p->parentComponent_;
  31911. }
  31912. const Component* const c = p->getComponentAt (x, y);
  31913. return (c == this) || (returnTrueIfWithinAChild && isParentOf (c));
  31914. }
  31915. Component* Component::getComponentAt (const int x, const int y)
  31916. {
  31917. if (flags.visibleFlag
  31918. && ((unsigned int) x) < (unsigned int) getWidth()
  31919. && ((unsigned int) y) < (unsigned int) getHeight()
  31920. && hitTest (x, y))
  31921. {
  31922. for (int i = childComponentList_.size(); --i >= 0;)
  31923. {
  31924. Component* const child = childComponentList_.getUnchecked(i);
  31925. Component* const c = child->getComponentAt (x - child->getX(),
  31926. y - child->getY());
  31927. if (c != 0)
  31928. return c;
  31929. }
  31930. return this;
  31931. }
  31932. return 0;
  31933. }
  31934. void Component::addChildComponent (Component* const child, int zOrder)
  31935. {
  31936. // if component methods are being called from threads other than the message
  31937. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31938. checkMessageManagerIsLocked
  31939. if (child != 0 && child->parentComponent_ != this)
  31940. {
  31941. if (child->parentComponent_ != 0)
  31942. child->parentComponent_->removeChildComponent (child);
  31943. else
  31944. child->removeFromDesktop();
  31945. child->parentComponent_ = this;
  31946. if (child->isVisible())
  31947. child->repaintParent();
  31948. if (! child->isAlwaysOnTop())
  31949. {
  31950. if (zOrder < 0 || zOrder > childComponentList_.size())
  31951. zOrder = childComponentList_.size();
  31952. while (zOrder > 0)
  31953. {
  31954. if (! childComponentList_.getUnchecked (zOrder - 1)->isAlwaysOnTop())
  31955. break;
  31956. --zOrder;
  31957. }
  31958. }
  31959. childComponentList_.insert (zOrder, child);
  31960. child->internalHierarchyChanged();
  31961. internalChildrenChanged();
  31962. }
  31963. }
  31964. void Component::addAndMakeVisible (Component* const child, int zOrder)
  31965. {
  31966. if (child != 0)
  31967. {
  31968. child->setVisible (true);
  31969. addChildComponent (child, zOrder);
  31970. }
  31971. }
  31972. void Component::removeChildComponent (Component* const child)
  31973. {
  31974. removeChildComponent (childComponentList_.indexOf (child));
  31975. }
  31976. Component* Component::removeChildComponent (const int index)
  31977. {
  31978. // if component methods are being called from threads other than the message
  31979. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31980. checkMessageManagerIsLocked
  31981. Component* const child = childComponentList_ [index];
  31982. if (child != 0)
  31983. {
  31984. sendFakeMouseMove();
  31985. child->repaintParent();
  31986. childComponentList_.remove (index);
  31987. child->parentComponent_ = 0;
  31988. JUCE_TRY
  31989. {
  31990. if ((currentlyFocusedComponent == child)
  31991. || child->isParentOf (currentlyFocusedComponent))
  31992. {
  31993. // get rid first to force the grabKeyboardFocus to change to us.
  31994. giveAwayFocus();
  31995. grabKeyboardFocus();
  31996. }
  31997. }
  31998. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  31999. catch (const std::exception& e)
  32000. {
  32001. currentlyFocusedComponent = 0;
  32002. Desktop::getInstance().triggerFocusCallback();
  32003. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__);
  32004. }
  32005. catch (...)
  32006. {
  32007. currentlyFocusedComponent = 0;
  32008. Desktop::getInstance().triggerFocusCallback();
  32009. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__);
  32010. }
  32011. #endif
  32012. child->internalHierarchyChanged();
  32013. internalChildrenChanged();
  32014. }
  32015. return child;
  32016. }
  32017. void Component::removeAllChildren()
  32018. {
  32019. for (int i = childComponentList_.size(); --i >= 0;)
  32020. removeChildComponent (i);
  32021. }
  32022. void Component::deleteAllChildren()
  32023. {
  32024. for (int i = childComponentList_.size(); --i >= 0;)
  32025. delete (removeChildComponent (i));
  32026. }
  32027. int Component::getNumChildComponents() const throw()
  32028. {
  32029. return childComponentList_.size();
  32030. }
  32031. Component* Component::getChildComponent (const int index) const throw()
  32032. {
  32033. return childComponentList_ [index];
  32034. }
  32035. int Component::getIndexOfChildComponent (const Component* const child) const throw()
  32036. {
  32037. return childComponentList_.indexOf (const_cast <Component*> (child));
  32038. }
  32039. Component* Component::getTopLevelComponent() const throw()
  32040. {
  32041. const Component* comp = this;
  32042. while (comp->parentComponent_ != 0)
  32043. comp = comp->parentComponent_;
  32044. return (Component*) comp;
  32045. }
  32046. bool Component::isParentOf (const Component* possibleChild) const throw()
  32047. {
  32048. while (possibleChild->isValidComponent())
  32049. {
  32050. possibleChild = possibleChild->parentComponent_;
  32051. if (possibleChild == this)
  32052. return true;
  32053. }
  32054. return false;
  32055. }
  32056. void Component::parentHierarchyChanged()
  32057. {
  32058. }
  32059. void Component::childrenChanged()
  32060. {
  32061. }
  32062. void Component::internalChildrenChanged()
  32063. {
  32064. const ComponentDeletionWatcher deletionChecker (this);
  32065. const bool hasListeners = componentListeners_ != 0;
  32066. childrenChanged();
  32067. if (hasListeners)
  32068. {
  32069. if (deletionChecker.hasBeenDeleted())
  32070. return;
  32071. for (int i = componentListeners_->size(); --i >= 0;)
  32072. {
  32073. ((ComponentListener*) componentListeners_->getUnchecked (i))
  32074. ->componentChildrenChanged (*this);
  32075. if (deletionChecker.hasBeenDeleted())
  32076. return;
  32077. i = jmin (i, componentListeners_->size());
  32078. }
  32079. }
  32080. }
  32081. void Component::internalHierarchyChanged()
  32082. {
  32083. parentHierarchyChanged();
  32084. const ComponentDeletionWatcher deletionChecker (this);
  32085. if (componentListeners_ != 0)
  32086. {
  32087. for (int i = componentListeners_->size(); --i >= 0;)
  32088. {
  32089. ((ComponentListener*) componentListeners_->getUnchecked (i))
  32090. ->componentParentHierarchyChanged (*this);
  32091. if (deletionChecker.hasBeenDeleted())
  32092. return;
  32093. i = jmin (i, componentListeners_->size());
  32094. }
  32095. }
  32096. for (int i = childComponentList_.size(); --i >= 0;)
  32097. {
  32098. childComponentList_.getUnchecked (i)->internalHierarchyChanged();
  32099. // you really shouldn't delete the parent component during a callback telling you
  32100. // that it's changed..
  32101. jassert (! deletionChecker.hasBeenDeleted());
  32102. if (deletionChecker.hasBeenDeleted())
  32103. return;
  32104. i = jmin (i, childComponentList_.size());
  32105. }
  32106. }
  32107. void* Component::runModalLoopCallback (void* userData)
  32108. {
  32109. return (void*) (pointer_sized_int) ((Component*) userData)->runModalLoop();
  32110. }
  32111. int Component::runModalLoop()
  32112. {
  32113. if (! MessageManager::getInstance()->isThisTheMessageThread())
  32114. {
  32115. // use a callback so this can be called from non-gui threads
  32116. return (int) (pointer_sized_int)
  32117. MessageManager::getInstance()
  32118. ->callFunctionOnMessageThread (&runModalLoopCallback, (void*) this);
  32119. }
  32120. Component* const prevFocused = getCurrentlyFocusedComponent();
  32121. ScopedPointer <ComponentDeletionWatcher> deletionChecker;
  32122. if (prevFocused != 0)
  32123. deletionChecker = new ComponentDeletionWatcher (prevFocused);
  32124. if (! isCurrentlyModal())
  32125. enterModalState();
  32126. JUCE_TRY
  32127. {
  32128. while (flags.currentlyModalFlag && flags.visibleFlag)
  32129. {
  32130. if (! MessageManager::getInstance()->runDispatchLoopUntil (20))
  32131. break;
  32132. // check whether this component was deleted during the last message
  32133. if (! isValidMessageListener())
  32134. break;
  32135. }
  32136. }
  32137. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  32138. catch (const std::exception& e)
  32139. {
  32140. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__);
  32141. return 0;
  32142. }
  32143. catch (...)
  32144. {
  32145. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__);
  32146. return 0;
  32147. }
  32148. #endif
  32149. const int modalIndex = modalComponentReturnValueKeys.indexOf (this);
  32150. int returnValue = 0;
  32151. if (modalIndex >= 0)
  32152. {
  32153. modalComponentReturnValueKeys.remove (modalIndex);
  32154. returnValue = modalReturnValues.remove (modalIndex);
  32155. }
  32156. modalComponentStack.removeValue (this);
  32157. if (deletionChecker != 0 && ! deletionChecker->hasBeenDeleted())
  32158. prevFocused->grabKeyboardFocus();
  32159. return returnValue;
  32160. }
  32161. void Component::enterModalState (const bool takeKeyboardFocus_)
  32162. {
  32163. // if component methods are being called from threads other than the message
  32164. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32165. checkMessageManagerIsLocked
  32166. // Check for an attempt to make a component modal when it already is!
  32167. // This can cause nasty problems..
  32168. jassert (! flags.currentlyModalFlag);
  32169. if (! isCurrentlyModal())
  32170. {
  32171. modalComponentStack.add (this);
  32172. modalComponentReturnValueKeys.add (this);
  32173. modalReturnValues.add (0);
  32174. flags.currentlyModalFlag = true;
  32175. setVisible (true);
  32176. if (takeKeyboardFocus_)
  32177. grabKeyboardFocus();
  32178. }
  32179. }
  32180. void Component::exitModalState (const int returnValue)
  32181. {
  32182. if (isCurrentlyModal())
  32183. {
  32184. if (MessageManager::getInstance()->isThisTheMessageThread())
  32185. {
  32186. const int modalIndex = modalComponentReturnValueKeys.indexOf (this);
  32187. if (modalIndex >= 0)
  32188. {
  32189. modalReturnValues.set (modalIndex, returnValue);
  32190. }
  32191. else
  32192. {
  32193. modalComponentReturnValueKeys.add (this);
  32194. modalReturnValues.add (returnValue);
  32195. }
  32196. modalComponentStack.removeValue (this);
  32197. flags.currentlyModalFlag = false;
  32198. bringModalComponentToFront();
  32199. }
  32200. else
  32201. {
  32202. postMessage (new Message (exitModalStateMessage, returnValue, 0, 0));
  32203. }
  32204. }
  32205. }
  32206. bool Component::isCurrentlyModal() const throw()
  32207. {
  32208. return flags.currentlyModalFlag
  32209. && getCurrentlyModalComponent() == this;
  32210. }
  32211. bool Component::isCurrentlyBlockedByAnotherModalComponent() const throw()
  32212. {
  32213. Component* const mc = getCurrentlyModalComponent();
  32214. return mc != 0
  32215. && mc != this
  32216. && (! mc->isParentOf (this))
  32217. && ! mc->canModalEventBeSentToComponent (this);
  32218. }
  32219. int JUCE_CALLTYPE Component::getNumCurrentlyModalComponents() throw()
  32220. {
  32221. return modalComponentStack.size();
  32222. }
  32223. Component* JUCE_CALLTYPE Component::getCurrentlyModalComponent (int index) throw()
  32224. {
  32225. Component* const c = (Component*) (modalComponentStack [modalComponentStack.size() - index - 1]);
  32226. return c->isValidComponent() ? c : 0;
  32227. }
  32228. void Component::bringModalComponentToFront()
  32229. {
  32230. ComponentPeer* lastOne = 0;
  32231. for (int i = 0; i < getNumCurrentlyModalComponents(); ++i)
  32232. {
  32233. Component* const c = getCurrentlyModalComponent (i);
  32234. if (c == 0)
  32235. break;
  32236. ComponentPeer* peer = c->getPeer();
  32237. if (peer != 0 && peer != lastOne)
  32238. {
  32239. if (lastOne == 0)
  32240. {
  32241. peer->toFront (true);
  32242. peer->grabFocus();
  32243. }
  32244. else
  32245. peer->toBehind (lastOne);
  32246. lastOne = peer;
  32247. }
  32248. }
  32249. }
  32250. void Component::setBroughtToFrontOnMouseClick (const bool shouldBeBroughtToFront) throw()
  32251. {
  32252. flags.bringToFrontOnClickFlag = shouldBeBroughtToFront;
  32253. }
  32254. bool Component::isBroughtToFrontOnMouseClick() const throw()
  32255. {
  32256. return flags.bringToFrontOnClickFlag;
  32257. }
  32258. void Component::setMouseCursor (const MouseCursor& cursor) throw()
  32259. {
  32260. cursor_ = cursor;
  32261. if (flags.visibleFlag)
  32262. {
  32263. int mx, my;
  32264. getMouseXYRelative (mx, my);
  32265. if (flags.draggingFlag || reallyContains (mx, my, false))
  32266. {
  32267. internalUpdateMouseCursor (false);
  32268. }
  32269. }
  32270. }
  32271. const MouseCursor Component::getMouseCursor()
  32272. {
  32273. return cursor_;
  32274. }
  32275. void Component::updateMouseCursor() const throw()
  32276. {
  32277. sendFakeMouseMove();
  32278. }
  32279. void Component::internalUpdateMouseCursor (bool forcedUpdate) throw()
  32280. {
  32281. ComponentPeer* const peer = getPeer();
  32282. if (peer != 0)
  32283. {
  32284. MouseCursor mc (getLookAndFeel().getMouseCursorFor (*this));
  32285. if (isUnboundedMouseModeOn && (unboundedMouseOffsetX != 0
  32286. || unboundedMouseOffsetY != 0
  32287. || ! isCursorVisibleUntilOffscreen))
  32288. {
  32289. mc = MouseCursor::NoCursor;
  32290. forcedUpdate = true;
  32291. }
  32292. static void* currentCursorHandle = 0;
  32293. if (forcedUpdate || mc.getHandle() != currentCursorHandle)
  32294. {
  32295. currentCursorHandle = mc.getHandle();
  32296. mc.showInWindow (peer);
  32297. }
  32298. }
  32299. }
  32300. void Component::setRepaintsOnMouseActivity (const bool shouldRepaint) throw()
  32301. {
  32302. flags.repaintOnMouseActivityFlag = shouldRepaint;
  32303. }
  32304. void Component::repaintParent() throw()
  32305. {
  32306. if (flags.visibleFlag)
  32307. internalRepaint (0, 0, getWidth(), getHeight());
  32308. }
  32309. void Component::repaint() throw()
  32310. {
  32311. repaint (0, 0, getWidth(), getHeight());
  32312. }
  32313. void Component::repaint (const int x, const int y,
  32314. const int w, const int h) throw()
  32315. {
  32316. deleteAndZero (bufferedImage_);
  32317. if (flags.visibleFlag)
  32318. internalRepaint (x, y, w, h);
  32319. }
  32320. void Component::internalRepaint (int x, int y, int w, int h)
  32321. {
  32322. // if component methods are being called from threads other than the message
  32323. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32324. checkMessageManagerIsLocked
  32325. if (x < 0)
  32326. {
  32327. w += x;
  32328. x = 0;
  32329. }
  32330. if (x + w > getWidth())
  32331. w = getWidth() - x;
  32332. if (w > 0)
  32333. {
  32334. if (y < 0)
  32335. {
  32336. h += y;
  32337. y = 0;
  32338. }
  32339. if (y + h > getHeight())
  32340. h = getHeight() - y;
  32341. if (h > 0)
  32342. {
  32343. if (parentComponent_ != 0)
  32344. {
  32345. x += getX();
  32346. y += getY();
  32347. if (parentComponent_->flags.visibleFlag)
  32348. parentComponent_->internalRepaint (x, y, w, h);
  32349. }
  32350. else if (flags.hasHeavyweightPeerFlag)
  32351. {
  32352. ComponentPeer* const peer = getPeer();
  32353. if (peer != 0)
  32354. peer->repaint (x, y, w, h);
  32355. }
  32356. }
  32357. }
  32358. }
  32359. void Component::paintEntireComponent (Graphics& originalContext)
  32360. {
  32361. jassert (! originalContext.isClipEmpty());
  32362. #ifdef JUCE_DEBUG
  32363. flags.isInsidePaintCall = true;
  32364. #endif
  32365. Graphics* g = &originalContext;
  32366. Image* effectImage = 0;
  32367. if (effect_ != 0)
  32368. {
  32369. effectImage = Image::createNativeImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
  32370. getWidth(), getHeight(),
  32371. ! flags.opaqueFlag);
  32372. g = new Graphics (*effectImage);
  32373. }
  32374. g->saveState();
  32375. clipObscuredRegions (*g, g->getClipBounds(), 0, 0);
  32376. if (! g->isClipEmpty())
  32377. {
  32378. if (bufferedImage_ != 0)
  32379. {
  32380. g->setColour (Colours::black);
  32381. g->drawImageAt (bufferedImage_, 0, 0);
  32382. }
  32383. else
  32384. {
  32385. if (flags.bufferToImageFlag)
  32386. {
  32387. if (bufferedImage_ == 0)
  32388. {
  32389. bufferedImage_ = Image::createNativeImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
  32390. getWidth(), getHeight(), ! flags.opaqueFlag);
  32391. Graphics imG (*bufferedImage_);
  32392. paint (imG);
  32393. }
  32394. g->setColour (Colours::black);
  32395. g->drawImageAt (bufferedImage_, 0, 0);
  32396. }
  32397. else
  32398. {
  32399. paint (*g);
  32400. g->resetToDefaultState();
  32401. }
  32402. }
  32403. }
  32404. g->restoreState();
  32405. for (int i = 0; i < childComponentList_.size(); ++i)
  32406. {
  32407. Component* const child = childComponentList_.getUnchecked (i);
  32408. if (child->isVisible())
  32409. {
  32410. g->saveState();
  32411. if (g->reduceClipRegion (child->getX(), child->getY(),
  32412. child->getWidth(), child->getHeight()))
  32413. {
  32414. for (int j = i + 1; j < childComponentList_.size(); ++j)
  32415. {
  32416. const Component* const sibling = childComponentList_.getUnchecked (j);
  32417. if (sibling->flags.opaqueFlag && sibling->isVisible())
  32418. g->excludeClipRegion (sibling->getX(), sibling->getY(),
  32419. sibling->getWidth(), sibling->getHeight());
  32420. }
  32421. if (! g->isClipEmpty())
  32422. {
  32423. g->setOrigin (child->getX(), child->getY());
  32424. child->paintEntireComponent (*g);
  32425. }
  32426. }
  32427. g->restoreState();
  32428. }
  32429. }
  32430. JUCE_TRY
  32431. {
  32432. g->saveState();
  32433. paintOverChildren (*g);
  32434. g->restoreState();
  32435. }
  32436. JUCE_CATCH_EXCEPTION
  32437. if (effect_ != 0)
  32438. {
  32439. delete g;
  32440. effect_->applyEffect (*effectImage, originalContext);
  32441. delete effectImage;
  32442. }
  32443. #ifdef JUCE_DEBUG
  32444. flags.isInsidePaintCall = false;
  32445. #endif
  32446. }
  32447. Image* Component::createComponentSnapshot (const Rectangle<int>& areaToGrab,
  32448. const bool clipImageToComponentBounds)
  32449. {
  32450. Rectangle<int> r (areaToGrab);
  32451. if (clipImageToComponentBounds)
  32452. r = r.getIntersection (Rectangle<int> (0, 0, getWidth(), getHeight()));
  32453. Image* const componentImage = Image::createNativeImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
  32454. jmax (1, r.getWidth()),
  32455. jmax (1, r.getHeight()),
  32456. true);
  32457. Graphics imageContext (*componentImage);
  32458. imageContext.setOrigin (-r.getX(),
  32459. -r.getY());
  32460. paintEntireComponent (imageContext);
  32461. return componentImage;
  32462. }
  32463. void Component::setComponentEffect (ImageEffectFilter* const effect)
  32464. {
  32465. if (effect_ != effect)
  32466. {
  32467. effect_ = effect;
  32468. repaint();
  32469. }
  32470. }
  32471. LookAndFeel& Component::getLookAndFeel() const throw()
  32472. {
  32473. const Component* c = this;
  32474. do
  32475. {
  32476. if (c->lookAndFeel_ != 0)
  32477. return *(c->lookAndFeel_);
  32478. c = c->parentComponent_;
  32479. }
  32480. while (c != 0);
  32481. return LookAndFeel::getDefaultLookAndFeel();
  32482. }
  32483. void Component::setLookAndFeel (LookAndFeel* const newLookAndFeel)
  32484. {
  32485. if (lookAndFeel_ != newLookAndFeel)
  32486. {
  32487. lookAndFeel_ = newLookAndFeel;
  32488. sendLookAndFeelChange();
  32489. }
  32490. }
  32491. void Component::lookAndFeelChanged()
  32492. {
  32493. }
  32494. void Component::sendLookAndFeelChange()
  32495. {
  32496. repaint();
  32497. lookAndFeelChanged();
  32498. // (it's not a great idea to do anything that would delete this component
  32499. // during the lookAndFeelChanged() callback)
  32500. jassert (isValidComponent());
  32501. const ComponentDeletionWatcher deletionChecker (this);
  32502. for (int i = childComponentList_.size(); --i >= 0;)
  32503. {
  32504. childComponentList_.getUnchecked (i)->sendLookAndFeelChange();
  32505. if (deletionChecker.hasBeenDeleted())
  32506. return;
  32507. i = jmin (i, childComponentList_.size());
  32508. }
  32509. }
  32510. static const var::identifier getColourPropertyId (const int colourId)
  32511. {
  32512. String s;
  32513. s.preallocateStorage (18);
  32514. s << T("jcclr_") << colourId;
  32515. return s;
  32516. }
  32517. const Colour Component::findColour (const int colourId, const bool inheritFromParent) const throw()
  32518. {
  32519. var* v = properties.getItem (getColourPropertyId (colourId));
  32520. if (v != 0)
  32521. return Colour ((int) *v);
  32522. if (inheritFromParent && parentComponent_ != 0)
  32523. return parentComponent_->findColour (colourId, true);
  32524. return getLookAndFeel().findColour (colourId);
  32525. }
  32526. bool Component::isColourSpecified (const int colourId) const throw()
  32527. {
  32528. return properties.contains (getColourPropertyId (colourId));
  32529. }
  32530. void Component::removeColour (const int colourId)
  32531. {
  32532. if (properties.remove (getColourPropertyId (colourId)))
  32533. colourChanged();
  32534. }
  32535. void Component::setColour (const int colourId, const Colour& colour)
  32536. {
  32537. if (properties.set (getColourPropertyId (colourId), (int) colour.getARGB()))
  32538. colourChanged();
  32539. }
  32540. void Component::copyAllExplicitColoursTo (Component& target) const throw()
  32541. {
  32542. bool changed = false;
  32543. for (int i = properties.size(); --i >= 0;)
  32544. {
  32545. const var::identifier name (properties.getName(i));
  32546. if (name.name.startsWith (T("jcclr_")))
  32547. if (target.properties.set (name, properties [name]))
  32548. changed = true;
  32549. }
  32550. if (changed)
  32551. target.colourChanged();
  32552. }
  32553. void Component::colourChanged()
  32554. {
  32555. }
  32556. const Rectangle<int> Component::getUnclippedArea() const
  32557. {
  32558. int x = 0, y = 0, w = getWidth(), h = getHeight();
  32559. Component* p = parentComponent_;
  32560. int px = getX();
  32561. int py = getY();
  32562. while (p != 0)
  32563. {
  32564. if (! Rectangle<int>::intersectRectangles (x, y, w, h, -px, -py, p->getWidth(), p->getHeight()))
  32565. return Rectangle<int>();
  32566. px += p->getX();
  32567. py += p->getY();
  32568. p = p->parentComponent_;
  32569. }
  32570. return Rectangle<int> (x, y, w, h);
  32571. }
  32572. void Component::clipObscuredRegions (Graphics& g, const Rectangle<int>& clipRect,
  32573. const int deltaX, const int deltaY) const throw()
  32574. {
  32575. for (int i = childComponentList_.size(); --i >= 0;)
  32576. {
  32577. const Component* const c = childComponentList_.getUnchecked(i);
  32578. if (c->isVisible())
  32579. {
  32580. Rectangle<int> newClip (clipRect.getIntersection (c->bounds_));
  32581. if (! newClip.isEmpty())
  32582. {
  32583. if (c->isOpaque())
  32584. {
  32585. g.excludeClipRegion (deltaX + newClip.getX(),
  32586. deltaY + newClip.getY(),
  32587. newClip.getWidth(),
  32588. newClip.getHeight());
  32589. }
  32590. else
  32591. {
  32592. newClip.translate (-c->getX(), -c->getY());
  32593. c->clipObscuredRegions (g, newClip,
  32594. c->getX() + deltaX,
  32595. c->getY() + deltaY);
  32596. }
  32597. }
  32598. }
  32599. }
  32600. }
  32601. void Component::getVisibleArea (RectangleList& result,
  32602. const bool includeSiblings) const
  32603. {
  32604. result.clear();
  32605. const Rectangle<int> unclipped (getUnclippedArea());
  32606. if (! unclipped.isEmpty())
  32607. {
  32608. result.add (unclipped);
  32609. if (includeSiblings)
  32610. {
  32611. const Component* const c = getTopLevelComponent();
  32612. int x = 0, y = 0;
  32613. c->relativePositionToOtherComponent (this, x, y);
  32614. c->subtractObscuredRegions (result, x, y,
  32615. Rectangle<int> (0, 0, c->getWidth(), c->getHeight()),
  32616. this);
  32617. }
  32618. subtractObscuredRegions (result, 0, 0, unclipped, 0);
  32619. result.consolidate();
  32620. }
  32621. }
  32622. void Component::subtractObscuredRegions (RectangleList& result,
  32623. const int deltaX,
  32624. const int deltaY,
  32625. const Rectangle<int>& clipRect,
  32626. const Component* const compToAvoid) const throw()
  32627. {
  32628. for (int i = childComponentList_.size(); --i >= 0;)
  32629. {
  32630. const Component* const c = childComponentList_.getUnchecked(i);
  32631. if (c != compToAvoid && c->isVisible())
  32632. {
  32633. if (c->isOpaque())
  32634. {
  32635. Rectangle<int> childBounds (c->bounds_.getIntersection (clipRect));
  32636. childBounds.translate (deltaX, deltaY);
  32637. result.subtract (childBounds);
  32638. }
  32639. else
  32640. {
  32641. Rectangle<int> newClip (clipRect.getIntersection (c->bounds_));
  32642. newClip.translate (-c->getX(), -c->getY());
  32643. c->subtractObscuredRegions (result,
  32644. c->getX() + deltaX,
  32645. c->getY() + deltaY,
  32646. newClip,
  32647. compToAvoid);
  32648. }
  32649. }
  32650. }
  32651. }
  32652. void Component::mouseEnter (const MouseEvent&)
  32653. {
  32654. // base class does nothing
  32655. }
  32656. void Component::mouseExit (const MouseEvent&)
  32657. {
  32658. // base class does nothing
  32659. }
  32660. void Component::mouseDown (const MouseEvent&)
  32661. {
  32662. // base class does nothing
  32663. }
  32664. void Component::mouseUp (const MouseEvent&)
  32665. {
  32666. // base class does nothing
  32667. }
  32668. void Component::mouseDrag (const MouseEvent&)
  32669. {
  32670. // base class does nothing
  32671. }
  32672. void Component::mouseMove (const MouseEvent&)
  32673. {
  32674. // base class does nothing
  32675. }
  32676. void Component::mouseDoubleClick (const MouseEvent&)
  32677. {
  32678. // base class does nothing
  32679. }
  32680. void Component::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  32681. {
  32682. // the base class just passes this event up to its parent..
  32683. if (parentComponent_ != 0)
  32684. parentComponent_->mouseWheelMove (e.getEventRelativeTo (parentComponent_),
  32685. wheelIncrementX, wheelIncrementY);
  32686. }
  32687. void Component::resized()
  32688. {
  32689. // base class does nothing
  32690. }
  32691. void Component::moved()
  32692. {
  32693. // base class does nothing
  32694. }
  32695. void Component::childBoundsChanged (Component*)
  32696. {
  32697. // base class does nothing
  32698. }
  32699. void Component::parentSizeChanged()
  32700. {
  32701. // base class does nothing
  32702. }
  32703. void Component::addComponentListener (ComponentListener* const newListener) throw()
  32704. {
  32705. if (componentListeners_ == 0)
  32706. componentListeners_ = new VoidArray();
  32707. componentListeners_->addIfNotAlreadyThere (newListener);
  32708. }
  32709. void Component::removeComponentListener (ComponentListener* const listenerToRemove) throw()
  32710. {
  32711. jassert (isValidComponent());
  32712. if (componentListeners_ != 0)
  32713. componentListeners_->removeValue (listenerToRemove);
  32714. }
  32715. void Component::inputAttemptWhenModal()
  32716. {
  32717. bringModalComponentToFront();
  32718. getLookAndFeel().playAlertSound();
  32719. }
  32720. bool Component::canModalEventBeSentToComponent (const Component*)
  32721. {
  32722. return false;
  32723. }
  32724. void Component::internalModalInputAttempt()
  32725. {
  32726. Component* const current = getCurrentlyModalComponent();
  32727. if (current != 0)
  32728. current->inputAttemptWhenModal();
  32729. }
  32730. void Component::paint (Graphics&)
  32731. {
  32732. // all painting is done in the subclasses
  32733. jassert (! isOpaque()); // if your component's opaque, you've gotta paint it!
  32734. }
  32735. void Component::paintOverChildren (Graphics&)
  32736. {
  32737. // all painting is done in the subclasses
  32738. }
  32739. void Component::handleMessage (const Message& message)
  32740. {
  32741. if (message.intParameter1 == exitModalStateMessage)
  32742. {
  32743. exitModalState (message.intParameter2);
  32744. }
  32745. else if (message.intParameter1 == customCommandMessage)
  32746. {
  32747. handleCommandMessage (message.intParameter2);
  32748. }
  32749. }
  32750. void Component::postCommandMessage (const int commandId) throw()
  32751. {
  32752. postMessage (new Message (customCommandMessage, commandId, 0, 0));
  32753. }
  32754. void Component::handleCommandMessage (int)
  32755. {
  32756. // used by subclasses
  32757. }
  32758. void Component::addMouseListener (MouseListener* const newListener,
  32759. const bool wantsEventsForAllNestedChildComponents) throw()
  32760. {
  32761. // if component methods are being called from threads other than the message
  32762. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32763. checkMessageManagerIsLocked
  32764. if (mouseListeners_ == 0)
  32765. mouseListeners_ = new VoidArray();
  32766. if (! mouseListeners_->contains (newListener))
  32767. {
  32768. if (wantsEventsForAllNestedChildComponents)
  32769. {
  32770. mouseListeners_->insert (0, newListener);
  32771. ++numDeepMouseListeners;
  32772. }
  32773. else
  32774. {
  32775. mouseListeners_->add (newListener);
  32776. }
  32777. }
  32778. }
  32779. void Component::removeMouseListener (MouseListener* const listenerToRemove) throw()
  32780. {
  32781. // if component methods are being called from threads other than the message
  32782. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32783. checkMessageManagerIsLocked
  32784. if (mouseListeners_ != 0)
  32785. {
  32786. const int index = mouseListeners_->indexOf (listenerToRemove);
  32787. if (index >= 0)
  32788. {
  32789. if (index < numDeepMouseListeners)
  32790. --numDeepMouseListeners;
  32791. mouseListeners_->remove (index);
  32792. }
  32793. }
  32794. }
  32795. void Component::internalMouseEnter (int x, int y, int64 time)
  32796. {
  32797. if (isCurrentlyBlockedByAnotherModalComponent())
  32798. {
  32799. // if something else is modal, always just show a normal mouse cursor
  32800. if (componentUnderMouse == this)
  32801. {
  32802. ComponentPeer* const peer = getPeer();
  32803. if (peer != 0)
  32804. {
  32805. MouseCursor mc (MouseCursor::NormalCursor);
  32806. mc.showInWindow (peer);
  32807. }
  32808. }
  32809. return;
  32810. }
  32811. if (isValidComponent() && ! flags.mouseInsideFlag)
  32812. {
  32813. flags.mouseInsideFlag = true;
  32814. flags.mouseOverFlag = true;
  32815. flags.draggingFlag = false;
  32816. const ComponentDeletionWatcher deletionChecker (this);
  32817. if (flags.repaintOnMouseActivityFlag)
  32818. repaint();
  32819. const MouseEvent me (x, y,
  32820. ModifierKeys::getCurrentModifiers(),
  32821. this,
  32822. Time (time),
  32823. x, y,
  32824. Time (time),
  32825. 0, false);
  32826. mouseEnter (me);
  32827. if (deletionChecker.hasBeenDeleted())
  32828. return;
  32829. Desktop::getInstance().resetTimer();
  32830. for (int i = Desktop::getInstance().mouseListeners.size(); --i >= 0;)
  32831. {
  32832. ((MouseListener*) Desktop::getInstance().mouseListeners[i])->mouseEnter (me);
  32833. if (deletionChecker.hasBeenDeleted())
  32834. return;
  32835. i = jmin (i, Desktop::getInstance().mouseListeners.size());
  32836. }
  32837. if (mouseListeners_ != 0)
  32838. {
  32839. for (int i = mouseListeners_->size(); --i >= 0;)
  32840. {
  32841. ((MouseListener*) mouseListeners_->getUnchecked(i))->mouseEnter (me);
  32842. if (deletionChecker.hasBeenDeleted())
  32843. return;
  32844. i = jmin (i, mouseListeners_->size());
  32845. }
  32846. }
  32847. const Component* p = parentComponent_;
  32848. while (p != 0)
  32849. {
  32850. const ComponentDeletionWatcher parentDeletionChecker (p);
  32851. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32852. {
  32853. ((MouseListener*) (p->mouseListeners_->getUnchecked(i)))->mouseEnter (me);
  32854. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  32855. return;
  32856. i = jmin (i, p->numDeepMouseListeners);
  32857. }
  32858. p = p->parentComponent_;
  32859. }
  32860. }
  32861. if (componentUnderMouse == this)
  32862. internalUpdateMouseCursor (true);
  32863. }
  32864. void Component::internalMouseExit (int x, int y, int64 time)
  32865. {
  32866. const ComponentDeletionWatcher deletionChecker (this);
  32867. if (flags.draggingFlag)
  32868. {
  32869. internalMouseUp (ModifierKeys::getCurrentModifiers().getRawFlags(), x, y, time);
  32870. if (deletionChecker.hasBeenDeleted())
  32871. return;
  32872. }
  32873. enableUnboundedMouseMovement (false);
  32874. if (flags.mouseInsideFlag || flags.mouseOverFlag)
  32875. {
  32876. flags.mouseInsideFlag = false;
  32877. flags.mouseOverFlag = false;
  32878. flags.draggingFlag = false;
  32879. if (flags.repaintOnMouseActivityFlag)
  32880. repaint();
  32881. const MouseEvent me (x, y,
  32882. ModifierKeys::getCurrentModifiers(),
  32883. this,
  32884. Time (time),
  32885. x, y,
  32886. Time (time),
  32887. 0, false);
  32888. mouseExit (me);
  32889. if (deletionChecker.hasBeenDeleted())
  32890. return;
  32891. Desktop::getInstance().resetTimer();
  32892. for (int i = Desktop::getInstance().mouseListeners.size(); --i >= 0;)
  32893. {
  32894. ((MouseListener*) Desktop::getInstance().mouseListeners[i])->mouseExit (me);
  32895. if (deletionChecker.hasBeenDeleted())
  32896. return;
  32897. i = jmin (i, Desktop::getInstance().mouseListeners.size());
  32898. }
  32899. if (mouseListeners_ != 0)
  32900. {
  32901. for (int i = mouseListeners_->size(); --i >= 0;)
  32902. {
  32903. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseExit (me);
  32904. if (deletionChecker.hasBeenDeleted())
  32905. return;
  32906. i = jmin (i, mouseListeners_->size());
  32907. }
  32908. }
  32909. const Component* p = parentComponent_;
  32910. while (p != 0)
  32911. {
  32912. const ComponentDeletionWatcher parentDeletionChecker (p);
  32913. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32914. {
  32915. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseExit (me);
  32916. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  32917. return;
  32918. i = jmin (i, p->numDeepMouseListeners);
  32919. }
  32920. p = p->parentComponent_;
  32921. }
  32922. }
  32923. }
  32924. class InternalDragRepeater : public Timer
  32925. {
  32926. public:
  32927. InternalDragRepeater() {}
  32928. ~InternalDragRepeater() {}
  32929. void timerCallback()
  32930. {
  32931. Component* const c = Component::getComponentUnderMouse();
  32932. if (c != 0 && c->isMouseButtonDown())
  32933. {
  32934. int x, y;
  32935. c->getMouseXYRelative (x, y);
  32936. // the offsets have been added on, so must be taken off before calling the
  32937. // drag.. otherwise they'll be added twice
  32938. x -= unboundedMouseOffsetX;
  32939. y -= unboundedMouseOffsetY;
  32940. c->internalMouseDrag (x, y, Time::currentTimeMillis());
  32941. }
  32942. }
  32943. juce_UseDebuggingNewOperator
  32944. private:
  32945. InternalDragRepeater (const InternalDragRepeater&);
  32946. InternalDragRepeater& operator= (const InternalDragRepeater&);
  32947. };
  32948. static InternalDragRepeater* dragRepeater = 0;
  32949. void Component::beginDragAutoRepeat (const int interval)
  32950. {
  32951. if (interval > 0)
  32952. {
  32953. if (dragRepeater == 0)
  32954. dragRepeater = new InternalDragRepeater();
  32955. if (dragRepeater->getTimerInterval() != interval)
  32956. dragRepeater->startTimer (interval);
  32957. }
  32958. else
  32959. {
  32960. deleteAndZero (dragRepeater);
  32961. }
  32962. }
  32963. void Component::internalMouseDown (const int x, const int y, const int64 time)
  32964. {
  32965. Desktop& desktop = Desktop::getInstance();
  32966. int gx = x, gy = y;
  32967. relativePositionToGlobal (gx, gy);
  32968. desktop.registerMouseDown (Point<int> (gx, gy), time, this);
  32969. const ComponentDeletionWatcher deletionChecker (this);
  32970. if (isCurrentlyBlockedByAnotherModalComponent())
  32971. {
  32972. internalModalInputAttempt();
  32973. if (deletionChecker.hasBeenDeleted())
  32974. return;
  32975. // If processing the input attempt has exited the modal loop, we'll allow the event
  32976. // to be delivered..
  32977. if (isCurrentlyBlockedByAnotherModalComponent())
  32978. {
  32979. // allow blocked mouse-events to go to global listeners..
  32980. const MouseEvent me (x, y,
  32981. ModifierKeys::getCurrentModifiers(),
  32982. this,
  32983. Time (time),
  32984. x, y,
  32985. desktop.getLastMouseDownTime(),
  32986. desktop.getNumberOfMultipleClicks(),
  32987. false);
  32988. desktop.resetTimer();
  32989. for (int i = desktop.mouseListeners.size(); --i >= 0;)
  32990. {
  32991. ((MouseListener*) desktop.mouseListeners[i])->mouseDown (me);
  32992. if (deletionChecker.hasBeenDeleted())
  32993. return;
  32994. i = jmin (i, desktop.mouseListeners.size());
  32995. }
  32996. return;
  32997. }
  32998. }
  32999. {
  33000. Component* c = this;
  33001. while (c != 0)
  33002. {
  33003. if (c->isBroughtToFrontOnMouseClick())
  33004. {
  33005. c->toFront (true);
  33006. if (deletionChecker.hasBeenDeleted())
  33007. return;
  33008. }
  33009. c = c->parentComponent_;
  33010. }
  33011. }
  33012. if (! flags.dontFocusOnMouseClickFlag)
  33013. grabFocusInternal (focusChangedByMouseClick);
  33014. if (! deletionChecker.hasBeenDeleted())
  33015. {
  33016. flags.draggingFlag = true;
  33017. flags.mouseOverFlag = true;
  33018. if (flags.repaintOnMouseActivityFlag)
  33019. repaint();
  33020. const MouseEvent me (x, y,
  33021. ModifierKeys::getCurrentModifiers(),
  33022. this,
  33023. desktop.getLastMouseDownTime(),
  33024. x, y,
  33025. desktop.getLastMouseDownTime(),
  33026. desktop.getNumberOfMultipleClicks(),
  33027. false);
  33028. mouseDown (me);
  33029. if (deletionChecker.hasBeenDeleted())
  33030. return;
  33031. desktop.resetTimer();
  33032. for (int i = desktop.mouseListeners.size(); --i >= 0;)
  33033. {
  33034. ((MouseListener*) desktop.mouseListeners[i])->mouseDown (me);
  33035. if (deletionChecker.hasBeenDeleted())
  33036. return;
  33037. i = jmin (i, desktop.mouseListeners.size());
  33038. }
  33039. if (mouseListeners_ != 0)
  33040. {
  33041. for (int i = mouseListeners_->size(); --i >= 0;)
  33042. {
  33043. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseDown (me);
  33044. if (deletionChecker.hasBeenDeleted())
  33045. return;
  33046. i = jmin (i, mouseListeners_->size());
  33047. }
  33048. }
  33049. const Component* p = parentComponent_;
  33050. while (p != 0)
  33051. {
  33052. const ComponentDeletionWatcher parentDeletionChecker (p);
  33053. for (int i = p->numDeepMouseListeners; --i >= 0;)
  33054. {
  33055. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseDown (me);
  33056. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  33057. return;
  33058. i = jmin (i, p->numDeepMouseListeners);
  33059. }
  33060. p = p->parentComponent_;
  33061. }
  33062. }
  33063. }
  33064. void Component::internalMouseUp (const int oldModifiers, int x, int y, const int64 time)
  33065. {
  33066. if (isValidComponent() && flags.draggingFlag)
  33067. {
  33068. Desktop& desktop = Desktop::getInstance();
  33069. flags.draggingFlag = false;
  33070. deleteAndZero (dragRepeater);
  33071. x += unboundedMouseOffsetX;
  33072. y += unboundedMouseOffsetY;
  33073. int gx = x, gy = y;
  33074. relativePositionToGlobal (gx, gy);
  33075. desktop.registerMouseDrag (Point<int> (gx, gy));
  33076. const ComponentDeletionWatcher deletionChecker (this);
  33077. if (flags.repaintOnMouseActivityFlag)
  33078. repaint();
  33079. int mdx, mdy;
  33080. Desktop::getLastMouseDownPosition (mdx, mdy);
  33081. globalPositionToRelative (mdx, mdy);
  33082. const Time lastMouseDownTime (desktop.getLastMouseDownTime());
  33083. const MouseEvent me (x, y,
  33084. oldModifiers,
  33085. this,
  33086. Time (time),
  33087. mdx, mdy,
  33088. lastMouseDownTime,
  33089. desktop.getNumberOfMultipleClicks(),
  33090. desktop.mouseMovedSignificantlySincePressed
  33091. || time > lastMouseDownTime.toMilliseconds() + 300);
  33092. mouseUp (me);
  33093. if (deletionChecker.hasBeenDeleted())
  33094. return;
  33095. desktop.resetTimer();
  33096. for (int i = desktop.mouseListeners.size(); --i >= 0;)
  33097. {
  33098. ((MouseListener*) desktop.mouseListeners[i])->mouseUp (me);
  33099. if (deletionChecker.hasBeenDeleted())
  33100. return;
  33101. i = jmin (i, desktop.mouseListeners.size());
  33102. }
  33103. if (mouseListeners_ != 0)
  33104. {
  33105. for (int i = mouseListeners_->size(); --i >= 0;)
  33106. {
  33107. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseUp (me);
  33108. if (deletionChecker.hasBeenDeleted())
  33109. return;
  33110. i = jmin (i, mouseListeners_->size());
  33111. }
  33112. }
  33113. {
  33114. const Component* p = parentComponent_;
  33115. while (p != 0)
  33116. {
  33117. const ComponentDeletionWatcher parentDeletionChecker (p);
  33118. for (int i = p->numDeepMouseListeners; --i >= 0;)
  33119. {
  33120. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseUp (me);
  33121. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  33122. return;
  33123. i = jmin (i, p->numDeepMouseListeners);
  33124. }
  33125. p = p->parentComponent_;
  33126. }
  33127. }
  33128. // check for double-click
  33129. if (me.getNumberOfClicks() >= 2)
  33130. {
  33131. const int numListeners = (mouseListeners_ != 0) ? mouseListeners_->size() : 0;
  33132. mouseDoubleClick (me);
  33133. int i;
  33134. for (i = desktop.mouseListeners.size(); --i >= 0;)
  33135. {
  33136. ((MouseListener*) desktop.mouseListeners[i])->mouseDoubleClick (me);
  33137. if (deletionChecker.hasBeenDeleted())
  33138. return;
  33139. i = jmin (i, desktop.mouseListeners.size());
  33140. }
  33141. for (i = numListeners; --i >= 0;)
  33142. {
  33143. if (deletionChecker.hasBeenDeleted() || mouseListeners_ == 0)
  33144. return;
  33145. MouseListener* const ml = (MouseListener*)((*mouseListeners_)[i]);
  33146. if (ml != 0)
  33147. ml->mouseDoubleClick (me);
  33148. }
  33149. if (deletionChecker.hasBeenDeleted())
  33150. return;
  33151. const Component* p = parentComponent_;
  33152. while (p != 0)
  33153. {
  33154. const ComponentDeletionWatcher parentDeletionChecker (p);
  33155. for (i = p->numDeepMouseListeners; --i >= 0;)
  33156. {
  33157. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseDoubleClick (me);
  33158. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  33159. return;
  33160. i = jmin (i, p->numDeepMouseListeners);
  33161. }
  33162. p = p->parentComponent_;
  33163. }
  33164. }
  33165. }
  33166. enableUnboundedMouseMovement (false);
  33167. }
  33168. void Component::internalMouseDrag (int x, int y, const int64 time)
  33169. {
  33170. if (isValidComponent() && flags.draggingFlag)
  33171. {
  33172. Desktop& desktop = Desktop::getInstance();
  33173. flags.mouseOverFlag = reallyContains (x, y, false);
  33174. x += unboundedMouseOffsetX;
  33175. y += unboundedMouseOffsetY;
  33176. int gx = x, gy = y;
  33177. relativePositionToGlobal (gx, gy);
  33178. desktop.registerMouseDrag (Point<int> (gx, gy));
  33179. const ComponentDeletionWatcher deletionChecker (this);
  33180. int mdx, mdy;
  33181. Desktop::getLastMouseDownPosition (mdx, mdy);
  33182. globalPositionToRelative (mdx, mdy);
  33183. const Time lastMouseDownTime (desktop.getLastMouseDownTime());
  33184. const MouseEvent me (x, y,
  33185. ModifierKeys::getCurrentModifiers(),
  33186. this,
  33187. Time (time),
  33188. mdx, mdy,
  33189. lastMouseDownTime,
  33190. desktop.getNumberOfMultipleClicks(),
  33191. desktop.mouseMovedSignificantlySincePressed
  33192. || time > lastMouseDownTime.toMilliseconds() + 300);
  33193. mouseDrag (me);
  33194. if (deletionChecker.hasBeenDeleted())
  33195. return;
  33196. desktop.resetTimer();
  33197. for (int i = desktop.mouseListeners.size(); --i >= 0;)
  33198. {
  33199. ((MouseListener*) desktop.mouseListeners[i])->mouseDrag (me);
  33200. if (deletionChecker.hasBeenDeleted())
  33201. return;
  33202. i = jmin (i, desktop.mouseListeners.size());
  33203. }
  33204. if (mouseListeners_ != 0)
  33205. {
  33206. for (int i = mouseListeners_->size(); --i >= 0;)
  33207. {
  33208. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseDrag (me);
  33209. if (deletionChecker.hasBeenDeleted())
  33210. return;
  33211. i = jmin (i, mouseListeners_->size());
  33212. }
  33213. }
  33214. const Component* p = parentComponent_;
  33215. while (p != 0)
  33216. {
  33217. const ComponentDeletionWatcher parentDeletionChecker (p);
  33218. for (int i = p->numDeepMouseListeners; --i >= 0;)
  33219. {
  33220. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseDrag (me);
  33221. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  33222. return;
  33223. i = jmin (i, p->numDeepMouseListeners);
  33224. }
  33225. p = p->parentComponent_;
  33226. }
  33227. if (this == componentUnderMouse)
  33228. {
  33229. if (isUnboundedMouseModeOn)
  33230. {
  33231. Rectangle<int> screenArea (getParentMonitorArea().expanded (-2, -2));
  33232. int mx, my;
  33233. Desktop::getMousePosition (mx, my);
  33234. if (! screenArea.contains (mx, my))
  33235. {
  33236. int deltaX = 0, deltaY = 0;
  33237. if (mx <= screenArea.getX() || mx >= screenArea.getRight())
  33238. deltaX = getScreenX() + getWidth() / 2 - mx;
  33239. if (my <= screenArea.getY() || my >= screenArea.getBottom())
  33240. deltaY = getScreenY() + getHeight() / 2 - my;
  33241. unboundedMouseOffsetX -= deltaX;
  33242. unboundedMouseOffsetY -= deltaY;
  33243. Desktop::setMousePosition (mx + deltaX,
  33244. my + deltaY);
  33245. }
  33246. else if (isCursorVisibleUntilOffscreen
  33247. && (unboundedMouseOffsetX != 0 || unboundedMouseOffsetY != 0)
  33248. && screenArea.contains (mx + unboundedMouseOffsetX,
  33249. my + unboundedMouseOffsetY))
  33250. {
  33251. mx += unboundedMouseOffsetX;
  33252. my += unboundedMouseOffsetY;
  33253. unboundedMouseOffsetX = 0;
  33254. unboundedMouseOffsetY = 0;
  33255. Desktop::setMousePosition (mx, my);
  33256. }
  33257. }
  33258. internalUpdateMouseCursor (false);
  33259. }
  33260. }
  33261. }
  33262. void Component::internalMouseMove (const int x, const int y, const int64 time)
  33263. {
  33264. const ComponentDeletionWatcher deletionChecker (this);
  33265. if (isValidComponent())
  33266. {
  33267. Desktop& desktop = Desktop::getInstance();
  33268. const MouseEvent me (x, y,
  33269. ModifierKeys::getCurrentModifiers(),
  33270. this,
  33271. Time (time),
  33272. x, y,
  33273. Time (time),
  33274. 0, false);
  33275. if (isCurrentlyBlockedByAnotherModalComponent())
  33276. {
  33277. // allow blocked mouse-events to go to global listeners..
  33278. desktop.sendMouseMove();
  33279. }
  33280. else
  33281. {
  33282. if (this == componentUnderMouse)
  33283. internalUpdateMouseCursor (false);
  33284. flags.mouseOverFlag = true;
  33285. mouseMove (me);
  33286. if (deletionChecker.hasBeenDeleted())
  33287. return;
  33288. desktop.resetTimer();
  33289. for (int i = desktop.mouseListeners.size(); --i >= 0;)
  33290. {
  33291. ((MouseListener*) desktop.mouseListeners[i])->mouseMove (me);
  33292. if (deletionChecker.hasBeenDeleted())
  33293. return;
  33294. i = jmin (i, desktop.mouseListeners.size());
  33295. }
  33296. if (mouseListeners_ != 0)
  33297. {
  33298. for (int i = mouseListeners_->size(); --i >= 0;)
  33299. {
  33300. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseMove (me);
  33301. if (deletionChecker.hasBeenDeleted())
  33302. return;
  33303. i = jmin (i, mouseListeners_->size());
  33304. }
  33305. }
  33306. const Component* p = parentComponent_;
  33307. while (p != 0)
  33308. {
  33309. const ComponentDeletionWatcher parentDeletionChecker (p);
  33310. for (int i = p->numDeepMouseListeners; --i >= 0;)
  33311. {
  33312. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseMove (me);
  33313. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  33314. return;
  33315. i = jmin (i, p->numDeepMouseListeners);
  33316. }
  33317. p = p->parentComponent_;
  33318. }
  33319. }
  33320. }
  33321. }
  33322. void Component::internalMouseWheel (const int intAmountX, const int intAmountY, const int64 time)
  33323. {
  33324. Desktop& desktop = Desktop::getInstance();
  33325. const ComponentDeletionWatcher deletionChecker (this);
  33326. const float wheelIncrementX = intAmountX * (1.0f / 256.0f);
  33327. const float wheelIncrementY = intAmountY * (1.0f / 256.0f);
  33328. int mx, my;
  33329. getMouseXYRelative (mx, my);
  33330. const MouseEvent me (mx, my,
  33331. ModifierKeys::getCurrentModifiers(),
  33332. this,
  33333. Time (time),
  33334. mx, my,
  33335. Time (time),
  33336. 0, false);
  33337. if (isCurrentlyBlockedByAnotherModalComponent())
  33338. {
  33339. // allow blocked mouse-events to go to global listeners..
  33340. for (int i = desktop.mouseListeners.size(); --i >= 0;)
  33341. {
  33342. ((MouseListener*) desktop.mouseListeners[i])->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  33343. if (deletionChecker.hasBeenDeleted())
  33344. return;
  33345. i = jmin (i, desktop.mouseListeners.size());
  33346. }
  33347. }
  33348. else
  33349. {
  33350. mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  33351. if (deletionChecker.hasBeenDeleted())
  33352. return;
  33353. for (int i = desktop.mouseListeners.size(); --i >= 0;)
  33354. {
  33355. ((MouseListener*) desktop.mouseListeners[i])->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  33356. if (deletionChecker.hasBeenDeleted())
  33357. return;
  33358. i = jmin (i, desktop.mouseListeners.size());
  33359. }
  33360. if (mouseListeners_ != 0)
  33361. {
  33362. for (int i = mouseListeners_->size(); --i >= 0;)
  33363. {
  33364. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  33365. if (deletionChecker.hasBeenDeleted())
  33366. return;
  33367. i = jmin (i, mouseListeners_->size());
  33368. }
  33369. }
  33370. const Component* p = parentComponent_;
  33371. while (p != 0)
  33372. {
  33373. const ComponentDeletionWatcher parentDeletionChecker (p);
  33374. for (int i = p->numDeepMouseListeners; --i >= 0;)
  33375. {
  33376. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  33377. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  33378. return;
  33379. i = jmin (i, p->numDeepMouseListeners);
  33380. }
  33381. p = p->parentComponent_;
  33382. }
  33383. sendFakeMouseMove();
  33384. }
  33385. }
  33386. void Component::sendFakeMouseMove() const
  33387. {
  33388. ComponentPeer* const peer = getPeer();
  33389. if (peer != 0)
  33390. peer->sendFakeMouseMove();
  33391. }
  33392. void Component::broughtToFront()
  33393. {
  33394. }
  33395. void Component::internalBroughtToFront()
  33396. {
  33397. if (isValidComponent())
  33398. {
  33399. if (flags.hasHeavyweightPeerFlag)
  33400. Desktop::getInstance().componentBroughtToFront (this);
  33401. const ComponentDeletionWatcher deletionChecker (this);
  33402. broughtToFront();
  33403. if (deletionChecker.hasBeenDeleted())
  33404. return;
  33405. if (componentListeners_ != 0)
  33406. {
  33407. for (int i = componentListeners_->size(); --i >= 0;)
  33408. {
  33409. ((ComponentListener*) componentListeners_->getUnchecked (i))
  33410. ->componentBroughtToFront (*this);
  33411. if (deletionChecker.hasBeenDeleted())
  33412. return;
  33413. i = jmin (i, componentListeners_->size());
  33414. }
  33415. }
  33416. // when brought to the front and there's a modal component blocking this one,
  33417. // we need to bring the modal one to the front instead..
  33418. Component* const cm = getCurrentlyModalComponent();
  33419. if (cm != 0 && cm->getTopLevelComponent() != getTopLevelComponent())
  33420. bringModalComponentToFront();
  33421. }
  33422. }
  33423. void Component::focusGained (FocusChangeType)
  33424. {
  33425. // base class does nothing
  33426. }
  33427. void Component::internalFocusGain (const FocusChangeType cause)
  33428. {
  33429. const ComponentDeletionWatcher deletionChecker (this);
  33430. focusGained (cause);
  33431. if (! deletionChecker.hasBeenDeleted())
  33432. internalChildFocusChange (cause);
  33433. }
  33434. void Component::focusLost (FocusChangeType)
  33435. {
  33436. // base class does nothing
  33437. }
  33438. void Component::internalFocusLoss (const FocusChangeType cause)
  33439. {
  33440. const ComponentDeletionWatcher deletionChecker (this);
  33441. focusLost (focusChangedDirectly);
  33442. if (! deletionChecker.hasBeenDeleted())
  33443. internalChildFocusChange (cause);
  33444. }
  33445. void Component::focusOfChildComponentChanged (FocusChangeType /*cause*/)
  33446. {
  33447. // base class does nothing
  33448. }
  33449. void Component::internalChildFocusChange (FocusChangeType cause)
  33450. {
  33451. const bool childIsNowFocused = hasKeyboardFocus (true);
  33452. if (flags.childCompFocusedFlag != childIsNowFocused)
  33453. {
  33454. flags.childCompFocusedFlag = childIsNowFocused;
  33455. const ComponentDeletionWatcher deletionChecker (this);
  33456. focusOfChildComponentChanged (cause);
  33457. if (deletionChecker.hasBeenDeleted())
  33458. return;
  33459. }
  33460. if (parentComponent_ != 0)
  33461. parentComponent_->internalChildFocusChange (cause);
  33462. }
  33463. bool Component::isEnabled() const throw()
  33464. {
  33465. return (! flags.isDisabledFlag)
  33466. && (parentComponent_ == 0 || parentComponent_->isEnabled());
  33467. }
  33468. void Component::setEnabled (const bool shouldBeEnabled)
  33469. {
  33470. if (flags.isDisabledFlag == shouldBeEnabled)
  33471. {
  33472. flags.isDisabledFlag = ! shouldBeEnabled;
  33473. // if any parent components are disabled, setting our flag won't make a difference,
  33474. // so no need to send a change message
  33475. if (parentComponent_ == 0 || parentComponent_->isEnabled())
  33476. sendEnablementChangeMessage();
  33477. }
  33478. }
  33479. void Component::sendEnablementChangeMessage()
  33480. {
  33481. const ComponentDeletionWatcher deletionChecker (this);
  33482. enablementChanged();
  33483. if (deletionChecker.hasBeenDeleted())
  33484. return;
  33485. for (int i = getNumChildComponents(); --i >= 0;)
  33486. {
  33487. Component* const c = getChildComponent (i);
  33488. if (c != 0)
  33489. {
  33490. c->sendEnablementChangeMessage();
  33491. if (deletionChecker.hasBeenDeleted())
  33492. return;
  33493. }
  33494. }
  33495. }
  33496. void Component::enablementChanged()
  33497. {
  33498. }
  33499. void Component::setWantsKeyboardFocus (const bool wantsFocus) throw()
  33500. {
  33501. flags.wantsFocusFlag = wantsFocus;
  33502. }
  33503. void Component::setMouseClickGrabsKeyboardFocus (const bool shouldGrabFocus)
  33504. {
  33505. flags.dontFocusOnMouseClickFlag = ! shouldGrabFocus;
  33506. }
  33507. bool Component::getMouseClickGrabsKeyboardFocus() const throw()
  33508. {
  33509. return ! flags.dontFocusOnMouseClickFlag;
  33510. }
  33511. bool Component::getWantsKeyboardFocus() const throw()
  33512. {
  33513. return flags.wantsFocusFlag && ! flags.isDisabledFlag;
  33514. }
  33515. void Component::setFocusContainer (const bool shouldBeFocusContainer) throw()
  33516. {
  33517. flags.isFocusContainerFlag = shouldBeFocusContainer;
  33518. }
  33519. bool Component::isFocusContainer() const throw()
  33520. {
  33521. return flags.isFocusContainerFlag;
  33522. }
  33523. int Component::getExplicitFocusOrder() const throw()
  33524. {
  33525. return properties ["_jexfo"];
  33526. }
  33527. void Component::setExplicitFocusOrder (const int newFocusOrderIndex) throw()
  33528. {
  33529. properties.set ("_jexfo", newFocusOrderIndex);
  33530. }
  33531. KeyboardFocusTraverser* Component::createFocusTraverser()
  33532. {
  33533. if (flags.isFocusContainerFlag || parentComponent_ == 0)
  33534. return new KeyboardFocusTraverser();
  33535. return parentComponent_->createFocusTraverser();
  33536. }
  33537. void Component::takeKeyboardFocus (const FocusChangeType cause)
  33538. {
  33539. // give the focus to this component
  33540. if (currentlyFocusedComponent != this)
  33541. {
  33542. JUCE_TRY
  33543. {
  33544. // get the focus onto our desktop window
  33545. ComponentPeer* const peer = getPeer();
  33546. if (peer != 0)
  33547. {
  33548. const ComponentDeletionWatcher deletionChecker (this);
  33549. peer->grabFocus();
  33550. if (peer->isFocused() && currentlyFocusedComponent != this)
  33551. {
  33552. Component* const componentLosingFocus = currentlyFocusedComponent;
  33553. currentlyFocusedComponent = this;
  33554. Desktop::getInstance().triggerFocusCallback();
  33555. // call this after setting currentlyFocusedComponent so that the one that's
  33556. // losing it has a chance to see where focus is going
  33557. if (componentLosingFocus->isValidComponent())
  33558. componentLosingFocus->internalFocusLoss (cause);
  33559. if (currentlyFocusedComponent == this)
  33560. {
  33561. focusGained (cause);
  33562. if (! deletionChecker.hasBeenDeleted())
  33563. internalChildFocusChange (cause);
  33564. }
  33565. }
  33566. }
  33567. }
  33568. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  33569. catch (const std::exception& e)
  33570. {
  33571. currentlyFocusedComponent = 0;
  33572. Desktop::getInstance().triggerFocusCallback();
  33573. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__);
  33574. }
  33575. catch (...)
  33576. {
  33577. currentlyFocusedComponent = 0;
  33578. Desktop::getInstance().triggerFocusCallback();
  33579. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__);
  33580. }
  33581. #endif
  33582. }
  33583. }
  33584. void Component::grabFocusInternal (const FocusChangeType cause, const bool canTryParent)
  33585. {
  33586. if (isShowing())
  33587. {
  33588. if (flags.wantsFocusFlag && (isEnabled() || parentComponent_ == 0))
  33589. {
  33590. takeKeyboardFocus (cause);
  33591. }
  33592. else
  33593. {
  33594. if (isParentOf (currentlyFocusedComponent)
  33595. && currentlyFocusedComponent->isShowing())
  33596. {
  33597. // do nothing if the focused component is actually a child of ours..
  33598. }
  33599. else
  33600. {
  33601. // find the default child component..
  33602. ScopedPointer <KeyboardFocusTraverser> traverser (createFocusTraverser());
  33603. if (traverser != 0)
  33604. {
  33605. Component* const defaultComp = traverser->getDefaultComponent (this);
  33606. traverser = 0;
  33607. if (defaultComp != 0)
  33608. {
  33609. defaultComp->grabFocusInternal (cause, false);
  33610. return;
  33611. }
  33612. }
  33613. if (canTryParent && parentComponent_ != 0)
  33614. {
  33615. // if no children want it and we're allowed to try our parent comp,
  33616. // then pass up to parent, which will try our siblings.
  33617. parentComponent_->grabFocusInternal (cause, true);
  33618. }
  33619. }
  33620. }
  33621. }
  33622. }
  33623. void Component::grabKeyboardFocus()
  33624. {
  33625. // if component methods are being called from threads other than the message
  33626. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  33627. checkMessageManagerIsLocked
  33628. grabFocusInternal (focusChangedDirectly);
  33629. }
  33630. void Component::moveKeyboardFocusToSibling (const bool moveToNext)
  33631. {
  33632. // if component methods are being called from threads other than the message
  33633. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  33634. checkMessageManagerIsLocked
  33635. if (parentComponent_ != 0)
  33636. {
  33637. ScopedPointer <KeyboardFocusTraverser> traverser (createFocusTraverser());
  33638. if (traverser != 0)
  33639. {
  33640. Component* const nextComp = moveToNext ? traverser->getNextComponent (this)
  33641. : traverser->getPreviousComponent (this);
  33642. traverser = 0;
  33643. if (nextComp != 0)
  33644. {
  33645. if (nextComp->isCurrentlyBlockedByAnotherModalComponent())
  33646. {
  33647. const ComponentDeletionWatcher deletionChecker (nextComp);
  33648. internalModalInputAttempt();
  33649. if (deletionChecker.hasBeenDeleted()
  33650. || nextComp->isCurrentlyBlockedByAnotherModalComponent())
  33651. return;
  33652. }
  33653. nextComp->grabFocusInternal (focusChangedByTabKey);
  33654. return;
  33655. }
  33656. }
  33657. parentComponent_->moveKeyboardFocusToSibling (moveToNext);
  33658. }
  33659. }
  33660. bool Component::hasKeyboardFocus (const bool trueIfChildIsFocused) const throw()
  33661. {
  33662. return (currentlyFocusedComponent == this)
  33663. || (trueIfChildIsFocused && isParentOf (currentlyFocusedComponent));
  33664. }
  33665. Component* JUCE_CALLTYPE Component::getCurrentlyFocusedComponent() throw()
  33666. {
  33667. return currentlyFocusedComponent;
  33668. }
  33669. void Component::giveAwayFocus()
  33670. {
  33671. // use a copy so we can clear the value before the call
  33672. Component* const componentLosingFocus = currentlyFocusedComponent;
  33673. currentlyFocusedComponent = 0;
  33674. Desktop::getInstance().triggerFocusCallback();
  33675. if (componentLosingFocus->isValidComponent())
  33676. componentLosingFocus->internalFocusLoss (focusChangedDirectly);
  33677. }
  33678. bool Component::isMouseOver() const throw()
  33679. {
  33680. return flags.mouseOverFlag;
  33681. }
  33682. bool Component::isMouseButtonDown() const throw()
  33683. {
  33684. return flags.draggingFlag;
  33685. }
  33686. bool Component::isMouseOverOrDragging() const throw()
  33687. {
  33688. return flags.mouseOverFlag || flags.draggingFlag;
  33689. }
  33690. bool JUCE_CALLTYPE Component::isMouseButtonDownAnywhere() throw()
  33691. {
  33692. return ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown();
  33693. }
  33694. void Component::getMouseXYRelative (int& mx, int& my) const throw()
  33695. {
  33696. Desktop::getMousePosition (mx, my);
  33697. globalPositionToRelative (mx, my);
  33698. mx += unboundedMouseOffsetX;
  33699. my += unboundedMouseOffsetY;
  33700. }
  33701. void Component::enableUnboundedMouseMovement (bool enable,
  33702. bool keepCursorVisibleUntilOffscreen) throw()
  33703. {
  33704. enable = enable && isMouseButtonDown();
  33705. isCursorVisibleUntilOffscreen = keepCursorVisibleUntilOffscreen;
  33706. if (enable != isUnboundedMouseModeOn)
  33707. {
  33708. if ((! enable) && ((! isCursorVisibleUntilOffscreen)
  33709. || unboundedMouseOffsetX != 0
  33710. || unboundedMouseOffsetY != 0))
  33711. {
  33712. // when released, return the mouse to within the component's bounds
  33713. int mx, my;
  33714. getMouseXYRelative (mx, my);
  33715. mx = jlimit (0, getWidth(), mx);
  33716. my = jlimit (0, getHeight(), my);
  33717. relativePositionToGlobal (mx, my);
  33718. Desktop::setMousePosition (mx, my);
  33719. }
  33720. isUnboundedMouseModeOn = enable;
  33721. unboundedMouseOffsetX = 0;
  33722. unboundedMouseOffsetY = 0;
  33723. internalUpdateMouseCursor (true);
  33724. }
  33725. }
  33726. Component* JUCE_CALLTYPE Component::getComponentUnderMouse() throw()
  33727. {
  33728. return componentUnderMouse;
  33729. }
  33730. const Rectangle<int> Component::getParentMonitorArea() const throw()
  33731. {
  33732. int centreX = getWidth() / 2;
  33733. int centreY = getHeight() / 2;
  33734. relativePositionToGlobal (centreX, centreY);
  33735. return Desktop::getInstance().getMonitorAreaContaining (centreX, centreY);
  33736. }
  33737. void Component::addKeyListener (KeyListener* const newListener) throw()
  33738. {
  33739. if (keyListeners_ == 0)
  33740. keyListeners_ = new VoidArray();
  33741. keyListeners_->addIfNotAlreadyThere (newListener);
  33742. }
  33743. void Component::removeKeyListener (KeyListener* const listenerToRemove) throw()
  33744. {
  33745. if (keyListeners_ != 0)
  33746. keyListeners_->removeValue (listenerToRemove);
  33747. }
  33748. bool Component::keyPressed (const KeyPress&)
  33749. {
  33750. return false;
  33751. }
  33752. bool Component::keyStateChanged (const bool /*isKeyDown*/)
  33753. {
  33754. return false;
  33755. }
  33756. void Component::modifierKeysChanged (const ModifierKeys& modifiers)
  33757. {
  33758. if (parentComponent_ != 0)
  33759. parentComponent_->modifierKeysChanged (modifiers);
  33760. }
  33761. void Component::internalModifierKeysChanged()
  33762. {
  33763. sendFakeMouseMove();
  33764. modifierKeysChanged (ModifierKeys::getCurrentModifiers());
  33765. }
  33766. ComponentPeer* Component::getPeer() const throw()
  33767. {
  33768. if (flags.hasHeavyweightPeerFlag)
  33769. return ComponentPeer::getPeerFor (this);
  33770. else if (parentComponent_ != 0)
  33771. return parentComponent_->getPeer();
  33772. else
  33773. return 0;
  33774. }
  33775. ComponentDeletionWatcher::ComponentDeletionWatcher (const Component* const componentToWatch_) throw()
  33776. : componentToWatch (componentToWatch_),
  33777. componentUID (componentToWatch_->getComponentUID())
  33778. {
  33779. // not possible to check on an already-deleted object..
  33780. jassert (componentToWatch_->isValidComponent());
  33781. }
  33782. ComponentDeletionWatcher::~ComponentDeletionWatcher() throw() {}
  33783. bool ComponentDeletionWatcher::hasBeenDeleted() const throw()
  33784. {
  33785. return ! (componentToWatch->isValidComponent()
  33786. && componentToWatch->getComponentUID() == componentUID);
  33787. }
  33788. const Component* ComponentDeletionWatcher::getComponent() const throw()
  33789. {
  33790. return hasBeenDeleted() ? 0 : componentToWatch;
  33791. }
  33792. END_JUCE_NAMESPACE
  33793. /*** End of inlined file: juce_Component.cpp ***/
  33794. /*** Start of inlined file: juce_ComponentListener.cpp ***/
  33795. BEGIN_JUCE_NAMESPACE
  33796. void ComponentListener::componentMovedOrResized (Component&, bool, bool)
  33797. {
  33798. }
  33799. void ComponentListener::componentBroughtToFront (Component&)
  33800. {
  33801. }
  33802. void ComponentListener::componentVisibilityChanged (Component&)
  33803. {
  33804. }
  33805. void ComponentListener::componentChildrenChanged (Component&)
  33806. {
  33807. }
  33808. void ComponentListener::componentParentHierarchyChanged (Component&)
  33809. {
  33810. }
  33811. void ComponentListener::componentNameChanged (Component&)
  33812. {
  33813. }
  33814. END_JUCE_NAMESPACE
  33815. /*** End of inlined file: juce_ComponentListener.cpp ***/
  33816. /*** Start of inlined file: juce_Desktop.cpp ***/
  33817. BEGIN_JUCE_NAMESPACE
  33818. Desktop::Desktop() throw()
  33819. : lastFakeMouseMoveX (0),
  33820. lastFakeMouseMoveY (0),
  33821. mouseClickCounter (0),
  33822. mouseMovedSignificantlySincePressed (false),
  33823. kioskModeComponent (0)
  33824. {
  33825. zerostruct (mouseDowns);
  33826. refreshMonitorSizes();
  33827. }
  33828. Desktop::~Desktop() throw()
  33829. {
  33830. jassert (instance == this);
  33831. instance = 0;
  33832. // doh! If you don't delete all your windows before exiting, you're going to
  33833. // be leaking memory!
  33834. jassert (desktopComponents.size() == 0);
  33835. }
  33836. Desktop& JUCE_CALLTYPE Desktop::getInstance() throw()
  33837. {
  33838. if (instance == 0)
  33839. instance = new Desktop();
  33840. return *instance;
  33841. }
  33842. Desktop* Desktop::instance = 0;
  33843. extern void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords,
  33844. const bool clipToWorkArea);
  33845. void Desktop::refreshMonitorSizes() throw()
  33846. {
  33847. const Array <Rectangle<int> > oldClipped (monitorCoordsClipped);
  33848. const Array <Rectangle<int> > oldUnclipped (monitorCoordsUnclipped);
  33849. monitorCoordsClipped.clear();
  33850. monitorCoordsUnclipped.clear();
  33851. juce_updateMultiMonitorInfo (monitorCoordsClipped, true);
  33852. juce_updateMultiMonitorInfo (monitorCoordsUnclipped, false);
  33853. jassert (monitorCoordsClipped.size() > 0
  33854. && monitorCoordsClipped.size() == monitorCoordsUnclipped.size());
  33855. if (oldClipped != monitorCoordsClipped
  33856. || oldUnclipped != monitorCoordsUnclipped)
  33857. {
  33858. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  33859. {
  33860. ComponentPeer* const p = ComponentPeer::getPeer (i);
  33861. if (p != 0)
  33862. p->handleScreenSizeChange();
  33863. }
  33864. }
  33865. }
  33866. int Desktop::getNumDisplayMonitors() const throw()
  33867. {
  33868. return monitorCoordsClipped.size();
  33869. }
  33870. const Rectangle<int> Desktop::getDisplayMonitorCoordinates (const int index, const bool clippedToWorkArea) const throw()
  33871. {
  33872. return clippedToWorkArea ? monitorCoordsClipped [index]
  33873. : monitorCoordsUnclipped [index];
  33874. }
  33875. const RectangleList Desktop::getAllMonitorDisplayAreas (const bool clippedToWorkArea) const throw()
  33876. {
  33877. RectangleList rl;
  33878. for (int i = 0; i < getNumDisplayMonitors(); ++i)
  33879. rl.addWithoutMerging (getDisplayMonitorCoordinates (i, clippedToWorkArea));
  33880. return rl;
  33881. }
  33882. const Rectangle<int> Desktop::getMainMonitorArea (const bool clippedToWorkArea) const throw()
  33883. {
  33884. return getDisplayMonitorCoordinates (0, clippedToWorkArea);
  33885. }
  33886. const Rectangle<int> Desktop::getMonitorAreaContaining (int cx, int cy, const bool clippedToWorkArea) const throw()
  33887. {
  33888. Rectangle<int> best (getMainMonitorArea (clippedToWorkArea));
  33889. double bestDistance = 1.0e10;
  33890. for (int i = getNumDisplayMonitors(); --i >= 0;)
  33891. {
  33892. const Rectangle<int> rect (getDisplayMonitorCoordinates (i, clippedToWorkArea));
  33893. if (rect.contains (cx, cy))
  33894. return rect;
  33895. const double distance = juce_hypot ((double) (rect.getCentreX() - cx),
  33896. (double) (rect.getCentreY() - cy));
  33897. if (distance < bestDistance)
  33898. {
  33899. bestDistance = distance;
  33900. best = rect;
  33901. }
  33902. }
  33903. return best;
  33904. }
  33905. int Desktop::getNumComponents() const throw()
  33906. {
  33907. return desktopComponents.size();
  33908. }
  33909. Component* Desktop::getComponent (const int index) const throw()
  33910. {
  33911. return desktopComponents [index];
  33912. }
  33913. Component* Desktop::findComponentAt (const int screenX,
  33914. const int screenY) const
  33915. {
  33916. for (int i = desktopComponents.size(); --i >= 0;)
  33917. {
  33918. Component* const c = desktopComponents.getUnchecked(i);
  33919. int x = screenX, y = screenY;
  33920. c->globalPositionToRelative (x, y);
  33921. if (c->contains (x, y))
  33922. return c->getComponentAt (x, y);
  33923. }
  33924. return 0;
  33925. }
  33926. void Desktop::addDesktopComponent (Component* const c) throw()
  33927. {
  33928. jassert (c != 0);
  33929. jassert (! desktopComponents.contains (c));
  33930. desktopComponents.addIfNotAlreadyThere (c);
  33931. }
  33932. void Desktop::removeDesktopComponent (Component* const c) throw()
  33933. {
  33934. desktopComponents.removeValue (c);
  33935. }
  33936. void Desktop::componentBroughtToFront (Component* const c) throw()
  33937. {
  33938. const int index = desktopComponents.indexOf (c);
  33939. jassert (index >= 0);
  33940. if (index >= 0)
  33941. {
  33942. int newIndex = -1;
  33943. if (! c->isAlwaysOnTop())
  33944. {
  33945. newIndex = desktopComponents.size();
  33946. while (newIndex > 0 && desktopComponents.getUnchecked (newIndex - 1)->isAlwaysOnTop())
  33947. --newIndex;
  33948. --newIndex;
  33949. }
  33950. desktopComponents.move (index, newIndex);
  33951. }
  33952. }
  33953. void Desktop::getLastMouseDownPosition (int& x, int& y) throw()
  33954. {
  33955. const Desktop& d = getInstance();
  33956. x = d.mouseDowns[0].position.getX();
  33957. y = d.mouseDowns[0].position.getY();
  33958. }
  33959. int Desktop::getMouseButtonClickCounter() throw()
  33960. {
  33961. return getInstance().mouseClickCounter;
  33962. }
  33963. void Desktop::incrementMouseClickCounter() throw()
  33964. {
  33965. ++mouseClickCounter;
  33966. }
  33967. const Time Desktop::getLastMouseDownTime() const throw()
  33968. {
  33969. return Time (mouseDowns[0].time);
  33970. }
  33971. void Desktop::registerMouseDown (const Point<int>& position, int64 time, Component* component) throw()
  33972. {
  33973. for (int i = numElementsInArray (mouseDowns); --i > 0;)
  33974. mouseDowns[i] = mouseDowns[i - 1];
  33975. mouseDowns[0].position = position;
  33976. mouseDowns[0].time = time;
  33977. mouseDowns[0].component = component;
  33978. mouseMovedSignificantlySincePressed = false;
  33979. }
  33980. void Desktop::registerMouseDrag (const Point<int>& position) throw()
  33981. {
  33982. mouseMovedSignificantlySincePressed
  33983. = mouseMovedSignificantlySincePressed
  33984. || abs (mouseDowns[0].position.getX() - position.getX()) >= 4
  33985. || abs (mouseDowns[0].position.getY() - position.getY()) >= 4;
  33986. }
  33987. int Desktop::getNumberOfMultipleClicks() const throw()
  33988. {
  33989. int numClicks = 0;
  33990. if (mouseDowns[0].time != 0)
  33991. {
  33992. if (! mouseMovedSignificantlySincePressed)
  33993. ++numClicks;
  33994. for (int i = 1; i < numElementsInArray (mouseDowns); ++i)
  33995. {
  33996. if (mouseDowns[0].time - mouseDowns[i].time
  33997. < (int) (MouseEvent::getDoubleClickTimeout() * (1.0 + 0.25 * (i - 1)))
  33998. && abs (mouseDowns[0].position.getX() - mouseDowns[i].position.getX()) < 8
  33999. && abs (mouseDowns[0].position.getY() - mouseDowns[i].position.getY()) < 8
  34000. && mouseDowns[0].component == mouseDowns[i].component)
  34001. {
  34002. ++numClicks;
  34003. }
  34004. else
  34005. {
  34006. break;
  34007. }
  34008. }
  34009. }
  34010. return numClicks;
  34011. }
  34012. void Desktop::addGlobalMouseListener (MouseListener* const listener) throw()
  34013. {
  34014. jassert (listener != 0);
  34015. if (listener != 0)
  34016. {
  34017. mouseListeners.add (listener);
  34018. resetTimer();
  34019. }
  34020. }
  34021. void Desktop::removeGlobalMouseListener (MouseListener* const listener) throw()
  34022. {
  34023. mouseListeners.removeValue (listener);
  34024. resetTimer();
  34025. }
  34026. void Desktop::addFocusChangeListener (FocusChangeListener* const listener) throw()
  34027. {
  34028. jassert (listener != 0);
  34029. if (listener != 0)
  34030. focusListeners.add (listener);
  34031. }
  34032. void Desktop::removeFocusChangeListener (FocusChangeListener* const listener) throw()
  34033. {
  34034. focusListeners.removeValue (listener);
  34035. }
  34036. void Desktop::triggerFocusCallback() throw()
  34037. {
  34038. triggerAsyncUpdate();
  34039. }
  34040. void Desktop::handleAsyncUpdate()
  34041. {
  34042. for (int i = focusListeners.size(); --i >= 0;)
  34043. {
  34044. ((FocusChangeListener*) focusListeners.getUnchecked (i))->globalFocusChanged (Component::getCurrentlyFocusedComponent());
  34045. i = jmin (i, focusListeners.size());
  34046. }
  34047. }
  34048. void Desktop::timerCallback()
  34049. {
  34050. int x, y;
  34051. getMousePosition (x, y);
  34052. if (lastFakeMouseMoveX != x || lastFakeMouseMoveY != y)
  34053. sendMouseMove();
  34054. }
  34055. void Desktop::sendMouseMove()
  34056. {
  34057. if (mouseListeners.size() > 0)
  34058. {
  34059. startTimer (20);
  34060. int x, y;
  34061. getMousePosition (x, y);
  34062. lastFakeMouseMoveX = x;
  34063. lastFakeMouseMoveY = y;
  34064. Component* const target = findComponentAt (x, y);
  34065. if (target != 0)
  34066. {
  34067. target->globalPositionToRelative (x, y);
  34068. ComponentDeletionWatcher deletionChecker (target);
  34069. const MouseEvent me (x, y,
  34070. ModifierKeys::getCurrentModifiers(),
  34071. target,
  34072. Time::getCurrentTime(),
  34073. x, y,
  34074. Time::getCurrentTime(),
  34075. 0, false);
  34076. for (int i = mouseListeners.size(); --i >= 0;)
  34077. {
  34078. if (ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown())
  34079. ((MouseListener*) mouseListeners[i])->mouseDrag (me);
  34080. else
  34081. ((MouseListener*) mouseListeners[i])->mouseMove (me);
  34082. if (deletionChecker.hasBeenDeleted())
  34083. return;
  34084. i = jmin (i, mouseListeners.size());
  34085. }
  34086. }
  34087. }
  34088. }
  34089. void Desktop::resetTimer() throw()
  34090. {
  34091. if (mouseListeners.size() == 0)
  34092. stopTimer();
  34093. else
  34094. startTimer (100);
  34095. getMousePosition (lastFakeMouseMoveX, lastFakeMouseMoveY);
  34096. }
  34097. extern void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars);
  34098. void Desktop::setKioskModeComponent (Component* componentToUse, const bool allowMenusAndBars)
  34099. {
  34100. if (kioskModeComponent != componentToUse)
  34101. {
  34102. // agh! Don't delete a component without first stopping it being the kiosk comp
  34103. jassert (kioskModeComponent == 0 || kioskModeComponent->isValidComponent());
  34104. // agh! Don't remove a component from the desktop if it's the kiosk comp!
  34105. jassert (kioskModeComponent == 0 || kioskModeComponent->isOnDesktop());
  34106. if (kioskModeComponent->isValidComponent())
  34107. {
  34108. juce_setKioskComponent (kioskModeComponent, false, allowMenusAndBars);
  34109. kioskModeComponent->setBounds (kioskComponentOriginalBounds);
  34110. }
  34111. kioskModeComponent = componentToUse;
  34112. if (kioskModeComponent != 0)
  34113. {
  34114. jassert (kioskModeComponent->isValidComponent());
  34115. // Only components that are already on the desktop can be put into kiosk mode!
  34116. jassert (kioskModeComponent->isOnDesktop());
  34117. kioskComponentOriginalBounds = kioskModeComponent->getBounds();
  34118. juce_setKioskComponent (kioskModeComponent, true, allowMenusAndBars);
  34119. }
  34120. }
  34121. }
  34122. END_JUCE_NAMESPACE
  34123. /*** End of inlined file: juce_Desktop.cpp ***/
  34124. /*** Start of inlined file: juce_ArrowButton.cpp ***/
  34125. BEGIN_JUCE_NAMESPACE
  34126. ArrowButton::ArrowButton (const String& name,
  34127. float arrowDirectionInRadians,
  34128. const Colour& arrowColour)
  34129. : Button (name),
  34130. colour (arrowColour)
  34131. {
  34132. path.lineTo (0.0f, 1.0f);
  34133. path.lineTo (1.0f, 0.5f);
  34134. path.closeSubPath();
  34135. path.applyTransform (AffineTransform::rotation (float_Pi * 2.0f * arrowDirectionInRadians,
  34136. 0.5f, 0.5f));
  34137. setComponentEffect (&shadow);
  34138. buttonStateChanged();
  34139. }
  34140. ArrowButton::~ArrowButton()
  34141. {
  34142. }
  34143. void ArrowButton::paintButton (Graphics& g,
  34144. bool /*isMouseOverButton*/,
  34145. bool /*isButtonDown*/)
  34146. {
  34147. g.setColour (colour);
  34148. g.fillPath (path, path.getTransformToScaleToFit ((float) offset,
  34149. (float) offset,
  34150. (float) (getWidth() - 3),
  34151. (float) (getHeight() - 3),
  34152. false));
  34153. }
  34154. void ArrowButton::buttonStateChanged()
  34155. {
  34156. offset = (isDown()) ? 1 : 0;
  34157. shadow.setShadowProperties ((isDown()) ? 1.2f : 3.0f,
  34158. 0.3f, -1, 0);
  34159. }
  34160. END_JUCE_NAMESPACE
  34161. /*** End of inlined file: juce_ArrowButton.cpp ***/
  34162. /*** Start of inlined file: juce_Button.cpp ***/
  34163. BEGIN_JUCE_NAMESPACE
  34164. class Button::RepeatTimer : public Timer
  34165. {
  34166. public:
  34167. RepeatTimer (Button& owner_) : owner (owner_) {}
  34168. void timerCallback() { owner.repeatTimerCallback(); }
  34169. juce_UseDebuggingNewOperator
  34170. private:
  34171. Button& owner;
  34172. RepeatTimer (const RepeatTimer&);
  34173. RepeatTimer& operator= (const RepeatTimer&);
  34174. };
  34175. Button::Button (const String& name)
  34176. : Component (name),
  34177. keySource (0),
  34178. text (name),
  34179. buttonPressTime (0),
  34180. lastTimeCallbackTime (0),
  34181. commandManagerToUse (0),
  34182. autoRepeatDelay (-1),
  34183. autoRepeatSpeed (0),
  34184. autoRepeatMinimumDelay (-1),
  34185. radioGroupId (0),
  34186. commandID (0),
  34187. connectedEdgeFlags (0),
  34188. buttonState (buttonNormal),
  34189. lastToggleState (false),
  34190. clickTogglesState (false),
  34191. needsToRelease (false),
  34192. needsRepainting (false),
  34193. isKeyDown (false),
  34194. triggerOnMouseDown (false),
  34195. generateTooltip (false)
  34196. {
  34197. setWantsKeyboardFocus (true);
  34198. isOn.addListener (this);
  34199. }
  34200. Button::~Button()
  34201. {
  34202. isOn.removeListener (this);
  34203. if (commandManagerToUse != 0)
  34204. commandManagerToUse->removeListener (this);
  34205. repeatTimer = 0;
  34206. clearShortcuts();
  34207. }
  34208. void Button::setButtonText (const String& newText)
  34209. {
  34210. if (text != newText)
  34211. {
  34212. text = newText;
  34213. repaint();
  34214. }
  34215. }
  34216. void Button::setTooltip (const String& newTooltip)
  34217. {
  34218. SettableTooltipClient::setTooltip (newTooltip);
  34219. generateTooltip = false;
  34220. }
  34221. const String Button::getTooltip()
  34222. {
  34223. if (generateTooltip && commandManagerToUse != 0 && commandID != 0)
  34224. {
  34225. String tt (commandManagerToUse->getDescriptionOfCommand (commandID));
  34226. Array <KeyPress> keyPresses (commandManagerToUse->getKeyMappings()->getKeyPressesAssignedToCommand (commandID));
  34227. for (int i = 0; i < keyPresses.size(); ++i)
  34228. {
  34229. const String key (keyPresses.getReference(i).getTextDescription());
  34230. tt << " [";
  34231. if (key.length() == 1)
  34232. tt << TRANS("shortcut") << ": '" << key << "']";
  34233. else
  34234. tt << key << ']';
  34235. }
  34236. return tt;
  34237. }
  34238. return SettableTooltipClient::getTooltip();
  34239. }
  34240. void Button::setConnectedEdges (const int connectedEdgeFlags_)
  34241. {
  34242. if (connectedEdgeFlags != connectedEdgeFlags_)
  34243. {
  34244. connectedEdgeFlags = connectedEdgeFlags_;
  34245. repaint();
  34246. }
  34247. }
  34248. void Button::setToggleState (const bool shouldBeOn,
  34249. const bool sendChangeNotification)
  34250. {
  34251. if (shouldBeOn != lastToggleState)
  34252. {
  34253. const ComponentDeletionWatcher deletionWatcher (this);
  34254. isOn = shouldBeOn;
  34255. lastToggleState = shouldBeOn;
  34256. repaint();
  34257. if (sendChangeNotification)
  34258. sendClickMessage (ModifierKeys());
  34259. if ((! deletionWatcher.hasBeenDeleted()) && lastToggleState)
  34260. turnOffOtherButtonsInGroup (sendChangeNotification);
  34261. }
  34262. }
  34263. void Button::setClickingTogglesState (const bool shouldToggle) throw()
  34264. {
  34265. clickTogglesState = shouldToggle;
  34266. // if you've got clickTogglesState turned on, you shouldn't also connect the button
  34267. // up to be a command invoker. Instead, your command handler must flip the state of whatever
  34268. // it is that this button represents, and the button will update its state to reflect this
  34269. // in the applicationCommandListChanged() method.
  34270. jassert (commandManagerToUse == 0 || ! clickTogglesState);
  34271. }
  34272. bool Button::getClickingTogglesState() const throw()
  34273. {
  34274. return clickTogglesState;
  34275. }
  34276. void Button::valueChanged (Value& value)
  34277. {
  34278. if (value.refersToSameSourceAs (isOn))
  34279. setToggleState (isOn.getValue(), true);
  34280. }
  34281. void Button::setRadioGroupId (const int newGroupId)
  34282. {
  34283. if (radioGroupId != newGroupId)
  34284. {
  34285. radioGroupId = newGroupId;
  34286. if (lastToggleState)
  34287. turnOffOtherButtonsInGroup (true);
  34288. }
  34289. }
  34290. void Button::turnOffOtherButtonsInGroup (const bool sendChangeNotification)
  34291. {
  34292. Component* const p = getParentComponent();
  34293. if (p != 0 && radioGroupId != 0)
  34294. {
  34295. const ComponentDeletionWatcher deletionWatcher (this);
  34296. for (int i = p->getNumChildComponents(); --i >= 0;)
  34297. {
  34298. Component* const c = p->getChildComponent (i);
  34299. if (c != this)
  34300. {
  34301. Button* const b = dynamic_cast <Button*> (c);
  34302. if (b != 0 && b->getRadioGroupId() == radioGroupId)
  34303. {
  34304. b->setToggleState (false, sendChangeNotification);
  34305. if (deletionWatcher.hasBeenDeleted())
  34306. return;
  34307. }
  34308. }
  34309. }
  34310. }
  34311. }
  34312. void Button::enablementChanged()
  34313. {
  34314. updateState (0);
  34315. repaint();
  34316. }
  34317. Button::ButtonState Button::updateState (const MouseEvent* const e)
  34318. {
  34319. ButtonState state = buttonNormal;
  34320. if (isEnabled() && isVisible() && ! isCurrentlyBlockedByAnotherModalComponent())
  34321. {
  34322. int mx, my;
  34323. if (e == 0)
  34324. {
  34325. getMouseXYRelative (mx, my);
  34326. }
  34327. else
  34328. {
  34329. const MouseEvent e2 (e->getEventRelativeTo (this));
  34330. mx = e2.x;
  34331. my = e2.y;
  34332. }
  34333. const bool over = reallyContains (mx, my, true);
  34334. const bool down = isMouseButtonDown();
  34335. if ((down && (over || (triggerOnMouseDown && buttonState == buttonDown))) || isKeyDown)
  34336. state = buttonDown;
  34337. else if (over)
  34338. state = buttonOver;
  34339. }
  34340. setState (state);
  34341. return state;
  34342. }
  34343. void Button::setState (const ButtonState newState)
  34344. {
  34345. if (buttonState != newState)
  34346. {
  34347. buttonState = newState;
  34348. repaint();
  34349. if (buttonState == buttonDown)
  34350. {
  34351. buttonPressTime = Time::getApproximateMillisecondCounter();
  34352. lastTimeCallbackTime = buttonPressTime;
  34353. }
  34354. sendStateMessage();
  34355. }
  34356. }
  34357. bool Button::isDown() const throw()
  34358. {
  34359. return buttonState == buttonDown;
  34360. }
  34361. bool Button::isOver() const throw()
  34362. {
  34363. return buttonState != buttonNormal;
  34364. }
  34365. void Button::buttonStateChanged()
  34366. {
  34367. }
  34368. uint32 Button::getMillisecondsSinceButtonDown() const throw()
  34369. {
  34370. const uint32 now = Time::getApproximateMillisecondCounter();
  34371. return now > buttonPressTime ? now - buttonPressTime : 0;
  34372. }
  34373. void Button::setTriggeredOnMouseDown (const bool isTriggeredOnMouseDown) throw()
  34374. {
  34375. triggerOnMouseDown = isTriggeredOnMouseDown;
  34376. }
  34377. void Button::clicked()
  34378. {
  34379. }
  34380. void Button::clicked (const ModifierKeys& /*modifiers*/)
  34381. {
  34382. clicked();
  34383. }
  34384. static const int clickMessageId = 0x2f3f4f99;
  34385. void Button::triggerClick()
  34386. {
  34387. postCommandMessage (clickMessageId);
  34388. }
  34389. void Button::internalClickCallback (const ModifierKeys& modifiers)
  34390. {
  34391. if (clickTogglesState)
  34392. setToggleState ((radioGroupId != 0) || ! lastToggleState, false);
  34393. sendClickMessage (modifiers);
  34394. }
  34395. void Button::flashButtonState()
  34396. {
  34397. if (isEnabled())
  34398. {
  34399. needsToRelease = true;
  34400. setState (buttonDown);
  34401. getRepeatTimer().startTimer (100);
  34402. }
  34403. }
  34404. void Button::handleCommandMessage (int commandId)
  34405. {
  34406. if (commandId == clickMessageId)
  34407. {
  34408. if (isEnabled())
  34409. {
  34410. flashButtonState();
  34411. internalClickCallback (ModifierKeys::getCurrentModifiers());
  34412. }
  34413. }
  34414. else
  34415. {
  34416. Component::handleCommandMessage (commandId);
  34417. }
  34418. }
  34419. void Button::addButtonListener (ButtonListener* const newListener)
  34420. {
  34421. jassert (newListener != 0);
  34422. jassert (! buttonListeners.contains (newListener)); // trying to add a listener to the list twice!
  34423. if (newListener != 0)
  34424. buttonListeners.add (newListener);
  34425. }
  34426. void Button::removeButtonListener (ButtonListener* const listener)
  34427. {
  34428. jassert (buttonListeners.contains (listener)); // trying to remove a listener that isn't on the list!
  34429. buttonListeners.removeValue (listener);
  34430. }
  34431. void Button::sendClickMessage (const ModifierKeys& modifiers)
  34432. {
  34433. const ComponentDeletionWatcher cdw (this);
  34434. if (commandManagerToUse != 0 && commandID != 0)
  34435. {
  34436. ApplicationCommandTarget::InvocationInfo info (commandID);
  34437. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromButton;
  34438. info.originatingComponent = this;
  34439. commandManagerToUse->invoke (info, true);
  34440. }
  34441. clicked (modifiers);
  34442. if (! cdw.hasBeenDeleted())
  34443. {
  34444. for (int i = buttonListeners.size(); --i >= 0;)
  34445. {
  34446. ButtonListener* const bl = (ButtonListener*) buttonListeners[i];
  34447. if (bl != 0)
  34448. {
  34449. bl->buttonClicked (this);
  34450. if (cdw.hasBeenDeleted())
  34451. return;
  34452. }
  34453. }
  34454. }
  34455. }
  34456. void Button::sendStateMessage()
  34457. {
  34458. const ComponentDeletionWatcher cdw (this);
  34459. buttonStateChanged();
  34460. if (cdw.hasBeenDeleted())
  34461. return;
  34462. for (int i = buttonListeners.size(); --i >= 0;)
  34463. {
  34464. ButtonListener* const bl = (ButtonListener*) buttonListeners[i];
  34465. if (bl != 0)
  34466. {
  34467. bl->buttonStateChanged (this);
  34468. if (cdw.hasBeenDeleted())
  34469. return;
  34470. }
  34471. }
  34472. }
  34473. void Button::paint (Graphics& g)
  34474. {
  34475. if (needsToRelease && isEnabled())
  34476. {
  34477. needsToRelease = false;
  34478. needsRepainting = true;
  34479. }
  34480. paintButton (g, isOver(), isDown());
  34481. }
  34482. void Button::mouseEnter (const MouseEvent& e)
  34483. {
  34484. updateState (&e);
  34485. }
  34486. void Button::mouseExit (const MouseEvent& e)
  34487. {
  34488. updateState (&e);
  34489. }
  34490. void Button::mouseDown (const MouseEvent& e)
  34491. {
  34492. updateState (&e);
  34493. if (isDown())
  34494. {
  34495. if (autoRepeatDelay >= 0)
  34496. getRepeatTimer().startTimer (autoRepeatDelay);
  34497. if (triggerOnMouseDown)
  34498. internalClickCallback (e.mods);
  34499. }
  34500. }
  34501. void Button::mouseUp (const MouseEvent& e)
  34502. {
  34503. const bool wasDown = isDown();
  34504. updateState (&e);
  34505. if (wasDown && isOver() && ! triggerOnMouseDown)
  34506. internalClickCallback (e.mods);
  34507. }
  34508. void Button::mouseDrag (const MouseEvent& e)
  34509. {
  34510. const ButtonState oldState = buttonState;
  34511. updateState (&e);
  34512. if (autoRepeatDelay >= 0 && buttonState != oldState && isDown())
  34513. getRepeatTimer().startTimer (autoRepeatSpeed);
  34514. }
  34515. void Button::focusGained (FocusChangeType)
  34516. {
  34517. updateState (0);
  34518. repaint();
  34519. }
  34520. void Button::focusLost (FocusChangeType)
  34521. {
  34522. updateState (0);
  34523. repaint();
  34524. }
  34525. void Button::setVisible (bool shouldBeVisible)
  34526. {
  34527. if (shouldBeVisible != isVisible())
  34528. {
  34529. Component::setVisible (shouldBeVisible);
  34530. if (! shouldBeVisible)
  34531. needsToRelease = false;
  34532. updateState (0);
  34533. }
  34534. else
  34535. {
  34536. Component::setVisible (shouldBeVisible);
  34537. }
  34538. }
  34539. void Button::parentHierarchyChanged()
  34540. {
  34541. Component* const newKeySource = (shortcuts.size() == 0) ? 0 : getTopLevelComponent();
  34542. if (newKeySource != keySource)
  34543. {
  34544. if (keySource->isValidComponent())
  34545. keySource->removeKeyListener (this);
  34546. keySource = newKeySource;
  34547. if (keySource->isValidComponent())
  34548. keySource->addKeyListener (this);
  34549. }
  34550. }
  34551. void Button::setCommandToTrigger (ApplicationCommandManager* const commandManagerToUse_,
  34552. const int commandID_,
  34553. const bool generateTooltip_)
  34554. {
  34555. commandID = commandID_;
  34556. generateTooltip = generateTooltip_;
  34557. if (commandManagerToUse != commandManagerToUse_)
  34558. {
  34559. if (commandManagerToUse != 0)
  34560. commandManagerToUse->removeListener (this);
  34561. commandManagerToUse = commandManagerToUse_;
  34562. if (commandManagerToUse != 0)
  34563. commandManagerToUse->addListener (this);
  34564. // if you've got clickTogglesState turned on, you shouldn't also connect the button
  34565. // up to be a command invoker. Instead, your command handler must flip the state of whatever
  34566. // it is that this button represents, and the button will update its state to reflect this
  34567. // in the applicationCommandListChanged() method.
  34568. jassert (commandManagerToUse == 0 || ! clickTogglesState);
  34569. }
  34570. if (commandManagerToUse != 0)
  34571. applicationCommandListChanged();
  34572. else
  34573. setEnabled (true);
  34574. }
  34575. void Button::applicationCommandInvoked (const ApplicationCommandTarget::InvocationInfo& info)
  34576. {
  34577. if (info.commandID == commandID
  34578. && (info.commandFlags & ApplicationCommandInfo::dontTriggerVisualFeedback) == 0)
  34579. {
  34580. flashButtonState();
  34581. }
  34582. }
  34583. void Button::applicationCommandListChanged()
  34584. {
  34585. if (commandManagerToUse != 0)
  34586. {
  34587. ApplicationCommandInfo info (0);
  34588. ApplicationCommandTarget* const target = commandManagerToUse->getTargetForCommand (commandID, info);
  34589. setEnabled (target != 0 && (info.flags & ApplicationCommandInfo::isDisabled) == 0);
  34590. if (target != 0)
  34591. setToggleState ((info.flags & ApplicationCommandInfo::isTicked) != 0, false);
  34592. }
  34593. }
  34594. void Button::addShortcut (const KeyPress& key)
  34595. {
  34596. if (key.isValid())
  34597. {
  34598. jassert (! isRegisteredForShortcut (key)); // already registered!
  34599. shortcuts.add (key);
  34600. parentHierarchyChanged();
  34601. }
  34602. }
  34603. void Button::clearShortcuts()
  34604. {
  34605. shortcuts.clear();
  34606. parentHierarchyChanged();
  34607. }
  34608. bool Button::isShortcutPressed() const
  34609. {
  34610. if (! isCurrentlyBlockedByAnotherModalComponent())
  34611. {
  34612. for (int i = shortcuts.size(); --i >= 0;)
  34613. if (shortcuts.getReference(i).isCurrentlyDown())
  34614. return true;
  34615. }
  34616. return false;
  34617. }
  34618. bool Button::isRegisteredForShortcut (const KeyPress& key) const
  34619. {
  34620. for (int i = shortcuts.size(); --i >= 0;)
  34621. if (key == shortcuts.getReference(i))
  34622. return true;
  34623. return false;
  34624. }
  34625. bool Button::keyStateChanged (const bool, Component*)
  34626. {
  34627. if (! isEnabled())
  34628. return false;
  34629. const bool wasDown = isKeyDown;
  34630. isKeyDown = isShortcutPressed();
  34631. if (autoRepeatDelay >= 0 && (isKeyDown && ! wasDown))
  34632. getRepeatTimer().startTimer (autoRepeatDelay);
  34633. updateState (0);
  34634. if (isEnabled() && wasDown && ! isKeyDown)
  34635. {
  34636. internalClickCallback (ModifierKeys::getCurrentModifiers());
  34637. // (return immediately - this button may now have been deleted)
  34638. return true;
  34639. }
  34640. return wasDown || isKeyDown;
  34641. }
  34642. bool Button::keyPressed (const KeyPress&, Component*)
  34643. {
  34644. // returning true will avoid forwarding events for keys that we're using as shortcuts
  34645. return isShortcutPressed();
  34646. }
  34647. bool Button::keyPressed (const KeyPress& key)
  34648. {
  34649. if (isEnabled() && key.isKeyCode (KeyPress::returnKey))
  34650. {
  34651. triggerClick();
  34652. return true;
  34653. }
  34654. return false;
  34655. }
  34656. void Button::setRepeatSpeed (const int initialDelayMillisecs,
  34657. const int repeatMillisecs,
  34658. const int minimumDelayInMillisecs) throw()
  34659. {
  34660. autoRepeatDelay = initialDelayMillisecs;
  34661. autoRepeatSpeed = repeatMillisecs;
  34662. autoRepeatMinimumDelay = jmin (autoRepeatSpeed, minimumDelayInMillisecs);
  34663. }
  34664. void Button::repeatTimerCallback()
  34665. {
  34666. if (needsRepainting)
  34667. {
  34668. getRepeatTimer().stopTimer();
  34669. updateState (0);
  34670. needsRepainting = false;
  34671. }
  34672. else if (autoRepeatSpeed > 0 && (isKeyDown || (updateState (0) == buttonDown)))
  34673. {
  34674. int repeatSpeed = autoRepeatSpeed;
  34675. if (autoRepeatMinimumDelay >= 0)
  34676. {
  34677. double timeHeldDown = jmin (1.0, getMillisecondsSinceButtonDown() / 4000.0);
  34678. timeHeldDown *= timeHeldDown;
  34679. repeatSpeed = repeatSpeed + (int) (timeHeldDown * (autoRepeatMinimumDelay - repeatSpeed));
  34680. }
  34681. repeatSpeed = jmax (1, repeatSpeed);
  34682. getRepeatTimer().startTimer (repeatSpeed);
  34683. const uint32 now = Time::getApproximateMillisecondCounter();
  34684. const int numTimesToCallback = (now > lastTimeCallbackTime) ? jmax (1, (int) (now - lastTimeCallbackTime) / repeatSpeed) : 1;
  34685. lastTimeCallbackTime = now;
  34686. const ComponentDeletionWatcher cdw (this);
  34687. for (int i = numTimesToCallback; --i >= 0;)
  34688. {
  34689. internalClickCallback (ModifierKeys::getCurrentModifiers());
  34690. if (cdw.hasBeenDeleted() || ! isDown())
  34691. return;
  34692. }
  34693. }
  34694. else if (! needsToRelease)
  34695. {
  34696. getRepeatTimer().stopTimer();
  34697. }
  34698. }
  34699. Button::RepeatTimer& Button::getRepeatTimer()
  34700. {
  34701. if (repeatTimer == 0)
  34702. repeatTimer = new RepeatTimer (*this);
  34703. return *repeatTimer;
  34704. }
  34705. END_JUCE_NAMESPACE
  34706. /*** End of inlined file: juce_Button.cpp ***/
  34707. /*** Start of inlined file: juce_DrawableButton.cpp ***/
  34708. BEGIN_JUCE_NAMESPACE
  34709. DrawableButton::DrawableButton (const String& name,
  34710. const DrawableButton::ButtonStyle buttonStyle)
  34711. : Button (name),
  34712. style (buttonStyle),
  34713. edgeIndent (3)
  34714. {
  34715. if (buttonStyle == ImageOnButtonBackground)
  34716. {
  34717. backgroundOff = Colour (0xffbbbbff);
  34718. backgroundOn = Colour (0xff3333ff);
  34719. }
  34720. else
  34721. {
  34722. backgroundOff = Colours::transparentBlack;
  34723. backgroundOn = Colour (0xaabbbbff);
  34724. }
  34725. }
  34726. DrawableButton::~DrawableButton()
  34727. {
  34728. deleteImages();
  34729. }
  34730. void DrawableButton::deleteImages()
  34731. {
  34732. }
  34733. void DrawableButton::setImages (const Drawable* normal,
  34734. const Drawable* over,
  34735. const Drawable* down,
  34736. const Drawable* disabled,
  34737. const Drawable* normalOn,
  34738. const Drawable* overOn,
  34739. const Drawable* downOn,
  34740. const Drawable* disabledOn)
  34741. {
  34742. deleteImages();
  34743. jassert (normal != 0); // you really need to give it at least a normal image..
  34744. if (normal != 0)
  34745. normalImage = normal->createCopy();
  34746. if (over != 0)
  34747. overImage = over->createCopy();
  34748. if (down != 0)
  34749. downImage = down->createCopy();
  34750. if (disabled != 0)
  34751. disabledImage = disabled->createCopy();
  34752. if (normalOn != 0)
  34753. normalImageOn = normalOn->createCopy();
  34754. if (overOn != 0)
  34755. overImageOn = overOn->createCopy();
  34756. if (downOn != 0)
  34757. downImageOn = downOn->createCopy();
  34758. if (disabledOn != 0)
  34759. disabledImageOn = disabledOn->createCopy();
  34760. repaint();
  34761. }
  34762. void DrawableButton::setButtonStyle (const DrawableButton::ButtonStyle newStyle)
  34763. {
  34764. if (style != newStyle)
  34765. {
  34766. style = newStyle;
  34767. repaint();
  34768. }
  34769. }
  34770. void DrawableButton::setBackgroundColours (const Colour& toggledOffColour,
  34771. const Colour& toggledOnColour)
  34772. {
  34773. if (backgroundOff != toggledOffColour
  34774. || backgroundOn != toggledOnColour)
  34775. {
  34776. backgroundOff = toggledOffColour;
  34777. backgroundOn = toggledOnColour;
  34778. repaint();
  34779. }
  34780. }
  34781. const Colour& DrawableButton::getBackgroundColour() const throw()
  34782. {
  34783. return getToggleState() ? backgroundOn
  34784. : backgroundOff;
  34785. }
  34786. void DrawableButton::setEdgeIndent (const int numPixelsIndent)
  34787. {
  34788. edgeIndent = numPixelsIndent;
  34789. repaint();
  34790. }
  34791. void DrawableButton::paintButton (Graphics& g,
  34792. bool isMouseOverButton,
  34793. bool isButtonDown)
  34794. {
  34795. Rectangle<int> imageSpace;
  34796. if (style == ImageOnButtonBackground)
  34797. {
  34798. const int insetX = getWidth() / 4;
  34799. const int insetY = getHeight() / 4;
  34800. imageSpace.setBounds (insetX, insetY, getWidth() - insetX * 2, getHeight() - insetY * 2);
  34801. getLookAndFeel().drawButtonBackground (g, *this,
  34802. getBackgroundColour(),
  34803. isMouseOverButton,
  34804. isButtonDown);
  34805. }
  34806. else
  34807. {
  34808. g.fillAll (getBackgroundColour());
  34809. const int textH = (style == ImageAboveTextLabel)
  34810. ? jmin (16, proportionOfHeight (0.25f))
  34811. : 0;
  34812. const int indentX = jmin (edgeIndent, proportionOfWidth (0.3f));
  34813. const int indentY = jmin (edgeIndent, proportionOfHeight (0.3f));
  34814. imageSpace.setBounds (indentX, indentY,
  34815. getWidth() - indentX * 2,
  34816. getHeight() - indentY * 2 - textH);
  34817. if (textH > 0)
  34818. {
  34819. g.setFont ((float) textH);
  34820. g.setColour (Colours::black.withAlpha (isEnabled() ? 1.0f : 0.4f));
  34821. g.drawFittedText (getButtonText(),
  34822. 2, getHeight() - textH - 1,
  34823. getWidth() - 4, textH,
  34824. Justification::centred, 1);
  34825. }
  34826. }
  34827. g.setImageResamplingQuality (Graphics::mediumResamplingQuality);
  34828. g.setOpacity (1.0f);
  34829. const Drawable* imageToDraw = 0;
  34830. if (isEnabled())
  34831. {
  34832. imageToDraw = getCurrentImage();
  34833. }
  34834. else
  34835. {
  34836. imageToDraw = getToggleState() ? disabledImageOn
  34837. : disabledImage;
  34838. if (imageToDraw == 0)
  34839. {
  34840. g.setOpacity (0.4f);
  34841. imageToDraw = getNormalImage();
  34842. }
  34843. }
  34844. if (imageToDraw != 0)
  34845. {
  34846. if (style == ImageRaw)
  34847. {
  34848. imageToDraw->draw (g, 1.0f);
  34849. }
  34850. else
  34851. {
  34852. imageToDraw->drawWithin (g,
  34853. imageSpace.getX(),
  34854. imageSpace.getY(),
  34855. imageSpace.getWidth(),
  34856. imageSpace.getHeight(),
  34857. RectanglePlacement::centred,
  34858. 1.0f);
  34859. }
  34860. }
  34861. }
  34862. const Drawable* DrawableButton::getCurrentImage() const throw()
  34863. {
  34864. if (isDown())
  34865. return getDownImage();
  34866. if (isOver())
  34867. return getOverImage();
  34868. return getNormalImage();
  34869. }
  34870. const Drawable* DrawableButton::getNormalImage() const throw()
  34871. {
  34872. return (getToggleState() && normalImageOn != 0) ? normalImageOn
  34873. : normalImage;
  34874. }
  34875. const Drawable* DrawableButton::getOverImage() const throw()
  34876. {
  34877. const Drawable* d = normalImage;
  34878. if (getToggleState())
  34879. {
  34880. if (overImageOn != 0)
  34881. d = overImageOn;
  34882. else if (normalImageOn != 0)
  34883. d = normalImageOn;
  34884. else if (overImage != 0)
  34885. d = overImage;
  34886. }
  34887. else
  34888. {
  34889. if (overImage != 0)
  34890. d = overImage;
  34891. }
  34892. return d;
  34893. }
  34894. const Drawable* DrawableButton::getDownImage() const throw()
  34895. {
  34896. const Drawable* d = normalImage;
  34897. if (getToggleState())
  34898. {
  34899. if (downImageOn != 0)
  34900. d = downImageOn;
  34901. else if (overImageOn != 0)
  34902. d = overImageOn;
  34903. else if (normalImageOn != 0)
  34904. d = normalImageOn;
  34905. else if (downImage != 0)
  34906. d = downImage;
  34907. else
  34908. d = getOverImage();
  34909. }
  34910. else
  34911. {
  34912. if (downImage != 0)
  34913. d = downImage;
  34914. else
  34915. d = getOverImage();
  34916. }
  34917. return d;
  34918. }
  34919. END_JUCE_NAMESPACE
  34920. /*** End of inlined file: juce_DrawableButton.cpp ***/
  34921. /*** Start of inlined file: juce_HyperlinkButton.cpp ***/
  34922. BEGIN_JUCE_NAMESPACE
  34923. HyperlinkButton::HyperlinkButton (const String& linkText,
  34924. const URL& linkURL)
  34925. : Button (linkText),
  34926. url (linkURL),
  34927. font (14.0f, Font::underlined),
  34928. resizeFont (true),
  34929. justification (Justification::centred)
  34930. {
  34931. setMouseCursor (MouseCursor::PointingHandCursor);
  34932. setTooltip (linkURL.toString (false));
  34933. }
  34934. HyperlinkButton::~HyperlinkButton()
  34935. {
  34936. }
  34937. void HyperlinkButton::setFont (const Font& newFont,
  34938. const bool resizeToMatchComponentHeight,
  34939. const Justification& justificationType)
  34940. {
  34941. font = newFont;
  34942. resizeFont = resizeToMatchComponentHeight;
  34943. justification = justificationType;
  34944. repaint();
  34945. }
  34946. void HyperlinkButton::setURL (const URL& newURL) throw()
  34947. {
  34948. url = newURL;
  34949. setTooltip (newURL.toString (false));
  34950. }
  34951. const Font HyperlinkButton::getFontToUse() const
  34952. {
  34953. Font f (font);
  34954. if (resizeFont)
  34955. f.setHeight (getHeight() * 0.7f);
  34956. return f;
  34957. }
  34958. void HyperlinkButton::changeWidthToFitText()
  34959. {
  34960. setSize (getFontToUse().getStringWidth (getName()) + 6, getHeight());
  34961. }
  34962. void HyperlinkButton::colourChanged()
  34963. {
  34964. repaint();
  34965. }
  34966. void HyperlinkButton::clicked()
  34967. {
  34968. if (url.isWellFormed())
  34969. url.launchInDefaultBrowser();
  34970. }
  34971. void HyperlinkButton::paintButton (Graphics& g,
  34972. bool isMouseOverButton,
  34973. bool isButtonDown)
  34974. {
  34975. const Colour textColour (findColour (textColourId));
  34976. if (isEnabled())
  34977. g.setColour ((isMouseOverButton) ? textColour.darker ((isButtonDown) ? 1.3f : 0.4f)
  34978. : textColour);
  34979. else
  34980. g.setColour (textColour.withMultipliedAlpha (0.4f));
  34981. g.setFont (getFontToUse());
  34982. g.drawText (getButtonText(),
  34983. 2, 0, getWidth() - 2, getHeight(),
  34984. justification.getOnlyHorizontalFlags() | Justification::verticallyCentred,
  34985. true);
  34986. }
  34987. END_JUCE_NAMESPACE
  34988. /*** End of inlined file: juce_HyperlinkButton.cpp ***/
  34989. /*** Start of inlined file: juce_ImageButton.cpp ***/
  34990. BEGIN_JUCE_NAMESPACE
  34991. ImageButton::ImageButton (const String& text_)
  34992. : Button (text_),
  34993. scaleImageToFit (true),
  34994. preserveProportions (true),
  34995. alphaThreshold (0),
  34996. imageX (0),
  34997. imageY (0),
  34998. imageW (0),
  34999. imageH (0),
  35000. normalImage (0),
  35001. overImage (0),
  35002. downImage (0)
  35003. {
  35004. }
  35005. ImageButton::~ImageButton()
  35006. {
  35007. deleteImages();
  35008. }
  35009. void ImageButton::deleteImages()
  35010. {
  35011. ImageCache::releaseOrDelete (normalImage);
  35012. ImageCache::releaseOrDelete (overImage);
  35013. ImageCache::releaseOrDelete (downImage);
  35014. }
  35015. void ImageButton::setImages (const bool resizeButtonNowToFitThisImage,
  35016. const bool rescaleImagesWhenButtonSizeChanges,
  35017. const bool preserveImageProportions,
  35018. Image* const normalImage_,
  35019. const float imageOpacityWhenNormal,
  35020. const Colour& overlayColourWhenNormal,
  35021. Image* const overImage_,
  35022. const float imageOpacityWhenOver,
  35023. const Colour& overlayColourWhenOver,
  35024. Image* const downImage_,
  35025. const float imageOpacityWhenDown,
  35026. const Colour& overlayColourWhenDown,
  35027. const float hitTestAlphaThreshold)
  35028. {
  35029. deleteImages();
  35030. normalImage = normalImage_;
  35031. overImage = overImage_;
  35032. downImage = downImage_;
  35033. if (resizeButtonNowToFitThisImage && normalImage != 0)
  35034. {
  35035. imageW = normalImage->getWidth();
  35036. imageH = normalImage->getHeight();
  35037. setSize (imageW, imageH);
  35038. }
  35039. scaleImageToFit = rescaleImagesWhenButtonSizeChanges;
  35040. preserveProportions = preserveImageProportions;
  35041. normalOpacity = imageOpacityWhenNormal;
  35042. normalOverlay = overlayColourWhenNormal;
  35043. overOpacity = imageOpacityWhenOver;
  35044. overOverlay = overlayColourWhenOver;
  35045. downOpacity = imageOpacityWhenDown;
  35046. downOverlay = overlayColourWhenDown;
  35047. alphaThreshold = (unsigned char) jlimit (0, 0xff, roundToInt (255.0f * hitTestAlphaThreshold));
  35048. repaint();
  35049. }
  35050. Image* ImageButton::getCurrentImage() const
  35051. {
  35052. if (isDown() || getToggleState())
  35053. return getDownImage();
  35054. if (isOver())
  35055. return getOverImage();
  35056. return getNormalImage();
  35057. }
  35058. Image* ImageButton::getNormalImage() const throw()
  35059. {
  35060. return normalImage;
  35061. }
  35062. Image* ImageButton::getOverImage() const throw()
  35063. {
  35064. return (overImage != 0) ? overImage
  35065. : normalImage;
  35066. }
  35067. Image* ImageButton::getDownImage() const throw()
  35068. {
  35069. return (downImage != 0) ? downImage
  35070. : getOverImage();
  35071. }
  35072. void ImageButton::paintButton (Graphics& g,
  35073. bool isMouseOverButton,
  35074. bool isButtonDown)
  35075. {
  35076. if (! isEnabled())
  35077. {
  35078. isMouseOverButton = false;
  35079. isButtonDown = false;
  35080. }
  35081. Image* const im = getCurrentImage();
  35082. if (im != 0)
  35083. {
  35084. const int iw = im->getWidth();
  35085. const int ih = im->getHeight();
  35086. imageW = getWidth();
  35087. imageH = getHeight();
  35088. imageX = (imageW - iw) >> 1;
  35089. imageY = (imageH - ih) >> 1;
  35090. if (scaleImageToFit)
  35091. {
  35092. if (preserveProportions)
  35093. {
  35094. int newW, newH;
  35095. const float imRatio = ih / (float)iw;
  35096. const float destRatio = imageH / (float)imageW;
  35097. if (imRatio > destRatio)
  35098. {
  35099. newW = roundToInt (imageH / imRatio);
  35100. newH = imageH;
  35101. }
  35102. else
  35103. {
  35104. newW = imageW;
  35105. newH = roundToInt (imageW * imRatio);
  35106. }
  35107. imageX = (imageW - newW) / 2;
  35108. imageY = (imageH - newH) / 2;
  35109. imageW = newW;
  35110. imageH = newH;
  35111. }
  35112. else
  35113. {
  35114. imageX = 0;
  35115. imageY = 0;
  35116. }
  35117. }
  35118. if (! scaleImageToFit)
  35119. {
  35120. imageW = iw;
  35121. imageH = ih;
  35122. }
  35123. getLookAndFeel().drawImageButton (g, im, imageX, imageY, imageW, imageH,
  35124. isButtonDown ? downOverlay
  35125. : (isMouseOverButton ? overOverlay
  35126. : normalOverlay),
  35127. isButtonDown ? downOpacity
  35128. : (isMouseOverButton ? overOpacity
  35129. : normalOpacity),
  35130. *this);
  35131. }
  35132. }
  35133. bool ImageButton::hitTest (int x, int y)
  35134. {
  35135. if (alphaThreshold == 0)
  35136. return true;
  35137. Image* const im = getCurrentImage();
  35138. return im == 0
  35139. || (imageW > 0 && imageH > 0
  35140. && alphaThreshold < im->getPixelAt (((x - imageX) * im->getWidth()) / imageW,
  35141. ((y - imageY) * im->getHeight()) / imageH).getAlpha());
  35142. }
  35143. END_JUCE_NAMESPACE
  35144. /*** End of inlined file: juce_ImageButton.cpp ***/
  35145. /*** Start of inlined file: juce_ShapeButton.cpp ***/
  35146. BEGIN_JUCE_NAMESPACE
  35147. ShapeButton::ShapeButton (const String& text_,
  35148. const Colour& normalColour_,
  35149. const Colour& overColour_,
  35150. const Colour& downColour_)
  35151. : Button (text_),
  35152. normalColour (normalColour_),
  35153. overColour (overColour_),
  35154. downColour (downColour_),
  35155. maintainShapeProportions (false),
  35156. outlineWidth (0.0f)
  35157. {
  35158. }
  35159. ShapeButton::~ShapeButton()
  35160. {
  35161. }
  35162. void ShapeButton::setColours (const Colour& newNormalColour,
  35163. const Colour& newOverColour,
  35164. const Colour& newDownColour)
  35165. {
  35166. normalColour = newNormalColour;
  35167. overColour = newOverColour;
  35168. downColour = newDownColour;
  35169. }
  35170. void ShapeButton::setOutline (const Colour& newOutlineColour,
  35171. const float newOutlineWidth)
  35172. {
  35173. outlineColour = newOutlineColour;
  35174. outlineWidth = newOutlineWidth;
  35175. }
  35176. void ShapeButton::setShape (const Path& newShape,
  35177. const bool resizeNowToFitThisShape,
  35178. const bool maintainShapeProportions_,
  35179. const bool hasShadow)
  35180. {
  35181. shape = newShape;
  35182. maintainShapeProportions = maintainShapeProportions_;
  35183. shadow.setShadowProperties (3.0f, 0.5f, 0, 0);
  35184. setComponentEffect ((hasShadow) ? &shadow : 0);
  35185. if (resizeNowToFitThisShape)
  35186. {
  35187. Rectangle<float> bounds (shape.getBounds());
  35188. if (hasShadow)
  35189. bounds.expand (4.0f, 4.0f);
  35190. shape.applyTransform (AffineTransform::translation (-bounds.getX(), -bounds.getY()));
  35191. setSize (1 + (int) (bounds.getWidth() + outlineWidth),
  35192. 1 + (int) (bounds.getHeight() + outlineWidth));
  35193. }
  35194. }
  35195. void ShapeButton::paintButton (Graphics& g, bool isMouseOverButton, bool isButtonDown)
  35196. {
  35197. if (! isEnabled())
  35198. {
  35199. isMouseOverButton = false;
  35200. isButtonDown = false;
  35201. }
  35202. g.setColour ((isButtonDown) ? downColour
  35203. : (isMouseOverButton) ? overColour
  35204. : normalColour);
  35205. int w = getWidth();
  35206. int h = getHeight();
  35207. if (getComponentEffect() != 0)
  35208. {
  35209. w -= 4;
  35210. h -= 4;
  35211. }
  35212. const float offset = (outlineWidth * 0.5f) + (isButtonDown ? 1.5f : 0.0f);
  35213. const AffineTransform trans (shape.getTransformToScaleToFit (offset, offset,
  35214. w - offset - outlineWidth,
  35215. h - offset - outlineWidth,
  35216. maintainShapeProportions));
  35217. g.fillPath (shape, trans);
  35218. if (outlineWidth > 0.0f)
  35219. {
  35220. g.setColour (outlineColour);
  35221. g.strokePath (shape, PathStrokeType (outlineWidth), trans);
  35222. }
  35223. }
  35224. END_JUCE_NAMESPACE
  35225. /*** End of inlined file: juce_ShapeButton.cpp ***/
  35226. /*** Start of inlined file: juce_TextButton.cpp ***/
  35227. BEGIN_JUCE_NAMESPACE
  35228. TextButton::TextButton (const String& name,
  35229. const String& toolTip)
  35230. : Button (name)
  35231. {
  35232. setTooltip (toolTip);
  35233. }
  35234. TextButton::~TextButton()
  35235. {
  35236. }
  35237. void TextButton::paintButton (Graphics& g,
  35238. bool isMouseOverButton,
  35239. bool isButtonDown)
  35240. {
  35241. getLookAndFeel().drawButtonBackground (g, *this,
  35242. findColour (getToggleState() ? buttonOnColourId
  35243. : buttonColourId),
  35244. isMouseOverButton,
  35245. isButtonDown);
  35246. getLookAndFeel().drawButtonText (g, *this,
  35247. isMouseOverButton,
  35248. isButtonDown);
  35249. }
  35250. void TextButton::colourChanged()
  35251. {
  35252. repaint();
  35253. }
  35254. const Font TextButton::getFont()
  35255. {
  35256. return Font (jmin (15.0f, getHeight() * 0.6f));
  35257. }
  35258. void TextButton::changeWidthToFitText (const int newHeight)
  35259. {
  35260. if (newHeight >= 0)
  35261. setSize (jmax (1, getWidth()), newHeight);
  35262. setSize (getFont().getStringWidth (getButtonText()) + getHeight(),
  35263. getHeight());
  35264. }
  35265. END_JUCE_NAMESPACE
  35266. /*** End of inlined file: juce_TextButton.cpp ***/
  35267. /*** Start of inlined file: juce_ToggleButton.cpp ***/
  35268. BEGIN_JUCE_NAMESPACE
  35269. ToggleButton::ToggleButton (const String& buttonText)
  35270. : Button (buttonText)
  35271. {
  35272. setClickingTogglesState (true);
  35273. }
  35274. ToggleButton::~ToggleButton()
  35275. {
  35276. }
  35277. void ToggleButton::paintButton (Graphics& g,
  35278. bool isMouseOverButton,
  35279. bool isButtonDown)
  35280. {
  35281. getLookAndFeel().drawToggleButton (g, *this,
  35282. isMouseOverButton,
  35283. isButtonDown);
  35284. }
  35285. void ToggleButton::changeWidthToFitText()
  35286. {
  35287. getLookAndFeel().changeToggleButtonWidthToFitText (*this);
  35288. }
  35289. void ToggleButton::colourChanged()
  35290. {
  35291. repaint();
  35292. }
  35293. END_JUCE_NAMESPACE
  35294. /*** End of inlined file: juce_ToggleButton.cpp ***/
  35295. /*** Start of inlined file: juce_ToolbarButton.cpp ***/
  35296. BEGIN_JUCE_NAMESPACE
  35297. ToolbarButton::ToolbarButton (const int itemId_,
  35298. const String& buttonText,
  35299. Drawable* const normalImage_,
  35300. Drawable* const toggledOnImage_)
  35301. : ToolbarItemComponent (itemId_, buttonText, true),
  35302. normalImage (normalImage_),
  35303. toggledOnImage (toggledOnImage_)
  35304. {
  35305. }
  35306. ToolbarButton::~ToolbarButton()
  35307. {
  35308. }
  35309. bool ToolbarButton::getToolbarItemSizes (int toolbarDepth,
  35310. bool /*isToolbarVertical*/,
  35311. int& preferredSize,
  35312. int& minSize, int& maxSize)
  35313. {
  35314. preferredSize = minSize = maxSize = toolbarDepth;
  35315. return true;
  35316. }
  35317. void ToolbarButton::paintButtonArea (Graphics& g,
  35318. int width, int height,
  35319. bool /*isMouseOver*/,
  35320. bool /*isMouseDown*/)
  35321. {
  35322. Drawable* d = normalImage;
  35323. if (getToggleState() && toggledOnImage != 0)
  35324. d = toggledOnImage;
  35325. if (! isEnabled())
  35326. {
  35327. Image im (Image::ARGB, width, height, true);
  35328. Graphics g2 (im);
  35329. d->drawWithin (g2, 0, 0, width, height, RectanglePlacement::centred, 1.0f);
  35330. im.desaturate();
  35331. g.drawImageAt (&im, 0, 0);
  35332. }
  35333. else
  35334. {
  35335. d->drawWithin (g, 0, 0, width, height, RectanglePlacement::centred, 1.0f);
  35336. }
  35337. }
  35338. void ToolbarButton::contentAreaChanged (const Rectangle<int>&)
  35339. {
  35340. }
  35341. END_JUCE_NAMESPACE
  35342. /*** End of inlined file: juce_ToolbarButton.cpp ***/
  35343. /*** Start of inlined file: juce_CodeDocument.cpp ***/
  35344. BEGIN_JUCE_NAMESPACE
  35345. class CodeDocumentLine
  35346. {
  35347. public:
  35348. CodeDocumentLine (const tchar* const line_,
  35349. const int lineLength_,
  35350. const int numNewLineChars,
  35351. const int lineStartInFile_)
  35352. : line (line_, lineLength_),
  35353. lineStartInFile (lineStartInFile_),
  35354. lineLength (lineLength_),
  35355. lineLengthWithoutNewLines (lineLength_ - numNewLineChars)
  35356. {
  35357. }
  35358. ~CodeDocumentLine()
  35359. {
  35360. }
  35361. static void createLines (Array <CodeDocumentLine*>& newLines, const String& text)
  35362. {
  35363. const tchar* const t = (const tchar*) text;
  35364. int pos = 0;
  35365. while (t [pos] != 0)
  35366. {
  35367. const int startOfLine = pos;
  35368. int numNewLineChars = 0;
  35369. while (t[pos] != 0)
  35370. {
  35371. if (t[pos] == T('\r'))
  35372. {
  35373. ++numNewLineChars;
  35374. ++pos;
  35375. if (t[pos] == T('\n'))
  35376. {
  35377. ++numNewLineChars;
  35378. ++pos;
  35379. }
  35380. break;
  35381. }
  35382. if (t[pos] == T('\n'))
  35383. {
  35384. ++numNewLineChars;
  35385. ++pos;
  35386. break;
  35387. }
  35388. ++pos;
  35389. }
  35390. newLines.add (new CodeDocumentLine (t + startOfLine, pos - startOfLine,
  35391. numNewLineChars, startOfLine));
  35392. }
  35393. jassert (pos == text.length());
  35394. }
  35395. bool endsWithLineBreak() const throw()
  35396. {
  35397. return lineLengthWithoutNewLines != lineLength;
  35398. }
  35399. void updateLength() throw()
  35400. {
  35401. lineLengthWithoutNewLines = lineLength = line.length();
  35402. while (lineLengthWithoutNewLines > 0
  35403. && (line [lineLengthWithoutNewLines - 1] == '\n'
  35404. || line [lineLengthWithoutNewLines - 1] == '\r'))
  35405. {
  35406. --lineLengthWithoutNewLines;
  35407. }
  35408. }
  35409. String line;
  35410. int lineStartInFile, lineLength, lineLengthWithoutNewLines;
  35411. };
  35412. CodeDocument::Iterator::Iterator (CodeDocument* const document_)
  35413. : document (document_),
  35414. currentLine (document_->lines[0]),
  35415. line (0),
  35416. position (0)
  35417. {
  35418. }
  35419. CodeDocument::Iterator::Iterator (const CodeDocument::Iterator& other)
  35420. : document (other.document),
  35421. currentLine (other.currentLine),
  35422. line (other.line),
  35423. position (other.position)
  35424. {
  35425. }
  35426. const CodeDocument::Iterator& CodeDocument::Iterator::operator= (const CodeDocument::Iterator& other) throw()
  35427. {
  35428. document = other.document;
  35429. currentLine = other.currentLine;
  35430. line = other.line;
  35431. position = other.position;
  35432. return *this;
  35433. }
  35434. CodeDocument::Iterator::~Iterator() throw()
  35435. {
  35436. }
  35437. juce_wchar CodeDocument::Iterator::nextChar()
  35438. {
  35439. if (currentLine == 0)
  35440. return 0;
  35441. jassert (currentLine == document->lines.getUnchecked (line));
  35442. const juce_wchar result = currentLine->line [position - currentLine->lineStartInFile];
  35443. skip();
  35444. return result;
  35445. }
  35446. void CodeDocument::Iterator::skip()
  35447. {
  35448. if (currentLine != 0)
  35449. {
  35450. jassert (currentLine == document->lines.getUnchecked (line));
  35451. if (++position >= currentLine->lineStartInFile + currentLine->lineLength)
  35452. {
  35453. ++line;
  35454. currentLine = document->lines [line];
  35455. }
  35456. }
  35457. }
  35458. void CodeDocument::Iterator::skipToEndOfLine()
  35459. {
  35460. if (currentLine != 0)
  35461. {
  35462. jassert (currentLine == document->lines.getUnchecked (line));
  35463. ++line;
  35464. currentLine = document->lines [line];
  35465. if (currentLine != 0)
  35466. position = currentLine->lineStartInFile;
  35467. else
  35468. position = document->getNumCharacters();
  35469. }
  35470. }
  35471. juce_wchar CodeDocument::Iterator::peekNextChar() const
  35472. {
  35473. if (currentLine == 0)
  35474. return 0;
  35475. jassert (currentLine == document->lines.getUnchecked (line));
  35476. return currentLine->line [position - currentLine->lineStartInFile];
  35477. }
  35478. void CodeDocument::Iterator::skipWhitespace()
  35479. {
  35480. while (CharacterFunctions::isWhitespace (peekNextChar()))
  35481. skip();
  35482. }
  35483. bool CodeDocument::Iterator::isEOF() const throw()
  35484. {
  35485. return currentLine == 0;
  35486. }
  35487. CodeDocument::Position::Position() throw()
  35488. : owner (0), characterPos (0), line (0),
  35489. indexInLine (0), positionMaintained (false)
  35490. {
  35491. }
  35492. CodeDocument::Position::Position (const CodeDocument* const ownerDocument,
  35493. const int line_, const int indexInLine_) throw()
  35494. : owner (const_cast <CodeDocument*> (ownerDocument)),
  35495. characterPos (0), line (line_),
  35496. indexInLine (indexInLine_), positionMaintained (false)
  35497. {
  35498. setLineAndIndex (line_, indexInLine_);
  35499. }
  35500. CodeDocument::Position::Position (const CodeDocument* const ownerDocument,
  35501. const int characterPos_) throw()
  35502. : owner (const_cast <CodeDocument*> (ownerDocument)),
  35503. positionMaintained (false)
  35504. {
  35505. setPosition (characterPos_);
  35506. }
  35507. CodeDocument::Position::Position (const Position& other) throw()
  35508. : owner (other.owner), characterPos (other.characterPos), line (other.line),
  35509. indexInLine (other.indexInLine), positionMaintained (false)
  35510. {
  35511. jassert (*this == other);
  35512. }
  35513. CodeDocument::Position::~Position() throw()
  35514. {
  35515. setPositionMaintained (false);
  35516. }
  35517. const CodeDocument::Position& CodeDocument::Position::operator= (const Position& other) throw()
  35518. {
  35519. if (this != &other)
  35520. {
  35521. const bool wasPositionMaintained = positionMaintained;
  35522. if (owner != other.owner)
  35523. setPositionMaintained (false);
  35524. owner = other.owner;
  35525. line = other.line;
  35526. indexInLine = other.indexInLine;
  35527. characterPos = other.characterPos;
  35528. setPositionMaintained (wasPositionMaintained);
  35529. jassert (*this == other);
  35530. }
  35531. return *this;
  35532. }
  35533. bool CodeDocument::Position::operator== (const Position& other) const throw()
  35534. {
  35535. jassert ((characterPos == other.characterPos)
  35536. == (line == other.line && indexInLine == other.indexInLine));
  35537. return characterPos == other.characterPos
  35538. && line == other.line
  35539. && indexInLine == other.indexInLine
  35540. && owner == other.owner;
  35541. }
  35542. bool CodeDocument::Position::operator!= (const Position& other) const throw()
  35543. {
  35544. return ! operator== (other);
  35545. }
  35546. void CodeDocument::Position::setLineAndIndex (const int newLine, const int newIndexInLine) throw()
  35547. {
  35548. jassert (owner != 0);
  35549. if (owner->lines.size() == 0)
  35550. {
  35551. line = 0;
  35552. indexInLine = 0;
  35553. characterPos = 0;
  35554. }
  35555. else
  35556. {
  35557. if (newLine >= owner->lines.size())
  35558. {
  35559. line = owner->lines.size() - 1;
  35560. CodeDocumentLine* const l = owner->lines.getUnchecked (line);
  35561. jassert (l != 0);
  35562. indexInLine = l->lineLengthWithoutNewLines;
  35563. characterPos = l->lineStartInFile + indexInLine;
  35564. }
  35565. else
  35566. {
  35567. line = jmax (0, newLine);
  35568. CodeDocumentLine* const l = owner->lines.getUnchecked (line);
  35569. jassert (l != 0);
  35570. if (l->lineLengthWithoutNewLines > 0)
  35571. indexInLine = jlimit (0, l->lineLengthWithoutNewLines, newIndexInLine);
  35572. else
  35573. indexInLine = 0;
  35574. characterPos = l->lineStartInFile + indexInLine;
  35575. }
  35576. }
  35577. }
  35578. void CodeDocument::Position::setPosition (const int newPosition) throw()
  35579. {
  35580. jassert (owner != 0);
  35581. line = 0;
  35582. indexInLine = 0;
  35583. characterPos = 0;
  35584. if (newPosition > 0)
  35585. {
  35586. int lineStart = 0;
  35587. int lineEnd = owner->lines.size();
  35588. for (;;)
  35589. {
  35590. if (lineEnd - lineStart < 4)
  35591. {
  35592. for (int i = lineStart; i < lineEnd; ++i)
  35593. {
  35594. CodeDocumentLine* const l = owner->lines.getUnchecked (i);
  35595. int index = newPosition - l->lineStartInFile;
  35596. if (index >= 0 && (index < l->lineLength || i == lineEnd - 1))
  35597. {
  35598. line = i;
  35599. indexInLine = jmin (l->lineLengthWithoutNewLines, index);
  35600. characterPos = l->lineStartInFile + indexInLine;
  35601. }
  35602. }
  35603. break;
  35604. }
  35605. else
  35606. {
  35607. const int midIndex = (lineStart + lineEnd + 1) / 2;
  35608. CodeDocumentLine* const mid = owner->lines.getUnchecked (midIndex);
  35609. if (newPosition >= mid->lineStartInFile)
  35610. lineStart = midIndex;
  35611. else
  35612. lineEnd = midIndex;
  35613. }
  35614. }
  35615. }
  35616. }
  35617. void CodeDocument::Position::moveBy (int characterDelta) throw()
  35618. {
  35619. jassert (owner != 0);
  35620. if (characterDelta == 1)
  35621. {
  35622. setPosition (getPosition());
  35623. // If moving right, make sure we don't get stuck between the \r and \n characters..
  35624. CodeDocumentLine* const l = owner->lines.getUnchecked (line);
  35625. if (indexInLine + characterDelta < l->lineLength
  35626. && indexInLine + characterDelta >= l->lineLengthWithoutNewLines + 1)
  35627. ++characterDelta;
  35628. }
  35629. setPosition (characterPos + characterDelta);
  35630. }
  35631. const CodeDocument::Position CodeDocument::Position::movedBy (const int characterDelta) const throw()
  35632. {
  35633. CodeDocument::Position p (*this);
  35634. p.moveBy (characterDelta);
  35635. return p;
  35636. }
  35637. const CodeDocument::Position CodeDocument::Position::movedByLines (const int deltaLines) const throw()
  35638. {
  35639. CodeDocument::Position p (*this);
  35640. p.setLineAndIndex (getLineNumber() + deltaLines, getIndexInLine());
  35641. return p;
  35642. }
  35643. const tchar CodeDocument::Position::getCharacter() const throw()
  35644. {
  35645. const CodeDocumentLine* const l = owner->lines [line];
  35646. return l == 0 ? 0 : l->line [getIndexInLine()];
  35647. }
  35648. const String CodeDocument::Position::getLineText() const throw()
  35649. {
  35650. const CodeDocumentLine* const l = owner->lines [line];
  35651. return l == 0 ? String::empty : l->line;
  35652. }
  35653. void CodeDocument::Position::setPositionMaintained (const bool isMaintained) throw()
  35654. {
  35655. if (isMaintained != positionMaintained)
  35656. {
  35657. positionMaintained = isMaintained;
  35658. if (owner != 0)
  35659. {
  35660. if (isMaintained)
  35661. {
  35662. jassert (! owner->positionsToMaintain.contains (this));
  35663. owner->positionsToMaintain.add (this);
  35664. }
  35665. else
  35666. {
  35667. jassert (owner->positionsToMaintain.contains (this));
  35668. owner->positionsToMaintain.removeValue (this);
  35669. }
  35670. }
  35671. }
  35672. }
  35673. CodeDocument::CodeDocument()
  35674. : undoManager (std::numeric_limits<int>::max(), 10000),
  35675. currentActionIndex (0),
  35676. indexOfSavedState (-1),
  35677. maximumLineLength (-1),
  35678. newLineChars ("\r\n")
  35679. {
  35680. }
  35681. CodeDocument::~CodeDocument()
  35682. {
  35683. }
  35684. const String CodeDocument::getAllContent() const throw()
  35685. {
  35686. return getTextBetween (Position (this, 0),
  35687. Position (this, lines.size(), 0));
  35688. }
  35689. const String CodeDocument::getTextBetween (const Position& start, const Position& end) const throw()
  35690. {
  35691. if (end.getPosition() <= start.getPosition())
  35692. return String::empty;
  35693. const int startLine = start.getLineNumber();
  35694. const int endLine = end.getLineNumber();
  35695. if (startLine == endLine)
  35696. {
  35697. CodeDocumentLine* const line = lines [startLine];
  35698. return (line == 0) ? String::empty : line->line.substring (start.getIndexInLine(), end.getIndexInLine());
  35699. }
  35700. String result;
  35701. result.preallocateStorage (end.getPosition() - start.getPosition() + 4);
  35702. String::Concatenator concatenator (result);
  35703. const int maxLine = jmin (lines.size() - 1, endLine);
  35704. for (int i = jmax (0, startLine); i <= maxLine; ++i)
  35705. {
  35706. const CodeDocumentLine* line = lines.getUnchecked(i);
  35707. int len = line->lineLength;
  35708. if (i == startLine)
  35709. {
  35710. const int index = start.getIndexInLine();
  35711. concatenator.append (line->line.substring (index, len));
  35712. }
  35713. else if (i == endLine)
  35714. {
  35715. len = end.getIndexInLine();
  35716. concatenator.append (line->line.substring (0, len));
  35717. }
  35718. else
  35719. {
  35720. concatenator.append (line->line);
  35721. }
  35722. }
  35723. return result;
  35724. }
  35725. int CodeDocument::getNumCharacters() const throw()
  35726. {
  35727. const CodeDocumentLine* const lastLine = lines.getLast();
  35728. return (lastLine == 0) ? 0 : lastLine->lineStartInFile + lastLine->lineLength;
  35729. }
  35730. const String CodeDocument::getLine (const int lineIndex) const throw()
  35731. {
  35732. const CodeDocumentLine* const line = lines [lineIndex];
  35733. return (line == 0) ? String::empty : line->line;
  35734. }
  35735. int CodeDocument::getMaximumLineLength() throw()
  35736. {
  35737. if (maximumLineLength < 0)
  35738. {
  35739. maximumLineLength = 0;
  35740. for (int i = lines.size(); --i >= 0;)
  35741. maximumLineLength = jmax (maximumLineLength, lines.getUnchecked(i)->lineLength);
  35742. }
  35743. return maximumLineLength;
  35744. }
  35745. void CodeDocument::deleteSection (const Position& startPosition, const Position& endPosition)
  35746. {
  35747. remove (startPosition.getPosition(), endPosition.getPosition(), true);
  35748. }
  35749. void CodeDocument::insertText (const Position& position, const String& text)
  35750. {
  35751. insert (text, position.getPosition(), true);
  35752. }
  35753. void CodeDocument::replaceAllContent (const String& newContent)
  35754. {
  35755. remove (0, getNumCharacters(), true);
  35756. insert (newContent, 0, true);
  35757. }
  35758. bool CodeDocument::loadFromStream (InputStream& stream)
  35759. {
  35760. replaceAllContent (stream.readEntireStreamAsString());
  35761. setSavePoint();
  35762. clearUndoHistory();
  35763. return true;
  35764. }
  35765. bool CodeDocument::writeToStream (OutputStream& stream)
  35766. {
  35767. for (int i = 0; i < lines.size(); ++i)
  35768. {
  35769. String temp (lines.getUnchecked(i)->line); // use a copy to avoid bloating the memory footprint of the stored string.
  35770. const char* utf8 = temp.toUTF8();
  35771. if (! stream.write (utf8, (int) strlen (utf8)))
  35772. return false;
  35773. }
  35774. return true;
  35775. }
  35776. void CodeDocument::setNewLineCharacters (const String& newLine) throw()
  35777. {
  35778. jassert (newLine == T("\r\n") || newLine == T("\n") || newLine == T("\r"));
  35779. newLineChars = newLine;
  35780. }
  35781. void CodeDocument::newTransaction()
  35782. {
  35783. undoManager.beginNewTransaction (String::empty);
  35784. }
  35785. void CodeDocument::undo()
  35786. {
  35787. newTransaction();
  35788. undoManager.undo();
  35789. }
  35790. void CodeDocument::redo()
  35791. {
  35792. undoManager.redo();
  35793. }
  35794. void CodeDocument::clearUndoHistory()
  35795. {
  35796. undoManager.clearUndoHistory();
  35797. }
  35798. void CodeDocument::setSavePoint() throw()
  35799. {
  35800. indexOfSavedState = currentActionIndex;
  35801. }
  35802. bool CodeDocument::hasChangedSinceSavePoint() const throw()
  35803. {
  35804. return currentActionIndex != indexOfSavedState;
  35805. }
  35806. static int getCodeCharacterCategory (const tchar character) throw()
  35807. {
  35808. return (CharacterFunctions::isLetterOrDigit (character) || character == '_')
  35809. ? 2 : (CharacterFunctions::isWhitespace (character) ? 0 : 1);
  35810. }
  35811. const CodeDocument::Position CodeDocument::findWordBreakAfter (const Position& position) const throw()
  35812. {
  35813. Position p (position);
  35814. const int maxDistance = 256;
  35815. int i = 0;
  35816. while (i < maxDistance
  35817. && CharacterFunctions::isWhitespace (p.getCharacter())
  35818. && (i == 0 || (p.getCharacter() != T('\n')
  35819. && p.getCharacter() != T('\r'))))
  35820. {
  35821. ++i;
  35822. p.moveBy (1);
  35823. }
  35824. if (i == 0)
  35825. {
  35826. const int type = getCodeCharacterCategory (p.getCharacter());
  35827. while (i < maxDistance && type == getCodeCharacterCategory (p.getCharacter()))
  35828. {
  35829. ++i;
  35830. p.moveBy (1);
  35831. }
  35832. while (i < maxDistance
  35833. && CharacterFunctions::isWhitespace (p.getCharacter())
  35834. && (i == 0 || (p.getCharacter() != T('\n')
  35835. && p.getCharacter() != T('\r'))))
  35836. {
  35837. ++i;
  35838. p.moveBy (1);
  35839. }
  35840. }
  35841. return p;
  35842. }
  35843. const CodeDocument::Position CodeDocument::findWordBreakBefore (const Position& position) const throw()
  35844. {
  35845. Position p (position);
  35846. const int maxDistance = 256;
  35847. int i = 0;
  35848. bool stoppedAtLineStart = false;
  35849. while (i < maxDistance)
  35850. {
  35851. const tchar c = p.movedBy (-1).getCharacter();
  35852. if (c == T('\r') || c == T('\n'))
  35853. {
  35854. stoppedAtLineStart = true;
  35855. if (i > 0)
  35856. break;
  35857. }
  35858. if (! CharacterFunctions::isWhitespace (c))
  35859. break;
  35860. p.moveBy (-1);
  35861. ++i;
  35862. }
  35863. if (i < maxDistance && ! stoppedAtLineStart)
  35864. {
  35865. const int type = getCodeCharacterCategory (p.movedBy (-1).getCharacter());
  35866. while (i < maxDistance && type == getCodeCharacterCategory (p.movedBy (-1).getCharacter()))
  35867. {
  35868. p.moveBy (-1);
  35869. ++i;
  35870. }
  35871. }
  35872. return p;
  35873. }
  35874. void CodeDocument::checkLastLineStatus()
  35875. {
  35876. while (lines.size() > 0
  35877. && lines.getLast()->lineLength == 0
  35878. && (lines.size() == 1 || ! lines.getUnchecked (lines.size() - 2)->endsWithLineBreak()))
  35879. {
  35880. // remove any empty lines at the end if the preceding line doesn't end in a newline.
  35881. lines.removeLast();
  35882. }
  35883. const CodeDocumentLine* const lastLine = lines.getLast();
  35884. if (lastLine != 0 && lastLine->endsWithLineBreak())
  35885. {
  35886. // check that there's an empty line at the end if the preceding one ends in a newline..
  35887. lines.add (new CodeDocumentLine (String::empty, 0, 0, lastLine->lineStartInFile + lastLine->lineLength));
  35888. }
  35889. }
  35890. void CodeDocument::addListener (CodeDocument::Listener* const listener) throw()
  35891. {
  35892. listeners.addIfNotAlreadyThere (listener);
  35893. }
  35894. void CodeDocument::removeListener (CodeDocument::Listener* const listener) throw()
  35895. {
  35896. listeners.removeValue (listener);
  35897. }
  35898. void CodeDocument::sendListenerChangeMessage (const int startLine, const int endLine)
  35899. {
  35900. const Position startPos (this, startLine, 0);
  35901. const Position endPos (this, endLine, 0);
  35902. for (int i = listeners.size(); --i >= 0;)
  35903. {
  35904. Listener* const l = (Listener*) listeners[i];
  35905. if (l != 0)
  35906. l->codeDocumentChanged (startPos, endPos);
  35907. }
  35908. }
  35909. class CodeDocumentInsertAction : public UndoableAction
  35910. {
  35911. CodeDocument& owner;
  35912. const String text;
  35913. int insertPos;
  35914. CodeDocumentInsertAction (const CodeDocumentInsertAction&);
  35915. const CodeDocumentInsertAction& operator= (const CodeDocumentInsertAction&);
  35916. public:
  35917. CodeDocumentInsertAction (CodeDocument& owner_, const String& text_, const int insertPos_) throw()
  35918. : owner (owner_),
  35919. text (text_),
  35920. insertPos (insertPos_)
  35921. {
  35922. }
  35923. ~CodeDocumentInsertAction() {}
  35924. bool perform()
  35925. {
  35926. owner.currentActionIndex++;
  35927. owner.insert (text, insertPos, false);
  35928. return true;
  35929. }
  35930. bool undo()
  35931. {
  35932. owner.currentActionIndex--;
  35933. owner.remove (insertPos, insertPos + text.length(), false);
  35934. return true;
  35935. }
  35936. int getSizeInUnits() { return text.length() + 32; }
  35937. };
  35938. void CodeDocument::insert (const String& text, const int insertPos, const bool undoable)
  35939. {
  35940. if (text.isEmpty())
  35941. return;
  35942. if (undoable)
  35943. {
  35944. undoManager.perform (new CodeDocumentInsertAction (*this, text, insertPos));
  35945. }
  35946. else
  35947. {
  35948. Position pos (this, insertPos);
  35949. const int firstAffectedLine = pos.getLineNumber();
  35950. int lastAffectedLine = firstAffectedLine + 1;
  35951. CodeDocumentLine* const firstLine = lines [firstAffectedLine];
  35952. String textInsideOriginalLine (text);
  35953. if (firstLine != 0)
  35954. {
  35955. const int index = pos.getIndexInLine();
  35956. textInsideOriginalLine = firstLine->line.substring (0, index)
  35957. + textInsideOriginalLine
  35958. + firstLine->line.substring (index);
  35959. }
  35960. maximumLineLength = -1;
  35961. Array <CodeDocumentLine*> newLines;
  35962. CodeDocumentLine::createLines (newLines, textInsideOriginalLine);
  35963. jassert (newLines.size() > 0);
  35964. CodeDocumentLine* const newFirstLine = newLines.getUnchecked (0);
  35965. newFirstLine->lineStartInFile = firstLine != 0 ? firstLine->lineStartInFile : 0;
  35966. lines.set (firstAffectedLine, newFirstLine);
  35967. if (newLines.size() > 1)
  35968. {
  35969. for (int i = 1; i < newLines.size(); ++i)
  35970. {
  35971. CodeDocumentLine* const l = newLines.getUnchecked (i);
  35972. lines.insert (firstAffectedLine + i, l);
  35973. }
  35974. lastAffectedLine = lines.size();
  35975. }
  35976. int i, lineStart = newFirstLine->lineStartInFile;
  35977. for (i = firstAffectedLine; i < lines.size(); ++i)
  35978. {
  35979. CodeDocumentLine* const l = lines.getUnchecked (i);
  35980. l->lineStartInFile = lineStart;
  35981. lineStart += l->lineLength;
  35982. }
  35983. checkLastLineStatus();
  35984. const int newTextLength = text.length();
  35985. for (i = 0; i < positionsToMaintain.size(); ++i)
  35986. {
  35987. CodeDocument::Position* const p = positionsToMaintain.getUnchecked(i);
  35988. if (p->getPosition() >= insertPos)
  35989. p->setPosition (p->getPosition() + newTextLength);
  35990. }
  35991. sendListenerChangeMessage (firstAffectedLine, lastAffectedLine);
  35992. }
  35993. }
  35994. class CodeDocumentDeleteAction : public UndoableAction
  35995. {
  35996. CodeDocument& owner;
  35997. int startPos, endPos;
  35998. String removedText;
  35999. CodeDocumentDeleteAction (const CodeDocumentDeleteAction&);
  36000. const CodeDocumentDeleteAction& operator= (const CodeDocumentDeleteAction&);
  36001. public:
  36002. CodeDocumentDeleteAction (CodeDocument& owner_, const int startPos_, const int endPos_) throw()
  36003. : owner (owner_),
  36004. startPos (startPos_),
  36005. endPos (endPos_)
  36006. {
  36007. removedText = owner.getTextBetween (CodeDocument::Position (&owner, startPos),
  36008. CodeDocument::Position (&owner, endPos));
  36009. }
  36010. ~CodeDocumentDeleteAction() {}
  36011. bool perform()
  36012. {
  36013. owner.currentActionIndex++;
  36014. owner.remove (startPos, endPos, false);
  36015. return true;
  36016. }
  36017. bool undo()
  36018. {
  36019. owner.currentActionIndex--;
  36020. owner.insert (removedText, startPos, false);
  36021. return true;
  36022. }
  36023. int getSizeInUnits() { return removedText.length() + 32; }
  36024. };
  36025. void CodeDocument::remove (const int startPos, const int endPos, const bool undoable)
  36026. {
  36027. if (endPos <= startPos)
  36028. return;
  36029. if (undoable)
  36030. {
  36031. undoManager.perform (new CodeDocumentDeleteAction (*this, startPos, endPos));
  36032. }
  36033. else
  36034. {
  36035. Position startPosition (this, startPos);
  36036. Position endPosition (this, endPos);
  36037. maximumLineLength = -1;
  36038. const int firstAffectedLine = startPosition.getLineNumber();
  36039. const int endLine = endPosition.getLineNumber();
  36040. int lastAffectedLine = firstAffectedLine + 1;
  36041. CodeDocumentLine* const firstLine = lines.getUnchecked (firstAffectedLine);
  36042. if (firstAffectedLine == endLine)
  36043. {
  36044. firstLine->line = firstLine->line.substring (0, startPosition.getIndexInLine())
  36045. + firstLine->line.substring (endPosition.getIndexInLine());
  36046. firstLine->updateLength();
  36047. }
  36048. else
  36049. {
  36050. lastAffectedLine = lines.size();
  36051. CodeDocumentLine* const lastLine = lines.getUnchecked (endLine);
  36052. jassert (lastLine != 0);
  36053. firstLine->line = firstLine->line.substring (0, startPosition.getIndexInLine())
  36054. + lastLine->line.substring (endPosition.getIndexInLine());
  36055. firstLine->updateLength();
  36056. int numLinesToRemove = endLine - firstAffectedLine;
  36057. lines.removeRange (firstAffectedLine + 1, numLinesToRemove);
  36058. }
  36059. int i;
  36060. for (i = firstAffectedLine + 1; i < lines.size(); ++i)
  36061. {
  36062. CodeDocumentLine* const l = lines.getUnchecked (i);
  36063. const CodeDocumentLine* const previousLine = lines.getUnchecked (i - 1);
  36064. l->lineStartInFile = previousLine->lineStartInFile + previousLine->lineLength;
  36065. }
  36066. checkLastLineStatus();
  36067. const int totalChars = getNumCharacters();
  36068. for (i = 0; i < positionsToMaintain.size(); ++i)
  36069. {
  36070. CodeDocument::Position* p = positionsToMaintain.getUnchecked(i);
  36071. if (p->getPosition() > startPosition.getPosition())
  36072. p->setPosition (jmax (startPos, p->getPosition() + startPos - endPos));
  36073. if (p->getPosition() > totalChars)
  36074. p->setPosition (totalChars);
  36075. }
  36076. sendListenerChangeMessage (firstAffectedLine, lastAffectedLine);
  36077. }
  36078. }
  36079. END_JUCE_NAMESPACE
  36080. /*** End of inlined file: juce_CodeDocument.cpp ***/
  36081. /*** Start of inlined file: juce_CodeEditorComponent.cpp ***/
  36082. BEGIN_JUCE_NAMESPACE
  36083. class CaretComponent : public Component,
  36084. public Timer
  36085. {
  36086. public:
  36087. CaretComponent()
  36088. {
  36089. setAlwaysOnTop (true);
  36090. setInterceptsMouseClicks (false, false);
  36091. }
  36092. ~CaretComponent()
  36093. {
  36094. }
  36095. void paint (Graphics& g)
  36096. {
  36097. if (getParentComponent()->hasKeyboardFocus (true))
  36098. g.fillAll (findColour (CodeEditorComponent::caretColourId));
  36099. }
  36100. void timerCallback()
  36101. {
  36102. setVisible (! isVisible());
  36103. }
  36104. void updatePosition (CodeEditorComponent& owner)
  36105. {
  36106. startTimer (400);
  36107. setVisible (true);
  36108. const Rectangle<int> pos (owner.getCharacterBounds (owner.getCaretPos()));
  36109. setBounds (pos.getX(), pos.getY(), 2, pos.getHeight());
  36110. }
  36111. };
  36112. class CodeEditorComponent::CodeEditorLine
  36113. {
  36114. public:
  36115. CodeEditorLine() throw()
  36116. {
  36117. }
  36118. ~CodeEditorLine() throw()
  36119. {
  36120. }
  36121. bool update (CodeDocument& document, int lineNum,
  36122. CodeDocument::Iterator& source,
  36123. CodeTokeniser* analyser, const int spacesPerTab,
  36124. const CodeDocument::Position& selectionStart,
  36125. const CodeDocument::Position& selectionEnd)
  36126. {
  36127. Array <SyntaxToken> newTokens;
  36128. newTokens.ensureStorageAllocated (8);
  36129. if (analyser == 0)
  36130. {
  36131. newTokens.add (SyntaxToken (document.getLine (lineNum), -1));
  36132. }
  36133. else if (lineNum < document.getNumLines())
  36134. {
  36135. const CodeDocument::Position pos (&document, lineNum, 0);
  36136. createTokens (pos.getPosition(), pos.getLineText(),
  36137. source, analyser, newTokens);
  36138. }
  36139. replaceTabsWithSpaces (newTokens, spacesPerTab);
  36140. int newHighlightStart = 0;
  36141. int newHighlightEnd = 0;
  36142. if (selectionStart.getLineNumber() <= lineNum && selectionEnd.getLineNumber() >= lineNum)
  36143. {
  36144. const String line (document.getLine (lineNum));
  36145. CodeDocument::Position lineStart (&document, lineNum, 0), lineEnd (&document, lineNum + 1, 0);
  36146. newHighlightStart = indexToColumn (jmax (0, selectionStart.getPosition() - lineStart.getPosition()),
  36147. line, spacesPerTab);
  36148. newHighlightEnd = indexToColumn (jmin (lineEnd.getPosition() - lineStart.getPosition(), selectionEnd.getPosition() - lineStart.getPosition()),
  36149. line, spacesPerTab);
  36150. }
  36151. if (newHighlightStart != highlightColumnStart || newHighlightEnd != highlightColumnEnd)
  36152. {
  36153. highlightColumnStart = newHighlightStart;
  36154. highlightColumnEnd = newHighlightEnd;
  36155. }
  36156. else
  36157. {
  36158. if (tokens.size() == newTokens.size())
  36159. {
  36160. bool allTheSame = true;
  36161. for (int i = newTokens.size(); --i >= 0;)
  36162. {
  36163. if (tokens.getReference(i) != newTokens.getReference(i))
  36164. {
  36165. allTheSame = false;
  36166. break;
  36167. }
  36168. }
  36169. if (allTheSame)
  36170. return false;
  36171. }
  36172. }
  36173. tokens.swapWithArray (newTokens);
  36174. return true;
  36175. }
  36176. void draw (CodeEditorComponent& owner, Graphics& g, const Font& font,
  36177. float x, const int y, const int baselineOffset, const int lineHeight,
  36178. const Colour& highlightColour) const throw()
  36179. {
  36180. if (highlightColumnStart < highlightColumnEnd)
  36181. {
  36182. g.setColour (highlightColour);
  36183. g.fillRect (roundToInt (x + highlightColumnStart * owner.getCharWidth()), y,
  36184. roundToInt ((highlightColumnEnd - highlightColumnStart) * owner.getCharWidth()), lineHeight);
  36185. }
  36186. int lastType = std::numeric_limits<int>::min();
  36187. for (int i = 0; i < tokens.size(); ++i)
  36188. {
  36189. SyntaxToken& token = tokens.getReference(i);
  36190. if (lastType != token.tokenType)
  36191. {
  36192. lastType = token.tokenType;
  36193. g.setColour (owner.getColourForTokenType (lastType));
  36194. }
  36195. g.drawSingleLineText (token.text, roundToInt (x), y + baselineOffset);
  36196. if (i < tokens.size() - 1)
  36197. {
  36198. if (token.width < 0)
  36199. token.width = font.getStringWidthFloat (token.text);
  36200. x += token.width;
  36201. }
  36202. }
  36203. }
  36204. private:
  36205. struct SyntaxToken
  36206. {
  36207. String text;
  36208. int tokenType;
  36209. float width;
  36210. SyntaxToken (const String& text_, const int type) throw()
  36211. : text (text_), tokenType (type), width (-1.0f)
  36212. {
  36213. }
  36214. bool operator!= (const SyntaxToken& other) const throw()
  36215. {
  36216. return text != other.text || tokenType != other.tokenType;
  36217. }
  36218. };
  36219. Array <SyntaxToken> tokens;
  36220. int highlightColumnStart, highlightColumnEnd;
  36221. static void createTokens (int startPosition, const String& lineText,
  36222. CodeDocument::Iterator& source,
  36223. CodeTokeniser* analyser,
  36224. Array <SyntaxToken>& newTokens)
  36225. {
  36226. CodeDocument::Iterator lastIterator (source);
  36227. const int lineLength = lineText.length();
  36228. for (;;)
  36229. {
  36230. int tokenType = analyser->readNextToken (source);
  36231. int tokenStart = lastIterator.getPosition();
  36232. int tokenEnd = source.getPosition();
  36233. if (tokenEnd <= tokenStart)
  36234. break;
  36235. tokenEnd -= startPosition;
  36236. if (tokenEnd > 0)
  36237. {
  36238. tokenStart -= startPosition;
  36239. newTokens.add (SyntaxToken (lineText.substring (jmax (0, tokenStart), tokenEnd),
  36240. tokenType));
  36241. if (tokenEnd >= lineLength)
  36242. break;
  36243. }
  36244. lastIterator = source;
  36245. }
  36246. source = lastIterator;
  36247. }
  36248. static void replaceTabsWithSpaces (Array <SyntaxToken>& tokens, const int spacesPerTab) throw()
  36249. {
  36250. int x = 0;
  36251. for (int i = 0; i < tokens.size(); ++i)
  36252. {
  36253. SyntaxToken& t = tokens.getReference(i);
  36254. for (;;)
  36255. {
  36256. int tabPos = t.text.indexOfChar (T('\t'));
  36257. if (tabPos < 0)
  36258. break;
  36259. const int spacesNeeded = spacesPerTab - ((tabPos + x) % spacesPerTab);
  36260. t.text = t.text.replaceSection (tabPos, 1, String::repeatedString (T(" "), spacesNeeded));
  36261. }
  36262. x += t.text.length();
  36263. }
  36264. }
  36265. int indexToColumn (int index, const String& line, int spacesPerTab) const throw()
  36266. {
  36267. jassert (index <= line.length());
  36268. int col = 0;
  36269. for (int i = 0; i < index; ++i)
  36270. {
  36271. if (line[i] != T('\t'))
  36272. ++col;
  36273. else
  36274. col += spacesPerTab - (col % spacesPerTab);
  36275. }
  36276. return col;
  36277. }
  36278. };
  36279. CodeEditorComponent::CodeEditorComponent (CodeDocument& document_,
  36280. CodeTokeniser* const codeTokeniser_)
  36281. : document (document_),
  36282. firstLineOnScreen (0),
  36283. gutter (5),
  36284. spacesPerTab (4),
  36285. lineHeight (0),
  36286. linesOnScreen (0),
  36287. columnsOnScreen (0),
  36288. scrollbarThickness (16),
  36289. columnToTryToMaintain (-1),
  36290. useSpacesForTabs (false),
  36291. xOffset (0),
  36292. codeTokeniser (codeTokeniser_)
  36293. {
  36294. caretPos = CodeDocument::Position (&document_, 0, 0);
  36295. caretPos.setPositionMaintained (true);
  36296. selectionStart = CodeDocument::Position (&document_, 0, 0);
  36297. selectionStart.setPositionMaintained (true);
  36298. selectionEnd = CodeDocument::Position (&document_, 0, 0);
  36299. selectionEnd.setPositionMaintained (true);
  36300. setOpaque (true);
  36301. setMouseCursor (MouseCursor (MouseCursor::IBeamCursor));
  36302. setWantsKeyboardFocus (true);
  36303. addAndMakeVisible (verticalScrollBar = new ScrollBar (true));
  36304. verticalScrollBar->setSingleStepSize (1.0);
  36305. addAndMakeVisible (horizontalScrollBar = new ScrollBar (false));
  36306. horizontalScrollBar->setSingleStepSize (1.0);
  36307. addAndMakeVisible (caret = new CaretComponent());
  36308. Font f (12.0f);
  36309. f.setTypefaceName (Font::getDefaultMonospacedFontName());
  36310. setFont (f);
  36311. resetToDefaultColours();
  36312. verticalScrollBar->addListener (this);
  36313. horizontalScrollBar->addListener (this);
  36314. document.addListener (this);
  36315. }
  36316. CodeEditorComponent::~CodeEditorComponent()
  36317. {
  36318. document.removeListener (this);
  36319. deleteAllChildren();
  36320. }
  36321. void CodeEditorComponent::loadContent (const String& newContent)
  36322. {
  36323. clearCachedIterators (0);
  36324. document.replaceAllContent (newContent);
  36325. document.clearUndoHistory();
  36326. document.setSavePoint();
  36327. caretPos.setPosition (0);
  36328. selectionStart.setPosition (0);
  36329. selectionEnd.setPosition (0);
  36330. scrollToLine (0);
  36331. }
  36332. void CodeEditorComponent::codeDocumentChanged (const CodeDocument::Position& affectedTextStart,
  36333. const CodeDocument::Position& affectedTextEnd)
  36334. {
  36335. clearCachedIterators (affectedTextStart.getLineNumber());
  36336. triggerAsyncUpdate();
  36337. ((CaretComponent*) caret)->updatePosition (*this);
  36338. columnToTryToMaintain = -1;
  36339. if (affectedTextEnd.getPosition() >= selectionStart.getPosition()
  36340. && affectedTextStart.getPosition() <= selectionEnd.getPosition())
  36341. deselectAll();
  36342. if (caretPos.getPosition() > affectedTextEnd.getPosition()
  36343. || caretPos.getPosition() < affectedTextStart.getPosition())
  36344. moveCaretTo (affectedTextStart, false);
  36345. updateScrollBars();
  36346. }
  36347. void CodeEditorComponent::resized()
  36348. {
  36349. linesOnScreen = (getHeight() - scrollbarThickness) / lineHeight;
  36350. columnsOnScreen = (int) ((getWidth() - scrollbarThickness) / charWidth);
  36351. lines.clear();
  36352. rebuildLineTokens();
  36353. ((CaretComponent*) caret)->updatePosition (*this);
  36354. verticalScrollBar->setBounds (getWidth() - scrollbarThickness, 0, scrollbarThickness, getHeight() - scrollbarThickness);
  36355. horizontalScrollBar->setBounds (gutter, getHeight() - scrollbarThickness, getWidth() - scrollbarThickness - gutter, scrollbarThickness);
  36356. updateScrollBars();
  36357. }
  36358. void CodeEditorComponent::paint (Graphics& g)
  36359. {
  36360. handleUpdateNowIfNeeded();
  36361. g.fillAll (findColour (CodeEditorComponent::backgroundColourId));
  36362. g.reduceClipRegion (gutter, 0, verticalScrollBar->getX() - gutter, horizontalScrollBar->getY());
  36363. g.setFont (font);
  36364. const int baselineOffset = (int) font.getAscent();
  36365. const Colour defaultColour (findColour (CodeEditorComponent::defaultTextColourId));
  36366. const Colour highlightColour (findColour (CodeEditorComponent::highlightColourId));
  36367. const Rectangle<int> clip (g.getClipBounds());
  36368. const int firstLineToDraw = jmax (0, clip.getY() / lineHeight);
  36369. const int lastLineToDraw = jmin (lines.size(), clip.getBottom() / lineHeight + 1);
  36370. for (int j = firstLineToDraw; j < lastLineToDraw; ++j)
  36371. {
  36372. lines.getUnchecked(j)->draw (*this, g, font,
  36373. (float) (gutter - xOffset * charWidth),
  36374. lineHeight * j, baselineOffset, lineHeight,
  36375. highlightColour);
  36376. }
  36377. }
  36378. void CodeEditorComponent::setScrollbarThickness (const int thickness) throw()
  36379. {
  36380. if (scrollbarThickness != thickness)
  36381. {
  36382. scrollbarThickness = thickness;
  36383. resized();
  36384. }
  36385. }
  36386. void CodeEditorComponent::handleAsyncUpdate()
  36387. {
  36388. rebuildLineTokens();
  36389. }
  36390. void CodeEditorComponent::rebuildLineTokens()
  36391. {
  36392. cancelPendingUpdate();
  36393. const int numNeeded = linesOnScreen + 1;
  36394. int minLineToRepaint = numNeeded;
  36395. int maxLineToRepaint = 0;
  36396. if (numNeeded != lines.size())
  36397. {
  36398. lines.clear();
  36399. for (int i = numNeeded; --i >= 0;)
  36400. lines.add (new CodeEditorLine());
  36401. minLineToRepaint = 0;
  36402. maxLineToRepaint = numNeeded;
  36403. }
  36404. jassert (numNeeded == lines.size());
  36405. CodeDocument::Iterator source (&document);
  36406. getIteratorForPosition (CodeDocument::Position (&document, firstLineOnScreen, 0).getPosition(), source);
  36407. for (int i = 0; i < numNeeded; ++i)
  36408. {
  36409. CodeEditorLine* const line = lines.getUnchecked(i);
  36410. if (line->update (document, firstLineOnScreen + i, source, codeTokeniser, spacesPerTab,
  36411. selectionStart, selectionEnd))
  36412. {
  36413. minLineToRepaint = jmin (minLineToRepaint, i);
  36414. maxLineToRepaint = jmax (maxLineToRepaint, i);
  36415. }
  36416. }
  36417. if (minLineToRepaint <= maxLineToRepaint)
  36418. {
  36419. repaint (gutter, lineHeight * minLineToRepaint - 1,
  36420. verticalScrollBar->getX() - gutter,
  36421. lineHeight * (1 + maxLineToRepaint - minLineToRepaint) + 2);
  36422. }
  36423. }
  36424. void CodeEditorComponent::moveCaretTo (const CodeDocument::Position& newPos, const bool highlighting)
  36425. {
  36426. caretPos = newPos;
  36427. columnToTryToMaintain = -1;
  36428. if (highlighting)
  36429. {
  36430. if (dragType == notDragging)
  36431. {
  36432. if (abs (caretPos.getPosition() - selectionStart.getPosition())
  36433. < abs (caretPos.getPosition() - selectionEnd.getPosition()))
  36434. dragType = draggingSelectionStart;
  36435. else
  36436. dragType = draggingSelectionEnd;
  36437. }
  36438. if (dragType == draggingSelectionStart)
  36439. {
  36440. selectionStart = caretPos;
  36441. if (selectionEnd.getPosition() < selectionStart.getPosition())
  36442. {
  36443. const CodeDocument::Position temp (selectionStart);
  36444. selectionStart = selectionEnd;
  36445. selectionEnd = temp;
  36446. dragType = draggingSelectionEnd;
  36447. }
  36448. }
  36449. else
  36450. {
  36451. selectionEnd = caretPos;
  36452. if (selectionEnd.getPosition() < selectionStart.getPosition())
  36453. {
  36454. const CodeDocument::Position temp (selectionStart);
  36455. selectionStart = selectionEnd;
  36456. selectionEnd = temp;
  36457. dragType = draggingSelectionStart;
  36458. }
  36459. }
  36460. triggerAsyncUpdate();
  36461. }
  36462. else
  36463. {
  36464. deselectAll();
  36465. }
  36466. ((CaretComponent*) caret)->updatePosition (*this);
  36467. scrollToKeepCaretOnScreen();
  36468. updateScrollBars();
  36469. }
  36470. void CodeEditorComponent::deselectAll()
  36471. {
  36472. if (selectionStart != selectionEnd)
  36473. triggerAsyncUpdate();
  36474. selectionStart = caretPos;
  36475. selectionEnd = caretPos;
  36476. }
  36477. void CodeEditorComponent::updateScrollBars()
  36478. {
  36479. verticalScrollBar->setRangeLimits (0, jmax (document.getNumLines(), firstLineOnScreen + linesOnScreen));
  36480. verticalScrollBar->setCurrentRange (firstLineOnScreen, linesOnScreen);
  36481. horizontalScrollBar->setRangeLimits (0, jmax ((double) document.getMaximumLineLength(), xOffset + columnsOnScreen));
  36482. horizontalScrollBar->setCurrentRange (xOffset, columnsOnScreen);
  36483. }
  36484. void CodeEditorComponent::scrollToLineInternal (int newFirstLineOnScreen)
  36485. {
  36486. newFirstLineOnScreen = jlimit (0, jmax (0, document.getNumLines() - 1),
  36487. newFirstLineOnScreen);
  36488. if (newFirstLineOnScreen != firstLineOnScreen)
  36489. {
  36490. firstLineOnScreen = newFirstLineOnScreen;
  36491. ((CaretComponent*) caret)->updatePosition (*this);
  36492. updateCachedIterators (firstLineOnScreen);
  36493. triggerAsyncUpdate();
  36494. }
  36495. }
  36496. void CodeEditorComponent::scrollToColumnInternal (double column)
  36497. {
  36498. const double newOffset = jlimit (0.0, document.getMaximumLineLength() + 3.0, column);
  36499. if (xOffset != newOffset)
  36500. {
  36501. xOffset = newOffset;
  36502. ((CaretComponent*) caret)->updatePosition (*this);
  36503. repaint();
  36504. }
  36505. }
  36506. void CodeEditorComponent::scrollToLine (int newFirstLineOnScreen)
  36507. {
  36508. scrollToLineInternal (newFirstLineOnScreen);
  36509. updateScrollBars();
  36510. }
  36511. void CodeEditorComponent::scrollToColumn (int newFirstColumnOnScreen)
  36512. {
  36513. scrollToColumnInternal (newFirstColumnOnScreen);
  36514. updateScrollBars();
  36515. }
  36516. void CodeEditorComponent::scrollBy (int deltaLines)
  36517. {
  36518. scrollToLine (firstLineOnScreen + deltaLines);
  36519. }
  36520. void CodeEditorComponent::scrollToKeepCaretOnScreen()
  36521. {
  36522. if (caretPos.getLineNumber() < firstLineOnScreen)
  36523. scrollBy (caretPos.getLineNumber() - firstLineOnScreen);
  36524. else if (caretPos.getLineNumber() >= firstLineOnScreen + linesOnScreen)
  36525. scrollBy (caretPos.getLineNumber() - (firstLineOnScreen + linesOnScreen - 1));
  36526. const int column = indexToColumn (caretPos.getLineNumber(), caretPos.getIndexInLine());
  36527. if (column >= xOffset + columnsOnScreen - 1)
  36528. scrollToColumn (column + 1 - columnsOnScreen);
  36529. else if (column < xOffset)
  36530. scrollToColumn (column);
  36531. }
  36532. const Rectangle<int> CodeEditorComponent::getCharacterBounds (const CodeDocument::Position& pos) const throw()
  36533. {
  36534. return Rectangle<int> (roundToInt ((gutter - xOffset * charWidth) + indexToColumn (pos.getLineNumber(), pos.getIndexInLine()) * charWidth),
  36535. (pos.getLineNumber() - firstLineOnScreen) * lineHeight,
  36536. roundToInt (charWidth),
  36537. lineHeight);
  36538. }
  36539. const CodeDocument::Position CodeEditorComponent::getPositionAt (int x, int y)
  36540. {
  36541. const int line = y / lineHeight + firstLineOnScreen;
  36542. const int column = roundToInt ((x - (gutter - xOffset * charWidth)) / charWidth);
  36543. const int index = columnToIndex (line, column);
  36544. return CodeDocument::Position (&document, line, index);
  36545. }
  36546. void CodeEditorComponent::insertTextAtCaret (const String& newText)
  36547. {
  36548. document.deleteSection (selectionStart, selectionEnd);
  36549. if (newText.isNotEmpty())
  36550. document.insertText (caretPos, newText);
  36551. scrollToKeepCaretOnScreen();
  36552. }
  36553. void CodeEditorComponent::insertTabAtCaret()
  36554. {
  36555. if (CharacterFunctions::isWhitespace (caretPos.getCharacter())
  36556. && caretPos.getLineNumber() == caretPos.movedBy (1).getLineNumber())
  36557. {
  36558. moveCaretTo (document.findWordBreakAfter (caretPos), false);
  36559. }
  36560. if (useSpacesForTabs)
  36561. {
  36562. const int caretCol = indexToColumn (caretPos.getLineNumber(), caretPos.getIndexInLine());
  36563. const int spacesNeeded = spacesPerTab - (caretCol % spacesPerTab);
  36564. insertTextAtCaret (String::repeatedString (T(" "), spacesNeeded));
  36565. }
  36566. else
  36567. {
  36568. insertTextAtCaret (T("\t"));
  36569. }
  36570. }
  36571. void CodeEditorComponent::cut()
  36572. {
  36573. insertTextAtCaret (String::empty);
  36574. }
  36575. void CodeEditorComponent::copy()
  36576. {
  36577. newTransaction();
  36578. const String selection (document.getTextBetween (selectionStart, selectionEnd));
  36579. if (selection.isNotEmpty())
  36580. SystemClipboard::copyTextToClipboard (selection);
  36581. }
  36582. void CodeEditorComponent::copyThenCut()
  36583. {
  36584. copy();
  36585. cut();
  36586. newTransaction();
  36587. }
  36588. void CodeEditorComponent::paste()
  36589. {
  36590. newTransaction();
  36591. const String clip (SystemClipboard::getTextFromClipboard());
  36592. if (clip.isNotEmpty())
  36593. insertTextAtCaret (clip);
  36594. newTransaction();
  36595. }
  36596. void CodeEditorComponent::cursorLeft (const bool moveInWholeWordSteps, const bool selecting)
  36597. {
  36598. newTransaction();
  36599. if (moveInWholeWordSteps)
  36600. moveCaretTo (document.findWordBreakBefore (caretPos), selecting);
  36601. else
  36602. moveCaretTo (caretPos.movedBy (-1), selecting);
  36603. }
  36604. void CodeEditorComponent::cursorRight (const bool moveInWholeWordSteps, const bool selecting)
  36605. {
  36606. newTransaction();
  36607. if (moveInWholeWordSteps)
  36608. moveCaretTo (document.findWordBreakAfter (caretPos), selecting);
  36609. else
  36610. moveCaretTo (caretPos.movedBy (1), selecting);
  36611. }
  36612. void CodeEditorComponent::moveLineDelta (const int delta, const bool selecting)
  36613. {
  36614. CodeDocument::Position pos (caretPos);
  36615. const int newLineNum = pos.getLineNumber() + delta;
  36616. if (columnToTryToMaintain < 0)
  36617. columnToTryToMaintain = indexToColumn (pos.getLineNumber(), pos.getIndexInLine());
  36618. pos.setLineAndIndex (newLineNum, columnToIndex (newLineNum, columnToTryToMaintain));
  36619. const int colToMaintain = columnToTryToMaintain;
  36620. moveCaretTo (pos, selecting);
  36621. columnToTryToMaintain = colToMaintain;
  36622. }
  36623. void CodeEditorComponent::cursorDown (const bool selecting)
  36624. {
  36625. newTransaction();
  36626. if (caretPos.getLineNumber() == document.getNumLines() - 1)
  36627. moveCaretTo (CodeDocument::Position (&document, std::numeric_limits<int>::max(), std::numeric_limits<int>::max()), selecting);
  36628. else
  36629. moveLineDelta (1, selecting);
  36630. }
  36631. void CodeEditorComponent::cursorUp (const bool selecting)
  36632. {
  36633. newTransaction();
  36634. if (caretPos.getLineNumber() == 0)
  36635. moveCaretTo (CodeDocument::Position (&document, 0, 0), selecting);
  36636. else
  36637. moveLineDelta (-1, selecting);
  36638. }
  36639. void CodeEditorComponent::pageDown (const bool selecting)
  36640. {
  36641. newTransaction();
  36642. scrollBy (jlimit (0, linesOnScreen, 1 + document.getNumLines() - firstLineOnScreen - linesOnScreen));
  36643. moveLineDelta (linesOnScreen, selecting);
  36644. }
  36645. void CodeEditorComponent::pageUp (const bool selecting)
  36646. {
  36647. newTransaction();
  36648. scrollBy (-linesOnScreen);
  36649. moveLineDelta (-linesOnScreen, selecting);
  36650. }
  36651. void CodeEditorComponent::scrollUp()
  36652. {
  36653. newTransaction();
  36654. scrollBy (1);
  36655. if (caretPos.getLineNumber() < firstLineOnScreen)
  36656. moveLineDelta (1, false);
  36657. }
  36658. void CodeEditorComponent::scrollDown()
  36659. {
  36660. newTransaction();
  36661. scrollBy (-1);
  36662. if (caretPos.getLineNumber() >= firstLineOnScreen + linesOnScreen)
  36663. moveLineDelta (-1, false);
  36664. }
  36665. void CodeEditorComponent::goToStartOfDocument (const bool selecting)
  36666. {
  36667. newTransaction();
  36668. moveCaretTo (CodeDocument::Position (&document, 0, 0), selecting);
  36669. }
  36670. static int findFirstNonWhitespaceChar (const String& line) throw()
  36671. {
  36672. const int len = line.length();
  36673. for (int i = 0; i < len; ++i)
  36674. if (! CharacterFunctions::isWhitespace (line [i]))
  36675. return i;
  36676. return 0;
  36677. }
  36678. void CodeEditorComponent::goToStartOfLine (const bool selecting)
  36679. {
  36680. newTransaction();
  36681. int index = findFirstNonWhitespaceChar (caretPos.getLineText());
  36682. if (index >= caretPos.getIndexInLine() && caretPos.getIndexInLine() > 0)
  36683. index = 0;
  36684. moveCaretTo (CodeDocument::Position (&document, caretPos.getLineNumber(), index), selecting);
  36685. }
  36686. void CodeEditorComponent::goToEndOfDocument (const bool selecting)
  36687. {
  36688. newTransaction();
  36689. moveCaretTo (CodeDocument::Position (&document, std::numeric_limits<int>::max(), std::numeric_limits<int>::max()), selecting);
  36690. }
  36691. void CodeEditorComponent::goToEndOfLine (const bool selecting)
  36692. {
  36693. newTransaction();
  36694. moveCaretTo (CodeDocument::Position (&document, caretPos.getLineNumber(), std::numeric_limits<int>::max()), selecting);
  36695. }
  36696. void CodeEditorComponent::backspace (const bool moveInWholeWordSteps)
  36697. {
  36698. if (moveInWholeWordSteps)
  36699. {
  36700. cut(); // in case something is already highlighted
  36701. moveCaretTo (document.findWordBreakBefore (caretPos), true);
  36702. }
  36703. else
  36704. {
  36705. if (selectionStart == selectionEnd)
  36706. selectionStart.moveBy (-1);
  36707. }
  36708. cut();
  36709. }
  36710. void CodeEditorComponent::deleteForward (const bool moveInWholeWordSteps)
  36711. {
  36712. if (moveInWholeWordSteps)
  36713. {
  36714. cut(); // in case something is already highlighted
  36715. moveCaretTo (document.findWordBreakAfter (caretPos), true);
  36716. }
  36717. else
  36718. {
  36719. if (selectionStart == selectionEnd)
  36720. selectionEnd.moveBy (1);
  36721. else
  36722. newTransaction();
  36723. }
  36724. cut();
  36725. }
  36726. void CodeEditorComponent::selectAll()
  36727. {
  36728. newTransaction();
  36729. moveCaretTo (CodeDocument::Position (&document, std::numeric_limits<int>::max(), std::numeric_limits<int>::max()), false);
  36730. moveCaretTo (CodeDocument::Position (&document, 0, 0), true);
  36731. }
  36732. void CodeEditorComponent::undo()
  36733. {
  36734. document.undo();
  36735. scrollToKeepCaretOnScreen();
  36736. }
  36737. void CodeEditorComponent::redo()
  36738. {
  36739. document.redo();
  36740. scrollToKeepCaretOnScreen();
  36741. }
  36742. void CodeEditorComponent::newTransaction()
  36743. {
  36744. document.newTransaction();
  36745. startTimer (600);
  36746. }
  36747. void CodeEditorComponent::timerCallback()
  36748. {
  36749. newTransaction();
  36750. }
  36751. const Range<int> CodeEditorComponent::getHighlightedRegion() const
  36752. {
  36753. return Range<int> (selectionStart.getPosition(), selectionEnd.getPosition());
  36754. }
  36755. void CodeEditorComponent::setHighlightedRegion (const Range<int>& newRange)
  36756. {
  36757. moveCaretTo (CodeDocument::Position (&document, newRange.getStart()), false);
  36758. moveCaretTo (CodeDocument::Position (&document, newRange.getEnd()), true);
  36759. }
  36760. const String CodeEditorComponent::getTextInRange (const Range<int>& range) const
  36761. {
  36762. return document.getTextBetween (CodeDocument::Position (&document, range.getStart()),
  36763. CodeDocument::Position (&document, range.getEnd()));
  36764. }
  36765. bool CodeEditorComponent::keyPressed (const KeyPress& key)
  36766. {
  36767. const bool moveInWholeWordSteps = key.getModifiers().isCtrlDown() || key.getModifiers().isAltDown();
  36768. const bool shiftDown = key.getModifiers().isShiftDown();
  36769. if (key.isKeyCode (KeyPress::leftKey))
  36770. {
  36771. cursorLeft (moveInWholeWordSteps, shiftDown);
  36772. }
  36773. else if (key.isKeyCode (KeyPress::rightKey))
  36774. {
  36775. cursorRight (moveInWholeWordSteps, shiftDown);
  36776. }
  36777. else if (key.isKeyCode (KeyPress::upKey))
  36778. {
  36779. if (key.getModifiers().isCtrlDown() && ! shiftDown)
  36780. scrollDown();
  36781. #if JUCE_MAC
  36782. else if (key.getModifiers().isCommandDown())
  36783. goToStartOfDocument (shiftDown);
  36784. #endif
  36785. else
  36786. cursorUp (shiftDown);
  36787. }
  36788. else if (key.isKeyCode (KeyPress::downKey))
  36789. {
  36790. if (key.getModifiers().isCtrlDown() && ! shiftDown)
  36791. scrollUp();
  36792. #if JUCE_MAC
  36793. else if (key.getModifiers().isCommandDown())
  36794. goToEndOfDocument (shiftDown);
  36795. #endif
  36796. else
  36797. cursorDown (shiftDown);
  36798. }
  36799. else if (key.isKeyCode (KeyPress::pageDownKey))
  36800. {
  36801. pageDown (shiftDown);
  36802. }
  36803. else if (key.isKeyCode (KeyPress::pageUpKey))
  36804. {
  36805. pageUp (shiftDown);
  36806. }
  36807. else if (key.isKeyCode (KeyPress::homeKey))
  36808. {
  36809. if (moveInWholeWordSteps)
  36810. goToStartOfDocument (shiftDown);
  36811. else
  36812. goToStartOfLine (shiftDown);
  36813. }
  36814. else if (key.isKeyCode (KeyPress::endKey))
  36815. {
  36816. if (moveInWholeWordSteps)
  36817. goToEndOfDocument (shiftDown);
  36818. else
  36819. goToEndOfLine (shiftDown);
  36820. }
  36821. else if (key.isKeyCode (KeyPress::backspaceKey))
  36822. {
  36823. backspace (moveInWholeWordSteps);
  36824. }
  36825. else if (key.isKeyCode (KeyPress::deleteKey))
  36826. {
  36827. deleteForward (moveInWholeWordSteps);
  36828. }
  36829. else if (key == KeyPress (T('c'), ModifierKeys::commandModifier, 0))
  36830. {
  36831. copy();
  36832. }
  36833. else if (key == KeyPress (T('x'), ModifierKeys::commandModifier, 0))
  36834. {
  36835. copyThenCut();
  36836. }
  36837. else if (key == KeyPress (T('v'), ModifierKeys::commandModifier, 0))
  36838. {
  36839. paste();
  36840. }
  36841. else if (key == KeyPress (T('z'), ModifierKeys::commandModifier, 0))
  36842. {
  36843. undo();
  36844. }
  36845. else if (key == KeyPress (T('y'), ModifierKeys::commandModifier, 0)
  36846. || key == KeyPress (T('z'), ModifierKeys::commandModifier | ModifierKeys::shiftModifier, 0))
  36847. {
  36848. redo();
  36849. }
  36850. else if (key == KeyPress (T('a'), ModifierKeys::commandModifier, 0))
  36851. {
  36852. selectAll();
  36853. }
  36854. else if (key == KeyPress::tabKey || key.getTextCharacter() == '\t')
  36855. {
  36856. insertTabAtCaret();
  36857. }
  36858. else if (key == KeyPress::returnKey)
  36859. {
  36860. newTransaction();
  36861. insertTextAtCaret (document.getNewLineCharacters());
  36862. }
  36863. else if (key.isKeyCode (KeyPress::escapeKey))
  36864. {
  36865. newTransaction();
  36866. }
  36867. else if (key.getTextCharacter() >= ' ')
  36868. {
  36869. insertTextAtCaret (String::charToString (key.getTextCharacter()));
  36870. }
  36871. else
  36872. {
  36873. return false;
  36874. }
  36875. return true;
  36876. }
  36877. void CodeEditorComponent::mouseDown (const MouseEvent& e)
  36878. {
  36879. newTransaction();
  36880. dragType = notDragging;
  36881. if (! e.mods.isPopupMenu())
  36882. {
  36883. beginDragAutoRepeat (100);
  36884. moveCaretTo (getPositionAt (e.x, e.y), e.mods.isShiftDown());
  36885. }
  36886. else
  36887. {
  36888. }
  36889. }
  36890. void CodeEditorComponent::mouseDrag (const MouseEvent& e)
  36891. {
  36892. if (! e.mods.isPopupMenu())
  36893. moveCaretTo (getPositionAt (e.x, e.y), true);
  36894. }
  36895. void CodeEditorComponent::mouseUp (const MouseEvent&)
  36896. {
  36897. newTransaction();
  36898. beginDragAutoRepeat (0);
  36899. dragType = notDragging;
  36900. }
  36901. void CodeEditorComponent::mouseDoubleClick (const MouseEvent& e)
  36902. {
  36903. CodeDocument::Position tokenStart (getPositionAt (e.x, e.y));
  36904. CodeDocument::Position tokenEnd (tokenStart);
  36905. if (e.getNumberOfClicks() > 2)
  36906. {
  36907. tokenStart.setLineAndIndex (tokenStart.getLineNumber(), 0);
  36908. tokenEnd.setLineAndIndex (tokenStart.getLineNumber() + 1, 0);
  36909. }
  36910. else
  36911. {
  36912. while (CharacterFunctions::isLetterOrDigit (tokenEnd.getCharacter()))
  36913. tokenEnd.moveBy (1);
  36914. tokenStart = tokenEnd;
  36915. while (tokenStart.getIndexInLine() > 0
  36916. && CharacterFunctions::isLetterOrDigit (tokenStart.movedBy (-1).getCharacter()))
  36917. tokenStart.moveBy (-1);
  36918. }
  36919. moveCaretTo (tokenEnd, false);
  36920. moveCaretTo (tokenStart, true);
  36921. }
  36922. void CodeEditorComponent::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  36923. {
  36924. verticalScrollBar->mouseWheelMove (e, 0, wheelIncrementY);
  36925. horizontalScrollBar->mouseWheelMove (e, wheelIncrementX, 0);
  36926. }
  36927. void CodeEditorComponent::scrollBarMoved (ScrollBar* scrollBarThatHasMoved, const double newRangeStart)
  36928. {
  36929. if (scrollBarThatHasMoved == verticalScrollBar)
  36930. scrollToLineInternal ((int) newRangeStart);
  36931. else
  36932. scrollToColumnInternal (newRangeStart);
  36933. }
  36934. void CodeEditorComponent::setTabSize (const int numSpaces, const bool insertSpaces) throw()
  36935. {
  36936. useSpacesForTabs = insertSpaces;
  36937. if (spacesPerTab != numSpaces)
  36938. {
  36939. spacesPerTab = numSpaces;
  36940. triggerAsyncUpdate();
  36941. }
  36942. }
  36943. int CodeEditorComponent::indexToColumn (int lineNum, int index) const throw()
  36944. {
  36945. const String line (document.getLine (lineNum));
  36946. jassert (index <= line.length());
  36947. int col = 0;
  36948. for (int i = 0; i < index; ++i)
  36949. {
  36950. if (line[i] != T('\t'))
  36951. ++col;
  36952. else
  36953. col += getTabSize() - (col % getTabSize());
  36954. }
  36955. return col;
  36956. }
  36957. int CodeEditorComponent::columnToIndex (int lineNum, int column) const throw()
  36958. {
  36959. const String line (document.getLine (lineNum));
  36960. const int lineLength = line.length();
  36961. int i, col = 0;
  36962. for (i = 0; i < lineLength; ++i)
  36963. {
  36964. if (line[i] != T('\t'))
  36965. ++col;
  36966. else
  36967. col += getTabSize() - (col % getTabSize());
  36968. if (col > column)
  36969. break;
  36970. }
  36971. return i;
  36972. }
  36973. void CodeEditorComponent::setFont (const Font& newFont)
  36974. {
  36975. font = newFont;
  36976. charWidth = font.getStringWidthFloat (T("0"));
  36977. lineHeight = roundToInt (font.getHeight());
  36978. resized();
  36979. }
  36980. void CodeEditorComponent::resetToDefaultColours()
  36981. {
  36982. coloursForTokenCategories.clear();
  36983. if (codeTokeniser != 0)
  36984. {
  36985. for (int i = codeTokeniser->getTokenTypes().size(); --i >= 0;)
  36986. setColourForTokenType (i, codeTokeniser->getDefaultColour (i));
  36987. }
  36988. }
  36989. void CodeEditorComponent::setColourForTokenType (const int tokenType, const Colour& colour)
  36990. {
  36991. jassert (tokenType < 256);
  36992. while (coloursForTokenCategories.size() < tokenType)
  36993. coloursForTokenCategories.add (Colours::black);
  36994. coloursForTokenCategories.set (tokenType, colour);
  36995. repaint();
  36996. }
  36997. const Colour CodeEditorComponent::getColourForTokenType (const int tokenType) const throw()
  36998. {
  36999. if (((unsigned int) tokenType) >= (unsigned int) coloursForTokenCategories.size())
  37000. return findColour (CodeEditorComponent::defaultTextColourId);
  37001. return coloursForTokenCategories.getReference (tokenType);
  37002. }
  37003. void CodeEditorComponent::clearCachedIterators (const int firstLineToBeInvalid) throw()
  37004. {
  37005. int i;
  37006. for (i = cachedIterators.size(); --i >= 0;)
  37007. if (cachedIterators.getUnchecked (i)->getLine() < firstLineToBeInvalid)
  37008. break;
  37009. cachedIterators.removeRange (jmax (0, i - 1), cachedIterators.size());
  37010. }
  37011. void CodeEditorComponent::updateCachedIterators (int maxLineNum)
  37012. {
  37013. const int maxNumCachedPositions = 5000;
  37014. const int linesBetweenCachedSources = jmax (10, document.getNumLines() / maxNumCachedPositions);
  37015. if (cachedIterators.size() == 0)
  37016. cachedIterators.add (new CodeDocument::Iterator (&document));
  37017. if (codeTokeniser == 0)
  37018. return;
  37019. for (;;)
  37020. {
  37021. CodeDocument::Iterator* last = cachedIterators.getLast();
  37022. if (last->getLine() >= maxLineNum)
  37023. break;
  37024. CodeDocument::Iterator* t = new CodeDocument::Iterator (*last);
  37025. cachedIterators.add (t);
  37026. const int targetLine = last->getLine() + linesBetweenCachedSources;
  37027. for (;;)
  37028. {
  37029. codeTokeniser->readNextToken (*t);
  37030. if (t->getLine() >= targetLine)
  37031. break;
  37032. if (t->isEOF())
  37033. return;
  37034. }
  37035. }
  37036. }
  37037. void CodeEditorComponent::getIteratorForPosition (int position, CodeDocument::Iterator& source)
  37038. {
  37039. if (codeTokeniser == 0)
  37040. return;
  37041. for (int i = cachedIterators.size(); --i >= 0;)
  37042. {
  37043. CodeDocument::Iterator* t = cachedIterators.getUnchecked (i);
  37044. if (t->getPosition() <= position)
  37045. {
  37046. source = *t;
  37047. break;
  37048. }
  37049. }
  37050. while (source.getPosition() < position)
  37051. {
  37052. const CodeDocument::Iterator original (source);
  37053. codeTokeniser->readNextToken (source);
  37054. if (source.getPosition() > position || source.isEOF())
  37055. {
  37056. source = original;
  37057. break;
  37058. }
  37059. }
  37060. }
  37061. END_JUCE_NAMESPACE
  37062. /*** End of inlined file: juce_CodeEditorComponent.cpp ***/
  37063. /*** Start of inlined file: juce_CPlusPlusCodeTokeniser.cpp ***/
  37064. BEGIN_JUCE_NAMESPACE
  37065. CPlusPlusCodeTokeniser::CPlusPlusCodeTokeniser()
  37066. {
  37067. }
  37068. CPlusPlusCodeTokeniser::~CPlusPlusCodeTokeniser()
  37069. {
  37070. }
  37071. namespace CppTokeniser
  37072. {
  37073. static bool isIdentifierStart (const tchar c) throw()
  37074. {
  37075. return CharacterFunctions::isLetter (c)
  37076. || c == T('_') || c == T('@');
  37077. }
  37078. static bool isIdentifierBody (const tchar c) throw()
  37079. {
  37080. return CharacterFunctions::isLetter (c)
  37081. || CharacterFunctions::isDigit (c)
  37082. || c == T('_') || c == T('@');
  37083. }
  37084. static int parseIdentifier (CodeDocument::Iterator& source) throw()
  37085. {
  37086. static const tchar* keywords2Char[] =
  37087. { T("if"), T("do"), T("or"), 0 };
  37088. static const tchar* keywords3Char[] =
  37089. { T("for"), T("int"), T("new"), T("try"), T("xor"), T("and"), T("asm"), T("not"), 0 };
  37090. static const tchar* keywords4Char[] =
  37091. { T("bool"), T("void"), T("this"), T("true"), T("long"), T("else"), T("char"),
  37092. T("enum"), T("case"), T("goto"), T("auto"), 0 };
  37093. static const tchar* keywords5Char[] =
  37094. { T("while"), T("bitor"), T("break"), T("catch"), T("class"), T("compl"), T("const"), T("false"),
  37095. T("float"), T("short"), T("throw"), T("union"), T("using"), T("or_eq"), 0 };
  37096. static const tchar* keywords6Char[] =
  37097. { T("return"), T("struct"), T("and_eq"), T("bitand"), T("delete"), T("double"), T("extern"),
  37098. T("friend"), T("inline"), T("not_eq"), T("public"), T("sizeof"), T("static"), T("signed"),
  37099. T("switch"), T("typeid"), T("wchar_t"), T("xor_eq"), 0};
  37100. static const tchar* keywordsOther[] =
  37101. { T("const_cast"), T("continue"), T("default"), T("explicit"), T("mutable"), T("namespace"),
  37102. T("operator"), T("private"), T("protected"), T("register"), T("reinterpret_cast"), T("static_cast"),
  37103. T("template"), T("typedef"), T("typename"), T("unsigned"), T("virtual"), T("volatile"),
  37104. T("@implementation"), T("@interface"), T("@end"), T("@synthesize"), T("@dynamic"), T("@public"),
  37105. T("@private"), T("@property"), T("@protected"), T("@class"), 0 };
  37106. int tokenLength = 0;
  37107. tchar possibleIdentifier [19];
  37108. while (isIdentifierBody (source.peekNextChar()))
  37109. {
  37110. const tchar c = source.nextChar();
  37111. if (tokenLength < numElementsInArray (possibleIdentifier) - 1)
  37112. possibleIdentifier [tokenLength] = c;
  37113. ++tokenLength;
  37114. }
  37115. if (tokenLength > 1 && tokenLength <= 16)
  37116. {
  37117. possibleIdentifier [tokenLength] = 0;
  37118. const tchar** k;
  37119. switch (tokenLength)
  37120. {
  37121. case 2: k = keywords2Char; break;
  37122. case 3: k = keywords3Char; break;
  37123. case 4: k = keywords4Char; break;
  37124. case 5: k = keywords5Char; break;
  37125. case 6: k = keywords6Char; break;
  37126. default: k = keywordsOther; break;
  37127. }
  37128. int i = 0;
  37129. while (k[i] != 0)
  37130. {
  37131. if (k[i][0] == possibleIdentifier[0] && CharacterFunctions::compare (k[i], possibleIdentifier) == 0)
  37132. return CPlusPlusCodeTokeniser::tokenType_builtInKeyword;
  37133. ++i;
  37134. }
  37135. }
  37136. return CPlusPlusCodeTokeniser::tokenType_identifier;
  37137. }
  37138. static bool skipNumberSuffix (CodeDocument::Iterator& source)
  37139. {
  37140. const juce_wchar c = source.peekNextChar();
  37141. if (c == 'l' || c == 'L' || c == 'u' || c == 'U')
  37142. source.skip();
  37143. if (CharacterFunctions::isLetterOrDigit (source.peekNextChar()))
  37144. return false;
  37145. return true;
  37146. }
  37147. static bool isHexDigit (const juce_wchar c) throw()
  37148. {
  37149. return (c >= '0' && c <= '9')
  37150. || (c >= 'a' && c <= 'f')
  37151. || (c >= 'A' && c <= 'F');
  37152. }
  37153. static bool parseHexLiteral (CodeDocument::Iterator& source) throw()
  37154. {
  37155. if (source.nextChar() != '0')
  37156. return false;
  37157. juce_wchar c = source.nextChar();
  37158. if (c != 'x' && c != 'X')
  37159. return false;
  37160. int numDigits = 0;
  37161. while (isHexDigit (source.peekNextChar()))
  37162. {
  37163. ++numDigits;
  37164. source.skip();
  37165. }
  37166. if (numDigits == 0)
  37167. return false;
  37168. return skipNumberSuffix (source);
  37169. }
  37170. static bool isOctalDigit (const juce_wchar c) throw()
  37171. {
  37172. return c >= '0' && c <= '7';
  37173. }
  37174. static bool parseOctalLiteral (CodeDocument::Iterator& source) throw()
  37175. {
  37176. if (source.nextChar() != '0')
  37177. return false;
  37178. if (! isOctalDigit (source.nextChar()))
  37179. return false;
  37180. while (isOctalDigit (source.peekNextChar()))
  37181. source.skip();
  37182. return skipNumberSuffix (source);
  37183. }
  37184. static bool isDecimalDigit (const juce_wchar c) throw()
  37185. {
  37186. return c >= '0' && c <= '9';
  37187. }
  37188. static bool parseDecimalLiteral (CodeDocument::Iterator& source) throw()
  37189. {
  37190. int numChars = 0;
  37191. while (isDecimalDigit (source.peekNextChar()))
  37192. {
  37193. ++numChars;
  37194. source.skip();
  37195. }
  37196. if (numChars == 0)
  37197. return false;
  37198. return skipNumberSuffix (source);
  37199. }
  37200. static bool parseFloatLiteral (CodeDocument::Iterator& source) throw()
  37201. {
  37202. int numDigits = 0;
  37203. while (isDecimalDigit (source.peekNextChar()))
  37204. {
  37205. source.skip();
  37206. ++numDigits;
  37207. }
  37208. const bool hasPoint = (source.peekNextChar() == '.');
  37209. if (hasPoint)
  37210. {
  37211. source.skip();
  37212. while (isDecimalDigit (source.peekNextChar()))
  37213. {
  37214. source.skip();
  37215. ++numDigits;
  37216. }
  37217. }
  37218. if (numDigits == 0)
  37219. return false;
  37220. juce_wchar c = source.peekNextChar();
  37221. const bool hasExponent = (c == 'e' || c == 'E');
  37222. if (hasExponent)
  37223. {
  37224. source.skip();
  37225. c = source.peekNextChar();
  37226. if (c == '+' || c == '-')
  37227. source.skip();
  37228. int numExpDigits = 0;
  37229. while (isDecimalDigit (source.peekNextChar()))
  37230. {
  37231. source.skip();
  37232. ++numExpDigits;
  37233. }
  37234. if (numExpDigits == 0)
  37235. return false;
  37236. }
  37237. c = source.peekNextChar();
  37238. if (c == 'f' || c == 'F')
  37239. source.skip();
  37240. else if (! (hasExponent || hasPoint))
  37241. return false;
  37242. return true;
  37243. }
  37244. static int parseNumber (CodeDocument::Iterator& source)
  37245. {
  37246. const CodeDocument::Iterator original (source);
  37247. if (parseFloatLiteral (source))
  37248. return CPlusPlusCodeTokeniser::tokenType_floatLiteral;
  37249. source = original;
  37250. if (parseHexLiteral (source))
  37251. return CPlusPlusCodeTokeniser::tokenType_integerLiteral;
  37252. source = original;
  37253. if (parseOctalLiteral (source))
  37254. return CPlusPlusCodeTokeniser::tokenType_integerLiteral;
  37255. source = original;
  37256. if (parseDecimalLiteral (source))
  37257. return CPlusPlusCodeTokeniser::tokenType_integerLiteral;
  37258. source = original;
  37259. source.skip();
  37260. return CPlusPlusCodeTokeniser::tokenType_error;
  37261. }
  37262. static void skipQuotedString (CodeDocument::Iterator& source) throw()
  37263. {
  37264. const juce_wchar quote = source.nextChar();
  37265. for (;;)
  37266. {
  37267. const juce_wchar c = source.nextChar();
  37268. if (c == quote || c == 0)
  37269. break;
  37270. if (c == '\\')
  37271. source.skip();
  37272. }
  37273. }
  37274. static void skipComment (CodeDocument::Iterator& source) throw()
  37275. {
  37276. bool lastWasStar = false;
  37277. for (;;)
  37278. {
  37279. const juce_wchar c = source.nextChar();
  37280. if (c == 0 || (c == T('/') && lastWasStar))
  37281. break;
  37282. lastWasStar = (c == '*');
  37283. }
  37284. }
  37285. }
  37286. int CPlusPlusCodeTokeniser::readNextToken (CodeDocument::Iterator& source)
  37287. {
  37288. int result = tokenType_error;
  37289. source.skipWhitespace();
  37290. tchar firstChar = source.peekNextChar();
  37291. switch (firstChar)
  37292. {
  37293. case 0:
  37294. source.skip();
  37295. break;
  37296. case T('0'):
  37297. case T('1'):
  37298. case T('2'):
  37299. case T('3'):
  37300. case T('4'):
  37301. case T('5'):
  37302. case T('6'):
  37303. case T('7'):
  37304. case T('8'):
  37305. case T('9'):
  37306. result = CppTokeniser::parseNumber (source);
  37307. break;
  37308. case T('.'):
  37309. result = CppTokeniser::parseNumber (source);
  37310. if (result == tokenType_error)
  37311. result = tokenType_punctuation;
  37312. break;
  37313. case T(','):
  37314. case T(';'):
  37315. case T(':'):
  37316. source.skip();
  37317. result = tokenType_punctuation;
  37318. break;
  37319. case T('('):
  37320. case T(')'):
  37321. case T('{'):
  37322. case T('}'):
  37323. case T('['):
  37324. case T(']'):
  37325. source.skip();
  37326. result = tokenType_bracket;
  37327. break;
  37328. case T('"'):
  37329. case T('\''):
  37330. CppTokeniser::skipQuotedString (source);
  37331. result = tokenType_stringLiteral;
  37332. break;
  37333. case T('+'):
  37334. result = tokenType_operator;
  37335. source.skip();
  37336. if (source.peekNextChar() == T('+'))
  37337. source.skip();
  37338. else if (source.peekNextChar() == T('='))
  37339. source.skip();
  37340. break;
  37341. case T('-'):
  37342. source.skip();
  37343. result = CppTokeniser::parseNumber (source);
  37344. if (result == tokenType_error)
  37345. {
  37346. result = tokenType_operator;
  37347. if (source.peekNextChar() == T('-'))
  37348. source.skip();
  37349. else if (source.peekNextChar() == T('='))
  37350. source.skip();
  37351. }
  37352. break;
  37353. case T('*'):
  37354. case T('%'):
  37355. case T('='):
  37356. case T('!'):
  37357. result = tokenType_operator;
  37358. source.skip();
  37359. if (source.peekNextChar() == T('='))
  37360. source.skip();
  37361. break;
  37362. case T('/'):
  37363. result = tokenType_operator;
  37364. source.skip();
  37365. if (source.peekNextChar() == T('='))
  37366. {
  37367. source.skip();
  37368. }
  37369. else if (source.peekNextChar() == T('/'))
  37370. {
  37371. result = tokenType_comment;
  37372. source.skipToEndOfLine();
  37373. }
  37374. else if (source.peekNextChar() == T('*'))
  37375. {
  37376. source.skip();
  37377. result = tokenType_comment;
  37378. CppTokeniser::skipComment (source);
  37379. }
  37380. break;
  37381. case T('?'):
  37382. case T('~'):
  37383. source.skip();
  37384. result = tokenType_operator;
  37385. break;
  37386. case T('<'):
  37387. source.skip();
  37388. result = tokenType_operator;
  37389. if (source.peekNextChar() == T('='))
  37390. {
  37391. source.skip();
  37392. }
  37393. else if (source.peekNextChar() == T('<'))
  37394. {
  37395. source.skip();
  37396. if (source.peekNextChar() == T('='))
  37397. source.skip();
  37398. }
  37399. break;
  37400. case T('>'):
  37401. source.skip();
  37402. result = tokenType_operator;
  37403. if (source.peekNextChar() == T('='))
  37404. {
  37405. source.skip();
  37406. }
  37407. else if (source.peekNextChar() == T('<'))
  37408. {
  37409. source.skip();
  37410. if (source.peekNextChar() == T('='))
  37411. source.skip();
  37412. }
  37413. break;
  37414. case T('|'):
  37415. source.skip();
  37416. result = tokenType_operator;
  37417. if (source.peekNextChar() == T('='))
  37418. {
  37419. source.skip();
  37420. }
  37421. else if (source.peekNextChar() == T('|'))
  37422. {
  37423. source.skip();
  37424. if (source.peekNextChar() == T('='))
  37425. source.skip();
  37426. }
  37427. break;
  37428. case T('&'):
  37429. source.skip();
  37430. result = tokenType_operator;
  37431. if (source.peekNextChar() == T('='))
  37432. {
  37433. source.skip();
  37434. }
  37435. else if (source.peekNextChar() == T('&'))
  37436. {
  37437. source.skip();
  37438. if (source.peekNextChar() == T('='))
  37439. source.skip();
  37440. }
  37441. break;
  37442. case T('^'):
  37443. source.skip();
  37444. result = tokenType_operator;
  37445. if (source.peekNextChar() == T('='))
  37446. {
  37447. source.skip();
  37448. }
  37449. else if (source.peekNextChar() == T('^'))
  37450. {
  37451. source.skip();
  37452. if (source.peekNextChar() == T('='))
  37453. source.skip();
  37454. }
  37455. break;
  37456. case T('#'):
  37457. result = tokenType_preprocessor;
  37458. source.skipToEndOfLine();
  37459. break;
  37460. default:
  37461. if (CppTokeniser::isIdentifierStart (firstChar))
  37462. result = CppTokeniser::parseIdentifier (source);
  37463. else
  37464. source.skip();
  37465. break;
  37466. }
  37467. //jassert (result != tokenType_unknown);
  37468. return result;
  37469. }
  37470. const StringArray CPlusPlusCodeTokeniser::getTokenTypes()
  37471. {
  37472. StringArray s;
  37473. s.add ("Error");
  37474. s.add ("Comment");
  37475. s.add ("C++ keyword");
  37476. s.add ("Identifier");
  37477. s.add ("Integer literal");
  37478. s.add ("Float literal");
  37479. s.add ("String literal");
  37480. s.add ("Operator");
  37481. s.add ("Bracket");
  37482. s.add ("Punctuation");
  37483. s.add ("Preprocessor line");
  37484. return s;
  37485. }
  37486. const Colour CPlusPlusCodeTokeniser::getDefaultColour (const int tokenType)
  37487. {
  37488. const uint32 colours[] =
  37489. {
  37490. 0xffcc0000, // error
  37491. 0xff00aa00, // comment
  37492. 0xff0000cc, // keyword
  37493. 0xff000000, // identifier
  37494. 0xff880000, // int literal
  37495. 0xff885500, // float literal
  37496. 0xff990099, // string literal
  37497. 0xff225500, // operator
  37498. 0xff000055, // bracket
  37499. 0xff004400, // punctuation
  37500. 0xff660000 // preprocessor
  37501. };
  37502. if (tokenType >= 0 && tokenType < numElementsInArray (colours))
  37503. return Colour (colours [tokenType]);
  37504. return Colours::black;
  37505. }
  37506. END_JUCE_NAMESPACE
  37507. /*** End of inlined file: juce_CPlusPlusCodeTokeniser.cpp ***/
  37508. /*** Start of inlined file: juce_ComboBox.cpp ***/
  37509. BEGIN_JUCE_NAMESPACE
  37510. ComboBox::ComboBox (const String& name)
  37511. : Component (name),
  37512. lastCurrentId (0),
  37513. isButtonDown (false),
  37514. separatorPending (false),
  37515. menuActive (false),
  37516. label (0)
  37517. {
  37518. noChoicesMessage = TRANS("(no choices)");
  37519. setRepaintsOnMouseActivity (true);
  37520. lookAndFeelChanged();
  37521. currentId.addListener (this);
  37522. }
  37523. ComboBox::~ComboBox()
  37524. {
  37525. currentId.removeListener (this);
  37526. if (menuActive)
  37527. PopupMenu::dismissAllActiveMenus();
  37528. deleteAllChildren();
  37529. }
  37530. void ComboBox::setEditableText (const bool isEditable)
  37531. {
  37532. label->setEditable (isEditable, isEditable, false);
  37533. setWantsKeyboardFocus (! isEditable);
  37534. resized();
  37535. }
  37536. bool ComboBox::isTextEditable() const throw()
  37537. {
  37538. return label->isEditable();
  37539. }
  37540. void ComboBox::setJustificationType (const Justification& justification) throw()
  37541. {
  37542. label->setJustificationType (justification);
  37543. }
  37544. const Justification ComboBox::getJustificationType() const throw()
  37545. {
  37546. return label->getJustificationType();
  37547. }
  37548. void ComboBox::setTooltip (const String& newTooltip)
  37549. {
  37550. SettableTooltipClient::setTooltip (newTooltip);
  37551. label->setTooltip (newTooltip);
  37552. }
  37553. void ComboBox::addItem (const String& newItemText,
  37554. const int newItemId) throw()
  37555. {
  37556. // you can't add empty strings to the list..
  37557. jassert (newItemText.isNotEmpty());
  37558. // IDs must be non-zero, as zero is used to indicate a lack of selecion.
  37559. jassert (newItemId != 0);
  37560. // you shouldn't use duplicate item IDs!
  37561. jassert (getItemForId (newItemId) == 0);
  37562. if (newItemText.isNotEmpty() && newItemId != 0)
  37563. {
  37564. if (separatorPending)
  37565. {
  37566. separatorPending = false;
  37567. ItemInfo* const item = new ItemInfo();
  37568. item->itemId = 0;
  37569. item->isEnabled = false;
  37570. item->isHeading = false;
  37571. items.add (item);
  37572. }
  37573. ItemInfo* const item = new ItemInfo();
  37574. item->name = newItemText;
  37575. item->itemId = newItemId;
  37576. item->isEnabled = true;
  37577. item->isHeading = false;
  37578. items.add (item);
  37579. }
  37580. }
  37581. void ComboBox::addSeparator() throw()
  37582. {
  37583. separatorPending = (items.size() > 0);
  37584. }
  37585. void ComboBox::addSectionHeading (const String& headingName) throw()
  37586. {
  37587. // you can't add empty strings to the list..
  37588. jassert (headingName.isNotEmpty());
  37589. if (headingName.isNotEmpty())
  37590. {
  37591. if (separatorPending)
  37592. {
  37593. separatorPending = false;
  37594. ItemInfo* const item = new ItemInfo();
  37595. item->itemId = 0;
  37596. item->isEnabled = false;
  37597. item->isHeading = false;
  37598. items.add (item);
  37599. }
  37600. ItemInfo* const item = new ItemInfo();
  37601. item->name = headingName;
  37602. item->itemId = 0;
  37603. item->isEnabled = true;
  37604. item->isHeading = true;
  37605. items.add (item);
  37606. }
  37607. }
  37608. void ComboBox::setItemEnabled (const int itemId,
  37609. const bool shouldBeEnabled) throw()
  37610. {
  37611. ItemInfo* const item = getItemForId (itemId);
  37612. if (item != 0)
  37613. item->isEnabled = shouldBeEnabled;
  37614. }
  37615. void ComboBox::changeItemText (const int itemId,
  37616. const String& newText) throw()
  37617. {
  37618. ItemInfo* const item = getItemForId (itemId);
  37619. jassert (item != 0);
  37620. if (item != 0)
  37621. item->name = newText;
  37622. }
  37623. void ComboBox::clear (const bool dontSendChangeMessage)
  37624. {
  37625. items.clear();
  37626. separatorPending = false;
  37627. if (! label->isEditable())
  37628. setSelectedItemIndex (-1, dontSendChangeMessage);
  37629. }
  37630. bool ComboBox::ItemInfo::isSeparator() const throw()
  37631. {
  37632. return name.isEmpty();
  37633. }
  37634. bool ComboBox::ItemInfo::isRealItem() const throw()
  37635. {
  37636. return ! (isHeading || name.isEmpty());
  37637. }
  37638. ComboBox::ItemInfo* ComboBox::getItemForId (const int itemId) const throw()
  37639. {
  37640. if (itemId != 0)
  37641. {
  37642. for (int i = items.size(); --i >= 0;)
  37643. if (items.getUnchecked(i)->itemId == itemId)
  37644. return items.getUnchecked(i);
  37645. }
  37646. return 0;
  37647. }
  37648. ComboBox::ItemInfo* ComboBox::getItemForIndex (const int index) const throw()
  37649. {
  37650. int n = 0;
  37651. for (int i = 0; i < items.size(); ++i)
  37652. {
  37653. ItemInfo* const item = items.getUnchecked(i);
  37654. if (item->isRealItem())
  37655. if (n++ == index)
  37656. return item;
  37657. }
  37658. return 0;
  37659. }
  37660. int ComboBox::getNumItems() const throw()
  37661. {
  37662. int n = 0;
  37663. for (int i = items.size(); --i >= 0;)
  37664. if (items.getUnchecked(i)->isRealItem())
  37665. ++n;
  37666. return n;
  37667. }
  37668. const String ComboBox::getItemText (const int index) const throw()
  37669. {
  37670. const ItemInfo* const item = getItemForIndex (index);
  37671. if (item != 0)
  37672. return item->name;
  37673. return String::empty;
  37674. }
  37675. int ComboBox::getItemId (const int index) const throw()
  37676. {
  37677. const ItemInfo* const item = getItemForIndex (index);
  37678. return (item != 0) ? item->itemId : 0;
  37679. }
  37680. int ComboBox::indexOfItemId (const int itemId) const throw()
  37681. {
  37682. int n = 0;
  37683. for (int i = 0; i < items.size(); ++i)
  37684. {
  37685. const ItemInfo* const item = items.getUnchecked(i);
  37686. if (item->isRealItem())
  37687. {
  37688. if (item->itemId == itemId)
  37689. return n;
  37690. ++n;
  37691. }
  37692. }
  37693. return -1;
  37694. }
  37695. int ComboBox::getSelectedItemIndex() const throw()
  37696. {
  37697. int index = indexOfItemId (currentId.getValue());
  37698. if (getText() != getItemText (index))
  37699. index = -1;
  37700. return index;
  37701. }
  37702. void ComboBox::setSelectedItemIndex (const int index,
  37703. const bool dontSendChangeMessage) throw()
  37704. {
  37705. setSelectedId (getItemId (index), dontSendChangeMessage);
  37706. }
  37707. int ComboBox::getSelectedId() const throw()
  37708. {
  37709. const ItemInfo* const item = getItemForId (currentId.getValue());
  37710. return (item != 0 && getText() == item->name)
  37711. ? item->itemId
  37712. : 0;
  37713. }
  37714. void ComboBox::setSelectedId (const int newItemId,
  37715. const bool dontSendChangeMessage) throw()
  37716. {
  37717. const ItemInfo* const item = getItemForId (newItemId);
  37718. const String newItemText (item != 0 ? item->name : String::empty);
  37719. if (lastCurrentId != newItemId || label->getText() != newItemText)
  37720. {
  37721. if (! dontSendChangeMessage)
  37722. triggerAsyncUpdate();
  37723. label->setText (newItemText, false);
  37724. lastCurrentId = newItemId;
  37725. currentId = newItemId;
  37726. repaint(); // for the benefit of the 'none selected' text
  37727. }
  37728. }
  37729. void ComboBox::valueChanged (Value&)
  37730. {
  37731. if (lastCurrentId != (int) currentId.getValue())
  37732. setSelectedId (currentId.getValue(), false);
  37733. }
  37734. const String ComboBox::getText() const throw()
  37735. {
  37736. return label->getText();
  37737. }
  37738. void ComboBox::setText (const String& newText,
  37739. const bool dontSendChangeMessage) throw()
  37740. {
  37741. for (int i = items.size(); --i >= 0;)
  37742. {
  37743. const ItemInfo* const item = items.getUnchecked(i);
  37744. if (item->isRealItem()
  37745. && item->name == newText)
  37746. {
  37747. setSelectedId (item->itemId, dontSendChangeMessage);
  37748. return;
  37749. }
  37750. }
  37751. lastCurrentId = 0;
  37752. currentId = 0;
  37753. if (label->getText() != newText)
  37754. {
  37755. label->setText (newText, false);
  37756. if (! dontSendChangeMessage)
  37757. triggerAsyncUpdate();
  37758. }
  37759. repaint();
  37760. }
  37761. void ComboBox::showEditor()
  37762. {
  37763. jassert (isTextEditable()); // you probably shouldn't do this to a non-editable combo box?
  37764. label->showEditor();
  37765. }
  37766. void ComboBox::setTextWhenNothingSelected (const String& newMessage) throw()
  37767. {
  37768. textWhenNothingSelected = newMessage;
  37769. repaint();
  37770. }
  37771. const String ComboBox::getTextWhenNothingSelected() const throw()
  37772. {
  37773. return textWhenNothingSelected;
  37774. }
  37775. void ComboBox::setTextWhenNoChoicesAvailable (const String& newMessage) throw()
  37776. {
  37777. noChoicesMessage = newMessage;
  37778. }
  37779. const String ComboBox::getTextWhenNoChoicesAvailable() const throw()
  37780. {
  37781. return noChoicesMessage;
  37782. }
  37783. void ComboBox::paint (Graphics& g)
  37784. {
  37785. getLookAndFeel().drawComboBox (g,
  37786. getWidth(),
  37787. getHeight(),
  37788. isButtonDown,
  37789. label->getRight(),
  37790. 0,
  37791. getWidth() - label->getRight(),
  37792. getHeight(),
  37793. *this);
  37794. if (textWhenNothingSelected.isNotEmpty()
  37795. && label->getText().isEmpty()
  37796. && ! label->isBeingEdited())
  37797. {
  37798. g.setColour (findColour (textColourId).withMultipliedAlpha (0.5f));
  37799. g.setFont (label->getFont());
  37800. g.drawFittedText (textWhenNothingSelected,
  37801. label->getX() + 2, label->getY() + 1,
  37802. label->getWidth() - 4, label->getHeight() - 2,
  37803. label->getJustificationType(),
  37804. jmax (1, (int) (label->getHeight() / label->getFont().getHeight())));
  37805. }
  37806. }
  37807. void ComboBox::resized()
  37808. {
  37809. if (getHeight() > 0 && getWidth() > 0)
  37810. getLookAndFeel().positionComboBoxText (*this, *label);
  37811. }
  37812. void ComboBox::enablementChanged()
  37813. {
  37814. repaint();
  37815. }
  37816. void ComboBox::lookAndFeelChanged()
  37817. {
  37818. repaint();
  37819. Label* const newLabel = getLookAndFeel().createComboBoxTextBox (*this);
  37820. if (label != 0)
  37821. {
  37822. newLabel->setEditable (label->isEditable());
  37823. newLabel->setJustificationType (label->getJustificationType());
  37824. newLabel->setTooltip (label->getTooltip());
  37825. newLabel->setText (label->getText(), false);
  37826. }
  37827. delete label;
  37828. label = newLabel;
  37829. addAndMakeVisible (newLabel);
  37830. newLabel->addListener (this);
  37831. newLabel->addMouseListener (this, false);
  37832. newLabel->setColour (Label::backgroundColourId, Colours::transparentBlack);
  37833. newLabel->setColour (Label::textColourId, findColour (ComboBox::textColourId));
  37834. newLabel->setColour (TextEditor::textColourId, findColour (ComboBox::textColourId));
  37835. newLabel->setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  37836. newLabel->setColour (TextEditor::highlightColourId, findColour (TextEditor::highlightColourId));
  37837. newLabel->setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  37838. resized();
  37839. }
  37840. void ComboBox::colourChanged()
  37841. {
  37842. lookAndFeelChanged();
  37843. }
  37844. bool ComboBox::keyPressed (const KeyPress& key)
  37845. {
  37846. bool used = false;
  37847. if (key.isKeyCode (KeyPress::upKey)
  37848. || key.isKeyCode (KeyPress::leftKey))
  37849. {
  37850. setSelectedItemIndex (jmax (0, getSelectedItemIndex() - 1));
  37851. used = true;
  37852. }
  37853. else if (key.isKeyCode (KeyPress::downKey)
  37854. || key.isKeyCode (KeyPress::rightKey))
  37855. {
  37856. setSelectedItemIndex (jmin (getSelectedItemIndex() + 1, getNumItems() - 1));
  37857. used = true;
  37858. }
  37859. else if (key.isKeyCode (KeyPress::returnKey))
  37860. {
  37861. showPopup();
  37862. used = true;
  37863. }
  37864. return used;
  37865. }
  37866. bool ComboBox::keyStateChanged (const bool isKeyDown)
  37867. {
  37868. // only forward key events that aren't used by this component
  37869. return isKeyDown
  37870. && (KeyPress::isKeyCurrentlyDown (KeyPress::upKey)
  37871. || KeyPress::isKeyCurrentlyDown (KeyPress::leftKey)
  37872. || KeyPress::isKeyCurrentlyDown (KeyPress::downKey)
  37873. || KeyPress::isKeyCurrentlyDown (KeyPress::rightKey));
  37874. }
  37875. void ComboBox::focusGained (FocusChangeType)
  37876. {
  37877. repaint();
  37878. }
  37879. void ComboBox::focusLost (FocusChangeType)
  37880. {
  37881. repaint();
  37882. }
  37883. void ComboBox::labelTextChanged (Label*)
  37884. {
  37885. triggerAsyncUpdate();
  37886. }
  37887. void ComboBox::showPopup()
  37888. {
  37889. if (! menuActive)
  37890. {
  37891. const int selectedId = getSelectedId();
  37892. ComponentDeletionWatcher deletionWatcher (this);
  37893. PopupMenu menu;
  37894. menu.setLookAndFeel (&getLookAndFeel());
  37895. for (int i = 0; i < items.size(); ++i)
  37896. {
  37897. const ItemInfo* const item = items.getUnchecked(i);
  37898. if (item->isSeparator())
  37899. menu.addSeparator();
  37900. else if (item->isHeading)
  37901. menu.addSectionHeader (item->name);
  37902. else
  37903. menu.addItem (item->itemId, item->name,
  37904. item->isEnabled, item->itemId == selectedId);
  37905. }
  37906. if (items.size() == 0)
  37907. menu.addItem (1, noChoicesMessage, false);
  37908. const int itemHeight = jlimit (12, 24, getHeight());
  37909. menuActive = true;
  37910. const int resultId = menu.showAt (this, selectedId,
  37911. getWidth(), 1, itemHeight);
  37912. if (deletionWatcher.hasBeenDeleted())
  37913. return;
  37914. menuActive = false;
  37915. if (resultId != 0)
  37916. setSelectedId (resultId);
  37917. }
  37918. }
  37919. void ComboBox::mouseDown (const MouseEvent& e)
  37920. {
  37921. beginDragAutoRepeat (300);
  37922. isButtonDown = isEnabled();
  37923. if (isButtonDown
  37924. && (e.eventComponent == this || ! label->isEditable()))
  37925. {
  37926. showPopup();
  37927. }
  37928. }
  37929. void ComboBox::mouseDrag (const MouseEvent& e)
  37930. {
  37931. beginDragAutoRepeat (50);
  37932. if (isButtonDown && ! e.mouseWasClicked())
  37933. showPopup();
  37934. }
  37935. void ComboBox::mouseUp (const MouseEvent& e2)
  37936. {
  37937. if (isButtonDown)
  37938. {
  37939. isButtonDown = false;
  37940. repaint();
  37941. const MouseEvent e (e2.getEventRelativeTo (this));
  37942. if (reallyContains (e.x, e.y, true)
  37943. && (e2.eventComponent == this || ! label->isEditable()))
  37944. {
  37945. showPopup();
  37946. }
  37947. }
  37948. }
  37949. void ComboBox::addListener (ComboBoxListener* const listener) throw()
  37950. {
  37951. jassert (listener != 0);
  37952. if (listener != 0)
  37953. listeners.add (listener);
  37954. }
  37955. void ComboBox::removeListener (ComboBoxListener* const listener) throw()
  37956. {
  37957. listeners.removeValue (listener);
  37958. }
  37959. void ComboBox::handleAsyncUpdate()
  37960. {
  37961. for (int i = listeners.size(); --i >= 0;)
  37962. {
  37963. ((ComboBoxListener*) listeners.getUnchecked (i))->comboBoxChanged (this);
  37964. i = jmin (i, listeners.size());
  37965. }
  37966. }
  37967. END_JUCE_NAMESPACE
  37968. /*** End of inlined file: juce_ComboBox.cpp ***/
  37969. /*** Start of inlined file: juce_Label.cpp ***/
  37970. BEGIN_JUCE_NAMESPACE
  37971. Label::Label (const String& componentName,
  37972. const String& labelText)
  37973. : Component (componentName),
  37974. textValue (labelText),
  37975. lastTextValue (labelText),
  37976. font (15.0f),
  37977. justification (Justification::centredLeft),
  37978. ownerComponent (0),
  37979. horizontalBorderSize (5),
  37980. verticalBorderSize (1),
  37981. minimumHorizontalScale (0.7f),
  37982. editSingleClick (false),
  37983. editDoubleClick (false),
  37984. lossOfFocusDiscardsChanges (false)
  37985. {
  37986. setColour (TextEditor::textColourId, Colours::black);
  37987. setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  37988. setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  37989. textValue.addListener (this);
  37990. }
  37991. Label::~Label()
  37992. {
  37993. textValue.removeListener (this);
  37994. if (ownerComponent != 0 && ! deletionWatcher->hasBeenDeleted())
  37995. ownerComponent->removeComponentListener (this);
  37996. editor = 0;
  37997. }
  37998. void Label::setText (const String& newText,
  37999. const bool broadcastChangeMessage)
  38000. {
  38001. hideEditor (true);
  38002. if (lastTextValue != newText)
  38003. {
  38004. lastTextValue = newText;
  38005. textValue = newText;
  38006. repaint();
  38007. textWasChanged();
  38008. if (ownerComponent != 0 && ! deletionWatcher->hasBeenDeleted())
  38009. componentMovedOrResized (*ownerComponent, true, true);
  38010. if (broadcastChangeMessage)
  38011. callChangeListeners();
  38012. }
  38013. }
  38014. const String Label::getText (const bool returnActiveEditorContents) const throw()
  38015. {
  38016. return (returnActiveEditorContents && isBeingEdited())
  38017. ? editor->getText()
  38018. : textValue.toString();
  38019. }
  38020. void Label::valueChanged (Value&)
  38021. {
  38022. if (lastTextValue != textValue.toString())
  38023. setText (textValue.toString(), true);
  38024. }
  38025. void Label::setFont (const Font& newFont) throw()
  38026. {
  38027. font = newFont;
  38028. repaint();
  38029. }
  38030. const Font& Label::getFont() const throw()
  38031. {
  38032. return font;
  38033. }
  38034. void Label::setEditable (const bool editOnSingleClick,
  38035. const bool editOnDoubleClick,
  38036. const bool lossOfFocusDiscardsChanges_) throw()
  38037. {
  38038. editSingleClick = editOnSingleClick;
  38039. editDoubleClick = editOnDoubleClick;
  38040. lossOfFocusDiscardsChanges = lossOfFocusDiscardsChanges_;
  38041. setWantsKeyboardFocus (editOnSingleClick || editOnDoubleClick);
  38042. setFocusContainer (editOnSingleClick || editOnDoubleClick);
  38043. }
  38044. void Label::setJustificationType (const Justification& justification_) throw()
  38045. {
  38046. justification = justification_;
  38047. repaint();
  38048. }
  38049. void Label::setBorderSize (int h, int v)
  38050. {
  38051. horizontalBorderSize = h;
  38052. verticalBorderSize = v;
  38053. repaint();
  38054. }
  38055. void Label::attachToComponent (Component* owner,
  38056. const bool onLeft)
  38057. {
  38058. if (ownerComponent != 0 && ! deletionWatcher->hasBeenDeleted())
  38059. ownerComponent->removeComponentListener (this);
  38060. deletionWatcher = 0;
  38061. ownerComponent = owner;
  38062. leftOfOwnerComp = onLeft;
  38063. if (ownerComponent != 0)
  38064. {
  38065. deletionWatcher = new ComponentDeletionWatcher (owner);
  38066. setVisible (owner->isVisible());
  38067. ownerComponent->addComponentListener (this);
  38068. componentParentHierarchyChanged (*ownerComponent);
  38069. componentMovedOrResized (*ownerComponent, true, true);
  38070. }
  38071. }
  38072. void Label::componentMovedOrResized (Component& component,
  38073. bool /*wasMoved*/,
  38074. bool /*wasResized*/)
  38075. {
  38076. if (leftOfOwnerComp)
  38077. {
  38078. setSize (jmin (getFont().getStringWidth (textValue.toString()) + 8, component.getX()),
  38079. component.getHeight());
  38080. setTopRightPosition (component.getX(), component.getY());
  38081. }
  38082. else
  38083. {
  38084. setSize (component.getWidth(),
  38085. 8 + roundToInt (getFont().getHeight()));
  38086. setTopLeftPosition (component.getX(), component.getY() - getHeight());
  38087. }
  38088. }
  38089. void Label::componentParentHierarchyChanged (Component& component)
  38090. {
  38091. if (component.getParentComponent() != 0)
  38092. component.getParentComponent()->addChildComponent (this);
  38093. }
  38094. void Label::componentVisibilityChanged (Component& component)
  38095. {
  38096. setVisible (component.isVisible());
  38097. }
  38098. void Label::textWasEdited()
  38099. {
  38100. }
  38101. void Label::textWasChanged()
  38102. {
  38103. }
  38104. void Label::showEditor()
  38105. {
  38106. if (editor == 0)
  38107. {
  38108. addAndMakeVisible (editor = createEditorComponent());
  38109. editor->setText (getText(), false);
  38110. editor->addListener (this);
  38111. editor->grabKeyboardFocus();
  38112. editor->setHighlightedRegion (Range<int> (0, textValue.toString().length()));
  38113. editor->addListener (this);
  38114. resized();
  38115. repaint();
  38116. editorShown (editor);
  38117. enterModalState();
  38118. editor->grabKeyboardFocus();
  38119. }
  38120. }
  38121. void Label::editorShown (TextEditor* /*editorComponent*/)
  38122. {
  38123. }
  38124. void Label::editorAboutToBeHidden (TextEditor* /*editorComponent*/)
  38125. {
  38126. }
  38127. bool Label::updateFromTextEditorContents()
  38128. {
  38129. jassert (editor != 0);
  38130. const String newText (editor->getText());
  38131. if (textValue.toString() != newText)
  38132. {
  38133. lastTextValue = newText;
  38134. textValue = newText;
  38135. repaint();
  38136. textWasChanged();
  38137. if (ownerComponent != 0 && ! deletionWatcher->hasBeenDeleted())
  38138. componentMovedOrResized (*ownerComponent, true, true);
  38139. return true;
  38140. }
  38141. return false;
  38142. }
  38143. void Label::hideEditor (const bool discardCurrentEditorContents)
  38144. {
  38145. if (editor != 0)
  38146. {
  38147. editorAboutToBeHidden (editor);
  38148. const bool changed = (! discardCurrentEditorContents)
  38149. && updateFromTextEditorContents();
  38150. editor = 0;
  38151. repaint();
  38152. if (changed)
  38153. textWasEdited();
  38154. exitModalState (0);
  38155. if (changed && isValidComponent())
  38156. callChangeListeners();
  38157. }
  38158. }
  38159. void Label::inputAttemptWhenModal()
  38160. {
  38161. if (editor != 0)
  38162. {
  38163. if (lossOfFocusDiscardsChanges)
  38164. textEditorEscapeKeyPressed (*editor);
  38165. else
  38166. textEditorReturnKeyPressed (*editor);
  38167. }
  38168. }
  38169. bool Label::isBeingEdited() const throw()
  38170. {
  38171. return editor != 0;
  38172. }
  38173. TextEditor* Label::createEditorComponent()
  38174. {
  38175. TextEditor* const ed = new TextEditor (getName());
  38176. ed->setFont (font);
  38177. // copy these colours from our own settings..
  38178. const int cols[] = { TextEditor::backgroundColourId,
  38179. TextEditor::textColourId,
  38180. TextEditor::highlightColourId,
  38181. TextEditor::highlightedTextColourId,
  38182. TextEditor::caretColourId,
  38183. TextEditor::outlineColourId,
  38184. TextEditor::focusedOutlineColourId,
  38185. TextEditor::shadowColourId };
  38186. for (int i = 0; i < numElementsInArray (cols); ++i)
  38187. ed->setColour (cols[i], findColour (cols[i]));
  38188. return ed;
  38189. }
  38190. void Label::paint (Graphics& g)
  38191. {
  38192. getLookAndFeel().drawLabel (g, *this);
  38193. }
  38194. void Label::mouseUp (const MouseEvent& e)
  38195. {
  38196. if (editSingleClick
  38197. && e.mouseWasClicked()
  38198. && contains (e.x, e.y)
  38199. && ! e.mods.isPopupMenu())
  38200. {
  38201. showEditor();
  38202. }
  38203. }
  38204. void Label::mouseDoubleClick (const MouseEvent& e)
  38205. {
  38206. if (editDoubleClick && ! e.mods.isPopupMenu())
  38207. showEditor();
  38208. }
  38209. void Label::resized()
  38210. {
  38211. if (editor != 0)
  38212. editor->setBoundsInset (BorderSize (0));
  38213. }
  38214. void Label::focusGained (FocusChangeType cause)
  38215. {
  38216. if (editSingleClick && cause == focusChangedByTabKey)
  38217. showEditor();
  38218. }
  38219. void Label::enablementChanged()
  38220. {
  38221. repaint();
  38222. }
  38223. void Label::colourChanged()
  38224. {
  38225. repaint();
  38226. }
  38227. void Label::setMinimumHorizontalScale (const float newScale)
  38228. {
  38229. if (minimumHorizontalScale != newScale)
  38230. {
  38231. minimumHorizontalScale = newScale;
  38232. repaint();
  38233. }
  38234. }
  38235. // We'll use a custom focus traverser here to make sure focus goes from the
  38236. // text editor to another component rather than back to the label itself.
  38237. class LabelKeyboardFocusTraverser : public KeyboardFocusTraverser
  38238. {
  38239. public:
  38240. LabelKeyboardFocusTraverser() {}
  38241. Component* getNextComponent (Component* current)
  38242. {
  38243. return KeyboardFocusTraverser::getNextComponent (dynamic_cast <TextEditor*> (current) != 0
  38244. ? current->getParentComponent() : current);
  38245. }
  38246. Component* getPreviousComponent (Component* current)
  38247. {
  38248. return KeyboardFocusTraverser::getPreviousComponent (dynamic_cast <TextEditor*> (current) != 0
  38249. ? current->getParentComponent() : current);
  38250. }
  38251. };
  38252. KeyboardFocusTraverser* Label::createFocusTraverser()
  38253. {
  38254. return new LabelKeyboardFocusTraverser();
  38255. }
  38256. void Label::addListener (LabelListener* const listener) throw()
  38257. {
  38258. jassert (listener != 0);
  38259. if (listener != 0)
  38260. listeners.add (listener);
  38261. }
  38262. void Label::removeListener (LabelListener* const listener) throw()
  38263. {
  38264. listeners.removeValue (listener);
  38265. }
  38266. void Label::callChangeListeners()
  38267. {
  38268. for (int i = listeners.size(); --i >= 0;)
  38269. {
  38270. ((LabelListener*) listeners.getUnchecked (i))->labelTextChanged (this);
  38271. i = jmin (i, listeners.size());
  38272. }
  38273. }
  38274. void Label::textEditorTextChanged (TextEditor& ed)
  38275. {
  38276. if (editor != 0)
  38277. {
  38278. jassert (&ed == editor);
  38279. if (! (hasKeyboardFocus (true) || isCurrentlyBlockedByAnotherModalComponent()))
  38280. {
  38281. if (lossOfFocusDiscardsChanges)
  38282. textEditorEscapeKeyPressed (ed);
  38283. else
  38284. textEditorReturnKeyPressed (ed);
  38285. }
  38286. }
  38287. }
  38288. void Label::textEditorReturnKeyPressed (TextEditor& ed)
  38289. {
  38290. if (editor != 0)
  38291. {
  38292. jassert (&ed == editor);
  38293. (void) ed;
  38294. const bool changed = updateFromTextEditorContents();
  38295. hideEditor (true);
  38296. if (changed)
  38297. {
  38298. textWasEdited();
  38299. if (isValidComponent())
  38300. callChangeListeners();
  38301. }
  38302. }
  38303. }
  38304. void Label::textEditorEscapeKeyPressed (TextEditor& ed)
  38305. {
  38306. if (editor != 0)
  38307. {
  38308. jassert (&ed == editor);
  38309. (void) ed;
  38310. editor->setText (textValue.toString(), false);
  38311. hideEditor (true);
  38312. }
  38313. }
  38314. void Label::textEditorFocusLost (TextEditor& ed)
  38315. {
  38316. textEditorTextChanged (ed);
  38317. }
  38318. END_JUCE_NAMESPACE
  38319. /*** End of inlined file: juce_Label.cpp ***/
  38320. /*** Start of inlined file: juce_ListBox.cpp ***/
  38321. BEGIN_JUCE_NAMESPACE
  38322. class ListBoxRowComponent : public Component,
  38323. public TooltipClient
  38324. {
  38325. public:
  38326. ListBoxRowComponent (ListBox& owner_)
  38327. : owner (owner_),
  38328. row (-1),
  38329. selected (false),
  38330. isDragging (false)
  38331. {
  38332. }
  38333. ~ListBoxRowComponent()
  38334. {
  38335. deleteAllChildren();
  38336. }
  38337. void paint (Graphics& g)
  38338. {
  38339. if (owner.getModel() != 0)
  38340. owner.getModel()->paintListBoxItem (row, g, getWidth(), getHeight(), selected);
  38341. }
  38342. void update (const int row_, const bool selected_)
  38343. {
  38344. if (row != row_ || selected != selected_)
  38345. {
  38346. repaint();
  38347. row = row_;
  38348. selected = selected_;
  38349. }
  38350. if (owner.getModel() != 0)
  38351. {
  38352. Component* const customComp = owner.getModel()->refreshComponentForRow (row_, selected_, getChildComponent (0));
  38353. if (customComp != 0)
  38354. {
  38355. addAndMakeVisible (customComp);
  38356. customComp->setBounds (0, 0, getWidth(), getHeight());
  38357. for (int i = getNumChildComponents(); --i >= 0;)
  38358. if (getChildComponent (i) != customComp)
  38359. delete getChildComponent (i);
  38360. }
  38361. else
  38362. {
  38363. deleteAllChildren();
  38364. }
  38365. }
  38366. }
  38367. void mouseDown (const MouseEvent& e)
  38368. {
  38369. isDragging = false;
  38370. selectRowOnMouseUp = false;
  38371. if (isEnabled())
  38372. {
  38373. if (! selected)
  38374. {
  38375. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  38376. if (owner.getModel() != 0)
  38377. owner.getModel()->listBoxItemClicked (row, e);
  38378. }
  38379. else
  38380. {
  38381. selectRowOnMouseUp = true;
  38382. }
  38383. }
  38384. }
  38385. void mouseUp (const MouseEvent& e)
  38386. {
  38387. if (isEnabled() && selectRowOnMouseUp && ! isDragging)
  38388. {
  38389. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  38390. if (owner.getModel() != 0)
  38391. owner.getModel()->listBoxItemClicked (row, e);
  38392. }
  38393. }
  38394. void mouseDoubleClick (const MouseEvent& e)
  38395. {
  38396. if (owner.getModel() != 0 && isEnabled())
  38397. owner.getModel()->listBoxItemDoubleClicked (row, e);
  38398. }
  38399. void mouseDrag (const MouseEvent& e)
  38400. {
  38401. if (isEnabled() && owner.getModel() != 0 && ! (e.mouseWasClicked() || isDragging))
  38402. {
  38403. const SparseSet <int> selectedRows (owner.getSelectedRows());
  38404. if (selectedRows.size() > 0)
  38405. {
  38406. const String dragDescription (owner.getModel()->getDragSourceDescription (selectedRows));
  38407. if (dragDescription.isNotEmpty())
  38408. {
  38409. isDragging = true;
  38410. owner.startDragAndDrop (e, dragDescription);
  38411. }
  38412. }
  38413. }
  38414. }
  38415. void resized()
  38416. {
  38417. if (getNumChildComponents() > 0)
  38418. getChildComponent(0)->setBounds (0, 0, getWidth(), getHeight());
  38419. }
  38420. const String getTooltip()
  38421. {
  38422. if (owner.getModel() != 0)
  38423. return owner.getModel()->getTooltipForRow (row);
  38424. return String::empty;
  38425. }
  38426. juce_UseDebuggingNewOperator
  38427. bool neededFlag;
  38428. private:
  38429. ListBox& owner;
  38430. int row;
  38431. bool selected, isDragging, selectRowOnMouseUp;
  38432. ListBoxRowComponent (const ListBoxRowComponent&);
  38433. const ListBoxRowComponent& operator= (const ListBoxRowComponent&);
  38434. };
  38435. class ListViewport : public Viewport
  38436. {
  38437. public:
  38438. int firstIndex, firstWholeIndex, lastWholeIndex;
  38439. bool hasUpdated;
  38440. ListViewport (ListBox& owner_)
  38441. : owner (owner_)
  38442. {
  38443. setWantsKeyboardFocus (false);
  38444. setViewedComponent (new Component());
  38445. getViewedComponent()->addMouseListener (this, false);
  38446. getViewedComponent()->setWantsKeyboardFocus (false);
  38447. }
  38448. ~ListViewport()
  38449. {
  38450. getViewedComponent()->removeMouseListener (this);
  38451. getViewedComponent()->deleteAllChildren();
  38452. }
  38453. ListBoxRowComponent* getComponentForRow (const int row) const throw()
  38454. {
  38455. return (ListBoxRowComponent*) getViewedComponent()
  38456. ->getChildComponent (row % jmax (1, getViewedComponent()->getNumChildComponents()));
  38457. }
  38458. int getRowNumberOfComponent (Component* const rowComponent) const throw()
  38459. {
  38460. const int index = getIndexOfChildComponent (rowComponent);
  38461. const int num = getViewedComponent()->getNumChildComponents();
  38462. for (int i = num; --i >= 0;)
  38463. if (((firstIndex + i) % jmax (1, num)) == index)
  38464. return firstIndex + i;
  38465. return -1;
  38466. }
  38467. Component* getComponentForRowIfOnscreen (const int row) const throw()
  38468. {
  38469. return (row >= firstIndex && row < firstIndex + getViewedComponent()->getNumChildComponents())
  38470. ? getComponentForRow (row) : 0;
  38471. }
  38472. void visibleAreaChanged (int, int, int, int)
  38473. {
  38474. updateVisibleArea (true);
  38475. if (owner.getModel() != 0)
  38476. owner.getModel()->listWasScrolled();
  38477. }
  38478. void updateVisibleArea (const bool makeSureItUpdatesContent)
  38479. {
  38480. hasUpdated = false;
  38481. const int newX = getViewedComponent()->getX();
  38482. int newY = getViewedComponent()->getY();
  38483. const int newW = jmax (owner.minimumRowWidth, getMaximumVisibleWidth());
  38484. const int newH = owner.totalItems * owner.getRowHeight();
  38485. if (newY + newH < getMaximumVisibleHeight() && newH > getMaximumVisibleHeight())
  38486. newY = getMaximumVisibleHeight() - newH;
  38487. getViewedComponent()->setBounds (newX, newY, newW, newH);
  38488. if (makeSureItUpdatesContent && ! hasUpdated)
  38489. updateContents();
  38490. }
  38491. void updateContents()
  38492. {
  38493. hasUpdated = true;
  38494. const int rowHeight = owner.getRowHeight();
  38495. if (rowHeight > 0)
  38496. {
  38497. const int y = getViewPositionY();
  38498. const int w = getViewedComponent()->getWidth();
  38499. const int numNeeded = 2 + getMaximumVisibleHeight() / rowHeight;
  38500. while (numNeeded > getViewedComponent()->getNumChildComponents())
  38501. getViewedComponent()->addAndMakeVisible (new ListBoxRowComponent (owner));
  38502. jassert (numNeeded >= 0);
  38503. while (numNeeded < getViewedComponent()->getNumChildComponents())
  38504. {
  38505. Component* const rowToRemove
  38506. = getViewedComponent()->getChildComponent (getViewedComponent()->getNumChildComponents() - 1);
  38507. delete rowToRemove;
  38508. }
  38509. firstIndex = y / rowHeight;
  38510. firstWholeIndex = (y + rowHeight - 1) / rowHeight;
  38511. lastWholeIndex = (y + getMaximumVisibleHeight() - 1) / rowHeight;
  38512. for (int i = 0; i < numNeeded; ++i)
  38513. {
  38514. const int row = i + firstIndex;
  38515. ListBoxRowComponent* const rowComp = getComponentForRow (row);
  38516. if (rowComp != 0)
  38517. {
  38518. rowComp->setBounds (0, row * rowHeight, w, rowHeight);
  38519. rowComp->update (row, owner.isRowSelected (row));
  38520. }
  38521. }
  38522. }
  38523. if (owner.headerComponent != 0)
  38524. owner.headerComponent->setBounds (owner.outlineThickness + getViewedComponent()->getX(),
  38525. owner.outlineThickness,
  38526. jmax (owner.getWidth() - owner.outlineThickness * 2,
  38527. getViewedComponent()->getWidth()),
  38528. owner.headerComponent->getHeight());
  38529. }
  38530. void paint (Graphics& g)
  38531. {
  38532. if (isOpaque())
  38533. g.fillAll (owner.findColour (ListBox::backgroundColourId));
  38534. }
  38535. bool keyPressed (const KeyPress& key)
  38536. {
  38537. if (key.isKeyCode (KeyPress::upKey)
  38538. || key.isKeyCode (KeyPress::downKey)
  38539. || key.isKeyCode (KeyPress::pageUpKey)
  38540. || key.isKeyCode (KeyPress::pageDownKey)
  38541. || key.isKeyCode (KeyPress::homeKey)
  38542. || key.isKeyCode (KeyPress::endKey))
  38543. {
  38544. // we want to avoid these keypresses going to the viewport, and instead allow
  38545. // them to pass up to our listbox..
  38546. return false;
  38547. }
  38548. return Viewport::keyPressed (key);
  38549. }
  38550. juce_UseDebuggingNewOperator
  38551. private:
  38552. ListBox& owner;
  38553. ListViewport (const ListViewport&);
  38554. const ListViewport& operator= (const ListViewport&);
  38555. };
  38556. ListBox::ListBox (const String& name, ListBoxModel* const model_)
  38557. : Component (name),
  38558. model (model_),
  38559. headerComponent (0),
  38560. totalItems (0),
  38561. rowHeight (22),
  38562. minimumRowWidth (0),
  38563. outlineThickness (0),
  38564. lastRowSelected (-1),
  38565. mouseMoveSelects (false),
  38566. multipleSelection (false),
  38567. hasDoneInitialUpdate (false)
  38568. {
  38569. addAndMakeVisible (viewport = new ListViewport (*this));
  38570. setWantsKeyboardFocus (true);
  38571. colourChanged();
  38572. }
  38573. ListBox::~ListBox()
  38574. {
  38575. deleteAllChildren();
  38576. }
  38577. void ListBox::setModel (ListBoxModel* const newModel)
  38578. {
  38579. if (model != newModel)
  38580. {
  38581. model = newModel;
  38582. updateContent();
  38583. }
  38584. }
  38585. void ListBox::setMultipleSelectionEnabled (bool b)
  38586. {
  38587. multipleSelection = b;
  38588. }
  38589. void ListBox::setMouseMoveSelectsRows (bool b)
  38590. {
  38591. mouseMoveSelects = b;
  38592. if (b)
  38593. addMouseListener (this, true);
  38594. }
  38595. void ListBox::paint (Graphics& g)
  38596. {
  38597. if (! hasDoneInitialUpdate)
  38598. updateContent();
  38599. g.fillAll (findColour (backgroundColourId));
  38600. }
  38601. void ListBox::paintOverChildren (Graphics& g)
  38602. {
  38603. if (outlineThickness > 0)
  38604. {
  38605. g.setColour (findColour (outlineColourId));
  38606. g.drawRect (0, 0, getWidth(), getHeight(), outlineThickness);
  38607. }
  38608. }
  38609. void ListBox::resized()
  38610. {
  38611. viewport->setBoundsInset (BorderSize (outlineThickness + ((headerComponent != 0) ? headerComponent->getHeight() : 0),
  38612. outlineThickness,
  38613. outlineThickness,
  38614. outlineThickness));
  38615. viewport->setSingleStepSizes (20, getRowHeight());
  38616. viewport->updateVisibleArea (false);
  38617. }
  38618. void ListBox::visibilityChanged()
  38619. {
  38620. viewport->updateVisibleArea (true);
  38621. }
  38622. Viewport* ListBox::getViewport() const throw()
  38623. {
  38624. return viewport;
  38625. }
  38626. void ListBox::updateContent()
  38627. {
  38628. hasDoneInitialUpdate = true;
  38629. totalItems = (model != 0) ? model->getNumRows() : 0;
  38630. bool selectionChanged = false;
  38631. if (selected [selected.size() - 1] >= totalItems)
  38632. {
  38633. selected.removeRange (totalItems, std::numeric_limits<int>::max() - totalItems);
  38634. lastRowSelected = getSelectedRow (0);
  38635. selectionChanged = true;
  38636. }
  38637. viewport->updateVisibleArea (isVisible());
  38638. viewport->resized();
  38639. if (selectionChanged && model != 0)
  38640. model->selectedRowsChanged (lastRowSelected);
  38641. }
  38642. void ListBox::selectRow (const int row,
  38643. bool dontScroll,
  38644. bool deselectOthersFirst)
  38645. {
  38646. selectRowInternal (row, dontScroll, deselectOthersFirst, false);
  38647. }
  38648. void ListBox::selectRowInternal (const int row,
  38649. bool dontScroll,
  38650. bool deselectOthersFirst,
  38651. bool isMouseClick)
  38652. {
  38653. if (! multipleSelection)
  38654. deselectOthersFirst = true;
  38655. if ((! isRowSelected (row))
  38656. || (deselectOthersFirst && getNumSelectedRows() > 1))
  38657. {
  38658. if (((unsigned int) row) < (unsigned int) totalItems)
  38659. {
  38660. if (deselectOthersFirst)
  38661. selected.clear();
  38662. selected.addRange (row, 1);
  38663. if (getHeight() == 0 || getWidth() == 0)
  38664. dontScroll = true;
  38665. viewport->hasUpdated = false;
  38666. if (row < viewport->firstWholeIndex && ! dontScroll)
  38667. {
  38668. viewport->setViewPosition (viewport->getViewPositionX(),
  38669. row * getRowHeight());
  38670. }
  38671. else if (row >= viewport->lastWholeIndex && ! dontScroll)
  38672. {
  38673. const int rowsOnScreen = viewport->lastWholeIndex - viewport->firstWholeIndex;
  38674. if (row >= lastRowSelected + rowsOnScreen
  38675. && rowsOnScreen < totalItems - 1
  38676. && ! isMouseClick)
  38677. {
  38678. viewport->setViewPosition (viewport->getViewPositionX(),
  38679. jlimit (0, jmax (0, totalItems - rowsOnScreen), row)
  38680. * getRowHeight());
  38681. }
  38682. else
  38683. {
  38684. viewport->setViewPosition (viewport->getViewPositionX(),
  38685. jmax (0, (row + 1) * getRowHeight() - viewport->getMaximumVisibleHeight()));
  38686. }
  38687. }
  38688. if (! viewport->hasUpdated)
  38689. viewport->updateContents();
  38690. lastRowSelected = row;
  38691. model->selectedRowsChanged (row);
  38692. }
  38693. else
  38694. {
  38695. if (deselectOthersFirst)
  38696. deselectAllRows();
  38697. }
  38698. }
  38699. }
  38700. void ListBox::deselectRow (const int row)
  38701. {
  38702. if (selected.contains (row))
  38703. {
  38704. selected.removeRange (row, 1);
  38705. if (row == lastRowSelected)
  38706. lastRowSelected = getSelectedRow (0);
  38707. viewport->updateContents();
  38708. model->selectedRowsChanged (lastRowSelected);
  38709. }
  38710. }
  38711. void ListBox::setSelectedRows (const SparseSet<int>& setOfRowsToBeSelected,
  38712. const bool sendNotificationEventToModel)
  38713. {
  38714. selected = setOfRowsToBeSelected;
  38715. selected.removeRange (totalItems, std::numeric_limits<int>::max() - totalItems);
  38716. if (! isRowSelected (lastRowSelected))
  38717. lastRowSelected = getSelectedRow (0);
  38718. viewport->updateContents();
  38719. if ((model != 0) && sendNotificationEventToModel)
  38720. model->selectedRowsChanged (lastRowSelected);
  38721. }
  38722. const SparseSet<int> ListBox::getSelectedRows() const
  38723. {
  38724. return selected;
  38725. }
  38726. void ListBox::selectRangeOfRows (int firstRow, int lastRow)
  38727. {
  38728. if (multipleSelection && (firstRow != lastRow))
  38729. {
  38730. const int numRows = totalItems - 1;
  38731. firstRow = jlimit (0, jmax (0, numRows), firstRow);
  38732. lastRow = jlimit (0, jmax (0, numRows), lastRow);
  38733. selected.addRange (jmin (firstRow, lastRow),
  38734. abs (firstRow - lastRow) + 1);
  38735. selected.removeRange (lastRow, 1);
  38736. }
  38737. selectRowInternal (lastRow, false, false, true);
  38738. }
  38739. void ListBox::flipRowSelection (const int row)
  38740. {
  38741. if (isRowSelected (row))
  38742. deselectRow (row);
  38743. else
  38744. selectRowInternal (row, false, false, true);
  38745. }
  38746. void ListBox::deselectAllRows()
  38747. {
  38748. if (! selected.isEmpty())
  38749. {
  38750. selected.clear();
  38751. lastRowSelected = -1;
  38752. viewport->updateContents();
  38753. if (model != 0)
  38754. model->selectedRowsChanged (lastRowSelected);
  38755. }
  38756. }
  38757. void ListBox::selectRowsBasedOnModifierKeys (const int row,
  38758. const ModifierKeys& mods)
  38759. {
  38760. if (multipleSelection && mods.isCommandDown())
  38761. {
  38762. flipRowSelection (row);
  38763. }
  38764. else if (multipleSelection && mods.isShiftDown() && lastRowSelected >= 0)
  38765. {
  38766. selectRangeOfRows (lastRowSelected, row);
  38767. }
  38768. else if ((! mods.isPopupMenu()) || ! isRowSelected (row))
  38769. {
  38770. selectRowInternal (row, false, true, true);
  38771. }
  38772. }
  38773. int ListBox::getNumSelectedRows() const
  38774. {
  38775. return selected.size();
  38776. }
  38777. int ListBox::getSelectedRow (const int index) const
  38778. {
  38779. return (((unsigned int) index) < (unsigned int) selected.size())
  38780. ? selected [index] : -1;
  38781. }
  38782. bool ListBox::isRowSelected (const int row) const
  38783. {
  38784. return selected.contains (row);
  38785. }
  38786. int ListBox::getLastRowSelected() const
  38787. {
  38788. return (isRowSelected (lastRowSelected)) ? lastRowSelected : -1;
  38789. }
  38790. int ListBox::getRowContainingPosition (const int x, const int y) const throw()
  38791. {
  38792. if (((unsigned int) x) < (unsigned int) getWidth())
  38793. {
  38794. const int row = (viewport->getViewPositionY() + y - viewport->getY()) / rowHeight;
  38795. if (((unsigned int) row) < (unsigned int) totalItems)
  38796. return row;
  38797. }
  38798. return -1;
  38799. }
  38800. int ListBox::getInsertionIndexForPosition (const int x, const int y) const throw()
  38801. {
  38802. if (((unsigned int) x) < (unsigned int) getWidth())
  38803. {
  38804. const int row = (viewport->getViewPositionY() + y + rowHeight / 2 - viewport->getY()) / rowHeight;
  38805. return jlimit (0, totalItems, row);
  38806. }
  38807. return -1;
  38808. }
  38809. Component* ListBox::getComponentForRowNumber (const int row) const throw()
  38810. {
  38811. Component* const listRowComp = viewport->getComponentForRowIfOnscreen (row);
  38812. return listRowComp != 0 ? listRowComp->getChildComponent (0) : 0;
  38813. }
  38814. int ListBox::getRowNumberOfComponent (Component* const rowComponent) const throw()
  38815. {
  38816. return viewport->getRowNumberOfComponent (rowComponent);
  38817. }
  38818. const Rectangle<int> ListBox::getRowPosition (const int rowNumber,
  38819. const bool relativeToComponentTopLeft) const throw()
  38820. {
  38821. const int rowHeight = getRowHeight();
  38822. int y = viewport->getY() + rowHeight * rowNumber;
  38823. if (relativeToComponentTopLeft)
  38824. y -= viewport->getViewPositionY();
  38825. return Rectangle<int> (viewport->getX(), y,
  38826. viewport->getViewedComponent()->getWidth(), rowHeight);
  38827. }
  38828. void ListBox::setVerticalPosition (const double proportion)
  38829. {
  38830. const int offscreen = viewport->getViewedComponent()->getHeight() - viewport->getHeight();
  38831. viewport->setViewPosition (viewport->getViewPositionX(),
  38832. jmax (0, roundToInt (proportion * offscreen)));
  38833. }
  38834. double ListBox::getVerticalPosition() const
  38835. {
  38836. const int offscreen = viewport->getViewedComponent()->getHeight() - viewport->getHeight();
  38837. return (offscreen > 0) ? viewport->getViewPositionY() / (double) offscreen
  38838. : 0;
  38839. }
  38840. int ListBox::getVisibleRowWidth() const throw()
  38841. {
  38842. return viewport->getViewWidth();
  38843. }
  38844. void ListBox::scrollToEnsureRowIsOnscreen (const int row)
  38845. {
  38846. if (row < viewport->firstWholeIndex)
  38847. {
  38848. viewport->setViewPosition (viewport->getViewPositionX(),
  38849. row * getRowHeight());
  38850. }
  38851. else if (row >= viewport->lastWholeIndex)
  38852. {
  38853. viewport->setViewPosition (viewport->getViewPositionX(),
  38854. jmax (0, (row + 1) * getRowHeight() - viewport->getMaximumVisibleHeight()));
  38855. }
  38856. }
  38857. bool ListBox::keyPressed (const KeyPress& key)
  38858. {
  38859. const int numVisibleRows = viewport->getHeight() / getRowHeight();
  38860. const bool multiple = multipleSelection
  38861. && (lastRowSelected >= 0)
  38862. && (key.getModifiers().isShiftDown()
  38863. || key.getModifiers().isCtrlDown()
  38864. || key.getModifiers().isCommandDown());
  38865. if (key.isKeyCode (KeyPress::upKey))
  38866. {
  38867. if (multiple)
  38868. selectRangeOfRows (lastRowSelected, lastRowSelected - 1);
  38869. else
  38870. selectRow (jmax (0, lastRowSelected - 1));
  38871. }
  38872. else if (key.isKeyCode (KeyPress::returnKey)
  38873. && isRowSelected (lastRowSelected))
  38874. {
  38875. if (model != 0)
  38876. model->returnKeyPressed (lastRowSelected);
  38877. }
  38878. else if (key.isKeyCode (KeyPress::pageUpKey))
  38879. {
  38880. if (multiple)
  38881. selectRangeOfRows (lastRowSelected, lastRowSelected - numVisibleRows);
  38882. else
  38883. selectRow (jmax (0, jmax (0, lastRowSelected) - numVisibleRows));
  38884. }
  38885. else if (key.isKeyCode (KeyPress::pageDownKey))
  38886. {
  38887. if (multiple)
  38888. selectRangeOfRows (lastRowSelected, lastRowSelected + numVisibleRows);
  38889. else
  38890. selectRow (jmin (totalItems - 1, jmax (0, lastRowSelected) + numVisibleRows));
  38891. }
  38892. else if (key.isKeyCode (KeyPress::homeKey))
  38893. {
  38894. if (multiple && key.getModifiers().isShiftDown())
  38895. selectRangeOfRows (lastRowSelected, 0);
  38896. else
  38897. selectRow (0);
  38898. }
  38899. else if (key.isKeyCode (KeyPress::endKey))
  38900. {
  38901. if (multiple && key.getModifiers().isShiftDown())
  38902. selectRangeOfRows (lastRowSelected, totalItems - 1);
  38903. else
  38904. selectRow (totalItems - 1);
  38905. }
  38906. else if (key.isKeyCode (KeyPress::downKey))
  38907. {
  38908. if (multiple)
  38909. selectRangeOfRows (lastRowSelected, lastRowSelected + 1);
  38910. else
  38911. selectRow (jmin (totalItems - 1, jmax (0, lastRowSelected) + 1));
  38912. }
  38913. else if ((key.isKeyCode (KeyPress::deleteKey) || key.isKeyCode (KeyPress::backspaceKey))
  38914. && isRowSelected (lastRowSelected))
  38915. {
  38916. if (model != 0)
  38917. model->deleteKeyPressed (lastRowSelected);
  38918. }
  38919. else if (multiple && key == KeyPress (T('a'), ModifierKeys::commandModifier, 0))
  38920. {
  38921. selectRangeOfRows (0, std::numeric_limits<int>::max());
  38922. }
  38923. else
  38924. {
  38925. return false;
  38926. }
  38927. return true;
  38928. }
  38929. bool ListBox::keyStateChanged (const bool isKeyDown)
  38930. {
  38931. return isKeyDown
  38932. && (KeyPress::isKeyCurrentlyDown (KeyPress::upKey)
  38933. || KeyPress::isKeyCurrentlyDown (KeyPress::pageUpKey)
  38934. || KeyPress::isKeyCurrentlyDown (KeyPress::downKey)
  38935. || KeyPress::isKeyCurrentlyDown (KeyPress::pageDownKey)
  38936. || KeyPress::isKeyCurrentlyDown (KeyPress::homeKey)
  38937. || KeyPress::isKeyCurrentlyDown (KeyPress::endKey)
  38938. || KeyPress::isKeyCurrentlyDown (KeyPress::returnKey));
  38939. }
  38940. void ListBox::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  38941. {
  38942. getHorizontalScrollBar()->mouseWheelMove (e, wheelIncrementX, 0);
  38943. getVerticalScrollBar()->mouseWheelMove (e, 0, wheelIncrementY);
  38944. }
  38945. void ListBox::mouseMove (const MouseEvent& e)
  38946. {
  38947. if (mouseMoveSelects)
  38948. {
  38949. const MouseEvent e2 (e.getEventRelativeTo (this));
  38950. selectRow (getRowContainingPosition (e2.x, e2.y), true);
  38951. lastMouseX = e2.x;
  38952. lastMouseY = e2.y;
  38953. }
  38954. }
  38955. void ListBox::mouseExit (const MouseEvent& e)
  38956. {
  38957. mouseMove (e);
  38958. }
  38959. void ListBox::mouseUp (const MouseEvent& e)
  38960. {
  38961. if (e.mouseWasClicked() && model != 0)
  38962. model->backgroundClicked();
  38963. }
  38964. void ListBox::setRowHeight (const int newHeight)
  38965. {
  38966. rowHeight = jmax (1, newHeight);
  38967. viewport->setSingleStepSizes (20, rowHeight);
  38968. updateContent();
  38969. }
  38970. int ListBox::getNumRowsOnScreen() const throw()
  38971. {
  38972. return viewport->getMaximumVisibleHeight() / rowHeight;
  38973. }
  38974. void ListBox::setMinimumContentWidth (const int newMinimumWidth)
  38975. {
  38976. minimumRowWidth = newMinimumWidth;
  38977. updateContent();
  38978. }
  38979. int ListBox::getVisibleContentWidth() const throw()
  38980. {
  38981. return viewport->getMaximumVisibleWidth();
  38982. }
  38983. ScrollBar* ListBox::getVerticalScrollBar() const throw()
  38984. {
  38985. return viewport->getVerticalScrollBar();
  38986. }
  38987. ScrollBar* ListBox::getHorizontalScrollBar() const throw()
  38988. {
  38989. return viewport->getHorizontalScrollBar();
  38990. }
  38991. void ListBox::colourChanged()
  38992. {
  38993. setOpaque (findColour (backgroundColourId).isOpaque());
  38994. viewport->setOpaque (isOpaque());
  38995. repaint();
  38996. }
  38997. void ListBox::setOutlineThickness (const int outlineThickness_)
  38998. {
  38999. outlineThickness = outlineThickness_;
  39000. resized();
  39001. }
  39002. void ListBox::setHeaderComponent (Component* const newHeaderComponent)
  39003. {
  39004. if (headerComponent != newHeaderComponent)
  39005. {
  39006. delete headerComponent;
  39007. headerComponent = newHeaderComponent;
  39008. addAndMakeVisible (newHeaderComponent);
  39009. ListBox::resized();
  39010. }
  39011. }
  39012. void ListBox::repaintRow (const int rowNumber) throw()
  39013. {
  39014. const Rectangle<int> r (getRowPosition (rowNumber, true));
  39015. repaint (r.getX(), r.getY(), r.getWidth(), r.getHeight());
  39016. }
  39017. Image* ListBox::createSnapshotOfSelectedRows (int& imageX, int& imageY)
  39018. {
  39019. Rectangle<int> imageArea;
  39020. const int firstRow = getRowContainingPosition (0, 0);
  39021. int i;
  39022. for (i = getNumRowsOnScreen() + 2; --i >= 0;)
  39023. {
  39024. Component* rowComp = viewport->getComponentForRowIfOnscreen (firstRow + i);
  39025. if (rowComp != 0 && isRowSelected (firstRow + i))
  39026. {
  39027. int x = 0, y = 0;
  39028. rowComp->relativePositionToOtherComponent (this, x, y);
  39029. const Rectangle<int> rowRect (x, y, rowComp->getWidth(), rowComp->getHeight());
  39030. if (imageArea.isEmpty())
  39031. imageArea = rowRect;
  39032. else
  39033. imageArea = imageArea.getUnion (rowRect);
  39034. }
  39035. }
  39036. imageArea = imageArea.getIntersection (Rectangle<int> (0, 0, getWidth(), getHeight()));
  39037. imageX = imageArea.getX();
  39038. imageY = imageArea.getY();
  39039. Image* snapshot = Image::createNativeImage (Image::ARGB, imageArea.getWidth(), imageArea.getHeight(), true);
  39040. for (i = getNumRowsOnScreen() + 2; --i >= 0;)
  39041. {
  39042. Component* rowComp = viewport->getComponentForRowIfOnscreen (firstRow + i);
  39043. if (rowComp != 0 && isRowSelected (firstRow + i))
  39044. {
  39045. int x = 0, y = 0;
  39046. rowComp->relativePositionToOtherComponent (this, x, y);
  39047. Graphics g (*snapshot);
  39048. g.setOrigin (x - imageX, y - imageY);
  39049. if (g.reduceClipRegion (0, 0, rowComp->getWidth(), rowComp->getHeight()))
  39050. rowComp->paintEntireComponent (g);
  39051. }
  39052. }
  39053. return snapshot;
  39054. }
  39055. void ListBox::startDragAndDrop (const MouseEvent& e, const String& dragDescription)
  39056. {
  39057. DragAndDropContainer* const dragContainer
  39058. = DragAndDropContainer::findParentDragContainerFor (this);
  39059. if (dragContainer != 0)
  39060. {
  39061. int x, y;
  39062. Image* dragImage = createSnapshotOfSelectedRows (x, y);
  39063. dragImage->multiplyAllAlphas (0.6f);
  39064. MouseEvent e2 (e.getEventRelativeTo (this));
  39065. const Point<int> p (x - e2.x, y - e2.y);
  39066. dragContainer->startDragging (dragDescription, this, dragImage, true, &p);
  39067. }
  39068. else
  39069. {
  39070. // to be able to do a drag-and-drop operation, the listbox needs to
  39071. // be inside a component which is also a DragAndDropContainer.
  39072. jassertfalse
  39073. }
  39074. }
  39075. Component* ListBoxModel::refreshComponentForRow (int, bool, Component* existingComponentToUpdate)
  39076. {
  39077. (void) existingComponentToUpdate;
  39078. jassert (existingComponentToUpdate == 0); // indicates a failure in the code the recycles the components
  39079. return 0;
  39080. }
  39081. void ListBoxModel::listBoxItemClicked (int, const MouseEvent&)
  39082. {
  39083. }
  39084. void ListBoxModel::listBoxItemDoubleClicked (int, const MouseEvent&)
  39085. {
  39086. }
  39087. void ListBoxModel::backgroundClicked()
  39088. {
  39089. }
  39090. void ListBoxModel::selectedRowsChanged (int)
  39091. {
  39092. }
  39093. void ListBoxModel::deleteKeyPressed (int)
  39094. {
  39095. }
  39096. void ListBoxModel::returnKeyPressed (int)
  39097. {
  39098. }
  39099. void ListBoxModel::listWasScrolled()
  39100. {
  39101. }
  39102. const String ListBoxModel::getDragSourceDescription (const SparseSet<int>&)
  39103. {
  39104. return String::empty;
  39105. }
  39106. const String ListBoxModel::getTooltipForRow (int)
  39107. {
  39108. return String::empty;
  39109. }
  39110. END_JUCE_NAMESPACE
  39111. /*** End of inlined file: juce_ListBox.cpp ***/
  39112. /*** Start of inlined file: juce_ProgressBar.cpp ***/
  39113. BEGIN_JUCE_NAMESPACE
  39114. ProgressBar::ProgressBar (double& progress_)
  39115. : progress (progress_),
  39116. displayPercentage (true),
  39117. lastCallbackTime (0)
  39118. {
  39119. currentValue = jlimit (0.0, 1.0, progress);
  39120. }
  39121. ProgressBar::~ProgressBar()
  39122. {
  39123. }
  39124. void ProgressBar::setPercentageDisplay (const bool shouldDisplayPercentage)
  39125. {
  39126. displayPercentage = shouldDisplayPercentage;
  39127. repaint();
  39128. }
  39129. void ProgressBar::setTextToDisplay (const String& text)
  39130. {
  39131. displayPercentage = false;
  39132. displayedMessage = text;
  39133. }
  39134. void ProgressBar::lookAndFeelChanged()
  39135. {
  39136. setOpaque (findColour (backgroundColourId).isOpaque());
  39137. }
  39138. void ProgressBar::colourChanged()
  39139. {
  39140. lookAndFeelChanged();
  39141. }
  39142. void ProgressBar::paint (Graphics& g)
  39143. {
  39144. String text;
  39145. if (displayPercentage)
  39146. {
  39147. if (currentValue >= 0 && currentValue <= 1.0)
  39148. text << roundToInt (currentValue * 100.0) << T("%");
  39149. }
  39150. else
  39151. {
  39152. text = displayedMessage;
  39153. }
  39154. getLookAndFeel().drawProgressBar (g, *this,
  39155. getWidth(), getHeight(),
  39156. currentValue, text);
  39157. }
  39158. void ProgressBar::visibilityChanged()
  39159. {
  39160. if (isVisible())
  39161. startTimer (30);
  39162. else
  39163. stopTimer();
  39164. }
  39165. void ProgressBar::timerCallback()
  39166. {
  39167. double newProgress = progress;
  39168. const uint32 now = Time::getMillisecondCounter();
  39169. const int timeSinceLastCallback = (int) (now - lastCallbackTime);
  39170. lastCallbackTime = now;
  39171. if (currentValue != newProgress
  39172. || newProgress < 0 || newProgress >= 1.0
  39173. || currentMessage != displayedMessage)
  39174. {
  39175. if (currentValue < newProgress
  39176. && newProgress >= 0 && newProgress < 1.0
  39177. && currentValue >= 0 && currentValue < 1.0)
  39178. {
  39179. newProgress = jmin (currentValue + 0.0008 * timeSinceLastCallback,
  39180. newProgress);
  39181. }
  39182. currentValue = newProgress;
  39183. currentMessage = displayedMessage;
  39184. repaint();
  39185. }
  39186. }
  39187. END_JUCE_NAMESPACE
  39188. /*** End of inlined file: juce_ProgressBar.cpp ***/
  39189. /*** Start of inlined file: juce_Slider.cpp ***/
  39190. BEGIN_JUCE_NAMESPACE
  39191. class SliderPopupDisplayComponent : public BubbleComponent
  39192. {
  39193. public:
  39194. SliderPopupDisplayComponent (Slider* const owner_)
  39195. : owner (owner_),
  39196. font (15.0f, Font::bold)
  39197. {
  39198. setAlwaysOnTop (true);
  39199. }
  39200. ~SliderPopupDisplayComponent()
  39201. {
  39202. }
  39203. void paintContent (Graphics& g, int w, int h)
  39204. {
  39205. g.setFont (font);
  39206. g.setColour (Colours::black);
  39207. g.drawFittedText (text, 0, 0, w, h, Justification::centred, 1);
  39208. }
  39209. void getContentSize (int& w, int& h)
  39210. {
  39211. w = font.getStringWidth (text) + 18;
  39212. h = (int) (font.getHeight() * 1.6f);
  39213. }
  39214. void updatePosition (const String& newText)
  39215. {
  39216. if (text != newText)
  39217. {
  39218. text = newText;
  39219. repaint();
  39220. }
  39221. BubbleComponent::setPosition (owner);
  39222. }
  39223. juce_UseDebuggingNewOperator
  39224. private:
  39225. Slider* owner;
  39226. Font font;
  39227. String text;
  39228. SliderPopupDisplayComponent (const SliderPopupDisplayComponent&);
  39229. const SliderPopupDisplayComponent& operator= (const SliderPopupDisplayComponent&);
  39230. };
  39231. Slider::Slider (const String& name)
  39232. : Component (name),
  39233. lastCurrentValue (0),
  39234. lastValueMin (0),
  39235. lastValueMax (0),
  39236. minimum (0),
  39237. maximum (10),
  39238. interval (0),
  39239. skewFactor (1.0),
  39240. velocityModeSensitivity (1.0),
  39241. velocityModeOffset (0.0),
  39242. velocityModeThreshold (1),
  39243. rotaryStart (float_Pi * 1.2f),
  39244. rotaryEnd (float_Pi * 2.8f),
  39245. numDecimalPlaces (7),
  39246. sliderRegionStart (0),
  39247. sliderRegionSize (1),
  39248. sliderBeingDragged (-1),
  39249. pixelsForFullDragExtent (250),
  39250. style (LinearHorizontal),
  39251. textBoxPos (TextBoxLeft),
  39252. textBoxWidth (80),
  39253. textBoxHeight (20),
  39254. incDecButtonMode (incDecButtonsNotDraggable),
  39255. editableText (true),
  39256. doubleClickToValue (false),
  39257. isVelocityBased (false),
  39258. userKeyOverridesVelocity (true),
  39259. rotaryStop (true),
  39260. incDecButtonsSideBySide (false),
  39261. sendChangeOnlyOnRelease (false),
  39262. popupDisplayEnabled (false),
  39263. menuEnabled (false),
  39264. menuShown (false),
  39265. scrollWheelEnabled (true),
  39266. snapsToMousePos (true),
  39267. valueBox (0),
  39268. incButton (0),
  39269. decButton (0),
  39270. popupDisplay (0),
  39271. parentForPopupDisplay (0)
  39272. {
  39273. setWantsKeyboardFocus (false);
  39274. setRepaintsOnMouseActivity (true);
  39275. lookAndFeelChanged();
  39276. updateText();
  39277. currentValue.addListener (this);
  39278. valueMin.addListener (this);
  39279. valueMax.addListener (this);
  39280. }
  39281. Slider::~Slider()
  39282. {
  39283. currentValue.removeListener (this);
  39284. valueMin.removeListener (this);
  39285. valueMax.removeListener (this);
  39286. popupDisplay = 0;
  39287. deleteAllChildren();
  39288. }
  39289. void Slider::handleAsyncUpdate()
  39290. {
  39291. cancelPendingUpdate();
  39292. for (int i = listeners.size(); --i >= 0;)
  39293. {
  39294. ((SliderListener*) listeners.getUnchecked (i))->sliderValueChanged (this);
  39295. i = jmin (i, listeners.size());
  39296. }
  39297. }
  39298. void Slider::sendDragStart()
  39299. {
  39300. startedDragging();
  39301. for (int i = listeners.size(); --i >= 0;)
  39302. {
  39303. ((SliderListener*) listeners.getUnchecked (i))->sliderDragStarted (this);
  39304. i = jmin (i, listeners.size());
  39305. }
  39306. }
  39307. void Slider::sendDragEnd()
  39308. {
  39309. stoppedDragging();
  39310. sliderBeingDragged = -1;
  39311. for (int i = listeners.size(); --i >= 0;)
  39312. {
  39313. ((SliderListener*) listeners.getUnchecked (i))->sliderDragEnded (this);
  39314. i = jmin (i, listeners.size());
  39315. }
  39316. }
  39317. void Slider::addListener (SliderListener* const listener)
  39318. {
  39319. jassert (listener != 0);
  39320. if (listener != 0)
  39321. listeners.add (listener);
  39322. }
  39323. void Slider::removeListener (SliderListener* const listener)
  39324. {
  39325. listeners.removeValue (listener);
  39326. }
  39327. void Slider::setSliderStyle (const SliderStyle newStyle)
  39328. {
  39329. if (style != newStyle)
  39330. {
  39331. style = newStyle;
  39332. repaint();
  39333. lookAndFeelChanged();
  39334. }
  39335. }
  39336. void Slider::setRotaryParameters (const float startAngleRadians,
  39337. const float endAngleRadians,
  39338. const bool stopAtEnd)
  39339. {
  39340. // make sure the values are sensible..
  39341. jassert (rotaryStart >= 0 && rotaryEnd >= 0);
  39342. jassert (rotaryStart < float_Pi * 4.0f && rotaryEnd < float_Pi * 4.0f);
  39343. jassert (rotaryStart < rotaryEnd);
  39344. rotaryStart = startAngleRadians;
  39345. rotaryEnd = endAngleRadians;
  39346. rotaryStop = stopAtEnd;
  39347. }
  39348. void Slider::setVelocityBasedMode (const bool velBased)
  39349. {
  39350. isVelocityBased = velBased;
  39351. }
  39352. void Slider::setVelocityModeParameters (const double sensitivity,
  39353. const int threshold,
  39354. const double offset,
  39355. const bool userCanPressKeyToSwapMode)
  39356. {
  39357. jassert (threshold >= 0);
  39358. jassert (sensitivity > 0);
  39359. jassert (offset >= 0);
  39360. velocityModeSensitivity = sensitivity;
  39361. velocityModeOffset = offset;
  39362. velocityModeThreshold = threshold;
  39363. userKeyOverridesVelocity = userCanPressKeyToSwapMode;
  39364. }
  39365. void Slider::setSkewFactor (const double factor)
  39366. {
  39367. skewFactor = factor;
  39368. }
  39369. void Slider::setSkewFactorFromMidPoint (const double sliderValueToShowAtMidPoint)
  39370. {
  39371. if (maximum > minimum)
  39372. skewFactor = log (0.5) / log ((sliderValueToShowAtMidPoint - minimum)
  39373. / (maximum - minimum));
  39374. }
  39375. void Slider::setMouseDragSensitivity (const int distanceForFullScaleDrag)
  39376. {
  39377. jassert (distanceForFullScaleDrag > 0);
  39378. pixelsForFullDragExtent = distanceForFullScaleDrag;
  39379. }
  39380. void Slider::setIncDecButtonsMode (const IncDecButtonMode mode)
  39381. {
  39382. if (incDecButtonMode != mode)
  39383. {
  39384. incDecButtonMode = mode;
  39385. lookAndFeelChanged();
  39386. }
  39387. }
  39388. void Slider::setTextBoxStyle (const TextEntryBoxPosition newPosition,
  39389. const bool isReadOnly,
  39390. const int textEntryBoxWidth,
  39391. const int textEntryBoxHeight)
  39392. {
  39393. textBoxPos = newPosition;
  39394. editableText = ! isReadOnly;
  39395. textBoxWidth = textEntryBoxWidth;
  39396. textBoxHeight = textEntryBoxHeight;
  39397. repaint();
  39398. lookAndFeelChanged();
  39399. }
  39400. void Slider::setTextBoxIsEditable (const bool shouldBeEditable)
  39401. {
  39402. editableText = shouldBeEditable;
  39403. if (valueBox != 0)
  39404. valueBox->setEditable (shouldBeEditable && isEnabled());
  39405. }
  39406. void Slider::showTextBox()
  39407. {
  39408. jassert (editableText); // this should probably be avoided in read-only sliders.
  39409. if (valueBox != 0)
  39410. valueBox->showEditor();
  39411. }
  39412. void Slider::hideTextBox (const bool discardCurrentEditorContents)
  39413. {
  39414. if (valueBox != 0)
  39415. {
  39416. valueBox->hideEditor (discardCurrentEditorContents);
  39417. if (discardCurrentEditorContents)
  39418. updateText();
  39419. }
  39420. }
  39421. void Slider::setChangeNotificationOnlyOnRelease (const bool onlyNotifyOnRelease)
  39422. {
  39423. sendChangeOnlyOnRelease = onlyNotifyOnRelease;
  39424. }
  39425. void Slider::setSliderSnapsToMousePosition (const bool shouldSnapToMouse)
  39426. {
  39427. snapsToMousePos = shouldSnapToMouse;
  39428. }
  39429. void Slider::setPopupDisplayEnabled (const bool enabled,
  39430. Component* const parentComponentToUse)
  39431. {
  39432. popupDisplayEnabled = enabled;
  39433. parentForPopupDisplay = parentComponentToUse;
  39434. }
  39435. void Slider::colourChanged()
  39436. {
  39437. lookAndFeelChanged();
  39438. }
  39439. void Slider::lookAndFeelChanged()
  39440. {
  39441. const String previousTextBoxContent (valueBox != 0 ? valueBox->getText()
  39442. : getTextFromValue (currentValue.getValue()));
  39443. deleteAllChildren();
  39444. valueBox = 0;
  39445. LookAndFeel& lf = getLookAndFeel();
  39446. if (textBoxPos != NoTextBox)
  39447. {
  39448. addAndMakeVisible (valueBox = getLookAndFeel().createSliderTextBox (*this));
  39449. valueBox->setWantsKeyboardFocus (false);
  39450. valueBox->setText (previousTextBoxContent, false);
  39451. valueBox->setEditable (editableText && isEnabled());
  39452. valueBox->addListener (this);
  39453. if (style == LinearBar)
  39454. valueBox->addMouseListener (this, false);
  39455. valueBox->setTooltip (getTooltip());
  39456. }
  39457. if (style == IncDecButtons)
  39458. {
  39459. addAndMakeVisible (incButton = lf.createSliderButton (true));
  39460. incButton->addButtonListener (this);
  39461. addAndMakeVisible (decButton = lf.createSliderButton (false));
  39462. decButton->addButtonListener (this);
  39463. if (incDecButtonMode != incDecButtonsNotDraggable)
  39464. {
  39465. incButton->addMouseListener (this, false);
  39466. decButton->addMouseListener (this, false);
  39467. }
  39468. else
  39469. {
  39470. incButton->setRepeatSpeed (300, 100, 20);
  39471. incButton->addMouseListener (decButton, false);
  39472. decButton->setRepeatSpeed (300, 100, 20);
  39473. decButton->addMouseListener (incButton, false);
  39474. }
  39475. incButton->setTooltip (getTooltip());
  39476. decButton->setTooltip (getTooltip());
  39477. }
  39478. setComponentEffect (lf.getSliderEffect());
  39479. resized();
  39480. repaint();
  39481. }
  39482. void Slider::setRange (const double newMin,
  39483. const double newMax,
  39484. const double newInt)
  39485. {
  39486. if (minimum != newMin
  39487. || maximum != newMax
  39488. || interval != newInt)
  39489. {
  39490. minimum = newMin;
  39491. maximum = newMax;
  39492. interval = newInt;
  39493. // figure out the number of DPs needed to display all values at this
  39494. // interval setting.
  39495. numDecimalPlaces = 7;
  39496. if (newInt != 0)
  39497. {
  39498. int v = abs ((int) (newInt * 10000000));
  39499. while ((v % 10) == 0)
  39500. {
  39501. --numDecimalPlaces;
  39502. v /= 10;
  39503. }
  39504. }
  39505. // keep the current values inside the new range..
  39506. if (style != TwoValueHorizontal && style != TwoValueVertical)
  39507. {
  39508. setValue (getValue(), false, false);
  39509. }
  39510. else
  39511. {
  39512. setMinValue (getMinValue(), false, false);
  39513. setMaxValue (getMaxValue(), false, false);
  39514. }
  39515. updateText();
  39516. }
  39517. }
  39518. void Slider::triggerChangeMessage (const bool synchronous)
  39519. {
  39520. if (synchronous)
  39521. handleAsyncUpdate();
  39522. else
  39523. triggerAsyncUpdate();
  39524. valueChanged();
  39525. }
  39526. void Slider::valueChanged (Value& value)
  39527. {
  39528. if (value.refersToSameSourceAs (currentValue))
  39529. {
  39530. if (style != TwoValueHorizontal && style != TwoValueVertical)
  39531. setValue (currentValue.getValue(), false, false);
  39532. }
  39533. else if (value.refersToSameSourceAs (valueMin))
  39534. setMinValue (valueMin.getValue(), false, false, true);
  39535. else if (value.refersToSameSourceAs (valueMax))
  39536. setMaxValue (valueMax.getValue(), false, false, true);
  39537. }
  39538. double Slider::getValue() const
  39539. {
  39540. // for a two-value style slider, you should use the getMinValue() and getMaxValue()
  39541. // methods to get the two values.
  39542. jassert (style != TwoValueHorizontal && style != TwoValueVertical);
  39543. return currentValue.getValue();
  39544. }
  39545. void Slider::setValue (double newValue,
  39546. const bool sendUpdateMessage,
  39547. const bool sendMessageSynchronously)
  39548. {
  39549. // for a two-value style slider, you should use the setMinValue() and setMaxValue()
  39550. // methods to set the two values.
  39551. jassert (style != TwoValueHorizontal && style != TwoValueVertical);
  39552. newValue = constrainedValue (newValue);
  39553. if (style == ThreeValueHorizontal || style == ThreeValueVertical)
  39554. {
  39555. jassert ((double) valueMin.getValue() <= (double) valueMax.getValue());
  39556. newValue = jlimit ((double) valueMin.getValue(),
  39557. (double) valueMax.getValue(),
  39558. newValue);
  39559. }
  39560. if (newValue != lastCurrentValue)
  39561. {
  39562. if (valueBox != 0)
  39563. valueBox->hideEditor (true);
  39564. lastCurrentValue = newValue;
  39565. currentValue = newValue;
  39566. updateText();
  39567. repaint();
  39568. if (popupDisplay != 0)
  39569. {
  39570. ((SliderPopupDisplayComponent*) popupDisplay)->updatePosition (getTextFromValue (newValue));
  39571. popupDisplay->repaint();
  39572. }
  39573. if (sendUpdateMessage)
  39574. triggerChangeMessage (sendMessageSynchronously);
  39575. }
  39576. }
  39577. double Slider::getMinValue() const
  39578. {
  39579. // The minimum value only applies to sliders that are in two- or three-value mode.
  39580. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  39581. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  39582. return valueMin.getValue();
  39583. }
  39584. double Slider::getMaxValue() const
  39585. {
  39586. // The maximum value only applies to sliders that are in two- or three-value mode.
  39587. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  39588. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  39589. return valueMax.getValue();
  39590. }
  39591. void Slider::setMinValue (double newValue, const bool sendUpdateMessage, const bool sendMessageSynchronously, const bool allowNudgingOfOtherValues)
  39592. {
  39593. // The minimum value only applies to sliders that are in two- or three-value mode.
  39594. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  39595. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  39596. newValue = constrainedValue (newValue);
  39597. if (style == TwoValueHorizontal || style == TwoValueVertical)
  39598. {
  39599. if (allowNudgingOfOtherValues && newValue > (double) valueMax.getValue())
  39600. setMaxValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39601. newValue = jmin ((double) valueMax.getValue(), newValue);
  39602. }
  39603. else
  39604. {
  39605. if (allowNudgingOfOtherValues && newValue > lastCurrentValue)
  39606. setValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39607. newValue = jmin (lastCurrentValue, newValue);
  39608. }
  39609. if (lastValueMin != newValue)
  39610. {
  39611. lastValueMin = newValue;
  39612. valueMin = newValue;
  39613. repaint();
  39614. if (popupDisplay != 0)
  39615. {
  39616. ((SliderPopupDisplayComponent*) popupDisplay)->updatePosition (getTextFromValue (newValue));
  39617. popupDisplay->repaint();
  39618. }
  39619. if (sendUpdateMessage)
  39620. triggerChangeMessage (sendMessageSynchronously);
  39621. }
  39622. }
  39623. void Slider::setMaxValue (double newValue, const bool sendUpdateMessage, const bool sendMessageSynchronously, const bool allowNudgingOfOtherValues)
  39624. {
  39625. // The maximum value only applies to sliders that are in two- or three-value mode.
  39626. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  39627. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  39628. newValue = constrainedValue (newValue);
  39629. if (style == TwoValueHorizontal || style == TwoValueVertical)
  39630. {
  39631. if (allowNudgingOfOtherValues && newValue < (double) valueMin.getValue())
  39632. setMinValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39633. newValue = jmax ((double) valueMin.getValue(), newValue);
  39634. }
  39635. else
  39636. {
  39637. if (allowNudgingOfOtherValues && newValue < lastCurrentValue)
  39638. setValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39639. newValue = jmax (lastCurrentValue, newValue);
  39640. }
  39641. if (lastValueMax != newValue)
  39642. {
  39643. lastValueMax = newValue;
  39644. valueMax = newValue;
  39645. repaint();
  39646. if (popupDisplay != 0)
  39647. {
  39648. ((SliderPopupDisplayComponent*) popupDisplay)->updatePosition (getTextFromValue (valueMax.getValue()));
  39649. popupDisplay->repaint();
  39650. }
  39651. if (sendUpdateMessage)
  39652. triggerChangeMessage (sendMessageSynchronously);
  39653. }
  39654. }
  39655. void Slider::setDoubleClickReturnValue (const bool isDoubleClickEnabled,
  39656. const double valueToSetOnDoubleClick)
  39657. {
  39658. doubleClickToValue = isDoubleClickEnabled;
  39659. doubleClickReturnValue = valueToSetOnDoubleClick;
  39660. }
  39661. double Slider::getDoubleClickReturnValue (bool& isEnabled_) const
  39662. {
  39663. isEnabled_ = doubleClickToValue;
  39664. return doubleClickReturnValue;
  39665. }
  39666. void Slider::updateText()
  39667. {
  39668. if (valueBox != 0)
  39669. valueBox->setText (getTextFromValue (currentValue.getValue()), false);
  39670. }
  39671. void Slider::setTextValueSuffix (const String& suffix)
  39672. {
  39673. if (textSuffix != suffix)
  39674. {
  39675. textSuffix = suffix;
  39676. updateText();
  39677. }
  39678. }
  39679. const String Slider::getTextFromValue (double v)
  39680. {
  39681. if (numDecimalPlaces > 0)
  39682. return String (v, numDecimalPlaces) + textSuffix;
  39683. else
  39684. return String (roundToInt (v)) + textSuffix;
  39685. }
  39686. double Slider::getValueFromText (const String& text)
  39687. {
  39688. String t (text.trimStart());
  39689. if (t.endsWith (textSuffix))
  39690. t = t.substring (0, t.length() - textSuffix.length());
  39691. while (t.startsWithChar (T('+')))
  39692. t = t.substring (1).trimStart();
  39693. return t.initialSectionContainingOnly (T("0123456789.,-"))
  39694. .getDoubleValue();
  39695. }
  39696. double Slider::proportionOfLengthToValue (double proportion)
  39697. {
  39698. if (skewFactor != 1.0 && proportion > 0.0)
  39699. proportion = exp (log (proportion) / skewFactor);
  39700. return minimum + (maximum - minimum) * proportion;
  39701. }
  39702. double Slider::valueToProportionOfLength (double value)
  39703. {
  39704. const double n = (value - minimum) / (maximum - minimum);
  39705. return skewFactor == 1.0 ? n : pow (n, skewFactor);
  39706. }
  39707. double Slider::snapValue (double attemptedValue, const bool)
  39708. {
  39709. return attemptedValue;
  39710. }
  39711. void Slider::startedDragging()
  39712. {
  39713. }
  39714. void Slider::stoppedDragging()
  39715. {
  39716. }
  39717. void Slider::valueChanged()
  39718. {
  39719. }
  39720. void Slider::enablementChanged()
  39721. {
  39722. repaint();
  39723. }
  39724. void Slider::setPopupMenuEnabled (const bool menuEnabled_)
  39725. {
  39726. menuEnabled = menuEnabled_;
  39727. }
  39728. void Slider::setScrollWheelEnabled (const bool enabled)
  39729. {
  39730. scrollWheelEnabled = enabled;
  39731. }
  39732. void Slider::labelTextChanged (Label* label)
  39733. {
  39734. const double newValue = snapValue (getValueFromText (label->getText()), false);
  39735. if (newValue != (double) currentValue.getValue())
  39736. {
  39737. sendDragStart();
  39738. setValue (newValue, true, true);
  39739. sendDragEnd();
  39740. }
  39741. updateText(); // force a clean-up of the text, needed in case setValue() hasn't done this.
  39742. }
  39743. void Slider::buttonClicked (Button* button)
  39744. {
  39745. if (style == IncDecButtons)
  39746. {
  39747. sendDragStart();
  39748. if (button == incButton)
  39749. setValue (snapValue (getValue() + interval, false), true, true);
  39750. else if (button == decButton)
  39751. setValue (snapValue (getValue() - interval, false), true, true);
  39752. sendDragEnd();
  39753. }
  39754. }
  39755. double Slider::constrainedValue (double value) const
  39756. {
  39757. if (interval > 0)
  39758. value = minimum + interval * floor ((value - minimum) / interval + 0.5);
  39759. if (value <= minimum || maximum <= minimum)
  39760. value = minimum;
  39761. else if (value >= maximum)
  39762. value = maximum;
  39763. return value;
  39764. }
  39765. float Slider::getLinearSliderPos (const double value)
  39766. {
  39767. double sliderPosProportional;
  39768. if (maximum > minimum)
  39769. {
  39770. if (value < minimum)
  39771. {
  39772. sliderPosProportional = 0.0;
  39773. }
  39774. else if (value > maximum)
  39775. {
  39776. sliderPosProportional = 1.0;
  39777. }
  39778. else
  39779. {
  39780. sliderPosProportional = valueToProportionOfLength (value);
  39781. jassert (sliderPosProportional >= 0 && sliderPosProportional <= 1.0);
  39782. }
  39783. }
  39784. else
  39785. {
  39786. sliderPosProportional = 0.5;
  39787. }
  39788. if (isVertical() || style == IncDecButtons)
  39789. sliderPosProportional = 1.0 - sliderPosProportional;
  39790. return (float) (sliderRegionStart + sliderPosProportional * sliderRegionSize);
  39791. }
  39792. bool Slider::isHorizontal() const
  39793. {
  39794. return style == LinearHorizontal
  39795. || style == LinearBar
  39796. || style == TwoValueHorizontal
  39797. || style == ThreeValueHorizontal;
  39798. }
  39799. bool Slider::isVertical() const
  39800. {
  39801. return style == LinearVertical
  39802. || style == TwoValueVertical
  39803. || style == ThreeValueVertical;
  39804. }
  39805. bool Slider::incDecDragDirectionIsHorizontal() const
  39806. {
  39807. return incDecButtonMode == incDecButtonsDraggable_Horizontal
  39808. || (incDecButtonMode == incDecButtonsDraggable_AutoDirection && incDecButtonsSideBySide);
  39809. }
  39810. float Slider::getPositionOfValue (const double value)
  39811. {
  39812. if (isHorizontal() || isVertical())
  39813. {
  39814. return getLinearSliderPos (value);
  39815. }
  39816. else
  39817. {
  39818. jassertfalse // not a valid call on a slider that doesn't work linearly!
  39819. return 0.0f;
  39820. }
  39821. }
  39822. void Slider::paint (Graphics& g)
  39823. {
  39824. if (style != IncDecButtons)
  39825. {
  39826. if (style == Rotary || style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  39827. {
  39828. const float sliderPos = (float) valueToProportionOfLength (lastCurrentValue);
  39829. jassert (sliderPos >= 0 && sliderPos <= 1.0f);
  39830. getLookAndFeel().drawRotarySlider (g,
  39831. sliderRect.getX(),
  39832. sliderRect.getY(),
  39833. sliderRect.getWidth(),
  39834. sliderRect.getHeight(),
  39835. sliderPos,
  39836. rotaryStart, rotaryEnd,
  39837. *this);
  39838. }
  39839. else
  39840. {
  39841. getLookAndFeel().drawLinearSlider (g,
  39842. sliderRect.getX(),
  39843. sliderRect.getY(),
  39844. sliderRect.getWidth(),
  39845. sliderRect.getHeight(),
  39846. getLinearSliderPos (lastCurrentValue),
  39847. getLinearSliderPos (lastValueMin),
  39848. getLinearSliderPos (lastValueMax),
  39849. style,
  39850. *this);
  39851. }
  39852. if (style == LinearBar && valueBox == 0)
  39853. {
  39854. g.setColour (findColour (Slider::textBoxOutlineColourId));
  39855. g.drawRect (0, 0, getWidth(), getHeight(), 1);
  39856. }
  39857. }
  39858. }
  39859. void Slider::resized()
  39860. {
  39861. int minXSpace = 0;
  39862. int minYSpace = 0;
  39863. if (textBoxPos == TextBoxLeft || textBoxPos == TextBoxRight)
  39864. minXSpace = 30;
  39865. else
  39866. minYSpace = 15;
  39867. const int tbw = jmax (0, jmin (textBoxWidth, getWidth() - minXSpace));
  39868. const int tbh = jmax (0, jmin (textBoxHeight, getHeight() - minYSpace));
  39869. if (style == LinearBar)
  39870. {
  39871. if (valueBox != 0)
  39872. valueBox->setBounds (0, 0, getWidth(), getHeight());
  39873. }
  39874. else
  39875. {
  39876. if (textBoxPos == NoTextBox)
  39877. {
  39878. sliderRect.setBounds (0, 0, getWidth(), getHeight());
  39879. }
  39880. else if (textBoxPos == TextBoxLeft)
  39881. {
  39882. valueBox->setBounds (0, (getHeight() - tbh) / 2, tbw, tbh);
  39883. sliderRect.setBounds (tbw, 0, getWidth() - tbw, getHeight());
  39884. }
  39885. else if (textBoxPos == TextBoxRight)
  39886. {
  39887. valueBox->setBounds (getWidth() - tbw, (getHeight() - tbh) / 2, tbw, tbh);
  39888. sliderRect.setBounds (0, 0, getWidth() - tbw, getHeight());
  39889. }
  39890. else if (textBoxPos == TextBoxAbove)
  39891. {
  39892. valueBox->setBounds ((getWidth() - tbw) / 2, 0, tbw, tbh);
  39893. sliderRect.setBounds (0, tbh, getWidth(), getHeight() - tbh);
  39894. }
  39895. else if (textBoxPos == TextBoxBelow)
  39896. {
  39897. valueBox->setBounds ((getWidth() - tbw) / 2, getHeight() - tbh, tbw, tbh);
  39898. sliderRect.setBounds (0, 0, getWidth(), getHeight() - tbh);
  39899. }
  39900. }
  39901. const int indent = getLookAndFeel().getSliderThumbRadius (*this);
  39902. if (style == LinearBar)
  39903. {
  39904. const int barIndent = 1;
  39905. sliderRegionStart = barIndent;
  39906. sliderRegionSize = getWidth() - barIndent * 2;
  39907. sliderRect.setBounds (sliderRegionStart, barIndent,
  39908. sliderRegionSize, getHeight() - barIndent * 2);
  39909. }
  39910. else if (isHorizontal())
  39911. {
  39912. sliderRegionStart = sliderRect.getX() + indent;
  39913. sliderRegionSize = jmax (1, sliderRect.getWidth() - indent * 2);
  39914. sliderRect.setBounds (sliderRegionStart, sliderRect.getY(),
  39915. sliderRegionSize, sliderRect.getHeight());
  39916. }
  39917. else if (isVertical())
  39918. {
  39919. sliderRegionStart = sliderRect.getY() + indent;
  39920. sliderRegionSize = jmax (1, sliderRect.getHeight() - indent * 2);
  39921. sliderRect.setBounds (sliderRect.getX(), sliderRegionStart,
  39922. sliderRect.getWidth(), sliderRegionSize);
  39923. }
  39924. else
  39925. {
  39926. sliderRegionStart = 0;
  39927. sliderRegionSize = 100;
  39928. }
  39929. if (style == IncDecButtons)
  39930. {
  39931. Rectangle<int> buttonRect (sliderRect);
  39932. if (textBoxPos == TextBoxLeft || textBoxPos == TextBoxRight)
  39933. buttonRect.expand (-2, 0);
  39934. else
  39935. buttonRect.expand (0, -2);
  39936. incDecButtonsSideBySide = buttonRect.getWidth() > buttonRect.getHeight();
  39937. if (incDecButtonsSideBySide)
  39938. {
  39939. decButton->setBounds (buttonRect.getX(),
  39940. buttonRect.getY(),
  39941. buttonRect.getWidth() / 2,
  39942. buttonRect.getHeight());
  39943. decButton->setConnectedEdges (Button::ConnectedOnRight);
  39944. incButton->setBounds (buttonRect.getCentreX(),
  39945. buttonRect.getY(),
  39946. buttonRect.getWidth() / 2,
  39947. buttonRect.getHeight());
  39948. incButton->setConnectedEdges (Button::ConnectedOnLeft);
  39949. }
  39950. else
  39951. {
  39952. incButton->setBounds (buttonRect.getX(),
  39953. buttonRect.getY(),
  39954. buttonRect.getWidth(),
  39955. buttonRect.getHeight() / 2);
  39956. incButton->setConnectedEdges (Button::ConnectedOnBottom);
  39957. decButton->setBounds (buttonRect.getX(),
  39958. buttonRect.getCentreY(),
  39959. buttonRect.getWidth(),
  39960. buttonRect.getHeight() / 2);
  39961. decButton->setConnectedEdges (Button::ConnectedOnTop);
  39962. }
  39963. }
  39964. }
  39965. void Slider::focusOfChildComponentChanged (FocusChangeType)
  39966. {
  39967. repaint();
  39968. }
  39969. void Slider::mouseDown (const MouseEvent& e)
  39970. {
  39971. mouseWasHidden = false;
  39972. incDecDragged = false;
  39973. mouseXWhenLastDragged = e.x;
  39974. mouseYWhenLastDragged = e.y;
  39975. mouseDragStartX = e.getMouseDownX();
  39976. mouseDragStartY = e.getMouseDownY();
  39977. if (isEnabled())
  39978. {
  39979. if (e.mods.isPopupMenu() && menuEnabled)
  39980. {
  39981. menuShown = true;
  39982. PopupMenu m;
  39983. m.setLookAndFeel (&getLookAndFeel());
  39984. m.addItem (1, TRANS ("velocity-sensitive mode"), true, isVelocityBased);
  39985. m.addSeparator();
  39986. if (style == Rotary || style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  39987. {
  39988. PopupMenu rotaryMenu;
  39989. rotaryMenu.addItem (2, TRANS ("use circular dragging"), true, style == Rotary);
  39990. rotaryMenu.addItem (3, TRANS ("use left-right dragging"), true, style == RotaryHorizontalDrag);
  39991. rotaryMenu.addItem (4, TRANS ("use up-down dragging"), true, style == RotaryVerticalDrag);
  39992. m.addSubMenu (TRANS ("rotary mode"), rotaryMenu);
  39993. }
  39994. const int r = m.show();
  39995. if (r == 1)
  39996. {
  39997. setVelocityBasedMode (! isVelocityBased);
  39998. }
  39999. else if (r == 2)
  40000. {
  40001. setSliderStyle (Rotary);
  40002. }
  40003. else if (r == 3)
  40004. {
  40005. setSliderStyle (RotaryHorizontalDrag);
  40006. }
  40007. else if (r == 4)
  40008. {
  40009. setSliderStyle (RotaryVerticalDrag);
  40010. }
  40011. }
  40012. else if (maximum > minimum)
  40013. {
  40014. menuShown = false;
  40015. if (valueBox != 0)
  40016. valueBox->hideEditor (true);
  40017. sliderBeingDragged = 0;
  40018. if (style == TwoValueHorizontal
  40019. || style == TwoValueVertical
  40020. || style == ThreeValueHorizontal
  40021. || style == ThreeValueVertical)
  40022. {
  40023. const float mousePos = (float) (isVertical() ? e.y : e.x);
  40024. const float normalPosDistance = fabsf (getLinearSliderPos (currentValue.getValue()) - mousePos);
  40025. const float minPosDistance = fabsf (getLinearSliderPos (valueMin.getValue()) - 0.1f - mousePos);
  40026. const float maxPosDistance = fabsf (getLinearSliderPos (valueMax.getValue()) + 0.1f - mousePos);
  40027. if (style == TwoValueHorizontal || style == TwoValueVertical)
  40028. {
  40029. if (maxPosDistance <= minPosDistance)
  40030. sliderBeingDragged = 2;
  40031. else
  40032. sliderBeingDragged = 1;
  40033. }
  40034. else if (style == ThreeValueHorizontal || style == ThreeValueVertical)
  40035. {
  40036. if (normalPosDistance >= minPosDistance && maxPosDistance >= minPosDistance)
  40037. sliderBeingDragged = 1;
  40038. else if (normalPosDistance >= maxPosDistance)
  40039. sliderBeingDragged = 2;
  40040. }
  40041. }
  40042. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  40043. lastAngle = rotaryStart + (rotaryEnd - rotaryStart)
  40044. * valueToProportionOfLength (currentValue.getValue());
  40045. valueWhenLastDragged = ((sliderBeingDragged == 2) ? valueMax
  40046. : ((sliderBeingDragged == 1) ? valueMin
  40047. : currentValue)).getValue();
  40048. valueOnMouseDown = valueWhenLastDragged;
  40049. if (popupDisplayEnabled)
  40050. {
  40051. SliderPopupDisplayComponent* const popup = new SliderPopupDisplayComponent (this);
  40052. popupDisplay = popup;
  40053. if (parentForPopupDisplay != 0)
  40054. {
  40055. parentForPopupDisplay->addChildComponent (popup);
  40056. }
  40057. else
  40058. {
  40059. popup->addToDesktop (0);
  40060. }
  40061. popup->setVisible (true);
  40062. }
  40063. sendDragStart();
  40064. mouseDrag (e);
  40065. }
  40066. }
  40067. }
  40068. void Slider::mouseUp (const MouseEvent&)
  40069. {
  40070. if (isEnabled()
  40071. && (! menuShown)
  40072. && (maximum > minimum)
  40073. && (style != IncDecButtons || incDecDragged))
  40074. {
  40075. restoreMouseIfHidden();
  40076. if (sendChangeOnlyOnRelease && valueOnMouseDown != (double) currentValue.getValue())
  40077. triggerChangeMessage (false);
  40078. sendDragEnd();
  40079. popupDisplay = 0;
  40080. if (style == IncDecButtons)
  40081. {
  40082. incButton->setState (Button::buttonNormal);
  40083. decButton->setState (Button::buttonNormal);
  40084. }
  40085. }
  40086. }
  40087. void Slider::restoreMouseIfHidden()
  40088. {
  40089. if (mouseWasHidden)
  40090. {
  40091. mouseWasHidden = false;
  40092. Component* c = Component::getComponentUnderMouse();
  40093. if (c == 0)
  40094. c = this;
  40095. c->enableUnboundedMouseMovement (false);
  40096. const double pos = (sliderBeingDragged == 2) ? getMaxValue()
  40097. : ((sliderBeingDragged == 1) ? getMinValue()
  40098. : (double) currentValue.getValue());
  40099. if (style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  40100. {
  40101. int x, y, downX, downY;
  40102. Desktop::getMousePosition (x, y);
  40103. Desktop::getLastMouseDownPosition (downX, downY);
  40104. if (style == RotaryHorizontalDrag)
  40105. {
  40106. const double posDiff = valueToProportionOfLength (pos) - valueToProportionOfLength (valueOnMouseDown);
  40107. x = roundToInt (pixelsForFullDragExtent * posDiff + downX);
  40108. y = downY;
  40109. }
  40110. else
  40111. {
  40112. const double posDiff = valueToProportionOfLength (valueOnMouseDown) - valueToProportionOfLength (pos);
  40113. x = downX;
  40114. y = roundToInt (pixelsForFullDragExtent * posDiff + downY);
  40115. }
  40116. Desktop::setMousePosition (x, y);
  40117. }
  40118. else
  40119. {
  40120. const int pixelPos = (int) getLinearSliderPos (pos);
  40121. int x = isHorizontal() ? pixelPos : (getWidth() / 2);
  40122. int y = isVertical() ? pixelPos : (getHeight() / 2);
  40123. relativePositionToGlobal (x, y);
  40124. Desktop::setMousePosition (x, y);
  40125. }
  40126. }
  40127. }
  40128. void Slider::modifierKeysChanged (const ModifierKeys& modifiers)
  40129. {
  40130. if (isEnabled()
  40131. && style != IncDecButtons
  40132. && style != Rotary
  40133. && isVelocityBased == modifiers.isAnyModifierKeyDown())
  40134. {
  40135. restoreMouseIfHidden();
  40136. }
  40137. }
  40138. static double smallestAngleBetween (double a1, double a2)
  40139. {
  40140. return jmin (fabs (a1 - a2),
  40141. fabs (a1 + double_Pi * 2.0 - a2),
  40142. fabs (a2 + double_Pi * 2.0 - a1));
  40143. }
  40144. void Slider::mouseDrag (const MouseEvent& e)
  40145. {
  40146. if (isEnabled()
  40147. && (! menuShown)
  40148. && (maximum > minimum))
  40149. {
  40150. if (style == Rotary)
  40151. {
  40152. int dx = e.x - sliderRect.getCentreX();
  40153. int dy = e.y - sliderRect.getCentreY();
  40154. if (dx * dx + dy * dy > 25)
  40155. {
  40156. double angle = atan2 ((double) dx, (double) -dy);
  40157. while (angle < 0.0)
  40158. angle += double_Pi * 2.0;
  40159. if (rotaryStop && ! e.mouseWasClicked())
  40160. {
  40161. if (fabs (angle - lastAngle) > double_Pi)
  40162. {
  40163. if (angle >= lastAngle)
  40164. angle -= double_Pi * 2.0;
  40165. else
  40166. angle += double_Pi * 2.0;
  40167. }
  40168. if (angle >= lastAngle)
  40169. angle = jmin (angle, (double) jmax (rotaryStart, rotaryEnd));
  40170. else
  40171. angle = jmax (angle, (double) jmin (rotaryStart, rotaryEnd));
  40172. }
  40173. else
  40174. {
  40175. while (angle < rotaryStart)
  40176. angle += double_Pi * 2.0;
  40177. if (angle > rotaryEnd)
  40178. {
  40179. if (smallestAngleBetween (angle, rotaryStart) <= smallestAngleBetween (angle, rotaryEnd))
  40180. angle = rotaryStart;
  40181. else
  40182. angle = rotaryEnd;
  40183. }
  40184. }
  40185. const double proportion = (angle - rotaryStart) / (rotaryEnd - rotaryStart);
  40186. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, proportion));
  40187. lastAngle = angle;
  40188. }
  40189. }
  40190. else
  40191. {
  40192. if (style == LinearBar && e.mouseWasClicked()
  40193. && valueBox != 0 && valueBox->isEditable())
  40194. return;
  40195. if (style == IncDecButtons && ! incDecDragged)
  40196. {
  40197. if (e.getDistanceFromDragStart() < 10 || e.mouseWasClicked())
  40198. return;
  40199. incDecDragged = true;
  40200. mouseDragStartX = e.x;
  40201. mouseDragStartY = e.y;
  40202. }
  40203. if ((isVelocityBased == (userKeyOverridesVelocity ? e.mods.testFlags (ModifierKeys::ctrlModifier | ModifierKeys::commandModifier | ModifierKeys::altModifier)
  40204. : false))
  40205. || ((maximum - minimum) / sliderRegionSize < interval))
  40206. {
  40207. const int mousePos = (isHorizontal() || style == RotaryHorizontalDrag) ? e.x : e.y;
  40208. double scaledMousePos = (mousePos - sliderRegionStart) / (double) sliderRegionSize;
  40209. if (style == RotaryHorizontalDrag
  40210. || style == RotaryVerticalDrag
  40211. || style == IncDecButtons
  40212. || ((style == LinearHorizontal || style == LinearVertical || style == LinearBar)
  40213. && ! snapsToMousePos))
  40214. {
  40215. const int mouseDiff = (style == RotaryHorizontalDrag
  40216. || style == LinearHorizontal
  40217. || style == LinearBar
  40218. || (style == IncDecButtons && incDecDragDirectionIsHorizontal()))
  40219. ? e.x - mouseDragStartX
  40220. : mouseDragStartY - e.y;
  40221. double newPos = valueToProportionOfLength (valueOnMouseDown)
  40222. + mouseDiff * (1.0 / pixelsForFullDragExtent);
  40223. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, newPos));
  40224. if (style == IncDecButtons)
  40225. {
  40226. incButton->setState (mouseDiff < 0 ? Button::buttonNormal : Button::buttonDown);
  40227. decButton->setState (mouseDiff > 0 ? Button::buttonNormal : Button::buttonDown);
  40228. }
  40229. }
  40230. else
  40231. {
  40232. if (isVertical())
  40233. scaledMousePos = 1.0 - scaledMousePos;
  40234. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, scaledMousePos));
  40235. }
  40236. }
  40237. else
  40238. {
  40239. const int mouseDiff = (isHorizontal() || style == RotaryHorizontalDrag
  40240. || (style == IncDecButtons && incDecDragDirectionIsHorizontal()))
  40241. ? e.x - mouseXWhenLastDragged
  40242. : e.y - mouseYWhenLastDragged;
  40243. const double maxSpeed = jmax (200, sliderRegionSize);
  40244. double speed = jlimit (0.0, maxSpeed, (double) abs (mouseDiff));
  40245. if (speed != 0)
  40246. {
  40247. speed = 0.2 * velocityModeSensitivity
  40248. * (1.0 + sin (double_Pi * (1.5 + jmin (0.5, velocityModeOffset
  40249. + jmax (0.0, (double) (speed - velocityModeThreshold))
  40250. / maxSpeed))));
  40251. if (mouseDiff < 0)
  40252. speed = -speed;
  40253. if (isVertical() || style == RotaryVerticalDrag
  40254. || (style == IncDecButtons && ! incDecDragDirectionIsHorizontal()))
  40255. speed = -speed;
  40256. const double currentPos = valueToProportionOfLength (valueWhenLastDragged);
  40257. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, currentPos + speed));
  40258. e.originalComponent->enableUnboundedMouseMovement (true, false);
  40259. mouseWasHidden = true;
  40260. }
  40261. }
  40262. }
  40263. valueWhenLastDragged = jlimit (minimum, maximum, valueWhenLastDragged);
  40264. if (sliderBeingDragged == 0)
  40265. {
  40266. setValue (snapValue (valueWhenLastDragged, true),
  40267. ! sendChangeOnlyOnRelease, true);
  40268. }
  40269. else if (sliderBeingDragged == 1)
  40270. {
  40271. setMinValue (snapValue (valueWhenLastDragged, true),
  40272. ! sendChangeOnlyOnRelease, false, true);
  40273. if (e.mods.isShiftDown())
  40274. setMaxValue (getMinValue() + minMaxDiff, false, false, true);
  40275. else
  40276. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  40277. }
  40278. else
  40279. {
  40280. jassert (sliderBeingDragged == 2);
  40281. setMaxValue (snapValue (valueWhenLastDragged, true),
  40282. ! sendChangeOnlyOnRelease, false, true);
  40283. if (e.mods.isShiftDown())
  40284. setMinValue (getMaxValue() - minMaxDiff, false, false, true);
  40285. else
  40286. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  40287. }
  40288. mouseXWhenLastDragged = e.x;
  40289. mouseYWhenLastDragged = e.y;
  40290. }
  40291. }
  40292. void Slider::mouseDoubleClick (const MouseEvent&)
  40293. {
  40294. if (doubleClickToValue
  40295. && isEnabled()
  40296. && style != IncDecButtons
  40297. && minimum <= doubleClickReturnValue
  40298. && maximum >= doubleClickReturnValue)
  40299. {
  40300. sendDragStart();
  40301. setValue (doubleClickReturnValue, true, true);
  40302. sendDragEnd();
  40303. }
  40304. }
  40305. void Slider::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  40306. {
  40307. if (scrollWheelEnabled && isEnabled()
  40308. && style != TwoValueHorizontal
  40309. && style != TwoValueVertical)
  40310. {
  40311. if (maximum > minimum && ! isMouseButtonDownAnywhere())
  40312. {
  40313. if (valueBox != 0)
  40314. valueBox->hideEditor (false);
  40315. const double value = (double) currentValue.getValue();
  40316. const double proportionDelta = (wheelIncrementX != 0 ? -wheelIncrementX : wheelIncrementY) * 0.15f;
  40317. const double currentPos = valueToProportionOfLength (value);
  40318. const double newValue = proportionOfLengthToValue (jlimit (0.0, 1.0, currentPos + proportionDelta));
  40319. double delta = (newValue != value)
  40320. ? jmax (fabs (newValue - value), interval) : 0;
  40321. if (value > newValue)
  40322. delta = -delta;
  40323. sendDragStart();
  40324. setValue (snapValue (value + delta, false), true, true);
  40325. sendDragEnd();
  40326. }
  40327. }
  40328. else
  40329. {
  40330. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  40331. }
  40332. }
  40333. void SliderListener::sliderDragStarted (Slider*)
  40334. {
  40335. }
  40336. void SliderListener::sliderDragEnded (Slider*)
  40337. {
  40338. }
  40339. END_JUCE_NAMESPACE
  40340. /*** End of inlined file: juce_Slider.cpp ***/
  40341. /*** Start of inlined file: juce_TableHeaderComponent.cpp ***/
  40342. BEGIN_JUCE_NAMESPACE
  40343. class DragOverlayComp : public Component
  40344. {
  40345. public:
  40346. DragOverlayComp (Image* const image_)
  40347. : image (image_)
  40348. {
  40349. image->multiplyAllAlphas (0.8f);
  40350. setAlwaysOnTop (true);
  40351. }
  40352. ~DragOverlayComp()
  40353. {
  40354. }
  40355. void paint (Graphics& g)
  40356. {
  40357. g.drawImageAt (image, 0, 0);
  40358. }
  40359. private:
  40360. ScopedPointer <Image> image;
  40361. DragOverlayComp (const DragOverlayComp&);
  40362. const DragOverlayComp& operator= (const DragOverlayComp&);
  40363. };
  40364. TableHeaderComponent::TableHeaderComponent()
  40365. : columnsChanged (false),
  40366. columnsResized (false),
  40367. sortChanged (false),
  40368. menuActive (true),
  40369. stretchToFit (false),
  40370. columnIdBeingResized (0),
  40371. columnIdBeingDragged (0),
  40372. columnIdUnderMouse (0),
  40373. lastDeliberateWidth (0)
  40374. {
  40375. }
  40376. TableHeaderComponent::~TableHeaderComponent()
  40377. {
  40378. dragOverlayComp = 0;
  40379. }
  40380. void TableHeaderComponent::setPopupMenuActive (const bool hasMenu)
  40381. {
  40382. menuActive = hasMenu;
  40383. }
  40384. bool TableHeaderComponent::isPopupMenuActive() const { return menuActive; }
  40385. int TableHeaderComponent::getNumColumns (const bool onlyCountVisibleColumns) const
  40386. {
  40387. if (onlyCountVisibleColumns)
  40388. {
  40389. int num = 0;
  40390. for (int i = columns.size(); --i >= 0;)
  40391. if (columns.getUnchecked(i)->isVisible())
  40392. ++num;
  40393. return num;
  40394. }
  40395. else
  40396. {
  40397. return columns.size();
  40398. }
  40399. }
  40400. const String TableHeaderComponent::getColumnName (const int columnId) const
  40401. {
  40402. const ColumnInfo* const ci = getInfoForId (columnId);
  40403. return ci != 0 ? ci->name : String::empty;
  40404. }
  40405. void TableHeaderComponent::setColumnName (const int columnId, const String& newName)
  40406. {
  40407. ColumnInfo* const ci = getInfoForId (columnId);
  40408. if (ci != 0 && ci->name != newName)
  40409. {
  40410. ci->name = newName;
  40411. sendColumnsChanged();
  40412. }
  40413. }
  40414. void TableHeaderComponent::addColumn (const String& columnName,
  40415. const int columnId,
  40416. const int width,
  40417. const int minimumWidth,
  40418. const int maximumWidth,
  40419. const int propertyFlags,
  40420. const int insertIndex)
  40421. {
  40422. // can't have a duplicate or null ID!
  40423. jassert (columnId != 0 && getIndexOfColumnId (columnId, false) < 0);
  40424. jassert (width > 0);
  40425. ColumnInfo* const ci = new ColumnInfo();
  40426. ci->name = columnName;
  40427. ci->id = columnId;
  40428. ci->width = width;
  40429. ci->lastDeliberateWidth = width;
  40430. ci->minimumWidth = minimumWidth;
  40431. ci->maximumWidth = maximumWidth;
  40432. if (ci->maximumWidth < 0)
  40433. ci->maximumWidth = std::numeric_limits<int>::max();
  40434. jassert (ci->maximumWidth >= ci->minimumWidth);
  40435. ci->propertyFlags = propertyFlags;
  40436. columns.insert (insertIndex, ci);
  40437. sendColumnsChanged();
  40438. }
  40439. void TableHeaderComponent::removeColumn (const int columnIdToRemove)
  40440. {
  40441. const int index = getIndexOfColumnId (columnIdToRemove, false);
  40442. if (index >= 0)
  40443. {
  40444. columns.remove (index);
  40445. sortChanged = true;
  40446. sendColumnsChanged();
  40447. }
  40448. }
  40449. void TableHeaderComponent::removeAllColumns()
  40450. {
  40451. if (columns.size() > 0)
  40452. {
  40453. columns.clear();
  40454. sendColumnsChanged();
  40455. }
  40456. }
  40457. void TableHeaderComponent::moveColumn (const int columnId, int newIndex)
  40458. {
  40459. const int currentIndex = getIndexOfColumnId (columnId, false);
  40460. newIndex = visibleIndexToTotalIndex (newIndex);
  40461. if (columns [currentIndex] != 0 && currentIndex != newIndex)
  40462. {
  40463. columns.move (currentIndex, newIndex);
  40464. sendColumnsChanged();
  40465. }
  40466. }
  40467. int TableHeaderComponent::getColumnWidth (const int columnId) const
  40468. {
  40469. const ColumnInfo* const ci = getInfoForId (columnId);
  40470. return ci != 0 ? ci->width : 0;
  40471. }
  40472. void TableHeaderComponent::setColumnWidth (const int columnId, const int newWidth)
  40473. {
  40474. ColumnInfo* const ci = getInfoForId (columnId);
  40475. if (ci != 0 && ci->width != newWidth)
  40476. {
  40477. const int numColumns = getNumColumns (true);
  40478. ci->lastDeliberateWidth = ci->width
  40479. = jlimit (ci->minimumWidth, ci->maximumWidth, newWidth);
  40480. if (stretchToFit)
  40481. {
  40482. const int index = getIndexOfColumnId (columnId, true) + 1;
  40483. if (((unsigned int) index) < (unsigned int) numColumns)
  40484. {
  40485. const int x = getColumnPosition (index).getX();
  40486. if (lastDeliberateWidth == 0)
  40487. lastDeliberateWidth = getTotalWidth();
  40488. resizeColumnsToFit (visibleIndexToTotalIndex (index), lastDeliberateWidth - x);
  40489. }
  40490. }
  40491. repaint();
  40492. columnsResized = true;
  40493. triggerAsyncUpdate();
  40494. }
  40495. }
  40496. int TableHeaderComponent::getIndexOfColumnId (const int columnId, const bool onlyCountVisibleColumns) const
  40497. {
  40498. int n = 0;
  40499. for (int i = 0; i < columns.size(); ++i)
  40500. {
  40501. if ((! onlyCountVisibleColumns) || columns.getUnchecked(i)->isVisible())
  40502. {
  40503. if (columns.getUnchecked(i)->id == columnId)
  40504. return n;
  40505. ++n;
  40506. }
  40507. }
  40508. return -1;
  40509. }
  40510. int TableHeaderComponent::getColumnIdOfIndex (int index, const bool onlyCountVisibleColumns) const
  40511. {
  40512. if (onlyCountVisibleColumns)
  40513. index = visibleIndexToTotalIndex (index);
  40514. const ColumnInfo* const ci = columns [index];
  40515. return (ci != 0) ? ci->id : 0;
  40516. }
  40517. const Rectangle<int> TableHeaderComponent::getColumnPosition (const int index) const
  40518. {
  40519. int x = 0, width = 0, n = 0;
  40520. for (int i = 0; i < columns.size(); ++i)
  40521. {
  40522. x += width;
  40523. if (columns.getUnchecked(i)->isVisible())
  40524. {
  40525. width = columns.getUnchecked(i)->width;
  40526. if (n++ == index)
  40527. break;
  40528. }
  40529. else
  40530. {
  40531. width = 0;
  40532. }
  40533. }
  40534. return Rectangle<int> (x, 0, width, getHeight());
  40535. }
  40536. int TableHeaderComponent::getColumnIdAtX (const int xToFind) const
  40537. {
  40538. if (xToFind >= 0)
  40539. {
  40540. int x = 0;
  40541. for (int i = 0; i < columns.size(); ++i)
  40542. {
  40543. const ColumnInfo* const ci = columns.getUnchecked(i);
  40544. if (ci->isVisible())
  40545. {
  40546. x += ci->width;
  40547. if (xToFind < x)
  40548. return ci->id;
  40549. }
  40550. }
  40551. }
  40552. return 0;
  40553. }
  40554. int TableHeaderComponent::getTotalWidth() const
  40555. {
  40556. int w = 0;
  40557. for (int i = columns.size(); --i >= 0;)
  40558. if (columns.getUnchecked(i)->isVisible())
  40559. w += columns.getUnchecked(i)->width;
  40560. return w;
  40561. }
  40562. void TableHeaderComponent::setStretchToFitActive (const bool shouldStretchToFit)
  40563. {
  40564. stretchToFit = shouldStretchToFit;
  40565. lastDeliberateWidth = getTotalWidth();
  40566. resized();
  40567. }
  40568. bool TableHeaderComponent::isStretchToFitActive() const
  40569. {
  40570. return stretchToFit;
  40571. }
  40572. void TableHeaderComponent::resizeAllColumnsToFit (int targetTotalWidth)
  40573. {
  40574. if (stretchToFit && getWidth() > 0
  40575. && columnIdBeingResized == 0 && columnIdBeingDragged == 0)
  40576. {
  40577. lastDeliberateWidth = targetTotalWidth;
  40578. resizeColumnsToFit (0, targetTotalWidth);
  40579. }
  40580. }
  40581. void TableHeaderComponent::resizeColumnsToFit (int firstColumnIndex, int targetTotalWidth)
  40582. {
  40583. targetTotalWidth = jmax (targetTotalWidth, 0);
  40584. StretchableObjectResizer sor;
  40585. int i;
  40586. for (i = firstColumnIndex; i < columns.size(); ++i)
  40587. {
  40588. ColumnInfo* const ci = columns.getUnchecked(i);
  40589. if (ci->isVisible())
  40590. sor.addItem (ci->lastDeliberateWidth, ci->minimumWidth, ci->maximumWidth);
  40591. }
  40592. sor.resizeToFit (targetTotalWidth);
  40593. int visIndex = 0;
  40594. for (i = firstColumnIndex; i < columns.size(); ++i)
  40595. {
  40596. ColumnInfo* const ci = columns.getUnchecked(i);
  40597. if (ci->isVisible())
  40598. {
  40599. const int newWidth = jlimit (ci->minimumWidth, ci->maximumWidth,
  40600. (int) floor (sor.getItemSize (visIndex++)));
  40601. if (newWidth != ci->width)
  40602. {
  40603. ci->width = newWidth;
  40604. repaint();
  40605. columnsResized = true;
  40606. triggerAsyncUpdate();
  40607. }
  40608. }
  40609. }
  40610. }
  40611. void TableHeaderComponent::setColumnVisible (const int columnId, const bool shouldBeVisible)
  40612. {
  40613. ColumnInfo* const ci = getInfoForId (columnId);
  40614. if (ci != 0 && shouldBeVisible != ci->isVisible())
  40615. {
  40616. if (shouldBeVisible)
  40617. ci->propertyFlags |= visible;
  40618. else
  40619. ci->propertyFlags &= ~visible;
  40620. sendColumnsChanged();
  40621. resized();
  40622. }
  40623. }
  40624. bool TableHeaderComponent::isColumnVisible (const int columnId) const
  40625. {
  40626. const ColumnInfo* const ci = getInfoForId (columnId);
  40627. return ci != 0 && ci->isVisible();
  40628. }
  40629. void TableHeaderComponent::setSortColumnId (const int columnId, const bool sortForwards)
  40630. {
  40631. if (getSortColumnId() != columnId || isSortedForwards() != sortForwards)
  40632. {
  40633. for (int i = columns.size(); --i >= 0;)
  40634. columns.getUnchecked(i)->propertyFlags &= ~(sortedForwards | sortedBackwards);
  40635. ColumnInfo* const ci = getInfoForId (columnId);
  40636. if (ci != 0)
  40637. ci->propertyFlags |= (sortForwards ? sortedForwards : sortedBackwards);
  40638. reSortTable();
  40639. }
  40640. }
  40641. int TableHeaderComponent::getSortColumnId() const
  40642. {
  40643. for (int i = columns.size(); --i >= 0;)
  40644. if ((columns.getUnchecked(i)->propertyFlags & (sortedForwards | sortedBackwards)) != 0)
  40645. return columns.getUnchecked(i)->id;
  40646. return 0;
  40647. }
  40648. bool TableHeaderComponent::isSortedForwards() const
  40649. {
  40650. for (int i = columns.size(); --i >= 0;)
  40651. if ((columns.getUnchecked(i)->propertyFlags & (sortedForwards | sortedBackwards)) != 0)
  40652. return (columns.getUnchecked(i)->propertyFlags & sortedForwards) != 0;
  40653. return true;
  40654. }
  40655. void TableHeaderComponent::reSortTable()
  40656. {
  40657. sortChanged = true;
  40658. repaint();
  40659. triggerAsyncUpdate();
  40660. }
  40661. const String TableHeaderComponent::toString() const
  40662. {
  40663. String s;
  40664. XmlElement doc ("TABLELAYOUT");
  40665. doc.setAttribute ("sortedCol", getSortColumnId());
  40666. doc.setAttribute ("sortForwards", isSortedForwards());
  40667. for (int i = 0; i < columns.size(); ++i)
  40668. {
  40669. const ColumnInfo* const ci = columns.getUnchecked (i);
  40670. XmlElement* const e = doc.createNewChildElement ("COLUMN");
  40671. e->setAttribute ("id", ci->id);
  40672. e->setAttribute ("visible", ci->isVisible());
  40673. e->setAttribute ("width", ci->width);
  40674. }
  40675. return doc.createDocument (String::empty, true, false);
  40676. }
  40677. void TableHeaderComponent::restoreFromString (const String& storedVersion)
  40678. {
  40679. XmlDocument doc (storedVersion);
  40680. ScopedPointer <XmlElement> storedXml (doc.getDocumentElement());
  40681. int index = 0;
  40682. if (storedXml != 0 && storedXml->hasTagName ("TABLELAYOUT"))
  40683. {
  40684. forEachXmlChildElement (*storedXml, col)
  40685. {
  40686. const int tabId = col->getIntAttribute ("id");
  40687. ColumnInfo* const ci = getInfoForId (tabId);
  40688. if (ci != 0)
  40689. {
  40690. columns.move (columns.indexOf (ci), index);
  40691. ci->width = col->getIntAttribute ("width");
  40692. setColumnVisible (tabId, col->getBoolAttribute ("visible"));
  40693. }
  40694. ++index;
  40695. }
  40696. columnsResized = true;
  40697. sendColumnsChanged();
  40698. setSortColumnId (storedXml->getIntAttribute ("sortedCol"),
  40699. storedXml->getBoolAttribute ("sortForwards", true));
  40700. }
  40701. }
  40702. void TableHeaderComponent::addListener (TableHeaderListener* const newListener)
  40703. {
  40704. listeners.addIfNotAlreadyThere (newListener);
  40705. }
  40706. void TableHeaderComponent::removeListener (TableHeaderListener* const listenerToRemove)
  40707. {
  40708. listeners.removeValue (listenerToRemove);
  40709. }
  40710. void TableHeaderComponent::columnClicked (int columnId, const ModifierKeys& mods)
  40711. {
  40712. const ColumnInfo* const ci = getInfoForId (columnId);
  40713. if (ci != 0 && (ci->propertyFlags & sortable) != 0 && ! mods.isPopupMenu())
  40714. setSortColumnId (columnId, (ci->propertyFlags & sortedForwards) == 0);
  40715. }
  40716. void TableHeaderComponent::addMenuItems (PopupMenu& menu, const int /*columnIdClicked*/)
  40717. {
  40718. for (int i = 0; i < columns.size(); ++i)
  40719. {
  40720. const ColumnInfo* const ci = columns.getUnchecked(i);
  40721. if ((ci->propertyFlags & appearsOnColumnMenu) != 0)
  40722. menu.addItem (ci->id, ci->name,
  40723. (ci->propertyFlags & (sortedForwards | sortedBackwards)) == 0,
  40724. isColumnVisible (ci->id));
  40725. }
  40726. }
  40727. void TableHeaderComponent::reactToMenuItem (const int menuReturnId, const int /*columnIdClicked*/)
  40728. {
  40729. if (getIndexOfColumnId (menuReturnId, false) >= 0)
  40730. setColumnVisible (menuReturnId, ! isColumnVisible (menuReturnId));
  40731. }
  40732. void TableHeaderComponent::paint (Graphics& g)
  40733. {
  40734. LookAndFeel& lf = getLookAndFeel();
  40735. lf.drawTableHeaderBackground (g, *this);
  40736. const Rectangle<int> clip (g.getClipBounds());
  40737. int x = 0;
  40738. for (int i = 0; i < columns.size(); ++i)
  40739. {
  40740. const ColumnInfo* const ci = columns.getUnchecked(i);
  40741. if (ci->isVisible())
  40742. {
  40743. if (x + ci->width > clip.getX()
  40744. && (ci->id != columnIdBeingDragged
  40745. || dragOverlayComp == 0
  40746. || ! dragOverlayComp->isVisible()))
  40747. {
  40748. g.saveState();
  40749. g.setOrigin (x, 0);
  40750. g.reduceClipRegion (0, 0, ci->width, getHeight());
  40751. lf.drawTableHeaderColumn (g, ci->name, ci->id, ci->width, getHeight(),
  40752. ci->id == columnIdUnderMouse,
  40753. ci->id == columnIdUnderMouse && isMouseButtonDown(),
  40754. ci->propertyFlags);
  40755. g.restoreState();
  40756. }
  40757. x += ci->width;
  40758. if (x >= clip.getRight())
  40759. break;
  40760. }
  40761. }
  40762. }
  40763. void TableHeaderComponent::resized()
  40764. {
  40765. }
  40766. void TableHeaderComponent::mouseMove (const MouseEvent& e)
  40767. {
  40768. updateColumnUnderMouse (e.x, e.y);
  40769. }
  40770. void TableHeaderComponent::mouseEnter (const MouseEvent& e)
  40771. {
  40772. updateColumnUnderMouse (e.x, e.y);
  40773. }
  40774. void TableHeaderComponent::mouseExit (const MouseEvent& e)
  40775. {
  40776. updateColumnUnderMouse (e.x, e.y);
  40777. }
  40778. void TableHeaderComponent::mouseDown (const MouseEvent& e)
  40779. {
  40780. repaint();
  40781. columnIdBeingResized = 0;
  40782. columnIdBeingDragged = 0;
  40783. if (columnIdUnderMouse != 0)
  40784. {
  40785. draggingColumnOffset = e.x - getColumnPosition (getIndexOfColumnId (columnIdUnderMouse, true)).getX();
  40786. if (e.mods.isPopupMenu())
  40787. columnClicked (columnIdUnderMouse, e.mods);
  40788. }
  40789. if (menuActive && e.mods.isPopupMenu())
  40790. showColumnChooserMenu (columnIdUnderMouse);
  40791. }
  40792. void TableHeaderComponent::mouseDrag (const MouseEvent& e)
  40793. {
  40794. if (columnIdBeingResized == 0
  40795. && columnIdBeingDragged == 0
  40796. && ! (e.mouseWasClicked() || e.mods.isPopupMenu()))
  40797. {
  40798. dragOverlayComp = 0;
  40799. columnIdBeingResized = getResizeDraggerAt (e.getMouseDownX());
  40800. if (columnIdBeingResized != 0)
  40801. {
  40802. const ColumnInfo* const ci = getInfoForId (columnIdBeingResized);
  40803. initialColumnWidth = ci->width;
  40804. }
  40805. else
  40806. {
  40807. beginDrag (e);
  40808. }
  40809. }
  40810. if (columnIdBeingResized != 0)
  40811. {
  40812. const ColumnInfo* const ci = getInfoForId (columnIdBeingResized);
  40813. if (ci != 0)
  40814. {
  40815. int w = jlimit (ci->minimumWidth, ci->maximumWidth,
  40816. initialColumnWidth + e.getDistanceFromDragStartX());
  40817. if (stretchToFit)
  40818. {
  40819. // prevent us dragging a column too far right if we're in stretch-to-fit mode
  40820. int minWidthOnRight = 0;
  40821. for (int i = getIndexOfColumnId (columnIdBeingResized, false) + 1; i < columns.size(); ++i)
  40822. if (columns.getUnchecked (i)->isVisible())
  40823. minWidthOnRight += columns.getUnchecked (i)->minimumWidth;
  40824. const Rectangle<int> currentPos (getColumnPosition (getIndexOfColumnId (columnIdBeingResized, true)));
  40825. w = jmax (ci->minimumWidth, jmin (w, getWidth() - minWidthOnRight - currentPos.getX()));
  40826. }
  40827. setColumnWidth (columnIdBeingResized, w);
  40828. }
  40829. }
  40830. else if (columnIdBeingDragged != 0)
  40831. {
  40832. if (e.y >= -50 && e.y < getHeight() + 50)
  40833. {
  40834. if (dragOverlayComp != 0)
  40835. {
  40836. dragOverlayComp->setVisible (true);
  40837. dragOverlayComp->setBounds (jlimit (0,
  40838. jmax (0, getTotalWidth() - dragOverlayComp->getWidth()),
  40839. e.x - draggingColumnOffset),
  40840. 0,
  40841. dragOverlayComp->getWidth(),
  40842. getHeight());
  40843. for (int i = columns.size(); --i >= 0;)
  40844. {
  40845. const int currentIndex = getIndexOfColumnId (columnIdBeingDragged, true);
  40846. int newIndex = currentIndex;
  40847. if (newIndex > 0)
  40848. {
  40849. // if the previous column isn't draggable, we can't move our column
  40850. // past it, because that'd change the undraggable column's position..
  40851. const ColumnInfo* const previous = columns.getUnchecked (newIndex - 1);
  40852. if ((previous->propertyFlags & draggable) != 0)
  40853. {
  40854. const int leftOfPrevious = getColumnPosition (newIndex - 1).getX();
  40855. const int rightOfCurrent = getColumnPosition (newIndex).getRight();
  40856. if (abs (dragOverlayComp->getX() - leftOfPrevious)
  40857. < abs (dragOverlayComp->getRight() - rightOfCurrent))
  40858. {
  40859. --newIndex;
  40860. }
  40861. }
  40862. }
  40863. if (newIndex < columns.size() - 1)
  40864. {
  40865. // if the next column isn't draggable, we can't move our column
  40866. // past it, because that'd change the undraggable column's position..
  40867. const ColumnInfo* const nextCol = columns.getUnchecked (newIndex + 1);
  40868. if ((nextCol->propertyFlags & draggable) != 0)
  40869. {
  40870. const int leftOfCurrent = getColumnPosition (newIndex).getX();
  40871. const int rightOfNext = getColumnPosition (newIndex + 1).getRight();
  40872. if (abs (dragOverlayComp->getX() - leftOfCurrent)
  40873. > abs (dragOverlayComp->getRight() - rightOfNext))
  40874. {
  40875. ++newIndex;
  40876. }
  40877. }
  40878. }
  40879. if (newIndex != currentIndex)
  40880. moveColumn (columnIdBeingDragged, newIndex);
  40881. else
  40882. break;
  40883. }
  40884. }
  40885. }
  40886. else
  40887. {
  40888. endDrag (draggingColumnOriginalIndex);
  40889. }
  40890. }
  40891. }
  40892. void TableHeaderComponent::beginDrag (const MouseEvent& e)
  40893. {
  40894. if (columnIdBeingDragged == 0)
  40895. {
  40896. columnIdBeingDragged = getColumnIdAtX (e.getMouseDownX());
  40897. const ColumnInfo* const ci = getInfoForId (columnIdBeingDragged);
  40898. if (ci == 0 || (ci->propertyFlags & draggable) == 0)
  40899. {
  40900. columnIdBeingDragged = 0;
  40901. }
  40902. else
  40903. {
  40904. draggingColumnOriginalIndex = getIndexOfColumnId (columnIdBeingDragged, true);
  40905. const Rectangle<int> columnRect (getColumnPosition (draggingColumnOriginalIndex));
  40906. const int temp = columnIdBeingDragged;
  40907. columnIdBeingDragged = 0;
  40908. addAndMakeVisible (dragOverlayComp = new DragOverlayComp (createComponentSnapshot (columnRect, false)));
  40909. columnIdBeingDragged = temp;
  40910. dragOverlayComp->setBounds (columnRect);
  40911. for (int i = listeners.size(); --i >= 0;)
  40912. {
  40913. listeners.getUnchecked(i)->tableColumnDraggingChanged (this, columnIdBeingDragged);
  40914. i = jmin (i, listeners.size() - 1);
  40915. }
  40916. }
  40917. }
  40918. }
  40919. void TableHeaderComponent::endDrag (const int finalIndex)
  40920. {
  40921. if (columnIdBeingDragged != 0)
  40922. {
  40923. moveColumn (columnIdBeingDragged, finalIndex);
  40924. columnIdBeingDragged = 0;
  40925. repaint();
  40926. for (int i = listeners.size(); --i >= 0;)
  40927. {
  40928. listeners.getUnchecked(i)->tableColumnDraggingChanged (this, 0);
  40929. i = jmin (i, listeners.size() - 1);
  40930. }
  40931. }
  40932. }
  40933. void TableHeaderComponent::mouseUp (const MouseEvent& e)
  40934. {
  40935. mouseDrag (e);
  40936. for (int i = columns.size(); --i >= 0;)
  40937. if (columns.getUnchecked (i)->isVisible())
  40938. columns.getUnchecked (i)->lastDeliberateWidth = columns.getUnchecked (i)->width;
  40939. columnIdBeingResized = 0;
  40940. repaint();
  40941. endDrag (getIndexOfColumnId (columnIdBeingDragged, true));
  40942. updateColumnUnderMouse (e.x, e.y);
  40943. if (columnIdUnderMouse != 0 && e.mouseWasClicked() && ! e.mods.isPopupMenu())
  40944. columnClicked (columnIdUnderMouse, e.mods);
  40945. dragOverlayComp = 0;
  40946. }
  40947. const MouseCursor TableHeaderComponent::getMouseCursor()
  40948. {
  40949. int x, y;
  40950. getMouseXYRelative (x, y);
  40951. if (columnIdBeingResized != 0 || (getResizeDraggerAt (x) != 0 && ! isMouseButtonDown()))
  40952. return MouseCursor (MouseCursor::LeftRightResizeCursor);
  40953. return Component::getMouseCursor();
  40954. }
  40955. bool TableHeaderComponent::ColumnInfo::isVisible() const
  40956. {
  40957. return (propertyFlags & TableHeaderComponent::visible) != 0;
  40958. }
  40959. TableHeaderComponent::ColumnInfo* TableHeaderComponent::getInfoForId (const int id) const
  40960. {
  40961. for (int i = columns.size(); --i >= 0;)
  40962. if (columns.getUnchecked(i)->id == id)
  40963. return columns.getUnchecked(i);
  40964. return 0;
  40965. }
  40966. int TableHeaderComponent::visibleIndexToTotalIndex (const int visibleIndex) const
  40967. {
  40968. int n = 0;
  40969. for (int i = 0; i < columns.size(); ++i)
  40970. {
  40971. if (columns.getUnchecked(i)->isVisible())
  40972. {
  40973. if (n == visibleIndex)
  40974. return i;
  40975. ++n;
  40976. }
  40977. }
  40978. return -1;
  40979. }
  40980. void TableHeaderComponent::sendColumnsChanged()
  40981. {
  40982. if (stretchToFit && lastDeliberateWidth > 0)
  40983. resizeAllColumnsToFit (lastDeliberateWidth);
  40984. repaint();
  40985. columnsChanged = true;
  40986. triggerAsyncUpdate();
  40987. }
  40988. void TableHeaderComponent::handleAsyncUpdate()
  40989. {
  40990. const bool changed = columnsChanged || sortChanged;
  40991. const bool sized = columnsResized || changed;
  40992. const bool sorted = sortChanged;
  40993. columnsChanged = false;
  40994. columnsResized = false;
  40995. sortChanged = false;
  40996. if (sorted)
  40997. {
  40998. for (int i = listeners.size(); --i >= 0;)
  40999. {
  41000. listeners.getUnchecked(i)->tableSortOrderChanged (this);
  41001. i = jmin (i, listeners.size() - 1);
  41002. }
  41003. }
  41004. if (changed)
  41005. {
  41006. for (int i = listeners.size(); --i >= 0;)
  41007. {
  41008. listeners.getUnchecked(i)->tableColumnsChanged (this);
  41009. i = jmin (i, listeners.size() - 1);
  41010. }
  41011. }
  41012. if (sized)
  41013. {
  41014. for (int i = listeners.size(); --i >= 0;)
  41015. {
  41016. listeners.getUnchecked(i)->tableColumnsResized (this);
  41017. i = jmin (i, listeners.size() - 1);
  41018. }
  41019. }
  41020. }
  41021. int TableHeaderComponent::getResizeDraggerAt (const int mouseX) const
  41022. {
  41023. if (((unsigned int) mouseX) < (unsigned int) getWidth())
  41024. {
  41025. const int draggableDistance = 3;
  41026. int x = 0;
  41027. for (int i = 0; i < columns.size(); ++i)
  41028. {
  41029. const ColumnInfo* const ci = columns.getUnchecked(i);
  41030. if (ci->isVisible())
  41031. {
  41032. if (abs (mouseX - (x + ci->width)) <= draggableDistance
  41033. && (ci->propertyFlags & resizable) != 0)
  41034. return ci->id;
  41035. x += ci->width;
  41036. }
  41037. }
  41038. }
  41039. return 0;
  41040. }
  41041. void TableHeaderComponent::updateColumnUnderMouse (int x, int y)
  41042. {
  41043. const int newCol = (reallyContains (x, y, true) && getResizeDraggerAt (x) == 0)
  41044. ? getColumnIdAtX (x) : 0;
  41045. if (newCol != columnIdUnderMouse)
  41046. {
  41047. columnIdUnderMouse = newCol;
  41048. repaint();
  41049. }
  41050. }
  41051. void TableHeaderComponent::showColumnChooserMenu (const int columnIdClicked)
  41052. {
  41053. PopupMenu m;
  41054. addMenuItems (m, columnIdClicked);
  41055. if (m.getNumItems() > 0)
  41056. {
  41057. m.setLookAndFeel (&getLookAndFeel());
  41058. const int result = m.show();
  41059. if (result != 0)
  41060. reactToMenuItem (result, columnIdClicked);
  41061. }
  41062. }
  41063. void TableHeaderListener::tableColumnDraggingChanged (TableHeaderComponent*, int)
  41064. {
  41065. }
  41066. END_JUCE_NAMESPACE
  41067. /*** End of inlined file: juce_TableHeaderComponent.cpp ***/
  41068. /*** Start of inlined file: juce_TableListBox.cpp ***/
  41069. BEGIN_JUCE_NAMESPACE
  41070. static const char* const tableColumnPropertyTag = "_tableColumnID";
  41071. class TableListRowComp : public Component,
  41072. public TooltipClient
  41073. {
  41074. public:
  41075. TableListRowComp (TableListBox& owner_)
  41076. : owner (owner_),
  41077. row (-1),
  41078. isSelected (false)
  41079. {
  41080. }
  41081. ~TableListRowComp()
  41082. {
  41083. deleteAllChildren();
  41084. }
  41085. void paint (Graphics& g)
  41086. {
  41087. TableListBoxModel* const model = owner.getModel();
  41088. if (model != 0)
  41089. {
  41090. const TableHeaderComponent* const header = owner.getHeader();
  41091. model->paintRowBackground (g, row, getWidth(), getHeight(), isSelected);
  41092. const int numColumns = header->getNumColumns (true);
  41093. for (int i = 0; i < numColumns; ++i)
  41094. {
  41095. if (! columnsWithComponents [i])
  41096. {
  41097. const int columnId = header->getColumnIdOfIndex (i, true);
  41098. Rectangle<int> columnRect (header->getColumnPosition (i));
  41099. columnRect.setSize (columnRect.getWidth(), getHeight());
  41100. g.saveState();
  41101. g.reduceClipRegion (columnRect);
  41102. g.setOrigin (columnRect.getX(), 0);
  41103. model->paintCell (g, row, columnId, columnRect.getWidth(), columnRect.getHeight(), isSelected);
  41104. g.restoreState();
  41105. }
  41106. }
  41107. }
  41108. }
  41109. void update (const int newRow, const bool isNowSelected)
  41110. {
  41111. if (newRow != row || isNowSelected != isSelected)
  41112. {
  41113. row = newRow;
  41114. isSelected = isNowSelected;
  41115. repaint();
  41116. }
  41117. if (row < owner.getNumRows())
  41118. {
  41119. jassert (row >= 0);
  41120. const var::identifier tagPropertyName ("_tableLastUseNum");
  41121. const int newTag = Random::getSystemRandom().nextInt();
  41122. const TableHeaderComponent* const header = owner.getHeader();
  41123. const int numColumns = header->getNumColumns (true);
  41124. int i;
  41125. columnsWithComponents.clear();
  41126. if (owner.getModel() != 0)
  41127. {
  41128. for (i = 0; i < numColumns; ++i)
  41129. {
  41130. const int columnId = header->getColumnIdOfIndex (i, true);
  41131. Component* const newComp
  41132. = owner.getModel()->refreshComponentForCell (row, columnId, isSelected,
  41133. findChildComponentForColumn (columnId));
  41134. if (newComp != 0)
  41135. {
  41136. addAndMakeVisible (newComp);
  41137. newComp->getProperties().set (tagPropertyName, newTag);
  41138. newComp->getProperties().set (tableColumnPropertyTag, columnId);
  41139. const Rectangle<int> columnRect (header->getColumnPosition (i));
  41140. newComp->setBounds (columnRect.getX(), 0, columnRect.getWidth(), getHeight());
  41141. columnsWithComponents.setBit (i);
  41142. }
  41143. }
  41144. }
  41145. for (i = getNumChildComponents(); --i >= 0;)
  41146. {
  41147. Component* const c = getChildComponent (i);
  41148. if ((int) c->getProperties() [tagPropertyName] != newTag)
  41149. delete c;
  41150. }
  41151. }
  41152. else
  41153. {
  41154. columnsWithComponents.clear();
  41155. deleteAllChildren();
  41156. }
  41157. }
  41158. void resized()
  41159. {
  41160. for (int i = getNumChildComponents(); --i >= 0;)
  41161. {
  41162. Component* const c = getChildComponent (i);
  41163. const int columnId = c->getProperties() [tableColumnPropertyTag];
  41164. if (columnId != 0)
  41165. {
  41166. const Rectangle<int> columnRect (owner.getHeader()->getColumnPosition (owner.getHeader()->getIndexOfColumnId (columnId, true)));
  41167. c->setBounds (columnRect.getX(), 0, columnRect.getWidth(), getHeight());
  41168. }
  41169. }
  41170. }
  41171. void mouseDown (const MouseEvent& e)
  41172. {
  41173. isDragging = false;
  41174. selectRowOnMouseUp = false;
  41175. if (isEnabled())
  41176. {
  41177. if (! isSelected)
  41178. {
  41179. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  41180. const int columnId = owner.getHeader()->getColumnIdAtX (e.x);
  41181. if (columnId != 0 && owner.getModel() != 0)
  41182. owner.getModel()->cellClicked (row, columnId, e);
  41183. }
  41184. else
  41185. {
  41186. selectRowOnMouseUp = true;
  41187. }
  41188. }
  41189. }
  41190. void mouseDrag (const MouseEvent& e)
  41191. {
  41192. if (isEnabled() && owner.getModel() != 0 && ! (e.mouseWasClicked() || isDragging))
  41193. {
  41194. const SparseSet <int> selectedRows (owner.getSelectedRows());
  41195. if (selectedRows.size() > 0)
  41196. {
  41197. const String dragDescription (owner.getModel()->getDragSourceDescription (selectedRows));
  41198. if (dragDescription.isNotEmpty())
  41199. {
  41200. isDragging = true;
  41201. owner.startDragAndDrop (e, dragDescription);
  41202. }
  41203. }
  41204. }
  41205. }
  41206. void mouseUp (const MouseEvent& e)
  41207. {
  41208. if (selectRowOnMouseUp && e.mouseWasClicked() && isEnabled())
  41209. {
  41210. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  41211. const int columnId = owner.getHeader()->getColumnIdAtX (e.x);
  41212. if (columnId != 0 && owner.getModel() != 0)
  41213. owner.getModel()->cellClicked (row, columnId, e);
  41214. }
  41215. }
  41216. void mouseDoubleClick (const MouseEvent& e)
  41217. {
  41218. const int columnId = owner.getHeader()->getColumnIdAtX (e.x);
  41219. if (columnId != 0 && owner.getModel() != 0)
  41220. owner.getModel()->cellDoubleClicked (row, columnId, e);
  41221. }
  41222. const String getTooltip()
  41223. {
  41224. int x, y;
  41225. getMouseXYRelative (x, y);
  41226. const int columnId = owner.getHeader()->getColumnIdAtX (x);
  41227. if (columnId != 0 && owner.getModel() != 0)
  41228. return owner.getModel()->getCellTooltip (row, columnId);
  41229. return String::empty;
  41230. }
  41231. juce_UseDebuggingNewOperator
  41232. private:
  41233. TableListBox& owner;
  41234. int row;
  41235. bool isSelected, isDragging, selectRowOnMouseUp;
  41236. BitArray columnsWithComponents;
  41237. Component* findChildComponentForColumn (const int columnId) const
  41238. {
  41239. for (int i = getNumChildComponents(); --i >= 0;)
  41240. {
  41241. Component* const c = getChildComponent (i);
  41242. if ((int) c->getProperties() [tableColumnPropertyTag] == columnId)
  41243. return c;
  41244. }
  41245. return 0;
  41246. }
  41247. TableListRowComp (const TableListRowComp&);
  41248. const TableListRowComp& operator= (const TableListRowComp&);
  41249. };
  41250. class TableListBoxHeader : public TableHeaderComponent
  41251. {
  41252. public:
  41253. TableListBoxHeader (TableListBox& owner_)
  41254. : owner (owner_)
  41255. {
  41256. }
  41257. ~TableListBoxHeader()
  41258. {
  41259. }
  41260. void addMenuItems (PopupMenu& menu, const int columnIdClicked)
  41261. {
  41262. if (owner.isAutoSizeMenuOptionShown())
  41263. {
  41264. menu.addItem (0xf836743, TRANS("Auto-size this column"), columnIdClicked != 0);
  41265. menu.addItem (0xf836744, TRANS("Auto-size all columns"), owner.getHeader()->getNumColumns (true) > 0);
  41266. menu.addSeparator();
  41267. }
  41268. TableHeaderComponent::addMenuItems (menu, columnIdClicked);
  41269. }
  41270. void reactToMenuItem (const int menuReturnId, const int columnIdClicked)
  41271. {
  41272. if (menuReturnId == 0xf836743)
  41273. {
  41274. owner.autoSizeColumn (columnIdClicked);
  41275. }
  41276. else if (menuReturnId == 0xf836744)
  41277. {
  41278. owner.autoSizeAllColumns();
  41279. }
  41280. else
  41281. {
  41282. TableHeaderComponent::reactToMenuItem (menuReturnId, columnIdClicked);
  41283. }
  41284. }
  41285. juce_UseDebuggingNewOperator
  41286. private:
  41287. TableListBox& owner;
  41288. TableListBoxHeader (const TableListBoxHeader&);
  41289. const TableListBoxHeader& operator= (const TableListBoxHeader&);
  41290. };
  41291. TableListBox::TableListBox (const String& name, TableListBoxModel* const model_)
  41292. : ListBox (name, 0),
  41293. model (model_),
  41294. autoSizeOptionsShown (true)
  41295. {
  41296. ListBox::model = this;
  41297. header = new TableListBoxHeader (*this);
  41298. header->setSize (100, 28);
  41299. header->addListener (this);
  41300. setHeaderComponent (header);
  41301. }
  41302. TableListBox::~TableListBox()
  41303. {
  41304. deleteAllChildren();
  41305. }
  41306. void TableListBox::setModel (TableListBoxModel* const newModel)
  41307. {
  41308. if (model != newModel)
  41309. {
  41310. model = newModel;
  41311. updateContent();
  41312. }
  41313. }
  41314. int TableListBox::getHeaderHeight() const
  41315. {
  41316. return header->getHeight();
  41317. }
  41318. void TableListBox::setHeaderHeight (const int newHeight)
  41319. {
  41320. header->setSize (header->getWidth(), newHeight);
  41321. resized();
  41322. }
  41323. void TableListBox::autoSizeColumn (const int columnId)
  41324. {
  41325. const int width = model != 0 ? model->getColumnAutoSizeWidth (columnId) : 0;
  41326. if (width > 0)
  41327. header->setColumnWidth (columnId, width);
  41328. }
  41329. void TableListBox::autoSizeAllColumns()
  41330. {
  41331. for (int i = 0; i < header->getNumColumns (true); ++i)
  41332. autoSizeColumn (header->getColumnIdOfIndex (i, true));
  41333. }
  41334. void TableListBox::setAutoSizeMenuOptionShown (const bool shouldBeShown)
  41335. {
  41336. autoSizeOptionsShown = shouldBeShown;
  41337. }
  41338. bool TableListBox::isAutoSizeMenuOptionShown() const
  41339. {
  41340. return autoSizeOptionsShown;
  41341. }
  41342. const Rectangle<int> TableListBox::getCellPosition (const int columnId,
  41343. const int rowNumber,
  41344. const bool relativeToComponentTopLeft) const
  41345. {
  41346. Rectangle<int> headerCell (header->getColumnPosition (header->getIndexOfColumnId (columnId, true)));
  41347. if (relativeToComponentTopLeft)
  41348. headerCell.translate (header->getX(), 0);
  41349. const Rectangle<int> row (getRowPosition (rowNumber, relativeToComponentTopLeft));
  41350. return Rectangle<int> (headerCell.getX(), row.getY(),
  41351. headerCell.getWidth(), row.getHeight());
  41352. }
  41353. void TableListBox::scrollToEnsureColumnIsOnscreen (const int columnId)
  41354. {
  41355. ScrollBar* const scrollbar = getHorizontalScrollBar();
  41356. if (scrollbar != 0)
  41357. {
  41358. const Rectangle<int> pos (header->getColumnPosition (header->getIndexOfColumnId (columnId, true)));
  41359. double x = scrollbar->getCurrentRangeStart();
  41360. const double w = scrollbar->getCurrentRangeSize();
  41361. if (pos.getX() < x)
  41362. x = pos.getX();
  41363. else if (pos.getRight() > x + w)
  41364. x += jmax (0.0, pos.getRight() - (x + w));
  41365. scrollbar->setCurrentRangeStart (x);
  41366. }
  41367. }
  41368. int TableListBox::getNumRows()
  41369. {
  41370. return model != 0 ? model->getNumRows() : 0;
  41371. }
  41372. void TableListBox::paintListBoxItem (int, Graphics&, int, int, bool)
  41373. {
  41374. }
  41375. Component* TableListBox::refreshComponentForRow (int rowNumber, bool isRowSelected_, Component* existingComponentToUpdate)
  41376. {
  41377. if (existingComponentToUpdate == 0)
  41378. existingComponentToUpdate = new TableListRowComp (*this);
  41379. ((TableListRowComp*) existingComponentToUpdate)->update (rowNumber, isRowSelected_);
  41380. return existingComponentToUpdate;
  41381. }
  41382. void TableListBox::selectedRowsChanged (int row)
  41383. {
  41384. if (model != 0)
  41385. model->selectedRowsChanged (row);
  41386. }
  41387. void TableListBox::deleteKeyPressed (int row)
  41388. {
  41389. if (model != 0)
  41390. model->deleteKeyPressed (row);
  41391. }
  41392. void TableListBox::returnKeyPressed (int row)
  41393. {
  41394. if (model != 0)
  41395. model->returnKeyPressed (row);
  41396. }
  41397. void TableListBox::backgroundClicked()
  41398. {
  41399. if (model != 0)
  41400. model->backgroundClicked();
  41401. }
  41402. void TableListBox::listWasScrolled()
  41403. {
  41404. if (model != 0)
  41405. model->listWasScrolled();
  41406. }
  41407. void TableListBox::tableColumnsChanged (TableHeaderComponent*)
  41408. {
  41409. setMinimumContentWidth (header->getTotalWidth());
  41410. repaint();
  41411. updateColumnComponents();
  41412. }
  41413. void TableListBox::tableColumnsResized (TableHeaderComponent*)
  41414. {
  41415. setMinimumContentWidth (header->getTotalWidth());
  41416. repaint();
  41417. updateColumnComponents();
  41418. }
  41419. void TableListBox::tableSortOrderChanged (TableHeaderComponent*)
  41420. {
  41421. if (model != 0)
  41422. model->sortOrderChanged (header->getSortColumnId(),
  41423. header->isSortedForwards());
  41424. }
  41425. void TableListBox::tableColumnDraggingChanged (TableHeaderComponent*, int columnIdNowBeingDragged_)
  41426. {
  41427. columnIdNowBeingDragged = columnIdNowBeingDragged_;
  41428. repaint();
  41429. }
  41430. void TableListBox::resized()
  41431. {
  41432. ListBox::resized();
  41433. header->resizeAllColumnsToFit (getVisibleContentWidth());
  41434. setMinimumContentWidth (header->getTotalWidth());
  41435. }
  41436. void TableListBox::updateColumnComponents() const
  41437. {
  41438. const int firstRow = getRowContainingPosition (0, 0);
  41439. for (int i = firstRow + getNumRowsOnScreen() + 2; --i >= firstRow;)
  41440. {
  41441. TableListRowComp* const rowComp = dynamic_cast <TableListRowComp*> (getComponentForRowNumber (i));
  41442. if (rowComp != 0)
  41443. rowComp->resized();
  41444. }
  41445. }
  41446. void TableListBoxModel::cellClicked (int, int, const MouseEvent&)
  41447. {
  41448. }
  41449. void TableListBoxModel::cellDoubleClicked (int, int, const MouseEvent&)
  41450. {
  41451. }
  41452. void TableListBoxModel::backgroundClicked()
  41453. {
  41454. }
  41455. void TableListBoxModel::sortOrderChanged (int, const bool)
  41456. {
  41457. }
  41458. int TableListBoxModel::getColumnAutoSizeWidth (int)
  41459. {
  41460. return 0;
  41461. }
  41462. void TableListBoxModel::selectedRowsChanged (int)
  41463. {
  41464. }
  41465. void TableListBoxModel::deleteKeyPressed (int)
  41466. {
  41467. }
  41468. void TableListBoxModel::returnKeyPressed (int)
  41469. {
  41470. }
  41471. void TableListBoxModel::listWasScrolled()
  41472. {
  41473. }
  41474. const String TableListBoxModel::getCellTooltip (int /*rowNumber*/, int /*columnId*/)
  41475. {
  41476. return String::empty;
  41477. }
  41478. const String TableListBoxModel::getDragSourceDescription (const SparseSet<int>&)
  41479. {
  41480. return String::empty;
  41481. }
  41482. Component* TableListBoxModel::refreshComponentForCell (int, int, bool, Component* existingComponentToUpdate)
  41483. {
  41484. (void) existingComponentToUpdate;
  41485. jassert (existingComponentToUpdate == 0); // indicates a failure in the code the recycles the components
  41486. return 0;
  41487. }
  41488. END_JUCE_NAMESPACE
  41489. /*** End of inlined file: juce_TableListBox.cpp ***/
  41490. /*** Start of inlined file: juce_TextEditor.cpp ***/
  41491. BEGIN_JUCE_NAMESPACE
  41492. // a word or space that can't be broken down any further
  41493. struct TextAtom
  41494. {
  41495. String atomText;
  41496. float width;
  41497. uint16 numChars;
  41498. bool isWhitespace() const { return CharacterFunctions::isWhitespace (atomText[0]); }
  41499. bool isNewLine() const { return atomText[0] == T('\r') || atomText[0] == T('\n'); }
  41500. const String getText (const tchar passwordCharacter) const
  41501. {
  41502. if (passwordCharacter == 0)
  41503. return atomText;
  41504. else
  41505. return String::repeatedString (String::charToString (passwordCharacter),
  41506. atomText.length());
  41507. }
  41508. const String getTrimmedText (const tchar passwordCharacter) const
  41509. {
  41510. if (passwordCharacter == 0)
  41511. return atomText.substring (0, numChars);
  41512. else if (isNewLine())
  41513. return String::empty;
  41514. else
  41515. return String::repeatedString (String::charToString (passwordCharacter), numChars);
  41516. }
  41517. };
  41518. // a run of text with a single font and colour
  41519. class UniformTextSection
  41520. {
  41521. public:
  41522. UniformTextSection (const String& text,
  41523. const Font& font_,
  41524. const Colour& colour_,
  41525. const tchar passwordCharacter)
  41526. : font (font_),
  41527. colour (colour_)
  41528. {
  41529. initialiseAtoms (text, passwordCharacter);
  41530. }
  41531. UniformTextSection (const UniformTextSection& other)
  41532. : font (other.font),
  41533. colour (other.colour)
  41534. {
  41535. atoms.ensureStorageAllocated (other.atoms.size());
  41536. for (int i = 0; i < other.atoms.size(); ++i)
  41537. atoms.add (new TextAtom (*(const TextAtom*) other.atoms.getUnchecked(i)));
  41538. }
  41539. ~UniformTextSection()
  41540. {
  41541. // (no need to delete the atoms, as they're explicitly deleted by the caller)
  41542. }
  41543. void clear()
  41544. {
  41545. for (int i = atoms.size(); --i >= 0;)
  41546. delete getAtom(i);
  41547. atoms.clear();
  41548. }
  41549. int getNumAtoms() const
  41550. {
  41551. return atoms.size();
  41552. }
  41553. TextAtom* getAtom (const int index) const
  41554. {
  41555. return (TextAtom*) atoms.getUnchecked (index);
  41556. }
  41557. void append (const UniformTextSection& other, const tchar passwordCharacter)
  41558. {
  41559. if (other.atoms.size() > 0)
  41560. {
  41561. TextAtom* const lastAtom = (TextAtom*) atoms.getLast();
  41562. int i = 0;
  41563. if (lastAtom != 0)
  41564. {
  41565. if (! CharacterFunctions::isWhitespace (lastAtom->atomText.getLastCharacter()))
  41566. {
  41567. TextAtom* const first = other.getAtom(0);
  41568. if (! CharacterFunctions::isWhitespace (first->atomText[0]))
  41569. {
  41570. lastAtom->atomText += first->atomText;
  41571. lastAtom->numChars = (uint16) (lastAtom->numChars + first->numChars);
  41572. lastAtom->width = font.getStringWidthFloat (lastAtom->getText (passwordCharacter));
  41573. delete first;
  41574. ++i;
  41575. }
  41576. }
  41577. }
  41578. atoms.ensureStorageAllocated (atoms.size() + other.atoms.size() - i);
  41579. while (i < other.atoms.size())
  41580. {
  41581. atoms.add (other.getAtom(i));
  41582. ++i;
  41583. }
  41584. }
  41585. }
  41586. UniformTextSection* split (const int indexToBreakAt,
  41587. const tchar passwordCharacter)
  41588. {
  41589. UniformTextSection* const section2 = new UniformTextSection (String::empty,
  41590. font, colour,
  41591. passwordCharacter);
  41592. int index = 0;
  41593. for (int i = 0; i < atoms.size(); ++i)
  41594. {
  41595. TextAtom* const atom = getAtom(i);
  41596. const int nextIndex = index + atom->numChars;
  41597. if (index == indexToBreakAt)
  41598. {
  41599. int j;
  41600. for (j = i; j < atoms.size(); ++j)
  41601. section2->atoms.add (getAtom (j));
  41602. for (j = atoms.size(); --j >= i;)
  41603. atoms.remove (j);
  41604. break;
  41605. }
  41606. else if (indexToBreakAt >= index && indexToBreakAt < nextIndex)
  41607. {
  41608. TextAtom* const secondAtom = new TextAtom();
  41609. secondAtom->atomText = atom->atomText.substring (indexToBreakAt - index);
  41610. secondAtom->width = font.getStringWidthFloat (secondAtom->getText (passwordCharacter));
  41611. secondAtom->numChars = (uint16) secondAtom->atomText.length();
  41612. section2->atoms.add (secondAtom);
  41613. atom->atomText = atom->atomText.substring (0, indexToBreakAt - index);
  41614. atom->width = font.getStringWidthFloat (atom->getText (passwordCharacter));
  41615. atom->numChars = (uint16) (indexToBreakAt - index);
  41616. int j;
  41617. for (j = i + 1; j < atoms.size(); ++j)
  41618. section2->atoms.add (getAtom (j));
  41619. for (j = atoms.size(); --j > i;)
  41620. atoms.remove (j);
  41621. break;
  41622. }
  41623. index = nextIndex;
  41624. }
  41625. return section2;
  41626. }
  41627. void appendAllText (String::Concatenator& concatenator) const
  41628. {
  41629. for (int i = 0; i < atoms.size(); ++i)
  41630. concatenator.append (getAtom(i)->atomText);
  41631. }
  41632. void appendSubstring (String::Concatenator& concatenator,
  41633. const Range<int>& range) const
  41634. {
  41635. int index = 0;
  41636. for (int i = 0; i < atoms.size(); ++i)
  41637. {
  41638. const TextAtom* const atom = getAtom (i);
  41639. const int nextIndex = index + atom->numChars;
  41640. if (range.getStart() < nextIndex)
  41641. {
  41642. if (range.getEnd() <= index)
  41643. break;
  41644. const Range<int> r ((range - index).getIntersectionWith (Range<int> (0, (int) atom->numChars)));
  41645. if (! r.isEmpty())
  41646. concatenator.append (atom->atomText.substring (r.getStart(), r.getEnd()));
  41647. }
  41648. index = nextIndex;
  41649. }
  41650. }
  41651. int getTotalLength() const
  41652. {
  41653. int total = 0;
  41654. for (int i = atoms.size(); --i >= 0;)
  41655. total += getAtom(i)->numChars;
  41656. return total;
  41657. }
  41658. void setFont (const Font& newFont,
  41659. const tchar passwordCharacter)
  41660. {
  41661. if (font != newFont)
  41662. {
  41663. font = newFont;
  41664. for (int i = atoms.size(); --i >= 0;)
  41665. {
  41666. TextAtom* const atom = (TextAtom*) atoms.getUnchecked(i);
  41667. atom->width = newFont.getStringWidthFloat (atom->getText (passwordCharacter));
  41668. }
  41669. }
  41670. }
  41671. juce_UseDebuggingNewOperator
  41672. Font font;
  41673. Colour colour;
  41674. private:
  41675. VoidArray atoms;
  41676. void initialiseAtoms (const String& textToParse,
  41677. const tchar passwordCharacter)
  41678. {
  41679. int i = 0;
  41680. const int len = textToParse.length();
  41681. const tchar* const text = (const tchar*) textToParse;
  41682. while (i < len)
  41683. {
  41684. int start = i;
  41685. // create a whitespace atom unless it starts with non-ws
  41686. if (CharacterFunctions::isWhitespace (text[i])
  41687. && text[i] != T('\r')
  41688. && text[i] != T('\n'))
  41689. {
  41690. while (i < len
  41691. && CharacterFunctions::isWhitespace (text[i])
  41692. && text[i] != T('\r')
  41693. && text[i] != T('\n'))
  41694. {
  41695. ++i;
  41696. }
  41697. }
  41698. else
  41699. {
  41700. if (text[i] == T('\r'))
  41701. {
  41702. ++i;
  41703. if ((i < len) && (text[i] == T('\n')))
  41704. {
  41705. ++start;
  41706. ++i;
  41707. }
  41708. }
  41709. else if (text[i] == T('\n'))
  41710. {
  41711. ++i;
  41712. }
  41713. else
  41714. {
  41715. while ((i < len) && ! CharacterFunctions::isWhitespace (text[i]))
  41716. ++i;
  41717. }
  41718. }
  41719. TextAtom* const atom = new TextAtom();
  41720. atom->atomText = String (text + start, i - start);
  41721. atom->width = font.getStringWidthFloat (atom->getText (passwordCharacter));
  41722. atom->numChars = (uint16) (i - start);
  41723. atoms.add (atom);
  41724. }
  41725. }
  41726. const UniformTextSection& operator= (const UniformTextSection& other);
  41727. };
  41728. class TextEditorIterator
  41729. {
  41730. public:
  41731. TextEditorIterator (const VoidArray& sections_,
  41732. const float wordWrapWidth_,
  41733. const tchar passwordCharacter_)
  41734. : indexInText (0),
  41735. lineY (0),
  41736. lineHeight (0),
  41737. maxDescent (0),
  41738. atomX (0),
  41739. atomRight (0),
  41740. atom (0),
  41741. currentSection (0),
  41742. sections (sections_),
  41743. sectionIndex (0),
  41744. atomIndex (0),
  41745. wordWrapWidth (wordWrapWidth_),
  41746. passwordCharacter (passwordCharacter_)
  41747. {
  41748. jassert (wordWrapWidth_ > 0);
  41749. if (sections.size() > 0)
  41750. {
  41751. currentSection = (const UniformTextSection*) sections.getUnchecked (sectionIndex);
  41752. if (currentSection != 0)
  41753. beginNewLine();
  41754. }
  41755. }
  41756. TextEditorIterator (const TextEditorIterator& other)
  41757. : indexInText (other.indexInText),
  41758. lineY (other.lineY),
  41759. lineHeight (other.lineHeight),
  41760. maxDescent (other.maxDescent),
  41761. atomX (other.atomX),
  41762. atomRight (other.atomRight),
  41763. atom (other.atom),
  41764. currentSection (other.currentSection),
  41765. sections (other.sections),
  41766. sectionIndex (other.sectionIndex),
  41767. atomIndex (other.atomIndex),
  41768. wordWrapWidth (other.wordWrapWidth),
  41769. passwordCharacter (other.passwordCharacter),
  41770. tempAtom (other.tempAtom)
  41771. {
  41772. }
  41773. ~TextEditorIterator()
  41774. {
  41775. }
  41776. bool next()
  41777. {
  41778. if (atom == &tempAtom)
  41779. {
  41780. const int numRemaining = tempAtom.atomText.length() - tempAtom.numChars;
  41781. if (numRemaining > 0)
  41782. {
  41783. tempAtom.atomText = tempAtom.atomText.substring (tempAtom.numChars);
  41784. atomX = 0;
  41785. if (tempAtom.numChars > 0)
  41786. lineY += lineHeight;
  41787. indexInText += tempAtom.numChars;
  41788. GlyphArrangement g;
  41789. g.addLineOfText (currentSection->font, atom->getText (passwordCharacter), 0.0f, 0.0f);
  41790. int split;
  41791. for (split = 0; split < g.getNumGlyphs(); ++split)
  41792. if (shouldWrap (g.getGlyph (split).getRight()))
  41793. break;
  41794. if (split > 0 && split <= numRemaining)
  41795. {
  41796. tempAtom.numChars = (uint16) split;
  41797. tempAtom.width = g.getGlyph (split - 1).getRight();
  41798. atomRight = atomX + tempAtom.width;
  41799. return true;
  41800. }
  41801. }
  41802. }
  41803. bool forceNewLine = false;
  41804. if (sectionIndex >= sections.size())
  41805. {
  41806. moveToEndOfLastAtom();
  41807. return false;
  41808. }
  41809. else if (atomIndex >= currentSection->getNumAtoms() - 1)
  41810. {
  41811. if (atomIndex >= currentSection->getNumAtoms())
  41812. {
  41813. if (++sectionIndex >= sections.size())
  41814. {
  41815. moveToEndOfLastAtom();
  41816. return false;
  41817. }
  41818. atomIndex = 0;
  41819. currentSection = (const UniformTextSection*) sections.getUnchecked (sectionIndex);
  41820. }
  41821. else
  41822. {
  41823. const TextAtom* const lastAtom = currentSection->getAtom (atomIndex);
  41824. if (! lastAtom->isWhitespace())
  41825. {
  41826. // handle the case where the last atom in a section is actually part of the same
  41827. // word as the first atom of the next section...
  41828. float right = atomRight + lastAtom->width;
  41829. float lineHeight2 = lineHeight;
  41830. float maxDescent2 = maxDescent;
  41831. for (int section = sectionIndex + 1; section < sections.size(); ++section)
  41832. {
  41833. const UniformTextSection* const s = (const UniformTextSection*) sections.getUnchecked (section);
  41834. if (s->getNumAtoms() == 0)
  41835. break;
  41836. const TextAtom* const nextAtom = s->getAtom (0);
  41837. if (nextAtom->isWhitespace())
  41838. break;
  41839. right += nextAtom->width;
  41840. lineHeight2 = jmax (lineHeight2, s->font.getHeight());
  41841. maxDescent2 = jmax (maxDescent2, s->font.getDescent());
  41842. if (shouldWrap (right))
  41843. {
  41844. lineHeight = lineHeight2;
  41845. maxDescent = maxDescent2;
  41846. forceNewLine = true;
  41847. break;
  41848. }
  41849. if (s->getNumAtoms() > 1)
  41850. break;
  41851. }
  41852. }
  41853. }
  41854. }
  41855. if (atom != 0)
  41856. {
  41857. atomX = atomRight;
  41858. indexInText += atom->numChars;
  41859. if (atom->isNewLine())
  41860. beginNewLine();
  41861. }
  41862. atom = currentSection->getAtom (atomIndex);
  41863. atomRight = atomX + atom->width;
  41864. ++atomIndex;
  41865. if (shouldWrap (atomRight) || forceNewLine)
  41866. {
  41867. if (atom->isWhitespace())
  41868. {
  41869. // leave whitespace at the end of a line, but truncate it to avoid scrolling
  41870. atomRight = jmin (atomRight, wordWrapWidth);
  41871. }
  41872. else
  41873. {
  41874. atomRight = atom->width;
  41875. if (shouldWrap (atomRight)) // atom too big to fit on a line, so break it up..
  41876. {
  41877. tempAtom = *atom;
  41878. tempAtom.width = 0;
  41879. tempAtom.numChars = 0;
  41880. atom = &tempAtom;
  41881. if (atomX > 0)
  41882. beginNewLine();
  41883. return next();
  41884. }
  41885. beginNewLine();
  41886. return true;
  41887. }
  41888. }
  41889. return true;
  41890. }
  41891. void beginNewLine()
  41892. {
  41893. atomX = 0;
  41894. lineY += lineHeight;
  41895. int tempSectionIndex = sectionIndex;
  41896. int tempAtomIndex = atomIndex;
  41897. const UniformTextSection* section = (const UniformTextSection*) sections.getUnchecked (tempSectionIndex);
  41898. lineHeight = section->font.getHeight();
  41899. maxDescent = section->font.getDescent();
  41900. float x = (atom != 0) ? atom->width : 0;
  41901. while (! shouldWrap (x))
  41902. {
  41903. if (tempSectionIndex >= sections.size())
  41904. break;
  41905. bool checkSize = false;
  41906. if (tempAtomIndex >= section->getNumAtoms())
  41907. {
  41908. if (++tempSectionIndex >= sections.size())
  41909. break;
  41910. tempAtomIndex = 0;
  41911. section = (const UniformTextSection*) sections.getUnchecked (tempSectionIndex);
  41912. checkSize = true;
  41913. }
  41914. const TextAtom* const nextAtom = section->getAtom (tempAtomIndex);
  41915. if (nextAtom == 0)
  41916. break;
  41917. x += nextAtom->width;
  41918. if (shouldWrap (x) || nextAtom->isNewLine())
  41919. break;
  41920. if (checkSize)
  41921. {
  41922. lineHeight = jmax (lineHeight, section->font.getHeight());
  41923. maxDescent = jmax (maxDescent, section->font.getDescent());
  41924. }
  41925. ++tempAtomIndex;
  41926. }
  41927. }
  41928. void draw (Graphics& g, const UniformTextSection*& lastSection) const
  41929. {
  41930. if (passwordCharacter != 0 || ! atom->isWhitespace())
  41931. {
  41932. if (lastSection != currentSection)
  41933. {
  41934. lastSection = currentSection;
  41935. g.setColour (currentSection->colour);
  41936. g.setFont (currentSection->font);
  41937. }
  41938. jassert (atom->getTrimmedText (passwordCharacter).isNotEmpty());
  41939. GlyphArrangement ga;
  41940. ga.addLineOfText (currentSection->font,
  41941. atom->getTrimmedText (passwordCharacter),
  41942. atomX,
  41943. (float) roundToInt (lineY + lineHeight - maxDescent));
  41944. ga.draw (g);
  41945. }
  41946. }
  41947. void drawSelection (Graphics& g,
  41948. const Range<int>& selection) const
  41949. {
  41950. const int startX = roundToInt (indexToX (selection.getStart()));
  41951. const int endX = roundToInt (indexToX (selection.getEnd()));
  41952. const int y = roundToInt (lineY);
  41953. const int nextY = roundToInt (lineY + lineHeight);
  41954. g.fillRect (startX, y, endX - startX, nextY - y);
  41955. }
  41956. void drawSelectedText (Graphics& g,
  41957. const Range<int>& selection,
  41958. const Colour& selectedTextColour) const
  41959. {
  41960. if (passwordCharacter != 0 || ! atom->isWhitespace())
  41961. {
  41962. GlyphArrangement ga;
  41963. ga.addLineOfText (currentSection->font,
  41964. atom->getTrimmedText (passwordCharacter),
  41965. atomX,
  41966. (float) roundToInt (lineY + lineHeight - maxDescent));
  41967. if (selection.getEnd() < indexInText + atom->numChars)
  41968. {
  41969. GlyphArrangement ga2 (ga);
  41970. ga2.removeRangeOfGlyphs (0, selection.getEnd() - indexInText);
  41971. ga.removeRangeOfGlyphs (selection.getEnd() - indexInText, -1);
  41972. g.setColour (currentSection->colour);
  41973. ga2.draw (g);
  41974. }
  41975. if (selection.getStart() > indexInText)
  41976. {
  41977. GlyphArrangement ga2 (ga);
  41978. ga2.removeRangeOfGlyphs (selection.getStart() - indexInText, -1);
  41979. ga.removeRangeOfGlyphs (0, selection.getStart() - indexInText);
  41980. g.setColour (currentSection->colour);
  41981. ga2.draw (g);
  41982. }
  41983. g.setColour (selectedTextColour);
  41984. ga.draw (g);
  41985. }
  41986. }
  41987. float indexToX (const int indexToFind) const
  41988. {
  41989. if (indexToFind <= indexInText)
  41990. return atomX;
  41991. if (indexToFind >= indexInText + atom->numChars)
  41992. return atomRight;
  41993. GlyphArrangement g;
  41994. g.addLineOfText (currentSection->font,
  41995. atom->getText (passwordCharacter),
  41996. atomX, 0.0f);
  41997. if (indexToFind - indexInText >= g.getNumGlyphs())
  41998. return atomRight;
  41999. return jmin (atomRight, g.getGlyph (indexToFind - indexInText).getLeft());
  42000. }
  42001. int xToIndex (const float xToFind) const
  42002. {
  42003. if (xToFind <= atomX || atom->isNewLine())
  42004. return indexInText;
  42005. if (xToFind >= atomRight)
  42006. return indexInText + atom->numChars;
  42007. GlyphArrangement g;
  42008. g.addLineOfText (currentSection->font,
  42009. atom->getText (passwordCharacter),
  42010. atomX, 0.0f);
  42011. int j;
  42012. for (j = 0; j < g.getNumGlyphs(); ++j)
  42013. if ((g.getGlyph(j).getLeft() + g.getGlyph(j).getRight()) / 2 > xToFind)
  42014. break;
  42015. return indexInText + j;
  42016. }
  42017. bool getCharPosition (const int index, float& cx, float& cy, float& lineHeight_)
  42018. {
  42019. while (next())
  42020. {
  42021. if (indexInText + atom->numChars > index)
  42022. {
  42023. cx = indexToX (index);
  42024. cy = lineY;
  42025. lineHeight_ = lineHeight;
  42026. return true;
  42027. }
  42028. }
  42029. cx = atomX;
  42030. cy = lineY;
  42031. lineHeight_ = lineHeight;
  42032. return false;
  42033. }
  42034. juce_UseDebuggingNewOperator
  42035. int indexInText;
  42036. float lineY, lineHeight, maxDescent;
  42037. float atomX, atomRight;
  42038. const TextAtom* atom;
  42039. const UniformTextSection* currentSection;
  42040. private:
  42041. const VoidArray& sections;
  42042. int sectionIndex, atomIndex;
  42043. const float wordWrapWidth;
  42044. const tchar passwordCharacter;
  42045. TextAtom tempAtom;
  42046. const TextEditorIterator& operator= (const TextEditorIterator&);
  42047. void moveToEndOfLastAtom()
  42048. {
  42049. if (atom != 0)
  42050. {
  42051. atomX = atomRight;
  42052. if (atom->isNewLine())
  42053. {
  42054. atomX = 0.0f;
  42055. lineY += lineHeight;
  42056. }
  42057. }
  42058. }
  42059. bool shouldWrap (const float x) const
  42060. {
  42061. return (x - 0.0001f) >= wordWrapWidth;
  42062. }
  42063. };
  42064. class TextEditorInsertAction : public UndoableAction
  42065. {
  42066. TextEditor& owner;
  42067. const String text;
  42068. const int insertIndex, oldCaretPos, newCaretPos;
  42069. const Font font;
  42070. const Colour colour;
  42071. TextEditorInsertAction (const TextEditorInsertAction&);
  42072. const TextEditorInsertAction& operator= (const TextEditorInsertAction&);
  42073. public:
  42074. TextEditorInsertAction (TextEditor& owner_,
  42075. const String& text_,
  42076. const int insertIndex_,
  42077. const Font& font_,
  42078. const Colour& colour_,
  42079. const int oldCaretPos_,
  42080. const int newCaretPos_)
  42081. : owner (owner_),
  42082. text (text_),
  42083. insertIndex (insertIndex_),
  42084. oldCaretPos (oldCaretPos_),
  42085. newCaretPos (newCaretPos_),
  42086. font (font_),
  42087. colour (colour_)
  42088. {
  42089. }
  42090. ~TextEditorInsertAction()
  42091. {
  42092. }
  42093. bool perform()
  42094. {
  42095. owner.insert (text, insertIndex, font, colour, 0, newCaretPos);
  42096. return true;
  42097. }
  42098. bool undo()
  42099. {
  42100. owner.remove (Range<int> (insertIndex, insertIndex + text.length()), 0, oldCaretPos);
  42101. return true;
  42102. }
  42103. int getSizeInUnits()
  42104. {
  42105. return text.length() + 16;
  42106. }
  42107. };
  42108. class TextEditorRemoveAction : public UndoableAction
  42109. {
  42110. TextEditor& owner;
  42111. const Range<int> range;
  42112. const int oldCaretPos, newCaretPos;
  42113. VoidArray removedSections;
  42114. TextEditorRemoveAction (const TextEditorRemoveAction&);
  42115. const TextEditorRemoveAction& operator= (const TextEditorRemoveAction&);
  42116. public:
  42117. TextEditorRemoveAction (TextEditor& owner_,
  42118. const Range<int> range_,
  42119. const int oldCaretPos_,
  42120. const int newCaretPos_,
  42121. const VoidArray& removedSections_)
  42122. : owner (owner_),
  42123. range (range_),
  42124. oldCaretPos (oldCaretPos_),
  42125. newCaretPos (newCaretPos_),
  42126. removedSections (removedSections_)
  42127. {
  42128. }
  42129. ~TextEditorRemoveAction()
  42130. {
  42131. for (int i = removedSections.size(); --i >= 0;)
  42132. {
  42133. UniformTextSection* const section = (UniformTextSection*) removedSections.getUnchecked (i);
  42134. section->clear();
  42135. delete section;
  42136. }
  42137. }
  42138. bool perform()
  42139. {
  42140. owner.remove (range, 0, newCaretPos);
  42141. return true;
  42142. }
  42143. bool undo()
  42144. {
  42145. owner.reinsert (range.getStart(), removedSections);
  42146. owner.moveCursorTo (oldCaretPos, false);
  42147. return true;
  42148. }
  42149. int getSizeInUnits()
  42150. {
  42151. int n = 0;
  42152. for (int i = removedSections.size(); --i >= 0;)
  42153. {
  42154. UniformTextSection* const section = (UniformTextSection*) removedSections.getUnchecked (i);
  42155. n += section->getTotalLength();
  42156. }
  42157. return n + 16;
  42158. }
  42159. };
  42160. class TextHolderComponent : public Component,
  42161. public Timer,
  42162. public Value::Listener
  42163. {
  42164. TextEditor& owner;
  42165. TextHolderComponent (const TextHolderComponent&);
  42166. const TextHolderComponent& operator= (const TextHolderComponent&);
  42167. public:
  42168. TextHolderComponent (TextEditor& owner_)
  42169. : owner (owner_)
  42170. {
  42171. setWantsKeyboardFocus (false);
  42172. setInterceptsMouseClicks (false, true);
  42173. owner.getTextValue().addListener (this);
  42174. }
  42175. ~TextHolderComponent()
  42176. {
  42177. owner.getTextValue().removeListener (this);
  42178. }
  42179. void paint (Graphics& g)
  42180. {
  42181. owner.drawContent (g);
  42182. }
  42183. void timerCallback()
  42184. {
  42185. owner.timerCallbackInt();
  42186. }
  42187. const MouseCursor getMouseCursor()
  42188. {
  42189. return owner.getMouseCursor();
  42190. }
  42191. void valueChanged (Value&)
  42192. {
  42193. owner.textWasChangedByValue();
  42194. }
  42195. };
  42196. class TextEditorViewport : public Viewport
  42197. {
  42198. TextEditor* const owner;
  42199. float lastWordWrapWidth;
  42200. TextEditorViewport (const TextEditorViewport&);
  42201. const TextEditorViewport& operator= (const TextEditorViewport&);
  42202. public:
  42203. TextEditorViewport (TextEditor* const owner_)
  42204. : owner (owner_),
  42205. lastWordWrapWidth (0)
  42206. {
  42207. }
  42208. ~TextEditorViewport()
  42209. {
  42210. }
  42211. void visibleAreaChanged (int, int, int, int)
  42212. {
  42213. const float wordWrapWidth = owner->getWordWrapWidth();
  42214. if (wordWrapWidth != lastWordWrapWidth)
  42215. {
  42216. lastWordWrapWidth = wordWrapWidth;
  42217. owner->updateTextHolderSize();
  42218. }
  42219. }
  42220. };
  42221. namespace TextEditorDefs
  42222. {
  42223. const int flashSpeedIntervalMs = 380;
  42224. const int textChangeMessageId = 0x10003001;
  42225. const int returnKeyMessageId = 0x10003002;
  42226. const int escapeKeyMessageId = 0x10003003;
  42227. const int focusLossMessageId = 0x10003004;
  42228. const int maxActionsPerTransaction = 100;
  42229. }
  42230. TextEditor::TextEditor (const String& name,
  42231. const tchar passwordCharacter_)
  42232. : Component (name),
  42233. borderSize (1, 1, 1, 3),
  42234. readOnly (false),
  42235. multiline (false),
  42236. wordWrap (false),
  42237. returnKeyStartsNewLine (false),
  42238. caretVisible (true),
  42239. popupMenuEnabled (true),
  42240. selectAllTextWhenFocused (false),
  42241. scrollbarVisible (true),
  42242. wasFocused (false),
  42243. caretFlashState (true),
  42244. keepCursorOnScreen (true),
  42245. tabKeyUsed (false),
  42246. menuActive (false),
  42247. valueTextNeedsUpdating (false),
  42248. cursorX (0),
  42249. cursorY (0),
  42250. cursorHeight (0),
  42251. maxTextLength (0),
  42252. leftIndent (4),
  42253. topIndent (4),
  42254. lastTransactionTime (0),
  42255. currentFont (14.0f),
  42256. totalNumChars (0),
  42257. caretPosition (0),
  42258. passwordCharacter (passwordCharacter_),
  42259. dragType (notDragging)
  42260. {
  42261. setOpaque (true);
  42262. addAndMakeVisible (viewport = new TextEditorViewport (this));
  42263. viewport->setViewedComponent (textHolder = new TextHolderComponent (*this));
  42264. viewport->setWantsKeyboardFocus (false);
  42265. viewport->setScrollBarsShown (false, false);
  42266. setMouseCursor (MouseCursor::IBeamCursor);
  42267. setWantsKeyboardFocus (true);
  42268. }
  42269. TextEditor::~TextEditor()
  42270. {
  42271. textValue.referTo (Value());
  42272. clearInternal (0);
  42273. viewport = 0;
  42274. textHolder = 0;
  42275. }
  42276. void TextEditor::newTransaction()
  42277. {
  42278. lastTransactionTime = Time::getApproximateMillisecondCounter();
  42279. undoManager.beginNewTransaction();
  42280. }
  42281. void TextEditor::doUndoRedo (const bool isRedo)
  42282. {
  42283. if (! isReadOnly())
  42284. {
  42285. if ((isRedo) ? undoManager.redo()
  42286. : undoManager.undo())
  42287. {
  42288. scrollToMakeSureCursorIsVisible();
  42289. repaint();
  42290. textChanged();
  42291. }
  42292. }
  42293. }
  42294. void TextEditor::setMultiLine (const bool shouldBeMultiLine,
  42295. const bool shouldWordWrap)
  42296. {
  42297. multiline = shouldBeMultiLine;
  42298. wordWrap = shouldWordWrap && shouldBeMultiLine;
  42299. setScrollbarsShown (scrollbarVisible);
  42300. viewport->setViewPosition (0, 0);
  42301. resized();
  42302. scrollToMakeSureCursorIsVisible();
  42303. }
  42304. bool TextEditor::isMultiLine() const
  42305. {
  42306. return multiline;
  42307. }
  42308. void TextEditor::setScrollbarsShown (bool enabled)
  42309. {
  42310. scrollbarVisible = enabled;
  42311. enabled = enabled && isMultiLine();
  42312. viewport->setScrollBarsShown (enabled, enabled);
  42313. }
  42314. void TextEditor::setReadOnly (const bool shouldBeReadOnly)
  42315. {
  42316. readOnly = shouldBeReadOnly;
  42317. enablementChanged();
  42318. }
  42319. bool TextEditor::isReadOnly() const
  42320. {
  42321. return readOnly || ! isEnabled();
  42322. }
  42323. void TextEditor::setReturnKeyStartsNewLine (const bool shouldStartNewLine)
  42324. {
  42325. returnKeyStartsNewLine = shouldStartNewLine;
  42326. }
  42327. void TextEditor::setTabKeyUsedAsCharacter (const bool shouldTabKeyBeUsed)
  42328. {
  42329. tabKeyUsed = shouldTabKeyBeUsed;
  42330. }
  42331. void TextEditor::setPopupMenuEnabled (const bool b)
  42332. {
  42333. popupMenuEnabled = b;
  42334. }
  42335. void TextEditor::setSelectAllWhenFocused (const bool b)
  42336. {
  42337. selectAllTextWhenFocused = b;
  42338. }
  42339. const Font TextEditor::getFont() const
  42340. {
  42341. return currentFont;
  42342. }
  42343. void TextEditor::setFont (const Font& newFont)
  42344. {
  42345. currentFont = newFont;
  42346. scrollToMakeSureCursorIsVisible();
  42347. }
  42348. void TextEditor::applyFontToAllText (const Font& newFont)
  42349. {
  42350. currentFont = newFont;
  42351. const Colour overallColour (findColour (textColourId));
  42352. for (int i = sections.size(); --i >= 0;)
  42353. {
  42354. UniformTextSection* const uts = (UniformTextSection*) sections.getUnchecked(i);
  42355. uts->setFont (newFont, passwordCharacter);
  42356. uts->colour = overallColour;
  42357. }
  42358. coalesceSimilarSections();
  42359. updateTextHolderSize();
  42360. scrollToMakeSureCursorIsVisible();
  42361. repaint();
  42362. }
  42363. void TextEditor::colourChanged()
  42364. {
  42365. setOpaque (findColour (backgroundColourId).isOpaque());
  42366. repaint();
  42367. }
  42368. void TextEditor::setCaretVisible (const bool shouldCaretBeVisible)
  42369. {
  42370. caretVisible = shouldCaretBeVisible;
  42371. if (shouldCaretBeVisible)
  42372. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  42373. setMouseCursor (shouldCaretBeVisible ? MouseCursor::IBeamCursor
  42374. : MouseCursor::NormalCursor);
  42375. }
  42376. void TextEditor::setInputRestrictions (const int maxLen,
  42377. const String& chars)
  42378. {
  42379. maxTextLength = jmax (0, maxLen);
  42380. allowedCharacters = chars;
  42381. }
  42382. void TextEditor::setTextToShowWhenEmpty (const String& text, const Colour& colourToUse)
  42383. {
  42384. textToShowWhenEmpty = text;
  42385. colourForTextWhenEmpty = colourToUse;
  42386. }
  42387. void TextEditor::setPasswordCharacter (const tchar newPasswordCharacter)
  42388. {
  42389. if (passwordCharacter != newPasswordCharacter)
  42390. {
  42391. passwordCharacter = newPasswordCharacter;
  42392. resized();
  42393. repaint();
  42394. }
  42395. }
  42396. void TextEditor::setScrollBarThickness (const int newThicknessPixels)
  42397. {
  42398. viewport->setScrollBarThickness (newThicknessPixels);
  42399. }
  42400. void TextEditor::setScrollBarButtonVisibility (const bool buttonsVisible)
  42401. {
  42402. viewport->setScrollBarButtonVisibility (buttonsVisible);
  42403. }
  42404. void TextEditor::clear()
  42405. {
  42406. clearInternal (0);
  42407. updateTextHolderSize();
  42408. undoManager.clearUndoHistory();
  42409. }
  42410. void TextEditor::setText (const String& newText,
  42411. const bool sendTextChangeMessage)
  42412. {
  42413. const int newLength = newText.length();
  42414. if (newLength != getTotalNumChars() || getText() != newText)
  42415. {
  42416. const int oldCursorPos = caretPosition;
  42417. const bool cursorWasAtEnd = oldCursorPos >= getTotalNumChars();
  42418. clearInternal (0);
  42419. insert (newText, 0, currentFont, findColour (textColourId), 0, caretPosition);
  42420. // if you're adding text with line-feeds to a single-line text editor, it
  42421. // ain't gonna look right!
  42422. jassert (multiline || ! newText.containsAnyOf (T("\r\n")));
  42423. if (cursorWasAtEnd && ! isMultiLine())
  42424. moveCursorTo (getTotalNumChars(), false);
  42425. else
  42426. moveCursorTo (oldCursorPos, false);
  42427. if (sendTextChangeMessage)
  42428. textChanged();
  42429. repaint();
  42430. }
  42431. updateTextHolderSize();
  42432. scrollToMakeSureCursorIsVisible();
  42433. undoManager.clearUndoHistory();
  42434. }
  42435. Value& TextEditor::getTextValue()
  42436. {
  42437. if (valueTextNeedsUpdating)
  42438. {
  42439. valueTextNeedsUpdating = false;
  42440. textValue = getText();
  42441. }
  42442. return textValue;
  42443. }
  42444. void TextEditor::textWasChangedByValue()
  42445. {
  42446. if (textValue.getValueSource().getReferenceCount() > 1)
  42447. setText (textValue.getValue());
  42448. }
  42449. void TextEditor::textChanged()
  42450. {
  42451. updateTextHolderSize();
  42452. postCommandMessage (TextEditorDefs::textChangeMessageId);
  42453. if (textValue.getValueSource().getReferenceCount() > 1)
  42454. {
  42455. valueTextNeedsUpdating = false;
  42456. textValue = getText();
  42457. }
  42458. }
  42459. void TextEditor::returnPressed()
  42460. {
  42461. postCommandMessage (TextEditorDefs::returnKeyMessageId);
  42462. }
  42463. void TextEditor::escapePressed()
  42464. {
  42465. postCommandMessage (TextEditorDefs::escapeKeyMessageId);
  42466. }
  42467. void TextEditor::addListener (TextEditorListener* const newListener)
  42468. {
  42469. jassert (newListener != 0)
  42470. if (newListener != 0)
  42471. listeners.add (newListener);
  42472. }
  42473. void TextEditor::removeListener (TextEditorListener* const listenerToRemove)
  42474. {
  42475. listeners.removeValue (listenerToRemove);
  42476. }
  42477. void TextEditor::timerCallbackInt()
  42478. {
  42479. const bool newState = (! caretFlashState) && ! isCurrentlyBlockedByAnotherModalComponent();
  42480. if (caretFlashState != newState)
  42481. {
  42482. caretFlashState = newState;
  42483. if (caretFlashState)
  42484. wasFocused = true;
  42485. if (caretVisible
  42486. && hasKeyboardFocus (false)
  42487. && ! isReadOnly())
  42488. {
  42489. repaintCaret();
  42490. }
  42491. }
  42492. const unsigned int now = Time::getApproximateMillisecondCounter();
  42493. if (now > lastTransactionTime + 200)
  42494. newTransaction();
  42495. }
  42496. void TextEditor::repaintCaret()
  42497. {
  42498. if (! findColour (caretColourId).isTransparent())
  42499. repaint (borderSize.getLeft() + textHolder->getX() + leftIndent + roundToInt (cursorX) - 1,
  42500. borderSize.getTop() + textHolder->getY() + topIndent + roundToInt (cursorY) - 1,
  42501. 4,
  42502. roundToInt (cursorHeight) + 2);
  42503. }
  42504. void TextEditor::repaintText (const Range<int>& range)
  42505. {
  42506. if (! range.isEmpty())
  42507. {
  42508. float x = 0, y = 0, lh = currentFont.getHeight();
  42509. const float wordWrapWidth = getWordWrapWidth();
  42510. if (wordWrapWidth > 0)
  42511. {
  42512. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  42513. i.getCharPosition (range.getStart(), x, y, lh);
  42514. const int y1 = (int) y;
  42515. int y2;
  42516. if (range.getEnd() >= getTotalNumChars())
  42517. {
  42518. y2 = getHeight();
  42519. }
  42520. else
  42521. {
  42522. i.getCharPosition (range.getEnd(), x, y, lh);
  42523. y2 = (int) (y + lh * 2.0f);
  42524. }
  42525. textHolder->repaint (0, y1, textHolder->getWidth(), y2 - y1);
  42526. }
  42527. }
  42528. }
  42529. void TextEditor::moveCaret (int newCaretPos)
  42530. {
  42531. if (newCaretPos < 0)
  42532. newCaretPos = 0;
  42533. else if (newCaretPos > getTotalNumChars())
  42534. newCaretPos = getTotalNumChars();
  42535. if (newCaretPos != getCaretPosition())
  42536. {
  42537. repaintCaret();
  42538. caretFlashState = true;
  42539. caretPosition = newCaretPos;
  42540. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  42541. scrollToMakeSureCursorIsVisible();
  42542. repaintCaret();
  42543. }
  42544. }
  42545. void TextEditor::setCaretPosition (const int newIndex)
  42546. {
  42547. moveCursorTo (newIndex, false);
  42548. }
  42549. int TextEditor::getCaretPosition() const
  42550. {
  42551. return caretPosition;
  42552. }
  42553. void TextEditor::scrollEditorToPositionCaret (const int desiredCaretX,
  42554. const int desiredCaretY)
  42555. {
  42556. updateCaretPosition();
  42557. int vx = roundToInt (cursorX) - desiredCaretX;
  42558. int vy = roundToInt (cursorY) - desiredCaretY;
  42559. if (desiredCaretX < jmax (1, proportionOfWidth (0.05f)))
  42560. {
  42561. vx += desiredCaretX - proportionOfWidth (0.2f);
  42562. }
  42563. else if (desiredCaretX > jmax (0, viewport->getMaximumVisibleWidth() - (wordWrap ? 2 : 10)))
  42564. {
  42565. vx += desiredCaretX + (isMultiLine() ? proportionOfWidth (0.2f) : 10) - viewport->getMaximumVisibleWidth();
  42566. }
  42567. vx = jlimit (0, jmax (0, textHolder->getWidth() + 8 - viewport->getMaximumVisibleWidth()), vx);
  42568. if (! isMultiLine())
  42569. {
  42570. vy = viewport->getViewPositionY();
  42571. }
  42572. else
  42573. {
  42574. vy = jlimit (0, jmax (0, textHolder->getHeight() - viewport->getMaximumVisibleHeight()), vy);
  42575. const int curH = roundToInt (cursorHeight);
  42576. if (desiredCaretY < 0)
  42577. {
  42578. vy = jmax (0, desiredCaretY + vy);
  42579. }
  42580. else if (desiredCaretY > jmax (0, viewport->getMaximumVisibleHeight() - topIndent - curH))
  42581. {
  42582. vy += desiredCaretY + 2 + curH + topIndent - viewport->getMaximumVisibleHeight();
  42583. }
  42584. }
  42585. viewport->setViewPosition (vx, vy);
  42586. }
  42587. const Rectangle<int> TextEditor::getCaretRectangle()
  42588. {
  42589. updateCaretPosition();
  42590. return Rectangle<int> (roundToInt (cursorX) - viewport->getX(),
  42591. roundToInt (cursorY) - viewport->getY(),
  42592. 1, roundToInt (cursorHeight));
  42593. }
  42594. float TextEditor::getWordWrapWidth() const
  42595. {
  42596. return (wordWrap) ? (float) (viewport->getMaximumVisibleWidth() - leftIndent - leftIndent / 2)
  42597. : 1.0e10f;
  42598. }
  42599. void TextEditor::updateTextHolderSize()
  42600. {
  42601. const float wordWrapWidth = getWordWrapWidth();
  42602. if (wordWrapWidth > 0)
  42603. {
  42604. float maxWidth = 0.0f;
  42605. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  42606. while (i.next())
  42607. maxWidth = jmax (maxWidth, i.atomRight);
  42608. const int w = leftIndent + roundToInt (maxWidth);
  42609. const int h = topIndent + roundToInt (jmax (i.lineY + i.lineHeight,
  42610. currentFont.getHeight()));
  42611. textHolder->setSize (w + 1, h + 1);
  42612. }
  42613. }
  42614. int TextEditor::getTextWidth() const
  42615. {
  42616. return textHolder->getWidth();
  42617. }
  42618. int TextEditor::getTextHeight() const
  42619. {
  42620. return textHolder->getHeight();
  42621. }
  42622. void TextEditor::setIndents (const int newLeftIndent,
  42623. const int newTopIndent)
  42624. {
  42625. leftIndent = newLeftIndent;
  42626. topIndent = newTopIndent;
  42627. }
  42628. void TextEditor::setBorder (const BorderSize& border)
  42629. {
  42630. borderSize = border;
  42631. resized();
  42632. }
  42633. const BorderSize TextEditor::getBorder() const
  42634. {
  42635. return borderSize;
  42636. }
  42637. void TextEditor::setScrollToShowCursor (const bool shouldScrollToShowCursor)
  42638. {
  42639. keepCursorOnScreen = shouldScrollToShowCursor;
  42640. }
  42641. void TextEditor::updateCaretPosition()
  42642. {
  42643. cursorHeight = currentFont.getHeight(); // (in case the text is empty and the call below doesn't set this value)
  42644. getCharPosition (caretPosition, cursorX, cursorY, cursorHeight);
  42645. }
  42646. void TextEditor::scrollToMakeSureCursorIsVisible()
  42647. {
  42648. updateCaretPosition();
  42649. if (keepCursorOnScreen)
  42650. {
  42651. int x = viewport->getViewPositionX();
  42652. int y = viewport->getViewPositionY();
  42653. const int relativeCursorX = roundToInt (cursorX) - x;
  42654. const int relativeCursorY = roundToInt (cursorY) - y;
  42655. if (relativeCursorX < jmax (1, proportionOfWidth (0.05f)))
  42656. {
  42657. x += relativeCursorX - proportionOfWidth (0.2f);
  42658. }
  42659. else if (relativeCursorX > jmax (0, viewport->getMaximumVisibleWidth() - (wordWrap ? 2 : 10)))
  42660. {
  42661. x += relativeCursorX + (isMultiLine() ? proportionOfWidth (0.2f) : 10) - viewport->getMaximumVisibleWidth();
  42662. }
  42663. x = jlimit (0, jmax (0, textHolder->getWidth() + 8 - viewport->getMaximumVisibleWidth()), x);
  42664. if (! isMultiLine())
  42665. {
  42666. y = (getHeight() - textHolder->getHeight() - topIndent) / -2;
  42667. }
  42668. else
  42669. {
  42670. const int curH = roundToInt (cursorHeight);
  42671. if (relativeCursorY < 0)
  42672. {
  42673. y = jmax (0, relativeCursorY + y);
  42674. }
  42675. else if (relativeCursorY > jmax (0, viewport->getMaximumVisibleHeight() - topIndent - curH))
  42676. {
  42677. y += relativeCursorY + 2 + curH + topIndent - viewport->getMaximumVisibleHeight();
  42678. }
  42679. }
  42680. viewport->setViewPosition (x, y);
  42681. }
  42682. }
  42683. void TextEditor::moveCursorTo (const int newPosition,
  42684. const bool isSelecting)
  42685. {
  42686. if (isSelecting)
  42687. {
  42688. moveCaret (newPosition);
  42689. const Range<int> oldSelection (selection);
  42690. if (dragType == notDragging)
  42691. {
  42692. if (abs (getCaretPosition() - selection.getStart()) < abs (getCaretPosition() - selection.getEnd()))
  42693. dragType = draggingSelectionStart;
  42694. else
  42695. dragType = draggingSelectionEnd;
  42696. }
  42697. if (dragType == draggingSelectionStart)
  42698. {
  42699. if (getCaretPosition() >= selection.getEnd())
  42700. dragType = draggingSelectionEnd;
  42701. selection = Range<int>::between (getCaretPosition(), selection.getEnd());
  42702. }
  42703. else
  42704. {
  42705. if (getCaretPosition() < selection.getStart())
  42706. dragType = draggingSelectionStart;
  42707. selection = Range<int>::between (getCaretPosition(), selection.getStart());
  42708. }
  42709. repaintText (selection.getUnionWith (oldSelection));
  42710. }
  42711. else
  42712. {
  42713. dragType = notDragging;
  42714. repaintText (selection);
  42715. moveCaret (newPosition);
  42716. selection = Range<int>::emptyRange (getCaretPosition());
  42717. }
  42718. }
  42719. int TextEditor::getTextIndexAt (const int x,
  42720. const int y)
  42721. {
  42722. return indexAtPosition ((float) (x + viewport->getViewPositionX() - leftIndent),
  42723. (float) (y + viewport->getViewPositionY() - topIndent));
  42724. }
  42725. void TextEditor::insertTextAtCaret (const String& newText_)
  42726. {
  42727. String newText (newText_);
  42728. if (allowedCharacters.isNotEmpty())
  42729. newText = newText.retainCharacters (allowedCharacters);
  42730. if (! isMultiLine())
  42731. newText = newText.replaceCharacters (T("\r\n"), T(" "));
  42732. else
  42733. newText = newText.replace (T("\r\n"), T("\n"));
  42734. const int newCaretPos = selection.getStart() + newText.length();
  42735. const int insertIndex = selection.getStart();
  42736. remove (selection, &undoManager,
  42737. newText.isNotEmpty() ? newCaretPos - 1 : newCaretPos);
  42738. if (maxTextLength > 0)
  42739. newText = newText.substring (0, maxTextLength - getTotalNumChars());
  42740. if (newText.isNotEmpty())
  42741. insert (newText,
  42742. insertIndex,
  42743. currentFont,
  42744. findColour (textColourId),
  42745. &undoManager,
  42746. newCaretPos);
  42747. textChanged();
  42748. }
  42749. void TextEditor::setHighlightedRegion (const Range<int>& newSelection)
  42750. {
  42751. moveCursorTo (newSelection.getStart(), false);
  42752. moveCursorTo (newSelection.getEnd(), true);
  42753. }
  42754. void TextEditor::copy()
  42755. {
  42756. if (passwordCharacter == 0)
  42757. {
  42758. const String selection (getHighlightedText());
  42759. if (selection.isNotEmpty())
  42760. SystemClipboard::copyTextToClipboard (selection);
  42761. }
  42762. }
  42763. void TextEditor::paste()
  42764. {
  42765. if (! isReadOnly())
  42766. {
  42767. const String clip (SystemClipboard::getTextFromClipboard());
  42768. if (clip.isNotEmpty())
  42769. insertTextAtCaret (clip);
  42770. }
  42771. }
  42772. void TextEditor::cut()
  42773. {
  42774. if (! isReadOnly())
  42775. {
  42776. moveCaret (selection.getEnd());
  42777. insertTextAtCaret (String::empty);
  42778. }
  42779. }
  42780. void TextEditor::drawContent (Graphics& g)
  42781. {
  42782. const float wordWrapWidth = getWordWrapWidth();
  42783. if (wordWrapWidth > 0)
  42784. {
  42785. g.setOrigin (leftIndent, topIndent);
  42786. const Rectangle<int> clip (g.getClipBounds());
  42787. Colour selectedTextColour;
  42788. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  42789. while (i.lineY + 200.0 < clip.getY() && i.next())
  42790. {}
  42791. if (! selection.isEmpty())
  42792. {
  42793. g.setColour (findColour (highlightColourId)
  42794. .withMultipliedAlpha (hasKeyboardFocus (true) ? 1.0f : 0.5f));
  42795. selectedTextColour = findColour (highlightedTextColourId);
  42796. TextEditorIterator i2 (i);
  42797. while (i2.next() && i2.lineY < clip.getBottom())
  42798. {
  42799. if (i2.lineY + i2.lineHeight >= clip.getY()
  42800. && selection.intersects (Range<int> (i2.indexInText, i2.indexInText + i2.atom->numChars)))
  42801. {
  42802. i2.drawSelection (g, selection);
  42803. }
  42804. }
  42805. }
  42806. const UniformTextSection* lastSection = 0;
  42807. while (i.next() && i.lineY < clip.getBottom())
  42808. {
  42809. if (i.lineY + i.lineHeight >= clip.getY())
  42810. {
  42811. if (selection.intersects (Range<int> (i.indexInText, i.indexInText + i.atom->numChars)))
  42812. {
  42813. i.drawSelectedText (g, selection, selectedTextColour);
  42814. lastSection = 0;
  42815. }
  42816. else
  42817. {
  42818. i.draw (g, lastSection);
  42819. }
  42820. }
  42821. }
  42822. }
  42823. }
  42824. void TextEditor::paint (Graphics& g)
  42825. {
  42826. getLookAndFeel().fillTextEditorBackground (g, getWidth(), getHeight(), *this);
  42827. }
  42828. void TextEditor::paintOverChildren (Graphics& g)
  42829. {
  42830. if (caretFlashState
  42831. && hasKeyboardFocus (false)
  42832. && caretVisible
  42833. && ! isReadOnly())
  42834. {
  42835. g.setColour (findColour (caretColourId));
  42836. g.fillRect (borderSize.getLeft() + textHolder->getX() + leftIndent + cursorX,
  42837. borderSize.getTop() + textHolder->getY() + topIndent + cursorY,
  42838. 2.0f, cursorHeight);
  42839. }
  42840. if (textToShowWhenEmpty.isNotEmpty()
  42841. && (! hasKeyboardFocus (false))
  42842. && getTotalNumChars() == 0)
  42843. {
  42844. g.setColour (colourForTextWhenEmpty);
  42845. g.setFont (getFont());
  42846. if (isMultiLine())
  42847. {
  42848. g.drawText (textToShowWhenEmpty,
  42849. 0, 0, getWidth(), getHeight(),
  42850. Justification::centred, true);
  42851. }
  42852. else
  42853. {
  42854. g.drawText (textToShowWhenEmpty,
  42855. leftIndent, topIndent,
  42856. viewport->getWidth() - leftIndent,
  42857. viewport->getHeight() - topIndent,
  42858. Justification::centredLeft, true);
  42859. }
  42860. }
  42861. getLookAndFeel().drawTextEditorOutline (g, getWidth(), getHeight(), *this);
  42862. }
  42863. void TextEditor::mouseDown (const MouseEvent& e)
  42864. {
  42865. beginDragAutoRepeat (100);
  42866. newTransaction();
  42867. if (wasFocused || ! selectAllTextWhenFocused)
  42868. {
  42869. if (! (popupMenuEnabled && e.mods.isPopupMenu()))
  42870. {
  42871. moveCursorTo (getTextIndexAt (e.x, e.y),
  42872. e.mods.isShiftDown());
  42873. }
  42874. else
  42875. {
  42876. PopupMenu m;
  42877. m.setLookAndFeel (&getLookAndFeel());
  42878. addPopupMenuItems (m, &e);
  42879. menuActive = true;
  42880. const int result = m.show();
  42881. menuActive = false;
  42882. if (result != 0)
  42883. performPopupMenuAction (result);
  42884. }
  42885. }
  42886. }
  42887. void TextEditor::mouseDrag (const MouseEvent& e)
  42888. {
  42889. if (wasFocused || ! selectAllTextWhenFocused)
  42890. {
  42891. if (! (popupMenuEnabled && e.mods.isPopupMenu()))
  42892. {
  42893. moveCursorTo (getTextIndexAt (e.x, e.y), true);
  42894. }
  42895. }
  42896. }
  42897. void TextEditor::mouseUp (const MouseEvent& e)
  42898. {
  42899. newTransaction();
  42900. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  42901. if (wasFocused || ! selectAllTextWhenFocused)
  42902. {
  42903. if (e.mouseWasClicked() && ! (popupMenuEnabled && e.mods.isPopupMenu()))
  42904. {
  42905. moveCaret (getTextIndexAt (e.x, e.y));
  42906. }
  42907. }
  42908. wasFocused = true;
  42909. }
  42910. void TextEditor::mouseDoubleClick (const MouseEvent& e)
  42911. {
  42912. int tokenEnd = getTextIndexAt (e.x, e.y);
  42913. int tokenStart = tokenEnd;
  42914. if (e.getNumberOfClicks() > 3)
  42915. {
  42916. tokenStart = 0;
  42917. tokenEnd = getTotalNumChars();
  42918. }
  42919. else
  42920. {
  42921. const String t (getText());
  42922. const int totalLength = getTotalNumChars();
  42923. while (tokenEnd < totalLength)
  42924. {
  42925. if (CharacterFunctions::isLetterOrDigit (t [tokenEnd]))
  42926. ++tokenEnd;
  42927. else
  42928. break;
  42929. }
  42930. tokenStart = tokenEnd;
  42931. while (tokenStart > 0)
  42932. {
  42933. if (CharacterFunctions::isLetterOrDigit (t [tokenStart - 1]))
  42934. --tokenStart;
  42935. else
  42936. break;
  42937. }
  42938. if (e.getNumberOfClicks() > 2)
  42939. {
  42940. while (tokenEnd < totalLength)
  42941. {
  42942. if (t [tokenEnd] != T('\r') && t [tokenEnd] != T('\n'))
  42943. ++tokenEnd;
  42944. else
  42945. break;
  42946. }
  42947. while (tokenStart > 0)
  42948. {
  42949. if (t [tokenStart - 1] != T('\r') && t [tokenStart - 1] != T('\n'))
  42950. --tokenStart;
  42951. else
  42952. break;
  42953. }
  42954. }
  42955. }
  42956. moveCursorTo (tokenEnd, false);
  42957. moveCursorTo (tokenStart, true);
  42958. }
  42959. void TextEditor::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  42960. {
  42961. if (! viewport->useMouseWheelMoveIfNeeded (e, wheelIncrementX, wheelIncrementY))
  42962. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  42963. }
  42964. bool TextEditor::keyPressed (const KeyPress& key)
  42965. {
  42966. if (isReadOnly() && key != KeyPress (T('c'), ModifierKeys::commandModifier, 0))
  42967. return false;
  42968. const bool moveInWholeWordSteps = key.getModifiers().isCtrlDown() || key.getModifiers().isAltDown();
  42969. if (key.isKeyCode (KeyPress::leftKey)
  42970. || key.isKeyCode (KeyPress::upKey))
  42971. {
  42972. newTransaction();
  42973. int newPos;
  42974. if (isMultiLine() && key.isKeyCode (KeyPress::upKey))
  42975. newPos = indexAtPosition (cursorX, cursorY - 1);
  42976. else if (moveInWholeWordSteps)
  42977. newPos = findWordBreakBefore (getCaretPosition());
  42978. else
  42979. newPos = getCaretPosition() - 1;
  42980. moveCursorTo (newPos, key.getModifiers().isShiftDown());
  42981. }
  42982. else if (key.isKeyCode (KeyPress::rightKey)
  42983. || key.isKeyCode (KeyPress::downKey))
  42984. {
  42985. newTransaction();
  42986. int newPos;
  42987. if (isMultiLine() && key.isKeyCode (KeyPress::downKey))
  42988. newPos = indexAtPosition (cursorX, cursorY + cursorHeight + 1);
  42989. else if (moveInWholeWordSteps)
  42990. newPos = findWordBreakAfter (getCaretPosition());
  42991. else
  42992. newPos = getCaretPosition() + 1;
  42993. moveCursorTo (newPos, key.getModifiers().isShiftDown());
  42994. }
  42995. else if (key.isKeyCode (KeyPress::pageDownKey) && isMultiLine())
  42996. {
  42997. newTransaction();
  42998. moveCursorTo (indexAtPosition (cursorX, cursorY + cursorHeight + viewport->getViewHeight()),
  42999. key.getModifiers().isShiftDown());
  43000. }
  43001. else if (key.isKeyCode (KeyPress::pageUpKey) && isMultiLine())
  43002. {
  43003. newTransaction();
  43004. moveCursorTo (indexAtPosition (cursorX, cursorY - viewport->getViewHeight()),
  43005. key.getModifiers().isShiftDown());
  43006. }
  43007. else if (key.isKeyCode (KeyPress::homeKey))
  43008. {
  43009. newTransaction();
  43010. if (isMultiLine() && ! moveInWholeWordSteps)
  43011. moveCursorTo (indexAtPosition (0.0f, cursorY),
  43012. key.getModifiers().isShiftDown());
  43013. else
  43014. moveCursorTo (0, key.getModifiers().isShiftDown());
  43015. }
  43016. else if (key.isKeyCode (KeyPress::endKey))
  43017. {
  43018. newTransaction();
  43019. if (isMultiLine() && ! moveInWholeWordSteps)
  43020. moveCursorTo (indexAtPosition ((float) textHolder->getWidth(), cursorY),
  43021. key.getModifiers().isShiftDown());
  43022. else
  43023. moveCursorTo (getTotalNumChars(), key.getModifiers().isShiftDown());
  43024. }
  43025. else if (key.isKeyCode (KeyPress::backspaceKey))
  43026. {
  43027. if (moveInWholeWordSteps)
  43028. {
  43029. moveCursorTo (findWordBreakBefore (getCaretPosition()), true);
  43030. }
  43031. else
  43032. {
  43033. if (selection.isEmpty() && selection.getStart() > 0)
  43034. selection.setStart (selection.getEnd() - 1);
  43035. }
  43036. cut();
  43037. }
  43038. else if (key.isKeyCode (KeyPress::deleteKey))
  43039. {
  43040. if (key.getModifiers().isShiftDown())
  43041. copy();
  43042. if (selection.isEmpty() && selection.getStart() < getTotalNumChars())
  43043. selection.setEnd (selection.getStart() + 1);
  43044. cut();
  43045. }
  43046. else if (key == KeyPress (T('c'), ModifierKeys::commandModifier, 0)
  43047. || key == KeyPress (KeyPress::insertKey, ModifierKeys::ctrlModifier, 0))
  43048. {
  43049. newTransaction();
  43050. copy();
  43051. }
  43052. else if (key == KeyPress (T('x'), ModifierKeys::commandModifier, 0))
  43053. {
  43054. newTransaction();
  43055. copy();
  43056. cut();
  43057. }
  43058. else if (key == KeyPress (T('v'), ModifierKeys::commandModifier, 0)
  43059. || key == KeyPress (KeyPress::insertKey, ModifierKeys::shiftModifier, 0))
  43060. {
  43061. newTransaction();
  43062. paste();
  43063. }
  43064. else if (key == KeyPress (T('z'), ModifierKeys::commandModifier, 0))
  43065. {
  43066. newTransaction();
  43067. doUndoRedo (false);
  43068. }
  43069. else if (key == KeyPress (T('y'), ModifierKeys::commandModifier, 0))
  43070. {
  43071. newTransaction();
  43072. doUndoRedo (true);
  43073. }
  43074. else if (key == KeyPress (T('a'), ModifierKeys::commandModifier, 0))
  43075. {
  43076. newTransaction();
  43077. moveCursorTo (getTotalNumChars(), false);
  43078. moveCursorTo (0, true);
  43079. }
  43080. else if (key == KeyPress::returnKey)
  43081. {
  43082. newTransaction();
  43083. if (returnKeyStartsNewLine)
  43084. insertTextAtCaret (T("\n"));
  43085. else
  43086. returnPressed();
  43087. }
  43088. else if (key.isKeyCode (KeyPress::escapeKey))
  43089. {
  43090. newTransaction();
  43091. moveCursorTo (getCaretPosition(), false);
  43092. escapePressed();
  43093. }
  43094. else if (key.getTextCharacter() >= ' '
  43095. || (tabKeyUsed && (key.getTextCharacter() == '\t')))
  43096. {
  43097. insertTextAtCaret (String::charToString (key.getTextCharacter()));
  43098. lastTransactionTime = Time::getApproximateMillisecondCounter();
  43099. }
  43100. else
  43101. {
  43102. return false;
  43103. }
  43104. return true;
  43105. }
  43106. bool TextEditor::keyStateChanged (const bool isKeyDown)
  43107. {
  43108. if (! isKeyDown)
  43109. return false;
  43110. #if JUCE_WIN32
  43111. if (KeyPress (KeyPress::F4Key, ModifierKeys::altModifier, 0).isCurrentlyDown())
  43112. return false; // We need to explicitly allow alt-F4 to pass through on Windows
  43113. #endif
  43114. // (overridden to avoid forwarding key events to the parent)
  43115. return ! ModifierKeys::getCurrentModifiers().isCommandDown();
  43116. }
  43117. const int baseMenuItemID = 0x7fff0000;
  43118. void TextEditor::addPopupMenuItems (PopupMenu& m, const MouseEvent*)
  43119. {
  43120. const bool writable = ! isReadOnly();
  43121. if (passwordCharacter == 0)
  43122. {
  43123. m.addItem (baseMenuItemID + 1, TRANS("cut"), writable);
  43124. m.addItem (baseMenuItemID + 2, TRANS("copy"), ! selection.isEmpty());
  43125. m.addItem (baseMenuItemID + 3, TRANS("paste"), writable);
  43126. }
  43127. m.addItem (baseMenuItemID + 4, TRANS("delete"), writable);
  43128. m.addSeparator();
  43129. m.addItem (baseMenuItemID + 5, TRANS("select all"));
  43130. m.addSeparator();
  43131. m.addItem (baseMenuItemID + 6, TRANS("undo"), undoManager.canUndo());
  43132. m.addItem (baseMenuItemID + 7, TRANS("redo"), undoManager.canRedo());
  43133. }
  43134. void TextEditor::performPopupMenuAction (const int menuItemID)
  43135. {
  43136. switch (menuItemID)
  43137. {
  43138. case baseMenuItemID + 1:
  43139. copy();
  43140. cut();
  43141. break;
  43142. case baseMenuItemID + 2:
  43143. copy();
  43144. break;
  43145. case baseMenuItemID + 3:
  43146. paste();
  43147. break;
  43148. case baseMenuItemID + 4:
  43149. cut();
  43150. break;
  43151. case baseMenuItemID + 5:
  43152. moveCursorTo (getTotalNumChars(), false);
  43153. moveCursorTo (0, true);
  43154. break;
  43155. case baseMenuItemID + 6:
  43156. doUndoRedo (false);
  43157. break;
  43158. case baseMenuItemID + 7:
  43159. doUndoRedo (true);
  43160. break;
  43161. default:
  43162. break;
  43163. }
  43164. }
  43165. void TextEditor::focusGained (FocusChangeType)
  43166. {
  43167. newTransaction();
  43168. caretFlashState = true;
  43169. if (selectAllTextWhenFocused)
  43170. {
  43171. moveCursorTo (0, false);
  43172. moveCursorTo (getTotalNumChars(), true);
  43173. }
  43174. repaint();
  43175. if (caretVisible)
  43176. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  43177. ComponentPeer* const peer = getPeer();
  43178. if (peer != 0 && ! isReadOnly())
  43179. peer->textInputRequired (getScreenX() - peer->getScreenX(),
  43180. getScreenY() - peer->getScreenY());
  43181. }
  43182. void TextEditor::focusLost (FocusChangeType)
  43183. {
  43184. newTransaction();
  43185. wasFocused = false;
  43186. textHolder->stopTimer();
  43187. caretFlashState = false;
  43188. postCommandMessage (TextEditorDefs::focusLossMessageId);
  43189. repaint();
  43190. }
  43191. void TextEditor::resized()
  43192. {
  43193. viewport->setBoundsInset (borderSize);
  43194. viewport->setSingleStepSizes (16, roundToInt (currentFont.getHeight()));
  43195. updateTextHolderSize();
  43196. if (! isMultiLine())
  43197. {
  43198. scrollToMakeSureCursorIsVisible();
  43199. }
  43200. else
  43201. {
  43202. updateCaretPosition();
  43203. }
  43204. }
  43205. void TextEditor::handleCommandMessage (const int commandId)
  43206. {
  43207. const ComponentDeletionWatcher deletionChecker (this);
  43208. for (int i = listeners.size(); --i >= 0;)
  43209. {
  43210. TextEditorListener* const tl = (TextEditorListener*) listeners [i];
  43211. if (tl != 0)
  43212. {
  43213. switch (commandId)
  43214. {
  43215. case TextEditorDefs::textChangeMessageId:
  43216. tl->textEditorTextChanged (*this);
  43217. break;
  43218. case TextEditorDefs::returnKeyMessageId:
  43219. tl->textEditorReturnKeyPressed (*this);
  43220. break;
  43221. case TextEditorDefs::escapeKeyMessageId:
  43222. tl->textEditorEscapeKeyPressed (*this);
  43223. break;
  43224. case TextEditorDefs::focusLossMessageId:
  43225. tl->textEditorFocusLost (*this);
  43226. break;
  43227. default:
  43228. jassertfalse
  43229. break;
  43230. }
  43231. if (i > 0 && deletionChecker.hasBeenDeleted())
  43232. return;
  43233. }
  43234. }
  43235. }
  43236. void TextEditor::enablementChanged()
  43237. {
  43238. setMouseCursor (MouseCursor (isReadOnly() ? MouseCursor::NormalCursor
  43239. : MouseCursor::IBeamCursor));
  43240. repaint();
  43241. }
  43242. void TextEditor::clearInternal (UndoManager* const um)
  43243. {
  43244. remove (Range<int> (0, getTotalNumChars()), um, caretPosition);
  43245. }
  43246. void TextEditor::insert (const String& text,
  43247. const int insertIndex,
  43248. const Font& font,
  43249. const Colour& colour,
  43250. UndoManager* const um,
  43251. const int caretPositionToMoveTo)
  43252. {
  43253. if (text.isNotEmpty())
  43254. {
  43255. if (um != 0)
  43256. {
  43257. if (um->getNumActionsInCurrentTransaction() > TextEditorDefs::maxActionsPerTransaction)
  43258. newTransaction();
  43259. um->perform (new TextEditorInsertAction (*this,
  43260. text,
  43261. insertIndex,
  43262. font,
  43263. colour,
  43264. caretPosition,
  43265. caretPositionToMoveTo));
  43266. }
  43267. else
  43268. {
  43269. repaintText (Range<int> (insertIndex, getTotalNumChars())); // must do this before and after changing the data, in case
  43270. // a line gets moved due to word wrap
  43271. int index = 0;
  43272. int nextIndex = 0;
  43273. for (int i = 0; i < sections.size(); ++i)
  43274. {
  43275. nextIndex = index + ((UniformTextSection*) sections.getUnchecked(i))->getTotalLength();
  43276. if (insertIndex == index)
  43277. {
  43278. sections.insert (i, new UniformTextSection (text,
  43279. font, colour,
  43280. passwordCharacter));
  43281. break;
  43282. }
  43283. else if (insertIndex > index && insertIndex < nextIndex)
  43284. {
  43285. splitSection (i, insertIndex - index);
  43286. sections.insert (i + 1, new UniformTextSection (text,
  43287. font, colour,
  43288. passwordCharacter));
  43289. break;
  43290. }
  43291. index = nextIndex;
  43292. }
  43293. if (nextIndex == insertIndex)
  43294. sections.add (new UniformTextSection (text,
  43295. font, colour,
  43296. passwordCharacter));
  43297. coalesceSimilarSections();
  43298. totalNumChars = -1;
  43299. valueTextNeedsUpdating = true;
  43300. moveCursorTo (caretPositionToMoveTo, false);
  43301. repaintText (Range<int> (insertIndex, getTotalNumChars()));
  43302. }
  43303. }
  43304. }
  43305. void TextEditor::reinsert (const int insertIndex,
  43306. const VoidArray& sectionsToInsert)
  43307. {
  43308. int index = 0;
  43309. int nextIndex = 0;
  43310. for (int i = 0; i < sections.size(); ++i)
  43311. {
  43312. nextIndex = index + ((UniformTextSection*) sections.getUnchecked(i))->getTotalLength();
  43313. if (insertIndex == index)
  43314. {
  43315. for (int j = sectionsToInsert.size(); --j >= 0;)
  43316. sections.insert (i, new UniformTextSection (*(UniformTextSection*) sectionsToInsert.getUnchecked(j)));
  43317. break;
  43318. }
  43319. else if (insertIndex > index && insertIndex < nextIndex)
  43320. {
  43321. splitSection (i, insertIndex - index);
  43322. for (int j = sectionsToInsert.size(); --j >= 0;)
  43323. sections.insert (i + 1, new UniformTextSection (*(UniformTextSection*) sectionsToInsert.getUnchecked(j)));
  43324. break;
  43325. }
  43326. index = nextIndex;
  43327. }
  43328. if (nextIndex == insertIndex)
  43329. {
  43330. for (int j = 0; j < sectionsToInsert.size(); ++j)
  43331. sections.add (new UniformTextSection (*(UniformTextSection*) sectionsToInsert.getUnchecked(j)));
  43332. }
  43333. coalesceSimilarSections();
  43334. totalNumChars = -1;
  43335. valueTextNeedsUpdating = true;
  43336. }
  43337. void TextEditor::remove (const Range<int>& range,
  43338. UndoManager* const um,
  43339. const int caretPositionToMoveTo)
  43340. {
  43341. if (! range.isEmpty())
  43342. {
  43343. int index = 0;
  43344. for (int i = 0; i < sections.size(); ++i)
  43345. {
  43346. const int nextIndex = index + ((UniformTextSection*) sections[i])->getTotalLength();
  43347. if (range.getStart() > index && range.getStart() < nextIndex)
  43348. {
  43349. splitSection (i, range.getStart() - index);
  43350. --i;
  43351. }
  43352. else if (range.getEnd() > index && range.getEnd() < nextIndex)
  43353. {
  43354. splitSection (i, range.getEnd() - index);
  43355. --i;
  43356. }
  43357. else
  43358. {
  43359. index = nextIndex;
  43360. if (index > range.getEnd())
  43361. break;
  43362. }
  43363. }
  43364. index = 0;
  43365. if (um != 0)
  43366. {
  43367. VoidArray removedSections;
  43368. for (int i = 0; i < sections.size(); ++i)
  43369. {
  43370. if (range.getEnd() <= range.getStart())
  43371. break;
  43372. UniformTextSection* const section = (UniformTextSection*) sections.getUnchecked (i);
  43373. const int nextIndex = index + section->getTotalLength();
  43374. if (range.getStart() <= index && range.getEnd() >= nextIndex)
  43375. removedSections.add (new UniformTextSection (*section));
  43376. index = nextIndex;
  43377. }
  43378. if (um->getNumActionsInCurrentTransaction() > TextEditorDefs::maxActionsPerTransaction)
  43379. newTransaction();
  43380. um->perform (new TextEditorRemoveAction (*this,
  43381. range,
  43382. caretPosition,
  43383. caretPositionToMoveTo,
  43384. removedSections));
  43385. }
  43386. else
  43387. {
  43388. Range<int> remainingRange (range);
  43389. for (int i = 0; i < sections.size(); ++i)
  43390. {
  43391. UniformTextSection* const section = (UniformTextSection*) sections.getUnchecked (i);
  43392. const int nextIndex = index + section->getTotalLength();
  43393. if (remainingRange.getStart() <= index && remainingRange.getEnd() >= nextIndex)
  43394. {
  43395. sections.remove(i);
  43396. section->clear();
  43397. delete section;
  43398. remainingRange.setEnd (remainingRange.getEnd() - (nextIndex - index));
  43399. if (remainingRange.isEmpty())
  43400. break;
  43401. --i;
  43402. }
  43403. else
  43404. {
  43405. index = nextIndex;
  43406. }
  43407. }
  43408. coalesceSimilarSections();
  43409. totalNumChars = -1;
  43410. valueTextNeedsUpdating = true;
  43411. moveCursorTo (caretPositionToMoveTo, false);
  43412. repaintText (Range<int> (range.getStart(), getTotalNumChars()));
  43413. }
  43414. }
  43415. }
  43416. const String TextEditor::getText() const
  43417. {
  43418. String t;
  43419. t.preallocateStorage (getTotalNumChars());
  43420. String::Concatenator concatenator (t);
  43421. for (int i = 0; i < sections.size(); ++i)
  43422. ((const UniformTextSection*) sections.getUnchecked(i))->appendAllText (concatenator);
  43423. return t;
  43424. }
  43425. const String TextEditor::getTextInRange (const Range<int>& range) const
  43426. {
  43427. String t;
  43428. if (! range.isEmpty())
  43429. {
  43430. t.preallocateStorage (jmin (getTotalNumChars(), range.getLength()));
  43431. String::Concatenator concatenator (t);
  43432. int index = 0;
  43433. for (int i = 0; i < sections.size(); ++i)
  43434. {
  43435. const UniformTextSection* const s = (const UniformTextSection*) sections.getUnchecked(i);
  43436. const int nextIndex = index + s->getTotalLength();
  43437. if (range.getStart() < nextIndex)
  43438. {
  43439. if (range.getEnd() <= index)
  43440. break;
  43441. s->appendSubstring (concatenator, range - index);
  43442. }
  43443. index = nextIndex;
  43444. }
  43445. }
  43446. return t;
  43447. }
  43448. const String TextEditor::getHighlightedText() const
  43449. {
  43450. return getTextInRange (selection);
  43451. }
  43452. int TextEditor::getTotalNumChars() const
  43453. {
  43454. if (totalNumChars < 0)
  43455. {
  43456. totalNumChars = 0;
  43457. for (int i = sections.size(); --i >= 0;)
  43458. totalNumChars += ((const UniformTextSection*) sections.getUnchecked(i))->getTotalLength();
  43459. }
  43460. return totalNumChars;
  43461. }
  43462. bool TextEditor::isEmpty() const
  43463. {
  43464. return getTotalNumChars() == 0;
  43465. }
  43466. void TextEditor::getCharPosition (const int index, float& cx, float& cy, float& lineHeight) const
  43467. {
  43468. const float wordWrapWidth = getWordWrapWidth();
  43469. if (wordWrapWidth > 0 && sections.size() > 0)
  43470. {
  43471. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  43472. i.getCharPosition (index, cx, cy, lineHeight);
  43473. }
  43474. else
  43475. {
  43476. cx = cy = 0;
  43477. lineHeight = currentFont.getHeight();
  43478. }
  43479. }
  43480. int TextEditor::indexAtPosition (const float x, const float y)
  43481. {
  43482. const float wordWrapWidth = getWordWrapWidth();
  43483. if (wordWrapWidth > 0)
  43484. {
  43485. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  43486. while (i.next())
  43487. {
  43488. if (i.lineY + i.lineHeight > y)
  43489. {
  43490. if (i.lineY > y)
  43491. return jmax (0, i.indexInText - 1);
  43492. if (i.atomX >= x)
  43493. return i.indexInText;
  43494. if (x < i.atomRight)
  43495. return i.xToIndex (x);
  43496. }
  43497. }
  43498. }
  43499. return getTotalNumChars();
  43500. }
  43501. static int getCharacterCategory (const tchar character)
  43502. {
  43503. return CharacterFunctions::isLetterOrDigit (character)
  43504. ? 2 : (CharacterFunctions::isWhitespace (character) ? 0 : 1);
  43505. }
  43506. int TextEditor::findWordBreakAfter (const int position) const
  43507. {
  43508. const String t (getTextInRange (Range<int> (position, position + 512)));
  43509. const int totalLength = t.length();
  43510. int i = 0;
  43511. while (i < totalLength && CharacterFunctions::isWhitespace (t[i]))
  43512. ++i;
  43513. const int type = getCharacterCategory (t[i]);
  43514. while (i < totalLength && type == getCharacterCategory (t[i]))
  43515. ++i;
  43516. while (i < totalLength && CharacterFunctions::isWhitespace (t[i]))
  43517. ++i;
  43518. return position + i;
  43519. }
  43520. int TextEditor::findWordBreakBefore (const int position) const
  43521. {
  43522. if (position <= 0)
  43523. return 0;
  43524. const int startOfBuffer = jmax (0, position - 512);
  43525. const String t (getTextInRange (Range<int> (startOfBuffer, position)));
  43526. int i = position - startOfBuffer;
  43527. while (i > 0 && CharacterFunctions::isWhitespace (t [i - 1]))
  43528. --i;
  43529. if (i > 0)
  43530. {
  43531. const int type = getCharacterCategory (t [i - 1]);
  43532. while (i > 0 && type == getCharacterCategory (t [i - 1]))
  43533. --i;
  43534. }
  43535. jassert (startOfBuffer + i >= 0);
  43536. return startOfBuffer + i;
  43537. }
  43538. void TextEditor::splitSection (const int sectionIndex,
  43539. const int charToSplitAt)
  43540. {
  43541. jassert (sections[sectionIndex] != 0);
  43542. sections.insert (sectionIndex + 1,
  43543. ((UniformTextSection*) sections.getUnchecked (sectionIndex))
  43544. ->split (charToSplitAt, passwordCharacter));
  43545. }
  43546. void TextEditor::coalesceSimilarSections()
  43547. {
  43548. for (int i = 0; i < sections.size() - 1; ++i)
  43549. {
  43550. UniformTextSection* const s1 = (UniformTextSection*) sections.getUnchecked (i);
  43551. UniformTextSection* const s2 = (UniformTextSection*) sections.getUnchecked (i + 1);
  43552. if (s1->font == s2->font
  43553. && s1->colour == s2->colour)
  43554. {
  43555. s1->append (*s2, passwordCharacter);
  43556. sections.remove (i + 1);
  43557. delete s2;
  43558. --i;
  43559. }
  43560. }
  43561. }
  43562. END_JUCE_NAMESPACE
  43563. /*** End of inlined file: juce_TextEditor.cpp ***/
  43564. /*** Start of inlined file: juce_Toolbar.cpp ***/
  43565. BEGIN_JUCE_NAMESPACE
  43566. const tchar* const Toolbar::toolbarDragDescriptor = T("_toolbarItem_");
  43567. class ToolbarSpacerComp : public ToolbarItemComponent
  43568. {
  43569. public:
  43570. ToolbarSpacerComp (const int itemId_, const float fixedSize_, const bool drawBar_)
  43571. : ToolbarItemComponent (itemId_, String::empty, false),
  43572. fixedSize (fixedSize_),
  43573. drawBar (drawBar_)
  43574. {
  43575. }
  43576. ~ToolbarSpacerComp()
  43577. {
  43578. }
  43579. bool getToolbarItemSizes (int toolbarThickness, bool /*isToolbarVertical*/,
  43580. int& preferredSize, int& minSize, int& maxSize)
  43581. {
  43582. if (fixedSize <= 0)
  43583. {
  43584. preferredSize = toolbarThickness * 2;
  43585. minSize = 4;
  43586. maxSize = 32768;
  43587. }
  43588. else
  43589. {
  43590. maxSize = roundToInt (toolbarThickness * fixedSize);
  43591. minSize = drawBar ? maxSize : jmin (4, maxSize);
  43592. preferredSize = maxSize;
  43593. if (getEditingMode() == editableOnPalette)
  43594. preferredSize = maxSize = toolbarThickness / (drawBar ? 3 : 2);
  43595. }
  43596. return true;
  43597. }
  43598. void paintButtonArea (Graphics&, int, int, bool, bool)
  43599. {
  43600. }
  43601. void contentAreaChanged (const Rectangle<int>&)
  43602. {
  43603. }
  43604. int getResizeOrder() const throw()
  43605. {
  43606. return fixedSize <= 0 ? 0 : 1;
  43607. }
  43608. void paint (Graphics& g)
  43609. {
  43610. const int w = getWidth();
  43611. const int h = getHeight();
  43612. if (drawBar)
  43613. {
  43614. g.setColour (findColour (Toolbar::separatorColourId, true));
  43615. const float thickness = 0.2f;
  43616. if (isToolbarVertical())
  43617. g.fillRect (w * 0.1f, h * (0.5f - thickness * 0.5f), w * 0.8f, h * thickness);
  43618. else
  43619. g.fillRect (w * (0.5f - thickness * 0.5f), h * 0.1f, w * thickness, h * 0.8f);
  43620. }
  43621. if (getEditingMode() != normalMode && ! drawBar)
  43622. {
  43623. g.setColour (findColour (Toolbar::separatorColourId, true));
  43624. const int indentX = jmin (2, (w - 3) / 2);
  43625. const int indentY = jmin (2, (h - 3) / 2);
  43626. g.drawRect (indentX, indentY, w - indentX * 2, h - indentY * 2, 1);
  43627. if (fixedSize <= 0)
  43628. {
  43629. float x1, y1, x2, y2, x3, y3, x4, y4, hw, hl;
  43630. if (isToolbarVertical())
  43631. {
  43632. x1 = w * 0.5f;
  43633. y1 = h * 0.4f;
  43634. x2 = x1;
  43635. y2 = indentX * 2.0f;
  43636. x3 = x1;
  43637. y3 = h * 0.6f;
  43638. x4 = x1;
  43639. y4 = h - y2;
  43640. hw = w * 0.15f;
  43641. hl = w * 0.2f;
  43642. }
  43643. else
  43644. {
  43645. x1 = w * 0.4f;
  43646. y1 = h * 0.5f;
  43647. x2 = indentX * 2.0f;
  43648. y2 = y1;
  43649. x3 = w * 0.6f;
  43650. y3 = y1;
  43651. x4 = w - x2;
  43652. y4 = y1;
  43653. hw = h * 0.15f;
  43654. hl = h * 0.2f;
  43655. }
  43656. Path p;
  43657. p.addArrow (x1, y1, x2, y2, 1.5f, hw, hl);
  43658. p.addArrow (x3, y3, x4, y4, 1.5f, hw, hl);
  43659. g.fillPath (p);
  43660. }
  43661. }
  43662. }
  43663. juce_UseDebuggingNewOperator
  43664. private:
  43665. const float fixedSize;
  43666. const bool drawBar;
  43667. ToolbarSpacerComp (const ToolbarSpacerComp&);
  43668. const ToolbarSpacerComp& operator= (const ToolbarSpacerComp&);
  43669. };
  43670. class MissingItemsComponent : public PopupMenuCustomComponent
  43671. {
  43672. public:
  43673. MissingItemsComponent (Toolbar& owner_, const int height_)
  43674. : PopupMenuCustomComponent (true),
  43675. owner (owner_),
  43676. height (height_)
  43677. {
  43678. for (int i = owner_.items.size(); --i >= 0;)
  43679. {
  43680. ToolbarItemComponent* const tc = owner_.items.getUnchecked(i);
  43681. if (dynamic_cast <ToolbarSpacerComp*> (tc) == 0 && ! tc->isVisible())
  43682. {
  43683. oldIndexes.insert (0, i);
  43684. addAndMakeVisible (tc, 0);
  43685. }
  43686. }
  43687. layout (400);
  43688. }
  43689. ~MissingItemsComponent()
  43690. {
  43691. // deleting the toolbar while its menu it open??
  43692. jassert (owner.isValidComponent());
  43693. for (int i = 0; i < getNumChildComponents(); ++i)
  43694. {
  43695. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getChildComponent (i));
  43696. if (tc != 0)
  43697. {
  43698. tc->setVisible (false);
  43699. const int index = oldIndexes.remove (i);
  43700. owner.addChildComponent (tc, index);
  43701. --i;
  43702. }
  43703. }
  43704. owner.resized();
  43705. }
  43706. void layout (const int preferredWidth)
  43707. {
  43708. const int indent = 8;
  43709. int x = indent;
  43710. int y = indent;
  43711. int maxX = 0;
  43712. for (int i = 0; i < getNumChildComponents(); ++i)
  43713. {
  43714. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getChildComponent (i));
  43715. if (tc != 0)
  43716. {
  43717. int preferredSize = 1, minSize = 1, maxSize = 1;
  43718. if (tc->getToolbarItemSizes (height, false, preferredSize, minSize, maxSize))
  43719. {
  43720. if (x + preferredSize > preferredWidth && x > indent)
  43721. {
  43722. x = indent;
  43723. y += height;
  43724. }
  43725. tc->setBounds (x, y, preferredSize, height);
  43726. x += preferredSize;
  43727. maxX = jmax (maxX, x);
  43728. }
  43729. }
  43730. }
  43731. setSize (maxX + 8, y + height + 8);
  43732. }
  43733. void getIdealSize (int& idealWidth, int& idealHeight)
  43734. {
  43735. idealWidth = getWidth();
  43736. idealHeight = getHeight();
  43737. }
  43738. juce_UseDebuggingNewOperator
  43739. private:
  43740. Toolbar& owner;
  43741. const int height;
  43742. Array <int> oldIndexes;
  43743. MissingItemsComponent (const MissingItemsComponent&);
  43744. const MissingItemsComponent& operator= (const MissingItemsComponent&);
  43745. };
  43746. Toolbar::Toolbar()
  43747. : vertical (false),
  43748. isEditingActive (false),
  43749. toolbarStyle (Toolbar::iconsOnly)
  43750. {
  43751. addChildComponent (missingItemsButton = getLookAndFeel().createToolbarMissingItemsButton (*this));
  43752. missingItemsButton->setAlwaysOnTop (true);
  43753. missingItemsButton->addButtonListener (this);
  43754. }
  43755. Toolbar::~Toolbar()
  43756. {
  43757. animator.cancelAllAnimations (true);
  43758. deleteAllChildren();
  43759. }
  43760. void Toolbar::setVertical (const bool shouldBeVertical)
  43761. {
  43762. if (vertical != shouldBeVertical)
  43763. {
  43764. vertical = shouldBeVertical;
  43765. resized();
  43766. }
  43767. }
  43768. void Toolbar::clear()
  43769. {
  43770. for (int i = items.size(); --i >= 0;)
  43771. {
  43772. ToolbarItemComponent* const tc = items.getUnchecked(i);
  43773. items.remove (i);
  43774. delete tc;
  43775. }
  43776. resized();
  43777. }
  43778. ToolbarItemComponent* Toolbar::createItem (ToolbarItemFactory& factory, const int itemId)
  43779. {
  43780. if (itemId == ToolbarItemFactory::separatorBarId)
  43781. return new ToolbarSpacerComp (itemId, 0.1f, true);
  43782. else if (itemId == ToolbarItemFactory::spacerId)
  43783. return new ToolbarSpacerComp (itemId, 0.5f, false);
  43784. else if (itemId == ToolbarItemFactory::flexibleSpacerId)
  43785. return new ToolbarSpacerComp (itemId, 0, false);
  43786. return factory.createItem (itemId);
  43787. }
  43788. void Toolbar::addItemInternal (ToolbarItemFactory& factory,
  43789. const int itemId,
  43790. const int insertIndex)
  43791. {
  43792. // An ID can't be zero - this might indicate a mistake somewhere?
  43793. jassert (itemId != 0);
  43794. ToolbarItemComponent* const tc = createItem (factory, itemId);
  43795. if (tc != 0)
  43796. {
  43797. #ifdef JUCE_DEBUG
  43798. Array <int> allowedIds;
  43799. factory.getAllToolbarItemIds (allowedIds);
  43800. // If your factory can create an item for a given ID, it must also return
  43801. // that ID from its getAllToolbarItemIds() method!
  43802. jassert (allowedIds.contains (itemId));
  43803. #endif
  43804. items.insert (insertIndex, tc);
  43805. addAndMakeVisible (tc, insertIndex);
  43806. }
  43807. }
  43808. void Toolbar::addItem (ToolbarItemFactory& factory,
  43809. const int itemId,
  43810. const int insertIndex)
  43811. {
  43812. addItemInternal (factory, itemId, insertIndex);
  43813. resized();
  43814. }
  43815. void Toolbar::addDefaultItems (ToolbarItemFactory& factoryToUse)
  43816. {
  43817. Array <int> ids;
  43818. factoryToUse.getDefaultItemSet (ids);
  43819. clear();
  43820. for (int i = 0; i < ids.size(); ++i)
  43821. addItemInternal (factoryToUse, ids.getUnchecked (i), -1);
  43822. resized();
  43823. }
  43824. void Toolbar::removeToolbarItem (const int itemIndex)
  43825. {
  43826. ToolbarItemComponent* const tc = getItemComponent (itemIndex);
  43827. if (tc != 0)
  43828. {
  43829. items.removeValue (tc);
  43830. delete tc;
  43831. resized();
  43832. }
  43833. }
  43834. int Toolbar::getNumItems() const throw()
  43835. {
  43836. return items.size();
  43837. }
  43838. int Toolbar::getItemId (const int itemIndex) const throw()
  43839. {
  43840. ToolbarItemComponent* const tc = getItemComponent (itemIndex);
  43841. return tc != 0 ? tc->getItemId() : 0;
  43842. }
  43843. ToolbarItemComponent* Toolbar::getItemComponent (const int itemIndex) const throw()
  43844. {
  43845. return items [itemIndex];
  43846. }
  43847. ToolbarItemComponent* Toolbar::getNextActiveComponent (int index, const int delta) const
  43848. {
  43849. for (;;)
  43850. {
  43851. index += delta;
  43852. ToolbarItemComponent* const tc = getItemComponent (index);
  43853. if (tc == 0)
  43854. break;
  43855. if (tc->isActive)
  43856. return tc;
  43857. }
  43858. return 0;
  43859. }
  43860. void Toolbar::setStyle (const ToolbarItemStyle& newStyle)
  43861. {
  43862. if (toolbarStyle != newStyle)
  43863. {
  43864. toolbarStyle = newStyle;
  43865. updateAllItemPositions (false);
  43866. }
  43867. }
  43868. const String Toolbar::toString() const
  43869. {
  43870. String s (T("TB:"));
  43871. for (int i = 0; i < getNumItems(); ++i)
  43872. s << getItemId(i) << T(' ');
  43873. return s.trimEnd();
  43874. }
  43875. bool Toolbar::restoreFromString (ToolbarItemFactory& factoryToUse,
  43876. const String& savedVersion)
  43877. {
  43878. if (! savedVersion.startsWith (T("TB:")))
  43879. return false;
  43880. StringArray tokens;
  43881. tokens.addTokens (savedVersion.substring (3), false);
  43882. clear();
  43883. for (int i = 0; i < tokens.size(); ++i)
  43884. addItemInternal (factoryToUse, tokens[i].getIntValue(), -1);
  43885. resized();
  43886. return true;
  43887. }
  43888. void Toolbar::paint (Graphics& g)
  43889. {
  43890. getLookAndFeel().paintToolbarBackground (g, getWidth(), getHeight(), *this);
  43891. }
  43892. int Toolbar::getThickness() const throw()
  43893. {
  43894. return vertical ? getWidth() : getHeight();
  43895. }
  43896. int Toolbar::getLength() const throw()
  43897. {
  43898. return vertical ? getHeight() : getWidth();
  43899. }
  43900. void Toolbar::setEditingActive (const bool active)
  43901. {
  43902. if (isEditingActive != active)
  43903. {
  43904. isEditingActive = active;
  43905. updateAllItemPositions (false);
  43906. }
  43907. }
  43908. void Toolbar::resized()
  43909. {
  43910. updateAllItemPositions (false);
  43911. }
  43912. void Toolbar::updateAllItemPositions (const bool animate)
  43913. {
  43914. if (getWidth() > 0 && getHeight() > 0)
  43915. {
  43916. StretchableObjectResizer resizer;
  43917. int i;
  43918. for (i = 0; i < items.size(); ++i)
  43919. {
  43920. ToolbarItemComponent* const tc = items.getUnchecked(i);
  43921. tc->setEditingMode (isEditingActive ? ToolbarItemComponent::editableOnToolbar
  43922. : ToolbarItemComponent::normalMode);
  43923. tc->setStyle (toolbarStyle);
  43924. ToolbarSpacerComp* const spacer = dynamic_cast <ToolbarSpacerComp*> (tc);
  43925. int preferredSize = 1, minSize = 1, maxSize = 1;
  43926. if (tc->getToolbarItemSizes (getThickness(), isVertical(),
  43927. preferredSize, minSize, maxSize))
  43928. {
  43929. tc->isActive = true;
  43930. resizer.addItem (preferredSize, minSize, maxSize,
  43931. spacer != 0 ? spacer->getResizeOrder() : 2);
  43932. }
  43933. else
  43934. {
  43935. tc->isActive = false;
  43936. tc->setVisible (false);
  43937. }
  43938. }
  43939. resizer.resizeToFit (getLength());
  43940. int totalLength = 0;
  43941. for (i = 0; i < resizer.getNumItems(); ++i)
  43942. totalLength += (int) resizer.getItemSize (i);
  43943. const bool itemsOffTheEnd = totalLength > getLength();
  43944. const int extrasButtonSize = getThickness() / 2;
  43945. missingItemsButton->setSize (extrasButtonSize, extrasButtonSize);
  43946. missingItemsButton->setVisible (itemsOffTheEnd);
  43947. missingItemsButton->setEnabled (! isEditingActive);
  43948. if (vertical)
  43949. missingItemsButton->setCentrePosition (getWidth() / 2,
  43950. getHeight() - 4 - extrasButtonSize / 2);
  43951. else
  43952. missingItemsButton->setCentrePosition (getWidth() - 4 - extrasButtonSize / 2,
  43953. getHeight() / 2);
  43954. const int maxLength = itemsOffTheEnd ? (vertical ? missingItemsButton->getY()
  43955. : missingItemsButton->getX()) - 4
  43956. : getLength();
  43957. int pos = 0, activeIndex = 0;
  43958. for (i = 0; i < items.size(); ++i)
  43959. {
  43960. ToolbarItemComponent* const tc = items.getUnchecked(i);
  43961. if (tc->isActive)
  43962. {
  43963. const int size = (int) resizer.getItemSize (activeIndex++);
  43964. Rectangle<int> newBounds;
  43965. if (vertical)
  43966. newBounds.setBounds (0, pos, getWidth(), size);
  43967. else
  43968. newBounds.setBounds (pos, 0, size, getHeight());
  43969. if (animate)
  43970. {
  43971. animator.animateComponent (tc, newBounds, 200, 3.0, 0.0);
  43972. }
  43973. else
  43974. {
  43975. animator.cancelAnimation (tc, false);
  43976. tc->setBounds (newBounds);
  43977. }
  43978. pos += size;
  43979. tc->setVisible (pos <= maxLength
  43980. && ((! tc->isBeingDragged)
  43981. || tc->getEditingMode() == ToolbarItemComponent::editableOnPalette));
  43982. }
  43983. }
  43984. }
  43985. }
  43986. void Toolbar::buttonClicked (Button*)
  43987. {
  43988. jassert (missingItemsButton->isShowing());
  43989. if (missingItemsButton->isShowing())
  43990. {
  43991. PopupMenu m;
  43992. m.addCustomItem (1, new MissingItemsComponent (*this, getThickness()));
  43993. m.showAt (missingItemsButton);
  43994. }
  43995. }
  43996. bool Toolbar::isInterestedInDragSource (const String& sourceDescription,
  43997. Component* /*sourceComponent*/)
  43998. {
  43999. return sourceDescription == toolbarDragDescriptor && isEditingActive;
  44000. }
  44001. void Toolbar::itemDragMove (const String&, Component* sourceComponent, int x, int y)
  44002. {
  44003. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (sourceComponent);
  44004. if (tc != 0)
  44005. {
  44006. if (getNumItems() == 0)
  44007. {
  44008. if (tc->getEditingMode() == ToolbarItemComponent::editableOnPalette)
  44009. {
  44010. ToolbarItemPalette* const palette = tc->findParentComponentOfClass ((ToolbarItemPalette*) 0);
  44011. if (palette != 0)
  44012. palette->replaceComponent (tc);
  44013. }
  44014. else
  44015. {
  44016. jassert (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar);
  44017. }
  44018. items.add (tc);
  44019. addChildComponent (tc);
  44020. updateAllItemPositions (false);
  44021. }
  44022. else
  44023. {
  44024. for (int i = getNumItems(); --i >= 0;)
  44025. {
  44026. int currentIndex = getIndexOfChildComponent (tc);
  44027. if (currentIndex < 0)
  44028. {
  44029. if (tc->getEditingMode() == ToolbarItemComponent::editableOnPalette)
  44030. {
  44031. ToolbarItemPalette* const palette = tc->findParentComponentOfClass ((ToolbarItemPalette*) 0);
  44032. if (palette != 0)
  44033. palette->replaceComponent (tc);
  44034. }
  44035. else
  44036. {
  44037. jassert (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar);
  44038. }
  44039. items.add (tc);
  44040. addChildComponent (tc);
  44041. currentIndex = getIndexOfChildComponent (tc);
  44042. updateAllItemPositions (true);
  44043. }
  44044. int newIndex = currentIndex;
  44045. const int dragObjectLeft = vertical ? (y - tc->dragOffsetY) : (x - tc->dragOffsetX);
  44046. const int dragObjectRight = dragObjectLeft + (vertical ? tc->getHeight() : tc->getWidth());
  44047. const Rectangle<int> current (animator.getComponentDestination (getChildComponent (newIndex)));
  44048. ToolbarItemComponent* const prev = getNextActiveComponent (newIndex, -1);
  44049. if (prev != 0)
  44050. {
  44051. const Rectangle<int> previousPos (animator.getComponentDestination (prev));
  44052. if (abs (dragObjectLeft - (vertical ? previousPos.getY() : previousPos.getX())
  44053. < abs (dragObjectRight - (vertical ? current.getBottom() : current.getRight()))))
  44054. {
  44055. newIndex = getIndexOfChildComponent (prev);
  44056. }
  44057. }
  44058. ToolbarItemComponent* const next = getNextActiveComponent (newIndex, 1);
  44059. if (next != 0)
  44060. {
  44061. const Rectangle<int> nextPos (animator.getComponentDestination (next));
  44062. if (abs (dragObjectLeft - (vertical ? current.getY() : current.getX())
  44063. > abs (dragObjectRight - (vertical ? nextPos.getBottom() : nextPos.getRight()))))
  44064. {
  44065. newIndex = getIndexOfChildComponent (next) + 1;
  44066. }
  44067. }
  44068. if (newIndex != currentIndex)
  44069. {
  44070. items.removeValue (tc);
  44071. removeChildComponent (tc);
  44072. addChildComponent (tc, newIndex);
  44073. items.insert (newIndex, tc);
  44074. updateAllItemPositions (true);
  44075. }
  44076. else
  44077. {
  44078. break;
  44079. }
  44080. }
  44081. }
  44082. }
  44083. }
  44084. void Toolbar::itemDragExit (const String&, Component* sourceComponent)
  44085. {
  44086. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (sourceComponent);
  44087. if (tc != 0)
  44088. {
  44089. if (isParentOf (tc))
  44090. {
  44091. items.removeValue (tc);
  44092. removeChildComponent (tc);
  44093. updateAllItemPositions (true);
  44094. }
  44095. }
  44096. }
  44097. void Toolbar::itemDropped (const String&, Component*, int, int)
  44098. {
  44099. }
  44100. void Toolbar::mouseDown (const MouseEvent& e)
  44101. {
  44102. if (e.mods.isPopupMenu())
  44103. {
  44104. }
  44105. }
  44106. class ToolbarCustomisationDialog : public DialogWindow
  44107. {
  44108. public:
  44109. ToolbarCustomisationDialog (ToolbarItemFactory& factory,
  44110. Toolbar* const toolbar_,
  44111. const int optionFlags)
  44112. : DialogWindow (TRANS("Add/remove items from toolbar"), Colours::white, true, true),
  44113. toolbar (toolbar_)
  44114. {
  44115. setContentComponent (new CustomiserPanel (factory, toolbar, optionFlags), true, true);
  44116. setResizable (true, true);
  44117. setResizeLimits (400, 300, 1500, 1000);
  44118. positionNearBar();
  44119. }
  44120. ~ToolbarCustomisationDialog()
  44121. {
  44122. setContentComponent (0, true);
  44123. }
  44124. void closeButtonPressed()
  44125. {
  44126. setVisible (false);
  44127. }
  44128. bool canModalEventBeSentToComponent (const Component* comp)
  44129. {
  44130. return toolbar->isParentOf (comp);
  44131. }
  44132. void positionNearBar()
  44133. {
  44134. const Rectangle<int> screenSize (toolbar->getParentMonitorArea());
  44135. const int tbx = toolbar->getScreenX();
  44136. const int tby = toolbar->getScreenY();
  44137. const int gap = 8;
  44138. int x, y;
  44139. if (toolbar->isVertical())
  44140. {
  44141. y = tby;
  44142. if (tbx > screenSize.getCentreX())
  44143. x = tbx - getWidth() - gap;
  44144. else
  44145. x = tbx + toolbar->getWidth() + gap;
  44146. }
  44147. else
  44148. {
  44149. x = tbx + (toolbar->getWidth() - getWidth()) / 2;
  44150. if (tby > screenSize.getCentreY())
  44151. y = tby - getHeight() - gap;
  44152. else
  44153. y = tby + toolbar->getHeight() + gap;
  44154. }
  44155. setTopLeftPosition (x, y);
  44156. }
  44157. private:
  44158. Toolbar* const toolbar;
  44159. class CustomiserPanel : public Component,
  44160. private ComboBoxListener,
  44161. private ButtonListener
  44162. {
  44163. public:
  44164. CustomiserPanel (ToolbarItemFactory& factory_,
  44165. Toolbar* const toolbar_,
  44166. const int optionFlags)
  44167. : factory (factory_),
  44168. toolbar (toolbar_),
  44169. styleBox (0),
  44170. defaultButton (0)
  44171. {
  44172. addAndMakeVisible (palette = new ToolbarItemPalette (factory, toolbar));
  44173. if ((optionFlags & (Toolbar::allowIconsOnlyChoice
  44174. | Toolbar::allowIconsWithTextChoice
  44175. | Toolbar::allowTextOnlyChoice)) != 0)
  44176. {
  44177. addAndMakeVisible (styleBox = new ComboBox (String::empty));
  44178. styleBox->setEditableText (false);
  44179. if ((optionFlags & Toolbar::allowIconsOnlyChoice) != 0)
  44180. styleBox->addItem (TRANS("Show icons only"), 1);
  44181. if ((optionFlags & Toolbar::allowIconsWithTextChoice) != 0)
  44182. styleBox->addItem (TRANS("Show icons and descriptions"), 2);
  44183. if ((optionFlags & Toolbar::allowTextOnlyChoice) != 0)
  44184. styleBox->addItem (TRANS("Show descriptions only"), 3);
  44185. if (toolbar_->getStyle() == Toolbar::iconsOnly)
  44186. styleBox->setSelectedId (1);
  44187. else if (toolbar_->getStyle() == Toolbar::iconsWithText)
  44188. styleBox->setSelectedId (2);
  44189. else if (toolbar_->getStyle() == Toolbar::textOnly)
  44190. styleBox->setSelectedId (3);
  44191. styleBox->addListener (this);
  44192. }
  44193. if ((optionFlags & Toolbar::showResetToDefaultsButton) != 0)
  44194. {
  44195. addAndMakeVisible (defaultButton = new TextButton (TRANS ("Restore to default set of items")));
  44196. defaultButton->addButtonListener (this);
  44197. }
  44198. addAndMakeVisible (instructions = new Label (String::empty,
  44199. 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.")));
  44200. instructions->setFont (Font (13.0f));
  44201. setSize (500, 300);
  44202. }
  44203. ~CustomiserPanel()
  44204. {
  44205. deleteAllChildren();
  44206. }
  44207. void comboBoxChanged (ComboBox*)
  44208. {
  44209. if (styleBox->getSelectedId() == 1)
  44210. toolbar->setStyle (Toolbar::iconsOnly);
  44211. else if (styleBox->getSelectedId() == 2)
  44212. toolbar->setStyle (Toolbar::iconsWithText);
  44213. else if (styleBox->getSelectedId() == 3)
  44214. toolbar->setStyle (Toolbar::textOnly);
  44215. palette->resized(); // to make it update the styles
  44216. }
  44217. void buttonClicked (Button*)
  44218. {
  44219. toolbar->addDefaultItems (factory);
  44220. }
  44221. void paint (Graphics& g)
  44222. {
  44223. Colour background;
  44224. DialogWindow* const dw = findParentComponentOfClass ((DialogWindow*) 0);
  44225. if (dw != 0)
  44226. background = dw->getBackgroundColour();
  44227. g.setColour (background.contrasting().withAlpha (0.3f));
  44228. g.fillRect (palette->getX(), palette->getBottom() - 1, palette->getWidth(), 1);
  44229. }
  44230. void resized()
  44231. {
  44232. palette->setBounds (0, 0, getWidth(), getHeight() - 120);
  44233. if (styleBox != 0)
  44234. styleBox->setBounds (10, getHeight() - 110, 200, 22);
  44235. if (defaultButton != 0)
  44236. {
  44237. defaultButton->changeWidthToFitText (22);
  44238. defaultButton->setTopLeftPosition (240, getHeight() - 110);
  44239. }
  44240. instructions->setBounds (10, getHeight() - 80, getWidth() - 20, 80);
  44241. }
  44242. private:
  44243. ToolbarItemFactory& factory;
  44244. Toolbar* const toolbar;
  44245. Label* instructions;
  44246. ToolbarItemPalette* palette;
  44247. ComboBox* styleBox;
  44248. TextButton* defaultButton;
  44249. };
  44250. };
  44251. void Toolbar::showCustomisationDialog (ToolbarItemFactory& factory, const int optionFlags)
  44252. {
  44253. setEditingActive (true);
  44254. ToolbarCustomisationDialog dw (factory, this, optionFlags);
  44255. dw.runModalLoop();
  44256. jassert (isValidComponent()); // ? deleting the toolbar while it's being edited?
  44257. setEditingActive (false);
  44258. }
  44259. END_JUCE_NAMESPACE
  44260. /*** End of inlined file: juce_Toolbar.cpp ***/
  44261. /*** Start of inlined file: juce_ToolbarItemComponent.cpp ***/
  44262. BEGIN_JUCE_NAMESPACE
  44263. ToolbarItemFactory::ToolbarItemFactory()
  44264. {
  44265. }
  44266. ToolbarItemFactory::~ToolbarItemFactory()
  44267. {
  44268. }
  44269. class ItemDragAndDropOverlayComponent : public Component
  44270. {
  44271. public:
  44272. ItemDragAndDropOverlayComponent()
  44273. : isDragging (false)
  44274. {
  44275. setAlwaysOnTop (true);
  44276. setRepaintsOnMouseActivity (true);
  44277. setMouseCursor (MouseCursor::DraggingHandCursor);
  44278. }
  44279. ~ItemDragAndDropOverlayComponent()
  44280. {
  44281. }
  44282. void paint (Graphics& g)
  44283. {
  44284. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  44285. if (isMouseOverOrDragging()
  44286. && tc != 0
  44287. && tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
  44288. {
  44289. g.setColour (findColour (Toolbar::editingModeOutlineColourId, true));
  44290. g.drawRect (0, 0, getWidth(), getHeight(),
  44291. jmin (2, (getWidth() - 1) / 2, (getHeight() - 1) / 2));
  44292. }
  44293. }
  44294. void mouseDown (const MouseEvent& e)
  44295. {
  44296. isDragging = false;
  44297. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  44298. if (tc != 0)
  44299. {
  44300. tc->dragOffsetX = e.x;
  44301. tc->dragOffsetY = e.y;
  44302. }
  44303. }
  44304. void mouseDrag (const MouseEvent& e)
  44305. {
  44306. if (! (isDragging || e.mouseWasClicked()))
  44307. {
  44308. isDragging = true;
  44309. DragAndDropContainer* const dnd = DragAndDropContainer::findParentDragContainerFor (this);
  44310. if (dnd != 0)
  44311. {
  44312. dnd->startDragging (Toolbar::toolbarDragDescriptor, getParentComponent(), 0, true);
  44313. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  44314. if (tc != 0)
  44315. {
  44316. tc->isBeingDragged = true;
  44317. if (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
  44318. tc->setVisible (false);
  44319. }
  44320. }
  44321. }
  44322. }
  44323. void mouseUp (const MouseEvent&)
  44324. {
  44325. isDragging = false;
  44326. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  44327. if (tc != 0)
  44328. {
  44329. tc->isBeingDragged = false;
  44330. Toolbar* const tb = tc->getToolbar();
  44331. if (tb != 0)
  44332. tb->updateAllItemPositions (true);
  44333. else if (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
  44334. delete tc;
  44335. }
  44336. }
  44337. void parentSizeChanged()
  44338. {
  44339. setBounds (0, 0, getParentWidth(), getParentHeight());
  44340. }
  44341. juce_UseDebuggingNewOperator
  44342. private:
  44343. bool isDragging;
  44344. ItemDragAndDropOverlayComponent (const ItemDragAndDropOverlayComponent&);
  44345. const ItemDragAndDropOverlayComponent& operator= (const ItemDragAndDropOverlayComponent&);
  44346. };
  44347. ToolbarItemComponent::ToolbarItemComponent (const int itemId_,
  44348. const String& labelText,
  44349. const bool isBeingUsedAsAButton_)
  44350. : Button (labelText),
  44351. itemId (itemId_),
  44352. mode (normalMode),
  44353. toolbarStyle (Toolbar::iconsOnly),
  44354. dragOffsetX (0),
  44355. dragOffsetY (0),
  44356. isActive (true),
  44357. isBeingDragged (false),
  44358. isBeingUsedAsAButton (isBeingUsedAsAButton_)
  44359. {
  44360. // Your item ID can't be 0!
  44361. jassert (itemId_ != 0);
  44362. }
  44363. ToolbarItemComponent::~ToolbarItemComponent()
  44364. {
  44365. jassert (overlayComp == 0 || overlayComp->isValidComponent());
  44366. overlayComp = 0;
  44367. }
  44368. Toolbar* ToolbarItemComponent::getToolbar() const
  44369. {
  44370. return dynamic_cast <Toolbar*> (getParentComponent());
  44371. }
  44372. bool ToolbarItemComponent::isToolbarVertical() const
  44373. {
  44374. const Toolbar* const t = getToolbar();
  44375. return t != 0 && t->isVertical();
  44376. }
  44377. void ToolbarItemComponent::setStyle (const Toolbar::ToolbarItemStyle& newStyle)
  44378. {
  44379. if (toolbarStyle != newStyle)
  44380. {
  44381. toolbarStyle = newStyle;
  44382. repaint();
  44383. resized();
  44384. }
  44385. }
  44386. void ToolbarItemComponent::paintButton (Graphics& g, bool isMouseOver, bool isMouseDown)
  44387. {
  44388. if (isBeingUsedAsAButton)
  44389. getLookAndFeel().paintToolbarButtonBackground (g, getWidth(), getHeight(),
  44390. isMouseOver, isMouseDown, *this);
  44391. if (toolbarStyle != Toolbar::iconsOnly)
  44392. {
  44393. const int indent = contentArea.getX();
  44394. int y = indent;
  44395. int h = getHeight() - indent * 2;
  44396. if (toolbarStyle == Toolbar::iconsWithText)
  44397. {
  44398. y = contentArea.getBottom() + indent / 2;
  44399. h -= contentArea.getHeight();
  44400. }
  44401. getLookAndFeel().paintToolbarButtonLabel (g, indent, y, getWidth() - indent * 2, h,
  44402. getButtonText(), *this);
  44403. }
  44404. if (! contentArea.isEmpty())
  44405. {
  44406. g.saveState();
  44407. g.setOrigin (contentArea.getX(), contentArea.getY());
  44408. g.reduceClipRegion (0, 0, contentArea.getWidth(), contentArea.getHeight());
  44409. paintButtonArea (g, contentArea.getWidth(), contentArea.getHeight(), isMouseOver, isMouseDown);
  44410. g.restoreState();
  44411. }
  44412. }
  44413. void ToolbarItemComponent::resized()
  44414. {
  44415. if (toolbarStyle != Toolbar::textOnly)
  44416. {
  44417. const int indent = jmin (proportionOfWidth (0.08f),
  44418. proportionOfHeight (0.08f));
  44419. contentArea = Rectangle<int> (indent, indent,
  44420. getWidth() - indent * 2,
  44421. toolbarStyle == Toolbar::iconsWithText ? proportionOfHeight (0.55f)
  44422. : (getHeight() - indent * 2));
  44423. }
  44424. else
  44425. {
  44426. contentArea = Rectangle<int>();
  44427. }
  44428. contentAreaChanged (contentArea);
  44429. }
  44430. void ToolbarItemComponent::setEditingMode (const ToolbarEditingMode newMode)
  44431. {
  44432. if (mode != newMode)
  44433. {
  44434. mode = newMode;
  44435. repaint();
  44436. if (mode == normalMode)
  44437. {
  44438. jassert (overlayComp == 0 || overlayComp->isValidComponent());
  44439. overlayComp = 0;
  44440. }
  44441. else if (overlayComp == 0)
  44442. {
  44443. addAndMakeVisible (overlayComp = new ItemDragAndDropOverlayComponent());
  44444. overlayComp->parentSizeChanged();
  44445. }
  44446. resized();
  44447. }
  44448. }
  44449. END_JUCE_NAMESPACE
  44450. /*** End of inlined file: juce_ToolbarItemComponent.cpp ***/
  44451. /*** Start of inlined file: juce_ToolbarItemPalette.cpp ***/
  44452. BEGIN_JUCE_NAMESPACE
  44453. ToolbarItemPalette::ToolbarItemPalette (ToolbarItemFactory& factory_,
  44454. Toolbar* const toolbar_)
  44455. : factory (factory_),
  44456. toolbar (toolbar_)
  44457. {
  44458. Component* const itemHolder = new Component();
  44459. Array <int> allIds;
  44460. factory_.getAllToolbarItemIds (allIds);
  44461. for (int i = 0; i < allIds.size(); ++i)
  44462. {
  44463. ToolbarItemComponent* const tc = Toolbar::createItem (factory_, allIds.getUnchecked (i));
  44464. jassert (tc != 0);
  44465. if (tc != 0)
  44466. {
  44467. itemHolder->addAndMakeVisible (tc);
  44468. tc->setEditingMode (ToolbarItemComponent::editableOnPalette);
  44469. }
  44470. }
  44471. viewport = new Viewport();
  44472. viewport->setViewedComponent (itemHolder);
  44473. addAndMakeVisible (viewport);
  44474. }
  44475. ToolbarItemPalette::~ToolbarItemPalette()
  44476. {
  44477. viewport->getViewedComponent()->deleteAllChildren();
  44478. deleteAllChildren();
  44479. }
  44480. void ToolbarItemPalette::resized()
  44481. {
  44482. viewport->setBoundsInset (BorderSize (1));
  44483. Component* const itemHolder = viewport->getViewedComponent();
  44484. const int indent = 8;
  44485. const int preferredWidth = viewport->getWidth() - viewport->getScrollBarThickness() - indent;
  44486. const int height = toolbar->getThickness();
  44487. int x = indent;
  44488. int y = indent;
  44489. int maxX = 0;
  44490. for (int i = 0; i < itemHolder->getNumChildComponents(); ++i)
  44491. {
  44492. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (itemHolder->getChildComponent (i));
  44493. if (tc != 0)
  44494. {
  44495. tc->setStyle (toolbar->getStyle());
  44496. int preferredSize = 1, minSize = 1, maxSize = 1;
  44497. if (tc->getToolbarItemSizes (height, false, preferredSize, minSize, maxSize))
  44498. {
  44499. if (x + preferredSize > preferredWidth && x > indent)
  44500. {
  44501. x = indent;
  44502. y += height;
  44503. }
  44504. tc->setBounds (x, y, preferredSize, height);
  44505. x += preferredSize + 8;
  44506. maxX = jmax (maxX, x);
  44507. }
  44508. }
  44509. }
  44510. itemHolder->setSize (maxX, y + height + 8);
  44511. }
  44512. void ToolbarItemPalette::replaceComponent (ToolbarItemComponent* const comp)
  44513. {
  44514. ToolbarItemComponent* const tc = Toolbar::createItem (factory, comp->getItemId());
  44515. jassert (tc != 0);
  44516. if (tc != 0)
  44517. {
  44518. tc->setBounds (comp->getBounds());
  44519. tc->setStyle (toolbar->getStyle());
  44520. tc->setEditingMode (comp->getEditingMode());
  44521. viewport->getViewedComponent()->addAndMakeVisible (tc, getIndexOfChildComponent (comp));
  44522. }
  44523. }
  44524. END_JUCE_NAMESPACE
  44525. /*** End of inlined file: juce_ToolbarItemPalette.cpp ***/
  44526. /*** Start of inlined file: juce_TreeView.cpp ***/
  44527. BEGIN_JUCE_NAMESPACE
  44528. class TreeViewContentComponent : public Component,
  44529. public TooltipClient
  44530. {
  44531. public:
  44532. TreeViewContentComponent (TreeView* const owner_)
  44533. : owner (owner_),
  44534. buttonUnderMouse (0),
  44535. isDragging (false)
  44536. {
  44537. }
  44538. ~TreeViewContentComponent()
  44539. {
  44540. deleteAllChildren();
  44541. }
  44542. void mouseDown (const MouseEvent& e)
  44543. {
  44544. updateButtonUnderMouse (e);
  44545. isDragging = false;
  44546. needSelectionOnMouseUp = false;
  44547. Rectangle<int> pos;
  44548. TreeViewItem* const item = findItemAt (e.y, pos);
  44549. if (item == 0)
  44550. return;
  44551. // (if the open/close buttons are hidden, we'll treat clicks to the left of the item
  44552. // as selection clicks)
  44553. if (e.x < pos.getX() && owner->openCloseButtonsVisible)
  44554. {
  44555. if (e.x >= pos.getX() - owner->getIndentSize())
  44556. item->setOpen (! item->isOpen());
  44557. // (clicks to the left of an open/close button are ignored)
  44558. }
  44559. else
  44560. {
  44561. // mouse-down inside the body of the item..
  44562. if (! owner->isMultiSelectEnabled())
  44563. item->setSelected (true, true);
  44564. else if (item->isSelected())
  44565. needSelectionOnMouseUp = ! e.mods.isPopupMenu();
  44566. else
  44567. selectBasedOnModifiers (item, e.mods);
  44568. MouseEvent e2 (e);
  44569. e2.x -= pos.getX();
  44570. e2.y -= pos.getY();
  44571. if (e2.x >= 0)
  44572. item->itemClicked (e2);
  44573. }
  44574. }
  44575. void mouseUp (const MouseEvent& e)
  44576. {
  44577. updateButtonUnderMouse (e);
  44578. if (needSelectionOnMouseUp && e.mouseWasClicked())
  44579. {
  44580. Rectangle<int> pos;
  44581. TreeViewItem* const item = findItemAt (e.y, pos);
  44582. if (item != 0)
  44583. selectBasedOnModifiers (item, e.mods);
  44584. }
  44585. }
  44586. void mouseDoubleClick (const MouseEvent& e)
  44587. {
  44588. if (e.getNumberOfClicks() != 3) // ignore triple clicks
  44589. {
  44590. Rectangle<int> pos;
  44591. TreeViewItem* const item = findItemAt (e.y, pos);
  44592. if (item != 0 && (e.x >= pos.getX() || ! owner->openCloseButtonsVisible))
  44593. {
  44594. MouseEvent e2 (e);
  44595. e2.x -= pos.getX();
  44596. e2.y -= pos.getY();
  44597. item->itemDoubleClicked (e2);
  44598. }
  44599. }
  44600. }
  44601. void mouseDrag (const MouseEvent& e)
  44602. {
  44603. if (isEnabled()
  44604. && ! (isDragging || e.mouseWasClicked()
  44605. || e.getDistanceFromDragStart() < 5
  44606. || e.mods.isPopupMenu()))
  44607. {
  44608. isDragging = true;
  44609. Rectangle<int> pos;
  44610. TreeViewItem* const item = findItemAt (e.getMouseDownY(), pos);
  44611. if (item != 0 && e.getMouseDownX() >= pos.getX())
  44612. {
  44613. const String dragDescription (item->getDragSourceDescription());
  44614. if (dragDescription.isNotEmpty())
  44615. {
  44616. DragAndDropContainer* const dragContainer
  44617. = DragAndDropContainer::findParentDragContainerFor (this);
  44618. if (dragContainer != 0)
  44619. {
  44620. pos.setSize (pos.getWidth(), item->itemHeight);
  44621. Image* dragImage = Component::createComponentSnapshot (pos, true);
  44622. dragImage->multiplyAllAlphas (0.6f);
  44623. Point<int> imageOffset (pos.getX() - e.x, pos.getY() - e.y);
  44624. dragContainer->startDragging (dragDescription, owner, dragImage, true, &imageOffset);
  44625. }
  44626. else
  44627. {
  44628. // to be able to do a drag-and-drop operation, the treeview needs to
  44629. // be inside a component which is also a DragAndDropContainer.
  44630. jassertfalse
  44631. }
  44632. }
  44633. }
  44634. }
  44635. }
  44636. void mouseMove (const MouseEvent& e)
  44637. {
  44638. updateButtonUnderMouse (e);
  44639. }
  44640. void mouseExit (const MouseEvent& e)
  44641. {
  44642. updateButtonUnderMouse (e);
  44643. }
  44644. void paint (Graphics& g);
  44645. TreeViewItem* findItemAt (int y, Rectangle<int>& itemPosition) const;
  44646. void updateComponents()
  44647. {
  44648. const int visibleTop = -getY();
  44649. const int visibleBottom = visibleTop + getParentHeight();
  44650. BitArray itemsToKeep;
  44651. TreeViewItem* item = owner->rootItem;
  44652. int y = (item != 0 && !owner->rootItemVisible) ? -item->itemHeight : 0;
  44653. while (item != 0 && y < visibleBottom)
  44654. {
  44655. y += item->itemHeight;
  44656. if (y >= visibleTop)
  44657. {
  44658. const int index = rowComponentIds.indexOf (item->uid);
  44659. if (index < 0)
  44660. {
  44661. Component* const comp = item->createItemComponent();
  44662. if (comp != 0)
  44663. {
  44664. addAndMakeVisible (comp);
  44665. itemsToKeep.setBit (rowComponentItems.size());
  44666. rowComponentItems.add (item);
  44667. rowComponentIds.add (item->uid);
  44668. rowComponents.add (comp);
  44669. }
  44670. }
  44671. else
  44672. {
  44673. itemsToKeep.setBit (index);
  44674. }
  44675. }
  44676. item = item->getNextVisibleItem (true);
  44677. }
  44678. for (int i = rowComponentItems.size(); --i >= 0;)
  44679. {
  44680. Component* const comp = (Component*) rowComponents.getUnchecked(i);
  44681. bool keep = false;
  44682. if (isParentOf (comp))
  44683. {
  44684. if (itemsToKeep[i])
  44685. {
  44686. const TreeViewItem* const item = (TreeViewItem*) rowComponentItems.getUnchecked(i);
  44687. Rectangle<int> pos (item->getItemPosition (false));
  44688. pos.setSize (pos.getWidth(), item->itemHeight);
  44689. if (pos.getBottom() >= visibleTop && pos.getY() < visibleBottom)
  44690. {
  44691. keep = true;
  44692. comp->setBounds (pos);
  44693. }
  44694. }
  44695. if ((! keep)
  44696. && Component::isMouseButtonDownAnywhere()
  44697. && (comp == Component::getComponentUnderMouse()
  44698. || comp->isParentOf (Component::getComponentUnderMouse())))
  44699. {
  44700. keep = true;
  44701. comp->setSize (0, 0);
  44702. }
  44703. }
  44704. if (! keep)
  44705. {
  44706. delete comp;
  44707. rowComponents.remove (i);
  44708. rowComponentIds.remove (i);
  44709. rowComponentItems.remove (i);
  44710. }
  44711. }
  44712. }
  44713. void updateButtonUnderMouse (const MouseEvent& e)
  44714. {
  44715. TreeViewItem* newItem = 0;
  44716. if (owner->openCloseButtonsVisible)
  44717. {
  44718. Rectangle<int> pos;
  44719. TreeViewItem* item = findItemAt (e.y, pos);
  44720. if (item != 0 && e.x < pos.getX() && e.x >= pos.getX() - owner->getIndentSize())
  44721. {
  44722. newItem = item;
  44723. if (! newItem->mightContainSubItems())
  44724. newItem = 0;
  44725. }
  44726. }
  44727. if (buttonUnderMouse != newItem)
  44728. {
  44729. if (buttonUnderMouse != 0 && containsItem (buttonUnderMouse))
  44730. {
  44731. const Rectangle<int> r (buttonUnderMouse->getItemPosition (false));
  44732. repaint (0, r.getY(), r.getX(), buttonUnderMouse->getItemHeight());
  44733. }
  44734. buttonUnderMouse = newItem;
  44735. if (buttonUnderMouse != 0)
  44736. {
  44737. const Rectangle<int> r (buttonUnderMouse->getItemPosition (false));
  44738. repaint (0, r.getY(), r.getX(), buttonUnderMouse->getItemHeight());
  44739. }
  44740. }
  44741. }
  44742. bool isMouseOverButton (TreeViewItem* item) const throw()
  44743. {
  44744. return item == buttonUnderMouse;
  44745. }
  44746. void resized()
  44747. {
  44748. owner->itemsChanged();
  44749. }
  44750. const String getTooltip()
  44751. {
  44752. int x, y;
  44753. getMouseXYRelative (x, y);
  44754. Rectangle<int> pos;
  44755. TreeViewItem* const item = findItemAt (y, pos);
  44756. if (item != 0)
  44757. return item->getTooltip();
  44758. return owner->getTooltip();
  44759. }
  44760. juce_UseDebuggingNewOperator
  44761. private:
  44762. TreeView* const owner;
  44763. VoidArray rowComponentItems;
  44764. Array <int> rowComponentIds;
  44765. VoidArray rowComponents;
  44766. TreeViewItem* buttonUnderMouse;
  44767. bool isDragging, needSelectionOnMouseUp;
  44768. TreeViewContentComponent (const TreeViewContentComponent&);
  44769. const TreeViewContentComponent& operator= (const TreeViewContentComponent&);
  44770. void selectBasedOnModifiers (TreeViewItem* const item, const ModifierKeys& modifiers)
  44771. {
  44772. TreeViewItem* firstSelected = 0;
  44773. if (modifiers.isShiftDown() && ((firstSelected = owner->getSelectedItem (0)) != 0))
  44774. {
  44775. TreeViewItem* const lastSelected = owner->getSelectedItem (owner->getNumSelectedItems() - 1);
  44776. jassert (lastSelected != 0);
  44777. int rowStart = firstSelected->getRowNumberInTree();
  44778. int rowEnd = lastSelected->getRowNumberInTree();
  44779. if (rowStart > rowEnd)
  44780. swapVariables (rowStart, rowEnd);
  44781. int ourRow = item->getRowNumberInTree();
  44782. int otherEnd = ourRow < rowEnd ? rowStart : rowEnd;
  44783. if (ourRow > otherEnd)
  44784. swapVariables (ourRow, otherEnd);
  44785. for (int i = ourRow; i <= otherEnd; ++i)
  44786. owner->getItemOnRow (i)->setSelected (true, false);
  44787. }
  44788. else
  44789. {
  44790. const bool cmd = modifiers.isCommandDown();
  44791. item->setSelected ((! cmd) || (! item->isSelected()), ! cmd);
  44792. }
  44793. }
  44794. bool containsItem (TreeViewItem* const item) const
  44795. {
  44796. for (int i = rowComponentItems.size(); --i >= 0;)
  44797. if ((TreeViewItem*) rowComponentItems.getUnchecked (i) == item)
  44798. return true;
  44799. return false;
  44800. }
  44801. };
  44802. class TreeViewport : public Viewport
  44803. {
  44804. public:
  44805. TreeViewport() throw() {}
  44806. ~TreeViewport() throw() {}
  44807. void updateComponents()
  44808. {
  44809. if (getViewedComponent() != 0)
  44810. ((TreeViewContentComponent*) getViewedComponent())->updateComponents();
  44811. repaint();
  44812. }
  44813. void visibleAreaChanged (int, int, int, int)
  44814. {
  44815. updateComponents();
  44816. }
  44817. juce_UseDebuggingNewOperator
  44818. private:
  44819. TreeViewport (const TreeViewport&);
  44820. const TreeViewport& operator= (const TreeViewport&);
  44821. };
  44822. TreeView::TreeView (const String& componentName)
  44823. : Component (componentName),
  44824. rootItem (0),
  44825. dragInsertPointHighlight (0),
  44826. dragTargetGroupHighlight (0),
  44827. indentSize (24),
  44828. defaultOpenness (false),
  44829. needsRecalculating (true),
  44830. rootItemVisible (true),
  44831. multiSelectEnabled (false),
  44832. openCloseButtonsVisible (true)
  44833. {
  44834. addAndMakeVisible (viewport = new TreeViewport());
  44835. viewport->setViewedComponent (new TreeViewContentComponent (this));
  44836. viewport->setWantsKeyboardFocus (false);
  44837. setWantsKeyboardFocus (true);
  44838. }
  44839. TreeView::~TreeView()
  44840. {
  44841. if (rootItem != 0)
  44842. rootItem->setOwnerView (0);
  44843. deleteAllChildren();
  44844. }
  44845. void TreeView::setRootItem (TreeViewItem* const newRootItem)
  44846. {
  44847. if (rootItem != newRootItem)
  44848. {
  44849. if (newRootItem != 0)
  44850. {
  44851. jassert (newRootItem->ownerView == 0); // can't use a tree item in more than one tree at once..
  44852. if (newRootItem->ownerView != 0)
  44853. newRootItem->ownerView->setRootItem (0);
  44854. }
  44855. if (rootItem != 0)
  44856. rootItem->setOwnerView (0);
  44857. rootItem = newRootItem;
  44858. if (newRootItem != 0)
  44859. newRootItem->setOwnerView (this);
  44860. needsRecalculating = true;
  44861. handleAsyncUpdate();
  44862. if (rootItem != 0 && (defaultOpenness || ! rootItemVisible))
  44863. {
  44864. rootItem->setOpen (false); // force a re-open
  44865. rootItem->setOpen (true);
  44866. }
  44867. }
  44868. }
  44869. void TreeView::deleteRootItem()
  44870. {
  44871. const ScopedPointer <TreeViewItem> deleter (rootItem);
  44872. setRootItem (0);
  44873. }
  44874. void TreeView::setRootItemVisible (const bool shouldBeVisible)
  44875. {
  44876. rootItemVisible = shouldBeVisible;
  44877. if (rootItem != 0 && (defaultOpenness || ! rootItemVisible))
  44878. {
  44879. rootItem->setOpen (false); // force a re-open
  44880. rootItem->setOpen (true);
  44881. }
  44882. itemsChanged();
  44883. }
  44884. void TreeView::colourChanged()
  44885. {
  44886. setOpaque (findColour (backgroundColourId).isOpaque());
  44887. repaint();
  44888. }
  44889. void TreeView::setIndentSize (const int newIndentSize)
  44890. {
  44891. if (indentSize != newIndentSize)
  44892. {
  44893. indentSize = newIndentSize;
  44894. resized();
  44895. }
  44896. }
  44897. void TreeView::setDefaultOpenness (const bool isOpenByDefault)
  44898. {
  44899. if (defaultOpenness != isOpenByDefault)
  44900. {
  44901. defaultOpenness = isOpenByDefault;
  44902. itemsChanged();
  44903. }
  44904. }
  44905. void TreeView::setMultiSelectEnabled (const bool canMultiSelect)
  44906. {
  44907. multiSelectEnabled = canMultiSelect;
  44908. }
  44909. void TreeView::setOpenCloseButtonsVisible (const bool shouldBeVisible)
  44910. {
  44911. if (openCloseButtonsVisible != shouldBeVisible)
  44912. {
  44913. openCloseButtonsVisible = shouldBeVisible;
  44914. itemsChanged();
  44915. }
  44916. }
  44917. void TreeView::clearSelectedItems()
  44918. {
  44919. if (rootItem != 0)
  44920. rootItem->deselectAllRecursively();
  44921. }
  44922. int TreeView::getNumSelectedItems() const throw()
  44923. {
  44924. return (rootItem != 0) ? rootItem->countSelectedItemsRecursively() : 0;
  44925. }
  44926. TreeViewItem* TreeView::getSelectedItem (const int index) const throw()
  44927. {
  44928. return (rootItem != 0) ? rootItem->getSelectedItemWithIndex (index) : 0;
  44929. }
  44930. int TreeView::getNumRowsInTree() const
  44931. {
  44932. if (rootItem != 0)
  44933. return rootItem->getNumRows() - (rootItemVisible ? 0 : 1);
  44934. return 0;
  44935. }
  44936. TreeViewItem* TreeView::getItemOnRow (int index) const
  44937. {
  44938. if (! rootItemVisible)
  44939. ++index;
  44940. if (rootItem != 0 && index >= 0)
  44941. return rootItem->getItemOnRow (index);
  44942. return 0;
  44943. }
  44944. TreeViewItem* TreeView::getItemAt (int y) const throw()
  44945. {
  44946. TreeViewContentComponent* const tc = (TreeViewContentComponent*) viewport->getViewedComponent();
  44947. int x;
  44948. relativePositionToOtherComponent (tc, x, y);
  44949. Rectangle<int> pos;
  44950. return tc->findItemAt (y, pos);
  44951. }
  44952. TreeViewItem* TreeView::findItemFromIdentifierString (const String& identifierString) const
  44953. {
  44954. if (rootItem == 0)
  44955. return 0;
  44956. return rootItem->findItemFromIdentifierString (identifierString);
  44957. }
  44958. XmlElement* TreeView::getOpennessState (const bool alsoIncludeScrollPosition) const
  44959. {
  44960. XmlElement* e = 0;
  44961. if (rootItem != 0)
  44962. {
  44963. e = rootItem->getOpennessState();
  44964. if (e != 0 && alsoIncludeScrollPosition)
  44965. e->setAttribute (T("scrollPos"), viewport->getViewPositionY());
  44966. }
  44967. return e;
  44968. }
  44969. void TreeView::restoreOpennessState (const XmlElement& newState)
  44970. {
  44971. if (rootItem != 0)
  44972. {
  44973. rootItem->restoreOpennessState (newState);
  44974. if (newState.hasAttribute (T("scrollPos")))
  44975. viewport->setViewPosition (viewport->getViewPositionX(),
  44976. newState.getIntAttribute (T("scrollPos")));
  44977. }
  44978. }
  44979. void TreeView::paint (Graphics& g)
  44980. {
  44981. g.fillAll (findColour (backgroundColourId));
  44982. }
  44983. void TreeView::resized()
  44984. {
  44985. viewport->setBounds (0, 0, getWidth(), getHeight());
  44986. itemsChanged();
  44987. handleAsyncUpdate();
  44988. }
  44989. void TreeView::enablementChanged()
  44990. {
  44991. repaint();
  44992. }
  44993. void TreeView::moveSelectedRow (int delta)
  44994. {
  44995. if (delta == 0)
  44996. return;
  44997. int rowSelected = 0;
  44998. TreeViewItem* const firstSelected = getSelectedItem (0);
  44999. if (firstSelected != 0)
  45000. rowSelected = firstSelected->getRowNumberInTree();
  45001. rowSelected = jlimit (0, getNumRowsInTree() - 1, rowSelected + delta);
  45002. for (;;)
  45003. {
  45004. TreeViewItem* item = getItemOnRow (rowSelected);
  45005. if (item != 0)
  45006. {
  45007. if (! item->canBeSelected())
  45008. {
  45009. // if the row we want to highlight doesn't allow it, try skipping
  45010. // to the next item..
  45011. const int nextRowToTry = jlimit (0, getNumRowsInTree() - 1,
  45012. rowSelected + (delta < 0 ? -1 : 1));
  45013. if (rowSelected != nextRowToTry)
  45014. {
  45015. rowSelected = nextRowToTry;
  45016. continue;
  45017. }
  45018. else
  45019. {
  45020. break;
  45021. }
  45022. }
  45023. item->setSelected (true, true);
  45024. scrollToKeepItemVisible (item);
  45025. }
  45026. break;
  45027. }
  45028. }
  45029. void TreeView::scrollToKeepItemVisible (TreeViewItem* item)
  45030. {
  45031. if (item != 0 && item->ownerView == this)
  45032. {
  45033. handleAsyncUpdate();
  45034. item = item->getDeepestOpenParentItem();
  45035. int y = item->y;
  45036. int viewTop = viewport->getViewPositionY();
  45037. if (y < viewTop)
  45038. {
  45039. viewport->setViewPosition (viewport->getViewPositionX(), y);
  45040. }
  45041. else if (y + item->itemHeight > viewTop + viewport->getViewHeight())
  45042. {
  45043. viewport->setViewPosition (viewport->getViewPositionX(),
  45044. (y + item->itemHeight) - viewport->getViewHeight());
  45045. }
  45046. }
  45047. }
  45048. bool TreeView::keyPressed (const KeyPress& key)
  45049. {
  45050. if (key.isKeyCode (KeyPress::upKey))
  45051. {
  45052. moveSelectedRow (-1);
  45053. }
  45054. else if (key.isKeyCode (KeyPress::downKey))
  45055. {
  45056. moveSelectedRow (1);
  45057. }
  45058. else if (key.isKeyCode (KeyPress::pageDownKey) || key.isKeyCode (KeyPress::pageUpKey))
  45059. {
  45060. if (rootItem != 0)
  45061. {
  45062. int rowsOnScreen = getHeight() / jmax (1, rootItem->itemHeight);
  45063. if (key.isKeyCode (KeyPress::pageUpKey))
  45064. rowsOnScreen = -rowsOnScreen;
  45065. moveSelectedRow (rowsOnScreen);
  45066. }
  45067. }
  45068. else if (key.isKeyCode (KeyPress::homeKey))
  45069. {
  45070. moveSelectedRow (-0x3fffffff);
  45071. }
  45072. else if (key.isKeyCode (KeyPress::endKey))
  45073. {
  45074. moveSelectedRow (0x3fffffff);
  45075. }
  45076. else if (key.isKeyCode (KeyPress::returnKey))
  45077. {
  45078. TreeViewItem* const firstSelected = getSelectedItem (0);
  45079. if (firstSelected != 0)
  45080. firstSelected->setOpen (! firstSelected->isOpen());
  45081. }
  45082. else if (key.isKeyCode (KeyPress::leftKey))
  45083. {
  45084. TreeViewItem* const firstSelected = getSelectedItem (0);
  45085. if (firstSelected != 0)
  45086. {
  45087. if (firstSelected->isOpen())
  45088. {
  45089. firstSelected->setOpen (false);
  45090. }
  45091. else
  45092. {
  45093. TreeViewItem* parent = firstSelected->parentItem;
  45094. if ((! rootItemVisible) && parent == rootItem)
  45095. parent = 0;
  45096. if (parent != 0)
  45097. {
  45098. parent->setSelected (true, true);
  45099. scrollToKeepItemVisible (parent);
  45100. }
  45101. }
  45102. }
  45103. }
  45104. else if (key.isKeyCode (KeyPress::rightKey))
  45105. {
  45106. TreeViewItem* const firstSelected = getSelectedItem (0);
  45107. if (firstSelected != 0)
  45108. {
  45109. if (firstSelected->isOpen() || ! firstSelected->mightContainSubItems())
  45110. moveSelectedRow (1);
  45111. else
  45112. firstSelected->setOpen (true);
  45113. }
  45114. }
  45115. else
  45116. {
  45117. return false;
  45118. }
  45119. return true;
  45120. }
  45121. void TreeView::itemsChanged() throw()
  45122. {
  45123. needsRecalculating = true;
  45124. repaint();
  45125. triggerAsyncUpdate();
  45126. }
  45127. void TreeView::handleAsyncUpdate()
  45128. {
  45129. if (needsRecalculating)
  45130. {
  45131. needsRecalculating = false;
  45132. const ScopedLock sl (nodeAlterationLock);
  45133. if (rootItem != 0)
  45134. rootItem->updatePositions (rootItemVisible ? 0 : -rootItem->itemHeight);
  45135. ((TreeViewport*) viewport)->updateComponents();
  45136. if (rootItem != 0)
  45137. {
  45138. viewport->getViewedComponent()
  45139. ->setSize (jmax (viewport->getMaximumVisibleWidth(), rootItem->totalWidth),
  45140. rootItem->totalHeight - (rootItemVisible ? 0 : rootItem->itemHeight));
  45141. }
  45142. else
  45143. {
  45144. viewport->getViewedComponent()->setSize (0, 0);
  45145. }
  45146. }
  45147. }
  45148. class TreeViewDragInsertPointHighlight : public Component
  45149. {
  45150. public:
  45151. TreeViewDragInsertPointHighlight()
  45152. : lastItem (0)
  45153. {
  45154. setSize (100, 12);
  45155. setAlwaysOnTop (true);
  45156. setInterceptsMouseClicks (false, false);
  45157. }
  45158. ~TreeViewDragInsertPointHighlight() {}
  45159. void setTargetPosition (TreeViewItem* const item, int insertIndex, const int x, const int y, const int width) throw()
  45160. {
  45161. lastItem = item;
  45162. lastIndex = insertIndex;
  45163. const int offset = getHeight() / 2;
  45164. setBounds (x - offset, y - offset, width - (x - offset), getHeight());
  45165. }
  45166. void paint (Graphics& g)
  45167. {
  45168. Path p;
  45169. const float h = (float) getHeight();
  45170. p.addEllipse (2.0f, 2.0f, h - 4.0f, h - 4.0f);
  45171. p.startNewSubPath (h - 2.0f, h / 2.0f);
  45172. p.lineTo ((float) getWidth(), h / 2.0f);
  45173. g.setColour (findColour (TreeView::dragAndDropIndicatorColourId, true));
  45174. g.strokePath (p, PathStrokeType (2.0f));
  45175. }
  45176. TreeViewItem* lastItem;
  45177. int lastIndex;
  45178. };
  45179. class TreeViewDragTargetGroupHighlight : public Component
  45180. {
  45181. public:
  45182. TreeViewDragTargetGroupHighlight()
  45183. {
  45184. setAlwaysOnTop (true);
  45185. setInterceptsMouseClicks (false, false);
  45186. }
  45187. ~TreeViewDragTargetGroupHighlight() {}
  45188. void setTargetPosition (TreeViewItem* const item) throw()
  45189. {
  45190. Rectangle<int> r (item->getItemPosition (true));
  45191. r.setHeight (item->getItemHeight());
  45192. setBounds (r);
  45193. }
  45194. void paint (Graphics& g)
  45195. {
  45196. g.setColour (findColour (TreeView::dragAndDropIndicatorColourId, true));
  45197. g.drawRoundedRectangle (1.0f, 1.0f, getWidth() - 2.0f, getHeight() - 2.0f, 3.0f, 2.0f);
  45198. }
  45199. };
  45200. void TreeView::showDragHighlight (TreeViewItem* item, int insertIndex, int x, int y) throw()
  45201. {
  45202. beginDragAutoRepeat (1000 / 30);
  45203. if (dragInsertPointHighlight == 0)
  45204. {
  45205. addAndMakeVisible (dragInsertPointHighlight = new TreeViewDragInsertPointHighlight());
  45206. addAndMakeVisible (dragTargetGroupHighlight = new TreeViewDragTargetGroupHighlight());
  45207. }
  45208. ((TreeViewDragInsertPointHighlight*) dragInsertPointHighlight)
  45209. ->setTargetPosition (item, insertIndex, x, y, viewport->getViewWidth());
  45210. ((TreeViewDragTargetGroupHighlight*) dragTargetGroupHighlight)
  45211. ->setTargetPosition (item);
  45212. }
  45213. void TreeView::hideDragHighlight() throw()
  45214. {
  45215. deleteAndZero (dragInsertPointHighlight);
  45216. deleteAndZero (dragTargetGroupHighlight);
  45217. }
  45218. TreeViewItem* TreeView::getInsertPosition (int& x, int& y, int& insertIndex,
  45219. const StringArray& files, const String& sourceDescription,
  45220. Component* sourceComponent) const throw()
  45221. {
  45222. insertIndex = 0;
  45223. TreeViewItem* item = getItemAt (y);
  45224. if (item == 0)
  45225. return 0;
  45226. Rectangle<int> itemPos (item->getItemPosition (true));
  45227. insertIndex = item->getIndexInParent();
  45228. const int oldY = y;
  45229. y = itemPos.getY();
  45230. if (item->getNumSubItems() == 0 || ! item->isOpen())
  45231. {
  45232. if (files.size() > 0 ? item->isInterestedInFileDrag (files)
  45233. : item->isInterestedInDragSource (sourceDescription, sourceComponent))
  45234. {
  45235. // Check if we're trying to drag into an empty group item..
  45236. if (oldY > itemPos.getY() + itemPos.getHeight() / 4
  45237. && oldY < itemPos.getBottom() - itemPos.getHeight() / 4)
  45238. {
  45239. insertIndex = 0;
  45240. x = itemPos.getX() + getIndentSize();
  45241. y = itemPos.getBottom();
  45242. return item;
  45243. }
  45244. }
  45245. }
  45246. if (oldY > itemPos.getCentreY())
  45247. {
  45248. y += item->getItemHeight();
  45249. while (item->isLastOfSiblings() && item->parentItem != 0
  45250. && item->parentItem->parentItem != 0)
  45251. {
  45252. if (x > itemPos.getX())
  45253. break;
  45254. item = item->parentItem;
  45255. itemPos = item->getItemPosition (true);
  45256. insertIndex = item->getIndexInParent();
  45257. }
  45258. ++insertIndex;
  45259. }
  45260. x = itemPos.getX();
  45261. return item->parentItem;
  45262. }
  45263. void TreeView::handleDrag (const StringArray& files, const String& sourceDescription, Component* sourceComponent, int x, int y)
  45264. {
  45265. const bool scrolled = viewport->autoScroll (x, y, 20, 10);
  45266. int insertIndex;
  45267. TreeViewItem* const item = getInsertPosition (x, y, insertIndex, files, sourceDescription, sourceComponent);
  45268. if (item != 0)
  45269. {
  45270. if (scrolled || dragInsertPointHighlight == 0
  45271. || ((TreeViewDragInsertPointHighlight*) dragInsertPointHighlight)->lastItem != item
  45272. || ((TreeViewDragInsertPointHighlight*) dragInsertPointHighlight)->lastIndex != insertIndex)
  45273. {
  45274. if (files.size() > 0 ? item->isInterestedInFileDrag (files)
  45275. : item->isInterestedInDragSource (sourceDescription, sourceComponent))
  45276. showDragHighlight (item, insertIndex, x, y);
  45277. else
  45278. hideDragHighlight();
  45279. }
  45280. }
  45281. else
  45282. {
  45283. hideDragHighlight();
  45284. }
  45285. }
  45286. void TreeView::handleDrop (const StringArray& files, const String& sourceDescription, Component* sourceComponent, int x, int y)
  45287. {
  45288. hideDragHighlight();
  45289. int insertIndex;
  45290. TreeViewItem* const item = getInsertPosition (x, y, insertIndex, files, sourceDescription, sourceComponent);
  45291. if (item != 0)
  45292. {
  45293. if (files.size() > 0)
  45294. {
  45295. if (item->isInterestedInFileDrag (files))
  45296. item->filesDropped (files, insertIndex);
  45297. }
  45298. else
  45299. {
  45300. if (item->isInterestedInDragSource (sourceDescription, sourceComponent))
  45301. item->itemDropped (sourceDescription, sourceComponent, insertIndex);
  45302. }
  45303. }
  45304. }
  45305. bool TreeView::isInterestedInFileDrag (const StringArray&)
  45306. {
  45307. return true;
  45308. }
  45309. void TreeView::fileDragEnter (const StringArray& files, int x, int y)
  45310. {
  45311. fileDragMove (files, x, y);
  45312. }
  45313. void TreeView::fileDragMove (const StringArray& files, int x, int y)
  45314. {
  45315. handleDrag (files, String::empty, 0, x, y);
  45316. }
  45317. void TreeView::fileDragExit (const StringArray&)
  45318. {
  45319. hideDragHighlight();
  45320. }
  45321. void TreeView::filesDropped (const StringArray& files, int x, int y)
  45322. {
  45323. handleDrop (files, String::empty, 0, x, y);
  45324. }
  45325. bool TreeView::isInterestedInDragSource (const String& /*sourceDescription*/, Component* /*sourceComponent*/)
  45326. {
  45327. return true;
  45328. }
  45329. void TreeView::itemDragEnter (const String& sourceDescription, Component* sourceComponent, int x, int y)
  45330. {
  45331. itemDragMove (sourceDescription, sourceComponent, x, y);
  45332. }
  45333. void TreeView::itemDragMove (const String& sourceDescription, Component* sourceComponent, int x, int y)
  45334. {
  45335. handleDrag (StringArray(), sourceDescription, sourceComponent, x, y);
  45336. }
  45337. void TreeView::itemDragExit (const String& /*sourceDescription*/, Component* /*sourceComponent*/)
  45338. {
  45339. hideDragHighlight();
  45340. }
  45341. void TreeView::itemDropped (const String& sourceDescription, Component* sourceComponent, int x, int y)
  45342. {
  45343. handleDrop (StringArray(), sourceDescription, sourceComponent, x, y);
  45344. }
  45345. void TreeViewContentComponent::paint (Graphics& g)
  45346. {
  45347. if (owner->rootItem != 0)
  45348. {
  45349. owner->handleAsyncUpdate();
  45350. if (! owner->rootItemVisible)
  45351. g.setOrigin (0, -owner->rootItem->itemHeight);
  45352. owner->rootItem->paintRecursively (g, getWidth());
  45353. }
  45354. }
  45355. TreeViewItem* TreeViewContentComponent::findItemAt (int y, Rectangle<int>& itemPosition) const
  45356. {
  45357. if (owner->rootItem != 0)
  45358. {
  45359. owner->handleAsyncUpdate();
  45360. if (! owner->rootItemVisible)
  45361. y += owner->rootItem->itemHeight;
  45362. TreeViewItem* const ti = owner->rootItem->findItemRecursively (y);
  45363. if (ti != 0)
  45364. itemPosition = ti->getItemPosition (false);
  45365. return ti;
  45366. }
  45367. return 0;
  45368. }
  45369. enum TreeViewOpenness
  45370. {
  45371. opennessDefault = 0,
  45372. opennessClosed = 1,
  45373. opennessOpen = 2
  45374. };
  45375. TreeViewItem::TreeViewItem()
  45376. : ownerView (0),
  45377. parentItem (0),
  45378. y (0),
  45379. itemHeight (0),
  45380. totalHeight (0),
  45381. selected (false),
  45382. redrawNeeded (true),
  45383. drawLinesInside (true),
  45384. drawsInLeftMargin (false),
  45385. openness (opennessDefault)
  45386. {
  45387. static int nextUID = 0;
  45388. uid = nextUID++;
  45389. }
  45390. TreeViewItem::~TreeViewItem()
  45391. {
  45392. }
  45393. const String TreeViewItem::getUniqueName() const
  45394. {
  45395. return String::empty;
  45396. }
  45397. void TreeViewItem::itemOpennessChanged (bool)
  45398. {
  45399. }
  45400. int TreeViewItem::getNumSubItems() const throw()
  45401. {
  45402. return subItems.size();
  45403. }
  45404. TreeViewItem* TreeViewItem::getSubItem (const int index) const throw()
  45405. {
  45406. return subItems [index];
  45407. }
  45408. void TreeViewItem::clearSubItems()
  45409. {
  45410. if (subItems.size() > 0)
  45411. {
  45412. if (ownerView != 0)
  45413. {
  45414. const ScopedLock sl (ownerView->nodeAlterationLock);
  45415. subItems.clear();
  45416. treeHasChanged();
  45417. }
  45418. else
  45419. {
  45420. subItems.clear();
  45421. }
  45422. }
  45423. }
  45424. void TreeViewItem::addSubItem (TreeViewItem* const newItem, const int insertPosition)
  45425. {
  45426. if (newItem != 0)
  45427. {
  45428. newItem->parentItem = this;
  45429. newItem->setOwnerView (ownerView);
  45430. newItem->y = 0;
  45431. newItem->itemHeight = newItem->getItemHeight();
  45432. newItem->totalHeight = 0;
  45433. newItem->itemWidth = newItem->getItemWidth();
  45434. newItem->totalWidth = 0;
  45435. if (ownerView != 0)
  45436. {
  45437. const ScopedLock sl (ownerView->nodeAlterationLock);
  45438. subItems.insert (insertPosition, newItem);
  45439. treeHasChanged();
  45440. if (newItem->isOpen())
  45441. newItem->itemOpennessChanged (true);
  45442. }
  45443. else
  45444. {
  45445. subItems.insert (insertPosition, newItem);
  45446. if (newItem->isOpen())
  45447. newItem->itemOpennessChanged (true);
  45448. }
  45449. }
  45450. }
  45451. void TreeViewItem::removeSubItem (const int index, const bool deleteItem)
  45452. {
  45453. if (ownerView != 0)
  45454. ownerView->nodeAlterationLock.enter();
  45455. if (((unsigned int) index) < (unsigned int) subItems.size())
  45456. {
  45457. subItems.remove (index, deleteItem);
  45458. treeHasChanged();
  45459. }
  45460. if (ownerView != 0)
  45461. ownerView->nodeAlterationLock.exit();
  45462. }
  45463. bool TreeViewItem::isOpen() const throw()
  45464. {
  45465. if (openness == opennessDefault)
  45466. return ownerView != 0 && ownerView->defaultOpenness;
  45467. else
  45468. return openness == opennessOpen;
  45469. }
  45470. void TreeViewItem::setOpen (const bool shouldBeOpen)
  45471. {
  45472. if (isOpen() != shouldBeOpen)
  45473. {
  45474. openness = shouldBeOpen ? opennessOpen
  45475. : opennessClosed;
  45476. treeHasChanged();
  45477. itemOpennessChanged (isOpen());
  45478. }
  45479. }
  45480. bool TreeViewItem::isSelected() const throw()
  45481. {
  45482. return selected;
  45483. }
  45484. void TreeViewItem::deselectAllRecursively()
  45485. {
  45486. setSelected (false, false);
  45487. for (int i = 0; i < subItems.size(); ++i)
  45488. subItems.getUnchecked(i)->deselectAllRecursively();
  45489. }
  45490. void TreeViewItem::setSelected (const bool shouldBeSelected,
  45491. const bool deselectOtherItemsFirst)
  45492. {
  45493. if (shouldBeSelected && ! canBeSelected())
  45494. return;
  45495. if (deselectOtherItemsFirst)
  45496. getTopLevelItem()->deselectAllRecursively();
  45497. if (shouldBeSelected != selected)
  45498. {
  45499. selected = shouldBeSelected;
  45500. if (ownerView != 0)
  45501. ownerView->repaint();
  45502. itemSelectionChanged (shouldBeSelected);
  45503. }
  45504. }
  45505. void TreeViewItem::paintItem (Graphics&, int, int)
  45506. {
  45507. }
  45508. void TreeViewItem::paintOpenCloseButton (Graphics& g, int width, int height, bool isMouseOver)
  45509. {
  45510. ownerView->getLookAndFeel()
  45511. .drawTreeviewPlusMinusBox (g, 0, 0, width, height, ! isOpen(), isMouseOver);
  45512. }
  45513. void TreeViewItem::itemClicked (const MouseEvent&)
  45514. {
  45515. }
  45516. void TreeViewItem::itemDoubleClicked (const MouseEvent&)
  45517. {
  45518. if (mightContainSubItems())
  45519. setOpen (! isOpen());
  45520. }
  45521. void TreeViewItem::itemSelectionChanged (bool)
  45522. {
  45523. }
  45524. const String TreeViewItem::getTooltip()
  45525. {
  45526. return String::empty;
  45527. }
  45528. const String TreeViewItem::getDragSourceDescription()
  45529. {
  45530. return String::empty;
  45531. }
  45532. bool TreeViewItem::isInterestedInFileDrag (const StringArray&)
  45533. {
  45534. return false;
  45535. }
  45536. void TreeViewItem::filesDropped (const StringArray& /*files*/, int /*insertIndex*/)
  45537. {
  45538. }
  45539. bool TreeViewItem::isInterestedInDragSource (const String& /*sourceDescription*/, Component* /*sourceComponent*/)
  45540. {
  45541. return false;
  45542. }
  45543. void TreeViewItem::itemDropped (const String& /*sourceDescription*/, Component* /*sourceComponent*/, int /*insertIndex*/)
  45544. {
  45545. }
  45546. const Rectangle<int> TreeViewItem::getItemPosition (const bool relativeToTreeViewTopLeft) const throw()
  45547. {
  45548. const int indentX = getIndentX();
  45549. int width = itemWidth;
  45550. if (ownerView != 0 && width < 0)
  45551. width = ownerView->viewport->getViewWidth() - indentX;
  45552. Rectangle<int> r (indentX, y, jmax (0, width), totalHeight);
  45553. if (relativeToTreeViewTopLeft)
  45554. r.setPosition (r.getX() - ownerView->viewport->getViewPositionX(),
  45555. r.getY() - ownerView->viewport->getViewPositionY());
  45556. return r;
  45557. }
  45558. void TreeViewItem::treeHasChanged() const throw()
  45559. {
  45560. if (ownerView != 0)
  45561. ownerView->itemsChanged();
  45562. }
  45563. void TreeViewItem::repaintItem() const
  45564. {
  45565. if (ownerView != 0 && areAllParentsOpen())
  45566. {
  45567. const Rectangle<int> r (getItemPosition (true));
  45568. ownerView->viewport->repaint (0, r.getY(), r.getRight(), r.getHeight());
  45569. }
  45570. }
  45571. bool TreeViewItem::areAllParentsOpen() const throw()
  45572. {
  45573. return parentItem == 0
  45574. || (parentItem->isOpen() && parentItem->areAllParentsOpen());
  45575. }
  45576. void TreeViewItem::updatePositions (int newY)
  45577. {
  45578. y = newY;
  45579. itemHeight = getItemHeight();
  45580. totalHeight = itemHeight;
  45581. itemWidth = getItemWidth();
  45582. totalWidth = jmax (itemWidth, 0) + getIndentX();
  45583. if (isOpen())
  45584. {
  45585. newY += totalHeight;
  45586. for (int i = 0; i < subItems.size(); ++i)
  45587. {
  45588. TreeViewItem* const ti = subItems.getUnchecked(i);
  45589. ti->updatePositions (newY);
  45590. newY += ti->totalHeight;
  45591. totalHeight += ti->totalHeight;
  45592. totalWidth = jmax (totalWidth, ti->totalWidth);
  45593. }
  45594. }
  45595. }
  45596. TreeViewItem* TreeViewItem::getDeepestOpenParentItem() throw()
  45597. {
  45598. TreeViewItem* result = this;
  45599. TreeViewItem* item = this;
  45600. while (item->parentItem != 0)
  45601. {
  45602. item = item->parentItem;
  45603. if (! item->isOpen())
  45604. result = item;
  45605. }
  45606. return result;
  45607. }
  45608. void TreeViewItem::setOwnerView (TreeView* const newOwner) throw()
  45609. {
  45610. ownerView = newOwner;
  45611. for (int i = subItems.size(); --i >= 0;)
  45612. subItems.getUnchecked(i)->setOwnerView (newOwner);
  45613. }
  45614. int TreeViewItem::getIndentX() const throw()
  45615. {
  45616. const int indentWidth = ownerView->getIndentSize();
  45617. int x = ownerView->rootItemVisible ? indentWidth : 0;
  45618. if (! ownerView->openCloseButtonsVisible)
  45619. x -= indentWidth;
  45620. TreeViewItem* p = parentItem;
  45621. while (p != 0)
  45622. {
  45623. x += indentWidth;
  45624. p = p->parentItem;
  45625. }
  45626. return x;
  45627. }
  45628. void TreeViewItem::setDrawsInLeftMargin (bool canDrawInLeftMargin) throw()
  45629. {
  45630. drawsInLeftMargin = canDrawInLeftMargin;
  45631. }
  45632. void TreeViewItem::paintRecursively (Graphics& g, int width)
  45633. {
  45634. jassert (ownerView != 0);
  45635. if (ownerView == 0)
  45636. return;
  45637. const int indent = getIndentX();
  45638. const int itemW = itemWidth < 0 ? width - indent : itemWidth;
  45639. g.setColour (ownerView->findColour (TreeView::linesColourId));
  45640. const float halfH = itemHeight * 0.5f;
  45641. int depth = 0;
  45642. TreeViewItem* p = parentItem;
  45643. while (p != 0)
  45644. {
  45645. ++depth;
  45646. p = p->parentItem;
  45647. }
  45648. if (! ownerView->rootItemVisible)
  45649. --depth;
  45650. const int indentWidth = ownerView->getIndentSize();
  45651. if (depth >= 0 && ownerView->openCloseButtonsVisible)
  45652. {
  45653. float x = (depth + 0.5f) * indentWidth;
  45654. if (depth >= 0)
  45655. {
  45656. if (parentItem != 0 && parentItem->drawLinesInside)
  45657. g.drawLine (x, 0, x, isLastOfSiblings() ? halfH : (float) itemHeight);
  45658. if ((parentItem != 0 && parentItem->drawLinesInside)
  45659. || (parentItem == 0 && drawLinesInside))
  45660. g.drawLine (x, halfH, x + indentWidth / 2, halfH);
  45661. }
  45662. p = parentItem;
  45663. int d = depth;
  45664. while (p != 0 && --d >= 0)
  45665. {
  45666. x -= (float) indentWidth;
  45667. if ((p->parentItem == 0 || p->parentItem->drawLinesInside)
  45668. && ! p->isLastOfSiblings())
  45669. {
  45670. g.drawLine (x, 0, x, (float) itemHeight);
  45671. }
  45672. p = p->parentItem;
  45673. }
  45674. if (mightContainSubItems())
  45675. {
  45676. g.saveState();
  45677. g.setOrigin (depth * indentWidth, 0);
  45678. g.reduceClipRegion (0, 0, indentWidth, itemHeight);
  45679. paintOpenCloseButton (g, indentWidth, itemHeight,
  45680. ((TreeViewContentComponent*) ownerView->viewport->getViewedComponent())
  45681. ->isMouseOverButton (this));
  45682. g.restoreState();
  45683. }
  45684. }
  45685. {
  45686. g.saveState();
  45687. g.setOrigin (indent, 0);
  45688. if (g.reduceClipRegion (drawsInLeftMargin ? -indent : 0, 0,
  45689. drawsInLeftMargin ? itemW + indent : itemW, itemHeight))
  45690. paintItem (g, itemW, itemHeight);
  45691. g.restoreState();
  45692. }
  45693. if (isOpen())
  45694. {
  45695. const Rectangle<int> clip (g.getClipBounds());
  45696. for (int i = 0; i < subItems.size(); ++i)
  45697. {
  45698. TreeViewItem* const ti = subItems.getUnchecked(i);
  45699. const int relY = ti->y - y;
  45700. if (relY >= clip.getBottom())
  45701. break;
  45702. if (relY + ti->totalHeight >= clip.getY())
  45703. {
  45704. g.saveState();
  45705. g.setOrigin (0, relY);
  45706. if (g.reduceClipRegion (0, 0, width, ti->totalHeight))
  45707. ti->paintRecursively (g, width);
  45708. g.restoreState();
  45709. }
  45710. }
  45711. }
  45712. }
  45713. bool TreeViewItem::isLastOfSiblings() const throw()
  45714. {
  45715. return parentItem == 0
  45716. || parentItem->subItems.getLast() == this;
  45717. }
  45718. int TreeViewItem::getIndexInParent() const throw()
  45719. {
  45720. if (parentItem == 0)
  45721. return 0;
  45722. return parentItem->subItems.indexOf (this);
  45723. }
  45724. TreeViewItem* TreeViewItem::getTopLevelItem() throw()
  45725. {
  45726. return (parentItem == 0) ? this
  45727. : parentItem->getTopLevelItem();
  45728. }
  45729. int TreeViewItem::getNumRows() const throw()
  45730. {
  45731. int num = 1;
  45732. if (isOpen())
  45733. {
  45734. for (int i = subItems.size(); --i >= 0;)
  45735. num += subItems.getUnchecked(i)->getNumRows();
  45736. }
  45737. return num;
  45738. }
  45739. TreeViewItem* TreeViewItem::getItemOnRow (int index) throw()
  45740. {
  45741. if (index == 0)
  45742. return this;
  45743. if (index > 0 && isOpen())
  45744. {
  45745. --index;
  45746. for (int i = 0; i < subItems.size(); ++i)
  45747. {
  45748. TreeViewItem* const item = subItems.getUnchecked(i);
  45749. if (index == 0)
  45750. return item;
  45751. const int numRows = item->getNumRows();
  45752. if (numRows > index)
  45753. return item->getItemOnRow (index);
  45754. index -= numRows;
  45755. }
  45756. }
  45757. return 0;
  45758. }
  45759. TreeViewItem* TreeViewItem::findItemRecursively (int targetY) throw()
  45760. {
  45761. if (((unsigned int) targetY) < (unsigned int) totalHeight)
  45762. {
  45763. const int h = itemHeight;
  45764. if (targetY < h)
  45765. return this;
  45766. if (isOpen())
  45767. {
  45768. targetY -= h;
  45769. for (int i = 0; i < subItems.size(); ++i)
  45770. {
  45771. TreeViewItem* const ti = subItems.getUnchecked(i);
  45772. if (targetY < ti->totalHeight)
  45773. return ti->findItemRecursively (targetY);
  45774. targetY -= ti->totalHeight;
  45775. }
  45776. }
  45777. }
  45778. return 0;
  45779. }
  45780. int TreeViewItem::countSelectedItemsRecursively() const throw()
  45781. {
  45782. int total = 0;
  45783. if (isSelected())
  45784. ++total;
  45785. for (int i = subItems.size(); --i >= 0;)
  45786. total += subItems.getUnchecked(i)->countSelectedItemsRecursively();
  45787. return total;
  45788. }
  45789. TreeViewItem* TreeViewItem::getSelectedItemWithIndex (int index) throw()
  45790. {
  45791. if (isSelected())
  45792. {
  45793. if (index == 0)
  45794. return this;
  45795. --index;
  45796. }
  45797. if (index >= 0)
  45798. {
  45799. for (int i = 0; i < subItems.size(); ++i)
  45800. {
  45801. TreeViewItem* const item = subItems.getUnchecked(i);
  45802. TreeViewItem* const found = item->getSelectedItemWithIndex (index);
  45803. if (found != 0)
  45804. return found;
  45805. index -= item->countSelectedItemsRecursively();
  45806. }
  45807. }
  45808. return 0;
  45809. }
  45810. int TreeViewItem::getRowNumberInTree() const throw()
  45811. {
  45812. if (parentItem != 0 && ownerView != 0)
  45813. {
  45814. int n = 1 + parentItem->getRowNumberInTree();
  45815. int ourIndex = parentItem->subItems.indexOf (this);
  45816. jassert (ourIndex >= 0);
  45817. while (--ourIndex >= 0)
  45818. n += parentItem->subItems [ourIndex]->getNumRows();
  45819. if (parentItem->parentItem == 0
  45820. && ! ownerView->rootItemVisible)
  45821. --n;
  45822. return n;
  45823. }
  45824. else
  45825. {
  45826. return 0;
  45827. }
  45828. }
  45829. void TreeViewItem::setLinesDrawnForSubItems (const bool drawLines) throw()
  45830. {
  45831. drawLinesInside = drawLines;
  45832. }
  45833. TreeViewItem* TreeViewItem::getNextVisibleItem (const bool recurse) const throw()
  45834. {
  45835. if (recurse && isOpen() && subItems.size() > 0)
  45836. return subItems [0];
  45837. if (parentItem != 0)
  45838. {
  45839. const int nextIndex = parentItem->subItems.indexOf (this) + 1;
  45840. if (nextIndex >= parentItem->subItems.size())
  45841. return parentItem->getNextVisibleItem (false);
  45842. return parentItem->subItems [nextIndex];
  45843. }
  45844. return 0;
  45845. }
  45846. const String TreeViewItem::getItemIdentifierString() const
  45847. {
  45848. String s;
  45849. if (parentItem != 0)
  45850. s = parentItem->getItemIdentifierString();
  45851. return s + T("/") + getUniqueName().replaceCharacter (T('/'), T('\\'));
  45852. }
  45853. TreeViewItem* TreeViewItem::findItemFromIdentifierString (const String& identifierString)
  45854. {
  45855. const String uid (getUniqueName());
  45856. if (uid == identifierString)
  45857. return this;
  45858. if (identifierString.startsWith (uid + T("/")))
  45859. {
  45860. const String remainingPath (identifierString.substring (uid.length() + 1));
  45861. bool wasOpen = isOpen();
  45862. setOpen (true);
  45863. for (int i = subItems.size(); --i >= 0;)
  45864. {
  45865. TreeViewItem* item = subItems.getUnchecked(i)->findItemFromIdentifierString (remainingPath);
  45866. if (item != 0)
  45867. return item;
  45868. }
  45869. setOpen (wasOpen);
  45870. }
  45871. return 0;
  45872. }
  45873. void TreeViewItem::restoreOpennessState (const XmlElement& e) throw()
  45874. {
  45875. if (e.hasTagName (T("CLOSED")))
  45876. {
  45877. setOpen (false);
  45878. }
  45879. else if (e.hasTagName (T("OPEN")))
  45880. {
  45881. setOpen (true);
  45882. forEachXmlChildElement (e, n)
  45883. {
  45884. const String id (n->getStringAttribute (T("id")));
  45885. for (int i = 0; i < subItems.size(); ++i)
  45886. {
  45887. TreeViewItem* const ti = subItems.getUnchecked(i);
  45888. if (ti->getUniqueName() == id)
  45889. {
  45890. ti->restoreOpennessState (*n);
  45891. break;
  45892. }
  45893. }
  45894. }
  45895. }
  45896. }
  45897. XmlElement* TreeViewItem::getOpennessState() const throw()
  45898. {
  45899. const String name (getUniqueName());
  45900. if (name.isNotEmpty())
  45901. {
  45902. XmlElement* e;
  45903. if (isOpen())
  45904. {
  45905. e = new XmlElement (T("OPEN"));
  45906. for (int i = 0; i < subItems.size(); ++i)
  45907. e->addChildElement (subItems.getUnchecked(i)->getOpennessState());
  45908. }
  45909. else
  45910. {
  45911. e = new XmlElement (T("CLOSED"));
  45912. }
  45913. e->setAttribute (T("id"), name);
  45914. return e;
  45915. }
  45916. else
  45917. {
  45918. // trying to save the openness for an element that has no name - this won't
  45919. // work because it needs the names to identify what to open.
  45920. jassertfalse
  45921. }
  45922. return 0;
  45923. }
  45924. END_JUCE_NAMESPACE
  45925. /*** End of inlined file: juce_TreeView.cpp ***/
  45926. /*** Start of inlined file: juce_DirectoryContentsDisplayComponent.cpp ***/
  45927. BEGIN_JUCE_NAMESPACE
  45928. DirectoryContentsDisplayComponent::DirectoryContentsDisplayComponent (DirectoryContentsList& listToShow)
  45929. : fileList (listToShow)
  45930. {
  45931. }
  45932. DirectoryContentsDisplayComponent::~DirectoryContentsDisplayComponent()
  45933. {
  45934. }
  45935. FileBrowserListener::~FileBrowserListener()
  45936. {
  45937. }
  45938. void DirectoryContentsDisplayComponent::addListener (FileBrowserListener* const listener) throw()
  45939. {
  45940. jassert (listener != 0);
  45941. if (listener != 0)
  45942. listeners.add (listener);
  45943. }
  45944. void DirectoryContentsDisplayComponent::removeListener (FileBrowserListener* const listener) throw()
  45945. {
  45946. listeners.removeValue (listener);
  45947. }
  45948. void DirectoryContentsDisplayComponent::sendSelectionChangeMessage()
  45949. {
  45950. const ComponentDeletionWatcher deletionWatcher (dynamic_cast <Component*> (this));
  45951. for (int i = listeners.size(); --i >= 0;)
  45952. {
  45953. ((FileBrowserListener*) listeners.getUnchecked (i))->selectionChanged();
  45954. if (deletionWatcher.hasBeenDeleted())
  45955. return;
  45956. i = jmin (i, listeners.size() - 1);
  45957. }
  45958. }
  45959. void DirectoryContentsDisplayComponent::sendMouseClickMessage (const File& file, const MouseEvent& e)
  45960. {
  45961. if (fileList.getDirectory().exists())
  45962. {
  45963. const ComponentDeletionWatcher deletionWatcher (dynamic_cast <Component*> (this));
  45964. for (int i = listeners.size(); --i >= 0;)
  45965. {
  45966. ((FileBrowserListener*) listeners.getUnchecked (i))->fileClicked (file, e);
  45967. if (deletionWatcher.hasBeenDeleted())
  45968. return;
  45969. i = jmin (i, listeners.size() - 1);
  45970. }
  45971. }
  45972. }
  45973. void DirectoryContentsDisplayComponent::sendDoubleClickMessage (const File& file)
  45974. {
  45975. if (fileList.getDirectory().exists())
  45976. {
  45977. const ComponentDeletionWatcher deletionWatcher (dynamic_cast <Component*> (this));
  45978. for (int i = listeners.size(); --i >= 0;)
  45979. {
  45980. ((FileBrowserListener*) listeners.getUnchecked (i))->fileDoubleClicked (file);
  45981. if (deletionWatcher.hasBeenDeleted())
  45982. return;
  45983. i = jmin (i, listeners.size() - 1);
  45984. }
  45985. }
  45986. }
  45987. END_JUCE_NAMESPACE
  45988. /*** End of inlined file: juce_DirectoryContentsDisplayComponent.cpp ***/
  45989. /*** Start of inlined file: juce_DirectoryContentsList.cpp ***/
  45990. BEGIN_JUCE_NAMESPACE
  45991. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  45992. bool* isDirectory, bool* isHidden, int64* fileSize, Time* modTime,
  45993. Time* creationTime, bool* isReadOnly);
  45994. bool juce_findFileNext (void* handle, String& resultFile,
  45995. bool* isDirectory, bool* isHidden, int64* fileSize,
  45996. Time* modTime, Time* creationTime, bool* isReadOnly);
  45997. void juce_findFileClose (void* handle);
  45998. DirectoryContentsList::DirectoryContentsList (const FileFilter* const fileFilter_,
  45999. TimeSliceThread& thread_)
  46000. : fileFilter (fileFilter_),
  46001. thread (thread_),
  46002. includeDirectories (false),
  46003. includeFiles (false),
  46004. ignoreHiddenFiles (true),
  46005. fileFindHandle (0),
  46006. shouldStop (true)
  46007. {
  46008. }
  46009. DirectoryContentsList::~DirectoryContentsList()
  46010. {
  46011. clear();
  46012. }
  46013. void DirectoryContentsList::setIgnoresHiddenFiles (const bool shouldIgnoreHiddenFiles)
  46014. {
  46015. ignoreHiddenFiles = shouldIgnoreHiddenFiles;
  46016. }
  46017. const File& DirectoryContentsList::getDirectory() const
  46018. {
  46019. return root;
  46020. }
  46021. void DirectoryContentsList::setDirectory (const File& directory,
  46022. const bool includeDirectories_,
  46023. const bool includeFiles_)
  46024. {
  46025. if (directory != root
  46026. || includeDirectories != includeDirectories_
  46027. || includeFiles != includeFiles_)
  46028. {
  46029. clear();
  46030. root = directory;
  46031. includeDirectories = includeDirectories_;
  46032. includeFiles = includeFiles_;
  46033. refresh();
  46034. }
  46035. }
  46036. void DirectoryContentsList::clear()
  46037. {
  46038. shouldStop = true;
  46039. thread.removeTimeSliceClient (this);
  46040. if (fileFindHandle != 0)
  46041. {
  46042. juce_findFileClose (fileFindHandle);
  46043. fileFindHandle = 0;
  46044. }
  46045. if (files.size() > 0)
  46046. {
  46047. files.clear();
  46048. changed();
  46049. }
  46050. }
  46051. void DirectoryContentsList::refresh()
  46052. {
  46053. clear();
  46054. if (root.isDirectory())
  46055. {
  46056. String fileFound;
  46057. bool fileFoundIsDir, isHidden, isReadOnly;
  46058. int64 fileSize;
  46059. Time modTime, creationTime;
  46060. String path (root.getFullPathName());
  46061. if (! path.endsWithChar (File::separator))
  46062. path += File::separator;
  46063. jassert (fileFindHandle == 0);
  46064. fileFindHandle = juce_findFileStart (path, T("*"), fileFound,
  46065. &fileFoundIsDir,
  46066. &isHidden,
  46067. &fileSize,
  46068. &modTime,
  46069. &creationTime,
  46070. &isReadOnly);
  46071. if (fileFindHandle != 0 && fileFound.isNotEmpty())
  46072. {
  46073. if (addFile (fileFound, fileFoundIsDir, isHidden,
  46074. fileSize, modTime, creationTime, isReadOnly))
  46075. {
  46076. changed();
  46077. }
  46078. }
  46079. shouldStop = false;
  46080. thread.addTimeSliceClient (this);
  46081. }
  46082. }
  46083. int DirectoryContentsList::getNumFiles() const
  46084. {
  46085. return files.size();
  46086. }
  46087. bool DirectoryContentsList::getFileInfo (const int index,
  46088. FileInfo& result) const
  46089. {
  46090. const ScopedLock sl (fileListLock);
  46091. const FileInfo* const info = files [index];
  46092. if (info != 0)
  46093. {
  46094. result = *info;
  46095. return true;
  46096. }
  46097. return false;
  46098. }
  46099. const File DirectoryContentsList::getFile (const int index) const
  46100. {
  46101. const ScopedLock sl (fileListLock);
  46102. const FileInfo* const info = files [index];
  46103. if (info != 0)
  46104. return root.getChildFile (info->filename);
  46105. return File::nonexistent;
  46106. }
  46107. bool DirectoryContentsList::isStillLoading() const
  46108. {
  46109. return fileFindHandle != 0;
  46110. }
  46111. void DirectoryContentsList::changed()
  46112. {
  46113. sendChangeMessage (this);
  46114. }
  46115. bool DirectoryContentsList::useTimeSlice()
  46116. {
  46117. const uint32 startTime = Time::getApproximateMillisecondCounter();
  46118. bool hasChanged = false;
  46119. for (int i = 100; --i >= 0;)
  46120. {
  46121. if (! checkNextFile (hasChanged))
  46122. {
  46123. if (hasChanged)
  46124. changed();
  46125. return false;
  46126. }
  46127. if (shouldStop || (Time::getApproximateMillisecondCounter() > startTime + 150))
  46128. break;
  46129. }
  46130. if (hasChanged)
  46131. changed();
  46132. return true;
  46133. }
  46134. bool DirectoryContentsList::checkNextFile (bool& hasChanged)
  46135. {
  46136. if (fileFindHandle != 0)
  46137. {
  46138. String fileFound;
  46139. bool fileFoundIsDir, isHidden, isReadOnly;
  46140. int64 fileSize;
  46141. Time modTime, creationTime;
  46142. if (juce_findFileNext (fileFindHandle, fileFound,
  46143. &fileFoundIsDir, &isHidden,
  46144. &fileSize,
  46145. &modTime,
  46146. &creationTime,
  46147. &isReadOnly))
  46148. {
  46149. if (addFile (fileFound, fileFoundIsDir, isHidden, fileSize,
  46150. modTime, creationTime, isReadOnly))
  46151. {
  46152. hasChanged = true;
  46153. }
  46154. return true;
  46155. }
  46156. else
  46157. {
  46158. juce_findFileClose (fileFindHandle);
  46159. fileFindHandle = 0;
  46160. }
  46161. }
  46162. return false;
  46163. }
  46164. int DirectoryContentsList::compareElements (const DirectoryContentsList::FileInfo* const first,
  46165. const DirectoryContentsList::FileInfo* const second)
  46166. {
  46167. #if JUCE_WINDOWS
  46168. if (first->isDirectory != second->isDirectory)
  46169. return first->isDirectory ? -1 : 1;
  46170. #endif
  46171. return first->filename.compareIgnoreCase (second->filename);
  46172. }
  46173. bool DirectoryContentsList::addFile (const String& filename,
  46174. const bool isDir,
  46175. const bool isHidden,
  46176. const int64 fileSize,
  46177. const Time& modTime,
  46178. const Time& creationTime,
  46179. const bool isReadOnly)
  46180. {
  46181. if (filename == T("..")
  46182. || filename == T(".")
  46183. || (ignoreHiddenFiles && isHidden))
  46184. return false;
  46185. const File file (root.getChildFile (filename));
  46186. if (((isDir && includeDirectories) || ((! isDir) && includeFiles))
  46187. && (fileFilter == 0
  46188. || ((! isDir) && fileFilter->isFileSuitable (file))
  46189. || (isDir && fileFilter->isDirectorySuitable (file))))
  46190. {
  46191. ScopedPointer <FileInfo> info (new FileInfo());
  46192. info->filename = filename;
  46193. info->fileSize = fileSize;
  46194. info->modificationTime = modTime;
  46195. info->creationTime = creationTime;
  46196. info->isDirectory = isDir;
  46197. info->isReadOnly = isReadOnly;
  46198. const ScopedLock sl (fileListLock);
  46199. for (int i = files.size(); --i >= 0;)
  46200. if (files.getUnchecked(i)->filename == info->filename)
  46201. return false;
  46202. files.addSorted (*this, info.release());
  46203. return true;
  46204. }
  46205. return false;
  46206. }
  46207. END_JUCE_NAMESPACE
  46208. /*** End of inlined file: juce_DirectoryContentsList.cpp ***/
  46209. /*** Start of inlined file: juce_FileBrowserComponent.cpp ***/
  46210. BEGIN_JUCE_NAMESPACE
  46211. FileBrowserComponent::FileBrowserComponent (int flags_,
  46212. const File& initialFileOrDirectory,
  46213. const FileFilter* fileFilter_,
  46214. FilePreviewComponent* previewComp_)
  46215. : FileFilter (String::empty),
  46216. fileFilter (fileFilter_),
  46217. flags (flags_),
  46218. previewComp (previewComp_),
  46219. thread ("Juce FileBrowser")
  46220. {
  46221. // You need to specify one or other of the open/save flags..
  46222. jassert ((flags & (saveMode | openMode)) != 0);
  46223. jassert ((flags & (saveMode | openMode)) != (saveMode | openMode));
  46224. // You need to specify at least one of these flags..
  46225. jassert ((flags & (canSelectFiles | canSelectDirectories)) != 0);
  46226. String filename;
  46227. if (initialFileOrDirectory == File::nonexistent)
  46228. {
  46229. currentRoot = File::getCurrentWorkingDirectory();
  46230. }
  46231. else if (initialFileOrDirectory.isDirectory())
  46232. {
  46233. currentRoot = initialFileOrDirectory;
  46234. }
  46235. else
  46236. {
  46237. chosenFiles.add (initialFileOrDirectory);
  46238. currentRoot = initialFileOrDirectory.getParentDirectory();
  46239. filename = initialFileOrDirectory.getFileName();
  46240. }
  46241. fileList = new DirectoryContentsList (this, thread);
  46242. if ((flags & useTreeView) != 0)
  46243. {
  46244. FileTreeComponent* const tree = new FileTreeComponent (*fileList);
  46245. if ((flags & canSelectMultipleItems) != 0)
  46246. tree->setMultiSelectEnabled (true);
  46247. addAndMakeVisible (tree);
  46248. fileListComponent = tree;
  46249. }
  46250. else
  46251. {
  46252. FileListComponent* const list = new FileListComponent (*fileList);
  46253. list->setOutlineThickness (1);
  46254. if ((flags & canSelectMultipleItems) != 0)
  46255. list->setMultipleSelectionEnabled (true);
  46256. addAndMakeVisible (list);
  46257. fileListComponent = list;
  46258. }
  46259. fileListComponent->addListener (this);
  46260. addAndMakeVisible (currentPathBox = new ComboBox ("path"));
  46261. currentPathBox->setEditableText (true);
  46262. StringArray rootNames, rootPaths;
  46263. const BitArray separators (getRoots (rootNames, rootPaths));
  46264. for (int i = 0; i < rootNames.size(); ++i)
  46265. {
  46266. if (separators [i])
  46267. currentPathBox->addSeparator();
  46268. currentPathBox->addItem (rootNames[i], i + 1);
  46269. }
  46270. currentPathBox->addSeparator();
  46271. currentPathBox->addListener (this);
  46272. addAndMakeVisible (filenameBox = new TextEditor());
  46273. filenameBox->setMultiLine (false);
  46274. filenameBox->setSelectAllWhenFocused (true);
  46275. filenameBox->setText (filename, false);
  46276. filenameBox->addListener (this);
  46277. filenameBox->setReadOnly ((flags & (filenameBoxIsReadOnly | canSelectMultipleItems)) != 0);
  46278. Label* label = new Label ("f", TRANS("file:"));
  46279. addAndMakeVisible (label);
  46280. label->attachToComponent (filenameBox, true);
  46281. addAndMakeVisible (goUpButton = getLookAndFeel().createFileBrowserGoUpButton());
  46282. goUpButton->addButtonListener (this);
  46283. goUpButton->setTooltip (TRANS ("go up to parent directory"));
  46284. if (previewComp != 0)
  46285. addAndMakeVisible (previewComp);
  46286. setRoot (currentRoot);
  46287. thread.startThread (4);
  46288. }
  46289. FileBrowserComponent::~FileBrowserComponent()
  46290. {
  46291. if (previewComp != 0)
  46292. removeChildComponent (previewComp);
  46293. deleteAllChildren();
  46294. fileList = 0;
  46295. thread.stopThread (10000);
  46296. }
  46297. void FileBrowserComponent::addListener (FileBrowserListener* const newListener) throw()
  46298. {
  46299. jassert (newListener != 0)
  46300. if (newListener != 0)
  46301. listeners.add (newListener);
  46302. }
  46303. void FileBrowserComponent::removeListener (FileBrowserListener* const listener) throw()
  46304. {
  46305. listeners.removeValue (listener);
  46306. }
  46307. bool FileBrowserComponent::isSaveMode() const throw()
  46308. {
  46309. return (flags & saveMode) != 0;
  46310. }
  46311. int FileBrowserComponent::getNumSelectedFiles() const throw()
  46312. {
  46313. if (chosenFiles.size() == 0 && currentFileIsValid())
  46314. return 1;
  46315. return chosenFiles.size();
  46316. }
  46317. const File FileBrowserComponent::getSelectedFile (int index) const throw()
  46318. {
  46319. if (! filenameBox->isReadOnly())
  46320. return currentRoot.getChildFile (filenameBox->getText());
  46321. else
  46322. return chosenFiles[index];
  46323. }
  46324. bool FileBrowserComponent::currentFileIsValid() const
  46325. {
  46326. if (isSaveMode())
  46327. return ! getSelectedFile (0).isDirectory();
  46328. else
  46329. return getSelectedFile (0).exists();
  46330. }
  46331. const File FileBrowserComponent::getHighlightedFile() const throw()
  46332. {
  46333. return fileListComponent->getSelectedFile (0);
  46334. }
  46335. bool FileBrowserComponent::isFileSuitable (const File& file) const
  46336. {
  46337. return (flags & canSelectFiles) != 0 ? (fileFilter == 0 || fileFilter->isFileSuitable (file))
  46338. : false;
  46339. }
  46340. bool FileBrowserComponent::isDirectorySuitable (const File&) const
  46341. {
  46342. return true;
  46343. }
  46344. bool FileBrowserComponent::isFileOrDirSuitable (const File& f) const
  46345. {
  46346. if (f.isDirectory())
  46347. return (flags & canSelectDirectories) != 0 && (fileFilter == 0 || fileFilter->isDirectorySuitable (f));
  46348. return (flags & canSelectFiles) != 0 && f.exists()
  46349. && (fileFilter == 0 || fileFilter->isFileSuitable (f));
  46350. }
  46351. const File FileBrowserComponent::getRoot() const
  46352. {
  46353. return currentRoot;
  46354. }
  46355. void FileBrowserComponent::setRoot (const File& newRootDirectory)
  46356. {
  46357. if (currentRoot != newRootDirectory)
  46358. {
  46359. fileListComponent->scrollToTop();
  46360. String path (newRootDirectory.getFullPathName());
  46361. if (path.isEmpty())
  46362. path += File::separator;
  46363. StringArray rootNames, rootPaths;
  46364. getRoots (rootNames, rootPaths);
  46365. if (! rootPaths.contains (path, true))
  46366. {
  46367. bool alreadyListed = false;
  46368. for (int i = currentPathBox->getNumItems(); --i >= 0;)
  46369. {
  46370. if (currentPathBox->getItemText (i).equalsIgnoreCase (path))
  46371. {
  46372. alreadyListed = true;
  46373. break;
  46374. }
  46375. }
  46376. if (! alreadyListed)
  46377. currentPathBox->addItem (path, currentPathBox->getNumItems() + 2);
  46378. }
  46379. }
  46380. currentRoot = newRootDirectory;
  46381. fileList->setDirectory (currentRoot, true, true);
  46382. String currentRootName (currentRoot.getFullPathName());
  46383. if (currentRootName.isEmpty())
  46384. currentRootName += File::separator;
  46385. currentPathBox->setText (currentRootName, true);
  46386. goUpButton->setEnabled (currentRoot.getParentDirectory().isDirectory()
  46387. && currentRoot.getParentDirectory() != currentRoot);
  46388. }
  46389. void FileBrowserComponent::goUp()
  46390. {
  46391. setRoot (getRoot().getParentDirectory());
  46392. }
  46393. void FileBrowserComponent::refresh()
  46394. {
  46395. fileList->refresh();
  46396. }
  46397. const String FileBrowserComponent::getActionVerb() const
  46398. {
  46399. return isSaveMode() ? TRANS("Save") : TRANS("Open");
  46400. }
  46401. FilePreviewComponent* FileBrowserComponent::getPreviewComponent() const throw()
  46402. {
  46403. return previewComp;
  46404. }
  46405. void FileBrowserComponent::resized()
  46406. {
  46407. getLookAndFeel()
  46408. .layoutFileBrowserComponent (*this, fileListComponent,
  46409. previewComp, currentPathBox,
  46410. filenameBox, goUpButton);
  46411. }
  46412. void FileBrowserComponent::sendListenerChangeMessage()
  46413. {
  46414. ComponentDeletionWatcher deletionWatcher (this);
  46415. if (previewComp != 0)
  46416. previewComp->selectedFileChanged (getSelectedFile (0));
  46417. jassert (! deletionWatcher.hasBeenDeleted());
  46418. for (int i = listeners.size(); --i >= 0;)
  46419. {
  46420. ((FileBrowserListener*) listeners.getUnchecked (i))->selectionChanged();
  46421. if (deletionWatcher.hasBeenDeleted())
  46422. return;
  46423. i = jmin (i, listeners.size() - 1);
  46424. }
  46425. }
  46426. void FileBrowserComponent::selectionChanged()
  46427. {
  46428. StringArray newFilenames;
  46429. bool resetChosenFiles = true;
  46430. for (int i = 0; i < fileListComponent->getNumSelectedFiles(); ++i)
  46431. {
  46432. const File f (fileListComponent->getSelectedFile (i));
  46433. if (isFileOrDirSuitable (f))
  46434. {
  46435. if (resetChosenFiles)
  46436. {
  46437. chosenFiles.clear();
  46438. resetChosenFiles = false;
  46439. }
  46440. chosenFiles.add (f);
  46441. newFilenames.add (f.getRelativePathFrom (getRoot()));
  46442. }
  46443. }
  46444. if (newFilenames.size() > 0)
  46445. filenameBox->setText (newFilenames.joinIntoString (T(", ")), false);
  46446. sendListenerChangeMessage();
  46447. }
  46448. void FileBrowserComponent::fileClicked (const File& f, const MouseEvent& e)
  46449. {
  46450. ComponentDeletionWatcher deletionWatcher (this);
  46451. for (int i = listeners.size(); --i >= 0;)
  46452. {
  46453. ((FileBrowserListener*) listeners.getUnchecked (i))->fileClicked (f, e);
  46454. if (deletionWatcher.hasBeenDeleted())
  46455. return;
  46456. i = jmin (i, listeners.size() - 1);
  46457. }
  46458. }
  46459. void FileBrowserComponent::fileDoubleClicked (const File& f)
  46460. {
  46461. if (f.isDirectory())
  46462. {
  46463. setRoot (f);
  46464. }
  46465. else
  46466. {
  46467. ComponentDeletionWatcher deletionWatcher (this);
  46468. for (int i = listeners.size(); --i >= 0;)
  46469. {
  46470. ((FileBrowserListener*) listeners.getUnchecked (i))->fileDoubleClicked (f);
  46471. if (deletionWatcher.hasBeenDeleted())
  46472. return;
  46473. i = jmin (i, listeners.size() - 1);
  46474. }
  46475. }
  46476. }
  46477. bool FileBrowserComponent::keyPressed (const KeyPress& key)
  46478. {
  46479. #if JUCE_LINUX || JUCE_WINDOWS
  46480. if (key.getModifiers().isCommandDown()
  46481. && (key.getKeyCode() == 'H' || key.getKeyCode() == 'h'))
  46482. {
  46483. fileList->setIgnoresHiddenFiles (! fileList->ignoresHiddenFiles());
  46484. fileList->refresh();
  46485. return true;
  46486. }
  46487. #endif
  46488. return false;
  46489. }
  46490. void FileBrowserComponent::textEditorTextChanged (TextEditor&)
  46491. {
  46492. sendListenerChangeMessage();
  46493. }
  46494. void FileBrowserComponent::textEditorReturnKeyPressed (TextEditor&)
  46495. {
  46496. if (filenameBox->getText().containsChar (File::separator))
  46497. {
  46498. const File f (currentRoot.getChildFile (filenameBox->getText()));
  46499. if (f.isDirectory())
  46500. {
  46501. setRoot (f);
  46502. chosenFiles.clear();
  46503. filenameBox->setText (String::empty);
  46504. }
  46505. else
  46506. {
  46507. setRoot (f.getParentDirectory());
  46508. chosenFiles.clear();
  46509. chosenFiles.add (f);
  46510. filenameBox->setText (f.getFileName());
  46511. }
  46512. }
  46513. else
  46514. {
  46515. fileDoubleClicked (getSelectedFile (0));
  46516. }
  46517. }
  46518. void FileBrowserComponent::textEditorEscapeKeyPressed (TextEditor&)
  46519. {
  46520. }
  46521. void FileBrowserComponent::textEditorFocusLost (TextEditor&)
  46522. {
  46523. if (! isSaveMode())
  46524. selectionChanged();
  46525. }
  46526. void FileBrowserComponent::buttonClicked (Button*)
  46527. {
  46528. goUp();
  46529. }
  46530. void FileBrowserComponent::comboBoxChanged (ComboBox*)
  46531. {
  46532. const String newText (currentPathBox->getText().trim().unquoted());
  46533. if (newText.isNotEmpty())
  46534. {
  46535. const int index = currentPathBox->getSelectedId() - 1;
  46536. StringArray rootNames, rootPaths;
  46537. getRoots (rootNames, rootPaths);
  46538. if (rootPaths [index].isNotEmpty())
  46539. {
  46540. setRoot (File (rootPaths [index]));
  46541. }
  46542. else
  46543. {
  46544. File f (newText);
  46545. for (;;)
  46546. {
  46547. if (f.isDirectory())
  46548. {
  46549. setRoot (f);
  46550. break;
  46551. }
  46552. if (f.getParentDirectory() == f)
  46553. break;
  46554. f = f.getParentDirectory();
  46555. }
  46556. }
  46557. }
  46558. }
  46559. const BitArray FileBrowserComponent::getRoots (StringArray& rootNames, StringArray& rootPaths)
  46560. {
  46561. BitArray separators;
  46562. #if JUCE_WINDOWS
  46563. Array<File> roots;
  46564. File::findFileSystemRoots (roots);
  46565. rootPaths.clear();
  46566. for (int i = 0; i < roots.size(); ++i)
  46567. {
  46568. const File& drive = roots.getReference(i);
  46569. String name (drive.getFullPathName());
  46570. rootPaths.add (name);
  46571. if (drive.isOnHardDisk())
  46572. {
  46573. String volume (drive.getVolumeLabel());
  46574. if (volume.isEmpty())
  46575. volume = TRANS("Hard Drive");
  46576. name << " [" << drive.getVolumeLabel() << ']';
  46577. }
  46578. else if (drive.isOnCDRomDrive())
  46579. {
  46580. name << TRANS(" [CD/DVD drive]");
  46581. }
  46582. rootNames.add (name);
  46583. }
  46584. separators.setBit (rootPaths.size());
  46585. rootPaths.add (File::getSpecialLocation (File::userDocumentsDirectory).getFullPathName());
  46586. rootNames.add ("Documents");
  46587. rootPaths.add (File::getSpecialLocation (File::userDesktopDirectory).getFullPathName());
  46588. rootNames.add ("Desktop");
  46589. #endif
  46590. #if JUCE_MAC
  46591. rootPaths.add (File::getSpecialLocation (File::userHomeDirectory).getFullPathName());
  46592. rootNames.add ("Home folder");
  46593. rootPaths.add (File::getSpecialLocation (File::userDocumentsDirectory).getFullPathName());
  46594. rootNames.add ("Documents");
  46595. rootPaths.add (File::getSpecialLocation (File::userDesktopDirectory).getFullPathName());
  46596. rootNames.add ("Desktop");
  46597. separators.setBit (rootPaths.size());
  46598. Array <File> volumes;
  46599. File vol ("/Volumes");
  46600. vol.findChildFiles (volumes, File::findDirectories, false);
  46601. for (int i = 0; i < volumes.size(); ++i)
  46602. {
  46603. const File& volume = volumes.getReference(i);
  46604. if (volume.isDirectory() && ! volume.getFileName().startsWithChar (T('.')))
  46605. {
  46606. rootPaths.add (volume.getFullPathName());
  46607. rootNames.add (volume.getFileName());
  46608. }
  46609. }
  46610. #endif
  46611. #if JUCE_LINUX
  46612. rootPaths.add ("/");
  46613. rootNames.add ("/");
  46614. rootPaths.add (File::getSpecialLocation (File::userHomeDirectory).getFullPathName());
  46615. rootNames.add ("Home folder");
  46616. rootPaths.add (File::getSpecialLocation (File::userDesktopDirectory).getFullPathName());
  46617. rootNames.add ("Desktop");
  46618. #endif
  46619. return separators;
  46620. }
  46621. END_JUCE_NAMESPACE
  46622. /*** End of inlined file: juce_FileBrowserComponent.cpp ***/
  46623. /*** Start of inlined file: juce_FileChooser.cpp ***/
  46624. BEGIN_JUCE_NAMESPACE
  46625. FileChooser::FileChooser (const String& chooserBoxTitle,
  46626. const File& currentFileOrDirectory,
  46627. const String& fileFilters,
  46628. const bool useNativeDialogBox_)
  46629. : title (chooserBoxTitle),
  46630. filters (fileFilters),
  46631. startingFile (currentFileOrDirectory),
  46632. useNativeDialogBox (useNativeDialogBox_)
  46633. {
  46634. #if JUCE_LINUX
  46635. useNativeDialogBox = false;
  46636. #endif
  46637. if (! fileFilters.containsNonWhitespaceChars())
  46638. filters = T("*");
  46639. }
  46640. FileChooser::~FileChooser()
  46641. {
  46642. }
  46643. bool FileChooser::browseForFileToOpen (FilePreviewComponent* previewComponent)
  46644. {
  46645. return showDialog (false, true, false, false, false, previewComponent);
  46646. }
  46647. bool FileChooser::browseForMultipleFilesToOpen (FilePreviewComponent* previewComponent)
  46648. {
  46649. return showDialog (false, true, false, false, true, previewComponent);
  46650. }
  46651. bool FileChooser::browseForMultipleFilesOrDirectories (FilePreviewComponent* previewComponent)
  46652. {
  46653. return showDialog (true, true, false, false, true, previewComponent);
  46654. }
  46655. bool FileChooser::browseForFileToSave (const bool warnAboutOverwritingExistingFiles)
  46656. {
  46657. return showDialog (false, true, true, warnAboutOverwritingExistingFiles, false, 0);
  46658. }
  46659. bool FileChooser::browseForDirectory()
  46660. {
  46661. return showDialog (true, false, false, false, false, 0);
  46662. }
  46663. const File FileChooser::getResult() const
  46664. {
  46665. // if you've used a multiple-file select, you should use the getResults() method
  46666. // to retrieve all the files that were chosen.
  46667. jassert (results.size() <= 1);
  46668. return results.getFirst();
  46669. }
  46670. const Array<File>& FileChooser::getResults() const
  46671. {
  46672. return results;
  46673. }
  46674. bool FileChooser::showDialog (const bool selectsDirectories,
  46675. const bool selectsFiles,
  46676. const bool isSave,
  46677. const bool warnAboutOverwritingExistingFiles,
  46678. const bool selectMultipleFiles,
  46679. FilePreviewComponent* const previewComponent)
  46680. {
  46681. ScopedPointer <ComponentDeletionWatcher> currentlyFocusedChecker;
  46682. Component* const currentlyFocused = Component::getCurrentlyFocusedComponent();
  46683. if (currentlyFocused != 0)
  46684. currentlyFocusedChecker = new ComponentDeletionWatcher (currentlyFocused);
  46685. results.clear();
  46686. // the preview component needs to be the right size before you pass it in here..
  46687. jassert (previewComponent == 0 || (previewComponent->getWidth() > 10
  46688. && previewComponent->getHeight() > 10));
  46689. #if JUCE_WINDOWS
  46690. if (useNativeDialogBox && ! (selectsFiles && selectsDirectories))
  46691. #elif JUCE_MAC
  46692. if (useNativeDialogBox && (previewComponent == 0))
  46693. #else
  46694. if (false)
  46695. #endif
  46696. {
  46697. showPlatformDialog (results, title, startingFile, filters,
  46698. selectsDirectories, selectsFiles, isSave,
  46699. warnAboutOverwritingExistingFiles,
  46700. selectMultipleFiles,
  46701. previewComponent);
  46702. }
  46703. else
  46704. {
  46705. WildcardFileFilter wildcard (selectsFiles ? filters : String::empty,
  46706. selectsDirectories ? "*" : String::empty,
  46707. String::empty);
  46708. int flags = isSave ? FileBrowserComponent::saveMode
  46709. : FileBrowserComponent::openMode;
  46710. if (selectsFiles)
  46711. flags |= FileBrowserComponent::canSelectFiles;
  46712. if (selectsDirectories)
  46713. flags |= FileBrowserComponent::canSelectDirectories;
  46714. if (selectMultipleFiles)
  46715. flags |= FileBrowserComponent::canSelectMultipleItems;
  46716. FileBrowserComponent browserComponent (flags, startingFile, &wildcard, previewComponent);
  46717. FileChooserDialogBox box (title, String::empty,
  46718. browserComponent,
  46719. warnAboutOverwritingExistingFiles,
  46720. browserComponent.findColour (AlertWindow::backgroundColourId));
  46721. if (box.show())
  46722. {
  46723. for (int i = 0; i < browserComponent.getNumSelectedFiles(); ++i)
  46724. results.add (browserComponent.getSelectedFile (i));
  46725. }
  46726. }
  46727. if (currentlyFocused != 0 && ! currentlyFocusedChecker->hasBeenDeleted())
  46728. currentlyFocused->grabKeyboardFocus();
  46729. return results.size() > 0;
  46730. }
  46731. FilePreviewComponent::FilePreviewComponent()
  46732. {
  46733. }
  46734. FilePreviewComponent::~FilePreviewComponent()
  46735. {
  46736. }
  46737. END_JUCE_NAMESPACE
  46738. /*** End of inlined file: juce_FileChooser.cpp ***/
  46739. /*** Start of inlined file: juce_FileChooserDialogBox.cpp ***/
  46740. BEGIN_JUCE_NAMESPACE
  46741. FileChooserDialogBox::FileChooserDialogBox (const String& name,
  46742. const String& instructions,
  46743. FileBrowserComponent& chooserComponent,
  46744. const bool warnAboutOverwritingExistingFiles_,
  46745. const Colour& backgroundColour)
  46746. : ResizableWindow (name, backgroundColour, true),
  46747. warnAboutOverwritingExistingFiles (warnAboutOverwritingExistingFiles_)
  46748. {
  46749. content = new ContentComponent();
  46750. content->setName (name);
  46751. content->instructions = instructions;
  46752. content->chooserComponent = &chooserComponent;
  46753. content->addAndMakeVisible (&chooserComponent);
  46754. content->okButton = new TextButton (chooserComponent.getActionVerb());
  46755. content->addAndMakeVisible (content->okButton);
  46756. content->okButton->addButtonListener (this);
  46757. content->okButton->setEnabled (chooserComponent.currentFileIsValid());
  46758. content->okButton->addShortcut (KeyPress (KeyPress::returnKey, 0, 0));
  46759. content->cancelButton = new TextButton (TRANS("Cancel"));
  46760. content->addAndMakeVisible (content->cancelButton);
  46761. content->cancelButton->addButtonListener (this);
  46762. content->cancelButton->addShortcut (KeyPress (KeyPress::escapeKey, 0, 0));
  46763. setContentComponent (content);
  46764. setResizable (true, true);
  46765. setResizeLimits (300, 300, 1200, 1000);
  46766. content->chooserComponent->addListener (this);
  46767. }
  46768. FileChooserDialogBox::~FileChooserDialogBox()
  46769. {
  46770. content->chooserComponent->removeListener (this);
  46771. }
  46772. bool FileChooserDialogBox::show (int w, int h)
  46773. {
  46774. if (w <= 0)
  46775. {
  46776. Component* const previewComp = content->chooserComponent->getPreviewComponent();
  46777. if (previewComp != 0)
  46778. w = 400 + previewComp->getWidth();
  46779. else
  46780. w = 600;
  46781. }
  46782. if (h <= 0)
  46783. h = 500;
  46784. centreWithSize (w, h);
  46785. const bool ok = (runModalLoop() != 0);
  46786. setVisible (false);
  46787. return ok;
  46788. }
  46789. void FileChooserDialogBox::buttonClicked (Button* button)
  46790. {
  46791. if (button == content->okButton)
  46792. {
  46793. if (warnAboutOverwritingExistingFiles
  46794. && content->chooserComponent->isSaveMode()
  46795. && content->chooserComponent->getSelectedFile(0).exists())
  46796. {
  46797. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  46798. TRANS("File already exists"),
  46799. TRANS("There's already a file called:\n\n")
  46800. + content->chooserComponent->getSelectedFile(0).getFullPathName()
  46801. + T("\n\nAre you sure you want to overwrite it?"),
  46802. TRANS("overwrite"),
  46803. TRANS("cancel")))
  46804. {
  46805. return;
  46806. }
  46807. }
  46808. exitModalState (1);
  46809. }
  46810. else if (button == content->cancelButton)
  46811. closeButtonPressed();
  46812. }
  46813. void FileChooserDialogBox::closeButtonPressed()
  46814. {
  46815. setVisible (false);
  46816. }
  46817. void FileChooserDialogBox::selectionChanged()
  46818. {
  46819. content->okButton->setEnabled (content->chooserComponent->currentFileIsValid());
  46820. }
  46821. void FileChooserDialogBox::fileClicked (const File&, const MouseEvent&)
  46822. {
  46823. }
  46824. void FileChooserDialogBox::fileDoubleClicked (const File&)
  46825. {
  46826. selectionChanged();
  46827. content->okButton->triggerClick();
  46828. }
  46829. FileChooserDialogBox::ContentComponent::ContentComponent()
  46830. {
  46831. setInterceptsMouseClicks (false, true);
  46832. }
  46833. FileChooserDialogBox::ContentComponent::~ContentComponent()
  46834. {
  46835. delete okButton;
  46836. delete cancelButton;
  46837. }
  46838. void FileChooserDialogBox::ContentComponent::paint (Graphics& g)
  46839. {
  46840. g.setColour (getLookAndFeel().findColour (FileChooserDialogBox::titleTextColourId));
  46841. text.draw (g);
  46842. }
  46843. void FileChooserDialogBox::ContentComponent::resized()
  46844. {
  46845. getLookAndFeel().createFileChooserHeaderText (getName(), instructions, text, getWidth());
  46846. float left, top, right, bottom;
  46847. text.getBoundingBox (0, text.getNumGlyphs(), left, top, right, bottom, false);
  46848. const int y = roundToInt (bottom) + 10;
  46849. const int buttonHeight = 26;
  46850. const int buttonY = getHeight() - buttonHeight - 8;
  46851. chooserComponent->setBounds (0, y, getWidth(), buttonY - y - 20);
  46852. okButton->setBounds (proportionOfWidth (0.25f), buttonY,
  46853. proportionOfWidth (0.2f), buttonHeight);
  46854. cancelButton->setBounds (proportionOfWidth (0.55f), buttonY,
  46855. proportionOfWidth (0.2f), buttonHeight);
  46856. }
  46857. END_JUCE_NAMESPACE
  46858. /*** End of inlined file: juce_FileChooserDialogBox.cpp ***/
  46859. /*** Start of inlined file: juce_FileFilter.cpp ***/
  46860. BEGIN_JUCE_NAMESPACE
  46861. FileFilter::FileFilter (const String& filterDescription)
  46862. : description (filterDescription)
  46863. {
  46864. }
  46865. FileFilter::~FileFilter()
  46866. {
  46867. }
  46868. const String& FileFilter::getDescription() const throw()
  46869. {
  46870. return description;
  46871. }
  46872. END_JUCE_NAMESPACE
  46873. /*** End of inlined file: juce_FileFilter.cpp ***/
  46874. /*** Start of inlined file: juce_FileListComponent.cpp ***/
  46875. BEGIN_JUCE_NAMESPACE
  46876. Image* juce_createIconForFile (const File& file);
  46877. FileListComponent::FileListComponent (DirectoryContentsList& listToShow)
  46878. : ListBox (String::empty, 0),
  46879. DirectoryContentsDisplayComponent (listToShow)
  46880. {
  46881. setModel (this);
  46882. fileList.addChangeListener (this);
  46883. }
  46884. FileListComponent::~FileListComponent()
  46885. {
  46886. fileList.removeChangeListener (this);
  46887. deleteAllChildren();
  46888. }
  46889. int FileListComponent::getNumSelectedFiles() const
  46890. {
  46891. return getNumSelectedRows();
  46892. }
  46893. const File FileListComponent::getSelectedFile (int index) const
  46894. {
  46895. return fileList.getFile (getSelectedRow (index));
  46896. }
  46897. void FileListComponent::scrollToTop()
  46898. {
  46899. getVerticalScrollBar()->setCurrentRangeStart (0);
  46900. }
  46901. void FileListComponent::changeListenerCallback (void*)
  46902. {
  46903. updateContent();
  46904. if (lastDirectory != fileList.getDirectory())
  46905. {
  46906. lastDirectory = fileList.getDirectory();
  46907. deselectAllRows();
  46908. }
  46909. }
  46910. class FileListItemComponent : public Component,
  46911. public TimeSliceClient,
  46912. public AsyncUpdater
  46913. {
  46914. public:
  46915. FileListItemComponent (FileListComponent& owner_,
  46916. TimeSliceThread& thread_) throw()
  46917. : owner (owner_),
  46918. thread (thread_),
  46919. icon (0)
  46920. {
  46921. }
  46922. ~FileListItemComponent() throw()
  46923. {
  46924. thread.removeTimeSliceClient (this);
  46925. clearIcon();
  46926. }
  46927. void paint (Graphics& g)
  46928. {
  46929. getLookAndFeel().drawFileBrowserRow (g, getWidth(), getHeight(),
  46930. file.getFileName(),
  46931. icon,
  46932. fileSize, modTime,
  46933. isDirectory, highlighted,
  46934. index);
  46935. }
  46936. void mouseDown (const MouseEvent& e)
  46937. {
  46938. owner.selectRowsBasedOnModifierKeys (index, e.mods);
  46939. owner.sendMouseClickMessage (file, e);
  46940. }
  46941. void mouseDoubleClick (const MouseEvent&)
  46942. {
  46943. owner.sendDoubleClickMessage (file);
  46944. }
  46945. void update (const File& root,
  46946. const DirectoryContentsList::FileInfo* const fileInfo,
  46947. const int index_,
  46948. const bool highlighted_) throw()
  46949. {
  46950. thread.removeTimeSliceClient (this);
  46951. if (highlighted_ != highlighted
  46952. || index_ != index)
  46953. {
  46954. index = index_;
  46955. highlighted = highlighted_;
  46956. repaint();
  46957. }
  46958. File newFile;
  46959. String newFileSize;
  46960. String newModTime;
  46961. if (fileInfo != 0)
  46962. {
  46963. newFile = root.getChildFile (fileInfo->filename);
  46964. newFileSize = File::descriptionOfSizeInBytes (fileInfo->fileSize);
  46965. newModTime = fileInfo->modificationTime.formatted (T("%d %b '%y %H:%M"));
  46966. }
  46967. if (newFile != file
  46968. || fileSize != newFileSize
  46969. || modTime != newModTime)
  46970. {
  46971. file = newFile;
  46972. fileSize = newFileSize;
  46973. modTime = newModTime;
  46974. isDirectory = fileInfo != 0 && fileInfo->isDirectory;
  46975. repaint();
  46976. clearIcon();
  46977. }
  46978. if (file != File::nonexistent
  46979. && icon == 0 && ! isDirectory)
  46980. {
  46981. updateIcon (true);
  46982. if (icon == 0)
  46983. thread.addTimeSliceClient (this);
  46984. }
  46985. }
  46986. bool useTimeSlice()
  46987. {
  46988. updateIcon (false);
  46989. return false;
  46990. }
  46991. void handleAsyncUpdate()
  46992. {
  46993. repaint();
  46994. }
  46995. juce_UseDebuggingNewOperator
  46996. private:
  46997. FileListComponent& owner;
  46998. TimeSliceThread& thread;
  46999. bool highlighted;
  47000. int index;
  47001. File file;
  47002. String fileSize;
  47003. String modTime;
  47004. Image* icon;
  47005. bool isDirectory;
  47006. void clearIcon() throw()
  47007. {
  47008. ImageCache::release (icon);
  47009. icon = 0;
  47010. }
  47011. void updateIcon (const bool onlyUpdateIfCached) throw()
  47012. {
  47013. if (icon == 0)
  47014. {
  47015. const int hashCode = (file.getFullPathName() + T("_iconCacheSalt")).hashCode();
  47016. Image* im = ImageCache::getFromHashCode (hashCode);
  47017. if (im == 0 && ! onlyUpdateIfCached)
  47018. {
  47019. im = juce_createIconForFile (file);
  47020. if (im != 0)
  47021. ImageCache::addImageToCache (im, hashCode);
  47022. }
  47023. if (im != 0)
  47024. {
  47025. icon = im;
  47026. triggerAsyncUpdate();
  47027. }
  47028. }
  47029. }
  47030. };
  47031. int FileListComponent::getNumRows()
  47032. {
  47033. return fileList.getNumFiles();
  47034. }
  47035. void FileListComponent::paintListBoxItem (int, Graphics&, int, int, bool)
  47036. {
  47037. }
  47038. Component* FileListComponent::refreshComponentForRow (int row, bool isSelected, Component* existingComponentToUpdate)
  47039. {
  47040. FileListItemComponent* comp = dynamic_cast <FileListItemComponent*> (existingComponentToUpdate);
  47041. if (comp == 0)
  47042. {
  47043. delete existingComponentToUpdate;
  47044. comp = new FileListItemComponent (*this, fileList.getTimeSliceThread());
  47045. }
  47046. DirectoryContentsList::FileInfo fileInfo;
  47047. if (fileList.getFileInfo (row, fileInfo))
  47048. comp->update (fileList.getDirectory(), &fileInfo, row, isSelected);
  47049. else
  47050. comp->update (fileList.getDirectory(), 0, row, isSelected);
  47051. return comp;
  47052. }
  47053. void FileListComponent::selectedRowsChanged (int /*lastRowSelected*/)
  47054. {
  47055. sendSelectionChangeMessage();
  47056. }
  47057. void FileListComponent::deleteKeyPressed (int /*currentSelectedRow*/)
  47058. {
  47059. }
  47060. void FileListComponent::returnKeyPressed (int currentSelectedRow)
  47061. {
  47062. sendDoubleClickMessage (fileList.getFile (currentSelectedRow));
  47063. }
  47064. END_JUCE_NAMESPACE
  47065. /*** End of inlined file: juce_FileListComponent.cpp ***/
  47066. /*** Start of inlined file: juce_FilenameComponent.cpp ***/
  47067. BEGIN_JUCE_NAMESPACE
  47068. FilenameComponent::FilenameComponent (const String& name,
  47069. const File& currentFile,
  47070. const bool canEditFilename,
  47071. const bool isDirectory,
  47072. const bool isForSaving,
  47073. const String& fileBrowserWildcard,
  47074. const String& enforcedSuffix_,
  47075. const String& textWhenNothingSelected)
  47076. : Component (name),
  47077. maxRecentFiles (30),
  47078. isDir (isDirectory),
  47079. isSaving (isForSaving),
  47080. isFileDragOver (false),
  47081. wildcard (fileBrowserWildcard),
  47082. enforcedSuffix (enforcedSuffix_)
  47083. {
  47084. addAndMakeVisible (filenameBox = new ComboBox (T("fn")));
  47085. filenameBox->setEditableText (canEditFilename);
  47086. filenameBox->addListener (this);
  47087. filenameBox->setTextWhenNothingSelected (textWhenNothingSelected);
  47088. filenameBox->setTextWhenNoChoicesAvailable (TRANS("(no recently seleced files)"));
  47089. browseButton = 0;
  47090. setBrowseButtonText (T("..."));
  47091. setCurrentFile (currentFile, true);
  47092. }
  47093. FilenameComponent::~FilenameComponent()
  47094. {
  47095. deleteAllChildren();
  47096. }
  47097. void FilenameComponent::paintOverChildren (Graphics& g)
  47098. {
  47099. if (isFileDragOver)
  47100. {
  47101. g.setColour (Colours::red.withAlpha (0.2f));
  47102. g.drawRect (0, 0, getWidth(), getHeight(), 3);
  47103. }
  47104. }
  47105. void FilenameComponent::resized()
  47106. {
  47107. getLookAndFeel().layoutFilenameComponent (*this, filenameBox, browseButton);
  47108. }
  47109. void FilenameComponent::setBrowseButtonText (const String& newBrowseButtonText)
  47110. {
  47111. browseButtonText = newBrowseButtonText;
  47112. lookAndFeelChanged();
  47113. }
  47114. void FilenameComponent::lookAndFeelChanged()
  47115. {
  47116. deleteAndZero (browseButton);
  47117. addAndMakeVisible (browseButton = getLookAndFeel().createFilenameComponentBrowseButton (browseButtonText));
  47118. browseButton->setConnectedEdges (Button::ConnectedOnLeft);
  47119. resized();
  47120. browseButton->addButtonListener (this);
  47121. }
  47122. void FilenameComponent::setTooltip (const String& newTooltip)
  47123. {
  47124. SettableTooltipClient::setTooltip (newTooltip);
  47125. filenameBox->setTooltip (newTooltip);
  47126. }
  47127. void FilenameComponent::setDefaultBrowseTarget (const File& newDefaultDirectory) throw()
  47128. {
  47129. defaultBrowseFile = newDefaultDirectory;
  47130. }
  47131. void FilenameComponent::buttonClicked (Button*)
  47132. {
  47133. FileChooser fc (TRANS("Choose a new file"),
  47134. getCurrentFile() == File::nonexistent ? defaultBrowseFile
  47135. : getCurrentFile(),
  47136. wildcard);
  47137. if (isDir ? fc.browseForDirectory()
  47138. : (isSaving ? fc.browseForFileToSave (false)
  47139. : fc.browseForFileToOpen()))
  47140. {
  47141. setCurrentFile (fc.getResult(), true);
  47142. }
  47143. }
  47144. void FilenameComponent::comboBoxChanged (ComboBox*)
  47145. {
  47146. setCurrentFile (getCurrentFile(), true);
  47147. }
  47148. bool FilenameComponent::isInterestedInFileDrag (const StringArray&)
  47149. {
  47150. return true;
  47151. }
  47152. void FilenameComponent::filesDropped (const StringArray& filenames, int, int)
  47153. {
  47154. isFileDragOver = false;
  47155. repaint();
  47156. const File f (filenames[0]);
  47157. if (f.exists() && (f.isDirectory() == isDir))
  47158. setCurrentFile (f, true);
  47159. }
  47160. void FilenameComponent::fileDragEnter (const StringArray&, int, int)
  47161. {
  47162. isFileDragOver = true;
  47163. repaint();
  47164. }
  47165. void FilenameComponent::fileDragExit (const StringArray&)
  47166. {
  47167. isFileDragOver = false;
  47168. repaint();
  47169. }
  47170. const File FilenameComponent::getCurrentFile() const
  47171. {
  47172. File f (filenameBox->getText());
  47173. if (enforcedSuffix.isNotEmpty())
  47174. f = f.withFileExtension (enforcedSuffix);
  47175. return f;
  47176. }
  47177. void FilenameComponent::setCurrentFile (File newFile,
  47178. const bool addToRecentlyUsedList,
  47179. const bool sendChangeNotification)
  47180. {
  47181. if (enforcedSuffix.isNotEmpty())
  47182. newFile = newFile.withFileExtension (enforcedSuffix);
  47183. if (newFile.getFullPathName() != lastFilename)
  47184. {
  47185. lastFilename = newFile.getFullPathName();
  47186. if (addToRecentlyUsedList)
  47187. addRecentlyUsedFile (newFile);
  47188. filenameBox->setText (lastFilename, true);
  47189. if (sendChangeNotification)
  47190. triggerAsyncUpdate();
  47191. }
  47192. }
  47193. void FilenameComponent::setFilenameIsEditable (const bool shouldBeEditable)
  47194. {
  47195. filenameBox->setEditableText (shouldBeEditable);
  47196. }
  47197. const StringArray FilenameComponent::getRecentlyUsedFilenames() const
  47198. {
  47199. StringArray names;
  47200. for (int i = 0; i < filenameBox->getNumItems(); ++i)
  47201. names.add (filenameBox->getItemText (i));
  47202. return names;
  47203. }
  47204. void FilenameComponent::setRecentlyUsedFilenames (const StringArray& filenames)
  47205. {
  47206. if (filenames != getRecentlyUsedFilenames())
  47207. {
  47208. filenameBox->clear();
  47209. for (int i = 0; i < jmin (filenames.size(), maxRecentFiles); ++i)
  47210. filenameBox->addItem (filenames[i], i + 1);
  47211. }
  47212. }
  47213. void FilenameComponent::setMaxNumberOfRecentFiles (const int newMaximum)
  47214. {
  47215. maxRecentFiles = jmax (1, newMaximum);
  47216. setRecentlyUsedFilenames (getRecentlyUsedFilenames());
  47217. }
  47218. void FilenameComponent::addRecentlyUsedFile (const File& file)
  47219. {
  47220. StringArray files (getRecentlyUsedFilenames());
  47221. if (file.getFullPathName().isNotEmpty())
  47222. {
  47223. files.removeString (file.getFullPathName(), true);
  47224. files.insert (0, file.getFullPathName());
  47225. setRecentlyUsedFilenames (files);
  47226. }
  47227. }
  47228. void FilenameComponent::addListener (FilenameComponentListener* const listener) throw()
  47229. {
  47230. jassert (listener != 0);
  47231. if (listener != 0)
  47232. listeners.add (listener);
  47233. }
  47234. void FilenameComponent::removeListener (FilenameComponentListener* const listener) throw()
  47235. {
  47236. listeners.removeValue (listener);
  47237. }
  47238. void FilenameComponent::handleAsyncUpdate()
  47239. {
  47240. for (int i = listeners.size(); --i >= 0;)
  47241. {
  47242. ((FilenameComponentListener*) listeners.getUnchecked (i))->filenameComponentChanged (this);
  47243. i = jmin (i, listeners.size());
  47244. }
  47245. }
  47246. END_JUCE_NAMESPACE
  47247. /*** End of inlined file: juce_FilenameComponent.cpp ***/
  47248. /*** Start of inlined file: juce_FileSearchPathListComponent.cpp ***/
  47249. BEGIN_JUCE_NAMESPACE
  47250. FileSearchPathListComponent::FileSearchPathListComponent()
  47251. {
  47252. addAndMakeVisible (listBox = new ListBox (String::empty, this));
  47253. listBox->setColour (ListBox::backgroundColourId, Colours::black.withAlpha (0.02f));
  47254. listBox->setColour (ListBox::outlineColourId, Colours::black.withAlpha (0.1f));
  47255. listBox->setOutlineThickness (1);
  47256. addAndMakeVisible (addButton = new TextButton ("+"));
  47257. addButton->addButtonListener (this);
  47258. addButton->setConnectedEdges (Button::ConnectedOnLeft | Button::ConnectedOnRight | Button::ConnectedOnBottom | Button::ConnectedOnTop);
  47259. addAndMakeVisible (removeButton = new TextButton ("-"));
  47260. removeButton->addButtonListener (this);
  47261. removeButton->setConnectedEdges (Button::ConnectedOnLeft | Button::ConnectedOnRight | Button::ConnectedOnBottom | Button::ConnectedOnTop);
  47262. addAndMakeVisible (changeButton = new TextButton (TRANS("change...")));
  47263. changeButton->addButtonListener (this);
  47264. addAndMakeVisible (upButton = new DrawableButton (String::empty, DrawableButton::ImageOnButtonBackground));
  47265. upButton->addButtonListener (this);
  47266. {
  47267. Path arrowPath;
  47268. arrowPath.addArrow (50.0f, 100.0f, 50.0f, 0.0f, 40.0f, 100.0f, 50.0f);
  47269. DrawablePath arrowImage;
  47270. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  47271. arrowImage.setPath (arrowPath);
  47272. ((DrawableButton*) upButton)->setImages (&arrowImage);
  47273. }
  47274. addAndMakeVisible (downButton = new DrawableButton (String::empty, DrawableButton::ImageOnButtonBackground));
  47275. downButton->addButtonListener (this);
  47276. {
  47277. Path arrowPath;
  47278. arrowPath.addArrow (50.0f, 0.0f, 50.0f, 100.0f, 40.0f, 100.0f, 50.0f);
  47279. DrawablePath arrowImage;
  47280. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  47281. arrowImage.setPath (arrowPath);
  47282. ((DrawableButton*) downButton)->setImages (&arrowImage);
  47283. }
  47284. updateButtons();
  47285. }
  47286. FileSearchPathListComponent::~FileSearchPathListComponent()
  47287. {
  47288. deleteAllChildren();
  47289. }
  47290. void FileSearchPathListComponent::updateButtons() throw()
  47291. {
  47292. const bool anythingSelected = listBox->getNumSelectedRows() > 0;
  47293. removeButton->setEnabled (anythingSelected);
  47294. changeButton->setEnabled (anythingSelected);
  47295. upButton->setEnabled (anythingSelected);
  47296. downButton->setEnabled (anythingSelected);
  47297. }
  47298. void FileSearchPathListComponent::changed() throw()
  47299. {
  47300. listBox->updateContent();
  47301. listBox->repaint();
  47302. updateButtons();
  47303. }
  47304. void FileSearchPathListComponent::setPath (const FileSearchPath& newPath)
  47305. {
  47306. if (newPath.toString() != path.toString())
  47307. {
  47308. path = newPath;
  47309. changed();
  47310. }
  47311. }
  47312. void FileSearchPathListComponent::setDefaultBrowseTarget (const File& newDefaultDirectory) throw()
  47313. {
  47314. defaultBrowseTarget = newDefaultDirectory;
  47315. }
  47316. int FileSearchPathListComponent::getNumRows()
  47317. {
  47318. return path.getNumPaths();
  47319. }
  47320. void FileSearchPathListComponent::paintListBoxItem (int rowNumber, Graphics& g, int width, int height, bool rowIsSelected)
  47321. {
  47322. if (rowIsSelected)
  47323. g.fillAll (findColour (TextEditor::highlightColourId));
  47324. g.setColour (findColour (ListBox::textColourId));
  47325. Font f (height * 0.7f);
  47326. f.setHorizontalScale (0.9f);
  47327. g.setFont (f);
  47328. g.drawText (path [rowNumber].getFullPathName(),
  47329. 4, 0, width - 6, height,
  47330. Justification::centredLeft, true);
  47331. }
  47332. void FileSearchPathListComponent::deleteKeyPressed (int row)
  47333. {
  47334. if (((unsigned int) row) < (unsigned int) path.getNumPaths())
  47335. {
  47336. path.remove (row);
  47337. changed();
  47338. }
  47339. }
  47340. void FileSearchPathListComponent::returnKeyPressed (int row)
  47341. {
  47342. FileChooser chooser (TRANS("Change folder..."), path [row], T("*"));
  47343. if (chooser.browseForDirectory())
  47344. {
  47345. path.remove (row);
  47346. path.add (chooser.getResult(), row);
  47347. changed();
  47348. }
  47349. }
  47350. void FileSearchPathListComponent::listBoxItemDoubleClicked (int row, const MouseEvent&)
  47351. {
  47352. returnKeyPressed (row);
  47353. }
  47354. void FileSearchPathListComponent::selectedRowsChanged (int)
  47355. {
  47356. updateButtons();
  47357. }
  47358. void FileSearchPathListComponent::paint (Graphics& g)
  47359. {
  47360. g.fillAll (findColour (backgroundColourId));
  47361. }
  47362. void FileSearchPathListComponent::resized()
  47363. {
  47364. const int buttonH = 22;
  47365. const int buttonY = getHeight() - buttonH - 4;
  47366. listBox->setBounds (2, 2, getWidth() - 4, buttonY - 5);
  47367. addButton->setBounds (2, buttonY, buttonH, buttonH);
  47368. removeButton->setBounds (addButton->getRight(), buttonY, buttonH, buttonH);
  47369. ((TextButton*) changeButton)->changeWidthToFitText (buttonH);
  47370. downButton->setSize (buttonH * 2, buttonH);
  47371. upButton->setSize (buttonH * 2, buttonH);
  47372. downButton->setTopRightPosition (getWidth() - 2, buttonY);
  47373. upButton->setTopRightPosition (downButton->getX() - 4, buttonY);
  47374. changeButton->setTopRightPosition (upButton->getX() - 8, buttonY);
  47375. }
  47376. bool FileSearchPathListComponent::isInterestedInFileDrag (const StringArray&)
  47377. {
  47378. return true;
  47379. }
  47380. void FileSearchPathListComponent::filesDropped (const StringArray& filenames, int, int mouseY)
  47381. {
  47382. for (int i = filenames.size(); --i >= 0;)
  47383. {
  47384. const File f (filenames[i]);
  47385. if (f.isDirectory())
  47386. {
  47387. const int row = listBox->getRowContainingPosition (0, mouseY - listBox->getY());
  47388. path.add (f, row);
  47389. changed();
  47390. }
  47391. }
  47392. }
  47393. void FileSearchPathListComponent::buttonClicked (Button* button)
  47394. {
  47395. const int currentRow = listBox->getSelectedRow();
  47396. if (button == removeButton)
  47397. {
  47398. deleteKeyPressed (currentRow);
  47399. }
  47400. else if (button == addButton)
  47401. {
  47402. File start (defaultBrowseTarget);
  47403. if (start == File::nonexistent)
  47404. start = path [0];
  47405. if (start == File::nonexistent)
  47406. start = File::getCurrentWorkingDirectory();
  47407. FileChooser chooser (TRANS("Add a folder..."), start, T("*"));
  47408. if (chooser.browseForDirectory())
  47409. {
  47410. path.add (chooser.getResult(), currentRow);
  47411. }
  47412. }
  47413. else if (button == changeButton)
  47414. {
  47415. returnKeyPressed (currentRow);
  47416. }
  47417. else if (button == upButton)
  47418. {
  47419. if (currentRow > 0 && currentRow < path.getNumPaths())
  47420. {
  47421. const File f (path[currentRow]);
  47422. path.remove (currentRow);
  47423. path.add (f, currentRow - 1);
  47424. listBox->selectRow (currentRow - 1);
  47425. }
  47426. }
  47427. else if (button == downButton)
  47428. {
  47429. if (currentRow >= 0 && currentRow < path.getNumPaths() - 1)
  47430. {
  47431. const File f (path[currentRow]);
  47432. path.remove (currentRow);
  47433. path.add (f, currentRow + 1);
  47434. listBox->selectRow (currentRow + 1);
  47435. }
  47436. }
  47437. changed();
  47438. }
  47439. END_JUCE_NAMESPACE
  47440. /*** End of inlined file: juce_FileSearchPathListComponent.cpp ***/
  47441. /*** Start of inlined file: juce_FileTreeComponent.cpp ***/
  47442. BEGIN_JUCE_NAMESPACE
  47443. Image* juce_createIconForFile (const File& file);
  47444. class FileListTreeItem : public TreeViewItem,
  47445. public TimeSliceClient,
  47446. public AsyncUpdater,
  47447. public ChangeListener
  47448. {
  47449. public:
  47450. FileListTreeItem (FileTreeComponent& owner_,
  47451. DirectoryContentsList* const parentContentsList_,
  47452. const int indexInContentsList_,
  47453. const File& file_,
  47454. TimeSliceThread& thread_) throw()
  47455. : file (file_),
  47456. owner (owner_),
  47457. parentContentsList (parentContentsList_),
  47458. indexInContentsList (indexInContentsList_),
  47459. subContentsList (0),
  47460. canDeleteSubContentsList (false),
  47461. thread (thread_),
  47462. icon (0)
  47463. {
  47464. DirectoryContentsList::FileInfo fileInfo;
  47465. if (parentContentsList_ != 0
  47466. && parentContentsList_->getFileInfo (indexInContentsList_, fileInfo))
  47467. {
  47468. fileSize = File::descriptionOfSizeInBytes (fileInfo.fileSize);
  47469. modTime = fileInfo.modificationTime.formatted (T("%d %b '%y %H:%M"));
  47470. isDirectory = fileInfo.isDirectory;
  47471. }
  47472. else
  47473. {
  47474. isDirectory = true;
  47475. }
  47476. }
  47477. ~FileListTreeItem() throw()
  47478. {
  47479. thread.removeTimeSliceClient (this);
  47480. clearSubItems();
  47481. ImageCache::release (icon);
  47482. if (canDeleteSubContentsList)
  47483. delete subContentsList;
  47484. }
  47485. bool mightContainSubItems() { return isDirectory; }
  47486. const String getUniqueName() const { return file.getFullPathName(); }
  47487. int getItemHeight() const { return 22; }
  47488. const String getDragSourceDescription() { return owner.getDragAndDropDescription(); }
  47489. void itemOpennessChanged (bool isNowOpen)
  47490. {
  47491. if (isNowOpen)
  47492. {
  47493. clearSubItems();
  47494. isDirectory = file.isDirectory();
  47495. if (isDirectory)
  47496. {
  47497. if (subContentsList == 0)
  47498. {
  47499. jassert (parentContentsList != 0);
  47500. DirectoryContentsList* const l = new DirectoryContentsList (parentContentsList->getFilter(), thread);
  47501. l->setDirectory (file, true, true);
  47502. setSubContentsList (l);
  47503. canDeleteSubContentsList = true;
  47504. }
  47505. changeListenerCallback (0);
  47506. }
  47507. }
  47508. }
  47509. void setSubContentsList (DirectoryContentsList* newList) throw()
  47510. {
  47511. jassert (subContentsList == 0);
  47512. subContentsList = newList;
  47513. newList->addChangeListener (this);
  47514. }
  47515. void changeListenerCallback (void*)
  47516. {
  47517. clearSubItems();
  47518. if (isOpen() && subContentsList != 0)
  47519. {
  47520. for (int i = 0; i < subContentsList->getNumFiles(); ++i)
  47521. {
  47522. FileListTreeItem* const item
  47523. = new FileListTreeItem (owner, subContentsList, i, subContentsList->getFile(i), thread);
  47524. addSubItem (item);
  47525. }
  47526. }
  47527. }
  47528. void paintItem (Graphics& g, int width, int height)
  47529. {
  47530. if (file != File::nonexistent)
  47531. {
  47532. updateIcon (true);
  47533. if (icon == 0)
  47534. thread.addTimeSliceClient (this);
  47535. }
  47536. owner.getLookAndFeel()
  47537. .drawFileBrowserRow (g, width, height,
  47538. file.getFileName(),
  47539. icon,
  47540. fileSize, modTime,
  47541. isDirectory, isSelected(),
  47542. indexInContentsList);
  47543. }
  47544. void itemClicked (const MouseEvent& e)
  47545. {
  47546. owner.sendMouseClickMessage (file, e);
  47547. }
  47548. void itemDoubleClicked (const MouseEvent& e)
  47549. {
  47550. TreeViewItem::itemDoubleClicked (e);
  47551. owner.sendDoubleClickMessage (file);
  47552. }
  47553. void itemSelectionChanged (bool)
  47554. {
  47555. owner.sendSelectionChangeMessage();
  47556. }
  47557. bool useTimeSlice()
  47558. {
  47559. updateIcon (false);
  47560. thread.removeTimeSliceClient (this);
  47561. return false;
  47562. }
  47563. void handleAsyncUpdate()
  47564. {
  47565. owner.repaint();
  47566. }
  47567. const File file;
  47568. juce_UseDebuggingNewOperator
  47569. private:
  47570. FileTreeComponent& owner;
  47571. DirectoryContentsList* parentContentsList;
  47572. int indexInContentsList;
  47573. DirectoryContentsList* subContentsList;
  47574. bool isDirectory, canDeleteSubContentsList;
  47575. TimeSliceThread& thread;
  47576. Image* icon;
  47577. String fileSize;
  47578. String modTime;
  47579. void updateIcon (const bool onlyUpdateIfCached) throw()
  47580. {
  47581. if (icon == 0)
  47582. {
  47583. const int hashCode = (file.getFullPathName() + T("_iconCacheSalt")).hashCode();
  47584. Image* im = ImageCache::getFromHashCode (hashCode);
  47585. if (im == 0 && ! onlyUpdateIfCached)
  47586. {
  47587. im = juce_createIconForFile (file);
  47588. if (im != 0)
  47589. ImageCache::addImageToCache (im, hashCode);
  47590. }
  47591. if (im != 0)
  47592. {
  47593. icon = im;
  47594. triggerAsyncUpdate();
  47595. }
  47596. }
  47597. }
  47598. };
  47599. FileTreeComponent::FileTreeComponent (DirectoryContentsList& listToShow)
  47600. : DirectoryContentsDisplayComponent (listToShow)
  47601. {
  47602. FileListTreeItem* const root
  47603. = new FileListTreeItem (*this, 0, 0, listToShow.getDirectory(),
  47604. listToShow.getTimeSliceThread());
  47605. root->setSubContentsList (&listToShow);
  47606. setRootItemVisible (false);
  47607. setRootItem (root);
  47608. }
  47609. FileTreeComponent::~FileTreeComponent()
  47610. {
  47611. deleteRootItem();
  47612. }
  47613. const File FileTreeComponent::getSelectedFile (const int index) const
  47614. {
  47615. const FileListTreeItem* const item = dynamic_cast <const FileListTreeItem*> (getSelectedItem (index));
  47616. if (item != 0)
  47617. return item->file;
  47618. return File::nonexistent;
  47619. }
  47620. void FileTreeComponent::scrollToTop()
  47621. {
  47622. getViewport()->getVerticalScrollBar()->setCurrentRangeStart (0);
  47623. }
  47624. void FileTreeComponent::setDragAndDropDescription (const String& description) throw()
  47625. {
  47626. dragAndDropDescription = description;
  47627. }
  47628. END_JUCE_NAMESPACE
  47629. /*** End of inlined file: juce_FileTreeComponent.cpp ***/
  47630. /*** Start of inlined file: juce_ImagePreviewComponent.cpp ***/
  47631. BEGIN_JUCE_NAMESPACE
  47632. ImagePreviewComponent::ImagePreviewComponent()
  47633. {
  47634. }
  47635. ImagePreviewComponent::~ImagePreviewComponent()
  47636. {
  47637. }
  47638. void ImagePreviewComponent::getThumbSize (int& w, int& h) const
  47639. {
  47640. const int availableW = proportionOfWidth (0.97f);
  47641. const int availableH = getHeight() - 13 * 4;
  47642. const double scale = jmin (1.0,
  47643. availableW / (double) w,
  47644. availableH / (double) h);
  47645. w = roundToInt (scale * w);
  47646. h = roundToInt (scale * h);
  47647. }
  47648. void ImagePreviewComponent::selectedFileChanged (const File& file)
  47649. {
  47650. if (fileToLoad != file)
  47651. {
  47652. fileToLoad = file;
  47653. startTimer (100);
  47654. }
  47655. }
  47656. void ImagePreviewComponent::timerCallback()
  47657. {
  47658. stopTimer();
  47659. currentThumbnail = 0;
  47660. currentDetails = String::empty;
  47661. repaint();
  47662. ScopedPointer <FileInputStream> in (fileToLoad.createInputStream());
  47663. if (in != 0)
  47664. {
  47665. ImageFileFormat* const format = ImageFileFormat::findImageFormatForStream (*in);
  47666. if (format != 0)
  47667. {
  47668. currentThumbnail = format->decodeImage (*in);
  47669. if (currentThumbnail != 0)
  47670. {
  47671. int w = currentThumbnail->getWidth();
  47672. int h = currentThumbnail->getHeight();
  47673. currentDetails
  47674. << fileToLoad.getFileName() << "\n"
  47675. << format->getFormatName() << "\n"
  47676. << w << " x " << h << " pixels\n"
  47677. << File::descriptionOfSizeInBytes (fileToLoad.getSize());
  47678. getThumbSize (w, h);
  47679. currentThumbnail = currentThumbnail->createCopy (w, h);
  47680. }
  47681. }
  47682. }
  47683. }
  47684. void ImagePreviewComponent::paint (Graphics& g)
  47685. {
  47686. if (currentThumbnail != 0)
  47687. {
  47688. g.setFont (13.0f);
  47689. int w = currentThumbnail->getWidth();
  47690. int h = currentThumbnail->getHeight();
  47691. getThumbSize (w, h);
  47692. const int numLines = 4;
  47693. const int totalH = 13 * numLines + h + 4;
  47694. const int y = (getHeight() - totalH) / 2;
  47695. g.drawImageWithin (currentThumbnail,
  47696. (getWidth() - w) / 2, y, w, h,
  47697. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize,
  47698. false);
  47699. g.drawFittedText (currentDetails,
  47700. 0, y + h + 4, getWidth(), 100,
  47701. Justification::centredTop, numLines);
  47702. }
  47703. }
  47704. END_JUCE_NAMESPACE
  47705. /*** End of inlined file: juce_ImagePreviewComponent.cpp ***/
  47706. /*** Start of inlined file: juce_WildcardFileFilter.cpp ***/
  47707. BEGIN_JUCE_NAMESPACE
  47708. WildcardFileFilter::WildcardFileFilter (const String& fileWildcardPatterns,
  47709. const String& directoryWildcardPatterns,
  47710. const String& description_)
  47711. : FileFilter (description_.isEmpty() ? fileWildcardPatterns
  47712. : (description_ + T(" (") + fileWildcardPatterns + T(")")))
  47713. {
  47714. parse (fileWildcardPatterns, fileWildcards);
  47715. parse (directoryWildcardPatterns, directoryWildcards);
  47716. }
  47717. WildcardFileFilter::~WildcardFileFilter()
  47718. {
  47719. }
  47720. bool WildcardFileFilter::isFileSuitable (const File& file) const
  47721. {
  47722. return match (file, fileWildcards);
  47723. }
  47724. bool WildcardFileFilter::isDirectorySuitable (const File& file) const
  47725. {
  47726. return match (file, directoryWildcards);
  47727. }
  47728. void WildcardFileFilter::parse (const String& pattern, StringArray& result) throw()
  47729. {
  47730. result.addTokens (pattern.toLowerCase(), T(";,"), T("\"'"));
  47731. result.trim();
  47732. result.removeEmptyStrings();
  47733. // special case for *.*, because people use it to mean "any file", but it
  47734. // would actually ignore files with no extension.
  47735. for (int i = result.size(); --i >= 0;)
  47736. if (result[i] == T("*.*"))
  47737. result.set (i, T("*"));
  47738. }
  47739. bool WildcardFileFilter::match (const File& file, const StringArray& wildcards) throw()
  47740. {
  47741. const String filename (file.getFileName());
  47742. for (int i = wildcards.size(); --i >= 0;)
  47743. if (filename.matchesWildcard (wildcards[i], true))
  47744. return true;
  47745. return false;
  47746. }
  47747. END_JUCE_NAMESPACE
  47748. /*** End of inlined file: juce_WildcardFileFilter.cpp ***/
  47749. /*** Start of inlined file: juce_KeyboardFocusTraverser.cpp ***/
  47750. BEGIN_JUCE_NAMESPACE
  47751. KeyboardFocusTraverser::KeyboardFocusTraverser()
  47752. {
  47753. }
  47754. KeyboardFocusTraverser::~KeyboardFocusTraverser()
  47755. {
  47756. }
  47757. // This will sort a set of components, so that they are ordered in terms of
  47758. // left-to-right and then top-to-bottom.
  47759. class ScreenPositionComparator
  47760. {
  47761. public:
  47762. ScreenPositionComparator() {}
  47763. static int compareElements (const Component* const first, const Component* const second) throw()
  47764. {
  47765. int explicitOrder1 = first->getExplicitFocusOrder();
  47766. if (explicitOrder1 <= 0)
  47767. explicitOrder1 = std::numeric_limits<int>::max() / 2;
  47768. int explicitOrder2 = second->getExplicitFocusOrder();
  47769. if (explicitOrder2 <= 0)
  47770. explicitOrder2 = std::numeric_limits<int>::max() / 2;
  47771. if (explicitOrder1 != explicitOrder2)
  47772. return explicitOrder1 - explicitOrder2;
  47773. const int diff = first->getY() - second->getY();
  47774. return (diff == 0) ? first->getX() - second->getX()
  47775. : diff;
  47776. }
  47777. };
  47778. static void findAllFocusableComponents (Component* const parent, Array <Component*>& comps)
  47779. {
  47780. if (parent->getNumChildComponents() > 0)
  47781. {
  47782. Array <Component*> localComps;
  47783. ScreenPositionComparator comparator;
  47784. int i;
  47785. for (i = parent->getNumChildComponents(); --i >= 0;)
  47786. {
  47787. Component* const c = parent->getChildComponent (i);
  47788. if (c->isVisible() && c->isEnabled())
  47789. localComps.addSorted (comparator, c);
  47790. }
  47791. for (i = 0; i < localComps.size(); ++i)
  47792. {
  47793. Component* const c = localComps.getUnchecked (i);
  47794. if (c->getWantsKeyboardFocus())
  47795. comps.add (c);
  47796. if (! c->isFocusContainer())
  47797. findAllFocusableComponents (c, comps);
  47798. }
  47799. }
  47800. }
  47801. static Component* getIncrementedComponent (Component* const current, const int delta) throw()
  47802. {
  47803. Component* focusContainer = current->getParentComponent();
  47804. if (focusContainer != 0)
  47805. {
  47806. while (focusContainer->getParentComponent() != 0 && ! focusContainer->isFocusContainer())
  47807. focusContainer = focusContainer->getParentComponent();
  47808. if (focusContainer != 0)
  47809. {
  47810. Array <Component*> comps;
  47811. findAllFocusableComponents (focusContainer, comps);
  47812. if (comps.size() > 0)
  47813. {
  47814. const int index = comps.indexOf (current);
  47815. return comps [(index + comps.size() + delta) % comps.size()];
  47816. }
  47817. }
  47818. }
  47819. return 0;
  47820. }
  47821. Component* KeyboardFocusTraverser::getNextComponent (Component* current)
  47822. {
  47823. return getIncrementedComponent (current, 1);
  47824. }
  47825. Component* KeyboardFocusTraverser::getPreviousComponent (Component* current)
  47826. {
  47827. return getIncrementedComponent (current, -1);
  47828. }
  47829. Component* KeyboardFocusTraverser::getDefaultComponent (Component* parentComponent)
  47830. {
  47831. Array <Component*> comps;
  47832. if (parentComponent != 0)
  47833. findAllFocusableComponents (parentComponent, comps);
  47834. return comps.getFirst();
  47835. }
  47836. END_JUCE_NAMESPACE
  47837. /*** End of inlined file: juce_KeyboardFocusTraverser.cpp ***/
  47838. /*** Start of inlined file: juce_KeyListener.cpp ***/
  47839. BEGIN_JUCE_NAMESPACE
  47840. bool KeyListener::keyStateChanged (const bool, Component*)
  47841. {
  47842. return false;
  47843. }
  47844. END_JUCE_NAMESPACE
  47845. /*** End of inlined file: juce_KeyListener.cpp ***/
  47846. /*** Start of inlined file: juce_KeyMappingEditorComponent.cpp ***/
  47847. BEGIN_JUCE_NAMESPACE
  47848. // N.B. these two includes are put here deliberately to avoid problems with
  47849. // old GCCs failing on long include paths
  47850. const int maxKeys = 3;
  47851. class KeyMappingChangeButton : public Button
  47852. {
  47853. public:
  47854. KeyMappingChangeButton (KeyMappingEditorComponent* const owner_,
  47855. const CommandID commandID_,
  47856. const String& keyName,
  47857. const int keyNum_)
  47858. : Button (keyName),
  47859. owner (owner_),
  47860. commandID (commandID_),
  47861. keyNum (keyNum_)
  47862. {
  47863. setWantsKeyboardFocus (false);
  47864. setTriggeredOnMouseDown (keyNum >= 0);
  47865. if (keyNum_ < 0)
  47866. setTooltip (TRANS("adds a new key-mapping"));
  47867. else
  47868. setTooltip (TRANS("click to change this key-mapping"));
  47869. }
  47870. ~KeyMappingChangeButton()
  47871. {
  47872. }
  47873. void paintButton (Graphics& g, bool /*isOver*/, bool /*isDown*/)
  47874. {
  47875. getLookAndFeel().drawKeymapChangeButton (g, getWidth(), getHeight(), *this,
  47876. keyNum >= 0 ? getName() : String::empty);
  47877. }
  47878. void clicked()
  47879. {
  47880. if (keyNum >= 0)
  47881. {
  47882. // existing key clicked..
  47883. PopupMenu m;
  47884. m.addItem (1, TRANS("change this key-mapping"));
  47885. m.addSeparator();
  47886. m.addItem (2, TRANS("remove this key-mapping"));
  47887. const int res = m.show();
  47888. if (res == 1)
  47889. {
  47890. owner->assignNewKey (commandID, keyNum);
  47891. }
  47892. else if (res == 2)
  47893. {
  47894. owner->getMappings()->removeKeyPress (commandID, keyNum);
  47895. }
  47896. }
  47897. else
  47898. {
  47899. // + button pressed..
  47900. owner->assignNewKey (commandID, -1);
  47901. }
  47902. }
  47903. void fitToContent (const int h) throw()
  47904. {
  47905. if (keyNum < 0)
  47906. {
  47907. setSize (h, h);
  47908. }
  47909. else
  47910. {
  47911. Font f (h * 0.6f);
  47912. setSize (jlimit (h * 4, h * 8, 6 + f.getStringWidth (getName())), h);
  47913. }
  47914. }
  47915. juce_UseDebuggingNewOperator
  47916. private:
  47917. KeyMappingEditorComponent* const owner;
  47918. const CommandID commandID;
  47919. const int keyNum;
  47920. KeyMappingChangeButton (const KeyMappingChangeButton&);
  47921. const KeyMappingChangeButton& operator= (const KeyMappingChangeButton&);
  47922. };
  47923. class KeyMappingItemComponent : public Component
  47924. {
  47925. public:
  47926. KeyMappingItemComponent (KeyMappingEditorComponent* const owner_,
  47927. const CommandID commandID_)
  47928. : owner (owner_),
  47929. commandID (commandID_)
  47930. {
  47931. setInterceptsMouseClicks (false, true);
  47932. const bool isReadOnly = owner_->isCommandReadOnly (commandID);
  47933. const Array <KeyPress> keyPresses (owner_->getMappings()->getKeyPressesAssignedToCommand (commandID));
  47934. for (int i = 0; i < jmin (maxKeys, keyPresses.size()); ++i)
  47935. {
  47936. KeyMappingChangeButton* const kb
  47937. = new KeyMappingChangeButton (owner_, commandID,
  47938. owner_->getDescriptionForKeyPress (keyPresses.getReference (i)), i);
  47939. kb->setEnabled (! isReadOnly);
  47940. addAndMakeVisible (kb);
  47941. }
  47942. KeyMappingChangeButton* const kb
  47943. = new KeyMappingChangeButton (owner_, commandID, String::empty, -1);
  47944. addChildComponent (kb);
  47945. kb->setVisible (keyPresses.size() < maxKeys && ! isReadOnly);
  47946. }
  47947. ~KeyMappingItemComponent()
  47948. {
  47949. deleteAllChildren();
  47950. }
  47951. void paint (Graphics& g)
  47952. {
  47953. g.setFont (getHeight() * 0.7f);
  47954. g.setColour (findColour (KeyMappingEditorComponent::textColourId));
  47955. g.drawFittedText (owner->getMappings()->getCommandManager()->getNameOfCommand (commandID),
  47956. 4, 0, jmax (40, getChildComponent (0)->getX() - 5), getHeight(),
  47957. Justification::centredLeft, true);
  47958. }
  47959. void resized()
  47960. {
  47961. int x = getWidth() - 4;
  47962. for (int i = getNumChildComponents(); --i >= 0;)
  47963. {
  47964. KeyMappingChangeButton* const kb = dynamic_cast <KeyMappingChangeButton*> (getChildComponent (i));
  47965. kb->fitToContent (getHeight() - 2);
  47966. kb->setTopRightPosition (x, 1);
  47967. x -= kb->getWidth() + 5;
  47968. }
  47969. }
  47970. juce_UseDebuggingNewOperator
  47971. private:
  47972. KeyMappingEditorComponent* const owner;
  47973. const CommandID commandID;
  47974. KeyMappingItemComponent (const KeyMappingItemComponent&);
  47975. const KeyMappingItemComponent& operator= (const KeyMappingItemComponent&);
  47976. };
  47977. class KeyMappingTreeViewItem : public TreeViewItem
  47978. {
  47979. public:
  47980. KeyMappingTreeViewItem (KeyMappingEditorComponent* const owner_,
  47981. const CommandID commandID_)
  47982. : owner (owner_),
  47983. commandID (commandID_)
  47984. {
  47985. }
  47986. ~KeyMappingTreeViewItem()
  47987. {
  47988. }
  47989. const String getUniqueName() const { return String ((int) commandID) + "_id"; }
  47990. bool mightContainSubItems() { return false; }
  47991. int getItemHeight() const { return 20; }
  47992. Component* createItemComponent()
  47993. {
  47994. return new KeyMappingItemComponent (owner, commandID);
  47995. }
  47996. juce_UseDebuggingNewOperator
  47997. private:
  47998. KeyMappingEditorComponent* const owner;
  47999. const CommandID commandID;
  48000. KeyMappingTreeViewItem (const KeyMappingTreeViewItem&);
  48001. const KeyMappingTreeViewItem& operator= (const KeyMappingTreeViewItem&);
  48002. };
  48003. class KeyCategoryTreeViewItem : public TreeViewItem
  48004. {
  48005. public:
  48006. KeyCategoryTreeViewItem (KeyMappingEditorComponent* const owner_,
  48007. const String& name)
  48008. : owner (owner_),
  48009. categoryName (name)
  48010. {
  48011. }
  48012. ~KeyCategoryTreeViewItem()
  48013. {
  48014. }
  48015. const String getUniqueName() const { return categoryName + "_cat"; }
  48016. bool mightContainSubItems() { return true; }
  48017. int getItemHeight() const { return 28; }
  48018. void paintItem (Graphics& g, int width, int height)
  48019. {
  48020. g.setFont (height * 0.6f, Font::bold);
  48021. g.setColour (owner->findColour (KeyMappingEditorComponent::textColourId));
  48022. g.drawText (categoryName,
  48023. 2, 0, width - 2, height,
  48024. Justification::centredLeft, true);
  48025. }
  48026. void itemOpennessChanged (bool isNowOpen)
  48027. {
  48028. if (isNowOpen)
  48029. {
  48030. if (getNumSubItems() == 0)
  48031. {
  48032. Array <CommandID> commands (owner->getMappings()->getCommandManager()->getCommandsInCategory (categoryName));
  48033. for (int i = 0; i < commands.size(); ++i)
  48034. {
  48035. if (owner->shouldCommandBeIncluded (commands[i]))
  48036. addSubItem (new KeyMappingTreeViewItem (owner, commands[i]));
  48037. }
  48038. }
  48039. }
  48040. else
  48041. {
  48042. clearSubItems();
  48043. }
  48044. }
  48045. juce_UseDebuggingNewOperator
  48046. private:
  48047. KeyMappingEditorComponent* owner;
  48048. String categoryName;
  48049. KeyCategoryTreeViewItem (const KeyCategoryTreeViewItem&);
  48050. const KeyCategoryTreeViewItem& operator= (const KeyCategoryTreeViewItem&);
  48051. };
  48052. KeyMappingEditorComponent::KeyMappingEditorComponent (KeyPressMappingSet* const mappingManager,
  48053. const bool showResetToDefaultButton)
  48054. : mappings (mappingManager)
  48055. {
  48056. jassert (mappingManager != 0); // can't be null!
  48057. mappingManager->addChangeListener (this);
  48058. setLinesDrawnForSubItems (false);
  48059. resetButton = 0;
  48060. if (showResetToDefaultButton)
  48061. {
  48062. addAndMakeVisible (resetButton = new TextButton (TRANS("reset to defaults")));
  48063. resetButton->addButtonListener (this);
  48064. }
  48065. addAndMakeVisible (tree = new TreeView());
  48066. tree->setColour (TreeView::backgroundColourId, findColour (backgroundColourId));
  48067. tree->setRootItemVisible (false);
  48068. tree->setDefaultOpenness (true);
  48069. tree->setRootItem (this);
  48070. }
  48071. KeyMappingEditorComponent::~KeyMappingEditorComponent()
  48072. {
  48073. mappings->removeChangeListener (this);
  48074. deleteAllChildren();
  48075. }
  48076. bool KeyMappingEditorComponent::mightContainSubItems()
  48077. {
  48078. return true;
  48079. }
  48080. const String KeyMappingEditorComponent::getUniqueName() const
  48081. {
  48082. return T("keys");
  48083. }
  48084. void KeyMappingEditorComponent::setColours (const Colour& mainBackground,
  48085. const Colour& textColour)
  48086. {
  48087. setColour (backgroundColourId, mainBackground);
  48088. setColour (textColourId, textColour);
  48089. tree->setColour (TreeView::backgroundColourId, mainBackground);
  48090. }
  48091. void KeyMappingEditorComponent::parentHierarchyChanged()
  48092. {
  48093. changeListenerCallback (0);
  48094. }
  48095. void KeyMappingEditorComponent::resized()
  48096. {
  48097. int h = getHeight();
  48098. if (resetButton != 0)
  48099. {
  48100. const int buttonHeight = 20;
  48101. h -= buttonHeight + 8;
  48102. int x = getWidth() - 8;
  48103. const int y = h + 6;
  48104. resetButton->changeWidthToFitText (buttonHeight);
  48105. resetButton->setTopRightPosition (x, y);
  48106. }
  48107. tree->setBounds (0, 0, getWidth(), h);
  48108. }
  48109. void KeyMappingEditorComponent::buttonClicked (Button* button)
  48110. {
  48111. if (button == resetButton)
  48112. {
  48113. if (AlertWindow::showOkCancelBox (AlertWindow::QuestionIcon,
  48114. TRANS("Reset to defaults"),
  48115. TRANS("Are you sure you want to reset all the key-mappings to their default state?"),
  48116. TRANS("Reset")))
  48117. {
  48118. mappings->resetToDefaultMappings();
  48119. }
  48120. }
  48121. }
  48122. void KeyMappingEditorComponent::changeListenerCallback (void*)
  48123. {
  48124. ScopedPointer <XmlElement> openness (tree->getOpennessState (true));
  48125. clearSubItems();
  48126. const StringArray categories (mappings->getCommandManager()->getCommandCategories());
  48127. for (int i = 0; i < categories.size(); ++i)
  48128. {
  48129. const Array <CommandID> commands (mappings->getCommandManager()->getCommandsInCategory (categories[i]));
  48130. int count = 0;
  48131. for (int j = 0; j < commands.size(); ++j)
  48132. if (shouldCommandBeIncluded (commands[j]))
  48133. ++count;
  48134. if (count > 0)
  48135. addSubItem (new KeyCategoryTreeViewItem (this, categories[i]));
  48136. }
  48137. if (openness != 0)
  48138. tree->restoreOpennessState (*openness);
  48139. }
  48140. class KeyEntryWindow : public AlertWindow
  48141. {
  48142. public:
  48143. KeyEntryWindow (KeyMappingEditorComponent* const owner_)
  48144. : AlertWindow (TRANS("New key-mapping"),
  48145. TRANS("Please press a key combination now..."),
  48146. AlertWindow::NoIcon),
  48147. owner (owner_)
  48148. {
  48149. addButton (TRANS("ok"), 1);
  48150. addButton (TRANS("cancel"), 0);
  48151. // (avoid return + escape keys getting processed by the buttons..)
  48152. for (int i = getNumChildComponents(); --i >= 0;)
  48153. getChildComponent (i)->setWantsKeyboardFocus (false);
  48154. setWantsKeyboardFocus (true);
  48155. grabKeyboardFocus();
  48156. }
  48157. ~KeyEntryWindow()
  48158. {
  48159. }
  48160. bool keyPressed (const KeyPress& key)
  48161. {
  48162. lastPress = key;
  48163. String message (TRANS("Key: ") + owner->getDescriptionForKeyPress (key));
  48164. const CommandID previousCommand = owner->getMappings()->findCommandForKeyPress (key);
  48165. if (previousCommand != 0)
  48166. {
  48167. message << "\n\n"
  48168. << TRANS("(Currently assigned to \"")
  48169. << owner->getMappings()->getCommandManager()->getNameOfCommand (previousCommand)
  48170. << "\")";
  48171. }
  48172. setMessage (message);
  48173. return true;
  48174. }
  48175. bool keyStateChanged (const bool)
  48176. {
  48177. return true;
  48178. }
  48179. KeyPress lastPress;
  48180. juce_UseDebuggingNewOperator
  48181. private:
  48182. KeyMappingEditorComponent* owner;
  48183. KeyEntryWindow (const KeyEntryWindow&);
  48184. const KeyEntryWindow& operator= (const KeyEntryWindow&);
  48185. };
  48186. void KeyMappingEditorComponent::assignNewKey (const CommandID commandID, const int index)
  48187. {
  48188. KeyEntryWindow entryWindow (this);
  48189. if (entryWindow.runModalLoop() != 0)
  48190. {
  48191. entryWindow.setVisible (false);
  48192. if (entryWindow.lastPress.isValid())
  48193. {
  48194. const CommandID previousCommand = mappings->findCommandForKeyPress (entryWindow.lastPress);
  48195. if (previousCommand != 0)
  48196. {
  48197. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  48198. TRANS("Change key-mapping"),
  48199. TRANS("This key is already assigned to the command \"")
  48200. + mappings->getCommandManager()->getNameOfCommand (previousCommand)
  48201. + TRANS("\"\n\nDo you want to re-assign it to this new command instead?"),
  48202. TRANS("re-assign"),
  48203. TRANS("cancel")))
  48204. {
  48205. return;
  48206. }
  48207. }
  48208. mappings->removeKeyPress (entryWindow.lastPress);
  48209. if (index >= 0)
  48210. mappings->removeKeyPress (commandID, index);
  48211. mappings->addKeyPress (commandID, entryWindow.lastPress, index);
  48212. }
  48213. }
  48214. }
  48215. bool KeyMappingEditorComponent::shouldCommandBeIncluded (const CommandID commandID)
  48216. {
  48217. const ApplicationCommandInfo* const ci = mappings->getCommandManager()->getCommandForID (commandID);
  48218. return (ci != 0) && ((ci->flags & ApplicationCommandInfo::hiddenFromKeyEditor) == 0);
  48219. }
  48220. bool KeyMappingEditorComponent::isCommandReadOnly (const CommandID commandID)
  48221. {
  48222. const ApplicationCommandInfo* const ci = mappings->getCommandManager()->getCommandForID (commandID);
  48223. return (ci != 0) && ((ci->flags & ApplicationCommandInfo::readOnlyInKeyEditor) != 0);
  48224. }
  48225. const String KeyMappingEditorComponent::getDescriptionForKeyPress (const KeyPress& key)
  48226. {
  48227. return key.getTextDescription();
  48228. }
  48229. END_JUCE_NAMESPACE
  48230. /*** End of inlined file: juce_KeyMappingEditorComponent.cpp ***/
  48231. /*** Start of inlined file: juce_KeyPress.cpp ***/
  48232. BEGIN_JUCE_NAMESPACE
  48233. KeyPress::KeyPress() throw()
  48234. : keyCode (0),
  48235. mods (0),
  48236. textCharacter (0)
  48237. {
  48238. }
  48239. KeyPress::KeyPress (const int keyCode_,
  48240. const ModifierKeys& mods_,
  48241. const juce_wchar textCharacter_) throw()
  48242. : keyCode (keyCode_),
  48243. mods (mods_),
  48244. textCharacter (textCharacter_)
  48245. {
  48246. }
  48247. KeyPress::KeyPress (const int keyCode_) throw()
  48248. : keyCode (keyCode_),
  48249. textCharacter (0)
  48250. {
  48251. }
  48252. KeyPress::KeyPress (const KeyPress& other) throw()
  48253. : keyCode (other.keyCode),
  48254. mods (other.mods),
  48255. textCharacter (other.textCharacter)
  48256. {
  48257. }
  48258. const KeyPress& KeyPress::operator= (const KeyPress& other) throw()
  48259. {
  48260. keyCode = other.keyCode;
  48261. mods = other.mods;
  48262. textCharacter = other.textCharacter;
  48263. return *this;
  48264. }
  48265. bool KeyPress::operator== (const KeyPress& other) const throw()
  48266. {
  48267. return mods.getRawFlags() == other.mods.getRawFlags()
  48268. && (textCharacter == other.textCharacter
  48269. || textCharacter == 0
  48270. || other.textCharacter == 0)
  48271. && (keyCode == other.keyCode
  48272. || (keyCode < 256
  48273. && other.keyCode < 256
  48274. && CharacterFunctions::toLowerCase ((tchar) keyCode)
  48275. == CharacterFunctions::toLowerCase ((tchar) other.keyCode)));
  48276. }
  48277. bool KeyPress::operator!= (const KeyPress& other) const throw()
  48278. {
  48279. return ! operator== (other);
  48280. }
  48281. bool KeyPress::isCurrentlyDown() const throw()
  48282. {
  48283. return isKeyCurrentlyDown (keyCode)
  48284. && (ModifierKeys::getCurrentModifiers().getRawFlags() & ModifierKeys::allKeyboardModifiers)
  48285. == (mods.getRawFlags() & ModifierKeys::allKeyboardModifiers);
  48286. }
  48287. struct KeyNameAndCode
  48288. {
  48289. const char* name;
  48290. int code;
  48291. };
  48292. static const KeyNameAndCode keyNameTranslations[] =
  48293. {
  48294. { "spacebar", KeyPress::spaceKey },
  48295. { "return", KeyPress::returnKey },
  48296. { "escape", KeyPress::escapeKey },
  48297. { "backspace", KeyPress::backspaceKey },
  48298. { "cursor left", KeyPress::leftKey },
  48299. { "cursor right", KeyPress::rightKey },
  48300. { "cursor up", KeyPress::upKey },
  48301. { "cursor down", KeyPress::downKey },
  48302. { "page up", KeyPress::pageUpKey },
  48303. { "page down", KeyPress::pageDownKey },
  48304. { "home", KeyPress::homeKey },
  48305. { "end", KeyPress::endKey },
  48306. { "delete", KeyPress::deleteKey },
  48307. { "insert", KeyPress::insertKey },
  48308. { "tab", KeyPress::tabKey },
  48309. { "play", KeyPress::playKey },
  48310. { "stop", KeyPress::stopKey },
  48311. { "fast forward", KeyPress::fastForwardKey },
  48312. { "rewind", KeyPress::rewindKey }
  48313. };
  48314. static const tchar* const numberPadPrefix = T("numpad ");
  48315. const KeyPress KeyPress::createFromDescription (const String& desc) throw()
  48316. {
  48317. int modifiers = 0;
  48318. if (desc.containsWholeWordIgnoreCase (T("ctrl"))
  48319. || desc.containsWholeWordIgnoreCase (T("control"))
  48320. || desc.containsWholeWordIgnoreCase (T("ctl")))
  48321. modifiers |= ModifierKeys::ctrlModifier;
  48322. if (desc.containsWholeWordIgnoreCase (T("shift"))
  48323. || desc.containsWholeWordIgnoreCase (T("shft")))
  48324. modifiers |= ModifierKeys::shiftModifier;
  48325. if (desc.containsWholeWordIgnoreCase (T("alt"))
  48326. || desc.containsWholeWordIgnoreCase (T("option")))
  48327. modifiers |= ModifierKeys::altModifier;
  48328. if (desc.containsWholeWordIgnoreCase (T("command"))
  48329. || desc.containsWholeWordIgnoreCase (T("cmd")))
  48330. modifiers |= ModifierKeys::commandModifier;
  48331. int key = 0;
  48332. for (int i = 0; i < numElementsInArray (keyNameTranslations); ++i)
  48333. {
  48334. if (desc.containsWholeWordIgnoreCase (String (keyNameTranslations[i].name)))
  48335. {
  48336. key = keyNameTranslations[i].code;
  48337. break;
  48338. }
  48339. }
  48340. if (key == 0)
  48341. {
  48342. // see if it's a numpad key..
  48343. if (desc.containsIgnoreCase (numberPadPrefix))
  48344. {
  48345. const tchar lastChar = desc.trimEnd().getLastCharacter();
  48346. if (lastChar >= T('0') && lastChar <= T('9'))
  48347. key = numberPad0 + lastChar - T('0');
  48348. else if (lastChar == T('+'))
  48349. key = numberPadAdd;
  48350. else if (lastChar == T('-'))
  48351. key = numberPadSubtract;
  48352. else if (lastChar == T('*'))
  48353. key = numberPadMultiply;
  48354. else if (lastChar == T('/'))
  48355. key = numberPadDivide;
  48356. else if (lastChar == T('.'))
  48357. key = numberPadDecimalPoint;
  48358. else if (lastChar == T('='))
  48359. key = numberPadEquals;
  48360. else if (desc.endsWith (T("separator")))
  48361. key = numberPadSeparator;
  48362. else if (desc.endsWith (T("delete")))
  48363. key = numberPadDelete;
  48364. }
  48365. if (key == 0)
  48366. {
  48367. // see if it's a function key..
  48368. for (int i = 1; i <= 12; ++i)
  48369. if (desc.containsWholeWordIgnoreCase (T("f") + String (i)))
  48370. key = F1Key + i - 1;
  48371. if (key == 0)
  48372. {
  48373. // give up and use the hex code..
  48374. const int hexCode = desc.fromFirstOccurrenceOf (T("#"), false, false)
  48375. .toLowerCase()
  48376. .retainCharacters (T("0123456789abcdef"))
  48377. .getHexValue32();
  48378. if (hexCode > 0)
  48379. key = hexCode;
  48380. else
  48381. key = CharacterFunctions::toUpperCase (desc.getLastCharacter());
  48382. }
  48383. }
  48384. }
  48385. return KeyPress (key, ModifierKeys (modifiers), 0);
  48386. }
  48387. const String KeyPress::getTextDescription() const throw()
  48388. {
  48389. String desc;
  48390. if (keyCode > 0)
  48391. {
  48392. // some keyboard layouts use a shift-key to get the slash, but in those cases, we
  48393. // want to store it as being a slash, not shift+whatever.
  48394. if (textCharacter == T('/'))
  48395. return "/";
  48396. if (mods.isCtrlDown())
  48397. desc << "ctrl + ";
  48398. if (mods.isShiftDown())
  48399. desc << "shift + ";
  48400. #if JUCE_MAC
  48401. // only do this on the mac, because on Windows ctrl and command are the same,
  48402. // and this would get confusing
  48403. if (mods.isCommandDown())
  48404. desc << "command + ";
  48405. if (mods.isAltDown())
  48406. desc << "option + ";
  48407. #else
  48408. if (mods.isAltDown())
  48409. desc << "alt + ";
  48410. #endif
  48411. for (int i = 0; i < numElementsInArray (keyNameTranslations); ++i)
  48412. if (keyCode == keyNameTranslations[i].code)
  48413. return desc + keyNameTranslations[i].name;
  48414. if (keyCode >= F1Key && keyCode <= F16Key)
  48415. desc << 'F' << (1 + keyCode - F1Key);
  48416. else if (keyCode >= numberPad0 && keyCode <= numberPad9)
  48417. desc << numberPadPrefix << (keyCode - numberPad0);
  48418. else if (keyCode >= 33 && keyCode < 176)
  48419. desc += CharacterFunctions::toUpperCase ((tchar) keyCode);
  48420. else if (keyCode == numberPadAdd)
  48421. desc << numberPadPrefix << '+';
  48422. else if (keyCode == numberPadSubtract)
  48423. desc << numberPadPrefix << '-';
  48424. else if (keyCode == numberPadMultiply)
  48425. desc << numberPadPrefix << '*';
  48426. else if (keyCode == numberPadDivide)
  48427. desc << numberPadPrefix << '/';
  48428. else if (keyCode == numberPadSeparator)
  48429. desc << numberPadPrefix << "separator";
  48430. else if (keyCode == numberPadDecimalPoint)
  48431. desc << numberPadPrefix << '.';
  48432. else if (keyCode == numberPadDelete)
  48433. desc << numberPadPrefix << "delete";
  48434. else
  48435. desc << '#' << String::toHexString (keyCode);
  48436. }
  48437. return desc;
  48438. }
  48439. END_JUCE_NAMESPACE
  48440. /*** End of inlined file: juce_KeyPress.cpp ***/
  48441. /*** Start of inlined file: juce_KeyPressMappingSet.cpp ***/
  48442. BEGIN_JUCE_NAMESPACE
  48443. KeyPressMappingSet::KeyPressMappingSet (ApplicationCommandManager* const commandManager_) throw()
  48444. : commandManager (commandManager_)
  48445. {
  48446. // A manager is needed to get the descriptions of commands, and will be called when
  48447. // a command is invoked. So you can't leave this null..
  48448. jassert (commandManager_ != 0);
  48449. Desktop::getInstance().addFocusChangeListener (this);
  48450. }
  48451. KeyPressMappingSet::KeyPressMappingSet (const KeyPressMappingSet& other) throw()
  48452. : commandManager (other.commandManager)
  48453. {
  48454. Desktop::getInstance().addFocusChangeListener (this);
  48455. }
  48456. KeyPressMappingSet::~KeyPressMappingSet()
  48457. {
  48458. Desktop::getInstance().removeFocusChangeListener (this);
  48459. }
  48460. const Array <KeyPress> KeyPressMappingSet::getKeyPressesAssignedToCommand (const CommandID commandID) const throw()
  48461. {
  48462. for (int i = 0; i < mappings.size(); ++i)
  48463. if (mappings.getUnchecked(i)->commandID == commandID)
  48464. return mappings.getUnchecked (i)->keypresses;
  48465. return Array <KeyPress> ();
  48466. }
  48467. void KeyPressMappingSet::addKeyPress (const CommandID commandID,
  48468. const KeyPress& newKeyPress,
  48469. int insertIndex) throw()
  48470. {
  48471. // If you specify an upper-case letter but no shift key, how is the user supposed to press it!?
  48472. // Stick to lower-case letters when defining a keypress, to avoid ambiguity.
  48473. jassert (! (CharacterFunctions::isUpperCase (newKeyPress.getTextCharacter())
  48474. && ! newKeyPress.getModifiers().isShiftDown()));
  48475. if (findCommandForKeyPress (newKeyPress) != commandID)
  48476. {
  48477. removeKeyPress (newKeyPress);
  48478. if (newKeyPress.isValid())
  48479. {
  48480. for (int i = mappings.size(); --i >= 0;)
  48481. {
  48482. if (mappings.getUnchecked(i)->commandID == commandID)
  48483. {
  48484. mappings.getUnchecked(i)->keypresses.insert (insertIndex, newKeyPress);
  48485. sendChangeMessage (this);
  48486. return;
  48487. }
  48488. }
  48489. const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);
  48490. if (ci != 0)
  48491. {
  48492. CommandMapping* const cm = new CommandMapping();
  48493. cm->commandID = commandID;
  48494. cm->keypresses.add (newKeyPress);
  48495. cm->wantsKeyUpDownCallbacks = (ci->flags & ApplicationCommandInfo::wantsKeyUpDownCallbacks) != 0;
  48496. mappings.add (cm);
  48497. sendChangeMessage (this);
  48498. }
  48499. }
  48500. }
  48501. }
  48502. void KeyPressMappingSet::resetToDefaultMappings() throw()
  48503. {
  48504. mappings.clear();
  48505. for (int i = 0; i < commandManager->getNumCommands(); ++i)
  48506. {
  48507. const ApplicationCommandInfo* const ci = commandManager->getCommandForIndex (i);
  48508. for (int j = 0; j < ci->defaultKeypresses.size(); ++j)
  48509. {
  48510. addKeyPress (ci->commandID,
  48511. ci->defaultKeypresses.getReference (j));
  48512. }
  48513. }
  48514. sendChangeMessage (this);
  48515. }
  48516. void KeyPressMappingSet::resetToDefaultMapping (const CommandID commandID) throw()
  48517. {
  48518. clearAllKeyPresses (commandID);
  48519. const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);
  48520. for (int j = 0; j < ci->defaultKeypresses.size(); ++j)
  48521. {
  48522. addKeyPress (ci->commandID,
  48523. ci->defaultKeypresses.getReference (j));
  48524. }
  48525. }
  48526. void KeyPressMappingSet::clearAllKeyPresses() throw()
  48527. {
  48528. if (mappings.size() > 0)
  48529. {
  48530. sendChangeMessage (this);
  48531. mappings.clear();
  48532. }
  48533. }
  48534. void KeyPressMappingSet::clearAllKeyPresses (const CommandID commandID) throw()
  48535. {
  48536. for (int i = mappings.size(); --i >= 0;)
  48537. {
  48538. if (mappings.getUnchecked(i)->commandID == commandID)
  48539. {
  48540. mappings.remove (i);
  48541. sendChangeMessage (this);
  48542. }
  48543. }
  48544. }
  48545. void KeyPressMappingSet::removeKeyPress (const KeyPress& keypress) throw()
  48546. {
  48547. if (keypress.isValid())
  48548. {
  48549. for (int i = mappings.size(); --i >= 0;)
  48550. {
  48551. CommandMapping* const cm = mappings.getUnchecked(i);
  48552. for (int j = cm->keypresses.size(); --j >= 0;)
  48553. {
  48554. if (keypress == cm->keypresses [j])
  48555. {
  48556. cm->keypresses.remove (j);
  48557. sendChangeMessage (this);
  48558. }
  48559. }
  48560. }
  48561. }
  48562. }
  48563. void KeyPressMappingSet::removeKeyPress (const CommandID commandID,
  48564. const int keyPressIndex) throw()
  48565. {
  48566. for (int i = mappings.size(); --i >= 0;)
  48567. {
  48568. if (mappings.getUnchecked(i)->commandID == commandID)
  48569. {
  48570. mappings.getUnchecked(i)->keypresses.remove (keyPressIndex);
  48571. sendChangeMessage (this);
  48572. break;
  48573. }
  48574. }
  48575. }
  48576. CommandID KeyPressMappingSet::findCommandForKeyPress (const KeyPress& keyPress) const throw()
  48577. {
  48578. for (int i = 0; i < mappings.size(); ++i)
  48579. if (mappings.getUnchecked(i)->keypresses.contains (keyPress))
  48580. return mappings.getUnchecked(i)->commandID;
  48581. return 0;
  48582. }
  48583. bool KeyPressMappingSet::containsMapping (const CommandID commandID,
  48584. const KeyPress& keyPress) const throw()
  48585. {
  48586. for (int i = mappings.size(); --i >= 0;)
  48587. if (mappings.getUnchecked(i)->commandID == commandID)
  48588. return mappings.getUnchecked(i)->keypresses.contains (keyPress);
  48589. return false;
  48590. }
  48591. void KeyPressMappingSet::invokeCommand (const CommandID commandID,
  48592. const KeyPress& key,
  48593. const bool isKeyDown,
  48594. const int millisecsSinceKeyPressed,
  48595. Component* const originatingComponent) const
  48596. {
  48597. ApplicationCommandTarget::InvocationInfo info (commandID);
  48598. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromKeyPress;
  48599. info.isKeyDown = isKeyDown;
  48600. info.keyPress = key;
  48601. info.millisecsSinceKeyPressed = millisecsSinceKeyPressed;
  48602. info.originatingComponent = originatingComponent;
  48603. commandManager->invoke (info, false);
  48604. }
  48605. bool KeyPressMappingSet::restoreFromXml (const XmlElement& xmlVersion)
  48606. {
  48607. if (xmlVersion.hasTagName (T("KEYMAPPINGS")))
  48608. {
  48609. if (xmlVersion.getBoolAttribute (T("basedOnDefaults"), true))
  48610. {
  48611. // if the XML was created as a set of differences from the default mappings,
  48612. // (i.e. by calling createXml (true)), then we need to first restore the defaults.
  48613. resetToDefaultMappings();
  48614. }
  48615. else
  48616. {
  48617. // if the XML was created calling createXml (false), then we need to clear all
  48618. // the keys and treat the xml as describing the entire set of mappings.
  48619. clearAllKeyPresses();
  48620. }
  48621. forEachXmlChildElement (xmlVersion, map)
  48622. {
  48623. const CommandID commandId = map->getStringAttribute (T("commandId")).getHexValue32();
  48624. if (commandId != 0)
  48625. {
  48626. const KeyPress key (KeyPress::createFromDescription (map->getStringAttribute (T("key"))));
  48627. if (map->hasTagName (T("MAPPING")))
  48628. {
  48629. addKeyPress (commandId, key);
  48630. }
  48631. else if (map->hasTagName (T("UNMAPPING")))
  48632. {
  48633. if (containsMapping (commandId, key))
  48634. removeKeyPress (key);
  48635. }
  48636. }
  48637. }
  48638. return true;
  48639. }
  48640. return false;
  48641. }
  48642. XmlElement* KeyPressMappingSet::createXml (const bool saveDifferencesFromDefaultSet) const
  48643. {
  48644. ScopedPointer <KeyPressMappingSet> defaultSet;
  48645. if (saveDifferencesFromDefaultSet)
  48646. {
  48647. defaultSet = new KeyPressMappingSet (commandManager);
  48648. defaultSet->resetToDefaultMappings();
  48649. }
  48650. XmlElement* const doc = new XmlElement (T("KEYMAPPINGS"));
  48651. doc->setAttribute (T("basedOnDefaults"), saveDifferencesFromDefaultSet);
  48652. int i;
  48653. for (i = 0; i < mappings.size(); ++i)
  48654. {
  48655. const CommandMapping* const cm = mappings.getUnchecked(i);
  48656. for (int j = 0; j < cm->keypresses.size(); ++j)
  48657. {
  48658. if (defaultSet == 0
  48659. || ! defaultSet->containsMapping (cm->commandID, cm->keypresses.getReference (j)))
  48660. {
  48661. XmlElement* const map = doc->createNewChildElement ("MAPPING");
  48662. map->setAttribute (T("commandId"), String::toHexString ((int) cm->commandID));
  48663. map->setAttribute (T("description"), commandManager->getDescriptionOfCommand (cm->commandID));
  48664. map->setAttribute (T("key"), cm->keypresses.getReference (j).getTextDescription());
  48665. }
  48666. }
  48667. }
  48668. if (defaultSet != 0)
  48669. {
  48670. for (i = 0; i < defaultSet->mappings.size(); ++i)
  48671. {
  48672. const CommandMapping* const cm = defaultSet->mappings.getUnchecked(i);
  48673. for (int j = 0; j < cm->keypresses.size(); ++j)
  48674. {
  48675. if (! containsMapping (cm->commandID, cm->keypresses.getReference (j)))
  48676. {
  48677. XmlElement* const map = doc->createNewChildElement ("UNMAPPING");
  48678. map->setAttribute (T("commandId"), String::toHexString ((int) cm->commandID));
  48679. map->setAttribute (T("description"), commandManager->getDescriptionOfCommand (cm->commandID));
  48680. map->setAttribute (T("key"), cm->keypresses.getReference (j).getTextDescription());
  48681. }
  48682. }
  48683. }
  48684. }
  48685. return doc;
  48686. }
  48687. bool KeyPressMappingSet::keyPressed (const KeyPress& key,
  48688. Component* originatingComponent)
  48689. {
  48690. bool used = false;
  48691. const CommandID commandID = findCommandForKeyPress (key);
  48692. const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);
  48693. if (ci != 0
  48694. && (ci->flags & ApplicationCommandInfo::wantsKeyUpDownCallbacks) == 0)
  48695. {
  48696. ApplicationCommandInfo info (0);
  48697. if (commandManager->getTargetForCommand (commandID, info) != 0
  48698. && (info.flags & ApplicationCommandInfo::isDisabled) == 0)
  48699. {
  48700. invokeCommand (commandID, key, true, 0, originatingComponent);
  48701. used = true;
  48702. }
  48703. else
  48704. {
  48705. if (originatingComponent != 0)
  48706. originatingComponent->getLookAndFeel().playAlertSound();
  48707. }
  48708. }
  48709. return used;
  48710. }
  48711. bool KeyPressMappingSet::keyStateChanged (const bool /*isKeyDown*/, Component* originatingComponent)
  48712. {
  48713. bool used = false;
  48714. const uint32 now = Time::getMillisecondCounter();
  48715. for (int i = mappings.size(); --i >= 0;)
  48716. {
  48717. CommandMapping* const cm = mappings.getUnchecked(i);
  48718. if (cm->wantsKeyUpDownCallbacks)
  48719. {
  48720. for (int j = cm->keypresses.size(); --j >= 0;)
  48721. {
  48722. const KeyPress key (cm->keypresses.getReference (j));
  48723. const bool isDown = key.isCurrentlyDown();
  48724. int keyPressEntryIndex = 0;
  48725. bool wasDown = false;
  48726. for (int k = keysDown.size(); --k >= 0;)
  48727. {
  48728. if (key == keysDown.getUnchecked(k)->key)
  48729. {
  48730. keyPressEntryIndex = k;
  48731. wasDown = true;
  48732. used = true;
  48733. break;
  48734. }
  48735. }
  48736. if (isDown != wasDown)
  48737. {
  48738. int millisecs = 0;
  48739. if (isDown)
  48740. {
  48741. KeyPressTime* const k = new KeyPressTime();
  48742. k->key = key;
  48743. k->timeWhenPressed = now;
  48744. keysDown.add (k);
  48745. }
  48746. else
  48747. {
  48748. const uint32 pressTime = keysDown.getUnchecked (keyPressEntryIndex)->timeWhenPressed;
  48749. if (now > pressTime)
  48750. millisecs = now - pressTime;
  48751. keysDown.remove (keyPressEntryIndex);
  48752. }
  48753. invokeCommand (cm->commandID, key, isDown, millisecs, originatingComponent);
  48754. used = true;
  48755. }
  48756. }
  48757. }
  48758. }
  48759. return used;
  48760. }
  48761. void KeyPressMappingSet::globalFocusChanged (Component* focusedComponent)
  48762. {
  48763. if (focusedComponent != 0)
  48764. focusedComponent->keyStateChanged (false);
  48765. }
  48766. END_JUCE_NAMESPACE
  48767. /*** End of inlined file: juce_KeyPressMappingSet.cpp ***/
  48768. /*** Start of inlined file: juce_ModifierKeys.cpp ***/
  48769. BEGIN_JUCE_NAMESPACE
  48770. ModifierKeys::ModifierKeys (const int flags_) throw()
  48771. : flags (flags_)
  48772. {
  48773. }
  48774. ModifierKeys::ModifierKeys (const ModifierKeys& other) throw()
  48775. : flags (other.flags)
  48776. {
  48777. }
  48778. const ModifierKeys& ModifierKeys::operator= (const ModifierKeys& other) throw()
  48779. {
  48780. flags = other.flags;
  48781. return *this;
  48782. }
  48783. int ModifierKeys::currentModifierFlags = 0;
  48784. const ModifierKeys ModifierKeys::getCurrentModifiers() throw()
  48785. {
  48786. return ModifierKeys (currentModifierFlags);
  48787. }
  48788. int ModifierKeys::getNumMouseButtonsDown() const throw()
  48789. {
  48790. int num = 0;
  48791. if (isLeftButtonDown()) ++num;
  48792. if (isRightButtonDown()) ++num;
  48793. if (isMiddleButtonDown()) ++num;
  48794. return num;
  48795. }
  48796. END_JUCE_NAMESPACE
  48797. /*** End of inlined file: juce_ModifierKeys.cpp ***/
  48798. /*** Start of inlined file: juce_ComponentAnimator.cpp ***/
  48799. BEGIN_JUCE_NAMESPACE
  48800. struct AnimationTask
  48801. {
  48802. AnimationTask (Component* const comp)
  48803. : component (comp),
  48804. watcher (comp)
  48805. {
  48806. }
  48807. Component* component;
  48808. ComponentDeletionWatcher watcher;
  48809. Rectangle<int> destination;
  48810. int msElapsed, msTotal;
  48811. double startSpeed, midSpeed, endSpeed, lastProgress;
  48812. double left, top, right, bottom;
  48813. bool useTimeslice (const int elapsed)
  48814. {
  48815. if (watcher.hasBeenDeleted())
  48816. return false;
  48817. msElapsed += elapsed;
  48818. double newProgress = msElapsed / (double) msTotal;
  48819. if (newProgress >= 0 && newProgress < 1.0)
  48820. {
  48821. newProgress = timeToDistance (newProgress);
  48822. const double delta = (newProgress - lastProgress) / (1.0 - lastProgress);
  48823. jassert (newProgress >= lastProgress);
  48824. lastProgress = newProgress;
  48825. left += (destination.getX() - left) * delta;
  48826. top += (destination.getY() - top) * delta;
  48827. right += (destination.getRight() - right) * delta;
  48828. bottom += (destination.getBottom() - bottom) * delta;
  48829. if (delta < 1.0)
  48830. {
  48831. const Rectangle<int> newBounds (roundToInt (left),
  48832. roundToInt (top),
  48833. roundToInt (right - left),
  48834. roundToInt (bottom - top));
  48835. if (newBounds != destination)
  48836. {
  48837. component->setBounds (newBounds);
  48838. return true;
  48839. }
  48840. }
  48841. }
  48842. component->setBounds (destination);
  48843. return false;
  48844. }
  48845. void moveToFinalDestination()
  48846. {
  48847. if (! watcher.hasBeenDeleted())
  48848. component->setBounds (destination);
  48849. }
  48850. private:
  48851. inline double timeToDistance (const double time) const
  48852. {
  48853. return (time < 0.5) ? time * (startSpeed + time * (midSpeed - startSpeed))
  48854. : 0.5 * (startSpeed + 0.5 * (midSpeed - startSpeed))
  48855. + (time - 0.5) * (midSpeed + (time - 0.5) * (endSpeed - midSpeed));
  48856. }
  48857. };
  48858. ComponentAnimator::ComponentAnimator()
  48859. : lastTime (0)
  48860. {
  48861. }
  48862. ComponentAnimator::~ComponentAnimator()
  48863. {
  48864. cancelAllAnimations (false);
  48865. jassert (tasks.size() == 0);
  48866. }
  48867. void* ComponentAnimator::findTaskFor (Component* const component) const
  48868. {
  48869. for (int i = tasks.size(); --i >= 0;)
  48870. if (component == ((AnimationTask*) tasks.getUnchecked(i))->component)
  48871. return tasks.getUnchecked(i);
  48872. return 0;
  48873. }
  48874. void ComponentAnimator::animateComponent (Component* const component,
  48875. const Rectangle<int>& finalPosition,
  48876. const int millisecondsToSpendMoving,
  48877. const double startSpeed,
  48878. const double endSpeed)
  48879. {
  48880. if (component != 0)
  48881. {
  48882. AnimationTask* at = (AnimationTask*) findTaskFor (component);
  48883. if (at == 0)
  48884. {
  48885. at = new AnimationTask (component);
  48886. tasks.add (at);
  48887. sendChangeMessage (this);
  48888. }
  48889. at->msElapsed = 0;
  48890. at->lastProgress = 0;
  48891. at->msTotal = jmax (1, millisecondsToSpendMoving);
  48892. at->destination = finalPosition;
  48893. // the speeds must be 0 or greater!
  48894. jassert (startSpeed >= 0 && endSpeed >= 0)
  48895. const double invTotalDistance = 4.0 / (startSpeed + endSpeed + 2.0);
  48896. at->startSpeed = jmax (0.0, startSpeed * invTotalDistance);
  48897. at->midSpeed = invTotalDistance;
  48898. at->endSpeed = jmax (0.0, endSpeed * invTotalDistance);
  48899. at->left = component->getX();
  48900. at->top = component->getY();
  48901. at->right = component->getRight();
  48902. at->bottom = component->getBottom();
  48903. if (! isTimerRunning())
  48904. {
  48905. lastTime = Time::getMillisecondCounter();
  48906. startTimer (1000 / 50);
  48907. }
  48908. }
  48909. }
  48910. void ComponentAnimator::cancelAllAnimations (const bool moveComponentsToTheirFinalPositions)
  48911. {
  48912. for (int i = tasks.size(); --i >= 0;)
  48913. {
  48914. AnimationTask* const at = (AnimationTask*) tasks.getUnchecked(i);
  48915. if (moveComponentsToTheirFinalPositions)
  48916. at->moveToFinalDestination();
  48917. delete at;
  48918. tasks.remove (i);
  48919. sendChangeMessage (this);
  48920. }
  48921. }
  48922. void ComponentAnimator::cancelAnimation (Component* const component,
  48923. const bool moveComponentToItsFinalPosition)
  48924. {
  48925. AnimationTask* const at = (AnimationTask*) findTaskFor (component);
  48926. if (at != 0)
  48927. {
  48928. if (moveComponentToItsFinalPosition)
  48929. at->moveToFinalDestination();
  48930. tasks.removeValue (at);
  48931. delete at;
  48932. sendChangeMessage (this);
  48933. }
  48934. }
  48935. const Rectangle<int> ComponentAnimator::getComponentDestination (Component* const component)
  48936. {
  48937. AnimationTask* const at = (AnimationTask*) findTaskFor (component);
  48938. if (at != 0)
  48939. return at->destination;
  48940. else if (component != 0)
  48941. return component->getBounds();
  48942. return Rectangle<int>();
  48943. }
  48944. bool ComponentAnimator::isAnimating (Component* component) const
  48945. {
  48946. return findTaskFor (component) != 0;
  48947. }
  48948. void ComponentAnimator::timerCallback()
  48949. {
  48950. const uint32 timeNow = Time::getMillisecondCounter();
  48951. if (lastTime == 0 || lastTime == timeNow)
  48952. lastTime = timeNow;
  48953. const int elapsed = timeNow - lastTime;
  48954. for (int i = tasks.size(); --i >= 0;)
  48955. {
  48956. AnimationTask* const at = (AnimationTask*) tasks.getUnchecked(i);
  48957. if (! at->useTimeslice (elapsed))
  48958. {
  48959. tasks.remove (i);
  48960. delete at;
  48961. sendChangeMessage (this);
  48962. }
  48963. }
  48964. lastTime = timeNow;
  48965. if (tasks.size() == 0)
  48966. stopTimer();
  48967. }
  48968. END_JUCE_NAMESPACE
  48969. /*** End of inlined file: juce_ComponentAnimator.cpp ***/
  48970. /*** Start of inlined file: juce_ComponentBoundsConstrainer.cpp ***/
  48971. BEGIN_JUCE_NAMESPACE
  48972. ComponentBoundsConstrainer::ComponentBoundsConstrainer() throw()
  48973. : minW (0),
  48974. maxW (0x3fffffff),
  48975. minH (0),
  48976. maxH (0x3fffffff),
  48977. minOffTop (0),
  48978. minOffLeft (0),
  48979. minOffBottom (0),
  48980. minOffRight (0),
  48981. aspectRatio (0.0)
  48982. {
  48983. }
  48984. ComponentBoundsConstrainer::~ComponentBoundsConstrainer()
  48985. {
  48986. }
  48987. void ComponentBoundsConstrainer::setMinimumWidth (const int minimumWidth) throw()
  48988. {
  48989. minW = minimumWidth;
  48990. }
  48991. void ComponentBoundsConstrainer::setMaximumWidth (const int maximumWidth) throw()
  48992. {
  48993. maxW = maximumWidth;
  48994. }
  48995. void ComponentBoundsConstrainer::setMinimumHeight (const int minimumHeight) throw()
  48996. {
  48997. minH = minimumHeight;
  48998. }
  48999. void ComponentBoundsConstrainer::setMaximumHeight (const int maximumHeight) throw()
  49000. {
  49001. maxH = maximumHeight;
  49002. }
  49003. void ComponentBoundsConstrainer::setMinimumSize (const int minimumWidth, const int minimumHeight) throw()
  49004. {
  49005. jassert (maxW >= minimumWidth);
  49006. jassert (maxH >= minimumHeight);
  49007. jassert (minimumWidth > 0 && minimumHeight > 0);
  49008. minW = minimumWidth;
  49009. minH = minimumHeight;
  49010. if (minW > maxW)
  49011. maxW = minW;
  49012. if (minH > maxH)
  49013. maxH = minH;
  49014. }
  49015. void ComponentBoundsConstrainer::setMaximumSize (const int maximumWidth, const int maximumHeight) throw()
  49016. {
  49017. jassert (maximumWidth >= minW);
  49018. jassert (maximumHeight >= minH);
  49019. jassert (maximumWidth > 0 && maximumHeight > 0);
  49020. maxW = jmax (minW, maximumWidth);
  49021. maxH = jmax (minH, maximumHeight);
  49022. }
  49023. void ComponentBoundsConstrainer::setSizeLimits (const int minimumWidth,
  49024. const int minimumHeight,
  49025. const int maximumWidth,
  49026. const int maximumHeight) throw()
  49027. {
  49028. jassert (maximumWidth >= minimumWidth);
  49029. jassert (maximumHeight >= minimumHeight);
  49030. jassert (maximumWidth > 0 && maximumHeight > 0);
  49031. jassert (minimumWidth > 0 && minimumHeight > 0);
  49032. minW = jmax (0, minimumWidth);
  49033. minH = jmax (0, minimumHeight);
  49034. maxW = jmax (minW, maximumWidth);
  49035. maxH = jmax (minH, maximumHeight);
  49036. }
  49037. void ComponentBoundsConstrainer::setMinimumOnscreenAmounts (const int minimumWhenOffTheTop,
  49038. const int minimumWhenOffTheLeft,
  49039. const int minimumWhenOffTheBottom,
  49040. const int minimumWhenOffTheRight) throw()
  49041. {
  49042. minOffTop = minimumWhenOffTheTop;
  49043. minOffLeft = minimumWhenOffTheLeft;
  49044. minOffBottom = minimumWhenOffTheBottom;
  49045. minOffRight = minimumWhenOffTheRight;
  49046. }
  49047. void ComponentBoundsConstrainer::setFixedAspectRatio (const double widthOverHeight) throw()
  49048. {
  49049. aspectRatio = jmax (0.0, widthOverHeight);
  49050. }
  49051. double ComponentBoundsConstrainer::getFixedAspectRatio() const throw()
  49052. {
  49053. return aspectRatio;
  49054. }
  49055. void ComponentBoundsConstrainer::setBoundsForComponent (Component* const component,
  49056. const Rectangle<int>& targetBounds,
  49057. const bool isStretchingTop,
  49058. const bool isStretchingLeft,
  49059. const bool isStretchingBottom,
  49060. const bool isStretchingRight)
  49061. {
  49062. jassert (component != 0);
  49063. Rectangle<int> limits, bounds (targetBounds);
  49064. BorderSize border;
  49065. Component* const parent = component->getParentComponent();
  49066. if (parent == 0)
  49067. {
  49068. ComponentPeer* peer = component->getPeer();
  49069. if (peer != 0)
  49070. border = peer->getFrameSize();
  49071. limits = Desktop::getInstance().getMonitorAreaContaining (bounds.getCentreX(),
  49072. bounds.getCentreY());
  49073. }
  49074. else
  49075. {
  49076. limits.setSize (parent->getWidth(), parent->getHeight());
  49077. }
  49078. border.addTo (bounds);
  49079. checkBounds (bounds,
  49080. border.addedTo (component->getBounds()), limits,
  49081. isStretchingTop, isStretchingLeft,
  49082. isStretchingBottom, isStretchingRight);
  49083. border.subtractFrom (bounds);
  49084. applyBoundsToComponent (component, bounds);
  49085. }
  49086. void ComponentBoundsConstrainer::checkComponentBounds (Component* component)
  49087. {
  49088. setBoundsForComponent (component, component->getBounds(),
  49089. false, false, false, false);
  49090. }
  49091. void ComponentBoundsConstrainer::applyBoundsToComponent (Component* component,
  49092. const Rectangle<int>& bounds)
  49093. {
  49094. component->setBounds (bounds);
  49095. }
  49096. void ComponentBoundsConstrainer::resizeStart()
  49097. {
  49098. }
  49099. void ComponentBoundsConstrainer::resizeEnd()
  49100. {
  49101. }
  49102. void ComponentBoundsConstrainer::checkBounds (Rectangle<int>& bounds,
  49103. const Rectangle<int>& old,
  49104. const Rectangle<int>& limits,
  49105. const bool isStretchingTop,
  49106. const bool isStretchingLeft,
  49107. const bool isStretchingBottom,
  49108. const bool isStretchingRight)
  49109. {
  49110. int x = bounds.getX();
  49111. int y = bounds.getY();
  49112. int w = bounds.getWidth();
  49113. int h = bounds.getHeight();
  49114. // constrain the size if it's being stretched..
  49115. if (isStretchingLeft)
  49116. {
  49117. x = jlimit (old.getRight() - maxW, old.getRight() - minW, x);
  49118. w = old.getRight() - x;
  49119. }
  49120. if (isStretchingRight)
  49121. {
  49122. w = jlimit (minW, maxW, w);
  49123. }
  49124. if (isStretchingTop)
  49125. {
  49126. y = jlimit (old.getBottom() - maxH, old.getBottom() - minH, y);
  49127. h = old.getBottom() - y;
  49128. }
  49129. if (isStretchingBottom)
  49130. {
  49131. h = jlimit (minH, maxH, h);
  49132. }
  49133. // constrain the aspect ratio if one has been specified..
  49134. if (aspectRatio > 0.0 && w > 0 && h > 0)
  49135. {
  49136. bool adjustWidth;
  49137. if ((isStretchingTop || isStretchingBottom) && ! (isStretchingLeft || isStretchingRight))
  49138. {
  49139. adjustWidth = true;
  49140. }
  49141. else if ((isStretchingLeft || isStretchingRight) && ! (isStretchingTop || isStretchingBottom))
  49142. {
  49143. adjustWidth = false;
  49144. }
  49145. else
  49146. {
  49147. const double oldRatio = (old.getHeight() > 0) ? fabs (old.getWidth() / (double) old.getHeight()) : 0.0;
  49148. const double newRatio = fabs (w / (double) h);
  49149. adjustWidth = (oldRatio > newRatio);
  49150. }
  49151. if (adjustWidth)
  49152. {
  49153. w = roundToInt (h * aspectRatio);
  49154. if (w > maxW || w < minW)
  49155. {
  49156. w = jlimit (minW, maxW, w);
  49157. h = roundToInt (w / aspectRatio);
  49158. }
  49159. }
  49160. else
  49161. {
  49162. h = roundToInt (w / aspectRatio);
  49163. if (h > maxH || h < minH)
  49164. {
  49165. h = jlimit (minH, maxH, h);
  49166. w = roundToInt (h * aspectRatio);
  49167. }
  49168. }
  49169. if ((isStretchingTop || isStretchingBottom) && ! (isStretchingLeft || isStretchingRight))
  49170. {
  49171. x = old.getX() + (old.getWidth() - w) / 2;
  49172. }
  49173. else if ((isStretchingLeft || isStretchingRight) && ! (isStretchingTop || isStretchingBottom))
  49174. {
  49175. y = old.getY() + (old.getHeight() - h) / 2;
  49176. }
  49177. else
  49178. {
  49179. if (isStretchingLeft)
  49180. x = old.getRight() - w;
  49181. if (isStretchingTop)
  49182. y = old.getBottom() - h;
  49183. }
  49184. }
  49185. // ...and constrain the position if limits have been set for that.
  49186. if (minOffTop > 0 || minOffLeft > 0 || minOffBottom > 0 || minOffRight > 0)
  49187. {
  49188. if (minOffTop > 0)
  49189. {
  49190. const int limit = limits.getY() + jmin (minOffTop - h, 0);
  49191. if (y < limit)
  49192. {
  49193. if (isStretchingTop)
  49194. h -= (limit - y);
  49195. y = limit;
  49196. }
  49197. }
  49198. if (minOffLeft > 0)
  49199. {
  49200. const int limit = limits.getX() + jmin (minOffLeft - w, 0);
  49201. if (x < limit)
  49202. {
  49203. if (isStretchingLeft)
  49204. w -= (limit - x);
  49205. x = limit;
  49206. }
  49207. }
  49208. if (minOffBottom > 0)
  49209. {
  49210. const int limit = limits.getBottom() - jmin (minOffBottom, h);
  49211. if (y > limit)
  49212. {
  49213. if (isStretchingBottom)
  49214. h += (limit - y);
  49215. else
  49216. y = limit;
  49217. }
  49218. }
  49219. if (minOffRight > 0)
  49220. {
  49221. const int limit = limits.getRight() - jmin (minOffRight, w);
  49222. if (x > limit)
  49223. {
  49224. if (isStretchingRight)
  49225. w += (limit - x);
  49226. else
  49227. x = limit;
  49228. }
  49229. }
  49230. }
  49231. jassert (w >= 0 && h >= 0);
  49232. bounds = Rectangle<int> (x, y, w, h);
  49233. }
  49234. END_JUCE_NAMESPACE
  49235. /*** End of inlined file: juce_ComponentBoundsConstrainer.cpp ***/
  49236. /*** Start of inlined file: juce_ComponentMovementWatcher.cpp ***/
  49237. BEGIN_JUCE_NAMESPACE
  49238. ComponentMovementWatcher::ComponentMovementWatcher (Component* const component_)
  49239. : component (component_),
  49240. lastPeer (0),
  49241. reentrant (false)
  49242. {
  49243. jassert (component != 0); // can't use this with a null pointer..
  49244. #ifdef JUCE_DEBUG
  49245. deletionWatcher = new ComponentDeletionWatcher (component_);
  49246. #endif
  49247. component->addComponentListener (this);
  49248. registerWithParentComps();
  49249. }
  49250. ComponentMovementWatcher::~ComponentMovementWatcher()
  49251. {
  49252. component->removeComponentListener (this);
  49253. unregister();
  49254. }
  49255. void ComponentMovementWatcher::componentParentHierarchyChanged (Component&)
  49256. {
  49257. #ifdef JUCE_DEBUG
  49258. // agh! don't delete the target component without deleting this object first!
  49259. jassert (! deletionWatcher->hasBeenDeleted());
  49260. #endif
  49261. if (! reentrant)
  49262. {
  49263. reentrant = true;
  49264. ComponentPeer* const peer = component->getPeer();
  49265. if (peer != lastPeer)
  49266. {
  49267. ComponentDeletionWatcher watcher (component);
  49268. componentPeerChanged();
  49269. if (watcher.hasBeenDeleted())
  49270. return;
  49271. lastPeer = peer;
  49272. }
  49273. unregister();
  49274. registerWithParentComps();
  49275. reentrant = false;
  49276. componentMovedOrResized (*component, true, true);
  49277. }
  49278. }
  49279. void ComponentMovementWatcher::componentMovedOrResized (Component&, bool wasMoved, bool wasResized)
  49280. {
  49281. #ifdef JUCE_DEBUG
  49282. // agh! don't delete the target component without deleting this object first!
  49283. jassert (! deletionWatcher->hasBeenDeleted());
  49284. #endif
  49285. if (wasMoved)
  49286. {
  49287. int x = 0, y = 0;
  49288. component->relativePositionToOtherComponent (component->getTopLevelComponent(), x, y);
  49289. wasMoved = (lastX != x || lastY != y);
  49290. lastX = x;
  49291. lastY = y;
  49292. }
  49293. wasResized = (lastWidth != component->getWidth() || lastHeight != component->getHeight());
  49294. lastWidth = component->getWidth();
  49295. lastHeight = component->getHeight();
  49296. if (wasMoved || wasResized)
  49297. componentMovedOrResized (wasMoved, wasResized);
  49298. }
  49299. void ComponentMovementWatcher::registerWithParentComps() throw()
  49300. {
  49301. Component* p = component->getParentComponent();
  49302. while (p != 0)
  49303. {
  49304. p->addComponentListener (this);
  49305. registeredParentComps.add (p);
  49306. p = p->getParentComponent();
  49307. }
  49308. }
  49309. void ComponentMovementWatcher::unregister() throw()
  49310. {
  49311. for (int i = registeredParentComps.size(); --i >= 0;)
  49312. ((Component*) registeredParentComps.getUnchecked(i))->removeComponentListener (this);
  49313. registeredParentComps.clear();
  49314. }
  49315. END_JUCE_NAMESPACE
  49316. /*** End of inlined file: juce_ComponentMovementWatcher.cpp ***/
  49317. /*** Start of inlined file: juce_GroupComponent.cpp ***/
  49318. BEGIN_JUCE_NAMESPACE
  49319. GroupComponent::GroupComponent (const String& componentName,
  49320. const String& labelText)
  49321. : Component (componentName),
  49322. text (labelText),
  49323. justification (Justification::left)
  49324. {
  49325. setInterceptsMouseClicks (false, true);
  49326. }
  49327. GroupComponent::~GroupComponent()
  49328. {
  49329. }
  49330. void GroupComponent::setText (const String& newText) throw()
  49331. {
  49332. if (text != newText)
  49333. {
  49334. text = newText;
  49335. repaint();
  49336. }
  49337. }
  49338. const String GroupComponent::getText() const throw()
  49339. {
  49340. return text;
  49341. }
  49342. void GroupComponent::setTextLabelPosition (const Justification& newJustification)
  49343. {
  49344. if (justification.getFlags() != newJustification.getFlags())
  49345. {
  49346. justification = newJustification;
  49347. repaint();
  49348. }
  49349. }
  49350. void GroupComponent::paint (Graphics& g)
  49351. {
  49352. getLookAndFeel()
  49353. .drawGroupComponentOutline (g, getWidth(), getHeight(),
  49354. text, justification,
  49355. *this);
  49356. }
  49357. void GroupComponent::enablementChanged()
  49358. {
  49359. repaint();
  49360. }
  49361. void GroupComponent::colourChanged()
  49362. {
  49363. repaint();
  49364. }
  49365. END_JUCE_NAMESPACE
  49366. /*** End of inlined file: juce_GroupComponent.cpp ***/
  49367. /*** Start of inlined file: juce_MultiDocumentPanel.cpp ***/
  49368. BEGIN_JUCE_NAMESPACE
  49369. MultiDocumentPanelWindow::MultiDocumentPanelWindow (const Colour& backgroundColour)
  49370. : DocumentWindow (String::empty, backgroundColour,
  49371. DocumentWindow::maximiseButton | DocumentWindow::closeButton, false)
  49372. {
  49373. }
  49374. MultiDocumentPanelWindow::~MultiDocumentPanelWindow()
  49375. {
  49376. }
  49377. void MultiDocumentPanelWindow::maximiseButtonPressed()
  49378. {
  49379. MultiDocumentPanel* const owner = getOwner();
  49380. jassert (owner != 0); // these windows are only designed to be used inside a MultiDocumentPanel!
  49381. if (owner != 0)
  49382. owner->setLayoutMode (MultiDocumentPanel::MaximisedWindowsWithTabs);
  49383. }
  49384. void MultiDocumentPanelWindow::closeButtonPressed()
  49385. {
  49386. MultiDocumentPanel* const owner = getOwner();
  49387. jassert (owner != 0); // these windows are only designed to be used inside a MultiDocumentPanel!
  49388. if (owner != 0)
  49389. owner->closeDocument (getContentComponent(), true);
  49390. }
  49391. void MultiDocumentPanelWindow::activeWindowStatusChanged()
  49392. {
  49393. DocumentWindow::activeWindowStatusChanged();
  49394. updateOrder();
  49395. }
  49396. void MultiDocumentPanelWindow::broughtToFront()
  49397. {
  49398. DocumentWindow::broughtToFront();
  49399. updateOrder();
  49400. }
  49401. void MultiDocumentPanelWindow::updateOrder()
  49402. {
  49403. MultiDocumentPanel* const owner = getOwner();
  49404. if (owner != 0)
  49405. owner->updateOrder();
  49406. }
  49407. MultiDocumentPanel* MultiDocumentPanelWindow::getOwner() const throw()
  49408. {
  49409. // (unable to use the syntax findParentComponentOfClass <MultiDocumentPanel> () because of a VC6 compiler bug)
  49410. return findParentComponentOfClass ((MultiDocumentPanel*) 0);
  49411. }
  49412. class MDITabbedComponentInternal : public TabbedComponent
  49413. {
  49414. public:
  49415. MDITabbedComponentInternal()
  49416. : TabbedComponent (TabbedButtonBar::TabsAtTop)
  49417. {
  49418. }
  49419. ~MDITabbedComponentInternal()
  49420. {
  49421. }
  49422. void currentTabChanged (const int, const String&)
  49423. {
  49424. // (unable to use the syntax findParentComponentOfClass <MultiDocumentPanel> () because of a VC6 compiler bug)
  49425. MultiDocumentPanel* const owner = findParentComponentOfClass ((MultiDocumentPanel*) 0);
  49426. if (owner != 0)
  49427. owner->updateOrder();
  49428. }
  49429. };
  49430. MultiDocumentPanel::MultiDocumentPanel()
  49431. : mode (MaximisedWindowsWithTabs),
  49432. tabComponent (0),
  49433. backgroundColour (Colours::lightblue),
  49434. maximumNumDocuments (0),
  49435. numDocsBeforeTabsUsed (0)
  49436. {
  49437. setOpaque (true);
  49438. }
  49439. MultiDocumentPanel::~MultiDocumentPanel()
  49440. {
  49441. closeAllDocuments (false);
  49442. }
  49443. static bool shouldDeleteComp (Component* const c)
  49444. {
  49445. return c->getProperties() ["mdiDocumentDelete_"];
  49446. }
  49447. bool MultiDocumentPanel::closeAllDocuments (const bool checkItsOkToCloseFirst)
  49448. {
  49449. while (components.size() > 0)
  49450. if (! closeDocument (components.getLast(), checkItsOkToCloseFirst))
  49451. return false;
  49452. return true;
  49453. }
  49454. MultiDocumentPanelWindow* MultiDocumentPanel::createNewDocumentWindow()
  49455. {
  49456. return new MultiDocumentPanelWindow (backgroundColour);
  49457. }
  49458. void MultiDocumentPanel::addWindow (Component* component)
  49459. {
  49460. MultiDocumentPanelWindow* const dw = createNewDocumentWindow();
  49461. dw->setResizable (true, false);
  49462. dw->setContentComponent (component, false, true);
  49463. dw->setName (component->getName());
  49464. const var bkg (component->getProperties() ["mdiDocumentBkg_"]);
  49465. dw->setBackgroundColour (bkg.isVoid() ? backgroundColour : Colour ((int) bkg));
  49466. int x = 4;
  49467. Component* const topComp = getChildComponent (getNumChildComponents() - 1);
  49468. if (topComp != 0 && topComp->getX() == x && topComp->getY() == x)
  49469. x += 16;
  49470. dw->setTopLeftPosition (x, x);
  49471. const var pos (component->getProperties() ["mdiDocumentPos_"]);
  49472. if (pos.toString().isNotEmpty())
  49473. dw->restoreWindowStateFromString (pos.toString());
  49474. addAndMakeVisible (dw);
  49475. dw->toFront (true);
  49476. }
  49477. bool MultiDocumentPanel::addDocument (Component* const component,
  49478. const Colour& docColour,
  49479. const bool deleteWhenRemoved)
  49480. {
  49481. // If you try passing a full DocumentWindow or ResizableWindow in here, you'll end up
  49482. // with a frame-within-a-frame! Just pass in the bare content component.
  49483. jassert (dynamic_cast <ResizableWindow*> (component) == 0);
  49484. if (component == 0 || (maximumNumDocuments > 0 && components.size() >= maximumNumDocuments))
  49485. return false;
  49486. components.add (component);
  49487. component->getProperties().set ("mdiDocumentDelete_", deleteWhenRemoved);
  49488. component->getProperties().set ("mdiDocumentBkg_", (int) docColour.getARGB());
  49489. component->addComponentListener (this);
  49490. if (mode == FloatingWindows)
  49491. {
  49492. if (isFullscreenWhenOneDocument())
  49493. {
  49494. if (components.size() == 1)
  49495. {
  49496. addAndMakeVisible (component);
  49497. }
  49498. else
  49499. {
  49500. if (components.size() == 2)
  49501. addWindow (components.getFirst());
  49502. addWindow (component);
  49503. }
  49504. }
  49505. else
  49506. {
  49507. addWindow (component);
  49508. }
  49509. }
  49510. else
  49511. {
  49512. if (tabComponent == 0 && components.size() > numDocsBeforeTabsUsed)
  49513. {
  49514. addAndMakeVisible (tabComponent = new MDITabbedComponentInternal());
  49515. Array <Component*> temp (components);
  49516. for (int i = 0; i < temp.size(); ++i)
  49517. tabComponent->addTab (temp[i]->getName(), docColour, temp[i], false);
  49518. resized();
  49519. }
  49520. else
  49521. {
  49522. if (tabComponent != 0)
  49523. tabComponent->addTab (component->getName(), docColour, component, false);
  49524. else
  49525. addAndMakeVisible (component);
  49526. }
  49527. setActiveDocument (component);
  49528. }
  49529. resized();
  49530. activeDocumentChanged();
  49531. return true;
  49532. }
  49533. bool MultiDocumentPanel::closeDocument (Component* component,
  49534. const bool checkItsOkToCloseFirst)
  49535. {
  49536. if (components.contains (component))
  49537. {
  49538. if (checkItsOkToCloseFirst && ! tryToCloseDocument (component))
  49539. return false;
  49540. component->removeComponentListener (this);
  49541. const bool shouldDelete = shouldDeleteComp (component);
  49542. component->getProperties().remove ("mdiDocumentDelete_");
  49543. component->getProperties().remove ("mdiDocumentBkg_");
  49544. if (mode == FloatingWindows)
  49545. {
  49546. for (int i = getNumChildComponents(); --i >= 0;)
  49547. {
  49548. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49549. if (dw != 0 && dw->getContentComponent() == component)
  49550. {
  49551. dw->setContentComponent (0, false);
  49552. delete dw;
  49553. break;
  49554. }
  49555. }
  49556. if (shouldDelete)
  49557. delete component;
  49558. components.removeValue (component);
  49559. if (isFullscreenWhenOneDocument() && components.size() == 1)
  49560. {
  49561. for (int i = getNumChildComponents(); --i >= 0;)
  49562. {
  49563. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49564. if (dw != 0)
  49565. {
  49566. dw->setContentComponent (0, false);
  49567. delete dw;
  49568. }
  49569. }
  49570. addAndMakeVisible (components.getFirst());
  49571. }
  49572. }
  49573. else
  49574. {
  49575. jassert (components.indexOf (component) >= 0);
  49576. if (tabComponent != 0)
  49577. {
  49578. for (int i = tabComponent->getNumTabs(); --i >= 0;)
  49579. if (tabComponent->getTabContentComponent (i) == component)
  49580. tabComponent->removeTab (i);
  49581. }
  49582. else
  49583. {
  49584. removeChildComponent (component);
  49585. }
  49586. if (shouldDelete)
  49587. delete component;
  49588. if (tabComponent != 0 && tabComponent->getNumTabs() <= numDocsBeforeTabsUsed)
  49589. deleteAndZero (tabComponent);
  49590. components.removeValue (component);
  49591. if (components.size() > 0 && tabComponent == 0)
  49592. addAndMakeVisible (components.getFirst());
  49593. }
  49594. resized();
  49595. activeDocumentChanged();
  49596. }
  49597. else
  49598. {
  49599. jassertfalse
  49600. }
  49601. return true;
  49602. }
  49603. int MultiDocumentPanel::getNumDocuments() const throw()
  49604. {
  49605. return components.size();
  49606. }
  49607. Component* MultiDocumentPanel::getDocument (const int index) const throw()
  49608. {
  49609. return components [index];
  49610. }
  49611. Component* MultiDocumentPanel::getActiveDocument() const throw()
  49612. {
  49613. if (mode == FloatingWindows)
  49614. {
  49615. for (int i = getNumChildComponents(); --i >= 0;)
  49616. {
  49617. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49618. if (dw != 0 && dw->isActiveWindow())
  49619. return dw->getContentComponent();
  49620. }
  49621. }
  49622. return components.getLast();
  49623. }
  49624. void MultiDocumentPanel::setActiveDocument (Component* component)
  49625. {
  49626. if (mode == FloatingWindows)
  49627. {
  49628. component = getContainerComp (component);
  49629. if (component != 0)
  49630. component->toFront (true);
  49631. }
  49632. else if (tabComponent != 0)
  49633. {
  49634. jassert (components.indexOf (component) >= 0);
  49635. for (int i = tabComponent->getNumTabs(); --i >= 0;)
  49636. {
  49637. if (tabComponent->getTabContentComponent (i) == component)
  49638. {
  49639. tabComponent->setCurrentTabIndex (i);
  49640. break;
  49641. }
  49642. }
  49643. }
  49644. else
  49645. {
  49646. component->grabKeyboardFocus();
  49647. }
  49648. }
  49649. void MultiDocumentPanel::activeDocumentChanged()
  49650. {
  49651. }
  49652. void MultiDocumentPanel::setMaximumNumDocuments (const int newNumber)
  49653. {
  49654. maximumNumDocuments = newNumber;
  49655. }
  49656. void MultiDocumentPanel::useFullscreenWhenOneDocument (const bool shouldUseTabs)
  49657. {
  49658. numDocsBeforeTabsUsed = shouldUseTabs ? 1 : 0;
  49659. }
  49660. bool MultiDocumentPanel::isFullscreenWhenOneDocument() const throw()
  49661. {
  49662. return numDocsBeforeTabsUsed != 0;
  49663. }
  49664. void MultiDocumentPanel::setLayoutMode (const LayoutMode newLayoutMode)
  49665. {
  49666. if (mode != newLayoutMode)
  49667. {
  49668. mode = newLayoutMode;
  49669. if (mode == FloatingWindows)
  49670. {
  49671. deleteAndZero (tabComponent);
  49672. }
  49673. else
  49674. {
  49675. for (int i = getNumChildComponents(); --i >= 0;)
  49676. {
  49677. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49678. if (dw != 0)
  49679. {
  49680. dw->getContentComponent()->getProperties().set ("mdiDocumentPos_", dw->getWindowStateAsString());
  49681. dw->setContentComponent (0, false);
  49682. delete dw;
  49683. }
  49684. }
  49685. }
  49686. resized();
  49687. const Array <Component*> tempComps (components);
  49688. components.clear();
  49689. for (int i = 0; i < tempComps.size(); ++i)
  49690. {
  49691. Component* const c = tempComps.getUnchecked(i);
  49692. addDocument (c,
  49693. Colour ((int) c->getProperties().getWithDefault ("mdiDocumentBkg_", (int) Colours::white.getARGB())),
  49694. shouldDeleteComp (c));
  49695. }
  49696. }
  49697. }
  49698. void MultiDocumentPanel::setBackgroundColour (const Colour& newBackgroundColour)
  49699. {
  49700. if (backgroundColour != newBackgroundColour)
  49701. {
  49702. backgroundColour = newBackgroundColour;
  49703. setOpaque (newBackgroundColour.isOpaque());
  49704. repaint();
  49705. }
  49706. }
  49707. void MultiDocumentPanel::paint (Graphics& g)
  49708. {
  49709. g.fillAll (backgroundColour);
  49710. }
  49711. void MultiDocumentPanel::resized()
  49712. {
  49713. if (mode == MaximisedWindowsWithTabs || components.size() == numDocsBeforeTabsUsed)
  49714. {
  49715. for (int i = getNumChildComponents(); --i >= 0;)
  49716. getChildComponent (i)->setBounds (0, 0, getWidth(), getHeight());
  49717. }
  49718. setWantsKeyboardFocus (components.size() == 0);
  49719. }
  49720. Component* MultiDocumentPanel::getContainerComp (Component* c) const
  49721. {
  49722. if (mode == FloatingWindows)
  49723. {
  49724. for (int i = 0; i < getNumChildComponents(); ++i)
  49725. {
  49726. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49727. if (dw != 0 && dw->getContentComponent() == c)
  49728. {
  49729. c = dw;
  49730. break;
  49731. }
  49732. }
  49733. }
  49734. return c;
  49735. }
  49736. void MultiDocumentPanel::componentNameChanged (Component&)
  49737. {
  49738. if (mode == FloatingWindows)
  49739. {
  49740. for (int i = 0; i < getNumChildComponents(); ++i)
  49741. {
  49742. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49743. if (dw != 0)
  49744. dw->setName (dw->getContentComponent()->getName());
  49745. }
  49746. }
  49747. else if (tabComponent != 0)
  49748. {
  49749. for (int i = tabComponent->getNumTabs(); --i >= 0;)
  49750. tabComponent->setTabName (i, tabComponent->getTabContentComponent (i)->getName());
  49751. }
  49752. }
  49753. void MultiDocumentPanel::updateOrder()
  49754. {
  49755. const Array <Component*> oldList (components);
  49756. if (mode == FloatingWindows)
  49757. {
  49758. components.clear();
  49759. for (int i = 0; i < getNumChildComponents(); ++i)
  49760. {
  49761. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49762. if (dw != 0)
  49763. components.add (dw->getContentComponent());
  49764. }
  49765. }
  49766. else
  49767. {
  49768. if (tabComponent != 0)
  49769. {
  49770. Component* const current = tabComponent->getCurrentContentComponent();
  49771. if (current != 0)
  49772. {
  49773. components.removeValue (current);
  49774. components.add (current);
  49775. }
  49776. }
  49777. }
  49778. if (components != oldList)
  49779. activeDocumentChanged();
  49780. }
  49781. END_JUCE_NAMESPACE
  49782. /*** End of inlined file: juce_MultiDocumentPanel.cpp ***/
  49783. /*** Start of inlined file: juce_ResizableBorderComponent.cpp ***/
  49784. BEGIN_JUCE_NAMESPACE
  49785. const int zoneL = 1;
  49786. const int zoneR = 2;
  49787. const int zoneT = 4;
  49788. const int zoneB = 8;
  49789. ResizableBorderComponent::ResizableBorderComponent (Component* const componentToResize,
  49790. ComponentBoundsConstrainer* const constrainer_)
  49791. : component (componentToResize),
  49792. constrainer (constrainer_),
  49793. borderSize (5),
  49794. mouseZone (0)
  49795. {
  49796. }
  49797. ResizableBorderComponent::~ResizableBorderComponent()
  49798. {
  49799. }
  49800. void ResizableBorderComponent::paint (Graphics& g)
  49801. {
  49802. getLookAndFeel().drawResizableFrame (g, getWidth(), getHeight(), borderSize);
  49803. }
  49804. void ResizableBorderComponent::mouseEnter (const MouseEvent& e)
  49805. {
  49806. updateMouseZone (e);
  49807. }
  49808. void ResizableBorderComponent::mouseMove (const MouseEvent& e)
  49809. {
  49810. updateMouseZone (e);
  49811. }
  49812. void ResizableBorderComponent::mouseDown (const MouseEvent& e)
  49813. {
  49814. if (component->isValidComponent())
  49815. {
  49816. updateMouseZone (e);
  49817. originalX = component->getX();
  49818. originalY = component->getY();
  49819. originalW = component->getWidth();
  49820. originalH = component->getHeight();
  49821. if (constrainer != 0)
  49822. constrainer->resizeStart();
  49823. }
  49824. else
  49825. {
  49826. jassertfalse
  49827. }
  49828. }
  49829. void ResizableBorderComponent::mouseDrag (const MouseEvent& e)
  49830. {
  49831. if (! component->isValidComponent())
  49832. {
  49833. jassertfalse
  49834. return;
  49835. }
  49836. int x = originalX;
  49837. int y = originalY;
  49838. int w = originalW;
  49839. int h = originalH;
  49840. const int dx = e.getDistanceFromDragStartX();
  49841. const int dy = e.getDistanceFromDragStartY();
  49842. if ((mouseZone & zoneL) != 0)
  49843. {
  49844. x += dx;
  49845. w -= dx;
  49846. }
  49847. if ((mouseZone & zoneT) != 0)
  49848. {
  49849. y += dy;
  49850. h -= dy;
  49851. }
  49852. if ((mouseZone & zoneR) != 0)
  49853. w += dx;
  49854. if ((mouseZone & zoneB) != 0)
  49855. h += dy;
  49856. if (constrainer != 0)
  49857. constrainer->setBoundsForComponent (component,
  49858. Rectangle<int> (x, y, w, h),
  49859. (mouseZone & zoneT) != 0,
  49860. (mouseZone & zoneL) != 0,
  49861. (mouseZone & zoneB) != 0,
  49862. (mouseZone & zoneR) != 0);
  49863. else
  49864. component->setBounds (x, y, w, h);
  49865. }
  49866. void ResizableBorderComponent::mouseUp (const MouseEvent&)
  49867. {
  49868. if (constrainer != 0)
  49869. constrainer->resizeEnd();
  49870. }
  49871. bool ResizableBorderComponent::hitTest (int x, int y)
  49872. {
  49873. return x < borderSize.getLeft()
  49874. || x >= getWidth() - borderSize.getRight()
  49875. || y < borderSize.getTop()
  49876. || y >= getHeight() - borderSize.getBottom();
  49877. }
  49878. void ResizableBorderComponent::setBorderThickness (const BorderSize& newBorderSize) throw()
  49879. {
  49880. if (borderSize != newBorderSize)
  49881. {
  49882. borderSize = newBorderSize;
  49883. repaint();
  49884. }
  49885. }
  49886. const BorderSize ResizableBorderComponent::getBorderThickness() const throw()
  49887. {
  49888. return borderSize;
  49889. }
  49890. void ResizableBorderComponent::updateMouseZone (const MouseEvent& e) throw()
  49891. {
  49892. int newZone = 0;
  49893. if (ResizableBorderComponent::hitTest (e.x, e.y))
  49894. {
  49895. if (e.x < jmax (borderSize.getLeft(),
  49896. proportionOfWidth (0.1f),
  49897. jmin (10, proportionOfWidth (0.33f))))
  49898. newZone |= zoneL;
  49899. else if (e.x >= jmin (getWidth() - borderSize.getRight(),
  49900. proportionOfWidth (0.9f),
  49901. getWidth() - jmin (10, proportionOfWidth (0.33f))))
  49902. newZone |= zoneR;
  49903. if (e.y < jmax (borderSize.getTop(),
  49904. proportionOfHeight (0.1f),
  49905. jmin (10, proportionOfHeight (0.33f))))
  49906. newZone |= zoneT;
  49907. else if (e.y >= jmin (getHeight() - borderSize.getBottom(),
  49908. proportionOfHeight (0.9f),
  49909. getHeight() - jmin (10, proportionOfHeight (0.33f))))
  49910. newZone |= zoneB;
  49911. }
  49912. if (mouseZone != newZone)
  49913. {
  49914. mouseZone = newZone;
  49915. MouseCursor::StandardCursorType mc = MouseCursor::NormalCursor;
  49916. switch (newZone)
  49917. {
  49918. case (zoneL | zoneT):
  49919. mc = MouseCursor::TopLeftCornerResizeCursor;
  49920. break;
  49921. case zoneT:
  49922. mc = MouseCursor::TopEdgeResizeCursor;
  49923. break;
  49924. case (zoneR | zoneT):
  49925. mc = MouseCursor::TopRightCornerResizeCursor;
  49926. break;
  49927. case zoneL:
  49928. mc = MouseCursor::LeftEdgeResizeCursor;
  49929. break;
  49930. case zoneR:
  49931. mc = MouseCursor::RightEdgeResizeCursor;
  49932. break;
  49933. case (zoneL | zoneB):
  49934. mc = MouseCursor::BottomLeftCornerResizeCursor;
  49935. break;
  49936. case zoneB:
  49937. mc = MouseCursor::BottomEdgeResizeCursor;
  49938. break;
  49939. case (zoneR | zoneB):
  49940. mc = MouseCursor::BottomRightCornerResizeCursor;
  49941. break;
  49942. default:
  49943. break;
  49944. }
  49945. setMouseCursor (mc);
  49946. }
  49947. }
  49948. END_JUCE_NAMESPACE
  49949. /*** End of inlined file: juce_ResizableBorderComponent.cpp ***/
  49950. /*** Start of inlined file: juce_ResizableCornerComponent.cpp ***/
  49951. BEGIN_JUCE_NAMESPACE
  49952. ResizableCornerComponent::ResizableCornerComponent (Component* const componentToResize,
  49953. ComponentBoundsConstrainer* const constrainer_)
  49954. : component (componentToResize),
  49955. constrainer (constrainer_)
  49956. {
  49957. setRepaintsOnMouseActivity (true);
  49958. setMouseCursor (MouseCursor::BottomRightCornerResizeCursor);
  49959. }
  49960. ResizableCornerComponent::~ResizableCornerComponent()
  49961. {
  49962. }
  49963. void ResizableCornerComponent::paint (Graphics& g)
  49964. {
  49965. getLookAndFeel()
  49966. .drawCornerResizer (g, getWidth(), getHeight(),
  49967. isMouseOverOrDragging(),
  49968. isMouseButtonDown());
  49969. }
  49970. void ResizableCornerComponent::mouseDown (const MouseEvent&)
  49971. {
  49972. if (component->isValidComponent())
  49973. {
  49974. originalX = component->getX();
  49975. originalY = component->getY();
  49976. originalW = component->getWidth();
  49977. originalH = component->getHeight();
  49978. if (constrainer != 0)
  49979. constrainer->resizeStart();
  49980. }
  49981. else
  49982. {
  49983. jassertfalse
  49984. }
  49985. }
  49986. void ResizableCornerComponent::mouseDrag (const MouseEvent& e)
  49987. {
  49988. if (! component->isValidComponent())
  49989. {
  49990. jassertfalse
  49991. return;
  49992. }
  49993. int x = originalX;
  49994. int y = originalY;
  49995. int w = originalW + e.getDistanceFromDragStartX();
  49996. int h = originalH + e.getDistanceFromDragStartY();
  49997. if (constrainer != 0)
  49998. constrainer->setBoundsForComponent (component, Rectangle<int> (x, y, w, h),
  49999. false, false, true, true);
  50000. else
  50001. component->setBounds (x, y, w, h);
  50002. }
  50003. void ResizableCornerComponent::mouseUp (const MouseEvent&)
  50004. {
  50005. if (constrainer != 0)
  50006. constrainer->resizeStart();
  50007. }
  50008. bool ResizableCornerComponent::hitTest (int x, int y)
  50009. {
  50010. if (getWidth() <= 0)
  50011. return false;
  50012. const int yAtX = getHeight() - (getHeight() * x / getWidth());
  50013. return y >= yAtX - getHeight() / 4;
  50014. }
  50015. END_JUCE_NAMESPACE
  50016. /*** End of inlined file: juce_ResizableCornerComponent.cpp ***/
  50017. /*** Start of inlined file: juce_ScrollBar.cpp ***/
  50018. BEGIN_JUCE_NAMESPACE
  50019. class ScrollbarButton : public Button
  50020. {
  50021. public:
  50022. int direction;
  50023. ScrollbarButton (const int direction_,
  50024. ScrollBar& owner_) throw()
  50025. : Button (String::empty),
  50026. direction (direction_),
  50027. owner (owner_)
  50028. {
  50029. setWantsKeyboardFocus (false);
  50030. }
  50031. ~ScrollbarButton()
  50032. {
  50033. }
  50034. void paintButton (Graphics& g,
  50035. bool isMouseOver,
  50036. bool isMouseDown)
  50037. {
  50038. getLookAndFeel()
  50039. .drawScrollbarButton (g, owner,
  50040. getWidth(), getHeight(),
  50041. direction,
  50042. owner.isVertical(),
  50043. isMouseOver, isMouseDown);
  50044. }
  50045. void clicked()
  50046. {
  50047. owner.moveScrollbarInSteps ((direction == 1 || direction == 2) ? 1 : -1);
  50048. }
  50049. juce_UseDebuggingNewOperator
  50050. private:
  50051. ScrollBar& owner;
  50052. ScrollbarButton (const ScrollbarButton&);
  50053. const ScrollbarButton& operator= (const ScrollbarButton&);
  50054. };
  50055. ScrollBar::ScrollBar (const bool vertical_,
  50056. const bool buttonsAreVisible)
  50057. : minimum (0.0),
  50058. maximum (1.0),
  50059. rangeStart (0.0),
  50060. rangeSize (0.1),
  50061. singleStepSize (0.1),
  50062. thumbAreaStart (0),
  50063. thumbAreaSize (0),
  50064. thumbStart (0),
  50065. thumbSize (0),
  50066. initialDelayInMillisecs (100),
  50067. repeatDelayInMillisecs (50),
  50068. minimumDelayInMillisecs (10),
  50069. vertical (vertical_),
  50070. isDraggingThumb (false),
  50071. alwaysVisible (false),
  50072. upButton (0),
  50073. downButton (0)
  50074. {
  50075. setButtonVisibility (buttonsAreVisible);
  50076. setRepaintsOnMouseActivity (true);
  50077. setFocusContainer (true);
  50078. }
  50079. ScrollBar::~ScrollBar()
  50080. {
  50081. deleteAllChildren();
  50082. }
  50083. void ScrollBar::setRangeLimits (const double newMinimum,
  50084. const double newMaximum) throw()
  50085. {
  50086. minimum = newMinimum;
  50087. maximum = newMaximum;
  50088. jassert (maximum >= minimum); // these can't be the wrong way round!
  50089. setCurrentRangeStart (rangeStart);
  50090. updateThumbPosition();
  50091. }
  50092. void ScrollBar::setCurrentRange (double newStart,
  50093. double newSize) throw()
  50094. {
  50095. newSize = jlimit (0.0, maximum - minimum, newSize);
  50096. newStart = jlimit (minimum, maximum - newSize, newStart);
  50097. if (rangeStart != newStart
  50098. || rangeSize != newSize)
  50099. {
  50100. rangeStart = newStart;
  50101. rangeSize = newSize;
  50102. updateThumbPosition();
  50103. triggerAsyncUpdate();
  50104. }
  50105. }
  50106. void ScrollBar::setCurrentRangeStart (double newStart) throw()
  50107. {
  50108. setCurrentRange (newStart, rangeSize);
  50109. }
  50110. void ScrollBar::setSingleStepSize (const double newSingleStepSize) throw()
  50111. {
  50112. singleStepSize = newSingleStepSize;
  50113. }
  50114. void ScrollBar::moveScrollbarInSteps (const int howManySteps) throw()
  50115. {
  50116. setCurrentRangeStart (rangeStart + howManySteps * singleStepSize);
  50117. }
  50118. void ScrollBar::moveScrollbarInPages (const int howManyPages) throw()
  50119. {
  50120. setCurrentRangeStart (rangeStart + howManyPages * rangeSize);
  50121. }
  50122. void ScrollBar::scrollToTop() throw()
  50123. {
  50124. setCurrentRangeStart (minimum);
  50125. }
  50126. void ScrollBar::scrollToBottom() throw()
  50127. {
  50128. setCurrentRangeStart (maximum - rangeSize);
  50129. }
  50130. void ScrollBar::setButtonRepeatSpeed (const int initialDelayInMillisecs_,
  50131. const int repeatDelayInMillisecs_,
  50132. const int minimumDelayInMillisecs_) throw()
  50133. {
  50134. initialDelayInMillisecs = initialDelayInMillisecs_;
  50135. repeatDelayInMillisecs = repeatDelayInMillisecs_;
  50136. minimumDelayInMillisecs = minimumDelayInMillisecs_;
  50137. if (upButton != 0)
  50138. {
  50139. upButton->setRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
  50140. downButton->setRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
  50141. }
  50142. }
  50143. void ScrollBar::addListener (ScrollBarListener* const listener) throw()
  50144. {
  50145. jassert (listener != 0);
  50146. if (listener != 0)
  50147. listeners.add (listener);
  50148. }
  50149. void ScrollBar::removeListener (ScrollBarListener* const listener) throw()
  50150. {
  50151. listeners.removeValue (listener);
  50152. }
  50153. void ScrollBar::handleAsyncUpdate()
  50154. {
  50155. const double value = getCurrentRangeStart();
  50156. for (int i = listeners.size(); --i >= 0;)
  50157. {
  50158. ((ScrollBarListener*) listeners.getUnchecked (i))->scrollBarMoved (this, value);
  50159. i = jmin (i, listeners.size());
  50160. }
  50161. }
  50162. void ScrollBar::updateThumbPosition() throw()
  50163. {
  50164. int newThumbSize = roundToInt ((maximum > minimum) ? (rangeSize * thumbAreaSize) / (maximum - minimum)
  50165. : thumbAreaSize);
  50166. if (newThumbSize < getLookAndFeel().getMinimumScrollbarThumbSize (*this))
  50167. newThumbSize = jmin (getLookAndFeel().getMinimumScrollbarThumbSize (*this), thumbAreaSize - 1);
  50168. if (newThumbSize > thumbAreaSize)
  50169. newThumbSize = thumbAreaSize;
  50170. int newThumbStart = thumbAreaStart;
  50171. if (maximum - minimum > rangeSize)
  50172. newThumbStart += roundToInt (((rangeStart - minimum) * (thumbAreaSize - newThumbSize))
  50173. / ((maximum - minimum) - rangeSize));
  50174. setVisible (alwaysVisible || (maximum - minimum > rangeSize && rangeSize > 0.0));
  50175. if (thumbStart != newThumbStart || thumbSize != newThumbSize)
  50176. {
  50177. const int repaintStart = jmin (thumbStart, newThumbStart) - 4;
  50178. const int repaintSize = jmax (thumbStart + thumbSize, newThumbStart + newThumbSize) + 8 - repaintStart;
  50179. if (vertical)
  50180. repaint (0, repaintStart, getWidth(), repaintSize);
  50181. else
  50182. repaint (repaintStart, 0, repaintSize, getHeight());
  50183. thumbStart = newThumbStart;
  50184. thumbSize = newThumbSize;
  50185. }
  50186. }
  50187. void ScrollBar::setOrientation (const bool shouldBeVertical) throw()
  50188. {
  50189. if (vertical != shouldBeVertical)
  50190. {
  50191. vertical = shouldBeVertical;
  50192. if (upButton != 0)
  50193. {
  50194. ((ScrollbarButton*) upButton)->direction = (vertical) ? 0 : 3;
  50195. ((ScrollbarButton*) downButton)->direction = (vertical) ? 2 : 1;
  50196. }
  50197. updateThumbPosition();
  50198. }
  50199. }
  50200. void ScrollBar::setButtonVisibility (const bool buttonsAreVisible)
  50201. {
  50202. deleteAndZero (upButton);
  50203. deleteAndZero (downButton);
  50204. if (buttonsAreVisible)
  50205. {
  50206. addAndMakeVisible (upButton = new ScrollbarButton ((vertical) ? 0 : 3, *this));
  50207. addAndMakeVisible (downButton = new ScrollbarButton ((vertical) ? 2 : 1, *this));
  50208. setButtonRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
  50209. }
  50210. updateThumbPosition();
  50211. }
  50212. void ScrollBar::setAutoHide (const bool shouldHideWhenFullRange)
  50213. {
  50214. alwaysVisible = ! shouldHideWhenFullRange;
  50215. updateThumbPosition();
  50216. }
  50217. void ScrollBar::paint (Graphics& g)
  50218. {
  50219. if (thumbAreaSize > 0)
  50220. {
  50221. LookAndFeel& lf = getLookAndFeel();
  50222. const int thumb = (thumbAreaSize > lf.getMinimumScrollbarThumbSize (*this))
  50223. ? thumbSize : 0;
  50224. if (vertical)
  50225. {
  50226. lf.drawScrollbar (g, *this,
  50227. 0, thumbAreaStart,
  50228. getWidth(), thumbAreaSize,
  50229. vertical,
  50230. thumbStart, thumb,
  50231. isMouseOver(), isMouseButtonDown());
  50232. }
  50233. else
  50234. {
  50235. lf.drawScrollbar (g, *this,
  50236. thumbAreaStart, 0,
  50237. thumbAreaSize, getHeight(),
  50238. vertical,
  50239. thumbStart, thumb,
  50240. isMouseOver(), isMouseButtonDown());
  50241. }
  50242. }
  50243. }
  50244. void ScrollBar::lookAndFeelChanged()
  50245. {
  50246. setComponentEffect (getLookAndFeel().getScrollbarEffect());
  50247. }
  50248. void ScrollBar::resized()
  50249. {
  50250. const int length = ((vertical) ? getHeight() : getWidth());
  50251. const int buttonSize = (upButton != 0) ? jmin (getLookAndFeel().getScrollbarButtonSize (*this), (length >> 1))
  50252. : 0;
  50253. if (length < 32 + getLookAndFeel().getMinimumScrollbarThumbSize (*this))
  50254. {
  50255. thumbAreaStart = length >> 1;
  50256. thumbAreaSize = 0;
  50257. }
  50258. else
  50259. {
  50260. thumbAreaStart = buttonSize;
  50261. thumbAreaSize = length - (buttonSize << 1);
  50262. }
  50263. if (upButton != 0)
  50264. {
  50265. if (vertical)
  50266. {
  50267. upButton->setBounds (0, 0, getWidth(), buttonSize);
  50268. downButton->setBounds (0, thumbAreaStart + thumbAreaSize, getWidth(), buttonSize);
  50269. }
  50270. else
  50271. {
  50272. upButton->setBounds (0, 0, buttonSize, getHeight());
  50273. downButton->setBounds (thumbAreaStart + thumbAreaSize, 0, buttonSize, getHeight());
  50274. }
  50275. }
  50276. updateThumbPosition();
  50277. }
  50278. void ScrollBar::mouseDown (const MouseEvent& e)
  50279. {
  50280. isDraggingThumb = false;
  50281. lastMousePos = vertical ? e.y : e.x;
  50282. dragStartMousePos = lastMousePos;
  50283. dragStartRange = rangeStart;
  50284. if (dragStartMousePos < thumbStart)
  50285. {
  50286. moveScrollbarInPages (-1);
  50287. startTimer (400);
  50288. }
  50289. else if (dragStartMousePos >= thumbStart + thumbSize)
  50290. {
  50291. moveScrollbarInPages (1);
  50292. startTimer (400);
  50293. }
  50294. else
  50295. {
  50296. isDraggingThumb = (thumbAreaSize > getLookAndFeel().getMinimumScrollbarThumbSize (*this))
  50297. && (thumbAreaSize > thumbSize);
  50298. }
  50299. }
  50300. void ScrollBar::mouseDrag (const MouseEvent& e)
  50301. {
  50302. if (isDraggingThumb)
  50303. {
  50304. const int deltaPixels = ((vertical) ? e.y : e.x) - dragStartMousePos;
  50305. setCurrentRangeStart (dragStartRange
  50306. + deltaPixels * ((maximum - minimum) - rangeSize)
  50307. / (thumbAreaSize - thumbSize));
  50308. }
  50309. else
  50310. {
  50311. lastMousePos = (vertical) ? e.y : e.x;
  50312. }
  50313. }
  50314. void ScrollBar::mouseUp (const MouseEvent&)
  50315. {
  50316. isDraggingThumb = false;
  50317. stopTimer();
  50318. repaint();
  50319. }
  50320. void ScrollBar::mouseWheelMove (const MouseEvent&,
  50321. float wheelIncrementX,
  50322. float wheelIncrementY)
  50323. {
  50324. float increment = vertical ? wheelIncrementY : wheelIncrementX;
  50325. if (increment < 0)
  50326. increment = jmin (increment * 10.0f, -1.0f);
  50327. else if (increment > 0)
  50328. increment = jmax (increment * 10.0f, 1.0f);
  50329. setCurrentRangeStart (rangeStart - singleStepSize * increment);
  50330. }
  50331. void ScrollBar::timerCallback()
  50332. {
  50333. if (isMouseButtonDown())
  50334. {
  50335. startTimer (40);
  50336. if (lastMousePos < thumbStart)
  50337. setCurrentRangeStart (rangeStart - rangeSize);
  50338. else if (lastMousePos > thumbStart + thumbSize)
  50339. setCurrentRangeStart (rangeStart + rangeSize);
  50340. }
  50341. else
  50342. {
  50343. stopTimer();
  50344. }
  50345. }
  50346. bool ScrollBar::keyPressed (const KeyPress& key)
  50347. {
  50348. if (! isVisible())
  50349. return false;
  50350. if (key.isKeyCode (KeyPress::upKey) || key.isKeyCode (KeyPress::leftKey))
  50351. moveScrollbarInSteps (-1);
  50352. else if (key.isKeyCode (KeyPress::downKey) || key.isKeyCode (KeyPress::rightKey))
  50353. moveScrollbarInSteps (1);
  50354. else if (key.isKeyCode (KeyPress::pageUpKey))
  50355. moveScrollbarInPages (-1);
  50356. else if (key.isKeyCode (KeyPress::pageDownKey))
  50357. moveScrollbarInPages (1);
  50358. else if (key.isKeyCode (KeyPress::homeKey))
  50359. scrollToTop();
  50360. else if (key.isKeyCode (KeyPress::endKey))
  50361. scrollToBottom();
  50362. else
  50363. return false;
  50364. return true;
  50365. }
  50366. END_JUCE_NAMESPACE
  50367. /*** End of inlined file: juce_ScrollBar.cpp ***/
  50368. /*** Start of inlined file: juce_StretchableLayoutManager.cpp ***/
  50369. BEGIN_JUCE_NAMESPACE
  50370. StretchableLayoutManager::StretchableLayoutManager()
  50371. : totalSize (0)
  50372. {
  50373. }
  50374. StretchableLayoutManager::~StretchableLayoutManager()
  50375. {
  50376. }
  50377. void StretchableLayoutManager::clearAllItems()
  50378. {
  50379. items.clear();
  50380. totalSize = 0;
  50381. }
  50382. void StretchableLayoutManager::setItemLayout (const int itemIndex,
  50383. const double minimumSize,
  50384. const double maximumSize,
  50385. const double preferredSize)
  50386. {
  50387. ItemLayoutProperties* layout = getInfoFor (itemIndex);
  50388. if (layout == 0)
  50389. {
  50390. layout = new ItemLayoutProperties();
  50391. layout->itemIndex = itemIndex;
  50392. int i;
  50393. for (i = 0; i < items.size(); ++i)
  50394. if (items.getUnchecked (i)->itemIndex > itemIndex)
  50395. break;
  50396. items.insert (i, layout);
  50397. }
  50398. layout->minSize = minimumSize;
  50399. layout->maxSize = maximumSize;
  50400. layout->preferredSize = preferredSize;
  50401. layout->currentSize = 0;
  50402. }
  50403. bool StretchableLayoutManager::getItemLayout (const int itemIndex,
  50404. double& minimumSize,
  50405. double& maximumSize,
  50406. double& preferredSize) const
  50407. {
  50408. const ItemLayoutProperties* const layout = getInfoFor (itemIndex);
  50409. if (layout != 0)
  50410. {
  50411. minimumSize = layout->minSize;
  50412. maximumSize = layout->maxSize;
  50413. preferredSize = layout->preferredSize;
  50414. return true;
  50415. }
  50416. return false;
  50417. }
  50418. void StretchableLayoutManager::setTotalSize (const int newTotalSize)
  50419. {
  50420. totalSize = newTotalSize;
  50421. fitComponentsIntoSpace (0, items.size(), totalSize, 0);
  50422. }
  50423. int StretchableLayoutManager::getItemCurrentPosition (const int itemIndex) const
  50424. {
  50425. int pos = 0;
  50426. for (int i = 0; i < itemIndex; ++i)
  50427. {
  50428. const ItemLayoutProperties* const layout = getInfoFor (i);
  50429. if (layout != 0)
  50430. pos += layout->currentSize;
  50431. }
  50432. return pos;
  50433. }
  50434. int StretchableLayoutManager::getItemCurrentAbsoluteSize (const int itemIndex) const
  50435. {
  50436. const ItemLayoutProperties* const layout = getInfoFor (itemIndex);
  50437. if (layout != 0)
  50438. return layout->currentSize;
  50439. return 0;
  50440. }
  50441. double StretchableLayoutManager::getItemCurrentRelativeSize (const int itemIndex) const
  50442. {
  50443. const ItemLayoutProperties* const layout = getInfoFor (itemIndex);
  50444. if (layout != 0)
  50445. return -layout->currentSize / (double) totalSize;
  50446. return 0;
  50447. }
  50448. void StretchableLayoutManager::setItemPosition (const int itemIndex,
  50449. int newPosition)
  50450. {
  50451. for (int i = items.size(); --i >= 0;)
  50452. {
  50453. const ItemLayoutProperties* const layout = items.getUnchecked(i);
  50454. if (layout->itemIndex == itemIndex)
  50455. {
  50456. int realTotalSize = jmax (totalSize, getMinimumSizeOfItems (0, items.size()));
  50457. const int minSizeAfterThisComp = getMinimumSizeOfItems (i, items.size());
  50458. const int maxSizeAfterThisComp = getMaximumSizeOfItems (i + 1, items.size());
  50459. newPosition = jmax (newPosition, totalSize - maxSizeAfterThisComp - layout->currentSize);
  50460. newPosition = jmin (newPosition, realTotalSize - minSizeAfterThisComp);
  50461. int endPos = fitComponentsIntoSpace (0, i, newPosition, 0);
  50462. endPos += layout->currentSize;
  50463. fitComponentsIntoSpace (i + 1, items.size(), totalSize - endPos, endPos);
  50464. updatePrefSizesToMatchCurrentPositions();
  50465. break;
  50466. }
  50467. }
  50468. }
  50469. void StretchableLayoutManager::layOutComponents (Component** const components,
  50470. int numComponents,
  50471. int x, int y, int w, int h,
  50472. const bool vertically,
  50473. const bool resizeOtherDimension)
  50474. {
  50475. setTotalSize (vertically ? h : w);
  50476. int pos = vertically ? y : x;
  50477. for (int i = 0; i < numComponents; ++i)
  50478. {
  50479. const ItemLayoutProperties* const layout = getInfoFor (i);
  50480. if (layout != 0)
  50481. {
  50482. Component* const c = components[i];
  50483. if (c != 0)
  50484. {
  50485. if (i == numComponents - 1)
  50486. {
  50487. // if it's the last item, crop it to exactly fit the available space..
  50488. if (resizeOtherDimension)
  50489. {
  50490. if (vertically)
  50491. c->setBounds (x, pos, w, jmax (layout->currentSize, h - pos));
  50492. else
  50493. c->setBounds (pos, y, jmax (layout->currentSize, w - pos), h);
  50494. }
  50495. else
  50496. {
  50497. if (vertically)
  50498. c->setBounds (c->getX(), pos, c->getWidth(), jmax (layout->currentSize, h - pos));
  50499. else
  50500. c->setBounds (pos, c->getY(), jmax (layout->currentSize, w - pos), c->getHeight());
  50501. }
  50502. }
  50503. else
  50504. {
  50505. if (resizeOtherDimension)
  50506. {
  50507. if (vertically)
  50508. c->setBounds (x, pos, w, layout->currentSize);
  50509. else
  50510. c->setBounds (pos, y, layout->currentSize, h);
  50511. }
  50512. else
  50513. {
  50514. if (vertically)
  50515. c->setBounds (c->getX(), pos, c->getWidth(), layout->currentSize);
  50516. else
  50517. c->setBounds (pos, c->getY(), layout->currentSize, c->getHeight());
  50518. }
  50519. }
  50520. }
  50521. pos += layout->currentSize;
  50522. }
  50523. }
  50524. }
  50525. StretchableLayoutManager::ItemLayoutProperties* StretchableLayoutManager::getInfoFor (const int itemIndex) const
  50526. {
  50527. for (int i = items.size(); --i >= 0;)
  50528. if (items.getUnchecked(i)->itemIndex == itemIndex)
  50529. return items.getUnchecked(i);
  50530. return 0;
  50531. }
  50532. int StretchableLayoutManager::fitComponentsIntoSpace (const int startIndex,
  50533. const int endIndex,
  50534. const int availableSpace,
  50535. int startPos)
  50536. {
  50537. // calculate the total sizes
  50538. int i;
  50539. double totalIdealSize = 0.0;
  50540. int totalMinimums = 0;
  50541. for (i = startIndex; i < endIndex; ++i)
  50542. {
  50543. ItemLayoutProperties* const layout = items.getUnchecked (i);
  50544. layout->currentSize = sizeToRealSize (layout->minSize, totalSize);
  50545. totalMinimums += layout->currentSize;
  50546. totalIdealSize += sizeToRealSize (layout->preferredSize, availableSpace);
  50547. }
  50548. if (totalIdealSize <= 0)
  50549. totalIdealSize = 1.0;
  50550. // now calc the best sizes..
  50551. int extraSpace = availableSpace - totalMinimums;
  50552. while (extraSpace > 0)
  50553. {
  50554. int numWantingMoreSpace = 0;
  50555. int numHavingTakenExtraSpace = 0;
  50556. // first figure out how many comps want a slice of the extra space..
  50557. for (i = startIndex; i < endIndex; ++i)
  50558. {
  50559. ItemLayoutProperties* const layout = items.getUnchecked (i);
  50560. double sizeWanted = sizeToRealSize (layout->preferredSize, availableSpace);
  50561. const int bestSize = jlimit (layout->currentSize,
  50562. jmax (layout->currentSize,
  50563. sizeToRealSize (layout->maxSize, totalSize)),
  50564. roundToInt (sizeWanted * availableSpace / totalIdealSize));
  50565. if (bestSize > layout->currentSize)
  50566. ++numWantingMoreSpace;
  50567. }
  50568. // ..share out the extra space..
  50569. for (i = startIndex; i < endIndex; ++i)
  50570. {
  50571. ItemLayoutProperties* const layout = items.getUnchecked (i);
  50572. double sizeWanted = sizeToRealSize (layout->preferredSize, availableSpace);
  50573. int bestSize = jlimit (layout->currentSize,
  50574. jmax (layout->currentSize, sizeToRealSize (layout->maxSize, totalSize)),
  50575. roundToInt (sizeWanted * availableSpace / totalIdealSize));
  50576. const int extraWanted = bestSize - layout->currentSize;
  50577. if (extraWanted > 0)
  50578. {
  50579. const int extraAllowed = jmin (extraWanted,
  50580. extraSpace / jmax (1, numWantingMoreSpace));
  50581. if (extraAllowed > 0)
  50582. {
  50583. ++numHavingTakenExtraSpace;
  50584. --numWantingMoreSpace;
  50585. layout->currentSize += extraAllowed;
  50586. extraSpace -= extraAllowed;
  50587. }
  50588. }
  50589. }
  50590. if (numHavingTakenExtraSpace <= 0)
  50591. break;
  50592. }
  50593. // ..and calculate the end position
  50594. for (i = startIndex; i < endIndex; ++i)
  50595. {
  50596. ItemLayoutProperties* const layout = items.getUnchecked(i);
  50597. startPos += layout->currentSize;
  50598. }
  50599. return startPos;
  50600. }
  50601. int StretchableLayoutManager::getMinimumSizeOfItems (const int startIndex,
  50602. const int endIndex) const
  50603. {
  50604. int totalMinimums = 0;
  50605. for (int i = startIndex; i < endIndex; ++i)
  50606. totalMinimums += sizeToRealSize (items.getUnchecked (i)->minSize, totalSize);
  50607. return totalMinimums;
  50608. }
  50609. int StretchableLayoutManager::getMaximumSizeOfItems (const int startIndex, const int endIndex) const
  50610. {
  50611. int totalMaximums = 0;
  50612. for (int i = startIndex; i < endIndex; ++i)
  50613. totalMaximums += sizeToRealSize (items.getUnchecked (i)->maxSize, totalSize);
  50614. return totalMaximums;
  50615. }
  50616. void StretchableLayoutManager::updatePrefSizesToMatchCurrentPositions()
  50617. {
  50618. for (int i = 0; i < items.size(); ++i)
  50619. {
  50620. ItemLayoutProperties* const layout = items.getUnchecked (i);
  50621. layout->preferredSize
  50622. = (layout->preferredSize < 0) ? getItemCurrentRelativeSize (i)
  50623. : getItemCurrentAbsoluteSize (i);
  50624. }
  50625. }
  50626. int StretchableLayoutManager::sizeToRealSize (double size, int totalSpace)
  50627. {
  50628. if (size < 0)
  50629. size *= -totalSpace;
  50630. return roundToInt (size);
  50631. }
  50632. END_JUCE_NAMESPACE
  50633. /*** End of inlined file: juce_StretchableLayoutManager.cpp ***/
  50634. /*** Start of inlined file: juce_StretchableLayoutResizerBar.cpp ***/
  50635. BEGIN_JUCE_NAMESPACE
  50636. StretchableLayoutResizerBar::StretchableLayoutResizerBar (StretchableLayoutManager* layout_,
  50637. const int itemIndex_,
  50638. const bool isVertical_)
  50639. : layout (layout_),
  50640. itemIndex (itemIndex_),
  50641. isVertical (isVertical_)
  50642. {
  50643. setRepaintsOnMouseActivity (true);
  50644. setMouseCursor (MouseCursor (isVertical_ ? MouseCursor::LeftRightResizeCursor
  50645. : MouseCursor::UpDownResizeCursor));
  50646. }
  50647. StretchableLayoutResizerBar::~StretchableLayoutResizerBar()
  50648. {
  50649. }
  50650. void StretchableLayoutResizerBar::paint (Graphics& g)
  50651. {
  50652. getLookAndFeel().drawStretchableLayoutResizerBar (g,
  50653. getWidth(), getHeight(),
  50654. isVertical,
  50655. isMouseOver(),
  50656. isMouseButtonDown());
  50657. }
  50658. void StretchableLayoutResizerBar::mouseDown (const MouseEvent&)
  50659. {
  50660. mouseDownPos = layout->getItemCurrentPosition (itemIndex);
  50661. }
  50662. void StretchableLayoutResizerBar::mouseDrag (const MouseEvent& e)
  50663. {
  50664. const int desiredPos = mouseDownPos + (isVertical ? e.getDistanceFromDragStartX()
  50665. : e.getDistanceFromDragStartY());
  50666. layout->setItemPosition (itemIndex, desiredPos);
  50667. hasBeenMoved();
  50668. }
  50669. void StretchableLayoutResizerBar::hasBeenMoved()
  50670. {
  50671. if (getParentComponent() != 0)
  50672. getParentComponent()->resized();
  50673. }
  50674. END_JUCE_NAMESPACE
  50675. /*** End of inlined file: juce_StretchableLayoutResizerBar.cpp ***/
  50676. /*** Start of inlined file: juce_StretchableObjectResizer.cpp ***/
  50677. BEGIN_JUCE_NAMESPACE
  50678. StretchableObjectResizer::StretchableObjectResizer()
  50679. {
  50680. }
  50681. StretchableObjectResizer::~StretchableObjectResizer()
  50682. {
  50683. }
  50684. void StretchableObjectResizer::addItem (const double size,
  50685. const double minSize, const double maxSize,
  50686. const int order)
  50687. {
  50688. // the order must be >= 0 but less than the maximum integer value.
  50689. jassert (order >= 0 && order < std::numeric_limits<int>::max());
  50690. Item* const item = new Item();
  50691. item->size = size;
  50692. item->minSize = minSize;
  50693. item->maxSize = maxSize;
  50694. item->order = order;
  50695. items.add (item);
  50696. }
  50697. double StretchableObjectResizer::getItemSize (const int index) const throw()
  50698. {
  50699. const Item* const it = items [index];
  50700. return it != 0 ? it->size : 0;
  50701. }
  50702. void StretchableObjectResizer::resizeToFit (const double targetSize)
  50703. {
  50704. int order = 0;
  50705. for (;;)
  50706. {
  50707. double currentSize = 0;
  50708. double minSize = 0;
  50709. double maxSize = 0;
  50710. int nextHighestOrder = std::numeric_limits<int>::max();
  50711. for (int i = 0; i < items.size(); ++i)
  50712. {
  50713. const Item* const it = items.getUnchecked(i);
  50714. currentSize += it->size;
  50715. if (it->order <= order)
  50716. {
  50717. minSize += it->minSize;
  50718. maxSize += it->maxSize;
  50719. }
  50720. else
  50721. {
  50722. minSize += it->size;
  50723. maxSize += it->size;
  50724. nextHighestOrder = jmin (nextHighestOrder, it->order);
  50725. }
  50726. }
  50727. const double thisIterationTarget = jlimit (minSize, maxSize, targetSize);
  50728. if (thisIterationTarget >= currentSize)
  50729. {
  50730. const double availableExtraSpace = maxSize - currentSize;
  50731. const double targetAmountOfExtraSpace = thisIterationTarget - currentSize;
  50732. const double scale = targetAmountOfExtraSpace / availableExtraSpace;
  50733. for (int i = 0; i < items.size(); ++i)
  50734. {
  50735. Item* const it = items.getUnchecked(i);
  50736. if (it->order <= order)
  50737. it->size = jmin (it->maxSize, it->size + (it->maxSize - it->size) * scale);
  50738. }
  50739. }
  50740. else
  50741. {
  50742. const double amountOfSlack = currentSize - minSize;
  50743. const double targetAmountOfSlack = thisIterationTarget - minSize;
  50744. const double scale = targetAmountOfSlack / amountOfSlack;
  50745. for (int i = 0; i < items.size(); ++i)
  50746. {
  50747. Item* const it = items.getUnchecked(i);
  50748. if (it->order <= order)
  50749. it->size = jmax (it->minSize, it->minSize + (it->size - it->minSize) * scale);
  50750. }
  50751. }
  50752. if (nextHighestOrder < std::numeric_limits<int>::max())
  50753. order = nextHighestOrder;
  50754. else
  50755. break;
  50756. }
  50757. }
  50758. END_JUCE_NAMESPACE
  50759. /*** End of inlined file: juce_StretchableObjectResizer.cpp ***/
  50760. /*** Start of inlined file: juce_TabbedButtonBar.cpp ***/
  50761. BEGIN_JUCE_NAMESPACE
  50762. TabBarButton::TabBarButton (const String& name,
  50763. TabbedButtonBar* const owner_,
  50764. const int index)
  50765. : Button (name),
  50766. owner (owner_),
  50767. tabIndex (index),
  50768. overlapPixels (0)
  50769. {
  50770. shadow.setShadowProperties (2.2f, 0.7f, 0, 0);
  50771. setComponentEffect (&shadow);
  50772. setWantsKeyboardFocus (false);
  50773. }
  50774. TabBarButton::~TabBarButton()
  50775. {
  50776. }
  50777. void TabBarButton::paintButton (Graphics& g,
  50778. bool isMouseOverButton,
  50779. bool isButtonDown)
  50780. {
  50781. int x, y, w, h;
  50782. getActiveArea (x, y, w, h);
  50783. g.setOrigin (x, y);
  50784. getLookAndFeel()
  50785. .drawTabButton (g, w, h,
  50786. owner->getTabBackgroundColour (tabIndex),
  50787. tabIndex, getButtonText(), *this,
  50788. owner->getOrientation(),
  50789. isMouseOverButton, isButtonDown,
  50790. getToggleState());
  50791. }
  50792. void TabBarButton::clicked (const ModifierKeys& mods)
  50793. {
  50794. if (mods.isPopupMenu())
  50795. owner->popupMenuClickOnTab (tabIndex, getButtonText());
  50796. else
  50797. owner->setCurrentTabIndex (tabIndex);
  50798. }
  50799. bool TabBarButton::hitTest (int mx, int my)
  50800. {
  50801. int x, y, w, h;
  50802. getActiveArea (x, y, w, h);
  50803. if (owner->getOrientation() == TabbedButtonBar::TabsAtLeft
  50804. || owner->getOrientation() == TabbedButtonBar::TabsAtRight)
  50805. {
  50806. if (((unsigned int) mx) < (unsigned int) getWidth()
  50807. && my >= y + overlapPixels
  50808. && my < y + h - overlapPixels)
  50809. return true;
  50810. }
  50811. else
  50812. {
  50813. if (mx >= x + overlapPixels && mx < x + w - overlapPixels
  50814. && ((unsigned int) my) < (unsigned int) getHeight())
  50815. return true;
  50816. }
  50817. Path p;
  50818. getLookAndFeel()
  50819. .createTabButtonShape (p, w, h, tabIndex, getButtonText(), *this,
  50820. owner->getOrientation(),
  50821. false, false, getToggleState());
  50822. return p.contains ((float) (mx - x),
  50823. (float) (my - y));
  50824. }
  50825. int TabBarButton::getBestTabLength (const int depth)
  50826. {
  50827. return jlimit (depth * 2,
  50828. depth * 7,
  50829. getLookAndFeel().getTabButtonBestWidth (tabIndex, getButtonText(), depth, *this));
  50830. }
  50831. void TabBarButton::getActiveArea (int& x, int& y, int& w, int& h)
  50832. {
  50833. x = 0;
  50834. y = 0;
  50835. int r = getWidth();
  50836. int b = getHeight();
  50837. const int spaceAroundImage = getLookAndFeel().getTabButtonSpaceAroundImage();
  50838. if (owner->getOrientation() != TabbedButtonBar::TabsAtLeft)
  50839. r -= spaceAroundImage;
  50840. if (owner->getOrientation() != TabbedButtonBar::TabsAtRight)
  50841. x += spaceAroundImage;
  50842. if (owner->getOrientation() != TabbedButtonBar::TabsAtBottom)
  50843. y += spaceAroundImage;
  50844. if (owner->getOrientation() != TabbedButtonBar::TabsAtTop)
  50845. b -= spaceAroundImage;
  50846. w = r - x;
  50847. h = b - y;
  50848. }
  50849. class TabAreaBehindFrontButtonComponent : public Component
  50850. {
  50851. public:
  50852. TabAreaBehindFrontButtonComponent (TabbedButtonBar* const owner_)
  50853. : owner (owner_)
  50854. {
  50855. setInterceptsMouseClicks (false, false);
  50856. }
  50857. ~TabAreaBehindFrontButtonComponent()
  50858. {
  50859. }
  50860. void paint (Graphics& g)
  50861. {
  50862. getLookAndFeel()
  50863. .drawTabAreaBehindFrontButton (g, getWidth(), getHeight(),
  50864. *owner, owner->getOrientation());
  50865. }
  50866. void enablementChanged()
  50867. {
  50868. repaint();
  50869. }
  50870. private:
  50871. TabbedButtonBar* const owner;
  50872. TabAreaBehindFrontButtonComponent (const TabAreaBehindFrontButtonComponent&);
  50873. const TabAreaBehindFrontButtonComponent& operator= (const TabAreaBehindFrontButtonComponent&);
  50874. };
  50875. TabbedButtonBar::TabbedButtonBar (const Orientation orientation_)
  50876. : orientation (orientation_),
  50877. currentTabIndex (-1),
  50878. extraTabsButton (0)
  50879. {
  50880. setInterceptsMouseClicks (false, true);
  50881. addAndMakeVisible (behindFrontTab = new TabAreaBehindFrontButtonComponent (this));
  50882. setFocusContainer (true);
  50883. }
  50884. TabbedButtonBar::~TabbedButtonBar()
  50885. {
  50886. deleteAllChildren();
  50887. }
  50888. void TabbedButtonBar::setOrientation (const Orientation newOrientation)
  50889. {
  50890. orientation = newOrientation;
  50891. for (int i = getNumChildComponents(); --i >= 0;)
  50892. getChildComponent (i)->resized();
  50893. resized();
  50894. }
  50895. TabBarButton* TabbedButtonBar::createTabButton (const String& name, const int index)
  50896. {
  50897. return new TabBarButton (name, this, index);
  50898. }
  50899. void TabbedButtonBar::clearTabs()
  50900. {
  50901. tabs.clear();
  50902. tabColours.clear();
  50903. currentTabIndex = -1;
  50904. deleteAndZero (extraTabsButton);
  50905. removeChildComponent (behindFrontTab);
  50906. deleteAllChildren();
  50907. addChildComponent (behindFrontTab);
  50908. setCurrentTabIndex (-1);
  50909. }
  50910. void TabbedButtonBar::addTab (const String& tabName,
  50911. const Colour& tabBackgroundColour,
  50912. int insertIndex)
  50913. {
  50914. jassert (tabName.isNotEmpty()); // you have to give them all a name..
  50915. if (tabName.isNotEmpty())
  50916. {
  50917. if (((unsigned int) insertIndex) > (unsigned int) tabs.size())
  50918. insertIndex = tabs.size();
  50919. for (int i = tabs.size(); --i >= insertIndex;)
  50920. {
  50921. TabBarButton* const tb = getTabButton (i);
  50922. if (tb != 0)
  50923. tb->tabIndex++;
  50924. }
  50925. tabs.insert (insertIndex, tabName);
  50926. tabColours.insert (insertIndex, tabBackgroundColour);
  50927. TabBarButton* const tb = createTabButton (tabName, insertIndex);
  50928. jassert (tb != 0); // your createTabButton() mustn't return zero!
  50929. addAndMakeVisible (tb, insertIndex);
  50930. resized();
  50931. if (currentTabIndex < 0)
  50932. setCurrentTabIndex (0);
  50933. }
  50934. }
  50935. void TabbedButtonBar::setTabName (const int tabIndex,
  50936. const String& newName)
  50937. {
  50938. if (((unsigned int) tabIndex) < (unsigned int) tabs.size()
  50939. && tabs[tabIndex] != newName)
  50940. {
  50941. tabs.set (tabIndex, newName);
  50942. TabBarButton* const tb = getTabButton (tabIndex);
  50943. if (tb != 0)
  50944. tb->setButtonText (newName);
  50945. resized();
  50946. }
  50947. }
  50948. void TabbedButtonBar::removeTab (const int tabIndex)
  50949. {
  50950. if (((unsigned int) tabIndex) < (unsigned int) tabs.size())
  50951. {
  50952. const int oldTabIndex = currentTabIndex;
  50953. if (currentTabIndex == tabIndex)
  50954. currentTabIndex = -1;
  50955. tabs.remove (tabIndex);
  50956. tabColours.remove (tabIndex);
  50957. delete getTabButton (tabIndex);
  50958. for (int i = tabIndex + 1; i <= tabs.size(); ++i)
  50959. {
  50960. TabBarButton* const tb = getTabButton (i);
  50961. if (tb != 0)
  50962. tb->tabIndex--;
  50963. }
  50964. resized();
  50965. setCurrentTabIndex (jlimit (0, jmax (0, tabs.size() - 1), oldTabIndex));
  50966. }
  50967. }
  50968. void TabbedButtonBar::moveTab (const int currentIndex,
  50969. const int newIndex)
  50970. {
  50971. tabs.move (currentIndex, newIndex);
  50972. tabColours.move (currentIndex, newIndex);
  50973. resized();
  50974. }
  50975. int TabbedButtonBar::getNumTabs() const
  50976. {
  50977. return tabs.size();
  50978. }
  50979. const StringArray TabbedButtonBar::getTabNames() const
  50980. {
  50981. return tabs;
  50982. }
  50983. void TabbedButtonBar::setCurrentTabIndex (int newIndex, const bool sendChangeMessage_)
  50984. {
  50985. if (currentTabIndex != newIndex)
  50986. {
  50987. if (((unsigned int) newIndex) >= (unsigned int) tabs.size())
  50988. newIndex = -1;
  50989. currentTabIndex = newIndex;
  50990. for (int i = 0; i < getNumChildComponents(); ++i)
  50991. {
  50992. TabBarButton* const tb = dynamic_cast <TabBarButton*> (getChildComponent (i));
  50993. if (tb != 0)
  50994. tb->setToggleState (tb->tabIndex == newIndex, false);
  50995. }
  50996. resized();
  50997. if (sendChangeMessage_)
  50998. sendChangeMessage (this);
  50999. currentTabChanged (newIndex, newIndex >= 0 ? tabs [newIndex] : String::empty);
  51000. }
  51001. }
  51002. TabBarButton* TabbedButtonBar::getTabButton (const int index) const
  51003. {
  51004. for (int i = getNumChildComponents(); --i >= 0;)
  51005. {
  51006. TabBarButton* const tb = dynamic_cast <TabBarButton*> (getChildComponent (i));
  51007. if (tb != 0 && tb->tabIndex == index)
  51008. return tb;
  51009. }
  51010. return 0;
  51011. }
  51012. void TabbedButtonBar::lookAndFeelChanged()
  51013. {
  51014. deleteAndZero (extraTabsButton);
  51015. resized();
  51016. }
  51017. void TabbedButtonBar::resized()
  51018. {
  51019. const double minimumScale = 0.7;
  51020. int depth = getWidth();
  51021. int length = getHeight();
  51022. if (orientation == TabsAtTop || orientation == TabsAtBottom)
  51023. swapVariables (depth, length);
  51024. const int overlap = getLookAndFeel().getTabButtonOverlap (depth)
  51025. + getLookAndFeel().getTabButtonSpaceAroundImage() * 2;
  51026. int i, totalLength = overlap;
  51027. int numVisibleButtons = tabs.size();
  51028. for (i = 0; i < getNumChildComponents(); ++i)
  51029. {
  51030. TabBarButton* const tb = dynamic_cast <TabBarButton*> (getChildComponent (i));
  51031. if (tb != 0)
  51032. {
  51033. totalLength += tb->getBestTabLength (depth) - overlap;
  51034. tb->overlapPixels = overlap / 2;
  51035. }
  51036. }
  51037. double scale = 1.0;
  51038. if (totalLength > length)
  51039. scale = jmax (minimumScale, length / (double) totalLength);
  51040. const bool isTooBig = totalLength * scale > length;
  51041. int tabsButtonPos = 0;
  51042. if (isTooBig)
  51043. {
  51044. if (extraTabsButton == 0)
  51045. {
  51046. addAndMakeVisible (extraTabsButton = getLookAndFeel().createTabBarExtrasButton());
  51047. extraTabsButton->addButtonListener (this);
  51048. extraTabsButton->setAlwaysOnTop (true);
  51049. extraTabsButton->setTriggeredOnMouseDown (true);
  51050. }
  51051. const int buttonSize = jmin (proportionOfWidth (0.7f), proportionOfHeight (0.7f));
  51052. extraTabsButton->setSize (buttonSize, buttonSize);
  51053. if (orientation == TabsAtTop || orientation == TabsAtBottom)
  51054. {
  51055. tabsButtonPos = getWidth() - buttonSize / 2 - 1;
  51056. extraTabsButton->setCentrePosition (tabsButtonPos, getHeight() / 2);
  51057. }
  51058. else
  51059. {
  51060. tabsButtonPos = getHeight() - buttonSize / 2 - 1;
  51061. extraTabsButton->setCentrePosition (getWidth() / 2, tabsButtonPos);
  51062. }
  51063. totalLength = 0;
  51064. for (i = 0; i < tabs.size(); ++i)
  51065. {
  51066. TabBarButton* const tb = getTabButton (i);
  51067. if (tb != 0)
  51068. {
  51069. const int newLength = totalLength + tb->getBestTabLength (depth);
  51070. if (i > 0 && newLength * minimumScale > tabsButtonPos)
  51071. {
  51072. totalLength += overlap;
  51073. break;
  51074. }
  51075. numVisibleButtons = i + 1;
  51076. totalLength = newLength - overlap;
  51077. }
  51078. }
  51079. scale = jmax (minimumScale, tabsButtonPos / (double) totalLength);
  51080. }
  51081. else
  51082. {
  51083. deleteAndZero (extraTabsButton);
  51084. }
  51085. int pos = 0;
  51086. TabBarButton* frontTab = 0;
  51087. for (i = 0; i < tabs.size(); ++i)
  51088. {
  51089. TabBarButton* const tb = getTabButton (i);
  51090. if (tb != 0)
  51091. {
  51092. const int bestLength = roundToInt (scale * tb->getBestTabLength (depth));
  51093. if (i < numVisibleButtons)
  51094. {
  51095. if (orientation == TabsAtTop || orientation == TabsAtBottom)
  51096. tb->setBounds (pos, 0, bestLength, getHeight());
  51097. else
  51098. tb->setBounds (0, pos, getWidth(), bestLength);
  51099. tb->toBack();
  51100. if (tb->tabIndex == currentTabIndex)
  51101. frontTab = tb;
  51102. tb->setVisible (true);
  51103. }
  51104. else
  51105. {
  51106. tb->setVisible (false);
  51107. }
  51108. pos += bestLength - overlap;
  51109. }
  51110. }
  51111. behindFrontTab->setBounds (0, 0, getWidth(), getHeight());
  51112. if (frontTab != 0)
  51113. {
  51114. frontTab->toFront (false);
  51115. behindFrontTab->toBehind (frontTab);
  51116. }
  51117. }
  51118. const Colour TabbedButtonBar::getTabBackgroundColour (const int tabIndex)
  51119. {
  51120. return tabColours [tabIndex];
  51121. }
  51122. void TabbedButtonBar::setTabBackgroundColour (const int tabIndex, const Colour& newColour)
  51123. {
  51124. if (((unsigned int) tabIndex) < (unsigned int) tabColours.size()
  51125. && tabColours [tabIndex] != newColour)
  51126. {
  51127. tabColours.set (tabIndex, newColour);
  51128. repaint();
  51129. }
  51130. }
  51131. void TabbedButtonBar::buttonClicked (Button* button)
  51132. {
  51133. if (extraTabsButton == button)
  51134. {
  51135. PopupMenu m;
  51136. for (int i = 0; i < tabs.size(); ++i)
  51137. {
  51138. TabBarButton* const tb = getTabButton (i);
  51139. if (tb != 0 && ! tb->isVisible())
  51140. m.addItem (tb->tabIndex + 1, tabs[i], true, i == currentTabIndex);
  51141. }
  51142. const int res = m.showAt (extraTabsButton);
  51143. if (res != 0)
  51144. setCurrentTabIndex (res - 1);
  51145. }
  51146. }
  51147. void TabbedButtonBar::currentTabChanged (const int, const String&)
  51148. {
  51149. }
  51150. void TabbedButtonBar::popupMenuClickOnTab (const int, const String&)
  51151. {
  51152. }
  51153. END_JUCE_NAMESPACE
  51154. /*** End of inlined file: juce_TabbedButtonBar.cpp ***/
  51155. /*** Start of inlined file: juce_TabbedComponent.cpp ***/
  51156. BEGIN_JUCE_NAMESPACE
  51157. class TabCompButtonBar : public TabbedButtonBar
  51158. {
  51159. public:
  51160. TabCompButtonBar (TabbedComponent* const owner_,
  51161. const TabbedButtonBar::Orientation orientation)
  51162. : TabbedButtonBar (orientation),
  51163. owner (owner_)
  51164. {
  51165. }
  51166. ~TabCompButtonBar()
  51167. {
  51168. }
  51169. void currentTabChanged (const int newCurrentTabIndex,
  51170. const String& newTabName)
  51171. {
  51172. owner->changeCallback (newCurrentTabIndex, newTabName);
  51173. }
  51174. void popupMenuClickOnTab (const int tabIndex,
  51175. const String& tabName)
  51176. {
  51177. owner->popupMenuClickOnTab (tabIndex, tabName);
  51178. }
  51179. const Colour getTabBackgroundColour (const int tabIndex)
  51180. {
  51181. return owner->tabs->getTabBackgroundColour (tabIndex);
  51182. }
  51183. TabBarButton* createTabButton (const String& tabName, const int tabIndex)
  51184. {
  51185. return owner->createTabButton (tabName, tabIndex);
  51186. }
  51187. juce_UseDebuggingNewOperator
  51188. private:
  51189. TabbedComponent* const owner;
  51190. TabCompButtonBar (const TabCompButtonBar&);
  51191. const TabCompButtonBar& operator= (const TabCompButtonBar&);
  51192. };
  51193. TabbedComponent::TabbedComponent (const TabbedButtonBar::Orientation orientation)
  51194. : panelComponent (0),
  51195. tabDepth (30),
  51196. outlineThickness (1),
  51197. edgeIndent (0)
  51198. {
  51199. addAndMakeVisible (tabs = new TabCompButtonBar (this, orientation));
  51200. }
  51201. TabbedComponent::~TabbedComponent()
  51202. {
  51203. clearTabs();
  51204. delete tabs;
  51205. }
  51206. void TabbedComponent::setOrientation (const TabbedButtonBar::Orientation orientation)
  51207. {
  51208. tabs->setOrientation (orientation);
  51209. resized();
  51210. }
  51211. TabbedButtonBar::Orientation TabbedComponent::getOrientation() const throw()
  51212. {
  51213. return tabs->getOrientation();
  51214. }
  51215. void TabbedComponent::setTabBarDepth (const int newDepth)
  51216. {
  51217. if (tabDepth != newDepth)
  51218. {
  51219. tabDepth = newDepth;
  51220. resized();
  51221. }
  51222. }
  51223. TabBarButton* TabbedComponent::createTabButton (const String& tabName, const int tabIndex)
  51224. {
  51225. return new TabBarButton (tabName, tabs, tabIndex);
  51226. }
  51227. void TabbedComponent::clearTabs()
  51228. {
  51229. if (panelComponent != 0)
  51230. {
  51231. panelComponent->setVisible (false);
  51232. removeChildComponent (panelComponent);
  51233. panelComponent = 0;
  51234. }
  51235. tabs->clearTabs();
  51236. for (int i = contentComponents.size(); --i >= 0;)
  51237. {
  51238. Component* const c = contentComponents.getUnchecked(i);
  51239. // be careful not to delete these components until they've been removed from the tab component
  51240. jassert (c == 0 || c->isValidComponent());
  51241. if (c != 0 && c->getProperties() ["deleteByTabComp_"])
  51242. delete c;
  51243. }
  51244. contentComponents.clear();
  51245. }
  51246. void TabbedComponent::addTab (const String& tabName,
  51247. const Colour& tabBackgroundColour,
  51248. Component* const contentComponent,
  51249. const bool deleteComponentWhenNotNeeded,
  51250. const int insertIndex)
  51251. {
  51252. contentComponents.insert (insertIndex, contentComponent);
  51253. if (contentComponent != 0)
  51254. contentComponent->getProperties().set ("deleteByTabComp_", deleteComponentWhenNotNeeded);
  51255. tabs->addTab (tabName, tabBackgroundColour, insertIndex);
  51256. }
  51257. void TabbedComponent::setTabName (const int tabIndex,
  51258. const String& newName)
  51259. {
  51260. tabs->setTabName (tabIndex, newName);
  51261. }
  51262. void TabbedComponent::removeTab (const int tabIndex)
  51263. {
  51264. Component* const c = contentComponents [tabIndex];
  51265. if (c != 0 && c->getProperties() ["deleteByTabComp_"])
  51266. {
  51267. if (c == panelComponent)
  51268. panelComponent = 0;
  51269. delete c;
  51270. }
  51271. contentComponents.remove (tabIndex);
  51272. tabs->removeTab (tabIndex);
  51273. }
  51274. int TabbedComponent::getNumTabs() const
  51275. {
  51276. return tabs->getNumTabs();
  51277. }
  51278. const StringArray TabbedComponent::getTabNames() const
  51279. {
  51280. return tabs->getTabNames();
  51281. }
  51282. Component* TabbedComponent::getTabContentComponent (const int tabIndex) const throw()
  51283. {
  51284. return contentComponents [tabIndex];
  51285. }
  51286. const Colour TabbedComponent::getTabBackgroundColour (const int tabIndex) const throw()
  51287. {
  51288. return tabs->getTabBackgroundColour (tabIndex);
  51289. }
  51290. void TabbedComponent::setTabBackgroundColour (const int tabIndex, const Colour& newColour)
  51291. {
  51292. tabs->setTabBackgroundColour (tabIndex, newColour);
  51293. if (getCurrentTabIndex() == tabIndex)
  51294. repaint();
  51295. }
  51296. void TabbedComponent::setCurrentTabIndex (const int newTabIndex, const bool sendChangeMessage)
  51297. {
  51298. tabs->setCurrentTabIndex (newTabIndex, sendChangeMessage);
  51299. }
  51300. int TabbedComponent::getCurrentTabIndex() const
  51301. {
  51302. return tabs->getCurrentTabIndex();
  51303. }
  51304. const String& TabbedComponent::getCurrentTabName() const
  51305. {
  51306. return tabs->getCurrentTabName();
  51307. }
  51308. void TabbedComponent::setOutline (int thickness)
  51309. {
  51310. outlineThickness = thickness;
  51311. repaint();
  51312. }
  51313. void TabbedComponent::setIndent (const int indentThickness)
  51314. {
  51315. edgeIndent = indentThickness;
  51316. }
  51317. void TabbedComponent::paint (Graphics& g)
  51318. {
  51319. g.fillAll (findColour (backgroundColourId));
  51320. const TabbedButtonBar::Orientation o = getOrientation();
  51321. int x = 0;
  51322. int y = 0;
  51323. int r = getWidth();
  51324. int b = getHeight();
  51325. if (o == TabbedButtonBar::TabsAtTop)
  51326. y += tabDepth;
  51327. else if (o == TabbedButtonBar::TabsAtBottom)
  51328. b -= tabDepth;
  51329. else if (o == TabbedButtonBar::TabsAtLeft)
  51330. x += tabDepth;
  51331. else if (o == TabbedButtonBar::TabsAtRight)
  51332. r -= tabDepth;
  51333. g.reduceClipRegion (x, y, r - x, b - y);
  51334. g.fillAll (tabs->getTabBackgroundColour (getCurrentTabIndex()));
  51335. if (outlineThickness > 0)
  51336. {
  51337. if (o == TabbedButtonBar::TabsAtTop)
  51338. --y;
  51339. else if (o == TabbedButtonBar::TabsAtBottom)
  51340. ++b;
  51341. else if (o == TabbedButtonBar::TabsAtLeft)
  51342. --x;
  51343. else if (o == TabbedButtonBar::TabsAtRight)
  51344. ++r;
  51345. g.setColour (findColour (outlineColourId));
  51346. g.drawRect (x, y, r - x, b - y, outlineThickness);
  51347. }
  51348. }
  51349. void TabbedComponent::resized()
  51350. {
  51351. const TabbedButtonBar::Orientation o = getOrientation();
  51352. const int indent = edgeIndent + outlineThickness;
  51353. BorderSize indents (indent);
  51354. if (o == TabbedButtonBar::TabsAtTop)
  51355. {
  51356. tabs->setBounds (0, 0, getWidth(), tabDepth);
  51357. indents.setTop (tabDepth + edgeIndent);
  51358. }
  51359. else if (o == TabbedButtonBar::TabsAtBottom)
  51360. {
  51361. tabs->setBounds (0, getHeight() - tabDepth, getWidth(), tabDepth);
  51362. indents.setBottom (tabDepth + edgeIndent);
  51363. }
  51364. else if (o == TabbedButtonBar::TabsAtLeft)
  51365. {
  51366. tabs->setBounds (0, 0, tabDepth, getHeight());
  51367. indents.setLeft (tabDepth + edgeIndent);
  51368. }
  51369. else if (o == TabbedButtonBar::TabsAtRight)
  51370. {
  51371. tabs->setBounds (getWidth() - tabDepth, 0, tabDepth, getHeight());
  51372. indents.setRight (tabDepth + edgeIndent);
  51373. }
  51374. const Rectangle<int> bounds (indents.subtractedFrom (Rectangle<int> (0, 0, getWidth(), getHeight())));
  51375. for (int i = contentComponents.size(); --i >= 0;)
  51376. if (contentComponents.getUnchecked (i) != 0)
  51377. contentComponents.getUnchecked (i)->setBounds (bounds);
  51378. }
  51379. void TabbedComponent::lookAndFeelChanged()
  51380. {
  51381. for (int i = contentComponents.size(); --i >= 0;)
  51382. if (contentComponents.getUnchecked (i) != 0)
  51383. contentComponents.getUnchecked (i)->lookAndFeelChanged();
  51384. }
  51385. void TabbedComponent::changeCallback (const int newCurrentTabIndex,
  51386. const String& newTabName)
  51387. {
  51388. if (panelComponent != 0)
  51389. {
  51390. panelComponent->setVisible (false);
  51391. removeChildComponent (panelComponent);
  51392. panelComponent = 0;
  51393. }
  51394. if (getCurrentTabIndex() >= 0)
  51395. {
  51396. panelComponent = contentComponents [getCurrentTabIndex()];
  51397. if (panelComponent != 0)
  51398. {
  51399. // do these ops as two stages instead of addAndMakeVisible() so that the
  51400. // component has always got a parent when it gets the visibilityChanged() callback
  51401. addChildComponent (panelComponent);
  51402. panelComponent->setVisible (true);
  51403. panelComponent->toFront (true);
  51404. }
  51405. repaint();
  51406. }
  51407. resized();
  51408. currentTabChanged (newCurrentTabIndex, newTabName);
  51409. }
  51410. void TabbedComponent::currentTabChanged (const int, const String&)
  51411. {
  51412. }
  51413. void TabbedComponent::popupMenuClickOnTab (const int, const String&)
  51414. {
  51415. }
  51416. END_JUCE_NAMESPACE
  51417. /*** End of inlined file: juce_TabbedComponent.cpp ***/
  51418. /*** Start of inlined file: juce_Viewport.cpp ***/
  51419. BEGIN_JUCE_NAMESPACE
  51420. Viewport::Viewport (const String& componentName)
  51421. : Component (componentName),
  51422. contentComp (0),
  51423. lastVX (0),
  51424. lastVY (0),
  51425. lastVW (0),
  51426. lastVH (0),
  51427. scrollBarThickness (0),
  51428. singleStepX (16),
  51429. singleStepY (16),
  51430. showHScrollbar (true),
  51431. showVScrollbar (true)
  51432. {
  51433. // content holder is used to clip the contents so they don't overlap the scrollbars
  51434. addAndMakeVisible (contentHolder = new Component());
  51435. contentHolder->setInterceptsMouseClicks (false, true);
  51436. verticalScrollBar = new ScrollBar (true);
  51437. horizontalScrollBar = new ScrollBar (false);
  51438. addChildComponent (verticalScrollBar);
  51439. addChildComponent (horizontalScrollBar);
  51440. verticalScrollBar->addListener (this);
  51441. horizontalScrollBar->addListener (this);
  51442. setInterceptsMouseClicks (false, true);
  51443. setWantsKeyboardFocus (true);
  51444. }
  51445. Viewport::~Viewport()
  51446. {
  51447. contentHolder->deleteAllChildren();
  51448. deleteAllChildren();
  51449. }
  51450. void Viewport::visibleAreaChanged (int, int, int, int)
  51451. {
  51452. }
  51453. void Viewport::setViewedComponent (Component* const newViewedComponent)
  51454. {
  51455. if (contentComp != newViewedComponent)
  51456. {
  51457. if (contentComp->isValidComponent())
  51458. {
  51459. Component* const oldComp = contentComp;
  51460. contentComp = 0;
  51461. delete oldComp;
  51462. }
  51463. contentComp = newViewedComponent;
  51464. if (contentComp != 0)
  51465. {
  51466. contentComp->setTopLeftPosition (0, 0);
  51467. contentHolder->addAndMakeVisible (contentComp);
  51468. contentComp->addComponentListener (this);
  51469. }
  51470. updateVisibleRegion();
  51471. }
  51472. }
  51473. int Viewport::getMaximumVisibleWidth() const throw()
  51474. {
  51475. return jmax (0, getWidth() - (verticalScrollBar->isVisible() ? getScrollBarThickness() : 0));
  51476. }
  51477. int Viewport::getMaximumVisibleHeight() const throw()
  51478. {
  51479. return jmax (0, getHeight() - (horizontalScrollBar->isVisible() ? getScrollBarThickness() : 0));
  51480. }
  51481. void Viewport::setViewPosition (const int xPixelsOffset,
  51482. const int yPixelsOffset)
  51483. {
  51484. if (contentComp != 0)
  51485. contentComp->setTopLeftPosition (-xPixelsOffset,
  51486. -yPixelsOffset);
  51487. }
  51488. void Viewport::setViewPositionProportionately (const double x,
  51489. const double y)
  51490. {
  51491. if (contentComp != 0)
  51492. setViewPosition (jmax (0, roundToInt (x * (contentComp->getWidth() - getWidth()))),
  51493. jmax (0, roundToInt (y * (contentComp->getHeight() - getHeight()))));
  51494. }
  51495. bool Viewport::autoScroll (int mouseX, int mouseY, int activeBorderThickness, int maximumSpeed)
  51496. {
  51497. if (contentComp != 0)
  51498. {
  51499. int dx = 0, dy = 0;
  51500. if (mouseX < activeBorderThickness)
  51501. dx = activeBorderThickness - mouseX;
  51502. else if (mouseX >= contentHolder->getWidth() - activeBorderThickness)
  51503. dx = (contentHolder->getWidth() - activeBorderThickness) - mouseX;
  51504. if (dx < 0)
  51505. dx = jmax (dx, -maximumSpeed, contentHolder->getWidth() - contentComp->getRight());
  51506. else
  51507. dx = jmin (dx, maximumSpeed, -contentComp->getX());
  51508. if (mouseY < activeBorderThickness)
  51509. dy = activeBorderThickness - mouseY;
  51510. else if (mouseY >= contentHolder->getHeight() - activeBorderThickness)
  51511. dy = (contentHolder->getHeight() - activeBorderThickness) - mouseY;
  51512. if (dy < 0)
  51513. dy = jmax (dy, -maximumSpeed, contentHolder->getHeight() - contentComp->getBottom());
  51514. else
  51515. dy = jmin (dy, maximumSpeed, -contentComp->getY());
  51516. if (dx != 0 || dy != 0)
  51517. {
  51518. contentComp->setTopLeftPosition (contentComp->getX() + dx,
  51519. contentComp->getY() + dy);
  51520. return true;
  51521. }
  51522. }
  51523. return false;
  51524. }
  51525. void Viewport::componentMovedOrResized (Component&, bool, bool)
  51526. {
  51527. updateVisibleRegion();
  51528. }
  51529. void Viewport::resized()
  51530. {
  51531. updateVisibleRegion();
  51532. }
  51533. void Viewport::updateVisibleRegion()
  51534. {
  51535. if (contentComp != 0)
  51536. {
  51537. const int newVX = -contentComp->getX();
  51538. const int newVY = -contentComp->getY();
  51539. if (newVX == 0 && newVY == 0
  51540. && contentComp->getWidth() <= getWidth()
  51541. && contentComp->getHeight() <= getHeight())
  51542. {
  51543. horizontalScrollBar->setVisible (false);
  51544. verticalScrollBar->setVisible (false);
  51545. }
  51546. horizontalScrollBar->setRangeLimits (0.0, contentComp->getWidth());
  51547. horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
  51548. horizontalScrollBar->setSingleStepSize (singleStepX);
  51549. if (! (contentComp->getWidth() > 0 && showHScrollbar && getHeight() > getScrollBarThickness()))
  51550. horizontalScrollBar->setVisible (false);
  51551. verticalScrollBar->setRangeLimits (0.0, contentComp->getHeight());
  51552. verticalScrollBar->setCurrentRange (newVY, getMaximumVisibleHeight());
  51553. verticalScrollBar->setSingleStepSize (singleStepY);
  51554. if (! (contentComp->getHeight() > 0 && showVScrollbar && getWidth() > getScrollBarThickness()))
  51555. verticalScrollBar->setVisible (false);
  51556. if (verticalScrollBar->isVisible())
  51557. {
  51558. horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
  51559. verticalScrollBar->setCurrentRange (newVY, getMaximumVisibleHeight());
  51560. verticalScrollBar
  51561. ->setBounds (getMaximumVisibleWidth(), 0,
  51562. getScrollBarThickness(), getMaximumVisibleHeight());
  51563. }
  51564. if (horizontalScrollBar->isVisible())
  51565. {
  51566. horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
  51567. horizontalScrollBar
  51568. ->setBounds (0, getMaximumVisibleHeight(),
  51569. getMaximumVisibleWidth(), getScrollBarThickness());
  51570. }
  51571. contentHolder->setSize (getMaximumVisibleWidth(),
  51572. getMaximumVisibleHeight());
  51573. const int newVW = jmin (contentComp->getRight(), getMaximumVisibleWidth());
  51574. const int newVH = jmin (contentComp->getBottom(), getMaximumVisibleHeight());
  51575. if (newVX != lastVX
  51576. || newVY != lastVY
  51577. || newVW != lastVW
  51578. || newVH != lastVH)
  51579. {
  51580. lastVX = newVX;
  51581. lastVY = newVY;
  51582. lastVW = newVW;
  51583. lastVH = newVH;
  51584. visibleAreaChanged (newVX, newVY, newVW, newVH);
  51585. }
  51586. horizontalScrollBar->handleUpdateNowIfNeeded();
  51587. verticalScrollBar->handleUpdateNowIfNeeded();
  51588. }
  51589. else
  51590. {
  51591. horizontalScrollBar->setVisible (false);
  51592. verticalScrollBar->setVisible (false);
  51593. }
  51594. }
  51595. void Viewport::setSingleStepSizes (const int stepX,
  51596. const int stepY)
  51597. {
  51598. singleStepX = stepX;
  51599. singleStepY = stepY;
  51600. updateVisibleRegion();
  51601. }
  51602. void Viewport::setScrollBarsShown (const bool showVerticalScrollbarIfNeeded,
  51603. const bool showHorizontalScrollbarIfNeeded)
  51604. {
  51605. showVScrollbar = showVerticalScrollbarIfNeeded;
  51606. showHScrollbar = showHorizontalScrollbarIfNeeded;
  51607. updateVisibleRegion();
  51608. }
  51609. void Viewport::setScrollBarThickness (const int thickness)
  51610. {
  51611. scrollBarThickness = thickness;
  51612. updateVisibleRegion();
  51613. }
  51614. int Viewport::getScrollBarThickness() const throw()
  51615. {
  51616. return (scrollBarThickness > 0) ? scrollBarThickness
  51617. : getLookAndFeel().getDefaultScrollbarWidth();
  51618. }
  51619. void Viewport::setScrollBarButtonVisibility (const bool buttonsVisible)
  51620. {
  51621. verticalScrollBar->setButtonVisibility (buttonsVisible);
  51622. horizontalScrollBar->setButtonVisibility (buttonsVisible);
  51623. }
  51624. void Viewport::scrollBarMoved (ScrollBar* scrollBarThatHasMoved, const double newRangeStart)
  51625. {
  51626. if (scrollBarThatHasMoved == horizontalScrollBar)
  51627. {
  51628. setViewPosition (roundToInt (newRangeStart), getViewPositionY());
  51629. }
  51630. else if (scrollBarThatHasMoved == verticalScrollBar)
  51631. {
  51632. setViewPosition (getViewPositionX(), roundToInt (newRangeStart));
  51633. }
  51634. }
  51635. void Viewport::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  51636. {
  51637. if (! useMouseWheelMoveIfNeeded (e, wheelIncrementX, wheelIncrementY))
  51638. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  51639. }
  51640. bool Viewport::useMouseWheelMoveIfNeeded (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  51641. {
  51642. if (! (e.mods.isAltDown() || e.mods.isCtrlDown()))
  51643. {
  51644. const bool hasVertBar = verticalScrollBar->isVisible();
  51645. const bool hasHorzBar = horizontalScrollBar->isVisible();
  51646. if (hasHorzBar && (wheelIncrementX != 0 || e.mods.isShiftDown() || ! hasVertBar))
  51647. {
  51648. if (wheelIncrementX == 0 && ! hasVertBar)
  51649. wheelIncrementX = wheelIncrementY;
  51650. horizontalScrollBar->mouseWheelMove (e.getEventRelativeTo (horizontalScrollBar),
  51651. wheelIncrementX, wheelIncrementY);
  51652. return true;
  51653. }
  51654. else if (hasVertBar && wheelIncrementY != 0)
  51655. {
  51656. verticalScrollBar->mouseWheelMove (e.getEventRelativeTo (verticalScrollBar),
  51657. wheelIncrementX, wheelIncrementY);
  51658. return true;
  51659. }
  51660. }
  51661. return false;
  51662. }
  51663. bool Viewport::keyPressed (const KeyPress& key)
  51664. {
  51665. const bool isUpDownKey = key.isKeyCode (KeyPress::upKey)
  51666. || key.isKeyCode (KeyPress::downKey)
  51667. || key.isKeyCode (KeyPress::pageUpKey)
  51668. || key.isKeyCode (KeyPress::pageDownKey)
  51669. || key.isKeyCode (KeyPress::homeKey)
  51670. || key.isKeyCode (KeyPress::endKey);
  51671. if (verticalScrollBar->isVisible() && isUpDownKey)
  51672. return verticalScrollBar->keyPressed (key);
  51673. const bool isLeftRightKey = key.isKeyCode (KeyPress::leftKey)
  51674. || key.isKeyCode (KeyPress::rightKey);
  51675. if (horizontalScrollBar->isVisible() && (isUpDownKey || isLeftRightKey))
  51676. return horizontalScrollBar->keyPressed (key);
  51677. return false;
  51678. }
  51679. END_JUCE_NAMESPACE
  51680. /*** End of inlined file: juce_Viewport.cpp ***/
  51681. /*** Start of inlined file: juce_LookAndFeel.cpp ***/
  51682. BEGIN_JUCE_NAMESPACE
  51683. static const Colour createBaseColour (const Colour& buttonColour,
  51684. const bool hasKeyboardFocus,
  51685. const bool isMouseOverButton,
  51686. const bool isButtonDown) throw()
  51687. {
  51688. const float sat = hasKeyboardFocus ? 1.3f : 0.9f;
  51689. const Colour baseColour (buttonColour.withMultipliedSaturation (sat));
  51690. if (isButtonDown)
  51691. return baseColour.contrasting (0.2f);
  51692. else if (isMouseOverButton)
  51693. return baseColour.contrasting (0.1f);
  51694. return baseColour;
  51695. }
  51696. static String defaultSansName, defaultSerifName, defaultFixedName;
  51697. void clearUpDefaultFontNames() throw()
  51698. {
  51699. defaultSansName = String::empty;
  51700. defaultSerifName = String::empty;
  51701. defaultFixedName = String::empty;
  51702. }
  51703. LookAndFeel::LookAndFeel()
  51704. {
  51705. /* if this fails it means you're trying to create a LookAndFeel object before
  51706. the static Colours have been initialised. That ain't gonna work. It probably
  51707. means that you're using a static LookAndFeel object and that your compiler has
  51708. decided to intialise it before the Colours class.
  51709. */
  51710. jassert (Colours::white == Colour (0xffffffff));
  51711. // set up the standard set of colours..
  51712. const int textButtonColour = 0xffbbbbff;
  51713. const int textHighlightColour = 0x401111ee;
  51714. const int standardOutlineColour = 0xb2808080;
  51715. static const int standardColours[] =
  51716. {
  51717. TextButton::buttonColourId, textButtonColour,
  51718. TextButton::buttonOnColourId, 0xff4444ff,
  51719. TextButton::textColourOnId, 0xff000000,
  51720. TextButton::textColourOffId, 0xff000000,
  51721. ComboBox::buttonColourId, 0xffbbbbff,
  51722. ComboBox::outlineColourId, standardOutlineColour,
  51723. ToggleButton::textColourId, 0xff000000,
  51724. TextEditor::backgroundColourId, 0xffffffff,
  51725. TextEditor::textColourId, 0xff000000,
  51726. TextEditor::highlightColourId, textHighlightColour,
  51727. TextEditor::highlightedTextColourId, 0xff000000,
  51728. TextEditor::caretColourId, 0xff000000,
  51729. TextEditor::outlineColourId, 0x00000000,
  51730. TextEditor::focusedOutlineColourId, textButtonColour,
  51731. TextEditor::shadowColourId, 0x38000000,
  51732. Label::backgroundColourId, 0x00000000,
  51733. Label::textColourId, 0xff000000,
  51734. Label::outlineColourId, 0x00000000,
  51735. ScrollBar::backgroundColourId, 0x00000000,
  51736. ScrollBar::thumbColourId, 0xffffffff,
  51737. ScrollBar::trackColourId, 0xffffffff,
  51738. TreeView::linesColourId, 0x4c000000,
  51739. TreeView::backgroundColourId, 0x00000000,
  51740. TreeView::dragAndDropIndicatorColourId, 0x80ff0000,
  51741. PopupMenu::backgroundColourId, 0xffffffff,
  51742. PopupMenu::textColourId, 0xff000000,
  51743. PopupMenu::headerTextColourId, 0xff000000,
  51744. PopupMenu::highlightedTextColourId, 0xffffffff,
  51745. PopupMenu::highlightedBackgroundColourId, 0x991111aa,
  51746. ComboBox::textColourId, 0xff000000,
  51747. ComboBox::backgroundColourId, 0xffffffff,
  51748. ComboBox::arrowColourId, 0x99000000,
  51749. ListBox::backgroundColourId, 0xffffffff,
  51750. ListBox::outlineColourId, standardOutlineColour,
  51751. ListBox::textColourId, 0xff000000,
  51752. Slider::backgroundColourId, 0x00000000,
  51753. Slider::thumbColourId, textButtonColour,
  51754. Slider::trackColourId, 0x7fffffff,
  51755. Slider::rotarySliderFillColourId, 0x7f0000ff,
  51756. Slider::rotarySliderOutlineColourId, 0x66000000,
  51757. Slider::textBoxTextColourId, 0xff000000,
  51758. Slider::textBoxBackgroundColourId, 0xffffffff,
  51759. Slider::textBoxHighlightColourId, textHighlightColour,
  51760. Slider::textBoxOutlineColourId, standardOutlineColour,
  51761. ResizableWindow::backgroundColourId, 0xff777777,
  51762. //DocumentWindow::textColourId, 0xff000000, // (this is deliberately not set)
  51763. AlertWindow::backgroundColourId, 0xffededed,
  51764. AlertWindow::textColourId, 0xff000000,
  51765. AlertWindow::outlineColourId, 0xff666666,
  51766. ProgressBar::backgroundColourId, 0xffeeeeee,
  51767. ProgressBar::foregroundColourId, 0xffaaaaee,
  51768. TooltipWindow::backgroundColourId, 0xffeeeebb,
  51769. TooltipWindow::textColourId, 0xff000000,
  51770. TooltipWindow::outlineColourId, 0x4c000000,
  51771. TabbedComponent::backgroundColourId, 0x00000000,
  51772. TabbedComponent::outlineColourId, 0xff777777,
  51773. TabbedButtonBar::tabOutlineColourId, 0x80000000,
  51774. TabbedButtonBar::frontOutlineColourId, 0x90000000,
  51775. Toolbar::backgroundColourId, 0xfff6f8f9,
  51776. Toolbar::separatorColourId, 0x4c000000,
  51777. Toolbar::buttonMouseOverBackgroundColourId, 0x4c0000ff,
  51778. Toolbar::buttonMouseDownBackgroundColourId, 0x800000ff,
  51779. Toolbar::labelTextColourId, 0xff000000,
  51780. Toolbar::editingModeOutlineColourId, 0xffff0000,
  51781. HyperlinkButton::textColourId, 0xcc1111ee,
  51782. GroupComponent::outlineColourId, 0x66000000,
  51783. GroupComponent::textColourId, 0xff000000,
  51784. DirectoryContentsDisplayComponent::highlightColourId, textHighlightColour,
  51785. DirectoryContentsDisplayComponent::textColourId, 0xff000000,
  51786. 0x1000440, /*LassoComponent::lassoFillColourId*/ 0x66dddddd,
  51787. 0x1000441, /*LassoComponent::lassoOutlineColourId*/ 0x99111111,
  51788. MidiKeyboardComponent::whiteNoteColourId, 0xffffffff,
  51789. MidiKeyboardComponent::blackNoteColourId, 0xff000000,
  51790. MidiKeyboardComponent::keySeparatorLineColourId, 0x66000000,
  51791. MidiKeyboardComponent::mouseOverKeyOverlayColourId, 0x80ffff00,
  51792. MidiKeyboardComponent::keyDownOverlayColourId, 0xffb6b600,
  51793. MidiKeyboardComponent::textLabelColourId, 0xff000000,
  51794. MidiKeyboardComponent::upDownButtonBackgroundColourId, 0xffd3d3d3,
  51795. MidiKeyboardComponent::upDownButtonArrowColourId, 0xff000000,
  51796. CodeEditorComponent::backgroundColourId, 0xffffffff,
  51797. CodeEditorComponent::caretColourId, 0xff000000,
  51798. CodeEditorComponent::highlightColourId, textHighlightColour,
  51799. CodeEditorComponent::defaultTextColourId, 0xff000000,
  51800. ColourSelector::backgroundColourId, 0xffe5e5e5,
  51801. ColourSelector::labelTextColourId, 0xff000000,
  51802. KeyMappingEditorComponent::backgroundColourId, 0x00000000,
  51803. KeyMappingEditorComponent::textColourId, 0xff000000,
  51804. FileSearchPathListComponent::backgroundColourId, 0xffffffff,
  51805. FileChooserDialogBox::titleTextColourId, 0xff000000,
  51806. };
  51807. for (int i = 0; i < numElementsInArray (standardColours); i += 2)
  51808. setColour (standardColours [i], Colour (standardColours [i + 1]));
  51809. if (defaultSansName.isEmpty())
  51810. Font::getPlatformDefaultFontNames (defaultSansName, defaultSerifName, defaultFixedName);
  51811. defaultSans = defaultSansName;
  51812. defaultSerif = defaultSerifName;
  51813. defaultFixed = defaultFixedName;
  51814. }
  51815. LookAndFeel::~LookAndFeel()
  51816. {
  51817. }
  51818. const Colour LookAndFeel::findColour (const int colourId) const throw()
  51819. {
  51820. const int index = colourIds.indexOf (colourId);
  51821. if (index >= 0)
  51822. return colours [index];
  51823. jassertfalse
  51824. return Colours::black;
  51825. }
  51826. void LookAndFeel::setColour (const int colourId, const Colour& colour) throw()
  51827. {
  51828. const int index = colourIds.indexOf (colourId);
  51829. if (index >= 0)
  51830. colours.set (index, colour);
  51831. colourIds.add (colourId);
  51832. colours.add (colour);
  51833. }
  51834. bool LookAndFeel::isColourSpecified (const int colourId) const throw()
  51835. {
  51836. return colourIds.contains (colourId);
  51837. }
  51838. static LookAndFeel* defaultLF = 0;
  51839. static LookAndFeel* currentDefaultLF = 0;
  51840. LookAndFeel& LookAndFeel::getDefaultLookAndFeel() throw()
  51841. {
  51842. // if this happens, your app hasn't initialised itself properly.. if you're
  51843. // trying to hack your own main() function, have a look at
  51844. // JUCEApplication::initialiseForGUI()
  51845. jassert (currentDefaultLF != 0);
  51846. return *currentDefaultLF;
  51847. }
  51848. void LookAndFeel::setDefaultLookAndFeel (LookAndFeel* newDefaultLookAndFeel) throw()
  51849. {
  51850. if (newDefaultLookAndFeel == 0)
  51851. {
  51852. if (defaultLF == 0)
  51853. defaultLF = new LookAndFeel();
  51854. newDefaultLookAndFeel = defaultLF;
  51855. }
  51856. currentDefaultLF = newDefaultLookAndFeel;
  51857. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  51858. {
  51859. Component* const c = Desktop::getInstance().getComponent (i);
  51860. if (c != 0)
  51861. c->sendLookAndFeelChange();
  51862. }
  51863. }
  51864. void LookAndFeel::clearDefaultLookAndFeel() throw()
  51865. {
  51866. if (currentDefaultLF == defaultLF)
  51867. currentDefaultLF = 0;
  51868. deleteAndZero (defaultLF);
  51869. }
  51870. const Typeface::Ptr LookAndFeel::getTypefaceForFont (const Font& font)
  51871. {
  51872. String faceName (font.getTypefaceName());
  51873. if (faceName == Font::getDefaultSansSerifFontName())
  51874. faceName = defaultSans;
  51875. else if (faceName == Font::getDefaultSerifFontName())
  51876. faceName = defaultSerif;
  51877. else if (faceName == Font::getDefaultMonospacedFontName())
  51878. faceName = defaultFixed;
  51879. Font f (font);
  51880. f.setTypefaceName (faceName);
  51881. return Typeface::createSystemTypefaceFor (f);
  51882. }
  51883. void LookAndFeel::setDefaultSansSerifTypefaceName (const String& newName)
  51884. {
  51885. defaultSans = newName;
  51886. }
  51887. const MouseCursor LookAndFeel::getMouseCursorFor (Component& component)
  51888. {
  51889. return component.getMouseCursor();
  51890. }
  51891. void LookAndFeel::drawButtonBackground (Graphics& g,
  51892. Button& button,
  51893. const Colour& backgroundColour,
  51894. bool isMouseOverButton,
  51895. bool isButtonDown)
  51896. {
  51897. const int width = button.getWidth();
  51898. const int height = button.getHeight();
  51899. const float outlineThickness = button.isEnabled() ? ((isButtonDown || isMouseOverButton) ? 1.2f : 0.7f) : 0.4f;
  51900. const float halfThickness = outlineThickness * 0.5f;
  51901. const float indentL = button.isConnectedOnLeft() ? 0.1f : halfThickness;
  51902. const float indentR = button.isConnectedOnRight() ? 0.1f : halfThickness;
  51903. const float indentT = button.isConnectedOnTop() ? 0.1f : halfThickness;
  51904. const float indentB = button.isConnectedOnBottom() ? 0.1f : halfThickness;
  51905. const Colour baseColour (createBaseColour (backgroundColour,
  51906. button.hasKeyboardFocus (true),
  51907. isMouseOverButton, isButtonDown)
  51908. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  51909. drawGlassLozenge (g,
  51910. indentL,
  51911. indentT,
  51912. width - indentL - indentR,
  51913. height - indentT - indentB,
  51914. baseColour, outlineThickness, -1.0f,
  51915. button.isConnectedOnLeft(),
  51916. button.isConnectedOnRight(),
  51917. button.isConnectedOnTop(),
  51918. button.isConnectedOnBottom());
  51919. }
  51920. const Font LookAndFeel::getFontForTextButton (TextButton& button)
  51921. {
  51922. return button.getFont();
  51923. }
  51924. void LookAndFeel::drawButtonText (Graphics& g, TextButton& button,
  51925. bool /*isMouseOverButton*/, bool /*isButtonDown*/)
  51926. {
  51927. Font font (getFontForTextButton (button));
  51928. g.setFont (font);
  51929. g.setColour (button.findColour (button.getToggleState() ? TextButton::textColourOnId
  51930. : TextButton::textColourOffId)
  51931. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  51932. const int yIndent = jmin (4, button.proportionOfHeight (0.3f));
  51933. const int cornerSize = jmin (button.getHeight(), button.getWidth()) / 2;
  51934. const int fontHeight = roundToInt (font.getHeight() * 0.6f);
  51935. const int leftIndent = jmin (fontHeight, 2 + cornerSize / (button.isConnectedOnLeft() ? 4 : 2));
  51936. const int rightIndent = jmin (fontHeight, 2 + cornerSize / (button.isConnectedOnRight() ? 4 : 2));
  51937. g.drawFittedText (button.getButtonText(),
  51938. leftIndent,
  51939. yIndent,
  51940. button.getWidth() - leftIndent - rightIndent,
  51941. button.getHeight() - yIndent * 2,
  51942. Justification::centred, 2);
  51943. }
  51944. void LookAndFeel::drawTickBox (Graphics& g,
  51945. Component& component,
  51946. float x, float y, float w, float h,
  51947. const bool ticked,
  51948. const bool isEnabled,
  51949. const bool isMouseOverButton,
  51950. const bool isButtonDown)
  51951. {
  51952. const float boxSize = w * 0.7f;
  51953. drawGlassSphere (g, x, y + (h - boxSize) * 0.5f, boxSize,
  51954. createBaseColour (component.findColour (TextButton::buttonColourId)
  51955. .withMultipliedAlpha (isEnabled ? 1.0f : 0.5f),
  51956. true,
  51957. isMouseOverButton,
  51958. isButtonDown),
  51959. isEnabled ? ((isButtonDown || isMouseOverButton) ? 1.1f : 0.5f) : 0.3f);
  51960. if (ticked)
  51961. {
  51962. Path tick;
  51963. tick.startNewSubPath (1.5f, 3.0f);
  51964. tick.lineTo (3.0f, 6.0f);
  51965. tick.lineTo (6.0f, 0.0f);
  51966. g.setColour (isEnabled ? Colours::black : Colours::grey);
  51967. const AffineTransform trans (AffineTransform::scale (w / 9.0f, h / 9.0f)
  51968. .translated (x, y));
  51969. g.strokePath (tick, PathStrokeType (2.5f), trans);
  51970. }
  51971. }
  51972. void LookAndFeel::drawToggleButton (Graphics& g,
  51973. ToggleButton& button,
  51974. bool isMouseOverButton,
  51975. bool isButtonDown)
  51976. {
  51977. if (button.hasKeyboardFocus (true))
  51978. {
  51979. g.setColour (button.findColour (TextEditor::focusedOutlineColourId));
  51980. g.drawRect (0, 0, button.getWidth(), button.getHeight());
  51981. }
  51982. float fontSize = jmin (15.0f, button.getHeight() * 0.75f);
  51983. const float tickWidth = fontSize * 1.1f;
  51984. drawTickBox (g, button, 4.0f, (button.getHeight() - tickWidth) * 0.5f,
  51985. tickWidth, tickWidth,
  51986. button.getToggleState(),
  51987. button.isEnabled(),
  51988. isMouseOverButton,
  51989. isButtonDown);
  51990. g.setColour (button.findColour (ToggleButton::textColourId));
  51991. g.setFont (fontSize);
  51992. if (! button.isEnabled())
  51993. g.setOpacity (0.5f);
  51994. const int textX = (int) tickWidth + 5;
  51995. g.drawFittedText (button.getButtonText(),
  51996. textX, 0,
  51997. button.getWidth() - textX - 2, button.getHeight(),
  51998. Justification::centredLeft, 10);
  51999. }
  52000. void LookAndFeel::changeToggleButtonWidthToFitText (ToggleButton& button)
  52001. {
  52002. Font font (jmin (15.0f, button.getHeight() * 0.6f));
  52003. const int tickWidth = jmin (24, button.getHeight());
  52004. button.setSize (font.getStringWidth (button.getButtonText()) + tickWidth + 8,
  52005. button.getHeight());
  52006. }
  52007. AlertWindow* LookAndFeel::createAlertWindow (const String& title,
  52008. const String& message,
  52009. const String& button1,
  52010. const String& button2,
  52011. const String& button3,
  52012. AlertWindow::AlertIconType iconType,
  52013. int numButtons,
  52014. Component* associatedComponent)
  52015. {
  52016. AlertWindow* aw = new AlertWindow (title, message, iconType, associatedComponent);
  52017. if (numButtons == 1)
  52018. {
  52019. aw->addButton (button1, 0,
  52020. KeyPress (KeyPress::escapeKey, 0, 0),
  52021. KeyPress (KeyPress::returnKey, 0, 0));
  52022. }
  52023. else
  52024. {
  52025. const KeyPress button1ShortCut (CharacterFunctions::toLowerCase (button1[0]), 0, 0);
  52026. KeyPress button2ShortCut (CharacterFunctions::toLowerCase (button2[0]), 0, 0);
  52027. if (button1ShortCut == button2ShortCut)
  52028. button2ShortCut = KeyPress();
  52029. if (numButtons == 2)
  52030. {
  52031. aw->addButton (button1, 1, KeyPress (KeyPress::returnKey, 0, 0), button1ShortCut);
  52032. aw->addButton (button2, 0, KeyPress (KeyPress::escapeKey, 0, 0), button2ShortCut);
  52033. }
  52034. else if (numButtons == 3)
  52035. {
  52036. aw->addButton (button1, 1, button1ShortCut);
  52037. aw->addButton (button2, 2, button2ShortCut);
  52038. aw->addButton (button3, 0, KeyPress (KeyPress::escapeKey, 0, 0));
  52039. }
  52040. }
  52041. return aw;
  52042. }
  52043. void LookAndFeel::drawAlertBox (Graphics& g,
  52044. AlertWindow& alert,
  52045. const Rectangle<int>& textArea,
  52046. TextLayout& textLayout)
  52047. {
  52048. g.fillAll (alert.findColour (AlertWindow::backgroundColourId));
  52049. int iconSpaceUsed = 0;
  52050. Justification alignment (Justification::horizontallyCentred);
  52051. const int iconWidth = 80;
  52052. int iconSize = jmin (iconWidth + 50, alert.getHeight() + 20);
  52053. if (alert.containsAnyExtraComponents() || alert.getNumButtons() > 2)
  52054. iconSize = jmin (iconSize, textArea.getHeight() + 50);
  52055. const Rectangle<int> iconRect (iconSize / -10, iconSize / -10,
  52056. iconSize, iconSize);
  52057. if (alert.getAlertType() != AlertWindow::NoIcon)
  52058. {
  52059. Path icon;
  52060. uint32 colour;
  52061. char character;
  52062. if (alert.getAlertType() == AlertWindow::WarningIcon)
  52063. {
  52064. colour = 0x55ff5555;
  52065. character = '!';
  52066. icon.addTriangle (iconRect.getX() + iconRect.getWidth() * 0.5f, (float) iconRect.getY(),
  52067. (float) iconRect.getRight(), (float) iconRect.getBottom(),
  52068. (float) iconRect.getX(), (float) iconRect.getBottom());
  52069. icon = icon.createPathWithRoundedCorners (5.0f);
  52070. }
  52071. else
  52072. {
  52073. colour = alert.getAlertType() == AlertWindow::InfoIcon ? 0x605555ff : 0x40b69900;
  52074. character = alert.getAlertType() == AlertWindow::InfoIcon ? 'i' : '?';
  52075. icon.addEllipse ((float) iconRect.getX(), (float) iconRect.getY(),
  52076. (float) iconRect.getWidth(), (float) iconRect.getHeight());
  52077. }
  52078. GlyphArrangement ga;
  52079. ga.addFittedText (Font (iconRect.getHeight() * 0.9f, Font::bold),
  52080. String::charToString (character),
  52081. (float) iconRect.getX(), (float) iconRect.getY(),
  52082. (float) iconRect.getWidth(), (float) iconRect.getHeight(),
  52083. Justification::centred, false);
  52084. ga.createPath (icon);
  52085. icon.setUsingNonZeroWinding (false);
  52086. g.setColour (Colour (colour));
  52087. g.fillPath (icon);
  52088. iconSpaceUsed = iconWidth;
  52089. alignment = Justification::left;
  52090. }
  52091. g.setColour (alert.findColour (AlertWindow::textColourId));
  52092. textLayout.drawWithin (g,
  52093. textArea.getX() + iconSpaceUsed, textArea.getY(),
  52094. textArea.getWidth() - iconSpaceUsed, textArea.getHeight(),
  52095. alignment.getFlags() | Justification::top);
  52096. g.setColour (alert.findColour (AlertWindow::outlineColourId));
  52097. g.drawRect (0, 0, alert.getWidth(), alert.getHeight());
  52098. }
  52099. int LookAndFeel::getAlertBoxWindowFlags()
  52100. {
  52101. return ComponentPeer::windowAppearsOnTaskbar
  52102. | ComponentPeer::windowHasDropShadow;
  52103. }
  52104. int LookAndFeel::getAlertWindowButtonHeight()
  52105. {
  52106. return 28;
  52107. }
  52108. const Font LookAndFeel::getAlertWindowFont()
  52109. {
  52110. return Font (12.0f);
  52111. }
  52112. void LookAndFeel::drawProgressBar (Graphics& g, ProgressBar& progressBar,
  52113. int width, int height,
  52114. double progress, const String& textToShow)
  52115. {
  52116. const Colour background (progressBar.findColour (ProgressBar::backgroundColourId));
  52117. const Colour foreground (progressBar.findColour (ProgressBar::foregroundColourId));
  52118. g.fillAll (background);
  52119. if (progress >= 0.0f && progress < 1.0f)
  52120. {
  52121. drawGlassLozenge (g, 1.0f, 1.0f,
  52122. (float) jlimit (0.0, width - 2.0, progress * (width - 2.0)),
  52123. (float) (height - 2),
  52124. foreground,
  52125. 0.5f, 0.0f,
  52126. true, true, true, true);
  52127. }
  52128. else
  52129. {
  52130. // spinning bar..
  52131. g.setColour (foreground);
  52132. const int stripeWidth = height * 2;
  52133. const int position = (Time::getMillisecondCounter() / 15) % stripeWidth;
  52134. Path p;
  52135. for (float x = (float) (- position); x < width + stripeWidth; x += stripeWidth)
  52136. p.addQuadrilateral (x, 0.0f,
  52137. x + stripeWidth * 0.5f, 0.0f,
  52138. x, (float) height,
  52139. x - stripeWidth * 0.5f, (float) height);
  52140. Image im (Image::ARGB, width, height, true);
  52141. {
  52142. Graphics g2 (im);
  52143. drawGlassLozenge (g2, 1.0f, 1.0f,
  52144. (float) (width - 2),
  52145. (float) (height - 2),
  52146. foreground,
  52147. 0.5f, 0.0f,
  52148. true, true, true, true);
  52149. }
  52150. g.setTiledImageFill (im, 0, 0, 0.85f);
  52151. g.fillPath (p);
  52152. }
  52153. if (textToShow.isNotEmpty())
  52154. {
  52155. g.setColour (Colour::contrasting (background, foreground));
  52156. g.setFont (height * 0.6f);
  52157. g.drawText (textToShow, 0, 0, width, height, Justification::centred, false);
  52158. }
  52159. }
  52160. void LookAndFeel::drawSpinningWaitAnimation (Graphics& g, const Colour& colour, int x, int y, int w, int h)
  52161. {
  52162. const float radius = jmin (w, h) * 0.4f;
  52163. const float thickness = radius * 0.15f;
  52164. Path p;
  52165. p.addRoundedRectangle (radius * 0.4f, thickness * -0.5f,
  52166. radius * 0.6f, thickness,
  52167. thickness * 0.5f);
  52168. const float cx = x + w * 0.5f;
  52169. const float cy = y + h * 0.5f;
  52170. const uint32 animationIndex = (Time::getMillisecondCounter() / (1000 / 10)) % 12;
  52171. for (int i = 0; i < 12; ++i)
  52172. {
  52173. const int n = (i + 12 - animationIndex) % 12;
  52174. g.setColour (colour.withMultipliedAlpha ((n + 1) / 12.0f));
  52175. g.fillPath (p, AffineTransform::rotation (i * (float_Pi / 6.0f))
  52176. .translated (cx, cy));
  52177. }
  52178. }
  52179. void LookAndFeel::drawScrollbarButton (Graphics& g,
  52180. ScrollBar& scrollbar,
  52181. int width, int height,
  52182. int buttonDirection,
  52183. bool /*isScrollbarVertical*/,
  52184. bool /*isMouseOverButton*/,
  52185. bool isButtonDown)
  52186. {
  52187. Path p;
  52188. if (buttonDirection == 0)
  52189. p.addTriangle (width * 0.5f, height * 0.2f,
  52190. width * 0.1f, height * 0.7f,
  52191. width * 0.9f, height * 0.7f);
  52192. else if (buttonDirection == 1)
  52193. p.addTriangle (width * 0.8f, height * 0.5f,
  52194. width * 0.3f, height * 0.1f,
  52195. width * 0.3f, height * 0.9f);
  52196. else if (buttonDirection == 2)
  52197. p.addTriangle (width * 0.5f, height * 0.8f,
  52198. width * 0.1f, height * 0.3f,
  52199. width * 0.9f, height * 0.3f);
  52200. else if (buttonDirection == 3)
  52201. p.addTriangle (width * 0.2f, height * 0.5f,
  52202. width * 0.7f, height * 0.1f,
  52203. width * 0.7f, height * 0.9f);
  52204. if (isButtonDown)
  52205. g.setColour (scrollbar.findColour (ScrollBar::thumbColourId).contrasting (0.2f));
  52206. else
  52207. g.setColour (scrollbar.findColour (ScrollBar::thumbColourId));
  52208. g.fillPath (p);
  52209. g.setColour (Colour (0x80000000));
  52210. g.strokePath (p, PathStrokeType (0.5f));
  52211. }
  52212. void LookAndFeel::drawScrollbar (Graphics& g,
  52213. ScrollBar& scrollbar,
  52214. int x, int y,
  52215. int width, int height,
  52216. bool isScrollbarVertical,
  52217. int thumbStartPosition,
  52218. int thumbSize,
  52219. bool /*isMouseOver*/,
  52220. bool /*isMouseDown*/)
  52221. {
  52222. g.fillAll (scrollbar.findColour (ScrollBar::backgroundColourId));
  52223. Path slotPath, thumbPath;
  52224. const float slotIndent = jmin (width, height) > 15 ? 1.0f : 0.0f;
  52225. const float slotIndentx2 = slotIndent * 2.0f;
  52226. const float thumbIndent = slotIndent + 1.0f;
  52227. const float thumbIndentx2 = thumbIndent * 2.0f;
  52228. float gx1 = 0.0f, gy1 = 0.0f, gx2 = 0.0f, gy2 = 0.0f;
  52229. if (isScrollbarVertical)
  52230. {
  52231. slotPath.addRoundedRectangle (x + slotIndent,
  52232. y + slotIndent,
  52233. width - slotIndentx2,
  52234. height - slotIndentx2,
  52235. (width - slotIndentx2) * 0.5f);
  52236. if (thumbSize > 0)
  52237. thumbPath.addRoundedRectangle (x + thumbIndent,
  52238. thumbStartPosition + thumbIndent,
  52239. width - thumbIndentx2,
  52240. thumbSize - thumbIndentx2,
  52241. (width - thumbIndentx2) * 0.5f);
  52242. gx1 = (float) x;
  52243. gx2 = x + width * 0.7f;
  52244. }
  52245. else
  52246. {
  52247. slotPath.addRoundedRectangle (x + slotIndent,
  52248. y + slotIndent,
  52249. width - slotIndentx2,
  52250. height - slotIndentx2,
  52251. (height - slotIndentx2) * 0.5f);
  52252. if (thumbSize > 0)
  52253. thumbPath.addRoundedRectangle (thumbStartPosition + thumbIndent,
  52254. y + thumbIndent,
  52255. thumbSize - thumbIndentx2,
  52256. height - thumbIndentx2,
  52257. (height - thumbIndentx2) * 0.5f);
  52258. gy1 = (float) y;
  52259. gy2 = y + height * 0.7f;
  52260. }
  52261. const Colour thumbColour (scrollbar.findColour (ScrollBar::thumbColourId));
  52262. g.setGradientFill (ColourGradient (thumbColour.overlaidWith (Colour (0x44000000)), gx1, gy1,
  52263. thumbColour.overlaidWith (Colour (0x19000000)), gx2, gy2, false));
  52264. g.fillPath (slotPath);
  52265. if (isScrollbarVertical)
  52266. {
  52267. gx1 = x + width * 0.6f;
  52268. gx2 = (float) x + width;
  52269. }
  52270. else
  52271. {
  52272. gy1 = y + height * 0.6f;
  52273. gy2 = (float) y + height;
  52274. }
  52275. g.setGradientFill (ColourGradient (Colours::transparentBlack,gx1, gy1,
  52276. Colour (0x19000000), gx2, gy2, false));
  52277. g.fillPath (slotPath);
  52278. g.setColour (thumbColour);
  52279. g.fillPath (thumbPath);
  52280. g.setGradientFill (ColourGradient (Colour (0x10000000), gx1, gy1,
  52281. Colours::transparentBlack, gx2, gy2, false));
  52282. g.saveState();
  52283. if (isScrollbarVertical)
  52284. g.reduceClipRegion (x + width / 2, y, width, height);
  52285. else
  52286. g.reduceClipRegion (x, y + height / 2, width, height);
  52287. g.fillPath (thumbPath);
  52288. g.restoreState();
  52289. g.setColour (Colour (0x4c000000));
  52290. g.strokePath (thumbPath, PathStrokeType (0.4f));
  52291. }
  52292. ImageEffectFilter* LookAndFeel::getScrollbarEffect()
  52293. {
  52294. return 0;
  52295. }
  52296. int LookAndFeel::getMinimumScrollbarThumbSize (ScrollBar& scrollbar)
  52297. {
  52298. return jmin (scrollbar.getWidth(), scrollbar.getHeight()) * 2;
  52299. }
  52300. int LookAndFeel::getDefaultScrollbarWidth()
  52301. {
  52302. return 18;
  52303. }
  52304. int LookAndFeel::getScrollbarButtonSize (ScrollBar& scrollbar)
  52305. {
  52306. return 2 + (scrollbar.isVertical() ? scrollbar.getWidth()
  52307. : scrollbar.getHeight());
  52308. }
  52309. const Path LookAndFeel::getTickShape (const float height)
  52310. {
  52311. static const unsigned char tickShapeData[] =
  52312. {
  52313. 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,
  52314. 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,
  52315. 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,
  52316. 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,
  52317. 96,140,68,0,128,188,67,0,224,168,68,0,0,119,67,99,101
  52318. };
  52319. Path p;
  52320. p.loadPathFromData (tickShapeData, sizeof (tickShapeData));
  52321. p.scaleToFit (0, 0, height * 2.0f, height, true);
  52322. return p;
  52323. }
  52324. const Path LookAndFeel::getCrossShape (const float height)
  52325. {
  52326. static const unsigned char crossShapeData[] =
  52327. {
  52328. 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,
  52329. 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,
  52330. 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,
  52331. 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,
  52332. 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,
  52333. 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,
  52334. 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
  52335. };
  52336. Path p;
  52337. p.loadPathFromData (crossShapeData, sizeof (crossShapeData));
  52338. p.scaleToFit (0, 0, height * 2.0f, height, true);
  52339. return p;
  52340. }
  52341. void LookAndFeel::drawTreeviewPlusMinusBox (Graphics& g, int x, int y, int w, int h, bool isPlus, bool /*isMouseOver*/)
  52342. {
  52343. const int boxSize = ((jmin (16, w, h) << 1) / 3) | 1;
  52344. x += (w - boxSize) >> 1;
  52345. y += (h - boxSize) >> 1;
  52346. w = boxSize;
  52347. h = boxSize;
  52348. g.setColour (Colour (0xe5ffffff));
  52349. g.fillRect (x, y, w, h);
  52350. g.setColour (Colour (0x80000000));
  52351. g.drawRect (x, y, w, h);
  52352. const float size = boxSize / 2 + 1.0f;
  52353. const float centre = (float) (boxSize / 2);
  52354. g.fillRect (x + (w - size) * 0.5f, y + centre, size, 1.0f);
  52355. if (isPlus)
  52356. g.fillRect (x + centre, y + (h - size) * 0.5f, 1.0f, size);
  52357. }
  52358. void LookAndFeel::drawBubble (Graphics& g,
  52359. float tipX, float tipY,
  52360. float boxX, float boxY,
  52361. float boxW, float boxH)
  52362. {
  52363. int side = 0;
  52364. if (tipX < boxX)
  52365. side = 1;
  52366. else if (tipX > boxX + boxW)
  52367. side = 3;
  52368. else if (tipY > boxY + boxH)
  52369. side = 2;
  52370. const float indent = 2.0f;
  52371. Path p;
  52372. p.addBubble (boxX + indent,
  52373. boxY + indent,
  52374. boxW - indent * 2.0f,
  52375. boxH - indent * 2.0f,
  52376. 5.0f,
  52377. tipX, tipY,
  52378. side,
  52379. 0.5f,
  52380. jmin (15.0f, boxW * 0.3f, boxH * 0.3f));
  52381. //xxx need to take comp as param for colour
  52382. g.setColour (findColour (TooltipWindow::backgroundColourId).withAlpha (0.9f));
  52383. g.fillPath (p);
  52384. //xxx as above
  52385. g.setColour (findColour (TooltipWindow::textColourId).withAlpha (0.4f));
  52386. g.strokePath (p, PathStrokeType (1.33f));
  52387. }
  52388. const Font LookAndFeel::getPopupMenuFont()
  52389. {
  52390. return Font (17.0f);
  52391. }
  52392. void LookAndFeel::getIdealPopupMenuItemSize (const String& text,
  52393. const bool isSeparator,
  52394. int standardMenuItemHeight,
  52395. int& idealWidth,
  52396. int& idealHeight)
  52397. {
  52398. if (isSeparator)
  52399. {
  52400. idealWidth = 50;
  52401. idealHeight = standardMenuItemHeight > 0 ? standardMenuItemHeight / 2 : 10;
  52402. }
  52403. else
  52404. {
  52405. Font font (getPopupMenuFont());
  52406. if (standardMenuItemHeight > 0 && font.getHeight() > standardMenuItemHeight / 1.3f)
  52407. font.setHeight (standardMenuItemHeight / 1.3f);
  52408. idealHeight = standardMenuItemHeight > 0 ? standardMenuItemHeight : roundToInt (font.getHeight() * 1.3f);
  52409. idealWidth = font.getStringWidth (text) + idealHeight * 2;
  52410. }
  52411. }
  52412. void LookAndFeel::drawPopupMenuBackground (Graphics& g, int width, int height)
  52413. {
  52414. const Colour background (findColour (PopupMenu::backgroundColourId));
  52415. g.fillAll (background);
  52416. g.setColour (background.overlaidWith (Colour (0x2badd8e6)));
  52417. for (int i = 0; i < height; i += 3)
  52418. g.fillRect (0, i, width, 1);
  52419. #if ! JUCE_MAC
  52420. g.setColour (findColour (PopupMenu::textColourId).withAlpha (0.6f));
  52421. g.drawRect (0, 0, width, height);
  52422. #endif
  52423. }
  52424. void LookAndFeel::drawPopupMenuUpDownArrow (Graphics& g,
  52425. int width, int height,
  52426. bool isScrollUpArrow)
  52427. {
  52428. const Colour background (findColour (PopupMenu::backgroundColourId));
  52429. g.setGradientFill (ColourGradient (background, 0.0f, height * 0.5f,
  52430. background.withAlpha (0.0f),
  52431. 0.0f, isScrollUpArrow ? ((float) height) : 0.0f,
  52432. false));
  52433. g.fillRect (1, 1, width - 2, height - 2);
  52434. const float hw = width * 0.5f;
  52435. const float arrowW = height * 0.3f;
  52436. const float y1 = height * (isScrollUpArrow ? 0.6f : 0.3f);
  52437. const float y2 = height * (isScrollUpArrow ? 0.3f : 0.6f);
  52438. Path p;
  52439. p.addTriangle (hw - arrowW, y1,
  52440. hw + arrowW, y1,
  52441. hw, y2);
  52442. g.setColour (findColour (PopupMenu::textColourId).withAlpha (0.5f));
  52443. g.fillPath (p);
  52444. }
  52445. void LookAndFeel::drawPopupMenuItem (Graphics& g,
  52446. int width, int height,
  52447. const bool isSeparator,
  52448. const bool isActive,
  52449. const bool isHighlighted,
  52450. const bool isTicked,
  52451. const bool hasSubMenu,
  52452. const String& text,
  52453. const String& shortcutKeyText,
  52454. Image* image,
  52455. const Colour* const textColourToUse)
  52456. {
  52457. const float halfH = height * 0.5f;
  52458. if (isSeparator)
  52459. {
  52460. const float separatorIndent = 5.5f;
  52461. g.setColour (Colour (0x33000000));
  52462. g.drawLine (separatorIndent, halfH, width - separatorIndent, halfH);
  52463. g.setColour (Colour (0x66ffffff));
  52464. g.drawLine (separatorIndent, halfH + 1.0f, width - separatorIndent, halfH + 1.0f);
  52465. }
  52466. else
  52467. {
  52468. Colour textColour (findColour (PopupMenu::textColourId));
  52469. if (textColourToUse != 0)
  52470. textColour = *textColourToUse;
  52471. if (isHighlighted)
  52472. {
  52473. g.setColour (findColour (PopupMenu::highlightedBackgroundColourId));
  52474. g.fillRect (1, 1, width - 2, height - 2);
  52475. g.setColour (findColour (PopupMenu::highlightedTextColourId));
  52476. }
  52477. else
  52478. {
  52479. g.setColour (textColour);
  52480. }
  52481. if (! isActive)
  52482. g.setOpacity (0.3f);
  52483. Font font (getPopupMenuFont());
  52484. if (font.getHeight() > height / 1.3f)
  52485. font.setHeight (height / 1.3f);
  52486. g.setFont (font);
  52487. const int leftBorder = (height * 5) / 4;
  52488. const int rightBorder = 4;
  52489. if (image != 0)
  52490. {
  52491. g.drawImageWithin (image,
  52492. 2, 1, leftBorder - 4, height - 2,
  52493. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize, false);
  52494. }
  52495. else if (isTicked)
  52496. {
  52497. const Path tick (getTickShape (1.0f));
  52498. const float th = font.getAscent();
  52499. const float ty = halfH - th * 0.5f;
  52500. g.fillPath (tick, tick.getTransformToScaleToFit (2.0f, ty, (float) (leftBorder - 4),
  52501. th, true));
  52502. }
  52503. g.drawFittedText (text,
  52504. leftBorder, 0,
  52505. width - (leftBorder + rightBorder), height,
  52506. Justification::centredLeft, 1);
  52507. if (shortcutKeyText.isNotEmpty())
  52508. {
  52509. Font f2 (font);
  52510. f2.setHeight (f2.getHeight() * 0.75f);
  52511. f2.setHorizontalScale (0.95f);
  52512. g.setFont (f2);
  52513. g.drawText (shortcutKeyText,
  52514. leftBorder,
  52515. 0,
  52516. width - (leftBorder + rightBorder + 4),
  52517. height,
  52518. Justification::centredRight,
  52519. true);
  52520. }
  52521. if (hasSubMenu)
  52522. {
  52523. const float arrowH = 0.6f * getPopupMenuFont().getAscent();
  52524. const float x = width - height * 0.6f;
  52525. Path p;
  52526. p.addTriangle (x, halfH - arrowH * 0.5f,
  52527. x, halfH + arrowH * 0.5f,
  52528. x + arrowH * 0.6f, halfH);
  52529. g.fillPath (p);
  52530. }
  52531. }
  52532. }
  52533. int LookAndFeel::getMenuWindowFlags()
  52534. {
  52535. return ComponentPeer::windowHasDropShadow;
  52536. }
  52537. void LookAndFeel::drawMenuBarBackground (Graphics& g, int width, int height,
  52538. bool, MenuBarComponent& menuBar)
  52539. {
  52540. const Colour baseColour (createBaseColour (menuBar.findColour (PopupMenu::backgroundColourId), false, false, false));
  52541. if (menuBar.isEnabled())
  52542. {
  52543. drawShinyButtonShape (g,
  52544. -4.0f, 0.0f,
  52545. width + 8.0f, (float) height,
  52546. 0.0f,
  52547. baseColour,
  52548. 0.4f,
  52549. true, true, true, true);
  52550. }
  52551. else
  52552. {
  52553. g.fillAll (baseColour);
  52554. }
  52555. }
  52556. const Font LookAndFeel::getMenuBarFont (MenuBarComponent& menuBar, int /*itemIndex*/, const String& /*itemText*/)
  52557. {
  52558. return Font (menuBar.getHeight() * 0.7f);
  52559. }
  52560. int LookAndFeel::getMenuBarItemWidth (MenuBarComponent& menuBar, int itemIndex, const String& itemText)
  52561. {
  52562. return getMenuBarFont (menuBar, itemIndex, itemText)
  52563. .getStringWidth (itemText) + menuBar.getHeight();
  52564. }
  52565. void LookAndFeel::drawMenuBarItem (Graphics& g,
  52566. int width, int height,
  52567. int itemIndex,
  52568. const String& itemText,
  52569. bool isMouseOverItem,
  52570. bool isMenuOpen,
  52571. bool /*isMouseOverBar*/,
  52572. MenuBarComponent& menuBar)
  52573. {
  52574. if (! menuBar.isEnabled())
  52575. {
  52576. g.setColour (menuBar.findColour (PopupMenu::textColourId)
  52577. .withMultipliedAlpha (0.5f));
  52578. }
  52579. else if (isMenuOpen || isMouseOverItem)
  52580. {
  52581. g.fillAll (menuBar.findColour (PopupMenu::highlightedBackgroundColourId));
  52582. g.setColour (menuBar.findColour (PopupMenu::highlightedTextColourId));
  52583. }
  52584. else
  52585. {
  52586. g.setColour (menuBar.findColour (PopupMenu::textColourId));
  52587. }
  52588. g.setFont (getMenuBarFont (menuBar, itemIndex, itemText));
  52589. g.drawFittedText (itemText, 0, 0, width, height, Justification::centred, 1);
  52590. }
  52591. void LookAndFeel::fillTextEditorBackground (Graphics& g, int /*width*/, int /*height*/,
  52592. TextEditor& textEditor)
  52593. {
  52594. g.fillAll (textEditor.findColour (TextEditor::backgroundColourId));
  52595. }
  52596. void LookAndFeel::drawTextEditorOutline (Graphics& g, int width, int height, TextEditor& textEditor)
  52597. {
  52598. if (textEditor.isEnabled())
  52599. {
  52600. if (textEditor.hasKeyboardFocus (true) && ! textEditor.isReadOnly())
  52601. {
  52602. const int border = 2;
  52603. g.setColour (textEditor.findColour (TextEditor::focusedOutlineColourId));
  52604. g.drawRect (0, 0, width, height, border);
  52605. g.setOpacity (1.0f);
  52606. const Colour shadowColour (textEditor.findColour (TextEditor::shadowColourId).withMultipliedAlpha (0.75f));
  52607. g.drawBevel (0, 0, width, height + 2, border + 2, shadowColour, shadowColour);
  52608. }
  52609. else
  52610. {
  52611. g.setColour (textEditor.findColour (TextEditor::outlineColourId));
  52612. g.drawRect (0, 0, width, height);
  52613. g.setOpacity (1.0f);
  52614. const Colour shadowColour (textEditor.findColour (TextEditor::shadowColourId));
  52615. g.drawBevel (0, 0, width, height + 2, 3, shadowColour, shadowColour);
  52616. }
  52617. }
  52618. }
  52619. void LookAndFeel::drawComboBox (Graphics& g, int width, int height,
  52620. const bool isButtonDown,
  52621. int buttonX, int buttonY,
  52622. int buttonW, int buttonH,
  52623. ComboBox& box)
  52624. {
  52625. g.fillAll (box.findColour (ComboBox::backgroundColourId));
  52626. if (box.isEnabled() && box.hasKeyboardFocus (false))
  52627. {
  52628. g.setColour (box.findColour (TextButton::buttonColourId));
  52629. g.drawRect (0, 0, width, height, 2);
  52630. }
  52631. else
  52632. {
  52633. g.setColour (box.findColour (ComboBox::outlineColourId));
  52634. g.drawRect (0, 0, width, height);
  52635. }
  52636. const float outlineThickness = box.isEnabled() ? (isButtonDown ? 1.2f : 0.5f) : 0.3f;
  52637. const Colour baseColour (createBaseColour (box.findColour (ComboBox::buttonColourId),
  52638. box.hasKeyboardFocus (true),
  52639. false, isButtonDown)
  52640. .withMultipliedAlpha (box.isEnabled() ? 1.0f : 0.5f));
  52641. drawGlassLozenge (g,
  52642. buttonX + outlineThickness, buttonY + outlineThickness,
  52643. buttonW - outlineThickness * 2.0f, buttonH - outlineThickness * 2.0f,
  52644. baseColour, outlineThickness, -1.0f,
  52645. true, true, true, true);
  52646. if (box.isEnabled())
  52647. {
  52648. const float arrowX = 0.3f;
  52649. const float arrowH = 0.2f;
  52650. Path p;
  52651. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.45f - arrowH),
  52652. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.45f,
  52653. buttonX + buttonW * arrowX, buttonY + buttonH * 0.45f);
  52654. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.55f + arrowH),
  52655. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.55f,
  52656. buttonX + buttonW * arrowX, buttonY + buttonH * 0.55f);
  52657. g.setColour (box.findColour (ComboBox::arrowColourId));
  52658. g.fillPath (p);
  52659. }
  52660. }
  52661. const Font LookAndFeel::getComboBoxFont (ComboBox& box)
  52662. {
  52663. return Font (jmin (15.0f, box.getHeight() * 0.85f));
  52664. }
  52665. Label* LookAndFeel::createComboBoxTextBox (ComboBox&)
  52666. {
  52667. return new Label (String::empty, String::empty);
  52668. }
  52669. void LookAndFeel::positionComboBoxText (ComboBox& box, Label& label)
  52670. {
  52671. label.setBounds (1, 1,
  52672. box.getWidth() + 3 - box.getHeight(),
  52673. box.getHeight() - 2);
  52674. label.setFont (getComboBoxFont (box));
  52675. }
  52676. void LookAndFeel::drawLabel (Graphics& g, Label& label)
  52677. {
  52678. g.fillAll (label.findColour (Label::backgroundColourId));
  52679. if (! label.isBeingEdited())
  52680. {
  52681. const float alpha = label.isEnabled() ? 1.0f : 0.5f;
  52682. g.setColour (label.findColour (Label::textColourId).withMultipliedAlpha (alpha));
  52683. g.setFont (label.getFont());
  52684. g.drawFittedText (label.getText(),
  52685. label.getHorizontalBorderSize(),
  52686. label.getVerticalBorderSize(),
  52687. label.getWidth() - 2 * label.getHorizontalBorderSize(),
  52688. label.getHeight() - 2 * label.getVerticalBorderSize(),
  52689. label.getJustificationType(),
  52690. jmax (1, (int) (label.getHeight() / label.getFont().getHeight())),
  52691. label.getMinimumHorizontalScale());
  52692. g.setColour (label.findColour (Label::outlineColourId).withMultipliedAlpha (alpha));
  52693. g.drawRect (0, 0, label.getWidth(), label.getHeight());
  52694. }
  52695. else if (label.isEnabled())
  52696. {
  52697. g.setColour (label.findColour (Label::outlineColourId));
  52698. g.drawRect (0, 0, label.getWidth(), label.getHeight());
  52699. }
  52700. }
  52701. void LookAndFeel::drawLinearSliderBackground (Graphics& g,
  52702. int x, int y,
  52703. int width, int height,
  52704. float /*sliderPos*/,
  52705. float /*minSliderPos*/,
  52706. float /*maxSliderPos*/,
  52707. const Slider::SliderStyle /*style*/,
  52708. Slider& slider)
  52709. {
  52710. const float sliderRadius = (float) (getSliderThumbRadius (slider) - 2);
  52711. const Colour trackColour (slider.findColour (Slider::trackColourId));
  52712. const Colour gradCol1 (trackColour.overlaidWith (Colours::black.withAlpha (slider.isEnabled() ? 0.25f : 0.13f)));
  52713. const Colour gradCol2 (trackColour.overlaidWith (Colour (0x14000000)));
  52714. Path indent;
  52715. if (slider.isHorizontal())
  52716. {
  52717. const float iy = y + height * 0.5f - sliderRadius * 0.5f;
  52718. const float ih = sliderRadius;
  52719. g.setGradientFill (ColourGradient (gradCol1, 0.0f, iy,
  52720. gradCol2, 0.0f, iy + ih, false));
  52721. indent.addRoundedRectangle (x - sliderRadius * 0.5f, iy,
  52722. width + sliderRadius, ih,
  52723. 5.0f);
  52724. g.fillPath (indent);
  52725. }
  52726. else
  52727. {
  52728. const float ix = x + width * 0.5f - sliderRadius * 0.5f;
  52729. const float iw = sliderRadius;
  52730. g.setGradientFill (ColourGradient (gradCol1, ix, 0.0f,
  52731. gradCol2, ix + iw, 0.0f, false));
  52732. indent.addRoundedRectangle (ix, y - sliderRadius * 0.5f,
  52733. iw, height + sliderRadius,
  52734. 5.0f);
  52735. g.fillPath (indent);
  52736. }
  52737. g.setColour (Colour (0x4c000000));
  52738. g.strokePath (indent, PathStrokeType (0.5f));
  52739. }
  52740. void LookAndFeel::drawLinearSliderThumb (Graphics& g,
  52741. int x, int y,
  52742. int width, int height,
  52743. float sliderPos,
  52744. float minSliderPos,
  52745. float maxSliderPos,
  52746. const Slider::SliderStyle style,
  52747. Slider& slider)
  52748. {
  52749. const float sliderRadius = (float) (getSliderThumbRadius (slider) - 2);
  52750. Colour knobColour (createBaseColour (slider.findColour (Slider::thumbColourId),
  52751. slider.hasKeyboardFocus (false) && slider.isEnabled(),
  52752. slider.isMouseOverOrDragging() && slider.isEnabled(),
  52753. slider.isMouseButtonDown() && slider.isEnabled()));
  52754. const float outlineThickness = slider.isEnabled() ? 0.8f : 0.3f;
  52755. if (style == Slider::LinearHorizontal || style == Slider::LinearVertical)
  52756. {
  52757. float kx, ky;
  52758. if (style == Slider::LinearVertical)
  52759. {
  52760. kx = x + width * 0.5f;
  52761. ky = sliderPos;
  52762. }
  52763. else
  52764. {
  52765. kx = sliderPos;
  52766. ky = y + height * 0.5f;
  52767. }
  52768. drawGlassSphere (g,
  52769. kx - sliderRadius,
  52770. ky - sliderRadius,
  52771. sliderRadius * 2.0f,
  52772. knobColour, outlineThickness);
  52773. }
  52774. else
  52775. {
  52776. if (style == Slider::ThreeValueVertical)
  52777. {
  52778. drawGlassSphere (g, x + width * 0.5f - sliderRadius,
  52779. sliderPos - sliderRadius,
  52780. sliderRadius * 2.0f,
  52781. knobColour, outlineThickness);
  52782. }
  52783. else if (style == Slider::ThreeValueHorizontal)
  52784. {
  52785. drawGlassSphere (g,sliderPos - sliderRadius,
  52786. y + height * 0.5f - sliderRadius,
  52787. sliderRadius * 2.0f,
  52788. knobColour, outlineThickness);
  52789. }
  52790. if (style == Slider::TwoValueVertical || style == Slider::ThreeValueVertical)
  52791. {
  52792. const float sr = jmin (sliderRadius, width * 0.4f);
  52793. drawGlassPointer (g, jmax (0.0f, x + width * 0.5f - sliderRadius * 2.0f),
  52794. minSliderPos - sliderRadius,
  52795. sliderRadius * 2.0f, knobColour, outlineThickness, 1);
  52796. drawGlassPointer (g, jmin (x + width - sliderRadius * 2.0f, x + width * 0.5f), maxSliderPos - sr,
  52797. sliderRadius * 2.0f, knobColour, outlineThickness, 3);
  52798. }
  52799. else if (style == Slider::TwoValueHorizontal || style == Slider::ThreeValueHorizontal)
  52800. {
  52801. const float sr = jmin (sliderRadius, height * 0.4f);
  52802. drawGlassPointer (g, minSliderPos - sr,
  52803. jmax (0.0f, y + height * 0.5f - sliderRadius * 2.0f),
  52804. sliderRadius * 2.0f, knobColour, outlineThickness, 2);
  52805. drawGlassPointer (g, maxSliderPos - sliderRadius,
  52806. jmin (y + height - sliderRadius * 2.0f, y + height * 0.5f),
  52807. sliderRadius * 2.0f, knobColour, outlineThickness, 4);
  52808. }
  52809. }
  52810. }
  52811. void LookAndFeel::drawLinearSlider (Graphics& g,
  52812. int x, int y,
  52813. int width, int height,
  52814. float sliderPos,
  52815. float minSliderPos,
  52816. float maxSliderPos,
  52817. const Slider::SliderStyle style,
  52818. Slider& slider)
  52819. {
  52820. g.fillAll (slider.findColour (Slider::backgroundColourId));
  52821. if (style == Slider::LinearBar)
  52822. {
  52823. const bool isMouseOver = slider.isMouseOverOrDragging() && slider.isEnabled();
  52824. Colour baseColour (createBaseColour (slider.findColour (Slider::thumbColourId)
  52825. .withMultipliedSaturation (slider.isEnabled() ? 1.0f : 0.5f),
  52826. false,
  52827. isMouseOver,
  52828. isMouseOver || slider.isMouseButtonDown()));
  52829. drawShinyButtonShape (g,
  52830. (float) x, (float) y, sliderPos - (float) x, (float) height, 0.0f,
  52831. baseColour,
  52832. slider.isEnabled() ? 0.9f : 0.3f,
  52833. true, true, true, true);
  52834. }
  52835. else
  52836. {
  52837. drawLinearSliderBackground (g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
  52838. drawLinearSliderThumb (g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
  52839. }
  52840. }
  52841. int LookAndFeel::getSliderThumbRadius (Slider& slider)
  52842. {
  52843. return jmin (7,
  52844. slider.getHeight() / 2,
  52845. slider.getWidth() / 2) + 2;
  52846. }
  52847. void LookAndFeel::drawRotarySlider (Graphics& g,
  52848. int x, int y,
  52849. int width, int height,
  52850. float sliderPos,
  52851. const float rotaryStartAngle,
  52852. const float rotaryEndAngle,
  52853. Slider& slider)
  52854. {
  52855. const float radius = jmin (width / 2, height / 2) - 2.0f;
  52856. const float centreX = x + width * 0.5f;
  52857. const float centreY = y + height * 0.5f;
  52858. const float rx = centreX - radius;
  52859. const float ry = centreY - radius;
  52860. const float rw = radius * 2.0f;
  52861. const float angle = rotaryStartAngle + sliderPos * (rotaryEndAngle - rotaryStartAngle);
  52862. const bool isMouseOver = slider.isMouseOverOrDragging() && slider.isEnabled();
  52863. if (radius > 12.0f)
  52864. {
  52865. if (slider.isEnabled())
  52866. g.setColour (slider.findColour (Slider::rotarySliderFillColourId).withAlpha (isMouseOver ? 1.0f : 0.7f));
  52867. else
  52868. g.setColour (Colour (0x80808080));
  52869. const float thickness = 0.7f;
  52870. {
  52871. Path filledArc;
  52872. filledArc.addPieSegment (rx, ry, rw, rw,
  52873. rotaryStartAngle,
  52874. angle,
  52875. thickness);
  52876. g.fillPath (filledArc);
  52877. }
  52878. if (thickness > 0)
  52879. {
  52880. const float innerRadius = radius * 0.2f;
  52881. Path p;
  52882. p.addTriangle (-innerRadius, 0.0f,
  52883. 0.0f, -radius * thickness * 1.1f,
  52884. innerRadius, 0.0f);
  52885. p.addEllipse (-innerRadius, -innerRadius, innerRadius * 2.0f, innerRadius * 2.0f);
  52886. g.fillPath (p, AffineTransform::rotation (angle).translated (centreX, centreY));
  52887. }
  52888. if (slider.isEnabled())
  52889. g.setColour (slider.findColour (Slider::rotarySliderOutlineColourId));
  52890. else
  52891. g.setColour (Colour (0x80808080));
  52892. Path outlineArc;
  52893. outlineArc.addPieSegment (rx, ry, rw, rw, rotaryStartAngle, rotaryEndAngle, thickness);
  52894. outlineArc.closeSubPath();
  52895. g.strokePath (outlineArc, PathStrokeType (slider.isEnabled() ? (isMouseOver ? 2.0f : 1.2f) : 0.3f));
  52896. }
  52897. else
  52898. {
  52899. if (slider.isEnabled())
  52900. g.setColour (slider.findColour (Slider::rotarySliderFillColourId).withAlpha (isMouseOver ? 1.0f : 0.7f));
  52901. else
  52902. g.setColour (Colour (0x80808080));
  52903. Path p;
  52904. p.addEllipse (-0.4f * rw, -0.4f * rw, rw * 0.8f, rw * 0.8f);
  52905. PathStrokeType (rw * 0.1f).createStrokedPath (p, p);
  52906. p.addLineSegment (0.0f, 0.0f, 0.0f, -radius, rw * 0.2f);
  52907. g.fillPath (p, AffineTransform::rotation (angle).translated (centreX, centreY));
  52908. }
  52909. }
  52910. Button* LookAndFeel::createSliderButton (const bool isIncrement)
  52911. {
  52912. return new TextButton (isIncrement ? "+" : "-", String::empty);
  52913. }
  52914. class SliderLabelComp : public Label
  52915. {
  52916. public:
  52917. SliderLabelComp() : Label (String::empty, String::empty) {}
  52918. ~SliderLabelComp() {}
  52919. void mouseWheelMove (const MouseEvent&, float, float) {}
  52920. };
  52921. Label* LookAndFeel::createSliderTextBox (Slider& slider)
  52922. {
  52923. Label* const l = new SliderLabelComp();
  52924. l->setJustificationType (Justification::centred);
  52925. l->setColour (Label::textColourId, slider.findColour (Slider::textBoxTextColourId));
  52926. l->setColour (Label::backgroundColourId,
  52927. (slider.getSliderStyle() == Slider::LinearBar) ? Colours::transparentBlack
  52928. : slider.findColour (Slider::textBoxBackgroundColourId));
  52929. l->setColour (Label::outlineColourId, slider.findColour (Slider::textBoxOutlineColourId));
  52930. l->setColour (TextEditor::textColourId, slider.findColour (Slider::textBoxTextColourId));
  52931. l->setColour (TextEditor::backgroundColourId,
  52932. slider.findColour (Slider::textBoxBackgroundColourId)
  52933. .withAlpha (slider.getSliderStyle() == Slider::LinearBar ? 0.7f : 1.0f));
  52934. l->setColour (TextEditor::outlineColourId, slider.findColour (Slider::textBoxOutlineColourId));
  52935. return l;
  52936. }
  52937. ImageEffectFilter* LookAndFeel::getSliderEffect()
  52938. {
  52939. return 0;
  52940. }
  52941. static const TextLayout layoutTooltipText (const String& text) throw()
  52942. {
  52943. const float tooltipFontSize = 12.0f;
  52944. const int maxToolTipWidth = 400;
  52945. const Font f (tooltipFontSize, Font::bold);
  52946. TextLayout tl (text, f);
  52947. tl.layout (maxToolTipWidth, Justification::left, true);
  52948. return tl;
  52949. }
  52950. void LookAndFeel::getTooltipSize (const String& tipText, int& width, int& height)
  52951. {
  52952. const TextLayout tl (layoutTooltipText (tipText));
  52953. width = tl.getWidth() + 14;
  52954. height = tl.getHeight() + 6;
  52955. }
  52956. void LookAndFeel::drawTooltip (Graphics& g, const String& text, int width, int height)
  52957. {
  52958. g.fillAll (findColour (TooltipWindow::backgroundColourId));
  52959. const Colour textCol (findColour (TooltipWindow::textColourId));
  52960. #if ! JUCE_MAC // The mac windows already have a non-optional 1 pix outline, so don't double it here..
  52961. g.setColour (findColour (TooltipWindow::outlineColourId));
  52962. g.drawRect (0, 0, width, height, 1);
  52963. #endif
  52964. const TextLayout tl (layoutTooltipText (text));
  52965. g.setColour (findColour (TooltipWindow::textColourId));
  52966. tl.drawWithin (g, 0, 0, width, height, Justification::centred);
  52967. }
  52968. Button* LookAndFeel::createFilenameComponentBrowseButton (const String& text)
  52969. {
  52970. return new TextButton (text, TRANS("click to browse for a different file"));
  52971. }
  52972. void LookAndFeel::layoutFilenameComponent (FilenameComponent& filenameComp,
  52973. ComboBox* filenameBox,
  52974. Button* browseButton)
  52975. {
  52976. browseButton->setSize (80, filenameComp.getHeight());
  52977. TextButton* const tb = dynamic_cast <TextButton*> (browseButton);
  52978. if (tb != 0)
  52979. tb->changeWidthToFitText();
  52980. browseButton->setTopRightPosition (filenameComp.getWidth(), 0);
  52981. filenameBox->setBounds (0, 0, browseButton->getX(), filenameComp.getHeight());
  52982. }
  52983. void LookAndFeel::drawImageButton (Graphics& g, Image* image,
  52984. int imageX, int imageY, int imageW, int imageH,
  52985. const Colour& overlayColour,
  52986. float imageOpacity,
  52987. ImageButton& button)
  52988. {
  52989. if (! button.isEnabled())
  52990. imageOpacity *= 0.3f;
  52991. if (! overlayColour.isOpaque())
  52992. {
  52993. g.setOpacity (imageOpacity);
  52994. g.drawImage (image, imageX, imageY, imageW, imageH,
  52995. 0, 0, image->getWidth(), image->getHeight(), false);
  52996. }
  52997. if (! overlayColour.isTransparent())
  52998. {
  52999. g.setColour (overlayColour);
  53000. g.drawImage (image, imageX, imageY, imageW, imageH,
  53001. 0, 0, image->getWidth(), image->getHeight(), true);
  53002. }
  53003. }
  53004. void LookAndFeel::drawCornerResizer (Graphics& g,
  53005. int w, int h,
  53006. bool /*isMouseOver*/,
  53007. bool /*isMouseDragging*/)
  53008. {
  53009. const float lineThickness = jmin (w, h) * 0.075f;
  53010. for (float i = 0.0f; i < 1.0f; i += 0.3f)
  53011. {
  53012. g.setColour (Colours::lightgrey);
  53013. g.drawLine (w * i,
  53014. h + 1.0f,
  53015. w + 1.0f,
  53016. h * i,
  53017. lineThickness);
  53018. g.setColour (Colours::darkgrey);
  53019. g.drawLine (w * i + lineThickness,
  53020. h + 1.0f,
  53021. w + 1.0f,
  53022. h * i + lineThickness,
  53023. lineThickness);
  53024. }
  53025. }
  53026. void LookAndFeel::drawResizableFrame (Graphics&, int /*w*/, int /*h*/,
  53027. const BorderSize& /*borders*/)
  53028. {
  53029. }
  53030. void LookAndFeel::fillResizableWindowBackground (Graphics& g, int /*w*/, int /*h*/,
  53031. const BorderSize& /*border*/, ResizableWindow& window)
  53032. {
  53033. g.fillAll (window.getBackgroundColour());
  53034. }
  53035. void LookAndFeel::drawResizableWindowBorder (Graphics& g, int w, int h,
  53036. const BorderSize& border, ResizableWindow&)
  53037. {
  53038. g.setColour (Colour (0x80000000));
  53039. g.drawRect (0, 0, w, h);
  53040. g.setColour (Colour (0x19000000));
  53041. g.drawRect (border.getLeft() - 1,
  53042. border.getTop() - 1,
  53043. w + 2 - border.getLeftAndRight(),
  53044. h + 2 - border.getTopAndBottom());
  53045. }
  53046. void LookAndFeel::drawDocumentWindowTitleBar (DocumentWindow& window,
  53047. Graphics& g, int w, int h,
  53048. int titleSpaceX, int titleSpaceW,
  53049. const Image* icon,
  53050. bool drawTitleTextOnLeft)
  53051. {
  53052. const bool isActive = window.isActiveWindow();
  53053. g.setGradientFill (ColourGradient (window.getBackgroundColour(),
  53054. 0.0f, 0.0f,
  53055. window.getBackgroundColour().contrasting (isActive ? 0.15f : 0.05f),
  53056. 0.0f, (float) h, false));
  53057. g.fillAll();
  53058. Font font (h * 0.65f, Font::bold);
  53059. g.setFont (font);
  53060. int textW = font.getStringWidth (window.getName());
  53061. int iconW = 0;
  53062. int iconH = 0;
  53063. if (icon != 0)
  53064. {
  53065. iconH = (int) font.getHeight();
  53066. iconW = icon->getWidth() * iconH / icon->getHeight() + 4;
  53067. }
  53068. textW = jmin (titleSpaceW, textW + iconW);
  53069. int textX = drawTitleTextOnLeft ? titleSpaceX
  53070. : jmax (titleSpaceX, (w - textW) / 2);
  53071. if (textX + textW > titleSpaceX + titleSpaceW)
  53072. textX = titleSpaceX + titleSpaceW - textW;
  53073. if (icon != 0)
  53074. {
  53075. g.setOpacity (isActive ? 1.0f : 0.6f);
  53076. g.drawImageWithin (icon, textX, (h - iconH) / 2, iconW, iconH,
  53077. RectanglePlacement::centred, false);
  53078. textX += iconW;
  53079. textW -= iconW;
  53080. }
  53081. if (window.isColourSpecified (DocumentWindow::textColourId) || isColourSpecified (DocumentWindow::textColourId))
  53082. g.setColour (findColour (DocumentWindow::textColourId));
  53083. else
  53084. g.setColour (window.getBackgroundColour().contrasting (isActive ? 0.7f : 0.4f));
  53085. g.drawText (window.getName(), textX, 0, textW, h, Justification::centredLeft, true);
  53086. }
  53087. class GlassWindowButton : public Button
  53088. {
  53089. public:
  53090. GlassWindowButton (const String& name, const Colour& col,
  53091. const Path& normalShape_,
  53092. const Path& toggledShape_) throw()
  53093. : Button (name),
  53094. colour (col),
  53095. normalShape (normalShape_),
  53096. toggledShape (toggledShape_)
  53097. {
  53098. }
  53099. ~GlassWindowButton()
  53100. {
  53101. }
  53102. void paintButton (Graphics& g, bool isMouseOverButton, bool isButtonDown)
  53103. {
  53104. float alpha = isMouseOverButton ? (isButtonDown ? 1.0f : 0.8f) : 0.55f;
  53105. if (! isEnabled())
  53106. alpha *= 0.5f;
  53107. float x = 0, y = 0, diam;
  53108. if (getWidth() < getHeight())
  53109. {
  53110. diam = (float) getWidth();
  53111. y = (getHeight() - getWidth()) * 0.5f;
  53112. }
  53113. else
  53114. {
  53115. diam = (float) getHeight();
  53116. y = (getWidth() - getHeight()) * 0.5f;
  53117. }
  53118. x += diam * 0.05f;
  53119. y += diam * 0.05f;
  53120. diam *= 0.9f;
  53121. g.setGradientFill (ColourGradient (Colour::greyLevel (0.9f).withAlpha (alpha), 0, y + diam,
  53122. Colour::greyLevel (0.6f).withAlpha (alpha), 0, y, false));
  53123. g.fillEllipse (x, y, diam, diam);
  53124. x += 2.0f;
  53125. y += 2.0f;
  53126. diam -= 4.0f;
  53127. LookAndFeel::drawGlassSphere (g, x, y, diam, colour.withAlpha (alpha), 1.0f);
  53128. Path& p = getToggleState() ? toggledShape : normalShape;
  53129. const AffineTransform t (p.getTransformToScaleToFit (x + diam * 0.3f, y + diam * 0.3f,
  53130. diam * 0.4f, diam * 0.4f, true));
  53131. g.setColour (Colours::black.withAlpha (alpha * 0.6f));
  53132. g.fillPath (p, t);
  53133. }
  53134. juce_UseDebuggingNewOperator
  53135. private:
  53136. Colour colour;
  53137. Path normalShape, toggledShape;
  53138. GlassWindowButton (const GlassWindowButton&);
  53139. const GlassWindowButton& operator= (const GlassWindowButton&);
  53140. };
  53141. Button* LookAndFeel::createDocumentWindowButton (int buttonType)
  53142. {
  53143. Path shape;
  53144. const float crossThickness = 0.25f;
  53145. if (buttonType == DocumentWindow::closeButton)
  53146. {
  53147. shape.addLineSegment (0.0f, 0.0f, 1.0f, 1.0f, crossThickness * 1.4f);
  53148. shape.addLineSegment (1.0f, 0.0f, 0.0f, 1.0f, crossThickness * 1.4f);
  53149. return new GlassWindowButton ("close", Colour (0xffdd1100), shape, shape);
  53150. }
  53151. else if (buttonType == DocumentWindow::minimiseButton)
  53152. {
  53153. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, crossThickness);
  53154. return new GlassWindowButton ("minimise", Colour (0xffaa8811), shape, shape);
  53155. }
  53156. else if (buttonType == DocumentWindow::maximiseButton)
  53157. {
  53158. shape.addLineSegment (0.5f, 0.0f, 0.5f, 1.0f, crossThickness);
  53159. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, crossThickness);
  53160. Path fullscreenShape;
  53161. fullscreenShape.startNewSubPath (45.0f, 100.0f);
  53162. fullscreenShape.lineTo (0.0f, 100.0f);
  53163. fullscreenShape.lineTo (0.0f, 0.0f);
  53164. fullscreenShape.lineTo (100.0f, 0.0f);
  53165. fullscreenShape.lineTo (100.0f, 45.0f);
  53166. fullscreenShape.addRectangle (45.0f, 45.0f, 100.0f, 100.0f);
  53167. PathStrokeType (30.0f).createStrokedPath (fullscreenShape, fullscreenShape);
  53168. return new GlassWindowButton ("maximise", Colour (0xff119911), shape, fullscreenShape);
  53169. }
  53170. jassertfalse
  53171. return 0;
  53172. }
  53173. void LookAndFeel::positionDocumentWindowButtons (DocumentWindow&,
  53174. int titleBarX,
  53175. int titleBarY,
  53176. int titleBarW,
  53177. int titleBarH,
  53178. Button* minimiseButton,
  53179. Button* maximiseButton,
  53180. Button* closeButton,
  53181. bool positionTitleBarButtonsOnLeft)
  53182. {
  53183. const int buttonW = titleBarH - titleBarH / 8;
  53184. int x = positionTitleBarButtonsOnLeft ? titleBarX + 4
  53185. : titleBarX + titleBarW - buttonW - buttonW / 4;
  53186. if (closeButton != 0)
  53187. {
  53188. closeButton->setBounds (x, titleBarY, buttonW, titleBarH);
  53189. x += positionTitleBarButtonsOnLeft ? buttonW : -(buttonW + buttonW / 4);
  53190. }
  53191. if (positionTitleBarButtonsOnLeft)
  53192. swapVariables (minimiseButton, maximiseButton);
  53193. if (maximiseButton != 0)
  53194. {
  53195. maximiseButton->setBounds (x, titleBarY, buttonW, titleBarH);
  53196. x += positionTitleBarButtonsOnLeft ? buttonW : -buttonW;
  53197. }
  53198. if (minimiseButton != 0)
  53199. minimiseButton->setBounds (x, titleBarY, buttonW, titleBarH);
  53200. }
  53201. int LookAndFeel::getDefaultMenuBarHeight()
  53202. {
  53203. return 24;
  53204. }
  53205. DropShadower* LookAndFeel::createDropShadowerForComponent (Component*)
  53206. {
  53207. return new DropShadower (0.4f, 1, 5, 10);
  53208. }
  53209. void LookAndFeel::drawStretchableLayoutResizerBar (Graphics& g,
  53210. int w, int h,
  53211. bool /*isVerticalBar*/,
  53212. bool isMouseOver,
  53213. bool isMouseDragging)
  53214. {
  53215. float alpha = 0.5f;
  53216. if (isMouseOver || isMouseDragging)
  53217. {
  53218. g.fillAll (Colour (0x190000ff));
  53219. alpha = 1.0f;
  53220. }
  53221. const float cx = w * 0.5f;
  53222. const float cy = h * 0.5f;
  53223. const float cr = jmin (w, h) * 0.4f;
  53224. g.setGradientFill (ColourGradient (Colours::white.withAlpha (alpha), cx + cr * 0.1f, cy + cr,
  53225. Colours::black.withAlpha (alpha), cx, cy - cr * 4.0f,
  53226. true));
  53227. g.fillEllipse (cx - cr, cy - cr, cr * 2.0f, cr * 2.0f);
  53228. }
  53229. void LookAndFeel::drawGroupComponentOutline (Graphics& g, int width, int height,
  53230. const String& text,
  53231. const Justification& position,
  53232. GroupComponent& group)
  53233. {
  53234. const float textH = 15.0f;
  53235. const float indent = 3.0f;
  53236. const float textEdgeGap = 4.0f;
  53237. float cs = 5.0f;
  53238. Font f (textH);
  53239. Path p;
  53240. float x = indent;
  53241. float y = f.getAscent() - 3.0f;
  53242. float w = jmax (0.0f, width - x * 2.0f);
  53243. float h = jmax (0.0f, height - y - indent);
  53244. cs = jmin (cs, w * 0.5f, h * 0.5f);
  53245. const float cs2 = 2.0f * cs;
  53246. float textW = text.isEmpty() ? 0 : jlimit (0.0f, jmax (0.0f, w - cs2 - textEdgeGap * 2), f.getStringWidth (text) + textEdgeGap * 2.0f);
  53247. float textX = cs + textEdgeGap;
  53248. if (position.testFlags (Justification::horizontallyCentred))
  53249. textX = cs + (w - cs2 - textW) * 0.5f;
  53250. else if (position.testFlags (Justification::right))
  53251. textX = w - cs - textW - textEdgeGap;
  53252. p.startNewSubPath (x + textX + textW, y);
  53253. p.lineTo (x + w - cs, y);
  53254. p.addArc (x + w - cs2, y, cs2, cs2, 0, float_Pi * 0.5f);
  53255. p.lineTo (x + w, y + h - cs);
  53256. p.addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
  53257. p.lineTo (x + cs, y + h);
  53258. p.addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
  53259. p.lineTo (x, y + cs);
  53260. p.addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f);
  53261. p.lineTo (x + textX, y);
  53262. const float alpha = group.isEnabled() ? 1.0f : 0.5f;
  53263. g.setColour (group.findColour (GroupComponent::outlineColourId)
  53264. .withMultipliedAlpha (alpha));
  53265. g.strokePath (p, PathStrokeType (2.0f));
  53266. g.setColour (group.findColour (GroupComponent::textColourId)
  53267. .withMultipliedAlpha (alpha));
  53268. g.setFont (f);
  53269. g.drawText (text,
  53270. roundToInt (x + textX), 0,
  53271. roundToInt (textW),
  53272. roundToInt (textH),
  53273. Justification::centred, true);
  53274. }
  53275. int LookAndFeel::getTabButtonOverlap (int tabDepth)
  53276. {
  53277. return 1 + tabDepth / 3;
  53278. }
  53279. int LookAndFeel::getTabButtonSpaceAroundImage()
  53280. {
  53281. return 4;
  53282. }
  53283. void LookAndFeel::createTabButtonShape (Path& p,
  53284. int width, int height,
  53285. int /*tabIndex*/,
  53286. const String& /*text*/,
  53287. Button& /*button*/,
  53288. TabbedButtonBar::Orientation orientation,
  53289. const bool /*isMouseOver*/,
  53290. const bool /*isMouseDown*/,
  53291. const bool /*isFrontTab*/)
  53292. {
  53293. const float w = (float) width;
  53294. const float h = (float) height;
  53295. float length = w;
  53296. float depth = h;
  53297. if (orientation == TabbedButtonBar::TabsAtLeft
  53298. || orientation == TabbedButtonBar::TabsAtRight)
  53299. {
  53300. swapVariables (length, depth);
  53301. }
  53302. const float indent = (float) getTabButtonOverlap ((int) depth);
  53303. const float overhang = 4.0f;
  53304. if (orientation == TabbedButtonBar::TabsAtLeft)
  53305. {
  53306. p.startNewSubPath (w, 0.0f);
  53307. p.lineTo (0.0f, indent);
  53308. p.lineTo (0.0f, h - indent);
  53309. p.lineTo (w, h);
  53310. p.lineTo (w + overhang, h + overhang);
  53311. p.lineTo (w + overhang, -overhang);
  53312. }
  53313. else if (orientation == TabbedButtonBar::TabsAtRight)
  53314. {
  53315. p.startNewSubPath (0.0f, 0.0f);
  53316. p.lineTo (w, indent);
  53317. p.lineTo (w, h - indent);
  53318. p.lineTo (0.0f, h);
  53319. p.lineTo (-overhang, h + overhang);
  53320. p.lineTo (-overhang, -overhang);
  53321. }
  53322. else if (orientation == TabbedButtonBar::TabsAtBottom)
  53323. {
  53324. p.startNewSubPath (0.0f, 0.0f);
  53325. p.lineTo (indent, h);
  53326. p.lineTo (w - indent, h);
  53327. p.lineTo (w, 0.0f);
  53328. p.lineTo (w + overhang, -overhang);
  53329. p.lineTo (-overhang, -overhang);
  53330. }
  53331. else
  53332. {
  53333. p.startNewSubPath (0.0f, h);
  53334. p.lineTo (indent, 0.0f);
  53335. p.lineTo (w - indent, 0.0f);
  53336. p.lineTo (w, h);
  53337. p.lineTo (w + overhang, h + overhang);
  53338. p.lineTo (-overhang, h + overhang);
  53339. }
  53340. p.closeSubPath();
  53341. p = p.createPathWithRoundedCorners (3.0f);
  53342. }
  53343. void LookAndFeel::fillTabButtonShape (Graphics& g,
  53344. const Path& path,
  53345. const Colour& preferredColour,
  53346. int /*tabIndex*/,
  53347. const String& /*text*/,
  53348. Button& button,
  53349. TabbedButtonBar::Orientation /*orientation*/,
  53350. const bool /*isMouseOver*/,
  53351. const bool /*isMouseDown*/,
  53352. const bool isFrontTab)
  53353. {
  53354. g.setColour (isFrontTab ? preferredColour
  53355. : preferredColour.withMultipliedAlpha (0.9f));
  53356. g.fillPath (path);
  53357. g.setColour (button.findColour (isFrontTab ? TabbedButtonBar::frontOutlineColourId
  53358. : TabbedButtonBar::tabOutlineColourId, false)
  53359. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  53360. g.strokePath (path, PathStrokeType (isFrontTab ? 1.0f : 0.5f));
  53361. }
  53362. void LookAndFeel::drawTabButtonText (Graphics& g,
  53363. int x, int y, int w, int h,
  53364. const Colour& preferredBackgroundColour,
  53365. int /*tabIndex*/,
  53366. const String& text,
  53367. Button& button,
  53368. TabbedButtonBar::Orientation orientation,
  53369. const bool isMouseOver,
  53370. const bool isMouseDown,
  53371. const bool isFrontTab)
  53372. {
  53373. int length = w;
  53374. int depth = h;
  53375. if (orientation == TabbedButtonBar::TabsAtLeft
  53376. || orientation == TabbedButtonBar::TabsAtRight)
  53377. {
  53378. swapVariables (length, depth);
  53379. }
  53380. Font font (depth * 0.6f);
  53381. font.setUnderline (button.hasKeyboardFocus (false));
  53382. GlyphArrangement textLayout;
  53383. textLayout.addFittedText (font, text.trim(),
  53384. 0.0f, 0.0f, (float) length, (float) depth,
  53385. Justification::centred,
  53386. jmax (1, depth / 12));
  53387. AffineTransform transform;
  53388. if (orientation == TabbedButtonBar::TabsAtLeft)
  53389. {
  53390. transform = transform.rotated (float_Pi * -0.5f)
  53391. .translated ((float) x, (float) (y + h));
  53392. }
  53393. else if (orientation == TabbedButtonBar::TabsAtRight)
  53394. {
  53395. transform = transform.rotated (float_Pi * 0.5f)
  53396. .translated ((float) (x + w), (float) y);
  53397. }
  53398. else
  53399. {
  53400. transform = transform.translated ((float) x, (float) y);
  53401. }
  53402. if (isFrontTab && (button.isColourSpecified (TabbedButtonBar::frontTextColourId) || isColourSpecified (TabbedButtonBar::frontTextColourId)))
  53403. g.setColour (findColour (TabbedButtonBar::frontTextColourId));
  53404. else if (button.isColourSpecified (TabbedButtonBar::tabTextColourId) || isColourSpecified (TabbedButtonBar::tabTextColourId))
  53405. g.setColour (findColour (TabbedButtonBar::tabTextColourId));
  53406. else
  53407. g.setColour (preferredBackgroundColour.contrasting());
  53408. if (! (isMouseOver || isMouseDown))
  53409. g.setOpacity (0.8f);
  53410. if (! button.isEnabled())
  53411. g.setOpacity (0.3f);
  53412. textLayout.draw (g, transform);
  53413. }
  53414. int LookAndFeel::getTabButtonBestWidth (int /*tabIndex*/,
  53415. const String& text,
  53416. int tabDepth,
  53417. Button&)
  53418. {
  53419. Font f (tabDepth * 0.6f);
  53420. return f.getStringWidth (text.trim()) + getTabButtonOverlap (tabDepth) * 2;
  53421. }
  53422. void LookAndFeel::drawTabButton (Graphics& g,
  53423. int w, int h,
  53424. const Colour& preferredColour,
  53425. int tabIndex,
  53426. const String& text,
  53427. Button& button,
  53428. TabbedButtonBar::Orientation orientation,
  53429. const bool isMouseOver,
  53430. const bool isMouseDown,
  53431. const bool isFrontTab)
  53432. {
  53433. int length = w;
  53434. int depth = h;
  53435. if (orientation == TabbedButtonBar::TabsAtLeft
  53436. || orientation == TabbedButtonBar::TabsAtRight)
  53437. {
  53438. swapVariables (length, depth);
  53439. }
  53440. Path tabShape;
  53441. createTabButtonShape (tabShape, w, h,
  53442. tabIndex, text, button, orientation,
  53443. isMouseOver, isMouseDown, isFrontTab);
  53444. fillTabButtonShape (g, tabShape, preferredColour,
  53445. tabIndex, text, button, orientation,
  53446. isMouseOver, isMouseDown, isFrontTab);
  53447. const int indent = getTabButtonOverlap (depth);
  53448. int x = 0, y = 0;
  53449. if (orientation == TabbedButtonBar::TabsAtLeft
  53450. || orientation == TabbedButtonBar::TabsAtRight)
  53451. {
  53452. y += indent;
  53453. h -= indent * 2;
  53454. }
  53455. else
  53456. {
  53457. x += indent;
  53458. w -= indent * 2;
  53459. }
  53460. drawTabButtonText (g, x, y, w, h, preferredColour,
  53461. tabIndex, text, button, orientation,
  53462. isMouseOver, isMouseDown, isFrontTab);
  53463. }
  53464. void LookAndFeel::drawTabAreaBehindFrontButton (Graphics& g,
  53465. int w, int h,
  53466. TabbedButtonBar& tabBar,
  53467. TabbedButtonBar::Orientation orientation)
  53468. {
  53469. const float shadowSize = 0.2f;
  53470. float x1 = 0.0f, y1 = 0.0f, x2 = 0.0f, y2 = 0.0f;
  53471. Rectangle<int> shadowRect;
  53472. if (orientation == TabbedButtonBar::TabsAtLeft)
  53473. {
  53474. x1 = (float) w;
  53475. x2 = w * (1.0f - shadowSize);
  53476. shadowRect.setBounds ((int) x2, 0, w - (int) x2, h);
  53477. }
  53478. else if (orientation == TabbedButtonBar::TabsAtRight)
  53479. {
  53480. x2 = w * shadowSize;
  53481. shadowRect.setBounds (0, 0, (int) x2, h);
  53482. }
  53483. else if (orientation == TabbedButtonBar::TabsAtBottom)
  53484. {
  53485. y2 = h * shadowSize;
  53486. shadowRect.setBounds (0, 0, w, (int) y2);
  53487. }
  53488. else
  53489. {
  53490. y1 = (float) h;
  53491. y2 = h * (1.0f - shadowSize);
  53492. shadowRect.setBounds (0, (int) y2, w, h - (int) y2);
  53493. }
  53494. g.setGradientFill (ColourGradient (Colours::black.withAlpha (tabBar.isEnabled() ? 0.3f : 0.15f), x1, y1,
  53495. Colours::transparentBlack, x2, y2, false));
  53496. shadowRect.expand (2, 2);
  53497. g.fillRect (shadowRect);
  53498. g.setColour (Colour (0x80000000));
  53499. if (orientation == TabbedButtonBar::TabsAtLeft)
  53500. {
  53501. g.fillRect (w - 1, 0, 1, h);
  53502. }
  53503. else if (orientation == TabbedButtonBar::TabsAtRight)
  53504. {
  53505. g.fillRect (0, 0, 1, h);
  53506. }
  53507. else if (orientation == TabbedButtonBar::TabsAtBottom)
  53508. {
  53509. g.fillRect (0, 0, w, 1);
  53510. }
  53511. else
  53512. {
  53513. g.fillRect (0, h - 1, w, 1);
  53514. }
  53515. }
  53516. Button* LookAndFeel::createTabBarExtrasButton()
  53517. {
  53518. const float thickness = 7.0f;
  53519. const float indent = 22.0f;
  53520. Path p;
  53521. p.addEllipse (-10.0f, -10.0f, 120.0f, 120.0f);
  53522. DrawablePath ellipse;
  53523. ellipse.setPath (p);
  53524. ellipse.setFill (Colour (0x99ffffff));
  53525. p.clear();
  53526. p.addEllipse (0.0f, 0.0f, 100.0f, 100.0f);
  53527. p.addRectangle (indent, 50.0f - thickness, 100.0f - indent * 2.0f, thickness * 2.0f);
  53528. p.addRectangle (50.0f - thickness, indent, thickness * 2.0f, 50.0f - indent - thickness);
  53529. p.addRectangle (50.0f - thickness, 50.0f + thickness, thickness * 2.0f, 50.0f - indent - thickness);
  53530. p.setUsingNonZeroWinding (false);
  53531. DrawablePath dp;
  53532. dp.setPath (p);
  53533. dp.setFill (Colour (0x59000000));
  53534. DrawableComposite normalImage;
  53535. normalImage.insertDrawable (ellipse);
  53536. normalImage.insertDrawable (dp);
  53537. dp.setFill (Colour (0xcc000000));
  53538. DrawableComposite overImage;
  53539. overImage.insertDrawable (ellipse);
  53540. overImage.insertDrawable (dp);
  53541. DrawableButton* db = new DrawableButton (T("tabs"), DrawableButton::ImageFitted);
  53542. db->setImages (&normalImage, &overImage, 0);
  53543. return db;
  53544. }
  53545. void LookAndFeel::drawTableHeaderBackground (Graphics& g, TableHeaderComponent& header)
  53546. {
  53547. g.fillAll (Colours::white);
  53548. const int w = header.getWidth();
  53549. const int h = header.getHeight();
  53550. g.setGradientFill (ColourGradient (Colour (0xffe8ebf9), 0.0f, h * 0.5f,
  53551. Colour (0xfff6f8f9), 0.0f, h - 1.0f,
  53552. false));
  53553. g.fillRect (0, h / 2, w, h);
  53554. g.setColour (Colour (0x33000000));
  53555. g.fillRect (0, h - 1, w, 1);
  53556. for (int i = header.getNumColumns (true); --i >= 0;)
  53557. g.fillRect (header.getColumnPosition (i).getRight() - 1, 0, 1, h - 1);
  53558. }
  53559. void LookAndFeel::drawTableHeaderColumn (Graphics& g, const String& columnName, int /*columnId*/,
  53560. int width, int height,
  53561. bool isMouseOver, bool isMouseDown,
  53562. int columnFlags)
  53563. {
  53564. if (isMouseDown)
  53565. g.fillAll (Colour (0x8899aadd));
  53566. else if (isMouseOver)
  53567. g.fillAll (Colour (0x5599aadd));
  53568. int rightOfText = width - 4;
  53569. if ((columnFlags & (TableHeaderComponent::sortedForwards | TableHeaderComponent::sortedBackwards)) != 0)
  53570. {
  53571. const float top = height * ((columnFlags & TableHeaderComponent::sortedForwards) != 0 ? 0.35f : (1.0f - 0.35f));
  53572. const float bottom = height - top;
  53573. const float w = height * 0.5f;
  53574. const float x = rightOfText - (w * 1.25f);
  53575. rightOfText = (int) x;
  53576. Path sortArrow;
  53577. sortArrow.addTriangle (x, bottom, x + w * 0.5f, top, x + w, bottom);
  53578. g.setColour (Colour (0x99000000));
  53579. g.fillPath (sortArrow);
  53580. }
  53581. g.setColour (Colours::black);
  53582. g.setFont (height * 0.5f, Font::bold);
  53583. const int textX = 4;
  53584. g.drawFittedText (columnName, textX, 0, rightOfText - textX, height, Justification::centredLeft, 1);
  53585. }
  53586. void LookAndFeel::paintToolbarBackground (Graphics& g, int w, int h, Toolbar& toolbar)
  53587. {
  53588. const Colour background (toolbar.findColour (Toolbar::backgroundColourId));
  53589. g.setGradientFill (ColourGradient (background, 0.0f, 0.0f,
  53590. background.darker (0.1f),
  53591. toolbar.isVertical() ? w - 1.0f : 0.0f,
  53592. toolbar.isVertical() ? 0.0f : h - 1.0f,
  53593. false));
  53594. g.fillAll();
  53595. }
  53596. Button* LookAndFeel::createToolbarMissingItemsButton (Toolbar& /*toolbar*/)
  53597. {
  53598. return createTabBarExtrasButton();
  53599. }
  53600. void LookAndFeel::paintToolbarButtonBackground (Graphics& g, int /*width*/, int /*height*/,
  53601. bool isMouseOver, bool isMouseDown,
  53602. ToolbarItemComponent& component)
  53603. {
  53604. if (isMouseDown)
  53605. g.fillAll (component.findColour (Toolbar::buttonMouseDownBackgroundColourId, true));
  53606. else if (isMouseOver)
  53607. g.fillAll (component.findColour (Toolbar::buttonMouseOverBackgroundColourId, true));
  53608. }
  53609. void LookAndFeel::paintToolbarButtonLabel (Graphics& g, int x, int y, int width, int height,
  53610. const String& text, ToolbarItemComponent& component)
  53611. {
  53612. g.setColour (component.findColour (Toolbar::labelTextColourId, true)
  53613. .withAlpha (component.isEnabled() ? 1.0f : 0.25f));
  53614. const float fontHeight = jmin (14.0f, height * 0.85f);
  53615. g.setFont (fontHeight);
  53616. g.drawFittedText (text,
  53617. x, y, width, height,
  53618. Justification::centred,
  53619. jmax (1, height / (int) fontHeight));
  53620. }
  53621. void LookAndFeel::drawPropertyPanelSectionHeader (Graphics& g, const String& name,
  53622. bool isOpen, int width, int height)
  53623. {
  53624. const int buttonSize = (height * 3) / 4;
  53625. const int buttonIndent = (height - buttonSize) / 2;
  53626. drawTreeviewPlusMinusBox (g, buttonIndent, buttonIndent, buttonSize, buttonSize, ! isOpen, false);
  53627. const int textX = buttonIndent * 2 + buttonSize + 2;
  53628. g.setColour (Colours::black);
  53629. g.setFont (height * 0.7f, Font::bold);
  53630. g.drawText (name, textX, 0, width - textX - 4, height, Justification::centredLeft, true);
  53631. }
  53632. void LookAndFeel::drawPropertyComponentBackground (Graphics& g, int width, int height,
  53633. PropertyComponent&)
  53634. {
  53635. g.setColour (Colour (0x66ffffff));
  53636. g.fillRect (0, 0, width, height - 1);
  53637. }
  53638. void LookAndFeel::drawPropertyComponentLabel (Graphics& g, int, int height,
  53639. PropertyComponent& component)
  53640. {
  53641. g.setColour (Colours::black);
  53642. if (! component.isEnabled())
  53643. g.setOpacity (0.6f);
  53644. g.setFont (jmin (height, 24) * 0.65f);
  53645. const Rectangle<int> r (getPropertyComponentContentPosition (component));
  53646. g.drawFittedText (component.getName(),
  53647. 3, r.getY(), r.getX() - 5, r.getHeight(),
  53648. Justification::centredLeft, 2);
  53649. }
  53650. const Rectangle<int> LookAndFeel::getPropertyComponentContentPosition (PropertyComponent& component)
  53651. {
  53652. return Rectangle<int> (component.getWidth() / 3, 1,
  53653. component.getWidth() - component.getWidth() / 3 - 1, component.getHeight() - 3);
  53654. }
  53655. void LookAndFeel::createFileChooserHeaderText (const String& title,
  53656. const String& instructions,
  53657. GlyphArrangement& text,
  53658. int width)
  53659. {
  53660. text.clear();
  53661. text.addJustifiedText (Font (17.0f, Font::bold), title,
  53662. 8.0f, 22.0f, width - 16.0f,
  53663. Justification::centred);
  53664. text.addJustifiedText (Font (14.0f), instructions,
  53665. 8.0f, 24.0f + 16.0f, width - 16.0f,
  53666. Justification::centred);
  53667. }
  53668. void LookAndFeel::drawFileBrowserRow (Graphics& g, int width, int height,
  53669. const String& filename, Image* icon,
  53670. const String& fileSizeDescription,
  53671. const String& fileTimeDescription,
  53672. const bool isDirectory,
  53673. const bool isItemSelected,
  53674. const int /*itemIndex*/)
  53675. {
  53676. if (isItemSelected)
  53677. g.fillAll (findColour (DirectoryContentsDisplayComponent::highlightColourId));
  53678. g.setColour (findColour (DirectoryContentsDisplayComponent::textColourId));
  53679. g.setFont (height * 0.7f);
  53680. Image* im = icon;
  53681. Image* toRelease = 0;
  53682. if (im == 0)
  53683. {
  53684. toRelease = im = (isDirectory ? getDefaultFolderImage()
  53685. : getDefaultDocumentFileImage());
  53686. }
  53687. const int x = 32;
  53688. if (im != 0)
  53689. {
  53690. g.drawImageWithin (im, 2, 2, x - 4, height - 4,
  53691. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize,
  53692. false);
  53693. ImageCache::release (toRelease);
  53694. }
  53695. if (width > 450 && ! isDirectory)
  53696. {
  53697. const int sizeX = roundToInt (width * 0.7f);
  53698. const int dateX = roundToInt (width * 0.8f);
  53699. g.drawFittedText (filename,
  53700. x, 0, sizeX - x, height,
  53701. Justification::centredLeft, 1);
  53702. g.setFont (height * 0.5f);
  53703. g.setColour (Colours::darkgrey);
  53704. if (! isDirectory)
  53705. {
  53706. g.drawFittedText (fileSizeDescription,
  53707. sizeX, 0, dateX - sizeX - 8, height,
  53708. Justification::centredRight, 1);
  53709. g.drawFittedText (fileTimeDescription,
  53710. dateX, 0, width - 8 - dateX, height,
  53711. Justification::centredRight, 1);
  53712. }
  53713. }
  53714. else
  53715. {
  53716. g.drawFittedText (filename,
  53717. x, 0, width - x, height,
  53718. Justification::centredLeft, 1);
  53719. }
  53720. }
  53721. Button* LookAndFeel::createFileBrowserGoUpButton()
  53722. {
  53723. DrawableButton* goUpButton = new DrawableButton ("up", DrawableButton::ImageOnButtonBackground);
  53724. Path arrowPath;
  53725. arrowPath.addArrow (50.0f, 100.0f, 50.0f, 0.0f, 40.0f, 100.0f, 50.0f);
  53726. DrawablePath arrowImage;
  53727. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  53728. arrowImage.setPath (arrowPath);
  53729. goUpButton->setImages (&arrowImage);
  53730. return goUpButton;
  53731. }
  53732. void LookAndFeel::layoutFileBrowserComponent (FileBrowserComponent& browserComp,
  53733. DirectoryContentsDisplayComponent* fileListComponent,
  53734. FilePreviewComponent* previewComp,
  53735. ComboBox* currentPathBox,
  53736. TextEditor* filenameBox,
  53737. Button* goUpButton)
  53738. {
  53739. const int x = 8;
  53740. int w = browserComp.getWidth() - x - x;
  53741. if (previewComp != 0)
  53742. {
  53743. const int previewWidth = w / 3;
  53744. previewComp->setBounds (x + w - previewWidth, 0, previewWidth, browserComp.getHeight());
  53745. w -= previewWidth + 4;
  53746. }
  53747. int y = 4;
  53748. const int controlsHeight = 22;
  53749. const int bottomSectionHeight = controlsHeight + 8;
  53750. const int upButtonWidth = 50;
  53751. currentPathBox->setBounds (x, y, w - upButtonWidth - 6, controlsHeight);
  53752. goUpButton->setBounds (x + w - upButtonWidth, y, upButtonWidth, controlsHeight);
  53753. y += controlsHeight + 4;
  53754. Component* const listAsComp = dynamic_cast <Component*> (fileListComponent);
  53755. listAsComp->setBounds (x, y, w, browserComp.getHeight() - y - bottomSectionHeight);
  53756. y = listAsComp->getBottom() + 4;
  53757. filenameBox->setBounds (x + 50, y, w - 50, controlsHeight);
  53758. }
  53759. Image* LookAndFeel::getDefaultFolderImage()
  53760. {
  53761. 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,
  53762. 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,
  53763. 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,
  53764. 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,
  53765. 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,
  53766. 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,
  53767. 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,
  53768. 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,
  53769. 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,
  53770. 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,
  53771. 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,
  53772. 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,
  53773. 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,
  53774. 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,
  53775. 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,
  53776. 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,
  53777. 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,
  53778. 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,
  53779. 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,
  53780. 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,
  53781. 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,
  53782. 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,
  53783. 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,
  53784. 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,
  53785. 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,
  53786. 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,
  53787. 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,
  53788. 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,
  53789. 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,
  53790. 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,
  53791. 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,
  53792. 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,
  53793. 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,
  53794. 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,
  53795. 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,
  53796. 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,
  53797. 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,
  53798. 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,
  53799. 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,
  53800. 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,
  53801. 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,
  53802. 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,
  53803. 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,
  53804. 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};
  53805. return ImageCache::getFromMemory (foldericon_png, sizeof (foldericon_png));
  53806. }
  53807. Image* LookAndFeel::getDefaultDocumentFileImage()
  53808. {
  53809. 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,
  53810. 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,
  53811. 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,
  53812. 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,
  53813. 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,
  53814. 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,
  53815. 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,
  53816. 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,
  53817. 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,
  53818. 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,
  53819. 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,
  53820. 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,
  53821. 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,
  53822. 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,
  53823. 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,
  53824. 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,
  53825. 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,
  53826. 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,
  53827. 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,
  53828. 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,
  53829. 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,
  53830. 174,66,96,130,0,0};
  53831. return ImageCache::getFromMemory (fileicon_png, sizeof (fileicon_png));
  53832. }
  53833. void LookAndFeel::playAlertSound()
  53834. {
  53835. PlatformUtilities::beep();
  53836. }
  53837. void LookAndFeel::drawLevelMeter (Graphics& g, int width, int height, float level)
  53838. {
  53839. g.setColour (Colours::white.withAlpha (0.7f));
  53840. g.fillRoundedRectangle (0.0f, 0.0f, (float) width, (float) height, 3.0f);
  53841. g.setColour (Colours::black.withAlpha (0.2f));
  53842. g.drawRoundedRectangle (1.0f, 1.0f, width - 2.0f, height - 2.0f, 3.0f, 1.0f);
  53843. const int totalBlocks = 7;
  53844. const int numBlocks = roundToInt (totalBlocks * level);
  53845. const float w = (width - 6.0f) / (float) totalBlocks;
  53846. for (int i = 0; i < totalBlocks; ++i)
  53847. {
  53848. if (i >= numBlocks)
  53849. g.setColour (Colours::lightblue.withAlpha (0.6f));
  53850. else
  53851. g.setColour (i < totalBlocks - 1 ? Colours::blue.withAlpha (0.5f)
  53852. : Colours::red);
  53853. g.fillRoundedRectangle (3.0f + i * w + w * 0.1f, 3.0f, w * 0.8f, height - 6.0f, w * 0.4f);
  53854. }
  53855. }
  53856. void LookAndFeel::drawKeymapChangeButton (Graphics& g, int width, int height, Button& button, const String& keyDescription)
  53857. {
  53858. const Colour textColour (button.findColour (KeyMappingEditorComponent::textColourId, true));
  53859. if (keyDescription.isNotEmpty())
  53860. {
  53861. if (button.isEnabled())
  53862. {
  53863. const float alpha = button.isDown() ? 0.3f : (button.isOver() ? 0.15f : 0.08f);
  53864. g.fillAll (textColour.withAlpha (alpha));
  53865. g.setOpacity (0.3f);
  53866. g.drawBevel (0, 0, width, height, 2);
  53867. }
  53868. g.setColour (textColour);
  53869. g.setFont (height * 0.6f);
  53870. g.drawFittedText (keyDescription,
  53871. 3, 0, width - 6, height,
  53872. Justification::centred, 1);
  53873. }
  53874. else
  53875. {
  53876. const float thickness = 7.0f;
  53877. const float indent = 22.0f;
  53878. Path p;
  53879. p.addEllipse (0.0f, 0.0f, 100.0f, 100.0f);
  53880. p.addRectangle (indent, 50.0f - thickness, 100.0f - indent * 2.0f, thickness * 2.0f);
  53881. p.addRectangle (50.0f - thickness, indent, thickness * 2.0f, 50.0f - indent - thickness);
  53882. p.addRectangle (50.0f - thickness, 50.0f + thickness, thickness * 2.0f, 50.0f - indent - thickness);
  53883. p.setUsingNonZeroWinding (false);
  53884. g.setColour (textColour.withAlpha (button.isDown() ? 0.7f : (button.isOver() ? 0.5f : 0.3f)));
  53885. g.fillPath (p, p.getTransformToScaleToFit (2.0f, 2.0f, width - 4.0f, height - 4.0f, true));
  53886. }
  53887. if (button.hasKeyboardFocus (false))
  53888. {
  53889. g.setColour (textColour.withAlpha (0.4f));
  53890. g.drawRect (0, 0, width, height);
  53891. }
  53892. }
  53893. static void createRoundedPath (Path& p,
  53894. const float x, const float y,
  53895. const float w, const float h,
  53896. const float cs,
  53897. const bool curveTopLeft, const bool curveTopRight,
  53898. const bool curveBottomLeft, const bool curveBottomRight) throw()
  53899. {
  53900. const float cs2 = 2.0f * cs;
  53901. if (curveTopLeft)
  53902. {
  53903. p.startNewSubPath (x, y + cs);
  53904. p.addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f);
  53905. }
  53906. else
  53907. {
  53908. p.startNewSubPath (x, y);
  53909. }
  53910. if (curveTopRight)
  53911. {
  53912. p.lineTo (x + w - cs, y);
  53913. p.addArc (x + w - cs2, y, cs2, cs2, 0.0f, float_Pi * 0.5f);
  53914. }
  53915. else
  53916. {
  53917. p.lineTo (x + w, y);
  53918. }
  53919. if (curveBottomRight)
  53920. {
  53921. p.lineTo (x + w, y + h - cs);
  53922. p.addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
  53923. }
  53924. else
  53925. {
  53926. p.lineTo (x + w, y + h);
  53927. }
  53928. if (curveBottomLeft)
  53929. {
  53930. p.lineTo (x + cs, y + h);
  53931. p.addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
  53932. }
  53933. else
  53934. {
  53935. p.lineTo (x, y + h);
  53936. }
  53937. p.closeSubPath();
  53938. }
  53939. void LookAndFeel::drawShinyButtonShape (Graphics& g,
  53940. float x, float y, float w, float h,
  53941. float maxCornerSize,
  53942. const Colour& baseColour,
  53943. const float strokeWidth,
  53944. const bool flatOnLeft,
  53945. const bool flatOnRight,
  53946. const bool flatOnTop,
  53947. const bool flatOnBottom) throw()
  53948. {
  53949. if (w <= strokeWidth * 1.1f || h <= strokeWidth * 1.1f)
  53950. return;
  53951. const float cs = jmin (maxCornerSize, w * 0.5f, h * 0.5f);
  53952. Path outline;
  53953. createRoundedPath (outline, x, y, w, h, cs,
  53954. ! (flatOnLeft || flatOnTop),
  53955. ! (flatOnRight || flatOnTop),
  53956. ! (flatOnLeft || flatOnBottom),
  53957. ! (flatOnRight || flatOnBottom));
  53958. ColourGradient cg (baseColour, 0.0f, y,
  53959. baseColour.overlaidWith (Colour (0x070000ff)), 0.0f, y + h,
  53960. false);
  53961. cg.addColour (0.5, baseColour.overlaidWith (Colour (0x33ffffff)));
  53962. cg.addColour (0.51, baseColour.overlaidWith (Colour (0x110000ff)));
  53963. g.setGradientFill (cg);
  53964. g.fillPath (outline);
  53965. g.setColour (Colour (0x80000000));
  53966. g.strokePath (outline, PathStrokeType (strokeWidth));
  53967. }
  53968. void LookAndFeel::drawGlassSphere (Graphics& g,
  53969. const float x, const float y,
  53970. const float diameter,
  53971. const Colour& colour,
  53972. const float outlineThickness) throw()
  53973. {
  53974. if (diameter <= outlineThickness)
  53975. return;
  53976. Path p;
  53977. p.addEllipse (x, y, diameter, diameter);
  53978. {
  53979. ColourGradient cg (Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y,
  53980. Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y + diameter, false);
  53981. cg.addColour (0.4, Colours::white.overlaidWith (colour));
  53982. g.setGradientFill (cg);
  53983. g.fillPath (p);
  53984. }
  53985. g.setGradientFill (ColourGradient (Colours::white, 0, y + diameter * 0.06f,
  53986. Colours::transparentWhite, 0, y + diameter * 0.3f, false));
  53987. g.fillEllipse (x + diameter * 0.2f, y + diameter * 0.05f, diameter * 0.6f, diameter * 0.4f);
  53988. ColourGradient cg (Colours::transparentBlack,
  53989. x + diameter * 0.5f, y + diameter * 0.5f,
  53990. Colours::black.withAlpha (0.5f * outlineThickness * colour.getFloatAlpha()),
  53991. x, y + diameter * 0.5f, true);
  53992. cg.addColour (0.7, Colours::transparentBlack);
  53993. cg.addColour (0.8, Colours::black.withAlpha (0.1f * outlineThickness));
  53994. g.setGradientFill (cg);
  53995. g.fillPath (p);
  53996. g.setColour (Colours::black.withAlpha (0.5f * colour.getFloatAlpha()));
  53997. g.drawEllipse (x, y, diameter, diameter, outlineThickness);
  53998. }
  53999. void LookAndFeel::drawGlassPointer (Graphics& g,
  54000. const float x, const float y,
  54001. const float diameter,
  54002. const Colour& colour, const float outlineThickness,
  54003. const int direction) throw()
  54004. {
  54005. if (diameter <= outlineThickness)
  54006. return;
  54007. Path p;
  54008. p.startNewSubPath (x + diameter * 0.5f, y);
  54009. p.lineTo (x + diameter, y + diameter * 0.6f);
  54010. p.lineTo (x + diameter, y + diameter);
  54011. p.lineTo (x, y + diameter);
  54012. p.lineTo (x, y + diameter * 0.6f);
  54013. p.closeSubPath();
  54014. p.applyTransform (AffineTransform::rotation (direction * (float_Pi * 0.5f), x + diameter * 0.5f, y + diameter * 0.5f));
  54015. {
  54016. ColourGradient cg (Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y,
  54017. Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y + diameter, false);
  54018. cg.addColour (0.4, Colours::white.overlaidWith (colour));
  54019. g.setGradientFill (cg);
  54020. g.fillPath (p);
  54021. }
  54022. ColourGradient cg (Colours::transparentBlack,
  54023. x + diameter * 0.5f, y + diameter * 0.5f,
  54024. Colours::black.withAlpha (0.5f * outlineThickness * colour.getFloatAlpha()),
  54025. x - diameter * 0.2f, y + diameter * 0.5f, true);
  54026. cg.addColour (0.5, Colours::transparentBlack);
  54027. cg.addColour (0.7, Colours::black.withAlpha (0.07f * outlineThickness));
  54028. g.setGradientFill (cg);
  54029. g.fillPath (p);
  54030. g.setColour (Colours::black.withAlpha (0.5f * colour.getFloatAlpha()));
  54031. g.strokePath (p, PathStrokeType (outlineThickness));
  54032. }
  54033. void LookAndFeel::drawGlassLozenge (Graphics& g,
  54034. const float x, const float y,
  54035. const float width, const float height,
  54036. const Colour& colour,
  54037. const float outlineThickness,
  54038. const float cornerSize,
  54039. const bool flatOnLeft,
  54040. const bool flatOnRight,
  54041. const bool flatOnTop,
  54042. const bool flatOnBottom) throw()
  54043. {
  54044. if (width <= outlineThickness || height <= outlineThickness)
  54045. return;
  54046. const int intX = (int) x;
  54047. const int intY = (int) y;
  54048. const int intW = (int) width;
  54049. const int intH = (int) height;
  54050. const float cs = cornerSize < 0 ? jmin (width * 0.5f, height * 0.5f) : cornerSize;
  54051. const float edgeBlurRadius = height * 0.75f + (height - cs * 2.0f);
  54052. const int intEdge = (int) edgeBlurRadius;
  54053. Path outline;
  54054. createRoundedPath (outline, x, y, width, height, cs,
  54055. ! (flatOnLeft || flatOnTop),
  54056. ! (flatOnRight || flatOnTop),
  54057. ! (flatOnLeft || flatOnBottom),
  54058. ! (flatOnRight || flatOnBottom));
  54059. {
  54060. ColourGradient cg (colour.darker (0.2f), 0, y,
  54061. colour.darker (0.2f), 0, y + height, false);
  54062. cg.addColour (0.03, colour.withMultipliedAlpha (0.3f));
  54063. cg.addColour (0.4, colour);
  54064. cg.addColour (0.97, colour.withMultipliedAlpha (0.3f));
  54065. g.setGradientFill (cg);
  54066. g.fillPath (outline);
  54067. }
  54068. ColourGradient cg (Colours::transparentBlack, x + edgeBlurRadius, y + height * 0.5f,
  54069. colour.darker (0.2f), x, y + height * 0.5f, true);
  54070. cg.addColour (jlimit (0.0, 1.0, 1.0 - (cs * 0.5f) / edgeBlurRadius), Colours::transparentBlack);
  54071. cg.addColour (jlimit (0.0, 1.0, 1.0 - (cs * 0.25f) / edgeBlurRadius), colour.darker (0.2f).withMultipliedAlpha (0.3f));
  54072. if (! (flatOnLeft || flatOnTop || flatOnBottom))
  54073. {
  54074. g.saveState();
  54075. g.setGradientFill (cg);
  54076. g.reduceClipRegion (intX, intY, intEdge, intH);
  54077. g.fillPath (outline);
  54078. g.restoreState();
  54079. }
  54080. if (! (flatOnRight || flatOnTop || flatOnBottom))
  54081. {
  54082. cg.x1 = x + width - edgeBlurRadius;
  54083. cg.x2 = x + width;
  54084. g.saveState();
  54085. g.setGradientFill (cg);
  54086. g.reduceClipRegion (intX + intW - intEdge, intY, 2 + intEdge, intH);
  54087. g.fillPath (outline);
  54088. g.restoreState();
  54089. }
  54090. {
  54091. const float leftIndent = flatOnLeft ? 0.0f : cs * 0.4f;
  54092. const float rightIndent = flatOnRight ? 0.0f : cs * 0.4f;
  54093. Path highlight;
  54094. createRoundedPath (highlight,
  54095. x + leftIndent,
  54096. y + cs * 0.1f,
  54097. width - (leftIndent + rightIndent),
  54098. height * 0.4f, cs * 0.4f,
  54099. ! (flatOnLeft || flatOnTop),
  54100. ! (flatOnRight || flatOnTop),
  54101. ! (flatOnLeft || flatOnBottom),
  54102. ! (flatOnRight || flatOnBottom));
  54103. g.setGradientFill (ColourGradient (colour.brighter (10.0f), 0, y + height * 0.06f,
  54104. Colours::transparentWhite, 0, y + height * 0.4f, false));
  54105. g.fillPath (highlight);
  54106. }
  54107. g.setColour (colour.darker().withMultipliedAlpha (1.5f));
  54108. g.strokePath (outline, PathStrokeType (outlineThickness));
  54109. }
  54110. END_JUCE_NAMESPACE
  54111. /*** End of inlined file: juce_LookAndFeel.cpp ***/
  54112. /*** Start of inlined file: juce_OldSchoolLookAndFeel.cpp ***/
  54113. BEGIN_JUCE_NAMESPACE
  54114. OldSchoolLookAndFeel::OldSchoolLookAndFeel()
  54115. {
  54116. setColour (TextButton::buttonColourId, Colour (0xffbbbbff));
  54117. setColour (ListBox::outlineColourId, findColour (ComboBox::outlineColourId));
  54118. setColour (ScrollBar::thumbColourId, Colour (0xffbbbbdd));
  54119. setColour (ScrollBar::backgroundColourId, Colours::transparentBlack);
  54120. setColour (Slider::thumbColourId, Colours::white);
  54121. setColour (Slider::trackColourId, Colour (0x7f000000));
  54122. setColour (Slider::textBoxOutlineColourId, Colours::grey);
  54123. setColour (ProgressBar::backgroundColourId, Colours::white.withAlpha (0.6f));
  54124. setColour (ProgressBar::foregroundColourId, Colours::green.withAlpha (0.7f));
  54125. setColour (PopupMenu::backgroundColourId, Colour (0xffeef5f8));
  54126. setColour (PopupMenu::highlightedBackgroundColourId, Colour (0xbfa4c2ce));
  54127. setColour (PopupMenu::highlightedTextColourId, Colours::black);
  54128. setColour (TextEditor::focusedOutlineColourId, findColour (TextButton::buttonColourId));
  54129. scrollbarShadow.setShadowProperties (2.2f, 0.5f, 0, 0);
  54130. }
  54131. OldSchoolLookAndFeel::~OldSchoolLookAndFeel()
  54132. {
  54133. }
  54134. void OldSchoolLookAndFeel::drawButtonBackground (Graphics& g,
  54135. Button& button,
  54136. const Colour& backgroundColour,
  54137. bool isMouseOverButton,
  54138. bool isButtonDown)
  54139. {
  54140. const int width = button.getWidth();
  54141. const int height = button.getHeight();
  54142. const float indent = 2.0f;
  54143. const int cornerSize = jmin (roundToInt (width * 0.4f),
  54144. roundToInt (height * 0.4f));
  54145. Path p;
  54146. p.addRoundedRectangle (indent, indent,
  54147. width - indent * 2.0f,
  54148. height - indent * 2.0f,
  54149. (float) cornerSize);
  54150. Colour bc (backgroundColour.withMultipliedSaturation (0.3f));
  54151. if (isMouseOverButton)
  54152. {
  54153. if (isButtonDown)
  54154. bc = bc.brighter();
  54155. else if (bc.getBrightness() > 0.5f)
  54156. bc = bc.darker (0.1f);
  54157. else
  54158. bc = bc.brighter (0.1f);
  54159. }
  54160. g.setColour (bc);
  54161. g.fillPath (p);
  54162. g.setColour (bc.contrasting().withAlpha ((isMouseOverButton) ? 0.6f : 0.4f));
  54163. g.strokePath (p, PathStrokeType ((isMouseOverButton) ? 2.0f : 1.4f));
  54164. }
  54165. void OldSchoolLookAndFeel::drawTickBox (Graphics& g,
  54166. Component& /*component*/,
  54167. int x, int y, int w, int h,
  54168. const bool ticked,
  54169. const bool isEnabled,
  54170. const bool /*isMouseOverButton*/,
  54171. const bool isButtonDown)
  54172. {
  54173. Path box;
  54174. box.addRoundedRectangle (0.0f, 2.0f, 6.0f, 6.0f, 1.0f);
  54175. g.setColour (isEnabled ? Colours::blue.withAlpha (isButtonDown ? 0.3f : 0.1f)
  54176. : Colours::lightgrey.withAlpha (0.1f));
  54177. AffineTransform trans (AffineTransform::scale (w / 9.0f, h / 9.0f)
  54178. .translated ((float) x, (float) y));
  54179. g.fillPath (box, trans);
  54180. g.setColour (Colours::black.withAlpha (0.6f));
  54181. g.strokePath (box, PathStrokeType (0.9f), trans);
  54182. if (ticked)
  54183. {
  54184. Path tick;
  54185. tick.startNewSubPath (1.5f, 3.0f);
  54186. tick.lineTo (3.0f, 6.0f);
  54187. tick.lineTo (6.0f, 0.0f);
  54188. g.setColour (isEnabled ? Colours::black : Colours::grey);
  54189. g.strokePath (tick, PathStrokeType (2.5f), trans);
  54190. }
  54191. }
  54192. void OldSchoolLookAndFeel::drawToggleButton (Graphics& g,
  54193. ToggleButton& button,
  54194. bool isMouseOverButton,
  54195. bool isButtonDown)
  54196. {
  54197. if (button.hasKeyboardFocus (true))
  54198. {
  54199. g.setColour (button.findColour (TextEditor::focusedOutlineColourId));
  54200. g.drawRect (0, 0, button.getWidth(), button.getHeight());
  54201. }
  54202. const int tickWidth = jmin (20, button.getHeight() - 4);
  54203. drawTickBox (g, button, 4, (button.getHeight() - tickWidth) / 2,
  54204. tickWidth, tickWidth,
  54205. button.getToggleState(),
  54206. button.isEnabled(),
  54207. isMouseOverButton,
  54208. isButtonDown);
  54209. g.setColour (button.findColour (ToggleButton::textColourId));
  54210. g.setFont (jmin (15.0f, button.getHeight() * 0.6f));
  54211. if (! button.isEnabled())
  54212. g.setOpacity (0.5f);
  54213. const int textX = tickWidth + 5;
  54214. g.drawFittedText (button.getButtonText(),
  54215. textX, 4,
  54216. button.getWidth() - textX - 2, button.getHeight() - 8,
  54217. Justification::centredLeft, 10);
  54218. }
  54219. void OldSchoolLookAndFeel::drawProgressBar (Graphics& g, ProgressBar& progressBar,
  54220. int width, int height,
  54221. double progress, const String& textToShow)
  54222. {
  54223. if (progress < 0 || progress >= 1.0)
  54224. {
  54225. LookAndFeel::drawProgressBar (g, progressBar, width, height, progress, textToShow);
  54226. }
  54227. else
  54228. {
  54229. const Colour background (progressBar.findColour (ProgressBar::backgroundColourId));
  54230. const Colour foreground (progressBar.findColour (ProgressBar::foregroundColourId));
  54231. g.fillAll (background);
  54232. g.setColour (foreground);
  54233. g.fillRect (1, 1,
  54234. jlimit (0, width - 2, roundToInt (progress * (width - 2))),
  54235. height - 2);
  54236. if (textToShow.isNotEmpty())
  54237. {
  54238. g.setColour (Colour::contrasting (background, foreground));
  54239. g.setFont (height * 0.6f);
  54240. g.drawText (textToShow, 0, 0, width, height, Justification::centred, false);
  54241. }
  54242. }
  54243. }
  54244. void OldSchoolLookAndFeel::drawScrollbarButton (Graphics& g,
  54245. ScrollBar& bar,
  54246. int width, int height,
  54247. int buttonDirection,
  54248. bool isScrollbarVertical,
  54249. bool isMouseOverButton,
  54250. bool isButtonDown)
  54251. {
  54252. if (isScrollbarVertical)
  54253. width -= 2;
  54254. else
  54255. height -= 2;
  54256. Path p;
  54257. if (buttonDirection == 0)
  54258. p.addTriangle (width * 0.5f, height * 0.2f,
  54259. width * 0.1f, height * 0.7f,
  54260. width * 0.9f, height * 0.7f);
  54261. else if (buttonDirection == 1)
  54262. p.addTriangle (width * 0.8f, height * 0.5f,
  54263. width * 0.3f, height * 0.1f,
  54264. width * 0.3f, height * 0.9f);
  54265. else if (buttonDirection == 2)
  54266. p.addTriangle (width * 0.5f, height * 0.8f,
  54267. width * 0.1f, height * 0.3f,
  54268. width * 0.9f, height * 0.3f);
  54269. else if (buttonDirection == 3)
  54270. p.addTriangle (width * 0.2f, height * 0.5f,
  54271. width * 0.7f, height * 0.1f,
  54272. width * 0.7f, height * 0.9f);
  54273. if (isButtonDown)
  54274. g.setColour (Colours::white);
  54275. else if (isMouseOverButton)
  54276. g.setColour (Colours::white.withAlpha (0.7f));
  54277. else
  54278. g.setColour (bar.findColour (ScrollBar::thumbColourId).withAlpha (0.5f));
  54279. g.fillPath (p);
  54280. g.setColour (Colours::black.withAlpha (0.5f));
  54281. g.strokePath (p, PathStrokeType (0.5f));
  54282. }
  54283. void OldSchoolLookAndFeel::drawScrollbar (Graphics& g,
  54284. ScrollBar& bar,
  54285. int x, int y,
  54286. int width, int height,
  54287. bool isScrollbarVertical,
  54288. int thumbStartPosition,
  54289. int thumbSize,
  54290. bool isMouseOver,
  54291. bool isMouseDown)
  54292. {
  54293. g.fillAll (bar.findColour (ScrollBar::backgroundColourId));
  54294. g.setColour (bar.findColour (ScrollBar::thumbColourId)
  54295. .withAlpha ((isMouseOver || isMouseDown) ? 0.4f : 0.15f));
  54296. if (thumbSize > 0.0f)
  54297. {
  54298. Rectangle<int> thumb;
  54299. if (isScrollbarVertical)
  54300. {
  54301. width -= 2;
  54302. g.fillRect (x + roundToInt (width * 0.35f), y,
  54303. roundToInt (width * 0.3f), height);
  54304. thumb.setBounds (x + 1, thumbStartPosition,
  54305. width - 2, thumbSize);
  54306. }
  54307. else
  54308. {
  54309. height -= 2;
  54310. g.fillRect (x, y + roundToInt (height * 0.35f),
  54311. width, roundToInt (height * 0.3f));
  54312. thumb.setBounds (thumbStartPosition, y + 1,
  54313. thumbSize, height - 2);
  54314. }
  54315. g.setColour (bar.findColour (ScrollBar::thumbColourId)
  54316. .withAlpha ((isMouseOver || isMouseDown) ? 0.95f : 0.7f));
  54317. g.fillRect (thumb);
  54318. g.setColour (Colours::black.withAlpha ((isMouseOver || isMouseDown) ? 0.4f : 0.25f));
  54319. g.drawRect (thumb.getX(), thumb.getY(), thumb.getWidth(), thumb.getHeight());
  54320. if (thumbSize > 16)
  54321. {
  54322. for (int i = 3; --i >= 0;)
  54323. {
  54324. const float linePos = thumbStartPosition + thumbSize / 2 + (i - 1) * 4.0f;
  54325. g.setColour (Colours::black.withAlpha (0.15f));
  54326. if (isScrollbarVertical)
  54327. {
  54328. g.drawLine (x + width * 0.2f, linePos, width * 0.8f, linePos);
  54329. g.setColour (Colours::white.withAlpha (0.15f));
  54330. g.drawLine (width * 0.2f, linePos - 1, width * 0.8f, linePos - 1);
  54331. }
  54332. else
  54333. {
  54334. g.drawLine (linePos, height * 0.2f, linePos, height * 0.8f);
  54335. g.setColour (Colours::white.withAlpha (0.15f));
  54336. g.drawLine (linePos - 1, height * 0.2f, linePos - 1, height * 0.8f);
  54337. }
  54338. }
  54339. }
  54340. }
  54341. }
  54342. ImageEffectFilter* OldSchoolLookAndFeel::getScrollbarEffect()
  54343. {
  54344. return &scrollbarShadow;
  54345. }
  54346. void OldSchoolLookAndFeel::drawPopupMenuBackground (Graphics& g, int width, int height)
  54347. {
  54348. g.fillAll (findColour (PopupMenu::backgroundColourId));
  54349. g.setColour (Colours::black.withAlpha (0.6f));
  54350. g.drawRect (0, 0, width, height);
  54351. }
  54352. void OldSchoolLookAndFeel::drawMenuBarBackground (Graphics& g, int /*width*/, int /*height*/,
  54353. bool, MenuBarComponent& menuBar)
  54354. {
  54355. g.fillAll (menuBar.findColour (PopupMenu::backgroundColourId));
  54356. }
  54357. void OldSchoolLookAndFeel::drawTextEditorOutline (Graphics& g, int width, int height, TextEditor& textEditor)
  54358. {
  54359. if (textEditor.isEnabled())
  54360. {
  54361. g.setColour (textEditor.findColour (TextEditor::outlineColourId));
  54362. g.drawRect (0, 0, width, height);
  54363. }
  54364. }
  54365. void OldSchoolLookAndFeel::drawComboBox (Graphics& g, int width, int height,
  54366. const bool isButtonDown,
  54367. int buttonX, int buttonY,
  54368. int buttonW, int buttonH,
  54369. ComboBox& box)
  54370. {
  54371. g.fillAll (box.findColour (ComboBox::backgroundColourId));
  54372. g.setColour (box.findColour ((isButtonDown) ? ComboBox::buttonColourId
  54373. : ComboBox::backgroundColourId));
  54374. g.fillRect (buttonX, buttonY, buttonW, buttonH);
  54375. g.setColour (box.findColour (ComboBox::outlineColourId));
  54376. g.drawRect (0, 0, width, height);
  54377. const float arrowX = 0.2f;
  54378. const float arrowH = 0.3f;
  54379. if (box.isEnabled())
  54380. {
  54381. Path p;
  54382. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.45f - arrowH),
  54383. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.45f,
  54384. buttonX + buttonW * arrowX, buttonY + buttonH * 0.45f);
  54385. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.55f + arrowH),
  54386. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.55f,
  54387. buttonX + buttonW * arrowX, buttonY + buttonH * 0.55f);
  54388. g.setColour (box.findColour ((isButtonDown) ? ComboBox::backgroundColourId
  54389. : ComboBox::buttonColourId));
  54390. g.fillPath (p);
  54391. }
  54392. }
  54393. const Font OldSchoolLookAndFeel::getComboBoxFont (ComboBox& box)
  54394. {
  54395. Font f (jmin (15.0f, box.getHeight() * 0.85f));
  54396. f.setHorizontalScale (0.9f);
  54397. return f;
  54398. }
  54399. static void drawTriangle (Graphics& g, float x1, float y1, float x2, float y2, float x3, float y3, const Colour& fill, const Colour& outline) throw()
  54400. {
  54401. Path p;
  54402. p.addTriangle (x1, y1, x2, y2, x3, y3);
  54403. g.setColour (fill);
  54404. g.fillPath (p);
  54405. g.setColour (outline);
  54406. g.strokePath (p, PathStrokeType (0.3f));
  54407. }
  54408. void OldSchoolLookAndFeel::drawLinearSlider (Graphics& g,
  54409. int x, int y,
  54410. int w, int h,
  54411. float sliderPos,
  54412. float minSliderPos,
  54413. float maxSliderPos,
  54414. const Slider::SliderStyle style,
  54415. Slider& slider)
  54416. {
  54417. g.fillAll (slider.findColour (Slider::backgroundColourId));
  54418. if (style == Slider::LinearBar)
  54419. {
  54420. g.setColour (slider.findColour (Slider::thumbColourId));
  54421. g.fillRect (x, y, (int) sliderPos - x, h);
  54422. g.setColour (slider.findColour (Slider::textBoxTextColourId).withMultipliedAlpha (0.5f));
  54423. g.drawRect (x, y, (int) sliderPos - x, h);
  54424. }
  54425. else
  54426. {
  54427. g.setColour (slider.findColour (Slider::trackColourId)
  54428. .withMultipliedAlpha (slider.isEnabled() ? 1.0f : 0.3f));
  54429. if (slider.isHorizontal())
  54430. {
  54431. g.fillRect (x, y + roundToInt (h * 0.6f),
  54432. w, roundToInt (h * 0.2f));
  54433. }
  54434. else
  54435. {
  54436. g.fillRect (x + roundToInt (w * 0.5f - jmin (3.0f, w * 0.1f)), y,
  54437. jmin (4, roundToInt (w * 0.2f)), h);
  54438. }
  54439. float alpha = 0.35f;
  54440. if (slider.isEnabled())
  54441. alpha = slider.isMouseOverOrDragging() ? 1.0f : 0.7f;
  54442. const Colour fill (slider.findColour (Slider::thumbColourId).withAlpha (alpha));
  54443. const Colour outline (Colours::black.withAlpha (slider.isEnabled() ? 0.7f : 0.35f));
  54444. if (style == Slider::TwoValueVertical || style == Slider::ThreeValueVertical)
  54445. {
  54446. drawTriangle (g, x + w * 0.5f + jmin (4.0f, w * 0.3f), minSliderPos,
  54447. x + w * 0.5f - jmin (8.0f, w * 0.4f), minSliderPos - 7.0f,
  54448. x + w * 0.5f - jmin (8.0f, w * 0.4f), minSliderPos,
  54449. fill, outline);
  54450. drawTriangle (g, x + w * 0.5f + jmin (4.0f, w * 0.3f), maxSliderPos,
  54451. x + w * 0.5f - jmin (8.0f, w * 0.4f), maxSliderPos,
  54452. x + w * 0.5f - jmin (8.0f, w * 0.4f), maxSliderPos + 7.0f,
  54453. fill, outline);
  54454. }
  54455. else if (style == Slider::TwoValueHorizontal || style == Slider::ThreeValueHorizontal)
  54456. {
  54457. drawTriangle (g, minSliderPos, y + h * 0.6f - jmin (4.0f, h * 0.3f),
  54458. minSliderPos - 7.0f, y + h * 0.9f ,
  54459. minSliderPos, y + h * 0.9f,
  54460. fill, outline);
  54461. drawTriangle (g, maxSliderPos, y + h * 0.6f - jmin (4.0f, h * 0.3f),
  54462. maxSliderPos, y + h * 0.9f,
  54463. maxSliderPos + 7.0f, y + h * 0.9f,
  54464. fill, outline);
  54465. }
  54466. if (style == Slider::LinearHorizontal || style == Slider::ThreeValueHorizontal)
  54467. {
  54468. drawTriangle (g, sliderPos, y + h * 0.9f,
  54469. sliderPos - 7.0f, y + h * 0.2f,
  54470. sliderPos + 7.0f, y + h * 0.2f,
  54471. fill, outline);
  54472. }
  54473. else if (style == Slider::LinearVertical || style == Slider::ThreeValueVertical)
  54474. {
  54475. drawTriangle (g, x + w * 0.5f - jmin (4.0f, w * 0.3f), sliderPos,
  54476. x + w * 0.5f + jmin (8.0f, w * 0.4f), sliderPos - 7.0f,
  54477. x + w * 0.5f + jmin (8.0f, w * 0.4f), sliderPos + 7.0f,
  54478. fill, outline);
  54479. }
  54480. }
  54481. }
  54482. Button* OldSchoolLookAndFeel::createSliderButton (const bool isIncrement)
  54483. {
  54484. if (isIncrement)
  54485. return new ArrowButton ("u", 0.75f, Colours::white.withAlpha (0.8f));
  54486. else
  54487. return new ArrowButton ("d", 0.25f, Colours::white.withAlpha (0.8f));
  54488. }
  54489. ImageEffectFilter* OldSchoolLookAndFeel::getSliderEffect()
  54490. {
  54491. return &scrollbarShadow;
  54492. }
  54493. int OldSchoolLookAndFeel::getSliderThumbRadius (Slider&)
  54494. {
  54495. return 8;
  54496. }
  54497. void OldSchoolLookAndFeel::drawCornerResizer (Graphics& g,
  54498. int w, int h,
  54499. bool isMouseOver,
  54500. bool isMouseDragging)
  54501. {
  54502. g.setColour ((isMouseOver || isMouseDragging) ? Colours::lightgrey
  54503. : Colours::darkgrey);
  54504. const float lineThickness = jmin (w, h) * 0.1f;
  54505. for (float i = 0.0f; i < 1.0f; i += 0.3f)
  54506. {
  54507. g.drawLine (w * i,
  54508. h + 1.0f,
  54509. w + 1.0f,
  54510. h * i,
  54511. lineThickness);
  54512. }
  54513. }
  54514. Button* OldSchoolLookAndFeel::createDocumentWindowButton (int buttonType)
  54515. {
  54516. Path shape;
  54517. if (buttonType == DocumentWindow::closeButton)
  54518. {
  54519. shape.addLineSegment (0.0f, 0.0f, 1.0f, 1.0f, 0.35f);
  54520. shape.addLineSegment (1.0f, 0.0f, 0.0f, 1.0f, 0.35f);
  54521. ShapeButton* const b = new ShapeButton ("close",
  54522. Colour (0x7fff3333),
  54523. Colour (0xd7ff3333),
  54524. Colour (0xf7ff3333));
  54525. b->setShape (shape, true, true, true);
  54526. return b;
  54527. }
  54528. else if (buttonType == DocumentWindow::minimiseButton)
  54529. {
  54530. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, 0.25f);
  54531. DrawableButton* b = new DrawableButton ("minimise", DrawableButton::ImageFitted);
  54532. DrawablePath dp;
  54533. dp.setPath (shape);
  54534. dp.setFill (Colours::black.withAlpha (0.3f));
  54535. b->setImages (&dp);
  54536. return b;
  54537. }
  54538. else if (buttonType == DocumentWindow::maximiseButton)
  54539. {
  54540. shape.addLineSegment (0.5f, 0.0f, 0.5f, 1.0f, 0.25f);
  54541. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, 0.25f);
  54542. DrawableButton* b = new DrawableButton ("maximise", DrawableButton::ImageFitted);
  54543. DrawablePath dp;
  54544. dp.setPath (shape);
  54545. dp.setFill (Colours::black.withAlpha (0.3f));
  54546. b->setImages (&dp);
  54547. return b;
  54548. }
  54549. jassertfalse
  54550. return 0;
  54551. }
  54552. void OldSchoolLookAndFeel::positionDocumentWindowButtons (DocumentWindow&,
  54553. int titleBarX,
  54554. int titleBarY,
  54555. int titleBarW,
  54556. int titleBarH,
  54557. Button* minimiseButton,
  54558. Button* maximiseButton,
  54559. Button* closeButton,
  54560. bool positionTitleBarButtonsOnLeft)
  54561. {
  54562. titleBarY += titleBarH / 8;
  54563. titleBarH -= titleBarH / 4;
  54564. const int buttonW = titleBarH;
  54565. int x = positionTitleBarButtonsOnLeft ? titleBarX + 4
  54566. : titleBarX + titleBarW - buttonW - 4;
  54567. if (closeButton != 0)
  54568. {
  54569. closeButton->setBounds (x, titleBarY, buttonW, titleBarH);
  54570. x += positionTitleBarButtonsOnLeft ? buttonW + buttonW / 5
  54571. : -(buttonW + buttonW / 5);
  54572. }
  54573. if (positionTitleBarButtonsOnLeft)
  54574. swapVariables (minimiseButton, maximiseButton);
  54575. if (maximiseButton != 0)
  54576. {
  54577. maximiseButton->setBounds (x, titleBarY - 2, buttonW, titleBarH);
  54578. x += positionTitleBarButtonsOnLeft ? buttonW : -buttonW;
  54579. }
  54580. if (minimiseButton != 0)
  54581. minimiseButton->setBounds (x, titleBarY - 2, buttonW, titleBarH);
  54582. }
  54583. END_JUCE_NAMESPACE
  54584. /*** End of inlined file: juce_OldSchoolLookAndFeel.cpp ***/
  54585. /*** Start of inlined file: juce_MenuBarComponent.cpp ***/
  54586. BEGIN_JUCE_NAMESPACE
  54587. class DummyMenuComponent : public Component
  54588. {
  54589. DummyMenuComponent (const DummyMenuComponent&);
  54590. const DummyMenuComponent& operator= (const DummyMenuComponent&);
  54591. public:
  54592. DummyMenuComponent() {}
  54593. ~DummyMenuComponent() {}
  54594. void inputAttemptWhenModal()
  54595. {
  54596. exitModalState (0);
  54597. }
  54598. };
  54599. MenuBarComponent::MenuBarComponent (MenuBarModel* model_)
  54600. : model (0),
  54601. itemUnderMouse (-1),
  54602. currentPopupIndex (-1),
  54603. indexToShowAgain (-1),
  54604. lastMouseX (0),
  54605. lastMouseY (0),
  54606. inModalState (false)
  54607. {
  54608. setRepaintsOnMouseActivity (true);
  54609. setWantsKeyboardFocus (false);
  54610. setMouseClickGrabsKeyboardFocus (false);
  54611. setModel (model_);
  54612. }
  54613. MenuBarComponent::~MenuBarComponent()
  54614. {
  54615. setModel (0);
  54616. Desktop::getInstance().removeGlobalMouseListener (this);
  54617. currentPopup = 0;
  54618. }
  54619. void MenuBarComponent::setModel (MenuBarModel* const newModel)
  54620. {
  54621. if (model != newModel)
  54622. {
  54623. if (model != 0)
  54624. model->removeListener (this);
  54625. model = newModel;
  54626. if (model != 0)
  54627. model->addListener (this);
  54628. repaint();
  54629. menuBarItemsChanged (0);
  54630. }
  54631. }
  54632. void MenuBarComponent::paint (Graphics& g)
  54633. {
  54634. const bool isMouseOverBar = currentPopupIndex >= 0 || itemUnderMouse >= 0 || isMouseOver();
  54635. getLookAndFeel().drawMenuBarBackground (g,
  54636. getWidth(),
  54637. getHeight(),
  54638. isMouseOverBar,
  54639. *this);
  54640. if (model != 0)
  54641. {
  54642. for (int i = 0; i < menuNames.size(); ++i)
  54643. {
  54644. g.saveState();
  54645. g.setOrigin (xPositions [i], 0);
  54646. g.reduceClipRegion (0, 0, xPositions[i + 1] - xPositions[i], getHeight());
  54647. getLookAndFeel().drawMenuBarItem (g,
  54648. xPositions[i + 1] - xPositions[i],
  54649. getHeight(),
  54650. i,
  54651. menuNames[i],
  54652. i == itemUnderMouse,
  54653. i == currentPopupIndex,
  54654. isMouseOverBar,
  54655. *this);
  54656. g.restoreState();
  54657. }
  54658. }
  54659. }
  54660. void MenuBarComponent::resized()
  54661. {
  54662. xPositions.clear();
  54663. int x = 2;
  54664. xPositions.add (x);
  54665. for (int i = 0; i < menuNames.size(); ++i)
  54666. {
  54667. x += getLookAndFeel().getMenuBarItemWidth (*this, i, menuNames[i]);
  54668. xPositions.add (x);
  54669. }
  54670. }
  54671. int MenuBarComponent::getItemAt (const int x, const int y)
  54672. {
  54673. for (int i = 0; i < xPositions.size(); ++i)
  54674. if (x >= xPositions[i] && x < xPositions[i + 1])
  54675. return reallyContains (x, y, true) ? i : -1;
  54676. return -1;
  54677. }
  54678. void MenuBarComponent::repaintMenuItem (int index)
  54679. {
  54680. if (((unsigned int) index) < (unsigned int) xPositions.size())
  54681. {
  54682. const int x1 = xPositions [index];
  54683. const int x2 = xPositions [index + 1];
  54684. repaint (x1 - 2, 0, x2 - x1 + 4, getHeight());
  54685. }
  54686. }
  54687. void MenuBarComponent::updateItemUnderMouse (int x, int y)
  54688. {
  54689. const int newItem = getItemAt (x, y);
  54690. if (itemUnderMouse != newItem)
  54691. {
  54692. repaintMenuItem (itemUnderMouse);
  54693. itemUnderMouse = newItem;
  54694. repaintMenuItem (itemUnderMouse);
  54695. }
  54696. }
  54697. void MenuBarComponent::hideCurrentMenu()
  54698. {
  54699. currentPopup = 0;
  54700. repaint();
  54701. }
  54702. void MenuBarComponent::showMenu (int index)
  54703. {
  54704. if (index != currentPopupIndex)
  54705. {
  54706. if (inModalState)
  54707. {
  54708. hideCurrentMenu();
  54709. indexToShowAgain = index;
  54710. return;
  54711. }
  54712. indexToShowAgain = -1;
  54713. currentPopupIndex = -1;
  54714. itemUnderMouse = index;
  54715. currentPopup = 0;
  54716. menuBarItemsChanged (0);
  54717. Component* const prevFocused = getCurrentlyFocusedComponent();
  54718. ScopedPointer <ComponentDeletionWatcher> prevCompDeletionChecker;
  54719. if (prevFocused != 0)
  54720. prevCompDeletionChecker = new ComponentDeletionWatcher (prevFocused);
  54721. ComponentDeletionWatcher deletionChecker (this);
  54722. enterModalState (false);
  54723. inModalState = true;
  54724. int result = 0;
  54725. ApplicationCommandManager* managerOfChosenCommand = 0;
  54726. Desktop::getInstance().addGlobalMouseListener (this);
  54727. for (;;)
  54728. {
  54729. const int x = getScreenX() + xPositions [itemUnderMouse];
  54730. const int w = xPositions [itemUnderMouse + 1] - xPositions [itemUnderMouse];
  54731. currentPopupIndex = itemUnderMouse;
  54732. indexToShowAgain = -1;
  54733. repaint();
  54734. if (((unsigned int) itemUnderMouse) < (unsigned int) menuNames.size())
  54735. {
  54736. PopupMenu m (model->getMenuForIndex (itemUnderMouse,
  54737. menuNames [itemUnderMouse]));
  54738. if (m.lookAndFeel == 0)
  54739. m.setLookAndFeel (&getLookAndFeel());
  54740. currentPopup = m.createMenuComponent (x, getScreenY(),
  54741. w, getHeight(),
  54742. 0, w, 0, 0,
  54743. true, this,
  54744. &managerOfChosenCommand,
  54745. this);
  54746. }
  54747. if (currentPopup == 0)
  54748. {
  54749. currentPopup = new DummyMenuComponent();
  54750. addAndMakeVisible (currentPopup);
  54751. }
  54752. currentPopup->enterModalState (false);
  54753. currentPopup->toFront (false); // need to do this after making it modal, or it could
  54754. // be stuck behind other comps that are already modal..
  54755. result = currentPopup->runModalLoop();
  54756. if (deletionChecker.hasBeenDeleted())
  54757. return;
  54758. const int lastPopupIndex = currentPopupIndex;
  54759. currentPopup = 0;
  54760. currentPopupIndex = -1;
  54761. if (result != 0)
  54762. {
  54763. topLevelIndexClicked = lastPopupIndex;
  54764. break;
  54765. }
  54766. else if (indexToShowAgain >= 0)
  54767. {
  54768. menuBarItemsChanged (0);
  54769. repaint();
  54770. itemUnderMouse = indexToShowAgain;
  54771. if (((unsigned int) itemUnderMouse) >= (unsigned int) menuNames.size())
  54772. break;
  54773. }
  54774. else
  54775. {
  54776. break;
  54777. }
  54778. }
  54779. Desktop::getInstance().removeGlobalMouseListener (this);
  54780. inModalState = false;
  54781. exitModalState (0);
  54782. if (prevCompDeletionChecker != 0 && ! prevCompDeletionChecker->hasBeenDeleted())
  54783. prevFocused->grabKeyboardFocus();
  54784. int mx, my;
  54785. getMouseXYRelative (mx, my);
  54786. updateItemUnderMouse (mx, my);
  54787. repaint();
  54788. if (result != 0)
  54789. {
  54790. if (managerOfChosenCommand != 0)
  54791. {
  54792. ApplicationCommandTarget::InvocationInfo info (result);
  54793. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  54794. managerOfChosenCommand->invoke (info, true);
  54795. }
  54796. postCommandMessage (result);
  54797. }
  54798. }
  54799. }
  54800. void MenuBarComponent::handleCommandMessage (int commandId)
  54801. {
  54802. if (model != 0)
  54803. model->menuItemSelected (commandId, topLevelIndexClicked);
  54804. }
  54805. void MenuBarComponent::mouseEnter (const MouseEvent& e)
  54806. {
  54807. if (e.eventComponent == this)
  54808. updateItemUnderMouse (e.x, e.y);
  54809. }
  54810. void MenuBarComponent::mouseExit (const MouseEvent& e)
  54811. {
  54812. if (e.eventComponent == this)
  54813. updateItemUnderMouse (e.x, e.y);
  54814. }
  54815. void MenuBarComponent::mouseDown (const MouseEvent& e)
  54816. {
  54817. const MouseEvent e2 (e.getEventRelativeTo (this));
  54818. if (currentPopupIndex < 0)
  54819. {
  54820. updateItemUnderMouse (e2.x, e2.y);
  54821. currentPopupIndex = -2;
  54822. showMenu (itemUnderMouse);
  54823. }
  54824. }
  54825. void MenuBarComponent::mouseDrag (const MouseEvent& e)
  54826. {
  54827. const MouseEvent e2 (e.getEventRelativeTo (this));
  54828. const int item = getItemAt (e2.x, e2.y);
  54829. if (item >= 0)
  54830. showMenu (item);
  54831. }
  54832. void MenuBarComponent::mouseUp (const MouseEvent& e)
  54833. {
  54834. const MouseEvent e2 (e.getEventRelativeTo (this));
  54835. updateItemUnderMouse (e2.x, e2.y);
  54836. if (itemUnderMouse < 0 && dynamic_cast <DummyMenuComponent*> ((Component*) currentPopup) != 0)
  54837. hideCurrentMenu();
  54838. }
  54839. void MenuBarComponent::mouseMove (const MouseEvent& e)
  54840. {
  54841. const MouseEvent e2 (e.getEventRelativeTo (this));
  54842. if (lastMouseX != e2.x || lastMouseY != e2.y)
  54843. {
  54844. if (currentPopupIndex >= 0)
  54845. {
  54846. const int item = getItemAt (e2.x, e2.y);
  54847. if (item >= 0)
  54848. showMenu (item);
  54849. }
  54850. else
  54851. {
  54852. updateItemUnderMouse (e2.x, e2.y);
  54853. }
  54854. lastMouseX = e2.x;
  54855. lastMouseY = e2.y;
  54856. }
  54857. }
  54858. bool MenuBarComponent::keyPressed (const KeyPress& key)
  54859. {
  54860. bool used = false;
  54861. const int numMenus = menuNames.size();
  54862. const int currentIndex = jlimit (0, menuNames.size() - 1, currentPopupIndex);
  54863. if (key.isKeyCode (KeyPress::leftKey))
  54864. {
  54865. showMenu ((currentIndex + numMenus - 1) % numMenus);
  54866. used = true;
  54867. }
  54868. else if (key.isKeyCode (KeyPress::rightKey))
  54869. {
  54870. showMenu ((currentIndex + 1) % numMenus);
  54871. used = true;
  54872. }
  54873. return used;
  54874. }
  54875. void MenuBarComponent::inputAttemptWhenModal()
  54876. {
  54877. hideCurrentMenu();
  54878. }
  54879. void MenuBarComponent::menuBarItemsChanged (MenuBarModel* /*menuBarModel*/)
  54880. {
  54881. StringArray newNames;
  54882. if (model != 0)
  54883. newNames = model->getMenuBarNames();
  54884. if (newNames != menuNames)
  54885. {
  54886. menuNames = newNames;
  54887. repaint();
  54888. resized();
  54889. }
  54890. }
  54891. void MenuBarComponent::menuCommandInvoked (MenuBarModel* /*menuBarModel*/,
  54892. const ApplicationCommandTarget::InvocationInfo& info)
  54893. {
  54894. if (model == 0
  54895. || (info.commandFlags & ApplicationCommandInfo::dontTriggerVisualFeedback) != 0)
  54896. return;
  54897. for (int i = 0; i < menuNames.size(); ++i)
  54898. {
  54899. const PopupMenu menu (model->getMenuForIndex (i, menuNames [i]));
  54900. if (menu.containsCommandItem (info.commandID))
  54901. {
  54902. itemUnderMouse = i;
  54903. repaintMenuItem (i);
  54904. startTimer (200);
  54905. break;
  54906. }
  54907. }
  54908. }
  54909. void MenuBarComponent::timerCallback()
  54910. {
  54911. stopTimer();
  54912. int mx, my;
  54913. getMouseXYRelative (mx, my);
  54914. updateItemUnderMouse (mx, my);
  54915. }
  54916. END_JUCE_NAMESPACE
  54917. /*** End of inlined file: juce_MenuBarComponent.cpp ***/
  54918. /*** Start of inlined file: juce_MenuBarModel.cpp ***/
  54919. BEGIN_JUCE_NAMESPACE
  54920. MenuBarModel::MenuBarModel() throw()
  54921. : manager (0)
  54922. {
  54923. }
  54924. MenuBarModel::~MenuBarModel()
  54925. {
  54926. setApplicationCommandManagerToWatch (0);
  54927. }
  54928. void MenuBarModel::menuItemsChanged()
  54929. {
  54930. triggerAsyncUpdate();
  54931. }
  54932. void MenuBarModel::setApplicationCommandManagerToWatch (ApplicationCommandManager* const newManager) throw()
  54933. {
  54934. if (manager != newManager)
  54935. {
  54936. if (manager != 0)
  54937. manager->removeListener (this);
  54938. manager = newManager;
  54939. if (manager != 0)
  54940. manager->addListener (this);
  54941. }
  54942. }
  54943. void MenuBarModel::addListener (MenuBarModelListener* const newListener) throw()
  54944. {
  54945. jassert (newListener != 0);
  54946. jassert (! listeners.contains (newListener)); // trying to add a listener to the list twice!
  54947. if (newListener != 0)
  54948. listeners.add (newListener);
  54949. }
  54950. void MenuBarModel::removeListener (MenuBarModelListener* const listenerToRemove) throw()
  54951. {
  54952. // Trying to remove a listener that isn't on the list!
  54953. // If this assertion happens because this object is a dangling pointer, make sure you've not
  54954. // deleted this menu model while it's still being used by something (e.g. by a MenuBarComponent)
  54955. jassert (listeners.contains (listenerToRemove));
  54956. listeners.removeValue (listenerToRemove);
  54957. }
  54958. void MenuBarModel::handleAsyncUpdate()
  54959. {
  54960. for (int i = listeners.size(); --i >= 0;)
  54961. {
  54962. ((MenuBarModelListener*) listeners.getUnchecked (i))->menuBarItemsChanged (this);
  54963. i = jmin (i, listeners.size());
  54964. }
  54965. }
  54966. void MenuBarModel::applicationCommandInvoked (const ApplicationCommandTarget::InvocationInfo& info)
  54967. {
  54968. for (int i = listeners.size(); --i >= 0;)
  54969. {
  54970. ((MenuBarModelListener*) listeners.getUnchecked (i))->menuCommandInvoked (this, info);
  54971. i = jmin (i, listeners.size());
  54972. }
  54973. }
  54974. void MenuBarModel::applicationCommandListChanged()
  54975. {
  54976. menuItemsChanged();
  54977. }
  54978. END_JUCE_NAMESPACE
  54979. /*** End of inlined file: juce_MenuBarModel.cpp ***/
  54980. /*** Start of inlined file: juce_PopupMenu.cpp ***/
  54981. BEGIN_JUCE_NAMESPACE
  54982. class PopupMenu::Item
  54983. {
  54984. public:
  54985. Item()
  54986. : itemId (0), active (true), isSeparator (true), isTicked (false),
  54987. usesColour (false), customComp (0), commandManager (0)
  54988. {
  54989. }
  54990. Item (const int itemId_,
  54991. const String& text_,
  54992. const bool active_,
  54993. const bool isTicked_,
  54994. const Image* im,
  54995. const Colour& textColour_,
  54996. const bool usesColour_,
  54997. PopupMenuCustomComponent* const customComp_,
  54998. const PopupMenu* const subMenu_,
  54999. ApplicationCommandManager* const commandManager_)
  55000. : itemId (itemId_), text (text_), textColour (textColour_),
  55001. active (active_), isSeparator (false), isTicked (isTicked_),
  55002. usesColour (usesColour_), customComp (customComp_),
  55003. commandManager (commandManager_)
  55004. {
  55005. if (subMenu_ != 0)
  55006. subMenu = new PopupMenu (*subMenu_);
  55007. if (im != 0)
  55008. image = im->createCopy();
  55009. if (commandManager_ != 0 && itemId_ != 0)
  55010. {
  55011. String shortcutKey;
  55012. Array <KeyPress> keyPresses (commandManager_->getKeyMappings()
  55013. ->getKeyPressesAssignedToCommand (itemId_));
  55014. for (int i = 0; i < keyPresses.size(); ++i)
  55015. {
  55016. const String key (keyPresses.getReference(i).getTextDescription());
  55017. if (shortcutKey.isNotEmpty())
  55018. shortcutKey << ", ";
  55019. if (key.length() == 1)
  55020. shortcutKey << "shortcut: '" << key << '\'';
  55021. else
  55022. shortcutKey << key;
  55023. }
  55024. shortcutKey = shortcutKey.trim();
  55025. if (shortcutKey.isNotEmpty())
  55026. text << "<end>" << shortcutKey;
  55027. }
  55028. }
  55029. Item (const Item& other)
  55030. : itemId (other.itemId),
  55031. text (other.text),
  55032. textColour (other.textColour),
  55033. active (other.active),
  55034. isSeparator (other.isSeparator),
  55035. isTicked (other.isTicked),
  55036. usesColour (other.usesColour),
  55037. customComp (other.customComp),
  55038. commandManager (other.commandManager)
  55039. {
  55040. if (other.subMenu != 0)
  55041. subMenu = new PopupMenu (*(other.subMenu));
  55042. if (other.image != 0)
  55043. image = other.image->createCopy();
  55044. }
  55045. ~Item()
  55046. {
  55047. customComp = 0;
  55048. }
  55049. bool canBeTriggered() const throw()
  55050. {
  55051. return active && ! (isSeparator || (subMenu != 0));
  55052. }
  55053. bool hasActiveSubMenu() const throw()
  55054. {
  55055. return active && (subMenu != 0);
  55056. }
  55057. const int itemId;
  55058. String text;
  55059. const Colour textColour;
  55060. const bool active, isSeparator, isTicked, usesColour;
  55061. ScopedPointer <Image> image;
  55062. ReferenceCountedObjectPtr <PopupMenuCustomComponent> customComp;
  55063. ScopedPointer <PopupMenu> subMenu;
  55064. ApplicationCommandManager* const commandManager;
  55065. juce_UseDebuggingNewOperator
  55066. private:
  55067. Item& operator= (const Item&);
  55068. };
  55069. class PopupMenu::ItemComponent : public Component
  55070. {
  55071. public:
  55072. ItemComponent (const PopupMenu::Item& itemInfo_)
  55073. : itemInfo (itemInfo_),
  55074. isHighlighted (false)
  55075. {
  55076. if (itemInfo.customComp != 0)
  55077. addAndMakeVisible (itemInfo.customComp);
  55078. }
  55079. ~ItemComponent()
  55080. {
  55081. if (itemInfo.customComp != 0)
  55082. removeChildComponent (itemInfo.customComp);
  55083. }
  55084. void getIdealSize (int& idealWidth,
  55085. int& idealHeight,
  55086. const int standardItemHeight)
  55087. {
  55088. if (itemInfo.customComp != 0)
  55089. {
  55090. itemInfo.customComp->getIdealSize (idealWidth, idealHeight);
  55091. }
  55092. else
  55093. {
  55094. getLookAndFeel().getIdealPopupMenuItemSize (itemInfo.text,
  55095. itemInfo.isSeparator,
  55096. standardItemHeight,
  55097. idealWidth,
  55098. idealHeight);
  55099. }
  55100. }
  55101. void paint (Graphics& g)
  55102. {
  55103. if (itemInfo.customComp == 0)
  55104. {
  55105. String mainText (itemInfo.text);
  55106. String endText;
  55107. const int endIndex = mainText.indexOf (T("<end>"));
  55108. if (endIndex >= 0)
  55109. {
  55110. endText = mainText.substring (endIndex + 5).trim();
  55111. mainText = mainText.substring (0, endIndex);
  55112. }
  55113. getLookAndFeel()
  55114. .drawPopupMenuItem (g, getWidth(), getHeight(),
  55115. itemInfo.isSeparator,
  55116. itemInfo.active,
  55117. isHighlighted,
  55118. itemInfo.isTicked,
  55119. itemInfo.subMenu != 0,
  55120. mainText, endText,
  55121. itemInfo.image,
  55122. itemInfo.usesColour ? &(itemInfo.textColour) : 0);
  55123. }
  55124. }
  55125. void resized()
  55126. {
  55127. if (getNumChildComponents() > 0)
  55128. getChildComponent(0)->setBounds (2, 0, getWidth() - 4, getHeight());
  55129. }
  55130. void setHighlighted (bool shouldBeHighlighted)
  55131. {
  55132. shouldBeHighlighted = shouldBeHighlighted && itemInfo.active;
  55133. if (isHighlighted != shouldBeHighlighted)
  55134. {
  55135. isHighlighted = shouldBeHighlighted;
  55136. if (itemInfo.customComp != 0)
  55137. {
  55138. itemInfo.customComp->isHighlighted = shouldBeHighlighted;
  55139. itemInfo.customComp->repaint();
  55140. }
  55141. repaint();
  55142. }
  55143. }
  55144. PopupMenu::Item itemInfo;
  55145. juce_UseDebuggingNewOperator
  55146. private:
  55147. bool isHighlighted;
  55148. ItemComponent (const ItemComponent&);
  55149. ItemComponent& operator= (const ItemComponent&);
  55150. };
  55151. namespace PopupMenuSettings
  55152. {
  55153. static const int scrollZone = 24;
  55154. static const int borderSize = 2;
  55155. static const int timerInterval = 50;
  55156. static const int dismissCommandId = 0x6287345f;
  55157. }
  55158. class PopupMenu::Window : public Component,
  55159. private Timer
  55160. {
  55161. public:
  55162. Window()
  55163. : Component (T("menu")),
  55164. owner (0),
  55165. currentChild (0),
  55166. activeSubMenu (0),
  55167. menuBarComponent (0),
  55168. managerOfChosenCommand (0),
  55169. componentAttachedTo (0),
  55170. lastMouseX (0),
  55171. lastMouseY (0),
  55172. minimumWidth (0),
  55173. maximumNumColumns (7),
  55174. standardItemHeight (0),
  55175. isOver (false),
  55176. hasBeenOver (false),
  55177. isDown (false),
  55178. needsToScroll (false),
  55179. hideOnExit (false),
  55180. disableMouseMoves (false),
  55181. hasAnyJuceCompHadFocus (false),
  55182. numColumns (0),
  55183. contentHeight (0),
  55184. childYOffset (0),
  55185. timeEnteredCurrentChildComp (0),
  55186. scrollAcceleration (1.0)
  55187. {
  55188. menuCreationTime = lastFocused = lastScroll = Time::getMillisecondCounter();
  55189. setWantsKeyboardFocus (true);
  55190. setMouseClickGrabsKeyboardFocus (false);
  55191. setOpaque (true);
  55192. setAlwaysOnTop (true);
  55193. Desktop::getInstance().addGlobalMouseListener (this);
  55194. getActiveWindows().add (this);
  55195. }
  55196. ~Window()
  55197. {
  55198. getActiveWindows().removeValue (this);
  55199. Desktop::getInstance().removeGlobalMouseListener (this);
  55200. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  55201. activeSubMenu = 0;
  55202. deleteAllChildren();
  55203. attachedCompWatcher = 0;
  55204. }
  55205. static Window* create (const PopupMenu& menu,
  55206. const bool dismissOnMouseUp,
  55207. Window* const owner_,
  55208. const int minX, const int maxX,
  55209. const int minY, const int maxY,
  55210. const int minimumWidth,
  55211. const int maximumNumColumns,
  55212. const int standardItemHeight,
  55213. const bool alignToRectangle,
  55214. const int itemIdThatMustBeVisible,
  55215. Component* const menuBarComponent,
  55216. ApplicationCommandManager** managerOfChosenCommand,
  55217. Component* const componentAttachedTo)
  55218. {
  55219. if (menu.items.size() > 0)
  55220. {
  55221. int totalItems = 0;
  55222. ScopedPointer <Window> mw (new Window());
  55223. mw->setLookAndFeel (menu.lookAndFeel);
  55224. mw->setWantsKeyboardFocus (false);
  55225. mw->minimumWidth = minimumWidth;
  55226. mw->maximumNumColumns = maximumNumColumns;
  55227. mw->standardItemHeight = standardItemHeight;
  55228. mw->dismissOnMouseUp = dismissOnMouseUp;
  55229. for (int i = 0; i < menu.items.size(); ++i)
  55230. {
  55231. PopupMenu::Item* const item = menu.items.getUnchecked(i);
  55232. mw->addItem (*item);
  55233. ++totalItems;
  55234. }
  55235. if (totalItems > 0)
  55236. {
  55237. mw->owner = owner_;
  55238. mw->menuBarComponent = menuBarComponent;
  55239. mw->managerOfChosenCommand = managerOfChosenCommand;
  55240. mw->componentAttachedTo = componentAttachedTo;
  55241. mw->attachedCompWatcher = componentAttachedTo != 0 ? new ComponentDeletionWatcher (componentAttachedTo) : 0;
  55242. mw->calculateWindowPos (minX, maxX, minY, maxY, alignToRectangle);
  55243. mw->setTopLeftPosition (mw->windowPos.getX(),
  55244. mw->windowPos.getY());
  55245. mw->updateYPositions();
  55246. if (itemIdThatMustBeVisible != 0)
  55247. {
  55248. const int y = minY - mw->windowPos.getY();
  55249. mw->ensureItemIsVisible (itemIdThatMustBeVisible,
  55250. (((unsigned int) y) < (unsigned int) mw->windowPos.getHeight()) ? y : -1);
  55251. }
  55252. mw->resizeToBestWindowPos();
  55253. mw->addToDesktop (ComponentPeer::windowIsTemporary
  55254. | mw->getLookAndFeel().getMenuWindowFlags());
  55255. return mw.release();
  55256. }
  55257. }
  55258. return 0;
  55259. }
  55260. void paint (Graphics& g)
  55261. {
  55262. getLookAndFeel().drawPopupMenuBackground (g, getWidth(), getHeight());
  55263. }
  55264. void paintOverChildren (Graphics& g)
  55265. {
  55266. if (isScrolling())
  55267. {
  55268. LookAndFeel& lf = getLookAndFeel();
  55269. if (isScrollZoneActive (false))
  55270. lf.drawPopupMenuUpDownArrow (g, getWidth(), PopupMenuSettings::scrollZone, true);
  55271. if (isScrollZoneActive (true))
  55272. {
  55273. g.setOrigin (0, getHeight() - PopupMenuSettings::scrollZone);
  55274. lf.drawPopupMenuUpDownArrow (g, getWidth(), PopupMenuSettings::scrollZone, false);
  55275. }
  55276. }
  55277. }
  55278. bool isScrollZoneActive (bool bottomOne) const
  55279. {
  55280. return isScrolling()
  55281. && (bottomOne
  55282. ? childYOffset < contentHeight - windowPos.getHeight()
  55283. : childYOffset > 0);
  55284. }
  55285. void addItem (const PopupMenu::Item& item)
  55286. {
  55287. PopupMenu::ItemComponent* const mic = new PopupMenu::ItemComponent (item);
  55288. addAndMakeVisible (mic);
  55289. int itemW = 80;
  55290. int itemH = 16;
  55291. mic->getIdealSize (itemW, itemH, standardItemHeight);
  55292. mic->setSize (itemW, jlimit (2, 600, itemH));
  55293. mic->addMouseListener (this, false);
  55294. }
  55295. // hide this and all sub-comps
  55296. void hide (const PopupMenu::Item* const item)
  55297. {
  55298. if (isVisible())
  55299. {
  55300. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  55301. activeSubMenu = 0;
  55302. currentChild = 0;
  55303. exitModalState (item != 0 ? item->itemId : 0);
  55304. setVisible (false);
  55305. if (item != 0
  55306. && item->commandManager != 0
  55307. && item->itemId != 0)
  55308. {
  55309. *managerOfChosenCommand = item->commandManager;
  55310. }
  55311. }
  55312. }
  55313. void dismissMenu (const PopupMenu::Item* const item)
  55314. {
  55315. if (owner != 0)
  55316. {
  55317. owner->dismissMenu (item);
  55318. }
  55319. else
  55320. {
  55321. if (item != 0)
  55322. {
  55323. // need a copy of this on the stack as the one passed in will get deleted during this call
  55324. const PopupMenu::Item mi (*item);
  55325. hide (&mi);
  55326. }
  55327. else
  55328. {
  55329. hide (0);
  55330. }
  55331. }
  55332. }
  55333. void mouseMove (const MouseEvent&)
  55334. {
  55335. timerCallback();
  55336. }
  55337. void mouseDown (const MouseEvent&)
  55338. {
  55339. timerCallback();
  55340. }
  55341. void mouseDrag (const MouseEvent&)
  55342. {
  55343. timerCallback();
  55344. }
  55345. void mouseUp (const MouseEvent&)
  55346. {
  55347. timerCallback();
  55348. }
  55349. void mouseWheelMove (const MouseEvent&, float /*amountX*/, float amountY)
  55350. {
  55351. alterChildYPos (roundToInt (-10.0f * amountY * PopupMenuSettings::scrollZone));
  55352. lastMouseX = -1;
  55353. }
  55354. bool keyPressed (const KeyPress& key)
  55355. {
  55356. if (key.isKeyCode (KeyPress::downKey))
  55357. {
  55358. selectNextItem (1);
  55359. }
  55360. else if (key.isKeyCode (KeyPress::upKey))
  55361. {
  55362. selectNextItem (-1);
  55363. }
  55364. else if (key.isKeyCode (KeyPress::leftKey))
  55365. {
  55366. Window* parentWindow = owner;
  55367. if (parentWindow != 0)
  55368. {
  55369. PopupMenu::ItemComponent* currentChildOfParent
  55370. = (parentWindow != 0) ? parentWindow->currentChild : 0;
  55371. hide (0);
  55372. if (parentWindow->isValidComponent())
  55373. parentWindow->setCurrentlyHighlightedChild (currentChildOfParent);
  55374. disableTimerUntilMouseMoves();
  55375. }
  55376. else if (menuBarComponent != 0)
  55377. {
  55378. menuBarComponent->keyPressed (key);
  55379. }
  55380. }
  55381. else if (key.isKeyCode (KeyPress::rightKey))
  55382. {
  55383. disableTimerUntilMouseMoves();
  55384. if (showSubMenuFor (currentChild))
  55385. {
  55386. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  55387. if (activeSubMenu != 0 && activeSubMenu->isVisible())
  55388. activeSubMenu->selectNextItem (1);
  55389. }
  55390. else if (menuBarComponent != 0)
  55391. {
  55392. menuBarComponent->keyPressed (key);
  55393. }
  55394. }
  55395. else if (key.isKeyCode (KeyPress::returnKey))
  55396. {
  55397. triggerCurrentlyHighlightedItem();
  55398. }
  55399. else if (key.isKeyCode (KeyPress::escapeKey))
  55400. {
  55401. dismissMenu (0);
  55402. }
  55403. else
  55404. {
  55405. return false;
  55406. }
  55407. return true;
  55408. }
  55409. void inputAttemptWhenModal()
  55410. {
  55411. timerCallback();
  55412. if (! isOverAnyMenu())
  55413. {
  55414. if (componentAttachedTo != 0 && ! attachedCompWatcher->hasBeenDeleted())
  55415. {
  55416. // we want to dismiss the menu, but if we do it synchronously, then
  55417. // the mouse-click will be allowed to pass through. That's good, except
  55418. // when the user clicks on the button that orginally popped the menu up,
  55419. // as they'll expect the menu to go away, and in fact it'll just
  55420. // come back. So only dismiss synchronously if they're not on the original
  55421. // comp that we're attached to.
  55422. int mx, my;
  55423. componentAttachedTo->getMouseXYRelative (mx, my);
  55424. if (componentAttachedTo->reallyContains (mx, my, true))
  55425. {
  55426. postCommandMessage (PopupMenuSettings::dismissCommandId); // dismiss asynchrounously
  55427. return;
  55428. }
  55429. }
  55430. dismissMenu (0);
  55431. }
  55432. }
  55433. void handleCommandMessage (int commandId)
  55434. {
  55435. Component::handleCommandMessage (commandId);
  55436. if (commandId == PopupMenuSettings::dismissCommandId)
  55437. dismissMenu (0);
  55438. }
  55439. void timerCallback()
  55440. {
  55441. if (! isVisible())
  55442. return;
  55443. if (attachedCompWatcher != 0 && attachedCompWatcher->hasBeenDeleted())
  55444. {
  55445. dismissMenu (0);
  55446. return;
  55447. }
  55448. Window* currentlyModalWindow = dynamic_cast <Window*> (Component::getCurrentlyModalComponent());
  55449. if (currentlyModalWindow != 0 && ! treeContains (currentlyModalWindow))
  55450. return;
  55451. startTimer (PopupMenuSettings::timerInterval); // do this in case it was called from a mouse
  55452. // move rather than a real timer callback
  55453. int mx, my;
  55454. Desktop::getMousePosition (mx, my);
  55455. int x = mx, y = my;
  55456. globalPositionToRelative (x, y);
  55457. const uint32 now = Time::getMillisecondCounter();
  55458. if (now > timeEnteredCurrentChildComp + 100
  55459. && reallyContains (x, y, true)
  55460. && currentChild->isValidComponent()
  55461. && (! disableMouseMoves)
  55462. && ! (activeSubMenu != 0 && activeSubMenu->isVisible()))
  55463. {
  55464. showSubMenuFor (currentChild);
  55465. }
  55466. if (mx != lastMouseX || my != lastMouseY || now > lastMouseMoveTime + 350)
  55467. {
  55468. highlightItemUnderMouse (mx, my, x, y);
  55469. }
  55470. bool overScrollArea = false;
  55471. if (isScrolling()
  55472. && (isOver || (isDown && ((unsigned int) x) < (unsigned int) getWidth()))
  55473. && ((isScrollZoneActive (false) && y < PopupMenuSettings::scrollZone)
  55474. || (isScrollZoneActive (true) && y > getHeight() - PopupMenuSettings::scrollZone)))
  55475. {
  55476. if (now > lastScroll + 20)
  55477. {
  55478. scrollAcceleration = jmin (4.0, scrollAcceleration * 1.04);
  55479. int amount = 0;
  55480. for (int i = 0; i < getNumChildComponents() && amount == 0; ++i)
  55481. amount = ((int) scrollAcceleration) * getChildComponent (i)->getHeight();
  55482. alterChildYPos (y < PopupMenuSettings::scrollZone ? -amount : amount);
  55483. lastScroll = now;
  55484. }
  55485. overScrollArea = true;
  55486. lastMouseX = -1; // trigger a mouse-move
  55487. }
  55488. else
  55489. {
  55490. scrollAcceleration = 1.0;
  55491. }
  55492. const bool wasDown = isDown;
  55493. bool isOverAny = isOverAnyMenu();
  55494. if (hideOnExit && hasBeenOver && (! isOverAny) && activeSubMenu != 0)
  55495. {
  55496. activeSubMenu->updateMouseOverStatus (mx, my);
  55497. isOverAny = isOverAnyMenu();
  55498. }
  55499. if (hideOnExit && hasBeenOver && ! isOverAny)
  55500. {
  55501. hide (0);
  55502. }
  55503. else
  55504. {
  55505. isDown = hasBeenOver
  55506. && (ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown()
  55507. || ModifierKeys::getCurrentModifiersRealtime().isAnyMouseButtonDown());
  55508. bool anyFocused = Process::isForegroundProcess();
  55509. if (anyFocused && Component::getCurrentlyFocusedComponent() == 0)
  55510. {
  55511. // because no component at all may have focus, our test here will
  55512. // only be triggered when something has focus and then loses it.
  55513. anyFocused = ! hasAnyJuceCompHadFocus;
  55514. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  55515. {
  55516. if (ComponentPeer::getPeer (i)->isFocused())
  55517. {
  55518. anyFocused = true;
  55519. hasAnyJuceCompHadFocus = true;
  55520. break;
  55521. }
  55522. }
  55523. }
  55524. if (! anyFocused)
  55525. {
  55526. if (now > lastFocused + 10)
  55527. {
  55528. wasHiddenBecauseOfAppChange() = true;
  55529. dismissMenu (0);
  55530. return; // may have been deleted by the previous call..
  55531. }
  55532. }
  55533. else if (wasDown && now > menuCreationTime + 250
  55534. && ! (isDown || overScrollArea))
  55535. {
  55536. isOver = reallyContains (x, y, true);
  55537. if (isOver)
  55538. {
  55539. triggerCurrentlyHighlightedItem();
  55540. }
  55541. else if ((hasBeenOver || ! dismissOnMouseUp) && ! isOverAny)
  55542. {
  55543. dismissMenu (0);
  55544. }
  55545. return; // may have been deleted by the previous calls..
  55546. }
  55547. else
  55548. {
  55549. lastFocused = now;
  55550. }
  55551. }
  55552. }
  55553. static Array<Window*>& getActiveWindows()
  55554. {
  55555. static Array<Window*> activeMenuWindows;
  55556. return activeMenuWindows;
  55557. }
  55558. static bool& wasHiddenBecauseOfAppChange() throw()
  55559. {
  55560. static bool b = false;
  55561. return b;
  55562. }
  55563. juce_UseDebuggingNewOperator
  55564. private:
  55565. Window* owner;
  55566. PopupMenu::ItemComponent* currentChild;
  55567. ScopedPointer <Window> activeSubMenu;
  55568. Component* menuBarComponent;
  55569. ApplicationCommandManager** managerOfChosenCommand;
  55570. Component* componentAttachedTo;
  55571. ScopedPointer <ComponentDeletionWatcher> attachedCompWatcher;
  55572. Rectangle<int> windowPos;
  55573. int lastMouseX, lastMouseY;
  55574. int minimumWidth, maximumNumColumns, standardItemHeight;
  55575. bool isOver, hasBeenOver, isDown, needsToScroll;
  55576. bool dismissOnMouseUp, hideOnExit, disableMouseMoves, hasAnyJuceCompHadFocus;
  55577. int numColumns, contentHeight, childYOffset;
  55578. Array <int> columnWidths;
  55579. uint32 menuCreationTime, lastFocused, lastScroll, lastMouseMoveTime, timeEnteredCurrentChildComp;
  55580. double scrollAcceleration;
  55581. bool overlaps (const Rectangle<int>& r) const
  55582. {
  55583. return r.intersects (getBounds())
  55584. || (owner != 0 && owner->overlaps (r));
  55585. }
  55586. bool isOverAnyMenu() const
  55587. {
  55588. return (owner != 0) ? owner->isOverAnyMenu()
  55589. : isOverChildren();
  55590. }
  55591. bool isOverChildren() const
  55592. {
  55593. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  55594. return isVisible()
  55595. && (isOver || (activeSubMenu != 0 && activeSubMenu->isOverChildren()));
  55596. }
  55597. void updateMouseOverStatus (const int mx, const int my)
  55598. {
  55599. int rx = mx, ry = my;
  55600. globalPositionToRelative (rx, ry);
  55601. isOver = reallyContains (rx, ry, true);
  55602. if (activeSubMenu != 0)
  55603. activeSubMenu->updateMouseOverStatus (mx, my);
  55604. }
  55605. bool treeContains (const Window* const window) const throw()
  55606. {
  55607. const Window* mw = this;
  55608. while (mw->owner != 0)
  55609. mw = mw->owner;
  55610. while (mw != 0)
  55611. {
  55612. if (mw == window)
  55613. return true;
  55614. mw = mw->activeSubMenu;
  55615. }
  55616. return false;
  55617. }
  55618. void calculateWindowPos (const int minX, const int maxX,
  55619. const int minY, const int maxY,
  55620. const bool alignToRectangle)
  55621. {
  55622. const Rectangle<int> mon (Desktop::getInstance()
  55623. .getMonitorAreaContaining ((minX + maxX) / 2,
  55624. (minY + maxY) / 2,
  55625. #if JUCE_MAC
  55626. true));
  55627. #else
  55628. false)); // on windows, don't stop the menu overlapping the taskbar
  55629. #endif
  55630. int x, y, widthToUse, heightToUse;
  55631. layoutMenuItems (mon.getWidth() - 24, widthToUse, heightToUse);
  55632. if (alignToRectangle)
  55633. {
  55634. x = minX;
  55635. const int spaceUnder = mon.getHeight() - (maxY - mon.getY());
  55636. const int spaceOver = minY - mon.getY();
  55637. if (heightToUse < spaceUnder - 30 || spaceUnder >= spaceOver)
  55638. y = maxY;
  55639. else
  55640. y = minY - heightToUse;
  55641. }
  55642. else
  55643. {
  55644. bool tendTowardsRight = (minX + maxX) / 2 < mon.getCentreX();
  55645. if (owner != 0)
  55646. {
  55647. if (owner->owner != 0)
  55648. {
  55649. const bool ownerGoingRight = (owner->getX() + owner->getWidth() / 2
  55650. > owner->owner->getX() + owner->owner->getWidth() / 2);
  55651. if (ownerGoingRight && maxX + widthToUse < mon.getRight() - 4)
  55652. tendTowardsRight = true;
  55653. else if ((! ownerGoingRight) && minX > widthToUse + 4)
  55654. tendTowardsRight = false;
  55655. }
  55656. else if (maxX + widthToUse < mon.getRight() - 32)
  55657. {
  55658. tendTowardsRight = true;
  55659. }
  55660. }
  55661. const int biggestSpace = jmax (mon.getRight() - maxX,
  55662. minX - mon.getX()) - 32;
  55663. if (biggestSpace < widthToUse)
  55664. {
  55665. layoutMenuItems (biggestSpace + (maxX - minX) / 3, widthToUse, heightToUse);
  55666. if (numColumns > 1)
  55667. layoutMenuItems (biggestSpace - 4, widthToUse, heightToUse);
  55668. tendTowardsRight = (mon.getRight() - maxX) >= (minX - mon.getX());
  55669. }
  55670. if (tendTowardsRight)
  55671. x = jmin (mon.getRight() - widthToUse - 4, maxX);
  55672. else
  55673. x = jmax (mon.getX() + 4, minX - widthToUse);
  55674. y = minY;
  55675. if ((minY + maxY) / 2 > mon.getCentreY())
  55676. y = jmax (mon.getY(), maxY - heightToUse);
  55677. }
  55678. x = jmax (mon.getX() + 1, jmin (mon.getRight() - (widthToUse + 6), x));
  55679. y = jmax (mon.getY() + 1, jmin (mon.getBottom() - (heightToUse + 6), y));
  55680. windowPos.setBounds (x, y, widthToUse, heightToUse);
  55681. // sets this flag if it's big enough to obscure any of its parent menus
  55682. hideOnExit = (owner != 0)
  55683. && owner->windowPos.intersects (windowPos.expanded (-4, -4));
  55684. }
  55685. void layoutMenuItems (const int maxMenuW, int& width, int& height)
  55686. {
  55687. numColumns = 0;
  55688. contentHeight = 0;
  55689. const int maxMenuH = getParentHeight() - 24;
  55690. int totalW;
  55691. do
  55692. {
  55693. ++numColumns;
  55694. totalW = workOutBestSize (maxMenuW);
  55695. if (totalW > maxMenuW)
  55696. {
  55697. numColumns = jmax (1, numColumns - 1);
  55698. totalW = workOutBestSize (maxMenuW); // to update col widths
  55699. break;
  55700. }
  55701. else if (totalW > maxMenuW / 2 || contentHeight < maxMenuH)
  55702. {
  55703. break;
  55704. }
  55705. } while (numColumns < maximumNumColumns);
  55706. const int actualH = jmin (contentHeight, maxMenuH);
  55707. needsToScroll = contentHeight > actualH;
  55708. width = updateYPositions();
  55709. height = actualH + PopupMenuSettings::borderSize * 2;
  55710. }
  55711. int workOutBestSize (const int maxMenuW)
  55712. {
  55713. int totalW = 0;
  55714. contentHeight = 0;
  55715. int childNum = 0;
  55716. for (int col = 0; col < numColumns; ++col)
  55717. {
  55718. int i, colW = 50, colH = 0;
  55719. const int numChildren = jmin (getNumChildComponents() - childNum,
  55720. (getNumChildComponents() + numColumns - 1) / numColumns);
  55721. for (i = numChildren; --i >= 0;)
  55722. {
  55723. colW = jmax (colW, getChildComponent (childNum + i)->getWidth());
  55724. colH += getChildComponent (childNum + i)->getHeight();
  55725. }
  55726. colW = jmin (maxMenuW / jmax (1, numColumns - 2), colW + PopupMenuSettings::borderSize * 2);
  55727. columnWidths.set (col, colW);
  55728. totalW += colW;
  55729. contentHeight = jmax (contentHeight, colH);
  55730. childNum += numChildren;
  55731. }
  55732. if (totalW < minimumWidth)
  55733. {
  55734. totalW = minimumWidth;
  55735. for (int col = 0; col < numColumns; ++col)
  55736. columnWidths.set (0, totalW / numColumns);
  55737. }
  55738. return totalW;
  55739. }
  55740. void ensureItemIsVisible (const int itemId, int wantedY)
  55741. {
  55742. jassert (itemId != 0)
  55743. for (int i = getNumChildComponents(); --i >= 0;)
  55744. {
  55745. PopupMenu::ItemComponent* const m = (PopupMenu::ItemComponent*) getChildComponent (i);
  55746. if (m != 0
  55747. && m->itemInfo.itemId == itemId
  55748. && windowPos.getHeight() > PopupMenuSettings::scrollZone * 4)
  55749. {
  55750. const int currentY = m->getY();
  55751. if (wantedY > 0 || currentY < 0 || m->getBottom() > windowPos.getHeight())
  55752. {
  55753. if (wantedY < 0)
  55754. wantedY = jlimit (PopupMenuSettings::scrollZone,
  55755. jmax (PopupMenuSettings::scrollZone,
  55756. windowPos.getHeight() - (PopupMenuSettings::scrollZone + m->getHeight())),
  55757. currentY);
  55758. const Rectangle<int> mon (Desktop::getInstance()
  55759. .getMonitorAreaContaining (windowPos.getX(),
  55760. windowPos.getY(),
  55761. true));
  55762. int deltaY = wantedY - currentY;
  55763. windowPos.setSize (jmin (windowPos.getWidth(), mon.getWidth()),
  55764. jmin (windowPos.getHeight(), mon.getHeight()));
  55765. const int newY = jlimit (mon.getY(),
  55766. mon.getBottom() - windowPos.getHeight(),
  55767. windowPos.getY() + deltaY);
  55768. deltaY -= newY - windowPos.getY();
  55769. childYOffset -= deltaY;
  55770. windowPos.setPosition (windowPos.getX(), newY);
  55771. updateYPositions();
  55772. }
  55773. break;
  55774. }
  55775. }
  55776. }
  55777. void resizeToBestWindowPos()
  55778. {
  55779. Rectangle<int> r (windowPos);
  55780. if (childYOffset < 0)
  55781. {
  55782. r.setBounds (r.getX(), r.getY() - childYOffset,
  55783. r.getWidth(), r.getHeight() + childYOffset);
  55784. }
  55785. else if (childYOffset > 0)
  55786. {
  55787. const int spaceAtBottom = r.getHeight() - (contentHeight - childYOffset);
  55788. if (spaceAtBottom > 0)
  55789. r.setSize (r.getWidth(), r.getHeight() - spaceAtBottom);
  55790. }
  55791. setBounds (r);
  55792. updateYPositions();
  55793. }
  55794. void alterChildYPos (const int delta)
  55795. {
  55796. if (isScrolling())
  55797. {
  55798. childYOffset += delta;
  55799. if (delta < 0)
  55800. {
  55801. childYOffset = jmax (childYOffset, 0);
  55802. }
  55803. else if (delta > 0)
  55804. {
  55805. childYOffset = jmin (childYOffset,
  55806. contentHeight - windowPos.getHeight() + PopupMenuSettings::borderSize);
  55807. }
  55808. updateYPositions();
  55809. }
  55810. else
  55811. {
  55812. childYOffset = 0;
  55813. }
  55814. resizeToBestWindowPos();
  55815. repaint();
  55816. }
  55817. int updateYPositions()
  55818. {
  55819. int x = 0;
  55820. int childNum = 0;
  55821. for (int col = 0; col < numColumns; ++col)
  55822. {
  55823. const int numChildren = jmin (getNumChildComponents() - childNum,
  55824. (getNumChildComponents() + numColumns - 1) / numColumns);
  55825. const int colW = columnWidths [col];
  55826. int y = PopupMenuSettings::borderSize - (childYOffset + (getY() - windowPos.getY()));
  55827. for (int i = 0; i < numChildren; ++i)
  55828. {
  55829. Component* const c = getChildComponent (childNum + i);
  55830. c->setBounds (x, y, colW, c->getHeight());
  55831. y += c->getHeight();
  55832. }
  55833. x += colW;
  55834. childNum += numChildren;
  55835. }
  55836. return x;
  55837. }
  55838. bool isScrolling() const throw()
  55839. {
  55840. return childYOffset != 0 || needsToScroll;
  55841. }
  55842. void setCurrentlyHighlightedChild (PopupMenu::ItemComponent* const child)
  55843. {
  55844. if (currentChild->isValidComponent())
  55845. currentChild->setHighlighted (false);
  55846. currentChild = child;
  55847. if (currentChild != 0)
  55848. {
  55849. currentChild->setHighlighted (true);
  55850. timeEnteredCurrentChildComp = Time::getApproximateMillisecondCounter();
  55851. }
  55852. }
  55853. bool showSubMenuFor (PopupMenu::ItemComponent* const childComp)
  55854. {
  55855. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  55856. activeSubMenu = 0;
  55857. if (childComp->isValidComponent() && childComp->itemInfo.hasActiveSubMenu())
  55858. {
  55859. int left = 0, top = 0;
  55860. childComp->relativePositionToGlobal (left, top);
  55861. int right = childComp->getWidth(), bottom = childComp->getHeight();
  55862. childComp->relativePositionToGlobal (right, bottom);
  55863. activeSubMenu = Window::create (*(childComp->itemInfo.subMenu),
  55864. dismissOnMouseUp,
  55865. this,
  55866. left, right, top, bottom,
  55867. 0, maximumNumColumns,
  55868. standardItemHeight,
  55869. false, 0, menuBarComponent,
  55870. managerOfChosenCommand,
  55871. componentAttachedTo);
  55872. if (activeSubMenu != 0)
  55873. {
  55874. activeSubMenu->setVisible (true);
  55875. activeSubMenu->enterModalState (false);
  55876. activeSubMenu->toFront (false);
  55877. return true;
  55878. }
  55879. }
  55880. return false;
  55881. }
  55882. void highlightItemUnderMouse (const int mx, const int my, const int x, const int y)
  55883. {
  55884. isOver = reallyContains (x, y, true);
  55885. if (isOver)
  55886. hasBeenOver = true;
  55887. if (abs (lastMouseX - mx) > 2 || abs (lastMouseY - my) > 2)
  55888. {
  55889. lastMouseMoveTime = Time::getApproximateMillisecondCounter();
  55890. if (disableMouseMoves && isOver)
  55891. disableMouseMoves = false;
  55892. }
  55893. if (disableMouseMoves)
  55894. return;
  55895. bool isMovingTowardsMenu = false;
  55896. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent())
  55897. if (isOver && (activeSubMenu != 0) && (mx != lastMouseX || my != lastMouseY))
  55898. {
  55899. // try to intelligently guess whether the user is moving the mouse towards a currently-open
  55900. // submenu. To do this, look at whether the mouse stays inside a triangular region that
  55901. // extends from the last mouse pos to the submenu's rectangle..
  55902. float subX = (float) activeSubMenu->getScreenX();
  55903. if (activeSubMenu->getX() > getX())
  55904. {
  55905. lastMouseX -= 2; // to enlarge the triangle a bit, in case the mouse only moves a couple of pixels
  55906. }
  55907. else
  55908. {
  55909. lastMouseX += 2;
  55910. subX += activeSubMenu->getWidth();
  55911. }
  55912. Path areaTowardsSubMenu;
  55913. areaTowardsSubMenu.addTriangle ((float) lastMouseX,
  55914. (float) lastMouseY,
  55915. subX,
  55916. (float) activeSubMenu->getScreenY(),
  55917. subX,
  55918. (float) (activeSubMenu->getScreenY() + activeSubMenu->getHeight()));
  55919. isMovingTowardsMenu = areaTowardsSubMenu.contains ((float) mx, (float) my);
  55920. }
  55921. lastMouseX = mx;
  55922. lastMouseY = my;
  55923. if (! isMovingTowardsMenu)
  55924. {
  55925. Component* c = getComponentAt (x, y);
  55926. if (c == this)
  55927. c = 0;
  55928. PopupMenu::ItemComponent* mic = dynamic_cast <PopupMenu::ItemComponent*> (c);
  55929. if (mic == 0 && c != 0)
  55930. mic = c->findParentComponentOfClass ((PopupMenu::ItemComponent*) 0);
  55931. if (mic != currentChild
  55932. && (isOver || (activeSubMenu == 0) || ! activeSubMenu->isVisible()))
  55933. {
  55934. if (isOver && (c != 0) && (activeSubMenu != 0))
  55935. {
  55936. activeSubMenu->hide (0);
  55937. }
  55938. if (! isOver)
  55939. mic = 0;
  55940. setCurrentlyHighlightedChild (mic);
  55941. }
  55942. }
  55943. }
  55944. void triggerCurrentlyHighlightedItem()
  55945. {
  55946. if (currentChild->isValidComponent()
  55947. && currentChild->itemInfo.canBeTriggered()
  55948. && (currentChild->itemInfo.customComp == 0
  55949. || currentChild->itemInfo.customComp->isTriggeredAutomatically))
  55950. {
  55951. dismissMenu (&currentChild->itemInfo);
  55952. }
  55953. }
  55954. void selectNextItem (const int delta)
  55955. {
  55956. disableTimerUntilMouseMoves();
  55957. PopupMenu::ItemComponent* mic = 0;
  55958. bool wasLastOne = (currentChild == 0);
  55959. const int numItems = getNumChildComponents();
  55960. for (int i = 0; i < numItems + 1; ++i)
  55961. {
  55962. int index = (delta > 0) ? i : (numItems - 1 - i);
  55963. index = (index + numItems) % numItems;
  55964. mic = dynamic_cast <PopupMenu::ItemComponent*> (getChildComponent (index));
  55965. if (mic != 0 && (mic->itemInfo.canBeTriggered() || mic->itemInfo.hasActiveSubMenu())
  55966. && wasLastOne)
  55967. break;
  55968. if (mic == currentChild)
  55969. wasLastOne = true;
  55970. }
  55971. setCurrentlyHighlightedChild (mic);
  55972. }
  55973. void disableTimerUntilMouseMoves()
  55974. {
  55975. disableMouseMoves = true;
  55976. if (owner != 0)
  55977. owner->disableTimerUntilMouseMoves();
  55978. }
  55979. Window (const Window&);
  55980. Window& operator= (const Window&);
  55981. };
  55982. PopupMenu::PopupMenu()
  55983. : lookAndFeel (0),
  55984. separatorPending (false)
  55985. {
  55986. }
  55987. PopupMenu::PopupMenu (const PopupMenu& other)
  55988. : lookAndFeel (other.lookAndFeel),
  55989. separatorPending (false)
  55990. {
  55991. items.ensureStorageAllocated (other.items.size());
  55992. for (int i = 0; i < other.items.size(); ++i)
  55993. items.add (new Item (*other.items.getUnchecked(i)));
  55994. }
  55995. const PopupMenu& PopupMenu::operator= (const PopupMenu& other)
  55996. {
  55997. if (this != &other)
  55998. {
  55999. lookAndFeel = other.lookAndFeel;
  56000. clear();
  56001. items.ensureStorageAllocated (other.items.size());
  56002. for (int i = 0; i < other.items.size(); ++i)
  56003. items.add (new Item (*other.items.getUnchecked(i)));
  56004. }
  56005. return *this;
  56006. }
  56007. PopupMenu::~PopupMenu()
  56008. {
  56009. clear();
  56010. }
  56011. void PopupMenu::clear()
  56012. {
  56013. items.clear();
  56014. separatorPending = false;
  56015. }
  56016. void PopupMenu::addSeparatorIfPending()
  56017. {
  56018. if (separatorPending)
  56019. {
  56020. separatorPending = false;
  56021. if (items.size() > 0)
  56022. items.add (new Item());
  56023. }
  56024. }
  56025. void PopupMenu::addItem (const int itemResultId,
  56026. const String& itemText,
  56027. const bool isActive,
  56028. const bool isTicked,
  56029. const Image* const iconToUse)
  56030. {
  56031. jassert (itemResultId != 0); // 0 is used as a return value to indicate that the user
  56032. // didn't pick anything, so you shouldn't use it as the id
  56033. // for an item..
  56034. addSeparatorIfPending();
  56035. items.add (new Item (itemResultId, itemText, isActive, isTicked,
  56036. iconToUse, Colours::black, false, 0, 0, 0));
  56037. }
  56038. void PopupMenu::addCommandItem (ApplicationCommandManager* commandManager,
  56039. const int commandID,
  56040. const String& displayName)
  56041. {
  56042. jassert (commandManager != 0 && commandID != 0);
  56043. const ApplicationCommandInfo* const registeredInfo = commandManager->getCommandForID (commandID);
  56044. if (registeredInfo != 0)
  56045. {
  56046. ApplicationCommandInfo info (*registeredInfo);
  56047. ApplicationCommandTarget* const target = commandManager->getTargetForCommand (commandID, info);
  56048. addSeparatorIfPending();
  56049. items.add (new Item (commandID,
  56050. displayName.isNotEmpty() ? displayName
  56051. : info.shortName,
  56052. target != 0 && (info.flags & ApplicationCommandInfo::isDisabled) == 0,
  56053. (info.flags & ApplicationCommandInfo::isTicked) != 0,
  56054. 0,
  56055. Colours::black,
  56056. false,
  56057. 0, 0,
  56058. commandManager));
  56059. }
  56060. }
  56061. void PopupMenu::addColouredItem (const int itemResultId,
  56062. const String& itemText,
  56063. const Colour& itemTextColour,
  56064. const bool isActive,
  56065. const bool isTicked,
  56066. const Image* const iconToUse)
  56067. {
  56068. jassert (itemResultId != 0); // 0 is used as a return value to indicate that the user
  56069. // didn't pick anything, so you shouldn't use it as the id
  56070. // for an item..
  56071. addSeparatorIfPending();
  56072. items.add (new Item (itemResultId, itemText, isActive, isTicked,
  56073. iconToUse, itemTextColour, true, 0, 0, 0));
  56074. }
  56075. void PopupMenu::addCustomItem (const int itemResultId,
  56076. PopupMenuCustomComponent* const customComponent)
  56077. {
  56078. jassert (itemResultId != 0); // 0 is used as a return value to indicate that the user
  56079. // didn't pick anything, so you shouldn't use it as the id
  56080. // for an item..
  56081. addSeparatorIfPending();
  56082. items.add (new Item (itemResultId, String::empty, true, false, 0,
  56083. Colours::black, false, customComponent, 0, 0));
  56084. }
  56085. class NormalComponentWrapper : public PopupMenuCustomComponent
  56086. {
  56087. public:
  56088. NormalComponentWrapper (Component* const comp,
  56089. const int w, const int h,
  56090. const bool triggerMenuItemAutomaticallyWhenClicked)
  56091. : PopupMenuCustomComponent (triggerMenuItemAutomaticallyWhenClicked),
  56092. width (w),
  56093. height (h)
  56094. {
  56095. addAndMakeVisible (comp);
  56096. }
  56097. ~NormalComponentWrapper() {}
  56098. void getIdealSize (int& idealWidth, int& idealHeight)
  56099. {
  56100. idealWidth = width;
  56101. idealHeight = height;
  56102. }
  56103. void resized()
  56104. {
  56105. if (getChildComponent(0) != 0)
  56106. getChildComponent(0)->setBounds (0, 0, getWidth(), getHeight());
  56107. }
  56108. juce_UseDebuggingNewOperator
  56109. private:
  56110. const int width, height;
  56111. NormalComponentWrapper (const NormalComponentWrapper&);
  56112. const NormalComponentWrapper& operator= (const NormalComponentWrapper&);
  56113. };
  56114. void PopupMenu::addCustomItem (const int itemResultId,
  56115. Component* customComponent,
  56116. int idealWidth, int idealHeight,
  56117. const bool triggerMenuItemAutomaticallyWhenClicked)
  56118. {
  56119. addCustomItem (itemResultId,
  56120. new NormalComponentWrapper (customComponent,
  56121. idealWidth, idealHeight,
  56122. triggerMenuItemAutomaticallyWhenClicked));
  56123. }
  56124. void PopupMenu::addSubMenu (const String& subMenuName,
  56125. const PopupMenu& subMenu,
  56126. const bool isActive,
  56127. Image* const iconToUse,
  56128. const bool isTicked)
  56129. {
  56130. addSeparatorIfPending();
  56131. items.add (new Item (0, subMenuName, isActive && (subMenu.getNumItems() > 0), isTicked,
  56132. iconToUse, Colours::black, false, 0, &subMenu, 0));
  56133. }
  56134. void PopupMenu::addSeparator()
  56135. {
  56136. separatorPending = true;
  56137. }
  56138. class HeaderItemComponent : public PopupMenuCustomComponent
  56139. {
  56140. public:
  56141. HeaderItemComponent (const String& name)
  56142. : PopupMenuCustomComponent (false)
  56143. {
  56144. setName (name);
  56145. }
  56146. ~HeaderItemComponent()
  56147. {
  56148. }
  56149. void paint (Graphics& g)
  56150. {
  56151. Font f (getLookAndFeel().getPopupMenuFont());
  56152. f.setBold (true);
  56153. g.setFont (f);
  56154. g.setColour (findColour (PopupMenu::headerTextColourId));
  56155. g.drawFittedText (getName(),
  56156. 12, 0, getWidth() - 16, proportionOfHeight (0.8f),
  56157. Justification::bottomLeft, 1);
  56158. }
  56159. void getIdealSize (int& idealWidth,
  56160. int& idealHeight)
  56161. {
  56162. getLookAndFeel().getIdealPopupMenuItemSize (getName(), false, -1, idealWidth, idealHeight);
  56163. idealHeight += idealHeight / 2;
  56164. idealWidth += idealWidth / 4;
  56165. }
  56166. juce_UseDebuggingNewOperator
  56167. };
  56168. void PopupMenu::addSectionHeader (const String& title)
  56169. {
  56170. addCustomItem (0X4734a34f, new HeaderItemComponent (title));
  56171. }
  56172. Component* PopupMenu::createMenuComponent (const int x, const int y, const int w, const int h,
  56173. const int itemIdThatMustBeVisible,
  56174. const int minimumWidth,
  56175. const int maximumNumColumns,
  56176. const int standardItemHeight,
  56177. const bool alignToRectangle,
  56178. Component* menuBarComponent,
  56179. ApplicationCommandManager** managerOfChosenCommand,
  56180. Component* const componentAttachedTo)
  56181. {
  56182. Window* const pw
  56183. = Window::create (*this,
  56184. ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown(),
  56185. 0,
  56186. x, x + w,
  56187. y, y + h,
  56188. minimumWidth,
  56189. maximumNumColumns,
  56190. standardItemHeight,
  56191. alignToRectangle,
  56192. itemIdThatMustBeVisible,
  56193. menuBarComponent,
  56194. managerOfChosenCommand,
  56195. componentAttachedTo);
  56196. if (pw != 0)
  56197. pw->setVisible (true);
  56198. return pw;
  56199. }
  56200. int PopupMenu::showMenu (const int x, const int y, const int w, const int h,
  56201. const int itemIdThatMustBeVisible,
  56202. const int minimumWidth,
  56203. const int maximumNumColumns,
  56204. const int standardItemHeight,
  56205. const bool alignToRectangle,
  56206. Component* const componentAttachedTo)
  56207. {
  56208. Component* const prevFocused = Component::getCurrentlyFocusedComponent();
  56209. ScopedPointer <ComponentDeletionWatcher> deletionChecker[2];
  56210. if (prevFocused != 0)
  56211. deletionChecker[0] = new ComponentDeletionWatcher (prevFocused);
  56212. Component* const prevTopLevel = (prevFocused != 0) ? prevFocused->getTopLevelComponent() : 0;
  56213. if (prevTopLevel != 0)
  56214. deletionChecker[1] = new ComponentDeletionWatcher (prevTopLevel);
  56215. Window::wasHiddenBecauseOfAppChange() = false;
  56216. int result = 0;
  56217. ApplicationCommandManager* managerOfChosenCommand = 0;
  56218. ScopedPointer <Component> popupComp (createMenuComponent (x, y, w, h,
  56219. itemIdThatMustBeVisible,
  56220. minimumWidth,
  56221. maximumNumColumns > 0 ? maximumNumColumns : 7,
  56222. standardItemHeight,
  56223. alignToRectangle, 0,
  56224. &managerOfChosenCommand,
  56225. componentAttachedTo));
  56226. if (popupComp != 0)
  56227. {
  56228. popupComp->enterModalState (false);
  56229. popupComp->toFront (false); // need to do this after making it modal, or it could
  56230. // be stuck behind other comps that are already modal..
  56231. result = popupComp->runModalLoop();
  56232. popupComp = 0;
  56233. if (! Window::wasHiddenBecauseOfAppChange())
  56234. {
  56235. if (deletionChecker[1] != 0 && ! deletionChecker[1]->hasBeenDeleted())
  56236. prevTopLevel->toFront (true);
  56237. if (deletionChecker[0] != 0 && ! deletionChecker[0]->hasBeenDeleted())
  56238. prevFocused->grabKeyboardFocus();
  56239. }
  56240. }
  56241. if (managerOfChosenCommand != 0 && result != 0)
  56242. {
  56243. ApplicationCommandTarget::InvocationInfo info (result);
  56244. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  56245. managerOfChosenCommand->invoke (info, true);
  56246. }
  56247. return result;
  56248. }
  56249. int PopupMenu::show (const int itemIdThatMustBeVisible,
  56250. const int minimumWidth,
  56251. const int maximumNumColumns,
  56252. const int standardItemHeight)
  56253. {
  56254. int x, y;
  56255. Desktop::getMousePosition (x, y);
  56256. return showAt (x, y,
  56257. itemIdThatMustBeVisible,
  56258. minimumWidth,
  56259. maximumNumColumns,
  56260. standardItemHeight);
  56261. }
  56262. int PopupMenu::showAt (const int screenX,
  56263. const int screenY,
  56264. const int itemIdThatMustBeVisible,
  56265. const int minimumWidth,
  56266. const int maximumNumColumns,
  56267. const int standardItemHeight)
  56268. {
  56269. return showMenu (screenX, screenY, 1, 1,
  56270. itemIdThatMustBeVisible,
  56271. minimumWidth, maximumNumColumns,
  56272. standardItemHeight,
  56273. false, 0);
  56274. }
  56275. int PopupMenu::showAt (Component* componentToAttachTo,
  56276. const int itemIdThatMustBeVisible,
  56277. const int minimumWidth,
  56278. const int maximumNumColumns,
  56279. const int standardItemHeight)
  56280. {
  56281. if (componentToAttachTo != 0)
  56282. {
  56283. return showMenu (componentToAttachTo->getScreenX(),
  56284. componentToAttachTo->getScreenY(),
  56285. componentToAttachTo->getWidth(),
  56286. componentToAttachTo->getHeight(),
  56287. itemIdThatMustBeVisible,
  56288. minimumWidth,
  56289. maximumNumColumns,
  56290. standardItemHeight,
  56291. true, componentToAttachTo);
  56292. }
  56293. else
  56294. {
  56295. return show (itemIdThatMustBeVisible,
  56296. minimumWidth,
  56297. maximumNumColumns,
  56298. standardItemHeight);
  56299. }
  56300. }
  56301. void JUCE_CALLTYPE PopupMenu::dismissAllActiveMenus()
  56302. {
  56303. for (int i = Window::getActiveWindows().size(); --i >= 0;)
  56304. {
  56305. Window* const pmw = Window::getActiveWindows()[i];
  56306. if (pmw != 0)
  56307. pmw->dismissMenu (0);
  56308. }
  56309. }
  56310. int PopupMenu::getNumItems() const throw()
  56311. {
  56312. int num = 0;
  56313. for (int i = items.size(); --i >= 0;)
  56314. if (! (items.getUnchecked(i))->isSeparator)
  56315. ++num;
  56316. return num;
  56317. }
  56318. bool PopupMenu::containsCommandItem (const int commandID) const
  56319. {
  56320. for (int i = items.size(); --i >= 0;)
  56321. {
  56322. const Item* mi = items.getUnchecked (i);
  56323. if ((mi->itemId == commandID && mi->commandManager != 0)
  56324. || (mi->subMenu != 0 && mi->subMenu->containsCommandItem (commandID)))
  56325. {
  56326. return true;
  56327. }
  56328. }
  56329. return false;
  56330. }
  56331. bool PopupMenu::containsAnyActiveItems() const throw()
  56332. {
  56333. for (int i = items.size(); --i >= 0;)
  56334. {
  56335. const Item* const mi = items.getUnchecked (i);
  56336. if (mi->subMenu != 0)
  56337. {
  56338. if (mi->subMenu->containsAnyActiveItems())
  56339. return true;
  56340. }
  56341. else if (mi->active)
  56342. {
  56343. return true;
  56344. }
  56345. }
  56346. return false;
  56347. }
  56348. void PopupMenu::setLookAndFeel (LookAndFeel* const newLookAndFeel)
  56349. {
  56350. lookAndFeel = newLookAndFeel;
  56351. }
  56352. PopupMenuCustomComponent::PopupMenuCustomComponent (const bool isTriggeredAutomatically_)
  56353. : isHighlighted (false),
  56354. isTriggeredAutomatically (isTriggeredAutomatically_)
  56355. {
  56356. }
  56357. PopupMenuCustomComponent::~PopupMenuCustomComponent()
  56358. {
  56359. }
  56360. void PopupMenuCustomComponent::triggerMenuItem()
  56361. {
  56362. PopupMenu::ItemComponent* const mic = dynamic_cast <PopupMenu::ItemComponent*> (getParentComponent());
  56363. if (mic != 0)
  56364. {
  56365. PopupMenu::Window* const pmw = dynamic_cast <PopupMenu::Window*> (mic->getParentComponent());
  56366. if (pmw != 0)
  56367. {
  56368. pmw->dismissMenu (&mic->itemInfo);
  56369. }
  56370. else
  56371. {
  56372. // something must have gone wrong with the component hierarchy if this happens..
  56373. jassertfalse
  56374. }
  56375. }
  56376. else
  56377. {
  56378. // why isn't this component inside a menu? Not much point triggering the item if
  56379. // there's no menu.
  56380. jassertfalse
  56381. }
  56382. }
  56383. PopupMenu::MenuItemIterator::MenuItemIterator (const PopupMenu& menu_)
  56384. : subMenu (0),
  56385. itemId (0),
  56386. isSeparator (false),
  56387. isTicked (false),
  56388. isEnabled (false),
  56389. isCustomComponent (false),
  56390. isSectionHeader (false),
  56391. customColour (0),
  56392. customImage (0),
  56393. menu (menu_),
  56394. index (0)
  56395. {
  56396. }
  56397. PopupMenu::MenuItemIterator::~MenuItemIterator()
  56398. {
  56399. }
  56400. bool PopupMenu::MenuItemIterator::next()
  56401. {
  56402. if (index >= menu.items.size())
  56403. return false;
  56404. const Item* const item = menu.items.getUnchecked (index);
  56405. ++index;
  56406. itemName = item->customComp != 0 ? item->customComp->getName() : item->text;
  56407. subMenu = item->subMenu;
  56408. itemId = item->itemId;
  56409. isSeparator = item->isSeparator;
  56410. isTicked = item->isTicked;
  56411. isEnabled = item->active;
  56412. isSectionHeader = dynamic_cast <HeaderItemComponent*> ((PopupMenuCustomComponent*) item->customComp) != 0;
  56413. isCustomComponent = (! isSectionHeader) && item->customComp != 0;
  56414. customColour = item->usesColour ? &(item->textColour) : 0;
  56415. customImage = item->image;
  56416. commandManager = item->commandManager;
  56417. return true;
  56418. }
  56419. END_JUCE_NAMESPACE
  56420. /*** End of inlined file: juce_PopupMenu.cpp ***/
  56421. /*** Start of inlined file: juce_ComponentDragger.cpp ***/
  56422. BEGIN_JUCE_NAMESPACE
  56423. ComponentDragger::ComponentDragger()
  56424. : constrainer (0),
  56425. originalX (0),
  56426. originalY (0)
  56427. {
  56428. }
  56429. ComponentDragger::~ComponentDragger()
  56430. {
  56431. }
  56432. void ComponentDragger::startDraggingComponent (Component* const componentToDrag,
  56433. ComponentBoundsConstrainer* const constrainer_)
  56434. {
  56435. jassert (componentToDrag->isValidComponent());
  56436. if (componentToDrag->isValidComponent())
  56437. {
  56438. constrainer = constrainer_;
  56439. originalX = 0;
  56440. originalY = 0;
  56441. componentToDrag->relativePositionToGlobal (originalX, originalY);
  56442. }
  56443. }
  56444. void ComponentDragger::dragComponent (Component* const componentToDrag, const MouseEvent& e)
  56445. {
  56446. jassert (componentToDrag->isValidComponent());
  56447. jassert (e.mods.isAnyMouseButtonDown()); // (the event has to be a drag event..)
  56448. if (componentToDrag->isValidComponent())
  56449. {
  56450. int x = originalX;
  56451. int y = originalY;
  56452. int w = componentToDrag->getWidth();
  56453. int h = componentToDrag->getHeight();
  56454. const Component* const parentComp = componentToDrag->getParentComponent();
  56455. if (parentComp != 0)
  56456. parentComp->globalPositionToRelative (x, y);
  56457. x += e.getDistanceFromDragStartX();
  56458. y += e.getDistanceFromDragStartY();
  56459. if (constrainer != 0)
  56460. constrainer->setBoundsForComponent (componentToDrag, Rectangle<int> (x, y, w, h),
  56461. false, false, false, false);
  56462. else
  56463. componentToDrag->setBounds (x, y, w, h);
  56464. }
  56465. }
  56466. END_JUCE_NAMESPACE
  56467. /*** End of inlined file: juce_ComponentDragger.cpp ***/
  56468. /*** Start of inlined file: juce_DragAndDropContainer.cpp ***/
  56469. BEGIN_JUCE_NAMESPACE
  56470. bool juce_performDragDropFiles (const StringArray& files, const bool copyFiles, bool& shouldStop);
  56471. bool juce_performDragDropText (const String& text, bool& shouldStop);
  56472. class DragImageComponent : public Component,
  56473. public Timer
  56474. {
  56475. private:
  56476. ScopedPointer <Image> image;
  56477. Component* const source;
  56478. DragAndDropContainer* const owner;
  56479. ScopedPointer <ComponentDeletionWatcher> sourceWatcher, mouseDragSourceWatcher, currentlyOverWatcher;
  56480. Component* mouseDragSource;
  56481. DragAndDropTarget* currentlyOver;
  56482. String dragDesc;
  56483. const int imageX, imageY;
  56484. bool hasCheckedForExternalDrag, drawImage;
  56485. DragImageComponent (const DragImageComponent&);
  56486. const DragImageComponent& operator= (const DragImageComponent&);
  56487. public:
  56488. DragImageComponent (Image* const im,
  56489. const String& desc,
  56490. Component* const s,
  56491. DragAndDropContainer* const o,
  56492. const int imageX_, const int imageY_)
  56493. : image (im),
  56494. source (s),
  56495. owner (o),
  56496. currentlyOver (0),
  56497. dragDesc (desc),
  56498. imageX (imageX_),
  56499. imageY (imageY_),
  56500. hasCheckedForExternalDrag (false),
  56501. drawImage (true)
  56502. {
  56503. setSize (im->getWidth(), im->getHeight());
  56504. sourceWatcher = new ComponentDeletionWatcher (source);
  56505. mouseDragSource = Component::getComponentUnderMouse();
  56506. if (mouseDragSource == 0)
  56507. mouseDragSource = source;
  56508. mouseDragSourceWatcher = new ComponentDeletionWatcher (mouseDragSource);
  56509. mouseDragSource->addMouseListener (this, false);
  56510. startTimer (200);
  56511. setInterceptsMouseClicks (false, false);
  56512. setAlwaysOnTop (true);
  56513. }
  56514. ~DragImageComponent()
  56515. {
  56516. if ((DragImageComponent*) owner->dragImageComponent == this)
  56517. owner->dragImageComponent.release();
  56518. if (! mouseDragSourceWatcher->hasBeenDeleted())
  56519. {
  56520. mouseDragSource->removeMouseListener (this);
  56521. if (currentlyOverWatcher != 0 && ! currentlyOverWatcher->hasBeenDeleted())
  56522. if (currentlyOver->isInterestedInDragSource (dragDesc, source))
  56523. currentlyOver->itemDragExit (dragDesc, source);
  56524. }
  56525. }
  56526. void paint (Graphics& g)
  56527. {
  56528. if (isOpaque())
  56529. g.fillAll (Colours::white);
  56530. if (drawImage)
  56531. {
  56532. g.setOpacity (1.0f);
  56533. g.drawImageAt (image, 0, 0);
  56534. }
  56535. }
  56536. DragAndDropTarget* findTarget (const int screenX, const int screenY,
  56537. int& relX, int& relY) const
  56538. {
  56539. Component* hit = getParentComponent();
  56540. if (hit == 0)
  56541. {
  56542. hit = Desktop::getInstance().findComponentAt (screenX, screenY);
  56543. }
  56544. else
  56545. {
  56546. int rx = screenX, ry = screenY;
  56547. hit->globalPositionToRelative (rx, ry);
  56548. hit = hit->getComponentAt (rx, ry);
  56549. }
  56550. // (note: use a local copy of the dragDesc member in case the callback runs
  56551. // a modal loop and deletes this object before the method completes)
  56552. const String dragDescLocal (dragDesc);
  56553. while (hit != 0)
  56554. {
  56555. DragAndDropTarget* const ddt = dynamic_cast <DragAndDropTarget*> (hit);
  56556. if (ddt != 0 && ddt->isInterestedInDragSource (dragDescLocal, source))
  56557. {
  56558. relX = screenX;
  56559. relY = screenY;
  56560. hit->globalPositionToRelative (relX, relY);
  56561. return ddt;
  56562. }
  56563. hit = hit->getParentComponent();
  56564. }
  56565. return 0;
  56566. }
  56567. void mouseUp (const MouseEvent& e)
  56568. {
  56569. if (e.originalComponent != this)
  56570. {
  56571. if (! mouseDragSourceWatcher->hasBeenDeleted())
  56572. mouseDragSource->removeMouseListener (this);
  56573. bool dropAccepted = false;
  56574. DragAndDropTarget* ddt = 0;
  56575. int relX = 0, relY = 0;
  56576. if (isVisible())
  56577. {
  56578. setVisible (false);
  56579. ddt = findTarget (e.getScreenX(),
  56580. e.getScreenY(),
  56581. relX, relY);
  56582. // fade this component and remove it - it'll be deleted later by the timer callback
  56583. dropAccepted = ddt != 0;
  56584. setVisible (true);
  56585. if (dropAccepted || sourceWatcher->hasBeenDeleted())
  56586. {
  56587. fadeOutComponent (120);
  56588. }
  56589. else
  56590. {
  56591. int targetX = source->getWidth() / 2;
  56592. int targetY = source->getHeight() / 2;
  56593. source->relativePositionToGlobal (targetX, targetY);
  56594. int ourCentreX = getWidth() / 2;
  56595. int ourCentreY = getHeight() / 2;
  56596. relativePositionToGlobal (ourCentreX, ourCentreY);
  56597. fadeOutComponent (120,
  56598. targetX - ourCentreX,
  56599. targetY - ourCentreY);
  56600. }
  56601. }
  56602. if (getParentComponent() != 0)
  56603. getParentComponent()->removeChildComponent (this);
  56604. if (dropAccepted && ddt != 0)
  56605. {
  56606. // (note: use a local copy of the dragDesc member in case the callback runs
  56607. // a modal loop and deletes this object before the method completes)
  56608. const String dragDescLocal (dragDesc);
  56609. currentlyOverWatcher = 0;
  56610. currentlyOver = 0;
  56611. ddt->itemDropped (dragDescLocal, source, relX, relY);
  56612. }
  56613. // careful - this object could now be deleted..
  56614. }
  56615. }
  56616. void updateLocation (const bool canDoExternalDrag, int x, int y)
  56617. {
  56618. // (note: use a local copy of the dragDesc member in case the callback runs
  56619. // a modal loop and deletes this object before it returns)
  56620. const String dragDescLocal (dragDesc);
  56621. int newX = x + imageX;
  56622. int newY = y + imageY;
  56623. if (getParentComponent() != 0)
  56624. getParentComponent()->globalPositionToRelative (newX, newY);
  56625. //if (newX != getX() || newY != getY())
  56626. {
  56627. setTopLeftPosition (newX, newY);
  56628. int relX = 0, relY = 0;
  56629. DragAndDropTarget* const ddt = findTarget (x, y, relX, relY);
  56630. drawImage = (ddt == 0) || ddt->shouldDrawDragImageWhenOver();
  56631. if (ddt != currentlyOver)
  56632. {
  56633. if (currentlyOverWatcher != 0 && ! currentlyOverWatcher->hasBeenDeleted())
  56634. {
  56635. Component* const over = dynamic_cast <Component*> (currentlyOver);
  56636. if (over != 0
  56637. && over->isValidComponent()
  56638. && ! (sourceWatcher->hasBeenDeleted())
  56639. && currentlyOver->isInterestedInDragSource (dragDescLocal, source))
  56640. {
  56641. currentlyOver->itemDragExit (dragDescLocal, source);
  56642. }
  56643. }
  56644. currentlyOver = ddt;
  56645. currentlyOverWatcher = 0;
  56646. if (ddt != 0)
  56647. {
  56648. currentlyOverWatcher = new ComponentDeletionWatcher (dynamic_cast <Component*> (ddt));
  56649. if (currentlyOver->isInterestedInDragSource (dragDescLocal, source))
  56650. currentlyOver->itemDragEnter (dragDescLocal, source, relX, relY);
  56651. }
  56652. }
  56653. else if (currentlyOverWatcher != 0 && currentlyOverWatcher->hasBeenDeleted())
  56654. {
  56655. currentlyOver = 0;
  56656. currentlyOverWatcher = 0;
  56657. }
  56658. if (currentlyOver != 0
  56659. && currentlyOver->isInterestedInDragSource (dragDescLocal, source))
  56660. currentlyOver->itemDragMove (dragDescLocal, source, relX, relY);
  56661. if (currentlyOver == 0
  56662. && canDoExternalDrag
  56663. && ! hasCheckedForExternalDrag)
  56664. {
  56665. if (Desktop::getInstance().findComponentAt (x, y) == 0)
  56666. {
  56667. hasCheckedForExternalDrag = true;
  56668. StringArray files;
  56669. bool canMoveFiles = false;
  56670. if (owner->shouldDropFilesWhenDraggedExternally (dragDescLocal, source, files, canMoveFiles)
  56671. && files.size() > 0)
  56672. {
  56673. ComponentDeletionWatcher cdw (this);
  56674. setVisible (false);
  56675. if (ModifierKeys::getCurrentModifiersRealtime().isAnyMouseButtonDown())
  56676. DragAndDropContainer::performExternalDragDropOfFiles (files, canMoveFiles);
  56677. if (! cdw.hasBeenDeleted())
  56678. delete this;
  56679. return;
  56680. }
  56681. }
  56682. }
  56683. }
  56684. }
  56685. void mouseDrag (const MouseEvent& e)
  56686. {
  56687. if (e.originalComponent != this)
  56688. updateLocation (true, e.getScreenX(), e.getScreenY());
  56689. }
  56690. void timerCallback()
  56691. {
  56692. if (sourceWatcher->hasBeenDeleted())
  56693. {
  56694. delete this;
  56695. }
  56696. else if (! isMouseButtonDownAnywhere())
  56697. {
  56698. if (! mouseDragSourceWatcher->hasBeenDeleted())
  56699. mouseDragSource->removeMouseListener (this);
  56700. delete this;
  56701. }
  56702. }
  56703. };
  56704. DragAndDropContainer::DragAndDropContainer()
  56705. {
  56706. }
  56707. DragAndDropContainer::~DragAndDropContainer()
  56708. {
  56709. dragImageComponent = 0;
  56710. }
  56711. void DragAndDropContainer::startDragging (const String& sourceDescription,
  56712. Component* sourceComponent,
  56713. Image* dragImage_,
  56714. const bool allowDraggingToExternalWindows,
  56715. const Point<int>* imageOffsetFromMouse)
  56716. {
  56717. ScopedPointer <Image> dragImage (dragImage_);
  56718. if (dragImageComponent == 0)
  56719. {
  56720. Component* const thisComp = dynamic_cast <Component*> (this);
  56721. if (thisComp != 0)
  56722. {
  56723. int mx, my;
  56724. Desktop::getLastMouseDownPosition (mx, my);
  56725. int imageX = 0, imageY = 0;
  56726. if (dragImage == 0)
  56727. {
  56728. dragImage = sourceComponent->createComponentSnapshot (Rectangle<int> (0, 0, sourceComponent->getWidth(), sourceComponent->getHeight()));
  56729. if (dragImage->getFormat() != Image::ARGB)
  56730. {
  56731. Image* newIm = Image::createNativeImage (Image::ARGB, dragImage->getWidth(), dragImage->getHeight(), true);
  56732. Graphics g2 (*newIm);
  56733. g2.drawImageAt (dragImage, 0, 0);
  56734. dragImage = newIm;
  56735. }
  56736. dragImage->multiplyAllAlphas (0.6f);
  56737. const int lo = 150;
  56738. const int hi = 400;
  56739. int rx = mx, ry = my;
  56740. sourceComponent->globalPositionToRelative (rx, ry);
  56741. const int cx = jlimit (0, dragImage->getWidth(), rx);
  56742. const int cy = jlimit (0, dragImage->getHeight(), ry);
  56743. for (int y = dragImage->getHeight(); --y >= 0;)
  56744. {
  56745. const double dy = (y - cy) * (y - cy);
  56746. for (int x = dragImage->getWidth(); --x >= 0;)
  56747. {
  56748. const int dx = x - cx;
  56749. const int distance = roundToInt (sqrt (dx * dx + dy));
  56750. if (distance > lo)
  56751. {
  56752. const float alpha = (distance > hi) ? 0
  56753. : (hi - distance) / (float) (hi - lo)
  56754. + Random::getSystemRandom().nextFloat() * 0.008f;
  56755. dragImage->multiplyAlphaAt (x, y, alpha);
  56756. }
  56757. }
  56758. }
  56759. imageX = -cx;
  56760. imageY = -cy;
  56761. }
  56762. else
  56763. {
  56764. if (imageOffsetFromMouse == 0)
  56765. {
  56766. imageX = dragImage->getWidth() / -2;
  56767. imageY = dragImage->getHeight() / -2;
  56768. }
  56769. else
  56770. {
  56771. imageX = imageOffsetFromMouse->getX();
  56772. imageY = imageOffsetFromMouse->getY();
  56773. }
  56774. }
  56775. dragImageComponent = new DragImageComponent (dragImage.release(), sourceDescription, sourceComponent,
  56776. this, imageX, imageY);
  56777. currentDragDesc = sourceDescription;
  56778. if (allowDraggingToExternalWindows)
  56779. {
  56780. if (! Desktop::canUseSemiTransparentWindows())
  56781. dragImageComponent->setOpaque (true);
  56782. dragImageComponent->addToDesktop (ComponentPeer::windowIgnoresMouseClicks
  56783. | ComponentPeer::windowIsTemporary
  56784. | ComponentPeer::windowIgnoresKeyPresses);
  56785. }
  56786. else
  56787. thisComp->addChildComponent (dragImageComponent);
  56788. ((DragImageComponent*) dragImageComponent)->updateLocation (false, mx, my);
  56789. dragImageComponent->setVisible (true);
  56790. }
  56791. else
  56792. {
  56793. // this class must only be implemented by an object that
  56794. // is also a Component.
  56795. jassertfalse
  56796. }
  56797. }
  56798. }
  56799. bool DragAndDropContainer::isDragAndDropActive() const
  56800. {
  56801. return dragImageComponent != 0;
  56802. }
  56803. const String DragAndDropContainer::getCurrentDragDescription() const
  56804. {
  56805. return (dragImageComponent != 0) ? currentDragDesc
  56806. : String::empty;
  56807. }
  56808. DragAndDropContainer* DragAndDropContainer::findParentDragContainerFor (Component* c)
  56809. {
  56810. if (c == 0)
  56811. return 0;
  56812. // (unable to use the syntax findParentComponentOfClass <DragAndDropContainer> () because of a VC6 compiler bug)
  56813. return c->findParentComponentOfClass ((DragAndDropContainer*) 0);
  56814. }
  56815. bool DragAndDropContainer::shouldDropFilesWhenDraggedExternally (const String&, Component*, StringArray&, bool&)
  56816. {
  56817. return false;
  56818. }
  56819. void DragAndDropTarget::itemDragEnter (const String&, Component*, int, int)
  56820. {
  56821. }
  56822. void DragAndDropTarget::itemDragMove (const String&, Component*, int, int)
  56823. {
  56824. }
  56825. void DragAndDropTarget::itemDragExit (const String&, Component*)
  56826. {
  56827. }
  56828. bool DragAndDropTarget::shouldDrawDragImageWhenOver()
  56829. {
  56830. return true;
  56831. }
  56832. void FileDragAndDropTarget::fileDragEnter (const StringArray&, int, int)
  56833. {
  56834. }
  56835. void FileDragAndDropTarget::fileDragMove (const StringArray&, int, int)
  56836. {
  56837. }
  56838. void FileDragAndDropTarget::fileDragExit (const StringArray&)
  56839. {
  56840. }
  56841. END_JUCE_NAMESPACE
  56842. /*** End of inlined file: juce_DragAndDropContainer.cpp ***/
  56843. /*** Start of inlined file: juce_MouseCursor.cpp ***/
  56844. BEGIN_JUCE_NAMESPACE
  56845. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw();
  56846. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw();
  56847. // isStandard set depending on which interface was used to create the cursor
  56848. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw();
  56849. static CriticalSection activeCursorListLock;
  56850. static VoidArray activeCursors;
  56851. class SharedMouseCursorInternal : public ReferenceCountedObject
  56852. {
  56853. public:
  56854. SharedMouseCursorInternal (const MouseCursor::StandardCursorType type) throw()
  56855. : standardType (type),
  56856. isStandard (true)
  56857. {
  56858. handle = juce_createStandardMouseCursor (standardType);
  56859. activeCursors.add (this);
  56860. }
  56861. SharedMouseCursorInternal (const Image& image, const int hotSpotX, const int hotSpotY) throw()
  56862. : standardType (MouseCursor::NormalCursor),
  56863. isStandard (false)
  56864. {
  56865. handle = juce_createMouseCursorFromImage (image, hotSpotX, hotSpotY);
  56866. }
  56867. ~SharedMouseCursorInternal() throw()
  56868. {
  56869. juce_deleteMouseCursor (handle, isStandard);
  56870. activeCursors.removeValue (this);
  56871. }
  56872. void* getHandle() const throw()
  56873. {
  56874. return handle;
  56875. }
  56876. static SharedMouseCursorInternal* findInstance (MouseCursor::StandardCursorType type) throw()
  56877. {
  56878. for (int i = activeCursors.size(); --i >= 0;)
  56879. {
  56880. SharedMouseCursorInternal* const r = (SharedMouseCursorInternal*) activeCursors.getUnchecked(i);
  56881. if (r->standardType == type)
  56882. return r;
  56883. }
  56884. return new SharedMouseCursorInternal (type);
  56885. }
  56886. juce_UseDebuggingNewOperator
  56887. private:
  56888. void* handle;
  56889. const MouseCursor::StandardCursorType standardType;
  56890. const bool isStandard;
  56891. const SharedMouseCursorInternal& operator= (const SharedMouseCursorInternal&);
  56892. };
  56893. MouseCursor::MouseCursor() throw()
  56894. {
  56895. const ScopedLock sl (activeCursorListLock);
  56896. cursorHandle = SharedMouseCursorInternal::findInstance (NormalCursor);
  56897. }
  56898. MouseCursor::MouseCursor (const StandardCursorType type) throw()
  56899. {
  56900. const ScopedLock sl (activeCursorListLock);
  56901. cursorHandle = SharedMouseCursorInternal::findInstance (type);
  56902. }
  56903. MouseCursor::MouseCursor (const Image& image, const int hotSpotX, const int hotSpotY) throw()
  56904. {
  56905. const ScopedLock sl (activeCursorListLock);
  56906. cursorHandle = new SharedMouseCursorInternal (image, hotSpotX, hotSpotY);
  56907. }
  56908. MouseCursor::MouseCursor (const MouseCursor& other) throw()
  56909. : cursorHandle (other.cursorHandle)
  56910. {
  56911. }
  56912. MouseCursor::~MouseCursor() throw()
  56913. {
  56914. }
  56915. const MouseCursor& MouseCursor::operator= (const MouseCursor& other) throw()
  56916. {
  56917. cursorHandle = other.cursorHandle;
  56918. return *this;
  56919. }
  56920. bool MouseCursor::operator== (const MouseCursor& other) const throw()
  56921. {
  56922. return cursorHandle == other.cursorHandle;
  56923. }
  56924. bool MouseCursor::operator!= (const MouseCursor& other) const throw()
  56925. {
  56926. return cursorHandle != other.cursorHandle;
  56927. }
  56928. void* MouseCursor::getHandle() const throw()
  56929. {
  56930. return cursorHandle->getHandle();
  56931. }
  56932. void MouseCursor::showWaitCursor() throw()
  56933. {
  56934. const MouseCursor mc (MouseCursor::WaitCursor);
  56935. mc.showInAllWindows();
  56936. }
  56937. void MouseCursor::hideWaitCursor() throw()
  56938. {
  56939. Component* const c = Component::getComponentUnderMouse();
  56940. MouseCursor mc (c->isValidComponent() ? c->getLookAndFeel().getMouseCursorFor (*c)
  56941. : MouseCursor::NormalCursor);
  56942. mc.showInAllWindows();
  56943. }
  56944. END_JUCE_NAMESPACE
  56945. /*** End of inlined file: juce_MouseCursor.cpp ***/
  56946. /*** Start of inlined file: juce_MouseEvent.cpp ***/
  56947. BEGIN_JUCE_NAMESPACE
  56948. MouseEvent::MouseEvent (const int x_,
  56949. const int y_,
  56950. const ModifierKeys& mods_,
  56951. Component* const originator,
  56952. const Time& eventTime_,
  56953. const int mouseDownX_,
  56954. const int mouseDownY_,
  56955. const Time& mouseDownTime_,
  56956. const int numberOfClicks_,
  56957. const bool mouseWasDragged) throw()
  56958. : x (x_),
  56959. y (y_),
  56960. mods (mods_),
  56961. eventComponent (originator),
  56962. originalComponent (originator),
  56963. eventTime (eventTime_),
  56964. mouseDownX (mouseDownX_),
  56965. mouseDownY (mouseDownY_),
  56966. mouseDownTime (mouseDownTime_),
  56967. numberOfClicks (numberOfClicks_),
  56968. wasMovedSinceMouseDown (mouseWasDragged)
  56969. {
  56970. }
  56971. MouseEvent::~MouseEvent() throw()
  56972. {
  56973. }
  56974. bool MouseEvent::mouseWasClicked() const throw()
  56975. {
  56976. return ! wasMovedSinceMouseDown;
  56977. }
  56978. int MouseEvent::getMouseDownX() const throw()
  56979. {
  56980. return mouseDownX;
  56981. }
  56982. int MouseEvent::getMouseDownY() const throw()
  56983. {
  56984. return mouseDownY;
  56985. }
  56986. int MouseEvent::getDistanceFromDragStartX() const throw()
  56987. {
  56988. return x - mouseDownX;
  56989. }
  56990. int MouseEvent::getDistanceFromDragStartY() const throw()
  56991. {
  56992. return y - mouseDownY;
  56993. }
  56994. int MouseEvent::getDistanceFromDragStart() const throw()
  56995. {
  56996. return roundToInt (juce_hypot (getDistanceFromDragStartX(),
  56997. getDistanceFromDragStartY()));
  56998. }
  56999. int MouseEvent::getLengthOfMousePress() const throw()
  57000. {
  57001. if (mouseDownTime.toMilliseconds() > 0)
  57002. return jmax (0, (int) (eventTime - mouseDownTime).inMilliseconds());
  57003. return 0;
  57004. }
  57005. int MouseEvent::getScreenX() const throw()
  57006. {
  57007. int sx = x, sy = y;
  57008. eventComponent->relativePositionToGlobal (sx, sy);
  57009. return sx;
  57010. }
  57011. int MouseEvent::getScreenY() const throw()
  57012. {
  57013. int sx = x, sy = y;
  57014. eventComponent->relativePositionToGlobal (sx, sy);
  57015. return sy;
  57016. }
  57017. int MouseEvent::getMouseDownScreenX() const throw()
  57018. {
  57019. int sx = mouseDownX, sy = mouseDownY;
  57020. eventComponent->relativePositionToGlobal (sx, sy);
  57021. return sx;
  57022. }
  57023. int MouseEvent::getMouseDownScreenY() const throw()
  57024. {
  57025. int sx = mouseDownX, sy = mouseDownY;
  57026. eventComponent->relativePositionToGlobal (sx, sy);
  57027. return sy;
  57028. }
  57029. const MouseEvent MouseEvent::getEventRelativeTo (Component* const otherComponent) const throw()
  57030. {
  57031. if (otherComponent == 0)
  57032. {
  57033. jassertfalse
  57034. return *this;
  57035. }
  57036. MouseEvent me (*this);
  57037. eventComponent->relativePositionToOtherComponent (otherComponent, me.x, me.y);
  57038. eventComponent->relativePositionToOtherComponent (otherComponent, me.mouseDownX, me.mouseDownY);
  57039. me.eventComponent = otherComponent;
  57040. return me;
  57041. }
  57042. static int doubleClickTimeOutMs = 400;
  57043. void MouseEvent::setDoubleClickTimeout (const int newTime) throw()
  57044. {
  57045. doubleClickTimeOutMs = newTime;
  57046. }
  57047. int MouseEvent::getDoubleClickTimeout() throw()
  57048. {
  57049. return doubleClickTimeOutMs;
  57050. }
  57051. END_JUCE_NAMESPACE
  57052. /*** End of inlined file: juce_MouseEvent.cpp ***/
  57053. /*** Start of inlined file: juce_MouseHoverDetector.cpp ***/
  57054. BEGIN_JUCE_NAMESPACE
  57055. MouseHoverDetector::MouseHoverDetector (const int hoverTimeMillisecs_)
  57056. : source (0),
  57057. hoverTimeMillisecs (hoverTimeMillisecs_),
  57058. hasJustHovered (false)
  57059. {
  57060. internalTimer.owner = this;
  57061. }
  57062. MouseHoverDetector::~MouseHoverDetector()
  57063. {
  57064. setHoverComponent (0);
  57065. }
  57066. void MouseHoverDetector::setHoverTimeMillisecs (const int newTimeInMillisecs)
  57067. {
  57068. hoverTimeMillisecs = newTimeInMillisecs;
  57069. }
  57070. void MouseHoverDetector::setHoverComponent (Component* const newSourceComponent)
  57071. {
  57072. if (source != newSourceComponent)
  57073. {
  57074. internalTimer.stopTimer();
  57075. hasJustHovered = false;
  57076. if (source != 0)
  57077. {
  57078. // ! you need to delete the hover detector before deleting its component
  57079. jassert (source->isValidComponent());
  57080. source->removeMouseListener (&internalTimer);
  57081. }
  57082. source = newSourceComponent;
  57083. if (newSourceComponent != 0)
  57084. newSourceComponent->addMouseListener (&internalTimer, false);
  57085. }
  57086. }
  57087. void MouseHoverDetector::hoverTimerCallback()
  57088. {
  57089. internalTimer.stopTimer();
  57090. if (source != 0)
  57091. {
  57092. int mx, my;
  57093. source->getMouseXYRelative (mx, my);
  57094. if (source->reallyContains (mx, my, false))
  57095. {
  57096. hasJustHovered = true;
  57097. mouseHovered (mx, my);
  57098. }
  57099. }
  57100. }
  57101. void MouseHoverDetector::checkJustHoveredCallback()
  57102. {
  57103. if (hasJustHovered)
  57104. {
  57105. hasJustHovered = false;
  57106. mouseMovedAfterHover();
  57107. }
  57108. }
  57109. void MouseHoverDetector::HoverDetectorInternal::timerCallback()
  57110. {
  57111. owner->hoverTimerCallback();
  57112. }
  57113. void MouseHoverDetector::HoverDetectorInternal::mouseEnter (const MouseEvent&)
  57114. {
  57115. stopTimer();
  57116. owner->checkJustHoveredCallback();
  57117. }
  57118. void MouseHoverDetector::HoverDetectorInternal::mouseExit (const MouseEvent&)
  57119. {
  57120. stopTimer();
  57121. owner->checkJustHoveredCallback();
  57122. }
  57123. void MouseHoverDetector::HoverDetectorInternal::mouseDown (const MouseEvent&)
  57124. {
  57125. stopTimer();
  57126. owner->checkJustHoveredCallback();
  57127. }
  57128. void MouseHoverDetector::HoverDetectorInternal::mouseUp (const MouseEvent&)
  57129. {
  57130. stopTimer();
  57131. owner->checkJustHoveredCallback();
  57132. }
  57133. void MouseHoverDetector::HoverDetectorInternal::mouseMove (const MouseEvent& e)
  57134. {
  57135. if (lastX != e.x || lastY != e.y) // to avoid fake mouse-moves setting it off
  57136. {
  57137. lastX = e.x;
  57138. lastY = e.y;
  57139. if (owner->source != 0)
  57140. startTimer (owner->hoverTimeMillisecs);
  57141. owner->checkJustHoveredCallback();
  57142. }
  57143. }
  57144. void MouseHoverDetector::HoverDetectorInternal::mouseWheelMove (const MouseEvent&, float, float)
  57145. {
  57146. stopTimer();
  57147. owner->checkJustHoveredCallback();
  57148. }
  57149. END_JUCE_NAMESPACE
  57150. /*** End of inlined file: juce_MouseHoverDetector.cpp ***/
  57151. /*** Start of inlined file: juce_MouseListener.cpp ***/
  57152. BEGIN_JUCE_NAMESPACE
  57153. void MouseListener::mouseEnter (const MouseEvent&)
  57154. {
  57155. }
  57156. void MouseListener::mouseExit (const MouseEvent&)
  57157. {
  57158. }
  57159. void MouseListener::mouseDown (const MouseEvent&)
  57160. {
  57161. }
  57162. void MouseListener::mouseUp (const MouseEvent&)
  57163. {
  57164. }
  57165. void MouseListener::mouseDrag (const MouseEvent&)
  57166. {
  57167. }
  57168. void MouseListener::mouseMove (const MouseEvent&)
  57169. {
  57170. }
  57171. void MouseListener::mouseDoubleClick (const MouseEvent&)
  57172. {
  57173. }
  57174. void MouseListener::mouseWheelMove (const MouseEvent&, float, float)
  57175. {
  57176. }
  57177. END_JUCE_NAMESPACE
  57178. /*** End of inlined file: juce_MouseListener.cpp ***/
  57179. /*** Start of inlined file: juce_BooleanPropertyComponent.cpp ***/
  57180. BEGIN_JUCE_NAMESPACE
  57181. BooleanPropertyComponent::BooleanPropertyComponent (const String& name,
  57182. const String& buttonTextWhenTrue,
  57183. const String& buttonTextWhenFalse)
  57184. : PropertyComponent (name),
  57185. onText (buttonTextWhenTrue),
  57186. offText (buttonTextWhenFalse)
  57187. {
  57188. createButton();
  57189. button->addButtonListener (this);
  57190. }
  57191. BooleanPropertyComponent::BooleanPropertyComponent (const Value& valueToControl,
  57192. const String& name,
  57193. const String& buttonText)
  57194. : PropertyComponent (name),
  57195. onText (buttonText),
  57196. offText (buttonText)
  57197. {
  57198. createButton();
  57199. button->setButtonText (buttonText);
  57200. button->getToggleStateValue().referTo (valueToControl);
  57201. button->setClickingTogglesState (true);
  57202. }
  57203. BooleanPropertyComponent::~BooleanPropertyComponent()
  57204. {
  57205. deleteAllChildren();
  57206. }
  57207. void BooleanPropertyComponent::createButton()
  57208. {
  57209. addAndMakeVisible (button = new ToggleButton (String::empty));
  57210. button->setClickingTogglesState (false);
  57211. }
  57212. void BooleanPropertyComponent::setState (const bool newState)
  57213. {
  57214. button->setToggleState (newState, true);
  57215. }
  57216. bool BooleanPropertyComponent::getState() const
  57217. {
  57218. return button->getToggleState();
  57219. }
  57220. void BooleanPropertyComponent::paint (Graphics& g)
  57221. {
  57222. PropertyComponent::paint (g);
  57223. const Rectangle<int> r (button->getBounds());
  57224. g.setColour (Colours::white);
  57225. g.fillRect (r);
  57226. g.setColour (findColour (ComboBox::outlineColourId));
  57227. g.drawRect (r.getX(), r.getY(), r.getWidth(), r.getHeight());
  57228. }
  57229. void BooleanPropertyComponent::refresh()
  57230. {
  57231. button->setToggleState (getState(), false);
  57232. button->setButtonText (button->getToggleState() ? onText : offText);
  57233. }
  57234. void BooleanPropertyComponent::buttonClicked (Button*)
  57235. {
  57236. setState (! getState());
  57237. }
  57238. END_JUCE_NAMESPACE
  57239. /*** End of inlined file: juce_BooleanPropertyComponent.cpp ***/
  57240. /*** Start of inlined file: juce_ButtonPropertyComponent.cpp ***/
  57241. BEGIN_JUCE_NAMESPACE
  57242. ButtonPropertyComponent::ButtonPropertyComponent (const String& name,
  57243. const bool triggerOnMouseDown)
  57244. : PropertyComponent (name)
  57245. {
  57246. addAndMakeVisible (button = new TextButton (String::empty));
  57247. button->setTriggeredOnMouseDown (triggerOnMouseDown);
  57248. button->addButtonListener (this);
  57249. }
  57250. ButtonPropertyComponent::~ButtonPropertyComponent()
  57251. {
  57252. deleteAllChildren();
  57253. }
  57254. void ButtonPropertyComponent::refresh()
  57255. {
  57256. button->setButtonText (getButtonText());
  57257. }
  57258. void ButtonPropertyComponent::buttonClicked (Button*)
  57259. {
  57260. buttonClicked();
  57261. }
  57262. END_JUCE_NAMESPACE
  57263. /*** End of inlined file: juce_ButtonPropertyComponent.cpp ***/
  57264. /*** Start of inlined file: juce_ChoicePropertyComponent.cpp ***/
  57265. BEGIN_JUCE_NAMESPACE
  57266. ChoicePropertyComponent::ChoicePropertyComponent (const String& name)
  57267. : PropertyComponent (name),
  57268. comboBox (0)
  57269. {
  57270. }
  57271. ChoicePropertyComponent::ChoicePropertyComponent (const Value& valueToControl,
  57272. const String& name,
  57273. const StringArray& choices_,
  57274. const Array <int>* choiceIDs)
  57275. : PropertyComponent (name),
  57276. choices (choices_),
  57277. comboBox (0)
  57278. {
  57279. createComboBox (choiceIDs);
  57280. comboBox->getSelectedIdAsValue().referTo (valueToControl);
  57281. }
  57282. ChoicePropertyComponent::~ChoicePropertyComponent()
  57283. {
  57284. deleteAllChildren();
  57285. }
  57286. void ChoicePropertyComponent::createComboBox (const Array <int>* choiceIDs)
  57287. {
  57288. // The array of IDs must contain the same number of values as the choices list!
  57289. jassert (choiceIDs == 0 || choiceIDs->size() == choices.size());
  57290. addAndMakeVisible (comboBox = new ComboBox (String::empty));
  57291. for (int i = 0; i < choices.size(); ++i)
  57292. {
  57293. if (choices[i].isNotEmpty())
  57294. comboBox->addItem (choices[i], choiceIDs == 0 ? (i + 1)
  57295. : ((*choiceIDs)[i]));
  57296. else
  57297. comboBox->addSeparator();
  57298. }
  57299. comboBox->setEditableText (false);
  57300. }
  57301. void ChoicePropertyComponent::setIndex (const int newIndex)
  57302. {
  57303. comboBox->setSelectedId (comboBox->getItemId (newIndex));
  57304. }
  57305. int ChoicePropertyComponent::getIndex() const
  57306. {
  57307. return comboBox->getSelectedItemIndex();
  57308. }
  57309. const StringArray& ChoicePropertyComponent::getChoices() const
  57310. {
  57311. return choices;
  57312. }
  57313. void ChoicePropertyComponent::refresh()
  57314. {
  57315. if (comboBox == 0)
  57316. {
  57317. createComboBox (0);
  57318. comboBox->addListener (this);
  57319. }
  57320. comboBox->setSelectedId (getIndex() + 1, true);
  57321. }
  57322. void ChoicePropertyComponent::comboBoxChanged (ComboBox*)
  57323. {
  57324. const int newIndex = comboBox->getSelectedId() - 1;
  57325. if (newIndex != getIndex())
  57326. setIndex (newIndex);
  57327. }
  57328. END_JUCE_NAMESPACE
  57329. /*** End of inlined file: juce_ChoicePropertyComponent.cpp ***/
  57330. /*** Start of inlined file: juce_PropertyComponent.cpp ***/
  57331. BEGIN_JUCE_NAMESPACE
  57332. PropertyComponent::PropertyComponent (const String& name,
  57333. const int preferredHeight_)
  57334. : Component (name),
  57335. preferredHeight (preferredHeight_)
  57336. {
  57337. jassert (name.isNotEmpty());
  57338. }
  57339. PropertyComponent::~PropertyComponent()
  57340. {
  57341. }
  57342. void PropertyComponent::paint (Graphics& g)
  57343. {
  57344. getLookAndFeel().drawPropertyComponentBackground (g, getWidth(), getHeight(), *this);
  57345. getLookAndFeel().drawPropertyComponentLabel (g, getWidth(), getHeight(), *this);
  57346. }
  57347. void PropertyComponent::resized()
  57348. {
  57349. if (getNumChildComponents() > 0)
  57350. getChildComponent (0)->setBounds (getLookAndFeel().getPropertyComponentContentPosition (*this));
  57351. }
  57352. void PropertyComponent::enablementChanged()
  57353. {
  57354. repaint();
  57355. }
  57356. END_JUCE_NAMESPACE
  57357. /*** End of inlined file: juce_PropertyComponent.cpp ***/
  57358. /*** Start of inlined file: juce_PropertyPanel.cpp ***/
  57359. BEGIN_JUCE_NAMESPACE
  57360. class PropertyHolderComponent : public Component
  57361. {
  57362. public:
  57363. PropertyHolderComponent()
  57364. {
  57365. }
  57366. ~PropertyHolderComponent()
  57367. {
  57368. deleteAllChildren();
  57369. }
  57370. void paint (Graphics&)
  57371. {
  57372. }
  57373. void updateLayout (const int width);
  57374. void refreshAll() const;
  57375. };
  57376. class PropertySectionComponent : public Component
  57377. {
  57378. public:
  57379. PropertySectionComponent (const String& sectionTitle,
  57380. const Array <PropertyComponent*>& newProperties,
  57381. const bool open)
  57382. : Component (sectionTitle),
  57383. titleHeight (sectionTitle.isNotEmpty() ? 22 : 0),
  57384. isOpen_ (open)
  57385. {
  57386. for (int i = newProperties.size(); --i >= 0;)
  57387. {
  57388. addAndMakeVisible (newProperties.getUnchecked(i));
  57389. newProperties.getUnchecked(i)->refresh();
  57390. }
  57391. }
  57392. ~PropertySectionComponent()
  57393. {
  57394. deleteAllChildren();
  57395. }
  57396. void paint (Graphics& g)
  57397. {
  57398. if (titleHeight > 0)
  57399. getLookAndFeel().drawPropertyPanelSectionHeader (g, getName(), isOpen(), getWidth(), titleHeight);
  57400. }
  57401. void resized()
  57402. {
  57403. int y = titleHeight;
  57404. for (int i = getNumChildComponents(); --i >= 0;)
  57405. {
  57406. PropertyComponent* const pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57407. if (pec != 0)
  57408. {
  57409. const int prefH = pec->getPreferredHeight();
  57410. pec->setBounds (1, y, getWidth() - 2, prefH);
  57411. y += prefH;
  57412. }
  57413. }
  57414. }
  57415. int getPreferredHeight() const
  57416. {
  57417. int y = titleHeight;
  57418. if (isOpen())
  57419. {
  57420. for (int i = 0; i < getNumChildComponents(); ++i)
  57421. {
  57422. PropertyComponent* pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57423. if (pec != 0)
  57424. y += pec->getPreferredHeight();
  57425. }
  57426. }
  57427. return y;
  57428. }
  57429. void setOpen (const bool open)
  57430. {
  57431. if (isOpen_ != open)
  57432. {
  57433. isOpen_ = open;
  57434. for (int i = 0; i < getNumChildComponents(); ++i)
  57435. {
  57436. PropertyComponent* pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57437. if (pec != 0)
  57438. pec->setVisible (open);
  57439. }
  57440. // (unable to use the syntax findParentComponentOfClass <DragAndDropContainer> () because of a VC6 compiler bug)
  57441. PropertyPanel* const pp = findParentComponentOfClass ((PropertyPanel*) 0);
  57442. if (pp != 0)
  57443. pp->resized();
  57444. }
  57445. }
  57446. bool isOpen() const
  57447. {
  57448. return isOpen_;
  57449. }
  57450. void refreshAll() const
  57451. {
  57452. for (int i = 0; i < getNumChildComponents(); ++i)
  57453. {
  57454. PropertyComponent* pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57455. if (pec != 0)
  57456. pec->refresh();
  57457. }
  57458. }
  57459. void mouseDown (const MouseEvent&)
  57460. {
  57461. }
  57462. void mouseUp (const MouseEvent& e)
  57463. {
  57464. if (e.getMouseDownX() < titleHeight
  57465. && e.x < titleHeight
  57466. && e.y < titleHeight
  57467. && e.getNumberOfClicks() != 2)
  57468. {
  57469. setOpen (! isOpen());
  57470. }
  57471. }
  57472. void mouseDoubleClick (const MouseEvent& e)
  57473. {
  57474. if (e.y < titleHeight)
  57475. setOpen (! isOpen());
  57476. }
  57477. private:
  57478. int titleHeight;
  57479. bool isOpen_;
  57480. };
  57481. void PropertyHolderComponent::updateLayout (const int width)
  57482. {
  57483. int y = 0;
  57484. for (int i = getNumChildComponents(); --i >= 0;)
  57485. {
  57486. PropertySectionComponent* const section
  57487. = dynamic_cast <PropertySectionComponent*> (getChildComponent (i));
  57488. if (section != 0)
  57489. {
  57490. const int prefH = section->getPreferredHeight();
  57491. section->setBounds (0, y, width, prefH);
  57492. y += prefH;
  57493. }
  57494. }
  57495. setSize (width, y);
  57496. repaint();
  57497. }
  57498. void PropertyHolderComponent::refreshAll() const
  57499. {
  57500. for (int i = getNumChildComponents(); --i >= 0;)
  57501. {
  57502. PropertySectionComponent* const section
  57503. = dynamic_cast <PropertySectionComponent*> (getChildComponent (i));
  57504. if (section != 0)
  57505. section->refreshAll();
  57506. }
  57507. }
  57508. PropertyPanel::PropertyPanel()
  57509. {
  57510. messageWhenEmpty = TRANS("(nothing selected)");
  57511. addAndMakeVisible (viewport = new Viewport());
  57512. viewport->setViewedComponent (propertyHolderComponent = new PropertyHolderComponent());
  57513. viewport->setFocusContainer (true);
  57514. }
  57515. PropertyPanel::~PropertyPanel()
  57516. {
  57517. clear();
  57518. deleteAllChildren();
  57519. }
  57520. void PropertyPanel::paint (Graphics& g)
  57521. {
  57522. if (propertyHolderComponent->getNumChildComponents() == 0)
  57523. {
  57524. g.setColour (Colours::black.withAlpha (0.5f));
  57525. g.setFont (14.0f);
  57526. g.drawText (messageWhenEmpty, 0, 0, getWidth(), 30,
  57527. Justification::centred, true);
  57528. }
  57529. }
  57530. void PropertyPanel::resized()
  57531. {
  57532. viewport->setBounds (0, 0, getWidth(), getHeight());
  57533. updatePropHolderLayout();
  57534. }
  57535. void PropertyPanel::clear()
  57536. {
  57537. if (propertyHolderComponent->getNumChildComponents() > 0)
  57538. {
  57539. propertyHolderComponent->deleteAllChildren();
  57540. repaint();
  57541. }
  57542. }
  57543. void PropertyPanel::addProperties (const Array <PropertyComponent*>& newProperties)
  57544. {
  57545. if (propertyHolderComponent->getNumChildComponents() == 0)
  57546. repaint();
  57547. propertyHolderComponent->addAndMakeVisible (new PropertySectionComponent (String::empty,
  57548. newProperties,
  57549. true), 0);
  57550. updatePropHolderLayout();
  57551. }
  57552. void PropertyPanel::addSection (const String& sectionTitle,
  57553. const Array <PropertyComponent*>& newProperties,
  57554. const bool shouldBeOpen)
  57555. {
  57556. jassert (sectionTitle.isNotEmpty());
  57557. if (propertyHolderComponent->getNumChildComponents() == 0)
  57558. repaint();
  57559. propertyHolderComponent->addAndMakeVisible (new PropertySectionComponent (sectionTitle,
  57560. newProperties,
  57561. shouldBeOpen), 0);
  57562. updatePropHolderLayout();
  57563. }
  57564. void PropertyPanel::updatePropHolderLayout() const
  57565. {
  57566. const int maxWidth = viewport->getMaximumVisibleWidth();
  57567. ((PropertyHolderComponent*) propertyHolderComponent)->updateLayout (maxWidth);
  57568. const int newMaxWidth = viewport->getMaximumVisibleWidth();
  57569. if (maxWidth != newMaxWidth)
  57570. {
  57571. // need to do this twice because of scrollbars changing the size, etc.
  57572. ((PropertyHolderComponent*) propertyHolderComponent)->updateLayout (newMaxWidth);
  57573. }
  57574. }
  57575. void PropertyPanel::refreshAll() const
  57576. {
  57577. ((PropertyHolderComponent*) propertyHolderComponent)->refreshAll();
  57578. }
  57579. const StringArray PropertyPanel::getSectionNames() const
  57580. {
  57581. StringArray s;
  57582. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57583. {
  57584. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57585. if (section != 0 && section->getName().isNotEmpty())
  57586. s.add (section->getName());
  57587. }
  57588. return s;
  57589. }
  57590. bool PropertyPanel::isSectionOpen (const int sectionIndex) const
  57591. {
  57592. int index = 0;
  57593. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57594. {
  57595. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57596. if (section != 0 && section->getName().isNotEmpty())
  57597. {
  57598. if (index == sectionIndex)
  57599. return section->isOpen();
  57600. ++index;
  57601. }
  57602. }
  57603. return false;
  57604. }
  57605. void PropertyPanel::setSectionOpen (const int sectionIndex, const bool shouldBeOpen)
  57606. {
  57607. int index = 0;
  57608. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57609. {
  57610. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57611. if (section != 0 && section->getName().isNotEmpty())
  57612. {
  57613. if (index == sectionIndex)
  57614. {
  57615. section->setOpen (shouldBeOpen);
  57616. break;
  57617. }
  57618. ++index;
  57619. }
  57620. }
  57621. }
  57622. void PropertyPanel::setSectionEnabled (const int sectionIndex, const bool shouldBeEnabled)
  57623. {
  57624. int index = 0;
  57625. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57626. {
  57627. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57628. if (section != 0 && section->getName().isNotEmpty())
  57629. {
  57630. if (index == sectionIndex)
  57631. {
  57632. section->setEnabled (shouldBeEnabled);
  57633. break;
  57634. }
  57635. ++index;
  57636. }
  57637. }
  57638. }
  57639. XmlElement* PropertyPanel::getOpennessState() const
  57640. {
  57641. XmlElement* const xml = new XmlElement (T("PROPERTYPANELSTATE"));
  57642. xml->setAttribute ("scrollPos", viewport->getViewPositionY());
  57643. const StringArray sections (getSectionNames());
  57644. for (int i = 0; i < sections.size(); ++i)
  57645. {
  57646. if (sections[i].isNotEmpty())
  57647. {
  57648. XmlElement* const e = xml->createNewChildElement ("SECTION");
  57649. e->setAttribute ("name", sections[i]);
  57650. e->setAttribute ("open", isSectionOpen (i) ? 1 : 0);
  57651. }
  57652. }
  57653. return xml;
  57654. }
  57655. void PropertyPanel::restoreOpennessState (const XmlElement& xml)
  57656. {
  57657. if (xml.hasTagName (T("PROPERTYPANELSTATE")))
  57658. {
  57659. const StringArray sections (getSectionNames());
  57660. forEachXmlChildElementWithTagName (xml, e, T("SECTION"))
  57661. {
  57662. setSectionOpen (sections.indexOf (e->getStringAttribute (T("name"))),
  57663. e->getBoolAttribute (T("open")));
  57664. }
  57665. viewport->setViewPosition (viewport->getViewPositionX(),
  57666. xml.getIntAttribute ("scrollPos", viewport->getViewPositionY()));
  57667. }
  57668. }
  57669. void PropertyPanel::setMessageWhenEmpty (const String& newMessage)
  57670. {
  57671. if (messageWhenEmpty != newMessage)
  57672. {
  57673. messageWhenEmpty = newMessage;
  57674. repaint();
  57675. }
  57676. }
  57677. const String& PropertyPanel::getMessageWhenEmpty() const
  57678. {
  57679. return messageWhenEmpty;
  57680. }
  57681. END_JUCE_NAMESPACE
  57682. /*** End of inlined file: juce_PropertyPanel.cpp ***/
  57683. /*** Start of inlined file: juce_SliderPropertyComponent.cpp ***/
  57684. BEGIN_JUCE_NAMESPACE
  57685. SliderPropertyComponent::SliderPropertyComponent (const String& name,
  57686. const double rangeMin,
  57687. const double rangeMax,
  57688. const double interval,
  57689. const double skewFactor)
  57690. : PropertyComponent (name)
  57691. {
  57692. addAndMakeVisible (slider = new Slider (name));
  57693. slider->setRange (rangeMin, rangeMax, interval);
  57694. slider->setSkewFactor (skewFactor);
  57695. slider->setSliderStyle (Slider::LinearBar);
  57696. slider->addListener (this);
  57697. }
  57698. SliderPropertyComponent::SliderPropertyComponent (Value& valueToControl,
  57699. const String& name,
  57700. const double rangeMin,
  57701. const double rangeMax,
  57702. const double interval,
  57703. const double skewFactor)
  57704. : PropertyComponent (name)
  57705. {
  57706. addAndMakeVisible (slider = new Slider (name));
  57707. slider->setRange (rangeMin, rangeMax, interval);
  57708. slider->setSkewFactor (skewFactor);
  57709. slider->setSliderStyle (Slider::LinearBar);
  57710. slider->getValueObject().referTo (valueToControl);
  57711. }
  57712. SliderPropertyComponent::~SliderPropertyComponent()
  57713. {
  57714. deleteAllChildren();
  57715. }
  57716. void SliderPropertyComponent::setValue (const double /*newValue*/)
  57717. {
  57718. }
  57719. const double SliderPropertyComponent::getValue() const
  57720. {
  57721. return slider->getValue();
  57722. }
  57723. void SliderPropertyComponent::refresh()
  57724. {
  57725. slider->setValue (getValue(), false);
  57726. }
  57727. void SliderPropertyComponent::sliderValueChanged (Slider*)
  57728. {
  57729. if (getValue() != slider->getValue())
  57730. setValue (slider->getValue());
  57731. }
  57732. END_JUCE_NAMESPACE
  57733. /*** End of inlined file: juce_SliderPropertyComponent.cpp ***/
  57734. /*** Start of inlined file: juce_TextPropertyComponent.cpp ***/
  57735. BEGIN_JUCE_NAMESPACE
  57736. class TextPropLabel : public Label
  57737. {
  57738. TextPropertyComponent& owner;
  57739. int maxChars;
  57740. bool isMultiline;
  57741. public:
  57742. TextPropLabel (TextPropertyComponent& owner_,
  57743. const int maxChars_, const bool isMultiline_)
  57744. : Label (String::empty, String::empty),
  57745. owner (owner_),
  57746. maxChars (maxChars_),
  57747. isMultiline (isMultiline_)
  57748. {
  57749. setEditable (true, true, false);
  57750. setColour (backgroundColourId, Colours::white);
  57751. setColour (outlineColourId, findColour (ComboBox::outlineColourId));
  57752. }
  57753. ~TextPropLabel()
  57754. {
  57755. }
  57756. TextEditor* createEditorComponent()
  57757. {
  57758. TextEditor* const textEditor = Label::createEditorComponent();
  57759. textEditor->setInputRestrictions (maxChars);
  57760. if (isMultiline)
  57761. {
  57762. textEditor->setMultiLine (true, true);
  57763. textEditor->setReturnKeyStartsNewLine (true);
  57764. }
  57765. return textEditor;
  57766. }
  57767. void textWasEdited()
  57768. {
  57769. owner.textWasEdited();
  57770. }
  57771. };
  57772. TextPropertyComponent::TextPropertyComponent (const String& name,
  57773. const int maxNumChars,
  57774. const bool isMultiLine)
  57775. : PropertyComponent (name)
  57776. {
  57777. createEditor (maxNumChars, isMultiLine);
  57778. }
  57779. TextPropertyComponent::TextPropertyComponent (const Value& valueToControl,
  57780. const String& name,
  57781. const int maxNumChars,
  57782. const bool isMultiLine)
  57783. : PropertyComponent (name)
  57784. {
  57785. createEditor (maxNumChars, isMultiLine);
  57786. textEditor->getTextValue().referTo (valueToControl);
  57787. }
  57788. TextPropertyComponent::~TextPropertyComponent()
  57789. {
  57790. deleteAllChildren();
  57791. }
  57792. void TextPropertyComponent::setText (const String& newText)
  57793. {
  57794. textEditor->setText (newText, true);
  57795. }
  57796. const String TextPropertyComponent::getText() const
  57797. {
  57798. return textEditor->getText();
  57799. }
  57800. void TextPropertyComponent::createEditor (const int maxNumChars, const bool isMultiLine)
  57801. {
  57802. addAndMakeVisible (textEditor = new TextPropLabel (*this, maxNumChars, isMultiLine));
  57803. if (isMultiLine)
  57804. {
  57805. textEditor->setJustificationType (Justification::topLeft);
  57806. preferredHeight = 120;
  57807. }
  57808. }
  57809. void TextPropertyComponent::refresh()
  57810. {
  57811. textEditor->setText (getText(), false);
  57812. }
  57813. void TextPropertyComponent::textWasEdited()
  57814. {
  57815. const String newText (textEditor->getText());
  57816. if (getText() != newText)
  57817. setText (newText);
  57818. }
  57819. END_JUCE_NAMESPACE
  57820. /*** End of inlined file: juce_TextPropertyComponent.cpp ***/
  57821. /*** Start of inlined file: juce_AudioDeviceSelectorComponent.cpp ***/
  57822. BEGIN_JUCE_NAMESPACE
  57823. class SimpleDeviceManagerInputLevelMeter : public Component,
  57824. public Timer
  57825. {
  57826. public:
  57827. SimpleDeviceManagerInputLevelMeter (AudioDeviceManager* const manager_)
  57828. : manager (manager_),
  57829. level (0)
  57830. {
  57831. startTimer (50);
  57832. manager->enableInputLevelMeasurement (true);
  57833. }
  57834. ~SimpleDeviceManagerInputLevelMeter()
  57835. {
  57836. manager->enableInputLevelMeasurement (false);
  57837. }
  57838. void timerCallback()
  57839. {
  57840. const float newLevel = (float) manager->getCurrentInputLevel();
  57841. if (fabsf (level - newLevel) > 0.005f)
  57842. {
  57843. level = newLevel;
  57844. repaint();
  57845. }
  57846. }
  57847. void paint (Graphics& g)
  57848. {
  57849. getLookAndFeel().drawLevelMeter (g, getWidth(), getHeight(),
  57850. (float) exp (log (level) / 3.0)); // (add a bit of a skew to make the level more obvious)
  57851. }
  57852. private:
  57853. AudioDeviceManager* const manager;
  57854. float level;
  57855. };
  57856. class MidiInputSelectorComponentListBox : public ListBox,
  57857. public ListBoxModel
  57858. {
  57859. public:
  57860. MidiInputSelectorComponentListBox (AudioDeviceManager& deviceManager_,
  57861. const String& noItemsMessage_,
  57862. const int minNumber_,
  57863. const int maxNumber_)
  57864. : ListBox (String::empty, 0),
  57865. deviceManager (deviceManager_),
  57866. noItemsMessage (noItemsMessage_),
  57867. minNumber (minNumber_),
  57868. maxNumber (maxNumber_)
  57869. {
  57870. items = MidiInput::getDevices();
  57871. setModel (this);
  57872. setOutlineThickness (1);
  57873. }
  57874. ~MidiInputSelectorComponentListBox()
  57875. {
  57876. }
  57877. int getNumRows()
  57878. {
  57879. return items.size();
  57880. }
  57881. void paintListBoxItem (int row,
  57882. Graphics& g,
  57883. int width, int height,
  57884. bool rowIsSelected)
  57885. {
  57886. if (((unsigned int) row) < (unsigned int) items.size())
  57887. {
  57888. if (rowIsSelected)
  57889. g.fillAll (findColour (TextEditor::highlightColourId)
  57890. .withMultipliedAlpha (0.3f));
  57891. const String item (items [row]);
  57892. bool enabled = deviceManager.isMidiInputEnabled (item);
  57893. const int x = getTickX();
  57894. const float tickW = height * 0.75f;
  57895. getLookAndFeel().drawTickBox (g, *this, x - tickW, (height - tickW) / 2, tickW, tickW,
  57896. enabled, true, true, false);
  57897. g.setFont (height * 0.6f);
  57898. g.setColour (findColour (ListBox::textColourId, true).withMultipliedAlpha (enabled ? 1.0f : 0.6f));
  57899. g.drawText (item, x, 0, width - x - 2, height, Justification::centredLeft, true);
  57900. }
  57901. }
  57902. void listBoxItemClicked (int row, const MouseEvent& e)
  57903. {
  57904. selectRow (row);
  57905. if (e.x < getTickX())
  57906. flipEnablement (row);
  57907. }
  57908. void listBoxItemDoubleClicked (int row, const MouseEvent&)
  57909. {
  57910. flipEnablement (row);
  57911. }
  57912. void returnKeyPressed (int row)
  57913. {
  57914. flipEnablement (row);
  57915. }
  57916. void paint (Graphics& g)
  57917. {
  57918. ListBox::paint (g);
  57919. if (items.size() == 0)
  57920. {
  57921. g.setColour (Colours::grey);
  57922. g.setFont (13.0f);
  57923. g.drawText (noItemsMessage,
  57924. 0, 0, getWidth(), getHeight() / 2,
  57925. Justification::centred, true);
  57926. }
  57927. }
  57928. int getBestHeight (const int preferredHeight)
  57929. {
  57930. const int extra = getOutlineThickness() * 2;
  57931. return jmax (getRowHeight() * 2 + extra,
  57932. jmin (getRowHeight() * getNumRows() + extra,
  57933. preferredHeight));
  57934. }
  57935. juce_UseDebuggingNewOperator
  57936. private:
  57937. AudioDeviceManager& deviceManager;
  57938. const String noItemsMessage;
  57939. StringArray items;
  57940. int minNumber, maxNumber;
  57941. void flipEnablement (const int row)
  57942. {
  57943. if (((unsigned int) row) < (unsigned int) items.size())
  57944. {
  57945. const String item (items [row]);
  57946. deviceManager.setMidiInputEnabled (item, ! deviceManager.isMidiInputEnabled (item));
  57947. }
  57948. }
  57949. int getTickX() const
  57950. {
  57951. return getRowHeight() + 5;
  57952. }
  57953. MidiInputSelectorComponentListBox (const MidiInputSelectorComponentListBox&);
  57954. const MidiInputSelectorComponentListBox& operator= (const MidiInputSelectorComponentListBox&);
  57955. };
  57956. class AudioDeviceSettingsPanel : public Component,
  57957. public ComboBoxListener,
  57958. public ChangeListener,
  57959. public ButtonListener
  57960. {
  57961. public:
  57962. AudioDeviceSettingsPanel (AudioIODeviceType* type_,
  57963. AudioIODeviceType::DeviceSetupDetails& setup_,
  57964. const bool hideAdvancedOptionsWithButton)
  57965. : type (type_),
  57966. setup (setup_)
  57967. {
  57968. sampleRateDropDown = 0;
  57969. sampleRateLabel = 0;
  57970. bufferSizeDropDown = 0;
  57971. bufferSizeLabel = 0;
  57972. outputDeviceDropDown = 0;
  57973. outputDeviceLabel = 0;
  57974. inputDeviceDropDown = 0;
  57975. inputDeviceLabel = 0;
  57976. testButton = 0;
  57977. inputLevelMeter = 0;
  57978. showUIButton = 0;
  57979. inputChanList = 0;
  57980. outputChanList = 0;
  57981. inputChanLabel = 0;
  57982. outputChanLabel = 0;
  57983. showAdvancedSettingsButton = 0;
  57984. if (hideAdvancedOptionsWithButton)
  57985. {
  57986. addAndMakeVisible (showAdvancedSettingsButton = new TextButton (TRANS("Show advanced settings...")));
  57987. showAdvancedSettingsButton->addButtonListener (this);
  57988. }
  57989. type->scanForDevices();
  57990. setup.manager->addChangeListener (this);
  57991. changeListenerCallback (0);
  57992. }
  57993. ~AudioDeviceSettingsPanel()
  57994. {
  57995. setup.manager->removeChangeListener (this);
  57996. deleteAndZero (outputDeviceLabel);
  57997. deleteAndZero (inputDeviceLabel);
  57998. deleteAndZero (sampleRateLabel);
  57999. deleteAndZero (bufferSizeLabel);
  58000. deleteAndZero (showUIButton);
  58001. deleteAndZero (inputChanLabel);
  58002. deleteAndZero (outputChanLabel);
  58003. deleteAndZero (showAdvancedSettingsButton);
  58004. deleteAllChildren();
  58005. }
  58006. void resized()
  58007. {
  58008. const int lx = proportionOfWidth (0.35f);
  58009. const int w = proportionOfWidth (0.4f);
  58010. const int h = 24;
  58011. const int space = 6;
  58012. const int dh = h + space;
  58013. int y = 0;
  58014. if (outputDeviceDropDown != 0)
  58015. {
  58016. outputDeviceDropDown->setBounds (lx, y, w, h);
  58017. if (testButton != 0)
  58018. testButton->setBounds (proportionOfWidth (0.77f),
  58019. outputDeviceDropDown->getY(),
  58020. proportionOfWidth (0.18f),
  58021. h);
  58022. y += dh;
  58023. }
  58024. if (inputDeviceDropDown != 0)
  58025. {
  58026. inputDeviceDropDown->setBounds (lx, y, w, h);
  58027. inputLevelMeter->setBounds (proportionOfWidth (0.77f),
  58028. inputDeviceDropDown->getY(),
  58029. proportionOfWidth (0.18f),
  58030. h);
  58031. y += dh;
  58032. }
  58033. const int maxBoxHeight = 100;//(getHeight() - y - dh * 2) / numBoxes;
  58034. if (outputChanList != 0)
  58035. {
  58036. const int bh = outputChanList->getBestHeight (maxBoxHeight);
  58037. outputChanList->setBounds (lx, y, proportionOfWidth (0.55f), bh);
  58038. y += bh + space;
  58039. }
  58040. if (inputChanList != 0)
  58041. {
  58042. const int bh = inputChanList->getBestHeight (maxBoxHeight);
  58043. inputChanList->setBounds (lx, y, proportionOfWidth (0.55f), bh);
  58044. y += bh + space;
  58045. }
  58046. y += space * 2;
  58047. if (showAdvancedSettingsButton != 0)
  58048. {
  58049. showAdvancedSettingsButton->changeWidthToFitText (h);
  58050. showAdvancedSettingsButton->setTopLeftPosition (lx, y);
  58051. }
  58052. if (sampleRateDropDown != 0)
  58053. {
  58054. sampleRateDropDown->setVisible (showAdvancedSettingsButton == 0
  58055. || ! showAdvancedSettingsButton->isVisible());
  58056. sampleRateDropDown->setBounds (lx, y, w, h);
  58057. y += dh;
  58058. }
  58059. if (bufferSizeDropDown != 0)
  58060. {
  58061. bufferSizeDropDown->setVisible (showAdvancedSettingsButton == 0
  58062. || ! showAdvancedSettingsButton->isVisible());
  58063. bufferSizeDropDown->setBounds (lx, y, w, h);
  58064. y += dh;
  58065. }
  58066. if (showUIButton != 0)
  58067. {
  58068. showUIButton->setVisible (showAdvancedSettingsButton == 0
  58069. || ! showAdvancedSettingsButton->isVisible());
  58070. showUIButton->changeWidthToFitText (h);
  58071. showUIButton->setTopLeftPosition (lx, y);
  58072. }
  58073. }
  58074. void comboBoxChanged (ComboBox* comboBoxThatHasChanged)
  58075. {
  58076. if (comboBoxThatHasChanged == 0)
  58077. return;
  58078. AudioDeviceManager::AudioDeviceSetup config;
  58079. setup.manager->getAudioDeviceSetup (config);
  58080. String error;
  58081. if (comboBoxThatHasChanged == outputDeviceDropDown
  58082. || comboBoxThatHasChanged == inputDeviceDropDown)
  58083. {
  58084. if (outputDeviceDropDown != 0)
  58085. config.outputDeviceName = outputDeviceDropDown->getSelectedId() < 0 ? String::empty
  58086. : outputDeviceDropDown->getText();
  58087. if (inputDeviceDropDown != 0)
  58088. config.inputDeviceName = inputDeviceDropDown->getSelectedId() < 0 ? String::empty
  58089. : inputDeviceDropDown->getText();
  58090. if (! type->hasSeparateInputsAndOutputs())
  58091. config.inputDeviceName = config.outputDeviceName;
  58092. if (comboBoxThatHasChanged == inputDeviceDropDown)
  58093. config.useDefaultInputChannels = true;
  58094. else
  58095. config.useDefaultOutputChannels = true;
  58096. error = setup.manager->setAudioDeviceSetup (config, true);
  58097. showCorrectDeviceName (inputDeviceDropDown, true);
  58098. showCorrectDeviceName (outputDeviceDropDown, false);
  58099. updateControlPanelButton();
  58100. resized();
  58101. }
  58102. else if (comboBoxThatHasChanged == sampleRateDropDown)
  58103. {
  58104. if (sampleRateDropDown->getSelectedId() > 0)
  58105. {
  58106. config.sampleRate = sampleRateDropDown->getSelectedId();
  58107. error = setup.manager->setAudioDeviceSetup (config, true);
  58108. }
  58109. }
  58110. else if (comboBoxThatHasChanged == bufferSizeDropDown)
  58111. {
  58112. if (bufferSizeDropDown->getSelectedId() > 0)
  58113. {
  58114. config.bufferSize = bufferSizeDropDown->getSelectedId();
  58115. error = setup.manager->setAudioDeviceSetup (config, true);
  58116. }
  58117. }
  58118. if (error.isNotEmpty())
  58119. {
  58120. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  58121. T("Error when trying to open audio device!"),
  58122. error);
  58123. }
  58124. }
  58125. void buttonClicked (Button* button)
  58126. {
  58127. if (button == showAdvancedSettingsButton)
  58128. {
  58129. showAdvancedSettingsButton->setVisible (false);
  58130. resized();
  58131. }
  58132. else if (button == showUIButton)
  58133. {
  58134. AudioIODevice* const device = setup.manager->getCurrentAudioDevice();
  58135. if (device != 0 && device->showControlPanel())
  58136. {
  58137. setup.manager->closeAudioDevice();
  58138. setup.manager->restartLastAudioDevice();
  58139. getTopLevelComponent()->toFront (true);
  58140. }
  58141. }
  58142. else if (button == testButton && testButton != 0)
  58143. {
  58144. setup.manager->playTestSound();
  58145. }
  58146. }
  58147. void updateControlPanelButton()
  58148. {
  58149. AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice();
  58150. deleteAndZero (showUIButton);
  58151. if (currentDevice != 0 && currentDevice->hasControlPanel())
  58152. {
  58153. addAndMakeVisible (showUIButton = new TextButton (TRANS ("show this device's control panel"),
  58154. TRANS ("opens the device's own control panel")));
  58155. showUIButton->addButtonListener (this);
  58156. }
  58157. resized();
  58158. }
  58159. void changeListenerCallback (void*)
  58160. {
  58161. AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice();
  58162. if (setup.maxNumOutputChannels > 0 || ! type->hasSeparateInputsAndOutputs())
  58163. {
  58164. if (outputDeviceDropDown == 0)
  58165. {
  58166. outputDeviceDropDown = new ComboBox (String::empty);
  58167. outputDeviceDropDown->addListener (this);
  58168. addAndMakeVisible (outputDeviceDropDown);
  58169. outputDeviceLabel = new Label (String::empty,
  58170. type->hasSeparateInputsAndOutputs() ? TRANS ("output:")
  58171. : TRANS ("device:"));
  58172. outputDeviceLabel->attachToComponent (outputDeviceDropDown, true);
  58173. if (setup.maxNumOutputChannels > 0)
  58174. {
  58175. addAndMakeVisible (testButton = new TextButton (TRANS ("Test")));
  58176. testButton->addButtonListener (this);
  58177. }
  58178. }
  58179. addNamesToDeviceBox (*outputDeviceDropDown, false);
  58180. }
  58181. if (setup.maxNumInputChannels > 0 && type->hasSeparateInputsAndOutputs())
  58182. {
  58183. if (inputDeviceDropDown == 0)
  58184. {
  58185. inputDeviceDropDown = new ComboBox (String::empty);
  58186. inputDeviceDropDown->addListener (this);
  58187. addAndMakeVisible (inputDeviceDropDown);
  58188. inputDeviceLabel = new Label (String::empty, TRANS ("input:"));
  58189. inputDeviceLabel->attachToComponent (inputDeviceDropDown, true);
  58190. addAndMakeVisible (inputLevelMeter
  58191. = new SimpleDeviceManagerInputLevelMeter (setup.manager));
  58192. }
  58193. addNamesToDeviceBox (*inputDeviceDropDown, true);
  58194. }
  58195. updateControlPanelButton();
  58196. showCorrectDeviceName (inputDeviceDropDown, true);
  58197. showCorrectDeviceName (outputDeviceDropDown, false);
  58198. if (currentDevice != 0)
  58199. {
  58200. if (setup.maxNumOutputChannels > 0
  58201. && setup.minNumOutputChannels < setup.manager->getCurrentAudioDevice()->getOutputChannelNames().size())
  58202. {
  58203. if (outputChanList == 0)
  58204. {
  58205. addAndMakeVisible (outputChanList
  58206. = new ChannelSelectorListBox (setup, ChannelSelectorListBox::audioOutputType,
  58207. TRANS ("(no audio output channels found)")));
  58208. outputChanLabel = new Label (String::empty, TRANS ("active output channels:"));
  58209. outputChanLabel->attachToComponent (outputChanList, true);
  58210. }
  58211. outputChanList->refresh();
  58212. }
  58213. else
  58214. {
  58215. deleteAndZero (outputChanLabel);
  58216. deleteAndZero (outputChanList);
  58217. }
  58218. if (setup.maxNumInputChannels > 0
  58219. && setup.minNumInputChannels < setup.manager->getCurrentAudioDevice()->getInputChannelNames().size())
  58220. {
  58221. if (inputChanList == 0)
  58222. {
  58223. addAndMakeVisible (inputChanList
  58224. = new ChannelSelectorListBox (setup, ChannelSelectorListBox::audioInputType,
  58225. TRANS ("(no audio input channels found)")));
  58226. inputChanLabel = new Label (String::empty, TRANS ("active input channels:"));
  58227. inputChanLabel->attachToComponent (inputChanList, true);
  58228. }
  58229. inputChanList->refresh();
  58230. }
  58231. else
  58232. {
  58233. deleteAndZero (inputChanLabel);
  58234. deleteAndZero (inputChanList);
  58235. }
  58236. // sample rate..
  58237. {
  58238. if (sampleRateDropDown == 0)
  58239. {
  58240. addAndMakeVisible (sampleRateDropDown = new ComboBox (String::empty));
  58241. sampleRateDropDown->addListener (this);
  58242. delete sampleRateLabel;
  58243. sampleRateLabel = new Label (String::empty, TRANS ("sample rate:"));
  58244. sampleRateLabel->attachToComponent (sampleRateDropDown, true);
  58245. }
  58246. else
  58247. {
  58248. sampleRateDropDown->clear();
  58249. sampleRateDropDown->removeListener (this);
  58250. }
  58251. const int numRates = currentDevice->getNumSampleRates();
  58252. for (int i = 0; i < numRates; ++i)
  58253. {
  58254. const int rate = roundToInt (currentDevice->getSampleRate (i));
  58255. sampleRateDropDown->addItem (String (rate) + T(" Hz"), rate);
  58256. }
  58257. sampleRateDropDown->setSelectedId (roundToInt (currentDevice->getCurrentSampleRate()), true);
  58258. sampleRateDropDown->addListener (this);
  58259. }
  58260. // buffer size
  58261. {
  58262. if (bufferSizeDropDown == 0)
  58263. {
  58264. addAndMakeVisible (bufferSizeDropDown = new ComboBox (String::empty));
  58265. bufferSizeDropDown->addListener (this);
  58266. delete bufferSizeLabel;
  58267. bufferSizeLabel = new Label (String::empty, TRANS ("audio buffer size:"));
  58268. bufferSizeLabel->attachToComponent (bufferSizeDropDown, true);
  58269. }
  58270. else
  58271. {
  58272. bufferSizeDropDown->clear();
  58273. }
  58274. const int numBufferSizes = currentDevice->getNumBufferSizesAvailable();
  58275. double currentRate = currentDevice->getCurrentSampleRate();
  58276. if (currentRate == 0)
  58277. currentRate = 48000.0;
  58278. for (int i = 0; i < numBufferSizes; ++i)
  58279. {
  58280. const int bs = currentDevice->getBufferSizeSamples (i);
  58281. bufferSizeDropDown->addItem (String (bs)
  58282. + T(" samples (")
  58283. + String (bs * 1000.0 / currentRate, 1)
  58284. + T(" ms)"),
  58285. bs);
  58286. }
  58287. bufferSizeDropDown->setSelectedId (currentDevice->getCurrentBufferSizeSamples(), true);
  58288. }
  58289. }
  58290. else
  58291. {
  58292. jassert (setup.manager->getCurrentAudioDevice() == 0); // not the correct device type!
  58293. deleteAndZero (sampleRateLabel);
  58294. deleteAndZero (bufferSizeLabel);
  58295. deleteAndZero (sampleRateDropDown);
  58296. deleteAndZero (bufferSizeDropDown);
  58297. if (outputDeviceDropDown != 0)
  58298. outputDeviceDropDown->setSelectedId (-1, true);
  58299. if (inputDeviceDropDown != 0)
  58300. inputDeviceDropDown->setSelectedId (-1, true);
  58301. }
  58302. resized();
  58303. setSize (getWidth(), getLowestY() + 4);
  58304. }
  58305. private:
  58306. AudioIODeviceType* const type;
  58307. const AudioIODeviceType::DeviceSetupDetails setup;
  58308. ComboBox* outputDeviceDropDown;
  58309. ComboBox* inputDeviceDropDown;
  58310. ComboBox* sampleRateDropDown;
  58311. ComboBox* bufferSizeDropDown;
  58312. Label* outputDeviceLabel;
  58313. Label* inputDeviceLabel;
  58314. Label* sampleRateLabel;
  58315. Label* bufferSizeLabel;
  58316. Label* inputChanLabel;
  58317. Label* outputChanLabel;
  58318. TextButton* testButton;
  58319. Component* inputLevelMeter;
  58320. TextButton* showUIButton;
  58321. TextButton* showAdvancedSettingsButton;
  58322. void showCorrectDeviceName (ComboBox* const box, const bool isInput)
  58323. {
  58324. if (box != 0)
  58325. {
  58326. AudioIODevice* const currentDevice = dynamic_cast <AudioIODevice*> (setup.manager->getCurrentAudioDevice());
  58327. const int index = type->getIndexOfDevice (currentDevice, isInput);
  58328. box->setSelectedId (index + 1, true);
  58329. if (testButton != 0 && ! isInput)
  58330. testButton->setEnabled (index >= 0);
  58331. }
  58332. }
  58333. void addNamesToDeviceBox (ComboBox& combo, bool isInputs)
  58334. {
  58335. const StringArray devs (type->getDeviceNames (isInputs));
  58336. combo.clear (true);
  58337. for (int i = 0; i < devs.size(); ++i)
  58338. combo.addItem (devs[i], i + 1);
  58339. combo.addItem (TRANS("<< none >>"), -1);
  58340. combo.setSelectedId (-1, true);
  58341. }
  58342. int getLowestY() const
  58343. {
  58344. int y = 0;
  58345. for (int i = getNumChildComponents(); --i >= 0;)
  58346. y = jmax (y, getChildComponent (i)->getBottom());
  58347. return y;
  58348. }
  58349. public:
  58350. class ChannelSelectorListBox : public ListBox,
  58351. public ListBoxModel
  58352. {
  58353. public:
  58354. enum BoxType
  58355. {
  58356. audioInputType,
  58357. audioOutputType
  58358. };
  58359. ChannelSelectorListBox (const AudioIODeviceType::DeviceSetupDetails& setup_,
  58360. const BoxType type_,
  58361. const String& noItemsMessage_)
  58362. : ListBox (String::empty, 0),
  58363. setup (setup_),
  58364. type (type_),
  58365. noItemsMessage (noItemsMessage_)
  58366. {
  58367. refresh();
  58368. setModel (this);
  58369. setOutlineThickness (1);
  58370. }
  58371. ~ChannelSelectorListBox()
  58372. {
  58373. }
  58374. void refresh()
  58375. {
  58376. items.clear();
  58377. AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice();
  58378. if (currentDevice != 0)
  58379. {
  58380. if (type == audioInputType)
  58381. items = currentDevice->getInputChannelNames();
  58382. else if (type == audioOutputType)
  58383. items = currentDevice->getOutputChannelNames();
  58384. if (setup.useStereoPairs)
  58385. {
  58386. StringArray pairs;
  58387. for (int i = 0; i < items.size(); i += 2)
  58388. {
  58389. String name (items[i]);
  58390. String name2 (items[i + 1]);
  58391. String commonBit;
  58392. for (int j = 0; j < name.length(); ++j)
  58393. if (name.substring (0, j).equalsIgnoreCase (name2.substring (0, j)))
  58394. commonBit = name.substring (0, j);
  58395. pairs.add (name.trim()
  58396. + " + "
  58397. + name2.substring (commonBit.length()).trim());
  58398. }
  58399. items = pairs;
  58400. }
  58401. }
  58402. updateContent();
  58403. repaint();
  58404. }
  58405. int getNumRows()
  58406. {
  58407. return items.size();
  58408. }
  58409. void paintListBoxItem (int row,
  58410. Graphics& g,
  58411. int width, int height,
  58412. bool rowIsSelected)
  58413. {
  58414. if (((unsigned int) row) < (unsigned int) items.size())
  58415. {
  58416. if (rowIsSelected)
  58417. g.fillAll (findColour (TextEditor::highlightColourId)
  58418. .withMultipliedAlpha (0.3f));
  58419. const String item (items [row]);
  58420. bool enabled = false;
  58421. AudioDeviceManager::AudioDeviceSetup config;
  58422. setup.manager->getAudioDeviceSetup (config);
  58423. if (setup.useStereoPairs)
  58424. {
  58425. if (type == audioInputType)
  58426. enabled = config.inputChannels [row * 2] || config.inputChannels [row * 2 + 1];
  58427. else if (type == audioOutputType)
  58428. enabled = config.outputChannels [row * 2] || config.outputChannels [row * 2 + 1];
  58429. }
  58430. else
  58431. {
  58432. if (type == audioInputType)
  58433. enabled = config.inputChannels [row];
  58434. else if (type == audioOutputType)
  58435. enabled = config.outputChannels [row];
  58436. }
  58437. const int x = getTickX();
  58438. const float tickW = height * 0.75f;
  58439. getLookAndFeel().drawTickBox (g, *this, x - tickW, (height - tickW) / 2, tickW, tickW,
  58440. enabled, true, true, false);
  58441. g.setFont (height * 0.6f);
  58442. g.setColour (findColour (ListBox::textColourId, true).withMultipliedAlpha (enabled ? 1.0f : 0.6f));
  58443. g.drawText (item, x, 0, width - x - 2, height, Justification::centredLeft, true);
  58444. }
  58445. }
  58446. void listBoxItemClicked (int row, const MouseEvent& e)
  58447. {
  58448. selectRow (row);
  58449. if (e.x < getTickX())
  58450. flipEnablement (row);
  58451. }
  58452. void listBoxItemDoubleClicked (int row, const MouseEvent&)
  58453. {
  58454. flipEnablement (row);
  58455. }
  58456. void returnKeyPressed (int row)
  58457. {
  58458. flipEnablement (row);
  58459. }
  58460. void paint (Graphics& g)
  58461. {
  58462. ListBox::paint (g);
  58463. if (items.size() == 0)
  58464. {
  58465. g.setColour (Colours::grey);
  58466. g.setFont (13.0f);
  58467. g.drawText (noItemsMessage,
  58468. 0, 0, getWidth(), getHeight() / 2,
  58469. Justification::centred, true);
  58470. }
  58471. }
  58472. int getBestHeight (int maxHeight)
  58473. {
  58474. return getRowHeight() * jlimit (2, jmax (2, maxHeight / getRowHeight()),
  58475. getNumRows())
  58476. + getOutlineThickness() * 2;
  58477. }
  58478. juce_UseDebuggingNewOperator
  58479. private:
  58480. const AudioIODeviceType::DeviceSetupDetails setup;
  58481. const BoxType type;
  58482. const String noItemsMessage;
  58483. StringArray items;
  58484. void flipEnablement (const int row)
  58485. {
  58486. jassert (type == audioInputType || type == audioOutputType);
  58487. if (((unsigned int) row) < (unsigned int) items.size())
  58488. {
  58489. AudioDeviceManager::AudioDeviceSetup config;
  58490. setup.manager->getAudioDeviceSetup (config);
  58491. if (setup.useStereoPairs)
  58492. {
  58493. BitArray bits;
  58494. BitArray& original = (type == audioInputType ? config.inputChannels
  58495. : config.outputChannels);
  58496. int i;
  58497. for (i = 0; i < 256; i += 2)
  58498. bits.setBit (i / 2, original [i] || original [i + 1]);
  58499. if (type == audioInputType)
  58500. {
  58501. config.useDefaultInputChannels = false;
  58502. flipBit (bits, row, setup.minNumInputChannels / 2, setup.maxNumInputChannels / 2);
  58503. }
  58504. else
  58505. {
  58506. config.useDefaultOutputChannels = false;
  58507. flipBit (bits, row, setup.minNumOutputChannels / 2, setup.maxNumOutputChannels / 2);
  58508. }
  58509. for (i = 0; i < 256; ++i)
  58510. original.setBit (i, bits [i / 2]);
  58511. }
  58512. else
  58513. {
  58514. if (type == audioInputType)
  58515. {
  58516. config.useDefaultInputChannels = false;
  58517. flipBit (config.inputChannels, row, setup.minNumInputChannels, setup.maxNumInputChannels);
  58518. }
  58519. else
  58520. {
  58521. config.useDefaultOutputChannels = false;
  58522. flipBit (config.outputChannels, row, setup.minNumOutputChannels, setup.maxNumOutputChannels);
  58523. }
  58524. }
  58525. String error (setup.manager->setAudioDeviceSetup (config, true));
  58526. if (! error.isEmpty())
  58527. {
  58528. //xxx
  58529. }
  58530. }
  58531. }
  58532. static void flipBit (BitArray& chans, int index, int minNumber, int maxNumber)
  58533. {
  58534. const int numActive = chans.countNumberOfSetBits();
  58535. if (chans [index])
  58536. {
  58537. if (numActive > minNumber)
  58538. chans.setBit (index, false);
  58539. }
  58540. else
  58541. {
  58542. if (numActive >= maxNumber)
  58543. {
  58544. const int firstActiveChan = chans.findNextSetBit();
  58545. chans.setBit (index > firstActiveChan
  58546. ? firstActiveChan : chans.getHighestBit(),
  58547. false);
  58548. }
  58549. chans.setBit (index, true);
  58550. }
  58551. }
  58552. int getTickX() const
  58553. {
  58554. return getRowHeight() + 5;
  58555. }
  58556. ChannelSelectorListBox (const ChannelSelectorListBox&);
  58557. const ChannelSelectorListBox& operator= (const ChannelSelectorListBox&);
  58558. };
  58559. private:
  58560. ChannelSelectorListBox* inputChanList;
  58561. ChannelSelectorListBox* outputChanList;
  58562. AudioDeviceSettingsPanel (const AudioDeviceSettingsPanel&);
  58563. const AudioDeviceSettingsPanel& operator= (const AudioDeviceSettingsPanel&);
  58564. };
  58565. AudioDeviceSelectorComponent::AudioDeviceSelectorComponent (AudioDeviceManager& deviceManager_,
  58566. const int minInputChannels_,
  58567. const int maxInputChannels_,
  58568. const int minOutputChannels_,
  58569. const int maxOutputChannels_,
  58570. const bool showMidiInputOptions,
  58571. const bool showMidiOutputSelector,
  58572. const bool showChannelsAsStereoPairs_,
  58573. const bool hideAdvancedOptionsWithButton_)
  58574. : deviceManager (deviceManager_),
  58575. deviceTypeDropDown (0),
  58576. deviceTypeDropDownLabel (0),
  58577. audioDeviceSettingsComp (0),
  58578. minOutputChannels (minOutputChannels_),
  58579. maxOutputChannels (maxOutputChannels_),
  58580. minInputChannels (minInputChannels_),
  58581. maxInputChannels (maxInputChannels_),
  58582. showChannelsAsStereoPairs (showChannelsAsStereoPairs_),
  58583. hideAdvancedOptionsWithButton (hideAdvancedOptionsWithButton_)
  58584. {
  58585. jassert (minOutputChannels >= 0 && minOutputChannels <= maxOutputChannels);
  58586. jassert (minInputChannels >= 0 && minInputChannels <= maxInputChannels);
  58587. if (deviceManager_.getAvailableDeviceTypes().size() > 1)
  58588. {
  58589. deviceTypeDropDown = new ComboBox (String::empty);
  58590. for (int i = 0; i < deviceManager_.getAvailableDeviceTypes().size(); ++i)
  58591. {
  58592. deviceTypeDropDown
  58593. ->addItem (deviceManager_.getAvailableDeviceTypes().getUnchecked(i)->getTypeName(),
  58594. i + 1);
  58595. }
  58596. addAndMakeVisible (deviceTypeDropDown);
  58597. deviceTypeDropDown->addListener (this);
  58598. deviceTypeDropDownLabel = new Label (String::empty, TRANS ("audio device type:"));
  58599. deviceTypeDropDownLabel->setJustificationType (Justification::centredRight);
  58600. deviceTypeDropDownLabel->attachToComponent (deviceTypeDropDown, true);
  58601. }
  58602. if (showMidiInputOptions)
  58603. {
  58604. addAndMakeVisible (midiInputsList
  58605. = new MidiInputSelectorComponentListBox (deviceManager,
  58606. TRANS("(no midi inputs available)"),
  58607. 0, 0));
  58608. midiInputsLabel = new Label (String::empty, TRANS ("active midi inputs:"));
  58609. midiInputsLabel->setJustificationType (Justification::topRight);
  58610. midiInputsLabel->attachToComponent (midiInputsList, true);
  58611. }
  58612. else
  58613. {
  58614. midiInputsList = 0;
  58615. midiInputsLabel = 0;
  58616. }
  58617. if (showMidiOutputSelector)
  58618. {
  58619. addAndMakeVisible (midiOutputSelector = new ComboBox (String::empty));
  58620. midiOutputSelector->addListener (this);
  58621. midiOutputLabel = new Label ("lm", TRANS("Midi Output:"));
  58622. midiOutputLabel->attachToComponent (midiOutputSelector, true);
  58623. }
  58624. else
  58625. {
  58626. midiOutputSelector = 0;
  58627. midiOutputLabel = 0;
  58628. }
  58629. deviceManager_.addChangeListener (this);
  58630. changeListenerCallback (0);
  58631. }
  58632. AudioDeviceSelectorComponent::~AudioDeviceSelectorComponent()
  58633. {
  58634. deviceManager.removeChangeListener (this);
  58635. deleteAllChildren();
  58636. }
  58637. void AudioDeviceSelectorComponent::resized()
  58638. {
  58639. const int lx = proportionOfWidth (0.35f);
  58640. const int w = proportionOfWidth (0.4f);
  58641. const int h = 24;
  58642. const int space = 6;
  58643. const int dh = h + space;
  58644. int y = 15;
  58645. if (deviceTypeDropDown != 0)
  58646. {
  58647. deviceTypeDropDown->setBounds (lx, y, proportionOfWidth (0.3f), h);
  58648. y += dh + space * 2;
  58649. }
  58650. if (audioDeviceSettingsComp != 0)
  58651. {
  58652. audioDeviceSettingsComp->setBounds (0, y, getWidth(), audioDeviceSettingsComp->getHeight());
  58653. y += audioDeviceSettingsComp->getHeight() + space;
  58654. }
  58655. if (midiInputsList != 0)
  58656. {
  58657. const int bh = midiInputsList->getBestHeight (jmin (h * 8, getHeight() - y - space - h));
  58658. midiInputsList->setBounds (lx, y, w, bh);
  58659. y += bh + space;
  58660. }
  58661. if (midiOutputSelector != 0)
  58662. midiOutputSelector->setBounds (lx, y, w, h);
  58663. }
  58664. void AudioDeviceSelectorComponent::childBoundsChanged (Component* child)
  58665. {
  58666. if (child == audioDeviceSettingsComp)
  58667. resized();
  58668. }
  58669. void AudioDeviceSelectorComponent::buttonClicked (Button*)
  58670. {
  58671. AudioIODevice* const device = deviceManager.getCurrentAudioDevice();
  58672. if (device != 0 && device->hasControlPanel())
  58673. {
  58674. if (device->showControlPanel())
  58675. deviceManager.restartLastAudioDevice();
  58676. getTopLevelComponent()->toFront (true);
  58677. }
  58678. }
  58679. void AudioDeviceSelectorComponent::comboBoxChanged (ComboBox* comboBoxThatHasChanged)
  58680. {
  58681. if (comboBoxThatHasChanged == deviceTypeDropDown)
  58682. {
  58683. AudioIODeviceType* const type = deviceManager.getAvailableDeviceTypes() [deviceTypeDropDown->getSelectedId() - 1];
  58684. if (type != 0)
  58685. {
  58686. deleteAndZero (audioDeviceSettingsComp);
  58687. deviceManager.setCurrentAudioDeviceType (type->getTypeName(), true);
  58688. changeListenerCallback (0); // needed in case the type hasn't actally changed
  58689. }
  58690. }
  58691. else if (comboBoxThatHasChanged == midiOutputSelector)
  58692. {
  58693. deviceManager.setDefaultMidiOutput (midiOutputSelector->getText());
  58694. }
  58695. }
  58696. void AudioDeviceSelectorComponent::changeListenerCallback (void*)
  58697. {
  58698. if (deviceTypeDropDown != 0)
  58699. {
  58700. deviceTypeDropDown->setText (deviceManager.getCurrentAudioDeviceType(), false);
  58701. }
  58702. if (audioDeviceSettingsComp == 0
  58703. || audioDeviceSettingsCompType != deviceManager.getCurrentAudioDeviceType())
  58704. {
  58705. audioDeviceSettingsCompType = deviceManager.getCurrentAudioDeviceType();
  58706. deleteAndZero (audioDeviceSettingsComp);
  58707. AudioIODeviceType* const type
  58708. = deviceManager.getAvailableDeviceTypes() [deviceTypeDropDown == 0
  58709. ? 0 : deviceTypeDropDown->getSelectedId() - 1];
  58710. if (type != 0)
  58711. {
  58712. AudioIODeviceType::DeviceSetupDetails details;
  58713. details.manager = &deviceManager;
  58714. details.minNumInputChannels = minInputChannels;
  58715. details.maxNumInputChannels = maxInputChannels;
  58716. details.minNumOutputChannels = minOutputChannels;
  58717. details.maxNumOutputChannels = maxOutputChannels;
  58718. details.useStereoPairs = showChannelsAsStereoPairs;
  58719. audioDeviceSettingsComp = new AudioDeviceSettingsPanel (type, details, hideAdvancedOptionsWithButton);
  58720. if (audioDeviceSettingsComp != 0)
  58721. {
  58722. addAndMakeVisible (audioDeviceSettingsComp);
  58723. audioDeviceSettingsComp->resized();
  58724. }
  58725. }
  58726. }
  58727. if (midiInputsList != 0)
  58728. {
  58729. midiInputsList->updateContent();
  58730. midiInputsList->repaint();
  58731. }
  58732. if (midiOutputSelector != 0)
  58733. {
  58734. midiOutputSelector->clear();
  58735. const StringArray midiOuts (MidiOutput::getDevices());
  58736. midiOutputSelector->addItem (TRANS("<< none >>"), -1);
  58737. midiOutputSelector->addSeparator();
  58738. for (int i = 0; i < midiOuts.size(); ++i)
  58739. midiOutputSelector->addItem (midiOuts[i], i + 1);
  58740. int current = -1;
  58741. if (deviceManager.getDefaultMidiOutput() != 0)
  58742. current = 1 + midiOuts.indexOf (deviceManager.getDefaultMidiOutputName());
  58743. midiOutputSelector->setSelectedId (current, true);
  58744. }
  58745. resized();
  58746. }
  58747. END_JUCE_NAMESPACE
  58748. /*** End of inlined file: juce_AudioDeviceSelectorComponent.cpp ***/
  58749. /*** Start of inlined file: juce_BubbleComponent.cpp ***/
  58750. BEGIN_JUCE_NAMESPACE
  58751. BubbleComponent::BubbleComponent()
  58752. : side (0),
  58753. allowablePlacements (above | below | left | right),
  58754. arrowTipX (0.0f),
  58755. arrowTipY (0.0f)
  58756. {
  58757. setInterceptsMouseClicks (false, false);
  58758. shadow.setShadowProperties (5.0f, 0.35f, 0, 0);
  58759. setComponentEffect (&shadow);
  58760. }
  58761. BubbleComponent::~BubbleComponent()
  58762. {
  58763. }
  58764. void BubbleComponent::paint (Graphics& g)
  58765. {
  58766. int x = content.getX();
  58767. int y = content.getY();
  58768. int w = content.getWidth();
  58769. int h = content.getHeight();
  58770. int cw, ch;
  58771. getContentSize (cw, ch);
  58772. if (side == 3)
  58773. x += w - cw;
  58774. else if (side != 1)
  58775. x += (w - cw) / 2;
  58776. w = cw;
  58777. if (side == 2)
  58778. y += h - ch;
  58779. else if (side != 0)
  58780. y += (h - ch) / 2;
  58781. h = ch;
  58782. getLookAndFeel().drawBubble (g, arrowTipX, arrowTipY,
  58783. (float) x, (float) y,
  58784. (float) w, (float) h);
  58785. const int cx = x + (w - cw) / 2;
  58786. const int cy = y + (h - ch) / 2;
  58787. const int indent = 3;
  58788. g.setOrigin (cx + indent, cy + indent);
  58789. g.reduceClipRegion (0, 0, cw - indent * 2, ch - indent * 2);
  58790. paintContent (g, cw - indent * 2, ch - indent * 2);
  58791. }
  58792. void BubbleComponent::setAllowedPlacement (const int newPlacement)
  58793. {
  58794. allowablePlacements = newPlacement;
  58795. }
  58796. void BubbleComponent::setPosition (Component* componentToPointTo)
  58797. {
  58798. jassert (componentToPointTo->isValidComponent());
  58799. int tx = 0;
  58800. int ty = 0;
  58801. if (getParentComponent() != 0)
  58802. componentToPointTo->relativePositionToOtherComponent (getParentComponent(), tx, ty);
  58803. else
  58804. componentToPointTo->relativePositionToGlobal (tx, ty);
  58805. setPosition (Rectangle<int> (tx, ty, componentToPointTo->getWidth(), componentToPointTo->getHeight()));
  58806. }
  58807. void BubbleComponent::setPosition (const int arrowTipX_,
  58808. const int arrowTipY_)
  58809. {
  58810. setPosition (Rectangle<int> (arrowTipX_, arrowTipY_, 1, 1));
  58811. }
  58812. void BubbleComponent::setPosition (const Rectangle<int>& rectangleToPointTo)
  58813. {
  58814. Rectangle<int> availableSpace;
  58815. if (getParentComponent() != 0)
  58816. {
  58817. availableSpace.setSize (getParentComponent()->getWidth(),
  58818. getParentComponent()->getHeight());
  58819. }
  58820. else
  58821. {
  58822. availableSpace = getParentMonitorArea();
  58823. }
  58824. int x = 0;
  58825. int y = 0;
  58826. int w = 150;
  58827. int h = 30;
  58828. getContentSize (w, h);
  58829. w += 30;
  58830. h += 30;
  58831. const float edgeIndent = 2.0f;
  58832. const int arrowLength = jmin (10, h / 3, w / 3);
  58833. int spaceAbove = ((allowablePlacements & above) != 0) ? jmax (0, rectangleToPointTo.getY() - availableSpace.getY()) : -1;
  58834. int spaceBelow = ((allowablePlacements & below) != 0) ? jmax (0, availableSpace.getBottom() - rectangleToPointTo.getBottom()) : -1;
  58835. int spaceLeft = ((allowablePlacements & left) != 0) ? jmax (0, rectangleToPointTo.getX() - availableSpace.getX()) : -1;
  58836. int spaceRight = ((allowablePlacements & right) != 0) ? jmax (0, availableSpace.getRight() - rectangleToPointTo.getRight()) : -1;
  58837. // look at whether the component is elongated, and if so, try to position next to its longer dimension.
  58838. if (rectangleToPointTo.getWidth() > rectangleToPointTo.getHeight() * 2
  58839. && (spaceAbove > h + 20 || spaceBelow > h + 20))
  58840. {
  58841. spaceLeft = spaceRight = 0;
  58842. }
  58843. else if (rectangleToPointTo.getWidth() < rectangleToPointTo.getHeight() / 2
  58844. && (spaceLeft > w + 20 || spaceRight > w + 20))
  58845. {
  58846. spaceAbove = spaceBelow = 0;
  58847. }
  58848. if (jmax (spaceAbove, spaceBelow) >= jmax (spaceLeft, spaceRight))
  58849. {
  58850. x = rectangleToPointTo.getX() + (rectangleToPointTo.getWidth() - w) / 2;
  58851. arrowTipX = w * 0.5f;
  58852. content.setSize (w, h - arrowLength);
  58853. if (spaceAbove >= spaceBelow)
  58854. {
  58855. // above
  58856. y = rectangleToPointTo.getY() - h;
  58857. content.setPosition (0, 0);
  58858. arrowTipY = h - edgeIndent;
  58859. side = 2;
  58860. }
  58861. else
  58862. {
  58863. // below
  58864. y = rectangleToPointTo.getBottom();
  58865. content.setPosition (0, arrowLength);
  58866. arrowTipY = edgeIndent;
  58867. side = 0;
  58868. }
  58869. }
  58870. else
  58871. {
  58872. y = rectangleToPointTo.getY() + (rectangleToPointTo.getHeight() - h) / 2;
  58873. arrowTipY = h * 0.5f;
  58874. content.setSize (w - arrowLength, h);
  58875. if (spaceLeft > spaceRight)
  58876. {
  58877. // on the left
  58878. x = rectangleToPointTo.getX() - w;
  58879. content.setPosition (0, 0);
  58880. arrowTipX = w - edgeIndent;
  58881. side = 3;
  58882. }
  58883. else
  58884. {
  58885. // on the right
  58886. x = rectangleToPointTo.getRight();
  58887. content.setPosition (arrowLength, 0);
  58888. arrowTipX = edgeIndent;
  58889. side = 1;
  58890. }
  58891. }
  58892. setBounds (x, y, w, h);
  58893. }
  58894. END_JUCE_NAMESPACE
  58895. /*** End of inlined file: juce_BubbleComponent.cpp ***/
  58896. /*** Start of inlined file: juce_BubbleMessageComponent.cpp ***/
  58897. BEGIN_JUCE_NAMESPACE
  58898. BubbleMessageComponent::BubbleMessageComponent (int fadeOutLengthMs)
  58899. : fadeOutLength (fadeOutLengthMs),
  58900. deleteAfterUse (false)
  58901. {
  58902. }
  58903. BubbleMessageComponent::~BubbleMessageComponent()
  58904. {
  58905. fadeOutComponent (fadeOutLength);
  58906. }
  58907. void BubbleMessageComponent::showAt (int x, int y,
  58908. const String& text,
  58909. const int numMillisecondsBeforeRemoving,
  58910. const bool removeWhenMouseClicked,
  58911. const bool deleteSelfAfterUse)
  58912. {
  58913. textLayout.clear();
  58914. textLayout.setText (text, Font (14.0f));
  58915. textLayout.layout (256, Justification::centredLeft, true);
  58916. setPosition (x, y);
  58917. init (numMillisecondsBeforeRemoving, removeWhenMouseClicked, deleteSelfAfterUse);
  58918. }
  58919. void BubbleMessageComponent::showAt (Component* const component,
  58920. const String& text,
  58921. const int numMillisecondsBeforeRemoving,
  58922. const bool removeWhenMouseClicked,
  58923. const bool deleteSelfAfterUse)
  58924. {
  58925. textLayout.clear();
  58926. textLayout.setText (text, Font (14.0f));
  58927. textLayout.layout (256, Justification::centredLeft, true);
  58928. setPosition (component);
  58929. init (numMillisecondsBeforeRemoving, removeWhenMouseClicked, deleteSelfAfterUse);
  58930. }
  58931. void BubbleMessageComponent::init (const int numMillisecondsBeforeRemoving,
  58932. const bool removeWhenMouseClicked,
  58933. const bool deleteSelfAfterUse)
  58934. {
  58935. setVisible (true);
  58936. deleteAfterUse = deleteSelfAfterUse;
  58937. if (numMillisecondsBeforeRemoving > 0)
  58938. expiryTime = Time::getMillisecondCounter() + numMillisecondsBeforeRemoving;
  58939. else
  58940. expiryTime = 0;
  58941. startTimer (77);
  58942. mouseClickCounter = Desktop::getInstance().getMouseButtonClickCounter();
  58943. if (! (removeWhenMouseClicked && isShowing()))
  58944. mouseClickCounter += 0xfffff;
  58945. repaint();
  58946. }
  58947. void BubbleMessageComponent::getContentSize (int& w, int& h)
  58948. {
  58949. w = textLayout.getWidth() + 16;
  58950. h = textLayout.getHeight() + 16;
  58951. }
  58952. void BubbleMessageComponent::paintContent (Graphics& g, int w, int h)
  58953. {
  58954. g.setColour (findColour (TooltipWindow::textColourId));
  58955. textLayout.drawWithin (g, 0, 0, w, h, Justification::centred);
  58956. }
  58957. void BubbleMessageComponent::timerCallback()
  58958. {
  58959. if (Desktop::getInstance().getMouseButtonClickCounter() > mouseClickCounter)
  58960. {
  58961. stopTimer();
  58962. setVisible (false);
  58963. if (deleteAfterUse)
  58964. delete this;
  58965. }
  58966. else if (expiryTime != 0 && Time::getMillisecondCounter() > expiryTime)
  58967. {
  58968. stopTimer();
  58969. fadeOutComponent (fadeOutLength);
  58970. if (deleteAfterUse)
  58971. delete this;
  58972. }
  58973. }
  58974. END_JUCE_NAMESPACE
  58975. /*** End of inlined file: juce_BubbleMessageComponent.cpp ***/
  58976. /*** Start of inlined file: juce_ColourSelector.cpp ***/
  58977. BEGIN_JUCE_NAMESPACE
  58978. static const int swatchesPerRow = 8;
  58979. static const int swatchHeight = 22;
  58980. class ColourComponentSlider : public Slider
  58981. {
  58982. public:
  58983. ColourComponentSlider (const String& name)
  58984. : Slider (name)
  58985. {
  58986. setRange (0.0, 255.0, 1.0);
  58987. }
  58988. ~ColourComponentSlider()
  58989. {
  58990. }
  58991. const String getTextFromValue (double value)
  58992. {
  58993. return String::formatted (T("%02X"), (int) value);
  58994. }
  58995. double getValueFromText (const String& text)
  58996. {
  58997. return (double) text.getHexValue32();
  58998. }
  58999. private:
  59000. ColourComponentSlider (const ColourComponentSlider&);
  59001. const ColourComponentSlider& operator= (const ColourComponentSlider&);
  59002. };
  59003. class ColourSpaceMarker : public Component
  59004. {
  59005. public:
  59006. ColourSpaceMarker()
  59007. {
  59008. setInterceptsMouseClicks (false, false);
  59009. }
  59010. ~ColourSpaceMarker()
  59011. {
  59012. }
  59013. void paint (Graphics& g)
  59014. {
  59015. g.setColour (Colour::greyLevel (0.1f));
  59016. g.drawEllipse (1.0f, 1.0f, getWidth() - 2.0f, getHeight() - 2.0f, 1.0f);
  59017. g.setColour (Colour::greyLevel (0.9f));
  59018. g.drawEllipse (2.0f, 2.0f, getWidth() - 4.0f, getHeight() - 4.0f, 1.0f);
  59019. }
  59020. private:
  59021. ColourSpaceMarker (const ColourSpaceMarker&);
  59022. const ColourSpaceMarker& operator= (const ColourSpaceMarker&);
  59023. };
  59024. class ColourSpaceView : public Component
  59025. {
  59026. ColourSelector* const owner;
  59027. float& h;
  59028. float& s;
  59029. float& v;
  59030. float lastHue;
  59031. ColourSpaceMarker* marker;
  59032. const int edge;
  59033. public:
  59034. ColourSpaceView (ColourSelector* owner_,
  59035. float& h_, float& s_, float& v_,
  59036. const int edgeSize)
  59037. : owner (owner_),
  59038. h (h_), s (s_), v (v_),
  59039. lastHue (0.0f),
  59040. edge (edgeSize)
  59041. {
  59042. addAndMakeVisible (marker = new ColourSpaceMarker());
  59043. setMouseCursor (MouseCursor::CrosshairCursor);
  59044. }
  59045. ~ColourSpaceView()
  59046. {
  59047. deleteAllChildren();
  59048. }
  59049. void paint (Graphics& g)
  59050. {
  59051. if (colours == 0)
  59052. {
  59053. const int width = getWidth() / 2;
  59054. const int height = getHeight() / 2;
  59055. colours = new Image (Image::RGB, width, height, false);
  59056. Image::BitmapData pixels (*colours, 0, 0, width, height, true);
  59057. for (int y = 0; y < height; ++y)
  59058. {
  59059. const float v = 1.0f - y / (float) height;
  59060. for (int x = 0; x < width; ++x)
  59061. {
  59062. const float s = x / (float) width;
  59063. const Colour col (h, s, v, 1.0f);
  59064. PixelRGB* const pix = (PixelRGB*) pixels.getPixelPointer (x, y);
  59065. pix->set (col.getPixelARGB());
  59066. }
  59067. }
  59068. }
  59069. g.setOpacity (1.0f);
  59070. g.drawImage (colours, edge, edge, getWidth() - edge * 2, getHeight() - edge * 2,
  59071. 0, 0, colours->getWidth(), colours->getHeight());
  59072. }
  59073. void mouseDown (const MouseEvent& e)
  59074. {
  59075. mouseDrag (e);
  59076. }
  59077. void mouseDrag (const MouseEvent& e)
  59078. {
  59079. const float s = (e.x - edge) / (float) (getWidth() - edge * 2);
  59080. const float v = 1.0f - (e.y - edge) / (float) (getHeight() - edge * 2);
  59081. owner->setSV (s, v);
  59082. }
  59083. void updateIfNeeded()
  59084. {
  59085. if (lastHue != h)
  59086. {
  59087. lastHue = h;
  59088. colours = 0;
  59089. repaint();
  59090. }
  59091. updateMarker();
  59092. }
  59093. void resized()
  59094. {
  59095. colours = 0;
  59096. updateMarker();
  59097. }
  59098. private:
  59099. ScopedPointer <Image> colours;
  59100. void updateMarker() const throw()
  59101. {
  59102. marker->setBounds (roundToInt ((getWidth() - edge * 2) * s),
  59103. roundToInt ((getHeight() - edge * 2) * (1.0f - v)),
  59104. edge * 2, edge * 2);
  59105. }
  59106. ColourSpaceView (const ColourSpaceView&);
  59107. const ColourSpaceView& operator= (const ColourSpaceView&);
  59108. };
  59109. class HueSelectorMarker : public Component
  59110. {
  59111. public:
  59112. HueSelectorMarker()
  59113. {
  59114. setInterceptsMouseClicks (false, false);
  59115. }
  59116. ~HueSelectorMarker()
  59117. {
  59118. }
  59119. void paint (Graphics& g)
  59120. {
  59121. Path p;
  59122. p.addTriangle (1.0f, 1.0f,
  59123. getWidth() * 0.3f, getHeight() * 0.5f,
  59124. 1.0f, getHeight() - 1.0f);
  59125. p.addTriangle (getWidth() - 1.0f, 1.0f,
  59126. getWidth() * 0.7f, getHeight() * 0.5f,
  59127. getWidth() - 1.0f, getHeight() - 1.0f);
  59128. g.setColour (Colours::white.withAlpha (0.75f));
  59129. g.fillPath (p);
  59130. g.setColour (Colours::black.withAlpha (0.75f));
  59131. g.strokePath (p, PathStrokeType (1.2f));
  59132. }
  59133. private:
  59134. HueSelectorMarker (const HueSelectorMarker&);
  59135. const HueSelectorMarker& operator= (const HueSelectorMarker&);
  59136. };
  59137. class HueSelectorComp : public Component
  59138. {
  59139. public:
  59140. HueSelectorComp (ColourSelector* owner_,
  59141. float& h_, float& s_, float& v_,
  59142. const int edgeSize)
  59143. : owner (owner_),
  59144. h (h_), s (s_), v (v_),
  59145. lastHue (0.0f),
  59146. edge (edgeSize)
  59147. {
  59148. addAndMakeVisible (marker = new HueSelectorMarker());
  59149. }
  59150. ~HueSelectorComp()
  59151. {
  59152. deleteAllChildren();
  59153. }
  59154. void paint (Graphics& g)
  59155. {
  59156. const float yScale = 1.0f / (getHeight() - edge * 2);
  59157. const Rectangle<int> clip (g.getClipBounds());
  59158. for (int y = jmin (clip.getBottom(), getHeight() - edge); --y >= jmax (edge, clip.getY());)
  59159. {
  59160. g.setColour (Colour ((y - edge) * yScale, 1.0f, 1.0f, 1.0f));
  59161. g.fillRect (edge, y, getWidth() - edge * 2, 1);
  59162. }
  59163. }
  59164. void resized()
  59165. {
  59166. marker->setBounds (0, roundToInt ((getHeight() - edge * 2) * h),
  59167. getWidth(), edge * 2);
  59168. }
  59169. void mouseDown (const MouseEvent& e)
  59170. {
  59171. mouseDrag (e);
  59172. }
  59173. void mouseDrag (const MouseEvent& e)
  59174. {
  59175. const float hue = (e.y - edge) / (float) (getHeight() - edge * 2);
  59176. owner->setHue (hue);
  59177. }
  59178. void updateIfNeeded()
  59179. {
  59180. resized();
  59181. }
  59182. private:
  59183. ColourSelector* const owner;
  59184. float& h;
  59185. float& s;
  59186. float& v;
  59187. float lastHue;
  59188. HueSelectorMarker* marker;
  59189. const int edge;
  59190. HueSelectorComp (const HueSelectorComp&);
  59191. const HueSelectorComp& operator= (const HueSelectorComp&);
  59192. };
  59193. class ColourSelector::SwatchComponent : public Component
  59194. {
  59195. public:
  59196. SwatchComponent (ColourSelector* owner_, int index_)
  59197. : owner (owner_),
  59198. index (index_)
  59199. {
  59200. }
  59201. ~SwatchComponent()
  59202. {
  59203. }
  59204. void paint (Graphics& g)
  59205. {
  59206. const Colour colour (owner->getSwatchColour (index));
  59207. g.fillCheckerBoard (0, 0, getWidth(), getHeight(),
  59208. 6, 6,
  59209. Colour (0xffdddddd).overlaidWith (colour),
  59210. Colour (0xffffffff).overlaidWith (colour));
  59211. }
  59212. void mouseDown (const MouseEvent&)
  59213. {
  59214. PopupMenu m;
  59215. m.addItem (1, TRANS("Use this swatch as the current colour"));
  59216. m.addSeparator();
  59217. m.addItem (2, TRANS("Set this swatch to the current colour"));
  59218. const int r = m.showAt (this);
  59219. if (r == 1)
  59220. {
  59221. owner->setCurrentColour (owner->getSwatchColour (index));
  59222. }
  59223. else if (r == 2)
  59224. {
  59225. if (owner->getSwatchColour (index) != owner->getCurrentColour())
  59226. {
  59227. owner->setSwatchColour (index, owner->getCurrentColour());
  59228. repaint();
  59229. }
  59230. }
  59231. }
  59232. private:
  59233. ColourSelector* const owner;
  59234. const int index;
  59235. SwatchComponent (const SwatchComponent&);
  59236. const SwatchComponent& operator= (const SwatchComponent&);
  59237. };
  59238. ColourSelector::ColourSelector (const int flags_,
  59239. const int edgeGap_,
  59240. const int gapAroundColourSpaceComponent)
  59241. : colour (Colours::white),
  59242. flags (flags_),
  59243. topSpace (0),
  59244. edgeGap (edgeGap_)
  59245. {
  59246. // not much point having a selector with no components in it!
  59247. jassert ((flags_ & (showColourAtTop | showSliders | showColourspace)) != 0);
  59248. updateHSV();
  59249. if ((flags & showSliders) != 0)
  59250. {
  59251. addAndMakeVisible (sliders[0] = new ColourComponentSlider (TRANS ("red")));
  59252. addAndMakeVisible (sliders[1] = new ColourComponentSlider (TRANS ("green")));
  59253. addAndMakeVisible (sliders[2] = new ColourComponentSlider (TRANS ("blue")));
  59254. addChildComponent (sliders[3] = new ColourComponentSlider (TRANS ("alpha")));
  59255. sliders[3]->setVisible ((flags & showAlphaChannel) != 0);
  59256. for (int i = 4; --i >= 0;)
  59257. sliders[i]->addListener (this);
  59258. }
  59259. else
  59260. {
  59261. zeromem (sliders, sizeof (sliders));
  59262. }
  59263. if ((flags & showColourspace) != 0)
  59264. {
  59265. addAndMakeVisible (colourSpace = new ColourSpaceView (this, h, s, v, gapAroundColourSpaceComponent));
  59266. addAndMakeVisible (hueSelector = new HueSelectorComp (this, h, s, v, gapAroundColourSpaceComponent));
  59267. }
  59268. else
  59269. {
  59270. colourSpace = 0;
  59271. hueSelector = 0;
  59272. }
  59273. update();
  59274. }
  59275. ColourSelector::~ColourSelector()
  59276. {
  59277. dispatchPendingMessages();
  59278. swatchComponents.clear();
  59279. deleteAllChildren();
  59280. }
  59281. const Colour ColourSelector::getCurrentColour() const
  59282. {
  59283. return ((flags & showAlphaChannel) != 0) ? colour
  59284. : colour.withAlpha ((uint8) 0xff);
  59285. }
  59286. void ColourSelector::setCurrentColour (const Colour& c)
  59287. {
  59288. if (c != colour)
  59289. {
  59290. colour = ((flags & showAlphaChannel) != 0) ? c : c.withAlpha ((uint8) 0xff);
  59291. updateHSV();
  59292. update();
  59293. }
  59294. }
  59295. void ColourSelector::setHue (float newH)
  59296. {
  59297. newH = jlimit (0.0f, 1.0f, newH);
  59298. if (h != newH)
  59299. {
  59300. h = newH;
  59301. colour = Colour (h, s, v, colour.getFloatAlpha());
  59302. update();
  59303. }
  59304. }
  59305. void ColourSelector::setSV (float newS, float newV)
  59306. {
  59307. newS = jlimit (0.0f, 1.0f, newS);
  59308. newV = jlimit (0.0f, 1.0f, newV);
  59309. if (s != newS || v != newV)
  59310. {
  59311. s = newS;
  59312. v = newV;
  59313. colour = Colour (h, s, v, colour.getFloatAlpha());
  59314. update();
  59315. }
  59316. }
  59317. void ColourSelector::updateHSV()
  59318. {
  59319. colour.getHSB (h, s, v);
  59320. }
  59321. void ColourSelector::update()
  59322. {
  59323. if (sliders[0] != 0)
  59324. {
  59325. sliders[0]->setValue ((int) colour.getRed());
  59326. sliders[1]->setValue ((int) colour.getGreen());
  59327. sliders[2]->setValue ((int) colour.getBlue());
  59328. sliders[3]->setValue ((int) colour.getAlpha());
  59329. }
  59330. if (colourSpace != 0)
  59331. {
  59332. ((ColourSpaceView*) colourSpace)->updateIfNeeded();
  59333. ((HueSelectorComp*) hueSelector)->updateIfNeeded();
  59334. }
  59335. if ((flags & showColourAtTop) != 0)
  59336. repaint (0, edgeGap, getWidth(), topSpace - edgeGap);
  59337. sendChangeMessage (this);
  59338. }
  59339. void ColourSelector::paint (Graphics& g)
  59340. {
  59341. g.fillAll (findColour (backgroundColourId));
  59342. if ((flags & showColourAtTop) != 0)
  59343. {
  59344. const Colour colour (getCurrentColour());
  59345. g.fillCheckerBoard (edgeGap, edgeGap, getWidth() - edgeGap - edgeGap, topSpace - edgeGap - edgeGap,
  59346. 10, 10,
  59347. Colour (0xffdddddd).overlaidWith (colour),
  59348. Colour (0xffffffff).overlaidWith (colour));
  59349. g.setColour (Colours::white.overlaidWith (colour).contrasting());
  59350. g.setFont (14.0f, true);
  59351. g.drawText (((flags & showAlphaChannel) != 0)
  59352. ? String::formatted (T("#%02X%02X%02X%02X"),
  59353. (int) colour.getAlpha(),
  59354. (int) colour.getRed(),
  59355. (int) colour.getGreen(),
  59356. (int) colour.getBlue())
  59357. : String::formatted (T("#%02X%02X%02X"),
  59358. (int) colour.getRed(),
  59359. (int) colour.getGreen(),
  59360. (int) colour.getBlue()),
  59361. 0, edgeGap, getWidth(), topSpace - edgeGap * 2,
  59362. Justification::centred, false);
  59363. }
  59364. if ((flags & showSliders) != 0)
  59365. {
  59366. g.setColour (findColour (labelTextColourId));
  59367. g.setFont (11.0f);
  59368. for (int i = 4; --i >= 0;)
  59369. {
  59370. if (sliders[i]->isVisible())
  59371. g.drawText (sliders[i]->getName() + T(":"),
  59372. 0, sliders[i]->getY(),
  59373. sliders[i]->getX() - 8, sliders[i]->getHeight(),
  59374. Justification::centredRight, false);
  59375. }
  59376. }
  59377. }
  59378. void ColourSelector::resized()
  59379. {
  59380. const int numSliders = ((flags & showAlphaChannel) != 0) ? 4 : 3;
  59381. const int numSwatches = getNumSwatches();
  59382. const int swatchSpace = numSwatches > 0 ? edgeGap + swatchHeight * ((numSwatches + 7) / swatchesPerRow) : 0;
  59383. const int sliderSpace = ((flags & showSliders) != 0) ? jmin (22 * numSliders + edgeGap, proportionOfHeight (0.3f)) : 0;
  59384. topSpace = ((flags & showColourAtTop) != 0) ? jmin (30 + edgeGap * 2, proportionOfHeight (0.2f)) : edgeGap;
  59385. int y = topSpace;
  59386. if ((flags & showColourspace) != 0)
  59387. {
  59388. const int hueWidth = jmin (50, proportionOfWidth (0.15f));
  59389. colourSpace->setBounds (edgeGap, y,
  59390. getWidth() - hueWidth - edgeGap - 4,
  59391. getHeight() - topSpace - sliderSpace - swatchSpace - edgeGap);
  59392. hueSelector->setBounds (colourSpace->getRight() + 4, y,
  59393. getWidth() - edgeGap - (colourSpace->getRight() + 4),
  59394. colourSpace->getHeight());
  59395. y = getHeight() - sliderSpace - swatchSpace - edgeGap;
  59396. }
  59397. if ((flags & showSliders) != 0)
  59398. {
  59399. const int sliderHeight = jmax (4, sliderSpace / numSliders);
  59400. for (int i = 0; i < numSliders; ++i)
  59401. {
  59402. sliders[i]->setBounds (proportionOfWidth (0.2f), y,
  59403. proportionOfWidth (0.72f), sliderHeight - 2);
  59404. y += sliderHeight;
  59405. }
  59406. }
  59407. if (numSwatches > 0)
  59408. {
  59409. const int startX = 8;
  59410. const int xGap = 4;
  59411. const int yGap = 4;
  59412. const int swatchWidth = (getWidth() - startX * 2) / swatchesPerRow;
  59413. y += edgeGap;
  59414. if (swatchComponents.size() != numSwatches)
  59415. {
  59416. swatchComponents.clear();
  59417. for (int i = 0; i < numSwatches; ++i)
  59418. {
  59419. SwatchComponent* const sc = new SwatchComponent (this, i);
  59420. swatchComponents.add (sc);
  59421. addAndMakeVisible (sc);
  59422. }
  59423. }
  59424. int x = startX;
  59425. for (int i = 0; i < swatchComponents.size(); ++i)
  59426. {
  59427. SwatchComponent* const sc = swatchComponents.getUnchecked(i);
  59428. sc->setBounds (x + xGap / 2,
  59429. y + yGap / 2,
  59430. swatchWidth - xGap,
  59431. swatchHeight - yGap);
  59432. if (((i + 1) % swatchesPerRow) == 0)
  59433. {
  59434. x = startX;
  59435. y += swatchHeight;
  59436. }
  59437. else
  59438. {
  59439. x += swatchWidth;
  59440. }
  59441. }
  59442. }
  59443. }
  59444. void ColourSelector::sliderValueChanged (Slider*)
  59445. {
  59446. if (sliders[0] != 0)
  59447. setCurrentColour (Colour ((uint8) sliders[0]->getValue(),
  59448. (uint8) sliders[1]->getValue(),
  59449. (uint8) sliders[2]->getValue(),
  59450. (uint8) sliders[3]->getValue()));
  59451. }
  59452. int ColourSelector::getNumSwatches() const
  59453. {
  59454. return 0;
  59455. }
  59456. const Colour ColourSelector::getSwatchColour (const int) const
  59457. {
  59458. jassertfalse // if you've overridden getNumSwatches(), you also need to implement this method
  59459. return Colours::black;
  59460. }
  59461. void ColourSelector::setSwatchColour (const int, const Colour&) const
  59462. {
  59463. jassertfalse // if you've overridden getNumSwatches(), you also need to implement this method
  59464. }
  59465. END_JUCE_NAMESPACE
  59466. /*** End of inlined file: juce_ColourSelector.cpp ***/
  59467. /*** Start of inlined file: juce_DropShadower.cpp ***/
  59468. BEGIN_JUCE_NAMESPACE
  59469. class ShadowWindow : public Component
  59470. {
  59471. Component* owner;
  59472. Image** shadowImageSections;
  59473. const int type; // 0 = left, 1 = right, 2 = top, 3 = bottom. left + right are full-height
  59474. public:
  59475. ShadowWindow (Component* const owner_,
  59476. const int type_,
  59477. Image** const shadowImageSections_)
  59478. : owner (owner_),
  59479. shadowImageSections (shadowImageSections_),
  59480. type (type_)
  59481. {
  59482. setInterceptsMouseClicks (false, false);
  59483. if (owner_->isOnDesktop())
  59484. {
  59485. setSize (1, 1); // to keep the OS happy by not having zero-size windows
  59486. addToDesktop (ComponentPeer::windowIgnoresMouseClicks
  59487. | ComponentPeer::windowIsTemporary
  59488. | ComponentPeer::windowIgnoresKeyPresses);
  59489. }
  59490. else if (owner_->getParentComponent() != 0)
  59491. {
  59492. owner_->getParentComponent()->addChildComponent (this);
  59493. }
  59494. }
  59495. ~ShadowWindow()
  59496. {
  59497. }
  59498. void paint (Graphics& g)
  59499. {
  59500. Image* const topLeft = shadowImageSections [type * 3];
  59501. Image* const bottomRight = shadowImageSections [type * 3 + 1];
  59502. Image* const filler = shadowImageSections [type * 3 + 2];
  59503. g.setOpacity (1.0f);
  59504. if (type < 2)
  59505. {
  59506. int imH = jmin (topLeft->getHeight(), getHeight() / 2);
  59507. g.drawImage (topLeft,
  59508. 0, 0, topLeft->getWidth(), imH,
  59509. 0, 0, topLeft->getWidth(), imH);
  59510. imH = jmin (bottomRight->getHeight(), getHeight() - getHeight() / 2);
  59511. g.drawImage (bottomRight,
  59512. 0, getHeight() - imH, bottomRight->getWidth(), imH,
  59513. 0, bottomRight->getHeight() - imH, bottomRight->getWidth(), imH);
  59514. g.setTiledImageFill (*filler, 0, 0, 1.0f);
  59515. g.fillRect (0, topLeft->getHeight(), getWidth(), getHeight() - (topLeft->getHeight() + bottomRight->getHeight()));
  59516. }
  59517. else
  59518. {
  59519. int imW = jmin (topLeft->getWidth(), getWidth() / 2);
  59520. g.drawImage (topLeft,
  59521. 0, 0, imW, topLeft->getHeight(),
  59522. 0, 0, imW, topLeft->getHeight());
  59523. imW = jmin (bottomRight->getWidth(), getWidth() - getWidth() / 2);
  59524. g.drawImage (bottomRight,
  59525. getWidth() - imW, 0, imW, bottomRight->getHeight(),
  59526. bottomRight->getWidth() - imW, 0, imW, bottomRight->getHeight());
  59527. g.setTiledImageFill (*filler, 0, 0, 1.0f);
  59528. g.fillRect (topLeft->getWidth(), 0, getWidth() - (topLeft->getWidth() + bottomRight->getWidth()), getHeight());
  59529. }
  59530. }
  59531. void resized()
  59532. {
  59533. repaint(); // (needed for correct repainting)
  59534. }
  59535. private:
  59536. ShadowWindow (const ShadowWindow&);
  59537. const ShadowWindow& operator= (const ShadowWindow&);
  59538. };
  59539. DropShadower::DropShadower (const float alpha_,
  59540. const int xOffset_,
  59541. const int yOffset_,
  59542. const float blurRadius_)
  59543. : owner (0),
  59544. numShadows (0),
  59545. shadowEdge (jmax (xOffset_, yOffset_) + (int) blurRadius_),
  59546. xOffset (xOffset_),
  59547. yOffset (yOffset_),
  59548. alpha (alpha_),
  59549. blurRadius (blurRadius_),
  59550. inDestructor (false),
  59551. reentrant (false)
  59552. {
  59553. }
  59554. DropShadower::~DropShadower()
  59555. {
  59556. if (owner != 0)
  59557. owner->removeComponentListener (this);
  59558. inDestructor = true;
  59559. deleteShadowWindows();
  59560. }
  59561. void DropShadower::deleteShadowWindows()
  59562. {
  59563. if (numShadows > 0)
  59564. {
  59565. int i;
  59566. for (i = numShadows; --i >= 0;)
  59567. delete shadowWindows[i];
  59568. for (i = 12; --i >= 0;)
  59569. delete shadowImageSections[i];
  59570. numShadows = 0;
  59571. }
  59572. }
  59573. void DropShadower::setOwner (Component* componentToFollow)
  59574. {
  59575. if (componentToFollow != owner)
  59576. {
  59577. if (owner != 0)
  59578. owner->removeComponentListener (this);
  59579. // (the component can't be null)
  59580. jassert (componentToFollow != 0);
  59581. owner = componentToFollow;
  59582. jassert (owner != 0);
  59583. jassert (owner->isOpaque()); // doesn't work properly for semi-transparent comps!
  59584. owner->addComponentListener (this);
  59585. updateShadows();
  59586. }
  59587. }
  59588. void DropShadower::componentMovedOrResized (Component&, bool /*wasMoved*/, bool /*wasResized*/)
  59589. {
  59590. updateShadows();
  59591. }
  59592. void DropShadower::componentBroughtToFront (Component&)
  59593. {
  59594. bringShadowWindowsToFront();
  59595. }
  59596. void DropShadower::componentChildrenChanged (Component&)
  59597. {
  59598. }
  59599. void DropShadower::componentParentHierarchyChanged (Component&)
  59600. {
  59601. deleteShadowWindows();
  59602. updateShadows();
  59603. }
  59604. void DropShadower::componentVisibilityChanged (Component&)
  59605. {
  59606. updateShadows();
  59607. }
  59608. void DropShadower::updateShadows()
  59609. {
  59610. if (reentrant || inDestructor || (owner == 0))
  59611. return;
  59612. reentrant = true;
  59613. ComponentPeer* const nw = owner->getPeer();
  59614. const bool isOwnerVisible = owner->isVisible()
  59615. && (nw == 0 || ! nw->isMinimised());
  59616. const bool createShadowWindows = numShadows == 0
  59617. && owner->getWidth() > 0
  59618. && owner->getHeight() > 0
  59619. && isOwnerVisible
  59620. && (Desktop::canUseSemiTransparentWindows()
  59621. || owner->getParentComponent() != 0);
  59622. if (createShadowWindows)
  59623. {
  59624. // keep a cached version of the image to save doing the gaussian too often
  59625. String imageId;
  59626. imageId << shadowEdge << T(',')
  59627. << xOffset << T(',')
  59628. << yOffset << T(',')
  59629. << alpha;
  59630. const int hash = imageId.hashCode();
  59631. Image* bigIm = ImageCache::getFromHashCode (hash);
  59632. if (bigIm == 0)
  59633. {
  59634. bigIm = Image::createNativeImage (Image::ARGB, shadowEdge * 5, shadowEdge * 5, true);
  59635. Graphics bigG (*bigIm);
  59636. bigG.setColour (Colours::black.withAlpha (alpha));
  59637. bigG.fillRect (shadowEdge + xOffset,
  59638. shadowEdge + yOffset,
  59639. bigIm->getWidth() - (shadowEdge * 2),
  59640. bigIm->getHeight() - (shadowEdge * 2));
  59641. ImageConvolutionKernel blurKernel (roundToInt (blurRadius * 2.0f));
  59642. blurKernel.createGaussianBlur (blurRadius);
  59643. blurKernel.applyToImage (*bigIm, 0,
  59644. xOffset,
  59645. yOffset,
  59646. bigIm->getWidth(),
  59647. bigIm->getHeight());
  59648. ImageCache::addImageToCache (bigIm, hash);
  59649. }
  59650. const int iw = bigIm->getWidth();
  59651. const int ih = bigIm->getHeight();
  59652. const int shadowEdge2 = shadowEdge * 2;
  59653. setShadowImage (bigIm, 0, shadowEdge, shadowEdge2, 0, 0);
  59654. setShadowImage (bigIm, 1, shadowEdge, shadowEdge2, 0, ih - shadowEdge2);
  59655. setShadowImage (bigIm, 2, shadowEdge, shadowEdge, 0, shadowEdge2);
  59656. setShadowImage (bigIm, 3, shadowEdge, shadowEdge2, iw - shadowEdge, 0);
  59657. setShadowImage (bigIm, 4, shadowEdge, shadowEdge2, iw - shadowEdge, ih - shadowEdge2);
  59658. setShadowImage (bigIm, 5, shadowEdge, shadowEdge, iw - shadowEdge, shadowEdge2);
  59659. setShadowImage (bigIm, 6, shadowEdge, shadowEdge, shadowEdge, 0);
  59660. setShadowImage (bigIm, 7, shadowEdge, shadowEdge, iw - shadowEdge2, 0);
  59661. setShadowImage (bigIm, 8, shadowEdge, shadowEdge, shadowEdge2, 0);
  59662. setShadowImage (bigIm, 9, shadowEdge, shadowEdge, shadowEdge, ih - shadowEdge);
  59663. setShadowImage (bigIm, 10, shadowEdge, shadowEdge, iw - shadowEdge2, ih - shadowEdge);
  59664. setShadowImage (bigIm, 11, shadowEdge, shadowEdge, shadowEdge2, ih - shadowEdge);
  59665. ImageCache::release (bigIm);
  59666. for (int i = 0; i < 4; ++i)
  59667. {
  59668. shadowWindows[numShadows] = new ShadowWindow (owner, i, shadowImageSections);
  59669. ++numShadows;
  59670. }
  59671. }
  59672. if (numShadows > 0)
  59673. {
  59674. for (int i = numShadows; --i >= 0;)
  59675. {
  59676. shadowWindows[i]->setAlwaysOnTop (owner->isAlwaysOnTop());
  59677. shadowWindows[i]->setVisible (isOwnerVisible);
  59678. }
  59679. const int x = owner->getX();
  59680. const int y = owner->getY() - shadowEdge;
  59681. const int w = owner->getWidth();
  59682. const int h = owner->getHeight() + shadowEdge + shadowEdge;
  59683. shadowWindows[0]->setBounds (x - shadowEdge,
  59684. y,
  59685. shadowEdge,
  59686. h);
  59687. shadowWindows[1]->setBounds (x + w,
  59688. y,
  59689. shadowEdge,
  59690. h);
  59691. shadowWindows[2]->setBounds (x,
  59692. y,
  59693. w,
  59694. shadowEdge);
  59695. shadowWindows[3]->setBounds (x,
  59696. owner->getBottom(),
  59697. w,
  59698. shadowEdge);
  59699. }
  59700. reentrant = false;
  59701. if (createShadowWindows)
  59702. bringShadowWindowsToFront();
  59703. }
  59704. void DropShadower::setShadowImage (Image* const src,
  59705. const int num,
  59706. const int w,
  59707. const int h,
  59708. const int sx,
  59709. const int sy)
  59710. {
  59711. shadowImageSections[num] = new Image (Image::ARGB, w, h, true);
  59712. Graphics g (*shadowImageSections[num]);
  59713. g.drawImage (src, 0, 0, w, h, sx, sy, w, h);
  59714. }
  59715. void DropShadower::bringShadowWindowsToFront()
  59716. {
  59717. if (! (inDestructor || reentrant))
  59718. {
  59719. updateShadows();
  59720. reentrant = true;
  59721. for (int i = numShadows; --i >= 0;)
  59722. shadowWindows[i]->toBehind (owner);
  59723. reentrant = false;
  59724. }
  59725. }
  59726. END_JUCE_NAMESPACE
  59727. /*** End of inlined file: juce_DropShadower.cpp ***/
  59728. /*** Start of inlined file: juce_MagnifierComponent.cpp ***/
  59729. BEGIN_JUCE_NAMESPACE
  59730. class MagnifyingPeer : public ComponentPeer
  59731. {
  59732. public:
  59733. MagnifyingPeer (Component* const component_,
  59734. MagnifierComponent* const magnifierComp_)
  59735. : ComponentPeer (component_, 0),
  59736. magnifierComp (magnifierComp_)
  59737. {
  59738. }
  59739. ~MagnifyingPeer()
  59740. {
  59741. }
  59742. void* getNativeHandle() const { return 0; }
  59743. void setVisible (bool) {}
  59744. void setTitle (const String&) {}
  59745. void setPosition (int, int) {}
  59746. void setSize (int, int) {}
  59747. void setBounds (int, int, int, int, const bool) {}
  59748. void setMinimised (bool) {}
  59749. bool isMinimised() const { return false; }
  59750. void setFullScreen (bool) {}
  59751. bool isFullScreen() const { return false; }
  59752. const BorderSize getFrameSize() const { return BorderSize (0); }
  59753. bool setAlwaysOnTop (bool) { return true; }
  59754. void toFront (bool) {}
  59755. void toBehind (ComponentPeer*) {}
  59756. void setIcon (const Image&) {}
  59757. bool isFocused() const
  59758. {
  59759. return magnifierComp->hasKeyboardFocus (true);
  59760. }
  59761. void grabFocus()
  59762. {
  59763. ComponentPeer* peer = magnifierComp->getPeer();
  59764. if (peer != 0)
  59765. peer->grabFocus();
  59766. }
  59767. void textInputRequired (int x, int y)
  59768. {
  59769. ComponentPeer* peer = magnifierComp->getPeer();
  59770. if (peer != 0)
  59771. peer->textInputRequired (x, y);
  59772. }
  59773. void getBounds (int& x, int& y, int& w, int& h) const
  59774. {
  59775. x = magnifierComp->getScreenX();
  59776. y = magnifierComp->getScreenY();
  59777. w = component->getWidth();
  59778. h = component->getHeight();
  59779. }
  59780. int getScreenX() const { return magnifierComp->getScreenX(); }
  59781. int getScreenY() const { return magnifierComp->getScreenY(); }
  59782. void relativePositionToGlobal (int& x, int& y)
  59783. {
  59784. const double zoom = magnifierComp->getScaleFactor();
  59785. x = roundToInt (x * zoom);
  59786. y = roundToInt (y * zoom);
  59787. magnifierComp->relativePositionToGlobal (x, y);
  59788. }
  59789. void globalPositionToRelative (int& x, int& y)
  59790. {
  59791. magnifierComp->globalPositionToRelative (x, y);
  59792. const double zoom = magnifierComp->getScaleFactor();
  59793. x = roundToInt (x / zoom);
  59794. y = roundToInt (y / zoom);
  59795. }
  59796. bool contains (int x, int y, bool) const
  59797. {
  59798. return ((unsigned int) x) < (unsigned int) magnifierComp->getWidth()
  59799. && ((unsigned int) y) < (unsigned int) magnifierComp->getHeight();
  59800. }
  59801. void repaint (int x, int y, int w, int h)
  59802. {
  59803. const double zoom = magnifierComp->getScaleFactor();
  59804. magnifierComp->repaint ((int) (x * zoom),
  59805. (int) (y * zoom),
  59806. roundToInt (w * zoom) + 1,
  59807. roundToInt (h * zoom) + 1);
  59808. }
  59809. void performAnyPendingRepaintsNow()
  59810. {
  59811. }
  59812. juce_UseDebuggingNewOperator
  59813. private:
  59814. MagnifierComponent* const magnifierComp;
  59815. MagnifyingPeer (const MagnifyingPeer&);
  59816. const MagnifyingPeer& operator= (const MagnifyingPeer&);
  59817. };
  59818. class PeerHolderComp : public Component
  59819. {
  59820. public:
  59821. PeerHolderComp (MagnifierComponent* const magnifierComp_)
  59822. : magnifierComp (magnifierComp_)
  59823. {
  59824. setVisible (true);
  59825. }
  59826. ~PeerHolderComp()
  59827. {
  59828. }
  59829. ComponentPeer* createNewPeer (int, void*)
  59830. {
  59831. return new MagnifyingPeer (this, magnifierComp);
  59832. }
  59833. void childBoundsChanged (Component* c)
  59834. {
  59835. if (c != 0)
  59836. {
  59837. setSize (c->getWidth(), c->getHeight());
  59838. magnifierComp->childBoundsChanged (this);
  59839. }
  59840. }
  59841. void mouseWheelMove (const MouseEvent& e, float ix, float iy)
  59842. {
  59843. // unhandled mouse wheel moves can be referred upwards to the parent comp..
  59844. Component* const p = magnifierComp->getParentComponent();
  59845. if (p != 0)
  59846. p->mouseWheelMove (e.getEventRelativeTo (p), ix, iy);
  59847. }
  59848. private:
  59849. MagnifierComponent* const magnifierComp;
  59850. PeerHolderComp (const PeerHolderComp&);
  59851. const PeerHolderComp& operator= (const PeerHolderComp&);
  59852. };
  59853. MagnifierComponent::MagnifierComponent (Component* const content_,
  59854. const bool deleteContentCompWhenNoLongerNeeded)
  59855. : content (content_),
  59856. scaleFactor (0.0),
  59857. peer (0),
  59858. deleteContent (deleteContentCompWhenNoLongerNeeded),
  59859. quality (Graphics::lowResamplingQuality)
  59860. {
  59861. holderComp = new PeerHolderComp (this);
  59862. setScaleFactor (1.0);
  59863. }
  59864. MagnifierComponent::~MagnifierComponent()
  59865. {
  59866. delete holderComp;
  59867. if (deleteContent)
  59868. delete content;
  59869. }
  59870. void MagnifierComponent::setScaleFactor (double newScaleFactor)
  59871. {
  59872. jassert (newScaleFactor > 0.0); // hmm - unlikely to work well with a negative scale factor
  59873. newScaleFactor = jlimit (1.0 / 8.0, 1000.0, newScaleFactor);
  59874. if (scaleFactor != newScaleFactor)
  59875. {
  59876. scaleFactor = newScaleFactor;
  59877. if (scaleFactor == 1.0)
  59878. {
  59879. holderComp->removeFromDesktop();
  59880. peer = 0;
  59881. addChildComponent (content);
  59882. childBoundsChanged (content);
  59883. }
  59884. else
  59885. {
  59886. holderComp->addAndMakeVisible (content);
  59887. holderComp->childBoundsChanged (content);
  59888. childBoundsChanged (holderComp);
  59889. holderComp->addToDesktop (0);
  59890. peer = holderComp->getPeer();
  59891. }
  59892. repaint();
  59893. }
  59894. }
  59895. void MagnifierComponent::setResamplingQuality (Graphics::ResamplingQuality newQuality)
  59896. {
  59897. quality = newQuality;
  59898. }
  59899. void MagnifierComponent::paint (Graphics& g)
  59900. {
  59901. const int w = holderComp->getWidth();
  59902. const int h = holderComp->getHeight();
  59903. if (w == 0 || h == 0)
  59904. return;
  59905. const Rectangle<int> r (g.getClipBounds());
  59906. const int srcX = (int) (r.getX() / scaleFactor);
  59907. const int srcY = (int) (r.getY() / scaleFactor);
  59908. int srcW = roundToInt (r.getRight() / scaleFactor) - srcX;
  59909. int srcH = roundToInt (r.getBottom() / scaleFactor) - srcY;
  59910. if (scaleFactor >= 1.0)
  59911. {
  59912. ++srcW;
  59913. ++srcH;
  59914. }
  59915. Image temp (Image::ARGB, jmax (w, srcX + srcW), jmax (h, srcY + srcH), false);
  59916. temp.clear (srcX, srcY, srcW, srcH);
  59917. {
  59918. Graphics g2 (temp);
  59919. g2.reduceClipRegion (srcX, srcY, srcW, srcH);
  59920. holderComp->paintEntireComponent (g2);
  59921. }
  59922. g.setImageResamplingQuality (quality);
  59923. g.drawImageTransformed (&temp, temp.getBounds(),
  59924. AffineTransform::scale ((float) scaleFactor, (float) scaleFactor),
  59925. false);
  59926. }
  59927. void MagnifierComponent::childBoundsChanged (Component* c)
  59928. {
  59929. if (c != 0)
  59930. setSize (roundToInt (c->getWidth() * scaleFactor),
  59931. roundToInt (c->getHeight() * scaleFactor));
  59932. }
  59933. void MagnifierComponent::mouseDown (const MouseEvent& e)
  59934. {
  59935. if (peer != 0)
  59936. peer->handleMouseDown (scaleInt (e.x), scaleInt (e.y), e.eventTime.toMilliseconds());
  59937. }
  59938. void MagnifierComponent::mouseUp (const MouseEvent& e)
  59939. {
  59940. if (peer != 0)
  59941. peer->handleMouseUp (e.mods.getRawFlags(), scaleInt (e.x), scaleInt (e.y), e.eventTime.toMilliseconds());
  59942. }
  59943. void MagnifierComponent::mouseDrag (const MouseEvent& e)
  59944. {
  59945. if (peer != 0)
  59946. peer->handleMouseDrag (scaleInt (e.x), scaleInt (e.y), e.eventTime.toMilliseconds());
  59947. }
  59948. void MagnifierComponent::mouseMove (const MouseEvent& e)
  59949. {
  59950. if (peer != 0)
  59951. peer->handleMouseMove (scaleInt (e.x), scaleInt (e.y), e.eventTime.toMilliseconds());
  59952. }
  59953. void MagnifierComponent::mouseEnter (const MouseEvent& e)
  59954. {
  59955. if (peer != 0)
  59956. peer->handleMouseEnter (scaleInt (e.x), scaleInt (e.y), e.eventTime.toMilliseconds());
  59957. }
  59958. void MagnifierComponent::mouseExit (const MouseEvent& e)
  59959. {
  59960. if (peer != 0)
  59961. peer->handleMouseExit (scaleInt (e.x), scaleInt (e.y), e.eventTime.toMilliseconds());
  59962. }
  59963. void MagnifierComponent::mouseWheelMove (const MouseEvent& e, float ix, float iy)
  59964. {
  59965. if (peer != 0)
  59966. peer->handleMouseWheel (roundToInt (ix * 256.0f),
  59967. roundToInt (iy * 256.0f),
  59968. e.eventTime.toMilliseconds());
  59969. else
  59970. Component::mouseWheelMove (e, ix, iy);
  59971. }
  59972. int MagnifierComponent::scaleInt (const int n) const
  59973. {
  59974. return roundToInt (n / scaleFactor);
  59975. }
  59976. END_JUCE_NAMESPACE
  59977. /*** End of inlined file: juce_MagnifierComponent.cpp ***/
  59978. /*** Start of inlined file: juce_MidiKeyboardComponent.cpp ***/
  59979. BEGIN_JUCE_NAMESPACE
  59980. class MidiKeyboardUpDownButton : public Button
  59981. {
  59982. public:
  59983. MidiKeyboardUpDownButton (MidiKeyboardComponent* const owner_,
  59984. const int delta_)
  59985. : Button (String::empty),
  59986. owner (owner_),
  59987. delta (delta_)
  59988. {
  59989. setOpaque (true);
  59990. }
  59991. ~MidiKeyboardUpDownButton()
  59992. {
  59993. }
  59994. void clicked()
  59995. {
  59996. int note = owner->getLowestVisibleKey();
  59997. if (delta < 0)
  59998. note = (note - 1) / 12;
  59999. else
  60000. note = note / 12 + 1;
  60001. owner->setLowestVisibleKey (note * 12);
  60002. }
  60003. void paintButton (Graphics& g,
  60004. bool isMouseOverButton,
  60005. bool isButtonDown)
  60006. {
  60007. owner->drawUpDownButton (g, getWidth(), getHeight(),
  60008. isMouseOverButton, isButtonDown,
  60009. delta > 0);
  60010. }
  60011. private:
  60012. MidiKeyboardComponent* const owner;
  60013. const int delta;
  60014. MidiKeyboardUpDownButton (const MidiKeyboardUpDownButton&);
  60015. const MidiKeyboardUpDownButton& operator= (const MidiKeyboardUpDownButton&);
  60016. };
  60017. MidiKeyboardComponent::MidiKeyboardComponent (MidiKeyboardState& state_,
  60018. const Orientation orientation_)
  60019. : state (state_),
  60020. xOffset (0),
  60021. blackNoteLength (1),
  60022. keyWidth (16.0f),
  60023. orientation (orientation_),
  60024. midiChannel (1),
  60025. midiInChannelMask (0xffff),
  60026. velocity (1.0f),
  60027. noteUnderMouse (-1),
  60028. mouseDownNote (-1),
  60029. rangeStart (0),
  60030. rangeEnd (127),
  60031. firstKey (12 * 4),
  60032. canScroll (true),
  60033. mouseDragging (false),
  60034. useMousePositionForVelocity (true),
  60035. keyMappingOctave (6),
  60036. octaveNumForMiddleC (3)
  60037. {
  60038. addChildComponent (scrollDown = new MidiKeyboardUpDownButton (this, -1));
  60039. addChildComponent (scrollUp = new MidiKeyboardUpDownButton (this, 1));
  60040. // initialise with a default set of querty key-mappings..
  60041. const char* const keymap = "awsedftgyhujkolp;";
  60042. for (int i = String (keymap).length(); --i >= 0;)
  60043. setKeyPressForNote (KeyPress (keymap[i], 0, 0), i);
  60044. setOpaque (true);
  60045. setWantsKeyboardFocus (true);
  60046. state.addListener (this);
  60047. }
  60048. MidiKeyboardComponent::~MidiKeyboardComponent()
  60049. {
  60050. state.removeListener (this);
  60051. jassert (mouseDownNote < 0 && keysPressed.countNumberOfSetBits() == 0); // leaving stuck notes!
  60052. deleteAllChildren();
  60053. }
  60054. void MidiKeyboardComponent::setKeyWidth (const float widthInPixels)
  60055. {
  60056. keyWidth = widthInPixels;
  60057. resized();
  60058. }
  60059. void MidiKeyboardComponent::setOrientation (const Orientation newOrientation)
  60060. {
  60061. if (orientation != newOrientation)
  60062. {
  60063. orientation = newOrientation;
  60064. resized();
  60065. }
  60066. }
  60067. void MidiKeyboardComponent::setAvailableRange (const int lowestNote,
  60068. const int highestNote)
  60069. {
  60070. jassert (lowestNote >= 0 && lowestNote <= 127);
  60071. jassert (highestNote >= 0 && highestNote <= 127);
  60072. jassert (lowestNote <= highestNote);
  60073. if (rangeStart != lowestNote || rangeEnd != highestNote)
  60074. {
  60075. rangeStart = jlimit (0, 127, lowestNote);
  60076. rangeEnd = jlimit (0, 127, highestNote);
  60077. firstKey = jlimit (rangeStart, rangeEnd, firstKey);
  60078. resized();
  60079. }
  60080. }
  60081. void MidiKeyboardComponent::setLowestVisibleKey (int noteNumber)
  60082. {
  60083. noteNumber = jlimit (rangeStart, rangeEnd, noteNumber);
  60084. if (noteNumber != firstKey)
  60085. {
  60086. firstKey = noteNumber;
  60087. sendChangeMessage (this);
  60088. resized();
  60089. }
  60090. }
  60091. void MidiKeyboardComponent::setScrollButtonsVisible (const bool canScroll_)
  60092. {
  60093. if (canScroll != canScroll_)
  60094. {
  60095. canScroll = canScroll_;
  60096. resized();
  60097. }
  60098. }
  60099. void MidiKeyboardComponent::colourChanged()
  60100. {
  60101. repaint();
  60102. }
  60103. void MidiKeyboardComponent::setMidiChannel (const int midiChannelNumber)
  60104. {
  60105. jassert (midiChannelNumber > 0 && midiChannelNumber <= 16);
  60106. if (midiChannel != midiChannelNumber)
  60107. {
  60108. resetAnyKeysInUse();
  60109. midiChannel = jlimit (1, 16, midiChannelNumber);
  60110. }
  60111. }
  60112. void MidiKeyboardComponent::setMidiChannelsToDisplay (const int midiChannelMask)
  60113. {
  60114. midiInChannelMask = midiChannelMask;
  60115. triggerAsyncUpdate();
  60116. }
  60117. void MidiKeyboardComponent::setVelocity (const float velocity_, const bool useMousePositionForVelocity_)
  60118. {
  60119. velocity = jlimit (0.0f, 1.0f, velocity_);
  60120. useMousePositionForVelocity = useMousePositionForVelocity_;
  60121. }
  60122. void MidiKeyboardComponent::getKeyPosition (int midiNoteNumber, const float keyWidth, int& x, int& w) const
  60123. {
  60124. jassert (midiNoteNumber >= 0 && midiNoteNumber < 128);
  60125. static const float blackNoteWidth = 0.7f;
  60126. static const float notePos[] = { 0.0f, 1 - blackNoteWidth * 0.6f,
  60127. 1.0f, 2 - blackNoteWidth * 0.4f,
  60128. 2.0f, 3.0f, 4 - blackNoteWidth * 0.7f,
  60129. 4.0f, 5 - blackNoteWidth * 0.5f,
  60130. 5.0f, 6 - blackNoteWidth * 0.3f,
  60131. 6.0f };
  60132. static const float widths[] = { 1.0f, blackNoteWidth,
  60133. 1.0f, blackNoteWidth,
  60134. 1.0f, 1.0f, blackNoteWidth,
  60135. 1.0f, blackNoteWidth,
  60136. 1.0f, blackNoteWidth,
  60137. 1.0f };
  60138. const int octave = midiNoteNumber / 12;
  60139. const int note = midiNoteNumber % 12;
  60140. x = roundToInt (octave * 7.0f * keyWidth + notePos [note] * keyWidth);
  60141. w = roundToInt (widths [note] * keyWidth);
  60142. }
  60143. void MidiKeyboardComponent::getKeyPos (int midiNoteNumber, int& x, int& w) const
  60144. {
  60145. getKeyPosition (midiNoteNumber, keyWidth, x, w);
  60146. int rx, rw;
  60147. getKeyPosition (rangeStart, keyWidth, rx, rw);
  60148. x -= xOffset + rx;
  60149. }
  60150. int MidiKeyboardComponent::getKeyStartPosition (const int midiNoteNumber) const
  60151. {
  60152. int x, y;
  60153. getKeyPos (midiNoteNumber, x, y);
  60154. return x;
  60155. }
  60156. static const uint8 whiteNotes[] = { 0, 2, 4, 5, 7, 9, 11 };
  60157. static const uint8 blackNotes[] = { 1, 3, 6, 8, 10 };
  60158. int MidiKeyboardComponent::xyToNote (int x, int y, float& mousePositionVelocity)
  60159. {
  60160. if (! reallyContains (x, y, false))
  60161. return -1;
  60162. if (orientation != horizontalKeyboard)
  60163. {
  60164. swapVariables (x, y);
  60165. if (orientation == verticalKeyboardFacingLeft)
  60166. y = getWidth() - y;
  60167. else
  60168. x = getHeight() - x;
  60169. }
  60170. return remappedXYToNote (x + xOffset, y, mousePositionVelocity);
  60171. }
  60172. int MidiKeyboardComponent::remappedXYToNote (int x, int y, float& mousePositionVelocity) const
  60173. {
  60174. if (y < blackNoteLength)
  60175. {
  60176. for (int octaveStart = 12 * (rangeStart / 12); octaveStart <= rangeEnd; octaveStart += 12)
  60177. {
  60178. for (int i = 0; i < 5; ++i)
  60179. {
  60180. const int note = octaveStart + blackNotes [i];
  60181. if (note >= rangeStart && note <= rangeEnd)
  60182. {
  60183. int kx, kw;
  60184. getKeyPos (note, kx, kw);
  60185. kx += xOffset;
  60186. if (x >= kx && x < kx + kw)
  60187. {
  60188. mousePositionVelocity = y / (float) blackNoteLength;
  60189. return note;
  60190. }
  60191. }
  60192. }
  60193. }
  60194. }
  60195. for (int octaveStart = 12 * (rangeStart / 12); octaveStart <= rangeEnd; octaveStart += 12)
  60196. {
  60197. for (int i = 0; i < 7; ++i)
  60198. {
  60199. const int note = octaveStart + whiteNotes [i];
  60200. if (note >= rangeStart && note <= rangeEnd)
  60201. {
  60202. int kx, kw;
  60203. getKeyPos (note, kx, kw);
  60204. kx += xOffset;
  60205. if (x >= kx && x < kx + kw)
  60206. {
  60207. const int whiteNoteLength = (orientation == horizontalKeyboard) ? getHeight() : getWidth();
  60208. mousePositionVelocity = y / (float) whiteNoteLength;
  60209. return note;
  60210. }
  60211. }
  60212. }
  60213. }
  60214. mousePositionVelocity = 0;
  60215. return -1;
  60216. }
  60217. void MidiKeyboardComponent::repaintNote (const int noteNum)
  60218. {
  60219. if (noteNum >= rangeStart && noteNum <= rangeEnd)
  60220. {
  60221. int x, w;
  60222. getKeyPos (noteNum, x, w);
  60223. if (orientation == horizontalKeyboard)
  60224. repaint (x, 0, w, getHeight());
  60225. else if (orientation == verticalKeyboardFacingLeft)
  60226. repaint (0, x, getWidth(), w);
  60227. else if (orientation == verticalKeyboardFacingRight)
  60228. repaint (0, getHeight() - x - w, getWidth(), w);
  60229. }
  60230. }
  60231. void MidiKeyboardComponent::paint (Graphics& g)
  60232. {
  60233. g.fillAll (Colours::white.overlaidWith (findColour (whiteNoteColourId)));
  60234. const Colour lineColour (findColour (keySeparatorLineColourId));
  60235. const Colour textColour (findColour (textLabelColourId));
  60236. int x, w, octave;
  60237. for (octave = 0; octave < 128; octave += 12)
  60238. {
  60239. for (int white = 0; white < 7; ++white)
  60240. {
  60241. const int noteNum = octave + whiteNotes [white];
  60242. if (noteNum >= rangeStart && noteNum <= rangeEnd)
  60243. {
  60244. getKeyPos (noteNum, x, w);
  60245. if (orientation == horizontalKeyboard)
  60246. drawWhiteNote (noteNum, g, x, 0, w, getHeight(),
  60247. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  60248. noteUnderMouse == noteNum,
  60249. lineColour, textColour);
  60250. else if (orientation == verticalKeyboardFacingLeft)
  60251. drawWhiteNote (noteNum, g, 0, x, getWidth(), w,
  60252. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  60253. noteUnderMouse == noteNum,
  60254. lineColour, textColour);
  60255. else if (orientation == verticalKeyboardFacingRight)
  60256. drawWhiteNote (noteNum, g, 0, getHeight() - x - w, getWidth(), w,
  60257. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  60258. noteUnderMouse == noteNum,
  60259. lineColour, textColour);
  60260. }
  60261. }
  60262. }
  60263. float x1 = 0.0f, y1 = 0.0f, x2 = 0.0f, y2 = 0.0f;
  60264. if (orientation == verticalKeyboardFacingLeft)
  60265. {
  60266. x1 = getWidth() - 1.0f;
  60267. x2 = getWidth() - 5.0f;
  60268. }
  60269. else if (orientation == verticalKeyboardFacingRight)
  60270. x2 = 5.0f;
  60271. else
  60272. y2 = 5.0f;
  60273. g.setGradientFill (ColourGradient (Colours::black.withAlpha (0.3f), x1, y1,
  60274. Colours::transparentBlack, x2, y2, false));
  60275. getKeyPos (rangeEnd, x, w);
  60276. x += w;
  60277. if (orientation == verticalKeyboardFacingLeft)
  60278. g.fillRect (getWidth() - 5, 0, 5, x);
  60279. else if (orientation == verticalKeyboardFacingRight)
  60280. g.fillRect (0, 0, 5, x);
  60281. else
  60282. g.fillRect (0, 0, x, 5);
  60283. g.setColour (lineColour);
  60284. if (orientation == verticalKeyboardFacingLeft)
  60285. g.fillRect (0, 0, 1, x);
  60286. else if (orientation == verticalKeyboardFacingRight)
  60287. g.fillRect (getWidth() - 1, 0, 1, x);
  60288. else
  60289. g.fillRect (0, getHeight() - 1, x, 1);
  60290. const Colour blackNoteColour (findColour (blackNoteColourId));
  60291. for (octave = 0; octave < 128; octave += 12)
  60292. {
  60293. for (int black = 0; black < 5; ++black)
  60294. {
  60295. const int noteNum = octave + blackNotes [black];
  60296. if (noteNum >= rangeStart && noteNum <= rangeEnd)
  60297. {
  60298. getKeyPos (noteNum, x, w);
  60299. if (orientation == horizontalKeyboard)
  60300. drawBlackNote (noteNum, g, x, 0, w, blackNoteLength,
  60301. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  60302. noteUnderMouse == noteNum,
  60303. blackNoteColour);
  60304. else if (orientation == verticalKeyboardFacingLeft)
  60305. drawBlackNote (noteNum, g, getWidth() - blackNoteLength, x, blackNoteLength, w,
  60306. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  60307. noteUnderMouse == noteNum,
  60308. blackNoteColour);
  60309. else if (orientation == verticalKeyboardFacingRight)
  60310. drawBlackNote (noteNum, g, 0, getHeight() - x - w, blackNoteLength, w,
  60311. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  60312. noteUnderMouse == noteNum,
  60313. blackNoteColour);
  60314. }
  60315. }
  60316. }
  60317. }
  60318. void MidiKeyboardComponent::drawWhiteNote (int midiNoteNumber,
  60319. Graphics& g, int x, int y, int w, int h,
  60320. bool isDown, bool isOver,
  60321. const Colour& lineColour,
  60322. const Colour& textColour)
  60323. {
  60324. Colour c (Colours::transparentWhite);
  60325. if (isDown)
  60326. c = findColour (keyDownOverlayColourId);
  60327. if (isOver)
  60328. c = c.overlaidWith (findColour (mouseOverKeyOverlayColourId));
  60329. g.setColour (c);
  60330. g.fillRect (x, y, w, h);
  60331. const String text (getWhiteNoteText (midiNoteNumber));
  60332. if (! text.isEmpty())
  60333. {
  60334. g.setColour (textColour);
  60335. Font f (jmin (12.0f, keyWidth * 0.9f));
  60336. f.setHorizontalScale (0.8f);
  60337. g.setFont (f);
  60338. Justification justification (Justification::centredBottom);
  60339. if (orientation == verticalKeyboardFacingLeft)
  60340. justification = Justification::centredLeft;
  60341. else if (orientation == verticalKeyboardFacingRight)
  60342. justification = Justification::centredRight;
  60343. g.drawFittedText (text, x + 2, y + 2, w - 4, h - 4, justification, 1);
  60344. }
  60345. g.setColour (lineColour);
  60346. if (orientation == horizontalKeyboard)
  60347. g.fillRect (x, y, 1, h);
  60348. else if (orientation == verticalKeyboardFacingLeft)
  60349. g.fillRect (x, y, w, 1);
  60350. else if (orientation == verticalKeyboardFacingRight)
  60351. g.fillRect (x, y + h - 1, w, 1);
  60352. if (midiNoteNumber == rangeEnd)
  60353. {
  60354. if (orientation == horizontalKeyboard)
  60355. g.fillRect (x + w, y, 1, h);
  60356. else if (orientation == verticalKeyboardFacingLeft)
  60357. g.fillRect (x, y + h, w, 1);
  60358. else if (orientation == verticalKeyboardFacingRight)
  60359. g.fillRect (x, y - 1, w, 1);
  60360. }
  60361. }
  60362. void MidiKeyboardComponent::drawBlackNote (int /*midiNoteNumber*/,
  60363. Graphics& g, int x, int y, int w, int h,
  60364. bool isDown, bool isOver,
  60365. const Colour& noteFillColour)
  60366. {
  60367. Colour c (noteFillColour);
  60368. if (isDown)
  60369. c = c.overlaidWith (findColour (keyDownOverlayColourId));
  60370. if (isOver)
  60371. c = c.overlaidWith (findColour (mouseOverKeyOverlayColourId));
  60372. g.setColour (c);
  60373. g.fillRect (x, y, w, h);
  60374. if (isDown)
  60375. {
  60376. g.setColour (noteFillColour);
  60377. g.drawRect (x, y, w, h);
  60378. }
  60379. else
  60380. {
  60381. const int xIndent = jmax (1, jmin (w, h) / 8);
  60382. g.setColour (c.brighter());
  60383. if (orientation == horizontalKeyboard)
  60384. g.fillRect (x + xIndent, y, w - xIndent * 2, 7 * h / 8);
  60385. else if (orientation == verticalKeyboardFacingLeft)
  60386. g.fillRect (x + w / 8, y + xIndent, w - w / 8, h - xIndent * 2);
  60387. else if (orientation == verticalKeyboardFacingRight)
  60388. g.fillRect (x, y + xIndent, 7 * w / 8, h - xIndent * 2);
  60389. }
  60390. }
  60391. void MidiKeyboardComponent::setOctaveForMiddleC (const int octaveNumForMiddleC_) throw()
  60392. {
  60393. octaveNumForMiddleC = octaveNumForMiddleC_;
  60394. repaint();
  60395. }
  60396. const String MidiKeyboardComponent::getWhiteNoteText (const int midiNoteNumber)
  60397. {
  60398. if (keyWidth > 14.0f && midiNoteNumber % 12 == 0)
  60399. return MidiMessage::getMidiNoteName (midiNoteNumber, true, true, octaveNumForMiddleC);
  60400. return String::empty;
  60401. }
  60402. void MidiKeyboardComponent::drawUpDownButton (Graphics& g, int w, int h,
  60403. const bool isMouseOver,
  60404. const bool isButtonDown,
  60405. const bool movesOctavesUp)
  60406. {
  60407. g.fillAll (findColour (upDownButtonBackgroundColourId));
  60408. float angle;
  60409. if (orientation == MidiKeyboardComponent::horizontalKeyboard)
  60410. angle = movesOctavesUp ? 0.0f : 0.5f;
  60411. else if (orientation == MidiKeyboardComponent::verticalKeyboardFacingLeft)
  60412. angle = movesOctavesUp ? 0.25f : 0.75f;
  60413. else
  60414. angle = movesOctavesUp ? 0.75f : 0.25f;
  60415. Path path;
  60416. path.lineTo (0.0f, 1.0f);
  60417. path.lineTo (1.0f, 0.5f);
  60418. path.closeSubPath();
  60419. path.applyTransform (AffineTransform::rotation (float_Pi * 2.0f * angle, 0.5f, 0.5f));
  60420. g.setColour (findColour (upDownButtonArrowColourId)
  60421. .withAlpha (isButtonDown ? 1.0f : (isMouseOver ? 0.6f : 0.4f)));
  60422. g.fillPath (path, path.getTransformToScaleToFit (1.0f, 1.0f,
  60423. w - 2.0f,
  60424. h - 2.0f,
  60425. true));
  60426. }
  60427. void MidiKeyboardComponent::resized()
  60428. {
  60429. int w = getWidth();
  60430. int h = getHeight();
  60431. if (w > 0 && h > 0)
  60432. {
  60433. if (orientation != horizontalKeyboard)
  60434. swapVariables (w, h);
  60435. blackNoteLength = roundToInt (h * 0.7f);
  60436. int kx2, kw2;
  60437. getKeyPos (rangeEnd, kx2, kw2);
  60438. kx2 += kw2;
  60439. if (firstKey != rangeStart)
  60440. {
  60441. int kx1, kw1;
  60442. getKeyPos (rangeStart, kx1, kw1);
  60443. if (kx2 - kx1 <= w)
  60444. {
  60445. firstKey = rangeStart;
  60446. sendChangeMessage (this);
  60447. repaint();
  60448. }
  60449. }
  60450. const bool showScrollButtons = canScroll && (firstKey > rangeStart || kx2 > w + xOffset * 2);
  60451. scrollDown->setVisible (showScrollButtons);
  60452. scrollUp->setVisible (showScrollButtons);
  60453. xOffset = 0;
  60454. if (showScrollButtons)
  60455. {
  60456. const int scrollButtonW = jmin (12, w / 2);
  60457. if (orientation == horizontalKeyboard)
  60458. {
  60459. scrollDown->setBounds (0, 0, scrollButtonW, getHeight());
  60460. scrollUp->setBounds (getWidth() - scrollButtonW, 0, scrollButtonW, getHeight());
  60461. }
  60462. else if (orientation == verticalKeyboardFacingLeft)
  60463. {
  60464. scrollDown->setBounds (0, 0, getWidth(), scrollButtonW);
  60465. scrollUp->setBounds (0, getHeight() - scrollButtonW, getWidth(), scrollButtonW);
  60466. }
  60467. else if (orientation == verticalKeyboardFacingRight)
  60468. {
  60469. scrollDown->setBounds (0, getHeight() - scrollButtonW, getWidth(), scrollButtonW);
  60470. scrollUp->setBounds (0, 0, getWidth(), scrollButtonW);
  60471. }
  60472. int endOfLastKey, kw;
  60473. getKeyPos (rangeEnd, endOfLastKey, kw);
  60474. endOfLastKey += kw;
  60475. float mousePositionVelocity;
  60476. const int spaceAvailable = w - scrollButtonW * 2;
  60477. const int lastStartKey = remappedXYToNote (endOfLastKey - spaceAvailable, 0, mousePositionVelocity) + 1;
  60478. if (lastStartKey >= 0 && firstKey > lastStartKey)
  60479. {
  60480. firstKey = jlimit (rangeStart, rangeEnd, lastStartKey);
  60481. sendChangeMessage (this);
  60482. }
  60483. int newOffset = 0;
  60484. getKeyPos (firstKey, newOffset, kw);
  60485. xOffset = newOffset - scrollButtonW;
  60486. }
  60487. else
  60488. {
  60489. firstKey = rangeStart;
  60490. }
  60491. timerCallback();
  60492. repaint();
  60493. }
  60494. }
  60495. void MidiKeyboardComponent::handleNoteOn (MidiKeyboardState*, int /*midiChannel*/, int /*midiNoteNumber*/, float /*velocity*/)
  60496. {
  60497. triggerAsyncUpdate();
  60498. }
  60499. void MidiKeyboardComponent::handleNoteOff (MidiKeyboardState*, int /*midiChannel*/, int /*midiNoteNumber*/)
  60500. {
  60501. triggerAsyncUpdate();
  60502. }
  60503. void MidiKeyboardComponent::handleAsyncUpdate()
  60504. {
  60505. for (int i = rangeStart; i <= rangeEnd; ++i)
  60506. {
  60507. if (keysCurrentlyDrawnDown[i] != state.isNoteOnForChannels (midiInChannelMask, i))
  60508. {
  60509. keysCurrentlyDrawnDown.setBit (i, state.isNoteOnForChannels (midiInChannelMask, i));
  60510. repaintNote (i);
  60511. }
  60512. }
  60513. }
  60514. void MidiKeyboardComponent::resetAnyKeysInUse()
  60515. {
  60516. if (keysPressed.countNumberOfSetBits() > 0 || mouseDownNote > 0)
  60517. {
  60518. state.allNotesOff (midiChannel);
  60519. keysPressed.clear();
  60520. mouseDownNote = -1;
  60521. }
  60522. }
  60523. void MidiKeyboardComponent::updateNoteUnderMouse (int x, int y)
  60524. {
  60525. float mousePositionVelocity = 0.0f;
  60526. const int newNote = (mouseDragging || isMouseOver())
  60527. ? xyToNote (x, y, mousePositionVelocity) : -1;
  60528. if (noteUnderMouse != newNote)
  60529. {
  60530. if (mouseDownNote >= 0)
  60531. {
  60532. state.noteOff (midiChannel, mouseDownNote);
  60533. mouseDownNote = -1;
  60534. }
  60535. if (mouseDragging && newNote >= 0)
  60536. {
  60537. if (! useMousePositionForVelocity)
  60538. mousePositionVelocity = 1.0f;
  60539. state.noteOn (midiChannel, newNote, mousePositionVelocity * velocity);
  60540. mouseDownNote = newNote;
  60541. }
  60542. repaintNote (noteUnderMouse);
  60543. noteUnderMouse = newNote;
  60544. repaintNote (noteUnderMouse);
  60545. }
  60546. else if (mouseDownNote >= 0 && ! mouseDragging)
  60547. {
  60548. state.noteOff (midiChannel, mouseDownNote);
  60549. mouseDownNote = -1;
  60550. }
  60551. }
  60552. void MidiKeyboardComponent::mouseMove (const MouseEvent& e)
  60553. {
  60554. updateNoteUnderMouse (e.x, e.y);
  60555. stopTimer();
  60556. }
  60557. void MidiKeyboardComponent::mouseDrag (const MouseEvent& e)
  60558. {
  60559. float mousePositionVelocity;
  60560. const int newNote = xyToNote (e.x, e.y, mousePositionVelocity);
  60561. if (newNote >= 0)
  60562. mouseDraggedToKey (newNote, e);
  60563. updateNoteUnderMouse (e.x, e.y);
  60564. }
  60565. bool MidiKeyboardComponent::mouseDownOnKey (int /*midiNoteNumber*/, const MouseEvent&)
  60566. {
  60567. return true;
  60568. }
  60569. void MidiKeyboardComponent::mouseDraggedToKey (int /*midiNoteNumber*/, const MouseEvent&)
  60570. {
  60571. }
  60572. void MidiKeyboardComponent::mouseDown (const MouseEvent& e)
  60573. {
  60574. float mousePositionVelocity;
  60575. const int newNote = xyToNote (e.x, e.y, mousePositionVelocity);
  60576. mouseDragging = false;
  60577. if (newNote >= 0 && mouseDownOnKey (newNote, e))
  60578. {
  60579. repaintNote (noteUnderMouse);
  60580. noteUnderMouse = -1;
  60581. mouseDragging = true;
  60582. updateNoteUnderMouse (e.x, e.y);
  60583. startTimer (500);
  60584. }
  60585. }
  60586. void MidiKeyboardComponent::mouseUp (const MouseEvent& e)
  60587. {
  60588. mouseDragging = false;
  60589. updateNoteUnderMouse (e.x, e.y);
  60590. stopTimer();
  60591. }
  60592. void MidiKeyboardComponent::mouseEnter (const MouseEvent& e)
  60593. {
  60594. updateNoteUnderMouse (e.x, e.y);
  60595. }
  60596. void MidiKeyboardComponent::mouseExit (const MouseEvent& e)
  60597. {
  60598. updateNoteUnderMouse (e.x, e.y);
  60599. }
  60600. void MidiKeyboardComponent::mouseWheelMove (const MouseEvent&, float ix, float iy)
  60601. {
  60602. setLowestVisibleKey (getLowestVisibleKey() + roundToInt ((ix != 0 ? ix : iy) * 5.0f));
  60603. }
  60604. void MidiKeyboardComponent::timerCallback()
  60605. {
  60606. int mx, my;
  60607. getMouseXYRelative (mx, my);
  60608. updateNoteUnderMouse (mx, my);
  60609. }
  60610. void MidiKeyboardComponent::clearKeyMappings()
  60611. {
  60612. resetAnyKeysInUse();
  60613. keyPressNotes.clear();
  60614. keyPresses.clear();
  60615. }
  60616. void MidiKeyboardComponent::setKeyPressForNote (const KeyPress& key,
  60617. const int midiNoteOffsetFromC)
  60618. {
  60619. removeKeyPressForNote (midiNoteOffsetFromC);
  60620. keyPressNotes.add (midiNoteOffsetFromC);
  60621. keyPresses.add (key);
  60622. }
  60623. void MidiKeyboardComponent::removeKeyPressForNote (const int midiNoteOffsetFromC)
  60624. {
  60625. for (int i = keyPressNotes.size(); --i >= 0;)
  60626. {
  60627. if (keyPressNotes.getUnchecked (i) == midiNoteOffsetFromC)
  60628. {
  60629. keyPressNotes.remove (i);
  60630. keyPresses.remove (i);
  60631. }
  60632. }
  60633. }
  60634. void MidiKeyboardComponent::setKeyPressBaseOctave (const int newOctaveNumber)
  60635. {
  60636. jassert (newOctaveNumber >= 0 && newOctaveNumber <= 10);
  60637. keyMappingOctave = newOctaveNumber;
  60638. }
  60639. bool MidiKeyboardComponent::keyStateChanged (const bool /*isKeyDown*/)
  60640. {
  60641. bool keyPressUsed = false;
  60642. for (int i = keyPresses.size(); --i >= 0;)
  60643. {
  60644. const int note = 12 * keyMappingOctave + keyPressNotes.getUnchecked (i);
  60645. if (keyPresses.getReference(i).isCurrentlyDown())
  60646. {
  60647. if (! keysPressed [note])
  60648. {
  60649. keysPressed.setBit (note);
  60650. state.noteOn (midiChannel, note, velocity);
  60651. keyPressUsed = true;
  60652. }
  60653. }
  60654. else
  60655. {
  60656. if (keysPressed [note])
  60657. {
  60658. keysPressed.clearBit (note);
  60659. state.noteOff (midiChannel, note);
  60660. keyPressUsed = true;
  60661. }
  60662. }
  60663. }
  60664. return keyPressUsed;
  60665. }
  60666. void MidiKeyboardComponent::focusLost (FocusChangeType)
  60667. {
  60668. resetAnyKeysInUse();
  60669. }
  60670. END_JUCE_NAMESPACE
  60671. /*** End of inlined file: juce_MidiKeyboardComponent.cpp ***/
  60672. /*** Start of inlined file: juce_OpenGLComponent.cpp ***/
  60673. #if JUCE_OPENGL
  60674. BEGIN_JUCE_NAMESPACE
  60675. extern void juce_glViewport (const int w, const int h);
  60676. OpenGLPixelFormat::OpenGLPixelFormat (const int bitsPerRGBComponent,
  60677. const int alphaBits_,
  60678. const int depthBufferBits_,
  60679. const int stencilBufferBits_) throw()
  60680. : redBits (bitsPerRGBComponent),
  60681. greenBits (bitsPerRGBComponent),
  60682. blueBits (bitsPerRGBComponent),
  60683. alphaBits (alphaBits_),
  60684. depthBufferBits (depthBufferBits_),
  60685. stencilBufferBits (stencilBufferBits_),
  60686. accumulationBufferRedBits (0),
  60687. accumulationBufferGreenBits (0),
  60688. accumulationBufferBlueBits (0),
  60689. accumulationBufferAlphaBits (0),
  60690. fullSceneAntiAliasingNumSamples (0)
  60691. {
  60692. }
  60693. bool OpenGLPixelFormat::operator== (const OpenGLPixelFormat& other) const throw()
  60694. {
  60695. return memcmp (this, &other, sizeof (other)) == 0;
  60696. }
  60697. static VoidArray knownContexts;
  60698. OpenGLContext::OpenGLContext() throw()
  60699. {
  60700. knownContexts.add (this);
  60701. }
  60702. OpenGLContext::~OpenGLContext()
  60703. {
  60704. knownContexts.removeValue (this);
  60705. }
  60706. OpenGLContext* OpenGLContext::getCurrentContext()
  60707. {
  60708. for (int i = knownContexts.size(); --i >= 0;)
  60709. {
  60710. OpenGLContext* const oglc = (OpenGLContext*) knownContexts.getUnchecked(i);
  60711. if (oglc->isActive())
  60712. return oglc;
  60713. }
  60714. return 0;
  60715. }
  60716. class OpenGLComponent::OpenGLComponentWatcher : public ComponentMovementWatcher
  60717. {
  60718. public:
  60719. OpenGLComponentWatcher (OpenGLComponent* const owner_)
  60720. : ComponentMovementWatcher (owner_),
  60721. owner (owner_),
  60722. wasShowing (false)
  60723. {
  60724. }
  60725. ~OpenGLComponentWatcher() {}
  60726. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  60727. {
  60728. owner->updateContextPosition();
  60729. }
  60730. void componentPeerChanged()
  60731. {
  60732. const ScopedLock sl (owner->getContextLock());
  60733. owner->deleteContext();
  60734. }
  60735. void componentVisibilityChanged (Component&)
  60736. {
  60737. const bool isShowingNow = owner->isShowing();
  60738. if (wasShowing != isShowingNow)
  60739. {
  60740. wasShowing = isShowingNow;
  60741. owner->updateContextPosition();
  60742. }
  60743. }
  60744. juce_UseDebuggingNewOperator
  60745. private:
  60746. OpenGLComponent* const owner;
  60747. bool wasShowing;
  60748. };
  60749. OpenGLComponent::OpenGLComponent()
  60750. : context (0),
  60751. contextToShareListsWith (0),
  60752. needToUpdateViewport (true)
  60753. {
  60754. setOpaque (true);
  60755. componentWatcher = new OpenGLComponentWatcher (this);
  60756. }
  60757. OpenGLComponent::~OpenGLComponent()
  60758. {
  60759. deleteContext();
  60760. componentWatcher = 0;
  60761. }
  60762. void OpenGLComponent::deleteContext()
  60763. {
  60764. const ScopedLock sl (contextLock);
  60765. deleteAndZero (context);
  60766. }
  60767. void OpenGLComponent::updateContextPosition()
  60768. {
  60769. needToUpdateViewport = true;
  60770. if (getWidth() > 0 && getHeight() > 0)
  60771. {
  60772. Component* const topComp = getTopLevelComponent();
  60773. if (topComp->getPeer() != 0)
  60774. {
  60775. const ScopedLock sl (contextLock);
  60776. if (context != 0)
  60777. context->updateWindowPosition (getScreenX() - topComp->getScreenX(),
  60778. getScreenY() - topComp->getScreenY(),
  60779. getWidth(),
  60780. getHeight(),
  60781. topComp->getHeight());
  60782. }
  60783. }
  60784. }
  60785. const OpenGLPixelFormat OpenGLComponent::getPixelFormat() const
  60786. {
  60787. OpenGLPixelFormat pf;
  60788. const ScopedLock sl (contextLock);
  60789. if (context != 0)
  60790. pf = context->getPixelFormat();
  60791. return pf;
  60792. }
  60793. void OpenGLComponent::setPixelFormat (const OpenGLPixelFormat& formatToUse)
  60794. {
  60795. if (! (preferredPixelFormat == formatToUse))
  60796. {
  60797. const ScopedLock sl (contextLock);
  60798. deleteContext();
  60799. preferredPixelFormat = formatToUse;
  60800. }
  60801. }
  60802. void OpenGLComponent::shareWith (OpenGLContext* c)
  60803. {
  60804. if (contextToShareListsWith != c)
  60805. {
  60806. const ScopedLock sl (contextLock);
  60807. deleteContext();
  60808. contextToShareListsWith = c;
  60809. }
  60810. }
  60811. bool OpenGLComponent::makeCurrentContextActive()
  60812. {
  60813. if (context == 0)
  60814. {
  60815. const ScopedLock sl (contextLock);
  60816. if (isShowing() && getTopLevelComponent()->getPeer() != 0)
  60817. {
  60818. context = OpenGLContext::createContextForWindow (this,
  60819. preferredPixelFormat,
  60820. contextToShareListsWith);
  60821. if (context != 0)
  60822. {
  60823. updateContextPosition();
  60824. if (context->makeActive())
  60825. newOpenGLContextCreated();
  60826. }
  60827. }
  60828. }
  60829. return context != 0 && context->makeActive();
  60830. }
  60831. void OpenGLComponent::makeCurrentContextInactive()
  60832. {
  60833. if (context != 0)
  60834. context->makeInactive();
  60835. }
  60836. bool OpenGLComponent::isActiveContext() const throw()
  60837. {
  60838. return context != 0 && context->isActive();
  60839. }
  60840. void OpenGLComponent::swapBuffers()
  60841. {
  60842. if (context != 0)
  60843. context->swapBuffers();
  60844. }
  60845. void OpenGLComponent::paint (Graphics&)
  60846. {
  60847. if (renderAndSwapBuffers())
  60848. {
  60849. ComponentPeer* const peer = getPeer();
  60850. if (peer != 0)
  60851. {
  60852. peer->addMaskedRegion (getScreenX() - peer->getScreenX(),
  60853. getScreenY() - peer->getScreenY(),
  60854. getWidth(), getHeight());
  60855. }
  60856. }
  60857. }
  60858. bool OpenGLComponent::renderAndSwapBuffers()
  60859. {
  60860. const ScopedLock sl (contextLock);
  60861. if (! makeCurrentContextActive())
  60862. return false;
  60863. if (needToUpdateViewport)
  60864. {
  60865. needToUpdateViewport = false;
  60866. juce_glViewport (getWidth(), getHeight());
  60867. }
  60868. renderOpenGL();
  60869. swapBuffers();
  60870. return true;
  60871. }
  60872. void OpenGLComponent::internalRepaint (int x, int y, int w, int h)
  60873. {
  60874. Component::internalRepaint (x, y, w, h);
  60875. if (context != 0)
  60876. context->repaint();
  60877. }
  60878. END_JUCE_NAMESPACE
  60879. #endif
  60880. /*** End of inlined file: juce_OpenGLComponent.cpp ***/
  60881. /*** Start of inlined file: juce_PreferencesPanel.cpp ***/
  60882. BEGIN_JUCE_NAMESPACE
  60883. PreferencesPanel::PreferencesPanel()
  60884. : buttonSize (70)
  60885. {
  60886. }
  60887. PreferencesPanel::~PreferencesPanel()
  60888. {
  60889. currentPage = 0;
  60890. deleteAllChildren();
  60891. }
  60892. void PreferencesPanel::addSettingsPage (const String& title,
  60893. const Drawable* icon,
  60894. const Drawable* overIcon,
  60895. const Drawable* downIcon)
  60896. {
  60897. DrawableButton* button = new DrawableButton (title, DrawableButton::ImageAboveTextLabel);
  60898. button->setImages (icon, overIcon, downIcon);
  60899. button->setRadioGroupId (1);
  60900. button->addButtonListener (this);
  60901. button->setClickingTogglesState (true);
  60902. button->setWantsKeyboardFocus (false);
  60903. addAndMakeVisible (button);
  60904. resized();
  60905. if (currentPage == 0)
  60906. setCurrentPage (title);
  60907. }
  60908. void PreferencesPanel::addSettingsPage (const String& title,
  60909. const char* imageData,
  60910. const int imageDataSize)
  60911. {
  60912. DrawableImage icon, iconOver, iconDown;
  60913. icon.setImage (ImageCache::getFromMemory (imageData, imageDataSize), true);
  60914. iconOver.setImage (ImageCache::getFromMemory (imageData, imageDataSize), true);
  60915. iconOver.setOverlayColour (Colours::black.withAlpha (0.12f));
  60916. iconDown.setImage (ImageCache::getFromMemory (imageData, imageDataSize), true);
  60917. iconDown.setOverlayColour (Colours::black.withAlpha (0.25f));
  60918. addSettingsPage (title, &icon, &iconOver, &iconDown);
  60919. }
  60920. class PrefsDialogWindow : public DialogWindow
  60921. {
  60922. public:
  60923. PrefsDialogWindow (const String& dialogtitle,
  60924. const Colour& backgroundColour)
  60925. : DialogWindow (dialogtitle, backgroundColour, true)
  60926. {
  60927. }
  60928. ~PrefsDialogWindow()
  60929. {
  60930. }
  60931. void closeButtonPressed()
  60932. {
  60933. exitModalState (0);
  60934. }
  60935. private:
  60936. PrefsDialogWindow (const PrefsDialogWindow&);
  60937. const PrefsDialogWindow& operator= (const PrefsDialogWindow&);
  60938. };
  60939. void PreferencesPanel::showInDialogBox (const String& dialogtitle,
  60940. int dialogWidth,
  60941. int dialogHeight,
  60942. const Colour& backgroundColour)
  60943. {
  60944. setSize (dialogWidth, dialogHeight);
  60945. PrefsDialogWindow dw (dialogtitle, backgroundColour);
  60946. dw.setContentComponent (this, true, true);
  60947. dw.centreAroundComponent (0, dw.getWidth(), dw.getHeight());
  60948. dw.runModalLoop();
  60949. dw.setContentComponent (0, false, false);
  60950. }
  60951. void PreferencesPanel::resized()
  60952. {
  60953. int x = 0;
  60954. for (int i = 0; i < getNumChildComponents(); ++i)
  60955. {
  60956. Component* c = getChildComponent (i);
  60957. if (dynamic_cast <DrawableButton*> (c) == 0)
  60958. {
  60959. c->setBounds (0, buttonSize + 5, getWidth(), getHeight() - buttonSize - 5);
  60960. }
  60961. else
  60962. {
  60963. c->setBounds (x, 0, buttonSize, buttonSize);
  60964. x += buttonSize;
  60965. }
  60966. }
  60967. }
  60968. void PreferencesPanel::paint (Graphics& g)
  60969. {
  60970. g.setColour (Colours::grey);
  60971. g.fillRect (0, buttonSize + 2, getWidth(), 1);
  60972. }
  60973. void PreferencesPanel::setCurrentPage (const String& pageName)
  60974. {
  60975. if (currentPageName != pageName)
  60976. {
  60977. currentPageName = pageName;
  60978. currentPage = 0;
  60979. currentPage = createComponentForPage (pageName);
  60980. if (currentPage != 0)
  60981. {
  60982. addAndMakeVisible (currentPage);
  60983. currentPage->toBack();
  60984. resized();
  60985. }
  60986. for (int i = 0; i < getNumChildComponents(); ++i)
  60987. {
  60988. DrawableButton* db = dynamic_cast <DrawableButton*> (getChildComponent (i));
  60989. if (db != 0 && db->getName() == pageName)
  60990. {
  60991. db->setToggleState (true, false);
  60992. break;
  60993. }
  60994. }
  60995. }
  60996. }
  60997. void PreferencesPanel::buttonClicked (Button*)
  60998. {
  60999. for (int i = 0; i < getNumChildComponents(); ++i)
  61000. {
  61001. DrawableButton* db = dynamic_cast <DrawableButton*> (getChildComponent (i));
  61002. if (db != 0 && db->getToggleState())
  61003. {
  61004. setCurrentPage (db->getName());
  61005. break;
  61006. }
  61007. }
  61008. }
  61009. END_JUCE_NAMESPACE
  61010. /*** End of inlined file: juce_PreferencesPanel.cpp ***/
  61011. /*** Start of inlined file: juce_SystemTrayIconComponent.cpp ***/
  61012. #if JUCE_WINDOWS || JUCE_LINUX
  61013. BEGIN_JUCE_NAMESPACE
  61014. SystemTrayIconComponent::SystemTrayIconComponent()
  61015. {
  61016. addToDesktop (0);
  61017. }
  61018. SystemTrayIconComponent::~SystemTrayIconComponent()
  61019. {
  61020. }
  61021. END_JUCE_NAMESPACE
  61022. #endif
  61023. /*** End of inlined file: juce_SystemTrayIconComponent.cpp ***/
  61024. /*** Start of inlined file: juce_AlertWindow.cpp ***/
  61025. BEGIN_JUCE_NAMESPACE
  61026. static const int titleH = 24;
  61027. static const int iconWidth = 80;
  61028. class AlertWindowTextEditor : public TextEditor
  61029. {
  61030. public:
  61031. static const tchar passwordChar;
  61032. AlertWindowTextEditor (const String& name, const bool isPasswordBox)
  61033. : TextEditor (name, isPasswordBox ? passwordChar : 0)
  61034. {
  61035. setSelectAllWhenFocused (true);
  61036. }
  61037. ~AlertWindowTextEditor()
  61038. {
  61039. }
  61040. void returnPressed()
  61041. {
  61042. // pass these up the component hierarchy to be trigger the buttons
  61043. getParentComponent()->keyPressed (KeyPress (KeyPress::returnKey, 0, T('\n')));
  61044. }
  61045. void escapePressed()
  61046. {
  61047. // pass these up the component hierarchy to be trigger the buttons
  61048. getParentComponent()->keyPressed (KeyPress (KeyPress::escapeKey, 0, 0));
  61049. }
  61050. private:
  61051. AlertWindowTextEditor (const AlertWindowTextEditor&);
  61052. const AlertWindowTextEditor& operator= (const AlertWindowTextEditor&);
  61053. };
  61054. #if JUCE_LINUX
  61055. const tchar AlertWindowTextEditor::passwordChar = 0x2022;
  61056. #else
  61057. const tchar AlertWindowTextEditor::passwordChar = 0x25cf;
  61058. #endif
  61059. AlertWindow::AlertWindow (const String& title,
  61060. const String& message,
  61061. AlertIconType iconType,
  61062. Component* associatedComponent_)
  61063. : TopLevelWindow (title, true),
  61064. alertIconType (iconType),
  61065. associatedComponent (associatedComponent_)
  61066. {
  61067. if (message.isEmpty())
  61068. text = T(" "); // to force an update if the message is empty
  61069. setMessage (message);
  61070. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  61071. {
  61072. Component* const c = Desktop::getInstance().getComponent (i);
  61073. if (c != 0 && c->isAlwaysOnTop() && c->isShowing())
  61074. {
  61075. setAlwaysOnTop (true);
  61076. break;
  61077. }
  61078. }
  61079. if (JUCEApplication::getInstance() == 0)
  61080. setAlwaysOnTop (true); // for a plugin, make it always-on-top because the host windows are often top-level
  61081. lookAndFeelChanged();
  61082. constrainer.setMinimumOnscreenAmounts (0x10000, 0x10000, 0x10000, 0x10000);
  61083. }
  61084. AlertWindow::~AlertWindow()
  61085. {
  61086. for (int i = customComps.size(); --i >= 0;)
  61087. removeChildComponent ((Component*) customComps[i]);
  61088. deleteAllChildren();
  61089. }
  61090. void AlertWindow::userTriedToCloseWindow()
  61091. {
  61092. exitModalState (0);
  61093. }
  61094. void AlertWindow::setMessage (const String& message)
  61095. {
  61096. const String newMessage (message.substring (0, 2048));
  61097. if (text != newMessage)
  61098. {
  61099. text = newMessage;
  61100. font.setHeight (15.0f);
  61101. Font titleFont (font.getHeight() * 1.1f, Font::bold);
  61102. textLayout.setText (getName() + T("\n\n"), titleFont);
  61103. textLayout.appendText (text, font);
  61104. updateLayout (true);
  61105. repaint();
  61106. }
  61107. }
  61108. void AlertWindow::buttonClicked (Button* button)
  61109. {
  61110. for (int i = 0; i < buttons.size(); i++)
  61111. {
  61112. TextButton* const c = (TextButton*) buttons[i];
  61113. if (button->getName() == c->getName())
  61114. {
  61115. if (c->getParentComponent() != 0)
  61116. c->getParentComponent()->exitModalState (c->getCommandID());
  61117. break;
  61118. }
  61119. }
  61120. }
  61121. void AlertWindow::addButton (const String& name,
  61122. const int returnValue,
  61123. const KeyPress& shortcutKey1,
  61124. const KeyPress& shortcutKey2)
  61125. {
  61126. TextButton* const b = new TextButton (name, String::empty);
  61127. b->setWantsKeyboardFocus (true);
  61128. b->setMouseClickGrabsKeyboardFocus (false);
  61129. b->setCommandToTrigger (0, returnValue, false);
  61130. b->addShortcut (shortcutKey1);
  61131. b->addShortcut (shortcutKey2);
  61132. b->addButtonListener (this);
  61133. b->changeWidthToFitText (getLookAndFeel().getAlertWindowButtonHeight());
  61134. addAndMakeVisible (b, 0);
  61135. buttons.add (b);
  61136. updateLayout (false);
  61137. }
  61138. int AlertWindow::getNumButtons() const
  61139. {
  61140. return buttons.size();
  61141. }
  61142. void AlertWindow::addTextEditor (const String& name,
  61143. const String& initialContents,
  61144. const String& onScreenLabel,
  61145. const bool isPasswordBox)
  61146. {
  61147. AlertWindowTextEditor* const tc = new AlertWindowTextEditor (name, isPasswordBox);
  61148. tc->setColour (TextEditor::outlineColourId, findColour (ComboBox::outlineColourId));
  61149. tc->setFont (font);
  61150. tc->setText (initialContents);
  61151. tc->setCaretPosition (initialContents.length());
  61152. addAndMakeVisible (tc);
  61153. textBoxes.add (tc);
  61154. allComps.add (tc);
  61155. textboxNames.add (onScreenLabel);
  61156. updateLayout (false);
  61157. }
  61158. const String AlertWindow::getTextEditorContents (const String& nameOfTextEditor) const
  61159. {
  61160. for (int i = textBoxes.size(); --i >= 0;)
  61161. if (((TextEditor*)textBoxes[i])->getName() == nameOfTextEditor)
  61162. return ((TextEditor*)textBoxes[i])->getText();
  61163. return String::empty;
  61164. }
  61165. void AlertWindow::addComboBox (const String& name,
  61166. const StringArray& items,
  61167. const String& onScreenLabel)
  61168. {
  61169. ComboBox* const cb = new ComboBox (name);
  61170. for (int i = 0; i < items.size(); ++i)
  61171. cb->addItem (items[i], i + 1);
  61172. addAndMakeVisible (cb);
  61173. cb->setSelectedItemIndex (0);
  61174. comboBoxes.add (cb);
  61175. allComps.add (cb);
  61176. comboBoxNames.add (onScreenLabel);
  61177. updateLayout (false);
  61178. }
  61179. ComboBox* AlertWindow::getComboBoxComponent (const String& nameOfList) const
  61180. {
  61181. for (int i = comboBoxes.size(); --i >= 0;)
  61182. if (((ComboBox*) comboBoxes[i])->getName() == nameOfList)
  61183. return (ComboBox*) comboBoxes[i];
  61184. return 0;
  61185. }
  61186. class AlertTextComp : public TextEditor
  61187. {
  61188. AlertTextComp (const AlertTextComp&);
  61189. const AlertTextComp& operator= (const AlertTextComp&);
  61190. int bestWidth;
  61191. public:
  61192. AlertTextComp (const String& message,
  61193. const Font& font)
  61194. {
  61195. setReadOnly (true);
  61196. setMultiLine (true, true);
  61197. setCaretVisible (false);
  61198. setScrollbarsShown (true);
  61199. lookAndFeelChanged();
  61200. setWantsKeyboardFocus (false);
  61201. setFont (font);
  61202. setText (message, false);
  61203. bestWidth = 2 * (int) sqrt (font.getHeight() * font.getStringWidth (message));
  61204. setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  61205. setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  61206. setColour (TextEditor::shadowColourId, Colours::transparentBlack);
  61207. }
  61208. ~AlertTextComp()
  61209. {
  61210. }
  61211. int getPreferredWidth() const throw() { return bestWidth; }
  61212. void updateLayout (const int width)
  61213. {
  61214. TextLayout text;
  61215. text.appendText (getText(), getFont());
  61216. text.layout (width - 8, Justification::topLeft, true);
  61217. setSize (width, jmin (width, text.getHeight() + (int) getFont().getHeight()));
  61218. }
  61219. };
  61220. void AlertWindow::addTextBlock (const String& text)
  61221. {
  61222. AlertTextComp* const c = new AlertTextComp (text, font);
  61223. textBlocks.add (c);
  61224. allComps.add (c);
  61225. addAndMakeVisible (c);
  61226. updateLayout (false);
  61227. }
  61228. void AlertWindow::addProgressBarComponent (double& progressValue)
  61229. {
  61230. ProgressBar* const pb = new ProgressBar (progressValue);
  61231. progressBars.add (pb);
  61232. allComps.add (pb);
  61233. addAndMakeVisible (pb);
  61234. updateLayout (false);
  61235. }
  61236. void AlertWindow::addCustomComponent (Component* const component)
  61237. {
  61238. customComps.add (component);
  61239. allComps.add (component);
  61240. addAndMakeVisible (component);
  61241. updateLayout (false);
  61242. }
  61243. int AlertWindow::getNumCustomComponents() const
  61244. {
  61245. return customComps.size();
  61246. }
  61247. Component* AlertWindow::getCustomComponent (const int index) const
  61248. {
  61249. return (Component*) customComps [index];
  61250. }
  61251. Component* AlertWindow::removeCustomComponent (const int index)
  61252. {
  61253. Component* const c = getCustomComponent (index);
  61254. if (c != 0)
  61255. {
  61256. customComps.removeValue (c);
  61257. allComps.removeValue (c);
  61258. removeChildComponent (c);
  61259. updateLayout (false);
  61260. }
  61261. return c;
  61262. }
  61263. void AlertWindow::paint (Graphics& g)
  61264. {
  61265. getLookAndFeel().drawAlertBox (g, *this, textArea, textLayout);
  61266. g.setColour (findColour (textColourId));
  61267. g.setFont (getLookAndFeel().getAlertWindowFont());
  61268. int i;
  61269. for (i = textBoxes.size(); --i >= 0;)
  61270. {
  61271. const TextEditor* const te = (TextEditor*) textBoxes[i];
  61272. g.drawFittedText (textboxNames[i],
  61273. te->getX(), te->getY() - 14,
  61274. te->getWidth(), 14,
  61275. Justification::centredLeft, 1);
  61276. }
  61277. for (i = comboBoxNames.size(); --i >= 0;)
  61278. {
  61279. const ComboBox* const cb = (ComboBox*) comboBoxes[i];
  61280. g.drawFittedText (comboBoxNames[i],
  61281. cb->getX(), cb->getY() - 14,
  61282. cb->getWidth(), 14,
  61283. Justification::centredLeft, 1);
  61284. }
  61285. for (i = customComps.size(); --i >= 0;)
  61286. {
  61287. const Component* const c = (Component*) customComps[i];
  61288. g.drawFittedText (c->getName(),
  61289. c->getX(), c->getY() - 14,
  61290. c->getWidth(), 14,
  61291. Justification::centredLeft, 1);
  61292. }
  61293. }
  61294. void AlertWindow::updateLayout (const bool onlyIncreaseSize)
  61295. {
  61296. const int wid = jmax (font.getStringWidth (text),
  61297. font.getStringWidth (getName()));
  61298. const int sw = (int) sqrt (font.getHeight() * wid);
  61299. int w = jmin (300 + sw * 2, (int) (getParentWidth() * 0.7f));
  61300. const int edgeGap = 10;
  61301. const int labelHeight = 18;
  61302. int iconSpace;
  61303. if (alertIconType == NoIcon)
  61304. {
  61305. textLayout.layout (w, Justification::horizontallyCentred, true);
  61306. iconSpace = 0;
  61307. }
  61308. else
  61309. {
  61310. textLayout.layout (w, Justification::left, true);
  61311. iconSpace = iconWidth;
  61312. }
  61313. w = jmax (350, textLayout.getWidth() + iconSpace + edgeGap * 4);
  61314. w = jmin (w, (int) (getParentWidth() * 0.7f));
  61315. const int textLayoutH = textLayout.getHeight();
  61316. const int textBottom = 16 + titleH + textLayoutH;
  61317. int h = textBottom;
  61318. int buttonW = 40;
  61319. int i;
  61320. for (i = 0; i < buttons.size(); ++i)
  61321. buttonW += 16 + ((const TextButton*) buttons[i])->getWidth();
  61322. w = jmax (buttonW, w);
  61323. h += (textBoxes.size() + comboBoxes.size() + progressBars.size()) * 50;
  61324. if (buttons.size() > 0)
  61325. h += 20 + ((TextButton*) buttons[0])->getHeight();
  61326. for (i = customComps.size(); --i >= 0;)
  61327. {
  61328. Component* c = (Component*) customComps[i];
  61329. w = jmax (w, (c->getWidth() * 100) / 80);
  61330. h += 10 + c->getHeight();
  61331. if (c->getName().isNotEmpty())
  61332. h += labelHeight;
  61333. }
  61334. for (i = textBlocks.size(); --i >= 0;)
  61335. {
  61336. const AlertTextComp* const ac = (AlertTextComp*) textBlocks[i];
  61337. w = jmax (w, ac->getPreferredWidth());
  61338. }
  61339. w = jmin (w, (int) (getParentWidth() * 0.7f));
  61340. for (i = textBlocks.size(); --i >= 0;)
  61341. {
  61342. AlertTextComp* const ac = (AlertTextComp*) textBlocks[i];
  61343. ac->updateLayout ((int) (w * 0.8f));
  61344. h += ac->getHeight() + 10;
  61345. }
  61346. h = jmin (getParentHeight() - 50, h);
  61347. if (onlyIncreaseSize)
  61348. {
  61349. w = jmax (w, getWidth());
  61350. h = jmax (h, getHeight());
  61351. }
  61352. if (! isVisible())
  61353. {
  61354. centreAroundComponent (associatedComponent, w, h);
  61355. }
  61356. else
  61357. {
  61358. const int cx = getX() + getWidth() / 2;
  61359. const int cy = getY() + getHeight() / 2;
  61360. setBounds (cx - w / 2,
  61361. cy - h / 2,
  61362. w, h);
  61363. }
  61364. textArea.setBounds (edgeGap, edgeGap, w - (edgeGap * 2), h - edgeGap);
  61365. const int spacer = 16;
  61366. int totalWidth = -spacer;
  61367. for (i = buttons.size(); --i >= 0;)
  61368. totalWidth += ((TextButton*) buttons[i])->getWidth() + spacer;
  61369. int x = (w - totalWidth) / 2;
  61370. int y = (int) (getHeight() * 0.95f);
  61371. for (i = 0; i < buttons.size(); ++i)
  61372. {
  61373. TextButton* const c = (TextButton*) buttons[i];
  61374. int ny = proportionOfHeight (0.95f) - c->getHeight();
  61375. c->setTopLeftPosition (x, ny);
  61376. if (ny < y)
  61377. y = ny;
  61378. x += c->getWidth() + spacer;
  61379. c->toFront (false);
  61380. }
  61381. y = textBottom;
  61382. for (i = 0; i < allComps.size(); ++i)
  61383. {
  61384. Component* const c = (Component*) allComps[i];
  61385. int h = 22;
  61386. const int comboIndex = comboBoxes.indexOf (c);
  61387. if (comboIndex >= 0 && comboBoxNames [comboIndex].isNotEmpty())
  61388. y += labelHeight;
  61389. const int tbIndex = textBoxes.indexOf (c);
  61390. if (tbIndex >= 0 && textboxNames[tbIndex].isNotEmpty())
  61391. y += labelHeight;
  61392. if (customComps.contains (c))
  61393. {
  61394. if (c->getName().isNotEmpty())
  61395. y += labelHeight;
  61396. c->setTopLeftPosition (proportionOfWidth (0.1f), y);
  61397. h = c->getHeight();
  61398. }
  61399. else if (textBlocks.contains (c))
  61400. {
  61401. c->setTopLeftPosition ((getWidth() - c->getWidth()) / 2, y);
  61402. h = c->getHeight();
  61403. }
  61404. else
  61405. {
  61406. c->setBounds (proportionOfWidth (0.1f), y, proportionOfWidth (0.8f), h);
  61407. }
  61408. y += h + 10;
  61409. }
  61410. setWantsKeyboardFocus (getNumChildComponents() == 0);
  61411. }
  61412. bool AlertWindow::containsAnyExtraComponents() const
  61413. {
  61414. return textBoxes.size()
  61415. + comboBoxes.size()
  61416. + progressBars.size()
  61417. + customComps.size() > 0;
  61418. }
  61419. void AlertWindow::mouseDown (const MouseEvent&)
  61420. {
  61421. dragger.startDraggingComponent (this, &constrainer);
  61422. }
  61423. void AlertWindow::mouseDrag (const MouseEvent& e)
  61424. {
  61425. dragger.dragComponent (this, e);
  61426. }
  61427. bool AlertWindow::keyPressed (const KeyPress& key)
  61428. {
  61429. for (int i = buttons.size(); --i >= 0;)
  61430. {
  61431. TextButton* const b = (TextButton*) buttons[i];
  61432. if (b->isRegisteredForShortcut (key))
  61433. {
  61434. b->triggerClick();
  61435. return true;
  61436. }
  61437. }
  61438. if (key.isKeyCode (KeyPress::escapeKey) && buttons.size() == 0)
  61439. {
  61440. exitModalState (0);
  61441. return true;
  61442. }
  61443. else if (key.isKeyCode (KeyPress::returnKey) && buttons.size() == 1)
  61444. {
  61445. ((TextButton*) buttons.getFirst())->triggerClick();
  61446. return true;
  61447. }
  61448. return false;
  61449. }
  61450. void AlertWindow::lookAndFeelChanged()
  61451. {
  61452. const int flags = getLookAndFeel().getAlertBoxWindowFlags();
  61453. setUsingNativeTitleBar ((flags & ComponentPeer::windowHasTitleBar) != 0);
  61454. setDropShadowEnabled (isOpaque() && (flags & ComponentPeer::windowHasDropShadow) != 0);
  61455. }
  61456. int AlertWindow::getDesktopWindowStyleFlags() const
  61457. {
  61458. return getLookAndFeel().getAlertBoxWindowFlags();
  61459. }
  61460. struct AlertWindowInfo
  61461. {
  61462. String title, message, button1, button2, button3;
  61463. AlertWindow::AlertIconType iconType;
  61464. int numButtons;
  61465. Component* associatedComponent;
  61466. int run() const
  61467. {
  61468. return (int) (pointer_sized_int)
  61469. MessageManager::getInstance()->callFunctionOnMessageThread (showCallback, (void*) this);
  61470. }
  61471. private:
  61472. int show() const
  61473. {
  61474. jassert (associatedComponent == 0 || associatedComponent->isValidComponent()); // has your comp been deleted?
  61475. LookAndFeel& lf = associatedComponent->isValidComponent() ? associatedComponent->getLookAndFeel()
  61476. : LookAndFeel::getDefaultLookAndFeel();
  61477. ScopedPointer <Component> alertBox (lf.createAlertWindow (title, message, button1, button2, button3,
  61478. iconType, numButtons, associatedComponent));
  61479. jassert (alertBox != 0); // you have to return one of these!
  61480. return alertBox->runModalLoop();
  61481. }
  61482. static void* showCallback (void* userData)
  61483. {
  61484. return (void*) (pointer_sized_int) ((const AlertWindowInfo*) userData)->show();
  61485. }
  61486. };
  61487. void AlertWindow::showMessageBox (AlertIconType iconType,
  61488. const String& title,
  61489. const String& message,
  61490. const String& buttonText,
  61491. Component* associatedComponent)
  61492. {
  61493. AlertWindowInfo info;
  61494. info.title = title;
  61495. info.message = message;
  61496. info.button1 = buttonText.isEmpty() ? TRANS("ok") : buttonText;
  61497. info.iconType = iconType;
  61498. info.numButtons = 1;
  61499. info.associatedComponent = associatedComponent;
  61500. info.run();
  61501. }
  61502. bool AlertWindow::showOkCancelBox (AlertIconType iconType,
  61503. const String& title,
  61504. const String& message,
  61505. const String& button1Text,
  61506. const String& button2Text,
  61507. Component* associatedComponent)
  61508. {
  61509. AlertWindowInfo info;
  61510. info.title = title;
  61511. info.message = message;
  61512. info.button1 = button1Text.isEmpty() ? TRANS("ok") : button1Text;
  61513. info.button2 = button2Text.isEmpty() ? TRANS("cancel") : button2Text;
  61514. info.iconType = iconType;
  61515. info.numButtons = 2;
  61516. info.associatedComponent = associatedComponent;
  61517. return info.run() != 0;
  61518. }
  61519. int AlertWindow::showYesNoCancelBox (AlertIconType iconType,
  61520. const String& title,
  61521. const String& message,
  61522. const String& button1Text,
  61523. const String& button2Text,
  61524. const String& button3Text,
  61525. Component* associatedComponent)
  61526. {
  61527. AlertWindowInfo info;
  61528. info.title = title;
  61529. info.message = message;
  61530. info.button1 = button1Text.isEmpty() ? TRANS("yes") : button1Text;
  61531. info.button2 = button2Text.isEmpty() ? TRANS("no") : button2Text;
  61532. info.button3 = button3Text.isEmpty() ? TRANS("cancel") : button3Text;
  61533. info.iconType = iconType;
  61534. info.numButtons = 3;
  61535. info.associatedComponent = associatedComponent;
  61536. return info.run();
  61537. }
  61538. END_JUCE_NAMESPACE
  61539. /*** End of inlined file: juce_AlertWindow.cpp ***/
  61540. /*** Start of inlined file: juce_ComponentPeer.cpp ***/
  61541. BEGIN_JUCE_NAMESPACE
  61542. //#define JUCE_ENABLE_REPAINT_DEBUGGING 1
  61543. static const int fakeMouseMoveMessage = 0x7fff00ff;
  61544. static VoidArray heavyweightPeers;
  61545. ComponentPeer::ComponentPeer (Component* const component_,
  61546. const int styleFlags_) throw()
  61547. : component (component_),
  61548. styleFlags (styleFlags_),
  61549. lastPaintTime (0),
  61550. constrainer (0),
  61551. lastFocusedComponent (0),
  61552. lastDragAndDropCompUnderMouse (0),
  61553. fakeMouseMessageSent (false),
  61554. isWindowMinimised (false)
  61555. {
  61556. heavyweightPeers.add (this);
  61557. }
  61558. ComponentPeer::~ComponentPeer()
  61559. {
  61560. heavyweightPeers.removeValue (this);
  61561. Desktop::getInstance().triggerFocusCallback();
  61562. }
  61563. int ComponentPeer::getNumPeers() throw()
  61564. {
  61565. return heavyweightPeers.size();
  61566. }
  61567. ComponentPeer* ComponentPeer::getPeer (const int index) throw()
  61568. {
  61569. return (ComponentPeer*) heavyweightPeers [index];
  61570. }
  61571. ComponentPeer* ComponentPeer::getPeerFor (const Component* const component) throw()
  61572. {
  61573. for (int i = heavyweightPeers.size(); --i >= 0;)
  61574. {
  61575. ComponentPeer* const peer = (ComponentPeer*) heavyweightPeers.getUnchecked(i);
  61576. if (peer->getComponent() == component)
  61577. return peer;
  61578. }
  61579. return 0;
  61580. }
  61581. bool ComponentPeer::isValidPeer (const ComponentPeer* const peer) throw()
  61582. {
  61583. return heavyweightPeers.contains (const_cast <ComponentPeer*> (peer));
  61584. }
  61585. void ComponentPeer::updateCurrentModifiers() throw()
  61586. {
  61587. ModifierKeys::updateCurrentModifiers();
  61588. }
  61589. void ComponentPeer::handleMouseEnter (int x, int y, const int64 time)
  61590. {
  61591. jassert (component->isValidComponent());
  61592. updateCurrentModifiers();
  61593. Component* c = component->getComponentAt (x, y);
  61594. const ComponentDeletionWatcher deletionChecker (component);
  61595. if (c != Component::componentUnderMouse && Component::componentUnderMouse != 0)
  61596. {
  61597. jassert (Component::componentUnderMouse->isValidComponent());
  61598. const int oldX = x;
  61599. const int oldY = y;
  61600. component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y);
  61601. Component::componentUnderMouse->internalMouseExit (x, y, time);
  61602. Component::componentUnderMouse = 0;
  61603. if (deletionChecker.hasBeenDeleted())
  61604. return;
  61605. c = component->getComponentAt (oldX, oldY);
  61606. }
  61607. Component::componentUnderMouse = c;
  61608. if (Component::componentUnderMouse != 0)
  61609. {
  61610. component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y);
  61611. Component::componentUnderMouse->internalMouseEnter (x, y, time);
  61612. }
  61613. }
  61614. void ComponentPeer::handleMouseMove (int x, int y, const int64 time)
  61615. {
  61616. jassert (component->isValidComponent());
  61617. updateCurrentModifiers();
  61618. fakeMouseMessageSent = false;
  61619. const ComponentDeletionWatcher deletionChecker (component);
  61620. Component* c = component->getComponentAt (x, y);
  61621. if (c != Component::componentUnderMouse)
  61622. {
  61623. const int oldX = x;
  61624. const int oldY = y;
  61625. if (Component::componentUnderMouse != 0)
  61626. {
  61627. component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y);
  61628. Component::componentUnderMouse->internalMouseExit (x, y, time);
  61629. x = oldX;
  61630. y = oldY;
  61631. Component::componentUnderMouse = 0;
  61632. if (deletionChecker.hasBeenDeleted())
  61633. return; // if this window has just been deleted..
  61634. c = component->getComponentAt (x, y);
  61635. }
  61636. Component::componentUnderMouse = c;
  61637. if (c != 0)
  61638. {
  61639. component->relativePositionToOtherComponent (c, x, y);
  61640. c->internalMouseEnter (x, y, time);
  61641. x = oldX;
  61642. y = oldY;
  61643. if (deletionChecker.hasBeenDeleted())
  61644. return; // if this window has just been deleted..
  61645. }
  61646. }
  61647. if (Component::componentUnderMouse != 0)
  61648. {
  61649. component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y);
  61650. Component::componentUnderMouse->internalMouseMove (x, y, time);
  61651. }
  61652. }
  61653. void ComponentPeer::handleMouseDown (int x, int y, const int64 time)
  61654. {
  61655. Desktop::getInstance().incrementMouseClickCounter();
  61656. updateCurrentModifiers();
  61657. if (ModifierKeys::getCurrentModifiers().getNumMouseButtonsDown() == 1)
  61658. {
  61659. Component::componentUnderMouse = component->getComponentAt (x, y);
  61660. if (Component::componentUnderMouse != 0)
  61661. {
  61662. component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y);
  61663. Component::componentUnderMouse->internalMouseDown (x, y, time);
  61664. }
  61665. }
  61666. }
  61667. void ComponentPeer::handleMouseDrag (int x, int y, const int64 time)
  61668. {
  61669. updateCurrentModifiers();
  61670. if (Component::componentUnderMouse != 0)
  61671. {
  61672. component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y);
  61673. Component::componentUnderMouse->internalMouseDrag (x, y, time);
  61674. }
  61675. }
  61676. void ComponentPeer::handleMouseUp (const int oldModifiers, int x, int y, const int64 time)
  61677. {
  61678. updateCurrentModifiers();
  61679. if (ModifierKeys (oldModifiers).getNumMouseButtonsDown() == 1)
  61680. {
  61681. const ComponentDeletionWatcher deletionChecker (component);
  61682. Component* c = component->getComponentAt (x, y);
  61683. if (c != Component::componentUnderMouse)
  61684. {
  61685. const int oldX = x;
  61686. const int oldY = y;
  61687. if (Component::componentUnderMouse != 0)
  61688. {
  61689. component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y);
  61690. Component::componentUnderMouse->internalMouseUp (oldModifiers, x, y, time);
  61691. x = oldX;
  61692. y = oldY;
  61693. if (Component::componentUnderMouse != 0)
  61694. Component::componentUnderMouse->internalMouseExit (x, y, time);
  61695. if (deletionChecker.hasBeenDeleted())
  61696. return;
  61697. c = component->getComponentAt (oldX, oldY);
  61698. }
  61699. Component::componentUnderMouse = c;
  61700. if (Component::componentUnderMouse != 0)
  61701. {
  61702. component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y);
  61703. Component::componentUnderMouse->internalMouseEnter (x, y, time);
  61704. }
  61705. }
  61706. else
  61707. {
  61708. if (Component::componentUnderMouse != 0)
  61709. {
  61710. component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y);
  61711. Component::componentUnderMouse->internalMouseUp (oldModifiers, x, y, time);
  61712. }
  61713. }
  61714. }
  61715. }
  61716. void ComponentPeer::handleMouseExit (int x, int y, const int64 time)
  61717. {
  61718. jassert (component->isValidComponent());
  61719. updateCurrentModifiers();
  61720. if (Component::componentUnderMouse != 0)
  61721. {
  61722. component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y);
  61723. Component::componentUnderMouse->internalMouseExit (x, y, time);
  61724. Component::componentUnderMouse = 0;
  61725. }
  61726. }
  61727. void ComponentPeer::handleMouseWheel (const int amountX, const int amountY, const int64 time)
  61728. {
  61729. updateCurrentModifiers();
  61730. if (Component::componentUnderMouse != 0)
  61731. Component::componentUnderMouse->internalMouseWheel (amountX, amountY, time);
  61732. }
  61733. void ComponentPeer::sendFakeMouseMove() throw()
  61734. {
  61735. if ((! fakeMouseMessageSent)
  61736. && component->flags.hasHeavyweightPeerFlag
  61737. && ! ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown())
  61738. {
  61739. if (! isMinimised())
  61740. {
  61741. int realX, realY, realW, realH;
  61742. getBounds (realX, realY, realW, realH);
  61743. component->bounds_.setBounds (realX, realY, realW, realH);
  61744. }
  61745. int x, y;
  61746. component->getMouseXYRelative (x, y);
  61747. if (((unsigned int) x) < (unsigned int) component->getWidth()
  61748. && ((unsigned int) y) < (unsigned int) component->getHeight()
  61749. && contains (x, y, false))
  61750. {
  61751. postMessage (new Message (fakeMouseMoveMessage, x, y, 0));
  61752. }
  61753. fakeMouseMessageSent = true;
  61754. }
  61755. }
  61756. void ComponentPeer::handleMessage (const Message& message)
  61757. {
  61758. if (message.intParameter1 == fakeMouseMoveMessage)
  61759. {
  61760. if (! ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown())
  61761. handleMouseMove (message.intParameter2,
  61762. message.intParameter3,
  61763. Time::currentTimeMillis());
  61764. }
  61765. }
  61766. void ComponentPeer::handlePaint (LowLevelGraphicsContext& contextToPaintTo)
  61767. {
  61768. Graphics g (&contextToPaintTo);
  61769. #if JUCE_ENABLE_REPAINT_DEBUGGING
  61770. g.saveState();
  61771. #endif
  61772. JUCE_TRY
  61773. {
  61774. component->paintEntireComponent (g);
  61775. }
  61776. JUCE_CATCH_EXCEPTION
  61777. #if JUCE_ENABLE_REPAINT_DEBUGGING
  61778. // enabling this code will fill all areas that get repainted with a colour overlay, to show
  61779. // clearly when things are being repainted.
  61780. {
  61781. g.restoreState();
  61782. g.fillAll (Colour ((uint8) Random::getSystemRandom().nextInt (255),
  61783. (uint8) Random::getSystemRandom().nextInt (255),
  61784. (uint8) Random::getSystemRandom().nextInt (255),
  61785. (uint8) 0x50));
  61786. }
  61787. #endif
  61788. }
  61789. bool ComponentPeer::handleKeyPress (const int keyCode,
  61790. const juce_wchar textCharacter)
  61791. {
  61792. updateCurrentModifiers();
  61793. Component* target = Component::currentlyFocusedComponent->isValidComponent()
  61794. ? Component::currentlyFocusedComponent
  61795. : component;
  61796. if (target->isCurrentlyBlockedByAnotherModalComponent())
  61797. {
  61798. Component* const currentModalComp = Component::getCurrentlyModalComponent();
  61799. if (currentModalComp != 0)
  61800. target = currentModalComp;
  61801. }
  61802. const KeyPress keyInfo (keyCode,
  61803. ModifierKeys::getCurrentModifiers().getRawFlags()
  61804. & ModifierKeys::allKeyboardModifiers,
  61805. textCharacter);
  61806. bool keyWasUsed = false;
  61807. while (target != 0)
  61808. {
  61809. const ComponentDeletionWatcher deletionChecker (target);
  61810. if (target->keyListeners_ != 0)
  61811. {
  61812. for (int i = target->keyListeners_->size(); --i >= 0;)
  61813. {
  61814. keyWasUsed = ((KeyListener*) target->keyListeners_->getUnchecked(i))->keyPressed (keyInfo, target);
  61815. if (keyWasUsed || deletionChecker.hasBeenDeleted())
  61816. return keyWasUsed;
  61817. i = jmin (i, target->keyListeners_->size());
  61818. }
  61819. }
  61820. keyWasUsed = target->keyPressed (keyInfo);
  61821. if (keyWasUsed || deletionChecker.hasBeenDeleted())
  61822. break;
  61823. if (keyInfo.isKeyCode (KeyPress::tabKey) && Component::getCurrentlyFocusedComponent() != 0)
  61824. {
  61825. Component* const currentlyFocused = Component::getCurrentlyFocusedComponent();
  61826. currentlyFocused->moveKeyboardFocusToSibling (! keyInfo.getModifiers().isShiftDown());
  61827. keyWasUsed = (currentlyFocused != Component::getCurrentlyFocusedComponent());
  61828. break;
  61829. }
  61830. target = target->parentComponent_;
  61831. }
  61832. return keyWasUsed;
  61833. }
  61834. bool ComponentPeer::handleKeyUpOrDown (const bool isKeyDown)
  61835. {
  61836. updateCurrentModifiers();
  61837. Component* target = Component::currentlyFocusedComponent->isValidComponent()
  61838. ? Component::currentlyFocusedComponent
  61839. : component;
  61840. if (target->isCurrentlyBlockedByAnotherModalComponent())
  61841. {
  61842. Component* const currentModalComp = Component::getCurrentlyModalComponent();
  61843. if (currentModalComp != 0)
  61844. target = currentModalComp;
  61845. }
  61846. bool keyWasUsed = false;
  61847. while (target != 0)
  61848. {
  61849. const ComponentDeletionWatcher deletionChecker (target);
  61850. keyWasUsed = target->keyStateChanged (isKeyDown);
  61851. if (keyWasUsed || deletionChecker.hasBeenDeleted())
  61852. break;
  61853. if (target->keyListeners_ != 0)
  61854. {
  61855. for (int i = target->keyListeners_->size(); --i >= 0;)
  61856. {
  61857. keyWasUsed = ((KeyListener*) target->keyListeners_->getUnchecked(i))->keyStateChanged (isKeyDown, target);
  61858. if (keyWasUsed || deletionChecker.hasBeenDeleted())
  61859. return keyWasUsed;
  61860. i = jmin (i, target->keyListeners_->size());
  61861. }
  61862. }
  61863. target = target->parentComponent_;
  61864. }
  61865. return keyWasUsed;
  61866. }
  61867. void ComponentPeer::handleModifierKeysChange()
  61868. {
  61869. updateCurrentModifiers();
  61870. Component* target = Component::getComponentUnderMouse();
  61871. if (target == 0)
  61872. target = Component::getCurrentlyFocusedComponent();
  61873. if (target == 0)
  61874. target = component;
  61875. if (target->isValidComponent())
  61876. target->internalModifierKeysChanged();
  61877. }
  61878. void ComponentPeer::handleBroughtToFront()
  61879. {
  61880. updateCurrentModifiers();
  61881. if (component != 0)
  61882. component->internalBroughtToFront();
  61883. }
  61884. void ComponentPeer::setConstrainer (ComponentBoundsConstrainer* const newConstrainer) throw()
  61885. {
  61886. constrainer = newConstrainer;
  61887. }
  61888. void ComponentPeer::handleMovedOrResized()
  61889. {
  61890. jassert (component->isValidComponent());
  61891. updateCurrentModifiers();
  61892. const bool nowMinimised = isMinimised();
  61893. if (component->flags.hasHeavyweightPeerFlag && ! nowMinimised)
  61894. {
  61895. const ComponentDeletionWatcher deletionChecker (component);
  61896. int realX, realY, realW, realH;
  61897. getBounds (realX, realY, realW, realH);
  61898. const bool wasMoved = (component->getX() != realX || component->getY() != realY);
  61899. const bool wasResized = (component->getWidth() != realW || component->getHeight() != realH);
  61900. if (wasMoved || wasResized)
  61901. {
  61902. component->bounds_.setBounds (realX, realY, realW, realH);
  61903. if (wasResized)
  61904. component->repaint();
  61905. component->sendMovedResizedMessages (wasMoved, wasResized);
  61906. if (deletionChecker.hasBeenDeleted())
  61907. return;
  61908. }
  61909. }
  61910. if (isWindowMinimised != nowMinimised)
  61911. {
  61912. isWindowMinimised = nowMinimised;
  61913. component->minimisationStateChanged (nowMinimised);
  61914. component->sendVisibilityChangeMessage();
  61915. }
  61916. if (! isFullScreen())
  61917. lastNonFullscreenBounds = component->getBounds();
  61918. }
  61919. void ComponentPeer::handleFocusGain()
  61920. {
  61921. updateCurrentModifiers();
  61922. if (component->isParentOf (lastFocusedComponent))
  61923. {
  61924. Component::currentlyFocusedComponent = lastFocusedComponent;
  61925. Desktop::getInstance().triggerFocusCallback();
  61926. lastFocusedComponent->internalFocusGain (Component::focusChangedDirectly);
  61927. }
  61928. else
  61929. {
  61930. if (! component->isCurrentlyBlockedByAnotherModalComponent())
  61931. component->grabKeyboardFocus();
  61932. else
  61933. Component::bringModalComponentToFront();
  61934. }
  61935. }
  61936. void ComponentPeer::handleFocusLoss()
  61937. {
  61938. updateCurrentModifiers();
  61939. if (component->hasKeyboardFocus (true))
  61940. {
  61941. lastFocusedComponent = Component::currentlyFocusedComponent;
  61942. if (lastFocusedComponent != 0)
  61943. {
  61944. Component::currentlyFocusedComponent = 0;
  61945. Desktop::getInstance().triggerFocusCallback();
  61946. lastFocusedComponent->internalFocusLoss (Component::focusChangedByMouseClick);
  61947. }
  61948. }
  61949. }
  61950. Component* ComponentPeer::getLastFocusedSubcomponent() const throw()
  61951. {
  61952. return (component->isParentOf (lastFocusedComponent) && lastFocusedComponent->isShowing())
  61953. ? lastFocusedComponent
  61954. : component;
  61955. }
  61956. void ComponentPeer::handleScreenSizeChange()
  61957. {
  61958. updateCurrentModifiers();
  61959. component->parentSizeChanged();
  61960. handleMovedOrResized();
  61961. }
  61962. void ComponentPeer::setNonFullScreenBounds (const Rectangle<int>& newBounds) throw()
  61963. {
  61964. lastNonFullscreenBounds = newBounds;
  61965. }
  61966. const Rectangle<int>& ComponentPeer::getNonFullScreenBounds() const throw()
  61967. {
  61968. return lastNonFullscreenBounds;
  61969. }
  61970. static FileDragAndDropTarget* findDragAndDropTarget (Component* c,
  61971. const StringArray& files,
  61972. FileDragAndDropTarget* const lastOne)
  61973. {
  61974. while (c != 0)
  61975. {
  61976. FileDragAndDropTarget* const t = dynamic_cast <FileDragAndDropTarget*> (c);
  61977. if (t != 0 && (t == lastOne || t->isInterestedInFileDrag (files)))
  61978. return t;
  61979. c = c->getParentComponent();
  61980. }
  61981. return 0;
  61982. }
  61983. void ComponentPeer::handleFileDragMove (const StringArray& files, int x, int y)
  61984. {
  61985. updateCurrentModifiers();
  61986. FileDragAndDropTarget* lastTarget = 0;
  61987. if (dragAndDropTargetComponent != 0 && ! dragAndDropTargetComponent->hasBeenDeleted())
  61988. lastTarget = const_cast <FileDragAndDropTarget*> (dynamic_cast <const FileDragAndDropTarget*> (dragAndDropTargetComponent->getComponent()));
  61989. FileDragAndDropTarget* newTarget = 0;
  61990. Component* const compUnderMouse = component->getComponentAt (x, y);
  61991. if (compUnderMouse != lastDragAndDropCompUnderMouse)
  61992. {
  61993. lastDragAndDropCompUnderMouse = compUnderMouse;
  61994. newTarget = findDragAndDropTarget (compUnderMouse, files, lastTarget);
  61995. if (newTarget != lastTarget)
  61996. {
  61997. if (lastTarget != 0)
  61998. lastTarget->fileDragExit (files);
  61999. dragAndDropTargetComponent = 0;
  62000. if (newTarget != 0)
  62001. {
  62002. Component* const targetComp = dynamic_cast <Component*> (newTarget);
  62003. int mx = x, my = y;
  62004. component->relativePositionToOtherComponent (targetComp, mx, my);
  62005. dragAndDropTargetComponent = new ComponentDeletionWatcher (dynamic_cast <Component*> (newTarget));
  62006. newTarget->fileDragEnter (files, mx, my);
  62007. }
  62008. }
  62009. }
  62010. else
  62011. {
  62012. newTarget = lastTarget;
  62013. }
  62014. if (newTarget != 0)
  62015. {
  62016. Component* const targetComp = dynamic_cast <Component*> (newTarget);
  62017. component->relativePositionToOtherComponent (targetComp, x, y);
  62018. newTarget->fileDragMove (files, x, y);
  62019. }
  62020. }
  62021. void ComponentPeer::handleFileDragExit (const StringArray& files)
  62022. {
  62023. handleFileDragMove (files, -1, -1);
  62024. jassert (dragAndDropTargetComponent == 0);
  62025. lastDragAndDropCompUnderMouse = 0;
  62026. }
  62027. void ComponentPeer::handleFileDragDrop (const StringArray& files, int x, int y)
  62028. {
  62029. handleFileDragMove (files, x, y);
  62030. if (dragAndDropTargetComponent != 0 && ! dragAndDropTargetComponent->hasBeenDeleted())
  62031. {
  62032. FileDragAndDropTarget* const target = const_cast <FileDragAndDropTarget*> (dynamic_cast <const FileDragAndDropTarget*> (dragAndDropTargetComponent->getComponent()));
  62033. dragAndDropTargetComponent = 0;
  62034. lastDragAndDropCompUnderMouse = 0;
  62035. if (target != 0)
  62036. {
  62037. Component* const targetComp = dynamic_cast <Component*> (target);
  62038. if (targetComp->isCurrentlyBlockedByAnotherModalComponent())
  62039. {
  62040. targetComp->internalModalInputAttempt();
  62041. if (targetComp->isCurrentlyBlockedByAnotherModalComponent())
  62042. return;
  62043. }
  62044. component->relativePositionToOtherComponent (targetComp, x, y);
  62045. target->filesDropped (files, x, y);
  62046. }
  62047. }
  62048. }
  62049. void ComponentPeer::handleUserClosingWindow()
  62050. {
  62051. updateCurrentModifiers();
  62052. component->userTriedToCloseWindow();
  62053. }
  62054. void ComponentPeer::bringModalComponentToFront()
  62055. {
  62056. Component::bringModalComponentToFront();
  62057. }
  62058. void ComponentPeer::clearMaskedRegion() throw()
  62059. {
  62060. maskedRegion.clear();
  62061. }
  62062. void ComponentPeer::addMaskedRegion (int x, int y, int w, int h) throw()
  62063. {
  62064. maskedRegion.add (x, y, w, h);
  62065. }
  62066. const StringArray ComponentPeer::getAvailableRenderingEngines() throw()
  62067. {
  62068. StringArray s;
  62069. s.add ("Software Renderer");
  62070. return s;
  62071. }
  62072. int ComponentPeer::getCurrentRenderingEngine() throw()
  62073. {
  62074. return 0;
  62075. }
  62076. void ComponentPeer::setCurrentRenderingEngine (int /*index*/) throw()
  62077. {
  62078. }
  62079. END_JUCE_NAMESPACE
  62080. /*** End of inlined file: juce_ComponentPeer.cpp ***/
  62081. /*** Start of inlined file: juce_DialogWindow.cpp ***/
  62082. BEGIN_JUCE_NAMESPACE
  62083. DialogWindow::DialogWindow (const String& name,
  62084. const Colour& backgroundColour_,
  62085. const bool escapeKeyTriggersCloseButton_,
  62086. const bool addToDesktop_)
  62087. : DocumentWindow (name, backgroundColour_, DocumentWindow::closeButton, addToDesktop_),
  62088. escapeKeyTriggersCloseButton (escapeKeyTriggersCloseButton_)
  62089. {
  62090. }
  62091. DialogWindow::~DialogWindow()
  62092. {
  62093. }
  62094. void DialogWindow::resized()
  62095. {
  62096. DocumentWindow::resized();
  62097. const KeyPress esc (KeyPress::escapeKey, 0, 0);
  62098. if (escapeKeyTriggersCloseButton
  62099. && getCloseButton() != 0
  62100. && ! getCloseButton()->isRegisteredForShortcut (esc))
  62101. {
  62102. getCloseButton()->addShortcut (esc);
  62103. }
  62104. }
  62105. class TempDialogWindow : public DialogWindow
  62106. {
  62107. public:
  62108. TempDialogWindow (const String& title, const Colour& colour, const bool escapeCloses)
  62109. : DialogWindow (title, colour, escapeCloses, true)
  62110. {
  62111. }
  62112. ~TempDialogWindow()
  62113. {
  62114. }
  62115. void closeButtonPressed()
  62116. {
  62117. setVisible (false);
  62118. }
  62119. private:
  62120. TempDialogWindow (const TempDialogWindow&);
  62121. const TempDialogWindow& operator= (const TempDialogWindow&);
  62122. };
  62123. int DialogWindow::showModalDialog (const String& dialogTitle,
  62124. Component* contentComponent,
  62125. Component* componentToCentreAround,
  62126. const Colour& colour,
  62127. const bool escapeKeyTriggersCloseButton,
  62128. const bool shouldBeResizable,
  62129. const bool useBottomRightCornerResizer)
  62130. {
  62131. TempDialogWindow dw (dialogTitle, colour, escapeKeyTriggersCloseButton);
  62132. dw.setContentComponent (contentComponent, true, true);
  62133. dw.centreAroundComponent (componentToCentreAround, dw.getWidth(), dw.getHeight());
  62134. dw.setResizable (shouldBeResizable, useBottomRightCornerResizer);
  62135. const int result = dw.runModalLoop();
  62136. dw.setContentComponent (0, false);
  62137. return result;
  62138. }
  62139. END_JUCE_NAMESPACE
  62140. /*** End of inlined file: juce_DialogWindow.cpp ***/
  62141. /*** Start of inlined file: juce_DocumentWindow.cpp ***/
  62142. BEGIN_JUCE_NAMESPACE
  62143. class DocumentWindow::ButtonListenerProxy : public ButtonListener
  62144. {
  62145. public:
  62146. ButtonListenerProxy (DocumentWindow& owner_)
  62147. : owner (owner_)
  62148. {
  62149. }
  62150. void buttonClicked (Button* button)
  62151. {
  62152. if (button == owner.getMinimiseButton())
  62153. owner.minimiseButtonPressed();
  62154. else if (button == owner.getMaximiseButton())
  62155. owner.maximiseButtonPressed();
  62156. else if (button == owner.getCloseButton())
  62157. owner.closeButtonPressed();
  62158. }
  62159. juce_UseDebuggingNewOperator
  62160. private:
  62161. DocumentWindow& owner;
  62162. ButtonListenerProxy (const ButtonListenerProxy&);
  62163. ButtonListenerProxy& operator= (const ButtonListenerProxy&);
  62164. };
  62165. DocumentWindow::DocumentWindow (const String& title,
  62166. const Colour& backgroundColour,
  62167. const int requiredButtons_,
  62168. const bool addToDesktop_)
  62169. : ResizableWindow (title, backgroundColour, addToDesktop_),
  62170. titleBarHeight (26),
  62171. menuBarHeight (24),
  62172. requiredButtons (requiredButtons_),
  62173. #if JUCE_MAC
  62174. positionTitleBarButtonsOnLeft (true),
  62175. #else
  62176. positionTitleBarButtonsOnLeft (false),
  62177. #endif
  62178. drawTitleTextCentred (true),
  62179. menuBarModel (0)
  62180. {
  62181. setResizeLimits (128, 128, 32768, 32768);
  62182. lookAndFeelChanged();
  62183. }
  62184. DocumentWindow::~DocumentWindow()
  62185. {
  62186. for (int i = numElementsInArray (titleBarButtons); --i >= 0;)
  62187. titleBarButtons[i] = 0;
  62188. menuBar = 0;
  62189. }
  62190. void DocumentWindow::repaintTitleBar()
  62191. {
  62192. const Rectangle<int> titleBarArea (getTitleBarArea());
  62193. repaint (titleBarArea.getX(), titleBarArea.getY(),
  62194. titleBarArea.getWidth(), titleBarArea.getHeight());
  62195. }
  62196. void DocumentWindow::setName (const String& newName)
  62197. {
  62198. if (newName != getName())
  62199. {
  62200. Component::setName (newName);
  62201. repaintTitleBar();
  62202. }
  62203. }
  62204. void DocumentWindow::setIcon (const Image* imageToUse)
  62205. {
  62206. titleBarIcon = imageToUse != 0 ? imageToUse->createCopy() : 0;
  62207. repaintTitleBar();
  62208. }
  62209. void DocumentWindow::setTitleBarHeight (const int newHeight)
  62210. {
  62211. titleBarHeight = newHeight;
  62212. resized();
  62213. repaintTitleBar();
  62214. }
  62215. void DocumentWindow::setTitleBarButtonsRequired (const int requiredButtons_,
  62216. const bool positionTitleBarButtonsOnLeft_)
  62217. {
  62218. requiredButtons = requiredButtons_;
  62219. positionTitleBarButtonsOnLeft = positionTitleBarButtonsOnLeft_;
  62220. lookAndFeelChanged();
  62221. }
  62222. void DocumentWindow::setTitleBarTextCentred (const bool textShouldBeCentred)
  62223. {
  62224. drawTitleTextCentred = textShouldBeCentred;
  62225. repaintTitleBar();
  62226. }
  62227. void DocumentWindow::setMenuBar (MenuBarModel* menuBarModel_,
  62228. const int menuBarHeight_)
  62229. {
  62230. if (menuBarModel != menuBarModel_)
  62231. {
  62232. menuBar = 0;
  62233. menuBarModel = menuBarModel_;
  62234. menuBarHeight = (menuBarHeight_ > 0) ? menuBarHeight_
  62235. : getLookAndFeel().getDefaultMenuBarHeight();
  62236. if (menuBarModel != 0)
  62237. {
  62238. // (call the Component method directly to avoid the assertion in ResizableWindow)
  62239. Component::addAndMakeVisible (menuBar = new MenuBarComponent (menuBarModel));
  62240. menuBar->setEnabled (isActiveWindow());
  62241. }
  62242. resized();
  62243. }
  62244. }
  62245. void DocumentWindow::closeButtonPressed()
  62246. {
  62247. /* If you've got a close button, you have to override this method to get
  62248. rid of your window!
  62249. If the window is just a pop-up, you should override this method and make
  62250. it delete the window in whatever way is appropriate for your app. E.g. you
  62251. might just want to call "delete this".
  62252. If your app is centred around this window such that the whole app should quit when
  62253. the window is closed, then you will probably want to use this method as an opportunity
  62254. to call JUCEApplication::quit(), and leave the window to be deleted later by your
  62255. JUCEApplication::shutdown() method. (Doing it this way means that your window will
  62256. still get cleaned-up if the app is quit by some other means (e.g. a cmd-Q on the mac
  62257. or closing it via the taskbar icon on Windows).
  62258. */
  62259. jassertfalse
  62260. }
  62261. void DocumentWindow::minimiseButtonPressed()
  62262. {
  62263. setMinimised (true);
  62264. }
  62265. void DocumentWindow::maximiseButtonPressed()
  62266. {
  62267. setFullScreen (! isFullScreen());
  62268. }
  62269. void DocumentWindow::paint (Graphics& g)
  62270. {
  62271. ResizableWindow::paint (g);
  62272. if (resizableBorder == 0)
  62273. {
  62274. g.setColour (getBackgroundColour().overlaidWith (Colour (0x80000000)));
  62275. const BorderSize border (getBorderThickness());
  62276. g.fillRect (0, 0, getWidth(), border.getTop());
  62277. g.fillRect (0, border.getTop(), border.getLeft(), getHeight() - border.getTopAndBottom());
  62278. g.fillRect (getWidth() - border.getRight(), border.getTop(), border.getRight(), getHeight() - border.getTopAndBottom());
  62279. g.fillRect (0, getHeight() - border.getBottom(), getWidth(), border.getBottom());
  62280. }
  62281. const Rectangle<int> titleBarArea (getTitleBarArea());
  62282. g.setOrigin (titleBarArea.getX(), titleBarArea.getY());
  62283. g.reduceClipRegion (0, 0, titleBarArea.getWidth(), titleBarArea.getHeight());
  62284. int titleSpaceX1 = 6;
  62285. int titleSpaceX2 = titleBarArea.getWidth() - 6;
  62286. for (int i = 0; i < 3; ++i)
  62287. {
  62288. if (titleBarButtons[i] != 0)
  62289. {
  62290. if (positionTitleBarButtonsOnLeft)
  62291. titleSpaceX1 = jmax (titleSpaceX1, titleBarButtons[i]->getRight() + (getWidth() - titleBarButtons[i]->getRight()) / 8);
  62292. else
  62293. titleSpaceX2 = jmin (titleSpaceX2, titleBarButtons[i]->getX() - (titleBarButtons[i]->getX() / 8));
  62294. }
  62295. }
  62296. getLookAndFeel().drawDocumentWindowTitleBar (*this, g,
  62297. titleBarArea.getWidth(),
  62298. titleBarArea.getHeight(),
  62299. titleSpaceX1,
  62300. jmax (1, titleSpaceX2 - titleSpaceX1),
  62301. titleBarIcon,
  62302. ! drawTitleTextCentred);
  62303. }
  62304. void DocumentWindow::resized()
  62305. {
  62306. ResizableWindow::resized();
  62307. if (titleBarButtons[1] != 0)
  62308. titleBarButtons[1]->setToggleState (isFullScreen(), false);
  62309. const Rectangle<int> titleBarArea (getTitleBarArea());
  62310. getLookAndFeel()
  62311. .positionDocumentWindowButtons (*this,
  62312. titleBarArea.getX(), titleBarArea.getY(),
  62313. titleBarArea.getWidth(), titleBarArea.getHeight(),
  62314. titleBarButtons[0],
  62315. titleBarButtons[1],
  62316. titleBarButtons[2],
  62317. positionTitleBarButtonsOnLeft);
  62318. if (menuBar != 0)
  62319. menuBar->setBounds (titleBarArea.getX(), titleBarArea.getBottom(),
  62320. titleBarArea.getWidth(), menuBarHeight);
  62321. }
  62322. const BorderSize DocumentWindow::getBorderThickness()
  62323. {
  62324. return BorderSize ((isFullScreen() || isUsingNativeTitleBar())
  62325. ? 0 : (resizableBorder != 0 ? 4 : 1));
  62326. }
  62327. const BorderSize DocumentWindow::getContentComponentBorder()
  62328. {
  62329. BorderSize border (getBorderThickness());
  62330. border.setTop (border.getTop()
  62331. + (isUsingNativeTitleBar() ? 0 : titleBarHeight)
  62332. + (menuBar != 0 ? menuBarHeight : 0));
  62333. return border;
  62334. }
  62335. int DocumentWindow::getTitleBarHeight() const
  62336. {
  62337. return isUsingNativeTitleBar() ? 0 : jmin (titleBarHeight, getHeight() - 4);
  62338. }
  62339. const Rectangle<int> DocumentWindow::getTitleBarArea()
  62340. {
  62341. const BorderSize border (getBorderThickness());
  62342. return Rectangle<int> (border.getLeft(), border.getTop(),
  62343. getWidth() - border.getLeftAndRight(),
  62344. getTitleBarHeight());
  62345. }
  62346. Button* DocumentWindow::getCloseButton() const throw()
  62347. {
  62348. return titleBarButtons[2];
  62349. }
  62350. Button* DocumentWindow::getMinimiseButton() const throw()
  62351. {
  62352. return titleBarButtons[0];
  62353. }
  62354. Button* DocumentWindow::getMaximiseButton() const throw()
  62355. {
  62356. return titleBarButtons[1];
  62357. }
  62358. int DocumentWindow::getDesktopWindowStyleFlags() const
  62359. {
  62360. int flags = ResizableWindow::getDesktopWindowStyleFlags();
  62361. if ((requiredButtons & minimiseButton) != 0)
  62362. flags |= ComponentPeer::windowHasMinimiseButton;
  62363. if ((requiredButtons & maximiseButton) != 0)
  62364. flags |= ComponentPeer::windowHasMaximiseButton;
  62365. if ((requiredButtons & closeButton) != 0)
  62366. flags |= ComponentPeer::windowHasCloseButton;
  62367. return flags;
  62368. }
  62369. void DocumentWindow::lookAndFeelChanged()
  62370. {
  62371. int i;
  62372. for (i = numElementsInArray (titleBarButtons); --i >= 0;)
  62373. titleBarButtons[i] = 0;
  62374. if (! isUsingNativeTitleBar())
  62375. {
  62376. titleBarButtons[0] = ((requiredButtons & minimiseButton) != 0)
  62377. ? getLookAndFeel().createDocumentWindowButton (minimiseButton) : 0;
  62378. titleBarButtons[1] = ((requiredButtons & maximiseButton) != 0)
  62379. ? getLookAndFeel().createDocumentWindowButton (maximiseButton) : 0;
  62380. titleBarButtons[2] = ((requiredButtons & closeButton) != 0)
  62381. ? getLookAndFeel().createDocumentWindowButton (closeButton) : 0;
  62382. for (i = 0; i < 3; ++i)
  62383. {
  62384. if (titleBarButtons[i] != 0)
  62385. {
  62386. if (buttonListener == 0)
  62387. buttonListener = new ButtonListenerProxy (*this);
  62388. titleBarButtons[i]->addButtonListener (buttonListener);
  62389. titleBarButtons[i]->setWantsKeyboardFocus (false);
  62390. // (call the Component method directly to avoid the assertion in ResizableWindow)
  62391. Component::addAndMakeVisible (titleBarButtons[i]);
  62392. }
  62393. }
  62394. if (getCloseButton() != 0)
  62395. {
  62396. #if JUCE_MAC
  62397. getCloseButton()->addShortcut (KeyPress (T('w'), ModifierKeys::commandModifier, 0));
  62398. #else
  62399. getCloseButton()->addShortcut (KeyPress (KeyPress::F4Key, ModifierKeys::altModifier, 0));
  62400. #endif
  62401. }
  62402. }
  62403. activeWindowStatusChanged();
  62404. ResizableWindow::lookAndFeelChanged();
  62405. }
  62406. void DocumentWindow::parentHierarchyChanged()
  62407. {
  62408. lookAndFeelChanged();
  62409. }
  62410. void DocumentWindow::activeWindowStatusChanged()
  62411. {
  62412. ResizableWindow::activeWindowStatusChanged();
  62413. for (int i = numElementsInArray (titleBarButtons); --i >= 0;)
  62414. if (titleBarButtons[i] != 0)
  62415. titleBarButtons[i]->setEnabled (isActiveWindow());
  62416. if (menuBar != 0)
  62417. menuBar->setEnabled (isActiveWindow());
  62418. }
  62419. void DocumentWindow::mouseDoubleClick (const MouseEvent& e)
  62420. {
  62421. if (getTitleBarArea().contains (e.x, e.y)
  62422. && getMaximiseButton() != 0)
  62423. {
  62424. getMaximiseButton()->triggerClick();
  62425. }
  62426. }
  62427. void DocumentWindow::userTriedToCloseWindow()
  62428. {
  62429. closeButtonPressed();
  62430. }
  62431. END_JUCE_NAMESPACE
  62432. /*** End of inlined file: juce_DocumentWindow.cpp ***/
  62433. /*** Start of inlined file: juce_ResizableWindow.cpp ***/
  62434. BEGIN_JUCE_NAMESPACE
  62435. ResizableWindow::ResizableWindow (const String& name,
  62436. const bool addToDesktop_)
  62437. : TopLevelWindow (name, addToDesktop_),
  62438. resizeToFitContent (false),
  62439. fullscreen (false),
  62440. lastNonFullScreenPos (50, 50, 256, 256),
  62441. constrainer (0)
  62442. #ifdef JUCE_DEBUG
  62443. , hasBeenResized (false)
  62444. #endif
  62445. {
  62446. defaultConstrainer.setMinimumOnscreenAmounts (0x10000, 16, 24, 16);
  62447. lastNonFullScreenPos.setBounds (50, 50, 256, 256);
  62448. if (addToDesktop_)
  62449. Component::addToDesktop (getDesktopWindowStyleFlags());
  62450. }
  62451. ResizableWindow::ResizableWindow (const String& name,
  62452. const Colour& backgroundColour_,
  62453. const bool addToDesktop_)
  62454. : TopLevelWindow (name, addToDesktop_),
  62455. resizeToFitContent (false),
  62456. fullscreen (false),
  62457. lastNonFullScreenPos (50, 50, 256, 256),
  62458. constrainer (0)
  62459. #ifdef JUCE_DEBUG
  62460. , hasBeenResized (false)
  62461. #endif
  62462. {
  62463. setBackgroundColour (backgroundColour_);
  62464. defaultConstrainer.setMinimumOnscreenAmounts (0x10000, 16, 24, 16);
  62465. if (addToDesktop_)
  62466. Component::addToDesktop (getDesktopWindowStyleFlags());
  62467. }
  62468. ResizableWindow::~ResizableWindow()
  62469. {
  62470. resizableCorner = 0;
  62471. resizableBorder = 0;
  62472. contentComponent = 0;
  62473. // have you been adding your own components directly to this window..? tut tut tut.
  62474. // Read the instructions for using a ResizableWindow!
  62475. jassert (getNumChildComponents() == 0);
  62476. }
  62477. int ResizableWindow::getDesktopWindowStyleFlags() const
  62478. {
  62479. int flags = TopLevelWindow::getDesktopWindowStyleFlags();
  62480. if (isResizable() && (flags & ComponentPeer::windowHasTitleBar) != 0)
  62481. flags |= ComponentPeer::windowIsResizable;
  62482. return flags;
  62483. }
  62484. void ResizableWindow::setContentComponent (Component* const newContentComponent,
  62485. const bool deleteOldOne,
  62486. const bool resizeToFit)
  62487. {
  62488. resizeToFitContent = resizeToFit;
  62489. if (newContentComponent != (Component*) contentComponent)
  62490. {
  62491. if (! deleteOldOne)
  62492. removeChildComponent (contentComponent.release());
  62493. contentComponent = newContentComponent;
  62494. Component::addAndMakeVisible (contentComponent);
  62495. }
  62496. if (resizeToFit)
  62497. childBoundsChanged (contentComponent);
  62498. resized(); // must always be called to position the new content comp
  62499. }
  62500. void ResizableWindow::setContentComponentSize (int width, int height)
  62501. {
  62502. jassert (width > 0 && height > 0); // not a great idea to give it a zero size..
  62503. const BorderSize border (getContentComponentBorder());
  62504. setSize (width + border.getLeftAndRight(),
  62505. height + border.getTopAndBottom());
  62506. }
  62507. const BorderSize ResizableWindow::getBorderThickness()
  62508. {
  62509. return BorderSize (isUsingNativeTitleBar() ? 0 : ((resizableBorder != 0 && ! isFullScreen()) ? 5 : 3));
  62510. }
  62511. const BorderSize ResizableWindow::getContentComponentBorder()
  62512. {
  62513. return getBorderThickness();
  62514. }
  62515. void ResizableWindow::moved()
  62516. {
  62517. updateLastPos();
  62518. }
  62519. void ResizableWindow::visibilityChanged()
  62520. {
  62521. TopLevelWindow::visibilityChanged();
  62522. updateLastPos();
  62523. }
  62524. void ResizableWindow::resized()
  62525. {
  62526. if (resizableBorder != 0)
  62527. {
  62528. resizableBorder->setVisible (! isFullScreen());
  62529. resizableBorder->setBorderThickness (getBorderThickness());
  62530. resizableBorder->setSize (getWidth(), getHeight());
  62531. resizableBorder->toBack();
  62532. }
  62533. if (resizableCorner != 0)
  62534. {
  62535. resizableCorner->setVisible (! isFullScreen());
  62536. const int resizerSize = 18;
  62537. resizableCorner->setBounds (getWidth() - resizerSize,
  62538. getHeight() - resizerSize,
  62539. resizerSize, resizerSize);
  62540. }
  62541. if (contentComponent != 0)
  62542. contentComponent->setBoundsInset (getContentComponentBorder());
  62543. updateLastPos();
  62544. #ifdef JUCE_DEBUG
  62545. hasBeenResized = true;
  62546. #endif
  62547. }
  62548. void ResizableWindow::childBoundsChanged (Component* child)
  62549. {
  62550. if ((child == contentComponent) && (child != 0) && resizeToFitContent)
  62551. {
  62552. // not going to look very good if this component has a zero size..
  62553. jassert (child->getWidth() > 0);
  62554. jassert (child->getHeight() > 0);
  62555. const BorderSize borders (getContentComponentBorder());
  62556. setSize (child->getWidth() + borders.getLeftAndRight(),
  62557. child->getHeight() + borders.getTopAndBottom());
  62558. }
  62559. }
  62560. void ResizableWindow::activeWindowStatusChanged()
  62561. {
  62562. const BorderSize borders (getContentComponentBorder());
  62563. repaint (0, 0, getWidth(), borders.getTop());
  62564. repaint (0, borders.getTop(), borders.getLeft(), getHeight() - borders.getBottom() - borders.getTop());
  62565. repaint (0, getHeight() - borders.getBottom(), getWidth(), borders.getBottom());
  62566. repaint (getWidth() - borders.getRight(), borders.getTop(), borders.getRight(), getHeight() - borders.getBottom() - borders.getTop());
  62567. }
  62568. void ResizableWindow::setResizable (const bool shouldBeResizable,
  62569. const bool useBottomRightCornerResizer)
  62570. {
  62571. if (shouldBeResizable)
  62572. {
  62573. if (useBottomRightCornerResizer)
  62574. {
  62575. resizableBorder = 0;
  62576. if (resizableCorner == 0)
  62577. {
  62578. Component::addChildComponent (resizableCorner = new ResizableCornerComponent (this, constrainer));
  62579. resizableCorner->setAlwaysOnTop (true);
  62580. }
  62581. }
  62582. else
  62583. {
  62584. resizableCorner = 0;
  62585. if (resizableBorder == 0)
  62586. Component::addChildComponent (resizableBorder = new ResizableBorderComponent (this, constrainer));
  62587. }
  62588. }
  62589. else
  62590. {
  62591. resizableCorner = 0;
  62592. resizableBorder = 0;
  62593. }
  62594. if (isUsingNativeTitleBar())
  62595. recreateDesktopWindow();
  62596. childBoundsChanged (contentComponent);
  62597. resized();
  62598. }
  62599. bool ResizableWindow::isResizable() const throw()
  62600. {
  62601. return resizableCorner != 0
  62602. || resizableBorder != 0;
  62603. }
  62604. void ResizableWindow::setResizeLimits (const int newMinimumWidth,
  62605. const int newMinimumHeight,
  62606. const int newMaximumWidth,
  62607. const int newMaximumHeight) throw()
  62608. {
  62609. // if you've set up a custom constrainer then these settings won't have any effect..
  62610. jassert (constrainer == &defaultConstrainer || constrainer == 0);
  62611. if (constrainer == 0)
  62612. setConstrainer (&defaultConstrainer);
  62613. defaultConstrainer.setSizeLimits (newMinimumWidth, newMinimumHeight,
  62614. newMaximumWidth, newMaximumHeight);
  62615. setBoundsConstrained (getBounds());
  62616. }
  62617. void ResizableWindow::setConstrainer (ComponentBoundsConstrainer* newConstrainer)
  62618. {
  62619. if (constrainer != newConstrainer)
  62620. {
  62621. constrainer = newConstrainer;
  62622. const bool useBottomRightCornerResizer = resizableCorner != 0;
  62623. const bool shouldBeResizable = useBottomRightCornerResizer || resizableBorder != 0;
  62624. resizableCorner = 0;
  62625. resizableBorder = 0;
  62626. setResizable (shouldBeResizable, useBottomRightCornerResizer);
  62627. ComponentPeer* const peer = getPeer();
  62628. if (peer != 0)
  62629. peer->setConstrainer (newConstrainer);
  62630. }
  62631. }
  62632. void ResizableWindow::setBoundsConstrained (const Rectangle<int>& bounds)
  62633. {
  62634. if (constrainer != 0)
  62635. constrainer->setBoundsForComponent (this, bounds, false, false, false, false);
  62636. else
  62637. setBounds (bounds);
  62638. }
  62639. void ResizableWindow::paint (Graphics& g)
  62640. {
  62641. getLookAndFeel().fillResizableWindowBackground (g, getWidth(), getHeight(),
  62642. getBorderThickness(), *this);
  62643. if (! isFullScreen())
  62644. {
  62645. getLookAndFeel().drawResizableWindowBorder (g, getWidth(), getHeight(),
  62646. getBorderThickness(), *this);
  62647. }
  62648. #ifdef JUCE_DEBUG
  62649. /* If this fails, then you've probably written a subclass with a resized()
  62650. callback but forgotten to make it call its parent class's resized() method.
  62651. It's important when you override methods like resized(), moved(),
  62652. etc., that you make sure the base class methods also get called.
  62653. Of course you shouldn't really be overriding ResizableWindow::resized() anyway,
  62654. because your content should all be inside the content component - and it's the
  62655. content component's resized() method that you should be using to do your
  62656. layout.
  62657. */
  62658. jassert (hasBeenResized || (getWidth() == 0 && getHeight() == 0));
  62659. #endif
  62660. }
  62661. void ResizableWindow::lookAndFeelChanged()
  62662. {
  62663. resized();
  62664. if (isOnDesktop())
  62665. {
  62666. Component::addToDesktop (getDesktopWindowStyleFlags());
  62667. ComponentPeer* const peer = getPeer();
  62668. if (peer != 0)
  62669. peer->setConstrainer (constrainer);
  62670. }
  62671. }
  62672. const Colour ResizableWindow::getBackgroundColour() const throw()
  62673. {
  62674. return findColour (backgroundColourId, false);
  62675. }
  62676. void ResizableWindow::setBackgroundColour (const Colour& newColour)
  62677. {
  62678. Colour backgroundColour (newColour);
  62679. if (! Desktop::canUseSemiTransparentWindows())
  62680. backgroundColour = newColour.withAlpha (1.0f);
  62681. setColour (backgroundColourId, backgroundColour);
  62682. setOpaque (backgroundColour.isOpaque());
  62683. repaint();
  62684. }
  62685. bool ResizableWindow::isFullScreen() const
  62686. {
  62687. if (isOnDesktop())
  62688. {
  62689. ComponentPeer* const peer = getPeer();
  62690. return peer != 0 && peer->isFullScreen();
  62691. }
  62692. return fullscreen;
  62693. }
  62694. void ResizableWindow::setFullScreen (const bool shouldBeFullScreen)
  62695. {
  62696. if (shouldBeFullScreen != isFullScreen())
  62697. {
  62698. updateLastPos();
  62699. fullscreen = shouldBeFullScreen;
  62700. if (isOnDesktop())
  62701. {
  62702. ComponentPeer* const peer = getPeer();
  62703. if (peer != 0)
  62704. {
  62705. // keep a copy of this intact in case the real one gets messed-up while we're un-maximising
  62706. const Rectangle<int> lastPos (lastNonFullScreenPos);
  62707. peer->setFullScreen (shouldBeFullScreen);
  62708. if (! shouldBeFullScreen)
  62709. setBounds (lastPos);
  62710. }
  62711. else
  62712. {
  62713. jassertfalse
  62714. }
  62715. }
  62716. else
  62717. {
  62718. if (shouldBeFullScreen)
  62719. setBounds (0, 0, getParentWidth(), getParentHeight());
  62720. else
  62721. setBounds (lastNonFullScreenPos);
  62722. }
  62723. resized();
  62724. }
  62725. }
  62726. bool ResizableWindow::isMinimised() const
  62727. {
  62728. ComponentPeer* const peer = getPeer();
  62729. return (peer != 0) && peer->isMinimised();
  62730. }
  62731. void ResizableWindow::setMinimised (const bool shouldMinimise)
  62732. {
  62733. if (shouldMinimise != isMinimised())
  62734. {
  62735. ComponentPeer* const peer = getPeer();
  62736. if (peer != 0)
  62737. {
  62738. updateLastPos();
  62739. peer->setMinimised (shouldMinimise);
  62740. }
  62741. else
  62742. {
  62743. jassertfalse
  62744. }
  62745. }
  62746. }
  62747. void ResizableWindow::updateLastPos()
  62748. {
  62749. if (isShowing() && ! (isFullScreen() || isMinimised()))
  62750. {
  62751. lastNonFullScreenPos = getBounds();
  62752. }
  62753. }
  62754. void ResizableWindow::parentSizeChanged()
  62755. {
  62756. if (isFullScreen() && getParentComponent() != 0)
  62757. {
  62758. setBounds (0, 0, getParentWidth(), getParentHeight());
  62759. }
  62760. }
  62761. const String ResizableWindow::getWindowStateAsString()
  62762. {
  62763. updateLastPos();
  62764. return (isFullScreen() ? "fs " : "") + lastNonFullScreenPos.toString();
  62765. }
  62766. bool ResizableWindow::restoreWindowStateFromString (const String& s)
  62767. {
  62768. StringArray tokens;
  62769. tokens.addTokens (s, false);
  62770. tokens.removeEmptyStrings();
  62771. tokens.trim();
  62772. const bool fs = tokens[0].startsWithIgnoreCase (T("fs"));
  62773. const int firstCoord = fs ? 1 : 0;
  62774. if (tokens.size() != firstCoord + 4)
  62775. return false;
  62776. Rectangle<int> newPos (tokens[firstCoord].getIntValue(),
  62777. tokens[firstCoord + 1].getIntValue(),
  62778. tokens[firstCoord + 2].getIntValue(),
  62779. tokens[firstCoord + 3].getIntValue());
  62780. if (newPos.isEmpty())
  62781. return false;
  62782. const Rectangle<int> screen (Desktop::getInstance().getMonitorAreaContaining (newPos.getCentreX(),
  62783. newPos.getCentreY()));
  62784. ComponentPeer* const peer = isOnDesktop() ? getPeer() : 0;
  62785. if (peer != 0)
  62786. peer->getFrameSize().addTo (newPos);
  62787. if (! screen.contains (newPos))
  62788. {
  62789. newPos.setSize (jmin (newPos.getWidth(), screen.getWidth()),
  62790. jmin (newPos.getHeight(), screen.getHeight()));
  62791. newPos.setPosition (jlimit (screen.getX(), screen.getRight() - newPos.getWidth(), newPos.getX()),
  62792. jlimit (screen.getY(), screen.getBottom() - newPos.getHeight(), newPos.getY()));
  62793. }
  62794. if (peer != 0)
  62795. {
  62796. peer->getFrameSize().subtractFrom (newPos);
  62797. peer->setNonFullScreenBounds (newPos);
  62798. }
  62799. lastNonFullScreenPos = newPos;
  62800. setFullScreen (fs);
  62801. if (! fs)
  62802. setBoundsConstrained (newPos);
  62803. return true;
  62804. }
  62805. void ResizableWindow::mouseDown (const MouseEvent&)
  62806. {
  62807. if (! isFullScreen())
  62808. dragger.startDraggingComponent (this, constrainer);
  62809. }
  62810. void ResizableWindow::mouseDrag (const MouseEvent& e)
  62811. {
  62812. if (! isFullScreen())
  62813. dragger.dragComponent (this, e);
  62814. }
  62815. #ifdef JUCE_DEBUG
  62816. void ResizableWindow::addChildComponent (Component* const child, int zOrder)
  62817. {
  62818. /* Agh! You shouldn't add components directly to a ResizableWindow - this class
  62819. manages its child components automatically, and if you add your own it'll cause
  62820. trouble. Instead, use setContentComponent() to give it a component which
  62821. will be automatically resized and kept in the right place - then you can add
  62822. subcomponents to the content comp. See the notes for the ResizableWindow class
  62823. for more info.
  62824. If you really know what you're doing and want to avoid this assertion, just call
  62825. Component::addChildComponent directly.
  62826. */
  62827. jassertfalse
  62828. Component::addChildComponent (child, zOrder);
  62829. }
  62830. void ResizableWindow::addAndMakeVisible (Component* const child, int zOrder)
  62831. {
  62832. /* Agh! You shouldn't add components directly to a ResizableWindow - this class
  62833. manages its child components automatically, and if you add your own it'll cause
  62834. trouble. Instead, use setContentComponent() to give it a component which
  62835. will be automatically resized and kept in the right place - then you can add
  62836. subcomponents to the content comp. See the notes for the ResizableWindow class
  62837. for more info.
  62838. If you really know what you're doing and want to avoid this assertion, just call
  62839. Component::addAndMakeVisible directly.
  62840. */
  62841. jassertfalse
  62842. Component::addAndMakeVisible (child, zOrder);
  62843. }
  62844. #endif
  62845. END_JUCE_NAMESPACE
  62846. /*** End of inlined file: juce_ResizableWindow.cpp ***/
  62847. /*** Start of inlined file: juce_SplashScreen.cpp ***/
  62848. BEGIN_JUCE_NAMESPACE
  62849. SplashScreen::SplashScreen()
  62850. : backgroundImage (0)
  62851. {
  62852. setOpaque (true);
  62853. }
  62854. SplashScreen::~SplashScreen()
  62855. {
  62856. ImageCache::releaseOrDelete (backgroundImage);
  62857. }
  62858. void SplashScreen::show (const String& title,
  62859. Image* const backgroundImage_,
  62860. const int minimumTimeToDisplayFor,
  62861. const bool useDropShadow,
  62862. const bool removeOnMouseClick)
  62863. {
  62864. backgroundImage = backgroundImage_;
  62865. jassert (backgroundImage_ != 0);
  62866. if (backgroundImage_ != 0)
  62867. {
  62868. setOpaque (! backgroundImage_->hasAlphaChannel());
  62869. show (title,
  62870. backgroundImage_->getWidth(),
  62871. backgroundImage_->getHeight(),
  62872. minimumTimeToDisplayFor,
  62873. useDropShadow,
  62874. removeOnMouseClick);
  62875. }
  62876. }
  62877. void SplashScreen::show (const String& title,
  62878. const int width,
  62879. const int height,
  62880. const int minimumTimeToDisplayFor,
  62881. const bool useDropShadow,
  62882. const bool removeOnMouseClick)
  62883. {
  62884. setName (title);
  62885. setAlwaysOnTop (true);
  62886. setVisible (true);
  62887. centreWithSize (width, height);
  62888. addToDesktop (useDropShadow ? ComponentPeer::windowHasDropShadow : 0);
  62889. toFront (false);
  62890. MessageManager::getInstance()->runDispatchLoopUntil (300);
  62891. repaint();
  62892. originalClickCounter = removeOnMouseClick
  62893. ? Desktop::getMouseButtonClickCounter()
  62894. : std::numeric_limits<int>::max();
  62895. earliestTimeToDelete = Time::getCurrentTime() + RelativeTime::milliseconds (minimumTimeToDisplayFor);
  62896. startTimer (50);
  62897. }
  62898. void SplashScreen::paint (Graphics& g)
  62899. {
  62900. if (backgroundImage != 0)
  62901. {
  62902. g.setOpacity (1.0f);
  62903. g.drawImage (backgroundImage,
  62904. 0, 0, getWidth(), getHeight(),
  62905. 0, 0, backgroundImage->getWidth(), backgroundImage->getHeight());
  62906. }
  62907. }
  62908. void SplashScreen::timerCallback()
  62909. {
  62910. if (Time::getCurrentTime() > earliestTimeToDelete
  62911. || Desktop::getMouseButtonClickCounter() > originalClickCounter)
  62912. {
  62913. delete this;
  62914. }
  62915. }
  62916. END_JUCE_NAMESPACE
  62917. /*** End of inlined file: juce_SplashScreen.cpp ***/
  62918. /*** Start of inlined file: juce_ThreadWithProgressWindow.cpp ***/
  62919. BEGIN_JUCE_NAMESPACE
  62920. ThreadWithProgressWindow::ThreadWithProgressWindow (const String& title,
  62921. const bool hasProgressBar,
  62922. const bool hasCancelButton,
  62923. const int timeOutMsWhenCancelling_,
  62924. const String& cancelButtonText)
  62925. : Thread ("Juce Progress Window"),
  62926. progress (0.0),
  62927. timeOutMsWhenCancelling (timeOutMsWhenCancelling_)
  62928. {
  62929. alertWindow = LookAndFeel::getDefaultLookAndFeel()
  62930. .createAlertWindow (title, String::empty, cancelButtonText,
  62931. String::empty, String::empty,
  62932. AlertWindow::NoIcon, hasCancelButton ? 1 : 0, 0);
  62933. if (hasProgressBar)
  62934. alertWindow->addProgressBarComponent (progress);
  62935. }
  62936. ThreadWithProgressWindow::~ThreadWithProgressWindow()
  62937. {
  62938. stopThread (timeOutMsWhenCancelling);
  62939. }
  62940. bool ThreadWithProgressWindow::runThread (const int priority)
  62941. {
  62942. startThread (priority);
  62943. startTimer (100);
  62944. {
  62945. const ScopedLock sl (messageLock);
  62946. alertWindow->setMessage (message);
  62947. }
  62948. const bool finishedNaturally = alertWindow->runModalLoop() != 0;
  62949. stopThread (timeOutMsWhenCancelling);
  62950. alertWindow->setVisible (false);
  62951. return finishedNaturally;
  62952. }
  62953. void ThreadWithProgressWindow::setProgress (const double newProgress)
  62954. {
  62955. progress = newProgress;
  62956. }
  62957. void ThreadWithProgressWindow::setStatusMessage (const String& newStatusMessage)
  62958. {
  62959. const ScopedLock sl (messageLock);
  62960. message = newStatusMessage;
  62961. }
  62962. void ThreadWithProgressWindow::timerCallback()
  62963. {
  62964. if (! isThreadRunning())
  62965. {
  62966. // thread has finished normally..
  62967. alertWindow->exitModalState (1);
  62968. alertWindow->setVisible (false);
  62969. }
  62970. else
  62971. {
  62972. const ScopedLock sl (messageLock);
  62973. alertWindow->setMessage (message);
  62974. }
  62975. }
  62976. END_JUCE_NAMESPACE
  62977. /*** End of inlined file: juce_ThreadWithProgressWindow.cpp ***/
  62978. /*** Start of inlined file: juce_TooltipWindow.cpp ***/
  62979. BEGIN_JUCE_NAMESPACE
  62980. TooltipWindow::TooltipWindow (Component* const parentComponent,
  62981. const int millisecondsBeforeTipAppears_)
  62982. : Component ("tooltip"),
  62983. millisecondsBeforeTipAppears (millisecondsBeforeTipAppears_),
  62984. mouseX (0),
  62985. mouseY (0),
  62986. lastHideTime (0),
  62987. lastComponentUnderMouse (0),
  62988. changedCompsSinceShown (true)
  62989. {
  62990. startTimer (123);
  62991. setAlwaysOnTop (true);
  62992. setOpaque (true);
  62993. if (parentComponent != 0)
  62994. parentComponent->addChildComponent (this);
  62995. }
  62996. TooltipWindow::~TooltipWindow()
  62997. {
  62998. hide();
  62999. }
  63000. void TooltipWindow::setMillisecondsBeforeTipAppears (const int newTimeMs) throw()
  63001. {
  63002. millisecondsBeforeTipAppears = newTimeMs;
  63003. }
  63004. void TooltipWindow::paint (Graphics& g)
  63005. {
  63006. getLookAndFeel().drawTooltip (g, tipShowing, getWidth(), getHeight());
  63007. }
  63008. void TooltipWindow::mouseEnter (const MouseEvent&)
  63009. {
  63010. hide();
  63011. }
  63012. void TooltipWindow::showFor (const String& tip)
  63013. {
  63014. jassert (tip.isNotEmpty());
  63015. tipShowing = tip;
  63016. int mx, my;
  63017. Desktop::getMousePosition (mx, my);
  63018. if (getParentComponent() != 0)
  63019. getParentComponent()->globalPositionToRelative (mx, my);
  63020. int x, y, w, h;
  63021. getLookAndFeel().getTooltipSize (tip, w, h);
  63022. if (mx > getParentWidth() / 2)
  63023. x = mx - (w + 12);
  63024. else
  63025. x = mx + 24;
  63026. if (my > getParentHeight() / 2)
  63027. y = my - (h + 6);
  63028. else
  63029. y = my + 6;
  63030. setBounds (x, y, w, h);
  63031. setVisible (true);
  63032. if (getParentComponent() == 0)
  63033. {
  63034. addToDesktop (ComponentPeer::windowHasDropShadow
  63035. | ComponentPeer::windowIsTemporary
  63036. | ComponentPeer::windowIgnoresKeyPresses);
  63037. }
  63038. toFront (false);
  63039. }
  63040. const String TooltipWindow::getTipFor (Component* const c)
  63041. {
  63042. if (c->isValidComponent()
  63043. && Process::isForegroundProcess()
  63044. && ! Component::isMouseButtonDownAnywhere())
  63045. {
  63046. TooltipClient* const ttc = dynamic_cast <TooltipClient*> (c);
  63047. if (ttc != 0 && ! c->isCurrentlyBlockedByAnotherModalComponent())
  63048. return ttc->getTooltip();
  63049. }
  63050. return String::empty;
  63051. }
  63052. void TooltipWindow::hide()
  63053. {
  63054. tipShowing = String::empty;
  63055. removeFromDesktop();
  63056. setVisible (false);
  63057. }
  63058. void TooltipWindow::timerCallback()
  63059. {
  63060. const unsigned int now = Time::getApproximateMillisecondCounter();
  63061. Component* const newComp = Component::getComponentUnderMouse();
  63062. const String newTip (getTipFor (newComp));
  63063. const bool tipChanged = (newTip != lastTipUnderMouse || newComp != lastComponentUnderMouse);
  63064. lastComponentUnderMouse = newComp;
  63065. lastTipUnderMouse = newTip;
  63066. const int clickCount = Desktop::getInstance().getMouseButtonClickCounter();
  63067. const bool mouseWasClicked = clickCount > mouseClicks;
  63068. mouseClicks = clickCount;
  63069. int mx, my;
  63070. Desktop::getMousePosition (mx, my);
  63071. const bool mouseMovedQuickly = (abs (mx - mouseX) + abs (my - mouseY) > 12);
  63072. mouseX = mx;
  63073. mouseY = my;
  63074. if (tipChanged || mouseWasClicked || mouseMovedQuickly)
  63075. lastCompChangeTime = now;
  63076. if (isVisible() || now < lastHideTime + 500)
  63077. {
  63078. // if a tip is currently visible (or has just disappeared), update to a new one
  63079. // immediately if needed..
  63080. if (newComp == 0 || mouseWasClicked || newTip.isEmpty())
  63081. {
  63082. if (isVisible())
  63083. {
  63084. lastHideTime = now;
  63085. hide();
  63086. }
  63087. }
  63088. else if (tipChanged)
  63089. {
  63090. showFor (newTip);
  63091. }
  63092. }
  63093. else
  63094. {
  63095. // if there isn't currently a tip, but one is needed, only let it
  63096. // appear after a timeout..
  63097. if (newTip.isNotEmpty()
  63098. && newTip != tipShowing
  63099. && now > lastCompChangeTime + millisecondsBeforeTipAppears)
  63100. {
  63101. showFor (newTip);
  63102. }
  63103. }
  63104. }
  63105. END_JUCE_NAMESPACE
  63106. /*** End of inlined file: juce_TooltipWindow.cpp ***/
  63107. /*** Start of inlined file: juce_TopLevelWindow.cpp ***/
  63108. BEGIN_JUCE_NAMESPACE
  63109. class TopLevelWindowManager : public Timer,
  63110. public DeletedAtShutdown
  63111. {
  63112. public:
  63113. TopLevelWindowManager()
  63114. : currentActive (0)
  63115. {
  63116. }
  63117. ~TopLevelWindowManager()
  63118. {
  63119. clearSingletonInstance();
  63120. }
  63121. juce_DeclareSingleton_SingleThreaded_Minimal (TopLevelWindowManager)
  63122. void timerCallback()
  63123. {
  63124. startTimer (jmin (1731, getTimerInterval() * 2));
  63125. TopLevelWindow* active = 0;
  63126. if (Process::isForegroundProcess())
  63127. {
  63128. active = currentActive;
  63129. Component* const c = Component::getCurrentlyFocusedComponent();
  63130. TopLevelWindow* tlw = dynamic_cast <TopLevelWindow*> (c);
  63131. if (tlw == 0 && c != 0)
  63132. // (unable to use the syntax findParentComponentOfClass <TopLevelWindow> () because of a VC6 compiler bug)
  63133. tlw = c->findParentComponentOfClass ((TopLevelWindow*) 0);
  63134. if (tlw != 0)
  63135. active = tlw;
  63136. }
  63137. if (active != currentActive)
  63138. {
  63139. currentActive = active;
  63140. for (int i = windows.size(); --i >= 0;)
  63141. {
  63142. TopLevelWindow* const tlw = (TopLevelWindow*) windows.getUnchecked (i);
  63143. tlw->setWindowActive (isWindowActive (tlw));
  63144. i = jmin (i, windows.size() - 1);
  63145. }
  63146. Desktop::getInstance().triggerFocusCallback();
  63147. }
  63148. }
  63149. bool addWindow (TopLevelWindow* const w) throw()
  63150. {
  63151. windows.add (w);
  63152. startTimer (10);
  63153. return isWindowActive (w);
  63154. }
  63155. void removeWindow (TopLevelWindow* const w) throw()
  63156. {
  63157. startTimer (10);
  63158. if (currentActive == w)
  63159. currentActive = 0;
  63160. windows.removeValue (w);
  63161. if (windows.size() == 0)
  63162. deleteInstance();
  63163. }
  63164. VoidArray windows;
  63165. private:
  63166. TopLevelWindow* currentActive;
  63167. bool isWindowActive (TopLevelWindow* const tlw) const throw()
  63168. {
  63169. return (tlw == currentActive
  63170. || tlw->isParentOf (currentActive)
  63171. || tlw->hasKeyboardFocus (true))
  63172. && tlw->isShowing();
  63173. }
  63174. TopLevelWindowManager (const TopLevelWindowManager&);
  63175. const TopLevelWindowManager& operator= (const TopLevelWindowManager&);
  63176. };
  63177. juce_ImplementSingleton_SingleThreaded (TopLevelWindowManager)
  63178. void juce_CheckCurrentlyFocusedTopLevelWindow()
  63179. {
  63180. if (TopLevelWindowManager::getInstanceWithoutCreating() != 0)
  63181. TopLevelWindowManager::getInstanceWithoutCreating()->startTimer (20);
  63182. }
  63183. TopLevelWindow::TopLevelWindow (const String& name,
  63184. const bool addToDesktop_)
  63185. : Component (name),
  63186. useDropShadow (true),
  63187. useNativeTitleBar (false),
  63188. windowIsActive_ (false)
  63189. {
  63190. setOpaque (true);
  63191. if (addToDesktop_)
  63192. Component::addToDesktop (getDesktopWindowStyleFlags());
  63193. else
  63194. setDropShadowEnabled (true);
  63195. setWantsKeyboardFocus (true);
  63196. setBroughtToFrontOnMouseClick (true);
  63197. windowIsActive_ = TopLevelWindowManager::getInstance()->addWindow (this);
  63198. }
  63199. TopLevelWindow::~TopLevelWindow()
  63200. {
  63201. shadower = 0;
  63202. TopLevelWindowManager::getInstance()->removeWindow (this);
  63203. }
  63204. void TopLevelWindow::focusOfChildComponentChanged (FocusChangeType)
  63205. {
  63206. if (hasKeyboardFocus (true))
  63207. TopLevelWindowManager::getInstance()->timerCallback();
  63208. else
  63209. TopLevelWindowManager::getInstance()->startTimer (10);
  63210. }
  63211. void TopLevelWindow::setWindowActive (const bool isNowActive) throw()
  63212. {
  63213. if (windowIsActive_ != isNowActive)
  63214. {
  63215. windowIsActive_ = isNowActive;
  63216. activeWindowStatusChanged();
  63217. }
  63218. }
  63219. void TopLevelWindow::activeWindowStatusChanged()
  63220. {
  63221. }
  63222. void TopLevelWindow::parentHierarchyChanged()
  63223. {
  63224. setDropShadowEnabled (useDropShadow);
  63225. }
  63226. void TopLevelWindow::visibilityChanged()
  63227. {
  63228. if (isShowing())
  63229. toFront (true);
  63230. }
  63231. int TopLevelWindow::getDesktopWindowStyleFlags() const
  63232. {
  63233. int flags = ComponentPeer::windowAppearsOnTaskbar;
  63234. if (useDropShadow)
  63235. flags |= ComponentPeer::windowHasDropShadow;
  63236. if (useNativeTitleBar)
  63237. flags |= ComponentPeer::windowHasTitleBar;
  63238. return flags;
  63239. }
  63240. void TopLevelWindow::setDropShadowEnabled (const bool useShadow)
  63241. {
  63242. useDropShadow = useShadow;
  63243. if (isOnDesktop())
  63244. {
  63245. shadower = 0;
  63246. Component::addToDesktop (getDesktopWindowStyleFlags());
  63247. }
  63248. else
  63249. {
  63250. if (useShadow && isOpaque())
  63251. {
  63252. if (shadower == 0)
  63253. {
  63254. shadower = getLookAndFeel().createDropShadowerForComponent (this);
  63255. if (shadower != 0)
  63256. shadower->setOwner (this);
  63257. }
  63258. }
  63259. else
  63260. {
  63261. shadower = 0;
  63262. }
  63263. }
  63264. }
  63265. void TopLevelWindow::setUsingNativeTitleBar (const bool useNativeTitleBar_)
  63266. {
  63267. if (useNativeTitleBar != useNativeTitleBar_)
  63268. {
  63269. useNativeTitleBar = useNativeTitleBar_;
  63270. recreateDesktopWindow();
  63271. sendLookAndFeelChange();
  63272. }
  63273. }
  63274. void TopLevelWindow::recreateDesktopWindow()
  63275. {
  63276. if (isOnDesktop())
  63277. {
  63278. Component::addToDesktop (getDesktopWindowStyleFlags());
  63279. toFront (true);
  63280. }
  63281. }
  63282. void TopLevelWindow::addToDesktop (int windowStyleFlags, void* nativeWindowToAttachTo)
  63283. {
  63284. /* It's not recommended to change the desktop window flags directly for a TopLevelWindow,
  63285. because this class needs to make sure its layout corresponds with settings like whether
  63286. it's got a native title bar or not.
  63287. If you need custom flags for your window, you can override the getDesktopWindowStyleFlags()
  63288. method. If you do this, it's best to call the base class's getDesktopWindowStyleFlags()
  63289. method, then add or remove whatever flags are necessary from this value before returning it.
  63290. */
  63291. jassert ((windowStyleFlags & ~ComponentPeer::windowIsSemiTransparent)
  63292. == (getDesktopWindowStyleFlags() & ~ComponentPeer::windowIsSemiTransparent));
  63293. Component::addToDesktop (windowStyleFlags, nativeWindowToAttachTo);
  63294. if (windowStyleFlags != getDesktopWindowStyleFlags())
  63295. sendLookAndFeelChange();
  63296. }
  63297. void TopLevelWindow::centreAroundComponent (Component* c, const int width, const int height)
  63298. {
  63299. if (c == 0)
  63300. c = TopLevelWindow::getActiveTopLevelWindow();
  63301. if (c == 0)
  63302. {
  63303. centreWithSize (width, height);
  63304. }
  63305. else
  63306. {
  63307. int x = (c->getWidth() - width) / 2;
  63308. int y = (c->getHeight() - height) / 2;
  63309. c->relativePositionToGlobal (x, y);
  63310. Rectangle<int> parentArea (c->getParentMonitorArea());
  63311. if (getParentComponent() != 0)
  63312. {
  63313. getParentComponent()->globalPositionToRelative (x, y);
  63314. parentArea.setBounds (0, 0, getParentWidth(), getParentHeight());
  63315. }
  63316. parentArea.reduce (12, 12);
  63317. setBounds (jlimit (parentArea.getX(), jmax (parentArea.getX(), parentArea.getRight() - width), x),
  63318. jlimit (parentArea.getY(), jmax (parentArea.getY(), parentArea.getBottom() - height), y),
  63319. width, height);
  63320. }
  63321. }
  63322. int TopLevelWindow::getNumTopLevelWindows() throw()
  63323. {
  63324. return TopLevelWindowManager::getInstance()->windows.size();
  63325. }
  63326. TopLevelWindow* TopLevelWindow::getTopLevelWindow (const int index) throw()
  63327. {
  63328. return (TopLevelWindow*) TopLevelWindowManager::getInstance()->windows [index];
  63329. }
  63330. TopLevelWindow* TopLevelWindow::getActiveTopLevelWindow() throw()
  63331. {
  63332. TopLevelWindow* best = 0;
  63333. int bestNumTWLParents = -1;
  63334. for (int i = TopLevelWindow::getNumTopLevelWindows(); --i >= 0;)
  63335. {
  63336. TopLevelWindow* const tlw = TopLevelWindow::getTopLevelWindow (i);
  63337. if (tlw->isActiveWindow())
  63338. {
  63339. int numTWLParents = 0;
  63340. const Component* c = tlw->getParentComponent();
  63341. while (c != 0)
  63342. {
  63343. if (dynamic_cast <const TopLevelWindow*> (c) != 0)
  63344. ++numTWLParents;
  63345. c = c->getParentComponent();
  63346. }
  63347. if (bestNumTWLParents < numTWLParents)
  63348. {
  63349. best = tlw;
  63350. bestNumTWLParents = numTWLParents;
  63351. }
  63352. }
  63353. }
  63354. return best;
  63355. }
  63356. END_JUCE_NAMESPACE
  63357. /*** End of inlined file: juce_TopLevelWindow.cpp ***/
  63358. /*** Start of inlined file: juce_Colour.cpp ***/
  63359. BEGIN_JUCE_NAMESPACE
  63360. static uint8 floatAlphaToInt (const float alpha)
  63361. {
  63362. return (uint8) jlimit (0, 0xff, roundToInt (alpha * 255.0f));
  63363. }
  63364. static const float oneOver255 = 1.0f / 255.0f;
  63365. Colour::Colour() throw()
  63366. : argb (0)
  63367. {
  63368. }
  63369. Colour::Colour (const Colour& other) throw()
  63370. : argb (other.argb)
  63371. {
  63372. }
  63373. const Colour& Colour::operator= (const Colour& other) throw()
  63374. {
  63375. argb = other.argb;
  63376. return *this;
  63377. }
  63378. bool Colour::operator== (const Colour& other) const throw()
  63379. {
  63380. return argb.getARGB() == other.argb.getARGB();
  63381. }
  63382. bool Colour::operator!= (const Colour& other) const throw()
  63383. {
  63384. return argb.getARGB() != other.argb.getARGB();
  63385. }
  63386. Colour::Colour (const uint32 argb_) throw()
  63387. : argb (argb_)
  63388. {
  63389. }
  63390. Colour::Colour (const uint8 red,
  63391. const uint8 green,
  63392. const uint8 blue) throw()
  63393. {
  63394. argb.setARGB (0xff, red, green, blue);
  63395. }
  63396. const Colour Colour::fromRGB (const uint8 red,
  63397. const uint8 green,
  63398. const uint8 blue) throw()
  63399. {
  63400. return Colour (red, green, blue);
  63401. }
  63402. Colour::Colour (const uint8 red,
  63403. const uint8 green,
  63404. const uint8 blue,
  63405. const uint8 alpha) throw()
  63406. {
  63407. argb.setARGB (alpha, red, green, blue);
  63408. }
  63409. const Colour Colour::fromRGBA (const uint8 red,
  63410. const uint8 green,
  63411. const uint8 blue,
  63412. const uint8 alpha) throw()
  63413. {
  63414. return Colour (red, green, blue, alpha);
  63415. }
  63416. Colour::Colour (const uint8 red,
  63417. const uint8 green,
  63418. const uint8 blue,
  63419. const float alpha) throw()
  63420. {
  63421. argb.setARGB (floatAlphaToInt (alpha), red, green, blue);
  63422. }
  63423. const Colour Colour::fromRGBAFloat (const uint8 red,
  63424. const uint8 green,
  63425. const uint8 blue,
  63426. const float alpha) throw()
  63427. {
  63428. return Colour (red, green, blue, alpha);
  63429. }
  63430. static void convertHSBtoRGB (float h, float s, float v,
  63431. uint8& r, uint8& g, uint8& b) throw()
  63432. {
  63433. v = jlimit (0.0f, 1.0f, v);
  63434. v *= 255.0f;
  63435. const uint8 intV = (uint8) roundToInt (v);
  63436. if (s <= 0)
  63437. {
  63438. r = intV;
  63439. g = intV;
  63440. b = intV;
  63441. }
  63442. else
  63443. {
  63444. s = jmin (1.0f, s);
  63445. h = jlimit (0.0f, 1.0f, h);
  63446. h = (h - floorf (h)) * 6.0f + 0.00001f; // need a small adjustment to compensate for rounding errors
  63447. const float f = h - floorf (h);
  63448. const uint8 x = (uint8) roundToInt (v * (1.0f - s));
  63449. const float y = v * (1.0f - s * f);
  63450. const float z = v * (1.0f - (s * (1.0f - f)));
  63451. if (h < 1.0f)
  63452. {
  63453. r = intV;
  63454. g = (uint8) roundToInt (z);
  63455. b = x;
  63456. }
  63457. else if (h < 2.0f)
  63458. {
  63459. r = (uint8) roundToInt (y);
  63460. g = intV;
  63461. b = x;
  63462. }
  63463. else if (h < 3.0f)
  63464. {
  63465. r = x;
  63466. g = intV;
  63467. b = (uint8) roundToInt (z);
  63468. }
  63469. else if (h < 4.0f)
  63470. {
  63471. r = x;
  63472. g = (uint8) roundToInt (y);
  63473. b = intV;
  63474. }
  63475. else if (h < 5.0f)
  63476. {
  63477. r = (uint8) roundToInt (z);
  63478. g = x;
  63479. b = intV;
  63480. }
  63481. else if (h < 6.0f)
  63482. {
  63483. r = intV;
  63484. g = x;
  63485. b = (uint8) roundToInt (y);
  63486. }
  63487. else
  63488. {
  63489. r = 0;
  63490. g = 0;
  63491. b = 0;
  63492. }
  63493. }
  63494. }
  63495. Colour::Colour (const float hue,
  63496. const float saturation,
  63497. const float brightness,
  63498. const float alpha) throw()
  63499. {
  63500. uint8 r = getRed(), g = getGreen(), b = getBlue();
  63501. convertHSBtoRGB (hue, saturation, brightness, r, g, b);
  63502. argb.setARGB (floatAlphaToInt (alpha), r, g, b);
  63503. }
  63504. const Colour Colour::fromHSV (const float hue,
  63505. const float saturation,
  63506. const float brightness,
  63507. const float alpha) throw()
  63508. {
  63509. return Colour (hue, saturation, brightness, alpha);
  63510. }
  63511. Colour::Colour (const float hue,
  63512. const float saturation,
  63513. const float brightness,
  63514. const uint8 alpha) throw()
  63515. {
  63516. uint8 r = getRed(), g = getGreen(), b = getBlue();
  63517. convertHSBtoRGB (hue, saturation, brightness, r, g, b);
  63518. argb.setARGB (alpha, r, g, b);
  63519. }
  63520. Colour::~Colour() throw()
  63521. {
  63522. }
  63523. const PixelARGB Colour::getPixelARGB() const throw()
  63524. {
  63525. PixelARGB p (argb);
  63526. p.premultiply();
  63527. return p;
  63528. }
  63529. uint32 Colour::getARGB() const throw()
  63530. {
  63531. return argb.getARGB();
  63532. }
  63533. bool Colour::isTransparent() const throw()
  63534. {
  63535. return getAlpha() == 0;
  63536. }
  63537. bool Colour::isOpaque() const throw()
  63538. {
  63539. return getAlpha() == 0xff;
  63540. }
  63541. const Colour Colour::withAlpha (const uint8 newAlpha) const throw()
  63542. {
  63543. PixelARGB newCol (argb);
  63544. newCol.setAlpha (newAlpha);
  63545. return Colour (newCol.getARGB());
  63546. }
  63547. const Colour Colour::withAlpha (const float newAlpha) const throw()
  63548. {
  63549. jassert (newAlpha >= 0 && newAlpha <= 1.0f);
  63550. PixelARGB newCol (argb);
  63551. newCol.setAlpha (floatAlphaToInt (newAlpha));
  63552. return Colour (newCol.getARGB());
  63553. }
  63554. const Colour Colour::withMultipliedAlpha (const float alphaMultiplier) const throw()
  63555. {
  63556. jassert (alphaMultiplier >= 0);
  63557. PixelARGB newCol (argb);
  63558. newCol.setAlpha ((uint8) jmin (0xff, roundToInt (alphaMultiplier * newCol.getAlpha())));
  63559. return Colour (newCol.getARGB());
  63560. }
  63561. const Colour Colour::overlaidWith (const Colour& src) const throw()
  63562. {
  63563. const int destAlpha = getAlpha();
  63564. if (destAlpha > 0)
  63565. {
  63566. const int invA = 0xff - (int) src.getAlpha();
  63567. const int resA = 0xff - (((0xff - destAlpha) * invA) >> 8);
  63568. if (resA > 0)
  63569. {
  63570. const int da = (invA * destAlpha) / resA;
  63571. return Colour ((uint8) (src.getRed() + ((((int) getRed() - src.getRed()) * da) >> 8)),
  63572. (uint8) (src.getGreen() + ((((int) getGreen() - src.getGreen()) * da) >> 8)),
  63573. (uint8) (src.getBlue() + ((((int) getBlue() - src.getBlue()) * da) >> 8)),
  63574. (uint8) resA);
  63575. }
  63576. return *this;
  63577. }
  63578. else
  63579. {
  63580. return src;
  63581. }
  63582. }
  63583. const Colour Colour::interpolatedWith (const Colour& other, float proportionOfOther) const throw()
  63584. {
  63585. if (proportionOfOther <= 0)
  63586. return *this;
  63587. if (proportionOfOther >= 1.0f)
  63588. return other;
  63589. PixelARGB c1 (getPixelARGB());
  63590. const PixelARGB c2 (other.getPixelARGB());
  63591. c1.tween (c2, roundToInt (proportionOfOther * 255.0f));
  63592. c1.unpremultiply();
  63593. return Colour (c1.getARGB());
  63594. }
  63595. float Colour::getFloatRed() const throw()
  63596. {
  63597. return getRed() * oneOver255;
  63598. }
  63599. float Colour::getFloatGreen() const throw()
  63600. {
  63601. return getGreen() * oneOver255;
  63602. }
  63603. float Colour::getFloatBlue() const throw()
  63604. {
  63605. return getBlue() * oneOver255;
  63606. }
  63607. float Colour::getFloatAlpha() const throw()
  63608. {
  63609. return getAlpha() * oneOver255;
  63610. }
  63611. void Colour::getHSB (float& h, float& s, float& v) const throw()
  63612. {
  63613. const int r = getRed();
  63614. const int g = getGreen();
  63615. const int b = getBlue();
  63616. const int hi = jmax (r, g, b);
  63617. const int lo = jmin (r, g, b);
  63618. if (hi != 0)
  63619. {
  63620. s = (hi - lo) / (float) hi;
  63621. if (s != 0)
  63622. {
  63623. const float invDiff = 1.0f / (hi - lo);
  63624. const float red = (hi - r) * invDiff;
  63625. const float green = (hi - g) * invDiff;
  63626. const float blue = (hi - b) * invDiff;
  63627. if (r == hi)
  63628. h = blue - green;
  63629. else if (g == hi)
  63630. h = 2.0f + red - blue;
  63631. else
  63632. h = 4.0f + green - red;
  63633. h *= 1.0f / 6.0f;
  63634. if (h < 0)
  63635. ++h;
  63636. }
  63637. else
  63638. {
  63639. h = 0;
  63640. }
  63641. }
  63642. else
  63643. {
  63644. s = 0;
  63645. h = 0;
  63646. }
  63647. v = hi * oneOver255;
  63648. }
  63649. float Colour::getHue() const throw()
  63650. {
  63651. float h, s, b;
  63652. getHSB (h, s, b);
  63653. return h;
  63654. }
  63655. const Colour Colour::withHue (const float hue) const throw()
  63656. {
  63657. float h, s, b;
  63658. getHSB (h, s, b);
  63659. return Colour (hue, s, b, getAlpha());
  63660. }
  63661. const Colour Colour::withRotatedHue (const float amountToRotate) const throw()
  63662. {
  63663. float h, s, b;
  63664. getHSB (h, s, b);
  63665. h += amountToRotate;
  63666. h -= floorf (h);
  63667. return Colour (h, s, b, getAlpha());
  63668. }
  63669. float Colour::getSaturation() const throw()
  63670. {
  63671. float h, s, b;
  63672. getHSB (h, s, b);
  63673. return s;
  63674. }
  63675. const Colour Colour::withSaturation (const float saturation) const throw()
  63676. {
  63677. float h, s, b;
  63678. getHSB (h, s, b);
  63679. return Colour (h, saturation, b, getAlpha());
  63680. }
  63681. const Colour Colour::withMultipliedSaturation (const float amount) const throw()
  63682. {
  63683. float h, s, b;
  63684. getHSB (h, s, b);
  63685. return Colour (h, jmin (1.0f, s * amount), b, getAlpha());
  63686. }
  63687. float Colour::getBrightness() const throw()
  63688. {
  63689. float h, s, b;
  63690. getHSB (h, s, b);
  63691. return b;
  63692. }
  63693. const Colour Colour::withBrightness (const float brightness) const throw()
  63694. {
  63695. float h, s, b;
  63696. getHSB (h, s, b);
  63697. return Colour (h, s, brightness, getAlpha());
  63698. }
  63699. const Colour Colour::withMultipliedBrightness (const float amount) const throw()
  63700. {
  63701. float h, s, b;
  63702. getHSB (h, s, b);
  63703. b *= amount;
  63704. if (b > 1.0f)
  63705. b = 1.0f;
  63706. return Colour (h, s, b, getAlpha());
  63707. }
  63708. const Colour Colour::brighter (float amount) const throw()
  63709. {
  63710. amount = 1.0f / (1.0f + amount);
  63711. return Colour ((uint8) (255 - (amount * (255 - getRed()))),
  63712. (uint8) (255 - (amount * (255 - getGreen()))),
  63713. (uint8) (255 - (amount * (255 - getBlue()))),
  63714. getAlpha());
  63715. }
  63716. const Colour Colour::darker (float amount) const throw()
  63717. {
  63718. amount = 1.0f / (1.0f + amount);
  63719. return Colour ((uint8) (amount * getRed()),
  63720. (uint8) (amount * getGreen()),
  63721. (uint8) (amount * getBlue()),
  63722. getAlpha());
  63723. }
  63724. const Colour Colour::greyLevel (const float brightness) throw()
  63725. {
  63726. const uint8 level
  63727. = (uint8) jlimit (0x00, 0xff, roundToInt (brightness * 255.0f));
  63728. return Colour (level, level, level);
  63729. }
  63730. const Colour Colour::contrasting (const float amount) const throw()
  63731. {
  63732. return overlaidWith ((((int) getRed() + (int) getGreen() + (int) getBlue() >= 3 * 128)
  63733. ? Colours::black
  63734. : Colours::white).withAlpha (amount));
  63735. }
  63736. const Colour Colour::contrasting (const Colour& colour1,
  63737. const Colour& colour2) throw()
  63738. {
  63739. const float b1 = colour1.getBrightness();
  63740. const float b2 = colour2.getBrightness();
  63741. float best = 0.0f;
  63742. float bestDist = 0.0f;
  63743. for (float i = 0.0f; i < 1.0f; i += 0.02f)
  63744. {
  63745. const float d1 = fabsf (i - b1);
  63746. const float d2 = fabsf (i - b2);
  63747. const float dist = jmin (d1, d2, 1.0f - d1, 1.0f - d2);
  63748. if (dist > bestDist)
  63749. {
  63750. best = i;
  63751. bestDist = dist;
  63752. }
  63753. }
  63754. return colour1.overlaidWith (colour2.withMultipliedAlpha (0.5f))
  63755. .withBrightness (best);
  63756. }
  63757. const String Colour::toString() const throw()
  63758. {
  63759. return String::toHexString ((int) argb.getARGB());
  63760. }
  63761. const Colour Colour::fromString (const String& encodedColourString)
  63762. {
  63763. return Colour ((uint32) encodedColourString.getHexValue32());
  63764. }
  63765. END_JUCE_NAMESPACE
  63766. /*** End of inlined file: juce_Colour.cpp ***/
  63767. /*** Start of inlined file: juce_ColourGradient.cpp ***/
  63768. BEGIN_JUCE_NAMESPACE
  63769. ColourGradient::ColourGradient() throw()
  63770. {
  63771. #ifdef JUCE_DEBUG
  63772. x1 = 987654.0f;
  63773. #endif
  63774. }
  63775. ColourGradient::ColourGradient (const Colour& colour1,
  63776. const float x1_,
  63777. const float y1_,
  63778. const Colour& colour2,
  63779. const float x2_,
  63780. const float y2_,
  63781. const bool isRadial_) throw()
  63782. : x1 (x1_),
  63783. y1 (y1_),
  63784. x2 (x2_),
  63785. y2 (y2_),
  63786. isRadial (isRadial_)
  63787. {
  63788. colours.add (0);
  63789. colours.add (colour1.getARGB());
  63790. colours.add (1 << 16);
  63791. colours.add (colour2.getARGB());
  63792. }
  63793. ColourGradient::~ColourGradient() throw()
  63794. {
  63795. }
  63796. void ColourGradient::clearColours() throw()
  63797. {
  63798. colours.clear();
  63799. }
  63800. void ColourGradient::addColour (const double proportionAlongGradient,
  63801. const Colour& colour) throw()
  63802. {
  63803. // must be within the two end-points
  63804. jassert (proportionAlongGradient >= 0 && proportionAlongGradient <= 1.0);
  63805. const uint32 pos = jlimit (0, 65535, roundToInt (proportionAlongGradient * 65536.0));
  63806. int i;
  63807. for (i = 0; i < colours.size(); i += 2)
  63808. if (colours.getUnchecked(i) > pos)
  63809. break;
  63810. colours.insert (i, pos);
  63811. colours.insert (i + 1, colour.getARGB());
  63812. }
  63813. void ColourGradient::multiplyOpacity (const float multiplier) throw()
  63814. {
  63815. for (int i = 1; i < colours.size(); i += 2)
  63816. {
  63817. const Colour c (colours.getUnchecked(i));
  63818. colours.set (i, c.withMultipliedAlpha (multiplier).getARGB());
  63819. }
  63820. }
  63821. int ColourGradient::getNumColours() const throw()
  63822. {
  63823. return colours.size() >> 1;
  63824. }
  63825. double ColourGradient::getColourPosition (const int index) const throw()
  63826. {
  63827. return jlimit (0.0, 1.0, colours [index << 1] / 65535.0);
  63828. }
  63829. const Colour ColourGradient::getColour (const int index) const throw()
  63830. {
  63831. return Colour (colours [(index << 1) + 1]);
  63832. }
  63833. const Colour ColourGradient::getColourAtPosition (const float position) const throw()
  63834. {
  63835. jassert (colours.getUnchecked (0) == 0); // the first colour specified has to go at position 0
  63836. const int integerPos = jlimit (0, 65535, roundToInt (position * 65536.0f));
  63837. if (integerPos <= 0 || colours.size() <= 2)
  63838. return getColour (0);
  63839. int i = colours.size() - 2;
  63840. while (integerPos < (int) colours.getUnchecked(i))
  63841. i -= 2;
  63842. if (i >= colours.size() - 2)
  63843. return Colour (colours.getUnchecked(i));
  63844. const int pos1 = colours.getUnchecked (i);
  63845. const Colour col1 (colours.getUnchecked (i + 1));
  63846. const int pos2 = colours.getUnchecked (i + 2);
  63847. const Colour col2 (colours.getUnchecked (i + 3));
  63848. return col1.interpolatedWith (col2, (integerPos - pos1) / (float) (pos2 - pos1));
  63849. }
  63850. int ColourGradient::createLookupTable (const AffineTransform& transform, HeapBlock <PixelARGB>& lookupTable) const throw()
  63851. {
  63852. #ifdef JUCE_DEBUG
  63853. // trying to use the object without setting its co-ordinates? Have a careful read of
  63854. // the comments for the constructors.
  63855. jassert (x1 != 987654.0f);
  63856. #endif
  63857. const int numColours = colours.size() >> 1;
  63858. float tx1 = x1, ty1 = y1, tx2 = x2, ty2 = y2;
  63859. transform.transformPoint (tx1, ty1);
  63860. transform.transformPoint (tx2, ty2);
  63861. const double distance = juce_hypot (tx1 - tx2, ty1 - ty2);
  63862. const int numEntries = jlimit (1, (numColours - 1) << 8, 3 * (int) distance);
  63863. lookupTable.malloc (numEntries);
  63864. if (numColours >= 2)
  63865. {
  63866. jassert (colours.getUnchecked (0) == 0); // the first colour specified has to go at position 0
  63867. PixelARGB pix1 (colours.getUnchecked (1));
  63868. pix1.premultiply();
  63869. int index = 0;
  63870. for (int j = 2; j < colours.size(); j += 2)
  63871. {
  63872. const int numToDo = ((colours.getUnchecked (j) * (numEntries - 1)) >> 16) - index;
  63873. PixelARGB pix2 (colours.getUnchecked (j + 1));
  63874. pix2.premultiply();
  63875. for (int i = 0; i < numToDo; ++i)
  63876. {
  63877. jassert (index >= 0 && index < numEntries);
  63878. lookupTable[index] = pix1;
  63879. lookupTable[index].tween (pix2, (i << 8) / numToDo);
  63880. ++index;
  63881. }
  63882. pix1 = pix2;
  63883. }
  63884. while (index < numEntries)
  63885. lookupTable [index++] = pix1;
  63886. }
  63887. else
  63888. {
  63889. jassertfalse // no colours specified!
  63890. }
  63891. return numEntries;
  63892. }
  63893. bool ColourGradient::isOpaque() const throw()
  63894. {
  63895. for (int i = 1; i < colours.size(); i += 2)
  63896. if (PixelARGB (colours.getUnchecked(i)).getAlpha() < 0xff)
  63897. return false;
  63898. return true;
  63899. }
  63900. bool ColourGradient::isInvisible() const throw()
  63901. {
  63902. for (int i = 1; i < colours.size(); i += 2)
  63903. if (PixelARGB (colours.getUnchecked(i)).getAlpha() > 0)
  63904. return false;
  63905. return true;
  63906. }
  63907. END_JUCE_NAMESPACE
  63908. /*** End of inlined file: juce_ColourGradient.cpp ***/
  63909. /*** Start of inlined file: juce_Colours.cpp ***/
  63910. BEGIN_JUCE_NAMESPACE
  63911. const Colour Colours::transparentBlack (0);
  63912. const Colour Colours::transparentWhite (0x00ffffff);
  63913. const Colour Colours::aliceblue (0xfff0f8ff);
  63914. const Colour Colours::antiquewhite (0xfffaebd7);
  63915. const Colour Colours::aqua (0xff00ffff);
  63916. const Colour Colours::aquamarine (0xff7fffd4);
  63917. const Colour Colours::azure (0xfff0ffff);
  63918. const Colour Colours::beige (0xfff5f5dc);
  63919. const Colour Colours::bisque (0xffffe4c4);
  63920. const Colour Colours::black (0xff000000);
  63921. const Colour Colours::blanchedalmond (0xffffebcd);
  63922. const Colour Colours::blue (0xff0000ff);
  63923. const Colour Colours::blueviolet (0xff8a2be2);
  63924. const Colour Colours::brown (0xffa52a2a);
  63925. const Colour Colours::burlywood (0xffdeb887);
  63926. const Colour Colours::cadetblue (0xff5f9ea0);
  63927. const Colour Colours::chartreuse (0xff7fff00);
  63928. const Colour Colours::chocolate (0xffd2691e);
  63929. const Colour Colours::coral (0xffff7f50);
  63930. const Colour Colours::cornflowerblue (0xff6495ed);
  63931. const Colour Colours::cornsilk (0xfffff8dc);
  63932. const Colour Colours::crimson (0xffdc143c);
  63933. const Colour Colours::cyan (0xff00ffff);
  63934. const Colour Colours::darkblue (0xff00008b);
  63935. const Colour Colours::darkcyan (0xff008b8b);
  63936. const Colour Colours::darkgoldenrod (0xffb8860b);
  63937. const Colour Colours::darkgrey (0xff555555);
  63938. const Colour Colours::darkgreen (0xff006400);
  63939. const Colour Colours::darkkhaki (0xffbdb76b);
  63940. const Colour Colours::darkmagenta (0xff8b008b);
  63941. const Colour Colours::darkolivegreen (0xff556b2f);
  63942. const Colour Colours::darkorange (0xffff8c00);
  63943. const Colour Colours::darkorchid (0xff9932cc);
  63944. const Colour Colours::darkred (0xff8b0000);
  63945. const Colour Colours::darksalmon (0xffe9967a);
  63946. const Colour Colours::darkseagreen (0xff8fbc8f);
  63947. const Colour Colours::darkslateblue (0xff483d8b);
  63948. const Colour Colours::darkslategrey (0xff2f4f4f);
  63949. const Colour Colours::darkturquoise (0xff00ced1);
  63950. const Colour Colours::darkviolet (0xff9400d3);
  63951. const Colour Colours::deeppink (0xffff1493);
  63952. const Colour Colours::deepskyblue (0xff00bfff);
  63953. const Colour Colours::dimgrey (0xff696969);
  63954. const Colour Colours::dodgerblue (0xff1e90ff);
  63955. const Colour Colours::firebrick (0xffb22222);
  63956. const Colour Colours::floralwhite (0xfffffaf0);
  63957. const Colour Colours::forestgreen (0xff228b22);
  63958. const Colour Colours::fuchsia (0xffff00ff);
  63959. const Colour Colours::gainsboro (0xffdcdcdc);
  63960. const Colour Colours::gold (0xffffd700);
  63961. const Colour Colours::goldenrod (0xffdaa520);
  63962. const Colour Colours::grey (0xff808080);
  63963. const Colour Colours::green (0xff008000);
  63964. const Colour Colours::greenyellow (0xffadff2f);
  63965. const Colour Colours::honeydew (0xfff0fff0);
  63966. const Colour Colours::hotpink (0xffff69b4);
  63967. const Colour Colours::indianred (0xffcd5c5c);
  63968. const Colour Colours::indigo (0xff4b0082);
  63969. const Colour Colours::ivory (0xfffffff0);
  63970. const Colour Colours::khaki (0xfff0e68c);
  63971. const Colour Colours::lavender (0xffe6e6fa);
  63972. const Colour Colours::lavenderblush (0xfffff0f5);
  63973. const Colour Colours::lemonchiffon (0xfffffacd);
  63974. const Colour Colours::lightblue (0xffadd8e6);
  63975. const Colour Colours::lightcoral (0xfff08080);
  63976. const Colour Colours::lightcyan (0xffe0ffff);
  63977. const Colour Colours::lightgoldenrodyellow (0xfffafad2);
  63978. const Colour Colours::lightgreen (0xff90ee90);
  63979. const Colour Colours::lightgrey (0xffd3d3d3);
  63980. const Colour Colours::lightpink (0xffffb6c1);
  63981. const Colour Colours::lightsalmon (0xffffa07a);
  63982. const Colour Colours::lightseagreen (0xff20b2aa);
  63983. const Colour Colours::lightskyblue (0xff87cefa);
  63984. const Colour Colours::lightslategrey (0xff778899);
  63985. const Colour Colours::lightsteelblue (0xffb0c4de);
  63986. const Colour Colours::lightyellow (0xffffffe0);
  63987. const Colour Colours::lime (0xff00ff00);
  63988. const Colour Colours::limegreen (0xff32cd32);
  63989. const Colour Colours::linen (0xfffaf0e6);
  63990. const Colour Colours::magenta (0xffff00ff);
  63991. const Colour Colours::maroon (0xff800000);
  63992. const Colour Colours::mediumaquamarine (0xff66cdaa);
  63993. const Colour Colours::mediumblue (0xff0000cd);
  63994. const Colour Colours::mediumorchid (0xffba55d3);
  63995. const Colour Colours::mediumpurple (0xff9370db);
  63996. const Colour Colours::mediumseagreen (0xff3cb371);
  63997. const Colour Colours::mediumslateblue (0xff7b68ee);
  63998. const Colour Colours::mediumspringgreen (0xff00fa9a);
  63999. const Colour Colours::mediumturquoise (0xff48d1cc);
  64000. const Colour Colours::mediumvioletred (0xffc71585);
  64001. const Colour Colours::midnightblue (0xff191970);
  64002. const Colour Colours::mintcream (0xfff5fffa);
  64003. const Colour Colours::mistyrose (0xffffe4e1);
  64004. const Colour Colours::navajowhite (0xffffdead);
  64005. const Colour Colours::navy (0xff000080);
  64006. const Colour Colours::oldlace (0xfffdf5e6);
  64007. const Colour Colours::olive (0xff808000);
  64008. const Colour Colours::olivedrab (0xff6b8e23);
  64009. const Colour Colours::orange (0xffffa500);
  64010. const Colour Colours::orangered (0xffff4500);
  64011. const Colour Colours::orchid (0xffda70d6);
  64012. const Colour Colours::palegoldenrod (0xffeee8aa);
  64013. const Colour Colours::palegreen (0xff98fb98);
  64014. const Colour Colours::paleturquoise (0xffafeeee);
  64015. const Colour Colours::palevioletred (0xffdb7093);
  64016. const Colour Colours::papayawhip (0xffffefd5);
  64017. const Colour Colours::peachpuff (0xffffdab9);
  64018. const Colour Colours::peru (0xffcd853f);
  64019. const Colour Colours::pink (0xffffc0cb);
  64020. const Colour Colours::plum (0xffdda0dd);
  64021. const Colour Colours::powderblue (0xffb0e0e6);
  64022. const Colour Colours::purple (0xff800080);
  64023. const Colour Colours::red (0xffff0000);
  64024. const Colour Colours::rosybrown (0xffbc8f8f);
  64025. const Colour Colours::royalblue (0xff4169e1);
  64026. const Colour Colours::saddlebrown (0xff8b4513);
  64027. const Colour Colours::salmon (0xfffa8072);
  64028. const Colour Colours::sandybrown (0xfff4a460);
  64029. const Colour Colours::seagreen (0xff2e8b57);
  64030. const Colour Colours::seashell (0xfffff5ee);
  64031. const Colour Colours::sienna (0xffa0522d);
  64032. const Colour Colours::silver (0xffc0c0c0);
  64033. const Colour Colours::skyblue (0xff87ceeb);
  64034. const Colour Colours::slateblue (0xff6a5acd);
  64035. const Colour Colours::slategrey (0xff708090);
  64036. const Colour Colours::snow (0xfffffafa);
  64037. const Colour Colours::springgreen (0xff00ff7f);
  64038. const Colour Colours::steelblue (0xff4682b4);
  64039. const Colour Colours::tan (0xffd2b48c);
  64040. const Colour Colours::teal (0xff008080);
  64041. const Colour Colours::thistle (0xffd8bfd8);
  64042. const Colour Colours::tomato (0xffff6347);
  64043. const Colour Colours::turquoise (0xff40e0d0);
  64044. const Colour Colours::violet (0xffee82ee);
  64045. const Colour Colours::wheat (0xfff5deb3);
  64046. const Colour Colours::white (0xffffffff);
  64047. const Colour Colours::whitesmoke (0xfff5f5f5);
  64048. const Colour Colours::yellow (0xffffff00);
  64049. const Colour Colours::yellowgreen (0xff9acd32);
  64050. const Colour Colours::findColourForName (const String& colourName,
  64051. const Colour& defaultColour)
  64052. {
  64053. static const int presets[] =
  64054. {
  64055. // (first value is the string's hashcode, second is ARGB)
  64056. 0x05978fff, 0xff000000, /* black */
  64057. 0x06bdcc29, 0xffffffff, /* white */
  64058. 0x002e305a, 0xff0000ff, /* blue */
  64059. 0x00308adf, 0xff808080, /* grey */
  64060. 0x05e0cf03, 0xff008000, /* green */
  64061. 0x0001b891, 0xffff0000, /* red */
  64062. 0xd43c6474, 0xffffff00, /* yellow */
  64063. 0x620886da, 0xfff0f8ff, /* aliceblue */
  64064. 0x20a2676a, 0xfffaebd7, /* antiquewhite */
  64065. 0x002dcebc, 0xff00ffff, /* aqua */
  64066. 0x46bb5f7e, 0xff7fffd4, /* aquamarine */
  64067. 0x0590228f, 0xfff0ffff, /* azure */
  64068. 0x05947fe4, 0xfff5f5dc, /* beige */
  64069. 0xad388e35, 0xffffe4c4, /* bisque */
  64070. 0x00674f7e, 0xffffebcd, /* blanchedalmond */
  64071. 0x39129959, 0xff8a2be2, /* blueviolet */
  64072. 0x059a8136, 0xffa52a2a, /* brown */
  64073. 0x89cea8f9, 0xffdeb887, /* burlywood */
  64074. 0x0fa260cf, 0xff5f9ea0, /* cadetblue */
  64075. 0x6b748956, 0xff7fff00, /* chartreuse */
  64076. 0x2903623c, 0xffd2691e, /* chocolate */
  64077. 0x05a74431, 0xffff7f50, /* coral */
  64078. 0x618d42dd, 0xff6495ed, /* cornflowerblue */
  64079. 0xe4b479fd, 0xfffff8dc, /* cornsilk */
  64080. 0x3d8c4edf, 0xffdc143c, /* crimson */
  64081. 0x002ed323, 0xff00ffff, /* cyan */
  64082. 0x67cc74d0, 0xff00008b, /* darkblue */
  64083. 0x67cd1799, 0xff008b8b, /* darkcyan */
  64084. 0x31bbd168, 0xffb8860b, /* darkgoldenrod */
  64085. 0x67cecf55, 0xff555555, /* darkgrey */
  64086. 0x920b194d, 0xff006400, /* darkgreen */
  64087. 0x923edd4c, 0xffbdb76b, /* darkkhaki */
  64088. 0x5c293873, 0xff8b008b, /* darkmagenta */
  64089. 0x6b6671fe, 0xff556b2f, /* darkolivegreen */
  64090. 0xbcfd2524, 0xffff8c00, /* darkorange */
  64091. 0xbcfdf799, 0xff9932cc, /* darkorchid */
  64092. 0x55ee0d5b, 0xff8b0000, /* darkred */
  64093. 0xc2e5f564, 0xffe9967a, /* darksalmon */
  64094. 0x61be858a, 0xff8fbc8f, /* darkseagreen */
  64095. 0xc2b0f2bd, 0xff483d8b, /* darkslateblue */
  64096. 0xc2b34d42, 0xff2f4f4f, /* darkslategrey */
  64097. 0x7cf2b06b, 0xff00ced1, /* darkturquoise */
  64098. 0xc8769375, 0xff9400d3, /* darkviolet */
  64099. 0x25832862, 0xffff1493, /* deeppink */
  64100. 0xfcad568f, 0xff00bfff, /* deepskyblue */
  64101. 0x634c8b67, 0xff696969, /* dimgrey */
  64102. 0x45c1ce55, 0xff1e90ff, /* dodgerblue */
  64103. 0xef19e3cb, 0xffb22222, /* firebrick */
  64104. 0xb852b195, 0xfffffaf0, /* floralwhite */
  64105. 0xd086fd06, 0xff228b22, /* forestgreen */
  64106. 0xe106b6d7, 0xffff00ff, /* fuchsia */
  64107. 0x7880d61e, 0xffdcdcdc, /* gainsboro */
  64108. 0x00308060, 0xffffd700, /* gold */
  64109. 0xb3b3bc1e, 0xffdaa520, /* goldenrod */
  64110. 0xbab8a537, 0xffadff2f, /* greenyellow */
  64111. 0xe4cacafb, 0xfff0fff0, /* honeydew */
  64112. 0x41892743, 0xffff69b4, /* hotpink */
  64113. 0xd5796f1a, 0xffcd5c5c, /* indianred */
  64114. 0xb969fed2, 0xff4b0082, /* indigo */
  64115. 0x05fef6a9, 0xfffffff0, /* ivory */
  64116. 0x06149302, 0xfff0e68c, /* khaki */
  64117. 0xad5a05c7, 0xffe6e6fa, /* lavender */
  64118. 0x7c4d5b99, 0xfffff0f5, /* lavenderblush */
  64119. 0x195756f0, 0xfffffacd, /* lemonchiffon */
  64120. 0x28e4ea70, 0xffadd8e6, /* lightblue */
  64121. 0xf3c7ccdb, 0xfff08080, /* lightcoral */
  64122. 0x28e58d39, 0xffe0ffff, /* lightcyan */
  64123. 0x21234e3c, 0xfffafad2, /* lightgoldenrodyellow */
  64124. 0xf40157ad, 0xff90ee90, /* lightgreen */
  64125. 0x28e744f5, 0xffd3d3d3, /* lightgrey */
  64126. 0x28eb3b8c, 0xffffb6c1, /* lightpink */
  64127. 0x9fb78304, 0xffffa07a, /* lightsalmon */
  64128. 0x50632b2a, 0xff20b2aa, /* lightseagreen */
  64129. 0x68fb7b25, 0xff87cefa, /* lightskyblue */
  64130. 0xa8a35ba2, 0xff778899, /* lightslategrey */
  64131. 0xa20d484f, 0xffb0c4de, /* lightsteelblue */
  64132. 0xaa2cf10a, 0xffffffe0, /* lightyellow */
  64133. 0x0032afd5, 0xff00ff00, /* lime */
  64134. 0x607bbc4e, 0xff32cd32, /* limegreen */
  64135. 0x06234efa, 0xfffaf0e6, /* linen */
  64136. 0x316858a9, 0xffff00ff, /* magenta */
  64137. 0xbf8ca470, 0xff800000, /* maroon */
  64138. 0xbd58e0b3, 0xff66cdaa, /* mediumaquamarine */
  64139. 0x967dfd4f, 0xff0000cd, /* mediumblue */
  64140. 0x056f5c58, 0xffba55d3, /* mediumorchid */
  64141. 0x07556b71, 0xff9370db, /* mediumpurple */
  64142. 0x5369b689, 0xff3cb371, /* mediumseagreen */
  64143. 0x066be19e, 0xff7b68ee, /* mediumslateblue */
  64144. 0x3256b281, 0xff00fa9a, /* mediumspringgreen */
  64145. 0xc0ad9f4c, 0xff48d1cc, /* mediumturquoise */
  64146. 0x628e63dd, 0xffc71585, /* mediumvioletred */
  64147. 0x168eb32a, 0xff191970, /* midnightblue */
  64148. 0x4306b960, 0xfff5fffa, /* mintcream */
  64149. 0x4cbc0e6b, 0xffffe4e1, /* mistyrose */
  64150. 0xe97218a6, 0xffffdead, /* navajowhite */
  64151. 0x00337bb6, 0xff000080, /* navy */
  64152. 0xadd2d33e, 0xfffdf5e6, /* oldlace */
  64153. 0x064ee1db, 0xff808000, /* olive */
  64154. 0x9e33a98a, 0xff6b8e23, /* olivedrab */
  64155. 0xc3de262e, 0xffffa500, /* orange */
  64156. 0x58bebba3, 0xffff4500, /* orangered */
  64157. 0xc3def8a3, 0xffda70d6, /* orchid */
  64158. 0x28cb4834, 0xffeee8aa, /* palegoldenrod */
  64159. 0x3d9dd619, 0xff98fb98, /* palegreen */
  64160. 0x74022737, 0xffafeeee, /* paleturquoise */
  64161. 0x15e2ebc8, 0xffdb7093, /* palevioletred */
  64162. 0x5fd898e2, 0xffffefd5, /* papayawhip */
  64163. 0x93e1b776, 0xffffdab9, /* peachpuff */
  64164. 0x003472f8, 0xffcd853f, /* peru */
  64165. 0x00348176, 0xffffc0cb, /* pink */
  64166. 0x00348d94, 0xffdda0dd, /* plum */
  64167. 0xd036be93, 0xffb0e0e6, /* powderblue */
  64168. 0xc5c507bc, 0xff800080, /* purple */
  64169. 0xa89d65b3, 0xffbc8f8f, /* rosybrown */
  64170. 0xbd9413e1, 0xff4169e1, /* royalblue */
  64171. 0xf456044f, 0xff8b4513, /* saddlebrown */
  64172. 0xc9c6f66e, 0xfffa8072, /* salmon */
  64173. 0x0bb131e1, 0xfff4a460, /* sandybrown */
  64174. 0x34636c14, 0xff2e8b57, /* seagreen */
  64175. 0x3507fb41, 0xfffff5ee, /* seashell */
  64176. 0xca348772, 0xffa0522d, /* sienna */
  64177. 0xca37d30d, 0xffc0c0c0, /* silver */
  64178. 0x80da74fb, 0xff87ceeb, /* skyblue */
  64179. 0x44a8dd73, 0xff6a5acd, /* slateblue */
  64180. 0x44ab37f8, 0xff708090, /* slategrey */
  64181. 0x0035f183, 0xfffffafa, /* snow */
  64182. 0xd5440d16, 0xff00ff7f, /* springgreen */
  64183. 0x3e1524a5, 0xff4682b4, /* steelblue */
  64184. 0x0001bfa1, 0xffd2b48c, /* tan */
  64185. 0x0036425c, 0xff008080, /* teal */
  64186. 0xafc8858f, 0xffd8bfd8, /* thistle */
  64187. 0xcc41600a, 0xffff6347, /* tomato */
  64188. 0xfeea9b21, 0xff40e0d0, /* turquoise */
  64189. 0xcf57947f, 0xffee82ee, /* violet */
  64190. 0x06bdbae7, 0xfff5deb3, /* wheat */
  64191. 0x10802ee6, 0xfff5f5f5, /* whitesmoke */
  64192. 0xe1b5130f, 0xff9acd32 /* yellowgreen */
  64193. };
  64194. const int hash = colourName.trim().toLowerCase().hashCode();
  64195. for (int i = 0; i < numElementsInArray (presets); i += 2)
  64196. if (presets [i] == hash)
  64197. return Colour (presets [i + 1]);
  64198. return defaultColour;
  64199. }
  64200. END_JUCE_NAMESPACE
  64201. /*** End of inlined file: juce_Colours.cpp ***/
  64202. /*** Start of inlined file: juce_EdgeTable.cpp ***/
  64203. BEGIN_JUCE_NAMESPACE
  64204. const int juce_edgeTableDefaultEdgesPerLine = 32;
  64205. static void copyEdgeTableData (int* dest, const int destLineStride, const int* src, const int srcLineStride, int numLines) throw()
  64206. {
  64207. while (--numLines >= 0)
  64208. {
  64209. memcpy (dest, src, (src[0] * 2 + 1) * sizeof (int));
  64210. src += srcLineStride;
  64211. dest += destLineStride;
  64212. }
  64213. }
  64214. EdgeTable::EdgeTable (const Rectangle<int>& bounds_,
  64215. const Path& path, const AffineTransform& transform) throw()
  64216. : bounds (bounds_),
  64217. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  64218. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  64219. needToCheckEmptinesss (true)
  64220. {
  64221. table.malloc ((bounds.getHeight() + 1) * lineStrideElements);
  64222. int* t = table;
  64223. for (int i = bounds.getHeight(); --i >= 0;)
  64224. {
  64225. *t = 0;
  64226. t += lineStrideElements;
  64227. }
  64228. const int topLimit = bounds.getY() << 8;
  64229. const int heightLimit = bounds.getHeight() << 8;
  64230. const int leftLimit = bounds.getX() << 8;
  64231. const int rightLimit = bounds.getRight() << 8;
  64232. PathFlatteningIterator iter (path, transform);
  64233. while (iter.next())
  64234. {
  64235. int y1 = roundToInt (iter.y1 * 256.0f);
  64236. int y2 = roundToInt (iter.y2 * 256.0f);
  64237. if (y1 != y2)
  64238. {
  64239. y1 -= topLimit;
  64240. y2 -= topLimit;
  64241. const int startY = y1;
  64242. int direction = -1;
  64243. if (y1 > y2)
  64244. {
  64245. swapVariables (y1, y2);
  64246. direction = 1;
  64247. }
  64248. if (y1 < 0)
  64249. y1 = 0;
  64250. if (y2 > heightLimit)
  64251. y2 = heightLimit;
  64252. if (y1 < y2)
  64253. {
  64254. const double startX = 256.0f * iter.x1;
  64255. const double multiplier = (iter.x2 - iter.x1) / (iter.y2 - iter.y1);
  64256. const int stepSize = jlimit (1, 256, 256 / (1 + (int) fabs (multiplier)));
  64257. do
  64258. {
  64259. const int step = jmin (stepSize, y2 - y1, 256 - (y1 & 255));
  64260. int x = roundToInt (startX + multiplier * ((y1 + (step >> 1)) - startY));
  64261. if (x < leftLimit)
  64262. x = leftLimit;
  64263. else if (x >= rightLimit)
  64264. x = rightLimit - 1;
  64265. addEdgePoint (x, y1 >> 8, direction * step);
  64266. y1 += step;
  64267. }
  64268. while (y1 < y2);
  64269. }
  64270. }
  64271. }
  64272. sanitiseLevels (path.isUsingNonZeroWinding());
  64273. }
  64274. EdgeTable::EdgeTable (const Rectangle<int>& rectangleToAdd) throw()
  64275. : bounds (rectangleToAdd),
  64276. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  64277. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  64278. needToCheckEmptinesss (true)
  64279. {
  64280. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  64281. table[0] = 0;
  64282. const int x1 = rectangleToAdd.getX() << 8;
  64283. const int x2 = rectangleToAdd.getRight() << 8;
  64284. int* t = table;
  64285. for (int i = rectangleToAdd.getHeight(); --i >= 0;)
  64286. {
  64287. t[0] = 2;
  64288. t[1] = x1;
  64289. t[2] = 255;
  64290. t[3] = x2;
  64291. t[4] = 0;
  64292. t += lineStrideElements;
  64293. }
  64294. }
  64295. EdgeTable::EdgeTable (const RectangleList& rectanglesToAdd) throw()
  64296. : bounds (rectanglesToAdd.getBounds()),
  64297. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  64298. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  64299. needToCheckEmptinesss (true)
  64300. {
  64301. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  64302. int* t = table;
  64303. for (int i = bounds.getHeight(); --i >= 0;)
  64304. {
  64305. *t = 0;
  64306. t += lineStrideElements;
  64307. }
  64308. for (RectangleList::Iterator iter (rectanglesToAdd); iter.next();)
  64309. {
  64310. const Rectangle<int>* const r = iter.getRectangle();
  64311. const int x1 = r->getX() << 8;
  64312. const int x2 = r->getRight() << 8;
  64313. int y = r->getY() - bounds.getY();
  64314. for (int j = r->getHeight(); --j >= 0;)
  64315. {
  64316. addEdgePoint (x1, y, 255);
  64317. addEdgePoint (x2, y, -255);
  64318. ++y;
  64319. }
  64320. }
  64321. sanitiseLevels (true);
  64322. }
  64323. EdgeTable::EdgeTable (const float x, const float y, const float w, const float h) throw()
  64324. : bounds (Rectangle<int> ((int) floorf (x), roundToInt (y * 256.0f) >> 8, 2 + (int) w, 2 + (int) h)),
  64325. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  64326. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  64327. needToCheckEmptinesss (true)
  64328. {
  64329. jassert (w > 0 && h > 0);
  64330. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  64331. table[0] = 0;
  64332. const int x1 = roundToInt (x * 256.0f);
  64333. const int x2 = roundToInt ((x + w) * 256.0f);
  64334. int y1 = roundToInt (y * 256.0f) - (bounds.getY() << 8);
  64335. jassert (y1 < 256);
  64336. int y2 = roundToInt ((y + h) * 256.0f) - (bounds.getY() << 8);
  64337. if (x2 <= x1 || y2 <= y1)
  64338. {
  64339. bounds.setHeight (0);
  64340. return;
  64341. }
  64342. int lineY = 0;
  64343. int* t = table;
  64344. if ((y1 >> 8) == (y2 >> 8))
  64345. {
  64346. t[0] = 2;
  64347. t[1] = x1;
  64348. t[2] = y2 - y1;
  64349. t[3] = x2;
  64350. t[4] = 0;
  64351. ++lineY;
  64352. t += lineStrideElements;
  64353. }
  64354. else
  64355. {
  64356. t[0] = 2;
  64357. t[1] = x1;
  64358. t[2] = 255 - (y1 & 255);
  64359. t[3] = x2;
  64360. t[4] = 0;
  64361. ++lineY;
  64362. t += lineStrideElements;
  64363. while (lineY < (y2 >> 8))
  64364. {
  64365. t[0] = 2;
  64366. t[1] = x1;
  64367. t[2] = 255;
  64368. t[3] = x2;
  64369. t[4] = 0;
  64370. ++lineY;
  64371. t += lineStrideElements;
  64372. }
  64373. jassert (lineY < bounds.getHeight());
  64374. t[0] = 2;
  64375. t[1] = x1;
  64376. t[2] = y2 & 255;
  64377. t[3] = x2;
  64378. t[4] = 0;
  64379. ++lineY;
  64380. t += lineStrideElements;
  64381. }
  64382. while (lineY < bounds.getHeight())
  64383. {
  64384. t[0] = 0;
  64385. t += lineStrideElements;
  64386. ++lineY;
  64387. }
  64388. }
  64389. EdgeTable::EdgeTable (const EdgeTable& other) throw()
  64390. : table (0)
  64391. {
  64392. operator= (other);
  64393. }
  64394. const EdgeTable& EdgeTable::operator= (const EdgeTable& other) throw()
  64395. {
  64396. bounds = other.bounds;
  64397. maxEdgesPerLine = other.maxEdgesPerLine;
  64398. lineStrideElements = other.lineStrideElements;
  64399. needToCheckEmptinesss = other.needToCheckEmptinesss;
  64400. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  64401. copyEdgeTableData (table, lineStrideElements, other.table, lineStrideElements, bounds.getHeight());
  64402. return *this;
  64403. }
  64404. EdgeTable::~EdgeTable() throw()
  64405. {
  64406. }
  64407. void EdgeTable::sanitiseLevels (const bool useNonZeroWinding) throw()
  64408. {
  64409. // Convert the table from relative windings to absolute levels..
  64410. int* lineStart = table;
  64411. for (int i = bounds.getHeight(); --i >= 0;)
  64412. {
  64413. int* line = lineStart;
  64414. lineStart += lineStrideElements;
  64415. int num = *line;
  64416. if (num == 0)
  64417. continue;
  64418. int level = 0;
  64419. if (useNonZeroWinding)
  64420. {
  64421. while (--num > 0)
  64422. {
  64423. line += 2;
  64424. level += *line;
  64425. int corrected = abs (level);
  64426. if (corrected >> 8)
  64427. corrected = 255;
  64428. *line = corrected;
  64429. }
  64430. }
  64431. else
  64432. {
  64433. while (--num > 0)
  64434. {
  64435. line += 2;
  64436. level += *line;
  64437. int corrected = abs (level);
  64438. if (corrected >> 8)
  64439. {
  64440. corrected &= 511;
  64441. if (corrected >> 8)
  64442. corrected = 511 - corrected;
  64443. }
  64444. *line = corrected;
  64445. }
  64446. }
  64447. line[2] = 0; // force the last level to 0, just in case something went wrong in creating the table
  64448. }
  64449. }
  64450. void EdgeTable::remapTableForNumEdges (const int newNumEdgesPerLine) throw()
  64451. {
  64452. if (newNumEdgesPerLine != maxEdgesPerLine)
  64453. {
  64454. maxEdgesPerLine = newNumEdgesPerLine;
  64455. jassert (bounds.getHeight() > 0);
  64456. const int newLineStrideElements = maxEdgesPerLine * 2 + 1;
  64457. HeapBlock <int> newTable (bounds.getHeight() * newLineStrideElements);
  64458. copyEdgeTableData (newTable, newLineStrideElements, table, lineStrideElements, bounds.getHeight());
  64459. table.swapWith (newTable);
  64460. lineStrideElements = newLineStrideElements;
  64461. }
  64462. }
  64463. void EdgeTable::optimiseTable() throw()
  64464. {
  64465. int maxLineElements = 0;
  64466. for (int i = bounds.getHeight(); --i >= 0;)
  64467. maxLineElements = jmax (maxLineElements, table [i * lineStrideElements]);
  64468. remapTableForNumEdges (maxLineElements);
  64469. }
  64470. void EdgeTable::addEdgePoint (const int x, const int y, const int winding) throw()
  64471. {
  64472. jassert (y >= 0 && y < bounds.getHeight());
  64473. int* line = table + lineStrideElements * y;
  64474. const int numPoints = line[0];
  64475. int n = numPoints << 1;
  64476. if (n > 0)
  64477. {
  64478. while (n > 0)
  64479. {
  64480. const int cx = line [n - 1];
  64481. if (cx <= x)
  64482. {
  64483. if (cx == x)
  64484. {
  64485. line [n] += winding;
  64486. return;
  64487. }
  64488. break;
  64489. }
  64490. n -= 2;
  64491. }
  64492. if (numPoints >= maxEdgesPerLine)
  64493. {
  64494. remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine);
  64495. jassert (numPoints < maxEdgesPerLine);
  64496. line = table + lineStrideElements * y;
  64497. }
  64498. memmove (line + (n + 3), line + (n + 1), sizeof (int) * ((numPoints << 1) - n));
  64499. }
  64500. line [n + 1] = x;
  64501. line [n + 2] = winding;
  64502. line[0]++;
  64503. }
  64504. void EdgeTable::translate (float dx, int dy) throw()
  64505. {
  64506. bounds.setPosition (bounds.getX() + (int) floorf (dx), bounds.getY() + dy);
  64507. int* lineStart = table;
  64508. const int intDx = (int) (dx * 256.0f);
  64509. for (int i = bounds.getHeight(); --i >= 0;)
  64510. {
  64511. int* line = lineStart;
  64512. lineStart += lineStrideElements;
  64513. int num = *line++;
  64514. while (--num >= 0)
  64515. {
  64516. *line += intDx;
  64517. line += 2;
  64518. }
  64519. }
  64520. }
  64521. void EdgeTable::intersectWithEdgeTableLine (const int y, const int* otherLine) throw()
  64522. {
  64523. jassert (y >= 0 && y < bounds.getHeight());
  64524. int* dest = table + lineStrideElements * y;
  64525. if (dest[0] == 0)
  64526. return;
  64527. int otherNumPoints = *otherLine;
  64528. if (otherNumPoints == 0)
  64529. {
  64530. *dest = 0;
  64531. return;
  64532. }
  64533. const int right = bounds.getRight() << 8;
  64534. // optimise for the common case where our line lies entirely within a
  64535. // single pair of points, as happens when clipping to a simple rect.
  64536. if (otherNumPoints == 2 && otherLine[2] >= 255)
  64537. {
  64538. clipEdgeTableLineToRange (dest, otherLine[1], jmin (right, otherLine[3]));
  64539. return;
  64540. }
  64541. ++otherLine;
  64542. const size_t lineSizeBytes = (dest[0] * 2 + 1) * sizeof (int);
  64543. int* temp = (int*) alloca (lineSizeBytes);
  64544. memcpy (temp, dest, lineSizeBytes);
  64545. const int* src1 = temp;
  64546. int srcNum1 = *src1++;
  64547. int x1 = *src1++;
  64548. const int* src2 = otherLine;
  64549. int srcNum2 = otherNumPoints;
  64550. int x2 = *src2++;
  64551. int destIndex = 0, destTotal = 0;
  64552. int level1 = 0, level2 = 0;
  64553. int lastX = std::numeric_limits<int>::min(), lastLevel = 0;
  64554. while (srcNum1 > 0 && srcNum2 > 0)
  64555. {
  64556. int nextX;
  64557. if (x1 < x2)
  64558. {
  64559. nextX = x1;
  64560. level1 = *src1++;
  64561. x1 = *src1++;
  64562. --srcNum1;
  64563. }
  64564. else if (x1 == x2)
  64565. {
  64566. nextX = x1;
  64567. level1 = *src1++;
  64568. level2 = *src2++;
  64569. x1 = *src1++;
  64570. x2 = *src2++;
  64571. --srcNum1;
  64572. --srcNum2;
  64573. }
  64574. else
  64575. {
  64576. nextX = x2;
  64577. level2 = *src2++;
  64578. x2 = *src2++;
  64579. --srcNum2;
  64580. }
  64581. if (nextX > lastX)
  64582. {
  64583. if (nextX >= right)
  64584. break;
  64585. lastX = nextX;
  64586. const int nextLevel = (level1 * (level2 + 1)) >> 8;
  64587. jassert (((unsigned int) nextLevel) < (unsigned int) 256);
  64588. if (nextLevel != lastLevel)
  64589. {
  64590. if (destTotal >= maxEdgesPerLine)
  64591. {
  64592. dest[0] = destTotal;
  64593. remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine);
  64594. dest = table + lineStrideElements * y;
  64595. }
  64596. ++destTotal;
  64597. lastLevel = nextLevel;
  64598. dest[++destIndex] = nextX;
  64599. dest[++destIndex] = nextLevel;
  64600. }
  64601. }
  64602. }
  64603. if (lastLevel > 0)
  64604. {
  64605. if (destTotal >= maxEdgesPerLine)
  64606. {
  64607. dest[0] = destTotal;
  64608. remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine);
  64609. dest = table + lineStrideElements * y;
  64610. }
  64611. ++destTotal;
  64612. dest[++destIndex] = right;
  64613. dest[++destIndex] = 0;
  64614. }
  64615. dest[0] = destTotal;
  64616. #if JUCE_DEBUG
  64617. int last = std::numeric_limits<int>::min();
  64618. for (int i = 0; i < dest[0]; ++i)
  64619. {
  64620. jassert (dest[i * 2 + 1] > last);
  64621. last = dest[i * 2 + 1];
  64622. }
  64623. jassert (dest [dest[0] * 2] == 0);
  64624. #endif
  64625. }
  64626. void EdgeTable::clipEdgeTableLineToRange (int* dest, const int x1, const int x2) throw()
  64627. {
  64628. int* lastItem = dest + (dest[0] * 2 - 1);
  64629. if (x2 < lastItem[0])
  64630. {
  64631. if (x2 <= dest[1])
  64632. {
  64633. dest[0] = 0;
  64634. return;
  64635. }
  64636. while (x2 < lastItem[-2])
  64637. {
  64638. --(dest[0]);
  64639. lastItem -= 2;
  64640. }
  64641. lastItem[0] = x2;
  64642. lastItem[1] = 0;
  64643. }
  64644. if (x1 > dest[1])
  64645. {
  64646. while (lastItem[0] > x1)
  64647. lastItem -= 2;
  64648. const int itemsRemoved = (int) (lastItem - (dest + 1)) / 2;
  64649. if (itemsRemoved > 0)
  64650. {
  64651. dest[0] -= itemsRemoved;
  64652. memmove (dest + 1, lastItem, dest[0] * (sizeof (int) * 2));
  64653. }
  64654. dest[1] = x1;
  64655. }
  64656. }
  64657. void EdgeTable::clipToRectangle (const Rectangle<int>& r) throw()
  64658. {
  64659. const Rectangle<int> clipped (r.getIntersection (bounds));
  64660. if (clipped.isEmpty())
  64661. {
  64662. needToCheckEmptinesss = false;
  64663. bounds.setHeight (0);
  64664. }
  64665. else
  64666. {
  64667. const int top = clipped.getY() - bounds.getY();
  64668. const int bottom = clipped.getBottom() - bounds.getY();
  64669. if (bottom < bounds.getHeight())
  64670. bounds.setHeight (bottom);
  64671. if (clipped.getRight() < bounds.getRight())
  64672. bounds.setRight (clipped.getRight());
  64673. for (int i = top; --i >= 0;)
  64674. table [lineStrideElements * i] = 0;
  64675. if (clipped.getX() > bounds.getX())
  64676. {
  64677. const int x1 = clipped.getX() << 8;
  64678. const int x2 = jmin (bounds.getRight(), clipped.getRight()) << 8;
  64679. int* line = table + lineStrideElements * top;
  64680. for (int i = bottom - top; --i >= 0;)
  64681. {
  64682. if (line[0] != 0)
  64683. clipEdgeTableLineToRange (line, x1, x2);
  64684. line += lineStrideElements;
  64685. }
  64686. }
  64687. needToCheckEmptinesss = true;
  64688. }
  64689. }
  64690. void EdgeTable::excludeRectangle (const Rectangle<int>& r) throw()
  64691. {
  64692. const Rectangle<int> clipped (r.getIntersection (bounds));
  64693. if (! clipped.isEmpty())
  64694. {
  64695. const int top = clipped.getY() - bounds.getY();
  64696. const int bottom = clipped.getBottom() - bounds.getY();
  64697. //XXX optimise here by shortening the table if it fills top or bottom
  64698. const int rectLine[] = { 4, std::numeric_limits<int>::min(), 255,
  64699. clipped.getX() << 8, 0,
  64700. clipped.getRight() << 8, 255,
  64701. std::numeric_limits<int>::max(), 0 };
  64702. for (int i = top; i < bottom; ++i)
  64703. intersectWithEdgeTableLine (i, rectLine);
  64704. needToCheckEmptinesss = true;
  64705. }
  64706. }
  64707. void EdgeTable::clipToEdgeTable (const EdgeTable& other)
  64708. {
  64709. const Rectangle<int> clipped (other.bounds.getIntersection (bounds));
  64710. if (clipped.isEmpty())
  64711. {
  64712. needToCheckEmptinesss = false;
  64713. bounds.setHeight (0);
  64714. }
  64715. else
  64716. {
  64717. const int top = clipped.getY() - bounds.getY();
  64718. const int bottom = clipped.getBottom() - bounds.getY();
  64719. if (bottom < bounds.getHeight())
  64720. bounds.setHeight (bottom);
  64721. if (clipped.getRight() < bounds.getRight())
  64722. bounds.setRight (clipped.getRight());
  64723. int i = 0;
  64724. for (i = top; --i >= 0;)
  64725. table [lineStrideElements * i] = 0;
  64726. const int* otherLine = other.table + other.lineStrideElements * (clipped.getY() - other.bounds.getY());
  64727. for (i = top; i < bottom; ++i)
  64728. {
  64729. intersectWithEdgeTableLine (i, otherLine);
  64730. otherLine += other.lineStrideElements;
  64731. }
  64732. needToCheckEmptinesss = true;
  64733. }
  64734. }
  64735. void EdgeTable::clipLineToMask (int x, int y, uint8* mask, int maskStride, int numPixels) throw()
  64736. {
  64737. y -= bounds.getY();
  64738. if (y < 0 || y >= bounds.getHeight())
  64739. return;
  64740. needToCheckEmptinesss = true;
  64741. if (numPixels <= 0)
  64742. {
  64743. table [lineStrideElements * y] = 0;
  64744. return;
  64745. }
  64746. int* tempLine = (int*) alloca ((numPixels * 2 + 4) * sizeof (int));
  64747. int destIndex = 0, lastLevel = 0;
  64748. while (--numPixels >= 0)
  64749. {
  64750. const int alpha = *mask;
  64751. mask += maskStride;
  64752. if (alpha != lastLevel)
  64753. {
  64754. tempLine[++destIndex] = (x << 8);
  64755. tempLine[++destIndex] = alpha;
  64756. lastLevel = alpha;
  64757. }
  64758. ++x;
  64759. }
  64760. if (lastLevel > 0)
  64761. {
  64762. tempLine[++destIndex] = (x << 8);
  64763. tempLine[++destIndex] = 0;
  64764. }
  64765. tempLine[0] = destIndex >> 1;
  64766. intersectWithEdgeTableLine (y, tempLine);
  64767. }
  64768. bool EdgeTable::isEmpty() throw()
  64769. {
  64770. if (needToCheckEmptinesss)
  64771. {
  64772. needToCheckEmptinesss = false;
  64773. int* t = table;
  64774. for (int i = bounds.getHeight(); --i >= 0;)
  64775. {
  64776. if (t[0] > 1)
  64777. return false;
  64778. t += lineStrideElements;
  64779. }
  64780. bounds.setHeight (0);
  64781. }
  64782. return bounds.getHeight() == 0;
  64783. }
  64784. END_JUCE_NAMESPACE
  64785. /*** End of inlined file: juce_EdgeTable.cpp ***/
  64786. /*** Start of inlined file: juce_FillType.cpp ***/
  64787. BEGIN_JUCE_NAMESPACE
  64788. FillType::FillType() throw()
  64789. : colour (0xff000000), image (0)
  64790. {
  64791. }
  64792. FillType::FillType (const Colour& colour_) throw()
  64793. : colour (colour_), image (0)
  64794. {
  64795. }
  64796. FillType::FillType (const ColourGradient& gradient_) throw()
  64797. : colour (0xff000000), gradient (new ColourGradient (gradient_)), image (0)
  64798. {
  64799. }
  64800. FillType::FillType (const Image& image_, const AffineTransform& transform_) throw()
  64801. : colour (0xff000000), image (&image_), transform (transform_)
  64802. {
  64803. }
  64804. FillType::FillType (const FillType& other) throw()
  64805. : colour (other.colour),
  64806. gradient (other.gradient != 0 ? new ColourGradient (*other.gradient) : 0),
  64807. image (other.image), transform (other.transform)
  64808. {
  64809. }
  64810. const FillType& FillType::operator= (const FillType& other) throw()
  64811. {
  64812. if (this != &other)
  64813. {
  64814. colour = other.colour;
  64815. gradient = (other.gradient != 0 ? new ColourGradient (*other.gradient) : 0);
  64816. image = other.image;
  64817. transform = other.transform;
  64818. }
  64819. return *this;
  64820. }
  64821. FillType::~FillType() throw()
  64822. {
  64823. }
  64824. void FillType::setColour (const Colour& newColour) throw()
  64825. {
  64826. gradient = 0;
  64827. image = 0;
  64828. colour = newColour;
  64829. }
  64830. void FillType::setGradient (const ColourGradient& newGradient) throw()
  64831. {
  64832. if (gradient != 0)
  64833. {
  64834. *gradient = newGradient;
  64835. }
  64836. else
  64837. {
  64838. image = 0;
  64839. gradient = new ColourGradient (newGradient);
  64840. colour = Colours::black;
  64841. }
  64842. }
  64843. void FillType::setTiledImage (const Image& image_, const AffineTransform& transform_) throw()
  64844. {
  64845. gradient = 0;
  64846. image = &image_;
  64847. transform = transform_;
  64848. colour = Colours::black;
  64849. }
  64850. void FillType::setOpacity (const float newOpacity) throw()
  64851. {
  64852. colour = colour.withAlpha (newOpacity);
  64853. }
  64854. END_JUCE_NAMESPACE
  64855. /*** End of inlined file: juce_FillType.cpp ***/
  64856. /*** Start of inlined file: juce_Graphics.cpp ***/
  64857. BEGIN_JUCE_NAMESPACE
  64858. static const Graphics::ResamplingQuality defaultQuality = Graphics::mediumResamplingQuality;
  64859. template <typename Type>
  64860. static bool areCoordsSensibleNumbers (Type x, Type y, Type w, Type h)
  64861. {
  64862. const int maxVal = 0x3fffffff;
  64863. return (int) x >= -maxVal && (int) x <= maxVal
  64864. && (int) y >= -maxVal && (int) y <= maxVal
  64865. && (int) w >= -maxVal && (int) w <= maxVal
  64866. && (int) h >= -maxVal && (int) h <= maxVal;
  64867. }
  64868. LowLevelGraphicsContext::LowLevelGraphicsContext()
  64869. {
  64870. }
  64871. LowLevelGraphicsContext::~LowLevelGraphicsContext()
  64872. {
  64873. }
  64874. Graphics::Graphics (Image& imageToDrawOnto) throw()
  64875. : context (imageToDrawOnto.createLowLevelContext()),
  64876. contextToDelete (context),
  64877. saveStatePending (false)
  64878. {
  64879. resetToDefaultState();
  64880. }
  64881. Graphics::Graphics (LowLevelGraphicsContext* const internalContext) throw()
  64882. : context (internalContext),
  64883. saveStatePending (false)
  64884. {
  64885. resetToDefaultState();
  64886. }
  64887. Graphics::~Graphics() throw()
  64888. {
  64889. }
  64890. void Graphics::resetToDefaultState() throw()
  64891. {
  64892. saveStateIfPending();
  64893. context->setFill (FillType());
  64894. context->setFont (Font());
  64895. context->setInterpolationQuality (defaultQuality);
  64896. }
  64897. bool Graphics::isVectorDevice() const throw()
  64898. {
  64899. return context->isVectorDevice();
  64900. }
  64901. bool Graphics::reduceClipRegion (const int x, const int y,
  64902. const int w, const int h) throw()
  64903. {
  64904. saveStateIfPending();
  64905. return context->clipToRectangle (Rectangle<int> (x, y, w, h));
  64906. }
  64907. bool Graphics::reduceClipRegion (const RectangleList& clipRegion) throw()
  64908. {
  64909. saveStateIfPending();
  64910. return context->clipToRectangleList (clipRegion);
  64911. }
  64912. bool Graphics::reduceClipRegion (const Path& path, const AffineTransform& transform) throw()
  64913. {
  64914. saveStateIfPending();
  64915. context->clipToPath (path, transform);
  64916. return ! context->isClipEmpty();
  64917. }
  64918. bool Graphics::reduceClipRegion (const Image& image, const Rectangle<int>& sourceClipRegion, const AffineTransform& transform) throw()
  64919. {
  64920. saveStateIfPending();
  64921. context->clipToImageAlpha (image, sourceClipRegion, transform);
  64922. return ! context->isClipEmpty();
  64923. }
  64924. void Graphics::excludeClipRegion (const int x, const int y,
  64925. const int w, const int h) throw()
  64926. {
  64927. saveStateIfPending();
  64928. context->excludeClipRectangle (Rectangle<int> (x, y, w, h));
  64929. }
  64930. bool Graphics::isClipEmpty() const throw()
  64931. {
  64932. return context->isClipEmpty();
  64933. }
  64934. const Rectangle<int> Graphics::getClipBounds() const throw()
  64935. {
  64936. return context->getClipBounds();
  64937. }
  64938. void Graphics::saveState() throw()
  64939. {
  64940. saveStateIfPending();
  64941. saveStatePending = true;
  64942. }
  64943. void Graphics::restoreState() throw()
  64944. {
  64945. if (saveStatePending)
  64946. saveStatePending = false;
  64947. else
  64948. context->restoreState();
  64949. }
  64950. void Graphics::saveStateIfPending() throw()
  64951. {
  64952. if (saveStatePending)
  64953. {
  64954. saveStatePending = false;
  64955. context->saveState();
  64956. }
  64957. }
  64958. void Graphics::setOrigin (const int newOriginX,
  64959. const int newOriginY) throw()
  64960. {
  64961. saveStateIfPending();
  64962. context->setOrigin (newOriginX, newOriginY);
  64963. }
  64964. bool Graphics::clipRegionIntersects (const int x, const int y,
  64965. const int w, const int h) const throw()
  64966. {
  64967. return context->clipRegionIntersects (Rectangle<int> (x, y, w, h));
  64968. }
  64969. void Graphics::setColour (const Colour& newColour) throw()
  64970. {
  64971. saveStateIfPending();
  64972. context->setFill (FillType (newColour));
  64973. }
  64974. void Graphics::setOpacity (const float newOpacity) throw()
  64975. {
  64976. saveStateIfPending();
  64977. context->setOpacity (newOpacity);
  64978. }
  64979. void Graphics::setGradientFill (const ColourGradient& gradient) throw()
  64980. {
  64981. saveStateIfPending();
  64982. context->setFill (FillType (gradient));
  64983. }
  64984. void Graphics::setTiledImageFill (const Image& imageToUse,
  64985. const int anchorX,
  64986. const int anchorY,
  64987. const float opacity) throw()
  64988. {
  64989. saveStateIfPending();
  64990. context->setFill (FillType (imageToUse, AffineTransform::translation ((float) anchorX, (float) anchorY)));
  64991. context->setOpacity (opacity);
  64992. }
  64993. void Graphics::setFillType (const FillType& newFill) throw()
  64994. {
  64995. saveStateIfPending();
  64996. context->setFill (newFill);
  64997. }
  64998. void Graphics::setFont (const Font& newFont) throw()
  64999. {
  65000. saveStateIfPending();
  65001. context->setFont (newFont);
  65002. }
  65003. void Graphics::setFont (const float newFontHeight,
  65004. const int newFontStyleFlags) throw()
  65005. {
  65006. saveStateIfPending();
  65007. Font f (context->getFont());
  65008. f.setSizeAndStyle (newFontHeight, newFontStyleFlags, 1.0f, 0);
  65009. context->setFont (f);
  65010. }
  65011. void Graphics::drawSingleLineText (const String& text,
  65012. const int startX,
  65013. const int baselineY) const throw()
  65014. {
  65015. if (text.isNotEmpty()
  65016. && startX < context->getClipBounds().getRight())
  65017. {
  65018. GlyphArrangement arr;
  65019. arr.addLineOfText (context->getFont(), text, (float) startX, (float) baselineY);
  65020. arr.draw (*this);
  65021. }
  65022. }
  65023. void Graphics::drawTextAsPath (const String& text,
  65024. const AffineTransform& transform) const throw()
  65025. {
  65026. if (text.isNotEmpty())
  65027. {
  65028. GlyphArrangement arr;
  65029. arr.addLineOfText (context->getFont(), text, 0.0f, 0.0f);
  65030. arr.draw (*this, transform);
  65031. }
  65032. }
  65033. void Graphics::drawMultiLineText (const String& text,
  65034. const int startX,
  65035. const int baselineY,
  65036. const int maximumLineWidth) const throw()
  65037. {
  65038. if (text.isNotEmpty()
  65039. && startX < context->getClipBounds().getRight())
  65040. {
  65041. GlyphArrangement arr;
  65042. arr.addJustifiedText (context->getFont(), text,
  65043. (float) startX, (float) baselineY, (float) maximumLineWidth,
  65044. Justification::left);
  65045. arr.draw (*this);
  65046. }
  65047. }
  65048. void Graphics::drawText (const String& text,
  65049. const int x,
  65050. const int y,
  65051. const int width,
  65052. const int height,
  65053. const Justification& justificationType,
  65054. const bool useEllipsesIfTooBig) const throw()
  65055. {
  65056. if (text.isNotEmpty() && context->clipRegionIntersects (Rectangle<int> (x, y, width, height)))
  65057. {
  65058. GlyphArrangement arr;
  65059. arr.addCurtailedLineOfText (context->getFont(), text,
  65060. 0.0f, 0.0f, (float)width,
  65061. useEllipsesIfTooBig);
  65062. arr.justifyGlyphs (0, arr.getNumGlyphs(),
  65063. (float) x, (float) y,
  65064. (float) width, (float) height,
  65065. justificationType);
  65066. arr.draw (*this);
  65067. }
  65068. }
  65069. void Graphics::drawFittedText (const String& text,
  65070. const int x,
  65071. const int y,
  65072. const int width,
  65073. const int height,
  65074. const Justification& justification,
  65075. const int maximumNumberOfLines,
  65076. const float minimumHorizontalScale) const throw()
  65077. {
  65078. if (text.isNotEmpty()
  65079. && width > 0 && height > 0
  65080. && context->clipRegionIntersects (Rectangle<int> (x, y, width, height)))
  65081. {
  65082. GlyphArrangement arr;
  65083. arr.addFittedText (context->getFont(), text,
  65084. (float) x, (float) y,
  65085. (float) width, (float) height,
  65086. justification,
  65087. maximumNumberOfLines,
  65088. minimumHorizontalScale);
  65089. arr.draw (*this);
  65090. }
  65091. }
  65092. void Graphics::fillRect (int x,
  65093. int y,
  65094. int width,
  65095. int height) const throw()
  65096. {
  65097. // passing in a silly number can cause maths problems in rendering!
  65098. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65099. context->fillRect (Rectangle<int> (x, y, width, height), false);
  65100. }
  65101. void Graphics::fillRect (const Rectangle<int>& r) const throw()
  65102. {
  65103. context->fillRect (r, false);
  65104. }
  65105. void Graphics::fillRect (const float x,
  65106. const float y,
  65107. const float width,
  65108. const float height) const throw()
  65109. {
  65110. // passing in a silly number can cause maths problems in rendering!
  65111. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65112. Path p;
  65113. p.addRectangle (x, y, width, height);
  65114. fillPath (p);
  65115. }
  65116. void Graphics::setPixel (int x, int y) const throw()
  65117. {
  65118. context->fillRect (Rectangle<int> (x, y, 1, 1), false);
  65119. }
  65120. void Graphics::fillAll() const throw()
  65121. {
  65122. fillRect (context->getClipBounds());
  65123. }
  65124. void Graphics::fillAll (const Colour& colourToUse) const throw()
  65125. {
  65126. if (! colourToUse.isTransparent())
  65127. {
  65128. const Rectangle<int> clip (context->getClipBounds());
  65129. context->saveState();
  65130. context->setFill (FillType (colourToUse));
  65131. context->fillRect (clip, false);
  65132. context->restoreState();
  65133. }
  65134. }
  65135. void Graphics::fillPath (const Path& path,
  65136. const AffineTransform& transform) const throw()
  65137. {
  65138. if ((! context->isClipEmpty()) && ! path.isEmpty())
  65139. context->fillPath (path, transform);
  65140. }
  65141. void Graphics::strokePath (const Path& path,
  65142. const PathStrokeType& strokeType,
  65143. const AffineTransform& transform) const throw()
  65144. {
  65145. Path stroke;
  65146. strokeType.createStrokedPath (stroke, path, transform);
  65147. fillPath (stroke);
  65148. }
  65149. void Graphics::drawRect (const int x,
  65150. const int y,
  65151. const int width,
  65152. const int height,
  65153. const int lineThickness) const throw()
  65154. {
  65155. // passing in a silly number can cause maths problems in rendering!
  65156. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65157. context->fillRect (Rectangle<int> (x, y, width, lineThickness), false);
  65158. context->fillRect (Rectangle<int> (x, y + lineThickness, lineThickness, height - lineThickness * 2), false);
  65159. context->fillRect (Rectangle<int> (x + width - lineThickness, y + lineThickness, lineThickness, height - lineThickness * 2), false);
  65160. context->fillRect (Rectangle<int> (x, y + height - lineThickness, width, lineThickness), false);
  65161. }
  65162. void Graphics::drawRect (const float x,
  65163. const float y,
  65164. const float width,
  65165. const float height,
  65166. const float lineThickness) const throw()
  65167. {
  65168. // passing in a silly number can cause maths problems in rendering!
  65169. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65170. Path p;
  65171. p.addRectangle (x, y, width, lineThickness);
  65172. p.addRectangle (x, y + lineThickness, lineThickness, height - lineThickness * 2.0f);
  65173. p.addRectangle (x + width - lineThickness, y + lineThickness, lineThickness, height - lineThickness * 2.0f);
  65174. p.addRectangle (x, y + height - lineThickness, width, lineThickness);
  65175. fillPath (p);
  65176. }
  65177. void Graphics::drawRect (const Rectangle<int>& r,
  65178. const int lineThickness) const throw()
  65179. {
  65180. drawRect (r.getX(), r.getY(),
  65181. r.getWidth(), r.getHeight(),
  65182. lineThickness);
  65183. }
  65184. void Graphics::drawBevel (const int x,
  65185. const int y,
  65186. const int width,
  65187. const int height,
  65188. const int bevelThickness,
  65189. const Colour& topLeftColour,
  65190. const Colour& bottomRightColour,
  65191. const bool useGradient,
  65192. const bool sharpEdgeOnOutside) const throw()
  65193. {
  65194. // passing in a silly number can cause maths problems in rendering!
  65195. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65196. if (clipRegionIntersects (x, y, width, height))
  65197. {
  65198. context->saveState();
  65199. const float oldOpacity = 1.0f;//xxx state->colour.getFloatAlpha();
  65200. const float ramp = oldOpacity / bevelThickness;
  65201. for (int i = bevelThickness; --i >= 0;)
  65202. {
  65203. const float op = useGradient ? ramp * (sharpEdgeOnOutside ? bevelThickness - i : i)
  65204. : oldOpacity;
  65205. context->setFill (FillType (topLeftColour.withMultipliedAlpha (op)));
  65206. context->fillRect (Rectangle<int> (x + i, y + i, width - i * 2, 1), false);
  65207. context->setFill (FillType (topLeftColour.withMultipliedAlpha (op * 0.75f)));
  65208. context->fillRect (Rectangle<int> (x + i, y + i + 1, 1, height - i * 2 - 2), false);
  65209. context->setFill (FillType (bottomRightColour.withMultipliedAlpha (op)));
  65210. context->fillRect (Rectangle<int> (x + i, y + height - i - 1, width - i * 2, 1), false);
  65211. context->setFill (FillType (bottomRightColour.withMultipliedAlpha (op * 0.75f)));
  65212. context->fillRect (Rectangle<int> (x + width - i - 1, y + i + 1, 1, height - i * 2 - 2), false);
  65213. }
  65214. context->restoreState();
  65215. }
  65216. }
  65217. void Graphics::fillEllipse (const float x,
  65218. const float y,
  65219. const float width,
  65220. const float height) const throw()
  65221. {
  65222. // passing in a silly number can cause maths problems in rendering!
  65223. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65224. Path p;
  65225. p.addEllipse (x, y, width, height);
  65226. fillPath (p);
  65227. }
  65228. void Graphics::drawEllipse (const float x,
  65229. const float y,
  65230. const float width,
  65231. const float height,
  65232. const float lineThickness) const throw()
  65233. {
  65234. // passing in a silly number can cause maths problems in rendering!
  65235. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65236. Path p;
  65237. p.addEllipse (x, y, width, height);
  65238. strokePath (p, PathStrokeType (lineThickness));
  65239. }
  65240. void Graphics::fillRoundedRectangle (const float x,
  65241. const float y,
  65242. const float width,
  65243. const float height,
  65244. const float cornerSize) const throw()
  65245. {
  65246. // passing in a silly number can cause maths problems in rendering!
  65247. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65248. Path p;
  65249. p.addRoundedRectangle (x, y, width, height, cornerSize);
  65250. fillPath (p);
  65251. }
  65252. void Graphics::fillRoundedRectangle (const Rectangle<int>& r,
  65253. const float cornerSize) const throw()
  65254. {
  65255. fillRoundedRectangle ((float) r.getX(),
  65256. (float) r.getY(),
  65257. (float) r.getWidth(),
  65258. (float) r.getHeight(),
  65259. cornerSize);
  65260. }
  65261. void Graphics::drawRoundedRectangle (const float x,
  65262. const float y,
  65263. const float width,
  65264. const float height,
  65265. const float cornerSize,
  65266. const float lineThickness) const throw()
  65267. {
  65268. // passing in a silly number can cause maths problems in rendering!
  65269. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65270. Path p;
  65271. p.addRoundedRectangle (x, y, width, height, cornerSize);
  65272. strokePath (p, PathStrokeType (lineThickness));
  65273. }
  65274. void Graphics::drawRoundedRectangle (const Rectangle<int>& r,
  65275. const float cornerSize,
  65276. const float lineThickness) const throw()
  65277. {
  65278. drawRoundedRectangle ((float) r.getX(),
  65279. (float) r.getY(),
  65280. (float) r.getWidth(),
  65281. (float) r.getHeight(),
  65282. cornerSize, lineThickness);
  65283. }
  65284. void Graphics::drawArrow (const float startX,
  65285. const float startY,
  65286. const float endX,
  65287. const float endY,
  65288. const float lineThickness,
  65289. const float arrowheadWidth,
  65290. const float arrowheadLength) const throw()
  65291. {
  65292. Path p;
  65293. p.addArrow (startX, startY, endX, endY,
  65294. lineThickness, arrowheadWidth, arrowheadLength);
  65295. fillPath (p);
  65296. }
  65297. void Graphics::fillCheckerBoard (int x, int y,
  65298. int width, int height,
  65299. const int checkWidth,
  65300. const int checkHeight,
  65301. const Colour& colour1,
  65302. const Colour& colour2) const throw()
  65303. {
  65304. jassert (checkWidth > 0 && checkHeight > 0); // can't be zero or less!
  65305. if (checkWidth > 0 && checkHeight > 0)
  65306. {
  65307. context->saveState();
  65308. if (colour1 == colour2)
  65309. {
  65310. context->setFill (FillType (colour1));
  65311. context->fillRect (Rectangle<int> (x, y, width, height), false);
  65312. }
  65313. else
  65314. {
  65315. const Rectangle<int> clip (context->getClipBounds());
  65316. const int right = jmin (x + width, clip.getRight());
  65317. const int bottom = jmin (y + height, clip.getBottom());
  65318. int cy = 0;
  65319. while (y < bottom)
  65320. {
  65321. int cx = cy;
  65322. for (int xx = x; xx < right; xx += checkWidth)
  65323. {
  65324. context->setFill (FillType (((cx++ & 1) == 0) ? colour1 : colour2));
  65325. context->fillRect (Rectangle<int> (xx, y, jmin (checkWidth, right - xx), jmin (checkHeight, bottom - y)),
  65326. false);
  65327. }
  65328. ++cy;
  65329. y += checkHeight;
  65330. }
  65331. }
  65332. context->restoreState();
  65333. }
  65334. }
  65335. void Graphics::drawVerticalLine (const int x, float top, float bottom) const throw()
  65336. {
  65337. context->drawVerticalLine (x, top, bottom);
  65338. }
  65339. void Graphics::drawHorizontalLine (const int y, float left, float right) const throw()
  65340. {
  65341. context->drawHorizontalLine (y, left, right);
  65342. }
  65343. void Graphics::drawLine (float x1, float y1, float x2, float y2) const throw()
  65344. {
  65345. context->drawLine (x1, y1, x2, y2);
  65346. }
  65347. void Graphics::drawLine (const float startX,
  65348. const float startY,
  65349. const float endX,
  65350. const float endY,
  65351. const float lineThickness) const throw()
  65352. {
  65353. Path p;
  65354. p.addLineSegment (startX, startY, endX, endY, lineThickness);
  65355. fillPath (p);
  65356. }
  65357. void Graphics::drawLine (const Line& line) const throw()
  65358. {
  65359. drawLine (line.getStartX(), line.getStartY(), line.getEndX(), line.getEndY());
  65360. }
  65361. void Graphics::drawLine (const Line& line,
  65362. const float lineThickness) const throw()
  65363. {
  65364. drawLine (line.getStartX(), line.getStartY(), line.getEndX(), line.getEndY(), lineThickness);
  65365. }
  65366. void Graphics::drawDashedLine (const float startX,
  65367. const float startY,
  65368. const float endX,
  65369. const float endY,
  65370. const float* const dashLengths,
  65371. const int numDashLengths,
  65372. const float lineThickness) const throw()
  65373. {
  65374. const double dx = endX - startX;
  65375. const double dy = endY - startY;
  65376. const double totalLen = juce_hypot (dx, dy);
  65377. if (totalLen >= 0.5)
  65378. {
  65379. const double onePixAlpha = 1.0 / totalLen;
  65380. double alpha = 0.0;
  65381. float x = startX;
  65382. float y = startY;
  65383. int n = 0;
  65384. while (alpha < 1.0f)
  65385. {
  65386. alpha = jmin (1.0, alpha + dashLengths[n++] * onePixAlpha);
  65387. n = n % numDashLengths;
  65388. const float oldX = x;
  65389. const float oldY = y;
  65390. x = (float) (startX + dx * alpha);
  65391. y = (float) (startY + dy * alpha);
  65392. if ((n & 1) != 0)
  65393. {
  65394. if (lineThickness != 1.0f)
  65395. drawLine (oldX, oldY, x, y, lineThickness);
  65396. else
  65397. drawLine (oldX, oldY, x, y);
  65398. }
  65399. }
  65400. }
  65401. }
  65402. void Graphics::setImageResamplingQuality (const Graphics::ResamplingQuality newQuality) throw()
  65403. {
  65404. saveStateIfPending();
  65405. context->setInterpolationQuality (newQuality);
  65406. }
  65407. void Graphics::drawImageAt (const Image* const imageToDraw,
  65408. const int topLeftX,
  65409. const int topLeftY,
  65410. const bool fillAlphaChannelWithCurrentBrush) const throw()
  65411. {
  65412. if (imageToDraw != 0)
  65413. {
  65414. const int imageW = imageToDraw->getWidth();
  65415. const int imageH = imageToDraw->getHeight();
  65416. drawImage (imageToDraw,
  65417. topLeftX, topLeftY, imageW, imageH,
  65418. 0, 0, imageW, imageH,
  65419. fillAlphaChannelWithCurrentBrush);
  65420. }
  65421. }
  65422. void Graphics::drawImageWithin (const Image* const imageToDraw,
  65423. const int destX,
  65424. const int destY,
  65425. const int destW,
  65426. const int destH,
  65427. const RectanglePlacement& placementWithinTarget,
  65428. const bool fillAlphaChannelWithCurrentBrush) const throw()
  65429. {
  65430. // passing in a silly number can cause maths problems in rendering!
  65431. jassert (areCoordsSensibleNumbers (destX, destY, destW, destH));
  65432. if (imageToDraw != 0)
  65433. {
  65434. const int imageW = imageToDraw->getWidth();
  65435. const int imageH = imageToDraw->getHeight();
  65436. if (imageW > 0 && imageH > 0)
  65437. {
  65438. double newX = 0.0, newY = 0.0;
  65439. double newW = imageW;
  65440. double newH = imageH;
  65441. placementWithinTarget.applyTo (newX, newY, newW, newH,
  65442. destX, destY, destW, destH);
  65443. if (newW > 0 && newH > 0)
  65444. {
  65445. drawImage (imageToDraw,
  65446. roundToInt (newX), roundToInt (newY),
  65447. roundToInt (newW), roundToInt (newH),
  65448. 0, 0, imageW, imageH,
  65449. fillAlphaChannelWithCurrentBrush);
  65450. }
  65451. }
  65452. }
  65453. }
  65454. void Graphics::drawImage (const Image* const imageToDraw,
  65455. int dx, int dy, int dw, int dh,
  65456. int sx, int sy, int sw, int sh,
  65457. const bool fillAlphaChannelWithCurrentBrush) const throw()
  65458. {
  65459. // passing in a silly number can cause maths problems in rendering!
  65460. jassert (areCoordsSensibleNumbers (dx, dy, dw, dh));
  65461. jassert (areCoordsSensibleNumbers (sx, sy, sw, sh));
  65462. if (context->clipRegionIntersects (Rectangle<int> (dx, dy, dw, dh)))
  65463. {
  65464. drawImageTransformed (imageToDraw, Rectangle<int> (sx, sy, sw, sh),
  65465. AffineTransform::scale (dw / (float) sw, dh / (float) sh)
  65466. .translated ((float) dx, (float) dy),
  65467. fillAlphaChannelWithCurrentBrush);
  65468. }
  65469. }
  65470. void Graphics::drawImageTransformed (const Image* const imageToDraw,
  65471. const Rectangle<int>& imageSubRegion,
  65472. const AffineTransform& transform,
  65473. const bool fillAlphaChannelWithCurrentBrush) const throw()
  65474. {
  65475. if (imageToDraw != 0 && ! context->isClipEmpty())
  65476. {
  65477. const Rectangle<int> srcClip (imageSubRegion.getIntersection (imageToDraw->getBounds()));
  65478. if (fillAlphaChannelWithCurrentBrush)
  65479. {
  65480. context->saveState();
  65481. context->clipToImageAlpha (*imageToDraw, srcClip, transform);
  65482. fillAll();
  65483. context->restoreState();
  65484. }
  65485. else
  65486. {
  65487. context->drawImage (*imageToDraw, srcClip, transform, false);
  65488. }
  65489. }
  65490. }
  65491. END_JUCE_NAMESPACE
  65492. /*** End of inlined file: juce_Graphics.cpp ***/
  65493. /*** Start of inlined file: juce_Justification.cpp ***/
  65494. BEGIN_JUCE_NAMESPACE
  65495. Justification::Justification (const Justification& other) throw()
  65496. : flags (other.flags)
  65497. {
  65498. }
  65499. const Justification& Justification::operator= (const Justification& other) throw()
  65500. {
  65501. flags = other.flags;
  65502. return *this;
  65503. }
  65504. int Justification::getOnlyVerticalFlags() const throw()
  65505. {
  65506. return flags & (top | bottom | verticallyCentred);
  65507. }
  65508. int Justification::getOnlyHorizontalFlags() const throw()
  65509. {
  65510. return flags & (left | right | horizontallyCentred | horizontallyJustified);
  65511. }
  65512. void Justification::applyToRectangle (int& x, int& y,
  65513. const int w, const int h,
  65514. const int spaceX, const int spaceY,
  65515. const int spaceW, const int spaceH) const throw()
  65516. {
  65517. if ((flags & horizontallyCentred) != 0)
  65518. {
  65519. x = spaceX + ((spaceW - w) >> 1);
  65520. }
  65521. else if ((flags & right) != 0)
  65522. {
  65523. x = spaceX + spaceW - w;
  65524. }
  65525. else
  65526. {
  65527. x = spaceX;
  65528. }
  65529. if ((flags & verticallyCentred) != 0)
  65530. {
  65531. y = spaceY + ((spaceH - h) >> 1);
  65532. }
  65533. else if ((flags & bottom) != 0)
  65534. {
  65535. y = spaceY + spaceH - h;
  65536. }
  65537. else
  65538. {
  65539. y = spaceY;
  65540. }
  65541. }
  65542. END_JUCE_NAMESPACE
  65543. /*** End of inlined file: juce_Justification.cpp ***/
  65544. /*** Start of inlined file: juce_LowLevelGraphicsPostScriptRenderer.cpp ***/
  65545. BEGIN_JUCE_NAMESPACE
  65546. // this will throw an assertion if you try to draw something that's not
  65547. // possible in postscript
  65548. #define WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS 0
  65549. #if defined (JUCE_DEBUG) && WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS
  65550. #define notPossibleInPostscriptAssert jassertfalse
  65551. #else
  65552. #define notPossibleInPostscriptAssert
  65553. #endif
  65554. LowLevelGraphicsPostScriptRenderer::LowLevelGraphicsPostScriptRenderer (OutputStream& resultingPostScript,
  65555. const String& documentTitle,
  65556. const int totalWidth_,
  65557. const int totalHeight_)
  65558. : out (resultingPostScript),
  65559. totalWidth (totalWidth_),
  65560. totalHeight (totalHeight_),
  65561. needToClip (true)
  65562. {
  65563. stateStack.add (new SavedState());
  65564. stateStack.getLast()->clip = Rectangle<int> (0, 0, totalWidth_, totalHeight_);
  65565. const float scale = jmin ((520.0f / totalWidth_), (750.0f / totalHeight));
  65566. out << "%!PS-Adobe-3.0 EPSF-3.0"
  65567. "\n%%BoundingBox: 0 0 600 824"
  65568. "\n%%Pages: 0"
  65569. "\n%%Creator: Raw Material Software JUCE"
  65570. "\n%%Title: " << documentTitle <<
  65571. "\n%%CreationDate: none"
  65572. "\n%%LanguageLevel: 2"
  65573. "\n%%EndComments"
  65574. "\n%%BeginProlog"
  65575. "\n%%BeginResource: JRes"
  65576. "\n/bd {bind def} bind def"
  65577. "\n/c {setrgbcolor} bd"
  65578. "\n/m {moveto} bd"
  65579. "\n/l {lineto} bd"
  65580. "\n/rl {rlineto} bd"
  65581. "\n/ct {curveto} bd"
  65582. "\n/cp {closepath} bd"
  65583. "\n/pr {3 index 3 index moveto 1 index 0 rlineto 0 1 index rlineto pop neg 0 rlineto pop pop closepath} bd"
  65584. "\n/doclip {initclip newpath} bd"
  65585. "\n/endclip {clip newpath} bd"
  65586. "\n%%EndResource"
  65587. "\n%%EndProlog"
  65588. "\n%%BeginSetup"
  65589. "\n%%EndSetup"
  65590. "\n%%Page: 1 1"
  65591. "\n%%BeginPageSetup"
  65592. "\n%%EndPageSetup\n\n"
  65593. << "40 800 translate\n"
  65594. << scale << ' ' << scale << " scale\n\n";
  65595. }
  65596. LowLevelGraphicsPostScriptRenderer::~LowLevelGraphicsPostScriptRenderer()
  65597. {
  65598. }
  65599. bool LowLevelGraphicsPostScriptRenderer::isVectorDevice() const
  65600. {
  65601. return true;
  65602. }
  65603. void LowLevelGraphicsPostScriptRenderer::setOrigin (int x, int y)
  65604. {
  65605. if (x != 0 || y != 0)
  65606. {
  65607. stateStack.getLast()->xOffset += x;
  65608. stateStack.getLast()->yOffset += y;
  65609. needToClip = true;
  65610. }
  65611. }
  65612. bool LowLevelGraphicsPostScriptRenderer::clipToRectangle (const Rectangle<int>& r)
  65613. {
  65614. needToClip = true;
  65615. return stateStack.getLast()->clip.clipTo (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65616. }
  65617. bool LowLevelGraphicsPostScriptRenderer::clipToRectangleList (const RectangleList& clipRegion)
  65618. {
  65619. needToClip = true;
  65620. return stateStack.getLast()->clip.clipTo (clipRegion);
  65621. }
  65622. void LowLevelGraphicsPostScriptRenderer::excludeClipRectangle (const Rectangle<int>& r)
  65623. {
  65624. needToClip = true;
  65625. stateStack.getLast()->clip.subtract (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65626. }
  65627. void LowLevelGraphicsPostScriptRenderer::clipToPath (const Path& path, const AffineTransform& transform)
  65628. {
  65629. writeClip();
  65630. Path p (path);
  65631. p.applyTransform (transform.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset));
  65632. writePath (p);
  65633. out << "clip\n";
  65634. }
  65635. void LowLevelGraphicsPostScriptRenderer::clipToImageAlpha (const Image& /*sourceImage*/, const Rectangle<int>& /*srcClip*/, const AffineTransform& /*transform*/)
  65636. {
  65637. needToClip = true;
  65638. jassertfalse // xxx
  65639. }
  65640. bool LowLevelGraphicsPostScriptRenderer::clipRegionIntersects (const Rectangle<int>& r)
  65641. {
  65642. return stateStack.getLast()->clip.intersectsRectangle (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65643. }
  65644. const Rectangle<int> LowLevelGraphicsPostScriptRenderer::getClipBounds() const
  65645. {
  65646. return stateStack.getLast()->clip.getBounds().translated (-stateStack.getLast()->xOffset,
  65647. -stateStack.getLast()->yOffset);
  65648. }
  65649. bool LowLevelGraphicsPostScriptRenderer::isClipEmpty() const
  65650. {
  65651. return stateStack.getLast()->clip.isEmpty();
  65652. }
  65653. LowLevelGraphicsPostScriptRenderer::SavedState::SavedState()
  65654. : xOffset (0),
  65655. yOffset (0)
  65656. {
  65657. }
  65658. LowLevelGraphicsPostScriptRenderer::SavedState::~SavedState()
  65659. {
  65660. }
  65661. void LowLevelGraphicsPostScriptRenderer::saveState()
  65662. {
  65663. stateStack.add (new SavedState (*stateStack.getLast()));
  65664. }
  65665. void LowLevelGraphicsPostScriptRenderer::restoreState()
  65666. {
  65667. jassert (stateStack.size() > 0);
  65668. if (stateStack.size() > 0)
  65669. stateStack.removeLast();
  65670. }
  65671. void LowLevelGraphicsPostScriptRenderer::writeClip()
  65672. {
  65673. if (needToClip)
  65674. {
  65675. needToClip = false;
  65676. out << "doclip ";
  65677. int itemsOnLine = 0;
  65678. for (RectangleList::Iterator i (stateStack.getLast()->clip); i.next();)
  65679. {
  65680. if (++itemsOnLine == 6)
  65681. {
  65682. itemsOnLine = 0;
  65683. out << '\n';
  65684. }
  65685. const Rectangle<int>& r = *i.getRectangle();
  65686. out << r.getX() << ' ' << -r.getY() << ' '
  65687. << r.getWidth() << ' ' << -r.getHeight() << " pr ";
  65688. }
  65689. out << "endclip\n";
  65690. }
  65691. }
  65692. void LowLevelGraphicsPostScriptRenderer::writeColour (const Colour& colour)
  65693. {
  65694. Colour c (Colours::white.overlaidWith (colour));
  65695. if (lastColour != c)
  65696. {
  65697. lastColour = c;
  65698. out << String (c.getFloatRed(), 3) << ' '
  65699. << String (c.getFloatGreen(), 3) << ' '
  65700. << String (c.getFloatBlue(), 3) << " c\n";
  65701. }
  65702. }
  65703. void LowLevelGraphicsPostScriptRenderer::writeXY (const float x, const float y) const
  65704. {
  65705. out << String (x, 2) << ' '
  65706. << String (-y, 2) << ' ';
  65707. }
  65708. void LowLevelGraphicsPostScriptRenderer::writePath (const Path& path) const
  65709. {
  65710. out << "newpath ";
  65711. float lastX = 0.0f;
  65712. float lastY = 0.0f;
  65713. int itemsOnLine = 0;
  65714. Path::Iterator i (path);
  65715. while (i.next())
  65716. {
  65717. if (++itemsOnLine == 4)
  65718. {
  65719. itemsOnLine = 0;
  65720. out << '\n';
  65721. }
  65722. switch (i.elementType)
  65723. {
  65724. case Path::Iterator::startNewSubPath:
  65725. writeXY (i.x1, i.y1);
  65726. lastX = i.x1;
  65727. lastY = i.y1;
  65728. out << "m ";
  65729. break;
  65730. case Path::Iterator::lineTo:
  65731. writeXY (i.x1, i.y1);
  65732. lastX = i.x1;
  65733. lastY = i.y1;
  65734. out << "l ";
  65735. break;
  65736. case Path::Iterator::quadraticTo:
  65737. {
  65738. const float cp1x = lastX + (i.x1 - lastX) * 2.0f / 3.0f;
  65739. const float cp1y = lastY + (i.y1 - lastY) * 2.0f / 3.0f;
  65740. const float cp2x = cp1x + (i.x2 - lastX) / 3.0f;
  65741. const float cp2y = cp1y + (i.y2 - lastY) / 3.0f;
  65742. writeXY (cp1x, cp1y);
  65743. writeXY (cp2x, cp2y);
  65744. writeXY (i.x2, i.y2);
  65745. out << "ct ";
  65746. lastX = i.x2;
  65747. lastY = i.y2;
  65748. }
  65749. break;
  65750. case Path::Iterator::cubicTo:
  65751. writeXY (i.x1, i.y1);
  65752. writeXY (i.x2, i.y2);
  65753. writeXY (i.x3, i.y3);
  65754. out << "ct ";
  65755. lastX = i.x3;
  65756. lastY = i.y3;
  65757. break;
  65758. case Path::Iterator::closePath:
  65759. out << "cp ";
  65760. break;
  65761. default:
  65762. jassertfalse
  65763. break;
  65764. }
  65765. }
  65766. out << '\n';
  65767. }
  65768. void LowLevelGraphicsPostScriptRenderer::writeTransform (const AffineTransform& trans) const
  65769. {
  65770. out << "[ "
  65771. << trans.mat00 << ' '
  65772. << trans.mat10 << ' '
  65773. << trans.mat01 << ' '
  65774. << trans.mat11 << ' '
  65775. << trans.mat02 << ' '
  65776. << trans.mat12 << " ] concat ";
  65777. }
  65778. void LowLevelGraphicsPostScriptRenderer::setFill (const FillType& fillType)
  65779. {
  65780. stateStack.getLast()->fillType = fillType;
  65781. }
  65782. void LowLevelGraphicsPostScriptRenderer::setOpacity (float /*opacity*/)
  65783. {
  65784. }
  65785. void LowLevelGraphicsPostScriptRenderer::setInterpolationQuality (Graphics::ResamplingQuality /*quality*/)
  65786. {
  65787. }
  65788. void LowLevelGraphicsPostScriptRenderer::fillRect (const Rectangle<int>& r, const bool /*replaceExistingContents*/)
  65789. {
  65790. if (stateStack.getLast()->fillType.isColour())
  65791. {
  65792. writeClip();
  65793. writeColour (stateStack.getLast()->fillType.colour);
  65794. Rectangle<int> r2 (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65795. out << r2.getX() << ' ' << -r2.getBottom() << ' ' << r2.getWidth() << ' ' << r2.getHeight() << " rectfill\n";
  65796. }
  65797. else
  65798. {
  65799. Path p;
  65800. p.addRectangle (r);
  65801. fillPath (p, AffineTransform::identity);
  65802. }
  65803. }
  65804. void LowLevelGraphicsPostScriptRenderer::fillPath (const Path& path, const AffineTransform& t)
  65805. {
  65806. if (stateStack.getLast()->fillType.isColour())
  65807. {
  65808. writeClip();
  65809. Path p (path);
  65810. p.applyTransform (t.translated ((float) stateStack.getLast()->xOffset,
  65811. (float) stateStack.getLast()->yOffset));
  65812. writePath (p);
  65813. writeColour (stateStack.getLast()->fillType.colour);
  65814. out << "fill\n";
  65815. }
  65816. else if (stateStack.getLast()->fillType.isGradient())
  65817. {
  65818. // this doesn't work correctly yet - it could be improved to handle solid gradients, but
  65819. // postscript can't do semi-transparent ones.
  65820. notPossibleInPostscriptAssert // you can disable this warning by setting the WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS flag at the top of this file
  65821. writeClip();
  65822. out << "gsave ";
  65823. {
  65824. Path p (path);
  65825. p.applyTransform (t.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset));
  65826. writePath (p);
  65827. out << "clip\n";
  65828. }
  65829. const Rectangle<int> bounds (stateStack.getLast()->clip.getBounds());
  65830. // ideally this would draw lots of lines or ellipses to approximate the gradient, but for the
  65831. // time-being, this just fills it with the average colour..
  65832. writeColour (stateStack.getLast()->fillType.gradient->getColourAtPosition (0.5f));
  65833. out << bounds.getX() << ' ' << -bounds.getBottom() << ' ' << bounds.getWidth() << ' ' << bounds.getHeight() << " rectfill\n";
  65834. out << "grestore\n";
  65835. }
  65836. }
  65837. void LowLevelGraphicsPostScriptRenderer::writeImage (const Image& im,
  65838. const int sx, const int sy,
  65839. const int maxW, const int maxH) const
  65840. {
  65841. out << "{<\n";
  65842. const int w = jmin (maxW, im.getWidth());
  65843. const int h = jmin (maxH, im.getHeight());
  65844. int charsOnLine = 0;
  65845. const Image::BitmapData srcData (im, 0, 0, w, h);
  65846. Colour pixel;
  65847. for (int y = h; --y >= 0;)
  65848. {
  65849. for (int x = 0; x < w; ++x)
  65850. {
  65851. const uint8* pixelData = srcData.getPixelPointer (x, y);
  65852. if (x >= sx && y >= sy)
  65853. {
  65854. if (im.isARGB())
  65855. {
  65856. PixelARGB p (*(const PixelARGB*) pixelData);
  65857. p.unpremultiply();
  65858. pixel = Colours::white.overlaidWith (Colour (p.getARGB()));
  65859. }
  65860. else if (im.isRGB())
  65861. {
  65862. pixel = Colour (((const PixelRGB*) pixelData)->getARGB());
  65863. }
  65864. else
  65865. {
  65866. pixel = Colour ((uint8) 0, (uint8) 0, (uint8) 0, *pixelData);
  65867. }
  65868. }
  65869. else
  65870. {
  65871. pixel = Colours::transparentWhite;
  65872. }
  65873. const uint8 pixelValues[3] = { pixel.getRed(), pixel.getGreen(), pixel.getBlue() };
  65874. out << String::toHexString (pixelValues, 3, 0);
  65875. charsOnLine += 3;
  65876. if (charsOnLine > 100)
  65877. {
  65878. out << '\n';
  65879. charsOnLine = 0;
  65880. }
  65881. }
  65882. }
  65883. out << "\n>}\n";
  65884. }
  65885. void LowLevelGraphicsPostScriptRenderer::drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  65886. const AffineTransform& transform, const bool /*fillEntireClipAsTiles*/)
  65887. {
  65888. const int w = jmin (sourceImage.getWidth(), srcClip.getRight());
  65889. const int h = jmin (sourceImage.getHeight(), srcClip.getBottom());
  65890. writeClip();
  65891. out << "gsave ";
  65892. writeTransform (transform.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset)
  65893. .scaled (1.0f, -1.0f));
  65894. RectangleList imageClip;
  65895. sourceImage.createSolidAreaMask (imageClip, 0.5f);
  65896. imageClip.clipTo (srcClip);
  65897. out << "newpath ";
  65898. int itemsOnLine = 0;
  65899. for (RectangleList::Iterator i (imageClip); i.next();)
  65900. {
  65901. if (++itemsOnLine == 6)
  65902. {
  65903. out << '\n';
  65904. itemsOnLine = 0;
  65905. }
  65906. const Rectangle<int>& r = *i.getRectangle();
  65907. out << r.getX() << ' ' << r.getY() << ' ' << r.getWidth() << ' ' << r.getHeight() << " pr ";
  65908. }
  65909. out << " clip newpath\n";
  65910. out << w << ' ' << h << " scale\n";
  65911. out << w << ' ' << h << " 8 [" << w << " 0 0 -" << h << ' ' << (int) 0 << ' ' << h << " ]\n";
  65912. writeImage (sourceImage, srcClip.getX(), srcClip.getY(), srcClip.getWidth(), srcClip.getHeight());
  65913. out << "false 3 colorimage grestore\n";
  65914. needToClip = true;
  65915. }
  65916. void LowLevelGraphicsPostScriptRenderer::drawLine (double x1, double y1, double x2, double y2)
  65917. {
  65918. Path p;
  65919. p.addLineSegment ((float) x1, (float) y1, (float) x2, (float) y2, 1.0f);
  65920. fillPath (p, AffineTransform::identity);
  65921. }
  65922. void LowLevelGraphicsPostScriptRenderer::drawVerticalLine (const int x, double top, double bottom)
  65923. {
  65924. drawLine (x, top, x, bottom);
  65925. }
  65926. void LowLevelGraphicsPostScriptRenderer::drawHorizontalLine (const int y, double left, double right)
  65927. {
  65928. drawLine (left, y, right, y);
  65929. }
  65930. void LowLevelGraphicsPostScriptRenderer::setFont (const Font& newFont)
  65931. {
  65932. stateStack.getLast()->font = newFont;
  65933. }
  65934. const Font LowLevelGraphicsPostScriptRenderer::getFont()
  65935. {
  65936. return stateStack.getLast()->font;
  65937. }
  65938. void LowLevelGraphicsPostScriptRenderer::drawGlyph (int glyphNumber, const AffineTransform& transform)
  65939. {
  65940. Path p;
  65941. Font& font = stateStack.getLast()->font;
  65942. font.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  65943. fillPath (p, AffineTransform::scale (font.getHeight() * font.getHorizontalScale(), font.getHeight()).followedBy (transform));
  65944. }
  65945. END_JUCE_NAMESPACE
  65946. /*** End of inlined file: juce_LowLevelGraphicsPostScriptRenderer.cpp ***/
  65947. /*** Start of inlined file: juce_LowLevelGraphicsSoftwareRenderer.cpp ***/
  65948. BEGIN_JUCE_NAMESPACE
  65949. #if (JUCE_WINDOWS || JUCE_LINUX) && ! JUCE_64BIT
  65950. #define JUCE_USE_SSE_INSTRUCTIONS 1
  65951. #endif
  65952. #if JUCE_MSVC && JUCE_DEBUG
  65953. #pragma warning (disable: 4714) // warning about forcedinline methods not being inlined
  65954. #endif
  65955. #if JUCE_MSVC
  65956. #pragma warning (push)
  65957. #pragma warning (disable: 4127) // "expression is constant" warning
  65958. #endif
  65959. template <class PixelType, bool replaceExisting = false>
  65960. class SolidColourEdgeTableRenderer
  65961. {
  65962. public:
  65963. SolidColourEdgeTableRenderer (const Image::BitmapData& data_, const PixelARGB& colour) throw()
  65964. : data (data_),
  65965. sourceColour (colour)
  65966. {
  65967. if (sizeof (PixelType) == 3)
  65968. {
  65969. areRGBComponentsEqual = sourceColour.getRed() == sourceColour.getGreen()
  65970. && sourceColour.getGreen() == sourceColour.getBlue();
  65971. filler[0].set (sourceColour);
  65972. filler[1].set (sourceColour);
  65973. filler[2].set (sourceColour);
  65974. filler[3].set (sourceColour);
  65975. }
  65976. }
  65977. forcedinline void setEdgeTableYPos (const int y) throw()
  65978. {
  65979. linePixels = (PixelType*) data.getLinePointer (y);
  65980. }
  65981. forcedinline void handleEdgeTablePixel (const int x, const int alphaLevel) const throw()
  65982. {
  65983. if (replaceExisting)
  65984. linePixels[x].set (sourceColour);
  65985. else
  65986. linePixels[x].blend (sourceColour, alphaLevel);
  65987. }
  65988. forcedinline void handleEdgeTableLine (const int x, int width, const int alphaLevel) const throw()
  65989. {
  65990. PixelARGB p (sourceColour);
  65991. p.multiplyAlpha (alphaLevel);
  65992. PixelType* dest = linePixels + x;
  65993. if (replaceExisting || p.getAlpha() >= 0xff)
  65994. replaceLine (dest, p, width);
  65995. else
  65996. blendLine (dest, p, width);
  65997. }
  65998. private:
  65999. const Image::BitmapData& data;
  66000. PixelType* linePixels;
  66001. PixelARGB sourceColour;
  66002. PixelRGB filler [4];
  66003. bool areRGBComponentsEqual;
  66004. inline void blendLine (PixelType* dest, const PixelARGB& colour, int width) const
  66005. {
  66006. do
  66007. {
  66008. dest->blend (colour);
  66009. ++dest;
  66010. } while (--width > 0);
  66011. }
  66012. forcedinline void replaceLine (PixelRGB* dest, const PixelARGB& colour, int width) const throw()
  66013. {
  66014. if (areRGBComponentsEqual) // if all the component values are the same, we can cheat..
  66015. {
  66016. memset (dest, colour.getRed(), width * 3);
  66017. }
  66018. else
  66019. {
  66020. if (width >> 5)
  66021. {
  66022. const int* const intFiller = (const int*) filler;
  66023. while (width > 8 && (((pointer_sized_int) dest) & 7) != 0)
  66024. {
  66025. dest->set (colour);
  66026. ++dest;
  66027. --width;
  66028. }
  66029. while (width > 4)
  66030. {
  66031. ((int*) dest) [0] = intFiller[0];
  66032. ((int*) dest) [1] = intFiller[1];
  66033. ((int*) dest) [2] = intFiller[2];
  66034. dest = (PixelRGB*) (((uint8*) dest) + 12);
  66035. width -= 4;
  66036. }
  66037. }
  66038. while (--width >= 0)
  66039. {
  66040. dest->set (colour);
  66041. ++dest;
  66042. }
  66043. }
  66044. }
  66045. forcedinline void replaceLine (PixelAlpha* dest, const PixelARGB& colour, int width) const throw()
  66046. {
  66047. memset (dest, colour.getAlpha(), width);
  66048. }
  66049. forcedinline void replaceLine (PixelARGB* dest, const PixelARGB& colour, int width) const throw()
  66050. {
  66051. do
  66052. {
  66053. dest->set (colour);
  66054. ++dest;
  66055. } while (--width > 0);
  66056. }
  66057. SolidColourEdgeTableRenderer (const SolidColourEdgeTableRenderer&);
  66058. const SolidColourEdgeTableRenderer& operator= (const SolidColourEdgeTableRenderer&);
  66059. };
  66060. class LinearGradientPixelGenerator
  66061. {
  66062. public:
  66063. LinearGradientPixelGenerator (const ColourGradient& gradient, const AffineTransform& transform, const PixelARGB* const lookupTable_, const int numEntries_)
  66064. : lookupTable (lookupTable_), numEntries (numEntries_)
  66065. {
  66066. jassert (numEntries_ >= 0);
  66067. float x1 = gradient.x1;
  66068. float y1 = gradient.y1;
  66069. float x2 = gradient.x2;
  66070. float y2 = gradient.y2;
  66071. if (! transform.isIdentity())
  66072. {
  66073. const Line l (x2, y2, x1, y1);
  66074. const Point<float> p3 = l.getPointAlongLine (0.0f, 100.0f);
  66075. float x3 = p3.getX();
  66076. float y3 = p3.getY();
  66077. transform.transformPoint (x1, y1);
  66078. transform.transformPoint (x2, y2);
  66079. transform.transformPoint (x3, y3);
  66080. const Line l2 (x2, y2, x3, y3);
  66081. const float prop = l2.findNearestPointTo (x1, y1);
  66082. const Point<float> newP2 (l2.getPointAlongLineProportionally (prop));
  66083. x2 = newP2.getX();
  66084. y2 = newP2.getY();
  66085. }
  66086. vertical = fabs (x1 - x2) < 0.001f;
  66087. horizontal = fabs (y1 - y2) < 0.001f;
  66088. if (vertical)
  66089. {
  66090. scale = roundToInt ((numEntries << (int) numScaleBits) / (double) (y2 - y1));
  66091. start = roundToInt (y1 * scale);
  66092. }
  66093. else if (horizontal)
  66094. {
  66095. scale = roundToInt ((numEntries << (int) numScaleBits) / (double) (x2 - x1));
  66096. start = roundToInt (x1 * scale);
  66097. }
  66098. else
  66099. {
  66100. grad = (y2 - y1) / (double) (x1 - x2);
  66101. yTerm = y1 - x1 / grad;
  66102. scale = roundToInt ((numEntries << (int) numScaleBits) / (yTerm * grad - (y2 * grad - x2)));
  66103. grad *= scale;
  66104. }
  66105. }
  66106. forcedinline void setY (const int y) throw()
  66107. {
  66108. if (vertical)
  66109. linePix = lookupTable [jlimit (0, numEntries, (y * scale - start) >> (int) numScaleBits)];
  66110. else if (! horizontal)
  66111. start = roundToInt ((y - yTerm) * grad);
  66112. }
  66113. forcedinline const PixelARGB getPixel (const int x) const throw()
  66114. {
  66115. return vertical ? linePix
  66116. : lookupTable [jlimit (0, numEntries, (x * scale - start) >> (int) numScaleBits)];
  66117. }
  66118. private:
  66119. const PixelARGB* const lookupTable;
  66120. const int numEntries;
  66121. PixelARGB linePix;
  66122. int start, scale;
  66123. double grad, yTerm;
  66124. bool vertical, horizontal;
  66125. enum { numScaleBits = 12 };
  66126. LinearGradientPixelGenerator (const LinearGradientPixelGenerator&);
  66127. const LinearGradientPixelGenerator& operator= (const LinearGradientPixelGenerator&);
  66128. };
  66129. class RadialGradientPixelGenerator
  66130. {
  66131. public:
  66132. RadialGradientPixelGenerator (const ColourGradient& gradient, const AffineTransform&,
  66133. const PixelARGB* const lookupTable_, const int numEntries_) throw()
  66134. : lookupTable (lookupTable_),
  66135. numEntries (numEntries_),
  66136. gx1 (gradient.x1),
  66137. gy1 (gradient.y1)
  66138. {
  66139. jassert (numEntries_ >= 0);
  66140. const float gdx = gradient.x1 - gradient.x2;
  66141. const float gdy = gradient.y1 - gradient.y2;
  66142. maxDist = gdx * gdx + gdy * gdy;
  66143. invScale = numEntries / sqrt (maxDist);
  66144. jassert (roundToInt (sqrt (maxDist) * invScale) <= numEntries);
  66145. }
  66146. forcedinline void setY (const int y) throw()
  66147. {
  66148. dy = y - gy1;
  66149. dy *= dy;
  66150. }
  66151. forcedinline const PixelARGB getPixel (const int px) const throw()
  66152. {
  66153. double x = px - gx1;
  66154. x *= x;
  66155. x += dy;
  66156. return lookupTable [x >= maxDist ? numEntries : roundToInt (sqrt (x) * invScale)];
  66157. }
  66158. protected:
  66159. const PixelARGB* const lookupTable;
  66160. const int numEntries;
  66161. const double gx1, gy1;
  66162. double maxDist, invScale, dy;
  66163. RadialGradientPixelGenerator (const RadialGradientPixelGenerator&);
  66164. const RadialGradientPixelGenerator& operator= (const RadialGradientPixelGenerator&);
  66165. };
  66166. class TransformedRadialGradientPixelGenerator : public RadialGradientPixelGenerator
  66167. {
  66168. public:
  66169. TransformedRadialGradientPixelGenerator (const ColourGradient& gradient, const AffineTransform& transform,
  66170. const PixelARGB* const lookupTable_, const int numEntries_) throw()
  66171. : RadialGradientPixelGenerator (gradient, transform, lookupTable_, numEntries_),
  66172. inverseTransform (transform.inverted())
  66173. {
  66174. tM10 = inverseTransform.mat10;
  66175. tM00 = inverseTransform.mat00;
  66176. }
  66177. forcedinline void setY (const int y) throw()
  66178. {
  66179. lineYM01 = inverseTransform.mat01 * y + inverseTransform.mat02 - gx1;
  66180. lineYM11 = inverseTransform.mat11 * y + inverseTransform.mat12 - gy1;
  66181. }
  66182. forcedinline const PixelARGB getPixel (const int px) const throw()
  66183. {
  66184. double x = px;
  66185. const double y = tM10 * x + lineYM11;
  66186. x = tM00 * x + lineYM01;
  66187. x *= x;
  66188. x += y * y;
  66189. if (x >= maxDist)
  66190. return lookupTable [numEntries];
  66191. else
  66192. return lookupTable [jmin (numEntries, roundToInt (sqrt (x) * invScale))];
  66193. }
  66194. private:
  66195. double tM10, tM00, lineYM01, lineYM11;
  66196. const AffineTransform inverseTransform;
  66197. TransformedRadialGradientPixelGenerator (const TransformedRadialGradientPixelGenerator&);
  66198. const TransformedRadialGradientPixelGenerator& operator= (const TransformedRadialGradientPixelGenerator&);
  66199. };
  66200. template <class PixelType, class GradientType>
  66201. class GradientEdgeTableRenderer : public GradientType
  66202. {
  66203. public:
  66204. GradientEdgeTableRenderer (const Image::BitmapData& destData_, const ColourGradient& gradient, const AffineTransform& transform,
  66205. const PixelARGB* const lookupTable_, const int numEntries_) throw()
  66206. : GradientType (gradient, transform, lookupTable_, numEntries_ - 1),
  66207. destData (destData_)
  66208. {
  66209. }
  66210. forcedinline void setEdgeTableYPos (const int y) throw()
  66211. {
  66212. linePixels = (PixelType*) destData.getLinePointer (y);
  66213. GradientType::setY (y);
  66214. }
  66215. forcedinline void handleEdgeTablePixel (const int x, const int alphaLevel) const throw()
  66216. {
  66217. linePixels[x].blend (GradientType::getPixel (x), alphaLevel);
  66218. }
  66219. forcedinline void handleEdgeTableLine (int x, int width, const int alphaLevel) const throw()
  66220. {
  66221. PixelType* dest = linePixels + x;
  66222. if (alphaLevel < 0xff)
  66223. {
  66224. do
  66225. {
  66226. (dest++)->blend (GradientType::getPixel (x++), alphaLevel);
  66227. } while (--width > 0);
  66228. }
  66229. else
  66230. {
  66231. do
  66232. {
  66233. (dest++)->blend (GradientType::getPixel (x++));
  66234. } while (--width > 0);
  66235. }
  66236. }
  66237. private:
  66238. const Image::BitmapData& destData;
  66239. PixelType* linePixels;
  66240. GradientEdgeTableRenderer (const GradientEdgeTableRenderer&);
  66241. const GradientEdgeTableRenderer& operator= (const GradientEdgeTableRenderer&);
  66242. };
  66243. static forcedinline int safeModulo (int n, const int divisor) throw()
  66244. {
  66245. jassert (divisor > 0);
  66246. n %= divisor;
  66247. return (n < 0) ? (n + divisor) : n;
  66248. }
  66249. template <class DestPixelType, class SrcPixelType, bool repeatPattern>
  66250. class ImageFillEdgeTableRenderer
  66251. {
  66252. public:
  66253. ImageFillEdgeTableRenderer (const Image::BitmapData& destData_,
  66254. const Image::BitmapData& srcData_,
  66255. const int extraAlpha_,
  66256. const int x, const int y) throw()
  66257. : destData (destData_),
  66258. srcData (srcData_),
  66259. extraAlpha (extraAlpha_ + 1),
  66260. xOffset (repeatPattern ? safeModulo (x, srcData_.width) - srcData_.width : x),
  66261. yOffset (repeatPattern ? safeModulo (y, srcData_.height) - srcData_.height : y)
  66262. {
  66263. }
  66264. forcedinline void setEdgeTableYPos (int y) throw()
  66265. {
  66266. linePixels = (DestPixelType*) destData.getLinePointer (y);
  66267. y -= yOffset;
  66268. if (repeatPattern)
  66269. {
  66270. jassert (y >= 0);
  66271. y %= srcData.height;
  66272. }
  66273. sourceLineStart = (SrcPixelType*) srcData.getLinePointer (y);
  66274. }
  66275. forcedinline void handleEdgeTablePixel (int x, int alphaLevel) const throw()
  66276. {
  66277. alphaLevel = (alphaLevel * extraAlpha) >> 8;
  66278. linePixels[x].blend (sourceLineStart [repeatPattern ? ((x - xOffset) % srcData.width) : (x - xOffset)], alphaLevel);
  66279. }
  66280. forcedinline void handleEdgeTableLine (int x, int width, int alphaLevel) const throw()
  66281. {
  66282. DestPixelType* dest = linePixels + x;
  66283. alphaLevel = (alphaLevel * extraAlpha) >> 8;
  66284. x -= xOffset;
  66285. jassert (repeatPattern || (x >= 0 && x + width <= srcData.width));
  66286. if (alphaLevel < 0xfe)
  66287. {
  66288. do
  66289. {
  66290. dest++ ->blend (sourceLineStart [repeatPattern ? (x++ % srcData.width) : x++], alphaLevel);
  66291. } while (--width > 0);
  66292. }
  66293. else
  66294. {
  66295. if (repeatPattern)
  66296. {
  66297. do
  66298. {
  66299. dest++ ->blend (sourceLineStart [x++ % srcData.width]);
  66300. } while (--width > 0);
  66301. }
  66302. else
  66303. {
  66304. copyRow (dest, sourceLineStart + x, width);
  66305. }
  66306. }
  66307. }
  66308. void clipEdgeTableLine (EdgeTable& et, int x, int y, int width) throw()
  66309. {
  66310. jassert (x - xOffset >= 0 && x + width - xOffset <= srcData.width);
  66311. SrcPixelType* s = (SrcPixelType*) srcData.getLinePointer (y - yOffset);
  66312. uint8* mask = (uint8*) (s + x - xOffset);
  66313. if (sizeof (SrcPixelType) == sizeof (PixelARGB))
  66314. mask += PixelARGB::indexA;
  66315. et.clipLineToMask (x, y, mask, sizeof (SrcPixelType), width);
  66316. }
  66317. private:
  66318. const Image::BitmapData& destData;
  66319. const Image::BitmapData& srcData;
  66320. const int extraAlpha, xOffset, yOffset;
  66321. DestPixelType* linePixels;
  66322. SrcPixelType* sourceLineStart;
  66323. template <class PixelType1, class PixelType2>
  66324. forcedinline static void copyRow (PixelType1* dest, PixelType2* src, int width) throw()
  66325. {
  66326. do
  66327. {
  66328. dest++ ->blend (*src++);
  66329. } while (--width > 0);
  66330. }
  66331. forcedinline static void copyRow (PixelRGB* dest, PixelRGB* src, int width) throw()
  66332. {
  66333. memcpy (dest, src, width * sizeof (PixelRGB));
  66334. }
  66335. ImageFillEdgeTableRenderer (const ImageFillEdgeTableRenderer&);
  66336. const ImageFillEdgeTableRenderer& operator= (const ImageFillEdgeTableRenderer&);
  66337. };
  66338. template <class DestPixelType, class SrcPixelType, bool repeatPattern>
  66339. class TransformedImageFillEdgeTableRenderer
  66340. {
  66341. public:
  66342. TransformedImageFillEdgeTableRenderer (const Image::BitmapData& destData_,
  66343. const Image::BitmapData& srcData_,
  66344. const AffineTransform& transform,
  66345. const int extraAlpha_,
  66346. const bool betterQuality_) throw()
  66347. : interpolator (transform),
  66348. destData (destData_),
  66349. srcData (srcData_),
  66350. extraAlpha (extraAlpha_ + 1),
  66351. betterQuality (betterQuality_),
  66352. pixelOffset (betterQuality_ ? 0.5f : 0.0f),
  66353. pixelOffsetInt (betterQuality_ ? -128 : 0),
  66354. maxX (srcData_.width - 1),
  66355. maxY (srcData_.height - 1),
  66356. scratchSize (2048)
  66357. {
  66358. scratchBuffer.malloc (scratchSize);
  66359. }
  66360. ~TransformedImageFillEdgeTableRenderer() throw()
  66361. {
  66362. }
  66363. forcedinline void setEdgeTableYPos (const int newY) throw()
  66364. {
  66365. y = newY;
  66366. linePixels = (DestPixelType*) destData.getLinePointer (newY);
  66367. }
  66368. forcedinline void handleEdgeTablePixel (const int x, int alphaLevel) throw()
  66369. {
  66370. alphaLevel *= extraAlpha;
  66371. alphaLevel >>= 8;
  66372. SrcPixelType p;
  66373. generate (&p, x, 1);
  66374. linePixels[x].blend (p, alphaLevel);
  66375. }
  66376. forcedinline void handleEdgeTableLine (const int x, int width, int alphaLevel) throw()
  66377. {
  66378. if (width > scratchSize)
  66379. {
  66380. scratchSize = width;
  66381. scratchBuffer.malloc (scratchSize);
  66382. }
  66383. SrcPixelType* span = scratchBuffer;
  66384. generate (span, x, width);
  66385. DestPixelType* dest = linePixels + x;
  66386. alphaLevel *= extraAlpha;
  66387. alphaLevel >>= 8;
  66388. if (alphaLevel < 0xfe)
  66389. {
  66390. do
  66391. {
  66392. dest++ ->blend (*span++, alphaLevel);
  66393. } while (--width > 0);
  66394. }
  66395. else
  66396. {
  66397. do
  66398. {
  66399. dest++ ->blend (*span++);
  66400. } while (--width > 0);
  66401. }
  66402. }
  66403. void clipEdgeTableLine (EdgeTable& et, int x, int y_, int width) throw()
  66404. {
  66405. if (width > scratchSize)
  66406. {
  66407. scratchSize = width;
  66408. scratchBuffer.malloc (scratchSize);
  66409. }
  66410. uint8* mask = (uint8*) scratchBuffer;
  66411. y = y_;
  66412. generate ((SrcPixelType*) mask, x, width);
  66413. if (sizeof (SrcPixelType) == sizeof (PixelARGB))
  66414. mask += PixelARGB::indexA;
  66415. et.clipLineToMask (x, y_, mask, sizeof (SrcPixelType), width);
  66416. }
  66417. private:
  66418. void generate (PixelARGB* dest, const int x, int numPixels) throw()
  66419. {
  66420. this->interpolator.setStartOfLine (x + pixelOffset, y + pixelOffset, numPixels);
  66421. do
  66422. {
  66423. int hiResX, hiResY;
  66424. this->interpolator.next (hiResX, hiResY);
  66425. hiResX += pixelOffsetInt;
  66426. hiResY += pixelOffsetInt;
  66427. int loResX = hiResX >> 8;
  66428. int loResY = hiResY >> 8;
  66429. if (repeatPattern)
  66430. {
  66431. loResX = safeModulo (loResX, srcData.width);
  66432. loResY = safeModulo (loResY, srcData.height);
  66433. }
  66434. if (betterQuality
  66435. && ((unsigned int) loResX) < (unsigned int) maxX
  66436. && ((unsigned int) loResY) < (unsigned int) maxY)
  66437. {
  66438. uint32 c[4] = { 256 * 128, 256 * 128, 256 * 128, 256 * 128 };
  66439. hiResX &= 255;
  66440. hiResY &= 255;
  66441. const uint8* src = this->srcData.getPixelPointer (loResX, loResY);
  66442. uint32 weight = (256 - hiResX) * (256 - hiResY);
  66443. c[0] += weight * src[0];
  66444. c[1] += weight * src[1];
  66445. c[2] += weight * src[2];
  66446. c[3] += weight * src[3];
  66447. weight = hiResX * (256 - hiResY);
  66448. c[0] += weight * src[4];
  66449. c[1] += weight * src[5];
  66450. c[2] += weight * src[6];
  66451. c[3] += weight * src[7];
  66452. src += this->srcData.lineStride;
  66453. weight = (256 - hiResX) * hiResY;
  66454. c[0] += weight * src[0];
  66455. c[1] += weight * src[1];
  66456. c[2] += weight * src[2];
  66457. c[3] += weight * src[3];
  66458. weight = hiResX * hiResY;
  66459. c[0] += weight * src[4];
  66460. c[1] += weight * src[5];
  66461. c[2] += weight * src[6];
  66462. c[3] += weight * src[7];
  66463. dest->setARGB ((uint8) (c[PixelARGB::indexA] >> 16),
  66464. (uint8) (c[PixelARGB::indexR] >> 16),
  66465. (uint8) (c[PixelARGB::indexG] >> 16),
  66466. (uint8) (c[PixelARGB::indexB] >> 16));
  66467. }
  66468. else
  66469. {
  66470. if (! repeatPattern)
  66471. {
  66472. // Beyond the edges, just repeat the edge pixels and leave the anti-aliasing to be handled by the edgetable
  66473. if (loResX < 0) loResX = 0;
  66474. if (loResY < 0) loResY = 0;
  66475. if (loResX > maxX) loResX = maxX;
  66476. if (loResY > maxY) loResY = maxY;
  66477. }
  66478. dest->set (*(const PixelARGB*) this->srcData.getPixelPointer (loResX, loResY));
  66479. }
  66480. ++dest;
  66481. } while (--numPixels > 0);
  66482. }
  66483. void generate (PixelRGB* dest, const int x, int numPixels) throw()
  66484. {
  66485. this->interpolator.setStartOfLine (x + pixelOffset, y + pixelOffset, numPixels);
  66486. do
  66487. {
  66488. int hiResX, hiResY;
  66489. this->interpolator.next (hiResX, hiResY);
  66490. hiResX += pixelOffsetInt;
  66491. hiResY += pixelOffsetInt;
  66492. int loResX = hiResX >> 8;
  66493. int loResY = hiResY >> 8;
  66494. if (repeatPattern)
  66495. {
  66496. loResX = safeModulo (loResX, srcData.width);
  66497. loResY = safeModulo (loResY, srcData.height);
  66498. }
  66499. if (betterQuality
  66500. && ((unsigned int) loResX) < (unsigned int) maxX
  66501. && ((unsigned int) loResY) < (unsigned int) maxY)
  66502. {
  66503. uint32 c[3] = { 256 * 128, 256 * 128, 256 * 128 };
  66504. hiResX &= 255;
  66505. hiResY &= 255;
  66506. const uint8* src = this->srcData.getPixelPointer (loResX, loResY);
  66507. unsigned int weight = (256 - hiResX) * (256 - hiResY);
  66508. c[0] += weight * src[0];
  66509. c[1] += weight * src[1];
  66510. c[2] += weight * src[2];
  66511. weight = hiResX * (256 - hiResY);
  66512. c[0] += weight * src[3];
  66513. c[1] += weight * src[4];
  66514. c[2] += weight * src[5];
  66515. src += this->srcData.lineStride;
  66516. weight = (256 - hiResX) * hiResY;
  66517. c[0] += weight * src[0];
  66518. c[1] += weight * src[1];
  66519. c[2] += weight * src[2];
  66520. weight = hiResX * hiResY;
  66521. c[0] += weight * src[3];
  66522. c[1] += weight * src[4];
  66523. c[2] += weight * src[5];
  66524. dest->setARGB ((uint8) 255,
  66525. (uint8) (c[PixelRGB::indexR] >> 16),
  66526. (uint8) (c[PixelRGB::indexG] >> 16),
  66527. (uint8) (c[PixelRGB::indexB] >> 16));
  66528. }
  66529. else
  66530. {
  66531. if (! repeatPattern)
  66532. {
  66533. // Beyond the edges, just repeat the edge pixels and leave the anti-aliasing to be handled by the edgetable
  66534. if (loResX < 0) loResX = 0;
  66535. if (loResY < 0) loResY = 0;
  66536. if (loResX > maxX) loResX = maxX;
  66537. if (loResY > maxY) loResY = maxY;
  66538. }
  66539. dest->set (*(const PixelRGB*) this->srcData.getPixelPointer (loResX, loResY));
  66540. }
  66541. ++dest;
  66542. } while (--numPixels > 0);
  66543. }
  66544. void generate (PixelAlpha* dest, const int x, int numPixels) throw()
  66545. {
  66546. this->interpolator.setStartOfLine (x + pixelOffset, y + pixelOffset, numPixels);
  66547. do
  66548. {
  66549. int hiResX, hiResY;
  66550. this->interpolator.next (hiResX, hiResY);
  66551. hiResX += pixelOffsetInt;
  66552. hiResY += pixelOffsetInt;
  66553. int loResX = hiResX >> 8;
  66554. int loResY = hiResY >> 8;
  66555. if (repeatPattern)
  66556. {
  66557. loResX = safeModulo (loResX, srcData.width);
  66558. loResY = safeModulo (loResY, srcData.height);
  66559. }
  66560. if (betterQuality
  66561. && ((unsigned int) loResX) < (unsigned int) maxX
  66562. && ((unsigned int) loResY) < (unsigned int) maxY)
  66563. {
  66564. hiResX &= 255;
  66565. hiResY &= 255;
  66566. const uint8* src = this->srcData.getPixelPointer (loResX, loResY);
  66567. uint32 c = 256 * 128;
  66568. c += src[0] * ((256 - hiResX) * (256 - hiResY));
  66569. c += src[1] * (hiResX * (256 - hiResY));
  66570. src += this->srcData.lineStride;
  66571. c += src[0] * ((256 - hiResX) * hiResY);
  66572. c += src[1] * (hiResX * hiResY);
  66573. *((uint8*) dest) = (uint8) c;
  66574. }
  66575. else
  66576. {
  66577. if (! repeatPattern)
  66578. {
  66579. // Beyond the edges, just repeat the edge pixels and leave the anti-aliasing to be handled by the edgetable
  66580. if (loResX < 0) loResX = 0;
  66581. if (loResY < 0) loResY = 0;
  66582. if (loResX > maxX) loResX = maxX;
  66583. if (loResY > maxY) loResY = maxY;
  66584. }
  66585. *((uint8*) dest) = *(this->srcData.getPixelPointer (loResX, loResY));
  66586. }
  66587. ++dest;
  66588. } while (--numPixels > 0);
  66589. }
  66590. class TransformedImageSpanInterpolator
  66591. {
  66592. public:
  66593. TransformedImageSpanInterpolator (const AffineTransform& transform) throw()
  66594. : inverseTransform (transform.inverted())
  66595. {}
  66596. void setStartOfLine (float x, float y, const int numPixels) throw()
  66597. {
  66598. float x1 = x, y1 = y;
  66599. inverseTransform.transformPoint (x1, y1);
  66600. x += numPixels;
  66601. inverseTransform.transformPoint (x, y);
  66602. xBresenham.set ((int) (x1 * 256.0f), (int) (x * 256.0f), numPixels);
  66603. yBresenham.set ((int) (y1 * 256.0f), (int) (y * 256.0f), numPixels);
  66604. }
  66605. void next (int& x, int& y) throw()
  66606. {
  66607. x = xBresenham.n;
  66608. xBresenham.stepToNext();
  66609. y = yBresenham.n;
  66610. yBresenham.stepToNext();
  66611. }
  66612. private:
  66613. class BresenhamInterpolator
  66614. {
  66615. public:
  66616. BresenhamInterpolator() throw() {}
  66617. void set (const int n1, const int n2, const int numSteps_) throw()
  66618. {
  66619. numSteps = jmax (1, numSteps_);
  66620. step = (n2 - n1) / numSteps;
  66621. remainder = modulo = (n2 - n1) % numSteps;
  66622. n = n1;
  66623. if (modulo <= 0)
  66624. {
  66625. modulo += numSteps;
  66626. remainder += numSteps;
  66627. --step;
  66628. }
  66629. modulo -= numSteps;
  66630. }
  66631. forcedinline void stepToNext() throw()
  66632. {
  66633. modulo += remainder;
  66634. n += step;
  66635. if (modulo > 0)
  66636. {
  66637. modulo -= numSteps;
  66638. ++n;
  66639. }
  66640. }
  66641. int n;
  66642. private:
  66643. int numSteps, step, modulo, remainder;
  66644. };
  66645. const AffineTransform inverseTransform;
  66646. BresenhamInterpolator xBresenham, yBresenham;
  66647. TransformedImageSpanInterpolator (const TransformedImageSpanInterpolator&);
  66648. const TransformedImageSpanInterpolator& operator= (const TransformedImageSpanInterpolator&);
  66649. };
  66650. TransformedImageSpanInterpolator interpolator;
  66651. const Image::BitmapData& destData;
  66652. const Image::BitmapData& srcData;
  66653. const int extraAlpha;
  66654. const bool betterQuality;
  66655. const float pixelOffset;
  66656. const int pixelOffsetInt, maxX, maxY;
  66657. int y;
  66658. DestPixelType* linePixels;
  66659. HeapBlock <SrcPixelType> scratchBuffer;
  66660. int scratchSize;
  66661. TransformedImageFillEdgeTableRenderer (const TransformedImageFillEdgeTableRenderer&);
  66662. const TransformedImageFillEdgeTableRenderer& operator= (const TransformedImageFillEdgeTableRenderer&);
  66663. };
  66664. class LLGCSavedState
  66665. {
  66666. public:
  66667. LLGCSavedState (const Rectangle<int>& clip_, const int xOffset_, const int yOffset_,
  66668. const Font& font_, const FillType& fillType_,
  66669. const Graphics::ResamplingQuality interpolationQuality_) throw()
  66670. : edgeTable (new EdgeTableHolder (EdgeTable (clip_))),
  66671. xOffset (xOffset_), yOffset (yOffset_),
  66672. font (font_), fillType (fillType_),
  66673. interpolationQuality (interpolationQuality_)
  66674. {
  66675. }
  66676. LLGCSavedState (const LLGCSavedState& other) throw()
  66677. : edgeTable (other.edgeTable), xOffset (other.xOffset),
  66678. yOffset (other.yOffset), font (other.font),
  66679. fillType (other.fillType), interpolationQuality (other.interpolationQuality)
  66680. {
  66681. }
  66682. ~LLGCSavedState() throw()
  66683. {
  66684. }
  66685. bool clipToRectangle (const Rectangle<int>& r) throw()
  66686. {
  66687. dupeEdgeTableIfMultiplyReferenced();
  66688. edgeTable->edgeTable.clipToRectangle (r.translated (xOffset, yOffset));
  66689. return ! edgeTable->edgeTable.isEmpty();
  66690. }
  66691. bool clipToRectangleList (const RectangleList& r) throw()
  66692. {
  66693. dupeEdgeTableIfMultiplyReferenced();
  66694. RectangleList offsetList (r);
  66695. offsetList.offsetAll (xOffset, yOffset);
  66696. EdgeTable e2 (offsetList);
  66697. edgeTable->edgeTable.clipToEdgeTable (e2);
  66698. return ! edgeTable->edgeTable.isEmpty();
  66699. }
  66700. bool excludeClipRectangle (const Rectangle<int>& r) throw()
  66701. {
  66702. dupeEdgeTableIfMultiplyReferenced();
  66703. edgeTable->edgeTable.excludeRectangle (r.translated (xOffset, yOffset));
  66704. return ! edgeTable->edgeTable.isEmpty();
  66705. }
  66706. void clipToPath (const Path& p, const AffineTransform& transform) throw()
  66707. {
  66708. dupeEdgeTableIfMultiplyReferenced();
  66709. EdgeTable et (edgeTable->edgeTable.getMaximumBounds(), p, transform.translated ((float) xOffset, (float) yOffset));
  66710. edgeTable->edgeTable.clipToEdgeTable (et);
  66711. }
  66712. void fillEdgeTable (Image& image, EdgeTable& et, const bool replaceContents = false) throw()
  66713. {
  66714. et.clipToEdgeTable (edgeTable->edgeTable);
  66715. Image::BitmapData destData (image, 0, 0, image.getWidth(), image.getHeight(), true);
  66716. if (fillType.isGradient())
  66717. {
  66718. jassert (! replaceContents); // that option is just for solid colours
  66719. ColourGradient g2 (*(fillType.gradient));
  66720. g2.multiplyOpacity (fillType.getOpacity());
  66721. g2.x1 -= 0.5f; g2.y1 -= 0.5f;
  66722. g2.x2 -= 0.5f; g2.y2 -= 0.5f;
  66723. AffineTransform transform (fillType.transform.translated ((float) xOffset, (float) yOffset));
  66724. const bool isIdentity = transform.isOnlyTranslation();
  66725. if (isIdentity)
  66726. {
  66727. // If our translation doesn't involve any distortion, we can speed it up..
  66728. transform.transformPoint (g2.x1, g2.y1);
  66729. transform.transformPoint (g2.x2, g2.y2);
  66730. transform = AffineTransform::identity;
  66731. }
  66732. HeapBlock <PixelARGB> lookupTable;
  66733. const int numLookupEntries = g2.createLookupTable (transform, lookupTable);
  66734. jassert (numLookupEntries > 0);
  66735. switch (image.getFormat())
  66736. {
  66737. case Image::ARGB: renderGradient (et, destData, g2, transform, lookupTable, numLookupEntries, isIdentity, (PixelARGB*) 0); break;
  66738. case Image::RGB: renderGradient (et, destData, g2, transform, lookupTable, numLookupEntries, isIdentity, (PixelRGB*) 0); break;
  66739. default: renderGradient (et, destData, g2, transform, lookupTable, numLookupEntries, isIdentity, (PixelAlpha*) 0); break;
  66740. }
  66741. }
  66742. else if (fillType.isTiledImage())
  66743. {
  66744. renderImage (image, *(fillType.image), fillType.image->getBounds(), fillType.transform, &et);
  66745. }
  66746. else
  66747. {
  66748. const PixelARGB fillColour (fillType.colour.getPixelARGB());
  66749. switch (image.getFormat())
  66750. {
  66751. case Image::ARGB: renderSolidFill (et, destData, fillColour, replaceContents, (PixelARGB*) 0); break;
  66752. case Image::RGB: renderSolidFill (et, destData, fillColour, replaceContents, (PixelRGB*) 0); break;
  66753. default: renderSolidFill (et, destData, fillColour, replaceContents, (PixelAlpha*) 0); break;
  66754. }
  66755. }
  66756. }
  66757. void renderImage (Image& destImage, const Image& sourceImage, const Rectangle<int>& srcClip,
  66758. const AffineTransform& t, const EdgeTable* const tiledFillClipRegion) throw()
  66759. {
  66760. const AffineTransform transform (t.translated ((float) xOffset, (float) yOffset));
  66761. const Image::BitmapData destData (destImage, 0, 0, destImage.getWidth(), destImage.getHeight(), true);
  66762. const Image::BitmapData srcData (sourceImage, srcClip.getX(), srcClip.getY(), srcClip.getWidth(), srcClip.getHeight());
  66763. const int alpha = fillType.colour.getAlpha();
  66764. const bool betterQuality = (interpolationQuality != Graphics::lowResamplingQuality);
  66765. if (transform.isOnlyTranslation())
  66766. {
  66767. // If our translation doesn't involve any distortion, just use a simple blit..
  66768. int tx = (int) (transform.getTranslationX() * 256.0f);
  66769. int ty = (int) (transform.getTranslationY() * 256.0f);
  66770. if ((! betterQuality) || ((tx | ty) & 224) == 0)
  66771. {
  66772. tx = ((tx + 128) >> 8);
  66773. ty = ((ty + 128) >> 8);
  66774. if (tiledFillClipRegion != 0)
  66775. {
  66776. blittedRenderImage (sourceImage, destImage, *tiledFillClipRegion, destData, srcData, alpha, tx, ty, true);
  66777. }
  66778. else
  66779. {
  66780. EdgeTable et (Rectangle<int> (tx, ty, srcClip.getWidth(), srcClip.getHeight()).getIntersection (destImage.getBounds()));
  66781. et.clipToEdgeTable (edgeTable->edgeTable);
  66782. if (! et.isEmpty())
  66783. blittedRenderImage (sourceImage, destImage, et, destData, srcData, alpha, tx, ty, false);
  66784. }
  66785. return;
  66786. }
  66787. }
  66788. if (transform.isSingularity())
  66789. return;
  66790. if (tiledFillClipRegion != 0)
  66791. {
  66792. transformedRenderImage (sourceImage, destImage, *tiledFillClipRegion, destData, srcData, alpha, transform, betterQuality, true);
  66793. }
  66794. else
  66795. {
  66796. Path p;
  66797. p.addRectangle (0.0f, 0.0f, (float) srcClip.getWidth(), (float) srcClip.getHeight());
  66798. EdgeTable et (edgeTable->edgeTable.getMaximumBounds(), p, transform);
  66799. et.clipToEdgeTable (edgeTable->edgeTable);
  66800. if (! et.isEmpty())
  66801. transformedRenderImage (sourceImage, destImage, et, destData, srcData, alpha, transform, betterQuality, false);
  66802. }
  66803. }
  66804. void clipToImageAlpha (const Image& image, const Rectangle<int>& srcClip, const AffineTransform& t) throw()
  66805. {
  66806. if (! image.hasAlphaChannel())
  66807. {
  66808. Path p;
  66809. p.addRectangle (srcClip);
  66810. clipToPath (p, t);
  66811. return;
  66812. }
  66813. dupeEdgeTableIfMultiplyReferenced();
  66814. const AffineTransform transform (t.translated ((float) xOffset, (float) yOffset));
  66815. const Image::BitmapData srcData (image, srcClip.getX(), srcClip.getY(), srcClip.getWidth(), srcClip.getHeight());
  66816. const bool betterQuality = (interpolationQuality != Graphics::lowResamplingQuality);
  66817. EdgeTable& et = edgeTable->edgeTable;
  66818. if (transform.isOnlyTranslation())
  66819. {
  66820. // If our translation doesn't involve any distortion, just use a simple blit..
  66821. const int tx = (int) (transform.getTranslationX() * 256.0f);
  66822. const int ty = (int) (transform.getTranslationY() * 256.0f);
  66823. if ((! betterQuality) || ((tx | ty) & 224) == 0)
  66824. {
  66825. const int imageX = ((tx + 128) >> 8);
  66826. const int imageY = ((ty + 128) >> 8);
  66827. if (image.getFormat() == Image::ARGB)
  66828. straightClipImage (et, srcData, imageX, imageY, (PixelARGB*)0);
  66829. else
  66830. straightClipImage (et, srcData, imageX, imageY, (PixelAlpha*)0);
  66831. return;
  66832. }
  66833. }
  66834. if (transform.isSingularity())
  66835. {
  66836. et.clipToRectangle (Rectangle<int>());
  66837. return;
  66838. }
  66839. {
  66840. Path p;
  66841. p.addRectangle (0, 0, (float) srcData.width, (float) srcData.height);
  66842. EdgeTable et2 (et.getMaximumBounds(), p, transform);
  66843. et.clipToEdgeTable (et2);
  66844. }
  66845. if (! et.isEmpty())
  66846. {
  66847. if (image.getFormat() == Image::ARGB)
  66848. transformedClipImage (et, srcData, transform, betterQuality, (PixelARGB*)0);
  66849. else
  66850. transformedClipImage (et, srcData, transform, betterQuality, (PixelAlpha*)0);
  66851. }
  66852. }
  66853. template <class SrcPixelType>
  66854. void transformedClipImage (EdgeTable& et, const Image::BitmapData& srcData, const AffineTransform& transform, const bool betterQuality, const SrcPixelType *) throw()
  66855. {
  66856. TransformedImageFillEdgeTableRenderer <SrcPixelType, SrcPixelType, false> renderer (srcData, srcData, transform, 255, betterQuality);
  66857. for (int y = 0; y < et.getMaximumBounds().getHeight(); ++y)
  66858. renderer.clipEdgeTableLine (et, et.getMaximumBounds().getX(), y + et.getMaximumBounds().getY(),
  66859. et.getMaximumBounds().getWidth());
  66860. }
  66861. template <class SrcPixelType>
  66862. void straightClipImage (EdgeTable& et, const Image::BitmapData& srcData, int imageX, int imageY, const SrcPixelType *) throw()
  66863. {
  66864. Rectangle<int> r (imageX, imageY, srcData.width, srcData.height);
  66865. et.clipToRectangle (r);
  66866. ImageFillEdgeTableRenderer <SrcPixelType, SrcPixelType, false> renderer (srcData, srcData, 255, imageX, imageY);
  66867. for (int y = 0; y < r.getHeight(); ++y)
  66868. renderer.clipEdgeTableLine (et, r.getX(), y + r.getY(), r.getWidth());
  66869. }
  66870. class EdgeTableHolder : public ReferenceCountedObject
  66871. {
  66872. public:
  66873. EdgeTableHolder (const EdgeTable& e) throw() : edgeTable (e) {}
  66874. EdgeTable edgeTable;
  66875. };
  66876. ReferenceCountedObjectPtr<EdgeTableHolder> edgeTable;
  66877. int xOffset, yOffset;
  66878. Font font;
  66879. FillType fillType;
  66880. Graphics::ResamplingQuality interpolationQuality;
  66881. private:
  66882. const LLGCSavedState& operator= (const LLGCSavedState&);
  66883. void dupeEdgeTableIfMultiplyReferenced() throw()
  66884. {
  66885. if (edgeTable->getReferenceCount() > 1)
  66886. edgeTable = new EdgeTableHolder (edgeTable->edgeTable);
  66887. }
  66888. template <class DestPixelType>
  66889. void renderGradient (EdgeTable& et, const Image::BitmapData& destData, const ColourGradient& g, const AffineTransform& transform,
  66890. const PixelARGB* const lookupTable, const int numLookupEntries, const bool isIdentity, DestPixelType*) throw()
  66891. {
  66892. jassert (destData.pixelStride == sizeof (DestPixelType));
  66893. if (g.isRadial)
  66894. {
  66895. if (isIdentity)
  66896. {
  66897. GradientEdgeTableRenderer <DestPixelType, RadialGradientPixelGenerator> renderer (destData, g, transform, lookupTable, numLookupEntries);
  66898. et.iterate (renderer);
  66899. }
  66900. else
  66901. {
  66902. GradientEdgeTableRenderer <DestPixelType, TransformedRadialGradientPixelGenerator> renderer (destData, g, transform, lookupTable, numLookupEntries);
  66903. et.iterate (renderer);
  66904. }
  66905. }
  66906. else
  66907. {
  66908. GradientEdgeTableRenderer <DestPixelType, LinearGradientPixelGenerator> renderer (destData, g, transform, lookupTable, numLookupEntries);
  66909. et.iterate (renderer);
  66910. }
  66911. }
  66912. template <class DestPixelType>
  66913. void renderSolidFill (EdgeTable& et, const Image::BitmapData& destData, const PixelARGB& fillColour, const bool replaceContents, DestPixelType*) throw()
  66914. {
  66915. jassert (destData.pixelStride == sizeof (DestPixelType));
  66916. if (replaceContents)
  66917. {
  66918. SolidColourEdgeTableRenderer <DestPixelType, true> r (destData, fillColour);
  66919. et.iterate (r);
  66920. }
  66921. else
  66922. {
  66923. SolidColourEdgeTableRenderer <DestPixelType, false> r (destData, fillColour);
  66924. et.iterate (r);
  66925. }
  66926. }
  66927. void transformedRenderImage (const Image& srcImage, Image& destImage, const EdgeTable& et, const Image::BitmapData& destData, const Image::BitmapData& srcData,
  66928. const int alpha, const AffineTransform& transform, const bool betterQuality, const bool repeatPattern) throw()
  66929. {
  66930. switch (destImage.getFormat())
  66931. {
  66932. case Image::ARGB:
  66933. switch (srcImage.getFormat())
  66934. {
  66935. case Image::ARGB:
  66936. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelARGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66937. else { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelARGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66938. break;
  66939. case Image::RGB:
  66940. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelRGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66941. else { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelRGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66942. break;
  66943. default:
  66944. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66945. else { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66946. break;
  66947. }
  66948. break;
  66949. case Image::RGB:
  66950. switch (srcImage.getFormat())
  66951. {
  66952. case Image::ARGB:
  66953. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelARGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66954. else { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelARGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66955. break;
  66956. case Image::RGB:
  66957. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelRGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66958. else { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelRGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66959. break;
  66960. default:
  66961. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66962. else { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66963. break;
  66964. }
  66965. break;
  66966. default:
  66967. switch (srcImage.getFormat())
  66968. {
  66969. case Image::ARGB:
  66970. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66971. else { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66972. break;
  66973. case Image::RGB:
  66974. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66975. else { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66976. break;
  66977. default:
  66978. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66979. else { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66980. break;
  66981. }
  66982. break;
  66983. }
  66984. }
  66985. void blittedRenderImage (const Image& srcImage, Image& destImage, const EdgeTable& et, const Image::BitmapData& destData,
  66986. const Image::BitmapData& srcData, const int alpha, int x, int y, const bool repeatPattern) throw()
  66987. {
  66988. switch (destImage.getFormat())
  66989. {
  66990. case Image::ARGB:
  66991. switch (srcImage.getFormat())
  66992. {
  66993. case Image::ARGB:
  66994. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelARGB, PixelARGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66995. else { ImageFillEdgeTableRenderer <PixelARGB, PixelARGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66996. break;
  66997. case Image::RGB:
  66998. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelARGB, PixelRGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66999. else { ImageFillEdgeTableRenderer <PixelARGB, PixelRGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  67000. break;
  67001. default:
  67002. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  67003. else { ImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  67004. break;
  67005. }
  67006. break;
  67007. case Image::RGB:
  67008. switch (srcImage.getFormat())
  67009. {
  67010. case Image::ARGB:
  67011. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelRGB, PixelARGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  67012. else { ImageFillEdgeTableRenderer <PixelRGB, PixelARGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  67013. break;
  67014. case Image::RGB:
  67015. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelRGB, PixelRGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  67016. else { ImageFillEdgeTableRenderer <PixelRGB, PixelRGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  67017. break;
  67018. default:
  67019. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  67020. else { ImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  67021. break;
  67022. }
  67023. break;
  67024. default:
  67025. switch (srcImage.getFormat())
  67026. {
  67027. case Image::ARGB:
  67028. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  67029. else { ImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  67030. break;
  67031. case Image::RGB:
  67032. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  67033. else { ImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  67034. break;
  67035. default:
  67036. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  67037. else { ImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  67038. break;
  67039. }
  67040. break;
  67041. }
  67042. }
  67043. };
  67044. LowLevelGraphicsSoftwareRenderer::LowLevelGraphicsSoftwareRenderer (Image& image_)
  67045. : image (image_)
  67046. {
  67047. currentState = new LLGCSavedState (image_.getBounds(), 0, 0, Font(),
  67048. FillType(), Graphics::mediumResamplingQuality);
  67049. }
  67050. LowLevelGraphicsSoftwareRenderer::~LowLevelGraphicsSoftwareRenderer()
  67051. {
  67052. }
  67053. bool LowLevelGraphicsSoftwareRenderer::isVectorDevice() const
  67054. {
  67055. return false;
  67056. }
  67057. void LowLevelGraphicsSoftwareRenderer::setOrigin (int x, int y)
  67058. {
  67059. currentState->xOffset += x;
  67060. currentState->yOffset += y;
  67061. }
  67062. bool LowLevelGraphicsSoftwareRenderer::clipToRectangle (const Rectangle<int>& r)
  67063. {
  67064. return currentState->clipToRectangle (r);
  67065. }
  67066. bool LowLevelGraphicsSoftwareRenderer::clipToRectangleList (const RectangleList& clipRegion)
  67067. {
  67068. return currentState->clipToRectangleList (clipRegion);
  67069. }
  67070. void LowLevelGraphicsSoftwareRenderer::excludeClipRectangle (const Rectangle<int>& r)
  67071. {
  67072. currentState->excludeClipRectangle (r);
  67073. }
  67074. void LowLevelGraphicsSoftwareRenderer::clipToPath (const Path& path, const AffineTransform& transform)
  67075. {
  67076. currentState->clipToPath (path, transform);
  67077. }
  67078. void LowLevelGraphicsSoftwareRenderer::clipToImageAlpha (const Image& sourceImage, const Rectangle<int>& srcClip, const AffineTransform& transform)
  67079. {
  67080. currentState->clipToImageAlpha (sourceImage, srcClip, transform);
  67081. }
  67082. bool LowLevelGraphicsSoftwareRenderer::clipRegionIntersects (const Rectangle<int>& r)
  67083. {
  67084. return currentState->edgeTable->edgeTable.getMaximumBounds()
  67085. .intersects (r.translated (currentState->xOffset, currentState->yOffset));
  67086. }
  67087. const Rectangle<int> LowLevelGraphicsSoftwareRenderer::getClipBounds() const
  67088. {
  67089. return currentState->edgeTable->edgeTable.getMaximumBounds().translated (-currentState->xOffset, -currentState->yOffset);
  67090. }
  67091. bool LowLevelGraphicsSoftwareRenderer::isClipEmpty() const
  67092. {
  67093. return currentState->edgeTable->edgeTable.isEmpty();
  67094. }
  67095. void LowLevelGraphicsSoftwareRenderer::saveState()
  67096. {
  67097. stateStack.add (new LLGCSavedState (*currentState));
  67098. }
  67099. void LowLevelGraphicsSoftwareRenderer::restoreState()
  67100. {
  67101. LLGCSavedState* const top = stateStack.getLast();
  67102. if (top != 0)
  67103. {
  67104. currentState = top;
  67105. stateStack.removeLast (1, false);
  67106. }
  67107. else
  67108. {
  67109. jassertfalse // trying to pop with an empty stack!
  67110. }
  67111. }
  67112. void LowLevelGraphicsSoftwareRenderer::setFill (const FillType& fillType)
  67113. {
  67114. currentState->fillType = fillType;
  67115. }
  67116. void LowLevelGraphicsSoftwareRenderer::setOpacity (float newOpacity)
  67117. {
  67118. currentState->fillType.setOpacity (newOpacity);
  67119. }
  67120. void LowLevelGraphicsSoftwareRenderer::setInterpolationQuality (Graphics::ResamplingQuality quality)
  67121. {
  67122. currentState->interpolationQuality = quality;
  67123. }
  67124. void LowLevelGraphicsSoftwareRenderer::fillRect (const Rectangle<int>& r, const bool replaceExistingContents)
  67125. {
  67126. const Rectangle<int>& totalClip = currentState->edgeTable->edgeTable.getMaximumBounds();
  67127. const Rectangle<int> clipped (totalClip.getIntersection (r.translated (currentState->xOffset, currentState->yOffset)));
  67128. if (! clipped.isEmpty())
  67129. {
  67130. EdgeTable et (clipped);
  67131. currentState->fillEdgeTable (image, et, replaceExistingContents);
  67132. }
  67133. }
  67134. void LowLevelGraphicsSoftwareRenderer::fillPath (const Path& path, const AffineTransform& transform)
  67135. {
  67136. EdgeTable et (currentState->edgeTable->edgeTable.getMaximumBounds(),
  67137. path, transform.translated ((float) currentState->xOffset,
  67138. (float) currentState->yOffset));
  67139. currentState->fillEdgeTable (image, et);
  67140. }
  67141. void LowLevelGraphicsSoftwareRenderer::drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  67142. const AffineTransform& transform, const bool fillEntireClipAsTiles)
  67143. {
  67144. jassert (sourceImage.getBounds().contains (srcClip));
  67145. currentState->renderImage (image, sourceImage, srcClip, transform,
  67146. fillEntireClipAsTiles ? &(currentState->edgeTable->edgeTable) : 0);
  67147. }
  67148. void LowLevelGraphicsSoftwareRenderer::drawLine (double x1, double y1, double x2, double y2)
  67149. {
  67150. Path p;
  67151. p.addLineSegment ((float) x1, (float) y1, (float) x2, (float) y2, 1.0f);
  67152. fillPath (p, AffineTransform::identity);
  67153. }
  67154. void LowLevelGraphicsSoftwareRenderer::drawVerticalLine (const int x, double top, double bottom)
  67155. {
  67156. if (bottom > top)
  67157. {
  67158. EdgeTable et ((float) (x + currentState->xOffset), (float) (top + currentState->yOffset), 1.0f, (float) (bottom - top));
  67159. currentState->fillEdgeTable (image, et);
  67160. }
  67161. }
  67162. void LowLevelGraphicsSoftwareRenderer::drawHorizontalLine (const int y, double left, double right)
  67163. {
  67164. if (right > left)
  67165. {
  67166. EdgeTable et ((float) (left + currentState->xOffset), (float) (y + currentState->yOffset),
  67167. (float) (right - left), 1.0f);
  67168. currentState->fillEdgeTable (image, et);
  67169. }
  67170. }
  67171. class GlyphCache : private DeletedAtShutdown
  67172. {
  67173. public:
  67174. GlyphCache() throw()
  67175. : accessCounter (0), hits (0), misses (0)
  67176. {
  67177. for (int i = 120; --i >= 0;)
  67178. glyphs.add (new CachedGlyph());
  67179. }
  67180. ~GlyphCache() throw()
  67181. {
  67182. clearSingletonInstance();
  67183. }
  67184. juce_DeclareSingleton_SingleThreaded_Minimal (GlyphCache);
  67185. void drawGlyph (LLGCSavedState& state, Image& image, const Font& font, const int glyphNumber, float x, float y) throw()
  67186. {
  67187. ++accessCounter;
  67188. int oldestCounter = std::numeric_limits<int>::max();
  67189. CachedGlyph* oldest = 0;
  67190. for (int i = glyphs.size(); --i >= 0;)
  67191. {
  67192. CachedGlyph* const glyph = glyphs.getUnchecked (i);
  67193. if (glyph->glyph == glyphNumber && glyph->font == font)
  67194. {
  67195. ++hits;
  67196. glyph->lastAccessCount = accessCounter;
  67197. glyph->draw (state, image, x, y);
  67198. return;
  67199. }
  67200. if (glyph->lastAccessCount <= oldestCounter)
  67201. {
  67202. oldestCounter = glyph->lastAccessCount;
  67203. oldest = glyph;
  67204. }
  67205. }
  67206. if (hits + ++misses > (glyphs.size() << 4))
  67207. {
  67208. if (misses * 2 > hits)
  67209. {
  67210. for (int i = 32; --i >= 0;)
  67211. glyphs.add (new CachedGlyph());
  67212. }
  67213. hits = misses = 0;
  67214. oldest = glyphs.getLast();
  67215. }
  67216. jassert (oldest != 0);
  67217. oldest->lastAccessCount = accessCounter;
  67218. oldest->generate (font, glyphNumber);
  67219. oldest->draw (state, image, x, y);
  67220. }
  67221. class CachedGlyph
  67222. {
  67223. public:
  67224. CachedGlyph() : glyph (0), lastAccessCount (0) {}
  67225. ~CachedGlyph() {}
  67226. void draw (LLGCSavedState& state, Image& image, const float x, const float y) const throw()
  67227. {
  67228. if (edgeTable != 0)
  67229. {
  67230. EdgeTable et (*edgeTable);
  67231. et.translate (x, roundToInt (y));
  67232. state.fillEdgeTable (image, et, false);
  67233. }
  67234. }
  67235. void generate (const Font& newFont, const int glyphNumber) throw()
  67236. {
  67237. font = newFont;
  67238. glyph = glyphNumber;
  67239. edgeTable = 0;
  67240. Path glyphPath;
  67241. font.getTypeface()->getOutlineForGlyph (glyphNumber, glyphPath);
  67242. if (! glyphPath.isEmpty())
  67243. {
  67244. const float fontHeight = font.getHeight();
  67245. const AffineTransform transform (AffineTransform::scale (fontHeight * font.getHorizontalScale(), fontHeight)
  67246. .translated (0.0f, -0.5f));
  67247. edgeTable = new EdgeTable (glyphPath.getBoundsTransformed (transform).getSmallestIntegerContainer().expanded (1, 0),
  67248. glyphPath, transform);
  67249. }
  67250. }
  67251. int glyph, lastAccessCount;
  67252. Font font;
  67253. juce_UseDebuggingNewOperator
  67254. private:
  67255. ScopedPointer <EdgeTable> edgeTable;
  67256. CachedGlyph (const CachedGlyph&);
  67257. const CachedGlyph& operator= (const CachedGlyph&);
  67258. };
  67259. juce_UseDebuggingNewOperator
  67260. private:
  67261. OwnedArray <CachedGlyph> glyphs;
  67262. int accessCounter, hits, misses;
  67263. GlyphCache (const GlyphCache&);
  67264. const GlyphCache& operator= (const GlyphCache&);
  67265. };
  67266. juce_ImplementSingleton_SingleThreaded (GlyphCache);
  67267. void LowLevelGraphicsSoftwareRenderer::setFont (const Font& newFont)
  67268. {
  67269. currentState->font = newFont;
  67270. }
  67271. const Font LowLevelGraphicsSoftwareRenderer::getFont()
  67272. {
  67273. return currentState->font;
  67274. }
  67275. void LowLevelGraphicsSoftwareRenderer::drawGlyph (int glyphNumber, const AffineTransform& transform)
  67276. {
  67277. Font& f = currentState->font;
  67278. if (transform.isOnlyTranslation())
  67279. {
  67280. GlyphCache::getInstance()->drawGlyph (*currentState, image, f, glyphNumber,
  67281. transform.getTranslationX() + (float) currentState->xOffset,
  67282. transform.getTranslationY() + (float) currentState->yOffset);
  67283. }
  67284. else
  67285. {
  67286. Path p;
  67287. f.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  67288. fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight()).followedBy (transform));
  67289. }
  67290. }
  67291. #if JUCE_MSVC
  67292. #pragma warning (pop)
  67293. #endif
  67294. END_JUCE_NAMESPACE
  67295. /*** End of inlined file: juce_LowLevelGraphicsSoftwareRenderer.cpp ***/
  67296. /*** Start of inlined file: juce_RectanglePlacement.cpp ***/
  67297. BEGIN_JUCE_NAMESPACE
  67298. RectanglePlacement::RectanglePlacement (const RectanglePlacement& other) throw()
  67299. : flags (other.flags)
  67300. {
  67301. }
  67302. const RectanglePlacement& RectanglePlacement::operator= (const RectanglePlacement& other) throw()
  67303. {
  67304. flags = other.flags;
  67305. return *this;
  67306. }
  67307. void RectanglePlacement::applyTo (double& x, double& y,
  67308. double& w, double& h,
  67309. const double dx, const double dy,
  67310. const double dw, const double dh) const throw()
  67311. {
  67312. if (w == 0 || h == 0)
  67313. return;
  67314. if ((flags & stretchToFit) != 0)
  67315. {
  67316. x = dx;
  67317. y = dy;
  67318. w = dw;
  67319. h = dh;
  67320. }
  67321. else
  67322. {
  67323. double scale = (flags & fillDestination) != 0 ? jmax (dw / w, dh / h)
  67324. : jmin (dw / w, dh / h);
  67325. if ((flags & onlyReduceInSize) != 0)
  67326. scale = jmin (scale, 1.0);
  67327. if ((flags & onlyIncreaseInSize) != 0)
  67328. scale = jmax (scale, 1.0);
  67329. w *= scale;
  67330. h *= scale;
  67331. if ((flags & xLeft) != 0)
  67332. x = dx;
  67333. else if ((flags & xRight) != 0)
  67334. x = dx + dw - w;
  67335. else
  67336. x = dx + (dw - w) * 0.5;
  67337. if ((flags & yTop) != 0)
  67338. y = dy;
  67339. else if ((flags & yBottom) != 0)
  67340. y = dy + dh - h;
  67341. else
  67342. y = dy + (dh - h) * 0.5;
  67343. }
  67344. }
  67345. const AffineTransform RectanglePlacement::getTransformToFit (float x, float y,
  67346. float w, float h,
  67347. const float dx, const float dy,
  67348. const float dw, const float dh) const throw()
  67349. {
  67350. if (w == 0 || h == 0)
  67351. return AffineTransform::identity;
  67352. const float scaleX = dw / w;
  67353. const float scaleY = dh / h;
  67354. if ((flags & stretchToFit) != 0)
  67355. return AffineTransform::translation (-x, -y)
  67356. .scaled (scaleX, scaleY)
  67357. .translated (dx, dy);
  67358. float scale = (flags & fillDestination) != 0 ? jmax (scaleX, scaleY)
  67359. : jmin (scaleX, scaleY);
  67360. if ((flags & onlyReduceInSize) != 0)
  67361. scale = jmin (scale, 1.0f);
  67362. if ((flags & onlyIncreaseInSize) != 0)
  67363. scale = jmax (scale, 1.0f);
  67364. w *= scale;
  67365. h *= scale;
  67366. float newX = dx;
  67367. if ((flags & xRight) != 0)
  67368. newX += dw - w; // right
  67369. else if ((flags & xLeft) == 0)
  67370. newX += (dw - w) / 2.0f; // centre
  67371. float newY = dy;
  67372. if ((flags & yBottom) != 0)
  67373. newY += dh - h; // bottom
  67374. else if ((flags & yTop) == 0)
  67375. newY += (dh - h) / 2.0f; // centre
  67376. return AffineTransform::translation (-x, -y)
  67377. .scaled (scale, scale)
  67378. .translated (newX, newY);
  67379. }
  67380. END_JUCE_NAMESPACE
  67381. /*** End of inlined file: juce_RectanglePlacement.cpp ***/
  67382. /*** Start of inlined file: juce_Drawable.cpp ***/
  67383. BEGIN_JUCE_NAMESPACE
  67384. Drawable::RenderingContext::RenderingContext (Graphics& g_,
  67385. const AffineTransform& transform_,
  67386. const float opacity_) throw()
  67387. : g (g_),
  67388. transform (transform_),
  67389. opacity (opacity_)
  67390. {
  67391. }
  67392. Drawable::Drawable()
  67393. {
  67394. }
  67395. Drawable::~Drawable()
  67396. {
  67397. }
  67398. void Drawable::draw (Graphics& g, const float opacity,
  67399. const AffineTransform& transform) const
  67400. {
  67401. render (RenderingContext (g, transform, opacity));
  67402. }
  67403. void Drawable::drawAt (Graphics& g, const float x, const float y, const float opacity) const
  67404. {
  67405. draw (g, opacity, AffineTransform::translation (x, y));
  67406. }
  67407. void Drawable::drawWithin (Graphics& g,
  67408. const int destX,
  67409. const int destY,
  67410. const int destW,
  67411. const int destH,
  67412. const RectanglePlacement& placement,
  67413. const float opacity) const
  67414. {
  67415. if (destW > 0 && destH > 0)
  67416. {
  67417. Rectangle<float> bounds (getBounds());
  67418. draw (g, opacity,
  67419. placement.getTransformToFit (bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight(),
  67420. (float) destX, (float) destY,
  67421. (float) destW, (float) destH));
  67422. }
  67423. }
  67424. Drawable* Drawable::createFromImageData (const void* data, const size_t numBytes)
  67425. {
  67426. Drawable* result = 0;
  67427. Image* const image = ImageFileFormat::loadFrom (data, (int) numBytes);
  67428. if (image != 0)
  67429. {
  67430. DrawableImage* const di = new DrawableImage();
  67431. di->setImage (image, true);
  67432. result = di;
  67433. }
  67434. else
  67435. {
  67436. const String asString (String::createStringFromData (data, (int) numBytes));
  67437. XmlDocument doc (asString);
  67438. ScopedPointer <XmlElement> outer (doc.getDocumentElement (true));
  67439. if (outer != 0 && outer->hasTagName (T("svg")))
  67440. {
  67441. ScopedPointer <XmlElement> svg (doc.getDocumentElement());
  67442. if (svg != 0)
  67443. result = Drawable::createFromSVG (*svg);
  67444. }
  67445. }
  67446. return result;
  67447. }
  67448. Drawable* Drawable::createFromImageDataStream (InputStream& dataSource)
  67449. {
  67450. MemoryBlock mb;
  67451. dataSource.readIntoMemoryBlock (mb);
  67452. return createFromImageData (mb.getData(), mb.getSize());
  67453. }
  67454. Drawable* Drawable::createFromImageFile (const File& file)
  67455. {
  67456. const ScopedPointer <FileInputStream> fin (file.createInputStream());
  67457. return fin != 0 ? createFromImageDataStream (*fin) : 0;
  67458. }
  67459. Drawable* Drawable::createFromValueTree (const ValueTree& tree) throw()
  67460. {
  67461. Drawable* d = DrawablePath::createFromValueTree (tree);
  67462. if (d == 0)
  67463. {
  67464. d = DrawableComposite::createFromValueTree (tree);
  67465. if (d == 0)
  67466. {
  67467. d = DrawableImage::createFromValueTree (tree);
  67468. if (d == 0)
  67469. d = DrawableText::createFromValueTree (tree);
  67470. }
  67471. }
  67472. return d;
  67473. }
  67474. END_JUCE_NAMESPACE
  67475. /*** End of inlined file: juce_Drawable.cpp ***/
  67476. /*** Start of inlined file: juce_DrawableComposite.cpp ***/
  67477. BEGIN_JUCE_NAMESPACE
  67478. DrawableComposite::DrawableComposite()
  67479. {
  67480. }
  67481. DrawableComposite::~DrawableComposite()
  67482. {
  67483. }
  67484. void DrawableComposite::insertDrawable (Drawable* drawable,
  67485. const AffineTransform& transform,
  67486. const int index)
  67487. {
  67488. if (drawable != 0)
  67489. {
  67490. if (! drawables.contains (drawable))
  67491. {
  67492. drawables.insert (index, drawable);
  67493. if (transform.isIdentity())
  67494. transforms.insert (index, 0);
  67495. else
  67496. transforms.insert (index, new AffineTransform (transform));
  67497. }
  67498. else
  67499. {
  67500. jassertfalse // trying to add a drawable that's already in here!
  67501. }
  67502. }
  67503. }
  67504. void DrawableComposite::insertDrawable (const Drawable& drawable,
  67505. const AffineTransform& transform,
  67506. const int index)
  67507. {
  67508. insertDrawable (drawable.createCopy(), transform, index);
  67509. }
  67510. void DrawableComposite::removeDrawable (const int index, const bool deleteDrawable)
  67511. {
  67512. drawables.remove (index, deleteDrawable);
  67513. transforms.remove (index);
  67514. }
  67515. void DrawableComposite::bringToFront (const int index)
  67516. {
  67517. if (index >= 0 && index < drawables.size() - 1)
  67518. {
  67519. drawables.move (index, -1);
  67520. transforms.move (index, -1);
  67521. }
  67522. }
  67523. void DrawableComposite::render (const Drawable::RenderingContext& context) const
  67524. {
  67525. if (drawables.size() > 0 && context.opacity > 0)
  67526. {
  67527. if (context.opacity >= 1.0f || drawables.size() == 1)
  67528. {
  67529. Drawable::RenderingContext contextCopy (context);
  67530. for (int i = 0; i < drawables.size(); ++i)
  67531. {
  67532. const AffineTransform* const t = transforms.getUnchecked(i);
  67533. contextCopy.transform = (t == 0) ? context.transform
  67534. : t->followedBy (context.transform);
  67535. drawables.getUnchecked(i)->render (contextCopy);
  67536. }
  67537. }
  67538. else
  67539. {
  67540. // To correctly render a whole composite layer with an overall transparency,
  67541. // we need to render everything opaquely into a temp buffer, then blend that
  67542. // with the target opacity...
  67543. const Rectangle<int> clipBounds (context.g.getClipBounds());
  67544. Image tempImage (Image::ARGB, clipBounds.getWidth(), clipBounds.getHeight(), true);
  67545. {
  67546. Graphics tempG (tempImage);
  67547. tempG.setOrigin (-clipBounds.getX(), -clipBounds.getY());
  67548. Drawable::RenderingContext tempContext (tempG, context.transform, 1.0f);
  67549. render (tempContext);
  67550. }
  67551. context.g.setOpacity (context.opacity);
  67552. context.g.drawImageAt (&tempImage, clipBounds.getX(), clipBounds.getY());
  67553. }
  67554. }
  67555. }
  67556. const Rectangle<float> DrawableComposite::getBounds() const
  67557. {
  67558. Rectangle<float> bounds;
  67559. for (int i = 0; i < drawables.size(); ++i)
  67560. {
  67561. const Drawable* const d = drawables.getUnchecked(i);
  67562. const AffineTransform* const t = transforms.getUnchecked(i);
  67563. bounds = bounds.getUnion (t == 0 ? d->getBounds()
  67564. : d->getBounds().transformed (*t));
  67565. }
  67566. return bounds;
  67567. }
  67568. bool DrawableComposite::hitTest (float x, float y) const
  67569. {
  67570. for (int i = 0; i < drawables.size(); ++i)
  67571. {
  67572. float tx = x;
  67573. float ty = y;
  67574. const AffineTransform* const t = transforms.getUnchecked(i);
  67575. if (t != 0)
  67576. t->inverted().transformPoint (tx, ty);
  67577. if (drawables.getUnchecked(i)->hitTest (tx, ty))
  67578. return true;
  67579. }
  67580. return false;
  67581. }
  67582. Drawable* DrawableComposite::createCopy() const
  67583. {
  67584. DrawableComposite* const dc = new DrawableComposite();
  67585. for (int i = 0; i < drawables.size(); ++i)
  67586. {
  67587. dc->drawables.add (drawables.getUnchecked(i)->createCopy());
  67588. const AffineTransform* const t = transforms.getUnchecked(i);
  67589. dc->transforms.add (t != 0 ? new AffineTransform (*t) : 0);
  67590. }
  67591. return dc;
  67592. }
  67593. ValueTree DrawableComposite::createValueTree() const throw()
  67594. {
  67595. ValueTree v (T("Group"));
  67596. if (getName().isNotEmpty())
  67597. v.setProperty ("id", getName(), 0);
  67598. for (int i = 0; i < drawables.size(); ++i)
  67599. {
  67600. Drawable* const d = drawables.getUnchecked(i);
  67601. ValueTree child (d->createValueTree());
  67602. AffineTransform* transform = transforms.getUnchecked(i);
  67603. if (transform != 0)
  67604. {
  67605. String t;
  67606. t << transform->mat00 << " " << transform->mat01 << " " << transform->mat02 << " "
  67607. << transform->mat10 << " " << transform->mat11 << " " << transform->mat12;
  67608. child.setProperty ("transform", t, 0);
  67609. }
  67610. v.addChild (child, -1, 0);
  67611. }
  67612. return v;
  67613. }
  67614. DrawableComposite* DrawableComposite::createFromValueTree (const ValueTree& tree) throw()
  67615. {
  67616. if (! tree.hasType ("Group"))
  67617. return 0;
  67618. DrawableComposite* dc = new DrawableComposite();
  67619. dc->setName (tree ["id"]);
  67620. for (int i = 0; i < tree.getNumChildren(); ++i)
  67621. {
  67622. ValueTree childTree (tree.getChild (i));
  67623. Drawable* d = Drawable::createFromValueTree (childTree);
  67624. if (d != 0)
  67625. {
  67626. AffineTransform transform;
  67627. const String transformAtt (childTree ["transform"].toString());
  67628. if (transformAtt.isNotEmpty())
  67629. {
  67630. StringArray tokens;
  67631. tokens.addTokens (transformAtt.trim(), false);
  67632. tokens.removeEmptyStrings (true);
  67633. if (tokens.size() == 6)
  67634. {
  67635. float f[6];
  67636. for (int j = 0; j < 6; ++j)
  67637. f[j] = (float) tokens[j].getDoubleValue();
  67638. transform = AffineTransform (f[0], f[1], f[2], f[3], f[4], f[5]);
  67639. }
  67640. }
  67641. dc->insertDrawable (d, transform);
  67642. }
  67643. }
  67644. return dc;
  67645. }
  67646. END_JUCE_NAMESPACE
  67647. /*** End of inlined file: juce_DrawableComposite.cpp ***/
  67648. /*** Start of inlined file: juce_DrawableImage.cpp ***/
  67649. BEGIN_JUCE_NAMESPACE
  67650. DrawableImage::DrawableImage()
  67651. : image (0),
  67652. canDeleteImage (false),
  67653. opacity (1.0f),
  67654. overlayColour (0x00000000)
  67655. {
  67656. }
  67657. DrawableImage::~DrawableImage()
  67658. {
  67659. clearImage();
  67660. }
  67661. void DrawableImage::clearImage()
  67662. {
  67663. if (canDeleteImage && image != 0)
  67664. ImageCache::releaseOrDelete (image);
  67665. image = 0;
  67666. }
  67667. void DrawableImage::setImage (const Image& imageToCopy)
  67668. {
  67669. clearImage();
  67670. image = new Image (imageToCopy);
  67671. canDeleteImage = true;
  67672. }
  67673. void DrawableImage::setImage (Image* imageToUse,
  67674. const bool releaseWhenNotNeeded)
  67675. {
  67676. clearImage();
  67677. image = imageToUse;
  67678. canDeleteImage = releaseWhenNotNeeded;
  67679. }
  67680. void DrawableImage::setOpacity (const float newOpacity)
  67681. {
  67682. opacity = newOpacity;
  67683. }
  67684. void DrawableImage::setOverlayColour (const Colour& newOverlayColour)
  67685. {
  67686. overlayColour = newOverlayColour;
  67687. }
  67688. void DrawableImage::render (const Drawable::RenderingContext& context) const
  67689. {
  67690. if (image != 0)
  67691. {
  67692. if (opacity > 0.0f && ! overlayColour.isOpaque())
  67693. {
  67694. context.g.setOpacity (context.opacity * opacity);
  67695. context.g.drawImageTransformed (image, image->getBounds(),
  67696. context.transform, false);
  67697. }
  67698. if (! overlayColour.isTransparent())
  67699. {
  67700. context.g.setColour (overlayColour.withMultipliedAlpha (context.opacity));
  67701. context.g.drawImageTransformed (image, image->getBounds(),
  67702. context.transform, true);
  67703. }
  67704. }
  67705. }
  67706. const Rectangle<float> DrawableImage::getBounds() const
  67707. {
  67708. if (image == 0)
  67709. return Rectangle<float>();
  67710. return Rectangle<float> (0, 0, (float) image->getWidth(), (float) image->getHeight());
  67711. }
  67712. bool DrawableImage::hitTest (float x, float y) const
  67713. {
  67714. return image != 0
  67715. && x >= 0.0f
  67716. && y >= 0.0f
  67717. && x < image->getWidth()
  67718. && y < image->getHeight()
  67719. && image->getPixelAt (roundToInt (x), roundToInt (y)).getAlpha() >= 127;
  67720. }
  67721. Drawable* DrawableImage::createCopy() const
  67722. {
  67723. DrawableImage* const di = new DrawableImage();
  67724. di->opacity = opacity;
  67725. di->overlayColour = overlayColour;
  67726. if (image != 0)
  67727. {
  67728. if ((! canDeleteImage) || ! ImageCache::isImageInCache (image))
  67729. {
  67730. di->setImage (*image);
  67731. }
  67732. else
  67733. {
  67734. ImageCache::incReferenceCount (image);
  67735. di->setImage (image, true);
  67736. }
  67737. }
  67738. return di;
  67739. }
  67740. ValueTree DrawableImage::createValueTree() const throw()
  67741. {
  67742. ValueTree v (T("Image"));
  67743. if (getName().isNotEmpty())
  67744. v.setProperty ("id", getName(), 0);
  67745. if (opacity < 1.0f)
  67746. v.setProperty ("opacity", (double) opacity, 0);
  67747. if (! overlayColour.isTransparent())
  67748. v.setProperty ("overlay", String::toHexString ((int) overlayColour.getARGB()), 0);
  67749. if (image != 0)
  67750. {
  67751. MemoryOutputStream imageData;
  67752. PNGImageFormat pngFormat;
  67753. if (pngFormat.writeImageToStream (*image, imageData))
  67754. {
  67755. String base64 (MemoryBlock (imageData.getData(), imageData.getDataSize()).toBase64Encoding());
  67756. for (int i = (base64.length() & ~127); i >= 0; i -= 128)
  67757. base64 = base64.substring (0, i) + "\n" + base64.substring (i);
  67758. v.setProperty ("data", base64, 0);
  67759. }
  67760. }
  67761. return v;
  67762. }
  67763. DrawableImage* DrawableImage::createFromValueTree (const ValueTree& tree) throw()
  67764. {
  67765. if (! tree.hasType ("Image"))
  67766. return 0;
  67767. DrawableImage* di = new DrawableImage();
  67768. di->setName (tree ["id"]);
  67769. di->opacity = tree.hasProperty ("opacity") ? (float) tree ["opacity"] : 1.0f;
  67770. di->overlayColour = Colour (tree ["overlay"].toString().getHexValue32());
  67771. MemoryBlock imageData;
  67772. if (imageData.fromBase64Encoding (tree ["data"]))
  67773. {
  67774. Image* const im = ImageFileFormat::loadFrom (imageData.getData(), (int) imageData.getSize());
  67775. if (im == 0)
  67776. return false;
  67777. di->setImage (im, true);
  67778. }
  67779. return di;
  67780. }
  67781. END_JUCE_NAMESPACE
  67782. /*** End of inlined file: juce_DrawableImage.cpp ***/
  67783. /*** Start of inlined file: juce_DrawablePath.cpp ***/
  67784. BEGIN_JUCE_NAMESPACE
  67785. DrawablePath::DrawablePath()
  67786. : mainFill (FillType (Colours::black)),
  67787. strokeFill (FillType (Colours::transparentBlack)),
  67788. strokeType (0.0f)
  67789. {
  67790. }
  67791. DrawablePath::~DrawablePath()
  67792. {
  67793. }
  67794. void DrawablePath::setPath (const Path& newPath) throw()
  67795. {
  67796. path = newPath;
  67797. updateOutline();
  67798. }
  67799. void DrawablePath::setFill (const FillType& newFill) throw()
  67800. {
  67801. mainFill = newFill;
  67802. }
  67803. void DrawablePath::setStrokeFill (const FillType& newFill) throw()
  67804. {
  67805. strokeFill = newFill;
  67806. }
  67807. void DrawablePath::setStrokeType (const PathStrokeType& newStrokeType) throw()
  67808. {
  67809. strokeType = newStrokeType;
  67810. updateOutline();
  67811. }
  67812. void DrawablePath::setStrokeThickness (const float newThickness) throw()
  67813. {
  67814. setStrokeType (PathStrokeType (newThickness, strokeType.getJointStyle(), strokeType.getEndStyle()));
  67815. }
  67816. void DrawablePath::render (const Drawable::RenderingContext& context) const
  67817. {
  67818. {
  67819. FillType f (mainFill);
  67820. if (f.isGradient())
  67821. f.gradient->multiplyOpacity (context.opacity);
  67822. f.transform = f.transform.followedBy (context.transform);
  67823. context.g.setFillType (f);
  67824. context.g.fillPath (path, context.transform);
  67825. }
  67826. if (strokeType.getStrokeThickness() > 0.0f)
  67827. {
  67828. FillType f (strokeFill);
  67829. if (f.isGradient())
  67830. f.gradient->multiplyOpacity (context.opacity);
  67831. f.transform = f.transform.followedBy (context.transform);
  67832. context.g.setFillType (f);
  67833. context.g.fillPath (stroke, context.transform);
  67834. }
  67835. }
  67836. void DrawablePath::updateOutline()
  67837. {
  67838. stroke.clear();
  67839. strokeType.createStrokedPath (stroke, path, AffineTransform::identity, 4.0f);
  67840. }
  67841. const Rectangle<float> DrawablePath::getBounds() const
  67842. {
  67843. if (strokeType.getStrokeThickness() > 0.0f)
  67844. return stroke.getBounds();
  67845. else
  67846. return path.getBounds();
  67847. }
  67848. bool DrawablePath::hitTest (float x, float y) const
  67849. {
  67850. return path.contains (x, y)
  67851. || stroke.contains (x, y);
  67852. }
  67853. Drawable* DrawablePath::createCopy() const
  67854. {
  67855. DrawablePath* const dp = new DrawablePath();
  67856. dp->path = path;
  67857. dp->stroke = stroke;
  67858. dp->mainFill = mainFill;
  67859. dp->strokeFill = strokeFill;
  67860. dp->strokeType = strokeType;
  67861. return dp;
  67862. }
  67863. static const FillType readFillTypeFromTree (const ValueTree& v)
  67864. {
  67865. const String type (v["type"].toString());
  67866. if (type.equalsIgnoreCase (T("solid")))
  67867. {
  67868. const String colour (v ["colour"].toString());
  67869. return FillType (Colour (colour.isEmpty() ? (uint32) 0xff000000
  67870. : (uint32) colour.getHexValue32()));
  67871. }
  67872. else if (type.equalsIgnoreCase ("gradient"))
  67873. {
  67874. ColourGradient g;
  67875. g.x1 = v["x1"];
  67876. g.y1 = v["y1"];
  67877. g.x2 = v["x2"];
  67878. g.y2 = v["y2"];
  67879. g.isRadial = v["radial"];
  67880. StringArray colours;
  67881. colours.addTokens (v["colours"].toString(), false);
  67882. for (int i = 0; i < colours.size() / 2; ++i)
  67883. g.addColour (colours[i * 2].getDoubleValue(),
  67884. Colour ((uint32) colours[i * 2 + 1].getHexValue32()));
  67885. return FillType (g);
  67886. }
  67887. jassertfalse
  67888. return FillType();
  67889. }
  67890. static ValueTree createTreeForFillType (const String& tagName, const FillType& fillType)
  67891. {
  67892. ValueTree v (tagName);
  67893. if (fillType.isColour())
  67894. {
  67895. v.setProperty ("type", T("solid"), 0);
  67896. v.setProperty ("colour", String::toHexString ((int) fillType.colour.getARGB()), 0);
  67897. }
  67898. else if (fillType.isGradient())
  67899. {
  67900. v.setProperty ("type", T("gradient"), 0);
  67901. v.setProperty ("x1", fillType.gradient->x1, 0);
  67902. v.setProperty ("y1", fillType.gradient->y1, 0);
  67903. v.setProperty ("x2", fillType.gradient->x2, 0);
  67904. v.setProperty ("y2", fillType.gradient->y2, 0);
  67905. v.setProperty ("radial", fillType.gradient->isRadial, 0);
  67906. String s;
  67907. for (int i = 0; i < fillType.gradient->getNumColours(); ++i)
  67908. s << " " << fillType.gradient->getColourPosition (i)
  67909. << " " << String::toHexString ((int) fillType.gradient->getColour(i).getARGB());
  67910. v.setProperty ("colours", s.trimStart(), 0);
  67911. }
  67912. else
  67913. {
  67914. jassertfalse //xxx
  67915. }
  67916. return v;
  67917. }
  67918. ValueTree DrawablePath::createValueTree() const throw()
  67919. {
  67920. ValueTree v (T("Path"));
  67921. v.addChild (createTreeForFillType (T("fill"), mainFill), -1, 0);
  67922. v.addChild (createTreeForFillType (T("stroke"), strokeFill), -1, 0);
  67923. if (getName().isNotEmpty())
  67924. v.setProperty ("id", getName(), 0);
  67925. v.setProperty ("strokeWidth", (double) strokeType.getStrokeThickness(), 0);
  67926. v.setProperty ("jointStyle", strokeType.getJointStyle() == PathStrokeType::mitered
  67927. ? T("miter") : (strokeType.getJointStyle() == PathStrokeType::curved ? T("curved") : T("bevel")), 0);
  67928. v.setProperty ("capStyle", strokeType.getEndStyle() == PathStrokeType::butt
  67929. ? T("butt") : (strokeType.getEndStyle() == PathStrokeType::square ? T("square") : T("round")), 0);
  67930. v.setProperty ("path", path.toString(), 0);
  67931. return v;
  67932. }
  67933. DrawablePath* DrawablePath::createFromValueTree (const ValueTree& tree) throw()
  67934. {
  67935. if (! tree.hasType ("Path"))
  67936. return 0;
  67937. DrawablePath* p = new DrawablePath();
  67938. p->setName (tree ["id"]);
  67939. p->mainFill = readFillTypeFromTree (tree.getChildWithName (T("fill")));
  67940. p->strokeFill = readFillTypeFromTree (tree.getChildWithName (T("stroke")));
  67941. const String jointStyle (tree ["jointStyle"].toString());
  67942. const String endStyle (tree ["capStyle"].toString());
  67943. p->strokeType
  67944. = PathStrokeType (tree ["strokeWidth"],
  67945. jointStyle.equalsIgnoreCase (T("curved")) ? PathStrokeType::curved
  67946. : (jointStyle.equalsIgnoreCase (T("bevel")) ? PathStrokeType::beveled
  67947. : PathStrokeType::mitered),
  67948. endStyle.equalsIgnoreCase (T("square")) ? PathStrokeType::square
  67949. : (endStyle.equalsIgnoreCase (T("round")) ? PathStrokeType::rounded
  67950. : PathStrokeType::butt));
  67951. p->path.clear();
  67952. p->path.restoreFromString (tree ["path"]);
  67953. p->updateOutline();
  67954. return p;
  67955. }
  67956. END_JUCE_NAMESPACE
  67957. /*** End of inlined file: juce_DrawablePath.cpp ***/
  67958. /*** Start of inlined file: juce_DrawableText.cpp ***/
  67959. BEGIN_JUCE_NAMESPACE
  67960. DrawableText::DrawableText()
  67961. : colour (Colours::white)
  67962. {
  67963. }
  67964. DrawableText::~DrawableText()
  67965. {
  67966. }
  67967. void DrawableText::setText (const GlyphArrangement& newText)
  67968. {
  67969. text = newText;
  67970. }
  67971. void DrawableText::setText (const String& newText, const Font& fontToUse)
  67972. {
  67973. text.clear();
  67974. text.addLineOfText (fontToUse, newText, 0.0f, 0.0f);
  67975. }
  67976. void DrawableText::setColour (const Colour& newColour)
  67977. {
  67978. colour = newColour;
  67979. }
  67980. void DrawableText::render (const Drawable::RenderingContext& context) const
  67981. {
  67982. context.g.setColour (colour.withMultipliedAlpha (context.opacity));
  67983. text.draw (context.g, context.transform);
  67984. }
  67985. const Rectangle<float> DrawableText::getBounds() const
  67986. {
  67987. float x, y, w, h;
  67988. text.getBoundingBox (0, -1, x, y, w, h, false); // (really returns top, left, bottom, right)
  67989. w -= x;
  67990. h -= y;
  67991. return Rectangle<float> (x, y, w, h);
  67992. }
  67993. bool DrawableText::hitTest (float x, float y) const
  67994. {
  67995. return text.findGlyphIndexAt (x, y) >= 0;
  67996. }
  67997. Drawable* DrawableText::createCopy() const
  67998. {
  67999. DrawableText* const dt = new DrawableText();
  68000. dt->text = text;
  68001. dt->colour = colour;
  68002. return dt;
  68003. }
  68004. ValueTree DrawableText::createValueTree() const throw()
  68005. {
  68006. ValueTree v (T("Text"));
  68007. if (getName().isNotEmpty())
  68008. v.setProperty ("id", getName(), 0);
  68009. jassertfalse // xxx not finished!
  68010. return v;
  68011. }
  68012. DrawableText* DrawableText::createFromValueTree (const ValueTree& tree) throw()
  68013. {
  68014. if (! tree.hasType ("Text"))
  68015. return 0;
  68016. DrawableText* dt = new DrawableText();
  68017. dt->setName (tree ["id"]);
  68018. jassertfalse // xxx not finished!
  68019. return dt;
  68020. }
  68021. END_JUCE_NAMESPACE
  68022. /*** End of inlined file: juce_DrawableText.cpp ***/
  68023. /*** Start of inlined file: juce_SVGParser.cpp ***/
  68024. BEGIN_JUCE_NAMESPACE
  68025. class SVGState
  68026. {
  68027. public:
  68028. SVGState (const XmlElement* const topLevel)
  68029. : topLevelXml (topLevel),
  68030. elementX (0), elementY (0),
  68031. width (512), height (512),
  68032. viewBoxW (0), viewBoxH (0)
  68033. {
  68034. }
  68035. ~SVGState()
  68036. {
  68037. }
  68038. Drawable* parseSVGElement (const XmlElement& xml)
  68039. {
  68040. if (! xml.hasTagName (T("svg")))
  68041. return 0;
  68042. DrawableComposite* const drawable = new DrawableComposite();
  68043. drawable->setName (xml.getStringAttribute (T("id")));
  68044. SVGState newState (*this);
  68045. if (xml.hasAttribute (T("transform")))
  68046. newState.addTransform (xml);
  68047. newState.elementX = getCoordLength (xml.getStringAttribute (T("x"), String (newState.elementX)), viewBoxW);
  68048. newState.elementY = getCoordLength (xml.getStringAttribute (T("y"), String (newState.elementY)), viewBoxH);
  68049. newState.width = getCoordLength (xml.getStringAttribute (T("width"), String (newState.width)), viewBoxW);
  68050. newState.height = getCoordLength (xml.getStringAttribute (T("height"), String (newState.height)), viewBoxH);
  68051. if (xml.hasAttribute (T("viewBox")))
  68052. {
  68053. const String viewParams (xml.getStringAttribute (T("viewBox")));
  68054. int i = 0;
  68055. float vx, vy, vw, vh;
  68056. if (parseCoords (viewParams, vx, vy, i, true)
  68057. && parseCoords (viewParams, vw, vh, i, true)
  68058. && vw > 0
  68059. && vh > 0)
  68060. {
  68061. newState.viewBoxW = vw;
  68062. newState.viewBoxH = vh;
  68063. int placementFlags = 0;
  68064. const String aspect (xml.getStringAttribute (T("preserveAspectRatio")));
  68065. if (aspect.containsIgnoreCase (T("none")))
  68066. {
  68067. placementFlags = RectanglePlacement::stretchToFit;
  68068. }
  68069. else
  68070. {
  68071. if (aspect.containsIgnoreCase (T("slice")))
  68072. placementFlags |= RectanglePlacement::fillDestination;
  68073. if (aspect.containsIgnoreCase (T("xMin")))
  68074. placementFlags |= RectanglePlacement::xLeft;
  68075. else if (aspect.containsIgnoreCase (T("xMax")))
  68076. placementFlags |= RectanglePlacement::xRight;
  68077. else
  68078. placementFlags |= RectanglePlacement::xMid;
  68079. if (aspect.containsIgnoreCase (T("yMin")))
  68080. placementFlags |= RectanglePlacement::yTop;
  68081. else if (aspect.containsIgnoreCase (T("yMax")))
  68082. placementFlags |= RectanglePlacement::yBottom;
  68083. else
  68084. placementFlags |= RectanglePlacement::yMid;
  68085. }
  68086. const RectanglePlacement placement (placementFlags);
  68087. newState.transform
  68088. = placement.getTransformToFit (vx, vy, vw, vh,
  68089. 0.0f, 0.0f, newState.width, newState.height)
  68090. .followedBy (newState.transform);
  68091. }
  68092. }
  68093. else
  68094. {
  68095. if (viewBoxW == 0)
  68096. newState.viewBoxW = newState.width;
  68097. if (viewBoxH == 0)
  68098. newState.viewBoxH = newState.height;
  68099. }
  68100. newState.parseSubElements (xml, drawable);
  68101. return drawable;
  68102. }
  68103. private:
  68104. const XmlElement* const topLevelXml;
  68105. float elementX, elementY, width, height, viewBoxW, viewBoxH;
  68106. AffineTransform transform;
  68107. String cssStyleText;
  68108. void parseSubElements (const XmlElement& xml, DrawableComposite* const parentDrawable)
  68109. {
  68110. forEachXmlChildElement (xml, e)
  68111. {
  68112. Drawable* d = 0;
  68113. if (e->hasTagName (T("g")))
  68114. d = parseGroupElement (*e);
  68115. else if (e->hasTagName (T("svg")))
  68116. d = parseSVGElement (*e);
  68117. else if (e->hasTagName (T("path")))
  68118. d = parsePath (*e);
  68119. else if (e->hasTagName (T("rect")))
  68120. d = parseRect (*e);
  68121. else if (e->hasTagName (T("circle")))
  68122. d = parseCircle (*e);
  68123. else if (e->hasTagName (T("ellipse")))
  68124. d = parseEllipse (*e);
  68125. else if (e->hasTagName (T("line")))
  68126. d = parseLine (*e);
  68127. else if (e->hasTagName (T("polyline")))
  68128. d = parsePolygon (*e, true);
  68129. else if (e->hasTagName (T("polygon")))
  68130. d = parsePolygon (*e, false);
  68131. else if (e->hasTagName (T("text")))
  68132. d = parseText (*e);
  68133. else if (e->hasTagName (T("switch")))
  68134. d = parseSwitch (*e);
  68135. else if (e->hasTagName (T("style")))
  68136. parseCSSStyle (*e);
  68137. parentDrawable->insertDrawable (d);
  68138. }
  68139. }
  68140. DrawableComposite* parseSwitch (const XmlElement& xml)
  68141. {
  68142. const XmlElement* const group = xml.getChildByName (T("g"));
  68143. if (group != 0)
  68144. return parseGroupElement (*group);
  68145. return 0;
  68146. }
  68147. DrawableComposite* parseGroupElement (const XmlElement& xml)
  68148. {
  68149. DrawableComposite* const drawable = new DrawableComposite();
  68150. drawable->setName (xml.getStringAttribute (T("id")));
  68151. if (xml.hasAttribute (T("transform")))
  68152. {
  68153. SVGState newState (*this);
  68154. newState.addTransform (xml);
  68155. newState.parseSubElements (xml, drawable);
  68156. }
  68157. else
  68158. {
  68159. parseSubElements (xml, drawable);
  68160. }
  68161. return drawable;
  68162. }
  68163. Drawable* parsePath (const XmlElement& xml) const
  68164. {
  68165. const String d (xml.getStringAttribute (T("d")).trimStart());
  68166. Path path;
  68167. if (getStyleAttribute (&xml, T("fill-rule")).trim().equalsIgnoreCase (T("evenodd")))
  68168. path.setUsingNonZeroWinding (false);
  68169. int index = 0;
  68170. float lastX = 0, lastY = 0;
  68171. float lastX2 = 0, lastY2 = 0;
  68172. tchar lastCommandChar = 0;
  68173. bool carryOn = true;
  68174. const String validCommandChars (T("MmLlHhVvCcSsQqTtAaZz"));
  68175. for (;;)
  68176. {
  68177. float x, y, x2, y2, x3, y3;
  68178. const bool isRelative = (d[index] >= 'a' && d[index] <= 'z');
  68179. if (validCommandChars.containsChar (d[index]))
  68180. lastCommandChar = d [index++];
  68181. switch (lastCommandChar)
  68182. {
  68183. case T('M'):
  68184. case T('m'):
  68185. case T('L'):
  68186. case T('l'):
  68187. if (parseCoords (d, x, y, index, false))
  68188. {
  68189. if (isRelative)
  68190. {
  68191. x += lastX;
  68192. y += lastY;
  68193. }
  68194. if (lastCommandChar == T('M') || lastCommandChar == T('m'))
  68195. path.startNewSubPath (x, y);
  68196. else
  68197. path.lineTo (x, y);
  68198. lastX2 = lastX;
  68199. lastY2 = lastY;
  68200. lastX = x;
  68201. lastY = y;
  68202. }
  68203. else
  68204. {
  68205. ++index;
  68206. }
  68207. break;
  68208. case T('H'):
  68209. case T('h'):
  68210. if (parseCoord (d, x, index, false, true))
  68211. {
  68212. if (isRelative)
  68213. x += lastX;
  68214. path.lineTo (x, lastY);
  68215. lastX2 = lastX;
  68216. lastX = x;
  68217. }
  68218. else
  68219. {
  68220. ++index;
  68221. }
  68222. break;
  68223. case T('V'):
  68224. case T('v'):
  68225. if (parseCoord (d, y, index, false, false))
  68226. {
  68227. if (isRelative)
  68228. y += lastY;
  68229. path.lineTo (lastX, y);
  68230. lastY2 = lastY;
  68231. lastY = y;
  68232. }
  68233. else
  68234. {
  68235. ++index;
  68236. }
  68237. break;
  68238. case T('C'):
  68239. case T('c'):
  68240. if (parseCoords (d, x, y, index, false)
  68241. && parseCoords (d, x2, y2, index, false)
  68242. && parseCoords (d, x3, y3, index, false))
  68243. {
  68244. if (isRelative)
  68245. {
  68246. x += lastX;
  68247. y += lastY;
  68248. x2 += lastX;
  68249. y2 += lastY;
  68250. x3 += lastX;
  68251. y3 += lastY;
  68252. }
  68253. path.cubicTo (x, y, x2, y2, x3, y3);
  68254. lastX2 = x2;
  68255. lastY2 = y2;
  68256. lastX = x3;
  68257. lastY = y3;
  68258. }
  68259. else
  68260. {
  68261. ++index;
  68262. }
  68263. break;
  68264. case T('S'):
  68265. case T('s'):
  68266. if (parseCoords (d, x, y, index, false)
  68267. && parseCoords (d, x3, y3, index, false))
  68268. {
  68269. if (isRelative)
  68270. {
  68271. x += lastX;
  68272. y += lastY;
  68273. x3 += lastX;
  68274. y3 += lastY;
  68275. }
  68276. x2 = lastX + (lastX - lastX2);
  68277. y2 = lastY + (lastY - lastY2);
  68278. path.cubicTo (x2, y2, x, y, x3, y3);
  68279. lastX2 = x;
  68280. lastY2 = y;
  68281. lastX = x3;
  68282. lastY = y3;
  68283. }
  68284. else
  68285. {
  68286. ++index;
  68287. }
  68288. break;
  68289. case T('Q'):
  68290. case T('q'):
  68291. if (parseCoords (d, x, y, index, false)
  68292. && parseCoords (d, x2, y2, index, false))
  68293. {
  68294. if (isRelative)
  68295. {
  68296. x += lastX;
  68297. y += lastY;
  68298. x2 += lastX;
  68299. y2 += lastY;
  68300. }
  68301. path.quadraticTo (x, y, x2, y2);
  68302. lastX2 = x;
  68303. lastY2 = y;
  68304. lastX = x2;
  68305. lastY = y2;
  68306. }
  68307. else
  68308. {
  68309. ++index;
  68310. }
  68311. break;
  68312. case T('T'):
  68313. case T('t'):
  68314. if (parseCoords (d, x, y, index, false))
  68315. {
  68316. if (isRelative)
  68317. {
  68318. x += lastX;
  68319. y += lastY;
  68320. }
  68321. x2 = lastX + (lastX - lastX2);
  68322. y2 = lastY + (lastY - lastY2);
  68323. path.quadraticTo (x2, y2, x, y);
  68324. lastX2 = x2;
  68325. lastY2 = y2;
  68326. lastX = x;
  68327. lastY = y;
  68328. }
  68329. else
  68330. {
  68331. ++index;
  68332. }
  68333. break;
  68334. case T('A'):
  68335. case T('a'):
  68336. if (parseCoords (d, x, y, index, false))
  68337. {
  68338. String num;
  68339. if (parseNextNumber (d, num, index, false))
  68340. {
  68341. const float angle = num.getFloatValue() * (180.0f / float_Pi);
  68342. if (parseNextNumber (d, num, index, false))
  68343. {
  68344. const bool largeArc = num.getIntValue() != 0;
  68345. if (parseNextNumber (d, num, index, false))
  68346. {
  68347. const bool sweep = num.getIntValue() != 0;
  68348. if (parseCoords (d, x2, y2, index, false))
  68349. {
  68350. if (isRelative)
  68351. {
  68352. x2 += lastX;
  68353. y2 += lastY;
  68354. }
  68355. if (lastX != x2 || lastY != y2)
  68356. {
  68357. double centreX, centreY, startAngle, deltaAngle;
  68358. double rx = x, ry = y;
  68359. endpointToCentreParameters (lastX, lastY, x2, y2,
  68360. angle, largeArc, sweep,
  68361. rx, ry, centreX, centreY,
  68362. startAngle, deltaAngle);
  68363. path.addCentredArc ((float) centreX, (float) centreY,
  68364. (float) rx, (float) ry,
  68365. angle, (float) startAngle, (float) (startAngle + deltaAngle),
  68366. false);
  68367. path.lineTo (x2, y2);
  68368. }
  68369. lastX2 = lastX;
  68370. lastY2 = lastY;
  68371. lastX = x2;
  68372. lastY = y2;
  68373. }
  68374. }
  68375. }
  68376. }
  68377. }
  68378. else
  68379. {
  68380. ++index;
  68381. }
  68382. break;
  68383. case T('Z'):
  68384. case T('z'):
  68385. path.closeSubPath();
  68386. while (CharacterFunctions::isWhitespace (d [index]))
  68387. ++index;
  68388. break;
  68389. default:
  68390. carryOn = false;
  68391. break;
  68392. }
  68393. if (! carryOn)
  68394. break;
  68395. }
  68396. return parseShape (xml, path);
  68397. }
  68398. Drawable* parseRect (const XmlElement& xml) const
  68399. {
  68400. Path rect;
  68401. const bool hasRX = xml.hasAttribute (T("rx"));
  68402. const bool hasRY = xml.hasAttribute (T("ry"));
  68403. if (hasRX || hasRY)
  68404. {
  68405. float rx = getCoordLength (xml.getStringAttribute (T("rx")), viewBoxW);
  68406. float ry = getCoordLength (xml.getStringAttribute (T("ry")), viewBoxH);
  68407. if (! hasRX)
  68408. rx = ry;
  68409. else if (! hasRY)
  68410. ry = rx;
  68411. rect.addRoundedRectangle (getCoordLength (xml.getStringAttribute (T("x")), viewBoxW),
  68412. getCoordLength (xml.getStringAttribute (T("y")), viewBoxH),
  68413. getCoordLength (xml.getStringAttribute (T("width")), viewBoxW),
  68414. getCoordLength (xml.getStringAttribute (T("height")), viewBoxH),
  68415. rx, ry);
  68416. }
  68417. else
  68418. {
  68419. rect.addRectangle (getCoordLength (xml.getStringAttribute (T("x")), viewBoxW),
  68420. getCoordLength (xml.getStringAttribute (T("y")), viewBoxH),
  68421. getCoordLength (xml.getStringAttribute (T("width")), viewBoxW),
  68422. getCoordLength (xml.getStringAttribute (T("height")), viewBoxH));
  68423. }
  68424. return parseShape (xml, rect);
  68425. }
  68426. Drawable* parseCircle (const XmlElement& xml) const
  68427. {
  68428. Path circle;
  68429. const float cx = getCoordLength (xml.getStringAttribute (T("cx")), viewBoxW);
  68430. const float cy = getCoordLength (xml.getStringAttribute (T("cy")), viewBoxH);
  68431. const float radius = getCoordLength (xml.getStringAttribute (T("r")), viewBoxW);
  68432. circle.addEllipse (cx - radius, cy - radius, radius * 2.0f, radius * 2.0f);
  68433. return parseShape (xml, circle);
  68434. }
  68435. Drawable* parseEllipse (const XmlElement& xml) const
  68436. {
  68437. Path ellipse;
  68438. const float cx = getCoordLength (xml.getStringAttribute (T("cx")), viewBoxW);
  68439. const float cy = getCoordLength (xml.getStringAttribute (T("cy")), viewBoxH);
  68440. const float radiusX = getCoordLength (xml.getStringAttribute (T("rx")), viewBoxW);
  68441. const float radiusY = getCoordLength (xml.getStringAttribute (T("ry")), viewBoxH);
  68442. ellipse.addEllipse (cx - radiusX, cy - radiusY, radiusX * 2.0f, radiusY * 2.0f);
  68443. return parseShape (xml, ellipse);
  68444. }
  68445. Drawable* parseLine (const XmlElement& xml) const
  68446. {
  68447. Path line;
  68448. const float x1 = getCoordLength (xml.getStringAttribute (T("x1")), viewBoxW);
  68449. const float y1 = getCoordLength (xml.getStringAttribute (T("y1")), viewBoxH);
  68450. const float x2 = getCoordLength (xml.getStringAttribute (T("x2")), viewBoxW);
  68451. const float y2 = getCoordLength (xml.getStringAttribute (T("y2")), viewBoxH);
  68452. line.startNewSubPath (x1, y1);
  68453. line.lineTo (x2, y2);
  68454. return parseShape (xml, line);
  68455. }
  68456. Drawable* parsePolygon (const XmlElement& xml, const bool isPolyline) const
  68457. {
  68458. const String points (xml.getStringAttribute (T("points")));
  68459. Path path;
  68460. int index = 0;
  68461. float x, y;
  68462. if (parseCoords (points, x, y, index, true))
  68463. {
  68464. float firstX = x;
  68465. float firstY = y;
  68466. float lastX = 0, lastY = 0;
  68467. path.startNewSubPath (x, y);
  68468. while (parseCoords (points, x, y, index, true))
  68469. {
  68470. lastX = x;
  68471. lastY = y;
  68472. path.lineTo (x, y);
  68473. }
  68474. if ((! isPolyline) || (firstX == lastX && firstY == lastY))
  68475. path.closeSubPath();
  68476. }
  68477. return parseShape (xml, path);
  68478. }
  68479. Drawable* parseShape (const XmlElement& xml, Path& path,
  68480. const bool shouldParseTransform = true) const
  68481. {
  68482. if (shouldParseTransform && xml.hasAttribute (T("transform")))
  68483. {
  68484. SVGState newState (*this);
  68485. newState.addTransform (xml);
  68486. return newState.parseShape (xml, path, false);
  68487. }
  68488. DrawablePath* dp = new DrawablePath();
  68489. dp->setName (xml.getStringAttribute (T("id")));
  68490. dp->setFill (FillType (Colours::transparentBlack));
  68491. path.applyTransform (transform);
  68492. dp->setPath (path);
  68493. Path::Iterator iter (path);
  68494. bool containsClosedSubPath = false;
  68495. while (iter.next())
  68496. {
  68497. if (iter.elementType == Path::Iterator::closePath)
  68498. {
  68499. containsClosedSubPath = true;
  68500. break;
  68501. }
  68502. }
  68503. dp->setFill (getPathFillType (path,
  68504. getStyleAttribute (&xml, T("fill")),
  68505. getStyleAttribute (&xml, T("fill-opacity")),
  68506. getStyleAttribute (&xml, T("opacity")),
  68507. containsClosedSubPath ? Colours::black
  68508. : Colours::transparentBlack));
  68509. const String strokeType (getStyleAttribute (&xml, T("stroke")));
  68510. if (strokeType.isNotEmpty() && ! strokeType.equalsIgnoreCase (T("none")))
  68511. {
  68512. dp->setStrokeFill (getPathFillType (path, strokeType,
  68513. getStyleAttribute (&xml, T("stroke-opacity")),
  68514. getStyleAttribute (&xml, T("opacity")),
  68515. Colours::transparentBlack));
  68516. dp->setStrokeType (getStrokeFor (&xml));
  68517. }
  68518. return dp;
  68519. }
  68520. const XmlElement* findLinkedElement (const XmlElement* e) const
  68521. {
  68522. const String id (e->getStringAttribute (T("xlink:href")));
  68523. if (! id.startsWithChar (T('#')))
  68524. return 0;
  68525. return findElementForId (topLevelXml, id.substring (1));
  68526. }
  68527. void addGradientStopsIn (ColourGradient& cg, const XmlElement* const fillXml) const
  68528. {
  68529. if (fillXml == 0)
  68530. return;
  68531. forEachXmlChildElementWithTagName (*fillXml, e, T("stop"))
  68532. {
  68533. int index = 0;
  68534. Colour col (parseColour (getStyleAttribute (e, T("stop-color")), index, Colours::black));
  68535. const String opacity (getStyleAttribute (e, T("stop-opacity"), T("1")));
  68536. col = col.withMultipliedAlpha (jlimit (0.0f, 1.0f, opacity.getFloatValue()));
  68537. double offset = e->getDoubleAttribute (T("offset"));
  68538. if (e->getStringAttribute (T("offset")).containsChar (T('%')))
  68539. offset *= 0.01;
  68540. cg.addColour (jlimit (0.0, 1.0, offset), col);
  68541. }
  68542. }
  68543. const FillType getPathFillType (const Path& path,
  68544. const String& fill,
  68545. const String& fillOpacity,
  68546. const String& overallOpacity,
  68547. const Colour& defaultColour) const
  68548. {
  68549. float opacity = 1.0f;
  68550. if (overallOpacity.isNotEmpty())
  68551. opacity = jlimit (0.0f, 1.0f, overallOpacity.getFloatValue());
  68552. if (fillOpacity.isNotEmpty())
  68553. opacity *= (jlimit (0.0f, 1.0f, fillOpacity.getFloatValue()));
  68554. if (fill.startsWithIgnoreCase (T("url")))
  68555. {
  68556. const String id (fill.fromFirstOccurrenceOf (T("#"), false, false)
  68557. .upToLastOccurrenceOf (T(")"), false, false).trim());
  68558. const XmlElement* const fillXml = findElementForId (topLevelXml, id);
  68559. if (fillXml != 0
  68560. && (fillXml->hasTagName (T("linearGradient"))
  68561. || fillXml->hasTagName (T("radialGradient"))))
  68562. {
  68563. const XmlElement* inheritedFrom = findLinkedElement (fillXml);
  68564. ColourGradient gradient;
  68565. addGradientStopsIn (gradient, inheritedFrom);
  68566. addGradientStopsIn (gradient, fillXml);
  68567. if (gradient.getNumColours() > 0)
  68568. {
  68569. gradient.addColour (0.0, gradient.getColour (0));
  68570. gradient.addColour (1.0, gradient.getColour (gradient.getNumColours() - 1));
  68571. }
  68572. else
  68573. {
  68574. gradient.addColour (0.0, Colours::black);
  68575. gradient.addColour (1.0, Colours::black);
  68576. }
  68577. if (overallOpacity.isNotEmpty())
  68578. gradient.multiplyOpacity (overallOpacity.getFloatValue());
  68579. jassert (gradient.getNumColours() > 0);
  68580. gradient.isRadial = fillXml->hasTagName (T("radialGradient"));
  68581. float width = viewBoxW;
  68582. float height = viewBoxH;
  68583. float dx = 0.0f;
  68584. float dy = 0.0f;
  68585. const bool userSpace = fillXml->getStringAttribute (T("gradientUnits")).equalsIgnoreCase (T("userSpaceOnUse"));
  68586. if (! userSpace)
  68587. {
  68588. const Rectangle<float> bounds (path.getBounds());
  68589. dx = bounds.getX();
  68590. dy = bounds.getY();
  68591. width = bounds.getWidth();
  68592. height = bounds.getHeight();
  68593. }
  68594. if (gradient.isRadial)
  68595. {
  68596. gradient.x1 = dx + getCoordLength (fillXml->getStringAttribute (T("cx"), T("50%")), width);
  68597. gradient.y1 = dy + getCoordLength (fillXml->getStringAttribute (T("cy"), T("50%")), height);
  68598. const float radius = getCoordLength (fillXml->getStringAttribute (T("r"), T("50%")), width);
  68599. gradient.x2 = gradient.x1 + radius;
  68600. gradient.y2 = gradient.y1;
  68601. //xxx (the fx, fy focal point isn't handled properly here..)
  68602. }
  68603. else
  68604. {
  68605. gradient.x1 = dx + getCoordLength (fillXml->getStringAttribute (T("x1"), T("0%")), width);
  68606. gradient.y1 = dy + getCoordLength (fillXml->getStringAttribute (T("y1"), T("0%")), height);
  68607. gradient.x2 = dx + getCoordLength (fillXml->getStringAttribute (T("x2"), T("100%")), width);
  68608. gradient.y2 = dy + getCoordLength (fillXml->getStringAttribute (T("y2"), T("0%")), height);
  68609. if (gradient.x1 == gradient.x2 && gradient.y1 == gradient.y2)
  68610. return Colour (gradient.getColour (gradient.getNumColours() - 1));
  68611. }
  68612. FillType type (gradient);
  68613. type.transform = parseTransform (fillXml->getStringAttribute (T("gradientTransform")))
  68614. .followedBy (transform);
  68615. return type;
  68616. }
  68617. }
  68618. if (fill.equalsIgnoreCase (T("none")))
  68619. return Colours::transparentBlack;
  68620. int i = 0;
  68621. const Colour colour (parseColour (fill, i, defaultColour));
  68622. return colour.withMultipliedAlpha (opacity);
  68623. }
  68624. const PathStrokeType getStrokeFor (const XmlElement* const xml) const
  68625. {
  68626. const String width (getStyleAttribute (xml, T("stroke-width")));
  68627. const String cap (getStyleAttribute (xml, T("stroke-linecap")));
  68628. const String join (getStyleAttribute (xml, T("stroke-linejoin")));
  68629. //const String mitreLimit (getStyleAttribute (xml, T("stroke-miterlimit")));
  68630. //const String dashArray (getStyleAttribute (xml, T("stroke-dasharray")));
  68631. //const String dashOffset (getStyleAttribute (xml, T("stroke-dashoffset")));
  68632. PathStrokeType::JointStyle joinStyle = PathStrokeType::mitered;
  68633. PathStrokeType::EndCapStyle capStyle = PathStrokeType::butt;
  68634. if (join.equalsIgnoreCase (T("round")))
  68635. joinStyle = PathStrokeType::curved;
  68636. else if (join.equalsIgnoreCase (T("bevel")))
  68637. joinStyle = PathStrokeType::beveled;
  68638. if (cap.equalsIgnoreCase (T("round")))
  68639. capStyle = PathStrokeType::rounded;
  68640. else if (cap.equalsIgnoreCase (T("square")))
  68641. capStyle = PathStrokeType::square;
  68642. float ox = 0.0f, oy = 0.0f;
  68643. transform.transformPoint (ox, oy);
  68644. float x = getCoordLength (width, viewBoxW), y = 0.0f;
  68645. transform.transformPoint (x, y);
  68646. return PathStrokeType (width.isNotEmpty() ? juce_hypotf (x - ox, y - oy) : 1.0f,
  68647. joinStyle, capStyle);
  68648. }
  68649. Drawable* parseText (const XmlElement& xml)
  68650. {
  68651. Array <float> xCoords, yCoords, dxCoords, dyCoords;
  68652. getCoordList (xCoords, getInheritedAttribute (&xml, T("x")), true, true);
  68653. getCoordList (yCoords, getInheritedAttribute (&xml, T("y")), true, false);
  68654. getCoordList (dxCoords, getInheritedAttribute (&xml, T("dx")), true, true);
  68655. getCoordList (dyCoords, getInheritedAttribute (&xml, T("dy")), true, false);
  68656. //xxx not done text yet!
  68657. forEachXmlChildElement (xml, e)
  68658. {
  68659. if (e->isTextElement())
  68660. {
  68661. const String text (e->getText());
  68662. Path path;
  68663. Drawable* s = parseShape (*e, path);
  68664. delete s;
  68665. }
  68666. else if (e->hasTagName (T("tspan")))
  68667. {
  68668. Drawable* s = parseText (*e);
  68669. delete s;
  68670. }
  68671. }
  68672. return 0;
  68673. }
  68674. void addTransform (const XmlElement& xml)
  68675. {
  68676. transform = parseTransform (xml.getStringAttribute (T("transform")))
  68677. .followedBy (transform);
  68678. }
  68679. bool parseCoord (const String& s, float& value, int& index,
  68680. const bool allowUnits, const bool isX) const
  68681. {
  68682. String number;
  68683. if (! parseNextNumber (s, number, index, allowUnits))
  68684. {
  68685. value = 0;
  68686. return false;
  68687. }
  68688. value = getCoordLength (number, isX ? viewBoxW : viewBoxH);
  68689. return true;
  68690. }
  68691. bool parseCoords (const String& s, float& x, float& y,
  68692. int& index, const bool allowUnits) const
  68693. {
  68694. return parseCoord (s, x, index, allowUnits, true)
  68695. && parseCoord (s, y, index, allowUnits, false);
  68696. }
  68697. float getCoordLength (const String& s, const float sizeForProportions) const
  68698. {
  68699. float n = s.getFloatValue();
  68700. const int len = s.length();
  68701. if (len > 2)
  68702. {
  68703. const float dpi = 96.0f;
  68704. const tchar n1 = s [len - 2];
  68705. const tchar n2 = s [len - 1];
  68706. if (n1 == T('i') && n2 == T('n'))
  68707. n *= dpi;
  68708. else if (n1 == T('m') && n2 == T('m'))
  68709. n *= dpi / 25.4f;
  68710. else if (n1 == T('c') && n2 == T('m'))
  68711. n *= dpi / 2.54f;
  68712. else if (n1 == T('p') && n2 == T('c'))
  68713. n *= 15.0f;
  68714. else if (n2 == T('%'))
  68715. n *= 0.01f * sizeForProportions;
  68716. }
  68717. return n;
  68718. }
  68719. void getCoordList (Array <float>& coords, const String& list,
  68720. const bool allowUnits, const bool isX) const
  68721. {
  68722. int index = 0;
  68723. float value;
  68724. while (parseCoord (list, value, index, allowUnits, isX))
  68725. coords.add (value);
  68726. }
  68727. void parseCSSStyle (const XmlElement& xml)
  68728. {
  68729. cssStyleText = xml.getAllSubText() + T("\n") + cssStyleText;
  68730. }
  68731. const String getStyleAttribute (const XmlElement* xml, const String& attributeName,
  68732. const String& defaultValue = String::empty) const
  68733. {
  68734. if (xml->hasAttribute (attributeName))
  68735. return xml->getStringAttribute (attributeName, defaultValue);
  68736. const String styleAtt (xml->getStringAttribute (T("style")));
  68737. if (styleAtt.isNotEmpty())
  68738. {
  68739. const String value (getAttributeFromStyleList (styleAtt, attributeName, String::empty));
  68740. if (value.isNotEmpty())
  68741. return value;
  68742. }
  68743. else if (xml->hasAttribute (T("class")))
  68744. {
  68745. const String className (T(".") + xml->getStringAttribute (T("class")));
  68746. int index = cssStyleText.indexOfIgnoreCase (className + T(" "));
  68747. if (index < 0)
  68748. index = cssStyleText.indexOfIgnoreCase (className + T("{"));
  68749. if (index >= 0)
  68750. {
  68751. const int openBracket = cssStyleText.indexOfChar (index, T('{'));
  68752. if (openBracket > index)
  68753. {
  68754. const int closeBracket = cssStyleText.indexOfChar (openBracket, T('}'));
  68755. if (closeBracket > openBracket)
  68756. {
  68757. const String value (getAttributeFromStyleList (cssStyleText.substring (openBracket + 1, closeBracket), attributeName, defaultValue));
  68758. if (value.isNotEmpty())
  68759. return value;
  68760. }
  68761. }
  68762. }
  68763. }
  68764. xml = const_cast <XmlElement*> (topLevelXml)->findParentElementOf (xml);
  68765. if (xml != 0)
  68766. return getStyleAttribute (xml, attributeName, defaultValue);
  68767. return defaultValue;
  68768. }
  68769. const String getInheritedAttribute (const XmlElement* xml, const String& attributeName) const
  68770. {
  68771. if (xml->hasAttribute (attributeName))
  68772. return xml->getStringAttribute (attributeName);
  68773. xml = const_cast <XmlElement*> (topLevelXml)->findParentElementOf (xml);
  68774. if (xml != 0)
  68775. return getInheritedAttribute (xml, attributeName);
  68776. return String::empty;
  68777. }
  68778. static bool isIdentifierChar (const tchar c)
  68779. {
  68780. return CharacterFunctions::isLetter (c) || c == T('-');
  68781. }
  68782. static const String getAttributeFromStyleList (const String& list, const String& attributeName, const String& defaultValue)
  68783. {
  68784. int i = 0;
  68785. for (;;)
  68786. {
  68787. i = list.indexOf (i, attributeName);
  68788. if (i < 0)
  68789. break;
  68790. if ((i == 0 || (i > 0 && ! isIdentifierChar (list [i - 1])))
  68791. && ! isIdentifierChar (list [i + attributeName.length()]))
  68792. {
  68793. i = list.indexOfChar (i, T(':'));
  68794. if (i < 0)
  68795. break;
  68796. int end = list.indexOfChar (i, T(';'));
  68797. if (end < 0)
  68798. end = 0x7ffff;
  68799. return list.substring (i + 1, end).trim();
  68800. }
  68801. ++i;
  68802. }
  68803. return defaultValue;
  68804. }
  68805. static bool parseNextNumber (const String& source, String& value, int& index, const bool allowUnits)
  68806. {
  68807. const tchar* const s = (const tchar*) source;
  68808. while (CharacterFunctions::isWhitespace (s[index]) || s[index] == T(','))
  68809. ++index;
  68810. int start = index;
  68811. if (CharacterFunctions::isDigit (s[index]) || s[index] == T('.') || s[index] == T('-'))
  68812. ++index;
  68813. while (CharacterFunctions::isDigit (s[index]) || s[index] == T('.'))
  68814. ++index;
  68815. if ((s[index] == T('e') || s[index] == T('E'))
  68816. && (CharacterFunctions::isDigit (s[index + 1])
  68817. || s[index + 1] == T('-')
  68818. || s[index + 1] == T('+')))
  68819. {
  68820. index += 2;
  68821. while (CharacterFunctions::isDigit (s[index]))
  68822. ++index;
  68823. }
  68824. if (allowUnits)
  68825. {
  68826. while (CharacterFunctions::isLetter (s[index]))
  68827. ++index;
  68828. }
  68829. if (index == start)
  68830. return false;
  68831. value = String (s + start, index - start);
  68832. while (CharacterFunctions::isWhitespace (s[index]) || s[index] == T(','))
  68833. ++index;
  68834. return true;
  68835. }
  68836. static const Colour parseColour (const String& s, int& index, const Colour& defaultColour)
  68837. {
  68838. if (s [index] == T('#'))
  68839. {
  68840. uint32 hex [6];
  68841. zeromem (hex, sizeof (hex));
  68842. int numChars = 0;
  68843. for (int i = 6; --i >= 0;)
  68844. {
  68845. const int hexValue = CharacterFunctions::getHexDigitValue (s [++index]);
  68846. if (hexValue >= 0)
  68847. hex [numChars++] = hexValue;
  68848. else
  68849. break;
  68850. }
  68851. if (numChars <= 3)
  68852. return Colour ((uint8) (hex [0] * 0x11),
  68853. (uint8) (hex [1] * 0x11),
  68854. (uint8) (hex [2] * 0x11));
  68855. else
  68856. return Colour ((uint8) ((hex [0] << 4) + hex [1]),
  68857. (uint8) ((hex [2] << 4) + hex [3]),
  68858. (uint8) ((hex [4] << 4) + hex [5]));
  68859. }
  68860. else if (s [index] == T('r')
  68861. && s [index + 1] == T('g')
  68862. && s [index + 2] == T('b'))
  68863. {
  68864. const int openBracket = s.indexOfChar (index, T('('));
  68865. const int closeBracket = s.indexOfChar (openBracket, T(')'));
  68866. if (openBracket >= 3 && closeBracket > openBracket)
  68867. {
  68868. index = closeBracket;
  68869. StringArray tokens;
  68870. tokens.addTokens (s.substring (openBracket + 1, closeBracket), T(","), T(""));
  68871. tokens.trim();
  68872. tokens.removeEmptyStrings();
  68873. if (tokens[0].containsChar (T('%')))
  68874. return Colour ((uint8) roundToInt (2.55 * tokens[0].getDoubleValue()),
  68875. (uint8) roundToInt (2.55 * tokens[1].getDoubleValue()),
  68876. (uint8) roundToInt (2.55 * tokens[2].getDoubleValue()));
  68877. else
  68878. return Colour ((uint8) tokens[0].getIntValue(),
  68879. (uint8) tokens[1].getIntValue(),
  68880. (uint8) tokens[2].getIntValue());
  68881. }
  68882. }
  68883. return Colours::findColourForName (s, defaultColour);
  68884. }
  68885. static const AffineTransform parseTransform (String t)
  68886. {
  68887. AffineTransform result;
  68888. while (t.isNotEmpty())
  68889. {
  68890. StringArray tokens;
  68891. tokens.addTokens (t.fromFirstOccurrenceOf (T("("), false, false)
  68892. .upToFirstOccurrenceOf (T(")"), false, false),
  68893. T(", "), 0);
  68894. tokens.removeEmptyStrings (true);
  68895. float numbers [6];
  68896. for (int i = 0; i < 6; ++i)
  68897. numbers[i] = tokens[i].getFloatValue();
  68898. AffineTransform trans;
  68899. if (t.startsWithIgnoreCase (T("matrix")))
  68900. {
  68901. trans = AffineTransform (numbers[0], numbers[2], numbers[4],
  68902. numbers[1], numbers[3], numbers[5]);
  68903. }
  68904. else if (t.startsWithIgnoreCase (T("translate")))
  68905. {
  68906. trans = trans.translated (numbers[0], numbers[1]);
  68907. }
  68908. else if (t.startsWithIgnoreCase (T("scale")))
  68909. {
  68910. if (tokens.size() == 1)
  68911. trans = trans.scaled (numbers[0], numbers[0]);
  68912. else
  68913. trans = trans.scaled (numbers[0], numbers[1]);
  68914. }
  68915. else if (t.startsWithIgnoreCase (T("rotate")))
  68916. {
  68917. if (tokens.size() != 3)
  68918. trans = trans.rotated (numbers[0] / (180.0f / float_Pi));
  68919. else
  68920. trans = trans.rotated (numbers[0] / (180.0f / float_Pi),
  68921. numbers[1], numbers[2]);
  68922. }
  68923. else if (t.startsWithIgnoreCase (T("skewX")))
  68924. {
  68925. trans = AffineTransform (1.0f, tanf (numbers[0] * (float_Pi / 180.0f)), 0.0f,
  68926. 0.0f, 1.0f, 0.0f);
  68927. }
  68928. else if (t.startsWithIgnoreCase (T("skewY")))
  68929. {
  68930. trans = AffineTransform (1.0f, 0.0f, 0.0f,
  68931. tanf (numbers[0] * (float_Pi / 180.0f)), 1.0f, 0.0f);
  68932. }
  68933. result = trans.followedBy (result);
  68934. t = t.fromFirstOccurrenceOf (T(")"), false, false).trimStart();
  68935. }
  68936. return result;
  68937. }
  68938. static void endpointToCentreParameters (const double x1, const double y1,
  68939. const double x2, const double y2,
  68940. const double angle,
  68941. const bool largeArc, const bool sweep,
  68942. double& rx, double& ry,
  68943. double& centreX, double& centreY,
  68944. double& startAngle, double& deltaAngle)
  68945. {
  68946. const double midX = (x1 - x2) * 0.5;
  68947. const double midY = (y1 - y2) * 0.5;
  68948. const double cosAngle = cos (angle);
  68949. const double sinAngle = sin (angle);
  68950. const double xp = cosAngle * midX + sinAngle * midY;
  68951. const double yp = cosAngle * midY - sinAngle * midX;
  68952. const double xp2 = xp * xp;
  68953. const double yp2 = yp * yp;
  68954. double rx2 = rx * rx;
  68955. double ry2 = ry * ry;
  68956. const double s = (xp2 / rx2) + (yp2 / ry2);
  68957. double c;
  68958. if (s <= 1.0)
  68959. {
  68960. c = sqrt (jmax (0.0, ((rx2 * ry2) - (rx2 * yp2) - (ry2 * xp2))
  68961. / (( rx2 * yp2) + (ry2 * xp2))));
  68962. if (largeArc == sweep)
  68963. c = -c;
  68964. }
  68965. else
  68966. {
  68967. const double s2 = sqrt (s);
  68968. rx *= s2;
  68969. ry *= s2;
  68970. rx2 = rx * rx;
  68971. ry2 = ry * ry;
  68972. c = 0;
  68973. }
  68974. const double cpx = ((rx * yp) / ry) * c;
  68975. const double cpy = ((-ry * xp) / rx) * c;
  68976. centreX = ((x1 + x2) * 0.5) + (cosAngle * cpx) - (sinAngle * cpy);
  68977. centreY = ((y1 + y2) * 0.5) + (sinAngle * cpx) + (cosAngle * cpy);
  68978. const double ux = (xp - cpx) / rx;
  68979. const double uy = (yp - cpy) / ry;
  68980. const double vx = (-xp - cpx) / rx;
  68981. const double vy = (-yp - cpy) / ry;
  68982. const double length = juce_hypot (ux, uy);
  68983. startAngle = acos (jlimit (-1.0, 1.0, ux / length));
  68984. if (uy < 0)
  68985. startAngle = -startAngle;
  68986. startAngle += double_Pi * 0.5;
  68987. deltaAngle = acos (jlimit (-1.0, 1.0, ((ux * vx) + (uy * vy))
  68988. / (length * juce_hypot (vx, vy))));
  68989. if ((ux * vy) - (uy * vx) < 0)
  68990. deltaAngle = -deltaAngle;
  68991. if (sweep)
  68992. {
  68993. if (deltaAngle < 0)
  68994. deltaAngle += double_Pi * 2.0;
  68995. }
  68996. else
  68997. {
  68998. if (deltaAngle > 0)
  68999. deltaAngle -= double_Pi * 2.0;
  69000. }
  69001. deltaAngle = fmod (deltaAngle, double_Pi * 2.0);
  69002. }
  69003. static const XmlElement* findElementForId (const XmlElement* const parent, const String& id)
  69004. {
  69005. forEachXmlChildElement (*parent, e)
  69006. {
  69007. if (e->compareAttribute (T("id"), id))
  69008. return e;
  69009. const XmlElement* const found = findElementForId (e, id);
  69010. if (found != 0)
  69011. return found;
  69012. }
  69013. return 0;
  69014. }
  69015. const SVGState& operator= (const SVGState&);
  69016. };
  69017. Drawable* Drawable::createFromSVG (const XmlElement& svgDocument)
  69018. {
  69019. SVGState state (&svgDocument);
  69020. return state.parseSVGElement (svgDocument);
  69021. }
  69022. END_JUCE_NAMESPACE
  69023. /*** End of inlined file: juce_SVGParser.cpp ***/
  69024. /*** Start of inlined file: juce_DropShadowEffect.cpp ***/
  69025. BEGIN_JUCE_NAMESPACE
  69026. #if JUCE_MSVC
  69027. #pragma optimize ("t", on) // try to avoid slowing everything down in debug builds
  69028. #endif
  69029. DropShadowEffect::DropShadowEffect()
  69030. : offsetX (0),
  69031. offsetY (0),
  69032. radius (4),
  69033. opacity (0.6f)
  69034. {
  69035. }
  69036. DropShadowEffect::~DropShadowEffect()
  69037. {
  69038. }
  69039. void DropShadowEffect::setShadowProperties (const float newRadius,
  69040. const float newOpacity,
  69041. const int newShadowOffsetX,
  69042. const int newShadowOffsetY)
  69043. {
  69044. radius = jmax (1.1f, newRadius);
  69045. offsetX = newShadowOffsetX;
  69046. offsetY = newShadowOffsetY;
  69047. opacity = newOpacity;
  69048. }
  69049. void DropShadowEffect::applyEffect (Image& image, Graphics& g)
  69050. {
  69051. const int w = image.getWidth();
  69052. const int h = image.getHeight();
  69053. Image shadowImage (Image::SingleChannel, w, h, false);
  69054. const Image::BitmapData srcData (image, 0, 0, w, h);
  69055. const Image::BitmapData destData (shadowImage, 0, 0, w, h, true);
  69056. const int filter = roundToInt (63.0f / radius);
  69057. const int radiusMinus1 = roundToInt ((radius - 1.0f) * 63.0f);
  69058. for (int x = w; --x >= 0;)
  69059. {
  69060. int shadowAlpha = 0;
  69061. const PixelARGB* src = ((const PixelARGB*) srcData.data) + x;
  69062. uint8* shadowPix = destData.data + x;
  69063. for (int y = h; --y >= 0;)
  69064. {
  69065. shadowAlpha = ((shadowAlpha * radiusMinus1 + (src->getAlpha() << 6)) * filter) >> 12;
  69066. *shadowPix = (uint8) shadowAlpha;
  69067. src = (const PixelARGB*) (((const uint8*) src) + srcData.lineStride);
  69068. shadowPix += destData.lineStride;
  69069. }
  69070. }
  69071. for (int y = h; --y >= 0;)
  69072. {
  69073. int shadowAlpha = 0;
  69074. uint8* shadowPix = destData.getLinePointer (y);
  69075. for (int x = w; --x >= 0;)
  69076. {
  69077. shadowAlpha = ((shadowAlpha * radiusMinus1 + (*shadowPix << 6)) * filter) >> 12;
  69078. *shadowPix++ = (uint8) shadowAlpha;
  69079. }
  69080. }
  69081. g.setColour (Colours::black.withAlpha (opacity));
  69082. g.drawImageAt (&shadowImage, offsetX, offsetY, true);
  69083. g.setOpacity (1.0f);
  69084. g.drawImageAt (&image, 0, 0);
  69085. }
  69086. END_JUCE_NAMESPACE
  69087. /*** End of inlined file: juce_DropShadowEffect.cpp ***/
  69088. /*** Start of inlined file: juce_GlowEffect.cpp ***/
  69089. BEGIN_JUCE_NAMESPACE
  69090. GlowEffect::GlowEffect()
  69091. : radius (2.0f),
  69092. colour (Colours::white)
  69093. {
  69094. }
  69095. GlowEffect::~GlowEffect()
  69096. {
  69097. }
  69098. void GlowEffect::setGlowProperties (const float newRadius,
  69099. const Colour& newColour)
  69100. {
  69101. radius = newRadius;
  69102. colour = newColour;
  69103. }
  69104. void GlowEffect::applyEffect (Image& image, Graphics& g)
  69105. {
  69106. const int w = image.getWidth();
  69107. const int h = image.getHeight();
  69108. Image temp (image.getFormat(), w, h, true);
  69109. ImageConvolutionKernel blurKernel (roundToInt (radius * 2.0f));
  69110. blurKernel.createGaussianBlur (radius);
  69111. blurKernel.rescaleAllValues (radius);
  69112. blurKernel.applyToImage (temp, &image, 0, 0, w, h);
  69113. g.setColour (colour);
  69114. g.drawImageAt (&temp, 0, 0, true);
  69115. g.setOpacity (1.0f);
  69116. g.drawImageAt (&image, 0, 0, false);
  69117. }
  69118. END_JUCE_NAMESPACE
  69119. /*** End of inlined file: juce_GlowEffect.cpp ***/
  69120. /*** Start of inlined file: juce_ReduceOpacityEffect.cpp ***/
  69121. BEGIN_JUCE_NAMESPACE
  69122. ReduceOpacityEffect::ReduceOpacityEffect (const float opacity_)
  69123. : opacity (opacity_)
  69124. {
  69125. }
  69126. ReduceOpacityEffect::~ReduceOpacityEffect()
  69127. {
  69128. }
  69129. void ReduceOpacityEffect::setOpacity (const float newOpacity)
  69130. {
  69131. opacity = jlimit (0.0f, 1.0f, newOpacity);
  69132. }
  69133. void ReduceOpacityEffect::applyEffect (Image& image, Graphics& g)
  69134. {
  69135. g.setOpacity (opacity);
  69136. g.drawImageAt (&image, 0, 0);
  69137. }
  69138. END_JUCE_NAMESPACE
  69139. /*** End of inlined file: juce_ReduceOpacityEffect.cpp ***/
  69140. /*** Start of inlined file: juce_Font.cpp ***/
  69141. BEGIN_JUCE_NAMESPACE
  69142. static const float minFontHeight = 0.1f;
  69143. static const float maxFontHeight = 10000.0f;
  69144. static const float defaultFontHeight = 14.0f;
  69145. static const tchar* const juce_defaultFontNameSans = T("<Sans-Serif>");
  69146. static const tchar* const juce_defaultFontNameSerif = T("<Serif>");
  69147. static const tchar* const juce_defaultFontNameMono = T("<Monospaced>");
  69148. void clearUpDefaultFontNames() throw(); // in juce_LookAndFeel.cpp
  69149. Font::SharedFontInternal::SharedFontInternal (const String& typefaceName_, const float height_, const float horizontalScale_,
  69150. const float kerning_, const float ascent_, const int styleFlags_,
  69151. Typeface* const typeface_) throw()
  69152. : typefaceName (typefaceName_),
  69153. height (height_),
  69154. horizontalScale (horizontalScale_),
  69155. kerning (kerning_),
  69156. ascent (ascent_),
  69157. styleFlags (styleFlags_),
  69158. typeface (typeface_)
  69159. {
  69160. }
  69161. Font::SharedFontInternal::SharedFontInternal (const SharedFontInternal& other) throw()
  69162. : typefaceName (other.typefaceName),
  69163. height (other.height),
  69164. horizontalScale (other.horizontalScale),
  69165. kerning (other.kerning),
  69166. ascent (other.ascent),
  69167. styleFlags (other.styleFlags),
  69168. typeface (other.typeface)
  69169. {
  69170. }
  69171. Font::Font() throw()
  69172. : font (new SharedFontInternal (juce_defaultFontNameSans, defaultFontHeight,
  69173. 1.0f, 0, 0, Font::plain, 0))
  69174. {
  69175. }
  69176. Font::Font (const float fontHeight, const int styleFlags_) throw()
  69177. : font (new SharedFontInternal (juce_defaultFontNameSans, jlimit (minFontHeight, maxFontHeight, fontHeight),
  69178. 1.0f, 0, 0, styleFlags_, 0))
  69179. {
  69180. }
  69181. Font::Font (const String& typefaceName_,
  69182. const float fontHeight,
  69183. const int styleFlags_) throw()
  69184. : font (new SharedFontInternal (typefaceName_, jlimit (minFontHeight, maxFontHeight, fontHeight),
  69185. 1.0f, 0, 0, styleFlags_, 0))
  69186. {
  69187. }
  69188. Font::Font (const Font& other) throw()
  69189. : font (other.font)
  69190. {
  69191. }
  69192. const Font& Font::operator= (const Font& other) throw()
  69193. {
  69194. font = other.font;
  69195. return *this;
  69196. }
  69197. Font::~Font() throw()
  69198. {
  69199. }
  69200. Font::Font (const Typeface::Ptr& typeface) throw()
  69201. : font (new SharedFontInternal (typeface->getName(), defaultFontHeight,
  69202. 1.0f, 0, 0, Font::plain, typeface))
  69203. {
  69204. }
  69205. bool Font::operator== (const Font& other) const throw()
  69206. {
  69207. return font == other.font
  69208. || (font->height == other.font->height
  69209. && font->styleFlags == other.font->styleFlags
  69210. && font->horizontalScale == other.font->horizontalScale
  69211. && font->kerning == other.font->kerning
  69212. && font->typefaceName == other.font->typefaceName);
  69213. }
  69214. bool Font::operator!= (const Font& other) const throw()
  69215. {
  69216. return ! operator== (other);
  69217. }
  69218. void Font::dupeInternalIfShared() throw()
  69219. {
  69220. if (font->getReferenceCount() > 1)
  69221. font = new SharedFontInternal (*font);
  69222. }
  69223. const String Font::getDefaultSansSerifFontName() throw()
  69224. {
  69225. return juce_defaultFontNameSans;
  69226. }
  69227. const String Font::getDefaultSerifFontName() throw()
  69228. {
  69229. return juce_defaultFontNameSerif;
  69230. }
  69231. const String Font::getDefaultMonospacedFontName() throw()
  69232. {
  69233. return juce_defaultFontNameMono;
  69234. }
  69235. void Font::setTypefaceName (const String& faceName) throw()
  69236. {
  69237. if (faceName != font->typefaceName)
  69238. {
  69239. dupeInternalIfShared();
  69240. font->typefaceName = faceName;
  69241. font->typeface = 0;
  69242. font->ascent = 0;
  69243. }
  69244. }
  69245. static String fallbackFont;
  69246. const String Font::getFallbackFontName() throw()
  69247. {
  69248. return fallbackFont;
  69249. }
  69250. void Font::setFallbackFontName (const String& name) throw()
  69251. {
  69252. fallbackFont = name;
  69253. }
  69254. void Font::setHeight (float newHeight) throw()
  69255. {
  69256. newHeight = jlimit (minFontHeight, maxFontHeight, newHeight);
  69257. if (font->height != newHeight)
  69258. {
  69259. dupeInternalIfShared();
  69260. font->height = newHeight;
  69261. }
  69262. }
  69263. void Font::setHeightWithoutChangingWidth (float newHeight) throw()
  69264. {
  69265. newHeight = jlimit (minFontHeight, maxFontHeight, newHeight);
  69266. if (font->height != newHeight)
  69267. {
  69268. dupeInternalIfShared();
  69269. font->horizontalScale *= (font->height / newHeight);
  69270. font->height = newHeight;
  69271. }
  69272. }
  69273. void Font::setStyleFlags (const int newFlags) throw()
  69274. {
  69275. if (font->styleFlags != newFlags)
  69276. {
  69277. dupeInternalIfShared();
  69278. font->styleFlags = newFlags;
  69279. font->typeface = 0;
  69280. font->ascent = 0;
  69281. }
  69282. }
  69283. void Font::setSizeAndStyle (float newHeight,
  69284. const int newStyleFlags,
  69285. const float newHorizontalScale,
  69286. const float newKerningAmount) throw()
  69287. {
  69288. newHeight = jlimit (minFontHeight, maxFontHeight, newHeight);
  69289. if (font->height != newHeight
  69290. || font->horizontalScale != newHorizontalScale
  69291. || font->kerning != newKerningAmount)
  69292. {
  69293. dupeInternalIfShared();
  69294. font->height = newHeight;
  69295. font->horizontalScale = newHorizontalScale;
  69296. font->kerning = newKerningAmount;
  69297. }
  69298. setStyleFlags (newStyleFlags);
  69299. }
  69300. void Font::setHorizontalScale (const float scaleFactor) throw()
  69301. {
  69302. dupeInternalIfShared();
  69303. font->horizontalScale = scaleFactor;
  69304. }
  69305. void Font::setExtraKerningFactor (const float extraKerning) throw()
  69306. {
  69307. dupeInternalIfShared();
  69308. font->kerning = extraKerning;
  69309. }
  69310. void Font::setBold (const bool shouldBeBold) throw()
  69311. {
  69312. setStyleFlags (shouldBeBold ? (font->styleFlags | bold)
  69313. : (font->styleFlags & ~bold));
  69314. }
  69315. bool Font::isBold() const throw()
  69316. {
  69317. return (font->styleFlags & bold) != 0;
  69318. }
  69319. void Font::setItalic (const bool shouldBeItalic) throw()
  69320. {
  69321. setStyleFlags (shouldBeItalic ? (font->styleFlags | italic)
  69322. : (font->styleFlags & ~italic));
  69323. }
  69324. bool Font::isItalic() const throw()
  69325. {
  69326. return (font->styleFlags & italic) != 0;
  69327. }
  69328. void Font::setUnderline (const bool shouldBeUnderlined) throw()
  69329. {
  69330. setStyleFlags (shouldBeUnderlined ? (font->styleFlags | underlined)
  69331. : (font->styleFlags & ~underlined));
  69332. }
  69333. bool Font::isUnderlined() const throw()
  69334. {
  69335. return (font->styleFlags & underlined) != 0;
  69336. }
  69337. float Font::getAscent() const throw()
  69338. {
  69339. if (font->ascent == 0)
  69340. font->ascent = getTypeface()->getAscent();
  69341. return font->height * font->ascent;
  69342. }
  69343. float Font::getDescent() const throw()
  69344. {
  69345. return font->height - getAscent();
  69346. }
  69347. int Font::getStringWidth (const String& text) const throw()
  69348. {
  69349. return roundToInt (getStringWidthFloat (text));
  69350. }
  69351. float Font::getStringWidthFloat (const String& text) const throw()
  69352. {
  69353. float w = getTypeface()->getStringWidth (text);
  69354. if (font->kerning != 0)
  69355. w += font->kerning * text.length();
  69356. return w * font->height * font->horizontalScale;
  69357. }
  69358. void Font::getGlyphPositions (const String& text, Array <int>& glyphs, Array <float>& xOffsets) const throw()
  69359. {
  69360. getTypeface()->getGlyphPositions (text, glyphs, xOffsets);
  69361. const float scale = font->height * font->horizontalScale;
  69362. const int num = xOffsets.size();
  69363. if (num > 0)
  69364. {
  69365. float* const x = &(xOffsets.getReference(0));
  69366. if (font->kerning != 0)
  69367. {
  69368. for (int i = 0; i < num; ++i)
  69369. x[i] = (x[i] + i * font->kerning) * scale;
  69370. }
  69371. else
  69372. {
  69373. for (int i = 0; i < num; ++i)
  69374. x[i] *= scale;
  69375. }
  69376. }
  69377. }
  69378. void Font::findFonts (Array<Font>& destArray) throw()
  69379. {
  69380. const StringArray names (findAllTypefaceNames());
  69381. for (int i = 0; i < names.size(); ++i)
  69382. destArray.add (Font (names[i], defaultFontHeight, Font::plain));
  69383. }
  69384. class TypefaceCache : public DeletedAtShutdown
  69385. {
  69386. public:
  69387. TypefaceCache (int numToCache = 10) throw()
  69388. : counter (1)
  69389. {
  69390. while (--numToCache >= 0)
  69391. faces.add (new CachedFace());
  69392. }
  69393. ~TypefaceCache()
  69394. {
  69395. clearUpDefaultFontNames();
  69396. clearSingletonInstance();
  69397. }
  69398. juce_DeclareSingleton_SingleThreaded_Minimal (TypefaceCache)
  69399. const Typeface::Ptr findTypefaceFor (const Font& font) throw()
  69400. {
  69401. const int flags = font.getStyleFlags() & (Font::bold | Font::italic);
  69402. const String faceName (font.getTypefaceName());
  69403. int i;
  69404. for (i = faces.size(); --i >= 0;)
  69405. {
  69406. CachedFace* const face = faces.getUnchecked(i);
  69407. if (face->flags == flags
  69408. && face->typefaceName == faceName)
  69409. {
  69410. face->lastUsageCount = ++counter;
  69411. return face->typeFace;
  69412. }
  69413. }
  69414. int replaceIndex = 0;
  69415. int bestLastUsageCount = std::numeric_limits<int>::max();
  69416. for (i = faces.size(); --i >= 0;)
  69417. {
  69418. const int lu = faces.getUnchecked(i)->lastUsageCount;
  69419. if (bestLastUsageCount > lu)
  69420. {
  69421. bestLastUsageCount = lu;
  69422. replaceIndex = i;
  69423. }
  69424. }
  69425. CachedFace* const face = faces.getUnchecked (replaceIndex);
  69426. face->typefaceName = faceName;
  69427. face->flags = flags;
  69428. face->lastUsageCount = ++counter;
  69429. face->typeFace = LookAndFeel::getDefaultLookAndFeel().getTypefaceForFont (font);
  69430. jassert (face->typeFace != 0); // the look and feel must return a typeface!
  69431. return face->typeFace;
  69432. }
  69433. juce_UseDebuggingNewOperator
  69434. private:
  69435. struct CachedFace
  69436. {
  69437. CachedFace() throw()
  69438. : lastUsageCount (0), flags (-1)
  69439. {
  69440. }
  69441. String typefaceName;
  69442. int lastUsageCount;
  69443. int flags;
  69444. Typeface::Ptr typeFace;
  69445. };
  69446. int counter;
  69447. OwnedArray <CachedFace> faces;
  69448. TypefaceCache (const TypefaceCache&);
  69449. const TypefaceCache& operator= (const TypefaceCache&);
  69450. };
  69451. juce_ImplementSingleton_SingleThreaded (TypefaceCache)
  69452. Typeface* Font::getTypeface() const throw()
  69453. {
  69454. if (font->typeface == 0)
  69455. font->typeface = TypefaceCache::getInstance()->findTypefaceFor (*this);
  69456. return font->typeface;
  69457. }
  69458. END_JUCE_NAMESPACE
  69459. /*** End of inlined file: juce_Font.cpp ***/
  69460. /*** Start of inlined file: juce_GlyphArrangement.cpp ***/
  69461. BEGIN_JUCE_NAMESPACE
  69462. PositionedGlyph::PositionedGlyph()
  69463. {
  69464. }
  69465. void PositionedGlyph::draw (const Graphics& g) const
  69466. {
  69467. if (! isWhitespace())
  69468. {
  69469. g.getInternalContext()->setFont (font);
  69470. g.getInternalContext()->drawGlyph (glyph, AffineTransform::translation (x, y));
  69471. }
  69472. }
  69473. void PositionedGlyph::draw (const Graphics& g,
  69474. const AffineTransform& transform) const
  69475. {
  69476. if (! isWhitespace())
  69477. {
  69478. g.getInternalContext()->setFont (font);
  69479. g.getInternalContext()->drawGlyph (glyph, AffineTransform::translation (x, y)
  69480. .followedBy (transform));
  69481. }
  69482. }
  69483. void PositionedGlyph::createPath (Path& path) const
  69484. {
  69485. if (! isWhitespace())
  69486. {
  69487. Typeface* const t = font.getTypeface();
  69488. if (t != 0)
  69489. {
  69490. Path p;
  69491. t->getOutlineForGlyph (glyph, p);
  69492. path.addPath (p, AffineTransform::scale (font.getHeight() * font.getHorizontalScale(), font.getHeight())
  69493. .translated (x, y));
  69494. }
  69495. }
  69496. }
  69497. bool PositionedGlyph::hitTest (float px, float py) const
  69498. {
  69499. if (px >= getLeft() && px < getRight()
  69500. && py >= getTop() && py < getBottom()
  69501. && ! isWhitespace())
  69502. {
  69503. Typeface* const t = font.getTypeface();
  69504. if (t != 0)
  69505. {
  69506. Path p;
  69507. t->getOutlineForGlyph (glyph, p);
  69508. AffineTransform::translation (-x, -y)
  69509. .scaled (1.0f / (font.getHeight() * font.getHorizontalScale()), 1.0f / font.getHeight())
  69510. .transformPoint (px, py);
  69511. return p.contains (px, py);
  69512. }
  69513. }
  69514. return false;
  69515. }
  69516. void PositionedGlyph::moveBy (const float deltaX,
  69517. const float deltaY)
  69518. {
  69519. x += deltaX;
  69520. y += deltaY;
  69521. }
  69522. GlyphArrangement::GlyphArrangement()
  69523. {
  69524. glyphs.ensureStorageAllocated (128);
  69525. }
  69526. GlyphArrangement::GlyphArrangement (const GlyphArrangement& other)
  69527. {
  69528. addGlyphArrangement (other);
  69529. }
  69530. const GlyphArrangement& GlyphArrangement::operator= (const GlyphArrangement& other)
  69531. {
  69532. if (this != &other)
  69533. {
  69534. clear();
  69535. addGlyphArrangement (other);
  69536. }
  69537. return *this;
  69538. }
  69539. GlyphArrangement::~GlyphArrangement()
  69540. {
  69541. }
  69542. void GlyphArrangement::clear()
  69543. {
  69544. glyphs.clear();
  69545. }
  69546. PositionedGlyph& GlyphArrangement::getGlyph (const int index) const
  69547. {
  69548. jassert (((unsigned int) index) < (unsigned int) glyphs.size());
  69549. return *glyphs [index];
  69550. }
  69551. void GlyphArrangement::addGlyphArrangement (const GlyphArrangement& other)
  69552. {
  69553. glyphs.ensureStorageAllocated (glyphs.size() + other.glyphs.size());
  69554. for (int i = 0; i < other.glyphs.size(); ++i)
  69555. glyphs.add (new PositionedGlyph (*other.glyphs.getUnchecked (i)));
  69556. }
  69557. void GlyphArrangement::removeRangeOfGlyphs (int startIndex, const int num)
  69558. {
  69559. glyphs.removeRange (startIndex, num < 0 ? glyphs.size() : num);
  69560. }
  69561. void GlyphArrangement::addLineOfText (const Font& font,
  69562. const String& text,
  69563. const float xOffset,
  69564. const float yOffset)
  69565. {
  69566. addCurtailedLineOfText (font, text,
  69567. xOffset, yOffset,
  69568. 1.0e10f, false);
  69569. }
  69570. void GlyphArrangement::addCurtailedLineOfText (const Font& font,
  69571. const String& text,
  69572. float xOffset,
  69573. const float yOffset,
  69574. const float maxWidthPixels,
  69575. const bool useEllipsis)
  69576. {
  69577. int textLen = text.length();
  69578. if (textLen > 0)
  69579. {
  69580. Array <int> newGlyphs;
  69581. Array <float> xOffsets;
  69582. font.getGlyphPositions (text, newGlyphs, xOffsets);
  69583. const juce_wchar* const unicodeText = (const juce_wchar*) text;
  69584. textLen = jmin (textLen, newGlyphs.size());
  69585. for (int i = 0; i < textLen; ++i)
  69586. {
  69587. const float thisX = xOffsets.getUnchecked (i);
  69588. const float nextX = xOffsets.getUnchecked (i + 1);
  69589. if (nextX > maxWidthPixels + 1.0f)
  69590. {
  69591. // curtail the string if it's too wide..
  69592. if (useEllipsis && textLen > 3 && glyphs.size() >= 3)
  69593. insertEllipsis (font, xOffset + maxWidthPixels, 0, glyphs.size());
  69594. break;
  69595. }
  69596. else
  69597. {
  69598. PositionedGlyph* const pg = new PositionedGlyph();
  69599. pg->x = xOffset + thisX;
  69600. pg->y = yOffset;
  69601. pg->w = nextX - thisX;
  69602. pg->font = font;
  69603. pg->glyph = newGlyphs.getUnchecked(i);
  69604. pg->character = unicodeText[i];
  69605. glyphs.add (pg);
  69606. }
  69607. }
  69608. }
  69609. }
  69610. int GlyphArrangement::insertEllipsis (const Font& font, const float maxXPos,
  69611. const int startIndex, int endIndex)
  69612. {
  69613. int numDeleted = 0;
  69614. if (glyphs.size() > 0)
  69615. {
  69616. Array<int> dotGlyphs;
  69617. Array<float> dotXs;
  69618. font.getGlyphPositions (T(".."), dotGlyphs, dotXs);
  69619. const float dx = dotXs[1];
  69620. float xOffset = 0.0f, yOffset = 0.0f;
  69621. while (endIndex > startIndex)
  69622. {
  69623. const PositionedGlyph* pg = glyphs.getUnchecked (--endIndex);
  69624. xOffset = pg->x;
  69625. yOffset = pg->y;
  69626. glyphs.remove (endIndex);
  69627. ++numDeleted;
  69628. if (xOffset + dx * 3 <= maxXPos)
  69629. break;
  69630. }
  69631. for (int i = 3; --i >= 0;)
  69632. {
  69633. PositionedGlyph* const pg = new PositionedGlyph();
  69634. pg->x = xOffset;
  69635. pg->y = yOffset;
  69636. pg->w = dx;
  69637. pg->font = font;
  69638. pg->character = '.';
  69639. pg->glyph = dotGlyphs.getFirst();
  69640. glyphs.insert (endIndex++, pg);
  69641. --numDeleted;
  69642. xOffset += dx;
  69643. if (xOffset > maxXPos)
  69644. break;
  69645. }
  69646. }
  69647. return numDeleted;
  69648. }
  69649. void GlyphArrangement::addJustifiedText (const Font& font,
  69650. const String& text,
  69651. float x, float y,
  69652. const float maxLineWidth,
  69653. const Justification& horizontalLayout)
  69654. {
  69655. int lineStartIndex = glyphs.size();
  69656. addLineOfText (font, text, x, y);
  69657. const float originalY = y;
  69658. while (lineStartIndex < glyphs.size())
  69659. {
  69660. int i = lineStartIndex;
  69661. if (glyphs.getUnchecked(i)->getCharacter() != T('\n')
  69662. && glyphs.getUnchecked(i)->getCharacter() != T('\r'))
  69663. ++i;
  69664. const float lineMaxX = glyphs.getUnchecked (lineStartIndex)->getLeft() + maxLineWidth;
  69665. int lastWordBreakIndex = -1;
  69666. while (i < glyphs.size())
  69667. {
  69668. const PositionedGlyph* pg = glyphs.getUnchecked (i);
  69669. const juce_wchar c = pg->getCharacter();
  69670. if (c == T('\r') || c == T('\n'))
  69671. {
  69672. ++i;
  69673. if (c == T('\r') && i < glyphs.size()
  69674. && glyphs.getUnchecked(i)->getCharacter() == T('\n'))
  69675. ++i;
  69676. break;
  69677. }
  69678. else if (pg->isWhitespace())
  69679. {
  69680. lastWordBreakIndex = i + 1;
  69681. }
  69682. else if (pg->getRight() - 0.0001f >= lineMaxX)
  69683. {
  69684. if (lastWordBreakIndex >= 0)
  69685. i = lastWordBreakIndex;
  69686. break;
  69687. }
  69688. ++i;
  69689. }
  69690. const float currentLineStartX = glyphs.getUnchecked (lineStartIndex)->getLeft();
  69691. float currentLineEndX = currentLineStartX;
  69692. for (int j = i; --j >= lineStartIndex;)
  69693. {
  69694. if (! glyphs.getUnchecked (j)->isWhitespace())
  69695. {
  69696. currentLineEndX = glyphs.getUnchecked (j)->getRight();
  69697. break;
  69698. }
  69699. }
  69700. float deltaX = 0.0f;
  69701. if (horizontalLayout.testFlags (Justification::horizontallyJustified))
  69702. spreadOutLine (lineStartIndex, i - lineStartIndex, maxLineWidth);
  69703. else if (horizontalLayout.testFlags (Justification::horizontallyCentred))
  69704. deltaX = (maxLineWidth - (currentLineEndX - currentLineStartX)) * 0.5f;
  69705. else if (horizontalLayout.testFlags (Justification::right))
  69706. deltaX = maxLineWidth - (currentLineEndX - currentLineStartX);
  69707. moveRangeOfGlyphs (lineStartIndex, i - lineStartIndex,
  69708. x + deltaX - currentLineStartX, y - originalY);
  69709. lineStartIndex = i;
  69710. y += font.getHeight();
  69711. }
  69712. }
  69713. void GlyphArrangement::addFittedText (const Font& f,
  69714. const String& text,
  69715. const float x, const float y,
  69716. const float width, const float height,
  69717. const Justification& layout,
  69718. int maximumLines,
  69719. const float minimumHorizontalScale)
  69720. {
  69721. // doesn't make much sense if this is outside a sensible range of 0.5 to 1.0
  69722. jassert (minimumHorizontalScale > 0 && minimumHorizontalScale <= 1.0f);
  69723. if (text.containsAnyOf (T("\r\n")))
  69724. {
  69725. GlyphArrangement ga;
  69726. ga.addJustifiedText (f, text, x, y, width, layout);
  69727. float l, t, r, b;
  69728. ga.getBoundingBox (0, -1, l, t, r, b, false);
  69729. float dy = y - t;
  69730. if (layout.testFlags (Justification::verticallyCentred))
  69731. dy += (height - (b - t)) * 0.5f;
  69732. else if (layout.testFlags (Justification::bottom))
  69733. dy += height - (b - t);
  69734. ga.moveRangeOfGlyphs (0, -1, 0.0f, dy);
  69735. glyphs.ensureStorageAllocated (glyphs.size() + ga.glyphs.size());
  69736. for (int i = 0; i < ga.glyphs.size(); ++i)
  69737. glyphs.add (ga.glyphs.getUnchecked (i));
  69738. ga.glyphs.clear (false);
  69739. return;
  69740. }
  69741. int startIndex = glyphs.size();
  69742. addLineOfText (f, text.trim(), x, y);
  69743. if (glyphs.size() > startIndex)
  69744. {
  69745. float lineWidth = glyphs.getUnchecked (glyphs.size() - 1)->getRight()
  69746. - glyphs.getUnchecked (startIndex)->getLeft();
  69747. if (lineWidth <= 0)
  69748. return;
  69749. if (lineWidth * minimumHorizontalScale < width)
  69750. {
  69751. if (lineWidth > width)
  69752. stretchRangeOfGlyphs (startIndex, glyphs.size() - startIndex,
  69753. width / lineWidth);
  69754. justifyGlyphs (startIndex, glyphs.size() - startIndex,
  69755. x, y, width, height, layout);
  69756. }
  69757. else if (maximumLines <= 1)
  69758. {
  69759. fitLineIntoSpace (startIndex, glyphs.size() - startIndex,
  69760. x, y, width, height, f, layout, minimumHorizontalScale);
  69761. }
  69762. else
  69763. {
  69764. Font font (f);
  69765. String txt (text.trim());
  69766. const int length = txt.length();
  69767. const int originalStartIndex = startIndex;
  69768. int numLines = 1;
  69769. if (length <= 12 && ! txt.containsAnyOf (T(" -\t\r\n")))
  69770. maximumLines = 1;
  69771. maximumLines = jmin (maximumLines, length);
  69772. while (numLines < maximumLines)
  69773. {
  69774. ++numLines;
  69775. const float newFontHeight = height / (float) numLines;
  69776. if (newFontHeight < font.getHeight())
  69777. {
  69778. font.setHeight (jmax (8.0f, newFontHeight));
  69779. removeRangeOfGlyphs (startIndex, -1);
  69780. addLineOfText (font, txt, x, y);
  69781. lineWidth = glyphs.getUnchecked (glyphs.size() - 1)->getRight()
  69782. - glyphs.getUnchecked (startIndex)->getLeft();
  69783. }
  69784. if (numLines > lineWidth / width || newFontHeight < 8.0f)
  69785. break;
  69786. }
  69787. if (numLines < 1)
  69788. numLines = 1;
  69789. float lineY = y;
  69790. float widthPerLine = lineWidth / numLines;
  69791. int lastLineStartIndex = 0;
  69792. for (int line = 0; line < numLines; ++line)
  69793. {
  69794. int i = startIndex;
  69795. lastLineStartIndex = i;
  69796. float lineStartX = glyphs.getUnchecked (startIndex)->getLeft();
  69797. if (line == numLines - 1)
  69798. {
  69799. widthPerLine = width;
  69800. i = glyphs.size();
  69801. }
  69802. else
  69803. {
  69804. while (i < glyphs.size())
  69805. {
  69806. lineWidth = (glyphs.getUnchecked (i)->getRight() - lineStartX);
  69807. if (lineWidth > widthPerLine)
  69808. {
  69809. // got to a point where the line's too long, so skip forward to find a
  69810. // good place to break it..
  69811. const int searchStartIndex = i;
  69812. while (i < glyphs.size())
  69813. {
  69814. if ((glyphs.getUnchecked (i)->getRight() - lineStartX) * minimumHorizontalScale < width)
  69815. {
  69816. if (glyphs.getUnchecked (i)->isWhitespace()
  69817. || glyphs.getUnchecked (i)->getCharacter() == T('-'))
  69818. {
  69819. ++i;
  69820. break;
  69821. }
  69822. }
  69823. else
  69824. {
  69825. // can't find a suitable break, so try looking backwards..
  69826. i = searchStartIndex;
  69827. for (int back = 1; back < jmin (5, i - startIndex - 1); ++back)
  69828. {
  69829. if (glyphs.getUnchecked (i - back)->isWhitespace()
  69830. || glyphs.getUnchecked (i - back)->getCharacter() == T('-'))
  69831. {
  69832. i -= back - 1;
  69833. break;
  69834. }
  69835. }
  69836. break;
  69837. }
  69838. ++i;
  69839. }
  69840. break;
  69841. }
  69842. ++i;
  69843. }
  69844. int wsStart = i;
  69845. while (wsStart > 0 && glyphs.getUnchecked (wsStart - 1)->isWhitespace())
  69846. --wsStart;
  69847. int wsEnd = i;
  69848. while (wsEnd < glyphs.size() && glyphs.getUnchecked (wsEnd)->isWhitespace())
  69849. ++wsEnd;
  69850. removeRangeOfGlyphs (wsStart, wsEnd - wsStart);
  69851. i = jmax (wsStart, startIndex + 1);
  69852. }
  69853. i -= fitLineIntoSpace (startIndex, i - startIndex,
  69854. x, lineY, width, font.getHeight(), font,
  69855. layout.getOnlyHorizontalFlags() | Justification::verticallyCentred,
  69856. minimumHorizontalScale);
  69857. startIndex = i;
  69858. lineY += font.getHeight();
  69859. if (startIndex >= glyphs.size())
  69860. break;
  69861. }
  69862. justifyGlyphs (originalStartIndex, glyphs.size() - originalStartIndex,
  69863. x, y, width, height, layout.getFlags() & ~Justification::horizontallyJustified);
  69864. }
  69865. }
  69866. }
  69867. void GlyphArrangement::moveRangeOfGlyphs (int startIndex, int num,
  69868. const float dx, const float dy)
  69869. {
  69870. jassert (startIndex >= 0);
  69871. if (dx != 0.0f || dy != 0.0f)
  69872. {
  69873. if (num < 0 || startIndex + num > glyphs.size())
  69874. num = glyphs.size() - startIndex;
  69875. while (--num >= 0)
  69876. glyphs.getUnchecked (startIndex++)->moveBy (dx, dy);
  69877. }
  69878. }
  69879. int GlyphArrangement::fitLineIntoSpace (int start, int numGlyphs, float x, float y, float w, float h, const Font& font,
  69880. const Justification& justification, float minimumHorizontalScale)
  69881. {
  69882. int numDeleted = 0;
  69883. const float lineStartX = glyphs.getUnchecked (start)->getLeft();
  69884. float lineWidth = glyphs.getUnchecked (start + numGlyphs - 1)->getRight() - lineStartX;
  69885. if (lineWidth > w)
  69886. {
  69887. if (minimumHorizontalScale < 1.0f)
  69888. {
  69889. stretchRangeOfGlyphs (start, numGlyphs, jmax (minimumHorizontalScale, w / lineWidth));
  69890. lineWidth = glyphs.getUnchecked (start + numGlyphs - 1)->getRight() - lineStartX - 0.5f;
  69891. }
  69892. if (lineWidth > w)
  69893. {
  69894. numDeleted = insertEllipsis (font, lineStartX + w, start, start + numGlyphs);
  69895. numGlyphs -= numDeleted;
  69896. }
  69897. }
  69898. justifyGlyphs (start, numGlyphs, x, y, w, h, justification);
  69899. return numDeleted;
  69900. }
  69901. void GlyphArrangement::stretchRangeOfGlyphs (int startIndex, int num,
  69902. const float horizontalScaleFactor)
  69903. {
  69904. jassert (startIndex >= 0);
  69905. if (num < 0 || startIndex + num > glyphs.size())
  69906. num = glyphs.size() - startIndex;
  69907. if (num > 0)
  69908. {
  69909. const float xAnchor = glyphs.getUnchecked (startIndex)->getLeft();
  69910. while (--num >= 0)
  69911. {
  69912. PositionedGlyph* const pg = glyphs.getUnchecked (startIndex++);
  69913. pg->x = xAnchor + (pg->x - xAnchor) * horizontalScaleFactor;
  69914. pg->font.setHorizontalScale (pg->font.getHorizontalScale() * horizontalScaleFactor);
  69915. pg->w *= horizontalScaleFactor;
  69916. }
  69917. }
  69918. }
  69919. void GlyphArrangement::getBoundingBox (int startIndex, int num,
  69920. float& left,
  69921. float& top,
  69922. float& right,
  69923. float& bottom,
  69924. const bool includeWhitespace) const
  69925. {
  69926. jassert (startIndex >= 0);
  69927. if (num < 0 || startIndex + num > glyphs.size())
  69928. num = glyphs.size() - startIndex;
  69929. left = 0.0f;
  69930. top = 0.0f;
  69931. right = 0.0f;
  69932. bottom = 0.0f;
  69933. bool isFirst = true;
  69934. while (--num >= 0)
  69935. {
  69936. const PositionedGlyph* const pg = glyphs.getUnchecked (startIndex++);
  69937. if (includeWhitespace || ! pg->isWhitespace())
  69938. {
  69939. if (isFirst)
  69940. {
  69941. isFirst = false;
  69942. left = pg->getLeft();
  69943. top = pg->getTop();
  69944. right = pg->getRight();
  69945. bottom = pg->getBottom();
  69946. }
  69947. else
  69948. {
  69949. left = jmin (left, pg->getLeft());
  69950. top = jmin (top, pg->getTop());
  69951. right = jmax (right, pg->getRight());
  69952. bottom = jmax (bottom, pg->getBottom());
  69953. }
  69954. }
  69955. }
  69956. }
  69957. void GlyphArrangement::justifyGlyphs (const int startIndex,
  69958. const int num,
  69959. const float x, const float y,
  69960. const float width, const float height,
  69961. const Justification& justification)
  69962. {
  69963. jassert (num >= 0 && startIndex >= 0);
  69964. if (glyphs.size() > 0 && num > 0)
  69965. {
  69966. float left, top, right, bottom;
  69967. getBoundingBox (startIndex, num, left, top, right, bottom,
  69968. ! justification.testFlags (Justification::horizontallyJustified
  69969. | Justification::horizontallyCentred));
  69970. float deltaX = 0.0f;
  69971. if (justification.testFlags (Justification::horizontallyJustified))
  69972. deltaX = x - left;
  69973. else if (justification.testFlags (Justification::horizontallyCentred))
  69974. deltaX = x + (width - (right - left)) * 0.5f - left;
  69975. else if (justification.testFlags (Justification::right))
  69976. deltaX = (x + width) - right;
  69977. else
  69978. deltaX = x - left;
  69979. float deltaY = 0.0f;
  69980. if (justification.testFlags (Justification::top))
  69981. deltaY = y - top;
  69982. else if (justification.testFlags (Justification::bottom))
  69983. deltaY = (y + height) - bottom;
  69984. else
  69985. deltaY = y + (height - (bottom - top)) * 0.5f - top;
  69986. moveRangeOfGlyphs (startIndex, num, deltaX, deltaY);
  69987. if (justification.testFlags (Justification::horizontallyJustified))
  69988. {
  69989. int lineStart = 0;
  69990. float baseY = glyphs.getUnchecked (startIndex)->getBaselineY();
  69991. int i;
  69992. for (i = 0; i < num; ++i)
  69993. {
  69994. const float glyphY = glyphs.getUnchecked (startIndex + i)->getBaselineY();
  69995. if (glyphY != baseY)
  69996. {
  69997. spreadOutLine (startIndex + lineStart, i - lineStart, width);
  69998. lineStart = i;
  69999. baseY = glyphY;
  70000. }
  70001. }
  70002. if (i > lineStart)
  70003. spreadOutLine (startIndex + lineStart, i - lineStart, width);
  70004. }
  70005. }
  70006. }
  70007. void GlyphArrangement::spreadOutLine (const int start, const int num, const float targetWidth)
  70008. {
  70009. if (start + num < glyphs.size()
  70010. && glyphs.getUnchecked (start + num - 1)->getCharacter() != T('\r')
  70011. && glyphs.getUnchecked (start + num - 1)->getCharacter() != T('\n'))
  70012. {
  70013. int numSpaces = 0;
  70014. int spacesAtEnd = 0;
  70015. for (int i = 0; i < num; ++i)
  70016. {
  70017. if (glyphs.getUnchecked (start + i)->isWhitespace())
  70018. {
  70019. ++spacesAtEnd;
  70020. ++numSpaces;
  70021. }
  70022. else
  70023. {
  70024. spacesAtEnd = 0;
  70025. }
  70026. }
  70027. numSpaces -= spacesAtEnd;
  70028. if (numSpaces > 0)
  70029. {
  70030. const float startX = glyphs.getUnchecked (start)->getLeft();
  70031. const float endX = glyphs.getUnchecked (start + num - 1 - spacesAtEnd)->getRight();
  70032. const float extraPaddingBetweenWords
  70033. = (targetWidth - (endX - startX)) / (float) numSpaces;
  70034. float deltaX = 0.0f;
  70035. for (int i = 0; i < num; ++i)
  70036. {
  70037. glyphs.getUnchecked (start + i)->moveBy (deltaX, 0.0f);
  70038. if (glyphs.getUnchecked (start + i)->isWhitespace())
  70039. deltaX += extraPaddingBetweenWords;
  70040. }
  70041. }
  70042. }
  70043. }
  70044. void GlyphArrangement::draw (const Graphics& g) const
  70045. {
  70046. for (int i = 0; i < glyphs.size(); ++i)
  70047. {
  70048. const PositionedGlyph* const pg = glyphs.getUnchecked(i);
  70049. if (pg->font.isUnderlined())
  70050. {
  70051. const float lineThickness = (pg->font.getDescent()) * 0.3f;
  70052. float nextX = pg->x + pg->w;
  70053. if (i < glyphs.size() - 1 && glyphs.getUnchecked (i + 1)->y == pg->y)
  70054. nextX = glyphs.getUnchecked (i + 1)->x;
  70055. g.fillRect (pg->x, pg->y + lineThickness * 2.0f,
  70056. nextX - pg->x, lineThickness);
  70057. }
  70058. pg->draw (g);
  70059. }
  70060. }
  70061. void GlyphArrangement::draw (const Graphics& g, const AffineTransform& transform) const
  70062. {
  70063. for (int i = 0; i < glyphs.size(); ++i)
  70064. {
  70065. const PositionedGlyph* const pg = glyphs.getUnchecked(i);
  70066. if (pg->font.isUnderlined())
  70067. {
  70068. const float lineThickness = (pg->font.getDescent()) * 0.3f;
  70069. float nextX = pg->x + pg->w;
  70070. if (i < glyphs.size() - 1 && glyphs.getUnchecked (i + 1)->y == pg->y)
  70071. nextX = glyphs.getUnchecked (i + 1)->x;
  70072. Path p;
  70073. p.addLineSegment (pg->x, pg->y + lineThickness * 2.0f,
  70074. nextX, pg->y + lineThickness * 2.0f,
  70075. lineThickness);
  70076. g.fillPath (p, transform);
  70077. }
  70078. pg->draw (g, transform);
  70079. }
  70080. }
  70081. void GlyphArrangement::createPath (Path& path) const
  70082. {
  70083. for (int i = 0; i < glyphs.size(); ++i)
  70084. glyphs.getUnchecked (i)->createPath (path);
  70085. }
  70086. int GlyphArrangement::findGlyphIndexAt (float x, float y) const
  70087. {
  70088. for (int i = 0; i < glyphs.size(); ++i)
  70089. if (glyphs.getUnchecked (i)->hitTest (x, y))
  70090. return i;
  70091. return -1;
  70092. }
  70093. END_JUCE_NAMESPACE
  70094. /*** End of inlined file: juce_GlyphArrangement.cpp ***/
  70095. /*** Start of inlined file: juce_TextLayout.cpp ***/
  70096. BEGIN_JUCE_NAMESPACE
  70097. class TextLayout::Token
  70098. {
  70099. public:
  70100. String text;
  70101. Font font;
  70102. int x, y, w, h;
  70103. int line, lineHeight;
  70104. bool isWhitespace, isNewLine;
  70105. Token (const String& t,
  70106. const Font& f,
  70107. const bool isWhitespace_) throw()
  70108. : text (t),
  70109. font (f),
  70110. x(0),
  70111. y(0),
  70112. isWhitespace (isWhitespace_)
  70113. {
  70114. w = font.getStringWidth (t);
  70115. h = roundToInt (f.getHeight());
  70116. isNewLine = t.containsAnyOf (T("\r\n"));
  70117. }
  70118. Token (const Token& other) throw()
  70119. : text (other.text),
  70120. font (other.font),
  70121. x (other.x),
  70122. y (other.y),
  70123. w (other.w),
  70124. h (other.h),
  70125. line (other.line),
  70126. lineHeight (other.lineHeight),
  70127. isWhitespace (other.isWhitespace),
  70128. isNewLine (other.isNewLine)
  70129. {
  70130. }
  70131. ~Token() throw()
  70132. {
  70133. }
  70134. void draw (Graphics& g,
  70135. const int xOffset,
  70136. const int yOffset) throw()
  70137. {
  70138. if (! isWhitespace)
  70139. {
  70140. g.setFont (font);
  70141. g.drawSingleLineText (text.trimEnd(),
  70142. xOffset + x,
  70143. yOffset + y + (lineHeight - h)
  70144. + roundToInt (font.getAscent()));
  70145. }
  70146. }
  70147. juce_UseDebuggingNewOperator
  70148. };
  70149. TextLayout::TextLayout() throw()
  70150. : totalLines (0)
  70151. {
  70152. tokens.ensureStorageAllocated (64);
  70153. }
  70154. TextLayout::TextLayout (const String& text,
  70155. const Font& font) throw()
  70156. : totalLines (0)
  70157. {
  70158. tokens.ensureStorageAllocated (64);
  70159. appendText (text, font);
  70160. }
  70161. TextLayout::TextLayout (const TextLayout& other) throw()
  70162. : totalLines (0)
  70163. {
  70164. *this = other;
  70165. }
  70166. const TextLayout& TextLayout::operator= (const TextLayout& other) throw()
  70167. {
  70168. if (this != &other)
  70169. {
  70170. clear();
  70171. totalLines = other.totalLines;
  70172. for (int i = 0; i < other.tokens.size(); ++i)
  70173. tokens.add (new Token (*other.tokens.getUnchecked(i)));
  70174. }
  70175. return *this;
  70176. }
  70177. TextLayout::~TextLayout() throw()
  70178. {
  70179. clear();
  70180. }
  70181. void TextLayout::clear() throw()
  70182. {
  70183. tokens.clear();
  70184. totalLines = 0;
  70185. }
  70186. void TextLayout::appendText (const String& text,
  70187. const Font& font) throw()
  70188. {
  70189. const tchar* t = text;
  70190. String currentString;
  70191. int lastCharType = 0;
  70192. for (;;)
  70193. {
  70194. const tchar c = *t++;
  70195. if (c == 0)
  70196. break;
  70197. int charType;
  70198. if (c == T('\r') || c == T('\n'))
  70199. {
  70200. charType = 0;
  70201. }
  70202. else if (CharacterFunctions::isWhitespace (c))
  70203. {
  70204. charType = 2;
  70205. }
  70206. else
  70207. {
  70208. charType = 1;
  70209. }
  70210. if (charType == 0 || charType != lastCharType)
  70211. {
  70212. if (currentString.isNotEmpty())
  70213. {
  70214. tokens.add (new Token (currentString, font,
  70215. lastCharType == 2 || lastCharType == 0));
  70216. }
  70217. currentString = String::charToString (c);
  70218. if (c == T('\r') && *t == T('\n'))
  70219. currentString += *t++;
  70220. }
  70221. else
  70222. {
  70223. currentString += c;
  70224. }
  70225. lastCharType = charType;
  70226. }
  70227. if (currentString.isNotEmpty())
  70228. tokens.add (new Token (currentString, font, lastCharType == 2));
  70229. }
  70230. void TextLayout::setText (const String& text, const Font& font) throw()
  70231. {
  70232. clear();
  70233. appendText (text, font);
  70234. }
  70235. void TextLayout::layout (int maxWidth,
  70236. const Justification& justification,
  70237. const bool attemptToBalanceLineLengths) throw()
  70238. {
  70239. if (attemptToBalanceLineLengths)
  70240. {
  70241. const int originalW = maxWidth;
  70242. int bestWidth = maxWidth;
  70243. float bestLineProportion = 0.0f;
  70244. while (maxWidth > originalW / 2)
  70245. {
  70246. layout (maxWidth, justification, false);
  70247. if (getNumLines() <= 1)
  70248. return;
  70249. const int lastLineW = getLineWidth (getNumLines() - 1);
  70250. const int lastButOneLineW = getLineWidth (getNumLines() - 2);
  70251. const float prop = lastLineW / (float) lastButOneLineW;
  70252. if (prop > 0.9f)
  70253. return;
  70254. if (prop > bestLineProportion)
  70255. {
  70256. bestLineProportion = prop;
  70257. bestWidth = maxWidth;
  70258. }
  70259. maxWidth -= 10;
  70260. }
  70261. layout (bestWidth, justification, false);
  70262. }
  70263. else
  70264. {
  70265. int x = 0;
  70266. int y = 0;
  70267. int h = 0;
  70268. totalLines = 0;
  70269. int i;
  70270. for (i = 0; i < tokens.size(); ++i)
  70271. {
  70272. Token* const t = tokens.getUnchecked(i);
  70273. t->x = x;
  70274. t->y = y;
  70275. t->line = totalLines;
  70276. x += t->w;
  70277. h = jmax (h, t->h);
  70278. const Token* nextTok = tokens [i + 1];
  70279. if (nextTok == 0)
  70280. break;
  70281. if (t->isNewLine || ((! nextTok->isWhitespace) && x + nextTok->w > maxWidth))
  70282. {
  70283. // finished a line, so go back and update the heights of the things on it
  70284. for (int j = i; j >= 0; --j)
  70285. {
  70286. Token* const tok = tokens.getUnchecked(j);
  70287. if (tok->line == totalLines)
  70288. tok->lineHeight = h;
  70289. else
  70290. break;
  70291. }
  70292. x = 0;
  70293. y += h;
  70294. h = 0;
  70295. ++totalLines;
  70296. }
  70297. }
  70298. // finished a line, so go back and update the heights of the things on it
  70299. for (int j = jmin (i, tokens.size() - 1); j >= 0; --j)
  70300. {
  70301. Token* const t = tokens.getUnchecked(j);
  70302. if (t->line == totalLines)
  70303. t->lineHeight = h;
  70304. else
  70305. break;
  70306. }
  70307. ++totalLines;
  70308. if (! justification.testFlags (Justification::left))
  70309. {
  70310. int totalW = getWidth();
  70311. for (i = totalLines; --i >= 0;)
  70312. {
  70313. const int lineW = getLineWidth (i);
  70314. int dx = 0;
  70315. if (justification.testFlags (Justification::horizontallyCentred))
  70316. dx = (totalW - lineW) / 2;
  70317. else if (justification.testFlags (Justification::right))
  70318. dx = totalW - lineW;
  70319. for (int j = tokens.size(); --j >= 0;)
  70320. {
  70321. Token* const t = tokens.getUnchecked(j);
  70322. if (t->line == i)
  70323. t->x += dx;
  70324. }
  70325. }
  70326. }
  70327. }
  70328. }
  70329. int TextLayout::getLineWidth (const int lineNumber) const throw()
  70330. {
  70331. int maxW = 0;
  70332. for (int i = tokens.size(); --i >= 0;)
  70333. {
  70334. const Token* const t = tokens.getUnchecked(i);
  70335. if (t->line == lineNumber && ! t->isWhitespace)
  70336. maxW = jmax (maxW, t->x + t->w);
  70337. }
  70338. return maxW;
  70339. }
  70340. int TextLayout::getWidth() const throw()
  70341. {
  70342. int maxW = 0;
  70343. for (int i = tokens.size(); --i >= 0;)
  70344. {
  70345. const Token* const t = tokens.getUnchecked(i);
  70346. if (! t->isWhitespace)
  70347. maxW = jmax (maxW, t->x + t->w);
  70348. }
  70349. return maxW;
  70350. }
  70351. int TextLayout::getHeight() const throw()
  70352. {
  70353. int maxH = 0;
  70354. for (int i = tokens.size(); --i >= 0;)
  70355. {
  70356. const Token* const t = tokens.getUnchecked(i);
  70357. if (! t->isWhitespace)
  70358. maxH = jmax (maxH, t->y + t->h);
  70359. }
  70360. return maxH;
  70361. }
  70362. void TextLayout::draw (Graphics& g,
  70363. const int xOffset,
  70364. const int yOffset) const throw()
  70365. {
  70366. for (int i = tokens.size(); --i >= 0;)
  70367. tokens.getUnchecked(i)->draw (g, xOffset, yOffset);
  70368. }
  70369. void TextLayout::drawWithin (Graphics& g,
  70370. int x, int y, int w, int h,
  70371. const Justification& justification) const throw()
  70372. {
  70373. justification.applyToRectangle (x, y, getWidth(), getHeight(),
  70374. x, y, w, h);
  70375. draw (g, x, y);
  70376. }
  70377. END_JUCE_NAMESPACE
  70378. /*** End of inlined file: juce_TextLayout.cpp ***/
  70379. /*** Start of inlined file: juce_Typeface.cpp ***/
  70380. BEGIN_JUCE_NAMESPACE
  70381. Typeface::Typeface (const String& name_) throw()
  70382. : name (name_)
  70383. {
  70384. }
  70385. Typeface::~Typeface()
  70386. {
  70387. }
  70388. class CustomTypeface::GlyphInfo
  70389. {
  70390. public:
  70391. GlyphInfo (const juce_wchar character_, const Path& path_, const float width_) throw()
  70392. : character (character_), path (path_), width (width_)
  70393. {
  70394. }
  70395. ~GlyphInfo() throw()
  70396. {
  70397. }
  70398. struct KerningPair
  70399. {
  70400. juce_wchar character2;
  70401. float kerningAmount;
  70402. };
  70403. void addKerningPair (const juce_wchar subsequentCharacter,
  70404. const float extraKerningAmount) throw()
  70405. {
  70406. KerningPair kp;
  70407. kp.character2 = subsequentCharacter;
  70408. kp.kerningAmount = extraKerningAmount;
  70409. kerningPairs.add (kp);
  70410. }
  70411. float getHorizontalSpacing (const juce_wchar subsequentCharacter) const throw()
  70412. {
  70413. if (subsequentCharacter != 0)
  70414. {
  70415. for (int i = kerningPairs.size(); --i >= 0;)
  70416. if (kerningPairs.getReference(i).character2 == subsequentCharacter)
  70417. return width + kerningPairs.getReference(i).kerningAmount;
  70418. }
  70419. return width;
  70420. }
  70421. const juce_wchar character;
  70422. const Path path;
  70423. float width;
  70424. Array <KerningPair> kerningPairs;
  70425. juce_UseDebuggingNewOperator
  70426. private:
  70427. GlyphInfo (const GlyphInfo&);
  70428. const GlyphInfo& operator= (const GlyphInfo&);
  70429. };
  70430. CustomTypeface::CustomTypeface()
  70431. : Typeface (String::empty)
  70432. {
  70433. clear();
  70434. }
  70435. CustomTypeface::CustomTypeface (InputStream& serialisedTypefaceStream)
  70436. : Typeface (String::empty)
  70437. {
  70438. clear();
  70439. GZIPDecompressorInputStream gzin (&serialisedTypefaceStream, false);
  70440. BufferedInputStream in (&gzin, 32768, false);
  70441. name = in.readString();
  70442. isBold = in.readBool();
  70443. isItalic = in.readBool();
  70444. ascent = in.readFloat();
  70445. defaultCharacter = (juce_wchar) in.readShort();
  70446. int i, numChars = in.readInt();
  70447. for (i = 0; i < numChars; ++i)
  70448. {
  70449. const juce_wchar c = (juce_wchar) in.readShort();
  70450. const float width = in.readFloat();
  70451. Path p;
  70452. p.loadPathFromStream (in);
  70453. addGlyph (c, p, width);
  70454. }
  70455. const int numKerningPairs = in.readInt();
  70456. for (i = 0; i < numKerningPairs; ++i)
  70457. {
  70458. const juce_wchar char1 = (juce_wchar) in.readShort();
  70459. const juce_wchar char2 = (juce_wchar) in.readShort();
  70460. addKerningPair (char1, char2, in.readFloat());
  70461. }
  70462. }
  70463. CustomTypeface::~CustomTypeface()
  70464. {
  70465. }
  70466. void CustomTypeface::clear()
  70467. {
  70468. defaultCharacter = 0;
  70469. ascent = 1.0f;
  70470. isBold = isItalic = false;
  70471. zeromem (lookupTable, sizeof (lookupTable));
  70472. glyphs.clear();
  70473. }
  70474. void CustomTypeface::setCharacteristics (const String& name_, const float ascent_, const bool isBold_,
  70475. const bool isItalic_, const juce_wchar defaultCharacter_) throw()
  70476. {
  70477. name = name_;
  70478. defaultCharacter = defaultCharacter_;
  70479. ascent = ascent_;
  70480. isBold = isBold_;
  70481. isItalic = isItalic_;
  70482. }
  70483. void CustomTypeface::addGlyph (const juce_wchar character, const Path& path, const float width) throw()
  70484. {
  70485. // Check that you're not trying to add the same character twice..
  70486. jassert (findGlyph (character, false) == 0);
  70487. if (((unsigned int) character) < (unsigned int) numElementsInArray (lookupTable))
  70488. lookupTable [character] = (short) glyphs.size();
  70489. glyphs.add (new GlyphInfo (character, path, width));
  70490. }
  70491. void CustomTypeface::addKerningPair (const juce_wchar char1, const juce_wchar char2, const float extraAmount) throw()
  70492. {
  70493. if (extraAmount != 0)
  70494. {
  70495. GlyphInfo* const g = findGlyph (char1, true);
  70496. jassert (g != 0); // can only add kerning pairs for characters that exist!
  70497. if (g != 0)
  70498. g->addKerningPair (char2, extraAmount);
  70499. }
  70500. }
  70501. CustomTypeface::GlyphInfo* CustomTypeface::findGlyph (const juce_wchar character, const bool loadIfNeeded) throw()
  70502. {
  70503. if (((unsigned int) character) < (unsigned int) numElementsInArray (lookupTable) && lookupTable [character] > 0)
  70504. return glyphs [(int) lookupTable [(int) character]];
  70505. for (int i = 0; i < glyphs.size(); ++i)
  70506. {
  70507. GlyphInfo* const g = glyphs.getUnchecked(i);
  70508. if (g->character == character)
  70509. return g;
  70510. }
  70511. if (loadIfNeeded && loadGlyphIfPossible (character))
  70512. return findGlyph (character, false);
  70513. return 0;
  70514. }
  70515. CustomTypeface::GlyphInfo* CustomTypeface::findGlyphSubstituting (const juce_wchar character) throw()
  70516. {
  70517. GlyphInfo* glyph = findGlyph (character, true);
  70518. if (glyph == 0)
  70519. {
  70520. if (CharacterFunctions::isWhitespace (character) && character != L' ')
  70521. glyph = findGlyph (L' ', true);
  70522. if (glyph == 0)
  70523. {
  70524. const Font fallbackFont (Font::getFallbackFontName(), 10, 0);
  70525. Typeface* const fallbackTypeface = fallbackFont.getTypeface();
  70526. if (fallbackTypeface != 0 && fallbackTypeface != this)
  70527. {
  70528. //xxx
  70529. }
  70530. if (glyph == 0)
  70531. glyph = findGlyph (defaultCharacter, true);
  70532. }
  70533. }
  70534. return glyph;
  70535. }
  70536. bool CustomTypeface::loadGlyphIfPossible (const juce_wchar /*characterNeeded*/)
  70537. {
  70538. return false;
  70539. }
  70540. void CustomTypeface::addGlyphsFromOtherTypeface (Typeface& typefaceToCopy, juce_wchar characterStartIndex, int numCharacters) throw()
  70541. {
  70542. for (int i = 0; i < numCharacters; ++i)
  70543. {
  70544. const juce_wchar c = (juce_wchar) (characterStartIndex + i);
  70545. Array <int> glyphIndexes;
  70546. Array <float> offsets;
  70547. typefaceToCopy.getGlyphPositions (String::charToString (c), glyphIndexes, offsets);
  70548. const int glyphIndex = glyphIndexes.getFirst();
  70549. if (glyphIndex >= 0 && glyphIndexes.size() > 0)
  70550. {
  70551. const float glyphWidth = offsets[1];
  70552. Path p;
  70553. typefaceToCopy.getOutlineForGlyph (glyphIndex, p);
  70554. addGlyph (c, p, glyphWidth);
  70555. for (int j = glyphs.size() - 1; --j >= 0;)
  70556. {
  70557. const juce_wchar char2 = glyphs.getUnchecked (j)->character;
  70558. glyphIndexes.clearQuick();
  70559. offsets.clearQuick();
  70560. typefaceToCopy.getGlyphPositions (String::charToString (c) + String::charToString (char2), glyphIndexes, offsets);
  70561. if (offsets.size() > 1)
  70562. addKerningPair (c, char2, offsets[1] - glyphWidth);
  70563. }
  70564. }
  70565. }
  70566. }
  70567. bool CustomTypeface::writeToStream (OutputStream& outputStream)
  70568. {
  70569. GZIPCompressorOutputStream out (&outputStream);
  70570. out.writeString (name);
  70571. out.writeBool (isBold);
  70572. out.writeBool (isItalic);
  70573. out.writeFloat (ascent);
  70574. out.writeShort ((short) (unsigned short) defaultCharacter);
  70575. out.writeInt (glyphs.size());
  70576. int i, numKerningPairs = 0;
  70577. for (i = 0; i < glyphs.size(); ++i)
  70578. {
  70579. const GlyphInfo* const g = glyphs.getUnchecked (i);
  70580. out.writeShort ((short) (unsigned short) g->character);
  70581. out.writeFloat (g->width);
  70582. g->path.writePathToStream (out);
  70583. numKerningPairs += g->kerningPairs.size();
  70584. }
  70585. out.writeInt (numKerningPairs);
  70586. for (i = 0; i < glyphs.size(); ++i)
  70587. {
  70588. const GlyphInfo* const g = glyphs.getUnchecked (i);
  70589. for (int j = 0; j < g->kerningPairs.size(); ++j)
  70590. {
  70591. const GlyphInfo::KerningPair& p = g->kerningPairs.getReference (j);
  70592. out.writeShort ((short) (unsigned short) g->character);
  70593. out.writeShort ((short) (unsigned short) p.character2);
  70594. out.writeFloat (p.kerningAmount);
  70595. }
  70596. }
  70597. return true;
  70598. }
  70599. float CustomTypeface::getAscent() const
  70600. {
  70601. return ascent;
  70602. }
  70603. float CustomTypeface::getDescent() const
  70604. {
  70605. return 1.0f - ascent;
  70606. }
  70607. float CustomTypeface::getStringWidth (const String& text)
  70608. {
  70609. float x = 0;
  70610. const juce_wchar* t = (const juce_wchar*) text;
  70611. while (*t != 0)
  70612. {
  70613. const GlyphInfo* const glyph = findGlyphSubstituting (*t++);
  70614. if (glyph != 0)
  70615. x += glyph->getHorizontalSpacing (*t);
  70616. }
  70617. return x;
  70618. }
  70619. void CustomTypeface::getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array<float>& xOffsets)
  70620. {
  70621. xOffsets.add (0);
  70622. float x = 0;
  70623. const juce_wchar* t = (const juce_wchar*) text;
  70624. while (*t != 0)
  70625. {
  70626. const juce_wchar c = *t++;
  70627. const GlyphInfo* const glyph = findGlyphSubstituting (c);
  70628. if (glyph != 0)
  70629. {
  70630. x += glyph->getHorizontalSpacing (*t);
  70631. resultGlyphs.add ((int) glyph->character);
  70632. xOffsets.add (x);
  70633. }
  70634. }
  70635. }
  70636. bool CustomTypeface::getOutlineForGlyph (int glyphNumber, Path& path)
  70637. {
  70638. const GlyphInfo* const glyph = findGlyphSubstituting ((juce_wchar) glyphNumber);
  70639. if (glyph != 0)
  70640. {
  70641. path = glyph->path;
  70642. return true;
  70643. }
  70644. return false;
  70645. }
  70646. END_JUCE_NAMESPACE
  70647. /*** End of inlined file: juce_Typeface.cpp ***/
  70648. /*** Start of inlined file: juce_AffineTransform.cpp ***/
  70649. BEGIN_JUCE_NAMESPACE
  70650. AffineTransform::AffineTransform() throw()
  70651. : mat00 (1.0f),
  70652. mat01 (0),
  70653. mat02 (0),
  70654. mat10 (0),
  70655. mat11 (1.0f),
  70656. mat12 (0)
  70657. {
  70658. }
  70659. AffineTransform::AffineTransform (const AffineTransform& other) throw()
  70660. : mat00 (other.mat00),
  70661. mat01 (other.mat01),
  70662. mat02 (other.mat02),
  70663. mat10 (other.mat10),
  70664. mat11 (other.mat11),
  70665. mat12 (other.mat12)
  70666. {
  70667. }
  70668. AffineTransform::AffineTransform (const float mat00_,
  70669. const float mat01_,
  70670. const float mat02_,
  70671. const float mat10_,
  70672. const float mat11_,
  70673. const float mat12_) throw()
  70674. : mat00 (mat00_),
  70675. mat01 (mat01_),
  70676. mat02 (mat02_),
  70677. mat10 (mat10_),
  70678. mat11 (mat11_),
  70679. mat12 (mat12_)
  70680. {
  70681. }
  70682. const AffineTransform& AffineTransform::operator= (const AffineTransform& other) throw()
  70683. {
  70684. mat00 = other.mat00;
  70685. mat01 = other.mat01;
  70686. mat02 = other.mat02;
  70687. mat10 = other.mat10;
  70688. mat11 = other.mat11;
  70689. mat12 = other.mat12;
  70690. return *this;
  70691. }
  70692. bool AffineTransform::operator== (const AffineTransform& other) const throw()
  70693. {
  70694. return mat00 == other.mat00
  70695. && mat01 == other.mat01
  70696. && mat02 == other.mat02
  70697. && mat10 == other.mat10
  70698. && mat11 == other.mat11
  70699. && mat12 == other.mat12;
  70700. }
  70701. bool AffineTransform::operator!= (const AffineTransform& other) const throw()
  70702. {
  70703. return ! operator== (other);
  70704. }
  70705. bool AffineTransform::isIdentity() const throw()
  70706. {
  70707. return (mat01 == 0)
  70708. && (mat02 == 0)
  70709. && (mat10 == 0)
  70710. && (mat12 == 0)
  70711. && (mat00 == 1.0f)
  70712. && (mat11 == 1.0f);
  70713. }
  70714. const AffineTransform AffineTransform::identity;
  70715. const AffineTransform AffineTransform::followedBy (const AffineTransform& other) const throw()
  70716. {
  70717. return AffineTransform (other.mat00 * mat00 + other.mat01 * mat10,
  70718. other.mat00 * mat01 + other.mat01 * mat11,
  70719. other.mat00 * mat02 + other.mat01 * mat12 + other.mat02,
  70720. other.mat10 * mat00 + other.mat11 * mat10,
  70721. other.mat10 * mat01 + other.mat11 * mat11,
  70722. other.mat10 * mat02 + other.mat11 * mat12 + other.mat12);
  70723. }
  70724. const AffineTransform AffineTransform::followedBy (const float omat00,
  70725. const float omat01,
  70726. const float omat02,
  70727. const float omat10,
  70728. const float omat11,
  70729. const float omat12) const throw()
  70730. {
  70731. return AffineTransform (omat00 * mat00 + omat01 * mat10,
  70732. omat00 * mat01 + omat01 * mat11,
  70733. omat00 * mat02 + omat01 * mat12 + omat02,
  70734. omat10 * mat00 + omat11 * mat10,
  70735. omat10 * mat01 + omat11 * mat11,
  70736. omat10 * mat02 + omat11 * mat12 + omat12);
  70737. }
  70738. const AffineTransform AffineTransform::translated (const float dx,
  70739. const float dy) const throw()
  70740. {
  70741. return AffineTransform (mat00, mat01, mat02 + dx,
  70742. mat10, mat11, mat12 + dy);
  70743. }
  70744. const AffineTransform AffineTransform::translation (const float dx,
  70745. const float dy) throw()
  70746. {
  70747. return AffineTransform (1.0f, 0, dx,
  70748. 0, 1.0f, dy);
  70749. }
  70750. const AffineTransform AffineTransform::rotated (const float rad) const throw()
  70751. {
  70752. const float cosRad = cosf (rad);
  70753. const float sinRad = sinf (rad);
  70754. return followedBy (cosRad, -sinRad, 0,
  70755. sinRad, cosRad, 0);
  70756. }
  70757. const AffineTransform AffineTransform::rotation (const float rad) throw()
  70758. {
  70759. const float cosRad = cosf (rad);
  70760. const float sinRad = sinf (rad);
  70761. return AffineTransform (cosRad, -sinRad, 0,
  70762. sinRad, cosRad, 0);
  70763. }
  70764. const AffineTransform AffineTransform::rotated (const float angle,
  70765. const float pivotX,
  70766. const float pivotY) const throw()
  70767. {
  70768. return translated (-pivotX, -pivotY)
  70769. .rotated (angle)
  70770. .translated (pivotX, pivotY);
  70771. }
  70772. const AffineTransform AffineTransform::rotation (const float angle,
  70773. const float pivotX,
  70774. const float pivotY) throw()
  70775. {
  70776. return translation (-pivotX, -pivotY)
  70777. .rotated (angle)
  70778. .translated (pivotX, pivotY);
  70779. }
  70780. const AffineTransform AffineTransform::scaled (const float factorX,
  70781. const float factorY) const throw()
  70782. {
  70783. return AffineTransform (factorX * mat00, factorX * mat01, factorX * mat02,
  70784. factorY * mat10, factorY * mat11, factorY * mat12);
  70785. }
  70786. const AffineTransform AffineTransform::scale (const float factorX,
  70787. const float factorY) throw()
  70788. {
  70789. return AffineTransform (factorX, 0, 0,
  70790. 0, factorY, 0);
  70791. }
  70792. const AffineTransform AffineTransform::sheared (const float shearX,
  70793. const float shearY) const throw()
  70794. {
  70795. return followedBy (1.0f, shearX, 0,
  70796. shearY, 1.0f, 0);
  70797. }
  70798. const AffineTransform AffineTransform::inverted() const throw()
  70799. {
  70800. double determinant = (mat00 * mat11 - mat10 * mat01);
  70801. if (determinant != 0.0)
  70802. {
  70803. determinant = 1.0 / determinant;
  70804. const float dst00 = (float) (mat11 * determinant);
  70805. const float dst10 = (float) (-mat10 * determinant);
  70806. const float dst01 = (float) (-mat01 * determinant);
  70807. const float dst11 = (float) (mat00 * determinant);
  70808. return AffineTransform (dst00, dst01, -mat02 * dst00 - mat12 * dst01,
  70809. dst10, dst11, -mat02 * dst10 - mat12 * dst11);
  70810. }
  70811. else
  70812. {
  70813. // singularity..
  70814. return *this;
  70815. }
  70816. }
  70817. bool AffineTransform::isSingularity() const throw()
  70818. {
  70819. return (mat00 * mat11 - mat10 * mat01) == 0.0;
  70820. }
  70821. bool AffineTransform::isOnlyTranslation() const throw()
  70822. {
  70823. return (mat01 == 0)
  70824. && (mat10 == 0)
  70825. && (mat00 == 1.0f)
  70826. && (mat11 == 1.0f);
  70827. }
  70828. void AffineTransform::transformPoint (float& x,
  70829. float& y) const throw()
  70830. {
  70831. const float oldX = x;
  70832. x = mat00 * oldX + mat01 * y + mat02;
  70833. y = mat10 * oldX + mat11 * y + mat12;
  70834. }
  70835. void AffineTransform::transformPoint (double& x,
  70836. double& y) const throw()
  70837. {
  70838. const double oldX = x;
  70839. x = mat00 * oldX + mat01 * y + mat02;
  70840. y = mat10 * oldX + mat11 * y + mat12;
  70841. }
  70842. END_JUCE_NAMESPACE
  70843. /*** End of inlined file: juce_AffineTransform.cpp ***/
  70844. /*** Start of inlined file: juce_BorderSize.cpp ***/
  70845. BEGIN_JUCE_NAMESPACE
  70846. BorderSize::BorderSize() throw()
  70847. : top (0),
  70848. left (0),
  70849. bottom (0),
  70850. right (0)
  70851. {
  70852. }
  70853. BorderSize::BorderSize (const BorderSize& other) throw()
  70854. : top (other.top),
  70855. left (other.left),
  70856. bottom (other.bottom),
  70857. right (other.right)
  70858. {
  70859. }
  70860. BorderSize::BorderSize (const int topGap,
  70861. const int leftGap,
  70862. const int bottomGap,
  70863. const int rightGap) throw()
  70864. : top (topGap),
  70865. left (leftGap),
  70866. bottom (bottomGap),
  70867. right (rightGap)
  70868. {
  70869. }
  70870. BorderSize::BorderSize (const int allGaps) throw()
  70871. : top (allGaps),
  70872. left (allGaps),
  70873. bottom (allGaps),
  70874. right (allGaps)
  70875. {
  70876. }
  70877. BorderSize::~BorderSize() throw()
  70878. {
  70879. }
  70880. void BorderSize::setTop (const int newTopGap) throw()
  70881. {
  70882. top = newTopGap;
  70883. }
  70884. void BorderSize::setLeft (const int newLeftGap) throw()
  70885. {
  70886. left = newLeftGap;
  70887. }
  70888. void BorderSize::setBottom (const int newBottomGap) throw()
  70889. {
  70890. bottom = newBottomGap;
  70891. }
  70892. void BorderSize::setRight (const int newRightGap) throw()
  70893. {
  70894. right = newRightGap;
  70895. }
  70896. const Rectangle<int> BorderSize::subtractedFrom (const Rectangle<int>& r) const throw()
  70897. {
  70898. return Rectangle<int> (r.getX() + left,
  70899. r.getY() + top,
  70900. r.getWidth() - (left + right),
  70901. r.getHeight() - (top + bottom));
  70902. }
  70903. void BorderSize::subtractFrom (Rectangle<int>& r) const throw()
  70904. {
  70905. r.setBounds (r.getX() + left,
  70906. r.getY() + top,
  70907. r.getWidth() - (left + right),
  70908. r.getHeight() - (top + bottom));
  70909. }
  70910. const Rectangle<int> BorderSize::addedTo (const Rectangle<int>& r) const throw()
  70911. {
  70912. return Rectangle<int> (r.getX() - left,
  70913. r.getY() - top,
  70914. r.getWidth() + (left + right),
  70915. r.getHeight() + (top + bottom));
  70916. }
  70917. void BorderSize::addTo (Rectangle<int>& r) const throw()
  70918. {
  70919. r.setBounds (r.getX() - left,
  70920. r.getY() - top,
  70921. r.getWidth() + (left + right),
  70922. r.getHeight() + (top + bottom));
  70923. }
  70924. bool BorderSize::operator== (const BorderSize& other) const throw()
  70925. {
  70926. return top == other.top
  70927. && left == other.left
  70928. && bottom == other.bottom
  70929. && right == other.right;
  70930. }
  70931. bool BorderSize::operator!= (const BorderSize& other) const throw()
  70932. {
  70933. return ! operator== (other);
  70934. }
  70935. END_JUCE_NAMESPACE
  70936. /*** End of inlined file: juce_BorderSize.cpp ***/
  70937. /*** Start of inlined file: juce_Line.cpp ***/
  70938. BEGIN_JUCE_NAMESPACE
  70939. static bool juce_lineIntersection (const float x1, const float y1,
  70940. const float x2, const float y2,
  70941. const float x3, const float y3,
  70942. const float x4, const float y4,
  70943. float& intersectionX,
  70944. float& intersectionY) throw()
  70945. {
  70946. if (x2 != x3 || y2 != y3)
  70947. {
  70948. const float dx1 = x2 - x1;
  70949. const float dy1 = y2 - y1;
  70950. const float dx2 = x4 - x3;
  70951. const float dy2 = y4 - y3;
  70952. const float divisor = dx1 * dy2 - dx2 * dy1;
  70953. if (divisor == 0)
  70954. {
  70955. if (! ((dx1 == 0 && dy1 == 0) || (dx2 == 0 && dy2 == 0)))
  70956. {
  70957. if (dy1 == 0 && dy2 != 0)
  70958. {
  70959. const float along = (y1 - y3) / dy2;
  70960. intersectionX = x3 + along * dx2;
  70961. intersectionY = y1;
  70962. return along >= 0 && along <= 1.0f;
  70963. }
  70964. else if (dy2 == 0 && dy1 != 0)
  70965. {
  70966. const float along = (y3 - y1) / dy1;
  70967. intersectionX = x1 + along * dx1;
  70968. intersectionY = y3;
  70969. return along >= 0 && along <= 1.0f;
  70970. }
  70971. else if (dx1 == 0 && dx2 != 0)
  70972. {
  70973. const float along = (x1 - x3) / dx2;
  70974. intersectionX = x1;
  70975. intersectionY = y3 + along * dy2;
  70976. return along >= 0 && along <= 1.0f;
  70977. }
  70978. else if (dx2 == 0 && dx1 != 0)
  70979. {
  70980. const float along = (x3 - x1) / dx1;
  70981. intersectionX = x3;
  70982. intersectionY = y1 + along * dy1;
  70983. return along >= 0 && along <= 1.0f;
  70984. }
  70985. }
  70986. intersectionX = 0.5f * (x2 + x3);
  70987. intersectionY = 0.5f * (y2 + y3);
  70988. return false;
  70989. }
  70990. const float along1 = ((y1 - y3) * dx2 - (x1 - x3) * dy2) / divisor;
  70991. intersectionX = x1 + along1 * dx1;
  70992. intersectionY = y1 + along1 * dy1;
  70993. if (along1 < 0 || along1 > 1.0f)
  70994. return false;
  70995. const float along2 = ((y1 - y3) * dx1 - (x1 - x3) * dy1) / divisor;
  70996. return along2 >= 0 && along2 <= 1.0f;
  70997. }
  70998. intersectionX = x2;
  70999. intersectionY = y2;
  71000. return true;
  71001. }
  71002. Line::Line() throw()
  71003. : startX (0.0f),
  71004. startY (0.0f),
  71005. endX (0.0f),
  71006. endY (0.0f)
  71007. {
  71008. }
  71009. Line::Line (const Line& other) throw()
  71010. : startX (other.startX),
  71011. startY (other.startY),
  71012. endX (other.endX),
  71013. endY (other.endY)
  71014. {
  71015. }
  71016. Line::Line (const float startX_, const float startY_,
  71017. const float endX_, const float endY_) throw()
  71018. : startX (startX_),
  71019. startY (startY_),
  71020. endX (endX_),
  71021. endY (endY_)
  71022. {
  71023. }
  71024. Line::Line (const Point<float>& start,
  71025. const Point<float>& end) throw()
  71026. : startX (start.getX()),
  71027. startY (start.getY()),
  71028. endX (end.getX()),
  71029. endY (end.getY())
  71030. {
  71031. }
  71032. const Line& Line::operator= (const Line& other) throw()
  71033. {
  71034. startX = other.startX;
  71035. startY = other.startY;
  71036. endX = other.endX;
  71037. endY = other.endY;
  71038. return *this;
  71039. }
  71040. Line::~Line() throw()
  71041. {
  71042. }
  71043. const Point<float> Line::getStart() const throw()
  71044. {
  71045. return Point<float> (startX, startY);
  71046. }
  71047. const Point<float> Line::getEnd() const throw()
  71048. {
  71049. return Point<float> (endX, endY);
  71050. }
  71051. void Line::setStart (const float newStartX,
  71052. const float newStartY) throw()
  71053. {
  71054. startX = newStartX;
  71055. startY = newStartY;
  71056. }
  71057. void Line::setStart (const Point<float>& newStart) throw()
  71058. {
  71059. startX = newStart.getX();
  71060. startY = newStart.getY();
  71061. }
  71062. void Line::setEnd (const float newEndX,
  71063. const float newEndY) throw()
  71064. {
  71065. endX = newEndX;
  71066. endY = newEndY;
  71067. }
  71068. void Line::setEnd (const Point<float>& newEnd) throw()
  71069. {
  71070. endX = newEnd.getX();
  71071. endY = newEnd.getY();
  71072. }
  71073. bool Line::operator== (const Line& other) const throw()
  71074. {
  71075. return startX == other.startX
  71076. && startY == other.startY
  71077. && endX == other.endX
  71078. && endY == other.endY;
  71079. }
  71080. bool Line::operator!= (const Line& other) const throw()
  71081. {
  71082. return startX != other.startX
  71083. || startY != other.startY
  71084. || endX != other.endX
  71085. || endY != other.endY;
  71086. }
  71087. void Line::applyTransform (const AffineTransform& transform) throw()
  71088. {
  71089. transform.transformPoint (startX, startY);
  71090. transform.transformPoint (endX, endY);
  71091. }
  71092. float Line::getLength() const throw()
  71093. {
  71094. return (float) juce_hypot (startX - endX,
  71095. startY - endY);
  71096. }
  71097. float Line::getAngle() const throw()
  71098. {
  71099. return atan2f (endX - startX,
  71100. endY - startY);
  71101. }
  71102. const Point<float> Line::getPointAlongLine (const float distanceFromStart) const throw()
  71103. {
  71104. const float alpha = distanceFromStart / getLength();
  71105. return Point<float> (startX + (endX - startX) * alpha,
  71106. startY + (endY - startY) * alpha);
  71107. }
  71108. const Point<float> Line::getPointAlongLine (const float offsetX,
  71109. const float offsetY) const throw()
  71110. {
  71111. const float dx = endX - startX;
  71112. const float dy = endY - startY;
  71113. const double length = juce_hypot (dx, dy);
  71114. if (length == 0)
  71115. return Point<float> (startX, startY);
  71116. else
  71117. return Point<float> (startX + (float) (((dx * offsetX) - (dy * offsetY)) / length),
  71118. startY + (float) (((dy * offsetX) + (dx * offsetY)) / length));
  71119. }
  71120. const Point<float> Line::getPointAlongLineProportionally (const float alpha) const throw()
  71121. {
  71122. return Point<float> (startX + (endX - startX) * alpha,
  71123. startY + (endY - startY) * alpha);
  71124. }
  71125. float Line::getDistanceFromLine (const float x,
  71126. const float y) const throw()
  71127. {
  71128. const double dx = endX - startX;
  71129. const double dy = endY - startY;
  71130. const double length = dx * dx + dy * dy;
  71131. if (length > 0)
  71132. {
  71133. const double prop = ((x - startX) * dx + (y - startY) * dy) / length;
  71134. if (prop >= 0.0f && prop < 1.0f)
  71135. {
  71136. return (float) juce_hypot (x - (startX + prop * dx),
  71137. y - (startY + prop * dy));
  71138. }
  71139. }
  71140. return (float) jmin (juce_hypot (x - startX, y - startY),
  71141. juce_hypot (x - endX, y - endY));
  71142. }
  71143. float Line::findNearestPointTo (const float x,
  71144. const float y) const throw()
  71145. {
  71146. const double dx = endX - startX;
  71147. const double dy = endY - startY;
  71148. const double length = dx * dx + dy * dy;
  71149. if (length <= 0.0)
  71150. return 0.0f;
  71151. return jlimit (0.0f, 1.0f,
  71152. (float) (((x - startX) * dx + (y - startY) * dy) / length));
  71153. }
  71154. const Line Line::withShortenedStart (const float distanceToShortenBy) const throw()
  71155. {
  71156. const float length = getLength();
  71157. return Line (getPointAlongLine (jmin (distanceToShortenBy, length)),
  71158. getEnd());
  71159. }
  71160. const Line Line::withShortenedEnd (const float distanceToShortenBy) const throw()
  71161. {
  71162. const float length = getLength();
  71163. return Line (getStart(),
  71164. getPointAlongLine (length - jmin (distanceToShortenBy, length)));
  71165. }
  71166. bool Line::clipToPath (const Path& path,
  71167. const bool keepSectionOutsidePath) throw()
  71168. {
  71169. const bool startInside = path.contains (startX, startY);
  71170. const bool endInside = path.contains (endX, endY);
  71171. if (startInside == endInside)
  71172. {
  71173. if (keepSectionOutsidePath != startInside)
  71174. {
  71175. // entirely outside the path
  71176. return false;
  71177. }
  71178. else
  71179. {
  71180. // entirely inside the path
  71181. startX = 0.0f;
  71182. startY = 0.0f;
  71183. endX = 0.0f;
  71184. endY = 0.0f;
  71185. return true;
  71186. }
  71187. }
  71188. else
  71189. {
  71190. bool changed = false;
  71191. PathFlatteningIterator iter (path, AffineTransform::identity);
  71192. while (iter.next())
  71193. {
  71194. float ix, iy;
  71195. if (intersects (Line (iter.x1, iter.y1,
  71196. iter.x2, iter.y2),
  71197. ix, iy))
  71198. {
  71199. if ((startInside && keepSectionOutsidePath)
  71200. || (endInside && ! keepSectionOutsidePath))
  71201. {
  71202. setStart (ix, iy);
  71203. }
  71204. else
  71205. {
  71206. setEnd (ix, iy);
  71207. }
  71208. changed = true;
  71209. }
  71210. }
  71211. return changed;
  71212. }
  71213. }
  71214. bool Line::intersects (const Line& line,
  71215. float& intersectionX,
  71216. float& intersectionY) const throw()
  71217. {
  71218. return juce_lineIntersection (startX, startY,
  71219. endX, endY,
  71220. line.startX, line.startY,
  71221. line.endX, line.endY,
  71222. intersectionX,
  71223. intersectionY);
  71224. }
  71225. bool Line::isVertical() const throw()
  71226. {
  71227. return startX == endX;
  71228. }
  71229. bool Line::isHorizontal() const throw()
  71230. {
  71231. return startY == endY;
  71232. }
  71233. bool Line::isPointAbove (const float x, const float y) const throw()
  71234. {
  71235. return startX != endX
  71236. && y < ((endY - startY) * (x - startX)) / (endX - startX) + startY;
  71237. }
  71238. END_JUCE_NAMESPACE
  71239. /*** End of inlined file: juce_Line.cpp ***/
  71240. /*** Start of inlined file: juce_Path.cpp ***/
  71241. BEGIN_JUCE_NAMESPACE
  71242. // tests that some co-ords aren't NaNs
  71243. #define CHECK_COORDS_ARE_VALID(x, y) \
  71244. jassert (x == x && y == y);
  71245. const float Path::lineMarker = 100001.0f;
  71246. const float Path::moveMarker = 100002.0f;
  71247. const float Path::quadMarker = 100003.0f;
  71248. const float Path::cubicMarker = 100004.0f;
  71249. const float Path::closeSubPathMarker = 100005.0f;
  71250. static const int defaultGranularity = 32;
  71251. Path::Path() throw()
  71252. : numElements (0),
  71253. pathXMin (0),
  71254. pathXMax (0),
  71255. pathYMin (0),
  71256. pathYMax (0),
  71257. useNonZeroWinding (true)
  71258. {
  71259. }
  71260. Path::~Path() throw()
  71261. {
  71262. }
  71263. Path::Path (const Path& other) throw()
  71264. : numElements (other.numElements),
  71265. pathXMin (other.pathXMin),
  71266. pathXMax (other.pathXMax),
  71267. pathYMin (other.pathYMin),
  71268. pathYMax (other.pathYMax),
  71269. useNonZeroWinding (other.useNonZeroWinding)
  71270. {
  71271. if (numElements > 0)
  71272. {
  71273. data.setAllocatedSize (numElements);
  71274. memcpy (data.elements, other.data.elements, numElements * sizeof (float));
  71275. }
  71276. }
  71277. const Path& Path::operator= (const Path& other) throw()
  71278. {
  71279. if (this != &other)
  71280. {
  71281. data.ensureAllocatedSize (other.numElements);
  71282. numElements = other.numElements;
  71283. pathXMin = other.pathXMin;
  71284. pathXMax = other.pathXMax;
  71285. pathYMin = other.pathYMin;
  71286. pathYMax = other.pathYMax;
  71287. useNonZeroWinding = other.useNonZeroWinding;
  71288. if (numElements > 0)
  71289. memcpy (data.elements, other.data.elements, numElements * sizeof (float));
  71290. }
  71291. return *this;
  71292. }
  71293. void Path::clear() throw()
  71294. {
  71295. numElements = 0;
  71296. pathXMin = 0;
  71297. pathYMin = 0;
  71298. pathYMax = 0;
  71299. pathXMax = 0;
  71300. }
  71301. void Path::swapWithPath (Path& other)
  71302. {
  71303. data.swapWith (other.data);
  71304. swapVariables <int> (numElements, other.numElements);
  71305. swapVariables <float> (pathXMin, other.pathXMin);
  71306. swapVariables <float> (pathXMax, other.pathXMax);
  71307. swapVariables <float> (pathYMin, other.pathYMin);
  71308. swapVariables <float> (pathYMax, other.pathYMax);
  71309. swapVariables <bool> (useNonZeroWinding, other.useNonZeroWinding);
  71310. }
  71311. void Path::setUsingNonZeroWinding (const bool isNonZero) throw()
  71312. {
  71313. useNonZeroWinding = isNonZero;
  71314. }
  71315. void Path::scaleToFit (const float x, const float y, const float w, const float h,
  71316. const bool preserveProportions) throw()
  71317. {
  71318. applyTransform (getTransformToScaleToFit (x, y, w, h, preserveProportions));
  71319. }
  71320. bool Path::isEmpty() const throw()
  71321. {
  71322. int i = 0;
  71323. while (i < numElements)
  71324. {
  71325. const float type = data.elements [i++];
  71326. if (type == moveMarker)
  71327. {
  71328. i += 2;
  71329. }
  71330. else if (type == lineMarker
  71331. || type == quadMarker
  71332. || type == cubicMarker)
  71333. {
  71334. return false;
  71335. }
  71336. }
  71337. return true;
  71338. }
  71339. const Rectangle<float> Path::getBounds () const throw()
  71340. {
  71341. return Rectangle<float> (pathXMin, pathYMin,
  71342. pathXMax - pathXMin,
  71343. pathYMax - pathYMin);
  71344. }
  71345. const Rectangle<float> Path::getBoundsTransformed (const AffineTransform& transform) const throw()
  71346. {
  71347. return getBounds().transformed (transform);
  71348. }
  71349. void Path::startNewSubPath (const float x,
  71350. const float y) throw()
  71351. {
  71352. CHECK_COORDS_ARE_VALID (x, y);
  71353. if (numElements == 0)
  71354. {
  71355. pathXMin = pathXMax = x;
  71356. pathYMin = pathYMax = y;
  71357. }
  71358. else
  71359. {
  71360. pathXMin = jmin (pathXMin, x);
  71361. pathXMax = jmax (pathXMax, x);
  71362. pathYMin = jmin (pathYMin, y);
  71363. pathYMax = jmax (pathYMax, y);
  71364. }
  71365. data.ensureAllocatedSize (numElements + 3);
  71366. data.elements [numElements++] = moveMarker;
  71367. data.elements [numElements++] = x;
  71368. data.elements [numElements++] = y;
  71369. }
  71370. void Path::lineTo (const float x, const float y) throw()
  71371. {
  71372. CHECK_COORDS_ARE_VALID (x, y);
  71373. if (numElements == 0)
  71374. startNewSubPath (0, 0);
  71375. data.ensureAllocatedSize (numElements + 3);
  71376. data.elements [numElements++] = lineMarker;
  71377. data.elements [numElements++] = x;
  71378. data.elements [numElements++] = y;
  71379. pathXMin = jmin (pathXMin, x);
  71380. pathXMax = jmax (pathXMax, x);
  71381. pathYMin = jmin (pathYMin, y);
  71382. pathYMax = jmax (pathYMax, y);
  71383. }
  71384. void Path::quadraticTo (const float x1, const float y1,
  71385. const float x2, const float y2) throw()
  71386. {
  71387. CHECK_COORDS_ARE_VALID (x1, y1);
  71388. CHECK_COORDS_ARE_VALID (x2, y2);
  71389. if (numElements == 0)
  71390. startNewSubPath (0, 0);
  71391. data.ensureAllocatedSize (numElements + 5);
  71392. data.elements [numElements++] = quadMarker;
  71393. data.elements [numElements++] = x1;
  71394. data.elements [numElements++] = y1;
  71395. data.elements [numElements++] = x2;
  71396. data.elements [numElements++] = y2;
  71397. pathXMin = jmin (pathXMin, x1, x2);
  71398. pathXMax = jmax (pathXMax, x1, x2);
  71399. pathYMin = jmin (pathYMin, y1, y2);
  71400. pathYMax = jmax (pathYMax, y1, y2);
  71401. }
  71402. void Path::cubicTo (const float x1, const float y1,
  71403. const float x2, const float y2,
  71404. const float x3, const float y3) throw()
  71405. {
  71406. CHECK_COORDS_ARE_VALID (x1, y1);
  71407. CHECK_COORDS_ARE_VALID (x2, y2);
  71408. CHECK_COORDS_ARE_VALID (x3, y3);
  71409. if (numElements == 0)
  71410. startNewSubPath (0, 0);
  71411. data.ensureAllocatedSize (numElements + 7);
  71412. data.elements [numElements++] = cubicMarker;
  71413. data.elements [numElements++] = x1;
  71414. data.elements [numElements++] = y1;
  71415. data.elements [numElements++] = x2;
  71416. data.elements [numElements++] = y2;
  71417. data.elements [numElements++] = x3;
  71418. data.elements [numElements++] = y3;
  71419. pathXMin = jmin (pathXMin, x1, x2, x3);
  71420. pathXMax = jmax (pathXMax, x1, x2, x3);
  71421. pathYMin = jmin (pathYMin, y1, y2, y3);
  71422. pathYMax = jmax (pathYMax, y1, y2, y3);
  71423. }
  71424. void Path::closeSubPath() throw()
  71425. {
  71426. if (numElements > 0
  71427. && data.elements [numElements - 1] != closeSubPathMarker)
  71428. {
  71429. data.ensureAllocatedSize (numElements + 1);
  71430. data.elements [numElements++] = closeSubPathMarker;
  71431. }
  71432. }
  71433. const Point<float> Path::getCurrentPosition() const
  71434. {
  71435. int i = numElements - 1;
  71436. if (i > 0 && data.elements[i] == closeSubPathMarker)
  71437. {
  71438. while (i >= 0)
  71439. {
  71440. if (data.elements[i] == moveMarker)
  71441. {
  71442. i += 2;
  71443. break;
  71444. }
  71445. --i;
  71446. }
  71447. }
  71448. if (i > 0)
  71449. return Point<float> (data.elements [i - 1], data.elements [i]);
  71450. return Point<float>();
  71451. }
  71452. void Path::addRectangle (const float x, const float y,
  71453. const float w, const float h) throw()
  71454. {
  71455. float x1 = x, y1 = y, x2 = x + w, y2 = y + h;
  71456. if (w < 0)
  71457. swapVariables (x1, x2);
  71458. if (h < 0)
  71459. swapVariables (y1, y2);
  71460. data.ensureAllocatedSize (numElements + 13);
  71461. if (numElements == 0)
  71462. {
  71463. pathXMin = x1;
  71464. pathXMax = x2;
  71465. pathYMin = y1;
  71466. pathYMax = y2;
  71467. }
  71468. else
  71469. {
  71470. pathXMin = jmin (pathXMin, x1);
  71471. pathXMax = jmax (pathXMax, x2);
  71472. pathYMin = jmin (pathYMin, y1);
  71473. pathYMax = jmax (pathYMax, y2);
  71474. }
  71475. data.elements [numElements++] = moveMarker;
  71476. data.elements [numElements++] = x1;
  71477. data.elements [numElements++] = y2;
  71478. data.elements [numElements++] = lineMarker;
  71479. data.elements [numElements++] = x1;
  71480. data.elements [numElements++] = y1;
  71481. data.elements [numElements++] = lineMarker;
  71482. data.elements [numElements++] = x2;
  71483. data.elements [numElements++] = y1;
  71484. data.elements [numElements++] = lineMarker;
  71485. data.elements [numElements++] = x2;
  71486. data.elements [numElements++] = y2;
  71487. data.elements [numElements++] = closeSubPathMarker;
  71488. }
  71489. void Path::addRectangle (const Rectangle<int>& rectangle) throw()
  71490. {
  71491. addRectangle ((float) rectangle.getX(), (float) rectangle.getY(),
  71492. (float) rectangle.getWidth(), (float) rectangle.getHeight());
  71493. }
  71494. void Path::addRoundedRectangle (const float x, const float y,
  71495. const float w, const float h,
  71496. float csx,
  71497. float csy) throw()
  71498. {
  71499. csx = jmin (csx, w * 0.5f);
  71500. csy = jmin (csy, h * 0.5f);
  71501. const float cs45x = csx * 0.45f;
  71502. const float cs45y = csy * 0.45f;
  71503. const float x2 = x + w;
  71504. const float y2 = y + h;
  71505. startNewSubPath (x + csx, y);
  71506. lineTo (x2 - csx, y);
  71507. cubicTo (x2 - cs45x, y, x2, y + cs45y, x2, y + csy);
  71508. lineTo (x2, y2 - csy);
  71509. cubicTo (x2, y2 - cs45y, x2 - cs45x, y2, x2 - csx, y2);
  71510. lineTo (x + csx, y2);
  71511. cubicTo (x + cs45x, y2, x, y2 - cs45y, x, y2 - csy);
  71512. lineTo (x, y + csy);
  71513. cubicTo (x, y + cs45y, x + cs45x, y, x + csx, y);
  71514. closeSubPath();
  71515. }
  71516. void Path::addRoundedRectangle (const float x, const float y,
  71517. const float w, const float h,
  71518. float cs) throw()
  71519. {
  71520. addRoundedRectangle (x, y, w, h, cs, cs);
  71521. }
  71522. void Path::addTriangle (const float x1, const float y1,
  71523. const float x2, const float y2,
  71524. const float x3, const float y3) throw()
  71525. {
  71526. startNewSubPath (x1, y1);
  71527. lineTo (x2, y2);
  71528. lineTo (x3, y3);
  71529. closeSubPath();
  71530. }
  71531. void Path::addQuadrilateral (const float x1, const float y1,
  71532. const float x2, const float y2,
  71533. const float x3, const float y3,
  71534. const float x4, const float y4) throw()
  71535. {
  71536. startNewSubPath (x1, y1);
  71537. lineTo (x2, y2);
  71538. lineTo (x3, y3);
  71539. lineTo (x4, y4);
  71540. closeSubPath();
  71541. }
  71542. void Path::addEllipse (const float x, const float y,
  71543. const float w, const float h) throw()
  71544. {
  71545. const float hw = w * 0.5f;
  71546. const float hw55 = hw * 0.55f;
  71547. const float hh = h * 0.5f;
  71548. const float hh45 = hh * 0.55f;
  71549. const float cx = x + hw;
  71550. const float cy = y + hh;
  71551. startNewSubPath (cx, cy - hh);
  71552. cubicTo (cx + hw55, cy - hh, cx + hw, cy - hh45, cx + hw, cy);
  71553. cubicTo (cx + hw, cy + hh45, cx + hw55, cy + hh, cx, cy + hh);
  71554. cubicTo (cx - hw55, cy + hh, cx - hw, cy + hh45, cx - hw, cy);
  71555. cubicTo (cx - hw, cy - hh45, cx - hw55, cy - hh, cx, cy - hh);
  71556. closeSubPath();
  71557. }
  71558. void Path::addArc (const float x, const float y,
  71559. const float w, const float h,
  71560. const float fromRadians,
  71561. const float toRadians,
  71562. const bool startAsNewSubPath) throw()
  71563. {
  71564. const float radiusX = w / 2.0f;
  71565. const float radiusY = h / 2.0f;
  71566. addCentredArc (x + radiusX,
  71567. y + radiusY,
  71568. radiusX, radiusY,
  71569. 0.0f,
  71570. fromRadians, toRadians,
  71571. startAsNewSubPath);
  71572. }
  71573. static const float ellipseAngularIncrement = 0.05f;
  71574. void Path::addCentredArc (const float centreX, const float centreY,
  71575. const float radiusX, const float radiusY,
  71576. const float rotationOfEllipse,
  71577. const float fromRadians,
  71578. const float toRadians,
  71579. const bool startAsNewSubPath) throw()
  71580. {
  71581. if (radiusX > 0.0f && radiusY > 0.0f)
  71582. {
  71583. const AffineTransform rotation (AffineTransform::rotation (rotationOfEllipse, centreX, centreY));
  71584. float angle = fromRadians;
  71585. if (startAsNewSubPath)
  71586. {
  71587. float x = centreX + radiusX * sinf (angle);
  71588. float y = centreY - radiusY * cosf (angle);
  71589. if (rotationOfEllipse != 0)
  71590. rotation.transformPoint (x, y);
  71591. startNewSubPath (x, y);
  71592. }
  71593. if (fromRadians < toRadians)
  71594. {
  71595. if (startAsNewSubPath)
  71596. angle += ellipseAngularIncrement;
  71597. while (angle < toRadians)
  71598. {
  71599. float x = centreX + radiusX * sinf (angle);
  71600. float y = centreY - radiusY * cosf (angle);
  71601. if (rotationOfEllipse != 0)
  71602. rotation.transformPoint (x, y);
  71603. lineTo (x, y);
  71604. angle += ellipseAngularIncrement;
  71605. }
  71606. }
  71607. else
  71608. {
  71609. if (startAsNewSubPath)
  71610. angle -= ellipseAngularIncrement;
  71611. while (angle > toRadians)
  71612. {
  71613. float x = centreX + radiusX * sinf (angle);
  71614. float y = centreY - radiusY * cosf (angle);
  71615. if (rotationOfEllipse != 0)
  71616. rotation.transformPoint (x, y);
  71617. lineTo (x, y);
  71618. angle -= ellipseAngularIncrement;
  71619. }
  71620. }
  71621. float x = centreX + radiusX * sinf (toRadians);
  71622. float y = centreY - radiusY * cosf (toRadians);
  71623. if (rotationOfEllipse != 0)
  71624. rotation.transformPoint (x, y);
  71625. lineTo (x, y);
  71626. }
  71627. }
  71628. void Path::addPieSegment (const float x, const float y,
  71629. const float width, const float height,
  71630. const float fromRadians,
  71631. const float toRadians,
  71632. const float innerCircleProportionalSize)
  71633. {
  71634. float hw = width * 0.5f;
  71635. float hh = height * 0.5f;
  71636. const float centreX = x + hw;
  71637. const float centreY = y + hh;
  71638. startNewSubPath (centreX + hw * sinf (fromRadians),
  71639. centreY - hh * cosf (fromRadians));
  71640. addArc (x, y, width, height, fromRadians, toRadians);
  71641. if (fabs (fromRadians - toRadians) > float_Pi * 1.999f)
  71642. {
  71643. closeSubPath();
  71644. if (innerCircleProportionalSize > 0)
  71645. {
  71646. hw *= innerCircleProportionalSize;
  71647. hh *= innerCircleProportionalSize;
  71648. startNewSubPath (centreX + hw * sinf (toRadians),
  71649. centreY - hh * cosf (toRadians));
  71650. addArc (centreX - hw, centreY - hh, hw * 2.0f, hh * 2.0f,
  71651. toRadians, fromRadians);
  71652. }
  71653. }
  71654. else
  71655. {
  71656. if (innerCircleProportionalSize > 0)
  71657. {
  71658. hw *= innerCircleProportionalSize;
  71659. hh *= innerCircleProportionalSize;
  71660. addArc (centreX - hw, centreY - hh, hw * 2.0f, hh * 2.0f,
  71661. toRadians, fromRadians);
  71662. }
  71663. else
  71664. {
  71665. lineTo (centreX, centreY);
  71666. }
  71667. }
  71668. closeSubPath();
  71669. }
  71670. static void perpendicularOffset (const float x1, const float y1,
  71671. const float x2, const float y2,
  71672. const float offsetX, const float offsetY,
  71673. float& resultX, float& resultY) throw()
  71674. {
  71675. const float dx = x2 - x1;
  71676. const float dy = y2 - y1;
  71677. const float len = juce_hypotf (dx, dy);
  71678. if (len == 0)
  71679. {
  71680. resultX = x1;
  71681. resultY = y1;
  71682. }
  71683. else
  71684. {
  71685. resultX = x1 + ((dx * offsetX) - (dy * offsetY)) / len;
  71686. resultY = y1 + ((dy * offsetX) + (dx * offsetY)) / len;
  71687. }
  71688. }
  71689. void Path::addLineSegment (const float startX, const float startY,
  71690. const float endX, const float endY,
  71691. float lineThickness) throw()
  71692. {
  71693. lineThickness *= 0.5f;
  71694. float x, y;
  71695. perpendicularOffset (startX, startY, endX, endY,
  71696. 0, lineThickness, x, y);
  71697. startNewSubPath (x, y);
  71698. perpendicularOffset (startX, startY, endX, endY,
  71699. 0, -lineThickness, x, y);
  71700. lineTo (x, y);
  71701. perpendicularOffset (endX, endY, startX, startY,
  71702. 0, lineThickness, x, y);
  71703. lineTo (x, y);
  71704. perpendicularOffset (endX, endY, startX, startY,
  71705. 0, -lineThickness, x, y);
  71706. lineTo (x, y);
  71707. closeSubPath();
  71708. }
  71709. void Path::addArrow (const float startX, const float startY,
  71710. const float endX, const float endY,
  71711. float lineThickness,
  71712. float arrowheadWidth,
  71713. float arrowheadLength) throw()
  71714. {
  71715. lineThickness *= 0.5f;
  71716. arrowheadWidth *= 0.5f;
  71717. arrowheadLength = jmin (arrowheadLength, 0.8f * juce_hypotf (startX - endX,
  71718. startY - endY));
  71719. float x, y;
  71720. perpendicularOffset (startX, startY, endX, endY,
  71721. 0, lineThickness, x, y);
  71722. startNewSubPath (x, y);
  71723. perpendicularOffset (startX, startY, endX, endY,
  71724. 0, -lineThickness, x, y);
  71725. lineTo (x, y);
  71726. perpendicularOffset (endX, endY, startX, startY,
  71727. arrowheadLength, lineThickness, x, y);
  71728. lineTo (x, y);
  71729. perpendicularOffset (endX, endY, startX, startY,
  71730. arrowheadLength, arrowheadWidth, x, y);
  71731. lineTo (x, y);
  71732. perpendicularOffset (endX, endY, startX, startY,
  71733. 0, 0, x, y);
  71734. lineTo (x, y);
  71735. perpendicularOffset (endX, endY, startX, startY,
  71736. arrowheadLength, -arrowheadWidth, x, y);
  71737. lineTo (x, y);
  71738. perpendicularOffset (endX, endY, startX, startY,
  71739. arrowheadLength, -lineThickness, x, y);
  71740. lineTo (x, y);
  71741. closeSubPath();
  71742. }
  71743. void Path::addStar (const float centreX,
  71744. const float centreY,
  71745. const int numberOfPoints,
  71746. const float innerRadius,
  71747. const float outerRadius,
  71748. const float startAngle)
  71749. {
  71750. jassert (numberOfPoints > 1); // this would be silly.
  71751. if (numberOfPoints > 1)
  71752. {
  71753. const float angleBetweenPoints = float_Pi * 2.0f / numberOfPoints;
  71754. for (int i = 0; i < numberOfPoints; ++i)
  71755. {
  71756. float angle = startAngle + i * angleBetweenPoints;
  71757. const float x = centreX + outerRadius * sinf (angle);
  71758. const float y = centreY - outerRadius * cosf (angle);
  71759. if (i == 0)
  71760. startNewSubPath (x, y);
  71761. else
  71762. lineTo (x, y);
  71763. angle += angleBetweenPoints * 0.5f;
  71764. lineTo (centreX + innerRadius * sinf (angle),
  71765. centreY - innerRadius * cosf (angle));
  71766. }
  71767. closeSubPath();
  71768. }
  71769. }
  71770. void Path::addBubble (float x, float y,
  71771. float w, float h,
  71772. float cs,
  71773. float tipX,
  71774. float tipY,
  71775. int whichSide,
  71776. float arrowPos,
  71777. float arrowWidth)
  71778. {
  71779. if (w > 1.0f && h > 1.0f)
  71780. {
  71781. cs = jmin (cs, w * 0.5f, h * 0.5f);
  71782. const float cs2 = 2.0f * cs;
  71783. startNewSubPath (x + cs, y);
  71784. if (whichSide == 0)
  71785. {
  71786. const float halfArrowW = jmin (arrowWidth, w - cs2) * 0.5f;
  71787. const float arrowX1 = x + cs + jmax (0.0f, (w - cs2) * arrowPos - halfArrowW);
  71788. lineTo (arrowX1, y);
  71789. lineTo (tipX, tipY);
  71790. lineTo (arrowX1 + halfArrowW * 2.0f, y);
  71791. }
  71792. lineTo (x + w - cs, y);
  71793. if (cs > 0.0f)
  71794. addArc (x + w - cs2, y, cs2, cs2, 0, float_Pi * 0.5f);
  71795. if (whichSide == 3)
  71796. {
  71797. const float halfArrowH = jmin (arrowWidth, h - cs2) * 0.5f;
  71798. const float arrowY1 = y + cs + jmax (0.0f, (h - cs2) * arrowPos - halfArrowH);
  71799. lineTo (x + w, arrowY1);
  71800. lineTo (tipX, tipY);
  71801. lineTo (x + w, arrowY1 + halfArrowH * 2.0f);
  71802. }
  71803. lineTo (x + w, y + h - cs);
  71804. if (cs > 0.0f)
  71805. addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
  71806. if (whichSide == 2)
  71807. {
  71808. const float halfArrowW = jmin (arrowWidth, w - cs2) * 0.5f;
  71809. const float arrowX1 = x + cs + jmax (0.0f, (w - cs2) * arrowPos - halfArrowW);
  71810. lineTo (arrowX1 + halfArrowW * 2.0f, y + h);
  71811. lineTo (tipX, tipY);
  71812. lineTo (arrowX1, y + h);
  71813. }
  71814. lineTo (x + cs, y + h);
  71815. if (cs > 0.0f)
  71816. addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
  71817. if (whichSide == 1)
  71818. {
  71819. const float halfArrowH = jmin (arrowWidth, h - cs2) * 0.5f;
  71820. const float arrowY1 = y + cs + jmax (0.0f, (h - cs2) * arrowPos - halfArrowH);
  71821. lineTo (x, arrowY1 + halfArrowH * 2.0f);
  71822. lineTo (tipX, tipY);
  71823. lineTo (x, arrowY1);
  71824. }
  71825. lineTo (x, y + cs);
  71826. if (cs > 0.0f)
  71827. addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f - ellipseAngularIncrement);
  71828. closeSubPath();
  71829. }
  71830. }
  71831. void Path::addPath (const Path& other) throw()
  71832. {
  71833. int i = 0;
  71834. while (i < other.numElements)
  71835. {
  71836. const float type = other.data.elements [i++];
  71837. if (type == moveMarker)
  71838. {
  71839. startNewSubPath (other.data.elements [i],
  71840. other.data.elements [i + 1]);
  71841. i += 2;
  71842. }
  71843. else if (type == lineMarker)
  71844. {
  71845. lineTo (other.data.elements [i],
  71846. other.data.elements [i + 1]);
  71847. i += 2;
  71848. }
  71849. else if (type == quadMarker)
  71850. {
  71851. quadraticTo (other.data.elements [i],
  71852. other.data.elements [i + 1],
  71853. other.data.elements [i + 2],
  71854. other.data.elements [i + 3]);
  71855. i += 4;
  71856. }
  71857. else if (type == cubicMarker)
  71858. {
  71859. cubicTo (other.data.elements [i],
  71860. other.data.elements [i + 1],
  71861. other.data.elements [i + 2],
  71862. other.data.elements [i + 3],
  71863. other.data.elements [i + 4],
  71864. other.data.elements [i + 5]);
  71865. i += 6;
  71866. }
  71867. else if (type == closeSubPathMarker)
  71868. {
  71869. closeSubPath();
  71870. }
  71871. else
  71872. {
  71873. // something's gone wrong with the element list!
  71874. jassertfalse
  71875. }
  71876. }
  71877. }
  71878. void Path::addPath (const Path& other,
  71879. const AffineTransform& transformToApply) throw()
  71880. {
  71881. int i = 0;
  71882. while (i < other.numElements)
  71883. {
  71884. const float type = other.data.elements [i++];
  71885. if (type == closeSubPathMarker)
  71886. {
  71887. closeSubPath();
  71888. }
  71889. else
  71890. {
  71891. float x = other.data.elements [i++];
  71892. float y = other.data.elements [i++];
  71893. transformToApply.transformPoint (x, y);
  71894. if (type == moveMarker)
  71895. {
  71896. startNewSubPath (x, y);
  71897. }
  71898. else if (type == lineMarker)
  71899. {
  71900. lineTo (x, y);
  71901. }
  71902. else if (type == quadMarker)
  71903. {
  71904. float x2 = other.data.elements [i++];
  71905. float y2 = other.data.elements [i++];
  71906. transformToApply.transformPoint (x2, y2);
  71907. quadraticTo (x, y, x2, y2);
  71908. }
  71909. else if (type == cubicMarker)
  71910. {
  71911. float x2 = other.data.elements [i++];
  71912. float y2 = other.data.elements [i++];
  71913. float x3 = other.data.elements [i++];
  71914. float y3 = other.data.elements [i++];
  71915. transformToApply.transformPoint (x2, y2);
  71916. transformToApply.transformPoint (x3, y3);
  71917. cubicTo (x, y, x2, y2, x3, y3);
  71918. }
  71919. else
  71920. {
  71921. // something's gone wrong with the element list!
  71922. jassertfalse
  71923. }
  71924. }
  71925. }
  71926. }
  71927. void Path::applyTransform (const AffineTransform& transform) throw()
  71928. {
  71929. int i = 0;
  71930. pathYMin = pathXMin = 0;
  71931. pathYMax = pathXMax = 0;
  71932. bool setMaxMin = false;
  71933. while (i < numElements)
  71934. {
  71935. const float type = data.elements [i++];
  71936. if (type == moveMarker)
  71937. {
  71938. transform.transformPoint (data.elements [i],
  71939. data.elements [i + 1]);
  71940. if (setMaxMin)
  71941. {
  71942. pathXMin = jmin (pathXMin, data.elements [i]);
  71943. pathXMax = jmax (pathXMax, data.elements [i]);
  71944. pathYMin = jmin (pathYMin, data.elements [i + 1]);
  71945. pathYMax = jmax (pathYMax, data.elements [i + 1]);
  71946. }
  71947. else
  71948. {
  71949. pathXMin = pathXMax = data.elements [i];
  71950. pathYMin = pathYMax = data.elements [i + 1];
  71951. setMaxMin = true;
  71952. }
  71953. i += 2;
  71954. }
  71955. else if (type == lineMarker)
  71956. {
  71957. transform.transformPoint (data.elements [i],
  71958. data.elements [i + 1]);
  71959. pathXMin = jmin (pathXMin, data.elements [i]);
  71960. pathXMax = jmax (pathXMax, data.elements [i]);
  71961. pathYMin = jmin (pathYMin, data.elements [i + 1]);
  71962. pathYMax = jmax (pathYMax, data.elements [i + 1]);
  71963. i += 2;
  71964. }
  71965. else if (type == quadMarker)
  71966. {
  71967. transform.transformPoint (data.elements [i],
  71968. data.elements [i + 1]);
  71969. transform.transformPoint (data.elements [i + 2],
  71970. data.elements [i + 3]);
  71971. pathXMin = jmin (pathXMin, data.elements [i], data.elements [i + 2]);
  71972. pathXMax = jmax (pathXMax, data.elements [i], data.elements [i + 2]);
  71973. pathYMin = jmin (pathYMin, data.elements [i + 1], data.elements [i + 3]);
  71974. pathYMax = jmax (pathYMax, data.elements [i + 1], data.elements [i + 3]);
  71975. i += 4;
  71976. }
  71977. else if (type == cubicMarker)
  71978. {
  71979. transform.transformPoint (data.elements [i],
  71980. data.elements [i + 1]);
  71981. transform.transformPoint (data.elements [i + 2],
  71982. data.elements [i + 3]);
  71983. transform.transformPoint (data.elements [i + 4],
  71984. data.elements [i + 5]);
  71985. pathXMin = jmin (pathXMin, data.elements [i], data.elements [i + 2], data.elements [i + 4]);
  71986. pathXMax = jmax (pathXMax, data.elements [i], data.elements [i + 2], data.elements [i + 4]);
  71987. pathYMin = jmin (pathYMin, data.elements [i + 1], data.elements [i + 3], data.elements [i + 5]);
  71988. pathYMax = jmax (pathYMax, data.elements [i + 1], data.elements [i + 3], data.elements [i + 5]);
  71989. i += 6;
  71990. }
  71991. }
  71992. }
  71993. const AffineTransform Path::getTransformToScaleToFit (const float x, const float y,
  71994. const float w, const float h,
  71995. const bool preserveProportions,
  71996. const Justification& justification) const throw()
  71997. {
  71998. Rectangle<float> bounds (getBounds());
  71999. if (preserveProportions)
  72000. {
  72001. if (w <= 0 || h <= 0 || bounds.isEmpty())
  72002. return AffineTransform::identity;
  72003. float newW, newH;
  72004. const float srcRatio = bounds.getHeight() / bounds.getWidth();
  72005. if (srcRatio > h / w)
  72006. {
  72007. newW = h / srcRatio;
  72008. newH = h;
  72009. }
  72010. else
  72011. {
  72012. newW = w;
  72013. newH = w * srcRatio;
  72014. }
  72015. float newXCentre = x;
  72016. float newYCentre = y;
  72017. if (justification.testFlags (Justification::left))
  72018. newXCentre += newW * 0.5f;
  72019. else if (justification.testFlags (Justification::right))
  72020. newXCentre += w - newW * 0.5f;
  72021. else
  72022. newXCentre += w * 0.5f;
  72023. if (justification.testFlags (Justification::top))
  72024. newYCentre += newH * 0.5f;
  72025. else if (justification.testFlags (Justification::bottom))
  72026. newYCentre += h - newH * 0.5f;
  72027. else
  72028. newYCentre += h * 0.5f;
  72029. return AffineTransform::translation (bounds.getWidth() * -0.5f - bounds.getX(),
  72030. bounds.getHeight() * -0.5f - bounds.getY())
  72031. .scaled (newW / bounds.getWidth(), newH / bounds.getHeight())
  72032. .translated (newXCentre, newYCentre);
  72033. }
  72034. else
  72035. {
  72036. return AffineTransform::translation (-bounds.getX(), -bounds.getY())
  72037. .scaled (w / bounds.getWidth(), h / bounds.getHeight())
  72038. .translated (x, y);
  72039. }
  72040. }
  72041. bool Path::contains (const float x, const float y, const float tolerence) const throw()
  72042. {
  72043. if (x <= pathXMin || x >= pathXMax
  72044. || y <= pathYMin || y >= pathYMax)
  72045. return false;
  72046. PathFlatteningIterator i (*this, AffineTransform::identity, tolerence);
  72047. int positiveCrossings = 0;
  72048. int negativeCrossings = 0;
  72049. while (i.next())
  72050. {
  72051. if ((i.y1 <= y && i.y2 > y)
  72052. || (i.y2 <= y && i.y1 > y))
  72053. {
  72054. const float intersectX = i.x1 + (i.x2 - i.x1) * (y - i.y1) / (i.y2 - i.y1);
  72055. if (intersectX <= x)
  72056. {
  72057. if (i.y1 < i.y2)
  72058. ++positiveCrossings;
  72059. else
  72060. ++negativeCrossings;
  72061. }
  72062. }
  72063. }
  72064. return (useNonZeroWinding) ? (negativeCrossings != positiveCrossings)
  72065. : ((negativeCrossings + positiveCrossings) & 1) != 0;
  72066. }
  72067. bool Path::intersectsLine (const float x1, const float y1,
  72068. const float x2, const float y2,
  72069. const float tolerence) throw()
  72070. {
  72071. PathFlatteningIterator i (*this, AffineTransform::identity, tolerence);
  72072. const Line line1 (x1, y1, x2, y2);
  72073. while (i.next())
  72074. {
  72075. const Line line2 (i.x1, i.y1, i.x2, i.y2);
  72076. float ix, iy;
  72077. if (line1.intersects (line2, ix, iy))
  72078. return true;
  72079. }
  72080. return false;
  72081. }
  72082. const Path Path::createPathWithRoundedCorners (const float cornerRadius) const throw()
  72083. {
  72084. if (cornerRadius <= 0.01f)
  72085. return *this;
  72086. int indexOfPathStart = 0, indexOfPathStartThis = 0;
  72087. int n = 0;
  72088. bool lastWasLine = false, firstWasLine = false;
  72089. Path p;
  72090. while (n < numElements)
  72091. {
  72092. const float type = data.elements [n++];
  72093. if (type == moveMarker)
  72094. {
  72095. indexOfPathStart = p.numElements;
  72096. indexOfPathStartThis = n - 1;
  72097. const float x = data.elements [n++];
  72098. const float y = data.elements [n++];
  72099. p.startNewSubPath (x, y);
  72100. lastWasLine = false;
  72101. firstWasLine = (data.elements [n] == lineMarker);
  72102. }
  72103. else if (type == lineMarker || type == closeSubPathMarker)
  72104. {
  72105. float startX = 0, startY = 0, joinX = 0, joinY = 0, endX, endY;
  72106. if (type == lineMarker)
  72107. {
  72108. endX = data.elements [n++];
  72109. endY = data.elements [n++];
  72110. if (n > 8)
  72111. {
  72112. startX = data.elements [n - 8];
  72113. startY = data.elements [n - 7];
  72114. joinX = data.elements [n - 5];
  72115. joinY = data.elements [n - 4];
  72116. }
  72117. }
  72118. else
  72119. {
  72120. endX = data.elements [indexOfPathStartThis + 1];
  72121. endY = data.elements [indexOfPathStartThis + 2];
  72122. if (n > 6)
  72123. {
  72124. startX = data.elements [n - 6];
  72125. startY = data.elements [n - 5];
  72126. joinX = data.elements [n - 3];
  72127. joinY = data.elements [n - 2];
  72128. }
  72129. }
  72130. if (lastWasLine)
  72131. {
  72132. const double len1 = juce_hypot (startX - joinX,
  72133. startY - joinY);
  72134. if (len1 > 0)
  72135. {
  72136. const double propNeeded = jmin (0.5, cornerRadius / len1);
  72137. p.data.elements [p.numElements - 2] = (float) (joinX - (joinX - startX) * propNeeded);
  72138. p.data.elements [p.numElements - 1] = (float) (joinY - (joinY - startY) * propNeeded);
  72139. }
  72140. const double len2 = juce_hypot (endX - joinX,
  72141. endY - joinY);
  72142. if (len2 > 0)
  72143. {
  72144. const double propNeeded = jmin (0.5, cornerRadius / len2);
  72145. p.quadraticTo (joinX, joinY,
  72146. (float) (joinX + (endX - joinX) * propNeeded),
  72147. (float) (joinY + (endY - joinY) * propNeeded));
  72148. }
  72149. p.lineTo (endX, endY);
  72150. }
  72151. else if (type == lineMarker)
  72152. {
  72153. p.lineTo (endX, endY);
  72154. lastWasLine = true;
  72155. }
  72156. if (type == closeSubPathMarker)
  72157. {
  72158. if (firstWasLine)
  72159. {
  72160. startX = data.elements [n - 3];
  72161. startY = data.elements [n - 2];
  72162. joinX = endX;
  72163. joinY = endY;
  72164. endX = data.elements [indexOfPathStartThis + 4];
  72165. endY = data.elements [indexOfPathStartThis + 5];
  72166. const double len1 = juce_hypot (startX - joinX,
  72167. startY - joinY);
  72168. if (len1 > 0)
  72169. {
  72170. const double propNeeded = jmin (0.5, cornerRadius / len1);
  72171. p.data.elements [p.numElements - 2] = (float) (joinX - (joinX - startX) * propNeeded);
  72172. p.data.elements [p.numElements - 1] = (float) (joinY - (joinY - startY) * propNeeded);
  72173. }
  72174. const double len2 = juce_hypot (endX - joinX,
  72175. endY - joinY);
  72176. if (len2 > 0)
  72177. {
  72178. const double propNeeded = jmin (0.5, cornerRadius / len2);
  72179. endX = (float) (joinX + (endX - joinX) * propNeeded);
  72180. endY = (float) (joinY + (endY - joinY) * propNeeded);
  72181. p.quadraticTo (joinX, joinY, endX, endY);
  72182. p.data.elements [indexOfPathStart + 1] = endX;
  72183. p.data.elements [indexOfPathStart + 2] = endY;
  72184. }
  72185. }
  72186. p.closeSubPath();
  72187. }
  72188. }
  72189. else if (type == quadMarker)
  72190. {
  72191. lastWasLine = false;
  72192. const float x1 = data.elements [n++];
  72193. const float y1 = data.elements [n++];
  72194. const float x2 = data.elements [n++];
  72195. const float y2 = data.elements [n++];
  72196. p.quadraticTo (x1, y1, x2, y2);
  72197. }
  72198. else if (type == cubicMarker)
  72199. {
  72200. lastWasLine = false;
  72201. const float x1 = data.elements [n++];
  72202. const float y1 = data.elements [n++];
  72203. const float x2 = data.elements [n++];
  72204. const float y2 = data.elements [n++];
  72205. const float x3 = data.elements [n++];
  72206. const float y3 = data.elements [n++];
  72207. p.cubicTo (x1, y1, x2, y2, x3, y3);
  72208. }
  72209. }
  72210. return p;
  72211. }
  72212. void Path::loadPathFromStream (InputStream& source)
  72213. {
  72214. while (! source.isExhausted())
  72215. {
  72216. switch (source.readByte())
  72217. {
  72218. case 'm':
  72219. {
  72220. const float x = source.readFloat();
  72221. const float y = source.readFloat();
  72222. startNewSubPath (x, y);
  72223. break;
  72224. }
  72225. case 'l':
  72226. {
  72227. const float x = source.readFloat();
  72228. const float y = source.readFloat();
  72229. lineTo (x, y);
  72230. break;
  72231. }
  72232. case 'q':
  72233. {
  72234. const float x1 = source.readFloat();
  72235. const float y1 = source.readFloat();
  72236. const float x2 = source.readFloat();
  72237. const float y2 = source.readFloat();
  72238. quadraticTo (x1, y1, x2, y2);
  72239. break;
  72240. }
  72241. case 'b':
  72242. {
  72243. const float x1 = source.readFloat();
  72244. const float y1 = source.readFloat();
  72245. const float x2 = source.readFloat();
  72246. const float y2 = source.readFloat();
  72247. const float x3 = source.readFloat();
  72248. const float y3 = source.readFloat();
  72249. cubicTo (x1, y1, x2, y2, x3, y3);
  72250. break;
  72251. }
  72252. case 'c':
  72253. closeSubPath();
  72254. break;
  72255. case 'n':
  72256. useNonZeroWinding = true;
  72257. break;
  72258. case 'z':
  72259. useNonZeroWinding = false;
  72260. break;
  72261. case 'e':
  72262. return; // end of path marker
  72263. default:
  72264. jassertfalse // illegal char in the stream
  72265. break;
  72266. }
  72267. }
  72268. }
  72269. void Path::loadPathFromData (const unsigned char* const data,
  72270. const int numberOfBytes) throw()
  72271. {
  72272. MemoryInputStream in ((const char*) data, numberOfBytes, false);
  72273. loadPathFromStream (in);
  72274. }
  72275. void Path::writePathToStream (OutputStream& dest) const
  72276. {
  72277. dest.writeByte ((useNonZeroWinding) ? 'n' : 'z');
  72278. int i = 0;
  72279. while (i < numElements)
  72280. {
  72281. const float type = data.elements [i++];
  72282. if (type == moveMarker)
  72283. {
  72284. dest.writeByte ('m');
  72285. dest.writeFloat (data.elements [i++]);
  72286. dest.writeFloat (data.elements [i++]);
  72287. }
  72288. else if (type == lineMarker)
  72289. {
  72290. dest.writeByte ('l');
  72291. dest.writeFloat (data.elements [i++]);
  72292. dest.writeFloat (data.elements [i++]);
  72293. }
  72294. else if (type == quadMarker)
  72295. {
  72296. dest.writeByte ('q');
  72297. dest.writeFloat (data.elements [i++]);
  72298. dest.writeFloat (data.elements [i++]);
  72299. dest.writeFloat (data.elements [i++]);
  72300. dest.writeFloat (data.elements [i++]);
  72301. }
  72302. else if (type == cubicMarker)
  72303. {
  72304. dest.writeByte ('b');
  72305. dest.writeFloat (data.elements [i++]);
  72306. dest.writeFloat (data.elements [i++]);
  72307. dest.writeFloat (data.elements [i++]);
  72308. dest.writeFloat (data.elements [i++]);
  72309. dest.writeFloat (data.elements [i++]);
  72310. dest.writeFloat (data.elements [i++]);
  72311. }
  72312. else if (type == closeSubPathMarker)
  72313. {
  72314. dest.writeByte ('c');
  72315. }
  72316. }
  72317. dest.writeByte ('e'); // marks the end-of-path
  72318. }
  72319. const String Path::toString() const
  72320. {
  72321. MemoryOutputStream s (2048, 2048);
  72322. if (! useNonZeroWinding)
  72323. s << "a ";
  72324. int i = 0;
  72325. float lastMarker = 0.0f;
  72326. while (i < numElements)
  72327. {
  72328. const float marker = data.elements [i++];
  72329. char markerChar = 0;
  72330. int numCoords = 0;
  72331. if (marker == moveMarker)
  72332. {
  72333. markerChar = 'm';
  72334. numCoords = 2;
  72335. }
  72336. else if (marker == lineMarker)
  72337. {
  72338. markerChar = 'l';
  72339. numCoords = 2;
  72340. }
  72341. else if (marker == quadMarker)
  72342. {
  72343. markerChar = 'q';
  72344. numCoords = 4;
  72345. }
  72346. else if (marker == cubicMarker)
  72347. {
  72348. markerChar = 'c';
  72349. numCoords = 6;
  72350. }
  72351. else
  72352. {
  72353. jassert (marker == closeSubPathMarker);
  72354. markerChar = 'z';
  72355. }
  72356. if (marker != lastMarker)
  72357. {
  72358. s << markerChar << ' ';
  72359. lastMarker = marker;
  72360. }
  72361. while (--numCoords >= 0 && i < numElements)
  72362. {
  72363. String n (data.elements [i++], 3);
  72364. if (n.endsWithChar (T('0')))
  72365. {
  72366. do
  72367. {
  72368. n = n.dropLastCharacters (1);
  72369. } while (n.endsWithChar (T('0')));
  72370. if (n.endsWithChar (T('.')))
  72371. n = n.dropLastCharacters (1);
  72372. }
  72373. s << n << ' ';
  72374. }
  72375. }
  72376. const char* const result = (const char*) s.getData();
  72377. size_t len = s.getDataSize();
  72378. while (len > 0 && CharacterFunctions::isWhitespace (result [len - 1]))
  72379. --len;
  72380. return String (result, len);
  72381. }
  72382. static const String nextToken (const tchar*& t)
  72383. {
  72384. while (CharacterFunctions::isWhitespace (*t))
  72385. ++t;
  72386. const tchar* const start = t;
  72387. while (*t != 0 && ! CharacterFunctions::isWhitespace (*t))
  72388. ++t;
  72389. const int length = (int) (t - start);
  72390. while (CharacterFunctions::isWhitespace (*t))
  72391. ++t;
  72392. return String (start, length);
  72393. }
  72394. void Path::restoreFromString (const String& stringVersion)
  72395. {
  72396. clear();
  72397. setUsingNonZeroWinding (true);
  72398. const tchar* t = stringVersion;
  72399. tchar marker = T('m');
  72400. int numValues = 2;
  72401. float values [6];
  72402. while (*t != 0)
  72403. {
  72404. const String token (nextToken (t));
  72405. const tchar firstChar = token[0];
  72406. int startNum = 0;
  72407. if (firstChar == T('m') || firstChar == T('l'))
  72408. {
  72409. marker = firstChar;
  72410. numValues = 2;
  72411. }
  72412. else if (firstChar == T('q'))
  72413. {
  72414. marker = firstChar;
  72415. numValues = 4;
  72416. }
  72417. else if (firstChar == T('c'))
  72418. {
  72419. marker = firstChar;
  72420. numValues = 6;
  72421. }
  72422. else if (firstChar == T('z'))
  72423. {
  72424. marker = firstChar;
  72425. numValues = 0;
  72426. }
  72427. else if (firstChar == T('a'))
  72428. {
  72429. setUsingNonZeroWinding (false);
  72430. continue;
  72431. }
  72432. else
  72433. {
  72434. ++startNum;
  72435. values [0] = token.getFloatValue();
  72436. }
  72437. for (int i = startNum; i < numValues; ++i)
  72438. values [i] = nextToken (t).getFloatValue();
  72439. switch (marker)
  72440. {
  72441. case T('m'):
  72442. startNewSubPath (values[0], values[1]);
  72443. break;
  72444. case T('l'):
  72445. lineTo (values[0], values[1]);
  72446. break;
  72447. case T('q'):
  72448. quadraticTo (values[0], values[1],
  72449. values[2], values[3]);
  72450. break;
  72451. case T('c'):
  72452. cubicTo (values[0], values[1],
  72453. values[2], values[3],
  72454. values[4], values[5]);
  72455. break;
  72456. case T('z'):
  72457. closeSubPath();
  72458. break;
  72459. default:
  72460. jassertfalse // illegal string format?
  72461. break;
  72462. }
  72463. }
  72464. }
  72465. Path::Iterator::Iterator (const Path& path_)
  72466. : path (path_),
  72467. index (0)
  72468. {
  72469. }
  72470. Path::Iterator::~Iterator()
  72471. {
  72472. }
  72473. bool Path::Iterator::next()
  72474. {
  72475. const float* const elements = path.data.elements;
  72476. if (index < path.numElements)
  72477. {
  72478. const float type = elements [index++];
  72479. if (type == moveMarker)
  72480. {
  72481. elementType = startNewSubPath;
  72482. x1 = elements [index++];
  72483. y1 = elements [index++];
  72484. }
  72485. else if (type == lineMarker)
  72486. {
  72487. elementType = lineTo;
  72488. x1 = elements [index++];
  72489. y1 = elements [index++];
  72490. }
  72491. else if (type == quadMarker)
  72492. {
  72493. elementType = quadraticTo;
  72494. x1 = elements [index++];
  72495. y1 = elements [index++];
  72496. x2 = elements [index++];
  72497. y2 = elements [index++];
  72498. }
  72499. else if (type == cubicMarker)
  72500. {
  72501. elementType = cubicTo;
  72502. x1 = elements [index++];
  72503. y1 = elements [index++];
  72504. x2 = elements [index++];
  72505. y2 = elements [index++];
  72506. x3 = elements [index++];
  72507. y3 = elements [index++];
  72508. }
  72509. else if (type == closeSubPathMarker)
  72510. {
  72511. elementType = closePath;
  72512. }
  72513. return true;
  72514. }
  72515. return false;
  72516. }
  72517. END_JUCE_NAMESPACE
  72518. /*** End of inlined file: juce_Path.cpp ***/
  72519. /*** Start of inlined file: juce_PathIterator.cpp ***/
  72520. BEGIN_JUCE_NAMESPACE
  72521. #if JUCE_MSVC
  72522. #pragma optimize ("t", on)
  72523. #endif
  72524. PathFlatteningIterator::PathFlatteningIterator (const Path& path_,
  72525. const AffineTransform& transform_,
  72526. float tolerence_) throw()
  72527. : x2 (0),
  72528. y2 (0),
  72529. closesSubPath (false),
  72530. subPathIndex (-1),
  72531. path (path_),
  72532. transform (transform_),
  72533. points (path_.data.elements),
  72534. tolerence (tolerence_ * tolerence_),
  72535. subPathCloseX (0),
  72536. subPathCloseY (0),
  72537. stackBase (32),
  72538. index (0),
  72539. stackSize (32)
  72540. {
  72541. isIdentityTransform = transform.isIdentity();
  72542. stackPos = stackBase;
  72543. }
  72544. PathFlatteningIterator::~PathFlatteningIterator() throw()
  72545. {
  72546. }
  72547. bool PathFlatteningIterator::next() throw()
  72548. {
  72549. x1 = x2;
  72550. y1 = y2;
  72551. float x3 = 0;
  72552. float y3 = 0;
  72553. float x4 = 0;
  72554. float y4 = 0;
  72555. float type;
  72556. for (;;)
  72557. {
  72558. if (stackPos == stackBase)
  72559. {
  72560. if (index >= path.numElements)
  72561. {
  72562. return false;
  72563. }
  72564. else
  72565. {
  72566. type = points [index++];
  72567. if (type != Path::closeSubPathMarker)
  72568. {
  72569. x2 = points [index++];
  72570. y2 = points [index++];
  72571. if (! isIdentityTransform)
  72572. transform.transformPoint (x2, y2);
  72573. if (type == Path::quadMarker)
  72574. {
  72575. x3 = points [index++];
  72576. y3 = points [index++];
  72577. if (! isIdentityTransform)
  72578. transform.transformPoint (x3, y3);
  72579. }
  72580. else if (type == Path::cubicMarker)
  72581. {
  72582. x3 = points [index++];
  72583. y3 = points [index++];
  72584. x4 = points [index++];
  72585. y4 = points [index++];
  72586. if (! isIdentityTransform)
  72587. {
  72588. transform.transformPoint (x3, y3);
  72589. transform.transformPoint (x4, y4);
  72590. }
  72591. }
  72592. }
  72593. }
  72594. }
  72595. else
  72596. {
  72597. type = *--stackPos;
  72598. if (type != Path::closeSubPathMarker)
  72599. {
  72600. x2 = *--stackPos;
  72601. y2 = *--stackPos;
  72602. if (type == Path::quadMarker)
  72603. {
  72604. x3 = *--stackPos;
  72605. y3 = *--stackPos;
  72606. }
  72607. else if (type == Path::cubicMarker)
  72608. {
  72609. x3 = *--stackPos;
  72610. y3 = *--stackPos;
  72611. x4 = *--stackPos;
  72612. y4 = *--stackPos;
  72613. }
  72614. }
  72615. }
  72616. if (type == Path::lineMarker)
  72617. {
  72618. ++subPathIndex;
  72619. closesSubPath = (stackPos == stackBase)
  72620. && (index < path.numElements)
  72621. && (points [index] == Path::closeSubPathMarker)
  72622. && x2 == subPathCloseX
  72623. && y2 == subPathCloseY;
  72624. return true;
  72625. }
  72626. else if (type == Path::quadMarker)
  72627. {
  72628. const int offset = (int) (stackPos - stackBase);
  72629. if (offset >= stackSize - 10)
  72630. {
  72631. stackSize <<= 1;
  72632. stackBase.realloc (stackSize);
  72633. stackPos = stackBase + offset;
  72634. }
  72635. const float dx1 = x1 - x2;
  72636. const float dy1 = y1 - y2;
  72637. const float dx2 = x2 - x3;
  72638. const float dy2 = y2 - y3;
  72639. const float m1x = (x1 + x2) * 0.5f;
  72640. const float m1y = (y1 + y2) * 0.5f;
  72641. const float m2x = (x2 + x3) * 0.5f;
  72642. const float m2y = (y2 + y3) * 0.5f;
  72643. const float m3x = (m1x + m2x) * 0.5f;
  72644. const float m3y = (m1y + m2y) * 0.5f;
  72645. if (dx1*dx1 + dy1*dy1 + dx2*dx2 + dy2*dy2 > tolerence)
  72646. {
  72647. *stackPos++ = y3;
  72648. *stackPos++ = x3;
  72649. *stackPos++ = m2y;
  72650. *stackPos++ = m2x;
  72651. *stackPos++ = Path::quadMarker;
  72652. *stackPos++ = m3y;
  72653. *stackPos++ = m3x;
  72654. *stackPos++ = m1y;
  72655. *stackPos++ = m1x;
  72656. *stackPos++ = Path::quadMarker;
  72657. }
  72658. else
  72659. {
  72660. *stackPos++ = y3;
  72661. *stackPos++ = x3;
  72662. *stackPos++ = Path::lineMarker;
  72663. *stackPos++ = m3y;
  72664. *stackPos++ = m3x;
  72665. *stackPos++ = Path::lineMarker;
  72666. }
  72667. jassert (stackPos < stackBase + stackSize);
  72668. }
  72669. else if (type == Path::cubicMarker)
  72670. {
  72671. const int offset = (int) (stackPos - stackBase);
  72672. if (offset >= stackSize - 16)
  72673. {
  72674. stackSize <<= 1;
  72675. stackBase.realloc (stackSize);
  72676. stackPos = stackBase + offset;
  72677. }
  72678. const float dx1 = x1 - x2;
  72679. const float dy1 = y1 - y2;
  72680. const float dx2 = x2 - x3;
  72681. const float dy2 = y2 - y3;
  72682. const float dx3 = x3 - x4;
  72683. const float dy3 = y3 - y4;
  72684. const float m1x = (x1 + x2) * 0.5f;
  72685. const float m1y = (y1 + y2) * 0.5f;
  72686. const float m2x = (x3 + x2) * 0.5f;
  72687. const float m2y = (y3 + y2) * 0.5f;
  72688. const float m3x = (x3 + x4) * 0.5f;
  72689. const float m3y = (y3 + y4) * 0.5f;
  72690. const float m4x = (m1x + m2x) * 0.5f;
  72691. const float m4y = (m1y + m2y) * 0.5f;
  72692. const float m5x = (m3x + m2x) * 0.5f;
  72693. const float m5y = (m3y + m2y) * 0.5f;
  72694. if (dx1*dx1 + dy1*dy1 + dx2*dx2
  72695. + dy2*dy2 + dx3*dx3 + dy3*dy3 > tolerence)
  72696. {
  72697. *stackPos++ = y4;
  72698. *stackPos++ = x4;
  72699. *stackPos++ = m3y;
  72700. *stackPos++ = m3x;
  72701. *stackPos++ = m5y;
  72702. *stackPos++ = m5x;
  72703. *stackPos++ = Path::cubicMarker;
  72704. *stackPos++ = (m4y + m5y) * 0.5f;
  72705. *stackPos++ = (m4x + m5x) * 0.5f;
  72706. *stackPos++ = m4y;
  72707. *stackPos++ = m4x;
  72708. *stackPos++ = m1y;
  72709. *stackPos++ = m1x;
  72710. *stackPos++ = Path::cubicMarker;
  72711. }
  72712. else
  72713. {
  72714. *stackPos++ = y4;
  72715. *stackPos++ = x4;
  72716. *stackPos++ = Path::lineMarker;
  72717. *stackPos++ = m5y;
  72718. *stackPos++ = m5x;
  72719. *stackPos++ = Path::lineMarker;
  72720. *stackPos++ = m4y;
  72721. *stackPos++ = m4x;
  72722. *stackPos++ = Path::lineMarker;
  72723. }
  72724. }
  72725. else if (type == Path::closeSubPathMarker)
  72726. {
  72727. if (x2 != subPathCloseX || y2 != subPathCloseY)
  72728. {
  72729. x1 = x2;
  72730. y1 = y2;
  72731. x2 = subPathCloseX;
  72732. y2 = subPathCloseY;
  72733. closesSubPath = true;
  72734. return true;
  72735. }
  72736. }
  72737. else
  72738. {
  72739. jassert (type == Path::moveMarker);
  72740. subPathIndex = -1;
  72741. subPathCloseX = x1 = x2;
  72742. subPathCloseY = y1 = y2;
  72743. }
  72744. }
  72745. }
  72746. END_JUCE_NAMESPACE
  72747. /*** End of inlined file: juce_PathIterator.cpp ***/
  72748. /*** Start of inlined file: juce_PathStrokeType.cpp ***/
  72749. BEGIN_JUCE_NAMESPACE
  72750. PathStrokeType::PathStrokeType (const float strokeThickness,
  72751. const JointStyle jointStyle_,
  72752. const EndCapStyle endStyle_) throw()
  72753. : thickness (strokeThickness),
  72754. jointStyle (jointStyle_),
  72755. endStyle (endStyle_)
  72756. {
  72757. }
  72758. PathStrokeType::PathStrokeType (const PathStrokeType& other) throw()
  72759. : thickness (other.thickness),
  72760. jointStyle (other.jointStyle),
  72761. endStyle (other.endStyle)
  72762. {
  72763. }
  72764. const PathStrokeType& PathStrokeType::operator= (const PathStrokeType& other) throw()
  72765. {
  72766. thickness = other.thickness;
  72767. jointStyle = other.jointStyle;
  72768. endStyle = other.endStyle;
  72769. return *this;
  72770. }
  72771. PathStrokeType::~PathStrokeType() throw()
  72772. {
  72773. }
  72774. bool PathStrokeType::operator== (const PathStrokeType& other) const throw()
  72775. {
  72776. return thickness == other.thickness
  72777. && jointStyle == other.jointStyle
  72778. && endStyle == other.endStyle;
  72779. }
  72780. bool PathStrokeType::operator!= (const PathStrokeType& other) const throw()
  72781. {
  72782. return ! operator== (other);
  72783. }
  72784. static bool lineIntersection (const float x1, const float y1,
  72785. const float x2, const float y2,
  72786. const float x3, const float y3,
  72787. const float x4, const float y4,
  72788. float& intersectionX,
  72789. float& intersectionY,
  72790. float& distanceBeyondLine1EndSquared) throw()
  72791. {
  72792. if (x2 != x3 || y2 != y3)
  72793. {
  72794. const float dx1 = x2 - x1;
  72795. const float dy1 = y2 - y1;
  72796. const float dx2 = x4 - x3;
  72797. const float dy2 = y4 - y3;
  72798. const float divisor = dx1 * dy2 - dx2 * dy1;
  72799. if (divisor == 0)
  72800. {
  72801. if (! ((dx1 == 0 && dy1 == 0) || (dx2 == 0 && dy2 == 0)))
  72802. {
  72803. if (dy1 == 0 && dy2 != 0)
  72804. {
  72805. const float along = (y1 - y3) / dy2;
  72806. intersectionX = x3 + along * dx2;
  72807. intersectionY = y1;
  72808. distanceBeyondLine1EndSquared = intersectionX - x2;
  72809. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72810. if ((x2 > x1) == (intersectionX < x2))
  72811. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72812. return along >= 0 && along <= 1.0f;
  72813. }
  72814. else if (dy2 == 0 && dy1 != 0)
  72815. {
  72816. const float along = (y3 - y1) / dy1;
  72817. intersectionX = x1 + along * dx1;
  72818. intersectionY = y3;
  72819. distanceBeyondLine1EndSquared = (along - 1.0f) * dx1;
  72820. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72821. if (along < 1.0f)
  72822. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72823. return along >= 0 && along <= 1.0f;
  72824. }
  72825. else if (dx1 == 0 && dx2 != 0)
  72826. {
  72827. const float along = (x1 - x3) / dx2;
  72828. intersectionX = x1;
  72829. intersectionY = y3 + along * dy2;
  72830. distanceBeyondLine1EndSquared = intersectionY - y2;
  72831. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72832. if ((y2 > y1) == (intersectionY < y2))
  72833. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72834. return along >= 0 && along <= 1.0f;
  72835. }
  72836. else if (dx2 == 0 && dx1 != 0)
  72837. {
  72838. const float along = (x3 - x1) / dx1;
  72839. intersectionX = x3;
  72840. intersectionY = y1 + along * dy1;
  72841. distanceBeyondLine1EndSquared = (along - 1.0f) * dy1;
  72842. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72843. if (along < 1.0f)
  72844. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72845. return along >= 0 && along <= 1.0f;
  72846. }
  72847. }
  72848. intersectionX = 0.5f * (x2 + x3);
  72849. intersectionY = 0.5f * (y2 + y3);
  72850. distanceBeyondLine1EndSquared = 0.0f;
  72851. return false;
  72852. }
  72853. else
  72854. {
  72855. const float along1 = ((y1 - y3) * dx2 - (x1 - x3) * dy2) / divisor;
  72856. intersectionX = x1 + along1 * dx1;
  72857. intersectionY = y1 + along1 * dy1;
  72858. if (along1 >= 0 && along1 <= 1.0f)
  72859. {
  72860. const float along2 = ((y1 - y3) * dx1 - (x1 - x3) * dy1);
  72861. if (along2 >= 0 && along2 <= divisor)
  72862. {
  72863. distanceBeyondLine1EndSquared = 0.0f;
  72864. return true;
  72865. }
  72866. }
  72867. distanceBeyondLine1EndSquared = along1 - 1.0f;
  72868. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72869. distanceBeyondLine1EndSquared *= (dx1 * dx1 + dy1 * dy1);
  72870. if (along1 < 1.0f)
  72871. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72872. return false;
  72873. }
  72874. }
  72875. intersectionX = x2;
  72876. intersectionY = y2;
  72877. distanceBeyondLine1EndSquared = 0.0f;
  72878. return true;
  72879. }
  72880. // part of stroke drawing stuff
  72881. static void addEdgeAndJoint (Path& destPath,
  72882. const PathStrokeType::JointStyle style,
  72883. const float maxMiterExtensionSquared, const float width,
  72884. const float x1, const float y1,
  72885. const float x2, const float y2,
  72886. const float x3, const float y3,
  72887. const float x4, const float y4,
  72888. const float midX, const float midY) throw()
  72889. {
  72890. if (style == PathStrokeType::beveled
  72891. || (x3 == x4 && y3 == y4)
  72892. || (x1 == x2 && y1 == y2))
  72893. {
  72894. destPath.lineTo (x2, y2);
  72895. destPath.lineTo (x3, y3);
  72896. }
  72897. else
  72898. {
  72899. float jx, jy, distanceBeyondLine1EndSquared;
  72900. // if they intersect, use this point..
  72901. if (lineIntersection (x1, y1, x2, y2,
  72902. x3, y3, x4, y4,
  72903. jx, jy, distanceBeyondLine1EndSquared))
  72904. {
  72905. destPath.lineTo (jx, jy);
  72906. }
  72907. else
  72908. {
  72909. if (style == PathStrokeType::mitered)
  72910. {
  72911. if (distanceBeyondLine1EndSquared < maxMiterExtensionSquared
  72912. && distanceBeyondLine1EndSquared > 0.0f)
  72913. {
  72914. destPath.lineTo (jx, jy);
  72915. }
  72916. else
  72917. {
  72918. // the end sticks out too far, so just use a blunt joint
  72919. destPath.lineTo (x2, y2);
  72920. destPath.lineTo (x3, y3);
  72921. }
  72922. }
  72923. else
  72924. {
  72925. // curved joints
  72926. float angle1 = atan2f (x2 - midX, y2 - midY);
  72927. float angle2 = atan2f (x3 - midX, y3 - midY);
  72928. const float angleIncrement = 0.1f;
  72929. destPath.lineTo (x2, y2);
  72930. if (fabs (angle1 - angle2) > angleIncrement)
  72931. {
  72932. if (angle2 > angle1 + float_Pi
  72933. || (angle2 < angle1 && angle2 >= angle1 - float_Pi))
  72934. {
  72935. if (angle2 > angle1)
  72936. angle2 -= float_Pi * 2.0f;
  72937. jassert (angle1 <= angle2 + float_Pi);
  72938. angle1 -= angleIncrement;
  72939. while (angle1 > angle2)
  72940. {
  72941. destPath.lineTo (midX + width * sinf (angle1),
  72942. midY + width * cosf (angle1));
  72943. angle1 -= angleIncrement;
  72944. }
  72945. }
  72946. else
  72947. {
  72948. if (angle1 > angle2)
  72949. angle1 -= float_Pi * 2.0f;
  72950. jassert (angle1 >= angle2 - float_Pi);
  72951. angle1 += angleIncrement;
  72952. while (angle1 < angle2)
  72953. {
  72954. destPath.lineTo (midX + width * sinf (angle1),
  72955. midY + width * cosf (angle1));
  72956. angle1 += angleIncrement;
  72957. }
  72958. }
  72959. }
  72960. destPath.lineTo (x3, y3);
  72961. }
  72962. }
  72963. }
  72964. }
  72965. static inline void addLineEnd (Path& destPath,
  72966. const PathStrokeType::EndCapStyle style,
  72967. const float x1, const float y1,
  72968. const float x2, const float y2,
  72969. const float width) throw()
  72970. {
  72971. if (style == PathStrokeType::butt)
  72972. {
  72973. destPath.lineTo (x2, y2);
  72974. }
  72975. else
  72976. {
  72977. float offx1, offy1, offx2, offy2;
  72978. float dx = x2 - x1;
  72979. float dy = y2 - y1;
  72980. const float len = juce_hypotf (dx, dy);
  72981. if (len == 0)
  72982. {
  72983. offx1 = offx2 = x1;
  72984. offy1 = offy2 = y1;
  72985. }
  72986. else
  72987. {
  72988. const float offset = width / len;
  72989. dx *= offset;
  72990. dy *= offset;
  72991. offx1 = x1 + dy;
  72992. offy1 = y1 - dx;
  72993. offx2 = x2 + dy;
  72994. offy2 = y2 - dx;
  72995. }
  72996. if (style == PathStrokeType::square)
  72997. {
  72998. // sqaure ends
  72999. destPath.lineTo (offx1, offy1);
  73000. destPath.lineTo (offx2, offy2);
  73001. destPath.lineTo (x2, y2);
  73002. }
  73003. else
  73004. {
  73005. // rounded ends
  73006. const float midx = (offx1 + offx2) * 0.5f;
  73007. const float midy = (offy1 + offy2) * 0.5f;
  73008. destPath.cubicTo (x1 + (offx1 - x1) * 0.55f, y1 + (offy1 - y1) * 0.55f,
  73009. offx1 + (midx - offx1) * 0.45f, offy1 + (midy - offy1) * 0.45f,
  73010. midx, midy);
  73011. destPath.cubicTo (midx + (offx2 - midx) * 0.55f, midy + (offy2 - midy) * 0.55f,
  73012. offx2 + (x2 - offx2) * 0.45f, offy2 + (y2 - offy2) * 0.45f,
  73013. x2, y2);
  73014. }
  73015. }
  73016. }
  73017. struct LineSection
  73018. {
  73019. LineSection() {}
  73020. LineSection (int) {}
  73021. float x1, y1, x2, y2; // original line
  73022. float lx1, ly1, lx2, ly2; // the left-hand stroke
  73023. float rx1, ry1, rx2, ry2; // the right-hand stroke
  73024. };
  73025. static void addSubPath (Path& destPath, const Array <LineSection>& subPath,
  73026. const bool isClosed,
  73027. const float width, const float maxMiterExtensionSquared,
  73028. const PathStrokeType::JointStyle jointStyle, const PathStrokeType::EndCapStyle endStyle) throw()
  73029. {
  73030. jassert (subPath.size() > 0);
  73031. const LineSection& firstLine = subPath.getReference (0);
  73032. float lastX1 = firstLine.lx1;
  73033. float lastY1 = firstLine.ly1;
  73034. float lastX2 = firstLine.lx2;
  73035. float lastY2 = firstLine.ly2;
  73036. if (isClosed)
  73037. {
  73038. destPath.startNewSubPath (lastX1, lastY1);
  73039. }
  73040. else
  73041. {
  73042. destPath.startNewSubPath (firstLine.rx2, firstLine.ry2);
  73043. addLineEnd (destPath, endStyle,
  73044. firstLine.rx2, firstLine.ry2,
  73045. lastX1, lastY1,
  73046. width);
  73047. }
  73048. int i;
  73049. for (i = 1; i < subPath.size(); ++i)
  73050. {
  73051. const LineSection& l = subPath.getReference (i);
  73052. addEdgeAndJoint (destPath, jointStyle,
  73053. maxMiterExtensionSquared, width,
  73054. lastX1, lastY1, lastX2, lastY2,
  73055. l.lx1, l.ly1, l.lx2, l.ly2,
  73056. l.x1, l.y1);
  73057. lastX1 = l.lx1;
  73058. lastY1 = l.ly1;
  73059. lastX2 = l.lx2;
  73060. lastY2 = l.ly2;
  73061. }
  73062. const LineSection& lastLine = subPath.getReference (subPath.size() - 1);
  73063. if (isClosed)
  73064. {
  73065. const LineSection& l = subPath.getReference (0);
  73066. addEdgeAndJoint (destPath, jointStyle,
  73067. maxMiterExtensionSquared, width,
  73068. lastX1, lastY1, lastX2, lastY2,
  73069. l.lx1, l.ly1, l.lx2, l.ly2,
  73070. l.x1, l.y1);
  73071. destPath.closeSubPath();
  73072. destPath.startNewSubPath (lastLine.rx1, lastLine.ry1);
  73073. }
  73074. else
  73075. {
  73076. destPath.lineTo (lastX2, lastY2);
  73077. addLineEnd (destPath, endStyle,
  73078. lastX2, lastY2,
  73079. lastLine.rx1, lastLine.ry1,
  73080. width);
  73081. }
  73082. lastX1 = lastLine.rx1;
  73083. lastY1 = lastLine.ry1;
  73084. lastX2 = lastLine.rx2;
  73085. lastY2 = lastLine.ry2;
  73086. for (i = subPath.size() - 1; --i >= 0;)
  73087. {
  73088. const LineSection& l = subPath.getReference (i);
  73089. addEdgeAndJoint (destPath, jointStyle,
  73090. maxMiterExtensionSquared, width,
  73091. lastX1, lastY1, lastX2, lastY2,
  73092. l.rx1, l.ry1, l.rx2, l.ry2,
  73093. l.x2, l.y2);
  73094. lastX1 = l.rx1;
  73095. lastY1 = l.ry1;
  73096. lastX2 = l.rx2;
  73097. lastY2 = l.ry2;
  73098. }
  73099. if (isClosed)
  73100. {
  73101. addEdgeAndJoint (destPath, jointStyle,
  73102. maxMiterExtensionSquared, width,
  73103. lastX1, lastY1, lastX2, lastY2,
  73104. lastLine.rx1, lastLine.ry1, lastLine.rx2, lastLine.ry2,
  73105. lastLine.x2, lastLine.y2);
  73106. }
  73107. else
  73108. {
  73109. // do the last line
  73110. destPath.lineTo (lastX2, lastY2);
  73111. }
  73112. destPath.closeSubPath();
  73113. }
  73114. void PathStrokeType::createStrokedPath (Path& destPath,
  73115. const Path& source,
  73116. const AffineTransform& transform,
  73117. const float extraAccuracy) const throw()
  73118. {
  73119. if (thickness <= 0)
  73120. {
  73121. destPath.clear();
  73122. return;
  73123. }
  73124. const Path* sourcePath = &source;
  73125. Path temp;
  73126. if (sourcePath == &destPath)
  73127. {
  73128. destPath.swapWithPath (temp);
  73129. sourcePath = &temp;
  73130. }
  73131. else
  73132. {
  73133. destPath.clear();
  73134. }
  73135. destPath.setUsingNonZeroWinding (true);
  73136. const float maxMiterExtensionSquared = 9.0f * thickness * thickness;
  73137. const float width = 0.5f * thickness;
  73138. // Iterate the path, creating a list of the
  73139. // left/right-hand lines along either side of it...
  73140. PathFlatteningIterator it (*sourcePath, transform, 9.0f / extraAccuracy);
  73141. Array <LineSection> subPath;
  73142. LineSection l;
  73143. l.x1 = 0;
  73144. l.y1 = 0;
  73145. const float minSegmentLength = 2.0f / (extraAccuracy * extraAccuracy);
  73146. while (it.next())
  73147. {
  73148. if (it.subPathIndex == 0)
  73149. {
  73150. if (subPath.size() > 0)
  73151. {
  73152. addSubPath (destPath, subPath, false, width, maxMiterExtensionSquared, jointStyle, endStyle);
  73153. subPath.clearQuick();
  73154. }
  73155. l.x1 = it.x1;
  73156. l.y1 = it.y1;
  73157. }
  73158. l.x2 = it.x2;
  73159. l.y2 = it.y2;
  73160. float dx = l.x2 - l.x1;
  73161. float dy = l.y2 - l.y1;
  73162. const float hypotSquared = dx*dx + dy*dy;
  73163. if (it.closesSubPath || hypotSquared > minSegmentLength || it.isLastInSubpath())
  73164. {
  73165. const float len = sqrtf (hypotSquared);
  73166. if (len == 0)
  73167. {
  73168. l.rx1 = l.rx2 = l.lx1 = l.lx2 = l.x1;
  73169. l.ry1 = l.ry2 = l.ly1 = l.ly2 = l.y1;
  73170. }
  73171. else
  73172. {
  73173. const float offset = width / len;
  73174. dx *= offset;
  73175. dy *= offset;
  73176. l.rx2 = l.x1 - dy;
  73177. l.ry2 = l.y1 + dx;
  73178. l.lx1 = l.x1 + dy;
  73179. l.ly1 = l.y1 - dx;
  73180. l.lx2 = l.x2 + dy;
  73181. l.ly2 = l.y2 - dx;
  73182. l.rx1 = l.x2 - dy;
  73183. l.ry1 = l.y2 + dx;
  73184. }
  73185. subPath.add (l);
  73186. if (it.closesSubPath)
  73187. {
  73188. addSubPath (destPath, subPath, true, width, maxMiterExtensionSquared, jointStyle, endStyle);
  73189. subPath.clearQuick();
  73190. }
  73191. else
  73192. {
  73193. l.x1 = it.x2;
  73194. l.y1 = it.y2;
  73195. }
  73196. }
  73197. }
  73198. if (subPath.size() > 0)
  73199. addSubPath (destPath, subPath, false, width, maxMiterExtensionSquared, jointStyle, endStyle);
  73200. }
  73201. void PathStrokeType::createDashedStroke (Path& destPath,
  73202. const Path& sourcePath,
  73203. const float* dashLengths,
  73204. int numDashLengths,
  73205. const AffineTransform& transform,
  73206. const float extraAccuracy) const throw()
  73207. {
  73208. if (thickness <= 0)
  73209. return;
  73210. // this should really be an even number..
  73211. jassert ((numDashLengths & 1) == 0);
  73212. Path newDestPath;
  73213. PathFlatteningIterator it (sourcePath, transform, 9.0f / extraAccuracy);
  73214. bool first = true;
  73215. int dashNum = 0;
  73216. float pos = 0.0f, lineLen = 0.0f, lineEndPos = 0.0f;
  73217. float dx = 0.0f, dy = 0.0f;
  73218. for (;;)
  73219. {
  73220. const bool isSolid = ((dashNum & 1) == 0);
  73221. const float dashLen = dashLengths [dashNum++ % numDashLengths];
  73222. jassert (dashLen > 0); // must be a positive increment!
  73223. if (dashLen <= 0)
  73224. break;
  73225. pos += dashLen;
  73226. while (pos > lineEndPos)
  73227. {
  73228. if (! it.next())
  73229. {
  73230. if (isSolid && ! first)
  73231. newDestPath.lineTo (it.x2, it.y2);
  73232. createStrokedPath (destPath, newDestPath, AffineTransform::identity, extraAccuracy);
  73233. return;
  73234. }
  73235. if (isSolid && ! first)
  73236. newDestPath.lineTo (it.x1, it.y1);
  73237. else
  73238. newDestPath.startNewSubPath (it.x1, it.y1);
  73239. dx = it.x2 - it.x1;
  73240. dy = it.y2 - it.y1;
  73241. lineLen = juce_hypotf (dx, dy);
  73242. lineEndPos += lineLen;
  73243. first = it.closesSubPath;
  73244. }
  73245. const float alpha = (pos - (lineEndPos - lineLen)) / lineLen;
  73246. if (isSolid)
  73247. newDestPath.lineTo (it.x1 + dx * alpha,
  73248. it.y1 + dy * alpha);
  73249. else
  73250. newDestPath.startNewSubPath (it.x1 + dx * alpha,
  73251. it.y1 + dy * alpha);
  73252. }
  73253. }
  73254. END_JUCE_NAMESPACE
  73255. /*** End of inlined file: juce_PathStrokeType.cpp ***/
  73256. /*** Start of inlined file: juce_PositionedRectangle.cpp ***/
  73257. BEGIN_JUCE_NAMESPACE
  73258. PositionedRectangle::PositionedRectangle() throw()
  73259. : x (0.0),
  73260. y (0.0),
  73261. w (0.0),
  73262. h (0.0),
  73263. xMode (anchorAtLeftOrTop | absoluteFromParentTopLeft),
  73264. yMode (anchorAtLeftOrTop | absoluteFromParentTopLeft),
  73265. wMode (absoluteSize),
  73266. hMode (absoluteSize)
  73267. {
  73268. }
  73269. PositionedRectangle::PositionedRectangle (const PositionedRectangle& other) throw()
  73270. : x (other.x),
  73271. y (other.y),
  73272. w (other.w),
  73273. h (other.h),
  73274. xMode (other.xMode),
  73275. yMode (other.yMode),
  73276. wMode (other.wMode),
  73277. hMode (other.hMode)
  73278. {
  73279. }
  73280. const PositionedRectangle& PositionedRectangle::operator= (const PositionedRectangle& other) throw()
  73281. {
  73282. x = other.x;
  73283. y = other.y;
  73284. w = other.w;
  73285. h = other.h;
  73286. xMode = other.xMode;
  73287. yMode = other.yMode;
  73288. wMode = other.wMode;
  73289. hMode = other.hMode;
  73290. return *this;
  73291. }
  73292. PositionedRectangle::~PositionedRectangle() throw()
  73293. {
  73294. }
  73295. const bool PositionedRectangle::operator== (const PositionedRectangle& other) const throw()
  73296. {
  73297. return x == other.x
  73298. && y == other.y
  73299. && w == other.w
  73300. && h == other.h
  73301. && xMode == other.xMode
  73302. && yMode == other.yMode
  73303. && wMode == other.wMode
  73304. && hMode == other.hMode;
  73305. }
  73306. const bool PositionedRectangle::operator!= (const PositionedRectangle& other) const throw()
  73307. {
  73308. return ! operator== (other);
  73309. }
  73310. PositionedRectangle::PositionedRectangle (const String& stringVersion) throw()
  73311. {
  73312. StringArray tokens;
  73313. tokens.addTokens (stringVersion, false);
  73314. decodePosString (tokens [0], xMode, x);
  73315. decodePosString (tokens [1], yMode, y);
  73316. decodeSizeString (tokens [2], wMode, w);
  73317. decodeSizeString (tokens [3], hMode, h);
  73318. }
  73319. const String PositionedRectangle::toString() const throw()
  73320. {
  73321. String s;
  73322. s.preallocateStorage (12);
  73323. addPosDescription (s, xMode, x);
  73324. s << T(' ');
  73325. addPosDescription (s, yMode, y);
  73326. s << T(' ');
  73327. addSizeDescription (s, wMode, w);
  73328. s << T(' ');
  73329. addSizeDescription (s, hMode, h);
  73330. return s;
  73331. }
  73332. const Rectangle<int> PositionedRectangle::getRectangle (const Rectangle<int>& target) const throw()
  73333. {
  73334. jassert (! target.isEmpty());
  73335. double x_, y_, w_, h_;
  73336. applyPosAndSize (x_, w_, x, w, xMode, wMode, target.getX(), target.getWidth());
  73337. applyPosAndSize (y_, h_, y, h, yMode, hMode, target.getY(), target.getHeight());
  73338. return Rectangle<int> (roundToInt (x_), roundToInt (y_),
  73339. roundToInt (w_), roundToInt (h_));
  73340. }
  73341. void PositionedRectangle::getRectangleDouble (const Rectangle<int>& target,
  73342. double& x_, double& y_,
  73343. double& w_, double& h_) const throw()
  73344. {
  73345. jassert (! target.isEmpty());
  73346. applyPosAndSize (x_, w_, x, w, xMode, wMode, target.getX(), target.getWidth());
  73347. applyPosAndSize (y_, h_, y, h, yMode, hMode, target.getY(), target.getHeight());
  73348. }
  73349. void PositionedRectangle::applyToComponent (Component& comp) const throw()
  73350. {
  73351. comp.setBounds (getRectangle (Rectangle<int> (0, 0, comp.getParentWidth(), comp.getParentHeight())));
  73352. }
  73353. void PositionedRectangle::updateFrom (const Rectangle<int>& rectangle,
  73354. const Rectangle<int>& target) throw()
  73355. {
  73356. updatePosAndSize (x, w, rectangle.getX(), rectangle.getWidth(), xMode, wMode, target.getX(), target.getWidth());
  73357. updatePosAndSize (y, h, rectangle.getY(), rectangle.getHeight(), yMode, hMode, target.getY(), target.getHeight());
  73358. }
  73359. void PositionedRectangle::updateFromDouble (const double newX, const double newY,
  73360. const double newW, const double newH,
  73361. const Rectangle<int>& target) throw()
  73362. {
  73363. updatePosAndSize (x, w, newX, newW, xMode, wMode, target.getX(), target.getWidth());
  73364. updatePosAndSize (y, h, newY, newH, yMode, hMode, target.getY(), target.getHeight());
  73365. }
  73366. void PositionedRectangle::updateFromComponent (const Component& comp) throw()
  73367. {
  73368. if (comp.getParentComponent() == 0 && ! comp.isOnDesktop())
  73369. updateFrom (comp.getBounds(), Rectangle<int>());
  73370. else
  73371. updateFrom (comp.getBounds(), Rectangle<int> (0, 0, comp.getParentWidth(), comp.getParentHeight()));
  73372. }
  73373. PositionedRectangle::AnchorPoint PositionedRectangle::getAnchorPointX() const throw()
  73374. {
  73375. return (AnchorPoint) (xMode & (anchorAtLeftOrTop | anchorAtRightOrBottom | anchorAtCentre));
  73376. }
  73377. PositionedRectangle::PositionMode PositionedRectangle::getPositionModeX() const throw()
  73378. {
  73379. return (PositionMode) (xMode & (absoluteFromParentTopLeft
  73380. | absoluteFromParentBottomRight
  73381. | absoluteFromParentCentre
  73382. | proportionOfParentSize));
  73383. }
  73384. PositionedRectangle::AnchorPoint PositionedRectangle::getAnchorPointY() const throw()
  73385. {
  73386. return (AnchorPoint) (yMode & (anchorAtLeftOrTop | anchorAtRightOrBottom | anchorAtCentre));
  73387. }
  73388. PositionedRectangle::PositionMode PositionedRectangle::getPositionModeY() const throw()
  73389. {
  73390. return (PositionMode) (yMode & (absoluteFromParentTopLeft
  73391. | absoluteFromParentBottomRight
  73392. | absoluteFromParentCentre
  73393. | proportionOfParentSize));
  73394. }
  73395. PositionedRectangle::SizeMode PositionedRectangle::getWidthMode() const throw()
  73396. {
  73397. return (SizeMode) wMode;
  73398. }
  73399. PositionedRectangle::SizeMode PositionedRectangle::getHeightMode() const throw()
  73400. {
  73401. return (SizeMode) hMode;
  73402. }
  73403. void PositionedRectangle::setModes (const AnchorPoint xAnchor,
  73404. const PositionMode xMode_,
  73405. const AnchorPoint yAnchor,
  73406. const PositionMode yMode_,
  73407. const SizeMode widthMode,
  73408. const SizeMode heightMode,
  73409. const Rectangle<int>& target) throw()
  73410. {
  73411. if (xMode != (xAnchor | xMode_) || wMode != widthMode)
  73412. {
  73413. double tx, tw;
  73414. applyPosAndSize (tx, tw, x, w, xMode, wMode, target.getX(), target.getWidth());
  73415. xMode = (uint8) (xAnchor | xMode_);
  73416. wMode = (uint8) widthMode;
  73417. updatePosAndSize (x, w, tx, tw, xMode, wMode, target.getX(), target.getWidth());
  73418. }
  73419. if (yMode != (yAnchor | yMode_) || hMode != heightMode)
  73420. {
  73421. double ty, th;
  73422. applyPosAndSize (ty, th, y, h, yMode, hMode, target.getY(), target.getHeight());
  73423. yMode = (uint8) (yAnchor | yMode_);
  73424. hMode = (uint8) heightMode;
  73425. updatePosAndSize (y, h, ty, th, yMode, hMode, target.getY(), target.getHeight());
  73426. }
  73427. }
  73428. bool PositionedRectangle::isPositionAbsolute() const throw()
  73429. {
  73430. return xMode == absoluteFromParentTopLeft
  73431. && yMode == absoluteFromParentTopLeft
  73432. && wMode == absoluteSize
  73433. && hMode == absoluteSize;
  73434. }
  73435. void PositionedRectangle::addPosDescription (String& s, const uint8 mode, const double value) const throw()
  73436. {
  73437. if ((mode & proportionOfParentSize) != 0)
  73438. {
  73439. s << (roundToInt (value * 100000.0) / 1000.0) << T('%');
  73440. }
  73441. else
  73442. {
  73443. s << (roundToInt (value * 100.0) / 100.0);
  73444. if ((mode & absoluteFromParentBottomRight) != 0)
  73445. s << T('R');
  73446. else if ((mode & absoluteFromParentCentre) != 0)
  73447. s << T('C');
  73448. }
  73449. if ((mode & anchorAtRightOrBottom) != 0)
  73450. s << T('r');
  73451. else if ((mode & anchorAtCentre) != 0)
  73452. s << T('c');
  73453. }
  73454. void PositionedRectangle::addSizeDescription (String& s, const uint8 mode, const double value) const throw()
  73455. {
  73456. if (mode == proportionalSize)
  73457. s << (roundToInt (value * 100000.0) / 1000.0) << T('%');
  73458. else if (mode == parentSizeMinusAbsolute)
  73459. s << (roundToInt (value * 100.0) / 100.0) << T('M');
  73460. else
  73461. s << (roundToInt (value * 100.0) / 100.0);
  73462. }
  73463. void PositionedRectangle::decodePosString (const String& s, uint8& mode, double& value) throw()
  73464. {
  73465. if (s.containsChar (T('r')))
  73466. mode = anchorAtRightOrBottom;
  73467. else if (s.containsChar (T('c')))
  73468. mode = anchorAtCentre;
  73469. else
  73470. mode = anchorAtLeftOrTop;
  73471. if (s.containsChar (T('%')))
  73472. {
  73473. mode |= proportionOfParentSize;
  73474. value = s.removeCharacters (T("%rcRC")).getDoubleValue() / 100.0;
  73475. }
  73476. else
  73477. {
  73478. if (s.containsChar (T('R')))
  73479. mode |= absoluteFromParentBottomRight;
  73480. else if (s.containsChar (T('C')))
  73481. mode |= absoluteFromParentCentre;
  73482. else
  73483. mode |= absoluteFromParentTopLeft;
  73484. value = s.removeCharacters (T("rcRC")).getDoubleValue();
  73485. }
  73486. }
  73487. void PositionedRectangle::decodeSizeString (const String& s, uint8& mode, double& value) throw()
  73488. {
  73489. if (s.containsChar (T('%')))
  73490. {
  73491. mode = proportionalSize;
  73492. value = s.upToFirstOccurrenceOf (T("%"), false, false).getDoubleValue() / 100.0;
  73493. }
  73494. else if (s.containsChar (T('M')))
  73495. {
  73496. mode = parentSizeMinusAbsolute;
  73497. value = s.getDoubleValue();
  73498. }
  73499. else
  73500. {
  73501. mode = absoluteSize;
  73502. value = s.getDoubleValue();
  73503. }
  73504. }
  73505. void PositionedRectangle::applyPosAndSize (double& xOut, double& wOut,
  73506. const double x_, const double w_,
  73507. const uint8 xMode_, const uint8 wMode_,
  73508. const int parentPos,
  73509. const int parentSize) const throw()
  73510. {
  73511. if (wMode_ == proportionalSize)
  73512. wOut = roundToInt (w_ * parentSize);
  73513. else if (wMode_ == parentSizeMinusAbsolute)
  73514. wOut = jmax (0, parentSize - roundToInt (w_));
  73515. else
  73516. wOut = roundToInt (w_);
  73517. if ((xMode_ & proportionOfParentSize) != 0)
  73518. xOut = parentPos + x_ * parentSize;
  73519. else if ((xMode_ & absoluteFromParentBottomRight) != 0)
  73520. xOut = (parentPos + parentSize) - x_;
  73521. else if ((xMode_ & absoluteFromParentCentre) != 0)
  73522. xOut = x_ + (parentPos + parentSize / 2);
  73523. else
  73524. xOut = x_ + parentPos;
  73525. if ((xMode_ & anchorAtRightOrBottom) != 0)
  73526. xOut -= wOut;
  73527. else if ((xMode_ & anchorAtCentre) != 0)
  73528. xOut -= wOut / 2;
  73529. }
  73530. void PositionedRectangle::updatePosAndSize (double& xOut, double& wOut,
  73531. double x_, const double w_,
  73532. const uint8 xMode_, const uint8 wMode_,
  73533. const int parentPos,
  73534. const int parentSize) const throw()
  73535. {
  73536. if (wMode_ == proportionalSize)
  73537. {
  73538. if (parentSize > 0)
  73539. wOut = w_ / parentSize;
  73540. }
  73541. else if (wMode_ == parentSizeMinusAbsolute)
  73542. wOut = parentSize - w_;
  73543. else
  73544. wOut = w_;
  73545. if ((xMode_ & anchorAtRightOrBottom) != 0)
  73546. x_ += w_;
  73547. else if ((xMode_ & anchorAtCentre) != 0)
  73548. x_ += w_ / 2;
  73549. if ((xMode_ & proportionOfParentSize) != 0)
  73550. {
  73551. if (parentSize > 0)
  73552. xOut = (x_ - parentPos) / parentSize;
  73553. }
  73554. else if ((xMode_ & absoluteFromParentBottomRight) != 0)
  73555. xOut = (parentPos + parentSize) - x_;
  73556. else if ((xMode_ & absoluteFromParentCentre) != 0)
  73557. xOut = x_ - (parentPos + parentSize / 2);
  73558. else
  73559. xOut = x_ - parentPos;
  73560. }
  73561. END_JUCE_NAMESPACE
  73562. /*** End of inlined file: juce_PositionedRectangle.cpp ***/
  73563. /*** Start of inlined file: juce_RectangleList.cpp ***/
  73564. BEGIN_JUCE_NAMESPACE
  73565. RectangleList::RectangleList() throw()
  73566. {
  73567. }
  73568. RectangleList::RectangleList (const Rectangle<int>& rect) throw()
  73569. {
  73570. if (! rect.isEmpty())
  73571. rects.add (rect);
  73572. }
  73573. RectangleList::RectangleList (const RectangleList& other) throw()
  73574. : rects (other.rects)
  73575. {
  73576. }
  73577. const RectangleList& RectangleList::operator= (const RectangleList& other) throw()
  73578. {
  73579. rects = other.rects;
  73580. return *this;
  73581. }
  73582. RectangleList::~RectangleList() throw()
  73583. {
  73584. }
  73585. void RectangleList::clear() throw()
  73586. {
  73587. rects.clearQuick();
  73588. }
  73589. const Rectangle<int> RectangleList::getRectangle (const int index) const throw()
  73590. {
  73591. if (((unsigned int) index) < (unsigned int) rects.size())
  73592. return rects.getReference (index);
  73593. return Rectangle<int>();
  73594. }
  73595. bool RectangleList::isEmpty() const throw()
  73596. {
  73597. return rects.size() == 0;
  73598. }
  73599. RectangleList::Iterator::Iterator (const RectangleList& list) throw()
  73600. : current (0),
  73601. owner (list),
  73602. index (list.rects.size())
  73603. {
  73604. }
  73605. RectangleList::Iterator::~Iterator() throw()
  73606. {
  73607. }
  73608. bool RectangleList::Iterator::next() throw()
  73609. {
  73610. if (--index >= 0)
  73611. {
  73612. current = & (owner.rects.getReference (index));
  73613. return true;
  73614. }
  73615. return false;
  73616. }
  73617. void RectangleList::add (const Rectangle<int>& rect) throw()
  73618. {
  73619. if (! rect.isEmpty())
  73620. {
  73621. if (rects.size() == 0)
  73622. {
  73623. rects.add (rect);
  73624. }
  73625. else
  73626. {
  73627. bool anyOverlaps = false;
  73628. int i;
  73629. for (i = rects.size(); --i >= 0;)
  73630. {
  73631. Rectangle<int>& ourRect = rects.getReference (i);
  73632. if (rect.intersects (ourRect))
  73633. {
  73634. if (rect.contains (ourRect))
  73635. rects.remove (i);
  73636. else if (! ourRect.reduceIfPartlyContainedIn (rect))
  73637. anyOverlaps = true;
  73638. }
  73639. }
  73640. if (anyOverlaps && rects.size() > 0)
  73641. {
  73642. RectangleList r (rect);
  73643. for (i = rects.size(); --i >= 0;)
  73644. {
  73645. const Rectangle<int>& ourRect = rects.getReference (i);
  73646. if (rect.intersects (ourRect))
  73647. {
  73648. r.subtract (ourRect);
  73649. if (r.rects.size() == 0)
  73650. return;
  73651. }
  73652. }
  73653. for (i = r.getNumRectangles(); --i >= 0;)
  73654. rects.add (r.rects.getReference (i));
  73655. }
  73656. else
  73657. {
  73658. rects.add (rect);
  73659. }
  73660. }
  73661. }
  73662. }
  73663. void RectangleList::addWithoutMerging (const Rectangle<int>& rect) throw()
  73664. {
  73665. rects.add (rect);
  73666. }
  73667. void RectangleList::add (const int x, const int y, const int w, const int h) throw()
  73668. {
  73669. if (rects.size() == 0)
  73670. {
  73671. if (w > 0 && h > 0)
  73672. rects.add (Rectangle<int> (x, y, w, h));
  73673. }
  73674. else
  73675. {
  73676. add (Rectangle<int> (x, y, w, h));
  73677. }
  73678. }
  73679. void RectangleList::add (const RectangleList& other) throw()
  73680. {
  73681. for (int i = 0; i < other.rects.size(); ++i)
  73682. add (other.rects.getReference (i));
  73683. }
  73684. void RectangleList::subtract (const Rectangle<int>& rect) throw()
  73685. {
  73686. const int originalNumRects = rects.size();
  73687. if (originalNumRects > 0)
  73688. {
  73689. const int x1 = rect.x;
  73690. const int y1 = rect.y;
  73691. const int x2 = x1 + rect.w;
  73692. const int y2 = y1 + rect.h;
  73693. for (int i = getNumRectangles(); --i >= 0;)
  73694. {
  73695. Rectangle<int>& r = rects.getReference (i);
  73696. const int rx1 = r.x;
  73697. const int ry1 = r.y;
  73698. const int rx2 = rx1 + r.w;
  73699. const int ry2 = ry1 + r.h;
  73700. if (! (x2 <= rx1 || x1 >= rx2 || y2 <= ry1 || y1 >= ry2))
  73701. {
  73702. if (x1 > rx1 && x1 < rx2)
  73703. {
  73704. if (y1 <= ry1 && y2 >= ry2 && x2 >= rx2)
  73705. {
  73706. r.w = x1 - rx1;
  73707. }
  73708. else
  73709. {
  73710. r.x = x1;
  73711. r.w = rx2 - x1;
  73712. rects.insert (i + 1, Rectangle<int> (rx1, ry1, x1 - rx1, ry2 - ry1));
  73713. i += 2;
  73714. }
  73715. }
  73716. else if (x2 > rx1 && x2 < rx2)
  73717. {
  73718. r.x = x2;
  73719. r.w = rx2 - x2;
  73720. if (y1 > ry1 || y2 < ry2 || x1 > rx1)
  73721. {
  73722. rects.insert (i + 1, Rectangle<int> (rx1, ry1, x2 - rx1, ry2 - ry1));
  73723. i += 2;
  73724. }
  73725. }
  73726. else if (y1 > ry1 && y1 < ry2)
  73727. {
  73728. if (x1 <= rx1 && x2 >= rx2 && y2 >= ry2)
  73729. {
  73730. r.h = y1 - ry1;
  73731. }
  73732. else
  73733. {
  73734. r.y = y1;
  73735. r.h = ry2 - y1;
  73736. rects.insert (i + 1, Rectangle<int> (rx1, ry1, rx2 - rx1, y1 - ry1));
  73737. i += 2;
  73738. }
  73739. }
  73740. else if (y2 > ry1 && y2 < ry2)
  73741. {
  73742. r.y = y2;
  73743. r.h = ry2 - y2;
  73744. if (x1 > rx1 || x2 < rx2 || y1 > ry1)
  73745. {
  73746. rects.insert (i + 1, Rectangle<int> (rx1, ry1, rx2 - rx1, y2 - ry1));
  73747. i += 2;
  73748. }
  73749. }
  73750. else
  73751. {
  73752. rects.remove (i);
  73753. }
  73754. }
  73755. }
  73756. if (rects.size() > originalNumRects + 10)
  73757. consolidate();
  73758. }
  73759. }
  73760. void RectangleList::subtract (const RectangleList& otherList) throw()
  73761. {
  73762. for (int i = otherList.rects.size(); --i >= 0;)
  73763. subtract (otherList.rects.getReference (i));
  73764. }
  73765. bool RectangleList::clipTo (const Rectangle<int>& rect) throw()
  73766. {
  73767. bool notEmpty = false;
  73768. if (rect.isEmpty())
  73769. {
  73770. clear();
  73771. }
  73772. else
  73773. {
  73774. for (int i = rects.size(); --i >= 0;)
  73775. {
  73776. Rectangle<int>& r = rects.getReference (i);
  73777. if (! rect.intersectRectangle (r.x, r.y, r.w, r.h))
  73778. rects.remove (i);
  73779. else
  73780. notEmpty = true;
  73781. }
  73782. }
  73783. return notEmpty;
  73784. }
  73785. bool RectangleList::clipTo (const RectangleList& other) throw()
  73786. {
  73787. if (rects.size() == 0)
  73788. return false;
  73789. RectangleList result;
  73790. for (int j = 0; j < rects.size(); ++j)
  73791. {
  73792. const Rectangle<int>& rect = rects.getReference (j);
  73793. for (int i = other.rects.size(); --i >= 0;)
  73794. {
  73795. Rectangle<int> r (other.rects.getReference (i));
  73796. if (rect.intersectRectangle (r.x, r.y, r.w, r.h))
  73797. result.rects.add (r);
  73798. }
  73799. }
  73800. swapWith (result);
  73801. return ! isEmpty();
  73802. }
  73803. bool RectangleList::getIntersectionWith (const Rectangle<int>& rect, RectangleList& destRegion) const throw()
  73804. {
  73805. destRegion.clear();
  73806. if (! rect.isEmpty())
  73807. {
  73808. for (int i = rects.size(); --i >= 0;)
  73809. {
  73810. Rectangle<int> r (rects.getReference (i));
  73811. if (rect.intersectRectangle (r.x, r.y, r.w, r.h))
  73812. destRegion.rects.add (r);
  73813. }
  73814. }
  73815. return destRegion.rects.size() > 0;
  73816. }
  73817. void RectangleList::swapWith (RectangleList& otherList) throw()
  73818. {
  73819. rects.swapWithArray (otherList.rects);
  73820. }
  73821. void RectangleList::consolidate() throw()
  73822. {
  73823. int i;
  73824. for (i = 0; i < getNumRectangles() - 1; ++i)
  73825. {
  73826. Rectangle<int>& r = rects.getReference (i);
  73827. const int rx1 = r.x;
  73828. const int ry1 = r.y;
  73829. const int rx2 = rx1 + r.w;
  73830. const int ry2 = ry1 + r.h;
  73831. for (int j = rects.size(); --j > i;)
  73832. {
  73833. Rectangle<int>& r2 = rects.getReference (j);
  73834. const int jrx1 = r2.x;
  73835. const int jry1 = r2.y;
  73836. const int jrx2 = jrx1 + r2.w;
  73837. const int jry2 = jry1 + r2.h;
  73838. // if the vertical edges of any blocks are touching and their horizontals don't
  73839. // line up, split them horizontally..
  73840. if (jrx1 == rx2 || jrx2 == rx1)
  73841. {
  73842. if (jry1 > ry1 && jry1 < ry2)
  73843. {
  73844. r.h = jry1 - ry1;
  73845. rects.add (Rectangle<int> (rx1, jry1, rx2 - rx1, ry2 - jry1));
  73846. i = -1;
  73847. break;
  73848. }
  73849. if (jry2 > ry1 && jry2 < ry2)
  73850. {
  73851. r.h = jry2 - ry1;
  73852. rects.add (Rectangle<int> (rx1, jry2, rx2 - rx1, ry2 - jry2));
  73853. i = -1;
  73854. break;
  73855. }
  73856. else if (ry1 > jry1 && ry1 < jry2)
  73857. {
  73858. r2.h = ry1 - jry1;
  73859. rects.add (Rectangle<int> (jrx1, ry1, jrx2 - jrx1, jry2 - ry1));
  73860. i = -1;
  73861. break;
  73862. }
  73863. else if (ry2 > jry1 && ry2 < jry2)
  73864. {
  73865. r2.h = ry2 - jry1;
  73866. rects.add (Rectangle<int> (jrx1, ry2, jrx2 - jrx1, jry2 - ry2));
  73867. i = -1;
  73868. break;
  73869. }
  73870. }
  73871. }
  73872. }
  73873. for (i = 0; i < rects.size() - 1; ++i)
  73874. {
  73875. Rectangle<int>& r = rects.getReference (i);
  73876. for (int j = rects.size(); --j > i;)
  73877. {
  73878. if (r.enlargeIfAdjacent (rects.getReference (j)))
  73879. {
  73880. rects.remove (j);
  73881. i = -1;
  73882. break;
  73883. }
  73884. }
  73885. }
  73886. }
  73887. bool RectangleList::containsPoint (const int x, const int y) const throw()
  73888. {
  73889. for (int i = getNumRectangles(); --i >= 0;)
  73890. if (rects.getReference (i).contains (x, y))
  73891. return true;
  73892. return false;
  73893. }
  73894. bool RectangleList::containsRectangle (const Rectangle<int>& rectangleToCheck) const throw()
  73895. {
  73896. if (rects.size() > 1)
  73897. {
  73898. RectangleList r (rectangleToCheck);
  73899. for (int i = rects.size(); --i >= 0;)
  73900. {
  73901. r.subtract (rects.getReference (i));
  73902. if (r.rects.size() == 0)
  73903. return true;
  73904. }
  73905. }
  73906. else if (rects.size() > 0)
  73907. {
  73908. return rects.getReference (0).contains (rectangleToCheck);
  73909. }
  73910. return false;
  73911. }
  73912. bool RectangleList::intersectsRectangle (const Rectangle<int>& rectangleToCheck) const throw()
  73913. {
  73914. for (int i = rects.size(); --i >= 0;)
  73915. if (rects.getReference (i).intersects (rectangleToCheck))
  73916. return true;
  73917. return false;
  73918. }
  73919. bool RectangleList::intersects (const RectangleList& other) const throw()
  73920. {
  73921. for (int i = rects.size(); --i >= 0;)
  73922. if (other.intersectsRectangle (rects.getReference (i)))
  73923. return true;
  73924. return false;
  73925. }
  73926. const Rectangle<int> RectangleList::getBounds() const throw()
  73927. {
  73928. if (rects.size() <= 1)
  73929. {
  73930. if (rects.size() == 0)
  73931. return Rectangle<int>();
  73932. else
  73933. return rects.getReference (0);
  73934. }
  73935. else
  73936. {
  73937. const Rectangle<int>& r = rects.getReference (0);
  73938. int minX = r.x;
  73939. int minY = r.y;
  73940. int maxX = minX + r.w;
  73941. int maxY = minY + r.h;
  73942. for (int i = rects.size(); --i > 0;)
  73943. {
  73944. const Rectangle<int>& r2 = rects.getReference (i);
  73945. minX = jmin (minX, r2.x);
  73946. minY = jmin (minY, r2.y);
  73947. maxX = jmax (maxX, r2.getRight());
  73948. maxY = jmax (maxY, r2.getBottom());
  73949. }
  73950. return Rectangle<int> (minX, minY, maxX - minX, maxY - minY);
  73951. }
  73952. }
  73953. void RectangleList::offsetAll (const int dx, const int dy) throw()
  73954. {
  73955. for (int i = rects.size(); --i >= 0;)
  73956. {
  73957. Rectangle<int>& r = rects.getReference (i);
  73958. r.x += dx;
  73959. r.y += dy;
  73960. }
  73961. }
  73962. const Path RectangleList::toPath() const throw()
  73963. {
  73964. Path p;
  73965. for (int i = rects.size(); --i >= 0;)
  73966. {
  73967. const Rectangle<int>& r = rects.getReference (i);
  73968. p.addRectangle ((float) r.x,
  73969. (float) r.y,
  73970. (float) r.w,
  73971. (float) r.h);
  73972. }
  73973. return p;
  73974. }
  73975. END_JUCE_NAMESPACE
  73976. /*** End of inlined file: juce_RectangleList.cpp ***/
  73977. /*** Start of inlined file: juce_Image.cpp ***/
  73978. BEGIN_JUCE_NAMESPACE
  73979. static const int fullAlphaThreshold = 253;
  73980. Image::Image (const PixelFormat format_,
  73981. const int imageWidth_,
  73982. const int imageHeight_)
  73983. : format (format_),
  73984. imageWidth (imageWidth_),
  73985. imageHeight (imageHeight_),
  73986. imageData (0)
  73987. {
  73988. jassert (format_ == RGB || format_ == ARGB || format_ == SingleChannel);
  73989. jassert (imageWidth_ > 0 && imageHeight_ > 0); // it's illegal to create a zero-sized image - the
  73990. // actual image will be at least 1x1.
  73991. }
  73992. Image::Image (const PixelFormat format_,
  73993. const int imageWidth_,
  73994. const int imageHeight_,
  73995. const bool clearImage)
  73996. : format (format_),
  73997. imageWidth (imageWidth_),
  73998. imageHeight (imageHeight_)
  73999. {
  74000. jassert (format_ == RGB || format_ == ARGB || format_ == SingleChannel);
  74001. jassert (imageWidth_ > 0 && imageHeight_ > 0); // it's illegal to create a zero-sized image - the
  74002. // actual image will be at least 1x1.
  74003. pixelStride = (format == RGB) ? 3 : ((format == ARGB) ? 4 : 1);
  74004. lineStride = (pixelStride * jmax (1, imageWidth_) + 3) & ~3;
  74005. imageDataAllocated.allocate (lineStride * jmax (1, imageHeight_), clearImage);
  74006. imageData = imageDataAllocated;
  74007. }
  74008. Image::Image (const Image& other)
  74009. : format (other.format),
  74010. imageWidth (other.imageWidth),
  74011. imageHeight (other.imageHeight)
  74012. {
  74013. pixelStride = (format == RGB) ? 3 : ((format == ARGB) ? 4 : 1);
  74014. lineStride = (pixelStride * jmax (1, imageWidth) + 3) & ~3;
  74015. imageDataAllocated.malloc (lineStride * jmax (1, imageHeight));
  74016. imageData = imageDataAllocated;
  74017. BitmapData srcData (other, 0, 0, imageWidth, imageHeight);
  74018. setPixelData (0, 0, imageWidth, imageHeight, srcData.data, srcData.lineStride);
  74019. }
  74020. Image::~Image()
  74021. {
  74022. }
  74023. LowLevelGraphicsContext* Image::createLowLevelContext()
  74024. {
  74025. return new LowLevelGraphicsSoftwareRenderer (*this);
  74026. }
  74027. Image::BitmapData::BitmapData (Image& image, int x, int y, int w, int h, const bool /*makeWritable*/)
  74028. : data (image.imageData + image.lineStride * y + image.pixelStride * x),
  74029. lineStride (image.lineStride),
  74030. pixelStride (image.pixelStride),
  74031. width (w),
  74032. height (h)
  74033. {
  74034. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= image.getWidth() && y + h <= image.getHeight());
  74035. }
  74036. Image::BitmapData::BitmapData (const Image& image, int x, int y, int w, int h)
  74037. : data (image.imageData + image.lineStride * y + image.pixelStride * x),
  74038. lineStride (image.lineStride),
  74039. pixelStride (image.pixelStride),
  74040. width (w),
  74041. height (h)
  74042. {
  74043. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= image.getWidth() && y + h <= image.getHeight());
  74044. }
  74045. Image::BitmapData::~BitmapData()
  74046. {
  74047. }
  74048. void Image::setPixelData (int x, int y, int w, int h,
  74049. const uint8* sourcePixelData, int sourceLineStride)
  74050. {
  74051. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= imageWidth && y + h <= imageHeight);
  74052. if (Rectangle<int>::intersectRectangles (x, y, w, h, 0, 0, imageWidth, imageHeight))
  74053. {
  74054. const BitmapData dest (*this, x, y, w, h, true);
  74055. for (int i = 0; i < h; ++i)
  74056. {
  74057. memcpy (dest.getLinePointer(i),
  74058. sourcePixelData + sourceLineStride * i,
  74059. w * dest.pixelStride);
  74060. }
  74061. }
  74062. }
  74063. void Image::clear (int dx, int dy, int dw, int dh,
  74064. const Colour& colourToClearTo)
  74065. {
  74066. const PixelARGB col (colourToClearTo.getPixelARGB());
  74067. const BitmapData destData (*this, dx, dy, dw, dh, true);
  74068. uint8* dest = destData.data;
  74069. while (--dh >= 0)
  74070. {
  74071. uint8* line = dest;
  74072. dest += destData.lineStride;
  74073. if (isARGB())
  74074. {
  74075. for (int x = dw; --x >= 0;)
  74076. {
  74077. ((PixelARGB*) line)->set (col);
  74078. line += destData.pixelStride;
  74079. }
  74080. }
  74081. else if (isRGB())
  74082. {
  74083. for (int x = dw; --x >= 0;)
  74084. {
  74085. ((PixelRGB*) line)->set (col);
  74086. line += destData.pixelStride;
  74087. }
  74088. }
  74089. else
  74090. {
  74091. for (int x = dw; --x >= 0;)
  74092. {
  74093. *line = col.getAlpha();
  74094. line += destData.pixelStride;
  74095. }
  74096. }
  74097. }
  74098. }
  74099. Image* Image::createCopy (int newWidth, int newHeight,
  74100. const Graphics::ResamplingQuality quality) const
  74101. {
  74102. if (newWidth < 0)
  74103. newWidth = imageWidth;
  74104. if (newHeight < 0)
  74105. newHeight = imageHeight;
  74106. Image* const newImage = Image::createNativeImage (format, newWidth, newHeight, true);
  74107. Graphics g (*newImage);
  74108. g.setImageResamplingQuality (quality);
  74109. g.drawImage (this,
  74110. 0, 0, newWidth, newHeight,
  74111. 0, 0, imageWidth, imageHeight,
  74112. false);
  74113. return newImage;
  74114. }
  74115. Image* Image::createCopyOfAlphaChannel() const
  74116. {
  74117. jassert (format != SingleChannel);
  74118. Image* const newImage = Image::createNativeImage (SingleChannel, imageWidth, imageHeight, false);
  74119. if (! hasAlphaChannel())
  74120. {
  74121. newImage->clear (0, 0, imageWidth, imageHeight, Colours::black);
  74122. }
  74123. else
  74124. {
  74125. const BitmapData destData (*newImage, 0, 0, imageWidth, imageHeight, true);
  74126. const BitmapData srcData (*this, 0, 0, imageWidth, imageHeight);
  74127. for (int y = 0; y < imageHeight; ++y)
  74128. {
  74129. const PixelARGB* src = (const PixelARGB*) srcData.getLinePointer(y);
  74130. uint8* dst = destData.getLinePointer (y);
  74131. for (int x = imageWidth; --x >= 0;)
  74132. {
  74133. *dst++ = src->getAlpha();
  74134. ++src;
  74135. }
  74136. }
  74137. }
  74138. return newImage;
  74139. }
  74140. const Colour Image::getPixelAt (const int x, const int y) const
  74141. {
  74142. Colour c;
  74143. if (((unsigned int) x) < (unsigned int) imageWidth
  74144. && ((unsigned int) y) < (unsigned int) imageHeight)
  74145. {
  74146. const BitmapData srcData (*this, x, y, 1, 1);
  74147. if (isARGB())
  74148. {
  74149. PixelARGB p (*(const PixelARGB*) srcData.data);
  74150. p.unpremultiply();
  74151. c = Colour (p.getARGB());
  74152. }
  74153. else if (isRGB())
  74154. c = Colour (((const PixelRGB*) srcData.data)->getARGB());
  74155. else
  74156. c = Colour ((uint8) 0, (uint8) 0, (uint8) 0, *(srcData.data));
  74157. }
  74158. return c;
  74159. }
  74160. void Image::setPixelAt (const int x, const int y,
  74161. const Colour& colour)
  74162. {
  74163. if (((unsigned int) x) < (unsigned int) imageWidth
  74164. && ((unsigned int) y) < (unsigned int) imageHeight)
  74165. {
  74166. const BitmapData destData (*this, x, y, 1, 1, true);
  74167. const PixelARGB col (colour.getPixelARGB());
  74168. if (isARGB())
  74169. ((PixelARGB*) destData.data)->set (col);
  74170. else if (isRGB())
  74171. ((PixelRGB*) destData.data)->set (col);
  74172. else
  74173. *(destData.data) = col.getAlpha();
  74174. }
  74175. }
  74176. void Image::multiplyAlphaAt (const int x, const int y,
  74177. const float multiplier)
  74178. {
  74179. if (((unsigned int) x) < (unsigned int) imageWidth
  74180. && ((unsigned int) y) < (unsigned int) imageHeight
  74181. && hasAlphaChannel())
  74182. {
  74183. const BitmapData destData (*this, x, y, 1, 1, true);
  74184. if (isARGB())
  74185. ((PixelARGB*) destData.data)->multiplyAlpha (multiplier);
  74186. else
  74187. *(destData.data) = (uint8) (*(destData.data) * multiplier);
  74188. }
  74189. }
  74190. void Image::multiplyAllAlphas (const float amountToMultiplyBy)
  74191. {
  74192. if (hasAlphaChannel())
  74193. {
  74194. const BitmapData destData (*this, 0, 0, getWidth(), getHeight(), true);
  74195. if (isARGB())
  74196. {
  74197. for (int y = 0; y < imageHeight; ++y)
  74198. {
  74199. uint8* p = destData.getLinePointer (y);
  74200. for (int x = 0; x < imageWidth; ++x)
  74201. {
  74202. ((PixelARGB*) p)->multiplyAlpha (amountToMultiplyBy);
  74203. p += destData.pixelStride;
  74204. }
  74205. }
  74206. }
  74207. else
  74208. {
  74209. for (int y = 0; y < imageHeight; ++y)
  74210. {
  74211. uint8* p = destData.getLinePointer (y);
  74212. for (int x = 0; x < imageWidth; ++x)
  74213. {
  74214. *p = (uint8) (*p * amountToMultiplyBy);
  74215. p += destData.pixelStride;
  74216. }
  74217. }
  74218. }
  74219. }
  74220. else
  74221. {
  74222. jassertfalse // can't do this without an alpha-channel!
  74223. }
  74224. }
  74225. void Image::desaturate()
  74226. {
  74227. if (isARGB() || isRGB())
  74228. {
  74229. const BitmapData destData (*this, 0, 0, getWidth(), getHeight(), true);
  74230. if (isARGB())
  74231. {
  74232. for (int y = 0; y < imageHeight; ++y)
  74233. {
  74234. uint8* p = destData.getLinePointer (y);
  74235. for (int x = 0; x < imageWidth; ++x)
  74236. {
  74237. ((PixelARGB*) p)->desaturate();
  74238. p += destData.pixelStride;
  74239. }
  74240. }
  74241. }
  74242. else
  74243. {
  74244. for (int y = 0; y < imageHeight; ++y)
  74245. {
  74246. uint8* p = destData.getLinePointer (y);
  74247. for (int x = 0; x < imageWidth; ++x)
  74248. {
  74249. ((PixelRGB*) p)->desaturate();
  74250. p += destData.pixelStride;
  74251. }
  74252. }
  74253. }
  74254. }
  74255. }
  74256. void Image::createSolidAreaMask (RectangleList& result, const float alphaThreshold) const
  74257. {
  74258. if (hasAlphaChannel())
  74259. {
  74260. const uint8 threshold = (uint8) jlimit (0, 255, roundToInt (alphaThreshold * 255.0f));
  74261. SparseSet <int> pixelsOnRow;
  74262. const BitmapData srcData (*this, 0, 0, getWidth(), getHeight());
  74263. for (int y = 0; y < imageHeight; ++y)
  74264. {
  74265. pixelsOnRow.clear();
  74266. const uint8* lineData = srcData.getLinePointer (y);
  74267. if (isARGB())
  74268. {
  74269. for (int x = 0; x < imageWidth; ++x)
  74270. {
  74271. if (((const PixelARGB*) lineData)->getAlpha() >= threshold)
  74272. pixelsOnRow.addRange (x, 1);
  74273. lineData += srcData.pixelStride;
  74274. }
  74275. }
  74276. else
  74277. {
  74278. for (int x = 0; x < imageWidth; ++x)
  74279. {
  74280. if (*lineData >= threshold)
  74281. pixelsOnRow.addRange (x, 1);
  74282. lineData += srcData.pixelStride;
  74283. }
  74284. }
  74285. for (int i = 0; i < pixelsOnRow.getNumRanges(); ++i)
  74286. {
  74287. int x, w;
  74288. if (pixelsOnRow.getRange (i, x, w))
  74289. result.add (Rectangle<int> (x, y, w, 1));
  74290. }
  74291. result.consolidate();
  74292. }
  74293. }
  74294. else
  74295. {
  74296. result.add (0, 0, imageWidth, imageHeight);
  74297. }
  74298. }
  74299. void Image::moveImageSection (int dx, int dy,
  74300. int sx, int sy,
  74301. int w, int h)
  74302. {
  74303. if (dx < 0)
  74304. {
  74305. w += dx;
  74306. sx -= dx;
  74307. dx = 0;
  74308. }
  74309. if (dy < 0)
  74310. {
  74311. h += dy;
  74312. sy -= dy;
  74313. dy = 0;
  74314. }
  74315. if (sx < 0)
  74316. {
  74317. w += sx;
  74318. dx -= sx;
  74319. sx = 0;
  74320. }
  74321. if (sy < 0)
  74322. {
  74323. h += sy;
  74324. dy -= sy;
  74325. sy = 0;
  74326. }
  74327. const int minX = jmin (dx, sx);
  74328. const int minY = jmin (dy, sy);
  74329. w = jmin (w, getWidth() - jmax (sx, dx));
  74330. h = jmin (h, getHeight() - jmax (sy, dy));
  74331. if (w > 0 && h > 0)
  74332. {
  74333. const int maxX = jmax (dx, sx) + w;
  74334. const int maxY = jmax (dy, sy) + h;
  74335. const BitmapData destData (*this, minX, minY, maxX - minX, maxY - minY, true);
  74336. uint8* dst = destData.getPixelPointer (dx - minX, dy - minY);
  74337. const uint8* src = destData.getPixelPointer (sx - minX, sy - minY);
  74338. const int lineSize = destData.pixelStride * w;
  74339. if (dy > sy)
  74340. {
  74341. while (--h >= 0)
  74342. {
  74343. const int offset = h * destData.lineStride;
  74344. memmove (dst + offset, src + offset, lineSize);
  74345. }
  74346. }
  74347. else if (dst != src)
  74348. {
  74349. while (--h >= 0)
  74350. {
  74351. memmove (dst, src, lineSize);
  74352. dst += destData.lineStride;
  74353. src += destData.lineStride;
  74354. }
  74355. }
  74356. }
  74357. }
  74358. END_JUCE_NAMESPACE
  74359. /*** End of inlined file: juce_Image.cpp ***/
  74360. /*** Start of inlined file: juce_ImageCache.cpp ***/
  74361. BEGIN_JUCE_NAMESPACE
  74362. struct ImageCacheItem
  74363. {
  74364. ScopedPointer <Image> image;
  74365. int64 hashCode;
  74366. int refCount;
  74367. uint32 releaseTime;
  74368. juce_UseDebuggingNewOperator
  74369. };
  74370. static ImageCache* instance = 0;
  74371. static int cacheTimeout = 5000;
  74372. ImageCache::ImageCache()
  74373. {
  74374. }
  74375. ImageCache::~ImageCache()
  74376. {
  74377. jassert (instance == this);
  74378. instance = 0;
  74379. }
  74380. Image* ImageCache::getFromHashCode (const int64 hashCode)
  74381. {
  74382. if (instance != 0)
  74383. {
  74384. const ScopedLock sl (instance->lock);
  74385. for (int i = instance->images.size(); --i >= 0;)
  74386. {
  74387. ImageCacheItem* const ci = instance->images.getUnchecked(i);
  74388. if (ci->hashCode == hashCode)
  74389. {
  74390. ci->refCount++;
  74391. return ci->image;
  74392. }
  74393. }
  74394. }
  74395. return 0;
  74396. }
  74397. void ImageCache::addImageToCache (Image* const image,
  74398. const int64 hashCode)
  74399. {
  74400. if (image != 0)
  74401. {
  74402. if (instance == 0)
  74403. instance = new ImageCache();
  74404. ImageCacheItem* const newC = new ImageCacheItem();
  74405. newC->hashCode = hashCode;
  74406. newC->image = image;
  74407. newC->refCount = 1;
  74408. newC->releaseTime = 0;
  74409. const ScopedLock sl (instance->lock);
  74410. instance->images.add (newC);
  74411. }
  74412. }
  74413. void ImageCache::release (Image* const imageToRelease)
  74414. {
  74415. if (imageToRelease != 0 && instance != 0)
  74416. {
  74417. const ScopedLock sl (instance->lock);
  74418. for (int i = instance->images.size(); --i >= 0;)
  74419. {
  74420. ImageCacheItem* const ci = instance->images.getUnchecked(i);
  74421. if ((Image*) ci->image == imageToRelease)
  74422. {
  74423. if (--(ci->refCount) == 0)
  74424. ci->releaseTime = Time::getApproximateMillisecondCounter();
  74425. if (! instance->isTimerRunning())
  74426. instance->startTimer (999);
  74427. break;
  74428. }
  74429. }
  74430. }
  74431. }
  74432. void ImageCache::releaseOrDelete (Image* const imageToRelease)
  74433. {
  74434. if (isImageInCache (imageToRelease))
  74435. release (imageToRelease);
  74436. else
  74437. delete imageToRelease;
  74438. }
  74439. bool ImageCache::isImageInCache (Image* const imageToLookFor)
  74440. {
  74441. if (instance != 0)
  74442. {
  74443. const ScopedLock sl (instance->lock);
  74444. for (int i = instance->images.size(); --i >= 0;)
  74445. if ((Image*) instance->images.getUnchecked(i)->image == imageToLookFor)
  74446. return true;
  74447. }
  74448. return false;
  74449. }
  74450. void ImageCache::incReferenceCount (Image* const image)
  74451. {
  74452. if (instance != 0)
  74453. {
  74454. const ScopedLock sl (instance->lock);
  74455. for (int i = instance->images.size(); --i >= 0;)
  74456. {
  74457. ImageCacheItem* const ci = (ImageCacheItem*) instance->images.getUnchecked(i);
  74458. if ((Image*) ci->image == image)
  74459. {
  74460. ci->refCount++;
  74461. return;
  74462. }
  74463. }
  74464. }
  74465. jassertfalse // (trying to inc the ref count of an image that's not in the cache)
  74466. }
  74467. void ImageCache::timerCallback()
  74468. {
  74469. int numberStillNeedingReleasing = 0;
  74470. const unsigned int now = Time::getApproximateMillisecondCounter();
  74471. const ScopedLock sl (lock);
  74472. for (int i = images.size(); --i >= 0;)
  74473. {
  74474. ImageCacheItem* const ci = images.getUnchecked(i);
  74475. if (ci->refCount <= 0)
  74476. {
  74477. if (now > ci->releaseTime + cacheTimeout
  74478. || now < ci->releaseTime - 1000)
  74479. {
  74480. images.remove (i);
  74481. }
  74482. else
  74483. {
  74484. ++numberStillNeedingReleasing;
  74485. }
  74486. }
  74487. }
  74488. if (numberStillNeedingReleasing == 0)
  74489. stopTimer();
  74490. }
  74491. Image* ImageCache::getFromFile (const File& file)
  74492. {
  74493. const int64 hashCode = file.hashCode64();
  74494. Image* image = getFromHashCode (hashCode);
  74495. if (image == 0)
  74496. {
  74497. image = ImageFileFormat::loadFrom (file);
  74498. addImageToCache (image, hashCode);
  74499. }
  74500. return image;
  74501. }
  74502. Image* ImageCache::getFromMemory (const void* imageData,
  74503. const int dataSize)
  74504. {
  74505. const int64 hashCode = (int64) (pointer_sized_int) imageData;
  74506. Image* image = getFromHashCode (hashCode);
  74507. if (image == 0)
  74508. {
  74509. image = ImageFileFormat::loadFrom (imageData, dataSize);
  74510. addImageToCache (image, hashCode);
  74511. }
  74512. return image;
  74513. }
  74514. void ImageCache::setCacheTimeout (const int millisecs)
  74515. {
  74516. cacheTimeout = millisecs;
  74517. }
  74518. END_JUCE_NAMESPACE
  74519. /*** End of inlined file: juce_ImageCache.cpp ***/
  74520. /*** Start of inlined file: juce_ImageConvolutionKernel.cpp ***/
  74521. BEGIN_JUCE_NAMESPACE
  74522. ImageConvolutionKernel::ImageConvolutionKernel (const int size_)
  74523. : values (size_ * size_),
  74524. size (size_)
  74525. {
  74526. clear();
  74527. }
  74528. ImageConvolutionKernel::~ImageConvolutionKernel()
  74529. {
  74530. }
  74531. void ImageConvolutionKernel::setKernelValue (const int x,
  74532. const int y,
  74533. const float value)
  74534. {
  74535. if (((unsigned int) x) < (unsigned int) size
  74536. && ((unsigned int) y) < (unsigned int) size)
  74537. {
  74538. values [x + y * size] = value;
  74539. }
  74540. else
  74541. {
  74542. jassertfalse
  74543. }
  74544. }
  74545. void ImageConvolutionKernel::clear()
  74546. {
  74547. for (int i = size * size; --i >= 0;)
  74548. values[i] = 0;
  74549. }
  74550. void ImageConvolutionKernel::setOverallSum (const float desiredTotalSum)
  74551. {
  74552. double currentTotal = 0.0;
  74553. for (int i = size * size; --i >= 0;)
  74554. currentTotal += values[i];
  74555. rescaleAllValues ((float) (desiredTotalSum / currentTotal));
  74556. }
  74557. void ImageConvolutionKernel::rescaleAllValues (const float multiplier)
  74558. {
  74559. for (int i = size * size; --i >= 0;)
  74560. values[i] *= multiplier;
  74561. }
  74562. void ImageConvolutionKernel::createGaussianBlur (const float radius)
  74563. {
  74564. const double radiusFactor = -1.0 / (radius * radius * 2);
  74565. const int centre = size >> 1;
  74566. for (int y = size; --y >= 0;)
  74567. {
  74568. for (int x = size; --x >= 0;)
  74569. {
  74570. const int cx = x - centre;
  74571. const int cy = y - centre;
  74572. values [x + y * size] = (float) exp (radiusFactor * (cx * cx + cy * cy));
  74573. }
  74574. }
  74575. setOverallSum (1.0f);
  74576. }
  74577. void ImageConvolutionKernel::applyToImage (Image& destImage,
  74578. const Image* sourceImage,
  74579. int dx,
  74580. int dy,
  74581. int dw,
  74582. int dh) const
  74583. {
  74584. ScopedPointer <Image> imageCreated;
  74585. if (sourceImage == 0)
  74586. {
  74587. sourceImage = imageCreated = destImage.createCopy();
  74588. }
  74589. else
  74590. {
  74591. jassert (sourceImage->getWidth() == destImage.getWidth()
  74592. && sourceImage->getHeight() == destImage.getHeight()
  74593. && sourceImage->getFormat() == destImage.getFormat());
  74594. if (sourceImage->getWidth() != destImage.getWidth()
  74595. || sourceImage->getHeight() != destImage.getHeight()
  74596. || sourceImage->getFormat() != destImage.getFormat())
  74597. return;
  74598. }
  74599. const int imageWidth = destImage.getWidth();
  74600. const int imageHeight = destImage.getHeight();
  74601. if (dx >= imageWidth || dy >= imageHeight)
  74602. return;
  74603. if (dx + dw > imageWidth)
  74604. dw = imageWidth - dx;
  74605. if (dy + dh > imageHeight)
  74606. dh = imageHeight - dy;
  74607. const int dx2 = dx + dw;
  74608. const int dy2 = dy + dh;
  74609. const Image::BitmapData destData (destImage, dx, dy, dw, dh, true);
  74610. uint8* line = destData.data;
  74611. const Image::BitmapData srcData (*sourceImage, 0, 0, sourceImage->getWidth(), sourceImage->getHeight());
  74612. if (destData.pixelStride == 4)
  74613. {
  74614. for (int y = dy; y < dy2; ++y)
  74615. {
  74616. uint8* dest = line;
  74617. line += destData.lineStride;
  74618. for (int x = dx; x < dx2; ++x)
  74619. {
  74620. float c1 = 0;
  74621. float c2 = 0;
  74622. float c3 = 0;
  74623. float c4 = 0;
  74624. for (int yy = 0; yy < size; ++yy)
  74625. {
  74626. const int sy = y + yy - (size >> 1);
  74627. if (sy >= imageHeight)
  74628. break;
  74629. if (sy >= 0)
  74630. {
  74631. int sx = x - (size >> 1);
  74632. const uint8* src = srcData.getPixelPointer (sx, sy);
  74633. for (int xx = 0; xx < size; ++xx)
  74634. {
  74635. if (sx >= imageWidth)
  74636. break;
  74637. if (sx >= 0)
  74638. {
  74639. const float kernelMult = values [xx + yy * size];
  74640. c1 += kernelMult * *src++;
  74641. c2 += kernelMult * *src++;
  74642. c3 += kernelMult * *src++;
  74643. c4 += kernelMult * *src++;
  74644. }
  74645. else
  74646. {
  74647. src += 4;
  74648. }
  74649. ++sx;
  74650. }
  74651. }
  74652. }
  74653. *dest++ = (uint8) jmin (0xff, roundToInt (c1));
  74654. *dest++ = (uint8) jmin (0xff, roundToInt (c2));
  74655. *dest++ = (uint8) jmin (0xff, roundToInt (c3));
  74656. *dest++ = (uint8) jmin (0xff, roundToInt (c4));
  74657. }
  74658. }
  74659. }
  74660. else if (destData.pixelStride == 3)
  74661. {
  74662. for (int y = dy; y < dy2; ++y)
  74663. {
  74664. uint8* dest = line;
  74665. line += destData.lineStride;
  74666. for (int x = dx; x < dx2; ++x)
  74667. {
  74668. float c1 = 0;
  74669. float c2 = 0;
  74670. float c3 = 0;
  74671. for (int yy = 0; yy < size; ++yy)
  74672. {
  74673. const int sy = y + yy - (size >> 1);
  74674. if (sy >= imageHeight)
  74675. break;
  74676. if (sy >= 0)
  74677. {
  74678. int sx = x - (size >> 1);
  74679. const uint8* src = srcData.getPixelPointer (sx, sy);
  74680. for (int xx = 0; xx < size; ++xx)
  74681. {
  74682. if (sx >= imageWidth)
  74683. break;
  74684. if (sx >= 0)
  74685. {
  74686. const float kernelMult = values [xx + yy * size];
  74687. c1 += kernelMult * *src++;
  74688. c2 += kernelMult * *src++;
  74689. c3 += kernelMult * *src++;
  74690. }
  74691. else
  74692. {
  74693. src += 3;
  74694. }
  74695. ++sx;
  74696. }
  74697. }
  74698. }
  74699. *dest++ = (uint8) roundToInt (c1);
  74700. *dest++ = (uint8) roundToInt (c2);
  74701. *dest++ = (uint8) roundToInt (c3);
  74702. }
  74703. }
  74704. }
  74705. }
  74706. END_JUCE_NAMESPACE
  74707. /*** End of inlined file: juce_ImageConvolutionKernel.cpp ***/
  74708. /*** Start of inlined file: juce_ImageFileFormat.cpp ***/
  74709. BEGIN_JUCE_NAMESPACE
  74710. /*** Start of inlined file: juce_GIFLoader.h ***/
  74711. #ifndef __JUCE_GIFLOADER_JUCEHEADER__
  74712. #define __JUCE_GIFLOADER_JUCEHEADER__
  74713. #ifndef DOXYGEN
  74714. class GIFLoader
  74715. {
  74716. public:
  74717. GIFLoader (InputStream& in);
  74718. ~GIFLoader();
  74719. Image* getImage() const { return image; }
  74720. private:
  74721. Image* image;
  74722. InputStream& input;
  74723. uint8 buffer [300];
  74724. uint8 palette [256][4];
  74725. bool dataBlockIsZero, fresh, finished;
  74726. int currentBit, lastBit, lastByteIndex;
  74727. int codeSize, setCodeSize;
  74728. int maxCode, maxCodeSize;
  74729. int firstcode, oldcode;
  74730. int clearCode, end_code;
  74731. enum { maxGifCode = 1 << 12 };
  74732. int table [2] [maxGifCode];
  74733. int stack [2 * maxGifCode];
  74734. int *sp;
  74735. bool getSizeFromHeader (int& width, int& height);
  74736. bool readPalette (const int numCols);
  74737. int readDataBlock (unsigned char* dest);
  74738. int processExtension (int type, int& transparent);
  74739. int readLZWByte (bool initialise, int input_code_size);
  74740. int getCode (int code_size, bool initialise);
  74741. bool readImage (int width, int height, int interlace, int transparent);
  74742. static inline int makeWord (const uint8 a, const uint8 b) { return (b << 8) | a; }
  74743. GIFLoader (const GIFLoader&);
  74744. const GIFLoader& operator= (const GIFLoader&);
  74745. };
  74746. #endif // DOXYGEN
  74747. #endif // __JUCE_GIFLOADER_JUCEHEADER__
  74748. /*** End of inlined file: juce_GIFLoader.h ***/
  74749. Image* juce_loadPNGImageFromStream (InputStream& inputStream);
  74750. bool juce_writePNGImageToStream (const Image& image, OutputStream& out);
  74751. PNGImageFormat::PNGImageFormat() {}
  74752. PNGImageFormat::~PNGImageFormat() {}
  74753. const String PNGImageFormat::getFormatName()
  74754. {
  74755. return T("PNG");
  74756. }
  74757. bool PNGImageFormat::canUnderstand (InputStream& in)
  74758. {
  74759. const int bytesNeeded = 4;
  74760. char header [bytesNeeded];
  74761. return in.read (header, bytesNeeded) == bytesNeeded
  74762. && header[1] == 'P'
  74763. && header[2] == 'N'
  74764. && header[3] == 'G';
  74765. }
  74766. Image* PNGImageFormat::decodeImage (InputStream& in)
  74767. {
  74768. return juce_loadPNGImageFromStream (in);
  74769. }
  74770. bool PNGImageFormat::writeImageToStream (const Image& sourceImage,
  74771. OutputStream& destStream)
  74772. {
  74773. return juce_writePNGImageToStream (sourceImage, destStream);
  74774. }
  74775. Image* juce_loadJPEGImageFromStream (InputStream& inputStream);
  74776. bool juce_writeJPEGImageToStream (const Image& image, OutputStream& out, float quality);
  74777. JPEGImageFormat::JPEGImageFormat()
  74778. : quality (-1.0f)
  74779. {
  74780. }
  74781. JPEGImageFormat::~JPEGImageFormat() {}
  74782. void JPEGImageFormat::setQuality (const float newQuality)
  74783. {
  74784. quality = newQuality;
  74785. }
  74786. const String JPEGImageFormat::getFormatName()
  74787. {
  74788. return T("JPEG");
  74789. }
  74790. bool JPEGImageFormat::canUnderstand (InputStream& in)
  74791. {
  74792. const int bytesNeeded = 10;
  74793. uint8 header [bytesNeeded];
  74794. if (in.read (header, bytesNeeded) == bytesNeeded)
  74795. {
  74796. return header[0] == 0xff
  74797. && header[1] == 0xd8
  74798. && header[2] == 0xff
  74799. && (header[3] == 0xe0 || header[3] == 0xe1);
  74800. }
  74801. return false;
  74802. }
  74803. Image* JPEGImageFormat::decodeImage (InputStream& in)
  74804. {
  74805. return juce_loadJPEGImageFromStream (in);
  74806. }
  74807. bool JPEGImageFormat::writeImageToStream (const Image& sourceImage,
  74808. OutputStream& destStream)
  74809. {
  74810. return juce_writeJPEGImageToStream (sourceImage, destStream, quality);
  74811. }
  74812. class GIFImageFormat : public ImageFileFormat
  74813. {
  74814. public:
  74815. GIFImageFormat() {}
  74816. ~GIFImageFormat() {}
  74817. const String getFormatName()
  74818. {
  74819. return T("GIF");
  74820. }
  74821. bool canUnderstand (InputStream& in)
  74822. {
  74823. const int bytesNeeded = 4;
  74824. char header [bytesNeeded];
  74825. return (in.read (header, bytesNeeded) == bytesNeeded)
  74826. && header[0] == 'G'
  74827. && header[1] == 'I'
  74828. && header[2] == 'F';
  74829. }
  74830. Image* decodeImage (InputStream& in)
  74831. {
  74832. const ScopedPointer <GIFLoader> loader (new GIFLoader (in));
  74833. return loader->getImage();
  74834. }
  74835. bool writeImageToStream (const Image& /*sourceImage*/, OutputStream& /*destStream*/)
  74836. {
  74837. return false;
  74838. }
  74839. };
  74840. ImageFileFormat* ImageFileFormat::findImageFormatForStream (InputStream& input)
  74841. {
  74842. static PNGImageFormat png;
  74843. static JPEGImageFormat jpg;
  74844. static GIFImageFormat gif;
  74845. ImageFileFormat* formats[4];
  74846. int numFormats = 0;
  74847. formats [numFormats++] = &png;
  74848. formats [numFormats++] = &jpg;
  74849. formats [numFormats++] = &gif;
  74850. const int64 streamPos = input.getPosition();
  74851. for (int i = 0; i < numFormats; ++i)
  74852. {
  74853. const bool found = formats[i]->canUnderstand (input);
  74854. input.setPosition (streamPos);
  74855. if (found)
  74856. return formats[i];
  74857. }
  74858. return 0;
  74859. }
  74860. Image* ImageFileFormat::loadFrom (InputStream& input)
  74861. {
  74862. ImageFileFormat* const format = findImageFormatForStream (input);
  74863. if (format != 0)
  74864. return format->decodeImage (input);
  74865. return 0;
  74866. }
  74867. Image* ImageFileFormat::loadFrom (const File& file)
  74868. {
  74869. InputStream* const in = file.createInputStream();
  74870. if (in != 0)
  74871. {
  74872. BufferedInputStream b (in, 8192, true);
  74873. return loadFrom (b);
  74874. }
  74875. return 0;
  74876. }
  74877. Image* ImageFileFormat::loadFrom (const void* rawData, const int numBytes)
  74878. {
  74879. if (rawData != 0 && numBytes > 4)
  74880. {
  74881. MemoryInputStream stream (rawData, numBytes, false);
  74882. return loadFrom (stream);
  74883. }
  74884. return 0;
  74885. }
  74886. END_JUCE_NAMESPACE
  74887. /*** End of inlined file: juce_ImageFileFormat.cpp ***/
  74888. /*** Start of inlined file: juce_GIFLoader.cpp ***/
  74889. BEGIN_JUCE_NAMESPACE
  74890. GIFLoader::GIFLoader (InputStream& in)
  74891. : image (0),
  74892. input (in),
  74893. dataBlockIsZero (false),
  74894. fresh (false),
  74895. finished (false)
  74896. {
  74897. currentBit = lastBit = lastByteIndex = 0;
  74898. maxCode = maxCodeSize = codeSize = setCodeSize = 0;
  74899. firstcode = oldcode = 0;
  74900. clearCode = end_code = 0;
  74901. int imageWidth, imageHeight;
  74902. int transparent = -1;
  74903. if (! getSizeFromHeader (imageWidth, imageHeight))
  74904. return;
  74905. if ((imageWidth <= 0) || (imageHeight <= 0))
  74906. return;
  74907. unsigned char buf [16];
  74908. if (in.read (buf, 3) != 3)
  74909. return;
  74910. int numColours = 2 << (buf[0] & 7);
  74911. if ((buf[0] & 0x80) != 0)
  74912. readPalette (numColours);
  74913. for (;;)
  74914. {
  74915. if (input.read (buf, 1) != 1)
  74916. break;
  74917. if (buf[0] == ';')
  74918. break;
  74919. if (buf[0] == '!')
  74920. {
  74921. if (input.read (buf, 1) != 1)
  74922. break;
  74923. if (processExtension (buf[0], transparent) < 0)
  74924. break;
  74925. continue;
  74926. }
  74927. if (buf[0] != ',')
  74928. continue;
  74929. if (input.read (buf, 9) != 9)
  74930. break;
  74931. imageWidth = makeWord (buf[4], buf[5]);
  74932. imageHeight = makeWord (buf[6], buf[7]);
  74933. numColours = 2 << (buf[8] & 7);
  74934. if ((buf[8] & 0x80) != 0)
  74935. if (! readPalette (numColours))
  74936. break;
  74937. image = Image::createNativeImage ((transparent >= 0) ? Image::ARGB : Image::RGB,
  74938. imageWidth, imageHeight, (transparent >= 0));
  74939. readImage (imageWidth, imageHeight,
  74940. (buf[8] & 0x40) != 0,
  74941. transparent);
  74942. break;
  74943. }
  74944. }
  74945. GIFLoader::~GIFLoader()
  74946. {
  74947. }
  74948. bool GIFLoader::getSizeFromHeader (int& w, int& h)
  74949. {
  74950. unsigned char b [8];
  74951. if (input.read (b, 6) == 6)
  74952. {
  74953. if ((strncmp ("GIF87a", (char*) b, 6) == 0)
  74954. || (strncmp ("GIF89a", (char*) b, 6) == 0))
  74955. {
  74956. if (input.read (b, 4) == 4)
  74957. {
  74958. w = makeWord (b[0], b[1]);
  74959. h = makeWord (b[2], b[3]);
  74960. return true;
  74961. }
  74962. }
  74963. }
  74964. return false;
  74965. }
  74966. bool GIFLoader::readPalette (const int numCols)
  74967. {
  74968. unsigned char rgb[4];
  74969. for (int i = 0; i < numCols; ++i)
  74970. {
  74971. input.read (rgb, 3);
  74972. palette [i][0] = rgb[0];
  74973. palette [i][1] = rgb[1];
  74974. palette [i][2] = rgb[2];
  74975. palette [i][3] = 0xff;
  74976. }
  74977. return true;
  74978. }
  74979. int GIFLoader::readDataBlock (unsigned char* const dest)
  74980. {
  74981. unsigned char n;
  74982. if (input.read (&n, 1) == 1)
  74983. {
  74984. dataBlockIsZero = (n == 0);
  74985. if (dataBlockIsZero || (input.read (dest, n) == n))
  74986. return n;
  74987. }
  74988. return -1;
  74989. }
  74990. int GIFLoader::processExtension (const int type, int& transparent)
  74991. {
  74992. unsigned char b [300];
  74993. int n = 0;
  74994. if (type == 0xf9)
  74995. {
  74996. n = readDataBlock (b);
  74997. if (n < 0)
  74998. return 1;
  74999. if ((b[0] & 0x1) != 0)
  75000. transparent = b[3];
  75001. }
  75002. do
  75003. {
  75004. n = readDataBlock (b);
  75005. }
  75006. while (n > 0);
  75007. return n;
  75008. }
  75009. int GIFLoader::getCode (const int codeSize_, const bool initialise)
  75010. {
  75011. if (initialise)
  75012. {
  75013. currentBit = 0;
  75014. lastBit = 0;
  75015. finished = false;
  75016. return 0;
  75017. }
  75018. if ((currentBit + codeSize_) >= lastBit)
  75019. {
  75020. if (finished)
  75021. return -1;
  75022. buffer[0] = buffer [lastByteIndex - 2];
  75023. buffer[1] = buffer [lastByteIndex - 1];
  75024. const int n = readDataBlock (&buffer[2]);
  75025. if (n == 0)
  75026. finished = true;
  75027. lastByteIndex = 2 + n;
  75028. currentBit = (currentBit - lastBit) + 16;
  75029. lastBit = (2 + n) * 8 ;
  75030. }
  75031. int result = 0;
  75032. int i = currentBit;
  75033. for (int j = 0; j < codeSize_; ++j)
  75034. {
  75035. result |= ((buffer[i >> 3] & (1 << (i & 7))) != 0) << j;
  75036. ++i;
  75037. }
  75038. currentBit += codeSize_;
  75039. return result;
  75040. }
  75041. int GIFLoader::readLZWByte (const bool initialise, const int inputCodeSize)
  75042. {
  75043. int code, incode, i;
  75044. if (initialise)
  75045. {
  75046. setCodeSize = inputCodeSize;
  75047. codeSize = setCodeSize + 1;
  75048. clearCode = 1 << setCodeSize;
  75049. end_code = clearCode + 1;
  75050. maxCodeSize = 2 * clearCode;
  75051. maxCode = clearCode + 2;
  75052. getCode (0, true);
  75053. fresh = true;
  75054. for (i = 0; i < clearCode; ++i)
  75055. {
  75056. table[0][i] = 0;
  75057. table[1][i] = i;
  75058. }
  75059. for (; i < maxGifCode; ++i)
  75060. {
  75061. table[0][i] = 0;
  75062. table[1][i] = 0;
  75063. }
  75064. sp = stack;
  75065. return 0;
  75066. }
  75067. else if (fresh)
  75068. {
  75069. fresh = false;
  75070. do
  75071. {
  75072. firstcode = oldcode
  75073. = getCode (codeSize, false);
  75074. }
  75075. while (firstcode == clearCode);
  75076. return firstcode;
  75077. }
  75078. if (sp > stack)
  75079. return *--sp;
  75080. while ((code = getCode (codeSize, false)) >= 0)
  75081. {
  75082. if (code == clearCode)
  75083. {
  75084. for (i = 0; i < clearCode; ++i)
  75085. {
  75086. table[0][i] = 0;
  75087. table[1][i] = i;
  75088. }
  75089. for (; i < maxGifCode; ++i)
  75090. {
  75091. table[0][i] = 0;
  75092. table[1][i] = 0;
  75093. }
  75094. codeSize = setCodeSize + 1;
  75095. maxCodeSize = 2 * clearCode;
  75096. maxCode = clearCode + 2;
  75097. sp = stack;
  75098. firstcode = oldcode = getCode (codeSize, false);
  75099. return firstcode;
  75100. }
  75101. else if (code == end_code)
  75102. {
  75103. if (dataBlockIsZero)
  75104. return -2;
  75105. unsigned char buf [260];
  75106. int n;
  75107. while ((n = readDataBlock (buf)) > 0)
  75108. {}
  75109. if (n != 0)
  75110. return -2;
  75111. }
  75112. incode = code;
  75113. if (code >= maxCode)
  75114. {
  75115. *sp++ = firstcode;
  75116. code = oldcode;
  75117. }
  75118. while (code >= clearCode)
  75119. {
  75120. *sp++ = table[1][code];
  75121. if (code == table[0][code])
  75122. return -2;
  75123. code = table[0][code];
  75124. }
  75125. *sp++ = firstcode = table[1][code];
  75126. if ((code = maxCode) < maxGifCode)
  75127. {
  75128. table[0][code] = oldcode;
  75129. table[1][code] = firstcode;
  75130. ++maxCode;
  75131. if ((maxCode >= maxCodeSize)
  75132. && (maxCodeSize < maxGifCode))
  75133. {
  75134. maxCodeSize <<= 1;
  75135. ++codeSize;
  75136. }
  75137. }
  75138. oldcode = incode;
  75139. if (sp > stack)
  75140. return *--sp;
  75141. }
  75142. return code;
  75143. }
  75144. bool GIFLoader::readImage (const int width, const int height,
  75145. const int interlace, const int transparent)
  75146. {
  75147. unsigned char c;
  75148. if (input.read (&c, 1) != 1
  75149. || readLZWByte (true, c) < 0)
  75150. return false;
  75151. if (transparent >= 0)
  75152. {
  75153. palette [transparent][0] = 0;
  75154. palette [transparent][1] = 0;
  75155. palette [transparent][2] = 0;
  75156. palette [transparent][3] = 0;
  75157. }
  75158. int index;
  75159. int xpos = 0, ypos = 0, pass = 0;
  75160. const Image::BitmapData destData (*image, 0, 0, width, height, true);
  75161. uint8* p = destData.data;
  75162. const bool hasAlpha = image->hasAlphaChannel();
  75163. while ((index = readLZWByte (false, c)) >= 0)
  75164. {
  75165. const uint8* const paletteEntry = palette [index];
  75166. if (hasAlpha)
  75167. {
  75168. ((PixelARGB*) p)->setARGB (paletteEntry[3],
  75169. paletteEntry[0],
  75170. paletteEntry[1],
  75171. paletteEntry[2]);
  75172. ((PixelARGB*) p)->premultiply();
  75173. }
  75174. else
  75175. {
  75176. ((PixelRGB*) p)->setARGB (0,
  75177. paletteEntry[0],
  75178. paletteEntry[1],
  75179. paletteEntry[2]);
  75180. }
  75181. p += destData.pixelStride;
  75182. ++xpos;
  75183. if (xpos == width)
  75184. {
  75185. xpos = 0;
  75186. if (interlace)
  75187. {
  75188. switch (pass)
  75189. {
  75190. case 0:
  75191. case 1:
  75192. ypos += 8;
  75193. break;
  75194. case 2:
  75195. ypos += 4;
  75196. break;
  75197. case 3:
  75198. ypos += 2;
  75199. break;
  75200. }
  75201. while (ypos >= height)
  75202. {
  75203. ++pass;
  75204. switch (pass)
  75205. {
  75206. case 1:
  75207. ypos = 4;
  75208. break;
  75209. case 2:
  75210. ypos = 2;
  75211. break;
  75212. case 3:
  75213. ypos = 1;
  75214. break;
  75215. default:
  75216. return true;
  75217. }
  75218. }
  75219. }
  75220. else
  75221. {
  75222. ++ypos;
  75223. }
  75224. p = destData.getPixelPointer (xpos, ypos);
  75225. }
  75226. if (ypos >= height)
  75227. break;
  75228. }
  75229. return true;
  75230. }
  75231. END_JUCE_NAMESPACE
  75232. /*** End of inlined file: juce_GIFLoader.cpp ***/
  75233. #endif
  75234. //==============================================================================
  75235. // some files include lots of library code, so leave them to the end to avoid cluttering
  75236. // up the build for the clean files.
  75237. #if JUCE_BUILD_CORE
  75238. /*** Start of inlined file: juce_GZIPCompressorOutputStream.cpp ***/
  75239. namespace zlibNamespace
  75240. {
  75241. #if JUCE_INCLUDE_ZLIB_CODE
  75242. #undef OS_CODE
  75243. #undef fdopen
  75244. /*** Start of inlined file: zlib.h ***/
  75245. #ifndef ZLIB_H
  75246. #define ZLIB_H
  75247. /*** Start of inlined file: zconf.h ***/
  75248. #ifndef ZCONF_H
  75249. #define ZCONF_H
  75250. // *** Just a few hacks here to make it compile nicely with Juce..
  75251. #define Z_PREFIX 1
  75252. #undef __MACTYPES__
  75253. #ifdef _MSC_VER
  75254. #pragma warning (disable : 4131 4127 4244 4267)
  75255. #endif
  75256. #ifdef Z_PREFIX
  75257. # define deflateInit_ z_deflateInit_
  75258. # define deflate z_deflate
  75259. # define deflateEnd z_deflateEnd
  75260. # define inflateInit_ z_inflateInit_
  75261. # define inflate z_inflate
  75262. # define inflateEnd z_inflateEnd
  75263. # define deflateInit2_ z_deflateInit2_
  75264. # define deflateSetDictionary z_deflateSetDictionary
  75265. # define deflateCopy z_deflateCopy
  75266. # define deflateReset z_deflateReset
  75267. # define deflateParams z_deflateParams
  75268. # define deflateBound z_deflateBound
  75269. # define deflatePrime z_deflatePrime
  75270. # define inflateInit2_ z_inflateInit2_
  75271. # define inflateSetDictionary z_inflateSetDictionary
  75272. # define inflateSync z_inflateSync
  75273. # define inflateSyncPoint z_inflateSyncPoint
  75274. # define inflateCopy z_inflateCopy
  75275. # define inflateReset z_inflateReset
  75276. # define inflateBack z_inflateBack
  75277. # define inflateBackEnd z_inflateBackEnd
  75278. # define compress z_compress
  75279. # define compress2 z_compress2
  75280. # define compressBound z_compressBound
  75281. # define uncompress z_uncompress
  75282. # define adler32 z_adler32
  75283. # define crc32 z_crc32
  75284. # define get_crc_table z_get_crc_table
  75285. # define zError z_zError
  75286. # define alloc_func z_alloc_func
  75287. # define free_func z_free_func
  75288. # define in_func z_in_func
  75289. # define out_func z_out_func
  75290. # define Byte z_Byte
  75291. # define uInt z_uInt
  75292. # define uLong z_uLong
  75293. # define Bytef z_Bytef
  75294. # define charf z_charf
  75295. # define intf z_intf
  75296. # define uIntf z_uIntf
  75297. # define uLongf z_uLongf
  75298. # define voidpf z_voidpf
  75299. # define voidp z_voidp
  75300. #endif
  75301. #if defined(__MSDOS__) && !defined(MSDOS)
  75302. # define MSDOS
  75303. #endif
  75304. #if (defined(OS_2) || defined(__OS2__)) && !defined(OS2)
  75305. # define OS2
  75306. #endif
  75307. #if defined(_WINDOWS) && !defined(WINDOWS)
  75308. # define WINDOWS
  75309. #endif
  75310. #if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__)
  75311. # ifndef WIN32
  75312. # define WIN32
  75313. # endif
  75314. #endif
  75315. #if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32)
  75316. # if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__)
  75317. # ifndef SYS16BIT
  75318. # define SYS16BIT
  75319. # endif
  75320. # endif
  75321. #endif
  75322. #ifdef SYS16BIT
  75323. # define MAXSEG_64K
  75324. #endif
  75325. #ifdef MSDOS
  75326. # define UNALIGNED_OK
  75327. #endif
  75328. #ifdef __STDC_VERSION__
  75329. # ifndef STDC
  75330. # define STDC
  75331. # endif
  75332. # if __STDC_VERSION__ >= 199901L
  75333. # ifndef STDC99
  75334. # define STDC99
  75335. # endif
  75336. # endif
  75337. #endif
  75338. #if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus))
  75339. # define STDC
  75340. #endif
  75341. #if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__))
  75342. # define STDC
  75343. #endif
  75344. #if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32))
  75345. # define STDC
  75346. #endif
  75347. #if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__))
  75348. # define STDC
  75349. #endif
  75350. #if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */
  75351. # define STDC
  75352. #endif
  75353. #ifndef STDC
  75354. # ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
  75355. # define const /* note: need a more gentle solution here */
  75356. # endif
  75357. #endif
  75358. #if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
  75359. # define NO_DUMMY_DECL
  75360. #endif
  75361. #ifndef MAX_MEM_LEVEL
  75362. # ifdef MAXSEG_64K
  75363. # define MAX_MEM_LEVEL 8
  75364. # else
  75365. # define MAX_MEM_LEVEL 9
  75366. # endif
  75367. #endif
  75368. #ifndef MAX_WBITS
  75369. # define MAX_WBITS 15 /* 32K LZ77 window */
  75370. #endif
  75371. #ifndef OF /* function prototypes */
  75372. # ifdef STDC
  75373. # define OF(args) args
  75374. # else
  75375. # define OF(args) ()
  75376. # endif
  75377. #endif
  75378. #ifdef SYS16BIT
  75379. # if defined(M_I86SM) || defined(M_I86MM)
  75380. # define SMALL_MEDIUM
  75381. # ifdef _MSC_VER
  75382. # define FAR _far
  75383. # else
  75384. # define FAR far
  75385. # endif
  75386. # endif
  75387. # if (defined(__SMALL__) || defined(__MEDIUM__))
  75388. # define SMALL_MEDIUM
  75389. # ifdef __BORLANDC__
  75390. # define FAR _far
  75391. # else
  75392. # define FAR far
  75393. # endif
  75394. # endif
  75395. #endif
  75396. #if defined(WINDOWS) || defined(WIN32)
  75397. # ifdef ZLIB_DLL
  75398. # if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500))
  75399. # ifdef ZLIB_INTERNAL
  75400. # define ZEXTERN extern __declspec(dllexport)
  75401. # else
  75402. # define ZEXTERN extern __declspec(dllimport)
  75403. # endif
  75404. # endif
  75405. # endif /* ZLIB_DLL */
  75406. # ifdef ZLIB_WINAPI
  75407. # ifdef FAR
  75408. # undef FAR
  75409. # endif
  75410. # include <windows.h>
  75411. # define ZEXPORT WINAPI
  75412. # ifdef WIN32
  75413. # define ZEXPORTVA WINAPIV
  75414. # else
  75415. # define ZEXPORTVA FAR CDECL
  75416. # endif
  75417. # endif
  75418. #endif
  75419. #if defined (__BEOS__)
  75420. # ifdef ZLIB_DLL
  75421. # ifdef ZLIB_INTERNAL
  75422. # define ZEXPORT __declspec(dllexport)
  75423. # define ZEXPORTVA __declspec(dllexport)
  75424. # else
  75425. # define ZEXPORT __declspec(dllimport)
  75426. # define ZEXPORTVA __declspec(dllimport)
  75427. # endif
  75428. # endif
  75429. #endif
  75430. #ifndef ZEXTERN
  75431. # define ZEXTERN extern
  75432. #endif
  75433. #ifndef ZEXPORT
  75434. # define ZEXPORT
  75435. #endif
  75436. #ifndef ZEXPORTVA
  75437. # define ZEXPORTVA
  75438. #endif
  75439. #ifndef FAR
  75440. # define FAR
  75441. #endif
  75442. #if !defined(__MACTYPES__)
  75443. typedef unsigned char Byte; /* 8 bits */
  75444. #endif
  75445. typedef unsigned int uInt; /* 16 bits or more */
  75446. typedef unsigned long uLong; /* 32 bits or more */
  75447. #ifdef SMALL_MEDIUM
  75448. # define Bytef Byte FAR
  75449. #else
  75450. typedef Byte FAR Bytef;
  75451. #endif
  75452. typedef char FAR charf;
  75453. typedef int FAR intf;
  75454. typedef uInt FAR uIntf;
  75455. typedef uLong FAR uLongf;
  75456. #ifdef STDC
  75457. typedef void const *voidpc;
  75458. typedef void FAR *voidpf;
  75459. typedef void *voidp;
  75460. #else
  75461. typedef Byte const *voidpc;
  75462. typedef Byte FAR *voidpf;
  75463. typedef Byte *voidp;
  75464. #endif
  75465. #if 0 /* HAVE_UNISTD_H -- this line is updated by ./configure */
  75466. # include <sys/types.h> /* for off_t */
  75467. # include <unistd.h> /* for SEEK_* and off_t */
  75468. # ifdef VMS
  75469. # include <unixio.h> /* for off_t */
  75470. # endif
  75471. # define z_off_t off_t
  75472. #endif
  75473. #ifndef SEEK_SET
  75474. # define SEEK_SET 0 /* Seek from beginning of file. */
  75475. # define SEEK_CUR 1 /* Seek from current position. */
  75476. # define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
  75477. #endif
  75478. #ifndef z_off_t
  75479. # define z_off_t long
  75480. #endif
  75481. #if defined(__OS400__)
  75482. # define NO_vsnprintf
  75483. #endif
  75484. #if defined(__MVS__)
  75485. # define NO_vsnprintf
  75486. # ifdef FAR
  75487. # undef FAR
  75488. # endif
  75489. #endif
  75490. #if defined(__MVS__)
  75491. # pragma map(deflateInit_,"DEIN")
  75492. # pragma map(deflateInit2_,"DEIN2")
  75493. # pragma map(deflateEnd,"DEEND")
  75494. # pragma map(deflateBound,"DEBND")
  75495. # pragma map(inflateInit_,"ININ")
  75496. # pragma map(inflateInit2_,"ININ2")
  75497. # pragma map(inflateEnd,"INEND")
  75498. # pragma map(inflateSync,"INSY")
  75499. # pragma map(inflateSetDictionary,"INSEDI")
  75500. # pragma map(compressBound,"CMBND")
  75501. # pragma map(inflate_table,"INTABL")
  75502. # pragma map(inflate_fast,"INFA")
  75503. # pragma map(inflate_copyright,"INCOPY")
  75504. #endif
  75505. #endif /* ZCONF_H */
  75506. /*** End of inlined file: zconf.h ***/
  75507. #ifdef __cplusplus
  75508. extern "C" {
  75509. #endif
  75510. #define ZLIB_VERSION "1.2.3"
  75511. #define ZLIB_VERNUM 0x1230
  75512. typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
  75513. typedef void (*free_func) OF((voidpf opaque, voidpf address));
  75514. struct internal_state;
  75515. typedef struct z_stream_s {
  75516. Bytef *next_in; /* next input byte */
  75517. uInt avail_in; /* number of bytes available at next_in */
  75518. uLong total_in; /* total nb of input bytes read so far */
  75519. Bytef *next_out; /* next output byte should be put there */
  75520. uInt avail_out; /* remaining free space at next_out */
  75521. uLong total_out; /* total nb of bytes output so far */
  75522. char *msg; /* last error message, NULL if no error */
  75523. struct internal_state FAR *state; /* not visible by applications */
  75524. alloc_func zalloc; /* used to allocate the internal state */
  75525. free_func zfree; /* used to free the internal state */
  75526. voidpf opaque; /* private data object passed to zalloc and zfree */
  75527. int data_type; /* best guess about the data type: binary or text */
  75528. uLong adler; /* adler32 value of the uncompressed data */
  75529. uLong reserved; /* reserved for future use */
  75530. } z_stream;
  75531. typedef z_stream FAR *z_streamp;
  75532. typedef struct gz_header_s {
  75533. int text; /* true if compressed data believed to be text */
  75534. uLong time; /* modification time */
  75535. int xflags; /* extra flags (not used when writing a gzip file) */
  75536. int os; /* operating system */
  75537. Bytef *extra; /* pointer to extra field or Z_NULL if none */
  75538. uInt extra_len; /* extra field length (valid if extra != Z_NULL) */
  75539. uInt extra_max; /* space at extra (only when reading header) */
  75540. Bytef *name; /* pointer to zero-terminated file name or Z_NULL */
  75541. uInt name_max; /* space at name (only when reading header) */
  75542. Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */
  75543. uInt comm_max; /* space at comment (only when reading header) */
  75544. int hcrc; /* true if there was or will be a header crc */
  75545. int done; /* true when done reading gzip header (not used
  75546. when writing a gzip file) */
  75547. } gz_header;
  75548. typedef gz_header FAR *gz_headerp;
  75549. #define Z_NO_FLUSH 0
  75550. #define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
  75551. #define Z_SYNC_FLUSH 2
  75552. #define Z_FULL_FLUSH 3
  75553. #define Z_FINISH 4
  75554. #define Z_BLOCK 5
  75555. #define Z_OK 0
  75556. #define Z_STREAM_END 1
  75557. #define Z_NEED_DICT 2
  75558. #define Z_ERRNO (-1)
  75559. #define Z_STREAM_ERROR (-2)
  75560. #define Z_DATA_ERROR (-3)
  75561. #define Z_MEM_ERROR (-4)
  75562. #define Z_BUF_ERROR (-5)
  75563. #define Z_VERSION_ERROR (-6)
  75564. #define Z_NO_COMPRESSION 0
  75565. #define Z_BEST_SPEED 1
  75566. #define Z_BEST_COMPRESSION 9
  75567. #define Z_DEFAULT_COMPRESSION (-1)
  75568. #define Z_FILTERED 1
  75569. #define Z_HUFFMAN_ONLY 2
  75570. #define Z_RLE 3
  75571. #define Z_FIXED 4
  75572. #define Z_DEFAULT_STRATEGY 0
  75573. #define Z_BINARY 0
  75574. #define Z_TEXT 1
  75575. #define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */
  75576. #define Z_UNKNOWN 2
  75577. #define Z_DEFLATED 8
  75578. #define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
  75579. #define zlib_version zlibVersion()
  75580. //ZEXTERN const char * ZEXPORT zlibVersion OF((void));
  75581. ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
  75582. ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
  75583. ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
  75584. ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
  75585. ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
  75586. const Bytef *dictionary,
  75587. uInt dictLength));
  75588. ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
  75589. z_streamp source));
  75590. ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
  75591. ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
  75592. int level,
  75593. int strategy));
  75594. ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm,
  75595. int good_length,
  75596. int max_lazy,
  75597. int nice_length,
  75598. int max_chain));
  75599. ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm,
  75600. uLong sourceLen));
  75601. ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
  75602. int bits,
  75603. int value));
  75604. ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm,
  75605. gz_headerp head));
  75606. ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
  75607. const Bytef *dictionary,
  75608. uInt dictLength));
  75609. ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
  75610. ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,
  75611. z_streamp source));
  75612. ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
  75613. ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm,
  75614. int bits,
  75615. int value));
  75616. ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm,
  75617. gz_headerp head));
  75618. typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *));
  75619. typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned));
  75620. ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
  75621. in_func in, void FAR *in_desc,
  75622. out_func out, void FAR *out_desc));
  75623. ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm));
  75624. //ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void));
  75625. ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen,
  75626. const Bytef *source, uLong sourceLen));
  75627. ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
  75628. const Bytef *source, uLong sourceLen,
  75629. int level));
  75630. ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen));
  75631. ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
  75632. const Bytef *source, uLong sourceLen));
  75633. typedef voidp gzFile;
  75634. ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
  75635. ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
  75636. ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
  75637. ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
  75638. ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
  75639. voidpc buf, unsigned len));
  75640. ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...));
  75641. ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
  75642. ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
  75643. ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c));
  75644. ZEXTERN int ZEXPORT gzgetc OF((gzFile file));
  75645. ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file));
  75646. ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));
  75647. ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file,
  75648. z_off_t offset, int whence));
  75649. ZEXTERN int ZEXPORT gzrewind OF((gzFile file));
  75650. ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file));
  75651. ZEXTERN int ZEXPORT gzeof OF((gzFile file));
  75652. ZEXTERN int ZEXPORT gzdirect OF((gzFile file));
  75653. ZEXTERN int ZEXPORT gzclose OF((gzFile file));
  75654. ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
  75655. ZEXTERN void ZEXPORT gzclearerr OF((gzFile file));
  75656. ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
  75657. ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2,
  75658. z_off_t len2));
  75659. ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
  75660. ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2));
  75661. ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level,
  75662. const char *version, int stream_size));
  75663. ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm,
  75664. const char *version, int stream_size));
  75665. ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method,
  75666. int windowBits, int memLevel,
  75667. int strategy, const char *version,
  75668. int stream_size));
  75669. ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits,
  75670. const char *version, int stream_size));
  75671. ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
  75672. unsigned char FAR *window,
  75673. const char *version,
  75674. int stream_size));
  75675. #define deflateInit(strm, level) \
  75676. deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream))
  75677. #define inflateInit(strm) \
  75678. inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream))
  75679. #define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
  75680. deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
  75681. (strategy), ZLIB_VERSION, sizeof(z_stream))
  75682. #define inflateInit2(strm, windowBits) \
  75683. inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
  75684. #define inflateBackInit(strm, windowBits, window) \
  75685. inflateBackInit_((strm), (windowBits), (window), \
  75686. ZLIB_VERSION, sizeof(z_stream))
  75687. #if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL)
  75688. struct internal_state {int dummy;}; /* hack for buggy compilers */
  75689. #endif
  75690. ZEXTERN const char * ZEXPORT zError OF((int));
  75691. ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z));
  75692. ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void));
  75693. #ifdef __cplusplus
  75694. }
  75695. #endif
  75696. #endif /* ZLIB_H */
  75697. /*** End of inlined file: zlib.h ***/
  75698. #undef OS_CODE
  75699. #else
  75700. #include <zlib.h>
  75701. #endif
  75702. }
  75703. BEGIN_JUCE_NAMESPACE
  75704. using namespace zlibNamespace;
  75705. // internal helper object that holds the zlib structures so they don't have to be
  75706. // included publicly.
  75707. class GZIPCompressorHelper
  75708. {
  75709. public:
  75710. GZIPCompressorHelper (const int compressionLevel, const bool nowrap)
  75711. : data (0),
  75712. dataSize (0),
  75713. compLevel (compressionLevel),
  75714. strategy (0),
  75715. setParams (true),
  75716. streamIsValid (false),
  75717. finished (false),
  75718. shouldFinish (false)
  75719. {
  75720. zerostruct (stream);
  75721. streamIsValid = (deflateInit2 (&stream, compLevel, Z_DEFLATED,
  75722. nowrap ? -MAX_WBITS : MAX_WBITS,
  75723. 8, strategy) == Z_OK);
  75724. }
  75725. ~GZIPCompressorHelper()
  75726. {
  75727. if (streamIsValid)
  75728. deflateEnd (&stream);
  75729. }
  75730. bool needsInput() const throw()
  75731. {
  75732. return dataSize <= 0;
  75733. }
  75734. void setInput (uint8* const newData, const int size) throw()
  75735. {
  75736. data = newData;
  75737. dataSize = size;
  75738. }
  75739. int doNextBlock (uint8* const dest, const int destSize) throw()
  75740. {
  75741. if (streamIsValid)
  75742. {
  75743. stream.next_in = data;
  75744. stream.next_out = dest;
  75745. stream.avail_in = dataSize;
  75746. stream.avail_out = destSize;
  75747. const int result = setParams ? deflateParams (&stream, compLevel, strategy)
  75748. : deflate (&stream, shouldFinish ? Z_FINISH : Z_NO_FLUSH);
  75749. setParams = false;
  75750. switch (result)
  75751. {
  75752. case Z_STREAM_END:
  75753. finished = true;
  75754. // Deliberate fall-through..
  75755. case Z_OK:
  75756. data += dataSize - stream.avail_in;
  75757. dataSize = stream.avail_in;
  75758. return destSize - stream.avail_out;
  75759. default:
  75760. break;
  75761. }
  75762. }
  75763. return 0;
  75764. }
  75765. private:
  75766. z_stream stream;
  75767. uint8* data;
  75768. int dataSize, compLevel, strategy;
  75769. bool setParams, streamIsValid;
  75770. public:
  75771. bool finished, shouldFinish;
  75772. };
  75773. const int gzipCompBufferSize = 32768;
  75774. GZIPCompressorOutputStream::GZIPCompressorOutputStream (OutputStream* const destStream_,
  75775. int compressionLevel,
  75776. const bool deleteDestStream,
  75777. const bool noWrap)
  75778. : destStream (destStream_),
  75779. streamToDelete (deleteDestStream ? destStream_ : 0),
  75780. buffer (gzipCompBufferSize)
  75781. {
  75782. if (compressionLevel < 1 || compressionLevel > 9)
  75783. compressionLevel = -1;
  75784. helper = new GZIPCompressorHelper (compressionLevel, noWrap);
  75785. }
  75786. GZIPCompressorOutputStream::~GZIPCompressorOutputStream()
  75787. {
  75788. flush();
  75789. }
  75790. void GZIPCompressorOutputStream::flush()
  75791. {
  75792. if (! helper->finished)
  75793. {
  75794. helper->shouldFinish = true;
  75795. while (! helper->finished)
  75796. doNextBlock();
  75797. }
  75798. destStream->flush();
  75799. }
  75800. bool GZIPCompressorOutputStream::write (const void* destBuffer, int howMany)
  75801. {
  75802. if (! helper->finished)
  75803. {
  75804. helper->setInput ((uint8*) destBuffer, howMany);
  75805. while (! helper->needsInput())
  75806. {
  75807. if (! doNextBlock())
  75808. return false;
  75809. }
  75810. }
  75811. return true;
  75812. }
  75813. bool GZIPCompressorOutputStream::doNextBlock()
  75814. {
  75815. const int len = helper->doNextBlock (buffer, gzipCompBufferSize);
  75816. if (len > 0)
  75817. return destStream->write (buffer, len);
  75818. else
  75819. return true;
  75820. }
  75821. int64 GZIPCompressorOutputStream::getPosition()
  75822. {
  75823. return destStream->getPosition();
  75824. }
  75825. bool GZIPCompressorOutputStream::setPosition (int64 /*newPosition*/)
  75826. {
  75827. jassertfalse // can't do it!
  75828. return false;
  75829. }
  75830. END_JUCE_NAMESPACE
  75831. /*** End of inlined file: juce_GZIPCompressorOutputStream.cpp ***/
  75832. /*** Start of inlined file: juce_GZIPDecompressorInputStream.cpp ***/
  75833. #if JUCE_MSVC
  75834. #pragma warning (push)
  75835. #pragma warning (disable: 4309 4305)
  75836. #endif
  75837. namespace zlibNamespace
  75838. {
  75839. #if JUCE_INCLUDE_ZLIB_CODE
  75840. extern "C"
  75841. {
  75842. #undef OS_CODE
  75843. #undef fdopen
  75844. #define ZLIB_INTERNAL
  75845. #define NO_DUMMY_DECL
  75846. /*** Start of inlined file: adler32.c ***/
  75847. #define ZLIB_INTERNAL
  75848. #define BASE 65521UL /* largest prime smaller than 65536 */
  75849. #define NMAX 5552
  75850. #define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;}
  75851. #define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
  75852. #define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
  75853. #define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
  75854. #define DO16(buf) DO8(buf,0); DO8(buf,8);
  75855. #ifdef NO_DIVIDE
  75856. # define MOD(a) \
  75857. do { \
  75858. if (a >= (BASE << 16)) a -= (BASE << 16); \
  75859. if (a >= (BASE << 15)) a -= (BASE << 15); \
  75860. if (a >= (BASE << 14)) a -= (BASE << 14); \
  75861. if (a >= (BASE << 13)) a -= (BASE << 13); \
  75862. if (a >= (BASE << 12)) a -= (BASE << 12); \
  75863. if (a >= (BASE << 11)) a -= (BASE << 11); \
  75864. if (a >= (BASE << 10)) a -= (BASE << 10); \
  75865. if (a >= (BASE << 9)) a -= (BASE << 9); \
  75866. if (a >= (BASE << 8)) a -= (BASE << 8); \
  75867. if (a >= (BASE << 7)) a -= (BASE << 7); \
  75868. if (a >= (BASE << 6)) a -= (BASE << 6); \
  75869. if (a >= (BASE << 5)) a -= (BASE << 5); \
  75870. if (a >= (BASE << 4)) a -= (BASE << 4); \
  75871. if (a >= (BASE << 3)) a -= (BASE << 3); \
  75872. if (a >= (BASE << 2)) a -= (BASE << 2); \
  75873. if (a >= (BASE << 1)) a -= (BASE << 1); \
  75874. if (a >= BASE) a -= BASE; \
  75875. } while (0)
  75876. # define MOD4(a) \
  75877. do { \
  75878. if (a >= (BASE << 4)) a -= (BASE << 4); \
  75879. if (a >= (BASE << 3)) a -= (BASE << 3); \
  75880. if (a >= (BASE << 2)) a -= (BASE << 2); \
  75881. if (a >= (BASE << 1)) a -= (BASE << 1); \
  75882. if (a >= BASE) a -= BASE; \
  75883. } while (0)
  75884. #else
  75885. # define MOD(a) a %= BASE
  75886. # define MOD4(a) a %= BASE
  75887. #endif
  75888. uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len)
  75889. {
  75890. unsigned long sum2;
  75891. unsigned n;
  75892. sum2 = (adler >> 16) & 0xffff;
  75893. adler &= 0xffff;
  75894. if (len == 1) {
  75895. adler += buf[0];
  75896. if (adler >= BASE)
  75897. adler -= BASE;
  75898. sum2 += adler;
  75899. if (sum2 >= BASE)
  75900. sum2 -= BASE;
  75901. return adler | (sum2 << 16);
  75902. }
  75903. if (buf == Z_NULL)
  75904. return 1L;
  75905. if (len < 16) {
  75906. while (len--) {
  75907. adler += *buf++;
  75908. sum2 += adler;
  75909. }
  75910. if (adler >= BASE)
  75911. adler -= BASE;
  75912. MOD4(sum2); /* only added so many BASE's */
  75913. return adler | (sum2 << 16);
  75914. }
  75915. while (len >= NMAX) {
  75916. len -= NMAX;
  75917. n = NMAX / 16; /* NMAX is divisible by 16 */
  75918. do {
  75919. DO16(buf); /* 16 sums unrolled */
  75920. buf += 16;
  75921. } while (--n);
  75922. MOD(adler);
  75923. MOD(sum2);
  75924. }
  75925. if (len) { /* avoid modulos if none remaining */
  75926. while (len >= 16) {
  75927. len -= 16;
  75928. DO16(buf);
  75929. buf += 16;
  75930. }
  75931. while (len--) {
  75932. adler += *buf++;
  75933. sum2 += adler;
  75934. }
  75935. MOD(adler);
  75936. MOD(sum2);
  75937. }
  75938. return adler | (sum2 << 16);
  75939. }
  75940. uLong ZEXPORT adler32_combine(uLong adler1, uLong adler2, z_off_t len2)
  75941. {
  75942. unsigned long sum1;
  75943. unsigned long sum2;
  75944. unsigned rem;
  75945. rem = (unsigned)(len2 % BASE);
  75946. sum1 = adler1 & 0xffff;
  75947. sum2 = rem * sum1;
  75948. MOD(sum2);
  75949. sum1 += (adler2 & 0xffff) + BASE - 1;
  75950. sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
  75951. if (sum1 > BASE) sum1 -= BASE;
  75952. if (sum1 > BASE) sum1 -= BASE;
  75953. if (sum2 > (BASE << 1)) sum2 -= (BASE << 1);
  75954. if (sum2 > BASE) sum2 -= BASE;
  75955. return sum1 | (sum2 << 16);
  75956. }
  75957. /*** End of inlined file: adler32.c ***/
  75958. /*** Start of inlined file: compress.c ***/
  75959. #define ZLIB_INTERNAL
  75960. int ZEXPORT compress2 (Bytef *dest, uLongf *destLen, const Bytef *source,
  75961. uLong sourceLen, int level)
  75962. {
  75963. z_stream stream;
  75964. int err;
  75965. stream.next_in = (Bytef*)source;
  75966. stream.avail_in = (uInt)sourceLen;
  75967. #ifdef MAXSEG_64K
  75968. if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
  75969. #endif
  75970. stream.next_out = dest;
  75971. stream.avail_out = (uInt)*destLen;
  75972. if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
  75973. stream.zalloc = (alloc_func)0;
  75974. stream.zfree = (free_func)0;
  75975. stream.opaque = (voidpf)0;
  75976. err = deflateInit(&stream, level);
  75977. if (err != Z_OK) return err;
  75978. err = deflate(&stream, Z_FINISH);
  75979. if (err != Z_STREAM_END) {
  75980. deflateEnd(&stream);
  75981. return err == Z_OK ? Z_BUF_ERROR : err;
  75982. }
  75983. *destLen = stream.total_out;
  75984. err = deflateEnd(&stream);
  75985. return err;
  75986. }
  75987. int ZEXPORT compress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)
  75988. {
  75989. return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
  75990. }
  75991. uLong ZEXPORT compressBound (uLong sourceLen)
  75992. {
  75993. return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + 11;
  75994. }
  75995. /*** End of inlined file: compress.c ***/
  75996. #undef DO1
  75997. #undef DO8
  75998. /*** Start of inlined file: crc32.c ***/
  75999. #ifdef MAKECRCH
  76000. # include <stdio.h>
  76001. # ifndef DYNAMIC_CRC_TABLE
  76002. # define DYNAMIC_CRC_TABLE
  76003. # endif /* !DYNAMIC_CRC_TABLE */
  76004. #endif /* MAKECRCH */
  76005. /*** Start of inlined file: zutil.h ***/
  76006. #ifndef ZUTIL_H
  76007. #define ZUTIL_H
  76008. #define ZLIB_INTERNAL
  76009. #ifdef STDC
  76010. # ifndef _WIN32_WCE
  76011. # include <stddef.h>
  76012. # endif
  76013. # include <string.h>
  76014. # include <stdlib.h>
  76015. #endif
  76016. #ifdef NO_ERRNO_H
  76017. # ifdef _WIN32_WCE
  76018. # define errno z_errno
  76019. # endif
  76020. extern int errno;
  76021. #else
  76022. # ifndef _WIN32_WCE
  76023. # include <errno.h>
  76024. # endif
  76025. #endif
  76026. #ifndef local
  76027. # define local static
  76028. #endif
  76029. typedef unsigned char uch;
  76030. typedef uch FAR uchf;
  76031. typedef unsigned short ush;
  76032. typedef ush FAR ushf;
  76033. typedef unsigned long ulg;
  76034. extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
  76035. #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
  76036. #define ERR_RETURN(strm,err) \
  76037. return (strm->msg = (char*)ERR_MSG(err), (err))
  76038. #ifndef DEF_WBITS
  76039. # define DEF_WBITS MAX_WBITS
  76040. #endif
  76041. #if MAX_MEM_LEVEL >= 8
  76042. # define DEF_MEM_LEVEL 8
  76043. #else
  76044. # define DEF_MEM_LEVEL MAX_MEM_LEVEL
  76045. #endif
  76046. #define STORED_BLOCK 0
  76047. #define STATIC_TREES 1
  76048. #define DYN_TREES 2
  76049. #define MIN_MATCH 3
  76050. #define MAX_MATCH 258
  76051. #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
  76052. #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
  76053. # define OS_CODE 0x00
  76054. # if defined(__TURBOC__) || defined(__BORLANDC__)
  76055. # if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
  76056. void _Cdecl farfree( void *block );
  76057. void *_Cdecl farmalloc( unsigned long nbytes );
  76058. # else
  76059. # include <alloc.h>
  76060. # endif
  76061. # else /* MSC or DJGPP */
  76062. # include <malloc.h>
  76063. # endif
  76064. #endif
  76065. #ifdef AMIGA
  76066. # define OS_CODE 0x01
  76067. #endif
  76068. #if defined(VAXC) || defined(VMS)
  76069. # define OS_CODE 0x02
  76070. # define F_OPEN(name, mode) \
  76071. fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
  76072. #endif
  76073. #if defined(ATARI) || defined(atarist)
  76074. # define OS_CODE 0x05
  76075. #endif
  76076. #ifdef OS2
  76077. # define OS_CODE 0x06
  76078. # ifdef M_I86
  76079. #include <malloc.h>
  76080. # endif
  76081. #endif
  76082. #if defined(MACOS) || TARGET_OS_MAC
  76083. # define OS_CODE 0x07
  76084. # if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
  76085. # include <unix.h> /* for fdopen */
  76086. # else
  76087. # ifndef fdopen
  76088. # define fdopen(fd,mode) NULL /* No fdopen() */
  76089. # endif
  76090. # endif
  76091. #endif
  76092. #ifdef TOPS20
  76093. # define OS_CODE 0x0a
  76094. #endif
  76095. #ifdef WIN32
  76096. # ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */
  76097. # define OS_CODE 0x0b
  76098. # endif
  76099. #endif
  76100. #ifdef __50SERIES /* Prime/PRIMOS */
  76101. # define OS_CODE 0x0f
  76102. #endif
  76103. #if defined(_BEOS_) || defined(RISCOS)
  76104. # define fdopen(fd,mode) NULL /* No fdopen() */
  76105. #endif
  76106. #if (defined(_MSC_VER) && (_MSC_VER > 600))
  76107. # if defined(_WIN32_WCE)
  76108. # define fdopen(fd,mode) NULL /* No fdopen() */
  76109. # ifndef _PTRDIFF_T_DEFINED
  76110. typedef int ptrdiff_t;
  76111. # define _PTRDIFF_T_DEFINED
  76112. # endif
  76113. # else
  76114. # define fdopen(fd,type) _fdopen(fd,type)
  76115. # endif
  76116. #endif
  76117. #ifndef OS_CODE
  76118. # define OS_CODE 0x03 /* assume Unix */
  76119. #endif
  76120. #ifndef F_OPEN
  76121. # define F_OPEN(name, mode) fopen((name), (mode))
  76122. #endif
  76123. #if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
  76124. # ifndef HAVE_VSNPRINTF
  76125. # define HAVE_VSNPRINTF
  76126. # endif
  76127. #endif
  76128. #if defined(__CYGWIN__)
  76129. # ifndef HAVE_VSNPRINTF
  76130. # define HAVE_VSNPRINTF
  76131. # endif
  76132. #endif
  76133. #ifndef HAVE_VSNPRINTF
  76134. # ifdef MSDOS
  76135. # define NO_vsnprintf
  76136. # endif
  76137. # ifdef __TURBOC__
  76138. # define NO_vsnprintf
  76139. # endif
  76140. # ifdef WIN32
  76141. # if !defined(vsnprintf) && !defined(NO_vsnprintf)
  76142. # define vsnprintf _vsnprintf
  76143. # endif
  76144. # endif
  76145. # ifdef __SASC
  76146. # define NO_vsnprintf
  76147. # endif
  76148. #endif
  76149. #ifdef VMS
  76150. # define NO_vsnprintf
  76151. #endif
  76152. #if defined(pyr)
  76153. # define NO_MEMCPY
  76154. #endif
  76155. #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
  76156. # define NO_MEMCPY
  76157. #endif
  76158. #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
  76159. # define HAVE_MEMCPY
  76160. #endif
  76161. #ifdef HAVE_MEMCPY
  76162. # ifdef SMALL_MEDIUM /* MSDOS small or medium model */
  76163. # define zmemcpy _fmemcpy
  76164. # define zmemcmp _fmemcmp
  76165. # define zmemzero(dest, len) _fmemset(dest, 0, len)
  76166. # else
  76167. # define zmemcpy memcpy
  76168. # define zmemcmp memcmp
  76169. # define zmemzero(dest, len) memset(dest, 0, len)
  76170. # endif
  76171. #else
  76172. extern void zmemcpy OF((Bytef* dest, const Bytef* source, uInt len));
  76173. extern int zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len));
  76174. extern void zmemzero OF((Bytef* dest, uInt len));
  76175. #endif
  76176. #ifdef DEBUG
  76177. # include <stdio.h>
  76178. extern int z_verbose;
  76179. extern void z_error OF((const char *m));
  76180. # define Assert(cond,msg) {if(!(cond)) z_error(msg);}
  76181. # define Trace(x) {if (z_verbose>=0) fprintf x ;}
  76182. # define Tracev(x) {if (z_verbose>0) fprintf x ;}
  76183. # define Tracevv(x) {if (z_verbose>1) fprintf x ;}
  76184. # define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
  76185. # define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
  76186. #else
  76187. # define Assert(cond,msg)
  76188. # define Trace(x)
  76189. # define Tracev(x)
  76190. # define Tracevv(x)
  76191. # define Tracec(c,x)
  76192. # define Tracecv(c,x)
  76193. #endif
  76194. voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size));
  76195. void zcfree OF((voidpf opaque, voidpf ptr));
  76196. #define ZALLOC(strm, items, size) \
  76197. (*((strm)->zalloc))((strm)->opaque, (items), (size))
  76198. #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
  76199. #define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
  76200. #endif /* ZUTIL_H */
  76201. /*** End of inlined file: zutil.h ***/
  76202. /* for STDC and FAR definitions */
  76203. #define local static
  76204. #ifndef NOBYFOUR
  76205. # ifdef STDC /* need ANSI C limits.h to determine sizes */
  76206. # include <limits.h>
  76207. # define BYFOUR
  76208. # if (UINT_MAX == 0xffffffffUL)
  76209. typedef unsigned int u4;
  76210. # else
  76211. # if (ULONG_MAX == 0xffffffffUL)
  76212. typedef unsigned long u4;
  76213. # else
  76214. # if (USHRT_MAX == 0xffffffffUL)
  76215. typedef unsigned short u4;
  76216. # else
  76217. # undef BYFOUR /* can't find a four-byte integer type! */
  76218. # endif
  76219. # endif
  76220. # endif
  76221. # endif /* STDC */
  76222. #endif /* !NOBYFOUR */
  76223. #ifdef BYFOUR
  76224. # define REV(w) (((w)>>24)+(((w)>>8)&0xff00)+ \
  76225. (((w)&0xff00)<<8)+(((w)&0xff)<<24))
  76226. local unsigned long crc32_little OF((unsigned long,
  76227. const unsigned char FAR *, unsigned));
  76228. local unsigned long crc32_big OF((unsigned long,
  76229. const unsigned char FAR *, unsigned));
  76230. # define TBLS 8
  76231. #else
  76232. # define TBLS 1
  76233. #endif /* BYFOUR */
  76234. local unsigned long gf2_matrix_times OF((unsigned long *mat,
  76235. unsigned long vec));
  76236. local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat));
  76237. #ifdef DYNAMIC_CRC_TABLE
  76238. local volatile int crc_table_empty = 1;
  76239. local unsigned long FAR crc_table[TBLS][256];
  76240. local void make_crc_table OF((void));
  76241. #ifdef MAKECRCH
  76242. local void write_table OF((FILE *, const unsigned long FAR *));
  76243. #endif /* MAKECRCH */
  76244. local void make_crc_table()
  76245. {
  76246. unsigned long c;
  76247. int n, k;
  76248. unsigned long poly; /* polynomial exclusive-or pattern */
  76249. static volatile int first = 1; /* flag to limit concurrent making */
  76250. static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
  76251. if (first) {
  76252. first = 0;
  76253. poly = 0UL;
  76254. for (n = 0; n < sizeof(p)/sizeof(unsigned char); n++)
  76255. poly |= 1UL << (31 - p[n]);
  76256. for (n = 0; n < 256; n++) {
  76257. c = (unsigned long)n;
  76258. for (k = 0; k < 8; k++)
  76259. c = c & 1 ? poly ^ (c >> 1) : c >> 1;
  76260. crc_table[0][n] = c;
  76261. }
  76262. #ifdef BYFOUR
  76263. for (n = 0; n < 256; n++) {
  76264. c = crc_table[0][n];
  76265. crc_table[4][n] = REV(c);
  76266. for (k = 1; k < 4; k++) {
  76267. c = crc_table[0][c & 0xff] ^ (c >> 8);
  76268. crc_table[k][n] = c;
  76269. crc_table[k + 4][n] = REV(c);
  76270. }
  76271. }
  76272. #endif /* BYFOUR */
  76273. crc_table_empty = 0;
  76274. }
  76275. else { /* not first */
  76276. while (crc_table_empty)
  76277. ;
  76278. }
  76279. #ifdef MAKECRCH
  76280. {
  76281. FILE *out;
  76282. out = fopen("crc32.h", "w");
  76283. if (out == NULL) return;
  76284. fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n");
  76285. fprintf(out, " * Generated automatically by crc32.c\n */\n\n");
  76286. fprintf(out, "local const unsigned long FAR ");
  76287. fprintf(out, "crc_table[TBLS][256] =\n{\n {\n");
  76288. write_table(out, crc_table[0]);
  76289. # ifdef BYFOUR
  76290. fprintf(out, "#ifdef BYFOUR\n");
  76291. for (k = 1; k < 8; k++) {
  76292. fprintf(out, " },\n {\n");
  76293. write_table(out, crc_table[k]);
  76294. }
  76295. fprintf(out, "#endif\n");
  76296. # endif /* BYFOUR */
  76297. fprintf(out, " }\n};\n");
  76298. fclose(out);
  76299. }
  76300. #endif /* MAKECRCH */
  76301. }
  76302. #ifdef MAKECRCH
  76303. local void write_table(out, table)
  76304. FILE *out;
  76305. const unsigned long FAR *table;
  76306. {
  76307. int n;
  76308. for (n = 0; n < 256; n++)
  76309. fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ", table[n],
  76310. n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", "));
  76311. }
  76312. #endif /* MAKECRCH */
  76313. #else /* !DYNAMIC_CRC_TABLE */
  76314. /*** Start of inlined file: crc32.h ***/
  76315. local const unsigned long FAR crc_table[TBLS][256] =
  76316. {
  76317. {
  76318. 0x00000000UL, 0x77073096UL, 0xee0e612cUL, 0x990951baUL, 0x076dc419UL,
  76319. 0x706af48fUL, 0xe963a535UL, 0x9e6495a3UL, 0x0edb8832UL, 0x79dcb8a4UL,
  76320. 0xe0d5e91eUL, 0x97d2d988UL, 0x09b64c2bUL, 0x7eb17cbdUL, 0xe7b82d07UL,
  76321. 0x90bf1d91UL, 0x1db71064UL, 0x6ab020f2UL, 0xf3b97148UL, 0x84be41deUL,
  76322. 0x1adad47dUL, 0x6ddde4ebUL, 0xf4d4b551UL, 0x83d385c7UL, 0x136c9856UL,
  76323. 0x646ba8c0UL, 0xfd62f97aUL, 0x8a65c9ecUL, 0x14015c4fUL, 0x63066cd9UL,
  76324. 0xfa0f3d63UL, 0x8d080df5UL, 0x3b6e20c8UL, 0x4c69105eUL, 0xd56041e4UL,
  76325. 0xa2677172UL, 0x3c03e4d1UL, 0x4b04d447UL, 0xd20d85fdUL, 0xa50ab56bUL,
  76326. 0x35b5a8faUL, 0x42b2986cUL, 0xdbbbc9d6UL, 0xacbcf940UL, 0x32d86ce3UL,
  76327. 0x45df5c75UL, 0xdcd60dcfUL, 0xabd13d59UL, 0x26d930acUL, 0x51de003aUL,
  76328. 0xc8d75180UL, 0xbfd06116UL, 0x21b4f4b5UL, 0x56b3c423UL, 0xcfba9599UL,
  76329. 0xb8bda50fUL, 0x2802b89eUL, 0x5f058808UL, 0xc60cd9b2UL, 0xb10be924UL,
  76330. 0x2f6f7c87UL, 0x58684c11UL, 0xc1611dabUL, 0xb6662d3dUL, 0x76dc4190UL,
  76331. 0x01db7106UL, 0x98d220bcUL, 0xefd5102aUL, 0x71b18589UL, 0x06b6b51fUL,
  76332. 0x9fbfe4a5UL, 0xe8b8d433UL, 0x7807c9a2UL, 0x0f00f934UL, 0x9609a88eUL,
  76333. 0xe10e9818UL, 0x7f6a0dbbUL, 0x086d3d2dUL, 0x91646c97UL, 0xe6635c01UL,
  76334. 0x6b6b51f4UL, 0x1c6c6162UL, 0x856530d8UL, 0xf262004eUL, 0x6c0695edUL,
  76335. 0x1b01a57bUL, 0x8208f4c1UL, 0xf50fc457UL, 0x65b0d9c6UL, 0x12b7e950UL,
  76336. 0x8bbeb8eaUL, 0xfcb9887cUL, 0x62dd1ddfUL, 0x15da2d49UL, 0x8cd37cf3UL,
  76337. 0xfbd44c65UL, 0x4db26158UL, 0x3ab551ceUL, 0xa3bc0074UL, 0xd4bb30e2UL,
  76338. 0x4adfa541UL, 0x3dd895d7UL, 0xa4d1c46dUL, 0xd3d6f4fbUL, 0x4369e96aUL,
  76339. 0x346ed9fcUL, 0xad678846UL, 0xda60b8d0UL, 0x44042d73UL, 0x33031de5UL,
  76340. 0xaa0a4c5fUL, 0xdd0d7cc9UL, 0x5005713cUL, 0x270241aaUL, 0xbe0b1010UL,
  76341. 0xc90c2086UL, 0x5768b525UL, 0x206f85b3UL, 0xb966d409UL, 0xce61e49fUL,
  76342. 0x5edef90eUL, 0x29d9c998UL, 0xb0d09822UL, 0xc7d7a8b4UL, 0x59b33d17UL,
  76343. 0x2eb40d81UL, 0xb7bd5c3bUL, 0xc0ba6cadUL, 0xedb88320UL, 0x9abfb3b6UL,
  76344. 0x03b6e20cUL, 0x74b1d29aUL, 0xead54739UL, 0x9dd277afUL, 0x04db2615UL,
  76345. 0x73dc1683UL, 0xe3630b12UL, 0x94643b84UL, 0x0d6d6a3eUL, 0x7a6a5aa8UL,
  76346. 0xe40ecf0bUL, 0x9309ff9dUL, 0x0a00ae27UL, 0x7d079eb1UL, 0xf00f9344UL,
  76347. 0x8708a3d2UL, 0x1e01f268UL, 0x6906c2feUL, 0xf762575dUL, 0x806567cbUL,
  76348. 0x196c3671UL, 0x6e6b06e7UL, 0xfed41b76UL, 0x89d32be0UL, 0x10da7a5aUL,
  76349. 0x67dd4accUL, 0xf9b9df6fUL, 0x8ebeeff9UL, 0x17b7be43UL, 0x60b08ed5UL,
  76350. 0xd6d6a3e8UL, 0xa1d1937eUL, 0x38d8c2c4UL, 0x4fdff252UL, 0xd1bb67f1UL,
  76351. 0xa6bc5767UL, 0x3fb506ddUL, 0x48b2364bUL, 0xd80d2bdaUL, 0xaf0a1b4cUL,
  76352. 0x36034af6UL, 0x41047a60UL, 0xdf60efc3UL, 0xa867df55UL, 0x316e8eefUL,
  76353. 0x4669be79UL, 0xcb61b38cUL, 0xbc66831aUL, 0x256fd2a0UL, 0x5268e236UL,
  76354. 0xcc0c7795UL, 0xbb0b4703UL, 0x220216b9UL, 0x5505262fUL, 0xc5ba3bbeUL,
  76355. 0xb2bd0b28UL, 0x2bb45a92UL, 0x5cb36a04UL, 0xc2d7ffa7UL, 0xb5d0cf31UL,
  76356. 0x2cd99e8bUL, 0x5bdeae1dUL, 0x9b64c2b0UL, 0xec63f226UL, 0x756aa39cUL,
  76357. 0x026d930aUL, 0x9c0906a9UL, 0xeb0e363fUL, 0x72076785UL, 0x05005713UL,
  76358. 0x95bf4a82UL, 0xe2b87a14UL, 0x7bb12baeUL, 0x0cb61b38UL, 0x92d28e9bUL,
  76359. 0xe5d5be0dUL, 0x7cdcefb7UL, 0x0bdbdf21UL, 0x86d3d2d4UL, 0xf1d4e242UL,
  76360. 0x68ddb3f8UL, 0x1fda836eUL, 0x81be16cdUL, 0xf6b9265bUL, 0x6fb077e1UL,
  76361. 0x18b74777UL, 0x88085ae6UL, 0xff0f6a70UL, 0x66063bcaUL, 0x11010b5cUL,
  76362. 0x8f659effUL, 0xf862ae69UL, 0x616bffd3UL, 0x166ccf45UL, 0xa00ae278UL,
  76363. 0xd70dd2eeUL, 0x4e048354UL, 0x3903b3c2UL, 0xa7672661UL, 0xd06016f7UL,
  76364. 0x4969474dUL, 0x3e6e77dbUL, 0xaed16a4aUL, 0xd9d65adcUL, 0x40df0b66UL,
  76365. 0x37d83bf0UL, 0xa9bcae53UL, 0xdebb9ec5UL, 0x47b2cf7fUL, 0x30b5ffe9UL,
  76366. 0xbdbdf21cUL, 0xcabac28aUL, 0x53b39330UL, 0x24b4a3a6UL, 0xbad03605UL,
  76367. 0xcdd70693UL, 0x54de5729UL, 0x23d967bfUL, 0xb3667a2eUL, 0xc4614ab8UL,
  76368. 0x5d681b02UL, 0x2a6f2b94UL, 0xb40bbe37UL, 0xc30c8ea1UL, 0x5a05df1bUL,
  76369. 0x2d02ef8dUL
  76370. #ifdef BYFOUR
  76371. },
  76372. {
  76373. 0x00000000UL, 0x191b3141UL, 0x32366282UL, 0x2b2d53c3UL, 0x646cc504UL,
  76374. 0x7d77f445UL, 0x565aa786UL, 0x4f4196c7UL, 0xc8d98a08UL, 0xd1c2bb49UL,
  76375. 0xfaefe88aUL, 0xe3f4d9cbUL, 0xacb54f0cUL, 0xb5ae7e4dUL, 0x9e832d8eUL,
  76376. 0x87981ccfUL, 0x4ac21251UL, 0x53d92310UL, 0x78f470d3UL, 0x61ef4192UL,
  76377. 0x2eaed755UL, 0x37b5e614UL, 0x1c98b5d7UL, 0x05838496UL, 0x821b9859UL,
  76378. 0x9b00a918UL, 0xb02dfadbUL, 0xa936cb9aUL, 0xe6775d5dUL, 0xff6c6c1cUL,
  76379. 0xd4413fdfUL, 0xcd5a0e9eUL, 0x958424a2UL, 0x8c9f15e3UL, 0xa7b24620UL,
  76380. 0xbea97761UL, 0xf1e8e1a6UL, 0xe8f3d0e7UL, 0xc3de8324UL, 0xdac5b265UL,
  76381. 0x5d5daeaaUL, 0x44469febUL, 0x6f6bcc28UL, 0x7670fd69UL, 0x39316baeUL,
  76382. 0x202a5aefUL, 0x0b07092cUL, 0x121c386dUL, 0xdf4636f3UL, 0xc65d07b2UL,
  76383. 0xed705471UL, 0xf46b6530UL, 0xbb2af3f7UL, 0xa231c2b6UL, 0x891c9175UL,
  76384. 0x9007a034UL, 0x179fbcfbUL, 0x0e848dbaUL, 0x25a9de79UL, 0x3cb2ef38UL,
  76385. 0x73f379ffUL, 0x6ae848beUL, 0x41c51b7dUL, 0x58de2a3cUL, 0xf0794f05UL,
  76386. 0xe9627e44UL, 0xc24f2d87UL, 0xdb541cc6UL, 0x94158a01UL, 0x8d0ebb40UL,
  76387. 0xa623e883UL, 0xbf38d9c2UL, 0x38a0c50dUL, 0x21bbf44cUL, 0x0a96a78fUL,
  76388. 0x138d96ceUL, 0x5ccc0009UL, 0x45d73148UL, 0x6efa628bUL, 0x77e153caUL,
  76389. 0xbabb5d54UL, 0xa3a06c15UL, 0x888d3fd6UL, 0x91960e97UL, 0xded79850UL,
  76390. 0xc7cca911UL, 0xece1fad2UL, 0xf5facb93UL, 0x7262d75cUL, 0x6b79e61dUL,
  76391. 0x4054b5deUL, 0x594f849fUL, 0x160e1258UL, 0x0f152319UL, 0x243870daUL,
  76392. 0x3d23419bUL, 0x65fd6ba7UL, 0x7ce65ae6UL, 0x57cb0925UL, 0x4ed03864UL,
  76393. 0x0191aea3UL, 0x188a9fe2UL, 0x33a7cc21UL, 0x2abcfd60UL, 0xad24e1afUL,
  76394. 0xb43fd0eeUL, 0x9f12832dUL, 0x8609b26cUL, 0xc94824abUL, 0xd05315eaUL,
  76395. 0xfb7e4629UL, 0xe2657768UL, 0x2f3f79f6UL, 0x362448b7UL, 0x1d091b74UL,
  76396. 0x04122a35UL, 0x4b53bcf2UL, 0x52488db3UL, 0x7965de70UL, 0x607eef31UL,
  76397. 0xe7e6f3feUL, 0xfefdc2bfUL, 0xd5d0917cUL, 0xcccba03dUL, 0x838a36faUL,
  76398. 0x9a9107bbUL, 0xb1bc5478UL, 0xa8a76539UL, 0x3b83984bUL, 0x2298a90aUL,
  76399. 0x09b5fac9UL, 0x10aecb88UL, 0x5fef5d4fUL, 0x46f46c0eUL, 0x6dd93fcdUL,
  76400. 0x74c20e8cUL, 0xf35a1243UL, 0xea412302UL, 0xc16c70c1UL, 0xd8774180UL,
  76401. 0x9736d747UL, 0x8e2de606UL, 0xa500b5c5UL, 0xbc1b8484UL, 0x71418a1aUL,
  76402. 0x685abb5bUL, 0x4377e898UL, 0x5a6cd9d9UL, 0x152d4f1eUL, 0x0c367e5fUL,
  76403. 0x271b2d9cUL, 0x3e001cddUL, 0xb9980012UL, 0xa0833153UL, 0x8bae6290UL,
  76404. 0x92b553d1UL, 0xddf4c516UL, 0xc4eff457UL, 0xefc2a794UL, 0xf6d996d5UL,
  76405. 0xae07bce9UL, 0xb71c8da8UL, 0x9c31de6bUL, 0x852aef2aUL, 0xca6b79edUL,
  76406. 0xd37048acUL, 0xf85d1b6fUL, 0xe1462a2eUL, 0x66de36e1UL, 0x7fc507a0UL,
  76407. 0x54e85463UL, 0x4df36522UL, 0x02b2f3e5UL, 0x1ba9c2a4UL, 0x30849167UL,
  76408. 0x299fa026UL, 0xe4c5aeb8UL, 0xfdde9ff9UL, 0xd6f3cc3aUL, 0xcfe8fd7bUL,
  76409. 0x80a96bbcUL, 0x99b25afdUL, 0xb29f093eUL, 0xab84387fUL, 0x2c1c24b0UL,
  76410. 0x350715f1UL, 0x1e2a4632UL, 0x07317773UL, 0x4870e1b4UL, 0x516bd0f5UL,
  76411. 0x7a468336UL, 0x635db277UL, 0xcbfad74eUL, 0xd2e1e60fUL, 0xf9ccb5ccUL,
  76412. 0xe0d7848dUL, 0xaf96124aUL, 0xb68d230bUL, 0x9da070c8UL, 0x84bb4189UL,
  76413. 0x03235d46UL, 0x1a386c07UL, 0x31153fc4UL, 0x280e0e85UL, 0x674f9842UL,
  76414. 0x7e54a903UL, 0x5579fac0UL, 0x4c62cb81UL, 0x8138c51fUL, 0x9823f45eUL,
  76415. 0xb30ea79dUL, 0xaa1596dcUL, 0xe554001bUL, 0xfc4f315aUL, 0xd7626299UL,
  76416. 0xce7953d8UL, 0x49e14f17UL, 0x50fa7e56UL, 0x7bd72d95UL, 0x62cc1cd4UL,
  76417. 0x2d8d8a13UL, 0x3496bb52UL, 0x1fbbe891UL, 0x06a0d9d0UL, 0x5e7ef3ecUL,
  76418. 0x4765c2adUL, 0x6c48916eUL, 0x7553a02fUL, 0x3a1236e8UL, 0x230907a9UL,
  76419. 0x0824546aUL, 0x113f652bUL, 0x96a779e4UL, 0x8fbc48a5UL, 0xa4911b66UL,
  76420. 0xbd8a2a27UL, 0xf2cbbce0UL, 0xebd08da1UL, 0xc0fdde62UL, 0xd9e6ef23UL,
  76421. 0x14bce1bdUL, 0x0da7d0fcUL, 0x268a833fUL, 0x3f91b27eUL, 0x70d024b9UL,
  76422. 0x69cb15f8UL, 0x42e6463bUL, 0x5bfd777aUL, 0xdc656bb5UL, 0xc57e5af4UL,
  76423. 0xee530937UL, 0xf7483876UL, 0xb809aeb1UL, 0xa1129ff0UL, 0x8a3fcc33UL,
  76424. 0x9324fd72UL
  76425. },
  76426. {
  76427. 0x00000000UL, 0x01c26a37UL, 0x0384d46eUL, 0x0246be59UL, 0x0709a8dcUL,
  76428. 0x06cbc2ebUL, 0x048d7cb2UL, 0x054f1685UL, 0x0e1351b8UL, 0x0fd13b8fUL,
  76429. 0x0d9785d6UL, 0x0c55efe1UL, 0x091af964UL, 0x08d89353UL, 0x0a9e2d0aUL,
  76430. 0x0b5c473dUL, 0x1c26a370UL, 0x1de4c947UL, 0x1fa2771eUL, 0x1e601d29UL,
  76431. 0x1b2f0bacUL, 0x1aed619bUL, 0x18abdfc2UL, 0x1969b5f5UL, 0x1235f2c8UL,
  76432. 0x13f798ffUL, 0x11b126a6UL, 0x10734c91UL, 0x153c5a14UL, 0x14fe3023UL,
  76433. 0x16b88e7aUL, 0x177ae44dUL, 0x384d46e0UL, 0x398f2cd7UL, 0x3bc9928eUL,
  76434. 0x3a0bf8b9UL, 0x3f44ee3cUL, 0x3e86840bUL, 0x3cc03a52UL, 0x3d025065UL,
  76435. 0x365e1758UL, 0x379c7d6fUL, 0x35dac336UL, 0x3418a901UL, 0x3157bf84UL,
  76436. 0x3095d5b3UL, 0x32d36beaUL, 0x331101ddUL, 0x246be590UL, 0x25a98fa7UL,
  76437. 0x27ef31feUL, 0x262d5bc9UL, 0x23624d4cUL, 0x22a0277bUL, 0x20e69922UL,
  76438. 0x2124f315UL, 0x2a78b428UL, 0x2bbade1fUL, 0x29fc6046UL, 0x283e0a71UL,
  76439. 0x2d711cf4UL, 0x2cb376c3UL, 0x2ef5c89aUL, 0x2f37a2adUL, 0x709a8dc0UL,
  76440. 0x7158e7f7UL, 0x731e59aeUL, 0x72dc3399UL, 0x7793251cUL, 0x76514f2bUL,
  76441. 0x7417f172UL, 0x75d59b45UL, 0x7e89dc78UL, 0x7f4bb64fUL, 0x7d0d0816UL,
  76442. 0x7ccf6221UL, 0x798074a4UL, 0x78421e93UL, 0x7a04a0caUL, 0x7bc6cafdUL,
  76443. 0x6cbc2eb0UL, 0x6d7e4487UL, 0x6f38fadeUL, 0x6efa90e9UL, 0x6bb5866cUL,
  76444. 0x6a77ec5bUL, 0x68315202UL, 0x69f33835UL, 0x62af7f08UL, 0x636d153fUL,
  76445. 0x612bab66UL, 0x60e9c151UL, 0x65a6d7d4UL, 0x6464bde3UL, 0x662203baUL,
  76446. 0x67e0698dUL, 0x48d7cb20UL, 0x4915a117UL, 0x4b531f4eUL, 0x4a917579UL,
  76447. 0x4fde63fcUL, 0x4e1c09cbUL, 0x4c5ab792UL, 0x4d98dda5UL, 0x46c49a98UL,
  76448. 0x4706f0afUL, 0x45404ef6UL, 0x448224c1UL, 0x41cd3244UL, 0x400f5873UL,
  76449. 0x4249e62aUL, 0x438b8c1dUL, 0x54f16850UL, 0x55330267UL, 0x5775bc3eUL,
  76450. 0x56b7d609UL, 0x53f8c08cUL, 0x523aaabbUL, 0x507c14e2UL, 0x51be7ed5UL,
  76451. 0x5ae239e8UL, 0x5b2053dfUL, 0x5966ed86UL, 0x58a487b1UL, 0x5deb9134UL,
  76452. 0x5c29fb03UL, 0x5e6f455aUL, 0x5fad2f6dUL, 0xe1351b80UL, 0xe0f771b7UL,
  76453. 0xe2b1cfeeUL, 0xe373a5d9UL, 0xe63cb35cUL, 0xe7fed96bUL, 0xe5b86732UL,
  76454. 0xe47a0d05UL, 0xef264a38UL, 0xeee4200fUL, 0xeca29e56UL, 0xed60f461UL,
  76455. 0xe82fe2e4UL, 0xe9ed88d3UL, 0xebab368aUL, 0xea695cbdUL, 0xfd13b8f0UL,
  76456. 0xfcd1d2c7UL, 0xfe976c9eUL, 0xff5506a9UL, 0xfa1a102cUL, 0xfbd87a1bUL,
  76457. 0xf99ec442UL, 0xf85cae75UL, 0xf300e948UL, 0xf2c2837fUL, 0xf0843d26UL,
  76458. 0xf1465711UL, 0xf4094194UL, 0xf5cb2ba3UL, 0xf78d95faUL, 0xf64fffcdUL,
  76459. 0xd9785d60UL, 0xd8ba3757UL, 0xdafc890eUL, 0xdb3ee339UL, 0xde71f5bcUL,
  76460. 0xdfb39f8bUL, 0xddf521d2UL, 0xdc374be5UL, 0xd76b0cd8UL, 0xd6a966efUL,
  76461. 0xd4efd8b6UL, 0xd52db281UL, 0xd062a404UL, 0xd1a0ce33UL, 0xd3e6706aUL,
  76462. 0xd2241a5dUL, 0xc55efe10UL, 0xc49c9427UL, 0xc6da2a7eUL, 0xc7184049UL,
  76463. 0xc25756ccUL, 0xc3953cfbUL, 0xc1d382a2UL, 0xc011e895UL, 0xcb4dafa8UL,
  76464. 0xca8fc59fUL, 0xc8c97bc6UL, 0xc90b11f1UL, 0xcc440774UL, 0xcd866d43UL,
  76465. 0xcfc0d31aUL, 0xce02b92dUL, 0x91af9640UL, 0x906dfc77UL, 0x922b422eUL,
  76466. 0x93e92819UL, 0x96a63e9cUL, 0x976454abUL, 0x9522eaf2UL, 0x94e080c5UL,
  76467. 0x9fbcc7f8UL, 0x9e7eadcfUL, 0x9c381396UL, 0x9dfa79a1UL, 0x98b56f24UL,
  76468. 0x99770513UL, 0x9b31bb4aUL, 0x9af3d17dUL, 0x8d893530UL, 0x8c4b5f07UL,
  76469. 0x8e0de15eUL, 0x8fcf8b69UL, 0x8a809decUL, 0x8b42f7dbUL, 0x89044982UL,
  76470. 0x88c623b5UL, 0x839a6488UL, 0x82580ebfUL, 0x801eb0e6UL, 0x81dcdad1UL,
  76471. 0x8493cc54UL, 0x8551a663UL, 0x8717183aUL, 0x86d5720dUL, 0xa9e2d0a0UL,
  76472. 0xa820ba97UL, 0xaa6604ceUL, 0xaba46ef9UL, 0xaeeb787cUL, 0xaf29124bUL,
  76473. 0xad6fac12UL, 0xacadc625UL, 0xa7f18118UL, 0xa633eb2fUL, 0xa4755576UL,
  76474. 0xa5b73f41UL, 0xa0f829c4UL, 0xa13a43f3UL, 0xa37cfdaaUL, 0xa2be979dUL,
  76475. 0xb5c473d0UL, 0xb40619e7UL, 0xb640a7beUL, 0xb782cd89UL, 0xb2cddb0cUL,
  76476. 0xb30fb13bUL, 0xb1490f62UL, 0xb08b6555UL, 0xbbd72268UL, 0xba15485fUL,
  76477. 0xb853f606UL, 0xb9919c31UL, 0xbcde8ab4UL, 0xbd1ce083UL, 0xbf5a5edaUL,
  76478. 0xbe9834edUL
  76479. },
  76480. {
  76481. 0x00000000UL, 0xb8bc6765UL, 0xaa09c88bUL, 0x12b5afeeUL, 0x8f629757UL,
  76482. 0x37def032UL, 0x256b5fdcUL, 0x9dd738b9UL, 0xc5b428efUL, 0x7d084f8aUL,
  76483. 0x6fbde064UL, 0xd7018701UL, 0x4ad6bfb8UL, 0xf26ad8ddUL, 0xe0df7733UL,
  76484. 0x58631056UL, 0x5019579fUL, 0xe8a530faUL, 0xfa109f14UL, 0x42acf871UL,
  76485. 0xdf7bc0c8UL, 0x67c7a7adUL, 0x75720843UL, 0xcdce6f26UL, 0x95ad7f70UL,
  76486. 0x2d111815UL, 0x3fa4b7fbUL, 0x8718d09eUL, 0x1acfe827UL, 0xa2738f42UL,
  76487. 0xb0c620acUL, 0x087a47c9UL, 0xa032af3eUL, 0x188ec85bUL, 0x0a3b67b5UL,
  76488. 0xb28700d0UL, 0x2f503869UL, 0x97ec5f0cUL, 0x8559f0e2UL, 0x3de59787UL,
  76489. 0x658687d1UL, 0xdd3ae0b4UL, 0xcf8f4f5aUL, 0x7733283fUL, 0xeae41086UL,
  76490. 0x525877e3UL, 0x40edd80dUL, 0xf851bf68UL, 0xf02bf8a1UL, 0x48979fc4UL,
  76491. 0x5a22302aUL, 0xe29e574fUL, 0x7f496ff6UL, 0xc7f50893UL, 0xd540a77dUL,
  76492. 0x6dfcc018UL, 0x359fd04eUL, 0x8d23b72bUL, 0x9f9618c5UL, 0x272a7fa0UL,
  76493. 0xbafd4719UL, 0x0241207cUL, 0x10f48f92UL, 0xa848e8f7UL, 0x9b14583dUL,
  76494. 0x23a83f58UL, 0x311d90b6UL, 0x89a1f7d3UL, 0x1476cf6aUL, 0xaccaa80fUL,
  76495. 0xbe7f07e1UL, 0x06c36084UL, 0x5ea070d2UL, 0xe61c17b7UL, 0xf4a9b859UL,
  76496. 0x4c15df3cUL, 0xd1c2e785UL, 0x697e80e0UL, 0x7bcb2f0eUL, 0xc377486bUL,
  76497. 0xcb0d0fa2UL, 0x73b168c7UL, 0x6104c729UL, 0xd9b8a04cUL, 0x446f98f5UL,
  76498. 0xfcd3ff90UL, 0xee66507eUL, 0x56da371bUL, 0x0eb9274dUL, 0xb6054028UL,
  76499. 0xa4b0efc6UL, 0x1c0c88a3UL, 0x81dbb01aUL, 0x3967d77fUL, 0x2bd27891UL,
  76500. 0x936e1ff4UL, 0x3b26f703UL, 0x839a9066UL, 0x912f3f88UL, 0x299358edUL,
  76501. 0xb4446054UL, 0x0cf80731UL, 0x1e4da8dfUL, 0xa6f1cfbaUL, 0xfe92dfecUL,
  76502. 0x462eb889UL, 0x549b1767UL, 0xec277002UL, 0x71f048bbUL, 0xc94c2fdeUL,
  76503. 0xdbf98030UL, 0x6345e755UL, 0x6b3fa09cUL, 0xd383c7f9UL, 0xc1366817UL,
  76504. 0x798a0f72UL, 0xe45d37cbUL, 0x5ce150aeUL, 0x4e54ff40UL, 0xf6e89825UL,
  76505. 0xae8b8873UL, 0x1637ef16UL, 0x048240f8UL, 0xbc3e279dUL, 0x21e91f24UL,
  76506. 0x99557841UL, 0x8be0d7afUL, 0x335cb0caUL, 0xed59b63bUL, 0x55e5d15eUL,
  76507. 0x47507eb0UL, 0xffec19d5UL, 0x623b216cUL, 0xda874609UL, 0xc832e9e7UL,
  76508. 0x708e8e82UL, 0x28ed9ed4UL, 0x9051f9b1UL, 0x82e4565fUL, 0x3a58313aUL,
  76509. 0xa78f0983UL, 0x1f336ee6UL, 0x0d86c108UL, 0xb53aa66dUL, 0xbd40e1a4UL,
  76510. 0x05fc86c1UL, 0x1749292fUL, 0xaff54e4aUL, 0x322276f3UL, 0x8a9e1196UL,
  76511. 0x982bbe78UL, 0x2097d91dUL, 0x78f4c94bUL, 0xc048ae2eUL, 0xd2fd01c0UL,
  76512. 0x6a4166a5UL, 0xf7965e1cUL, 0x4f2a3979UL, 0x5d9f9697UL, 0xe523f1f2UL,
  76513. 0x4d6b1905UL, 0xf5d77e60UL, 0xe762d18eUL, 0x5fdeb6ebUL, 0xc2098e52UL,
  76514. 0x7ab5e937UL, 0x680046d9UL, 0xd0bc21bcUL, 0x88df31eaUL, 0x3063568fUL,
  76515. 0x22d6f961UL, 0x9a6a9e04UL, 0x07bda6bdUL, 0xbf01c1d8UL, 0xadb46e36UL,
  76516. 0x15080953UL, 0x1d724e9aUL, 0xa5ce29ffUL, 0xb77b8611UL, 0x0fc7e174UL,
  76517. 0x9210d9cdUL, 0x2aacbea8UL, 0x38191146UL, 0x80a57623UL, 0xd8c66675UL,
  76518. 0x607a0110UL, 0x72cfaefeUL, 0xca73c99bUL, 0x57a4f122UL, 0xef189647UL,
  76519. 0xfdad39a9UL, 0x45115eccUL, 0x764dee06UL, 0xcef18963UL, 0xdc44268dUL,
  76520. 0x64f841e8UL, 0xf92f7951UL, 0x41931e34UL, 0x5326b1daUL, 0xeb9ad6bfUL,
  76521. 0xb3f9c6e9UL, 0x0b45a18cUL, 0x19f00e62UL, 0xa14c6907UL, 0x3c9b51beUL,
  76522. 0x842736dbUL, 0x96929935UL, 0x2e2efe50UL, 0x2654b999UL, 0x9ee8defcUL,
  76523. 0x8c5d7112UL, 0x34e11677UL, 0xa9362eceUL, 0x118a49abUL, 0x033fe645UL,
  76524. 0xbb838120UL, 0xe3e09176UL, 0x5b5cf613UL, 0x49e959fdUL, 0xf1553e98UL,
  76525. 0x6c820621UL, 0xd43e6144UL, 0xc68bceaaUL, 0x7e37a9cfUL, 0xd67f4138UL,
  76526. 0x6ec3265dUL, 0x7c7689b3UL, 0xc4caeed6UL, 0x591dd66fUL, 0xe1a1b10aUL,
  76527. 0xf3141ee4UL, 0x4ba87981UL, 0x13cb69d7UL, 0xab770eb2UL, 0xb9c2a15cUL,
  76528. 0x017ec639UL, 0x9ca9fe80UL, 0x241599e5UL, 0x36a0360bUL, 0x8e1c516eUL,
  76529. 0x866616a7UL, 0x3eda71c2UL, 0x2c6fde2cUL, 0x94d3b949UL, 0x090481f0UL,
  76530. 0xb1b8e695UL, 0xa30d497bUL, 0x1bb12e1eUL, 0x43d23e48UL, 0xfb6e592dUL,
  76531. 0xe9dbf6c3UL, 0x516791a6UL, 0xccb0a91fUL, 0x740cce7aUL, 0x66b96194UL,
  76532. 0xde0506f1UL
  76533. },
  76534. {
  76535. 0x00000000UL, 0x96300777UL, 0x2c610eeeUL, 0xba510999UL, 0x19c46d07UL,
  76536. 0x8ff46a70UL, 0x35a563e9UL, 0xa395649eUL, 0x3288db0eUL, 0xa4b8dc79UL,
  76537. 0x1ee9d5e0UL, 0x88d9d297UL, 0x2b4cb609UL, 0xbd7cb17eUL, 0x072db8e7UL,
  76538. 0x911dbf90UL, 0x6410b71dUL, 0xf220b06aUL, 0x4871b9f3UL, 0xde41be84UL,
  76539. 0x7dd4da1aUL, 0xebe4dd6dUL, 0x51b5d4f4UL, 0xc785d383UL, 0x56986c13UL,
  76540. 0xc0a86b64UL, 0x7af962fdUL, 0xecc9658aUL, 0x4f5c0114UL, 0xd96c0663UL,
  76541. 0x633d0ffaUL, 0xf50d088dUL, 0xc8206e3bUL, 0x5e10694cUL, 0xe44160d5UL,
  76542. 0x727167a2UL, 0xd1e4033cUL, 0x47d4044bUL, 0xfd850dd2UL, 0x6bb50aa5UL,
  76543. 0xfaa8b535UL, 0x6c98b242UL, 0xd6c9bbdbUL, 0x40f9bcacUL, 0xe36cd832UL,
  76544. 0x755cdf45UL, 0xcf0dd6dcUL, 0x593dd1abUL, 0xac30d926UL, 0x3a00de51UL,
  76545. 0x8051d7c8UL, 0x1661d0bfUL, 0xb5f4b421UL, 0x23c4b356UL, 0x9995bacfUL,
  76546. 0x0fa5bdb8UL, 0x9eb80228UL, 0x0888055fUL, 0xb2d90cc6UL, 0x24e90bb1UL,
  76547. 0x877c6f2fUL, 0x114c6858UL, 0xab1d61c1UL, 0x3d2d66b6UL, 0x9041dc76UL,
  76548. 0x0671db01UL, 0xbc20d298UL, 0x2a10d5efUL, 0x8985b171UL, 0x1fb5b606UL,
  76549. 0xa5e4bf9fUL, 0x33d4b8e8UL, 0xa2c90778UL, 0x34f9000fUL, 0x8ea80996UL,
  76550. 0x18980ee1UL, 0xbb0d6a7fUL, 0x2d3d6d08UL, 0x976c6491UL, 0x015c63e6UL,
  76551. 0xf4516b6bUL, 0x62616c1cUL, 0xd8306585UL, 0x4e0062f2UL, 0xed95066cUL,
  76552. 0x7ba5011bUL, 0xc1f40882UL, 0x57c40ff5UL, 0xc6d9b065UL, 0x50e9b712UL,
  76553. 0xeab8be8bUL, 0x7c88b9fcUL, 0xdf1ddd62UL, 0x492dda15UL, 0xf37cd38cUL,
  76554. 0x654cd4fbUL, 0x5861b24dUL, 0xce51b53aUL, 0x7400bca3UL, 0xe230bbd4UL,
  76555. 0x41a5df4aUL, 0xd795d83dUL, 0x6dc4d1a4UL, 0xfbf4d6d3UL, 0x6ae96943UL,
  76556. 0xfcd96e34UL, 0x468867adUL, 0xd0b860daUL, 0x732d0444UL, 0xe51d0333UL,
  76557. 0x5f4c0aaaUL, 0xc97c0dddUL, 0x3c710550UL, 0xaa410227UL, 0x10100bbeUL,
  76558. 0x86200cc9UL, 0x25b56857UL, 0xb3856f20UL, 0x09d466b9UL, 0x9fe461ceUL,
  76559. 0x0ef9de5eUL, 0x98c9d929UL, 0x2298d0b0UL, 0xb4a8d7c7UL, 0x173db359UL,
  76560. 0x810db42eUL, 0x3b5cbdb7UL, 0xad6cbac0UL, 0x2083b8edUL, 0xb6b3bf9aUL,
  76561. 0x0ce2b603UL, 0x9ad2b174UL, 0x3947d5eaUL, 0xaf77d29dUL, 0x1526db04UL,
  76562. 0x8316dc73UL, 0x120b63e3UL, 0x843b6494UL, 0x3e6a6d0dUL, 0xa85a6a7aUL,
  76563. 0x0bcf0ee4UL, 0x9dff0993UL, 0x27ae000aUL, 0xb19e077dUL, 0x44930ff0UL,
  76564. 0xd2a30887UL, 0x68f2011eUL, 0xfec20669UL, 0x5d5762f7UL, 0xcb676580UL,
  76565. 0x71366c19UL, 0xe7066b6eUL, 0x761bd4feUL, 0xe02bd389UL, 0x5a7ada10UL,
  76566. 0xcc4add67UL, 0x6fdfb9f9UL, 0xf9efbe8eUL, 0x43beb717UL, 0xd58eb060UL,
  76567. 0xe8a3d6d6UL, 0x7e93d1a1UL, 0xc4c2d838UL, 0x52f2df4fUL, 0xf167bbd1UL,
  76568. 0x6757bca6UL, 0xdd06b53fUL, 0x4b36b248UL, 0xda2b0dd8UL, 0x4c1b0aafUL,
  76569. 0xf64a0336UL, 0x607a0441UL, 0xc3ef60dfUL, 0x55df67a8UL, 0xef8e6e31UL,
  76570. 0x79be6946UL, 0x8cb361cbUL, 0x1a8366bcUL, 0xa0d26f25UL, 0x36e26852UL,
  76571. 0x95770cccUL, 0x03470bbbUL, 0xb9160222UL, 0x2f260555UL, 0xbe3bbac5UL,
  76572. 0x280bbdb2UL, 0x925ab42bUL, 0x046ab35cUL, 0xa7ffd7c2UL, 0x31cfd0b5UL,
  76573. 0x8b9ed92cUL, 0x1daede5bUL, 0xb0c2649bUL, 0x26f263ecUL, 0x9ca36a75UL,
  76574. 0x0a936d02UL, 0xa906099cUL, 0x3f360eebUL, 0x85670772UL, 0x13570005UL,
  76575. 0x824abf95UL, 0x147ab8e2UL, 0xae2bb17bUL, 0x381bb60cUL, 0x9b8ed292UL,
  76576. 0x0dbed5e5UL, 0xb7efdc7cUL, 0x21dfdb0bUL, 0xd4d2d386UL, 0x42e2d4f1UL,
  76577. 0xf8b3dd68UL, 0x6e83da1fUL, 0xcd16be81UL, 0x5b26b9f6UL, 0xe177b06fUL,
  76578. 0x7747b718UL, 0xe65a0888UL, 0x706a0fffUL, 0xca3b0666UL, 0x5c0b0111UL,
  76579. 0xff9e658fUL, 0x69ae62f8UL, 0xd3ff6b61UL, 0x45cf6c16UL, 0x78e20aa0UL,
  76580. 0xeed20dd7UL, 0x5483044eUL, 0xc2b30339UL, 0x612667a7UL, 0xf71660d0UL,
  76581. 0x4d476949UL, 0xdb776e3eUL, 0x4a6ad1aeUL, 0xdc5ad6d9UL, 0x660bdf40UL,
  76582. 0xf03bd837UL, 0x53aebca9UL, 0xc59ebbdeUL, 0x7fcfb247UL, 0xe9ffb530UL,
  76583. 0x1cf2bdbdUL, 0x8ac2bacaUL, 0x3093b353UL, 0xa6a3b424UL, 0x0536d0baUL,
  76584. 0x9306d7cdUL, 0x2957de54UL, 0xbf67d923UL, 0x2e7a66b3UL, 0xb84a61c4UL,
  76585. 0x021b685dUL, 0x942b6f2aUL, 0x37be0bb4UL, 0xa18e0cc3UL, 0x1bdf055aUL,
  76586. 0x8def022dUL
  76587. },
  76588. {
  76589. 0x00000000UL, 0x41311b19UL, 0x82623632UL, 0xc3532d2bUL, 0x04c56c64UL,
  76590. 0x45f4777dUL, 0x86a75a56UL, 0xc796414fUL, 0x088ad9c8UL, 0x49bbc2d1UL,
  76591. 0x8ae8effaUL, 0xcbd9f4e3UL, 0x0c4fb5acUL, 0x4d7eaeb5UL, 0x8e2d839eUL,
  76592. 0xcf1c9887UL, 0x5112c24aUL, 0x1023d953UL, 0xd370f478UL, 0x9241ef61UL,
  76593. 0x55d7ae2eUL, 0x14e6b537UL, 0xd7b5981cUL, 0x96848305UL, 0x59981b82UL,
  76594. 0x18a9009bUL, 0xdbfa2db0UL, 0x9acb36a9UL, 0x5d5d77e6UL, 0x1c6c6cffUL,
  76595. 0xdf3f41d4UL, 0x9e0e5acdUL, 0xa2248495UL, 0xe3159f8cUL, 0x2046b2a7UL,
  76596. 0x6177a9beUL, 0xa6e1e8f1UL, 0xe7d0f3e8UL, 0x2483dec3UL, 0x65b2c5daUL,
  76597. 0xaaae5d5dUL, 0xeb9f4644UL, 0x28cc6b6fUL, 0x69fd7076UL, 0xae6b3139UL,
  76598. 0xef5a2a20UL, 0x2c09070bUL, 0x6d381c12UL, 0xf33646dfUL, 0xb2075dc6UL,
  76599. 0x715470edUL, 0x30656bf4UL, 0xf7f32abbUL, 0xb6c231a2UL, 0x75911c89UL,
  76600. 0x34a00790UL, 0xfbbc9f17UL, 0xba8d840eUL, 0x79dea925UL, 0x38efb23cUL,
  76601. 0xff79f373UL, 0xbe48e86aUL, 0x7d1bc541UL, 0x3c2ade58UL, 0x054f79f0UL,
  76602. 0x447e62e9UL, 0x872d4fc2UL, 0xc61c54dbUL, 0x018a1594UL, 0x40bb0e8dUL,
  76603. 0x83e823a6UL, 0xc2d938bfUL, 0x0dc5a038UL, 0x4cf4bb21UL, 0x8fa7960aUL,
  76604. 0xce968d13UL, 0x0900cc5cUL, 0x4831d745UL, 0x8b62fa6eUL, 0xca53e177UL,
  76605. 0x545dbbbaUL, 0x156ca0a3UL, 0xd63f8d88UL, 0x970e9691UL, 0x5098d7deUL,
  76606. 0x11a9ccc7UL, 0xd2fae1ecUL, 0x93cbfaf5UL, 0x5cd76272UL, 0x1de6796bUL,
  76607. 0xdeb55440UL, 0x9f844f59UL, 0x58120e16UL, 0x1923150fUL, 0xda703824UL,
  76608. 0x9b41233dUL, 0xa76bfd65UL, 0xe65ae67cUL, 0x2509cb57UL, 0x6438d04eUL,
  76609. 0xa3ae9101UL, 0xe29f8a18UL, 0x21cca733UL, 0x60fdbc2aUL, 0xafe124adUL,
  76610. 0xeed03fb4UL, 0x2d83129fUL, 0x6cb20986UL, 0xab2448c9UL, 0xea1553d0UL,
  76611. 0x29467efbUL, 0x687765e2UL, 0xf6793f2fUL, 0xb7482436UL, 0x741b091dUL,
  76612. 0x352a1204UL, 0xf2bc534bUL, 0xb38d4852UL, 0x70de6579UL, 0x31ef7e60UL,
  76613. 0xfef3e6e7UL, 0xbfc2fdfeUL, 0x7c91d0d5UL, 0x3da0cbccUL, 0xfa368a83UL,
  76614. 0xbb07919aUL, 0x7854bcb1UL, 0x3965a7a8UL, 0x4b98833bUL, 0x0aa99822UL,
  76615. 0xc9fab509UL, 0x88cbae10UL, 0x4f5def5fUL, 0x0e6cf446UL, 0xcd3fd96dUL,
  76616. 0x8c0ec274UL, 0x43125af3UL, 0x022341eaUL, 0xc1706cc1UL, 0x804177d8UL,
  76617. 0x47d73697UL, 0x06e62d8eUL, 0xc5b500a5UL, 0x84841bbcUL, 0x1a8a4171UL,
  76618. 0x5bbb5a68UL, 0x98e87743UL, 0xd9d96c5aUL, 0x1e4f2d15UL, 0x5f7e360cUL,
  76619. 0x9c2d1b27UL, 0xdd1c003eUL, 0x120098b9UL, 0x533183a0UL, 0x9062ae8bUL,
  76620. 0xd153b592UL, 0x16c5f4ddUL, 0x57f4efc4UL, 0x94a7c2efUL, 0xd596d9f6UL,
  76621. 0xe9bc07aeUL, 0xa88d1cb7UL, 0x6bde319cUL, 0x2aef2a85UL, 0xed796bcaUL,
  76622. 0xac4870d3UL, 0x6f1b5df8UL, 0x2e2a46e1UL, 0xe136de66UL, 0xa007c57fUL,
  76623. 0x6354e854UL, 0x2265f34dUL, 0xe5f3b202UL, 0xa4c2a91bUL, 0x67918430UL,
  76624. 0x26a09f29UL, 0xb8aec5e4UL, 0xf99fdefdUL, 0x3accf3d6UL, 0x7bfde8cfUL,
  76625. 0xbc6ba980UL, 0xfd5ab299UL, 0x3e099fb2UL, 0x7f3884abUL, 0xb0241c2cUL,
  76626. 0xf1150735UL, 0x32462a1eUL, 0x73773107UL, 0xb4e17048UL, 0xf5d06b51UL,
  76627. 0x3683467aUL, 0x77b25d63UL, 0x4ed7facbUL, 0x0fe6e1d2UL, 0xccb5ccf9UL,
  76628. 0x8d84d7e0UL, 0x4a1296afUL, 0x0b238db6UL, 0xc870a09dUL, 0x8941bb84UL,
  76629. 0x465d2303UL, 0x076c381aUL, 0xc43f1531UL, 0x850e0e28UL, 0x42984f67UL,
  76630. 0x03a9547eUL, 0xc0fa7955UL, 0x81cb624cUL, 0x1fc53881UL, 0x5ef42398UL,
  76631. 0x9da70eb3UL, 0xdc9615aaUL, 0x1b0054e5UL, 0x5a314ffcUL, 0x996262d7UL,
  76632. 0xd85379ceUL, 0x174fe149UL, 0x567efa50UL, 0x952dd77bUL, 0xd41ccc62UL,
  76633. 0x138a8d2dUL, 0x52bb9634UL, 0x91e8bb1fUL, 0xd0d9a006UL, 0xecf37e5eUL,
  76634. 0xadc26547UL, 0x6e91486cUL, 0x2fa05375UL, 0xe836123aUL, 0xa9070923UL,
  76635. 0x6a542408UL, 0x2b653f11UL, 0xe479a796UL, 0xa548bc8fUL, 0x661b91a4UL,
  76636. 0x272a8abdUL, 0xe0bccbf2UL, 0xa18dd0ebUL, 0x62defdc0UL, 0x23efe6d9UL,
  76637. 0xbde1bc14UL, 0xfcd0a70dUL, 0x3f838a26UL, 0x7eb2913fUL, 0xb924d070UL,
  76638. 0xf815cb69UL, 0x3b46e642UL, 0x7a77fd5bUL, 0xb56b65dcUL, 0xf45a7ec5UL,
  76639. 0x370953eeUL, 0x763848f7UL, 0xb1ae09b8UL, 0xf09f12a1UL, 0x33cc3f8aUL,
  76640. 0x72fd2493UL
  76641. },
  76642. {
  76643. 0x00000000UL, 0x376ac201UL, 0x6ed48403UL, 0x59be4602UL, 0xdca80907UL,
  76644. 0xebc2cb06UL, 0xb27c8d04UL, 0x85164f05UL, 0xb851130eUL, 0x8f3bd10fUL,
  76645. 0xd685970dUL, 0xe1ef550cUL, 0x64f91a09UL, 0x5393d808UL, 0x0a2d9e0aUL,
  76646. 0x3d475c0bUL, 0x70a3261cUL, 0x47c9e41dUL, 0x1e77a21fUL, 0x291d601eUL,
  76647. 0xac0b2f1bUL, 0x9b61ed1aUL, 0xc2dfab18UL, 0xf5b56919UL, 0xc8f23512UL,
  76648. 0xff98f713UL, 0xa626b111UL, 0x914c7310UL, 0x145a3c15UL, 0x2330fe14UL,
  76649. 0x7a8eb816UL, 0x4de47a17UL, 0xe0464d38UL, 0xd72c8f39UL, 0x8e92c93bUL,
  76650. 0xb9f80b3aUL, 0x3cee443fUL, 0x0b84863eUL, 0x523ac03cUL, 0x6550023dUL,
  76651. 0x58175e36UL, 0x6f7d9c37UL, 0x36c3da35UL, 0x01a91834UL, 0x84bf5731UL,
  76652. 0xb3d59530UL, 0xea6bd332UL, 0xdd011133UL, 0x90e56b24UL, 0xa78fa925UL,
  76653. 0xfe31ef27UL, 0xc95b2d26UL, 0x4c4d6223UL, 0x7b27a022UL, 0x2299e620UL,
  76654. 0x15f32421UL, 0x28b4782aUL, 0x1fdeba2bUL, 0x4660fc29UL, 0x710a3e28UL,
  76655. 0xf41c712dUL, 0xc376b32cUL, 0x9ac8f52eUL, 0xada2372fUL, 0xc08d9a70UL,
  76656. 0xf7e75871UL, 0xae591e73UL, 0x9933dc72UL, 0x1c259377UL, 0x2b4f5176UL,
  76657. 0x72f11774UL, 0x459bd575UL, 0x78dc897eUL, 0x4fb64b7fUL, 0x16080d7dUL,
  76658. 0x2162cf7cUL, 0xa4748079UL, 0x931e4278UL, 0xcaa0047aUL, 0xfdcac67bUL,
  76659. 0xb02ebc6cUL, 0x87447e6dUL, 0xdefa386fUL, 0xe990fa6eUL, 0x6c86b56bUL,
  76660. 0x5bec776aUL, 0x02523168UL, 0x3538f369UL, 0x087faf62UL, 0x3f156d63UL,
  76661. 0x66ab2b61UL, 0x51c1e960UL, 0xd4d7a665UL, 0xe3bd6464UL, 0xba032266UL,
  76662. 0x8d69e067UL, 0x20cbd748UL, 0x17a11549UL, 0x4e1f534bUL, 0x7975914aUL,
  76663. 0xfc63de4fUL, 0xcb091c4eUL, 0x92b75a4cUL, 0xa5dd984dUL, 0x989ac446UL,
  76664. 0xaff00647UL, 0xf64e4045UL, 0xc1248244UL, 0x4432cd41UL, 0x73580f40UL,
  76665. 0x2ae64942UL, 0x1d8c8b43UL, 0x5068f154UL, 0x67023355UL, 0x3ebc7557UL,
  76666. 0x09d6b756UL, 0x8cc0f853UL, 0xbbaa3a52UL, 0xe2147c50UL, 0xd57ebe51UL,
  76667. 0xe839e25aUL, 0xdf53205bUL, 0x86ed6659UL, 0xb187a458UL, 0x3491eb5dUL,
  76668. 0x03fb295cUL, 0x5a456f5eUL, 0x6d2fad5fUL, 0x801b35e1UL, 0xb771f7e0UL,
  76669. 0xeecfb1e2UL, 0xd9a573e3UL, 0x5cb33ce6UL, 0x6bd9fee7UL, 0x3267b8e5UL,
  76670. 0x050d7ae4UL, 0x384a26efUL, 0x0f20e4eeUL, 0x569ea2ecUL, 0x61f460edUL,
  76671. 0xe4e22fe8UL, 0xd388ede9UL, 0x8a36abebUL, 0xbd5c69eaUL, 0xf0b813fdUL,
  76672. 0xc7d2d1fcUL, 0x9e6c97feUL, 0xa90655ffUL, 0x2c101afaUL, 0x1b7ad8fbUL,
  76673. 0x42c49ef9UL, 0x75ae5cf8UL, 0x48e900f3UL, 0x7f83c2f2UL, 0x263d84f0UL,
  76674. 0x115746f1UL, 0x944109f4UL, 0xa32bcbf5UL, 0xfa958df7UL, 0xcdff4ff6UL,
  76675. 0x605d78d9UL, 0x5737bad8UL, 0x0e89fcdaUL, 0x39e33edbUL, 0xbcf571deUL,
  76676. 0x8b9fb3dfUL, 0xd221f5ddUL, 0xe54b37dcUL, 0xd80c6bd7UL, 0xef66a9d6UL,
  76677. 0xb6d8efd4UL, 0x81b22dd5UL, 0x04a462d0UL, 0x33cea0d1UL, 0x6a70e6d3UL,
  76678. 0x5d1a24d2UL, 0x10fe5ec5UL, 0x27949cc4UL, 0x7e2adac6UL, 0x494018c7UL,
  76679. 0xcc5657c2UL, 0xfb3c95c3UL, 0xa282d3c1UL, 0x95e811c0UL, 0xa8af4dcbUL,
  76680. 0x9fc58fcaUL, 0xc67bc9c8UL, 0xf1110bc9UL, 0x740744ccUL, 0x436d86cdUL,
  76681. 0x1ad3c0cfUL, 0x2db902ceUL, 0x4096af91UL, 0x77fc6d90UL, 0x2e422b92UL,
  76682. 0x1928e993UL, 0x9c3ea696UL, 0xab546497UL, 0xf2ea2295UL, 0xc580e094UL,
  76683. 0xf8c7bc9fUL, 0xcfad7e9eUL, 0x9613389cUL, 0xa179fa9dUL, 0x246fb598UL,
  76684. 0x13057799UL, 0x4abb319bUL, 0x7dd1f39aUL, 0x3035898dUL, 0x075f4b8cUL,
  76685. 0x5ee10d8eUL, 0x698bcf8fUL, 0xec9d808aUL, 0xdbf7428bUL, 0x82490489UL,
  76686. 0xb523c688UL, 0x88649a83UL, 0xbf0e5882UL, 0xe6b01e80UL, 0xd1dadc81UL,
  76687. 0x54cc9384UL, 0x63a65185UL, 0x3a181787UL, 0x0d72d586UL, 0xa0d0e2a9UL,
  76688. 0x97ba20a8UL, 0xce0466aaUL, 0xf96ea4abUL, 0x7c78ebaeUL, 0x4b1229afUL,
  76689. 0x12ac6fadUL, 0x25c6adacUL, 0x1881f1a7UL, 0x2feb33a6UL, 0x765575a4UL,
  76690. 0x413fb7a5UL, 0xc429f8a0UL, 0xf3433aa1UL, 0xaafd7ca3UL, 0x9d97bea2UL,
  76691. 0xd073c4b5UL, 0xe71906b4UL, 0xbea740b6UL, 0x89cd82b7UL, 0x0cdbcdb2UL,
  76692. 0x3bb10fb3UL, 0x620f49b1UL, 0x55658bb0UL, 0x6822d7bbUL, 0x5f4815baUL,
  76693. 0x06f653b8UL, 0x319c91b9UL, 0xb48adebcUL, 0x83e01cbdUL, 0xda5e5abfUL,
  76694. 0xed3498beUL
  76695. },
  76696. {
  76697. 0x00000000UL, 0x6567bcb8UL, 0x8bc809aaUL, 0xeeafb512UL, 0x5797628fUL,
  76698. 0x32f0de37UL, 0xdc5f6b25UL, 0xb938d79dUL, 0xef28b4c5UL, 0x8a4f087dUL,
  76699. 0x64e0bd6fUL, 0x018701d7UL, 0xb8bfd64aUL, 0xddd86af2UL, 0x3377dfe0UL,
  76700. 0x56106358UL, 0x9f571950UL, 0xfa30a5e8UL, 0x149f10faUL, 0x71f8ac42UL,
  76701. 0xc8c07bdfUL, 0xada7c767UL, 0x43087275UL, 0x266fcecdUL, 0x707fad95UL,
  76702. 0x1518112dUL, 0xfbb7a43fUL, 0x9ed01887UL, 0x27e8cf1aUL, 0x428f73a2UL,
  76703. 0xac20c6b0UL, 0xc9477a08UL, 0x3eaf32a0UL, 0x5bc88e18UL, 0xb5673b0aUL,
  76704. 0xd00087b2UL, 0x6938502fUL, 0x0c5fec97UL, 0xe2f05985UL, 0x8797e53dUL,
  76705. 0xd1878665UL, 0xb4e03addUL, 0x5a4f8fcfUL, 0x3f283377UL, 0x8610e4eaUL,
  76706. 0xe3775852UL, 0x0dd8ed40UL, 0x68bf51f8UL, 0xa1f82bf0UL, 0xc49f9748UL,
  76707. 0x2a30225aUL, 0x4f579ee2UL, 0xf66f497fUL, 0x9308f5c7UL, 0x7da740d5UL,
  76708. 0x18c0fc6dUL, 0x4ed09f35UL, 0x2bb7238dUL, 0xc518969fUL, 0xa07f2a27UL,
  76709. 0x1947fdbaUL, 0x7c204102UL, 0x928ff410UL, 0xf7e848a8UL, 0x3d58149bUL,
  76710. 0x583fa823UL, 0xb6901d31UL, 0xd3f7a189UL, 0x6acf7614UL, 0x0fa8caacUL,
  76711. 0xe1077fbeUL, 0x8460c306UL, 0xd270a05eUL, 0xb7171ce6UL, 0x59b8a9f4UL,
  76712. 0x3cdf154cUL, 0x85e7c2d1UL, 0xe0807e69UL, 0x0e2fcb7bUL, 0x6b4877c3UL,
  76713. 0xa20f0dcbUL, 0xc768b173UL, 0x29c70461UL, 0x4ca0b8d9UL, 0xf5986f44UL,
  76714. 0x90ffd3fcUL, 0x7e5066eeUL, 0x1b37da56UL, 0x4d27b90eUL, 0x284005b6UL,
  76715. 0xc6efb0a4UL, 0xa3880c1cUL, 0x1ab0db81UL, 0x7fd76739UL, 0x9178d22bUL,
  76716. 0xf41f6e93UL, 0x03f7263bUL, 0x66909a83UL, 0x883f2f91UL, 0xed589329UL,
  76717. 0x546044b4UL, 0x3107f80cUL, 0xdfa84d1eUL, 0xbacff1a6UL, 0xecdf92feUL,
  76718. 0x89b82e46UL, 0x67179b54UL, 0x027027ecUL, 0xbb48f071UL, 0xde2f4cc9UL,
  76719. 0x3080f9dbUL, 0x55e74563UL, 0x9ca03f6bUL, 0xf9c783d3UL, 0x176836c1UL,
  76720. 0x720f8a79UL, 0xcb375de4UL, 0xae50e15cUL, 0x40ff544eUL, 0x2598e8f6UL,
  76721. 0x73888baeUL, 0x16ef3716UL, 0xf8408204UL, 0x9d273ebcUL, 0x241fe921UL,
  76722. 0x41785599UL, 0xafd7e08bUL, 0xcab05c33UL, 0x3bb659edUL, 0x5ed1e555UL,
  76723. 0xb07e5047UL, 0xd519ecffUL, 0x6c213b62UL, 0x094687daUL, 0xe7e932c8UL,
  76724. 0x828e8e70UL, 0xd49eed28UL, 0xb1f95190UL, 0x5f56e482UL, 0x3a31583aUL,
  76725. 0x83098fa7UL, 0xe66e331fUL, 0x08c1860dUL, 0x6da63ab5UL, 0xa4e140bdUL,
  76726. 0xc186fc05UL, 0x2f294917UL, 0x4a4ef5afUL, 0xf3762232UL, 0x96119e8aUL,
  76727. 0x78be2b98UL, 0x1dd99720UL, 0x4bc9f478UL, 0x2eae48c0UL, 0xc001fdd2UL,
  76728. 0xa566416aUL, 0x1c5e96f7UL, 0x79392a4fUL, 0x97969f5dUL, 0xf2f123e5UL,
  76729. 0x05196b4dUL, 0x607ed7f5UL, 0x8ed162e7UL, 0xebb6de5fUL, 0x528e09c2UL,
  76730. 0x37e9b57aUL, 0xd9460068UL, 0xbc21bcd0UL, 0xea31df88UL, 0x8f566330UL,
  76731. 0x61f9d622UL, 0x049e6a9aUL, 0xbda6bd07UL, 0xd8c101bfUL, 0x366eb4adUL,
  76732. 0x53090815UL, 0x9a4e721dUL, 0xff29cea5UL, 0x11867bb7UL, 0x74e1c70fUL,
  76733. 0xcdd91092UL, 0xa8beac2aUL, 0x46111938UL, 0x2376a580UL, 0x7566c6d8UL,
  76734. 0x10017a60UL, 0xfeaecf72UL, 0x9bc973caUL, 0x22f1a457UL, 0x479618efUL,
  76735. 0xa939adfdUL, 0xcc5e1145UL, 0x06ee4d76UL, 0x6389f1ceUL, 0x8d2644dcUL,
  76736. 0xe841f864UL, 0x51792ff9UL, 0x341e9341UL, 0xdab12653UL, 0xbfd69aebUL,
  76737. 0xe9c6f9b3UL, 0x8ca1450bUL, 0x620ef019UL, 0x07694ca1UL, 0xbe519b3cUL,
  76738. 0xdb362784UL, 0x35999296UL, 0x50fe2e2eUL, 0x99b95426UL, 0xfcdee89eUL,
  76739. 0x12715d8cUL, 0x7716e134UL, 0xce2e36a9UL, 0xab498a11UL, 0x45e63f03UL,
  76740. 0x208183bbUL, 0x7691e0e3UL, 0x13f65c5bUL, 0xfd59e949UL, 0x983e55f1UL,
  76741. 0x2106826cUL, 0x44613ed4UL, 0xaace8bc6UL, 0xcfa9377eUL, 0x38417fd6UL,
  76742. 0x5d26c36eUL, 0xb389767cUL, 0xd6eecac4UL, 0x6fd61d59UL, 0x0ab1a1e1UL,
  76743. 0xe41e14f3UL, 0x8179a84bUL, 0xd769cb13UL, 0xb20e77abUL, 0x5ca1c2b9UL,
  76744. 0x39c67e01UL, 0x80fea99cUL, 0xe5991524UL, 0x0b36a036UL, 0x6e511c8eUL,
  76745. 0xa7166686UL, 0xc271da3eUL, 0x2cde6f2cUL, 0x49b9d394UL, 0xf0810409UL,
  76746. 0x95e6b8b1UL, 0x7b490da3UL, 0x1e2eb11bUL, 0x483ed243UL, 0x2d596efbUL,
  76747. 0xc3f6dbe9UL, 0xa6916751UL, 0x1fa9b0ccUL, 0x7ace0c74UL, 0x9461b966UL,
  76748. 0xf10605deUL
  76749. #endif
  76750. }
  76751. };
  76752. /*** End of inlined file: crc32.h ***/
  76753. #endif /* DYNAMIC_CRC_TABLE */
  76754. const unsigned long FAR * ZEXPORT get_crc_table()
  76755. {
  76756. #ifdef DYNAMIC_CRC_TABLE
  76757. if (crc_table_empty)
  76758. make_crc_table();
  76759. #endif /* DYNAMIC_CRC_TABLE */
  76760. return (const unsigned long FAR *)crc_table;
  76761. }
  76762. #define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8)
  76763. #define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1
  76764. unsigned long ZEXPORT crc32 (unsigned long crc, const unsigned char FAR *buf, unsigned len)
  76765. {
  76766. if (buf == Z_NULL) return 0UL;
  76767. #ifdef DYNAMIC_CRC_TABLE
  76768. if (crc_table_empty)
  76769. make_crc_table();
  76770. #endif /* DYNAMIC_CRC_TABLE */
  76771. #ifdef BYFOUR
  76772. if (sizeof(void *) == sizeof(ptrdiff_t)) {
  76773. u4 endian;
  76774. endian = 1;
  76775. if (*((unsigned char *)(&endian)))
  76776. return crc32_little(crc, buf, len);
  76777. else
  76778. return crc32_big(crc, buf, len);
  76779. }
  76780. #endif /* BYFOUR */
  76781. crc = crc ^ 0xffffffffUL;
  76782. while (len >= 8) {
  76783. DO8;
  76784. len -= 8;
  76785. }
  76786. if (len) do {
  76787. DO1;
  76788. } while (--len);
  76789. return crc ^ 0xffffffffUL;
  76790. }
  76791. #ifdef BYFOUR
  76792. #define DOLIT4 c ^= *buf4++; \
  76793. c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \
  76794. crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24]
  76795. #define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4
  76796. local unsigned long crc32_little(unsigned long crc, const unsigned char FAR *buf, unsigned len)
  76797. {
  76798. register u4 c;
  76799. register const u4 FAR *buf4;
  76800. c = (u4)crc;
  76801. c = ~c;
  76802. while (len && ((ptrdiff_t)buf & 3)) {
  76803. c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
  76804. len--;
  76805. }
  76806. buf4 = (const u4 FAR *)(const void FAR *)buf;
  76807. while (len >= 32) {
  76808. DOLIT32;
  76809. len -= 32;
  76810. }
  76811. while (len >= 4) {
  76812. DOLIT4;
  76813. len -= 4;
  76814. }
  76815. buf = (const unsigned char FAR *)buf4;
  76816. if (len) do {
  76817. c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
  76818. } while (--len);
  76819. c = ~c;
  76820. return (unsigned long)c;
  76821. }
  76822. #define DOBIG4 c ^= *++buf4; \
  76823. c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \
  76824. crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24]
  76825. #define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4
  76826. local unsigned long crc32_big (unsigned long crc, const unsigned char FAR *buf, unsigned len)
  76827. {
  76828. register u4 c;
  76829. register const u4 FAR *buf4;
  76830. c = REV((u4)crc);
  76831. c = ~c;
  76832. while (len && ((ptrdiff_t)buf & 3)) {
  76833. c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
  76834. len--;
  76835. }
  76836. buf4 = (const u4 FAR *)(const void FAR *)buf;
  76837. buf4--;
  76838. while (len >= 32) {
  76839. DOBIG32;
  76840. len -= 32;
  76841. }
  76842. while (len >= 4) {
  76843. DOBIG4;
  76844. len -= 4;
  76845. }
  76846. buf4++;
  76847. buf = (const unsigned char FAR *)buf4;
  76848. if (len) do {
  76849. c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
  76850. } while (--len);
  76851. c = ~c;
  76852. return (unsigned long)(REV(c));
  76853. }
  76854. #endif /* BYFOUR */
  76855. #define GF2_DIM 32 /* dimension of GF(2) vectors (length of CRC) */
  76856. local unsigned long gf2_matrix_times (unsigned long *mat, unsigned long vec)
  76857. {
  76858. unsigned long sum;
  76859. sum = 0;
  76860. while (vec) {
  76861. if (vec & 1)
  76862. sum ^= *mat;
  76863. vec >>= 1;
  76864. mat++;
  76865. }
  76866. return sum;
  76867. }
  76868. local void gf2_matrix_square (unsigned long *square, unsigned long *mat)
  76869. {
  76870. int n;
  76871. for (n = 0; n < GF2_DIM; n++)
  76872. square[n] = gf2_matrix_times(mat, mat[n]);
  76873. }
  76874. uLong ZEXPORT crc32_combine (uLong crc1, uLong crc2, z_off_t len2)
  76875. {
  76876. int n;
  76877. unsigned long row;
  76878. unsigned long even[GF2_DIM]; /* even-power-of-two zeros operator */
  76879. unsigned long odd[GF2_DIM]; /* odd-power-of-two zeros operator */
  76880. if (len2 == 0)
  76881. return crc1;
  76882. odd[0] = 0xedb88320L; /* CRC-32 polynomial */
  76883. row = 1;
  76884. for (n = 1; n < GF2_DIM; n++) {
  76885. odd[n] = row;
  76886. row <<= 1;
  76887. }
  76888. gf2_matrix_square(even, odd);
  76889. gf2_matrix_square(odd, even);
  76890. do {
  76891. gf2_matrix_square(even, odd);
  76892. if (len2 & 1)
  76893. crc1 = gf2_matrix_times(even, crc1);
  76894. len2 >>= 1;
  76895. if (len2 == 0)
  76896. break;
  76897. gf2_matrix_square(odd, even);
  76898. if (len2 & 1)
  76899. crc1 = gf2_matrix_times(odd, crc1);
  76900. len2 >>= 1;
  76901. } while (len2 != 0);
  76902. crc1 ^= crc2;
  76903. return crc1;
  76904. }
  76905. /*** End of inlined file: crc32.c ***/
  76906. /*** Start of inlined file: deflate.c ***/
  76907. /*** Start of inlined file: deflate.h ***/
  76908. #ifndef DEFLATE_H
  76909. #define DEFLATE_H
  76910. #ifndef NO_GZIP
  76911. # define GZIP
  76912. #endif
  76913. #define NO_DUMMY_DECL
  76914. #define LENGTH_CODES 29
  76915. #define LITERALS 256
  76916. #define L_CODES (LITERALS+1+LENGTH_CODES)
  76917. #define D_CODES 30
  76918. #define BL_CODES 19
  76919. #define HEAP_SIZE (2*L_CODES+1)
  76920. #define MAX_BITS 15
  76921. #define INIT_STATE 42
  76922. #define EXTRA_STATE 69
  76923. #define NAME_STATE 73
  76924. #define COMMENT_STATE 91
  76925. #define HCRC_STATE 103
  76926. #define BUSY_STATE 113
  76927. #define FINISH_STATE 666
  76928. typedef struct ct_data_s {
  76929. union {
  76930. ush freq; /* frequency count */
  76931. ush code; /* bit string */
  76932. } fc;
  76933. union {
  76934. ush dad; /* father node in Huffman tree */
  76935. ush len; /* length of bit string */
  76936. } dl;
  76937. } FAR ct_data;
  76938. #define Freq fc.freq
  76939. #define Code fc.code
  76940. #define Dad dl.dad
  76941. #define Len dl.len
  76942. typedef struct static_tree_desc_s static_tree_desc;
  76943. typedef struct tree_desc_s {
  76944. ct_data *dyn_tree; /* the dynamic tree */
  76945. int max_code; /* largest code with non zero frequency */
  76946. static_tree_desc *stat_desc; /* the corresponding static tree */
  76947. } FAR tree_desc;
  76948. typedef ush Pos;
  76949. typedef Pos FAR Posf;
  76950. typedef unsigned IPos;
  76951. typedef struct internal_state {
  76952. z_streamp strm; /* pointer back to this zlib stream */
  76953. int status; /* as the name implies */
  76954. Bytef *pending_buf; /* output still pending */
  76955. ulg pending_buf_size; /* size of pending_buf */
  76956. Bytef *pending_out; /* next pending byte to output to the stream */
  76957. uInt pending; /* nb of bytes in the pending buffer */
  76958. int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
  76959. gz_headerp gzhead; /* gzip header information to write */
  76960. uInt gzindex; /* where in extra, name, or comment */
  76961. Byte method; /* STORED (for zip only) or DEFLATED */
  76962. int last_flush; /* value of flush param for previous deflate call */
  76963. uInt w_size; /* LZ77 window size (32K by default) */
  76964. uInt w_bits; /* log2(w_size) (8..16) */
  76965. uInt w_mask; /* w_size - 1 */
  76966. Bytef *window;
  76967. ulg window_size;
  76968. Posf *prev;
  76969. Posf *head; /* Heads of the hash chains or NIL. */
  76970. uInt ins_h; /* hash index of string to be inserted */
  76971. uInt hash_size; /* number of elements in hash table */
  76972. uInt hash_bits; /* log2(hash_size) */
  76973. uInt hash_mask; /* hash_size-1 */
  76974. uInt hash_shift;
  76975. long block_start;
  76976. uInt match_length; /* length of best match */
  76977. IPos prev_match; /* previous match */
  76978. int match_available; /* set if previous match exists */
  76979. uInt strstart; /* start of string to insert */
  76980. uInt match_start; /* start of matching string */
  76981. uInt lookahead; /* number of valid bytes ahead in window */
  76982. uInt prev_length;
  76983. uInt max_chain_length;
  76984. uInt max_lazy_match;
  76985. # define max_insert_length max_lazy_match
  76986. int level; /* compression level (1..9) */
  76987. int strategy; /* favor or force Huffman coding*/
  76988. uInt good_match;
  76989. int nice_match; /* Stop searching when current match exceeds this */
  76990. struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */
  76991. struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
  76992. struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */
  76993. struct tree_desc_s l_desc; /* desc. for literal tree */
  76994. struct tree_desc_s d_desc; /* desc. for distance tree */
  76995. struct tree_desc_s bl_desc; /* desc. for bit length tree */
  76996. ush bl_count[MAX_BITS+1];
  76997. int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */
  76998. int heap_len; /* number of elements in the heap */
  76999. int heap_max; /* element of largest frequency */
  77000. uch depth[2*L_CODES+1];
  77001. uchf *l_buf; /* buffer for literals or lengths */
  77002. uInt lit_bufsize;
  77003. uInt last_lit; /* running index in l_buf */
  77004. ushf *d_buf;
  77005. ulg opt_len; /* bit length of current block with optimal trees */
  77006. ulg static_len; /* bit length of current block with static trees */
  77007. uInt matches; /* number of string matches in current block */
  77008. int last_eob_len; /* bit length of EOB code for last block */
  77009. #ifdef DEBUG
  77010. ulg compressed_len; /* total bit length of compressed file mod 2^32 */
  77011. ulg bits_sent; /* bit length of compressed data sent mod 2^32 */
  77012. #endif
  77013. ush bi_buf;
  77014. int bi_valid;
  77015. } FAR deflate_state;
  77016. #define put_byte(s, c) {s->pending_buf[s->pending++] = (c);}
  77017. #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
  77018. #define MAX_DIST(s) ((s)->w_size-MIN_LOOKAHEAD)
  77019. void _tr_init OF((deflate_state *s));
  77020. int _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc));
  77021. void _tr_flush_block OF((deflate_state *s, charf *buf, ulg stored_len,
  77022. int eof));
  77023. void _tr_align OF((deflate_state *s));
  77024. void _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len,
  77025. int eof));
  77026. #define d_code(dist) \
  77027. ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)])
  77028. #ifndef DEBUG
  77029. #if defined(GEN_TREES_H) || !defined(STDC)
  77030. extern uch _length_code[];
  77031. extern uch _dist_code[];
  77032. #else
  77033. extern const uch _length_code[];
  77034. extern const uch _dist_code[];
  77035. #endif
  77036. # define _tr_tally_lit(s, c, flush) \
  77037. { uch cc = (c); \
  77038. s->d_buf[s->last_lit] = 0; \
  77039. s->l_buf[s->last_lit++] = cc; \
  77040. s->dyn_ltree[cc].Freq++; \
  77041. flush = (s->last_lit == s->lit_bufsize-1); \
  77042. }
  77043. # define _tr_tally_dist(s, distance, length, flush) \
  77044. { uch len = (length); \
  77045. ush dist = (distance); \
  77046. s->d_buf[s->last_lit] = dist; \
  77047. s->l_buf[s->last_lit++] = len; \
  77048. dist--; \
  77049. s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
  77050. s->dyn_dtree[d_code(dist)].Freq++; \
  77051. flush = (s->last_lit == s->lit_bufsize-1); \
  77052. }
  77053. #else
  77054. # define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c)
  77055. # define _tr_tally_dist(s, distance, length, flush) \
  77056. flush = _tr_tally(s, distance, length)
  77057. #endif
  77058. #endif /* DEFLATE_H */
  77059. /*** End of inlined file: deflate.h ***/
  77060. const char deflate_copyright[] =
  77061. " deflate 1.2.3 Copyright 1995-2005 Jean-loup Gailly ";
  77062. typedef enum {
  77063. need_more, /* block not completed, need more input or more output */
  77064. block_done, /* block flush performed */
  77065. finish_started, /* finish started, need only more output at next deflate */
  77066. finish_done /* finish done, accept no more input or output */
  77067. } block_state;
  77068. typedef block_state (*compress_func) OF((deflate_state *s, int flush));
  77069. local void fill_window OF((deflate_state *s));
  77070. local block_state deflate_stored OF((deflate_state *s, int flush));
  77071. local block_state deflate_fast OF((deflate_state *s, int flush));
  77072. #ifndef FASTEST
  77073. local block_state deflate_slow OF((deflate_state *s, int flush));
  77074. #endif
  77075. local void lm_init OF((deflate_state *s));
  77076. local void putShortMSB OF((deflate_state *s, uInt b));
  77077. local void flush_pending OF((z_streamp strm));
  77078. local int read_buf OF((z_streamp strm, Bytef *buf, unsigned size));
  77079. #ifndef FASTEST
  77080. #ifdef ASMV
  77081. void match_init OF((void)); /* asm code initialization */
  77082. uInt longest_match OF((deflate_state *s, IPos cur_match));
  77083. #else
  77084. local uInt longest_match OF((deflate_state *s, IPos cur_match));
  77085. #endif
  77086. #endif
  77087. local uInt longest_match_fast OF((deflate_state *s, IPos cur_match));
  77088. #ifdef DEBUG
  77089. local void check_match OF((deflate_state *s, IPos start, IPos match,
  77090. int length));
  77091. #endif
  77092. #define NIL 0
  77093. #ifndef TOO_FAR
  77094. # define TOO_FAR 4096
  77095. #endif
  77096. #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
  77097. typedef struct config_s {
  77098. ush good_length; /* reduce lazy search above this match length */
  77099. ush max_lazy; /* do not perform lazy search above this match length */
  77100. ush nice_length; /* quit search above this match length */
  77101. ush max_chain;
  77102. compress_func func;
  77103. } config;
  77104. #ifdef FASTEST
  77105. local const config configuration_table[2] = {
  77106. {0, 0, 0, 0, deflate_stored}, /* store only */
  77107. {4, 4, 8, 4, deflate_fast}}; /* max speed, no lazy matches */
  77108. #else
  77109. local const config configuration_table[10] = {
  77110. {0, 0, 0, 0, deflate_stored}, /* store only */
  77111. {4, 4, 8, 4, deflate_fast}, /* max speed, no lazy matches */
  77112. {4, 5, 16, 8, deflate_fast},
  77113. {4, 6, 32, 32, deflate_fast},
  77114. {4, 4, 16, 16, deflate_slow}, /* lazy matches */
  77115. {8, 16, 32, 32, deflate_slow},
  77116. {8, 16, 128, 128, deflate_slow},
  77117. {8, 32, 128, 256, deflate_slow},
  77118. {32, 128, 258, 1024, deflate_slow},
  77119. {32, 258, 258, 4096, deflate_slow}}; /* max compression */
  77120. #endif
  77121. #define EQUAL 0
  77122. #ifndef NO_DUMMY_DECL
  77123. struct static_tree_desc_s {int dummy;}; /* for buggy compilers */
  77124. #endif
  77125. #define UPDATE_HASH(s,h,c) (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask)
  77126. #ifdef FASTEST
  77127. #define INSERT_STRING(s, str, match_head) \
  77128. (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
  77129. match_head = s->head[s->ins_h], \
  77130. s->head[s->ins_h] = (Pos)(str))
  77131. #else
  77132. #define INSERT_STRING(s, str, match_head) \
  77133. (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
  77134. match_head = s->prev[(str) & s->w_mask] = s->head[s->ins_h], \
  77135. s->head[s->ins_h] = (Pos)(str))
  77136. #endif
  77137. #define CLEAR_HASH(s) \
  77138. s->head[s->hash_size-1] = NIL; \
  77139. zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head));
  77140. int ZEXPORT deflateInit_(z_streamp strm, int level, const char *version, int stream_size)
  77141. {
  77142. return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL,
  77143. Z_DEFAULT_STRATEGY, version, stream_size);
  77144. }
  77145. int ZEXPORT deflateInit2_ (z_streamp strm, int level, int method, int windowBits, int memLevel, int strategy, const char *version, int stream_size)
  77146. {
  77147. deflate_state *s;
  77148. int wrap = 1;
  77149. static const char my_version[] = ZLIB_VERSION;
  77150. ushf *overlay;
  77151. if (version == Z_NULL || version[0] != my_version[0] ||
  77152. stream_size != sizeof(z_stream)) {
  77153. return Z_VERSION_ERROR;
  77154. }
  77155. if (strm == Z_NULL) return Z_STREAM_ERROR;
  77156. strm->msg = Z_NULL;
  77157. if (strm->zalloc == (alloc_func)0) {
  77158. strm->zalloc = zcalloc;
  77159. strm->opaque = (voidpf)0;
  77160. }
  77161. if (strm->zfree == (free_func)0) strm->zfree = zcfree;
  77162. #ifdef FASTEST
  77163. if (level != 0) level = 1;
  77164. #else
  77165. if (level == Z_DEFAULT_COMPRESSION) level = 6;
  77166. #endif
  77167. if (windowBits < 0) { /* suppress zlib wrapper */
  77168. wrap = 0;
  77169. windowBits = -windowBits;
  77170. }
  77171. #ifdef GZIP
  77172. else if (windowBits > 15) {
  77173. wrap = 2; /* write gzip wrapper instead */
  77174. windowBits -= 16;
  77175. }
  77176. #endif
  77177. if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED ||
  77178. windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
  77179. strategy < 0 || strategy > Z_FIXED) {
  77180. return Z_STREAM_ERROR;
  77181. }
  77182. if (windowBits == 8) windowBits = 9; /* until 256-byte window bug fixed */
  77183. s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state));
  77184. if (s == Z_NULL) return Z_MEM_ERROR;
  77185. strm->state = (struct internal_state FAR *)s;
  77186. s->strm = strm;
  77187. s->wrap = wrap;
  77188. s->gzhead = Z_NULL;
  77189. s->w_bits = windowBits;
  77190. s->w_size = 1 << s->w_bits;
  77191. s->w_mask = s->w_size - 1;
  77192. s->hash_bits = memLevel + 7;
  77193. s->hash_size = 1 << s->hash_bits;
  77194. s->hash_mask = s->hash_size - 1;
  77195. s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH);
  77196. s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte));
  77197. s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos));
  77198. s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos));
  77199. s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */
  77200. overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2);
  77201. s->pending_buf = (uchf *) overlay;
  77202. s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(ush)+2L);
  77203. if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
  77204. s->pending_buf == Z_NULL) {
  77205. s->status = FINISH_STATE;
  77206. strm->msg = (char*)ERR_MSG(Z_MEM_ERROR);
  77207. deflateEnd (strm);
  77208. return Z_MEM_ERROR;
  77209. }
  77210. s->d_buf = overlay + s->lit_bufsize/sizeof(ush);
  77211. s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize;
  77212. s->level = level;
  77213. s->strategy = strategy;
  77214. s->method = (Byte)method;
  77215. return deflateReset(strm);
  77216. }
  77217. int ZEXPORT deflateSetDictionary (z_streamp strm, const Bytef *dictionary, uInt dictLength)
  77218. {
  77219. deflate_state *s;
  77220. uInt length = dictLength;
  77221. uInt n;
  77222. IPos hash_head = 0;
  77223. if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL ||
  77224. strm->state->wrap == 2 ||
  77225. (strm->state->wrap == 1 && strm->state->status != INIT_STATE))
  77226. return Z_STREAM_ERROR;
  77227. s = strm->state;
  77228. if (s->wrap)
  77229. strm->adler = adler32(strm->adler, dictionary, dictLength);
  77230. if (length < MIN_MATCH) return Z_OK;
  77231. if (length > MAX_DIST(s)) {
  77232. length = MAX_DIST(s);
  77233. dictionary += dictLength - length; /* use the tail of the dictionary */
  77234. }
  77235. zmemcpy(s->window, dictionary, length);
  77236. s->strstart = length;
  77237. s->block_start = (long)length;
  77238. s->ins_h = s->window[0];
  77239. UPDATE_HASH(s, s->ins_h, s->window[1]);
  77240. for (n = 0; n <= length - MIN_MATCH; n++) {
  77241. INSERT_STRING(s, n, hash_head);
  77242. }
  77243. if (hash_head) hash_head = 0; /* to make compiler happy */
  77244. return Z_OK;
  77245. }
  77246. int ZEXPORT deflateReset (z_streamp strm)
  77247. {
  77248. deflate_state *s;
  77249. if (strm == Z_NULL || strm->state == Z_NULL ||
  77250. strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) {
  77251. return Z_STREAM_ERROR;
  77252. }
  77253. strm->total_in = strm->total_out = 0;
  77254. strm->msg = Z_NULL; /* use zfree if we ever allocate msg dynamically */
  77255. strm->data_type = Z_UNKNOWN;
  77256. s = (deflate_state *)strm->state;
  77257. s->pending = 0;
  77258. s->pending_out = s->pending_buf;
  77259. if (s->wrap < 0) {
  77260. s->wrap = -s->wrap; /* was made negative by deflate(..., Z_FINISH); */
  77261. }
  77262. s->status = s->wrap ? INIT_STATE : BUSY_STATE;
  77263. strm->adler =
  77264. #ifdef GZIP
  77265. s->wrap == 2 ? crc32(0L, Z_NULL, 0) :
  77266. #endif
  77267. adler32(0L, Z_NULL, 0);
  77268. s->last_flush = Z_NO_FLUSH;
  77269. _tr_init(s);
  77270. lm_init(s);
  77271. return Z_OK;
  77272. }
  77273. int ZEXPORT deflateSetHeader (z_streamp strm, gz_headerp head)
  77274. {
  77275. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77276. if (strm->state->wrap != 2) return Z_STREAM_ERROR;
  77277. strm->state->gzhead = head;
  77278. return Z_OK;
  77279. }
  77280. int ZEXPORT deflatePrime (z_streamp strm, int bits, int value)
  77281. {
  77282. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77283. strm->state->bi_valid = bits;
  77284. strm->state->bi_buf = (ush)(value & ((1 << bits) - 1));
  77285. return Z_OK;
  77286. }
  77287. int ZEXPORT deflateParams (z_streamp strm, int level, int strategy)
  77288. {
  77289. deflate_state *s;
  77290. compress_func func;
  77291. int err = Z_OK;
  77292. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77293. s = strm->state;
  77294. #ifdef FASTEST
  77295. if (level != 0) level = 1;
  77296. #else
  77297. if (level == Z_DEFAULT_COMPRESSION) level = 6;
  77298. #endif
  77299. if (level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED) {
  77300. return Z_STREAM_ERROR;
  77301. }
  77302. func = configuration_table[s->level].func;
  77303. if (func != configuration_table[level].func && strm->total_in != 0) {
  77304. err = deflate(strm, Z_PARTIAL_FLUSH);
  77305. }
  77306. if (s->level != level) {
  77307. s->level = level;
  77308. s->max_lazy_match = configuration_table[level].max_lazy;
  77309. s->good_match = configuration_table[level].good_length;
  77310. s->nice_match = configuration_table[level].nice_length;
  77311. s->max_chain_length = configuration_table[level].max_chain;
  77312. }
  77313. s->strategy = strategy;
  77314. return err;
  77315. }
  77316. int ZEXPORT deflateTune (z_streamp strm, int good_length, int max_lazy, int nice_length, int max_chain)
  77317. {
  77318. deflate_state *s;
  77319. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77320. s = strm->state;
  77321. s->good_match = good_length;
  77322. s->max_lazy_match = max_lazy;
  77323. s->nice_match = nice_length;
  77324. s->max_chain_length = max_chain;
  77325. return Z_OK;
  77326. }
  77327. uLong ZEXPORT deflateBound (z_streamp strm, uLong sourceLen)
  77328. {
  77329. deflate_state *s;
  77330. uLong destLen;
  77331. destLen = sourceLen +
  77332. ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 11;
  77333. if (strm == Z_NULL || strm->state == Z_NULL)
  77334. return destLen;
  77335. s = strm->state;
  77336. if (s->w_bits != 15 || s->hash_bits != 8 + 7)
  77337. return destLen;
  77338. return compressBound(sourceLen);
  77339. }
  77340. local void putShortMSB (deflate_state *s, uInt b)
  77341. {
  77342. put_byte(s, (Byte)(b >> 8));
  77343. put_byte(s, (Byte)(b & 0xff));
  77344. }
  77345. local void flush_pending (z_streamp strm)
  77346. {
  77347. unsigned len = strm->state->pending;
  77348. if (len > strm->avail_out) len = strm->avail_out;
  77349. if (len == 0) return;
  77350. zmemcpy(strm->next_out, strm->state->pending_out, len);
  77351. strm->next_out += len;
  77352. strm->state->pending_out += len;
  77353. strm->total_out += len;
  77354. strm->avail_out -= len;
  77355. strm->state->pending -= len;
  77356. if (strm->state->pending == 0) {
  77357. strm->state->pending_out = strm->state->pending_buf;
  77358. }
  77359. }
  77360. int ZEXPORT deflate (z_streamp strm, int flush)
  77361. {
  77362. int old_flush; /* value of flush param for previous deflate call */
  77363. deflate_state *s;
  77364. if (strm == Z_NULL || strm->state == Z_NULL ||
  77365. flush > Z_FINISH || flush < 0) {
  77366. return Z_STREAM_ERROR;
  77367. }
  77368. s = strm->state;
  77369. if (strm->next_out == Z_NULL ||
  77370. (strm->next_in == Z_NULL && strm->avail_in != 0) ||
  77371. (s->status == FINISH_STATE && flush != Z_FINISH)) {
  77372. ERR_RETURN(strm, Z_STREAM_ERROR);
  77373. }
  77374. if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR);
  77375. s->strm = strm; /* just in case */
  77376. old_flush = s->last_flush;
  77377. s->last_flush = flush;
  77378. if (s->status == INIT_STATE) {
  77379. #ifdef GZIP
  77380. if (s->wrap == 2) {
  77381. strm->adler = crc32(0L, Z_NULL, 0);
  77382. put_byte(s, 31);
  77383. put_byte(s, 139);
  77384. put_byte(s, 8);
  77385. if (s->gzhead == NULL) {
  77386. put_byte(s, 0);
  77387. put_byte(s, 0);
  77388. put_byte(s, 0);
  77389. put_byte(s, 0);
  77390. put_byte(s, 0);
  77391. put_byte(s, s->level == 9 ? 2 :
  77392. (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
  77393. 4 : 0));
  77394. put_byte(s, OS_CODE);
  77395. s->status = BUSY_STATE;
  77396. }
  77397. else {
  77398. put_byte(s, (s->gzhead->text ? 1 : 0) +
  77399. (s->gzhead->hcrc ? 2 : 0) +
  77400. (s->gzhead->extra == Z_NULL ? 0 : 4) +
  77401. (s->gzhead->name == Z_NULL ? 0 : 8) +
  77402. (s->gzhead->comment == Z_NULL ? 0 : 16)
  77403. );
  77404. put_byte(s, (Byte)(s->gzhead->time & 0xff));
  77405. put_byte(s, (Byte)((s->gzhead->time >> 8) & 0xff));
  77406. put_byte(s, (Byte)((s->gzhead->time >> 16) & 0xff));
  77407. put_byte(s, (Byte)((s->gzhead->time >> 24) & 0xff));
  77408. put_byte(s, s->level == 9 ? 2 :
  77409. (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
  77410. 4 : 0));
  77411. put_byte(s, s->gzhead->os & 0xff);
  77412. if (s->gzhead->extra != NULL) {
  77413. put_byte(s, s->gzhead->extra_len & 0xff);
  77414. put_byte(s, (s->gzhead->extra_len >> 8) & 0xff);
  77415. }
  77416. if (s->gzhead->hcrc)
  77417. strm->adler = crc32(strm->adler, s->pending_buf,
  77418. s->pending);
  77419. s->gzindex = 0;
  77420. s->status = EXTRA_STATE;
  77421. }
  77422. }
  77423. else
  77424. #endif
  77425. {
  77426. uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8;
  77427. uInt level_flags;
  77428. if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2)
  77429. level_flags = 0;
  77430. else if (s->level < 6)
  77431. level_flags = 1;
  77432. else if (s->level == 6)
  77433. level_flags = 2;
  77434. else
  77435. level_flags = 3;
  77436. header |= (level_flags << 6);
  77437. if (s->strstart != 0) header |= PRESET_DICT;
  77438. header += 31 - (header % 31);
  77439. s->status = BUSY_STATE;
  77440. putShortMSB(s, header);
  77441. if (s->strstart != 0) {
  77442. putShortMSB(s, (uInt)(strm->adler >> 16));
  77443. putShortMSB(s, (uInt)(strm->adler & 0xffff));
  77444. }
  77445. strm->adler = adler32(0L, Z_NULL, 0);
  77446. }
  77447. }
  77448. #ifdef GZIP
  77449. if (s->status == EXTRA_STATE) {
  77450. if (s->gzhead->extra != NULL) {
  77451. uInt beg = s->pending; /* start of bytes to update crc */
  77452. while (s->gzindex < (s->gzhead->extra_len & 0xffff)) {
  77453. if (s->pending == s->pending_buf_size) {
  77454. if (s->gzhead->hcrc && s->pending > beg)
  77455. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77456. s->pending - beg);
  77457. flush_pending(strm);
  77458. beg = s->pending;
  77459. if (s->pending == s->pending_buf_size)
  77460. break;
  77461. }
  77462. put_byte(s, s->gzhead->extra[s->gzindex]);
  77463. s->gzindex++;
  77464. }
  77465. if (s->gzhead->hcrc && s->pending > beg)
  77466. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77467. s->pending - beg);
  77468. if (s->gzindex == s->gzhead->extra_len) {
  77469. s->gzindex = 0;
  77470. s->status = NAME_STATE;
  77471. }
  77472. }
  77473. else
  77474. s->status = NAME_STATE;
  77475. }
  77476. if (s->status == NAME_STATE) {
  77477. if (s->gzhead->name != NULL) {
  77478. uInt beg = s->pending; /* start of bytes to update crc */
  77479. int val;
  77480. do {
  77481. if (s->pending == s->pending_buf_size) {
  77482. if (s->gzhead->hcrc && s->pending > beg)
  77483. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77484. s->pending - beg);
  77485. flush_pending(strm);
  77486. beg = s->pending;
  77487. if (s->pending == s->pending_buf_size) {
  77488. val = 1;
  77489. break;
  77490. }
  77491. }
  77492. val = s->gzhead->name[s->gzindex++];
  77493. put_byte(s, val);
  77494. } while (val != 0);
  77495. if (s->gzhead->hcrc && s->pending > beg)
  77496. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77497. s->pending - beg);
  77498. if (val == 0) {
  77499. s->gzindex = 0;
  77500. s->status = COMMENT_STATE;
  77501. }
  77502. }
  77503. else
  77504. s->status = COMMENT_STATE;
  77505. }
  77506. if (s->status == COMMENT_STATE) {
  77507. if (s->gzhead->comment != NULL) {
  77508. uInt beg = s->pending; /* start of bytes to update crc */
  77509. int val;
  77510. do {
  77511. if (s->pending == s->pending_buf_size) {
  77512. if (s->gzhead->hcrc && s->pending > beg)
  77513. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77514. s->pending - beg);
  77515. flush_pending(strm);
  77516. beg = s->pending;
  77517. if (s->pending == s->pending_buf_size) {
  77518. val = 1;
  77519. break;
  77520. }
  77521. }
  77522. val = s->gzhead->comment[s->gzindex++];
  77523. put_byte(s, val);
  77524. } while (val != 0);
  77525. if (s->gzhead->hcrc && s->pending > beg)
  77526. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77527. s->pending - beg);
  77528. if (val == 0)
  77529. s->status = HCRC_STATE;
  77530. }
  77531. else
  77532. s->status = HCRC_STATE;
  77533. }
  77534. if (s->status == HCRC_STATE) {
  77535. if (s->gzhead->hcrc) {
  77536. if (s->pending + 2 > s->pending_buf_size)
  77537. flush_pending(strm);
  77538. if (s->pending + 2 <= s->pending_buf_size) {
  77539. put_byte(s, (Byte)(strm->adler & 0xff));
  77540. put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
  77541. strm->adler = crc32(0L, Z_NULL, 0);
  77542. s->status = BUSY_STATE;
  77543. }
  77544. }
  77545. else
  77546. s->status = BUSY_STATE;
  77547. }
  77548. #endif
  77549. if (s->pending != 0) {
  77550. flush_pending(strm);
  77551. if (strm->avail_out == 0) {
  77552. s->last_flush = -1;
  77553. return Z_OK;
  77554. }
  77555. } else if (strm->avail_in == 0 && flush <= old_flush &&
  77556. flush != Z_FINISH) {
  77557. ERR_RETURN(strm, Z_BUF_ERROR);
  77558. }
  77559. if (s->status == FINISH_STATE && strm->avail_in != 0) {
  77560. ERR_RETURN(strm, Z_BUF_ERROR);
  77561. }
  77562. if (strm->avail_in != 0 || s->lookahead != 0 ||
  77563. (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) {
  77564. block_state bstate;
  77565. bstate = (*(configuration_table[s->level].func))(s, flush);
  77566. if (bstate == finish_started || bstate == finish_done) {
  77567. s->status = FINISH_STATE;
  77568. }
  77569. if (bstate == need_more || bstate == finish_started) {
  77570. if (strm->avail_out == 0) {
  77571. s->last_flush = -1; /* avoid BUF_ERROR next call, see above */
  77572. }
  77573. return Z_OK;
  77574. }
  77575. if (bstate == block_done) {
  77576. if (flush == Z_PARTIAL_FLUSH) {
  77577. _tr_align(s);
  77578. } else { /* FULL_FLUSH or SYNC_FLUSH */
  77579. _tr_stored_block(s, (char*)0, 0L, 0);
  77580. if (flush == Z_FULL_FLUSH) {
  77581. CLEAR_HASH(s); /* forget history */
  77582. }
  77583. }
  77584. flush_pending(strm);
  77585. if (strm->avail_out == 0) {
  77586. s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */
  77587. return Z_OK;
  77588. }
  77589. }
  77590. }
  77591. Assert(strm->avail_out > 0, "bug2");
  77592. if (flush != Z_FINISH) return Z_OK;
  77593. if (s->wrap <= 0) return Z_STREAM_END;
  77594. #ifdef GZIP
  77595. if (s->wrap == 2) {
  77596. put_byte(s, (Byte)(strm->adler & 0xff));
  77597. put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
  77598. put_byte(s, (Byte)((strm->adler >> 16) & 0xff));
  77599. put_byte(s, (Byte)((strm->adler >> 24) & 0xff));
  77600. put_byte(s, (Byte)(strm->total_in & 0xff));
  77601. put_byte(s, (Byte)((strm->total_in >> 8) & 0xff));
  77602. put_byte(s, (Byte)((strm->total_in >> 16) & 0xff));
  77603. put_byte(s, (Byte)((strm->total_in >> 24) & 0xff));
  77604. }
  77605. else
  77606. #endif
  77607. {
  77608. putShortMSB(s, (uInt)(strm->adler >> 16));
  77609. putShortMSB(s, (uInt)(strm->adler & 0xffff));
  77610. }
  77611. flush_pending(strm);
  77612. if (s->wrap > 0) s->wrap = -s->wrap; /* write the trailer only once! */
  77613. return s->pending != 0 ? Z_OK : Z_STREAM_END;
  77614. }
  77615. int ZEXPORT deflateEnd (z_streamp strm)
  77616. {
  77617. int status;
  77618. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77619. status = strm->state->status;
  77620. if (status != INIT_STATE &&
  77621. status != EXTRA_STATE &&
  77622. status != NAME_STATE &&
  77623. status != COMMENT_STATE &&
  77624. status != HCRC_STATE &&
  77625. status != BUSY_STATE &&
  77626. status != FINISH_STATE) {
  77627. return Z_STREAM_ERROR;
  77628. }
  77629. TRY_FREE(strm, strm->state->pending_buf);
  77630. TRY_FREE(strm, strm->state->head);
  77631. TRY_FREE(strm, strm->state->prev);
  77632. TRY_FREE(strm, strm->state->window);
  77633. ZFREE(strm, strm->state);
  77634. strm->state = Z_NULL;
  77635. return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK;
  77636. }
  77637. int ZEXPORT deflateCopy (z_streamp dest, z_streamp source)
  77638. {
  77639. #ifdef MAXSEG_64K
  77640. return Z_STREAM_ERROR;
  77641. #else
  77642. deflate_state *ds;
  77643. deflate_state *ss;
  77644. ushf *overlay;
  77645. if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL) {
  77646. return Z_STREAM_ERROR;
  77647. }
  77648. ss = source->state;
  77649. zmemcpy(dest, source, sizeof(z_stream));
  77650. ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state));
  77651. if (ds == Z_NULL) return Z_MEM_ERROR;
  77652. dest->state = (struct internal_state FAR *) ds;
  77653. zmemcpy(ds, ss, sizeof(deflate_state));
  77654. ds->strm = dest;
  77655. ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
  77656. ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos));
  77657. ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos));
  77658. overlay = (ushf *) ZALLOC(dest, ds->lit_bufsize, sizeof(ush)+2);
  77659. ds->pending_buf = (uchf *) overlay;
  77660. if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL ||
  77661. ds->pending_buf == Z_NULL) {
  77662. deflateEnd (dest);
  77663. return Z_MEM_ERROR;
  77664. }
  77665. zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte));
  77666. zmemcpy(ds->prev, ss->prev, ds->w_size * sizeof(Pos));
  77667. zmemcpy(ds->head, ss->head, ds->hash_size * sizeof(Pos));
  77668. zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size);
  77669. ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
  77670. ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush);
  77671. ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize;
  77672. ds->l_desc.dyn_tree = ds->dyn_ltree;
  77673. ds->d_desc.dyn_tree = ds->dyn_dtree;
  77674. ds->bl_desc.dyn_tree = ds->bl_tree;
  77675. return Z_OK;
  77676. #endif /* MAXSEG_64K */
  77677. }
  77678. local int read_buf (z_streamp strm, Bytef *buf, unsigned size)
  77679. {
  77680. unsigned len = strm->avail_in;
  77681. if (len > size) len = size;
  77682. if (len == 0) return 0;
  77683. strm->avail_in -= len;
  77684. if (strm->state->wrap == 1) {
  77685. strm->adler = adler32(strm->adler, strm->next_in, len);
  77686. }
  77687. #ifdef GZIP
  77688. else if (strm->state->wrap == 2) {
  77689. strm->adler = crc32(strm->adler, strm->next_in, len);
  77690. }
  77691. #endif
  77692. zmemcpy(buf, strm->next_in, len);
  77693. strm->next_in += len;
  77694. strm->total_in += len;
  77695. return (int)len;
  77696. }
  77697. local void lm_init (deflate_state *s)
  77698. {
  77699. s->window_size = (ulg)2L*s->w_size;
  77700. CLEAR_HASH(s);
  77701. s->max_lazy_match = configuration_table[s->level].max_lazy;
  77702. s->good_match = configuration_table[s->level].good_length;
  77703. s->nice_match = configuration_table[s->level].nice_length;
  77704. s->max_chain_length = configuration_table[s->level].max_chain;
  77705. s->strstart = 0;
  77706. s->block_start = 0L;
  77707. s->lookahead = 0;
  77708. s->match_length = s->prev_length = MIN_MATCH-1;
  77709. s->match_available = 0;
  77710. s->ins_h = 0;
  77711. #ifndef FASTEST
  77712. #ifdef ASMV
  77713. match_init(); /* initialize the asm code */
  77714. #endif
  77715. #endif
  77716. }
  77717. #ifndef FASTEST
  77718. #ifndef ASMV
  77719. local uInt longest_match(deflate_state *s, IPos cur_match)
  77720. {
  77721. unsigned chain_length = s->max_chain_length;/* max hash chain length */
  77722. register Bytef *scan = s->window + s->strstart; /* current string */
  77723. register Bytef *match; /* matched string */
  77724. register int len; /* length of current match */
  77725. int best_len = s->prev_length; /* best match length so far */
  77726. int nice_match = s->nice_match; /* stop if match long enough */
  77727. IPos limit = s->strstart > (IPos)MAX_DIST(s) ?
  77728. s->strstart - (IPos)MAX_DIST(s) : NIL;
  77729. Posf *prev = s->prev;
  77730. uInt wmask = s->w_mask;
  77731. #ifdef UNALIGNED_OK
  77732. register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1;
  77733. register ush scan_start = *(ushf*)scan;
  77734. register ush scan_end = *(ushf*)(scan+best_len-1);
  77735. #else
  77736. register Bytef *strend = s->window + s->strstart + MAX_MATCH;
  77737. register Byte scan_end1 = scan[best_len-1];
  77738. register Byte scan_end = scan[best_len];
  77739. #endif
  77740. Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
  77741. if (s->prev_length >= s->good_match) {
  77742. chain_length >>= 2;
  77743. }
  77744. if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead;
  77745. Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
  77746. do {
  77747. Assert(cur_match < s->strstart, "no future");
  77748. match = s->window + cur_match;
  77749. #if (defined(UNALIGNED_OK) && MAX_MATCH == 258)
  77750. if (*(ushf*)(match+best_len-1) != scan_end ||
  77751. *(ushf*)match != scan_start) continue;
  77752. Assert(scan[2] == match[2], "scan[2]?");
  77753. scan++, match++;
  77754. do {
  77755. } while (*(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77756. *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77757. *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77758. *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77759. scan < strend);
  77760. Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  77761. if (*scan == *match) scan++;
  77762. len = (MAX_MATCH - 1) - (int)(strend-scan);
  77763. scan = strend - (MAX_MATCH-1);
  77764. #else /* UNALIGNED_OK */
  77765. if (match[best_len] != scan_end ||
  77766. match[best_len-1] != scan_end1 ||
  77767. *match != *scan ||
  77768. *++match != scan[1]) continue;
  77769. scan += 2, match++;
  77770. Assert(*scan == *match, "match[2]?");
  77771. do {
  77772. } while (*++scan == *++match && *++scan == *++match &&
  77773. *++scan == *++match && *++scan == *++match &&
  77774. *++scan == *++match && *++scan == *++match &&
  77775. *++scan == *++match && *++scan == *++match &&
  77776. scan < strend);
  77777. Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  77778. len = MAX_MATCH - (int)(strend - scan);
  77779. scan = strend - MAX_MATCH;
  77780. #endif /* UNALIGNED_OK */
  77781. if (len > best_len) {
  77782. s->match_start = cur_match;
  77783. best_len = len;
  77784. if (len >= nice_match) break;
  77785. #ifdef UNALIGNED_OK
  77786. scan_end = *(ushf*)(scan+best_len-1);
  77787. #else
  77788. scan_end1 = scan[best_len-1];
  77789. scan_end = scan[best_len];
  77790. #endif
  77791. }
  77792. } while ((cur_match = prev[cur_match & wmask]) > limit
  77793. && --chain_length != 0);
  77794. if ((uInt)best_len <= s->lookahead) return (uInt)best_len;
  77795. return s->lookahead;
  77796. }
  77797. #endif /* ASMV */
  77798. #endif /* FASTEST */
  77799. local uInt longest_match_fast (deflate_state *s, IPos cur_match)
  77800. {
  77801. register Bytef *scan = s->window + s->strstart; /* current string */
  77802. register Bytef *match; /* matched string */
  77803. register int len; /* length of current match */
  77804. register Bytef *strend = s->window + s->strstart + MAX_MATCH;
  77805. Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
  77806. Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
  77807. Assert(cur_match < s->strstart, "no future");
  77808. match = s->window + cur_match;
  77809. if (match[0] != scan[0] || match[1] != scan[1]) return MIN_MATCH-1;
  77810. scan += 2, match += 2;
  77811. Assert(*scan == *match, "match[2]?");
  77812. do {
  77813. } while (*++scan == *++match && *++scan == *++match &&
  77814. *++scan == *++match && *++scan == *++match &&
  77815. *++scan == *++match && *++scan == *++match &&
  77816. *++scan == *++match && *++scan == *++match &&
  77817. scan < strend);
  77818. Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  77819. len = MAX_MATCH - (int)(strend - scan);
  77820. if (len < MIN_MATCH) return MIN_MATCH - 1;
  77821. s->match_start = cur_match;
  77822. return (uInt)len <= s->lookahead ? (uInt)len : s->lookahead;
  77823. }
  77824. #ifdef DEBUG
  77825. local void check_match(deflate_state *s, IPos start, IPos match, int length)
  77826. {
  77827. if (zmemcmp(s->window + match,
  77828. s->window + start, length) != EQUAL) {
  77829. fprintf(stderr, " start %u, match %u, length %d\n",
  77830. start, match, length);
  77831. do {
  77832. fprintf(stderr, "%c%c", s->window[match++], s->window[start++]);
  77833. } while (--length != 0);
  77834. z_error("invalid match");
  77835. }
  77836. if (z_verbose > 1) {
  77837. fprintf(stderr,"\\[%d,%d]", start-match, length);
  77838. do { putc(s->window[start++], stderr); } while (--length != 0);
  77839. }
  77840. }
  77841. #else
  77842. # define check_match(s, start, match, length)
  77843. #endif /* DEBUG */
  77844. local void fill_window (deflate_state *s)
  77845. {
  77846. register unsigned n, m;
  77847. register Posf *p;
  77848. unsigned more; /* Amount of free space at the end of the window. */
  77849. uInt wsize = s->w_size;
  77850. do {
  77851. more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
  77852. if (sizeof(int) <= 2) {
  77853. if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
  77854. more = wsize;
  77855. } else if (more == (unsigned)(-1)) {
  77856. more--;
  77857. }
  77858. }
  77859. if (s->strstart >= wsize+MAX_DIST(s)) {
  77860. zmemcpy(s->window, s->window+wsize, (unsigned)wsize);
  77861. s->match_start -= wsize;
  77862. s->strstart -= wsize; /* we now have strstart >= MAX_DIST */
  77863. s->block_start -= (long) wsize;
  77864. n = s->hash_size;
  77865. p = &s->head[n];
  77866. do {
  77867. m = *--p;
  77868. *p = (Pos)(m >= wsize ? m-wsize : NIL);
  77869. } while (--n);
  77870. n = wsize;
  77871. #ifndef FASTEST
  77872. p = &s->prev[n];
  77873. do {
  77874. m = *--p;
  77875. *p = (Pos)(m >= wsize ? m-wsize : NIL);
  77876. } while (--n);
  77877. #endif
  77878. more += wsize;
  77879. }
  77880. if (s->strm->avail_in == 0) return;
  77881. Assert(more >= 2, "more < 2");
  77882. n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more);
  77883. s->lookahead += n;
  77884. if (s->lookahead >= MIN_MATCH) {
  77885. s->ins_h = s->window[s->strstart];
  77886. UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
  77887. #if MIN_MATCH != 3
  77888. Call UPDATE_HASH() MIN_MATCH-3 more times
  77889. #endif
  77890. }
  77891. } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0);
  77892. }
  77893. #define FLUSH_BLOCK_ONLY(s, eof) { \
  77894. _tr_flush_block(s, (s->block_start >= 0L ? \
  77895. (charf *)&s->window[(unsigned)s->block_start] : \
  77896. (charf *)Z_NULL), \
  77897. (ulg)((long)s->strstart - s->block_start), \
  77898. (eof)); \
  77899. s->block_start = s->strstart; \
  77900. flush_pending(s->strm); \
  77901. Tracev((stderr,"[FLUSH]")); \
  77902. }
  77903. #define FLUSH_BLOCK(s, eof) { \
  77904. FLUSH_BLOCK_ONLY(s, eof); \
  77905. if (s->strm->avail_out == 0) return (eof) ? finish_started : need_more; \
  77906. }
  77907. local block_state deflate_stored(deflate_state *s, int flush)
  77908. {
  77909. ulg max_block_size = 0xffff;
  77910. ulg max_start;
  77911. if (max_block_size > s->pending_buf_size - 5) {
  77912. max_block_size = s->pending_buf_size - 5;
  77913. }
  77914. for (;;) {
  77915. if (s->lookahead <= 1) {
  77916. Assert(s->strstart < s->w_size+MAX_DIST(s) ||
  77917. s->block_start >= (long)s->w_size, "slide too late");
  77918. fill_window(s);
  77919. if (s->lookahead == 0 && flush == Z_NO_FLUSH) return need_more;
  77920. if (s->lookahead == 0) break; /* flush the current block */
  77921. }
  77922. Assert(s->block_start >= 0L, "block gone");
  77923. s->strstart += s->lookahead;
  77924. s->lookahead = 0;
  77925. max_start = s->block_start + max_block_size;
  77926. if (s->strstart == 0 || (ulg)s->strstart >= max_start) {
  77927. s->lookahead = (uInt)(s->strstart - max_start);
  77928. s->strstart = (uInt)max_start;
  77929. FLUSH_BLOCK(s, 0);
  77930. }
  77931. if (s->strstart - (uInt)s->block_start >= MAX_DIST(s)) {
  77932. FLUSH_BLOCK(s, 0);
  77933. }
  77934. }
  77935. FLUSH_BLOCK(s, flush == Z_FINISH);
  77936. return flush == Z_FINISH ? finish_done : block_done;
  77937. }
  77938. local block_state deflate_fast(deflate_state *s, int flush)
  77939. {
  77940. IPos hash_head = NIL; /* head of the hash chain */
  77941. int bflush; /* set if current block must be flushed */
  77942. for (;;) {
  77943. if (s->lookahead < MIN_LOOKAHEAD) {
  77944. fill_window(s);
  77945. if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
  77946. return need_more;
  77947. }
  77948. if (s->lookahead == 0) break; /* flush the current block */
  77949. }
  77950. if (s->lookahead >= MIN_MATCH) {
  77951. INSERT_STRING(s, s->strstart, hash_head);
  77952. }
  77953. if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s)) {
  77954. #ifdef FASTEST
  77955. if ((s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) ||
  77956. (s->strategy == Z_RLE && s->strstart - hash_head == 1)) {
  77957. s->match_length = longest_match_fast (s, hash_head);
  77958. }
  77959. #else
  77960. if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) {
  77961. s->match_length = longest_match (s, hash_head);
  77962. } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {
  77963. s->match_length = longest_match_fast (s, hash_head);
  77964. }
  77965. #endif
  77966. }
  77967. if (s->match_length >= MIN_MATCH) {
  77968. check_match(s, s->strstart, s->match_start, s->match_length);
  77969. _tr_tally_dist(s, s->strstart - s->match_start,
  77970. s->match_length - MIN_MATCH, bflush);
  77971. s->lookahead -= s->match_length;
  77972. #ifndef FASTEST
  77973. if (s->match_length <= s->max_insert_length &&
  77974. s->lookahead >= MIN_MATCH) {
  77975. s->match_length--; /* string at strstart already in table */
  77976. do {
  77977. s->strstart++;
  77978. INSERT_STRING(s, s->strstart, hash_head);
  77979. } while (--s->match_length != 0);
  77980. s->strstart++;
  77981. } else
  77982. #endif
  77983. {
  77984. s->strstart += s->match_length;
  77985. s->match_length = 0;
  77986. s->ins_h = s->window[s->strstart];
  77987. UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
  77988. #if MIN_MATCH != 3
  77989. Call UPDATE_HASH() MIN_MATCH-3 more times
  77990. #endif
  77991. }
  77992. } else {
  77993. Tracevv((stderr,"%c", s->window[s->strstart]));
  77994. _tr_tally_lit (s, s->window[s->strstart], bflush);
  77995. s->lookahead--;
  77996. s->strstart++;
  77997. }
  77998. if (bflush) FLUSH_BLOCK(s, 0);
  77999. }
  78000. FLUSH_BLOCK(s, flush == Z_FINISH);
  78001. return flush == Z_FINISH ? finish_done : block_done;
  78002. }
  78003. #ifndef FASTEST
  78004. local block_state deflate_slow(deflate_state *s, int flush)
  78005. {
  78006. IPos hash_head = NIL; /* head of hash chain */
  78007. int bflush; /* set if current block must be flushed */
  78008. for (;;) {
  78009. if (s->lookahead < MIN_LOOKAHEAD) {
  78010. fill_window(s);
  78011. if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
  78012. return need_more;
  78013. }
  78014. if (s->lookahead == 0) break; /* flush the current block */
  78015. }
  78016. if (s->lookahead >= MIN_MATCH) {
  78017. INSERT_STRING(s, s->strstart, hash_head);
  78018. }
  78019. s->prev_length = s->match_length, s->prev_match = s->match_start;
  78020. s->match_length = MIN_MATCH-1;
  78021. if (hash_head != NIL && s->prev_length < s->max_lazy_match &&
  78022. s->strstart - hash_head <= MAX_DIST(s)) {
  78023. if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) {
  78024. s->match_length = longest_match (s, hash_head);
  78025. } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {
  78026. s->match_length = longest_match_fast (s, hash_head);
  78027. }
  78028. if (s->match_length <= 5 && (s->strategy == Z_FILTERED
  78029. #if TOO_FAR <= 32767
  78030. || (s->match_length == MIN_MATCH &&
  78031. s->strstart - s->match_start > TOO_FAR)
  78032. #endif
  78033. )) {
  78034. s->match_length = MIN_MATCH-1;
  78035. }
  78036. }
  78037. if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) {
  78038. uInt max_insert = s->strstart + s->lookahead - MIN_MATCH;
  78039. check_match(s, s->strstart-1, s->prev_match, s->prev_length);
  78040. _tr_tally_dist(s, s->strstart -1 - s->prev_match,
  78041. s->prev_length - MIN_MATCH, bflush);
  78042. s->lookahead -= s->prev_length-1;
  78043. s->prev_length -= 2;
  78044. do {
  78045. if (++s->strstart <= max_insert) {
  78046. INSERT_STRING(s, s->strstart, hash_head);
  78047. }
  78048. } while (--s->prev_length != 0);
  78049. s->match_available = 0;
  78050. s->match_length = MIN_MATCH-1;
  78051. s->strstart++;
  78052. if (bflush) FLUSH_BLOCK(s, 0);
  78053. } else if (s->match_available) {
  78054. Tracevv((stderr,"%c", s->window[s->strstart-1]));
  78055. _tr_tally_lit(s, s->window[s->strstart-1], bflush);
  78056. if (bflush) {
  78057. FLUSH_BLOCK_ONLY(s, 0);
  78058. }
  78059. s->strstart++;
  78060. s->lookahead--;
  78061. if (s->strm->avail_out == 0) return need_more;
  78062. } else {
  78063. s->match_available = 1;
  78064. s->strstart++;
  78065. s->lookahead--;
  78066. }
  78067. }
  78068. Assert (flush != Z_NO_FLUSH, "no flush?");
  78069. if (s->match_available) {
  78070. Tracevv((stderr,"%c", s->window[s->strstart-1]));
  78071. _tr_tally_lit(s, s->window[s->strstart-1], bflush);
  78072. s->match_available = 0;
  78073. }
  78074. FLUSH_BLOCK(s, flush == Z_FINISH);
  78075. return flush == Z_FINISH ? finish_done : block_done;
  78076. }
  78077. #endif /* FASTEST */
  78078. #if 0
  78079. local block_state deflate_rle(s, flush)
  78080. deflate_state *s;
  78081. int flush;
  78082. {
  78083. int bflush; /* set if current block must be flushed */
  78084. uInt run; /* length of run */
  78085. uInt max; /* maximum length of run */
  78086. uInt prev; /* byte at distance one to match */
  78087. Bytef *scan; /* scan for end of run */
  78088. for (;;) {
  78089. if (s->lookahead < MAX_MATCH) {
  78090. fill_window(s);
  78091. if (s->lookahead < MAX_MATCH && flush == Z_NO_FLUSH) {
  78092. return need_more;
  78093. }
  78094. if (s->lookahead == 0) break; /* flush the current block */
  78095. }
  78096. run = 0;
  78097. if (s->strstart > 0) { /* if there is a previous byte, that is */
  78098. max = s->lookahead < MAX_MATCH ? s->lookahead : MAX_MATCH;
  78099. scan = s->window + s->strstart - 1;
  78100. prev = *scan++;
  78101. do {
  78102. if (*scan++ != prev)
  78103. break;
  78104. } while (++run < max);
  78105. }
  78106. if (run >= MIN_MATCH) {
  78107. check_match(s, s->strstart, s->strstart - 1, run);
  78108. _tr_tally_dist(s, 1, run - MIN_MATCH, bflush);
  78109. s->lookahead -= run;
  78110. s->strstart += run;
  78111. } else {
  78112. Tracevv((stderr,"%c", s->window[s->strstart]));
  78113. _tr_tally_lit (s, s->window[s->strstart], bflush);
  78114. s->lookahead--;
  78115. s->strstart++;
  78116. }
  78117. if (bflush) FLUSH_BLOCK(s, 0);
  78118. }
  78119. FLUSH_BLOCK(s, flush == Z_FINISH);
  78120. return flush == Z_FINISH ? finish_done : block_done;
  78121. }
  78122. #endif
  78123. /*** End of inlined file: deflate.c ***/
  78124. /*** Start of inlined file: inffast.c ***/
  78125. /*** Start of inlined file: inftrees.h ***/
  78126. #ifndef _INFTREES_H_
  78127. #define _INFTREES_H_
  78128. typedef struct {
  78129. unsigned char op; /* operation, extra bits, table bits */
  78130. unsigned char bits; /* bits in this part of the code */
  78131. unsigned short val; /* offset in table or code value */
  78132. } code;
  78133. #define ENOUGH 2048
  78134. #define MAXD 592
  78135. typedef enum {
  78136. CODES,
  78137. LENS,
  78138. DISTS
  78139. } codetype;
  78140. extern int inflate_table OF((codetype type, unsigned short FAR *lens,
  78141. unsigned codes, code FAR * FAR *table,
  78142. unsigned FAR *bits, unsigned short FAR *work));
  78143. #endif
  78144. /*** End of inlined file: inftrees.h ***/
  78145. /*** Start of inlined file: inflate.h ***/
  78146. #ifndef _INFLATE_H_
  78147. #define _INFLATE_H_
  78148. #ifndef NO_GZIP
  78149. # define GUNZIP
  78150. #endif
  78151. typedef enum {
  78152. HEAD, /* i: waiting for magic header */
  78153. FLAGS, /* i: waiting for method and flags (gzip) */
  78154. TIME, /* i: waiting for modification time (gzip) */
  78155. OS, /* i: waiting for extra flags and operating system (gzip) */
  78156. EXLEN, /* i: waiting for extra length (gzip) */
  78157. EXTRA, /* i: waiting for extra bytes (gzip) */
  78158. NAME, /* i: waiting for end of file name (gzip) */
  78159. COMMENT, /* i: waiting for end of comment (gzip) */
  78160. HCRC, /* i: waiting for header crc (gzip) */
  78161. DICTID, /* i: waiting for dictionary check value */
  78162. DICT, /* waiting for inflateSetDictionary() call */
  78163. TYPE, /* i: waiting for type bits, including last-flag bit */
  78164. TYPEDO, /* i: same, but skip check to exit inflate on new block */
  78165. STORED, /* i: waiting for stored size (length and complement) */
  78166. COPY, /* i/o: waiting for input or output to copy stored block */
  78167. TABLE, /* i: waiting for dynamic block table lengths */
  78168. LENLENS, /* i: waiting for code length code lengths */
  78169. CODELENS, /* i: waiting for length/lit and distance code lengths */
  78170. LEN, /* i: waiting for length/lit code */
  78171. LENEXT, /* i: waiting for length extra bits */
  78172. DIST, /* i: waiting for distance code */
  78173. DISTEXT, /* i: waiting for distance extra bits */
  78174. MATCH, /* o: waiting for output space to copy string */
  78175. LIT, /* o: waiting for output space to write literal */
  78176. CHECK, /* i: waiting for 32-bit check value */
  78177. LENGTH, /* i: waiting for 32-bit length (gzip) */
  78178. DONE, /* finished check, done -- remain here until reset */
  78179. BAD, /* got a data error -- remain here until reset */
  78180. MEM, /* got an inflate() memory error -- remain here until reset */
  78181. SYNC /* looking for synchronization bytes to restart inflate() */
  78182. } inflate_mode;
  78183. struct inflate_state {
  78184. inflate_mode mode; /* current inflate mode */
  78185. int last; /* true if processing last block */
  78186. int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
  78187. int havedict; /* true if dictionary provided */
  78188. int flags; /* gzip header method and flags (0 if zlib) */
  78189. unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */
  78190. unsigned long check; /* protected copy of check value */
  78191. unsigned long total; /* protected copy of output count */
  78192. gz_headerp head; /* where to save gzip header information */
  78193. unsigned wbits; /* log base 2 of requested window size */
  78194. unsigned wsize; /* window size or zero if not using window */
  78195. unsigned whave; /* valid bytes in the window */
  78196. unsigned write; /* window write index */
  78197. unsigned char FAR *window; /* allocated sliding window, if needed */
  78198. unsigned long hold; /* input bit accumulator */
  78199. unsigned bits; /* number of bits in "in" */
  78200. unsigned length; /* literal or length of data to copy */
  78201. unsigned offset; /* distance back to copy string from */
  78202. unsigned extra; /* extra bits needed */
  78203. code const FAR *lencode; /* starting table for length/literal codes */
  78204. code const FAR *distcode; /* starting table for distance codes */
  78205. unsigned lenbits; /* index bits for lencode */
  78206. unsigned distbits; /* index bits for distcode */
  78207. unsigned ncode; /* number of code length code lengths */
  78208. unsigned nlen; /* number of length code lengths */
  78209. unsigned ndist; /* number of distance code lengths */
  78210. unsigned have; /* number of code lengths in lens[] */
  78211. code FAR *next; /* next available space in codes[] */
  78212. unsigned short lens[320]; /* temporary storage for code lengths */
  78213. unsigned short work[288]; /* work area for code table building */
  78214. code codes[ENOUGH]; /* space for code tables */
  78215. };
  78216. #endif
  78217. /*** End of inlined file: inflate.h ***/
  78218. /*** Start of inlined file: inffast.h ***/
  78219. void inflate_fast OF((z_streamp strm, unsigned start));
  78220. /*** End of inlined file: inffast.h ***/
  78221. #ifndef ASMINF
  78222. #ifdef POSTINC
  78223. # define OFF 0
  78224. # define PUP(a) *(a)++
  78225. #else
  78226. # define OFF 1
  78227. # define PUP(a) *++(a)
  78228. #endif
  78229. void inflate_fast (z_streamp strm, unsigned start)
  78230. {
  78231. struct inflate_state FAR *state;
  78232. unsigned char FAR *in; /* local strm->next_in */
  78233. unsigned char FAR *last; /* while in < last, enough input available */
  78234. unsigned char FAR *out; /* local strm->next_out */
  78235. unsigned char FAR *beg; /* inflate()'s initial strm->next_out */
  78236. unsigned char FAR *end; /* while out < end, enough space available */
  78237. #ifdef INFLATE_STRICT
  78238. unsigned dmax; /* maximum distance from zlib header */
  78239. #endif
  78240. unsigned wsize; /* window size or zero if not using window */
  78241. unsigned whave; /* valid bytes in the window */
  78242. unsigned write; /* window write index */
  78243. unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */
  78244. unsigned long hold; /* local strm->hold */
  78245. unsigned bits; /* local strm->bits */
  78246. code const FAR *lcode; /* local strm->lencode */
  78247. code const FAR *dcode; /* local strm->distcode */
  78248. unsigned lmask; /* mask for first level of length codes */
  78249. unsigned dmask; /* mask for first level of distance codes */
  78250. code thisx; /* retrieved table entry */
  78251. unsigned op; /* code bits, operation, extra bits, or */
  78252. unsigned len; /* match length, unused bytes */
  78253. unsigned dist; /* match distance */
  78254. unsigned char FAR *from; /* where to copy match from */
  78255. state = (struct inflate_state FAR *)strm->state;
  78256. in = strm->next_in - OFF;
  78257. last = in + (strm->avail_in - 5);
  78258. out = strm->next_out - OFF;
  78259. beg = out - (start - strm->avail_out);
  78260. end = out + (strm->avail_out - 257);
  78261. #ifdef INFLATE_STRICT
  78262. dmax = state->dmax;
  78263. #endif
  78264. wsize = state->wsize;
  78265. whave = state->whave;
  78266. write = state->write;
  78267. window = state->window;
  78268. hold = state->hold;
  78269. bits = state->bits;
  78270. lcode = state->lencode;
  78271. dcode = state->distcode;
  78272. lmask = (1U << state->lenbits) - 1;
  78273. dmask = (1U << state->distbits) - 1;
  78274. do {
  78275. if (bits < 15) {
  78276. hold += (unsigned long)(PUP(in)) << bits;
  78277. bits += 8;
  78278. hold += (unsigned long)(PUP(in)) << bits;
  78279. bits += 8;
  78280. }
  78281. thisx = lcode[hold & lmask];
  78282. dolen:
  78283. op = (unsigned)(thisx.bits);
  78284. hold >>= op;
  78285. bits -= op;
  78286. op = (unsigned)(thisx.op);
  78287. if (op == 0) { /* literal */
  78288. Tracevv((stderr, thisx.val >= 0x20 && thisx.val < 0x7f ?
  78289. "inflate: literal '%c'\n" :
  78290. "inflate: literal 0x%02x\n", thisx.val));
  78291. PUP(out) = (unsigned char)(thisx.val);
  78292. }
  78293. else if (op & 16) { /* length base */
  78294. len = (unsigned)(thisx.val);
  78295. op &= 15; /* number of extra bits */
  78296. if (op) {
  78297. if (bits < op) {
  78298. hold += (unsigned long)(PUP(in)) << bits;
  78299. bits += 8;
  78300. }
  78301. len += (unsigned)hold & ((1U << op) - 1);
  78302. hold >>= op;
  78303. bits -= op;
  78304. }
  78305. Tracevv((stderr, "inflate: length %u\n", len));
  78306. if (bits < 15) {
  78307. hold += (unsigned long)(PUP(in)) << bits;
  78308. bits += 8;
  78309. hold += (unsigned long)(PUP(in)) << bits;
  78310. bits += 8;
  78311. }
  78312. thisx = dcode[hold & dmask];
  78313. dodist:
  78314. op = (unsigned)(thisx.bits);
  78315. hold >>= op;
  78316. bits -= op;
  78317. op = (unsigned)(thisx.op);
  78318. if (op & 16) { /* distance base */
  78319. dist = (unsigned)(thisx.val);
  78320. op &= 15; /* number of extra bits */
  78321. if (bits < op) {
  78322. hold += (unsigned long)(PUP(in)) << bits;
  78323. bits += 8;
  78324. if (bits < op) {
  78325. hold += (unsigned long)(PUP(in)) << bits;
  78326. bits += 8;
  78327. }
  78328. }
  78329. dist += (unsigned)hold & ((1U << op) - 1);
  78330. #ifdef INFLATE_STRICT
  78331. if (dist > dmax) {
  78332. strm->msg = (char *)"invalid distance too far back";
  78333. state->mode = BAD;
  78334. break;
  78335. }
  78336. #endif
  78337. hold >>= op;
  78338. bits -= op;
  78339. Tracevv((stderr, "inflate: distance %u\n", dist));
  78340. op = (unsigned)(out - beg); /* max distance in output */
  78341. if (dist > op) { /* see if copy from window */
  78342. op = dist - op; /* distance back in window */
  78343. if (op > whave) {
  78344. strm->msg = (char *)"invalid distance too far back";
  78345. state->mode = BAD;
  78346. break;
  78347. }
  78348. from = window - OFF;
  78349. if (write == 0) { /* very common case */
  78350. from += wsize - op;
  78351. if (op < len) { /* some from window */
  78352. len -= op;
  78353. do {
  78354. PUP(out) = PUP(from);
  78355. } while (--op);
  78356. from = out - dist; /* rest from output */
  78357. }
  78358. }
  78359. else if (write < op) { /* wrap around window */
  78360. from += wsize + write - op;
  78361. op -= write;
  78362. if (op < len) { /* some from end of window */
  78363. len -= op;
  78364. do {
  78365. PUP(out) = PUP(from);
  78366. } while (--op);
  78367. from = window - OFF;
  78368. if (write < len) { /* some from start of window */
  78369. op = write;
  78370. len -= op;
  78371. do {
  78372. PUP(out) = PUP(from);
  78373. } while (--op);
  78374. from = out - dist; /* rest from output */
  78375. }
  78376. }
  78377. }
  78378. else { /* contiguous in window */
  78379. from += write - op;
  78380. if (op < len) { /* some from window */
  78381. len -= op;
  78382. do {
  78383. PUP(out) = PUP(from);
  78384. } while (--op);
  78385. from = out - dist; /* rest from output */
  78386. }
  78387. }
  78388. while (len > 2) {
  78389. PUP(out) = PUP(from);
  78390. PUP(out) = PUP(from);
  78391. PUP(out) = PUP(from);
  78392. len -= 3;
  78393. }
  78394. if (len) {
  78395. PUP(out) = PUP(from);
  78396. if (len > 1)
  78397. PUP(out) = PUP(from);
  78398. }
  78399. }
  78400. else {
  78401. from = out - dist; /* copy direct from output */
  78402. do { /* minimum length is three */
  78403. PUP(out) = PUP(from);
  78404. PUP(out) = PUP(from);
  78405. PUP(out) = PUP(from);
  78406. len -= 3;
  78407. } while (len > 2);
  78408. if (len) {
  78409. PUP(out) = PUP(from);
  78410. if (len > 1)
  78411. PUP(out) = PUP(from);
  78412. }
  78413. }
  78414. }
  78415. else if ((op & 64) == 0) { /* 2nd level distance code */
  78416. thisx = dcode[thisx.val + (hold & ((1U << op) - 1))];
  78417. goto dodist;
  78418. }
  78419. else {
  78420. strm->msg = (char *)"invalid distance code";
  78421. state->mode = BAD;
  78422. break;
  78423. }
  78424. }
  78425. else if ((op & 64) == 0) { /* 2nd level length code */
  78426. thisx = lcode[thisx.val + (hold & ((1U << op) - 1))];
  78427. goto dolen;
  78428. }
  78429. else if (op & 32) { /* end-of-block */
  78430. Tracevv((stderr, "inflate: end of block\n"));
  78431. state->mode = TYPE;
  78432. break;
  78433. }
  78434. else {
  78435. strm->msg = (char *)"invalid literal/length code";
  78436. state->mode = BAD;
  78437. break;
  78438. }
  78439. } while (in < last && out < end);
  78440. len = bits >> 3;
  78441. in -= len;
  78442. bits -= len << 3;
  78443. hold &= (1U << bits) - 1;
  78444. strm->next_in = in + OFF;
  78445. strm->next_out = out + OFF;
  78446. strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last));
  78447. strm->avail_out = (unsigned)(out < end ?
  78448. 257 + (end - out) : 257 - (out - end));
  78449. state->hold = hold;
  78450. state->bits = bits;
  78451. return;
  78452. }
  78453. #endif /* !ASMINF */
  78454. /*** End of inlined file: inffast.c ***/
  78455. #undef PULLBYTE
  78456. #undef LOAD
  78457. #undef RESTORE
  78458. #undef INITBITS
  78459. #undef NEEDBITS
  78460. #undef DROPBITS
  78461. #undef BYTEBITS
  78462. /*** Start of inlined file: inflate.c ***/
  78463. /*** Start of inlined file: inffast.h ***/
  78464. void inflate_fast OF((z_streamp strm, unsigned start));
  78465. /*** End of inlined file: inffast.h ***/
  78466. #ifdef MAKEFIXED
  78467. # ifndef BUILDFIXED
  78468. # define BUILDFIXED
  78469. # endif
  78470. #endif
  78471. local void fixedtables OF((struct inflate_state FAR *state));
  78472. local int updatewindow OF((z_streamp strm, unsigned out));
  78473. #ifdef BUILDFIXED
  78474. void makefixed OF((void));
  78475. #endif
  78476. local unsigned syncsearch OF((unsigned FAR *have, unsigned char FAR *buf,
  78477. unsigned len));
  78478. int ZEXPORT inflateReset (z_streamp strm)
  78479. {
  78480. struct inflate_state FAR *state;
  78481. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  78482. state = (struct inflate_state FAR *)strm->state;
  78483. strm->total_in = strm->total_out = state->total = 0;
  78484. strm->msg = Z_NULL;
  78485. strm->adler = 1; /* to support ill-conceived Java test suite */
  78486. state->mode = HEAD;
  78487. state->last = 0;
  78488. state->havedict = 0;
  78489. state->dmax = 32768U;
  78490. state->head = Z_NULL;
  78491. state->wsize = 0;
  78492. state->whave = 0;
  78493. state->write = 0;
  78494. state->hold = 0;
  78495. state->bits = 0;
  78496. state->lencode = state->distcode = state->next = state->codes;
  78497. Tracev((stderr, "inflate: reset\n"));
  78498. return Z_OK;
  78499. }
  78500. int ZEXPORT inflatePrime (z_streamp strm, int bits, int value)
  78501. {
  78502. struct inflate_state FAR *state;
  78503. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  78504. state = (struct inflate_state FAR *)strm->state;
  78505. if (bits > 16 || state->bits + bits > 32) return Z_STREAM_ERROR;
  78506. value &= (1L << bits) - 1;
  78507. state->hold += value << state->bits;
  78508. state->bits += bits;
  78509. return Z_OK;
  78510. }
  78511. int ZEXPORT inflateInit2_(z_streamp strm, int windowBits, const char *version, int stream_size)
  78512. {
  78513. struct inflate_state FAR *state;
  78514. if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
  78515. stream_size != (int)(sizeof(z_stream)))
  78516. return Z_VERSION_ERROR;
  78517. if (strm == Z_NULL) return Z_STREAM_ERROR;
  78518. strm->msg = Z_NULL; /* in case we return an error */
  78519. if (strm->zalloc == (alloc_func)0) {
  78520. strm->zalloc = zcalloc;
  78521. strm->opaque = (voidpf)0;
  78522. }
  78523. if (strm->zfree == (free_func)0) strm->zfree = zcfree;
  78524. state = (struct inflate_state FAR *)
  78525. ZALLOC(strm, 1, sizeof(struct inflate_state));
  78526. if (state == Z_NULL) return Z_MEM_ERROR;
  78527. Tracev((stderr, "inflate: allocated\n"));
  78528. strm->state = (struct internal_state FAR *)state;
  78529. if (windowBits < 0) {
  78530. state->wrap = 0;
  78531. windowBits = -windowBits;
  78532. }
  78533. else {
  78534. state->wrap = (windowBits >> 4) + 1;
  78535. #ifdef GUNZIP
  78536. if (windowBits < 48) windowBits &= 15;
  78537. #endif
  78538. }
  78539. if (windowBits < 8 || windowBits > 15) {
  78540. ZFREE(strm, state);
  78541. strm->state = Z_NULL;
  78542. return Z_STREAM_ERROR;
  78543. }
  78544. state->wbits = (unsigned)windowBits;
  78545. state->window = Z_NULL;
  78546. return inflateReset(strm);
  78547. }
  78548. int ZEXPORT inflateInit_ (z_streamp strm, const char *version, int stream_size)
  78549. {
  78550. return inflateInit2_(strm, DEF_WBITS, version, stream_size);
  78551. }
  78552. local void fixedtables (struct inflate_state FAR *state)
  78553. {
  78554. #ifdef BUILDFIXED
  78555. static int virgin = 1;
  78556. static code *lenfix, *distfix;
  78557. static code fixed[544];
  78558. if (virgin) {
  78559. unsigned sym, bits;
  78560. static code *next;
  78561. sym = 0;
  78562. while (sym < 144) state->lens[sym++] = 8;
  78563. while (sym < 256) state->lens[sym++] = 9;
  78564. while (sym < 280) state->lens[sym++] = 7;
  78565. while (sym < 288) state->lens[sym++] = 8;
  78566. next = fixed;
  78567. lenfix = next;
  78568. bits = 9;
  78569. inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work);
  78570. sym = 0;
  78571. while (sym < 32) state->lens[sym++] = 5;
  78572. distfix = next;
  78573. bits = 5;
  78574. inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work);
  78575. virgin = 0;
  78576. }
  78577. #else /* !BUILDFIXED */
  78578. /*** Start of inlined file: inffixed.h ***/
  78579. static const code lenfix[512] = {
  78580. {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48},
  78581. {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128},
  78582. {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59},
  78583. {0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176},
  78584. {0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20},
  78585. {21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100},
  78586. {0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8},
  78587. {0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216},
  78588. {18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76},
  78589. {0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114},
  78590. {0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2},
  78591. {0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148},
  78592. {20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42},
  78593. {0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86},
  78594. {0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15},
  78595. {0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236},
  78596. {16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62},
  78597. {0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142},
  78598. {0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31},
  78599. {0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162},
  78600. {0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25},
  78601. {0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105},
  78602. {0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4},
  78603. {0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202},
  78604. {17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69},
  78605. {0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125},
  78606. {0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13},
  78607. {0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195},
  78608. {19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35},
  78609. {0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91},
  78610. {0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19},
  78611. {0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246},
  78612. {16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55},
  78613. {0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135},
  78614. {0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99},
  78615. {0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190},
  78616. {0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16},
  78617. {20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96},
  78618. {0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6},
  78619. {0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209},
  78620. {17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72},
  78621. {0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116},
  78622. {0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4},
  78623. {0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153},
  78624. {20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44},
  78625. {0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82},
  78626. {0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11},
  78627. {0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229},
  78628. {16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58},
  78629. {0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138},
  78630. {0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51},
  78631. {0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173},
  78632. {0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30},
  78633. {0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110},
  78634. {0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0},
  78635. {0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195},
  78636. {16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65},
  78637. {0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121},
  78638. {0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9},
  78639. {0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258},
  78640. {19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37},
  78641. {0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93},
  78642. {0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23},
  78643. {0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251},
  78644. {16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51},
  78645. {0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131},
  78646. {0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67},
  78647. {0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183},
  78648. {0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23},
  78649. {64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103},
  78650. {0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9},
  78651. {0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223},
  78652. {18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79},
  78653. {0,9,255}
  78654. };
  78655. static const code distfix[32] = {
  78656. {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025},
  78657. {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193},
  78658. {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385},
  78659. {19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577},
  78660. {16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073},
  78661. {22,5,193},{64,5,0}
  78662. };
  78663. /*** End of inlined file: inffixed.h ***/
  78664. #endif /* BUILDFIXED */
  78665. state->lencode = lenfix;
  78666. state->lenbits = 9;
  78667. state->distcode = distfix;
  78668. state->distbits = 5;
  78669. }
  78670. #ifdef MAKEFIXED
  78671. #include <stdio.h>
  78672. void makefixed()
  78673. {
  78674. unsigned low, size;
  78675. struct inflate_state state;
  78676. fixedtables(&state);
  78677. puts(" /* inffixed.h -- table for decoding fixed codes");
  78678. puts(" * Generated automatically by makefixed().");
  78679. puts(" */");
  78680. puts("");
  78681. puts(" /* WARNING: this file should *not* be used by applications.");
  78682. puts(" It is part of the implementation of this library and is");
  78683. puts(" subject to change. Applications should only use zlib.h.");
  78684. puts(" */");
  78685. puts("");
  78686. size = 1U << 9;
  78687. printf(" static const code lenfix[%u] = {", size);
  78688. low = 0;
  78689. for (;;) {
  78690. if ((low % 7) == 0) printf("\n ");
  78691. printf("{%u,%u,%d}", state.lencode[low].op, state.lencode[low].bits,
  78692. state.lencode[low].val);
  78693. if (++low == size) break;
  78694. putchar(',');
  78695. }
  78696. puts("\n };");
  78697. size = 1U << 5;
  78698. printf("\n static const code distfix[%u] = {", size);
  78699. low = 0;
  78700. for (;;) {
  78701. if ((low % 6) == 0) printf("\n ");
  78702. printf("{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits,
  78703. state.distcode[low].val);
  78704. if (++low == size) break;
  78705. putchar(',');
  78706. }
  78707. puts("\n };");
  78708. }
  78709. #endif /* MAKEFIXED */
  78710. local int updatewindow (z_streamp strm, unsigned out)
  78711. {
  78712. struct inflate_state FAR *state;
  78713. unsigned copy, dist;
  78714. state = (struct inflate_state FAR *)strm->state;
  78715. if (state->window == Z_NULL) {
  78716. state->window = (unsigned char FAR *)
  78717. ZALLOC(strm, 1U << state->wbits,
  78718. sizeof(unsigned char));
  78719. if (state->window == Z_NULL) return 1;
  78720. }
  78721. if (state->wsize == 0) {
  78722. state->wsize = 1U << state->wbits;
  78723. state->write = 0;
  78724. state->whave = 0;
  78725. }
  78726. copy = out - strm->avail_out;
  78727. if (copy >= state->wsize) {
  78728. zmemcpy(state->window, strm->next_out - state->wsize, state->wsize);
  78729. state->write = 0;
  78730. state->whave = state->wsize;
  78731. }
  78732. else {
  78733. dist = state->wsize - state->write;
  78734. if (dist > copy) dist = copy;
  78735. zmemcpy(state->window + state->write, strm->next_out - copy, dist);
  78736. copy -= dist;
  78737. if (copy) {
  78738. zmemcpy(state->window, strm->next_out - copy, copy);
  78739. state->write = copy;
  78740. state->whave = state->wsize;
  78741. }
  78742. else {
  78743. state->write += dist;
  78744. if (state->write == state->wsize) state->write = 0;
  78745. if (state->whave < state->wsize) state->whave += dist;
  78746. }
  78747. }
  78748. return 0;
  78749. }
  78750. #ifdef GUNZIP
  78751. # define UPDATE(check, buf, len) \
  78752. (state->flags ? crc32(check, buf, len) : adler32(check, buf, len))
  78753. #else
  78754. # define UPDATE(check, buf, len) adler32(check, buf, len)
  78755. #endif
  78756. #ifdef GUNZIP
  78757. # define CRC2(check, word) \
  78758. do { \
  78759. hbuf[0] = (unsigned char)(word); \
  78760. hbuf[1] = (unsigned char)((word) >> 8); \
  78761. check = crc32(check, hbuf, 2); \
  78762. } while (0)
  78763. # define CRC4(check, word) \
  78764. do { \
  78765. hbuf[0] = (unsigned char)(word); \
  78766. hbuf[1] = (unsigned char)((word) >> 8); \
  78767. hbuf[2] = (unsigned char)((word) >> 16); \
  78768. hbuf[3] = (unsigned char)((word) >> 24); \
  78769. check = crc32(check, hbuf, 4); \
  78770. } while (0)
  78771. #endif
  78772. #define LOAD() \
  78773. do { \
  78774. put = strm->next_out; \
  78775. left = strm->avail_out; \
  78776. next = strm->next_in; \
  78777. have = strm->avail_in; \
  78778. hold = state->hold; \
  78779. bits = state->bits; \
  78780. } while (0)
  78781. #define RESTORE() \
  78782. do { \
  78783. strm->next_out = put; \
  78784. strm->avail_out = left; \
  78785. strm->next_in = next; \
  78786. strm->avail_in = have; \
  78787. state->hold = hold; \
  78788. state->bits = bits; \
  78789. } while (0)
  78790. #define INITBITS() \
  78791. do { \
  78792. hold = 0; \
  78793. bits = 0; \
  78794. } while (0)
  78795. #define PULLBYTE() \
  78796. do { \
  78797. if (have == 0) goto inf_leave; \
  78798. have--; \
  78799. hold += (unsigned long)(*next++) << bits; \
  78800. bits += 8; \
  78801. } while (0)
  78802. #define NEEDBITS(n) \
  78803. do { \
  78804. while (bits < (unsigned)(n)) \
  78805. PULLBYTE(); \
  78806. } while (0)
  78807. #define BITS(n) \
  78808. ((unsigned)hold & ((1U << (n)) - 1))
  78809. #define DROPBITS(n) \
  78810. do { \
  78811. hold >>= (n); \
  78812. bits -= (unsigned)(n); \
  78813. } while (0)
  78814. #define BYTEBITS() \
  78815. do { \
  78816. hold >>= bits & 7; \
  78817. bits -= bits & 7; \
  78818. } while (0)
  78819. #define REVERSE(q) \
  78820. ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
  78821. (((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
  78822. int ZEXPORT inflate (z_streamp strm, int flush)
  78823. {
  78824. struct inflate_state FAR *state;
  78825. unsigned char FAR *next; /* next input */
  78826. unsigned char FAR *put; /* next output */
  78827. unsigned have, left; /* available input and output */
  78828. unsigned long hold; /* bit buffer */
  78829. unsigned bits; /* bits in bit buffer */
  78830. unsigned in, out; /* save starting available input and output */
  78831. unsigned copy; /* number of stored or match bytes to copy */
  78832. unsigned char FAR *from; /* where to copy match bytes from */
  78833. code thisx; /* current decoding table entry */
  78834. code last; /* parent table entry */
  78835. unsigned len; /* length to copy for repeats, bits to drop */
  78836. int ret; /* return code */
  78837. #ifdef GUNZIP
  78838. unsigned char hbuf[4]; /* buffer for gzip header crc calculation */
  78839. #endif
  78840. static const unsigned short order[19] = /* permutation of code lengths */
  78841. {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
  78842. if (strm == Z_NULL || strm->state == Z_NULL || strm->next_out == Z_NULL ||
  78843. (strm->next_in == Z_NULL && strm->avail_in != 0))
  78844. return Z_STREAM_ERROR;
  78845. state = (struct inflate_state FAR *)strm->state;
  78846. if (state->mode == TYPE) state->mode = TYPEDO; /* skip check */
  78847. LOAD();
  78848. in = have;
  78849. out = left;
  78850. ret = Z_OK;
  78851. for (;;)
  78852. switch (state->mode) {
  78853. case HEAD:
  78854. if (state->wrap == 0) {
  78855. state->mode = TYPEDO;
  78856. break;
  78857. }
  78858. NEEDBITS(16);
  78859. #ifdef GUNZIP
  78860. if ((state->wrap & 2) && hold == 0x8b1f) { /* gzip header */
  78861. state->check = crc32(0L, Z_NULL, 0);
  78862. CRC2(state->check, hold);
  78863. INITBITS();
  78864. state->mode = FLAGS;
  78865. break;
  78866. }
  78867. state->flags = 0; /* expect zlib header */
  78868. if (state->head != Z_NULL)
  78869. state->head->done = -1;
  78870. if (!(state->wrap & 1) || /* check if zlib header allowed */
  78871. #else
  78872. if (
  78873. #endif
  78874. ((BITS(8) << 8) + (hold >> 8)) % 31) {
  78875. strm->msg = (char *)"incorrect header check";
  78876. state->mode = BAD;
  78877. break;
  78878. }
  78879. if (BITS(4) != Z_DEFLATED) {
  78880. strm->msg = (char *)"unknown compression method";
  78881. state->mode = BAD;
  78882. break;
  78883. }
  78884. DROPBITS(4);
  78885. len = BITS(4) + 8;
  78886. if (len > state->wbits) {
  78887. strm->msg = (char *)"invalid window size";
  78888. state->mode = BAD;
  78889. break;
  78890. }
  78891. state->dmax = 1U << len;
  78892. Tracev((stderr, "inflate: zlib header ok\n"));
  78893. strm->adler = state->check = adler32(0L, Z_NULL, 0);
  78894. state->mode = hold & 0x200 ? DICTID : TYPE;
  78895. INITBITS();
  78896. break;
  78897. #ifdef GUNZIP
  78898. case FLAGS:
  78899. NEEDBITS(16);
  78900. state->flags = (int)(hold);
  78901. if ((state->flags & 0xff) != Z_DEFLATED) {
  78902. strm->msg = (char *)"unknown compression method";
  78903. state->mode = BAD;
  78904. break;
  78905. }
  78906. if (state->flags & 0xe000) {
  78907. strm->msg = (char *)"unknown header flags set";
  78908. state->mode = BAD;
  78909. break;
  78910. }
  78911. if (state->head != Z_NULL)
  78912. state->head->text = (int)((hold >> 8) & 1);
  78913. if (state->flags & 0x0200) CRC2(state->check, hold);
  78914. INITBITS();
  78915. state->mode = TIME;
  78916. case TIME:
  78917. NEEDBITS(32);
  78918. if (state->head != Z_NULL)
  78919. state->head->time = hold;
  78920. if (state->flags & 0x0200) CRC4(state->check, hold);
  78921. INITBITS();
  78922. state->mode = OS;
  78923. case OS:
  78924. NEEDBITS(16);
  78925. if (state->head != Z_NULL) {
  78926. state->head->xflags = (int)(hold & 0xff);
  78927. state->head->os = (int)(hold >> 8);
  78928. }
  78929. if (state->flags & 0x0200) CRC2(state->check, hold);
  78930. INITBITS();
  78931. state->mode = EXLEN;
  78932. case EXLEN:
  78933. if (state->flags & 0x0400) {
  78934. NEEDBITS(16);
  78935. state->length = (unsigned)(hold);
  78936. if (state->head != Z_NULL)
  78937. state->head->extra_len = (unsigned)hold;
  78938. if (state->flags & 0x0200) CRC2(state->check, hold);
  78939. INITBITS();
  78940. }
  78941. else if (state->head != Z_NULL)
  78942. state->head->extra = Z_NULL;
  78943. state->mode = EXTRA;
  78944. case EXTRA:
  78945. if (state->flags & 0x0400) {
  78946. copy = state->length;
  78947. if (copy > have) copy = have;
  78948. if (copy) {
  78949. if (state->head != Z_NULL &&
  78950. state->head->extra != Z_NULL) {
  78951. len = state->head->extra_len - state->length;
  78952. zmemcpy(state->head->extra + len, next,
  78953. len + copy > state->head->extra_max ?
  78954. state->head->extra_max - len : copy);
  78955. }
  78956. if (state->flags & 0x0200)
  78957. state->check = crc32(state->check, next, copy);
  78958. have -= copy;
  78959. next += copy;
  78960. state->length -= copy;
  78961. }
  78962. if (state->length) goto inf_leave;
  78963. }
  78964. state->length = 0;
  78965. state->mode = NAME;
  78966. case NAME:
  78967. if (state->flags & 0x0800) {
  78968. if (have == 0) goto inf_leave;
  78969. copy = 0;
  78970. do {
  78971. len = (unsigned)(next[copy++]);
  78972. if (state->head != Z_NULL &&
  78973. state->head->name != Z_NULL &&
  78974. state->length < state->head->name_max)
  78975. state->head->name[state->length++] = len;
  78976. } while (len && copy < have);
  78977. if (state->flags & 0x0200)
  78978. state->check = crc32(state->check, next, copy);
  78979. have -= copy;
  78980. next += copy;
  78981. if (len) goto inf_leave;
  78982. }
  78983. else if (state->head != Z_NULL)
  78984. state->head->name = Z_NULL;
  78985. state->length = 0;
  78986. state->mode = COMMENT;
  78987. case COMMENT:
  78988. if (state->flags & 0x1000) {
  78989. if (have == 0) goto inf_leave;
  78990. copy = 0;
  78991. do {
  78992. len = (unsigned)(next[copy++]);
  78993. if (state->head != Z_NULL &&
  78994. state->head->comment != Z_NULL &&
  78995. state->length < state->head->comm_max)
  78996. state->head->comment[state->length++] = len;
  78997. } while (len && copy < have);
  78998. if (state->flags & 0x0200)
  78999. state->check = crc32(state->check, next, copy);
  79000. have -= copy;
  79001. next += copy;
  79002. if (len) goto inf_leave;
  79003. }
  79004. else if (state->head != Z_NULL)
  79005. state->head->comment = Z_NULL;
  79006. state->mode = HCRC;
  79007. case HCRC:
  79008. if (state->flags & 0x0200) {
  79009. NEEDBITS(16);
  79010. if (hold != (state->check & 0xffff)) {
  79011. strm->msg = (char *)"header crc mismatch";
  79012. state->mode = BAD;
  79013. break;
  79014. }
  79015. INITBITS();
  79016. }
  79017. if (state->head != Z_NULL) {
  79018. state->head->hcrc = (int)((state->flags >> 9) & 1);
  79019. state->head->done = 1;
  79020. }
  79021. strm->adler = state->check = crc32(0L, Z_NULL, 0);
  79022. state->mode = TYPE;
  79023. break;
  79024. #endif
  79025. case DICTID:
  79026. NEEDBITS(32);
  79027. strm->adler = state->check = REVERSE(hold);
  79028. INITBITS();
  79029. state->mode = DICT;
  79030. case DICT:
  79031. if (state->havedict == 0) {
  79032. RESTORE();
  79033. return Z_NEED_DICT;
  79034. }
  79035. strm->adler = state->check = adler32(0L, Z_NULL, 0);
  79036. state->mode = TYPE;
  79037. case TYPE:
  79038. if (flush == Z_BLOCK) goto inf_leave;
  79039. case TYPEDO:
  79040. if (state->last) {
  79041. BYTEBITS();
  79042. state->mode = CHECK;
  79043. break;
  79044. }
  79045. NEEDBITS(3);
  79046. state->last = BITS(1);
  79047. DROPBITS(1);
  79048. switch (BITS(2)) {
  79049. case 0: /* stored block */
  79050. Tracev((stderr, "inflate: stored block%s\n",
  79051. state->last ? " (last)" : ""));
  79052. state->mode = STORED;
  79053. break;
  79054. case 1: /* fixed block */
  79055. fixedtables(state);
  79056. Tracev((stderr, "inflate: fixed codes block%s\n",
  79057. state->last ? " (last)" : ""));
  79058. state->mode = LEN; /* decode codes */
  79059. break;
  79060. case 2: /* dynamic block */
  79061. Tracev((stderr, "inflate: dynamic codes block%s\n",
  79062. state->last ? " (last)" : ""));
  79063. state->mode = TABLE;
  79064. break;
  79065. case 3:
  79066. strm->msg = (char *)"invalid block type";
  79067. state->mode = BAD;
  79068. }
  79069. DROPBITS(2);
  79070. break;
  79071. case STORED:
  79072. BYTEBITS(); /* go to byte boundary */
  79073. NEEDBITS(32);
  79074. if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
  79075. strm->msg = (char *)"invalid stored block lengths";
  79076. state->mode = BAD;
  79077. break;
  79078. }
  79079. state->length = (unsigned)hold & 0xffff;
  79080. Tracev((stderr, "inflate: stored length %u\n",
  79081. state->length));
  79082. INITBITS();
  79083. state->mode = COPY;
  79084. case COPY:
  79085. copy = state->length;
  79086. if (copy) {
  79087. if (copy > have) copy = have;
  79088. if (copy > left) copy = left;
  79089. if (copy == 0) goto inf_leave;
  79090. zmemcpy(put, next, copy);
  79091. have -= copy;
  79092. next += copy;
  79093. left -= copy;
  79094. put += copy;
  79095. state->length -= copy;
  79096. break;
  79097. }
  79098. Tracev((stderr, "inflate: stored end\n"));
  79099. state->mode = TYPE;
  79100. break;
  79101. case TABLE:
  79102. NEEDBITS(14);
  79103. state->nlen = BITS(5) + 257;
  79104. DROPBITS(5);
  79105. state->ndist = BITS(5) + 1;
  79106. DROPBITS(5);
  79107. state->ncode = BITS(4) + 4;
  79108. DROPBITS(4);
  79109. #ifndef PKZIP_BUG_WORKAROUND
  79110. if (state->nlen > 286 || state->ndist > 30) {
  79111. strm->msg = (char *)"too many length or distance symbols";
  79112. state->mode = BAD;
  79113. break;
  79114. }
  79115. #endif
  79116. Tracev((stderr, "inflate: table sizes ok\n"));
  79117. state->have = 0;
  79118. state->mode = LENLENS;
  79119. case LENLENS:
  79120. while (state->have < state->ncode) {
  79121. NEEDBITS(3);
  79122. state->lens[order[state->have++]] = (unsigned short)BITS(3);
  79123. DROPBITS(3);
  79124. }
  79125. while (state->have < 19)
  79126. state->lens[order[state->have++]] = 0;
  79127. state->next = state->codes;
  79128. state->lencode = (code const FAR *)(state->next);
  79129. state->lenbits = 7;
  79130. ret = inflate_table(CODES, state->lens, 19, &(state->next),
  79131. &(state->lenbits), state->work);
  79132. if (ret) {
  79133. strm->msg = (char *)"invalid code lengths set";
  79134. state->mode = BAD;
  79135. break;
  79136. }
  79137. Tracev((stderr, "inflate: code lengths ok\n"));
  79138. state->have = 0;
  79139. state->mode = CODELENS;
  79140. case CODELENS:
  79141. while (state->have < state->nlen + state->ndist) {
  79142. for (;;) {
  79143. thisx = state->lencode[BITS(state->lenbits)];
  79144. if ((unsigned)(thisx.bits) <= bits) break;
  79145. PULLBYTE();
  79146. }
  79147. if (thisx.val < 16) {
  79148. NEEDBITS(thisx.bits);
  79149. DROPBITS(thisx.bits);
  79150. state->lens[state->have++] = thisx.val;
  79151. }
  79152. else {
  79153. if (thisx.val == 16) {
  79154. NEEDBITS(thisx.bits + 2);
  79155. DROPBITS(thisx.bits);
  79156. if (state->have == 0) {
  79157. strm->msg = (char *)"invalid bit length repeat";
  79158. state->mode = BAD;
  79159. break;
  79160. }
  79161. len = state->lens[state->have - 1];
  79162. copy = 3 + BITS(2);
  79163. DROPBITS(2);
  79164. }
  79165. else if (thisx.val == 17) {
  79166. NEEDBITS(thisx.bits + 3);
  79167. DROPBITS(thisx.bits);
  79168. len = 0;
  79169. copy = 3 + BITS(3);
  79170. DROPBITS(3);
  79171. }
  79172. else {
  79173. NEEDBITS(thisx.bits + 7);
  79174. DROPBITS(thisx.bits);
  79175. len = 0;
  79176. copy = 11 + BITS(7);
  79177. DROPBITS(7);
  79178. }
  79179. if (state->have + copy > state->nlen + state->ndist) {
  79180. strm->msg = (char *)"invalid bit length repeat";
  79181. state->mode = BAD;
  79182. break;
  79183. }
  79184. while (copy--)
  79185. state->lens[state->have++] = (unsigned short)len;
  79186. }
  79187. }
  79188. if (state->mode == BAD) break;
  79189. state->next = state->codes;
  79190. state->lencode = (code const FAR *)(state->next);
  79191. state->lenbits = 9;
  79192. ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
  79193. &(state->lenbits), state->work);
  79194. if (ret) {
  79195. strm->msg = (char *)"invalid literal/lengths set";
  79196. state->mode = BAD;
  79197. break;
  79198. }
  79199. state->distcode = (code const FAR *)(state->next);
  79200. state->distbits = 6;
  79201. ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
  79202. &(state->next), &(state->distbits), state->work);
  79203. if (ret) {
  79204. strm->msg = (char *)"invalid distances set";
  79205. state->mode = BAD;
  79206. break;
  79207. }
  79208. Tracev((stderr, "inflate: codes ok\n"));
  79209. state->mode = LEN;
  79210. case LEN:
  79211. if (have >= 6 && left >= 258) {
  79212. RESTORE();
  79213. inflate_fast(strm, out);
  79214. LOAD();
  79215. break;
  79216. }
  79217. for (;;) {
  79218. thisx = state->lencode[BITS(state->lenbits)];
  79219. if ((unsigned)(thisx.bits) <= bits) break;
  79220. PULLBYTE();
  79221. }
  79222. if (thisx.op && (thisx.op & 0xf0) == 0) {
  79223. last = thisx;
  79224. for (;;) {
  79225. thisx = state->lencode[last.val +
  79226. (BITS(last.bits + last.op) >> last.bits)];
  79227. if ((unsigned)(last.bits + thisx.bits) <= bits) break;
  79228. PULLBYTE();
  79229. }
  79230. DROPBITS(last.bits);
  79231. }
  79232. DROPBITS(thisx.bits);
  79233. state->length = (unsigned)thisx.val;
  79234. if ((int)(thisx.op) == 0) {
  79235. Tracevv((stderr, thisx.val >= 0x20 && thisx.val < 0x7f ?
  79236. "inflate: literal '%c'\n" :
  79237. "inflate: literal 0x%02x\n", thisx.val));
  79238. state->mode = LIT;
  79239. break;
  79240. }
  79241. if (thisx.op & 32) {
  79242. Tracevv((stderr, "inflate: end of block\n"));
  79243. state->mode = TYPE;
  79244. break;
  79245. }
  79246. if (thisx.op & 64) {
  79247. strm->msg = (char *)"invalid literal/length code";
  79248. state->mode = BAD;
  79249. break;
  79250. }
  79251. state->extra = (unsigned)(thisx.op) & 15;
  79252. state->mode = LENEXT;
  79253. case LENEXT:
  79254. if (state->extra) {
  79255. NEEDBITS(state->extra);
  79256. state->length += BITS(state->extra);
  79257. DROPBITS(state->extra);
  79258. }
  79259. Tracevv((stderr, "inflate: length %u\n", state->length));
  79260. state->mode = DIST;
  79261. case DIST:
  79262. for (;;) {
  79263. thisx = state->distcode[BITS(state->distbits)];
  79264. if ((unsigned)(thisx.bits) <= bits) break;
  79265. PULLBYTE();
  79266. }
  79267. if ((thisx.op & 0xf0) == 0) {
  79268. last = thisx;
  79269. for (;;) {
  79270. thisx = state->distcode[last.val +
  79271. (BITS(last.bits + last.op) >> last.bits)];
  79272. if ((unsigned)(last.bits + thisx.bits) <= bits) break;
  79273. PULLBYTE();
  79274. }
  79275. DROPBITS(last.bits);
  79276. }
  79277. DROPBITS(thisx.bits);
  79278. if (thisx.op & 64) {
  79279. strm->msg = (char *)"invalid distance code";
  79280. state->mode = BAD;
  79281. break;
  79282. }
  79283. state->offset = (unsigned)thisx.val;
  79284. state->extra = (unsigned)(thisx.op) & 15;
  79285. state->mode = DISTEXT;
  79286. case DISTEXT:
  79287. if (state->extra) {
  79288. NEEDBITS(state->extra);
  79289. state->offset += BITS(state->extra);
  79290. DROPBITS(state->extra);
  79291. }
  79292. #ifdef INFLATE_STRICT
  79293. if (state->offset > state->dmax) {
  79294. strm->msg = (char *)"invalid distance too far back";
  79295. state->mode = BAD;
  79296. break;
  79297. }
  79298. #endif
  79299. if (state->offset > state->whave + out - left) {
  79300. strm->msg = (char *)"invalid distance too far back";
  79301. state->mode = BAD;
  79302. break;
  79303. }
  79304. Tracevv((stderr, "inflate: distance %u\n", state->offset));
  79305. state->mode = MATCH;
  79306. case MATCH:
  79307. if (left == 0) goto inf_leave;
  79308. copy = out - left;
  79309. if (state->offset > copy) { /* copy from window */
  79310. copy = state->offset - copy;
  79311. if (copy > state->write) {
  79312. copy -= state->write;
  79313. from = state->window + (state->wsize - copy);
  79314. }
  79315. else
  79316. from = state->window + (state->write - copy);
  79317. if (copy > state->length) copy = state->length;
  79318. }
  79319. else { /* copy from output */
  79320. from = put - state->offset;
  79321. copy = state->length;
  79322. }
  79323. if (copy > left) copy = left;
  79324. left -= copy;
  79325. state->length -= copy;
  79326. do {
  79327. *put++ = *from++;
  79328. } while (--copy);
  79329. if (state->length == 0) state->mode = LEN;
  79330. break;
  79331. case LIT:
  79332. if (left == 0) goto inf_leave;
  79333. *put++ = (unsigned char)(state->length);
  79334. left--;
  79335. state->mode = LEN;
  79336. break;
  79337. case CHECK:
  79338. if (state->wrap) {
  79339. NEEDBITS(32);
  79340. out -= left;
  79341. strm->total_out += out;
  79342. state->total += out;
  79343. if (out)
  79344. strm->adler = state->check =
  79345. UPDATE(state->check, put - out, out);
  79346. out = left;
  79347. if ((
  79348. #ifdef GUNZIP
  79349. state->flags ? hold :
  79350. #endif
  79351. REVERSE(hold)) != state->check) {
  79352. strm->msg = (char *)"incorrect data check";
  79353. state->mode = BAD;
  79354. break;
  79355. }
  79356. INITBITS();
  79357. Tracev((stderr, "inflate: check matches trailer\n"));
  79358. }
  79359. #ifdef GUNZIP
  79360. state->mode = LENGTH;
  79361. case LENGTH:
  79362. if (state->wrap && state->flags) {
  79363. NEEDBITS(32);
  79364. if (hold != (state->total & 0xffffffffUL)) {
  79365. strm->msg = (char *)"incorrect length check";
  79366. state->mode = BAD;
  79367. break;
  79368. }
  79369. INITBITS();
  79370. Tracev((stderr, "inflate: length matches trailer\n"));
  79371. }
  79372. #endif
  79373. state->mode = DONE;
  79374. case DONE:
  79375. ret = Z_STREAM_END;
  79376. goto inf_leave;
  79377. case BAD:
  79378. ret = Z_DATA_ERROR;
  79379. goto inf_leave;
  79380. case MEM:
  79381. return Z_MEM_ERROR;
  79382. case SYNC:
  79383. default:
  79384. return Z_STREAM_ERROR;
  79385. }
  79386. inf_leave:
  79387. RESTORE();
  79388. if (state->wsize || (state->mode < CHECK && out != strm->avail_out))
  79389. if (updatewindow(strm, out)) {
  79390. state->mode = MEM;
  79391. return Z_MEM_ERROR;
  79392. }
  79393. in -= strm->avail_in;
  79394. out -= strm->avail_out;
  79395. strm->total_in += in;
  79396. strm->total_out += out;
  79397. state->total += out;
  79398. if (state->wrap && out)
  79399. strm->adler = state->check =
  79400. UPDATE(state->check, strm->next_out - out, out);
  79401. strm->data_type = state->bits + (state->last ? 64 : 0) +
  79402. (state->mode == TYPE ? 128 : 0);
  79403. if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK)
  79404. ret = Z_BUF_ERROR;
  79405. return ret;
  79406. }
  79407. int ZEXPORT inflateEnd (z_streamp strm)
  79408. {
  79409. struct inflate_state FAR *state;
  79410. if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
  79411. return Z_STREAM_ERROR;
  79412. state = (struct inflate_state FAR *)strm->state;
  79413. if (state->window != Z_NULL) ZFREE(strm, state->window);
  79414. ZFREE(strm, strm->state);
  79415. strm->state = Z_NULL;
  79416. Tracev((stderr, "inflate: end\n"));
  79417. return Z_OK;
  79418. }
  79419. int ZEXPORT inflateSetDictionary (z_streamp strm, const Bytef *dictionary, uInt dictLength)
  79420. {
  79421. struct inflate_state FAR *state;
  79422. unsigned long id_;
  79423. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  79424. state = (struct inflate_state FAR *)strm->state;
  79425. if (state->wrap != 0 && state->mode != DICT)
  79426. return Z_STREAM_ERROR;
  79427. if (state->mode == DICT) {
  79428. id_ = adler32(0L, Z_NULL, 0);
  79429. id_ = adler32(id_, dictionary, dictLength);
  79430. if (id_ != state->check)
  79431. return Z_DATA_ERROR;
  79432. }
  79433. if (updatewindow(strm, strm->avail_out)) {
  79434. state->mode = MEM;
  79435. return Z_MEM_ERROR;
  79436. }
  79437. if (dictLength > state->wsize) {
  79438. zmemcpy(state->window, dictionary + dictLength - state->wsize,
  79439. state->wsize);
  79440. state->whave = state->wsize;
  79441. }
  79442. else {
  79443. zmemcpy(state->window + state->wsize - dictLength, dictionary,
  79444. dictLength);
  79445. state->whave = dictLength;
  79446. }
  79447. state->havedict = 1;
  79448. Tracev((stderr, "inflate: dictionary set\n"));
  79449. return Z_OK;
  79450. }
  79451. int ZEXPORT inflateGetHeader (z_streamp strm, gz_headerp head)
  79452. {
  79453. struct inflate_state FAR *state;
  79454. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  79455. state = (struct inflate_state FAR *)strm->state;
  79456. if ((state->wrap & 2) == 0) return Z_STREAM_ERROR;
  79457. state->head = head;
  79458. head->done = 0;
  79459. return Z_OK;
  79460. }
  79461. local unsigned syncsearch (unsigned FAR *have, unsigned char FAR *buf, unsigned len)
  79462. {
  79463. unsigned got;
  79464. unsigned next;
  79465. got = *have;
  79466. next = 0;
  79467. while (next < len && got < 4) {
  79468. if ((int)(buf[next]) == (got < 2 ? 0 : 0xff))
  79469. got++;
  79470. else if (buf[next])
  79471. got = 0;
  79472. else
  79473. got = 4 - got;
  79474. next++;
  79475. }
  79476. *have = got;
  79477. return next;
  79478. }
  79479. int ZEXPORT inflateSync (z_streamp strm)
  79480. {
  79481. unsigned len; /* number of bytes to look at or looked at */
  79482. unsigned long in, out; /* temporary to save total_in and total_out */
  79483. unsigned char buf[4]; /* to restore bit buffer to byte string */
  79484. struct inflate_state FAR *state;
  79485. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  79486. state = (struct inflate_state FAR *)strm->state;
  79487. if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR;
  79488. if (state->mode != SYNC) {
  79489. state->mode = SYNC;
  79490. state->hold <<= state->bits & 7;
  79491. state->bits -= state->bits & 7;
  79492. len = 0;
  79493. while (state->bits >= 8) {
  79494. buf[len++] = (unsigned char)(state->hold);
  79495. state->hold >>= 8;
  79496. state->bits -= 8;
  79497. }
  79498. state->have = 0;
  79499. syncsearch(&(state->have), buf, len);
  79500. }
  79501. len = syncsearch(&(state->have), strm->next_in, strm->avail_in);
  79502. strm->avail_in -= len;
  79503. strm->next_in += len;
  79504. strm->total_in += len;
  79505. if (state->have != 4) return Z_DATA_ERROR;
  79506. in = strm->total_in; out = strm->total_out;
  79507. inflateReset(strm);
  79508. strm->total_in = in; strm->total_out = out;
  79509. state->mode = TYPE;
  79510. return Z_OK;
  79511. }
  79512. int ZEXPORT inflateSyncPoint (z_streamp strm)
  79513. {
  79514. struct inflate_state FAR *state;
  79515. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  79516. state = (struct inflate_state FAR *)strm->state;
  79517. return state->mode == STORED && state->bits == 0;
  79518. }
  79519. int ZEXPORT inflateCopy(z_streamp dest, z_streamp source)
  79520. {
  79521. struct inflate_state FAR *state;
  79522. struct inflate_state FAR *copy;
  79523. unsigned char FAR *window;
  79524. unsigned wsize;
  79525. if (dest == Z_NULL || source == Z_NULL || source->state == Z_NULL ||
  79526. source->zalloc == (alloc_func)0 || source->zfree == (free_func)0)
  79527. return Z_STREAM_ERROR;
  79528. state = (struct inflate_state FAR *)source->state;
  79529. copy = (struct inflate_state FAR *)
  79530. ZALLOC(source, 1, sizeof(struct inflate_state));
  79531. if (copy == Z_NULL) return Z_MEM_ERROR;
  79532. window = Z_NULL;
  79533. if (state->window != Z_NULL) {
  79534. window = (unsigned char FAR *)
  79535. ZALLOC(source, 1U << state->wbits, sizeof(unsigned char));
  79536. if (window == Z_NULL) {
  79537. ZFREE(source, copy);
  79538. return Z_MEM_ERROR;
  79539. }
  79540. }
  79541. zmemcpy(dest, source, sizeof(z_stream));
  79542. zmemcpy(copy, state, sizeof(struct inflate_state));
  79543. if (state->lencode >= state->codes &&
  79544. state->lencode <= state->codes + ENOUGH - 1) {
  79545. copy->lencode = copy->codes + (state->lencode - state->codes);
  79546. copy->distcode = copy->codes + (state->distcode - state->codes);
  79547. }
  79548. copy->next = copy->codes + (state->next - state->codes);
  79549. if (window != Z_NULL) {
  79550. wsize = 1U << state->wbits;
  79551. zmemcpy(window, state->window, wsize);
  79552. }
  79553. copy->window = window;
  79554. dest->state = (struct internal_state FAR *)copy;
  79555. return Z_OK;
  79556. }
  79557. /*** End of inlined file: inflate.c ***/
  79558. /*** Start of inlined file: inftrees.c ***/
  79559. #define MAXBITS 15
  79560. const char inflate_copyright[] =
  79561. " inflate 1.2.3 Copyright 1995-2005 Mark Adler ";
  79562. int inflate_table (codetype type,
  79563. unsigned short FAR *lens,
  79564. unsigned codes,
  79565. code FAR * FAR *table,
  79566. unsigned FAR *bits,
  79567. unsigned short FAR *work)
  79568. {
  79569. unsigned len; /* a code's length in bits */
  79570. unsigned sym; /* index of code symbols */
  79571. unsigned min, max; /* minimum and maximum code lengths */
  79572. unsigned root; /* number of index bits for root table */
  79573. unsigned curr; /* number of index bits for current table */
  79574. unsigned drop; /* code bits to drop for sub-table */
  79575. int left; /* number of prefix codes available */
  79576. unsigned used; /* code entries in table used */
  79577. unsigned huff; /* Huffman code */
  79578. unsigned incr; /* for incrementing code, index */
  79579. unsigned fill; /* index for replicating entries */
  79580. unsigned low; /* low bits for current root entry */
  79581. unsigned mask; /* mask for low root bits */
  79582. code thisx; /* table entry for duplication */
  79583. code FAR *next; /* next available space in table */
  79584. const unsigned short FAR *base; /* base value table to use */
  79585. const unsigned short FAR *extra; /* extra bits table to use */
  79586. int end; /* use base and extra for symbol > end */
  79587. unsigned short count[MAXBITS+1]; /* number of codes of each length */
  79588. unsigned short offs[MAXBITS+1]; /* offsets in table for each length */
  79589. static const unsigned short lbase[31] = { /* Length codes 257..285 base */
  79590. 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
  79591. 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
  79592. static const unsigned short lext[31] = { /* Length codes 257..285 extra */
  79593. 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
  79594. 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 201, 196};
  79595. static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
  79596. 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
  79597. 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
  79598. 8193, 12289, 16385, 24577, 0, 0};
  79599. static const unsigned short dext[32] = { /* Distance codes 0..29 extra */
  79600. 16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22,
  79601. 23, 23, 24, 24, 25, 25, 26, 26, 27, 27,
  79602. 28, 28, 29, 29, 64, 64};
  79603. for (len = 0; len <= MAXBITS; len++)
  79604. count[len] = 0;
  79605. for (sym = 0; sym < codes; sym++)
  79606. count[lens[sym]]++;
  79607. root = *bits;
  79608. for (max = MAXBITS; max >= 1; max--)
  79609. if (count[max] != 0) break;
  79610. if (root > max) root = max;
  79611. if (max == 0) { /* no symbols to code at all */
  79612. thisx.op = (unsigned char)64; /* invalid code marker */
  79613. thisx.bits = (unsigned char)1;
  79614. thisx.val = (unsigned short)0;
  79615. *(*table)++ = thisx; /* make a table to force an error */
  79616. *(*table)++ = thisx;
  79617. *bits = 1;
  79618. return 0; /* no symbols, but wait for decoding to report error */
  79619. }
  79620. for (min = 1; min <= MAXBITS; min++)
  79621. if (count[min] != 0) break;
  79622. if (root < min) root = min;
  79623. left = 1;
  79624. for (len = 1; len <= MAXBITS; len++) {
  79625. left <<= 1;
  79626. left -= count[len];
  79627. if (left < 0) return -1; /* over-subscribed */
  79628. }
  79629. if (left > 0 && (type == CODES || max != 1))
  79630. return -1; /* incomplete set */
  79631. offs[1] = 0;
  79632. for (len = 1; len < MAXBITS; len++)
  79633. offs[len + 1] = offs[len] + count[len];
  79634. for (sym = 0; sym < codes; sym++)
  79635. if (lens[sym] != 0) work[offs[lens[sym]]++] = (unsigned short)sym;
  79636. switch (type) {
  79637. case CODES:
  79638. base = extra = work; /* dummy value--not used */
  79639. end = 19;
  79640. break;
  79641. case LENS:
  79642. base = lbase;
  79643. base -= 257;
  79644. extra = lext;
  79645. extra -= 257;
  79646. end = 256;
  79647. break;
  79648. default: /* DISTS */
  79649. base = dbase;
  79650. extra = dext;
  79651. end = -1;
  79652. }
  79653. huff = 0; /* starting code */
  79654. sym = 0; /* starting code symbol */
  79655. len = min; /* starting code length */
  79656. next = *table; /* current table to fill in */
  79657. curr = root; /* current table index bits */
  79658. drop = 0; /* current bits to drop from code for index */
  79659. low = (unsigned)(-1); /* trigger new sub-table when len > root */
  79660. used = 1U << root; /* use root table entries */
  79661. mask = used - 1; /* mask for comparing low */
  79662. if (type == LENS && used >= ENOUGH - MAXD)
  79663. return 1;
  79664. for (;;) {
  79665. thisx.bits = (unsigned char)(len - drop);
  79666. if ((int)(work[sym]) < end) {
  79667. thisx.op = (unsigned char)0;
  79668. thisx.val = work[sym];
  79669. }
  79670. else if ((int)(work[sym]) > end) {
  79671. thisx.op = (unsigned char)(extra[work[sym]]);
  79672. thisx.val = base[work[sym]];
  79673. }
  79674. else {
  79675. thisx.op = (unsigned char)(32 + 64); /* end of block */
  79676. thisx.val = 0;
  79677. }
  79678. incr = 1U << (len - drop);
  79679. fill = 1U << curr;
  79680. min = fill; /* save offset to next table */
  79681. do {
  79682. fill -= incr;
  79683. next[(huff >> drop) + fill] = thisx;
  79684. } while (fill != 0);
  79685. incr = 1U << (len - 1);
  79686. while (huff & incr)
  79687. incr >>= 1;
  79688. if (incr != 0) {
  79689. huff &= incr - 1;
  79690. huff += incr;
  79691. }
  79692. else
  79693. huff = 0;
  79694. sym++;
  79695. if (--(count[len]) == 0) {
  79696. if (len == max) break;
  79697. len = lens[work[sym]];
  79698. }
  79699. if (len > root && (huff & mask) != low) {
  79700. if (drop == 0)
  79701. drop = root;
  79702. next += min; /* here min is 1 << curr */
  79703. curr = len - drop;
  79704. left = (int)(1 << curr);
  79705. while (curr + drop < max) {
  79706. left -= count[curr + drop];
  79707. if (left <= 0) break;
  79708. curr++;
  79709. left <<= 1;
  79710. }
  79711. used += 1U << curr;
  79712. if (type == LENS && used >= ENOUGH - MAXD)
  79713. return 1;
  79714. low = huff & mask;
  79715. (*table)[low].op = (unsigned char)curr;
  79716. (*table)[low].bits = (unsigned char)root;
  79717. (*table)[low].val = (unsigned short)(next - *table);
  79718. }
  79719. }
  79720. thisx.op = (unsigned char)64; /* invalid code marker */
  79721. thisx.bits = (unsigned char)(len - drop);
  79722. thisx.val = (unsigned short)0;
  79723. while (huff != 0) {
  79724. if (drop != 0 && (huff & mask) != low) {
  79725. drop = 0;
  79726. len = root;
  79727. next = *table;
  79728. thisx.bits = (unsigned char)len;
  79729. }
  79730. next[huff >> drop] = thisx;
  79731. incr = 1U << (len - 1);
  79732. while (huff & incr)
  79733. incr >>= 1;
  79734. if (incr != 0) {
  79735. huff &= incr - 1;
  79736. huff += incr;
  79737. }
  79738. else
  79739. huff = 0;
  79740. }
  79741. *table += used;
  79742. *bits = root;
  79743. return 0;
  79744. }
  79745. /*** End of inlined file: inftrees.c ***/
  79746. /*** Start of inlined file: trees.c ***/
  79747. #ifdef DEBUG
  79748. # include <ctype.h>
  79749. #endif
  79750. #define MAX_BL_BITS 7
  79751. #define END_BLOCK 256
  79752. #define REP_3_6 16
  79753. #define REPZ_3_10 17
  79754. #define REPZ_11_138 18
  79755. local const int extra_lbits[LENGTH_CODES] /* extra bits for each length code */
  79756. = {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};
  79757. local const int extra_dbits[D_CODES] /* extra bits for each distance code */
  79758. = {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};
  79759. local const int extra_blbits[BL_CODES]/* extra bits for each bit length code */
  79760. = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7};
  79761. local const uch bl_order[BL_CODES]
  79762. = {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15};
  79763. #define Buf_size (8 * 2*sizeof(char))
  79764. #define DIST_CODE_LEN 512 /* see definition of array dist_code below */
  79765. #if defined(GEN_TREES_H) || !defined(STDC)
  79766. local ct_data static_ltree[L_CODES+2];
  79767. local ct_data static_dtree[D_CODES];
  79768. uch _dist_code[DIST_CODE_LEN];
  79769. uch _length_code[MAX_MATCH-MIN_MATCH+1];
  79770. local int base_length[LENGTH_CODES];
  79771. local int base_dist[D_CODES];
  79772. #else
  79773. /*** Start of inlined file: trees.h ***/
  79774. local const ct_data static_ltree[L_CODES+2] = {
  79775. {{ 12},{ 8}}, {{140},{ 8}}, {{ 76},{ 8}}, {{204},{ 8}}, {{ 44},{ 8}},
  79776. {{172},{ 8}}, {{108},{ 8}}, {{236},{ 8}}, {{ 28},{ 8}}, {{156},{ 8}},
  79777. {{ 92},{ 8}}, {{220},{ 8}}, {{ 60},{ 8}}, {{188},{ 8}}, {{124},{ 8}},
  79778. {{252},{ 8}}, {{ 2},{ 8}}, {{130},{ 8}}, {{ 66},{ 8}}, {{194},{ 8}},
  79779. {{ 34},{ 8}}, {{162},{ 8}}, {{ 98},{ 8}}, {{226},{ 8}}, {{ 18},{ 8}},
  79780. {{146},{ 8}}, {{ 82},{ 8}}, {{210},{ 8}}, {{ 50},{ 8}}, {{178},{ 8}},
  79781. {{114},{ 8}}, {{242},{ 8}}, {{ 10},{ 8}}, {{138},{ 8}}, {{ 74},{ 8}},
  79782. {{202},{ 8}}, {{ 42},{ 8}}, {{170},{ 8}}, {{106},{ 8}}, {{234},{ 8}},
  79783. {{ 26},{ 8}}, {{154},{ 8}}, {{ 90},{ 8}}, {{218},{ 8}}, {{ 58},{ 8}},
  79784. {{186},{ 8}}, {{122},{ 8}}, {{250},{ 8}}, {{ 6},{ 8}}, {{134},{ 8}},
  79785. {{ 70},{ 8}}, {{198},{ 8}}, {{ 38},{ 8}}, {{166},{ 8}}, {{102},{ 8}},
  79786. {{230},{ 8}}, {{ 22},{ 8}}, {{150},{ 8}}, {{ 86},{ 8}}, {{214},{ 8}},
  79787. {{ 54},{ 8}}, {{182},{ 8}}, {{118},{ 8}}, {{246},{ 8}}, {{ 14},{ 8}},
  79788. {{142},{ 8}}, {{ 78},{ 8}}, {{206},{ 8}}, {{ 46},{ 8}}, {{174},{ 8}},
  79789. {{110},{ 8}}, {{238},{ 8}}, {{ 30},{ 8}}, {{158},{ 8}}, {{ 94},{ 8}},
  79790. {{222},{ 8}}, {{ 62},{ 8}}, {{190},{ 8}}, {{126},{ 8}}, {{254},{ 8}},
  79791. {{ 1},{ 8}}, {{129},{ 8}}, {{ 65},{ 8}}, {{193},{ 8}}, {{ 33},{ 8}},
  79792. {{161},{ 8}}, {{ 97},{ 8}}, {{225},{ 8}}, {{ 17},{ 8}}, {{145},{ 8}},
  79793. {{ 81},{ 8}}, {{209},{ 8}}, {{ 49},{ 8}}, {{177},{ 8}}, {{113},{ 8}},
  79794. {{241},{ 8}}, {{ 9},{ 8}}, {{137},{ 8}}, {{ 73},{ 8}}, {{201},{ 8}},
  79795. {{ 41},{ 8}}, {{169},{ 8}}, {{105},{ 8}}, {{233},{ 8}}, {{ 25},{ 8}},
  79796. {{153},{ 8}}, {{ 89},{ 8}}, {{217},{ 8}}, {{ 57},{ 8}}, {{185},{ 8}},
  79797. {{121},{ 8}}, {{249},{ 8}}, {{ 5},{ 8}}, {{133},{ 8}}, {{ 69},{ 8}},
  79798. {{197},{ 8}}, {{ 37},{ 8}}, {{165},{ 8}}, {{101},{ 8}}, {{229},{ 8}},
  79799. {{ 21},{ 8}}, {{149},{ 8}}, {{ 85},{ 8}}, {{213},{ 8}}, {{ 53},{ 8}},
  79800. {{181},{ 8}}, {{117},{ 8}}, {{245},{ 8}}, {{ 13},{ 8}}, {{141},{ 8}},
  79801. {{ 77},{ 8}}, {{205},{ 8}}, {{ 45},{ 8}}, {{173},{ 8}}, {{109},{ 8}},
  79802. {{237},{ 8}}, {{ 29},{ 8}}, {{157},{ 8}}, {{ 93},{ 8}}, {{221},{ 8}},
  79803. {{ 61},{ 8}}, {{189},{ 8}}, {{125},{ 8}}, {{253},{ 8}}, {{ 19},{ 9}},
  79804. {{275},{ 9}}, {{147},{ 9}}, {{403},{ 9}}, {{ 83},{ 9}}, {{339},{ 9}},
  79805. {{211},{ 9}}, {{467},{ 9}}, {{ 51},{ 9}}, {{307},{ 9}}, {{179},{ 9}},
  79806. {{435},{ 9}}, {{115},{ 9}}, {{371},{ 9}}, {{243},{ 9}}, {{499},{ 9}},
  79807. {{ 11},{ 9}}, {{267},{ 9}}, {{139},{ 9}}, {{395},{ 9}}, {{ 75},{ 9}},
  79808. {{331},{ 9}}, {{203},{ 9}}, {{459},{ 9}}, {{ 43},{ 9}}, {{299},{ 9}},
  79809. {{171},{ 9}}, {{427},{ 9}}, {{107},{ 9}}, {{363},{ 9}}, {{235},{ 9}},
  79810. {{491},{ 9}}, {{ 27},{ 9}}, {{283},{ 9}}, {{155},{ 9}}, {{411},{ 9}},
  79811. {{ 91},{ 9}}, {{347},{ 9}}, {{219},{ 9}}, {{475},{ 9}}, {{ 59},{ 9}},
  79812. {{315},{ 9}}, {{187},{ 9}}, {{443},{ 9}}, {{123},{ 9}}, {{379},{ 9}},
  79813. {{251},{ 9}}, {{507},{ 9}}, {{ 7},{ 9}}, {{263},{ 9}}, {{135},{ 9}},
  79814. {{391},{ 9}}, {{ 71},{ 9}}, {{327},{ 9}}, {{199},{ 9}}, {{455},{ 9}},
  79815. {{ 39},{ 9}}, {{295},{ 9}}, {{167},{ 9}}, {{423},{ 9}}, {{103},{ 9}},
  79816. {{359},{ 9}}, {{231},{ 9}}, {{487},{ 9}}, {{ 23},{ 9}}, {{279},{ 9}},
  79817. {{151},{ 9}}, {{407},{ 9}}, {{ 87},{ 9}}, {{343},{ 9}}, {{215},{ 9}},
  79818. {{471},{ 9}}, {{ 55},{ 9}}, {{311},{ 9}}, {{183},{ 9}}, {{439},{ 9}},
  79819. {{119},{ 9}}, {{375},{ 9}}, {{247},{ 9}}, {{503},{ 9}}, {{ 15},{ 9}},
  79820. {{271},{ 9}}, {{143},{ 9}}, {{399},{ 9}}, {{ 79},{ 9}}, {{335},{ 9}},
  79821. {{207},{ 9}}, {{463},{ 9}}, {{ 47},{ 9}}, {{303},{ 9}}, {{175},{ 9}},
  79822. {{431},{ 9}}, {{111},{ 9}}, {{367},{ 9}}, {{239},{ 9}}, {{495},{ 9}},
  79823. {{ 31},{ 9}}, {{287},{ 9}}, {{159},{ 9}}, {{415},{ 9}}, {{ 95},{ 9}},
  79824. {{351},{ 9}}, {{223},{ 9}}, {{479},{ 9}}, {{ 63},{ 9}}, {{319},{ 9}},
  79825. {{191},{ 9}}, {{447},{ 9}}, {{127},{ 9}}, {{383},{ 9}}, {{255},{ 9}},
  79826. {{511},{ 9}}, {{ 0},{ 7}}, {{ 64},{ 7}}, {{ 32},{ 7}}, {{ 96},{ 7}},
  79827. {{ 16},{ 7}}, {{ 80},{ 7}}, {{ 48},{ 7}}, {{112},{ 7}}, {{ 8},{ 7}},
  79828. {{ 72},{ 7}}, {{ 40},{ 7}}, {{104},{ 7}}, {{ 24},{ 7}}, {{ 88},{ 7}},
  79829. {{ 56},{ 7}}, {{120},{ 7}}, {{ 4},{ 7}}, {{ 68},{ 7}}, {{ 36},{ 7}},
  79830. {{100},{ 7}}, {{ 20},{ 7}}, {{ 84},{ 7}}, {{ 52},{ 7}}, {{116},{ 7}},
  79831. {{ 3},{ 8}}, {{131},{ 8}}, {{ 67},{ 8}}, {{195},{ 8}}, {{ 35},{ 8}},
  79832. {{163},{ 8}}, {{ 99},{ 8}}, {{227},{ 8}}
  79833. };
  79834. local const ct_data static_dtree[D_CODES] = {
  79835. {{ 0},{ 5}}, {{16},{ 5}}, {{ 8},{ 5}}, {{24},{ 5}}, {{ 4},{ 5}},
  79836. {{20},{ 5}}, {{12},{ 5}}, {{28},{ 5}}, {{ 2},{ 5}}, {{18},{ 5}},
  79837. {{10},{ 5}}, {{26},{ 5}}, {{ 6},{ 5}}, {{22},{ 5}}, {{14},{ 5}},
  79838. {{30},{ 5}}, {{ 1},{ 5}}, {{17},{ 5}}, {{ 9},{ 5}}, {{25},{ 5}},
  79839. {{ 5},{ 5}}, {{21},{ 5}}, {{13},{ 5}}, {{29},{ 5}}, {{ 3},{ 5}},
  79840. {{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}}
  79841. };
  79842. const uch _dist_code[DIST_CODE_LEN] = {
  79843. 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8,
  79844. 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10,
  79845. 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
  79846. 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
  79847. 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13,
  79848. 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
  79849. 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  79850. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  79851. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  79852. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15,
  79853. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  79854. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  79855. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 16, 17,
  79856. 18, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22,
  79857. 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  79858. 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
  79859. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
  79860. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27,
  79861. 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
  79862. 27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  79863. 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  79864. 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  79865. 28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  79866. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  79867. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  79868. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29
  79869. };
  79870. const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {
  79871. 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12,
  79872. 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16,
  79873. 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19,
  79874. 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  79875. 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22,
  79876. 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23,
  79877. 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  79878. 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  79879. 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
  79880. 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26,
  79881. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
  79882. 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
  79883. 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28
  79884. };
  79885. local const int base_length[LENGTH_CODES] = {
  79886. 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56,
  79887. 64, 80, 96, 112, 128, 160, 192, 224, 0
  79888. };
  79889. local const int base_dist[D_CODES] = {
  79890. 0, 1, 2, 3, 4, 6, 8, 12, 16, 24,
  79891. 32, 48, 64, 96, 128, 192, 256, 384, 512, 768,
  79892. 1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576
  79893. };
  79894. /*** End of inlined file: trees.h ***/
  79895. #endif /* GEN_TREES_H */
  79896. struct static_tree_desc_s {
  79897. const ct_data *static_tree; /* static tree or NULL */
  79898. const intf *extra_bits; /* extra bits for each code or NULL */
  79899. int extra_base; /* base index for extra_bits */
  79900. int elems; /* max number of elements in the tree */
  79901. int max_length; /* max bit length for the codes */
  79902. };
  79903. local static_tree_desc static_l_desc =
  79904. {static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS};
  79905. local static_tree_desc static_d_desc =
  79906. {static_dtree, extra_dbits, 0, D_CODES, MAX_BITS};
  79907. local static_tree_desc static_bl_desc =
  79908. {(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS};
  79909. local void tr_static_init OF((void));
  79910. local void init_block OF((deflate_state *s));
  79911. local void pqdownheap OF((deflate_state *s, ct_data *tree, int k));
  79912. local void gen_bitlen OF((deflate_state *s, tree_desc *desc));
  79913. local void gen_codes OF((ct_data *tree, int max_code, ushf *bl_count));
  79914. local void build_tree OF((deflate_state *s, tree_desc *desc));
  79915. local void scan_tree OF((deflate_state *s, ct_data *tree, int max_code));
  79916. local void send_tree OF((deflate_state *s, ct_data *tree, int max_code));
  79917. local int build_bl_tree OF((deflate_state *s));
  79918. local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes,
  79919. int blcodes));
  79920. local void compress_block OF((deflate_state *s, ct_data *ltree,
  79921. ct_data *dtree));
  79922. local void set_data_type OF((deflate_state *s));
  79923. local unsigned bi_reverse OF((unsigned value, int length));
  79924. local void bi_windup OF((deflate_state *s));
  79925. local void bi_flush OF((deflate_state *s));
  79926. local void copy_block OF((deflate_state *s, charf *buf, unsigned len,
  79927. int header));
  79928. #ifdef GEN_TREES_H
  79929. local void gen_trees_header OF((void));
  79930. #endif
  79931. #ifndef DEBUG
  79932. # define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len)
  79933. #else /* DEBUG */
  79934. # define send_code(s, c, tree) \
  79935. { if (z_verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \
  79936. send_bits(s, tree[c].Code, tree[c].Len); }
  79937. #endif
  79938. #define put_short(s, w) { \
  79939. put_byte(s, (uch)((w) & 0xff)); \
  79940. put_byte(s, (uch)((ush)(w) >> 8)); \
  79941. }
  79942. #ifdef DEBUG
  79943. local void send_bits OF((deflate_state *s, int value, int length));
  79944. local void send_bits (deflate_state *s, int value, int length)
  79945. {
  79946. Tracevv((stderr," l %2d v %4x ", length, value));
  79947. Assert(length > 0 && length <= 15, "invalid length");
  79948. s->bits_sent += (ulg)length;
  79949. if (s->bi_valid > (int)Buf_size - length) {
  79950. s->bi_buf |= (value << s->bi_valid);
  79951. put_short(s, s->bi_buf);
  79952. s->bi_buf = (ush)value >> (Buf_size - s->bi_valid);
  79953. s->bi_valid += length - Buf_size;
  79954. } else {
  79955. s->bi_buf |= value << s->bi_valid;
  79956. s->bi_valid += length;
  79957. }
  79958. }
  79959. #else /* !DEBUG */
  79960. #define send_bits(s, value, length) \
  79961. { int len = length;\
  79962. if (s->bi_valid > (int)Buf_size - len) {\
  79963. int val = value;\
  79964. s->bi_buf |= (val << s->bi_valid);\
  79965. put_short(s, s->bi_buf);\
  79966. s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\
  79967. s->bi_valid += len - Buf_size;\
  79968. } else {\
  79969. s->bi_buf |= (value) << s->bi_valid;\
  79970. s->bi_valid += len;\
  79971. }\
  79972. }
  79973. #endif /* DEBUG */
  79974. local void tr_static_init()
  79975. {
  79976. #if defined(GEN_TREES_H) || !defined(STDC)
  79977. static int static_init_done = 0;
  79978. int n; /* iterates over tree elements */
  79979. int bits; /* bit counter */
  79980. int length; /* length value */
  79981. int code; /* code value */
  79982. int dist; /* distance index */
  79983. ush bl_count[MAX_BITS+1];
  79984. if (static_init_done) return;
  79985. static_l_desc.static_tree = static_ltree;
  79986. static_l_desc.extra_bits = extra_lbits;
  79987. static_d_desc.static_tree = static_dtree;
  79988. static_d_desc.extra_bits = extra_dbits;
  79989. static_bl_desc.extra_bits = extra_blbits;
  79990. length = 0;
  79991. for (code = 0; code < LENGTH_CODES-1; code++) {
  79992. base_length[code] = length;
  79993. for (n = 0; n < (1<<extra_lbits[code]); n++) {
  79994. _length_code[length++] = (uch)code;
  79995. }
  79996. }
  79997. Assert (length == 256, "tr_static_init: length != 256");
  79998. _length_code[length-1] = (uch)code;
  79999. dist = 0;
  80000. for (code = 0 ; code < 16; code++) {
  80001. base_dist[code] = dist;
  80002. for (n = 0; n < (1<<extra_dbits[code]); n++) {
  80003. _dist_code[dist++] = (uch)code;
  80004. }
  80005. }
  80006. Assert (dist == 256, "tr_static_init: dist != 256");
  80007. dist >>= 7; /* from now on, all distances are divided by 128 */
  80008. for ( ; code < D_CODES; code++) {
  80009. base_dist[code] = dist << 7;
  80010. for (n = 0; n < (1<<(extra_dbits[code]-7)); n++) {
  80011. _dist_code[256 + dist++] = (uch)code;
  80012. }
  80013. }
  80014. Assert (dist == 256, "tr_static_init: 256+dist != 512");
  80015. for (bits = 0; bits <= MAX_BITS; bits++) bl_count[bits] = 0;
  80016. n = 0;
  80017. while (n <= 143) static_ltree[n++].Len = 8, bl_count[8]++;
  80018. while (n <= 255) static_ltree[n++].Len = 9, bl_count[9]++;
  80019. while (n <= 279) static_ltree[n++].Len = 7, bl_count[7]++;
  80020. while (n <= 287) static_ltree[n++].Len = 8, bl_count[8]++;
  80021. gen_codes((ct_data *)static_ltree, L_CODES+1, bl_count);
  80022. for (n = 0; n < D_CODES; n++) {
  80023. static_dtree[n].Len = 5;
  80024. static_dtree[n].Code = bi_reverse((unsigned)n, 5);
  80025. }
  80026. static_init_done = 1;
  80027. # ifdef GEN_TREES_H
  80028. gen_trees_header();
  80029. # endif
  80030. #endif /* defined(GEN_TREES_H) || !defined(STDC) */
  80031. }
  80032. #ifdef GEN_TREES_H
  80033. # ifndef DEBUG
  80034. # include <stdio.h>
  80035. # endif
  80036. # define SEPARATOR(i, last, width) \
  80037. ((i) == (last)? "\n};\n\n" : \
  80038. ((i) % (width) == (width)-1 ? ",\n" : ", "))
  80039. void gen_trees_header()
  80040. {
  80041. FILE *header = fopen("trees.h", "w");
  80042. int i;
  80043. Assert (header != NULL, "Can't open trees.h");
  80044. fprintf(header,
  80045. "/* header created automatically with -DGEN_TREES_H */\n\n");
  80046. fprintf(header, "local const ct_data static_ltree[L_CODES+2] = {\n");
  80047. for (i = 0; i < L_CODES+2; i++) {
  80048. fprintf(header, "{{%3u},{%3u}}%s", static_ltree[i].Code,
  80049. static_ltree[i].Len, SEPARATOR(i, L_CODES+1, 5));
  80050. }
  80051. fprintf(header, "local const ct_data static_dtree[D_CODES] = {\n");
  80052. for (i = 0; i < D_CODES; i++) {
  80053. fprintf(header, "{{%2u},{%2u}}%s", static_dtree[i].Code,
  80054. static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5));
  80055. }
  80056. fprintf(header, "const uch _dist_code[DIST_CODE_LEN] = {\n");
  80057. for (i = 0; i < DIST_CODE_LEN; i++) {
  80058. fprintf(header, "%2u%s", _dist_code[i],
  80059. SEPARATOR(i, DIST_CODE_LEN-1, 20));
  80060. }
  80061. fprintf(header, "const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {\n");
  80062. for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) {
  80063. fprintf(header, "%2u%s", _length_code[i],
  80064. SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20));
  80065. }
  80066. fprintf(header, "local const int base_length[LENGTH_CODES] = {\n");
  80067. for (i = 0; i < LENGTH_CODES; i++) {
  80068. fprintf(header, "%1u%s", base_length[i],
  80069. SEPARATOR(i, LENGTH_CODES-1, 20));
  80070. }
  80071. fprintf(header, "local const int base_dist[D_CODES] = {\n");
  80072. for (i = 0; i < D_CODES; i++) {
  80073. fprintf(header, "%5u%s", base_dist[i],
  80074. SEPARATOR(i, D_CODES-1, 10));
  80075. }
  80076. fclose(header);
  80077. }
  80078. #endif /* GEN_TREES_H */
  80079. void _tr_init(deflate_state *s)
  80080. {
  80081. tr_static_init();
  80082. s->l_desc.dyn_tree = s->dyn_ltree;
  80083. s->l_desc.stat_desc = &static_l_desc;
  80084. s->d_desc.dyn_tree = s->dyn_dtree;
  80085. s->d_desc.stat_desc = &static_d_desc;
  80086. s->bl_desc.dyn_tree = s->bl_tree;
  80087. s->bl_desc.stat_desc = &static_bl_desc;
  80088. s->bi_buf = 0;
  80089. s->bi_valid = 0;
  80090. s->last_eob_len = 8; /* enough lookahead for inflate */
  80091. #ifdef DEBUG
  80092. s->compressed_len = 0L;
  80093. s->bits_sent = 0L;
  80094. #endif
  80095. init_block(s);
  80096. }
  80097. local void init_block (deflate_state *s)
  80098. {
  80099. int n; /* iterates over tree elements */
  80100. for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0;
  80101. for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0;
  80102. for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0;
  80103. s->dyn_ltree[END_BLOCK].Freq = 1;
  80104. s->opt_len = s->static_len = 0L;
  80105. s->last_lit = s->matches = 0;
  80106. }
  80107. #define SMALLEST 1
  80108. #define pqremove(s, tree, top) \
  80109. {\
  80110. top = s->heap[SMALLEST]; \
  80111. s->heap[SMALLEST] = s->heap[s->heap_len--]; \
  80112. pqdownheap(s, tree, SMALLEST); \
  80113. }
  80114. #define smaller(tree, n, m, depth) \
  80115. (tree[n].Freq < tree[m].Freq || \
  80116. (tree[n].Freq == tree[m].Freq && depth[n] <= depth[m]))
  80117. local void pqdownheap (deflate_state *s,
  80118. ct_data *tree, /* the tree to restore */
  80119. int k) /* node to move down */
  80120. {
  80121. int v = s->heap[k];
  80122. int j = k << 1; /* left son of k */
  80123. while (j <= s->heap_len) {
  80124. if (j < s->heap_len &&
  80125. smaller(tree, s->heap[j+1], s->heap[j], s->depth)) {
  80126. j++;
  80127. }
  80128. if (smaller(tree, v, s->heap[j], s->depth)) break;
  80129. s->heap[k] = s->heap[j]; k = j;
  80130. j <<= 1;
  80131. }
  80132. s->heap[k] = v;
  80133. }
  80134. local void gen_bitlen (deflate_state *s, tree_desc *desc)
  80135. {
  80136. ct_data *tree = desc->dyn_tree;
  80137. int max_code = desc->max_code;
  80138. const ct_data *stree = desc->stat_desc->static_tree;
  80139. const intf *extra = desc->stat_desc->extra_bits;
  80140. int base = desc->stat_desc->extra_base;
  80141. int max_length = desc->stat_desc->max_length;
  80142. int h; /* heap index */
  80143. int n, m; /* iterate over the tree elements */
  80144. int bits; /* bit length */
  80145. int xbits; /* extra bits */
  80146. ush f; /* frequency */
  80147. int overflow = 0; /* number of elements with bit length too large */
  80148. for (bits = 0; bits <= MAX_BITS; bits++) s->bl_count[bits] = 0;
  80149. tree[s->heap[s->heap_max]].Len = 0; /* root of the heap */
  80150. for (h = s->heap_max+1; h < HEAP_SIZE; h++) {
  80151. n = s->heap[h];
  80152. bits = tree[tree[n].Dad].Len + 1;
  80153. if (bits > max_length) bits = max_length, overflow++;
  80154. tree[n].Len = (ush)bits;
  80155. if (n > max_code) continue; /* not a leaf node */
  80156. s->bl_count[bits]++;
  80157. xbits = 0;
  80158. if (n >= base) xbits = extra[n-base];
  80159. f = tree[n].Freq;
  80160. s->opt_len += (ulg)f * (bits + xbits);
  80161. if (stree) s->static_len += (ulg)f * (stree[n].Len + xbits);
  80162. }
  80163. if (overflow == 0) return;
  80164. Trace((stderr,"\nbit length overflow\n"));
  80165. do {
  80166. bits = max_length-1;
  80167. while (s->bl_count[bits] == 0) bits--;
  80168. s->bl_count[bits]--; /* move one leaf down the tree */
  80169. s->bl_count[bits+1] += 2; /* move one overflow item as its brother */
  80170. s->bl_count[max_length]--;
  80171. overflow -= 2;
  80172. } while (overflow > 0);
  80173. for (bits = max_length; bits != 0; bits--) {
  80174. n = s->bl_count[bits];
  80175. while (n != 0) {
  80176. m = s->heap[--h];
  80177. if (m > max_code) continue;
  80178. if ((unsigned) tree[m].Len != (unsigned) bits) {
  80179. Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
  80180. s->opt_len += ((long)bits - (long)tree[m].Len)
  80181. *(long)tree[m].Freq;
  80182. tree[m].Len = (ush)bits;
  80183. }
  80184. n--;
  80185. }
  80186. }
  80187. }
  80188. local void gen_codes (ct_data *tree, /* the tree to decorate */
  80189. int max_code, /* largest code with non zero frequency */
  80190. ushf *bl_count) /* number of codes at each bit length */
  80191. {
  80192. ush next_code[MAX_BITS+1]; /* next code value for each bit length */
  80193. ush code = 0; /* running code value */
  80194. int bits; /* bit index */
  80195. int n; /* code index */
  80196. for (bits = 1; bits <= MAX_BITS; bits++) {
  80197. next_code[bits] = code = (code + bl_count[bits-1]) << 1;
  80198. }
  80199. Assert (code + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1,
  80200. "inconsistent bit counts");
  80201. Tracev((stderr,"\ngen_codes: max_code %d ", max_code));
  80202. for (n = 0; n <= max_code; n++) {
  80203. int len = tree[n].Len;
  80204. if (len == 0) continue;
  80205. tree[n].Code = bi_reverse(next_code[len]++, len);
  80206. Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
  80207. n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));
  80208. }
  80209. }
  80210. local void build_tree (deflate_state *s,
  80211. tree_desc *desc) /* the tree descriptor */
  80212. {
  80213. ct_data *tree = desc->dyn_tree;
  80214. const ct_data *stree = desc->stat_desc->static_tree;
  80215. int elems = desc->stat_desc->elems;
  80216. int n, m; /* iterate over heap elements */
  80217. int max_code = -1; /* largest code with non zero frequency */
  80218. int node; /* new node being created */
  80219. s->heap_len = 0, s->heap_max = HEAP_SIZE;
  80220. for (n = 0; n < elems; n++) {
  80221. if (tree[n].Freq != 0) {
  80222. s->heap[++(s->heap_len)] = max_code = n;
  80223. s->depth[n] = 0;
  80224. } else {
  80225. tree[n].Len = 0;
  80226. }
  80227. }
  80228. while (s->heap_len < 2) {
  80229. node = s->heap[++(s->heap_len)] = (max_code < 2 ? ++max_code : 0);
  80230. tree[node].Freq = 1;
  80231. s->depth[node] = 0;
  80232. s->opt_len--; if (stree) s->static_len -= stree[node].Len;
  80233. }
  80234. desc->max_code = max_code;
  80235. for (n = s->heap_len/2; n >= 1; n--) pqdownheap(s, tree, n);
  80236. node = elems; /* next internal node of the tree */
  80237. do {
  80238. pqremove(s, tree, n); /* n = node of least frequency */
  80239. m = s->heap[SMALLEST]; /* m = node of next least frequency */
  80240. s->heap[--(s->heap_max)] = n; /* keep the nodes sorted by frequency */
  80241. s->heap[--(s->heap_max)] = m;
  80242. tree[node].Freq = tree[n].Freq + tree[m].Freq;
  80243. s->depth[node] = (uch)((s->depth[n] >= s->depth[m] ?
  80244. s->depth[n] : s->depth[m]) + 1);
  80245. tree[n].Dad = tree[m].Dad = (ush)node;
  80246. #ifdef DUMP_BL_TREE
  80247. if (tree == s->bl_tree) {
  80248. fprintf(stderr,"\nnode %d(%d), sons %d(%d) %d(%d)",
  80249. node, tree[node].Freq, n, tree[n].Freq, m, tree[m].Freq);
  80250. }
  80251. #endif
  80252. s->heap[SMALLEST] = node++;
  80253. pqdownheap(s, tree, SMALLEST);
  80254. } while (s->heap_len >= 2);
  80255. s->heap[--(s->heap_max)] = s->heap[SMALLEST];
  80256. gen_bitlen(s, (tree_desc *)desc);
  80257. gen_codes ((ct_data *)tree, max_code, s->bl_count);
  80258. }
  80259. local void scan_tree (deflate_state *s,
  80260. ct_data *tree, /* the tree to be scanned */
  80261. int max_code) /* and its largest code of non zero frequency */
  80262. {
  80263. int n; /* iterates over all tree elements */
  80264. int prevlen = -1; /* last emitted length */
  80265. int curlen; /* length of current code */
  80266. int nextlen = tree[0].Len; /* length of next code */
  80267. int count = 0; /* repeat count of the current code */
  80268. int max_count = 7; /* max repeat count */
  80269. int min_count = 4; /* min repeat count */
  80270. if (nextlen == 0) max_count = 138, min_count = 3;
  80271. tree[max_code+1].Len = (ush)0xffff; /* guard */
  80272. for (n = 0; n <= max_code; n++) {
  80273. curlen = nextlen; nextlen = tree[n+1].Len;
  80274. if (++count < max_count && curlen == nextlen) {
  80275. continue;
  80276. } else if (count < min_count) {
  80277. s->bl_tree[curlen].Freq += count;
  80278. } else if (curlen != 0) {
  80279. if (curlen != prevlen) s->bl_tree[curlen].Freq++;
  80280. s->bl_tree[REP_3_6].Freq++;
  80281. } else if (count <= 10) {
  80282. s->bl_tree[REPZ_3_10].Freq++;
  80283. } else {
  80284. s->bl_tree[REPZ_11_138].Freq++;
  80285. }
  80286. count = 0; prevlen = curlen;
  80287. if (nextlen == 0) {
  80288. max_count = 138, min_count = 3;
  80289. } else if (curlen == nextlen) {
  80290. max_count = 6, min_count = 3;
  80291. } else {
  80292. max_count = 7, min_count = 4;
  80293. }
  80294. }
  80295. }
  80296. local void send_tree (deflate_state *s,
  80297. ct_data *tree, /* the tree to be scanned */
  80298. int max_code) /* and its largest code of non zero frequency */
  80299. {
  80300. int n; /* iterates over all tree elements */
  80301. int prevlen = -1; /* last emitted length */
  80302. int curlen; /* length of current code */
  80303. int nextlen = tree[0].Len; /* length of next code */
  80304. int count = 0; /* repeat count of the current code */
  80305. int max_count = 7; /* max repeat count */
  80306. int min_count = 4; /* min repeat count */
  80307. /* guard already set */
  80308. if (nextlen == 0) max_count = 138, min_count = 3;
  80309. for (n = 0; n <= max_code; n++) {
  80310. curlen = nextlen; nextlen = tree[n+1].Len;
  80311. if (++count < max_count && curlen == nextlen) {
  80312. continue;
  80313. } else if (count < min_count) {
  80314. do { send_code(s, curlen, s->bl_tree); } while (--count != 0);
  80315. } else if (curlen != 0) {
  80316. if (curlen != prevlen) {
  80317. send_code(s, curlen, s->bl_tree); count--;
  80318. }
  80319. Assert(count >= 3 && count <= 6, " 3_6?");
  80320. send_code(s, REP_3_6, s->bl_tree); send_bits(s, count-3, 2);
  80321. } else if (count <= 10) {
  80322. send_code(s, REPZ_3_10, s->bl_tree); send_bits(s, count-3, 3);
  80323. } else {
  80324. send_code(s, REPZ_11_138, s->bl_tree); send_bits(s, count-11, 7);
  80325. }
  80326. count = 0; prevlen = curlen;
  80327. if (nextlen == 0) {
  80328. max_count = 138, min_count = 3;
  80329. } else if (curlen == nextlen) {
  80330. max_count = 6, min_count = 3;
  80331. } else {
  80332. max_count = 7, min_count = 4;
  80333. }
  80334. }
  80335. }
  80336. local int build_bl_tree (deflate_state *s)
  80337. {
  80338. int max_blindex; /* index of last bit length code of non zero freq */
  80339. scan_tree(s, (ct_data *)s->dyn_ltree, s->l_desc.max_code);
  80340. scan_tree(s, (ct_data *)s->dyn_dtree, s->d_desc.max_code);
  80341. build_tree(s, (tree_desc *)(&(s->bl_desc)));
  80342. for (max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex--) {
  80343. if (s->bl_tree[bl_order[max_blindex]].Len != 0) break;
  80344. }
  80345. s->opt_len += 3*(max_blindex+1) + 5+5+4;
  80346. Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld",
  80347. s->opt_len, s->static_len));
  80348. return max_blindex;
  80349. }
  80350. local void send_all_trees (deflate_state *s,
  80351. int lcodes, int dcodes, int blcodes) /* number of codes for each tree */
  80352. {
  80353. int rank; /* index in bl_order */
  80354. Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");
  80355. Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES,
  80356. "too many codes");
  80357. Tracev((stderr, "\nbl counts: "));
  80358. send_bits(s, lcodes-257, 5); /* not +255 as stated in appnote.txt */
  80359. send_bits(s, dcodes-1, 5);
  80360. send_bits(s, blcodes-4, 4); /* not -3 as stated in appnote.txt */
  80361. for (rank = 0; rank < blcodes; rank++) {
  80362. Tracev((stderr, "\nbl code %2d ", bl_order[rank]));
  80363. send_bits(s, s->bl_tree[bl_order[rank]].Len, 3);
  80364. }
  80365. Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent));
  80366. send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */
  80367. Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent));
  80368. send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */
  80369. Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent));
  80370. }
  80371. void _tr_stored_block (deflate_state *s, charf *buf, ulg stored_len, int eof)
  80372. {
  80373. send_bits(s, (STORED_BLOCK<<1)+eof, 3); /* send block type */
  80374. #ifdef DEBUG
  80375. s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L;
  80376. s->compressed_len += (stored_len + 4) << 3;
  80377. #endif
  80378. copy_block(s, buf, (unsigned)stored_len, 1); /* with header */
  80379. }
  80380. void _tr_align (deflate_state *s)
  80381. {
  80382. send_bits(s, STATIC_TREES<<1, 3);
  80383. send_code(s, END_BLOCK, static_ltree);
  80384. #ifdef DEBUG
  80385. s->compressed_len += 10L; /* 3 for block type, 7 for EOB */
  80386. #endif
  80387. bi_flush(s);
  80388. if (1 + s->last_eob_len + 10 - s->bi_valid < 9) {
  80389. send_bits(s, STATIC_TREES<<1, 3);
  80390. send_code(s, END_BLOCK, static_ltree);
  80391. #ifdef DEBUG
  80392. s->compressed_len += 10L;
  80393. #endif
  80394. bi_flush(s);
  80395. }
  80396. s->last_eob_len = 7;
  80397. }
  80398. void _tr_flush_block (deflate_state *s,
  80399. charf *buf, /* input block, or NULL if too old */
  80400. ulg stored_len, /* length of input block */
  80401. int eof) /* true if this is the last block for a file */
  80402. {
  80403. ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */
  80404. int max_blindex = 0; /* index of last bit length code of non zero freq */
  80405. if (s->level > 0) {
  80406. if (stored_len > 0 && s->strm->data_type == Z_UNKNOWN)
  80407. set_data_type(s);
  80408. build_tree(s, (tree_desc *)(&(s->l_desc)));
  80409. Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len,
  80410. s->static_len));
  80411. build_tree(s, (tree_desc *)(&(s->d_desc)));
  80412. Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len,
  80413. s->static_len));
  80414. max_blindex = build_bl_tree(s);
  80415. opt_lenb = (s->opt_len+3+7)>>3;
  80416. static_lenb = (s->static_len+3+7)>>3;
  80417. Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",
  80418. opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
  80419. s->last_lit));
  80420. if (static_lenb <= opt_lenb) opt_lenb = static_lenb;
  80421. } else {
  80422. Assert(buf != (char*)0, "lost buf");
  80423. opt_lenb = static_lenb = stored_len + 5; /* force a stored block */
  80424. }
  80425. #ifdef FORCE_STORED
  80426. if (buf != (char*)0) { /* force stored block */
  80427. #else
  80428. if (stored_len+4 <= opt_lenb && buf != (char*)0) {
  80429. #endif
  80430. _tr_stored_block(s, buf, stored_len, eof);
  80431. #ifdef FORCE_STATIC
  80432. } else if (static_lenb >= 0) { /* force static trees */
  80433. #else
  80434. } else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) {
  80435. #endif
  80436. send_bits(s, (STATIC_TREES<<1)+eof, 3);
  80437. compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree);
  80438. #ifdef DEBUG
  80439. s->compressed_len += 3 + s->static_len;
  80440. #endif
  80441. } else {
  80442. send_bits(s, (DYN_TREES<<1)+eof, 3);
  80443. send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1,
  80444. max_blindex+1);
  80445. compress_block(s, (ct_data *)s->dyn_ltree, (ct_data *)s->dyn_dtree);
  80446. #ifdef DEBUG
  80447. s->compressed_len += 3 + s->opt_len;
  80448. #endif
  80449. }
  80450. Assert (s->compressed_len == s->bits_sent, "bad compressed size");
  80451. init_block(s);
  80452. if (eof) {
  80453. bi_windup(s);
  80454. #ifdef DEBUG
  80455. s->compressed_len += 7; /* align on byte boundary */
  80456. #endif
  80457. }
  80458. Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,
  80459. s->compressed_len-7*eof));
  80460. }
  80461. int _tr_tally (deflate_state *s,
  80462. unsigned dist, /* distance of matched string */
  80463. unsigned lc) /* match length-MIN_MATCH or unmatched char (if dist==0) */
  80464. {
  80465. s->d_buf[s->last_lit] = (ush)dist;
  80466. s->l_buf[s->last_lit++] = (uch)lc;
  80467. if (dist == 0) {
  80468. s->dyn_ltree[lc].Freq++;
  80469. } else {
  80470. s->matches++;
  80471. dist--; /* dist = match distance - 1 */
  80472. Assert((ush)dist < (ush)MAX_DIST(s) &&
  80473. (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) &&
  80474. (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match");
  80475. s->dyn_ltree[_length_code[lc]+LITERALS+1].Freq++;
  80476. s->dyn_dtree[d_code(dist)].Freq++;
  80477. }
  80478. #ifdef TRUNCATE_BLOCK
  80479. if ((s->last_lit & 0x1fff) == 0 && s->level > 2) {
  80480. ulg out_length = (ulg)s->last_lit*8L;
  80481. ulg in_length = (ulg)((long)s->strstart - s->block_start);
  80482. int dcode;
  80483. for (dcode = 0; dcode < D_CODES; dcode++) {
  80484. out_length += (ulg)s->dyn_dtree[dcode].Freq *
  80485. (5L+extra_dbits[dcode]);
  80486. }
  80487. out_length >>= 3;
  80488. Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ",
  80489. s->last_lit, in_length, out_length,
  80490. 100L - out_length*100L/in_length));
  80491. if (s->matches < s->last_lit/2 && out_length < in_length/2) return 1;
  80492. }
  80493. #endif
  80494. return (s->last_lit == s->lit_bufsize-1);
  80495. }
  80496. local void compress_block (deflate_state *s,
  80497. ct_data *ltree, /* literal tree */
  80498. ct_data *dtree) /* distance tree */
  80499. {
  80500. unsigned dist; /* distance of matched string */
  80501. int lc; /* match length or unmatched char (if dist == 0) */
  80502. unsigned lx = 0; /* running index in l_buf */
  80503. unsigned code; /* the code to send */
  80504. int extra; /* number of extra bits to send */
  80505. if (s->last_lit != 0) do {
  80506. dist = s->d_buf[lx];
  80507. lc = s->l_buf[lx++];
  80508. if (dist == 0) {
  80509. send_code(s, lc, ltree); /* send a literal byte */
  80510. Tracecv(isgraph(lc), (stderr," '%c' ", lc));
  80511. } else {
  80512. code = _length_code[lc];
  80513. send_code(s, code+LITERALS+1, ltree); /* send the length code */
  80514. extra = extra_lbits[code];
  80515. if (extra != 0) {
  80516. lc -= base_length[code];
  80517. send_bits(s, lc, extra); /* send the extra length bits */
  80518. }
  80519. dist--; /* dist is now the match distance - 1 */
  80520. code = d_code(dist);
  80521. Assert (code < D_CODES, "bad d_code");
  80522. send_code(s, code, dtree); /* send the distance code */
  80523. extra = extra_dbits[code];
  80524. if (extra != 0) {
  80525. dist -= base_dist[code];
  80526. send_bits(s, dist, extra); /* send the extra distance bits */
  80527. }
  80528. } /* literal or match pair ? */
  80529. Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx,
  80530. "pendingBuf overflow");
  80531. } while (lx < s->last_lit);
  80532. send_code(s, END_BLOCK, ltree);
  80533. s->last_eob_len = ltree[END_BLOCK].Len;
  80534. }
  80535. local void set_data_type (deflate_state *s)
  80536. {
  80537. int n;
  80538. for (n = 0; n < 9; n++)
  80539. if (s->dyn_ltree[n].Freq != 0)
  80540. break;
  80541. if (n == 9)
  80542. for (n = 14; n < 32; n++)
  80543. if (s->dyn_ltree[n].Freq != 0)
  80544. break;
  80545. s->strm->data_type = (n == 32) ? Z_TEXT : Z_BINARY;
  80546. }
  80547. local unsigned bi_reverse (unsigned code, int len)
  80548. {
  80549. register unsigned res = 0;
  80550. do {
  80551. res |= code & 1;
  80552. code >>= 1, res <<= 1;
  80553. } while (--len > 0);
  80554. return res >> 1;
  80555. }
  80556. local void bi_flush (deflate_state *s)
  80557. {
  80558. if (s->bi_valid == 16) {
  80559. put_short(s, s->bi_buf);
  80560. s->bi_buf = 0;
  80561. s->bi_valid = 0;
  80562. } else if (s->bi_valid >= 8) {
  80563. put_byte(s, (Byte)s->bi_buf);
  80564. s->bi_buf >>= 8;
  80565. s->bi_valid -= 8;
  80566. }
  80567. }
  80568. local void bi_windup (deflate_state *s)
  80569. {
  80570. if (s->bi_valid > 8) {
  80571. put_short(s, s->bi_buf);
  80572. } else if (s->bi_valid > 0) {
  80573. put_byte(s, (Byte)s->bi_buf);
  80574. }
  80575. s->bi_buf = 0;
  80576. s->bi_valid = 0;
  80577. #ifdef DEBUG
  80578. s->bits_sent = (s->bits_sent+7) & ~7;
  80579. #endif
  80580. }
  80581. local void copy_block(deflate_state *s,
  80582. charf *buf, /* the input data */
  80583. unsigned len, /* its length */
  80584. int header) /* true if block header must be written */
  80585. {
  80586. bi_windup(s); /* align on byte boundary */
  80587. s->last_eob_len = 8; /* enough lookahead for inflate */
  80588. if (header) {
  80589. put_short(s, (ush)len);
  80590. put_short(s, (ush)~len);
  80591. #ifdef DEBUG
  80592. s->bits_sent += 2*16;
  80593. #endif
  80594. }
  80595. #ifdef DEBUG
  80596. s->bits_sent += (ulg)len<<3;
  80597. #endif
  80598. while (len--) {
  80599. put_byte(s, *buf++);
  80600. }
  80601. }
  80602. /*** End of inlined file: trees.c ***/
  80603. /*** Start of inlined file: zutil.c ***/
  80604. #ifndef NO_DUMMY_DECL
  80605. struct internal_state {int dummy;}; /* for buggy compilers */
  80606. #endif
  80607. const char * const z_errmsg[10] = {
  80608. "need dictionary", /* Z_NEED_DICT 2 */
  80609. "stream end", /* Z_STREAM_END 1 */
  80610. "", /* Z_OK 0 */
  80611. "file error", /* Z_ERRNO (-1) */
  80612. "stream error", /* Z_STREAM_ERROR (-2) */
  80613. "data error", /* Z_DATA_ERROR (-3) */
  80614. "insufficient memory", /* Z_MEM_ERROR (-4) */
  80615. "buffer error", /* Z_BUF_ERROR (-5) */
  80616. "incompatible version",/* Z_VERSION_ERROR (-6) */
  80617. ""};
  80618. #ifdef DEBUG
  80619. # ifndef verbose
  80620. # define verbose 0
  80621. # endif
  80622. int z_verbose = verbose;
  80623. void z_error (const char *m)
  80624. {
  80625. fprintf(stderr, "%s\n", m);
  80626. exit(1);
  80627. }
  80628. #endif
  80629. const char * ZEXPORT zError(int err)
  80630. {
  80631. return ERR_MSG(err);
  80632. }
  80633. #if defined(_WIN32_WCE)
  80634. int errno = 0;
  80635. #endif
  80636. #ifndef HAVE_MEMCPY
  80637. void zmemcpy(dest, source, len)
  80638. Bytef* dest;
  80639. const Bytef* source;
  80640. uInt len;
  80641. {
  80642. if (len == 0) return;
  80643. do {
  80644. *dest++ = *source++; /* ??? to be unrolled */
  80645. } while (--len != 0);
  80646. }
  80647. int zmemcmp(s1, s2, len)
  80648. const Bytef* s1;
  80649. const Bytef* s2;
  80650. uInt len;
  80651. {
  80652. uInt j;
  80653. for (j = 0; j < len; j++) {
  80654. if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
  80655. }
  80656. return 0;
  80657. }
  80658. void zmemzero(dest, len)
  80659. Bytef* dest;
  80660. uInt len;
  80661. {
  80662. if (len == 0) return;
  80663. do {
  80664. *dest++ = 0; /* ??? to be unrolled */
  80665. } while (--len != 0);
  80666. }
  80667. #endif
  80668. #ifdef SYS16BIT
  80669. #ifdef __TURBOC__
  80670. # define MY_ZCALLOC
  80671. #define MAX_PTR 10
  80672. local int next_ptr = 0;
  80673. typedef struct ptr_table_s {
  80674. voidpf org_ptr;
  80675. voidpf new_ptr;
  80676. } ptr_table;
  80677. local ptr_table table[MAX_PTR];
  80678. voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  80679. {
  80680. voidpf buf = opaque; /* just to make some compilers happy */
  80681. ulg bsize = (ulg)items*size;
  80682. if (bsize < 65520L) {
  80683. buf = farmalloc(bsize);
  80684. if (*(ush*)&buf != 0) return buf;
  80685. } else {
  80686. buf = farmalloc(bsize + 16L);
  80687. }
  80688. if (buf == NULL || next_ptr >= MAX_PTR) return NULL;
  80689. table[next_ptr].org_ptr = buf;
  80690. *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4;
  80691. *(ush*)&buf = 0;
  80692. table[next_ptr++].new_ptr = buf;
  80693. return buf;
  80694. }
  80695. void zcfree (voidpf opaque, voidpf ptr)
  80696. {
  80697. int n;
  80698. if (*(ush*)&ptr != 0) { /* object < 64K */
  80699. farfree(ptr);
  80700. return;
  80701. }
  80702. for (n = 0; n < next_ptr; n++) {
  80703. if (ptr != table[n].new_ptr) continue;
  80704. farfree(table[n].org_ptr);
  80705. while (++n < next_ptr) {
  80706. table[n-1] = table[n];
  80707. }
  80708. next_ptr--;
  80709. return;
  80710. }
  80711. ptr = opaque; /* just to make some compilers happy */
  80712. Assert(0, "zcfree: ptr not found");
  80713. }
  80714. #endif /* __TURBOC__ */
  80715. #ifdef M_I86
  80716. # define MY_ZCALLOC
  80717. #if (!defined(_MSC_VER) || (_MSC_VER <= 600))
  80718. # define _halloc halloc
  80719. # define _hfree hfree
  80720. #endif
  80721. voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  80722. {
  80723. if (opaque) opaque = 0; /* to make compiler happy */
  80724. return _halloc((long)items, size);
  80725. }
  80726. void zcfree (voidpf opaque, voidpf ptr)
  80727. {
  80728. if (opaque) opaque = 0; /* to make compiler happy */
  80729. _hfree(ptr);
  80730. }
  80731. #endif /* M_I86 */
  80732. #endif /* SYS16BIT */
  80733. #ifndef MY_ZCALLOC /* Any system without a special alloc function */
  80734. #ifndef STDC
  80735. extern voidp malloc OF((uInt size));
  80736. extern voidp calloc OF((uInt items, uInt size));
  80737. extern void free OF((voidpf ptr));
  80738. #endif
  80739. voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  80740. {
  80741. if (opaque) items += size - size; /* make compiler happy */
  80742. return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) :
  80743. (voidpf)calloc(items, size);
  80744. }
  80745. void zcfree (voidpf opaque, voidpf ptr)
  80746. {
  80747. free(ptr);
  80748. if (opaque) return; /* make compiler happy */
  80749. }
  80750. #endif /* MY_ZCALLOC */
  80751. /*** End of inlined file: zutil.c ***/
  80752. #undef Byte
  80753. }
  80754. #else
  80755. #include <zlib.h>
  80756. #endif
  80757. }
  80758. #if JUCE_MSVC
  80759. #pragma warning (pop)
  80760. #endif
  80761. BEGIN_JUCE_NAMESPACE
  80762. using namespace zlibNamespace;
  80763. // internal helper object that holds the zlib structures so they don't have to be
  80764. // included publicly.
  80765. class GZIPDecompressHelper
  80766. {
  80767. public:
  80768. GZIPDecompressHelper (const bool noWrap) throw()
  80769. : data (0),
  80770. dataSize (0),
  80771. finished (true),
  80772. needsDictionary (false),
  80773. error (true),
  80774. streamIsValid (false)
  80775. {
  80776. zerostruct (stream);
  80777. streamIsValid = (inflateInit2 (&stream, noWrap ? -MAX_WBITS : MAX_WBITS) == Z_OK);
  80778. finished = error = ! streamIsValid;
  80779. }
  80780. ~GZIPDecompressHelper() throw()
  80781. {
  80782. if (streamIsValid)
  80783. inflateEnd (&stream);
  80784. }
  80785. bool needsInput() const throw() { return dataSize <= 0; }
  80786. void setInput (uint8* const data_, const int size) throw()
  80787. {
  80788. data = data_;
  80789. dataSize = size;
  80790. }
  80791. int doNextBlock (uint8* const dest, const int destSize) throw()
  80792. {
  80793. if (streamIsValid && data != 0 && ! finished)
  80794. {
  80795. stream.next_in = data;
  80796. stream.next_out = dest;
  80797. stream.avail_in = dataSize;
  80798. stream.avail_out = destSize;
  80799. switch (inflate (&stream, Z_PARTIAL_FLUSH))
  80800. {
  80801. case Z_STREAM_END:
  80802. finished = true;
  80803. // deliberate fall-through
  80804. case Z_OK:
  80805. data += dataSize - stream.avail_in;
  80806. dataSize = stream.avail_in;
  80807. return destSize - stream.avail_out;
  80808. case Z_NEED_DICT:
  80809. needsDictionary = true;
  80810. data += dataSize - stream.avail_in;
  80811. dataSize = stream.avail_in;
  80812. break;
  80813. case Z_DATA_ERROR:
  80814. case Z_MEM_ERROR:
  80815. error = true;
  80816. default:
  80817. break;
  80818. }
  80819. }
  80820. return 0;
  80821. }
  80822. private:
  80823. z_stream stream;
  80824. uint8* data;
  80825. int dataSize;
  80826. public:
  80827. bool finished, needsDictionary, error, streamIsValid;
  80828. };
  80829. const int gzipDecompBufferSize = 32768;
  80830. GZIPDecompressorInputStream::GZIPDecompressorInputStream (InputStream* const sourceStream_,
  80831. const bool deleteSourceWhenDestroyed,
  80832. const bool noWrap_,
  80833. const int64 uncompressedStreamLength_)
  80834. : sourceStream (sourceStream_),
  80835. streamToDelete (deleteSourceWhenDestroyed ? sourceStream_ : 0),
  80836. uncompressedStreamLength (uncompressedStreamLength_),
  80837. noWrap (noWrap_),
  80838. isEof (false),
  80839. activeBufferSize (0),
  80840. originalSourcePos (sourceStream_->getPosition()),
  80841. currentPos (0),
  80842. buffer (gzipDecompBufferSize),
  80843. helper (new GZIPDecompressHelper (noWrap_))
  80844. {
  80845. }
  80846. GZIPDecompressorInputStream::~GZIPDecompressorInputStream()
  80847. {
  80848. }
  80849. int64 GZIPDecompressorInputStream::getTotalLength()
  80850. {
  80851. return uncompressedStreamLength;
  80852. }
  80853. int GZIPDecompressorInputStream::read (void* destBuffer, int howMany)
  80854. {
  80855. if ((howMany > 0) && ! isEof)
  80856. {
  80857. jassert (destBuffer != 0);
  80858. if (destBuffer != 0)
  80859. {
  80860. int numRead = 0;
  80861. uint8* d = (uint8*) destBuffer;
  80862. while (! helper->error)
  80863. {
  80864. const int n = helper->doNextBlock (d, howMany);
  80865. currentPos += n;
  80866. if (n == 0)
  80867. {
  80868. if (helper->finished || helper->needsDictionary)
  80869. {
  80870. isEof = true;
  80871. return numRead;
  80872. }
  80873. if (helper->needsInput())
  80874. {
  80875. activeBufferSize = sourceStream->read (buffer, gzipDecompBufferSize);
  80876. if (activeBufferSize > 0)
  80877. {
  80878. helper->setInput ((uint8*) buffer, activeBufferSize);
  80879. }
  80880. else
  80881. {
  80882. isEof = true;
  80883. return numRead;
  80884. }
  80885. }
  80886. }
  80887. else
  80888. {
  80889. numRead += n;
  80890. howMany -= n;
  80891. d += n;
  80892. if (howMany <= 0)
  80893. return numRead;
  80894. }
  80895. }
  80896. }
  80897. }
  80898. return 0;
  80899. }
  80900. bool GZIPDecompressorInputStream::isExhausted()
  80901. {
  80902. return helper->error || isEof;
  80903. }
  80904. int64 GZIPDecompressorInputStream::getPosition()
  80905. {
  80906. return currentPos;
  80907. }
  80908. bool GZIPDecompressorInputStream::setPosition (int64 newPos)
  80909. {
  80910. if (newPos < currentPos)
  80911. {
  80912. // to go backwards, reset the stream and start again..
  80913. isEof = false;
  80914. activeBufferSize = 0;
  80915. currentPos = 0;
  80916. helper = new GZIPDecompressHelper (noWrap);
  80917. sourceStream->setPosition (originalSourcePos);
  80918. }
  80919. skipNextBytes (newPos - currentPos);
  80920. return true;
  80921. }
  80922. END_JUCE_NAMESPACE
  80923. /*** End of inlined file: juce_GZIPDecompressorInputStream.cpp ***/
  80924. #endif
  80925. #if JUCE_BUILD_NATIVE && ! JUCE_ONLY_BUILD_CORE_LIBRARY
  80926. /*** Start of inlined file: juce_FlacAudioFormat.cpp ***/
  80927. #if JUCE_USE_FLAC
  80928. #if JUCE_WINDOWS
  80929. #include <windows.h>
  80930. #endif
  80931. #ifdef _MSC_VER
  80932. #pragma warning (disable : 4505)
  80933. #pragma warning (push)
  80934. #endif
  80935. namespace FlacNamespace
  80936. {
  80937. #if JUCE_INCLUDE_FLAC_CODE
  80938. #define FLAC__NO_DLL 1
  80939. #if ! defined (SIZE_MAX)
  80940. #define SIZE_MAX 0xffffffff
  80941. #endif
  80942. #define __STDC_LIMIT_MACROS 1
  80943. /*** Start of inlined file: all.h ***/
  80944. #ifndef FLAC__ALL_H
  80945. #define FLAC__ALL_H
  80946. /*** Start of inlined file: export.h ***/
  80947. #ifndef FLAC__EXPORT_H
  80948. #define FLAC__EXPORT_H
  80949. #if defined(FLAC__NO_DLL) || !defined(_MSC_VER)
  80950. #define FLAC_API
  80951. #else
  80952. #ifdef FLAC_API_EXPORTS
  80953. #define FLAC_API _declspec(dllexport)
  80954. #else
  80955. #define FLAC_API _declspec(dllimport)
  80956. #endif
  80957. #endif
  80958. #define FLAC_API_VERSION_CURRENT 10
  80959. #define FLAC_API_VERSION_REVISION 0 /**< see above */
  80960. #define FLAC_API_VERSION_AGE 2 /**< see above */
  80961. #ifdef __cplusplus
  80962. extern "C" {
  80963. #endif
  80964. extern FLAC_API int FLAC_API_SUPPORTS_OGG_FLAC;
  80965. #ifdef __cplusplus
  80966. }
  80967. #endif
  80968. #endif
  80969. /*** End of inlined file: export.h ***/
  80970. /*** Start of inlined file: assert.h ***/
  80971. #ifndef FLAC__ASSERT_H
  80972. #define FLAC__ASSERT_H
  80973. /* we need this since some compilers (like MSVC) leave assert()s on release code (and we don't want to use their ASSERT) */
  80974. #ifdef DEBUG
  80975. #include <assert.h>
  80976. #define FLAC__ASSERT(x) assert(x)
  80977. #define FLAC__ASSERT_DECLARATION(x) x
  80978. #else
  80979. #define FLAC__ASSERT(x)
  80980. #define FLAC__ASSERT_DECLARATION(x)
  80981. #endif
  80982. #endif
  80983. /*** End of inlined file: assert.h ***/
  80984. /*** Start of inlined file: callback.h ***/
  80985. #ifndef FLAC__CALLBACK_H
  80986. #define FLAC__CALLBACK_H
  80987. /*** Start of inlined file: ordinals.h ***/
  80988. #ifndef FLAC__ORDINALS_H
  80989. #define FLAC__ORDINALS_H
  80990. #if !(defined(_MSC_VER) || defined(__BORLANDC__) || defined(__EMX__))
  80991. #include <inttypes.h>
  80992. #endif
  80993. typedef signed char FLAC__int8;
  80994. typedef unsigned char FLAC__uint8;
  80995. #if defined(_MSC_VER) || defined(__BORLANDC__)
  80996. typedef __int16 FLAC__int16;
  80997. typedef __int32 FLAC__int32;
  80998. typedef __int64 FLAC__int64;
  80999. typedef unsigned __int16 FLAC__uint16;
  81000. typedef unsigned __int32 FLAC__uint32;
  81001. typedef unsigned __int64 FLAC__uint64;
  81002. #elif defined(__EMX__)
  81003. typedef short FLAC__int16;
  81004. typedef long FLAC__int32;
  81005. typedef long long FLAC__int64;
  81006. typedef unsigned short FLAC__uint16;
  81007. typedef unsigned long FLAC__uint32;
  81008. typedef unsigned long long FLAC__uint64;
  81009. #else
  81010. typedef int16_t FLAC__int16;
  81011. typedef int32_t FLAC__int32;
  81012. typedef int64_t FLAC__int64;
  81013. typedef uint16_t FLAC__uint16;
  81014. typedef uint32_t FLAC__uint32;
  81015. typedef uint64_t FLAC__uint64;
  81016. #endif
  81017. typedef int FLAC__bool;
  81018. typedef FLAC__uint8 FLAC__byte;
  81019. #ifdef true
  81020. #undef true
  81021. #endif
  81022. #ifdef false
  81023. #undef false
  81024. #endif
  81025. #ifndef __cplusplus
  81026. #define true 1
  81027. #define false 0
  81028. #endif
  81029. #endif
  81030. /*** End of inlined file: ordinals.h ***/
  81031. #include <stdlib.h> /* for size_t */
  81032. #ifdef __cplusplus
  81033. extern "C" {
  81034. #endif
  81035. typedef void* FLAC__IOHandle;
  81036. typedef size_t (*FLAC__IOCallback_Read) (void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle);
  81037. typedef size_t (*FLAC__IOCallback_Write) (const void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle);
  81038. typedef int (*FLAC__IOCallback_Seek) (FLAC__IOHandle handle, FLAC__int64 offset, int whence);
  81039. typedef FLAC__int64 (*FLAC__IOCallback_Tell) (FLAC__IOHandle handle);
  81040. typedef int (*FLAC__IOCallback_Eof) (FLAC__IOHandle handle);
  81041. typedef int (*FLAC__IOCallback_Close) (FLAC__IOHandle handle);
  81042. typedef struct {
  81043. FLAC__IOCallback_Read read;
  81044. FLAC__IOCallback_Write write;
  81045. FLAC__IOCallback_Seek seek;
  81046. FLAC__IOCallback_Tell tell;
  81047. FLAC__IOCallback_Eof eof;
  81048. FLAC__IOCallback_Close close;
  81049. } FLAC__IOCallbacks;
  81050. #ifdef __cplusplus
  81051. }
  81052. #endif
  81053. #endif
  81054. /*** End of inlined file: callback.h ***/
  81055. /*** Start of inlined file: format.h ***/
  81056. #ifndef FLAC__FORMAT_H
  81057. #define FLAC__FORMAT_H
  81058. #ifdef __cplusplus
  81059. extern "C" {
  81060. #endif
  81061. #define FLAC__MAX_METADATA_TYPE_CODE (126u)
  81062. #define FLAC__MIN_BLOCK_SIZE (16u)
  81063. #define FLAC__MAX_BLOCK_SIZE (65535u)
  81064. #define FLAC__SUBSET_MAX_BLOCK_SIZE_48000HZ (4608u)
  81065. #define FLAC__MAX_CHANNELS (8u)
  81066. #define FLAC__MIN_BITS_PER_SAMPLE (4u)
  81067. #define FLAC__MAX_BITS_PER_SAMPLE (32u)
  81068. #define FLAC__REFERENCE_CODEC_MAX_BITS_PER_SAMPLE (24u)
  81069. #define FLAC__MAX_SAMPLE_RATE (655350u)
  81070. #define FLAC__MAX_LPC_ORDER (32u)
  81071. #define FLAC__SUBSET_MAX_LPC_ORDER_48000HZ (12u)
  81072. #define FLAC__MIN_QLP_COEFF_PRECISION (5u)
  81073. #define FLAC__MAX_QLP_COEFF_PRECISION (15u)
  81074. #define FLAC__MAX_FIXED_ORDER (4u)
  81075. #define FLAC__MAX_RICE_PARTITION_ORDER (15u)
  81076. #define FLAC__SUBSET_MAX_RICE_PARTITION_ORDER (8u)
  81077. extern FLAC_API const char *FLAC__VERSION_STRING;
  81078. extern FLAC_API const char *FLAC__VENDOR_STRING;
  81079. extern FLAC_API const FLAC__byte FLAC__STREAM_SYNC_STRING[4]; /* = "fLaC" */
  81080. extern FLAC_API const unsigned FLAC__STREAM_SYNC; /* = 0x664C6143 */
  81081. extern FLAC_API const unsigned FLAC__STREAM_SYNC_LEN; /* = 32 bits */
  81082. #define FLAC__STREAM_SYNC_LENGTH (4u)
  81083. typedef enum {
  81084. FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE = 0,
  81085. FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2 = 1
  81086. } FLAC__EntropyCodingMethodType;
  81087. extern FLAC_API const char * const FLAC__EntropyCodingMethodTypeString[];
  81088. typedef struct {
  81089. unsigned *parameters;
  81090. unsigned *raw_bits;
  81091. unsigned capacity_by_order;
  81092. } FLAC__EntropyCodingMethod_PartitionedRiceContents;
  81093. typedef struct {
  81094. unsigned order;
  81095. const FLAC__EntropyCodingMethod_PartitionedRiceContents *contents;
  81096. } FLAC__EntropyCodingMethod_PartitionedRice;
  81097. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN; /**< == 4 (bits) */
  81098. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN; /**< == 4 (bits) */
  81099. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN; /**< == 5 (bits) */
  81100. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN; /**< == 5 (bits) */
  81101. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  81102. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER;
  81103. typedef struct {
  81104. FLAC__EntropyCodingMethodType type;
  81105. union {
  81106. FLAC__EntropyCodingMethod_PartitionedRice partitioned_rice;
  81107. } data;
  81108. } FLAC__EntropyCodingMethod;
  81109. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_TYPE_LEN; /**< == 2 (bits) */
  81110. typedef enum {
  81111. FLAC__SUBFRAME_TYPE_CONSTANT = 0, /**< constant signal */
  81112. FLAC__SUBFRAME_TYPE_VERBATIM = 1, /**< uncompressed signal */
  81113. FLAC__SUBFRAME_TYPE_FIXED = 2, /**< fixed polynomial prediction */
  81114. FLAC__SUBFRAME_TYPE_LPC = 3 /**< linear prediction */
  81115. } FLAC__SubframeType;
  81116. extern FLAC_API const char * const FLAC__SubframeTypeString[];
  81117. typedef struct {
  81118. FLAC__int32 value; /**< The constant signal value. */
  81119. } FLAC__Subframe_Constant;
  81120. typedef struct {
  81121. const FLAC__int32 *data; /**< A pointer to verbatim signal. */
  81122. } FLAC__Subframe_Verbatim;
  81123. typedef struct {
  81124. FLAC__EntropyCodingMethod entropy_coding_method;
  81125. unsigned order;
  81126. FLAC__int32 warmup[FLAC__MAX_FIXED_ORDER];
  81127. const FLAC__int32 *residual;
  81128. } FLAC__Subframe_Fixed;
  81129. typedef struct {
  81130. FLAC__EntropyCodingMethod entropy_coding_method;
  81131. unsigned order;
  81132. unsigned qlp_coeff_precision;
  81133. int quantization_level;
  81134. FLAC__int32 qlp_coeff[FLAC__MAX_LPC_ORDER];
  81135. FLAC__int32 warmup[FLAC__MAX_LPC_ORDER];
  81136. const FLAC__int32 *residual;
  81137. } FLAC__Subframe_LPC;
  81138. extern FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN; /**< == 4 (bits) */
  81139. extern FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN; /**< == 5 (bits) */
  81140. typedef struct {
  81141. FLAC__SubframeType type;
  81142. union {
  81143. FLAC__Subframe_Constant constant;
  81144. FLAC__Subframe_Fixed fixed;
  81145. FLAC__Subframe_LPC lpc;
  81146. FLAC__Subframe_Verbatim verbatim;
  81147. } data;
  81148. unsigned wasted_bits;
  81149. } FLAC__Subframe;
  81150. extern FLAC_API const unsigned FLAC__SUBFRAME_ZERO_PAD_LEN;
  81151. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LEN; /**< == 6 (bits) */
  81152. extern FLAC_API const unsigned FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN; /**< == 1 (bit) */
  81153. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_CONSTANT_BYTE_ALIGNED_MASK; /**< = 0x00 */
  81154. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_VERBATIM_BYTE_ALIGNED_MASK; /**< = 0x02 */
  81155. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK; /**< = 0x10 */
  81156. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LPC_BYTE_ALIGNED_MASK; /**< = 0x40 */
  81157. typedef enum {
  81158. FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT = 0, /**< independent channels */
  81159. FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE = 1, /**< left+side stereo */
  81160. FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE = 2, /**< right+side stereo */
  81161. FLAC__CHANNEL_ASSIGNMENT_MID_SIDE = 3 /**< mid+side stereo */
  81162. } FLAC__ChannelAssignment;
  81163. extern FLAC_API const char * const FLAC__ChannelAssignmentString[];
  81164. typedef enum {
  81165. FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER, /**< number contains the frame number */
  81166. FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER /**< number contains the sample number of first sample in frame */
  81167. } FLAC__FrameNumberType;
  81168. extern FLAC_API const char * const FLAC__FrameNumberTypeString[];
  81169. typedef struct {
  81170. unsigned blocksize;
  81171. unsigned sample_rate;
  81172. unsigned channels;
  81173. FLAC__ChannelAssignment channel_assignment;
  81174. unsigned bits_per_sample;
  81175. FLAC__FrameNumberType number_type;
  81176. union {
  81177. FLAC__uint32 frame_number;
  81178. FLAC__uint64 sample_number;
  81179. } number;
  81180. FLAC__uint8 crc;
  81181. } FLAC__FrameHeader;
  81182. extern FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC; /**< == 0x3ffe; the frame header sync code */
  81183. extern FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC_LEN; /**< == 14 (bits) */
  81184. extern FLAC_API const unsigned FLAC__FRAME_HEADER_RESERVED_LEN; /**< == 1 (bits) */
  81185. extern FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN; /**< == 1 (bits) */
  81186. extern FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCK_SIZE_LEN; /**< == 4 (bits) */
  81187. extern FLAC_API const unsigned FLAC__FRAME_HEADER_SAMPLE_RATE_LEN; /**< == 4 (bits) */
  81188. extern FLAC_API const unsigned FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN; /**< == 4 (bits) */
  81189. extern FLAC_API const unsigned FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN; /**< == 3 (bits) */
  81190. extern FLAC_API const unsigned FLAC__FRAME_HEADER_ZERO_PAD_LEN; /**< == 1 (bit) */
  81191. extern FLAC_API const unsigned FLAC__FRAME_HEADER_CRC_LEN; /**< == 8 (bits) */
  81192. typedef struct {
  81193. FLAC__uint16 crc;
  81194. } FLAC__FrameFooter;
  81195. extern FLAC_API const unsigned FLAC__FRAME_FOOTER_CRC_LEN; /**< == 16 (bits) */
  81196. typedef struct {
  81197. FLAC__FrameHeader header;
  81198. FLAC__Subframe subframes[FLAC__MAX_CHANNELS];
  81199. FLAC__FrameFooter footer;
  81200. } FLAC__Frame;
  81201. typedef enum {
  81202. FLAC__METADATA_TYPE_STREAMINFO = 0,
  81203. FLAC__METADATA_TYPE_PADDING = 1,
  81204. FLAC__METADATA_TYPE_APPLICATION = 2,
  81205. FLAC__METADATA_TYPE_SEEKTABLE = 3,
  81206. FLAC__METADATA_TYPE_VORBIS_COMMENT = 4,
  81207. FLAC__METADATA_TYPE_CUESHEET = 5,
  81208. FLAC__METADATA_TYPE_PICTURE = 6,
  81209. FLAC__METADATA_TYPE_UNDEFINED = 7
  81210. } FLAC__MetadataType;
  81211. extern FLAC_API const char * const FLAC__MetadataTypeString[];
  81212. typedef struct {
  81213. unsigned min_blocksize, max_blocksize;
  81214. unsigned min_framesize, max_framesize;
  81215. unsigned sample_rate;
  81216. unsigned channels;
  81217. unsigned bits_per_sample;
  81218. FLAC__uint64 total_samples;
  81219. FLAC__byte md5sum[16];
  81220. } FLAC__StreamMetadata_StreamInfo;
  81221. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN; /**< == 16 (bits) */
  81222. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN; /**< == 16 (bits) */
  81223. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN; /**< == 24 (bits) */
  81224. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN; /**< == 24 (bits) */
  81225. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN; /**< == 20 (bits) */
  81226. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN; /**< == 3 (bits) */
  81227. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN; /**< == 5 (bits) */
  81228. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN; /**< == 36 (bits) */
  81229. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MD5SUM_LEN; /**< == 128 (bits) */
  81230. #define FLAC__STREAM_METADATA_STREAMINFO_LENGTH (34u)
  81231. typedef struct {
  81232. int dummy;
  81233. } FLAC__StreamMetadata_Padding;
  81234. typedef struct {
  81235. FLAC__byte id[4];
  81236. FLAC__byte *data;
  81237. } FLAC__StreamMetadata_Application;
  81238. extern FLAC_API const unsigned FLAC__STREAM_METADATA_APPLICATION_ID_LEN; /**< == 32 (bits) */
  81239. typedef struct {
  81240. FLAC__uint64 sample_number;
  81241. FLAC__uint64 stream_offset;
  81242. unsigned frame_samples;
  81243. } FLAC__StreamMetadata_SeekPoint;
  81244. extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN; /**< == 64 (bits) */
  81245. extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN; /**< == 64 (bits) */
  81246. extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN; /**< == 16 (bits) */
  81247. #define FLAC__STREAM_METADATA_SEEKPOINT_LENGTH (18u)
  81248. extern FLAC_API const FLAC__uint64 FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
  81249. typedef struct {
  81250. unsigned num_points;
  81251. FLAC__StreamMetadata_SeekPoint *points;
  81252. } FLAC__StreamMetadata_SeekTable;
  81253. typedef struct {
  81254. FLAC__uint32 length;
  81255. FLAC__byte *entry;
  81256. } FLAC__StreamMetadata_VorbisComment_Entry;
  81257. extern FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN; /**< == 32 (bits) */
  81258. typedef struct {
  81259. FLAC__StreamMetadata_VorbisComment_Entry vendor_string;
  81260. FLAC__uint32 num_comments;
  81261. FLAC__StreamMetadata_VorbisComment_Entry *comments;
  81262. } FLAC__StreamMetadata_VorbisComment;
  81263. extern FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN; /**< == 32 (bits) */
  81264. typedef struct {
  81265. FLAC__uint64 offset;
  81266. FLAC__byte number;
  81267. } FLAC__StreamMetadata_CueSheet_Index;
  81268. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN; /**< == 64 (bits) */
  81269. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN; /**< == 8 (bits) */
  81270. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN; /**< == 3*8 (bits) */
  81271. typedef struct {
  81272. FLAC__uint64 offset;
  81273. FLAC__byte number;
  81274. char isrc[13];
  81275. unsigned type:1;
  81276. unsigned pre_emphasis:1;
  81277. FLAC__byte num_indices;
  81278. FLAC__StreamMetadata_CueSheet_Index *indices;
  81279. } FLAC__StreamMetadata_CueSheet_Track;
  81280. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN; /**< == 64 (bits) */
  81281. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN; /**< == 8 (bits) */
  81282. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN; /**< == 12*8 (bits) */
  81283. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN; /**< == 1 (bit) */
  81284. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN; /**< == 1 (bit) */
  81285. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN; /**< == 6+13*8 (bits) */
  81286. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN; /**< == 8 (bits) */
  81287. typedef struct {
  81288. char media_catalog_number[129];
  81289. FLAC__uint64 lead_in;
  81290. FLAC__bool is_cd;
  81291. unsigned num_tracks;
  81292. FLAC__StreamMetadata_CueSheet_Track *tracks;
  81293. } FLAC__StreamMetadata_CueSheet;
  81294. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN; /**< == 128*8 (bits) */
  81295. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN; /**< == 64 (bits) */
  81296. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN; /**< == 1 (bit) */
  81297. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN; /**< == 7+258*8 (bits) */
  81298. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN; /**< == 8 (bits) */
  81299. typedef enum {
  81300. FLAC__STREAM_METADATA_PICTURE_TYPE_OTHER = 0, /**< Other */
  81301. FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD = 1, /**< 32x32 pixels 'file icon' (PNG only) */
  81302. FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON = 2, /**< Other file icon */
  81303. FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER = 3, /**< Cover (front) */
  81304. FLAC__STREAM_METADATA_PICTURE_TYPE_BACK_COVER = 4, /**< Cover (back) */
  81305. FLAC__STREAM_METADATA_PICTURE_TYPE_LEAFLET_PAGE = 5, /**< Leaflet page */
  81306. FLAC__STREAM_METADATA_PICTURE_TYPE_MEDIA = 6, /**< Media (e.g. label side of CD) */
  81307. FLAC__STREAM_METADATA_PICTURE_TYPE_LEAD_ARTIST = 7, /**< Lead artist/lead performer/soloist */
  81308. FLAC__STREAM_METADATA_PICTURE_TYPE_ARTIST = 8, /**< Artist/performer */
  81309. FLAC__STREAM_METADATA_PICTURE_TYPE_CONDUCTOR = 9, /**< Conductor */
  81310. FLAC__STREAM_METADATA_PICTURE_TYPE_BAND = 10, /**< Band/Orchestra */
  81311. FLAC__STREAM_METADATA_PICTURE_TYPE_COMPOSER = 11, /**< Composer */
  81312. FLAC__STREAM_METADATA_PICTURE_TYPE_LYRICIST = 12, /**< Lyricist/text writer */
  81313. FLAC__STREAM_METADATA_PICTURE_TYPE_RECORDING_LOCATION = 13, /**< Recording Location */
  81314. FLAC__STREAM_METADATA_PICTURE_TYPE_DURING_RECORDING = 14, /**< During recording */
  81315. FLAC__STREAM_METADATA_PICTURE_TYPE_DURING_PERFORMANCE = 15, /**< During performance */
  81316. FLAC__STREAM_METADATA_PICTURE_TYPE_VIDEO_SCREEN_CAPTURE = 16, /**< Movie/video screen capture */
  81317. FLAC__STREAM_METADATA_PICTURE_TYPE_FISH = 17, /**< A bright coloured fish */
  81318. FLAC__STREAM_METADATA_PICTURE_TYPE_ILLUSTRATION = 18, /**< Illustration */
  81319. FLAC__STREAM_METADATA_PICTURE_TYPE_BAND_LOGOTYPE = 19, /**< Band/artist logotype */
  81320. FLAC__STREAM_METADATA_PICTURE_TYPE_PUBLISHER_LOGOTYPE = 20, /**< Publisher/Studio logotype */
  81321. FLAC__STREAM_METADATA_PICTURE_TYPE_UNDEFINED
  81322. } FLAC__StreamMetadata_Picture_Type;
  81323. extern FLAC_API const char * const FLAC__StreamMetadata_Picture_TypeString[];
  81324. typedef struct {
  81325. FLAC__StreamMetadata_Picture_Type type;
  81326. char *mime_type;
  81327. FLAC__byte *description;
  81328. FLAC__uint32 width;
  81329. FLAC__uint32 height;
  81330. FLAC__uint32 depth;
  81331. FLAC__uint32 colors;
  81332. FLAC__uint32 data_length;
  81333. FLAC__byte *data;
  81334. } FLAC__StreamMetadata_Picture;
  81335. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_TYPE_LEN; /**< == 32 (bits) */
  81336. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN; /**< == 32 (bits) */
  81337. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN; /**< == 32 (bits) */
  81338. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN; /**< == 32 (bits) */
  81339. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN; /**< == 32 (bits) */
  81340. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN; /**< == 32 (bits) */
  81341. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_COLORS_LEN; /**< == 32 (bits) */
  81342. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN; /**< == 32 (bits) */
  81343. typedef struct {
  81344. FLAC__byte *data;
  81345. } FLAC__StreamMetadata_Unknown;
  81346. typedef struct {
  81347. FLAC__MetadataType type;
  81348. FLAC__bool is_last;
  81349. unsigned length;
  81350. union {
  81351. FLAC__StreamMetadata_StreamInfo stream_info;
  81352. FLAC__StreamMetadata_Padding padding;
  81353. FLAC__StreamMetadata_Application application;
  81354. FLAC__StreamMetadata_SeekTable seek_table;
  81355. FLAC__StreamMetadata_VorbisComment vorbis_comment;
  81356. FLAC__StreamMetadata_CueSheet cue_sheet;
  81357. FLAC__StreamMetadata_Picture picture;
  81358. FLAC__StreamMetadata_Unknown unknown;
  81359. } data;
  81360. } FLAC__StreamMetadata;
  81361. extern FLAC_API const unsigned FLAC__STREAM_METADATA_IS_LAST_LEN; /**< == 1 (bit) */
  81362. extern FLAC_API const unsigned FLAC__STREAM_METADATA_TYPE_LEN; /**< == 7 (bits) */
  81363. extern FLAC_API const unsigned FLAC__STREAM_METADATA_LENGTH_LEN; /**< == 24 (bits) */
  81364. #define FLAC__STREAM_METADATA_HEADER_LENGTH (4u)
  81365. FLAC_API FLAC__bool FLAC__format_sample_rate_is_valid(unsigned sample_rate);
  81366. FLAC_API FLAC__bool FLAC__format_sample_rate_is_subset(unsigned sample_rate);
  81367. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_name_is_legal(const char *name);
  81368. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_value_is_legal(const FLAC__byte *value, unsigned length);
  81369. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_is_legal(const FLAC__byte *entry, unsigned length);
  81370. FLAC_API FLAC__bool FLAC__format_seektable_is_legal(const FLAC__StreamMetadata_SeekTable *seek_table);
  81371. FLAC_API unsigned FLAC__format_seektable_sort(FLAC__StreamMetadata_SeekTable *seek_table);
  81372. FLAC_API FLAC__bool FLAC__format_cuesheet_is_legal(const FLAC__StreamMetadata_CueSheet *cue_sheet, FLAC__bool check_cd_da_subset, const char **violation);
  81373. FLAC_API FLAC__bool FLAC__format_picture_is_legal(const FLAC__StreamMetadata_Picture *picture, const char **violation);
  81374. #ifdef __cplusplus
  81375. }
  81376. #endif
  81377. #endif
  81378. /*** End of inlined file: format.h ***/
  81379. /*** Start of inlined file: metadata.h ***/
  81380. #ifndef FLAC__METADATA_H
  81381. #define FLAC__METADATA_H
  81382. #include <sys/types.h> /* for off_t */
  81383. #ifdef __cplusplus
  81384. extern "C" {
  81385. #endif
  81386. FLAC_API FLAC__bool FLAC__metadata_get_streaminfo(const char *filename, FLAC__StreamMetadata *streaminfo);
  81387. FLAC_API FLAC__bool FLAC__metadata_get_tags(const char *filename, FLAC__StreamMetadata **tags);
  81388. FLAC_API FLAC__bool FLAC__metadata_get_cuesheet(const char *filename, FLAC__StreamMetadata **cuesheet);
  81389. 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);
  81390. struct FLAC__Metadata_SimpleIterator;
  81391. typedef struct FLAC__Metadata_SimpleIterator FLAC__Metadata_SimpleIterator;
  81392. typedef enum {
  81393. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK = 0,
  81394. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ILLEGAL_INPUT,
  81395. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ERROR_OPENING_FILE,
  81396. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_A_FLAC_FILE,
  81397. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_WRITABLE,
  81398. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_BAD_METADATA,
  81399. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR,
  81400. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR,
  81401. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR,
  81402. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_RENAME_ERROR,
  81403. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_UNLINK_ERROR,
  81404. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR,
  81405. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_INTERNAL_ERROR
  81406. } FLAC__Metadata_SimpleIteratorStatus;
  81407. extern FLAC_API const char * const FLAC__Metadata_SimpleIteratorStatusString[];
  81408. FLAC_API FLAC__Metadata_SimpleIterator *FLAC__metadata_simple_iterator_new(void);
  81409. FLAC_API void FLAC__metadata_simple_iterator_delete(FLAC__Metadata_SimpleIterator *iterator);
  81410. FLAC_API FLAC__Metadata_SimpleIteratorStatus FLAC__metadata_simple_iterator_status(FLAC__Metadata_SimpleIterator *iterator);
  81411. 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);
  81412. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_is_writable(const FLAC__Metadata_SimpleIterator *iterator);
  81413. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_next(FLAC__Metadata_SimpleIterator *iterator);
  81414. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_prev(FLAC__Metadata_SimpleIterator *iterator);
  81415. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_is_last(const FLAC__Metadata_SimpleIterator *iterator);
  81416. FLAC_API off_t FLAC__metadata_simple_iterator_get_block_offset(const FLAC__Metadata_SimpleIterator *iterator);
  81417. FLAC_API FLAC__MetadataType FLAC__metadata_simple_iterator_get_block_type(const FLAC__Metadata_SimpleIterator *iterator);
  81418. FLAC_API unsigned FLAC__metadata_simple_iterator_get_block_length(const FLAC__Metadata_SimpleIterator *iterator);
  81419. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_get_application_id(FLAC__Metadata_SimpleIterator *iterator, FLAC__byte *id);
  81420. FLAC_API FLAC__StreamMetadata *FLAC__metadata_simple_iterator_get_block(FLAC__Metadata_SimpleIterator *iterator);
  81421. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_set_block(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool use_padding);
  81422. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_insert_block_after(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool use_padding);
  81423. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_delete_block(FLAC__Metadata_SimpleIterator *iterator, FLAC__bool use_padding);
  81424. struct FLAC__Metadata_Chain;
  81425. typedef struct FLAC__Metadata_Chain FLAC__Metadata_Chain;
  81426. struct FLAC__Metadata_Iterator;
  81427. typedef struct FLAC__Metadata_Iterator FLAC__Metadata_Iterator;
  81428. typedef enum {
  81429. FLAC__METADATA_CHAIN_STATUS_OK = 0,
  81430. FLAC__METADATA_CHAIN_STATUS_ILLEGAL_INPUT,
  81431. FLAC__METADATA_CHAIN_STATUS_ERROR_OPENING_FILE,
  81432. FLAC__METADATA_CHAIN_STATUS_NOT_A_FLAC_FILE,
  81433. FLAC__METADATA_CHAIN_STATUS_NOT_WRITABLE,
  81434. FLAC__METADATA_CHAIN_STATUS_BAD_METADATA,
  81435. FLAC__METADATA_CHAIN_STATUS_READ_ERROR,
  81436. FLAC__METADATA_CHAIN_STATUS_SEEK_ERROR,
  81437. FLAC__METADATA_CHAIN_STATUS_WRITE_ERROR,
  81438. FLAC__METADATA_CHAIN_STATUS_RENAME_ERROR,
  81439. FLAC__METADATA_CHAIN_STATUS_UNLINK_ERROR,
  81440. FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR,
  81441. FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR,
  81442. FLAC__METADATA_CHAIN_STATUS_INVALID_CALLBACKS,
  81443. FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH,
  81444. FLAC__METADATA_CHAIN_STATUS_WRONG_WRITE_CALL
  81445. } FLAC__Metadata_ChainStatus;
  81446. extern FLAC_API const char * const FLAC__Metadata_ChainStatusString[];
  81447. FLAC_API FLAC__Metadata_Chain *FLAC__metadata_chain_new(void);
  81448. FLAC_API void FLAC__metadata_chain_delete(FLAC__Metadata_Chain *chain);
  81449. FLAC_API FLAC__Metadata_ChainStatus FLAC__metadata_chain_status(FLAC__Metadata_Chain *chain);
  81450. FLAC_API FLAC__bool FLAC__metadata_chain_read(FLAC__Metadata_Chain *chain, const char *filename);
  81451. FLAC_API FLAC__bool FLAC__metadata_chain_read_ogg(FLAC__Metadata_Chain *chain, const char *filename);
  81452. FLAC_API FLAC__bool FLAC__metadata_chain_read_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
  81453. FLAC_API FLAC__bool FLAC__metadata_chain_read_ogg_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
  81454. FLAC_API FLAC__bool FLAC__metadata_chain_check_if_tempfile_needed(FLAC__Metadata_Chain *chain, FLAC__bool use_padding);
  81455. FLAC_API FLAC__bool FLAC__metadata_chain_write(FLAC__Metadata_Chain *chain, FLAC__bool use_padding, FLAC__bool preserve_file_stats);
  81456. FLAC_API FLAC__bool FLAC__metadata_chain_write_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__bool use_padding, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
  81457. 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);
  81458. FLAC_API void FLAC__metadata_chain_merge_padding(FLAC__Metadata_Chain *chain);
  81459. FLAC_API void FLAC__metadata_chain_sort_padding(FLAC__Metadata_Chain *chain);
  81460. FLAC_API FLAC__Metadata_Iterator *FLAC__metadata_iterator_new(void);
  81461. FLAC_API void FLAC__metadata_iterator_delete(FLAC__Metadata_Iterator *iterator);
  81462. FLAC_API void FLAC__metadata_iterator_init(FLAC__Metadata_Iterator *iterator, FLAC__Metadata_Chain *chain);
  81463. FLAC_API FLAC__bool FLAC__metadata_iterator_next(FLAC__Metadata_Iterator *iterator);
  81464. FLAC_API FLAC__bool FLAC__metadata_iterator_prev(FLAC__Metadata_Iterator *iterator);
  81465. FLAC_API FLAC__MetadataType FLAC__metadata_iterator_get_block_type(const FLAC__Metadata_Iterator *iterator);
  81466. FLAC_API FLAC__StreamMetadata *FLAC__metadata_iterator_get_block(FLAC__Metadata_Iterator *iterator);
  81467. FLAC_API FLAC__bool FLAC__metadata_iterator_set_block(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
  81468. FLAC_API FLAC__bool FLAC__metadata_iterator_delete_block(FLAC__Metadata_Iterator *iterator, FLAC__bool replace_with_padding);
  81469. FLAC_API FLAC__bool FLAC__metadata_iterator_insert_block_before(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
  81470. FLAC_API FLAC__bool FLAC__metadata_iterator_insert_block_after(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
  81471. FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_new(FLAC__MetadataType type);
  81472. FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_clone(const FLAC__StreamMetadata *object);
  81473. FLAC_API void FLAC__metadata_object_delete(FLAC__StreamMetadata *object);
  81474. FLAC_API FLAC__bool FLAC__metadata_object_is_equal(const FLAC__StreamMetadata *block1, const FLAC__StreamMetadata *block2);
  81475. FLAC_API FLAC__bool FLAC__metadata_object_application_set_data(FLAC__StreamMetadata *object, FLAC__byte *data, unsigned length, FLAC__bool copy);
  81476. FLAC_API FLAC__bool FLAC__metadata_object_seektable_resize_points(FLAC__StreamMetadata *object, unsigned new_num_points);
  81477. FLAC_API void FLAC__metadata_object_seektable_set_point(FLAC__StreamMetadata *object, unsigned point_num, FLAC__StreamMetadata_SeekPoint point);
  81478. FLAC_API FLAC__bool FLAC__metadata_object_seektable_insert_point(FLAC__StreamMetadata *object, unsigned point_num, FLAC__StreamMetadata_SeekPoint point);
  81479. FLAC_API FLAC__bool FLAC__metadata_object_seektable_delete_point(FLAC__StreamMetadata *object, unsigned point_num);
  81480. FLAC_API FLAC__bool FLAC__metadata_object_seektable_is_legal(const FLAC__StreamMetadata *object);
  81481. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_placeholders(FLAC__StreamMetadata *object, unsigned num);
  81482. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_point(FLAC__StreamMetadata *object, FLAC__uint64 sample_number);
  81483. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_points(FLAC__StreamMetadata *object, FLAC__uint64 sample_numbers[], unsigned num);
  81484. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points(FLAC__StreamMetadata *object, unsigned num, FLAC__uint64 total_samples);
  81485. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points_by_samples(FLAC__StreamMetadata *object, unsigned samples, FLAC__uint64 total_samples);
  81486. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_sort(FLAC__StreamMetadata *object, FLAC__bool compact);
  81487. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_set_vendor_string(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  81488. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_resize_comments(FLAC__StreamMetadata *object, unsigned new_num_comments);
  81489. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_set_comment(FLAC__StreamMetadata *object, unsigned comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  81490. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_insert_comment(FLAC__StreamMetadata *object, unsigned comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  81491. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_append_comment(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  81492. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_replace_comment(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool all, FLAC__bool copy);
  81493. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_delete_comment(FLAC__StreamMetadata *object, unsigned comment_num);
  81494. 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);
  81495. 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);
  81496. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_entry_matches(const FLAC__StreamMetadata_VorbisComment_Entry entry, const char *field_name, unsigned field_name_length);
  81497. FLAC_API int FLAC__metadata_object_vorbiscomment_find_entry_from(const FLAC__StreamMetadata *object, unsigned offset, const char *field_name);
  81498. FLAC_API int FLAC__metadata_object_vorbiscomment_remove_entry_matching(FLAC__StreamMetadata *object, const char *field_name);
  81499. FLAC_API int FLAC__metadata_object_vorbiscomment_remove_entries_matching(FLAC__StreamMetadata *object, const char *field_name);
  81500. FLAC_API FLAC__StreamMetadata_CueSheet_Track *FLAC__metadata_object_cuesheet_track_new(void);
  81501. FLAC_API FLAC__StreamMetadata_CueSheet_Track *FLAC__metadata_object_cuesheet_track_clone(const FLAC__StreamMetadata_CueSheet_Track *object);
  81502. FLAC_API void FLAC__metadata_object_cuesheet_track_delete(FLAC__StreamMetadata_CueSheet_Track *object);
  81503. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_resize_indices(FLAC__StreamMetadata *object, unsigned track_num, unsigned new_num_indices);
  81504. 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);
  81505. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_insert_blank_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num);
  81506. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_delete_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num);
  81507. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_resize_tracks(FLAC__StreamMetadata *object, unsigned new_num_tracks);
  81508. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_set_track(FLAC__StreamMetadata *object, unsigned track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy);
  81509. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_track(FLAC__StreamMetadata *object, unsigned track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy);
  81510. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_blank_track(FLAC__StreamMetadata *object, unsigned track_num);
  81511. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_delete_track(FLAC__StreamMetadata *object, unsigned track_num);
  81512. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_is_legal(const FLAC__StreamMetadata *object, FLAC__bool check_cd_da_subset, const char **violation);
  81513. FLAC_API FLAC__uint32 FLAC__metadata_object_cuesheet_calculate_cddb_id(const FLAC__StreamMetadata *object);
  81514. FLAC_API FLAC__bool FLAC__metadata_object_picture_set_mime_type(FLAC__StreamMetadata *object, char *mime_type, FLAC__bool copy);
  81515. FLAC_API FLAC__bool FLAC__metadata_object_picture_set_description(FLAC__StreamMetadata *object, FLAC__byte *description, FLAC__bool copy);
  81516. FLAC_API FLAC__bool FLAC__metadata_object_picture_set_data(FLAC__StreamMetadata *object, FLAC__byte *data, FLAC__uint32 length, FLAC__bool copy);
  81517. FLAC_API FLAC__bool FLAC__metadata_object_picture_is_legal(const FLAC__StreamMetadata *object, const char **violation);
  81518. #ifdef __cplusplus
  81519. }
  81520. #endif
  81521. #endif
  81522. /*** End of inlined file: metadata.h ***/
  81523. /*** Start of inlined file: stream_decoder.h ***/
  81524. #ifndef FLAC__STREAM_DECODER_H
  81525. #define FLAC__STREAM_DECODER_H
  81526. #include <stdio.h> /* for FILE */
  81527. #ifdef __cplusplus
  81528. extern "C" {
  81529. #endif
  81530. typedef enum {
  81531. FLAC__STREAM_DECODER_SEARCH_FOR_METADATA = 0,
  81532. FLAC__STREAM_DECODER_READ_METADATA,
  81533. FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC,
  81534. FLAC__STREAM_DECODER_READ_FRAME,
  81535. FLAC__STREAM_DECODER_END_OF_STREAM,
  81536. FLAC__STREAM_DECODER_OGG_ERROR,
  81537. FLAC__STREAM_DECODER_SEEK_ERROR,
  81538. FLAC__STREAM_DECODER_ABORTED,
  81539. FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR,
  81540. FLAC__STREAM_DECODER_UNINITIALIZED
  81541. } FLAC__StreamDecoderState;
  81542. extern FLAC_API const char * const FLAC__StreamDecoderStateString[];
  81543. typedef enum {
  81544. FLAC__STREAM_DECODER_INIT_STATUS_OK = 0,
  81545. FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER,
  81546. FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS,
  81547. FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR,
  81548. FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE,
  81549. FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED
  81550. } FLAC__StreamDecoderInitStatus;
  81551. extern FLAC_API const char * const FLAC__StreamDecoderInitStatusString[];
  81552. typedef enum {
  81553. FLAC__STREAM_DECODER_READ_STATUS_CONTINUE,
  81554. FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM,
  81555. FLAC__STREAM_DECODER_READ_STATUS_ABORT
  81556. } FLAC__StreamDecoderReadStatus;
  81557. extern FLAC_API const char * const FLAC__StreamDecoderReadStatusString[];
  81558. typedef enum {
  81559. FLAC__STREAM_DECODER_SEEK_STATUS_OK,
  81560. FLAC__STREAM_DECODER_SEEK_STATUS_ERROR,
  81561. FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED
  81562. } FLAC__StreamDecoderSeekStatus;
  81563. extern FLAC_API const char * const FLAC__StreamDecoderSeekStatusString[];
  81564. typedef enum {
  81565. FLAC__STREAM_DECODER_TELL_STATUS_OK,
  81566. FLAC__STREAM_DECODER_TELL_STATUS_ERROR,
  81567. FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED
  81568. } FLAC__StreamDecoderTellStatus;
  81569. extern FLAC_API const char * const FLAC__StreamDecoderTellStatusString[];
  81570. typedef enum {
  81571. FLAC__STREAM_DECODER_LENGTH_STATUS_OK,
  81572. FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR,
  81573. FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED
  81574. } FLAC__StreamDecoderLengthStatus;
  81575. extern FLAC_API const char * const FLAC__StreamDecoderLengthStatusString[];
  81576. typedef enum {
  81577. FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE,
  81578. FLAC__STREAM_DECODER_WRITE_STATUS_ABORT
  81579. } FLAC__StreamDecoderWriteStatus;
  81580. extern FLAC_API const char * const FLAC__StreamDecoderWriteStatusString[];
  81581. typedef enum {
  81582. FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC,
  81583. FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER,
  81584. FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH,
  81585. FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM
  81586. } FLAC__StreamDecoderErrorStatus;
  81587. extern FLAC_API const char * const FLAC__StreamDecoderErrorStatusString[];
  81588. struct FLAC__StreamDecoderProtected;
  81589. struct FLAC__StreamDecoderPrivate;
  81590. typedef struct {
  81591. struct FLAC__StreamDecoderProtected *protected_; /* avoid the C++ keyword 'protected' */
  81592. struct FLAC__StreamDecoderPrivate *private_; /* avoid the C++ keyword 'private' */
  81593. } FLAC__StreamDecoder;
  81594. typedef FLAC__StreamDecoderReadStatus (*FLAC__StreamDecoderReadCallback)(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  81595. typedef FLAC__StreamDecoderSeekStatus (*FLAC__StreamDecoderSeekCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  81596. typedef FLAC__StreamDecoderTellStatus (*FLAC__StreamDecoderTellCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  81597. typedef FLAC__StreamDecoderLengthStatus (*FLAC__StreamDecoderLengthCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
  81598. typedef FLAC__bool (*FLAC__StreamDecoderEofCallback)(const FLAC__StreamDecoder *decoder, void *client_data);
  81599. typedef FLAC__StreamDecoderWriteStatus (*FLAC__StreamDecoderWriteCallback)(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
  81600. typedef void (*FLAC__StreamDecoderMetadataCallback)(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
  81601. typedef void (*FLAC__StreamDecoderErrorCallback)(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
  81602. FLAC_API FLAC__StreamDecoder *FLAC__stream_decoder_new(void);
  81603. FLAC_API void FLAC__stream_decoder_delete(FLAC__StreamDecoder *decoder);
  81604. FLAC_API FLAC__bool FLAC__stream_decoder_set_ogg_serial_number(FLAC__StreamDecoder *decoder, long serial_number);
  81605. FLAC_API FLAC__bool FLAC__stream_decoder_set_md5_checking(FLAC__StreamDecoder *decoder, FLAC__bool value);
  81606. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond(FLAC__StreamDecoder *decoder, FLAC__MetadataType type);
  81607. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4]);
  81608. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_all(FLAC__StreamDecoder *decoder);
  81609. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore(FLAC__StreamDecoder *decoder, FLAC__MetadataType type);
  81610. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4]);
  81611. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_all(FLAC__StreamDecoder *decoder);
  81612. FLAC_API FLAC__StreamDecoderState FLAC__stream_decoder_get_state(const FLAC__StreamDecoder *decoder);
  81613. FLAC_API const char *FLAC__stream_decoder_get_resolved_state_string(const FLAC__StreamDecoder *decoder);
  81614. FLAC_API FLAC__bool FLAC__stream_decoder_get_md5_checking(const FLAC__StreamDecoder *decoder);
  81615. FLAC_API FLAC__uint64 FLAC__stream_decoder_get_total_samples(const FLAC__StreamDecoder *decoder);
  81616. FLAC_API unsigned FLAC__stream_decoder_get_channels(const FLAC__StreamDecoder *decoder);
  81617. FLAC_API FLAC__ChannelAssignment FLAC__stream_decoder_get_channel_assignment(const FLAC__StreamDecoder *decoder);
  81618. FLAC_API unsigned FLAC__stream_decoder_get_bits_per_sample(const FLAC__StreamDecoder *decoder);
  81619. FLAC_API unsigned FLAC__stream_decoder_get_sample_rate(const FLAC__StreamDecoder *decoder);
  81620. FLAC_API unsigned FLAC__stream_decoder_get_blocksize(const FLAC__StreamDecoder *decoder);
  81621. FLAC_API FLAC__bool FLAC__stream_decoder_get_decode_position(const FLAC__StreamDecoder *decoder, FLAC__uint64 *position);
  81622. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_stream(
  81623. FLAC__StreamDecoder *decoder,
  81624. FLAC__StreamDecoderReadCallback read_callback,
  81625. FLAC__StreamDecoderSeekCallback seek_callback,
  81626. FLAC__StreamDecoderTellCallback tell_callback,
  81627. FLAC__StreamDecoderLengthCallback length_callback,
  81628. FLAC__StreamDecoderEofCallback eof_callback,
  81629. FLAC__StreamDecoderWriteCallback write_callback,
  81630. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81631. FLAC__StreamDecoderErrorCallback error_callback,
  81632. void *client_data
  81633. );
  81634. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_stream(
  81635. FLAC__StreamDecoder *decoder,
  81636. FLAC__StreamDecoderReadCallback read_callback,
  81637. FLAC__StreamDecoderSeekCallback seek_callback,
  81638. FLAC__StreamDecoderTellCallback tell_callback,
  81639. FLAC__StreamDecoderLengthCallback length_callback,
  81640. FLAC__StreamDecoderEofCallback eof_callback,
  81641. FLAC__StreamDecoderWriteCallback write_callback,
  81642. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81643. FLAC__StreamDecoderErrorCallback error_callback,
  81644. void *client_data
  81645. );
  81646. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_FILE(
  81647. FLAC__StreamDecoder *decoder,
  81648. FILE *file,
  81649. FLAC__StreamDecoderWriteCallback write_callback,
  81650. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81651. FLAC__StreamDecoderErrorCallback error_callback,
  81652. void *client_data
  81653. );
  81654. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_FILE(
  81655. FLAC__StreamDecoder *decoder,
  81656. FILE *file,
  81657. FLAC__StreamDecoderWriteCallback write_callback,
  81658. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81659. FLAC__StreamDecoderErrorCallback error_callback,
  81660. void *client_data
  81661. );
  81662. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_file(
  81663. FLAC__StreamDecoder *decoder,
  81664. const char *filename,
  81665. FLAC__StreamDecoderWriteCallback write_callback,
  81666. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81667. FLAC__StreamDecoderErrorCallback error_callback,
  81668. void *client_data
  81669. );
  81670. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_file(
  81671. FLAC__StreamDecoder *decoder,
  81672. const char *filename,
  81673. FLAC__StreamDecoderWriteCallback write_callback,
  81674. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81675. FLAC__StreamDecoderErrorCallback error_callback,
  81676. void *client_data
  81677. );
  81678. FLAC_API FLAC__bool FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder);
  81679. FLAC_API FLAC__bool FLAC__stream_decoder_flush(FLAC__StreamDecoder *decoder);
  81680. FLAC_API FLAC__bool FLAC__stream_decoder_reset(FLAC__StreamDecoder *decoder);
  81681. FLAC_API FLAC__bool FLAC__stream_decoder_process_single(FLAC__StreamDecoder *decoder);
  81682. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_metadata(FLAC__StreamDecoder *decoder);
  81683. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_stream(FLAC__StreamDecoder *decoder);
  81684. FLAC_API FLAC__bool FLAC__stream_decoder_skip_single_frame(FLAC__StreamDecoder *decoder);
  81685. FLAC_API FLAC__bool FLAC__stream_decoder_seek_absolute(FLAC__StreamDecoder *decoder, FLAC__uint64 sample);
  81686. #ifdef __cplusplus
  81687. }
  81688. #endif
  81689. #endif
  81690. /*** End of inlined file: stream_decoder.h ***/
  81691. /*** Start of inlined file: stream_encoder.h ***/
  81692. #ifndef FLAC__STREAM_ENCODER_H
  81693. #define FLAC__STREAM_ENCODER_H
  81694. #include <stdio.h> /* for FILE */
  81695. #ifdef __cplusplus
  81696. extern "C" {
  81697. #endif
  81698. typedef enum {
  81699. FLAC__STREAM_ENCODER_OK = 0,
  81700. FLAC__STREAM_ENCODER_UNINITIALIZED,
  81701. FLAC__STREAM_ENCODER_OGG_ERROR,
  81702. FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR,
  81703. FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA,
  81704. FLAC__STREAM_ENCODER_CLIENT_ERROR,
  81705. FLAC__STREAM_ENCODER_IO_ERROR,
  81706. FLAC__STREAM_ENCODER_FRAMING_ERROR,
  81707. FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR
  81708. } FLAC__StreamEncoderState;
  81709. extern FLAC_API const char * const FLAC__StreamEncoderStateString[];
  81710. typedef enum {
  81711. FLAC__STREAM_ENCODER_INIT_STATUS_OK = 0,
  81712. FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR,
  81713. FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER,
  81714. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS,
  81715. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS,
  81716. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE,
  81717. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE,
  81718. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE,
  81719. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER,
  81720. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION,
  81721. FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER,
  81722. FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE,
  81723. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA,
  81724. FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED
  81725. } FLAC__StreamEncoderInitStatus;
  81726. extern FLAC_API const char * const FLAC__StreamEncoderInitStatusString[];
  81727. typedef enum {
  81728. FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE,
  81729. FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM,
  81730. FLAC__STREAM_ENCODER_READ_STATUS_ABORT,
  81731. FLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED
  81732. } FLAC__StreamEncoderReadStatus;
  81733. extern FLAC_API const char * const FLAC__StreamEncoderReadStatusString[];
  81734. typedef enum {
  81735. FLAC__STREAM_ENCODER_WRITE_STATUS_OK = 0,
  81736. FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR
  81737. } FLAC__StreamEncoderWriteStatus;
  81738. extern FLAC_API const char * const FLAC__StreamEncoderWriteStatusString[];
  81739. typedef enum {
  81740. FLAC__STREAM_ENCODER_SEEK_STATUS_OK,
  81741. FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR,
  81742. FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED
  81743. } FLAC__StreamEncoderSeekStatus;
  81744. extern FLAC_API const char * const FLAC__StreamEncoderSeekStatusString[];
  81745. typedef enum {
  81746. FLAC__STREAM_ENCODER_TELL_STATUS_OK,
  81747. FLAC__STREAM_ENCODER_TELL_STATUS_ERROR,
  81748. FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED
  81749. } FLAC__StreamEncoderTellStatus;
  81750. extern FLAC_API const char * const FLAC__StreamEncoderTellStatusString[];
  81751. struct FLAC__StreamEncoderProtected;
  81752. struct FLAC__StreamEncoderPrivate;
  81753. typedef struct {
  81754. struct FLAC__StreamEncoderProtected *protected_; /* avoid the C++ keyword 'protected' */
  81755. struct FLAC__StreamEncoderPrivate *private_; /* avoid the C++ keyword 'private' */
  81756. } FLAC__StreamEncoder;
  81757. typedef FLAC__StreamEncoderReadStatus (*FLAC__StreamEncoderReadCallback)(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  81758. typedef FLAC__StreamEncoderWriteStatus (*FLAC__StreamEncoderWriteCallback)(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame, void *client_data);
  81759. typedef FLAC__StreamEncoderSeekStatus (*FLAC__StreamEncoderSeekCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  81760. typedef FLAC__StreamEncoderTellStatus (*FLAC__StreamEncoderTellCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  81761. typedef void (*FLAC__StreamEncoderMetadataCallback)(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetadata *metadata, void *client_data);
  81762. 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);
  81763. FLAC_API FLAC__StreamEncoder *FLAC__stream_encoder_new(void);
  81764. FLAC_API void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder);
  81765. FLAC_API FLAC__bool FLAC__stream_encoder_set_ogg_serial_number(FLAC__StreamEncoder *encoder, long serial_number);
  81766. FLAC_API FLAC__bool FLAC__stream_encoder_set_verify(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81767. FLAC_API FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81768. FLAC_API FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encoder, unsigned value);
  81769. FLAC_API FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder *encoder, unsigned value);
  81770. FLAC_API FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *encoder, unsigned value);
  81771. FLAC_API FLAC__bool FLAC__stream_encoder_set_compression_level(FLAC__StreamEncoder *encoder, unsigned value);
  81772. FLAC_API FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, unsigned value);
  81773. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81774. FLAC_API FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81775. FLAC_API FLAC__bool FLAC__stream_encoder_set_apodization(FLAC__StreamEncoder *encoder, const char *specification);
  81776. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_lpc_order(FLAC__StreamEncoder *encoder, unsigned value);
  81777. FLAC_API FLAC__bool FLAC__stream_encoder_set_qlp_coeff_precision(FLAC__StreamEncoder *encoder, unsigned value);
  81778. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_qlp_coeff_prec_search(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81779. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_escape_coding(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81780. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_exhaustive_model_search(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81781. FLAC_API FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value);
  81782. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value);
  81783. FLAC_API FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__StreamEncoder *encoder, unsigned value);
  81784. FLAC_API FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__StreamEncoder *encoder, FLAC__uint64 value);
  81785. FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks);
  81786. FLAC_API FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder);
  81787. FLAC_API FLAC__StreamDecoderState FLAC__stream_encoder_get_verify_decoder_state(const FLAC__StreamEncoder *encoder);
  81788. FLAC_API const char *FLAC__stream_encoder_get_resolved_state_string(const FLAC__StreamEncoder *encoder);
  81789. 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);
  81790. FLAC_API FLAC__bool FLAC__stream_encoder_get_verify(const FLAC__StreamEncoder *encoder);
  81791. FLAC_API FLAC__bool FLAC__stream_encoder_get_streamable_subset(const FLAC__StreamEncoder *encoder);
  81792. FLAC_API unsigned FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder);
  81793. FLAC_API unsigned FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder);
  81794. FLAC_API unsigned FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder);
  81795. FLAC_API unsigned FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder);
  81796. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder);
  81797. FLAC_API FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder);
  81798. FLAC_API unsigned FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder);
  81799. FLAC_API unsigned FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder);
  81800. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder);
  81801. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_escape_coding(const FLAC__StreamEncoder *encoder);
  81802. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder);
  81803. FLAC_API unsigned FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder *encoder);
  81804. FLAC_API unsigned FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder *encoder);
  81805. FLAC_API unsigned FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder);
  81806. FLAC_API FLAC__uint64 FLAC__stream_encoder_get_total_samples_estimate(const FLAC__StreamEncoder *encoder);
  81807. 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);
  81808. 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);
  81809. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE(FLAC__StreamEncoder *encoder, FILE *file, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81810. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_FILE(FLAC__StreamEncoder *encoder, FILE *file, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81811. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_file(FLAC__StreamEncoder *encoder, const char *filename, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81812. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_file(FLAC__StreamEncoder *encoder, const char *filename, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81813. FLAC_API FLAC__bool FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder);
  81814. FLAC_API FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples);
  81815. FLAC_API FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], unsigned samples);
  81816. #ifdef __cplusplus
  81817. }
  81818. #endif
  81819. #endif
  81820. /*** End of inlined file: stream_encoder.h ***/
  81821. #ifdef _MSC_VER
  81822. static _inline FLAC__uint32 local_swap32_(FLAC__uint32 x)
  81823. {
  81824. x = ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);
  81825. return (x>>16) | (x<<16);
  81826. }
  81827. #endif
  81828. #if defined(_MSC_VER) && defined(_X86_)
  81829. static void local_swap32_block_(FLAC__uint32 *start, FLAC__uint32 len)
  81830. {
  81831. __asm {
  81832. mov edx, start
  81833. mov ecx, len
  81834. test ecx, ecx
  81835. loop1:
  81836. jz done1
  81837. mov eax, [edx]
  81838. bswap eax
  81839. mov [edx], eax
  81840. add edx, 4
  81841. dec ecx
  81842. jmp short loop1
  81843. done1:
  81844. }
  81845. }
  81846. #endif
  81847. #endif
  81848. /*** End of inlined file: all.h ***/
  81849. /*** Start of inlined file: bitmath.c ***/
  81850. /*** Start of inlined file: juce_FlacHeader.h ***/
  81851. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  81852. // tasks..
  81853. #define VERSION "1.2.1"
  81854. #define FLAC__NO_DLL 1
  81855. #if JUCE_MSVC
  81856. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  81857. #endif
  81858. #if JUCE_MAC
  81859. #define FLAC__SYS_DARWIN 1
  81860. #endif
  81861. /*** End of inlined file: juce_FlacHeader.h ***/
  81862. #if JUCE_USE_FLAC
  81863. #if HAVE_CONFIG_H
  81864. # include <config.h>
  81865. #endif
  81866. /*** Start of inlined file: bitmath.h ***/
  81867. #ifndef FLAC__PRIVATE__BITMATH_H
  81868. #define FLAC__PRIVATE__BITMATH_H
  81869. unsigned FLAC__bitmath_ilog2(FLAC__uint32 v);
  81870. unsigned FLAC__bitmath_ilog2_wide(FLAC__uint64 v);
  81871. unsigned FLAC__bitmath_silog2(int v);
  81872. unsigned FLAC__bitmath_silog2_wide(FLAC__int64 v);
  81873. #endif
  81874. /*** End of inlined file: bitmath.h ***/
  81875. unsigned FLAC__bitmath_ilog2(FLAC__uint32 v)
  81876. {
  81877. unsigned l = 0;
  81878. FLAC__ASSERT(v > 0);
  81879. while(v >>= 1)
  81880. l++;
  81881. return l;
  81882. }
  81883. unsigned FLAC__bitmath_ilog2_wide(FLAC__uint64 v)
  81884. {
  81885. unsigned l = 0;
  81886. FLAC__ASSERT(v > 0);
  81887. while(v >>= 1)
  81888. l++;
  81889. return l;
  81890. }
  81891. unsigned FLAC__bitmath_silog2(int v)
  81892. {
  81893. while(1) {
  81894. if(v == 0) {
  81895. return 0;
  81896. }
  81897. else if(v > 0) {
  81898. unsigned l = 0;
  81899. while(v) {
  81900. l++;
  81901. v >>= 1;
  81902. }
  81903. return l+1;
  81904. }
  81905. else if(v == -1) {
  81906. return 2;
  81907. }
  81908. else {
  81909. v++;
  81910. v = -v;
  81911. }
  81912. }
  81913. }
  81914. unsigned FLAC__bitmath_silog2_wide(FLAC__int64 v)
  81915. {
  81916. while(1) {
  81917. if(v == 0) {
  81918. return 0;
  81919. }
  81920. else if(v > 0) {
  81921. unsigned l = 0;
  81922. while(v) {
  81923. l++;
  81924. v >>= 1;
  81925. }
  81926. return l+1;
  81927. }
  81928. else if(v == -1) {
  81929. return 2;
  81930. }
  81931. else {
  81932. v++;
  81933. v = -v;
  81934. }
  81935. }
  81936. }
  81937. #endif
  81938. /*** End of inlined file: bitmath.c ***/
  81939. /*** Start of inlined file: bitreader.c ***/
  81940. /*** Start of inlined file: juce_FlacHeader.h ***/
  81941. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  81942. // tasks..
  81943. #define VERSION "1.2.1"
  81944. #define FLAC__NO_DLL 1
  81945. #if JUCE_MSVC
  81946. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  81947. #endif
  81948. #if JUCE_MAC
  81949. #define FLAC__SYS_DARWIN 1
  81950. #endif
  81951. /*** End of inlined file: juce_FlacHeader.h ***/
  81952. #if JUCE_USE_FLAC
  81953. #if HAVE_CONFIG_H
  81954. # include <config.h>
  81955. #endif
  81956. #include <stdlib.h> /* for malloc() */
  81957. #include <string.h> /* for memcpy(), memset() */
  81958. #ifdef _MSC_VER
  81959. #include <winsock.h> /* for ntohl() */
  81960. #elif defined FLAC__SYS_DARWIN
  81961. #include <machine/endian.h> /* for ntohl() */
  81962. #elif defined __MINGW32__
  81963. #include <winsock.h> /* for ntohl() */
  81964. #else
  81965. #include <netinet/in.h> /* for ntohl() */
  81966. #endif
  81967. /*** Start of inlined file: bitreader.h ***/
  81968. #ifndef FLAC__PRIVATE__BITREADER_H
  81969. #define FLAC__PRIVATE__BITREADER_H
  81970. #include <stdio.h> /* for FILE */
  81971. /*** Start of inlined file: cpu.h ***/
  81972. #ifndef FLAC__PRIVATE__CPU_H
  81973. #define FLAC__PRIVATE__CPU_H
  81974. #ifdef HAVE_CONFIG_H
  81975. #include <config.h>
  81976. #endif
  81977. typedef enum {
  81978. FLAC__CPUINFO_TYPE_IA32,
  81979. FLAC__CPUINFO_TYPE_PPC,
  81980. FLAC__CPUINFO_TYPE_UNKNOWN
  81981. } FLAC__CPUInfo_Type;
  81982. typedef struct {
  81983. FLAC__bool cpuid;
  81984. FLAC__bool bswap;
  81985. FLAC__bool cmov;
  81986. FLAC__bool mmx;
  81987. FLAC__bool fxsr;
  81988. FLAC__bool sse;
  81989. FLAC__bool sse2;
  81990. FLAC__bool sse3;
  81991. FLAC__bool ssse3;
  81992. FLAC__bool _3dnow;
  81993. FLAC__bool ext3dnow;
  81994. FLAC__bool extmmx;
  81995. } FLAC__CPUInfo_IA32;
  81996. typedef struct {
  81997. FLAC__bool altivec;
  81998. FLAC__bool ppc64;
  81999. } FLAC__CPUInfo_PPC;
  82000. typedef struct {
  82001. FLAC__bool use_asm;
  82002. FLAC__CPUInfo_Type type;
  82003. union {
  82004. FLAC__CPUInfo_IA32 ia32;
  82005. FLAC__CPUInfo_PPC ppc;
  82006. } data;
  82007. } FLAC__CPUInfo;
  82008. void FLAC__cpu_info(FLAC__CPUInfo *info);
  82009. #ifndef FLAC__NO_ASM
  82010. #ifdef FLAC__CPU_IA32
  82011. #ifdef FLAC__HAS_NASM
  82012. FLAC__uint32 FLAC__cpu_have_cpuid_asm_ia32(void);
  82013. void FLAC__cpu_info_asm_ia32(FLAC__uint32 *flags_edx, FLAC__uint32 *flags_ecx);
  82014. FLAC__uint32 FLAC__cpu_info_extended_amd_asm_ia32(void);
  82015. #endif
  82016. #endif
  82017. #endif
  82018. #endif
  82019. /*** End of inlined file: cpu.h ***/
  82020. struct FLAC__BitReader;
  82021. typedef struct FLAC__BitReader FLAC__BitReader;
  82022. typedef FLAC__bool (*FLAC__BitReaderReadCallback)(FLAC__byte buffer[], size_t *bytes, void *client_data);
  82023. FLAC__BitReader *FLAC__bitreader_new(void);
  82024. void FLAC__bitreader_delete(FLAC__BitReader *br);
  82025. FLAC__bool FLAC__bitreader_init(FLAC__BitReader *br, FLAC__CPUInfo cpu, FLAC__BitReaderReadCallback rcb, void *cd);
  82026. void FLAC__bitreader_free(FLAC__BitReader *br); /* does not 'free(br)' */
  82027. FLAC__bool FLAC__bitreader_clear(FLAC__BitReader *br);
  82028. void FLAC__bitreader_dump(const FLAC__BitReader *br, FILE *out);
  82029. void FLAC__bitreader_reset_read_crc16(FLAC__BitReader *br, FLAC__uint16 seed);
  82030. FLAC__uint16 FLAC__bitreader_get_read_crc16(FLAC__BitReader *br);
  82031. FLAC__bool FLAC__bitreader_is_consumed_byte_aligned(const FLAC__BitReader *br);
  82032. unsigned FLAC__bitreader_bits_left_for_byte_alignment(const FLAC__BitReader *br);
  82033. unsigned FLAC__bitreader_get_input_bits_unconsumed(const FLAC__BitReader *br);
  82034. FLAC__bool FLAC__bitreader_read_raw_uint32(FLAC__BitReader *br, FLAC__uint32 *val, unsigned bits);
  82035. FLAC__bool FLAC__bitreader_read_raw_int32(FLAC__BitReader *br, FLAC__int32 *val, unsigned bits);
  82036. FLAC__bool FLAC__bitreader_read_raw_uint64(FLAC__BitReader *br, FLAC__uint64 *val, unsigned bits);
  82037. FLAC__bool FLAC__bitreader_read_uint32_little_endian(FLAC__BitReader *br, FLAC__uint32 *val); /*only for bits=32*/
  82038. FLAC__bool FLAC__bitreader_skip_bits_no_crc(FLAC__BitReader *br, unsigned bits); /* WATCHOUT: does not CRC the skipped data! */ /*@@@@ add to unit tests */
  82039. FLAC__bool FLAC__bitreader_skip_byte_block_aligned_no_crc(FLAC__BitReader *br, unsigned nvals); /* WATCHOUT: does not CRC the read data! */
  82040. 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! */
  82041. FLAC__bool FLAC__bitreader_read_unary_unsigned(FLAC__BitReader *br, unsigned *val);
  82042. FLAC__bool FLAC__bitreader_read_rice_signed(FLAC__BitReader *br, int *val, unsigned parameter);
  82043. FLAC__bool FLAC__bitreader_read_rice_signed_block(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter);
  82044. #ifndef FLAC__NO_ASM
  82045. # ifdef FLAC__CPU_IA32
  82046. # ifdef FLAC__HAS_NASM
  82047. FLAC__bool FLAC__bitreader_read_rice_signed_block_asm_ia32_bswap(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter);
  82048. # endif
  82049. # endif
  82050. #endif
  82051. #if 0 /* UNUSED */
  82052. FLAC__bool FLAC__bitreader_read_golomb_signed(FLAC__BitReader *br, int *val, unsigned parameter);
  82053. FLAC__bool FLAC__bitreader_read_golomb_unsigned(FLAC__BitReader *br, unsigned *val, unsigned parameter);
  82054. #endif
  82055. FLAC__bool FLAC__bitreader_read_utf8_uint32(FLAC__BitReader *br, FLAC__uint32 *val, FLAC__byte *raw, unsigned *rawlen);
  82056. FLAC__bool FLAC__bitreader_read_utf8_uint64(FLAC__BitReader *br, FLAC__uint64 *val, FLAC__byte *raw, unsigned *rawlen);
  82057. FLAC__bool bitreader_read_from_client_(FLAC__BitReader *br);
  82058. #endif
  82059. /*** End of inlined file: bitreader.h ***/
  82060. /*** Start of inlined file: crc.h ***/
  82061. #ifndef FLAC__PRIVATE__CRC_H
  82062. #define FLAC__PRIVATE__CRC_H
  82063. extern FLAC__byte const FLAC__crc8_table[256];
  82064. #define FLAC__CRC8_UPDATE(data, crc) (crc) = FLAC__crc8_table[(crc) ^ (data)];
  82065. void FLAC__crc8_update(const FLAC__byte data, FLAC__uint8 *crc);
  82066. void FLAC__crc8_update_block(const FLAC__byte *data, unsigned len, FLAC__uint8 *crc);
  82067. FLAC__uint8 FLAC__crc8(const FLAC__byte *data, unsigned len);
  82068. extern unsigned FLAC__crc16_table[256];
  82069. #define FLAC__CRC16_UPDATE(data, crc) (((((crc)<<8) & 0xffff) ^ FLAC__crc16_table[((crc)>>8) ^ (data)]))
  82070. #if 0
  82071. #define FLAC__CRC16_UPDATE(data, crc) ((((crc)<<8) ^ FLAC__crc16_table[((crc)>>8) ^ (data)]) & 0xffff)
  82072. #endif
  82073. unsigned FLAC__crc16(const FLAC__byte *data, unsigned len);
  82074. #endif
  82075. /*** End of inlined file: crc.h ***/
  82076. typedef FLAC__uint32 brword;
  82077. #define FLAC__BYTES_PER_WORD 4
  82078. #define FLAC__BITS_PER_WORD 32
  82079. #define FLAC__WORD_ALL_ONES ((FLAC__uint32)0xffffffff)
  82080. #if WORDS_BIGENDIAN
  82081. #define SWAP_BE_WORD_TO_HOST(x) (x)
  82082. #else
  82083. #if defined (_MSC_VER) && defined (_X86_)
  82084. #define SWAP_BE_WORD_TO_HOST(x) local_swap32_(x)
  82085. #else
  82086. #define SWAP_BE_WORD_TO_HOST(x) ntohl(x)
  82087. #endif
  82088. #endif
  82089. #define COUNT_ZERO_MSBS(word) ( \
  82090. (word) <= 0xffff ? \
  82091. ( (word) <= 0xff? byte_to_unary_table[word] + 24 : byte_to_unary_table[(word) >> 8] + 16 ) : \
  82092. ( (word) <= 0xffffff? byte_to_unary_table[word >> 16] + 8 : byte_to_unary_table[(word) >> 24] ) \
  82093. )
  82094. #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])) )
  82095. static const unsigned FLAC__BITREADER_DEFAULT_CAPACITY = 65536u / FLAC__BITS_PER_WORD; /* in words */
  82096. static const unsigned char byte_to_unary_table[] = {
  82097. 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4,
  82098. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  82099. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  82100. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  82101. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  82102. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  82103. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  82104. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  82105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  82106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  82107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  82108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  82109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  82110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  82111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  82112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  82113. };
  82114. #ifdef min
  82115. #undef min
  82116. #endif
  82117. #define min(x,y) ((x)<(y)?(x):(y))
  82118. #ifdef max
  82119. #undef max
  82120. #endif
  82121. #define max(x,y) ((x)>(y)?(x):(y))
  82122. #ifdef _MSC_VER
  82123. #define FLAC__U64L(x) x
  82124. #else
  82125. #define FLAC__U64L(x) x##LLU
  82126. #endif
  82127. #ifndef FLaC__INLINE
  82128. #define FLaC__INLINE
  82129. #endif
  82130. struct FLAC__BitReader {
  82131. brword *buffer;
  82132. unsigned capacity; /* in words */
  82133. unsigned words; /* # of completed words in buffer */
  82134. unsigned bytes; /* # of bytes in incomplete word at buffer[words] */
  82135. unsigned consumed_words; /* #words ... */
  82136. unsigned consumed_bits; /* ... + (#bits of head word) already consumed from the front of buffer */
  82137. unsigned read_crc16; /* the running frame CRC */
  82138. unsigned crc16_align; /* the number of bits in the current consumed word that should not be CRC'd */
  82139. FLAC__BitReaderReadCallback read_callback;
  82140. void *client_data;
  82141. FLAC__CPUInfo cpu_info;
  82142. };
  82143. static FLaC__INLINE void crc16_update_word_(FLAC__BitReader *br, brword word)
  82144. {
  82145. register unsigned crc = br->read_crc16;
  82146. #if FLAC__BYTES_PER_WORD == 4
  82147. switch(br->crc16_align) {
  82148. case 0: crc = FLAC__CRC16_UPDATE((unsigned)(word >> 24), crc);
  82149. case 8: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 16) & 0xff), crc);
  82150. case 16: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 8) & 0xff), crc);
  82151. case 24: br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)(word & 0xff), crc);
  82152. }
  82153. #elif FLAC__BYTES_PER_WORD == 8
  82154. switch(br->crc16_align) {
  82155. case 0: crc = FLAC__CRC16_UPDATE((unsigned)(word >> 56), crc);
  82156. case 8: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 48) & 0xff), crc);
  82157. case 16: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 40) & 0xff), crc);
  82158. case 24: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 32) & 0xff), crc);
  82159. case 32: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 24) & 0xff), crc);
  82160. case 40: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 16) & 0xff), crc);
  82161. case 48: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 8) & 0xff), crc);
  82162. case 56: br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)(word & 0xff), crc);
  82163. }
  82164. #else
  82165. for( ; br->crc16_align < FLAC__BITS_PER_WORD; br->crc16_align += 8)
  82166. crc = FLAC__CRC16_UPDATE((unsigned)((word >> (FLAC__BITS_PER_WORD-8-br->crc16_align)) & 0xff), crc);
  82167. br->read_crc16 = crc;
  82168. #endif
  82169. br->crc16_align = 0;
  82170. }
  82171. FLAC__bool bitreader_read_from_client_(FLAC__BitReader *br)
  82172. {
  82173. unsigned start, end;
  82174. size_t bytes;
  82175. FLAC__byte *target;
  82176. if(br->consumed_words > 0) {
  82177. start = br->consumed_words;
  82178. end = br->words + (br->bytes? 1:0);
  82179. memmove(br->buffer, br->buffer+start, FLAC__BYTES_PER_WORD * (end - start));
  82180. br->words -= start;
  82181. br->consumed_words = 0;
  82182. }
  82183. bytes = (br->capacity - br->words) * FLAC__BYTES_PER_WORD - br->bytes;
  82184. if(bytes == 0)
  82185. return false; /* no space left, buffer is too small; see note for FLAC__BITREADER_DEFAULT_CAPACITY */
  82186. target = ((FLAC__byte*)(br->buffer+br->words)) + br->bytes;
  82187. #if WORDS_BIGENDIAN
  82188. #else
  82189. if(br->bytes)
  82190. br->buffer[br->words] = SWAP_BE_WORD_TO_HOST(br->buffer[br->words]);
  82191. #endif
  82192. if(!br->read_callback(target, &bytes, br->client_data))
  82193. return false;
  82194. #if WORDS_BIGENDIAN
  82195. #else
  82196. end = (br->words*FLAC__BYTES_PER_WORD + br->bytes + bytes + (FLAC__BYTES_PER_WORD-1)) / FLAC__BYTES_PER_WORD;
  82197. # if defined(_MSC_VER) && defined (_X86_) && (FLAC__BYTES_PER_WORD == 4)
  82198. if(br->cpu_info.type == FLAC__CPUINFO_TYPE_IA32 && br->cpu_info.data.ia32.bswap) {
  82199. start = br->words;
  82200. local_swap32_block_(br->buffer + start, end - start);
  82201. }
  82202. else
  82203. # endif
  82204. for(start = br->words; start < end; start++)
  82205. br->buffer[start] = SWAP_BE_WORD_TO_HOST(br->buffer[start]);
  82206. #endif
  82207. end = br->words*FLAC__BYTES_PER_WORD + br->bytes + bytes;
  82208. br->words = end / FLAC__BYTES_PER_WORD;
  82209. br->bytes = end % FLAC__BYTES_PER_WORD;
  82210. return true;
  82211. }
  82212. FLAC__BitReader *FLAC__bitreader_new(void)
  82213. {
  82214. FLAC__BitReader *br = (FLAC__BitReader*)calloc(1, sizeof(FLAC__BitReader));
  82215. return br;
  82216. }
  82217. void FLAC__bitreader_delete(FLAC__BitReader *br)
  82218. {
  82219. FLAC__ASSERT(0 != br);
  82220. FLAC__bitreader_free(br);
  82221. free(br);
  82222. }
  82223. FLAC__bool FLAC__bitreader_init(FLAC__BitReader *br, FLAC__CPUInfo cpu, FLAC__BitReaderReadCallback rcb, void *cd)
  82224. {
  82225. FLAC__ASSERT(0 != br);
  82226. br->words = br->bytes = 0;
  82227. br->consumed_words = br->consumed_bits = 0;
  82228. br->capacity = FLAC__BITREADER_DEFAULT_CAPACITY;
  82229. br->buffer = (brword*)malloc(sizeof(brword) * br->capacity);
  82230. if(br->buffer == 0)
  82231. return false;
  82232. br->read_callback = rcb;
  82233. br->client_data = cd;
  82234. br->cpu_info = cpu;
  82235. return true;
  82236. }
  82237. void FLAC__bitreader_free(FLAC__BitReader *br)
  82238. {
  82239. FLAC__ASSERT(0 != br);
  82240. if(0 != br->buffer)
  82241. free(br->buffer);
  82242. br->buffer = 0;
  82243. br->capacity = 0;
  82244. br->words = br->bytes = 0;
  82245. br->consumed_words = br->consumed_bits = 0;
  82246. br->read_callback = 0;
  82247. br->client_data = 0;
  82248. }
  82249. FLAC__bool FLAC__bitreader_clear(FLAC__BitReader *br)
  82250. {
  82251. br->words = br->bytes = 0;
  82252. br->consumed_words = br->consumed_bits = 0;
  82253. return true;
  82254. }
  82255. void FLAC__bitreader_dump(const FLAC__BitReader *br, FILE *out)
  82256. {
  82257. unsigned i, j;
  82258. if(br == 0) {
  82259. fprintf(out, "bitreader is NULL\n");
  82260. }
  82261. else {
  82262. 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);
  82263. for(i = 0; i < br->words; i++) {
  82264. fprintf(out, "%08X: ", i);
  82265. for(j = 0; j < FLAC__BITS_PER_WORD; j++)
  82266. if(i < br->consumed_words || (i == br->consumed_words && j < br->consumed_bits))
  82267. fprintf(out, ".");
  82268. else
  82269. fprintf(out, "%01u", br->buffer[i] & (1 << (FLAC__BITS_PER_WORD-j-1)) ? 1:0);
  82270. fprintf(out, "\n");
  82271. }
  82272. if(br->bytes > 0) {
  82273. fprintf(out, "%08X: ", i);
  82274. for(j = 0; j < br->bytes*8; j++)
  82275. if(i < br->consumed_words || (i == br->consumed_words && j < br->consumed_bits))
  82276. fprintf(out, ".");
  82277. else
  82278. fprintf(out, "%01u", br->buffer[i] & (1 << (br->bytes*8-j-1)) ? 1:0);
  82279. fprintf(out, "\n");
  82280. }
  82281. }
  82282. }
  82283. void FLAC__bitreader_reset_read_crc16(FLAC__BitReader *br, FLAC__uint16 seed)
  82284. {
  82285. FLAC__ASSERT(0 != br);
  82286. FLAC__ASSERT(0 != br->buffer);
  82287. FLAC__ASSERT((br->consumed_bits & 7) == 0);
  82288. br->read_crc16 = (unsigned)seed;
  82289. br->crc16_align = br->consumed_bits;
  82290. }
  82291. FLAC__uint16 FLAC__bitreader_get_read_crc16(FLAC__BitReader *br)
  82292. {
  82293. FLAC__ASSERT(0 != br);
  82294. FLAC__ASSERT(0 != br->buffer);
  82295. FLAC__ASSERT((br->consumed_bits & 7) == 0);
  82296. FLAC__ASSERT(br->crc16_align <= br->consumed_bits);
  82297. if(br->consumed_bits) {
  82298. const brword tail = br->buffer[br->consumed_words];
  82299. for( ; br->crc16_align < br->consumed_bits; br->crc16_align += 8)
  82300. br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)((tail >> (FLAC__BITS_PER_WORD-8-br->crc16_align)) & 0xff), br->read_crc16);
  82301. }
  82302. return br->read_crc16;
  82303. }
  82304. FLaC__INLINE FLAC__bool FLAC__bitreader_is_consumed_byte_aligned(const FLAC__BitReader *br)
  82305. {
  82306. return ((br->consumed_bits & 7) == 0);
  82307. }
  82308. FLaC__INLINE unsigned FLAC__bitreader_bits_left_for_byte_alignment(const FLAC__BitReader *br)
  82309. {
  82310. return 8 - (br->consumed_bits & 7);
  82311. }
  82312. FLaC__INLINE unsigned FLAC__bitreader_get_input_bits_unconsumed(const FLAC__BitReader *br)
  82313. {
  82314. return (br->words-br->consumed_words)*FLAC__BITS_PER_WORD + br->bytes*8 - br->consumed_bits;
  82315. }
  82316. FLaC__INLINE FLAC__bool FLAC__bitreader_read_raw_uint32(FLAC__BitReader *br, FLAC__uint32 *val, unsigned bits)
  82317. {
  82318. FLAC__ASSERT(0 != br);
  82319. FLAC__ASSERT(0 != br->buffer);
  82320. FLAC__ASSERT(bits <= 32);
  82321. FLAC__ASSERT((br->capacity*FLAC__BITS_PER_WORD) * 2 >= bits);
  82322. FLAC__ASSERT(br->consumed_words <= br->words);
  82323. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  82324. if(bits == 0) { /* OPT: investigate if this can ever happen, maybe change to assertion */
  82325. *val = 0;
  82326. return true;
  82327. }
  82328. while((br->words-br->consumed_words)*FLAC__BITS_PER_WORD + br->bytes*8 - br->consumed_bits < bits) {
  82329. if(!bitreader_read_from_client_(br))
  82330. return false;
  82331. }
  82332. if(br->consumed_words < br->words) { /* if we've not consumed up to a partial tail word... */
  82333. if(br->consumed_bits) {
  82334. const unsigned n = FLAC__BITS_PER_WORD - br->consumed_bits;
  82335. const brword word = br->buffer[br->consumed_words];
  82336. if(bits < n) {
  82337. *val = (word & (FLAC__WORD_ALL_ONES >> br->consumed_bits)) >> (n-bits);
  82338. br->consumed_bits += bits;
  82339. return true;
  82340. }
  82341. *val = word & (FLAC__WORD_ALL_ONES >> br->consumed_bits);
  82342. bits -= n;
  82343. crc16_update_word_(br, word);
  82344. br->consumed_words++;
  82345. br->consumed_bits = 0;
  82346. 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 */
  82347. *val <<= bits;
  82348. *val |= (br->buffer[br->consumed_words] >> (FLAC__BITS_PER_WORD-bits));
  82349. br->consumed_bits = bits;
  82350. }
  82351. return true;
  82352. }
  82353. else {
  82354. const brword word = br->buffer[br->consumed_words];
  82355. if(bits < FLAC__BITS_PER_WORD) {
  82356. *val = word >> (FLAC__BITS_PER_WORD-bits);
  82357. br->consumed_bits = bits;
  82358. return true;
  82359. }
  82360. *val = word;
  82361. crc16_update_word_(br, word);
  82362. br->consumed_words++;
  82363. return true;
  82364. }
  82365. }
  82366. else {
  82367. if(br->consumed_bits) {
  82368. FLAC__ASSERT(br->consumed_bits + bits <= br->bytes*8);
  82369. *val = (br->buffer[br->consumed_words] & (FLAC__WORD_ALL_ONES >> br->consumed_bits)) >> (FLAC__BITS_PER_WORD-br->consumed_bits-bits);
  82370. br->consumed_bits += bits;
  82371. return true;
  82372. }
  82373. else {
  82374. *val = br->buffer[br->consumed_words] >> (FLAC__BITS_PER_WORD-bits);
  82375. br->consumed_bits += bits;
  82376. return true;
  82377. }
  82378. }
  82379. }
  82380. FLAC__bool FLAC__bitreader_read_raw_int32(FLAC__BitReader *br, FLAC__int32 *val, unsigned bits)
  82381. {
  82382. if(!FLAC__bitreader_read_raw_uint32(br, (FLAC__uint32*)val, bits))
  82383. return false;
  82384. *val <<= (32-bits);
  82385. *val >>= (32-bits);
  82386. return true;
  82387. }
  82388. FLAC__bool FLAC__bitreader_read_raw_uint64(FLAC__BitReader *br, FLAC__uint64 *val, unsigned bits)
  82389. {
  82390. FLAC__uint32 hi, lo;
  82391. if(bits > 32) {
  82392. if(!FLAC__bitreader_read_raw_uint32(br, &hi, bits-32))
  82393. return false;
  82394. if(!FLAC__bitreader_read_raw_uint32(br, &lo, 32))
  82395. return false;
  82396. *val = hi;
  82397. *val <<= 32;
  82398. *val |= lo;
  82399. }
  82400. else {
  82401. if(!FLAC__bitreader_read_raw_uint32(br, &lo, bits))
  82402. return false;
  82403. *val = lo;
  82404. }
  82405. return true;
  82406. }
  82407. FLaC__INLINE FLAC__bool FLAC__bitreader_read_uint32_little_endian(FLAC__BitReader *br, FLAC__uint32 *val)
  82408. {
  82409. FLAC__uint32 x8, x32 = 0;
  82410. if(!FLAC__bitreader_read_raw_uint32(br, &x32, 8))
  82411. return false;
  82412. if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8))
  82413. return false;
  82414. x32 |= (x8 << 8);
  82415. if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8))
  82416. return false;
  82417. x32 |= (x8 << 16);
  82418. if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8))
  82419. return false;
  82420. x32 |= (x8 << 24);
  82421. *val = x32;
  82422. return true;
  82423. }
  82424. FLAC__bool FLAC__bitreader_skip_bits_no_crc(FLAC__BitReader *br, unsigned bits)
  82425. {
  82426. FLAC__ASSERT(0 != br);
  82427. FLAC__ASSERT(0 != br->buffer);
  82428. if(bits > 0) {
  82429. const unsigned n = br->consumed_bits & 7;
  82430. unsigned m;
  82431. FLAC__uint32 x;
  82432. if(n != 0) {
  82433. m = min(8-n, bits);
  82434. if(!FLAC__bitreader_read_raw_uint32(br, &x, m))
  82435. return false;
  82436. bits -= m;
  82437. }
  82438. m = bits / 8;
  82439. if(m > 0) {
  82440. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(br, m))
  82441. return false;
  82442. bits %= 8;
  82443. }
  82444. if(bits > 0) {
  82445. if(!FLAC__bitreader_read_raw_uint32(br, &x, bits))
  82446. return false;
  82447. }
  82448. }
  82449. return true;
  82450. }
  82451. FLAC__bool FLAC__bitreader_skip_byte_block_aligned_no_crc(FLAC__BitReader *br, unsigned nvals)
  82452. {
  82453. FLAC__uint32 x;
  82454. FLAC__ASSERT(0 != br);
  82455. FLAC__ASSERT(0 != br->buffer);
  82456. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(br));
  82457. while(nvals && br->consumed_bits) { /* i.e. run until we read 'nvals' bytes or we hit the end of the head word */
  82458. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82459. return false;
  82460. nvals--;
  82461. }
  82462. if(0 == nvals)
  82463. return true;
  82464. while(nvals >= FLAC__BYTES_PER_WORD) {
  82465. if(br->consumed_words < br->words) {
  82466. br->consumed_words++;
  82467. nvals -= FLAC__BYTES_PER_WORD;
  82468. }
  82469. else if(!bitreader_read_from_client_(br))
  82470. return false;
  82471. }
  82472. while(nvals) {
  82473. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82474. return false;
  82475. nvals--;
  82476. }
  82477. return true;
  82478. }
  82479. FLAC__bool FLAC__bitreader_read_byte_block_aligned_no_crc(FLAC__BitReader *br, FLAC__byte *val, unsigned nvals)
  82480. {
  82481. FLAC__uint32 x;
  82482. FLAC__ASSERT(0 != br);
  82483. FLAC__ASSERT(0 != br->buffer);
  82484. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(br));
  82485. while(nvals && br->consumed_bits) { /* i.e. run until we read 'nvals' bytes or we hit the end of the head word */
  82486. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82487. return false;
  82488. *val++ = (FLAC__byte)x;
  82489. nvals--;
  82490. }
  82491. if(0 == nvals)
  82492. return true;
  82493. while(nvals >= FLAC__BYTES_PER_WORD) {
  82494. if(br->consumed_words < br->words) {
  82495. const brword word = br->buffer[br->consumed_words++];
  82496. #if FLAC__BYTES_PER_WORD == 4
  82497. val[0] = (FLAC__byte)(word >> 24);
  82498. val[1] = (FLAC__byte)(word >> 16);
  82499. val[2] = (FLAC__byte)(word >> 8);
  82500. val[3] = (FLAC__byte)word;
  82501. #elif FLAC__BYTES_PER_WORD == 8
  82502. val[0] = (FLAC__byte)(word >> 56);
  82503. val[1] = (FLAC__byte)(word >> 48);
  82504. val[2] = (FLAC__byte)(word >> 40);
  82505. val[3] = (FLAC__byte)(word >> 32);
  82506. val[4] = (FLAC__byte)(word >> 24);
  82507. val[5] = (FLAC__byte)(word >> 16);
  82508. val[6] = (FLAC__byte)(word >> 8);
  82509. val[7] = (FLAC__byte)word;
  82510. #else
  82511. for(x = 0; x < FLAC__BYTES_PER_WORD; x++)
  82512. val[x] = (FLAC__byte)(word >> (8*(FLAC__BYTES_PER_WORD-x-1)));
  82513. #endif
  82514. val += FLAC__BYTES_PER_WORD;
  82515. nvals -= FLAC__BYTES_PER_WORD;
  82516. }
  82517. else if(!bitreader_read_from_client_(br))
  82518. return false;
  82519. }
  82520. while(nvals) {
  82521. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82522. return false;
  82523. *val++ = (FLAC__byte)x;
  82524. nvals--;
  82525. }
  82526. return true;
  82527. }
  82528. FLaC__INLINE FLAC__bool FLAC__bitreader_read_unary_unsigned(FLAC__BitReader *br, unsigned *val)
  82529. #if 0 /* slow but readable version */
  82530. {
  82531. unsigned bit;
  82532. FLAC__ASSERT(0 != br);
  82533. FLAC__ASSERT(0 != br->buffer);
  82534. *val = 0;
  82535. while(1) {
  82536. if(!FLAC__bitreader_read_bit(br, &bit))
  82537. return false;
  82538. if(bit)
  82539. break;
  82540. else
  82541. *val++;
  82542. }
  82543. return true;
  82544. }
  82545. #else
  82546. {
  82547. unsigned i;
  82548. FLAC__ASSERT(0 != br);
  82549. FLAC__ASSERT(0 != br->buffer);
  82550. *val = 0;
  82551. while(1) {
  82552. while(br->consumed_words < br->words) { /* if we've not consumed up to a partial tail word... */
  82553. brword b = br->buffer[br->consumed_words] << br->consumed_bits;
  82554. if(b) {
  82555. i = COUNT_ZERO_MSBS(b);
  82556. *val += i;
  82557. i++;
  82558. br->consumed_bits += i;
  82559. if(br->consumed_bits >= FLAC__BITS_PER_WORD) { /* faster way of testing if(br->consumed_bits == FLAC__BITS_PER_WORD) */
  82560. crc16_update_word_(br, br->buffer[br->consumed_words]);
  82561. br->consumed_words++;
  82562. br->consumed_bits = 0;
  82563. }
  82564. return true;
  82565. }
  82566. else {
  82567. *val += FLAC__BITS_PER_WORD - br->consumed_bits;
  82568. crc16_update_word_(br, br->buffer[br->consumed_words]);
  82569. br->consumed_words++;
  82570. br->consumed_bits = 0;
  82571. }
  82572. }
  82573. if(br->bytes) {
  82574. const unsigned end = br->bytes * 8;
  82575. brword b = (br->buffer[br->consumed_words] & (FLAC__WORD_ALL_ONES << (FLAC__BITS_PER_WORD-end))) << br->consumed_bits;
  82576. if(b) {
  82577. i = COUNT_ZERO_MSBS(b);
  82578. *val += i;
  82579. i++;
  82580. br->consumed_bits += i;
  82581. FLAC__ASSERT(br->consumed_bits < FLAC__BITS_PER_WORD);
  82582. return true;
  82583. }
  82584. else {
  82585. *val += end - br->consumed_bits;
  82586. br->consumed_bits += end;
  82587. FLAC__ASSERT(br->consumed_bits < FLAC__BITS_PER_WORD);
  82588. }
  82589. }
  82590. if(!bitreader_read_from_client_(br))
  82591. return false;
  82592. }
  82593. }
  82594. #endif
  82595. FLAC__bool FLAC__bitreader_read_rice_signed(FLAC__BitReader *br, int *val, unsigned parameter)
  82596. {
  82597. FLAC__uint32 lsbs = 0, msbs = 0;
  82598. unsigned uval;
  82599. FLAC__ASSERT(0 != br);
  82600. FLAC__ASSERT(0 != br->buffer);
  82601. FLAC__ASSERT(parameter <= 31);
  82602. if(!FLAC__bitreader_read_unary_unsigned(br, (unsigned int*) &msbs))
  82603. return false;
  82604. if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, parameter))
  82605. return false;
  82606. uval = (msbs << parameter) | lsbs;
  82607. if(uval & 1)
  82608. *val = -((int)(uval >> 1)) - 1;
  82609. else
  82610. *val = (int)(uval >> 1);
  82611. return true;
  82612. }
  82613. FLAC__bool FLAC__bitreader_read_rice_signed_block(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter)
  82614. #ifdef _MSC_VER
  82615. {
  82616. unsigned i;
  82617. unsigned uval = 0;
  82618. unsigned bits; /* the # of binary LSBs left to read to finish a rice codeword */
  82619. register unsigned cwords;
  82620. register unsigned cbits;
  82621. FLAC__ASSERT(0 != br);
  82622. FLAC__ASSERT(0 != br->buffer);
  82623. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  82624. FLAC__ASSERT(parameter < 32);
  82625. if(nvals == 0)
  82626. return true;
  82627. cbits = br->consumed_bits;
  82628. cwords = br->consumed_words;
  82629. while(1) {
  82630. while(1) {
  82631. while(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82632. brword b = br->buffer[cwords] << cbits;
  82633. if(b) {
  82634. #if 0 /* slower, probably due to bad register allocation... */ && defined FLAC__CPU_IA32 && !defined FLAC__NO_ASM && FLAC__BITS_PER_WORD == 32
  82635. __asm {
  82636. bsr eax, b
  82637. not eax
  82638. and eax, 31
  82639. mov i, eax
  82640. }
  82641. #else
  82642. i = COUNT_ZERO_MSBS(b);
  82643. #endif
  82644. uval += i;
  82645. bits = parameter;
  82646. i++;
  82647. cbits += i;
  82648. if(cbits == FLAC__BITS_PER_WORD) {
  82649. crc16_update_word_(br, br->buffer[cwords]);
  82650. cwords++;
  82651. cbits = 0;
  82652. }
  82653. goto break1;
  82654. }
  82655. else {
  82656. uval += FLAC__BITS_PER_WORD - cbits;
  82657. crc16_update_word_(br, br->buffer[cwords]);
  82658. cwords++;
  82659. cbits = 0;
  82660. }
  82661. }
  82662. if(br->bytes) {
  82663. const unsigned end = br->bytes * 8;
  82664. brword b = (br->buffer[cwords] & (FLAC__WORD_ALL_ONES << (FLAC__BITS_PER_WORD-end))) << cbits;
  82665. if(b) {
  82666. i = COUNT_ZERO_MSBS(b);
  82667. uval += i;
  82668. bits = parameter;
  82669. i++;
  82670. cbits += i;
  82671. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82672. goto break1;
  82673. }
  82674. else {
  82675. uval += end - cbits;
  82676. cbits += end;
  82677. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82678. }
  82679. }
  82680. br->consumed_bits = cbits;
  82681. br->consumed_words = cwords;
  82682. if(!bitreader_read_from_client_(br))
  82683. return false;
  82684. cwords = br->consumed_words;
  82685. }
  82686. break1:
  82687. FLAC__ASSERT(cwords <= br->words);
  82688. if(bits) {
  82689. while((br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits < bits) {
  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. }
  82696. if(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82697. if(cbits) {
  82698. const unsigned n = FLAC__BITS_PER_WORD - cbits;
  82699. const brword word = br->buffer[cwords];
  82700. if(bits < n) {
  82701. uval <<= bits;
  82702. uval |= (word & (FLAC__WORD_ALL_ONES >> cbits)) >> (n-bits);
  82703. cbits += bits;
  82704. goto break2;
  82705. }
  82706. uval <<= n;
  82707. uval |= word & (FLAC__WORD_ALL_ONES >> cbits);
  82708. bits -= n;
  82709. crc16_update_word_(br, word);
  82710. cwords++;
  82711. cbits = 0;
  82712. 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 */
  82713. uval <<= bits;
  82714. uval |= (br->buffer[cwords] >> (FLAC__BITS_PER_WORD-bits));
  82715. cbits = bits;
  82716. }
  82717. goto break2;
  82718. }
  82719. else {
  82720. FLAC__ASSERT(bits < FLAC__BITS_PER_WORD);
  82721. uval <<= bits;
  82722. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-bits);
  82723. cbits = bits;
  82724. goto break2;
  82725. }
  82726. }
  82727. else {
  82728. uval <<= bits;
  82729. if(cbits) {
  82730. FLAC__ASSERT(cbits + bits <= br->bytes*8);
  82731. uval |= (br->buffer[cwords] & (FLAC__WORD_ALL_ONES >> cbits)) >> (FLAC__BITS_PER_WORD-cbits-bits);
  82732. cbits += bits;
  82733. goto break2;
  82734. }
  82735. else {
  82736. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-bits);
  82737. cbits += bits;
  82738. goto break2;
  82739. }
  82740. }
  82741. }
  82742. break2:
  82743. *vals = (int)(uval >> 1 ^ -(int)(uval & 1));
  82744. --nvals;
  82745. if(nvals == 0) {
  82746. br->consumed_bits = cbits;
  82747. br->consumed_words = cwords;
  82748. return true;
  82749. }
  82750. uval = 0;
  82751. ++vals;
  82752. }
  82753. }
  82754. #else
  82755. {
  82756. unsigned i;
  82757. unsigned uval = 0;
  82758. register unsigned cwords;
  82759. register unsigned cbits;
  82760. unsigned ucbits; /* keep track of the number of unconsumed bits in the buffer */
  82761. FLAC__ASSERT(0 != br);
  82762. FLAC__ASSERT(0 != br->buffer);
  82763. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  82764. FLAC__ASSERT(parameter < 32);
  82765. if(nvals == 0)
  82766. return true;
  82767. cbits = br->consumed_bits;
  82768. cwords = br->consumed_words;
  82769. ucbits = (br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits;
  82770. while(1) {
  82771. while(1) {
  82772. while(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82773. brword b = br->buffer[cwords] << cbits;
  82774. if(b) {
  82775. #if 0 /* is not discernably faster... */ && defined FLAC__CPU_IA32 && !defined FLAC__NO_ASM && FLAC__BITS_PER_WORD == 32 && defined __GNUC__
  82776. asm volatile (
  82777. "bsrl %1, %0;"
  82778. "notl %0;"
  82779. "andl $31, %0;"
  82780. : "=r"(i)
  82781. : "r"(b)
  82782. );
  82783. #else
  82784. i = COUNT_ZERO_MSBS(b);
  82785. #endif
  82786. uval += i;
  82787. cbits += i;
  82788. cbits++; /* skip over stop bit */
  82789. if(cbits >= FLAC__BITS_PER_WORD) { /* faster way of testing if(cbits == FLAC__BITS_PER_WORD) */
  82790. crc16_update_word_(br, br->buffer[cwords]);
  82791. cwords++;
  82792. cbits = 0;
  82793. }
  82794. goto break1;
  82795. }
  82796. else {
  82797. uval += FLAC__BITS_PER_WORD - cbits;
  82798. crc16_update_word_(br, br->buffer[cwords]);
  82799. cwords++;
  82800. cbits = 0;
  82801. }
  82802. }
  82803. if(br->bytes) {
  82804. const unsigned end = br->bytes * 8;
  82805. brword b = (br->buffer[cwords] & ~(FLAC__WORD_ALL_ONES >> end)) << cbits;
  82806. if(b) {
  82807. i = COUNT_ZERO_MSBS(b);
  82808. uval += i;
  82809. cbits += i;
  82810. cbits++; /* skip over stop bit */
  82811. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82812. goto break1;
  82813. }
  82814. else {
  82815. uval += end - cbits;
  82816. cbits += end;
  82817. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82818. }
  82819. }
  82820. br->consumed_bits = cbits;
  82821. br->consumed_words = cwords;
  82822. if(!bitreader_read_from_client_(br))
  82823. return false;
  82824. cwords = br->consumed_words;
  82825. ucbits = (br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits + uval;
  82826. }
  82827. break1:
  82828. ucbits -= uval;
  82829. ucbits--; /* account for stop bit */
  82830. FLAC__ASSERT(cwords <= br->words);
  82831. if(parameter) {
  82832. while(ucbits < parameter) {
  82833. br->consumed_bits = cbits;
  82834. br->consumed_words = cwords;
  82835. if(!bitreader_read_from_client_(br))
  82836. return false;
  82837. cwords = br->consumed_words;
  82838. ucbits = (br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits;
  82839. }
  82840. if(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82841. if(cbits) {
  82842. const unsigned n = FLAC__BITS_PER_WORD - cbits;
  82843. const brword word = br->buffer[cwords];
  82844. if(parameter < n) {
  82845. uval <<= parameter;
  82846. uval |= (word & (FLAC__WORD_ALL_ONES >> cbits)) >> (n-parameter);
  82847. cbits += parameter;
  82848. }
  82849. else {
  82850. uval <<= n;
  82851. uval |= word & (FLAC__WORD_ALL_ONES >> cbits);
  82852. crc16_update_word_(br, word);
  82853. cwords++;
  82854. cbits = parameter - n;
  82855. 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 */
  82856. uval <<= cbits;
  82857. uval |= (br->buffer[cwords] >> (FLAC__BITS_PER_WORD-cbits));
  82858. }
  82859. }
  82860. }
  82861. else {
  82862. cbits = parameter;
  82863. uval <<= parameter;
  82864. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-cbits);
  82865. }
  82866. }
  82867. else {
  82868. uval <<= parameter;
  82869. if(cbits) {
  82870. FLAC__ASSERT(cbits + parameter <= br->bytes*8);
  82871. uval |= (br->buffer[cwords] & (FLAC__WORD_ALL_ONES >> cbits)) >> (FLAC__BITS_PER_WORD-cbits-parameter);
  82872. cbits += parameter;
  82873. }
  82874. else {
  82875. cbits = parameter;
  82876. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-cbits);
  82877. }
  82878. }
  82879. }
  82880. ucbits -= parameter;
  82881. *vals = (int)(uval >> 1 ^ -(int)(uval & 1));
  82882. --nvals;
  82883. if(nvals == 0) {
  82884. br->consumed_bits = cbits;
  82885. br->consumed_words = cwords;
  82886. return true;
  82887. }
  82888. uval = 0;
  82889. ++vals;
  82890. }
  82891. }
  82892. #endif
  82893. #if 0 /* UNUSED */
  82894. FLAC__bool FLAC__bitreader_read_golomb_signed(FLAC__BitReader *br, int *val, unsigned parameter)
  82895. {
  82896. FLAC__uint32 lsbs = 0, msbs = 0;
  82897. unsigned bit, uval, k;
  82898. FLAC__ASSERT(0 != br);
  82899. FLAC__ASSERT(0 != br->buffer);
  82900. k = FLAC__bitmath_ilog2(parameter);
  82901. if(!FLAC__bitreader_read_unary_unsigned(br, &msbs))
  82902. return false;
  82903. if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, k))
  82904. return false;
  82905. if(parameter == 1u<<k) {
  82906. uval = (msbs << k) | lsbs;
  82907. }
  82908. else {
  82909. unsigned d = (1 << (k+1)) - parameter;
  82910. if(lsbs >= d) {
  82911. if(!FLAC__bitreader_read_bit(br, &bit))
  82912. return false;
  82913. lsbs <<= 1;
  82914. lsbs |= bit;
  82915. lsbs -= d;
  82916. }
  82917. uval = msbs * parameter + lsbs;
  82918. }
  82919. if(uval & 1)
  82920. *val = -((int)(uval >> 1)) - 1;
  82921. else
  82922. *val = (int)(uval >> 1);
  82923. return true;
  82924. }
  82925. FLAC__bool FLAC__bitreader_read_golomb_unsigned(FLAC__BitReader *br, unsigned *val, unsigned parameter)
  82926. {
  82927. FLAC__uint32 lsbs, msbs = 0;
  82928. unsigned bit, k;
  82929. FLAC__ASSERT(0 != br);
  82930. FLAC__ASSERT(0 != br->buffer);
  82931. k = FLAC__bitmath_ilog2(parameter);
  82932. if(!FLAC__bitreader_read_unary_unsigned(br, &msbs))
  82933. return false;
  82934. if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, k))
  82935. return false;
  82936. if(parameter == 1u<<k) {
  82937. *val = (msbs << k) | lsbs;
  82938. }
  82939. else {
  82940. unsigned d = (1 << (k+1)) - parameter;
  82941. if(lsbs >= d) {
  82942. if(!FLAC__bitreader_read_bit(br, &bit))
  82943. return false;
  82944. lsbs <<= 1;
  82945. lsbs |= bit;
  82946. lsbs -= d;
  82947. }
  82948. *val = msbs * parameter + lsbs;
  82949. }
  82950. return true;
  82951. }
  82952. #endif /* UNUSED */
  82953. FLAC__bool FLAC__bitreader_read_utf8_uint32(FLAC__BitReader *br, FLAC__uint32 *val, FLAC__byte *raw, unsigned *rawlen)
  82954. {
  82955. FLAC__uint32 v = 0;
  82956. FLAC__uint32 x;
  82957. unsigned i;
  82958. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82959. return false;
  82960. if(raw)
  82961. raw[(*rawlen)++] = (FLAC__byte)x;
  82962. if(!(x & 0x80)) { /* 0xxxxxxx */
  82963. v = x;
  82964. i = 0;
  82965. }
  82966. else if(x & 0xC0 && !(x & 0x20)) { /* 110xxxxx */
  82967. v = x & 0x1F;
  82968. i = 1;
  82969. }
  82970. else if(x & 0xE0 && !(x & 0x10)) { /* 1110xxxx */
  82971. v = x & 0x0F;
  82972. i = 2;
  82973. }
  82974. else if(x & 0xF0 && !(x & 0x08)) { /* 11110xxx */
  82975. v = x & 0x07;
  82976. i = 3;
  82977. }
  82978. else if(x & 0xF8 && !(x & 0x04)) { /* 111110xx */
  82979. v = x & 0x03;
  82980. i = 4;
  82981. }
  82982. else if(x & 0xFC && !(x & 0x02)) { /* 1111110x */
  82983. v = x & 0x01;
  82984. i = 5;
  82985. }
  82986. else {
  82987. *val = 0xffffffff;
  82988. return true;
  82989. }
  82990. for( ; i; i--) {
  82991. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82992. return false;
  82993. if(raw)
  82994. raw[(*rawlen)++] = (FLAC__byte)x;
  82995. if(!(x & 0x80) || (x & 0x40)) { /* 10xxxxxx */
  82996. *val = 0xffffffff;
  82997. return true;
  82998. }
  82999. v <<= 6;
  83000. v |= (x & 0x3F);
  83001. }
  83002. *val = v;
  83003. return true;
  83004. }
  83005. FLAC__bool FLAC__bitreader_read_utf8_uint64(FLAC__BitReader *br, FLAC__uint64 *val, FLAC__byte *raw, unsigned *rawlen)
  83006. {
  83007. FLAC__uint64 v = 0;
  83008. FLAC__uint32 x;
  83009. unsigned i;
  83010. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  83011. return false;
  83012. if(raw)
  83013. raw[(*rawlen)++] = (FLAC__byte)x;
  83014. if(!(x & 0x80)) { /* 0xxxxxxx */
  83015. v = x;
  83016. i = 0;
  83017. }
  83018. else if(x & 0xC0 && !(x & 0x20)) { /* 110xxxxx */
  83019. v = x & 0x1F;
  83020. i = 1;
  83021. }
  83022. else if(x & 0xE0 && !(x & 0x10)) { /* 1110xxxx */
  83023. v = x & 0x0F;
  83024. i = 2;
  83025. }
  83026. else if(x & 0xF0 && !(x & 0x08)) { /* 11110xxx */
  83027. v = x & 0x07;
  83028. i = 3;
  83029. }
  83030. else if(x & 0xF8 && !(x & 0x04)) { /* 111110xx */
  83031. v = x & 0x03;
  83032. i = 4;
  83033. }
  83034. else if(x & 0xFC && !(x & 0x02)) { /* 1111110x */
  83035. v = x & 0x01;
  83036. i = 5;
  83037. }
  83038. else if(x & 0xFE && !(x & 0x01)) { /* 11111110 */
  83039. v = 0;
  83040. i = 6;
  83041. }
  83042. else {
  83043. *val = FLAC__U64L(0xffffffffffffffff);
  83044. return true;
  83045. }
  83046. for( ; i; i--) {
  83047. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  83048. return false;
  83049. if(raw)
  83050. raw[(*rawlen)++] = (FLAC__byte)x;
  83051. if(!(x & 0x80) || (x & 0x40)) { /* 10xxxxxx */
  83052. *val = FLAC__U64L(0xffffffffffffffff);
  83053. return true;
  83054. }
  83055. v <<= 6;
  83056. v |= (x & 0x3F);
  83057. }
  83058. *val = v;
  83059. return true;
  83060. }
  83061. #endif
  83062. /*** End of inlined file: bitreader.c ***/
  83063. /*** Start of inlined file: bitwriter.c ***/
  83064. /*** Start of inlined file: juce_FlacHeader.h ***/
  83065. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  83066. // tasks..
  83067. #define VERSION "1.2.1"
  83068. #define FLAC__NO_DLL 1
  83069. #if JUCE_MSVC
  83070. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  83071. #endif
  83072. #if JUCE_MAC
  83073. #define FLAC__SYS_DARWIN 1
  83074. #endif
  83075. /*** End of inlined file: juce_FlacHeader.h ***/
  83076. #if JUCE_USE_FLAC
  83077. #if HAVE_CONFIG_H
  83078. # include <config.h>
  83079. #endif
  83080. #include <stdlib.h> /* for malloc() */
  83081. #include <string.h> /* for memcpy(), memset() */
  83082. #ifdef _MSC_VER
  83083. #include <winsock.h> /* for ntohl() */
  83084. #elif defined FLAC__SYS_DARWIN
  83085. #include <machine/endian.h> /* for ntohl() */
  83086. #elif defined __MINGW32__
  83087. #include <winsock.h> /* for ntohl() */
  83088. #else
  83089. #include <netinet/in.h> /* for ntohl() */
  83090. #endif
  83091. #if 0 /* UNUSED */
  83092. #endif
  83093. /*** Start of inlined file: bitwriter.h ***/
  83094. #ifndef FLAC__PRIVATE__BITWRITER_H
  83095. #define FLAC__PRIVATE__BITWRITER_H
  83096. #include <stdio.h> /* for FILE */
  83097. struct FLAC__BitWriter;
  83098. typedef struct FLAC__BitWriter FLAC__BitWriter;
  83099. FLAC__BitWriter *FLAC__bitwriter_new(void);
  83100. void FLAC__bitwriter_delete(FLAC__BitWriter *bw);
  83101. FLAC__bool FLAC__bitwriter_init(FLAC__BitWriter *bw);
  83102. void FLAC__bitwriter_free(FLAC__BitWriter *bw); /* does not 'free(buffer)' */
  83103. void FLAC__bitwriter_clear(FLAC__BitWriter *bw);
  83104. void FLAC__bitwriter_dump(const FLAC__BitWriter *bw, FILE *out);
  83105. FLAC__bool FLAC__bitwriter_get_write_crc16(FLAC__BitWriter *bw, FLAC__uint16 *crc);
  83106. FLAC__bool FLAC__bitwriter_get_write_crc8(FLAC__BitWriter *bw, FLAC__byte *crc);
  83107. FLAC__bool FLAC__bitwriter_is_byte_aligned(const FLAC__BitWriter *bw);
  83108. unsigned FLAC__bitwriter_get_input_bits_unconsumed(const FLAC__BitWriter *bw); /* can be called anytime, returns total # of bits unconsumed */
  83109. FLAC__bool FLAC__bitwriter_get_buffer(FLAC__BitWriter *bw, const FLAC__byte **buffer, size_t *bytes);
  83110. void FLAC__bitwriter_release_buffer(FLAC__BitWriter *bw);
  83111. FLAC__bool FLAC__bitwriter_write_zeroes(FLAC__BitWriter *bw, unsigned bits);
  83112. FLAC__bool FLAC__bitwriter_write_raw_uint32(FLAC__BitWriter *bw, FLAC__uint32 val, unsigned bits);
  83113. FLAC__bool FLAC__bitwriter_write_raw_int32(FLAC__BitWriter *bw, FLAC__int32 val, unsigned bits);
  83114. FLAC__bool FLAC__bitwriter_write_raw_uint64(FLAC__BitWriter *bw, FLAC__uint64 val, unsigned bits);
  83115. FLAC__bool FLAC__bitwriter_write_raw_uint32_little_endian(FLAC__BitWriter *bw, FLAC__uint32 val); /*only for bits=32*/
  83116. FLAC__bool FLAC__bitwriter_write_byte_block(FLAC__BitWriter *bw, const FLAC__byte vals[], unsigned nvals);
  83117. FLAC__bool FLAC__bitwriter_write_unary_unsigned(FLAC__BitWriter *bw, unsigned val);
  83118. unsigned FLAC__bitwriter_rice_bits(FLAC__int32 val, unsigned parameter);
  83119. #if 0 /* UNUSED */
  83120. unsigned FLAC__bitwriter_golomb_bits_signed(int val, unsigned parameter);
  83121. unsigned FLAC__bitwriter_golomb_bits_unsigned(unsigned val, unsigned parameter);
  83122. #endif
  83123. FLAC__bool FLAC__bitwriter_write_rice_signed(FLAC__BitWriter *bw, FLAC__int32 val, unsigned parameter);
  83124. FLAC__bool FLAC__bitwriter_write_rice_signed_block(FLAC__BitWriter *bw, const FLAC__int32 *vals, unsigned nvals, unsigned parameter);
  83125. #if 0 /* UNUSED */
  83126. FLAC__bool FLAC__bitwriter_write_golomb_signed(FLAC__BitWriter *bw, int val, unsigned parameter);
  83127. FLAC__bool FLAC__bitwriter_write_golomb_unsigned(FLAC__BitWriter *bw, unsigned val, unsigned parameter);
  83128. #endif
  83129. FLAC__bool FLAC__bitwriter_write_utf8_uint32(FLAC__BitWriter *bw, FLAC__uint32 val);
  83130. FLAC__bool FLAC__bitwriter_write_utf8_uint64(FLAC__BitWriter *bw, FLAC__uint64 val);
  83131. FLAC__bool FLAC__bitwriter_zero_pad_to_byte_boundary(FLAC__BitWriter *bw);
  83132. #endif
  83133. /*** End of inlined file: bitwriter.h ***/
  83134. /*** Start of inlined file: alloc.h ***/
  83135. #ifndef FLAC__SHARE__ALLOC_H
  83136. #define FLAC__SHARE__ALLOC_H
  83137. #if HAVE_CONFIG_H
  83138. # include <config.h>
  83139. #endif
  83140. #include <limits.h> /* for SIZE_MAX */
  83141. #if !defined _MSC_VER && !defined __MINGW32__ && !defined __EMX__
  83142. #include <stdint.h> /* for SIZE_MAX in case limits.h didn't get it */
  83143. #endif
  83144. #include <stdlib.h> /* for size_t, malloc(), etc */
  83145. #ifndef SIZE_MAX
  83146. # ifndef SIZE_T_MAX
  83147. # ifdef _MSC_VER
  83148. # define SIZE_T_MAX UINT_MAX
  83149. # else
  83150. # error
  83151. # endif
  83152. # endif
  83153. # define SIZE_MAX SIZE_T_MAX
  83154. #endif
  83155. #ifndef FLaC__INLINE
  83156. #define FLaC__INLINE
  83157. #endif
  83158. static FLaC__INLINE void *safe_malloc_(size_t size)
  83159. {
  83160. if(!size)
  83161. size++;
  83162. return malloc(size);
  83163. }
  83164. static FLaC__INLINE void *safe_calloc_(size_t nmemb, size_t size)
  83165. {
  83166. if(!nmemb || !size)
  83167. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  83168. return calloc(nmemb, size);
  83169. }
  83170. static FLaC__INLINE void *safe_malloc_add_2op_(size_t size1, size_t size2)
  83171. {
  83172. size2 += size1;
  83173. if(size2 < size1)
  83174. return 0;
  83175. return safe_malloc_(size2);
  83176. }
  83177. static FLaC__INLINE void *safe_malloc_add_3op_(size_t size1, size_t size2, size_t size3)
  83178. {
  83179. size2 += size1;
  83180. if(size2 < size1)
  83181. return 0;
  83182. size3 += size2;
  83183. if(size3 < size2)
  83184. return 0;
  83185. return safe_malloc_(size3);
  83186. }
  83187. static FLaC__INLINE void *safe_malloc_add_4op_(size_t size1, size_t size2, size_t size3, size_t size4)
  83188. {
  83189. size2 += size1;
  83190. if(size2 < size1)
  83191. return 0;
  83192. size3 += size2;
  83193. if(size3 < size2)
  83194. return 0;
  83195. size4 += size3;
  83196. if(size4 < size3)
  83197. return 0;
  83198. return safe_malloc_(size4);
  83199. }
  83200. static FLaC__INLINE void *safe_malloc_mul_2op_(size_t size1, size_t size2)
  83201. #if 0
  83202. needs support for cases where sizeof(size_t) != 4
  83203. {
  83204. if(sizeof(size_t) == 4) {
  83205. if ((double)size1 * (double)size2 < 4294967296.0)
  83206. return malloc(size1*size2);
  83207. }
  83208. return 0;
  83209. }
  83210. #else
  83211. {
  83212. if(!size1 || !size2)
  83213. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  83214. if(size1 > SIZE_MAX / size2)
  83215. return 0;
  83216. return malloc(size1*size2);
  83217. }
  83218. #endif
  83219. static FLaC__INLINE void *safe_malloc_mul_3op_(size_t size1, size_t size2, size_t size3)
  83220. {
  83221. if(!size1 || !size2 || !size3)
  83222. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  83223. if(size1 > SIZE_MAX / size2)
  83224. return 0;
  83225. size1 *= size2;
  83226. if(size1 > SIZE_MAX / size3)
  83227. return 0;
  83228. return malloc(size1*size3);
  83229. }
  83230. static FLaC__INLINE void *safe_malloc_mul2add_(size_t size1, size_t size2, size_t size3)
  83231. {
  83232. if(!size1 || !size2)
  83233. return safe_malloc_(size3);
  83234. if(size1 > SIZE_MAX / size2)
  83235. return 0;
  83236. return safe_malloc_add_2op_(size1*size2, size3);
  83237. }
  83238. static FLaC__INLINE void *safe_malloc_muladd2_(size_t size1, size_t size2, size_t size3)
  83239. {
  83240. if(!size1 || (!size2 && !size3))
  83241. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  83242. size2 += size3;
  83243. if(size2 < size3)
  83244. return 0;
  83245. return safe_malloc_mul_2op_(size1, size2);
  83246. }
  83247. static FLaC__INLINE void *safe_realloc_add_2op_(void *ptr, size_t size1, size_t size2)
  83248. {
  83249. size2 += size1;
  83250. if(size2 < size1)
  83251. return 0;
  83252. return realloc(ptr, size2);
  83253. }
  83254. static FLaC__INLINE void *safe_realloc_add_3op_(void *ptr, size_t size1, size_t size2, size_t size3)
  83255. {
  83256. size2 += size1;
  83257. if(size2 < size1)
  83258. return 0;
  83259. size3 += size2;
  83260. if(size3 < size2)
  83261. return 0;
  83262. return realloc(ptr, size3);
  83263. }
  83264. static FLaC__INLINE void *safe_realloc_add_4op_(void *ptr, size_t size1, size_t size2, size_t size3, size_t size4)
  83265. {
  83266. size2 += size1;
  83267. if(size2 < size1)
  83268. return 0;
  83269. size3 += size2;
  83270. if(size3 < size2)
  83271. return 0;
  83272. size4 += size3;
  83273. if(size4 < size3)
  83274. return 0;
  83275. return realloc(ptr, size4);
  83276. }
  83277. static FLaC__INLINE void *safe_realloc_mul_2op_(void *ptr, size_t size1, size_t size2)
  83278. {
  83279. if(!size1 || !size2)
  83280. return realloc(ptr, 0); /* preserve POSIX realloc(ptr, 0) semantics */
  83281. if(size1 > SIZE_MAX / size2)
  83282. return 0;
  83283. return realloc(ptr, size1*size2);
  83284. }
  83285. static FLaC__INLINE void *safe_realloc_muladd2_(void *ptr, size_t size1, size_t size2, size_t size3)
  83286. {
  83287. if(!size1 || (!size2 && !size3))
  83288. return realloc(ptr, 0); /* preserve POSIX realloc(ptr, 0) semantics */
  83289. size2 += size3;
  83290. if(size2 < size3)
  83291. return 0;
  83292. return safe_realloc_mul_2op_(ptr, size1, size2);
  83293. }
  83294. #endif
  83295. /*** End of inlined file: alloc.h ***/
  83296. typedef FLAC__uint32 bwword;
  83297. #define FLAC__BYTES_PER_WORD 4
  83298. #define FLAC__BITS_PER_WORD 32
  83299. #define FLAC__WORD_ALL_ONES ((FLAC__uint32)0xffffffff)
  83300. #if WORDS_BIGENDIAN
  83301. #define SWAP_BE_WORD_TO_HOST(x) (x)
  83302. #else
  83303. #ifdef _MSC_VER
  83304. #define SWAP_BE_WORD_TO_HOST(x) local_swap32_(x)
  83305. #else
  83306. #define SWAP_BE_WORD_TO_HOST(x) ntohl(x)
  83307. #endif
  83308. #endif
  83309. static const unsigned FLAC__BITWRITER_DEFAULT_CAPACITY = 32768u / sizeof(bwword); /* size in words */
  83310. static const unsigned FLAC__BITWRITER_DEFAULT_INCREMENT = 4096u / sizeof(bwword); /* size in words */
  83311. #define FLAC__WORDS_TO_BITS(words) ((words) * FLAC__BITS_PER_WORD)
  83312. #define FLAC__TOTAL_BITS(bw) (FLAC__WORDS_TO_BITS((bw)->words) + (bw)->bits)
  83313. #ifdef min
  83314. #undef min
  83315. #endif
  83316. #define min(x,y) ((x)<(y)?(x):(y))
  83317. #ifdef _MSC_VER
  83318. #define FLAC__U64L(x) x
  83319. #else
  83320. #define FLAC__U64L(x) x##LLU
  83321. #endif
  83322. #ifndef FLaC__INLINE
  83323. #define FLaC__INLINE
  83324. #endif
  83325. struct FLAC__BitWriter {
  83326. bwword *buffer;
  83327. bwword accum; /* accumulator; bits are right-justified; when full, accum is appended to buffer */
  83328. unsigned capacity; /* capacity of buffer in words */
  83329. unsigned words; /* # of complete words in buffer */
  83330. unsigned bits; /* # of used bits in accum */
  83331. };
  83332. static FLAC__bool bitwriter_grow_(FLAC__BitWriter *bw, unsigned bits_to_add)
  83333. {
  83334. unsigned new_capacity;
  83335. bwword *new_buffer;
  83336. FLAC__ASSERT(0 != bw);
  83337. FLAC__ASSERT(0 != bw->buffer);
  83338. new_capacity = bw->words + ((bw->bits + bits_to_add + FLAC__BITS_PER_WORD - 1) / FLAC__BITS_PER_WORD);
  83339. if(bw->capacity >= new_capacity)
  83340. return true;
  83341. if((new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT)
  83342. new_capacity += FLAC__BITWRITER_DEFAULT_INCREMENT - ((new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT);
  83343. FLAC__ASSERT(0 == (new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT);
  83344. FLAC__ASSERT(new_capacity > bw->capacity);
  83345. FLAC__ASSERT(new_capacity >= bw->words + ((bw->bits + bits_to_add + FLAC__BITS_PER_WORD - 1) / FLAC__BITS_PER_WORD));
  83346. new_buffer = (bwword*)safe_realloc_mul_2op_(bw->buffer, sizeof(bwword), /*times*/new_capacity);
  83347. if(new_buffer == 0)
  83348. return false;
  83349. bw->buffer = new_buffer;
  83350. bw->capacity = new_capacity;
  83351. return true;
  83352. }
  83353. FLAC__BitWriter *FLAC__bitwriter_new(void)
  83354. {
  83355. FLAC__BitWriter *bw = (FLAC__BitWriter*)calloc(1, sizeof(FLAC__BitWriter));
  83356. return bw;
  83357. }
  83358. void FLAC__bitwriter_delete(FLAC__BitWriter *bw)
  83359. {
  83360. FLAC__ASSERT(0 != bw);
  83361. FLAC__bitwriter_free(bw);
  83362. free(bw);
  83363. }
  83364. FLAC__bool FLAC__bitwriter_init(FLAC__BitWriter *bw)
  83365. {
  83366. FLAC__ASSERT(0 != bw);
  83367. bw->words = bw->bits = 0;
  83368. bw->capacity = FLAC__BITWRITER_DEFAULT_CAPACITY;
  83369. bw->buffer = (bwword*)malloc(sizeof(bwword) * bw->capacity);
  83370. if(bw->buffer == 0)
  83371. return false;
  83372. return true;
  83373. }
  83374. void FLAC__bitwriter_free(FLAC__BitWriter *bw)
  83375. {
  83376. FLAC__ASSERT(0 != bw);
  83377. if(0 != bw->buffer)
  83378. free(bw->buffer);
  83379. bw->buffer = 0;
  83380. bw->capacity = 0;
  83381. bw->words = bw->bits = 0;
  83382. }
  83383. void FLAC__bitwriter_clear(FLAC__BitWriter *bw)
  83384. {
  83385. bw->words = bw->bits = 0;
  83386. }
  83387. void FLAC__bitwriter_dump(const FLAC__BitWriter *bw, FILE *out)
  83388. {
  83389. unsigned i, j;
  83390. if(bw == 0) {
  83391. fprintf(out, "bitwriter is NULL\n");
  83392. }
  83393. else {
  83394. fprintf(out, "bitwriter: capacity=%u words=%u bits=%u total_bits=%u\n", bw->capacity, bw->words, bw->bits, FLAC__TOTAL_BITS(bw));
  83395. for(i = 0; i < bw->words; i++) {
  83396. fprintf(out, "%08X: ", i);
  83397. for(j = 0; j < FLAC__BITS_PER_WORD; j++)
  83398. fprintf(out, "%01u", bw->buffer[i] & (1 << (FLAC__BITS_PER_WORD-j-1)) ? 1:0);
  83399. fprintf(out, "\n");
  83400. }
  83401. if(bw->bits > 0) {
  83402. fprintf(out, "%08X: ", i);
  83403. for(j = 0; j < bw->bits; j++)
  83404. fprintf(out, "%01u", bw->accum & (1 << (bw->bits-j-1)) ? 1:0);
  83405. fprintf(out, "\n");
  83406. }
  83407. }
  83408. }
  83409. FLAC__bool FLAC__bitwriter_get_write_crc16(FLAC__BitWriter *bw, FLAC__uint16 *crc)
  83410. {
  83411. const FLAC__byte *buffer;
  83412. size_t bytes;
  83413. FLAC__ASSERT((bw->bits & 7) == 0); /* assert that we're byte-aligned */
  83414. if(!FLAC__bitwriter_get_buffer(bw, &buffer, &bytes))
  83415. return false;
  83416. *crc = (FLAC__uint16)FLAC__crc16(buffer, bytes);
  83417. FLAC__bitwriter_release_buffer(bw);
  83418. return true;
  83419. }
  83420. FLAC__bool FLAC__bitwriter_get_write_crc8(FLAC__BitWriter *bw, FLAC__byte *crc)
  83421. {
  83422. const FLAC__byte *buffer;
  83423. size_t bytes;
  83424. FLAC__ASSERT((bw->bits & 7) == 0); /* assert that we're byte-aligned */
  83425. if(!FLAC__bitwriter_get_buffer(bw, &buffer, &bytes))
  83426. return false;
  83427. *crc = FLAC__crc8(buffer, bytes);
  83428. FLAC__bitwriter_release_buffer(bw);
  83429. return true;
  83430. }
  83431. FLAC__bool FLAC__bitwriter_is_byte_aligned(const FLAC__BitWriter *bw)
  83432. {
  83433. return ((bw->bits & 7) == 0);
  83434. }
  83435. unsigned FLAC__bitwriter_get_input_bits_unconsumed(const FLAC__BitWriter *bw)
  83436. {
  83437. return FLAC__TOTAL_BITS(bw);
  83438. }
  83439. FLAC__bool FLAC__bitwriter_get_buffer(FLAC__BitWriter *bw, const FLAC__byte **buffer, size_t *bytes)
  83440. {
  83441. FLAC__ASSERT((bw->bits & 7) == 0);
  83442. if(bw->bits & 7)
  83443. return false;
  83444. if(bw->bits) {
  83445. FLAC__ASSERT(bw->words <= bw->capacity);
  83446. if(bw->words == bw->capacity && !bitwriter_grow_(bw, FLAC__BITS_PER_WORD))
  83447. return false;
  83448. bw->buffer[bw->words] = SWAP_BE_WORD_TO_HOST(bw->accum << (FLAC__BITS_PER_WORD-bw->bits));
  83449. }
  83450. *buffer = (FLAC__byte*)bw->buffer;
  83451. *bytes = (FLAC__BYTES_PER_WORD * bw->words) + (bw->bits >> 3);
  83452. return true;
  83453. }
  83454. void FLAC__bitwriter_release_buffer(FLAC__BitWriter *bw)
  83455. {
  83456. (void)bw;
  83457. }
  83458. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_zeroes(FLAC__BitWriter *bw, unsigned bits)
  83459. {
  83460. unsigned n;
  83461. FLAC__ASSERT(0 != bw);
  83462. FLAC__ASSERT(0 != bw->buffer);
  83463. if(bits == 0)
  83464. return true;
  83465. if(bw->capacity <= bw->words + bits && !bitwriter_grow_(bw, bits))
  83466. return false;
  83467. if(bw->bits) {
  83468. n = min(FLAC__BITS_PER_WORD - bw->bits, bits);
  83469. bw->accum <<= n;
  83470. bits -= n;
  83471. bw->bits += n;
  83472. if(bw->bits == FLAC__BITS_PER_WORD) {
  83473. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83474. bw->bits = 0;
  83475. }
  83476. else
  83477. return true;
  83478. }
  83479. while(bits >= FLAC__BITS_PER_WORD) {
  83480. bw->buffer[bw->words++] = 0;
  83481. bits -= FLAC__BITS_PER_WORD;
  83482. }
  83483. if(bits > 0) {
  83484. bw->accum = 0;
  83485. bw->bits = bits;
  83486. }
  83487. return true;
  83488. }
  83489. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_uint32(FLAC__BitWriter *bw, FLAC__uint32 val, unsigned bits)
  83490. {
  83491. register unsigned left;
  83492. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  83493. FLAC__ASSERT(0 != bw);
  83494. FLAC__ASSERT(0 != bw->buffer);
  83495. FLAC__ASSERT(bits <= 32);
  83496. if(bits == 0)
  83497. return true;
  83498. if(bw->capacity <= bw->words + bits && !bitwriter_grow_(bw, bits))
  83499. return false;
  83500. left = FLAC__BITS_PER_WORD - bw->bits;
  83501. if(bits < left) {
  83502. bw->accum <<= bits;
  83503. bw->accum |= val;
  83504. bw->bits += bits;
  83505. }
  83506. 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 */
  83507. bw->accum <<= left;
  83508. bw->accum |= val >> (bw->bits = bits - left);
  83509. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83510. bw->accum = val;
  83511. }
  83512. else {
  83513. bw->accum = val;
  83514. bw->bits = 0;
  83515. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(val);
  83516. }
  83517. return true;
  83518. }
  83519. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_int32(FLAC__BitWriter *bw, FLAC__int32 val, unsigned bits)
  83520. {
  83521. if(bits < 32)
  83522. val &= (~(0xffffffff << bits));
  83523. return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, bits);
  83524. }
  83525. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_uint64(FLAC__BitWriter *bw, FLAC__uint64 val, unsigned bits)
  83526. {
  83527. if(bits > 32) {
  83528. return
  83529. FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)(val>>32), bits-32) &&
  83530. FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, 32);
  83531. }
  83532. else
  83533. return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, bits);
  83534. }
  83535. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_uint32_little_endian(FLAC__BitWriter *bw, FLAC__uint32 val)
  83536. {
  83537. if(!FLAC__bitwriter_write_raw_uint32(bw, val & 0xff, 8))
  83538. return false;
  83539. if(!FLAC__bitwriter_write_raw_uint32(bw, (val>>8) & 0xff, 8))
  83540. return false;
  83541. if(!FLAC__bitwriter_write_raw_uint32(bw, (val>>16) & 0xff, 8))
  83542. return false;
  83543. if(!FLAC__bitwriter_write_raw_uint32(bw, val>>24, 8))
  83544. return false;
  83545. return true;
  83546. }
  83547. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_byte_block(FLAC__BitWriter *bw, const FLAC__byte vals[], unsigned nvals)
  83548. {
  83549. unsigned i;
  83550. for(i = 0; i < nvals; i++) {
  83551. if(!FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)(vals[i]), 8))
  83552. return false;
  83553. }
  83554. return true;
  83555. }
  83556. FLAC__bool FLAC__bitwriter_write_unary_unsigned(FLAC__BitWriter *bw, unsigned val)
  83557. {
  83558. if(val < 32)
  83559. return FLAC__bitwriter_write_raw_uint32(bw, 1, ++val);
  83560. else
  83561. return
  83562. FLAC__bitwriter_write_zeroes(bw, val) &&
  83563. FLAC__bitwriter_write_raw_uint32(bw, 1, 1);
  83564. }
  83565. unsigned FLAC__bitwriter_rice_bits(FLAC__int32 val, unsigned parameter)
  83566. {
  83567. FLAC__uint32 uval;
  83568. FLAC__ASSERT(parameter < sizeof(unsigned)*8);
  83569. uval = (val<<1) ^ (val>>31);
  83570. return 1 + parameter + (uval >> parameter);
  83571. }
  83572. #if 0 /* UNUSED */
  83573. unsigned FLAC__bitwriter_golomb_bits_signed(int val, unsigned parameter)
  83574. {
  83575. unsigned bits, msbs, uval;
  83576. unsigned k;
  83577. FLAC__ASSERT(parameter > 0);
  83578. if(val < 0)
  83579. uval = (unsigned)(((-(++val)) << 1) + 1);
  83580. else
  83581. uval = (unsigned)(val << 1);
  83582. k = FLAC__bitmath_ilog2(parameter);
  83583. if(parameter == 1u<<k) {
  83584. FLAC__ASSERT(k <= 30);
  83585. msbs = uval >> k;
  83586. bits = 1 + k + msbs;
  83587. }
  83588. else {
  83589. unsigned q, r, d;
  83590. d = (1 << (k+1)) - parameter;
  83591. q = uval / parameter;
  83592. r = uval - (q * parameter);
  83593. bits = 1 + q + k;
  83594. if(r >= d)
  83595. bits++;
  83596. }
  83597. return bits;
  83598. }
  83599. unsigned FLAC__bitwriter_golomb_bits_unsigned(unsigned uval, unsigned parameter)
  83600. {
  83601. unsigned bits, msbs;
  83602. unsigned k;
  83603. FLAC__ASSERT(parameter > 0);
  83604. k = FLAC__bitmath_ilog2(parameter);
  83605. if(parameter == 1u<<k) {
  83606. FLAC__ASSERT(k <= 30);
  83607. msbs = uval >> k;
  83608. bits = 1 + k + msbs;
  83609. }
  83610. else {
  83611. unsigned q, r, d;
  83612. d = (1 << (k+1)) - parameter;
  83613. q = uval / parameter;
  83614. r = uval - (q * parameter);
  83615. bits = 1 + q + k;
  83616. if(r >= d)
  83617. bits++;
  83618. }
  83619. return bits;
  83620. }
  83621. #endif /* UNUSED */
  83622. FLAC__bool FLAC__bitwriter_write_rice_signed(FLAC__BitWriter *bw, FLAC__int32 val, unsigned parameter)
  83623. {
  83624. unsigned total_bits, interesting_bits, msbs;
  83625. FLAC__uint32 uval, pattern;
  83626. FLAC__ASSERT(0 != bw);
  83627. FLAC__ASSERT(0 != bw->buffer);
  83628. FLAC__ASSERT(parameter < 8*sizeof(uval));
  83629. uval = (val<<1) ^ (val>>31);
  83630. msbs = uval >> parameter;
  83631. interesting_bits = 1 + parameter;
  83632. total_bits = interesting_bits + msbs;
  83633. pattern = 1 << parameter; /* the unary end bit */
  83634. pattern |= (uval & ((1<<parameter)-1)); /* the binary LSBs */
  83635. if(total_bits <= 32)
  83636. return FLAC__bitwriter_write_raw_uint32(bw, pattern, total_bits);
  83637. else
  83638. return
  83639. FLAC__bitwriter_write_zeroes(bw, msbs) && /* write the unary MSBs */
  83640. FLAC__bitwriter_write_raw_uint32(bw, pattern, interesting_bits); /* write the unary end bit and binary LSBs */
  83641. }
  83642. FLAC__bool FLAC__bitwriter_write_rice_signed_block(FLAC__BitWriter *bw, const FLAC__int32 *vals, unsigned nvals, unsigned parameter)
  83643. {
  83644. const FLAC__uint32 mask1 = FLAC__WORD_ALL_ONES << parameter; /* we val|=mask1 to set the stop bit above it... */
  83645. const FLAC__uint32 mask2 = FLAC__WORD_ALL_ONES >> (31-parameter); /* ...then mask off the bits above the stop bit with val&=mask2*/
  83646. FLAC__uint32 uval;
  83647. unsigned left;
  83648. const unsigned lsbits = 1 + parameter;
  83649. unsigned msbits;
  83650. FLAC__ASSERT(0 != bw);
  83651. FLAC__ASSERT(0 != bw->buffer);
  83652. FLAC__ASSERT(parameter < 8*sizeof(bwword)-1);
  83653. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  83654. while(nvals) {
  83655. uval = (*vals<<1) ^ (*vals>>31);
  83656. msbits = uval >> parameter;
  83657. #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) */
  83658. if(bw->bits && bw->bits + msbits + lsbits <= FLAC__BITS_PER_WORD) { /* i.e. if the whole thing fits in the current bwword */
  83659. bw->bits = bw->bits + msbits + lsbits;
  83660. uval |= mask1; /* set stop bit */
  83661. uval &= mask2; /* mask off unused top bits */
  83662. bw->accum <<= msbits;
  83663. bw->accum <<= lsbits;
  83664. bw->accum |= uval;
  83665. if(bw->bits == FLAC__BITS_PER_WORD) {
  83666. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83667. bw->bits = 0;
  83668. if(bw->capacity <= bw->words && nvals > 1 && !bitwriter_grow_(bw, 1)) {
  83669. FLAC__ASSERT(bw->capacity == bw->words);
  83670. return false;
  83671. }
  83672. }
  83673. }
  83674. else {
  83675. #elif 1 /*@@@@@@ OPT: try this version with MSVC6 to see if better, not much difference for gcc-4 */
  83676. if(bw->bits && bw->bits + msbits + lsbits < FLAC__BITS_PER_WORD) { /* i.e. if the whole thing fits in the current bwword */
  83677. bw->bits = bw->bits + msbits + lsbits;
  83678. uval |= mask1; /* set stop bit */
  83679. uval &= mask2; /* mask off unused top bits */
  83680. bw->accum <<= msbits + lsbits;
  83681. bw->accum |= uval;
  83682. }
  83683. else {
  83684. #endif
  83685. if(bw->capacity <= bw->words + bw->bits + msbits + 1/*lsbits always fit in 1 bwword*/ && !bitwriter_grow_(bw, msbits+lsbits))
  83686. return false;
  83687. if(msbits) {
  83688. if(bw->bits) {
  83689. left = FLAC__BITS_PER_WORD - bw->bits;
  83690. if(msbits < left) {
  83691. bw->accum <<= msbits;
  83692. bw->bits += msbits;
  83693. goto break1;
  83694. }
  83695. else {
  83696. bw->accum <<= left;
  83697. msbits -= left;
  83698. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83699. bw->bits = 0;
  83700. }
  83701. }
  83702. while(msbits >= FLAC__BITS_PER_WORD) {
  83703. bw->buffer[bw->words++] = 0;
  83704. msbits -= FLAC__BITS_PER_WORD;
  83705. }
  83706. if(msbits > 0) {
  83707. bw->accum = 0;
  83708. bw->bits = msbits;
  83709. }
  83710. }
  83711. break1:
  83712. uval |= mask1; /* set stop bit */
  83713. uval &= mask2; /* mask off unused top bits */
  83714. left = FLAC__BITS_PER_WORD - bw->bits;
  83715. if(lsbits < left) {
  83716. bw->accum <<= lsbits;
  83717. bw->accum |= uval;
  83718. bw->bits += lsbits;
  83719. }
  83720. else {
  83721. FLAC__ASSERT(bw->bits);
  83722. FLAC__ASSERT(left < FLAC__BITS_PER_WORD);
  83723. bw->accum <<= left;
  83724. bw->accum |= uval >> (bw->bits = lsbits - left);
  83725. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83726. bw->accum = uval;
  83727. }
  83728. #if 1
  83729. }
  83730. #endif
  83731. vals++;
  83732. nvals--;
  83733. }
  83734. return true;
  83735. }
  83736. #if 0 /* UNUSED */
  83737. FLAC__bool FLAC__bitwriter_write_golomb_signed(FLAC__BitWriter *bw, int val, unsigned parameter)
  83738. {
  83739. unsigned total_bits, msbs, uval;
  83740. unsigned k;
  83741. FLAC__ASSERT(0 != bw);
  83742. FLAC__ASSERT(0 != bw->buffer);
  83743. FLAC__ASSERT(parameter > 0);
  83744. if(val < 0)
  83745. uval = (unsigned)(((-(++val)) << 1) + 1);
  83746. else
  83747. uval = (unsigned)(val << 1);
  83748. k = FLAC__bitmath_ilog2(parameter);
  83749. if(parameter == 1u<<k) {
  83750. unsigned pattern;
  83751. FLAC__ASSERT(k <= 30);
  83752. msbs = uval >> k;
  83753. total_bits = 1 + k + msbs;
  83754. pattern = 1 << k; /* the unary end bit */
  83755. pattern |= (uval & ((1u<<k)-1)); /* the binary LSBs */
  83756. if(total_bits <= 32) {
  83757. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, total_bits))
  83758. return false;
  83759. }
  83760. else {
  83761. if(!FLAC__bitwriter_write_zeroes(bw, msbs))
  83762. return false;
  83763. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, k+1))
  83764. return false;
  83765. }
  83766. }
  83767. else {
  83768. unsigned q, r, d;
  83769. d = (1 << (k+1)) - parameter;
  83770. q = uval / parameter;
  83771. r = uval - (q * parameter);
  83772. if(!FLAC__bitwriter_write_zeroes(bw, q))
  83773. return false;
  83774. if(!FLAC__bitwriter_write_raw_uint32(bw, 1, 1))
  83775. return false;
  83776. if(r >= d) {
  83777. if(!FLAC__bitwriter_write_raw_uint32(bw, r+d, k+1))
  83778. return false;
  83779. }
  83780. else {
  83781. if(!FLAC__bitwriter_write_raw_uint32(bw, r, k))
  83782. return false;
  83783. }
  83784. }
  83785. return true;
  83786. }
  83787. FLAC__bool FLAC__bitwriter_write_golomb_unsigned(FLAC__BitWriter *bw, unsigned uval, unsigned parameter)
  83788. {
  83789. unsigned total_bits, msbs;
  83790. unsigned k;
  83791. FLAC__ASSERT(0 != bw);
  83792. FLAC__ASSERT(0 != bw->buffer);
  83793. FLAC__ASSERT(parameter > 0);
  83794. k = FLAC__bitmath_ilog2(parameter);
  83795. if(parameter == 1u<<k) {
  83796. unsigned pattern;
  83797. FLAC__ASSERT(k <= 30);
  83798. msbs = uval >> k;
  83799. total_bits = 1 + k + msbs;
  83800. pattern = 1 << k; /* the unary end bit */
  83801. pattern |= (uval & ((1u<<k)-1)); /* the binary LSBs */
  83802. if(total_bits <= 32) {
  83803. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, total_bits))
  83804. return false;
  83805. }
  83806. else {
  83807. if(!FLAC__bitwriter_write_zeroes(bw, msbs))
  83808. return false;
  83809. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, k+1))
  83810. return false;
  83811. }
  83812. }
  83813. else {
  83814. unsigned q, r, d;
  83815. d = (1 << (k+1)) - parameter;
  83816. q = uval / parameter;
  83817. r = uval - (q * parameter);
  83818. if(!FLAC__bitwriter_write_zeroes(bw, q))
  83819. return false;
  83820. if(!FLAC__bitwriter_write_raw_uint32(bw, 1, 1))
  83821. return false;
  83822. if(r >= d) {
  83823. if(!FLAC__bitwriter_write_raw_uint32(bw, r+d, k+1))
  83824. return false;
  83825. }
  83826. else {
  83827. if(!FLAC__bitwriter_write_raw_uint32(bw, r, k))
  83828. return false;
  83829. }
  83830. }
  83831. return true;
  83832. }
  83833. #endif /* UNUSED */
  83834. FLAC__bool FLAC__bitwriter_write_utf8_uint32(FLAC__BitWriter *bw, FLAC__uint32 val)
  83835. {
  83836. FLAC__bool ok = 1;
  83837. FLAC__ASSERT(0 != bw);
  83838. FLAC__ASSERT(0 != bw->buffer);
  83839. FLAC__ASSERT(!(val & 0x80000000)); /* this version only handles 31 bits */
  83840. if(val < 0x80) {
  83841. return FLAC__bitwriter_write_raw_uint32(bw, val, 8);
  83842. }
  83843. else if(val < 0x800) {
  83844. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xC0 | (val>>6), 8);
  83845. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83846. }
  83847. else if(val < 0x10000) {
  83848. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xE0 | (val>>12), 8);
  83849. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83850. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83851. }
  83852. else if(val < 0x200000) {
  83853. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF0 | (val>>18), 8);
  83854. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
  83855. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83856. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83857. }
  83858. else if(val < 0x4000000) {
  83859. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF8 | (val>>24), 8);
  83860. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>18)&0x3F), 8);
  83861. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
  83862. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83863. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83864. }
  83865. else {
  83866. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFC | (val>>30), 8);
  83867. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>24)&0x3F), 8);
  83868. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>18)&0x3F), 8);
  83869. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
  83870. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83871. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83872. }
  83873. return ok;
  83874. }
  83875. FLAC__bool FLAC__bitwriter_write_utf8_uint64(FLAC__BitWriter *bw, FLAC__uint64 val)
  83876. {
  83877. FLAC__bool ok = 1;
  83878. FLAC__ASSERT(0 != bw);
  83879. FLAC__ASSERT(0 != bw->buffer);
  83880. FLAC__ASSERT(!(val & FLAC__U64L(0xFFFFFFF000000000))); /* this version only handles 36 bits */
  83881. if(val < 0x80) {
  83882. return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, 8);
  83883. }
  83884. else if(val < 0x800) {
  83885. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xC0 | (FLAC__uint32)(val>>6), 8);
  83886. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83887. }
  83888. else if(val < 0x10000) {
  83889. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xE0 | (FLAC__uint32)(val>>12), 8);
  83890. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83891. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83892. }
  83893. else if(val < 0x200000) {
  83894. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF0 | (FLAC__uint32)(val>>18), 8);
  83895. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83896. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83897. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83898. }
  83899. else if(val < 0x4000000) {
  83900. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF8 | (FLAC__uint32)(val>>24), 8);
  83901. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
  83902. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83903. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83904. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83905. }
  83906. else if(val < 0x80000000) {
  83907. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFC | (FLAC__uint32)(val>>30), 8);
  83908. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>24)&0x3F), 8);
  83909. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
  83910. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83911. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83912. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83913. }
  83914. else {
  83915. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFE, 8);
  83916. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>30)&0x3F), 8);
  83917. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>24)&0x3F), 8);
  83918. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
  83919. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83920. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83921. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83922. }
  83923. return ok;
  83924. }
  83925. FLAC__bool FLAC__bitwriter_zero_pad_to_byte_boundary(FLAC__BitWriter *bw)
  83926. {
  83927. if(bw->bits & 7u)
  83928. return FLAC__bitwriter_write_zeroes(bw, 8 - (bw->bits & 7u));
  83929. else
  83930. return true;
  83931. }
  83932. #endif
  83933. /*** End of inlined file: bitwriter.c ***/
  83934. /*** Start of inlined file: cpu.c ***/
  83935. /*** Start of inlined file: juce_FlacHeader.h ***/
  83936. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  83937. // tasks..
  83938. #define VERSION "1.2.1"
  83939. #define FLAC__NO_DLL 1
  83940. #if JUCE_MSVC
  83941. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  83942. #endif
  83943. #if JUCE_MAC
  83944. #define FLAC__SYS_DARWIN 1
  83945. #endif
  83946. /*** End of inlined file: juce_FlacHeader.h ***/
  83947. #if JUCE_USE_FLAC
  83948. #if HAVE_CONFIG_H
  83949. # include <config.h>
  83950. #endif
  83951. #include <stdlib.h>
  83952. #include <stdio.h>
  83953. #if defined FLAC__CPU_IA32
  83954. # include <signal.h>
  83955. #elif defined FLAC__CPU_PPC
  83956. # if !defined FLAC__NO_ASM
  83957. # if defined FLAC__SYS_DARWIN
  83958. # include <sys/sysctl.h>
  83959. # include <mach/mach.h>
  83960. # include <mach/mach_host.h>
  83961. # include <mach/host_info.h>
  83962. # include <mach/machine.h>
  83963. # ifndef CPU_SUBTYPE_POWERPC_970
  83964. # define CPU_SUBTYPE_POWERPC_970 ((cpu_subtype_t) 100)
  83965. # endif
  83966. # else /* FLAC__SYS_DARWIN */
  83967. # include <signal.h>
  83968. # include <setjmp.h>
  83969. static sigjmp_buf jmpbuf;
  83970. static volatile sig_atomic_t canjump = 0;
  83971. static void sigill_handler (int sig)
  83972. {
  83973. if (!canjump) {
  83974. signal (sig, SIG_DFL);
  83975. raise (sig);
  83976. }
  83977. canjump = 0;
  83978. siglongjmp (jmpbuf, 1);
  83979. }
  83980. # endif /* FLAC__SYS_DARWIN */
  83981. # endif /* FLAC__NO_ASM */
  83982. #endif /* FLAC__CPU_PPC */
  83983. #if defined (__NetBSD__) || defined(__OpenBSD__)
  83984. #include <sys/param.h>
  83985. #include <sys/sysctl.h>
  83986. #include <machine/cpu.h>
  83987. #endif
  83988. #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
  83989. #include <sys/types.h>
  83990. #include <sys/sysctl.h>
  83991. #endif
  83992. #if defined(__APPLE__)
  83993. #endif
  83994. static const unsigned FLAC__CPUINFO_IA32_CPUID_CMOV = 0x00008000;
  83995. static const unsigned FLAC__CPUINFO_IA32_CPUID_MMX = 0x00800000;
  83996. static const unsigned FLAC__CPUINFO_IA32_CPUID_FXSR = 0x01000000;
  83997. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE = 0x02000000;
  83998. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE2 = 0x04000000;
  83999. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE3 = 0x00000001;
  84000. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSSE3 = 0x00000200;
  84001. static const unsigned FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_3DNOW = 0x80000000;
  84002. static const unsigned FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXT3DNOW = 0x40000000;
  84003. static const unsigned FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXTMMX = 0x00400000;
  84004. #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM && !defined FLAC__NO_SSE_OS && !defined FLAC__SSE_OS
  84005. # if defined(__linux__)
  84006. # undef USE_OBSOLETE_SIGCONTEXT_FLAVOR /* #define this to use the older signal handler method */
  84007. # ifdef USE_OBSOLETE_SIGCONTEXT_FLAVOR
  84008. static void sigill_handler_sse_os(int signal, struct sigcontext sc)
  84009. {
  84010. (void)signal;
  84011. sc.eip += 3 + 3 + 6;
  84012. }
  84013. # else
  84014. # include <sys/ucontext.h>
  84015. static void sigill_handler_sse_os(int signal, siginfo_t *si, void *uc)
  84016. {
  84017. (void)signal, (void)si;
  84018. ((ucontext_t*)uc)->uc_mcontext.gregs[14/*REG_EIP*/] += 3 + 3 + 6;
  84019. }
  84020. # endif
  84021. # elif defined(_MSC_VER)
  84022. # include <windows.h>
  84023. # undef USE_TRY_CATCH_FLAVOR /* #define this to use the try/catch method for catching illegal opcode exception */
  84024. # ifdef USE_TRY_CATCH_FLAVOR
  84025. # else
  84026. LONG CALLBACK sigill_handler_sse_os(EXCEPTION_POINTERS *ep)
  84027. {
  84028. if(ep->ExceptionRecord->ExceptionCode == EXCEPTION_ILLEGAL_INSTRUCTION) {
  84029. ep->ContextRecord->Eip += 3 + 3 + 6;
  84030. return EXCEPTION_CONTINUE_EXECUTION;
  84031. }
  84032. return EXCEPTION_CONTINUE_SEARCH;
  84033. }
  84034. # endif
  84035. # endif
  84036. #endif
  84037. void FLAC__cpu_info(FLAC__CPUInfo *info)
  84038. {
  84039. #ifdef FLAC__CPU_IA32
  84040. info->type = FLAC__CPUINFO_TYPE_IA32;
  84041. #if !defined FLAC__NO_ASM && defined FLAC__HAS_NASM
  84042. info->use_asm = true; /* we assume a minimum of 80386 with FLAC__CPU_IA32 */
  84043. info->data.ia32.cpuid = FLAC__cpu_have_cpuid_asm_ia32()? true : false;
  84044. info->data.ia32.bswap = info->data.ia32.cpuid; /* CPUID => BSWAP since it came after */
  84045. info->data.ia32.cmov = false;
  84046. info->data.ia32.mmx = false;
  84047. info->data.ia32.fxsr = false;
  84048. info->data.ia32.sse = false;
  84049. info->data.ia32.sse2 = false;
  84050. info->data.ia32.sse3 = false;
  84051. info->data.ia32.ssse3 = false;
  84052. info->data.ia32._3dnow = false;
  84053. info->data.ia32.ext3dnow = false;
  84054. info->data.ia32.extmmx = false;
  84055. if(info->data.ia32.cpuid) {
  84056. FLAC__uint32 flags_edx, flags_ecx;
  84057. FLAC__cpu_info_asm_ia32(&flags_edx, &flags_ecx);
  84058. info->data.ia32.cmov = (flags_edx & FLAC__CPUINFO_IA32_CPUID_CMOV )? true : false;
  84059. info->data.ia32.mmx = (flags_edx & FLAC__CPUINFO_IA32_CPUID_MMX )? true : false;
  84060. info->data.ia32.fxsr = (flags_edx & FLAC__CPUINFO_IA32_CPUID_FXSR )? true : false;
  84061. info->data.ia32.sse = (flags_edx & FLAC__CPUINFO_IA32_CPUID_SSE )? true : false;
  84062. info->data.ia32.sse2 = (flags_edx & FLAC__CPUINFO_IA32_CPUID_SSE2 )? true : false;
  84063. info->data.ia32.sse3 = (flags_ecx & FLAC__CPUINFO_IA32_CPUID_SSE3 )? true : false;
  84064. info->data.ia32.ssse3 = (flags_ecx & FLAC__CPUINFO_IA32_CPUID_SSSE3)? true : false;
  84065. #ifdef FLAC__USE_3DNOW
  84066. flags_edx = FLAC__cpu_info_extended_amd_asm_ia32();
  84067. info->data.ia32._3dnow = (flags_edx & FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_3DNOW )? true : false;
  84068. info->data.ia32.ext3dnow = (flags_edx & FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXT3DNOW)? true : false;
  84069. info->data.ia32.extmmx = (flags_edx & FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXTMMX )? true : false;
  84070. #else
  84071. info->data.ia32._3dnow = info->data.ia32.ext3dnow = info->data.ia32.extmmx = false;
  84072. #endif
  84073. #ifdef DEBUG
  84074. fprintf(stderr, "CPU info (IA-32):\n");
  84075. fprintf(stderr, " CPUID ...... %c\n", info->data.ia32.cpuid ? 'Y' : 'n');
  84076. fprintf(stderr, " BSWAP ...... %c\n", info->data.ia32.bswap ? 'Y' : 'n');
  84077. fprintf(stderr, " CMOV ....... %c\n", info->data.ia32.cmov ? 'Y' : 'n');
  84078. fprintf(stderr, " MMX ........ %c\n", info->data.ia32.mmx ? 'Y' : 'n');
  84079. fprintf(stderr, " FXSR ....... %c\n", info->data.ia32.fxsr ? 'Y' : 'n');
  84080. fprintf(stderr, " SSE ........ %c\n", info->data.ia32.sse ? 'Y' : 'n');
  84081. fprintf(stderr, " SSE2 ....... %c\n", info->data.ia32.sse2 ? 'Y' : 'n');
  84082. fprintf(stderr, " SSE3 ....... %c\n", info->data.ia32.sse3 ? 'Y' : 'n');
  84083. fprintf(stderr, " SSSE3 ...... %c\n", info->data.ia32.ssse3 ? 'Y' : 'n');
  84084. fprintf(stderr, " 3DNow! ..... %c\n", info->data.ia32._3dnow ? 'Y' : 'n');
  84085. fprintf(stderr, " 3DNow!-ext . %c\n", info->data.ia32.ext3dnow? 'Y' : 'n');
  84086. fprintf(stderr, " 3DNow!-MMX . %c\n", info->data.ia32.extmmx ? 'Y' : 'n');
  84087. #endif
  84088. if(info->data.ia32.fxsr || info->data.ia32.sse || info->data.ia32.sse2) {
  84089. #if defined FLAC__NO_SSE_OS
  84090. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84091. #elif defined FLAC__SSE_OS
  84092. #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) || defined(__APPLE__)
  84093. int sse = 0;
  84094. size_t len;
  84095. len = sizeof(sse); sse = sse || (sysctlbyname("hw.instruction_sse", &sse, &len, NULL, 0) == 0 && sse);
  84096. len = sizeof(sse); sse = sse || (sysctlbyname("hw.optional.sse" , &sse, &len, NULL, 0) == 0 && sse); /* __APPLE__ ? */
  84097. if(!sse)
  84098. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84099. #elif defined(__NetBSD__) || defined (__OpenBSD__)
  84100. # if __NetBSD_Version__ >= 105250000 || (defined __OpenBSD__)
  84101. int val = 0, mib[2] = { CTL_MACHDEP, CPU_SSE };
  84102. size_t len = sizeof(val);
  84103. if(sysctl(mib, 2, &val, &len, NULL, 0) < 0 || !val)
  84104. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84105. else { /* double-check SSE2 */
  84106. mib[1] = CPU_SSE2;
  84107. len = sizeof(val);
  84108. if(sysctl(mib, 2, &val, &len, NULL, 0) < 0 || !val)
  84109. info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84110. }
  84111. # else
  84112. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84113. # endif
  84114. #elif defined(__linux__)
  84115. int sse = 0;
  84116. struct sigaction sigill_save;
  84117. #ifdef USE_OBSOLETE_SIGCONTEXT_FLAVOR
  84118. if(0 == sigaction(SIGILL, NULL, &sigill_save) && signal(SIGILL, (void (*)(int))sigill_handler_sse_os) != SIG_ERR)
  84119. #else
  84120. struct sigaction sigill_sse;
  84121. sigill_sse.sa_sigaction = sigill_handler_sse_os;
  84122. __sigemptyset(&sigill_sse.sa_mask);
  84123. 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 */
  84124. if(0 == sigaction(SIGILL, &sigill_sse, &sigill_save))
  84125. #endif
  84126. {
  84127. asm volatile (
  84128. "xorl %0,%0\n\t" /* for some reason, still need to do this to clear 'sse' var */
  84129. "xorps %%xmm0,%%xmm0\n\t" /* will cause SIGILL if unsupported by OS */
  84130. "incl %0\n\t" /* SIGILL handler will jump over this */
  84131. "nop\n\t" /* SIGILL jump lands here if "inc" is 9 bytes */
  84132. "nop\n\t"
  84133. "nop\n\t"
  84134. "nop\n\t"
  84135. "nop\n\t"
  84136. "nop\n\t"
  84137. "nop\n\t" /* SIGILL jump lands here if "inc" is 3 bytes (expected) */
  84138. "nop\n\t"
  84139. "nop" /* SIGILL jump lands here if "inc" is 1 byte */
  84140. : "=r"(sse)
  84141. : "r"(sse)
  84142. );
  84143. sigaction(SIGILL, &sigill_save, NULL);
  84144. }
  84145. if(!sse)
  84146. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84147. #elif defined(_MSC_VER)
  84148. # ifdef USE_TRY_CATCH_FLAVOR
  84149. _try {
  84150. __asm {
  84151. # if _MSC_VER <= 1200
  84152. _emit 0x0F
  84153. _emit 0x57
  84154. _emit 0xC0
  84155. # else
  84156. xorps xmm0,xmm0
  84157. # endif
  84158. }
  84159. }
  84160. _except(EXCEPTION_EXECUTE_HANDLER) {
  84161. if (_exception_code() == STATUS_ILLEGAL_INSTRUCTION)
  84162. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84163. }
  84164. # else
  84165. int sse = 0;
  84166. LPTOP_LEVEL_EXCEPTION_FILTER save = SetUnhandledExceptionFilter(sigill_handler_sse_os);
  84167. __asm {
  84168. # if _MSC_VER <= 1200
  84169. _emit 0x0F
  84170. _emit 0x57
  84171. _emit 0xC0
  84172. # else
  84173. xorps xmm0,xmm0
  84174. # endif
  84175. inc sse
  84176. nop
  84177. nop
  84178. nop
  84179. nop
  84180. nop
  84181. nop
  84182. nop
  84183. nop
  84184. nop
  84185. }
  84186. SetUnhandledExceptionFilter(save);
  84187. if(!sse)
  84188. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84189. # endif
  84190. #else
  84191. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84192. #endif
  84193. #ifdef DEBUG
  84194. fprintf(stderr, " SSE OS sup . %c\n", info->data.ia32.sse ? 'Y' : 'n');
  84195. #endif
  84196. }
  84197. }
  84198. #else
  84199. info->use_asm = false;
  84200. #endif
  84201. #elif defined FLAC__CPU_PPC
  84202. info->type = FLAC__CPUINFO_TYPE_PPC;
  84203. # if !defined FLAC__NO_ASM
  84204. info->use_asm = true;
  84205. # ifdef FLAC__USE_ALTIVEC
  84206. # if defined FLAC__SYS_DARWIN
  84207. {
  84208. int val = 0, mib[2] = { CTL_HW, HW_VECTORUNIT };
  84209. size_t len = sizeof(val);
  84210. info->data.ppc.altivec = !(sysctl(mib, 2, &val, &len, NULL, 0) || !val);
  84211. }
  84212. {
  84213. host_basic_info_data_t hostInfo;
  84214. mach_msg_type_number_t infoCount;
  84215. infoCount = HOST_BASIC_INFO_COUNT;
  84216. host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&hostInfo, &infoCount);
  84217. info->data.ppc.ppc64 = (hostInfo.cpu_type == CPU_TYPE_POWERPC) && (hostInfo.cpu_subtype == CPU_SUBTYPE_POWERPC_970);
  84218. }
  84219. # else /* FLAC__USE_ALTIVEC && !FLAC__SYS_DARWIN */
  84220. {
  84221. info->data.ppc.altivec = 0;
  84222. info->data.ppc.ppc64 = 0;
  84223. signal (SIGILL, sigill_handler);
  84224. canjump = 0;
  84225. if (!sigsetjmp (jmpbuf, 1)) {
  84226. canjump = 1;
  84227. asm volatile (
  84228. "mtspr 256, %0\n\t"
  84229. "vand %%v0, %%v0, %%v0"
  84230. :
  84231. : "r" (-1)
  84232. );
  84233. info->data.ppc.altivec = 1;
  84234. }
  84235. canjump = 0;
  84236. if (!sigsetjmp (jmpbuf, 1)) {
  84237. int x = 0;
  84238. canjump = 1;
  84239. asm volatile ("cntlzd %0, %1" : "=r" (x) : "r" (x) );
  84240. info->data.ppc.ppc64 = 1;
  84241. }
  84242. signal (SIGILL, SIG_DFL); /*@@@@@@ should save and restore old signal */
  84243. }
  84244. # endif
  84245. # else /* !FLAC__USE_ALTIVEC */
  84246. info->data.ppc.altivec = 0;
  84247. info->data.ppc.ppc64 = 0;
  84248. # endif
  84249. # else
  84250. info->use_asm = false;
  84251. # endif
  84252. #else
  84253. info->type = FLAC__CPUINFO_TYPE_UNKNOWN;
  84254. info->use_asm = false;
  84255. #endif
  84256. }
  84257. #endif
  84258. /*** End of inlined file: cpu.c ***/
  84259. /*** Start of inlined file: crc.c ***/
  84260. /*** Start of inlined file: juce_FlacHeader.h ***/
  84261. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84262. // tasks..
  84263. #define VERSION "1.2.1"
  84264. #define FLAC__NO_DLL 1
  84265. #if JUCE_MSVC
  84266. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84267. #endif
  84268. #if JUCE_MAC
  84269. #define FLAC__SYS_DARWIN 1
  84270. #endif
  84271. /*** End of inlined file: juce_FlacHeader.h ***/
  84272. #if JUCE_USE_FLAC
  84273. #if HAVE_CONFIG_H
  84274. # include <config.h>
  84275. #endif
  84276. FLAC__byte const FLAC__crc8_table[256] = {
  84277. 0x00, 0x07, 0x0E, 0x09, 0x1C, 0x1B, 0x12, 0x15,
  84278. 0x38, 0x3F, 0x36, 0x31, 0x24, 0x23, 0x2A, 0x2D,
  84279. 0x70, 0x77, 0x7E, 0x79, 0x6C, 0x6B, 0x62, 0x65,
  84280. 0x48, 0x4F, 0x46, 0x41, 0x54, 0x53, 0x5A, 0x5D,
  84281. 0xE0, 0xE7, 0xEE, 0xE9, 0xFC, 0xFB, 0xF2, 0xF5,
  84282. 0xD8, 0xDF, 0xD6, 0xD1, 0xC4, 0xC3, 0xCA, 0xCD,
  84283. 0x90, 0x97, 0x9E, 0x99, 0x8C, 0x8B, 0x82, 0x85,
  84284. 0xA8, 0xAF, 0xA6, 0xA1, 0xB4, 0xB3, 0xBA, 0xBD,
  84285. 0xC7, 0xC0, 0xC9, 0xCE, 0xDB, 0xDC, 0xD5, 0xD2,
  84286. 0xFF, 0xF8, 0xF1, 0xF6, 0xE3, 0xE4, 0xED, 0xEA,
  84287. 0xB7, 0xB0, 0xB9, 0xBE, 0xAB, 0xAC, 0xA5, 0xA2,
  84288. 0x8F, 0x88, 0x81, 0x86, 0x93, 0x94, 0x9D, 0x9A,
  84289. 0x27, 0x20, 0x29, 0x2E, 0x3B, 0x3C, 0x35, 0x32,
  84290. 0x1F, 0x18, 0x11, 0x16, 0x03, 0x04, 0x0D, 0x0A,
  84291. 0x57, 0x50, 0x59, 0x5E, 0x4B, 0x4C, 0x45, 0x42,
  84292. 0x6F, 0x68, 0x61, 0x66, 0x73, 0x74, 0x7D, 0x7A,
  84293. 0x89, 0x8E, 0x87, 0x80, 0x95, 0x92, 0x9B, 0x9C,
  84294. 0xB1, 0xB6, 0xBF, 0xB8, 0xAD, 0xAA, 0xA3, 0xA4,
  84295. 0xF9, 0xFE, 0xF7, 0xF0, 0xE5, 0xE2, 0xEB, 0xEC,
  84296. 0xC1, 0xC6, 0xCF, 0xC8, 0xDD, 0xDA, 0xD3, 0xD4,
  84297. 0x69, 0x6E, 0x67, 0x60, 0x75, 0x72, 0x7B, 0x7C,
  84298. 0x51, 0x56, 0x5F, 0x58, 0x4D, 0x4A, 0x43, 0x44,
  84299. 0x19, 0x1E, 0x17, 0x10, 0x05, 0x02, 0x0B, 0x0C,
  84300. 0x21, 0x26, 0x2F, 0x28, 0x3D, 0x3A, 0x33, 0x34,
  84301. 0x4E, 0x49, 0x40, 0x47, 0x52, 0x55, 0x5C, 0x5B,
  84302. 0x76, 0x71, 0x78, 0x7F, 0x6A, 0x6D, 0x64, 0x63,
  84303. 0x3E, 0x39, 0x30, 0x37, 0x22, 0x25, 0x2C, 0x2B,
  84304. 0x06, 0x01, 0x08, 0x0F, 0x1A, 0x1D, 0x14, 0x13,
  84305. 0xAE, 0xA9, 0xA0, 0xA7, 0xB2, 0xB5, 0xBC, 0xBB,
  84306. 0x96, 0x91, 0x98, 0x9F, 0x8A, 0x8D, 0x84, 0x83,
  84307. 0xDE, 0xD9, 0xD0, 0xD7, 0xC2, 0xC5, 0xCC, 0xCB,
  84308. 0xE6, 0xE1, 0xE8, 0xEF, 0xFA, 0xFD, 0xF4, 0xF3
  84309. };
  84310. unsigned FLAC__crc16_table[256] = {
  84311. 0x0000, 0x8005, 0x800f, 0x000a, 0x801b, 0x001e, 0x0014, 0x8011,
  84312. 0x8033, 0x0036, 0x003c, 0x8039, 0x0028, 0x802d, 0x8027, 0x0022,
  84313. 0x8063, 0x0066, 0x006c, 0x8069, 0x0078, 0x807d, 0x8077, 0x0072,
  84314. 0x0050, 0x8055, 0x805f, 0x005a, 0x804b, 0x004e, 0x0044, 0x8041,
  84315. 0x80c3, 0x00c6, 0x00cc, 0x80c9, 0x00d8, 0x80dd, 0x80d7, 0x00d2,
  84316. 0x00f0, 0x80f5, 0x80ff, 0x00fa, 0x80eb, 0x00ee, 0x00e4, 0x80e1,
  84317. 0x00a0, 0x80a5, 0x80af, 0x00aa, 0x80bb, 0x00be, 0x00b4, 0x80b1,
  84318. 0x8093, 0x0096, 0x009c, 0x8099, 0x0088, 0x808d, 0x8087, 0x0082,
  84319. 0x8183, 0x0186, 0x018c, 0x8189, 0x0198, 0x819d, 0x8197, 0x0192,
  84320. 0x01b0, 0x81b5, 0x81bf, 0x01ba, 0x81ab, 0x01ae, 0x01a4, 0x81a1,
  84321. 0x01e0, 0x81e5, 0x81ef, 0x01ea, 0x81fb, 0x01fe, 0x01f4, 0x81f1,
  84322. 0x81d3, 0x01d6, 0x01dc, 0x81d9, 0x01c8, 0x81cd, 0x81c7, 0x01c2,
  84323. 0x0140, 0x8145, 0x814f, 0x014a, 0x815b, 0x015e, 0x0154, 0x8151,
  84324. 0x8173, 0x0176, 0x017c, 0x8179, 0x0168, 0x816d, 0x8167, 0x0162,
  84325. 0x8123, 0x0126, 0x012c, 0x8129, 0x0138, 0x813d, 0x8137, 0x0132,
  84326. 0x0110, 0x8115, 0x811f, 0x011a, 0x810b, 0x010e, 0x0104, 0x8101,
  84327. 0x8303, 0x0306, 0x030c, 0x8309, 0x0318, 0x831d, 0x8317, 0x0312,
  84328. 0x0330, 0x8335, 0x833f, 0x033a, 0x832b, 0x032e, 0x0324, 0x8321,
  84329. 0x0360, 0x8365, 0x836f, 0x036a, 0x837b, 0x037e, 0x0374, 0x8371,
  84330. 0x8353, 0x0356, 0x035c, 0x8359, 0x0348, 0x834d, 0x8347, 0x0342,
  84331. 0x03c0, 0x83c5, 0x83cf, 0x03ca, 0x83db, 0x03de, 0x03d4, 0x83d1,
  84332. 0x83f3, 0x03f6, 0x03fc, 0x83f9, 0x03e8, 0x83ed, 0x83e7, 0x03e2,
  84333. 0x83a3, 0x03a6, 0x03ac, 0x83a9, 0x03b8, 0x83bd, 0x83b7, 0x03b2,
  84334. 0x0390, 0x8395, 0x839f, 0x039a, 0x838b, 0x038e, 0x0384, 0x8381,
  84335. 0x0280, 0x8285, 0x828f, 0x028a, 0x829b, 0x029e, 0x0294, 0x8291,
  84336. 0x82b3, 0x02b6, 0x02bc, 0x82b9, 0x02a8, 0x82ad, 0x82a7, 0x02a2,
  84337. 0x82e3, 0x02e6, 0x02ec, 0x82e9, 0x02f8, 0x82fd, 0x82f7, 0x02f2,
  84338. 0x02d0, 0x82d5, 0x82df, 0x02da, 0x82cb, 0x02ce, 0x02c4, 0x82c1,
  84339. 0x8243, 0x0246, 0x024c, 0x8249, 0x0258, 0x825d, 0x8257, 0x0252,
  84340. 0x0270, 0x8275, 0x827f, 0x027a, 0x826b, 0x026e, 0x0264, 0x8261,
  84341. 0x0220, 0x8225, 0x822f, 0x022a, 0x823b, 0x023e, 0x0234, 0x8231,
  84342. 0x8213, 0x0216, 0x021c, 0x8219, 0x0208, 0x820d, 0x8207, 0x0202
  84343. };
  84344. void FLAC__crc8_update(const FLAC__byte data, FLAC__uint8 *crc)
  84345. {
  84346. *crc = FLAC__crc8_table[*crc ^ data];
  84347. }
  84348. void FLAC__crc8_update_block(const FLAC__byte *data, unsigned len, FLAC__uint8 *crc)
  84349. {
  84350. while(len--)
  84351. *crc = FLAC__crc8_table[*crc ^ *data++];
  84352. }
  84353. FLAC__uint8 FLAC__crc8(const FLAC__byte *data, unsigned len)
  84354. {
  84355. FLAC__uint8 crc = 0;
  84356. while(len--)
  84357. crc = FLAC__crc8_table[crc ^ *data++];
  84358. return crc;
  84359. }
  84360. unsigned FLAC__crc16(const FLAC__byte *data, unsigned len)
  84361. {
  84362. unsigned crc = 0;
  84363. while(len--)
  84364. crc = ((crc<<8) ^ FLAC__crc16_table[(crc>>8) ^ *data++]) & 0xffff;
  84365. return crc;
  84366. }
  84367. #endif
  84368. /*** End of inlined file: crc.c ***/
  84369. /*** Start of inlined file: fixed.c ***/
  84370. /*** Start of inlined file: juce_FlacHeader.h ***/
  84371. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84372. // tasks..
  84373. #define VERSION "1.2.1"
  84374. #define FLAC__NO_DLL 1
  84375. #if JUCE_MSVC
  84376. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84377. #endif
  84378. #if JUCE_MAC
  84379. #define FLAC__SYS_DARWIN 1
  84380. #endif
  84381. /*** End of inlined file: juce_FlacHeader.h ***/
  84382. #if JUCE_USE_FLAC
  84383. #if HAVE_CONFIG_H
  84384. # include <config.h>
  84385. #endif
  84386. #include <math.h>
  84387. #include <string.h>
  84388. /*** Start of inlined file: fixed.h ***/
  84389. #ifndef FLAC__PRIVATE__FIXED_H
  84390. #define FLAC__PRIVATE__FIXED_H
  84391. #ifdef HAVE_CONFIG_H
  84392. #include <config.h>
  84393. #endif
  84394. /*** Start of inlined file: float.h ***/
  84395. #ifndef FLAC__PRIVATE__FLOAT_H
  84396. #define FLAC__PRIVATE__FLOAT_H
  84397. #ifdef HAVE_CONFIG_H
  84398. #include <config.h>
  84399. #endif
  84400. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84401. typedef double FLAC__double;
  84402. typedef float FLAC__float;
  84403. typedef float FLAC__real;
  84404. #else
  84405. typedef FLAC__int32 FLAC__fixedpoint;
  84406. extern const FLAC__fixedpoint FLAC__FP_ZERO;
  84407. extern const FLAC__fixedpoint FLAC__FP_ONE_HALF;
  84408. extern const FLAC__fixedpoint FLAC__FP_ONE;
  84409. extern const FLAC__fixedpoint FLAC__FP_LN2;
  84410. extern const FLAC__fixedpoint FLAC__FP_E;
  84411. #define FLAC__fixedpoint_trunc(x) ((x)>>16)
  84412. #define FLAC__fixedpoint_mul(x, y) ( (FLAC__fixedpoint) ( ((FLAC__int64)(x)*(FLAC__int64)(y)) >> 16 ) )
  84413. #define FLAC__fixedpoint_div(x, y) ( (FLAC__fixedpoint) ( ( ((FLAC__int64)(x)<<32) / (FLAC__int64)(y) ) >> 16 ) )
  84414. FLAC__uint32 FLAC__fixedpoint_log2(FLAC__uint32 x, unsigned fracbits, unsigned precision);
  84415. #endif
  84416. #endif
  84417. /*** End of inlined file: float.h ***/
  84418. /*** Start of inlined file: format.h ***/
  84419. #ifndef FLAC__PRIVATE__FORMAT_H
  84420. #define FLAC__PRIVATE__FORMAT_H
  84421. unsigned FLAC__format_get_max_rice_partition_order(unsigned blocksize, unsigned predictor_order);
  84422. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize(unsigned blocksize);
  84423. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(unsigned limit, unsigned blocksize, unsigned predictor_order);
  84424. void FLAC__format_entropy_coding_method_partitioned_rice_contents_init(FLAC__EntropyCodingMethod_PartitionedRiceContents *object);
  84425. void FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(FLAC__EntropyCodingMethod_PartitionedRiceContents *object);
  84426. FLAC__bool FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(FLAC__EntropyCodingMethod_PartitionedRiceContents *object, unsigned max_partition_order);
  84427. #endif
  84428. /*** End of inlined file: format.h ***/
  84429. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84430. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  84431. # ifndef FLAC__NO_ASM
  84432. # ifdef FLAC__CPU_IA32
  84433. # ifdef FLAC__HAS_NASM
  84434. 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]);
  84435. # endif
  84436. # endif
  84437. # endif
  84438. 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]);
  84439. #else
  84440. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  84441. 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]);
  84442. #endif
  84443. void FLAC__fixed_compute_residual(const FLAC__int32 data[], unsigned data_len, unsigned order, FLAC__int32 residual[]);
  84444. void FLAC__fixed_restore_signal(const FLAC__int32 residual[], unsigned data_len, unsigned order, FLAC__int32 data[]);
  84445. #endif
  84446. /*** End of inlined file: fixed.h ***/
  84447. #ifndef M_LN2
  84448. #define M_LN2 0.69314718055994530942
  84449. #endif
  84450. #ifdef min
  84451. #undef min
  84452. #endif
  84453. #define min(x,y) ((x) < (y)? (x) : (y))
  84454. #ifdef local_abs
  84455. #undef local_abs
  84456. #endif
  84457. #define local_abs(x) ((unsigned)((x)<0? -(x) : (x)))
  84458. #ifdef FLAC__INTEGER_ONLY_LIBRARY
  84459. static FLAC__fixedpoint local__compute_rbps_integerized(FLAC__uint32 err, FLAC__uint32 n)
  84460. {
  84461. FLAC__uint32 rbps;
  84462. unsigned bits; /* the number of bits required to represent a number */
  84463. int fracbits; /* the number of bits of rbps that comprise the fractional part */
  84464. FLAC__ASSERT(sizeof(rbps) == sizeof(FLAC__fixedpoint));
  84465. FLAC__ASSERT(err > 0);
  84466. FLAC__ASSERT(n > 0);
  84467. FLAC__ASSERT(n <= FLAC__MAX_BLOCK_SIZE);
  84468. if(err <= n)
  84469. return 0;
  84470. fracbits = (8*sizeof(err)) - (FLAC__bitmath_ilog2(err)+1);
  84471. err <<= fracbits;
  84472. err /= n;
  84473. FLAC__ASSERT(err > 0);
  84474. bits = FLAC__bitmath_ilog2(err)+1;
  84475. if(bits > 16) {
  84476. err >>= (bits-16);
  84477. fracbits -= (bits-16);
  84478. }
  84479. rbps = (FLAC__uint32)err;
  84480. rbps *= FLAC__FP_LN2;
  84481. fracbits += 16;
  84482. FLAC__ASSERT(fracbits >= 0);
  84483. {
  84484. const int f = fracbits & 3;
  84485. if(f) {
  84486. rbps >>= f;
  84487. fracbits -= f;
  84488. }
  84489. }
  84490. rbps = FLAC__fixedpoint_log2(rbps, fracbits, (unsigned)(-1));
  84491. if(rbps == 0)
  84492. return 0;
  84493. FLAC__ASSERT((int)FLAC__bitmath_ilog2(rbps)+1 <= fracbits + 6);
  84494. FLAC__ASSERT(fracbits >= -3);
  84495. if(fracbits < 16)
  84496. return rbps << (16-fracbits);
  84497. else if(fracbits > 16)
  84498. return rbps >> (fracbits-16);
  84499. else
  84500. return rbps;
  84501. }
  84502. static FLAC__fixedpoint local__compute_rbps_wide_integerized(FLAC__uint64 err, FLAC__uint32 n)
  84503. {
  84504. FLAC__uint32 rbps;
  84505. unsigned bits; /* the number of bits required to represent a number */
  84506. int fracbits; /* the number of bits of rbps that comprise the fractional part */
  84507. FLAC__ASSERT(sizeof(rbps) == sizeof(FLAC__fixedpoint));
  84508. FLAC__ASSERT(err > 0);
  84509. FLAC__ASSERT(n > 0);
  84510. FLAC__ASSERT(n <= FLAC__MAX_BLOCK_SIZE);
  84511. if(err <= n)
  84512. return 0;
  84513. fracbits = (8*sizeof(err)) - (FLAC__bitmath_ilog2_wide(err)+1);
  84514. err <<= fracbits;
  84515. err /= n;
  84516. FLAC__ASSERT(err > 0);
  84517. bits = FLAC__bitmath_ilog2_wide(err)+1;
  84518. if(bits > 16) {
  84519. err >>= (bits-16);
  84520. fracbits -= (bits-16);
  84521. }
  84522. rbps = (FLAC__uint32)err;
  84523. rbps *= FLAC__FP_LN2;
  84524. fracbits += 16;
  84525. FLAC__ASSERT(fracbits >= 0);
  84526. {
  84527. const int f = fracbits & 3;
  84528. if(f) {
  84529. rbps >>= f;
  84530. fracbits -= f;
  84531. }
  84532. }
  84533. rbps = FLAC__fixedpoint_log2(rbps, fracbits, (unsigned)(-1));
  84534. if(rbps == 0)
  84535. return 0;
  84536. FLAC__ASSERT((int)FLAC__bitmath_ilog2(rbps)+1 <= fracbits + 6);
  84537. FLAC__ASSERT(fracbits >= -3);
  84538. if(fracbits < 16)
  84539. return rbps << (16-fracbits);
  84540. else if(fracbits > 16)
  84541. return rbps >> (fracbits-16);
  84542. else
  84543. return rbps;
  84544. }
  84545. #endif
  84546. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84547. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1])
  84548. #else
  84549. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1])
  84550. #endif
  84551. {
  84552. FLAC__int32 last_error_0 = data[-1];
  84553. FLAC__int32 last_error_1 = data[-1] - data[-2];
  84554. FLAC__int32 last_error_2 = last_error_1 - (data[-2] - data[-3]);
  84555. FLAC__int32 last_error_3 = last_error_2 - (data[-2] - 2*data[-3] + data[-4]);
  84556. FLAC__int32 error, save;
  84557. FLAC__uint32 total_error_0 = 0, total_error_1 = 0, total_error_2 = 0, total_error_3 = 0, total_error_4 = 0;
  84558. unsigned i, order;
  84559. for(i = 0; i < data_len; i++) {
  84560. error = data[i] ; total_error_0 += local_abs(error); save = error;
  84561. error -= last_error_0; total_error_1 += local_abs(error); last_error_0 = save; save = error;
  84562. error -= last_error_1; total_error_2 += local_abs(error); last_error_1 = save; save = error;
  84563. error -= last_error_2; total_error_3 += local_abs(error); last_error_2 = save; save = error;
  84564. error -= last_error_3; total_error_4 += local_abs(error); last_error_3 = save;
  84565. }
  84566. if(total_error_0 < min(min(min(total_error_1, total_error_2), total_error_3), total_error_4))
  84567. order = 0;
  84568. else if(total_error_1 < min(min(total_error_2, total_error_3), total_error_4))
  84569. order = 1;
  84570. else if(total_error_2 < min(total_error_3, total_error_4))
  84571. order = 2;
  84572. else if(total_error_3 < total_error_4)
  84573. order = 3;
  84574. else
  84575. order = 4;
  84576. FLAC__ASSERT(data_len > 0 || total_error_0 == 0);
  84577. FLAC__ASSERT(data_len > 0 || total_error_1 == 0);
  84578. FLAC__ASSERT(data_len > 0 || total_error_2 == 0);
  84579. FLAC__ASSERT(data_len > 0 || total_error_3 == 0);
  84580. FLAC__ASSERT(data_len > 0 || total_error_4 == 0);
  84581. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84582. 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);
  84583. 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);
  84584. 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);
  84585. 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);
  84586. 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);
  84587. #else
  84588. residual_bits_per_sample[0] = (total_error_0 > 0) ? local__compute_rbps_integerized(total_error_0, data_len) : 0;
  84589. residual_bits_per_sample[1] = (total_error_1 > 0) ? local__compute_rbps_integerized(total_error_1, data_len) : 0;
  84590. residual_bits_per_sample[2] = (total_error_2 > 0) ? local__compute_rbps_integerized(total_error_2, data_len) : 0;
  84591. residual_bits_per_sample[3] = (total_error_3 > 0) ? local__compute_rbps_integerized(total_error_3, data_len) : 0;
  84592. residual_bits_per_sample[4] = (total_error_4 > 0) ? local__compute_rbps_integerized(total_error_4, data_len) : 0;
  84593. #endif
  84594. return order;
  84595. }
  84596. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84597. 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])
  84598. #else
  84599. 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])
  84600. #endif
  84601. {
  84602. FLAC__int32 last_error_0 = data[-1];
  84603. FLAC__int32 last_error_1 = data[-1] - data[-2];
  84604. FLAC__int32 last_error_2 = last_error_1 - (data[-2] - data[-3]);
  84605. FLAC__int32 last_error_3 = last_error_2 - (data[-2] - 2*data[-3] + data[-4]);
  84606. FLAC__int32 error, save;
  84607. FLAC__uint64 total_error_0 = 0, total_error_1 = 0, total_error_2 = 0, total_error_3 = 0, total_error_4 = 0;
  84608. unsigned i, order;
  84609. for(i = 0; i < data_len; i++) {
  84610. error = data[i] ; total_error_0 += local_abs(error); save = error;
  84611. error -= last_error_0; total_error_1 += local_abs(error); last_error_0 = save; save = error;
  84612. error -= last_error_1; total_error_2 += local_abs(error); last_error_1 = save; save = error;
  84613. error -= last_error_2; total_error_3 += local_abs(error); last_error_2 = save; save = error;
  84614. error -= last_error_3; total_error_4 += local_abs(error); last_error_3 = save;
  84615. }
  84616. if(total_error_0 < min(min(min(total_error_1, total_error_2), total_error_3), total_error_4))
  84617. order = 0;
  84618. else if(total_error_1 < min(min(total_error_2, total_error_3), total_error_4))
  84619. order = 1;
  84620. else if(total_error_2 < min(total_error_3, total_error_4))
  84621. order = 2;
  84622. else if(total_error_3 < total_error_4)
  84623. order = 3;
  84624. else
  84625. order = 4;
  84626. FLAC__ASSERT(data_len > 0 || total_error_0 == 0);
  84627. FLAC__ASSERT(data_len > 0 || total_error_1 == 0);
  84628. FLAC__ASSERT(data_len > 0 || total_error_2 == 0);
  84629. FLAC__ASSERT(data_len > 0 || total_error_3 == 0);
  84630. FLAC__ASSERT(data_len > 0 || total_error_4 == 0);
  84631. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84632. #if defined _MSC_VER || defined __MINGW32__
  84633. 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);
  84634. 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);
  84635. 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);
  84636. 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);
  84637. 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);
  84638. #else
  84639. 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);
  84640. 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);
  84641. 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);
  84642. 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);
  84643. 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);
  84644. #endif
  84645. #else
  84646. residual_bits_per_sample[0] = (total_error_0 > 0) ? local__compute_rbps_wide_integerized(total_error_0, data_len) : 0;
  84647. residual_bits_per_sample[1] = (total_error_1 > 0) ? local__compute_rbps_wide_integerized(total_error_1, data_len) : 0;
  84648. residual_bits_per_sample[2] = (total_error_2 > 0) ? local__compute_rbps_wide_integerized(total_error_2, data_len) : 0;
  84649. residual_bits_per_sample[3] = (total_error_3 > 0) ? local__compute_rbps_wide_integerized(total_error_3, data_len) : 0;
  84650. residual_bits_per_sample[4] = (total_error_4 > 0) ? local__compute_rbps_wide_integerized(total_error_4, data_len) : 0;
  84651. #endif
  84652. return order;
  84653. }
  84654. void FLAC__fixed_compute_residual(const FLAC__int32 data[], unsigned data_len, unsigned order, FLAC__int32 residual[])
  84655. {
  84656. const int idata_len = (int)data_len;
  84657. int i;
  84658. switch(order) {
  84659. case 0:
  84660. FLAC__ASSERT(sizeof(residual[0]) == sizeof(data[0]));
  84661. memcpy(residual, data, sizeof(residual[0])*data_len);
  84662. break;
  84663. case 1:
  84664. for(i = 0; i < idata_len; i++)
  84665. residual[i] = data[i] - data[i-1];
  84666. break;
  84667. case 2:
  84668. for(i = 0; i < idata_len; i++)
  84669. #if 1 /* OPT: may be faster with some compilers on some systems */
  84670. residual[i] = data[i] - (data[i-1] << 1) + data[i-2];
  84671. #else
  84672. residual[i] = data[i] - 2*data[i-1] + data[i-2];
  84673. #endif
  84674. break;
  84675. case 3:
  84676. for(i = 0; i < idata_len; i++)
  84677. #if 1 /* OPT: may be faster with some compilers on some systems */
  84678. residual[i] = data[i] - (((data[i-1]-data[i-2])<<1) + (data[i-1]-data[i-2])) - data[i-3];
  84679. #else
  84680. residual[i] = data[i] - 3*data[i-1] + 3*data[i-2] - data[i-3];
  84681. #endif
  84682. break;
  84683. case 4:
  84684. for(i = 0; i < idata_len; i++)
  84685. #if 1 /* OPT: may be faster with some compilers on some systems */
  84686. residual[i] = data[i] - ((data[i-1]+data[i-3])<<2) + ((data[i-2]<<2) + (data[i-2]<<1)) + data[i-4];
  84687. #else
  84688. residual[i] = data[i] - 4*data[i-1] + 6*data[i-2] - 4*data[i-3] + data[i-4];
  84689. #endif
  84690. break;
  84691. default:
  84692. FLAC__ASSERT(0);
  84693. }
  84694. }
  84695. void FLAC__fixed_restore_signal(const FLAC__int32 residual[], unsigned data_len, unsigned order, FLAC__int32 data[])
  84696. {
  84697. int i, idata_len = (int)data_len;
  84698. switch(order) {
  84699. case 0:
  84700. FLAC__ASSERT(sizeof(residual[0]) == sizeof(data[0]));
  84701. memcpy(data, residual, sizeof(residual[0])*data_len);
  84702. break;
  84703. case 1:
  84704. for(i = 0; i < idata_len; i++)
  84705. data[i] = residual[i] + data[i-1];
  84706. break;
  84707. case 2:
  84708. for(i = 0; i < idata_len; i++)
  84709. #if 1 /* OPT: may be faster with some compilers on some systems */
  84710. data[i] = residual[i] + (data[i-1]<<1) - data[i-2];
  84711. #else
  84712. data[i] = residual[i] + 2*data[i-1] - data[i-2];
  84713. #endif
  84714. break;
  84715. case 3:
  84716. for(i = 0; i < idata_len; i++)
  84717. #if 1 /* OPT: may be faster with some compilers on some systems */
  84718. data[i] = residual[i] + (((data[i-1]-data[i-2])<<1) + (data[i-1]-data[i-2])) + data[i-3];
  84719. #else
  84720. data[i] = residual[i] + 3*data[i-1] - 3*data[i-2] + data[i-3];
  84721. #endif
  84722. break;
  84723. case 4:
  84724. for(i = 0; i < idata_len; i++)
  84725. #if 1 /* OPT: may be faster with some compilers on some systems */
  84726. data[i] = residual[i] + ((data[i-1]+data[i-3])<<2) - ((data[i-2]<<2) + (data[i-2]<<1)) - data[i-4];
  84727. #else
  84728. data[i] = residual[i] + 4*data[i-1] - 6*data[i-2] + 4*data[i-3] - data[i-4];
  84729. #endif
  84730. break;
  84731. default:
  84732. FLAC__ASSERT(0);
  84733. }
  84734. }
  84735. #endif
  84736. /*** End of inlined file: fixed.c ***/
  84737. /*** Start of inlined file: float.c ***/
  84738. /*** Start of inlined file: juce_FlacHeader.h ***/
  84739. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84740. // tasks..
  84741. #define VERSION "1.2.1"
  84742. #define FLAC__NO_DLL 1
  84743. #if JUCE_MSVC
  84744. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84745. #endif
  84746. #if JUCE_MAC
  84747. #define FLAC__SYS_DARWIN 1
  84748. #endif
  84749. /*** End of inlined file: juce_FlacHeader.h ***/
  84750. #if JUCE_USE_FLAC
  84751. #if HAVE_CONFIG_H
  84752. # include <config.h>
  84753. #endif
  84754. #ifdef FLAC__INTEGER_ONLY_LIBRARY
  84755. #ifdef _MSC_VER
  84756. #define FLAC__U64L(x) x
  84757. #else
  84758. #define FLAC__U64L(x) x##LLU
  84759. #endif
  84760. const FLAC__fixedpoint FLAC__FP_ZERO = 0;
  84761. const FLAC__fixedpoint FLAC__FP_ONE_HALF = 0x00008000;
  84762. const FLAC__fixedpoint FLAC__FP_ONE = 0x00010000;
  84763. const FLAC__fixedpoint FLAC__FP_LN2 = 45426;
  84764. const FLAC__fixedpoint FLAC__FP_E = 178145;
  84765. #define LOG2_LOOKUP_PRECISION 16
  84766. static const FLAC__uint32 log2_lookup[][LOG2_LOOKUP_PRECISION] = {
  84767. {
  84768. 0x00000000,
  84769. 0x00000001,
  84770. 0x00000000,
  84771. 0x00000000,
  84772. 0x00000000,
  84773. 0x00000000,
  84774. 0x00000000,
  84775. 0x00000000,
  84776. 0x00000000,
  84777. 0x00000000,
  84778. 0x00000000,
  84779. 0x00000000,
  84780. 0x00000000,
  84781. 0x00000000,
  84782. 0x00000000,
  84783. 0x00000000
  84784. },
  84785. {
  84786. 0x00000000,
  84787. 0x00000010,
  84788. 0x00000007,
  84789. 0x00000003,
  84790. 0x00000001,
  84791. 0x00000001,
  84792. 0x00000000,
  84793. 0x00000000,
  84794. 0x00000000,
  84795. 0x00000000,
  84796. 0x00000000,
  84797. 0x00000000,
  84798. 0x00000000,
  84799. 0x00000000,
  84800. 0x00000000,
  84801. 0x00000000
  84802. },
  84803. {
  84804. 0x00000000,
  84805. 0x00000100,
  84806. 0x0000006a,
  84807. 0x00000031,
  84808. 0x00000018,
  84809. 0x0000000c,
  84810. 0x00000006,
  84811. 0x00000003,
  84812. 0x00000001,
  84813. 0x00000001,
  84814. 0x00000000,
  84815. 0x00000000,
  84816. 0x00000000,
  84817. 0x00000000,
  84818. 0x00000000,
  84819. 0x00000000
  84820. },
  84821. {
  84822. 0x00000000,
  84823. 0x00001000,
  84824. 0x000006a4,
  84825. 0x00000315,
  84826. 0x0000017d,
  84827. 0x000000bc,
  84828. 0x0000005d,
  84829. 0x0000002e,
  84830. 0x00000017,
  84831. 0x0000000c,
  84832. 0x00000006,
  84833. 0x00000003,
  84834. 0x00000001,
  84835. 0x00000001,
  84836. 0x00000000,
  84837. 0x00000000
  84838. },
  84839. {
  84840. 0x00000000,
  84841. 0x00010000,
  84842. 0x00006a40,
  84843. 0x00003151,
  84844. 0x000017d6,
  84845. 0x00000bba,
  84846. 0x000005d1,
  84847. 0x000002e6,
  84848. 0x00000172,
  84849. 0x000000b9,
  84850. 0x0000005c,
  84851. 0x0000002e,
  84852. 0x00000017,
  84853. 0x0000000c,
  84854. 0x00000006,
  84855. 0x00000003
  84856. },
  84857. {
  84858. 0x00000000,
  84859. 0x00100000,
  84860. 0x0006a3fe,
  84861. 0x00031513,
  84862. 0x00017d60,
  84863. 0x0000bb9d,
  84864. 0x00005d10,
  84865. 0x00002e59,
  84866. 0x00001721,
  84867. 0x00000b8e,
  84868. 0x000005c6,
  84869. 0x000002e3,
  84870. 0x00000171,
  84871. 0x000000b9,
  84872. 0x0000005c,
  84873. 0x0000002e
  84874. },
  84875. {
  84876. 0x00000000,
  84877. 0x01000000,
  84878. 0x006a3fe6,
  84879. 0x00315130,
  84880. 0x0017d605,
  84881. 0x000bb9ca,
  84882. 0x0005d0fc,
  84883. 0x0002e58f,
  84884. 0x0001720e,
  84885. 0x0000b8d8,
  84886. 0x00005c61,
  84887. 0x00002e2d,
  84888. 0x00001716,
  84889. 0x00000b8b,
  84890. 0x000005c5,
  84891. 0x000002e3
  84892. },
  84893. {
  84894. 0x00000000,
  84895. 0x10000000,
  84896. 0x06a3fe5c,
  84897. 0x03151301,
  84898. 0x017d6049,
  84899. 0x00bb9ca6,
  84900. 0x005d0fba,
  84901. 0x002e58f7,
  84902. 0x001720da,
  84903. 0x000b8d87,
  84904. 0x0005c60b,
  84905. 0x0002e2d7,
  84906. 0x00017160,
  84907. 0x0000b8ad,
  84908. 0x00005c56,
  84909. 0x00002e2b
  84910. }
  84911. };
  84912. #if 0
  84913. static const FLAC__uint64 log2_lookup_wide[] = {
  84914. {
  84915. 0x00000000,
  84916. FLAC__U64L(0x100000000),
  84917. FLAC__U64L(0x6a3fe5c6),
  84918. FLAC__U64L(0x31513015),
  84919. FLAC__U64L(0x17d60497),
  84920. FLAC__U64L(0x0bb9ca65),
  84921. FLAC__U64L(0x05d0fba2),
  84922. FLAC__U64L(0x02e58f74),
  84923. FLAC__U64L(0x01720d9c),
  84924. FLAC__U64L(0x00b8d875),
  84925. FLAC__U64L(0x005c60aa),
  84926. FLAC__U64L(0x002e2d72),
  84927. FLAC__U64L(0x00171600),
  84928. FLAC__U64L(0x000b8ad2),
  84929. FLAC__U64L(0x0005c55d),
  84930. FLAC__U64L(0x0002e2ac)
  84931. },
  84932. {
  84933. 0x00000000,
  84934. FLAC__U64L(0x1000000000000),
  84935. FLAC__U64L(0x6a3fe5c60429),
  84936. FLAC__U64L(0x315130157f7a),
  84937. FLAC__U64L(0x17d60496cfbb),
  84938. FLAC__U64L(0xbb9ca64ecac),
  84939. FLAC__U64L(0x5d0fba187cd),
  84940. FLAC__U64L(0x2e58f7441ee),
  84941. FLAC__U64L(0x1720d9c06a8),
  84942. FLAC__U64L(0xb8d8752173),
  84943. FLAC__U64L(0x5c60aa252e),
  84944. FLAC__U64L(0x2e2d71b0d8),
  84945. FLAC__U64L(0x1716001719),
  84946. FLAC__U64L(0xb8ad1de1b),
  84947. FLAC__U64L(0x5c55d640d),
  84948. FLAC__U64L(0x2e2abcf52)
  84949. }
  84950. };
  84951. #endif
  84952. FLAC__uint32 FLAC__fixedpoint_log2(FLAC__uint32 x, unsigned fracbits, unsigned precision)
  84953. {
  84954. const FLAC__uint32 ONE = (1u << fracbits);
  84955. const FLAC__uint32 *table = log2_lookup[fracbits >> 2];
  84956. FLAC__ASSERT(fracbits < 32);
  84957. FLAC__ASSERT((fracbits & 0x3) == 0);
  84958. if(x < ONE)
  84959. return 0;
  84960. if(precision > LOG2_LOOKUP_PRECISION)
  84961. precision = LOG2_LOOKUP_PRECISION;
  84962. {
  84963. FLAC__uint32 y = 0;
  84964. FLAC__uint32 z = x >> 1, k = 1;
  84965. while (x > ONE && k < precision) {
  84966. if (x - z >= ONE) {
  84967. x -= z;
  84968. z = x >> k;
  84969. y += table[k];
  84970. }
  84971. else {
  84972. z >>= 1;
  84973. k++;
  84974. }
  84975. }
  84976. return y;
  84977. }
  84978. }
  84979. #endif /* defined FLAC__INTEGER_ONLY_LIBRARY */
  84980. #endif
  84981. /*** End of inlined file: float.c ***/
  84982. /*** Start of inlined file: format.c ***/
  84983. /*** Start of inlined file: juce_FlacHeader.h ***/
  84984. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84985. // tasks..
  84986. #define VERSION "1.2.1"
  84987. #define FLAC__NO_DLL 1
  84988. #if JUCE_MSVC
  84989. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84990. #endif
  84991. #if JUCE_MAC
  84992. #define FLAC__SYS_DARWIN 1
  84993. #endif
  84994. /*** End of inlined file: juce_FlacHeader.h ***/
  84995. #if JUCE_USE_FLAC
  84996. #if HAVE_CONFIG_H
  84997. # include <config.h>
  84998. #endif
  84999. #include <stdio.h>
  85000. #include <stdlib.h> /* for qsort() */
  85001. #include <string.h> /* for memset() */
  85002. #ifndef FLaC__INLINE
  85003. #define FLaC__INLINE
  85004. #endif
  85005. #ifdef min
  85006. #undef min
  85007. #endif
  85008. #define min(a,b) ((a)<(b)?(a):(b))
  85009. #ifdef _MSC_VER
  85010. #define FLAC__U64L(x) x
  85011. #else
  85012. #define FLAC__U64L(x) x##LLU
  85013. #endif
  85014. FLAC_API const char *FLAC__VERSION_STRING = VERSION
  85015. ;
  85016. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINW32__
  85017. FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC 1.2.1 20070917";
  85018. #else
  85019. FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC " VERSION " 20070917";
  85020. #endif
  85021. FLAC_API const FLAC__byte FLAC__STREAM_SYNC_STRING[4] = { 'f','L','a','C' };
  85022. FLAC_API const unsigned FLAC__STREAM_SYNC = 0x664C6143;
  85023. FLAC_API const unsigned FLAC__STREAM_SYNC_LEN = 32; /* bits */
  85024. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN = 16; /* bits */
  85025. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN = 16; /* bits */
  85026. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN = 24; /* bits */
  85027. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN = 24; /* bits */
  85028. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN = 20; /* bits */
  85029. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN = 3; /* bits */
  85030. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN = 5; /* bits */
  85031. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN = 36; /* bits */
  85032. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MD5SUM_LEN = 128; /* bits */
  85033. FLAC_API const unsigned FLAC__STREAM_METADATA_APPLICATION_ID_LEN = 32; /* bits */
  85034. FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN = 64; /* bits */
  85035. FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN = 64; /* bits */
  85036. FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN = 16; /* bits */
  85037. FLAC_API const FLAC__uint64 FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER = FLAC__U64L(0xffffffffffffffff);
  85038. FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN = 32; /* bits */
  85039. FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN = 32; /* bits */
  85040. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN = 64; /* bits */
  85041. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN = 8; /* bits */
  85042. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN = 3*8; /* bits */
  85043. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN = 64; /* bits */
  85044. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN = 8; /* bits */
  85045. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN = 12*8; /* bits */
  85046. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN = 1; /* bit */
  85047. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN = 1; /* bit */
  85048. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN = 6+13*8; /* bits */
  85049. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN = 8; /* bits */
  85050. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN = 128*8; /* bits */
  85051. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN = 64; /* bits */
  85052. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN = 1; /* bit */
  85053. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN = 7+258*8; /* bits */
  85054. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN = 8; /* bits */
  85055. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_TYPE_LEN = 32; /* bits */
  85056. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN = 32; /* bits */
  85057. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN = 32; /* bits */
  85058. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN = 32; /* bits */
  85059. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN = 32; /* bits */
  85060. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN = 32; /* bits */
  85061. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_COLORS_LEN = 32; /* bits */
  85062. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN = 32; /* bits */
  85063. FLAC_API const unsigned FLAC__STREAM_METADATA_IS_LAST_LEN = 1; /* bits */
  85064. FLAC_API const unsigned FLAC__STREAM_METADATA_TYPE_LEN = 7; /* bits */
  85065. FLAC_API const unsigned FLAC__STREAM_METADATA_LENGTH_LEN = 24; /* bits */
  85066. FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC = 0x3ffe;
  85067. FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC_LEN = 14; /* bits */
  85068. FLAC_API const unsigned FLAC__FRAME_HEADER_RESERVED_LEN = 1; /* bits */
  85069. FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN = 1; /* bits */
  85070. FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCK_SIZE_LEN = 4; /* bits */
  85071. FLAC_API const unsigned FLAC__FRAME_HEADER_SAMPLE_RATE_LEN = 4; /* bits */
  85072. FLAC_API const unsigned FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN = 4; /* bits */
  85073. FLAC_API const unsigned FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN = 3; /* bits */
  85074. FLAC_API const unsigned FLAC__FRAME_HEADER_ZERO_PAD_LEN = 1; /* bits */
  85075. FLAC_API const unsigned FLAC__FRAME_HEADER_CRC_LEN = 8; /* bits */
  85076. FLAC_API const unsigned FLAC__FRAME_FOOTER_CRC_LEN = 16; /* bits */
  85077. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_TYPE_LEN = 2; /* bits */
  85078. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN = 4; /* bits */
  85079. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN = 4; /* bits */
  85080. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN = 5; /* bits */
  85081. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN = 5; /* bits */
  85082. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER = 15; /* == (1<<FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN)-1 */
  85083. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER = 31; /* == (1<<FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN)-1 */
  85084. FLAC_API const char * const FLAC__EntropyCodingMethodTypeString[] = {
  85085. "PARTITIONED_RICE",
  85086. "PARTITIONED_RICE2"
  85087. };
  85088. FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN = 4; /* bits */
  85089. FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN = 5; /* bits */
  85090. FLAC_API const unsigned FLAC__SUBFRAME_ZERO_PAD_LEN = 1; /* bits */
  85091. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LEN = 6; /* bits */
  85092. FLAC_API const unsigned FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN = 1; /* bits */
  85093. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_CONSTANT_BYTE_ALIGNED_MASK = 0x00;
  85094. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_VERBATIM_BYTE_ALIGNED_MASK = 0x02;
  85095. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK = 0x10;
  85096. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LPC_BYTE_ALIGNED_MASK = 0x40;
  85097. FLAC_API const char * const FLAC__SubframeTypeString[] = {
  85098. "CONSTANT",
  85099. "VERBATIM",
  85100. "FIXED",
  85101. "LPC"
  85102. };
  85103. FLAC_API const char * const FLAC__ChannelAssignmentString[] = {
  85104. "INDEPENDENT",
  85105. "LEFT_SIDE",
  85106. "RIGHT_SIDE",
  85107. "MID_SIDE"
  85108. };
  85109. FLAC_API const char * const FLAC__FrameNumberTypeString[] = {
  85110. "FRAME_NUMBER_TYPE_FRAME_NUMBER",
  85111. "FRAME_NUMBER_TYPE_SAMPLE_NUMBER"
  85112. };
  85113. FLAC_API const char * const FLAC__MetadataTypeString[] = {
  85114. "STREAMINFO",
  85115. "PADDING",
  85116. "APPLICATION",
  85117. "SEEKTABLE",
  85118. "VORBIS_COMMENT",
  85119. "CUESHEET",
  85120. "PICTURE"
  85121. };
  85122. FLAC_API const char * const FLAC__StreamMetadata_Picture_TypeString[] = {
  85123. "Other",
  85124. "32x32 pixels 'file icon' (PNG only)",
  85125. "Other file icon",
  85126. "Cover (front)",
  85127. "Cover (back)",
  85128. "Leaflet page",
  85129. "Media (e.g. label side of CD)",
  85130. "Lead artist/lead performer/soloist",
  85131. "Artist/performer",
  85132. "Conductor",
  85133. "Band/Orchestra",
  85134. "Composer",
  85135. "Lyricist/text writer",
  85136. "Recording Location",
  85137. "During recording",
  85138. "During performance",
  85139. "Movie/video screen capture",
  85140. "A bright coloured fish",
  85141. "Illustration",
  85142. "Band/artist logotype",
  85143. "Publisher/Studio logotype"
  85144. };
  85145. FLAC_API FLAC__bool FLAC__format_sample_rate_is_valid(unsigned sample_rate)
  85146. {
  85147. if(sample_rate == 0 || sample_rate > FLAC__MAX_SAMPLE_RATE) {
  85148. return false;
  85149. }
  85150. else
  85151. return true;
  85152. }
  85153. FLAC_API FLAC__bool FLAC__format_sample_rate_is_subset(unsigned sample_rate)
  85154. {
  85155. if(
  85156. !FLAC__format_sample_rate_is_valid(sample_rate) ||
  85157. (
  85158. sample_rate >= (1u << 16) &&
  85159. !(sample_rate % 1000 == 0 || sample_rate % 10 == 0)
  85160. )
  85161. ) {
  85162. return false;
  85163. }
  85164. else
  85165. return true;
  85166. }
  85167. FLAC_API FLAC__bool FLAC__format_seektable_is_legal(const FLAC__StreamMetadata_SeekTable *seek_table)
  85168. {
  85169. unsigned i;
  85170. FLAC__uint64 prev_sample_number = 0;
  85171. FLAC__bool got_prev = false;
  85172. FLAC__ASSERT(0 != seek_table);
  85173. for(i = 0; i < seek_table->num_points; i++) {
  85174. if(got_prev) {
  85175. if(
  85176. seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
  85177. seek_table->points[i].sample_number <= prev_sample_number
  85178. )
  85179. return false;
  85180. }
  85181. prev_sample_number = seek_table->points[i].sample_number;
  85182. got_prev = true;
  85183. }
  85184. return true;
  85185. }
  85186. static int seekpoint_compare_(const FLAC__StreamMetadata_SeekPoint *l, const FLAC__StreamMetadata_SeekPoint *r)
  85187. {
  85188. if(l->sample_number == r->sample_number)
  85189. return 0;
  85190. else if(l->sample_number < r->sample_number)
  85191. return -1;
  85192. else
  85193. return 1;
  85194. }
  85195. FLAC_API unsigned FLAC__format_seektable_sort(FLAC__StreamMetadata_SeekTable *seek_table)
  85196. {
  85197. unsigned i, j;
  85198. FLAC__bool first;
  85199. FLAC__ASSERT(0 != seek_table);
  85200. qsort(seek_table->points, seek_table->num_points, sizeof(FLAC__StreamMetadata_SeekPoint), (int (*)(const void *, const void *))seekpoint_compare_);
  85201. first = true;
  85202. for(i = j = 0; i < seek_table->num_points; i++) {
  85203. if(seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER) {
  85204. if(!first) {
  85205. if(seek_table->points[i].sample_number == seek_table->points[j-1].sample_number)
  85206. continue;
  85207. }
  85208. }
  85209. first = false;
  85210. seek_table->points[j++] = seek_table->points[i];
  85211. }
  85212. for(i = j; i < seek_table->num_points; i++) {
  85213. seek_table->points[i].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
  85214. seek_table->points[i].stream_offset = 0;
  85215. seek_table->points[i].frame_samples = 0;
  85216. }
  85217. return j;
  85218. }
  85219. static FLaC__INLINE unsigned utf8len_(const FLAC__byte *utf8)
  85220. {
  85221. FLAC__ASSERT(0 != utf8);
  85222. if ((utf8[0] & 0x80) == 0) {
  85223. return 1;
  85224. }
  85225. else if ((utf8[0] & 0xE0) == 0xC0 && (utf8[1] & 0xC0) == 0x80) {
  85226. if ((utf8[0] & 0xFE) == 0xC0) /* overlong sequence check */
  85227. return 0;
  85228. return 2;
  85229. }
  85230. else if ((utf8[0] & 0xF0) == 0xE0 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80) {
  85231. if (utf8[0] == 0xE0 && (utf8[1] & 0xE0) == 0x80) /* overlong sequence check */
  85232. return 0;
  85233. if (utf8[0] == 0xED && (utf8[1] & 0xE0) == 0xA0) /* D800-DFFF */
  85234. return 0;
  85235. if (utf8[0] == 0xEF && utf8[1] == 0xBF && (utf8[2] & 0xFE) == 0xBE) /* FFFE-FFFF */
  85236. return 0;
  85237. return 3;
  85238. }
  85239. else if ((utf8[0] & 0xF8) == 0xF0 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80 && (utf8[3] & 0xC0) == 0x80) {
  85240. if (utf8[0] == 0xF0 && (utf8[1] & 0xF0) == 0x80) /* overlong sequence check */
  85241. return 0;
  85242. return 4;
  85243. }
  85244. else if ((utf8[0] & 0xFC) == 0xF8 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80 && (utf8[3] & 0xC0) == 0x80 && (utf8[4] & 0xC0) == 0x80) {
  85245. if (utf8[0] == 0xF8 && (utf8[1] & 0xF8) == 0x80) /* overlong sequence check */
  85246. return 0;
  85247. return 5;
  85248. }
  85249. 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) {
  85250. if (utf8[0] == 0xFC && (utf8[1] & 0xFC) == 0x80) /* overlong sequence check */
  85251. return 0;
  85252. return 6;
  85253. }
  85254. else {
  85255. return 0;
  85256. }
  85257. }
  85258. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_name_is_legal(const char *name)
  85259. {
  85260. char c;
  85261. for(c = *name; c; c = *(++name))
  85262. if(c < 0x20 || c == 0x3d || c > 0x7d)
  85263. return false;
  85264. return true;
  85265. }
  85266. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_value_is_legal(const FLAC__byte *value, unsigned length)
  85267. {
  85268. if(length == (unsigned)(-1)) {
  85269. while(*value) {
  85270. unsigned n = utf8len_(value);
  85271. if(n == 0)
  85272. return false;
  85273. value += n;
  85274. }
  85275. }
  85276. else {
  85277. const FLAC__byte *end = value + length;
  85278. while(value < end) {
  85279. unsigned n = utf8len_(value);
  85280. if(n == 0)
  85281. return false;
  85282. value += n;
  85283. }
  85284. if(value != end)
  85285. return false;
  85286. }
  85287. return true;
  85288. }
  85289. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_is_legal(const FLAC__byte *entry, unsigned length)
  85290. {
  85291. const FLAC__byte *s, *end;
  85292. for(s = entry, end = s + length; s < end && *s != '='; s++) {
  85293. if(*s < 0x20 || *s > 0x7D)
  85294. return false;
  85295. }
  85296. if(s == end)
  85297. return false;
  85298. s++; /* skip '=' */
  85299. while(s < end) {
  85300. unsigned n = utf8len_(s);
  85301. if(n == 0)
  85302. return false;
  85303. s += n;
  85304. }
  85305. if(s != end)
  85306. return false;
  85307. return true;
  85308. }
  85309. FLAC_API FLAC__bool FLAC__format_cuesheet_is_legal(const FLAC__StreamMetadata_CueSheet *cue_sheet, FLAC__bool check_cd_da_subset, const char **violation)
  85310. {
  85311. unsigned i, j;
  85312. if(check_cd_da_subset) {
  85313. if(cue_sheet->lead_in < 2 * 44100) {
  85314. if(violation) *violation = "CD-DA cue sheet must have a lead-in length of at least 2 seconds";
  85315. return false;
  85316. }
  85317. if(cue_sheet->lead_in % 588 != 0) {
  85318. if(violation) *violation = "CD-DA cue sheet lead-in length must be evenly divisible by 588 samples";
  85319. return false;
  85320. }
  85321. }
  85322. if(cue_sheet->num_tracks == 0) {
  85323. if(violation) *violation = "cue sheet must have at least one track (the lead-out)";
  85324. return false;
  85325. }
  85326. if(check_cd_da_subset && cue_sheet->tracks[cue_sheet->num_tracks-1].number != 170) {
  85327. if(violation) *violation = "CD-DA cue sheet must have a lead-out track number 170 (0xAA)";
  85328. return false;
  85329. }
  85330. for(i = 0; i < cue_sheet->num_tracks; i++) {
  85331. if(cue_sheet->tracks[i].number == 0) {
  85332. if(violation) *violation = "cue sheet may not have a track number 0";
  85333. return false;
  85334. }
  85335. if(check_cd_da_subset) {
  85336. if(!((cue_sheet->tracks[i].number >= 1 && cue_sheet->tracks[i].number <= 99) || cue_sheet->tracks[i].number == 170)) {
  85337. if(violation) *violation = "CD-DA cue sheet track number must be 1-99 or 170";
  85338. return false;
  85339. }
  85340. }
  85341. if(check_cd_da_subset && cue_sheet->tracks[i].offset % 588 != 0) {
  85342. if(violation) {
  85343. if(i == cue_sheet->num_tracks-1) /* the lead-out track... */
  85344. *violation = "CD-DA cue sheet lead-out offset must be evenly divisible by 588 samples";
  85345. else
  85346. *violation = "CD-DA cue sheet track offset must be evenly divisible by 588 samples";
  85347. }
  85348. return false;
  85349. }
  85350. if(i < cue_sheet->num_tracks - 1) {
  85351. if(cue_sheet->tracks[i].num_indices == 0) {
  85352. if(violation) *violation = "cue sheet track must have at least one index point";
  85353. return false;
  85354. }
  85355. if(cue_sheet->tracks[i].indices[0].number > 1) {
  85356. if(violation) *violation = "cue sheet track's first index number must be 0 or 1";
  85357. return false;
  85358. }
  85359. }
  85360. for(j = 0; j < cue_sheet->tracks[i].num_indices; j++) {
  85361. if(check_cd_da_subset && cue_sheet->tracks[i].indices[j].offset % 588 != 0) {
  85362. if(violation) *violation = "CD-DA cue sheet track index offset must be evenly divisible by 588 samples";
  85363. return false;
  85364. }
  85365. if(j > 0) {
  85366. if(cue_sheet->tracks[i].indices[j].number != cue_sheet->tracks[i].indices[j-1].number + 1) {
  85367. if(violation) *violation = "cue sheet track index numbers must increase by 1";
  85368. return false;
  85369. }
  85370. }
  85371. }
  85372. }
  85373. return true;
  85374. }
  85375. FLAC_API FLAC__bool FLAC__format_picture_is_legal(const FLAC__StreamMetadata_Picture *picture, const char **violation)
  85376. {
  85377. char *p;
  85378. FLAC__byte *b;
  85379. for(p = picture->mime_type; *p; p++) {
  85380. if(*p < 0x20 || *p > 0x7e) {
  85381. if(violation) *violation = "MIME type string must contain only printable ASCII characters (0x20-0x7e)";
  85382. return false;
  85383. }
  85384. }
  85385. for(b = picture->description; *b; ) {
  85386. unsigned n = utf8len_(b);
  85387. if(n == 0) {
  85388. if(violation) *violation = "description string must be valid UTF-8";
  85389. return false;
  85390. }
  85391. b += n;
  85392. }
  85393. return true;
  85394. }
  85395. unsigned FLAC__format_get_max_rice_partition_order(unsigned blocksize, unsigned predictor_order)
  85396. {
  85397. return
  85398. FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(
  85399. FLAC__format_get_max_rice_partition_order_from_blocksize(blocksize),
  85400. blocksize,
  85401. predictor_order
  85402. );
  85403. }
  85404. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize(unsigned blocksize)
  85405. {
  85406. unsigned max_rice_partition_order = 0;
  85407. while(!(blocksize & 1)) {
  85408. max_rice_partition_order++;
  85409. blocksize >>= 1;
  85410. }
  85411. return min(FLAC__MAX_RICE_PARTITION_ORDER, max_rice_partition_order);
  85412. }
  85413. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(unsigned limit, unsigned blocksize, unsigned predictor_order)
  85414. {
  85415. unsigned max_rice_partition_order = limit;
  85416. while(max_rice_partition_order > 0 && (blocksize >> max_rice_partition_order) <= predictor_order)
  85417. max_rice_partition_order--;
  85418. FLAC__ASSERT(
  85419. (max_rice_partition_order == 0 && blocksize >= predictor_order) ||
  85420. (max_rice_partition_order > 0 && blocksize >> max_rice_partition_order > predictor_order)
  85421. );
  85422. return max_rice_partition_order;
  85423. }
  85424. void FLAC__format_entropy_coding_method_partitioned_rice_contents_init(FLAC__EntropyCodingMethod_PartitionedRiceContents *object)
  85425. {
  85426. FLAC__ASSERT(0 != object);
  85427. object->parameters = 0;
  85428. object->raw_bits = 0;
  85429. object->capacity_by_order = 0;
  85430. }
  85431. void FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(FLAC__EntropyCodingMethod_PartitionedRiceContents *object)
  85432. {
  85433. FLAC__ASSERT(0 != object);
  85434. if(0 != object->parameters)
  85435. free(object->parameters);
  85436. if(0 != object->raw_bits)
  85437. free(object->raw_bits);
  85438. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(object);
  85439. }
  85440. FLAC__bool FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(FLAC__EntropyCodingMethod_PartitionedRiceContents *object, unsigned max_partition_order)
  85441. {
  85442. FLAC__ASSERT(0 != object);
  85443. FLAC__ASSERT(object->capacity_by_order > 0 || (0 == object->parameters && 0 == object->raw_bits));
  85444. if(object->capacity_by_order < max_partition_order) {
  85445. if(0 == (object->parameters = (unsigned*)realloc(object->parameters, sizeof(unsigned)*(1 << max_partition_order))))
  85446. return false;
  85447. if(0 == (object->raw_bits = (unsigned*)realloc(object->raw_bits, sizeof(unsigned)*(1 << max_partition_order))))
  85448. return false;
  85449. memset(object->raw_bits, 0, sizeof(unsigned)*(1 << max_partition_order));
  85450. object->capacity_by_order = max_partition_order;
  85451. }
  85452. return true;
  85453. }
  85454. #endif
  85455. /*** End of inlined file: format.c ***/
  85456. /*** Start of inlined file: lpc_flac.c ***/
  85457. /*** Start of inlined file: juce_FlacHeader.h ***/
  85458. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  85459. // tasks..
  85460. #define VERSION "1.2.1"
  85461. #define FLAC__NO_DLL 1
  85462. #if JUCE_MSVC
  85463. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  85464. #endif
  85465. #if JUCE_MAC
  85466. #define FLAC__SYS_DARWIN 1
  85467. #endif
  85468. /*** End of inlined file: juce_FlacHeader.h ***/
  85469. #if JUCE_USE_FLAC
  85470. #if HAVE_CONFIG_H
  85471. # include <config.h>
  85472. #endif
  85473. #include <math.h>
  85474. /*** Start of inlined file: lpc.h ***/
  85475. #ifndef FLAC__PRIVATE__LPC_H
  85476. #define FLAC__PRIVATE__LPC_H
  85477. #ifdef HAVE_CONFIG_H
  85478. #include <config.h>
  85479. #endif
  85480. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  85481. void FLAC__lpc_window_data(const FLAC__int32 in[], const FLAC__real window[], FLAC__real out[], unsigned data_len);
  85482. void FLAC__lpc_compute_autocorrelation(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85483. #ifndef FLAC__NO_ASM
  85484. # ifdef FLAC__CPU_IA32
  85485. # ifdef FLAC__HAS_NASM
  85486. void FLAC__lpc_compute_autocorrelation_asm_ia32(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85487. void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_4(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85488. void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_8(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85489. void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_12(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85490. void FLAC__lpc_compute_autocorrelation_asm_ia32_3dnow(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85491. # endif
  85492. # endif
  85493. #endif
  85494. void FLAC__lpc_compute_lp_coefficients(const FLAC__real autoc[], unsigned *max_order, FLAC__real lp_coeff[][FLAC__MAX_LPC_ORDER], FLAC__double error[]);
  85495. int FLAC__lpc_quantize_coefficients(const FLAC__real lp_coeff[], unsigned order, unsigned precision, FLAC__int32 qlp_coeff[], int *shift);
  85496. 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[]);
  85497. 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[]);
  85498. #ifndef FLAC__NO_ASM
  85499. # ifdef FLAC__CPU_IA32
  85500. # ifdef FLAC__HAS_NASM
  85501. 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[]);
  85502. 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[]);
  85503. # endif
  85504. # endif
  85505. #endif
  85506. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  85507. 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[]);
  85508. 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[]);
  85509. #ifndef FLAC__NO_ASM
  85510. # ifdef FLAC__CPU_IA32
  85511. # ifdef FLAC__HAS_NASM
  85512. 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[]);
  85513. 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[]);
  85514. # endif /* FLAC__HAS_NASM */
  85515. # elif defined FLAC__CPU_PPC
  85516. 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[]);
  85517. 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[]);
  85518. # endif/* FLAC__CPU_IA32 || FLAC__CPU_PPC */
  85519. #endif /* FLAC__NO_ASM */
  85520. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  85521. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample(FLAC__double lpc_error, unsigned total_samples);
  85522. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(FLAC__double lpc_error, FLAC__double error_scale);
  85523. unsigned FLAC__lpc_compute_best_order(const FLAC__double lpc_error[], unsigned max_order, unsigned total_samples, unsigned overhead_bits_per_order);
  85524. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  85525. #endif
  85526. /*** End of inlined file: lpc.h ***/
  85527. #if defined DEBUG || defined FLAC__OVERFLOW_DETECT || defined FLAC__OVERFLOW_DETECT_VERBOSE
  85528. #include <stdio.h>
  85529. #endif
  85530. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  85531. #ifndef M_LN2
  85532. #define M_LN2 0.69314718055994530942
  85533. #endif
  85534. #define FLAC__LPC_UNROLLED_FILTER_LOOPS
  85535. void FLAC__lpc_window_data(const FLAC__int32 in[], const FLAC__real window[], FLAC__real out[], unsigned data_len)
  85536. {
  85537. unsigned i;
  85538. for(i = 0; i < data_len; i++)
  85539. out[i] = in[i] * window[i];
  85540. }
  85541. void FLAC__lpc_compute_autocorrelation(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[])
  85542. {
  85543. #if 0
  85544. FLAC__real d;
  85545. unsigned i;
  85546. FLAC__ASSERT(lag > 0);
  85547. FLAC__ASSERT(lag <= data_len);
  85548. while(lag--) {
  85549. for(i = lag, d = 0.0; i < data_len; i++)
  85550. d += data[i] * data[i - lag];
  85551. autoc[lag] = d;
  85552. }
  85553. #endif
  85554. FLAC__real d;
  85555. unsigned sample, coeff;
  85556. const unsigned limit = data_len - lag;
  85557. FLAC__ASSERT(lag > 0);
  85558. FLAC__ASSERT(lag <= data_len);
  85559. for(coeff = 0; coeff < lag; coeff++)
  85560. autoc[coeff] = 0.0;
  85561. for(sample = 0; sample <= limit; sample++) {
  85562. d = data[sample];
  85563. for(coeff = 0; coeff < lag; coeff++)
  85564. autoc[coeff] += d * data[sample+coeff];
  85565. }
  85566. for(; sample < data_len; sample++) {
  85567. d = data[sample];
  85568. for(coeff = 0; coeff < data_len - sample; coeff++)
  85569. autoc[coeff] += d * data[sample+coeff];
  85570. }
  85571. }
  85572. void FLAC__lpc_compute_lp_coefficients(const FLAC__real autoc[], unsigned *max_order, FLAC__real lp_coeff[][FLAC__MAX_LPC_ORDER], FLAC__double error[])
  85573. {
  85574. unsigned i, j;
  85575. FLAC__double r, err, ref[FLAC__MAX_LPC_ORDER], lpc[FLAC__MAX_LPC_ORDER];
  85576. FLAC__ASSERT(0 != max_order);
  85577. FLAC__ASSERT(0 < *max_order);
  85578. FLAC__ASSERT(*max_order <= FLAC__MAX_LPC_ORDER);
  85579. FLAC__ASSERT(autoc[0] != 0.0);
  85580. err = autoc[0];
  85581. for(i = 0; i < *max_order; i++) {
  85582. r = -autoc[i+1];
  85583. for(j = 0; j < i; j++)
  85584. r -= lpc[j] * autoc[i-j];
  85585. ref[i] = (r/=err);
  85586. lpc[i]=r;
  85587. for(j = 0; j < (i>>1); j++) {
  85588. FLAC__double tmp = lpc[j];
  85589. lpc[j] += r * lpc[i-1-j];
  85590. lpc[i-1-j] += r * tmp;
  85591. }
  85592. if(i & 1)
  85593. lpc[j] += lpc[j] * r;
  85594. err *= (1.0 - r * r);
  85595. for(j = 0; j <= i; j++)
  85596. lp_coeff[i][j] = (FLAC__real)(-lpc[j]); /* negate FIR filter coeff to get predictor coeff */
  85597. error[i] = err;
  85598. if(err == 0.0) {
  85599. *max_order = i+1;
  85600. return;
  85601. }
  85602. }
  85603. }
  85604. int FLAC__lpc_quantize_coefficients(const FLAC__real lp_coeff[], unsigned order, unsigned precision, FLAC__int32 qlp_coeff[], int *shift)
  85605. {
  85606. unsigned i;
  85607. FLAC__double cmax;
  85608. FLAC__int32 qmax, qmin;
  85609. FLAC__ASSERT(precision > 0);
  85610. FLAC__ASSERT(precision >= FLAC__MIN_QLP_COEFF_PRECISION);
  85611. precision--;
  85612. qmax = 1 << precision;
  85613. qmin = -qmax;
  85614. qmax--;
  85615. cmax = 0.0;
  85616. for(i = 0; i < order; i++) {
  85617. const FLAC__double d = fabs(lp_coeff[i]);
  85618. if(d > cmax)
  85619. cmax = d;
  85620. }
  85621. if(cmax <= 0.0) {
  85622. return 2;
  85623. }
  85624. else {
  85625. const int max_shiftlimit = (1 << (FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN-1)) - 1;
  85626. const int min_shiftlimit = -max_shiftlimit - 1;
  85627. int log2cmax;
  85628. (void)frexp(cmax, &log2cmax);
  85629. log2cmax--;
  85630. *shift = (int)precision - log2cmax - 1;
  85631. if(*shift > max_shiftlimit)
  85632. *shift = max_shiftlimit;
  85633. else if(*shift < min_shiftlimit)
  85634. return 1;
  85635. }
  85636. if(*shift >= 0) {
  85637. FLAC__double error = 0.0;
  85638. FLAC__int32 q;
  85639. for(i = 0; i < order; i++) {
  85640. error += lp_coeff[i] * (1 << *shift);
  85641. #if 1 /* unfortunately lround() is C99 */
  85642. if(error >= 0.0)
  85643. q = (FLAC__int32)(error + 0.5);
  85644. else
  85645. q = (FLAC__int32)(error - 0.5);
  85646. #else
  85647. q = lround(error);
  85648. #endif
  85649. #ifdef FLAC__OVERFLOW_DETECT
  85650. if(q > qmax+1) /* we expect q==qmax+1 occasionally due to rounding */
  85651. 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]);
  85652. else if(q < qmin)
  85653. 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]);
  85654. #endif
  85655. if(q > qmax)
  85656. q = qmax;
  85657. else if(q < qmin)
  85658. q = qmin;
  85659. error -= q;
  85660. qlp_coeff[i] = q;
  85661. }
  85662. }
  85663. else {
  85664. const int nshift = -(*shift);
  85665. FLAC__double error = 0.0;
  85666. FLAC__int32 q;
  85667. #ifdef DEBUG
  85668. fprintf(stderr,"FLAC__lpc_quantize_coefficients: negative shift=%d order=%u cmax=%f\n", *shift, order, cmax);
  85669. #endif
  85670. for(i = 0; i < order; i++) {
  85671. error += lp_coeff[i] / (1 << nshift);
  85672. #if 1 /* unfortunately lround() is C99 */
  85673. if(error >= 0.0)
  85674. q = (FLAC__int32)(error + 0.5);
  85675. else
  85676. q = (FLAC__int32)(error - 0.5);
  85677. #else
  85678. q = lround(error);
  85679. #endif
  85680. #ifdef FLAC__OVERFLOW_DETECT
  85681. if(q > qmax+1) /* we expect q==qmax+1 occasionally due to rounding */
  85682. 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]);
  85683. else if(q < qmin)
  85684. 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]);
  85685. #endif
  85686. if(q > qmax)
  85687. q = qmax;
  85688. else if(q < qmin)
  85689. q = qmin;
  85690. error -= q;
  85691. qlp_coeff[i] = q;
  85692. }
  85693. *shift = 0;
  85694. }
  85695. return 0;
  85696. }
  85697. 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[])
  85698. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  85699. {
  85700. FLAC__int64 sumo;
  85701. unsigned i, j;
  85702. FLAC__int32 sum;
  85703. const FLAC__int32 *history;
  85704. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  85705. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  85706. for(i=0;i<order;i++)
  85707. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  85708. fprintf(stderr,"\n");
  85709. #endif
  85710. FLAC__ASSERT(order > 0);
  85711. for(i = 0; i < data_len; i++) {
  85712. sumo = 0;
  85713. sum = 0;
  85714. history = data;
  85715. for(j = 0; j < order; j++) {
  85716. sum += qlp_coeff[j] * (*(--history));
  85717. sumo += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*history);
  85718. #if defined _MSC_VER
  85719. if(sumo > 2147483647I64 || sumo < -2147483648I64)
  85720. 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);
  85721. #else
  85722. if(sumo > 2147483647ll || sumo < -2147483648ll)
  85723. 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);
  85724. #endif
  85725. }
  85726. *(residual++) = *(data++) - (sum >> lp_quantization);
  85727. }
  85728. }
  85729. #else /* fully unrolled version for normal use */
  85730. {
  85731. int i;
  85732. FLAC__int32 sum;
  85733. FLAC__ASSERT(order > 0);
  85734. FLAC__ASSERT(order <= 32);
  85735. if(order <= 12) {
  85736. if(order > 8) {
  85737. if(order > 10) {
  85738. if(order == 12) {
  85739. for(i = 0; i < (int)data_len; i++) {
  85740. sum = 0;
  85741. sum += qlp_coeff[11] * data[i-12];
  85742. sum += qlp_coeff[10] * data[i-11];
  85743. sum += qlp_coeff[9] * data[i-10];
  85744. sum += qlp_coeff[8] * data[i-9];
  85745. sum += qlp_coeff[7] * data[i-8];
  85746. sum += qlp_coeff[6] * data[i-7];
  85747. sum += qlp_coeff[5] * data[i-6];
  85748. sum += qlp_coeff[4] * data[i-5];
  85749. sum += qlp_coeff[3] * data[i-4];
  85750. sum += qlp_coeff[2] * data[i-3];
  85751. sum += qlp_coeff[1] * data[i-2];
  85752. sum += qlp_coeff[0] * data[i-1];
  85753. residual[i] = data[i] - (sum >> lp_quantization);
  85754. }
  85755. }
  85756. else { /* order == 11 */
  85757. for(i = 0; i < (int)data_len; i++) {
  85758. sum = 0;
  85759. sum += qlp_coeff[10] * data[i-11];
  85760. sum += qlp_coeff[9] * data[i-10];
  85761. sum += qlp_coeff[8] * data[i-9];
  85762. sum += qlp_coeff[7] * data[i-8];
  85763. sum += qlp_coeff[6] * data[i-7];
  85764. sum += qlp_coeff[5] * data[i-6];
  85765. sum += qlp_coeff[4] * data[i-5];
  85766. sum += qlp_coeff[3] * data[i-4];
  85767. sum += qlp_coeff[2] * data[i-3];
  85768. sum += qlp_coeff[1] * data[i-2];
  85769. sum += qlp_coeff[0] * data[i-1];
  85770. residual[i] = data[i] - (sum >> lp_quantization);
  85771. }
  85772. }
  85773. }
  85774. else {
  85775. if(order == 10) {
  85776. for(i = 0; i < (int)data_len; i++) {
  85777. sum = 0;
  85778. sum += qlp_coeff[9] * data[i-10];
  85779. sum += qlp_coeff[8] * data[i-9];
  85780. sum += qlp_coeff[7] * data[i-8];
  85781. sum += qlp_coeff[6] * data[i-7];
  85782. sum += qlp_coeff[5] * data[i-6];
  85783. sum += qlp_coeff[4] * data[i-5];
  85784. sum += qlp_coeff[3] * data[i-4];
  85785. sum += qlp_coeff[2] * data[i-3];
  85786. sum += qlp_coeff[1] * data[i-2];
  85787. sum += qlp_coeff[0] * data[i-1];
  85788. residual[i] = data[i] - (sum >> lp_quantization);
  85789. }
  85790. }
  85791. else { /* order == 9 */
  85792. for(i = 0; i < (int)data_len; i++) {
  85793. sum = 0;
  85794. sum += qlp_coeff[8] * data[i-9];
  85795. sum += qlp_coeff[7] * data[i-8];
  85796. sum += qlp_coeff[6] * data[i-7];
  85797. sum += qlp_coeff[5] * data[i-6];
  85798. sum += qlp_coeff[4] * data[i-5];
  85799. sum += qlp_coeff[3] * data[i-4];
  85800. sum += qlp_coeff[2] * data[i-3];
  85801. sum += qlp_coeff[1] * data[i-2];
  85802. sum += qlp_coeff[0] * data[i-1];
  85803. residual[i] = data[i] - (sum >> lp_quantization);
  85804. }
  85805. }
  85806. }
  85807. }
  85808. else if(order > 4) {
  85809. if(order > 6) {
  85810. if(order == 8) {
  85811. for(i = 0; i < (int)data_len; i++) {
  85812. sum = 0;
  85813. sum += qlp_coeff[7] * data[i-8];
  85814. sum += qlp_coeff[6] * data[i-7];
  85815. sum += qlp_coeff[5] * data[i-6];
  85816. sum += qlp_coeff[4] * data[i-5];
  85817. sum += qlp_coeff[3] * data[i-4];
  85818. sum += qlp_coeff[2] * data[i-3];
  85819. sum += qlp_coeff[1] * data[i-2];
  85820. sum += qlp_coeff[0] * data[i-1];
  85821. residual[i] = data[i] - (sum >> lp_quantization);
  85822. }
  85823. }
  85824. else { /* order == 7 */
  85825. for(i = 0; i < (int)data_len; i++) {
  85826. sum = 0;
  85827. sum += qlp_coeff[6] * data[i-7];
  85828. sum += qlp_coeff[5] * data[i-6];
  85829. sum += qlp_coeff[4] * data[i-5];
  85830. sum += qlp_coeff[3] * data[i-4];
  85831. sum += qlp_coeff[2] * data[i-3];
  85832. sum += qlp_coeff[1] * data[i-2];
  85833. sum += qlp_coeff[0] * data[i-1];
  85834. residual[i] = data[i] - (sum >> lp_quantization);
  85835. }
  85836. }
  85837. }
  85838. else {
  85839. if(order == 6) {
  85840. for(i = 0; i < (int)data_len; i++) {
  85841. sum = 0;
  85842. sum += qlp_coeff[5] * data[i-6];
  85843. sum += qlp_coeff[4] * data[i-5];
  85844. sum += qlp_coeff[3] * data[i-4];
  85845. sum += qlp_coeff[2] * data[i-3];
  85846. sum += qlp_coeff[1] * data[i-2];
  85847. sum += qlp_coeff[0] * data[i-1];
  85848. residual[i] = data[i] - (sum >> lp_quantization);
  85849. }
  85850. }
  85851. else { /* order == 5 */
  85852. for(i = 0; i < (int)data_len; i++) {
  85853. sum = 0;
  85854. sum += qlp_coeff[4] * data[i-5];
  85855. sum += qlp_coeff[3] * data[i-4];
  85856. sum += qlp_coeff[2] * data[i-3];
  85857. sum += qlp_coeff[1] * data[i-2];
  85858. sum += qlp_coeff[0] * data[i-1];
  85859. residual[i] = data[i] - (sum >> lp_quantization);
  85860. }
  85861. }
  85862. }
  85863. }
  85864. else {
  85865. if(order > 2) {
  85866. if(order == 4) {
  85867. for(i = 0; i < (int)data_len; i++) {
  85868. sum = 0;
  85869. sum += qlp_coeff[3] * data[i-4];
  85870. sum += qlp_coeff[2] * data[i-3];
  85871. sum += qlp_coeff[1] * data[i-2];
  85872. sum += qlp_coeff[0] * data[i-1];
  85873. residual[i] = data[i] - (sum >> lp_quantization);
  85874. }
  85875. }
  85876. else { /* order == 3 */
  85877. for(i = 0; i < (int)data_len; i++) {
  85878. sum = 0;
  85879. sum += qlp_coeff[2] * data[i-3];
  85880. sum += qlp_coeff[1] * data[i-2];
  85881. sum += qlp_coeff[0] * data[i-1];
  85882. residual[i] = data[i] - (sum >> lp_quantization);
  85883. }
  85884. }
  85885. }
  85886. else {
  85887. if(order == 2) {
  85888. for(i = 0; i < (int)data_len; i++) {
  85889. sum = 0;
  85890. sum += qlp_coeff[1] * data[i-2];
  85891. sum += qlp_coeff[0] * data[i-1];
  85892. residual[i] = data[i] - (sum >> lp_quantization);
  85893. }
  85894. }
  85895. else { /* order == 1 */
  85896. for(i = 0; i < (int)data_len; i++)
  85897. residual[i] = data[i] - ((qlp_coeff[0] * data[i-1]) >> lp_quantization);
  85898. }
  85899. }
  85900. }
  85901. }
  85902. else { /* order > 12 */
  85903. for(i = 0; i < (int)data_len; i++) {
  85904. sum = 0;
  85905. switch(order) {
  85906. case 32: sum += qlp_coeff[31] * data[i-32];
  85907. case 31: sum += qlp_coeff[30] * data[i-31];
  85908. case 30: sum += qlp_coeff[29] * data[i-30];
  85909. case 29: sum += qlp_coeff[28] * data[i-29];
  85910. case 28: sum += qlp_coeff[27] * data[i-28];
  85911. case 27: sum += qlp_coeff[26] * data[i-27];
  85912. case 26: sum += qlp_coeff[25] * data[i-26];
  85913. case 25: sum += qlp_coeff[24] * data[i-25];
  85914. case 24: sum += qlp_coeff[23] * data[i-24];
  85915. case 23: sum += qlp_coeff[22] * data[i-23];
  85916. case 22: sum += qlp_coeff[21] * data[i-22];
  85917. case 21: sum += qlp_coeff[20] * data[i-21];
  85918. case 20: sum += qlp_coeff[19] * data[i-20];
  85919. case 19: sum += qlp_coeff[18] * data[i-19];
  85920. case 18: sum += qlp_coeff[17] * data[i-18];
  85921. case 17: sum += qlp_coeff[16] * data[i-17];
  85922. case 16: sum += qlp_coeff[15] * data[i-16];
  85923. case 15: sum += qlp_coeff[14] * data[i-15];
  85924. case 14: sum += qlp_coeff[13] * data[i-14];
  85925. case 13: sum += qlp_coeff[12] * data[i-13];
  85926. sum += qlp_coeff[11] * data[i-12];
  85927. sum += qlp_coeff[10] * data[i-11];
  85928. sum += qlp_coeff[ 9] * data[i-10];
  85929. sum += qlp_coeff[ 8] * data[i- 9];
  85930. sum += qlp_coeff[ 7] * data[i- 8];
  85931. sum += qlp_coeff[ 6] * data[i- 7];
  85932. sum += qlp_coeff[ 5] * data[i- 6];
  85933. sum += qlp_coeff[ 4] * data[i- 5];
  85934. sum += qlp_coeff[ 3] * data[i- 4];
  85935. sum += qlp_coeff[ 2] * data[i- 3];
  85936. sum += qlp_coeff[ 1] * data[i- 2];
  85937. sum += qlp_coeff[ 0] * data[i- 1];
  85938. }
  85939. residual[i] = data[i] - (sum >> lp_quantization);
  85940. }
  85941. }
  85942. }
  85943. #endif
  85944. 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[])
  85945. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  85946. {
  85947. unsigned i, j;
  85948. FLAC__int64 sum;
  85949. const FLAC__int32 *history;
  85950. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  85951. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  85952. for(i=0;i<order;i++)
  85953. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  85954. fprintf(stderr,"\n");
  85955. #endif
  85956. FLAC__ASSERT(order > 0);
  85957. for(i = 0; i < data_len; i++) {
  85958. sum = 0;
  85959. history = data;
  85960. for(j = 0; j < order; j++)
  85961. sum += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*(--history));
  85962. if(FLAC__bitmath_silog2_wide(sum >> lp_quantization) > 32) {
  85963. #if defined _MSC_VER
  85964. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: OVERFLOW, i=%u, sum=%I64d\n", i, sum >> lp_quantization);
  85965. #else
  85966. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: OVERFLOW, i=%u, sum=%lld\n", i, (long long)(sum >> lp_quantization));
  85967. #endif
  85968. break;
  85969. }
  85970. if(FLAC__bitmath_silog2_wide((FLAC__int64)(*data) - (sum >> lp_quantization)) > 32) {
  85971. #if defined _MSC_VER
  85972. 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));
  85973. #else
  85974. 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)));
  85975. #endif
  85976. break;
  85977. }
  85978. *(residual++) = *(data++) - (FLAC__int32)(sum >> lp_quantization);
  85979. }
  85980. }
  85981. #else /* fully unrolled version for normal use */
  85982. {
  85983. int i;
  85984. FLAC__int64 sum;
  85985. FLAC__ASSERT(order > 0);
  85986. FLAC__ASSERT(order <= 32);
  85987. if(order <= 12) {
  85988. if(order > 8) {
  85989. if(order > 10) {
  85990. if(order == 12) {
  85991. for(i = 0; i < (int)data_len; i++) {
  85992. sum = 0;
  85993. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  85994. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  85995. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85996. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85997. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85998. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85999. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86000. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86001. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86002. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86003. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86004. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86005. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86006. }
  86007. }
  86008. else { /* order == 11 */
  86009. for(i = 0; i < (int)data_len; i++) {
  86010. sum = 0;
  86011. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  86012. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  86013. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86014. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86015. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86016. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86017. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86018. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86019. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86020. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86021. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86022. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86023. }
  86024. }
  86025. }
  86026. else {
  86027. if(order == 10) {
  86028. for(i = 0; i < (int)data_len; i++) {
  86029. sum = 0;
  86030. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  86031. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86032. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86033. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86034. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86035. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86036. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86037. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86038. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86039. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86040. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86041. }
  86042. }
  86043. else { /* order == 9 */
  86044. for(i = 0; i < (int)data_len; i++) {
  86045. sum = 0;
  86046. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86047. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86048. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86049. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86050. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86051. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86052. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86053. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86054. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86055. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86056. }
  86057. }
  86058. }
  86059. }
  86060. else if(order > 4) {
  86061. if(order > 6) {
  86062. if(order == 8) {
  86063. for(i = 0; i < (int)data_len; i++) {
  86064. sum = 0;
  86065. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86066. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86067. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86068. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86069. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86070. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86071. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86072. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86073. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86074. }
  86075. }
  86076. else { /* order == 7 */
  86077. for(i = 0; i < (int)data_len; i++) {
  86078. sum = 0;
  86079. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86080. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86081. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86082. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86083. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86084. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86085. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86086. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86087. }
  86088. }
  86089. }
  86090. else {
  86091. if(order == 6) {
  86092. for(i = 0; i < (int)data_len; i++) {
  86093. sum = 0;
  86094. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86095. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86096. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86097. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86098. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86099. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86100. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86101. }
  86102. }
  86103. else { /* order == 5 */
  86104. for(i = 0; i < (int)data_len; i++) {
  86105. sum = 0;
  86106. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86107. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86108. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86109. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86110. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86111. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86112. }
  86113. }
  86114. }
  86115. }
  86116. else {
  86117. if(order > 2) {
  86118. if(order == 4) {
  86119. for(i = 0; i < (int)data_len; i++) {
  86120. sum = 0;
  86121. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86122. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86123. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86124. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86125. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86126. }
  86127. }
  86128. else { /* order == 3 */
  86129. for(i = 0; i < (int)data_len; i++) {
  86130. sum = 0;
  86131. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86132. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86133. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86134. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86135. }
  86136. }
  86137. }
  86138. else {
  86139. if(order == 2) {
  86140. for(i = 0; i < (int)data_len; i++) {
  86141. sum = 0;
  86142. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86143. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86144. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86145. }
  86146. }
  86147. else { /* order == 1 */
  86148. for(i = 0; i < (int)data_len; i++)
  86149. residual[i] = data[i] - (FLAC__int32)((qlp_coeff[0] * (FLAC__int64)data[i-1]) >> lp_quantization);
  86150. }
  86151. }
  86152. }
  86153. }
  86154. else { /* order > 12 */
  86155. for(i = 0; i < (int)data_len; i++) {
  86156. sum = 0;
  86157. switch(order) {
  86158. case 32: sum += qlp_coeff[31] * (FLAC__int64)data[i-32];
  86159. case 31: sum += qlp_coeff[30] * (FLAC__int64)data[i-31];
  86160. case 30: sum += qlp_coeff[29] * (FLAC__int64)data[i-30];
  86161. case 29: sum += qlp_coeff[28] * (FLAC__int64)data[i-29];
  86162. case 28: sum += qlp_coeff[27] * (FLAC__int64)data[i-28];
  86163. case 27: sum += qlp_coeff[26] * (FLAC__int64)data[i-27];
  86164. case 26: sum += qlp_coeff[25] * (FLAC__int64)data[i-26];
  86165. case 25: sum += qlp_coeff[24] * (FLAC__int64)data[i-25];
  86166. case 24: sum += qlp_coeff[23] * (FLAC__int64)data[i-24];
  86167. case 23: sum += qlp_coeff[22] * (FLAC__int64)data[i-23];
  86168. case 22: sum += qlp_coeff[21] * (FLAC__int64)data[i-22];
  86169. case 21: sum += qlp_coeff[20] * (FLAC__int64)data[i-21];
  86170. case 20: sum += qlp_coeff[19] * (FLAC__int64)data[i-20];
  86171. case 19: sum += qlp_coeff[18] * (FLAC__int64)data[i-19];
  86172. case 18: sum += qlp_coeff[17] * (FLAC__int64)data[i-18];
  86173. case 17: sum += qlp_coeff[16] * (FLAC__int64)data[i-17];
  86174. case 16: sum += qlp_coeff[15] * (FLAC__int64)data[i-16];
  86175. case 15: sum += qlp_coeff[14] * (FLAC__int64)data[i-15];
  86176. case 14: sum += qlp_coeff[13] * (FLAC__int64)data[i-14];
  86177. case 13: sum += qlp_coeff[12] * (FLAC__int64)data[i-13];
  86178. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  86179. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  86180. sum += qlp_coeff[ 9] * (FLAC__int64)data[i-10];
  86181. sum += qlp_coeff[ 8] * (FLAC__int64)data[i- 9];
  86182. sum += qlp_coeff[ 7] * (FLAC__int64)data[i- 8];
  86183. sum += qlp_coeff[ 6] * (FLAC__int64)data[i- 7];
  86184. sum += qlp_coeff[ 5] * (FLAC__int64)data[i- 6];
  86185. sum += qlp_coeff[ 4] * (FLAC__int64)data[i- 5];
  86186. sum += qlp_coeff[ 3] * (FLAC__int64)data[i- 4];
  86187. sum += qlp_coeff[ 2] * (FLAC__int64)data[i- 3];
  86188. sum += qlp_coeff[ 1] * (FLAC__int64)data[i- 2];
  86189. sum += qlp_coeff[ 0] * (FLAC__int64)data[i- 1];
  86190. }
  86191. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86192. }
  86193. }
  86194. }
  86195. #endif
  86196. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  86197. 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[])
  86198. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  86199. {
  86200. FLAC__int64 sumo;
  86201. unsigned i, j;
  86202. FLAC__int32 sum;
  86203. const FLAC__int32 *r = residual, *history;
  86204. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  86205. fprintf(stderr,"FLAC__lpc_restore_signal: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  86206. for(i=0;i<order;i++)
  86207. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  86208. fprintf(stderr,"\n");
  86209. #endif
  86210. FLAC__ASSERT(order > 0);
  86211. for(i = 0; i < data_len; i++) {
  86212. sumo = 0;
  86213. sum = 0;
  86214. history = data;
  86215. for(j = 0; j < order; j++) {
  86216. sum += qlp_coeff[j] * (*(--history));
  86217. sumo += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*history);
  86218. #if defined _MSC_VER
  86219. if(sumo > 2147483647I64 || sumo < -2147483648I64)
  86220. 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);
  86221. #else
  86222. if(sumo > 2147483647ll || sumo < -2147483648ll)
  86223. 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);
  86224. #endif
  86225. }
  86226. *(data++) = *(r++) + (sum >> lp_quantization);
  86227. }
  86228. }
  86229. #else /* fully unrolled version for normal use */
  86230. {
  86231. int i;
  86232. FLAC__int32 sum;
  86233. FLAC__ASSERT(order > 0);
  86234. FLAC__ASSERT(order <= 32);
  86235. if(order <= 12) {
  86236. if(order > 8) {
  86237. if(order > 10) {
  86238. if(order == 12) {
  86239. for(i = 0; i < (int)data_len; i++) {
  86240. sum = 0;
  86241. sum += qlp_coeff[11] * data[i-12];
  86242. sum += qlp_coeff[10] * data[i-11];
  86243. sum += qlp_coeff[9] * data[i-10];
  86244. sum += qlp_coeff[8] * data[i-9];
  86245. sum += qlp_coeff[7] * data[i-8];
  86246. sum += qlp_coeff[6] * data[i-7];
  86247. sum += qlp_coeff[5] * data[i-6];
  86248. sum += qlp_coeff[4] * data[i-5];
  86249. sum += qlp_coeff[3] * data[i-4];
  86250. sum += qlp_coeff[2] * data[i-3];
  86251. sum += qlp_coeff[1] * data[i-2];
  86252. sum += qlp_coeff[0] * data[i-1];
  86253. data[i] = residual[i] + (sum >> lp_quantization);
  86254. }
  86255. }
  86256. else { /* order == 11 */
  86257. for(i = 0; i < (int)data_len; i++) {
  86258. sum = 0;
  86259. sum += qlp_coeff[10] * data[i-11];
  86260. sum += qlp_coeff[9] * data[i-10];
  86261. sum += qlp_coeff[8] * data[i-9];
  86262. sum += qlp_coeff[7] * data[i-8];
  86263. sum += qlp_coeff[6] * data[i-7];
  86264. sum += qlp_coeff[5] * data[i-6];
  86265. sum += qlp_coeff[4] * data[i-5];
  86266. sum += qlp_coeff[3] * data[i-4];
  86267. sum += qlp_coeff[2] * data[i-3];
  86268. sum += qlp_coeff[1] * data[i-2];
  86269. sum += qlp_coeff[0] * data[i-1];
  86270. data[i] = residual[i] + (sum >> lp_quantization);
  86271. }
  86272. }
  86273. }
  86274. else {
  86275. if(order == 10) {
  86276. for(i = 0; i < (int)data_len; i++) {
  86277. sum = 0;
  86278. sum += qlp_coeff[9] * data[i-10];
  86279. sum += qlp_coeff[8] * data[i-9];
  86280. sum += qlp_coeff[7] * data[i-8];
  86281. sum += qlp_coeff[6] * data[i-7];
  86282. sum += qlp_coeff[5] * data[i-6];
  86283. sum += qlp_coeff[4] * data[i-5];
  86284. sum += qlp_coeff[3] * data[i-4];
  86285. sum += qlp_coeff[2] * data[i-3];
  86286. sum += qlp_coeff[1] * data[i-2];
  86287. sum += qlp_coeff[0] * data[i-1];
  86288. data[i] = residual[i] + (sum >> lp_quantization);
  86289. }
  86290. }
  86291. else { /* order == 9 */
  86292. for(i = 0; i < (int)data_len; i++) {
  86293. sum = 0;
  86294. sum += qlp_coeff[8] * data[i-9];
  86295. sum += qlp_coeff[7] * data[i-8];
  86296. sum += qlp_coeff[6] * data[i-7];
  86297. sum += qlp_coeff[5] * data[i-6];
  86298. sum += qlp_coeff[4] * data[i-5];
  86299. sum += qlp_coeff[3] * data[i-4];
  86300. sum += qlp_coeff[2] * data[i-3];
  86301. sum += qlp_coeff[1] * data[i-2];
  86302. sum += qlp_coeff[0] * data[i-1];
  86303. data[i] = residual[i] + (sum >> lp_quantization);
  86304. }
  86305. }
  86306. }
  86307. }
  86308. else if(order > 4) {
  86309. if(order > 6) {
  86310. if(order == 8) {
  86311. for(i = 0; i < (int)data_len; i++) {
  86312. sum = 0;
  86313. sum += qlp_coeff[7] * data[i-8];
  86314. sum += qlp_coeff[6] * data[i-7];
  86315. sum += qlp_coeff[5] * data[i-6];
  86316. sum += qlp_coeff[4] * data[i-5];
  86317. sum += qlp_coeff[3] * data[i-4];
  86318. sum += qlp_coeff[2] * data[i-3];
  86319. sum += qlp_coeff[1] * data[i-2];
  86320. sum += qlp_coeff[0] * data[i-1];
  86321. data[i] = residual[i] + (sum >> lp_quantization);
  86322. }
  86323. }
  86324. else { /* order == 7 */
  86325. for(i = 0; i < (int)data_len; i++) {
  86326. sum = 0;
  86327. sum += qlp_coeff[6] * data[i-7];
  86328. sum += qlp_coeff[5] * data[i-6];
  86329. sum += qlp_coeff[4] * data[i-5];
  86330. sum += qlp_coeff[3] * data[i-4];
  86331. sum += qlp_coeff[2] * data[i-3];
  86332. sum += qlp_coeff[1] * data[i-2];
  86333. sum += qlp_coeff[0] * data[i-1];
  86334. data[i] = residual[i] + (sum >> lp_quantization);
  86335. }
  86336. }
  86337. }
  86338. else {
  86339. if(order == 6) {
  86340. for(i = 0; i < (int)data_len; i++) {
  86341. sum = 0;
  86342. sum += qlp_coeff[5] * data[i-6];
  86343. sum += qlp_coeff[4] * data[i-5];
  86344. sum += qlp_coeff[3] * data[i-4];
  86345. sum += qlp_coeff[2] * data[i-3];
  86346. sum += qlp_coeff[1] * data[i-2];
  86347. sum += qlp_coeff[0] * data[i-1];
  86348. data[i] = residual[i] + (sum >> lp_quantization);
  86349. }
  86350. }
  86351. else { /* order == 5 */
  86352. for(i = 0; i < (int)data_len; i++) {
  86353. sum = 0;
  86354. sum += qlp_coeff[4] * data[i-5];
  86355. sum += qlp_coeff[3] * data[i-4];
  86356. sum += qlp_coeff[2] * data[i-3];
  86357. sum += qlp_coeff[1] * data[i-2];
  86358. sum += qlp_coeff[0] * data[i-1];
  86359. data[i] = residual[i] + (sum >> lp_quantization);
  86360. }
  86361. }
  86362. }
  86363. }
  86364. else {
  86365. if(order > 2) {
  86366. if(order == 4) {
  86367. for(i = 0; i < (int)data_len; i++) {
  86368. sum = 0;
  86369. sum += qlp_coeff[3] * data[i-4];
  86370. sum += qlp_coeff[2] * data[i-3];
  86371. sum += qlp_coeff[1] * data[i-2];
  86372. sum += qlp_coeff[0] * data[i-1];
  86373. data[i] = residual[i] + (sum >> lp_quantization);
  86374. }
  86375. }
  86376. else { /* order == 3 */
  86377. for(i = 0; i < (int)data_len; i++) {
  86378. sum = 0;
  86379. sum += qlp_coeff[2] * data[i-3];
  86380. sum += qlp_coeff[1] * data[i-2];
  86381. sum += qlp_coeff[0] * data[i-1];
  86382. data[i] = residual[i] + (sum >> lp_quantization);
  86383. }
  86384. }
  86385. }
  86386. else {
  86387. if(order == 2) {
  86388. for(i = 0; i < (int)data_len; i++) {
  86389. sum = 0;
  86390. sum += qlp_coeff[1] * data[i-2];
  86391. sum += qlp_coeff[0] * data[i-1];
  86392. data[i] = residual[i] + (sum >> lp_quantization);
  86393. }
  86394. }
  86395. else { /* order == 1 */
  86396. for(i = 0; i < (int)data_len; i++)
  86397. data[i] = residual[i] + ((qlp_coeff[0] * data[i-1]) >> lp_quantization);
  86398. }
  86399. }
  86400. }
  86401. }
  86402. else { /* order > 12 */
  86403. for(i = 0; i < (int)data_len; i++) {
  86404. sum = 0;
  86405. switch(order) {
  86406. case 32: sum += qlp_coeff[31] * data[i-32];
  86407. case 31: sum += qlp_coeff[30] * data[i-31];
  86408. case 30: sum += qlp_coeff[29] * data[i-30];
  86409. case 29: sum += qlp_coeff[28] * data[i-29];
  86410. case 28: sum += qlp_coeff[27] * data[i-28];
  86411. case 27: sum += qlp_coeff[26] * data[i-27];
  86412. case 26: sum += qlp_coeff[25] * data[i-26];
  86413. case 25: sum += qlp_coeff[24] * data[i-25];
  86414. case 24: sum += qlp_coeff[23] * data[i-24];
  86415. case 23: sum += qlp_coeff[22] * data[i-23];
  86416. case 22: sum += qlp_coeff[21] * data[i-22];
  86417. case 21: sum += qlp_coeff[20] * data[i-21];
  86418. case 20: sum += qlp_coeff[19] * data[i-20];
  86419. case 19: sum += qlp_coeff[18] * data[i-19];
  86420. case 18: sum += qlp_coeff[17] * data[i-18];
  86421. case 17: sum += qlp_coeff[16] * data[i-17];
  86422. case 16: sum += qlp_coeff[15] * data[i-16];
  86423. case 15: sum += qlp_coeff[14] * data[i-15];
  86424. case 14: sum += qlp_coeff[13] * data[i-14];
  86425. case 13: sum += qlp_coeff[12] * data[i-13];
  86426. sum += qlp_coeff[11] * data[i-12];
  86427. sum += qlp_coeff[10] * data[i-11];
  86428. sum += qlp_coeff[ 9] * data[i-10];
  86429. sum += qlp_coeff[ 8] * data[i- 9];
  86430. sum += qlp_coeff[ 7] * data[i- 8];
  86431. sum += qlp_coeff[ 6] * data[i- 7];
  86432. sum += qlp_coeff[ 5] * data[i- 6];
  86433. sum += qlp_coeff[ 4] * data[i- 5];
  86434. sum += qlp_coeff[ 3] * data[i- 4];
  86435. sum += qlp_coeff[ 2] * data[i- 3];
  86436. sum += qlp_coeff[ 1] * data[i- 2];
  86437. sum += qlp_coeff[ 0] * data[i- 1];
  86438. }
  86439. data[i] = residual[i] + (sum >> lp_quantization);
  86440. }
  86441. }
  86442. }
  86443. #endif
  86444. 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[])
  86445. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  86446. {
  86447. unsigned i, j;
  86448. FLAC__int64 sum;
  86449. const FLAC__int32 *r = residual, *history;
  86450. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  86451. fprintf(stderr,"FLAC__lpc_restore_signal_wide: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  86452. for(i=0;i<order;i++)
  86453. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  86454. fprintf(stderr,"\n");
  86455. #endif
  86456. FLAC__ASSERT(order > 0);
  86457. for(i = 0; i < data_len; i++) {
  86458. sum = 0;
  86459. history = data;
  86460. for(j = 0; j < order; j++)
  86461. sum += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*(--history));
  86462. if(FLAC__bitmath_silog2_wide(sum >> lp_quantization) > 32) {
  86463. #ifdef _MSC_VER
  86464. fprintf(stderr,"FLAC__lpc_restore_signal_wide: OVERFLOW, i=%u, sum=%I64d\n", i, sum >> lp_quantization);
  86465. #else
  86466. fprintf(stderr,"FLAC__lpc_restore_signal_wide: OVERFLOW, i=%u, sum=%lld\n", i, (long long)(sum >> lp_quantization));
  86467. #endif
  86468. break;
  86469. }
  86470. if(FLAC__bitmath_silog2_wide((FLAC__int64)(*r) + (sum >> lp_quantization)) > 32) {
  86471. #ifdef _MSC_VER
  86472. 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));
  86473. #else
  86474. 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)));
  86475. #endif
  86476. break;
  86477. }
  86478. *(data++) = *(r++) + (FLAC__int32)(sum >> lp_quantization);
  86479. }
  86480. }
  86481. #else /* fully unrolled version for normal use */
  86482. {
  86483. int i;
  86484. FLAC__int64 sum;
  86485. FLAC__ASSERT(order > 0);
  86486. FLAC__ASSERT(order <= 32);
  86487. if(order <= 12) {
  86488. if(order > 8) {
  86489. if(order > 10) {
  86490. if(order == 12) {
  86491. for(i = 0; i < (int)data_len; i++) {
  86492. sum = 0;
  86493. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  86494. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  86495. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  86496. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86497. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86498. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86499. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86500. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86501. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86502. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86503. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86504. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86505. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86506. }
  86507. }
  86508. else { /* order == 11 */
  86509. for(i = 0; i < (int)data_len; i++) {
  86510. sum = 0;
  86511. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  86512. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  86513. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86514. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86515. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86516. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86517. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86518. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86519. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86520. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86521. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86522. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86523. }
  86524. }
  86525. }
  86526. else {
  86527. if(order == 10) {
  86528. for(i = 0; i < (int)data_len; i++) {
  86529. sum = 0;
  86530. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  86531. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86532. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86533. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86534. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86535. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86536. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86537. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86538. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86539. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86540. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86541. }
  86542. }
  86543. else { /* order == 9 */
  86544. for(i = 0; i < (int)data_len; i++) {
  86545. sum = 0;
  86546. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86547. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86548. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86549. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86550. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86551. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86552. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86553. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86554. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86555. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86556. }
  86557. }
  86558. }
  86559. }
  86560. else if(order > 4) {
  86561. if(order > 6) {
  86562. if(order == 8) {
  86563. for(i = 0; i < (int)data_len; i++) {
  86564. sum = 0;
  86565. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86566. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86567. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86568. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86569. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86570. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86571. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86572. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86573. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86574. }
  86575. }
  86576. else { /* order == 7 */
  86577. for(i = 0; i < (int)data_len; i++) {
  86578. sum = 0;
  86579. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86580. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86581. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86582. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86583. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86584. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86585. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86586. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86587. }
  86588. }
  86589. }
  86590. else {
  86591. if(order == 6) {
  86592. for(i = 0; i < (int)data_len; i++) {
  86593. sum = 0;
  86594. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86595. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86596. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86597. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86598. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86599. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86600. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86601. }
  86602. }
  86603. else { /* order == 5 */
  86604. for(i = 0; i < (int)data_len; i++) {
  86605. sum = 0;
  86606. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86607. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86608. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86609. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86610. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86611. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86612. }
  86613. }
  86614. }
  86615. }
  86616. else {
  86617. if(order > 2) {
  86618. if(order == 4) {
  86619. for(i = 0; i < (int)data_len; i++) {
  86620. sum = 0;
  86621. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86622. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86623. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86624. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86625. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86626. }
  86627. }
  86628. else { /* order == 3 */
  86629. for(i = 0; i < (int)data_len; i++) {
  86630. sum = 0;
  86631. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86632. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86633. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86634. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86635. }
  86636. }
  86637. }
  86638. else {
  86639. if(order == 2) {
  86640. for(i = 0; i < (int)data_len; i++) {
  86641. sum = 0;
  86642. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86643. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86644. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86645. }
  86646. }
  86647. else { /* order == 1 */
  86648. for(i = 0; i < (int)data_len; i++)
  86649. data[i] = residual[i] + (FLAC__int32)((qlp_coeff[0] * (FLAC__int64)data[i-1]) >> lp_quantization);
  86650. }
  86651. }
  86652. }
  86653. }
  86654. else { /* order > 12 */
  86655. for(i = 0; i < (int)data_len; i++) {
  86656. sum = 0;
  86657. switch(order) {
  86658. case 32: sum += qlp_coeff[31] * (FLAC__int64)data[i-32];
  86659. case 31: sum += qlp_coeff[30] * (FLAC__int64)data[i-31];
  86660. case 30: sum += qlp_coeff[29] * (FLAC__int64)data[i-30];
  86661. case 29: sum += qlp_coeff[28] * (FLAC__int64)data[i-29];
  86662. case 28: sum += qlp_coeff[27] * (FLAC__int64)data[i-28];
  86663. case 27: sum += qlp_coeff[26] * (FLAC__int64)data[i-27];
  86664. case 26: sum += qlp_coeff[25] * (FLAC__int64)data[i-26];
  86665. case 25: sum += qlp_coeff[24] * (FLAC__int64)data[i-25];
  86666. case 24: sum += qlp_coeff[23] * (FLAC__int64)data[i-24];
  86667. case 23: sum += qlp_coeff[22] * (FLAC__int64)data[i-23];
  86668. case 22: sum += qlp_coeff[21] * (FLAC__int64)data[i-22];
  86669. case 21: sum += qlp_coeff[20] * (FLAC__int64)data[i-21];
  86670. case 20: sum += qlp_coeff[19] * (FLAC__int64)data[i-20];
  86671. case 19: sum += qlp_coeff[18] * (FLAC__int64)data[i-19];
  86672. case 18: sum += qlp_coeff[17] * (FLAC__int64)data[i-18];
  86673. case 17: sum += qlp_coeff[16] * (FLAC__int64)data[i-17];
  86674. case 16: sum += qlp_coeff[15] * (FLAC__int64)data[i-16];
  86675. case 15: sum += qlp_coeff[14] * (FLAC__int64)data[i-15];
  86676. case 14: sum += qlp_coeff[13] * (FLAC__int64)data[i-14];
  86677. case 13: sum += qlp_coeff[12] * (FLAC__int64)data[i-13];
  86678. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  86679. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  86680. sum += qlp_coeff[ 9] * (FLAC__int64)data[i-10];
  86681. sum += qlp_coeff[ 8] * (FLAC__int64)data[i- 9];
  86682. sum += qlp_coeff[ 7] * (FLAC__int64)data[i- 8];
  86683. sum += qlp_coeff[ 6] * (FLAC__int64)data[i- 7];
  86684. sum += qlp_coeff[ 5] * (FLAC__int64)data[i- 6];
  86685. sum += qlp_coeff[ 4] * (FLAC__int64)data[i- 5];
  86686. sum += qlp_coeff[ 3] * (FLAC__int64)data[i- 4];
  86687. sum += qlp_coeff[ 2] * (FLAC__int64)data[i- 3];
  86688. sum += qlp_coeff[ 1] * (FLAC__int64)data[i- 2];
  86689. sum += qlp_coeff[ 0] * (FLAC__int64)data[i- 1];
  86690. }
  86691. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86692. }
  86693. }
  86694. }
  86695. #endif
  86696. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  86697. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample(FLAC__double lpc_error, unsigned total_samples)
  86698. {
  86699. FLAC__double error_scale;
  86700. FLAC__ASSERT(total_samples > 0);
  86701. error_scale = 0.5 * M_LN2 * M_LN2 / (FLAC__double)total_samples;
  86702. return FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(lpc_error, error_scale);
  86703. }
  86704. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(FLAC__double lpc_error, FLAC__double error_scale)
  86705. {
  86706. if(lpc_error > 0.0) {
  86707. FLAC__double bps = (FLAC__double)0.5 * log(error_scale * lpc_error) / M_LN2;
  86708. if(bps >= 0.0)
  86709. return bps;
  86710. else
  86711. return 0.0;
  86712. }
  86713. else if(lpc_error < 0.0) { /* error should not be negative but can happen due to inadequate floating-point resolution */
  86714. return 1e32;
  86715. }
  86716. else {
  86717. return 0.0;
  86718. }
  86719. }
  86720. unsigned FLAC__lpc_compute_best_order(const FLAC__double lpc_error[], unsigned max_order, unsigned total_samples, unsigned overhead_bits_per_order)
  86721. {
  86722. 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 */
  86723. FLAC__double bits, best_bits, error_scale;
  86724. FLAC__ASSERT(max_order > 0);
  86725. FLAC__ASSERT(total_samples > 0);
  86726. error_scale = 0.5 * M_LN2 * M_LN2 / (FLAC__double)total_samples;
  86727. best_index = 0;
  86728. best_bits = (unsigned)(-1);
  86729. for(index = 0, order = 1; index < max_order; index++, order++) {
  86730. 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);
  86731. if(bits < best_bits) {
  86732. best_index = index;
  86733. best_bits = bits;
  86734. }
  86735. }
  86736. return best_index+1; /* +1 since index of lpc_error[] is order-1 */
  86737. }
  86738. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  86739. #endif
  86740. /*** End of inlined file: lpc_flac.c ***/
  86741. /*** Start of inlined file: md5.c ***/
  86742. /*** Start of inlined file: juce_FlacHeader.h ***/
  86743. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  86744. // tasks..
  86745. #define VERSION "1.2.1"
  86746. #define FLAC__NO_DLL 1
  86747. #if JUCE_MSVC
  86748. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  86749. #endif
  86750. #if JUCE_MAC
  86751. #define FLAC__SYS_DARWIN 1
  86752. #endif
  86753. /*** End of inlined file: juce_FlacHeader.h ***/
  86754. #if JUCE_USE_FLAC
  86755. #if HAVE_CONFIG_H
  86756. # include <config.h>
  86757. #endif
  86758. #include <stdlib.h> /* for malloc() */
  86759. #include <string.h> /* for memcpy() */
  86760. /*** Start of inlined file: md5.h ***/
  86761. #ifndef FLAC__PRIVATE__MD5_H
  86762. #define FLAC__PRIVATE__MD5_H
  86763. typedef struct {
  86764. FLAC__uint32 in[16];
  86765. FLAC__uint32 buf[4];
  86766. FLAC__uint32 bytes[2];
  86767. FLAC__byte *internal_buf;
  86768. size_t capacity;
  86769. } FLAC__MD5Context;
  86770. void FLAC__MD5Init(FLAC__MD5Context *context);
  86771. void FLAC__MD5Final(FLAC__byte digest[16], FLAC__MD5Context *context);
  86772. FLAC__bool FLAC__MD5Accumulate(FLAC__MD5Context *ctx, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample);
  86773. #endif
  86774. /*** End of inlined file: md5.h ***/
  86775. #ifndef FLaC__INLINE
  86776. #define FLaC__INLINE
  86777. #endif
  86778. #define F1(x, y, z) (z ^ (x & (y ^ z)))
  86779. #define F2(x, y, z) F1(z, x, y)
  86780. #define F3(x, y, z) (x ^ y ^ z)
  86781. #define F4(x, y, z) (y ^ (x | ~z))
  86782. #define MD5STEP(f,w,x,y,z,in,s) \
  86783. (w += f(x,y,z) + in, w = (w<<s | w>>(32-s)) + x)
  86784. static void FLAC__MD5Transform(FLAC__uint32 buf[4], FLAC__uint32 const in[16])
  86785. {
  86786. register FLAC__uint32 a, b, c, d;
  86787. a = buf[0];
  86788. b = buf[1];
  86789. c = buf[2];
  86790. d = buf[3];
  86791. MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
  86792. MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
  86793. MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
  86794. MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
  86795. MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
  86796. MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
  86797. MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
  86798. MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
  86799. MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
  86800. MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
  86801. MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
  86802. MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
  86803. MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
  86804. MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
  86805. MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
  86806. MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
  86807. MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
  86808. MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
  86809. MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
  86810. MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
  86811. MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
  86812. MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
  86813. MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
  86814. MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
  86815. MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
  86816. MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
  86817. MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
  86818. MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
  86819. MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
  86820. MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
  86821. MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
  86822. MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
  86823. MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
  86824. MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
  86825. MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
  86826. MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
  86827. MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
  86828. MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
  86829. MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
  86830. MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
  86831. MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
  86832. MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
  86833. MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
  86834. MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
  86835. MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
  86836. MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
  86837. MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
  86838. MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
  86839. MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
  86840. MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
  86841. MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
  86842. MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
  86843. MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
  86844. MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
  86845. MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
  86846. MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
  86847. MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
  86848. MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
  86849. MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
  86850. MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
  86851. MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
  86852. MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
  86853. MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
  86854. MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
  86855. buf[0] += a;
  86856. buf[1] += b;
  86857. buf[2] += c;
  86858. buf[3] += d;
  86859. }
  86860. #if WORDS_BIGENDIAN
  86861. //@@@@@@ OPT: use bswap/intrinsics
  86862. static void byteSwap(FLAC__uint32 *buf, unsigned words)
  86863. {
  86864. register FLAC__uint32 x;
  86865. do {
  86866. x = *buf;
  86867. x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff);
  86868. *buf++ = (x >> 16) | (x << 16);
  86869. } while (--words);
  86870. }
  86871. static void byteSwapX16(FLAC__uint32 *buf)
  86872. {
  86873. register FLAC__uint32 x;
  86874. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86875. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86876. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86877. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86878. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86879. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86880. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86881. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86882. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86883. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86884. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86885. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86886. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86887. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86888. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86889. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf = (x >> 16) | (x << 16);
  86890. }
  86891. #else
  86892. #define byteSwap(buf, words)
  86893. #define byteSwapX16(buf)
  86894. #endif
  86895. static void FLAC__MD5Update(FLAC__MD5Context *ctx, FLAC__byte const *buf, unsigned len)
  86896. {
  86897. FLAC__uint32 t;
  86898. t = ctx->bytes[0];
  86899. if ((ctx->bytes[0] = t + len) < t)
  86900. ctx->bytes[1]++; /* Carry from low to high */
  86901. t = 64 - (t & 0x3f); /* Space available in ctx->in (at least 1) */
  86902. if (t > len) {
  86903. memcpy((FLAC__byte *)ctx->in + 64 - t, buf, len);
  86904. return;
  86905. }
  86906. memcpy((FLAC__byte *)ctx->in + 64 - t, buf, t);
  86907. byteSwapX16(ctx->in);
  86908. FLAC__MD5Transform(ctx->buf, ctx->in);
  86909. buf += t;
  86910. len -= t;
  86911. while (len >= 64) {
  86912. memcpy(ctx->in, buf, 64);
  86913. byteSwapX16(ctx->in);
  86914. FLAC__MD5Transform(ctx->buf, ctx->in);
  86915. buf += 64;
  86916. len -= 64;
  86917. }
  86918. memcpy(ctx->in, buf, len);
  86919. }
  86920. void FLAC__MD5Init(FLAC__MD5Context *ctx)
  86921. {
  86922. ctx->buf[0] = 0x67452301;
  86923. ctx->buf[1] = 0xefcdab89;
  86924. ctx->buf[2] = 0x98badcfe;
  86925. ctx->buf[3] = 0x10325476;
  86926. ctx->bytes[0] = 0;
  86927. ctx->bytes[1] = 0;
  86928. ctx->internal_buf = 0;
  86929. ctx->capacity = 0;
  86930. }
  86931. void FLAC__MD5Final(FLAC__byte digest[16], FLAC__MD5Context *ctx)
  86932. {
  86933. int count = ctx->bytes[0] & 0x3f; /* Number of bytes in ctx->in */
  86934. FLAC__byte *p = (FLAC__byte *)ctx->in + count;
  86935. *p++ = 0x80;
  86936. count = 56 - 1 - count;
  86937. if (count < 0) { /* Padding forces an extra block */
  86938. memset(p, 0, count + 8);
  86939. byteSwapX16(ctx->in);
  86940. FLAC__MD5Transform(ctx->buf, ctx->in);
  86941. p = (FLAC__byte *)ctx->in;
  86942. count = 56;
  86943. }
  86944. memset(p, 0, count);
  86945. byteSwap(ctx->in, 14);
  86946. ctx->in[14] = ctx->bytes[0] << 3;
  86947. ctx->in[15] = ctx->bytes[1] << 3 | ctx->bytes[0] >> 29;
  86948. FLAC__MD5Transform(ctx->buf, ctx->in);
  86949. byteSwap(ctx->buf, 4);
  86950. memcpy(digest, ctx->buf, 16);
  86951. memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */
  86952. if(0 != ctx->internal_buf) {
  86953. free(ctx->internal_buf);
  86954. ctx->internal_buf = 0;
  86955. ctx->capacity = 0;
  86956. }
  86957. }
  86958. static void format_input_(FLAC__byte *buf, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample)
  86959. {
  86960. unsigned channel, sample;
  86961. register FLAC__int32 a_word;
  86962. register FLAC__byte *buf_ = buf;
  86963. #if WORDS_BIGENDIAN
  86964. #else
  86965. if(channels == 2 && bytes_per_sample == 2) {
  86966. FLAC__int16 *buf1_ = ((FLAC__int16*)buf_) + 1;
  86967. memcpy(buf_, signal[0], sizeof(FLAC__int32) * samples);
  86968. for(sample = 0; sample < samples; sample++, buf1_+=2)
  86969. *buf1_ = (FLAC__int16)signal[1][sample];
  86970. }
  86971. else if(channels == 1 && bytes_per_sample == 2) {
  86972. FLAC__int16 *buf1_ = (FLAC__int16*)buf_;
  86973. for(sample = 0; sample < samples; sample++)
  86974. *buf1_++ = (FLAC__int16)signal[0][sample];
  86975. }
  86976. else
  86977. #endif
  86978. if(bytes_per_sample == 2) {
  86979. if(channels == 2) {
  86980. for(sample = 0; sample < samples; sample++) {
  86981. a_word = signal[0][sample];
  86982. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86983. *buf_++ = (FLAC__byte)a_word;
  86984. a_word = signal[1][sample];
  86985. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86986. *buf_++ = (FLAC__byte)a_word;
  86987. }
  86988. }
  86989. else if(channels == 1) {
  86990. for(sample = 0; sample < samples; sample++) {
  86991. a_word = signal[0][sample];
  86992. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86993. *buf_++ = (FLAC__byte)a_word;
  86994. }
  86995. }
  86996. else {
  86997. for(sample = 0; sample < samples; sample++) {
  86998. for(channel = 0; channel < channels; channel++) {
  86999. a_word = signal[channel][sample];
  87000. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87001. *buf_++ = (FLAC__byte)a_word;
  87002. }
  87003. }
  87004. }
  87005. }
  87006. else if(bytes_per_sample == 3) {
  87007. if(channels == 2) {
  87008. for(sample = 0; sample < samples; sample++) {
  87009. a_word = signal[0][sample];
  87010. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87011. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87012. *buf_++ = (FLAC__byte)a_word;
  87013. a_word = signal[1][sample];
  87014. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87015. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87016. *buf_++ = (FLAC__byte)a_word;
  87017. }
  87018. }
  87019. else if(channels == 1) {
  87020. for(sample = 0; sample < samples; sample++) {
  87021. a_word = signal[0][sample];
  87022. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87023. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87024. *buf_++ = (FLAC__byte)a_word;
  87025. }
  87026. }
  87027. else {
  87028. for(sample = 0; sample < samples; sample++) {
  87029. for(channel = 0; channel < channels; channel++) {
  87030. a_word = signal[channel][sample];
  87031. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87032. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87033. *buf_++ = (FLAC__byte)a_word;
  87034. }
  87035. }
  87036. }
  87037. }
  87038. else if(bytes_per_sample == 1) {
  87039. if(channels == 2) {
  87040. for(sample = 0; sample < samples; sample++) {
  87041. a_word = signal[0][sample];
  87042. *buf_++ = (FLAC__byte)a_word;
  87043. a_word = signal[1][sample];
  87044. *buf_++ = (FLAC__byte)a_word;
  87045. }
  87046. }
  87047. else if(channels == 1) {
  87048. for(sample = 0; sample < samples; sample++) {
  87049. a_word = signal[0][sample];
  87050. *buf_++ = (FLAC__byte)a_word;
  87051. }
  87052. }
  87053. else {
  87054. for(sample = 0; sample < samples; sample++) {
  87055. for(channel = 0; channel < channels; channel++) {
  87056. a_word = signal[channel][sample];
  87057. *buf_++ = (FLAC__byte)a_word;
  87058. }
  87059. }
  87060. }
  87061. }
  87062. else { /* bytes_per_sample == 4, maybe optimize more later */
  87063. for(sample = 0; sample < samples; sample++) {
  87064. for(channel = 0; channel < channels; channel++) {
  87065. a_word = signal[channel][sample];
  87066. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87067. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87068. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87069. *buf_++ = (FLAC__byte)a_word;
  87070. }
  87071. }
  87072. }
  87073. }
  87074. FLAC__bool FLAC__MD5Accumulate(FLAC__MD5Context *ctx, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample)
  87075. {
  87076. const size_t bytes_needed = (size_t)channels * (size_t)samples * (size_t)bytes_per_sample;
  87077. if((size_t)channels > SIZE_MAX / (size_t)bytes_per_sample)
  87078. return false;
  87079. if((size_t)channels * (size_t)bytes_per_sample > SIZE_MAX / (size_t)samples)
  87080. return false;
  87081. if(ctx->capacity < bytes_needed) {
  87082. FLAC__byte *tmp = (FLAC__byte*)realloc(ctx->internal_buf, bytes_needed);
  87083. if(0 == tmp) {
  87084. free(ctx->internal_buf);
  87085. if(0 == (ctx->internal_buf = (FLAC__byte*)safe_malloc_(bytes_needed)))
  87086. return false;
  87087. }
  87088. ctx->internal_buf = tmp;
  87089. ctx->capacity = bytes_needed;
  87090. }
  87091. format_input_(ctx->internal_buf, signal, channels, samples, bytes_per_sample);
  87092. FLAC__MD5Update(ctx, ctx->internal_buf, bytes_needed);
  87093. return true;
  87094. }
  87095. #endif
  87096. /*** End of inlined file: md5.c ***/
  87097. /*** Start of inlined file: memory.c ***/
  87098. /*** Start of inlined file: juce_FlacHeader.h ***/
  87099. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  87100. // tasks..
  87101. #define VERSION "1.2.1"
  87102. #define FLAC__NO_DLL 1
  87103. #if JUCE_MSVC
  87104. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  87105. #endif
  87106. #if JUCE_MAC
  87107. #define FLAC__SYS_DARWIN 1
  87108. #endif
  87109. /*** End of inlined file: juce_FlacHeader.h ***/
  87110. #if JUCE_USE_FLAC
  87111. #if HAVE_CONFIG_H
  87112. # include <config.h>
  87113. #endif
  87114. /*** Start of inlined file: memory.h ***/
  87115. #ifndef FLAC__PRIVATE__MEMORY_H
  87116. #define FLAC__PRIVATE__MEMORY_H
  87117. #ifdef HAVE_CONFIG_H
  87118. #include <config.h>
  87119. #endif
  87120. #include <stdlib.h> /* for size_t */
  87121. void *FLAC__memory_alloc_aligned(size_t bytes, void **aligned_address);
  87122. FLAC__bool FLAC__memory_alloc_aligned_int32_array(unsigned elements, FLAC__int32 **unaligned_pointer, FLAC__int32 **aligned_pointer);
  87123. FLAC__bool FLAC__memory_alloc_aligned_uint32_array(unsigned elements, FLAC__uint32 **unaligned_pointer, FLAC__uint32 **aligned_pointer);
  87124. FLAC__bool FLAC__memory_alloc_aligned_uint64_array(unsigned elements, FLAC__uint64 **unaligned_pointer, FLAC__uint64 **aligned_pointer);
  87125. FLAC__bool FLAC__memory_alloc_aligned_unsigned_array(unsigned elements, unsigned **unaligned_pointer, unsigned **aligned_pointer);
  87126. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  87127. FLAC__bool FLAC__memory_alloc_aligned_real_array(unsigned elements, FLAC__real **unaligned_pointer, FLAC__real **aligned_pointer);
  87128. #endif
  87129. #endif
  87130. /*** End of inlined file: memory.h ***/
  87131. void *FLAC__memory_alloc_aligned(size_t bytes, void **aligned_address)
  87132. {
  87133. void *x;
  87134. FLAC__ASSERT(0 != aligned_address);
  87135. #ifdef FLAC__ALIGN_MALLOC_DATA
  87136. x = safe_malloc_add_2op_(bytes, /*+*/31);
  87137. #ifdef SIZEOF_VOIDP
  87138. #if SIZEOF_VOIDP == 4
  87139. *aligned_address = (void*)(((unsigned)x + 31) & -32);
  87140. #elif SIZEOF_VOIDP == 8
  87141. *aligned_address = (void*)(((FLAC__uint64)x + 31) & (FLAC__uint64)(-((FLAC__int64)32)));
  87142. #else
  87143. # error Unsupported sizeof(void*)
  87144. #endif
  87145. #else
  87146. if(sizeof(void*) == sizeof(unsigned))
  87147. *aligned_address = (void*)(((unsigned)x + 31) & -32);
  87148. else if(sizeof(void*) == sizeof(FLAC__uint64))
  87149. *aligned_address = (void*)(((FLAC__uint64)x + 31) & (FLAC__uint64)(-((FLAC__int64)32)));
  87150. else
  87151. return 0;
  87152. #endif
  87153. #else
  87154. x = safe_malloc_(bytes);
  87155. *aligned_address = x;
  87156. #endif
  87157. return x;
  87158. }
  87159. FLAC__bool FLAC__memory_alloc_aligned_int32_array(unsigned elements, FLAC__int32 **unaligned_pointer, FLAC__int32 **aligned_pointer)
  87160. {
  87161. FLAC__int32 *pu; /* unaligned pointer */
  87162. union { /* union needed to comply with C99 pointer aliasing rules */
  87163. FLAC__int32 *pa; /* aligned pointer */
  87164. void *pv; /* aligned pointer alias */
  87165. } u;
  87166. FLAC__ASSERT(elements > 0);
  87167. FLAC__ASSERT(0 != unaligned_pointer);
  87168. FLAC__ASSERT(0 != aligned_pointer);
  87169. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  87170. pu = (FLAC__int32*)FLAC__memory_alloc_aligned(sizeof(*pu) * (size_t)elements, &u.pv);
  87171. if(0 == pu) {
  87172. return false;
  87173. }
  87174. else {
  87175. if(*unaligned_pointer != 0)
  87176. free(*unaligned_pointer);
  87177. *unaligned_pointer = pu;
  87178. *aligned_pointer = u.pa;
  87179. return true;
  87180. }
  87181. }
  87182. FLAC__bool FLAC__memory_alloc_aligned_uint32_array(unsigned elements, FLAC__uint32 **unaligned_pointer, FLAC__uint32 **aligned_pointer)
  87183. {
  87184. FLAC__uint32 *pu; /* unaligned pointer */
  87185. union { /* union needed to comply with C99 pointer aliasing rules */
  87186. FLAC__uint32 *pa; /* aligned pointer */
  87187. void *pv; /* aligned pointer alias */
  87188. } u;
  87189. FLAC__ASSERT(elements > 0);
  87190. FLAC__ASSERT(0 != unaligned_pointer);
  87191. FLAC__ASSERT(0 != aligned_pointer);
  87192. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  87193. pu = (FLAC__uint32*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  87194. if(0 == pu) {
  87195. return false;
  87196. }
  87197. else {
  87198. if(*unaligned_pointer != 0)
  87199. free(*unaligned_pointer);
  87200. *unaligned_pointer = pu;
  87201. *aligned_pointer = u.pa;
  87202. return true;
  87203. }
  87204. }
  87205. FLAC__bool FLAC__memory_alloc_aligned_uint64_array(unsigned elements, FLAC__uint64 **unaligned_pointer, FLAC__uint64 **aligned_pointer)
  87206. {
  87207. FLAC__uint64 *pu; /* unaligned pointer */
  87208. union { /* union needed to comply with C99 pointer aliasing rules */
  87209. FLAC__uint64 *pa; /* aligned pointer */
  87210. void *pv; /* aligned pointer alias */
  87211. } u;
  87212. FLAC__ASSERT(elements > 0);
  87213. FLAC__ASSERT(0 != unaligned_pointer);
  87214. FLAC__ASSERT(0 != aligned_pointer);
  87215. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  87216. pu = (FLAC__uint64*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  87217. if(0 == pu) {
  87218. return false;
  87219. }
  87220. else {
  87221. if(*unaligned_pointer != 0)
  87222. free(*unaligned_pointer);
  87223. *unaligned_pointer = pu;
  87224. *aligned_pointer = u.pa;
  87225. return true;
  87226. }
  87227. }
  87228. FLAC__bool FLAC__memory_alloc_aligned_unsigned_array(unsigned elements, unsigned **unaligned_pointer, unsigned **aligned_pointer)
  87229. {
  87230. unsigned *pu; /* unaligned pointer */
  87231. union { /* union needed to comply with C99 pointer aliasing rules */
  87232. unsigned *pa; /* aligned pointer */
  87233. void *pv; /* aligned pointer alias */
  87234. } u;
  87235. FLAC__ASSERT(elements > 0);
  87236. FLAC__ASSERT(0 != unaligned_pointer);
  87237. FLAC__ASSERT(0 != aligned_pointer);
  87238. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  87239. pu = (unsigned*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  87240. if(0 == pu) {
  87241. return false;
  87242. }
  87243. else {
  87244. if(*unaligned_pointer != 0)
  87245. free(*unaligned_pointer);
  87246. *unaligned_pointer = pu;
  87247. *aligned_pointer = u.pa;
  87248. return true;
  87249. }
  87250. }
  87251. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  87252. FLAC__bool FLAC__memory_alloc_aligned_real_array(unsigned elements, FLAC__real **unaligned_pointer, FLAC__real **aligned_pointer)
  87253. {
  87254. FLAC__real *pu; /* unaligned pointer */
  87255. union { /* union needed to comply with C99 pointer aliasing rules */
  87256. FLAC__real *pa; /* aligned pointer */
  87257. void *pv; /* aligned pointer alias */
  87258. } u;
  87259. FLAC__ASSERT(elements > 0);
  87260. FLAC__ASSERT(0 != unaligned_pointer);
  87261. FLAC__ASSERT(0 != aligned_pointer);
  87262. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  87263. pu = (FLAC__real*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  87264. if(0 == pu) {
  87265. return false;
  87266. }
  87267. else {
  87268. if(*unaligned_pointer != 0)
  87269. free(*unaligned_pointer);
  87270. *unaligned_pointer = pu;
  87271. *aligned_pointer = u.pa;
  87272. return true;
  87273. }
  87274. }
  87275. #endif
  87276. #endif
  87277. /*** End of inlined file: memory.c ***/
  87278. /*** Start of inlined file: stream_decoder.c ***/
  87279. /*** Start of inlined file: juce_FlacHeader.h ***/
  87280. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  87281. // tasks..
  87282. #define VERSION "1.2.1"
  87283. #define FLAC__NO_DLL 1
  87284. #if JUCE_MSVC
  87285. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  87286. #endif
  87287. #if JUCE_MAC
  87288. #define FLAC__SYS_DARWIN 1
  87289. #endif
  87290. /*** End of inlined file: juce_FlacHeader.h ***/
  87291. #if JUCE_USE_FLAC
  87292. #if HAVE_CONFIG_H
  87293. # include <config.h>
  87294. #endif
  87295. #if defined _MSC_VER || defined __MINGW32__
  87296. #include <io.h> /* for _setmode() */
  87297. #include <fcntl.h> /* for _O_BINARY */
  87298. #endif
  87299. #if defined __CYGWIN__ || defined __EMX__
  87300. #include <io.h> /* for setmode(), O_BINARY */
  87301. #include <fcntl.h> /* for _O_BINARY */
  87302. #endif
  87303. #include <stdio.h>
  87304. #include <stdlib.h> /* for malloc() */
  87305. #include <string.h> /* for memset/memcpy() */
  87306. #include <sys/stat.h> /* for stat() */
  87307. #include <sys/types.h> /* for off_t */
  87308. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINGW32__
  87309. #if _MSC_VER <= 1600 || defined __BORLANDC__ /* @@@ [2G limit] */
  87310. #define fseeko fseek
  87311. #define ftello ftell
  87312. #endif
  87313. #endif
  87314. /*** Start of inlined file: stream_decoder.h ***/
  87315. #ifndef FLAC__PROTECTED__STREAM_DECODER_H
  87316. #define FLAC__PROTECTED__STREAM_DECODER_H
  87317. #if FLAC__HAS_OGG
  87318. #include "include/private/ogg_decoder_aspect.h"
  87319. #endif
  87320. typedef struct FLAC__StreamDecoderProtected {
  87321. FLAC__StreamDecoderState state;
  87322. unsigned channels;
  87323. FLAC__ChannelAssignment channel_assignment;
  87324. unsigned bits_per_sample;
  87325. unsigned sample_rate; /* in Hz */
  87326. unsigned blocksize; /* in samples (per channel) */
  87327. FLAC__bool md5_checking; /* if true, generate MD5 signature of decoded data and compare against signature in the STREAMINFO metadata block */
  87328. #if FLAC__HAS_OGG
  87329. FLAC__OggDecoderAspect ogg_decoder_aspect;
  87330. #endif
  87331. } FLAC__StreamDecoderProtected;
  87332. unsigned FLAC__stream_decoder_get_input_bytes_unconsumed(const FLAC__StreamDecoder *decoder);
  87333. #endif
  87334. /*** End of inlined file: stream_decoder.h ***/
  87335. #ifdef max
  87336. #undef max
  87337. #endif
  87338. #define max(a,b) ((a)>(b)?(a):(b))
  87339. #ifdef _MSC_VER
  87340. #define FLAC__U64L(x) x
  87341. #else
  87342. #define FLAC__U64L(x) x##LLU
  87343. #endif
  87344. FLAC_API int FLAC_API_SUPPORTS_OGG_FLAC =
  87345. #if FLAC__HAS_OGG
  87346. 1
  87347. #else
  87348. 0
  87349. #endif
  87350. ;
  87351. static FLAC__byte ID3V2_TAG_[3] = { 'I', 'D', '3' };
  87352. static void set_defaults_dec(FLAC__StreamDecoder *decoder);
  87353. static FILE *get_binary_stdin_(void);
  87354. static FLAC__bool allocate_output_(FLAC__StreamDecoder *decoder, unsigned size, unsigned channels);
  87355. static FLAC__bool has_id_filtered_(FLAC__StreamDecoder *decoder, FLAC__byte *id);
  87356. static FLAC__bool find_metadata_(FLAC__StreamDecoder *decoder);
  87357. static FLAC__bool read_metadata_(FLAC__StreamDecoder *decoder);
  87358. static FLAC__bool read_metadata_streaminfo_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length);
  87359. static FLAC__bool read_metadata_seektable_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length);
  87360. static FLAC__bool read_metadata_vorbiscomment_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_VorbisComment *obj);
  87361. static FLAC__bool read_metadata_cuesheet_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_CueSheet *obj);
  87362. static FLAC__bool read_metadata_picture_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_Picture *obj);
  87363. static FLAC__bool skip_id3v2_tag_(FLAC__StreamDecoder *decoder);
  87364. static FLAC__bool frame_sync_(FLAC__StreamDecoder *decoder);
  87365. static FLAC__bool read_frame_(FLAC__StreamDecoder *decoder, FLAC__bool *got_a_frame, FLAC__bool do_full_decode);
  87366. static FLAC__bool read_frame_header_(FLAC__StreamDecoder *decoder);
  87367. static FLAC__bool read_subframe_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
  87368. static FLAC__bool read_subframe_constant_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
  87369. static FLAC__bool read_subframe_fixed_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode);
  87370. static FLAC__bool read_subframe_lpc_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode);
  87371. static FLAC__bool read_subframe_verbatim_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
  87372. 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);
  87373. static FLAC__bool read_zero_padding_(FLAC__StreamDecoder *decoder);
  87374. static FLAC__bool read_callback_(FLAC__byte buffer[], size_t *bytes, void *client_data);
  87375. #if FLAC__HAS_OGG
  87376. static FLAC__StreamDecoderReadStatus read_callback_ogg_aspect_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes);
  87377. static FLAC__OggDecoderAspectReadStatus read_callback_proxy_(const void *void_decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  87378. #endif
  87379. static FLAC__StreamDecoderWriteStatus write_audio_frame_to_client_(FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[]);
  87380. static void send_error_to_client_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status);
  87381. static FLAC__bool seek_to_absolute_sample_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample);
  87382. #if FLAC__HAS_OGG
  87383. static FLAC__bool seek_to_absolute_sample_ogg_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample);
  87384. #endif
  87385. static FLAC__StreamDecoderReadStatus file_read_callback_dec (const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  87386. static FLAC__StreamDecoderSeekStatus file_seek_callback_dec (const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  87387. static FLAC__StreamDecoderTellStatus file_tell_callback_dec (const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  87388. static FLAC__StreamDecoderLengthStatus file_length_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
  87389. static FLAC__bool file_eof_callback_(const FLAC__StreamDecoder *decoder, void *client_data);
  87390. typedef struct FLAC__StreamDecoderPrivate {
  87391. #if FLAC__HAS_OGG
  87392. FLAC__bool is_ogg;
  87393. #endif
  87394. FLAC__StreamDecoderReadCallback read_callback;
  87395. FLAC__StreamDecoderSeekCallback seek_callback;
  87396. FLAC__StreamDecoderTellCallback tell_callback;
  87397. FLAC__StreamDecoderLengthCallback length_callback;
  87398. FLAC__StreamDecoderEofCallback eof_callback;
  87399. FLAC__StreamDecoderWriteCallback write_callback;
  87400. FLAC__StreamDecoderMetadataCallback metadata_callback;
  87401. FLAC__StreamDecoderErrorCallback error_callback;
  87402. 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[]);
  87403. 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[]);
  87404. 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[]);
  87405. 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[]);
  87406. FLAC__bool (*local_bitreader_read_rice_signed_block)(FLAC__BitReader *br, int* vals, unsigned nvals, unsigned parameter);
  87407. void *client_data;
  87408. FILE *file; /* only used if FLAC__stream_decoder_init_file()/FLAC__stream_decoder_init_file() called, else NULL */
  87409. FLAC__BitReader *input;
  87410. FLAC__int32 *output[FLAC__MAX_CHANNELS];
  87411. FLAC__int32 *residual[FLAC__MAX_CHANNELS]; /* WATCHOUT: these are the aligned pointers; the real pointers that should be free()'d are residual_unaligned[] below */
  87412. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents[FLAC__MAX_CHANNELS];
  87413. unsigned output_capacity, output_channels;
  87414. FLAC__uint32 fixed_block_size, next_fixed_block_size;
  87415. FLAC__uint64 samples_decoded;
  87416. FLAC__bool has_stream_info, has_seek_table;
  87417. FLAC__StreamMetadata stream_info;
  87418. FLAC__StreamMetadata seek_table;
  87419. FLAC__bool metadata_filter[128]; /* MAGIC number 128 == total number of metadata block types == 1 << 7 */
  87420. FLAC__byte *metadata_filter_ids;
  87421. size_t metadata_filter_ids_count, metadata_filter_ids_capacity; /* units for both are IDs, not bytes */
  87422. FLAC__Frame frame;
  87423. FLAC__bool cached; /* true if there is a byte in lookahead */
  87424. FLAC__CPUInfo cpuinfo;
  87425. FLAC__byte header_warmup[2]; /* contains the sync code and reserved bits */
  87426. FLAC__byte lookahead; /* temp storage when we need to look ahead one byte in the stream */
  87427. FLAC__int32 *residual_unaligned[FLAC__MAX_CHANNELS];
  87428. 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 */
  87429. FLAC__bool internal_reset_hack; /* used only during init() so we can call reset to set up the decoder without rewinding the input */
  87430. FLAC__bool is_seeking;
  87431. FLAC__MD5Context md5context;
  87432. FLAC__byte computed_md5sum[16]; /* this is the sum we computed from the decoded data */
  87433. FLAC__Frame last_frame; /* holds the info of the last frame we seeked to */
  87434. FLAC__uint64 first_frame_offset; /* hint to the seek routine of where in the stream the first audio frame starts */
  87435. FLAC__uint64 target_sample;
  87436. unsigned unparseable_frame_count; /* used to tell whether we're decoding a future version of FLAC or just got a bad sync */
  87437. #if FLAC__HAS_OGG
  87438. FLAC__bool got_a_frame; /* hack needed in Ogg FLAC seek routine to check when process_single() actually writes a frame */
  87439. #endif
  87440. } FLAC__StreamDecoderPrivate;
  87441. FLAC_API const char * const FLAC__StreamDecoderStateString[] = {
  87442. "FLAC__STREAM_DECODER_SEARCH_FOR_METADATA",
  87443. "FLAC__STREAM_DECODER_READ_METADATA",
  87444. "FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC",
  87445. "FLAC__STREAM_DECODER_READ_FRAME",
  87446. "FLAC__STREAM_DECODER_END_OF_STREAM",
  87447. "FLAC__STREAM_DECODER_OGG_ERROR",
  87448. "FLAC__STREAM_DECODER_SEEK_ERROR",
  87449. "FLAC__STREAM_DECODER_ABORTED",
  87450. "FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR",
  87451. "FLAC__STREAM_DECODER_UNINITIALIZED"
  87452. };
  87453. FLAC_API const char * const FLAC__StreamDecoderInitStatusString[] = {
  87454. "FLAC__STREAM_DECODER_INIT_STATUS_OK",
  87455. "FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER",
  87456. "FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS",
  87457. "FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR",
  87458. "FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE",
  87459. "FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED"
  87460. };
  87461. FLAC_API const char * const FLAC__StreamDecoderReadStatusString[] = {
  87462. "FLAC__STREAM_DECODER_READ_STATUS_CONTINUE",
  87463. "FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM",
  87464. "FLAC__STREAM_DECODER_READ_STATUS_ABORT"
  87465. };
  87466. FLAC_API const char * const FLAC__StreamDecoderSeekStatusString[] = {
  87467. "FLAC__STREAM_DECODER_SEEK_STATUS_OK",
  87468. "FLAC__STREAM_DECODER_SEEK_STATUS_ERROR",
  87469. "FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED"
  87470. };
  87471. FLAC_API const char * const FLAC__StreamDecoderTellStatusString[] = {
  87472. "FLAC__STREAM_DECODER_TELL_STATUS_OK",
  87473. "FLAC__STREAM_DECODER_TELL_STATUS_ERROR",
  87474. "FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED"
  87475. };
  87476. FLAC_API const char * const FLAC__StreamDecoderLengthStatusString[] = {
  87477. "FLAC__STREAM_DECODER_LENGTH_STATUS_OK",
  87478. "FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR",
  87479. "FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED"
  87480. };
  87481. FLAC_API const char * const FLAC__StreamDecoderWriteStatusString[] = {
  87482. "FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE",
  87483. "FLAC__STREAM_DECODER_WRITE_STATUS_ABORT"
  87484. };
  87485. FLAC_API const char * const FLAC__StreamDecoderErrorStatusString[] = {
  87486. "FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC",
  87487. "FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER",
  87488. "FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH",
  87489. "FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM"
  87490. };
  87491. FLAC_API FLAC__StreamDecoder *FLAC__stream_decoder_new(void)
  87492. {
  87493. FLAC__StreamDecoder *decoder;
  87494. unsigned i;
  87495. FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is not true */
  87496. decoder = (FLAC__StreamDecoder*)calloc(1, sizeof(FLAC__StreamDecoder));
  87497. if(decoder == 0) {
  87498. return 0;
  87499. }
  87500. decoder->protected_ = (FLAC__StreamDecoderProtected*)calloc(1, sizeof(FLAC__StreamDecoderProtected));
  87501. if(decoder->protected_ == 0) {
  87502. free(decoder);
  87503. return 0;
  87504. }
  87505. decoder->private_ = (FLAC__StreamDecoderPrivate*)calloc(1, sizeof(FLAC__StreamDecoderPrivate));
  87506. if(decoder->private_ == 0) {
  87507. free(decoder->protected_);
  87508. free(decoder);
  87509. return 0;
  87510. }
  87511. decoder->private_->input = FLAC__bitreader_new();
  87512. if(decoder->private_->input == 0) {
  87513. free(decoder->private_);
  87514. free(decoder->protected_);
  87515. free(decoder);
  87516. return 0;
  87517. }
  87518. decoder->private_->metadata_filter_ids_capacity = 16;
  87519. if(0 == (decoder->private_->metadata_filter_ids = (FLAC__byte*)malloc((FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8) * decoder->private_->metadata_filter_ids_capacity))) {
  87520. FLAC__bitreader_delete(decoder->private_->input);
  87521. free(decoder->private_);
  87522. free(decoder->protected_);
  87523. free(decoder);
  87524. return 0;
  87525. }
  87526. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  87527. decoder->private_->output[i] = 0;
  87528. decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0;
  87529. }
  87530. decoder->private_->output_capacity = 0;
  87531. decoder->private_->output_channels = 0;
  87532. decoder->private_->has_seek_table = false;
  87533. for(i = 0; i < FLAC__MAX_CHANNELS; i++)
  87534. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&decoder->private_->partitioned_rice_contents[i]);
  87535. decoder->private_->file = 0;
  87536. set_defaults_dec(decoder);
  87537. decoder->protected_->state = FLAC__STREAM_DECODER_UNINITIALIZED;
  87538. return decoder;
  87539. }
  87540. FLAC_API void FLAC__stream_decoder_delete(FLAC__StreamDecoder *decoder)
  87541. {
  87542. unsigned i;
  87543. FLAC__ASSERT(0 != decoder);
  87544. FLAC__ASSERT(0 != decoder->protected_);
  87545. FLAC__ASSERT(0 != decoder->private_);
  87546. FLAC__ASSERT(0 != decoder->private_->input);
  87547. (void)FLAC__stream_decoder_finish(decoder);
  87548. if(0 != decoder->private_->metadata_filter_ids)
  87549. free(decoder->private_->metadata_filter_ids);
  87550. FLAC__bitreader_delete(decoder->private_->input);
  87551. for(i = 0; i < FLAC__MAX_CHANNELS; i++)
  87552. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&decoder->private_->partitioned_rice_contents[i]);
  87553. free(decoder->private_);
  87554. free(decoder->protected_);
  87555. free(decoder);
  87556. }
  87557. static FLAC__StreamDecoderInitStatus init_stream_internal_dec(
  87558. FLAC__StreamDecoder *decoder,
  87559. FLAC__StreamDecoderReadCallback read_callback,
  87560. FLAC__StreamDecoderSeekCallback seek_callback,
  87561. FLAC__StreamDecoderTellCallback tell_callback,
  87562. FLAC__StreamDecoderLengthCallback length_callback,
  87563. FLAC__StreamDecoderEofCallback eof_callback,
  87564. FLAC__StreamDecoderWriteCallback write_callback,
  87565. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87566. FLAC__StreamDecoderErrorCallback error_callback,
  87567. void *client_data,
  87568. FLAC__bool is_ogg
  87569. )
  87570. {
  87571. FLAC__ASSERT(0 != decoder);
  87572. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87573. return FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED;
  87574. #if !FLAC__HAS_OGG
  87575. if(is_ogg)
  87576. return FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER;
  87577. #endif
  87578. if(
  87579. 0 == read_callback ||
  87580. 0 == write_callback ||
  87581. 0 == error_callback ||
  87582. (seek_callback && (0 == tell_callback || 0 == length_callback || 0 == eof_callback))
  87583. )
  87584. return FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS;
  87585. #if FLAC__HAS_OGG
  87586. decoder->private_->is_ogg = is_ogg;
  87587. if(is_ogg && !FLAC__ogg_decoder_aspect_init(&decoder->protected_->ogg_decoder_aspect))
  87588. return decoder->protected_->state = FLAC__STREAM_DECODER_OGG_ERROR;
  87589. #endif
  87590. FLAC__cpu_info(&decoder->private_->cpuinfo);
  87591. decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal;
  87592. decoder->private_->local_lpc_restore_signal_64bit = FLAC__lpc_restore_signal_wide;
  87593. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal;
  87594. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal;
  87595. decoder->private_->local_bitreader_read_rice_signed_block = FLAC__bitreader_read_rice_signed_block;
  87596. #ifndef FLAC__NO_ASM
  87597. if(decoder->private_->cpuinfo.use_asm) {
  87598. #ifdef FLAC__CPU_IA32
  87599. FLAC__ASSERT(decoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_IA32);
  87600. #ifdef FLAC__HAS_NASM
  87601. #if 1 /*@@@@@@ OPT: not clearly faster, needs more testing */
  87602. if(decoder->private_->cpuinfo.data.ia32.bswap)
  87603. decoder->private_->local_bitreader_read_rice_signed_block = FLAC__bitreader_read_rice_signed_block_asm_ia32_bswap;
  87604. #endif
  87605. if(decoder->private_->cpuinfo.data.ia32.mmx) {
  87606. decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal_asm_ia32;
  87607. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ia32_mmx;
  87608. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ia32_mmx;
  87609. }
  87610. else {
  87611. decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal_asm_ia32;
  87612. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ia32;
  87613. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ia32;
  87614. }
  87615. #endif
  87616. #elif defined FLAC__CPU_PPC
  87617. FLAC__ASSERT(decoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_PPC);
  87618. if(decoder->private_->cpuinfo.data.ppc.altivec) {
  87619. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ppc_altivec_16;
  87620. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ppc_altivec_16_order8;
  87621. }
  87622. #endif
  87623. }
  87624. #endif
  87625. if(!FLAC__bitreader_init(decoder->private_->input, decoder->private_->cpuinfo, read_callback_, decoder)) {
  87626. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87627. return FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR;
  87628. }
  87629. decoder->private_->read_callback = read_callback;
  87630. decoder->private_->seek_callback = seek_callback;
  87631. decoder->private_->tell_callback = tell_callback;
  87632. decoder->private_->length_callback = length_callback;
  87633. decoder->private_->eof_callback = eof_callback;
  87634. decoder->private_->write_callback = write_callback;
  87635. decoder->private_->metadata_callback = metadata_callback;
  87636. decoder->private_->error_callback = error_callback;
  87637. decoder->private_->client_data = client_data;
  87638. decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size = 0;
  87639. decoder->private_->samples_decoded = 0;
  87640. decoder->private_->has_stream_info = false;
  87641. decoder->private_->cached = false;
  87642. decoder->private_->do_md5_checking = decoder->protected_->md5_checking;
  87643. decoder->private_->is_seeking = false;
  87644. decoder->private_->internal_reset_hack = true; /* so the following reset does not try to rewind the input */
  87645. if(!FLAC__stream_decoder_reset(decoder)) {
  87646. return FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR;
  87647. }
  87648. return FLAC__STREAM_DECODER_INIT_STATUS_OK;
  87649. }
  87650. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_stream(
  87651. FLAC__StreamDecoder *decoder,
  87652. FLAC__StreamDecoderReadCallback read_callback,
  87653. FLAC__StreamDecoderSeekCallback seek_callback,
  87654. FLAC__StreamDecoderTellCallback tell_callback,
  87655. FLAC__StreamDecoderLengthCallback length_callback,
  87656. FLAC__StreamDecoderEofCallback eof_callback,
  87657. FLAC__StreamDecoderWriteCallback write_callback,
  87658. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87659. FLAC__StreamDecoderErrorCallback error_callback,
  87660. void *client_data
  87661. )
  87662. {
  87663. return init_stream_internal_dec(
  87664. decoder,
  87665. read_callback,
  87666. seek_callback,
  87667. tell_callback,
  87668. length_callback,
  87669. eof_callback,
  87670. write_callback,
  87671. metadata_callback,
  87672. error_callback,
  87673. client_data,
  87674. false
  87675. );
  87676. }
  87677. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_stream(
  87678. FLAC__StreamDecoder *decoder,
  87679. FLAC__StreamDecoderReadCallback read_callback,
  87680. FLAC__StreamDecoderSeekCallback seek_callback,
  87681. FLAC__StreamDecoderTellCallback tell_callback,
  87682. FLAC__StreamDecoderLengthCallback length_callback,
  87683. FLAC__StreamDecoderEofCallback eof_callback,
  87684. FLAC__StreamDecoderWriteCallback write_callback,
  87685. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87686. FLAC__StreamDecoderErrorCallback error_callback,
  87687. void *client_data
  87688. )
  87689. {
  87690. return init_stream_internal_dec(
  87691. decoder,
  87692. read_callback,
  87693. seek_callback,
  87694. tell_callback,
  87695. length_callback,
  87696. eof_callback,
  87697. write_callback,
  87698. metadata_callback,
  87699. error_callback,
  87700. client_data,
  87701. true
  87702. );
  87703. }
  87704. static FLAC__StreamDecoderInitStatus init_FILE_internal_(
  87705. FLAC__StreamDecoder *decoder,
  87706. FILE *file,
  87707. FLAC__StreamDecoderWriteCallback write_callback,
  87708. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87709. FLAC__StreamDecoderErrorCallback error_callback,
  87710. void *client_data,
  87711. FLAC__bool is_ogg
  87712. )
  87713. {
  87714. FLAC__ASSERT(0 != decoder);
  87715. FLAC__ASSERT(0 != file);
  87716. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87717. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED);
  87718. if(0 == write_callback || 0 == error_callback)
  87719. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS);
  87720. if(file == stdin)
  87721. file = get_binary_stdin_(); /* just to be safe */
  87722. decoder->private_->file = file;
  87723. return init_stream_internal_dec(
  87724. decoder,
  87725. file_read_callback_dec,
  87726. decoder->private_->file == stdin? 0: file_seek_callback_dec,
  87727. decoder->private_->file == stdin? 0: file_tell_callback_dec,
  87728. decoder->private_->file == stdin? 0: file_length_callback_,
  87729. file_eof_callback_,
  87730. write_callback,
  87731. metadata_callback,
  87732. error_callback,
  87733. client_data,
  87734. is_ogg
  87735. );
  87736. }
  87737. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_FILE(
  87738. FLAC__StreamDecoder *decoder,
  87739. FILE *file,
  87740. FLAC__StreamDecoderWriteCallback write_callback,
  87741. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87742. FLAC__StreamDecoderErrorCallback error_callback,
  87743. void *client_data
  87744. )
  87745. {
  87746. return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/false);
  87747. }
  87748. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_FILE(
  87749. FLAC__StreamDecoder *decoder,
  87750. FILE *file,
  87751. FLAC__StreamDecoderWriteCallback write_callback,
  87752. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87753. FLAC__StreamDecoderErrorCallback error_callback,
  87754. void *client_data
  87755. )
  87756. {
  87757. return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/true);
  87758. }
  87759. static FLAC__StreamDecoderInitStatus init_file_internal_(
  87760. FLAC__StreamDecoder *decoder,
  87761. const char *filename,
  87762. FLAC__StreamDecoderWriteCallback write_callback,
  87763. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87764. FLAC__StreamDecoderErrorCallback error_callback,
  87765. void *client_data,
  87766. FLAC__bool is_ogg
  87767. )
  87768. {
  87769. FILE *file;
  87770. FLAC__ASSERT(0 != decoder);
  87771. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87772. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED);
  87773. if(0 == write_callback || 0 == error_callback)
  87774. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS);
  87775. file = filename? fopen(filename, "rb") : stdin;
  87776. if(0 == file)
  87777. return FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE;
  87778. return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, is_ogg);
  87779. }
  87780. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_file(
  87781. FLAC__StreamDecoder *decoder,
  87782. const char *filename,
  87783. FLAC__StreamDecoderWriteCallback write_callback,
  87784. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87785. FLAC__StreamDecoderErrorCallback error_callback,
  87786. void *client_data
  87787. )
  87788. {
  87789. return init_file_internal_(decoder, filename, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/false);
  87790. }
  87791. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_file(
  87792. FLAC__StreamDecoder *decoder,
  87793. const char *filename,
  87794. FLAC__StreamDecoderWriteCallback write_callback,
  87795. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87796. FLAC__StreamDecoderErrorCallback error_callback,
  87797. void *client_data
  87798. )
  87799. {
  87800. return init_file_internal_(decoder, filename, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/true);
  87801. }
  87802. FLAC_API FLAC__bool FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder)
  87803. {
  87804. FLAC__bool md5_failed = false;
  87805. unsigned i;
  87806. FLAC__ASSERT(0 != decoder);
  87807. FLAC__ASSERT(0 != decoder->private_);
  87808. FLAC__ASSERT(0 != decoder->protected_);
  87809. if(decoder->protected_->state == FLAC__STREAM_DECODER_UNINITIALIZED)
  87810. return true;
  87811. FLAC__MD5Final(decoder->private_->computed_md5sum, &decoder->private_->md5context);
  87812. if(decoder->private_->has_seek_table && 0 != decoder->private_->seek_table.data.seek_table.points) {
  87813. free(decoder->private_->seek_table.data.seek_table.points);
  87814. decoder->private_->seek_table.data.seek_table.points = 0;
  87815. decoder->private_->has_seek_table = false;
  87816. }
  87817. FLAC__bitreader_free(decoder->private_->input);
  87818. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  87819. if(0 != decoder->private_->output[i]) {
  87820. free(decoder->private_->output[i]-4);
  87821. decoder->private_->output[i] = 0;
  87822. }
  87823. if(0 != decoder->private_->residual_unaligned[i]) {
  87824. free(decoder->private_->residual_unaligned[i]);
  87825. decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0;
  87826. }
  87827. }
  87828. decoder->private_->output_capacity = 0;
  87829. decoder->private_->output_channels = 0;
  87830. #if FLAC__HAS_OGG
  87831. if(decoder->private_->is_ogg)
  87832. FLAC__ogg_decoder_aspect_finish(&decoder->protected_->ogg_decoder_aspect);
  87833. #endif
  87834. if(0 != decoder->private_->file) {
  87835. if(decoder->private_->file != stdin)
  87836. fclose(decoder->private_->file);
  87837. decoder->private_->file = 0;
  87838. }
  87839. if(decoder->private_->do_md5_checking) {
  87840. if(memcmp(decoder->private_->stream_info.data.stream_info.md5sum, decoder->private_->computed_md5sum, 16))
  87841. md5_failed = true;
  87842. }
  87843. decoder->private_->is_seeking = false;
  87844. set_defaults_dec(decoder);
  87845. decoder->protected_->state = FLAC__STREAM_DECODER_UNINITIALIZED;
  87846. return !md5_failed;
  87847. }
  87848. FLAC_API FLAC__bool FLAC__stream_decoder_set_ogg_serial_number(FLAC__StreamDecoder *decoder, long value)
  87849. {
  87850. FLAC__ASSERT(0 != decoder);
  87851. FLAC__ASSERT(0 != decoder->private_);
  87852. FLAC__ASSERT(0 != decoder->protected_);
  87853. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87854. return false;
  87855. #if FLAC__HAS_OGG
  87856. FLAC__ogg_decoder_aspect_set_serial_number(&decoder->protected_->ogg_decoder_aspect, value);
  87857. return true;
  87858. #else
  87859. (void)value;
  87860. return false;
  87861. #endif
  87862. }
  87863. FLAC_API FLAC__bool FLAC__stream_decoder_set_md5_checking(FLAC__StreamDecoder *decoder, FLAC__bool value)
  87864. {
  87865. FLAC__ASSERT(0 != decoder);
  87866. FLAC__ASSERT(0 != decoder->protected_);
  87867. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87868. return false;
  87869. decoder->protected_->md5_checking = value;
  87870. return true;
  87871. }
  87872. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond(FLAC__StreamDecoder *decoder, FLAC__MetadataType type)
  87873. {
  87874. FLAC__ASSERT(0 != decoder);
  87875. FLAC__ASSERT(0 != decoder->private_);
  87876. FLAC__ASSERT(0 != decoder->protected_);
  87877. FLAC__ASSERT((unsigned)type <= FLAC__MAX_METADATA_TYPE_CODE);
  87878. if((unsigned)type > FLAC__MAX_METADATA_TYPE_CODE)
  87879. return false;
  87880. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87881. return false;
  87882. decoder->private_->metadata_filter[type] = true;
  87883. if(type == FLAC__METADATA_TYPE_APPLICATION)
  87884. decoder->private_->metadata_filter_ids_count = 0;
  87885. return true;
  87886. }
  87887. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4])
  87888. {
  87889. FLAC__ASSERT(0 != decoder);
  87890. FLAC__ASSERT(0 != decoder->private_);
  87891. FLAC__ASSERT(0 != decoder->protected_);
  87892. FLAC__ASSERT(0 != id);
  87893. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87894. return false;
  87895. if(decoder->private_->metadata_filter[FLAC__METADATA_TYPE_APPLICATION])
  87896. return true;
  87897. FLAC__ASSERT(0 != decoder->private_->metadata_filter_ids);
  87898. if(decoder->private_->metadata_filter_ids_count == decoder->private_->metadata_filter_ids_capacity) {
  87899. 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))) {
  87900. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87901. return false;
  87902. }
  87903. decoder->private_->metadata_filter_ids_capacity *= 2;
  87904. }
  87905. 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));
  87906. decoder->private_->metadata_filter_ids_count++;
  87907. return true;
  87908. }
  87909. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_all(FLAC__StreamDecoder *decoder)
  87910. {
  87911. unsigned i;
  87912. FLAC__ASSERT(0 != decoder);
  87913. FLAC__ASSERT(0 != decoder->private_);
  87914. FLAC__ASSERT(0 != decoder->protected_);
  87915. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87916. return false;
  87917. for(i = 0; i < sizeof(decoder->private_->metadata_filter) / sizeof(decoder->private_->metadata_filter[0]); i++)
  87918. decoder->private_->metadata_filter[i] = true;
  87919. decoder->private_->metadata_filter_ids_count = 0;
  87920. return true;
  87921. }
  87922. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore(FLAC__StreamDecoder *decoder, FLAC__MetadataType type)
  87923. {
  87924. FLAC__ASSERT(0 != decoder);
  87925. FLAC__ASSERT(0 != decoder->private_);
  87926. FLAC__ASSERT(0 != decoder->protected_);
  87927. FLAC__ASSERT((unsigned)type <= FLAC__MAX_METADATA_TYPE_CODE);
  87928. if((unsigned)type > FLAC__MAX_METADATA_TYPE_CODE)
  87929. return false;
  87930. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87931. return false;
  87932. decoder->private_->metadata_filter[type] = false;
  87933. if(type == FLAC__METADATA_TYPE_APPLICATION)
  87934. decoder->private_->metadata_filter_ids_count = 0;
  87935. return true;
  87936. }
  87937. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4])
  87938. {
  87939. FLAC__ASSERT(0 != decoder);
  87940. FLAC__ASSERT(0 != decoder->private_);
  87941. FLAC__ASSERT(0 != decoder->protected_);
  87942. FLAC__ASSERT(0 != id);
  87943. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87944. return false;
  87945. if(!decoder->private_->metadata_filter[FLAC__METADATA_TYPE_APPLICATION])
  87946. return true;
  87947. FLAC__ASSERT(0 != decoder->private_->metadata_filter_ids);
  87948. if(decoder->private_->metadata_filter_ids_count == decoder->private_->metadata_filter_ids_capacity) {
  87949. 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))) {
  87950. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87951. return false;
  87952. }
  87953. decoder->private_->metadata_filter_ids_capacity *= 2;
  87954. }
  87955. 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));
  87956. decoder->private_->metadata_filter_ids_count++;
  87957. return true;
  87958. }
  87959. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_all(FLAC__StreamDecoder *decoder)
  87960. {
  87961. FLAC__ASSERT(0 != decoder);
  87962. FLAC__ASSERT(0 != decoder->private_);
  87963. FLAC__ASSERT(0 != decoder->protected_);
  87964. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87965. return false;
  87966. memset(decoder->private_->metadata_filter, 0, sizeof(decoder->private_->metadata_filter));
  87967. decoder->private_->metadata_filter_ids_count = 0;
  87968. return true;
  87969. }
  87970. FLAC_API FLAC__StreamDecoderState FLAC__stream_decoder_get_state(const FLAC__StreamDecoder *decoder)
  87971. {
  87972. FLAC__ASSERT(0 != decoder);
  87973. FLAC__ASSERT(0 != decoder->protected_);
  87974. return decoder->protected_->state;
  87975. }
  87976. FLAC_API const char *FLAC__stream_decoder_get_resolved_state_string(const FLAC__StreamDecoder *decoder)
  87977. {
  87978. return FLAC__StreamDecoderStateString[decoder->protected_->state];
  87979. }
  87980. FLAC_API FLAC__bool FLAC__stream_decoder_get_md5_checking(const FLAC__StreamDecoder *decoder)
  87981. {
  87982. FLAC__ASSERT(0 != decoder);
  87983. FLAC__ASSERT(0 != decoder->protected_);
  87984. return decoder->protected_->md5_checking;
  87985. }
  87986. FLAC_API FLAC__uint64 FLAC__stream_decoder_get_total_samples(const FLAC__StreamDecoder *decoder)
  87987. {
  87988. FLAC__ASSERT(0 != decoder);
  87989. FLAC__ASSERT(0 != decoder->protected_);
  87990. return decoder->private_->has_stream_info? decoder->private_->stream_info.data.stream_info.total_samples : 0;
  87991. }
  87992. FLAC_API unsigned FLAC__stream_decoder_get_channels(const FLAC__StreamDecoder *decoder)
  87993. {
  87994. FLAC__ASSERT(0 != decoder);
  87995. FLAC__ASSERT(0 != decoder->protected_);
  87996. return decoder->protected_->channels;
  87997. }
  87998. FLAC_API FLAC__ChannelAssignment FLAC__stream_decoder_get_channel_assignment(const FLAC__StreamDecoder *decoder)
  87999. {
  88000. FLAC__ASSERT(0 != decoder);
  88001. FLAC__ASSERT(0 != decoder->protected_);
  88002. return decoder->protected_->channel_assignment;
  88003. }
  88004. FLAC_API unsigned FLAC__stream_decoder_get_bits_per_sample(const FLAC__StreamDecoder *decoder)
  88005. {
  88006. FLAC__ASSERT(0 != decoder);
  88007. FLAC__ASSERT(0 != decoder->protected_);
  88008. return decoder->protected_->bits_per_sample;
  88009. }
  88010. FLAC_API unsigned FLAC__stream_decoder_get_sample_rate(const FLAC__StreamDecoder *decoder)
  88011. {
  88012. FLAC__ASSERT(0 != decoder);
  88013. FLAC__ASSERT(0 != decoder->protected_);
  88014. return decoder->protected_->sample_rate;
  88015. }
  88016. FLAC_API unsigned FLAC__stream_decoder_get_blocksize(const FLAC__StreamDecoder *decoder)
  88017. {
  88018. FLAC__ASSERT(0 != decoder);
  88019. FLAC__ASSERT(0 != decoder->protected_);
  88020. return decoder->protected_->blocksize;
  88021. }
  88022. FLAC_API FLAC__bool FLAC__stream_decoder_get_decode_position(const FLAC__StreamDecoder *decoder, FLAC__uint64 *position)
  88023. {
  88024. FLAC__ASSERT(0 != decoder);
  88025. FLAC__ASSERT(0 != decoder->private_);
  88026. FLAC__ASSERT(0 != position);
  88027. #if FLAC__HAS_OGG
  88028. if(decoder->private_->is_ogg)
  88029. return false;
  88030. #endif
  88031. if(0 == decoder->private_->tell_callback)
  88032. return false;
  88033. if(decoder->private_->tell_callback(decoder, position, decoder->private_->client_data) != FLAC__STREAM_DECODER_TELL_STATUS_OK)
  88034. return false;
  88035. if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input))
  88036. return false;
  88037. FLAC__ASSERT(*position >= FLAC__stream_decoder_get_input_bytes_unconsumed(decoder));
  88038. *position -= FLAC__stream_decoder_get_input_bytes_unconsumed(decoder);
  88039. return true;
  88040. }
  88041. FLAC_API FLAC__bool FLAC__stream_decoder_flush(FLAC__StreamDecoder *decoder)
  88042. {
  88043. FLAC__ASSERT(0 != decoder);
  88044. FLAC__ASSERT(0 != decoder->private_);
  88045. FLAC__ASSERT(0 != decoder->protected_);
  88046. decoder->private_->samples_decoded = 0;
  88047. decoder->private_->do_md5_checking = false;
  88048. #if FLAC__HAS_OGG
  88049. if(decoder->private_->is_ogg)
  88050. FLAC__ogg_decoder_aspect_flush(&decoder->protected_->ogg_decoder_aspect);
  88051. #endif
  88052. if(!FLAC__bitreader_clear(decoder->private_->input)) {
  88053. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88054. return false;
  88055. }
  88056. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88057. return true;
  88058. }
  88059. FLAC_API FLAC__bool FLAC__stream_decoder_reset(FLAC__StreamDecoder *decoder)
  88060. {
  88061. FLAC__ASSERT(0 != decoder);
  88062. FLAC__ASSERT(0 != decoder->private_);
  88063. FLAC__ASSERT(0 != decoder->protected_);
  88064. if(!FLAC__stream_decoder_flush(decoder)) {
  88065. return false;
  88066. }
  88067. #if FLAC__HAS_OGG
  88068. if(decoder->private_->is_ogg)
  88069. FLAC__ogg_decoder_aspect_reset(&decoder->protected_->ogg_decoder_aspect);
  88070. #endif
  88071. if(!decoder->private_->internal_reset_hack) {
  88072. if(decoder->private_->file == stdin)
  88073. return false; /* can't rewind stdin, reset fails */
  88074. if(decoder->private_->seek_callback && decoder->private_->seek_callback(decoder, 0, decoder->private_->client_data) == FLAC__STREAM_DECODER_SEEK_STATUS_ERROR)
  88075. return false; /* seekable and seek fails, reset fails */
  88076. }
  88077. else
  88078. decoder->private_->internal_reset_hack = false;
  88079. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_METADATA;
  88080. decoder->private_->has_stream_info = false;
  88081. if(decoder->private_->has_seek_table && 0 != decoder->private_->seek_table.data.seek_table.points) {
  88082. free(decoder->private_->seek_table.data.seek_table.points);
  88083. decoder->private_->seek_table.data.seek_table.points = 0;
  88084. decoder->private_->has_seek_table = false;
  88085. }
  88086. decoder->private_->do_md5_checking = decoder->protected_->md5_checking;
  88087. decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size = 0;
  88088. FLAC__MD5Init(&decoder->private_->md5context);
  88089. decoder->private_->first_frame_offset = 0;
  88090. decoder->private_->unparseable_frame_count = 0;
  88091. return true;
  88092. }
  88093. FLAC_API FLAC__bool FLAC__stream_decoder_process_single(FLAC__StreamDecoder *decoder)
  88094. {
  88095. FLAC__bool got_a_frame;
  88096. FLAC__ASSERT(0 != decoder);
  88097. FLAC__ASSERT(0 != decoder->protected_);
  88098. while(1) {
  88099. switch(decoder->protected_->state) {
  88100. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  88101. if(!find_metadata_(decoder))
  88102. return false; /* above function sets the status for us */
  88103. break;
  88104. case FLAC__STREAM_DECODER_READ_METADATA:
  88105. if(!read_metadata_(decoder))
  88106. return false; /* above function sets the status for us */
  88107. else
  88108. return true;
  88109. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  88110. if(!frame_sync_(decoder))
  88111. return true; /* above function sets the status for us */
  88112. break;
  88113. case FLAC__STREAM_DECODER_READ_FRAME:
  88114. if(!read_frame_(decoder, &got_a_frame, /*do_full_decode=*/true))
  88115. return false; /* above function sets the status for us */
  88116. if(got_a_frame)
  88117. return true; /* above function sets the status for us */
  88118. break;
  88119. case FLAC__STREAM_DECODER_END_OF_STREAM:
  88120. case FLAC__STREAM_DECODER_ABORTED:
  88121. return true;
  88122. default:
  88123. FLAC__ASSERT(0);
  88124. return false;
  88125. }
  88126. }
  88127. }
  88128. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_metadata(FLAC__StreamDecoder *decoder)
  88129. {
  88130. FLAC__ASSERT(0 != decoder);
  88131. FLAC__ASSERT(0 != decoder->protected_);
  88132. while(1) {
  88133. switch(decoder->protected_->state) {
  88134. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  88135. if(!find_metadata_(decoder))
  88136. return false; /* above function sets the status for us */
  88137. break;
  88138. case FLAC__STREAM_DECODER_READ_METADATA:
  88139. if(!read_metadata_(decoder))
  88140. return false; /* above function sets the status for us */
  88141. break;
  88142. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  88143. case FLAC__STREAM_DECODER_READ_FRAME:
  88144. case FLAC__STREAM_DECODER_END_OF_STREAM:
  88145. case FLAC__STREAM_DECODER_ABORTED:
  88146. return true;
  88147. default:
  88148. FLAC__ASSERT(0);
  88149. return false;
  88150. }
  88151. }
  88152. }
  88153. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_stream(FLAC__StreamDecoder *decoder)
  88154. {
  88155. FLAC__bool dummy;
  88156. FLAC__ASSERT(0 != decoder);
  88157. FLAC__ASSERT(0 != decoder->protected_);
  88158. while(1) {
  88159. switch(decoder->protected_->state) {
  88160. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  88161. if(!find_metadata_(decoder))
  88162. return false; /* above function sets the status for us */
  88163. break;
  88164. case FLAC__STREAM_DECODER_READ_METADATA:
  88165. if(!read_metadata_(decoder))
  88166. return false; /* above function sets the status for us */
  88167. break;
  88168. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  88169. if(!frame_sync_(decoder))
  88170. return true; /* above function sets the status for us */
  88171. break;
  88172. case FLAC__STREAM_DECODER_READ_FRAME:
  88173. if(!read_frame_(decoder, &dummy, /*do_full_decode=*/true))
  88174. return false; /* above function sets the status for us */
  88175. break;
  88176. case FLAC__STREAM_DECODER_END_OF_STREAM:
  88177. case FLAC__STREAM_DECODER_ABORTED:
  88178. return true;
  88179. default:
  88180. FLAC__ASSERT(0);
  88181. return false;
  88182. }
  88183. }
  88184. }
  88185. FLAC_API FLAC__bool FLAC__stream_decoder_skip_single_frame(FLAC__StreamDecoder *decoder)
  88186. {
  88187. FLAC__bool got_a_frame;
  88188. FLAC__ASSERT(0 != decoder);
  88189. FLAC__ASSERT(0 != decoder->protected_);
  88190. while(1) {
  88191. switch(decoder->protected_->state) {
  88192. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  88193. case FLAC__STREAM_DECODER_READ_METADATA:
  88194. return false; /* above function sets the status for us */
  88195. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  88196. if(!frame_sync_(decoder))
  88197. return true; /* above function sets the status for us */
  88198. break;
  88199. case FLAC__STREAM_DECODER_READ_FRAME:
  88200. if(!read_frame_(decoder, &got_a_frame, /*do_full_decode=*/false))
  88201. return false; /* above function sets the status for us */
  88202. if(got_a_frame)
  88203. return true; /* above function sets the status for us */
  88204. break;
  88205. case FLAC__STREAM_DECODER_END_OF_STREAM:
  88206. case FLAC__STREAM_DECODER_ABORTED:
  88207. return true;
  88208. default:
  88209. FLAC__ASSERT(0);
  88210. return false;
  88211. }
  88212. }
  88213. }
  88214. FLAC_API FLAC__bool FLAC__stream_decoder_seek_absolute(FLAC__StreamDecoder *decoder, FLAC__uint64 sample)
  88215. {
  88216. FLAC__uint64 length;
  88217. FLAC__ASSERT(0 != decoder);
  88218. if(
  88219. decoder->protected_->state != FLAC__STREAM_DECODER_SEARCH_FOR_METADATA &&
  88220. decoder->protected_->state != FLAC__STREAM_DECODER_READ_METADATA &&
  88221. decoder->protected_->state != FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC &&
  88222. decoder->protected_->state != FLAC__STREAM_DECODER_READ_FRAME &&
  88223. decoder->protected_->state != FLAC__STREAM_DECODER_END_OF_STREAM
  88224. )
  88225. return false;
  88226. if(0 == decoder->private_->seek_callback)
  88227. return false;
  88228. FLAC__ASSERT(decoder->private_->seek_callback);
  88229. FLAC__ASSERT(decoder->private_->tell_callback);
  88230. FLAC__ASSERT(decoder->private_->length_callback);
  88231. FLAC__ASSERT(decoder->private_->eof_callback);
  88232. if(FLAC__stream_decoder_get_total_samples(decoder) > 0 && sample >= FLAC__stream_decoder_get_total_samples(decoder))
  88233. return false;
  88234. decoder->private_->is_seeking = true;
  88235. decoder->private_->do_md5_checking = false;
  88236. if(decoder->private_->length_callback(decoder, &length, decoder->private_->client_data) != FLAC__STREAM_DECODER_LENGTH_STATUS_OK) {
  88237. decoder->private_->is_seeking = false;
  88238. return false;
  88239. }
  88240. if(
  88241. decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_METADATA ||
  88242. decoder->protected_->state == FLAC__STREAM_DECODER_READ_METADATA
  88243. ) {
  88244. if(!FLAC__stream_decoder_process_until_end_of_metadata(decoder)) {
  88245. decoder->private_->is_seeking = false;
  88246. return false;
  88247. }
  88248. if(FLAC__stream_decoder_get_total_samples(decoder) > 0 && sample >= FLAC__stream_decoder_get_total_samples(decoder)) {
  88249. decoder->private_->is_seeking = false;
  88250. return false;
  88251. }
  88252. }
  88253. {
  88254. const FLAC__bool ok =
  88255. #if FLAC__HAS_OGG
  88256. decoder->private_->is_ogg?
  88257. seek_to_absolute_sample_ogg_(decoder, length, sample) :
  88258. #endif
  88259. seek_to_absolute_sample_(decoder, length, sample)
  88260. ;
  88261. decoder->private_->is_seeking = false;
  88262. return ok;
  88263. }
  88264. }
  88265. unsigned FLAC__stream_decoder_get_input_bytes_unconsumed(const FLAC__StreamDecoder *decoder)
  88266. {
  88267. FLAC__ASSERT(0 != decoder);
  88268. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88269. FLAC__ASSERT(!(FLAC__bitreader_get_input_bits_unconsumed(decoder->private_->input) & 7));
  88270. return FLAC__bitreader_get_input_bits_unconsumed(decoder->private_->input) / 8;
  88271. }
  88272. void set_defaults_dec(FLAC__StreamDecoder *decoder)
  88273. {
  88274. #if FLAC__HAS_OGG
  88275. decoder->private_->is_ogg = false;
  88276. #endif
  88277. decoder->private_->read_callback = 0;
  88278. decoder->private_->seek_callback = 0;
  88279. decoder->private_->tell_callback = 0;
  88280. decoder->private_->length_callback = 0;
  88281. decoder->private_->eof_callback = 0;
  88282. decoder->private_->write_callback = 0;
  88283. decoder->private_->metadata_callback = 0;
  88284. decoder->private_->error_callback = 0;
  88285. decoder->private_->client_data = 0;
  88286. memset(decoder->private_->metadata_filter, 0, sizeof(decoder->private_->metadata_filter));
  88287. decoder->private_->metadata_filter[FLAC__METADATA_TYPE_STREAMINFO] = true;
  88288. decoder->private_->metadata_filter_ids_count = 0;
  88289. decoder->protected_->md5_checking = false;
  88290. #if FLAC__HAS_OGG
  88291. FLAC__ogg_decoder_aspect_set_defaults(&decoder->protected_->ogg_decoder_aspect);
  88292. #endif
  88293. }
  88294. FILE *get_binary_stdin_(void)
  88295. {
  88296. #if defined _MSC_VER || defined __MINGW32__
  88297. _setmode(_fileno(stdin), _O_BINARY);
  88298. #elif defined __CYGWIN__
  88299. setmode(_fileno(stdin), _O_BINARY);
  88300. #elif defined __EMX__
  88301. setmode(fileno(stdin), O_BINARY);
  88302. #endif
  88303. return stdin;
  88304. }
  88305. FLAC__bool allocate_output_(FLAC__StreamDecoder *decoder, unsigned size, unsigned channels)
  88306. {
  88307. unsigned i;
  88308. FLAC__int32 *tmp;
  88309. if(size <= decoder->private_->output_capacity && channels <= decoder->private_->output_channels)
  88310. return true;
  88311. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  88312. if(0 != decoder->private_->output[i]) {
  88313. free(decoder->private_->output[i]-4);
  88314. decoder->private_->output[i] = 0;
  88315. }
  88316. if(0 != decoder->private_->residual_unaligned[i]) {
  88317. free(decoder->private_->residual_unaligned[i]);
  88318. decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0;
  88319. }
  88320. }
  88321. for(i = 0; i < channels; i++) {
  88322. tmp = (FLAC__int32*)safe_malloc_muladd2_(sizeof(FLAC__int32), /*times (*/size, /*+*/4/*)*/);
  88323. if(tmp == 0) {
  88324. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88325. return false;
  88326. }
  88327. memset(tmp, 0, sizeof(FLAC__int32)*4);
  88328. decoder->private_->output[i] = tmp + 4;
  88329. if(!FLAC__memory_alloc_aligned_int32_array(size, &decoder->private_->residual_unaligned[i], &decoder->private_->residual[i])) {
  88330. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88331. return false;
  88332. }
  88333. }
  88334. decoder->private_->output_capacity = size;
  88335. decoder->private_->output_channels = channels;
  88336. return true;
  88337. }
  88338. FLAC__bool has_id_filtered_(FLAC__StreamDecoder *decoder, FLAC__byte *id)
  88339. {
  88340. size_t i;
  88341. FLAC__ASSERT(0 != decoder);
  88342. FLAC__ASSERT(0 != decoder->private_);
  88343. for(i = 0; i < decoder->private_->metadata_filter_ids_count; i++)
  88344. if(0 == memcmp(decoder->private_->metadata_filter_ids + i * (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8), id, (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8)))
  88345. return true;
  88346. return false;
  88347. }
  88348. FLAC__bool find_metadata_(FLAC__StreamDecoder *decoder)
  88349. {
  88350. FLAC__uint32 x;
  88351. unsigned i, id_;
  88352. FLAC__bool first = true;
  88353. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88354. for(i = id_ = 0; i < 4; ) {
  88355. if(decoder->private_->cached) {
  88356. x = (FLAC__uint32)decoder->private_->lookahead;
  88357. decoder->private_->cached = false;
  88358. }
  88359. else {
  88360. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88361. return false; /* read_callback_ sets the state for us */
  88362. }
  88363. if(x == FLAC__STREAM_SYNC_STRING[i]) {
  88364. first = true;
  88365. i++;
  88366. id_ = 0;
  88367. continue;
  88368. }
  88369. if(x == ID3V2_TAG_[id_]) {
  88370. id_++;
  88371. i = 0;
  88372. if(id_ == 3) {
  88373. if(!skip_id3v2_tag_(decoder))
  88374. return false; /* skip_id3v2_tag_ sets the state for us */
  88375. }
  88376. continue;
  88377. }
  88378. id_ = 0;
  88379. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88380. decoder->private_->header_warmup[0] = (FLAC__byte)x;
  88381. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88382. return false; /* read_callback_ sets the state for us */
  88383. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88384. decoder->private_->lookahead = (FLAC__byte)x;
  88385. decoder->private_->cached = true;
  88386. }
  88387. else if(x >> 2 == 0x3e) { /* MAGIC NUMBER for the last 6 sync bits */
  88388. decoder->private_->header_warmup[1] = (FLAC__byte)x;
  88389. decoder->protected_->state = FLAC__STREAM_DECODER_READ_FRAME;
  88390. return true;
  88391. }
  88392. }
  88393. i = 0;
  88394. if(first) {
  88395. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88396. first = false;
  88397. }
  88398. }
  88399. decoder->protected_->state = FLAC__STREAM_DECODER_READ_METADATA;
  88400. return true;
  88401. }
  88402. FLAC__bool read_metadata_(FLAC__StreamDecoder *decoder)
  88403. {
  88404. FLAC__bool is_last;
  88405. FLAC__uint32 i, x, type, length;
  88406. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88407. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_IS_LAST_LEN))
  88408. return false; /* read_callback_ sets the state for us */
  88409. is_last = x? true : false;
  88410. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &type, FLAC__STREAM_METADATA_TYPE_LEN))
  88411. return false; /* read_callback_ sets the state for us */
  88412. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &length, FLAC__STREAM_METADATA_LENGTH_LEN))
  88413. return false; /* read_callback_ sets the state for us */
  88414. if(type == FLAC__METADATA_TYPE_STREAMINFO) {
  88415. if(!read_metadata_streaminfo_(decoder, is_last, length))
  88416. return false;
  88417. decoder->private_->has_stream_info = true;
  88418. 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))
  88419. decoder->private_->do_md5_checking = false;
  88420. if(!decoder->private_->is_seeking && decoder->private_->metadata_filter[FLAC__METADATA_TYPE_STREAMINFO] && decoder->private_->metadata_callback)
  88421. decoder->private_->metadata_callback(decoder, &decoder->private_->stream_info, decoder->private_->client_data);
  88422. }
  88423. else if(type == FLAC__METADATA_TYPE_SEEKTABLE) {
  88424. if(!read_metadata_seektable_(decoder, is_last, length))
  88425. return false;
  88426. decoder->private_->has_seek_table = true;
  88427. if(!decoder->private_->is_seeking && decoder->private_->metadata_filter[FLAC__METADATA_TYPE_SEEKTABLE] && decoder->private_->metadata_callback)
  88428. decoder->private_->metadata_callback(decoder, &decoder->private_->seek_table, decoder->private_->client_data);
  88429. }
  88430. else {
  88431. FLAC__bool skip_it = !decoder->private_->metadata_filter[type];
  88432. unsigned real_length = length;
  88433. FLAC__StreamMetadata block;
  88434. block.is_last = is_last;
  88435. block.type = (FLAC__MetadataType)type;
  88436. block.length = length;
  88437. if(type == FLAC__METADATA_TYPE_APPLICATION) {
  88438. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.application.id, FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8))
  88439. return false; /* read_callback_ sets the state for us */
  88440. if(real_length < FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8) { /* underflow check */
  88441. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;/*@@@@@@ maybe wrong error? need to resync?*/
  88442. return false;
  88443. }
  88444. real_length -= FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8;
  88445. if(decoder->private_->metadata_filter_ids_count > 0 && has_id_filtered_(decoder, block.data.application.id))
  88446. skip_it = !skip_it;
  88447. }
  88448. if(skip_it) {
  88449. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, real_length))
  88450. return false; /* read_callback_ sets the state for us */
  88451. }
  88452. else {
  88453. switch(type) {
  88454. case FLAC__METADATA_TYPE_PADDING:
  88455. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, real_length))
  88456. return false; /* read_callback_ sets the state for us */
  88457. break;
  88458. case FLAC__METADATA_TYPE_APPLICATION:
  88459. if(real_length > 0) {
  88460. if(0 == (block.data.application.data = (FLAC__byte*)malloc(real_length))) {
  88461. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88462. return false;
  88463. }
  88464. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.application.data, real_length))
  88465. return false; /* read_callback_ sets the state for us */
  88466. }
  88467. else
  88468. block.data.application.data = 0;
  88469. break;
  88470. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  88471. if(!read_metadata_vorbiscomment_(decoder, &block.data.vorbis_comment))
  88472. return false;
  88473. break;
  88474. case FLAC__METADATA_TYPE_CUESHEET:
  88475. if(!read_metadata_cuesheet_(decoder, &block.data.cue_sheet))
  88476. return false;
  88477. break;
  88478. case FLAC__METADATA_TYPE_PICTURE:
  88479. if(!read_metadata_picture_(decoder, &block.data.picture))
  88480. return false;
  88481. break;
  88482. case FLAC__METADATA_TYPE_STREAMINFO:
  88483. case FLAC__METADATA_TYPE_SEEKTABLE:
  88484. FLAC__ASSERT(0);
  88485. break;
  88486. default:
  88487. if(real_length > 0) {
  88488. if(0 == (block.data.unknown.data = (FLAC__byte*)malloc(real_length))) {
  88489. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88490. return false;
  88491. }
  88492. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.unknown.data, real_length))
  88493. return false; /* read_callback_ sets the state for us */
  88494. }
  88495. else
  88496. block.data.unknown.data = 0;
  88497. break;
  88498. }
  88499. if(!decoder->private_->is_seeking && decoder->private_->metadata_callback)
  88500. decoder->private_->metadata_callback(decoder, &block, decoder->private_->client_data);
  88501. switch(type) {
  88502. case FLAC__METADATA_TYPE_PADDING:
  88503. break;
  88504. case FLAC__METADATA_TYPE_APPLICATION:
  88505. if(0 != block.data.application.data)
  88506. free(block.data.application.data);
  88507. break;
  88508. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  88509. if(0 != block.data.vorbis_comment.vendor_string.entry)
  88510. free(block.data.vorbis_comment.vendor_string.entry);
  88511. if(block.data.vorbis_comment.num_comments > 0)
  88512. for(i = 0; i < block.data.vorbis_comment.num_comments; i++)
  88513. if(0 != block.data.vorbis_comment.comments[i].entry)
  88514. free(block.data.vorbis_comment.comments[i].entry);
  88515. if(0 != block.data.vorbis_comment.comments)
  88516. free(block.data.vorbis_comment.comments);
  88517. break;
  88518. case FLAC__METADATA_TYPE_CUESHEET:
  88519. if(block.data.cue_sheet.num_tracks > 0)
  88520. for(i = 0; i < block.data.cue_sheet.num_tracks; i++)
  88521. if(0 != block.data.cue_sheet.tracks[i].indices)
  88522. free(block.data.cue_sheet.tracks[i].indices);
  88523. if(0 != block.data.cue_sheet.tracks)
  88524. free(block.data.cue_sheet.tracks);
  88525. break;
  88526. case FLAC__METADATA_TYPE_PICTURE:
  88527. if(0 != block.data.picture.mime_type)
  88528. free(block.data.picture.mime_type);
  88529. if(0 != block.data.picture.description)
  88530. free(block.data.picture.description);
  88531. if(0 != block.data.picture.data)
  88532. free(block.data.picture.data);
  88533. break;
  88534. case FLAC__METADATA_TYPE_STREAMINFO:
  88535. case FLAC__METADATA_TYPE_SEEKTABLE:
  88536. FLAC__ASSERT(0);
  88537. default:
  88538. if(0 != block.data.unknown.data)
  88539. free(block.data.unknown.data);
  88540. break;
  88541. }
  88542. }
  88543. }
  88544. if(is_last) {
  88545. if(!FLAC__stream_decoder_get_decode_position(decoder, &decoder->private_->first_frame_offset))
  88546. decoder->private_->first_frame_offset = 0;
  88547. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88548. }
  88549. return true;
  88550. }
  88551. FLAC__bool read_metadata_streaminfo_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length)
  88552. {
  88553. FLAC__uint32 x;
  88554. unsigned bits, used_bits = 0;
  88555. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88556. decoder->private_->stream_info.type = FLAC__METADATA_TYPE_STREAMINFO;
  88557. decoder->private_->stream_info.is_last = is_last;
  88558. decoder->private_->stream_info.length = length;
  88559. bits = FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN;
  88560. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, bits))
  88561. return false; /* read_callback_ sets the state for us */
  88562. decoder->private_->stream_info.data.stream_info.min_blocksize = x;
  88563. used_bits += bits;
  88564. bits = FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN;
  88565. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN))
  88566. return false; /* read_callback_ sets the state for us */
  88567. decoder->private_->stream_info.data.stream_info.max_blocksize = x;
  88568. used_bits += bits;
  88569. bits = FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN;
  88570. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN))
  88571. return false; /* read_callback_ sets the state for us */
  88572. decoder->private_->stream_info.data.stream_info.min_framesize = x;
  88573. used_bits += bits;
  88574. bits = FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN;
  88575. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN))
  88576. return false; /* read_callback_ sets the state for us */
  88577. decoder->private_->stream_info.data.stream_info.max_framesize = x;
  88578. used_bits += bits;
  88579. bits = FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN;
  88580. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN))
  88581. return false; /* read_callback_ sets the state for us */
  88582. decoder->private_->stream_info.data.stream_info.sample_rate = x;
  88583. used_bits += bits;
  88584. bits = FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN;
  88585. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN))
  88586. return false; /* read_callback_ sets the state for us */
  88587. decoder->private_->stream_info.data.stream_info.channels = x+1;
  88588. used_bits += bits;
  88589. bits = FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN;
  88590. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN))
  88591. return false; /* read_callback_ sets the state for us */
  88592. decoder->private_->stream_info.data.stream_info.bits_per_sample = x+1;
  88593. used_bits += bits;
  88594. bits = FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN;
  88595. 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))
  88596. return false; /* read_callback_ sets the state for us */
  88597. used_bits += bits;
  88598. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, decoder->private_->stream_info.data.stream_info.md5sum, 16))
  88599. return false; /* read_callback_ sets the state for us */
  88600. used_bits += 16*8;
  88601. FLAC__ASSERT(used_bits % 8 == 0);
  88602. length -= (used_bits / 8);
  88603. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, length))
  88604. return false; /* read_callback_ sets the state for us */
  88605. return true;
  88606. }
  88607. FLAC__bool read_metadata_seektable_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length)
  88608. {
  88609. FLAC__uint32 i, x;
  88610. FLAC__uint64 xx;
  88611. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88612. decoder->private_->seek_table.type = FLAC__METADATA_TYPE_SEEKTABLE;
  88613. decoder->private_->seek_table.is_last = is_last;
  88614. decoder->private_->seek_table.length = length;
  88615. decoder->private_->seek_table.data.seek_table.num_points = length / FLAC__STREAM_METADATA_SEEKPOINT_LENGTH;
  88616. 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)))) {
  88617. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88618. return false;
  88619. }
  88620. for(i = 0; i < decoder->private_->seek_table.data.seek_table.num_points; i++) {
  88621. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &xx, FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN))
  88622. return false; /* read_callback_ sets the state for us */
  88623. decoder->private_->seek_table.data.seek_table.points[i].sample_number = xx;
  88624. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &xx, FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN))
  88625. return false; /* read_callback_ sets the state for us */
  88626. decoder->private_->seek_table.data.seek_table.points[i].stream_offset = xx;
  88627. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN))
  88628. return false; /* read_callback_ sets the state for us */
  88629. decoder->private_->seek_table.data.seek_table.points[i].frame_samples = x;
  88630. }
  88631. length -= (decoder->private_->seek_table.data.seek_table.num_points * FLAC__STREAM_METADATA_SEEKPOINT_LENGTH);
  88632. if(length > 0) {
  88633. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, length))
  88634. return false; /* read_callback_ sets the state for us */
  88635. }
  88636. return true;
  88637. }
  88638. FLAC__bool read_metadata_vorbiscomment_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_VorbisComment *obj)
  88639. {
  88640. FLAC__uint32 i;
  88641. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88642. FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN == 32);
  88643. if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->vendor_string.length))
  88644. return false; /* read_callback_ sets the state for us */
  88645. if(obj->vendor_string.length > 0) {
  88646. if(0 == (obj->vendor_string.entry = (FLAC__byte*)safe_malloc_add_2op_(obj->vendor_string.length, /*+*/1))) {
  88647. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88648. return false;
  88649. }
  88650. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->vendor_string.entry, obj->vendor_string.length))
  88651. return false; /* read_callback_ sets the state for us */
  88652. obj->vendor_string.entry[obj->vendor_string.length] = '\0';
  88653. }
  88654. else
  88655. obj->vendor_string.entry = 0;
  88656. FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN == 32);
  88657. if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->num_comments))
  88658. return false; /* read_callback_ sets the state for us */
  88659. if(obj->num_comments > 0) {
  88660. if(0 == (obj->comments = (FLAC__StreamMetadata_VorbisComment_Entry*)safe_malloc_mul_2op_(obj->num_comments, /*times*/sizeof(FLAC__StreamMetadata_VorbisComment_Entry)))) {
  88661. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88662. return false;
  88663. }
  88664. for(i = 0; i < obj->num_comments; i++) {
  88665. FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN == 32);
  88666. if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->comments[i].length))
  88667. return false; /* read_callback_ sets the state for us */
  88668. if(obj->comments[i].length > 0) {
  88669. if(0 == (obj->comments[i].entry = (FLAC__byte*)safe_malloc_add_2op_(obj->comments[i].length, /*+*/1))) {
  88670. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88671. return false;
  88672. }
  88673. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->comments[i].entry, obj->comments[i].length))
  88674. return false; /* read_callback_ sets the state for us */
  88675. obj->comments[i].entry[obj->comments[i].length] = '\0';
  88676. }
  88677. else
  88678. obj->comments[i].entry = 0;
  88679. }
  88680. }
  88681. else {
  88682. obj->comments = 0;
  88683. }
  88684. return true;
  88685. }
  88686. FLAC__bool read_metadata_cuesheet_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_CueSheet *obj)
  88687. {
  88688. FLAC__uint32 i, j, x;
  88689. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88690. memset(obj, 0, sizeof(FLAC__StreamMetadata_CueSheet));
  88691. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN % 8 == 0);
  88692. 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))
  88693. return false; /* read_callback_ sets the state for us */
  88694. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &obj->lead_in, FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN))
  88695. return false; /* read_callback_ sets the state for us */
  88696. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN))
  88697. return false; /* read_callback_ sets the state for us */
  88698. obj->is_cd = x? true : false;
  88699. if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN))
  88700. return false; /* read_callback_ sets the state for us */
  88701. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN))
  88702. return false; /* read_callback_ sets the state for us */
  88703. obj->num_tracks = x;
  88704. if(obj->num_tracks > 0) {
  88705. if(0 == (obj->tracks = (FLAC__StreamMetadata_CueSheet_Track*)safe_calloc_(obj->num_tracks, sizeof(FLAC__StreamMetadata_CueSheet_Track)))) {
  88706. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88707. return false;
  88708. }
  88709. for(i = 0; i < obj->num_tracks; i++) {
  88710. FLAC__StreamMetadata_CueSheet_Track *track = &obj->tracks[i];
  88711. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &track->offset, FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN))
  88712. return false; /* read_callback_ sets the state for us */
  88713. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN))
  88714. return false; /* read_callback_ sets the state for us */
  88715. track->number = (FLAC__byte)x;
  88716. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN % 8 == 0);
  88717. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, (FLAC__byte*)track->isrc, FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN/8))
  88718. return false; /* read_callback_ sets the state for us */
  88719. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN))
  88720. return false; /* read_callback_ sets the state for us */
  88721. track->type = x;
  88722. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN))
  88723. return false; /* read_callback_ sets the state for us */
  88724. track->pre_emphasis = x;
  88725. if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN))
  88726. return false; /* read_callback_ sets the state for us */
  88727. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN))
  88728. return false; /* read_callback_ sets the state for us */
  88729. track->num_indices = (FLAC__byte)x;
  88730. if(track->num_indices > 0) {
  88731. if(0 == (track->indices = (FLAC__StreamMetadata_CueSheet_Index*)safe_calloc_(track->num_indices, sizeof(FLAC__StreamMetadata_CueSheet_Index)))) {
  88732. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88733. return false;
  88734. }
  88735. for(j = 0; j < track->num_indices; j++) {
  88736. FLAC__StreamMetadata_CueSheet_Index *index = &track->indices[j];
  88737. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &index->offset, FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN))
  88738. return false; /* read_callback_ sets the state for us */
  88739. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN))
  88740. return false; /* read_callback_ sets the state for us */
  88741. index->number = (FLAC__byte)x;
  88742. if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN))
  88743. return false; /* read_callback_ sets the state for us */
  88744. }
  88745. }
  88746. }
  88747. }
  88748. return true;
  88749. }
  88750. FLAC__bool read_metadata_picture_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_Picture *obj)
  88751. {
  88752. FLAC__uint32 x;
  88753. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88754. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_TYPE_LEN))
  88755. return false; /* read_callback_ sets the state for us */
  88756. obj->type = (FLAC__StreamMetadata_Picture_Type) x;
  88757. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN))
  88758. return false; /* read_callback_ sets the state for us */
  88759. if(0 == (obj->mime_type = (char*)safe_malloc_add_2op_(x, /*+*/1))) {
  88760. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88761. return false;
  88762. }
  88763. if(x > 0) {
  88764. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, (FLAC__byte*)obj->mime_type, x))
  88765. return false; /* read_callback_ sets the state for us */
  88766. }
  88767. obj->mime_type[x] = '\0';
  88768. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN))
  88769. return false; /* read_callback_ sets the state for us */
  88770. if(0 == (obj->description = (FLAC__byte*)safe_malloc_add_2op_(x, /*+*/1))) {
  88771. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88772. return false;
  88773. }
  88774. if(x > 0) {
  88775. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->description, x))
  88776. return false; /* read_callback_ sets the state for us */
  88777. }
  88778. obj->description[x] = '\0';
  88779. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->width, FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN))
  88780. return false; /* read_callback_ sets the state for us */
  88781. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->height, FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN))
  88782. return false; /* read_callback_ sets the state for us */
  88783. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->depth, FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN))
  88784. return false; /* read_callback_ sets the state for us */
  88785. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->colors, FLAC__STREAM_METADATA_PICTURE_COLORS_LEN))
  88786. return false; /* read_callback_ sets the state for us */
  88787. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &(obj->data_length), FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN))
  88788. return false; /* read_callback_ sets the state for us */
  88789. if(0 == (obj->data = (FLAC__byte*)safe_malloc_(obj->data_length))) {
  88790. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88791. return false;
  88792. }
  88793. if(obj->data_length > 0) {
  88794. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->data, obj->data_length))
  88795. return false; /* read_callback_ sets the state for us */
  88796. }
  88797. return true;
  88798. }
  88799. FLAC__bool skip_id3v2_tag_(FLAC__StreamDecoder *decoder)
  88800. {
  88801. FLAC__uint32 x;
  88802. unsigned i, skip;
  88803. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 24))
  88804. return false; /* read_callback_ sets the state for us */
  88805. skip = 0;
  88806. for(i = 0; i < 4; i++) {
  88807. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88808. return false; /* read_callback_ sets the state for us */
  88809. skip <<= 7;
  88810. skip |= (x & 0x7f);
  88811. }
  88812. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, skip))
  88813. return false; /* read_callback_ sets the state for us */
  88814. return true;
  88815. }
  88816. FLAC__bool frame_sync_(FLAC__StreamDecoder *decoder)
  88817. {
  88818. FLAC__uint32 x;
  88819. FLAC__bool first = true;
  88820. if(FLAC__stream_decoder_get_total_samples(decoder) > 0) {
  88821. if(decoder->private_->samples_decoded >= FLAC__stream_decoder_get_total_samples(decoder)) {
  88822. decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
  88823. return true;
  88824. }
  88825. }
  88826. if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input)) {
  88827. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__bitreader_bits_left_for_byte_alignment(decoder->private_->input)))
  88828. return false; /* read_callback_ sets the state for us */
  88829. }
  88830. while(1) {
  88831. if(decoder->private_->cached) {
  88832. x = (FLAC__uint32)decoder->private_->lookahead;
  88833. decoder->private_->cached = false;
  88834. }
  88835. else {
  88836. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88837. return false; /* read_callback_ sets the state for us */
  88838. }
  88839. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88840. decoder->private_->header_warmup[0] = (FLAC__byte)x;
  88841. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88842. return false; /* read_callback_ sets the state for us */
  88843. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88844. decoder->private_->lookahead = (FLAC__byte)x;
  88845. decoder->private_->cached = true;
  88846. }
  88847. else if(x >> 2 == 0x3e) { /* MAGIC NUMBER for the last 6 sync bits */
  88848. decoder->private_->header_warmup[1] = (FLAC__byte)x;
  88849. decoder->protected_->state = FLAC__STREAM_DECODER_READ_FRAME;
  88850. return true;
  88851. }
  88852. }
  88853. if(first) {
  88854. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88855. first = false;
  88856. }
  88857. }
  88858. return true;
  88859. }
  88860. FLAC__bool read_frame_(FLAC__StreamDecoder *decoder, FLAC__bool *got_a_frame, FLAC__bool do_full_decode)
  88861. {
  88862. unsigned channel;
  88863. unsigned i;
  88864. FLAC__int32 mid, side;
  88865. unsigned frame_crc; /* the one we calculate from the input stream */
  88866. FLAC__uint32 x;
  88867. *got_a_frame = false;
  88868. frame_crc = 0;
  88869. frame_crc = FLAC__CRC16_UPDATE(decoder->private_->header_warmup[0], frame_crc);
  88870. frame_crc = FLAC__CRC16_UPDATE(decoder->private_->header_warmup[1], frame_crc);
  88871. FLAC__bitreader_reset_read_crc16(decoder->private_->input, (FLAC__uint16)frame_crc);
  88872. if(!read_frame_header_(decoder))
  88873. return false;
  88874. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means we didn't sync on a valid header */
  88875. return true;
  88876. if(!allocate_output_(decoder, decoder->private_->frame.header.blocksize, decoder->private_->frame.header.channels))
  88877. return false;
  88878. for(channel = 0; channel < decoder->private_->frame.header.channels; channel++) {
  88879. unsigned bps = decoder->private_->frame.header.bits_per_sample;
  88880. switch(decoder->private_->frame.header.channel_assignment) {
  88881. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  88882. break;
  88883. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  88884. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88885. if(channel == 1)
  88886. bps++;
  88887. break;
  88888. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  88889. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88890. if(channel == 0)
  88891. bps++;
  88892. break;
  88893. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  88894. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88895. if(channel == 1)
  88896. bps++;
  88897. break;
  88898. default:
  88899. FLAC__ASSERT(0);
  88900. }
  88901. if(!read_subframe_(decoder, channel, bps, do_full_decode))
  88902. return false;
  88903. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption */
  88904. return true;
  88905. }
  88906. if(!read_zero_padding_(decoder))
  88907. return false;
  88908. 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) */
  88909. return true;
  88910. frame_crc = FLAC__bitreader_get_read_crc16(decoder->private_->input);
  88911. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__FRAME_FOOTER_CRC_LEN))
  88912. return false; /* read_callback_ sets the state for us */
  88913. if(frame_crc == x) {
  88914. if(do_full_decode) {
  88915. switch(decoder->private_->frame.header.channel_assignment) {
  88916. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  88917. break;
  88918. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  88919. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88920. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  88921. decoder->private_->output[1][i] = decoder->private_->output[0][i] - decoder->private_->output[1][i];
  88922. break;
  88923. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  88924. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88925. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  88926. decoder->private_->output[0][i] += decoder->private_->output[1][i];
  88927. break;
  88928. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  88929. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88930. for(i = 0; i < decoder->private_->frame.header.blocksize; i++) {
  88931. #if 1
  88932. mid = decoder->private_->output[0][i];
  88933. side = decoder->private_->output[1][i];
  88934. mid <<= 1;
  88935. mid |= (side & 1); /* i.e. if 'side' is odd... */
  88936. decoder->private_->output[0][i] = (mid + side) >> 1;
  88937. decoder->private_->output[1][i] = (mid - side) >> 1;
  88938. #else
  88939. mid = (decoder->private_->output[0][i] << 1) | (decoder->private_->output[1][i] & 1); /* i.e. if 'side' is odd... */
  88940. decoder->private_->output[0][i] = (mid + decoder->private_->output[1][i]) >> 1;
  88941. decoder->private_->output[1][i] = (mid - decoder->private_->output[1][i]) >> 1;
  88942. #endif
  88943. }
  88944. break;
  88945. default:
  88946. FLAC__ASSERT(0);
  88947. break;
  88948. }
  88949. }
  88950. }
  88951. else {
  88952. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH);
  88953. if(do_full_decode) {
  88954. for(channel = 0; channel < decoder->private_->frame.header.channels; channel++) {
  88955. memset(decoder->private_->output[channel], 0, sizeof(FLAC__int32) * decoder->private_->frame.header.blocksize);
  88956. }
  88957. }
  88958. }
  88959. *got_a_frame = true;
  88960. if(decoder->private_->next_fixed_block_size)
  88961. decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size;
  88962. decoder->protected_->channels = decoder->private_->frame.header.channels;
  88963. decoder->protected_->channel_assignment = decoder->private_->frame.header.channel_assignment;
  88964. decoder->protected_->bits_per_sample = decoder->private_->frame.header.bits_per_sample;
  88965. decoder->protected_->sample_rate = decoder->private_->frame.header.sample_rate;
  88966. decoder->protected_->blocksize = decoder->private_->frame.header.blocksize;
  88967. FLAC__ASSERT(decoder->private_->frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  88968. decoder->private_->samples_decoded = decoder->private_->frame.header.number.sample_number + decoder->private_->frame.header.blocksize;
  88969. if(do_full_decode) {
  88970. if(write_audio_frame_to_client_(decoder, &decoder->private_->frame, (const FLAC__int32 * const *)decoder->private_->output) != FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE)
  88971. return false;
  88972. }
  88973. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88974. return true;
  88975. }
  88976. FLAC__bool read_frame_header_(FLAC__StreamDecoder *decoder)
  88977. {
  88978. FLAC__uint32 x;
  88979. FLAC__uint64 xx;
  88980. unsigned i, blocksize_hint = 0, sample_rate_hint = 0;
  88981. FLAC__byte crc8, raw_header[16]; /* MAGIC NUMBER based on the maximum frame header size, including CRC */
  88982. unsigned raw_header_len;
  88983. FLAC__bool is_unparseable = false;
  88984. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88985. raw_header[0] = decoder->private_->header_warmup[0];
  88986. raw_header[1] = decoder->private_->header_warmup[1];
  88987. raw_header_len = 2;
  88988. if(raw_header[1] & 0x02) /* MAGIC NUMBER */
  88989. is_unparseable = true;
  88990. for(i = 0; i < 2; i++) {
  88991. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88992. return false; /* read_callback_ sets the state for us */
  88993. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88994. decoder->private_->lookahead = (FLAC__byte)x;
  88995. decoder->private_->cached = true;
  88996. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88997. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88998. return true;
  88999. }
  89000. raw_header[raw_header_len++] = (FLAC__byte)x;
  89001. }
  89002. switch(x = raw_header[2] >> 4) {
  89003. case 0:
  89004. is_unparseable = true;
  89005. break;
  89006. case 1:
  89007. decoder->private_->frame.header.blocksize = 192;
  89008. break;
  89009. case 2:
  89010. case 3:
  89011. case 4:
  89012. case 5:
  89013. decoder->private_->frame.header.blocksize = 576 << (x-2);
  89014. break;
  89015. case 6:
  89016. case 7:
  89017. blocksize_hint = x;
  89018. break;
  89019. case 8:
  89020. case 9:
  89021. case 10:
  89022. case 11:
  89023. case 12:
  89024. case 13:
  89025. case 14:
  89026. case 15:
  89027. decoder->private_->frame.header.blocksize = 256 << (x-8);
  89028. break;
  89029. default:
  89030. FLAC__ASSERT(0);
  89031. break;
  89032. }
  89033. switch(x = raw_header[2] & 0x0f) {
  89034. case 0:
  89035. if(decoder->private_->has_stream_info)
  89036. decoder->private_->frame.header.sample_rate = decoder->private_->stream_info.data.stream_info.sample_rate;
  89037. else
  89038. is_unparseable = true;
  89039. break;
  89040. case 1:
  89041. decoder->private_->frame.header.sample_rate = 88200;
  89042. break;
  89043. case 2:
  89044. decoder->private_->frame.header.sample_rate = 176400;
  89045. break;
  89046. case 3:
  89047. decoder->private_->frame.header.sample_rate = 192000;
  89048. break;
  89049. case 4:
  89050. decoder->private_->frame.header.sample_rate = 8000;
  89051. break;
  89052. case 5:
  89053. decoder->private_->frame.header.sample_rate = 16000;
  89054. break;
  89055. case 6:
  89056. decoder->private_->frame.header.sample_rate = 22050;
  89057. break;
  89058. case 7:
  89059. decoder->private_->frame.header.sample_rate = 24000;
  89060. break;
  89061. case 8:
  89062. decoder->private_->frame.header.sample_rate = 32000;
  89063. break;
  89064. case 9:
  89065. decoder->private_->frame.header.sample_rate = 44100;
  89066. break;
  89067. case 10:
  89068. decoder->private_->frame.header.sample_rate = 48000;
  89069. break;
  89070. case 11:
  89071. decoder->private_->frame.header.sample_rate = 96000;
  89072. break;
  89073. case 12:
  89074. case 13:
  89075. case 14:
  89076. sample_rate_hint = x;
  89077. break;
  89078. case 15:
  89079. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  89080. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89081. return true;
  89082. default:
  89083. FLAC__ASSERT(0);
  89084. }
  89085. x = (unsigned)(raw_header[3] >> 4);
  89086. if(x & 8) {
  89087. decoder->private_->frame.header.channels = 2;
  89088. switch(x & 7) {
  89089. case 0:
  89090. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE;
  89091. break;
  89092. case 1:
  89093. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE;
  89094. break;
  89095. case 2:
  89096. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_MID_SIDE;
  89097. break;
  89098. default:
  89099. is_unparseable = true;
  89100. break;
  89101. }
  89102. }
  89103. else {
  89104. decoder->private_->frame.header.channels = (unsigned)x + 1;
  89105. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT;
  89106. }
  89107. switch(x = (unsigned)(raw_header[3] & 0x0e) >> 1) {
  89108. case 0:
  89109. if(decoder->private_->has_stream_info)
  89110. decoder->private_->frame.header.bits_per_sample = decoder->private_->stream_info.data.stream_info.bits_per_sample;
  89111. else
  89112. is_unparseable = true;
  89113. break;
  89114. case 1:
  89115. decoder->private_->frame.header.bits_per_sample = 8;
  89116. break;
  89117. case 2:
  89118. decoder->private_->frame.header.bits_per_sample = 12;
  89119. break;
  89120. case 4:
  89121. decoder->private_->frame.header.bits_per_sample = 16;
  89122. break;
  89123. case 5:
  89124. decoder->private_->frame.header.bits_per_sample = 20;
  89125. break;
  89126. case 6:
  89127. decoder->private_->frame.header.bits_per_sample = 24;
  89128. break;
  89129. case 3:
  89130. case 7:
  89131. is_unparseable = true;
  89132. break;
  89133. default:
  89134. FLAC__ASSERT(0);
  89135. break;
  89136. }
  89137. if(raw_header[3] & 0x01) /* MAGIC NUMBER */
  89138. is_unparseable = true;
  89139. if(
  89140. raw_header[1] & 0x01 ||
  89141. (decoder->private_->has_stream_info && decoder->private_->stream_info.data.stream_info.min_blocksize != decoder->private_->stream_info.data.stream_info.max_blocksize)
  89142. ) { /* variable blocksize */
  89143. if(!FLAC__bitreader_read_utf8_uint64(decoder->private_->input, &xx, raw_header, &raw_header_len))
  89144. return false; /* read_callback_ sets the state for us */
  89145. if(xx == FLAC__U64L(0xffffffffffffffff)) { /* i.e. non-UTF8 code... */
  89146. decoder->private_->lookahead = raw_header[raw_header_len-1]; /* back up as much as we can */
  89147. decoder->private_->cached = true;
  89148. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  89149. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89150. return true;
  89151. }
  89152. decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER;
  89153. decoder->private_->frame.header.number.sample_number = xx;
  89154. }
  89155. else { /* fixed blocksize */
  89156. if(!FLAC__bitreader_read_utf8_uint32(decoder->private_->input, &x, raw_header, &raw_header_len))
  89157. return false; /* read_callback_ sets the state for us */
  89158. if(x == 0xffffffff) { /* i.e. non-UTF8 code... */
  89159. decoder->private_->lookahead = raw_header[raw_header_len-1]; /* back up as much as we can */
  89160. decoder->private_->cached = true;
  89161. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  89162. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89163. return true;
  89164. }
  89165. decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER;
  89166. decoder->private_->frame.header.number.frame_number = x;
  89167. }
  89168. if(blocksize_hint) {
  89169. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  89170. return false; /* read_callback_ sets the state for us */
  89171. raw_header[raw_header_len++] = (FLAC__byte)x;
  89172. if(blocksize_hint == 7) {
  89173. FLAC__uint32 _x;
  89174. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &_x, 8))
  89175. return false; /* read_callback_ sets the state for us */
  89176. raw_header[raw_header_len++] = (FLAC__byte)_x;
  89177. x = (x << 8) | _x;
  89178. }
  89179. decoder->private_->frame.header.blocksize = x+1;
  89180. }
  89181. if(sample_rate_hint) {
  89182. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  89183. return false; /* read_callback_ sets the state for us */
  89184. raw_header[raw_header_len++] = (FLAC__byte)x;
  89185. if(sample_rate_hint != 12) {
  89186. FLAC__uint32 _x;
  89187. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &_x, 8))
  89188. return false; /* read_callback_ sets the state for us */
  89189. raw_header[raw_header_len++] = (FLAC__byte)_x;
  89190. x = (x << 8) | _x;
  89191. }
  89192. if(sample_rate_hint == 12)
  89193. decoder->private_->frame.header.sample_rate = x*1000;
  89194. else if(sample_rate_hint == 13)
  89195. decoder->private_->frame.header.sample_rate = x;
  89196. else
  89197. decoder->private_->frame.header.sample_rate = x*10;
  89198. }
  89199. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  89200. return false; /* read_callback_ sets the state for us */
  89201. crc8 = (FLAC__byte)x;
  89202. if(FLAC__crc8(raw_header, raw_header_len) != crc8) {
  89203. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  89204. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89205. return true;
  89206. }
  89207. decoder->private_->next_fixed_block_size = 0;
  89208. if(decoder->private_->frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER) {
  89209. x = decoder->private_->frame.header.number.frame_number;
  89210. decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER;
  89211. if(decoder->private_->fixed_block_size)
  89212. decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->fixed_block_size * (FLAC__uint64)x;
  89213. else if(decoder->private_->has_stream_info) {
  89214. if(decoder->private_->stream_info.data.stream_info.min_blocksize == decoder->private_->stream_info.data.stream_info.max_blocksize) {
  89215. decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->stream_info.data.stream_info.min_blocksize * (FLAC__uint64)x;
  89216. decoder->private_->next_fixed_block_size = decoder->private_->stream_info.data.stream_info.max_blocksize;
  89217. }
  89218. else
  89219. is_unparseable = true;
  89220. }
  89221. else if(x == 0) {
  89222. decoder->private_->frame.header.number.sample_number = 0;
  89223. decoder->private_->next_fixed_block_size = decoder->private_->frame.header.blocksize;
  89224. }
  89225. else {
  89226. decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->frame.header.blocksize * (FLAC__uint64)x;
  89227. }
  89228. }
  89229. if(is_unparseable) {
  89230. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  89231. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89232. return true;
  89233. }
  89234. return true;
  89235. }
  89236. FLAC__bool read_subframe_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
  89237. {
  89238. FLAC__uint32 x;
  89239. FLAC__bool wasted_bits;
  89240. unsigned i;
  89241. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8)) /* MAGIC NUMBER */
  89242. return false; /* read_callback_ sets the state for us */
  89243. wasted_bits = (x & 1);
  89244. x &= 0xfe;
  89245. if(wasted_bits) {
  89246. unsigned u;
  89247. if(!FLAC__bitreader_read_unary_unsigned(decoder->private_->input, &u))
  89248. return false; /* read_callback_ sets the state for us */
  89249. decoder->private_->frame.subframes[channel].wasted_bits = u+1;
  89250. bps -= decoder->private_->frame.subframes[channel].wasted_bits;
  89251. }
  89252. else
  89253. decoder->private_->frame.subframes[channel].wasted_bits = 0;
  89254. if(x & 0x80) {
  89255. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  89256. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89257. return true;
  89258. }
  89259. else if(x == 0) {
  89260. if(!read_subframe_constant_(decoder, channel, bps, do_full_decode))
  89261. return false;
  89262. }
  89263. else if(x == 2) {
  89264. if(!read_subframe_verbatim_(decoder, channel, bps, do_full_decode))
  89265. return false;
  89266. }
  89267. else if(x < 16) {
  89268. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  89269. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89270. return true;
  89271. }
  89272. else if(x <= 24) {
  89273. if(!read_subframe_fixed_(decoder, channel, bps, (x>>1)&7, do_full_decode))
  89274. return false;
  89275. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption */
  89276. return true;
  89277. }
  89278. else if(x < 64) {
  89279. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  89280. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89281. return true;
  89282. }
  89283. else {
  89284. if(!read_subframe_lpc_(decoder, channel, bps, ((x>>1)&31)+1, do_full_decode))
  89285. return false;
  89286. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption */
  89287. return true;
  89288. }
  89289. if(wasted_bits && do_full_decode) {
  89290. x = decoder->private_->frame.subframes[channel].wasted_bits;
  89291. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  89292. decoder->private_->output[channel][i] <<= x;
  89293. }
  89294. return true;
  89295. }
  89296. FLAC__bool read_subframe_constant_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
  89297. {
  89298. FLAC__Subframe_Constant *subframe = &decoder->private_->frame.subframes[channel].data.constant;
  89299. FLAC__int32 x;
  89300. unsigned i;
  89301. FLAC__int32 *output = decoder->private_->output[channel];
  89302. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_CONSTANT;
  89303. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &x, bps))
  89304. return false; /* read_callback_ sets the state for us */
  89305. subframe->value = x;
  89306. if(do_full_decode) {
  89307. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  89308. output[i] = x;
  89309. }
  89310. return true;
  89311. }
  89312. FLAC__bool read_subframe_fixed_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode)
  89313. {
  89314. FLAC__Subframe_Fixed *subframe = &decoder->private_->frame.subframes[channel].data.fixed;
  89315. FLAC__int32 i32;
  89316. FLAC__uint32 u32;
  89317. unsigned u;
  89318. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_FIXED;
  89319. subframe->residual = decoder->private_->residual[channel];
  89320. subframe->order = order;
  89321. for(u = 0; u < order; u++) {
  89322. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, bps))
  89323. return false; /* read_callback_ sets the state for us */
  89324. subframe->warmup[u] = i32;
  89325. }
  89326. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN))
  89327. return false; /* read_callback_ sets the state for us */
  89328. subframe->entropy_coding_method.type = (FLAC__EntropyCodingMethodType)u32;
  89329. switch(subframe->entropy_coding_method.type) {
  89330. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  89331. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  89332. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  89333. return false; /* read_callback_ sets the state for us */
  89334. subframe->entropy_coding_method.data.partitioned_rice.order = u32;
  89335. subframe->entropy_coding_method.data.partitioned_rice.contents = &decoder->private_->partitioned_rice_contents[channel];
  89336. break;
  89337. default:
  89338. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  89339. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89340. return true;
  89341. }
  89342. switch(subframe->entropy_coding_method.type) {
  89343. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  89344. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  89345. 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))
  89346. return false;
  89347. break;
  89348. default:
  89349. FLAC__ASSERT(0);
  89350. }
  89351. if(do_full_decode) {
  89352. memcpy(decoder->private_->output[channel], subframe->warmup, sizeof(FLAC__int32) * order);
  89353. FLAC__fixed_restore_signal(decoder->private_->residual[channel], decoder->private_->frame.header.blocksize-order, order, decoder->private_->output[channel]+order);
  89354. }
  89355. return true;
  89356. }
  89357. FLAC__bool read_subframe_lpc_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode)
  89358. {
  89359. FLAC__Subframe_LPC *subframe = &decoder->private_->frame.subframes[channel].data.lpc;
  89360. FLAC__int32 i32;
  89361. FLAC__uint32 u32;
  89362. unsigned u;
  89363. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_LPC;
  89364. subframe->residual = decoder->private_->residual[channel];
  89365. subframe->order = order;
  89366. for(u = 0; u < order; u++) {
  89367. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, bps))
  89368. return false; /* read_callback_ sets the state for us */
  89369. subframe->warmup[u] = i32;
  89370. }
  89371. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN))
  89372. return false; /* read_callback_ sets the state for us */
  89373. if(u32 == (1u << FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN) - 1) {
  89374. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  89375. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89376. return true;
  89377. }
  89378. subframe->qlp_coeff_precision = u32+1;
  89379. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN))
  89380. return false; /* read_callback_ sets the state for us */
  89381. subframe->quantization_level = i32;
  89382. for(u = 0; u < order; u++) {
  89383. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, subframe->qlp_coeff_precision))
  89384. return false; /* read_callback_ sets the state for us */
  89385. subframe->qlp_coeff[u] = i32;
  89386. }
  89387. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN))
  89388. return false; /* read_callback_ sets the state for us */
  89389. subframe->entropy_coding_method.type = (FLAC__EntropyCodingMethodType)u32;
  89390. switch(subframe->entropy_coding_method.type) {
  89391. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  89392. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  89393. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  89394. return false; /* read_callback_ sets the state for us */
  89395. subframe->entropy_coding_method.data.partitioned_rice.order = u32;
  89396. subframe->entropy_coding_method.data.partitioned_rice.contents = &decoder->private_->partitioned_rice_contents[channel];
  89397. break;
  89398. default:
  89399. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  89400. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89401. return true;
  89402. }
  89403. switch(subframe->entropy_coding_method.type) {
  89404. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  89405. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  89406. 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))
  89407. return false;
  89408. break;
  89409. default:
  89410. FLAC__ASSERT(0);
  89411. }
  89412. if(do_full_decode) {
  89413. memcpy(decoder->private_->output[channel], subframe->warmup, sizeof(FLAC__int32) * order);
  89414. if(bps + subframe->qlp_coeff_precision + FLAC__bitmath_ilog2(order) <= 32)
  89415. if(bps <= 16 && subframe->qlp_coeff_precision <= 16) {
  89416. if(order <= 8)
  89417. 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);
  89418. else
  89419. 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);
  89420. }
  89421. else
  89422. 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);
  89423. else
  89424. 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);
  89425. }
  89426. return true;
  89427. }
  89428. FLAC__bool read_subframe_verbatim_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
  89429. {
  89430. FLAC__Subframe_Verbatim *subframe = &decoder->private_->frame.subframes[channel].data.verbatim;
  89431. FLAC__int32 x, *residual = decoder->private_->residual[channel];
  89432. unsigned i;
  89433. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_VERBATIM;
  89434. subframe->data = residual;
  89435. for(i = 0; i < decoder->private_->frame.header.blocksize; i++) {
  89436. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &x, bps))
  89437. return false; /* read_callback_ sets the state for us */
  89438. residual[i] = x;
  89439. }
  89440. if(do_full_decode)
  89441. memcpy(decoder->private_->output[channel], subframe->data, sizeof(FLAC__int32) * decoder->private_->frame.header.blocksize);
  89442. return true;
  89443. }
  89444. 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)
  89445. {
  89446. FLAC__uint32 rice_parameter;
  89447. int i;
  89448. unsigned partition, sample, u;
  89449. const unsigned partitions = 1u << partition_order;
  89450. const unsigned partition_samples = partition_order > 0? decoder->private_->frame.header.blocksize >> partition_order : decoder->private_->frame.header.blocksize - predictor_order;
  89451. const unsigned plen = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN;
  89452. const unsigned pesc = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  89453. if(partition_order == 0) {
  89454. if(decoder->private_->frame.header.blocksize < predictor_order) {
  89455. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  89456. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89457. return true;
  89458. }
  89459. }
  89460. else {
  89461. if(partition_samples < predictor_order) {
  89462. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  89463. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89464. return true;
  89465. }
  89466. }
  89467. if(!FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(partitioned_rice_contents, max(6, partition_order))) {
  89468. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  89469. return false;
  89470. }
  89471. sample = 0;
  89472. for(partition = 0; partition < partitions; partition++) {
  89473. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &rice_parameter, plen))
  89474. return false; /* read_callback_ sets the state for us */
  89475. partitioned_rice_contents->parameters[partition] = rice_parameter;
  89476. if(rice_parameter < pesc) {
  89477. partitioned_rice_contents->raw_bits[partition] = 0;
  89478. u = (partition_order == 0 || partition > 0)? partition_samples : partition_samples - predictor_order;
  89479. if(!decoder->private_->local_bitreader_read_rice_signed_block(decoder->private_->input, (int*) residual + sample, u, rice_parameter))
  89480. return false; /* read_callback_ sets the state for us */
  89481. sample += u;
  89482. }
  89483. else {
  89484. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &rice_parameter, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
  89485. return false; /* read_callback_ sets the state for us */
  89486. partitioned_rice_contents->raw_bits[partition] = rice_parameter;
  89487. for(u = (partition_order == 0 || partition > 0)? 0 : predictor_order; u < partition_samples; u++, sample++) {
  89488. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, (FLAC__int32*) &i, rice_parameter))
  89489. return false; /* read_callback_ sets the state for us */
  89490. residual[sample] = i;
  89491. }
  89492. }
  89493. }
  89494. return true;
  89495. }
  89496. FLAC__bool read_zero_padding_(FLAC__StreamDecoder *decoder)
  89497. {
  89498. if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input)) {
  89499. FLAC__uint32 zero = 0;
  89500. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &zero, FLAC__bitreader_bits_left_for_byte_alignment(decoder->private_->input)))
  89501. return false; /* read_callback_ sets the state for us */
  89502. if(zero != 0) {
  89503. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  89504. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89505. }
  89506. }
  89507. return true;
  89508. }
  89509. FLAC__bool read_callback_(FLAC__byte buffer[], size_t *bytes, void *client_data)
  89510. {
  89511. FLAC__StreamDecoder *decoder = (FLAC__StreamDecoder *)client_data;
  89512. if(
  89513. #if FLAC__HAS_OGG
  89514. !decoder->private_->is_ogg &&
  89515. #endif
  89516. decoder->private_->eof_callback && decoder->private_->eof_callback(decoder, decoder->private_->client_data)
  89517. ) {
  89518. *bytes = 0;
  89519. decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
  89520. return false;
  89521. }
  89522. else if(*bytes > 0) {
  89523. if(decoder->private_->is_seeking && decoder->private_->unparseable_frame_count > 20) {
  89524. decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
  89525. return false;
  89526. }
  89527. else {
  89528. const FLAC__StreamDecoderReadStatus status =
  89529. #if FLAC__HAS_OGG
  89530. decoder->private_->is_ogg?
  89531. read_callback_ogg_aspect_(decoder, buffer, bytes) :
  89532. #endif
  89533. decoder->private_->read_callback(decoder, buffer, bytes, decoder->private_->client_data)
  89534. ;
  89535. if(status == FLAC__STREAM_DECODER_READ_STATUS_ABORT) {
  89536. decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
  89537. return false;
  89538. }
  89539. else if(*bytes == 0) {
  89540. if(
  89541. status == FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM ||
  89542. (
  89543. #if FLAC__HAS_OGG
  89544. !decoder->private_->is_ogg &&
  89545. #endif
  89546. decoder->private_->eof_callback && decoder->private_->eof_callback(decoder, decoder->private_->client_data)
  89547. )
  89548. ) {
  89549. decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
  89550. return false;
  89551. }
  89552. else
  89553. return true;
  89554. }
  89555. else
  89556. return true;
  89557. }
  89558. }
  89559. else {
  89560. decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
  89561. return false;
  89562. }
  89563. }
  89564. #if FLAC__HAS_OGG
  89565. FLAC__StreamDecoderReadStatus read_callback_ogg_aspect_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes)
  89566. {
  89567. switch(FLAC__ogg_decoder_aspect_read_callback_wrapper(&decoder->protected_->ogg_decoder_aspect, buffer, bytes, read_callback_proxy_, decoder, decoder->private_->client_data)) {
  89568. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_OK:
  89569. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  89570. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_LOST_SYNC:
  89571. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  89572. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM:
  89573. return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
  89574. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_NOT_FLAC:
  89575. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_UNSUPPORTED_MAPPING_VERSION:
  89576. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT:
  89577. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_ERROR:
  89578. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_MEMORY_ALLOCATION_ERROR:
  89579. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  89580. default:
  89581. FLAC__ASSERT(0);
  89582. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  89583. }
  89584. }
  89585. FLAC__OggDecoderAspectReadStatus read_callback_proxy_(const void *void_decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  89586. {
  89587. FLAC__StreamDecoder *decoder = (FLAC__StreamDecoder*)void_decoder;
  89588. switch(decoder->private_->read_callback(decoder, buffer, bytes, client_data)) {
  89589. case FLAC__STREAM_DECODER_READ_STATUS_CONTINUE:
  89590. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_OK;
  89591. case FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM:
  89592. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM;
  89593. case FLAC__STREAM_DECODER_READ_STATUS_ABORT:
  89594. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT;
  89595. default:
  89596. FLAC__ASSERT(0);
  89597. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT;
  89598. }
  89599. }
  89600. #endif
  89601. FLAC__StreamDecoderWriteStatus write_audio_frame_to_client_(FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[])
  89602. {
  89603. if(decoder->private_->is_seeking) {
  89604. FLAC__uint64 this_frame_sample = frame->header.number.sample_number;
  89605. FLAC__uint64 next_frame_sample = this_frame_sample + (FLAC__uint64)frame->header.blocksize;
  89606. FLAC__uint64 target_sample = decoder->private_->target_sample;
  89607. FLAC__ASSERT(frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  89608. #if FLAC__HAS_OGG
  89609. decoder->private_->got_a_frame = true;
  89610. #endif
  89611. decoder->private_->last_frame = *frame; /* save the frame */
  89612. if(this_frame_sample <= target_sample && target_sample < next_frame_sample) { /* we hit our target frame */
  89613. unsigned delta = (unsigned)(target_sample - this_frame_sample);
  89614. decoder->private_->is_seeking = false;
  89615. if(delta > 0) {
  89616. unsigned channel;
  89617. const FLAC__int32 *newbuffer[FLAC__MAX_CHANNELS];
  89618. for(channel = 0; channel < frame->header.channels; channel++)
  89619. newbuffer[channel] = buffer[channel] + delta;
  89620. decoder->private_->last_frame.header.blocksize -= delta;
  89621. decoder->private_->last_frame.header.number.sample_number += (FLAC__uint64)delta;
  89622. return decoder->private_->write_callback(decoder, &decoder->private_->last_frame, newbuffer, decoder->private_->client_data);
  89623. }
  89624. else {
  89625. return decoder->private_->write_callback(decoder, frame, buffer, decoder->private_->client_data);
  89626. }
  89627. }
  89628. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  89629. }
  89630. if(!decoder->private_->has_stream_info)
  89631. decoder->private_->do_md5_checking = false;
  89632. if(decoder->private_->do_md5_checking) {
  89633. if(!FLAC__MD5Accumulate(&decoder->private_->md5context, buffer, frame->header.channels, frame->header.blocksize, (frame->header.bits_per_sample+7) / 8))
  89634. return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
  89635. }
  89636. return decoder->private_->write_callback(decoder, frame, buffer, decoder->private_->client_data);
  89637. }
  89638. void send_error_to_client_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status)
  89639. {
  89640. if(!decoder->private_->is_seeking)
  89641. decoder->private_->error_callback(decoder, status, decoder->private_->client_data);
  89642. else if(status == FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM)
  89643. decoder->private_->unparseable_frame_count++;
  89644. }
  89645. FLAC__bool seek_to_absolute_sample_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample)
  89646. {
  89647. FLAC__uint64 first_frame_offset = decoder->private_->first_frame_offset, lower_bound, upper_bound, lower_bound_sample, upper_bound_sample, this_frame_sample;
  89648. FLAC__int64 pos = -1;
  89649. int i;
  89650. unsigned approx_bytes_per_frame;
  89651. FLAC__bool first_seek = true;
  89652. const FLAC__uint64 total_samples = FLAC__stream_decoder_get_total_samples(decoder);
  89653. const unsigned min_blocksize = decoder->private_->stream_info.data.stream_info.min_blocksize;
  89654. const unsigned max_blocksize = decoder->private_->stream_info.data.stream_info.max_blocksize;
  89655. const unsigned max_framesize = decoder->private_->stream_info.data.stream_info.max_framesize;
  89656. const unsigned min_framesize = decoder->private_->stream_info.data.stream_info.min_framesize;
  89657. unsigned channels = FLAC__stream_decoder_get_channels(decoder);
  89658. unsigned bps = FLAC__stream_decoder_get_bits_per_sample(decoder);
  89659. const FLAC__StreamMetadata_SeekTable *seek_table = decoder->private_->has_seek_table? &decoder->private_->seek_table.data.seek_table : 0;
  89660. if(channels == 0)
  89661. channels = decoder->private_->stream_info.data.stream_info.channels;
  89662. if(bps == 0)
  89663. bps = decoder->private_->stream_info.data.stream_info.bits_per_sample;
  89664. if(max_framesize > 0)
  89665. approx_bytes_per_frame = (max_framesize + min_framesize) / 2 + 1;
  89666. else if(min_blocksize == max_blocksize && min_blocksize > 0) {
  89667. approx_bytes_per_frame = min_blocksize * channels * bps/8 + 64;
  89668. }
  89669. else
  89670. approx_bytes_per_frame = 4096 * channels * bps/8 + 64;
  89671. lower_bound = first_frame_offset;
  89672. lower_bound_sample = 0;
  89673. upper_bound = stream_length;
  89674. upper_bound_sample = total_samples > 0 ? total_samples : target_sample /*estimate it*/;
  89675. if(seek_table) {
  89676. FLAC__uint64 new_lower_bound = lower_bound;
  89677. FLAC__uint64 new_upper_bound = upper_bound;
  89678. FLAC__uint64 new_lower_bound_sample = lower_bound_sample;
  89679. FLAC__uint64 new_upper_bound_sample = upper_bound_sample;
  89680. for(i = (int)seek_table->num_points - 1; i >= 0; i--) {
  89681. if(
  89682. seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
  89683. seek_table->points[i].frame_samples > 0 && /* defense against bad seekpoints */
  89684. (total_samples <= 0 || seek_table->points[i].sample_number < total_samples) && /* defense against bad seekpoints */
  89685. seek_table->points[i].sample_number <= target_sample
  89686. )
  89687. break;
  89688. }
  89689. if(i >= 0) { /* i.e. we found a suitable seek point... */
  89690. new_lower_bound = first_frame_offset + seek_table->points[i].stream_offset;
  89691. new_lower_bound_sample = seek_table->points[i].sample_number;
  89692. }
  89693. for(i = 0; i < (int)seek_table->num_points; i++) {
  89694. if(
  89695. seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
  89696. seek_table->points[i].frame_samples > 0 && /* defense against bad seekpoints */
  89697. (total_samples <= 0 || seek_table->points[i].sample_number < total_samples) && /* defense against bad seekpoints */
  89698. seek_table->points[i].sample_number > target_sample
  89699. )
  89700. break;
  89701. }
  89702. if(i < (int)seek_table->num_points) { /* i.e. we found a suitable seek point... */
  89703. new_upper_bound = first_frame_offset + seek_table->points[i].stream_offset;
  89704. new_upper_bound_sample = seek_table->points[i].sample_number;
  89705. }
  89706. if(new_upper_bound >= new_lower_bound) {
  89707. lower_bound = new_lower_bound;
  89708. upper_bound = new_upper_bound;
  89709. lower_bound_sample = new_lower_bound_sample;
  89710. upper_bound_sample = new_upper_bound_sample;
  89711. }
  89712. }
  89713. FLAC__ASSERT(upper_bound_sample >= lower_bound_sample);
  89714. if(upper_bound_sample == lower_bound_sample)
  89715. upper_bound_sample++;
  89716. decoder->private_->target_sample = target_sample;
  89717. while(1) {
  89718. if (lower_bound_sample >= upper_bound_sample || lower_bound > upper_bound) {
  89719. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89720. return false;
  89721. }
  89722. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89723. #if defined _MSC_VER || defined __MINGW32__
  89724. 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;
  89725. #else
  89726. 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;
  89727. #endif
  89728. #else
  89729. if(upper_bound - lower_bound < 0xffffffff)
  89730. 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;
  89731. else /* @@@ WATCHOUT, ~2TB limit */
  89732. 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;
  89733. #endif
  89734. if(pos >= (FLAC__int64)upper_bound)
  89735. pos = (FLAC__int64)upper_bound - 1;
  89736. if(pos < (FLAC__int64)lower_bound)
  89737. pos = (FLAC__int64)lower_bound;
  89738. if(decoder->private_->seek_callback(decoder, (FLAC__uint64)pos, decoder->private_->client_data) != FLAC__STREAM_DECODER_SEEK_STATUS_OK) {
  89739. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89740. return false;
  89741. }
  89742. if(!FLAC__stream_decoder_flush(decoder)) {
  89743. return false;
  89744. }
  89745. decoder->private_->unparseable_frame_count = 0;
  89746. if(!FLAC__stream_decoder_process_single(decoder)) {
  89747. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89748. return false;
  89749. }
  89750. #if 0
  89751. if(decoder->protected_->state != FLAC__SEEKABLE_STREAM_DECODER_SEEKING && decoder->protected_->state != FLAC__STREAM_DECODER_END_OF_STREAM)
  89752. break;
  89753. #endif
  89754. if(!decoder->private_->is_seeking)
  89755. break;
  89756. FLAC__ASSERT(decoder->private_->last_frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  89757. this_frame_sample = decoder->private_->last_frame.header.number.sample_number;
  89758. if (0 == decoder->private_->samples_decoded || (this_frame_sample + decoder->private_->last_frame.header.blocksize >= upper_bound_sample && !first_seek)) {
  89759. if (pos == (FLAC__int64)lower_bound) {
  89760. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89761. return false;
  89762. }
  89763. approx_bytes_per_frame = approx_bytes_per_frame? approx_bytes_per_frame * 2 : 16;
  89764. continue;
  89765. }
  89766. first_seek = false;
  89767. if (this_frame_sample < lower_bound_sample) {
  89768. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89769. return false;
  89770. }
  89771. if(target_sample < this_frame_sample) {
  89772. upper_bound_sample = this_frame_sample + decoder->private_->last_frame.header.blocksize;
  89773. if(!FLAC__stream_decoder_get_decode_position(decoder, &upper_bound)) {
  89774. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89775. return false;
  89776. }
  89777. approx_bytes_per_frame = (unsigned)(2 * (upper_bound - pos) / 3 + 16);
  89778. }
  89779. else { /* target_sample >= this_frame_sample + this frame's blocksize */
  89780. lower_bound_sample = this_frame_sample + decoder->private_->last_frame.header.blocksize;
  89781. if(!FLAC__stream_decoder_get_decode_position(decoder, &lower_bound)) {
  89782. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89783. return false;
  89784. }
  89785. approx_bytes_per_frame = (unsigned)(2 * (lower_bound - pos) / 3 + 16);
  89786. }
  89787. }
  89788. return true;
  89789. }
  89790. #if FLAC__HAS_OGG
  89791. FLAC__bool seek_to_absolute_sample_ogg_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample)
  89792. {
  89793. FLAC__uint64 left_pos = 0, right_pos = stream_length;
  89794. FLAC__uint64 left_sample = 0, right_sample = FLAC__stream_decoder_get_total_samples(decoder);
  89795. FLAC__uint64 this_frame_sample = (FLAC__uint64)0 - 1;
  89796. FLAC__uint64 pos = 0; /* only initialized to avoid compiler warning */
  89797. FLAC__bool did_a_seek;
  89798. unsigned iteration = 0;
  89799. unsigned BINARY_SEARCH_AFTER_ITERATION = 2;
  89800. static const FLAC__uint64 LINEAR_SEARCH_WITHIN_SAMPLES = FLAC__MAX_BLOCK_SIZE * 2;
  89801. if(right_sample == 0) {
  89802. right_sample = (FLAC__uint64)(-1);
  89803. BINARY_SEARCH_AFTER_ITERATION = 0;
  89804. }
  89805. decoder->private_->target_sample = target_sample;
  89806. for( ; ; iteration++) {
  89807. if (iteration == 0 || this_frame_sample > target_sample || target_sample - this_frame_sample > LINEAR_SEARCH_WITHIN_SAMPLES) {
  89808. if (iteration >= BINARY_SEARCH_AFTER_ITERATION) {
  89809. pos = (right_pos + left_pos) / 2;
  89810. }
  89811. else {
  89812. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89813. #if defined _MSC_VER || defined __MINGW32__
  89814. 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));
  89815. #else
  89816. pos = (FLAC__uint64)((FLAC__double)(target_sample - left_sample) / (FLAC__double)(right_sample - left_sample) * (FLAC__double)(right_pos - left_pos));
  89817. #endif
  89818. #else
  89819. if ((target_sample-left_sample <= 0xffffffff) && (right_pos-left_pos <= 0xffffffff))
  89820. pos = (FLAC__int64)(((target_sample-left_sample) * (right_pos-left_pos)) / (right_sample-left_sample));
  89821. else /* @@@ WATCHOUT, ~2TB limit */
  89822. pos = (FLAC__int64)((((target_sample-left_sample)>>8) * ((right_pos-left_pos)>>8)) / ((right_sample-left_sample)>>16));
  89823. #endif
  89824. }
  89825. if(decoder->private_->seek_callback((FLAC__StreamDecoder*)decoder, (FLAC__uint64)pos, decoder->private_->client_data) != FLAC__STREAM_DECODER_SEEK_STATUS_OK) {
  89826. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89827. return false;
  89828. }
  89829. if(!FLAC__stream_decoder_flush(decoder)) {
  89830. return false;
  89831. }
  89832. did_a_seek = true;
  89833. }
  89834. else
  89835. did_a_seek = false;
  89836. decoder->private_->got_a_frame = false;
  89837. if(!FLAC__stream_decoder_process_single(decoder)) {
  89838. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89839. return false;
  89840. }
  89841. if(!decoder->private_->got_a_frame) {
  89842. if(did_a_seek) {
  89843. right_pos = pos;
  89844. BINARY_SEARCH_AFTER_ITERATION = 0;
  89845. }
  89846. else {
  89847. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89848. return false;
  89849. }
  89850. }
  89851. else if(!decoder->private_->is_seeking) {
  89852. break;
  89853. }
  89854. else {
  89855. this_frame_sample = decoder->private_->last_frame.header.number.sample_number;
  89856. FLAC__ASSERT(decoder->private_->last_frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  89857. if (did_a_seek) {
  89858. if (this_frame_sample <= target_sample) {
  89859. FLAC__ASSERT(this_frame_sample != target_sample);
  89860. left_sample = this_frame_sample;
  89861. if (left_pos == pos) {
  89862. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89863. return false;
  89864. }
  89865. left_pos = pos;
  89866. }
  89867. else if(this_frame_sample > target_sample) {
  89868. right_sample = this_frame_sample;
  89869. if (right_pos == pos) {
  89870. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89871. return false;
  89872. }
  89873. right_pos = pos;
  89874. }
  89875. }
  89876. }
  89877. }
  89878. return true;
  89879. }
  89880. #endif
  89881. FLAC__StreamDecoderReadStatus file_read_callback_dec(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  89882. {
  89883. (void)client_data;
  89884. if(*bytes > 0) {
  89885. *bytes = fread(buffer, sizeof(FLAC__byte), *bytes, decoder->private_->file);
  89886. if(ferror(decoder->private_->file))
  89887. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  89888. else if(*bytes == 0)
  89889. return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
  89890. else
  89891. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  89892. }
  89893. else
  89894. return FLAC__STREAM_DECODER_READ_STATUS_ABORT; /* abort to avoid a deadlock */
  89895. }
  89896. FLAC__StreamDecoderSeekStatus file_seek_callback_dec(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data)
  89897. {
  89898. (void)client_data;
  89899. if(decoder->private_->file == stdin)
  89900. return FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED;
  89901. else if(fseeko(decoder->private_->file, (off_t)absolute_byte_offset, SEEK_SET) < 0)
  89902. return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR;
  89903. else
  89904. return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
  89905. }
  89906. FLAC__StreamDecoderTellStatus file_tell_callback_dec(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
  89907. {
  89908. off_t pos;
  89909. (void)client_data;
  89910. if(decoder->private_->file == stdin)
  89911. return FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED;
  89912. else if((pos = ftello(decoder->private_->file)) < 0)
  89913. return FLAC__STREAM_DECODER_TELL_STATUS_ERROR;
  89914. else {
  89915. *absolute_byte_offset = (FLAC__uint64)pos;
  89916. return FLAC__STREAM_DECODER_TELL_STATUS_OK;
  89917. }
  89918. }
  89919. FLAC__StreamDecoderLengthStatus file_length_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data)
  89920. {
  89921. struct stat filestats;
  89922. (void)client_data;
  89923. if(decoder->private_->file == stdin)
  89924. return FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED;
  89925. else if(fstat(fileno(decoder->private_->file), &filestats) != 0)
  89926. return FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR;
  89927. else {
  89928. *stream_length = (FLAC__uint64)filestats.st_size;
  89929. return FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
  89930. }
  89931. }
  89932. FLAC__bool file_eof_callback_(const FLAC__StreamDecoder *decoder, void *client_data)
  89933. {
  89934. (void)client_data;
  89935. return feof(decoder->private_->file)? true : false;
  89936. }
  89937. #endif
  89938. /*** End of inlined file: stream_decoder.c ***/
  89939. /*** Start of inlined file: stream_encoder.c ***/
  89940. /*** Start of inlined file: juce_FlacHeader.h ***/
  89941. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  89942. // tasks..
  89943. #define VERSION "1.2.1"
  89944. #define FLAC__NO_DLL 1
  89945. #if JUCE_MSVC
  89946. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  89947. #endif
  89948. #if JUCE_MAC
  89949. #define FLAC__SYS_DARWIN 1
  89950. #endif
  89951. /*** End of inlined file: juce_FlacHeader.h ***/
  89952. #if JUCE_USE_FLAC
  89953. #if HAVE_CONFIG_H
  89954. # include <config.h>
  89955. #endif
  89956. #if defined _MSC_VER || defined __MINGW32__
  89957. #include <io.h> /* for _setmode() */
  89958. #include <fcntl.h> /* for _O_BINARY */
  89959. #endif
  89960. #if defined __CYGWIN__ || defined __EMX__
  89961. #include <io.h> /* for setmode(), O_BINARY */
  89962. #include <fcntl.h> /* for _O_BINARY */
  89963. #endif
  89964. #include <limits.h>
  89965. #include <stdio.h>
  89966. #include <stdlib.h> /* for malloc() */
  89967. #include <string.h> /* for memcpy() */
  89968. #include <sys/types.h> /* for off_t */
  89969. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINGW32__
  89970. #if _MSC_VER <= 1600 || defined __BORLANDC__ /* @@@ [2G limit] */
  89971. #define fseeko fseek
  89972. #define ftello ftell
  89973. #endif
  89974. #endif
  89975. /*** Start of inlined file: stream_encoder.h ***/
  89976. #ifndef FLAC__PROTECTED__STREAM_ENCODER_H
  89977. #define FLAC__PROTECTED__STREAM_ENCODER_H
  89978. #if FLAC__HAS_OGG
  89979. #include "private/ogg_encoder_aspect.h"
  89980. #endif
  89981. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89982. #define FLAC__MAX_APODIZATION_FUNCTIONS 32
  89983. typedef enum {
  89984. FLAC__APODIZATION_BARTLETT,
  89985. FLAC__APODIZATION_BARTLETT_HANN,
  89986. FLAC__APODIZATION_BLACKMAN,
  89987. FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE,
  89988. FLAC__APODIZATION_CONNES,
  89989. FLAC__APODIZATION_FLATTOP,
  89990. FLAC__APODIZATION_GAUSS,
  89991. FLAC__APODIZATION_HAMMING,
  89992. FLAC__APODIZATION_HANN,
  89993. FLAC__APODIZATION_KAISER_BESSEL,
  89994. FLAC__APODIZATION_NUTTALL,
  89995. FLAC__APODIZATION_RECTANGLE,
  89996. FLAC__APODIZATION_TRIANGLE,
  89997. FLAC__APODIZATION_TUKEY,
  89998. FLAC__APODIZATION_WELCH
  89999. } FLAC__ApodizationFunction;
  90000. typedef struct {
  90001. FLAC__ApodizationFunction type;
  90002. union {
  90003. struct {
  90004. FLAC__real stddev;
  90005. } gauss;
  90006. struct {
  90007. FLAC__real p;
  90008. } tukey;
  90009. } parameters;
  90010. } FLAC__ApodizationSpecification;
  90011. #endif // #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90012. typedef struct FLAC__StreamEncoderProtected {
  90013. FLAC__StreamEncoderState state;
  90014. FLAC__bool verify;
  90015. FLAC__bool streamable_subset;
  90016. FLAC__bool do_md5;
  90017. FLAC__bool do_mid_side_stereo;
  90018. FLAC__bool loose_mid_side_stereo;
  90019. unsigned channels;
  90020. unsigned bits_per_sample;
  90021. unsigned sample_rate;
  90022. unsigned blocksize;
  90023. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90024. unsigned num_apodizations;
  90025. FLAC__ApodizationSpecification apodizations[FLAC__MAX_APODIZATION_FUNCTIONS];
  90026. #endif
  90027. unsigned max_lpc_order;
  90028. unsigned qlp_coeff_precision;
  90029. FLAC__bool do_qlp_coeff_prec_search;
  90030. FLAC__bool do_exhaustive_model_search;
  90031. FLAC__bool do_escape_coding;
  90032. unsigned min_residual_partition_order;
  90033. unsigned max_residual_partition_order;
  90034. unsigned rice_parameter_search_dist;
  90035. FLAC__uint64 total_samples_estimate;
  90036. FLAC__StreamMetadata **metadata;
  90037. unsigned num_metadata_blocks;
  90038. FLAC__uint64 streaminfo_offset, seektable_offset, audio_offset;
  90039. #if FLAC__HAS_OGG
  90040. FLAC__OggEncoderAspect ogg_encoder_aspect;
  90041. #endif
  90042. } FLAC__StreamEncoderProtected;
  90043. #endif
  90044. /*** End of inlined file: stream_encoder.h ***/
  90045. #if FLAC__HAS_OGG
  90046. #include "include/private/ogg_helper.h"
  90047. #include "include/private/ogg_mapping.h"
  90048. #endif
  90049. /*** Start of inlined file: stream_encoder_framing.h ***/
  90050. #ifndef FLAC__PRIVATE__STREAM_ENCODER_FRAMING_H
  90051. #define FLAC__PRIVATE__STREAM_ENCODER_FRAMING_H
  90052. FLAC__bool FLAC__add_metadata_block(const FLAC__StreamMetadata *metadata, FLAC__BitWriter *bw);
  90053. FLAC__bool FLAC__frame_add_header(const FLAC__FrameHeader *header, FLAC__BitWriter *bw);
  90054. FLAC__bool FLAC__subframe_add_constant(const FLAC__Subframe_Constant *subframe, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  90055. FLAC__bool FLAC__subframe_add_fixed(const FLAC__Subframe_Fixed *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  90056. FLAC__bool FLAC__subframe_add_lpc(const FLAC__Subframe_LPC *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  90057. FLAC__bool FLAC__subframe_add_verbatim(const FLAC__Subframe_Verbatim *subframe, unsigned samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  90058. #endif
  90059. /*** End of inlined file: stream_encoder_framing.h ***/
  90060. /*** Start of inlined file: window.h ***/
  90061. #ifndef FLAC__PRIVATE__WINDOW_H
  90062. #define FLAC__PRIVATE__WINDOW_H
  90063. #ifdef HAVE_CONFIG_H
  90064. #include <config.h>
  90065. #endif
  90066. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90067. void FLAC__window_bartlett(FLAC__real *window, const FLAC__int32 L);
  90068. void FLAC__window_bartlett_hann(FLAC__real *window, const FLAC__int32 L);
  90069. void FLAC__window_blackman(FLAC__real *window, const FLAC__int32 L);
  90070. void FLAC__window_blackman_harris_4term_92db_sidelobe(FLAC__real *window, const FLAC__int32 L);
  90071. void FLAC__window_connes(FLAC__real *window, const FLAC__int32 L);
  90072. void FLAC__window_flattop(FLAC__real *window, const FLAC__int32 L);
  90073. void FLAC__window_gauss(FLAC__real *window, const FLAC__int32 L, const FLAC__real stddev); /* 0.0 < stddev <= 0.5 */
  90074. void FLAC__window_hamming(FLAC__real *window, const FLAC__int32 L);
  90075. void FLAC__window_hann(FLAC__real *window, const FLAC__int32 L);
  90076. void FLAC__window_kaiser_bessel(FLAC__real *window, const FLAC__int32 L);
  90077. void FLAC__window_nuttall(FLAC__real *window, const FLAC__int32 L);
  90078. void FLAC__window_rectangle(FLAC__real *window, const FLAC__int32 L);
  90079. void FLAC__window_triangle(FLAC__real *window, const FLAC__int32 L);
  90080. void FLAC__window_tukey(FLAC__real *window, const FLAC__int32 L, const FLAC__real p);
  90081. void FLAC__window_welch(FLAC__real *window, const FLAC__int32 L);
  90082. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  90083. #endif
  90084. /*** End of inlined file: window.h ***/
  90085. #ifndef FLaC__INLINE
  90086. #define FLaC__INLINE
  90087. #endif
  90088. #ifdef min
  90089. #undef min
  90090. #endif
  90091. #define min(x,y) ((x)<(y)?(x):(y))
  90092. #ifdef max
  90093. #undef max
  90094. #endif
  90095. #define max(x,y) ((x)>(y)?(x):(y))
  90096. #undef EXACT_RICE_BITS_CALCULATION
  90097. #undef ENABLE_RICE_PARAMETER_SEARCH
  90098. typedef struct {
  90099. FLAC__int32 *data[FLAC__MAX_CHANNELS];
  90100. unsigned size; /* of each data[] in samples */
  90101. unsigned tail;
  90102. } verify_input_fifo;
  90103. typedef struct {
  90104. const FLAC__byte *data;
  90105. unsigned capacity;
  90106. unsigned bytes;
  90107. } verify_output;
  90108. typedef enum {
  90109. ENCODER_IN_MAGIC = 0,
  90110. ENCODER_IN_METADATA = 1,
  90111. ENCODER_IN_AUDIO = 2
  90112. } EncoderStateHint;
  90113. static struct CompressionLevels {
  90114. FLAC__bool do_mid_side_stereo;
  90115. FLAC__bool loose_mid_side_stereo;
  90116. unsigned max_lpc_order;
  90117. unsigned qlp_coeff_precision;
  90118. FLAC__bool do_qlp_coeff_prec_search;
  90119. FLAC__bool do_escape_coding;
  90120. FLAC__bool do_exhaustive_model_search;
  90121. unsigned min_residual_partition_order;
  90122. unsigned max_residual_partition_order;
  90123. unsigned rice_parameter_search_dist;
  90124. } compression_levels_[] = {
  90125. { false, false, 0, 0, false, false, false, 0, 3, 0 },
  90126. { true , true , 0, 0, false, false, false, 0, 3, 0 },
  90127. { true , false, 0, 0, false, false, false, 0, 3, 0 },
  90128. { false, false, 6, 0, false, false, false, 0, 4, 0 },
  90129. { true , true , 8, 0, false, false, false, 0, 4, 0 },
  90130. { true , false, 8, 0, false, false, false, 0, 5, 0 },
  90131. { true , false, 8, 0, false, false, false, 0, 6, 0 },
  90132. { true , false, 8, 0, false, false, true , 0, 6, 0 },
  90133. { true , false, 12, 0, false, false, true , 0, 6, 0 }
  90134. };
  90135. static void set_defaults_enc(FLAC__StreamEncoder *encoder);
  90136. static void free_(FLAC__StreamEncoder *encoder);
  90137. static FLAC__bool resize_buffers_(FLAC__StreamEncoder *encoder, unsigned new_blocksize);
  90138. static FLAC__bool write_bitbuffer_(FLAC__StreamEncoder *encoder, unsigned samples, FLAC__bool is_last_block);
  90139. static FLAC__StreamEncoderWriteStatus write_frame_(FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, FLAC__bool is_last_block);
  90140. static void update_metadata_(const FLAC__StreamEncoder *encoder);
  90141. #if FLAC__HAS_OGG
  90142. static void update_ogg_metadata_(FLAC__StreamEncoder *encoder);
  90143. #endif
  90144. static FLAC__bool process_frame_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block, FLAC__bool is_last_block);
  90145. static FLAC__bool process_subframes_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block);
  90146. static FLAC__bool process_subframe_(
  90147. FLAC__StreamEncoder *encoder,
  90148. unsigned min_partition_order,
  90149. unsigned max_partition_order,
  90150. const FLAC__FrameHeader *frame_header,
  90151. unsigned subframe_bps,
  90152. const FLAC__int32 integer_signal[],
  90153. FLAC__Subframe *subframe[2],
  90154. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents[2],
  90155. FLAC__int32 *residual[2],
  90156. unsigned *best_subframe,
  90157. unsigned *best_bits
  90158. );
  90159. static FLAC__bool add_subframe_(
  90160. FLAC__StreamEncoder *encoder,
  90161. unsigned blocksize,
  90162. unsigned subframe_bps,
  90163. const FLAC__Subframe *subframe,
  90164. FLAC__BitWriter *frame
  90165. );
  90166. static unsigned evaluate_constant_subframe_(
  90167. FLAC__StreamEncoder *encoder,
  90168. const FLAC__int32 signal,
  90169. unsigned blocksize,
  90170. unsigned subframe_bps,
  90171. FLAC__Subframe *subframe
  90172. );
  90173. static unsigned evaluate_fixed_subframe_(
  90174. FLAC__StreamEncoder *encoder,
  90175. const FLAC__int32 signal[],
  90176. FLAC__int32 residual[],
  90177. FLAC__uint64 abs_residual_partition_sums[],
  90178. unsigned raw_bits_per_partition[],
  90179. unsigned blocksize,
  90180. unsigned subframe_bps,
  90181. unsigned order,
  90182. unsigned rice_parameter,
  90183. unsigned rice_parameter_limit,
  90184. unsigned min_partition_order,
  90185. unsigned max_partition_order,
  90186. FLAC__bool do_escape_coding,
  90187. unsigned rice_parameter_search_dist,
  90188. FLAC__Subframe *subframe,
  90189. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  90190. );
  90191. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90192. static unsigned evaluate_lpc_subframe_(
  90193. FLAC__StreamEncoder *encoder,
  90194. const FLAC__int32 signal[],
  90195. FLAC__int32 residual[],
  90196. FLAC__uint64 abs_residual_partition_sums[],
  90197. unsigned raw_bits_per_partition[],
  90198. const FLAC__real lp_coeff[],
  90199. unsigned blocksize,
  90200. unsigned subframe_bps,
  90201. unsigned order,
  90202. unsigned qlp_coeff_precision,
  90203. unsigned rice_parameter,
  90204. unsigned rice_parameter_limit,
  90205. unsigned min_partition_order,
  90206. unsigned max_partition_order,
  90207. FLAC__bool do_escape_coding,
  90208. unsigned rice_parameter_search_dist,
  90209. FLAC__Subframe *subframe,
  90210. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  90211. );
  90212. #endif
  90213. static unsigned evaluate_verbatim_subframe_(
  90214. FLAC__StreamEncoder *encoder,
  90215. const FLAC__int32 signal[],
  90216. unsigned blocksize,
  90217. unsigned subframe_bps,
  90218. FLAC__Subframe *subframe
  90219. );
  90220. static unsigned find_best_partition_order_(
  90221. struct FLAC__StreamEncoderPrivate *private_,
  90222. const FLAC__int32 residual[],
  90223. FLAC__uint64 abs_residual_partition_sums[],
  90224. unsigned raw_bits_per_partition[],
  90225. unsigned residual_samples,
  90226. unsigned predictor_order,
  90227. unsigned rice_parameter,
  90228. unsigned rice_parameter_limit,
  90229. unsigned min_partition_order,
  90230. unsigned max_partition_order,
  90231. unsigned bps,
  90232. FLAC__bool do_escape_coding,
  90233. unsigned rice_parameter_search_dist,
  90234. FLAC__EntropyCodingMethod *best_ecm
  90235. );
  90236. static void precompute_partition_info_sums_(
  90237. const FLAC__int32 residual[],
  90238. FLAC__uint64 abs_residual_partition_sums[],
  90239. unsigned residual_samples,
  90240. unsigned predictor_order,
  90241. unsigned min_partition_order,
  90242. unsigned max_partition_order,
  90243. unsigned bps
  90244. );
  90245. static void precompute_partition_info_escapes_(
  90246. const FLAC__int32 residual[],
  90247. unsigned raw_bits_per_partition[],
  90248. unsigned residual_samples,
  90249. unsigned predictor_order,
  90250. unsigned min_partition_order,
  90251. unsigned max_partition_order
  90252. );
  90253. static FLAC__bool set_partitioned_rice_(
  90254. #ifdef EXACT_RICE_BITS_CALCULATION
  90255. const FLAC__int32 residual[],
  90256. #endif
  90257. const FLAC__uint64 abs_residual_partition_sums[],
  90258. const unsigned raw_bits_per_partition[],
  90259. const unsigned residual_samples,
  90260. const unsigned predictor_order,
  90261. const unsigned suggested_rice_parameter,
  90262. const unsigned rice_parameter_limit,
  90263. const unsigned rice_parameter_search_dist,
  90264. const unsigned partition_order,
  90265. const FLAC__bool search_for_escapes,
  90266. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents,
  90267. unsigned *bits
  90268. );
  90269. static unsigned get_wasted_bits_(FLAC__int32 signal[], unsigned samples);
  90270. static void append_to_verify_fifo_(
  90271. verify_input_fifo *fifo,
  90272. const FLAC__int32 * const input[],
  90273. unsigned input_offset,
  90274. unsigned channels,
  90275. unsigned wide_samples
  90276. );
  90277. static void append_to_verify_fifo_interleaved_(
  90278. verify_input_fifo *fifo,
  90279. const FLAC__int32 input[],
  90280. unsigned input_offset,
  90281. unsigned channels,
  90282. unsigned wide_samples
  90283. );
  90284. static FLAC__StreamDecoderReadStatus verify_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  90285. static FLAC__StreamDecoderWriteStatus verify_write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
  90286. static void verify_metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
  90287. static void verify_error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
  90288. static FLAC__StreamEncoderReadStatus file_read_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  90289. static FLAC__StreamEncoderSeekStatus file_seek_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  90290. static FLAC__StreamEncoderTellStatus file_tell_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  90291. 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);
  90292. static FILE *get_binary_stdout_(void);
  90293. typedef struct FLAC__StreamEncoderPrivate {
  90294. unsigned input_capacity; /* current size (in samples) of the signal and residual buffers */
  90295. FLAC__int32 *integer_signal[FLAC__MAX_CHANNELS]; /* the integer version of the input signal */
  90296. FLAC__int32 *integer_signal_mid_side[2]; /* the integer version of the mid-side input signal (stereo only) */
  90297. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90298. FLAC__real *real_signal[FLAC__MAX_CHANNELS]; /* (@@@ currently unused) the floating-point version of the input signal */
  90299. FLAC__real *real_signal_mid_side[2]; /* (@@@ currently unused) the floating-point version of the mid-side input signal (stereo only) */
  90300. FLAC__real *window[FLAC__MAX_APODIZATION_FUNCTIONS]; /* the pre-computed floating-point window for each apodization function */
  90301. FLAC__real *windowed_signal; /* the integer_signal[] * current window[] */
  90302. #endif
  90303. unsigned subframe_bps[FLAC__MAX_CHANNELS]; /* the effective bits per sample of the input signal (stream bps - wasted bits) */
  90304. unsigned subframe_bps_mid_side[2]; /* the effective bits per sample of the mid-side input signal (stream bps - wasted bits + 0/1) */
  90305. FLAC__int32 *residual_workspace[FLAC__MAX_CHANNELS][2]; /* each channel has a candidate and best workspace where the subframe residual signals will be stored */
  90306. FLAC__int32 *residual_workspace_mid_side[2][2];
  90307. FLAC__Subframe subframe_workspace[FLAC__MAX_CHANNELS][2];
  90308. FLAC__Subframe subframe_workspace_mid_side[2][2];
  90309. FLAC__Subframe *subframe_workspace_ptr[FLAC__MAX_CHANNELS][2];
  90310. FLAC__Subframe *subframe_workspace_ptr_mid_side[2][2];
  90311. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_workspace[FLAC__MAX_CHANNELS][2];
  90312. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_workspace_mid_side[FLAC__MAX_CHANNELS][2];
  90313. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents_workspace_ptr[FLAC__MAX_CHANNELS][2];
  90314. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents_workspace_ptr_mid_side[FLAC__MAX_CHANNELS][2];
  90315. unsigned best_subframe[FLAC__MAX_CHANNELS]; /* index (0 or 1) into 2nd dimension of the above workspaces */
  90316. unsigned best_subframe_mid_side[2];
  90317. unsigned best_subframe_bits[FLAC__MAX_CHANNELS]; /* size in bits of the best subframe for each channel */
  90318. unsigned best_subframe_bits_mid_side[2];
  90319. FLAC__uint64 *abs_residual_partition_sums; /* workspace where the sum of abs(candidate residual) for each partition is stored */
  90320. unsigned *raw_bits_per_partition; /* workspace where the sum of silog2(candidate residual) for each partition is stored */
  90321. FLAC__BitWriter *frame; /* the current frame being worked on */
  90322. unsigned loose_mid_side_stereo_frames; /* rounded number of frames the encoder will use before trying both independent and mid/side frames again */
  90323. unsigned loose_mid_side_stereo_frame_count; /* number of frames using the current channel assignment */
  90324. FLAC__ChannelAssignment last_channel_assignment;
  90325. FLAC__StreamMetadata streaminfo; /* scratchpad for STREAMINFO as it is built */
  90326. FLAC__StreamMetadata_SeekTable *seek_table; /* pointer into encoder->protected_->metadata_ where the seek table is */
  90327. unsigned current_sample_number;
  90328. unsigned current_frame_number;
  90329. FLAC__MD5Context md5context;
  90330. FLAC__CPUInfo cpuinfo;
  90331. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90332. unsigned (*local_fixed_compute_best_predictor)(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  90333. #else
  90334. unsigned (*local_fixed_compute_best_predictor)(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  90335. #endif
  90336. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90337. void (*local_lpc_compute_autocorrelation)(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  90338. 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[]);
  90339. 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[]);
  90340. 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[]);
  90341. #endif
  90342. FLAC__bool use_wide_by_block; /* use slow 64-bit versions of some functions because of the block size */
  90343. FLAC__bool use_wide_by_partition; /* use slow 64-bit versions of some functions because of the min partition order and blocksize */
  90344. FLAC__bool use_wide_by_order; /* use slow 64-bit versions of some functions because of the lpc order */
  90345. FLAC__bool disable_constant_subframes;
  90346. FLAC__bool disable_fixed_subframes;
  90347. FLAC__bool disable_verbatim_subframes;
  90348. #if FLAC__HAS_OGG
  90349. FLAC__bool is_ogg;
  90350. #endif
  90351. FLAC__StreamEncoderReadCallback read_callback; /* currently only needed for Ogg FLAC */
  90352. FLAC__StreamEncoderSeekCallback seek_callback;
  90353. FLAC__StreamEncoderTellCallback tell_callback;
  90354. FLAC__StreamEncoderWriteCallback write_callback;
  90355. FLAC__StreamEncoderMetadataCallback metadata_callback;
  90356. FLAC__StreamEncoderProgressCallback progress_callback;
  90357. void *client_data;
  90358. unsigned first_seekpoint_to_check;
  90359. FILE *file; /* only used when encoding to a file */
  90360. FLAC__uint64 bytes_written;
  90361. FLAC__uint64 samples_written;
  90362. unsigned frames_written;
  90363. unsigned total_frames_estimate;
  90364. FLAC__int32 *integer_signal_unaligned[FLAC__MAX_CHANNELS];
  90365. FLAC__int32 *integer_signal_mid_side_unaligned[2];
  90366. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90367. FLAC__real *real_signal_unaligned[FLAC__MAX_CHANNELS]; /* (@@@ currently unused) */
  90368. FLAC__real *real_signal_mid_side_unaligned[2]; /* (@@@ currently unused) */
  90369. FLAC__real *window_unaligned[FLAC__MAX_APODIZATION_FUNCTIONS];
  90370. FLAC__real *windowed_signal_unaligned;
  90371. #endif
  90372. FLAC__int32 *residual_workspace_unaligned[FLAC__MAX_CHANNELS][2];
  90373. FLAC__int32 *residual_workspace_mid_side_unaligned[2][2];
  90374. FLAC__uint64 *abs_residual_partition_sums_unaligned;
  90375. unsigned *raw_bits_per_partition_unaligned;
  90376. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90377. FLAC__real lp_coeff[FLAC__MAX_LPC_ORDER][FLAC__MAX_LPC_ORDER]; /* from process_subframe_() */
  90378. #endif
  90379. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_extra[2]; /* from find_best_partition_order_() */
  90380. struct {
  90381. FLAC__StreamDecoder *decoder;
  90382. EncoderStateHint state_hint;
  90383. FLAC__bool needs_magic_hack;
  90384. verify_input_fifo input_fifo;
  90385. verify_output output;
  90386. struct {
  90387. FLAC__uint64 absolute_sample;
  90388. unsigned frame_number;
  90389. unsigned channel;
  90390. unsigned sample;
  90391. FLAC__int32 expected;
  90392. FLAC__int32 got;
  90393. } error_stats;
  90394. } verify;
  90395. FLAC__bool is_being_deleted; /* if true, call to ..._finish() from ..._delete() will not call the callbacks */
  90396. } FLAC__StreamEncoderPrivate;
  90397. FLAC_API const char * const FLAC__StreamEncoderStateString[] = {
  90398. "FLAC__STREAM_ENCODER_OK",
  90399. "FLAC__STREAM_ENCODER_UNINITIALIZED",
  90400. "FLAC__STREAM_ENCODER_OGG_ERROR",
  90401. "FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR",
  90402. "FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA",
  90403. "FLAC__STREAM_ENCODER_CLIENT_ERROR",
  90404. "FLAC__STREAM_ENCODER_IO_ERROR",
  90405. "FLAC__STREAM_ENCODER_FRAMING_ERROR",
  90406. "FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR"
  90407. };
  90408. FLAC_API const char * const FLAC__StreamEncoderInitStatusString[] = {
  90409. "FLAC__STREAM_ENCODER_INIT_STATUS_OK",
  90410. "FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR",
  90411. "FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER",
  90412. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS",
  90413. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS",
  90414. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE",
  90415. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE",
  90416. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE",
  90417. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER",
  90418. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION",
  90419. "FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER",
  90420. "FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE",
  90421. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA",
  90422. "FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED"
  90423. };
  90424. FLAC_API const char * const FLAC__treamEncoderReadStatusString[] = {
  90425. "FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE",
  90426. "FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM",
  90427. "FLAC__STREAM_ENCODER_READ_STATUS_ABORT",
  90428. "FLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED"
  90429. };
  90430. FLAC_API const char * const FLAC__StreamEncoderWriteStatusString[] = {
  90431. "FLAC__STREAM_ENCODER_WRITE_STATUS_OK",
  90432. "FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR"
  90433. };
  90434. FLAC_API const char * const FLAC__StreamEncoderSeekStatusString[] = {
  90435. "FLAC__STREAM_ENCODER_SEEK_STATUS_OK",
  90436. "FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR",
  90437. "FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED"
  90438. };
  90439. FLAC_API const char * const FLAC__StreamEncoderTellStatusString[] = {
  90440. "FLAC__STREAM_ENCODER_TELL_STATUS_OK",
  90441. "FLAC__STREAM_ENCODER_TELL_STATUS_ERROR",
  90442. "FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED"
  90443. };
  90444. static const unsigned OVERREAD_ = 1;
  90445. FLAC_API FLAC__StreamEncoder *FLAC__stream_encoder_new(void)
  90446. {
  90447. FLAC__StreamEncoder *encoder;
  90448. unsigned i;
  90449. FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is not true */
  90450. encoder = (FLAC__StreamEncoder*)calloc(1, sizeof(FLAC__StreamEncoder));
  90451. if(encoder == 0) {
  90452. return 0;
  90453. }
  90454. encoder->protected_ = (FLAC__StreamEncoderProtected*)calloc(1, sizeof(FLAC__StreamEncoderProtected));
  90455. if(encoder->protected_ == 0) {
  90456. free(encoder);
  90457. return 0;
  90458. }
  90459. encoder->private_ = (FLAC__StreamEncoderPrivate*)calloc(1, sizeof(FLAC__StreamEncoderPrivate));
  90460. if(encoder->private_ == 0) {
  90461. free(encoder->protected_);
  90462. free(encoder);
  90463. return 0;
  90464. }
  90465. encoder->private_->frame = FLAC__bitwriter_new();
  90466. if(encoder->private_->frame == 0) {
  90467. free(encoder->private_);
  90468. free(encoder->protected_);
  90469. free(encoder);
  90470. return 0;
  90471. }
  90472. encoder->private_->file = 0;
  90473. set_defaults_enc(encoder);
  90474. encoder->private_->is_being_deleted = false;
  90475. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  90476. encoder->private_->subframe_workspace_ptr[i][0] = &encoder->private_->subframe_workspace[i][0];
  90477. encoder->private_->subframe_workspace_ptr[i][1] = &encoder->private_->subframe_workspace[i][1];
  90478. }
  90479. for(i = 0; i < 2; i++) {
  90480. encoder->private_->subframe_workspace_ptr_mid_side[i][0] = &encoder->private_->subframe_workspace_mid_side[i][0];
  90481. encoder->private_->subframe_workspace_ptr_mid_side[i][1] = &encoder->private_->subframe_workspace_mid_side[i][1];
  90482. }
  90483. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  90484. encoder->private_->partitioned_rice_contents_workspace_ptr[i][0] = &encoder->private_->partitioned_rice_contents_workspace[i][0];
  90485. encoder->private_->partitioned_rice_contents_workspace_ptr[i][1] = &encoder->private_->partitioned_rice_contents_workspace[i][1];
  90486. }
  90487. for(i = 0; i < 2; i++) {
  90488. encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[i][0] = &encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0];
  90489. encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[i][1] = &encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1];
  90490. }
  90491. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  90492. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace[i][0]);
  90493. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace[i][1]);
  90494. }
  90495. for(i = 0; i < 2; i++) {
  90496. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0]);
  90497. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1]);
  90498. }
  90499. for(i = 0; i < 2; i++)
  90500. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_extra[i]);
  90501. encoder->protected_->state = FLAC__STREAM_ENCODER_UNINITIALIZED;
  90502. return encoder;
  90503. }
  90504. FLAC_API void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder)
  90505. {
  90506. unsigned i;
  90507. FLAC__ASSERT(0 != encoder);
  90508. FLAC__ASSERT(0 != encoder->protected_);
  90509. FLAC__ASSERT(0 != encoder->private_);
  90510. FLAC__ASSERT(0 != encoder->private_->frame);
  90511. encoder->private_->is_being_deleted = true;
  90512. (void)FLAC__stream_encoder_finish(encoder);
  90513. if(0 != encoder->private_->verify.decoder)
  90514. FLAC__stream_decoder_delete(encoder->private_->verify.decoder);
  90515. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  90516. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace[i][0]);
  90517. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace[i][1]);
  90518. }
  90519. for(i = 0; i < 2; i++) {
  90520. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0]);
  90521. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1]);
  90522. }
  90523. for(i = 0; i < 2; i++)
  90524. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_extra[i]);
  90525. FLAC__bitwriter_delete(encoder->private_->frame);
  90526. free(encoder->private_);
  90527. free(encoder->protected_);
  90528. free(encoder);
  90529. }
  90530. static FLAC__StreamEncoderInitStatus init_stream_internal_enc(
  90531. FLAC__StreamEncoder *encoder,
  90532. FLAC__StreamEncoderReadCallback read_callback,
  90533. FLAC__StreamEncoderWriteCallback write_callback,
  90534. FLAC__StreamEncoderSeekCallback seek_callback,
  90535. FLAC__StreamEncoderTellCallback tell_callback,
  90536. FLAC__StreamEncoderMetadataCallback metadata_callback,
  90537. void *client_data,
  90538. FLAC__bool is_ogg
  90539. )
  90540. {
  90541. unsigned i;
  90542. FLAC__bool metadata_has_seektable, metadata_has_vorbis_comment, metadata_picture_has_type1, metadata_picture_has_type2;
  90543. FLAC__ASSERT(0 != encoder);
  90544. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90545. return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
  90546. #if !FLAC__HAS_OGG
  90547. if(is_ogg)
  90548. return FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER;
  90549. #endif
  90550. if(0 == write_callback || (seek_callback && 0 == tell_callback))
  90551. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS;
  90552. if(encoder->protected_->channels == 0 || encoder->protected_->channels > FLAC__MAX_CHANNELS)
  90553. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS;
  90554. if(encoder->protected_->channels != 2) {
  90555. encoder->protected_->do_mid_side_stereo = false;
  90556. encoder->protected_->loose_mid_side_stereo = false;
  90557. }
  90558. else if(!encoder->protected_->do_mid_side_stereo)
  90559. encoder->protected_->loose_mid_side_stereo = false;
  90560. if(encoder->protected_->bits_per_sample >= 32)
  90561. encoder->protected_->do_mid_side_stereo = false; /* since we currenty do 32-bit math, the side channel would have 33 bps and overflow */
  90562. if(encoder->protected_->bits_per_sample < FLAC__MIN_BITS_PER_SAMPLE || encoder->protected_->bits_per_sample > FLAC__REFERENCE_CODEC_MAX_BITS_PER_SAMPLE)
  90563. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE;
  90564. if(!FLAC__format_sample_rate_is_valid(encoder->protected_->sample_rate))
  90565. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE;
  90566. if(encoder->protected_->blocksize == 0) {
  90567. if(encoder->protected_->max_lpc_order == 0)
  90568. encoder->protected_->blocksize = 1152;
  90569. else
  90570. encoder->protected_->blocksize = 4096;
  90571. }
  90572. if(encoder->protected_->blocksize < FLAC__MIN_BLOCK_SIZE || encoder->protected_->blocksize > FLAC__MAX_BLOCK_SIZE)
  90573. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE;
  90574. if(encoder->protected_->max_lpc_order > FLAC__MAX_LPC_ORDER)
  90575. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER;
  90576. if(encoder->protected_->blocksize < encoder->protected_->max_lpc_order)
  90577. return FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER;
  90578. if(encoder->protected_->qlp_coeff_precision == 0) {
  90579. if(encoder->protected_->bits_per_sample < 16) {
  90580. encoder->protected_->qlp_coeff_precision = max(FLAC__MIN_QLP_COEFF_PRECISION, 2 + encoder->protected_->bits_per_sample / 2);
  90581. }
  90582. else if(encoder->protected_->bits_per_sample == 16) {
  90583. if(encoder->protected_->blocksize <= 192)
  90584. encoder->protected_->qlp_coeff_precision = 7;
  90585. else if(encoder->protected_->blocksize <= 384)
  90586. encoder->protected_->qlp_coeff_precision = 8;
  90587. else if(encoder->protected_->blocksize <= 576)
  90588. encoder->protected_->qlp_coeff_precision = 9;
  90589. else if(encoder->protected_->blocksize <= 1152)
  90590. encoder->protected_->qlp_coeff_precision = 10;
  90591. else if(encoder->protected_->blocksize <= 2304)
  90592. encoder->protected_->qlp_coeff_precision = 11;
  90593. else if(encoder->protected_->blocksize <= 4608)
  90594. encoder->protected_->qlp_coeff_precision = 12;
  90595. else
  90596. encoder->protected_->qlp_coeff_precision = 13;
  90597. }
  90598. else {
  90599. if(encoder->protected_->blocksize <= 384)
  90600. encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION-2;
  90601. else if(encoder->protected_->blocksize <= 1152)
  90602. encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION-1;
  90603. else
  90604. encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION;
  90605. }
  90606. FLAC__ASSERT(encoder->protected_->qlp_coeff_precision <= FLAC__MAX_QLP_COEFF_PRECISION);
  90607. }
  90608. else if(encoder->protected_->qlp_coeff_precision < FLAC__MIN_QLP_COEFF_PRECISION || encoder->protected_->qlp_coeff_precision > FLAC__MAX_QLP_COEFF_PRECISION)
  90609. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION;
  90610. if(encoder->protected_->streamable_subset) {
  90611. if(
  90612. encoder->protected_->blocksize != 192 &&
  90613. encoder->protected_->blocksize != 576 &&
  90614. encoder->protected_->blocksize != 1152 &&
  90615. encoder->protected_->blocksize != 2304 &&
  90616. encoder->protected_->blocksize != 4608 &&
  90617. encoder->protected_->blocksize != 256 &&
  90618. encoder->protected_->blocksize != 512 &&
  90619. encoder->protected_->blocksize != 1024 &&
  90620. encoder->protected_->blocksize != 2048 &&
  90621. encoder->protected_->blocksize != 4096 &&
  90622. encoder->protected_->blocksize != 8192 &&
  90623. encoder->protected_->blocksize != 16384
  90624. )
  90625. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90626. if(!FLAC__format_sample_rate_is_subset(encoder->protected_->sample_rate))
  90627. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90628. if(
  90629. encoder->protected_->bits_per_sample != 8 &&
  90630. encoder->protected_->bits_per_sample != 12 &&
  90631. encoder->protected_->bits_per_sample != 16 &&
  90632. encoder->protected_->bits_per_sample != 20 &&
  90633. encoder->protected_->bits_per_sample != 24
  90634. )
  90635. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90636. if(encoder->protected_->max_residual_partition_order > FLAC__SUBSET_MAX_RICE_PARTITION_ORDER)
  90637. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90638. if(
  90639. encoder->protected_->sample_rate <= 48000 &&
  90640. (
  90641. encoder->protected_->blocksize > FLAC__SUBSET_MAX_BLOCK_SIZE_48000HZ ||
  90642. encoder->protected_->max_lpc_order > FLAC__SUBSET_MAX_LPC_ORDER_48000HZ
  90643. )
  90644. ) {
  90645. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90646. }
  90647. }
  90648. if(encoder->protected_->max_residual_partition_order >= (1u << FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  90649. encoder->protected_->max_residual_partition_order = (1u << FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN) - 1;
  90650. if(encoder->protected_->min_residual_partition_order >= encoder->protected_->max_residual_partition_order)
  90651. encoder->protected_->min_residual_partition_order = encoder->protected_->max_residual_partition_order;
  90652. #if FLAC__HAS_OGG
  90653. if(is_ogg && 0 != encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 1) {
  90654. unsigned i;
  90655. for(i = 1; i < encoder->protected_->num_metadata_blocks; i++) {
  90656. if(0 != encoder->protected_->metadata[i] && encoder->protected_->metadata[i]->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
  90657. FLAC__StreamMetadata *vc = encoder->protected_->metadata[i];
  90658. for( ; i > 0; i--)
  90659. encoder->protected_->metadata[i] = encoder->protected_->metadata[i-1];
  90660. encoder->protected_->metadata[0] = vc;
  90661. break;
  90662. }
  90663. }
  90664. }
  90665. #endif
  90666. if(0 != encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 0) {
  90667. unsigned i;
  90668. for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
  90669. if(0 != encoder->protected_->metadata[i] && encoder->protected_->metadata[i]->type == FLAC__METADATA_TYPE_SEEKTABLE) {
  90670. encoder->private_->seek_table = &encoder->protected_->metadata[i]->data.seek_table;
  90671. break; /* take only the first one */
  90672. }
  90673. }
  90674. }
  90675. if(0 == encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 0)
  90676. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90677. metadata_has_seektable = false;
  90678. metadata_has_vorbis_comment = false;
  90679. metadata_picture_has_type1 = false;
  90680. metadata_picture_has_type2 = false;
  90681. for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
  90682. const FLAC__StreamMetadata *m = encoder->protected_->metadata[i];
  90683. if(m->type == FLAC__METADATA_TYPE_STREAMINFO)
  90684. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90685. else if(m->type == FLAC__METADATA_TYPE_SEEKTABLE) {
  90686. if(metadata_has_seektable) /* only one is allowed */
  90687. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90688. metadata_has_seektable = true;
  90689. if(!FLAC__format_seektable_is_legal(&m->data.seek_table))
  90690. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90691. }
  90692. else if(m->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
  90693. if(metadata_has_vorbis_comment) /* only one is allowed */
  90694. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90695. metadata_has_vorbis_comment = true;
  90696. }
  90697. else if(m->type == FLAC__METADATA_TYPE_CUESHEET) {
  90698. if(!FLAC__format_cuesheet_is_legal(&m->data.cue_sheet, m->data.cue_sheet.is_cd, /*violation=*/0))
  90699. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90700. }
  90701. else if(m->type == FLAC__METADATA_TYPE_PICTURE) {
  90702. if(!FLAC__format_picture_is_legal(&m->data.picture, /*violation=*/0))
  90703. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90704. if(m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD) {
  90705. if(metadata_picture_has_type1) /* there should only be 1 per stream */
  90706. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90707. metadata_picture_has_type1 = true;
  90708. if(
  90709. m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD &&
  90710. (
  90711. (strcmp(m->data.picture.mime_type, "image/png") && strcmp(m->data.picture.mime_type, "-->")) ||
  90712. m->data.picture.width != 32 ||
  90713. m->data.picture.height != 32
  90714. )
  90715. )
  90716. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90717. }
  90718. else if(m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON) {
  90719. if(metadata_picture_has_type2) /* there should only be 1 per stream */
  90720. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90721. metadata_picture_has_type2 = true;
  90722. }
  90723. }
  90724. }
  90725. encoder->private_->input_capacity = 0;
  90726. for(i = 0; i < encoder->protected_->channels; i++) {
  90727. encoder->private_->integer_signal_unaligned[i] = encoder->private_->integer_signal[i] = 0;
  90728. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90729. encoder->private_->real_signal_unaligned[i] = encoder->private_->real_signal[i] = 0;
  90730. #endif
  90731. }
  90732. for(i = 0; i < 2; i++) {
  90733. encoder->private_->integer_signal_mid_side_unaligned[i] = encoder->private_->integer_signal_mid_side[i] = 0;
  90734. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90735. encoder->private_->real_signal_mid_side_unaligned[i] = encoder->private_->real_signal_mid_side[i] = 0;
  90736. #endif
  90737. }
  90738. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90739. for(i = 0; i < encoder->protected_->num_apodizations; i++)
  90740. encoder->private_->window_unaligned[i] = encoder->private_->window[i] = 0;
  90741. encoder->private_->windowed_signal_unaligned = encoder->private_->windowed_signal = 0;
  90742. #endif
  90743. for(i = 0; i < encoder->protected_->channels; i++) {
  90744. encoder->private_->residual_workspace_unaligned[i][0] = encoder->private_->residual_workspace[i][0] = 0;
  90745. encoder->private_->residual_workspace_unaligned[i][1] = encoder->private_->residual_workspace[i][1] = 0;
  90746. encoder->private_->best_subframe[i] = 0;
  90747. }
  90748. for(i = 0; i < 2; i++) {
  90749. encoder->private_->residual_workspace_mid_side_unaligned[i][0] = encoder->private_->residual_workspace_mid_side[i][0] = 0;
  90750. encoder->private_->residual_workspace_mid_side_unaligned[i][1] = encoder->private_->residual_workspace_mid_side[i][1] = 0;
  90751. encoder->private_->best_subframe_mid_side[i] = 0;
  90752. }
  90753. encoder->private_->abs_residual_partition_sums_unaligned = encoder->private_->abs_residual_partition_sums = 0;
  90754. encoder->private_->raw_bits_per_partition_unaligned = encoder->private_->raw_bits_per_partition = 0;
  90755. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90756. encoder->private_->loose_mid_side_stereo_frames = (unsigned)((FLAC__double)encoder->protected_->sample_rate * 0.4 / (FLAC__double)encoder->protected_->blocksize + 0.5);
  90757. #else
  90758. FLAC__ASSERT(FLAC__MAX_SAMPLE_RATE <= 655350);
  90759. FLAC__ASSERT(FLAC__MAX_BLOCK_SIZE <= 65535);
  90760. FLAC__ASSERT(encoder->protected_->sample_rate <= 655350);
  90761. FLAC__ASSERT(encoder->protected_->blocksize <= 65535);
  90762. 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);
  90763. #endif
  90764. if(encoder->private_->loose_mid_side_stereo_frames == 0)
  90765. encoder->private_->loose_mid_side_stereo_frames = 1;
  90766. encoder->private_->loose_mid_side_stereo_frame_count = 0;
  90767. encoder->private_->current_sample_number = 0;
  90768. encoder->private_->current_frame_number = 0;
  90769. encoder->private_->use_wide_by_block = (encoder->protected_->bits_per_sample + FLAC__bitmath_ilog2(encoder->protected_->blocksize)+1 > 30);
  90770. 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? */
  90771. encoder->private_->use_wide_by_partition = (false); /*@@@ need to set this */
  90772. FLAC__cpu_info(&encoder->private_->cpuinfo);
  90773. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90774. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation;
  90775. #endif
  90776. encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor;
  90777. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90778. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients;
  90779. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_64bit = FLAC__lpc_compute_residual_from_qlp_coefficients_wide;
  90780. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients;
  90781. #endif
  90782. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90783. # ifndef FLAC__NO_ASM
  90784. if(encoder->private_->cpuinfo.use_asm) {
  90785. # ifdef FLAC__CPU_IA32
  90786. FLAC__ASSERT(encoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_IA32);
  90787. # ifdef FLAC__HAS_NASM
  90788. if(encoder->private_->cpuinfo.data.ia32.sse) {
  90789. if(encoder->protected_->max_lpc_order < 4)
  90790. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_4;
  90791. else if(encoder->protected_->max_lpc_order < 8)
  90792. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_8;
  90793. else if(encoder->protected_->max_lpc_order < 12)
  90794. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_12;
  90795. else
  90796. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32;
  90797. }
  90798. else if(encoder->private_->cpuinfo.data.ia32._3dnow)
  90799. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_3dnow;
  90800. else
  90801. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32;
  90802. if(encoder->private_->cpuinfo.data.ia32.mmx) {
  90803. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
  90804. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32_mmx;
  90805. }
  90806. else {
  90807. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
  90808. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
  90809. }
  90810. if(encoder->private_->cpuinfo.data.ia32.mmx && encoder->private_->cpuinfo.data.ia32.cmov)
  90811. encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor_asm_ia32_mmx_cmov;
  90812. # endif /* FLAC__HAS_NASM */
  90813. # endif /* FLAC__CPU_IA32 */
  90814. }
  90815. # endif /* !FLAC__NO_ASM */
  90816. #endif /* !FLAC__INTEGER_ONLY_LIBRARY */
  90817. if(encoder->private_->use_wide_by_block) {
  90818. encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor_wide;
  90819. }
  90820. encoder->protected_->state = FLAC__STREAM_ENCODER_OK;
  90821. #if FLAC__HAS_OGG
  90822. encoder->private_->is_ogg = is_ogg;
  90823. if(is_ogg && !FLAC__ogg_encoder_aspect_init(&encoder->protected_->ogg_encoder_aspect)) {
  90824. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  90825. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90826. }
  90827. #endif
  90828. encoder->private_->read_callback = read_callback;
  90829. encoder->private_->write_callback = write_callback;
  90830. encoder->private_->seek_callback = seek_callback;
  90831. encoder->private_->tell_callback = tell_callback;
  90832. encoder->private_->metadata_callback = metadata_callback;
  90833. encoder->private_->client_data = client_data;
  90834. if(!resize_buffers_(encoder, encoder->protected_->blocksize)) {
  90835. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90836. }
  90837. if(!FLAC__bitwriter_init(encoder->private_->frame)) {
  90838. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  90839. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90840. }
  90841. if(encoder->protected_->verify) {
  90842. encoder->private_->verify.input_fifo.size = encoder->protected_->blocksize+OVERREAD_;
  90843. for(i = 0; i < encoder->protected_->channels; i++) {
  90844. 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))) {
  90845. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  90846. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90847. }
  90848. }
  90849. encoder->private_->verify.input_fifo.tail = 0;
  90850. encoder->private_->verify.decoder = FLAC__stream_decoder_new();
  90851. if(0 == encoder->private_->verify.decoder) {
  90852. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  90853. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90854. }
  90855. 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) {
  90856. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  90857. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90858. }
  90859. }
  90860. encoder->private_->verify.error_stats.absolute_sample = 0;
  90861. encoder->private_->verify.error_stats.frame_number = 0;
  90862. encoder->private_->verify.error_stats.channel = 0;
  90863. encoder->private_->verify.error_stats.sample = 0;
  90864. encoder->private_->verify.error_stats.expected = 0;
  90865. encoder->private_->verify.error_stats.got = 0;
  90866. encoder->private_->first_seekpoint_to_check = 0;
  90867. encoder->private_->samples_written = 0;
  90868. encoder->protected_->streaminfo_offset = 0;
  90869. encoder->protected_->seektable_offset = 0;
  90870. encoder->protected_->audio_offset = 0;
  90871. if(encoder->protected_->verify)
  90872. encoder->private_->verify.state_hint = ENCODER_IN_MAGIC;
  90873. if(!FLAC__bitwriter_write_raw_uint32(encoder->private_->frame, FLAC__STREAM_SYNC, FLAC__STREAM_SYNC_LEN)) {
  90874. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90875. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90876. }
  90877. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90878. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90879. }
  90880. if(encoder->protected_->verify)
  90881. encoder->private_->verify.state_hint = ENCODER_IN_METADATA;
  90882. encoder->private_->streaminfo.type = FLAC__METADATA_TYPE_STREAMINFO;
  90883. encoder->private_->streaminfo.is_last = false; /* we will have at a minimum a VORBIS_COMMENT afterwards */
  90884. encoder->private_->streaminfo.length = FLAC__STREAM_METADATA_STREAMINFO_LENGTH;
  90885. encoder->private_->streaminfo.data.stream_info.min_blocksize = encoder->protected_->blocksize; /* this encoder uses the same blocksize for the whole stream */
  90886. encoder->private_->streaminfo.data.stream_info.max_blocksize = encoder->protected_->blocksize;
  90887. encoder->private_->streaminfo.data.stream_info.min_framesize = 0; /* we don't know this yet; have to fill it in later */
  90888. encoder->private_->streaminfo.data.stream_info.max_framesize = 0; /* we don't know this yet; have to fill it in later */
  90889. encoder->private_->streaminfo.data.stream_info.sample_rate = encoder->protected_->sample_rate;
  90890. encoder->private_->streaminfo.data.stream_info.channels = encoder->protected_->channels;
  90891. encoder->private_->streaminfo.data.stream_info.bits_per_sample = encoder->protected_->bits_per_sample;
  90892. encoder->private_->streaminfo.data.stream_info.total_samples = encoder->protected_->total_samples_estimate; /* we will replace this later with the real total */
  90893. memset(encoder->private_->streaminfo.data.stream_info.md5sum, 0, 16); /* we don't know this yet; have to fill it in later */
  90894. if(encoder->protected_->do_md5)
  90895. FLAC__MD5Init(&encoder->private_->md5context);
  90896. if(!FLAC__add_metadata_block(&encoder->private_->streaminfo, encoder->private_->frame)) {
  90897. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90898. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90899. }
  90900. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90901. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90902. }
  90903. encoder->private_->streaminfo.data.stream_info.min_framesize = (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN) - 1;
  90904. encoder->private_->streaminfo.data.stream_info.total_samples = 0;
  90905. if(!metadata_has_vorbis_comment) {
  90906. FLAC__StreamMetadata vorbis_comment;
  90907. vorbis_comment.type = FLAC__METADATA_TYPE_VORBIS_COMMENT;
  90908. vorbis_comment.is_last = (encoder->protected_->num_metadata_blocks == 0);
  90909. vorbis_comment.length = 4 + 4; /* MAGIC NUMBER */
  90910. vorbis_comment.data.vorbis_comment.vendor_string.length = 0;
  90911. vorbis_comment.data.vorbis_comment.vendor_string.entry = 0;
  90912. vorbis_comment.data.vorbis_comment.num_comments = 0;
  90913. vorbis_comment.data.vorbis_comment.comments = 0;
  90914. if(!FLAC__add_metadata_block(&vorbis_comment, encoder->private_->frame)) {
  90915. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90916. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90917. }
  90918. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90919. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90920. }
  90921. }
  90922. for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
  90923. encoder->protected_->metadata[i]->is_last = (i == encoder->protected_->num_metadata_blocks - 1);
  90924. if(!FLAC__add_metadata_block(encoder->protected_->metadata[i], encoder->private_->frame)) {
  90925. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90926. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90927. }
  90928. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90929. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90930. }
  90931. }
  90932. 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 */
  90933. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  90934. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90935. }
  90936. if(encoder->protected_->verify)
  90937. encoder->private_->verify.state_hint = ENCODER_IN_AUDIO;
  90938. return FLAC__STREAM_ENCODER_INIT_STATUS_OK;
  90939. }
  90940. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_stream(
  90941. FLAC__StreamEncoder *encoder,
  90942. FLAC__StreamEncoderWriteCallback write_callback,
  90943. FLAC__StreamEncoderSeekCallback seek_callback,
  90944. FLAC__StreamEncoderTellCallback tell_callback,
  90945. FLAC__StreamEncoderMetadataCallback metadata_callback,
  90946. void *client_data
  90947. )
  90948. {
  90949. return init_stream_internal_enc(
  90950. encoder,
  90951. 0,
  90952. write_callback,
  90953. seek_callback,
  90954. tell_callback,
  90955. metadata_callback,
  90956. client_data,
  90957. false
  90958. );
  90959. }
  90960. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_stream(
  90961. FLAC__StreamEncoder *encoder,
  90962. FLAC__StreamEncoderReadCallback read_callback,
  90963. FLAC__StreamEncoderWriteCallback write_callback,
  90964. FLAC__StreamEncoderSeekCallback seek_callback,
  90965. FLAC__StreamEncoderTellCallback tell_callback,
  90966. FLAC__StreamEncoderMetadataCallback metadata_callback,
  90967. void *client_data
  90968. )
  90969. {
  90970. return init_stream_internal_enc(
  90971. encoder,
  90972. read_callback,
  90973. write_callback,
  90974. seek_callback,
  90975. tell_callback,
  90976. metadata_callback,
  90977. client_data,
  90978. true
  90979. );
  90980. }
  90981. static FLAC__StreamEncoderInitStatus init_FILE_internal_enc(
  90982. FLAC__StreamEncoder *encoder,
  90983. FILE *file,
  90984. FLAC__StreamEncoderProgressCallback progress_callback,
  90985. void *client_data,
  90986. FLAC__bool is_ogg
  90987. )
  90988. {
  90989. FLAC__StreamEncoderInitStatus init_status;
  90990. FLAC__ASSERT(0 != encoder);
  90991. FLAC__ASSERT(0 != file);
  90992. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90993. return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
  90994. if(file == 0) {
  90995. encoder->protected_->state = FLAC__STREAM_ENCODER_IO_ERROR;
  90996. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90997. }
  90998. if(file == stdout)
  90999. file = get_binary_stdout_(); /* just to be safe */
  91000. encoder->private_->file = file;
  91001. encoder->private_->progress_callback = progress_callback;
  91002. encoder->private_->bytes_written = 0;
  91003. encoder->private_->samples_written = 0;
  91004. encoder->private_->frames_written = 0;
  91005. init_status = init_stream_internal_enc(
  91006. encoder,
  91007. encoder->private_->file == stdout? 0 : is_ogg? file_read_callback_enc : 0,
  91008. file_write_callback_,
  91009. encoder->private_->file == stdout? 0 : file_seek_callback_enc,
  91010. encoder->private_->file == stdout? 0 : file_tell_callback_enc,
  91011. 0,
  91012. client_data,
  91013. is_ogg
  91014. );
  91015. if(init_status != FLAC__STREAM_ENCODER_INIT_STATUS_OK) {
  91016. return init_status;
  91017. }
  91018. {
  91019. unsigned blocksize = FLAC__stream_encoder_get_blocksize(encoder);
  91020. FLAC__ASSERT(blocksize != 0);
  91021. encoder->private_->total_frames_estimate = (unsigned)((FLAC__stream_encoder_get_total_samples_estimate(encoder) + blocksize - 1) / blocksize);
  91022. }
  91023. return init_status;
  91024. }
  91025. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE(
  91026. FLAC__StreamEncoder *encoder,
  91027. FILE *file,
  91028. FLAC__StreamEncoderProgressCallback progress_callback,
  91029. void *client_data
  91030. )
  91031. {
  91032. return init_FILE_internal_enc(encoder, file, progress_callback, client_data, /*is_ogg=*/false);
  91033. }
  91034. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_FILE(
  91035. FLAC__StreamEncoder *encoder,
  91036. FILE *file,
  91037. FLAC__StreamEncoderProgressCallback progress_callback,
  91038. void *client_data
  91039. )
  91040. {
  91041. return init_FILE_internal_enc(encoder, file, progress_callback, client_data, /*is_ogg=*/true);
  91042. }
  91043. static FLAC__StreamEncoderInitStatus init_file_internal_enc(
  91044. FLAC__StreamEncoder *encoder,
  91045. const char *filename,
  91046. FLAC__StreamEncoderProgressCallback progress_callback,
  91047. void *client_data,
  91048. FLAC__bool is_ogg
  91049. )
  91050. {
  91051. FILE *file;
  91052. FLAC__ASSERT(0 != encoder);
  91053. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91054. return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
  91055. file = filename? fopen(filename, "w+b") : stdout;
  91056. if(file == 0) {
  91057. encoder->protected_->state = FLAC__STREAM_ENCODER_IO_ERROR;
  91058. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  91059. }
  91060. return init_FILE_internal_enc(encoder, file, progress_callback, client_data, is_ogg);
  91061. }
  91062. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_file(
  91063. FLAC__StreamEncoder *encoder,
  91064. const char *filename,
  91065. FLAC__StreamEncoderProgressCallback progress_callback,
  91066. void *client_data
  91067. )
  91068. {
  91069. return init_file_internal_enc(encoder, filename, progress_callback, client_data, /*is_ogg=*/false);
  91070. }
  91071. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_file(
  91072. FLAC__StreamEncoder *encoder,
  91073. const char *filename,
  91074. FLAC__StreamEncoderProgressCallback progress_callback,
  91075. void *client_data
  91076. )
  91077. {
  91078. return init_file_internal_enc(encoder, filename, progress_callback, client_data, /*is_ogg=*/true);
  91079. }
  91080. FLAC_API FLAC__bool FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder)
  91081. {
  91082. FLAC__bool error = false;
  91083. FLAC__ASSERT(0 != encoder);
  91084. FLAC__ASSERT(0 != encoder->private_);
  91085. FLAC__ASSERT(0 != encoder->protected_);
  91086. if(encoder->protected_->state == FLAC__STREAM_ENCODER_UNINITIALIZED)
  91087. return true;
  91088. if(encoder->protected_->state == FLAC__STREAM_ENCODER_OK && !encoder->private_->is_being_deleted) {
  91089. if(encoder->private_->current_sample_number != 0) {
  91090. const FLAC__bool is_fractional_block = encoder->protected_->blocksize != encoder->private_->current_sample_number;
  91091. encoder->protected_->blocksize = encoder->private_->current_sample_number;
  91092. if(!process_frame_(encoder, is_fractional_block, /*is_last_block=*/true))
  91093. error = true;
  91094. }
  91095. }
  91096. if(encoder->protected_->do_md5)
  91097. FLAC__MD5Final(encoder->private_->streaminfo.data.stream_info.md5sum, &encoder->private_->md5context);
  91098. if(!encoder->private_->is_being_deleted) {
  91099. if(encoder->protected_->state == FLAC__STREAM_ENCODER_OK) {
  91100. if(encoder->private_->seek_callback) {
  91101. #if FLAC__HAS_OGG
  91102. if(encoder->private_->is_ogg)
  91103. update_ogg_metadata_(encoder);
  91104. else
  91105. #endif
  91106. update_metadata_(encoder);
  91107. if(encoder->protected_->state != FLAC__STREAM_ENCODER_OK)
  91108. error = true;
  91109. }
  91110. if(encoder->private_->metadata_callback)
  91111. encoder->private_->metadata_callback(encoder, &encoder->private_->streaminfo, encoder->private_->client_data);
  91112. }
  91113. if(encoder->protected_->verify && 0 != encoder->private_->verify.decoder && !FLAC__stream_decoder_finish(encoder->private_->verify.decoder)) {
  91114. if(!error)
  91115. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA;
  91116. error = true;
  91117. }
  91118. }
  91119. if(0 != encoder->private_->file) {
  91120. if(encoder->private_->file != stdout)
  91121. fclose(encoder->private_->file);
  91122. encoder->private_->file = 0;
  91123. }
  91124. #if FLAC__HAS_OGG
  91125. if(encoder->private_->is_ogg)
  91126. FLAC__ogg_encoder_aspect_finish(&encoder->protected_->ogg_encoder_aspect);
  91127. #endif
  91128. free_(encoder);
  91129. set_defaults_enc(encoder);
  91130. if(!error)
  91131. encoder->protected_->state = FLAC__STREAM_ENCODER_UNINITIALIZED;
  91132. return !error;
  91133. }
  91134. FLAC_API FLAC__bool FLAC__stream_encoder_set_ogg_serial_number(FLAC__StreamEncoder *encoder, long value)
  91135. {
  91136. FLAC__ASSERT(0 != encoder);
  91137. FLAC__ASSERT(0 != encoder->private_);
  91138. FLAC__ASSERT(0 != encoder->protected_);
  91139. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91140. return false;
  91141. #if FLAC__HAS_OGG
  91142. FLAC__ogg_encoder_aspect_set_serial_number(&encoder->protected_->ogg_encoder_aspect, value);
  91143. return true;
  91144. #else
  91145. (void)value;
  91146. return false;
  91147. #endif
  91148. }
  91149. FLAC_API FLAC__bool FLAC__stream_encoder_set_verify(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91150. {
  91151. FLAC__ASSERT(0 != encoder);
  91152. FLAC__ASSERT(0 != encoder->private_);
  91153. FLAC__ASSERT(0 != encoder->protected_);
  91154. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91155. return false;
  91156. #ifndef FLAC__MANDATORY_VERIFY_WHILE_ENCODING
  91157. encoder->protected_->verify = value;
  91158. #endif
  91159. return true;
  91160. }
  91161. FLAC_API FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91162. {
  91163. FLAC__ASSERT(0 != encoder);
  91164. FLAC__ASSERT(0 != encoder->private_);
  91165. FLAC__ASSERT(0 != encoder->protected_);
  91166. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91167. return false;
  91168. encoder->protected_->streamable_subset = value;
  91169. return true;
  91170. }
  91171. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_md5(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91172. {
  91173. FLAC__ASSERT(0 != encoder);
  91174. FLAC__ASSERT(0 != encoder->private_);
  91175. FLAC__ASSERT(0 != encoder->protected_);
  91176. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91177. return false;
  91178. encoder->protected_->do_md5 = value;
  91179. return true;
  91180. }
  91181. FLAC_API FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encoder, unsigned value)
  91182. {
  91183. FLAC__ASSERT(0 != encoder);
  91184. FLAC__ASSERT(0 != encoder->private_);
  91185. FLAC__ASSERT(0 != encoder->protected_);
  91186. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91187. return false;
  91188. encoder->protected_->channels = value;
  91189. return true;
  91190. }
  91191. FLAC_API FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder *encoder, unsigned value)
  91192. {
  91193. FLAC__ASSERT(0 != encoder);
  91194. FLAC__ASSERT(0 != encoder->private_);
  91195. FLAC__ASSERT(0 != encoder->protected_);
  91196. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91197. return false;
  91198. encoder->protected_->bits_per_sample = value;
  91199. return true;
  91200. }
  91201. FLAC_API FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *encoder, unsigned value)
  91202. {
  91203. FLAC__ASSERT(0 != encoder);
  91204. FLAC__ASSERT(0 != encoder->private_);
  91205. FLAC__ASSERT(0 != encoder->protected_);
  91206. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91207. return false;
  91208. encoder->protected_->sample_rate = value;
  91209. return true;
  91210. }
  91211. FLAC_API FLAC__bool FLAC__stream_encoder_set_compression_level(FLAC__StreamEncoder *encoder, unsigned value)
  91212. {
  91213. FLAC__bool ok = true;
  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. if(value >= sizeof(compression_levels_)/sizeof(compression_levels_[0]))
  91220. value = sizeof(compression_levels_)/sizeof(compression_levels_[0]) - 1;
  91221. ok &= FLAC__stream_encoder_set_do_mid_side_stereo (encoder, compression_levels_[value].do_mid_side_stereo);
  91222. ok &= FLAC__stream_encoder_set_loose_mid_side_stereo (encoder, compression_levels_[value].loose_mid_side_stereo);
  91223. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91224. #if 0
  91225. ok &= FLAC__stream_encoder_set_apodization (encoder, compression_levels_[value].apodization);
  91226. #else
  91227. encoder->protected_->num_apodizations = 1;
  91228. encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
  91229. encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
  91230. #endif
  91231. #endif
  91232. ok &= FLAC__stream_encoder_set_max_lpc_order (encoder, compression_levels_[value].max_lpc_order);
  91233. ok &= FLAC__stream_encoder_set_qlp_coeff_precision (encoder, compression_levels_[value].qlp_coeff_precision);
  91234. ok &= FLAC__stream_encoder_set_do_qlp_coeff_prec_search (encoder, compression_levels_[value].do_qlp_coeff_prec_search);
  91235. ok &= FLAC__stream_encoder_set_do_escape_coding (encoder, compression_levels_[value].do_escape_coding);
  91236. ok &= FLAC__stream_encoder_set_do_exhaustive_model_search (encoder, compression_levels_[value].do_exhaustive_model_search);
  91237. ok &= FLAC__stream_encoder_set_min_residual_partition_order(encoder, compression_levels_[value].min_residual_partition_order);
  91238. ok &= FLAC__stream_encoder_set_max_residual_partition_order(encoder, compression_levels_[value].max_residual_partition_order);
  91239. ok &= FLAC__stream_encoder_set_rice_parameter_search_dist (encoder, compression_levels_[value].rice_parameter_search_dist);
  91240. return ok;
  91241. }
  91242. FLAC_API FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, unsigned value)
  91243. {
  91244. FLAC__ASSERT(0 != encoder);
  91245. FLAC__ASSERT(0 != encoder->private_);
  91246. FLAC__ASSERT(0 != encoder->protected_);
  91247. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91248. return false;
  91249. encoder->protected_->blocksize = value;
  91250. return true;
  91251. }
  91252. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91253. {
  91254. FLAC__ASSERT(0 != encoder);
  91255. FLAC__ASSERT(0 != encoder->private_);
  91256. FLAC__ASSERT(0 != encoder->protected_);
  91257. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91258. return false;
  91259. encoder->protected_->do_mid_side_stereo = value;
  91260. return true;
  91261. }
  91262. FLAC_API FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91263. {
  91264. FLAC__ASSERT(0 != encoder);
  91265. FLAC__ASSERT(0 != encoder->private_);
  91266. FLAC__ASSERT(0 != encoder->protected_);
  91267. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91268. return false;
  91269. encoder->protected_->loose_mid_side_stereo = value;
  91270. return true;
  91271. }
  91272. FLAC_API FLAC__bool FLAC__stream_encoder_set_apodization(FLAC__StreamEncoder *encoder, const char *specification)
  91273. {
  91274. FLAC__ASSERT(0 != encoder);
  91275. FLAC__ASSERT(0 != encoder->private_);
  91276. FLAC__ASSERT(0 != encoder->protected_);
  91277. FLAC__ASSERT(0 != specification);
  91278. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91279. return false;
  91280. #ifdef FLAC__INTEGER_ONLY_LIBRARY
  91281. (void)specification; /* silently ignore since we haven't integerized; will always use a rectangular window */
  91282. #else
  91283. encoder->protected_->num_apodizations = 0;
  91284. while(1) {
  91285. const char *s = strchr(specification, ';');
  91286. const size_t n = s? (size_t)(s - specification) : strlen(specification);
  91287. if (n==8 && 0 == strncmp("bartlett" , specification, n))
  91288. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BARTLETT;
  91289. else if(n==13 && 0 == strncmp("bartlett_hann", specification, n))
  91290. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BARTLETT_HANN;
  91291. else if(n==8 && 0 == strncmp("blackman" , specification, n))
  91292. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BLACKMAN;
  91293. else if(n==26 && 0 == strncmp("blackman_harris_4term_92db", specification, n))
  91294. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE;
  91295. else if(n==6 && 0 == strncmp("connes" , specification, n))
  91296. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_CONNES;
  91297. else if(n==7 && 0 == strncmp("flattop" , specification, n))
  91298. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_FLATTOP;
  91299. else if(n>7 && 0 == strncmp("gauss(" , specification, 6)) {
  91300. FLAC__real stddev = (FLAC__real)strtod(specification+6, 0);
  91301. if (stddev > 0.0 && stddev <= 0.5) {
  91302. encoder->protected_->apodizations[encoder->protected_->num_apodizations].parameters.gauss.stddev = stddev;
  91303. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_GAUSS;
  91304. }
  91305. }
  91306. else if(n==7 && 0 == strncmp("hamming" , specification, n))
  91307. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_HAMMING;
  91308. else if(n==4 && 0 == strncmp("hann" , specification, n))
  91309. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_HANN;
  91310. else if(n==13 && 0 == strncmp("kaiser_bessel", specification, n))
  91311. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_KAISER_BESSEL;
  91312. else if(n==7 && 0 == strncmp("nuttall" , specification, n))
  91313. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_NUTTALL;
  91314. else if(n==9 && 0 == strncmp("rectangle" , specification, n))
  91315. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_RECTANGLE;
  91316. else if(n==8 && 0 == strncmp("triangle" , specification, n))
  91317. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_TRIANGLE;
  91318. else if(n>7 && 0 == strncmp("tukey(" , specification, 6)) {
  91319. FLAC__real p = (FLAC__real)strtod(specification+6, 0);
  91320. if (p >= 0.0 && p <= 1.0) {
  91321. encoder->protected_->apodizations[encoder->protected_->num_apodizations].parameters.tukey.p = p;
  91322. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_TUKEY;
  91323. }
  91324. }
  91325. else if(n==5 && 0 == strncmp("welch" , specification, n))
  91326. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_WELCH;
  91327. if (encoder->protected_->num_apodizations == 32)
  91328. break;
  91329. if (s)
  91330. specification = s+1;
  91331. else
  91332. break;
  91333. }
  91334. if(encoder->protected_->num_apodizations == 0) {
  91335. encoder->protected_->num_apodizations = 1;
  91336. encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
  91337. encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
  91338. }
  91339. #endif
  91340. return true;
  91341. }
  91342. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_lpc_order(FLAC__StreamEncoder *encoder, unsigned value)
  91343. {
  91344. FLAC__ASSERT(0 != encoder);
  91345. FLAC__ASSERT(0 != encoder->private_);
  91346. FLAC__ASSERT(0 != encoder->protected_);
  91347. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91348. return false;
  91349. encoder->protected_->max_lpc_order = value;
  91350. return true;
  91351. }
  91352. FLAC_API FLAC__bool FLAC__stream_encoder_set_qlp_coeff_precision(FLAC__StreamEncoder *encoder, unsigned value)
  91353. {
  91354. FLAC__ASSERT(0 != encoder);
  91355. FLAC__ASSERT(0 != encoder->private_);
  91356. FLAC__ASSERT(0 != encoder->protected_);
  91357. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91358. return false;
  91359. encoder->protected_->qlp_coeff_precision = value;
  91360. return true;
  91361. }
  91362. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_qlp_coeff_prec_search(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91363. {
  91364. FLAC__ASSERT(0 != encoder);
  91365. FLAC__ASSERT(0 != encoder->private_);
  91366. FLAC__ASSERT(0 != encoder->protected_);
  91367. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91368. return false;
  91369. encoder->protected_->do_qlp_coeff_prec_search = value;
  91370. return true;
  91371. }
  91372. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_escape_coding(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91373. {
  91374. FLAC__ASSERT(0 != encoder);
  91375. FLAC__ASSERT(0 != encoder->private_);
  91376. FLAC__ASSERT(0 != encoder->protected_);
  91377. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91378. return false;
  91379. #if 0
  91380. encoder->protected_->do_escape_coding = value;
  91381. #else
  91382. (void)value;
  91383. #endif
  91384. return true;
  91385. }
  91386. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_exhaustive_model_search(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91387. {
  91388. FLAC__ASSERT(0 != encoder);
  91389. FLAC__ASSERT(0 != encoder->private_);
  91390. FLAC__ASSERT(0 != encoder->protected_);
  91391. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91392. return false;
  91393. encoder->protected_->do_exhaustive_model_search = value;
  91394. return true;
  91395. }
  91396. FLAC_API FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value)
  91397. {
  91398. FLAC__ASSERT(0 != encoder);
  91399. FLAC__ASSERT(0 != encoder->private_);
  91400. FLAC__ASSERT(0 != encoder->protected_);
  91401. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91402. return false;
  91403. encoder->protected_->min_residual_partition_order = value;
  91404. return true;
  91405. }
  91406. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value)
  91407. {
  91408. FLAC__ASSERT(0 != encoder);
  91409. FLAC__ASSERT(0 != encoder->private_);
  91410. FLAC__ASSERT(0 != encoder->protected_);
  91411. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91412. return false;
  91413. encoder->protected_->max_residual_partition_order = value;
  91414. return true;
  91415. }
  91416. FLAC_API FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__StreamEncoder *encoder, unsigned value)
  91417. {
  91418. FLAC__ASSERT(0 != encoder);
  91419. FLAC__ASSERT(0 != encoder->private_);
  91420. FLAC__ASSERT(0 != encoder->protected_);
  91421. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91422. return false;
  91423. #if 0
  91424. encoder->protected_->rice_parameter_search_dist = value;
  91425. #else
  91426. (void)value;
  91427. #endif
  91428. return true;
  91429. }
  91430. FLAC_API FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__StreamEncoder *encoder, FLAC__uint64 value)
  91431. {
  91432. FLAC__ASSERT(0 != encoder);
  91433. FLAC__ASSERT(0 != encoder->private_);
  91434. FLAC__ASSERT(0 != encoder->protected_);
  91435. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91436. return false;
  91437. encoder->protected_->total_samples_estimate = value;
  91438. return true;
  91439. }
  91440. FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks)
  91441. {
  91442. FLAC__ASSERT(0 != encoder);
  91443. FLAC__ASSERT(0 != encoder->private_);
  91444. FLAC__ASSERT(0 != encoder->protected_);
  91445. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91446. return false;
  91447. if(0 == metadata)
  91448. num_blocks = 0;
  91449. if(0 == num_blocks)
  91450. metadata = 0;
  91451. if(encoder->protected_->metadata) {
  91452. free(encoder->protected_->metadata);
  91453. encoder->protected_->metadata = 0;
  91454. encoder->protected_->num_metadata_blocks = 0;
  91455. }
  91456. if(num_blocks) {
  91457. FLAC__StreamMetadata **m;
  91458. if(0 == (m = (FLAC__StreamMetadata**)safe_malloc_mul_2op_(sizeof(m[0]), /*times*/num_blocks)))
  91459. return false;
  91460. memcpy(m, metadata, sizeof(m[0]) * num_blocks);
  91461. encoder->protected_->metadata = m;
  91462. encoder->protected_->num_metadata_blocks = num_blocks;
  91463. }
  91464. #if FLAC__HAS_OGG
  91465. if(!FLAC__ogg_encoder_aspect_set_num_metadata(&encoder->protected_->ogg_encoder_aspect, num_blocks))
  91466. return false;
  91467. #endif
  91468. return true;
  91469. }
  91470. FLAC_API FLAC__bool FLAC__stream_encoder_disable_constant_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91471. {
  91472. FLAC__ASSERT(0 != encoder);
  91473. FLAC__ASSERT(0 != encoder->private_);
  91474. FLAC__ASSERT(0 != encoder->protected_);
  91475. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91476. return false;
  91477. encoder->private_->disable_constant_subframes = value;
  91478. return true;
  91479. }
  91480. FLAC_API FLAC__bool FLAC__stream_encoder_disable_fixed_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91481. {
  91482. FLAC__ASSERT(0 != encoder);
  91483. FLAC__ASSERT(0 != encoder->private_);
  91484. FLAC__ASSERT(0 != encoder->protected_);
  91485. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91486. return false;
  91487. encoder->private_->disable_fixed_subframes = value;
  91488. return true;
  91489. }
  91490. FLAC_API FLAC__bool FLAC__stream_encoder_disable_verbatim_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91491. {
  91492. FLAC__ASSERT(0 != encoder);
  91493. FLAC__ASSERT(0 != encoder->private_);
  91494. FLAC__ASSERT(0 != encoder->protected_);
  91495. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91496. return false;
  91497. encoder->private_->disable_verbatim_subframes = value;
  91498. return true;
  91499. }
  91500. FLAC_API FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder)
  91501. {
  91502. FLAC__ASSERT(0 != encoder);
  91503. FLAC__ASSERT(0 != encoder->private_);
  91504. FLAC__ASSERT(0 != encoder->protected_);
  91505. return encoder->protected_->state;
  91506. }
  91507. FLAC_API FLAC__StreamDecoderState FLAC__stream_encoder_get_verify_decoder_state(const FLAC__StreamEncoder *encoder)
  91508. {
  91509. FLAC__ASSERT(0 != encoder);
  91510. FLAC__ASSERT(0 != encoder->private_);
  91511. FLAC__ASSERT(0 != encoder->protected_);
  91512. if(encoder->protected_->verify)
  91513. return FLAC__stream_decoder_get_state(encoder->private_->verify.decoder);
  91514. else
  91515. return FLAC__STREAM_DECODER_UNINITIALIZED;
  91516. }
  91517. FLAC_API const char *FLAC__stream_encoder_get_resolved_state_string(const FLAC__StreamEncoder *encoder)
  91518. {
  91519. FLAC__ASSERT(0 != encoder);
  91520. FLAC__ASSERT(0 != encoder->private_);
  91521. FLAC__ASSERT(0 != encoder->protected_);
  91522. if(encoder->protected_->state != FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR)
  91523. return FLAC__StreamEncoderStateString[encoder->protected_->state];
  91524. else
  91525. return FLAC__stream_decoder_get_resolved_state_string(encoder->private_->verify.decoder);
  91526. }
  91527. 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)
  91528. {
  91529. FLAC__ASSERT(0 != encoder);
  91530. FLAC__ASSERT(0 != encoder->private_);
  91531. FLAC__ASSERT(0 != encoder->protected_);
  91532. if(0 != absolute_sample)
  91533. *absolute_sample = encoder->private_->verify.error_stats.absolute_sample;
  91534. if(0 != frame_number)
  91535. *frame_number = encoder->private_->verify.error_stats.frame_number;
  91536. if(0 != channel)
  91537. *channel = encoder->private_->verify.error_stats.channel;
  91538. if(0 != sample)
  91539. *sample = encoder->private_->verify.error_stats.sample;
  91540. if(0 != expected)
  91541. *expected = encoder->private_->verify.error_stats.expected;
  91542. if(0 != got)
  91543. *got = encoder->private_->verify.error_stats.got;
  91544. }
  91545. FLAC_API FLAC__bool FLAC__stream_encoder_get_verify(const FLAC__StreamEncoder *encoder)
  91546. {
  91547. FLAC__ASSERT(0 != encoder);
  91548. FLAC__ASSERT(0 != encoder->private_);
  91549. FLAC__ASSERT(0 != encoder->protected_);
  91550. return encoder->protected_->verify;
  91551. }
  91552. FLAC_API FLAC__bool FLAC__stream_encoder_get_streamable_subset(const FLAC__StreamEncoder *encoder)
  91553. {
  91554. FLAC__ASSERT(0 != encoder);
  91555. FLAC__ASSERT(0 != encoder->private_);
  91556. FLAC__ASSERT(0 != encoder->protected_);
  91557. return encoder->protected_->streamable_subset;
  91558. }
  91559. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_md5(const FLAC__StreamEncoder *encoder)
  91560. {
  91561. FLAC__ASSERT(0 != encoder);
  91562. FLAC__ASSERT(0 != encoder->private_);
  91563. FLAC__ASSERT(0 != encoder->protected_);
  91564. return encoder->protected_->do_md5;
  91565. }
  91566. FLAC_API unsigned FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder)
  91567. {
  91568. FLAC__ASSERT(0 != encoder);
  91569. FLAC__ASSERT(0 != encoder->private_);
  91570. FLAC__ASSERT(0 != encoder->protected_);
  91571. return encoder->protected_->channels;
  91572. }
  91573. FLAC_API unsigned FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder)
  91574. {
  91575. FLAC__ASSERT(0 != encoder);
  91576. FLAC__ASSERT(0 != encoder->private_);
  91577. FLAC__ASSERT(0 != encoder->protected_);
  91578. return encoder->protected_->bits_per_sample;
  91579. }
  91580. FLAC_API unsigned FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder)
  91581. {
  91582. FLAC__ASSERT(0 != encoder);
  91583. FLAC__ASSERT(0 != encoder->private_);
  91584. FLAC__ASSERT(0 != encoder->protected_);
  91585. return encoder->protected_->sample_rate;
  91586. }
  91587. FLAC_API unsigned FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder)
  91588. {
  91589. FLAC__ASSERT(0 != encoder);
  91590. FLAC__ASSERT(0 != encoder->private_);
  91591. FLAC__ASSERT(0 != encoder->protected_);
  91592. return encoder->protected_->blocksize;
  91593. }
  91594. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder)
  91595. {
  91596. FLAC__ASSERT(0 != encoder);
  91597. FLAC__ASSERT(0 != encoder->private_);
  91598. FLAC__ASSERT(0 != encoder->protected_);
  91599. return encoder->protected_->do_mid_side_stereo;
  91600. }
  91601. FLAC_API FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder)
  91602. {
  91603. FLAC__ASSERT(0 != encoder);
  91604. FLAC__ASSERT(0 != encoder->private_);
  91605. FLAC__ASSERT(0 != encoder->protected_);
  91606. return encoder->protected_->loose_mid_side_stereo;
  91607. }
  91608. FLAC_API unsigned FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder)
  91609. {
  91610. FLAC__ASSERT(0 != encoder);
  91611. FLAC__ASSERT(0 != encoder->private_);
  91612. FLAC__ASSERT(0 != encoder->protected_);
  91613. return encoder->protected_->max_lpc_order;
  91614. }
  91615. FLAC_API unsigned FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder)
  91616. {
  91617. FLAC__ASSERT(0 != encoder);
  91618. FLAC__ASSERT(0 != encoder->private_);
  91619. FLAC__ASSERT(0 != encoder->protected_);
  91620. return encoder->protected_->qlp_coeff_precision;
  91621. }
  91622. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder)
  91623. {
  91624. FLAC__ASSERT(0 != encoder);
  91625. FLAC__ASSERT(0 != encoder->private_);
  91626. FLAC__ASSERT(0 != encoder->protected_);
  91627. return encoder->protected_->do_qlp_coeff_prec_search;
  91628. }
  91629. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_escape_coding(const FLAC__StreamEncoder *encoder)
  91630. {
  91631. FLAC__ASSERT(0 != encoder);
  91632. FLAC__ASSERT(0 != encoder->private_);
  91633. FLAC__ASSERT(0 != encoder->protected_);
  91634. return encoder->protected_->do_escape_coding;
  91635. }
  91636. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder)
  91637. {
  91638. FLAC__ASSERT(0 != encoder);
  91639. FLAC__ASSERT(0 != encoder->private_);
  91640. FLAC__ASSERT(0 != encoder->protected_);
  91641. return encoder->protected_->do_exhaustive_model_search;
  91642. }
  91643. FLAC_API unsigned FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder *encoder)
  91644. {
  91645. FLAC__ASSERT(0 != encoder);
  91646. FLAC__ASSERT(0 != encoder->private_);
  91647. FLAC__ASSERT(0 != encoder->protected_);
  91648. return encoder->protected_->min_residual_partition_order;
  91649. }
  91650. FLAC_API unsigned FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder *encoder)
  91651. {
  91652. FLAC__ASSERT(0 != encoder);
  91653. FLAC__ASSERT(0 != encoder->private_);
  91654. FLAC__ASSERT(0 != encoder->protected_);
  91655. return encoder->protected_->max_residual_partition_order;
  91656. }
  91657. FLAC_API unsigned FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder)
  91658. {
  91659. FLAC__ASSERT(0 != encoder);
  91660. FLAC__ASSERT(0 != encoder->private_);
  91661. FLAC__ASSERT(0 != encoder->protected_);
  91662. return encoder->protected_->rice_parameter_search_dist;
  91663. }
  91664. FLAC_API FLAC__uint64 FLAC__stream_encoder_get_total_samples_estimate(const FLAC__StreamEncoder *encoder)
  91665. {
  91666. FLAC__ASSERT(0 != encoder);
  91667. FLAC__ASSERT(0 != encoder->private_);
  91668. FLAC__ASSERT(0 != encoder->protected_);
  91669. return encoder->protected_->total_samples_estimate;
  91670. }
  91671. FLAC_API FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples)
  91672. {
  91673. unsigned i, j = 0, channel;
  91674. const unsigned channels = encoder->protected_->channels, blocksize = encoder->protected_->blocksize;
  91675. FLAC__ASSERT(0 != encoder);
  91676. FLAC__ASSERT(0 != encoder->private_);
  91677. FLAC__ASSERT(0 != encoder->protected_);
  91678. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91679. do {
  91680. const unsigned n = min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j);
  91681. if(encoder->protected_->verify)
  91682. append_to_verify_fifo_(&encoder->private_->verify.input_fifo, buffer, j, channels, n);
  91683. for(channel = 0; channel < channels; channel++)
  91684. memcpy(&encoder->private_->integer_signal[channel][encoder->private_->current_sample_number], &buffer[channel][j], sizeof(buffer[channel][0]) * n);
  91685. if(encoder->protected_->do_mid_side_stereo) {
  91686. FLAC__ASSERT(channels == 2);
  91687. for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
  91688. encoder->private_->integer_signal_mid_side[1][i] = buffer[0][j] - buffer[1][j];
  91689. 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' ! */
  91690. }
  91691. }
  91692. else
  91693. j += n;
  91694. encoder->private_->current_sample_number += n;
  91695. if(encoder->private_->current_sample_number > blocksize) {
  91696. FLAC__ASSERT(encoder->private_->current_sample_number == blocksize+OVERREAD_);
  91697. FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
  91698. if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
  91699. return false;
  91700. for(channel = 0; channel < channels; channel++)
  91701. encoder->private_->integer_signal[channel][0] = encoder->private_->integer_signal[channel][blocksize];
  91702. if(encoder->protected_->do_mid_side_stereo) {
  91703. encoder->private_->integer_signal_mid_side[0][0] = encoder->private_->integer_signal_mid_side[0][blocksize];
  91704. encoder->private_->integer_signal_mid_side[1][0] = encoder->private_->integer_signal_mid_side[1][blocksize];
  91705. }
  91706. encoder->private_->current_sample_number = 1;
  91707. }
  91708. } while(j < samples);
  91709. return true;
  91710. }
  91711. FLAC_API FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], unsigned samples)
  91712. {
  91713. unsigned i, j, k, channel;
  91714. FLAC__int32 x, mid, side;
  91715. const unsigned channels = encoder->protected_->channels, blocksize = encoder->protected_->blocksize;
  91716. FLAC__ASSERT(0 != encoder);
  91717. FLAC__ASSERT(0 != encoder->private_);
  91718. FLAC__ASSERT(0 != encoder->protected_);
  91719. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91720. j = k = 0;
  91721. if(encoder->protected_->do_mid_side_stereo && channels == 2) {
  91722. do {
  91723. if(encoder->protected_->verify)
  91724. append_to_verify_fifo_interleaved_(&encoder->private_->verify.input_fifo, buffer, j, channels, min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j));
  91725. for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
  91726. encoder->private_->integer_signal[0][i] = mid = side = buffer[k++];
  91727. x = buffer[k++];
  91728. encoder->private_->integer_signal[1][i] = x;
  91729. mid += x;
  91730. side -= x;
  91731. mid >>= 1; /* NOTE: not the same as 'mid = (left + right) / 2' ! */
  91732. encoder->private_->integer_signal_mid_side[1][i] = side;
  91733. encoder->private_->integer_signal_mid_side[0][i] = mid;
  91734. }
  91735. encoder->private_->current_sample_number = i;
  91736. if(i > blocksize) {
  91737. if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
  91738. return false;
  91739. /* move unprocessed overread samples to beginnings of arrays */
  91740. FLAC__ASSERT(i == blocksize+OVERREAD_);
  91741. FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
  91742. encoder->private_->integer_signal[0][0] = encoder->private_->integer_signal[0][blocksize];
  91743. encoder->private_->integer_signal[1][0] = encoder->private_->integer_signal[1][blocksize];
  91744. encoder->private_->integer_signal_mid_side[0][0] = encoder->private_->integer_signal_mid_side[0][blocksize];
  91745. encoder->private_->integer_signal_mid_side[1][0] = encoder->private_->integer_signal_mid_side[1][blocksize];
  91746. encoder->private_->current_sample_number = 1;
  91747. }
  91748. } while(j < samples);
  91749. }
  91750. else {
  91751. do {
  91752. if(encoder->protected_->verify)
  91753. append_to_verify_fifo_interleaved_(&encoder->private_->verify.input_fifo, buffer, j, channels, min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j));
  91754. for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
  91755. for(channel = 0; channel < channels; channel++)
  91756. encoder->private_->integer_signal[channel][i] = buffer[k++];
  91757. }
  91758. encoder->private_->current_sample_number = i;
  91759. if(i > blocksize) {
  91760. if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
  91761. return false;
  91762. /* move unprocessed overread samples to beginnings of arrays */
  91763. FLAC__ASSERT(i == blocksize+OVERREAD_);
  91764. FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
  91765. for(channel = 0; channel < channels; channel++)
  91766. encoder->private_->integer_signal[channel][0] = encoder->private_->integer_signal[channel][blocksize];
  91767. encoder->private_->current_sample_number = 1;
  91768. }
  91769. } while(j < samples);
  91770. }
  91771. return true;
  91772. }
  91773. void set_defaults_enc(FLAC__StreamEncoder *encoder)
  91774. {
  91775. FLAC__ASSERT(0 != encoder);
  91776. #ifdef FLAC__MANDATORY_VERIFY_WHILE_ENCODING
  91777. encoder->protected_->verify = true;
  91778. #else
  91779. encoder->protected_->verify = false;
  91780. #endif
  91781. encoder->protected_->streamable_subset = true;
  91782. encoder->protected_->do_md5 = true;
  91783. encoder->protected_->do_mid_side_stereo = false;
  91784. encoder->protected_->loose_mid_side_stereo = false;
  91785. encoder->protected_->channels = 2;
  91786. encoder->protected_->bits_per_sample = 16;
  91787. encoder->protected_->sample_rate = 44100;
  91788. encoder->protected_->blocksize = 0;
  91789. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91790. encoder->protected_->num_apodizations = 1;
  91791. encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
  91792. encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
  91793. #endif
  91794. encoder->protected_->max_lpc_order = 0;
  91795. encoder->protected_->qlp_coeff_precision = 0;
  91796. encoder->protected_->do_qlp_coeff_prec_search = false;
  91797. encoder->protected_->do_exhaustive_model_search = false;
  91798. encoder->protected_->do_escape_coding = false;
  91799. encoder->protected_->min_residual_partition_order = 0;
  91800. encoder->protected_->max_residual_partition_order = 0;
  91801. encoder->protected_->rice_parameter_search_dist = 0;
  91802. encoder->protected_->total_samples_estimate = 0;
  91803. encoder->protected_->metadata = 0;
  91804. encoder->protected_->num_metadata_blocks = 0;
  91805. encoder->private_->seek_table = 0;
  91806. encoder->private_->disable_constant_subframes = false;
  91807. encoder->private_->disable_fixed_subframes = false;
  91808. encoder->private_->disable_verbatim_subframes = false;
  91809. #if FLAC__HAS_OGG
  91810. encoder->private_->is_ogg = false;
  91811. #endif
  91812. encoder->private_->read_callback = 0;
  91813. encoder->private_->write_callback = 0;
  91814. encoder->private_->seek_callback = 0;
  91815. encoder->private_->tell_callback = 0;
  91816. encoder->private_->metadata_callback = 0;
  91817. encoder->private_->progress_callback = 0;
  91818. encoder->private_->client_data = 0;
  91819. #if FLAC__HAS_OGG
  91820. FLAC__ogg_encoder_aspect_set_defaults(&encoder->protected_->ogg_encoder_aspect);
  91821. #endif
  91822. }
  91823. void free_(FLAC__StreamEncoder *encoder)
  91824. {
  91825. unsigned i, channel;
  91826. FLAC__ASSERT(0 != encoder);
  91827. if(encoder->protected_->metadata) {
  91828. free(encoder->protected_->metadata);
  91829. encoder->protected_->metadata = 0;
  91830. encoder->protected_->num_metadata_blocks = 0;
  91831. }
  91832. for(i = 0; i < encoder->protected_->channels; i++) {
  91833. if(0 != encoder->private_->integer_signal_unaligned[i]) {
  91834. free(encoder->private_->integer_signal_unaligned[i]);
  91835. encoder->private_->integer_signal_unaligned[i] = 0;
  91836. }
  91837. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91838. if(0 != encoder->private_->real_signal_unaligned[i]) {
  91839. free(encoder->private_->real_signal_unaligned[i]);
  91840. encoder->private_->real_signal_unaligned[i] = 0;
  91841. }
  91842. #endif
  91843. }
  91844. for(i = 0; i < 2; i++) {
  91845. if(0 != encoder->private_->integer_signal_mid_side_unaligned[i]) {
  91846. free(encoder->private_->integer_signal_mid_side_unaligned[i]);
  91847. encoder->private_->integer_signal_mid_side_unaligned[i] = 0;
  91848. }
  91849. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91850. if(0 != encoder->private_->real_signal_mid_side_unaligned[i]) {
  91851. free(encoder->private_->real_signal_mid_side_unaligned[i]);
  91852. encoder->private_->real_signal_mid_side_unaligned[i] = 0;
  91853. }
  91854. #endif
  91855. }
  91856. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91857. for(i = 0; i < encoder->protected_->num_apodizations; i++) {
  91858. if(0 != encoder->private_->window_unaligned[i]) {
  91859. free(encoder->private_->window_unaligned[i]);
  91860. encoder->private_->window_unaligned[i] = 0;
  91861. }
  91862. }
  91863. if(0 != encoder->private_->windowed_signal_unaligned) {
  91864. free(encoder->private_->windowed_signal_unaligned);
  91865. encoder->private_->windowed_signal_unaligned = 0;
  91866. }
  91867. #endif
  91868. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  91869. for(i = 0; i < 2; i++) {
  91870. if(0 != encoder->private_->residual_workspace_unaligned[channel][i]) {
  91871. free(encoder->private_->residual_workspace_unaligned[channel][i]);
  91872. encoder->private_->residual_workspace_unaligned[channel][i] = 0;
  91873. }
  91874. }
  91875. }
  91876. for(channel = 0; channel < 2; channel++) {
  91877. for(i = 0; i < 2; i++) {
  91878. if(0 != encoder->private_->residual_workspace_mid_side_unaligned[channel][i]) {
  91879. free(encoder->private_->residual_workspace_mid_side_unaligned[channel][i]);
  91880. encoder->private_->residual_workspace_mid_side_unaligned[channel][i] = 0;
  91881. }
  91882. }
  91883. }
  91884. if(0 != encoder->private_->abs_residual_partition_sums_unaligned) {
  91885. free(encoder->private_->abs_residual_partition_sums_unaligned);
  91886. encoder->private_->abs_residual_partition_sums_unaligned = 0;
  91887. }
  91888. if(0 != encoder->private_->raw_bits_per_partition_unaligned) {
  91889. free(encoder->private_->raw_bits_per_partition_unaligned);
  91890. encoder->private_->raw_bits_per_partition_unaligned = 0;
  91891. }
  91892. if(encoder->protected_->verify) {
  91893. for(i = 0; i < encoder->protected_->channels; i++) {
  91894. if(0 != encoder->private_->verify.input_fifo.data[i]) {
  91895. free(encoder->private_->verify.input_fifo.data[i]);
  91896. encoder->private_->verify.input_fifo.data[i] = 0;
  91897. }
  91898. }
  91899. }
  91900. FLAC__bitwriter_free(encoder->private_->frame);
  91901. }
  91902. FLAC__bool resize_buffers_(FLAC__StreamEncoder *encoder, unsigned new_blocksize)
  91903. {
  91904. FLAC__bool ok;
  91905. unsigned i, channel;
  91906. FLAC__ASSERT(new_blocksize > 0);
  91907. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91908. FLAC__ASSERT(encoder->private_->current_sample_number == 0);
  91909. if(new_blocksize <= encoder->private_->input_capacity)
  91910. return true;
  91911. ok = true;
  91912. for(i = 0; ok && i < encoder->protected_->channels; i++) {
  91913. ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize+4+OVERREAD_, &encoder->private_->integer_signal_unaligned[i], &encoder->private_->integer_signal[i]);
  91914. memset(encoder->private_->integer_signal[i], 0, sizeof(FLAC__int32)*4);
  91915. encoder->private_->integer_signal[i] += 4;
  91916. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91917. #if 0 /* @@@ currently unused */
  91918. if(encoder->protected_->max_lpc_order > 0)
  91919. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize+OVERREAD_, &encoder->private_->real_signal_unaligned[i], &encoder->private_->real_signal[i]);
  91920. #endif
  91921. #endif
  91922. }
  91923. for(i = 0; ok && i < 2; i++) {
  91924. 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]);
  91925. memset(encoder->private_->integer_signal_mid_side[i], 0, sizeof(FLAC__int32)*4);
  91926. encoder->private_->integer_signal_mid_side[i] += 4;
  91927. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91928. #if 0 /* @@@ currently unused */
  91929. if(encoder->protected_->max_lpc_order > 0)
  91930. 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]);
  91931. #endif
  91932. #endif
  91933. }
  91934. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91935. if(ok && encoder->protected_->max_lpc_order > 0) {
  91936. for(i = 0; ok && i < encoder->protected_->num_apodizations; i++)
  91937. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize, &encoder->private_->window_unaligned[i], &encoder->private_->window[i]);
  91938. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize, &encoder->private_->windowed_signal_unaligned, &encoder->private_->windowed_signal);
  91939. }
  91940. #endif
  91941. for(channel = 0; ok && channel < encoder->protected_->channels; channel++) {
  91942. for(i = 0; ok && i < 2; i++) {
  91943. ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize, &encoder->private_->residual_workspace_unaligned[channel][i], &encoder->private_->residual_workspace[channel][i]);
  91944. }
  91945. }
  91946. for(channel = 0; ok && channel < 2; channel++) {
  91947. for(i = 0; ok && i < 2; i++) {
  91948. 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]);
  91949. }
  91950. }
  91951. ok = ok && FLAC__memory_alloc_aligned_uint64_array(new_blocksize * 2, &encoder->private_->abs_residual_partition_sums_unaligned, &encoder->private_->abs_residual_partition_sums);
  91952. if(encoder->protected_->do_escape_coding)
  91953. ok = ok && FLAC__memory_alloc_aligned_unsigned_array(new_blocksize * 2, &encoder->private_->raw_bits_per_partition_unaligned, &encoder->private_->raw_bits_per_partition);
  91954. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91955. if(ok && new_blocksize != encoder->private_->input_capacity && encoder->protected_->max_lpc_order > 0) {
  91956. for(i = 0; ok && i < encoder->protected_->num_apodizations; i++) {
  91957. switch(encoder->protected_->apodizations[i].type) {
  91958. case FLAC__APODIZATION_BARTLETT:
  91959. FLAC__window_bartlett(encoder->private_->window[i], new_blocksize);
  91960. break;
  91961. case FLAC__APODIZATION_BARTLETT_HANN:
  91962. FLAC__window_bartlett_hann(encoder->private_->window[i], new_blocksize);
  91963. break;
  91964. case FLAC__APODIZATION_BLACKMAN:
  91965. FLAC__window_blackman(encoder->private_->window[i], new_blocksize);
  91966. break;
  91967. case FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE:
  91968. FLAC__window_blackman_harris_4term_92db_sidelobe(encoder->private_->window[i], new_blocksize);
  91969. break;
  91970. case FLAC__APODIZATION_CONNES:
  91971. FLAC__window_connes(encoder->private_->window[i], new_blocksize);
  91972. break;
  91973. case FLAC__APODIZATION_FLATTOP:
  91974. FLAC__window_flattop(encoder->private_->window[i], new_blocksize);
  91975. break;
  91976. case FLAC__APODIZATION_GAUSS:
  91977. FLAC__window_gauss(encoder->private_->window[i], new_blocksize, encoder->protected_->apodizations[i].parameters.gauss.stddev);
  91978. break;
  91979. case FLAC__APODIZATION_HAMMING:
  91980. FLAC__window_hamming(encoder->private_->window[i], new_blocksize);
  91981. break;
  91982. case FLAC__APODIZATION_HANN:
  91983. FLAC__window_hann(encoder->private_->window[i], new_blocksize);
  91984. break;
  91985. case FLAC__APODIZATION_KAISER_BESSEL:
  91986. FLAC__window_kaiser_bessel(encoder->private_->window[i], new_blocksize);
  91987. break;
  91988. case FLAC__APODIZATION_NUTTALL:
  91989. FLAC__window_nuttall(encoder->private_->window[i], new_blocksize);
  91990. break;
  91991. case FLAC__APODIZATION_RECTANGLE:
  91992. FLAC__window_rectangle(encoder->private_->window[i], new_blocksize);
  91993. break;
  91994. case FLAC__APODIZATION_TRIANGLE:
  91995. FLAC__window_triangle(encoder->private_->window[i], new_blocksize);
  91996. break;
  91997. case FLAC__APODIZATION_TUKEY:
  91998. FLAC__window_tukey(encoder->private_->window[i], new_blocksize, encoder->protected_->apodizations[i].parameters.tukey.p);
  91999. break;
  92000. case FLAC__APODIZATION_WELCH:
  92001. FLAC__window_welch(encoder->private_->window[i], new_blocksize);
  92002. break;
  92003. default:
  92004. FLAC__ASSERT(0);
  92005. FLAC__window_hann(encoder->private_->window[i], new_blocksize);
  92006. break;
  92007. }
  92008. }
  92009. }
  92010. #endif
  92011. if(ok)
  92012. encoder->private_->input_capacity = new_blocksize;
  92013. else
  92014. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  92015. return ok;
  92016. }
  92017. FLAC__bool write_bitbuffer_(FLAC__StreamEncoder *encoder, unsigned samples, FLAC__bool is_last_block)
  92018. {
  92019. const FLAC__byte *buffer;
  92020. size_t bytes;
  92021. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(encoder->private_->frame));
  92022. if(!FLAC__bitwriter_get_buffer(encoder->private_->frame, &buffer, &bytes)) {
  92023. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  92024. return false;
  92025. }
  92026. if(encoder->protected_->verify) {
  92027. encoder->private_->verify.output.data = buffer;
  92028. encoder->private_->verify.output.bytes = bytes;
  92029. if(encoder->private_->verify.state_hint == ENCODER_IN_MAGIC) {
  92030. encoder->private_->verify.needs_magic_hack = true;
  92031. }
  92032. else {
  92033. if(!FLAC__stream_decoder_process_single(encoder->private_->verify.decoder)) {
  92034. FLAC__bitwriter_release_buffer(encoder->private_->frame);
  92035. FLAC__bitwriter_clear(encoder->private_->frame);
  92036. if(encoder->protected_->state != FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA)
  92037. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  92038. return false;
  92039. }
  92040. }
  92041. }
  92042. if(write_frame_(encoder, buffer, bytes, samples, is_last_block) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  92043. FLAC__bitwriter_release_buffer(encoder->private_->frame);
  92044. FLAC__bitwriter_clear(encoder->private_->frame);
  92045. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92046. return false;
  92047. }
  92048. FLAC__bitwriter_release_buffer(encoder->private_->frame);
  92049. FLAC__bitwriter_clear(encoder->private_->frame);
  92050. if(samples > 0) {
  92051. encoder->private_->streaminfo.data.stream_info.min_framesize = min(bytes, encoder->private_->streaminfo.data.stream_info.min_framesize);
  92052. encoder->private_->streaminfo.data.stream_info.max_framesize = max(bytes, encoder->private_->streaminfo.data.stream_info.max_framesize);
  92053. }
  92054. return true;
  92055. }
  92056. FLAC__StreamEncoderWriteStatus write_frame_(FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, FLAC__bool is_last_block)
  92057. {
  92058. FLAC__StreamEncoderWriteStatus status;
  92059. FLAC__uint64 output_position = 0;
  92060. if(encoder->private_->tell_callback && encoder->private_->tell_callback(encoder, &output_position, encoder->private_->client_data) == FLAC__STREAM_ENCODER_TELL_STATUS_ERROR) {
  92061. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92062. return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
  92063. }
  92064. if(samples == 0) {
  92065. FLAC__MetadataType type = (FLAC__MetadataType) (buffer[0] & 0x7f);
  92066. if(type == FLAC__METADATA_TYPE_STREAMINFO)
  92067. encoder->protected_->streaminfo_offset = output_position;
  92068. else if(type == FLAC__METADATA_TYPE_SEEKTABLE && encoder->protected_->seektable_offset == 0)
  92069. encoder->protected_->seektable_offset = output_position;
  92070. }
  92071. if(0 != encoder->private_->seek_table && encoder->protected_->audio_offset > 0 && encoder->private_->seek_table->num_points > 0) {
  92072. const unsigned blocksize = FLAC__stream_encoder_get_blocksize(encoder);
  92073. const FLAC__uint64 frame_first_sample = encoder->private_->samples_written;
  92074. const FLAC__uint64 frame_last_sample = frame_first_sample + (FLAC__uint64)blocksize - 1;
  92075. FLAC__uint64 test_sample;
  92076. unsigned i;
  92077. for(i = encoder->private_->first_seekpoint_to_check; i < encoder->private_->seek_table->num_points; i++) {
  92078. test_sample = encoder->private_->seek_table->points[i].sample_number;
  92079. if(test_sample > frame_last_sample) {
  92080. break;
  92081. }
  92082. else if(test_sample >= frame_first_sample) {
  92083. encoder->private_->seek_table->points[i].sample_number = frame_first_sample;
  92084. encoder->private_->seek_table->points[i].stream_offset = output_position - encoder->protected_->audio_offset;
  92085. encoder->private_->seek_table->points[i].frame_samples = blocksize;
  92086. encoder->private_->first_seekpoint_to_check++;
  92087. }
  92088. else {
  92089. encoder->private_->first_seekpoint_to_check++;
  92090. }
  92091. }
  92092. }
  92093. #if FLAC__HAS_OGG
  92094. if(encoder->private_->is_ogg) {
  92095. status = FLAC__ogg_encoder_aspect_write_callback_wrapper(
  92096. &encoder->protected_->ogg_encoder_aspect,
  92097. buffer,
  92098. bytes,
  92099. samples,
  92100. encoder->private_->current_frame_number,
  92101. is_last_block,
  92102. (FLAC__OggEncoderAspectWriteCallbackProxy)encoder->private_->write_callback,
  92103. encoder,
  92104. encoder->private_->client_data
  92105. );
  92106. }
  92107. else
  92108. #endif
  92109. status = encoder->private_->write_callback(encoder, buffer, bytes, samples, encoder->private_->current_frame_number, encoder->private_->client_data);
  92110. if(status == FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  92111. encoder->private_->bytes_written += bytes;
  92112. encoder->private_->samples_written += samples;
  92113. encoder->private_->frames_written = max(encoder->private_->frames_written, encoder->private_->current_frame_number+1);
  92114. }
  92115. else
  92116. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92117. return status;
  92118. }
  92119. void update_metadata_(const FLAC__StreamEncoder *encoder)
  92120. {
  92121. FLAC__byte b[max(6, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)];
  92122. const FLAC__StreamMetadata *metadata = &encoder->private_->streaminfo;
  92123. const FLAC__uint64 samples = metadata->data.stream_info.total_samples;
  92124. const unsigned min_framesize = metadata->data.stream_info.min_framesize;
  92125. const unsigned max_framesize = metadata->data.stream_info.max_framesize;
  92126. const unsigned bps = metadata->data.stream_info.bits_per_sample;
  92127. FLAC__StreamEncoderSeekStatus seek_status;
  92128. FLAC__ASSERT(metadata->type == FLAC__METADATA_TYPE_STREAMINFO);
  92129. {
  92130. const unsigned md5_offset =
  92131. FLAC__STREAM_METADATA_HEADER_LENGTH +
  92132. (
  92133. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  92134. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  92135. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  92136. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  92137. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  92138. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  92139. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN +
  92140. FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN
  92141. ) / 8;
  92142. if((seek_status = encoder->private_->seek_callback(encoder, encoder->protected_->streaminfo_offset + md5_offset, encoder->private_->client_data)) != FLAC__STREAM_ENCODER_SEEK_STATUS_OK) {
  92143. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  92144. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92145. return;
  92146. }
  92147. if(encoder->private_->write_callback(encoder, metadata->data.stream_info.md5sum, 16, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  92148. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92149. return;
  92150. }
  92151. }
  92152. {
  92153. const unsigned total_samples_byte_offset =
  92154. FLAC__STREAM_METADATA_HEADER_LENGTH +
  92155. (
  92156. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  92157. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  92158. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  92159. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  92160. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  92161. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  92162. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN
  92163. - 4
  92164. ) / 8;
  92165. b[0] = ((FLAC__byte)(bps-1) << 4) | (FLAC__byte)((samples >> 32) & 0x0F);
  92166. b[1] = (FLAC__byte)((samples >> 24) & 0xFF);
  92167. b[2] = (FLAC__byte)((samples >> 16) & 0xFF);
  92168. b[3] = (FLAC__byte)((samples >> 8) & 0xFF);
  92169. b[4] = (FLAC__byte)(samples & 0xFF);
  92170. 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) {
  92171. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  92172. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92173. return;
  92174. }
  92175. if(encoder->private_->write_callback(encoder, b, 5, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  92176. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92177. return;
  92178. }
  92179. }
  92180. {
  92181. const unsigned min_framesize_offset =
  92182. FLAC__STREAM_METADATA_HEADER_LENGTH +
  92183. (
  92184. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  92185. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN
  92186. ) / 8;
  92187. b[0] = (FLAC__byte)((min_framesize >> 16) & 0xFF);
  92188. b[1] = (FLAC__byte)((min_framesize >> 8) & 0xFF);
  92189. b[2] = (FLAC__byte)(min_framesize & 0xFF);
  92190. b[3] = (FLAC__byte)((max_framesize >> 16) & 0xFF);
  92191. b[4] = (FLAC__byte)((max_framesize >> 8) & 0xFF);
  92192. b[5] = (FLAC__byte)(max_framesize & 0xFF);
  92193. 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) {
  92194. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  92195. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92196. return;
  92197. }
  92198. if(encoder->private_->write_callback(encoder, b, 6, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  92199. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92200. return;
  92201. }
  92202. }
  92203. if(0 != encoder->private_->seek_table && encoder->private_->seek_table->num_points > 0 && encoder->protected_->seektable_offset > 0) {
  92204. unsigned i;
  92205. FLAC__format_seektable_sort(encoder->private_->seek_table);
  92206. FLAC__ASSERT(FLAC__format_seektable_is_legal(encoder->private_->seek_table));
  92207. 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) {
  92208. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  92209. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92210. return;
  92211. }
  92212. for(i = 0; i < encoder->private_->seek_table->num_points; i++) {
  92213. FLAC__uint64 xx;
  92214. unsigned x;
  92215. xx = encoder->private_->seek_table->points[i].sample_number;
  92216. b[7] = (FLAC__byte)xx; xx >>= 8;
  92217. b[6] = (FLAC__byte)xx; xx >>= 8;
  92218. b[5] = (FLAC__byte)xx; xx >>= 8;
  92219. b[4] = (FLAC__byte)xx; xx >>= 8;
  92220. b[3] = (FLAC__byte)xx; xx >>= 8;
  92221. b[2] = (FLAC__byte)xx; xx >>= 8;
  92222. b[1] = (FLAC__byte)xx; xx >>= 8;
  92223. b[0] = (FLAC__byte)xx; xx >>= 8;
  92224. xx = encoder->private_->seek_table->points[i].stream_offset;
  92225. b[15] = (FLAC__byte)xx; xx >>= 8;
  92226. b[14] = (FLAC__byte)xx; xx >>= 8;
  92227. b[13] = (FLAC__byte)xx; xx >>= 8;
  92228. b[12] = (FLAC__byte)xx; xx >>= 8;
  92229. b[11] = (FLAC__byte)xx; xx >>= 8;
  92230. b[10] = (FLAC__byte)xx; xx >>= 8;
  92231. b[9] = (FLAC__byte)xx; xx >>= 8;
  92232. b[8] = (FLAC__byte)xx; xx >>= 8;
  92233. x = encoder->private_->seek_table->points[i].frame_samples;
  92234. b[17] = (FLAC__byte)x; x >>= 8;
  92235. b[16] = (FLAC__byte)x; x >>= 8;
  92236. if(encoder->private_->write_callback(encoder, b, 18, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  92237. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92238. return;
  92239. }
  92240. }
  92241. }
  92242. }
  92243. #if FLAC__HAS_OGG
  92244. void update_ogg_metadata_(FLAC__StreamEncoder *encoder)
  92245. {
  92246. static const unsigned FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH =
  92247. FLAC__OGG_MAPPING_PACKET_TYPE_LENGTH +
  92248. FLAC__OGG_MAPPING_MAGIC_LENGTH +
  92249. FLAC__OGG_MAPPING_VERSION_MAJOR_LENGTH +
  92250. FLAC__OGG_MAPPING_VERSION_MINOR_LENGTH +
  92251. FLAC__OGG_MAPPING_NUM_HEADERS_LENGTH +
  92252. FLAC__STREAM_SYNC_LENGTH
  92253. ;
  92254. FLAC__byte b[max(6, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)];
  92255. const FLAC__StreamMetadata *metadata = &encoder->private_->streaminfo;
  92256. const FLAC__uint64 samples = metadata->data.stream_info.total_samples;
  92257. const unsigned min_framesize = metadata->data.stream_info.min_framesize;
  92258. const unsigned max_framesize = metadata->data.stream_info.max_framesize;
  92259. ogg_page page;
  92260. FLAC__ASSERT(metadata->type == FLAC__METADATA_TYPE_STREAMINFO);
  92261. FLAC__ASSERT(0 != encoder->private_->seek_callback);
  92262. if(encoder->private_->seek_callback(encoder, 0, encoder->private_->client_data) == FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED)
  92263. return;
  92264. simple_ogg_page__init(&page);
  92265. if(!simple_ogg_page__get_at(encoder, encoder->protected_->streaminfo_offset, &page, encoder->private_->seek_callback, encoder->private_->read_callback, encoder->private_->client_data)) {
  92266. simple_ogg_page__clear(&page);
  92267. return; /* state already set */
  92268. }
  92269. {
  92270. const unsigned md5_offset =
  92271. FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
  92272. FLAC__STREAM_METADATA_HEADER_LENGTH +
  92273. (
  92274. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  92275. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  92276. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  92277. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  92278. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  92279. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  92280. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN +
  92281. FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN
  92282. ) / 8;
  92283. if(md5_offset + 16 > (unsigned)page.body_len) {
  92284. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  92285. simple_ogg_page__clear(&page);
  92286. return;
  92287. }
  92288. memcpy(page.body + md5_offset, metadata->data.stream_info.md5sum, 16);
  92289. }
  92290. {
  92291. const unsigned total_samples_byte_offset =
  92292. FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
  92293. FLAC__STREAM_METADATA_HEADER_LENGTH +
  92294. (
  92295. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  92296. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  92297. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  92298. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  92299. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  92300. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  92301. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN
  92302. - 4
  92303. ) / 8;
  92304. if(total_samples_byte_offset + 5 > (unsigned)page.body_len) {
  92305. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  92306. simple_ogg_page__clear(&page);
  92307. return;
  92308. }
  92309. b[0] = (FLAC__byte)page.body[total_samples_byte_offset] & 0xF0;
  92310. b[0] |= (FLAC__byte)((samples >> 32) & 0x0F);
  92311. b[1] = (FLAC__byte)((samples >> 24) & 0xFF);
  92312. b[2] = (FLAC__byte)((samples >> 16) & 0xFF);
  92313. b[3] = (FLAC__byte)((samples >> 8) & 0xFF);
  92314. b[4] = (FLAC__byte)(samples & 0xFF);
  92315. memcpy(page.body + total_samples_byte_offset, b, 5);
  92316. }
  92317. {
  92318. const unsigned min_framesize_offset =
  92319. FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
  92320. FLAC__STREAM_METADATA_HEADER_LENGTH +
  92321. (
  92322. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  92323. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN
  92324. ) / 8;
  92325. if(min_framesize_offset + 6 > (unsigned)page.body_len) {
  92326. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  92327. simple_ogg_page__clear(&page);
  92328. return;
  92329. }
  92330. b[0] = (FLAC__byte)((min_framesize >> 16) & 0xFF);
  92331. b[1] = (FLAC__byte)((min_framesize >> 8) & 0xFF);
  92332. b[2] = (FLAC__byte)(min_framesize & 0xFF);
  92333. b[3] = (FLAC__byte)((max_framesize >> 16) & 0xFF);
  92334. b[4] = (FLAC__byte)((max_framesize >> 8) & 0xFF);
  92335. b[5] = (FLAC__byte)(max_framesize & 0xFF);
  92336. memcpy(page.body + min_framesize_offset, b, 6);
  92337. }
  92338. if(!simple_ogg_page__set_at(encoder, encoder->protected_->streaminfo_offset, &page, encoder->private_->seek_callback, encoder->private_->write_callback, encoder->private_->client_data)) {
  92339. simple_ogg_page__clear(&page);
  92340. return; /* state already set */
  92341. }
  92342. simple_ogg_page__clear(&page);
  92343. if(0 != encoder->private_->seek_table && encoder->private_->seek_table->num_points > 0 && encoder->protected_->seektable_offset > 0) {
  92344. unsigned i;
  92345. FLAC__byte *p;
  92346. FLAC__format_seektable_sort(encoder->private_->seek_table);
  92347. FLAC__ASSERT(FLAC__format_seektable_is_legal(encoder->private_->seek_table));
  92348. simple_ogg_page__init(&page);
  92349. if(!simple_ogg_page__get_at(encoder, encoder->protected_->seektable_offset, &page, encoder->private_->seek_callback, encoder->private_->read_callback, encoder->private_->client_data)) {
  92350. simple_ogg_page__clear(&page);
  92351. return; /* state already set */
  92352. }
  92353. if((FLAC__STREAM_METADATA_HEADER_LENGTH + 18*encoder->private_->seek_table->num_points) != (unsigned)page.body_len) {
  92354. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  92355. simple_ogg_page__clear(&page);
  92356. return;
  92357. }
  92358. for(i = 0, p = page.body + FLAC__STREAM_METADATA_HEADER_LENGTH; i < encoder->private_->seek_table->num_points; i++, p += 18) {
  92359. FLAC__uint64 xx;
  92360. unsigned x;
  92361. xx = encoder->private_->seek_table->points[i].sample_number;
  92362. b[7] = (FLAC__byte)xx; xx >>= 8;
  92363. b[6] = (FLAC__byte)xx; xx >>= 8;
  92364. b[5] = (FLAC__byte)xx; xx >>= 8;
  92365. b[4] = (FLAC__byte)xx; xx >>= 8;
  92366. b[3] = (FLAC__byte)xx; xx >>= 8;
  92367. b[2] = (FLAC__byte)xx; xx >>= 8;
  92368. b[1] = (FLAC__byte)xx; xx >>= 8;
  92369. b[0] = (FLAC__byte)xx; xx >>= 8;
  92370. xx = encoder->private_->seek_table->points[i].stream_offset;
  92371. b[15] = (FLAC__byte)xx; xx >>= 8;
  92372. b[14] = (FLAC__byte)xx; xx >>= 8;
  92373. b[13] = (FLAC__byte)xx; xx >>= 8;
  92374. b[12] = (FLAC__byte)xx; xx >>= 8;
  92375. b[11] = (FLAC__byte)xx; xx >>= 8;
  92376. b[10] = (FLAC__byte)xx; xx >>= 8;
  92377. b[9] = (FLAC__byte)xx; xx >>= 8;
  92378. b[8] = (FLAC__byte)xx; xx >>= 8;
  92379. x = encoder->private_->seek_table->points[i].frame_samples;
  92380. b[17] = (FLAC__byte)x; x >>= 8;
  92381. b[16] = (FLAC__byte)x; x >>= 8;
  92382. memcpy(p, b, 18);
  92383. }
  92384. if(!simple_ogg_page__set_at(encoder, encoder->protected_->seektable_offset, &page, encoder->private_->seek_callback, encoder->private_->write_callback, encoder->private_->client_data)) {
  92385. simple_ogg_page__clear(&page);
  92386. return; /* state already set */
  92387. }
  92388. simple_ogg_page__clear(&page);
  92389. }
  92390. }
  92391. #endif
  92392. FLAC__bool process_frame_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block, FLAC__bool is_last_block)
  92393. {
  92394. FLAC__uint16 crc;
  92395. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  92396. 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)) {
  92397. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  92398. return false;
  92399. }
  92400. if(!process_subframes_(encoder, is_fractional_block)) {
  92401. return false;
  92402. }
  92403. if(!FLAC__bitwriter_zero_pad_to_byte_boundary(encoder->private_->frame)) {
  92404. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  92405. return false;
  92406. }
  92407. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(encoder->private_->frame));
  92408. if(
  92409. !FLAC__bitwriter_get_write_crc16(encoder->private_->frame, &crc) ||
  92410. !FLAC__bitwriter_write_raw_uint32(encoder->private_->frame, crc, FLAC__FRAME_FOOTER_CRC_LEN)
  92411. ) {
  92412. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  92413. return false;
  92414. }
  92415. if(!write_bitbuffer_(encoder, encoder->protected_->blocksize, is_last_block)) {
  92416. return false;
  92417. }
  92418. encoder->private_->current_sample_number = 0;
  92419. encoder->private_->current_frame_number++;
  92420. encoder->private_->streaminfo.data.stream_info.total_samples += (FLAC__uint64)encoder->protected_->blocksize;
  92421. return true;
  92422. }
  92423. FLAC__bool process_subframes_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block)
  92424. {
  92425. FLAC__FrameHeader frame_header;
  92426. unsigned channel, min_partition_order = encoder->protected_->min_residual_partition_order, max_partition_order;
  92427. FLAC__bool do_independent, do_mid_side;
  92428. if(is_fractional_block) {
  92429. max_partition_order = 0;
  92430. }
  92431. else {
  92432. max_partition_order = FLAC__format_get_max_rice_partition_order_from_blocksize(encoder->protected_->blocksize);
  92433. max_partition_order = min(max_partition_order, encoder->protected_->max_residual_partition_order);
  92434. }
  92435. min_partition_order = min(min_partition_order, max_partition_order);
  92436. frame_header.blocksize = encoder->protected_->blocksize;
  92437. frame_header.sample_rate = encoder->protected_->sample_rate;
  92438. frame_header.channels = encoder->protected_->channels;
  92439. frame_header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT; /* the default unless the encoder determines otherwise */
  92440. frame_header.bits_per_sample = encoder->protected_->bits_per_sample;
  92441. frame_header.number_type = FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER;
  92442. frame_header.number.frame_number = encoder->private_->current_frame_number;
  92443. if(encoder->protected_->do_mid_side_stereo) {
  92444. if(encoder->protected_->loose_mid_side_stereo) {
  92445. if(encoder->private_->loose_mid_side_stereo_frame_count == 0) {
  92446. do_independent = true;
  92447. do_mid_side = true;
  92448. }
  92449. else {
  92450. do_independent = (encoder->private_->last_channel_assignment == FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT);
  92451. do_mid_side = !do_independent;
  92452. }
  92453. }
  92454. else {
  92455. do_independent = true;
  92456. do_mid_side = true;
  92457. }
  92458. }
  92459. else {
  92460. do_independent = true;
  92461. do_mid_side = false;
  92462. }
  92463. FLAC__ASSERT(do_independent || do_mid_side);
  92464. if(do_independent) {
  92465. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  92466. const unsigned w = get_wasted_bits_(encoder->private_->integer_signal[channel], encoder->protected_->blocksize);
  92467. encoder->private_->subframe_workspace[channel][0].wasted_bits = encoder->private_->subframe_workspace[channel][1].wasted_bits = w;
  92468. encoder->private_->subframe_bps[channel] = encoder->protected_->bits_per_sample - w;
  92469. }
  92470. }
  92471. if(do_mid_side) {
  92472. FLAC__ASSERT(encoder->protected_->channels == 2);
  92473. for(channel = 0; channel < 2; channel++) {
  92474. const unsigned w = get_wasted_bits_(encoder->private_->integer_signal_mid_side[channel], encoder->protected_->blocksize);
  92475. encoder->private_->subframe_workspace_mid_side[channel][0].wasted_bits = encoder->private_->subframe_workspace_mid_side[channel][1].wasted_bits = w;
  92476. encoder->private_->subframe_bps_mid_side[channel] = encoder->protected_->bits_per_sample - w + (channel==0? 0:1);
  92477. }
  92478. }
  92479. if(do_independent) {
  92480. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  92481. if(!
  92482. process_subframe_(
  92483. encoder,
  92484. min_partition_order,
  92485. max_partition_order,
  92486. &frame_header,
  92487. encoder->private_->subframe_bps[channel],
  92488. encoder->private_->integer_signal[channel],
  92489. encoder->private_->subframe_workspace_ptr[channel],
  92490. encoder->private_->partitioned_rice_contents_workspace_ptr[channel],
  92491. encoder->private_->residual_workspace[channel],
  92492. encoder->private_->best_subframe+channel,
  92493. encoder->private_->best_subframe_bits+channel
  92494. )
  92495. )
  92496. return false;
  92497. }
  92498. }
  92499. if(do_mid_side) {
  92500. FLAC__ASSERT(encoder->protected_->channels == 2);
  92501. for(channel = 0; channel < 2; channel++) {
  92502. if(!
  92503. process_subframe_(
  92504. encoder,
  92505. min_partition_order,
  92506. max_partition_order,
  92507. &frame_header,
  92508. encoder->private_->subframe_bps_mid_side[channel],
  92509. encoder->private_->integer_signal_mid_side[channel],
  92510. encoder->private_->subframe_workspace_ptr_mid_side[channel],
  92511. encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[channel],
  92512. encoder->private_->residual_workspace_mid_side[channel],
  92513. encoder->private_->best_subframe_mid_side+channel,
  92514. encoder->private_->best_subframe_bits_mid_side+channel
  92515. )
  92516. )
  92517. return false;
  92518. }
  92519. }
  92520. if(do_mid_side) {
  92521. unsigned left_bps = 0, right_bps = 0; /* initialized only to prevent superfluous compiler warning */
  92522. FLAC__Subframe *left_subframe = 0, *right_subframe = 0; /* initialized only to prevent superfluous compiler warning */
  92523. FLAC__ChannelAssignment channel_assignment;
  92524. FLAC__ASSERT(encoder->protected_->channels == 2);
  92525. if(encoder->protected_->loose_mid_side_stereo && encoder->private_->loose_mid_side_stereo_frame_count > 0) {
  92526. channel_assignment = (encoder->private_->last_channel_assignment == FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT? FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT : FLAC__CHANNEL_ASSIGNMENT_MID_SIDE);
  92527. }
  92528. else {
  92529. unsigned bits[4]; /* WATCHOUT - indexed by FLAC__ChannelAssignment */
  92530. unsigned min_bits;
  92531. int ca;
  92532. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT == 0);
  92533. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE == 1);
  92534. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE == 2);
  92535. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_MID_SIDE == 3);
  92536. FLAC__ASSERT(do_independent && do_mid_side);
  92537. bits[FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT] = encoder->private_->best_subframe_bits [0] + encoder->private_->best_subframe_bits [1];
  92538. bits[FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE ] = encoder->private_->best_subframe_bits [0] + encoder->private_->best_subframe_bits_mid_side[1];
  92539. bits[FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE ] = encoder->private_->best_subframe_bits [1] + encoder->private_->best_subframe_bits_mid_side[1];
  92540. bits[FLAC__CHANNEL_ASSIGNMENT_MID_SIDE ] = encoder->private_->best_subframe_bits_mid_side[0] + encoder->private_->best_subframe_bits_mid_side[1];
  92541. channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT;
  92542. min_bits = bits[channel_assignment];
  92543. for(ca = 1; ca <= 3; ca++) {
  92544. if(bits[ca] < min_bits) {
  92545. min_bits = bits[ca];
  92546. channel_assignment = (FLAC__ChannelAssignment)ca;
  92547. }
  92548. }
  92549. }
  92550. frame_header.channel_assignment = channel_assignment;
  92551. if(!FLAC__frame_add_header(&frame_header, encoder->private_->frame)) {
  92552. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92553. return false;
  92554. }
  92555. switch(channel_assignment) {
  92556. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  92557. left_subframe = &encoder->private_->subframe_workspace [0][encoder->private_->best_subframe [0]];
  92558. right_subframe = &encoder->private_->subframe_workspace [1][encoder->private_->best_subframe [1]];
  92559. break;
  92560. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  92561. left_subframe = &encoder->private_->subframe_workspace [0][encoder->private_->best_subframe [0]];
  92562. right_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
  92563. break;
  92564. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  92565. left_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
  92566. right_subframe = &encoder->private_->subframe_workspace [1][encoder->private_->best_subframe [1]];
  92567. break;
  92568. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  92569. left_subframe = &encoder->private_->subframe_workspace_mid_side[0][encoder->private_->best_subframe_mid_side[0]];
  92570. right_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
  92571. break;
  92572. default:
  92573. FLAC__ASSERT(0);
  92574. }
  92575. switch(channel_assignment) {
  92576. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  92577. left_bps = encoder->private_->subframe_bps [0];
  92578. right_bps = encoder->private_->subframe_bps [1];
  92579. break;
  92580. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  92581. left_bps = encoder->private_->subframe_bps [0];
  92582. right_bps = encoder->private_->subframe_bps_mid_side[1];
  92583. break;
  92584. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  92585. left_bps = encoder->private_->subframe_bps_mid_side[1];
  92586. right_bps = encoder->private_->subframe_bps [1];
  92587. break;
  92588. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  92589. left_bps = encoder->private_->subframe_bps_mid_side[0];
  92590. right_bps = encoder->private_->subframe_bps_mid_side[1];
  92591. break;
  92592. default:
  92593. FLAC__ASSERT(0);
  92594. }
  92595. if(!add_subframe_(encoder, frame_header.blocksize, left_bps , left_subframe , encoder->private_->frame))
  92596. return false;
  92597. if(!add_subframe_(encoder, frame_header.blocksize, right_bps, right_subframe, encoder->private_->frame))
  92598. return false;
  92599. }
  92600. else {
  92601. if(!FLAC__frame_add_header(&frame_header, encoder->private_->frame)) {
  92602. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92603. return false;
  92604. }
  92605. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  92606. 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)) {
  92607. return false;
  92608. }
  92609. }
  92610. }
  92611. if(encoder->protected_->loose_mid_side_stereo) {
  92612. encoder->private_->loose_mid_side_stereo_frame_count++;
  92613. if(encoder->private_->loose_mid_side_stereo_frame_count >= encoder->private_->loose_mid_side_stereo_frames)
  92614. encoder->private_->loose_mid_side_stereo_frame_count = 0;
  92615. }
  92616. encoder->private_->last_channel_assignment = frame_header.channel_assignment;
  92617. return true;
  92618. }
  92619. FLAC__bool process_subframe_(
  92620. FLAC__StreamEncoder *encoder,
  92621. unsigned min_partition_order,
  92622. unsigned max_partition_order,
  92623. const FLAC__FrameHeader *frame_header,
  92624. unsigned subframe_bps,
  92625. const FLAC__int32 integer_signal[],
  92626. FLAC__Subframe *subframe[2],
  92627. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents[2],
  92628. FLAC__int32 *residual[2],
  92629. unsigned *best_subframe,
  92630. unsigned *best_bits
  92631. )
  92632. {
  92633. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92634. FLAC__float fixed_residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1];
  92635. #else
  92636. FLAC__fixedpoint fixed_residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1];
  92637. #endif
  92638. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92639. FLAC__double lpc_residual_bits_per_sample;
  92640. 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 */
  92641. FLAC__double lpc_error[FLAC__MAX_LPC_ORDER];
  92642. unsigned min_lpc_order, max_lpc_order, lpc_order;
  92643. unsigned min_qlp_coeff_precision, max_qlp_coeff_precision, qlp_coeff_precision;
  92644. #endif
  92645. unsigned min_fixed_order, max_fixed_order, guess_fixed_order, fixed_order;
  92646. unsigned rice_parameter;
  92647. unsigned _candidate_bits, _best_bits;
  92648. unsigned _best_subframe;
  92649. 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;
  92650. FLAC__ASSERT(frame_header->blocksize > 0);
  92651. _best_subframe = 0;
  92652. if(encoder->private_->disable_verbatim_subframes && frame_header->blocksize >= FLAC__MAX_FIXED_ORDER)
  92653. _best_bits = UINT_MAX;
  92654. else
  92655. _best_bits = evaluate_verbatim_subframe_(encoder, integer_signal, frame_header->blocksize, subframe_bps, subframe[_best_subframe]);
  92656. if(frame_header->blocksize >= FLAC__MAX_FIXED_ORDER) {
  92657. unsigned signal_is_constant = false;
  92658. 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);
  92659. if(
  92660. !encoder->private_->disable_constant_subframes &&
  92661. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92662. fixed_residual_bits_per_sample[1] == 0.0
  92663. #else
  92664. fixed_residual_bits_per_sample[1] == FLAC__FP_ZERO
  92665. #endif
  92666. ) {
  92667. unsigned i;
  92668. signal_is_constant = true;
  92669. for(i = 1; i < frame_header->blocksize; i++) {
  92670. if(integer_signal[0] != integer_signal[i]) {
  92671. signal_is_constant = false;
  92672. break;
  92673. }
  92674. }
  92675. }
  92676. if(signal_is_constant) {
  92677. _candidate_bits = evaluate_constant_subframe_(encoder, integer_signal[0], frame_header->blocksize, subframe_bps, subframe[!_best_subframe]);
  92678. if(_candidate_bits < _best_bits) {
  92679. _best_subframe = !_best_subframe;
  92680. _best_bits = _candidate_bits;
  92681. }
  92682. }
  92683. else {
  92684. if(!encoder->private_->disable_fixed_subframes || (encoder->protected_->max_lpc_order == 0 && _best_bits == UINT_MAX)) {
  92685. if(encoder->protected_->do_exhaustive_model_search) {
  92686. min_fixed_order = 0;
  92687. max_fixed_order = FLAC__MAX_FIXED_ORDER;
  92688. }
  92689. else {
  92690. min_fixed_order = max_fixed_order = guess_fixed_order;
  92691. }
  92692. if(max_fixed_order >= frame_header->blocksize)
  92693. max_fixed_order = frame_header->blocksize - 1;
  92694. for(fixed_order = min_fixed_order; fixed_order <= max_fixed_order; fixed_order++) {
  92695. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92696. if(fixed_residual_bits_per_sample[fixed_order] >= (FLAC__float)subframe_bps)
  92697. continue; /* don't even try */
  92698. 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 */
  92699. #else
  92700. if(FLAC__fixedpoint_trunc(fixed_residual_bits_per_sample[fixed_order]) >= (int)subframe_bps)
  92701. continue; /* don't even try */
  92702. 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 */
  92703. #endif
  92704. rice_parameter++; /* to account for the signed->unsigned conversion during rice coding */
  92705. if(rice_parameter >= rice_parameter_limit) {
  92706. #ifdef DEBUG_VERBOSE
  92707. fprintf(stderr, "clipping rice_parameter (%u -> %u) @0\n", rice_parameter, rice_parameter_limit - 1);
  92708. #endif
  92709. rice_parameter = rice_parameter_limit - 1;
  92710. }
  92711. _candidate_bits =
  92712. evaluate_fixed_subframe_(
  92713. encoder,
  92714. integer_signal,
  92715. residual[!_best_subframe],
  92716. encoder->private_->abs_residual_partition_sums,
  92717. encoder->private_->raw_bits_per_partition,
  92718. frame_header->blocksize,
  92719. subframe_bps,
  92720. fixed_order,
  92721. rice_parameter,
  92722. rice_parameter_limit,
  92723. min_partition_order,
  92724. max_partition_order,
  92725. encoder->protected_->do_escape_coding,
  92726. encoder->protected_->rice_parameter_search_dist,
  92727. subframe[!_best_subframe],
  92728. partitioned_rice_contents[!_best_subframe]
  92729. );
  92730. if(_candidate_bits < _best_bits) {
  92731. _best_subframe = !_best_subframe;
  92732. _best_bits = _candidate_bits;
  92733. }
  92734. }
  92735. }
  92736. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92737. if(encoder->protected_->max_lpc_order > 0) {
  92738. if(encoder->protected_->max_lpc_order >= frame_header->blocksize)
  92739. max_lpc_order = frame_header->blocksize-1;
  92740. else
  92741. max_lpc_order = encoder->protected_->max_lpc_order;
  92742. if(max_lpc_order > 0) {
  92743. unsigned a;
  92744. for (a = 0; a < encoder->protected_->num_apodizations; a++) {
  92745. FLAC__lpc_window_data(integer_signal, encoder->private_->window[a], encoder->private_->windowed_signal, frame_header->blocksize);
  92746. encoder->private_->local_lpc_compute_autocorrelation(encoder->private_->windowed_signal, frame_header->blocksize, max_lpc_order+1, autoc);
  92747. if(autoc[0] != 0.0) {
  92748. FLAC__lpc_compute_lp_coefficients(autoc, &max_lpc_order, encoder->private_->lp_coeff, lpc_error);
  92749. if(encoder->protected_->do_exhaustive_model_search) {
  92750. min_lpc_order = 1;
  92751. }
  92752. else {
  92753. const unsigned guess_lpc_order =
  92754. FLAC__lpc_compute_best_order(
  92755. lpc_error,
  92756. max_lpc_order,
  92757. frame_header->blocksize,
  92758. subframe_bps + (
  92759. encoder->protected_->do_qlp_coeff_prec_search?
  92760. FLAC__MIN_QLP_COEFF_PRECISION : /* have to guess; use the min possible size to avoid accidentally favoring lower orders */
  92761. encoder->protected_->qlp_coeff_precision
  92762. )
  92763. );
  92764. min_lpc_order = max_lpc_order = guess_lpc_order;
  92765. }
  92766. if(max_lpc_order >= frame_header->blocksize)
  92767. max_lpc_order = frame_header->blocksize - 1;
  92768. for(lpc_order = min_lpc_order; lpc_order <= max_lpc_order; lpc_order++) {
  92769. lpc_residual_bits_per_sample = FLAC__lpc_compute_expected_bits_per_residual_sample(lpc_error[lpc_order-1], frame_header->blocksize-lpc_order);
  92770. if(lpc_residual_bits_per_sample >= (FLAC__double)subframe_bps)
  92771. continue; /* don't even try */
  92772. rice_parameter = (lpc_residual_bits_per_sample > 0.0)? (unsigned)(lpc_residual_bits_per_sample+0.5) : 0; /* 0.5 is for rounding */
  92773. rice_parameter++; /* to account for the signed->unsigned conversion during rice coding */
  92774. if(rice_parameter >= rice_parameter_limit) {
  92775. #ifdef DEBUG_VERBOSE
  92776. fprintf(stderr, "clipping rice_parameter (%u -> %u) @1\n", rice_parameter, rice_parameter_limit - 1);
  92777. #endif
  92778. rice_parameter = rice_parameter_limit - 1;
  92779. }
  92780. if(encoder->protected_->do_qlp_coeff_prec_search) {
  92781. min_qlp_coeff_precision = FLAC__MIN_QLP_COEFF_PRECISION;
  92782. if(subframe_bps <= 17) {
  92783. max_qlp_coeff_precision = min(32 - subframe_bps - lpc_order, FLAC__MAX_QLP_COEFF_PRECISION);
  92784. max_qlp_coeff_precision = max(max_qlp_coeff_precision, min_qlp_coeff_precision);
  92785. }
  92786. else
  92787. max_qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION;
  92788. }
  92789. else {
  92790. min_qlp_coeff_precision = max_qlp_coeff_precision = encoder->protected_->qlp_coeff_precision;
  92791. }
  92792. for(qlp_coeff_precision = min_qlp_coeff_precision; qlp_coeff_precision <= max_qlp_coeff_precision; qlp_coeff_precision++) {
  92793. _candidate_bits =
  92794. evaluate_lpc_subframe_(
  92795. encoder,
  92796. integer_signal,
  92797. residual[!_best_subframe],
  92798. encoder->private_->abs_residual_partition_sums,
  92799. encoder->private_->raw_bits_per_partition,
  92800. encoder->private_->lp_coeff[lpc_order-1],
  92801. frame_header->blocksize,
  92802. subframe_bps,
  92803. lpc_order,
  92804. qlp_coeff_precision,
  92805. rice_parameter,
  92806. rice_parameter_limit,
  92807. min_partition_order,
  92808. max_partition_order,
  92809. encoder->protected_->do_escape_coding,
  92810. encoder->protected_->rice_parameter_search_dist,
  92811. subframe[!_best_subframe],
  92812. partitioned_rice_contents[!_best_subframe]
  92813. );
  92814. if(_candidate_bits > 0) { /* if == 0, there was a problem quantizing the lpcoeffs */
  92815. if(_candidate_bits < _best_bits) {
  92816. _best_subframe = !_best_subframe;
  92817. _best_bits = _candidate_bits;
  92818. }
  92819. }
  92820. }
  92821. }
  92822. }
  92823. }
  92824. }
  92825. }
  92826. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  92827. }
  92828. }
  92829. if(_best_bits == UINT_MAX) {
  92830. FLAC__ASSERT(_best_subframe == 0);
  92831. _best_bits = evaluate_verbatim_subframe_(encoder, integer_signal, frame_header->blocksize, subframe_bps, subframe[_best_subframe]);
  92832. }
  92833. *best_subframe = _best_subframe;
  92834. *best_bits = _best_bits;
  92835. return true;
  92836. }
  92837. FLAC__bool add_subframe_(
  92838. FLAC__StreamEncoder *encoder,
  92839. unsigned blocksize,
  92840. unsigned subframe_bps,
  92841. const FLAC__Subframe *subframe,
  92842. FLAC__BitWriter *frame
  92843. )
  92844. {
  92845. switch(subframe->type) {
  92846. case FLAC__SUBFRAME_TYPE_CONSTANT:
  92847. if(!FLAC__subframe_add_constant(&(subframe->data.constant), subframe_bps, subframe->wasted_bits, frame)) {
  92848. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92849. return false;
  92850. }
  92851. break;
  92852. case FLAC__SUBFRAME_TYPE_FIXED:
  92853. if(!FLAC__subframe_add_fixed(&(subframe->data.fixed), blocksize - subframe->data.fixed.order, subframe_bps, subframe->wasted_bits, frame)) {
  92854. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92855. return false;
  92856. }
  92857. break;
  92858. case FLAC__SUBFRAME_TYPE_LPC:
  92859. if(!FLAC__subframe_add_lpc(&(subframe->data.lpc), blocksize - subframe->data.lpc.order, subframe_bps, subframe->wasted_bits, frame)) {
  92860. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92861. return false;
  92862. }
  92863. break;
  92864. case FLAC__SUBFRAME_TYPE_VERBATIM:
  92865. if(!FLAC__subframe_add_verbatim(&(subframe->data.verbatim), blocksize, subframe_bps, subframe->wasted_bits, frame)) {
  92866. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92867. return false;
  92868. }
  92869. break;
  92870. default:
  92871. FLAC__ASSERT(0);
  92872. }
  92873. return true;
  92874. }
  92875. #define SPOTCHECK_ESTIMATE 0
  92876. #if SPOTCHECK_ESTIMATE
  92877. static void spotcheck_subframe_estimate_(
  92878. FLAC__StreamEncoder *encoder,
  92879. unsigned blocksize,
  92880. unsigned subframe_bps,
  92881. const FLAC__Subframe *subframe,
  92882. unsigned estimate
  92883. )
  92884. {
  92885. FLAC__bool ret;
  92886. FLAC__BitWriter *frame = FLAC__bitwriter_new();
  92887. if(frame == 0) {
  92888. fprintf(stderr, "EST: can't allocate frame\n");
  92889. return;
  92890. }
  92891. if(!FLAC__bitwriter_init(frame)) {
  92892. fprintf(stderr, "EST: can't init frame\n");
  92893. return;
  92894. }
  92895. ret = add_subframe_(encoder, blocksize, subframe_bps, subframe, frame);
  92896. FLAC__ASSERT(ret);
  92897. {
  92898. const unsigned actual = FLAC__bitwriter_get_input_bits_unconsumed(frame);
  92899. if(estimate != actual)
  92900. 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);
  92901. }
  92902. FLAC__bitwriter_delete(frame);
  92903. }
  92904. #endif
  92905. unsigned evaluate_constant_subframe_(
  92906. FLAC__StreamEncoder *encoder,
  92907. const FLAC__int32 signal,
  92908. unsigned blocksize,
  92909. unsigned subframe_bps,
  92910. FLAC__Subframe *subframe
  92911. )
  92912. {
  92913. unsigned estimate;
  92914. subframe->type = FLAC__SUBFRAME_TYPE_CONSTANT;
  92915. subframe->data.constant.value = signal;
  92916. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + subframe_bps;
  92917. #if SPOTCHECK_ESTIMATE
  92918. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92919. #else
  92920. (void)encoder, (void)blocksize;
  92921. #endif
  92922. return estimate;
  92923. }
  92924. unsigned evaluate_fixed_subframe_(
  92925. FLAC__StreamEncoder *encoder,
  92926. const FLAC__int32 signal[],
  92927. FLAC__int32 residual[],
  92928. FLAC__uint64 abs_residual_partition_sums[],
  92929. unsigned raw_bits_per_partition[],
  92930. unsigned blocksize,
  92931. unsigned subframe_bps,
  92932. unsigned order,
  92933. unsigned rice_parameter,
  92934. unsigned rice_parameter_limit,
  92935. unsigned min_partition_order,
  92936. unsigned max_partition_order,
  92937. FLAC__bool do_escape_coding,
  92938. unsigned rice_parameter_search_dist,
  92939. FLAC__Subframe *subframe,
  92940. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  92941. )
  92942. {
  92943. unsigned i, residual_bits, estimate;
  92944. const unsigned residual_samples = blocksize - order;
  92945. FLAC__fixed_compute_residual(signal+order, residual_samples, order, residual);
  92946. subframe->type = FLAC__SUBFRAME_TYPE_FIXED;
  92947. subframe->data.fixed.entropy_coding_method.type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE;
  92948. subframe->data.fixed.entropy_coding_method.data.partitioned_rice.contents = partitioned_rice_contents;
  92949. subframe->data.fixed.residual = residual;
  92950. residual_bits =
  92951. find_best_partition_order_(
  92952. encoder->private_,
  92953. residual,
  92954. abs_residual_partition_sums,
  92955. raw_bits_per_partition,
  92956. residual_samples,
  92957. order,
  92958. rice_parameter,
  92959. rice_parameter_limit,
  92960. min_partition_order,
  92961. max_partition_order,
  92962. subframe_bps,
  92963. do_escape_coding,
  92964. rice_parameter_search_dist,
  92965. &subframe->data.fixed.entropy_coding_method
  92966. );
  92967. subframe->data.fixed.order = order;
  92968. for(i = 0; i < order; i++)
  92969. subframe->data.fixed.warmup[i] = signal[i];
  92970. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + (order * subframe_bps) + residual_bits;
  92971. #if SPOTCHECK_ESTIMATE
  92972. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92973. #endif
  92974. return estimate;
  92975. }
  92976. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92977. unsigned evaluate_lpc_subframe_(
  92978. FLAC__StreamEncoder *encoder,
  92979. const FLAC__int32 signal[],
  92980. FLAC__int32 residual[],
  92981. FLAC__uint64 abs_residual_partition_sums[],
  92982. unsigned raw_bits_per_partition[],
  92983. const FLAC__real lp_coeff[],
  92984. unsigned blocksize,
  92985. unsigned subframe_bps,
  92986. unsigned order,
  92987. unsigned qlp_coeff_precision,
  92988. unsigned rice_parameter,
  92989. unsigned rice_parameter_limit,
  92990. unsigned min_partition_order,
  92991. unsigned max_partition_order,
  92992. FLAC__bool do_escape_coding,
  92993. unsigned rice_parameter_search_dist,
  92994. FLAC__Subframe *subframe,
  92995. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  92996. )
  92997. {
  92998. FLAC__int32 qlp_coeff[FLAC__MAX_LPC_ORDER];
  92999. unsigned i, residual_bits, estimate;
  93000. int quantization, ret;
  93001. const unsigned residual_samples = blocksize - order;
  93002. if(subframe_bps <= 16) {
  93003. FLAC__ASSERT(order > 0);
  93004. FLAC__ASSERT(order <= FLAC__MAX_LPC_ORDER);
  93005. qlp_coeff_precision = min(qlp_coeff_precision, 32 - subframe_bps - FLAC__bitmath_ilog2(order));
  93006. }
  93007. ret = FLAC__lpc_quantize_coefficients(lp_coeff, order, qlp_coeff_precision, qlp_coeff, &quantization);
  93008. if(ret != 0)
  93009. return 0; /* this is a hack to indicate to the caller that we can't do lp at this order on this subframe */
  93010. if(subframe_bps + qlp_coeff_precision + FLAC__bitmath_ilog2(order) <= 32)
  93011. if(subframe_bps <= 16 && qlp_coeff_precision <= 16)
  93012. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
  93013. else
  93014. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
  93015. else
  93016. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_64bit(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
  93017. subframe->type = FLAC__SUBFRAME_TYPE_LPC;
  93018. subframe->data.lpc.entropy_coding_method.type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE;
  93019. subframe->data.lpc.entropy_coding_method.data.partitioned_rice.contents = partitioned_rice_contents;
  93020. subframe->data.lpc.residual = residual;
  93021. residual_bits =
  93022. find_best_partition_order_(
  93023. encoder->private_,
  93024. residual,
  93025. abs_residual_partition_sums,
  93026. raw_bits_per_partition,
  93027. residual_samples,
  93028. order,
  93029. rice_parameter,
  93030. rice_parameter_limit,
  93031. min_partition_order,
  93032. max_partition_order,
  93033. subframe_bps,
  93034. do_escape_coding,
  93035. rice_parameter_search_dist,
  93036. &subframe->data.lpc.entropy_coding_method
  93037. );
  93038. subframe->data.lpc.order = order;
  93039. subframe->data.lpc.qlp_coeff_precision = qlp_coeff_precision;
  93040. subframe->data.lpc.quantization_level = quantization;
  93041. memcpy(subframe->data.lpc.qlp_coeff, qlp_coeff, sizeof(FLAC__int32)*FLAC__MAX_LPC_ORDER);
  93042. for(i = 0; i < order; i++)
  93043. subframe->data.lpc.warmup[i] = signal[i];
  93044. 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;
  93045. #if SPOTCHECK_ESTIMATE
  93046. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  93047. #endif
  93048. return estimate;
  93049. }
  93050. #endif
  93051. unsigned evaluate_verbatim_subframe_(
  93052. FLAC__StreamEncoder *encoder,
  93053. const FLAC__int32 signal[],
  93054. unsigned blocksize,
  93055. unsigned subframe_bps,
  93056. FLAC__Subframe *subframe
  93057. )
  93058. {
  93059. unsigned estimate;
  93060. subframe->type = FLAC__SUBFRAME_TYPE_VERBATIM;
  93061. subframe->data.verbatim.data = signal;
  93062. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + (blocksize * subframe_bps);
  93063. #if SPOTCHECK_ESTIMATE
  93064. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  93065. #else
  93066. (void)encoder;
  93067. #endif
  93068. return estimate;
  93069. }
  93070. unsigned find_best_partition_order_(
  93071. FLAC__StreamEncoderPrivate *private_,
  93072. const FLAC__int32 residual[],
  93073. FLAC__uint64 abs_residual_partition_sums[],
  93074. unsigned raw_bits_per_partition[],
  93075. unsigned residual_samples,
  93076. unsigned predictor_order,
  93077. unsigned rice_parameter,
  93078. unsigned rice_parameter_limit,
  93079. unsigned min_partition_order,
  93080. unsigned max_partition_order,
  93081. unsigned bps,
  93082. FLAC__bool do_escape_coding,
  93083. unsigned rice_parameter_search_dist,
  93084. FLAC__EntropyCodingMethod *best_ecm
  93085. )
  93086. {
  93087. unsigned residual_bits, best_residual_bits = 0;
  93088. unsigned best_parameters_index = 0;
  93089. unsigned best_partition_order = 0;
  93090. const unsigned blocksize = residual_samples + predictor_order;
  93091. max_partition_order = FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(max_partition_order, blocksize, predictor_order);
  93092. min_partition_order = min(min_partition_order, max_partition_order);
  93093. precompute_partition_info_sums_(residual, abs_residual_partition_sums, residual_samples, predictor_order, min_partition_order, max_partition_order, bps);
  93094. if(do_escape_coding)
  93095. precompute_partition_info_escapes_(residual, raw_bits_per_partition, residual_samples, predictor_order, min_partition_order, max_partition_order);
  93096. {
  93097. int partition_order;
  93098. unsigned sum;
  93099. for(partition_order = (int)max_partition_order, sum = 0; partition_order >= (int)min_partition_order; partition_order--) {
  93100. if(!
  93101. set_partitioned_rice_(
  93102. #ifdef EXACT_RICE_BITS_CALCULATION
  93103. residual,
  93104. #endif
  93105. abs_residual_partition_sums+sum,
  93106. raw_bits_per_partition+sum,
  93107. residual_samples,
  93108. predictor_order,
  93109. rice_parameter,
  93110. rice_parameter_limit,
  93111. rice_parameter_search_dist,
  93112. (unsigned)partition_order,
  93113. do_escape_coding,
  93114. &private_->partitioned_rice_contents_extra[!best_parameters_index],
  93115. &residual_bits
  93116. )
  93117. )
  93118. {
  93119. FLAC__ASSERT(best_residual_bits != 0);
  93120. break;
  93121. }
  93122. sum += 1u << partition_order;
  93123. if(best_residual_bits == 0 || residual_bits < best_residual_bits) {
  93124. best_residual_bits = residual_bits;
  93125. best_parameters_index = !best_parameters_index;
  93126. best_partition_order = partition_order;
  93127. }
  93128. }
  93129. }
  93130. best_ecm->data.partitioned_rice.order = best_partition_order;
  93131. {
  93132. FLAC__EntropyCodingMethod_PartitionedRiceContents* prc = (FLAC__EntropyCodingMethod_PartitionedRiceContents*)best_ecm->data.partitioned_rice.contents;
  93133. unsigned partition;
  93134. FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(prc, max(6, best_partition_order));
  93135. memcpy(prc->parameters, private_->partitioned_rice_contents_extra[best_parameters_index].parameters, sizeof(unsigned)*(1<<(best_partition_order)));
  93136. if(do_escape_coding)
  93137. memcpy(prc->raw_bits, private_->partitioned_rice_contents_extra[best_parameters_index].raw_bits, sizeof(unsigned)*(1<<(best_partition_order)));
  93138. for(partition = 0; partition < (1u<<best_partition_order); partition++) {
  93139. if(prc->parameters[partition] >= FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER) {
  93140. best_ecm->type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2;
  93141. break;
  93142. }
  93143. }
  93144. }
  93145. return best_residual_bits;
  93146. }
  93147. #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM
  93148. extern void precompute_partition_info_sums_32bit_asm_ia32_(
  93149. const FLAC__int32 residual[],
  93150. FLAC__uint64 abs_residual_partition_sums[],
  93151. unsigned blocksize,
  93152. unsigned predictor_order,
  93153. unsigned min_partition_order,
  93154. unsigned max_partition_order
  93155. );
  93156. #endif
  93157. void precompute_partition_info_sums_(
  93158. const FLAC__int32 residual[],
  93159. FLAC__uint64 abs_residual_partition_sums[],
  93160. unsigned residual_samples,
  93161. unsigned predictor_order,
  93162. unsigned min_partition_order,
  93163. unsigned max_partition_order,
  93164. unsigned bps
  93165. )
  93166. {
  93167. const unsigned default_partition_samples = (residual_samples + predictor_order) >> max_partition_order;
  93168. unsigned partitions = 1u << max_partition_order;
  93169. FLAC__ASSERT(default_partition_samples > predictor_order);
  93170. #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM
  93171. if(FLAC__bitmath_ilog2(default_partition_samples) + bps < 32) {
  93172. precompute_partition_info_sums_32bit_asm_ia32_(residual, abs_residual_partition_sums, residual_samples + predictor_order, predictor_order, min_partition_order, max_partition_order);
  93173. return;
  93174. }
  93175. #endif
  93176. {
  93177. unsigned partition, residual_sample, end = (unsigned)(-(int)predictor_order);
  93178. if(FLAC__bitmath_ilog2(default_partition_samples) + bps < 32) {
  93179. FLAC__uint32 abs_residual_partition_sum;
  93180. for(partition = residual_sample = 0; partition < partitions; partition++) {
  93181. end += default_partition_samples;
  93182. abs_residual_partition_sum = 0;
  93183. for( ; residual_sample < end; residual_sample++)
  93184. abs_residual_partition_sum += abs(residual[residual_sample]); /* abs(INT_MIN) is undefined, but if the residual is INT_MIN we have bigger problems */
  93185. abs_residual_partition_sums[partition] = abs_residual_partition_sum;
  93186. }
  93187. }
  93188. else { /* have to pessimistically use 64 bits for accumulator */
  93189. FLAC__uint64 abs_residual_partition_sum;
  93190. for(partition = residual_sample = 0; partition < partitions; partition++) {
  93191. end += default_partition_samples;
  93192. abs_residual_partition_sum = 0;
  93193. for( ; residual_sample < end; residual_sample++)
  93194. abs_residual_partition_sum += abs(residual[residual_sample]); /* abs(INT_MIN) is undefined, but if the residual is INT_MIN we have bigger problems */
  93195. abs_residual_partition_sums[partition] = abs_residual_partition_sum;
  93196. }
  93197. }
  93198. }
  93199. {
  93200. unsigned from_partition = 0, to_partition = partitions;
  93201. int partition_order;
  93202. for(partition_order = (int)max_partition_order - 1; partition_order >= (int)min_partition_order; partition_order--) {
  93203. unsigned i;
  93204. partitions >>= 1;
  93205. for(i = 0; i < partitions; i++) {
  93206. abs_residual_partition_sums[to_partition++] =
  93207. abs_residual_partition_sums[from_partition ] +
  93208. abs_residual_partition_sums[from_partition+1];
  93209. from_partition += 2;
  93210. }
  93211. }
  93212. }
  93213. }
  93214. void precompute_partition_info_escapes_(
  93215. const FLAC__int32 residual[],
  93216. unsigned raw_bits_per_partition[],
  93217. unsigned residual_samples,
  93218. unsigned predictor_order,
  93219. unsigned min_partition_order,
  93220. unsigned max_partition_order
  93221. )
  93222. {
  93223. int partition_order;
  93224. unsigned from_partition, to_partition = 0;
  93225. const unsigned blocksize = residual_samples + predictor_order;
  93226. for(partition_order = (int)max_partition_order; partition_order >= 0; partition_order--) {
  93227. FLAC__int32 r;
  93228. FLAC__uint32 rmax;
  93229. unsigned partition, partition_sample, partition_samples, residual_sample;
  93230. const unsigned partitions = 1u << partition_order;
  93231. const unsigned default_partition_samples = blocksize >> partition_order;
  93232. FLAC__ASSERT(default_partition_samples > predictor_order);
  93233. for(partition = residual_sample = 0; partition < partitions; partition++) {
  93234. partition_samples = default_partition_samples;
  93235. if(partition == 0)
  93236. partition_samples -= predictor_order;
  93237. rmax = 0;
  93238. for(partition_sample = 0; partition_sample < partition_samples; partition_sample++) {
  93239. r = residual[residual_sample++];
  93240. if(r < 0)
  93241. rmax |= ~r;
  93242. else
  93243. rmax |= r;
  93244. }
  93245. raw_bits_per_partition[partition] = rmax? FLAC__bitmath_ilog2(rmax) + 2 : 1;
  93246. }
  93247. to_partition = partitions;
  93248. break; /*@@@ yuck, should remove the 'for' loop instead */
  93249. }
  93250. for(from_partition = 0, --partition_order; partition_order >= (int)min_partition_order; partition_order--) {
  93251. unsigned m;
  93252. unsigned i;
  93253. const unsigned partitions = 1u << partition_order;
  93254. for(i = 0; i < partitions; i++) {
  93255. m = raw_bits_per_partition[from_partition];
  93256. from_partition++;
  93257. raw_bits_per_partition[to_partition] = max(m, raw_bits_per_partition[from_partition]);
  93258. from_partition++;
  93259. to_partition++;
  93260. }
  93261. }
  93262. }
  93263. #ifdef EXACT_RICE_BITS_CALCULATION
  93264. static FLaC__INLINE unsigned count_rice_bits_in_partition_(
  93265. const unsigned rice_parameter,
  93266. const unsigned partition_samples,
  93267. const FLAC__int32 *residual
  93268. )
  93269. {
  93270. unsigned i, partition_bits =
  93271. 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 */
  93272. (1+rice_parameter) * partition_samples /* 1 for unary stop bit + rice_parameter for the binary portion */
  93273. ;
  93274. for(i = 0; i < partition_samples; i++)
  93275. partition_bits += ( (FLAC__uint32)((residual[i]<<1)^(residual[i]>>31)) >> rice_parameter );
  93276. return partition_bits;
  93277. }
  93278. #else
  93279. static FLaC__INLINE unsigned count_rice_bits_in_partition_(
  93280. const unsigned rice_parameter,
  93281. const unsigned partition_samples,
  93282. const FLAC__uint64 abs_residual_partition_sum
  93283. )
  93284. {
  93285. return
  93286. 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 */
  93287. (1+rice_parameter) * partition_samples + /* 1 for unary stop bit + rice_parameter for the binary portion */
  93288. (
  93289. rice_parameter?
  93290. (unsigned)(abs_residual_partition_sum >> (rice_parameter-1)) /* rice_parameter-1 because the real coder sign-folds instead of using a sign bit */
  93291. : (unsigned)(abs_residual_partition_sum << 1) /* can't shift by negative number, so reverse */
  93292. )
  93293. - (partition_samples >> 1)
  93294. ;
  93295. }
  93296. #endif
  93297. FLAC__bool set_partitioned_rice_(
  93298. #ifdef EXACT_RICE_BITS_CALCULATION
  93299. const FLAC__int32 residual[],
  93300. #endif
  93301. const FLAC__uint64 abs_residual_partition_sums[],
  93302. const unsigned raw_bits_per_partition[],
  93303. const unsigned residual_samples,
  93304. const unsigned predictor_order,
  93305. const unsigned suggested_rice_parameter,
  93306. const unsigned rice_parameter_limit,
  93307. const unsigned rice_parameter_search_dist,
  93308. const unsigned partition_order,
  93309. const FLAC__bool search_for_escapes,
  93310. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents,
  93311. unsigned *bits
  93312. )
  93313. {
  93314. unsigned rice_parameter, partition_bits;
  93315. unsigned best_partition_bits, best_rice_parameter = 0;
  93316. unsigned bits_ = FLAC__ENTROPY_CODING_METHOD_TYPE_LEN + FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN;
  93317. unsigned *parameters, *raw_bits;
  93318. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  93319. unsigned min_rice_parameter, max_rice_parameter;
  93320. #else
  93321. (void)rice_parameter_search_dist;
  93322. #endif
  93323. FLAC__ASSERT(suggested_rice_parameter < FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER);
  93324. FLAC__ASSERT(rice_parameter_limit <= FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER);
  93325. FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(partitioned_rice_contents, max(6, partition_order));
  93326. parameters = partitioned_rice_contents->parameters;
  93327. raw_bits = partitioned_rice_contents->raw_bits;
  93328. if(partition_order == 0) {
  93329. best_partition_bits = (unsigned)(-1);
  93330. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  93331. if(rice_parameter_search_dist) {
  93332. if(suggested_rice_parameter < rice_parameter_search_dist)
  93333. min_rice_parameter = 0;
  93334. else
  93335. min_rice_parameter = suggested_rice_parameter - rice_parameter_search_dist;
  93336. max_rice_parameter = suggested_rice_parameter + rice_parameter_search_dist;
  93337. if(max_rice_parameter >= rice_parameter_limit) {
  93338. #ifdef DEBUG_VERBOSE
  93339. fprintf(stderr, "clipping rice_parameter (%u -> %u) @5\n", max_rice_parameter, rice_parameter_limit - 1);
  93340. #endif
  93341. max_rice_parameter = rice_parameter_limit - 1;
  93342. }
  93343. }
  93344. else
  93345. min_rice_parameter = max_rice_parameter = suggested_rice_parameter;
  93346. for(rice_parameter = min_rice_parameter; rice_parameter <= max_rice_parameter; rice_parameter++) {
  93347. #else
  93348. rice_parameter = suggested_rice_parameter;
  93349. #endif
  93350. #ifdef EXACT_RICE_BITS_CALCULATION
  93351. partition_bits = count_rice_bits_in_partition_(rice_parameter, residual_samples, residual);
  93352. #else
  93353. partition_bits = count_rice_bits_in_partition_(rice_parameter, residual_samples, abs_residual_partition_sums[0]);
  93354. #endif
  93355. if(partition_bits < best_partition_bits) {
  93356. best_rice_parameter = rice_parameter;
  93357. best_partition_bits = partition_bits;
  93358. }
  93359. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  93360. }
  93361. #endif
  93362. if(search_for_escapes) {
  93363. 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;
  93364. if(partition_bits <= best_partition_bits) {
  93365. raw_bits[0] = raw_bits_per_partition[0];
  93366. best_rice_parameter = 0; /* will be converted to appropriate escape parameter later */
  93367. best_partition_bits = partition_bits;
  93368. }
  93369. else
  93370. raw_bits[0] = 0;
  93371. }
  93372. parameters[0] = best_rice_parameter;
  93373. bits_ += best_partition_bits;
  93374. }
  93375. else {
  93376. unsigned partition, residual_sample;
  93377. unsigned partition_samples;
  93378. FLAC__uint64 mean, k;
  93379. const unsigned partitions = 1u << partition_order;
  93380. for(partition = residual_sample = 0; partition < partitions; partition++) {
  93381. partition_samples = (residual_samples+predictor_order) >> partition_order;
  93382. if(partition == 0) {
  93383. if(partition_samples <= predictor_order)
  93384. return false;
  93385. else
  93386. partition_samples -= predictor_order;
  93387. }
  93388. mean = abs_residual_partition_sums[partition];
  93389. for(rice_parameter = 0, k = partition_samples; k < mean; rice_parameter++, k <<= 1)
  93390. ;
  93391. if(rice_parameter >= rice_parameter_limit) {
  93392. #ifdef DEBUG_VERBOSE
  93393. fprintf(stderr, "clipping rice_parameter (%u -> %u) @6\n", rice_parameter, rice_parameter_limit - 1);
  93394. #endif
  93395. rice_parameter = rice_parameter_limit - 1;
  93396. }
  93397. best_partition_bits = (unsigned)(-1);
  93398. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  93399. if(rice_parameter_search_dist) {
  93400. if(rice_parameter < rice_parameter_search_dist)
  93401. min_rice_parameter = 0;
  93402. else
  93403. min_rice_parameter = rice_parameter - rice_parameter_search_dist;
  93404. max_rice_parameter = rice_parameter + rice_parameter_search_dist;
  93405. if(max_rice_parameter >= rice_parameter_limit) {
  93406. #ifdef DEBUG_VERBOSE
  93407. fprintf(stderr, "clipping rice_parameter (%u -> %u) @7\n", max_rice_parameter, rice_parameter_limit - 1);
  93408. #endif
  93409. max_rice_parameter = rice_parameter_limit - 1;
  93410. }
  93411. }
  93412. else
  93413. min_rice_parameter = max_rice_parameter = rice_parameter;
  93414. for(rice_parameter = min_rice_parameter; rice_parameter <= max_rice_parameter; rice_parameter++) {
  93415. #endif
  93416. #ifdef EXACT_RICE_BITS_CALCULATION
  93417. partition_bits = count_rice_bits_in_partition_(rice_parameter, partition_samples, residual+residual_sample);
  93418. #else
  93419. partition_bits = count_rice_bits_in_partition_(rice_parameter, partition_samples, abs_residual_partition_sums[partition]);
  93420. #endif
  93421. if(partition_bits < best_partition_bits) {
  93422. best_rice_parameter = rice_parameter;
  93423. best_partition_bits = partition_bits;
  93424. }
  93425. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  93426. }
  93427. #endif
  93428. if(search_for_escapes) {
  93429. 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;
  93430. if(partition_bits <= best_partition_bits) {
  93431. raw_bits[partition] = raw_bits_per_partition[partition];
  93432. best_rice_parameter = 0; /* will be converted to appropriate escape parameter later */
  93433. best_partition_bits = partition_bits;
  93434. }
  93435. else
  93436. raw_bits[partition] = 0;
  93437. }
  93438. parameters[partition] = best_rice_parameter;
  93439. bits_ += best_partition_bits;
  93440. residual_sample += partition_samples;
  93441. }
  93442. }
  93443. *bits = bits_;
  93444. return true;
  93445. }
  93446. unsigned get_wasted_bits_(FLAC__int32 signal[], unsigned samples)
  93447. {
  93448. unsigned i, shift;
  93449. FLAC__int32 x = 0;
  93450. for(i = 0; i < samples && !(x&1); i++)
  93451. x |= signal[i];
  93452. if(x == 0) {
  93453. shift = 0;
  93454. }
  93455. else {
  93456. for(shift = 0; !(x&1); shift++)
  93457. x >>= 1;
  93458. }
  93459. if(shift > 0) {
  93460. for(i = 0; i < samples; i++)
  93461. signal[i] >>= shift;
  93462. }
  93463. return shift;
  93464. }
  93465. void append_to_verify_fifo_(verify_input_fifo *fifo, const FLAC__int32 * const input[], unsigned input_offset, unsigned channels, unsigned wide_samples)
  93466. {
  93467. unsigned channel;
  93468. for(channel = 0; channel < channels; channel++)
  93469. memcpy(&fifo->data[channel][fifo->tail], &input[channel][input_offset], sizeof(FLAC__int32) * wide_samples);
  93470. fifo->tail += wide_samples;
  93471. FLAC__ASSERT(fifo->tail <= fifo->size);
  93472. }
  93473. void append_to_verify_fifo_interleaved_(verify_input_fifo *fifo, const FLAC__int32 input[], unsigned input_offset, unsigned channels, unsigned wide_samples)
  93474. {
  93475. unsigned channel;
  93476. unsigned sample, wide_sample;
  93477. unsigned tail = fifo->tail;
  93478. sample = input_offset * channels;
  93479. for(wide_sample = 0; wide_sample < wide_samples; wide_sample++) {
  93480. for(channel = 0; channel < channels; channel++)
  93481. fifo->data[channel][tail] = input[sample++];
  93482. tail++;
  93483. }
  93484. fifo->tail = tail;
  93485. FLAC__ASSERT(fifo->tail <= fifo->size);
  93486. }
  93487. FLAC__StreamDecoderReadStatus verify_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  93488. {
  93489. FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder*)client_data;
  93490. const size_t encoded_bytes = encoder->private_->verify.output.bytes;
  93491. (void)decoder;
  93492. if(encoder->private_->verify.needs_magic_hack) {
  93493. FLAC__ASSERT(*bytes >= FLAC__STREAM_SYNC_LENGTH);
  93494. *bytes = FLAC__STREAM_SYNC_LENGTH;
  93495. memcpy(buffer, FLAC__STREAM_SYNC_STRING, *bytes);
  93496. encoder->private_->verify.needs_magic_hack = false;
  93497. }
  93498. else {
  93499. if(encoded_bytes == 0) {
  93500. FLAC__ASSERT(0);
  93501. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  93502. }
  93503. else if(encoded_bytes < *bytes)
  93504. *bytes = encoded_bytes;
  93505. memcpy(buffer, encoder->private_->verify.output.data, *bytes);
  93506. encoder->private_->verify.output.data += *bytes;
  93507. encoder->private_->verify.output.bytes -= *bytes;
  93508. }
  93509. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  93510. }
  93511. FLAC__StreamDecoderWriteStatus verify_write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data)
  93512. {
  93513. FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder *)client_data;
  93514. unsigned channel;
  93515. const unsigned channels = frame->header.channels;
  93516. const unsigned blocksize = frame->header.blocksize;
  93517. const unsigned bytes_per_block = sizeof(FLAC__int32) * blocksize;
  93518. (void)decoder;
  93519. for(channel = 0; channel < channels; channel++) {
  93520. if(0 != memcmp(buffer[channel], encoder->private_->verify.input_fifo.data[channel], bytes_per_block)) {
  93521. unsigned i, sample = 0;
  93522. FLAC__int32 expect = 0, got = 0;
  93523. for(i = 0; i < blocksize; i++) {
  93524. if(buffer[channel][i] != encoder->private_->verify.input_fifo.data[channel][i]) {
  93525. sample = i;
  93526. expect = (FLAC__int32)encoder->private_->verify.input_fifo.data[channel][i];
  93527. got = (FLAC__int32)buffer[channel][i];
  93528. break;
  93529. }
  93530. }
  93531. FLAC__ASSERT(i < blocksize);
  93532. FLAC__ASSERT(frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  93533. encoder->private_->verify.error_stats.absolute_sample = frame->header.number.sample_number + sample;
  93534. encoder->private_->verify.error_stats.frame_number = (unsigned)(frame->header.number.sample_number / blocksize);
  93535. encoder->private_->verify.error_stats.channel = channel;
  93536. encoder->private_->verify.error_stats.sample = sample;
  93537. encoder->private_->verify.error_stats.expected = expect;
  93538. encoder->private_->verify.error_stats.got = got;
  93539. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA;
  93540. return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
  93541. }
  93542. }
  93543. encoder->private_->verify.input_fifo.tail -= blocksize;
  93544. FLAC__ASSERT(encoder->private_->verify.input_fifo.tail <= OVERREAD_);
  93545. for(channel = 0; channel < channels; channel++)
  93546. 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]));
  93547. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  93548. }
  93549. void verify_metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data)
  93550. {
  93551. (void)decoder, (void)metadata, (void)client_data;
  93552. }
  93553. void verify_error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data)
  93554. {
  93555. FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder*)client_data;
  93556. (void)decoder, (void)status;
  93557. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  93558. }
  93559. FLAC__StreamEncoderReadStatus file_read_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  93560. {
  93561. (void)client_data;
  93562. *bytes = fread(buffer, 1, *bytes, encoder->private_->file);
  93563. if (*bytes == 0) {
  93564. if (feof(encoder->private_->file))
  93565. return FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM;
  93566. else if (ferror(encoder->private_->file))
  93567. return FLAC__STREAM_ENCODER_READ_STATUS_ABORT;
  93568. }
  93569. return FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE;
  93570. }
  93571. FLAC__StreamEncoderSeekStatus file_seek_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data)
  93572. {
  93573. (void)client_data;
  93574. if(fseeko(encoder->private_->file, (off_t)absolute_byte_offset, SEEK_SET) < 0)
  93575. return FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR;
  93576. else
  93577. return FLAC__STREAM_ENCODER_SEEK_STATUS_OK;
  93578. }
  93579. FLAC__StreamEncoderTellStatus file_tell_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
  93580. {
  93581. off_t offset;
  93582. (void)client_data;
  93583. offset = ftello(encoder->private_->file);
  93584. if(offset < 0) {
  93585. return FLAC__STREAM_ENCODER_TELL_STATUS_ERROR;
  93586. }
  93587. else {
  93588. *absolute_byte_offset = (FLAC__uint64)offset;
  93589. return FLAC__STREAM_ENCODER_TELL_STATUS_OK;
  93590. }
  93591. }
  93592. #ifdef FLAC__VALGRIND_TESTING
  93593. static size_t local__fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
  93594. {
  93595. size_t ret = fwrite(ptr, size, nmemb, stream);
  93596. if(!ferror(stream))
  93597. fflush(stream);
  93598. return ret;
  93599. }
  93600. #else
  93601. #define local__fwrite fwrite
  93602. #endif
  93603. FLAC__StreamEncoderWriteStatus file_write_callback_(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame, void *client_data)
  93604. {
  93605. (void)client_data, (void)current_frame;
  93606. if(local__fwrite(buffer, sizeof(FLAC__byte), bytes, encoder->private_->file) == bytes) {
  93607. FLAC__bool call_it = 0 != encoder->private_->progress_callback && (
  93608. #if FLAC__HAS_OGG
  93609. encoder->private_->is_ogg? true :
  93610. #endif
  93611. samples > 0
  93612. );
  93613. if(call_it) {
  93614. 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);
  93615. }
  93616. return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
  93617. }
  93618. else
  93619. return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
  93620. }
  93621. FILE *get_binary_stdout_(void)
  93622. {
  93623. #if defined _MSC_VER || defined __MINGW32__
  93624. _setmode(_fileno(stdout), _O_BINARY);
  93625. #elif defined __CYGWIN__
  93626. setmode(_fileno(stdout), _O_BINARY);
  93627. #elif defined __EMX__
  93628. setmode(fileno(stdout), O_BINARY);
  93629. #endif
  93630. return stdout;
  93631. }
  93632. #endif
  93633. /*** End of inlined file: stream_encoder.c ***/
  93634. /*** Start of inlined file: stream_encoder_framing.c ***/
  93635. /*** Start of inlined file: juce_FlacHeader.h ***/
  93636. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  93637. // tasks..
  93638. #define VERSION "1.2.1"
  93639. #define FLAC__NO_DLL 1
  93640. #if JUCE_MSVC
  93641. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  93642. #endif
  93643. #if JUCE_MAC
  93644. #define FLAC__SYS_DARWIN 1
  93645. #endif
  93646. /*** End of inlined file: juce_FlacHeader.h ***/
  93647. #if JUCE_USE_FLAC
  93648. #if HAVE_CONFIG_H
  93649. # include <config.h>
  93650. #endif
  93651. #include <stdio.h>
  93652. #include <string.h> /* for strlen() */
  93653. #ifdef max
  93654. #undef max
  93655. #endif
  93656. #define max(x,y) ((x)>(y)?(x):(y))
  93657. static FLAC__bool add_entropy_coding_method_(FLAC__BitWriter *bw, const FLAC__EntropyCodingMethod *method);
  93658. 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);
  93659. FLAC__bool FLAC__add_metadata_block(const FLAC__StreamMetadata *metadata, FLAC__BitWriter *bw)
  93660. {
  93661. unsigned i, j;
  93662. const unsigned vendor_string_length = (unsigned)strlen(FLAC__VENDOR_STRING);
  93663. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->is_last, FLAC__STREAM_METADATA_IS_LAST_LEN))
  93664. return false;
  93665. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->type, FLAC__STREAM_METADATA_TYPE_LEN))
  93666. return false;
  93667. i = metadata->length;
  93668. if(metadata->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
  93669. FLAC__ASSERT(metadata->data.vorbis_comment.vendor_string.length == 0 || 0 != metadata->data.vorbis_comment.vendor_string.entry);
  93670. i -= metadata->data.vorbis_comment.vendor_string.length;
  93671. i += vendor_string_length;
  93672. }
  93673. FLAC__ASSERT(i < (1u << FLAC__STREAM_METADATA_LENGTH_LEN));
  93674. if(!FLAC__bitwriter_write_raw_uint32(bw, i, FLAC__STREAM_METADATA_LENGTH_LEN))
  93675. return false;
  93676. switch(metadata->type) {
  93677. case FLAC__METADATA_TYPE_STREAMINFO:
  93678. FLAC__ASSERT(metadata->data.stream_info.min_blocksize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN));
  93679. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.min_blocksize, FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN))
  93680. return false;
  93681. FLAC__ASSERT(metadata->data.stream_info.max_blocksize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN));
  93682. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.max_blocksize, FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN))
  93683. return false;
  93684. FLAC__ASSERT(metadata->data.stream_info.min_framesize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN));
  93685. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.min_framesize, FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN))
  93686. return false;
  93687. FLAC__ASSERT(metadata->data.stream_info.max_framesize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN));
  93688. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.max_framesize, FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN))
  93689. return false;
  93690. FLAC__ASSERT(FLAC__format_sample_rate_is_valid(metadata->data.stream_info.sample_rate));
  93691. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.sample_rate, FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN))
  93692. return false;
  93693. FLAC__ASSERT(metadata->data.stream_info.channels > 0);
  93694. FLAC__ASSERT(metadata->data.stream_info.channels <= (1u << FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN));
  93695. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.channels-1, FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN))
  93696. return false;
  93697. FLAC__ASSERT(metadata->data.stream_info.bits_per_sample > 0);
  93698. FLAC__ASSERT(metadata->data.stream_info.bits_per_sample <= (1u << FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN));
  93699. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.bits_per_sample-1, FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN))
  93700. return false;
  93701. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.stream_info.total_samples, FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN))
  93702. return false;
  93703. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.stream_info.md5sum, 16))
  93704. return false;
  93705. break;
  93706. case FLAC__METADATA_TYPE_PADDING:
  93707. if(!FLAC__bitwriter_write_zeroes(bw, metadata->length * 8))
  93708. return false;
  93709. break;
  93710. case FLAC__METADATA_TYPE_APPLICATION:
  93711. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.application.id, FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8))
  93712. return false;
  93713. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.application.data, metadata->length - (FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8)))
  93714. return false;
  93715. break;
  93716. case FLAC__METADATA_TYPE_SEEKTABLE:
  93717. for(i = 0; i < metadata->data.seek_table.num_points; i++) {
  93718. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.seek_table.points[i].sample_number, FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN))
  93719. return false;
  93720. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.seek_table.points[i].stream_offset, FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN))
  93721. return false;
  93722. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.seek_table.points[i].frame_samples, FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN))
  93723. return false;
  93724. }
  93725. break;
  93726. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  93727. if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, vendor_string_length))
  93728. return false;
  93729. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)FLAC__VENDOR_STRING, vendor_string_length))
  93730. return false;
  93731. if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, metadata->data.vorbis_comment.num_comments))
  93732. return false;
  93733. for(i = 0; i < metadata->data.vorbis_comment.num_comments; i++) {
  93734. if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, metadata->data.vorbis_comment.comments[i].length))
  93735. return false;
  93736. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.vorbis_comment.comments[i].entry, metadata->data.vorbis_comment.comments[i].length))
  93737. return false;
  93738. }
  93739. break;
  93740. case FLAC__METADATA_TYPE_CUESHEET:
  93741. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN % 8 == 0);
  93742. 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))
  93743. return false;
  93744. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.cue_sheet.lead_in, FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN))
  93745. return false;
  93746. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.cue_sheet.is_cd? 1 : 0, FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN))
  93747. return false;
  93748. if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN))
  93749. return false;
  93750. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.cue_sheet.num_tracks, FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN))
  93751. return false;
  93752. for(i = 0; i < metadata->data.cue_sheet.num_tracks; i++) {
  93753. const FLAC__StreamMetadata_CueSheet_Track *track = metadata->data.cue_sheet.tracks + i;
  93754. if(!FLAC__bitwriter_write_raw_uint64(bw, track->offset, FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN))
  93755. return false;
  93756. if(!FLAC__bitwriter_write_raw_uint32(bw, track->number, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN))
  93757. return false;
  93758. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN % 8 == 0);
  93759. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)track->isrc, FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN/8))
  93760. return false;
  93761. if(!FLAC__bitwriter_write_raw_uint32(bw, track->type, FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN))
  93762. return false;
  93763. if(!FLAC__bitwriter_write_raw_uint32(bw, track->pre_emphasis, FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN))
  93764. return false;
  93765. if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN))
  93766. return false;
  93767. if(!FLAC__bitwriter_write_raw_uint32(bw, track->num_indices, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN))
  93768. return false;
  93769. for(j = 0; j < track->num_indices; j++) {
  93770. const FLAC__StreamMetadata_CueSheet_Index *index = track->indices + j;
  93771. if(!FLAC__bitwriter_write_raw_uint64(bw, index->offset, FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN))
  93772. return false;
  93773. if(!FLAC__bitwriter_write_raw_uint32(bw, index->number, FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN))
  93774. return false;
  93775. if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN))
  93776. return false;
  93777. }
  93778. }
  93779. break;
  93780. case FLAC__METADATA_TYPE_PICTURE:
  93781. {
  93782. size_t len;
  93783. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.type, FLAC__STREAM_METADATA_PICTURE_TYPE_LEN))
  93784. return false;
  93785. len = strlen(metadata->data.picture.mime_type);
  93786. if(!FLAC__bitwriter_write_raw_uint32(bw, len, FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN))
  93787. return false;
  93788. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)metadata->data.picture.mime_type, len))
  93789. return false;
  93790. len = strlen((const char *)metadata->data.picture.description);
  93791. if(!FLAC__bitwriter_write_raw_uint32(bw, len, FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN))
  93792. return false;
  93793. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.picture.description, len))
  93794. return false;
  93795. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.width, FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN))
  93796. return false;
  93797. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.height, FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN))
  93798. return false;
  93799. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.depth, FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN))
  93800. return false;
  93801. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.colors, FLAC__STREAM_METADATA_PICTURE_COLORS_LEN))
  93802. return false;
  93803. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.data_length, FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN))
  93804. return false;
  93805. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.picture.data, metadata->data.picture.data_length))
  93806. return false;
  93807. }
  93808. break;
  93809. default:
  93810. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.unknown.data, metadata->length))
  93811. return false;
  93812. break;
  93813. }
  93814. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(bw));
  93815. return true;
  93816. }
  93817. FLAC__bool FLAC__frame_add_header(const FLAC__FrameHeader *header, FLAC__BitWriter *bw)
  93818. {
  93819. unsigned u, blocksize_hint, sample_rate_hint;
  93820. FLAC__byte crc;
  93821. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(bw));
  93822. if(!FLAC__bitwriter_write_raw_uint32(bw, FLAC__FRAME_HEADER_SYNC, FLAC__FRAME_HEADER_SYNC_LEN))
  93823. return false;
  93824. if(!FLAC__bitwriter_write_raw_uint32(bw, 0, FLAC__FRAME_HEADER_RESERVED_LEN))
  93825. return false;
  93826. if(!FLAC__bitwriter_write_raw_uint32(bw, (header->number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER)? 0 : 1, FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN))
  93827. return false;
  93828. FLAC__ASSERT(header->blocksize > 0 && header->blocksize <= FLAC__MAX_BLOCK_SIZE);
  93829. FLAC__ASSERT(FLAC__MAX_BLOCK_SIZE <= 65535u);
  93830. blocksize_hint = 0;
  93831. switch(header->blocksize) {
  93832. case 192: u = 1; break;
  93833. case 576: u = 2; break;
  93834. case 1152: u = 3; break;
  93835. case 2304: u = 4; break;
  93836. case 4608: u = 5; break;
  93837. case 256: u = 8; break;
  93838. case 512: u = 9; break;
  93839. case 1024: u = 10; break;
  93840. case 2048: u = 11; break;
  93841. case 4096: u = 12; break;
  93842. case 8192: u = 13; break;
  93843. case 16384: u = 14; break;
  93844. case 32768: u = 15; break;
  93845. default:
  93846. if(header->blocksize <= 0x100)
  93847. blocksize_hint = u = 6;
  93848. else
  93849. blocksize_hint = u = 7;
  93850. break;
  93851. }
  93852. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_BLOCK_SIZE_LEN))
  93853. return false;
  93854. FLAC__ASSERT(FLAC__format_sample_rate_is_valid(header->sample_rate));
  93855. sample_rate_hint = 0;
  93856. switch(header->sample_rate) {
  93857. case 88200: u = 1; break;
  93858. case 176400: u = 2; break;
  93859. case 192000: u = 3; break;
  93860. case 8000: u = 4; break;
  93861. case 16000: u = 5; break;
  93862. case 22050: u = 6; break;
  93863. case 24000: u = 7; break;
  93864. case 32000: u = 8; break;
  93865. case 44100: u = 9; break;
  93866. case 48000: u = 10; break;
  93867. case 96000: u = 11; break;
  93868. default:
  93869. if(header->sample_rate <= 255000 && header->sample_rate % 1000 == 0)
  93870. sample_rate_hint = u = 12;
  93871. else if(header->sample_rate % 10 == 0)
  93872. sample_rate_hint = u = 14;
  93873. else if(header->sample_rate <= 0xffff)
  93874. sample_rate_hint = u = 13;
  93875. else
  93876. u = 0;
  93877. break;
  93878. }
  93879. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_SAMPLE_RATE_LEN))
  93880. return false;
  93881. FLAC__ASSERT(header->channels > 0 && header->channels <= (1u << FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN) && header->channels <= FLAC__MAX_CHANNELS);
  93882. switch(header->channel_assignment) {
  93883. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  93884. u = header->channels - 1;
  93885. break;
  93886. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  93887. FLAC__ASSERT(header->channels == 2);
  93888. u = 8;
  93889. break;
  93890. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  93891. FLAC__ASSERT(header->channels == 2);
  93892. u = 9;
  93893. break;
  93894. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  93895. FLAC__ASSERT(header->channels == 2);
  93896. u = 10;
  93897. break;
  93898. default:
  93899. FLAC__ASSERT(0);
  93900. }
  93901. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN))
  93902. return false;
  93903. FLAC__ASSERT(header->bits_per_sample > 0 && header->bits_per_sample <= (1u << FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN));
  93904. switch(header->bits_per_sample) {
  93905. case 8 : u = 1; break;
  93906. case 12: u = 2; break;
  93907. case 16: u = 4; break;
  93908. case 20: u = 5; break;
  93909. case 24: u = 6; break;
  93910. default: u = 0; break;
  93911. }
  93912. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN))
  93913. return false;
  93914. if(!FLAC__bitwriter_write_raw_uint32(bw, 0, FLAC__FRAME_HEADER_ZERO_PAD_LEN))
  93915. return false;
  93916. if(header->number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER) {
  93917. if(!FLAC__bitwriter_write_utf8_uint32(bw, header->number.frame_number))
  93918. return false;
  93919. }
  93920. else {
  93921. if(!FLAC__bitwriter_write_utf8_uint64(bw, header->number.sample_number))
  93922. return false;
  93923. }
  93924. if(blocksize_hint)
  93925. if(!FLAC__bitwriter_write_raw_uint32(bw, header->blocksize-1, (blocksize_hint==6)? 8:16))
  93926. return false;
  93927. switch(sample_rate_hint) {
  93928. case 12:
  93929. if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate / 1000, 8))
  93930. return false;
  93931. break;
  93932. case 13:
  93933. if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate, 16))
  93934. return false;
  93935. break;
  93936. case 14:
  93937. if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate / 10, 16))
  93938. return false;
  93939. break;
  93940. }
  93941. if(!FLAC__bitwriter_get_write_crc8(bw, &crc))
  93942. return false;
  93943. if(!FLAC__bitwriter_write_raw_uint32(bw, crc, FLAC__FRAME_HEADER_CRC_LEN))
  93944. return false;
  93945. return true;
  93946. }
  93947. FLAC__bool FLAC__subframe_add_constant(const FLAC__Subframe_Constant *subframe, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93948. {
  93949. FLAC__bool ok;
  93950. ok =
  93951. 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) &&
  93952. (wasted_bits? FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1) : true) &&
  93953. FLAC__bitwriter_write_raw_int32(bw, subframe->value, subframe_bps)
  93954. ;
  93955. return ok;
  93956. }
  93957. FLAC__bool FLAC__subframe_add_fixed(const FLAC__Subframe_Fixed *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93958. {
  93959. unsigned i;
  93960. 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))
  93961. return false;
  93962. if(wasted_bits)
  93963. if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1))
  93964. return false;
  93965. for(i = 0; i < subframe->order; i++)
  93966. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->warmup[i], subframe_bps))
  93967. return false;
  93968. if(!add_entropy_coding_method_(bw, &subframe->entropy_coding_method))
  93969. return false;
  93970. switch(subframe->entropy_coding_method.type) {
  93971. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  93972. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  93973. if(!add_residual_partitioned_rice_(
  93974. bw,
  93975. subframe->residual,
  93976. residual_samples,
  93977. subframe->order,
  93978. subframe->entropy_coding_method.data.partitioned_rice.contents->parameters,
  93979. subframe->entropy_coding_method.data.partitioned_rice.contents->raw_bits,
  93980. subframe->entropy_coding_method.data.partitioned_rice.order,
  93981. subframe->entropy_coding_method.type == FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2
  93982. ))
  93983. return false;
  93984. break;
  93985. default:
  93986. FLAC__ASSERT(0);
  93987. }
  93988. return true;
  93989. }
  93990. FLAC__bool FLAC__subframe_add_lpc(const FLAC__Subframe_LPC *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93991. {
  93992. unsigned i;
  93993. 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))
  93994. return false;
  93995. if(wasted_bits)
  93996. if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1))
  93997. return false;
  93998. for(i = 0; i < subframe->order; i++)
  93999. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->warmup[i], subframe_bps))
  94000. return false;
  94001. if(!FLAC__bitwriter_write_raw_uint32(bw, subframe->qlp_coeff_precision-1, FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN))
  94002. return false;
  94003. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->quantization_level, FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN))
  94004. return false;
  94005. for(i = 0; i < subframe->order; i++)
  94006. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->qlp_coeff[i], subframe->qlp_coeff_precision))
  94007. return false;
  94008. if(!add_entropy_coding_method_(bw, &subframe->entropy_coding_method))
  94009. return false;
  94010. switch(subframe->entropy_coding_method.type) {
  94011. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  94012. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  94013. if(!add_residual_partitioned_rice_(
  94014. bw,
  94015. subframe->residual,
  94016. residual_samples,
  94017. subframe->order,
  94018. subframe->entropy_coding_method.data.partitioned_rice.contents->parameters,
  94019. subframe->entropy_coding_method.data.partitioned_rice.contents->raw_bits,
  94020. subframe->entropy_coding_method.data.partitioned_rice.order,
  94021. subframe->entropy_coding_method.type == FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2
  94022. ))
  94023. return false;
  94024. break;
  94025. default:
  94026. FLAC__ASSERT(0);
  94027. }
  94028. return true;
  94029. }
  94030. FLAC__bool FLAC__subframe_add_verbatim(const FLAC__Subframe_Verbatim *subframe, unsigned samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  94031. {
  94032. unsigned i;
  94033. const FLAC__int32 *signal = subframe->data;
  94034. 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))
  94035. return false;
  94036. if(wasted_bits)
  94037. if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1))
  94038. return false;
  94039. for(i = 0; i < samples; i++)
  94040. if(!FLAC__bitwriter_write_raw_int32(bw, signal[i], subframe_bps))
  94041. return false;
  94042. return true;
  94043. }
  94044. FLAC__bool add_entropy_coding_method_(FLAC__BitWriter *bw, const FLAC__EntropyCodingMethod *method)
  94045. {
  94046. if(!FLAC__bitwriter_write_raw_uint32(bw, method->type, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN))
  94047. return false;
  94048. switch(method->type) {
  94049. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  94050. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  94051. if(!FLAC__bitwriter_write_raw_uint32(bw, method->data.partitioned_rice.order, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  94052. return false;
  94053. break;
  94054. default:
  94055. FLAC__ASSERT(0);
  94056. }
  94057. return true;
  94058. }
  94059. 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)
  94060. {
  94061. const unsigned plen = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN;
  94062. const unsigned pesc = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  94063. if(partition_order == 0) {
  94064. unsigned i;
  94065. if(raw_bits[0] == 0) {
  94066. if(!FLAC__bitwriter_write_raw_uint32(bw, rice_parameters[0], plen))
  94067. return false;
  94068. if(!FLAC__bitwriter_write_rice_signed_block(bw, residual, residual_samples, rice_parameters[0]))
  94069. return false;
  94070. }
  94071. else {
  94072. FLAC__ASSERT(rice_parameters[0] == 0);
  94073. if(!FLAC__bitwriter_write_raw_uint32(bw, pesc, plen))
  94074. return false;
  94075. if(!FLAC__bitwriter_write_raw_uint32(bw, raw_bits[0], FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
  94076. return false;
  94077. for(i = 0; i < residual_samples; i++) {
  94078. if(!FLAC__bitwriter_write_raw_int32(bw, residual[i], raw_bits[0]))
  94079. return false;
  94080. }
  94081. }
  94082. return true;
  94083. }
  94084. else {
  94085. unsigned i, j, k = 0, k_last = 0;
  94086. unsigned partition_samples;
  94087. const unsigned default_partition_samples = (residual_samples+predictor_order) >> partition_order;
  94088. for(i = 0; i < (1u<<partition_order); i++) {
  94089. partition_samples = default_partition_samples;
  94090. if(i == 0)
  94091. partition_samples -= predictor_order;
  94092. k += partition_samples;
  94093. if(raw_bits[i] == 0) {
  94094. if(!FLAC__bitwriter_write_raw_uint32(bw, rice_parameters[i], plen))
  94095. return false;
  94096. if(!FLAC__bitwriter_write_rice_signed_block(bw, residual+k_last, k-k_last, rice_parameters[i]))
  94097. return false;
  94098. }
  94099. else {
  94100. if(!FLAC__bitwriter_write_raw_uint32(bw, pesc, plen))
  94101. return false;
  94102. if(!FLAC__bitwriter_write_raw_uint32(bw, raw_bits[i], FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
  94103. return false;
  94104. for(j = k_last; j < k; j++) {
  94105. if(!FLAC__bitwriter_write_raw_int32(bw, residual[j], raw_bits[i]))
  94106. return false;
  94107. }
  94108. }
  94109. k_last = k;
  94110. }
  94111. return true;
  94112. }
  94113. }
  94114. #endif
  94115. /*** End of inlined file: stream_encoder_framing.c ***/
  94116. /*** Start of inlined file: window_flac.c ***/
  94117. /*** Start of inlined file: juce_FlacHeader.h ***/
  94118. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  94119. // tasks..
  94120. #define VERSION "1.2.1"
  94121. #define FLAC__NO_DLL 1
  94122. #if JUCE_MSVC
  94123. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  94124. #endif
  94125. #if JUCE_MAC
  94126. #define FLAC__SYS_DARWIN 1
  94127. #endif
  94128. /*** End of inlined file: juce_FlacHeader.h ***/
  94129. #if JUCE_USE_FLAC
  94130. #if HAVE_CONFIG_H
  94131. # include <config.h>
  94132. #endif
  94133. #include <math.h>
  94134. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  94135. #ifndef M_PI
  94136. #define M_PI 3.14159265358979323846
  94137. #endif
  94138. void FLAC__window_bartlett(FLAC__real *window, const FLAC__int32 L)
  94139. {
  94140. const FLAC__int32 N = L - 1;
  94141. FLAC__int32 n;
  94142. if (L & 1) {
  94143. for (n = 0; n <= N/2; n++)
  94144. window[n] = 2.0f * n / (float)N;
  94145. for (; n <= N; n++)
  94146. window[n] = 2.0f - 2.0f * n / (float)N;
  94147. }
  94148. else {
  94149. for (n = 0; n <= L/2-1; n++)
  94150. window[n] = 2.0f * n / (float)N;
  94151. for (; n <= N; n++)
  94152. window[n] = 2.0f - 2.0f * (N-n) / (float)N;
  94153. }
  94154. }
  94155. void FLAC__window_bartlett_hann(FLAC__real *window, const FLAC__int32 L)
  94156. {
  94157. const FLAC__int32 N = L - 1;
  94158. FLAC__int32 n;
  94159. for (n = 0; n < L; n++)
  94160. 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)));
  94161. }
  94162. void FLAC__window_blackman(FLAC__real *window, const FLAC__int32 L)
  94163. {
  94164. const FLAC__int32 N = L - 1;
  94165. FLAC__int32 n;
  94166. for (n = 0; n < L; n++)
  94167. window[n] = (FLAC__real)(0.42f - 0.5f * cos(2.0f * M_PI * n / N) + 0.08f * cos(4.0f * M_PI * n / N));
  94168. }
  94169. void FLAC__window_blackman_harris_4term_92db_sidelobe(FLAC__real *window, const FLAC__int32 L)
  94170. {
  94171. const FLAC__int32 N = L - 1;
  94172. FLAC__int32 n;
  94173. for (n = 0; n <= N; n++)
  94174. 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));
  94175. }
  94176. void FLAC__window_connes(FLAC__real *window, const FLAC__int32 L)
  94177. {
  94178. const FLAC__int32 N = L - 1;
  94179. const double N2 = (double)N / 2.;
  94180. FLAC__int32 n;
  94181. for (n = 0; n <= N; n++) {
  94182. double k = ((double)n - N2) / N2;
  94183. k = 1.0f - k * k;
  94184. window[n] = (FLAC__real)(k * k);
  94185. }
  94186. }
  94187. void FLAC__window_flattop(FLAC__real *window, const FLAC__int32 L)
  94188. {
  94189. const FLAC__int32 N = L - 1;
  94190. FLAC__int32 n;
  94191. for (n = 0; n < L; n++)
  94192. 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));
  94193. }
  94194. void FLAC__window_gauss(FLAC__real *window, const FLAC__int32 L, const FLAC__real stddev)
  94195. {
  94196. const FLAC__int32 N = L - 1;
  94197. const double N2 = (double)N / 2.;
  94198. FLAC__int32 n;
  94199. for (n = 0; n <= N; n++) {
  94200. const double k = ((double)n - N2) / (stddev * N2);
  94201. window[n] = (FLAC__real)exp(-0.5f * k * k);
  94202. }
  94203. }
  94204. void FLAC__window_hamming(FLAC__real *window, const FLAC__int32 L)
  94205. {
  94206. const FLAC__int32 N = L - 1;
  94207. FLAC__int32 n;
  94208. for (n = 0; n < L; n++)
  94209. window[n] = (FLAC__real)(0.54f - 0.46f * cos(2.0f * M_PI * n / N));
  94210. }
  94211. void FLAC__window_hann(FLAC__real *window, const FLAC__int32 L)
  94212. {
  94213. const FLAC__int32 N = L - 1;
  94214. FLAC__int32 n;
  94215. for (n = 0; n < L; n++)
  94216. window[n] = (FLAC__real)(0.5f - 0.5f * cos(2.0f * M_PI * n / N));
  94217. }
  94218. void FLAC__window_kaiser_bessel(FLAC__real *window, const FLAC__int32 L)
  94219. {
  94220. const FLAC__int32 N = L - 1;
  94221. FLAC__int32 n;
  94222. for (n = 0; n < L; n++)
  94223. 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));
  94224. }
  94225. void FLAC__window_nuttall(FLAC__real *window, const FLAC__int32 L)
  94226. {
  94227. const FLAC__int32 N = L - 1;
  94228. FLAC__int32 n;
  94229. for (n = 0; n < L; n++)
  94230. 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));
  94231. }
  94232. void FLAC__window_rectangle(FLAC__real *window, const FLAC__int32 L)
  94233. {
  94234. FLAC__int32 n;
  94235. for (n = 0; n < L; n++)
  94236. window[n] = 1.0f;
  94237. }
  94238. void FLAC__window_triangle(FLAC__real *window, const FLAC__int32 L)
  94239. {
  94240. FLAC__int32 n;
  94241. if (L & 1) {
  94242. for (n = 1; n <= L+1/2; n++)
  94243. window[n-1] = 2.0f * n / ((float)L + 1.0f);
  94244. for (; n <= L; n++)
  94245. window[n-1] = - (float)(2 * (L - n + 1)) / ((float)L + 1.0f);
  94246. }
  94247. else {
  94248. for (n = 1; n <= L/2; n++)
  94249. window[n-1] = 2.0f * n / (float)L;
  94250. for (; n <= L; n++)
  94251. window[n-1] = ((float)(2 * (L - n)) + 1.0f) / (float)L;
  94252. }
  94253. }
  94254. void FLAC__window_tukey(FLAC__real *window, const FLAC__int32 L, const FLAC__real p)
  94255. {
  94256. if (p <= 0.0)
  94257. FLAC__window_rectangle(window, L);
  94258. else if (p >= 1.0)
  94259. FLAC__window_hann(window, L);
  94260. else {
  94261. const FLAC__int32 Np = (FLAC__int32)(p / 2.0f * L) - 1;
  94262. FLAC__int32 n;
  94263. FLAC__window_rectangle(window, L);
  94264. if (Np > 0) {
  94265. for (n = 0; n <= Np; n++) {
  94266. window[n] = (FLAC__real)(0.5f - 0.5f * cos(M_PI * n / Np));
  94267. window[L-Np-1+n] = (FLAC__real)(0.5f - 0.5f * cos(M_PI * (n+Np) / Np));
  94268. }
  94269. }
  94270. }
  94271. }
  94272. void FLAC__window_welch(FLAC__real *window, const FLAC__int32 L)
  94273. {
  94274. const FLAC__int32 N = L - 1;
  94275. const double N2 = (double)N / 2.;
  94276. FLAC__int32 n;
  94277. for (n = 0; n <= N; n++) {
  94278. const double k = ((double)n - N2) / N2;
  94279. window[n] = (FLAC__real)(1.0f - k * k);
  94280. }
  94281. }
  94282. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  94283. #endif
  94284. /*** End of inlined file: window_flac.c ***/
  94285. #else
  94286. #include <FLAC/all.h>
  94287. #endif
  94288. }
  94289. #ifdef _MSC_VER
  94290. #pragma warning (pop)
  94291. #endif
  94292. BEGIN_JUCE_NAMESPACE
  94293. using namespace FlacNamespace;
  94294. static const char* const flacFormatName = "FLAC file";
  94295. static const tchar* const flacExtensions[] = { T(".flac"), 0 };
  94296. class FlacReader : public AudioFormatReader
  94297. {
  94298. FLAC__StreamDecoder* decoder;
  94299. AudioSampleBuffer reservoir;
  94300. int reservoirStart, samplesInReservoir;
  94301. bool ok, scanningForLength;
  94302. public:
  94303. FlacReader (InputStream* const in)
  94304. : AudioFormatReader (in, TRANS (flacFormatName)),
  94305. reservoir (2, 0),
  94306. reservoirStart (0),
  94307. samplesInReservoir (0),
  94308. scanningForLength (false)
  94309. {
  94310. using namespace FlacNamespace;
  94311. lengthInSamples = 0;
  94312. decoder = FLAC__stream_decoder_new();
  94313. ok = FLAC__stream_decoder_init_stream (decoder,
  94314. readCallback_, seekCallback_, tellCallback_, lengthCallback_,
  94315. eofCallback_, writeCallback_, metadataCallback_, errorCallback_,
  94316. (void*) this) == FLAC__STREAM_DECODER_INIT_STATUS_OK;
  94317. if (ok)
  94318. {
  94319. FLAC__stream_decoder_process_until_end_of_metadata (decoder);
  94320. if (lengthInSamples == 0 && sampleRate > 0)
  94321. {
  94322. // the length hasn't been stored in the metadata, so we'll need to
  94323. // work it out the length the hard way, by scanning the whole file..
  94324. scanningForLength = true;
  94325. FLAC__stream_decoder_process_until_end_of_stream (decoder);
  94326. scanningForLength = false;
  94327. const int64 tempLength = lengthInSamples;
  94328. FLAC__stream_decoder_reset (decoder);
  94329. FLAC__stream_decoder_process_until_end_of_metadata (decoder);
  94330. lengthInSamples = tempLength;
  94331. }
  94332. }
  94333. }
  94334. ~FlacReader()
  94335. {
  94336. FLAC__stream_decoder_delete (decoder);
  94337. }
  94338. void useMetadata (const FLAC__StreamMetadata_StreamInfo& info)
  94339. {
  94340. sampleRate = info.sample_rate;
  94341. bitsPerSample = info.bits_per_sample;
  94342. lengthInSamples = (unsigned int) info.total_samples;
  94343. numChannels = info.channels;
  94344. reservoir.setSize (numChannels, 2 * info.max_blocksize, false, false, true);
  94345. }
  94346. // returns the number of samples read
  94347. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  94348. int64 startSampleInFile, int numSamples)
  94349. {
  94350. using namespace FlacNamespace;
  94351. if (! ok)
  94352. return false;
  94353. while (numSamples > 0)
  94354. {
  94355. if (startSampleInFile >= reservoirStart
  94356. && startSampleInFile < reservoirStart + samplesInReservoir)
  94357. {
  94358. const int num = (int) jmin ((int64) numSamples,
  94359. reservoirStart + samplesInReservoir - startSampleInFile);
  94360. jassert (num > 0);
  94361. for (int i = jmin (numDestChannels, reservoir.getNumChannels()); --i >= 0;)
  94362. if (destSamples[i] != 0)
  94363. memcpy (destSamples[i] + startOffsetInDestBuffer,
  94364. reservoir.getSampleData (i, (int) (startSampleInFile - reservoirStart)),
  94365. sizeof (int) * num);
  94366. startOffsetInDestBuffer += num;
  94367. startSampleInFile += num;
  94368. numSamples -= num;
  94369. }
  94370. else
  94371. {
  94372. if (startSampleInFile >= (int) lengthInSamples)
  94373. {
  94374. samplesInReservoir = 0;
  94375. }
  94376. else if (startSampleInFile < reservoirStart
  94377. || startSampleInFile > reservoirStart + jmax (samplesInReservoir, 511))
  94378. {
  94379. // had some problems with flac crashing if the read pos is aligned more
  94380. // accurately than this. Probably fixed in newer versions of the library, though.
  94381. reservoirStart = (int) (startSampleInFile & ~511);
  94382. samplesInReservoir = 0;
  94383. FLAC__stream_decoder_seek_absolute (decoder, (FLAC__uint64) reservoirStart);
  94384. }
  94385. else
  94386. {
  94387. reservoirStart += samplesInReservoir;
  94388. samplesInReservoir = 0;
  94389. FLAC__stream_decoder_process_single (decoder);
  94390. }
  94391. if (samplesInReservoir == 0)
  94392. break;
  94393. }
  94394. }
  94395. if (numSamples > 0)
  94396. {
  94397. for (int i = numDestChannels; --i >= 0;)
  94398. if (destSamples[i] != 0)
  94399. zeromem (destSamples[i] + startOffsetInDestBuffer,
  94400. sizeof (int) * numSamples);
  94401. }
  94402. return true;
  94403. }
  94404. void useSamples (const FLAC__int32* const buffer[], int numSamples)
  94405. {
  94406. if (scanningForLength)
  94407. {
  94408. lengthInSamples += numSamples;
  94409. }
  94410. else
  94411. {
  94412. if (numSamples > reservoir.getNumSamples())
  94413. reservoir.setSize (numChannels, numSamples, false, false, true);
  94414. const int bitsToShift = 32 - bitsPerSample;
  94415. for (int i = 0; i < (int) numChannels; ++i)
  94416. {
  94417. const FLAC__int32* src = buffer[i];
  94418. int n = i;
  94419. while (src == 0 && n > 0)
  94420. src = buffer [--n];
  94421. if (src != 0)
  94422. {
  94423. int* dest = (int*) reservoir.getSampleData(i);
  94424. for (int j = 0; j < numSamples; ++j)
  94425. dest[j] = src[j] << bitsToShift;
  94426. }
  94427. }
  94428. samplesInReservoir = numSamples;
  94429. }
  94430. }
  94431. static FLAC__StreamDecoderReadStatus readCallback_ (const FLAC__StreamDecoder*, FLAC__byte buffer[], size_t* bytes, void* client_data)
  94432. {
  94433. *bytes = (unsigned int) ((const FlacReader*) client_data)->input->read (buffer, (int) *bytes);
  94434. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  94435. }
  94436. static FLAC__StreamDecoderSeekStatus seekCallback_ (const FLAC__StreamDecoder*, FLAC__uint64 absolute_byte_offset, void* client_data)
  94437. {
  94438. ((const FlacReader*) client_data)->input->setPosition ((int) absolute_byte_offset);
  94439. return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
  94440. }
  94441. static FLAC__StreamDecoderTellStatus tellCallback_ (const FLAC__StreamDecoder*, FLAC__uint64* absolute_byte_offset, void* client_data)
  94442. {
  94443. *absolute_byte_offset = ((const FlacReader*) client_data)->input->getPosition();
  94444. return FLAC__STREAM_DECODER_TELL_STATUS_OK;
  94445. }
  94446. static FLAC__StreamDecoderLengthStatus lengthCallback_ (const FLAC__StreamDecoder*, FLAC__uint64* stream_length, void* client_data)
  94447. {
  94448. *stream_length = ((const FlacReader*) client_data)->input->getTotalLength();
  94449. return FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
  94450. }
  94451. static FLAC__bool eofCallback_ (const FLAC__StreamDecoder*, void* client_data)
  94452. {
  94453. return ((const FlacReader*) client_data)->input->isExhausted();
  94454. }
  94455. static FLAC__StreamDecoderWriteStatus writeCallback_ (const FLAC__StreamDecoder*,
  94456. const FLAC__Frame* frame,
  94457. const FLAC__int32* const buffer[],
  94458. void* client_data)
  94459. {
  94460. ((FlacReader*) client_data)->useSamples (buffer, frame->header.blocksize);
  94461. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  94462. }
  94463. static void metadataCallback_ (const FLAC__StreamDecoder*,
  94464. const FLAC__StreamMetadata* metadata,
  94465. void* client_data)
  94466. {
  94467. ((FlacReader*) client_data)->useMetadata (metadata->data.stream_info);
  94468. }
  94469. static void errorCallback_ (const FLAC__StreamDecoder*, FLAC__StreamDecoderErrorStatus, void*)
  94470. {
  94471. }
  94472. juce_UseDebuggingNewOperator
  94473. };
  94474. class FlacWriter : public AudioFormatWriter
  94475. {
  94476. FLAC__StreamEncoder* encoder;
  94477. MemoryBlock temp;
  94478. public:
  94479. bool ok;
  94480. FlacWriter (OutputStream* const out,
  94481. const double sampleRate_,
  94482. const int numChannels_,
  94483. const int bitsPerSample_)
  94484. : AudioFormatWriter (out, TRANS (flacFormatName),
  94485. sampleRate_,
  94486. numChannels_,
  94487. bitsPerSample_)
  94488. {
  94489. using namespace FlacNamespace;
  94490. encoder = FLAC__stream_encoder_new();
  94491. FLAC__stream_encoder_set_do_mid_side_stereo (encoder, numChannels == 2);
  94492. FLAC__stream_encoder_set_loose_mid_side_stereo (encoder, numChannels == 2);
  94493. FLAC__stream_encoder_set_channels (encoder, numChannels);
  94494. FLAC__stream_encoder_set_bits_per_sample (encoder, jmin ((unsigned int) 24, bitsPerSample));
  94495. FLAC__stream_encoder_set_sample_rate (encoder, (unsigned int) sampleRate);
  94496. FLAC__stream_encoder_set_blocksize (encoder, 2048);
  94497. FLAC__stream_encoder_set_do_escape_coding (encoder, true);
  94498. ok = FLAC__stream_encoder_init_stream (encoder,
  94499. encodeWriteCallback, encodeSeekCallback,
  94500. encodeTellCallback, encodeMetadataCallback,
  94501. (void*) this) == FLAC__STREAM_ENCODER_INIT_STATUS_OK;
  94502. }
  94503. ~FlacWriter()
  94504. {
  94505. if (ok)
  94506. {
  94507. FLAC__stream_encoder_finish (encoder);
  94508. output->flush();
  94509. }
  94510. else
  94511. {
  94512. output = 0; // to stop the base class deleting this, as it needs to be returned
  94513. // to the caller of createWriter()
  94514. }
  94515. FLAC__stream_encoder_delete (encoder);
  94516. }
  94517. bool write (const int** samplesToWrite, int numSamples)
  94518. {
  94519. if (! ok)
  94520. return false;
  94521. int* buf[3];
  94522. const int bitsToShift = 32 - bitsPerSample;
  94523. if (bitsToShift > 0)
  94524. {
  94525. const int numChannelsToWrite = (samplesToWrite[1] == 0) ? 1 : 2;
  94526. temp.setSize (sizeof (int) * numSamples * numChannelsToWrite);
  94527. buf[0] = (int*) temp.getData();
  94528. buf[1] = buf[0] + numSamples;
  94529. buf[2] = 0;
  94530. for (int i = numChannelsToWrite; --i >= 0;)
  94531. {
  94532. if (samplesToWrite[i] != 0)
  94533. {
  94534. for (int j = 0; j < numSamples; ++j)
  94535. buf [i][j] = (samplesToWrite [i][j] >> bitsToShift);
  94536. }
  94537. }
  94538. samplesToWrite = (const int**) buf;
  94539. }
  94540. return FLAC__stream_encoder_process (encoder,
  94541. (const FLAC__int32**) samplesToWrite,
  94542. numSamples) != 0;
  94543. }
  94544. bool writeData (const void* const data, const int size) const
  94545. {
  94546. return output->write (data, size);
  94547. }
  94548. static void packUint32 (FLAC__uint32 val, FLAC__byte* b, const int bytes)
  94549. {
  94550. b += bytes;
  94551. for (int i = 0; i < bytes; ++i)
  94552. {
  94553. *(--b) = (FLAC__byte) (val & 0xff);
  94554. val >>= 8;
  94555. }
  94556. }
  94557. void writeMetaData (const FLAC__StreamMetadata* metadata)
  94558. {
  94559. using namespace FlacNamespace;
  94560. const FLAC__StreamMetadata_StreamInfo& info = metadata->data.stream_info;
  94561. unsigned char buffer [FLAC__STREAM_METADATA_STREAMINFO_LENGTH];
  94562. const unsigned int channelsMinus1 = info.channels - 1;
  94563. const unsigned int bitsMinus1 = info.bits_per_sample - 1;
  94564. packUint32 (info.min_blocksize, buffer, 2);
  94565. packUint32 (info.max_blocksize, buffer + 2, 2);
  94566. packUint32 (info.min_framesize, buffer + 4, 3);
  94567. packUint32 (info.max_framesize, buffer + 7, 3);
  94568. buffer[10] = (uint8) ((info.sample_rate >> 12) & 0xff);
  94569. buffer[11] = (uint8) ((info.sample_rate >> 4) & 0xff);
  94570. buffer[12] = (uint8) (((info.sample_rate & 0x0f) << 4) | (channelsMinus1 << 1) | (bitsMinus1 >> 4));
  94571. buffer[13] = (FLAC__byte) (((bitsMinus1 & 0x0f) << 4) | (unsigned int) ((info.total_samples >> 32) & 0x0f));
  94572. packUint32 ((FLAC__uint32) info.total_samples, buffer + 14, 4);
  94573. memcpy (buffer + 18, info.md5sum, 16);
  94574. const bool seekOk = output->setPosition (4);
  94575. (void) seekOk;
  94576. // if this fails, you've given it an output stream that can't seek! It needs
  94577. // to be able to seek back to write the header
  94578. jassert (seekOk);
  94579. output->writeIntBigEndian (FLAC__STREAM_METADATA_STREAMINFO_LENGTH);
  94580. output->write (buffer, FLAC__STREAM_METADATA_STREAMINFO_LENGTH);
  94581. }
  94582. static FLAC__StreamEncoderWriteStatus encodeWriteCallback (const FLAC__StreamEncoder*,
  94583. const FLAC__byte buffer[],
  94584. size_t bytes,
  94585. unsigned int /*samples*/,
  94586. unsigned int /*current_frame*/,
  94587. void* client_data)
  94588. {
  94589. using namespace FlacNamespace;
  94590. return ((FlacWriter*) client_data)->writeData (buffer, (int) bytes)
  94591. ? FLAC__STREAM_ENCODER_WRITE_STATUS_OK
  94592. : FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
  94593. }
  94594. static FLAC__StreamEncoderSeekStatus encodeSeekCallback (const FLAC__StreamEncoder*, FLAC__uint64, void*)
  94595. {
  94596. return FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED;
  94597. }
  94598. static FLAC__StreamEncoderTellStatus encodeTellCallback (const FLAC__StreamEncoder*, FLAC__uint64* absolute_byte_offset, void* client_data)
  94599. {
  94600. if (client_data == 0)
  94601. return FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED;
  94602. *absolute_byte_offset = (FLAC__uint64) ((FlacWriter*) client_data)->output->getPosition();
  94603. return FLAC__STREAM_ENCODER_TELL_STATUS_OK;
  94604. }
  94605. static void encodeMetadataCallback (const FLAC__StreamEncoder*,
  94606. const FLAC__StreamMetadata* metadata,
  94607. void* client_data)
  94608. {
  94609. ((FlacWriter*) client_data)->writeMetaData (metadata);
  94610. }
  94611. juce_UseDebuggingNewOperator
  94612. };
  94613. FlacAudioFormat::FlacAudioFormat()
  94614. : AudioFormat (TRANS (flacFormatName), (const tchar**) flacExtensions)
  94615. {
  94616. }
  94617. FlacAudioFormat::~FlacAudioFormat()
  94618. {
  94619. }
  94620. const Array <int> FlacAudioFormat::getPossibleSampleRates()
  94621. {
  94622. const int rates[] = { 22050, 32000, 44100, 48000, 88200, 96000, 0 };
  94623. return Array <int> (rates);
  94624. }
  94625. const Array <int> FlacAudioFormat::getPossibleBitDepths()
  94626. {
  94627. const int depths[] = { 16, 24, 0 };
  94628. return Array <int> (depths);
  94629. }
  94630. bool FlacAudioFormat::canDoStereo()
  94631. {
  94632. return true;
  94633. }
  94634. bool FlacAudioFormat::canDoMono()
  94635. {
  94636. return true;
  94637. }
  94638. bool FlacAudioFormat::isCompressed()
  94639. {
  94640. return true;
  94641. }
  94642. AudioFormatReader* FlacAudioFormat::createReaderFor (InputStream* in,
  94643. const bool deleteStreamIfOpeningFails)
  94644. {
  94645. ScopedPointer <FlacReader> r (new FlacReader (in));
  94646. if (r->sampleRate != 0)
  94647. return r.release();
  94648. if (! deleteStreamIfOpeningFails)
  94649. r->input = 0;
  94650. return 0;
  94651. }
  94652. AudioFormatWriter* FlacAudioFormat::createWriterFor (OutputStream* out,
  94653. double sampleRate,
  94654. unsigned int numberOfChannels,
  94655. int bitsPerSample,
  94656. const StringPairArray& /*metadataValues*/,
  94657. int /*qualityOptionIndex*/)
  94658. {
  94659. if (getPossibleBitDepths().contains (bitsPerSample))
  94660. {
  94661. ScopedPointer <FlacWriter> w (new FlacWriter (out,
  94662. sampleRate,
  94663. numberOfChannels,
  94664. bitsPerSample));
  94665. if (w->ok)
  94666. return w.release();
  94667. }
  94668. return 0;
  94669. }
  94670. END_JUCE_NAMESPACE
  94671. #endif
  94672. /*** End of inlined file: juce_FlacAudioFormat.cpp ***/
  94673. /*** Start of inlined file: juce_OggVorbisAudioFormat.cpp ***/
  94674. #if JUCE_USE_OGGVORBIS
  94675. #if JUCE_MAC
  94676. #define __MACOSX__ 1
  94677. #endif
  94678. namespace OggVorbisNamespace
  94679. {
  94680. #if JUCE_INCLUDE_OGGVORBIS_CODE
  94681. /*** Start of inlined file: vorbisenc.h ***/
  94682. #ifndef _OV_ENC_H_
  94683. #define _OV_ENC_H_
  94684. #ifdef __cplusplus
  94685. extern "C"
  94686. {
  94687. #endif /* __cplusplus */
  94688. /*** Start of inlined file: codec.h ***/
  94689. #ifndef _vorbis_codec_h_
  94690. #define _vorbis_codec_h_
  94691. #ifdef __cplusplus
  94692. extern "C"
  94693. {
  94694. #endif /* __cplusplus */
  94695. /*** Start of inlined file: ogg.h ***/
  94696. #ifndef _OGG_H
  94697. #define _OGG_H
  94698. #ifdef __cplusplus
  94699. extern "C" {
  94700. #endif
  94701. /*** Start of inlined file: os_types.h ***/
  94702. #ifndef _OS_TYPES_H
  94703. #define _OS_TYPES_H
  94704. #define _ogg_malloc malloc
  94705. #define _ogg_calloc calloc
  94706. #define _ogg_realloc realloc
  94707. #define _ogg_free free
  94708. #if defined(_WIN32)
  94709. # if defined(__CYGWIN__)
  94710. # include <_G_config.h>
  94711. typedef _G_int64_t ogg_int64_t;
  94712. typedef _G_int32_t ogg_int32_t;
  94713. typedef _G_uint32_t ogg_uint32_t;
  94714. typedef _G_int16_t ogg_int16_t;
  94715. typedef _G_uint16_t ogg_uint16_t;
  94716. # elif defined(__MINGW32__)
  94717. typedef short ogg_int16_t;
  94718. typedef unsigned short ogg_uint16_t;
  94719. typedef int ogg_int32_t;
  94720. typedef unsigned int ogg_uint32_t;
  94721. typedef long long ogg_int64_t;
  94722. typedef unsigned long long ogg_uint64_t;
  94723. # elif defined(__MWERKS__)
  94724. typedef long long ogg_int64_t;
  94725. typedef int ogg_int32_t;
  94726. typedef unsigned int ogg_uint32_t;
  94727. typedef short ogg_int16_t;
  94728. typedef unsigned short ogg_uint16_t;
  94729. # else
  94730. typedef __int64 ogg_int64_t;
  94731. typedef __int32 ogg_int32_t;
  94732. typedef unsigned __int32 ogg_uint32_t;
  94733. typedef __int16 ogg_int16_t;
  94734. typedef unsigned __int16 ogg_uint16_t;
  94735. # endif
  94736. #elif defined(__MACOS__)
  94737. # include <sys/types.h>
  94738. typedef SInt16 ogg_int16_t;
  94739. typedef UInt16 ogg_uint16_t;
  94740. typedef SInt32 ogg_int32_t;
  94741. typedef UInt32 ogg_uint32_t;
  94742. typedef SInt64 ogg_int64_t;
  94743. #elif defined(__MACOSX__) /* MacOS X Framework build */
  94744. # include <sys/types.h>
  94745. typedef int16_t ogg_int16_t;
  94746. typedef u_int16_t ogg_uint16_t;
  94747. typedef int32_t ogg_int32_t;
  94748. typedef u_int32_t ogg_uint32_t;
  94749. typedef int64_t ogg_int64_t;
  94750. #elif defined(__BEOS__)
  94751. # include <inttypes.h>
  94752. typedef int16_t ogg_int16_t;
  94753. typedef u_int16_t ogg_uint16_t;
  94754. typedef int32_t ogg_int32_t;
  94755. typedef u_int32_t ogg_uint32_t;
  94756. typedef int64_t ogg_int64_t;
  94757. #elif defined (__EMX__)
  94758. typedef short ogg_int16_t;
  94759. typedef unsigned short ogg_uint16_t;
  94760. typedef int ogg_int32_t;
  94761. typedef unsigned int ogg_uint32_t;
  94762. typedef long long ogg_int64_t;
  94763. #elif defined (DJGPP)
  94764. typedef short ogg_int16_t;
  94765. typedef int ogg_int32_t;
  94766. typedef unsigned int ogg_uint32_t;
  94767. typedef long long ogg_int64_t;
  94768. #elif defined(R5900)
  94769. typedef long ogg_int64_t;
  94770. typedef int ogg_int32_t;
  94771. typedef unsigned ogg_uint32_t;
  94772. typedef short ogg_int16_t;
  94773. #elif defined(__SYMBIAN32__)
  94774. typedef signed short ogg_int16_t;
  94775. typedef unsigned short ogg_uint16_t;
  94776. typedef signed int ogg_int32_t;
  94777. typedef unsigned int ogg_uint32_t;
  94778. typedef long long int ogg_int64_t;
  94779. #else
  94780. # include <sys/types.h>
  94781. /*** Start of inlined file: config_types.h ***/
  94782. #ifndef __CONFIG_TYPES_H__
  94783. #define __CONFIG_TYPES_H__
  94784. typedef int16_t ogg_int16_t;
  94785. typedef unsigned short ogg_uint16_t;
  94786. typedef int32_t ogg_int32_t;
  94787. typedef unsigned int ogg_uint32_t;
  94788. typedef int64_t ogg_int64_t;
  94789. #endif
  94790. /*** End of inlined file: config_types.h ***/
  94791. #endif
  94792. #endif /* _OS_TYPES_H */
  94793. /*** End of inlined file: os_types.h ***/
  94794. typedef struct {
  94795. long endbyte;
  94796. int endbit;
  94797. unsigned char *buffer;
  94798. unsigned char *ptr;
  94799. long storage;
  94800. } oggpack_buffer;
  94801. typedef struct {
  94802. unsigned char *header;
  94803. long header_len;
  94804. unsigned char *body;
  94805. long body_len;
  94806. } ogg_page;
  94807. ogg_uint32_t ogg_bitreverse(ogg_uint32_t x){
  94808. x= ((x>>16)&0x0000ffffUL) | ((x<<16)&0xffff0000UL);
  94809. x= ((x>> 8)&0x00ff00ffUL) | ((x<< 8)&0xff00ff00UL);
  94810. x= ((x>> 4)&0x0f0f0f0fUL) | ((x<< 4)&0xf0f0f0f0UL);
  94811. x= ((x>> 2)&0x33333333UL) | ((x<< 2)&0xccccccccUL);
  94812. return((x>> 1)&0x55555555UL) | ((x<< 1)&0xaaaaaaaaUL);
  94813. }
  94814. typedef struct {
  94815. unsigned char *body_data; /* bytes from packet bodies */
  94816. long body_storage; /* storage elements allocated */
  94817. long body_fill; /* elements stored; fill mark */
  94818. long body_returned; /* elements of fill returned */
  94819. int *lacing_vals; /* The values that will go to the segment table */
  94820. ogg_int64_t *granule_vals; /* granulepos values for headers. Not compact
  94821. this way, but it is simple coupled to the
  94822. lacing fifo */
  94823. long lacing_storage;
  94824. long lacing_fill;
  94825. long lacing_packet;
  94826. long lacing_returned;
  94827. unsigned char header[282]; /* working space for header encode */
  94828. int header_fill;
  94829. int e_o_s; /* set when we have buffered the last packet in the
  94830. logical bitstream */
  94831. int b_o_s; /* set after we've written the initial page
  94832. of a logical bitstream */
  94833. long serialno;
  94834. long pageno;
  94835. ogg_int64_t packetno; /* sequence number for decode; the framing
  94836. knows where there's a hole in the data,
  94837. but we need coupling so that the codec
  94838. (which is in a seperate abstraction
  94839. layer) also knows about the gap */
  94840. ogg_int64_t granulepos;
  94841. } ogg_stream_state;
  94842. typedef struct {
  94843. unsigned char *packet;
  94844. long bytes;
  94845. long b_o_s;
  94846. long e_o_s;
  94847. ogg_int64_t granulepos;
  94848. ogg_int64_t packetno; /* sequence number for decode; the framing
  94849. knows where there's a hole in the data,
  94850. but we need coupling so that the codec
  94851. (which is in a seperate abstraction
  94852. layer) also knows about the gap */
  94853. } ogg_packet;
  94854. typedef struct {
  94855. unsigned char *data;
  94856. int storage;
  94857. int fill;
  94858. int returned;
  94859. int unsynced;
  94860. int headerbytes;
  94861. int bodybytes;
  94862. } ogg_sync_state;
  94863. extern void oggpack_writeinit(oggpack_buffer *b);
  94864. extern void oggpack_writetrunc(oggpack_buffer *b,long bits);
  94865. extern void oggpack_writealign(oggpack_buffer *b);
  94866. extern void oggpack_writecopy(oggpack_buffer *b,void *source,long bits);
  94867. extern void oggpack_reset(oggpack_buffer *b);
  94868. extern void oggpack_writeclear(oggpack_buffer *b);
  94869. extern void oggpack_readinit(oggpack_buffer *b,unsigned char *buf,int bytes);
  94870. extern void oggpack_write(oggpack_buffer *b,unsigned long value,int bits);
  94871. extern long oggpack_look(oggpack_buffer *b,int bits);
  94872. extern long oggpack_look1(oggpack_buffer *b);
  94873. extern void oggpack_adv(oggpack_buffer *b,int bits);
  94874. extern void oggpack_adv1(oggpack_buffer *b);
  94875. extern long oggpack_read(oggpack_buffer *b,int bits);
  94876. extern long oggpack_read1(oggpack_buffer *b);
  94877. extern long oggpack_bytes(oggpack_buffer *b);
  94878. extern long oggpack_bits(oggpack_buffer *b);
  94879. extern unsigned char *oggpack_get_buffer(oggpack_buffer *b);
  94880. extern void oggpackB_writeinit(oggpack_buffer *b);
  94881. extern void oggpackB_writetrunc(oggpack_buffer *b,long bits);
  94882. extern void oggpackB_writealign(oggpack_buffer *b);
  94883. extern void oggpackB_writecopy(oggpack_buffer *b,void *source,long bits);
  94884. extern void oggpackB_reset(oggpack_buffer *b);
  94885. extern void oggpackB_writeclear(oggpack_buffer *b);
  94886. extern void oggpackB_readinit(oggpack_buffer *b,unsigned char *buf,int bytes);
  94887. extern void oggpackB_write(oggpack_buffer *b,unsigned long value,int bits);
  94888. extern long oggpackB_look(oggpack_buffer *b,int bits);
  94889. extern long oggpackB_look1(oggpack_buffer *b);
  94890. extern void oggpackB_adv(oggpack_buffer *b,int bits);
  94891. extern void oggpackB_adv1(oggpack_buffer *b);
  94892. extern long oggpackB_read(oggpack_buffer *b,int bits);
  94893. extern long oggpackB_read1(oggpack_buffer *b);
  94894. extern long oggpackB_bytes(oggpack_buffer *b);
  94895. extern long oggpackB_bits(oggpack_buffer *b);
  94896. extern unsigned char *oggpackB_get_buffer(oggpack_buffer *b);
  94897. extern int ogg_stream_packetin(ogg_stream_state *os, ogg_packet *op);
  94898. extern int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og);
  94899. extern int ogg_stream_flush(ogg_stream_state *os, ogg_page *og);
  94900. extern int ogg_sync_init(ogg_sync_state *oy);
  94901. extern int ogg_sync_clear(ogg_sync_state *oy);
  94902. extern int ogg_sync_reset(ogg_sync_state *oy);
  94903. extern int ogg_sync_destroy(ogg_sync_state *oy);
  94904. extern char *ogg_sync_buffer(ogg_sync_state *oy, long size);
  94905. extern int ogg_sync_wrote(ogg_sync_state *oy, long bytes);
  94906. extern long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og);
  94907. extern int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og);
  94908. extern int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og);
  94909. extern int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op);
  94910. extern int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op);
  94911. extern int ogg_stream_init(ogg_stream_state *os,int serialno);
  94912. extern int ogg_stream_clear(ogg_stream_state *os);
  94913. extern int ogg_stream_reset(ogg_stream_state *os);
  94914. extern int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno);
  94915. extern int ogg_stream_destroy(ogg_stream_state *os);
  94916. extern int ogg_stream_eos(ogg_stream_state *os);
  94917. extern void ogg_page_checksum_set(ogg_page *og);
  94918. extern int ogg_page_version(ogg_page *og);
  94919. extern int ogg_page_continued(ogg_page *og);
  94920. extern int ogg_page_bos(ogg_page *og);
  94921. extern int ogg_page_eos(ogg_page *og);
  94922. extern ogg_int64_t ogg_page_granulepos(ogg_page *og);
  94923. extern int ogg_page_serialno(ogg_page *og);
  94924. extern long ogg_page_pageno(ogg_page *og);
  94925. extern int ogg_page_packets(ogg_page *og);
  94926. extern void ogg_packet_clear(ogg_packet *op);
  94927. #ifdef __cplusplus
  94928. }
  94929. #endif
  94930. #endif /* _OGG_H */
  94931. /*** End of inlined file: ogg.h ***/
  94932. typedef struct vorbis_info{
  94933. int version;
  94934. int channels;
  94935. long rate;
  94936. long bitrate_upper;
  94937. long bitrate_nominal;
  94938. long bitrate_lower;
  94939. long bitrate_window;
  94940. void *codec_setup;
  94941. } vorbis_info;
  94942. typedef struct vorbis_dsp_state{
  94943. int analysisp;
  94944. vorbis_info *vi;
  94945. float **pcm;
  94946. float **pcmret;
  94947. int pcm_storage;
  94948. int pcm_current;
  94949. int pcm_returned;
  94950. int preextrapolate;
  94951. int eofflag;
  94952. long lW;
  94953. long W;
  94954. long nW;
  94955. long centerW;
  94956. ogg_int64_t granulepos;
  94957. ogg_int64_t sequence;
  94958. ogg_int64_t glue_bits;
  94959. ogg_int64_t time_bits;
  94960. ogg_int64_t floor_bits;
  94961. ogg_int64_t res_bits;
  94962. void *backend_state;
  94963. } vorbis_dsp_state;
  94964. typedef struct vorbis_block{
  94965. float **pcm; /* this is a pointer into local storage */
  94966. oggpack_buffer opb;
  94967. long lW;
  94968. long W;
  94969. long nW;
  94970. int pcmend;
  94971. int mode;
  94972. int eofflag;
  94973. ogg_int64_t granulepos;
  94974. ogg_int64_t sequence;
  94975. vorbis_dsp_state *vd; /* For read-only access of configuration */
  94976. void *localstore;
  94977. long localtop;
  94978. long localalloc;
  94979. long totaluse;
  94980. struct alloc_chain *reap;
  94981. long glue_bits;
  94982. long time_bits;
  94983. long floor_bits;
  94984. long res_bits;
  94985. void *internal;
  94986. } vorbis_block;
  94987. struct alloc_chain{
  94988. void *ptr;
  94989. struct alloc_chain *next;
  94990. };
  94991. typedef struct vorbis_comment{
  94992. char **user_comments;
  94993. int *comment_lengths;
  94994. int comments;
  94995. char *vendor;
  94996. } vorbis_comment;
  94997. extern void vorbis_info_init(vorbis_info *vi);
  94998. extern void vorbis_info_clear(vorbis_info *vi);
  94999. extern int vorbis_info_blocksize(vorbis_info *vi,int zo);
  95000. extern void vorbis_comment_init(vorbis_comment *vc);
  95001. extern void vorbis_comment_add(vorbis_comment *vc, char *comment);
  95002. extern void vorbis_comment_add_tag(vorbis_comment *vc,
  95003. const char *tag, char *contents);
  95004. extern char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count);
  95005. extern int vorbis_comment_query_count(vorbis_comment *vc, char *tag);
  95006. extern void vorbis_comment_clear(vorbis_comment *vc);
  95007. extern int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb);
  95008. extern int vorbis_block_clear(vorbis_block *vb);
  95009. extern void vorbis_dsp_clear(vorbis_dsp_state *v);
  95010. extern double vorbis_granule_time(vorbis_dsp_state *v,
  95011. ogg_int64_t granulepos);
  95012. extern int vorbis_analysis_init(vorbis_dsp_state *v,vorbis_info *vi);
  95013. extern int vorbis_commentheader_out(vorbis_comment *vc, ogg_packet *op);
  95014. extern int vorbis_analysis_headerout(vorbis_dsp_state *v,
  95015. vorbis_comment *vc,
  95016. ogg_packet *op,
  95017. ogg_packet *op_comm,
  95018. ogg_packet *op_code);
  95019. extern float **vorbis_analysis_buffer(vorbis_dsp_state *v,int vals);
  95020. extern int vorbis_analysis_wrote(vorbis_dsp_state *v,int vals);
  95021. extern int vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb);
  95022. extern int vorbis_analysis(vorbis_block *vb,ogg_packet *op);
  95023. extern int vorbis_bitrate_addblock(vorbis_block *vb);
  95024. extern int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd,
  95025. ogg_packet *op);
  95026. extern int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,
  95027. ogg_packet *op);
  95028. extern int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi);
  95029. extern int vorbis_synthesis_restart(vorbis_dsp_state *v);
  95030. extern int vorbis_synthesis(vorbis_block *vb,ogg_packet *op);
  95031. extern int vorbis_synthesis_trackonly(vorbis_block *vb,ogg_packet *op);
  95032. extern int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb);
  95033. extern int vorbis_synthesis_pcmout(vorbis_dsp_state *v,float ***pcm);
  95034. extern int vorbis_synthesis_lapout(vorbis_dsp_state *v,float ***pcm);
  95035. extern int vorbis_synthesis_read(vorbis_dsp_state *v,int samples);
  95036. extern long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op);
  95037. extern int vorbis_synthesis_halfrate(vorbis_info *v,int flag);
  95038. extern int vorbis_synthesis_halfrate_p(vorbis_info *v);
  95039. #define OV_FALSE -1
  95040. #define OV_EOF -2
  95041. #define OV_HOLE -3
  95042. #define OV_EREAD -128
  95043. #define OV_EFAULT -129
  95044. #define OV_EIMPL -130
  95045. #define OV_EINVAL -131
  95046. #define OV_ENOTVORBIS -132
  95047. #define OV_EBADHEADER -133
  95048. #define OV_EVERSION -134
  95049. #define OV_ENOTAUDIO -135
  95050. #define OV_EBADPACKET -136
  95051. #define OV_EBADLINK -137
  95052. #define OV_ENOSEEK -138
  95053. #ifdef __cplusplus
  95054. }
  95055. #endif /* __cplusplus */
  95056. #endif
  95057. /*** End of inlined file: codec.h ***/
  95058. extern int vorbis_encode_init(vorbis_info *vi,
  95059. long channels,
  95060. long rate,
  95061. long max_bitrate,
  95062. long nominal_bitrate,
  95063. long min_bitrate);
  95064. extern int vorbis_encode_setup_managed(vorbis_info *vi,
  95065. long channels,
  95066. long rate,
  95067. long max_bitrate,
  95068. long nominal_bitrate,
  95069. long min_bitrate);
  95070. extern int vorbis_encode_setup_vbr(vorbis_info *vi,
  95071. long channels,
  95072. long rate,
  95073. float quality /* quality level from 0. (lo) to 1. (hi) */
  95074. );
  95075. extern int vorbis_encode_init_vbr(vorbis_info *vi,
  95076. long channels,
  95077. long rate,
  95078. float base_quality /* quality level from 0. (lo) to 1. (hi) */
  95079. );
  95080. extern int vorbis_encode_setup_init(vorbis_info *vi);
  95081. extern int vorbis_encode_ctl(vorbis_info *vi,int number,void *arg);
  95082. #define OV_ECTL_RATEMANAGE_GET 0x10
  95083. #define OV_ECTL_RATEMANAGE_SET 0x11
  95084. #define OV_ECTL_RATEMANAGE_AVG 0x12
  95085. #define OV_ECTL_RATEMANAGE_HARD 0x13
  95086. struct ovectl_ratemanage_arg {
  95087. int management_active;
  95088. long bitrate_hard_min;
  95089. long bitrate_hard_max;
  95090. double bitrate_hard_window;
  95091. long bitrate_av_lo;
  95092. long bitrate_av_hi;
  95093. double bitrate_av_window;
  95094. double bitrate_av_window_center;
  95095. };
  95096. #define OV_ECTL_RATEMANAGE2_GET 0x14
  95097. #define OV_ECTL_RATEMANAGE2_SET 0x15
  95098. struct ovectl_ratemanage2_arg {
  95099. int management_active;
  95100. long bitrate_limit_min_kbps;
  95101. long bitrate_limit_max_kbps;
  95102. long bitrate_limit_reservoir_bits;
  95103. double bitrate_limit_reservoir_bias;
  95104. long bitrate_average_kbps;
  95105. double bitrate_average_damping;
  95106. };
  95107. #define OV_ECTL_LOWPASS_GET 0x20
  95108. #define OV_ECTL_LOWPASS_SET 0x21
  95109. #define OV_ECTL_IBLOCK_GET 0x30
  95110. #define OV_ECTL_IBLOCK_SET 0x31
  95111. #ifdef __cplusplus
  95112. }
  95113. #endif /* __cplusplus */
  95114. #endif
  95115. /*** End of inlined file: vorbisenc.h ***/
  95116. /*** Start of inlined file: vorbisfile.h ***/
  95117. #ifndef _OV_FILE_H_
  95118. #define _OV_FILE_H_
  95119. #ifdef __cplusplus
  95120. extern "C"
  95121. {
  95122. #endif /* __cplusplus */
  95123. #include <stdio.h>
  95124. typedef struct {
  95125. size_t (*read_func) (void *ptr, size_t size, size_t nmemb, void *datasource);
  95126. int (*seek_func) (void *datasource, ogg_int64_t offset, int whence);
  95127. int (*close_func) (void *datasource);
  95128. long (*tell_func) (void *datasource);
  95129. } ov_callbacks;
  95130. #define NOTOPEN 0
  95131. #define PARTOPEN 1
  95132. #define OPENED 2
  95133. #define STREAMSET 3
  95134. #define INITSET 4
  95135. typedef struct OggVorbis_File {
  95136. void *datasource; /* Pointer to a FILE *, etc. */
  95137. int seekable;
  95138. ogg_int64_t offset;
  95139. ogg_int64_t end;
  95140. ogg_sync_state oy;
  95141. int links;
  95142. ogg_int64_t *offsets;
  95143. ogg_int64_t *dataoffsets;
  95144. long *serialnos;
  95145. ogg_int64_t *pcmlengths; /* overloaded to maintain binary
  95146. compatability; x2 size, stores both
  95147. beginning and end values */
  95148. vorbis_info *vi;
  95149. vorbis_comment *vc;
  95150. ogg_int64_t pcm_offset;
  95151. int ready_state;
  95152. long current_serialno;
  95153. int current_link;
  95154. double bittrack;
  95155. double samptrack;
  95156. ogg_stream_state os; /* take physical pages, weld into a logical
  95157. stream of packets */
  95158. vorbis_dsp_state vd; /* central working state for the packet->PCM decoder */
  95159. vorbis_block vb; /* local working space for packet->PCM decode */
  95160. ov_callbacks callbacks;
  95161. } OggVorbis_File;
  95162. extern int ov_clear(OggVorbis_File *vf);
  95163. extern int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
  95164. extern int ov_open_callbacks(void *datasource, OggVorbis_File *vf,
  95165. char *initial, long ibytes, ov_callbacks callbacks);
  95166. extern int ov_test(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
  95167. extern int ov_test_callbacks(void *datasource, OggVorbis_File *vf,
  95168. char *initial, long ibytes, ov_callbacks callbacks);
  95169. extern int ov_test_open(OggVorbis_File *vf);
  95170. extern long ov_bitrate(OggVorbis_File *vf,int i);
  95171. extern long ov_bitrate_instant(OggVorbis_File *vf);
  95172. extern long ov_streams(OggVorbis_File *vf);
  95173. extern long ov_seekable(OggVorbis_File *vf);
  95174. extern long ov_serialnumber(OggVorbis_File *vf,int i);
  95175. extern ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i);
  95176. extern ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i);
  95177. extern double ov_time_total(OggVorbis_File *vf,int i);
  95178. extern int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos);
  95179. extern int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos);
  95180. extern int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos);
  95181. extern int ov_time_seek(OggVorbis_File *vf,double pos);
  95182. extern int ov_time_seek_page(OggVorbis_File *vf,double pos);
  95183. extern int ov_raw_seek_lap(OggVorbis_File *vf,ogg_int64_t pos);
  95184. extern int ov_pcm_seek_lap(OggVorbis_File *vf,ogg_int64_t pos);
  95185. extern int ov_pcm_seek_page_lap(OggVorbis_File *vf,ogg_int64_t pos);
  95186. extern int ov_time_seek_lap(OggVorbis_File *vf,double pos);
  95187. extern int ov_time_seek_page_lap(OggVorbis_File *vf,double pos);
  95188. extern ogg_int64_t ov_raw_tell(OggVorbis_File *vf);
  95189. extern ogg_int64_t ov_pcm_tell(OggVorbis_File *vf);
  95190. extern double ov_time_tell(OggVorbis_File *vf);
  95191. extern vorbis_info *ov_info(OggVorbis_File *vf,int link);
  95192. extern vorbis_comment *ov_comment(OggVorbis_File *vf,int link);
  95193. extern long ov_read_float(OggVorbis_File *vf,float ***pcm_channels,int samples,
  95194. int *bitstream);
  95195. extern long ov_read(OggVorbis_File *vf,char *buffer,int length,
  95196. int bigendianp,int word,int sgned,int *bitstream);
  95197. extern int ov_crosslap(OggVorbis_File *vf1,OggVorbis_File *vf2);
  95198. extern int ov_halfrate(OggVorbis_File *vf,int flag);
  95199. extern int ov_halfrate_p(OggVorbis_File *vf);
  95200. #ifdef __cplusplus
  95201. }
  95202. #endif /* __cplusplus */
  95203. #endif
  95204. /*** End of inlined file: vorbisfile.h ***/
  95205. /*** Start of inlined file: bitwise.c ***/
  95206. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  95207. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  95208. // tasks..
  95209. #if JUCE_MSVC
  95210. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  95211. #endif
  95212. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  95213. #if JUCE_USE_OGGVORBIS
  95214. #include <string.h>
  95215. #include <stdlib.h>
  95216. #define BUFFER_INCREMENT 256
  95217. static const unsigned long mask[]=
  95218. {0x00000000,0x00000001,0x00000003,0x00000007,0x0000000f,
  95219. 0x0000001f,0x0000003f,0x0000007f,0x000000ff,0x000001ff,
  95220. 0x000003ff,0x000007ff,0x00000fff,0x00001fff,0x00003fff,
  95221. 0x00007fff,0x0000ffff,0x0001ffff,0x0003ffff,0x0007ffff,
  95222. 0x000fffff,0x001fffff,0x003fffff,0x007fffff,0x00ffffff,
  95223. 0x01ffffff,0x03ffffff,0x07ffffff,0x0fffffff,0x1fffffff,
  95224. 0x3fffffff,0x7fffffff,0xffffffff };
  95225. static const unsigned int mask8B[]=
  95226. {0x00,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff};
  95227. void oggpack_writeinit(oggpack_buffer *b){
  95228. memset(b,0,sizeof(*b));
  95229. b->ptr=b->buffer=(unsigned char*) _ogg_malloc(BUFFER_INCREMENT);
  95230. b->buffer[0]='\0';
  95231. b->storage=BUFFER_INCREMENT;
  95232. }
  95233. void oggpackB_writeinit(oggpack_buffer *b){
  95234. oggpack_writeinit(b);
  95235. }
  95236. void oggpack_writetrunc(oggpack_buffer *b,long bits){
  95237. long bytes=bits>>3;
  95238. bits-=bytes*8;
  95239. b->ptr=b->buffer+bytes;
  95240. b->endbit=bits;
  95241. b->endbyte=bytes;
  95242. *b->ptr&=mask[bits];
  95243. }
  95244. void oggpackB_writetrunc(oggpack_buffer *b,long bits){
  95245. long bytes=bits>>3;
  95246. bits-=bytes*8;
  95247. b->ptr=b->buffer+bytes;
  95248. b->endbit=bits;
  95249. b->endbyte=bytes;
  95250. *b->ptr&=mask8B[bits];
  95251. }
  95252. void oggpack_write(oggpack_buffer *b,unsigned long value,int bits){
  95253. if(b->endbyte+4>=b->storage){
  95254. b->buffer=(unsigned char*) _ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT);
  95255. b->storage+=BUFFER_INCREMENT;
  95256. b->ptr=b->buffer+b->endbyte;
  95257. }
  95258. value&=mask[bits];
  95259. bits+=b->endbit;
  95260. b->ptr[0]|=value<<b->endbit;
  95261. if(bits>=8){
  95262. b->ptr[1]=(unsigned char)(value>>(8-b->endbit));
  95263. if(bits>=16){
  95264. b->ptr[2]=(unsigned char)(value>>(16-b->endbit));
  95265. if(bits>=24){
  95266. b->ptr[3]=(unsigned char)(value>>(24-b->endbit));
  95267. if(bits>=32){
  95268. if(b->endbit)
  95269. b->ptr[4]=(unsigned char)(value>>(32-b->endbit));
  95270. else
  95271. b->ptr[4]=0;
  95272. }
  95273. }
  95274. }
  95275. }
  95276. b->endbyte+=bits/8;
  95277. b->ptr+=bits/8;
  95278. b->endbit=bits&7;
  95279. }
  95280. void oggpackB_write(oggpack_buffer *b,unsigned long value,int bits){
  95281. if(b->endbyte+4>=b->storage){
  95282. b->buffer=(unsigned char*) _ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT);
  95283. b->storage+=BUFFER_INCREMENT;
  95284. b->ptr=b->buffer+b->endbyte;
  95285. }
  95286. value=(value&mask[bits])<<(32-bits);
  95287. bits+=b->endbit;
  95288. b->ptr[0]|=value>>(24+b->endbit);
  95289. if(bits>=8){
  95290. b->ptr[1]=(unsigned char)(value>>(16+b->endbit));
  95291. if(bits>=16){
  95292. b->ptr[2]=(unsigned char)(value>>(8+b->endbit));
  95293. if(bits>=24){
  95294. b->ptr[3]=(unsigned char)(value>>(b->endbit));
  95295. if(bits>=32){
  95296. if(b->endbit)
  95297. b->ptr[4]=(unsigned char)(value<<(8-b->endbit));
  95298. else
  95299. b->ptr[4]=0;
  95300. }
  95301. }
  95302. }
  95303. }
  95304. b->endbyte+=bits/8;
  95305. b->ptr+=bits/8;
  95306. b->endbit=bits&7;
  95307. }
  95308. void oggpack_writealign(oggpack_buffer *b){
  95309. int bits=8-b->endbit;
  95310. if(bits<8)
  95311. oggpack_write(b,0,bits);
  95312. }
  95313. void oggpackB_writealign(oggpack_buffer *b){
  95314. int bits=8-b->endbit;
  95315. if(bits<8)
  95316. oggpackB_write(b,0,bits);
  95317. }
  95318. static void oggpack_writecopy_helper(oggpack_buffer *b,
  95319. void *source,
  95320. long bits,
  95321. void (*w)(oggpack_buffer *,
  95322. unsigned long,
  95323. int),
  95324. int msb){
  95325. unsigned char *ptr=(unsigned char *)source;
  95326. long bytes=bits/8;
  95327. bits-=bytes*8;
  95328. if(b->endbit){
  95329. int i;
  95330. for(i=0;i<bytes;i++)
  95331. w(b,(unsigned long)(ptr[i]),8);
  95332. }else{
  95333. if(b->endbyte+bytes+1>=b->storage){
  95334. b->storage=b->endbyte+bytes+BUFFER_INCREMENT;
  95335. b->buffer=(unsigned char*) _ogg_realloc(b->buffer,b->storage);
  95336. b->ptr=b->buffer+b->endbyte;
  95337. }
  95338. memmove(b->ptr,source,bytes);
  95339. b->ptr+=bytes;
  95340. b->endbyte+=bytes;
  95341. *b->ptr=0;
  95342. }
  95343. if(bits){
  95344. if(msb)
  95345. w(b,(unsigned long)(ptr[bytes]>>(8-bits)),bits);
  95346. else
  95347. w(b,(unsigned long)(ptr[bytes]),bits);
  95348. }
  95349. }
  95350. void oggpack_writecopy(oggpack_buffer *b,void *source,long bits){
  95351. oggpack_writecopy_helper(b,source,bits,oggpack_write,0);
  95352. }
  95353. void oggpackB_writecopy(oggpack_buffer *b,void *source,long bits){
  95354. oggpack_writecopy_helper(b,source,bits,oggpackB_write,1);
  95355. }
  95356. void oggpack_reset(oggpack_buffer *b){
  95357. b->ptr=b->buffer;
  95358. b->buffer[0]=0;
  95359. b->endbit=b->endbyte=0;
  95360. }
  95361. void oggpackB_reset(oggpack_buffer *b){
  95362. oggpack_reset(b);
  95363. }
  95364. void oggpack_writeclear(oggpack_buffer *b){
  95365. _ogg_free(b->buffer);
  95366. memset(b,0,sizeof(*b));
  95367. }
  95368. void oggpackB_writeclear(oggpack_buffer *b){
  95369. oggpack_writeclear(b);
  95370. }
  95371. void oggpack_readinit(oggpack_buffer *b,unsigned char *buf,int bytes){
  95372. memset(b,0,sizeof(*b));
  95373. b->buffer=b->ptr=buf;
  95374. b->storage=bytes;
  95375. }
  95376. void oggpackB_readinit(oggpack_buffer *b,unsigned char *buf,int bytes){
  95377. oggpack_readinit(b,buf,bytes);
  95378. }
  95379. long oggpack_look(oggpack_buffer *b,int bits){
  95380. unsigned long ret;
  95381. unsigned long m=mask[bits];
  95382. bits+=b->endbit;
  95383. if(b->endbyte+4>=b->storage){
  95384. if(b->endbyte*8+bits>b->storage*8)return(-1);
  95385. }
  95386. ret=b->ptr[0]>>b->endbit;
  95387. if(bits>8){
  95388. ret|=b->ptr[1]<<(8-b->endbit);
  95389. if(bits>16){
  95390. ret|=b->ptr[2]<<(16-b->endbit);
  95391. if(bits>24){
  95392. ret|=b->ptr[3]<<(24-b->endbit);
  95393. if(bits>32 && b->endbit)
  95394. ret|=b->ptr[4]<<(32-b->endbit);
  95395. }
  95396. }
  95397. }
  95398. return(m&ret);
  95399. }
  95400. long oggpackB_look(oggpack_buffer *b,int bits){
  95401. unsigned long ret;
  95402. int m=32-bits;
  95403. bits+=b->endbit;
  95404. if(b->endbyte+4>=b->storage){
  95405. if(b->endbyte*8+bits>b->storage*8)return(-1);
  95406. }
  95407. ret=b->ptr[0]<<(24+b->endbit);
  95408. if(bits>8){
  95409. ret|=b->ptr[1]<<(16+b->endbit);
  95410. if(bits>16){
  95411. ret|=b->ptr[2]<<(8+b->endbit);
  95412. if(bits>24){
  95413. ret|=b->ptr[3]<<(b->endbit);
  95414. if(bits>32 && b->endbit)
  95415. ret|=b->ptr[4]>>(8-b->endbit);
  95416. }
  95417. }
  95418. }
  95419. return ((ret&0xffffffff)>>(m>>1))>>((m+1)>>1);
  95420. }
  95421. long oggpack_look1(oggpack_buffer *b){
  95422. if(b->endbyte>=b->storage)return(-1);
  95423. return((b->ptr[0]>>b->endbit)&1);
  95424. }
  95425. long oggpackB_look1(oggpack_buffer *b){
  95426. if(b->endbyte>=b->storage)return(-1);
  95427. return((b->ptr[0]>>(7-b->endbit))&1);
  95428. }
  95429. void oggpack_adv(oggpack_buffer *b,int bits){
  95430. bits+=b->endbit;
  95431. b->ptr+=bits/8;
  95432. b->endbyte+=bits/8;
  95433. b->endbit=bits&7;
  95434. }
  95435. void oggpackB_adv(oggpack_buffer *b,int bits){
  95436. oggpack_adv(b,bits);
  95437. }
  95438. void oggpack_adv1(oggpack_buffer *b){
  95439. if(++(b->endbit)>7){
  95440. b->endbit=0;
  95441. b->ptr++;
  95442. b->endbyte++;
  95443. }
  95444. }
  95445. void oggpackB_adv1(oggpack_buffer *b){
  95446. oggpack_adv1(b);
  95447. }
  95448. long oggpack_read(oggpack_buffer *b,int bits){
  95449. long ret;
  95450. unsigned long m=mask[bits];
  95451. bits+=b->endbit;
  95452. if(b->endbyte+4>=b->storage){
  95453. ret=-1L;
  95454. if(b->endbyte*8+bits>b->storage*8)goto overflow;
  95455. }
  95456. ret=b->ptr[0]>>b->endbit;
  95457. if(bits>8){
  95458. ret|=b->ptr[1]<<(8-b->endbit);
  95459. if(bits>16){
  95460. ret|=b->ptr[2]<<(16-b->endbit);
  95461. if(bits>24){
  95462. ret|=b->ptr[3]<<(24-b->endbit);
  95463. if(bits>32 && b->endbit){
  95464. ret|=b->ptr[4]<<(32-b->endbit);
  95465. }
  95466. }
  95467. }
  95468. }
  95469. ret&=m;
  95470. overflow:
  95471. b->ptr+=bits/8;
  95472. b->endbyte+=bits/8;
  95473. b->endbit=bits&7;
  95474. return(ret);
  95475. }
  95476. long oggpackB_read(oggpack_buffer *b,int bits){
  95477. long ret;
  95478. long m=32-bits;
  95479. bits+=b->endbit;
  95480. if(b->endbyte+4>=b->storage){
  95481. ret=-1L;
  95482. if(b->endbyte*8+bits>b->storage*8)goto overflow;
  95483. }
  95484. ret=b->ptr[0]<<(24+b->endbit);
  95485. if(bits>8){
  95486. ret|=b->ptr[1]<<(16+b->endbit);
  95487. if(bits>16){
  95488. ret|=b->ptr[2]<<(8+b->endbit);
  95489. if(bits>24){
  95490. ret|=b->ptr[3]<<(b->endbit);
  95491. if(bits>32 && b->endbit)
  95492. ret|=b->ptr[4]>>(8-b->endbit);
  95493. }
  95494. }
  95495. }
  95496. ret=((ret&0xffffffffUL)>>(m>>1))>>((m+1)>>1);
  95497. overflow:
  95498. b->ptr+=bits/8;
  95499. b->endbyte+=bits/8;
  95500. b->endbit=bits&7;
  95501. return(ret);
  95502. }
  95503. long oggpack_read1(oggpack_buffer *b){
  95504. long ret;
  95505. if(b->endbyte>=b->storage){
  95506. ret=-1L;
  95507. goto overflow;
  95508. }
  95509. ret=(b->ptr[0]>>b->endbit)&1;
  95510. overflow:
  95511. b->endbit++;
  95512. if(b->endbit>7){
  95513. b->endbit=0;
  95514. b->ptr++;
  95515. b->endbyte++;
  95516. }
  95517. return(ret);
  95518. }
  95519. long oggpackB_read1(oggpack_buffer *b){
  95520. long ret;
  95521. if(b->endbyte>=b->storage){
  95522. ret=-1L;
  95523. goto overflow;
  95524. }
  95525. ret=(b->ptr[0]>>(7-b->endbit))&1;
  95526. overflow:
  95527. b->endbit++;
  95528. if(b->endbit>7){
  95529. b->endbit=0;
  95530. b->ptr++;
  95531. b->endbyte++;
  95532. }
  95533. return(ret);
  95534. }
  95535. long oggpack_bytes(oggpack_buffer *b){
  95536. return(b->endbyte+(b->endbit+7)/8);
  95537. }
  95538. long oggpack_bits(oggpack_buffer *b){
  95539. return(b->endbyte*8+b->endbit);
  95540. }
  95541. long oggpackB_bytes(oggpack_buffer *b){
  95542. return oggpack_bytes(b);
  95543. }
  95544. long oggpackB_bits(oggpack_buffer *b){
  95545. return oggpack_bits(b);
  95546. }
  95547. unsigned char *oggpack_get_buffer(oggpack_buffer *b){
  95548. return(b->buffer);
  95549. }
  95550. unsigned char *oggpackB_get_buffer(oggpack_buffer *b){
  95551. return oggpack_get_buffer(b);
  95552. }
  95553. #ifdef _V_SELFTEST
  95554. #include <stdio.h>
  95555. static int ilog(unsigned int v){
  95556. int ret=0;
  95557. while(v){
  95558. ret++;
  95559. v>>=1;
  95560. }
  95561. return(ret);
  95562. }
  95563. oggpack_buffer o;
  95564. oggpack_buffer r;
  95565. void report(char *in){
  95566. fprintf(stderr,"%s",in);
  95567. exit(1);
  95568. }
  95569. void cliptest(unsigned long *b,int vals,int bits,int *comp,int compsize){
  95570. long bytes,i;
  95571. unsigned char *buffer;
  95572. oggpack_reset(&o);
  95573. for(i=0;i<vals;i++)
  95574. oggpack_write(&o,b[i],bits?bits:ilog(b[i]));
  95575. buffer=oggpack_get_buffer(&o);
  95576. bytes=oggpack_bytes(&o);
  95577. if(bytes!=compsize)report("wrong number of bytes!\n");
  95578. for(i=0;i<bytes;i++)if(buffer[i]!=comp[i]){
  95579. for(i=0;i<bytes;i++)fprintf(stderr,"%x %x\n",(int)buffer[i],(int)comp[i]);
  95580. report("wrote incorrect value!\n");
  95581. }
  95582. oggpack_readinit(&r,buffer,bytes);
  95583. for(i=0;i<vals;i++){
  95584. int tbit=bits?bits:ilog(b[i]);
  95585. if(oggpack_look(&r,tbit)==-1)
  95586. report("out of data!\n");
  95587. if(oggpack_look(&r,tbit)!=(b[i]&mask[tbit]))
  95588. report("looked at incorrect value!\n");
  95589. if(tbit==1)
  95590. if(oggpack_look1(&r)!=(b[i]&mask[tbit]))
  95591. report("looked at single bit incorrect value!\n");
  95592. if(tbit==1){
  95593. if(oggpack_read1(&r)!=(b[i]&mask[tbit]))
  95594. report("read incorrect single bit value!\n");
  95595. }else{
  95596. if(oggpack_read(&r,tbit)!=(b[i]&mask[tbit]))
  95597. report("read incorrect value!\n");
  95598. }
  95599. }
  95600. if(oggpack_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95601. }
  95602. void cliptestB(unsigned long *b,int vals,int bits,int *comp,int compsize){
  95603. long bytes,i;
  95604. unsigned char *buffer;
  95605. oggpackB_reset(&o);
  95606. for(i=0;i<vals;i++)
  95607. oggpackB_write(&o,b[i],bits?bits:ilog(b[i]));
  95608. buffer=oggpackB_get_buffer(&o);
  95609. bytes=oggpackB_bytes(&o);
  95610. if(bytes!=compsize)report("wrong number of bytes!\n");
  95611. for(i=0;i<bytes;i++)if(buffer[i]!=comp[i]){
  95612. for(i=0;i<bytes;i++)fprintf(stderr,"%x %x\n",(int)buffer[i],(int)comp[i]);
  95613. report("wrote incorrect value!\n");
  95614. }
  95615. oggpackB_readinit(&r,buffer,bytes);
  95616. for(i=0;i<vals;i++){
  95617. int tbit=bits?bits:ilog(b[i]);
  95618. if(oggpackB_look(&r,tbit)==-1)
  95619. report("out of data!\n");
  95620. if(oggpackB_look(&r,tbit)!=(b[i]&mask[tbit]))
  95621. report("looked at incorrect value!\n");
  95622. if(tbit==1)
  95623. if(oggpackB_look1(&r)!=(b[i]&mask[tbit]))
  95624. report("looked at single bit incorrect value!\n");
  95625. if(tbit==1){
  95626. if(oggpackB_read1(&r)!=(b[i]&mask[tbit]))
  95627. report("read incorrect single bit value!\n");
  95628. }else{
  95629. if(oggpackB_read(&r,tbit)!=(b[i]&mask[tbit]))
  95630. report("read incorrect value!\n");
  95631. }
  95632. }
  95633. if(oggpackB_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95634. }
  95635. int main(void){
  95636. unsigned char *buffer;
  95637. long bytes,i;
  95638. static unsigned long testbuffer1[]=
  95639. {18,12,103948,4325,543,76,432,52,3,65,4,56,32,42,34,21,1,23,32,546,456,7,
  95640. 567,56,8,8,55,3,52,342,341,4,265,7,67,86,2199,21,7,1,5,1,4};
  95641. int test1size=43;
  95642. static unsigned long testbuffer2[]=
  95643. {216531625L,1237861823,56732452,131,3212421,12325343,34547562,12313212,
  95644. 1233432,534,5,346435231,14436467,7869299,76326614,167548585,
  95645. 85525151,0,12321,1,349528352};
  95646. int test2size=21;
  95647. static unsigned long testbuffer3[]=
  95648. {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,
  95649. 0,1,30,1,1,1,0,0,1,0,0,0,12,0,11,0,1,0,0,1};
  95650. int test3size=56;
  95651. static unsigned long large[]=
  95652. {2136531625L,2137861823,56732452,131,3212421,12325343,34547562,12313212,
  95653. 1233432,534,5,2146435231,14436467,7869299,76326614,167548585,
  95654. 85525151,0,12321,1,2146528352};
  95655. int onesize=33;
  95656. static int one[33]={146,25,44,151,195,15,153,176,233,131,196,65,85,172,47,40,
  95657. 34,242,223,136,35,222,211,86,171,50,225,135,214,75,172,
  95658. 223,4};
  95659. static int oneB[33]={150,101,131,33,203,15,204,216,105,193,156,65,84,85,222,
  95660. 8,139,145,227,126,34,55,244,171,85,100,39,195,173,18,
  95661. 245,251,128};
  95662. int twosize=6;
  95663. static int two[6]={61,255,255,251,231,29};
  95664. static int twoB[6]={247,63,255,253,249,120};
  95665. int threesize=54;
  95666. static int three[54]={169,2,232,252,91,132,156,36,89,13,123,176,144,32,254,
  95667. 142,224,85,59,121,144,79,124,23,67,90,90,216,79,23,83,
  95668. 58,135,196,61,55,129,183,54,101,100,170,37,127,126,10,
  95669. 100,52,4,14,18,86,77,1};
  95670. static int threeB[54]={206,128,42,153,57,8,183,251,13,89,36,30,32,144,183,
  95671. 130,59,240,121,59,85,223,19,228,180,134,33,107,74,98,
  95672. 233,253,196,135,63,2,110,114,50,155,90,127,37,170,104,
  95673. 200,20,254,4,58,106,176,144,0};
  95674. int foursize=38;
  95675. static int four[38]={18,6,163,252,97,194,104,131,32,1,7,82,137,42,129,11,72,
  95676. 132,60,220,112,8,196,109,64,179,86,9,137,195,208,122,169,
  95677. 28,2,133,0,1};
  95678. static int fourB[38]={36,48,102,83,243,24,52,7,4,35,132,10,145,21,2,93,2,41,
  95679. 1,219,184,16,33,184,54,149,170,132,18,30,29,98,229,67,
  95680. 129,10,4,32};
  95681. int fivesize=45;
  95682. static int five[45]={169,2,126,139,144,172,30,4,80,72,240,59,130,218,73,62,
  95683. 241,24,210,44,4,20,0,248,116,49,135,100,110,130,181,169,
  95684. 84,75,159,2,1,0,132,192,8,0,0,18,22};
  95685. static int fiveB[45]={1,84,145,111,245,100,128,8,56,36,40,71,126,78,213,226,
  95686. 124,105,12,0,133,128,0,162,233,242,67,152,77,205,77,
  95687. 172,150,169,129,79,128,0,6,4,32,0,27,9,0};
  95688. int sixsize=7;
  95689. static int six[7]={17,177,170,242,169,19,148};
  95690. static int sixB[7]={136,141,85,79,149,200,41};
  95691. oggpack_writeinit(&o);
  95692. fprintf(stderr,"\nSmall preclipped packing (LSb): ");
  95693. cliptest(testbuffer1,test1size,0,one,onesize);
  95694. fprintf(stderr,"ok.");
  95695. fprintf(stderr,"\nNull bit call (LSb): ");
  95696. cliptest(testbuffer3,test3size,0,two,twosize);
  95697. fprintf(stderr,"ok.");
  95698. fprintf(stderr,"\nLarge preclipped packing (LSb): ");
  95699. cliptest(testbuffer2,test2size,0,three,threesize);
  95700. fprintf(stderr,"ok.");
  95701. fprintf(stderr,"\n32 bit preclipped packing (LSb): ");
  95702. oggpack_reset(&o);
  95703. for(i=0;i<test2size;i++)
  95704. oggpack_write(&o,large[i],32);
  95705. buffer=oggpack_get_buffer(&o);
  95706. bytes=oggpack_bytes(&o);
  95707. oggpack_readinit(&r,buffer,bytes);
  95708. for(i=0;i<test2size;i++){
  95709. if(oggpack_look(&r,32)==-1)report("out of data. failed!");
  95710. if(oggpack_look(&r,32)!=large[i]){
  95711. fprintf(stderr,"%ld != %ld (%lx!=%lx):",oggpack_look(&r,32),large[i],
  95712. oggpack_look(&r,32),large[i]);
  95713. report("read incorrect value!\n");
  95714. }
  95715. oggpack_adv(&r,32);
  95716. }
  95717. if(oggpack_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95718. fprintf(stderr,"ok.");
  95719. fprintf(stderr,"\nSmall unclipped packing (LSb): ");
  95720. cliptest(testbuffer1,test1size,7,four,foursize);
  95721. fprintf(stderr,"ok.");
  95722. fprintf(stderr,"\nLarge unclipped packing (LSb): ");
  95723. cliptest(testbuffer2,test2size,17,five,fivesize);
  95724. fprintf(stderr,"ok.");
  95725. fprintf(stderr,"\nSingle bit unclipped packing (LSb): ");
  95726. cliptest(testbuffer3,test3size,1,six,sixsize);
  95727. fprintf(stderr,"ok.");
  95728. fprintf(stderr,"\nTesting read past end (LSb): ");
  95729. oggpack_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95730. for(i=0;i<64;i++){
  95731. if(oggpack_read(&r,1)!=0){
  95732. fprintf(stderr,"failed; got -1 prematurely.\n");
  95733. exit(1);
  95734. }
  95735. }
  95736. if(oggpack_look(&r,1)!=-1 ||
  95737. oggpack_read(&r,1)!=-1){
  95738. fprintf(stderr,"failed; read past end without -1.\n");
  95739. exit(1);
  95740. }
  95741. oggpack_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95742. if(oggpack_read(&r,30)!=0 || oggpack_read(&r,16)!=0){
  95743. fprintf(stderr,"failed 2; got -1 prematurely.\n");
  95744. exit(1);
  95745. }
  95746. if(oggpack_look(&r,18)!=0 ||
  95747. oggpack_look(&r,18)!=0){
  95748. fprintf(stderr,"failed 3; got -1 prematurely.\n");
  95749. exit(1);
  95750. }
  95751. if(oggpack_look(&r,19)!=-1 ||
  95752. oggpack_look(&r,19)!=-1){
  95753. fprintf(stderr,"failed; read past end without -1.\n");
  95754. exit(1);
  95755. }
  95756. if(oggpack_look(&r,32)!=-1 ||
  95757. oggpack_look(&r,32)!=-1){
  95758. fprintf(stderr,"failed; read past end without -1.\n");
  95759. exit(1);
  95760. }
  95761. oggpack_writeclear(&o);
  95762. fprintf(stderr,"ok.\n");
  95763. oggpackB_writeinit(&o);
  95764. fprintf(stderr,"\nSmall preclipped packing (MSb): ");
  95765. cliptestB(testbuffer1,test1size,0,oneB,onesize);
  95766. fprintf(stderr,"ok.");
  95767. fprintf(stderr,"\nNull bit call (MSb): ");
  95768. cliptestB(testbuffer3,test3size,0,twoB,twosize);
  95769. fprintf(stderr,"ok.");
  95770. fprintf(stderr,"\nLarge preclipped packing (MSb): ");
  95771. cliptestB(testbuffer2,test2size,0,threeB,threesize);
  95772. fprintf(stderr,"ok.");
  95773. fprintf(stderr,"\n32 bit preclipped packing (MSb): ");
  95774. oggpackB_reset(&o);
  95775. for(i=0;i<test2size;i++)
  95776. oggpackB_write(&o,large[i],32);
  95777. buffer=oggpackB_get_buffer(&o);
  95778. bytes=oggpackB_bytes(&o);
  95779. oggpackB_readinit(&r,buffer,bytes);
  95780. for(i=0;i<test2size;i++){
  95781. if(oggpackB_look(&r,32)==-1)report("out of data. failed!");
  95782. if(oggpackB_look(&r,32)!=large[i]){
  95783. fprintf(stderr,"%ld != %ld (%lx!=%lx):",oggpackB_look(&r,32),large[i],
  95784. oggpackB_look(&r,32),large[i]);
  95785. report("read incorrect value!\n");
  95786. }
  95787. oggpackB_adv(&r,32);
  95788. }
  95789. if(oggpackB_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95790. fprintf(stderr,"ok.");
  95791. fprintf(stderr,"\nSmall unclipped packing (MSb): ");
  95792. cliptestB(testbuffer1,test1size,7,fourB,foursize);
  95793. fprintf(stderr,"ok.");
  95794. fprintf(stderr,"\nLarge unclipped packing (MSb): ");
  95795. cliptestB(testbuffer2,test2size,17,fiveB,fivesize);
  95796. fprintf(stderr,"ok.");
  95797. fprintf(stderr,"\nSingle bit unclipped packing (MSb): ");
  95798. cliptestB(testbuffer3,test3size,1,sixB,sixsize);
  95799. fprintf(stderr,"ok.");
  95800. fprintf(stderr,"\nTesting read past end (MSb): ");
  95801. oggpackB_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95802. for(i=0;i<64;i++){
  95803. if(oggpackB_read(&r,1)!=0){
  95804. fprintf(stderr,"failed; got -1 prematurely.\n");
  95805. exit(1);
  95806. }
  95807. }
  95808. if(oggpackB_look(&r,1)!=-1 ||
  95809. oggpackB_read(&r,1)!=-1){
  95810. fprintf(stderr,"failed; read past end without -1.\n");
  95811. exit(1);
  95812. }
  95813. oggpackB_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95814. if(oggpackB_read(&r,30)!=0 || oggpackB_read(&r,16)!=0){
  95815. fprintf(stderr,"failed 2; got -1 prematurely.\n");
  95816. exit(1);
  95817. }
  95818. if(oggpackB_look(&r,18)!=0 ||
  95819. oggpackB_look(&r,18)!=0){
  95820. fprintf(stderr,"failed 3; got -1 prematurely.\n");
  95821. exit(1);
  95822. }
  95823. if(oggpackB_look(&r,19)!=-1 ||
  95824. oggpackB_look(&r,19)!=-1){
  95825. fprintf(stderr,"failed; read past end without -1.\n");
  95826. exit(1);
  95827. }
  95828. if(oggpackB_look(&r,32)!=-1 ||
  95829. oggpackB_look(&r,32)!=-1){
  95830. fprintf(stderr,"failed; read past end without -1.\n");
  95831. exit(1);
  95832. }
  95833. oggpackB_writeclear(&o);
  95834. fprintf(stderr,"ok.\n\n");
  95835. return(0);
  95836. }
  95837. #endif /* _V_SELFTEST */
  95838. #undef BUFFER_INCREMENT
  95839. #endif
  95840. /*** End of inlined file: bitwise.c ***/
  95841. /*** Start of inlined file: framing.c ***/
  95842. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  95843. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  95844. // tasks..
  95845. #if JUCE_MSVC
  95846. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  95847. #endif
  95848. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  95849. #if JUCE_USE_OGGVORBIS
  95850. #include <stdlib.h>
  95851. #include <string.h>
  95852. int ogg_page_version(ogg_page *og){
  95853. return((int)(og->header[4]));
  95854. }
  95855. int ogg_page_continued(ogg_page *og){
  95856. return((int)(og->header[5]&0x01));
  95857. }
  95858. int ogg_page_bos(ogg_page *og){
  95859. return((int)(og->header[5]&0x02));
  95860. }
  95861. int ogg_page_eos(ogg_page *og){
  95862. return((int)(og->header[5]&0x04));
  95863. }
  95864. ogg_int64_t ogg_page_granulepos(ogg_page *og){
  95865. unsigned char *page=og->header;
  95866. ogg_int64_t granulepos=page[13]&(0xff);
  95867. granulepos= (granulepos<<8)|(page[12]&0xff);
  95868. granulepos= (granulepos<<8)|(page[11]&0xff);
  95869. granulepos= (granulepos<<8)|(page[10]&0xff);
  95870. granulepos= (granulepos<<8)|(page[9]&0xff);
  95871. granulepos= (granulepos<<8)|(page[8]&0xff);
  95872. granulepos= (granulepos<<8)|(page[7]&0xff);
  95873. granulepos= (granulepos<<8)|(page[6]&0xff);
  95874. return(granulepos);
  95875. }
  95876. int ogg_page_serialno(ogg_page *og){
  95877. return(og->header[14] |
  95878. (og->header[15]<<8) |
  95879. (og->header[16]<<16) |
  95880. (og->header[17]<<24));
  95881. }
  95882. long ogg_page_pageno(ogg_page *og){
  95883. return(og->header[18] |
  95884. (og->header[19]<<8) |
  95885. (og->header[20]<<16) |
  95886. (og->header[21]<<24));
  95887. }
  95888. int ogg_page_packets(ogg_page *og){
  95889. int i,n=og->header[26],count=0;
  95890. for(i=0;i<n;i++)
  95891. if(og->header[27+i]<255)count++;
  95892. return(count);
  95893. }
  95894. #if 0
  95895. static ogg_uint32_t _ogg_crc_entry(unsigned long index){
  95896. int i;
  95897. unsigned long r;
  95898. r = index << 24;
  95899. for (i=0; i<8; i++)
  95900. if (r & 0x80000000UL)
  95901. r = (r << 1) ^ 0x04c11db7; /* The same as the ethernet generator
  95902. polynomial, although we use an
  95903. unreflected alg and an init/final
  95904. of 0, not 0xffffffff */
  95905. else
  95906. r<<=1;
  95907. return (r & 0xffffffffUL);
  95908. }
  95909. #endif
  95910. static const ogg_uint32_t crc_lookup[256]={
  95911. 0x00000000,0x04c11db7,0x09823b6e,0x0d4326d9,
  95912. 0x130476dc,0x17c56b6b,0x1a864db2,0x1e475005,
  95913. 0x2608edb8,0x22c9f00f,0x2f8ad6d6,0x2b4bcb61,
  95914. 0x350c9b64,0x31cd86d3,0x3c8ea00a,0x384fbdbd,
  95915. 0x4c11db70,0x48d0c6c7,0x4593e01e,0x4152fda9,
  95916. 0x5f15adac,0x5bd4b01b,0x569796c2,0x52568b75,
  95917. 0x6a1936c8,0x6ed82b7f,0x639b0da6,0x675a1011,
  95918. 0x791d4014,0x7ddc5da3,0x709f7b7a,0x745e66cd,
  95919. 0x9823b6e0,0x9ce2ab57,0x91a18d8e,0x95609039,
  95920. 0x8b27c03c,0x8fe6dd8b,0x82a5fb52,0x8664e6e5,
  95921. 0xbe2b5b58,0xbaea46ef,0xb7a96036,0xb3687d81,
  95922. 0xad2f2d84,0xa9ee3033,0xa4ad16ea,0xa06c0b5d,
  95923. 0xd4326d90,0xd0f37027,0xddb056fe,0xd9714b49,
  95924. 0xc7361b4c,0xc3f706fb,0xceb42022,0xca753d95,
  95925. 0xf23a8028,0xf6fb9d9f,0xfbb8bb46,0xff79a6f1,
  95926. 0xe13ef6f4,0xe5ffeb43,0xe8bccd9a,0xec7dd02d,
  95927. 0x34867077,0x30476dc0,0x3d044b19,0x39c556ae,
  95928. 0x278206ab,0x23431b1c,0x2e003dc5,0x2ac12072,
  95929. 0x128e9dcf,0x164f8078,0x1b0ca6a1,0x1fcdbb16,
  95930. 0x018aeb13,0x054bf6a4,0x0808d07d,0x0cc9cdca,
  95931. 0x7897ab07,0x7c56b6b0,0x71159069,0x75d48dde,
  95932. 0x6b93dddb,0x6f52c06c,0x6211e6b5,0x66d0fb02,
  95933. 0x5e9f46bf,0x5a5e5b08,0x571d7dd1,0x53dc6066,
  95934. 0x4d9b3063,0x495a2dd4,0x44190b0d,0x40d816ba,
  95935. 0xaca5c697,0xa864db20,0xa527fdf9,0xa1e6e04e,
  95936. 0xbfa1b04b,0xbb60adfc,0xb6238b25,0xb2e29692,
  95937. 0x8aad2b2f,0x8e6c3698,0x832f1041,0x87ee0df6,
  95938. 0x99a95df3,0x9d684044,0x902b669d,0x94ea7b2a,
  95939. 0xe0b41de7,0xe4750050,0xe9362689,0xedf73b3e,
  95940. 0xf3b06b3b,0xf771768c,0xfa325055,0xfef34de2,
  95941. 0xc6bcf05f,0xc27dede8,0xcf3ecb31,0xcbffd686,
  95942. 0xd5b88683,0xd1799b34,0xdc3abded,0xd8fba05a,
  95943. 0x690ce0ee,0x6dcdfd59,0x608edb80,0x644fc637,
  95944. 0x7a089632,0x7ec98b85,0x738aad5c,0x774bb0eb,
  95945. 0x4f040d56,0x4bc510e1,0x46863638,0x42472b8f,
  95946. 0x5c007b8a,0x58c1663d,0x558240e4,0x51435d53,
  95947. 0x251d3b9e,0x21dc2629,0x2c9f00f0,0x285e1d47,
  95948. 0x36194d42,0x32d850f5,0x3f9b762c,0x3b5a6b9b,
  95949. 0x0315d626,0x07d4cb91,0x0a97ed48,0x0e56f0ff,
  95950. 0x1011a0fa,0x14d0bd4d,0x19939b94,0x1d528623,
  95951. 0xf12f560e,0xf5ee4bb9,0xf8ad6d60,0xfc6c70d7,
  95952. 0xe22b20d2,0xe6ea3d65,0xeba91bbc,0xef68060b,
  95953. 0xd727bbb6,0xd3e6a601,0xdea580d8,0xda649d6f,
  95954. 0xc423cd6a,0xc0e2d0dd,0xcda1f604,0xc960ebb3,
  95955. 0xbd3e8d7e,0xb9ff90c9,0xb4bcb610,0xb07daba7,
  95956. 0xae3afba2,0xaafbe615,0xa7b8c0cc,0xa379dd7b,
  95957. 0x9b3660c6,0x9ff77d71,0x92b45ba8,0x9675461f,
  95958. 0x8832161a,0x8cf30bad,0x81b02d74,0x857130c3,
  95959. 0x5d8a9099,0x594b8d2e,0x5408abf7,0x50c9b640,
  95960. 0x4e8ee645,0x4a4ffbf2,0x470cdd2b,0x43cdc09c,
  95961. 0x7b827d21,0x7f436096,0x7200464f,0x76c15bf8,
  95962. 0x68860bfd,0x6c47164a,0x61043093,0x65c52d24,
  95963. 0x119b4be9,0x155a565e,0x18197087,0x1cd86d30,
  95964. 0x029f3d35,0x065e2082,0x0b1d065b,0x0fdc1bec,
  95965. 0x3793a651,0x3352bbe6,0x3e119d3f,0x3ad08088,
  95966. 0x2497d08d,0x2056cd3a,0x2d15ebe3,0x29d4f654,
  95967. 0xc5a92679,0xc1683bce,0xcc2b1d17,0xc8ea00a0,
  95968. 0xd6ad50a5,0xd26c4d12,0xdf2f6bcb,0xdbee767c,
  95969. 0xe3a1cbc1,0xe760d676,0xea23f0af,0xeee2ed18,
  95970. 0xf0a5bd1d,0xf464a0aa,0xf9278673,0xfde69bc4,
  95971. 0x89b8fd09,0x8d79e0be,0x803ac667,0x84fbdbd0,
  95972. 0x9abc8bd5,0x9e7d9662,0x933eb0bb,0x97ffad0c,
  95973. 0xafb010b1,0xab710d06,0xa6322bdf,0xa2f33668,
  95974. 0xbcb4666d,0xb8757bda,0xb5365d03,0xb1f740b4};
  95975. int ogg_stream_init(ogg_stream_state *os,int serialno){
  95976. if(os){
  95977. memset(os,0,sizeof(*os));
  95978. os->body_storage=16*1024;
  95979. os->body_data=(unsigned char*) _ogg_malloc(os->body_storage*sizeof(*os->body_data));
  95980. os->lacing_storage=1024;
  95981. os->lacing_vals=(int*) _ogg_malloc(os->lacing_storage*sizeof(*os->lacing_vals));
  95982. os->granule_vals=(ogg_int64_t*) _ogg_malloc(os->lacing_storage*sizeof(*os->granule_vals));
  95983. os->serialno=serialno;
  95984. return(0);
  95985. }
  95986. return(-1);
  95987. }
  95988. int ogg_stream_clear(ogg_stream_state *os){
  95989. if(os){
  95990. if(os->body_data)_ogg_free(os->body_data);
  95991. if(os->lacing_vals)_ogg_free(os->lacing_vals);
  95992. if(os->granule_vals)_ogg_free(os->granule_vals);
  95993. memset(os,0,sizeof(*os));
  95994. }
  95995. return(0);
  95996. }
  95997. int ogg_stream_destroy(ogg_stream_state *os){
  95998. if(os){
  95999. ogg_stream_clear(os);
  96000. _ogg_free(os);
  96001. }
  96002. return(0);
  96003. }
  96004. static void _os_body_expand(ogg_stream_state *os,int needed){
  96005. if(os->body_storage<=os->body_fill+needed){
  96006. os->body_storage+=(needed+1024);
  96007. os->body_data=(unsigned char*) _ogg_realloc(os->body_data,os->body_storage*sizeof(*os->body_data));
  96008. }
  96009. }
  96010. static void _os_lacing_expand(ogg_stream_state *os,int needed){
  96011. if(os->lacing_storage<=os->lacing_fill+needed){
  96012. os->lacing_storage+=(needed+32);
  96013. os->lacing_vals=(int*)_ogg_realloc(os->lacing_vals,os->lacing_storage*sizeof(*os->lacing_vals));
  96014. os->granule_vals=(ogg_int64_t*)_ogg_realloc(os->granule_vals,os->lacing_storage*sizeof(*os->granule_vals));
  96015. }
  96016. }
  96017. void ogg_page_checksum_set(ogg_page *og){
  96018. if(og){
  96019. ogg_uint32_t crc_reg=0;
  96020. int i;
  96021. og->header[22]=0;
  96022. og->header[23]=0;
  96023. og->header[24]=0;
  96024. og->header[25]=0;
  96025. for(i=0;i<og->header_len;i++)
  96026. crc_reg=(crc_reg<<8)^crc_lookup[((crc_reg >> 24)&0xff)^og->header[i]];
  96027. for(i=0;i<og->body_len;i++)
  96028. crc_reg=(crc_reg<<8)^crc_lookup[((crc_reg >> 24)&0xff)^og->body[i]];
  96029. og->header[22]=(unsigned char)(crc_reg&0xff);
  96030. og->header[23]=(unsigned char)((crc_reg>>8)&0xff);
  96031. og->header[24]=(unsigned char)((crc_reg>>16)&0xff);
  96032. og->header[25]=(unsigned char)((crc_reg>>24)&0xff);
  96033. }
  96034. }
  96035. int ogg_stream_packetin(ogg_stream_state *os,ogg_packet *op){
  96036. int lacing_vals=op->bytes/255+1,i;
  96037. if(os->body_returned){
  96038. os->body_fill-=os->body_returned;
  96039. if(os->body_fill)
  96040. memmove(os->body_data,os->body_data+os->body_returned,
  96041. os->body_fill);
  96042. os->body_returned=0;
  96043. }
  96044. _os_body_expand(os,op->bytes);
  96045. _os_lacing_expand(os,lacing_vals);
  96046. memcpy(os->body_data+os->body_fill,op->packet,op->bytes);
  96047. os->body_fill+=op->bytes;
  96048. for(i=0;i<lacing_vals-1;i++){
  96049. os->lacing_vals[os->lacing_fill+i]=255;
  96050. os->granule_vals[os->lacing_fill+i]=os->granulepos;
  96051. }
  96052. os->lacing_vals[os->lacing_fill+i]=(op->bytes)%255;
  96053. os->granulepos=os->granule_vals[os->lacing_fill+i]=op->granulepos;
  96054. os->lacing_vals[os->lacing_fill]|= 0x100;
  96055. os->lacing_fill+=lacing_vals;
  96056. os->packetno++;
  96057. if(op->e_o_s)os->e_o_s=1;
  96058. return(0);
  96059. }
  96060. int ogg_stream_flush(ogg_stream_state *os,ogg_page *og){
  96061. int i;
  96062. int vals=0;
  96063. int maxvals=(os->lacing_fill>255?255:os->lacing_fill);
  96064. int bytes=0;
  96065. long acc=0;
  96066. ogg_int64_t granule_pos=-1;
  96067. if(maxvals==0)return(0);
  96068. if(os->b_o_s==0){ /* 'initial header page' case */
  96069. granule_pos=0;
  96070. for(vals=0;vals<maxvals;vals++){
  96071. if((os->lacing_vals[vals]&0x0ff)<255){
  96072. vals++;
  96073. break;
  96074. }
  96075. }
  96076. }else{
  96077. for(vals=0;vals<maxvals;vals++){
  96078. if(acc>4096)break;
  96079. acc+=os->lacing_vals[vals]&0x0ff;
  96080. if((os->lacing_vals[vals]&0xff)<255)
  96081. granule_pos=os->granule_vals[vals];
  96082. }
  96083. }
  96084. memcpy(os->header,"OggS",4);
  96085. os->header[4]=0x00;
  96086. os->header[5]=0x00;
  96087. if((os->lacing_vals[0]&0x100)==0)os->header[5]|=0x01;
  96088. if(os->b_o_s==0)os->header[5]|=0x02;
  96089. if(os->e_o_s && os->lacing_fill==vals)os->header[5]|=0x04;
  96090. os->b_o_s=1;
  96091. for(i=6;i<14;i++){
  96092. os->header[i]=(unsigned char)(granule_pos&0xff);
  96093. granule_pos>>=8;
  96094. }
  96095. {
  96096. long serialno=os->serialno;
  96097. for(i=14;i<18;i++){
  96098. os->header[i]=(unsigned char)(serialno&0xff);
  96099. serialno>>=8;
  96100. }
  96101. }
  96102. if(os->pageno==-1)os->pageno=0; /* because someone called
  96103. stream_reset; this would be a
  96104. strange thing to do in an
  96105. encode stream, but it has
  96106. plausible uses */
  96107. {
  96108. long pageno=os->pageno++;
  96109. for(i=18;i<22;i++){
  96110. os->header[i]=(unsigned char)(pageno&0xff);
  96111. pageno>>=8;
  96112. }
  96113. }
  96114. os->header[22]=0;
  96115. os->header[23]=0;
  96116. os->header[24]=0;
  96117. os->header[25]=0;
  96118. os->header[26]=(unsigned char)(vals&0xff);
  96119. for(i=0;i<vals;i++)
  96120. bytes+=os->header[i+27]=(unsigned char)(os->lacing_vals[i]&0xff);
  96121. og->header=os->header;
  96122. og->header_len=os->header_fill=vals+27;
  96123. og->body=os->body_data+os->body_returned;
  96124. og->body_len=bytes;
  96125. os->lacing_fill-=vals;
  96126. memmove(os->lacing_vals,os->lacing_vals+vals,os->lacing_fill*sizeof(*os->lacing_vals));
  96127. memmove(os->granule_vals,os->granule_vals+vals,os->lacing_fill*sizeof(*os->granule_vals));
  96128. os->body_returned+=bytes;
  96129. ogg_page_checksum_set(og);
  96130. return(1);
  96131. }
  96132. int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og){
  96133. if((os->e_o_s&&os->lacing_fill) || /* 'were done, now flush' case */
  96134. os->body_fill-os->body_returned > 4096 ||/* 'page nominal size' case */
  96135. os->lacing_fill>=255 || /* 'segment table full' case */
  96136. (os->lacing_fill&&!os->b_o_s)){ /* 'initial header page' case */
  96137. return(ogg_stream_flush(os,og));
  96138. }
  96139. return(0);
  96140. }
  96141. int ogg_stream_eos(ogg_stream_state *os){
  96142. return os->e_o_s;
  96143. }
  96144. int ogg_sync_init(ogg_sync_state *oy){
  96145. if(oy){
  96146. memset(oy,0,sizeof(*oy));
  96147. }
  96148. return(0);
  96149. }
  96150. int ogg_sync_clear(ogg_sync_state *oy){
  96151. if(oy){
  96152. if(oy->data)_ogg_free(oy->data);
  96153. ogg_sync_init(oy);
  96154. }
  96155. return(0);
  96156. }
  96157. int ogg_sync_destroy(ogg_sync_state *oy){
  96158. if(oy){
  96159. ogg_sync_clear(oy);
  96160. _ogg_free(oy);
  96161. }
  96162. return(0);
  96163. }
  96164. char *ogg_sync_buffer(ogg_sync_state *oy, long size){
  96165. if(oy->returned){
  96166. oy->fill-=oy->returned;
  96167. if(oy->fill>0)
  96168. memmove(oy->data,oy->data+oy->returned,oy->fill);
  96169. oy->returned=0;
  96170. }
  96171. if(size>oy->storage-oy->fill){
  96172. long newsize=size+oy->fill+4096; /* an extra page to be nice */
  96173. if(oy->data)
  96174. oy->data=(unsigned char*) _ogg_realloc(oy->data,newsize);
  96175. else
  96176. oy->data=(unsigned char*) _ogg_malloc(newsize);
  96177. oy->storage=newsize;
  96178. }
  96179. return((char *)oy->data+oy->fill);
  96180. }
  96181. int ogg_sync_wrote(ogg_sync_state *oy, long bytes){
  96182. if(oy->fill+bytes>oy->storage)return(-1);
  96183. oy->fill+=bytes;
  96184. return(0);
  96185. }
  96186. long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og){
  96187. unsigned char *page=oy->data+oy->returned;
  96188. unsigned char *next;
  96189. long bytes=oy->fill-oy->returned;
  96190. if(oy->headerbytes==0){
  96191. int headerbytes,i;
  96192. if(bytes<27)return(0); /* not enough for a header */
  96193. if(memcmp(page,"OggS",4))goto sync_fail;
  96194. headerbytes=page[26]+27;
  96195. if(bytes<headerbytes)return(0); /* not enough for header + seg table */
  96196. for(i=0;i<page[26];i++)
  96197. oy->bodybytes+=page[27+i];
  96198. oy->headerbytes=headerbytes;
  96199. }
  96200. if(oy->bodybytes+oy->headerbytes>bytes)return(0);
  96201. {
  96202. char chksum[4];
  96203. ogg_page log;
  96204. memcpy(chksum,page+22,4);
  96205. memset(page+22,0,4);
  96206. log.header=page;
  96207. log.header_len=oy->headerbytes;
  96208. log.body=page+oy->headerbytes;
  96209. log.body_len=oy->bodybytes;
  96210. ogg_page_checksum_set(&log);
  96211. if(memcmp(chksum,page+22,4)){
  96212. memcpy(page+22,chksum,4);
  96213. goto sync_fail;
  96214. }
  96215. }
  96216. {
  96217. unsigned char *page=oy->data+oy->returned;
  96218. long bytes;
  96219. if(og){
  96220. og->header=page;
  96221. og->header_len=oy->headerbytes;
  96222. og->body=page+oy->headerbytes;
  96223. og->body_len=oy->bodybytes;
  96224. }
  96225. oy->unsynced=0;
  96226. oy->returned+=(bytes=oy->headerbytes+oy->bodybytes);
  96227. oy->headerbytes=0;
  96228. oy->bodybytes=0;
  96229. return(bytes);
  96230. }
  96231. sync_fail:
  96232. oy->headerbytes=0;
  96233. oy->bodybytes=0;
  96234. next=(unsigned char*)memchr(page+1,'O',bytes-1);
  96235. if(!next)
  96236. next=oy->data+oy->fill;
  96237. oy->returned=next-oy->data;
  96238. return(-(next-page));
  96239. }
  96240. int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og){
  96241. for(;;){
  96242. long ret=ogg_sync_pageseek(oy,og);
  96243. if(ret>0){
  96244. return(1);
  96245. }
  96246. if(ret==0){
  96247. return(0);
  96248. }
  96249. if(!oy->unsynced){
  96250. oy->unsynced=1;
  96251. return(-1);
  96252. }
  96253. }
  96254. }
  96255. int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og){
  96256. unsigned char *header=og->header;
  96257. unsigned char *body=og->body;
  96258. long bodysize=og->body_len;
  96259. int segptr=0;
  96260. int version=ogg_page_version(og);
  96261. int continued=ogg_page_continued(og);
  96262. int bos=ogg_page_bos(og);
  96263. int eos=ogg_page_eos(og);
  96264. ogg_int64_t granulepos=ogg_page_granulepos(og);
  96265. int serialno=ogg_page_serialno(og);
  96266. long pageno=ogg_page_pageno(og);
  96267. int segments=header[26];
  96268. {
  96269. long lr=os->lacing_returned;
  96270. long br=os->body_returned;
  96271. if(br){
  96272. os->body_fill-=br;
  96273. if(os->body_fill)
  96274. memmove(os->body_data,os->body_data+br,os->body_fill);
  96275. os->body_returned=0;
  96276. }
  96277. if(lr){
  96278. if(os->lacing_fill-lr){
  96279. memmove(os->lacing_vals,os->lacing_vals+lr,
  96280. (os->lacing_fill-lr)*sizeof(*os->lacing_vals));
  96281. memmove(os->granule_vals,os->granule_vals+lr,
  96282. (os->lacing_fill-lr)*sizeof(*os->granule_vals));
  96283. }
  96284. os->lacing_fill-=lr;
  96285. os->lacing_packet-=lr;
  96286. os->lacing_returned=0;
  96287. }
  96288. }
  96289. if(serialno!=os->serialno)return(-1);
  96290. if(version>0)return(-1);
  96291. _os_lacing_expand(os,segments+1);
  96292. if(pageno!=os->pageno){
  96293. int i;
  96294. for(i=os->lacing_packet;i<os->lacing_fill;i++)
  96295. os->body_fill-=os->lacing_vals[i]&0xff;
  96296. os->lacing_fill=os->lacing_packet;
  96297. if(os->pageno!=-1){
  96298. os->lacing_vals[os->lacing_fill++]=0x400;
  96299. os->lacing_packet++;
  96300. }
  96301. }
  96302. if(continued){
  96303. if(os->lacing_fill<1 ||
  96304. os->lacing_vals[os->lacing_fill-1]==0x400){
  96305. bos=0;
  96306. for(;segptr<segments;segptr++){
  96307. int val=header[27+segptr];
  96308. body+=val;
  96309. bodysize-=val;
  96310. if(val<255){
  96311. segptr++;
  96312. break;
  96313. }
  96314. }
  96315. }
  96316. }
  96317. if(bodysize){
  96318. _os_body_expand(os,bodysize);
  96319. memcpy(os->body_data+os->body_fill,body,bodysize);
  96320. os->body_fill+=bodysize;
  96321. }
  96322. {
  96323. int saved=-1;
  96324. while(segptr<segments){
  96325. int val=header[27+segptr];
  96326. os->lacing_vals[os->lacing_fill]=val;
  96327. os->granule_vals[os->lacing_fill]=-1;
  96328. if(bos){
  96329. os->lacing_vals[os->lacing_fill]|=0x100;
  96330. bos=0;
  96331. }
  96332. if(val<255)saved=os->lacing_fill;
  96333. os->lacing_fill++;
  96334. segptr++;
  96335. if(val<255)os->lacing_packet=os->lacing_fill;
  96336. }
  96337. if(saved!=-1){
  96338. os->granule_vals[saved]=granulepos;
  96339. }
  96340. }
  96341. if(eos){
  96342. os->e_o_s=1;
  96343. if(os->lacing_fill>0)
  96344. os->lacing_vals[os->lacing_fill-1]|=0x200;
  96345. }
  96346. os->pageno=pageno+1;
  96347. return(0);
  96348. }
  96349. int ogg_sync_reset(ogg_sync_state *oy){
  96350. oy->fill=0;
  96351. oy->returned=0;
  96352. oy->unsynced=0;
  96353. oy->headerbytes=0;
  96354. oy->bodybytes=0;
  96355. return(0);
  96356. }
  96357. int ogg_stream_reset(ogg_stream_state *os){
  96358. os->body_fill=0;
  96359. os->body_returned=0;
  96360. os->lacing_fill=0;
  96361. os->lacing_packet=0;
  96362. os->lacing_returned=0;
  96363. os->header_fill=0;
  96364. os->e_o_s=0;
  96365. os->b_o_s=0;
  96366. os->pageno=-1;
  96367. os->packetno=0;
  96368. os->granulepos=0;
  96369. return(0);
  96370. }
  96371. int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno){
  96372. ogg_stream_reset(os);
  96373. os->serialno=serialno;
  96374. return(0);
  96375. }
  96376. static int _packetout(ogg_stream_state *os,ogg_packet *op,int adv){
  96377. int ptr=os->lacing_returned;
  96378. if(os->lacing_packet<=ptr)return(0);
  96379. if(os->lacing_vals[ptr]&0x400){
  96380. os->lacing_returned++;
  96381. os->packetno++;
  96382. return(-1);
  96383. }
  96384. if(!op && !adv)return(1); /* just using peek as an inexpensive way
  96385. to ask if there's a whole packet
  96386. waiting */
  96387. {
  96388. int size=os->lacing_vals[ptr]&0xff;
  96389. int bytes=size;
  96390. int eos=os->lacing_vals[ptr]&0x200; /* last packet of the stream? */
  96391. int bos=os->lacing_vals[ptr]&0x100; /* first packet of the stream? */
  96392. while(size==255){
  96393. int val=os->lacing_vals[++ptr];
  96394. size=val&0xff;
  96395. if(val&0x200)eos=0x200;
  96396. bytes+=size;
  96397. }
  96398. if(op){
  96399. op->e_o_s=eos;
  96400. op->b_o_s=bos;
  96401. op->packet=os->body_data+os->body_returned;
  96402. op->packetno=os->packetno;
  96403. op->granulepos=os->granule_vals[ptr];
  96404. op->bytes=bytes;
  96405. }
  96406. if(adv){
  96407. os->body_returned+=bytes;
  96408. os->lacing_returned=ptr+1;
  96409. os->packetno++;
  96410. }
  96411. }
  96412. return(1);
  96413. }
  96414. int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op){
  96415. return _packetout(os,op,1);
  96416. }
  96417. int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op){
  96418. return _packetout(os,op,0);
  96419. }
  96420. void ogg_packet_clear(ogg_packet *op) {
  96421. _ogg_free(op->packet);
  96422. memset(op, 0, sizeof(*op));
  96423. }
  96424. #ifdef _V_SELFTEST
  96425. #include <stdio.h>
  96426. ogg_stream_state os_en, os_de;
  96427. ogg_sync_state oy;
  96428. void checkpacket(ogg_packet *op,int len, int no, int pos){
  96429. long j;
  96430. static int sequence=0;
  96431. static int lastno=0;
  96432. if(op->bytes!=len){
  96433. fprintf(stderr,"incorrect packet length!\n");
  96434. exit(1);
  96435. }
  96436. if(op->granulepos!=pos){
  96437. fprintf(stderr,"incorrect packet position!\n");
  96438. exit(1);
  96439. }
  96440. if(no==0){
  96441. sequence=0;
  96442. }else{
  96443. sequence++;
  96444. if(no>lastno+1)
  96445. sequence++;
  96446. }
  96447. lastno=no;
  96448. if(op->packetno!=sequence){
  96449. fprintf(stderr,"incorrect packet sequence %ld != %d\n",
  96450. (long)(op->packetno),sequence);
  96451. exit(1);
  96452. }
  96453. for(j=0;j<op->bytes;j++)
  96454. if(op->packet[j]!=((j+no)&0xff)){
  96455. fprintf(stderr,"body data mismatch (1) at pos %ld: %x!=%lx!\n\n",
  96456. j,op->packet[j],(j+no)&0xff);
  96457. exit(1);
  96458. }
  96459. }
  96460. void check_page(unsigned char *data,const int *header,ogg_page *og){
  96461. long j;
  96462. for(j=0;j<og->body_len;j++)
  96463. if(og->body[j]!=data[j]){
  96464. fprintf(stderr,"body data mismatch (2) at pos %ld: %x!=%x!\n\n",
  96465. j,data[j],og->body[j]);
  96466. exit(1);
  96467. }
  96468. for(j=0;j<og->header_len;j++){
  96469. if(og->header[j]!=header[j]){
  96470. fprintf(stderr,"header content mismatch at pos %ld:\n",j);
  96471. for(j=0;j<header[26]+27;j++)
  96472. fprintf(stderr," (%ld)%02x:%02x",j,header[j],og->header[j]);
  96473. fprintf(stderr,"\n");
  96474. exit(1);
  96475. }
  96476. }
  96477. if(og->header_len!=header[26]+27){
  96478. fprintf(stderr,"header length incorrect! (%ld!=%d)\n",
  96479. og->header_len,header[26]+27);
  96480. exit(1);
  96481. }
  96482. }
  96483. void print_header(ogg_page *og){
  96484. int j;
  96485. fprintf(stderr,"\nHEADER:\n");
  96486. fprintf(stderr," capture: %c %c %c %c version: %d flags: %x\n",
  96487. og->header[0],og->header[1],og->header[2],og->header[3],
  96488. (int)og->header[4],(int)og->header[5]);
  96489. fprintf(stderr," granulepos: %d serialno: %d pageno: %ld\n",
  96490. (og->header[9]<<24)|(og->header[8]<<16)|
  96491. (og->header[7]<<8)|og->header[6],
  96492. (og->header[17]<<24)|(og->header[16]<<16)|
  96493. (og->header[15]<<8)|og->header[14],
  96494. ((long)(og->header[21])<<24)|(og->header[20]<<16)|
  96495. (og->header[19]<<8)|og->header[18]);
  96496. fprintf(stderr," checksum: %02x:%02x:%02x:%02x\n segments: %d (",
  96497. (int)og->header[22],(int)og->header[23],
  96498. (int)og->header[24],(int)og->header[25],
  96499. (int)og->header[26]);
  96500. for(j=27;j<og->header_len;j++)
  96501. fprintf(stderr,"%d ",(int)og->header[j]);
  96502. fprintf(stderr,")\n\n");
  96503. }
  96504. void copy_page(ogg_page *og){
  96505. unsigned char *temp=_ogg_malloc(og->header_len);
  96506. memcpy(temp,og->header,og->header_len);
  96507. og->header=temp;
  96508. temp=_ogg_malloc(og->body_len);
  96509. memcpy(temp,og->body,og->body_len);
  96510. og->body=temp;
  96511. }
  96512. void free_page(ogg_page *og){
  96513. _ogg_free (og->header);
  96514. _ogg_free (og->body);
  96515. }
  96516. void error(void){
  96517. fprintf(stderr,"error!\n");
  96518. exit(1);
  96519. }
  96520. const int head1_0[] = {0x4f,0x67,0x67,0x53,0,0x06,
  96521. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96522. 0x01,0x02,0x03,0x04,0,0,0,0,
  96523. 0x15,0xed,0xec,0x91,
  96524. 1,
  96525. 17};
  96526. const int head1_1[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96527. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96528. 0x01,0x02,0x03,0x04,0,0,0,0,
  96529. 0x59,0x10,0x6c,0x2c,
  96530. 1,
  96531. 17};
  96532. const int head2_1[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96533. 0x07,0x18,0x00,0x00,0x00,0x00,0x00,0x00,
  96534. 0x01,0x02,0x03,0x04,1,0,0,0,
  96535. 0x89,0x33,0x85,0xce,
  96536. 13,
  96537. 254,255,0,255,1,255,245,255,255,0,
  96538. 255,255,90};
  96539. const int head1_2[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96540. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96541. 0x01,0x02,0x03,0x04,0,0,0,0,
  96542. 0xff,0x7b,0x23,0x17,
  96543. 1,
  96544. 0};
  96545. const int head2_2[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96546. 0x07,0x28,0x00,0x00,0x00,0x00,0x00,0x00,
  96547. 0x01,0x02,0x03,0x04,1,0,0,0,
  96548. 0x5c,0x3f,0x66,0xcb,
  96549. 17,
  96550. 17,254,255,0,0,255,1,0,255,245,255,255,0,
  96551. 255,255,90,0};
  96552. const int head1_3[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96553. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96554. 0x01,0x02,0x03,0x04,0,0,0,0,
  96555. 0x01,0x27,0x31,0xaa,
  96556. 18,
  96557. 255,255,255,255,255,255,255,255,
  96558. 255,255,255,255,255,255,255,255,255,10};
  96559. const int head2_3[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96560. 0x07,0x08,0x00,0x00,0x00,0x00,0x00,0x00,
  96561. 0x01,0x02,0x03,0x04,1,0,0,0,
  96562. 0x7f,0x4e,0x8a,0xd2,
  96563. 4,
  96564. 255,4,255,0};
  96565. const int head1_4[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96566. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96567. 0x01,0x02,0x03,0x04,0,0,0,0,
  96568. 0xff,0x7b,0x23,0x17,
  96569. 1,
  96570. 0};
  96571. const int head2_4[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96572. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  96573. 0x01,0x02,0x03,0x04,1,0,0,0,
  96574. 0x54,0x05,0x51,0xc8,
  96575. 17,
  96576. 255,255,255,255,255,255,255,255,
  96577. 255,255,255,255,255,255,255,255,255};
  96578. const int head3_4[] = {0x4f,0x67,0x67,0x53,0,0x05,
  96579. 0x07,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,
  96580. 0x01,0x02,0x03,0x04,2,0,0,0,
  96581. 0xc8,0xc3,0xcb,0xed,
  96582. 5,
  96583. 10,255,4,255,0};
  96584. const int head1_5[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96585. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96586. 0x01,0x02,0x03,0x04,0,0,0,0,
  96587. 0xff,0x7b,0x23,0x17,
  96588. 1,
  96589. 0};
  96590. const int head2_5[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96591. 0x07,0xfc,0x03,0x00,0x00,0x00,0x00,0x00,
  96592. 0x01,0x02,0x03,0x04,1,0,0,0,
  96593. 0xed,0x2a,0x2e,0xa7,
  96594. 255,
  96595. 10,10,10,10,10,10,10,10,
  96596. 10,10,10,10,10,10,10,10,
  96597. 10,10,10,10,10,10,10,10,
  96598. 10,10,10,10,10,10,10,10,
  96599. 10,10,10,10,10,10,10,10,
  96600. 10,10,10,10,10,10,10,10,
  96601. 10,10,10,10,10,10,10,10,
  96602. 10,10,10,10,10,10,10,10,
  96603. 10,10,10,10,10,10,10,10,
  96604. 10,10,10,10,10,10,10,10,
  96605. 10,10,10,10,10,10,10,10,
  96606. 10,10,10,10,10,10,10,10,
  96607. 10,10,10,10,10,10,10,10,
  96608. 10,10,10,10,10,10,10,10,
  96609. 10,10,10,10,10,10,10,10,
  96610. 10,10,10,10,10,10,10,10,
  96611. 10,10,10,10,10,10,10,10,
  96612. 10,10,10,10,10,10,10,10,
  96613. 10,10,10,10,10,10,10,10,
  96614. 10,10,10,10,10,10,10,10,
  96615. 10,10,10,10,10,10,10,10,
  96616. 10,10,10,10,10,10,10,10,
  96617. 10,10,10,10,10,10,10,10,
  96618. 10,10,10,10,10,10,10,10,
  96619. 10,10,10,10,10,10,10,10,
  96620. 10,10,10,10,10,10,10,10,
  96621. 10,10,10,10,10,10,10,10,
  96622. 10,10,10,10,10,10,10,10,
  96623. 10,10,10,10,10,10,10,10,
  96624. 10,10,10,10,10,10,10,10,
  96625. 10,10,10,10,10,10,10,10,
  96626. 10,10,10,10,10,10,10};
  96627. const int head3_5[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96628. 0x07,0x00,0x04,0x00,0x00,0x00,0x00,0x00,
  96629. 0x01,0x02,0x03,0x04,2,0,0,0,
  96630. 0x6c,0x3b,0x82,0x3d,
  96631. 1,
  96632. 50};
  96633. const int head1_6[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96634. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96635. 0x01,0x02,0x03,0x04,0,0,0,0,
  96636. 0xff,0x7b,0x23,0x17,
  96637. 1,
  96638. 0};
  96639. const int head2_6[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96640. 0x07,0x04,0x00,0x00,0x00,0x00,0x00,0x00,
  96641. 0x01,0x02,0x03,0x04,1,0,0,0,
  96642. 0x3c,0xd9,0x4d,0x3f,
  96643. 17,
  96644. 100,255,255,255,255,255,255,255,255,
  96645. 255,255,255,255,255,255,255,255};
  96646. const int head3_6[] = {0x4f,0x67,0x67,0x53,0,0x01,
  96647. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  96648. 0x01,0x02,0x03,0x04,2,0,0,0,
  96649. 0x01,0xd2,0xe5,0xe5,
  96650. 17,
  96651. 255,255,255,255,255,255,255,255,
  96652. 255,255,255,255,255,255,255,255,255};
  96653. const int head4_6[] = {0x4f,0x67,0x67,0x53,0,0x05,
  96654. 0x07,0x10,0x00,0x00,0x00,0x00,0x00,0x00,
  96655. 0x01,0x02,0x03,0x04,3,0,0,0,
  96656. 0xef,0xdd,0x88,0xde,
  96657. 7,
  96658. 255,255,75,255,4,255,0};
  96659. const int head1_7[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96660. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96661. 0x01,0x02,0x03,0x04,0,0,0,0,
  96662. 0xff,0x7b,0x23,0x17,
  96663. 1,
  96664. 0};
  96665. const int head2_7[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96666. 0x07,0x04,0x00,0x00,0x00,0x00,0x00,0x00,
  96667. 0x01,0x02,0x03,0x04,1,0,0,0,
  96668. 0x3c,0xd9,0x4d,0x3f,
  96669. 17,
  96670. 100,255,255,255,255,255,255,255,255,
  96671. 255,255,255,255,255,255,255,255};
  96672. const int head3_7[] = {0x4f,0x67,0x67,0x53,0,0x05,
  96673. 0x07,0x08,0x00,0x00,0x00,0x00,0x00,0x00,
  96674. 0x01,0x02,0x03,0x04,2,0,0,0,
  96675. 0xd4,0xe0,0x60,0xe5,
  96676. 1,0};
  96677. void test_pack(const int *pl, const int **headers, int byteskip,
  96678. int pageskip, int packetskip){
  96679. unsigned char *data=_ogg_malloc(1024*1024); /* for scripted test cases only */
  96680. long inptr=0;
  96681. long outptr=0;
  96682. long deptr=0;
  96683. long depacket=0;
  96684. long granule_pos=7,pageno=0;
  96685. int i,j,packets,pageout=pageskip;
  96686. int eosflag=0;
  96687. int bosflag=0;
  96688. int byteskipcount=0;
  96689. ogg_stream_reset(&os_en);
  96690. ogg_stream_reset(&os_de);
  96691. ogg_sync_reset(&oy);
  96692. for(packets=0;packets<packetskip;packets++)
  96693. depacket+=pl[packets];
  96694. for(packets=0;;packets++)if(pl[packets]==-1)break;
  96695. for(i=0;i<packets;i++){
  96696. ogg_packet op;
  96697. int len=pl[i];
  96698. op.packet=data+inptr;
  96699. op.bytes=len;
  96700. op.e_o_s=(pl[i+1]<0?1:0);
  96701. op.granulepos=granule_pos;
  96702. granule_pos+=1024;
  96703. for(j=0;j<len;j++)data[inptr++]=i+j;
  96704. ogg_stream_packetin(&os_en,&op);
  96705. {
  96706. ogg_page og;
  96707. while(ogg_stream_pageout(&os_en,&og)){
  96708. fprintf(stderr,"%ld, ",pageno);
  96709. if(headers[pageno]==NULL){
  96710. fprintf(stderr,"coded too many pages!\n");
  96711. exit(1);
  96712. }
  96713. check_page(data+outptr,headers[pageno],&og);
  96714. outptr+=og.body_len;
  96715. pageno++;
  96716. if(pageskip){
  96717. bosflag=1;
  96718. pageskip--;
  96719. deptr+=og.body_len;
  96720. }
  96721. {
  96722. ogg_page og_de;
  96723. ogg_packet op_de,op_de2;
  96724. char *buf=ogg_sync_buffer(&oy,og.header_len+og.body_len);
  96725. char *next=buf;
  96726. byteskipcount+=og.header_len;
  96727. if(byteskipcount>byteskip){
  96728. memcpy(next,og.header,byteskipcount-byteskip);
  96729. next+=byteskipcount-byteskip;
  96730. byteskipcount=byteskip;
  96731. }
  96732. byteskipcount+=og.body_len;
  96733. if(byteskipcount>byteskip){
  96734. memcpy(next,og.body,byteskipcount-byteskip);
  96735. next+=byteskipcount-byteskip;
  96736. byteskipcount=byteskip;
  96737. }
  96738. ogg_sync_wrote(&oy,next-buf);
  96739. while(1){
  96740. int ret=ogg_sync_pageout(&oy,&og_de);
  96741. if(ret==0)break;
  96742. if(ret<0)continue;
  96743. fprintf(stderr,"(%ld), ",pageout);
  96744. check_page(data+deptr,headers[pageout],&og_de);
  96745. deptr+=og_de.body_len;
  96746. pageout++;
  96747. ogg_stream_pagein(&os_de,&og_de);
  96748. while(ogg_stream_packetpeek(&os_de,&op_de2)>0){
  96749. ogg_stream_packetpeek(&os_de,NULL);
  96750. ogg_stream_packetout(&os_de,&op_de); /* just catching them all */
  96751. if(memcmp(&op_de,&op_de2,sizeof(op_de))){
  96752. fprintf(stderr,"packetout != packetpeek! pos=%ld\n",
  96753. depacket);
  96754. exit(1);
  96755. }
  96756. if(memcmp(data+depacket,op_de.packet,op_de.bytes)){
  96757. fprintf(stderr,"packet data mismatch in decode! pos=%ld\n",
  96758. depacket);
  96759. exit(1);
  96760. }
  96761. if(bosflag==0 && op_de.b_o_s==0){
  96762. fprintf(stderr,"b_o_s flag not set on packet!\n");
  96763. exit(1);
  96764. }
  96765. if(bosflag && op_de.b_o_s){
  96766. fprintf(stderr,"b_o_s flag incorrectly set on packet!\n");
  96767. exit(1);
  96768. }
  96769. bosflag=1;
  96770. depacket+=op_de.bytes;
  96771. if(eosflag){
  96772. fprintf(stderr,"Multiple decoded packets with eos flag!\n");
  96773. exit(1);
  96774. }
  96775. if(op_de.e_o_s)eosflag=1;
  96776. if(op_de.granulepos!=-1){
  96777. fprintf(stderr," granule:%ld ",(long)op_de.granulepos);
  96778. }
  96779. }
  96780. }
  96781. }
  96782. }
  96783. }
  96784. }
  96785. _ogg_free(data);
  96786. if(headers[pageno]!=NULL){
  96787. fprintf(stderr,"did not write last page!\n");
  96788. exit(1);
  96789. }
  96790. if(headers[pageout]!=NULL){
  96791. fprintf(stderr,"did not decode last page!\n");
  96792. exit(1);
  96793. }
  96794. if(inptr!=outptr){
  96795. fprintf(stderr,"encoded page data incomplete!\n");
  96796. exit(1);
  96797. }
  96798. if(inptr!=deptr){
  96799. fprintf(stderr,"decoded page data incomplete!\n");
  96800. exit(1);
  96801. }
  96802. if(inptr!=depacket){
  96803. fprintf(stderr,"decoded packet data incomplete!\n");
  96804. exit(1);
  96805. }
  96806. if(!eosflag){
  96807. fprintf(stderr,"Never got a packet with EOS set!\n");
  96808. exit(1);
  96809. }
  96810. fprintf(stderr,"ok.\n");
  96811. }
  96812. int main(void){
  96813. ogg_stream_init(&os_en,0x04030201);
  96814. ogg_stream_init(&os_de,0x04030201);
  96815. ogg_sync_init(&oy);
  96816. {
  96817. const int packets[]={17, -1};
  96818. const int *headret[]={head1_0,NULL};
  96819. fprintf(stderr,"testing single page encoding... ");
  96820. test_pack(packets,headret,0,0,0);
  96821. }
  96822. {
  96823. const int packets[]={17, 254, 255, 256, 500, 510, 600, -1};
  96824. const int *headret[]={head1_1,head2_1,NULL};
  96825. fprintf(stderr,"testing basic page encoding... ");
  96826. test_pack(packets,headret,0,0,0);
  96827. }
  96828. {
  96829. const int packets[]={0,17, 254, 255, 0, 256, 0, 500, 510, 600, 0, -1};
  96830. const int *headret[]={head1_2,head2_2,NULL};
  96831. fprintf(stderr,"testing basic nil packets... ");
  96832. test_pack(packets,headret,0,0,0);
  96833. }
  96834. {
  96835. const int packets[]={4345,259,255,-1};
  96836. const int *headret[]={head1_3,head2_3,NULL};
  96837. fprintf(stderr,"testing initial-packet lacing > 4k... ");
  96838. test_pack(packets,headret,0,0,0);
  96839. }
  96840. {
  96841. const int packets[]={0,4345,259,255,-1};
  96842. const int *headret[]={head1_4,head2_4,head3_4,NULL};
  96843. fprintf(stderr,"testing single packet page span... ");
  96844. test_pack(packets,headret,0,0,0);
  96845. }
  96846. {
  96847. const int packets[]={0,10,10,10,10,10,10,10,10,
  96848. 10,10,10,10,10,10,10,10,
  96849. 10,10,10,10,10,10,10,10,
  96850. 10,10,10,10,10,10,10,10,
  96851. 10,10,10,10,10,10,10,10,
  96852. 10,10,10,10,10,10,10,10,
  96853. 10,10,10,10,10,10,10,10,
  96854. 10,10,10,10,10,10,10,10,
  96855. 10,10,10,10,10,10,10,10,
  96856. 10,10,10,10,10,10,10,10,
  96857. 10,10,10,10,10,10,10,10,
  96858. 10,10,10,10,10,10,10,10,
  96859. 10,10,10,10,10,10,10,10,
  96860. 10,10,10,10,10,10,10,10,
  96861. 10,10,10,10,10,10,10,10,
  96862. 10,10,10,10,10,10,10,10,
  96863. 10,10,10,10,10,10,10,10,
  96864. 10,10,10,10,10,10,10,10,
  96865. 10,10,10,10,10,10,10,10,
  96866. 10,10,10,10,10,10,10,10,
  96867. 10,10,10,10,10,10,10,10,
  96868. 10,10,10,10,10,10,10,10,
  96869. 10,10,10,10,10,10,10,10,
  96870. 10,10,10,10,10,10,10,10,
  96871. 10,10,10,10,10,10,10,10,
  96872. 10,10,10,10,10,10,10,10,
  96873. 10,10,10,10,10,10,10,10,
  96874. 10,10,10,10,10,10,10,10,
  96875. 10,10,10,10,10,10,10,10,
  96876. 10,10,10,10,10,10,10,10,
  96877. 10,10,10,10,10,10,10,10,
  96878. 10,10,10,10,10,10,10,50,-1};
  96879. const int *headret[]={head1_5,head2_5,head3_5,NULL};
  96880. fprintf(stderr,"testing max packet segments... ");
  96881. test_pack(packets,headret,0,0,0);
  96882. }
  96883. {
  96884. const int packets[]={0,100,9000,259,255,-1};
  96885. const int *headret[]={head1_6,head2_6,head3_6,head4_6,NULL};
  96886. fprintf(stderr,"testing very large packets... ");
  96887. test_pack(packets,headret,0,0,0);
  96888. }
  96889. {
  96890. const int packets[]={0,100,9000,259,255,-1};
  96891. const int *headret[]={head1_6,head2_6,head3_6,head4_6,NULL};
  96892. fprintf(stderr,"testing continuation resync in very large packets... ");
  96893. test_pack(packets,headret,100,2,3);
  96894. }
  96895. {
  96896. const int packets[]={0,100,4080,-1};
  96897. const int *headret[]={head1_7,head2_7,head3_7,NULL};
  96898. fprintf(stderr,"testing zero data page (1 nil packet)... ");
  96899. test_pack(packets,headret,0,0,0);
  96900. }
  96901. {
  96902. unsigned char *data=_ogg_malloc(1024*1024);
  96903. int pl[]={0,100,4079,2956,2057,76,34,912,0,234,1000,1000,1000,300,-1};
  96904. int inptr=0,i,j;
  96905. ogg_page og[5];
  96906. ogg_stream_reset(&os_en);
  96907. for(i=0;pl[i]!=-1;i++){
  96908. ogg_packet op;
  96909. int len=pl[i];
  96910. op.packet=data+inptr;
  96911. op.bytes=len;
  96912. op.e_o_s=(pl[i+1]<0?1:0);
  96913. op.granulepos=(i+1)*1000;
  96914. for(j=0;j<len;j++)data[inptr++]=i+j;
  96915. ogg_stream_packetin(&os_en,&op);
  96916. }
  96917. _ogg_free(data);
  96918. for(i=0;i<5;i++){
  96919. if(ogg_stream_pageout(&os_en,&og[i])==0){
  96920. fprintf(stderr,"Too few pages output building sync tests!\n");
  96921. exit(1);
  96922. }
  96923. copy_page(&og[i]);
  96924. }
  96925. {
  96926. ogg_page temp;
  96927. ogg_packet test;
  96928. fprintf(stderr,"Testing loss of pages... ");
  96929. ogg_sync_reset(&oy);
  96930. ogg_stream_reset(&os_de);
  96931. for(i=0;i<5;i++){
  96932. memcpy(ogg_sync_buffer(&oy,og[i].header_len),og[i].header,
  96933. og[i].header_len);
  96934. ogg_sync_wrote(&oy,og[i].header_len);
  96935. memcpy(ogg_sync_buffer(&oy,og[i].body_len),og[i].body,og[i].body_len);
  96936. ogg_sync_wrote(&oy,og[i].body_len);
  96937. }
  96938. ogg_sync_pageout(&oy,&temp);
  96939. ogg_stream_pagein(&os_de,&temp);
  96940. ogg_sync_pageout(&oy,&temp);
  96941. ogg_stream_pagein(&os_de,&temp);
  96942. ogg_sync_pageout(&oy,&temp);
  96943. ogg_sync_pageout(&oy,&temp);
  96944. ogg_stream_pagein(&os_de,&temp);
  96945. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96946. checkpacket(&test,0,0,0);
  96947. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96948. checkpacket(&test,100,1,-1);
  96949. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96950. checkpacket(&test,4079,2,3000);
  96951. if(ogg_stream_packetout(&os_de,&test)!=-1){
  96952. fprintf(stderr,"Error: loss of page did not return error\n");
  96953. exit(1);
  96954. }
  96955. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96956. checkpacket(&test,76,5,-1);
  96957. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96958. checkpacket(&test,34,6,-1);
  96959. fprintf(stderr,"ok.\n");
  96960. }
  96961. {
  96962. ogg_page temp;
  96963. ogg_packet test;
  96964. fprintf(stderr,"Testing loss of pages (rollback required)... ");
  96965. ogg_sync_reset(&oy);
  96966. ogg_stream_reset(&os_de);
  96967. for(i=0;i<5;i++){
  96968. memcpy(ogg_sync_buffer(&oy,og[i].header_len),og[i].header,
  96969. og[i].header_len);
  96970. ogg_sync_wrote(&oy,og[i].header_len);
  96971. memcpy(ogg_sync_buffer(&oy,og[i].body_len),og[i].body,og[i].body_len);
  96972. ogg_sync_wrote(&oy,og[i].body_len);
  96973. }
  96974. ogg_sync_pageout(&oy,&temp);
  96975. ogg_stream_pagein(&os_de,&temp);
  96976. ogg_sync_pageout(&oy,&temp);
  96977. ogg_stream_pagein(&os_de,&temp);
  96978. ogg_sync_pageout(&oy,&temp);
  96979. ogg_stream_pagein(&os_de,&temp);
  96980. ogg_sync_pageout(&oy,&temp);
  96981. ogg_sync_pageout(&oy,&temp);
  96982. ogg_stream_pagein(&os_de,&temp);
  96983. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96984. checkpacket(&test,0,0,0);
  96985. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96986. checkpacket(&test,100,1,-1);
  96987. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96988. checkpacket(&test,4079,2,3000);
  96989. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96990. checkpacket(&test,2956,3,4000);
  96991. if(ogg_stream_packetout(&os_de,&test)!=-1){
  96992. fprintf(stderr,"Error: loss of page did not return error\n");
  96993. exit(1);
  96994. }
  96995. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96996. checkpacket(&test,300,13,14000);
  96997. fprintf(stderr,"ok.\n");
  96998. }
  96999. {
  97000. ogg_page og_de;
  97001. fprintf(stderr,"Testing sync on partial inputs... ");
  97002. ogg_sync_reset(&oy);
  97003. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  97004. 3);
  97005. ogg_sync_wrote(&oy,3);
  97006. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  97007. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+3,
  97008. 20);
  97009. ogg_sync_wrote(&oy,20);
  97010. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  97011. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+23,
  97012. 5);
  97013. ogg_sync_wrote(&oy,5);
  97014. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  97015. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+28,
  97016. og[1].header_len-28);
  97017. ogg_sync_wrote(&oy,og[1].header_len-28);
  97018. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  97019. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,1000);
  97020. ogg_sync_wrote(&oy,1000);
  97021. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  97022. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body+1000,
  97023. og[1].body_len-1000);
  97024. ogg_sync_wrote(&oy,og[1].body_len-1000);
  97025. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  97026. fprintf(stderr,"ok.\n");
  97027. }
  97028. {
  97029. ogg_page og_de;
  97030. fprintf(stderr,"Testing sync on 1+partial inputs... ");
  97031. ogg_sync_reset(&oy);
  97032. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  97033. og[1].header_len);
  97034. ogg_sync_wrote(&oy,og[1].header_len);
  97035. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  97036. og[1].body_len);
  97037. ogg_sync_wrote(&oy,og[1].body_len);
  97038. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  97039. 20);
  97040. ogg_sync_wrote(&oy,20);
  97041. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  97042. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  97043. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+20,
  97044. og[1].header_len-20);
  97045. ogg_sync_wrote(&oy,og[1].header_len-20);
  97046. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  97047. og[1].body_len);
  97048. ogg_sync_wrote(&oy,og[1].body_len);
  97049. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  97050. fprintf(stderr,"ok.\n");
  97051. }
  97052. {
  97053. ogg_page og_de;
  97054. fprintf(stderr,"Testing search for capture... ");
  97055. ogg_sync_reset(&oy);
  97056. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  97057. og[1].body_len);
  97058. ogg_sync_wrote(&oy,og[1].body_len);
  97059. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  97060. og[1].header_len);
  97061. ogg_sync_wrote(&oy,og[1].header_len);
  97062. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  97063. og[1].body_len);
  97064. ogg_sync_wrote(&oy,og[1].body_len);
  97065. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,
  97066. 20);
  97067. ogg_sync_wrote(&oy,20);
  97068. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  97069. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  97070. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  97071. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header+20,
  97072. og[2].header_len-20);
  97073. ogg_sync_wrote(&oy,og[2].header_len-20);
  97074. memcpy(ogg_sync_buffer(&oy,og[2].body_len),og[2].body,
  97075. og[2].body_len);
  97076. ogg_sync_wrote(&oy,og[2].body_len);
  97077. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  97078. fprintf(stderr,"ok.\n");
  97079. }
  97080. {
  97081. ogg_page og_de;
  97082. fprintf(stderr,"Testing recapture... ");
  97083. ogg_sync_reset(&oy);
  97084. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  97085. og[1].header_len);
  97086. ogg_sync_wrote(&oy,og[1].header_len);
  97087. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  97088. og[1].body_len);
  97089. ogg_sync_wrote(&oy,og[1].body_len);
  97090. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,
  97091. og[2].header_len);
  97092. ogg_sync_wrote(&oy,og[2].header_len);
  97093. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,
  97094. og[2].header_len);
  97095. ogg_sync_wrote(&oy,og[2].header_len);
  97096. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  97097. memcpy(ogg_sync_buffer(&oy,og[2].body_len),og[2].body,
  97098. og[2].body_len-5);
  97099. ogg_sync_wrote(&oy,og[2].body_len-5);
  97100. memcpy(ogg_sync_buffer(&oy,og[3].header_len),og[3].header,
  97101. og[3].header_len);
  97102. ogg_sync_wrote(&oy,og[3].header_len);
  97103. memcpy(ogg_sync_buffer(&oy,og[3].body_len),og[3].body,
  97104. og[3].body_len);
  97105. ogg_sync_wrote(&oy,og[3].body_len);
  97106. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  97107. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  97108. fprintf(stderr,"ok.\n");
  97109. }
  97110. {
  97111. for(i=0;i<5;i++){
  97112. free_page(&og[i]);
  97113. }
  97114. }
  97115. }
  97116. return(0);
  97117. }
  97118. #endif
  97119. #endif
  97120. /*** End of inlined file: framing.c ***/
  97121. /*** Start of inlined file: analysis.c ***/
  97122. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  97123. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  97124. // tasks..
  97125. #if JUCE_MSVC
  97126. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  97127. #endif
  97128. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  97129. #if JUCE_USE_OGGVORBIS
  97130. #include <stdio.h>
  97131. #include <string.h>
  97132. #include <math.h>
  97133. /*** Start of inlined file: codec_internal.h ***/
  97134. #ifndef _V_CODECI_H_
  97135. #define _V_CODECI_H_
  97136. /*** Start of inlined file: envelope.h ***/
  97137. #ifndef _V_ENVELOPE_
  97138. #define _V_ENVELOPE_
  97139. /*** Start of inlined file: mdct.h ***/
  97140. #ifndef _OGG_mdct_H_
  97141. #define _OGG_mdct_H_
  97142. #ifdef MDCT_INTEGERIZED
  97143. #define DATA_TYPE int
  97144. #define REG_TYPE register int
  97145. #define TRIGBITS 14
  97146. #define cPI3_8 6270
  97147. #define cPI2_8 11585
  97148. #define cPI1_8 15137
  97149. #define FLOAT_CONV(x) ((int)((x)*(1<<TRIGBITS)+.5))
  97150. #define MULT_NORM(x) ((x)>>TRIGBITS)
  97151. #define HALVE(x) ((x)>>1)
  97152. #else
  97153. #define DATA_TYPE float
  97154. #define REG_TYPE float
  97155. #define cPI3_8 .38268343236508977175F
  97156. #define cPI2_8 .70710678118654752441F
  97157. #define cPI1_8 .92387953251128675613F
  97158. #define FLOAT_CONV(x) (x)
  97159. #define MULT_NORM(x) (x)
  97160. #define HALVE(x) ((x)*.5f)
  97161. #endif
  97162. typedef struct {
  97163. int n;
  97164. int log2n;
  97165. DATA_TYPE *trig;
  97166. int *bitrev;
  97167. DATA_TYPE scale;
  97168. } mdct_lookup;
  97169. extern void mdct_init(mdct_lookup *lookup,int n);
  97170. extern void mdct_clear(mdct_lookup *l);
  97171. extern void mdct_forward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out);
  97172. extern void mdct_backward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out);
  97173. #endif
  97174. /*** End of inlined file: mdct.h ***/
  97175. #define VE_PRE 16
  97176. #define VE_WIN 4
  97177. #define VE_POST 2
  97178. #define VE_AMP (VE_PRE+VE_POST-1)
  97179. #define VE_BANDS 7
  97180. #define VE_NEARDC 15
  97181. #define VE_MINSTRETCH 2 /* a bit less than short block */
  97182. #define VE_MAXSTRETCH 12 /* one-third full block */
  97183. typedef struct {
  97184. float ampbuf[VE_AMP];
  97185. int ampptr;
  97186. float nearDC[VE_NEARDC];
  97187. float nearDC_acc;
  97188. float nearDC_partialacc;
  97189. int nearptr;
  97190. } envelope_filter_state;
  97191. typedef struct {
  97192. int begin;
  97193. int end;
  97194. float *window;
  97195. float total;
  97196. } envelope_band;
  97197. typedef struct {
  97198. int ch;
  97199. int winlength;
  97200. int searchstep;
  97201. float minenergy;
  97202. mdct_lookup mdct;
  97203. float *mdct_win;
  97204. envelope_band band[VE_BANDS];
  97205. envelope_filter_state *filter;
  97206. int stretch;
  97207. int *mark;
  97208. long storage;
  97209. long current;
  97210. long curmark;
  97211. long cursor;
  97212. } envelope_lookup;
  97213. extern void _ve_envelope_init(envelope_lookup *e,vorbis_info *vi);
  97214. extern void _ve_envelope_clear(envelope_lookup *e);
  97215. extern long _ve_envelope_search(vorbis_dsp_state *v);
  97216. extern void _ve_envelope_shift(envelope_lookup *e,long shift);
  97217. extern int _ve_envelope_mark(vorbis_dsp_state *v);
  97218. #endif
  97219. /*** End of inlined file: envelope.h ***/
  97220. /*** Start of inlined file: codebook.h ***/
  97221. #ifndef _V_CODEBOOK_H_
  97222. #define _V_CODEBOOK_H_
  97223. typedef struct static_codebook{
  97224. long dim; /* codebook dimensions (elements per vector) */
  97225. long entries; /* codebook entries */
  97226. long *lengthlist; /* codeword lengths in bits */
  97227. int maptype; /* 0=none
  97228. 1=implicitly populated values from map column
  97229. 2=listed arbitrary values */
  97230. long q_min; /* packed 32 bit float; quant value 0 maps to minval */
  97231. long q_delta; /* packed 32 bit float; val 1 - val 0 == delta */
  97232. int q_quant; /* bits: 0 < quant <= 16 */
  97233. int q_sequencep; /* bitflag */
  97234. long *quantlist; /* map == 1: (int)(entries^(1/dim)) element column map
  97235. map == 2: list of dim*entries quantized entry vals
  97236. */
  97237. struct encode_aux_nearestmatch *nearest_tree;
  97238. struct encode_aux_threshmatch *thresh_tree;
  97239. struct encode_aux_pigeonhole *pigeon_tree;
  97240. int allocedp;
  97241. } static_codebook;
  97242. typedef struct encode_aux_nearestmatch{
  97243. long *ptr0;
  97244. long *ptr1;
  97245. long *p; /* decision points (each is an entry) */
  97246. long *q; /* decision points (each is an entry) */
  97247. long aux; /* number of tree entries */
  97248. long alloc;
  97249. } encode_aux_nearestmatch;
  97250. typedef struct encode_aux_threshmatch{
  97251. float *quantthresh;
  97252. long *quantmap;
  97253. int quantvals;
  97254. int threshvals;
  97255. } encode_aux_threshmatch;
  97256. typedef struct encode_aux_pigeonhole{
  97257. float min;
  97258. float del;
  97259. int mapentries;
  97260. int quantvals;
  97261. long *pigeonmap;
  97262. long fittotal;
  97263. long *fitlist;
  97264. long *fitmap;
  97265. long *fitlength;
  97266. } encode_aux_pigeonhole;
  97267. typedef struct codebook{
  97268. long dim; /* codebook dimensions (elements per vector) */
  97269. long entries; /* codebook entries */
  97270. long used_entries; /* populated codebook entries */
  97271. const static_codebook *c;
  97272. float *valuelist; /* list of dim*entries actual entry values */
  97273. ogg_uint32_t *codelist; /* list of bitstream codewords for each entry */
  97274. int *dec_index; /* only used if sparseness collapsed */
  97275. char *dec_codelengths;
  97276. ogg_uint32_t *dec_firsttable;
  97277. int dec_firsttablen;
  97278. int dec_maxlength;
  97279. } codebook;
  97280. extern void vorbis_staticbook_clear(static_codebook *b);
  97281. extern void vorbis_staticbook_destroy(static_codebook *b);
  97282. extern int vorbis_book_init_encode(codebook *dest,const static_codebook *source);
  97283. extern int vorbis_book_init_decode(codebook *dest,const static_codebook *source);
  97284. extern void vorbis_book_clear(codebook *b);
  97285. extern float *_book_unquantize(const static_codebook *b,int n,int *map);
  97286. extern float *_book_logdist(const static_codebook *b,float *vals);
  97287. extern float _float32_unpack(long val);
  97288. extern long _float32_pack(float val);
  97289. extern int _best(codebook *book, float *a, int step);
  97290. extern int _ilog(unsigned int v);
  97291. extern long _book_maptype1_quantvals(const static_codebook *b);
  97292. extern int vorbis_book_besterror(codebook *book,float *a,int step,int addmul);
  97293. extern long vorbis_book_codeword(codebook *book,int entry);
  97294. extern long vorbis_book_codelen(codebook *book,int entry);
  97295. extern int vorbis_staticbook_pack(const static_codebook *c,oggpack_buffer *b);
  97296. extern int vorbis_staticbook_unpack(oggpack_buffer *b,static_codebook *c);
  97297. extern int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b);
  97298. extern int vorbis_book_errorv(codebook *book, float *a);
  97299. extern int vorbis_book_encodev(codebook *book, int best,float *a,
  97300. oggpack_buffer *b);
  97301. extern long vorbis_book_decode(codebook *book, oggpack_buffer *b);
  97302. extern long vorbis_book_decodevs_add(codebook *book, float *a,
  97303. oggpack_buffer *b,int n);
  97304. extern long vorbis_book_decodev_set(codebook *book, float *a,
  97305. oggpack_buffer *b,int n);
  97306. extern long vorbis_book_decodev_add(codebook *book, float *a,
  97307. oggpack_buffer *b,int n);
  97308. extern long vorbis_book_decodevv_add(codebook *book, float **a,
  97309. long off,int ch,
  97310. oggpack_buffer *b,int n);
  97311. #endif
  97312. /*** End of inlined file: codebook.h ***/
  97313. #define BLOCKTYPE_IMPULSE 0
  97314. #define BLOCKTYPE_PADDING 1
  97315. #define BLOCKTYPE_TRANSITION 0
  97316. #define BLOCKTYPE_LONG 1
  97317. #define PACKETBLOBS 15
  97318. typedef struct vorbis_block_internal{
  97319. float **pcmdelay; /* this is a pointer into local storage */
  97320. float ampmax;
  97321. int blocktype;
  97322. oggpack_buffer *packetblob[PACKETBLOBS]; /* initialized, must be freed;
  97323. blob [PACKETBLOBS/2] points to
  97324. the oggpack_buffer in the
  97325. main vorbis_block */
  97326. } vorbis_block_internal;
  97327. typedef void vorbis_look_floor;
  97328. typedef void vorbis_look_residue;
  97329. typedef void vorbis_look_transform;
  97330. typedef struct {
  97331. int blockflag;
  97332. int windowtype;
  97333. int transformtype;
  97334. int mapping;
  97335. } vorbis_info_mode;
  97336. typedef void vorbis_info_floor;
  97337. typedef void vorbis_info_residue;
  97338. typedef void vorbis_info_mapping;
  97339. /*** Start of inlined file: psy.h ***/
  97340. #ifndef _V_PSY_H_
  97341. #define _V_PSY_H_
  97342. /*** Start of inlined file: smallft.h ***/
  97343. #ifndef _V_SMFT_H_
  97344. #define _V_SMFT_H_
  97345. typedef struct {
  97346. int n;
  97347. float *trigcache;
  97348. int *splitcache;
  97349. } drft_lookup;
  97350. extern void drft_forward(drft_lookup *l,float *data);
  97351. extern void drft_backward(drft_lookup *l,float *data);
  97352. extern void drft_init(drft_lookup *l,int n);
  97353. extern void drft_clear(drft_lookup *l);
  97354. #endif
  97355. /*** End of inlined file: smallft.h ***/
  97356. /*** Start of inlined file: backends.h ***/
  97357. #ifndef _vorbis_backend_h_
  97358. #define _vorbis_backend_h_
  97359. typedef struct{
  97360. void (*pack) (vorbis_info_floor *,oggpack_buffer *);
  97361. vorbis_info_floor *(*unpack)(vorbis_info *,oggpack_buffer *);
  97362. vorbis_look_floor *(*look) (vorbis_dsp_state *,vorbis_info_floor *);
  97363. void (*free_info) (vorbis_info_floor *);
  97364. void (*free_look) (vorbis_look_floor *);
  97365. void *(*inverse1) (struct vorbis_block *,vorbis_look_floor *);
  97366. int (*inverse2) (struct vorbis_block *,vorbis_look_floor *,
  97367. void *buffer,float *);
  97368. } vorbis_func_floor;
  97369. typedef struct{
  97370. int order;
  97371. long rate;
  97372. long barkmap;
  97373. int ampbits;
  97374. int ampdB;
  97375. int numbooks; /* <= 16 */
  97376. int books[16];
  97377. float lessthan; /* encode-only config setting hacks for libvorbis */
  97378. float greaterthan; /* encode-only config setting hacks for libvorbis */
  97379. } vorbis_info_floor0;
  97380. #define VIF_POSIT 63
  97381. #define VIF_CLASS 16
  97382. #define VIF_PARTS 31
  97383. typedef struct{
  97384. int partitions; /* 0 to 31 */
  97385. int partitionclass[VIF_PARTS]; /* 0 to 15 */
  97386. int class_dim[VIF_CLASS]; /* 1 to 8 */
  97387. int class_subs[VIF_CLASS]; /* 0,1,2,3 (bits: 1<<n poss) */
  97388. int class_book[VIF_CLASS]; /* subs ^ dim entries */
  97389. int class_subbook[VIF_CLASS][8]; /* [VIF_CLASS][subs] */
  97390. int mult; /* 1 2 3 or 4 */
  97391. int postlist[VIF_POSIT+2]; /* first two implicit */
  97392. float maxover;
  97393. float maxunder;
  97394. float maxerr;
  97395. float twofitweight;
  97396. float twofitatten;
  97397. int n;
  97398. } vorbis_info_floor1;
  97399. typedef struct{
  97400. void (*pack) (vorbis_info_residue *,oggpack_buffer *);
  97401. vorbis_info_residue *(*unpack)(vorbis_info *,oggpack_buffer *);
  97402. vorbis_look_residue *(*look) (vorbis_dsp_state *,
  97403. vorbis_info_residue *);
  97404. void (*free_info) (vorbis_info_residue *);
  97405. void (*free_look) (vorbis_look_residue *);
  97406. long **(*classx) (struct vorbis_block *,vorbis_look_residue *,
  97407. float **,int *,int);
  97408. int (*forward) (oggpack_buffer *,struct vorbis_block *,
  97409. vorbis_look_residue *,
  97410. float **,float **,int *,int,long **);
  97411. int (*inverse) (struct vorbis_block *,vorbis_look_residue *,
  97412. float **,int *,int);
  97413. } vorbis_func_residue;
  97414. typedef struct vorbis_info_residue0{
  97415. long begin;
  97416. long end;
  97417. int grouping; /* group n vectors per partition */
  97418. int partitions; /* possible codebooks for a partition */
  97419. int groupbook; /* huffbook for partitioning */
  97420. int secondstages[64]; /* expanded out to pointers in lookup */
  97421. int booklist[256]; /* list of second stage books */
  97422. float classmetric1[64];
  97423. float classmetric2[64];
  97424. } vorbis_info_residue0;
  97425. typedef struct{
  97426. void (*pack) (vorbis_info *,vorbis_info_mapping *,
  97427. oggpack_buffer *);
  97428. vorbis_info_mapping *(*unpack)(vorbis_info *,oggpack_buffer *);
  97429. void (*free_info) (vorbis_info_mapping *);
  97430. int (*forward) (struct vorbis_block *vb);
  97431. int (*inverse) (struct vorbis_block *vb,vorbis_info_mapping *);
  97432. } vorbis_func_mapping;
  97433. typedef struct vorbis_info_mapping0{
  97434. int submaps; /* <= 16 */
  97435. int chmuxlist[256]; /* up to 256 channels in a Vorbis stream */
  97436. int floorsubmap[16]; /* [mux] submap to floors */
  97437. int residuesubmap[16]; /* [mux] submap to residue */
  97438. int coupling_steps;
  97439. int coupling_mag[256];
  97440. int coupling_ang[256];
  97441. } vorbis_info_mapping0;
  97442. #endif
  97443. /*** End of inlined file: backends.h ***/
  97444. #ifndef EHMER_MAX
  97445. #define EHMER_MAX 56
  97446. #endif
  97447. #define P_BANDS 17 /* 62Hz to 16kHz */
  97448. #define P_LEVELS 8 /* 30dB to 100dB */
  97449. #define P_LEVEL_0 30. /* 30 dB */
  97450. #define P_NOISECURVES 3
  97451. #define NOISE_COMPAND_LEVELS 40
  97452. typedef struct vorbis_info_psy{
  97453. int blockflag;
  97454. float ath_adjatt;
  97455. float ath_maxatt;
  97456. float tone_masteratt[P_NOISECURVES];
  97457. float tone_centerboost;
  97458. float tone_decay;
  97459. float tone_abs_limit;
  97460. float toneatt[P_BANDS];
  97461. int noisemaskp;
  97462. float noisemaxsupp;
  97463. float noisewindowlo;
  97464. float noisewindowhi;
  97465. int noisewindowlomin;
  97466. int noisewindowhimin;
  97467. int noisewindowfixed;
  97468. float noiseoff[P_NOISECURVES][P_BANDS];
  97469. float noisecompand[NOISE_COMPAND_LEVELS];
  97470. float max_curve_dB;
  97471. int normal_channel_p;
  97472. int normal_point_p;
  97473. int normal_start;
  97474. int normal_partition;
  97475. double normal_thresh;
  97476. } vorbis_info_psy;
  97477. typedef struct{
  97478. int eighth_octave_lines;
  97479. float preecho_thresh[VE_BANDS];
  97480. float postecho_thresh[VE_BANDS];
  97481. float stretch_penalty;
  97482. float preecho_minenergy;
  97483. float ampmax_att_per_sec;
  97484. int coupling_pkHz[PACKETBLOBS];
  97485. int coupling_pointlimit[2][PACKETBLOBS];
  97486. int coupling_prepointamp[PACKETBLOBS];
  97487. int coupling_postpointamp[PACKETBLOBS];
  97488. int sliding_lowpass[2][PACKETBLOBS];
  97489. } vorbis_info_psy_global;
  97490. typedef struct {
  97491. float ampmax;
  97492. int channels;
  97493. vorbis_info_psy_global *gi;
  97494. int coupling_pointlimit[2][P_NOISECURVES];
  97495. } vorbis_look_psy_global;
  97496. typedef struct {
  97497. int n;
  97498. struct vorbis_info_psy *vi;
  97499. float ***tonecurves;
  97500. float **noiseoffset;
  97501. float *ath;
  97502. long *octave; /* in n.ocshift format */
  97503. long *bark;
  97504. long firstoc;
  97505. long shiftoc;
  97506. int eighth_octave_lines; /* power of two, please */
  97507. int total_octave_lines;
  97508. long rate; /* cache it */
  97509. float m_val; /* Masking compensation value */
  97510. } vorbis_look_psy;
  97511. extern void _vp_psy_init(vorbis_look_psy *p,vorbis_info_psy *vi,
  97512. vorbis_info_psy_global *gi,int n,long rate);
  97513. extern void _vp_psy_clear(vorbis_look_psy *p);
  97514. extern void *_vi_psy_dup(void *source);
  97515. extern void _vi_psy_free(vorbis_info_psy *i);
  97516. extern vorbis_info_psy *_vi_psy_copy(vorbis_info_psy *i);
  97517. extern void _vp_remove_floor(vorbis_look_psy *p,
  97518. float *mdct,
  97519. int *icodedflr,
  97520. float *residue,
  97521. int sliding_lowpass);
  97522. extern void _vp_noisemask(vorbis_look_psy *p,
  97523. float *logmdct,
  97524. float *logmask);
  97525. extern void _vp_tonemask(vorbis_look_psy *p,
  97526. float *logfft,
  97527. float *logmask,
  97528. float global_specmax,
  97529. float local_specmax);
  97530. extern void _vp_offset_and_mix(vorbis_look_psy *p,
  97531. float *noise,
  97532. float *tone,
  97533. int offset_select,
  97534. float *logmask,
  97535. float *mdct,
  97536. float *logmdct);
  97537. extern float _vp_ampmax_decay(float amp,vorbis_dsp_state *vd);
  97538. extern float **_vp_quantize_couple_memo(vorbis_block *vb,
  97539. vorbis_info_psy_global *g,
  97540. vorbis_look_psy *p,
  97541. vorbis_info_mapping0 *vi,
  97542. float **mdct);
  97543. extern void _vp_couple(int blobno,
  97544. vorbis_info_psy_global *g,
  97545. vorbis_look_psy *p,
  97546. vorbis_info_mapping0 *vi,
  97547. float **res,
  97548. float **mag_memo,
  97549. int **mag_sort,
  97550. int **ifloor,
  97551. int *nonzero,
  97552. int sliding_lowpass);
  97553. extern void _vp_noise_normalize(vorbis_look_psy *p,
  97554. float *in,float *out,int *sortedindex);
  97555. extern void _vp_noise_normalize_sort(vorbis_look_psy *p,
  97556. float *magnitudes,int *sortedindex);
  97557. extern int **_vp_quantize_couple_sort(vorbis_block *vb,
  97558. vorbis_look_psy *p,
  97559. vorbis_info_mapping0 *vi,
  97560. float **mags);
  97561. extern void hf_reduction(vorbis_info_psy_global *g,
  97562. vorbis_look_psy *p,
  97563. vorbis_info_mapping0 *vi,
  97564. float **mdct);
  97565. #endif
  97566. /*** End of inlined file: psy.h ***/
  97567. /*** Start of inlined file: bitrate.h ***/
  97568. #ifndef _V_BITRATE_H_
  97569. #define _V_BITRATE_H_
  97570. /*** Start of inlined file: os.h ***/
  97571. #ifndef _OS_H
  97572. #define _OS_H
  97573. #ifdef HAVE_CONFIG_H
  97574. #include "config.h"
  97575. #endif
  97576. #include <math.h>
  97577. /*** Start of inlined file: misc.h ***/
  97578. #ifndef _V_RANDOM_H_
  97579. #define _V_RANDOM_H_
  97580. extern int analysis_noisy;
  97581. extern void *_vorbis_block_alloc(vorbis_block *vb,long bytes);
  97582. extern void _vorbis_block_ripcord(vorbis_block *vb);
  97583. extern void _analysis_output(char *base,int i,float *v,int n,int bark,int dB,
  97584. ogg_int64_t off);
  97585. #ifdef DEBUG_MALLOC
  97586. #define _VDBG_GRAPHFILE "malloc.m"
  97587. extern void *_VDBG_malloc(void *ptr,long bytes,char *file,long line);
  97588. extern void _VDBG_free(void *ptr,char *file,long line);
  97589. #ifndef MISC_C
  97590. #undef _ogg_malloc
  97591. #undef _ogg_calloc
  97592. #undef _ogg_realloc
  97593. #undef _ogg_free
  97594. #define _ogg_malloc(x) _VDBG_malloc(NULL,(x),__FILE__,__LINE__)
  97595. #define _ogg_calloc(x,y) _VDBG_malloc(NULL,(x)*(y),__FILE__,__LINE__)
  97596. #define _ogg_realloc(x,y) _VDBG_malloc((x),(y),__FILE__,__LINE__)
  97597. #define _ogg_free(x) _VDBG_free((x),__FILE__,__LINE__)
  97598. #endif
  97599. #endif
  97600. #endif
  97601. /*** End of inlined file: misc.h ***/
  97602. #ifndef _V_IFDEFJAIL_H_
  97603. # define _V_IFDEFJAIL_H_
  97604. # ifdef __GNUC__
  97605. # define STIN static __inline__
  97606. # elif _WIN32
  97607. # define STIN static __inline
  97608. # else
  97609. # define STIN static
  97610. # endif
  97611. #ifdef DJGPP
  97612. # define rint(x) (floor((x)+0.5f))
  97613. #endif
  97614. #ifndef M_PI
  97615. # define M_PI (3.1415926536f)
  97616. #endif
  97617. #if defined(_WIN32) && !defined(__SYMBIAN32__)
  97618. # include <malloc.h>
  97619. # define rint(x) (floor((x)+0.5f))
  97620. # define NO_FLOAT_MATH_LIB
  97621. # define FAST_HYPOT(a, b) sqrt((a)*(a) + (b)*(b))
  97622. #endif
  97623. #if defined(__SYMBIAN32__) && defined(__WINS__)
  97624. void *_alloca(size_t size);
  97625. # define alloca _alloca
  97626. #endif
  97627. #ifndef FAST_HYPOT
  97628. # define FAST_HYPOT hypot
  97629. #endif
  97630. #endif
  97631. #ifdef HAVE_ALLOCA_H
  97632. # include <alloca.h>
  97633. #endif
  97634. #ifdef USE_MEMORY_H
  97635. # include <memory.h>
  97636. #endif
  97637. #ifndef min
  97638. # define min(x,y) ((x)>(y)?(y):(x))
  97639. #endif
  97640. #ifndef max
  97641. # define max(x,y) ((x)<(y)?(y):(x))
  97642. #endif
  97643. #if defined(__i386__) && defined(__GNUC__) && !defined(__BEOS__)
  97644. # define VORBIS_FPU_CONTROL
  97645. typedef ogg_int16_t vorbis_fpu_control;
  97646. static inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
  97647. ogg_int16_t ret;
  97648. ogg_int16_t temp;
  97649. __asm__ __volatile__("fnstcw %0\n\t"
  97650. "movw %0,%%dx\n\t"
  97651. "orw $62463,%%dx\n\t"
  97652. "movw %%dx,%1\n\t"
  97653. "fldcw %1\n\t":"=m"(ret):"m"(temp): "dx");
  97654. *fpu=ret;
  97655. }
  97656. static inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
  97657. __asm__ __volatile__("fldcw %0":: "m"(fpu));
  97658. }
  97659. static inline int vorbis_ftoi(double f){ /* yes, double! Otherwise,
  97660. we get extra fst/fld to
  97661. truncate precision */
  97662. int i;
  97663. __asm__("fistl %0": "=m"(i) : "t"(f));
  97664. return(i);
  97665. }
  97666. #endif
  97667. #if defined(_WIN32) && defined(_X86_) && !defined(__GNUC__) && !defined(__BORLANDC__)
  97668. # define VORBIS_FPU_CONTROL
  97669. typedef ogg_int16_t vorbis_fpu_control;
  97670. static __inline int vorbis_ftoi(double f){
  97671. int i;
  97672. __asm{
  97673. fld f
  97674. fistp i
  97675. }
  97676. return i;
  97677. }
  97678. static __inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
  97679. }
  97680. static __inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
  97681. }
  97682. #endif
  97683. #ifndef VORBIS_FPU_CONTROL
  97684. typedef int vorbis_fpu_control;
  97685. static int vorbis_ftoi(double f){
  97686. return (int)(f+.5);
  97687. }
  97688. # define vorbis_fpu_setround(vorbis_fpu_control) {}
  97689. # define vorbis_fpu_restore(vorbis_fpu_control) {}
  97690. #endif
  97691. #endif /* _OS_H */
  97692. /*** End of inlined file: os.h ***/
  97693. typedef struct bitrate_manager_state {
  97694. int managed;
  97695. long avg_reservoir;
  97696. long minmax_reservoir;
  97697. long avg_bitsper;
  97698. long min_bitsper;
  97699. long max_bitsper;
  97700. long short_per_long;
  97701. double avgfloat;
  97702. vorbis_block *vb;
  97703. int choice;
  97704. } bitrate_manager_state;
  97705. typedef struct bitrate_manager_info{
  97706. long avg_rate;
  97707. long min_rate;
  97708. long max_rate;
  97709. long reservoir_bits;
  97710. double reservoir_bias;
  97711. double slew_damp;
  97712. } bitrate_manager_info;
  97713. extern void vorbis_bitrate_init(vorbis_info *vi,bitrate_manager_state *bs);
  97714. extern void vorbis_bitrate_clear(bitrate_manager_state *bs);
  97715. extern int vorbis_bitrate_managed(vorbis_block *vb);
  97716. extern int vorbis_bitrate_addblock(vorbis_block *vb);
  97717. extern int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd, ogg_packet *op);
  97718. #endif
  97719. /*** End of inlined file: bitrate.h ***/
  97720. static int ilog(unsigned int v){
  97721. int ret=0;
  97722. while(v){
  97723. ret++;
  97724. v>>=1;
  97725. }
  97726. return(ret);
  97727. }
  97728. static int ilog2(unsigned int v){
  97729. int ret=0;
  97730. if(v)--v;
  97731. while(v){
  97732. ret++;
  97733. v>>=1;
  97734. }
  97735. return(ret);
  97736. }
  97737. typedef struct private_state {
  97738. envelope_lookup *ve; /* envelope lookup */
  97739. int window[2];
  97740. vorbis_look_transform **transform[2]; /* block, type */
  97741. drft_lookup fft_look[2];
  97742. int modebits;
  97743. vorbis_look_floor **flr;
  97744. vorbis_look_residue **residue;
  97745. vorbis_look_psy *psy;
  97746. vorbis_look_psy_global *psy_g_look;
  97747. unsigned char *header;
  97748. unsigned char *header1;
  97749. unsigned char *header2;
  97750. bitrate_manager_state bms;
  97751. ogg_int64_t sample_count;
  97752. } private_state;
  97753. /*** Start of inlined file: highlevel.h ***/
  97754. typedef struct highlevel_byblocktype {
  97755. double tone_mask_setting;
  97756. double tone_peaklimit_setting;
  97757. double noise_bias_setting;
  97758. double noise_compand_setting;
  97759. } highlevel_byblocktype;
  97760. typedef struct highlevel_encode_setup {
  97761. void *setup;
  97762. int set_in_stone;
  97763. double base_setting;
  97764. double long_setting;
  97765. double short_setting;
  97766. double impulse_noisetune;
  97767. int managed;
  97768. long bitrate_min;
  97769. long bitrate_av;
  97770. double bitrate_av_damp;
  97771. long bitrate_max;
  97772. long bitrate_reservoir;
  97773. double bitrate_reservoir_bias;
  97774. int impulse_block_p;
  97775. int noise_normalize_p;
  97776. double stereo_point_setting;
  97777. double lowpass_kHz;
  97778. double ath_floating_dB;
  97779. double ath_absolute_dB;
  97780. double amplitude_track_dBpersec;
  97781. double trigger_setting;
  97782. highlevel_byblocktype block[4]; /* padding, impulse, transition, long */
  97783. } highlevel_encode_setup;
  97784. /*** End of inlined file: highlevel.h ***/
  97785. typedef struct codec_setup_info {
  97786. long blocksizes[2];
  97787. int modes;
  97788. int maps;
  97789. int floors;
  97790. int residues;
  97791. int books;
  97792. int psys; /* encode only */
  97793. vorbis_info_mode *mode_param[64];
  97794. int map_type[64];
  97795. vorbis_info_mapping *map_param[64];
  97796. int floor_type[64];
  97797. vorbis_info_floor *floor_param[64];
  97798. int residue_type[64];
  97799. vorbis_info_residue *residue_param[64];
  97800. static_codebook *book_param[256];
  97801. codebook *fullbooks;
  97802. vorbis_info_psy *psy_param[4]; /* encode only */
  97803. vorbis_info_psy_global psy_g_param;
  97804. bitrate_manager_info bi;
  97805. highlevel_encode_setup hi; /* used only by vorbisenc.c. It's a
  97806. highly redundant structure, but
  97807. improves clarity of program flow. */
  97808. int halfrate_flag; /* painless downsample for decode */
  97809. } codec_setup_info;
  97810. extern vorbis_look_psy_global *_vp_global_look(vorbis_info *vi);
  97811. extern void _vp_global_free(vorbis_look_psy_global *look);
  97812. #endif
  97813. /*** End of inlined file: codec_internal.h ***/
  97814. /*** Start of inlined file: registry.h ***/
  97815. #ifndef _V_REG_H_
  97816. #define _V_REG_H_
  97817. #define VI_TRANSFORMB 1
  97818. #define VI_WINDOWB 1
  97819. #define VI_TIMEB 1
  97820. #define VI_FLOORB 2
  97821. #define VI_RESB 3
  97822. #define VI_MAPB 1
  97823. extern vorbis_func_floor *_floor_P[];
  97824. extern vorbis_func_residue *_residue_P[];
  97825. extern vorbis_func_mapping *_mapping_P[];
  97826. #endif
  97827. /*** End of inlined file: registry.h ***/
  97828. /*** Start of inlined file: scales.h ***/
  97829. #ifndef _V_SCALES_H_
  97830. #define _V_SCALES_H_
  97831. #include <math.h>
  97832. #define VORBIS_IEEE_FLOAT32 1
  97833. #ifdef VORBIS_IEEE_FLOAT32
  97834. static float unitnorm(float x){
  97835. union {
  97836. ogg_uint32_t i;
  97837. float f;
  97838. } ix;
  97839. ix.f = x;
  97840. ix.i = (ix.i & 0x80000000U) | (0x3f800000U);
  97841. return ix.f;
  97842. }
  97843. static float todB(const float *x){
  97844. union {
  97845. ogg_uint32_t i;
  97846. float f;
  97847. } ix;
  97848. ix.f = *x;
  97849. ix.i = ix.i&0x7fffffff;
  97850. return (float)(ix.i * 7.17711438e-7f -764.6161886f);
  97851. }
  97852. #define todB_nn(x) todB(x)
  97853. #else
  97854. static float unitnorm(float x){
  97855. if(x<0)return(-1.f);
  97856. return(1.f);
  97857. }
  97858. #define todB(x) (*(x)==0?-400.f:log(*(x)**(x))*4.34294480f)
  97859. #define todB_nn(x) (*(x)==0.f?-400.f:log(*(x))*8.6858896f)
  97860. #endif
  97861. #define fromdB(x) (exp((x)*.11512925f))
  97862. #define toBARK(n) (13.1f*atan(.00074f*(n))+2.24f*atan((n)*(n)*1.85e-8f)+1e-4f*(n))
  97863. #define fromBARK(z) (102.f*(z)-2.f*pow(z,2.f)+.4f*pow(z,3.f)+pow(1.46f,z)-1.f)
  97864. #define toMEL(n) (log(1.f+(n)*.001f)*1442.695f)
  97865. #define fromMEL(m) (1000.f*exp((m)/1442.695f)-1000.f)
  97866. #define toOC(n) (log(n)*1.442695f-5.965784f)
  97867. #define fromOC(o) (exp(((o)+5.965784f)*.693147f))
  97868. #endif
  97869. /*** End of inlined file: scales.h ***/
  97870. int analysis_noisy=1;
  97871. int vorbis_analysis(vorbis_block *vb, ogg_packet *op){
  97872. int ret,i;
  97873. vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
  97874. vb->glue_bits=0;
  97875. vb->time_bits=0;
  97876. vb->floor_bits=0;
  97877. vb->res_bits=0;
  97878. for(i=0;i<PACKETBLOBS;i++)
  97879. oggpack_reset(vbi->packetblob[i]);
  97880. if((ret=_mapping_P[0]->forward(vb)))
  97881. return(ret);
  97882. if(op){
  97883. if(vorbis_bitrate_managed(vb))
  97884. return(OV_EINVAL);
  97885. op->packet=oggpack_get_buffer(&vb->opb);
  97886. op->bytes=oggpack_bytes(&vb->opb);
  97887. op->b_o_s=0;
  97888. op->e_o_s=vb->eofflag;
  97889. op->granulepos=vb->granulepos;
  97890. op->packetno=vb->sequence; /* for sake of completeness */
  97891. }
  97892. return(0);
  97893. }
  97894. void _analysis_output_always(const char *base,int i,float *v,int n,int bark,int dB,ogg_int64_t off){
  97895. int j;
  97896. FILE *of;
  97897. char buffer[80];
  97898. sprintf(buffer,"%s_%d.m",base,i);
  97899. of=fopen(buffer,"w");
  97900. if(!of)perror("failed to open data dump file");
  97901. for(j=0;j<n;j++){
  97902. if(bark){
  97903. float b=toBARK((4000.f*j/n)+.25);
  97904. fprintf(of,"%f ",b);
  97905. }else
  97906. if(off!=0)
  97907. fprintf(of,"%f ",(double)(j+off)/8000.);
  97908. else
  97909. fprintf(of,"%f ",(double)j);
  97910. if(dB){
  97911. float val;
  97912. if(v[j]==0.)
  97913. val=-140.;
  97914. else
  97915. val=todB(v+j);
  97916. fprintf(of,"%f\n",val);
  97917. }else{
  97918. fprintf(of,"%f\n",v[j]);
  97919. }
  97920. }
  97921. fclose(of);
  97922. }
  97923. void _analysis_output(char *base,int i,float *v,int n,int bark,int dB,
  97924. ogg_int64_t off){
  97925. if(analysis_noisy)_analysis_output_always(base,i,v,n,bark,dB,off);
  97926. }
  97927. #endif
  97928. /*** End of inlined file: analysis.c ***/
  97929. /*** Start of inlined file: bitrate.c ***/
  97930. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  97931. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  97932. // tasks..
  97933. #if JUCE_MSVC
  97934. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  97935. #endif
  97936. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  97937. #if JUCE_USE_OGGVORBIS
  97938. #include <stdlib.h>
  97939. #include <string.h>
  97940. #include <math.h>
  97941. void vorbis_bitrate_init(vorbis_info *vi,bitrate_manager_state *bm){
  97942. codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
  97943. bitrate_manager_info *bi=&ci->bi;
  97944. memset(bm,0,sizeof(*bm));
  97945. if(bi && (bi->reservoir_bits>0)){
  97946. long ratesamples=vi->rate;
  97947. int halfsamples=ci->blocksizes[0]>>1;
  97948. bm->short_per_long=ci->blocksizes[1]/ci->blocksizes[0];
  97949. bm->managed=1;
  97950. bm->avg_bitsper= rint(1.*bi->avg_rate*halfsamples/ratesamples);
  97951. bm->min_bitsper= rint(1.*bi->min_rate*halfsamples/ratesamples);
  97952. bm->max_bitsper= rint(1.*bi->max_rate*halfsamples/ratesamples);
  97953. bm->avgfloat=PACKETBLOBS/2;
  97954. {
  97955. long desired_fill=bi->reservoir_bits*bi->reservoir_bias;
  97956. bm->minmax_reservoir=desired_fill;
  97957. bm->avg_reservoir=desired_fill;
  97958. }
  97959. }
  97960. }
  97961. void vorbis_bitrate_clear(bitrate_manager_state *bm){
  97962. memset(bm,0,sizeof(*bm));
  97963. return;
  97964. }
  97965. int vorbis_bitrate_managed(vorbis_block *vb){
  97966. vorbis_dsp_state *vd=vb->vd;
  97967. private_state *b=(private_state*)vd->backend_state;
  97968. bitrate_manager_state *bm=&b->bms;
  97969. if(bm && bm->managed)return(1);
  97970. return(0);
  97971. }
  97972. int vorbis_bitrate_addblock(vorbis_block *vb){
  97973. vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
  97974. vorbis_dsp_state *vd=vb->vd;
  97975. private_state *b=(private_state*)vd->backend_state;
  97976. bitrate_manager_state *bm=&b->bms;
  97977. vorbis_info *vi=vd->vi;
  97978. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  97979. bitrate_manager_info *bi=&ci->bi;
  97980. int choice=rint(bm->avgfloat);
  97981. long this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97982. long min_target_bits=(vb->W?bm->min_bitsper*bm->short_per_long:bm->min_bitsper);
  97983. long max_target_bits=(vb->W?bm->max_bitsper*bm->short_per_long:bm->max_bitsper);
  97984. int samples=ci->blocksizes[vb->W]>>1;
  97985. long desired_fill=bi->reservoir_bits*bi->reservoir_bias;
  97986. if(!bm->managed){
  97987. if(bm->vb)return(-1); /* one has been submitted without
  97988. being claimed */
  97989. bm->vb=vb;
  97990. return(0);
  97991. }
  97992. bm->vb=vb;
  97993. if(bm->avg_bitsper>0){
  97994. double slew=0.;
  97995. long avg_target_bits=(vb->W?bm->avg_bitsper*bm->short_per_long:bm->avg_bitsper);
  97996. double slewlimit= 15./bi->slew_damp;
  97997. if(bm->avg_reservoir+(this_bits-avg_target_bits)>desired_fill){
  97998. while(choice>0 && this_bits>avg_target_bits &&
  97999. bm->avg_reservoir+(this_bits-avg_target_bits)>desired_fill){
  98000. choice--;
  98001. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  98002. }
  98003. }else if(bm->avg_reservoir+(this_bits-avg_target_bits)<desired_fill){
  98004. while(choice+1<PACKETBLOBS && this_bits<avg_target_bits &&
  98005. bm->avg_reservoir+(this_bits-avg_target_bits)<desired_fill){
  98006. choice++;
  98007. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  98008. }
  98009. }
  98010. slew=rint(choice-bm->avgfloat)/samples*vi->rate;
  98011. if(slew<-slewlimit)slew=-slewlimit;
  98012. if(slew>slewlimit)slew=slewlimit;
  98013. choice=rint(bm->avgfloat+= slew/vi->rate*samples);
  98014. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  98015. }
  98016. if(bm->min_bitsper>0){
  98017. if(this_bits<min_target_bits){
  98018. while(bm->minmax_reservoir-(min_target_bits-this_bits)<0){
  98019. choice++;
  98020. if(choice>=PACKETBLOBS)break;
  98021. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  98022. }
  98023. }
  98024. }
  98025. if(bm->max_bitsper>0){
  98026. if(this_bits>max_target_bits){
  98027. while(bm->minmax_reservoir+(this_bits-max_target_bits)>bi->reservoir_bits){
  98028. choice--;
  98029. if(choice<0)break;
  98030. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  98031. }
  98032. }
  98033. }
  98034. if(choice<0){
  98035. long maxsize=(max_target_bits+(bi->reservoir_bits-bm->minmax_reservoir))/8;
  98036. bm->choice=choice=0;
  98037. if(oggpack_bytes(vbi->packetblob[choice])>maxsize){
  98038. oggpack_writetrunc(vbi->packetblob[choice],maxsize*8);
  98039. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  98040. }
  98041. }else{
  98042. long minsize=(min_target_bits-bm->minmax_reservoir+7)/8;
  98043. if(choice>=PACKETBLOBS)
  98044. choice=PACKETBLOBS-1;
  98045. bm->choice=choice;
  98046. minsize-=oggpack_bytes(vbi->packetblob[choice]);
  98047. while(minsize-->0)oggpack_write(vbi->packetblob[choice],0,8);
  98048. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  98049. }
  98050. if(bm->min_bitsper>0 || bm->max_bitsper>0){
  98051. if(max_target_bits>0 && this_bits>max_target_bits){
  98052. bm->minmax_reservoir+=(this_bits-max_target_bits);
  98053. }else if(min_target_bits>0 && this_bits<min_target_bits){
  98054. bm->minmax_reservoir+=(this_bits-min_target_bits);
  98055. }else{
  98056. if(bm->minmax_reservoir>desired_fill){
  98057. if(max_target_bits>0){ /* logical bulletproofing against initialization state */
  98058. bm->minmax_reservoir+=(this_bits-max_target_bits);
  98059. if(bm->minmax_reservoir<desired_fill)bm->minmax_reservoir=desired_fill;
  98060. }else{
  98061. bm->minmax_reservoir=desired_fill;
  98062. }
  98063. }else{
  98064. if(min_target_bits>0){ /* logical bulletproofing against initialization state */
  98065. bm->minmax_reservoir+=(this_bits-min_target_bits);
  98066. if(bm->minmax_reservoir>desired_fill)bm->minmax_reservoir=desired_fill;
  98067. }else{
  98068. bm->minmax_reservoir=desired_fill;
  98069. }
  98070. }
  98071. }
  98072. }
  98073. if(bm->avg_bitsper>0){
  98074. long avg_target_bits=(vb->W?bm->avg_bitsper*bm->short_per_long:bm->avg_bitsper);
  98075. bm->avg_reservoir+=this_bits-avg_target_bits;
  98076. }
  98077. return(0);
  98078. }
  98079. int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd,ogg_packet *op){
  98080. private_state *b=(private_state*)vd->backend_state;
  98081. bitrate_manager_state *bm=&b->bms;
  98082. vorbis_block *vb=bm->vb;
  98083. int choice=PACKETBLOBS/2;
  98084. if(!vb)return 0;
  98085. if(op){
  98086. vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
  98087. if(vorbis_bitrate_managed(vb))
  98088. choice=bm->choice;
  98089. op->packet=oggpack_get_buffer(vbi->packetblob[choice]);
  98090. op->bytes=oggpack_bytes(vbi->packetblob[choice]);
  98091. op->b_o_s=0;
  98092. op->e_o_s=vb->eofflag;
  98093. op->granulepos=vb->granulepos;
  98094. op->packetno=vb->sequence; /* for sake of completeness */
  98095. }
  98096. bm->vb=0;
  98097. return(1);
  98098. }
  98099. #endif
  98100. /*** End of inlined file: bitrate.c ***/
  98101. /*** Start of inlined file: block.c ***/
  98102. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  98103. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  98104. // tasks..
  98105. #if JUCE_MSVC
  98106. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  98107. #endif
  98108. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  98109. #if JUCE_USE_OGGVORBIS
  98110. #include <stdio.h>
  98111. #include <stdlib.h>
  98112. #include <string.h>
  98113. /*** Start of inlined file: window.h ***/
  98114. #ifndef _V_WINDOW_
  98115. #define _V_WINDOW_
  98116. extern float *_vorbis_window_get(int n);
  98117. extern void _vorbis_apply_window(float *d,int *winno,long *blocksizes,
  98118. int lW,int W,int nW);
  98119. #endif
  98120. /*** End of inlined file: window.h ***/
  98121. /*** Start of inlined file: lpc.h ***/
  98122. #ifndef _V_LPC_H_
  98123. #define _V_LPC_H_
  98124. extern float vorbis_lpc_from_data(float *data,float *lpc,int n,int m);
  98125. extern void vorbis_lpc_predict(float *coeff,float *prime,int m,
  98126. float *data,long n);
  98127. #endif
  98128. /*** End of inlined file: lpc.h ***/
  98129. #ifndef WORD_ALIGN
  98130. #define WORD_ALIGN 8
  98131. #endif
  98132. int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb){
  98133. int i;
  98134. memset(vb,0,sizeof(*vb));
  98135. vb->vd=v;
  98136. vb->localalloc=0;
  98137. vb->localstore=NULL;
  98138. if(v->analysisp){
  98139. vorbis_block_internal *vbi=(vorbis_block_internal*)
  98140. (vb->internal=(vorbis_block_internal*)_ogg_calloc(1,sizeof(vorbis_block_internal)));
  98141. vbi->ampmax=-9999;
  98142. for(i=0;i<PACKETBLOBS;i++){
  98143. if(i==PACKETBLOBS/2){
  98144. vbi->packetblob[i]=&vb->opb;
  98145. }else{
  98146. vbi->packetblob[i]=
  98147. (oggpack_buffer*) _ogg_calloc(1,sizeof(oggpack_buffer));
  98148. }
  98149. oggpack_writeinit(vbi->packetblob[i]);
  98150. }
  98151. }
  98152. return(0);
  98153. }
  98154. void *_vorbis_block_alloc(vorbis_block *vb,long bytes){
  98155. bytes=(bytes+(WORD_ALIGN-1)) & ~(WORD_ALIGN-1);
  98156. if(bytes+vb->localtop>vb->localalloc){
  98157. if(vb->localstore){
  98158. struct alloc_chain *link=(struct alloc_chain*)_ogg_malloc(sizeof(*link));
  98159. vb->totaluse+=vb->localtop;
  98160. link->next=vb->reap;
  98161. link->ptr=vb->localstore;
  98162. vb->reap=link;
  98163. }
  98164. vb->localalloc=bytes;
  98165. vb->localstore=_ogg_malloc(vb->localalloc);
  98166. vb->localtop=0;
  98167. }
  98168. {
  98169. void *ret=(void *)(((char *)vb->localstore)+vb->localtop);
  98170. vb->localtop+=bytes;
  98171. return ret;
  98172. }
  98173. }
  98174. void _vorbis_block_ripcord(vorbis_block *vb){
  98175. struct alloc_chain *reap=vb->reap;
  98176. while(reap){
  98177. struct alloc_chain *next=reap->next;
  98178. _ogg_free(reap->ptr);
  98179. memset(reap,0,sizeof(*reap));
  98180. _ogg_free(reap);
  98181. reap=next;
  98182. }
  98183. if(vb->totaluse){
  98184. vb->localstore=_ogg_realloc(vb->localstore,vb->totaluse+vb->localalloc);
  98185. vb->localalloc+=vb->totaluse;
  98186. vb->totaluse=0;
  98187. }
  98188. vb->localtop=0;
  98189. vb->reap=NULL;
  98190. }
  98191. int vorbis_block_clear(vorbis_block *vb){
  98192. int i;
  98193. vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
  98194. _vorbis_block_ripcord(vb);
  98195. if(vb->localstore)_ogg_free(vb->localstore);
  98196. if(vbi){
  98197. for(i=0;i<PACKETBLOBS;i++){
  98198. oggpack_writeclear(vbi->packetblob[i]);
  98199. if(i!=PACKETBLOBS/2)_ogg_free(vbi->packetblob[i]);
  98200. }
  98201. _ogg_free(vbi);
  98202. }
  98203. memset(vb,0,sizeof(*vb));
  98204. return(0);
  98205. }
  98206. static int _vds_shared_init(vorbis_dsp_state *v,vorbis_info *vi,int encp){
  98207. int i;
  98208. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98209. private_state *b=NULL;
  98210. int hs;
  98211. if(ci==NULL) return 1;
  98212. hs=ci->halfrate_flag;
  98213. memset(v,0,sizeof(*v));
  98214. b=(private_state*) (v->backend_state=(private_state*)_ogg_calloc(1,sizeof(*b)));
  98215. v->vi=vi;
  98216. b->modebits=ilog2(ci->modes);
  98217. b->transform[0]=(vorbis_look_transform**)_ogg_calloc(VI_TRANSFORMB,sizeof(*b->transform[0]));
  98218. b->transform[1]=(vorbis_look_transform**)_ogg_calloc(VI_TRANSFORMB,sizeof(*b->transform[1]));
  98219. b->transform[0][0]=_ogg_calloc(1,sizeof(mdct_lookup));
  98220. b->transform[1][0]=_ogg_calloc(1,sizeof(mdct_lookup));
  98221. mdct_init((mdct_lookup*)b->transform[0][0],ci->blocksizes[0]>>hs);
  98222. mdct_init((mdct_lookup*)b->transform[1][0],ci->blocksizes[1]>>hs);
  98223. b->window[0]=ilog2(ci->blocksizes[0])-6;
  98224. b->window[1]=ilog2(ci->blocksizes[1])-6;
  98225. if(encp){ /* encode/decode differ here */
  98226. drft_init(&b->fft_look[0],ci->blocksizes[0]);
  98227. drft_init(&b->fft_look[1],ci->blocksizes[1]);
  98228. if(!ci->fullbooks){
  98229. ci->fullbooks=(codebook*) _ogg_calloc(ci->books,sizeof(*ci->fullbooks));
  98230. for(i=0;i<ci->books;i++)
  98231. vorbis_book_init_encode(ci->fullbooks+i,ci->book_param[i]);
  98232. }
  98233. b->psy=(vorbis_look_psy*)_ogg_calloc(ci->psys,sizeof(*b->psy));
  98234. for(i=0;i<ci->psys;i++){
  98235. _vp_psy_init(b->psy+i,
  98236. ci->psy_param[i],
  98237. &ci->psy_g_param,
  98238. ci->blocksizes[ci->psy_param[i]->blockflag]/2,
  98239. vi->rate);
  98240. }
  98241. v->analysisp=1;
  98242. }else{
  98243. if(!ci->fullbooks){
  98244. ci->fullbooks=(codebook*) _ogg_calloc(ci->books,sizeof(*ci->fullbooks));
  98245. for(i=0;i<ci->books;i++){
  98246. vorbis_book_init_decode(ci->fullbooks+i,ci->book_param[i]);
  98247. vorbis_staticbook_destroy(ci->book_param[i]);
  98248. ci->book_param[i]=NULL;
  98249. }
  98250. }
  98251. }
  98252. v->pcm_storage=ci->blocksizes[1];
  98253. v->pcm=(float**)_ogg_malloc(vi->channels*sizeof(*v->pcm));
  98254. v->pcmret=(float**)_ogg_malloc(vi->channels*sizeof(*v->pcmret));
  98255. {
  98256. int i;
  98257. for(i=0;i<vi->channels;i++)
  98258. v->pcm[i]=(float*)_ogg_calloc(v->pcm_storage,sizeof(*v->pcm[i]));
  98259. }
  98260. v->lW=0; /* previous window size */
  98261. v->W=0; /* current window size */
  98262. v->centerW=ci->blocksizes[1]/2;
  98263. v->pcm_current=v->centerW;
  98264. b->flr=(vorbis_look_floor**)_ogg_calloc(ci->floors,sizeof(*b->flr));
  98265. b->residue=(vorbis_look_residue**)_ogg_calloc(ci->residues,sizeof(*b->residue));
  98266. for(i=0;i<ci->floors;i++)
  98267. b->flr[i]=_floor_P[ci->floor_type[i]]->
  98268. look(v,ci->floor_param[i]);
  98269. for(i=0;i<ci->residues;i++)
  98270. b->residue[i]=_residue_P[ci->residue_type[i]]->
  98271. look(v,ci->residue_param[i]);
  98272. return 0;
  98273. }
  98274. int vorbis_analysis_init(vorbis_dsp_state *v,vorbis_info *vi){
  98275. private_state *b=NULL;
  98276. if(_vds_shared_init(v,vi,1))return 1;
  98277. b=(private_state*)v->backend_state;
  98278. b->psy_g_look=_vp_global_look(vi);
  98279. b->ve=(envelope_lookup*)_ogg_calloc(1,sizeof(*b->ve));
  98280. _ve_envelope_init(b->ve,vi);
  98281. vorbis_bitrate_init(vi,&b->bms);
  98282. v->sequence=3;
  98283. return(0);
  98284. }
  98285. void vorbis_dsp_clear(vorbis_dsp_state *v){
  98286. int i;
  98287. if(v){
  98288. vorbis_info *vi=v->vi;
  98289. codec_setup_info *ci=(codec_setup_info*)(vi?vi->codec_setup:NULL);
  98290. private_state *b=(private_state*)v->backend_state;
  98291. if(b){
  98292. if(b->ve){
  98293. _ve_envelope_clear(b->ve);
  98294. _ogg_free(b->ve);
  98295. }
  98296. if(b->transform[0]){
  98297. mdct_clear((mdct_lookup*) b->transform[0][0]);
  98298. _ogg_free(b->transform[0][0]);
  98299. _ogg_free(b->transform[0]);
  98300. }
  98301. if(b->transform[1]){
  98302. mdct_clear((mdct_lookup*) b->transform[1][0]);
  98303. _ogg_free(b->transform[1][0]);
  98304. _ogg_free(b->transform[1]);
  98305. }
  98306. if(b->flr){
  98307. for(i=0;i<ci->floors;i++)
  98308. _floor_P[ci->floor_type[i]]->
  98309. free_look(b->flr[i]);
  98310. _ogg_free(b->flr);
  98311. }
  98312. if(b->residue){
  98313. for(i=0;i<ci->residues;i++)
  98314. _residue_P[ci->residue_type[i]]->
  98315. free_look(b->residue[i]);
  98316. _ogg_free(b->residue);
  98317. }
  98318. if(b->psy){
  98319. for(i=0;i<ci->psys;i++)
  98320. _vp_psy_clear(b->psy+i);
  98321. _ogg_free(b->psy);
  98322. }
  98323. if(b->psy_g_look)_vp_global_free(b->psy_g_look);
  98324. vorbis_bitrate_clear(&b->bms);
  98325. drft_clear(&b->fft_look[0]);
  98326. drft_clear(&b->fft_look[1]);
  98327. }
  98328. if(v->pcm){
  98329. for(i=0;i<vi->channels;i++)
  98330. if(v->pcm[i])_ogg_free(v->pcm[i]);
  98331. _ogg_free(v->pcm);
  98332. if(v->pcmret)_ogg_free(v->pcmret);
  98333. }
  98334. if(b){
  98335. if(b->header)_ogg_free(b->header);
  98336. if(b->header1)_ogg_free(b->header1);
  98337. if(b->header2)_ogg_free(b->header2);
  98338. _ogg_free(b);
  98339. }
  98340. memset(v,0,sizeof(*v));
  98341. }
  98342. }
  98343. float **vorbis_analysis_buffer(vorbis_dsp_state *v, int vals){
  98344. int i;
  98345. vorbis_info *vi=v->vi;
  98346. private_state *b=(private_state*)v->backend_state;
  98347. if(b->header)_ogg_free(b->header);b->header=NULL;
  98348. if(b->header1)_ogg_free(b->header1);b->header1=NULL;
  98349. if(b->header2)_ogg_free(b->header2);b->header2=NULL;
  98350. if(v->pcm_current+vals>=v->pcm_storage){
  98351. v->pcm_storage=v->pcm_current+vals*2;
  98352. for(i=0;i<vi->channels;i++){
  98353. v->pcm[i]=(float*)_ogg_realloc(v->pcm[i],v->pcm_storage*sizeof(*v->pcm[i]));
  98354. }
  98355. }
  98356. for(i=0;i<vi->channels;i++)
  98357. v->pcmret[i]=v->pcm[i]+v->pcm_current;
  98358. return(v->pcmret);
  98359. }
  98360. static void _preextrapolate_helper(vorbis_dsp_state *v){
  98361. int i;
  98362. int order=32;
  98363. float *lpc=(float*)alloca(order*sizeof(*lpc));
  98364. float *work=(float*)alloca(v->pcm_current*sizeof(*work));
  98365. long j;
  98366. v->preextrapolate=1;
  98367. if(v->pcm_current-v->centerW>order*2){ /* safety */
  98368. for(i=0;i<v->vi->channels;i++){
  98369. for(j=0;j<v->pcm_current;j++)
  98370. work[j]=v->pcm[i][v->pcm_current-j-1];
  98371. vorbis_lpc_from_data(work,lpc,v->pcm_current-v->centerW,order);
  98372. vorbis_lpc_predict(lpc,work+v->pcm_current-v->centerW-order,
  98373. order,
  98374. work+v->pcm_current-v->centerW,
  98375. v->centerW);
  98376. for(j=0;j<v->pcm_current;j++)
  98377. v->pcm[i][v->pcm_current-j-1]=work[j];
  98378. }
  98379. }
  98380. }
  98381. int vorbis_analysis_wrote(vorbis_dsp_state *v, int vals){
  98382. vorbis_info *vi=v->vi;
  98383. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98384. if(vals<=0){
  98385. int order=32;
  98386. int i;
  98387. float *lpc=(float*) alloca(order*sizeof(*lpc));
  98388. if(!v->preextrapolate)
  98389. _preextrapolate_helper(v);
  98390. vorbis_analysis_buffer(v,ci->blocksizes[1]*3);
  98391. v->eofflag=v->pcm_current;
  98392. v->pcm_current+=ci->blocksizes[1]*3;
  98393. for(i=0;i<vi->channels;i++){
  98394. if(v->eofflag>order*2){
  98395. long n;
  98396. n=v->eofflag;
  98397. if(n>ci->blocksizes[1])n=ci->blocksizes[1];
  98398. vorbis_lpc_from_data(v->pcm[i]+v->eofflag-n,lpc,n,order);
  98399. vorbis_lpc_predict(lpc,v->pcm[i]+v->eofflag-order,order,
  98400. v->pcm[i]+v->eofflag,v->pcm_current-v->eofflag);
  98401. }else{
  98402. memset(v->pcm[i]+v->eofflag,0,
  98403. (v->pcm_current-v->eofflag)*sizeof(*v->pcm[i]));
  98404. }
  98405. }
  98406. }else{
  98407. if(v->pcm_current+vals>v->pcm_storage)
  98408. return(OV_EINVAL);
  98409. v->pcm_current+=vals;
  98410. if(!v->preextrapolate && v->pcm_current-v->centerW>ci->blocksizes[1])
  98411. _preextrapolate_helper(v);
  98412. }
  98413. return(0);
  98414. }
  98415. int vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb){
  98416. int i;
  98417. vorbis_info *vi=v->vi;
  98418. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98419. private_state *b=(private_state*)v->backend_state;
  98420. vorbis_look_psy_global *g=b->psy_g_look;
  98421. long beginW=v->centerW-ci->blocksizes[v->W]/2,centerNext;
  98422. vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
  98423. if(!v->preextrapolate)return(0);
  98424. if(v->eofflag==-1)return(0);
  98425. {
  98426. long bp=_ve_envelope_search(v);
  98427. if(bp==-1){
  98428. if(v->eofflag==0)return(0); /* not enough data currently to search for a
  98429. full long block */
  98430. v->nW=0;
  98431. }else{
  98432. if(ci->blocksizes[0]==ci->blocksizes[1])
  98433. v->nW=0;
  98434. else
  98435. v->nW=bp;
  98436. }
  98437. }
  98438. centerNext=v->centerW+ci->blocksizes[v->W]/4+ci->blocksizes[v->nW]/4;
  98439. {
  98440. long blockbound=centerNext+ci->blocksizes[v->nW]/2;
  98441. if(v->pcm_current<blockbound)return(0); /* not enough data yet;
  98442. although this check is
  98443. less strict that the
  98444. _ve_envelope_search,
  98445. the search is not run
  98446. if we only use one
  98447. block size */
  98448. }
  98449. _vorbis_block_ripcord(vb);
  98450. vb->lW=v->lW;
  98451. vb->W=v->W;
  98452. vb->nW=v->nW;
  98453. if(v->W){
  98454. if(!v->lW || !v->nW){
  98455. vbi->blocktype=BLOCKTYPE_TRANSITION;
  98456. }else{
  98457. vbi->blocktype=BLOCKTYPE_LONG;
  98458. }
  98459. }else{
  98460. if(_ve_envelope_mark(v)){
  98461. vbi->blocktype=BLOCKTYPE_IMPULSE;
  98462. }else{
  98463. vbi->blocktype=BLOCKTYPE_PADDING;
  98464. }
  98465. }
  98466. vb->vd=v;
  98467. vb->sequence=v->sequence++;
  98468. vb->granulepos=v->granulepos;
  98469. vb->pcmend=ci->blocksizes[v->W];
  98470. if(vbi->ampmax>g->ampmax)g->ampmax=vbi->ampmax;
  98471. g->ampmax=_vp_ampmax_decay(g->ampmax,v);
  98472. vbi->ampmax=g->ampmax;
  98473. vb->pcm=(float**)_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels);
  98474. vbi->pcmdelay=(float**)_vorbis_block_alloc(vb,sizeof(*vbi->pcmdelay)*vi->channels);
  98475. for(i=0;i<vi->channels;i++){
  98476. vbi->pcmdelay[i]=
  98477. (float*) _vorbis_block_alloc(vb,(vb->pcmend+beginW)*sizeof(*vbi->pcmdelay[i]));
  98478. memcpy(vbi->pcmdelay[i],v->pcm[i],(vb->pcmend+beginW)*sizeof(*vbi->pcmdelay[i]));
  98479. vb->pcm[i]=vbi->pcmdelay[i]+beginW;
  98480. }
  98481. if(v->eofflag){
  98482. if(v->centerW>=v->eofflag){
  98483. v->eofflag=-1;
  98484. vb->eofflag=1;
  98485. return(1);
  98486. }
  98487. }
  98488. {
  98489. int new_centerNext=ci->blocksizes[1]/2;
  98490. int movementW=centerNext-new_centerNext;
  98491. if(movementW>0){
  98492. _ve_envelope_shift(b->ve,movementW);
  98493. v->pcm_current-=movementW;
  98494. for(i=0;i<vi->channels;i++)
  98495. memmove(v->pcm[i],v->pcm[i]+movementW,
  98496. v->pcm_current*sizeof(*v->pcm[i]));
  98497. v->lW=v->W;
  98498. v->W=v->nW;
  98499. v->centerW=new_centerNext;
  98500. if(v->eofflag){
  98501. v->eofflag-=movementW;
  98502. if(v->eofflag<=0)v->eofflag=-1;
  98503. if(v->centerW>=v->eofflag){
  98504. v->granulepos+=movementW-(v->centerW-v->eofflag);
  98505. }else{
  98506. v->granulepos+=movementW;
  98507. }
  98508. }else{
  98509. v->granulepos+=movementW;
  98510. }
  98511. }
  98512. }
  98513. return(1);
  98514. }
  98515. int vorbis_synthesis_restart(vorbis_dsp_state *v){
  98516. vorbis_info *vi=v->vi;
  98517. codec_setup_info *ci;
  98518. int hs;
  98519. if(!v->backend_state)return -1;
  98520. if(!vi)return -1;
  98521. ci=(codec_setup_info*) vi->codec_setup;
  98522. if(!ci)return -1;
  98523. hs=ci->halfrate_flag;
  98524. v->centerW=ci->blocksizes[1]>>(hs+1);
  98525. v->pcm_current=v->centerW>>hs;
  98526. v->pcm_returned=-1;
  98527. v->granulepos=-1;
  98528. v->sequence=-1;
  98529. v->eofflag=0;
  98530. ((private_state *)(v->backend_state))->sample_count=-1;
  98531. return(0);
  98532. }
  98533. int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi){
  98534. if(_vds_shared_init(v,vi,0)) return 1;
  98535. vorbis_synthesis_restart(v);
  98536. return 0;
  98537. }
  98538. int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb){
  98539. vorbis_info *vi=v->vi;
  98540. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98541. private_state *b=(private_state*)v->backend_state;
  98542. int hs=ci->halfrate_flag;
  98543. int i,j;
  98544. if(!vb)return(OV_EINVAL);
  98545. if(v->pcm_current>v->pcm_returned && v->pcm_returned!=-1)return(OV_EINVAL);
  98546. v->lW=v->W;
  98547. v->W=vb->W;
  98548. v->nW=-1;
  98549. if((v->sequence==-1)||
  98550. (v->sequence+1 != vb->sequence)){
  98551. v->granulepos=-1; /* out of sequence; lose count */
  98552. b->sample_count=-1;
  98553. }
  98554. v->sequence=vb->sequence;
  98555. if(vb->pcm){ /* no pcm to process if vorbis_synthesis_trackonly
  98556. was called on block */
  98557. int n=ci->blocksizes[v->W]>>(hs+1);
  98558. int n0=ci->blocksizes[0]>>(hs+1);
  98559. int n1=ci->blocksizes[1]>>(hs+1);
  98560. int thisCenter;
  98561. int prevCenter;
  98562. v->glue_bits+=vb->glue_bits;
  98563. v->time_bits+=vb->time_bits;
  98564. v->floor_bits+=vb->floor_bits;
  98565. v->res_bits+=vb->res_bits;
  98566. if(v->centerW){
  98567. thisCenter=n1;
  98568. prevCenter=0;
  98569. }else{
  98570. thisCenter=0;
  98571. prevCenter=n1;
  98572. }
  98573. for(j=0;j<vi->channels;j++){
  98574. if(v->lW){
  98575. if(v->W){
  98576. float *w=_vorbis_window_get(b->window[1]-hs);
  98577. float *pcm=v->pcm[j]+prevCenter;
  98578. float *p=vb->pcm[j];
  98579. for(i=0;i<n1;i++)
  98580. pcm[i]=pcm[i]*w[n1-i-1] + p[i]*w[i];
  98581. }else{
  98582. float *w=_vorbis_window_get(b->window[0]-hs);
  98583. float *pcm=v->pcm[j]+prevCenter+n1/2-n0/2;
  98584. float *p=vb->pcm[j];
  98585. for(i=0;i<n0;i++)
  98586. pcm[i]=pcm[i]*w[n0-i-1] +p[i]*w[i];
  98587. }
  98588. }else{
  98589. if(v->W){
  98590. float *w=_vorbis_window_get(b->window[0]-hs);
  98591. float *pcm=v->pcm[j]+prevCenter;
  98592. float *p=vb->pcm[j]+n1/2-n0/2;
  98593. for(i=0;i<n0;i++)
  98594. pcm[i]=pcm[i]*w[n0-i-1] +p[i]*w[i];
  98595. for(;i<n1/2+n0/2;i++)
  98596. pcm[i]=p[i];
  98597. }else{
  98598. float *w=_vorbis_window_get(b->window[0]-hs);
  98599. float *pcm=v->pcm[j]+prevCenter;
  98600. float *p=vb->pcm[j];
  98601. for(i=0;i<n0;i++)
  98602. pcm[i]=pcm[i]*w[n0-i-1] +p[i]*w[i];
  98603. }
  98604. }
  98605. {
  98606. float *pcm=v->pcm[j]+thisCenter;
  98607. float *p=vb->pcm[j]+n;
  98608. for(i=0;i<n;i++)
  98609. pcm[i]=p[i];
  98610. }
  98611. }
  98612. if(v->centerW)
  98613. v->centerW=0;
  98614. else
  98615. v->centerW=n1;
  98616. if(v->pcm_returned==-1){
  98617. v->pcm_returned=thisCenter;
  98618. v->pcm_current=thisCenter;
  98619. }else{
  98620. v->pcm_returned=prevCenter;
  98621. v->pcm_current=prevCenter+
  98622. ((ci->blocksizes[v->lW]/4+
  98623. ci->blocksizes[v->W]/4)>>hs);
  98624. }
  98625. }
  98626. if(b->sample_count==-1){
  98627. b->sample_count=0;
  98628. }else{
  98629. b->sample_count+=ci->blocksizes[v->lW]/4+ci->blocksizes[v->W]/4;
  98630. }
  98631. if(v->granulepos==-1){
  98632. if(vb->granulepos!=-1){ /* only set if we have a position to set to */
  98633. v->granulepos=vb->granulepos;
  98634. if(b->sample_count>v->granulepos){
  98635. if(vb->eofflag){
  98636. v->pcm_current-=(b->sample_count-v->granulepos)>>hs;
  98637. }else{
  98638. v->pcm_returned+=(b->sample_count-v->granulepos)>>hs;
  98639. if(v->pcm_returned>v->pcm_current)
  98640. v->pcm_returned=v->pcm_current;
  98641. }
  98642. }
  98643. }
  98644. }else{
  98645. v->granulepos+=ci->blocksizes[v->lW]/4+ci->blocksizes[v->W]/4;
  98646. if(vb->granulepos!=-1 && v->granulepos!=vb->granulepos){
  98647. if(v->granulepos>vb->granulepos){
  98648. long extra=v->granulepos-vb->granulepos;
  98649. if(extra)
  98650. if(vb->eofflag){
  98651. v->pcm_current-=extra>>hs;
  98652. } /* else {Shouldn't happen *unless* the bitstream is out of
  98653. spec. Either way, believe the bitstream } */
  98654. } /* else {Shouldn't happen *unless* the bitstream is out of
  98655. spec. Either way, believe the bitstream } */
  98656. v->granulepos=vb->granulepos;
  98657. }
  98658. }
  98659. if(vb->eofflag)v->eofflag=1;
  98660. return(0);
  98661. }
  98662. int vorbis_synthesis_pcmout(vorbis_dsp_state *v,float ***pcm){
  98663. vorbis_info *vi=v->vi;
  98664. if(v->pcm_returned>-1 && v->pcm_returned<v->pcm_current){
  98665. if(pcm){
  98666. int i;
  98667. for(i=0;i<vi->channels;i++)
  98668. v->pcmret[i]=v->pcm[i]+v->pcm_returned;
  98669. *pcm=v->pcmret;
  98670. }
  98671. return(v->pcm_current-v->pcm_returned);
  98672. }
  98673. return(0);
  98674. }
  98675. int vorbis_synthesis_read(vorbis_dsp_state *v,int n){
  98676. if(n && v->pcm_returned+n>v->pcm_current)return(OV_EINVAL);
  98677. v->pcm_returned+=n;
  98678. return(0);
  98679. }
  98680. int vorbis_synthesis_lapout(vorbis_dsp_state *v,float ***pcm){
  98681. vorbis_info *vi=v->vi;
  98682. codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
  98683. int hs=ci->halfrate_flag;
  98684. int n=ci->blocksizes[v->W]>>(hs+1);
  98685. int n0=ci->blocksizes[0]>>(hs+1);
  98686. int n1=ci->blocksizes[1]>>(hs+1);
  98687. int i,j;
  98688. if(v->pcm_returned<0)return 0;
  98689. if(v->centerW==n1){
  98690. for(j=0;j<vi->channels;j++){
  98691. float *p=v->pcm[j];
  98692. for(i=0;i<n1;i++){
  98693. float temp=p[i];
  98694. p[i]=p[i+n1];
  98695. p[i+n1]=temp;
  98696. }
  98697. }
  98698. v->pcm_current-=n1;
  98699. v->pcm_returned-=n1;
  98700. v->centerW=0;
  98701. }
  98702. if((v->lW^v->W)==1){
  98703. for(j=0;j<vi->channels;j++){
  98704. float *s=v->pcm[j];
  98705. float *d=v->pcm[j]+(n1-n0)/2;
  98706. for(i=(n1+n0)/2-1;i>=0;--i)
  98707. d[i]=s[i];
  98708. }
  98709. v->pcm_returned+=(n1-n0)/2;
  98710. v->pcm_current+=(n1-n0)/2;
  98711. }else{
  98712. if(v->lW==0){
  98713. for(j=0;j<vi->channels;j++){
  98714. float *s=v->pcm[j];
  98715. float *d=v->pcm[j]+n1-n0;
  98716. for(i=n0-1;i>=0;--i)
  98717. d[i]=s[i];
  98718. }
  98719. v->pcm_returned+=n1-n0;
  98720. v->pcm_current+=n1-n0;
  98721. }
  98722. }
  98723. if(pcm){
  98724. int i;
  98725. for(i=0;i<vi->channels;i++)
  98726. v->pcmret[i]=v->pcm[i]+v->pcm_returned;
  98727. *pcm=v->pcmret;
  98728. }
  98729. return(n1+n-v->pcm_returned);
  98730. }
  98731. float *vorbis_window(vorbis_dsp_state *v,int W){
  98732. vorbis_info *vi=v->vi;
  98733. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  98734. int hs=ci->halfrate_flag;
  98735. private_state *b=(private_state*)v->backend_state;
  98736. if(b->window[W]-1<0)return NULL;
  98737. return _vorbis_window_get(b->window[W]-hs);
  98738. }
  98739. #endif
  98740. /*** End of inlined file: block.c ***/
  98741. /*** Start of inlined file: codebook.c ***/
  98742. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  98743. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  98744. // tasks..
  98745. #if JUCE_MSVC
  98746. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  98747. #endif
  98748. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  98749. #if JUCE_USE_OGGVORBIS
  98750. #include <stdlib.h>
  98751. #include <string.h>
  98752. #include <math.h>
  98753. int vorbis_staticbook_pack(const static_codebook *c,oggpack_buffer *opb){
  98754. long i,j;
  98755. int ordered=0;
  98756. oggpack_write(opb,0x564342,24);
  98757. oggpack_write(opb,c->dim,16);
  98758. oggpack_write(opb,c->entries,24);
  98759. for(i=1;i<c->entries;i++)
  98760. if(c->lengthlist[i-1]==0 || c->lengthlist[i]<c->lengthlist[i-1])break;
  98761. if(i==c->entries)ordered=1;
  98762. if(ordered){
  98763. long count=0;
  98764. oggpack_write(opb,1,1); /* ordered */
  98765. oggpack_write(opb,c->lengthlist[0]-1,5); /* 1 to 32 */
  98766. for(i=1;i<c->entries;i++){
  98767. long thisx=c->lengthlist[i];
  98768. long last=c->lengthlist[i-1];
  98769. if(thisx>last){
  98770. for(j=last;j<thisx;j++){
  98771. oggpack_write(opb,i-count,_ilog(c->entries-count));
  98772. count=i;
  98773. }
  98774. }
  98775. }
  98776. oggpack_write(opb,i-count,_ilog(c->entries-count));
  98777. }else{
  98778. oggpack_write(opb,0,1); /* unordered */
  98779. for(i=0;i<c->entries;i++)
  98780. if(c->lengthlist[i]==0)break;
  98781. if(i==c->entries){
  98782. oggpack_write(opb,0,1); /* no unused entries */
  98783. for(i=0;i<c->entries;i++)
  98784. oggpack_write(opb,c->lengthlist[i]-1,5);
  98785. }else{
  98786. oggpack_write(opb,1,1); /* we have unused entries; thus we tag */
  98787. for(i=0;i<c->entries;i++){
  98788. if(c->lengthlist[i]==0){
  98789. oggpack_write(opb,0,1);
  98790. }else{
  98791. oggpack_write(opb,1,1);
  98792. oggpack_write(opb,c->lengthlist[i]-1,5);
  98793. }
  98794. }
  98795. }
  98796. }
  98797. oggpack_write(opb,c->maptype,4);
  98798. switch(c->maptype){
  98799. case 0:
  98800. break;
  98801. case 1:case 2:
  98802. if(!c->quantlist){
  98803. return(-1);
  98804. }
  98805. oggpack_write(opb,c->q_min,32);
  98806. oggpack_write(opb,c->q_delta,32);
  98807. oggpack_write(opb,c->q_quant-1,4);
  98808. oggpack_write(opb,c->q_sequencep,1);
  98809. {
  98810. int quantvals;
  98811. switch(c->maptype){
  98812. case 1:
  98813. quantvals=_book_maptype1_quantvals(c);
  98814. break;
  98815. case 2:
  98816. quantvals=c->entries*c->dim;
  98817. break;
  98818. default: /* NOT_REACHABLE */
  98819. quantvals=-1;
  98820. }
  98821. for(i=0;i<quantvals;i++)
  98822. oggpack_write(opb,labs(c->quantlist[i]),c->q_quant);
  98823. }
  98824. break;
  98825. default:
  98826. return(-1);
  98827. }
  98828. return(0);
  98829. }
  98830. int vorbis_staticbook_unpack(oggpack_buffer *opb,static_codebook *s){
  98831. long i,j;
  98832. memset(s,0,sizeof(*s));
  98833. s->allocedp=1;
  98834. if(oggpack_read(opb,24)!=0x564342)goto _eofout;
  98835. s->dim=oggpack_read(opb,16);
  98836. s->entries=oggpack_read(opb,24);
  98837. if(s->entries==-1)goto _eofout;
  98838. switch((int)oggpack_read(opb,1)){
  98839. case 0:
  98840. s->lengthlist=(long*)_ogg_malloc(sizeof(*s->lengthlist)*s->entries);
  98841. if(oggpack_read(opb,1)){
  98842. for(i=0;i<s->entries;i++){
  98843. if(oggpack_read(opb,1)){
  98844. long num=oggpack_read(opb,5);
  98845. if(num==-1)goto _eofout;
  98846. s->lengthlist[i]=num+1;
  98847. }else
  98848. s->lengthlist[i]=0;
  98849. }
  98850. }else{
  98851. for(i=0;i<s->entries;i++){
  98852. long num=oggpack_read(opb,5);
  98853. if(num==-1)goto _eofout;
  98854. s->lengthlist[i]=num+1;
  98855. }
  98856. }
  98857. break;
  98858. case 1:
  98859. {
  98860. long length=oggpack_read(opb,5)+1;
  98861. s->lengthlist=(long*)_ogg_malloc(sizeof(*s->lengthlist)*s->entries);
  98862. for(i=0;i<s->entries;){
  98863. long num=oggpack_read(opb,_ilog(s->entries-i));
  98864. if(num==-1)goto _eofout;
  98865. for(j=0;j<num && i<s->entries;j++,i++)
  98866. s->lengthlist[i]=length;
  98867. length++;
  98868. }
  98869. }
  98870. break;
  98871. default:
  98872. return(-1);
  98873. }
  98874. switch((s->maptype=oggpack_read(opb,4))){
  98875. case 0:
  98876. break;
  98877. case 1: case 2:
  98878. s->q_min=oggpack_read(opb,32);
  98879. s->q_delta=oggpack_read(opb,32);
  98880. s->q_quant=oggpack_read(opb,4)+1;
  98881. s->q_sequencep=oggpack_read(opb,1);
  98882. {
  98883. int quantvals=0;
  98884. switch(s->maptype){
  98885. case 1:
  98886. quantvals=_book_maptype1_quantvals(s);
  98887. break;
  98888. case 2:
  98889. quantvals=s->entries*s->dim;
  98890. break;
  98891. }
  98892. s->quantlist=(long*)_ogg_malloc(sizeof(*s->quantlist)*quantvals);
  98893. for(i=0;i<quantvals;i++)
  98894. s->quantlist[i]=oggpack_read(opb,s->q_quant);
  98895. if(quantvals&&s->quantlist[quantvals-1]==-1)goto _eofout;
  98896. }
  98897. break;
  98898. default:
  98899. goto _errout;
  98900. }
  98901. return(0);
  98902. _errout:
  98903. _eofout:
  98904. vorbis_staticbook_clear(s);
  98905. return(-1);
  98906. }
  98907. int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b){
  98908. oggpack_write(b,book->codelist[a],book->c->lengthlist[a]);
  98909. return(book->c->lengthlist[a]);
  98910. }
  98911. int vorbis_book_errorv(codebook *book,float *a){
  98912. int dim=book->dim,k;
  98913. int best=_best(book,a,1);
  98914. for(k=0;k<dim;k++)
  98915. a[k]=(book->valuelist+best*dim)[k];
  98916. return(best);
  98917. }
  98918. int vorbis_book_encodev(codebook *book,int best,float *a,oggpack_buffer *b){
  98919. int k,dim=book->dim;
  98920. for(k=0;k<dim;k++)
  98921. a[k]=(book->valuelist+best*dim)[k];
  98922. return(vorbis_book_encode(book,best,b));
  98923. }
  98924. STIN long decode_packed_entry_number(codebook *book, oggpack_buffer *b){
  98925. int read=book->dec_maxlength;
  98926. long lo,hi;
  98927. long lok = oggpack_look(b,book->dec_firsttablen);
  98928. if (lok >= 0) {
  98929. long entry = book->dec_firsttable[lok];
  98930. if(entry&0x80000000UL){
  98931. lo=(entry>>15)&0x7fff;
  98932. hi=book->used_entries-(entry&0x7fff);
  98933. }else{
  98934. oggpack_adv(b, book->dec_codelengths[entry-1]);
  98935. return(entry-1);
  98936. }
  98937. }else{
  98938. lo=0;
  98939. hi=book->used_entries;
  98940. }
  98941. lok = oggpack_look(b, read);
  98942. while(lok<0 && read>1)
  98943. lok = oggpack_look(b, --read);
  98944. if(lok<0)return -1;
  98945. {
  98946. ogg_uint32_t testword=ogg_bitreverse((ogg_uint32_t)lok);
  98947. while(hi-lo>1){
  98948. long p=(hi-lo)>>1;
  98949. long test=book->codelist[lo+p]>testword;
  98950. lo+=p&(test-1);
  98951. hi-=p&(-test);
  98952. }
  98953. if(book->dec_codelengths[lo]<=read){
  98954. oggpack_adv(b, book->dec_codelengths[lo]);
  98955. return(lo);
  98956. }
  98957. }
  98958. oggpack_adv(b, read);
  98959. return(-1);
  98960. }
  98961. long vorbis_book_decode(codebook *book, oggpack_buffer *b){
  98962. long packed_entry=decode_packed_entry_number(book,b);
  98963. if(packed_entry>=0)
  98964. return(book->dec_index[packed_entry]);
  98965. return(packed_entry);
  98966. }
  98967. long vorbis_book_decodevs_add(codebook *book,float *a,oggpack_buffer *b,int n){
  98968. int step=n/book->dim;
  98969. long *entry = (long*)alloca(sizeof(*entry)*step);
  98970. float **t = (float**)alloca(sizeof(*t)*step);
  98971. int i,j,o;
  98972. for (i = 0; i < step; i++) {
  98973. entry[i]=decode_packed_entry_number(book,b);
  98974. if(entry[i]==-1)return(-1);
  98975. t[i] = book->valuelist+entry[i]*book->dim;
  98976. }
  98977. for(i=0,o=0;i<book->dim;i++,o+=step)
  98978. for (j=0;j<step;j++)
  98979. a[o+j]+=t[j][i];
  98980. return(0);
  98981. }
  98982. long vorbis_book_decodev_add(codebook *book,float *a,oggpack_buffer *b,int n){
  98983. int i,j,entry;
  98984. float *t;
  98985. if(book->dim>8){
  98986. for(i=0;i<n;){
  98987. entry = decode_packed_entry_number(book,b);
  98988. if(entry==-1)return(-1);
  98989. t = book->valuelist+entry*book->dim;
  98990. for (j=0;j<book->dim;)
  98991. a[i++]+=t[j++];
  98992. }
  98993. }else{
  98994. for(i=0;i<n;){
  98995. entry = decode_packed_entry_number(book,b);
  98996. if(entry==-1)return(-1);
  98997. t = book->valuelist+entry*book->dim;
  98998. j=0;
  98999. switch((int)book->dim){
  99000. case 8:
  99001. a[i++]+=t[j++];
  99002. case 7:
  99003. a[i++]+=t[j++];
  99004. case 6:
  99005. a[i++]+=t[j++];
  99006. case 5:
  99007. a[i++]+=t[j++];
  99008. case 4:
  99009. a[i++]+=t[j++];
  99010. case 3:
  99011. a[i++]+=t[j++];
  99012. case 2:
  99013. a[i++]+=t[j++];
  99014. case 1:
  99015. a[i++]+=t[j++];
  99016. case 0:
  99017. break;
  99018. }
  99019. }
  99020. }
  99021. return(0);
  99022. }
  99023. long vorbis_book_decodev_set(codebook *book,float *a,oggpack_buffer *b,int n){
  99024. int i,j,entry;
  99025. float *t;
  99026. for(i=0;i<n;){
  99027. entry = decode_packed_entry_number(book,b);
  99028. if(entry==-1)return(-1);
  99029. t = book->valuelist+entry*book->dim;
  99030. for (j=0;j<book->dim;)
  99031. a[i++]=t[j++];
  99032. }
  99033. return(0);
  99034. }
  99035. long vorbis_book_decodevv_add(codebook *book,float **a,long offset,int ch,
  99036. oggpack_buffer *b,int n){
  99037. long i,j,entry;
  99038. int chptr=0;
  99039. for(i=offset/ch;i<(offset+n)/ch;){
  99040. entry = decode_packed_entry_number(book,b);
  99041. if(entry==-1)return(-1);
  99042. {
  99043. const float *t = book->valuelist+entry*book->dim;
  99044. for (j=0;j<book->dim;j++){
  99045. a[chptr++][i]+=t[j];
  99046. if(chptr==ch){
  99047. chptr=0;
  99048. i++;
  99049. }
  99050. }
  99051. }
  99052. }
  99053. return(0);
  99054. }
  99055. #ifdef _V_SELFTEST
  99056. #include <stdio.h>
  99057. #include "vorbis/book/lsp20_0.vqh"
  99058. #include "vorbis/book/res0a_13.vqh"
  99059. #define TESTSIZE 40
  99060. float test1[TESTSIZE]={
  99061. 0.105939f,
  99062. 0.215373f,
  99063. 0.429117f,
  99064. 0.587974f,
  99065. 0.181173f,
  99066. 0.296583f,
  99067. 0.515707f,
  99068. 0.715261f,
  99069. 0.162327f,
  99070. 0.263834f,
  99071. 0.342876f,
  99072. 0.406025f,
  99073. 0.103571f,
  99074. 0.223561f,
  99075. 0.368513f,
  99076. 0.540313f,
  99077. 0.136672f,
  99078. 0.395882f,
  99079. 0.587183f,
  99080. 0.652476f,
  99081. 0.114338f,
  99082. 0.417300f,
  99083. 0.525486f,
  99084. 0.698679f,
  99085. 0.147492f,
  99086. 0.324481f,
  99087. 0.643089f,
  99088. 0.757582f,
  99089. 0.139556f,
  99090. 0.215795f,
  99091. 0.324559f,
  99092. 0.399387f,
  99093. 0.120236f,
  99094. 0.267420f,
  99095. 0.446940f,
  99096. 0.608760f,
  99097. 0.115587f,
  99098. 0.287234f,
  99099. 0.571081f,
  99100. 0.708603f,
  99101. };
  99102. float test3[TESTSIZE]={
  99103. 0,1,-2,3,4,-5,6,7,8,9,
  99104. 8,-2,7,-1,4,6,8,3,1,-9,
  99105. 10,11,12,13,14,15,26,17,18,19,
  99106. 30,-25,-30,-1,-5,-32,4,3,-2,0};
  99107. static_codebook *testlist[]={&_vq_book_lsp20_0,
  99108. &_vq_book_res0a_13,NULL};
  99109. float *testvec[]={test1,test3};
  99110. int main(){
  99111. oggpack_buffer write;
  99112. oggpack_buffer read;
  99113. long ptr=0,i;
  99114. oggpack_writeinit(&write);
  99115. fprintf(stderr,"Testing codebook abstraction...:\n");
  99116. while(testlist[ptr]){
  99117. codebook c;
  99118. static_codebook s;
  99119. float *qv=alloca(sizeof(*qv)*TESTSIZE);
  99120. float *iv=alloca(sizeof(*iv)*TESTSIZE);
  99121. memcpy(qv,testvec[ptr],sizeof(*qv)*TESTSIZE);
  99122. memset(iv,0,sizeof(*iv)*TESTSIZE);
  99123. fprintf(stderr,"\tpacking/coding %ld... ",ptr);
  99124. oggpack_reset(&write);
  99125. vorbis_book_init_encode(&c,testlist[ptr]); /* get it into memory
  99126. we can write */
  99127. vorbis_staticbook_pack(testlist[ptr],&write);
  99128. fprintf(stderr,"Codebook size %ld bytes... ",oggpack_bytes(&write));
  99129. for(i=0;i<TESTSIZE;i+=c.dim){
  99130. int best=_best(&c,qv+i,1);
  99131. vorbis_book_encodev(&c,best,qv+i,&write);
  99132. }
  99133. vorbis_book_clear(&c);
  99134. fprintf(stderr,"OK.\n");
  99135. fprintf(stderr,"\tunpacking/decoding %ld... ",ptr);
  99136. oggpack_readinit(&read,oggpack_get_buffer(&write),oggpack_bytes(&write));
  99137. if(vorbis_staticbook_unpack(&read,&s)){
  99138. fprintf(stderr,"Error unpacking codebook.\n");
  99139. exit(1);
  99140. }
  99141. if(vorbis_book_init_decode(&c,&s)){
  99142. fprintf(stderr,"Error initializing codebook.\n");
  99143. exit(1);
  99144. }
  99145. for(i=0;i<TESTSIZE;i+=c.dim)
  99146. if(vorbis_book_decodev_set(&c,iv+i,&read,c.dim)==-1){
  99147. fprintf(stderr,"Error reading codebook test data (EOP).\n");
  99148. exit(1);
  99149. }
  99150. for(i=0;i<TESTSIZE;i++)
  99151. if(fabs(qv[i]-iv[i])>.000001){
  99152. fprintf(stderr,"read (%g) != written (%g) at position (%ld)\n",
  99153. iv[i],qv[i],i);
  99154. exit(1);
  99155. }
  99156. fprintf(stderr,"OK\n");
  99157. ptr++;
  99158. }
  99159. exit(0);
  99160. }
  99161. #endif
  99162. #endif
  99163. /*** End of inlined file: codebook.c ***/
  99164. /*** Start of inlined file: envelope.c ***/
  99165. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  99166. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  99167. // tasks..
  99168. #if JUCE_MSVC
  99169. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  99170. #endif
  99171. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  99172. #if JUCE_USE_OGGVORBIS
  99173. #include <stdlib.h>
  99174. #include <string.h>
  99175. #include <stdio.h>
  99176. #include <math.h>
  99177. void _ve_envelope_init(envelope_lookup *e,vorbis_info *vi){
  99178. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99179. vorbis_info_psy_global *gi=&ci->psy_g_param;
  99180. int ch=vi->channels;
  99181. int i,j;
  99182. int n=e->winlength=128;
  99183. e->searchstep=64; /* not random */
  99184. e->minenergy=gi->preecho_minenergy;
  99185. e->ch=ch;
  99186. e->storage=128;
  99187. e->cursor=ci->blocksizes[1]/2;
  99188. e->mdct_win=(float*)_ogg_calloc(n,sizeof(*e->mdct_win));
  99189. mdct_init(&e->mdct,n);
  99190. for(i=0;i<n;i++){
  99191. e->mdct_win[i]=sin(i/(n-1.)*M_PI);
  99192. e->mdct_win[i]*=e->mdct_win[i];
  99193. }
  99194. e->band[0].begin=2; e->band[0].end=4;
  99195. e->band[1].begin=4; e->band[1].end=5;
  99196. e->band[2].begin=6; e->band[2].end=6;
  99197. e->band[3].begin=9; e->band[3].end=8;
  99198. e->band[4].begin=13; e->band[4].end=8;
  99199. e->band[5].begin=17; e->band[5].end=8;
  99200. e->band[6].begin=22; e->band[6].end=8;
  99201. for(j=0;j<VE_BANDS;j++){
  99202. n=e->band[j].end;
  99203. e->band[j].window=(float*)_ogg_malloc(n*sizeof(*e->band[0].window));
  99204. for(i=0;i<n;i++){
  99205. e->band[j].window[i]=sin((i+.5)/n*M_PI);
  99206. e->band[j].total+=e->band[j].window[i];
  99207. }
  99208. e->band[j].total=1./e->band[j].total;
  99209. }
  99210. e->filter=(envelope_filter_state*)_ogg_calloc(VE_BANDS*ch,sizeof(*e->filter));
  99211. e->mark=(int*)_ogg_calloc(e->storage,sizeof(*e->mark));
  99212. }
  99213. void _ve_envelope_clear(envelope_lookup *e){
  99214. int i;
  99215. mdct_clear(&e->mdct);
  99216. for(i=0;i<VE_BANDS;i++)
  99217. _ogg_free(e->band[i].window);
  99218. _ogg_free(e->mdct_win);
  99219. _ogg_free(e->filter);
  99220. _ogg_free(e->mark);
  99221. memset(e,0,sizeof(*e));
  99222. }
  99223. static int _ve_amp(envelope_lookup *ve,
  99224. vorbis_info_psy_global *gi,
  99225. float *data,
  99226. envelope_band *bands,
  99227. envelope_filter_state *filters,
  99228. long pos){
  99229. long n=ve->winlength;
  99230. int ret=0;
  99231. long i,j;
  99232. float decay;
  99233. float minV=ve->minenergy;
  99234. float *vec=(float*) alloca(n*sizeof(*vec));
  99235. int stretch=max(VE_MINSTRETCH,ve->stretch/2);
  99236. float penalty=gi->stretch_penalty-(ve->stretch/2-VE_MINSTRETCH);
  99237. if(penalty<0.f)penalty=0.f;
  99238. if(penalty>gi->stretch_penalty)penalty=gi->stretch_penalty;
  99239. for(i=0;i<n;i++)
  99240. vec[i]=data[i]*ve->mdct_win[i];
  99241. mdct_forward(&ve->mdct,vec,vec);
  99242. {
  99243. float temp=vec[0]*vec[0]+.7*vec[1]*vec[1]+.2*vec[2]*vec[2];
  99244. int ptr=filters->nearptr;
  99245. if(ptr==0){
  99246. decay=filters->nearDC_acc=filters->nearDC_partialacc+temp;
  99247. filters->nearDC_partialacc=temp;
  99248. }else{
  99249. decay=filters->nearDC_acc+=temp;
  99250. filters->nearDC_partialacc+=temp;
  99251. }
  99252. filters->nearDC_acc-=filters->nearDC[ptr];
  99253. filters->nearDC[ptr]=temp;
  99254. decay*=(1./(VE_NEARDC+1));
  99255. filters->nearptr++;
  99256. if(filters->nearptr>=VE_NEARDC)filters->nearptr=0;
  99257. decay=todB(&decay)*.5-15.f;
  99258. }
  99259. for(i=0;i<n/2;i+=2){
  99260. float val=vec[i]*vec[i]+vec[i+1]*vec[i+1];
  99261. val=todB(&val)*.5f;
  99262. if(val<decay)val=decay;
  99263. if(val<minV)val=minV;
  99264. vec[i>>1]=val;
  99265. decay-=8.;
  99266. }
  99267. for(j=0;j<VE_BANDS;j++){
  99268. float acc=0.;
  99269. float valmax,valmin;
  99270. for(i=0;i<bands[j].end;i++)
  99271. acc+=vec[i+bands[j].begin]*bands[j].window[i];
  99272. acc*=bands[j].total;
  99273. {
  99274. int p,thisx=filters[j].ampptr;
  99275. float postmax,postmin,premax=-99999.f,premin=99999.f;
  99276. p=thisx;
  99277. p--;
  99278. if(p<0)p+=VE_AMP;
  99279. postmax=max(acc,filters[j].ampbuf[p]);
  99280. postmin=min(acc,filters[j].ampbuf[p]);
  99281. for(i=0;i<stretch;i++){
  99282. p--;
  99283. if(p<0)p+=VE_AMP;
  99284. premax=max(premax,filters[j].ampbuf[p]);
  99285. premin=min(premin,filters[j].ampbuf[p]);
  99286. }
  99287. valmin=postmin-premin;
  99288. valmax=postmax-premax;
  99289. filters[j].ampbuf[thisx]=acc;
  99290. filters[j].ampptr++;
  99291. if(filters[j].ampptr>=VE_AMP)filters[j].ampptr=0;
  99292. }
  99293. if(valmax>gi->preecho_thresh[j]+penalty){
  99294. ret|=1;
  99295. ret|=4;
  99296. }
  99297. if(valmin<gi->postecho_thresh[j]-penalty)ret|=2;
  99298. }
  99299. return(ret);
  99300. }
  99301. #if 0
  99302. static int seq=0;
  99303. static ogg_int64_t totalshift=-1024;
  99304. #endif
  99305. long _ve_envelope_search(vorbis_dsp_state *v){
  99306. vorbis_info *vi=v->vi;
  99307. codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
  99308. vorbis_info_psy_global *gi=&ci->psy_g_param;
  99309. envelope_lookup *ve=((private_state *)(v->backend_state))->ve;
  99310. long i,j;
  99311. int first=ve->current/ve->searchstep;
  99312. int last=v->pcm_current/ve->searchstep-VE_WIN;
  99313. if(first<0)first=0;
  99314. if(last+VE_WIN+VE_POST>ve->storage){
  99315. ve->storage=last+VE_WIN+VE_POST; /* be sure */
  99316. ve->mark=(int*)_ogg_realloc(ve->mark,ve->storage*sizeof(*ve->mark));
  99317. }
  99318. for(j=first;j<last;j++){
  99319. int ret=0;
  99320. ve->stretch++;
  99321. if(ve->stretch>VE_MAXSTRETCH*2)
  99322. ve->stretch=VE_MAXSTRETCH*2;
  99323. for(i=0;i<ve->ch;i++){
  99324. float *pcm=v->pcm[i]+ve->searchstep*(j);
  99325. ret|=_ve_amp(ve,gi,pcm,ve->band,ve->filter+i*VE_BANDS,j);
  99326. }
  99327. ve->mark[j+VE_POST]=0;
  99328. if(ret&1){
  99329. ve->mark[j]=1;
  99330. ve->mark[j+1]=1;
  99331. }
  99332. if(ret&2){
  99333. ve->mark[j]=1;
  99334. if(j>0)ve->mark[j-1]=1;
  99335. }
  99336. if(ret&4)ve->stretch=-1;
  99337. }
  99338. ve->current=last*ve->searchstep;
  99339. {
  99340. long centerW=v->centerW;
  99341. long testW=
  99342. centerW+
  99343. ci->blocksizes[v->W]/4+
  99344. ci->blocksizes[1]/2+
  99345. ci->blocksizes[0]/4;
  99346. j=ve->cursor;
  99347. while(j<ve->current-(ve->searchstep)){/* account for postecho
  99348. working back one window */
  99349. if(j>=testW)return(1);
  99350. ve->cursor=j;
  99351. if(ve->mark[j/ve->searchstep]){
  99352. if(j>centerW){
  99353. #if 0
  99354. if(j>ve->curmark){
  99355. float *marker=alloca(v->pcm_current*sizeof(*marker));
  99356. int l,m;
  99357. memset(marker,0,sizeof(*marker)*v->pcm_current);
  99358. fprintf(stderr,"mark! seq=%d, cursor:%fs time:%fs\n",
  99359. seq,
  99360. (totalshift+ve->cursor)/44100.,
  99361. (totalshift+j)/44100.);
  99362. _analysis_output_always("pcmL",seq,v->pcm[0],v->pcm_current,0,0,totalshift);
  99363. _analysis_output_always("pcmR",seq,v->pcm[1],v->pcm_current,0,0,totalshift);
  99364. _analysis_output_always("markL",seq,v->pcm[0],j,0,0,totalshift);
  99365. _analysis_output_always("markR",seq,v->pcm[1],j,0,0,totalshift);
  99366. for(m=0;m<VE_BANDS;m++){
  99367. char buf[80];
  99368. sprintf(buf,"delL%d",m);
  99369. for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->filter[m].markers[l]*.1;
  99370. _analysis_output_always(buf,seq,marker,v->pcm_current,0,0,totalshift);
  99371. }
  99372. for(m=0;m<VE_BANDS;m++){
  99373. char buf[80];
  99374. sprintf(buf,"delR%d",m);
  99375. for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->filter[m+VE_BANDS].markers[l]*.1;
  99376. _analysis_output_always(buf,seq,marker,v->pcm_current,0,0,totalshift);
  99377. }
  99378. for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->mark[l]*.4;
  99379. _analysis_output_always("mark",seq,marker,v->pcm_current,0,0,totalshift);
  99380. seq++;
  99381. }
  99382. #endif
  99383. ve->curmark=j;
  99384. if(j>=testW)return(1);
  99385. return(0);
  99386. }
  99387. }
  99388. j+=ve->searchstep;
  99389. }
  99390. }
  99391. return(-1);
  99392. }
  99393. int _ve_envelope_mark(vorbis_dsp_state *v){
  99394. envelope_lookup *ve=((private_state *)(v->backend_state))->ve;
  99395. vorbis_info *vi=v->vi;
  99396. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99397. long centerW=v->centerW;
  99398. long beginW=centerW-ci->blocksizes[v->W]/4;
  99399. long endW=centerW+ci->blocksizes[v->W]/4;
  99400. if(v->W){
  99401. beginW-=ci->blocksizes[v->lW]/4;
  99402. endW+=ci->blocksizes[v->nW]/4;
  99403. }else{
  99404. beginW-=ci->blocksizes[0]/4;
  99405. endW+=ci->blocksizes[0]/4;
  99406. }
  99407. if(ve->curmark>=beginW && ve->curmark<endW)return(1);
  99408. {
  99409. long first=beginW/ve->searchstep;
  99410. long last=endW/ve->searchstep;
  99411. long i;
  99412. for(i=first;i<last;i++)
  99413. if(ve->mark[i])return(1);
  99414. }
  99415. return(0);
  99416. }
  99417. void _ve_envelope_shift(envelope_lookup *e,long shift){
  99418. int smallsize=e->current/e->searchstep+VE_POST; /* adjust for placing marks
  99419. ahead of ve->current */
  99420. int smallshift=shift/e->searchstep;
  99421. memmove(e->mark,e->mark+smallshift,(smallsize-smallshift)*sizeof(*e->mark));
  99422. #if 0
  99423. for(i=0;i<VE_BANDS*e->ch;i++)
  99424. memmove(e->filter[i].markers,
  99425. e->filter[i].markers+smallshift,
  99426. (1024-smallshift)*sizeof(*(*e->filter).markers));
  99427. totalshift+=shift;
  99428. #endif
  99429. e->current-=shift;
  99430. if(e->curmark>=0)
  99431. e->curmark-=shift;
  99432. e->cursor-=shift;
  99433. }
  99434. #endif
  99435. /*** End of inlined file: envelope.c ***/
  99436. /*** Start of inlined file: floor0.c ***/
  99437. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  99438. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  99439. // tasks..
  99440. #if JUCE_MSVC
  99441. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  99442. #endif
  99443. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  99444. #if JUCE_USE_OGGVORBIS
  99445. #include <stdlib.h>
  99446. #include <string.h>
  99447. #include <math.h>
  99448. /*** Start of inlined file: lsp.h ***/
  99449. #ifndef _V_LSP_H_
  99450. #define _V_LSP_H_
  99451. extern int vorbis_lpc_to_lsp(float *lpc,float *lsp,int m);
  99452. extern void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,
  99453. float *lsp,int m,
  99454. float amp,float ampoffset);
  99455. #endif
  99456. /*** End of inlined file: lsp.h ***/
  99457. #include <stdio.h>
  99458. typedef struct {
  99459. int ln;
  99460. int m;
  99461. int **linearmap;
  99462. int n[2];
  99463. vorbis_info_floor0 *vi;
  99464. long bits;
  99465. long frames;
  99466. } vorbis_look_floor0;
  99467. static void floor0_free_info(vorbis_info_floor *i){
  99468. vorbis_info_floor0 *info=(vorbis_info_floor0 *)i;
  99469. if(info){
  99470. memset(info,0,sizeof(*info));
  99471. _ogg_free(info);
  99472. }
  99473. }
  99474. static void floor0_free_look(vorbis_look_floor *i){
  99475. vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
  99476. if(look){
  99477. if(look->linearmap){
  99478. if(look->linearmap[0])_ogg_free(look->linearmap[0]);
  99479. if(look->linearmap[1])_ogg_free(look->linearmap[1]);
  99480. _ogg_free(look->linearmap);
  99481. }
  99482. memset(look,0,sizeof(*look));
  99483. _ogg_free(look);
  99484. }
  99485. }
  99486. static vorbis_info_floor *floor0_unpack (vorbis_info *vi,oggpack_buffer *opb){
  99487. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99488. int j;
  99489. vorbis_info_floor0 *info=(vorbis_info_floor0*)_ogg_malloc(sizeof(*info));
  99490. info->order=oggpack_read(opb,8);
  99491. info->rate=oggpack_read(opb,16);
  99492. info->barkmap=oggpack_read(opb,16);
  99493. info->ampbits=oggpack_read(opb,6);
  99494. info->ampdB=oggpack_read(opb,8);
  99495. info->numbooks=oggpack_read(opb,4)+1;
  99496. if(info->order<1)goto err_out;
  99497. if(info->rate<1)goto err_out;
  99498. if(info->barkmap<1)goto err_out;
  99499. if(info->numbooks<1)goto err_out;
  99500. for(j=0;j<info->numbooks;j++){
  99501. info->books[j]=oggpack_read(opb,8);
  99502. if(info->books[j]<0 || info->books[j]>=ci->books)goto err_out;
  99503. }
  99504. return(info);
  99505. err_out:
  99506. floor0_free_info(info);
  99507. return(NULL);
  99508. }
  99509. static void floor0_map_lazy_init(vorbis_block *vb,
  99510. vorbis_info_floor *infoX,
  99511. vorbis_look_floor0 *look){
  99512. if(!look->linearmap[vb->W]){
  99513. vorbis_dsp_state *vd=vb->vd;
  99514. vorbis_info *vi=vd->vi;
  99515. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99516. vorbis_info_floor0 *info=(vorbis_info_floor0 *)infoX;
  99517. int W=vb->W;
  99518. int n=ci->blocksizes[W]/2,j;
  99519. float scale=look->ln/toBARK(info->rate/2.f);
  99520. look->linearmap[W]=(int*)_ogg_malloc((n+1)*sizeof(**look->linearmap));
  99521. for(j=0;j<n;j++){
  99522. int val=floor( toBARK((info->rate/2.f)/n*j)
  99523. *scale); /* bark numbers represent band edges */
  99524. if(val>=look->ln)val=look->ln-1; /* guard against the approximation */
  99525. look->linearmap[W][j]=val;
  99526. }
  99527. look->linearmap[W][j]=-1;
  99528. look->n[W]=n;
  99529. }
  99530. }
  99531. static vorbis_look_floor *floor0_look(vorbis_dsp_state *vd,
  99532. vorbis_info_floor *i){
  99533. vorbis_info_floor0 *info=(vorbis_info_floor0*)i;
  99534. vorbis_look_floor0 *look=(vorbis_look_floor0*)_ogg_calloc(1,sizeof(*look));
  99535. look->m=info->order;
  99536. look->ln=info->barkmap;
  99537. look->vi=info;
  99538. look->linearmap=(int**)_ogg_calloc(2,sizeof(*look->linearmap));
  99539. return look;
  99540. }
  99541. static void *floor0_inverse1(vorbis_block *vb,vorbis_look_floor *i){
  99542. vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
  99543. vorbis_info_floor0 *info=look->vi;
  99544. int j,k;
  99545. int ampraw=oggpack_read(&vb->opb,info->ampbits);
  99546. if(ampraw>0){ /* also handles the -1 out of data case */
  99547. long maxval=(1<<info->ampbits)-1;
  99548. float amp=(float)ampraw/maxval*info->ampdB;
  99549. int booknum=oggpack_read(&vb->opb,_ilog(info->numbooks));
  99550. if(booknum!=-1 && booknum<info->numbooks){ /* be paranoid */
  99551. codec_setup_info *ci=(codec_setup_info *)vb->vd->vi->codec_setup;
  99552. codebook *b=ci->fullbooks+info->books[booknum];
  99553. float last=0.f;
  99554. float *lsp=(float*)_vorbis_block_alloc(vb,sizeof(*lsp)*(look->m+b->dim+1));
  99555. for(j=0;j<look->m;j+=b->dim)
  99556. if(vorbis_book_decodev_set(b,lsp+j,&vb->opb,b->dim)==-1)goto eop;
  99557. for(j=0;j<look->m;){
  99558. for(k=0;k<b->dim;k++,j++)lsp[j]+=last;
  99559. last=lsp[j-1];
  99560. }
  99561. lsp[look->m]=amp;
  99562. return(lsp);
  99563. }
  99564. }
  99565. eop:
  99566. return(NULL);
  99567. }
  99568. static int floor0_inverse2(vorbis_block *vb,vorbis_look_floor *i,
  99569. void *memo,float *out){
  99570. vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
  99571. vorbis_info_floor0 *info=look->vi;
  99572. floor0_map_lazy_init(vb,info,look);
  99573. if(memo){
  99574. float *lsp=(float *)memo;
  99575. float amp=lsp[look->m];
  99576. vorbis_lsp_to_curve(out,
  99577. look->linearmap[vb->W],
  99578. look->n[vb->W],
  99579. look->ln,
  99580. lsp,look->m,amp,(float)info->ampdB);
  99581. return(1);
  99582. }
  99583. memset(out,0,sizeof(*out)*look->n[vb->W]);
  99584. return(0);
  99585. }
  99586. vorbis_func_floor floor0_exportbundle={
  99587. NULL,&floor0_unpack,&floor0_look,&floor0_free_info,
  99588. &floor0_free_look,&floor0_inverse1,&floor0_inverse2
  99589. };
  99590. #endif
  99591. /*** End of inlined file: floor0.c ***/
  99592. /*** Start of inlined file: floor1.c ***/
  99593. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  99594. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  99595. // tasks..
  99596. #if JUCE_MSVC
  99597. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  99598. #endif
  99599. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  99600. #if JUCE_USE_OGGVORBIS
  99601. #include <stdlib.h>
  99602. #include <string.h>
  99603. #include <math.h>
  99604. #include <stdio.h>
  99605. #define floor1_rangedB 140 /* floor 1 fixed at -140dB to 0dB range */
  99606. typedef struct {
  99607. int sorted_index[VIF_POSIT+2];
  99608. int forward_index[VIF_POSIT+2];
  99609. int reverse_index[VIF_POSIT+2];
  99610. int hineighbor[VIF_POSIT];
  99611. int loneighbor[VIF_POSIT];
  99612. int posts;
  99613. int n;
  99614. int quant_q;
  99615. vorbis_info_floor1 *vi;
  99616. long phrasebits;
  99617. long postbits;
  99618. long frames;
  99619. } vorbis_look_floor1;
  99620. typedef struct lsfit_acc{
  99621. long x0;
  99622. long x1;
  99623. long xa;
  99624. long ya;
  99625. long x2a;
  99626. long y2a;
  99627. long xya;
  99628. long an;
  99629. } lsfit_acc;
  99630. static void floor1_free_info(vorbis_info_floor *i){
  99631. vorbis_info_floor1 *info=(vorbis_info_floor1 *)i;
  99632. if(info){
  99633. memset(info,0,sizeof(*info));
  99634. _ogg_free(info);
  99635. }
  99636. }
  99637. static void floor1_free_look(vorbis_look_floor *i){
  99638. vorbis_look_floor1 *look=(vorbis_look_floor1 *)i;
  99639. if(look){
  99640. memset(look,0,sizeof(*look));
  99641. _ogg_free(look);
  99642. }
  99643. }
  99644. static void floor1_pack (vorbis_info_floor *i,oggpack_buffer *opb){
  99645. vorbis_info_floor1 *info=(vorbis_info_floor1 *)i;
  99646. int j,k;
  99647. int count=0;
  99648. int rangebits;
  99649. int maxposit=info->postlist[1];
  99650. int maxclass=-1;
  99651. oggpack_write(opb,info->partitions,5); /* only 0 to 31 legal */
  99652. for(j=0;j<info->partitions;j++){
  99653. oggpack_write(opb,info->partitionclass[j],4); /* only 0 to 15 legal */
  99654. if(maxclass<info->partitionclass[j])maxclass=info->partitionclass[j];
  99655. }
  99656. for(j=0;j<maxclass+1;j++){
  99657. oggpack_write(opb,info->class_dim[j]-1,3); /* 1 to 8 */
  99658. oggpack_write(opb,info->class_subs[j],2); /* 0 to 3 */
  99659. if(info->class_subs[j])oggpack_write(opb,info->class_book[j],8);
  99660. for(k=0;k<(1<<info->class_subs[j]);k++)
  99661. oggpack_write(opb,info->class_subbook[j][k]+1,8);
  99662. }
  99663. oggpack_write(opb,info->mult-1,2); /* only 1,2,3,4 legal now */
  99664. oggpack_write(opb,ilog2(maxposit),4);
  99665. rangebits=ilog2(maxposit);
  99666. for(j=0,k=0;j<info->partitions;j++){
  99667. count+=info->class_dim[info->partitionclass[j]];
  99668. for(;k<count;k++)
  99669. oggpack_write(opb,info->postlist[k+2],rangebits);
  99670. }
  99671. }
  99672. static vorbis_info_floor *floor1_unpack (vorbis_info *vi,oggpack_buffer *opb){
  99673. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99674. int j,k,count=0,maxclass=-1,rangebits;
  99675. vorbis_info_floor1 *info=(vorbis_info_floor1*)_ogg_calloc(1,sizeof(*info));
  99676. info->partitions=oggpack_read(opb,5); /* only 0 to 31 legal */
  99677. for(j=0;j<info->partitions;j++){
  99678. info->partitionclass[j]=oggpack_read(opb,4); /* only 0 to 15 legal */
  99679. if(maxclass<info->partitionclass[j])maxclass=info->partitionclass[j];
  99680. }
  99681. for(j=0;j<maxclass+1;j++){
  99682. info->class_dim[j]=oggpack_read(opb,3)+1; /* 1 to 8 */
  99683. info->class_subs[j]=oggpack_read(opb,2); /* 0,1,2,3 bits */
  99684. if(info->class_subs[j]<0)
  99685. goto err_out;
  99686. if(info->class_subs[j])info->class_book[j]=oggpack_read(opb,8);
  99687. if(info->class_book[j]<0 || info->class_book[j]>=ci->books)
  99688. goto err_out;
  99689. for(k=0;k<(1<<info->class_subs[j]);k++){
  99690. info->class_subbook[j][k]=oggpack_read(opb,8)-1;
  99691. if(info->class_subbook[j][k]<-1 || info->class_subbook[j][k]>=ci->books)
  99692. goto err_out;
  99693. }
  99694. }
  99695. info->mult=oggpack_read(opb,2)+1; /* only 1,2,3,4 legal now */
  99696. rangebits=oggpack_read(opb,4);
  99697. for(j=0,k=0;j<info->partitions;j++){
  99698. count+=info->class_dim[info->partitionclass[j]];
  99699. for(;k<count;k++){
  99700. int t=info->postlist[k+2]=oggpack_read(opb,rangebits);
  99701. if(t<0 || t>=(1<<rangebits))
  99702. goto err_out;
  99703. }
  99704. }
  99705. info->postlist[0]=0;
  99706. info->postlist[1]=1<<rangebits;
  99707. return(info);
  99708. err_out:
  99709. floor1_free_info(info);
  99710. return(NULL);
  99711. }
  99712. static int icomp(const void *a,const void *b){
  99713. return(**(int **)a-**(int **)b);
  99714. }
  99715. static vorbis_look_floor *floor1_look(vorbis_dsp_state *vd,
  99716. vorbis_info_floor *in){
  99717. int *sortpointer[VIF_POSIT+2];
  99718. vorbis_info_floor1 *info=(vorbis_info_floor1*)in;
  99719. vorbis_look_floor1 *look=(vorbis_look_floor1*)_ogg_calloc(1,sizeof(*look));
  99720. int i,j,n=0;
  99721. look->vi=info;
  99722. look->n=info->postlist[1];
  99723. for(i=0;i<info->partitions;i++)n+=info->class_dim[info->partitionclass[i]];
  99724. n+=2;
  99725. look->posts=n;
  99726. for(i=0;i<n;i++)sortpointer[i]=info->postlist+i;
  99727. qsort(sortpointer,n,sizeof(*sortpointer),icomp);
  99728. for(i=0;i<n;i++)look->forward_index[i]=sortpointer[i]-info->postlist;
  99729. for(i=0;i<n;i++)look->reverse_index[look->forward_index[i]]=i;
  99730. for(i=0;i<n;i++)look->sorted_index[i]=info->postlist[look->forward_index[i]];
  99731. switch(info->mult){
  99732. case 1: /* 1024 -> 256 */
  99733. look->quant_q=256;
  99734. break;
  99735. case 2: /* 1024 -> 128 */
  99736. look->quant_q=128;
  99737. break;
  99738. case 3: /* 1024 -> 86 */
  99739. look->quant_q=86;
  99740. break;
  99741. case 4: /* 1024 -> 64 */
  99742. look->quant_q=64;
  99743. break;
  99744. }
  99745. for(i=0;i<n-2;i++){
  99746. int lo=0;
  99747. int hi=1;
  99748. int lx=0;
  99749. int hx=look->n;
  99750. int currentx=info->postlist[i+2];
  99751. for(j=0;j<i+2;j++){
  99752. int x=info->postlist[j];
  99753. if(x>lx && x<currentx){
  99754. lo=j;
  99755. lx=x;
  99756. }
  99757. if(x<hx && x>currentx){
  99758. hi=j;
  99759. hx=x;
  99760. }
  99761. }
  99762. look->loneighbor[i]=lo;
  99763. look->hineighbor[i]=hi;
  99764. }
  99765. return(look);
  99766. }
  99767. static int render_point(int x0,int x1,int y0,int y1,int x){
  99768. y0&=0x7fff; /* mask off flag */
  99769. y1&=0x7fff;
  99770. {
  99771. int dy=y1-y0;
  99772. int adx=x1-x0;
  99773. int ady=abs(dy);
  99774. int err=ady*(x-x0);
  99775. int off=err/adx;
  99776. if(dy<0)return(y0-off);
  99777. return(y0+off);
  99778. }
  99779. }
  99780. static int vorbis_dBquant(const float *x){
  99781. int i= *x*7.3142857f+1023.5f;
  99782. if(i>1023)return(1023);
  99783. if(i<0)return(0);
  99784. return i;
  99785. }
  99786. static float FLOOR1_fromdB_LOOKUP[256]={
  99787. 1.0649863e-07F, 1.1341951e-07F, 1.2079015e-07F, 1.2863978e-07F,
  99788. 1.3699951e-07F, 1.4590251e-07F, 1.5538408e-07F, 1.6548181e-07F,
  99789. 1.7623575e-07F, 1.8768855e-07F, 1.9988561e-07F, 2.128753e-07F,
  99790. 2.2670913e-07F, 2.4144197e-07F, 2.5713223e-07F, 2.7384213e-07F,
  99791. 2.9163793e-07F, 3.1059021e-07F, 3.3077411e-07F, 3.5226968e-07F,
  99792. 3.7516214e-07F, 3.9954229e-07F, 4.2550680e-07F, 4.5315863e-07F,
  99793. 4.8260743e-07F, 5.1396998e-07F, 5.4737065e-07F, 5.8294187e-07F,
  99794. 6.2082472e-07F, 6.6116941e-07F, 7.0413592e-07F, 7.4989464e-07F,
  99795. 7.9862701e-07F, 8.5052630e-07F, 9.0579828e-07F, 9.6466216e-07F,
  99796. 1.0273513e-06F, 1.0941144e-06F, 1.1652161e-06F, 1.2409384e-06F,
  99797. 1.3215816e-06F, 1.4074654e-06F, 1.4989305e-06F, 1.5963394e-06F,
  99798. 1.7000785e-06F, 1.8105592e-06F, 1.9282195e-06F, 2.0535261e-06F,
  99799. 2.1869758e-06F, 2.3290978e-06F, 2.4804557e-06F, 2.6416497e-06F,
  99800. 2.8133190e-06F, 2.9961443e-06F, 3.1908506e-06F, 3.3982101e-06F,
  99801. 3.6190449e-06F, 3.8542308e-06F, 4.1047004e-06F, 4.3714470e-06F,
  99802. 4.6555282e-06F, 4.9580707e-06F, 5.2802740e-06F, 5.6234160e-06F,
  99803. 5.9888572e-06F, 6.3780469e-06F, 6.7925283e-06F, 7.2339451e-06F,
  99804. 7.7040476e-06F, 8.2047000e-06F, 8.7378876e-06F, 9.3057248e-06F,
  99805. 9.9104632e-06F, 1.0554501e-05F, 1.1240392e-05F, 1.1970856e-05F,
  99806. 1.2748789e-05F, 1.3577278e-05F, 1.4459606e-05F, 1.5399272e-05F,
  99807. 1.6400004e-05F, 1.7465768e-05F, 1.8600792e-05F, 1.9809576e-05F,
  99808. 2.1096914e-05F, 2.2467911e-05F, 2.3928002e-05F, 2.5482978e-05F,
  99809. 2.7139006e-05F, 2.8902651e-05F, 3.0780908e-05F, 3.2781225e-05F,
  99810. 3.4911534e-05F, 3.7180282e-05F, 3.9596466e-05F, 4.2169667e-05F,
  99811. 4.4910090e-05F, 4.7828601e-05F, 5.0936773e-05F, 5.4246931e-05F,
  99812. 5.7772202e-05F, 6.1526565e-05F, 6.5524908e-05F, 6.9783085e-05F,
  99813. 7.4317983e-05F, 7.9147585e-05F, 8.4291040e-05F, 8.9768747e-05F,
  99814. 9.5602426e-05F, 0.00010181521F, 0.00010843174F, 0.00011547824F,
  99815. 0.00012298267F, 0.00013097477F, 0.00013948625F, 0.00014855085F,
  99816. 0.00015820453F, 0.00016848555F, 0.00017943469F, 0.00019109536F,
  99817. 0.00020351382F, 0.00021673929F, 0.00023082423F, 0.00024582449F,
  99818. 0.00026179955F, 0.00027881276F, 0.00029693158F, 0.00031622787F,
  99819. 0.00033677814F, 0.00035866388F, 0.00038197188F, 0.00040679456F,
  99820. 0.00043323036F, 0.00046138411F, 0.00049136745F, 0.00052329927F,
  99821. 0.00055730621F, 0.00059352311F, 0.00063209358F, 0.00067317058F,
  99822. 0.00071691700F, 0.00076350630F, 0.00081312324F, 0.00086596457F,
  99823. 0.00092223983F, 0.00098217216F, 0.0010459992F, 0.0011139742F,
  99824. 0.0011863665F, 0.0012634633F, 0.0013455702F, 0.0014330129F,
  99825. 0.0015261382F, 0.0016253153F, 0.0017309374F, 0.0018434235F,
  99826. 0.0019632195F, 0.0020908006F, 0.0022266726F, 0.0023713743F,
  99827. 0.0025254795F, 0.0026895994F, 0.0028643847F, 0.0030505286F,
  99828. 0.0032487691F, 0.0034598925F, 0.0036847358F, 0.0039241906F,
  99829. 0.0041792066F, 0.0044507950F, 0.0047400328F, 0.0050480668F,
  99830. 0.0053761186F, 0.0057254891F, 0.0060975636F, 0.0064938176F,
  99831. 0.0069158225F, 0.0073652516F, 0.0078438871F, 0.0083536271F,
  99832. 0.0088964928F, 0.009474637F, 0.010090352F, 0.010746080F,
  99833. 0.011444421F, 0.012188144F, 0.012980198F, 0.013823725F,
  99834. 0.014722068F, 0.015678791F, 0.016697687F, 0.017782797F,
  99835. 0.018938423F, 0.020169149F, 0.021479854F, 0.022875735F,
  99836. 0.024362330F, 0.025945531F, 0.027631618F, 0.029427276F,
  99837. 0.031339626F, 0.033376252F, 0.035545228F, 0.037855157F,
  99838. 0.040315199F, 0.042935108F, 0.045725273F, 0.048696758F,
  99839. 0.051861348F, 0.055231591F, 0.058820850F, 0.062643361F,
  99840. 0.066714279F, 0.071049749F, 0.075666962F, 0.080584227F,
  99841. 0.085821044F, 0.091398179F, 0.097337747F, 0.10366330F,
  99842. 0.11039993F, 0.11757434F, 0.12521498F, 0.13335215F,
  99843. 0.14201813F, 0.15124727F, 0.16107617F, 0.17154380F,
  99844. 0.18269168F, 0.19456402F, 0.20720788F, 0.22067342F,
  99845. 0.23501402F, 0.25028656F, 0.26655159F, 0.28387361F,
  99846. 0.30232132F, 0.32196786F, 0.34289114F, 0.36517414F,
  99847. 0.38890521F, 0.41417847F, 0.44109412F, 0.46975890F,
  99848. 0.50028648F, 0.53279791F, 0.56742212F, 0.60429640F,
  99849. 0.64356699F, 0.68538959F, 0.72993007F, 0.77736504F,
  99850. 0.82788260F, 0.88168307F, 0.9389798F, 1.F,
  99851. };
  99852. static void render_line(int x0,int x1,int y0,int y1,float *d){
  99853. int dy=y1-y0;
  99854. int adx=x1-x0;
  99855. int ady=abs(dy);
  99856. int base=dy/adx;
  99857. int sy=(dy<0?base-1:base+1);
  99858. int x=x0;
  99859. int y=y0;
  99860. int err=0;
  99861. ady-=abs(base*adx);
  99862. d[x]*=FLOOR1_fromdB_LOOKUP[y];
  99863. while(++x<x1){
  99864. err=err+ady;
  99865. if(err>=adx){
  99866. err-=adx;
  99867. y+=sy;
  99868. }else{
  99869. y+=base;
  99870. }
  99871. d[x]*=FLOOR1_fromdB_LOOKUP[y];
  99872. }
  99873. }
  99874. static void render_line0(int x0,int x1,int y0,int y1,int *d){
  99875. int dy=y1-y0;
  99876. int adx=x1-x0;
  99877. int ady=abs(dy);
  99878. int base=dy/adx;
  99879. int sy=(dy<0?base-1:base+1);
  99880. int x=x0;
  99881. int y=y0;
  99882. int err=0;
  99883. ady-=abs(base*adx);
  99884. d[x]=y;
  99885. while(++x<x1){
  99886. err=err+ady;
  99887. if(err>=adx){
  99888. err-=adx;
  99889. y+=sy;
  99890. }else{
  99891. y+=base;
  99892. }
  99893. d[x]=y;
  99894. }
  99895. }
  99896. static int accumulate_fit(const float *flr,const float *mdct,
  99897. int x0, int x1,lsfit_acc *a,
  99898. int n,vorbis_info_floor1 *info){
  99899. long i;
  99900. 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;
  99901. memset(a,0,sizeof(*a));
  99902. a->x0=x0;
  99903. a->x1=x1;
  99904. if(x1>=n)x1=n-1;
  99905. for(i=x0;i<=x1;i++){
  99906. int quantized=vorbis_dBquant(flr+i);
  99907. if(quantized){
  99908. if(mdct[i]+info->twofitatten>=flr[i]){
  99909. xa += i;
  99910. ya += quantized;
  99911. x2a += i*i;
  99912. y2a += quantized*quantized;
  99913. xya += i*quantized;
  99914. na++;
  99915. }else{
  99916. xb += i;
  99917. yb += quantized;
  99918. x2b += i*i;
  99919. y2b += quantized*quantized;
  99920. xyb += i*quantized;
  99921. nb++;
  99922. }
  99923. }
  99924. }
  99925. xb+=xa;
  99926. yb+=ya;
  99927. x2b+=x2a;
  99928. y2b+=y2a;
  99929. xyb+=xya;
  99930. nb+=na;
  99931. {
  99932. int weight=nb*info->twofitweight/(na+1);
  99933. a->xa=xa*weight+xb;
  99934. a->ya=ya*weight+yb;
  99935. a->x2a=x2a*weight+x2b;
  99936. a->y2a=y2a*weight+y2b;
  99937. a->xya=xya*weight+xyb;
  99938. a->an=na*weight+nb;
  99939. }
  99940. return(na);
  99941. }
  99942. static void fit_line(lsfit_acc *a,int fits,int *y0,int *y1){
  99943. long x=0,y=0,x2=0,y2=0,xy=0,an=0,i;
  99944. long x0=a[0].x0;
  99945. long x1=a[fits-1].x1;
  99946. for(i=0;i<fits;i++){
  99947. x+=a[i].xa;
  99948. y+=a[i].ya;
  99949. x2+=a[i].x2a;
  99950. y2+=a[i].y2a;
  99951. xy+=a[i].xya;
  99952. an+=a[i].an;
  99953. }
  99954. if(*y0>=0){
  99955. x+= x0;
  99956. y+= *y0;
  99957. x2+= x0 * x0;
  99958. y2+= *y0 * *y0;
  99959. xy+= *y0 * x0;
  99960. an++;
  99961. }
  99962. if(*y1>=0){
  99963. x+= x1;
  99964. y+= *y1;
  99965. x2+= x1 * x1;
  99966. y2+= *y1 * *y1;
  99967. xy+= *y1 * x1;
  99968. an++;
  99969. }
  99970. if(an){
  99971. double fx=x;
  99972. double fy=y;
  99973. double fx2=x2;
  99974. double fxy=xy;
  99975. double denom=1./(an*fx2-fx*fx);
  99976. double a=(fy*fx2-fxy*fx)*denom;
  99977. double b=(an*fxy-fx*fy)*denom;
  99978. *y0=rint(a+b*x0);
  99979. *y1=rint(a+b*x1);
  99980. if(*y0>1023)*y0=1023;
  99981. if(*y1>1023)*y1=1023;
  99982. if(*y0<0)*y0=0;
  99983. if(*y1<0)*y1=0;
  99984. }else{
  99985. *y0=0;
  99986. *y1=0;
  99987. }
  99988. }
  99989. static int inspect_error(int x0,int x1,int y0,int y1,const float *mask,
  99990. const float *mdct,
  99991. vorbis_info_floor1 *info){
  99992. int dy=y1-y0;
  99993. int adx=x1-x0;
  99994. int ady=abs(dy);
  99995. int base=dy/adx;
  99996. int sy=(dy<0?base-1:base+1);
  99997. int x=x0;
  99998. int y=y0;
  99999. int err=0;
  100000. int val=vorbis_dBquant(mask+x);
  100001. int mse=0;
  100002. int n=0;
  100003. ady-=abs(base*adx);
  100004. mse=(y-val);
  100005. mse*=mse;
  100006. n++;
  100007. if(mdct[x]+info->twofitatten>=mask[x]){
  100008. if(y+info->maxover<val)return(1);
  100009. if(y-info->maxunder>val)return(1);
  100010. }
  100011. while(++x<x1){
  100012. err=err+ady;
  100013. if(err>=adx){
  100014. err-=adx;
  100015. y+=sy;
  100016. }else{
  100017. y+=base;
  100018. }
  100019. val=vorbis_dBquant(mask+x);
  100020. mse+=((y-val)*(y-val));
  100021. n++;
  100022. if(mdct[x]+info->twofitatten>=mask[x]){
  100023. if(val){
  100024. if(y+info->maxover<val)return(1);
  100025. if(y-info->maxunder>val)return(1);
  100026. }
  100027. }
  100028. }
  100029. if(info->maxover*info->maxover/n>info->maxerr)return(0);
  100030. if(info->maxunder*info->maxunder/n>info->maxerr)return(0);
  100031. if(mse/n>info->maxerr)return(1);
  100032. return(0);
  100033. }
  100034. static int post_Y(int *A,int *B,int pos){
  100035. if(A[pos]<0)
  100036. return B[pos];
  100037. if(B[pos]<0)
  100038. return A[pos];
  100039. return (A[pos]+B[pos])>>1;
  100040. }
  100041. int *floor1_fit(vorbis_block *vb,void *look_,
  100042. const float *logmdct, /* in */
  100043. const float *logmask){
  100044. long i,j;
  100045. vorbis_look_floor1 *look = (vorbis_look_floor1*) look_;
  100046. vorbis_info_floor1 *info=look->vi;
  100047. long n=look->n;
  100048. long posts=look->posts;
  100049. long nonzero=0;
  100050. lsfit_acc fits[VIF_POSIT+1];
  100051. int fit_valueA[VIF_POSIT+2]; /* index by range list position */
  100052. int fit_valueB[VIF_POSIT+2]; /* index by range list position */
  100053. int loneighbor[VIF_POSIT+2]; /* sorted index of range list position (+2) */
  100054. int hineighbor[VIF_POSIT+2];
  100055. int *output=NULL;
  100056. int memo[VIF_POSIT+2];
  100057. for(i=0;i<posts;i++)fit_valueA[i]=-200; /* mark all unused */
  100058. for(i=0;i<posts;i++)fit_valueB[i]=-200; /* mark all unused */
  100059. for(i=0;i<posts;i++)loneighbor[i]=0; /* 0 for the implicit 0 post */
  100060. for(i=0;i<posts;i++)hineighbor[i]=1; /* 1 for the implicit post at n */
  100061. for(i=0;i<posts;i++)memo[i]=-1; /* no neighbor yet */
  100062. if(posts==0){
  100063. nonzero+=accumulate_fit(logmask,logmdct,0,n,fits,n,info);
  100064. }else{
  100065. for(i=0;i<posts-1;i++)
  100066. nonzero+=accumulate_fit(logmask,logmdct,look->sorted_index[i],
  100067. look->sorted_index[i+1],fits+i,
  100068. n,info);
  100069. }
  100070. if(nonzero){
  100071. int y0=-200;
  100072. int y1=-200;
  100073. fit_line(fits,posts-1,&y0,&y1);
  100074. fit_valueA[0]=y0;
  100075. fit_valueB[0]=y0;
  100076. fit_valueB[1]=y1;
  100077. fit_valueA[1]=y1;
  100078. for(i=2;i<posts;i++){
  100079. int sortpos=look->reverse_index[i];
  100080. int ln=loneighbor[sortpos];
  100081. int hn=hineighbor[sortpos];
  100082. if(memo[ln]!=hn){
  100083. int lsortpos=look->reverse_index[ln];
  100084. int hsortpos=look->reverse_index[hn];
  100085. memo[ln]=hn;
  100086. {
  100087. int lx=info->postlist[ln];
  100088. int hx=info->postlist[hn];
  100089. int ly=post_Y(fit_valueA,fit_valueB,ln);
  100090. int hy=post_Y(fit_valueA,fit_valueB,hn);
  100091. if(ly==-1 || hy==-1){
  100092. exit(1);
  100093. }
  100094. if(inspect_error(lx,hx,ly,hy,logmask,logmdct,info)){
  100095. int ly0=-200;
  100096. int ly1=-200;
  100097. int hy0=-200;
  100098. int hy1=-200;
  100099. fit_line(fits+lsortpos,sortpos-lsortpos,&ly0,&ly1);
  100100. fit_line(fits+sortpos,hsortpos-sortpos,&hy0,&hy1);
  100101. fit_valueB[ln]=ly0;
  100102. if(ln==0)fit_valueA[ln]=ly0;
  100103. fit_valueA[i]=ly1;
  100104. fit_valueB[i]=hy0;
  100105. fit_valueA[hn]=hy1;
  100106. if(hn==1)fit_valueB[hn]=hy1;
  100107. if(ly1>=0 || hy0>=0){
  100108. for(j=sortpos-1;j>=0;j--)
  100109. if(hineighbor[j]==hn)
  100110. hineighbor[j]=i;
  100111. else
  100112. break;
  100113. for(j=sortpos+1;j<posts;j++)
  100114. if(loneighbor[j]==ln)
  100115. loneighbor[j]=i;
  100116. else
  100117. break;
  100118. }
  100119. }else{
  100120. fit_valueA[i]=-200;
  100121. fit_valueB[i]=-200;
  100122. }
  100123. }
  100124. }
  100125. }
  100126. output=(int*)_vorbis_block_alloc(vb,sizeof(*output)*posts);
  100127. output[0]=post_Y(fit_valueA,fit_valueB,0);
  100128. output[1]=post_Y(fit_valueA,fit_valueB,1);
  100129. for(i=2;i<posts;i++){
  100130. int ln=look->loneighbor[i-2];
  100131. int hn=look->hineighbor[i-2];
  100132. int x0=info->postlist[ln];
  100133. int x1=info->postlist[hn];
  100134. int y0=output[ln];
  100135. int y1=output[hn];
  100136. int predicted=render_point(x0,x1,y0,y1,info->postlist[i]);
  100137. int vx=post_Y(fit_valueA,fit_valueB,i);
  100138. if(vx>=0 && predicted!=vx){
  100139. output[i]=vx;
  100140. }else{
  100141. output[i]= predicted|0x8000;
  100142. }
  100143. }
  100144. }
  100145. return(output);
  100146. }
  100147. int *floor1_interpolate_fit(vorbis_block *vb,void *look_,
  100148. int *A,int *B,
  100149. int del){
  100150. long i;
  100151. vorbis_look_floor1* look = (vorbis_look_floor1*) look_;
  100152. long posts=look->posts;
  100153. int *output=NULL;
  100154. if(A && B){
  100155. output=(int*)_vorbis_block_alloc(vb,sizeof(*output)*posts);
  100156. for(i=0;i<posts;i++){
  100157. output[i]=((65536-del)*(A[i]&0x7fff)+del*(B[i]&0x7fff)+32768)>>16;
  100158. if(A[i]&0x8000 && B[i]&0x8000)output[i]|=0x8000;
  100159. }
  100160. }
  100161. return(output);
  100162. }
  100163. int floor1_encode(oggpack_buffer *opb,vorbis_block *vb,
  100164. void*look_,
  100165. int *post,int *ilogmask){
  100166. long i,j;
  100167. vorbis_look_floor1 *look = (vorbis_look_floor1 *) look_;
  100168. vorbis_info_floor1 *info=look->vi;
  100169. long posts=look->posts;
  100170. codec_setup_info *ci=(codec_setup_info*)vb->vd->vi->codec_setup;
  100171. int out[VIF_POSIT+2];
  100172. static_codebook **sbooks=ci->book_param;
  100173. codebook *books=ci->fullbooks;
  100174. static long seq=0;
  100175. if(post){
  100176. for(i=0;i<posts;i++){
  100177. int val=post[i]&0x7fff;
  100178. switch(info->mult){
  100179. case 1: /* 1024 -> 256 */
  100180. val>>=2;
  100181. break;
  100182. case 2: /* 1024 -> 128 */
  100183. val>>=3;
  100184. break;
  100185. case 3: /* 1024 -> 86 */
  100186. val/=12;
  100187. break;
  100188. case 4: /* 1024 -> 64 */
  100189. val>>=4;
  100190. break;
  100191. }
  100192. post[i]=val | (post[i]&0x8000);
  100193. }
  100194. out[0]=post[0];
  100195. out[1]=post[1];
  100196. for(i=2;i<posts;i++){
  100197. int ln=look->loneighbor[i-2];
  100198. int hn=look->hineighbor[i-2];
  100199. int x0=info->postlist[ln];
  100200. int x1=info->postlist[hn];
  100201. int y0=post[ln];
  100202. int y1=post[hn];
  100203. int predicted=render_point(x0,x1,y0,y1,info->postlist[i]);
  100204. if((post[i]&0x8000) || (predicted==post[i])){
  100205. post[i]=predicted|0x8000; /* in case there was roundoff jitter
  100206. in interpolation */
  100207. out[i]=0;
  100208. }else{
  100209. int headroom=(look->quant_q-predicted<predicted?
  100210. look->quant_q-predicted:predicted);
  100211. int val=post[i]-predicted;
  100212. if(val<0)
  100213. if(val<-headroom)
  100214. val=headroom-val-1;
  100215. else
  100216. val=-1-(val<<1);
  100217. else
  100218. if(val>=headroom)
  100219. val= val+headroom;
  100220. else
  100221. val<<=1;
  100222. out[i]=val;
  100223. post[ln]&=0x7fff;
  100224. post[hn]&=0x7fff;
  100225. }
  100226. }
  100227. oggpack_write(opb,1,1);
  100228. look->frames++;
  100229. look->postbits+=ilog(look->quant_q-1)*2;
  100230. oggpack_write(opb,out[0],ilog(look->quant_q-1));
  100231. oggpack_write(opb,out[1],ilog(look->quant_q-1));
  100232. for(i=0,j=2;i<info->partitions;i++){
  100233. int classx=info->partitionclass[i];
  100234. int cdim=info->class_dim[classx];
  100235. int csubbits=info->class_subs[classx];
  100236. int csub=1<<csubbits;
  100237. int bookas[8]={0,0,0,0,0,0,0,0};
  100238. int cval=0;
  100239. int cshift=0;
  100240. int k,l;
  100241. if(csubbits){
  100242. int maxval[8];
  100243. for(k=0;k<csub;k++){
  100244. int booknum=info->class_subbook[classx][k];
  100245. if(booknum<0){
  100246. maxval[k]=1;
  100247. }else{
  100248. maxval[k]=sbooks[info->class_subbook[classx][k]]->entries;
  100249. }
  100250. }
  100251. for(k=0;k<cdim;k++){
  100252. for(l=0;l<csub;l++){
  100253. int val=out[j+k];
  100254. if(val<maxval[l]){
  100255. bookas[k]=l;
  100256. break;
  100257. }
  100258. }
  100259. cval|= bookas[k]<<cshift;
  100260. cshift+=csubbits;
  100261. }
  100262. look->phrasebits+=
  100263. vorbis_book_encode(books+info->class_book[classx],cval,opb);
  100264. #ifdef TRAIN_FLOOR1
  100265. {
  100266. FILE *of;
  100267. char buffer[80];
  100268. sprintf(buffer,"line_%dx%ld_class%d.vqd",
  100269. vb->pcmend/2,posts-2,class);
  100270. of=fopen(buffer,"a");
  100271. fprintf(of,"%d\n",cval);
  100272. fclose(of);
  100273. }
  100274. #endif
  100275. }
  100276. for(k=0;k<cdim;k++){
  100277. int book=info->class_subbook[classx][bookas[k]];
  100278. if(book>=0){
  100279. if(out[j+k]<(books+book)->entries)
  100280. look->postbits+=vorbis_book_encode(books+book,
  100281. out[j+k],opb);
  100282. #ifdef TRAIN_FLOOR1
  100283. {
  100284. FILE *of;
  100285. char buffer[80];
  100286. sprintf(buffer,"line_%dx%ld_%dsub%d.vqd",
  100287. vb->pcmend/2,posts-2,class,bookas[k]);
  100288. of=fopen(buffer,"a");
  100289. fprintf(of,"%d\n",out[j+k]);
  100290. fclose(of);
  100291. }
  100292. #endif
  100293. }
  100294. }
  100295. j+=cdim;
  100296. }
  100297. {
  100298. int hx=0;
  100299. int lx=0;
  100300. int ly=post[0]*info->mult;
  100301. for(j=1;j<look->posts;j++){
  100302. int current=look->forward_index[j];
  100303. int hy=post[current]&0x7fff;
  100304. if(hy==post[current]){
  100305. hy*=info->mult;
  100306. hx=info->postlist[current];
  100307. render_line0(lx,hx,ly,hy,ilogmask);
  100308. lx=hx;
  100309. ly=hy;
  100310. }
  100311. }
  100312. for(j=hx;j<vb->pcmend/2;j++)ilogmask[j]=ly; /* be certain */
  100313. seq++;
  100314. return(1);
  100315. }
  100316. }else{
  100317. oggpack_write(opb,0,1);
  100318. memset(ilogmask,0,vb->pcmend/2*sizeof(*ilogmask));
  100319. seq++;
  100320. return(0);
  100321. }
  100322. }
  100323. static void *floor1_inverse1(vorbis_block *vb,vorbis_look_floor *in){
  100324. vorbis_look_floor1 *look=(vorbis_look_floor1 *)in;
  100325. vorbis_info_floor1 *info=look->vi;
  100326. codec_setup_info *ci=(codec_setup_info*)vb->vd->vi->codec_setup;
  100327. int i,j,k;
  100328. codebook *books=ci->fullbooks;
  100329. if(oggpack_read(&vb->opb,1)==1){
  100330. int *fit_value=(int*)_vorbis_block_alloc(vb,(look->posts)*sizeof(*fit_value));
  100331. fit_value[0]=oggpack_read(&vb->opb,ilog(look->quant_q-1));
  100332. fit_value[1]=oggpack_read(&vb->opb,ilog(look->quant_q-1));
  100333. for(i=0,j=2;i<info->partitions;i++){
  100334. int classx=info->partitionclass[i];
  100335. int cdim=info->class_dim[classx];
  100336. int csubbits=info->class_subs[classx];
  100337. int csub=1<<csubbits;
  100338. int cval=0;
  100339. if(csubbits){
  100340. cval=vorbis_book_decode(books+info->class_book[classx],&vb->opb);
  100341. if(cval==-1)goto eop;
  100342. }
  100343. for(k=0;k<cdim;k++){
  100344. int book=info->class_subbook[classx][cval&(csub-1)];
  100345. cval>>=csubbits;
  100346. if(book>=0){
  100347. if((fit_value[j+k]=vorbis_book_decode(books+book,&vb->opb))==-1)
  100348. goto eop;
  100349. }else{
  100350. fit_value[j+k]=0;
  100351. }
  100352. }
  100353. j+=cdim;
  100354. }
  100355. for(i=2;i<look->posts;i++){
  100356. int predicted=render_point(info->postlist[look->loneighbor[i-2]],
  100357. info->postlist[look->hineighbor[i-2]],
  100358. fit_value[look->loneighbor[i-2]],
  100359. fit_value[look->hineighbor[i-2]],
  100360. info->postlist[i]);
  100361. int hiroom=look->quant_q-predicted;
  100362. int loroom=predicted;
  100363. int room=(hiroom<loroom?hiroom:loroom)<<1;
  100364. int val=fit_value[i];
  100365. if(val){
  100366. if(val>=room){
  100367. if(hiroom>loroom){
  100368. val = val-loroom;
  100369. }else{
  100370. val = -1-(val-hiroom);
  100371. }
  100372. }else{
  100373. if(val&1){
  100374. val= -((val+1)>>1);
  100375. }else{
  100376. val>>=1;
  100377. }
  100378. }
  100379. fit_value[i]=val+predicted;
  100380. fit_value[look->loneighbor[i-2]]&=0x7fff;
  100381. fit_value[look->hineighbor[i-2]]&=0x7fff;
  100382. }else{
  100383. fit_value[i]=predicted|0x8000;
  100384. }
  100385. }
  100386. return(fit_value);
  100387. }
  100388. eop:
  100389. return(NULL);
  100390. }
  100391. static int floor1_inverse2(vorbis_block *vb,vorbis_look_floor *in,void *memo,
  100392. float *out){
  100393. vorbis_look_floor1 *look=(vorbis_look_floor1 *)in;
  100394. vorbis_info_floor1 *info=look->vi;
  100395. codec_setup_info *ci=(codec_setup_info*)vb->vd->vi->codec_setup;
  100396. int n=ci->blocksizes[vb->W]/2;
  100397. int j;
  100398. if(memo){
  100399. int *fit_value=(int *)memo;
  100400. int hx=0;
  100401. int lx=0;
  100402. int ly=fit_value[0]*info->mult;
  100403. for(j=1;j<look->posts;j++){
  100404. int current=look->forward_index[j];
  100405. int hy=fit_value[current]&0x7fff;
  100406. if(hy==fit_value[current]){
  100407. hy*=info->mult;
  100408. hx=info->postlist[current];
  100409. render_line(lx,hx,ly,hy,out);
  100410. lx=hx;
  100411. ly=hy;
  100412. }
  100413. }
  100414. for(j=hx;j<n;j++)out[j]*=FLOOR1_fromdB_LOOKUP[ly]; /* be certain */
  100415. return(1);
  100416. }
  100417. memset(out,0,sizeof(*out)*n);
  100418. return(0);
  100419. }
  100420. vorbis_func_floor floor1_exportbundle={
  100421. &floor1_pack,&floor1_unpack,&floor1_look,&floor1_free_info,
  100422. &floor1_free_look,&floor1_inverse1,&floor1_inverse2
  100423. };
  100424. #endif
  100425. /*** End of inlined file: floor1.c ***/
  100426. /*** Start of inlined file: info.c ***/
  100427. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100428. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100429. // tasks..
  100430. #if JUCE_MSVC
  100431. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100432. #endif
  100433. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100434. #if JUCE_USE_OGGVORBIS
  100435. #include <stdlib.h>
  100436. #include <string.h>
  100437. #include <ctype.h>
  100438. static void _v_writestring(oggpack_buffer *o, const char *s, int bytes){
  100439. while(bytes--){
  100440. oggpack_write(o,*s++,8);
  100441. }
  100442. }
  100443. static void _v_readstring(oggpack_buffer *o,char *buf,int bytes){
  100444. while(bytes--){
  100445. *buf++=oggpack_read(o,8);
  100446. }
  100447. }
  100448. void vorbis_comment_init(vorbis_comment *vc){
  100449. memset(vc,0,sizeof(*vc));
  100450. }
  100451. void vorbis_comment_add(vorbis_comment *vc,char *comment){
  100452. vc->user_comments=(char**)_ogg_realloc(vc->user_comments,
  100453. (vc->comments+2)*sizeof(*vc->user_comments));
  100454. vc->comment_lengths=(int*)_ogg_realloc(vc->comment_lengths,
  100455. (vc->comments+2)*sizeof(*vc->comment_lengths));
  100456. vc->comment_lengths[vc->comments]=strlen(comment);
  100457. vc->user_comments[vc->comments]=(char*)_ogg_malloc(vc->comment_lengths[vc->comments]+1);
  100458. strcpy(vc->user_comments[vc->comments], comment);
  100459. vc->comments++;
  100460. vc->user_comments[vc->comments]=NULL;
  100461. }
  100462. void vorbis_comment_add_tag(vorbis_comment *vc, const char *tag, char *contents){
  100463. char *comment=(char*)alloca(strlen(tag)+strlen(contents)+2); /* +2 for = and \0 */
  100464. strcpy(comment, tag);
  100465. strcat(comment, "=");
  100466. strcat(comment, contents);
  100467. vorbis_comment_add(vc, comment);
  100468. }
  100469. static int tagcompare(const char *s1, const char *s2, int n){
  100470. int c=0;
  100471. while(c < n){
  100472. if(toupper(s1[c]) != toupper(s2[c]))
  100473. return !0;
  100474. c++;
  100475. }
  100476. return 0;
  100477. }
  100478. char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count){
  100479. long i;
  100480. int found = 0;
  100481. int taglen = strlen(tag)+1; /* +1 for the = we append */
  100482. char *fulltag = (char*)alloca(taglen+ 1);
  100483. strcpy(fulltag, tag);
  100484. strcat(fulltag, "=");
  100485. for(i=0;i<vc->comments;i++){
  100486. if(!tagcompare(vc->user_comments[i], fulltag, taglen)){
  100487. if(count == found)
  100488. return vc->user_comments[i] + taglen;
  100489. else
  100490. found++;
  100491. }
  100492. }
  100493. return NULL; /* didn't find anything */
  100494. }
  100495. int vorbis_comment_query_count(vorbis_comment *vc, char *tag){
  100496. int i,count=0;
  100497. int taglen = strlen(tag)+1; /* +1 for the = we append */
  100498. char *fulltag = (char*)alloca(taglen+1);
  100499. strcpy(fulltag,tag);
  100500. strcat(fulltag, "=");
  100501. for(i=0;i<vc->comments;i++){
  100502. if(!tagcompare(vc->user_comments[i], fulltag, taglen))
  100503. count++;
  100504. }
  100505. return count;
  100506. }
  100507. void vorbis_comment_clear(vorbis_comment *vc){
  100508. if(vc){
  100509. long i;
  100510. for(i=0;i<vc->comments;i++)
  100511. if(vc->user_comments[i])_ogg_free(vc->user_comments[i]);
  100512. if(vc->user_comments)_ogg_free(vc->user_comments);
  100513. if(vc->comment_lengths)_ogg_free(vc->comment_lengths);
  100514. if(vc->vendor)_ogg_free(vc->vendor);
  100515. }
  100516. memset(vc,0,sizeof(*vc));
  100517. }
  100518. int vorbis_info_blocksize(vorbis_info *vi,int zo){
  100519. codec_setup_info *ci = (codec_setup_info*)vi->codec_setup;
  100520. return ci ? ci->blocksizes[zo] : -1;
  100521. }
  100522. void vorbis_info_init(vorbis_info *vi){
  100523. memset(vi,0,sizeof(*vi));
  100524. vi->codec_setup=_ogg_calloc(1,sizeof(codec_setup_info));
  100525. }
  100526. void vorbis_info_clear(vorbis_info *vi){
  100527. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100528. int i;
  100529. if(ci){
  100530. for(i=0;i<ci->modes;i++)
  100531. if(ci->mode_param[i])_ogg_free(ci->mode_param[i]);
  100532. for(i=0;i<ci->maps;i++) /* unpack does the range checking */
  100533. _mapping_P[ci->map_type[i]]->free_info(ci->map_param[i]);
  100534. for(i=0;i<ci->floors;i++) /* unpack does the range checking */
  100535. _floor_P[ci->floor_type[i]]->free_info(ci->floor_param[i]);
  100536. for(i=0;i<ci->residues;i++) /* unpack does the range checking */
  100537. _residue_P[ci->residue_type[i]]->free_info(ci->residue_param[i]);
  100538. for(i=0;i<ci->books;i++){
  100539. if(ci->book_param[i]){
  100540. vorbis_staticbook_destroy(ci->book_param[i]);
  100541. }
  100542. if(ci->fullbooks)
  100543. vorbis_book_clear(ci->fullbooks+i);
  100544. }
  100545. if(ci->fullbooks)
  100546. _ogg_free(ci->fullbooks);
  100547. for(i=0;i<ci->psys;i++)
  100548. _vi_psy_free(ci->psy_param[i]);
  100549. _ogg_free(ci);
  100550. }
  100551. memset(vi,0,sizeof(*vi));
  100552. }
  100553. static int _vorbis_unpack_info(vorbis_info *vi,oggpack_buffer *opb){
  100554. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100555. if(!ci)return(OV_EFAULT);
  100556. vi->version=oggpack_read(opb,32);
  100557. if(vi->version!=0)return(OV_EVERSION);
  100558. vi->channels=oggpack_read(opb,8);
  100559. vi->rate=oggpack_read(opb,32);
  100560. vi->bitrate_upper=oggpack_read(opb,32);
  100561. vi->bitrate_nominal=oggpack_read(opb,32);
  100562. vi->bitrate_lower=oggpack_read(opb,32);
  100563. ci->blocksizes[0]=1<<oggpack_read(opb,4);
  100564. ci->blocksizes[1]=1<<oggpack_read(opb,4);
  100565. if(vi->rate<1)goto err_out;
  100566. if(vi->channels<1)goto err_out;
  100567. if(ci->blocksizes[0]<8)goto err_out;
  100568. if(ci->blocksizes[1]<ci->blocksizes[0])goto err_out;
  100569. if(oggpack_read(opb,1)!=1)goto err_out; /* EOP check */
  100570. return(0);
  100571. err_out:
  100572. vorbis_info_clear(vi);
  100573. return(OV_EBADHEADER);
  100574. }
  100575. static int _vorbis_unpack_comment(vorbis_comment *vc,oggpack_buffer *opb){
  100576. int i;
  100577. int vendorlen=oggpack_read(opb,32);
  100578. if(vendorlen<0)goto err_out;
  100579. vc->vendor=(char*)_ogg_calloc(vendorlen+1,1);
  100580. _v_readstring(opb,vc->vendor,vendorlen);
  100581. vc->comments=oggpack_read(opb,32);
  100582. if(vc->comments<0)goto err_out;
  100583. vc->user_comments=(char**)_ogg_calloc(vc->comments+1,sizeof(*vc->user_comments));
  100584. vc->comment_lengths=(int*)_ogg_calloc(vc->comments+1, sizeof(*vc->comment_lengths));
  100585. for(i=0;i<vc->comments;i++){
  100586. int len=oggpack_read(opb,32);
  100587. if(len<0)goto err_out;
  100588. vc->comment_lengths[i]=len;
  100589. vc->user_comments[i]=(char*)_ogg_calloc(len+1,1);
  100590. _v_readstring(opb,vc->user_comments[i],len);
  100591. }
  100592. if(oggpack_read(opb,1)!=1)goto err_out; /* EOP check */
  100593. return(0);
  100594. err_out:
  100595. vorbis_comment_clear(vc);
  100596. return(OV_EBADHEADER);
  100597. }
  100598. static int _vorbis_unpack_books(vorbis_info *vi,oggpack_buffer *opb){
  100599. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100600. int i;
  100601. if(!ci)return(OV_EFAULT);
  100602. ci->books=oggpack_read(opb,8)+1;
  100603. for(i=0;i<ci->books;i++){
  100604. ci->book_param[i]=(static_codebook*)_ogg_calloc(1,sizeof(*ci->book_param[i]));
  100605. if(vorbis_staticbook_unpack(opb,ci->book_param[i]))goto err_out;
  100606. }
  100607. {
  100608. int times=oggpack_read(opb,6)+1;
  100609. for(i=0;i<times;i++){
  100610. int test=oggpack_read(opb,16);
  100611. if(test<0 || test>=VI_TIMEB)goto err_out;
  100612. }
  100613. }
  100614. ci->floors=oggpack_read(opb,6)+1;
  100615. for(i=0;i<ci->floors;i++){
  100616. ci->floor_type[i]=oggpack_read(opb,16);
  100617. if(ci->floor_type[i]<0 || ci->floor_type[i]>=VI_FLOORB)goto err_out;
  100618. ci->floor_param[i]=_floor_P[ci->floor_type[i]]->unpack(vi,opb);
  100619. if(!ci->floor_param[i])goto err_out;
  100620. }
  100621. ci->residues=oggpack_read(opb,6)+1;
  100622. for(i=0;i<ci->residues;i++){
  100623. ci->residue_type[i]=oggpack_read(opb,16);
  100624. if(ci->residue_type[i]<0 || ci->residue_type[i]>=VI_RESB)goto err_out;
  100625. ci->residue_param[i]=_residue_P[ci->residue_type[i]]->unpack(vi,opb);
  100626. if(!ci->residue_param[i])goto err_out;
  100627. }
  100628. ci->maps=oggpack_read(opb,6)+1;
  100629. for(i=0;i<ci->maps;i++){
  100630. ci->map_type[i]=oggpack_read(opb,16);
  100631. if(ci->map_type[i]<0 || ci->map_type[i]>=VI_MAPB)goto err_out;
  100632. ci->map_param[i]=_mapping_P[ci->map_type[i]]->unpack(vi,opb);
  100633. if(!ci->map_param[i])goto err_out;
  100634. }
  100635. ci->modes=oggpack_read(opb,6)+1;
  100636. for(i=0;i<ci->modes;i++){
  100637. ci->mode_param[i]=(vorbis_info_mode*)_ogg_calloc(1,sizeof(*ci->mode_param[i]));
  100638. ci->mode_param[i]->blockflag=oggpack_read(opb,1);
  100639. ci->mode_param[i]->windowtype=oggpack_read(opb,16);
  100640. ci->mode_param[i]->transformtype=oggpack_read(opb,16);
  100641. ci->mode_param[i]->mapping=oggpack_read(opb,8);
  100642. if(ci->mode_param[i]->windowtype>=VI_WINDOWB)goto err_out;
  100643. if(ci->mode_param[i]->transformtype>=VI_WINDOWB)goto err_out;
  100644. if(ci->mode_param[i]->mapping>=ci->maps)goto err_out;
  100645. }
  100646. if(oggpack_read(opb,1)!=1)goto err_out; /* top level EOP check */
  100647. return(0);
  100648. err_out:
  100649. vorbis_info_clear(vi);
  100650. return(OV_EBADHEADER);
  100651. }
  100652. int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,ogg_packet *op){
  100653. oggpack_buffer opb;
  100654. if(op){
  100655. oggpack_readinit(&opb,op->packet,op->bytes);
  100656. {
  100657. char buffer[6];
  100658. int packtype=oggpack_read(&opb,8);
  100659. memset(buffer,0,6);
  100660. _v_readstring(&opb,buffer,6);
  100661. if(memcmp(buffer,"vorbis",6)){
  100662. return(OV_ENOTVORBIS);
  100663. }
  100664. switch(packtype){
  100665. case 0x01: /* least significant *bit* is read first */
  100666. if(!op->b_o_s){
  100667. return(OV_EBADHEADER);
  100668. }
  100669. if(vi->rate!=0){
  100670. return(OV_EBADHEADER);
  100671. }
  100672. return(_vorbis_unpack_info(vi,&opb));
  100673. case 0x03: /* least significant *bit* is read first */
  100674. if(vi->rate==0){
  100675. return(OV_EBADHEADER);
  100676. }
  100677. return(_vorbis_unpack_comment(vc,&opb));
  100678. case 0x05: /* least significant *bit* is read first */
  100679. if(vi->rate==0 || vc->vendor==NULL){
  100680. return(OV_EBADHEADER);
  100681. }
  100682. return(_vorbis_unpack_books(vi,&opb));
  100683. default:
  100684. return(OV_EBADHEADER);
  100685. break;
  100686. }
  100687. }
  100688. }
  100689. return(OV_EBADHEADER);
  100690. }
  100691. static int _vorbis_pack_info(oggpack_buffer *opb,vorbis_info *vi){
  100692. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100693. if(!ci)return(OV_EFAULT);
  100694. oggpack_write(opb,0x01,8);
  100695. _v_writestring(opb,"vorbis", 6);
  100696. oggpack_write(opb,0x00,32);
  100697. oggpack_write(opb,vi->channels,8);
  100698. oggpack_write(opb,vi->rate,32);
  100699. oggpack_write(opb,vi->bitrate_upper,32);
  100700. oggpack_write(opb,vi->bitrate_nominal,32);
  100701. oggpack_write(opb,vi->bitrate_lower,32);
  100702. oggpack_write(opb,ilog2(ci->blocksizes[0]),4);
  100703. oggpack_write(opb,ilog2(ci->blocksizes[1]),4);
  100704. oggpack_write(opb,1,1);
  100705. return(0);
  100706. }
  100707. static int _vorbis_pack_comment(oggpack_buffer *opb,vorbis_comment *vc){
  100708. char temp[]="Xiph.Org libVorbis I 20050304";
  100709. int bytes = strlen(temp);
  100710. oggpack_write(opb,0x03,8);
  100711. _v_writestring(opb,"vorbis", 6);
  100712. oggpack_write(opb,bytes,32);
  100713. _v_writestring(opb,temp, bytes);
  100714. oggpack_write(opb,vc->comments,32);
  100715. if(vc->comments){
  100716. int i;
  100717. for(i=0;i<vc->comments;i++){
  100718. if(vc->user_comments[i]){
  100719. oggpack_write(opb,vc->comment_lengths[i],32);
  100720. _v_writestring(opb,vc->user_comments[i], vc->comment_lengths[i]);
  100721. }else{
  100722. oggpack_write(opb,0,32);
  100723. }
  100724. }
  100725. }
  100726. oggpack_write(opb,1,1);
  100727. return(0);
  100728. }
  100729. static int _vorbis_pack_books(oggpack_buffer *opb,vorbis_info *vi){
  100730. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100731. int i;
  100732. if(!ci)return(OV_EFAULT);
  100733. oggpack_write(opb,0x05,8);
  100734. _v_writestring(opb,"vorbis", 6);
  100735. oggpack_write(opb,ci->books-1,8);
  100736. for(i=0;i<ci->books;i++)
  100737. if(vorbis_staticbook_pack(ci->book_param[i],opb))goto err_out;
  100738. oggpack_write(opb,0,6);
  100739. oggpack_write(opb,0,16);
  100740. oggpack_write(opb,ci->floors-1,6);
  100741. for(i=0;i<ci->floors;i++){
  100742. oggpack_write(opb,ci->floor_type[i],16);
  100743. if(_floor_P[ci->floor_type[i]]->pack)
  100744. _floor_P[ci->floor_type[i]]->pack(ci->floor_param[i],opb);
  100745. else
  100746. goto err_out;
  100747. }
  100748. oggpack_write(opb,ci->residues-1,6);
  100749. for(i=0;i<ci->residues;i++){
  100750. oggpack_write(opb,ci->residue_type[i],16);
  100751. _residue_P[ci->residue_type[i]]->pack(ci->residue_param[i],opb);
  100752. }
  100753. oggpack_write(opb,ci->maps-1,6);
  100754. for(i=0;i<ci->maps;i++){
  100755. oggpack_write(opb,ci->map_type[i],16);
  100756. _mapping_P[ci->map_type[i]]->pack(vi,ci->map_param[i],opb);
  100757. }
  100758. oggpack_write(opb,ci->modes-1,6);
  100759. for(i=0;i<ci->modes;i++){
  100760. oggpack_write(opb,ci->mode_param[i]->blockflag,1);
  100761. oggpack_write(opb,ci->mode_param[i]->windowtype,16);
  100762. oggpack_write(opb,ci->mode_param[i]->transformtype,16);
  100763. oggpack_write(opb,ci->mode_param[i]->mapping,8);
  100764. }
  100765. oggpack_write(opb,1,1);
  100766. return(0);
  100767. err_out:
  100768. return(-1);
  100769. }
  100770. int vorbis_commentheader_out(vorbis_comment *vc,
  100771. ogg_packet *op){
  100772. oggpack_buffer opb;
  100773. oggpack_writeinit(&opb);
  100774. if(_vorbis_pack_comment(&opb,vc)) return OV_EIMPL;
  100775. op->packet = (unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100776. memcpy(op->packet, opb.buffer, oggpack_bytes(&opb));
  100777. op->bytes=oggpack_bytes(&opb);
  100778. op->b_o_s=0;
  100779. op->e_o_s=0;
  100780. op->granulepos=0;
  100781. op->packetno=1;
  100782. return 0;
  100783. }
  100784. int vorbis_analysis_headerout(vorbis_dsp_state *v,
  100785. vorbis_comment *vc,
  100786. ogg_packet *op,
  100787. ogg_packet *op_comm,
  100788. ogg_packet *op_code){
  100789. int ret=OV_EIMPL;
  100790. vorbis_info *vi=v->vi;
  100791. oggpack_buffer opb;
  100792. private_state *b=(private_state*)v->backend_state;
  100793. if(!b){
  100794. ret=OV_EFAULT;
  100795. goto err_out;
  100796. }
  100797. oggpack_writeinit(&opb);
  100798. if(_vorbis_pack_info(&opb,vi))goto err_out;
  100799. if(b->header)_ogg_free(b->header);
  100800. b->header=(unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100801. memcpy(b->header,opb.buffer,oggpack_bytes(&opb));
  100802. op->packet=b->header;
  100803. op->bytes=oggpack_bytes(&opb);
  100804. op->b_o_s=1;
  100805. op->e_o_s=0;
  100806. op->granulepos=0;
  100807. op->packetno=0;
  100808. oggpack_reset(&opb);
  100809. if(_vorbis_pack_comment(&opb,vc))goto err_out;
  100810. if(b->header1)_ogg_free(b->header1);
  100811. b->header1=(unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100812. memcpy(b->header1,opb.buffer,oggpack_bytes(&opb));
  100813. op_comm->packet=b->header1;
  100814. op_comm->bytes=oggpack_bytes(&opb);
  100815. op_comm->b_o_s=0;
  100816. op_comm->e_o_s=0;
  100817. op_comm->granulepos=0;
  100818. op_comm->packetno=1;
  100819. oggpack_reset(&opb);
  100820. if(_vorbis_pack_books(&opb,vi))goto err_out;
  100821. if(b->header2)_ogg_free(b->header2);
  100822. b->header2=(unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100823. memcpy(b->header2,opb.buffer,oggpack_bytes(&opb));
  100824. op_code->packet=b->header2;
  100825. op_code->bytes=oggpack_bytes(&opb);
  100826. op_code->b_o_s=0;
  100827. op_code->e_o_s=0;
  100828. op_code->granulepos=0;
  100829. op_code->packetno=2;
  100830. oggpack_writeclear(&opb);
  100831. return(0);
  100832. err_out:
  100833. oggpack_writeclear(&opb);
  100834. memset(op,0,sizeof(*op));
  100835. memset(op_comm,0,sizeof(*op_comm));
  100836. memset(op_code,0,sizeof(*op_code));
  100837. if(b->header)_ogg_free(b->header);
  100838. if(b->header1)_ogg_free(b->header1);
  100839. if(b->header2)_ogg_free(b->header2);
  100840. b->header=NULL;
  100841. b->header1=NULL;
  100842. b->header2=NULL;
  100843. return(ret);
  100844. }
  100845. double vorbis_granule_time(vorbis_dsp_state *v,ogg_int64_t granulepos){
  100846. if(granulepos>=0)
  100847. return((double)granulepos/v->vi->rate);
  100848. return(-1);
  100849. }
  100850. #endif
  100851. /*** End of inlined file: info.c ***/
  100852. /*** Start of inlined file: lpc.c ***/
  100853. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100854. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100855. // tasks..
  100856. #if JUCE_MSVC
  100857. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100858. #endif
  100859. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100860. #if JUCE_USE_OGGVORBIS
  100861. #include <stdlib.h>
  100862. #include <string.h>
  100863. #include <math.h>
  100864. float vorbis_lpc_from_data(float *data,float *lpci,int n,int m){
  100865. double *aut=(double*)alloca(sizeof(*aut)*(m+1));
  100866. double *lpc=(double*)alloca(sizeof(*lpc)*(m));
  100867. double error;
  100868. int i,j;
  100869. j=m+1;
  100870. while(j--){
  100871. double d=0; /* double needed for accumulator depth */
  100872. for(i=j;i<n;i++)d+=(double)data[i]*data[i-j];
  100873. aut[j]=d;
  100874. }
  100875. error=aut[0];
  100876. for(i=0;i<m;i++){
  100877. double r= -aut[i+1];
  100878. if(error==0){
  100879. memset(lpci,0,m*sizeof(*lpci));
  100880. return 0;
  100881. }
  100882. for(j=0;j<i;j++)r-=lpc[j]*aut[i-j];
  100883. r/=error;
  100884. lpc[i]=r;
  100885. for(j=0;j<i/2;j++){
  100886. double tmp=lpc[j];
  100887. lpc[j]+=r*lpc[i-1-j];
  100888. lpc[i-1-j]+=r*tmp;
  100889. }
  100890. if(i%2)lpc[j]+=lpc[j]*r;
  100891. error*=1.f-r*r;
  100892. }
  100893. for(j=0;j<m;j++)lpci[j]=(float)lpc[j];
  100894. return error;
  100895. }
  100896. void vorbis_lpc_predict(float *coeff,float *prime,int m,
  100897. float *data,long n){
  100898. long i,j,o,p;
  100899. float y;
  100900. float *work=(float*)alloca(sizeof(*work)*(m+n));
  100901. if(!prime)
  100902. for(i=0;i<m;i++)
  100903. work[i]=0.f;
  100904. else
  100905. for(i=0;i<m;i++)
  100906. work[i]=prime[i];
  100907. for(i=0;i<n;i++){
  100908. y=0;
  100909. o=i;
  100910. p=m;
  100911. for(j=0;j<m;j++)
  100912. y-=work[o++]*coeff[--p];
  100913. data[i]=work[o]=y;
  100914. }
  100915. }
  100916. #endif
  100917. /*** End of inlined file: lpc.c ***/
  100918. /*** Start of inlined file: lsp.c ***/
  100919. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100920. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100921. // tasks..
  100922. #if JUCE_MSVC
  100923. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100924. #endif
  100925. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100926. #if JUCE_USE_OGGVORBIS
  100927. #include <math.h>
  100928. #include <string.h>
  100929. #include <stdlib.h>
  100930. /*** Start of inlined file: lookup.h ***/
  100931. #ifndef _V_LOOKUP_H_
  100932. #ifdef FLOAT_LOOKUP
  100933. extern float vorbis_coslook(float a);
  100934. extern float vorbis_invsqlook(float a);
  100935. extern float vorbis_invsq2explook(int a);
  100936. extern float vorbis_fromdBlook(float a);
  100937. #endif
  100938. #ifdef INT_LOOKUP
  100939. extern long vorbis_invsqlook_i(long a,long e);
  100940. extern long vorbis_coslook_i(long a);
  100941. extern float vorbis_fromdBlook_i(long a);
  100942. #endif
  100943. #endif
  100944. /*** End of inlined file: lookup.h ***/
  100945. #define FLOAT_LOOKUP
  100946. #undef INT_LOOKUP
  100947. #ifdef FLOAT_LOOKUP
  100948. /*** Start of inlined file: lookup.c ***/
  100949. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100950. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100951. // tasks..
  100952. #if JUCE_MSVC
  100953. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100954. #endif
  100955. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100956. #if JUCE_USE_OGGVORBIS
  100957. #include <math.h>
  100958. /*** Start of inlined file: lookup.h ***/
  100959. #ifndef _V_LOOKUP_H_
  100960. #ifdef FLOAT_LOOKUP
  100961. extern float vorbis_coslook(float a);
  100962. extern float vorbis_invsqlook(float a);
  100963. extern float vorbis_invsq2explook(int a);
  100964. extern float vorbis_fromdBlook(float a);
  100965. #endif
  100966. #ifdef INT_LOOKUP
  100967. extern long vorbis_invsqlook_i(long a,long e);
  100968. extern long vorbis_coslook_i(long a);
  100969. extern float vorbis_fromdBlook_i(long a);
  100970. #endif
  100971. #endif
  100972. /*** End of inlined file: lookup.h ***/
  100973. /*** Start of inlined file: lookup_data.h ***/
  100974. #ifndef _V_LOOKUP_DATA_H_
  100975. #ifdef FLOAT_LOOKUP
  100976. #define COS_LOOKUP_SZ 128
  100977. static float COS_LOOKUP[COS_LOOKUP_SZ+1]={
  100978. +1.0000000000000f,+0.9996988186962f,+0.9987954562052f,+0.9972904566787f,
  100979. +0.9951847266722f,+0.9924795345987f,+0.9891765099648f,+0.9852776423889f,
  100980. +0.9807852804032f,+0.9757021300385f,+0.9700312531945f,+0.9637760657954f,
  100981. +0.9569403357322f,+0.9495281805930f,+0.9415440651830f,+0.9329927988347f,
  100982. +0.9238795325113f,+0.9142097557035f,+0.9039892931234f,+0.8932243011955f,
  100983. +0.8819212643484f,+0.8700869911087f,+0.8577286100003f,+0.8448535652497f,
  100984. +0.8314696123025f,+0.8175848131516f,+0.8032075314806f,+0.7883464276266f,
  100985. +0.7730104533627f,+0.7572088465065f,+0.7409511253550f,+0.7242470829515f,
  100986. +0.7071067811865f,+0.6895405447371f,+0.6715589548470f,+0.6531728429538f,
  100987. +0.6343932841636f,+0.6152315905806f,+0.5956993044924f,+0.5758081914178f,
  100988. +0.5555702330196f,+0.5349976198871f,+0.5141027441932f,+0.4928981922298f,
  100989. +0.4713967368260f,+0.4496113296546f,+0.4275550934303f,+0.4052413140050f,
  100990. +0.3826834323651f,+0.3598950365350f,+0.3368898533922f,+0.3136817403989f,
  100991. +0.2902846772545f,+0.2667127574749f,+0.2429801799033f,+0.2191012401569f,
  100992. +0.1950903220161f,+0.1709618887603f,+0.1467304744554f,+0.1224106751992f,
  100993. +0.0980171403296f,+0.0735645635997f,+0.0490676743274f,+0.0245412285229f,
  100994. +0.0000000000000f,-0.0245412285229f,-0.0490676743274f,-0.0735645635997f,
  100995. -0.0980171403296f,-0.1224106751992f,-0.1467304744554f,-0.1709618887603f,
  100996. -0.1950903220161f,-0.2191012401569f,-0.2429801799033f,-0.2667127574749f,
  100997. -0.2902846772545f,-0.3136817403989f,-0.3368898533922f,-0.3598950365350f,
  100998. -0.3826834323651f,-0.4052413140050f,-0.4275550934303f,-0.4496113296546f,
  100999. -0.4713967368260f,-0.4928981922298f,-0.5141027441932f,-0.5349976198871f,
  101000. -0.5555702330196f,-0.5758081914178f,-0.5956993044924f,-0.6152315905806f,
  101001. -0.6343932841636f,-0.6531728429538f,-0.6715589548470f,-0.6895405447371f,
  101002. -0.7071067811865f,-0.7242470829515f,-0.7409511253550f,-0.7572088465065f,
  101003. -0.7730104533627f,-0.7883464276266f,-0.8032075314806f,-0.8175848131516f,
  101004. -0.8314696123025f,-0.8448535652497f,-0.8577286100003f,-0.8700869911087f,
  101005. -0.8819212643484f,-0.8932243011955f,-0.9039892931234f,-0.9142097557035f,
  101006. -0.9238795325113f,-0.9329927988347f,-0.9415440651830f,-0.9495281805930f,
  101007. -0.9569403357322f,-0.9637760657954f,-0.9700312531945f,-0.9757021300385f,
  101008. -0.9807852804032f,-0.9852776423889f,-0.9891765099648f,-0.9924795345987f,
  101009. -0.9951847266722f,-0.9972904566787f,-0.9987954562052f,-0.9996988186962f,
  101010. -1.0000000000000f,
  101011. };
  101012. #define INVSQ_LOOKUP_SZ 32
  101013. static float INVSQ_LOOKUP[INVSQ_LOOKUP_SZ+1]={
  101014. 1.414213562373f,1.392621247646f,1.371988681140f,1.352246807566f,
  101015. 1.333333333333f,1.315191898443f,1.297771369046f,1.281025230441f,
  101016. 1.264911064067f,1.249390095109f,1.234426799697f,1.219988562661f,
  101017. 1.206045378311f,1.192569588000f,1.179535649239f,1.166919931983f,
  101018. 1.154700538379f,1.142857142857f,1.131370849898f,1.120224067222f,
  101019. 1.109400392450f,1.098884511590f,1.088662107904f,1.078719779941f,
  101020. 1.069044967650f,1.059625885652f,1.050451462878f,1.041511287847f,
  101021. 1.032795558989f,1.024295039463f,1.016001016002f,1.007905261358f,
  101022. 1.000000000000f,
  101023. };
  101024. #define INVSQ2EXP_LOOKUP_MIN (-32)
  101025. #define INVSQ2EXP_LOOKUP_MAX 32
  101026. static float INVSQ2EXP_LOOKUP[INVSQ2EXP_LOOKUP_MAX-\
  101027. INVSQ2EXP_LOOKUP_MIN+1]={
  101028. 65536.f, 46340.95001f, 32768.f, 23170.47501f,
  101029. 16384.f, 11585.2375f, 8192.f, 5792.618751f,
  101030. 4096.f, 2896.309376f, 2048.f, 1448.154688f,
  101031. 1024.f, 724.0773439f, 512.f, 362.038672f,
  101032. 256.f, 181.019336f, 128.f, 90.50966799f,
  101033. 64.f, 45.254834f, 32.f, 22.627417f,
  101034. 16.f, 11.3137085f, 8.f, 5.656854249f,
  101035. 4.f, 2.828427125f, 2.f, 1.414213562f,
  101036. 1.f, 0.7071067812f, 0.5f, 0.3535533906f,
  101037. 0.25f, 0.1767766953f, 0.125f, 0.08838834765f,
  101038. 0.0625f, 0.04419417382f, 0.03125f, 0.02209708691f,
  101039. 0.015625f, 0.01104854346f, 0.0078125f, 0.005524271728f,
  101040. 0.00390625f, 0.002762135864f, 0.001953125f, 0.001381067932f,
  101041. 0.0009765625f, 0.000690533966f, 0.00048828125f, 0.000345266983f,
  101042. 0.000244140625f,0.0001726334915f,0.0001220703125f,8.631674575e-05f,
  101043. 6.103515625e-05f,4.315837288e-05f,3.051757812e-05f,2.157918644e-05f,
  101044. 1.525878906e-05f,
  101045. };
  101046. #endif
  101047. #define FROMdB_LOOKUP_SZ 35
  101048. #define FROMdB2_LOOKUP_SZ 32
  101049. #define FROMdB_SHIFT 5
  101050. #define FROMdB2_SHIFT 3
  101051. #define FROMdB2_MASK 31
  101052. static float FROMdB_LOOKUP[FROMdB_LOOKUP_SZ]={
  101053. 1.f, 0.6309573445f, 0.3981071706f, 0.2511886432f,
  101054. 0.1584893192f, 0.1f, 0.06309573445f, 0.03981071706f,
  101055. 0.02511886432f, 0.01584893192f, 0.01f, 0.006309573445f,
  101056. 0.003981071706f, 0.002511886432f, 0.001584893192f, 0.001f,
  101057. 0.0006309573445f,0.0003981071706f,0.0002511886432f,0.0001584893192f,
  101058. 0.0001f,6.309573445e-05f,3.981071706e-05f,2.511886432e-05f,
  101059. 1.584893192e-05f, 1e-05f,6.309573445e-06f,3.981071706e-06f,
  101060. 2.511886432e-06f,1.584893192e-06f, 1e-06f,6.309573445e-07f,
  101061. 3.981071706e-07f,2.511886432e-07f,1.584893192e-07f,
  101062. };
  101063. static float FROMdB2_LOOKUP[FROMdB2_LOOKUP_SZ]={
  101064. 0.9928302478f, 0.9786445908f, 0.9646616199f, 0.9508784391f,
  101065. 0.9372921937f, 0.92390007f, 0.9106992942f, 0.8976871324f,
  101066. 0.8848608897f, 0.8722179097f, 0.8597555737f, 0.8474713009f,
  101067. 0.835362547f, 0.8234268041f, 0.8116616003f, 0.8000644989f,
  101068. 0.7886330981f, 0.7773650302f, 0.7662579617f, 0.755309592f,
  101069. 0.7445176537f, 0.7338799116f, 0.7233941627f, 0.7130582353f,
  101070. 0.7028699885f, 0.6928273125f, 0.6829281272f, 0.6731703824f,
  101071. 0.6635520573f, 0.6540711597f, 0.6447257262f, 0.6355138211f,
  101072. };
  101073. #ifdef INT_LOOKUP
  101074. #define INVSQ_LOOKUP_I_SHIFT 10
  101075. #define INVSQ_LOOKUP_I_MASK 1023
  101076. static long INVSQ_LOOKUP_I[64+1]={
  101077. 92682l, 91966l, 91267l, 90583l,
  101078. 89915l, 89261l, 88621l, 87995l,
  101079. 87381l, 86781l, 86192l, 85616l,
  101080. 85051l, 84497l, 83953l, 83420l,
  101081. 82897l, 82384l, 81880l, 81385l,
  101082. 80899l, 80422l, 79953l, 79492l,
  101083. 79039l, 78594l, 78156l, 77726l,
  101084. 77302l, 76885l, 76475l, 76072l,
  101085. 75674l, 75283l, 74898l, 74519l,
  101086. 74146l, 73778l, 73415l, 73058l,
  101087. 72706l, 72359l, 72016l, 71679l,
  101088. 71347l, 71019l, 70695l, 70376l,
  101089. 70061l, 69750l, 69444l, 69141l,
  101090. 68842l, 68548l, 68256l, 67969l,
  101091. 67685l, 67405l, 67128l, 66855l,
  101092. 66585l, 66318l, 66054l, 65794l,
  101093. 65536l,
  101094. };
  101095. #define COS_LOOKUP_I_SHIFT 9
  101096. #define COS_LOOKUP_I_MASK 511
  101097. #define COS_LOOKUP_I_SZ 128
  101098. static long COS_LOOKUP_I[COS_LOOKUP_I_SZ+1]={
  101099. 16384l, 16379l, 16364l, 16340l,
  101100. 16305l, 16261l, 16207l, 16143l,
  101101. 16069l, 15986l, 15893l, 15791l,
  101102. 15679l, 15557l, 15426l, 15286l,
  101103. 15137l, 14978l, 14811l, 14635l,
  101104. 14449l, 14256l, 14053l, 13842l,
  101105. 13623l, 13395l, 13160l, 12916l,
  101106. 12665l, 12406l, 12140l, 11866l,
  101107. 11585l, 11297l, 11003l, 10702l,
  101108. 10394l, 10080l, 9760l, 9434l,
  101109. 9102l, 8765l, 8423l, 8076l,
  101110. 7723l, 7366l, 7005l, 6639l,
  101111. 6270l, 5897l, 5520l, 5139l,
  101112. 4756l, 4370l, 3981l, 3590l,
  101113. 3196l, 2801l, 2404l, 2006l,
  101114. 1606l, 1205l, 804l, 402l,
  101115. 0l, -401l, -803l, -1204l,
  101116. -1605l, -2005l, -2403l, -2800l,
  101117. -3195l, -3589l, -3980l, -4369l,
  101118. -4755l, -5138l, -5519l, -5896l,
  101119. -6269l, -6638l, -7004l, -7365l,
  101120. -7722l, -8075l, -8422l, -8764l,
  101121. -9101l, -9433l, -9759l, -10079l,
  101122. -10393l, -10701l, -11002l, -11296l,
  101123. -11584l, -11865l, -12139l, -12405l,
  101124. -12664l, -12915l, -13159l, -13394l,
  101125. -13622l, -13841l, -14052l, -14255l,
  101126. -14448l, -14634l, -14810l, -14977l,
  101127. -15136l, -15285l, -15425l, -15556l,
  101128. -15678l, -15790l, -15892l, -15985l,
  101129. -16068l, -16142l, -16206l, -16260l,
  101130. -16304l, -16339l, -16363l, -16378l,
  101131. -16383l,
  101132. };
  101133. #endif
  101134. #endif
  101135. /*** End of inlined file: lookup_data.h ***/
  101136. #ifdef FLOAT_LOOKUP
  101137. float vorbis_coslook(float a){
  101138. double d=a*(.31830989*(float)COS_LOOKUP_SZ);
  101139. int i=vorbis_ftoi(d-.5);
  101140. return COS_LOOKUP[i]+ (d-i)*(COS_LOOKUP[i+1]-COS_LOOKUP[i]);
  101141. }
  101142. float vorbis_invsqlook(float a){
  101143. double d=a*(2.f*(float)INVSQ_LOOKUP_SZ)-(float)INVSQ_LOOKUP_SZ;
  101144. int i=vorbis_ftoi(d-.5f);
  101145. return INVSQ_LOOKUP[i]+ (d-i)*(INVSQ_LOOKUP[i+1]-INVSQ_LOOKUP[i]);
  101146. }
  101147. float vorbis_invsq2explook(int a){
  101148. return INVSQ2EXP_LOOKUP[a-INVSQ2EXP_LOOKUP_MIN];
  101149. }
  101150. #include <stdio.h>
  101151. float vorbis_fromdBlook(float a){
  101152. int i=vorbis_ftoi(a*((float)(-(1<<FROMdB2_SHIFT)))-.5f);
  101153. return (i<0)?1.f:
  101154. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  101155. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  101156. }
  101157. #endif
  101158. #ifdef INT_LOOKUP
  101159. long vorbis_invsqlook_i(long a,long e){
  101160. long i=(a&0x7fff)>>(INVSQ_LOOKUP_I_SHIFT-1);
  101161. long d=(a&INVSQ_LOOKUP_I_MASK)<<(16-INVSQ_LOOKUP_I_SHIFT); /* 0.16 */
  101162. long val=INVSQ_LOOKUP_I[i]- /* 1.16 */
  101163. (((INVSQ_LOOKUP_I[i]-INVSQ_LOOKUP_I[i+1])* /* 0.16 */
  101164. d)>>16); /* result 1.16 */
  101165. e+=32;
  101166. if(e&1)val=(val*5792)>>13; /* multiply val by 1/sqrt(2) */
  101167. e=(e>>1)-8;
  101168. return(val>>e);
  101169. }
  101170. float vorbis_fromdBlook_i(long a){
  101171. int i=(-a)>>(12-FROMdB2_SHIFT);
  101172. return (i<0)?1.f:
  101173. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  101174. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  101175. }
  101176. long vorbis_coslook_i(long a){
  101177. int i=a>>COS_LOOKUP_I_SHIFT;
  101178. int d=a&COS_LOOKUP_I_MASK;
  101179. return COS_LOOKUP_I[i]- ((d*(COS_LOOKUP_I[i]-COS_LOOKUP_I[i+1]))>>
  101180. COS_LOOKUP_I_SHIFT);
  101181. }
  101182. #endif
  101183. #endif
  101184. /*** End of inlined file: lookup.c ***/
  101185. /* catch this in the build system; we #include for
  101186. compilers (like gcc) that can't inline across
  101187. modules */
  101188. void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
  101189. float amp,float ampoffset){
  101190. int i;
  101191. float wdel=M_PI/ln;
  101192. vorbis_fpu_control fpu;
  101193. (void) fpu; // to avoid an unused variable warning
  101194. vorbis_fpu_setround(&fpu);
  101195. for(i=0;i<m;i++)lsp[i]=vorbis_coslook(lsp[i]);
  101196. i=0;
  101197. while(i<n){
  101198. int k=map[i];
  101199. int qexp;
  101200. float p=.7071067812f;
  101201. float q=.7071067812f;
  101202. float w=vorbis_coslook(wdel*k);
  101203. float *ftmp=lsp;
  101204. int c=m>>1;
  101205. do{
  101206. q*=ftmp[0]-w;
  101207. p*=ftmp[1]-w;
  101208. ftmp+=2;
  101209. }while(--c);
  101210. if(m&1){
  101211. q*=ftmp[0]-w;
  101212. q*=q;
  101213. p*=p*(1.f-w*w);
  101214. }else{
  101215. q*=q*(1.f+w);
  101216. p*=p*(1.f-w);
  101217. }
  101218. q=frexp(p+q,&qexp);
  101219. q=vorbis_fromdBlook(amp*
  101220. vorbis_invsqlook(q)*
  101221. vorbis_invsq2explook(qexp+m)-
  101222. ampoffset);
  101223. do{
  101224. curve[i++]*=q;
  101225. }while(map[i]==k);
  101226. }
  101227. vorbis_fpu_restore(fpu);
  101228. }
  101229. #else
  101230. #ifdef INT_LOOKUP
  101231. /*** Start of inlined file: lookup.c ***/
  101232. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  101233. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  101234. // tasks..
  101235. #if JUCE_MSVC
  101236. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  101237. #endif
  101238. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  101239. #if JUCE_USE_OGGVORBIS
  101240. #include <math.h>
  101241. /*** Start of inlined file: lookup.h ***/
  101242. #ifndef _V_LOOKUP_H_
  101243. #ifdef FLOAT_LOOKUP
  101244. extern float vorbis_coslook(float a);
  101245. extern float vorbis_invsqlook(float a);
  101246. extern float vorbis_invsq2explook(int a);
  101247. extern float vorbis_fromdBlook(float a);
  101248. #endif
  101249. #ifdef INT_LOOKUP
  101250. extern long vorbis_invsqlook_i(long a,long e);
  101251. extern long vorbis_coslook_i(long a);
  101252. extern float vorbis_fromdBlook_i(long a);
  101253. #endif
  101254. #endif
  101255. /*** End of inlined file: lookup.h ***/
  101256. /*** Start of inlined file: lookup_data.h ***/
  101257. #ifndef _V_LOOKUP_DATA_H_
  101258. #ifdef FLOAT_LOOKUP
  101259. #define COS_LOOKUP_SZ 128
  101260. static float COS_LOOKUP[COS_LOOKUP_SZ+1]={
  101261. +1.0000000000000f,+0.9996988186962f,+0.9987954562052f,+0.9972904566787f,
  101262. +0.9951847266722f,+0.9924795345987f,+0.9891765099648f,+0.9852776423889f,
  101263. +0.9807852804032f,+0.9757021300385f,+0.9700312531945f,+0.9637760657954f,
  101264. +0.9569403357322f,+0.9495281805930f,+0.9415440651830f,+0.9329927988347f,
  101265. +0.9238795325113f,+0.9142097557035f,+0.9039892931234f,+0.8932243011955f,
  101266. +0.8819212643484f,+0.8700869911087f,+0.8577286100003f,+0.8448535652497f,
  101267. +0.8314696123025f,+0.8175848131516f,+0.8032075314806f,+0.7883464276266f,
  101268. +0.7730104533627f,+0.7572088465065f,+0.7409511253550f,+0.7242470829515f,
  101269. +0.7071067811865f,+0.6895405447371f,+0.6715589548470f,+0.6531728429538f,
  101270. +0.6343932841636f,+0.6152315905806f,+0.5956993044924f,+0.5758081914178f,
  101271. +0.5555702330196f,+0.5349976198871f,+0.5141027441932f,+0.4928981922298f,
  101272. +0.4713967368260f,+0.4496113296546f,+0.4275550934303f,+0.4052413140050f,
  101273. +0.3826834323651f,+0.3598950365350f,+0.3368898533922f,+0.3136817403989f,
  101274. +0.2902846772545f,+0.2667127574749f,+0.2429801799033f,+0.2191012401569f,
  101275. +0.1950903220161f,+0.1709618887603f,+0.1467304744554f,+0.1224106751992f,
  101276. +0.0980171403296f,+0.0735645635997f,+0.0490676743274f,+0.0245412285229f,
  101277. +0.0000000000000f,-0.0245412285229f,-0.0490676743274f,-0.0735645635997f,
  101278. -0.0980171403296f,-0.1224106751992f,-0.1467304744554f,-0.1709618887603f,
  101279. -0.1950903220161f,-0.2191012401569f,-0.2429801799033f,-0.2667127574749f,
  101280. -0.2902846772545f,-0.3136817403989f,-0.3368898533922f,-0.3598950365350f,
  101281. -0.3826834323651f,-0.4052413140050f,-0.4275550934303f,-0.4496113296546f,
  101282. -0.4713967368260f,-0.4928981922298f,-0.5141027441932f,-0.5349976198871f,
  101283. -0.5555702330196f,-0.5758081914178f,-0.5956993044924f,-0.6152315905806f,
  101284. -0.6343932841636f,-0.6531728429538f,-0.6715589548470f,-0.6895405447371f,
  101285. -0.7071067811865f,-0.7242470829515f,-0.7409511253550f,-0.7572088465065f,
  101286. -0.7730104533627f,-0.7883464276266f,-0.8032075314806f,-0.8175848131516f,
  101287. -0.8314696123025f,-0.8448535652497f,-0.8577286100003f,-0.8700869911087f,
  101288. -0.8819212643484f,-0.8932243011955f,-0.9039892931234f,-0.9142097557035f,
  101289. -0.9238795325113f,-0.9329927988347f,-0.9415440651830f,-0.9495281805930f,
  101290. -0.9569403357322f,-0.9637760657954f,-0.9700312531945f,-0.9757021300385f,
  101291. -0.9807852804032f,-0.9852776423889f,-0.9891765099648f,-0.9924795345987f,
  101292. -0.9951847266722f,-0.9972904566787f,-0.9987954562052f,-0.9996988186962f,
  101293. -1.0000000000000f,
  101294. };
  101295. #define INVSQ_LOOKUP_SZ 32
  101296. static float INVSQ_LOOKUP[INVSQ_LOOKUP_SZ+1]={
  101297. 1.414213562373f,1.392621247646f,1.371988681140f,1.352246807566f,
  101298. 1.333333333333f,1.315191898443f,1.297771369046f,1.281025230441f,
  101299. 1.264911064067f,1.249390095109f,1.234426799697f,1.219988562661f,
  101300. 1.206045378311f,1.192569588000f,1.179535649239f,1.166919931983f,
  101301. 1.154700538379f,1.142857142857f,1.131370849898f,1.120224067222f,
  101302. 1.109400392450f,1.098884511590f,1.088662107904f,1.078719779941f,
  101303. 1.069044967650f,1.059625885652f,1.050451462878f,1.041511287847f,
  101304. 1.032795558989f,1.024295039463f,1.016001016002f,1.007905261358f,
  101305. 1.000000000000f,
  101306. };
  101307. #define INVSQ2EXP_LOOKUP_MIN (-32)
  101308. #define INVSQ2EXP_LOOKUP_MAX 32
  101309. static float INVSQ2EXP_LOOKUP[INVSQ2EXP_LOOKUP_MAX-\
  101310. INVSQ2EXP_LOOKUP_MIN+1]={
  101311. 65536.f, 46340.95001f, 32768.f, 23170.47501f,
  101312. 16384.f, 11585.2375f, 8192.f, 5792.618751f,
  101313. 4096.f, 2896.309376f, 2048.f, 1448.154688f,
  101314. 1024.f, 724.0773439f, 512.f, 362.038672f,
  101315. 256.f, 181.019336f, 128.f, 90.50966799f,
  101316. 64.f, 45.254834f, 32.f, 22.627417f,
  101317. 16.f, 11.3137085f, 8.f, 5.656854249f,
  101318. 4.f, 2.828427125f, 2.f, 1.414213562f,
  101319. 1.f, 0.7071067812f, 0.5f, 0.3535533906f,
  101320. 0.25f, 0.1767766953f, 0.125f, 0.08838834765f,
  101321. 0.0625f, 0.04419417382f, 0.03125f, 0.02209708691f,
  101322. 0.015625f, 0.01104854346f, 0.0078125f, 0.005524271728f,
  101323. 0.00390625f, 0.002762135864f, 0.001953125f, 0.001381067932f,
  101324. 0.0009765625f, 0.000690533966f, 0.00048828125f, 0.000345266983f,
  101325. 0.000244140625f,0.0001726334915f,0.0001220703125f,8.631674575e-05f,
  101326. 6.103515625e-05f,4.315837288e-05f,3.051757812e-05f,2.157918644e-05f,
  101327. 1.525878906e-05f,
  101328. };
  101329. #endif
  101330. #define FROMdB_LOOKUP_SZ 35
  101331. #define FROMdB2_LOOKUP_SZ 32
  101332. #define FROMdB_SHIFT 5
  101333. #define FROMdB2_SHIFT 3
  101334. #define FROMdB2_MASK 31
  101335. static float FROMdB_LOOKUP[FROMdB_LOOKUP_SZ]={
  101336. 1.f, 0.6309573445f, 0.3981071706f, 0.2511886432f,
  101337. 0.1584893192f, 0.1f, 0.06309573445f, 0.03981071706f,
  101338. 0.02511886432f, 0.01584893192f, 0.01f, 0.006309573445f,
  101339. 0.003981071706f, 0.002511886432f, 0.001584893192f, 0.001f,
  101340. 0.0006309573445f,0.0003981071706f,0.0002511886432f,0.0001584893192f,
  101341. 0.0001f,6.309573445e-05f,3.981071706e-05f,2.511886432e-05f,
  101342. 1.584893192e-05f, 1e-05f,6.309573445e-06f,3.981071706e-06f,
  101343. 2.511886432e-06f,1.584893192e-06f, 1e-06f,6.309573445e-07f,
  101344. 3.981071706e-07f,2.511886432e-07f,1.584893192e-07f,
  101345. };
  101346. static float FROMdB2_LOOKUP[FROMdB2_LOOKUP_SZ]={
  101347. 0.9928302478f, 0.9786445908f, 0.9646616199f, 0.9508784391f,
  101348. 0.9372921937f, 0.92390007f, 0.9106992942f, 0.8976871324f,
  101349. 0.8848608897f, 0.8722179097f, 0.8597555737f, 0.8474713009f,
  101350. 0.835362547f, 0.8234268041f, 0.8116616003f, 0.8000644989f,
  101351. 0.7886330981f, 0.7773650302f, 0.7662579617f, 0.755309592f,
  101352. 0.7445176537f, 0.7338799116f, 0.7233941627f, 0.7130582353f,
  101353. 0.7028699885f, 0.6928273125f, 0.6829281272f, 0.6731703824f,
  101354. 0.6635520573f, 0.6540711597f, 0.6447257262f, 0.6355138211f,
  101355. };
  101356. #ifdef INT_LOOKUP
  101357. #define INVSQ_LOOKUP_I_SHIFT 10
  101358. #define INVSQ_LOOKUP_I_MASK 1023
  101359. static long INVSQ_LOOKUP_I[64+1]={
  101360. 92682l, 91966l, 91267l, 90583l,
  101361. 89915l, 89261l, 88621l, 87995l,
  101362. 87381l, 86781l, 86192l, 85616l,
  101363. 85051l, 84497l, 83953l, 83420l,
  101364. 82897l, 82384l, 81880l, 81385l,
  101365. 80899l, 80422l, 79953l, 79492l,
  101366. 79039l, 78594l, 78156l, 77726l,
  101367. 77302l, 76885l, 76475l, 76072l,
  101368. 75674l, 75283l, 74898l, 74519l,
  101369. 74146l, 73778l, 73415l, 73058l,
  101370. 72706l, 72359l, 72016l, 71679l,
  101371. 71347l, 71019l, 70695l, 70376l,
  101372. 70061l, 69750l, 69444l, 69141l,
  101373. 68842l, 68548l, 68256l, 67969l,
  101374. 67685l, 67405l, 67128l, 66855l,
  101375. 66585l, 66318l, 66054l, 65794l,
  101376. 65536l,
  101377. };
  101378. #define COS_LOOKUP_I_SHIFT 9
  101379. #define COS_LOOKUP_I_MASK 511
  101380. #define COS_LOOKUP_I_SZ 128
  101381. static long COS_LOOKUP_I[COS_LOOKUP_I_SZ+1]={
  101382. 16384l, 16379l, 16364l, 16340l,
  101383. 16305l, 16261l, 16207l, 16143l,
  101384. 16069l, 15986l, 15893l, 15791l,
  101385. 15679l, 15557l, 15426l, 15286l,
  101386. 15137l, 14978l, 14811l, 14635l,
  101387. 14449l, 14256l, 14053l, 13842l,
  101388. 13623l, 13395l, 13160l, 12916l,
  101389. 12665l, 12406l, 12140l, 11866l,
  101390. 11585l, 11297l, 11003l, 10702l,
  101391. 10394l, 10080l, 9760l, 9434l,
  101392. 9102l, 8765l, 8423l, 8076l,
  101393. 7723l, 7366l, 7005l, 6639l,
  101394. 6270l, 5897l, 5520l, 5139l,
  101395. 4756l, 4370l, 3981l, 3590l,
  101396. 3196l, 2801l, 2404l, 2006l,
  101397. 1606l, 1205l, 804l, 402l,
  101398. 0l, -401l, -803l, -1204l,
  101399. -1605l, -2005l, -2403l, -2800l,
  101400. -3195l, -3589l, -3980l, -4369l,
  101401. -4755l, -5138l, -5519l, -5896l,
  101402. -6269l, -6638l, -7004l, -7365l,
  101403. -7722l, -8075l, -8422l, -8764l,
  101404. -9101l, -9433l, -9759l, -10079l,
  101405. -10393l, -10701l, -11002l, -11296l,
  101406. -11584l, -11865l, -12139l, -12405l,
  101407. -12664l, -12915l, -13159l, -13394l,
  101408. -13622l, -13841l, -14052l, -14255l,
  101409. -14448l, -14634l, -14810l, -14977l,
  101410. -15136l, -15285l, -15425l, -15556l,
  101411. -15678l, -15790l, -15892l, -15985l,
  101412. -16068l, -16142l, -16206l, -16260l,
  101413. -16304l, -16339l, -16363l, -16378l,
  101414. -16383l,
  101415. };
  101416. #endif
  101417. #endif
  101418. /*** End of inlined file: lookup_data.h ***/
  101419. #ifdef FLOAT_LOOKUP
  101420. float vorbis_coslook(float a){
  101421. double d=a*(.31830989*(float)COS_LOOKUP_SZ);
  101422. int i=vorbis_ftoi(d-.5);
  101423. return COS_LOOKUP[i]+ (d-i)*(COS_LOOKUP[i+1]-COS_LOOKUP[i]);
  101424. }
  101425. float vorbis_invsqlook(float a){
  101426. double d=a*(2.f*(float)INVSQ_LOOKUP_SZ)-(float)INVSQ_LOOKUP_SZ;
  101427. int i=vorbis_ftoi(d-.5f);
  101428. return INVSQ_LOOKUP[i]+ (d-i)*(INVSQ_LOOKUP[i+1]-INVSQ_LOOKUP[i]);
  101429. }
  101430. float vorbis_invsq2explook(int a){
  101431. return INVSQ2EXP_LOOKUP[a-INVSQ2EXP_LOOKUP_MIN];
  101432. }
  101433. #include <stdio.h>
  101434. float vorbis_fromdBlook(float a){
  101435. int i=vorbis_ftoi(a*((float)(-(1<<FROMdB2_SHIFT)))-.5f);
  101436. return (i<0)?1.f:
  101437. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  101438. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  101439. }
  101440. #endif
  101441. #ifdef INT_LOOKUP
  101442. long vorbis_invsqlook_i(long a,long e){
  101443. long i=(a&0x7fff)>>(INVSQ_LOOKUP_I_SHIFT-1);
  101444. long d=(a&INVSQ_LOOKUP_I_MASK)<<(16-INVSQ_LOOKUP_I_SHIFT); /* 0.16 */
  101445. long val=INVSQ_LOOKUP_I[i]- /* 1.16 */
  101446. (((INVSQ_LOOKUP_I[i]-INVSQ_LOOKUP_I[i+1])* /* 0.16 */
  101447. d)>>16); /* result 1.16 */
  101448. e+=32;
  101449. if(e&1)val=(val*5792)>>13; /* multiply val by 1/sqrt(2) */
  101450. e=(e>>1)-8;
  101451. return(val>>e);
  101452. }
  101453. float vorbis_fromdBlook_i(long a){
  101454. int i=(-a)>>(12-FROMdB2_SHIFT);
  101455. return (i<0)?1.f:
  101456. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  101457. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  101458. }
  101459. long vorbis_coslook_i(long a){
  101460. int i=a>>COS_LOOKUP_I_SHIFT;
  101461. int d=a&COS_LOOKUP_I_MASK;
  101462. return COS_LOOKUP_I[i]- ((d*(COS_LOOKUP_I[i]-COS_LOOKUP_I[i+1]))>>
  101463. COS_LOOKUP_I_SHIFT);
  101464. }
  101465. #endif
  101466. #endif
  101467. /*** End of inlined file: lookup.c ***/
  101468. /* catch this in the build system; we #include for
  101469. compilers (like gcc) that can't inline across
  101470. modules */
  101471. static int MLOOP_1[64]={
  101472. 0,10,11,11, 12,12,12,12, 13,13,13,13, 13,13,13,13,
  101473. 14,14,14,14, 14,14,14,14, 14,14,14,14, 14,14,14,14,
  101474. 15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
  101475. 15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
  101476. };
  101477. static int MLOOP_2[64]={
  101478. 0,4,5,5, 6,6,6,6, 7,7,7,7, 7,7,7,7,
  101479. 8,8,8,8, 8,8,8,8, 8,8,8,8, 8,8,8,8,
  101480. 9,9,9,9, 9,9,9,9, 9,9,9,9, 9,9,9,9,
  101481. 9,9,9,9, 9,9,9,9, 9,9,9,9, 9,9,9,9,
  101482. };
  101483. static int MLOOP_3[8]={0,1,2,2,3,3,3,3};
  101484. void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
  101485. float amp,float ampoffset){
  101486. int i;
  101487. int ampoffseti=rint(ampoffset*4096.f);
  101488. int ampi=rint(amp*16.f);
  101489. long *ilsp=alloca(m*sizeof(*ilsp));
  101490. for(i=0;i<m;i++)ilsp[i]=vorbis_coslook_i(lsp[i]/M_PI*65536.f+.5f);
  101491. i=0;
  101492. while(i<n){
  101493. int j,k=map[i];
  101494. unsigned long pi=46341; /* 2**-.5 in 0.16 */
  101495. unsigned long qi=46341;
  101496. int qexp=0,shift;
  101497. long wi=vorbis_coslook_i(k*65536/ln);
  101498. qi*=labs(ilsp[0]-wi);
  101499. pi*=labs(ilsp[1]-wi);
  101500. for(j=3;j<m;j+=2){
  101501. if(!(shift=MLOOP_1[(pi|qi)>>25]))
  101502. if(!(shift=MLOOP_2[(pi|qi)>>19]))
  101503. shift=MLOOP_3[(pi|qi)>>16];
  101504. qi=(qi>>shift)*labs(ilsp[j-1]-wi);
  101505. pi=(pi>>shift)*labs(ilsp[j]-wi);
  101506. qexp+=shift;
  101507. }
  101508. if(!(shift=MLOOP_1[(pi|qi)>>25]))
  101509. if(!(shift=MLOOP_2[(pi|qi)>>19]))
  101510. shift=MLOOP_3[(pi|qi)>>16];
  101511. if(m&1){
  101512. qi=(qi>>shift)*labs(ilsp[j-1]-wi);
  101513. pi=(pi>>shift)<<14;
  101514. qexp+=shift;
  101515. if(!(shift=MLOOP_1[(pi|qi)>>25]))
  101516. if(!(shift=MLOOP_2[(pi|qi)>>19]))
  101517. shift=MLOOP_3[(pi|qi)>>16];
  101518. pi>>=shift;
  101519. qi>>=shift;
  101520. qexp+=shift-14*((m+1)>>1);
  101521. pi=((pi*pi)>>16);
  101522. qi=((qi*qi)>>16);
  101523. qexp=qexp*2+m;
  101524. pi*=(1<<14)-((wi*wi)>>14);
  101525. qi+=pi>>14;
  101526. }else{
  101527. pi>>=shift;
  101528. qi>>=shift;
  101529. qexp+=shift-7*m;
  101530. pi=((pi*pi)>>16);
  101531. qi=((qi*qi)>>16);
  101532. qexp=qexp*2+m;
  101533. pi*=(1<<14)-wi;
  101534. qi*=(1<<14)+wi;
  101535. qi=(qi+pi)>>14;
  101536. }
  101537. if(qi&0xffff0000){ /* checks for 1.xxxxxxxxxxxxxxxx */
  101538. qi>>=1; qexp++;
  101539. }else
  101540. while(qi && !(qi&0x8000)){ /* checks for 0.0xxxxxxxxxxxxxxx or less*/
  101541. qi<<=1; qexp--;
  101542. }
  101543. amp=vorbis_fromdBlook_i(ampi* /* n.4 */
  101544. vorbis_invsqlook_i(qi,qexp)-
  101545. ampoffseti); /* 8.12[0] */
  101546. curve[i]*=amp;
  101547. while(map[++i]==k)curve[i]*=amp;
  101548. }
  101549. }
  101550. #else
  101551. void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
  101552. float amp,float ampoffset){
  101553. int i;
  101554. float wdel=M_PI/ln;
  101555. for(i=0;i<m;i++)lsp[i]=2.f*cos(lsp[i]);
  101556. i=0;
  101557. while(i<n){
  101558. int j,k=map[i];
  101559. float p=.5f;
  101560. float q=.5f;
  101561. float w=2.f*cos(wdel*k);
  101562. for(j=1;j<m;j+=2){
  101563. q *= w-lsp[j-1];
  101564. p *= w-lsp[j];
  101565. }
  101566. if(j==m){
  101567. q*=w-lsp[j-1];
  101568. p*=p*(4.f-w*w);
  101569. q*=q;
  101570. }else{
  101571. p*=p*(2.f-w);
  101572. q*=q*(2.f+w);
  101573. }
  101574. q=fromdB(amp/sqrt(p+q)-ampoffset);
  101575. curve[i]*=q;
  101576. while(map[++i]==k)curve[i]*=q;
  101577. }
  101578. }
  101579. #endif
  101580. #endif
  101581. static void cheby(float *g, int ord) {
  101582. int i, j;
  101583. g[0] *= .5f;
  101584. for(i=2; i<= ord; i++) {
  101585. for(j=ord; j >= i; j--) {
  101586. g[j-2] -= g[j];
  101587. g[j] += g[j];
  101588. }
  101589. }
  101590. }
  101591. static int comp(const void *a,const void *b){
  101592. return (*(float *)a<*(float *)b)-(*(float *)a>*(float *)b);
  101593. }
  101594. #define EPSILON 10e-7
  101595. static int Laguerre_With_Deflation(float *a,int ord,float *r){
  101596. int i,m;
  101597. double lastdelta=0.f;
  101598. double *defl=(double*)alloca(sizeof(*defl)*(ord+1));
  101599. for(i=0;i<=ord;i++)defl[i]=a[i];
  101600. for(m=ord;m>0;m--){
  101601. double newx=0.f,delta;
  101602. while(1){
  101603. double p=defl[m],pp=0.f,ppp=0.f,denom;
  101604. for(i=m;i>0;i--){
  101605. ppp = newx*ppp + pp;
  101606. pp = newx*pp + p;
  101607. p = newx*p + defl[i-1];
  101608. }
  101609. denom=(m-1) * ((m-1)*pp*pp - m*p*ppp);
  101610. if(denom<0)
  101611. return(-1); /* complex root! The LPC generator handed us a bad filter */
  101612. if(pp>0){
  101613. denom = pp + sqrt(denom);
  101614. if(denom<EPSILON)denom=EPSILON;
  101615. }else{
  101616. denom = pp - sqrt(denom);
  101617. if(denom>-(EPSILON))denom=-(EPSILON);
  101618. }
  101619. delta = m*p/denom;
  101620. newx -= delta;
  101621. if(delta<0.f)delta*=-1;
  101622. if(fabs(delta/newx)<10e-12)break;
  101623. lastdelta=delta;
  101624. }
  101625. r[m-1]=newx;
  101626. for(i=m;i>0;i--)
  101627. defl[i-1]+=newx*defl[i];
  101628. defl++;
  101629. }
  101630. return(0);
  101631. }
  101632. static int Newton_Raphson(float *a,int ord,float *r){
  101633. int i, k, count=0;
  101634. double error=1.f;
  101635. double *root=(double*)alloca(ord*sizeof(*root));
  101636. for(i=0; i<ord;i++) root[i] = r[i];
  101637. while(error>1e-20){
  101638. error=0;
  101639. for(i=0; i<ord; i++) { /* Update each point. */
  101640. double pp=0.,delta;
  101641. double rooti=root[i];
  101642. double p=a[ord];
  101643. for(k=ord-1; k>= 0; k--) {
  101644. pp= pp* rooti + p;
  101645. p = p * rooti + a[k];
  101646. }
  101647. delta = p/pp;
  101648. root[i] -= delta;
  101649. error+= delta*delta;
  101650. }
  101651. if(count>40)return(-1);
  101652. count++;
  101653. }
  101654. for(i=0; i<ord;i++) r[i] = root[i];
  101655. return(0);
  101656. }
  101657. int vorbis_lpc_to_lsp(float *lpc,float *lsp,int m){
  101658. int order2=(m+1)>>1;
  101659. int g1_order,g2_order;
  101660. float *g1=(float*)alloca(sizeof(*g1)*(order2+1));
  101661. float *g2=(float*)alloca(sizeof(*g2)*(order2+1));
  101662. float *g1r=(float*)alloca(sizeof(*g1r)*(order2+1));
  101663. float *g2r=(float*)alloca(sizeof(*g2r)*(order2+1));
  101664. int i;
  101665. g1_order=(m+1)>>1;
  101666. g2_order=(m) >>1;
  101667. g1[g1_order] = 1.f;
  101668. for(i=1;i<=g1_order;i++) g1[g1_order-i] = lpc[i-1]+lpc[m-i];
  101669. g2[g2_order] = 1.f;
  101670. for(i=1;i<=g2_order;i++) g2[g2_order-i] = lpc[i-1]-lpc[m-i];
  101671. if(g1_order>g2_order){
  101672. for(i=2; i<=g2_order;i++) g2[g2_order-i] += g2[g2_order-i+2];
  101673. }else{
  101674. for(i=1; i<=g1_order;i++) g1[g1_order-i] -= g1[g1_order-i+1];
  101675. for(i=1; i<=g2_order;i++) g2[g2_order-i] += g2[g2_order-i+1];
  101676. }
  101677. cheby(g1,g1_order);
  101678. cheby(g2,g2_order);
  101679. if(Laguerre_With_Deflation(g1,g1_order,g1r) ||
  101680. Laguerre_With_Deflation(g2,g2_order,g2r))
  101681. return(-1);
  101682. Newton_Raphson(g1,g1_order,g1r); /* if it fails, it leaves g1r alone */
  101683. Newton_Raphson(g2,g2_order,g2r); /* if it fails, it leaves g2r alone */
  101684. qsort(g1r,g1_order,sizeof(*g1r),comp);
  101685. qsort(g2r,g2_order,sizeof(*g2r),comp);
  101686. for(i=0;i<g1_order;i++)
  101687. lsp[i*2] = acos(g1r[i]);
  101688. for(i=0;i<g2_order;i++)
  101689. lsp[i*2+1] = acos(g2r[i]);
  101690. return(0);
  101691. }
  101692. #endif
  101693. /*** End of inlined file: lsp.c ***/
  101694. /*** Start of inlined file: mapping0.c ***/
  101695. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  101696. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  101697. // tasks..
  101698. #if JUCE_MSVC
  101699. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  101700. #endif
  101701. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  101702. #if JUCE_USE_OGGVORBIS
  101703. #include <stdlib.h>
  101704. #include <stdio.h>
  101705. #include <string.h>
  101706. #include <math.h>
  101707. static void mapping0_free_info(vorbis_info_mapping *i){
  101708. vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)i;
  101709. if(info){
  101710. memset(info,0,sizeof(*info));
  101711. _ogg_free(info);
  101712. }
  101713. }
  101714. static int ilog3(unsigned int v){
  101715. int ret=0;
  101716. if(v)--v;
  101717. while(v){
  101718. ret++;
  101719. v>>=1;
  101720. }
  101721. return(ret);
  101722. }
  101723. static void mapping0_pack(vorbis_info *vi,vorbis_info_mapping *vm,
  101724. oggpack_buffer *opb){
  101725. int i;
  101726. vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)vm;
  101727. if(info->submaps>1){
  101728. oggpack_write(opb,1,1);
  101729. oggpack_write(opb,info->submaps-1,4);
  101730. }else
  101731. oggpack_write(opb,0,1);
  101732. if(info->coupling_steps>0){
  101733. oggpack_write(opb,1,1);
  101734. oggpack_write(opb,info->coupling_steps-1,8);
  101735. for(i=0;i<info->coupling_steps;i++){
  101736. oggpack_write(opb,info->coupling_mag[i],ilog3(vi->channels));
  101737. oggpack_write(opb,info->coupling_ang[i],ilog3(vi->channels));
  101738. }
  101739. }else
  101740. oggpack_write(opb,0,1);
  101741. oggpack_write(opb,0,2); /* 2,3:reserved */
  101742. if(info->submaps>1){
  101743. for(i=0;i<vi->channels;i++)
  101744. oggpack_write(opb,info->chmuxlist[i],4);
  101745. }
  101746. for(i=0;i<info->submaps;i++){
  101747. oggpack_write(opb,0,8); /* time submap unused */
  101748. oggpack_write(opb,info->floorsubmap[i],8);
  101749. oggpack_write(opb,info->residuesubmap[i],8);
  101750. }
  101751. }
  101752. static vorbis_info_mapping *mapping0_unpack(vorbis_info *vi,oggpack_buffer *opb){
  101753. int i;
  101754. vorbis_info_mapping0 *info=(vorbis_info_mapping0*)_ogg_calloc(1,sizeof(*info));
  101755. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  101756. memset(info,0,sizeof(*info));
  101757. if(oggpack_read(opb,1))
  101758. info->submaps=oggpack_read(opb,4)+1;
  101759. else
  101760. info->submaps=1;
  101761. if(oggpack_read(opb,1)){
  101762. info->coupling_steps=oggpack_read(opb,8)+1;
  101763. for(i=0;i<info->coupling_steps;i++){
  101764. int testM=info->coupling_mag[i]=oggpack_read(opb,ilog3(vi->channels));
  101765. int testA=info->coupling_ang[i]=oggpack_read(opb,ilog3(vi->channels));
  101766. if(testM<0 ||
  101767. testA<0 ||
  101768. testM==testA ||
  101769. testM>=vi->channels ||
  101770. testA>=vi->channels) goto err_out;
  101771. }
  101772. }
  101773. if(oggpack_read(opb,2)>0)goto err_out; /* 2,3:reserved */
  101774. if(info->submaps>1){
  101775. for(i=0;i<vi->channels;i++){
  101776. info->chmuxlist[i]=oggpack_read(opb,4);
  101777. if(info->chmuxlist[i]>=info->submaps)goto err_out;
  101778. }
  101779. }
  101780. for(i=0;i<info->submaps;i++){
  101781. oggpack_read(opb,8); /* time submap unused */
  101782. info->floorsubmap[i]=oggpack_read(opb,8);
  101783. if(info->floorsubmap[i]>=ci->floors)goto err_out;
  101784. info->residuesubmap[i]=oggpack_read(opb,8);
  101785. if(info->residuesubmap[i]>=ci->residues)goto err_out;
  101786. }
  101787. return info;
  101788. err_out:
  101789. mapping0_free_info(info);
  101790. return(NULL);
  101791. }
  101792. #if 0
  101793. static long seq=0;
  101794. static ogg_int64_t total=0;
  101795. static float FLOOR1_fromdB_LOOKUP[256]={
  101796. 1.0649863e-07F, 1.1341951e-07F, 1.2079015e-07F, 1.2863978e-07F,
  101797. 1.3699951e-07F, 1.4590251e-07F, 1.5538408e-07F, 1.6548181e-07F,
  101798. 1.7623575e-07F, 1.8768855e-07F, 1.9988561e-07F, 2.128753e-07F,
  101799. 2.2670913e-07F, 2.4144197e-07F, 2.5713223e-07F, 2.7384213e-07F,
  101800. 2.9163793e-07F, 3.1059021e-07F, 3.3077411e-07F, 3.5226968e-07F,
  101801. 3.7516214e-07F, 3.9954229e-07F, 4.2550680e-07F, 4.5315863e-07F,
  101802. 4.8260743e-07F, 5.1396998e-07F, 5.4737065e-07F, 5.8294187e-07F,
  101803. 6.2082472e-07F, 6.6116941e-07F, 7.0413592e-07F, 7.4989464e-07F,
  101804. 7.9862701e-07F, 8.5052630e-07F, 9.0579828e-07F, 9.6466216e-07F,
  101805. 1.0273513e-06F, 1.0941144e-06F, 1.1652161e-06F, 1.2409384e-06F,
  101806. 1.3215816e-06F, 1.4074654e-06F, 1.4989305e-06F, 1.5963394e-06F,
  101807. 1.7000785e-06F, 1.8105592e-06F, 1.9282195e-06F, 2.0535261e-06F,
  101808. 2.1869758e-06F, 2.3290978e-06F, 2.4804557e-06F, 2.6416497e-06F,
  101809. 2.8133190e-06F, 2.9961443e-06F, 3.1908506e-06F, 3.3982101e-06F,
  101810. 3.6190449e-06F, 3.8542308e-06F, 4.1047004e-06F, 4.3714470e-06F,
  101811. 4.6555282e-06F, 4.9580707e-06F, 5.2802740e-06F, 5.6234160e-06F,
  101812. 5.9888572e-06F, 6.3780469e-06F, 6.7925283e-06F, 7.2339451e-06F,
  101813. 7.7040476e-06F, 8.2047000e-06F, 8.7378876e-06F, 9.3057248e-06F,
  101814. 9.9104632e-06F, 1.0554501e-05F, 1.1240392e-05F, 1.1970856e-05F,
  101815. 1.2748789e-05F, 1.3577278e-05F, 1.4459606e-05F, 1.5399272e-05F,
  101816. 1.6400004e-05F, 1.7465768e-05F, 1.8600792e-05F, 1.9809576e-05F,
  101817. 2.1096914e-05F, 2.2467911e-05F, 2.3928002e-05F, 2.5482978e-05F,
  101818. 2.7139006e-05F, 2.8902651e-05F, 3.0780908e-05F, 3.2781225e-05F,
  101819. 3.4911534e-05F, 3.7180282e-05F, 3.9596466e-05F, 4.2169667e-05F,
  101820. 4.4910090e-05F, 4.7828601e-05F, 5.0936773e-05F, 5.4246931e-05F,
  101821. 5.7772202e-05F, 6.1526565e-05F, 6.5524908e-05F, 6.9783085e-05F,
  101822. 7.4317983e-05F, 7.9147585e-05F, 8.4291040e-05F, 8.9768747e-05F,
  101823. 9.5602426e-05F, 0.00010181521F, 0.00010843174F, 0.00011547824F,
  101824. 0.00012298267F, 0.00013097477F, 0.00013948625F, 0.00014855085F,
  101825. 0.00015820453F, 0.00016848555F, 0.00017943469F, 0.00019109536F,
  101826. 0.00020351382F, 0.00021673929F, 0.00023082423F, 0.00024582449F,
  101827. 0.00026179955F, 0.00027881276F, 0.00029693158F, 0.00031622787F,
  101828. 0.00033677814F, 0.00035866388F, 0.00038197188F, 0.00040679456F,
  101829. 0.00043323036F, 0.00046138411F, 0.00049136745F, 0.00052329927F,
  101830. 0.00055730621F, 0.00059352311F, 0.00063209358F, 0.00067317058F,
  101831. 0.00071691700F, 0.00076350630F, 0.00081312324F, 0.00086596457F,
  101832. 0.00092223983F, 0.00098217216F, 0.0010459992F, 0.0011139742F,
  101833. 0.0011863665F, 0.0012634633F, 0.0013455702F, 0.0014330129F,
  101834. 0.0015261382F, 0.0016253153F, 0.0017309374F, 0.0018434235F,
  101835. 0.0019632195F, 0.0020908006F, 0.0022266726F, 0.0023713743F,
  101836. 0.0025254795F, 0.0026895994F, 0.0028643847F, 0.0030505286F,
  101837. 0.0032487691F, 0.0034598925F, 0.0036847358F, 0.0039241906F,
  101838. 0.0041792066F, 0.0044507950F, 0.0047400328F, 0.0050480668F,
  101839. 0.0053761186F, 0.0057254891F, 0.0060975636F, 0.0064938176F,
  101840. 0.0069158225F, 0.0073652516F, 0.0078438871F, 0.0083536271F,
  101841. 0.0088964928F, 0.009474637F, 0.010090352F, 0.010746080F,
  101842. 0.011444421F, 0.012188144F, 0.012980198F, 0.013823725F,
  101843. 0.014722068F, 0.015678791F, 0.016697687F, 0.017782797F,
  101844. 0.018938423F, 0.020169149F, 0.021479854F, 0.022875735F,
  101845. 0.024362330F, 0.025945531F, 0.027631618F, 0.029427276F,
  101846. 0.031339626F, 0.033376252F, 0.035545228F, 0.037855157F,
  101847. 0.040315199F, 0.042935108F, 0.045725273F, 0.048696758F,
  101848. 0.051861348F, 0.055231591F, 0.058820850F, 0.062643361F,
  101849. 0.066714279F, 0.071049749F, 0.075666962F, 0.080584227F,
  101850. 0.085821044F, 0.091398179F, 0.097337747F, 0.10366330F,
  101851. 0.11039993F, 0.11757434F, 0.12521498F, 0.13335215F,
  101852. 0.14201813F, 0.15124727F, 0.16107617F, 0.17154380F,
  101853. 0.18269168F, 0.19456402F, 0.20720788F, 0.22067342F,
  101854. 0.23501402F, 0.25028656F, 0.26655159F, 0.28387361F,
  101855. 0.30232132F, 0.32196786F, 0.34289114F, 0.36517414F,
  101856. 0.38890521F, 0.41417847F, 0.44109412F, 0.46975890F,
  101857. 0.50028648F, 0.53279791F, 0.56742212F, 0.60429640F,
  101858. 0.64356699F, 0.68538959F, 0.72993007F, 0.77736504F,
  101859. 0.82788260F, 0.88168307F, 0.9389798F, 1.F,
  101860. };
  101861. #endif
  101862. extern int *floor1_fit(vorbis_block *vb,void *look,
  101863. const float *logmdct, /* in */
  101864. const float *logmask);
  101865. extern int *floor1_interpolate_fit(vorbis_block *vb,void *look,
  101866. int *A,int *B,
  101867. int del);
  101868. extern int floor1_encode(oggpack_buffer *opb,vorbis_block *vb,
  101869. void*look,
  101870. int *post,int *ilogmask);
  101871. static int mapping0_forward(vorbis_block *vb){
  101872. vorbis_dsp_state *vd=vb->vd;
  101873. vorbis_info *vi=vd->vi;
  101874. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  101875. private_state *b=(private_state*)vb->vd->backend_state;
  101876. vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
  101877. int n=vb->pcmend;
  101878. int i,j,k;
  101879. int *nonzero = (int*) alloca(sizeof(*nonzero)*vi->channels);
  101880. float **gmdct = (float**) _vorbis_block_alloc(vb,vi->channels*sizeof(*gmdct));
  101881. int **ilogmaskch= (int**) _vorbis_block_alloc(vb,vi->channels*sizeof(*ilogmaskch));
  101882. int ***floor_posts = (int***) _vorbis_block_alloc(vb,vi->channels*sizeof(*floor_posts));
  101883. float global_ampmax=vbi->ampmax;
  101884. float *local_ampmax=(float*)alloca(sizeof(*local_ampmax)*vi->channels);
  101885. int blocktype=vbi->blocktype;
  101886. int modenumber=vb->W;
  101887. vorbis_info_mapping0 *info=(vorbis_info_mapping0*)ci->map_param[modenumber];
  101888. vorbis_look_psy *psy_look=
  101889. b->psy+blocktype+(vb->W?2:0);
  101890. vb->mode=modenumber;
  101891. for(i=0;i<vi->channels;i++){
  101892. float scale=4.f/n;
  101893. float scale_dB;
  101894. float *pcm =vb->pcm[i];
  101895. float *logfft =pcm;
  101896. gmdct[i]=(float*)_vorbis_block_alloc(vb,n/2*sizeof(**gmdct));
  101897. scale_dB=todB(&scale) + .345; /* + .345 is a hack; the original
  101898. todB estimation used on IEEE 754
  101899. compliant machines had a bug that
  101900. returned dB values about a third
  101901. of a decibel too high. The bug
  101902. was harmless because tunings
  101903. implicitly took that into
  101904. account. However, fixing the bug
  101905. in the estimator requires
  101906. changing all the tunings as well.
  101907. For now, it's easier to sync
  101908. things back up here, and
  101909. recalibrate the tunings in the
  101910. next major model upgrade. */
  101911. #if 0
  101912. if(vi->channels==2)
  101913. if(i==0)
  101914. _analysis_output("pcmL",seq,pcm,n,0,0,total-n/2);
  101915. else
  101916. _analysis_output("pcmR",seq,pcm,n,0,0,total-n/2);
  101917. #endif
  101918. _vorbis_apply_window(pcm,b->window,ci->blocksizes,vb->lW,vb->W,vb->nW);
  101919. #if 0
  101920. if(vi->channels==2)
  101921. if(i==0)
  101922. _analysis_output("windowedL",seq,pcm,n,0,0,total-n/2);
  101923. else
  101924. _analysis_output("windowedR",seq,pcm,n,0,0,total-n/2);
  101925. #endif
  101926. mdct_forward((mdct_lookup*) b->transform[vb->W][0],pcm,gmdct[i]);
  101927. drft_forward(&b->fft_look[vb->W],pcm);
  101928. logfft[0]=scale_dB+todB(pcm) + .345; /* + .345 is a hack; the
  101929. original todB estimation used on
  101930. IEEE 754 compliant machines had a
  101931. bug that returned dB values about
  101932. a third of a decibel too high.
  101933. The bug was harmless because
  101934. tunings implicitly took that into
  101935. account. However, fixing the bug
  101936. in the estimator requires
  101937. changing all the tunings as well.
  101938. For now, it's easier to sync
  101939. things back up here, and
  101940. recalibrate the tunings in the
  101941. next major model upgrade. */
  101942. local_ampmax[i]=logfft[0];
  101943. for(j=1;j<n-1;j+=2){
  101944. float temp=pcm[j]*pcm[j]+pcm[j+1]*pcm[j+1];
  101945. temp=logfft[(j+1)>>1]=scale_dB+.5f*todB(&temp) + .345; /* +
  101946. .345 is a hack; the original todB
  101947. estimation used on IEEE 754
  101948. compliant machines had a bug that
  101949. returned dB values about a third
  101950. of a decibel too high. The bug
  101951. was harmless because tunings
  101952. implicitly took that into
  101953. account. However, fixing the bug
  101954. in the estimator requires
  101955. changing all the tunings as well.
  101956. For now, it's easier to sync
  101957. things back up here, and
  101958. recalibrate the tunings in the
  101959. next major model upgrade. */
  101960. if(temp>local_ampmax[i])local_ampmax[i]=temp;
  101961. }
  101962. if(local_ampmax[i]>0.f)local_ampmax[i]=0.f;
  101963. if(local_ampmax[i]>global_ampmax)global_ampmax=local_ampmax[i];
  101964. #if 0
  101965. if(vi->channels==2){
  101966. if(i==0){
  101967. _analysis_output("fftL",seq,logfft,n/2,1,0,0);
  101968. }else{
  101969. _analysis_output("fftR",seq,logfft,n/2,1,0,0);
  101970. }
  101971. }
  101972. #endif
  101973. }
  101974. {
  101975. float *noise = (float*) _vorbis_block_alloc(vb,n/2*sizeof(*noise));
  101976. float *tone = (float*) _vorbis_block_alloc(vb,n/2*sizeof(*tone));
  101977. for(i=0;i<vi->channels;i++){
  101978. int submap=info->chmuxlist[i];
  101979. float *mdct =gmdct[i];
  101980. float *logfft =vb->pcm[i];
  101981. float *logmdct =logfft+n/2;
  101982. float *logmask =logfft;
  101983. vb->mode=modenumber;
  101984. floor_posts[i]=(int**) _vorbis_block_alloc(vb,PACKETBLOBS*sizeof(**floor_posts));
  101985. memset(floor_posts[i],0,sizeof(**floor_posts)*PACKETBLOBS);
  101986. for(j=0;j<n/2;j++)
  101987. logmdct[j]=todB(mdct+j) + .345; /* + .345 is a hack; the original
  101988. todB estimation used on IEEE 754
  101989. compliant machines had a bug that
  101990. returned dB values about a third
  101991. of a decibel too high. The bug
  101992. was harmless because tunings
  101993. implicitly took that into
  101994. account. However, fixing the bug
  101995. in the estimator requires
  101996. changing all the tunings as well.
  101997. For now, it's easier to sync
  101998. things back up here, and
  101999. recalibrate the tunings in the
  102000. next major model upgrade. */
  102001. #if 0
  102002. if(vi->channels==2){
  102003. if(i==0)
  102004. _analysis_output("mdctL",seq,logmdct,n/2,1,0,0);
  102005. else
  102006. _analysis_output("mdctR",seq,logmdct,n/2,1,0,0);
  102007. }else{
  102008. _analysis_output("mdct",seq,logmdct,n/2,1,0,0);
  102009. }
  102010. #endif
  102011. _vp_noisemask(psy_look,
  102012. logmdct,
  102013. noise); /* noise does not have by-frequency offset
  102014. bias applied yet */
  102015. #if 0
  102016. if(vi->channels==2){
  102017. if(i==0)
  102018. _analysis_output("noiseL",seq,noise,n/2,1,0,0);
  102019. else
  102020. _analysis_output("noiseR",seq,noise,n/2,1,0,0);
  102021. }
  102022. #endif
  102023. _vp_tonemask(psy_look,
  102024. logfft,
  102025. tone,
  102026. global_ampmax,
  102027. local_ampmax[i]);
  102028. #if 0
  102029. if(vi->channels==2){
  102030. if(i==0)
  102031. _analysis_output("toneL",seq,tone,n/2,1,0,0);
  102032. else
  102033. _analysis_output("toneR",seq,tone,n/2,1,0,0);
  102034. }
  102035. #endif
  102036. #if 0
  102037. {
  102038. float aotuv[psy_look->n];
  102039. #endif
  102040. _vp_offset_and_mix(psy_look,
  102041. noise,
  102042. tone,
  102043. 1,
  102044. logmask,
  102045. mdct,
  102046. logmdct);
  102047. #if 0
  102048. if(vi->channels==2){
  102049. if(i==0)
  102050. _analysis_output("aotuvM1_L",seq,aotuv,psy_look->n,1,1,0);
  102051. else
  102052. _analysis_output("aotuvM1_R",seq,aotuv,psy_look->n,1,1,0);
  102053. }
  102054. }
  102055. #endif
  102056. #if 0
  102057. if(vi->channels==2){
  102058. if(i==0)
  102059. _analysis_output("mask1L",seq,logmask,n/2,1,0,0);
  102060. else
  102061. _analysis_output("mask1R",seq,logmask,n/2,1,0,0);
  102062. }
  102063. #endif
  102064. if(ci->floor_type[info->floorsubmap[submap]]!=1)return(-1);
  102065. floor_posts[i][PACKETBLOBS/2]=
  102066. floor1_fit(vb,b->flr[info->floorsubmap[submap]],
  102067. logmdct,
  102068. logmask);
  102069. if(vorbis_bitrate_managed(vb) && floor_posts[i][PACKETBLOBS/2]){
  102070. _vp_offset_and_mix(psy_look,
  102071. noise,
  102072. tone,
  102073. 2,
  102074. logmask,
  102075. mdct,
  102076. logmdct);
  102077. #if 0
  102078. if(vi->channels==2){
  102079. if(i==0)
  102080. _analysis_output("mask2L",seq,logmask,n/2,1,0,0);
  102081. else
  102082. _analysis_output("mask2R",seq,logmask,n/2,1,0,0);
  102083. }
  102084. #endif
  102085. floor_posts[i][PACKETBLOBS-1]=
  102086. floor1_fit(vb,b->flr[info->floorsubmap[submap]],
  102087. logmdct,
  102088. logmask);
  102089. _vp_offset_and_mix(psy_look,
  102090. noise,
  102091. tone,
  102092. 0,
  102093. logmask,
  102094. mdct,
  102095. logmdct);
  102096. #if 0
  102097. if(vi->channels==2)
  102098. if(i==0)
  102099. _analysis_output("mask0L",seq,logmask,n/2,1,0,0);
  102100. else
  102101. _analysis_output("mask0R",seq,logmask,n/2,1,0,0);
  102102. #endif
  102103. floor_posts[i][0]=
  102104. floor1_fit(vb,b->flr[info->floorsubmap[submap]],
  102105. logmdct,
  102106. logmask);
  102107. for(k=1;k<PACKETBLOBS/2;k++)
  102108. floor_posts[i][k]=
  102109. floor1_interpolate_fit(vb,b->flr[info->floorsubmap[submap]],
  102110. floor_posts[i][0],
  102111. floor_posts[i][PACKETBLOBS/2],
  102112. k*65536/(PACKETBLOBS/2));
  102113. for(k=PACKETBLOBS/2+1;k<PACKETBLOBS-1;k++)
  102114. floor_posts[i][k]=
  102115. floor1_interpolate_fit(vb,b->flr[info->floorsubmap[submap]],
  102116. floor_posts[i][PACKETBLOBS/2],
  102117. floor_posts[i][PACKETBLOBS-1],
  102118. (k-PACKETBLOBS/2)*65536/(PACKETBLOBS/2));
  102119. }
  102120. }
  102121. }
  102122. vbi->ampmax=global_ampmax;
  102123. {
  102124. float **res_bundle=(float**) alloca(sizeof(*res_bundle)*vi->channels);
  102125. float **couple_bundle=(float**) alloca(sizeof(*couple_bundle)*vi->channels);
  102126. int *zerobundle=(int*) alloca(sizeof(*zerobundle)*vi->channels);
  102127. int **sortindex=(int**) alloca(sizeof(*sortindex)*vi->channels);
  102128. float **mag_memo;
  102129. int **mag_sort;
  102130. if(info->coupling_steps){
  102131. mag_memo=_vp_quantize_couple_memo(vb,
  102132. &ci->psy_g_param,
  102133. psy_look,
  102134. info,
  102135. gmdct);
  102136. mag_sort=_vp_quantize_couple_sort(vb,
  102137. psy_look,
  102138. info,
  102139. mag_memo);
  102140. hf_reduction(&ci->psy_g_param,
  102141. psy_look,
  102142. info,
  102143. mag_memo);
  102144. }
  102145. memset(sortindex,0,sizeof(*sortindex)*vi->channels);
  102146. if(psy_look->vi->normal_channel_p){
  102147. for(i=0;i<vi->channels;i++){
  102148. float *mdct =gmdct[i];
  102149. sortindex[i]=(int*) alloca(sizeof(**sortindex)*n/2);
  102150. _vp_noise_normalize_sort(psy_look,mdct,sortindex[i]);
  102151. }
  102152. }
  102153. for(k=(vorbis_bitrate_managed(vb)?0:PACKETBLOBS/2);
  102154. k<=(vorbis_bitrate_managed(vb)?PACKETBLOBS-1:PACKETBLOBS/2);
  102155. k++){
  102156. oggpack_buffer *opb=vbi->packetblob[k];
  102157. oggpack_write(opb,0,1);
  102158. oggpack_write(opb,modenumber,b->modebits);
  102159. if(vb->W){
  102160. oggpack_write(opb,vb->lW,1);
  102161. oggpack_write(opb,vb->nW,1);
  102162. }
  102163. for(i=0;i<vi->channels;i++){
  102164. int submap=info->chmuxlist[i];
  102165. float *mdct =gmdct[i];
  102166. float *res =vb->pcm[i];
  102167. int *ilogmask=ilogmaskch[i]=
  102168. (int*) _vorbis_block_alloc(vb,n/2*sizeof(**gmdct));
  102169. nonzero[i]=floor1_encode(opb,vb,b->flr[info->floorsubmap[submap]],
  102170. floor_posts[i][k],
  102171. ilogmask);
  102172. #if 0
  102173. {
  102174. char buf[80];
  102175. sprintf(buf,"maskI%c%d",i?'R':'L',k);
  102176. float work[n/2];
  102177. for(j=0;j<n/2;j++)
  102178. work[j]=FLOOR1_fromdB_LOOKUP[ilogmask[j]];
  102179. _analysis_output(buf,seq,work,n/2,1,1,0);
  102180. }
  102181. #endif
  102182. _vp_remove_floor(psy_look,
  102183. mdct,
  102184. ilogmask,
  102185. res,
  102186. ci->psy_g_param.sliding_lowpass[vb->W][k]);
  102187. _vp_noise_normalize(psy_look,res,res+n/2,sortindex[i]);
  102188. #if 0
  102189. {
  102190. char buf[80];
  102191. float work[n/2];
  102192. for(j=0;j<n/2;j++)
  102193. work[j]=FLOOR1_fromdB_LOOKUP[ilogmask[j]]*(res+n/2)[j];
  102194. sprintf(buf,"resI%c%d",i?'R':'L',k);
  102195. _analysis_output(buf,seq,work,n/2,1,1,0);
  102196. }
  102197. #endif
  102198. }
  102199. if(info->coupling_steps){
  102200. _vp_couple(k,
  102201. &ci->psy_g_param,
  102202. psy_look,
  102203. info,
  102204. vb->pcm,
  102205. mag_memo,
  102206. mag_sort,
  102207. ilogmaskch,
  102208. nonzero,
  102209. ci->psy_g_param.sliding_lowpass[vb->W][k]);
  102210. }
  102211. for(i=0;i<info->submaps;i++){
  102212. int ch_in_bundle=0;
  102213. long **classifications;
  102214. int resnum=info->residuesubmap[i];
  102215. for(j=0;j<vi->channels;j++){
  102216. if(info->chmuxlist[j]==i){
  102217. zerobundle[ch_in_bundle]=0;
  102218. if(nonzero[j])zerobundle[ch_in_bundle]=1;
  102219. res_bundle[ch_in_bundle]=vb->pcm[j];
  102220. couple_bundle[ch_in_bundle++]=vb->pcm[j]+n/2;
  102221. }
  102222. }
  102223. classifications=_residue_P[ci->residue_type[resnum]]->
  102224. classx(vb,b->residue[resnum],couple_bundle,zerobundle,ch_in_bundle);
  102225. _residue_P[ci->residue_type[resnum]]->
  102226. forward(opb,vb,b->residue[resnum],
  102227. couple_bundle,NULL,zerobundle,ch_in_bundle,classifications);
  102228. }
  102229. }
  102230. }
  102231. #if 0
  102232. seq++;
  102233. total+=ci->blocksizes[vb->W]/4+ci->blocksizes[vb->nW]/4;
  102234. #endif
  102235. return(0);
  102236. }
  102237. static int mapping0_inverse(vorbis_block *vb,vorbis_info_mapping *l){
  102238. vorbis_dsp_state *vd=vb->vd;
  102239. vorbis_info *vi=vd->vi;
  102240. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  102241. private_state *b=(private_state*)vd->backend_state;
  102242. vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)l;
  102243. int i,j;
  102244. long n=vb->pcmend=ci->blocksizes[vb->W];
  102245. float **pcmbundle=(float**) alloca(sizeof(*pcmbundle)*vi->channels);
  102246. int *zerobundle=(int*) alloca(sizeof(*zerobundle)*vi->channels);
  102247. int *nonzero =(int*) alloca(sizeof(*nonzero)*vi->channels);
  102248. void **floormemo=(void**) alloca(sizeof(*floormemo)*vi->channels);
  102249. for(i=0;i<vi->channels;i++){
  102250. int submap=info->chmuxlist[i];
  102251. floormemo[i]=_floor_P[ci->floor_type[info->floorsubmap[submap]]]->
  102252. inverse1(vb,b->flr[info->floorsubmap[submap]]);
  102253. if(floormemo[i])
  102254. nonzero[i]=1;
  102255. else
  102256. nonzero[i]=0;
  102257. memset(vb->pcm[i],0,sizeof(*vb->pcm[i])*n/2);
  102258. }
  102259. for(i=0;i<info->coupling_steps;i++){
  102260. if(nonzero[info->coupling_mag[i]] ||
  102261. nonzero[info->coupling_ang[i]]){
  102262. nonzero[info->coupling_mag[i]]=1;
  102263. nonzero[info->coupling_ang[i]]=1;
  102264. }
  102265. }
  102266. for(i=0;i<info->submaps;i++){
  102267. int ch_in_bundle=0;
  102268. for(j=0;j<vi->channels;j++){
  102269. if(info->chmuxlist[j]==i){
  102270. if(nonzero[j])
  102271. zerobundle[ch_in_bundle]=1;
  102272. else
  102273. zerobundle[ch_in_bundle]=0;
  102274. pcmbundle[ch_in_bundle++]=vb->pcm[j];
  102275. }
  102276. }
  102277. _residue_P[ci->residue_type[info->residuesubmap[i]]]->
  102278. inverse(vb,b->residue[info->residuesubmap[i]],
  102279. pcmbundle,zerobundle,ch_in_bundle);
  102280. }
  102281. for(i=info->coupling_steps-1;i>=0;i--){
  102282. float *pcmM=vb->pcm[info->coupling_mag[i]];
  102283. float *pcmA=vb->pcm[info->coupling_ang[i]];
  102284. for(j=0;j<n/2;j++){
  102285. float mag=pcmM[j];
  102286. float ang=pcmA[j];
  102287. if(mag>0)
  102288. if(ang>0){
  102289. pcmM[j]=mag;
  102290. pcmA[j]=mag-ang;
  102291. }else{
  102292. pcmA[j]=mag;
  102293. pcmM[j]=mag+ang;
  102294. }
  102295. else
  102296. if(ang>0){
  102297. pcmM[j]=mag;
  102298. pcmA[j]=mag+ang;
  102299. }else{
  102300. pcmA[j]=mag;
  102301. pcmM[j]=mag-ang;
  102302. }
  102303. }
  102304. }
  102305. for(i=0;i<vi->channels;i++){
  102306. float *pcm=vb->pcm[i];
  102307. int submap=info->chmuxlist[i];
  102308. _floor_P[ci->floor_type[info->floorsubmap[submap]]]->
  102309. inverse2(vb,b->flr[info->floorsubmap[submap]],
  102310. floormemo[i],pcm);
  102311. }
  102312. for(i=0;i<vi->channels;i++){
  102313. float *pcm=vb->pcm[i];
  102314. mdct_backward((mdct_lookup*) b->transform[vb->W][0],pcm,pcm);
  102315. }
  102316. return(0);
  102317. }
  102318. vorbis_func_mapping mapping0_exportbundle={
  102319. &mapping0_pack,
  102320. &mapping0_unpack,
  102321. &mapping0_free_info,
  102322. &mapping0_forward,
  102323. &mapping0_inverse
  102324. };
  102325. #endif
  102326. /*** End of inlined file: mapping0.c ***/
  102327. /*** Start of inlined file: mdct.c ***/
  102328. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  102329. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  102330. // tasks..
  102331. #if JUCE_MSVC
  102332. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  102333. #endif
  102334. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  102335. #if JUCE_USE_OGGVORBIS
  102336. #include <stdio.h>
  102337. #include <stdlib.h>
  102338. #include <string.h>
  102339. #include <math.h>
  102340. void mdct_init(mdct_lookup *lookup,int n){
  102341. int *bitrev=(int*) _ogg_malloc(sizeof(*bitrev)*(n/4));
  102342. DATA_TYPE *T=(DATA_TYPE*) _ogg_malloc(sizeof(*T)*(n+n/4));
  102343. int i;
  102344. int n2=n>>1;
  102345. int log2n=lookup->log2n=rint(log((float)n)/log(2.f));
  102346. lookup->n=n;
  102347. lookup->trig=T;
  102348. lookup->bitrev=bitrev;
  102349. for(i=0;i<n/4;i++){
  102350. T[i*2]=FLOAT_CONV(cos((M_PI/n)*(4*i)));
  102351. T[i*2+1]=FLOAT_CONV(-sin((M_PI/n)*(4*i)));
  102352. T[n2+i*2]=FLOAT_CONV(cos((M_PI/(2*n))*(2*i+1)));
  102353. T[n2+i*2+1]=FLOAT_CONV(sin((M_PI/(2*n))*(2*i+1)));
  102354. }
  102355. for(i=0;i<n/8;i++){
  102356. T[n+i*2]=FLOAT_CONV(cos((M_PI/n)*(4*i+2))*.5);
  102357. T[n+i*2+1]=FLOAT_CONV(-sin((M_PI/n)*(4*i+2))*.5);
  102358. }
  102359. {
  102360. int mask=(1<<(log2n-1))-1,i,j;
  102361. int msb=1<<(log2n-2);
  102362. for(i=0;i<n/8;i++){
  102363. int acc=0;
  102364. for(j=0;msb>>j;j++)
  102365. if((msb>>j)&i)acc|=1<<j;
  102366. bitrev[i*2]=((~acc)&mask)-1;
  102367. bitrev[i*2+1]=acc;
  102368. }
  102369. }
  102370. lookup->scale=FLOAT_CONV(4.f/n);
  102371. }
  102372. STIN void mdct_butterfly_8(DATA_TYPE *x){
  102373. REG_TYPE r0 = x[6] + x[2];
  102374. REG_TYPE r1 = x[6] - x[2];
  102375. REG_TYPE r2 = x[4] + x[0];
  102376. REG_TYPE r3 = x[4] - x[0];
  102377. x[6] = r0 + r2;
  102378. x[4] = r0 - r2;
  102379. r0 = x[5] - x[1];
  102380. r2 = x[7] - x[3];
  102381. x[0] = r1 + r0;
  102382. x[2] = r1 - r0;
  102383. r0 = x[5] + x[1];
  102384. r1 = x[7] + x[3];
  102385. x[3] = r2 + r3;
  102386. x[1] = r2 - r3;
  102387. x[7] = r1 + r0;
  102388. x[5] = r1 - r0;
  102389. }
  102390. STIN void mdct_butterfly_16(DATA_TYPE *x){
  102391. REG_TYPE r0 = x[1] - x[9];
  102392. REG_TYPE r1 = x[0] - x[8];
  102393. x[8] += x[0];
  102394. x[9] += x[1];
  102395. x[0] = MULT_NORM((r0 + r1) * cPI2_8);
  102396. x[1] = MULT_NORM((r0 - r1) * cPI2_8);
  102397. r0 = x[3] - x[11];
  102398. r1 = x[10] - x[2];
  102399. x[10] += x[2];
  102400. x[11] += x[3];
  102401. x[2] = r0;
  102402. x[3] = r1;
  102403. r0 = x[12] - x[4];
  102404. r1 = x[13] - x[5];
  102405. x[12] += x[4];
  102406. x[13] += x[5];
  102407. x[4] = MULT_NORM((r0 - r1) * cPI2_8);
  102408. x[5] = MULT_NORM((r0 + r1) * cPI2_8);
  102409. r0 = x[14] - x[6];
  102410. r1 = x[15] - x[7];
  102411. x[14] += x[6];
  102412. x[15] += x[7];
  102413. x[6] = r0;
  102414. x[7] = r1;
  102415. mdct_butterfly_8(x);
  102416. mdct_butterfly_8(x+8);
  102417. }
  102418. STIN void mdct_butterfly_32(DATA_TYPE *x){
  102419. REG_TYPE r0 = x[30] - x[14];
  102420. REG_TYPE r1 = x[31] - x[15];
  102421. x[30] += x[14];
  102422. x[31] += x[15];
  102423. x[14] = r0;
  102424. x[15] = r1;
  102425. r0 = x[28] - x[12];
  102426. r1 = x[29] - x[13];
  102427. x[28] += x[12];
  102428. x[29] += x[13];
  102429. x[12] = MULT_NORM( r0 * cPI1_8 - r1 * cPI3_8 );
  102430. x[13] = MULT_NORM( r0 * cPI3_8 + r1 * cPI1_8 );
  102431. r0 = x[26] - x[10];
  102432. r1 = x[27] - x[11];
  102433. x[26] += x[10];
  102434. x[27] += x[11];
  102435. x[10] = MULT_NORM(( r0 - r1 ) * cPI2_8);
  102436. x[11] = MULT_NORM(( r0 + r1 ) * cPI2_8);
  102437. r0 = x[24] - x[8];
  102438. r1 = x[25] - x[9];
  102439. x[24] += x[8];
  102440. x[25] += x[9];
  102441. x[8] = MULT_NORM( r0 * cPI3_8 - r1 * cPI1_8 );
  102442. x[9] = MULT_NORM( r1 * cPI3_8 + r0 * cPI1_8 );
  102443. r0 = x[22] - x[6];
  102444. r1 = x[7] - x[23];
  102445. x[22] += x[6];
  102446. x[23] += x[7];
  102447. x[6] = r1;
  102448. x[7] = r0;
  102449. r0 = x[4] - x[20];
  102450. r1 = x[5] - x[21];
  102451. x[20] += x[4];
  102452. x[21] += x[5];
  102453. x[4] = MULT_NORM( r1 * cPI1_8 + r0 * cPI3_8 );
  102454. x[5] = MULT_NORM( r1 * cPI3_8 - r0 * cPI1_8 );
  102455. r0 = x[2] - x[18];
  102456. r1 = x[3] - x[19];
  102457. x[18] += x[2];
  102458. x[19] += x[3];
  102459. x[2] = MULT_NORM(( r1 + r0 ) * cPI2_8);
  102460. x[3] = MULT_NORM(( r1 - r0 ) * cPI2_8);
  102461. r0 = x[0] - x[16];
  102462. r1 = x[1] - x[17];
  102463. x[16] += x[0];
  102464. x[17] += x[1];
  102465. x[0] = MULT_NORM( r1 * cPI3_8 + r0 * cPI1_8 );
  102466. x[1] = MULT_NORM( r1 * cPI1_8 - r0 * cPI3_8 );
  102467. mdct_butterfly_16(x);
  102468. mdct_butterfly_16(x+16);
  102469. }
  102470. STIN void mdct_butterfly_first(DATA_TYPE *T,
  102471. DATA_TYPE *x,
  102472. int points){
  102473. DATA_TYPE *x1 = x + points - 8;
  102474. DATA_TYPE *x2 = x + (points>>1) - 8;
  102475. REG_TYPE r0;
  102476. REG_TYPE r1;
  102477. do{
  102478. r0 = x1[6] - x2[6];
  102479. r1 = x1[7] - x2[7];
  102480. x1[6] += x2[6];
  102481. x1[7] += x2[7];
  102482. x2[6] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102483. x2[7] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102484. r0 = x1[4] - x2[4];
  102485. r1 = x1[5] - x2[5];
  102486. x1[4] += x2[4];
  102487. x1[5] += x2[5];
  102488. x2[4] = MULT_NORM(r1 * T[5] + r0 * T[4]);
  102489. x2[5] = MULT_NORM(r1 * T[4] - r0 * T[5]);
  102490. r0 = x1[2] - x2[2];
  102491. r1 = x1[3] - x2[3];
  102492. x1[2] += x2[2];
  102493. x1[3] += x2[3];
  102494. x2[2] = MULT_NORM(r1 * T[9] + r0 * T[8]);
  102495. x2[3] = MULT_NORM(r1 * T[8] - r0 * T[9]);
  102496. r0 = x1[0] - x2[0];
  102497. r1 = x1[1] - x2[1];
  102498. x1[0] += x2[0];
  102499. x1[1] += x2[1];
  102500. x2[0] = MULT_NORM(r1 * T[13] + r0 * T[12]);
  102501. x2[1] = MULT_NORM(r1 * T[12] - r0 * T[13]);
  102502. x1-=8;
  102503. x2-=8;
  102504. T+=16;
  102505. }while(x2>=x);
  102506. }
  102507. STIN void mdct_butterfly_generic(DATA_TYPE *T,
  102508. DATA_TYPE *x,
  102509. int points,
  102510. int trigint){
  102511. DATA_TYPE *x1 = x + points - 8;
  102512. DATA_TYPE *x2 = x + (points>>1) - 8;
  102513. REG_TYPE r0;
  102514. REG_TYPE r1;
  102515. do{
  102516. r0 = x1[6] - x2[6];
  102517. r1 = x1[7] - x2[7];
  102518. x1[6] += x2[6];
  102519. x1[7] += x2[7];
  102520. x2[6] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102521. x2[7] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102522. T+=trigint;
  102523. r0 = x1[4] - x2[4];
  102524. r1 = x1[5] - x2[5];
  102525. x1[4] += x2[4];
  102526. x1[5] += x2[5];
  102527. x2[4] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102528. x2[5] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102529. T+=trigint;
  102530. r0 = x1[2] - x2[2];
  102531. r1 = x1[3] - x2[3];
  102532. x1[2] += x2[2];
  102533. x1[3] += x2[3];
  102534. x2[2] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102535. x2[3] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102536. T+=trigint;
  102537. r0 = x1[0] - x2[0];
  102538. r1 = x1[1] - x2[1];
  102539. x1[0] += x2[0];
  102540. x1[1] += x2[1];
  102541. x2[0] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102542. x2[1] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102543. T+=trigint;
  102544. x1-=8;
  102545. x2-=8;
  102546. }while(x2>=x);
  102547. }
  102548. STIN void mdct_butterflies(mdct_lookup *init,
  102549. DATA_TYPE *x,
  102550. int points){
  102551. DATA_TYPE *T=init->trig;
  102552. int stages=init->log2n-5;
  102553. int i,j;
  102554. if(--stages>0){
  102555. mdct_butterfly_first(T,x,points);
  102556. }
  102557. for(i=1;--stages>0;i++){
  102558. for(j=0;j<(1<<i);j++)
  102559. mdct_butterfly_generic(T,x+(points>>i)*j,points>>i,4<<i);
  102560. }
  102561. for(j=0;j<points;j+=32)
  102562. mdct_butterfly_32(x+j);
  102563. }
  102564. void mdct_clear(mdct_lookup *l){
  102565. if(l){
  102566. if(l->trig)_ogg_free(l->trig);
  102567. if(l->bitrev)_ogg_free(l->bitrev);
  102568. memset(l,0,sizeof(*l));
  102569. }
  102570. }
  102571. STIN void mdct_bitreverse(mdct_lookup *init,
  102572. DATA_TYPE *x){
  102573. int n = init->n;
  102574. int *bit = init->bitrev;
  102575. DATA_TYPE *w0 = x;
  102576. DATA_TYPE *w1 = x = w0+(n>>1);
  102577. DATA_TYPE *T = init->trig+n;
  102578. do{
  102579. DATA_TYPE *x0 = x+bit[0];
  102580. DATA_TYPE *x1 = x+bit[1];
  102581. REG_TYPE r0 = x0[1] - x1[1];
  102582. REG_TYPE r1 = x0[0] + x1[0];
  102583. REG_TYPE r2 = MULT_NORM(r1 * T[0] + r0 * T[1]);
  102584. REG_TYPE r3 = MULT_NORM(r1 * T[1] - r0 * T[0]);
  102585. w1 -= 4;
  102586. r0 = HALVE(x0[1] + x1[1]);
  102587. r1 = HALVE(x0[0] - x1[0]);
  102588. w0[0] = r0 + r2;
  102589. w1[2] = r0 - r2;
  102590. w0[1] = r1 + r3;
  102591. w1[3] = r3 - r1;
  102592. x0 = x+bit[2];
  102593. x1 = x+bit[3];
  102594. r0 = x0[1] - x1[1];
  102595. r1 = x0[0] + x1[0];
  102596. r2 = MULT_NORM(r1 * T[2] + r0 * T[3]);
  102597. r3 = MULT_NORM(r1 * T[3] - r0 * T[2]);
  102598. r0 = HALVE(x0[1] + x1[1]);
  102599. r1 = HALVE(x0[0] - x1[0]);
  102600. w0[2] = r0 + r2;
  102601. w1[0] = r0 - r2;
  102602. w0[3] = r1 + r3;
  102603. w1[1] = r3 - r1;
  102604. T += 4;
  102605. bit += 4;
  102606. w0 += 4;
  102607. }while(w0<w1);
  102608. }
  102609. void mdct_backward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out){
  102610. int n=init->n;
  102611. int n2=n>>1;
  102612. int n4=n>>2;
  102613. DATA_TYPE *iX = in+n2-7;
  102614. DATA_TYPE *oX = out+n2+n4;
  102615. DATA_TYPE *T = init->trig+n4;
  102616. do{
  102617. oX -= 4;
  102618. oX[0] = MULT_NORM(-iX[2] * T[3] - iX[0] * T[2]);
  102619. oX[1] = MULT_NORM (iX[0] * T[3] - iX[2] * T[2]);
  102620. oX[2] = MULT_NORM(-iX[6] * T[1] - iX[4] * T[0]);
  102621. oX[3] = MULT_NORM (iX[4] * T[1] - iX[6] * T[0]);
  102622. iX -= 8;
  102623. T += 4;
  102624. }while(iX>=in);
  102625. iX = in+n2-8;
  102626. oX = out+n2+n4;
  102627. T = init->trig+n4;
  102628. do{
  102629. T -= 4;
  102630. oX[0] = MULT_NORM (iX[4] * T[3] + iX[6] * T[2]);
  102631. oX[1] = MULT_NORM (iX[4] * T[2] - iX[6] * T[3]);
  102632. oX[2] = MULT_NORM (iX[0] * T[1] + iX[2] * T[0]);
  102633. oX[3] = MULT_NORM (iX[0] * T[0] - iX[2] * T[1]);
  102634. iX -= 8;
  102635. oX += 4;
  102636. }while(iX>=in);
  102637. mdct_butterflies(init,out+n2,n2);
  102638. mdct_bitreverse(init,out);
  102639. {
  102640. DATA_TYPE *oX1=out+n2+n4;
  102641. DATA_TYPE *oX2=out+n2+n4;
  102642. DATA_TYPE *iX =out;
  102643. T =init->trig+n2;
  102644. do{
  102645. oX1-=4;
  102646. oX1[3] = MULT_NORM (iX[0] * T[1] - iX[1] * T[0]);
  102647. oX2[0] = -MULT_NORM (iX[0] * T[0] + iX[1] * T[1]);
  102648. oX1[2] = MULT_NORM (iX[2] * T[3] - iX[3] * T[2]);
  102649. oX2[1] = -MULT_NORM (iX[2] * T[2] + iX[3] * T[3]);
  102650. oX1[1] = MULT_NORM (iX[4] * T[5] - iX[5] * T[4]);
  102651. oX2[2] = -MULT_NORM (iX[4] * T[4] + iX[5] * T[5]);
  102652. oX1[0] = MULT_NORM (iX[6] * T[7] - iX[7] * T[6]);
  102653. oX2[3] = -MULT_NORM (iX[6] * T[6] + iX[7] * T[7]);
  102654. oX2+=4;
  102655. iX += 8;
  102656. T += 8;
  102657. }while(iX<oX1);
  102658. iX=out+n2+n4;
  102659. oX1=out+n4;
  102660. oX2=oX1;
  102661. do{
  102662. oX1-=4;
  102663. iX-=4;
  102664. oX2[0] = -(oX1[3] = iX[3]);
  102665. oX2[1] = -(oX1[2] = iX[2]);
  102666. oX2[2] = -(oX1[1] = iX[1]);
  102667. oX2[3] = -(oX1[0] = iX[0]);
  102668. oX2+=4;
  102669. }while(oX2<iX);
  102670. iX=out+n2+n4;
  102671. oX1=out+n2+n4;
  102672. oX2=out+n2;
  102673. do{
  102674. oX1-=4;
  102675. oX1[0]= iX[3];
  102676. oX1[1]= iX[2];
  102677. oX1[2]= iX[1];
  102678. oX1[3]= iX[0];
  102679. iX+=4;
  102680. }while(oX1>oX2);
  102681. }
  102682. }
  102683. void mdct_forward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out){
  102684. int n=init->n;
  102685. int n2=n>>1;
  102686. int n4=n>>2;
  102687. int n8=n>>3;
  102688. DATA_TYPE *w=(DATA_TYPE*) alloca(n*sizeof(*w)); /* forward needs working space */
  102689. DATA_TYPE *w2=w+n2;
  102690. REG_TYPE r0;
  102691. REG_TYPE r1;
  102692. DATA_TYPE *x0=in+n2+n4;
  102693. DATA_TYPE *x1=x0+1;
  102694. DATA_TYPE *T=init->trig+n2;
  102695. int i=0;
  102696. for(i=0;i<n8;i+=2){
  102697. x0 -=4;
  102698. T-=2;
  102699. r0= x0[2] + x1[0];
  102700. r1= x0[0] + x1[2];
  102701. w2[i]= MULT_NORM(r1*T[1] + r0*T[0]);
  102702. w2[i+1]= MULT_NORM(r1*T[0] - r0*T[1]);
  102703. x1 +=4;
  102704. }
  102705. x1=in+1;
  102706. for(;i<n2-n8;i+=2){
  102707. T-=2;
  102708. x0 -=4;
  102709. r0= x0[2] - x1[0];
  102710. r1= x0[0] - x1[2];
  102711. w2[i]= MULT_NORM(r1*T[1] + r0*T[0]);
  102712. w2[i+1]= MULT_NORM(r1*T[0] - r0*T[1]);
  102713. x1 +=4;
  102714. }
  102715. x0=in+n;
  102716. for(;i<n2;i+=2){
  102717. T-=2;
  102718. x0 -=4;
  102719. r0= -x0[2] - x1[0];
  102720. r1= -x0[0] - x1[2];
  102721. w2[i]= MULT_NORM(r1*T[1] + r0*T[0]);
  102722. w2[i+1]= MULT_NORM(r1*T[0] - r0*T[1]);
  102723. x1 +=4;
  102724. }
  102725. mdct_butterflies(init,w+n2,n2);
  102726. mdct_bitreverse(init,w);
  102727. T=init->trig+n2;
  102728. x0=out+n2;
  102729. for(i=0;i<n4;i++){
  102730. x0--;
  102731. out[i] =MULT_NORM((w[0]*T[0]+w[1]*T[1])*init->scale);
  102732. x0[0] =MULT_NORM((w[0]*T[1]-w[1]*T[0])*init->scale);
  102733. w+=2;
  102734. T+=2;
  102735. }
  102736. }
  102737. #endif
  102738. /*** End of inlined file: mdct.c ***/
  102739. /*** Start of inlined file: psy.c ***/
  102740. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  102741. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  102742. // tasks..
  102743. #if JUCE_MSVC
  102744. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  102745. #endif
  102746. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  102747. #if JUCE_USE_OGGVORBIS
  102748. #include <stdlib.h>
  102749. #include <math.h>
  102750. #include <string.h>
  102751. /*** Start of inlined file: masking.h ***/
  102752. #ifndef _V_MASKING_H_
  102753. #define _V_MASKING_H_
  102754. #define MAX_ATH 88
  102755. static float ATH[]={
  102756. -51, -52, -53, -54, -55, -56, -57, -58,
  102757. -59, -60, -61, -62, -63, -64, -65, -66,
  102758. -67, -68, -69, -70, -71, -72, -73, -74,
  102759. -75, -76, -77, -78, -80, -81, -82, -83,
  102760. -84, -85, -86, -87, -88, -88, -89, -89,
  102761. -90, -91, -91, -92, -93, -94, -95, -96,
  102762. -96, -97, -98, -98, -99, -99,-100,-100,
  102763. -101,-102,-103,-104,-106,-107,-107,-107,
  102764. -107,-105,-103,-102,-101, -99, -98, -96,
  102765. -95, -95, -96, -97, -96, -95, -93, -90,
  102766. -80, -70, -50, -40, -30, -30, -30, -30
  102767. };
  102768. #define EHMER_OFFSET 16
  102769. #define EHMER_MAX 56
  102770. static float tonemasks[P_BANDS][6][EHMER_MAX]={
  102771. {{ -60, -60, -60, -60, -60, -60, -60, -60,
  102772. -60, -60, -60, -60, -62, -62, -65, -73,
  102773. -69, -68, -68, -67, -70, -70, -72, -74,
  102774. -75, -79, -79, -80, -83, -88, -93, -100,
  102775. -110, -999, -999, -999, -999, -999, -999, -999,
  102776. -999, -999, -999, -999, -999, -999, -999, -999,
  102777. -999, -999, -999, -999, -999, -999, -999, -999},
  102778. { -48, -48, -48, -48, -48, -48, -48, -48,
  102779. -48, -48, -48, -48, -48, -53, -61, -66,
  102780. -66, -68, -67, -70, -76, -76, -72, -73,
  102781. -75, -76, -78, -79, -83, -88, -93, -100,
  102782. -110, -999, -999, -999, -999, -999, -999, -999,
  102783. -999, -999, -999, -999, -999, -999, -999, -999,
  102784. -999, -999, -999, -999, -999, -999, -999, -999},
  102785. { -37, -37, -37, -37, -37, -37, -37, -37,
  102786. -38, -40, -42, -46, -48, -53, -55, -62,
  102787. -65, -58, -56, -56, -61, -60, -65, -67,
  102788. -69, -71, -77, -77, -78, -80, -82, -84,
  102789. -88, -93, -98, -106, -112, -999, -999, -999,
  102790. -999, -999, -999, -999, -999, -999, -999, -999,
  102791. -999, -999, -999, -999, -999, -999, -999, -999},
  102792. { -25, -25, -25, -25, -25, -25, -25, -25,
  102793. -25, -26, -27, -29, -32, -38, -48, -52,
  102794. -52, -50, -48, -48, -51, -52, -54, -60,
  102795. -67, -67, -66, -68, -69, -73, -73, -76,
  102796. -80, -81, -81, -85, -85, -86, -88, -93,
  102797. -100, -110, -999, -999, -999, -999, -999, -999,
  102798. -999, -999, -999, -999, -999, -999, -999, -999},
  102799. { -16, -16, -16, -16, -16, -16, -16, -16,
  102800. -17, -19, -20, -22, -26, -28, -31, -40,
  102801. -47, -39, -39, -40, -42, -43, -47, -51,
  102802. -57, -52, -55, -55, -60, -58, -62, -63,
  102803. -70, -67, -69, -72, -73, -77, -80, -82,
  102804. -83, -87, -90, -94, -98, -104, -115, -999,
  102805. -999, -999, -999, -999, -999, -999, -999, -999},
  102806. { -8, -8, -8, -8, -8, -8, -8, -8,
  102807. -8, -8, -10, -11, -15, -19, -25, -30,
  102808. -34, -31, -30, -31, -29, -32, -35, -42,
  102809. -48, -42, -44, -46, -50, -50, -51, -52,
  102810. -59, -54, -55, -55, -58, -62, -63, -66,
  102811. -72, -73, -76, -75, -78, -80, -80, -81,
  102812. -84, -88, -90, -94, -98, -101, -106, -110}},
  102813. {{ -66, -66, -66, -66, -66, -66, -66, -66,
  102814. -66, -66, -66, -66, -66, -67, -67, -67,
  102815. -76, -72, -71, -74, -76, -76, -75, -78,
  102816. -79, -79, -81, -83, -86, -89, -93, -97,
  102817. -100, -105, -110, -999, -999, -999, -999, -999,
  102818. -999, -999, -999, -999, -999, -999, -999, -999,
  102819. -999, -999, -999, -999, -999, -999, -999, -999},
  102820. { -47, -47, -47, -47, -47, -47, -47, -47,
  102821. -47, -47, -47, -48, -51, -55, -59, -66,
  102822. -66, -66, -67, -66, -68, -69, -70, -74,
  102823. -79, -77, -77, -78, -80, -81, -82, -84,
  102824. -86, -88, -91, -95, -100, -108, -116, -999,
  102825. -999, -999, -999, -999, -999, -999, -999, -999,
  102826. -999, -999, -999, -999, -999, -999, -999, -999},
  102827. { -36, -36, -36, -36, -36, -36, -36, -36,
  102828. -36, -37, -37, -41, -44, -48, -51, -58,
  102829. -62, -60, -57, -59, -59, -60, -63, -65,
  102830. -72, -71, -70, -72, -74, -77, -76, -78,
  102831. -81, -81, -80, -83, -86, -91, -96, -100,
  102832. -105, -110, -999, -999, -999, -999, -999, -999,
  102833. -999, -999, -999, -999, -999, -999, -999, -999},
  102834. { -28, -28, -28, -28, -28, -28, -28, -28,
  102835. -28, -30, -32, -32, -33, -35, -41, -49,
  102836. -50, -49, -47, -48, -48, -52, -51, -57,
  102837. -65, -61, -59, -61, -64, -69, -70, -74,
  102838. -77, -77, -78, -81, -84, -85, -87, -90,
  102839. -92, -96, -100, -107, -112, -999, -999, -999,
  102840. -999, -999, -999, -999, -999, -999, -999, -999},
  102841. { -19, -19, -19, -19, -19, -19, -19, -19,
  102842. -20, -21, -23, -27, -30, -35, -36, -41,
  102843. -46, -44, -42, -40, -41, -41, -43, -48,
  102844. -55, -53, -52, -53, -56, -59, -58, -60,
  102845. -67, -66, -69, -71, -72, -75, -79, -81,
  102846. -84, -87, -90, -93, -97, -101, -107, -114,
  102847. -999, -999, -999, -999, -999, -999, -999, -999},
  102848. { -9, -9, -9, -9, -9, -9, -9, -9,
  102849. -11, -12, -12, -15, -16, -20, -23, -30,
  102850. -37, -34, -33, -34, -31, -32, -32, -38,
  102851. -47, -44, -41, -40, -47, -49, -46, -46,
  102852. -58, -50, -50, -54, -58, -62, -64, -67,
  102853. -67, -70, -72, -76, -79, -83, -87, -91,
  102854. -96, -100, -104, -110, -999, -999, -999, -999}},
  102855. {{ -62, -62, -62, -62, -62, -62, -62, -62,
  102856. -62, -62, -63, -64, -66, -67, -66, -68,
  102857. -75, -72, -76, -75, -76, -78, -79, -82,
  102858. -84, -85, -90, -94, -101, -110, -999, -999,
  102859. -999, -999, -999, -999, -999, -999, -999, -999,
  102860. -999, -999, -999, -999, -999, -999, -999, -999,
  102861. -999, -999, -999, -999, -999, -999, -999, -999},
  102862. { -59, -59, -59, -59, -59, -59, -59, -59,
  102863. -59, -59, -59, -60, -60, -61, -63, -66,
  102864. -71, -68, -70, -70, -71, -72, -72, -75,
  102865. -81, -78, -79, -82, -83, -86, -90, -97,
  102866. -103, -113, -999, -999, -999, -999, -999, -999,
  102867. -999, -999, -999, -999, -999, -999, -999, -999,
  102868. -999, -999, -999, -999, -999, -999, -999, -999},
  102869. { -53, -53, -53, -53, -53, -53, -53, -53,
  102870. -53, -54, -55, -57, -56, -57, -55, -61,
  102871. -65, -60, -60, -62, -63, -63, -66, -68,
  102872. -74, -73, -75, -75, -78, -80, -80, -82,
  102873. -85, -90, -96, -101, -108, -999, -999, -999,
  102874. -999, -999, -999, -999, -999, -999, -999, -999,
  102875. -999, -999, -999, -999, -999, -999, -999, -999},
  102876. { -46, -46, -46, -46, -46, -46, -46, -46,
  102877. -46, -46, -47, -47, -47, -47, -48, -51,
  102878. -57, -51, -49, -50, -51, -53, -54, -59,
  102879. -66, -60, -62, -67, -67, -70, -72, -75,
  102880. -76, -78, -81, -85, -88, -94, -97, -104,
  102881. -112, -999, -999, -999, -999, -999, -999, -999,
  102882. -999, -999, -999, -999, -999, -999, -999, -999},
  102883. { -36, -36, -36, -36, -36, -36, -36, -36,
  102884. -39, -41, -42, -42, -39, -38, -41, -43,
  102885. -52, -44, -40, -39, -37, -37, -40, -47,
  102886. -54, -50, -48, -50, -55, -61, -59, -62,
  102887. -66, -66, -66, -69, -69, -73, -74, -74,
  102888. -75, -77, -79, -82, -87, -91, -95, -100,
  102889. -108, -115, -999, -999, -999, -999, -999, -999},
  102890. { -28, -26, -24, -22, -20, -20, -23, -29,
  102891. -30, -31, -28, -27, -28, -28, -28, -35,
  102892. -40, -33, -32, -29, -30, -30, -30, -37,
  102893. -45, -41, -37, -38, -45, -47, -47, -48,
  102894. -53, -49, -48, -50, -49, -49, -51, -52,
  102895. -58, -56, -57, -56, -60, -61, -62, -70,
  102896. -72, -74, -78, -83, -88, -93, -100, -106}},
  102897. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102898. -999, -110, -105, -100, -95, -91, -87, -83,
  102899. -80, -78, -76, -78, -78, -81, -83, -85,
  102900. -86, -85, -86, -87, -90, -97, -107, -999,
  102901. -999, -999, -999, -999, -999, -999, -999, -999,
  102902. -999, -999, -999, -999, -999, -999, -999, -999,
  102903. -999, -999, -999, -999, -999, -999, -999, -999},
  102904. {-999, -999, -999, -110, -105, -100, -95, -90,
  102905. -85, -81, -77, -73, -70, -67, -67, -68,
  102906. -75, -73, -70, -69, -70, -72, -75, -79,
  102907. -84, -83, -84, -86, -88, -89, -89, -93,
  102908. -98, -105, -112, -999, -999, -999, -999, -999,
  102909. -999, -999, -999, -999, -999, -999, -999, -999,
  102910. -999, -999, -999, -999, -999, -999, -999, -999},
  102911. {-105, -100, -95, -90, -85, -80, -76, -71,
  102912. -68, -68, -65, -63, -63, -62, -62, -64,
  102913. -65, -64, -61, -62, -63, -64, -66, -68,
  102914. -73, -73, -74, -75, -76, -81, -83, -85,
  102915. -88, -89, -92, -95, -100, -108, -999, -999,
  102916. -999, -999, -999, -999, -999, -999, -999, -999,
  102917. -999, -999, -999, -999, -999, -999, -999, -999},
  102918. { -80, -75, -71, -68, -65, -63, -62, -61,
  102919. -61, -61, -61, -59, -56, -57, -53, -50,
  102920. -58, -52, -50, -50, -52, -53, -54, -58,
  102921. -67, -63, -67, -68, -72, -75, -78, -80,
  102922. -81, -81, -82, -85, -89, -90, -93, -97,
  102923. -101, -107, -114, -999, -999, -999, -999, -999,
  102924. -999, -999, -999, -999, -999, -999, -999, -999},
  102925. { -65, -61, -59, -57, -56, -55, -55, -56,
  102926. -56, -57, -55, -53, -52, -47, -44, -44,
  102927. -50, -44, -41, -39, -39, -42, -40, -46,
  102928. -51, -49, -50, -53, -54, -63, -60, -61,
  102929. -62, -66, -66, -66, -70, -73, -74, -75,
  102930. -76, -75, -79, -85, -89, -91, -96, -102,
  102931. -110, -999, -999, -999, -999, -999, -999, -999},
  102932. { -52, -50, -49, -49, -48, -48, -48, -49,
  102933. -50, -50, -49, -46, -43, -39, -35, -33,
  102934. -38, -36, -32, -29, -32, -32, -32, -35,
  102935. -44, -39, -38, -38, -46, -50, -45, -46,
  102936. -53, -50, -50, -50, -54, -54, -53, -53,
  102937. -56, -57, -59, -66, -70, -72, -74, -79,
  102938. -83, -85, -90, -97, -114, -999, -999, -999}},
  102939. {{-999, -999, -999, -999, -999, -999, -110, -105,
  102940. -100, -95, -90, -86, -80, -75, -75, -79,
  102941. -80, -79, -80, -81, -82, -88, -95, -103,
  102942. -110, -999, -999, -999, -999, -999, -999, -999,
  102943. -999, -999, -999, -999, -999, -999, -999, -999,
  102944. -999, -999, -999, -999, -999, -999, -999, -999,
  102945. -999, -999, -999, -999, -999, -999, -999, -999},
  102946. {-999, -999, -999, -999, -108, -103, -98, -93,
  102947. -88, -83, -79, -78, -75, -71, -67, -68,
  102948. -73, -73, -72, -73, -75, -77, -80, -82,
  102949. -88, -93, -100, -107, -114, -999, -999, -999,
  102950. -999, -999, -999, -999, -999, -999, -999, -999,
  102951. -999, -999, -999, -999, -999, -999, -999, -999,
  102952. -999, -999, -999, -999, -999, -999, -999, -999},
  102953. {-999, -999, -999, -110, -105, -101, -96, -90,
  102954. -86, -81, -77, -73, -69, -66, -61, -62,
  102955. -66, -64, -62, -65, -66, -70, -72, -76,
  102956. -81, -80, -84, -90, -95, -102, -110, -999,
  102957. -999, -999, -999, -999, -999, -999, -999, -999,
  102958. -999, -999, -999, -999, -999, -999, -999, -999,
  102959. -999, -999, -999, -999, -999, -999, -999, -999},
  102960. {-999, -999, -999, -107, -103, -97, -92, -88,
  102961. -83, -79, -74, -70, -66, -59, -53, -58,
  102962. -62, -55, -54, -54, -54, -58, -61, -62,
  102963. -72, -70, -72, -75, -78, -80, -81, -80,
  102964. -83, -83, -88, -93, -100, -107, -115, -999,
  102965. -999, -999, -999, -999, -999, -999, -999, -999,
  102966. -999, -999, -999, -999, -999, -999, -999, -999},
  102967. {-999, -999, -999, -105, -100, -95, -90, -85,
  102968. -80, -75, -70, -66, -62, -56, -48, -44,
  102969. -48, -46, -46, -43, -46, -48, -48, -51,
  102970. -58, -58, -59, -60, -62, -62, -61, -61,
  102971. -65, -64, -65, -68, -70, -74, -75, -78,
  102972. -81, -86, -95, -110, -999, -999, -999, -999,
  102973. -999, -999, -999, -999, -999, -999, -999, -999},
  102974. {-999, -999, -105, -100, -95, -90, -85, -80,
  102975. -75, -70, -65, -61, -55, -49, -39, -33,
  102976. -40, -35, -32, -38, -40, -33, -35, -37,
  102977. -46, -41, -45, -44, -46, -42, -45, -46,
  102978. -52, -50, -50, -50, -54, -54, -55, -57,
  102979. -62, -64, -66, -68, -70, -76, -81, -90,
  102980. -100, -110, -999, -999, -999, -999, -999, -999}},
  102981. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102982. -105, -98, -90, -85, -82, -83, -80, -78,
  102983. -84, -79, -80, -83, -87, -89, -91, -93,
  102984. -99, -106, -117, -999, -999, -999, -999, -999,
  102985. -999, -999, -999, -999, -999, -999, -999, -999,
  102986. -999, -999, -999, -999, -999, -999, -999, -999,
  102987. -999, -999, -999, -999, -999, -999, -999, -999},
  102988. {-999, -999, -999, -999, -999, -999, -999, -999,
  102989. -105, -98, -90, -85, -80, -75, -70, -68,
  102990. -74, -72, -74, -77, -80, -82, -85, -87,
  102991. -92, -89, -91, -95, -100, -106, -112, -999,
  102992. -999, -999, -999, -999, -999, -999, -999, -999,
  102993. -999, -999, -999, -999, -999, -999, -999, -999,
  102994. -999, -999, -999, -999, -999, -999, -999, -999},
  102995. {-999, -999, -999, -999, -999, -999, -999, -999,
  102996. -105, -98, -90, -83, -75, -71, -63, -64,
  102997. -67, -62, -64, -67, -70, -73, -77, -81,
  102998. -84, -83, -85, -89, -90, -93, -98, -104,
  102999. -109, -114, -999, -999, -999, -999, -999, -999,
  103000. -999, -999, -999, -999, -999, -999, -999, -999,
  103001. -999, -999, -999, -999, -999, -999, -999, -999},
  103002. {-999, -999, -999, -999, -999, -999, -999, -999,
  103003. -103, -96, -88, -81, -75, -68, -58, -54,
  103004. -56, -54, -56, -56, -58, -60, -63, -66,
  103005. -74, -69, -72, -72, -75, -74, -77, -81,
  103006. -81, -82, -84, -87, -93, -96, -99, -104,
  103007. -110, -999, -999, -999, -999, -999, -999, -999,
  103008. -999, -999, -999, -999, -999, -999, -999, -999},
  103009. {-999, -999, -999, -999, -999, -108, -102, -96,
  103010. -91, -85, -80, -74, -68, -60, -51, -46,
  103011. -48, -46, -43, -45, -47, -47, -49, -48,
  103012. -56, -53, -55, -58, -57, -63, -58, -60,
  103013. -66, -64, -67, -70, -70, -74, -77, -84,
  103014. -86, -89, -91, -93, -94, -101, -109, -118,
  103015. -999, -999, -999, -999, -999, -999, -999, -999},
  103016. {-999, -999, -999, -108, -103, -98, -93, -88,
  103017. -83, -78, -73, -68, -60, -53, -44, -35,
  103018. -38, -38, -34, -34, -36, -40, -41, -44,
  103019. -51, -45, -46, -47, -46, -54, -50, -49,
  103020. -50, -50, -50, -51, -54, -57, -58, -60,
  103021. -66, -66, -66, -64, -65, -68, -77, -82,
  103022. -87, -95, -110, -999, -999, -999, -999, -999}},
  103023. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103024. -107, -102, -97, -92, -87, -83, -78, -75,
  103025. -82, -79, -83, -85, -89, -92, -95, -98,
  103026. -101, -105, -109, -113, -999, -999, -999, -999,
  103027. -999, -999, -999, -999, -999, -999, -999, -999,
  103028. -999, -999, -999, -999, -999, -999, -999, -999,
  103029. -999, -999, -999, -999, -999, -999, -999, -999},
  103030. {-999, -999, -999, -999, -999, -999, -999, -106,
  103031. -100, -95, -90, -86, -81, -78, -74, -69,
  103032. -74, -74, -76, -79, -83, -84, -86, -89,
  103033. -92, -97, -93, -100, -103, -107, -110, -999,
  103034. -999, -999, -999, -999, -999, -999, -999, -999,
  103035. -999, -999, -999, -999, -999, -999, -999, -999,
  103036. -999, -999, -999, -999, -999, -999, -999, -999},
  103037. {-999, -999, -999, -999, -999, -999, -106, -100,
  103038. -95, -90, -87, -83, -80, -75, -69, -60,
  103039. -66, -66, -68, -70, -74, -78, -79, -81,
  103040. -81, -83, -84, -87, -93, -96, -99, -103,
  103041. -107, -110, -999, -999, -999, -999, -999, -999,
  103042. -999, -999, -999, -999, -999, -999, -999, -999,
  103043. -999, -999, -999, -999, -999, -999, -999, -999},
  103044. {-999, -999, -999, -999, -999, -108, -103, -98,
  103045. -93, -89, -85, -82, -78, -71, -62, -55,
  103046. -58, -58, -54, -54, -55, -59, -61, -62,
  103047. -70, -66, -66, -67, -70, -72, -75, -78,
  103048. -84, -84, -84, -88, -91, -90, -95, -98,
  103049. -102, -103, -106, -110, -999, -999, -999, -999,
  103050. -999, -999, -999, -999, -999, -999, -999, -999},
  103051. {-999, -999, -999, -999, -108, -103, -98, -94,
  103052. -90, -87, -82, -79, -73, -67, -58, -47,
  103053. -50, -45, -41, -45, -48, -44, -44, -49,
  103054. -54, -51, -48, -47, -49, -50, -51, -57,
  103055. -58, -60, -63, -69, -70, -69, -71, -74,
  103056. -78, -82, -90, -95, -101, -105, -110, -999,
  103057. -999, -999, -999, -999, -999, -999, -999, -999},
  103058. {-999, -999, -999, -105, -101, -97, -93, -90,
  103059. -85, -80, -77, -72, -65, -56, -48, -37,
  103060. -40, -36, -34, -40, -50, -47, -38, -41,
  103061. -47, -38, -35, -39, -38, -43, -40, -45,
  103062. -50, -45, -44, -47, -50, -55, -48, -48,
  103063. -52, -66, -70, -76, -82, -90, -97, -105,
  103064. -110, -999, -999, -999, -999, -999, -999, -999}},
  103065. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103066. -999, -108, -103, -98, -93, -86, -79, -76,
  103067. -83, -81, -85, -87, -89, -93, -98, -102,
  103068. -107, -112, -999, -999, -999, -999, -999, -999,
  103069. -999, -999, -999, -999, -999, -999, -999, -999,
  103070. -999, -999, -999, -999, -999, -999, -999, -999,
  103071. -999, -999, -999, -999, -999, -999, -999, -999},
  103072. {-999, -999, -999, -999, -999, -999, -999, -999,
  103073. -999, -108, -103, -98, -93, -86, -79, -71,
  103074. -77, -74, -77, -79, -81, -84, -85, -90,
  103075. -92, -93, -92, -98, -101, -108, -112, -999,
  103076. -999, -999, -999, -999, -999, -999, -999, -999,
  103077. -999, -999, -999, -999, -999, -999, -999, -999,
  103078. -999, -999, -999, -999, -999, -999, -999, -999},
  103079. {-999, -999, -999, -999, -999, -999, -999, -999,
  103080. -108, -103, -98, -93, -87, -78, -68, -65,
  103081. -66, -62, -65, -67, -70, -73, -75, -78,
  103082. -82, -82, -83, -84, -91, -93, -98, -102,
  103083. -106, -110, -999, -999, -999, -999, -999, -999,
  103084. -999, -999, -999, -999, -999, -999, -999, -999,
  103085. -999, -999, -999, -999, -999, -999, -999, -999},
  103086. {-999, -999, -999, -999, -999, -999, -999, -999,
  103087. -105, -100, -95, -90, -82, -74, -62, -57,
  103088. -58, -56, -51, -52, -52, -54, -54, -58,
  103089. -66, -59, -60, -63, -66, -69, -73, -79,
  103090. -83, -84, -80, -81, -81, -82, -88, -92,
  103091. -98, -105, -113, -999, -999, -999, -999, -999,
  103092. -999, -999, -999, -999, -999, -999, -999, -999},
  103093. {-999, -999, -999, -999, -999, -999, -999, -107,
  103094. -102, -97, -92, -84, -79, -69, -57, -47,
  103095. -52, -47, -44, -45, -50, -52, -42, -42,
  103096. -53, -43, -43, -48, -51, -56, -55, -52,
  103097. -57, -59, -61, -62, -67, -71, -78, -83,
  103098. -86, -94, -98, -103, -110, -999, -999, -999,
  103099. -999, -999, -999, -999, -999, -999, -999, -999},
  103100. {-999, -999, -999, -999, -999, -999, -105, -100,
  103101. -95, -90, -84, -78, -70, -61, -51, -41,
  103102. -40, -38, -40, -46, -52, -51, -41, -40,
  103103. -46, -40, -38, -38, -41, -46, -41, -46,
  103104. -47, -43, -43, -45, -41, -45, -56, -67,
  103105. -68, -83, -87, -90, -95, -102, -107, -113,
  103106. -999, -999, -999, -999, -999, -999, -999, -999}},
  103107. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103108. -999, -109, -105, -101, -96, -91, -84, -77,
  103109. -82, -82, -85, -89, -94, -100, -106, -110,
  103110. -999, -999, -999, -999, -999, -999, -999, -999,
  103111. -999, -999, -999, -999, -999, -999, -999, -999,
  103112. -999, -999, -999, -999, -999, -999, -999, -999,
  103113. -999, -999, -999, -999, -999, -999, -999, -999},
  103114. {-999, -999, -999, -999, -999, -999, -999, -999,
  103115. -999, -106, -103, -98, -92, -85, -80, -71,
  103116. -75, -72, -76, -80, -84, -86, -89, -93,
  103117. -100, -107, -113, -999, -999, -999, -999, -999,
  103118. -999, -999, -999, -999, -999, -999, -999, -999,
  103119. -999, -999, -999, -999, -999, -999, -999, -999,
  103120. -999, -999, -999, -999, -999, -999, -999, -999},
  103121. {-999, -999, -999, -999, -999, -999, -999, -107,
  103122. -104, -101, -97, -92, -88, -84, -80, -64,
  103123. -66, -63, -64, -66, -69, -73, -77, -83,
  103124. -83, -86, -91, -98, -104, -111, -999, -999,
  103125. -999, -999, -999, -999, -999, -999, -999, -999,
  103126. -999, -999, -999, -999, -999, -999, -999, -999,
  103127. -999, -999, -999, -999, -999, -999, -999, -999},
  103128. {-999, -999, -999, -999, -999, -999, -999, -107,
  103129. -104, -101, -97, -92, -90, -84, -74, -57,
  103130. -58, -52, -55, -54, -50, -52, -50, -52,
  103131. -63, -62, -69, -76, -77, -78, -78, -79,
  103132. -82, -88, -94, -100, -106, -111, -999, -999,
  103133. -999, -999, -999, -999, -999, -999, -999, -999,
  103134. -999, -999, -999, -999, -999, -999, -999, -999},
  103135. {-999, -999, -999, -999, -999, -999, -106, -102,
  103136. -98, -95, -90, -85, -83, -78, -70, -50,
  103137. -50, -41, -44, -49, -47, -50, -50, -44,
  103138. -55, -46, -47, -48, -48, -54, -49, -49,
  103139. -58, -62, -71, -81, -87, -92, -97, -102,
  103140. -108, -114, -999, -999, -999, -999, -999, -999,
  103141. -999, -999, -999, -999, -999, -999, -999, -999},
  103142. {-999, -999, -999, -999, -999, -999, -106, -102,
  103143. -98, -95, -90, -85, -83, -78, -70, -45,
  103144. -43, -41, -47, -50, -51, -50, -49, -45,
  103145. -47, -41, -44, -41, -39, -43, -38, -37,
  103146. -40, -41, -44, -50, -58, -65, -73, -79,
  103147. -85, -92, -97, -101, -105, -109, -113, -999,
  103148. -999, -999, -999, -999, -999, -999, -999, -999}},
  103149. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103150. -999, -999, -999, -107, -100, -95, -87, -81,
  103151. -85, -83, -88, -93, -100, -107, -114, -999,
  103152. -999, -999, -999, -999, -999, -999, -999, -999,
  103153. -999, -999, -999, -999, -999, -999, -999, -999,
  103154. -999, -999, -999, -999, -999, -999, -999, -999,
  103155. -999, -999, -999, -999, -999, -999, -999, -999},
  103156. {-999, -999, -999, -999, -999, -999, -999, -999,
  103157. -999, -999, -107, -101, -95, -88, -83, -76,
  103158. -73, -72, -79, -84, -90, -95, -100, -105,
  103159. -110, -115, -999, -999, -999, -999, -999, -999,
  103160. -999, -999, -999, -999, -999, -999, -999, -999,
  103161. -999, -999, -999, -999, -999, -999, -999, -999,
  103162. -999, -999, -999, -999, -999, -999, -999, -999},
  103163. {-999, -999, -999, -999, -999, -999, -999, -999,
  103164. -999, -999, -104, -98, -92, -87, -81, -70,
  103165. -65, -62, -67, -71, -74, -80, -85, -91,
  103166. -95, -99, -103, -108, -111, -114, -999, -999,
  103167. -999, -999, -999, -999, -999, -999, -999, -999,
  103168. -999, -999, -999, -999, -999, -999, -999, -999,
  103169. -999, -999, -999, -999, -999, -999, -999, -999},
  103170. {-999, -999, -999, -999, -999, -999, -999, -999,
  103171. -999, -999, -103, -97, -90, -85, -76, -60,
  103172. -56, -54, -60, -62, -61, -56, -63, -65,
  103173. -73, -74, -77, -75, -78, -81, -86, -87,
  103174. -88, -91, -94, -98, -103, -110, -999, -999,
  103175. -999, -999, -999, -999, -999, -999, -999, -999,
  103176. -999, -999, -999, -999, -999, -999, -999, -999},
  103177. {-999, -999, -999, -999, -999, -999, -999, -105,
  103178. -100, -97, -92, -86, -81, -79, -70, -57,
  103179. -51, -47, -51, -58, -60, -56, -53, -50,
  103180. -58, -52, -50, -50, -53, -55, -64, -69,
  103181. -71, -85, -82, -78, -81, -85, -95, -102,
  103182. -112, -999, -999, -999, -999, -999, -999, -999,
  103183. -999, -999, -999, -999, -999, -999, -999, -999},
  103184. {-999, -999, -999, -999, -999, -999, -999, -105,
  103185. -100, -97, -92, -85, -83, -79, -72, -49,
  103186. -40, -43, -43, -54, -56, -51, -50, -40,
  103187. -43, -38, -36, -35, -37, -38, -37, -44,
  103188. -54, -60, -57, -60, -70, -75, -84, -92,
  103189. -103, -112, -999, -999, -999, -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, -110, -102, -95, -89, -82,
  103193. -83, -84, -90, -92, -99, -107, -113, -999,
  103194. -999, -999, -999, -999, -999, -999, -999, -999,
  103195. -999, -999, -999, -999, -999, -999, -999, -999,
  103196. -999, -999, -999, -999, -999, -999, -999, -999,
  103197. -999, -999, -999, -999, -999, -999, -999, -999},
  103198. {-999, -999, -999, -999, -999, -999, -999, -999,
  103199. -999, -999, -107, -101, -95, -89, -83, -72,
  103200. -74, -78, -85, -88, -88, -90, -92, -98,
  103201. -105, -111, -999, -999, -999, -999, -999, -999,
  103202. -999, -999, -999, -999, -999, -999, -999, -999,
  103203. -999, -999, -999, -999, -999, -999, -999, -999,
  103204. -999, -999, -999, -999, -999, -999, -999, -999},
  103205. {-999, -999, -999, -999, -999, -999, -999, -999,
  103206. -999, -109, -103, -97, -93, -87, -81, -70,
  103207. -70, -67, -75, -73, -76, -79, -81, -83,
  103208. -88, -89, -97, -103, -110, -999, -999, -999,
  103209. -999, -999, -999, -999, -999, -999, -999, -999,
  103210. -999, -999, -999, -999, -999, -999, -999, -999,
  103211. -999, -999, -999, -999, -999, -999, -999, -999},
  103212. {-999, -999, -999, -999, -999, -999, -999, -999,
  103213. -999, -107, -100, -94, -88, -83, -75, -63,
  103214. -59, -59, -63, -66, -60, -62, -67, -67,
  103215. -77, -76, -81, -88, -86, -92, -96, -102,
  103216. -109, -116, -999, -999, -999, -999, -999, -999,
  103217. -999, -999, -999, -999, -999, -999, -999, -999,
  103218. -999, -999, -999, -999, -999, -999, -999, -999},
  103219. {-999, -999, -999, -999, -999, -999, -999, -999,
  103220. -999, -105, -98, -92, -86, -81, -73, -56,
  103221. -52, -47, -55, -60, -58, -52, -51, -45,
  103222. -49, -50, -53, -54, -61, -71, -70, -69,
  103223. -78, -79, -87, -90, -96, -104, -112, -999,
  103224. -999, -999, -999, -999, -999, -999, -999, -999,
  103225. -999, -999, -999, -999, -999, -999, -999, -999},
  103226. {-999, -999, -999, -999, -999, -999, -999, -999,
  103227. -999, -103, -96, -90, -86, -78, -70, -51,
  103228. -42, -47, -48, -55, -54, -54, -53, -42,
  103229. -35, -28, -33, -38, -37, -44, -47, -49,
  103230. -54, -63, -68, -78, -82, -89, -94, -99,
  103231. -104, -109, -114, -999, -999, -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, -110, -100, -90, -79,
  103235. -85, -81, -82, -82, -89, -94, -99, -103,
  103236. -109, -115, -999, -999, -999, -999, -999, -999,
  103237. -999, -999, -999, -999, -999, -999, -999, -999,
  103238. -999, -999, -999, -999, -999, -999, -999, -999,
  103239. -999, -999, -999, -999, -999, -999, -999, -999},
  103240. {-999, -999, -999, -999, -999, -999, -999, -999,
  103241. -999, -999, -999, -999, -105, -97, -85, -72,
  103242. -74, -70, -70, -70, -76, -85, -91, -93,
  103243. -97, -103, -109, -115, -999, -999, -999, -999,
  103244. -999, -999, -999, -999, -999, -999, -999, -999,
  103245. -999, -999, -999, -999, -999, -999, -999, -999,
  103246. -999, -999, -999, -999, -999, -999, -999, -999},
  103247. {-999, -999, -999, -999, -999, -999, -999, -999,
  103248. -999, -999, -999, -999, -112, -93, -81, -68,
  103249. -62, -60, -60, -57, -63, -70, -77, -82,
  103250. -90, -93, -98, -104, -109, -113, -999, -999,
  103251. -999, -999, -999, -999, -999, -999, -999, -999,
  103252. -999, -999, -999, -999, -999, -999, -999, -999,
  103253. -999, -999, -999, -999, -999, -999, -999, -999},
  103254. {-999, -999, -999, -999, -999, -999, -999, -999,
  103255. -999, -999, -999, -113, -100, -93, -84, -63,
  103256. -58, -48, -53, -54, -52, -52, -57, -64,
  103257. -66, -76, -83, -81, -85, -85, -90, -95,
  103258. -98, -101, -103, -106, -108, -111, -999, -999,
  103259. -999, -999, -999, -999, -999, -999, -999, -999,
  103260. -999, -999, -999, -999, -999, -999, -999, -999},
  103261. {-999, -999, -999, -999, -999, -999, -999, -999,
  103262. -999, -999, -999, -105, -95, -86, -74, -53,
  103263. -50, -38, -43, -49, -43, -42, -39, -39,
  103264. -46, -52, -57, -56, -72, -69, -74, -81,
  103265. -87, -92, -94, -97, -99, -102, -105, -108,
  103266. -999, -999, -999, -999, -999, -999, -999, -999,
  103267. -999, -999, -999, -999, -999, -999, -999, -999},
  103268. {-999, -999, -999, -999, -999, -999, -999, -999,
  103269. -999, -999, -108, -99, -90, -76, -66, -45,
  103270. -43, -41, -44, -47, -43, -47, -40, -30,
  103271. -31, -31, -39, -33, -40, -41, -43, -53,
  103272. -59, -70, -73, -77, -79, -82, -84, -87,
  103273. -999, -999, -999, -999, -999, -999, -999, -999,
  103274. -999, -999, -999, -999, -999, -999, -999, -999}},
  103275. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103276. -999, -999, -999, -999, -999, -110, -91, -76,
  103277. -75, -85, -93, -98, -104, -110, -999, -999,
  103278. -999, -999, -999, -999, -999, -999, -999, -999,
  103279. -999, -999, -999, -999, -999, -999, -999, -999,
  103280. -999, -999, -999, -999, -999, -999, -999, -999,
  103281. -999, -999, -999, -999, -999, -999, -999, -999},
  103282. {-999, -999, -999, -999, -999, -999, -999, -999,
  103283. -999, -999, -999, -999, -999, -110, -91, -70,
  103284. -70, -75, -86, -89, -94, -98, -101, -106,
  103285. -110, -999, -999, -999, -999, -999, -999, -999,
  103286. -999, -999, -999, -999, -999, -999, -999, -999,
  103287. -999, -999, -999, -999, -999, -999, -999, -999,
  103288. -999, -999, -999, -999, -999, -999, -999, -999},
  103289. {-999, -999, -999, -999, -999, -999, -999, -999,
  103290. -999, -999, -999, -999, -110, -95, -80, -60,
  103291. -65, -64, -74, -83, -88, -91, -95, -99,
  103292. -103, -107, -110, -999, -999, -999, -999, -999,
  103293. -999, -999, -999, -999, -999, -999, -999, -999,
  103294. -999, -999, -999, -999, -999, -999, -999, -999,
  103295. -999, -999, -999, -999, -999, -999, -999, -999},
  103296. {-999, -999, -999, -999, -999, -999, -999, -999,
  103297. -999, -999, -999, -999, -110, -95, -80, -58,
  103298. -55, -49, -66, -68, -71, -78, -78, -80,
  103299. -88, -85, -89, -97, -100, -105, -110, -999,
  103300. -999, -999, -999, -999, -999, -999, -999, -999,
  103301. -999, -999, -999, -999, -999, -999, -999, -999,
  103302. -999, -999, -999, -999, -999, -999, -999, -999},
  103303. {-999, -999, -999, -999, -999, -999, -999, -999,
  103304. -999, -999, -999, -999, -110, -95, -80, -53,
  103305. -52, -41, -59, -59, -49, -58, -56, -63,
  103306. -86, -79, -90, -93, -98, -103, -107, -112,
  103307. -999, -999, -999, -999, -999, -999, -999, -999,
  103308. -999, -999, -999, -999, -999, -999, -999, -999,
  103309. -999, -999, -999, -999, -999, -999, -999, -999},
  103310. {-999, -999, -999, -999, -999, -999, -999, -999,
  103311. -999, -999, -999, -110, -97, -91, -73, -45,
  103312. -40, -33, -53, -61, -49, -54, -50, -50,
  103313. -60, -52, -67, -74, -81, -92, -96, -100,
  103314. -105, -110, -999, -999, -999, -999, -999, -999,
  103315. -999, -999, -999, -999, -999, -999, -999, -999,
  103316. -999, -999, -999, -999, -999, -999, -999, -999}},
  103317. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103318. -999, -999, -999, -113, -106, -99, -92, -77,
  103319. -80, -88, -97, -106, -115, -999, -999, -999,
  103320. -999, -999, -999, -999, -999, -999, -999, -999,
  103321. -999, -999, -999, -999, -999, -999, -999, -999,
  103322. -999, -999, -999, -999, -999, -999, -999, -999,
  103323. -999, -999, -999, -999, -999, -999, -999, -999},
  103324. {-999, -999, -999, -999, -999, -999, -999, -999,
  103325. -999, -999, -116, -109, -102, -95, -89, -74,
  103326. -72, -88, -87, -95, -102, -109, -116, -999,
  103327. -999, -999, -999, -999, -999, -999, -999, -999,
  103328. -999, -999, -999, -999, -999, -999, -999, -999,
  103329. -999, -999, -999, -999, -999, -999, -999, -999,
  103330. -999, -999, -999, -999, -999, -999, -999, -999},
  103331. {-999, -999, -999, -999, -999, -999, -999, -999,
  103332. -999, -999, -116, -109, -102, -95, -89, -75,
  103333. -66, -74, -77, -78, -86, -87, -90, -96,
  103334. -105, -115, -999, -999, -999, -999, -999, -999,
  103335. -999, -999, -999, -999, -999, -999, -999, -999,
  103336. -999, -999, -999, -999, -999, -999, -999, -999,
  103337. -999, -999, -999, -999, -999, -999, -999, -999},
  103338. {-999, -999, -999, -999, -999, -999, -999, -999,
  103339. -999, -999, -115, -108, -101, -94, -88, -66,
  103340. -56, -61, -70, -65, -78, -72, -83, -84,
  103341. -93, -98, -105, -110, -999, -999, -999, -999,
  103342. -999, -999, -999, -999, -999, -999, -999, -999,
  103343. -999, -999, -999, -999, -999, -999, -999, -999,
  103344. -999, -999, -999, -999, -999, -999, -999, -999},
  103345. {-999, -999, -999, -999, -999, -999, -999, -999,
  103346. -999, -999, -110, -105, -95, -89, -82, -57,
  103347. -52, -52, -59, -56, -59, -58, -69, -67,
  103348. -88, -82, -82, -89, -94, -100, -108, -999,
  103349. -999, -999, -999, -999, -999, -999, -999, -999,
  103350. -999, -999, -999, -999, -999, -999, -999, -999,
  103351. -999, -999, -999, -999, -999, -999, -999, -999},
  103352. {-999, -999, -999, -999, -999, -999, -999, -999,
  103353. -999, -110, -101, -96, -90, -83, -77, -54,
  103354. -43, -38, -50, -48, -52, -48, -42, -42,
  103355. -51, -52, -53, -59, -65, -71, -78, -85,
  103356. -95, -999, -999, -999, -999, -999, -999, -999,
  103357. -999, -999, -999, -999, -999, -999, -999, -999,
  103358. -999, -999, -999, -999, -999, -999, -999, -999}},
  103359. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103360. -999, -999, -999, -999, -120, -105, -86, -68,
  103361. -78, -79, -90, -100, -110, -999, -999, -999,
  103362. -999, -999, -999, -999, -999, -999, -999, -999,
  103363. -999, -999, -999, -999, -999, -999, -999, -999,
  103364. -999, -999, -999, -999, -999, -999, -999, -999,
  103365. -999, -999, -999, -999, -999, -999, -999, -999},
  103366. {-999, -999, -999, -999, -999, -999, -999, -999,
  103367. -999, -999, -999, -999, -120, -105, -86, -66,
  103368. -73, -77, -88, -96, -105, -115, -999, -999,
  103369. -999, -999, -999, -999, -999, -999, -999, -999,
  103370. -999, -999, -999, -999, -999, -999, -999, -999,
  103371. -999, -999, -999, -999, -999, -999, -999, -999,
  103372. -999, -999, -999, -999, -999, -999, -999, -999},
  103373. {-999, -999, -999, -999, -999, -999, -999, -999,
  103374. -999, -999, -999, -120, -105, -92, -80, -61,
  103375. -64, -68, -80, -87, -92, -100, -110, -999,
  103376. -999, -999, -999, -999, -999, -999, -999, -999,
  103377. -999, -999, -999, -999, -999, -999, -999, -999,
  103378. -999, -999, -999, -999, -999, -999, -999, -999,
  103379. -999, -999, -999, -999, -999, -999, -999, -999},
  103380. {-999, -999, -999, -999, -999, -999, -999, -999,
  103381. -999, -999, -999, -120, -104, -91, -79, -52,
  103382. -60, -54, -64, -69, -77, -80, -82, -84,
  103383. -85, -87, -88, -90, -999, -999, -999, -999,
  103384. -999, -999, -999, -999, -999, -999, -999, -999,
  103385. -999, -999, -999, -999, -999, -999, -999, -999,
  103386. -999, -999, -999, -999, -999, -999, -999, -999},
  103387. {-999, -999, -999, -999, -999, -999, -999, -999,
  103388. -999, -999, -999, -118, -100, -87, -77, -49,
  103389. -50, -44, -58, -61, -61, -67, -65, -62,
  103390. -62, -62, -65, -68, -999, -999, -999, -999,
  103391. -999, -999, -999, -999, -999, -999, -999, -999,
  103392. -999, -999, -999, -999, -999, -999, -999, -999,
  103393. -999, -999, -999, -999, -999, -999, -999, -999},
  103394. {-999, -999, -999, -999, -999, -999, -999, -999,
  103395. -999, -999, -999, -115, -98, -84, -62, -49,
  103396. -44, -38, -46, -49, -49, -46, -39, -37,
  103397. -39, -40, -42, -43, -999, -999, -999, -999,
  103398. -999, -999, -999, -999, -999, -999, -999, -999,
  103399. -999, -999, -999, -999, -999, -999, -999, -999,
  103400. -999, -999, -999, -999, -999, -999, -999, -999}},
  103401. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103402. -999, -999, -999, -999, -999, -110, -88, -74,
  103403. -77, -82, -82, -85, -90, -94, -99, -104,
  103404. -999, -999, -999, -999, -999, -999, -999, -999,
  103405. -999, -999, -999, -999, -999, -999, -999, -999,
  103406. -999, -999, -999, -999, -999, -999, -999, -999,
  103407. -999, -999, -999, -999, -999, -999, -999, -999},
  103408. {-999, -999, -999, -999, -999, -999, -999, -999,
  103409. -999, -999, -999, -999, -999, -110, -88, -66,
  103410. -70, -81, -80, -81, -84, -88, -91, -93,
  103411. -999, -999, -999, -999, -999, -999, -999, -999,
  103412. -999, -999, -999, -999, -999, -999, -999, -999,
  103413. -999, -999, -999, -999, -999, -999, -999, -999,
  103414. -999, -999, -999, -999, -999, -999, -999, -999},
  103415. {-999, -999, -999, -999, -999, -999, -999, -999,
  103416. -999, -999, -999, -999, -999, -110, -88, -61,
  103417. -63, -70, -71, -74, -77, -80, -83, -85,
  103418. -999, -999, -999, -999, -999, -999, -999, -999,
  103419. -999, -999, -999, -999, -999, -999, -999, -999,
  103420. -999, -999, -999, -999, -999, -999, -999, -999,
  103421. -999, -999, -999, -999, -999, -999, -999, -999},
  103422. {-999, -999, -999, -999, -999, -999, -999, -999,
  103423. -999, -999, -999, -999, -999, -110, -86, -62,
  103424. -63, -62, -62, -58, -52, -50, -50, -52,
  103425. -54, -999, -999, -999, -999, -999, -999, -999,
  103426. -999, -999, -999, -999, -999, -999, -999, -999,
  103427. -999, -999, -999, -999, -999, -999, -999, -999,
  103428. -999, -999, -999, -999, -999, -999, -999, -999},
  103429. {-999, -999, -999, -999, -999, -999, -999, -999,
  103430. -999, -999, -999, -999, -118, -108, -84, -53,
  103431. -50, -50, -50, -55, -47, -45, -40, -40,
  103432. -40, -999, -999, -999, -999, -999, -999, -999,
  103433. -999, -999, -999, -999, -999, -999, -999, -999,
  103434. -999, -999, -999, -999, -999, -999, -999, -999,
  103435. -999, -999, -999, -999, -999, -999, -999, -999},
  103436. {-999, -999, -999, -999, -999, -999, -999, -999,
  103437. -999, -999, -999, -999, -118, -100, -73, -43,
  103438. -37, -42, -43, -53, -38, -37, -35, -35,
  103439. -38, -999, -999, -999, -999, -999, -999, -999,
  103440. -999, -999, -999, -999, -999, -999, -999, -999,
  103441. -999, -999, -999, -999, -999, -999, -999, -999,
  103442. -999, -999, -999, -999, -999, -999, -999, -999}},
  103443. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103444. -999, -999, -999, -110, -100, -91, -84, -74,
  103445. -80, -80, -80, -80, -80, -999, -999, -999,
  103446. -999, -999, -999, -999, -999, -999, -999, -999,
  103447. -999, -999, -999, -999, -999, -999, -999, -999,
  103448. -999, -999, -999, -999, -999, -999, -999, -999,
  103449. -999, -999, -999, -999, -999, -999, -999, -999},
  103450. {-999, -999, -999, -999, -999, -999, -999, -999,
  103451. -999, -999, -999, -110, -100, -91, -84, -74,
  103452. -68, -68, -68, -68, -68, -999, -999, -999,
  103453. -999, -999, -999, -999, -999, -999, -999, -999,
  103454. -999, -999, -999, -999, -999, -999, -999, -999,
  103455. -999, -999, -999, -999, -999, -999, -999, -999,
  103456. -999, -999, -999, -999, -999, -999, -999, -999},
  103457. {-999, -999, -999, -999, -999, -999, -999, -999,
  103458. -999, -999, -999, -110, -100, -86, -78, -70,
  103459. -60, -45, -30, -21, -999, -999, -999, -999,
  103460. -999, -999, -999, -999, -999, -999, -999, -999,
  103461. -999, -999, -999, -999, -999, -999, -999, -999,
  103462. -999, -999, -999, -999, -999, -999, -999, -999,
  103463. -999, -999, -999, -999, -999, -999, -999, -999},
  103464. {-999, -999, -999, -999, -999, -999, -999, -999,
  103465. -999, -999, -999, -110, -100, -87, -78, -67,
  103466. -48, -38, -29, -21, -999, -999, -999, -999,
  103467. -999, -999, -999, -999, -999, -999, -999, -999,
  103468. -999, -999, -999, -999, -999, -999, -999, -999,
  103469. -999, -999, -999, -999, -999, -999, -999, -999,
  103470. -999, -999, -999, -999, -999, -999, -999, -999},
  103471. {-999, -999, -999, -999, -999, -999, -999, -999,
  103472. -999, -999, -999, -110, -100, -86, -69, -56,
  103473. -45, -35, -33, -29, -999, -999, -999, -999,
  103474. -999, -999, -999, -999, -999, -999, -999, -999,
  103475. -999, -999, -999, -999, -999, -999, -999, -999,
  103476. -999, -999, -999, -999, -999, -999, -999, -999,
  103477. -999, -999, -999, -999, -999, -999, -999, -999},
  103478. {-999, -999, -999, -999, -999, -999, -999, -999,
  103479. -999, -999, -999, -110, -100, -83, -71, -48,
  103480. -27, -38, -37, -34, -999, -999, -999, -999,
  103481. -999, -999, -999, -999, -999, -999, -999, -999,
  103482. -999, -999, -999, -999, -999, -999, -999, -999,
  103483. -999, -999, -999, -999, -999, -999, -999, -999,
  103484. -999, -999, -999, -999, -999, -999, -999, -999}}
  103485. };
  103486. #endif
  103487. /*** End of inlined file: masking.h ***/
  103488. #define NEGINF -9999.f
  103489. static double stereo_threshholds[]={0.0, .5, 1.0, 1.5, 2.5, 4.5, 8.5, 16.5, 9e10};
  103490. static double stereo_threshholds_limited[]={0.0, .5, 1.0, 1.5, 2.0, 2.5, 4.5, 8.5, 9e10};
  103491. vorbis_look_psy_global *_vp_global_look(vorbis_info *vi){
  103492. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  103493. vorbis_info_psy_global *gi=&ci->psy_g_param;
  103494. vorbis_look_psy_global *look=(vorbis_look_psy_global*)_ogg_calloc(1,sizeof(*look));
  103495. look->channels=vi->channels;
  103496. look->ampmax=-9999.;
  103497. look->gi=gi;
  103498. return(look);
  103499. }
  103500. void _vp_global_free(vorbis_look_psy_global *look){
  103501. if(look){
  103502. memset(look,0,sizeof(*look));
  103503. _ogg_free(look);
  103504. }
  103505. }
  103506. void _vi_gpsy_free(vorbis_info_psy_global *i){
  103507. if(i){
  103508. memset(i,0,sizeof(*i));
  103509. _ogg_free(i);
  103510. }
  103511. }
  103512. void _vi_psy_free(vorbis_info_psy *i){
  103513. if(i){
  103514. memset(i,0,sizeof(*i));
  103515. _ogg_free(i);
  103516. }
  103517. }
  103518. static void min_curve(float *c,
  103519. float *c2){
  103520. int i;
  103521. for(i=0;i<EHMER_MAX;i++)if(c2[i]<c[i])c[i]=c2[i];
  103522. }
  103523. static void max_curve(float *c,
  103524. float *c2){
  103525. int i;
  103526. for(i=0;i<EHMER_MAX;i++)if(c2[i]>c[i])c[i]=c2[i];
  103527. }
  103528. static void attenuate_curve(float *c,float att){
  103529. int i;
  103530. for(i=0;i<EHMER_MAX;i++)
  103531. c[i]+=att;
  103532. }
  103533. static float ***setup_tone_curves(float curveatt_dB[P_BANDS],float binHz,int n,
  103534. float center_boost, float center_decay_rate){
  103535. int i,j,k,m;
  103536. float ath[EHMER_MAX];
  103537. float workc[P_BANDS][P_LEVELS][EHMER_MAX];
  103538. float athc[P_LEVELS][EHMER_MAX];
  103539. float *brute_buffer=(float*) alloca(n*sizeof(*brute_buffer));
  103540. float ***ret=(float***) _ogg_malloc(sizeof(*ret)*P_BANDS);
  103541. memset(workc,0,sizeof(workc));
  103542. for(i=0;i<P_BANDS;i++){
  103543. int ath_offset=i*4;
  103544. for(j=0;j<EHMER_MAX;j++){
  103545. float min=999.;
  103546. for(k=0;k<4;k++)
  103547. if(j+k+ath_offset<MAX_ATH){
  103548. if(min>ATH[j+k+ath_offset])min=ATH[j+k+ath_offset];
  103549. }else{
  103550. if(min>ATH[MAX_ATH-1])min=ATH[MAX_ATH-1];
  103551. }
  103552. ath[j]=min;
  103553. }
  103554. for(j=0;j<6;j++)
  103555. memcpy(workc[i][j+2],tonemasks[i][j],EHMER_MAX*sizeof(*tonemasks[i][j]));
  103556. memcpy(workc[i][0],tonemasks[i][0],EHMER_MAX*sizeof(*tonemasks[i][0]));
  103557. memcpy(workc[i][1],tonemasks[i][0],EHMER_MAX*sizeof(*tonemasks[i][0]));
  103558. for(j=0;j<P_LEVELS;j++){
  103559. for(k=0;k<EHMER_MAX;k++){
  103560. float adj=center_boost+abs(EHMER_OFFSET-k)*center_decay_rate;
  103561. if(adj<0. && center_boost>0)adj=0.;
  103562. if(adj>0. && center_boost<0)adj=0.;
  103563. workc[i][j][k]+=adj;
  103564. }
  103565. }
  103566. for(j=0;j<P_LEVELS;j++){
  103567. attenuate_curve(workc[i][j],curveatt_dB[i]+100.-(j<2?2:j)*10.-P_LEVEL_0);
  103568. memcpy(athc[j],ath,EHMER_MAX*sizeof(**athc));
  103569. attenuate_curve(athc[j],+100.-j*10.f-P_LEVEL_0);
  103570. max_curve(athc[j],workc[i][j]);
  103571. }
  103572. for(j=1;j<P_LEVELS;j++){
  103573. min_curve(athc[j],athc[j-1]);
  103574. min_curve(workc[i][j],athc[j]);
  103575. }
  103576. }
  103577. for(i=0;i<P_BANDS;i++){
  103578. int hi_curve,lo_curve,bin;
  103579. ret[i]=(float**)_ogg_malloc(sizeof(**ret)*P_LEVELS);
  103580. bin=floor(fromOC(i*.5)/binHz);
  103581. lo_curve= ceil(toOC(bin*binHz+1)*2);
  103582. hi_curve= floor(toOC((bin+1)*binHz)*2);
  103583. if(lo_curve>i)lo_curve=i;
  103584. if(lo_curve<0)lo_curve=0;
  103585. if(hi_curve>=P_BANDS)hi_curve=P_BANDS-1;
  103586. for(m=0;m<P_LEVELS;m++){
  103587. ret[i][m]=(float*)_ogg_malloc(sizeof(***ret)*(EHMER_MAX+2));
  103588. for(j=0;j<n;j++)brute_buffer[j]=999.;
  103589. for(k=lo_curve;k<=hi_curve;k++){
  103590. int l=0;
  103591. for(j=0;j<EHMER_MAX;j++){
  103592. int lo_bin= fromOC(j*.125+k*.5-2.0625)/binHz;
  103593. int hi_bin= fromOC(j*.125+k*.5-1.9375)/binHz+1;
  103594. if(lo_bin<0)lo_bin=0;
  103595. if(lo_bin>n)lo_bin=n;
  103596. if(lo_bin<l)l=lo_bin;
  103597. if(hi_bin<0)hi_bin=0;
  103598. if(hi_bin>n)hi_bin=n;
  103599. for(;l<hi_bin && l<n;l++)
  103600. if(brute_buffer[l]>workc[k][m][j])
  103601. brute_buffer[l]=workc[k][m][j];
  103602. }
  103603. for(;l<n;l++)
  103604. if(brute_buffer[l]>workc[k][m][EHMER_MAX-1])
  103605. brute_buffer[l]=workc[k][m][EHMER_MAX-1];
  103606. }
  103607. if(i+1<P_BANDS){
  103608. int l=0;
  103609. k=i+1;
  103610. for(j=0;j<EHMER_MAX;j++){
  103611. int lo_bin= fromOC(j*.125+i*.5-2.0625)/binHz;
  103612. int hi_bin= fromOC(j*.125+i*.5-1.9375)/binHz+1;
  103613. if(lo_bin<0)lo_bin=0;
  103614. if(lo_bin>n)lo_bin=n;
  103615. if(lo_bin<l)l=lo_bin;
  103616. if(hi_bin<0)hi_bin=0;
  103617. if(hi_bin>n)hi_bin=n;
  103618. for(;l<hi_bin && l<n;l++)
  103619. if(brute_buffer[l]>workc[k][m][j])
  103620. brute_buffer[l]=workc[k][m][j];
  103621. }
  103622. for(;l<n;l++)
  103623. if(brute_buffer[l]>workc[k][m][EHMER_MAX-1])
  103624. brute_buffer[l]=workc[k][m][EHMER_MAX-1];
  103625. }
  103626. for(j=0;j<EHMER_MAX;j++){
  103627. int bin=fromOC(j*.125+i*.5-2.)/binHz;
  103628. if(bin<0){
  103629. ret[i][m][j+2]=-999.;
  103630. }else{
  103631. if(bin>=n){
  103632. ret[i][m][j+2]=-999.;
  103633. }else{
  103634. ret[i][m][j+2]=brute_buffer[bin];
  103635. }
  103636. }
  103637. }
  103638. for(j=0;j<EHMER_OFFSET;j++)
  103639. if(ret[i][m][j+2]>-200.f)break;
  103640. ret[i][m][0]=j;
  103641. for(j=EHMER_MAX-1;j>EHMER_OFFSET+1;j--)
  103642. if(ret[i][m][j+2]>-200.f)
  103643. break;
  103644. ret[i][m][1]=j;
  103645. }
  103646. }
  103647. return(ret);
  103648. }
  103649. void _vp_psy_init(vorbis_look_psy *p,vorbis_info_psy *vi,
  103650. vorbis_info_psy_global *gi,int n,long rate){
  103651. long i,j,lo=-99,hi=1;
  103652. long maxoc;
  103653. memset(p,0,sizeof(*p));
  103654. p->eighth_octave_lines=gi->eighth_octave_lines;
  103655. p->shiftoc=rint(log(gi->eighth_octave_lines*8.f)/log(2.f))-1;
  103656. p->firstoc=toOC(.25f*rate*.5/n)*(1<<(p->shiftoc+1))-gi->eighth_octave_lines;
  103657. maxoc=toOC((n+.25f)*rate*.5/n)*(1<<(p->shiftoc+1))+.5f;
  103658. p->total_octave_lines=maxoc-p->firstoc+1;
  103659. p->ath=(float*)_ogg_malloc(n*sizeof(*p->ath));
  103660. p->octave=(long*)_ogg_malloc(n*sizeof(*p->octave));
  103661. p->bark=(long*)_ogg_malloc(n*sizeof(*p->bark));
  103662. p->vi=vi;
  103663. p->n=n;
  103664. p->rate=rate;
  103665. p->m_val = 1.;
  103666. if(rate < 26000) p->m_val = 0;
  103667. else if(rate < 38000) p->m_val = .94; /* 32kHz */
  103668. else if(rate > 46000) p->m_val = 1.275; /* 48kHz */
  103669. for(i=0,j=0;i<MAX_ATH-1;i++){
  103670. int endpos=rint(fromOC((i+1)*.125-2.)*2*n/rate);
  103671. float base=ATH[i];
  103672. if(j<endpos){
  103673. float delta=(ATH[i+1]-base)/(endpos-j);
  103674. for(;j<endpos && j<n;j++){
  103675. p->ath[j]=base+100.;
  103676. base+=delta;
  103677. }
  103678. }
  103679. }
  103680. for(i=0;i<n;i++){
  103681. float bark=toBARK(rate/(2*n)*i);
  103682. for(;lo+vi->noisewindowlomin<i &&
  103683. toBARK(rate/(2*n)*lo)<(bark-vi->noisewindowlo);lo++);
  103684. for(;hi<=n && (hi<i+vi->noisewindowhimin ||
  103685. toBARK(rate/(2*n)*hi)<(bark+vi->noisewindowhi));hi++);
  103686. p->bark[i]=((lo-1)<<16)+(hi-1);
  103687. }
  103688. for(i=0;i<n;i++)
  103689. p->octave[i]=toOC((i+.25f)*.5*rate/n)*(1<<(p->shiftoc+1))+.5f;
  103690. p->tonecurves=setup_tone_curves(vi->toneatt,rate*.5/n,n,
  103691. vi->tone_centerboost,vi->tone_decay);
  103692. p->noiseoffset=(float**)_ogg_malloc(P_NOISECURVES*sizeof(*p->noiseoffset));
  103693. for(i=0;i<P_NOISECURVES;i++)
  103694. p->noiseoffset[i]=(float*)_ogg_malloc(n*sizeof(**p->noiseoffset));
  103695. for(i=0;i<n;i++){
  103696. float halfoc=toOC((i+.5)*rate/(2.*n))*2.;
  103697. int inthalfoc;
  103698. float del;
  103699. if(halfoc<0)halfoc=0;
  103700. if(halfoc>=P_BANDS-1)halfoc=P_BANDS-1;
  103701. inthalfoc=(int)halfoc;
  103702. del=halfoc-inthalfoc;
  103703. for(j=0;j<P_NOISECURVES;j++)
  103704. p->noiseoffset[j][i]=
  103705. p->vi->noiseoff[j][inthalfoc]*(1.-del) +
  103706. p->vi->noiseoff[j][inthalfoc+1]*del;
  103707. }
  103708. #if 0
  103709. {
  103710. static int ls=0;
  103711. _analysis_output_always("noiseoff0",ls,p->noiseoffset[0],n,1,0,0);
  103712. _analysis_output_always("noiseoff1",ls,p->noiseoffset[1],n,1,0,0);
  103713. _analysis_output_always("noiseoff2",ls++,p->noiseoffset[2],n,1,0,0);
  103714. }
  103715. #endif
  103716. }
  103717. void _vp_psy_clear(vorbis_look_psy *p){
  103718. int i,j;
  103719. if(p){
  103720. if(p->ath)_ogg_free(p->ath);
  103721. if(p->octave)_ogg_free(p->octave);
  103722. if(p->bark)_ogg_free(p->bark);
  103723. if(p->tonecurves){
  103724. for(i=0;i<P_BANDS;i++){
  103725. for(j=0;j<P_LEVELS;j++){
  103726. _ogg_free(p->tonecurves[i][j]);
  103727. }
  103728. _ogg_free(p->tonecurves[i]);
  103729. }
  103730. _ogg_free(p->tonecurves);
  103731. }
  103732. if(p->noiseoffset){
  103733. for(i=0;i<P_NOISECURVES;i++){
  103734. _ogg_free(p->noiseoffset[i]);
  103735. }
  103736. _ogg_free(p->noiseoffset);
  103737. }
  103738. memset(p,0,sizeof(*p));
  103739. }
  103740. }
  103741. static void seed_curve(float *seed,
  103742. const float **curves,
  103743. float amp,
  103744. int oc, int n,
  103745. int linesper,float dBoffset){
  103746. int i,post1;
  103747. int seedptr;
  103748. const float *posts,*curve;
  103749. int choice=(int)((amp+dBoffset-P_LEVEL_0)*.1f);
  103750. choice=max(choice,0);
  103751. choice=min(choice,P_LEVELS-1);
  103752. posts=curves[choice];
  103753. curve=posts+2;
  103754. post1=(int)posts[1];
  103755. seedptr=oc+(posts[0]-EHMER_OFFSET)*linesper-(linesper>>1);
  103756. for(i=posts[0];i<post1;i++){
  103757. if(seedptr>0){
  103758. float lin=amp+curve[i];
  103759. if(seed[seedptr]<lin)seed[seedptr]=lin;
  103760. }
  103761. seedptr+=linesper;
  103762. if(seedptr>=n)break;
  103763. }
  103764. }
  103765. static void seed_loop(vorbis_look_psy *p,
  103766. const float ***curves,
  103767. const float *f,
  103768. const float *flr,
  103769. float *seed,
  103770. float specmax){
  103771. vorbis_info_psy *vi=p->vi;
  103772. long n=p->n,i;
  103773. float dBoffset=vi->max_curve_dB-specmax;
  103774. for(i=0;i<n;i++){
  103775. float max=f[i];
  103776. long oc=p->octave[i];
  103777. while(i+1<n && p->octave[i+1]==oc){
  103778. i++;
  103779. if(f[i]>max)max=f[i];
  103780. }
  103781. if(max+6.f>flr[i]){
  103782. oc=oc>>p->shiftoc;
  103783. if(oc>=P_BANDS)oc=P_BANDS-1;
  103784. if(oc<0)oc=0;
  103785. seed_curve(seed,
  103786. curves[oc],
  103787. max,
  103788. p->octave[i]-p->firstoc,
  103789. p->total_octave_lines,
  103790. p->eighth_octave_lines,
  103791. dBoffset);
  103792. }
  103793. }
  103794. }
  103795. static void seed_chase(float *seeds, int linesper, long n){
  103796. long *posstack=(long*)alloca(n*sizeof(*posstack));
  103797. float *ampstack=(float*)alloca(n*sizeof(*ampstack));
  103798. long stack=0;
  103799. long pos=0;
  103800. long i;
  103801. for(i=0;i<n;i++){
  103802. if(stack<2){
  103803. posstack[stack]=i;
  103804. ampstack[stack++]=seeds[i];
  103805. }else{
  103806. while(1){
  103807. if(seeds[i]<ampstack[stack-1]){
  103808. posstack[stack]=i;
  103809. ampstack[stack++]=seeds[i];
  103810. break;
  103811. }else{
  103812. if(i<posstack[stack-1]+linesper){
  103813. if(stack>1 && ampstack[stack-1]<=ampstack[stack-2] &&
  103814. i<posstack[stack-2]+linesper){
  103815. stack--;
  103816. continue;
  103817. }
  103818. }
  103819. posstack[stack]=i;
  103820. ampstack[stack++]=seeds[i];
  103821. break;
  103822. }
  103823. }
  103824. }
  103825. }
  103826. for(i=0;i<stack;i++){
  103827. long endpos;
  103828. if(i<stack-1 && ampstack[i+1]>ampstack[i]){
  103829. endpos=posstack[i+1];
  103830. }else{
  103831. endpos=posstack[i]+linesper+1; /* +1 is important, else bin 0 is
  103832. discarded in short frames */
  103833. }
  103834. if(endpos>n)endpos=n;
  103835. for(;pos<endpos;pos++)
  103836. seeds[pos]=ampstack[i];
  103837. }
  103838. }
  103839. #include<stdio.h>
  103840. static void max_seeds(vorbis_look_psy *p,
  103841. float *seed,
  103842. float *flr){
  103843. long n=p->total_octave_lines;
  103844. int linesper=p->eighth_octave_lines;
  103845. long linpos=0;
  103846. long pos;
  103847. seed_chase(seed,linesper,n); /* for masking */
  103848. pos=p->octave[0]-p->firstoc-(linesper>>1);
  103849. while(linpos+1<p->n){
  103850. float minV=seed[pos];
  103851. long end=((p->octave[linpos]+p->octave[linpos+1])>>1)-p->firstoc;
  103852. if(minV>p->vi->tone_abs_limit)minV=p->vi->tone_abs_limit;
  103853. while(pos+1<=end){
  103854. pos++;
  103855. if((seed[pos]>NEGINF && seed[pos]<minV) || minV==NEGINF)
  103856. minV=seed[pos];
  103857. }
  103858. end=pos+p->firstoc;
  103859. for(;linpos<p->n && p->octave[linpos]<=end;linpos++)
  103860. if(flr[linpos]<minV)flr[linpos]=minV;
  103861. }
  103862. {
  103863. float minV=seed[p->total_octave_lines-1];
  103864. for(;linpos<p->n;linpos++)
  103865. if(flr[linpos]<minV)flr[linpos]=minV;
  103866. }
  103867. }
  103868. static void bark_noise_hybridmp(int n,const long *b,
  103869. const float *f,
  103870. float *noise,
  103871. const float offset,
  103872. const int fixed){
  103873. float *N=(float*) alloca(n*sizeof(*N));
  103874. float *X=(float*) alloca(n*sizeof(*N));
  103875. float *XX=(float*) alloca(n*sizeof(*N));
  103876. float *Y=(float*) alloca(n*sizeof(*N));
  103877. float *XY=(float*) alloca(n*sizeof(*N));
  103878. float tN, tX, tXX, tY, tXY;
  103879. int i;
  103880. int lo, hi;
  103881. float R, A, B, D;
  103882. float w, x, y;
  103883. tN = tX = tXX = tY = tXY = 0.f;
  103884. y = f[0] + offset;
  103885. if (y < 1.f) y = 1.f;
  103886. w = y * y * .5;
  103887. tN += w;
  103888. tX += w;
  103889. tY += w * y;
  103890. N[0] = tN;
  103891. X[0] = tX;
  103892. XX[0] = tXX;
  103893. Y[0] = tY;
  103894. XY[0] = tXY;
  103895. for (i = 1, x = 1.f; i < n; i++, x += 1.f) {
  103896. y = f[i] + offset;
  103897. if (y < 1.f) y = 1.f;
  103898. w = y * y;
  103899. tN += w;
  103900. tX += w * x;
  103901. tXX += w * x * x;
  103902. tY += w * y;
  103903. tXY += w * x * y;
  103904. N[i] = tN;
  103905. X[i] = tX;
  103906. XX[i] = tXX;
  103907. Y[i] = tY;
  103908. XY[i] = tXY;
  103909. }
  103910. for (i = 0, x = 0.f;; i++, x += 1.f) {
  103911. lo = b[i] >> 16;
  103912. if( lo>=0 ) break;
  103913. hi = b[i] & 0xffff;
  103914. tN = N[hi] + N[-lo];
  103915. tX = X[hi] - X[-lo];
  103916. tXX = XX[hi] + XX[-lo];
  103917. tY = Y[hi] + Y[-lo];
  103918. tXY = XY[hi] - XY[-lo];
  103919. A = tY * tXX - tX * tXY;
  103920. B = tN * tXY - tX * tY;
  103921. D = tN * tXX - tX * tX;
  103922. R = (A + x * B) / D;
  103923. if (R < 0.f)
  103924. R = 0.f;
  103925. noise[i] = R - offset;
  103926. }
  103927. for ( ;; i++, x += 1.f) {
  103928. lo = b[i] >> 16;
  103929. hi = b[i] & 0xffff;
  103930. if(hi>=n)break;
  103931. tN = N[hi] - N[lo];
  103932. tX = X[hi] - X[lo];
  103933. tXX = XX[hi] - XX[lo];
  103934. tY = Y[hi] - Y[lo];
  103935. tXY = XY[hi] - XY[lo];
  103936. A = tY * tXX - tX * tXY;
  103937. B = tN * tXY - tX * tY;
  103938. D = tN * tXX - tX * tX;
  103939. R = (A + x * B) / D;
  103940. if (R < 0.f) R = 0.f;
  103941. noise[i] = R - offset;
  103942. }
  103943. for ( ; i < n; i++, x += 1.f) {
  103944. R = (A + x * B) / D;
  103945. if (R < 0.f) R = 0.f;
  103946. noise[i] = R - offset;
  103947. }
  103948. if (fixed <= 0) return;
  103949. for (i = 0, x = 0.f;; i++, x += 1.f) {
  103950. hi = i + fixed / 2;
  103951. lo = hi - fixed;
  103952. if(lo>=0)break;
  103953. tN = N[hi] + N[-lo];
  103954. tX = X[hi] - X[-lo];
  103955. tXX = XX[hi] + XX[-lo];
  103956. tY = Y[hi] + Y[-lo];
  103957. tXY = XY[hi] - XY[-lo];
  103958. A = tY * tXX - tX * tXY;
  103959. B = tN * tXY - tX * tY;
  103960. D = tN * tXX - tX * tX;
  103961. R = (A + x * B) / D;
  103962. if (R - offset < noise[i]) noise[i] = R - offset;
  103963. }
  103964. for ( ;; i++, x += 1.f) {
  103965. hi = i + fixed / 2;
  103966. lo = hi - fixed;
  103967. if(hi>=n)break;
  103968. tN = N[hi] - N[lo];
  103969. tX = X[hi] - X[lo];
  103970. tXX = XX[hi] - XX[lo];
  103971. tY = Y[hi] - Y[lo];
  103972. tXY = XY[hi] - XY[lo];
  103973. A = tY * tXX - tX * tXY;
  103974. B = tN * tXY - tX * tY;
  103975. D = tN * tXX - tX * tX;
  103976. R = (A + x * B) / D;
  103977. if (R - offset < noise[i]) noise[i] = R - offset;
  103978. }
  103979. for ( ; i < n; i++, x += 1.f) {
  103980. R = (A + x * B) / D;
  103981. if (R - offset < noise[i]) noise[i] = R - offset;
  103982. }
  103983. }
  103984. static float FLOOR1_fromdB_INV_LOOKUP[256]={
  103985. 0.F, 8.81683e+06F, 8.27882e+06F, 7.77365e+06F,
  103986. 7.29930e+06F, 6.85389e+06F, 6.43567e+06F, 6.04296e+06F,
  103987. 5.67422e+06F, 5.32798e+06F, 5.00286e+06F, 4.69759e+06F,
  103988. 4.41094e+06F, 4.14178e+06F, 3.88905e+06F, 3.65174e+06F,
  103989. 3.42891e+06F, 3.21968e+06F, 3.02321e+06F, 2.83873e+06F,
  103990. 2.66551e+06F, 2.50286e+06F, 2.35014e+06F, 2.20673e+06F,
  103991. 2.07208e+06F, 1.94564e+06F, 1.82692e+06F, 1.71544e+06F,
  103992. 1.61076e+06F, 1.51247e+06F, 1.42018e+06F, 1.33352e+06F,
  103993. 1.25215e+06F, 1.17574e+06F, 1.10400e+06F, 1.03663e+06F,
  103994. 973377.F, 913981.F, 858210.F, 805842.F,
  103995. 756669.F, 710497.F, 667142.F, 626433.F,
  103996. 588208.F, 552316.F, 518613.F, 486967.F,
  103997. 457252.F, 429351.F, 403152.F, 378551.F,
  103998. 355452.F, 333762.F, 313396.F, 294273.F,
  103999. 276316.F, 259455.F, 243623.F, 228757.F,
  104000. 214798.F, 201691.F, 189384.F, 177828.F,
  104001. 166977.F, 156788.F, 147221.F, 138237.F,
  104002. 129802.F, 121881.F, 114444.F, 107461.F,
  104003. 100903.F, 94746.3F, 88964.9F, 83536.2F,
  104004. 78438.8F, 73652.5F, 69158.2F, 64938.1F,
  104005. 60975.6F, 57254.9F, 53761.2F, 50480.6F,
  104006. 47400.3F, 44507.9F, 41792.0F, 39241.9F,
  104007. 36847.3F, 34598.9F, 32487.7F, 30505.3F,
  104008. 28643.8F, 26896.0F, 25254.8F, 23713.7F,
  104009. 22266.7F, 20908.0F, 19632.2F, 18434.2F,
  104010. 17309.4F, 16253.1F, 15261.4F, 14330.1F,
  104011. 13455.7F, 12634.6F, 11863.7F, 11139.7F,
  104012. 10460.0F, 9821.72F, 9222.39F, 8659.64F,
  104013. 8131.23F, 7635.06F, 7169.17F, 6731.70F,
  104014. 6320.93F, 5935.23F, 5573.06F, 5232.99F,
  104015. 4913.67F, 4613.84F, 4332.30F, 4067.94F,
  104016. 3819.72F, 3586.64F, 3367.78F, 3162.28F,
  104017. 2969.31F, 2788.13F, 2617.99F, 2458.24F,
  104018. 2308.24F, 2167.39F, 2035.14F, 1910.95F,
  104019. 1794.35F, 1684.85F, 1582.04F, 1485.51F,
  104020. 1394.86F, 1309.75F, 1229.83F, 1154.78F,
  104021. 1084.32F, 1018.15F, 956.024F, 897.687F,
  104022. 842.910F, 791.475F, 743.179F, 697.830F,
  104023. 655.249F, 615.265F, 577.722F, 542.469F,
  104024. 509.367F, 478.286F, 449.101F, 421.696F,
  104025. 395.964F, 371.803F, 349.115F, 327.812F,
  104026. 307.809F, 289.026F, 271.390F, 254.830F,
  104027. 239.280F, 224.679F, 210.969F, 198.096F,
  104028. 186.008F, 174.658F, 164.000F, 153.993F,
  104029. 144.596F, 135.773F, 127.488F, 119.708F,
  104030. 112.404F, 105.545F, 99.1046F, 93.0572F,
  104031. 87.3788F, 82.0469F, 77.0404F, 72.3394F,
  104032. 67.9252F, 63.7804F, 59.8885F, 56.2341F,
  104033. 52.8027F, 49.5807F, 46.5553F, 43.7144F,
  104034. 41.0470F, 38.5423F, 36.1904F, 33.9821F,
  104035. 31.9085F, 29.9614F, 28.1332F, 26.4165F,
  104036. 24.8045F, 23.2910F, 21.8697F, 20.5352F,
  104037. 19.2822F, 18.1056F, 17.0008F, 15.9634F,
  104038. 14.9893F, 14.0746F, 13.2158F, 12.4094F,
  104039. 11.6522F, 10.9411F, 10.2735F, 9.64662F,
  104040. 9.05798F, 8.50526F, 7.98626F, 7.49894F,
  104041. 7.04135F, 6.61169F, 6.20824F, 5.82941F,
  104042. 5.47370F, 5.13970F, 4.82607F, 4.53158F,
  104043. 4.25507F, 3.99542F, 3.75162F, 3.52269F,
  104044. 3.30774F, 3.10590F, 2.91638F, 2.73842F,
  104045. 2.57132F, 2.41442F, 2.26709F, 2.12875F,
  104046. 1.99885F, 1.87688F, 1.76236F, 1.65482F,
  104047. 1.55384F, 1.45902F, 1.36999F, 1.28640F,
  104048. 1.20790F, 1.13419F, 1.06499F, 1.F
  104049. };
  104050. void _vp_remove_floor(vorbis_look_psy *p,
  104051. float *mdct,
  104052. int *codedflr,
  104053. float *residue,
  104054. int sliding_lowpass){
  104055. int i,n=p->n;
  104056. if(sliding_lowpass>n)sliding_lowpass=n;
  104057. for(i=0;i<sliding_lowpass;i++){
  104058. residue[i]=
  104059. mdct[i]*FLOOR1_fromdB_INV_LOOKUP[codedflr[i]];
  104060. }
  104061. for(;i<n;i++)
  104062. residue[i]=0.;
  104063. }
  104064. void _vp_noisemask(vorbis_look_psy *p,
  104065. float *logmdct,
  104066. float *logmask){
  104067. int i,n=p->n;
  104068. float *work=(float*) alloca(n*sizeof(*work));
  104069. bark_noise_hybridmp(n,p->bark,logmdct,logmask,
  104070. 140.,-1);
  104071. for(i=0;i<n;i++)work[i]=logmdct[i]-logmask[i];
  104072. bark_noise_hybridmp(n,p->bark,work,logmask,0.,
  104073. p->vi->noisewindowfixed);
  104074. for(i=0;i<n;i++)work[i]=logmdct[i]-work[i];
  104075. #if 0
  104076. {
  104077. static int seq=0;
  104078. float work2[n];
  104079. for(i=0;i<n;i++){
  104080. work2[i]=logmask[i]+work[i];
  104081. }
  104082. if(seq&1)
  104083. _analysis_output("median2R",seq/2,work,n,1,0,0);
  104084. else
  104085. _analysis_output("median2L",seq/2,work,n,1,0,0);
  104086. if(seq&1)
  104087. _analysis_output("envelope2R",seq/2,work2,n,1,0,0);
  104088. else
  104089. _analysis_output("envelope2L",seq/2,work2,n,1,0,0);
  104090. seq++;
  104091. }
  104092. #endif
  104093. for(i=0;i<n;i++){
  104094. int dB=logmask[i]+.5;
  104095. if(dB>=NOISE_COMPAND_LEVELS)dB=NOISE_COMPAND_LEVELS-1;
  104096. if(dB<0)dB=0;
  104097. logmask[i]= work[i]+p->vi->noisecompand[dB];
  104098. }
  104099. }
  104100. void _vp_tonemask(vorbis_look_psy *p,
  104101. float *logfft,
  104102. float *logmask,
  104103. float global_specmax,
  104104. float local_specmax){
  104105. int i,n=p->n;
  104106. float *seed=(float*) alloca(sizeof(*seed)*p->total_octave_lines);
  104107. float att=local_specmax+p->vi->ath_adjatt;
  104108. for(i=0;i<p->total_octave_lines;i++)seed[i]=NEGINF;
  104109. if(att<p->vi->ath_maxatt)att=p->vi->ath_maxatt;
  104110. for(i=0;i<n;i++)
  104111. logmask[i]=p->ath[i]+att;
  104112. seed_loop(p,(const float ***)p->tonecurves,logfft,logmask,seed,global_specmax);
  104113. max_seeds(p,seed,logmask);
  104114. }
  104115. void _vp_offset_and_mix(vorbis_look_psy *p,
  104116. float *noise,
  104117. float *tone,
  104118. int offset_select,
  104119. float *logmask,
  104120. float *mdct,
  104121. float *logmdct){
  104122. int i,n=p->n;
  104123. float de, coeffi, cx;/* AoTuV */
  104124. float toneatt=p->vi->tone_masteratt[offset_select];
  104125. cx = p->m_val;
  104126. for(i=0;i<n;i++){
  104127. float val= noise[i]+p->noiseoffset[offset_select][i];
  104128. if(val>p->vi->noisemaxsupp)val=p->vi->noisemaxsupp;
  104129. logmask[i]=max(val,tone[i]+toneatt);
  104130. if(offset_select == 1) {
  104131. coeffi = -17.2; /* coeffi is a -17.2dB threshold */
  104132. val = val - logmdct[i]; /* val == mdct line value relative to floor in dB */
  104133. if(val > coeffi){
  104134. de = 1.0-((val-coeffi)*0.005*cx);
  104135. if(de < 0) de = 0.0001;
  104136. }else
  104137. de = 1.0-((val-coeffi)*0.0003*cx);
  104138. mdct[i] *= de;
  104139. }
  104140. }
  104141. }
  104142. float _vp_ampmax_decay(float amp,vorbis_dsp_state *vd){
  104143. vorbis_info *vi=vd->vi;
  104144. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  104145. vorbis_info_psy_global *gi=&ci->psy_g_param;
  104146. int n=ci->blocksizes[vd->W]/2;
  104147. float secs=(float)n/vi->rate;
  104148. amp+=secs*gi->ampmax_att_per_sec;
  104149. if(amp<-9999)amp=-9999;
  104150. return(amp);
  104151. }
  104152. static void couple_lossless(float A, float B,
  104153. float *qA, float *qB){
  104154. int test1=fabs(*qA)>fabs(*qB);
  104155. test1-= fabs(*qA)<fabs(*qB);
  104156. if(!test1)test1=((fabs(A)>fabs(B))<<1)-1;
  104157. if(test1==1){
  104158. *qB=(*qA>0.f?*qA-*qB:*qB-*qA);
  104159. }else{
  104160. float temp=*qB;
  104161. *qB=(*qB>0.f?*qA-*qB:*qB-*qA);
  104162. *qA=temp;
  104163. }
  104164. if(*qB>fabs(*qA)*1.9999f){
  104165. *qB= -fabs(*qA)*2.f;
  104166. *qA= -*qA;
  104167. }
  104168. }
  104169. static float hypot_lookup[32]={
  104170. -0.009935, -0.011245, -0.012726, -0.014397,
  104171. -0.016282, -0.018407, -0.020800, -0.023494,
  104172. -0.026522, -0.029923, -0.033737, -0.038010,
  104173. -0.042787, -0.048121, -0.054064, -0.060671,
  104174. -0.068000, -0.076109, -0.085054, -0.094892,
  104175. -0.105675, -0.117451, -0.130260, -0.144134,
  104176. -0.159093, -0.175146, -0.192286, -0.210490,
  104177. -0.229718, -0.249913, -0.271001, -0.292893};
  104178. static void precomputed_couple_point(float premag,
  104179. int floorA,int floorB,
  104180. float *mag, float *ang){
  104181. int test=(floorA>floorB)-1;
  104182. int offset=31-abs(floorA-floorB);
  104183. float floormag=hypot_lookup[((offset<0)-1)&offset]+1.f;
  104184. floormag*=FLOOR1_fromdB_INV_LOOKUP[(floorB&test)|(floorA&(~test))];
  104185. *mag=premag*floormag;
  104186. *ang=0.f;
  104187. }
  104188. static float dipole_hypot(float a, float b){
  104189. if(a>0.){
  104190. if(b>0.)return sqrt(a*a+b*b);
  104191. if(a>-b)return sqrt(a*a-b*b);
  104192. return -sqrt(b*b-a*a);
  104193. }
  104194. if(b<0.)return -sqrt(a*a+b*b);
  104195. if(-a>b)return -sqrt(a*a-b*b);
  104196. return sqrt(b*b-a*a);
  104197. }
  104198. static float round_hypot(float a, float b){
  104199. if(a>0.){
  104200. if(b>0.)return sqrt(a*a+b*b);
  104201. if(a>-b)return sqrt(a*a+b*b);
  104202. return -sqrt(b*b+a*a);
  104203. }
  104204. if(b<0.)return -sqrt(a*a+b*b);
  104205. if(-a>b)return -sqrt(a*a+b*b);
  104206. return sqrt(b*b+a*a);
  104207. }
  104208. float **_vp_quantize_couple_memo(vorbis_block *vb,
  104209. vorbis_info_psy_global *g,
  104210. vorbis_look_psy *p,
  104211. vorbis_info_mapping0 *vi,
  104212. float **mdct){
  104213. int i,j,n=p->n;
  104214. float **ret=(float**) _vorbis_block_alloc(vb,vi->coupling_steps*sizeof(*ret));
  104215. int limit=g->coupling_pointlimit[p->vi->blockflag][PACKETBLOBS/2];
  104216. for(i=0;i<vi->coupling_steps;i++){
  104217. float *mdctM=mdct[vi->coupling_mag[i]];
  104218. float *mdctA=mdct[vi->coupling_ang[i]];
  104219. ret[i]=(float*) _vorbis_block_alloc(vb,n*sizeof(**ret));
  104220. for(j=0;j<limit;j++)
  104221. ret[i][j]=dipole_hypot(mdctM[j],mdctA[j]);
  104222. for(;j<n;j++)
  104223. ret[i][j]=round_hypot(mdctM[j],mdctA[j]);
  104224. }
  104225. return(ret);
  104226. }
  104227. static int apsort(const void *a, const void *b){
  104228. float f1=fabs(**(float**)a);
  104229. float f2=fabs(**(float**)b);
  104230. return (f1<f2)-(f1>f2);
  104231. }
  104232. int **_vp_quantize_couple_sort(vorbis_block *vb,
  104233. vorbis_look_psy *p,
  104234. vorbis_info_mapping0 *vi,
  104235. float **mags){
  104236. if(p->vi->normal_point_p){
  104237. int i,j,k,n=p->n;
  104238. int **ret=(int**) _vorbis_block_alloc(vb,vi->coupling_steps*sizeof(*ret));
  104239. int partition=p->vi->normal_partition;
  104240. float **work=(float**) alloca(sizeof(*work)*partition);
  104241. for(i=0;i<vi->coupling_steps;i++){
  104242. ret[i]=(int*) _vorbis_block_alloc(vb,n*sizeof(**ret));
  104243. for(j=0;j<n;j+=partition){
  104244. for(k=0;k<partition;k++)work[k]=mags[i]+k+j;
  104245. qsort(work,partition,sizeof(*work),apsort);
  104246. for(k=0;k<partition;k++)ret[i][k+j]=work[k]-mags[i];
  104247. }
  104248. }
  104249. return(ret);
  104250. }
  104251. return(NULL);
  104252. }
  104253. void _vp_noise_normalize_sort(vorbis_look_psy *p,
  104254. float *magnitudes,int *sortedindex){
  104255. int i,j,n=p->n;
  104256. vorbis_info_psy *vi=p->vi;
  104257. int partition=vi->normal_partition;
  104258. float **work=(float**) alloca(sizeof(*work)*partition);
  104259. int start=vi->normal_start;
  104260. for(j=start;j<n;j+=partition){
  104261. if(j+partition>n)partition=n-j;
  104262. for(i=0;i<partition;i++)work[i]=magnitudes+i+j;
  104263. qsort(work,partition,sizeof(*work),apsort);
  104264. for(i=0;i<partition;i++){
  104265. sortedindex[i+j-start]=work[i]-magnitudes;
  104266. }
  104267. }
  104268. }
  104269. void _vp_noise_normalize(vorbis_look_psy *p,
  104270. float *in,float *out,int *sortedindex){
  104271. int flag=0,i,j=0,n=p->n;
  104272. vorbis_info_psy *vi=p->vi;
  104273. int partition=vi->normal_partition;
  104274. int start=vi->normal_start;
  104275. if(start>n)start=n;
  104276. if(vi->normal_channel_p){
  104277. for(;j<start;j++)
  104278. out[j]=rint(in[j]);
  104279. for(;j+partition<=n;j+=partition){
  104280. float acc=0.;
  104281. int k;
  104282. for(i=j;i<j+partition;i++)
  104283. acc+=in[i]*in[i];
  104284. for(i=0;i<partition;i++){
  104285. k=sortedindex[i+j-start];
  104286. if(in[k]*in[k]>=.25f){
  104287. out[k]=rint(in[k]);
  104288. acc-=in[k]*in[k];
  104289. flag=1;
  104290. }else{
  104291. if(acc<vi->normal_thresh)break;
  104292. out[k]=unitnorm(in[k]);
  104293. acc-=1.;
  104294. }
  104295. }
  104296. for(;i<partition;i++){
  104297. k=sortedindex[i+j-start];
  104298. out[k]=0.;
  104299. }
  104300. }
  104301. }
  104302. for(;j<n;j++)
  104303. out[j]=rint(in[j]);
  104304. }
  104305. void _vp_couple(int blobno,
  104306. vorbis_info_psy_global *g,
  104307. vorbis_look_psy *p,
  104308. vorbis_info_mapping0 *vi,
  104309. float **res,
  104310. float **mag_memo,
  104311. int **mag_sort,
  104312. int **ifloor,
  104313. int *nonzero,
  104314. int sliding_lowpass){
  104315. int i,j,k,n=p->n;
  104316. for(i=0;i<vi->coupling_steps;i++){
  104317. if(nonzero[vi->coupling_mag[i]] ||
  104318. nonzero[vi->coupling_ang[i]]){
  104319. float *rM=res[vi->coupling_mag[i]];
  104320. float *rA=res[vi->coupling_ang[i]];
  104321. float *qM=rM+n;
  104322. float *qA=rA+n;
  104323. int *floorM=ifloor[vi->coupling_mag[i]];
  104324. int *floorA=ifloor[vi->coupling_ang[i]];
  104325. float prepoint=stereo_threshholds[g->coupling_prepointamp[blobno]];
  104326. float postpoint=stereo_threshholds[g->coupling_postpointamp[blobno]];
  104327. int partition=(p->vi->normal_point_p?p->vi->normal_partition:p->n);
  104328. int limit=g->coupling_pointlimit[p->vi->blockflag][blobno];
  104329. int pointlimit=limit;
  104330. nonzero[vi->coupling_mag[i]]=1;
  104331. nonzero[vi->coupling_ang[i]]=1;
  104332. if(n > 1000)
  104333. postpoint=stereo_threshholds_limited[g->coupling_postpointamp[blobno]];
  104334. for(j=0;j<p->n;j+=partition){
  104335. float acc=0.f;
  104336. for(k=0;k<partition;k++){
  104337. int l=k+j;
  104338. if(l<sliding_lowpass){
  104339. if((l>=limit && fabs(rM[l])<postpoint && fabs(rA[l])<postpoint) ||
  104340. (fabs(rM[l])<prepoint && fabs(rA[l])<prepoint)){
  104341. precomputed_couple_point(mag_memo[i][l],
  104342. floorM[l],floorA[l],
  104343. qM+l,qA+l);
  104344. if(rint(qM[l])==0.f)acc+=qM[l]*qM[l];
  104345. }else{
  104346. couple_lossless(rM[l],rA[l],qM+l,qA+l);
  104347. }
  104348. }else{
  104349. qM[l]=0.;
  104350. qA[l]=0.;
  104351. }
  104352. }
  104353. if(p->vi->normal_point_p){
  104354. for(k=0;k<partition && acc>=p->vi->normal_thresh;k++){
  104355. int l=mag_sort[i][j+k];
  104356. if(l<sliding_lowpass && l>=pointlimit && rint(qM[l])==0.f){
  104357. qM[l]=unitnorm(qM[l]);
  104358. acc-=1.f;
  104359. }
  104360. }
  104361. }
  104362. }
  104363. }
  104364. }
  104365. }
  104366. void hf_reduction(vorbis_info_psy_global *g,
  104367. vorbis_look_psy *p,
  104368. vorbis_info_mapping0 *vi,
  104369. float **mdct){
  104370. int i,j,n=p->n, de=0.3*p->m_val;
  104371. int limit=g->coupling_pointlimit[p->vi->blockflag][PACKETBLOBS/2];
  104372. for(i=0; i<vi->coupling_steps; i++){
  104373. for(j=limit; j<n; j++)
  104374. mdct[i][j] *= (1.0 - de*((float)(j-limit) / (float)(n-limit)));
  104375. }
  104376. }
  104377. #endif
  104378. /*** End of inlined file: psy.c ***/
  104379. /*** Start of inlined file: registry.c ***/
  104380. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  104381. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  104382. // tasks..
  104383. #if JUCE_MSVC
  104384. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  104385. #endif
  104386. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  104387. #if JUCE_USE_OGGVORBIS
  104388. extern vorbis_func_floor floor0_exportbundle;
  104389. extern vorbis_func_floor floor1_exportbundle;
  104390. extern vorbis_func_residue residue0_exportbundle;
  104391. extern vorbis_func_residue residue1_exportbundle;
  104392. extern vorbis_func_residue residue2_exportbundle;
  104393. extern vorbis_func_mapping mapping0_exportbundle;
  104394. vorbis_func_floor *_floor_P[]={
  104395. &floor0_exportbundle,
  104396. &floor1_exportbundle,
  104397. };
  104398. vorbis_func_residue *_residue_P[]={
  104399. &residue0_exportbundle,
  104400. &residue1_exportbundle,
  104401. &residue2_exportbundle,
  104402. };
  104403. vorbis_func_mapping *_mapping_P[]={
  104404. &mapping0_exportbundle,
  104405. };
  104406. #endif
  104407. /*** End of inlined file: registry.c ***/
  104408. /*** Start of inlined file: res0.c ***/
  104409. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  104410. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  104411. // tasks..
  104412. #if JUCE_MSVC
  104413. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  104414. #endif
  104415. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  104416. #if JUCE_USE_OGGVORBIS
  104417. #include <stdlib.h>
  104418. #include <string.h>
  104419. #include <math.h>
  104420. #if defined(TRAIN_RES) || defined (TRAIN_RESAUX)
  104421. #include <stdio.h>
  104422. #endif
  104423. typedef struct {
  104424. vorbis_info_residue0 *info;
  104425. int parts;
  104426. int stages;
  104427. codebook *fullbooks;
  104428. codebook *phrasebook;
  104429. codebook ***partbooks;
  104430. int partvals;
  104431. int **decodemap;
  104432. long postbits;
  104433. long phrasebits;
  104434. long frames;
  104435. #if defined(TRAIN_RES) || defined(TRAIN_RESAUX)
  104436. int train_seq;
  104437. long *training_data[8][64];
  104438. float training_max[8][64];
  104439. float training_min[8][64];
  104440. float tmin;
  104441. float tmax;
  104442. #endif
  104443. } vorbis_look_residue0;
  104444. void res0_free_info(vorbis_info_residue *i){
  104445. vorbis_info_residue0 *info=(vorbis_info_residue0 *)i;
  104446. if(info){
  104447. memset(info,0,sizeof(*info));
  104448. _ogg_free(info);
  104449. }
  104450. }
  104451. void res0_free_look(vorbis_look_residue *i){
  104452. int j;
  104453. if(i){
  104454. vorbis_look_residue0 *look=(vorbis_look_residue0 *)i;
  104455. #ifdef TRAIN_RES
  104456. {
  104457. int j,k,l;
  104458. for(j=0;j<look->parts;j++){
  104459. for(k=0;k<8;k++)
  104460. if(look->training_data[k][j]){
  104461. char buffer[80];
  104462. FILE *of;
  104463. codebook *statebook=look->partbooks[j][k];
  104464. sprintf(buffer,"res_part%d_pass%d.vqd",j,k);
  104465. of=fopen(buffer,"a");
  104466. for(l=0;l<statebook->entries;l++)
  104467. fprintf(of,"%d:%ld\n",l,look->training_data[k][j][l]);
  104468. fclose(of);
  104469. _ogg_free(look->training_data[k][j]);
  104470. look->training_data[k][j]=NULL;
  104471. }
  104472. }
  104473. }
  104474. fprintf(stderr,"min/max residue: %g::%g\n",look->tmin,look->tmax);
  104475. #endif
  104476. for(j=0;j<look->parts;j++)
  104477. if(look->partbooks[j])_ogg_free(look->partbooks[j]);
  104478. _ogg_free(look->partbooks);
  104479. for(j=0;j<look->partvals;j++)
  104480. _ogg_free(look->decodemap[j]);
  104481. _ogg_free(look->decodemap);
  104482. memset(look,0,sizeof(*look));
  104483. _ogg_free(look);
  104484. }
  104485. }
  104486. static int icount(unsigned int v){
  104487. int ret=0;
  104488. while(v){
  104489. ret+=v&1;
  104490. v>>=1;
  104491. }
  104492. return(ret);
  104493. }
  104494. void res0_pack(vorbis_info_residue *vr,oggpack_buffer *opb){
  104495. vorbis_info_residue0 *info=(vorbis_info_residue0 *)vr;
  104496. int j,acc=0;
  104497. oggpack_write(opb,info->begin,24);
  104498. oggpack_write(opb,info->end,24);
  104499. oggpack_write(opb,info->grouping-1,24); /* residue vectors to group and
  104500. code with a partitioned book */
  104501. oggpack_write(opb,info->partitions-1,6); /* possible partition choices */
  104502. oggpack_write(opb,info->groupbook,8); /* group huffman book */
  104503. for(j=0;j<info->partitions;j++){
  104504. if(ilog(info->secondstages[j])>3){
  104505. oggpack_write(opb,info->secondstages[j],3);
  104506. oggpack_write(opb,1,1);
  104507. oggpack_write(opb,info->secondstages[j]>>3,5);
  104508. }else
  104509. oggpack_write(opb,info->secondstages[j],4); /* trailing zero */
  104510. acc+=icount(info->secondstages[j]);
  104511. }
  104512. for(j=0;j<acc;j++)
  104513. oggpack_write(opb,info->booklist[j],8);
  104514. }
  104515. vorbis_info_residue *res0_unpack(vorbis_info *vi,oggpack_buffer *opb){
  104516. int j,acc=0;
  104517. vorbis_info_residue0 *info=(vorbis_info_residue0*) _ogg_calloc(1,sizeof(*info));
  104518. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  104519. info->begin=oggpack_read(opb,24);
  104520. info->end=oggpack_read(opb,24);
  104521. info->grouping=oggpack_read(opb,24)+1;
  104522. info->partitions=oggpack_read(opb,6)+1;
  104523. info->groupbook=oggpack_read(opb,8);
  104524. for(j=0;j<info->partitions;j++){
  104525. int cascade=oggpack_read(opb,3);
  104526. if(oggpack_read(opb,1))
  104527. cascade|=(oggpack_read(opb,5)<<3);
  104528. info->secondstages[j]=cascade;
  104529. acc+=icount(cascade);
  104530. }
  104531. for(j=0;j<acc;j++)
  104532. info->booklist[j]=oggpack_read(opb,8);
  104533. if(info->groupbook>=ci->books)goto errout;
  104534. for(j=0;j<acc;j++)
  104535. if(info->booklist[j]>=ci->books)goto errout;
  104536. return(info);
  104537. errout:
  104538. res0_free_info(info);
  104539. return(NULL);
  104540. }
  104541. vorbis_look_residue *res0_look(vorbis_dsp_state *vd,
  104542. vorbis_info_residue *vr){
  104543. vorbis_info_residue0 *info=(vorbis_info_residue0 *)vr;
  104544. vorbis_look_residue0 *look=(vorbis_look_residue0 *)_ogg_calloc(1,sizeof(*look));
  104545. codec_setup_info *ci=(codec_setup_info*)vd->vi->codec_setup;
  104546. int j,k,acc=0;
  104547. int dim;
  104548. int maxstage=0;
  104549. look->info=info;
  104550. look->parts=info->partitions;
  104551. look->fullbooks=ci->fullbooks;
  104552. look->phrasebook=ci->fullbooks+info->groupbook;
  104553. dim=look->phrasebook->dim;
  104554. look->partbooks=(codebook***)_ogg_calloc(look->parts,sizeof(*look->partbooks));
  104555. for(j=0;j<look->parts;j++){
  104556. int stages=ilog(info->secondstages[j]);
  104557. if(stages){
  104558. if(stages>maxstage)maxstage=stages;
  104559. look->partbooks[j]=(codebook**) _ogg_calloc(stages,sizeof(*look->partbooks[j]));
  104560. for(k=0;k<stages;k++)
  104561. if(info->secondstages[j]&(1<<k)){
  104562. look->partbooks[j][k]=ci->fullbooks+info->booklist[acc++];
  104563. #ifdef TRAIN_RES
  104564. look->training_data[k][j]=_ogg_calloc(look->partbooks[j][k]->entries,
  104565. sizeof(***look->training_data));
  104566. #endif
  104567. }
  104568. }
  104569. }
  104570. look->partvals=rint(pow((float)look->parts,(float)dim));
  104571. look->stages=maxstage;
  104572. look->decodemap=(int**)_ogg_malloc(look->partvals*sizeof(*look->decodemap));
  104573. for(j=0;j<look->partvals;j++){
  104574. long val=j;
  104575. long mult=look->partvals/look->parts;
  104576. look->decodemap[j]=(int*)_ogg_malloc(dim*sizeof(*look->decodemap[j]));
  104577. for(k=0;k<dim;k++){
  104578. long deco=val/mult;
  104579. val-=deco*mult;
  104580. mult/=look->parts;
  104581. look->decodemap[j][k]=deco;
  104582. }
  104583. }
  104584. #if defined(TRAIN_RES) || defined (TRAIN_RESAUX)
  104585. {
  104586. static int train_seq=0;
  104587. look->train_seq=train_seq++;
  104588. }
  104589. #endif
  104590. return(look);
  104591. }
  104592. static int local_book_besterror(codebook *book,float *a){
  104593. int dim=book->dim,i,k,o;
  104594. int best=0;
  104595. encode_aux_threshmatch *tt=book->c->thresh_tree;
  104596. for(k=0,o=dim;k<dim;++k){
  104597. float val=a[--o];
  104598. i=tt->threshvals>>1;
  104599. if(val<tt->quantthresh[i]){
  104600. if(val<tt->quantthresh[i-1]){
  104601. for(--i;i>0;--i)
  104602. if(val>=tt->quantthresh[i-1])
  104603. break;
  104604. }
  104605. }else{
  104606. for(++i;i<tt->threshvals-1;++i)
  104607. if(val<tt->quantthresh[i])break;
  104608. }
  104609. best=(best*tt->quantvals)+tt->quantmap[i];
  104610. }
  104611. if(book->c->lengthlist[best]<=0){
  104612. const static_codebook *c=book->c;
  104613. int i,j;
  104614. float bestf=0.f;
  104615. float *e=book->valuelist;
  104616. best=-1;
  104617. for(i=0;i<book->entries;i++){
  104618. if(c->lengthlist[i]>0){
  104619. float thisx=0.f;
  104620. for(j=0;j<dim;j++){
  104621. float val=(e[j]-a[j]);
  104622. thisx+=val*val;
  104623. }
  104624. if(best==-1 || thisx<bestf){
  104625. bestf=thisx;
  104626. best=i;
  104627. }
  104628. }
  104629. e+=dim;
  104630. }
  104631. }
  104632. {
  104633. float *ptr=book->valuelist+best*dim;
  104634. for(i=0;i<dim;i++)
  104635. *a++ -= *ptr++;
  104636. }
  104637. return(best);
  104638. }
  104639. static int _encodepart(oggpack_buffer *opb,float *vec, int n,
  104640. codebook *book,long *acc){
  104641. int i,bits=0;
  104642. int dim=book->dim;
  104643. int step=n/dim;
  104644. for(i=0;i<step;i++){
  104645. int entry=local_book_besterror(book,vec+i*dim);
  104646. #ifdef TRAIN_RES
  104647. acc[entry]++;
  104648. #endif
  104649. bits+=vorbis_book_encode(book,entry,opb);
  104650. }
  104651. return(bits);
  104652. }
  104653. static long **_01class(vorbis_block *vb,vorbis_look_residue *vl,
  104654. float **in,int ch){
  104655. long i,j,k;
  104656. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104657. vorbis_info_residue0 *info=look->info;
  104658. int samples_per_partition=info->grouping;
  104659. int possible_partitions=info->partitions;
  104660. int n=info->end-info->begin;
  104661. int partvals=n/samples_per_partition;
  104662. long **partword=(long**)_vorbis_block_alloc(vb,ch*sizeof(*partword));
  104663. float scale=100./samples_per_partition;
  104664. for(i=0;i<ch;i++){
  104665. partword[i]=(long*)_vorbis_block_alloc(vb,n/samples_per_partition*sizeof(*partword[i]));
  104666. memset(partword[i],0,n/samples_per_partition*sizeof(*partword[i]));
  104667. }
  104668. for(i=0;i<partvals;i++){
  104669. int offset=i*samples_per_partition+info->begin;
  104670. for(j=0;j<ch;j++){
  104671. float max=0.;
  104672. float ent=0.;
  104673. for(k=0;k<samples_per_partition;k++){
  104674. if(fabs(in[j][offset+k])>max)max=fabs(in[j][offset+k]);
  104675. ent+=fabs(rint(in[j][offset+k]));
  104676. }
  104677. ent*=scale;
  104678. for(k=0;k<possible_partitions-1;k++)
  104679. if(max<=info->classmetric1[k] &&
  104680. (info->classmetric2[k]<0 || (int)ent<info->classmetric2[k]))
  104681. break;
  104682. partword[j][i]=k;
  104683. }
  104684. }
  104685. #ifdef TRAIN_RESAUX
  104686. {
  104687. FILE *of;
  104688. char buffer[80];
  104689. for(i=0;i<ch;i++){
  104690. sprintf(buffer,"resaux_%d.vqd",look->train_seq);
  104691. of=fopen(buffer,"a");
  104692. for(j=0;j<partvals;j++)
  104693. fprintf(of,"%ld, ",partword[i][j]);
  104694. fprintf(of,"\n");
  104695. fclose(of);
  104696. }
  104697. }
  104698. #endif
  104699. look->frames++;
  104700. return(partword);
  104701. }
  104702. static long **_2class(vorbis_block *vb,vorbis_look_residue *vl,float **in,
  104703. int ch){
  104704. long i,j,k,l;
  104705. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104706. vorbis_info_residue0 *info=look->info;
  104707. int samples_per_partition=info->grouping;
  104708. int possible_partitions=info->partitions;
  104709. int n=info->end-info->begin;
  104710. int partvals=n/samples_per_partition;
  104711. long **partword=(long**)_vorbis_block_alloc(vb,sizeof(*partword));
  104712. #if defined(TRAIN_RES) || defined (TRAIN_RESAUX)
  104713. FILE *of;
  104714. char buffer[80];
  104715. #endif
  104716. partword[0]=(long*)_vorbis_block_alloc(vb,n*ch/samples_per_partition*sizeof(*partword[0]));
  104717. memset(partword[0],0,n*ch/samples_per_partition*sizeof(*partword[0]));
  104718. for(i=0,l=info->begin/ch;i<partvals;i++){
  104719. float magmax=0.f;
  104720. float angmax=0.f;
  104721. for(j=0;j<samples_per_partition;j+=ch){
  104722. if(fabs(in[0][l])>magmax)magmax=fabs(in[0][l]);
  104723. for(k=1;k<ch;k++)
  104724. if(fabs(in[k][l])>angmax)angmax=fabs(in[k][l]);
  104725. l++;
  104726. }
  104727. for(j=0;j<possible_partitions-1;j++)
  104728. if(magmax<=info->classmetric1[j] &&
  104729. angmax<=info->classmetric2[j])
  104730. break;
  104731. partword[0][i]=j;
  104732. }
  104733. #ifdef TRAIN_RESAUX
  104734. sprintf(buffer,"resaux_%d.vqd",look->train_seq);
  104735. of=fopen(buffer,"a");
  104736. for(i=0;i<partvals;i++)
  104737. fprintf(of,"%ld, ",partword[0][i]);
  104738. fprintf(of,"\n");
  104739. fclose(of);
  104740. #endif
  104741. look->frames++;
  104742. return(partword);
  104743. }
  104744. static int _01forward(oggpack_buffer *opb,
  104745. vorbis_block *vb,vorbis_look_residue *vl,
  104746. float **in,int ch,
  104747. long **partword,
  104748. int (*encode)(oggpack_buffer *,float *,int,
  104749. codebook *,long *)){
  104750. long i,j,k,s;
  104751. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104752. vorbis_info_residue0 *info=look->info;
  104753. int samples_per_partition=info->grouping;
  104754. int possible_partitions=info->partitions;
  104755. int partitions_per_word=look->phrasebook->dim;
  104756. int n=info->end-info->begin;
  104757. int partvals=n/samples_per_partition;
  104758. long resbits[128];
  104759. long resvals[128];
  104760. #ifdef TRAIN_RES
  104761. for(i=0;i<ch;i++)
  104762. for(j=info->begin;j<info->end;j++){
  104763. if(in[i][j]>look->tmax)look->tmax=in[i][j];
  104764. if(in[i][j]<look->tmin)look->tmin=in[i][j];
  104765. }
  104766. #endif
  104767. memset(resbits,0,sizeof(resbits));
  104768. memset(resvals,0,sizeof(resvals));
  104769. for(s=0;s<look->stages;s++){
  104770. for(i=0;i<partvals;){
  104771. if(s==0){
  104772. for(j=0;j<ch;j++){
  104773. long val=partword[j][i];
  104774. for(k=1;k<partitions_per_word;k++){
  104775. val*=possible_partitions;
  104776. if(i+k<partvals)
  104777. val+=partword[j][i+k];
  104778. }
  104779. if(val<look->phrasebook->entries)
  104780. look->phrasebits+=vorbis_book_encode(look->phrasebook,val,opb);
  104781. #if 0 /*def TRAIN_RES*/
  104782. else
  104783. fprintf(stderr,"!");
  104784. #endif
  104785. }
  104786. }
  104787. for(k=0;k<partitions_per_word && i<partvals;k++,i++){
  104788. long offset=i*samples_per_partition+info->begin;
  104789. for(j=0;j<ch;j++){
  104790. if(s==0)resvals[partword[j][i]]+=samples_per_partition;
  104791. if(info->secondstages[partword[j][i]]&(1<<s)){
  104792. codebook *statebook=look->partbooks[partword[j][i]][s];
  104793. if(statebook){
  104794. int ret;
  104795. long *accumulator=NULL;
  104796. #ifdef TRAIN_RES
  104797. accumulator=look->training_data[s][partword[j][i]];
  104798. {
  104799. int l;
  104800. float *samples=in[j]+offset;
  104801. for(l=0;l<samples_per_partition;l++){
  104802. if(samples[l]<look->training_min[s][partword[j][i]])
  104803. look->training_min[s][partword[j][i]]=samples[l];
  104804. if(samples[l]>look->training_max[s][partword[j][i]])
  104805. look->training_max[s][partword[j][i]]=samples[l];
  104806. }
  104807. }
  104808. #endif
  104809. ret=encode(opb,in[j]+offset,samples_per_partition,
  104810. statebook,accumulator);
  104811. look->postbits+=ret;
  104812. resbits[partword[j][i]]+=ret;
  104813. }
  104814. }
  104815. }
  104816. }
  104817. }
  104818. }
  104819. return(0);
  104820. }
  104821. static int _01inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104822. float **in,int ch,
  104823. long (*decodepart)(codebook *, float *,
  104824. oggpack_buffer *,int)){
  104825. long i,j,k,l,s;
  104826. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104827. vorbis_info_residue0 *info=look->info;
  104828. int samples_per_partition=info->grouping;
  104829. int partitions_per_word=look->phrasebook->dim;
  104830. int n=info->end-info->begin;
  104831. int partvals=n/samples_per_partition;
  104832. int partwords=(partvals+partitions_per_word-1)/partitions_per_word;
  104833. int ***partword=(int***)alloca(ch*sizeof(*partword));
  104834. for(j=0;j<ch;j++)
  104835. partword[j]=(int**)_vorbis_block_alloc(vb,partwords*sizeof(*partword[j]));
  104836. for(s=0;s<look->stages;s++){
  104837. for(i=0,l=0;i<partvals;l++){
  104838. if(s==0){
  104839. for(j=0;j<ch;j++){
  104840. int temp=vorbis_book_decode(look->phrasebook,&vb->opb);
  104841. if(temp==-1)goto eopbreak;
  104842. partword[j][l]=look->decodemap[temp];
  104843. if(partword[j][l]==NULL)goto errout;
  104844. }
  104845. }
  104846. for(k=0;k<partitions_per_word && i<partvals;k++,i++)
  104847. for(j=0;j<ch;j++){
  104848. long offset=info->begin+i*samples_per_partition;
  104849. if(info->secondstages[partword[j][l][k]]&(1<<s)){
  104850. codebook *stagebook=look->partbooks[partword[j][l][k]][s];
  104851. if(stagebook){
  104852. if(decodepart(stagebook,in[j]+offset,&vb->opb,
  104853. samples_per_partition)==-1)goto eopbreak;
  104854. }
  104855. }
  104856. }
  104857. }
  104858. }
  104859. errout:
  104860. eopbreak:
  104861. return(0);
  104862. }
  104863. #if 0
  104864. long **res0_class(vorbis_block *vb,vorbis_look_residue *vl,
  104865. float **in,int *nonzero,int ch){
  104866. int i,used=0;
  104867. for(i=0;i<ch;i++)
  104868. if(nonzero[i])
  104869. in[used++]=in[i];
  104870. if(used)
  104871. return(_01class(vb,vl,in,used));
  104872. else
  104873. return(0);
  104874. }
  104875. int res0_forward(vorbis_block *vb,vorbis_look_residue *vl,
  104876. float **in,float **out,int *nonzero,int ch,
  104877. long **partword){
  104878. int i,j,used=0,n=vb->pcmend/2;
  104879. for(i=0;i<ch;i++)
  104880. if(nonzero[i]){
  104881. if(out)
  104882. for(j=0;j<n;j++)
  104883. out[i][j]+=in[i][j];
  104884. in[used++]=in[i];
  104885. }
  104886. if(used){
  104887. int ret=_01forward(vb,vl,in,used,partword,
  104888. _interleaved_encodepart);
  104889. if(out){
  104890. used=0;
  104891. for(i=0;i<ch;i++)
  104892. if(nonzero[i]){
  104893. for(j=0;j<n;j++)
  104894. out[i][j]-=in[used][j];
  104895. used++;
  104896. }
  104897. }
  104898. return(ret);
  104899. }else{
  104900. return(0);
  104901. }
  104902. }
  104903. #endif
  104904. int res0_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104905. float **in,int *nonzero,int ch){
  104906. int i,used=0;
  104907. for(i=0;i<ch;i++)
  104908. if(nonzero[i])
  104909. in[used++]=in[i];
  104910. if(used)
  104911. return(_01inverse(vb,vl,in,used,vorbis_book_decodevs_add));
  104912. else
  104913. return(0);
  104914. }
  104915. int res1_forward(oggpack_buffer *opb,vorbis_block *vb,vorbis_look_residue *vl,
  104916. float **in,float **out,int *nonzero,int ch,
  104917. long **partword){
  104918. int i,j,used=0,n=vb->pcmend/2;
  104919. for(i=0;i<ch;i++)
  104920. if(nonzero[i]){
  104921. if(out)
  104922. for(j=0;j<n;j++)
  104923. out[i][j]+=in[i][j];
  104924. in[used++]=in[i];
  104925. }
  104926. if(used){
  104927. int ret=_01forward(opb,vb,vl,in,used,partword,_encodepart);
  104928. if(out){
  104929. used=0;
  104930. for(i=0;i<ch;i++)
  104931. if(nonzero[i]){
  104932. for(j=0;j<n;j++)
  104933. out[i][j]-=in[used][j];
  104934. used++;
  104935. }
  104936. }
  104937. return(ret);
  104938. }else{
  104939. return(0);
  104940. }
  104941. }
  104942. long **res1_class(vorbis_block *vb,vorbis_look_residue *vl,
  104943. float **in,int *nonzero,int ch){
  104944. int i,used=0;
  104945. for(i=0;i<ch;i++)
  104946. if(nonzero[i])
  104947. in[used++]=in[i];
  104948. if(used)
  104949. return(_01class(vb,vl,in,used));
  104950. else
  104951. return(0);
  104952. }
  104953. int res1_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104954. float **in,int *nonzero,int ch){
  104955. int i,used=0;
  104956. for(i=0;i<ch;i++)
  104957. if(nonzero[i])
  104958. in[used++]=in[i];
  104959. if(used)
  104960. return(_01inverse(vb,vl,in,used,vorbis_book_decodev_add));
  104961. else
  104962. return(0);
  104963. }
  104964. long **res2_class(vorbis_block *vb,vorbis_look_residue *vl,
  104965. float **in,int *nonzero,int ch){
  104966. int i,used=0;
  104967. for(i=0;i<ch;i++)
  104968. if(nonzero[i])used++;
  104969. if(used)
  104970. return(_2class(vb,vl,in,ch));
  104971. else
  104972. return(0);
  104973. }
  104974. int res2_forward(oggpack_buffer *opb,
  104975. vorbis_block *vb,vorbis_look_residue *vl,
  104976. float **in,float **out,int *nonzero,int ch,
  104977. long **partword){
  104978. long i,j,k,n=vb->pcmend/2,used=0;
  104979. float *work=(float*)_vorbis_block_alloc(vb,ch*n*sizeof(*work));
  104980. for(i=0;i<ch;i++){
  104981. float *pcm=in[i];
  104982. if(nonzero[i])used++;
  104983. for(j=0,k=i;j<n;j++,k+=ch)
  104984. work[k]=pcm[j];
  104985. }
  104986. if(used){
  104987. int ret=_01forward(opb,vb,vl,&work,1,partword,_encodepart);
  104988. if(out){
  104989. for(i=0;i<ch;i++){
  104990. float *pcm=in[i];
  104991. float *sofar=out[i];
  104992. for(j=0,k=i;j<n;j++,k+=ch)
  104993. sofar[j]+=pcm[j]-work[k];
  104994. }
  104995. }
  104996. return(ret);
  104997. }else{
  104998. return(0);
  104999. }
  105000. }
  105001. int res2_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  105002. float **in,int *nonzero,int ch){
  105003. long i,k,l,s;
  105004. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  105005. vorbis_info_residue0 *info=look->info;
  105006. int samples_per_partition=info->grouping;
  105007. int partitions_per_word=look->phrasebook->dim;
  105008. int n=info->end-info->begin;
  105009. int partvals=n/samples_per_partition;
  105010. int partwords=(partvals+partitions_per_word-1)/partitions_per_word;
  105011. int **partword=(int**)_vorbis_block_alloc(vb,partwords*sizeof(*partword));
  105012. for(i=0;i<ch;i++)if(nonzero[i])break;
  105013. if(i==ch)return(0); /* no nonzero vectors */
  105014. for(s=0;s<look->stages;s++){
  105015. for(i=0,l=0;i<partvals;l++){
  105016. if(s==0){
  105017. int temp=vorbis_book_decode(look->phrasebook,&vb->opb);
  105018. if(temp==-1)goto eopbreak;
  105019. partword[l]=look->decodemap[temp];
  105020. if(partword[l]==NULL)goto errout;
  105021. }
  105022. for(k=0;k<partitions_per_word && i<partvals;k++,i++)
  105023. if(info->secondstages[partword[l][k]]&(1<<s)){
  105024. codebook *stagebook=look->partbooks[partword[l][k]][s];
  105025. if(stagebook){
  105026. if(vorbis_book_decodevv_add(stagebook,in,
  105027. i*samples_per_partition+info->begin,ch,
  105028. &vb->opb,samples_per_partition)==-1)
  105029. goto eopbreak;
  105030. }
  105031. }
  105032. }
  105033. }
  105034. errout:
  105035. eopbreak:
  105036. return(0);
  105037. }
  105038. vorbis_func_residue residue0_exportbundle={
  105039. NULL,
  105040. &res0_unpack,
  105041. &res0_look,
  105042. &res0_free_info,
  105043. &res0_free_look,
  105044. NULL,
  105045. NULL,
  105046. &res0_inverse
  105047. };
  105048. vorbis_func_residue residue1_exportbundle={
  105049. &res0_pack,
  105050. &res0_unpack,
  105051. &res0_look,
  105052. &res0_free_info,
  105053. &res0_free_look,
  105054. &res1_class,
  105055. &res1_forward,
  105056. &res1_inverse
  105057. };
  105058. vorbis_func_residue residue2_exportbundle={
  105059. &res0_pack,
  105060. &res0_unpack,
  105061. &res0_look,
  105062. &res0_free_info,
  105063. &res0_free_look,
  105064. &res2_class,
  105065. &res2_forward,
  105066. &res2_inverse
  105067. };
  105068. #endif
  105069. /*** End of inlined file: res0.c ***/
  105070. /*** Start of inlined file: sharedbook.c ***/
  105071. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  105072. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  105073. // tasks..
  105074. #if JUCE_MSVC
  105075. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  105076. #endif
  105077. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  105078. #if JUCE_USE_OGGVORBIS
  105079. #include <stdlib.h>
  105080. #include <math.h>
  105081. #include <string.h>
  105082. int _ilog(unsigned int v){
  105083. int ret=0;
  105084. while(v){
  105085. ret++;
  105086. v>>=1;
  105087. }
  105088. return(ret);
  105089. }
  105090. #define VQ_FEXP 10
  105091. #define VQ_FMAN 21
  105092. #define VQ_FEXP_BIAS 768 /* bias toward values smaller than 1. */
  105093. long _float32_pack(float val){
  105094. int sign=0;
  105095. long exp;
  105096. long mant;
  105097. if(val<0){
  105098. sign=0x80000000;
  105099. val= -val;
  105100. }
  105101. exp= floor(log(val)/log(2.f));
  105102. mant=rint(ldexp(val,(VQ_FMAN-1)-exp));
  105103. exp=(exp+VQ_FEXP_BIAS)<<VQ_FMAN;
  105104. return(sign|exp|mant);
  105105. }
  105106. float _float32_unpack(long val){
  105107. double mant=val&0x1fffff;
  105108. int sign=val&0x80000000;
  105109. long exp =(val&0x7fe00000L)>>VQ_FMAN;
  105110. if(sign)mant= -mant;
  105111. return(ldexp(mant,exp-(VQ_FMAN-1)-VQ_FEXP_BIAS));
  105112. }
  105113. ogg_uint32_t *_make_words(long *l,long n,long sparsecount){
  105114. long i,j,count=0;
  105115. ogg_uint32_t marker[33];
  105116. ogg_uint32_t *r=(ogg_uint32_t*)_ogg_malloc((sparsecount?sparsecount:n)*sizeof(*r));
  105117. memset(marker,0,sizeof(marker));
  105118. for(i=0;i<n;i++){
  105119. long length=l[i];
  105120. if(length>0){
  105121. ogg_uint32_t entry=marker[length];
  105122. if(length<32 && (entry>>length)){
  105123. _ogg_free(r);
  105124. return(NULL);
  105125. }
  105126. r[count++]=entry;
  105127. {
  105128. for(j=length;j>0;j--){
  105129. if(marker[j]&1){
  105130. if(j==1)
  105131. marker[1]++;
  105132. else
  105133. marker[j]=marker[j-1]<<1;
  105134. break; /* invariant says next upper marker would already
  105135. have been moved if it was on the same path */
  105136. }
  105137. marker[j]++;
  105138. }
  105139. }
  105140. for(j=length+1;j<33;j++)
  105141. if((marker[j]>>1) == entry){
  105142. entry=marker[j];
  105143. marker[j]=marker[j-1]<<1;
  105144. }else
  105145. break;
  105146. }else
  105147. if(sparsecount==0)count++;
  105148. }
  105149. for(i=0,count=0;i<n;i++){
  105150. ogg_uint32_t temp=0;
  105151. for(j=0;j<l[i];j++){
  105152. temp<<=1;
  105153. temp|=(r[count]>>j)&1;
  105154. }
  105155. if(sparsecount){
  105156. if(l[i])
  105157. r[count++]=temp;
  105158. }else
  105159. r[count++]=temp;
  105160. }
  105161. return(r);
  105162. }
  105163. long _book_maptype1_quantvals(const static_codebook *b){
  105164. long vals=floor(pow((float)b->entries,1.f/b->dim));
  105165. while(1){
  105166. long acc=1;
  105167. long acc1=1;
  105168. int i;
  105169. for(i=0;i<b->dim;i++){
  105170. acc*=vals;
  105171. acc1*=vals+1;
  105172. }
  105173. if(acc<=b->entries && acc1>b->entries){
  105174. return(vals);
  105175. }else{
  105176. if(acc>b->entries){
  105177. vals--;
  105178. }else{
  105179. vals++;
  105180. }
  105181. }
  105182. }
  105183. }
  105184. float *_book_unquantize(const static_codebook *b,int n,int *sparsemap){
  105185. long j,k,count=0;
  105186. if(b->maptype==1 || b->maptype==2){
  105187. int quantvals;
  105188. float mindel=_float32_unpack(b->q_min);
  105189. float delta=_float32_unpack(b->q_delta);
  105190. float *r=(float*)_ogg_calloc(n*b->dim,sizeof(*r));
  105191. switch(b->maptype){
  105192. case 1:
  105193. quantvals=_book_maptype1_quantvals(b);
  105194. for(j=0;j<b->entries;j++){
  105195. if((sparsemap && b->lengthlist[j]) || !sparsemap){
  105196. float last=0.f;
  105197. int indexdiv=1;
  105198. for(k=0;k<b->dim;k++){
  105199. int index= (j/indexdiv)%quantvals;
  105200. float val=b->quantlist[index];
  105201. val=fabs(val)*delta+mindel+last;
  105202. if(b->q_sequencep)last=val;
  105203. if(sparsemap)
  105204. r[sparsemap[count]*b->dim+k]=val;
  105205. else
  105206. r[count*b->dim+k]=val;
  105207. indexdiv*=quantvals;
  105208. }
  105209. count++;
  105210. }
  105211. }
  105212. break;
  105213. case 2:
  105214. for(j=0;j<b->entries;j++){
  105215. if((sparsemap && b->lengthlist[j]) || !sparsemap){
  105216. float last=0.f;
  105217. for(k=0;k<b->dim;k++){
  105218. float val=b->quantlist[j*b->dim+k];
  105219. val=fabs(val)*delta+mindel+last;
  105220. if(b->q_sequencep)last=val;
  105221. if(sparsemap)
  105222. r[sparsemap[count]*b->dim+k]=val;
  105223. else
  105224. r[count*b->dim+k]=val;
  105225. }
  105226. count++;
  105227. }
  105228. }
  105229. break;
  105230. }
  105231. return(r);
  105232. }
  105233. return(NULL);
  105234. }
  105235. void vorbis_staticbook_clear(static_codebook *b){
  105236. if(b->allocedp){
  105237. if(b->quantlist)_ogg_free(b->quantlist);
  105238. if(b->lengthlist)_ogg_free(b->lengthlist);
  105239. if(b->nearest_tree){
  105240. _ogg_free(b->nearest_tree->ptr0);
  105241. _ogg_free(b->nearest_tree->ptr1);
  105242. _ogg_free(b->nearest_tree->p);
  105243. _ogg_free(b->nearest_tree->q);
  105244. memset(b->nearest_tree,0,sizeof(*b->nearest_tree));
  105245. _ogg_free(b->nearest_tree);
  105246. }
  105247. if(b->thresh_tree){
  105248. _ogg_free(b->thresh_tree->quantthresh);
  105249. _ogg_free(b->thresh_tree->quantmap);
  105250. memset(b->thresh_tree,0,sizeof(*b->thresh_tree));
  105251. _ogg_free(b->thresh_tree);
  105252. }
  105253. memset(b,0,sizeof(*b));
  105254. }
  105255. }
  105256. void vorbis_staticbook_destroy(static_codebook *b){
  105257. if(b->allocedp){
  105258. vorbis_staticbook_clear(b);
  105259. _ogg_free(b);
  105260. }
  105261. }
  105262. void vorbis_book_clear(codebook *b){
  105263. if(b->valuelist)_ogg_free(b->valuelist);
  105264. if(b->codelist)_ogg_free(b->codelist);
  105265. if(b->dec_index)_ogg_free(b->dec_index);
  105266. if(b->dec_codelengths)_ogg_free(b->dec_codelengths);
  105267. if(b->dec_firsttable)_ogg_free(b->dec_firsttable);
  105268. memset(b,0,sizeof(*b));
  105269. }
  105270. int vorbis_book_init_encode(codebook *c,const static_codebook *s){
  105271. memset(c,0,sizeof(*c));
  105272. c->c=s;
  105273. c->entries=s->entries;
  105274. c->used_entries=s->entries;
  105275. c->dim=s->dim;
  105276. c->codelist=_make_words(s->lengthlist,s->entries,0);
  105277. c->valuelist=_book_unquantize(s,s->entries,NULL);
  105278. return(0);
  105279. }
  105280. static int sort32a(const void *a,const void *b){
  105281. return ( **(ogg_uint32_t **)a>**(ogg_uint32_t **)b)-
  105282. ( **(ogg_uint32_t **)a<**(ogg_uint32_t **)b);
  105283. }
  105284. int vorbis_book_init_decode(codebook *c,const static_codebook *s){
  105285. int i,j,n=0,tabn;
  105286. int *sortindex;
  105287. memset(c,0,sizeof(*c));
  105288. for(i=0;i<s->entries;i++)
  105289. if(s->lengthlist[i]>0)
  105290. n++;
  105291. c->entries=s->entries;
  105292. c->used_entries=n;
  105293. c->dim=s->dim;
  105294. {
  105295. ogg_uint32_t *codes=_make_words(s->lengthlist,s->entries,c->used_entries);
  105296. ogg_uint32_t **codep=(ogg_uint32_t**)alloca(sizeof(*codep)*n);
  105297. if(codes==NULL)goto err_out;
  105298. for(i=0;i<n;i++){
  105299. codes[i]=ogg_bitreverse(codes[i]);
  105300. codep[i]=codes+i;
  105301. }
  105302. qsort(codep,n,sizeof(*codep),sort32a);
  105303. sortindex=(int*)alloca(n*sizeof(*sortindex));
  105304. c->codelist=(ogg_uint32_t*)_ogg_malloc(n*sizeof(*c->codelist));
  105305. for(i=0;i<n;i++){
  105306. int position=codep[i]-codes;
  105307. sortindex[position]=i;
  105308. }
  105309. for(i=0;i<n;i++)
  105310. c->codelist[sortindex[i]]=codes[i];
  105311. _ogg_free(codes);
  105312. }
  105313. c->valuelist=_book_unquantize(s,n,sortindex);
  105314. c->dec_index=(int*)_ogg_malloc(n*sizeof(*c->dec_index));
  105315. for(n=0,i=0;i<s->entries;i++)
  105316. if(s->lengthlist[i]>0)
  105317. c->dec_index[sortindex[n++]]=i;
  105318. c->dec_codelengths=(char*)_ogg_malloc(n*sizeof(*c->dec_codelengths));
  105319. for(n=0,i=0;i<s->entries;i++)
  105320. if(s->lengthlist[i]>0)
  105321. c->dec_codelengths[sortindex[n++]]=s->lengthlist[i];
  105322. c->dec_firsttablen=_ilog(c->used_entries)-4; /* this is magic */
  105323. if(c->dec_firsttablen<5)c->dec_firsttablen=5;
  105324. if(c->dec_firsttablen>8)c->dec_firsttablen=8;
  105325. tabn=1<<c->dec_firsttablen;
  105326. c->dec_firsttable=(ogg_uint32_t*)_ogg_calloc(tabn,sizeof(*c->dec_firsttable));
  105327. c->dec_maxlength=0;
  105328. for(i=0;i<n;i++){
  105329. if(c->dec_maxlength<c->dec_codelengths[i])
  105330. c->dec_maxlength=c->dec_codelengths[i];
  105331. if(c->dec_codelengths[i]<=c->dec_firsttablen){
  105332. ogg_uint32_t orig=ogg_bitreverse(c->codelist[i]);
  105333. for(j=0;j<(1<<(c->dec_firsttablen-c->dec_codelengths[i]));j++)
  105334. c->dec_firsttable[orig|(j<<c->dec_codelengths[i])]=i+1;
  105335. }
  105336. }
  105337. {
  105338. ogg_uint32_t mask=0xfffffffeUL<<(31-c->dec_firsttablen);
  105339. long lo=0,hi=0;
  105340. for(i=0;i<tabn;i++){
  105341. ogg_uint32_t word=i<<(32-c->dec_firsttablen);
  105342. if(c->dec_firsttable[ogg_bitreverse(word)]==0){
  105343. while((lo+1)<n && c->codelist[lo+1]<=word)lo++;
  105344. while( hi<n && word>=(c->codelist[hi]&mask))hi++;
  105345. {
  105346. unsigned long loval=lo;
  105347. unsigned long hival=n-hi;
  105348. if(loval>0x7fff)loval=0x7fff;
  105349. if(hival>0x7fff)hival=0x7fff;
  105350. c->dec_firsttable[ogg_bitreverse(word)]=
  105351. 0x80000000UL | (loval<<15) | hival;
  105352. }
  105353. }
  105354. }
  105355. }
  105356. return(0);
  105357. err_out:
  105358. vorbis_book_clear(c);
  105359. return(-1);
  105360. }
  105361. static float _dist(int el,float *ref, float *b,int step){
  105362. int i;
  105363. float acc=0.f;
  105364. for(i=0;i<el;i++){
  105365. float val=(ref[i]-b[i*step]);
  105366. acc+=val*val;
  105367. }
  105368. return(acc);
  105369. }
  105370. int _best(codebook *book, float *a, int step){
  105371. encode_aux_threshmatch *tt=book->c->thresh_tree;
  105372. #if 0
  105373. encode_aux_nearestmatch *nt=book->c->nearest_tree;
  105374. encode_aux_pigeonhole *pt=book->c->pigeon_tree;
  105375. #endif
  105376. int dim=book->dim;
  105377. int k,o;
  105378. if(tt){
  105379. int index=0,i;
  105380. for(k=0,o=step*(dim-1);k<dim;k++,o-=step){
  105381. i=tt->threshvals>>1;
  105382. if(a[o]<tt->quantthresh[i]){
  105383. for(;i>0;i--)
  105384. if(a[o]>=tt->quantthresh[i-1])
  105385. break;
  105386. }else{
  105387. for(i++;i<tt->threshvals-1;i++)
  105388. if(a[o]<tt->quantthresh[i])break;
  105389. }
  105390. index=(index*tt->quantvals)+tt->quantmap[i];
  105391. }
  105392. if(book->c->lengthlist[index]>0) /* is this unused? If so, we'll
  105393. use a decision tree after all
  105394. and fall through*/
  105395. return(index);
  105396. }
  105397. #if 0
  105398. if(pt){
  105399. const static_codebook *c=book->c;
  105400. int i,besti=-1;
  105401. float best=0.f;
  105402. int entry=0;
  105403. if(c->q_sequencep){
  105404. int pv;
  105405. long mul=1;
  105406. float qlast=0;
  105407. for(k=0,o=0;k<dim;k++,o+=step){
  105408. pv=(int)((a[o]-qlast-pt->min)/pt->del);
  105409. if(pv<0 || pv>=pt->mapentries)break;
  105410. entry+=pt->pigeonmap[pv]*mul;
  105411. mul*=pt->quantvals;
  105412. qlast+=pv*pt->del+pt->min;
  105413. }
  105414. }else{
  105415. for(k=0,o=step*(dim-1);k<dim;k++,o-=step){
  105416. int pv=(int)((a[o]-pt->min)/pt->del);
  105417. if(pv<0 || pv>=pt->mapentries)break;
  105418. entry=entry*pt->quantvals+pt->pigeonmap[pv];
  105419. }
  105420. }
  105421. if(k==dim && pt->fitlength[entry]){
  105422. long *list=pt->fitlist+pt->fitmap[entry];
  105423. for(i=0;i<pt->fitlength[entry];i++){
  105424. float this=_dist(dim,book->valuelist+list[i]*dim,a,step);
  105425. if(besti==-1 || this<best){
  105426. best=this;
  105427. besti=list[i];
  105428. }
  105429. }
  105430. return(besti);
  105431. }
  105432. }
  105433. if(nt){
  105434. while(1){
  105435. float c=0.f;
  105436. float *p=book->valuelist+nt->p[ptr];
  105437. float *q=book->valuelist+nt->q[ptr];
  105438. for(k=0,o=0;k<dim;k++,o+=step)
  105439. c+=(p[k]-q[k])*(a[o]-(p[k]+q[k])*.5);
  105440. if(c>0.f) /* in A */
  105441. ptr= -nt->ptr0[ptr];
  105442. else /* in B */
  105443. ptr= -nt->ptr1[ptr];
  105444. if(ptr<=0)break;
  105445. }
  105446. return(-ptr);
  105447. }
  105448. #endif
  105449. {
  105450. const static_codebook *c=book->c;
  105451. int i,besti=-1;
  105452. float best=0.f;
  105453. float *e=book->valuelist;
  105454. for(i=0;i<book->entries;i++){
  105455. if(c->lengthlist[i]>0){
  105456. float thisx=_dist(dim,e,a,step);
  105457. if(besti==-1 || thisx<best){
  105458. best=thisx;
  105459. besti=i;
  105460. }
  105461. }
  105462. e+=dim;
  105463. }
  105464. return(besti);
  105465. }
  105466. }
  105467. long vorbis_book_codeword(codebook *book,int entry){
  105468. if(book->c) /* only use with encode; decode optimizations are
  105469. allowed to break this */
  105470. return book->codelist[entry];
  105471. return -1;
  105472. }
  105473. long vorbis_book_codelen(codebook *book,int entry){
  105474. if(book->c) /* only use with encode; decode optimizations are
  105475. allowed to break this */
  105476. return book->c->lengthlist[entry];
  105477. return -1;
  105478. }
  105479. #ifdef _V_SELFTEST
  105480. #include <stdio.h>
  105481. static long full_quantlist1[]={0,1,2,3, 4,5,6,7, 8,3,6,1};
  105482. static long partial_quantlist1[]={0,7,2};
  105483. static_codebook test1={
  105484. 4,16,
  105485. NULL,
  105486. 0,
  105487. 0,0,0,0,
  105488. NULL,
  105489. NULL,NULL
  105490. };
  105491. static float *test1_result=NULL;
  105492. static_codebook test2={
  105493. 4,3,
  105494. NULL,
  105495. 2,
  105496. -533200896,1611661312,4,0,
  105497. full_quantlist1,
  105498. NULL,NULL
  105499. };
  105500. static float test2_result[]={-3,-2,-1,0, 1,2,3,4, 5,0,3,-2};
  105501. static_codebook test3={
  105502. 4,3,
  105503. NULL,
  105504. 2,
  105505. -533200896,1611661312,4,1,
  105506. full_quantlist1,
  105507. NULL,NULL
  105508. };
  105509. static float test3_result[]={-3,-5,-6,-6, 1,3,6,10, 5,5,8,6};
  105510. static_codebook test4={
  105511. 3,27,
  105512. NULL,
  105513. 1,
  105514. -533200896,1611661312,4,0,
  105515. partial_quantlist1,
  105516. NULL,NULL
  105517. };
  105518. static float test4_result[]={-3,-3,-3, 4,-3,-3, -1,-3,-3,
  105519. -3, 4,-3, 4, 4,-3, -1, 4,-3,
  105520. -3,-1,-3, 4,-1,-3, -1,-1,-3,
  105521. -3,-3, 4, 4,-3, 4, -1,-3, 4,
  105522. -3, 4, 4, 4, 4, 4, -1, 4, 4,
  105523. -3,-1, 4, 4,-1, 4, -1,-1, 4,
  105524. -3,-3,-1, 4,-3,-1, -1,-3,-1,
  105525. -3, 4,-1, 4, 4,-1, -1, 4,-1,
  105526. -3,-1,-1, 4,-1,-1, -1,-1,-1};
  105527. static_codebook test5={
  105528. 3,27,
  105529. NULL,
  105530. 1,
  105531. -533200896,1611661312,4,1,
  105532. partial_quantlist1,
  105533. NULL,NULL
  105534. };
  105535. static float test5_result[]={-3,-6,-9, 4, 1,-2, -1,-4,-7,
  105536. -3, 1,-2, 4, 8, 5, -1, 3, 0,
  105537. -3,-4,-7, 4, 3, 0, -1,-2,-5,
  105538. -3,-6,-2, 4, 1, 5, -1,-4, 0,
  105539. -3, 1, 5, 4, 8,12, -1, 3, 7,
  105540. -3,-4, 0, 4, 3, 7, -1,-2, 2,
  105541. -3,-6,-7, 4, 1, 0, -1,-4,-5,
  105542. -3, 1, 0, 4, 8, 7, -1, 3, 2,
  105543. -3,-4,-5, 4, 3, 2, -1,-2,-3};
  105544. void run_test(static_codebook *b,float *comp){
  105545. float *out=_book_unquantize(b,b->entries,NULL);
  105546. int i;
  105547. if(comp){
  105548. if(!out){
  105549. fprintf(stderr,"_book_unquantize incorrectly returned NULL\n");
  105550. exit(1);
  105551. }
  105552. for(i=0;i<b->entries*b->dim;i++)
  105553. if(fabs(out[i]-comp[i])>.0001){
  105554. fprintf(stderr,"disagreement in unquantized and reference data:\n"
  105555. "position %d, %g != %g\n",i,out[i],comp[i]);
  105556. exit(1);
  105557. }
  105558. }else{
  105559. if(out){
  105560. fprintf(stderr,"_book_unquantize returned a value array: \n"
  105561. " correct result should have been NULL\n");
  105562. exit(1);
  105563. }
  105564. }
  105565. }
  105566. int main(){
  105567. fprintf(stderr,"Dequant test 1... ");
  105568. run_test(&test1,test1_result);
  105569. fprintf(stderr,"OK\nDequant test 2... ");
  105570. run_test(&test2,test2_result);
  105571. fprintf(stderr,"OK\nDequant test 3... ");
  105572. run_test(&test3,test3_result);
  105573. fprintf(stderr,"OK\nDequant test 4... ");
  105574. run_test(&test4,test4_result);
  105575. fprintf(stderr,"OK\nDequant test 5... ");
  105576. run_test(&test5,test5_result);
  105577. fprintf(stderr,"OK\n\n");
  105578. return(0);
  105579. }
  105580. #endif
  105581. #endif
  105582. /*** End of inlined file: sharedbook.c ***/
  105583. /*** Start of inlined file: smallft.c ***/
  105584. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  105585. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  105586. // tasks..
  105587. #if JUCE_MSVC
  105588. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  105589. #endif
  105590. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  105591. #if JUCE_USE_OGGVORBIS
  105592. #include <stdlib.h>
  105593. #include <string.h>
  105594. #include <math.h>
  105595. static void drfti1(int n, float *wa, int *ifac){
  105596. static int ntryh[4] = { 4,2,3,5 };
  105597. static float tpi = 6.28318530717958648f;
  105598. float arg,argh,argld,fi;
  105599. int ntry=0,i,j=-1;
  105600. int k1, l1, l2, ib;
  105601. int ld, ii, ip, is, nq, nr;
  105602. int ido, ipm, nfm1;
  105603. int nl=n;
  105604. int nf=0;
  105605. L101:
  105606. j++;
  105607. if (j < 4)
  105608. ntry=ntryh[j];
  105609. else
  105610. ntry+=2;
  105611. L104:
  105612. nq=nl/ntry;
  105613. nr=nl-ntry*nq;
  105614. if (nr!=0) goto L101;
  105615. nf++;
  105616. ifac[nf+1]=ntry;
  105617. nl=nq;
  105618. if(ntry!=2)goto L107;
  105619. if(nf==1)goto L107;
  105620. for (i=1;i<nf;i++){
  105621. ib=nf-i+1;
  105622. ifac[ib+1]=ifac[ib];
  105623. }
  105624. ifac[2] = 2;
  105625. L107:
  105626. if(nl!=1)goto L104;
  105627. ifac[0]=n;
  105628. ifac[1]=nf;
  105629. argh=tpi/n;
  105630. is=0;
  105631. nfm1=nf-1;
  105632. l1=1;
  105633. if(nfm1==0)return;
  105634. for (k1=0;k1<nfm1;k1++){
  105635. ip=ifac[k1+2];
  105636. ld=0;
  105637. l2=l1*ip;
  105638. ido=n/l2;
  105639. ipm=ip-1;
  105640. for (j=0;j<ipm;j++){
  105641. ld+=l1;
  105642. i=is;
  105643. argld=(float)ld*argh;
  105644. fi=0.f;
  105645. for (ii=2;ii<ido;ii+=2){
  105646. fi+=1.f;
  105647. arg=fi*argld;
  105648. wa[i++]=cos(arg);
  105649. wa[i++]=sin(arg);
  105650. }
  105651. is+=ido;
  105652. }
  105653. l1=l2;
  105654. }
  105655. }
  105656. static void fdrffti(int n, float *wsave, int *ifac){
  105657. if (n == 1) return;
  105658. drfti1(n, wsave+n, ifac);
  105659. }
  105660. static void dradf2(int ido,int l1,float *cc,float *ch,float *wa1){
  105661. int i,k;
  105662. float ti2,tr2;
  105663. int t0,t1,t2,t3,t4,t5,t6;
  105664. t1=0;
  105665. t0=(t2=l1*ido);
  105666. t3=ido<<1;
  105667. for(k=0;k<l1;k++){
  105668. ch[t1<<1]=cc[t1]+cc[t2];
  105669. ch[(t1<<1)+t3-1]=cc[t1]-cc[t2];
  105670. t1+=ido;
  105671. t2+=ido;
  105672. }
  105673. if(ido<2)return;
  105674. if(ido==2)goto L105;
  105675. t1=0;
  105676. t2=t0;
  105677. for(k=0;k<l1;k++){
  105678. t3=t2;
  105679. t4=(t1<<1)+(ido<<1);
  105680. t5=t1;
  105681. t6=t1+t1;
  105682. for(i=2;i<ido;i+=2){
  105683. t3+=2;
  105684. t4-=2;
  105685. t5+=2;
  105686. t6+=2;
  105687. tr2=wa1[i-2]*cc[t3-1]+wa1[i-1]*cc[t3];
  105688. ti2=wa1[i-2]*cc[t3]-wa1[i-1]*cc[t3-1];
  105689. ch[t6]=cc[t5]+ti2;
  105690. ch[t4]=ti2-cc[t5];
  105691. ch[t6-1]=cc[t5-1]+tr2;
  105692. ch[t4-1]=cc[t5-1]-tr2;
  105693. }
  105694. t1+=ido;
  105695. t2+=ido;
  105696. }
  105697. if(ido%2==1)return;
  105698. L105:
  105699. t3=(t2=(t1=ido)-1);
  105700. t2+=t0;
  105701. for(k=0;k<l1;k++){
  105702. ch[t1]=-cc[t2];
  105703. ch[t1-1]=cc[t3];
  105704. t1+=ido<<1;
  105705. t2+=ido;
  105706. t3+=ido;
  105707. }
  105708. }
  105709. static void dradf4(int ido,int l1,float *cc,float *ch,float *wa1,
  105710. float *wa2,float *wa3){
  105711. static float hsqt2 = .70710678118654752f;
  105712. int i,k,t0,t1,t2,t3,t4,t5,t6;
  105713. float ci2,ci3,ci4,cr2,cr3,cr4,ti1,ti2,ti3,ti4,tr1,tr2,tr3,tr4;
  105714. t0=l1*ido;
  105715. t1=t0;
  105716. t4=t1<<1;
  105717. t2=t1+(t1<<1);
  105718. t3=0;
  105719. for(k=0;k<l1;k++){
  105720. tr1=cc[t1]+cc[t2];
  105721. tr2=cc[t3]+cc[t4];
  105722. ch[t5=t3<<2]=tr1+tr2;
  105723. ch[(ido<<2)+t5-1]=tr2-tr1;
  105724. ch[(t5+=(ido<<1))-1]=cc[t3]-cc[t4];
  105725. ch[t5]=cc[t2]-cc[t1];
  105726. t1+=ido;
  105727. t2+=ido;
  105728. t3+=ido;
  105729. t4+=ido;
  105730. }
  105731. if(ido<2)return;
  105732. if(ido==2)goto L105;
  105733. t1=0;
  105734. for(k=0;k<l1;k++){
  105735. t2=t1;
  105736. t4=t1<<2;
  105737. t5=(t6=ido<<1)+t4;
  105738. for(i=2;i<ido;i+=2){
  105739. t3=(t2+=2);
  105740. t4+=2;
  105741. t5-=2;
  105742. t3+=t0;
  105743. cr2=wa1[i-2]*cc[t3-1]+wa1[i-1]*cc[t3];
  105744. ci2=wa1[i-2]*cc[t3]-wa1[i-1]*cc[t3-1];
  105745. t3+=t0;
  105746. cr3=wa2[i-2]*cc[t3-1]+wa2[i-1]*cc[t3];
  105747. ci3=wa2[i-2]*cc[t3]-wa2[i-1]*cc[t3-1];
  105748. t3+=t0;
  105749. cr4=wa3[i-2]*cc[t3-1]+wa3[i-1]*cc[t3];
  105750. ci4=wa3[i-2]*cc[t3]-wa3[i-1]*cc[t3-1];
  105751. tr1=cr2+cr4;
  105752. tr4=cr4-cr2;
  105753. ti1=ci2+ci4;
  105754. ti4=ci2-ci4;
  105755. ti2=cc[t2]+ci3;
  105756. ti3=cc[t2]-ci3;
  105757. tr2=cc[t2-1]+cr3;
  105758. tr3=cc[t2-1]-cr3;
  105759. ch[t4-1]=tr1+tr2;
  105760. ch[t4]=ti1+ti2;
  105761. ch[t5-1]=tr3-ti4;
  105762. ch[t5]=tr4-ti3;
  105763. ch[t4+t6-1]=ti4+tr3;
  105764. ch[t4+t6]=tr4+ti3;
  105765. ch[t5+t6-1]=tr2-tr1;
  105766. ch[t5+t6]=ti1-ti2;
  105767. }
  105768. t1+=ido;
  105769. }
  105770. if(ido&1)return;
  105771. L105:
  105772. t2=(t1=t0+ido-1)+(t0<<1);
  105773. t3=ido<<2;
  105774. t4=ido;
  105775. t5=ido<<1;
  105776. t6=ido;
  105777. for(k=0;k<l1;k++){
  105778. ti1=-hsqt2*(cc[t1]+cc[t2]);
  105779. tr1=hsqt2*(cc[t1]-cc[t2]);
  105780. ch[t4-1]=tr1+cc[t6-1];
  105781. ch[t4+t5-1]=cc[t6-1]-tr1;
  105782. ch[t4]=ti1-cc[t1+t0];
  105783. ch[t4+t5]=ti1+cc[t1+t0];
  105784. t1+=ido;
  105785. t2+=ido;
  105786. t4+=t3;
  105787. t6+=ido;
  105788. }
  105789. }
  105790. static void dradfg(int ido,int ip,int l1,int idl1,float *cc,float *c1,
  105791. float *c2,float *ch,float *ch2,float *wa){
  105792. static float tpi=6.283185307179586f;
  105793. int idij,ipph,i,j,k,l,ic,ik,is;
  105794. int t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
  105795. float dc2,ai1,ai2,ar1,ar2,ds2;
  105796. int nbd;
  105797. float dcp,arg,dsp,ar1h,ar2h;
  105798. int idp2,ipp2;
  105799. arg=tpi/(float)ip;
  105800. dcp=cos(arg);
  105801. dsp=sin(arg);
  105802. ipph=(ip+1)>>1;
  105803. ipp2=ip;
  105804. idp2=ido;
  105805. nbd=(ido-1)>>1;
  105806. t0=l1*ido;
  105807. t10=ip*ido;
  105808. if(ido==1)goto L119;
  105809. for(ik=0;ik<idl1;ik++)ch2[ik]=c2[ik];
  105810. t1=0;
  105811. for(j=1;j<ip;j++){
  105812. t1+=t0;
  105813. t2=t1;
  105814. for(k=0;k<l1;k++){
  105815. ch[t2]=c1[t2];
  105816. t2+=ido;
  105817. }
  105818. }
  105819. is=-ido;
  105820. t1=0;
  105821. if(nbd>l1){
  105822. for(j=1;j<ip;j++){
  105823. t1+=t0;
  105824. is+=ido;
  105825. t2= -ido+t1;
  105826. for(k=0;k<l1;k++){
  105827. idij=is-1;
  105828. t2+=ido;
  105829. t3=t2;
  105830. for(i=2;i<ido;i+=2){
  105831. idij+=2;
  105832. t3+=2;
  105833. ch[t3-1]=wa[idij-1]*c1[t3-1]+wa[idij]*c1[t3];
  105834. ch[t3]=wa[idij-1]*c1[t3]-wa[idij]*c1[t3-1];
  105835. }
  105836. }
  105837. }
  105838. }else{
  105839. for(j=1;j<ip;j++){
  105840. is+=ido;
  105841. idij=is-1;
  105842. t1+=t0;
  105843. t2=t1;
  105844. for(i=2;i<ido;i+=2){
  105845. idij+=2;
  105846. t2+=2;
  105847. t3=t2;
  105848. for(k=0;k<l1;k++){
  105849. ch[t3-1]=wa[idij-1]*c1[t3-1]+wa[idij]*c1[t3];
  105850. ch[t3]=wa[idij-1]*c1[t3]-wa[idij]*c1[t3-1];
  105851. t3+=ido;
  105852. }
  105853. }
  105854. }
  105855. }
  105856. t1=0;
  105857. t2=ipp2*t0;
  105858. if(nbd<l1){
  105859. for(j=1;j<ipph;j++){
  105860. t1+=t0;
  105861. t2-=t0;
  105862. t3=t1;
  105863. t4=t2;
  105864. for(i=2;i<ido;i+=2){
  105865. t3+=2;
  105866. t4+=2;
  105867. t5=t3-ido;
  105868. t6=t4-ido;
  105869. for(k=0;k<l1;k++){
  105870. t5+=ido;
  105871. t6+=ido;
  105872. c1[t5-1]=ch[t5-1]+ch[t6-1];
  105873. c1[t6-1]=ch[t5]-ch[t6];
  105874. c1[t5]=ch[t5]+ch[t6];
  105875. c1[t6]=ch[t6-1]-ch[t5-1];
  105876. }
  105877. }
  105878. }
  105879. }else{
  105880. for(j=1;j<ipph;j++){
  105881. t1+=t0;
  105882. t2-=t0;
  105883. t3=t1;
  105884. t4=t2;
  105885. for(k=0;k<l1;k++){
  105886. t5=t3;
  105887. t6=t4;
  105888. for(i=2;i<ido;i+=2){
  105889. t5+=2;
  105890. t6+=2;
  105891. c1[t5-1]=ch[t5-1]+ch[t6-1];
  105892. c1[t6-1]=ch[t5]-ch[t6];
  105893. c1[t5]=ch[t5]+ch[t6];
  105894. c1[t6]=ch[t6-1]-ch[t5-1];
  105895. }
  105896. t3+=ido;
  105897. t4+=ido;
  105898. }
  105899. }
  105900. }
  105901. L119:
  105902. for(ik=0;ik<idl1;ik++)c2[ik]=ch2[ik];
  105903. t1=0;
  105904. t2=ipp2*idl1;
  105905. for(j=1;j<ipph;j++){
  105906. t1+=t0;
  105907. t2-=t0;
  105908. t3=t1-ido;
  105909. t4=t2-ido;
  105910. for(k=0;k<l1;k++){
  105911. t3+=ido;
  105912. t4+=ido;
  105913. c1[t3]=ch[t3]+ch[t4];
  105914. c1[t4]=ch[t4]-ch[t3];
  105915. }
  105916. }
  105917. ar1=1.f;
  105918. ai1=0.f;
  105919. t1=0;
  105920. t2=ipp2*idl1;
  105921. t3=(ip-1)*idl1;
  105922. for(l=1;l<ipph;l++){
  105923. t1+=idl1;
  105924. t2-=idl1;
  105925. ar1h=dcp*ar1-dsp*ai1;
  105926. ai1=dcp*ai1+dsp*ar1;
  105927. ar1=ar1h;
  105928. t4=t1;
  105929. t5=t2;
  105930. t6=t3;
  105931. t7=idl1;
  105932. for(ik=0;ik<idl1;ik++){
  105933. ch2[t4++]=c2[ik]+ar1*c2[t7++];
  105934. ch2[t5++]=ai1*c2[t6++];
  105935. }
  105936. dc2=ar1;
  105937. ds2=ai1;
  105938. ar2=ar1;
  105939. ai2=ai1;
  105940. t4=idl1;
  105941. t5=(ipp2-1)*idl1;
  105942. for(j=2;j<ipph;j++){
  105943. t4+=idl1;
  105944. t5-=idl1;
  105945. ar2h=dc2*ar2-ds2*ai2;
  105946. ai2=dc2*ai2+ds2*ar2;
  105947. ar2=ar2h;
  105948. t6=t1;
  105949. t7=t2;
  105950. t8=t4;
  105951. t9=t5;
  105952. for(ik=0;ik<idl1;ik++){
  105953. ch2[t6++]+=ar2*c2[t8++];
  105954. ch2[t7++]+=ai2*c2[t9++];
  105955. }
  105956. }
  105957. }
  105958. t1=0;
  105959. for(j=1;j<ipph;j++){
  105960. t1+=idl1;
  105961. t2=t1;
  105962. for(ik=0;ik<idl1;ik++)ch2[ik]+=c2[t2++];
  105963. }
  105964. if(ido<l1)goto L132;
  105965. t1=0;
  105966. t2=0;
  105967. for(k=0;k<l1;k++){
  105968. t3=t1;
  105969. t4=t2;
  105970. for(i=0;i<ido;i++)cc[t4++]=ch[t3++];
  105971. t1+=ido;
  105972. t2+=t10;
  105973. }
  105974. goto L135;
  105975. L132:
  105976. for(i=0;i<ido;i++){
  105977. t1=i;
  105978. t2=i;
  105979. for(k=0;k<l1;k++){
  105980. cc[t2]=ch[t1];
  105981. t1+=ido;
  105982. t2+=t10;
  105983. }
  105984. }
  105985. L135:
  105986. t1=0;
  105987. t2=ido<<1;
  105988. t3=0;
  105989. t4=ipp2*t0;
  105990. for(j=1;j<ipph;j++){
  105991. t1+=t2;
  105992. t3+=t0;
  105993. t4-=t0;
  105994. t5=t1;
  105995. t6=t3;
  105996. t7=t4;
  105997. for(k=0;k<l1;k++){
  105998. cc[t5-1]=ch[t6];
  105999. cc[t5]=ch[t7];
  106000. t5+=t10;
  106001. t6+=ido;
  106002. t7+=ido;
  106003. }
  106004. }
  106005. if(ido==1)return;
  106006. if(nbd<l1)goto L141;
  106007. t1=-ido;
  106008. t3=0;
  106009. t4=0;
  106010. t5=ipp2*t0;
  106011. for(j=1;j<ipph;j++){
  106012. t1+=t2;
  106013. t3+=t2;
  106014. t4+=t0;
  106015. t5-=t0;
  106016. t6=t1;
  106017. t7=t3;
  106018. t8=t4;
  106019. t9=t5;
  106020. for(k=0;k<l1;k++){
  106021. for(i=2;i<ido;i+=2){
  106022. ic=idp2-i;
  106023. cc[i+t7-1]=ch[i+t8-1]+ch[i+t9-1];
  106024. cc[ic+t6-1]=ch[i+t8-1]-ch[i+t9-1];
  106025. cc[i+t7]=ch[i+t8]+ch[i+t9];
  106026. cc[ic+t6]=ch[i+t9]-ch[i+t8];
  106027. }
  106028. t6+=t10;
  106029. t7+=t10;
  106030. t8+=ido;
  106031. t9+=ido;
  106032. }
  106033. }
  106034. return;
  106035. L141:
  106036. t1=-ido;
  106037. t3=0;
  106038. t4=0;
  106039. t5=ipp2*t0;
  106040. for(j=1;j<ipph;j++){
  106041. t1+=t2;
  106042. t3+=t2;
  106043. t4+=t0;
  106044. t5-=t0;
  106045. for(i=2;i<ido;i+=2){
  106046. t6=idp2+t1-i;
  106047. t7=i+t3;
  106048. t8=i+t4;
  106049. t9=i+t5;
  106050. for(k=0;k<l1;k++){
  106051. cc[t7-1]=ch[t8-1]+ch[t9-1];
  106052. cc[t6-1]=ch[t8-1]-ch[t9-1];
  106053. cc[t7]=ch[t8]+ch[t9];
  106054. cc[t6]=ch[t9]-ch[t8];
  106055. t6+=t10;
  106056. t7+=t10;
  106057. t8+=ido;
  106058. t9+=ido;
  106059. }
  106060. }
  106061. }
  106062. }
  106063. static void drftf1(int n,float *c,float *ch,float *wa,int *ifac){
  106064. int i,k1,l1,l2;
  106065. int na,kh,nf;
  106066. int ip,iw,ido,idl1,ix2,ix3;
  106067. nf=ifac[1];
  106068. na=1;
  106069. l2=n;
  106070. iw=n;
  106071. for(k1=0;k1<nf;k1++){
  106072. kh=nf-k1;
  106073. ip=ifac[kh+1];
  106074. l1=l2/ip;
  106075. ido=n/l2;
  106076. idl1=ido*l1;
  106077. iw-=(ip-1)*ido;
  106078. na=1-na;
  106079. if(ip!=4)goto L102;
  106080. ix2=iw+ido;
  106081. ix3=ix2+ido;
  106082. if(na!=0)
  106083. dradf4(ido,l1,ch,c,wa+iw-1,wa+ix2-1,wa+ix3-1);
  106084. else
  106085. dradf4(ido,l1,c,ch,wa+iw-1,wa+ix2-1,wa+ix3-1);
  106086. goto L110;
  106087. L102:
  106088. if(ip!=2)goto L104;
  106089. if(na!=0)goto L103;
  106090. dradf2(ido,l1,c,ch,wa+iw-1);
  106091. goto L110;
  106092. L103:
  106093. dradf2(ido,l1,ch,c,wa+iw-1);
  106094. goto L110;
  106095. L104:
  106096. if(ido==1)na=1-na;
  106097. if(na!=0)goto L109;
  106098. dradfg(ido,ip,l1,idl1,c,c,c,ch,ch,wa+iw-1);
  106099. na=1;
  106100. goto L110;
  106101. L109:
  106102. dradfg(ido,ip,l1,idl1,ch,ch,ch,c,c,wa+iw-1);
  106103. na=0;
  106104. L110:
  106105. l2=l1;
  106106. }
  106107. if(na==1)return;
  106108. for(i=0;i<n;i++)c[i]=ch[i];
  106109. }
  106110. static void dradb2(int ido,int l1,float *cc,float *ch,float *wa1){
  106111. int i,k,t0,t1,t2,t3,t4,t5,t6;
  106112. float ti2,tr2;
  106113. t0=l1*ido;
  106114. t1=0;
  106115. t2=0;
  106116. t3=(ido<<1)-1;
  106117. for(k=0;k<l1;k++){
  106118. ch[t1]=cc[t2]+cc[t3+t2];
  106119. ch[t1+t0]=cc[t2]-cc[t3+t2];
  106120. t2=(t1+=ido)<<1;
  106121. }
  106122. if(ido<2)return;
  106123. if(ido==2)goto L105;
  106124. t1=0;
  106125. t2=0;
  106126. for(k=0;k<l1;k++){
  106127. t3=t1;
  106128. t5=(t4=t2)+(ido<<1);
  106129. t6=t0+t1;
  106130. for(i=2;i<ido;i+=2){
  106131. t3+=2;
  106132. t4+=2;
  106133. t5-=2;
  106134. t6+=2;
  106135. ch[t3-1]=cc[t4-1]+cc[t5-1];
  106136. tr2=cc[t4-1]-cc[t5-1];
  106137. ch[t3]=cc[t4]-cc[t5];
  106138. ti2=cc[t4]+cc[t5];
  106139. ch[t6-1]=wa1[i-2]*tr2-wa1[i-1]*ti2;
  106140. ch[t6]=wa1[i-2]*ti2+wa1[i-1]*tr2;
  106141. }
  106142. t2=(t1+=ido)<<1;
  106143. }
  106144. if(ido%2==1)return;
  106145. L105:
  106146. t1=ido-1;
  106147. t2=ido-1;
  106148. for(k=0;k<l1;k++){
  106149. ch[t1]=cc[t2]+cc[t2];
  106150. ch[t1+t0]=-(cc[t2+1]+cc[t2+1]);
  106151. t1+=ido;
  106152. t2+=ido<<1;
  106153. }
  106154. }
  106155. static void dradb3(int ido,int l1,float *cc,float *ch,float *wa1,
  106156. float *wa2){
  106157. static float taur = -.5f;
  106158. static float taui = .8660254037844386f;
  106159. int i,k,t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
  106160. float ci2,ci3,di2,di3,cr2,cr3,dr2,dr3,ti2,tr2;
  106161. t0=l1*ido;
  106162. t1=0;
  106163. t2=t0<<1;
  106164. t3=ido<<1;
  106165. t4=ido+(ido<<1);
  106166. t5=0;
  106167. for(k=0;k<l1;k++){
  106168. tr2=cc[t3-1]+cc[t3-1];
  106169. cr2=cc[t5]+(taur*tr2);
  106170. ch[t1]=cc[t5]+tr2;
  106171. ci3=taui*(cc[t3]+cc[t3]);
  106172. ch[t1+t0]=cr2-ci3;
  106173. ch[t1+t2]=cr2+ci3;
  106174. t1+=ido;
  106175. t3+=t4;
  106176. t5+=t4;
  106177. }
  106178. if(ido==1)return;
  106179. t1=0;
  106180. t3=ido<<1;
  106181. for(k=0;k<l1;k++){
  106182. t7=t1+(t1<<1);
  106183. t6=(t5=t7+t3);
  106184. t8=t1;
  106185. t10=(t9=t1+t0)+t0;
  106186. for(i=2;i<ido;i+=2){
  106187. t5+=2;
  106188. t6-=2;
  106189. t7+=2;
  106190. t8+=2;
  106191. t9+=2;
  106192. t10+=2;
  106193. tr2=cc[t5-1]+cc[t6-1];
  106194. cr2=cc[t7-1]+(taur*tr2);
  106195. ch[t8-1]=cc[t7-1]+tr2;
  106196. ti2=cc[t5]-cc[t6];
  106197. ci2=cc[t7]+(taur*ti2);
  106198. ch[t8]=cc[t7]+ti2;
  106199. cr3=taui*(cc[t5-1]-cc[t6-1]);
  106200. ci3=taui*(cc[t5]+cc[t6]);
  106201. dr2=cr2-ci3;
  106202. dr3=cr2+ci3;
  106203. di2=ci2+cr3;
  106204. di3=ci2-cr3;
  106205. ch[t9-1]=wa1[i-2]*dr2-wa1[i-1]*di2;
  106206. ch[t9]=wa1[i-2]*di2+wa1[i-1]*dr2;
  106207. ch[t10-1]=wa2[i-2]*dr3-wa2[i-1]*di3;
  106208. ch[t10]=wa2[i-2]*di3+wa2[i-1]*dr3;
  106209. }
  106210. t1+=ido;
  106211. }
  106212. }
  106213. static void dradb4(int ido,int l1,float *cc,float *ch,float *wa1,
  106214. float *wa2,float *wa3){
  106215. static float sqrt2=1.414213562373095f;
  106216. int i,k,t0,t1,t2,t3,t4,t5,t6,t7,t8;
  106217. float ci2,ci3,ci4,cr2,cr3,cr4,ti1,ti2,ti3,ti4,tr1,tr2,tr3,tr4;
  106218. t0=l1*ido;
  106219. t1=0;
  106220. t2=ido<<2;
  106221. t3=0;
  106222. t6=ido<<1;
  106223. for(k=0;k<l1;k++){
  106224. t4=t3+t6;
  106225. t5=t1;
  106226. tr3=cc[t4-1]+cc[t4-1];
  106227. tr4=cc[t4]+cc[t4];
  106228. tr1=cc[t3]-cc[(t4+=t6)-1];
  106229. tr2=cc[t3]+cc[t4-1];
  106230. ch[t5]=tr2+tr3;
  106231. ch[t5+=t0]=tr1-tr4;
  106232. ch[t5+=t0]=tr2-tr3;
  106233. ch[t5+=t0]=tr1+tr4;
  106234. t1+=ido;
  106235. t3+=t2;
  106236. }
  106237. if(ido<2)return;
  106238. if(ido==2)goto L105;
  106239. t1=0;
  106240. for(k=0;k<l1;k++){
  106241. t5=(t4=(t3=(t2=t1<<2)+t6))+t6;
  106242. t7=t1;
  106243. for(i=2;i<ido;i+=2){
  106244. t2+=2;
  106245. t3+=2;
  106246. t4-=2;
  106247. t5-=2;
  106248. t7+=2;
  106249. ti1=cc[t2]+cc[t5];
  106250. ti2=cc[t2]-cc[t5];
  106251. ti3=cc[t3]-cc[t4];
  106252. tr4=cc[t3]+cc[t4];
  106253. tr1=cc[t2-1]-cc[t5-1];
  106254. tr2=cc[t2-1]+cc[t5-1];
  106255. ti4=cc[t3-1]-cc[t4-1];
  106256. tr3=cc[t3-1]+cc[t4-1];
  106257. ch[t7-1]=tr2+tr3;
  106258. cr3=tr2-tr3;
  106259. ch[t7]=ti2+ti3;
  106260. ci3=ti2-ti3;
  106261. cr2=tr1-tr4;
  106262. cr4=tr1+tr4;
  106263. ci2=ti1+ti4;
  106264. ci4=ti1-ti4;
  106265. ch[(t8=t7+t0)-1]=wa1[i-2]*cr2-wa1[i-1]*ci2;
  106266. ch[t8]=wa1[i-2]*ci2+wa1[i-1]*cr2;
  106267. ch[(t8+=t0)-1]=wa2[i-2]*cr3-wa2[i-1]*ci3;
  106268. ch[t8]=wa2[i-2]*ci3+wa2[i-1]*cr3;
  106269. ch[(t8+=t0)-1]=wa3[i-2]*cr4-wa3[i-1]*ci4;
  106270. ch[t8]=wa3[i-2]*ci4+wa3[i-1]*cr4;
  106271. }
  106272. t1+=ido;
  106273. }
  106274. if(ido%2 == 1)return;
  106275. L105:
  106276. t1=ido;
  106277. t2=ido<<2;
  106278. t3=ido-1;
  106279. t4=ido+(ido<<1);
  106280. for(k=0;k<l1;k++){
  106281. t5=t3;
  106282. ti1=cc[t1]+cc[t4];
  106283. ti2=cc[t4]-cc[t1];
  106284. tr1=cc[t1-1]-cc[t4-1];
  106285. tr2=cc[t1-1]+cc[t4-1];
  106286. ch[t5]=tr2+tr2;
  106287. ch[t5+=t0]=sqrt2*(tr1-ti1);
  106288. ch[t5+=t0]=ti2+ti2;
  106289. ch[t5+=t0]=-sqrt2*(tr1+ti1);
  106290. t3+=ido;
  106291. t1+=t2;
  106292. t4+=t2;
  106293. }
  106294. }
  106295. static void dradbg(int ido,int ip,int l1,int idl1,float *cc,float *c1,
  106296. float *c2,float *ch,float *ch2,float *wa){
  106297. static float tpi=6.283185307179586f;
  106298. int idij,ipph,i,j,k,l,ik,is,t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,
  106299. t11,t12;
  106300. float dc2,ai1,ai2,ar1,ar2,ds2;
  106301. int nbd;
  106302. float dcp,arg,dsp,ar1h,ar2h;
  106303. int ipp2;
  106304. t10=ip*ido;
  106305. t0=l1*ido;
  106306. arg=tpi/(float)ip;
  106307. dcp=cos(arg);
  106308. dsp=sin(arg);
  106309. nbd=(ido-1)>>1;
  106310. ipp2=ip;
  106311. ipph=(ip+1)>>1;
  106312. if(ido<l1)goto L103;
  106313. t1=0;
  106314. t2=0;
  106315. for(k=0;k<l1;k++){
  106316. t3=t1;
  106317. t4=t2;
  106318. for(i=0;i<ido;i++){
  106319. ch[t3]=cc[t4];
  106320. t3++;
  106321. t4++;
  106322. }
  106323. t1+=ido;
  106324. t2+=t10;
  106325. }
  106326. goto L106;
  106327. L103:
  106328. t1=0;
  106329. for(i=0;i<ido;i++){
  106330. t2=t1;
  106331. t3=t1;
  106332. for(k=0;k<l1;k++){
  106333. ch[t2]=cc[t3];
  106334. t2+=ido;
  106335. t3+=t10;
  106336. }
  106337. t1++;
  106338. }
  106339. L106:
  106340. t1=0;
  106341. t2=ipp2*t0;
  106342. t7=(t5=ido<<1);
  106343. for(j=1;j<ipph;j++){
  106344. t1+=t0;
  106345. t2-=t0;
  106346. t3=t1;
  106347. t4=t2;
  106348. t6=t5;
  106349. for(k=0;k<l1;k++){
  106350. ch[t3]=cc[t6-1]+cc[t6-1];
  106351. ch[t4]=cc[t6]+cc[t6];
  106352. t3+=ido;
  106353. t4+=ido;
  106354. t6+=t10;
  106355. }
  106356. t5+=t7;
  106357. }
  106358. if (ido == 1)goto L116;
  106359. if(nbd<l1)goto L112;
  106360. t1=0;
  106361. t2=ipp2*t0;
  106362. t7=0;
  106363. for(j=1;j<ipph;j++){
  106364. t1+=t0;
  106365. t2-=t0;
  106366. t3=t1;
  106367. t4=t2;
  106368. t7+=(ido<<1);
  106369. t8=t7;
  106370. for(k=0;k<l1;k++){
  106371. t5=t3;
  106372. t6=t4;
  106373. t9=t8;
  106374. t11=t8;
  106375. for(i=2;i<ido;i+=2){
  106376. t5+=2;
  106377. t6+=2;
  106378. t9+=2;
  106379. t11-=2;
  106380. ch[t5-1]=cc[t9-1]+cc[t11-1];
  106381. ch[t6-1]=cc[t9-1]-cc[t11-1];
  106382. ch[t5]=cc[t9]-cc[t11];
  106383. ch[t6]=cc[t9]+cc[t11];
  106384. }
  106385. t3+=ido;
  106386. t4+=ido;
  106387. t8+=t10;
  106388. }
  106389. }
  106390. goto L116;
  106391. L112:
  106392. t1=0;
  106393. t2=ipp2*t0;
  106394. t7=0;
  106395. for(j=1;j<ipph;j++){
  106396. t1+=t0;
  106397. t2-=t0;
  106398. t3=t1;
  106399. t4=t2;
  106400. t7+=(ido<<1);
  106401. t8=t7;
  106402. t9=t7;
  106403. for(i=2;i<ido;i+=2){
  106404. t3+=2;
  106405. t4+=2;
  106406. t8+=2;
  106407. t9-=2;
  106408. t5=t3;
  106409. t6=t4;
  106410. t11=t8;
  106411. t12=t9;
  106412. for(k=0;k<l1;k++){
  106413. ch[t5-1]=cc[t11-1]+cc[t12-1];
  106414. ch[t6-1]=cc[t11-1]-cc[t12-1];
  106415. ch[t5]=cc[t11]-cc[t12];
  106416. ch[t6]=cc[t11]+cc[t12];
  106417. t5+=ido;
  106418. t6+=ido;
  106419. t11+=t10;
  106420. t12+=t10;
  106421. }
  106422. }
  106423. }
  106424. L116:
  106425. ar1=1.f;
  106426. ai1=0.f;
  106427. t1=0;
  106428. t9=(t2=ipp2*idl1);
  106429. t3=(ip-1)*idl1;
  106430. for(l=1;l<ipph;l++){
  106431. t1+=idl1;
  106432. t2-=idl1;
  106433. ar1h=dcp*ar1-dsp*ai1;
  106434. ai1=dcp*ai1+dsp*ar1;
  106435. ar1=ar1h;
  106436. t4=t1;
  106437. t5=t2;
  106438. t6=0;
  106439. t7=idl1;
  106440. t8=t3;
  106441. for(ik=0;ik<idl1;ik++){
  106442. c2[t4++]=ch2[t6++]+ar1*ch2[t7++];
  106443. c2[t5++]=ai1*ch2[t8++];
  106444. }
  106445. dc2=ar1;
  106446. ds2=ai1;
  106447. ar2=ar1;
  106448. ai2=ai1;
  106449. t6=idl1;
  106450. t7=t9-idl1;
  106451. for(j=2;j<ipph;j++){
  106452. t6+=idl1;
  106453. t7-=idl1;
  106454. ar2h=dc2*ar2-ds2*ai2;
  106455. ai2=dc2*ai2+ds2*ar2;
  106456. ar2=ar2h;
  106457. t4=t1;
  106458. t5=t2;
  106459. t11=t6;
  106460. t12=t7;
  106461. for(ik=0;ik<idl1;ik++){
  106462. c2[t4++]+=ar2*ch2[t11++];
  106463. c2[t5++]+=ai2*ch2[t12++];
  106464. }
  106465. }
  106466. }
  106467. t1=0;
  106468. for(j=1;j<ipph;j++){
  106469. t1+=idl1;
  106470. t2=t1;
  106471. for(ik=0;ik<idl1;ik++)ch2[ik]+=ch2[t2++];
  106472. }
  106473. t1=0;
  106474. t2=ipp2*t0;
  106475. for(j=1;j<ipph;j++){
  106476. t1+=t0;
  106477. t2-=t0;
  106478. t3=t1;
  106479. t4=t2;
  106480. for(k=0;k<l1;k++){
  106481. ch[t3]=c1[t3]-c1[t4];
  106482. ch[t4]=c1[t3]+c1[t4];
  106483. t3+=ido;
  106484. t4+=ido;
  106485. }
  106486. }
  106487. if(ido==1)goto L132;
  106488. if(nbd<l1)goto L128;
  106489. t1=0;
  106490. t2=ipp2*t0;
  106491. for(j=1;j<ipph;j++){
  106492. t1+=t0;
  106493. t2-=t0;
  106494. t3=t1;
  106495. t4=t2;
  106496. for(k=0;k<l1;k++){
  106497. t5=t3;
  106498. t6=t4;
  106499. for(i=2;i<ido;i+=2){
  106500. t5+=2;
  106501. t6+=2;
  106502. ch[t5-1]=c1[t5-1]-c1[t6];
  106503. ch[t6-1]=c1[t5-1]+c1[t6];
  106504. ch[t5]=c1[t5]+c1[t6-1];
  106505. ch[t6]=c1[t5]-c1[t6-1];
  106506. }
  106507. t3+=ido;
  106508. t4+=ido;
  106509. }
  106510. }
  106511. goto L132;
  106512. L128:
  106513. t1=0;
  106514. t2=ipp2*t0;
  106515. for(j=1;j<ipph;j++){
  106516. t1+=t0;
  106517. t2-=t0;
  106518. t3=t1;
  106519. t4=t2;
  106520. for(i=2;i<ido;i+=2){
  106521. t3+=2;
  106522. t4+=2;
  106523. t5=t3;
  106524. t6=t4;
  106525. for(k=0;k<l1;k++){
  106526. ch[t5-1]=c1[t5-1]-c1[t6];
  106527. ch[t6-1]=c1[t5-1]+c1[t6];
  106528. ch[t5]=c1[t5]+c1[t6-1];
  106529. ch[t6]=c1[t5]-c1[t6-1];
  106530. t5+=ido;
  106531. t6+=ido;
  106532. }
  106533. }
  106534. }
  106535. L132:
  106536. if(ido==1)return;
  106537. for(ik=0;ik<idl1;ik++)c2[ik]=ch2[ik];
  106538. t1=0;
  106539. for(j=1;j<ip;j++){
  106540. t2=(t1+=t0);
  106541. for(k=0;k<l1;k++){
  106542. c1[t2]=ch[t2];
  106543. t2+=ido;
  106544. }
  106545. }
  106546. if(nbd>l1)goto L139;
  106547. is= -ido-1;
  106548. t1=0;
  106549. for(j=1;j<ip;j++){
  106550. is+=ido;
  106551. t1+=t0;
  106552. idij=is;
  106553. t2=t1;
  106554. for(i=2;i<ido;i+=2){
  106555. t2+=2;
  106556. idij+=2;
  106557. t3=t2;
  106558. for(k=0;k<l1;k++){
  106559. c1[t3-1]=wa[idij-1]*ch[t3-1]-wa[idij]*ch[t3];
  106560. c1[t3]=wa[idij-1]*ch[t3]+wa[idij]*ch[t3-1];
  106561. t3+=ido;
  106562. }
  106563. }
  106564. }
  106565. return;
  106566. L139:
  106567. is= -ido-1;
  106568. t1=0;
  106569. for(j=1;j<ip;j++){
  106570. is+=ido;
  106571. t1+=t0;
  106572. t2=t1;
  106573. for(k=0;k<l1;k++){
  106574. idij=is;
  106575. t3=t2;
  106576. for(i=2;i<ido;i+=2){
  106577. idij+=2;
  106578. t3+=2;
  106579. c1[t3-1]=wa[idij-1]*ch[t3-1]-wa[idij]*ch[t3];
  106580. c1[t3]=wa[idij-1]*ch[t3]+wa[idij]*ch[t3-1];
  106581. }
  106582. t2+=ido;
  106583. }
  106584. }
  106585. }
  106586. static void drftb1(int n, float *c, float *ch, float *wa, int *ifac){
  106587. int i,k1,l1,l2;
  106588. int na;
  106589. int nf,ip,iw,ix2,ix3,ido,idl1;
  106590. nf=ifac[1];
  106591. na=0;
  106592. l1=1;
  106593. iw=1;
  106594. for(k1=0;k1<nf;k1++){
  106595. ip=ifac[k1 + 2];
  106596. l2=ip*l1;
  106597. ido=n/l2;
  106598. idl1=ido*l1;
  106599. if(ip!=4)goto L103;
  106600. ix2=iw+ido;
  106601. ix3=ix2+ido;
  106602. if(na!=0)
  106603. dradb4(ido,l1,ch,c,wa+iw-1,wa+ix2-1,wa+ix3-1);
  106604. else
  106605. dradb4(ido,l1,c,ch,wa+iw-1,wa+ix2-1,wa+ix3-1);
  106606. na=1-na;
  106607. goto L115;
  106608. L103:
  106609. if(ip!=2)goto L106;
  106610. if(na!=0)
  106611. dradb2(ido,l1,ch,c,wa+iw-1);
  106612. else
  106613. dradb2(ido,l1,c,ch,wa+iw-1);
  106614. na=1-na;
  106615. goto L115;
  106616. L106:
  106617. if(ip!=3)goto L109;
  106618. ix2=iw+ido;
  106619. if(na!=0)
  106620. dradb3(ido,l1,ch,c,wa+iw-1,wa+ix2-1);
  106621. else
  106622. dradb3(ido,l1,c,ch,wa+iw-1,wa+ix2-1);
  106623. na=1-na;
  106624. goto L115;
  106625. L109:
  106626. if(na!=0)
  106627. dradbg(ido,ip,l1,idl1,ch,ch,ch,c,c,wa+iw-1);
  106628. else
  106629. dradbg(ido,ip,l1,idl1,c,c,c,ch,ch,wa+iw-1);
  106630. if(ido==1)na=1-na;
  106631. L115:
  106632. l1=l2;
  106633. iw+=(ip-1)*ido;
  106634. }
  106635. if(na==0)return;
  106636. for(i=0;i<n;i++)c[i]=ch[i];
  106637. }
  106638. void drft_forward(drft_lookup *l,float *data){
  106639. if(l->n==1)return;
  106640. drftf1(l->n,data,l->trigcache,l->trigcache+l->n,l->splitcache);
  106641. }
  106642. void drft_backward(drft_lookup *l,float *data){
  106643. if (l->n==1)return;
  106644. drftb1(l->n,data,l->trigcache,l->trigcache+l->n,l->splitcache);
  106645. }
  106646. void drft_init(drft_lookup *l,int n){
  106647. l->n=n;
  106648. l->trigcache=(float*)_ogg_calloc(3*n,sizeof(*l->trigcache));
  106649. l->splitcache=(int*)_ogg_calloc(32,sizeof(*l->splitcache));
  106650. fdrffti(n, l->trigcache, l->splitcache);
  106651. }
  106652. void drft_clear(drft_lookup *l){
  106653. if(l){
  106654. if(l->trigcache)_ogg_free(l->trigcache);
  106655. if(l->splitcache)_ogg_free(l->splitcache);
  106656. memset(l,0,sizeof(*l));
  106657. }
  106658. }
  106659. #endif
  106660. /*** End of inlined file: smallft.c ***/
  106661. /*** Start of inlined file: synthesis.c ***/
  106662. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  106663. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  106664. // tasks..
  106665. #if JUCE_MSVC
  106666. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  106667. #endif
  106668. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  106669. #if JUCE_USE_OGGVORBIS
  106670. #include <stdio.h>
  106671. int vorbis_synthesis(vorbis_block *vb,ogg_packet *op){
  106672. vorbis_dsp_state *vd=vb->vd;
  106673. private_state *b=(private_state*)vd->backend_state;
  106674. vorbis_info *vi=vd->vi;
  106675. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  106676. oggpack_buffer *opb=&vb->opb;
  106677. int type,mode,i;
  106678. _vorbis_block_ripcord(vb);
  106679. oggpack_readinit(opb,op->packet,op->bytes);
  106680. if(oggpack_read(opb,1)!=0){
  106681. return(OV_ENOTAUDIO);
  106682. }
  106683. mode=oggpack_read(opb,b->modebits);
  106684. if(mode==-1)return(OV_EBADPACKET);
  106685. vb->mode=mode;
  106686. vb->W=ci->mode_param[mode]->blockflag;
  106687. if(vb->W){
  106688. vb->lW=oggpack_read(opb,1);
  106689. vb->nW=oggpack_read(opb,1);
  106690. if(vb->nW==-1) return(OV_EBADPACKET);
  106691. }else{
  106692. vb->lW=0;
  106693. vb->nW=0;
  106694. }
  106695. vb->granulepos=op->granulepos;
  106696. vb->sequence=op->packetno;
  106697. vb->eofflag=op->e_o_s;
  106698. vb->pcmend=ci->blocksizes[vb->W];
  106699. vb->pcm=(float**)_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels);
  106700. for(i=0;i<vi->channels;i++)
  106701. vb->pcm[i]=(float*)_vorbis_block_alloc(vb,vb->pcmend*sizeof(*vb->pcm[i]));
  106702. type=ci->map_type[ci->mode_param[mode]->mapping];
  106703. return(_mapping_P[type]->inverse(vb,ci->map_param[ci->mode_param[mode]->
  106704. mapping]));
  106705. }
  106706. int vorbis_synthesis_trackonly(vorbis_block *vb,ogg_packet *op){
  106707. vorbis_dsp_state *vd=vb->vd;
  106708. private_state *b=(private_state*)vd->backend_state;
  106709. vorbis_info *vi=vd->vi;
  106710. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106711. oggpack_buffer *opb=&vb->opb;
  106712. int mode;
  106713. _vorbis_block_ripcord(vb);
  106714. oggpack_readinit(opb,op->packet,op->bytes);
  106715. if(oggpack_read(opb,1)!=0){
  106716. return(OV_ENOTAUDIO);
  106717. }
  106718. mode=oggpack_read(opb,b->modebits);
  106719. if(mode==-1)return(OV_EBADPACKET);
  106720. vb->mode=mode;
  106721. vb->W=ci->mode_param[mode]->blockflag;
  106722. if(vb->W){
  106723. vb->lW=oggpack_read(opb,1);
  106724. vb->nW=oggpack_read(opb,1);
  106725. if(vb->nW==-1) return(OV_EBADPACKET);
  106726. }else{
  106727. vb->lW=0;
  106728. vb->nW=0;
  106729. }
  106730. vb->granulepos=op->granulepos;
  106731. vb->sequence=op->packetno;
  106732. vb->eofflag=op->e_o_s;
  106733. vb->pcmend=0;
  106734. vb->pcm=NULL;
  106735. return(0);
  106736. }
  106737. long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op){
  106738. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106739. oggpack_buffer opb;
  106740. int mode;
  106741. oggpack_readinit(&opb,op->packet,op->bytes);
  106742. if(oggpack_read(&opb,1)!=0){
  106743. return(OV_ENOTAUDIO);
  106744. }
  106745. {
  106746. int modebits=0;
  106747. int v=ci->modes;
  106748. while(v>1){
  106749. modebits++;
  106750. v>>=1;
  106751. }
  106752. mode=oggpack_read(&opb,modebits);
  106753. }
  106754. if(mode==-1)return(OV_EBADPACKET);
  106755. return(ci->blocksizes[ci->mode_param[mode]->blockflag]);
  106756. }
  106757. int vorbis_synthesis_halfrate(vorbis_info *vi,int flag){
  106758. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106759. if(ci->blocksizes[0]<=64 && flag)return -1;
  106760. ci->halfrate_flag=(flag?1:0);
  106761. return 0;
  106762. }
  106763. int vorbis_synthesis_halfrate_p(vorbis_info *vi){
  106764. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106765. return ci->halfrate_flag;
  106766. }
  106767. #endif
  106768. /*** End of inlined file: synthesis.c ***/
  106769. /*** Start of inlined file: vorbisenc.c ***/
  106770. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  106771. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  106772. // tasks..
  106773. #if JUCE_MSVC
  106774. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  106775. #endif
  106776. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  106777. #if JUCE_USE_OGGVORBIS
  106778. #include <stdlib.h>
  106779. #include <string.h>
  106780. #include <math.h>
  106781. typedef struct {
  106782. static_codebook *books[12][3];
  106783. } static_bookblock;
  106784. typedef struct {
  106785. int res_type;
  106786. int limit_type; /* 0 lowpass limited, 1 point stereo limited */
  106787. vorbis_info_residue0 *res;
  106788. static_codebook *book_aux;
  106789. static_codebook *book_aux_managed;
  106790. static_bookblock *books_base;
  106791. static_bookblock *books_base_managed;
  106792. } vorbis_residue_template;
  106793. typedef struct {
  106794. vorbis_info_mapping0 *map;
  106795. vorbis_residue_template *res;
  106796. } vorbis_mapping_template;
  106797. typedef struct vp_adjblock{
  106798. int block[P_BANDS];
  106799. } vp_adjblock;
  106800. typedef struct {
  106801. int data[NOISE_COMPAND_LEVELS];
  106802. } compandblock;
  106803. typedef struct {
  106804. int att[P_NOISECURVES];
  106805. float boost;
  106806. float decay;
  106807. } att3;
  106808. typedef struct { int data[P_NOISECURVES]; } adj3;
  106809. typedef struct {
  106810. int pre[PACKETBLOBS];
  106811. int post[PACKETBLOBS];
  106812. float kHz[PACKETBLOBS];
  106813. float lowpasskHz[PACKETBLOBS];
  106814. } adj_stereo;
  106815. typedef struct {
  106816. int lo;
  106817. int hi;
  106818. int fixed;
  106819. } noiseguard;
  106820. typedef struct {
  106821. int data[P_NOISECURVES][17];
  106822. } noise3;
  106823. typedef struct {
  106824. int mappings;
  106825. double *rate_mapping;
  106826. double *quality_mapping;
  106827. int coupling_restriction;
  106828. long samplerate_min_restriction;
  106829. long samplerate_max_restriction;
  106830. int *blocksize_short;
  106831. int *blocksize_long;
  106832. att3 *psy_tone_masteratt;
  106833. int *psy_tone_0dB;
  106834. int *psy_tone_dBsuppress;
  106835. vp_adjblock *psy_tone_adj_impulse;
  106836. vp_adjblock *psy_tone_adj_long;
  106837. vp_adjblock *psy_tone_adj_other;
  106838. noiseguard *psy_noiseguards;
  106839. noise3 *psy_noise_bias_impulse;
  106840. noise3 *psy_noise_bias_padding;
  106841. noise3 *psy_noise_bias_trans;
  106842. noise3 *psy_noise_bias_long;
  106843. int *psy_noise_dBsuppress;
  106844. compandblock *psy_noise_compand;
  106845. double *psy_noise_compand_short_mapping;
  106846. double *psy_noise_compand_long_mapping;
  106847. int *psy_noise_normal_start[2];
  106848. int *psy_noise_normal_partition[2];
  106849. double *psy_noise_normal_thresh;
  106850. int *psy_ath_float;
  106851. int *psy_ath_abs;
  106852. double *psy_lowpass;
  106853. vorbis_info_psy_global *global_params;
  106854. double *global_mapping;
  106855. adj_stereo *stereo_modes;
  106856. static_codebook ***floor_books;
  106857. vorbis_info_floor1 *floor_params;
  106858. int *floor_short_mapping;
  106859. int *floor_long_mapping;
  106860. vorbis_mapping_template *maps;
  106861. } ve_setup_data_template;
  106862. static vorbis_info_mode _mode_template[2]={
  106863. {0,0,0,0},
  106864. {1,0,0,1}
  106865. };
  106866. static vorbis_info_mapping0 _map_nominal[2]={
  106867. {1, {0,0}, {0}, {0}, 1,{0},{1}},
  106868. {1, {0,0}, {1}, {1}, 1,{0},{1}}
  106869. };
  106870. /*** Start of inlined file: setup_44.h ***/
  106871. /*** Start of inlined file: floor_all.h ***/
  106872. /*** Start of inlined file: floor_books.h ***/
  106873. static long _huff_lengthlist_line_256x7_0sub1[] = {
  106874. 0, 2, 3, 3, 3, 3, 4, 3, 4,
  106875. };
  106876. static static_codebook _huff_book_line_256x7_0sub1 = {
  106877. 1, 9,
  106878. _huff_lengthlist_line_256x7_0sub1,
  106879. 0, 0, 0, 0, 0,
  106880. NULL,
  106881. NULL,
  106882. NULL,
  106883. NULL,
  106884. 0
  106885. };
  106886. static long _huff_lengthlist_line_256x7_0sub2[] = {
  106887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 3, 4, 3, 5, 3,
  106888. 6, 3, 6, 4, 6, 4, 7, 5, 7,
  106889. };
  106890. static static_codebook _huff_book_line_256x7_0sub2 = {
  106891. 1, 25,
  106892. _huff_lengthlist_line_256x7_0sub2,
  106893. 0, 0, 0, 0, 0,
  106894. NULL,
  106895. NULL,
  106896. NULL,
  106897. NULL,
  106898. 0
  106899. };
  106900. static long _huff_lengthlist_line_256x7_0sub3[] = {
  106901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 2, 5, 3, 5, 3,
  106903. 6, 3, 6, 4, 7, 6, 7, 8, 7, 9, 8, 9, 9, 9,10, 9,
  106904. 11,13,11,13,10,10,13,13,13,13,13,13,12,12,12,12,
  106905. };
  106906. static static_codebook _huff_book_line_256x7_0sub3 = {
  106907. 1, 64,
  106908. _huff_lengthlist_line_256x7_0sub3,
  106909. 0, 0, 0, 0, 0,
  106910. NULL,
  106911. NULL,
  106912. NULL,
  106913. NULL,
  106914. 0
  106915. };
  106916. static long _huff_lengthlist_line_256x7_1sub1[] = {
  106917. 0, 3, 3, 3, 3, 2, 4, 3, 4,
  106918. };
  106919. static static_codebook _huff_book_line_256x7_1sub1 = {
  106920. 1, 9,
  106921. _huff_lengthlist_line_256x7_1sub1,
  106922. 0, 0, 0, 0, 0,
  106923. NULL,
  106924. NULL,
  106925. NULL,
  106926. NULL,
  106927. 0
  106928. };
  106929. static long _huff_lengthlist_line_256x7_1sub2[] = {
  106930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 3, 4, 3, 4, 4,
  106931. 5, 4, 6, 5, 6, 7, 6, 8, 8,
  106932. };
  106933. static static_codebook _huff_book_line_256x7_1sub2 = {
  106934. 1, 25,
  106935. _huff_lengthlist_line_256x7_1sub2,
  106936. 0, 0, 0, 0, 0,
  106937. NULL,
  106938. NULL,
  106939. NULL,
  106940. NULL,
  106941. 0
  106942. };
  106943. static long _huff_lengthlist_line_256x7_1sub3[] = {
  106944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 2, 4, 3, 6, 3, 7,
  106946. 3, 8, 5, 8, 6, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  106947. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7,
  106948. };
  106949. static static_codebook _huff_book_line_256x7_1sub3 = {
  106950. 1, 64,
  106951. _huff_lengthlist_line_256x7_1sub3,
  106952. 0, 0, 0, 0, 0,
  106953. NULL,
  106954. NULL,
  106955. NULL,
  106956. NULL,
  106957. 0
  106958. };
  106959. static long _huff_lengthlist_line_256x7_class0[] = {
  106960. 7, 5, 5, 9, 9, 6, 6, 9,12, 8, 7, 8,11, 8, 9,15,
  106961. 6, 3, 3, 7, 7, 4, 3, 6, 9, 6, 5, 6, 8, 6, 8,15,
  106962. 8, 5, 5, 9, 8, 5, 4, 6,10, 7, 5, 5,11, 8, 7,15,
  106963. 14,15,13,13,13,13, 8,11,15,10, 7, 6,11, 9,10,15,
  106964. };
  106965. static static_codebook _huff_book_line_256x7_class0 = {
  106966. 1, 64,
  106967. _huff_lengthlist_line_256x7_class0,
  106968. 0, 0, 0, 0, 0,
  106969. NULL,
  106970. NULL,
  106971. NULL,
  106972. NULL,
  106973. 0
  106974. };
  106975. static long _huff_lengthlist_line_256x7_class1[] = {
  106976. 5, 6, 8,15, 6, 9,10,15,10,11,12,15,15,15,15,15,
  106977. 4, 6, 7,15, 6, 7, 8,15, 9, 8, 9,15,15,15,15,15,
  106978. 6, 8, 9,15, 7, 7, 8,15,10, 9,10,15,15,15,15,15,
  106979. 15,13,15,15,15,10,11,15,15,13,13,15,15,15,15,15,
  106980. 4, 6, 7,15, 6, 8, 9,15,10,10,12,15,15,15,15,15,
  106981. 2, 5, 6,15, 5, 6, 7,15, 8, 6, 7,15,15,15,15,15,
  106982. 5, 6, 8,15, 5, 6, 7,15, 9, 6, 7,15,15,15,15,15,
  106983. 14,12,13,15,12,10,11,15,15,15,15,15,15,15,15,15,
  106984. 7, 8, 9,15, 9,10,10,15,15,14,14,15,15,15,15,15,
  106985. 5, 6, 7,15, 7, 8, 9,15,12, 9,10,15,15,15,15,15,
  106986. 7, 7, 9,15, 7, 7, 8,15,12, 8, 9,15,15,15,15,15,
  106987. 13,13,14,15,12,11,12,15,15,15,15,15,15,15,15,15,
  106988. 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
  106989. 13,13,13,15,15,15,15,15,15,15,15,15,15,15,15,15,
  106990. 15,12,13,15,15,12,13,15,15,14,15,15,15,15,15,15,
  106991. 15,15,15,15,15,15,13,15,15,15,15,15,15,15,15,15,
  106992. };
  106993. static static_codebook _huff_book_line_256x7_class1 = {
  106994. 1, 256,
  106995. _huff_lengthlist_line_256x7_class1,
  106996. 0, 0, 0, 0, 0,
  106997. NULL,
  106998. NULL,
  106999. NULL,
  107000. NULL,
  107001. 0
  107002. };
  107003. static long _huff_lengthlist_line_512x17_0sub0[] = {
  107004. 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  107005. 5, 6, 5, 6, 6, 6, 6, 5, 6, 6, 7, 6, 7, 6, 7, 6,
  107006. 7, 6, 8, 7, 8, 7, 8, 7, 8, 7, 8, 7, 9, 7, 9, 7,
  107007. 9, 7, 9, 8, 9, 8,10, 8,10, 8,10, 7,10, 6,10, 8,
  107008. 10, 8,11, 7,10, 7,11, 8,11,11,12,12,11,11,12,11,
  107009. 13,11,13,11,13,12,15,12,13,13,14,14,14,14,14,15,
  107010. 15,15,16,14,17,19,19,18,18,18,18,18,18,18,18,18,
  107011. 18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,
  107012. };
  107013. static static_codebook _huff_book_line_512x17_0sub0 = {
  107014. 1, 128,
  107015. _huff_lengthlist_line_512x17_0sub0,
  107016. 0, 0, 0, 0, 0,
  107017. NULL,
  107018. NULL,
  107019. NULL,
  107020. NULL,
  107021. 0
  107022. };
  107023. static long _huff_lengthlist_line_512x17_1sub0[] = {
  107024. 2, 4, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 6, 5,
  107025. 6, 5, 6, 6, 7, 6, 7, 6, 8, 7, 8, 7, 8, 7, 8, 7,
  107026. };
  107027. static static_codebook _huff_book_line_512x17_1sub0 = {
  107028. 1, 32,
  107029. _huff_lengthlist_line_512x17_1sub0,
  107030. 0, 0, 0, 0, 0,
  107031. NULL,
  107032. NULL,
  107033. NULL,
  107034. NULL,
  107035. 0
  107036. };
  107037. static long _huff_lengthlist_line_512x17_1sub1[] = {
  107038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107040. 4, 3, 5, 3, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 6, 5,
  107041. 6, 5, 7, 5, 8, 6, 8, 6, 8, 6, 8, 6, 8, 7, 9, 7,
  107042. 9, 7,11, 9,11,11,12,11,14,12,14,16,14,16,13,16,
  107043. 14,16,12,15,13,16,14,16,13,14,12,15,13,15,13,13,
  107044. 13,15,12,14,14,15,13,15,12,15,15,15,15,15,15,15,
  107045. 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
  107046. };
  107047. static static_codebook _huff_book_line_512x17_1sub1 = {
  107048. 1, 128,
  107049. _huff_lengthlist_line_512x17_1sub1,
  107050. 0, 0, 0, 0, 0,
  107051. NULL,
  107052. NULL,
  107053. NULL,
  107054. NULL,
  107055. 0
  107056. };
  107057. static long _huff_lengthlist_line_512x17_2sub1[] = {
  107058. 0, 4, 5, 4, 4, 4, 5, 4, 4, 4, 5, 4, 5, 4, 5, 3,
  107059. 5, 3,
  107060. };
  107061. static static_codebook _huff_book_line_512x17_2sub1 = {
  107062. 1, 18,
  107063. _huff_lengthlist_line_512x17_2sub1,
  107064. 0, 0, 0, 0, 0,
  107065. NULL,
  107066. NULL,
  107067. NULL,
  107068. NULL,
  107069. 0
  107070. };
  107071. static long _huff_lengthlist_line_512x17_2sub2[] = {
  107072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107073. 0, 0, 4, 3, 4, 3, 4, 4, 5, 4, 5, 4, 6, 4, 6, 5,
  107074. 6, 5, 7, 5, 7, 6, 8, 6, 8, 6, 8, 7, 8, 7, 9, 7,
  107075. 9, 8,
  107076. };
  107077. static static_codebook _huff_book_line_512x17_2sub2 = {
  107078. 1, 50,
  107079. _huff_lengthlist_line_512x17_2sub2,
  107080. 0, 0, 0, 0, 0,
  107081. NULL,
  107082. NULL,
  107083. NULL,
  107084. NULL,
  107085. 0
  107086. };
  107087. static long _huff_lengthlist_line_512x17_2sub3[] = {
  107088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107091. 0, 0, 3, 3, 3, 3, 4, 3, 4, 4, 5, 5, 6, 6, 7, 7,
  107092. 7, 8, 8,11, 8, 9, 9, 9,10,11,11,11, 9,10,10,11,
  107093. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,
  107094. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  107095. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  107096. };
  107097. static static_codebook _huff_book_line_512x17_2sub3 = {
  107098. 1, 128,
  107099. _huff_lengthlist_line_512x17_2sub3,
  107100. 0, 0, 0, 0, 0,
  107101. NULL,
  107102. NULL,
  107103. NULL,
  107104. NULL,
  107105. 0
  107106. };
  107107. static long _huff_lengthlist_line_512x17_3sub1[] = {
  107108. 0, 4, 4, 4, 4, 4, 4, 3, 4, 4, 4, 4, 4, 5, 4, 5,
  107109. 5, 5,
  107110. };
  107111. static static_codebook _huff_book_line_512x17_3sub1 = {
  107112. 1, 18,
  107113. _huff_lengthlist_line_512x17_3sub1,
  107114. 0, 0, 0, 0, 0,
  107115. NULL,
  107116. NULL,
  107117. NULL,
  107118. NULL,
  107119. 0
  107120. };
  107121. static long _huff_lengthlist_line_512x17_3sub2[] = {
  107122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107123. 0, 0, 2, 3, 3, 4, 3, 5, 4, 6, 4, 6, 5, 7, 6, 7,
  107124. 6, 8, 6, 8, 7, 9, 8,10, 8,12, 9,13,10,15,10,15,
  107125. 11,14,
  107126. };
  107127. static static_codebook _huff_book_line_512x17_3sub2 = {
  107128. 1, 50,
  107129. _huff_lengthlist_line_512x17_3sub2,
  107130. 0, 0, 0, 0, 0,
  107131. NULL,
  107132. NULL,
  107133. NULL,
  107134. NULL,
  107135. 0
  107136. };
  107137. static long _huff_lengthlist_line_512x17_3sub3[] = {
  107138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107141. 0, 0, 4, 8, 4, 8, 4, 8, 4, 8, 5, 8, 5, 8, 6, 8,
  107142. 4, 8, 4, 8, 5, 8, 5, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107143. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107144. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107145. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107146. };
  107147. static static_codebook _huff_book_line_512x17_3sub3 = {
  107148. 1, 128,
  107149. _huff_lengthlist_line_512x17_3sub3,
  107150. 0, 0, 0, 0, 0,
  107151. NULL,
  107152. NULL,
  107153. NULL,
  107154. NULL,
  107155. 0
  107156. };
  107157. static long _huff_lengthlist_line_512x17_class1[] = {
  107158. 1, 2, 3, 6, 5, 4, 7, 7,
  107159. };
  107160. static static_codebook _huff_book_line_512x17_class1 = {
  107161. 1, 8,
  107162. _huff_lengthlist_line_512x17_class1,
  107163. 0, 0, 0, 0, 0,
  107164. NULL,
  107165. NULL,
  107166. NULL,
  107167. NULL,
  107168. 0
  107169. };
  107170. static long _huff_lengthlist_line_512x17_class2[] = {
  107171. 3, 3, 3,14, 5, 4, 4,11, 8, 6, 6,10,17,12,11,17,
  107172. 6, 5, 5,15, 5, 3, 4,11, 8, 5, 5, 8,16, 9,10,14,
  107173. 10, 8, 9,17, 8, 6, 6,13,10, 7, 7,10,16,11,13,14,
  107174. 17,17,17,17,17,16,16,16,16,15,16,16,16,16,16,16,
  107175. };
  107176. static static_codebook _huff_book_line_512x17_class2 = {
  107177. 1, 64,
  107178. _huff_lengthlist_line_512x17_class2,
  107179. 0, 0, 0, 0, 0,
  107180. NULL,
  107181. NULL,
  107182. NULL,
  107183. NULL,
  107184. 0
  107185. };
  107186. static long _huff_lengthlist_line_512x17_class3[] = {
  107187. 2, 4, 6,17, 4, 5, 7,17, 8, 7,10,17,17,17,17,17,
  107188. 3, 4, 6,15, 3, 3, 6,15, 7, 6, 9,17,17,17,17,17,
  107189. 6, 8,10,17, 6, 6, 8,16, 9, 8,10,17,17,15,16,17,
  107190. 17,17,17,17,12,15,15,16,12,15,15,16,16,16,16,16,
  107191. };
  107192. static static_codebook _huff_book_line_512x17_class3 = {
  107193. 1, 64,
  107194. _huff_lengthlist_line_512x17_class3,
  107195. 0, 0, 0, 0, 0,
  107196. NULL,
  107197. NULL,
  107198. NULL,
  107199. NULL,
  107200. 0
  107201. };
  107202. static long _huff_lengthlist_line_128x4_class0[] = {
  107203. 7, 7, 7,11, 6, 6, 7,11, 7, 6, 6,10,12,10,10,13,
  107204. 7, 7, 8,11, 7, 7, 7,11, 7, 6, 7,10,11,10,10,13,
  107205. 10,10, 9,12, 9, 9, 9,11, 8, 8, 8,11,13,11,10,14,
  107206. 15,15,14,15,15,14,13,14,15,12,12,17,17,17,17,17,
  107207. 7, 7, 6, 9, 6, 6, 6, 9, 7, 6, 6, 8,11,11,10,12,
  107208. 7, 7, 7, 9, 7, 6, 6, 9, 7, 6, 6, 9,13,10,10,11,
  107209. 10, 9, 8,10, 9, 8, 8,10, 8, 8, 7, 9,13,12,10,11,
  107210. 17,14,14,13,15,14,12,13,17,13,12,15,17,17,14,17,
  107211. 7, 6, 6, 7, 6, 6, 5, 7, 6, 6, 6, 6,11, 9, 9, 9,
  107212. 7, 7, 6, 7, 7, 6, 6, 7, 6, 6, 6, 6,10, 9, 8, 9,
  107213. 10, 9, 8, 8, 9, 8, 7, 8, 8, 7, 6, 8,11,10, 9,10,
  107214. 17,17,12,15,15,15,12,14,14,14,10,12,15,13,12,13,
  107215. 11,10, 8,10,11,10, 8, 8,10, 9, 7, 7,10, 9, 9,11,
  107216. 11,11, 9,10,11,10, 8, 9,10, 8, 6, 8,10, 9, 9,11,
  107217. 14,13,10,12,12,11,10,10, 8, 7, 8,10,10,11,11,12,
  107218. 17,17,15,17,17,17,17,17,17,13,12,17,17,17,14,17,
  107219. };
  107220. static static_codebook _huff_book_line_128x4_class0 = {
  107221. 1, 256,
  107222. _huff_lengthlist_line_128x4_class0,
  107223. 0, 0, 0, 0, 0,
  107224. NULL,
  107225. NULL,
  107226. NULL,
  107227. NULL,
  107228. 0
  107229. };
  107230. static long _huff_lengthlist_line_128x4_0sub0[] = {
  107231. 2, 2, 2, 2,
  107232. };
  107233. static static_codebook _huff_book_line_128x4_0sub0 = {
  107234. 1, 4,
  107235. _huff_lengthlist_line_128x4_0sub0,
  107236. 0, 0, 0, 0, 0,
  107237. NULL,
  107238. NULL,
  107239. NULL,
  107240. NULL,
  107241. 0
  107242. };
  107243. static long _huff_lengthlist_line_128x4_0sub1[] = {
  107244. 0, 0, 0, 0, 3, 2, 3, 2, 3, 3,
  107245. };
  107246. static static_codebook _huff_book_line_128x4_0sub1 = {
  107247. 1, 10,
  107248. _huff_lengthlist_line_128x4_0sub1,
  107249. 0, 0, 0, 0, 0,
  107250. NULL,
  107251. NULL,
  107252. NULL,
  107253. NULL,
  107254. 0
  107255. };
  107256. static long _huff_lengthlist_line_128x4_0sub2[] = {
  107257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 4, 3, 4, 3,
  107258. 4, 4, 5, 4, 5, 4, 6, 5, 6,
  107259. };
  107260. static static_codebook _huff_book_line_128x4_0sub2 = {
  107261. 1, 25,
  107262. _huff_lengthlist_line_128x4_0sub2,
  107263. 0, 0, 0, 0, 0,
  107264. NULL,
  107265. NULL,
  107266. NULL,
  107267. NULL,
  107268. 0
  107269. };
  107270. static long _huff_lengthlist_line_128x4_0sub3[] = {
  107271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 3, 5, 3, 5, 3,
  107273. 5, 4, 6, 5, 6, 5, 7, 6, 6, 7, 7, 9, 9,11,11,16,
  107274. 11,14,10,11,11,13,16,15,15,15,15,15,15,15,15,15,
  107275. };
  107276. static static_codebook _huff_book_line_128x4_0sub3 = {
  107277. 1, 64,
  107278. _huff_lengthlist_line_128x4_0sub3,
  107279. 0, 0, 0, 0, 0,
  107280. NULL,
  107281. NULL,
  107282. NULL,
  107283. NULL,
  107284. 0
  107285. };
  107286. static long _huff_lengthlist_line_256x4_class0[] = {
  107287. 6, 7, 7,12, 6, 6, 7,12, 7, 6, 6,10,15,12,11,13,
  107288. 7, 7, 8,13, 7, 7, 8,12, 7, 7, 7,11,12,12,11,13,
  107289. 10, 9, 9,11, 9, 9, 9,10,10, 8, 8,12,14,12,12,14,
  107290. 11,11,12,14,11,12,11,15,15,12,13,15,15,15,15,15,
  107291. 6, 6, 7,10, 6, 6, 6,11, 7, 6, 6, 9,14,12,11,13,
  107292. 7, 7, 7,10, 6, 6, 7, 9, 7, 7, 6,10,13,12,10,12,
  107293. 9, 9, 9,11, 9, 9, 8, 9, 9, 8, 8,10,13,12,10,12,
  107294. 12,12,11,13,12,12,11,12,15,13,12,15,15,15,14,14,
  107295. 6, 6, 6, 8, 6, 6, 5, 6, 7, 7, 6, 5,11,10, 9, 8,
  107296. 7, 6, 6, 7, 6, 6, 5, 6, 7, 7, 6, 6,11,10, 9, 8,
  107297. 8, 8, 8, 9, 8, 8, 7, 8, 8, 8, 6, 7,11,10, 9, 9,
  107298. 14,11,10,14,14,11,10,15,13,11, 9,11,15,12,12,11,
  107299. 11, 9, 8, 8,10, 9, 8, 9,11,10, 9, 8,12,11,12,11,
  107300. 13,10, 8, 9,11,10, 8, 9,10, 9, 8, 9,10, 8,12,12,
  107301. 15,11,10,10,13,11,10,10, 8, 8, 7,12,10, 9,11,12,
  107302. 15,12,11,15,13,11,11,15,12,14,11,13,15,15,13,13,
  107303. };
  107304. static static_codebook _huff_book_line_256x4_class0 = {
  107305. 1, 256,
  107306. _huff_lengthlist_line_256x4_class0,
  107307. 0, 0, 0, 0, 0,
  107308. NULL,
  107309. NULL,
  107310. NULL,
  107311. NULL,
  107312. 0
  107313. };
  107314. static long _huff_lengthlist_line_256x4_0sub0[] = {
  107315. 2, 2, 2, 2,
  107316. };
  107317. static static_codebook _huff_book_line_256x4_0sub0 = {
  107318. 1, 4,
  107319. _huff_lengthlist_line_256x4_0sub0,
  107320. 0, 0, 0, 0, 0,
  107321. NULL,
  107322. NULL,
  107323. NULL,
  107324. NULL,
  107325. 0
  107326. };
  107327. static long _huff_lengthlist_line_256x4_0sub1[] = {
  107328. 0, 0, 0, 0, 2, 2, 3, 3, 3, 3,
  107329. };
  107330. static static_codebook _huff_book_line_256x4_0sub1 = {
  107331. 1, 10,
  107332. _huff_lengthlist_line_256x4_0sub1,
  107333. 0, 0, 0, 0, 0,
  107334. NULL,
  107335. NULL,
  107336. NULL,
  107337. NULL,
  107338. 0
  107339. };
  107340. static long _huff_lengthlist_line_256x4_0sub2[] = {
  107341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 3, 4, 3, 4, 3,
  107342. 5, 3, 5, 4, 5, 4, 6, 4, 6,
  107343. };
  107344. static static_codebook _huff_book_line_256x4_0sub2 = {
  107345. 1, 25,
  107346. _huff_lengthlist_line_256x4_0sub2,
  107347. 0, 0, 0, 0, 0,
  107348. NULL,
  107349. NULL,
  107350. NULL,
  107351. NULL,
  107352. 0
  107353. };
  107354. static long _huff_lengthlist_line_256x4_0sub3[] = {
  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, 2, 4, 3, 5, 3, 5, 3,
  107357. 6, 4, 7, 4, 7, 5, 7, 6, 7, 6, 7, 8,10,13,13,13,
  107358. 13,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,
  107359. };
  107360. static static_codebook _huff_book_line_256x4_0sub3 = {
  107361. 1, 64,
  107362. _huff_lengthlist_line_256x4_0sub3,
  107363. 0, 0, 0, 0, 0,
  107364. NULL,
  107365. NULL,
  107366. NULL,
  107367. NULL,
  107368. 0
  107369. };
  107370. static long _huff_lengthlist_line_128x7_class0[] = {
  107371. 10, 7, 8,13, 9, 6, 7,11,10, 8, 8,12,17,17,17,17,
  107372. 7, 5, 5, 9, 6, 4, 4, 8, 8, 5, 5, 8,16,14,13,16,
  107373. 7, 5, 5, 7, 6, 3, 3, 5, 8, 5, 4, 7,14,12,12,15,
  107374. 10, 7, 8, 9, 7, 5, 5, 6, 9, 6, 5, 5,15,12, 9,10,
  107375. };
  107376. static static_codebook _huff_book_line_128x7_class0 = {
  107377. 1, 64,
  107378. _huff_lengthlist_line_128x7_class0,
  107379. 0, 0, 0, 0, 0,
  107380. NULL,
  107381. NULL,
  107382. NULL,
  107383. NULL,
  107384. 0
  107385. };
  107386. static long _huff_lengthlist_line_128x7_class1[] = {
  107387. 8,13,17,17, 8,11,17,17,11,13,17,17,17,17,17,17,
  107388. 6,10,16,17, 6,10,15,17, 8,10,16,17,17,17,17,17,
  107389. 9,13,15,17, 8,11,17,17,10,12,17,17,17,17,17,17,
  107390. 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
  107391. 6,11,15,17, 7,10,15,17, 8,10,17,17,17,15,17,17,
  107392. 4, 8,13,17, 4, 7,13,17, 6, 8,15,17,16,15,17,17,
  107393. 6,11,15,17, 6, 9,13,17, 8,10,17,17,15,17,17,17,
  107394. 16,17,17,17,12,14,15,17,13,14,15,17,17,17,17,17,
  107395. 5,10,14,17, 5, 9,14,17, 7, 9,15,17,15,15,17,17,
  107396. 3, 7,12,17, 3, 6,11,17, 5, 7,13,17,12,12,17,17,
  107397. 5, 9,14,17, 3, 7,11,17, 5, 8,13,17,13,11,16,17,
  107398. 12,17,17,17, 9,14,15,17,10,11,14,17,16,14,17,17,
  107399. 8,12,17,17, 8,12,17,17,10,12,17,17,17,17,17,17,
  107400. 5,10,17,17, 5, 9,15,17, 7, 9,17,17,13,13,17,17,
  107401. 7,11,17,17, 6,10,15,17, 7, 9,15,17,12,11,17,17,
  107402. 12,15,17,17,11,14,17,17,11,10,15,17,17,16,17,17,
  107403. };
  107404. static static_codebook _huff_book_line_128x7_class1 = {
  107405. 1, 256,
  107406. _huff_lengthlist_line_128x7_class1,
  107407. 0, 0, 0, 0, 0,
  107408. NULL,
  107409. NULL,
  107410. NULL,
  107411. NULL,
  107412. 0
  107413. };
  107414. static long _huff_lengthlist_line_128x7_0sub1[] = {
  107415. 0, 3, 3, 3, 3, 3, 3, 3, 3,
  107416. };
  107417. static static_codebook _huff_book_line_128x7_0sub1 = {
  107418. 1, 9,
  107419. _huff_lengthlist_line_128x7_0sub1,
  107420. 0, 0, 0, 0, 0,
  107421. NULL,
  107422. NULL,
  107423. NULL,
  107424. NULL,
  107425. 0
  107426. };
  107427. static long _huff_lengthlist_line_128x7_0sub2[] = {
  107428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 4, 4, 4, 4,
  107429. 5, 4, 5, 4, 5, 4, 6, 4, 6,
  107430. };
  107431. static static_codebook _huff_book_line_128x7_0sub2 = {
  107432. 1, 25,
  107433. _huff_lengthlist_line_128x7_0sub2,
  107434. 0, 0, 0, 0, 0,
  107435. NULL,
  107436. NULL,
  107437. NULL,
  107438. NULL,
  107439. 0
  107440. };
  107441. static long _huff_lengthlist_line_128x7_0sub3[] = {
  107442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 3, 5, 3, 5, 4,
  107444. 5, 4, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107445. 7, 8, 9,11,13,13,13,13,13,13,13,13,13,13,13,13,
  107446. };
  107447. static static_codebook _huff_book_line_128x7_0sub3 = {
  107448. 1, 64,
  107449. _huff_lengthlist_line_128x7_0sub3,
  107450. 0, 0, 0, 0, 0,
  107451. NULL,
  107452. NULL,
  107453. NULL,
  107454. NULL,
  107455. 0
  107456. };
  107457. static long _huff_lengthlist_line_128x7_1sub1[] = {
  107458. 0, 3, 3, 2, 3, 3, 4, 3, 4,
  107459. };
  107460. static static_codebook _huff_book_line_128x7_1sub1 = {
  107461. 1, 9,
  107462. _huff_lengthlist_line_128x7_1sub1,
  107463. 0, 0, 0, 0, 0,
  107464. NULL,
  107465. NULL,
  107466. NULL,
  107467. NULL,
  107468. 0
  107469. };
  107470. static long _huff_lengthlist_line_128x7_1sub2[] = {
  107471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 3, 6, 3, 6, 3,
  107472. 6, 3, 7, 3, 8, 4, 9, 4, 9,
  107473. };
  107474. static static_codebook _huff_book_line_128x7_1sub2 = {
  107475. 1, 25,
  107476. _huff_lengthlist_line_128x7_1sub2,
  107477. 0, 0, 0, 0, 0,
  107478. NULL,
  107479. NULL,
  107480. NULL,
  107481. NULL,
  107482. 0
  107483. };
  107484. static long _huff_lengthlist_line_128x7_1sub3[] = {
  107485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 7, 2, 7, 3, 8, 4,
  107487. 9, 5, 9, 8,10,11,11,12,14,14,14,14,14,14,14,14,
  107488. 14,14,14,14,14,14,14,14,14,14,14,14,13,13,13,13,
  107489. };
  107490. static static_codebook _huff_book_line_128x7_1sub3 = {
  107491. 1, 64,
  107492. _huff_lengthlist_line_128x7_1sub3,
  107493. 0, 0, 0, 0, 0,
  107494. NULL,
  107495. NULL,
  107496. NULL,
  107497. NULL,
  107498. 0
  107499. };
  107500. static long _huff_lengthlist_line_128x11_class1[] = {
  107501. 1, 6, 3, 7, 2, 4, 5, 7,
  107502. };
  107503. static static_codebook _huff_book_line_128x11_class1 = {
  107504. 1, 8,
  107505. _huff_lengthlist_line_128x11_class1,
  107506. 0, 0, 0, 0, 0,
  107507. NULL,
  107508. NULL,
  107509. NULL,
  107510. NULL,
  107511. 0
  107512. };
  107513. static long _huff_lengthlist_line_128x11_class2[] = {
  107514. 1, 6,12,16, 4,12,15,16, 9,15,16,16,16,16,16,16,
  107515. 2, 5,11,16, 5,11,13,16, 9,13,16,16,16,16,16,16,
  107516. 4, 8,12,16, 5, 9,12,16, 9,13,15,16,16,16,16,16,
  107517. 15,16,16,16,11,14,13,16,12,15,16,16,16,16,16,15,
  107518. };
  107519. static static_codebook _huff_book_line_128x11_class2 = {
  107520. 1, 64,
  107521. _huff_lengthlist_line_128x11_class2,
  107522. 0, 0, 0, 0, 0,
  107523. NULL,
  107524. NULL,
  107525. NULL,
  107526. NULL,
  107527. 0
  107528. };
  107529. static long _huff_lengthlist_line_128x11_class3[] = {
  107530. 7, 6, 9,17, 7, 6, 8,17,12, 9,11,16,16,16,16,16,
  107531. 5, 4, 7,16, 5, 3, 6,14, 9, 6, 8,15,16,16,16,16,
  107532. 5, 4, 6,13, 3, 2, 4,11, 7, 4, 6,13,16,11,10,14,
  107533. 12,12,12,16, 9, 7,10,15,12, 9,11,16,16,15,15,16,
  107534. };
  107535. static static_codebook _huff_book_line_128x11_class3 = {
  107536. 1, 64,
  107537. _huff_lengthlist_line_128x11_class3,
  107538. 0, 0, 0, 0, 0,
  107539. NULL,
  107540. NULL,
  107541. NULL,
  107542. NULL,
  107543. 0
  107544. };
  107545. static long _huff_lengthlist_line_128x11_0sub0[] = {
  107546. 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107547. 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 6, 6, 6, 7, 6,
  107548. 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 8, 6, 8, 6, 8, 7,
  107549. 8, 7, 8, 7, 8, 7, 9, 7, 9, 8, 9, 8, 9, 8,10, 8,
  107550. 10, 9,10, 9,10, 9,11, 9,11, 9,10,10,11,10,11,10,
  107551. 11,11,11,11,11,11,12,13,14,14,14,15,15,16,16,16,
  107552. 17,15,16,15,16,16,17,17,16,17,17,17,17,17,17,17,
  107553. 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
  107554. };
  107555. static static_codebook _huff_book_line_128x11_0sub0 = {
  107556. 1, 128,
  107557. _huff_lengthlist_line_128x11_0sub0,
  107558. 0, 0, 0, 0, 0,
  107559. NULL,
  107560. NULL,
  107561. NULL,
  107562. NULL,
  107563. 0
  107564. };
  107565. static long _huff_lengthlist_line_128x11_1sub0[] = {
  107566. 2, 5, 5, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5, 5, 5, 5,
  107567. 6, 5, 6, 5, 6, 5, 7, 6, 7, 6, 7, 6, 8, 6, 8, 6,
  107568. };
  107569. static static_codebook _huff_book_line_128x11_1sub0 = {
  107570. 1, 32,
  107571. _huff_lengthlist_line_128x11_1sub0,
  107572. 0, 0, 0, 0, 0,
  107573. NULL,
  107574. NULL,
  107575. NULL,
  107576. NULL,
  107577. 0
  107578. };
  107579. static long _huff_lengthlist_line_128x11_1sub1[] = {
  107580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107582. 5, 3, 5, 3, 6, 4, 6, 4, 7, 4, 7, 4, 7, 4, 8, 4,
  107583. 8, 4, 9, 5, 9, 5, 9, 5, 9, 6,10, 6,10, 6,11, 7,
  107584. 10, 7,10, 8,11, 9,11, 9,11,10,11,11,12,11,11,12,
  107585. 15,15,12,14,11,14,12,14,11,14,13,14,12,14,11,14,
  107586. 11,14,12,14,11,14,11,14,13,13,14,14,14,14,14,14,
  107587. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  107588. };
  107589. static static_codebook _huff_book_line_128x11_1sub1 = {
  107590. 1, 128,
  107591. _huff_lengthlist_line_128x11_1sub1,
  107592. 0, 0, 0, 0, 0,
  107593. NULL,
  107594. NULL,
  107595. NULL,
  107596. NULL,
  107597. 0
  107598. };
  107599. static long _huff_lengthlist_line_128x11_2sub1[] = {
  107600. 0, 4, 5, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4, 4, 4,
  107601. 5, 5,
  107602. };
  107603. static static_codebook _huff_book_line_128x11_2sub1 = {
  107604. 1, 18,
  107605. _huff_lengthlist_line_128x11_2sub1,
  107606. 0, 0, 0, 0, 0,
  107607. NULL,
  107608. NULL,
  107609. NULL,
  107610. NULL,
  107611. 0
  107612. };
  107613. static long _huff_lengthlist_line_128x11_2sub2[] = {
  107614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107615. 0, 0, 3, 3, 3, 4, 4, 4, 4, 5, 4, 5, 4, 6, 5, 7,
  107616. 5, 7, 6, 8, 6, 8, 6, 9, 7, 9, 7,10, 7, 9, 8,11,
  107617. 8,11,
  107618. };
  107619. static static_codebook _huff_book_line_128x11_2sub2 = {
  107620. 1, 50,
  107621. _huff_lengthlist_line_128x11_2sub2,
  107622. 0, 0, 0, 0, 0,
  107623. NULL,
  107624. NULL,
  107625. NULL,
  107626. NULL,
  107627. 0
  107628. };
  107629. static long _huff_lengthlist_line_128x11_2sub3[] = {
  107630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107633. 0, 0, 4, 8, 3, 8, 4, 8, 4, 8, 6, 8, 5, 8, 4, 8,
  107634. 4, 8, 6, 8, 7, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107635. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107636. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107637. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107638. };
  107639. static static_codebook _huff_book_line_128x11_2sub3 = {
  107640. 1, 128,
  107641. _huff_lengthlist_line_128x11_2sub3,
  107642. 0, 0, 0, 0, 0,
  107643. NULL,
  107644. NULL,
  107645. NULL,
  107646. NULL,
  107647. 0
  107648. };
  107649. static long _huff_lengthlist_line_128x11_3sub1[] = {
  107650. 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 4,
  107651. 5, 4,
  107652. };
  107653. static static_codebook _huff_book_line_128x11_3sub1 = {
  107654. 1, 18,
  107655. _huff_lengthlist_line_128x11_3sub1,
  107656. 0, 0, 0, 0, 0,
  107657. NULL,
  107658. NULL,
  107659. NULL,
  107660. NULL,
  107661. 0
  107662. };
  107663. static long _huff_lengthlist_line_128x11_3sub2[] = {
  107664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107665. 0, 0, 5, 3, 5, 4, 6, 4, 6, 4, 7, 4, 7, 4, 8, 4,
  107666. 8, 4, 9, 4, 9, 4,10, 4,10, 5,10, 5,11, 5,12, 6,
  107667. 12, 6,
  107668. };
  107669. static static_codebook _huff_book_line_128x11_3sub2 = {
  107670. 1, 50,
  107671. _huff_lengthlist_line_128x11_3sub2,
  107672. 0, 0, 0, 0, 0,
  107673. NULL,
  107674. NULL,
  107675. NULL,
  107676. NULL,
  107677. 0
  107678. };
  107679. static long _huff_lengthlist_line_128x11_3sub3[] = {
  107680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107683. 0, 0, 7, 1, 6, 3, 7, 3, 8, 4, 8, 5, 8, 8, 8, 9,
  107684. 7, 8, 8, 7, 7, 7, 8, 9,10, 9, 9,10,10,10,10,10,
  107685. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  107686. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  107687. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9,
  107688. };
  107689. static static_codebook _huff_book_line_128x11_3sub3 = {
  107690. 1, 128,
  107691. _huff_lengthlist_line_128x11_3sub3,
  107692. 0, 0, 0, 0, 0,
  107693. NULL,
  107694. NULL,
  107695. NULL,
  107696. NULL,
  107697. 0
  107698. };
  107699. static long _huff_lengthlist_line_128x17_class1[] = {
  107700. 1, 3, 4, 7, 2, 5, 6, 7,
  107701. };
  107702. static static_codebook _huff_book_line_128x17_class1 = {
  107703. 1, 8,
  107704. _huff_lengthlist_line_128x17_class1,
  107705. 0, 0, 0, 0, 0,
  107706. NULL,
  107707. NULL,
  107708. NULL,
  107709. NULL,
  107710. 0
  107711. };
  107712. static long _huff_lengthlist_line_128x17_class2[] = {
  107713. 1, 4,10,19, 3, 8,13,19, 7,12,19,19,19,19,19,19,
  107714. 2, 6,11,19, 8,13,19,19, 9,11,19,19,19,19,19,19,
  107715. 6, 7,13,19, 9,13,19,19,10,13,18,18,18,18,18,18,
  107716. 18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,
  107717. };
  107718. static static_codebook _huff_book_line_128x17_class2 = {
  107719. 1, 64,
  107720. _huff_lengthlist_line_128x17_class2,
  107721. 0, 0, 0, 0, 0,
  107722. NULL,
  107723. NULL,
  107724. NULL,
  107725. NULL,
  107726. 0
  107727. };
  107728. static long _huff_lengthlist_line_128x17_class3[] = {
  107729. 3, 6,10,17, 4, 8,11,20, 8,10,11,20,20,20,20,20,
  107730. 2, 4, 8,18, 4, 6, 8,17, 7, 8,10,20,20,17,20,20,
  107731. 3, 5, 8,17, 3, 4, 6,17, 8, 8,10,17,17,12,16,20,
  107732. 13,13,15,20,10,10,12,20,15,14,15,20,20,20,19,19,
  107733. };
  107734. static static_codebook _huff_book_line_128x17_class3 = {
  107735. 1, 64,
  107736. _huff_lengthlist_line_128x17_class3,
  107737. 0, 0, 0, 0, 0,
  107738. NULL,
  107739. NULL,
  107740. NULL,
  107741. NULL,
  107742. 0
  107743. };
  107744. static long _huff_lengthlist_line_128x17_0sub0[] = {
  107745. 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107746. 7, 5, 7, 5, 7, 5, 7, 5, 7, 5, 7, 5, 8, 5, 8, 5,
  107747. 8, 5, 8, 5, 8, 6, 8, 6, 8, 6, 9, 6, 9, 6, 9, 6,
  107748. 9, 6, 9, 7, 9, 7, 9, 7, 9, 7,10, 7,10, 8,10, 8,
  107749. 10, 8,10, 8,10, 8,11, 8,11, 8,11, 8,11, 8,11, 9,
  107750. 12, 9,12, 9,12, 9,12, 9,12,10,12,10,13,11,13,11,
  107751. 14,12,14,13,15,14,16,14,17,15,18,16,20,20,20,20,
  107752. 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
  107753. };
  107754. static static_codebook _huff_book_line_128x17_0sub0 = {
  107755. 1, 128,
  107756. _huff_lengthlist_line_128x17_0sub0,
  107757. 0, 0, 0, 0, 0,
  107758. NULL,
  107759. NULL,
  107760. NULL,
  107761. NULL,
  107762. 0
  107763. };
  107764. static long _huff_lengthlist_line_128x17_1sub0[] = {
  107765. 2, 5, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 6, 5,
  107766. 6, 5, 6, 5, 7, 6, 7, 6, 7, 6, 8, 6, 9, 7, 9, 7,
  107767. };
  107768. static static_codebook _huff_book_line_128x17_1sub0 = {
  107769. 1, 32,
  107770. _huff_lengthlist_line_128x17_1sub0,
  107771. 0, 0, 0, 0, 0,
  107772. NULL,
  107773. NULL,
  107774. NULL,
  107775. NULL,
  107776. 0
  107777. };
  107778. static long _huff_lengthlist_line_128x17_1sub1[] = {
  107779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107781. 4, 3, 5, 3, 5, 3, 6, 3, 6, 4, 6, 4, 7, 4, 7, 5,
  107782. 8, 5, 8, 6, 9, 7, 9, 7, 9, 8,10, 9,10, 9,11,10,
  107783. 11,11,11,11,11,11,12,12,12,13,12,13,12,14,12,15,
  107784. 12,14,12,16,13,17,13,17,14,17,14,16,13,17,14,17,
  107785. 14,17,15,17,15,15,16,17,17,17,17,17,17,17,17,17,
  107786. 17,17,17,17,17,17,16,16,16,16,16,16,16,16,16,16,
  107787. };
  107788. static static_codebook _huff_book_line_128x17_1sub1 = {
  107789. 1, 128,
  107790. _huff_lengthlist_line_128x17_1sub1,
  107791. 0, 0, 0, 0, 0,
  107792. NULL,
  107793. NULL,
  107794. NULL,
  107795. NULL,
  107796. 0
  107797. };
  107798. static long _huff_lengthlist_line_128x17_2sub1[] = {
  107799. 0, 4, 5, 4, 6, 4, 8, 3, 9, 3, 9, 2, 9, 3, 8, 4,
  107800. 9, 4,
  107801. };
  107802. static static_codebook _huff_book_line_128x17_2sub1 = {
  107803. 1, 18,
  107804. _huff_lengthlist_line_128x17_2sub1,
  107805. 0, 0, 0, 0, 0,
  107806. NULL,
  107807. NULL,
  107808. NULL,
  107809. NULL,
  107810. 0
  107811. };
  107812. static long _huff_lengthlist_line_128x17_2sub2[] = {
  107813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107814. 0, 0, 5, 1, 5, 3, 5, 3, 5, 4, 7, 5,10, 7,10, 7,
  107815. 12,10,14,10,14, 9,14,11,14,14,14,13,13,13,13,13,
  107816. 13,13,
  107817. };
  107818. static static_codebook _huff_book_line_128x17_2sub2 = {
  107819. 1, 50,
  107820. _huff_lengthlist_line_128x17_2sub2,
  107821. 0, 0, 0, 0, 0,
  107822. NULL,
  107823. NULL,
  107824. NULL,
  107825. NULL,
  107826. 0
  107827. };
  107828. static long _huff_lengthlist_line_128x17_2sub3[] = {
  107829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107832. 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107833. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6,
  107834. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107835. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107836. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107837. };
  107838. static static_codebook _huff_book_line_128x17_2sub3 = {
  107839. 1, 128,
  107840. _huff_lengthlist_line_128x17_2sub3,
  107841. 0, 0, 0, 0, 0,
  107842. NULL,
  107843. NULL,
  107844. NULL,
  107845. NULL,
  107846. 0
  107847. };
  107848. static long _huff_lengthlist_line_128x17_3sub1[] = {
  107849. 0, 4, 4, 4, 4, 4, 4, 4, 5, 3, 5, 3, 5, 4, 6, 4,
  107850. 6, 4,
  107851. };
  107852. static static_codebook _huff_book_line_128x17_3sub1 = {
  107853. 1, 18,
  107854. _huff_lengthlist_line_128x17_3sub1,
  107855. 0, 0, 0, 0, 0,
  107856. NULL,
  107857. NULL,
  107858. NULL,
  107859. NULL,
  107860. 0
  107861. };
  107862. static long _huff_lengthlist_line_128x17_3sub2[] = {
  107863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107864. 0, 0, 5, 3, 6, 3, 6, 4, 7, 4, 7, 4, 7, 4, 8, 4,
  107865. 8, 4, 8, 4, 8, 4, 9, 4, 9, 5,10, 5,10, 7,10, 8,
  107866. 10, 8,
  107867. };
  107868. static static_codebook _huff_book_line_128x17_3sub2 = {
  107869. 1, 50,
  107870. _huff_lengthlist_line_128x17_3sub2,
  107871. 0, 0, 0, 0, 0,
  107872. NULL,
  107873. NULL,
  107874. NULL,
  107875. NULL,
  107876. 0
  107877. };
  107878. static long _huff_lengthlist_line_128x17_3sub3[] = {
  107879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107882. 0, 0, 3, 2, 4, 3, 4, 4, 4, 5, 4, 7, 5, 8, 5,11,
  107883. 6,10, 6,12, 7,12, 7,12, 8,12, 8,12,10,12,12,12,
  107884. 12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107885. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107886. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107887. };
  107888. static static_codebook _huff_book_line_128x17_3sub3 = {
  107889. 1, 128,
  107890. _huff_lengthlist_line_128x17_3sub3,
  107891. 0, 0, 0, 0, 0,
  107892. NULL,
  107893. NULL,
  107894. NULL,
  107895. NULL,
  107896. 0
  107897. };
  107898. static long _huff_lengthlist_line_1024x27_class1[] = {
  107899. 2,10, 8,14, 7,12,11,14, 1, 5, 3, 7, 4, 9, 7,13,
  107900. };
  107901. static static_codebook _huff_book_line_1024x27_class1 = {
  107902. 1, 16,
  107903. _huff_lengthlist_line_1024x27_class1,
  107904. 0, 0, 0, 0, 0,
  107905. NULL,
  107906. NULL,
  107907. NULL,
  107908. NULL,
  107909. 0
  107910. };
  107911. static long _huff_lengthlist_line_1024x27_class2[] = {
  107912. 1, 4, 2, 6, 3, 7, 5, 7,
  107913. };
  107914. static static_codebook _huff_book_line_1024x27_class2 = {
  107915. 1, 8,
  107916. _huff_lengthlist_line_1024x27_class2,
  107917. 0, 0, 0, 0, 0,
  107918. NULL,
  107919. NULL,
  107920. NULL,
  107921. NULL,
  107922. 0
  107923. };
  107924. static long _huff_lengthlist_line_1024x27_class3[] = {
  107925. 1, 5, 7,21, 5, 8, 9,21,10, 9,12,20,20,16,20,20,
  107926. 4, 8, 9,20, 6, 8, 9,20,11,11,13,20,20,15,17,20,
  107927. 9,11,14,20, 8,10,15,20,11,13,15,20,20,20,20,20,
  107928. 20,20,20,20,13,20,20,20,18,18,20,20,20,20,20,20,
  107929. 3, 6, 8,20, 6, 7, 9,20,10, 9,12,20,20,20,20,20,
  107930. 5, 7, 9,20, 6, 6, 9,20,10, 9,12,20,20,20,20,20,
  107931. 8,10,13,20, 8, 9,12,20,11,10,12,20,20,20,20,20,
  107932. 18,20,20,20,15,17,18,20,18,17,18,20,20,20,20,20,
  107933. 7,10,12,20, 8, 9,11,20,14,13,14,20,20,20,20,20,
  107934. 6, 9,12,20, 7, 8,11,20,12,11,13,20,20,20,20,20,
  107935. 9,11,15,20, 8,10,14,20,12,11,14,20,20,20,20,20,
  107936. 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
  107937. 11,16,18,20,15,15,17,20,20,17,20,20,20,20,20,20,
  107938. 9,14,16,20,12,12,15,20,17,15,18,20,20,20,20,20,
  107939. 16,19,18,20,15,16,20,20,17,17,20,20,20,20,20,20,
  107940. 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
  107941. };
  107942. static static_codebook _huff_book_line_1024x27_class3 = {
  107943. 1, 256,
  107944. _huff_lengthlist_line_1024x27_class3,
  107945. 0, 0, 0, 0, 0,
  107946. NULL,
  107947. NULL,
  107948. NULL,
  107949. NULL,
  107950. 0
  107951. };
  107952. static long _huff_lengthlist_line_1024x27_class4[] = {
  107953. 2, 3, 7,13, 4, 4, 7,15, 8, 6, 9,17,21,16,15,21,
  107954. 2, 5, 7,11, 5, 5, 7,14, 9, 7,10,16,17,15,16,21,
  107955. 4, 7,10,17, 7, 7, 9,15,11, 9,11,16,21,18,15,21,
  107956. 18,21,21,21,15,17,17,19,21,19,18,20,21,21,21,20,
  107957. };
  107958. static static_codebook _huff_book_line_1024x27_class4 = {
  107959. 1, 64,
  107960. _huff_lengthlist_line_1024x27_class4,
  107961. 0, 0, 0, 0, 0,
  107962. NULL,
  107963. NULL,
  107964. NULL,
  107965. NULL,
  107966. 0
  107967. };
  107968. static long _huff_lengthlist_line_1024x27_0sub0[] = {
  107969. 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107970. 6, 5, 6, 5, 6, 5, 6, 5, 7, 5, 7, 5, 7, 5, 7, 5,
  107971. 8, 6, 8, 6, 8, 6, 9, 6, 9, 6,10, 6,10, 6,11, 6,
  107972. 11, 7,11, 7,12, 7,12, 7,12, 7,12, 7,12, 7,12, 7,
  107973. 12, 7,12, 8,13, 8,12, 8,12, 8,13, 8,13, 9,13, 9,
  107974. 13, 9,13, 9,12,10,12,10,13,10,14,11,14,12,14,13,
  107975. 14,13,14,14,15,16,15,15,15,14,15,17,21,22,22,21,
  107976. 22,22,22,22,22,22,21,21,21,21,21,21,21,21,21,21,
  107977. };
  107978. static static_codebook _huff_book_line_1024x27_0sub0 = {
  107979. 1, 128,
  107980. _huff_lengthlist_line_1024x27_0sub0,
  107981. 0, 0, 0, 0, 0,
  107982. NULL,
  107983. NULL,
  107984. NULL,
  107985. NULL,
  107986. 0
  107987. };
  107988. static long _huff_lengthlist_line_1024x27_1sub0[] = {
  107989. 2, 5, 5, 4, 5, 4, 5, 4, 5, 4, 6, 5, 6, 5, 6, 5,
  107990. 6, 5, 7, 5, 7, 6, 8, 6, 8, 6, 8, 6, 9, 6, 9, 6,
  107991. };
  107992. static static_codebook _huff_book_line_1024x27_1sub0 = {
  107993. 1, 32,
  107994. _huff_lengthlist_line_1024x27_1sub0,
  107995. 0, 0, 0, 0, 0,
  107996. NULL,
  107997. NULL,
  107998. NULL,
  107999. NULL,
  108000. 0
  108001. };
  108002. static long _huff_lengthlist_line_1024x27_1sub1[] = {
  108003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108005. 8, 5, 8, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 4,
  108006. 9, 4, 9, 4, 9, 4, 8, 4, 8, 4, 9, 5, 9, 5, 9, 5,
  108007. 9, 5, 9, 6,10, 6,10, 7,10, 8,11, 9,11,11,12,13,
  108008. 12,14,13,15,13,15,14,16,14,17,15,17,15,15,16,16,
  108009. 15,16,16,16,15,18,16,15,17,17,19,19,19,19,19,19,
  108010. 19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,
  108011. };
  108012. static static_codebook _huff_book_line_1024x27_1sub1 = {
  108013. 1, 128,
  108014. _huff_lengthlist_line_1024x27_1sub1,
  108015. 0, 0, 0, 0, 0,
  108016. NULL,
  108017. NULL,
  108018. NULL,
  108019. NULL,
  108020. 0
  108021. };
  108022. static long _huff_lengthlist_line_1024x27_2sub0[] = {
  108023. 1, 5, 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  108024. 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 9, 8,10, 9,10, 9,
  108025. };
  108026. static static_codebook _huff_book_line_1024x27_2sub0 = {
  108027. 1, 32,
  108028. _huff_lengthlist_line_1024x27_2sub0,
  108029. 0, 0, 0, 0, 0,
  108030. NULL,
  108031. NULL,
  108032. NULL,
  108033. NULL,
  108034. 0
  108035. };
  108036. static long _huff_lengthlist_line_1024x27_2sub1[] = {
  108037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108039. 4, 3, 4, 3, 4, 4, 5, 4, 5, 4, 5, 5, 6, 5, 6, 5,
  108040. 7, 5, 7, 6, 7, 6, 8, 7, 8, 7, 8, 7, 9, 8, 9, 9,
  108041. 9, 9,10,10,10,11, 9,12, 9,12, 9,15,10,14, 9,13,
  108042. 10,13,10,12,10,12,10,13,10,12,11,13,11,14,12,13,
  108043. 13,14,14,13,14,15,14,16,13,13,14,16,16,16,16,16,
  108044. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,15,15,
  108045. };
  108046. static static_codebook _huff_book_line_1024x27_2sub1 = {
  108047. 1, 128,
  108048. _huff_lengthlist_line_1024x27_2sub1,
  108049. 0, 0, 0, 0, 0,
  108050. NULL,
  108051. NULL,
  108052. NULL,
  108053. NULL,
  108054. 0
  108055. };
  108056. static long _huff_lengthlist_line_1024x27_3sub1[] = {
  108057. 0, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4, 4, 4, 4, 5,
  108058. 5, 5,
  108059. };
  108060. static static_codebook _huff_book_line_1024x27_3sub1 = {
  108061. 1, 18,
  108062. _huff_lengthlist_line_1024x27_3sub1,
  108063. 0, 0, 0, 0, 0,
  108064. NULL,
  108065. NULL,
  108066. NULL,
  108067. NULL,
  108068. 0
  108069. };
  108070. static long _huff_lengthlist_line_1024x27_3sub2[] = {
  108071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108072. 0, 0, 3, 3, 4, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6,
  108073. 5, 7, 5, 8, 6, 8, 6, 9, 7,10, 7,10, 8,10, 8,11,
  108074. 9,11,
  108075. };
  108076. static static_codebook _huff_book_line_1024x27_3sub2 = {
  108077. 1, 50,
  108078. _huff_lengthlist_line_1024x27_3sub2,
  108079. 0, 0, 0, 0, 0,
  108080. NULL,
  108081. NULL,
  108082. NULL,
  108083. NULL,
  108084. 0
  108085. };
  108086. static long _huff_lengthlist_line_1024x27_3sub3[] = {
  108087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108090. 0, 0, 3, 7, 3, 8, 3,10, 3, 8, 3, 9, 3, 8, 4, 9,
  108091. 4, 9, 5, 9, 6,10, 6, 9, 7,11, 7,12, 9,13,10,13,
  108092. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  108093. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  108094. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  108095. };
  108096. static static_codebook _huff_book_line_1024x27_3sub3 = {
  108097. 1, 128,
  108098. _huff_lengthlist_line_1024x27_3sub3,
  108099. 0, 0, 0, 0, 0,
  108100. NULL,
  108101. NULL,
  108102. NULL,
  108103. NULL,
  108104. 0
  108105. };
  108106. static long _huff_lengthlist_line_1024x27_4sub1[] = {
  108107. 0, 4, 5, 4, 5, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4,
  108108. 5, 4,
  108109. };
  108110. static static_codebook _huff_book_line_1024x27_4sub1 = {
  108111. 1, 18,
  108112. _huff_lengthlist_line_1024x27_4sub1,
  108113. 0, 0, 0, 0, 0,
  108114. NULL,
  108115. NULL,
  108116. NULL,
  108117. NULL,
  108118. 0
  108119. };
  108120. static long _huff_lengthlist_line_1024x27_4sub2[] = {
  108121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108122. 0, 0, 4, 2, 4, 2, 5, 3, 5, 4, 6, 6, 6, 7, 7, 8,
  108123. 7, 8, 7, 8, 7, 9, 8, 9, 8, 9, 8,10, 8,11, 9,12,
  108124. 9,12,
  108125. };
  108126. static static_codebook _huff_book_line_1024x27_4sub2 = {
  108127. 1, 50,
  108128. _huff_lengthlist_line_1024x27_4sub2,
  108129. 0, 0, 0, 0, 0,
  108130. NULL,
  108131. NULL,
  108132. NULL,
  108133. NULL,
  108134. 0
  108135. };
  108136. static long _huff_lengthlist_line_1024x27_4sub3[] = {
  108137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108140. 0, 0, 2, 5, 2, 6, 3, 6, 4, 7, 4, 7, 5, 9, 5,11,
  108141. 6,11, 6,11, 7,11, 6,11, 6,11, 9,11, 8,11,11,11,
  108142. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  108143. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  108144. 11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,
  108145. };
  108146. static static_codebook _huff_book_line_1024x27_4sub3 = {
  108147. 1, 128,
  108148. _huff_lengthlist_line_1024x27_4sub3,
  108149. 0, 0, 0, 0, 0,
  108150. NULL,
  108151. NULL,
  108152. NULL,
  108153. NULL,
  108154. 0
  108155. };
  108156. static long _huff_lengthlist_line_2048x27_class1[] = {
  108157. 2, 6, 8, 9, 7,11,13,13, 1, 3, 5, 5, 6, 6,12,10,
  108158. };
  108159. static static_codebook _huff_book_line_2048x27_class1 = {
  108160. 1, 16,
  108161. _huff_lengthlist_line_2048x27_class1,
  108162. 0, 0, 0, 0, 0,
  108163. NULL,
  108164. NULL,
  108165. NULL,
  108166. NULL,
  108167. 0
  108168. };
  108169. static long _huff_lengthlist_line_2048x27_class2[] = {
  108170. 1, 2, 3, 6, 4, 7, 5, 7,
  108171. };
  108172. static static_codebook _huff_book_line_2048x27_class2 = {
  108173. 1, 8,
  108174. _huff_lengthlist_line_2048x27_class2,
  108175. 0, 0, 0, 0, 0,
  108176. NULL,
  108177. NULL,
  108178. NULL,
  108179. NULL,
  108180. 0
  108181. };
  108182. static long _huff_lengthlist_line_2048x27_class3[] = {
  108183. 3, 3, 6,16, 5, 5, 7,16, 9, 8,11,16,16,16,16,16,
  108184. 5, 5, 8,16, 5, 5, 7,16, 8, 7, 9,16,16,16,16,16,
  108185. 9, 9,12,16, 6, 8,11,16, 9,10,11,16,16,16,16,16,
  108186. 16,16,16,16,13,16,16,16,15,16,16,16,16,16,16,16,
  108187. 5, 4, 7,16, 6, 5, 8,16, 9, 8,10,16,16,16,16,16,
  108188. 5, 5, 7,15, 5, 4, 6,15, 7, 6, 8,16,16,16,16,16,
  108189. 9, 9,11,15, 7, 7, 9,16, 8, 8, 9,16,16,16,16,16,
  108190. 16,16,16,16,15,15,15,16,15,15,14,16,16,16,16,16,
  108191. 8, 8,11,16, 8, 9,10,16,11,10,14,16,16,16,16,16,
  108192. 6, 8,10,16, 6, 7,10,16, 8, 8,11,16,14,16,16,16,
  108193. 10,11,14,16, 9, 9,11,16,10,10,11,16,16,16,16,16,
  108194. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  108195. 16,16,16,16,15,16,16,16,16,16,16,16,16,16,16,16,
  108196. 12,16,15,16,12,14,16,16,16,16,16,16,16,16,16,16,
  108197. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  108198. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  108199. };
  108200. static static_codebook _huff_book_line_2048x27_class3 = {
  108201. 1, 256,
  108202. _huff_lengthlist_line_2048x27_class3,
  108203. 0, 0, 0, 0, 0,
  108204. NULL,
  108205. NULL,
  108206. NULL,
  108207. NULL,
  108208. 0
  108209. };
  108210. static long _huff_lengthlist_line_2048x27_class4[] = {
  108211. 2, 4, 7,13, 4, 5, 7,15, 8, 7,10,16,16,14,16,16,
  108212. 2, 4, 7,16, 3, 4, 7,14, 8, 8,10,16,16,16,15,16,
  108213. 6, 8,11,16, 7, 7, 9,16,11, 9,13,16,16,16,15,16,
  108214. 16,16,16,16,14,16,16,16,16,16,16,16,16,16,16,16,
  108215. };
  108216. static static_codebook _huff_book_line_2048x27_class4 = {
  108217. 1, 64,
  108218. _huff_lengthlist_line_2048x27_class4,
  108219. 0, 0, 0, 0, 0,
  108220. NULL,
  108221. NULL,
  108222. NULL,
  108223. NULL,
  108224. 0
  108225. };
  108226. static long _huff_lengthlist_line_2048x27_0sub0[] = {
  108227. 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  108228. 6, 5, 7, 5, 7, 5, 7, 5, 8, 5, 8, 5, 8, 5, 9, 5,
  108229. 9, 6,10, 6,10, 6,11, 6,11, 6,11, 6,11, 6,11, 6,
  108230. 11, 6,11, 6,12, 7,11, 7,11, 7,11, 7,11, 7,10, 7,
  108231. 11, 7,11, 7,12, 7,11, 8,11, 8,11, 8,11, 8,13, 8,
  108232. 12, 9,11, 9,11, 9,11,10,12,10,12, 9,12,10,12,11,
  108233. 14,12,16,12,12,11,14,16,17,17,17,17,17,17,17,17,
  108234. 17,17,17,17,17,17,17,17,17,17,17,17,16,16,16,16,
  108235. };
  108236. static static_codebook _huff_book_line_2048x27_0sub0 = {
  108237. 1, 128,
  108238. _huff_lengthlist_line_2048x27_0sub0,
  108239. 0, 0, 0, 0, 0,
  108240. NULL,
  108241. NULL,
  108242. NULL,
  108243. NULL,
  108244. 0
  108245. };
  108246. static long _huff_lengthlist_line_2048x27_1sub0[] = {
  108247. 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5,
  108248. 5, 5, 6, 6, 6, 6, 6, 6, 7, 6, 7, 6, 7, 6, 7, 6,
  108249. };
  108250. static static_codebook _huff_book_line_2048x27_1sub0 = {
  108251. 1, 32,
  108252. _huff_lengthlist_line_2048x27_1sub0,
  108253. 0, 0, 0, 0, 0,
  108254. NULL,
  108255. NULL,
  108256. NULL,
  108257. NULL,
  108258. 0
  108259. };
  108260. static long _huff_lengthlist_line_2048x27_1sub1[] = {
  108261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108263. 6, 5, 7, 5, 7, 4, 7, 4, 8, 4, 8, 4, 8, 4, 8, 3,
  108264. 8, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 5, 9, 5, 9, 6,
  108265. 9, 7, 9, 8, 9, 9, 9,10, 9,11, 9,14, 9,15,10,15,
  108266. 10,15,10,15,10,15,11,15,10,14,12,14,11,14,13,14,
  108267. 13,15,15,15,12,15,15,15,13,15,13,15,13,15,15,15,
  108268. 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,14,
  108269. };
  108270. static static_codebook _huff_book_line_2048x27_1sub1 = {
  108271. 1, 128,
  108272. _huff_lengthlist_line_2048x27_1sub1,
  108273. 0, 0, 0, 0, 0,
  108274. NULL,
  108275. NULL,
  108276. NULL,
  108277. NULL,
  108278. 0
  108279. };
  108280. static long _huff_lengthlist_line_2048x27_2sub0[] = {
  108281. 2, 4, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 6, 5,
  108282. 6, 5, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,
  108283. };
  108284. static static_codebook _huff_book_line_2048x27_2sub0 = {
  108285. 1, 32,
  108286. _huff_lengthlist_line_2048x27_2sub0,
  108287. 0, 0, 0, 0, 0,
  108288. NULL,
  108289. NULL,
  108290. NULL,
  108291. NULL,
  108292. 0
  108293. };
  108294. static long _huff_lengthlist_line_2048x27_2sub1[] = {
  108295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108297. 3, 4, 3, 4, 3, 4, 4, 5, 4, 5, 5, 5, 6, 6, 6, 7,
  108298. 6, 8, 6, 8, 6, 9, 7,10, 7,10, 7,10, 7,12, 7,12,
  108299. 7,12, 9,12,11,12,10,12,10,12,11,12,12,12,10,12,
  108300. 10,12,10,12, 9,12,11,12,12,12,12,12,11,12,11,12,
  108301. 12,12,12,12,12,12,12,12,10,10,12,12,12,12,12,10,
  108302. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  108303. };
  108304. static static_codebook _huff_book_line_2048x27_2sub1 = {
  108305. 1, 128,
  108306. _huff_lengthlist_line_2048x27_2sub1,
  108307. 0, 0, 0, 0, 0,
  108308. NULL,
  108309. NULL,
  108310. NULL,
  108311. NULL,
  108312. 0
  108313. };
  108314. static long _huff_lengthlist_line_2048x27_3sub1[] = {
  108315. 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  108316. 5, 5,
  108317. };
  108318. static static_codebook _huff_book_line_2048x27_3sub1 = {
  108319. 1, 18,
  108320. _huff_lengthlist_line_2048x27_3sub1,
  108321. 0, 0, 0, 0, 0,
  108322. NULL,
  108323. NULL,
  108324. NULL,
  108325. NULL,
  108326. 0
  108327. };
  108328. static long _huff_lengthlist_line_2048x27_3sub2[] = {
  108329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108330. 0, 0, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6,
  108331. 6, 7, 6, 7, 6, 8, 6, 9, 7, 9, 7, 9, 9,11, 9,12,
  108332. 10,12,
  108333. };
  108334. static static_codebook _huff_book_line_2048x27_3sub2 = {
  108335. 1, 50,
  108336. _huff_lengthlist_line_2048x27_3sub2,
  108337. 0, 0, 0, 0, 0,
  108338. NULL,
  108339. NULL,
  108340. NULL,
  108341. NULL,
  108342. 0
  108343. };
  108344. static long _huff_lengthlist_line_2048x27_3sub3[] = {
  108345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108348. 0, 0, 3, 6, 3, 7, 3, 7, 5, 7, 7, 7, 7, 7, 6, 7,
  108349. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108350. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108351. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108352. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108353. };
  108354. static static_codebook _huff_book_line_2048x27_3sub3 = {
  108355. 1, 128,
  108356. _huff_lengthlist_line_2048x27_3sub3,
  108357. 0, 0, 0, 0, 0,
  108358. NULL,
  108359. NULL,
  108360. NULL,
  108361. NULL,
  108362. 0
  108363. };
  108364. static long _huff_lengthlist_line_2048x27_4sub1[] = {
  108365. 0, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 4, 5, 4, 5, 4,
  108366. 4, 5,
  108367. };
  108368. static static_codebook _huff_book_line_2048x27_4sub1 = {
  108369. 1, 18,
  108370. _huff_lengthlist_line_2048x27_4sub1,
  108371. 0, 0, 0, 0, 0,
  108372. NULL,
  108373. NULL,
  108374. NULL,
  108375. NULL,
  108376. 0
  108377. };
  108378. static long _huff_lengthlist_line_2048x27_4sub2[] = {
  108379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108380. 0, 0, 3, 2, 4, 3, 4, 4, 4, 5, 5, 6, 5, 6, 5, 7,
  108381. 6, 6, 6, 7, 7, 7, 8, 9, 9, 9,12,10,11,10,10,12,
  108382. 10,10,
  108383. };
  108384. static static_codebook _huff_book_line_2048x27_4sub2 = {
  108385. 1, 50,
  108386. _huff_lengthlist_line_2048x27_4sub2,
  108387. 0, 0, 0, 0, 0,
  108388. NULL,
  108389. NULL,
  108390. NULL,
  108391. NULL,
  108392. 0
  108393. };
  108394. static long _huff_lengthlist_line_2048x27_4sub3[] = {
  108395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108398. 0, 0, 3, 6, 5, 7, 5, 7, 7, 7, 7, 7, 5, 7, 5, 7,
  108399. 5, 7, 5, 7, 7, 7, 7, 7, 4, 7, 7, 7, 7, 7, 7, 7,
  108400. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108401. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108402. 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  108403. };
  108404. static static_codebook _huff_book_line_2048x27_4sub3 = {
  108405. 1, 128,
  108406. _huff_lengthlist_line_2048x27_4sub3,
  108407. 0, 0, 0, 0, 0,
  108408. NULL,
  108409. NULL,
  108410. NULL,
  108411. NULL,
  108412. 0
  108413. };
  108414. static long _huff_lengthlist_line_256x4low_class0[] = {
  108415. 4, 5, 6,11, 5, 5, 6,10, 7, 7, 6, 6,14,13, 9, 9,
  108416. 6, 6, 6,10, 6, 6, 6, 9, 8, 7, 7, 9,14,12, 8,11,
  108417. 8, 7, 7,11, 8, 8, 7,11, 9, 9, 7, 9,13,11, 9,13,
  108418. 19,19,18,19,15,16,16,19,11,11,10,13,10,10, 9,15,
  108419. 5, 5, 6,13, 6, 6, 6,11, 8, 7, 6, 7,14,11,10,11,
  108420. 6, 6, 6,12, 7, 6, 6,11, 8, 7, 7,11,13,11, 9,11,
  108421. 9, 7, 6,12, 8, 7, 6,12, 9, 8, 8,11,13,10, 7,13,
  108422. 19,19,17,19,17,14,14,19,12,10, 8,12,13,10, 9,16,
  108423. 7, 8, 7,12, 7, 7, 7,11, 8, 7, 7, 8,12,12,11,11,
  108424. 8, 8, 7,12, 8, 7, 6,11, 8, 7, 7,10,10,11,10,11,
  108425. 9, 8, 8,13, 9, 8, 7,12,10, 9, 7,11, 9, 8, 7,11,
  108426. 18,18,15,18,18,16,17,18,15,11,10,18,11, 9, 9,18,
  108427. 16,16,13,16,12,11,10,16,12,11, 9, 6,15,12,11,13,
  108428. 16,16,14,14,13,11,12,16,12, 9, 9,13,13,10,10,12,
  108429. 17,18,17,17,14,15,14,16,14,12,14,15,12,10,11,12,
  108430. 18,18,18,18,18,18,18,18,18,12,13,18,16,11, 9,18,
  108431. };
  108432. static static_codebook _huff_book_line_256x4low_class0 = {
  108433. 1, 256,
  108434. _huff_lengthlist_line_256x4low_class0,
  108435. 0, 0, 0, 0, 0,
  108436. NULL,
  108437. NULL,
  108438. NULL,
  108439. NULL,
  108440. 0
  108441. };
  108442. static long _huff_lengthlist_line_256x4low_0sub0[] = {
  108443. 1, 3, 2, 3,
  108444. };
  108445. static static_codebook _huff_book_line_256x4low_0sub0 = {
  108446. 1, 4,
  108447. _huff_lengthlist_line_256x4low_0sub0,
  108448. 0, 0, 0, 0, 0,
  108449. NULL,
  108450. NULL,
  108451. NULL,
  108452. NULL,
  108453. 0
  108454. };
  108455. static long _huff_lengthlist_line_256x4low_0sub1[] = {
  108456. 0, 0, 0, 0, 2, 3, 2, 3, 3, 3,
  108457. };
  108458. static static_codebook _huff_book_line_256x4low_0sub1 = {
  108459. 1, 10,
  108460. _huff_lengthlist_line_256x4low_0sub1,
  108461. 0, 0, 0, 0, 0,
  108462. NULL,
  108463. NULL,
  108464. NULL,
  108465. NULL,
  108466. 0
  108467. };
  108468. static long _huff_lengthlist_line_256x4low_0sub2[] = {
  108469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 4, 3, 4,
  108470. 4, 4, 4, 4, 5, 5, 5, 6, 6,
  108471. };
  108472. static static_codebook _huff_book_line_256x4low_0sub2 = {
  108473. 1, 25,
  108474. _huff_lengthlist_line_256x4low_0sub2,
  108475. 0, 0, 0, 0, 0,
  108476. NULL,
  108477. NULL,
  108478. NULL,
  108479. NULL,
  108480. 0
  108481. };
  108482. static long _huff_lengthlist_line_256x4low_0sub3[] = {
  108483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 2, 4, 3, 5, 4,
  108485. 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 7, 8, 6, 9,
  108486. 7,12,11,16,13,16,12,15,13,15,12,14,12,15,15,15,
  108487. };
  108488. static static_codebook _huff_book_line_256x4low_0sub3 = {
  108489. 1, 64,
  108490. _huff_lengthlist_line_256x4low_0sub3,
  108491. 0, 0, 0, 0, 0,
  108492. NULL,
  108493. NULL,
  108494. NULL,
  108495. NULL,
  108496. 0
  108497. };
  108498. /*** End of inlined file: floor_books.h ***/
  108499. static static_codebook *_floor_128x4_books[]={
  108500. &_huff_book_line_128x4_class0,
  108501. &_huff_book_line_128x4_0sub0,
  108502. &_huff_book_line_128x4_0sub1,
  108503. &_huff_book_line_128x4_0sub2,
  108504. &_huff_book_line_128x4_0sub3,
  108505. };
  108506. static static_codebook *_floor_256x4_books[]={
  108507. &_huff_book_line_256x4_class0,
  108508. &_huff_book_line_256x4_0sub0,
  108509. &_huff_book_line_256x4_0sub1,
  108510. &_huff_book_line_256x4_0sub2,
  108511. &_huff_book_line_256x4_0sub3,
  108512. };
  108513. static static_codebook *_floor_128x7_books[]={
  108514. &_huff_book_line_128x7_class0,
  108515. &_huff_book_line_128x7_class1,
  108516. &_huff_book_line_128x7_0sub1,
  108517. &_huff_book_line_128x7_0sub2,
  108518. &_huff_book_line_128x7_0sub3,
  108519. &_huff_book_line_128x7_1sub1,
  108520. &_huff_book_line_128x7_1sub2,
  108521. &_huff_book_line_128x7_1sub3,
  108522. };
  108523. static static_codebook *_floor_256x7_books[]={
  108524. &_huff_book_line_256x7_class0,
  108525. &_huff_book_line_256x7_class1,
  108526. &_huff_book_line_256x7_0sub1,
  108527. &_huff_book_line_256x7_0sub2,
  108528. &_huff_book_line_256x7_0sub3,
  108529. &_huff_book_line_256x7_1sub1,
  108530. &_huff_book_line_256x7_1sub2,
  108531. &_huff_book_line_256x7_1sub3,
  108532. };
  108533. static static_codebook *_floor_128x11_books[]={
  108534. &_huff_book_line_128x11_class1,
  108535. &_huff_book_line_128x11_class2,
  108536. &_huff_book_line_128x11_class3,
  108537. &_huff_book_line_128x11_0sub0,
  108538. &_huff_book_line_128x11_1sub0,
  108539. &_huff_book_line_128x11_1sub1,
  108540. &_huff_book_line_128x11_2sub1,
  108541. &_huff_book_line_128x11_2sub2,
  108542. &_huff_book_line_128x11_2sub3,
  108543. &_huff_book_line_128x11_3sub1,
  108544. &_huff_book_line_128x11_3sub2,
  108545. &_huff_book_line_128x11_3sub3,
  108546. };
  108547. static static_codebook *_floor_128x17_books[]={
  108548. &_huff_book_line_128x17_class1,
  108549. &_huff_book_line_128x17_class2,
  108550. &_huff_book_line_128x17_class3,
  108551. &_huff_book_line_128x17_0sub0,
  108552. &_huff_book_line_128x17_1sub0,
  108553. &_huff_book_line_128x17_1sub1,
  108554. &_huff_book_line_128x17_2sub1,
  108555. &_huff_book_line_128x17_2sub2,
  108556. &_huff_book_line_128x17_2sub3,
  108557. &_huff_book_line_128x17_3sub1,
  108558. &_huff_book_line_128x17_3sub2,
  108559. &_huff_book_line_128x17_3sub3,
  108560. };
  108561. static static_codebook *_floor_256x4low_books[]={
  108562. &_huff_book_line_256x4low_class0,
  108563. &_huff_book_line_256x4low_0sub0,
  108564. &_huff_book_line_256x4low_0sub1,
  108565. &_huff_book_line_256x4low_0sub2,
  108566. &_huff_book_line_256x4low_0sub3,
  108567. };
  108568. static static_codebook *_floor_1024x27_books[]={
  108569. &_huff_book_line_1024x27_class1,
  108570. &_huff_book_line_1024x27_class2,
  108571. &_huff_book_line_1024x27_class3,
  108572. &_huff_book_line_1024x27_class4,
  108573. &_huff_book_line_1024x27_0sub0,
  108574. &_huff_book_line_1024x27_1sub0,
  108575. &_huff_book_line_1024x27_1sub1,
  108576. &_huff_book_line_1024x27_2sub0,
  108577. &_huff_book_line_1024x27_2sub1,
  108578. &_huff_book_line_1024x27_3sub1,
  108579. &_huff_book_line_1024x27_3sub2,
  108580. &_huff_book_line_1024x27_3sub3,
  108581. &_huff_book_line_1024x27_4sub1,
  108582. &_huff_book_line_1024x27_4sub2,
  108583. &_huff_book_line_1024x27_4sub3,
  108584. };
  108585. static static_codebook *_floor_2048x27_books[]={
  108586. &_huff_book_line_2048x27_class1,
  108587. &_huff_book_line_2048x27_class2,
  108588. &_huff_book_line_2048x27_class3,
  108589. &_huff_book_line_2048x27_class4,
  108590. &_huff_book_line_2048x27_0sub0,
  108591. &_huff_book_line_2048x27_1sub0,
  108592. &_huff_book_line_2048x27_1sub1,
  108593. &_huff_book_line_2048x27_2sub0,
  108594. &_huff_book_line_2048x27_2sub1,
  108595. &_huff_book_line_2048x27_3sub1,
  108596. &_huff_book_line_2048x27_3sub2,
  108597. &_huff_book_line_2048x27_3sub3,
  108598. &_huff_book_line_2048x27_4sub1,
  108599. &_huff_book_line_2048x27_4sub2,
  108600. &_huff_book_line_2048x27_4sub3,
  108601. };
  108602. static static_codebook *_floor_512x17_books[]={
  108603. &_huff_book_line_512x17_class1,
  108604. &_huff_book_line_512x17_class2,
  108605. &_huff_book_line_512x17_class3,
  108606. &_huff_book_line_512x17_0sub0,
  108607. &_huff_book_line_512x17_1sub0,
  108608. &_huff_book_line_512x17_1sub1,
  108609. &_huff_book_line_512x17_2sub1,
  108610. &_huff_book_line_512x17_2sub2,
  108611. &_huff_book_line_512x17_2sub3,
  108612. &_huff_book_line_512x17_3sub1,
  108613. &_huff_book_line_512x17_3sub2,
  108614. &_huff_book_line_512x17_3sub3,
  108615. };
  108616. static static_codebook **_floor_books[10]={
  108617. _floor_128x4_books,
  108618. _floor_256x4_books,
  108619. _floor_128x7_books,
  108620. _floor_256x7_books,
  108621. _floor_128x11_books,
  108622. _floor_128x17_books,
  108623. _floor_256x4low_books,
  108624. _floor_1024x27_books,
  108625. _floor_2048x27_books,
  108626. _floor_512x17_books,
  108627. };
  108628. static vorbis_info_floor1 _floor[10]={
  108629. {
  108630. 1,{0},{4},{2},{0},
  108631. {{1,2,3,4}},
  108632. 4,{0,128, 33,8,16,70},
  108633. 60,30,500, 1.,18., -1
  108634. },
  108635. {
  108636. 1,{0},{4},{2},{0},
  108637. {{1,2,3,4}},
  108638. 4,{0,256, 66,16,32,140},
  108639. 60,30,500, 1.,18., -1
  108640. },
  108641. {
  108642. 2,{0,1},{3,4},{2,2},{0,1},
  108643. {{-1,2,3,4},{-1,5,6,7}},
  108644. 4,{0,128, 14,4,58, 2,8,28,90},
  108645. 60,30,500, 1.,18., -1
  108646. },
  108647. {
  108648. 2,{0,1},{3,4},{2,2},{0,1},
  108649. {{-1,2,3,4},{-1,5,6,7}},
  108650. 4,{0,256, 28,8,116, 4,16,56,180},
  108651. 60,30,500, 1.,18., -1
  108652. },
  108653. {
  108654. 4,{0,1,2,3},{2,3,3,3},{0,1,2,2},{-1,0,1,2},
  108655. {{3},{4,5},{-1,6,7,8},{-1,9,10,11}},
  108656. 2,{0,128, 8,33, 4,16,70, 2,6,12, 23,46,90},
  108657. 60,30,500, 1,18., -1
  108658. },
  108659. {
  108660. 6,{0,1,1,2,3,3},{2,3,3,3},{0,1,2,2},{-1,0,1,2},
  108661. {{3},{4,5},{-1,6,7,8},{-1,9,10,11}},
  108662. 2,{0,128, 12,46, 4,8,16, 23,33,70, 2,6,10, 14,19,28, 39,58,90},
  108663. 60,30,500, 1,18., -1
  108664. },
  108665. {
  108666. 1,{0},{4},{2},{0},
  108667. {{1,2,3,4}},
  108668. 4,{0,256, 66,16,32,140},
  108669. 60,30,500, 1.,18., -1
  108670. },
  108671. {
  108672. 8,{0,1,2,2,3,3,4,4},{3,4,3,4,3},{0,1,1,2,2},{-1,0,1,2,3},
  108673. {{4},{5,6},{7,8},{-1,9,10,11},{-1,12,13,14}},
  108674. 2,{0,1024, 93,23,372, 6,46,186,750, 14,33,65, 130,260,556,
  108675. 3,10,18,28, 39,55,79,111, 158,220,312, 464,650,850},
  108676. 60,30,500, 3,18., -1 /* lowpass */
  108677. },
  108678. {
  108679. 8,{0,1,2,2,3,3,4,4},{3,4,3,4,3},{0,1,1,2,2},{-1,0,1,2,3},
  108680. {{4},{5,6},{7,8},{-1,9,10,11},{-1,12,13,14}},
  108681. 2,{0,2048, 186,46,744, 12,92,372,1500, 28,66,130, 260,520,1112,
  108682. 6,20,36,56, 78,110,158,222, 316,440,624, 928,1300,1700},
  108683. 60,30,500, 3,18., -1 /* lowpass */
  108684. },
  108685. {
  108686. 6,{0,1,1,2,3,3},{2,3,3,3},{0,1,2,2},{-1,0,1,2},
  108687. {{3},{4,5},{-1,6,7,8},{-1,9,10,11}},
  108688. 2,{0,512, 46,186, 16,33,65, 93,130,278,
  108689. 7,23,39, 55,79,110, 156,232,360},
  108690. 60,30,500, 1,18., -1 /* lowpass! */
  108691. },
  108692. };
  108693. /*** End of inlined file: floor_all.h ***/
  108694. /*** Start of inlined file: residue_44.h ***/
  108695. /*** Start of inlined file: res_books_stereo.h ***/
  108696. static long _vq_quantlist__16c0_s_p1_0[] = {
  108697. 1,
  108698. 0,
  108699. 2,
  108700. };
  108701. static long _vq_lengthlist__16c0_s_p1_0[] = {
  108702. 1, 4, 4, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  108703. 0, 0, 5, 7, 7, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9,10, 0, 0, 0,
  108708. 0, 0, 0, 7, 9,10, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  108713. 0, 0, 0, 0, 7, 9, 9, 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, 5, 8, 8, 0, 0, 0, 0,
  108748. 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 8,10,10, 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, 7,10,10, 0, 0, 0,
  108753. 0, 0, 0, 9, 9,12, 0, 0, 0, 0, 0, 0,10,12,11, 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, 7,10,10, 0, 0,
  108758. 0, 0, 0, 0, 9,12,10, 0, 0, 0, 0, 0, 0,10,11,12,
  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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0,
  108794. 0, 0, 0, 0, 8,10,10, 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, 7,10,10, 0, 0, 0, 0, 0, 0,10,12,11, 0,
  108799. 0, 0, 0, 0, 0, 9,10,12, 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, 7,10,10, 0, 0, 0, 0, 0, 0,10,11,12,
  108804. 0, 0, 0, 0, 0, 0, 9,12, 9, 0, 0, 0, 0, 0, 0, 0,
  108805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  109113. };
  109114. static float _vq_quantthresh__16c0_s_p1_0[] = {
  109115. -0.5, 0.5,
  109116. };
  109117. static long _vq_quantmap__16c0_s_p1_0[] = {
  109118. 1, 0, 2,
  109119. };
  109120. static encode_aux_threshmatch _vq_auxt__16c0_s_p1_0 = {
  109121. _vq_quantthresh__16c0_s_p1_0,
  109122. _vq_quantmap__16c0_s_p1_0,
  109123. 3,
  109124. 3
  109125. };
  109126. static static_codebook _16c0_s_p1_0 = {
  109127. 8, 6561,
  109128. _vq_lengthlist__16c0_s_p1_0,
  109129. 1, -535822336, 1611661312, 2, 0,
  109130. _vq_quantlist__16c0_s_p1_0,
  109131. NULL,
  109132. &_vq_auxt__16c0_s_p1_0,
  109133. NULL,
  109134. 0
  109135. };
  109136. static long _vq_quantlist__16c0_s_p2_0[] = {
  109137. 2,
  109138. 1,
  109139. 3,
  109140. 0,
  109141. 4,
  109142. };
  109143. static long _vq_lengthlist__16c0_s_p2_0[] = {
  109144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109183. 0,
  109184. };
  109185. static float _vq_quantthresh__16c0_s_p2_0[] = {
  109186. -1.5, -0.5, 0.5, 1.5,
  109187. };
  109188. static long _vq_quantmap__16c0_s_p2_0[] = {
  109189. 3, 1, 0, 2, 4,
  109190. };
  109191. static encode_aux_threshmatch _vq_auxt__16c0_s_p2_0 = {
  109192. _vq_quantthresh__16c0_s_p2_0,
  109193. _vq_quantmap__16c0_s_p2_0,
  109194. 5,
  109195. 5
  109196. };
  109197. static static_codebook _16c0_s_p2_0 = {
  109198. 4, 625,
  109199. _vq_lengthlist__16c0_s_p2_0,
  109200. 1, -533725184, 1611661312, 3, 0,
  109201. _vq_quantlist__16c0_s_p2_0,
  109202. NULL,
  109203. &_vq_auxt__16c0_s_p2_0,
  109204. NULL,
  109205. 0
  109206. };
  109207. static long _vq_quantlist__16c0_s_p3_0[] = {
  109208. 2,
  109209. 1,
  109210. 3,
  109211. 0,
  109212. 4,
  109213. };
  109214. static long _vq_lengthlist__16c0_s_p3_0[] = {
  109215. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 6, 6, 7, 6, 0, 0,
  109217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109218. 0, 0, 4, 6, 6, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  109220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109221. 0, 0, 0, 0, 6, 6, 6, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  109222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109254. 0,
  109255. };
  109256. static float _vq_quantthresh__16c0_s_p3_0[] = {
  109257. -1.5, -0.5, 0.5, 1.5,
  109258. };
  109259. static long _vq_quantmap__16c0_s_p3_0[] = {
  109260. 3, 1, 0, 2, 4,
  109261. };
  109262. static encode_aux_threshmatch _vq_auxt__16c0_s_p3_0 = {
  109263. _vq_quantthresh__16c0_s_p3_0,
  109264. _vq_quantmap__16c0_s_p3_0,
  109265. 5,
  109266. 5
  109267. };
  109268. static static_codebook _16c0_s_p3_0 = {
  109269. 4, 625,
  109270. _vq_lengthlist__16c0_s_p3_0,
  109271. 1, -533725184, 1611661312, 3, 0,
  109272. _vq_quantlist__16c0_s_p3_0,
  109273. NULL,
  109274. &_vq_auxt__16c0_s_p3_0,
  109275. NULL,
  109276. 0
  109277. };
  109278. static long _vq_quantlist__16c0_s_p4_0[] = {
  109279. 4,
  109280. 3,
  109281. 5,
  109282. 2,
  109283. 6,
  109284. 1,
  109285. 7,
  109286. 0,
  109287. 8,
  109288. };
  109289. static long _vq_lengthlist__16c0_s_p4_0[] = {
  109290. 1, 3, 2, 7, 8, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  109291. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  109292. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  109293. 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  109294. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109295. 0,
  109296. };
  109297. static float _vq_quantthresh__16c0_s_p4_0[] = {
  109298. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  109299. };
  109300. static long _vq_quantmap__16c0_s_p4_0[] = {
  109301. 7, 5, 3, 1, 0, 2, 4, 6,
  109302. 8,
  109303. };
  109304. static encode_aux_threshmatch _vq_auxt__16c0_s_p4_0 = {
  109305. _vq_quantthresh__16c0_s_p4_0,
  109306. _vq_quantmap__16c0_s_p4_0,
  109307. 9,
  109308. 9
  109309. };
  109310. static static_codebook _16c0_s_p4_0 = {
  109311. 2, 81,
  109312. _vq_lengthlist__16c0_s_p4_0,
  109313. 1, -531628032, 1611661312, 4, 0,
  109314. _vq_quantlist__16c0_s_p4_0,
  109315. NULL,
  109316. &_vq_auxt__16c0_s_p4_0,
  109317. NULL,
  109318. 0
  109319. };
  109320. static long _vq_quantlist__16c0_s_p5_0[] = {
  109321. 4,
  109322. 3,
  109323. 5,
  109324. 2,
  109325. 6,
  109326. 1,
  109327. 7,
  109328. 0,
  109329. 8,
  109330. };
  109331. static long _vq_lengthlist__16c0_s_p5_0[] = {
  109332. 1, 3, 3, 6, 6, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  109333. 8, 8, 0, 0, 0, 7, 7, 7, 7, 8, 8, 0, 0, 0, 7, 7,
  109334. 8, 8, 9, 9, 0, 0, 0, 7, 7, 8, 8, 9, 9, 0, 0, 0,
  109335. 8, 9, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  109336. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  109337. 10,
  109338. };
  109339. static float _vq_quantthresh__16c0_s_p5_0[] = {
  109340. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  109341. };
  109342. static long _vq_quantmap__16c0_s_p5_0[] = {
  109343. 7, 5, 3, 1, 0, 2, 4, 6,
  109344. 8,
  109345. };
  109346. static encode_aux_threshmatch _vq_auxt__16c0_s_p5_0 = {
  109347. _vq_quantthresh__16c0_s_p5_0,
  109348. _vq_quantmap__16c0_s_p5_0,
  109349. 9,
  109350. 9
  109351. };
  109352. static static_codebook _16c0_s_p5_0 = {
  109353. 2, 81,
  109354. _vq_lengthlist__16c0_s_p5_0,
  109355. 1, -531628032, 1611661312, 4, 0,
  109356. _vq_quantlist__16c0_s_p5_0,
  109357. NULL,
  109358. &_vq_auxt__16c0_s_p5_0,
  109359. NULL,
  109360. 0
  109361. };
  109362. static long _vq_quantlist__16c0_s_p6_0[] = {
  109363. 8,
  109364. 7,
  109365. 9,
  109366. 6,
  109367. 10,
  109368. 5,
  109369. 11,
  109370. 4,
  109371. 12,
  109372. 3,
  109373. 13,
  109374. 2,
  109375. 14,
  109376. 1,
  109377. 15,
  109378. 0,
  109379. 16,
  109380. };
  109381. static long _vq_lengthlist__16c0_s_p6_0[] = {
  109382. 1, 3, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  109383. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,11,
  109384. 11,11, 0, 0, 0, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,
  109385. 11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  109386. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  109387. 10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  109388. 11,11,12,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  109389. 10,11,11,12,12,12,13, 0, 0, 0, 9, 9, 9, 9,10,10,
  109390. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,10,10,10,
  109391. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  109392. 10,10,11,11,12,12,13,13,13,13, 0, 0, 0, 0, 0, 9,
  109393. 9,10,10,11,11,12,12,13,13,13,14, 0, 0, 0, 0, 0,
  109394. 10,10,10,11,11,11,12,12,13,13,13,14, 0, 0, 0, 0,
  109395. 0, 0, 0,10,10,11,11,12,12,13,13,14,14, 0, 0, 0,
  109396. 0, 0, 0, 0,11,11,12,12,13,13,13,13,14,14, 0, 0,
  109397. 0, 0, 0, 0, 0,11,11,12,12,12,13,13,14,15,14, 0,
  109398. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,14,14,15,
  109399. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,14,13,14,
  109400. 14,
  109401. };
  109402. static float _vq_quantthresh__16c0_s_p6_0[] = {
  109403. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  109404. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  109405. };
  109406. static long _vq_quantmap__16c0_s_p6_0[] = {
  109407. 15, 13, 11, 9, 7, 5, 3, 1,
  109408. 0, 2, 4, 6, 8, 10, 12, 14,
  109409. 16,
  109410. };
  109411. static encode_aux_threshmatch _vq_auxt__16c0_s_p6_0 = {
  109412. _vq_quantthresh__16c0_s_p6_0,
  109413. _vq_quantmap__16c0_s_p6_0,
  109414. 17,
  109415. 17
  109416. };
  109417. static static_codebook _16c0_s_p6_0 = {
  109418. 2, 289,
  109419. _vq_lengthlist__16c0_s_p6_0,
  109420. 1, -529530880, 1611661312, 5, 0,
  109421. _vq_quantlist__16c0_s_p6_0,
  109422. NULL,
  109423. &_vq_auxt__16c0_s_p6_0,
  109424. NULL,
  109425. 0
  109426. };
  109427. static long _vq_quantlist__16c0_s_p7_0[] = {
  109428. 1,
  109429. 0,
  109430. 2,
  109431. };
  109432. static long _vq_lengthlist__16c0_s_p7_0[] = {
  109433. 1, 4, 4, 6, 6, 6, 7, 6, 6, 4, 7, 7,11,10,10,11,
  109434. 11,10, 4, 7, 7,10,10,10,11,10,10, 6,10,10,11,11,
  109435. 11,11,11,10, 6, 9, 9,11,12,12,11, 9, 9, 6, 9,10,
  109436. 11,12,12,11, 9,10, 7,11,11,11,11,11,12,13,12, 6,
  109437. 9,10,11,10,10,12,13,13, 6,10, 9,11,10,10,11,12,
  109438. 13,
  109439. };
  109440. static float _vq_quantthresh__16c0_s_p7_0[] = {
  109441. -5.5, 5.5,
  109442. };
  109443. static long _vq_quantmap__16c0_s_p7_0[] = {
  109444. 1, 0, 2,
  109445. };
  109446. static encode_aux_threshmatch _vq_auxt__16c0_s_p7_0 = {
  109447. _vq_quantthresh__16c0_s_p7_0,
  109448. _vq_quantmap__16c0_s_p7_0,
  109449. 3,
  109450. 3
  109451. };
  109452. static static_codebook _16c0_s_p7_0 = {
  109453. 4, 81,
  109454. _vq_lengthlist__16c0_s_p7_0,
  109455. 1, -529137664, 1618345984, 2, 0,
  109456. _vq_quantlist__16c0_s_p7_0,
  109457. NULL,
  109458. &_vq_auxt__16c0_s_p7_0,
  109459. NULL,
  109460. 0
  109461. };
  109462. static long _vq_quantlist__16c0_s_p7_1[] = {
  109463. 5,
  109464. 4,
  109465. 6,
  109466. 3,
  109467. 7,
  109468. 2,
  109469. 8,
  109470. 1,
  109471. 9,
  109472. 0,
  109473. 10,
  109474. };
  109475. static long _vq_lengthlist__16c0_s_p7_1[] = {
  109476. 1, 3, 4, 6, 6, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7,
  109477. 8, 8, 8, 9, 9, 9,10,10,10, 6, 7, 8, 8, 8, 8, 9,
  109478. 8,10,10,10, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10, 7,
  109479. 7, 8, 8, 9, 9, 8, 9,10,10,10, 8, 8, 9, 9, 9, 9,
  109480. 9, 9,11,11,11, 8, 8, 9, 9, 9, 9, 9,10,10,11,11,
  109481. 9, 9, 9, 9, 9, 9, 9,10,11,11,11,10,11, 9, 9, 9,
  109482. 9,10, 9,11,11,11,10,11,10,10, 9, 9,10,10,11,11,
  109483. 11,11,11, 9, 9, 9, 9,10,10,
  109484. };
  109485. static float _vq_quantthresh__16c0_s_p7_1[] = {
  109486. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  109487. 3.5, 4.5,
  109488. };
  109489. static long _vq_quantmap__16c0_s_p7_1[] = {
  109490. 9, 7, 5, 3, 1, 0, 2, 4,
  109491. 6, 8, 10,
  109492. };
  109493. static encode_aux_threshmatch _vq_auxt__16c0_s_p7_1 = {
  109494. _vq_quantthresh__16c0_s_p7_1,
  109495. _vq_quantmap__16c0_s_p7_1,
  109496. 11,
  109497. 11
  109498. };
  109499. static static_codebook _16c0_s_p7_1 = {
  109500. 2, 121,
  109501. _vq_lengthlist__16c0_s_p7_1,
  109502. 1, -531365888, 1611661312, 4, 0,
  109503. _vq_quantlist__16c0_s_p7_1,
  109504. NULL,
  109505. &_vq_auxt__16c0_s_p7_1,
  109506. NULL,
  109507. 0
  109508. };
  109509. static long _vq_quantlist__16c0_s_p8_0[] = {
  109510. 6,
  109511. 5,
  109512. 7,
  109513. 4,
  109514. 8,
  109515. 3,
  109516. 9,
  109517. 2,
  109518. 10,
  109519. 1,
  109520. 11,
  109521. 0,
  109522. 12,
  109523. };
  109524. static long _vq_lengthlist__16c0_s_p8_0[] = {
  109525. 1, 4, 4, 7, 7, 7, 7, 7, 6, 8, 8,10,10, 6, 5, 6,
  109526. 8, 8, 8, 8, 8, 8, 8, 9,10,10, 7, 6, 6, 8, 8, 8,
  109527. 8, 8, 8, 8, 8,10,10, 0, 8, 8, 8, 8, 9, 8, 9, 9,
  109528. 9,10,10,10, 0, 9, 8, 8, 8, 9, 9, 8, 8, 9, 9,10,
  109529. 10, 0,12,11, 8, 8, 9, 9, 9, 9,10,10,11,10, 0,12,
  109530. 13, 8, 8, 9,10, 9, 9,11,11,11,12, 0, 0, 0, 8, 8,
  109531. 8, 8,10, 9,12,13,12,14, 0, 0, 0, 8, 8, 8, 9,10,
  109532. 10,12,12,13,14, 0, 0, 0,13,13, 9, 9,11,11, 0, 0,
  109533. 14, 0, 0, 0, 0,14,14,10,10,12,11,12,14,14,14, 0,
  109534. 0, 0, 0, 0,11,11,13,13,14,13,14,14, 0, 0, 0, 0,
  109535. 0,12,13,13,12,13,14,14,14,
  109536. };
  109537. static float _vq_quantthresh__16c0_s_p8_0[] = {
  109538. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  109539. 12.5, 17.5, 22.5, 27.5,
  109540. };
  109541. static long _vq_quantmap__16c0_s_p8_0[] = {
  109542. 11, 9, 7, 5, 3, 1, 0, 2,
  109543. 4, 6, 8, 10, 12,
  109544. };
  109545. static encode_aux_threshmatch _vq_auxt__16c0_s_p8_0 = {
  109546. _vq_quantthresh__16c0_s_p8_0,
  109547. _vq_quantmap__16c0_s_p8_0,
  109548. 13,
  109549. 13
  109550. };
  109551. static static_codebook _16c0_s_p8_0 = {
  109552. 2, 169,
  109553. _vq_lengthlist__16c0_s_p8_0,
  109554. 1, -526516224, 1616117760, 4, 0,
  109555. _vq_quantlist__16c0_s_p8_0,
  109556. NULL,
  109557. &_vq_auxt__16c0_s_p8_0,
  109558. NULL,
  109559. 0
  109560. };
  109561. static long _vq_quantlist__16c0_s_p8_1[] = {
  109562. 2,
  109563. 1,
  109564. 3,
  109565. 0,
  109566. 4,
  109567. };
  109568. static long _vq_lengthlist__16c0_s_p8_1[] = {
  109569. 1, 4, 3, 5, 5, 7, 7, 7, 6, 6, 7, 7, 7, 5, 5, 7,
  109570. 7, 7, 6, 6, 7, 7, 7, 6, 6,
  109571. };
  109572. static float _vq_quantthresh__16c0_s_p8_1[] = {
  109573. -1.5, -0.5, 0.5, 1.5,
  109574. };
  109575. static long _vq_quantmap__16c0_s_p8_1[] = {
  109576. 3, 1, 0, 2, 4,
  109577. };
  109578. static encode_aux_threshmatch _vq_auxt__16c0_s_p8_1 = {
  109579. _vq_quantthresh__16c0_s_p8_1,
  109580. _vq_quantmap__16c0_s_p8_1,
  109581. 5,
  109582. 5
  109583. };
  109584. static static_codebook _16c0_s_p8_1 = {
  109585. 2, 25,
  109586. _vq_lengthlist__16c0_s_p8_1,
  109587. 1, -533725184, 1611661312, 3, 0,
  109588. _vq_quantlist__16c0_s_p8_1,
  109589. NULL,
  109590. &_vq_auxt__16c0_s_p8_1,
  109591. NULL,
  109592. 0
  109593. };
  109594. static long _vq_quantlist__16c0_s_p9_0[] = {
  109595. 1,
  109596. 0,
  109597. 2,
  109598. };
  109599. static long _vq_lengthlist__16c0_s_p9_0[] = {
  109600. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  109601. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  109602. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  109603. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  109604. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  109605. 7,
  109606. };
  109607. static float _vq_quantthresh__16c0_s_p9_0[] = {
  109608. -157.5, 157.5,
  109609. };
  109610. static long _vq_quantmap__16c0_s_p9_0[] = {
  109611. 1, 0, 2,
  109612. };
  109613. static encode_aux_threshmatch _vq_auxt__16c0_s_p9_0 = {
  109614. _vq_quantthresh__16c0_s_p9_0,
  109615. _vq_quantmap__16c0_s_p9_0,
  109616. 3,
  109617. 3
  109618. };
  109619. static static_codebook _16c0_s_p9_0 = {
  109620. 4, 81,
  109621. _vq_lengthlist__16c0_s_p9_0,
  109622. 1, -518803456, 1628680192, 2, 0,
  109623. _vq_quantlist__16c0_s_p9_0,
  109624. NULL,
  109625. &_vq_auxt__16c0_s_p9_0,
  109626. NULL,
  109627. 0
  109628. };
  109629. static long _vq_quantlist__16c0_s_p9_1[] = {
  109630. 7,
  109631. 6,
  109632. 8,
  109633. 5,
  109634. 9,
  109635. 4,
  109636. 10,
  109637. 3,
  109638. 11,
  109639. 2,
  109640. 12,
  109641. 1,
  109642. 13,
  109643. 0,
  109644. 14,
  109645. };
  109646. static long _vq_lengthlist__16c0_s_p9_1[] = {
  109647. 1, 5, 5, 5, 5, 9,11,11,10,10,10,10,10,10,10, 7,
  109648. 6, 6, 6, 6,10,10,10,10,10,10,10,10,10,10, 7, 6,
  109649. 6, 6, 6,10, 9,10,10,10,10,10,10,10,10,10, 7, 7,
  109650. 8, 9,10,10,10,10,10,10,10,10,10,10,10, 8, 7,10,
  109651. 10,10, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109652. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109653. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109654. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109655. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109656. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109657. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109658. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109659. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109660. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109661. 10,
  109662. };
  109663. static float _vq_quantthresh__16c0_s_p9_1[] = {
  109664. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  109665. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  109666. };
  109667. static long _vq_quantmap__16c0_s_p9_1[] = {
  109668. 13, 11, 9, 7, 5, 3, 1, 0,
  109669. 2, 4, 6, 8, 10, 12, 14,
  109670. };
  109671. static encode_aux_threshmatch _vq_auxt__16c0_s_p9_1 = {
  109672. _vq_quantthresh__16c0_s_p9_1,
  109673. _vq_quantmap__16c0_s_p9_1,
  109674. 15,
  109675. 15
  109676. };
  109677. static static_codebook _16c0_s_p9_1 = {
  109678. 2, 225,
  109679. _vq_lengthlist__16c0_s_p9_1,
  109680. 1, -520986624, 1620377600, 4, 0,
  109681. _vq_quantlist__16c0_s_p9_1,
  109682. NULL,
  109683. &_vq_auxt__16c0_s_p9_1,
  109684. NULL,
  109685. 0
  109686. };
  109687. static long _vq_quantlist__16c0_s_p9_2[] = {
  109688. 10,
  109689. 9,
  109690. 11,
  109691. 8,
  109692. 12,
  109693. 7,
  109694. 13,
  109695. 6,
  109696. 14,
  109697. 5,
  109698. 15,
  109699. 4,
  109700. 16,
  109701. 3,
  109702. 17,
  109703. 2,
  109704. 18,
  109705. 1,
  109706. 19,
  109707. 0,
  109708. 20,
  109709. };
  109710. static long _vq_lengthlist__16c0_s_p9_2[] = {
  109711. 1, 5, 5, 7, 8, 8, 7, 9, 9, 9,12,12,11,12,12,10,
  109712. 10,11,12,12,12,11,12,12, 8, 9, 8, 7, 9,10,10,11,
  109713. 11,10,11,12,10,12,10,12,12,12,11,12,11, 9, 8, 8,
  109714. 9,10, 9, 8, 9,10,12,12,11,11,12,11,10,11,12,11,
  109715. 12,12, 8, 9, 9, 9,10,11,12,11,12,11,11,11,11,12,
  109716. 12,11,11,12,12,11,11, 9, 9, 8, 9, 9,11, 9, 9,10,
  109717. 9,11,11,11,11,12,11,11,10,12,12,12, 9,12,11,10,
  109718. 11,11,11,11,12,12,12,11,11,11,12,10,12,12,12,10,
  109719. 10, 9,10, 9,10,10, 9, 9, 9,10,10,12,10,11,11, 9,
  109720. 11,11,10,11,11,11,10,10,10, 9, 9,10,10, 9, 9,10,
  109721. 11,11,10,11,10,11,10,11,11,10,11,11,11,10, 9,10,
  109722. 10, 9,10, 9, 9,11, 9, 9,11,10,10,11,11,10,10,11,
  109723. 10,11, 8, 9,11,11,10, 9,10,11,11,10,11,11,10,10,
  109724. 10,11,10, 9,10,10,11, 9,10,10, 9,11,10,10,10,10,
  109725. 11,10,11,11, 9,11,10,11,10,10,11,11,10,10,10, 9,
  109726. 10,10,11,11,11, 9,10,10,10,10,10,11,10,10,10, 9,
  109727. 10,10,11,10,10,10,10,10, 9,10,11,10,10,10,10,11,
  109728. 11,11,10,10,10,10,10,11,10,11,10,11,10,10,10, 9,
  109729. 11,11,10,10,10,11,11,10,10,10,10,10,10,10,10,11,
  109730. 11, 9,10,10,10,11,10,11,10,10,10,11, 9,10,11,10,
  109731. 11,10,10, 9,10,10,10,11,10,11,10,10,10,10,10,11,
  109732. 11,10,11,11,10,10,11,11,10, 9, 9,10,10,10,10,10,
  109733. 9,11, 9,10,10,10,11,11,10,10,10,10,11,11,11,10,
  109734. 9, 9,10,10,11,10,10,10,10,10,11,11,11,10,10,10,
  109735. 11,11,11, 9,10,10,10,10, 9,10, 9,10,11,10,11,10,
  109736. 10,11,11,10,11,11,11,11,11,10,11,10,10,10, 9,11,
  109737. 11,10,11,11,11,11,11,11,11,11,11,10,11,10,10,10,
  109738. 10,11,10,10,11, 9,10,10,10,
  109739. };
  109740. static float _vq_quantthresh__16c0_s_p9_2[] = {
  109741. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  109742. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  109743. 6.5, 7.5, 8.5, 9.5,
  109744. };
  109745. static long _vq_quantmap__16c0_s_p9_2[] = {
  109746. 19, 17, 15, 13, 11, 9, 7, 5,
  109747. 3, 1, 0, 2, 4, 6, 8, 10,
  109748. 12, 14, 16, 18, 20,
  109749. };
  109750. static encode_aux_threshmatch _vq_auxt__16c0_s_p9_2 = {
  109751. _vq_quantthresh__16c0_s_p9_2,
  109752. _vq_quantmap__16c0_s_p9_2,
  109753. 21,
  109754. 21
  109755. };
  109756. static static_codebook _16c0_s_p9_2 = {
  109757. 2, 441,
  109758. _vq_lengthlist__16c0_s_p9_2,
  109759. 1, -529268736, 1611661312, 5, 0,
  109760. _vq_quantlist__16c0_s_p9_2,
  109761. NULL,
  109762. &_vq_auxt__16c0_s_p9_2,
  109763. NULL,
  109764. 0
  109765. };
  109766. static long _huff_lengthlist__16c0_s_single[] = {
  109767. 3, 4,19, 7, 9, 7, 8,11, 9,12, 4, 1,19, 6, 7, 7,
  109768. 8,10,11,13,18,18,18,18,18,18,18,18,18,18, 8, 6,
  109769. 18, 8, 9, 9,11,12,14,18, 9, 6,18, 9, 7, 8, 9,11,
  109770. 12,18, 7, 6,18, 8, 7, 7, 7, 9,11,17, 8, 8,18, 9,
  109771. 7, 6, 6, 8,11,17,10,10,18,12, 9, 8, 7, 9,12,18,
  109772. 13,15,18,15,13,11,10,11,15,18,14,18,18,18,18,18,
  109773. 16,16,18,18,
  109774. };
  109775. static static_codebook _huff_book__16c0_s_single = {
  109776. 2, 100,
  109777. _huff_lengthlist__16c0_s_single,
  109778. 0, 0, 0, 0, 0,
  109779. NULL,
  109780. NULL,
  109781. NULL,
  109782. NULL,
  109783. 0
  109784. };
  109785. static long _huff_lengthlist__16c1_s_long[] = {
  109786. 2, 5,20, 7,10, 7, 8,10,11,11, 4, 2,20, 5, 8, 6,
  109787. 7, 9,10,10,20,20,20,20,19,19,19,19,19,19, 7, 5,
  109788. 19, 6,10, 7, 9,11,13,17,11, 8,19,10, 7, 7, 8,10,
  109789. 11,15, 7, 5,19, 7, 7, 5, 6, 9,11,16, 7, 6,19, 8,
  109790. 7, 6, 6, 7, 9,13, 9, 9,19,11, 9, 8, 6, 7, 8,13,
  109791. 12,14,19,16,13,10, 9, 8, 9,13,14,17,19,18,18,17,
  109792. 12,11,11,13,
  109793. };
  109794. static static_codebook _huff_book__16c1_s_long = {
  109795. 2, 100,
  109796. _huff_lengthlist__16c1_s_long,
  109797. 0, 0, 0, 0, 0,
  109798. NULL,
  109799. NULL,
  109800. NULL,
  109801. NULL,
  109802. 0
  109803. };
  109804. static long _vq_quantlist__16c1_s_p1_0[] = {
  109805. 1,
  109806. 0,
  109807. 2,
  109808. };
  109809. static long _vq_lengthlist__16c1_s_p1_0[] = {
  109810. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  109811. 0, 0, 5, 7, 7, 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, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  109816. 0, 0, 0, 7, 8, 9, 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, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  109821. 0, 0, 0, 0, 7, 9, 9, 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, 5, 8, 7, 0, 0, 0, 0,
  109856. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 7, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  109861. 0, 0, 0, 9, 9,11, 0, 0, 0, 0, 0, 0, 9,11,10, 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, 7, 9, 9, 0, 0,
  109866. 0, 0, 0, 0, 8,11, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  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, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  109902. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  109907. 0, 0, 0, 0, 0, 8, 9,11, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  109912. 0, 0, 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0, 0,
  109913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  110221. };
  110222. static float _vq_quantthresh__16c1_s_p1_0[] = {
  110223. -0.5, 0.5,
  110224. };
  110225. static long _vq_quantmap__16c1_s_p1_0[] = {
  110226. 1, 0, 2,
  110227. };
  110228. static encode_aux_threshmatch _vq_auxt__16c1_s_p1_0 = {
  110229. _vq_quantthresh__16c1_s_p1_0,
  110230. _vq_quantmap__16c1_s_p1_0,
  110231. 3,
  110232. 3
  110233. };
  110234. static static_codebook _16c1_s_p1_0 = {
  110235. 8, 6561,
  110236. _vq_lengthlist__16c1_s_p1_0,
  110237. 1, -535822336, 1611661312, 2, 0,
  110238. _vq_quantlist__16c1_s_p1_0,
  110239. NULL,
  110240. &_vq_auxt__16c1_s_p1_0,
  110241. NULL,
  110242. 0
  110243. };
  110244. static long _vq_quantlist__16c1_s_p2_0[] = {
  110245. 2,
  110246. 1,
  110247. 3,
  110248. 0,
  110249. 4,
  110250. };
  110251. static long _vq_lengthlist__16c1_s_p2_0[] = {
  110252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110291. 0,
  110292. };
  110293. static float _vq_quantthresh__16c1_s_p2_0[] = {
  110294. -1.5, -0.5, 0.5, 1.5,
  110295. };
  110296. static long _vq_quantmap__16c1_s_p2_0[] = {
  110297. 3, 1, 0, 2, 4,
  110298. };
  110299. static encode_aux_threshmatch _vq_auxt__16c1_s_p2_0 = {
  110300. _vq_quantthresh__16c1_s_p2_0,
  110301. _vq_quantmap__16c1_s_p2_0,
  110302. 5,
  110303. 5
  110304. };
  110305. static static_codebook _16c1_s_p2_0 = {
  110306. 4, 625,
  110307. _vq_lengthlist__16c1_s_p2_0,
  110308. 1, -533725184, 1611661312, 3, 0,
  110309. _vq_quantlist__16c1_s_p2_0,
  110310. NULL,
  110311. &_vq_auxt__16c1_s_p2_0,
  110312. NULL,
  110313. 0
  110314. };
  110315. static long _vq_quantlist__16c1_s_p3_0[] = {
  110316. 2,
  110317. 1,
  110318. 3,
  110319. 0,
  110320. 4,
  110321. };
  110322. static long _vq_lengthlist__16c1_s_p3_0[] = {
  110323. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  110325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110326. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7, 9, 9,
  110328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110329. 0, 0, 0, 0, 6, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  110330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110362. 0,
  110363. };
  110364. static float _vq_quantthresh__16c1_s_p3_0[] = {
  110365. -1.5, -0.5, 0.5, 1.5,
  110366. };
  110367. static long _vq_quantmap__16c1_s_p3_0[] = {
  110368. 3, 1, 0, 2, 4,
  110369. };
  110370. static encode_aux_threshmatch _vq_auxt__16c1_s_p3_0 = {
  110371. _vq_quantthresh__16c1_s_p3_0,
  110372. _vq_quantmap__16c1_s_p3_0,
  110373. 5,
  110374. 5
  110375. };
  110376. static static_codebook _16c1_s_p3_0 = {
  110377. 4, 625,
  110378. _vq_lengthlist__16c1_s_p3_0,
  110379. 1, -533725184, 1611661312, 3, 0,
  110380. _vq_quantlist__16c1_s_p3_0,
  110381. NULL,
  110382. &_vq_auxt__16c1_s_p3_0,
  110383. NULL,
  110384. 0
  110385. };
  110386. static long _vq_quantlist__16c1_s_p4_0[] = {
  110387. 4,
  110388. 3,
  110389. 5,
  110390. 2,
  110391. 6,
  110392. 1,
  110393. 7,
  110394. 0,
  110395. 8,
  110396. };
  110397. static long _vq_lengthlist__16c1_s_p4_0[] = {
  110398. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  110399. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  110400. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  110401. 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 9, 0, 0, 0, 0, 0,
  110402. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110403. 0,
  110404. };
  110405. static float _vq_quantthresh__16c1_s_p4_0[] = {
  110406. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  110407. };
  110408. static long _vq_quantmap__16c1_s_p4_0[] = {
  110409. 7, 5, 3, 1, 0, 2, 4, 6,
  110410. 8,
  110411. };
  110412. static encode_aux_threshmatch _vq_auxt__16c1_s_p4_0 = {
  110413. _vq_quantthresh__16c1_s_p4_0,
  110414. _vq_quantmap__16c1_s_p4_0,
  110415. 9,
  110416. 9
  110417. };
  110418. static static_codebook _16c1_s_p4_0 = {
  110419. 2, 81,
  110420. _vq_lengthlist__16c1_s_p4_0,
  110421. 1, -531628032, 1611661312, 4, 0,
  110422. _vq_quantlist__16c1_s_p4_0,
  110423. NULL,
  110424. &_vq_auxt__16c1_s_p4_0,
  110425. NULL,
  110426. 0
  110427. };
  110428. static long _vq_quantlist__16c1_s_p5_0[] = {
  110429. 4,
  110430. 3,
  110431. 5,
  110432. 2,
  110433. 6,
  110434. 1,
  110435. 7,
  110436. 0,
  110437. 8,
  110438. };
  110439. static long _vq_lengthlist__16c1_s_p5_0[] = {
  110440. 1, 3, 3, 5, 5, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  110441. 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0, 8, 8,
  110442. 8, 8, 9, 9, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  110443. 9, 9, 8, 8,10,10, 0, 0, 0, 9, 9, 8, 8,10,10, 0,
  110444. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  110445. 10,
  110446. };
  110447. static float _vq_quantthresh__16c1_s_p5_0[] = {
  110448. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  110449. };
  110450. static long _vq_quantmap__16c1_s_p5_0[] = {
  110451. 7, 5, 3, 1, 0, 2, 4, 6,
  110452. 8,
  110453. };
  110454. static encode_aux_threshmatch _vq_auxt__16c1_s_p5_0 = {
  110455. _vq_quantthresh__16c1_s_p5_0,
  110456. _vq_quantmap__16c1_s_p5_0,
  110457. 9,
  110458. 9
  110459. };
  110460. static static_codebook _16c1_s_p5_0 = {
  110461. 2, 81,
  110462. _vq_lengthlist__16c1_s_p5_0,
  110463. 1, -531628032, 1611661312, 4, 0,
  110464. _vq_quantlist__16c1_s_p5_0,
  110465. NULL,
  110466. &_vq_auxt__16c1_s_p5_0,
  110467. NULL,
  110468. 0
  110469. };
  110470. static long _vq_quantlist__16c1_s_p6_0[] = {
  110471. 8,
  110472. 7,
  110473. 9,
  110474. 6,
  110475. 10,
  110476. 5,
  110477. 11,
  110478. 4,
  110479. 12,
  110480. 3,
  110481. 13,
  110482. 2,
  110483. 14,
  110484. 1,
  110485. 15,
  110486. 0,
  110487. 16,
  110488. };
  110489. static long _vq_lengthlist__16c1_s_p6_0[] = {
  110490. 1, 3, 3, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,11,12,
  110491. 12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  110492. 12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  110493. 11,12,12, 0, 0, 0, 8, 8, 8, 9,10, 9,10,10,10,10,
  110494. 11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,11,
  110495. 11,11,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  110496. 11,11,12,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  110497. 10,11,11,12,12,13,13, 0, 0, 0, 9, 9, 9, 9,10,10,
  110498. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,10,
  110499. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  110500. 10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0, 0, 9,
  110501. 9,10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0, 0,
  110502. 10,10,11,10,11,11,12,12,13,13,13,13, 0, 0, 0, 0,
  110503. 0, 0, 0,10,10,11,11,12,12,13,13,13,13, 0, 0, 0,
  110504. 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14, 0, 0,
  110505. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14, 0,
  110506. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  110507. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,13,13,14,
  110508. 14,
  110509. };
  110510. static float _vq_quantthresh__16c1_s_p6_0[] = {
  110511. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  110512. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  110513. };
  110514. static long _vq_quantmap__16c1_s_p6_0[] = {
  110515. 15, 13, 11, 9, 7, 5, 3, 1,
  110516. 0, 2, 4, 6, 8, 10, 12, 14,
  110517. 16,
  110518. };
  110519. static encode_aux_threshmatch _vq_auxt__16c1_s_p6_0 = {
  110520. _vq_quantthresh__16c1_s_p6_0,
  110521. _vq_quantmap__16c1_s_p6_0,
  110522. 17,
  110523. 17
  110524. };
  110525. static static_codebook _16c1_s_p6_0 = {
  110526. 2, 289,
  110527. _vq_lengthlist__16c1_s_p6_0,
  110528. 1, -529530880, 1611661312, 5, 0,
  110529. _vq_quantlist__16c1_s_p6_0,
  110530. NULL,
  110531. &_vq_auxt__16c1_s_p6_0,
  110532. NULL,
  110533. 0
  110534. };
  110535. static long _vq_quantlist__16c1_s_p7_0[] = {
  110536. 1,
  110537. 0,
  110538. 2,
  110539. };
  110540. static long _vq_lengthlist__16c1_s_p7_0[] = {
  110541. 1, 4, 4, 6, 6, 6, 7, 6, 6, 4, 7, 7,10, 9,10,10,
  110542. 10, 9, 4, 7, 7,10,10,10,11,10,10, 6,10,10,11,11,
  110543. 11,11,10,10, 6,10, 9,11,11,11,11,10,10, 6,10,10,
  110544. 11,11,11,11,10,10, 7,11,11,11,11,11,12,12,11, 6,
  110545. 10,10,11,10,10,11,11,11, 6,10,10,10,11,10,11,11,
  110546. 11,
  110547. };
  110548. static float _vq_quantthresh__16c1_s_p7_0[] = {
  110549. -5.5, 5.5,
  110550. };
  110551. static long _vq_quantmap__16c1_s_p7_0[] = {
  110552. 1, 0, 2,
  110553. };
  110554. static encode_aux_threshmatch _vq_auxt__16c1_s_p7_0 = {
  110555. _vq_quantthresh__16c1_s_p7_0,
  110556. _vq_quantmap__16c1_s_p7_0,
  110557. 3,
  110558. 3
  110559. };
  110560. static static_codebook _16c1_s_p7_0 = {
  110561. 4, 81,
  110562. _vq_lengthlist__16c1_s_p7_0,
  110563. 1, -529137664, 1618345984, 2, 0,
  110564. _vq_quantlist__16c1_s_p7_0,
  110565. NULL,
  110566. &_vq_auxt__16c1_s_p7_0,
  110567. NULL,
  110568. 0
  110569. };
  110570. static long _vq_quantlist__16c1_s_p7_1[] = {
  110571. 5,
  110572. 4,
  110573. 6,
  110574. 3,
  110575. 7,
  110576. 2,
  110577. 8,
  110578. 1,
  110579. 9,
  110580. 0,
  110581. 10,
  110582. };
  110583. static long _vq_lengthlist__16c1_s_p7_1[] = {
  110584. 2, 3, 3, 5, 6, 7, 7, 7, 7, 8, 8,10,10,10, 6, 6,
  110585. 7, 7, 8, 8, 8, 8,10,10,10, 6, 6, 7, 7, 8, 8, 8,
  110586. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  110587. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  110588. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  110589. 8, 8, 8, 8, 8, 8, 9, 9,10,10,10,10,10, 8, 8, 8,
  110590. 8, 9, 9,10,10,10,10,10, 9, 9, 8, 8, 9, 9,10,10,
  110591. 10,10,10, 8, 8, 8, 8, 9, 9,
  110592. };
  110593. static float _vq_quantthresh__16c1_s_p7_1[] = {
  110594. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  110595. 3.5, 4.5,
  110596. };
  110597. static long _vq_quantmap__16c1_s_p7_1[] = {
  110598. 9, 7, 5, 3, 1, 0, 2, 4,
  110599. 6, 8, 10,
  110600. };
  110601. static encode_aux_threshmatch _vq_auxt__16c1_s_p7_1 = {
  110602. _vq_quantthresh__16c1_s_p7_1,
  110603. _vq_quantmap__16c1_s_p7_1,
  110604. 11,
  110605. 11
  110606. };
  110607. static static_codebook _16c1_s_p7_1 = {
  110608. 2, 121,
  110609. _vq_lengthlist__16c1_s_p7_1,
  110610. 1, -531365888, 1611661312, 4, 0,
  110611. _vq_quantlist__16c1_s_p7_1,
  110612. NULL,
  110613. &_vq_auxt__16c1_s_p7_1,
  110614. NULL,
  110615. 0
  110616. };
  110617. static long _vq_quantlist__16c1_s_p8_0[] = {
  110618. 6,
  110619. 5,
  110620. 7,
  110621. 4,
  110622. 8,
  110623. 3,
  110624. 9,
  110625. 2,
  110626. 10,
  110627. 1,
  110628. 11,
  110629. 0,
  110630. 12,
  110631. };
  110632. static long _vq_lengthlist__16c1_s_p8_0[] = {
  110633. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 6, 5, 5,
  110634. 7, 8, 8, 9, 8, 8, 9, 9,10,11, 6, 5, 5, 8, 8, 9,
  110635. 9, 8, 8, 9,10,10,11, 0, 8, 8, 8, 9, 9, 9, 9, 9,
  110636. 10,10,11,11, 0, 9, 9, 9, 8, 9, 9, 9, 9,10,10,11,
  110637. 11, 0,13,13, 9, 9,10,10,10,10,11,11,12,12, 0,14,
  110638. 13, 9, 9,10,10,10,10,11,11,12,12, 0, 0, 0,10,10,
  110639. 9, 9,11,11,12,12,13,12, 0, 0, 0,10,10, 9, 9,10,
  110640. 10,12,12,13,13, 0, 0, 0,13,14,11,10,11,11,12,12,
  110641. 13,14, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  110642. 0, 0, 0, 0,12,12,12,12,13,13,14,15, 0, 0, 0, 0,
  110643. 0,12,12,12,12,13,13,14,15,
  110644. };
  110645. static float _vq_quantthresh__16c1_s_p8_0[] = {
  110646. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  110647. 12.5, 17.5, 22.5, 27.5,
  110648. };
  110649. static long _vq_quantmap__16c1_s_p8_0[] = {
  110650. 11, 9, 7, 5, 3, 1, 0, 2,
  110651. 4, 6, 8, 10, 12,
  110652. };
  110653. static encode_aux_threshmatch _vq_auxt__16c1_s_p8_0 = {
  110654. _vq_quantthresh__16c1_s_p8_0,
  110655. _vq_quantmap__16c1_s_p8_0,
  110656. 13,
  110657. 13
  110658. };
  110659. static static_codebook _16c1_s_p8_0 = {
  110660. 2, 169,
  110661. _vq_lengthlist__16c1_s_p8_0,
  110662. 1, -526516224, 1616117760, 4, 0,
  110663. _vq_quantlist__16c1_s_p8_0,
  110664. NULL,
  110665. &_vq_auxt__16c1_s_p8_0,
  110666. NULL,
  110667. 0
  110668. };
  110669. static long _vq_quantlist__16c1_s_p8_1[] = {
  110670. 2,
  110671. 1,
  110672. 3,
  110673. 0,
  110674. 4,
  110675. };
  110676. static long _vq_lengthlist__16c1_s_p8_1[] = {
  110677. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  110678. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  110679. };
  110680. static float _vq_quantthresh__16c1_s_p8_1[] = {
  110681. -1.5, -0.5, 0.5, 1.5,
  110682. };
  110683. static long _vq_quantmap__16c1_s_p8_1[] = {
  110684. 3, 1, 0, 2, 4,
  110685. };
  110686. static encode_aux_threshmatch _vq_auxt__16c1_s_p8_1 = {
  110687. _vq_quantthresh__16c1_s_p8_1,
  110688. _vq_quantmap__16c1_s_p8_1,
  110689. 5,
  110690. 5
  110691. };
  110692. static static_codebook _16c1_s_p8_1 = {
  110693. 2, 25,
  110694. _vq_lengthlist__16c1_s_p8_1,
  110695. 1, -533725184, 1611661312, 3, 0,
  110696. _vq_quantlist__16c1_s_p8_1,
  110697. NULL,
  110698. &_vq_auxt__16c1_s_p8_1,
  110699. NULL,
  110700. 0
  110701. };
  110702. static long _vq_quantlist__16c1_s_p9_0[] = {
  110703. 6,
  110704. 5,
  110705. 7,
  110706. 4,
  110707. 8,
  110708. 3,
  110709. 9,
  110710. 2,
  110711. 10,
  110712. 1,
  110713. 11,
  110714. 0,
  110715. 12,
  110716. };
  110717. static long _vq_lengthlist__16c1_s_p9_0[] = {
  110718. 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110719. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110720. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110721. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110722. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110723. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110724. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110725. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110726. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110727. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110728. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110729. };
  110730. static float _vq_quantthresh__16c1_s_p9_0[] = {
  110731. -1732.5, -1417.5, -1102.5, -787.5, -472.5, -157.5, 157.5, 472.5,
  110732. 787.5, 1102.5, 1417.5, 1732.5,
  110733. };
  110734. static long _vq_quantmap__16c1_s_p9_0[] = {
  110735. 11, 9, 7, 5, 3, 1, 0, 2,
  110736. 4, 6, 8, 10, 12,
  110737. };
  110738. static encode_aux_threshmatch _vq_auxt__16c1_s_p9_0 = {
  110739. _vq_quantthresh__16c1_s_p9_0,
  110740. _vq_quantmap__16c1_s_p9_0,
  110741. 13,
  110742. 13
  110743. };
  110744. static static_codebook _16c1_s_p9_0 = {
  110745. 2, 169,
  110746. _vq_lengthlist__16c1_s_p9_0,
  110747. 1, -513964032, 1628680192, 4, 0,
  110748. _vq_quantlist__16c1_s_p9_0,
  110749. NULL,
  110750. &_vq_auxt__16c1_s_p9_0,
  110751. NULL,
  110752. 0
  110753. };
  110754. static long _vq_quantlist__16c1_s_p9_1[] = {
  110755. 7,
  110756. 6,
  110757. 8,
  110758. 5,
  110759. 9,
  110760. 4,
  110761. 10,
  110762. 3,
  110763. 11,
  110764. 2,
  110765. 12,
  110766. 1,
  110767. 13,
  110768. 0,
  110769. 14,
  110770. };
  110771. static long _vq_lengthlist__16c1_s_p9_1[] = {
  110772. 1, 4, 4, 4, 4, 8, 8,12,13,14,14,14,14,14,14, 6,
  110773. 6, 6, 6, 6,10, 9,14,14,14,14,14,14,14,14, 7, 6,
  110774. 5, 6, 6,10, 9,12,13,13,13,13,13,13,13,13, 7, 7,
  110775. 9, 9,11,11,12,13,13,13,13,13,13,13,13, 7, 7, 8,
  110776. 8,11,12,13,13,13,13,13,13,13,13,13,12,12,10,10,
  110777. 13,12,13,13,13,13,13,13,13,13,13,12,12,10,10,13,
  110778. 13,13,13,13,13,13,13,13,13,13,13,13,13,12,13,12,
  110779. 13,13,13,13,13,13,13,13,13,13,13,13,12,13,13,13,
  110780. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110781. 13,13,13,13,13,13,13,13,13,13,13,13,12,13,13,13,
  110782. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110783. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110784. 13,13,13,13,13,13,13,13,13,12,13,13,13,13,13,13,
  110785. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110786. 13,
  110787. };
  110788. static float _vq_quantthresh__16c1_s_p9_1[] = {
  110789. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  110790. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  110791. };
  110792. static long _vq_quantmap__16c1_s_p9_1[] = {
  110793. 13, 11, 9, 7, 5, 3, 1, 0,
  110794. 2, 4, 6, 8, 10, 12, 14,
  110795. };
  110796. static encode_aux_threshmatch _vq_auxt__16c1_s_p9_1 = {
  110797. _vq_quantthresh__16c1_s_p9_1,
  110798. _vq_quantmap__16c1_s_p9_1,
  110799. 15,
  110800. 15
  110801. };
  110802. static static_codebook _16c1_s_p9_1 = {
  110803. 2, 225,
  110804. _vq_lengthlist__16c1_s_p9_1,
  110805. 1, -520986624, 1620377600, 4, 0,
  110806. _vq_quantlist__16c1_s_p9_1,
  110807. NULL,
  110808. &_vq_auxt__16c1_s_p9_1,
  110809. NULL,
  110810. 0
  110811. };
  110812. static long _vq_quantlist__16c1_s_p9_2[] = {
  110813. 10,
  110814. 9,
  110815. 11,
  110816. 8,
  110817. 12,
  110818. 7,
  110819. 13,
  110820. 6,
  110821. 14,
  110822. 5,
  110823. 15,
  110824. 4,
  110825. 16,
  110826. 3,
  110827. 17,
  110828. 2,
  110829. 18,
  110830. 1,
  110831. 19,
  110832. 0,
  110833. 20,
  110834. };
  110835. static long _vq_lengthlist__16c1_s_p9_2[] = {
  110836. 1, 4, 4, 6, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9,10,
  110837. 10,10, 9,10,10,11,12,12, 8, 8, 8, 8, 9, 9, 9, 9,
  110838. 10,10,10,10,10,11,11,10,12,11,11,13,11, 7, 7, 8,
  110839. 8, 8, 8, 9, 9, 9,10,10,10,10, 9,10,10,11,11,12,
  110840. 11,11, 8, 8, 8, 8, 9, 9,10,10,10,10,11,11,11,11,
  110841. 11,11,11,12,11,12,12, 8, 8, 9, 9, 9, 9, 9,10,10,
  110842. 10,10,10,10,11,11,11,11,11,11,12,11, 9, 9, 9, 9,
  110843. 10,10,10,10,11,10,11,11,11,11,11,11,12,12,12,12,
  110844. 11, 9, 9, 9, 9,10,10,10,10,11,11,11,11,11,11,11,
  110845. 11,11,12,12,12,13, 9,10,10, 9,11,10,10,10,10,11,
  110846. 11,11,11,11,10,11,12,11,12,12,11,12,11,10, 9,10,
  110847. 10,11,10,11,11,11,11,11,11,11,11,11,12,12,11,12,
  110848. 12,12,10,10,10,11,10,11,11,11,11,11,11,11,11,11,
  110849. 11,11,12,13,12,12,11, 9,10,10,11,11,10,11,11,11,
  110850. 12,11,11,11,11,11,12,12,13,13,12,13,10,10,12,10,
  110851. 11,11,11,11,11,11,11,11,11,12,12,11,13,12,12,12,
  110852. 12,13,12,11,11,11,11,11,11,12,11,12,11,11,11,11,
  110853. 12,12,13,12,11,12,12,11,11,11,11,11,12,11,11,11,
  110854. 11,12,11,11,12,11,12,13,13,12,12,12,12,11,11,11,
  110855. 11,11,12,11,11,12,11,12,11,11,11,11,13,12,12,12,
  110856. 12,13,11,11,11,12,12,11,11,11,12,11,12,12,12,11,
  110857. 12,13,12,11,11,12,12,11,12,11,11,11,12,12,11,12,
  110858. 11,11,11,12,12,12,12,13,12,13,12,12,12,12,11,11,
  110859. 12,11,11,11,11,11,11,12,12,12,13,12,11,13,13,12,
  110860. 12,11,12,10,11,11,11,11,12,11,12,12,11,12,12,13,
  110861. 12,12,13,12,12,12,12,12,11,12,12,12,11,12,11,11,
  110862. 11,12,13,12,13,13,13,13,13,12,13,13,12,12,13,11,
  110863. 11,11,11,11,12,11,11,12,11,
  110864. };
  110865. static float _vq_quantthresh__16c1_s_p9_2[] = {
  110866. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  110867. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  110868. 6.5, 7.5, 8.5, 9.5,
  110869. };
  110870. static long _vq_quantmap__16c1_s_p9_2[] = {
  110871. 19, 17, 15, 13, 11, 9, 7, 5,
  110872. 3, 1, 0, 2, 4, 6, 8, 10,
  110873. 12, 14, 16, 18, 20,
  110874. };
  110875. static encode_aux_threshmatch _vq_auxt__16c1_s_p9_2 = {
  110876. _vq_quantthresh__16c1_s_p9_2,
  110877. _vq_quantmap__16c1_s_p9_2,
  110878. 21,
  110879. 21
  110880. };
  110881. static static_codebook _16c1_s_p9_2 = {
  110882. 2, 441,
  110883. _vq_lengthlist__16c1_s_p9_2,
  110884. 1, -529268736, 1611661312, 5, 0,
  110885. _vq_quantlist__16c1_s_p9_2,
  110886. NULL,
  110887. &_vq_auxt__16c1_s_p9_2,
  110888. NULL,
  110889. 0
  110890. };
  110891. static long _huff_lengthlist__16c1_s_short[] = {
  110892. 5, 6,17, 8,12, 9,10,10,12,13, 5, 2,17, 4, 9, 5,
  110893. 7, 8,11,13,16,16,16,16,16,16,16,16,16,16, 6, 4,
  110894. 16, 5,10, 5, 7,10,14,16,13, 9,16,11, 8, 7, 8, 9,
  110895. 13,16, 7, 4,16, 5, 7, 4, 6, 8,11,13, 8, 6,16, 7,
  110896. 8, 5, 5, 7, 9,13, 9, 8,16, 9, 8, 6, 6, 7, 9,13,
  110897. 11,11,16,10,10, 7, 7, 7, 9,13,13,13,16,13,13, 9,
  110898. 9, 9,10,13,
  110899. };
  110900. static static_codebook _huff_book__16c1_s_short = {
  110901. 2, 100,
  110902. _huff_lengthlist__16c1_s_short,
  110903. 0, 0, 0, 0, 0,
  110904. NULL,
  110905. NULL,
  110906. NULL,
  110907. NULL,
  110908. 0
  110909. };
  110910. static long _huff_lengthlist__16c2_s_long[] = {
  110911. 4, 7, 9, 9, 9, 8, 9,10,15,19, 5, 4, 5, 6, 7, 7,
  110912. 8, 9,14,16, 6, 5, 4, 5, 6, 7, 8,10,12,19, 7, 6,
  110913. 5, 4, 5, 6, 7, 9,11,18, 8, 7, 6, 5, 5, 5, 7, 9,
  110914. 10,17, 8, 7, 7, 5, 5, 5, 6, 7,12,18, 8, 8, 8, 7,
  110915. 7, 5, 5, 7,12,18, 8, 9,10, 9, 9, 7, 6, 7,12,17,
  110916. 14,18,16,16,15,12,11,10,12,18,15,17,18,18,18,15,
  110917. 14,14,16,18,
  110918. };
  110919. static static_codebook _huff_book__16c2_s_long = {
  110920. 2, 100,
  110921. _huff_lengthlist__16c2_s_long,
  110922. 0, 0, 0, 0, 0,
  110923. NULL,
  110924. NULL,
  110925. NULL,
  110926. NULL,
  110927. 0
  110928. };
  110929. static long _vq_quantlist__16c2_s_p1_0[] = {
  110930. 1,
  110931. 0,
  110932. 2,
  110933. };
  110934. static long _vq_lengthlist__16c2_s_p1_0[] = {
  110935. 1, 3, 3, 0, 0, 0, 0, 0, 0, 4, 5, 5, 0, 0, 0, 0,
  110936. 0, 0, 4, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110940. 0,
  110941. };
  110942. static float _vq_quantthresh__16c2_s_p1_0[] = {
  110943. -0.5, 0.5,
  110944. };
  110945. static long _vq_quantmap__16c2_s_p1_0[] = {
  110946. 1, 0, 2,
  110947. };
  110948. static encode_aux_threshmatch _vq_auxt__16c2_s_p1_0 = {
  110949. _vq_quantthresh__16c2_s_p1_0,
  110950. _vq_quantmap__16c2_s_p1_0,
  110951. 3,
  110952. 3
  110953. };
  110954. static static_codebook _16c2_s_p1_0 = {
  110955. 4, 81,
  110956. _vq_lengthlist__16c2_s_p1_0,
  110957. 1, -535822336, 1611661312, 2, 0,
  110958. _vq_quantlist__16c2_s_p1_0,
  110959. NULL,
  110960. &_vq_auxt__16c2_s_p1_0,
  110961. NULL,
  110962. 0
  110963. };
  110964. static long _vq_quantlist__16c2_s_p2_0[] = {
  110965. 2,
  110966. 1,
  110967. 3,
  110968. 0,
  110969. 4,
  110970. };
  110971. static long _vq_lengthlist__16c2_s_p2_0[] = {
  110972. 2, 4, 3, 7, 7, 0, 0, 0, 7, 8, 0, 0, 0, 8, 8, 0,
  110973. 0, 0, 8, 8, 0, 0, 0, 8, 8, 4, 5, 4, 8, 8, 0, 0,
  110974. 0, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 9, 9, 0, 0, 0,
  110975. 9, 9, 4, 4, 5, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 8,
  110976. 8, 0, 0, 0, 9, 9, 0, 0, 0, 9, 9, 7, 8, 8,10,10,
  110977. 0, 0, 0,12,11, 0, 0, 0,11,11, 0, 0, 0,14,13, 0,
  110978. 0, 0,14,13, 7, 8, 8, 9,10, 0, 0, 0,11,12, 0, 0,
  110979. 0,11,11, 0, 0, 0,14,14, 0, 0, 0,13,14, 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, 8, 8, 8,11,11, 0, 0, 0,
  110985. 11,11, 0, 0, 0,12,11, 0, 0, 0,12,12, 0, 0, 0,13,
  110986. 13, 8, 8, 8,11,11, 0, 0, 0,11,11, 0, 0, 0,11,12,
  110987. 0, 0, 0,12,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0,
  110988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110992. 0, 0, 0, 0, 0, 8, 8, 8,12,11, 0, 0, 0,12,11, 0,
  110993. 0, 0,11,11, 0, 0, 0,13,13, 0, 0, 0,13,12, 8, 8,
  110994. 8,11,12, 0, 0, 0,11,12, 0, 0, 0,11,11, 0, 0, 0,
  110995. 13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111000. 0, 0, 8, 9, 9,14,13, 0, 0, 0,13,12, 0, 0, 0,13,
  111001. 13, 0, 0, 0,13,12, 0, 0, 0,13,13, 8, 9, 9,13,14,
  111002. 0, 0, 0,12,13, 0, 0, 0,13,13, 0, 0, 0,12,13, 0,
  111003. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8,
  111008. 9, 9,14,13, 0, 0, 0,13,13, 0, 0, 0,13,12, 0, 0,
  111009. 0,13,13, 0, 0, 0,13,12, 8, 9, 9,14,14, 0, 0, 0,
  111010. 13,13, 0, 0, 0,12,13, 0, 0, 0,13,13, 0, 0, 0,12,
  111011. 13,
  111012. };
  111013. static float _vq_quantthresh__16c2_s_p2_0[] = {
  111014. -1.5, -0.5, 0.5, 1.5,
  111015. };
  111016. static long _vq_quantmap__16c2_s_p2_0[] = {
  111017. 3, 1, 0, 2, 4,
  111018. };
  111019. static encode_aux_threshmatch _vq_auxt__16c2_s_p2_0 = {
  111020. _vq_quantthresh__16c2_s_p2_0,
  111021. _vq_quantmap__16c2_s_p2_0,
  111022. 5,
  111023. 5
  111024. };
  111025. static static_codebook _16c2_s_p2_0 = {
  111026. 4, 625,
  111027. _vq_lengthlist__16c2_s_p2_0,
  111028. 1, -533725184, 1611661312, 3, 0,
  111029. _vq_quantlist__16c2_s_p2_0,
  111030. NULL,
  111031. &_vq_auxt__16c2_s_p2_0,
  111032. NULL,
  111033. 0
  111034. };
  111035. static long _vq_quantlist__16c2_s_p3_0[] = {
  111036. 4,
  111037. 3,
  111038. 5,
  111039. 2,
  111040. 6,
  111041. 1,
  111042. 7,
  111043. 0,
  111044. 8,
  111045. };
  111046. static long _vq_lengthlist__16c2_s_p3_0[] = {
  111047. 1, 3, 3, 6, 6, 7, 7, 8, 8, 0, 0, 0, 6, 6, 7, 7,
  111048. 9, 9, 0, 0, 0, 6, 6, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  111049. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  111050. 7, 7, 9, 9,10,10, 0, 0, 0, 7, 7, 9, 9,10,10, 0,
  111051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111052. 0,
  111053. };
  111054. static float _vq_quantthresh__16c2_s_p3_0[] = {
  111055. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  111056. };
  111057. static long _vq_quantmap__16c2_s_p3_0[] = {
  111058. 7, 5, 3, 1, 0, 2, 4, 6,
  111059. 8,
  111060. };
  111061. static encode_aux_threshmatch _vq_auxt__16c2_s_p3_0 = {
  111062. _vq_quantthresh__16c2_s_p3_0,
  111063. _vq_quantmap__16c2_s_p3_0,
  111064. 9,
  111065. 9
  111066. };
  111067. static static_codebook _16c2_s_p3_0 = {
  111068. 2, 81,
  111069. _vq_lengthlist__16c2_s_p3_0,
  111070. 1, -531628032, 1611661312, 4, 0,
  111071. _vq_quantlist__16c2_s_p3_0,
  111072. NULL,
  111073. &_vq_auxt__16c2_s_p3_0,
  111074. NULL,
  111075. 0
  111076. };
  111077. static long _vq_quantlist__16c2_s_p4_0[] = {
  111078. 8,
  111079. 7,
  111080. 9,
  111081. 6,
  111082. 10,
  111083. 5,
  111084. 11,
  111085. 4,
  111086. 12,
  111087. 3,
  111088. 13,
  111089. 2,
  111090. 14,
  111091. 1,
  111092. 15,
  111093. 0,
  111094. 16,
  111095. };
  111096. static long _vq_lengthlist__16c2_s_p4_0[] = {
  111097. 2, 3, 3, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9,10,
  111098. 10, 0, 0, 0, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,
  111099. 11,11, 0, 0, 0, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,
  111100. 10,10,11, 0, 0, 0, 6, 6, 8, 8, 8, 8, 9, 9,10,10,
  111101. 10,11,11,11, 0, 0, 0, 6, 6, 8, 8, 9, 9, 9, 9,10,
  111102. 10,11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,
  111103. 10,10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9,
  111104. 9,10,10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  111105. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 8, 8, 9,
  111106. 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 0, 0,
  111107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111115. 0,
  111116. };
  111117. static float _vq_quantthresh__16c2_s_p4_0[] = {
  111118. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  111119. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  111120. };
  111121. static long _vq_quantmap__16c2_s_p4_0[] = {
  111122. 15, 13, 11, 9, 7, 5, 3, 1,
  111123. 0, 2, 4, 6, 8, 10, 12, 14,
  111124. 16,
  111125. };
  111126. static encode_aux_threshmatch _vq_auxt__16c2_s_p4_0 = {
  111127. _vq_quantthresh__16c2_s_p4_0,
  111128. _vq_quantmap__16c2_s_p4_0,
  111129. 17,
  111130. 17
  111131. };
  111132. static static_codebook _16c2_s_p4_0 = {
  111133. 2, 289,
  111134. _vq_lengthlist__16c2_s_p4_0,
  111135. 1, -529530880, 1611661312, 5, 0,
  111136. _vq_quantlist__16c2_s_p4_0,
  111137. NULL,
  111138. &_vq_auxt__16c2_s_p4_0,
  111139. NULL,
  111140. 0
  111141. };
  111142. static long _vq_quantlist__16c2_s_p5_0[] = {
  111143. 1,
  111144. 0,
  111145. 2,
  111146. };
  111147. static long _vq_lengthlist__16c2_s_p5_0[] = {
  111148. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 6, 6,10,10,10,10,
  111149. 10,10, 4, 7, 6,10,10,10,10,10,10, 5, 9, 9, 9,12,
  111150. 11,10,11,12, 7,10,10,12,12,12,12,12,12, 7,10,10,
  111151. 11,12,12,12,12,13, 6,10,10,10,12,12,10,12,12, 7,
  111152. 10,10,11,13,12,12,12,12, 7,10,10,11,12,12,12,12,
  111153. 12,
  111154. };
  111155. static float _vq_quantthresh__16c2_s_p5_0[] = {
  111156. -5.5, 5.5,
  111157. };
  111158. static long _vq_quantmap__16c2_s_p5_0[] = {
  111159. 1, 0, 2,
  111160. };
  111161. static encode_aux_threshmatch _vq_auxt__16c2_s_p5_0 = {
  111162. _vq_quantthresh__16c2_s_p5_0,
  111163. _vq_quantmap__16c2_s_p5_0,
  111164. 3,
  111165. 3
  111166. };
  111167. static static_codebook _16c2_s_p5_0 = {
  111168. 4, 81,
  111169. _vq_lengthlist__16c2_s_p5_0,
  111170. 1, -529137664, 1618345984, 2, 0,
  111171. _vq_quantlist__16c2_s_p5_0,
  111172. NULL,
  111173. &_vq_auxt__16c2_s_p5_0,
  111174. NULL,
  111175. 0
  111176. };
  111177. static long _vq_quantlist__16c2_s_p5_1[] = {
  111178. 5,
  111179. 4,
  111180. 6,
  111181. 3,
  111182. 7,
  111183. 2,
  111184. 8,
  111185. 1,
  111186. 9,
  111187. 0,
  111188. 10,
  111189. };
  111190. static long _vq_lengthlist__16c2_s_p5_1[] = {
  111191. 2, 3, 3, 6, 6, 7, 7, 7, 7, 8, 8,11,11,11, 6, 6,
  111192. 7, 7, 8, 8, 8, 8,11,11,11, 6, 6, 7, 7, 8, 8, 8,
  111193. 8,11,11,11, 6, 6, 8, 8, 8, 8, 9, 9,11,11,11, 6,
  111194. 6, 8, 8, 8, 8, 9, 9,11,11,11, 7, 7, 8, 8, 8, 8,
  111195. 8, 8,11,11,11, 7, 7, 8, 8, 8, 8, 8, 9,11,11,11,
  111196. 8, 8, 8, 8, 8, 8, 8, 8,11,11,11,11,11, 8, 8, 8,
  111197. 8, 8, 8,11,11,11,11,11, 8, 8, 8, 8, 8, 8,11,11,
  111198. 11,11,11, 7, 7, 8, 8, 8, 8,
  111199. };
  111200. static float _vq_quantthresh__16c2_s_p5_1[] = {
  111201. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  111202. 3.5, 4.5,
  111203. };
  111204. static long _vq_quantmap__16c2_s_p5_1[] = {
  111205. 9, 7, 5, 3, 1, 0, 2, 4,
  111206. 6, 8, 10,
  111207. };
  111208. static encode_aux_threshmatch _vq_auxt__16c2_s_p5_1 = {
  111209. _vq_quantthresh__16c2_s_p5_1,
  111210. _vq_quantmap__16c2_s_p5_1,
  111211. 11,
  111212. 11
  111213. };
  111214. static static_codebook _16c2_s_p5_1 = {
  111215. 2, 121,
  111216. _vq_lengthlist__16c2_s_p5_1,
  111217. 1, -531365888, 1611661312, 4, 0,
  111218. _vq_quantlist__16c2_s_p5_1,
  111219. NULL,
  111220. &_vq_auxt__16c2_s_p5_1,
  111221. NULL,
  111222. 0
  111223. };
  111224. static long _vq_quantlist__16c2_s_p6_0[] = {
  111225. 6,
  111226. 5,
  111227. 7,
  111228. 4,
  111229. 8,
  111230. 3,
  111231. 9,
  111232. 2,
  111233. 10,
  111234. 1,
  111235. 11,
  111236. 0,
  111237. 12,
  111238. };
  111239. static long _vq_lengthlist__16c2_s_p6_0[] = {
  111240. 1, 4, 4, 7, 6, 8, 8, 9, 9,10,10,11,11, 5, 5, 5,
  111241. 7, 7, 9, 9, 9, 9,11,11,12,12, 6, 5, 5, 7, 7, 9,
  111242. 9,10,10,11,11,12,12, 0, 6, 6, 7, 7, 9, 9,10,10,
  111243. 11,11,12,12, 0, 7, 7, 7, 7, 9, 9,10,10,11,12,12,
  111244. 12, 0,11,11, 8, 8,10,10,11,11,12,12,13,13, 0,11,
  111245. 12, 8, 8,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  111246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111250. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111251. };
  111252. static float _vq_quantthresh__16c2_s_p6_0[] = {
  111253. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  111254. 12.5, 17.5, 22.5, 27.5,
  111255. };
  111256. static long _vq_quantmap__16c2_s_p6_0[] = {
  111257. 11, 9, 7, 5, 3, 1, 0, 2,
  111258. 4, 6, 8, 10, 12,
  111259. };
  111260. static encode_aux_threshmatch _vq_auxt__16c2_s_p6_0 = {
  111261. _vq_quantthresh__16c2_s_p6_0,
  111262. _vq_quantmap__16c2_s_p6_0,
  111263. 13,
  111264. 13
  111265. };
  111266. static static_codebook _16c2_s_p6_0 = {
  111267. 2, 169,
  111268. _vq_lengthlist__16c2_s_p6_0,
  111269. 1, -526516224, 1616117760, 4, 0,
  111270. _vq_quantlist__16c2_s_p6_0,
  111271. NULL,
  111272. &_vq_auxt__16c2_s_p6_0,
  111273. NULL,
  111274. 0
  111275. };
  111276. static long _vq_quantlist__16c2_s_p6_1[] = {
  111277. 2,
  111278. 1,
  111279. 3,
  111280. 0,
  111281. 4,
  111282. };
  111283. static long _vq_lengthlist__16c2_s_p6_1[] = {
  111284. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  111285. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  111286. };
  111287. static float _vq_quantthresh__16c2_s_p6_1[] = {
  111288. -1.5, -0.5, 0.5, 1.5,
  111289. };
  111290. static long _vq_quantmap__16c2_s_p6_1[] = {
  111291. 3, 1, 0, 2, 4,
  111292. };
  111293. static encode_aux_threshmatch _vq_auxt__16c2_s_p6_1 = {
  111294. _vq_quantthresh__16c2_s_p6_1,
  111295. _vq_quantmap__16c2_s_p6_1,
  111296. 5,
  111297. 5
  111298. };
  111299. static static_codebook _16c2_s_p6_1 = {
  111300. 2, 25,
  111301. _vq_lengthlist__16c2_s_p6_1,
  111302. 1, -533725184, 1611661312, 3, 0,
  111303. _vq_quantlist__16c2_s_p6_1,
  111304. NULL,
  111305. &_vq_auxt__16c2_s_p6_1,
  111306. NULL,
  111307. 0
  111308. };
  111309. static long _vq_quantlist__16c2_s_p7_0[] = {
  111310. 6,
  111311. 5,
  111312. 7,
  111313. 4,
  111314. 8,
  111315. 3,
  111316. 9,
  111317. 2,
  111318. 10,
  111319. 1,
  111320. 11,
  111321. 0,
  111322. 12,
  111323. };
  111324. static long _vq_lengthlist__16c2_s_p7_0[] = {
  111325. 1, 4, 4, 7, 7, 8, 8, 9, 9,10,10,11,11, 5, 5, 5,
  111326. 8, 8, 9, 9,10,10,11,11,12,12, 6, 5, 5, 8, 8, 9,
  111327. 9,10,10,11,11,12,13,18, 6, 6, 7, 7, 9, 9,10,10,
  111328. 12,12,13,13,18, 6, 6, 7, 7, 9, 9,10,10,12,12,13,
  111329. 13,18,11,10, 8, 8,10,10,11,11,12,12,13,13,18,11,
  111330. 11, 8, 8,10,10,11,11,12,13,13,13,18,18,18,10,11,
  111331. 11,11,12,12,13,13,14,14,18,18,18,11,11,11,11,12,
  111332. 12,13,13,14,14,18,18,18,14,14,12,12,12,12,14,14,
  111333. 15,14,18,18,18,15,15,11,12,12,12,13,13,15,15,18,
  111334. 18,18,18,18,13,13,13,13,13,14,17,16,18,18,18,18,
  111335. 18,13,14,13,13,14,13,15,14,
  111336. };
  111337. static float _vq_quantthresh__16c2_s_p7_0[] = {
  111338. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  111339. 27.5, 38.5, 49.5, 60.5,
  111340. };
  111341. static long _vq_quantmap__16c2_s_p7_0[] = {
  111342. 11, 9, 7, 5, 3, 1, 0, 2,
  111343. 4, 6, 8, 10, 12,
  111344. };
  111345. static encode_aux_threshmatch _vq_auxt__16c2_s_p7_0 = {
  111346. _vq_quantthresh__16c2_s_p7_0,
  111347. _vq_quantmap__16c2_s_p7_0,
  111348. 13,
  111349. 13
  111350. };
  111351. static static_codebook _16c2_s_p7_0 = {
  111352. 2, 169,
  111353. _vq_lengthlist__16c2_s_p7_0,
  111354. 1, -523206656, 1618345984, 4, 0,
  111355. _vq_quantlist__16c2_s_p7_0,
  111356. NULL,
  111357. &_vq_auxt__16c2_s_p7_0,
  111358. NULL,
  111359. 0
  111360. };
  111361. static long _vq_quantlist__16c2_s_p7_1[] = {
  111362. 5,
  111363. 4,
  111364. 6,
  111365. 3,
  111366. 7,
  111367. 2,
  111368. 8,
  111369. 1,
  111370. 9,
  111371. 0,
  111372. 10,
  111373. };
  111374. static long _vq_lengthlist__16c2_s_p7_1[] = {
  111375. 2, 4, 4, 6, 6, 7, 7, 7, 7, 7, 7, 9, 9, 9, 6, 6,
  111376. 7, 7, 8, 8, 8, 8, 9, 9, 9, 6, 6, 7, 7, 8, 8, 8,
  111377. 8, 9, 9, 9, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 7,
  111378. 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 7, 7, 7, 7, 8, 8,
  111379. 8, 8, 9, 9, 9, 7, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9,
  111380. 7, 7, 8, 8, 7, 7, 8, 8, 9, 9, 9, 9, 9, 7, 7, 7,
  111381. 7, 8, 8, 9, 9, 9, 9, 9, 8, 8, 7, 7, 8, 8, 9, 9,
  111382. 9, 9, 9, 7, 7, 7, 7, 8, 8,
  111383. };
  111384. static float _vq_quantthresh__16c2_s_p7_1[] = {
  111385. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  111386. 3.5, 4.5,
  111387. };
  111388. static long _vq_quantmap__16c2_s_p7_1[] = {
  111389. 9, 7, 5, 3, 1, 0, 2, 4,
  111390. 6, 8, 10,
  111391. };
  111392. static encode_aux_threshmatch _vq_auxt__16c2_s_p7_1 = {
  111393. _vq_quantthresh__16c2_s_p7_1,
  111394. _vq_quantmap__16c2_s_p7_1,
  111395. 11,
  111396. 11
  111397. };
  111398. static static_codebook _16c2_s_p7_1 = {
  111399. 2, 121,
  111400. _vq_lengthlist__16c2_s_p7_1,
  111401. 1, -531365888, 1611661312, 4, 0,
  111402. _vq_quantlist__16c2_s_p7_1,
  111403. NULL,
  111404. &_vq_auxt__16c2_s_p7_1,
  111405. NULL,
  111406. 0
  111407. };
  111408. static long _vq_quantlist__16c2_s_p8_0[] = {
  111409. 7,
  111410. 6,
  111411. 8,
  111412. 5,
  111413. 9,
  111414. 4,
  111415. 10,
  111416. 3,
  111417. 11,
  111418. 2,
  111419. 12,
  111420. 1,
  111421. 13,
  111422. 0,
  111423. 14,
  111424. };
  111425. static long _vq_lengthlist__16c2_s_p8_0[] = {
  111426. 1, 4, 4, 7, 6, 7, 7, 6, 6, 8, 8, 9, 9,10,10, 6,
  111427. 6, 6, 8, 8, 9, 8, 8, 8, 9, 9,11,10,11,11, 7, 6,
  111428. 6, 8, 8, 9, 8, 7, 7, 9, 9,10,10,12,11,14, 8, 8,
  111429. 8, 9, 9, 9, 9, 9,10, 9,10,10,11,13,14, 8, 8, 8,
  111430. 8, 9, 9, 8, 8, 9, 9,10,10,11,12,14,13,11, 9, 9,
  111431. 9, 9, 9, 9, 9,10,11,10,13,12,14,11,13, 8, 9, 9,
  111432. 9, 9, 9,10,10,11,10,13,12,14,14,14, 8, 9, 9, 9,
  111433. 11,11,11,11,11,12,13,13,14,14,14, 9, 8, 9, 9,10,
  111434. 10,12,10,11,12,12,14,14,14,14,11,12,10,10,12,12,
  111435. 12,12,13,14,12,12,14,14,14,12,12, 9,10,11,11,12,
  111436. 14,12,14,14,14,14,14,14,14,14,11,11,12,11,12,14,
  111437. 14,14,14,14,14,14,14,14,14,12,11,11,11,11,14,14,
  111438. 14,14,14,14,14,14,14,14,14,14,13,12,14,14,14,14,
  111439. 14,14,14,14,14,14,14,14,14,12,12,12,13,14,14,13,
  111440. 13,
  111441. };
  111442. static float _vq_quantthresh__16c2_s_p8_0[] = {
  111443. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  111444. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  111445. };
  111446. static long _vq_quantmap__16c2_s_p8_0[] = {
  111447. 13, 11, 9, 7, 5, 3, 1, 0,
  111448. 2, 4, 6, 8, 10, 12, 14,
  111449. };
  111450. static encode_aux_threshmatch _vq_auxt__16c2_s_p8_0 = {
  111451. _vq_quantthresh__16c2_s_p8_0,
  111452. _vq_quantmap__16c2_s_p8_0,
  111453. 15,
  111454. 15
  111455. };
  111456. static static_codebook _16c2_s_p8_0 = {
  111457. 2, 225,
  111458. _vq_lengthlist__16c2_s_p8_0,
  111459. 1, -520986624, 1620377600, 4, 0,
  111460. _vq_quantlist__16c2_s_p8_0,
  111461. NULL,
  111462. &_vq_auxt__16c2_s_p8_0,
  111463. NULL,
  111464. 0
  111465. };
  111466. static long _vq_quantlist__16c2_s_p8_1[] = {
  111467. 10,
  111468. 9,
  111469. 11,
  111470. 8,
  111471. 12,
  111472. 7,
  111473. 13,
  111474. 6,
  111475. 14,
  111476. 5,
  111477. 15,
  111478. 4,
  111479. 16,
  111480. 3,
  111481. 17,
  111482. 2,
  111483. 18,
  111484. 1,
  111485. 19,
  111486. 0,
  111487. 20,
  111488. };
  111489. static long _vq_lengthlist__16c2_s_p8_1[] = {
  111490. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 8, 8, 8,
  111491. 8, 8, 8, 8, 8,11,12,11, 7, 7, 8, 8, 8, 8, 9, 9,
  111492. 9, 9, 9, 9, 9, 9, 9,10, 9, 9,11,11,10, 7, 7, 8,
  111493. 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  111494. 11,11, 8, 7, 8, 8, 9, 9, 9, 9, 9, 9,10,10, 9,10,
  111495. 10, 9,10,10,11,11,12, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  111496. 9, 9, 9,10, 9,10,10,10,10,11,11,11, 8, 8, 9, 9,
  111497. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,11,11,
  111498. 11, 8, 8, 9, 8, 9, 9, 9, 9,10, 9, 9, 9,10,10,10,
  111499. 10, 9,10,11,11,11, 9, 9, 9, 9,10, 9, 9, 9,10,10,
  111500. 9,10, 9,10,10,10,10,10,11,12,11,11,11, 9, 9, 9,
  111501. 9, 9,10,10, 9,10,10,10,10,10,10,10,10,12,11,13,
  111502. 13,11, 9, 9, 9, 9,10,10, 9,10,10,10,10,11,10,10,
  111503. 10,10,11,12,11,12,11, 9, 9, 9,10,10, 9,10,10,10,
  111504. 10,10,10,10,10,10,10,11,11,11,12,11, 9,10,10,10,
  111505. 10,10,10,10,10,10,10,10,10,10,10,10,11,12,12,12,
  111506. 11,11,11,10, 9,10,10,10,10,10,10,10,10,11,10,10,
  111507. 10,11,11,11,11,11,11,11,10,10,10,11,10,10,10,10,
  111508. 10,10,10,10,10,10,11,11,11,11,12,12,11,10,10,10,
  111509. 10,10,10,10,10,11,10,10,10,11,10,12,11,11,12,11,
  111510. 11,11,10,10,10,10,10,11,10,10,10,10,10,11,10,10,
  111511. 11,11,11,12,11,12,11,11,12,10,10,10,10,10,10,10,
  111512. 11,10,10,11,10,12,11,11,11,12,11,11,11,11,10,10,
  111513. 10,10,10,10,10,11,11,11,10,11,12,11,11,11,12,11,
  111514. 12,11,12,10,11,10,10,10,10,11,10,10,10,10,10,10,
  111515. 12,11,11,11,11,11,12,12,10,10,10,10,10,11,10,10,
  111516. 11,10,11,11,11,11,11,11,11,11,11,11,11,11,12,11,
  111517. 10,11,10,10,10,10,10,10,10,
  111518. };
  111519. static float _vq_quantthresh__16c2_s_p8_1[] = {
  111520. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  111521. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  111522. 6.5, 7.5, 8.5, 9.5,
  111523. };
  111524. static long _vq_quantmap__16c2_s_p8_1[] = {
  111525. 19, 17, 15, 13, 11, 9, 7, 5,
  111526. 3, 1, 0, 2, 4, 6, 8, 10,
  111527. 12, 14, 16, 18, 20,
  111528. };
  111529. static encode_aux_threshmatch _vq_auxt__16c2_s_p8_1 = {
  111530. _vq_quantthresh__16c2_s_p8_1,
  111531. _vq_quantmap__16c2_s_p8_1,
  111532. 21,
  111533. 21
  111534. };
  111535. static static_codebook _16c2_s_p8_1 = {
  111536. 2, 441,
  111537. _vq_lengthlist__16c2_s_p8_1,
  111538. 1, -529268736, 1611661312, 5, 0,
  111539. _vq_quantlist__16c2_s_p8_1,
  111540. NULL,
  111541. &_vq_auxt__16c2_s_p8_1,
  111542. NULL,
  111543. 0
  111544. };
  111545. static long _vq_quantlist__16c2_s_p9_0[] = {
  111546. 6,
  111547. 5,
  111548. 7,
  111549. 4,
  111550. 8,
  111551. 3,
  111552. 9,
  111553. 2,
  111554. 10,
  111555. 1,
  111556. 11,
  111557. 0,
  111558. 12,
  111559. };
  111560. static long _vq_lengthlist__16c2_s_p9_0[] = {
  111561. 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111562. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111563. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111564. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111565. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111566. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111567. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111568. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111569. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111570. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111571. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111572. };
  111573. static float _vq_quantthresh__16c2_s_p9_0[] = {
  111574. -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -465.5, 465.5, 1396.5,
  111575. 2327.5, 3258.5, 4189.5, 5120.5,
  111576. };
  111577. static long _vq_quantmap__16c2_s_p9_0[] = {
  111578. 11, 9, 7, 5, 3, 1, 0, 2,
  111579. 4, 6, 8, 10, 12,
  111580. };
  111581. static encode_aux_threshmatch _vq_auxt__16c2_s_p9_0 = {
  111582. _vq_quantthresh__16c2_s_p9_0,
  111583. _vq_quantmap__16c2_s_p9_0,
  111584. 13,
  111585. 13
  111586. };
  111587. static static_codebook _16c2_s_p9_0 = {
  111588. 2, 169,
  111589. _vq_lengthlist__16c2_s_p9_0,
  111590. 1, -510275072, 1631393792, 4, 0,
  111591. _vq_quantlist__16c2_s_p9_0,
  111592. NULL,
  111593. &_vq_auxt__16c2_s_p9_0,
  111594. NULL,
  111595. 0
  111596. };
  111597. static long _vq_quantlist__16c2_s_p9_1[] = {
  111598. 8,
  111599. 7,
  111600. 9,
  111601. 6,
  111602. 10,
  111603. 5,
  111604. 11,
  111605. 4,
  111606. 12,
  111607. 3,
  111608. 13,
  111609. 2,
  111610. 14,
  111611. 1,
  111612. 15,
  111613. 0,
  111614. 16,
  111615. };
  111616. static long _vq_lengthlist__16c2_s_p9_1[] = {
  111617. 1, 5, 5, 9, 8, 7, 7, 7, 6,10,11,11,11,11,11,11,
  111618. 11, 8, 7, 6, 8, 8,10, 9,10,10,10, 9,11,10,10,10,
  111619. 10,10, 8, 6, 6, 8, 8, 9, 8, 9, 8, 9,10,10,10,10,
  111620. 10,10,10,10, 8,10, 9, 9, 9, 9,10,10,10,10,10,10,
  111621. 10,10,10,10,10, 8, 9, 9, 9,10,10, 9,10,10,10,10,
  111622. 10,10,10,10,10,10,10,10, 9, 8, 9, 9,10,10,10,10,
  111623. 10,10,10,10,10,10,10,10, 9, 8, 8, 9, 9,10,10,10,
  111624. 10,10,10,10,10,10,10,10,10,10, 9,10, 9, 9,10,10,
  111625. 10,10,10,10,10,10,10,10,10,10,10, 9, 8, 9, 9,10,
  111626. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  111627. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111628. 8,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111629. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111630. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111631. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111632. 10,10,10,10, 9,10, 9,10,10,10,10,10,10,10,10,10,
  111633. 10,10,10,10,10,10,10,10,10, 9,10,10,10,10,10,10,
  111634. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111635. 10,
  111636. };
  111637. static float _vq_quantthresh__16c2_s_p9_1[] = {
  111638. -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5, -24.5,
  111639. 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5, 367.5,
  111640. };
  111641. static long _vq_quantmap__16c2_s_p9_1[] = {
  111642. 15, 13, 11, 9, 7, 5, 3, 1,
  111643. 0, 2, 4, 6, 8, 10, 12, 14,
  111644. 16,
  111645. };
  111646. static encode_aux_threshmatch _vq_auxt__16c2_s_p9_1 = {
  111647. _vq_quantthresh__16c2_s_p9_1,
  111648. _vq_quantmap__16c2_s_p9_1,
  111649. 17,
  111650. 17
  111651. };
  111652. static static_codebook _16c2_s_p9_1 = {
  111653. 2, 289,
  111654. _vq_lengthlist__16c2_s_p9_1,
  111655. 1, -518488064, 1622704128, 5, 0,
  111656. _vq_quantlist__16c2_s_p9_1,
  111657. NULL,
  111658. &_vq_auxt__16c2_s_p9_1,
  111659. NULL,
  111660. 0
  111661. };
  111662. static long _vq_quantlist__16c2_s_p9_2[] = {
  111663. 13,
  111664. 12,
  111665. 14,
  111666. 11,
  111667. 15,
  111668. 10,
  111669. 16,
  111670. 9,
  111671. 17,
  111672. 8,
  111673. 18,
  111674. 7,
  111675. 19,
  111676. 6,
  111677. 20,
  111678. 5,
  111679. 21,
  111680. 4,
  111681. 22,
  111682. 3,
  111683. 23,
  111684. 2,
  111685. 24,
  111686. 1,
  111687. 25,
  111688. 0,
  111689. 26,
  111690. };
  111691. static long _vq_lengthlist__16c2_s_p9_2[] = {
  111692. 1, 4, 4, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  111693. 7, 7, 7, 7, 8, 7, 8, 7, 7, 4, 4,
  111694. };
  111695. static float _vq_quantthresh__16c2_s_p9_2[] = {
  111696. -12.5, -11.5, -10.5, -9.5, -8.5, -7.5, -6.5, -5.5,
  111697. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  111698. 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5,
  111699. 11.5, 12.5,
  111700. };
  111701. static long _vq_quantmap__16c2_s_p9_2[] = {
  111702. 25, 23, 21, 19, 17, 15, 13, 11,
  111703. 9, 7, 5, 3, 1, 0, 2, 4,
  111704. 6, 8, 10, 12, 14, 16, 18, 20,
  111705. 22, 24, 26,
  111706. };
  111707. static encode_aux_threshmatch _vq_auxt__16c2_s_p9_2 = {
  111708. _vq_quantthresh__16c2_s_p9_2,
  111709. _vq_quantmap__16c2_s_p9_2,
  111710. 27,
  111711. 27
  111712. };
  111713. static static_codebook _16c2_s_p9_2 = {
  111714. 1, 27,
  111715. _vq_lengthlist__16c2_s_p9_2,
  111716. 1, -528875520, 1611661312, 5, 0,
  111717. _vq_quantlist__16c2_s_p9_2,
  111718. NULL,
  111719. &_vq_auxt__16c2_s_p9_2,
  111720. NULL,
  111721. 0
  111722. };
  111723. static long _huff_lengthlist__16c2_s_short[] = {
  111724. 7,10,11,11,11,14,15,15,17,14, 8, 6, 7, 7, 8, 9,
  111725. 11,11,14,17, 9, 6, 6, 6, 7, 7,10,11,15,16, 9, 6,
  111726. 6, 4, 4, 5, 8, 9,12,16,10, 6, 6, 4, 4, 4, 6, 9,
  111727. 13,16,10, 7, 6, 5, 4, 3, 5, 7,13,16,11, 9, 8, 7,
  111728. 6, 5, 5, 6,12,15,10,10,10, 9, 7, 6, 6, 7,11,15,
  111729. 13,13,13,13,11,10,10, 9,12,16,16,16,16,14,16,15,
  111730. 15,12,14,14,
  111731. };
  111732. static static_codebook _huff_book__16c2_s_short = {
  111733. 2, 100,
  111734. _huff_lengthlist__16c2_s_short,
  111735. 0, 0, 0, 0, 0,
  111736. NULL,
  111737. NULL,
  111738. NULL,
  111739. NULL,
  111740. 0
  111741. };
  111742. static long _vq_quantlist__8c0_s_p1_0[] = {
  111743. 1,
  111744. 0,
  111745. 2,
  111746. };
  111747. static long _vq_lengthlist__8c0_s_p1_0[] = {
  111748. 1, 5, 4, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  111749. 0, 0, 5, 7, 7, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 9, 0, 0, 0,
  111754. 0, 0, 0, 7, 8, 9, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  111759. 0, 0, 0, 0, 7, 9, 8, 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, 5, 8, 8, 0, 0, 0, 0,
  111794. 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 7,10, 9, 0, 0, 0,
  111799. 0, 0, 0, 8, 9,11, 0, 0, 0, 0, 0, 0, 9,11,11, 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, 7, 9,10, 0, 0,
  111804. 0, 0, 0, 0, 9,11,10, 0, 0, 0, 0, 0, 0, 9,11,11,
  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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  111840. 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,11, 0,
  111845. 0, 0, 0, 0, 0, 9,10,11, 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, 7, 9,10, 0, 0, 0, 0, 0, 0, 9,11,11,
  111850. 0, 0, 0, 0, 0, 0, 8,11, 9, 0, 0, 0, 0, 0, 0, 0,
  111851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  112159. };
  112160. static float _vq_quantthresh__8c0_s_p1_0[] = {
  112161. -0.5, 0.5,
  112162. };
  112163. static long _vq_quantmap__8c0_s_p1_0[] = {
  112164. 1, 0, 2,
  112165. };
  112166. static encode_aux_threshmatch _vq_auxt__8c0_s_p1_0 = {
  112167. _vq_quantthresh__8c0_s_p1_0,
  112168. _vq_quantmap__8c0_s_p1_0,
  112169. 3,
  112170. 3
  112171. };
  112172. static static_codebook _8c0_s_p1_0 = {
  112173. 8, 6561,
  112174. _vq_lengthlist__8c0_s_p1_0,
  112175. 1, -535822336, 1611661312, 2, 0,
  112176. _vq_quantlist__8c0_s_p1_0,
  112177. NULL,
  112178. &_vq_auxt__8c0_s_p1_0,
  112179. NULL,
  112180. 0
  112181. };
  112182. static long _vq_quantlist__8c0_s_p2_0[] = {
  112183. 2,
  112184. 1,
  112185. 3,
  112186. 0,
  112187. 4,
  112188. };
  112189. static long _vq_lengthlist__8c0_s_p2_0[] = {
  112190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112229. 0,
  112230. };
  112231. static float _vq_quantthresh__8c0_s_p2_0[] = {
  112232. -1.5, -0.5, 0.5, 1.5,
  112233. };
  112234. static long _vq_quantmap__8c0_s_p2_0[] = {
  112235. 3, 1, 0, 2, 4,
  112236. };
  112237. static encode_aux_threshmatch _vq_auxt__8c0_s_p2_0 = {
  112238. _vq_quantthresh__8c0_s_p2_0,
  112239. _vq_quantmap__8c0_s_p2_0,
  112240. 5,
  112241. 5
  112242. };
  112243. static static_codebook _8c0_s_p2_0 = {
  112244. 4, 625,
  112245. _vq_lengthlist__8c0_s_p2_0,
  112246. 1, -533725184, 1611661312, 3, 0,
  112247. _vq_quantlist__8c0_s_p2_0,
  112248. NULL,
  112249. &_vq_auxt__8c0_s_p2_0,
  112250. NULL,
  112251. 0
  112252. };
  112253. static long _vq_quantlist__8c0_s_p3_0[] = {
  112254. 2,
  112255. 1,
  112256. 3,
  112257. 0,
  112258. 4,
  112259. };
  112260. static long _vq_lengthlist__8c0_s_p3_0[] = {
  112261. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 6, 7, 7, 0, 0,
  112263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112264. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 8, 8,
  112266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112267. 0, 0, 0, 0, 6, 7, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  112268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112300. 0,
  112301. };
  112302. static float _vq_quantthresh__8c0_s_p3_0[] = {
  112303. -1.5, -0.5, 0.5, 1.5,
  112304. };
  112305. static long _vq_quantmap__8c0_s_p3_0[] = {
  112306. 3, 1, 0, 2, 4,
  112307. };
  112308. static encode_aux_threshmatch _vq_auxt__8c0_s_p3_0 = {
  112309. _vq_quantthresh__8c0_s_p3_0,
  112310. _vq_quantmap__8c0_s_p3_0,
  112311. 5,
  112312. 5
  112313. };
  112314. static static_codebook _8c0_s_p3_0 = {
  112315. 4, 625,
  112316. _vq_lengthlist__8c0_s_p3_0,
  112317. 1, -533725184, 1611661312, 3, 0,
  112318. _vq_quantlist__8c0_s_p3_0,
  112319. NULL,
  112320. &_vq_auxt__8c0_s_p3_0,
  112321. NULL,
  112322. 0
  112323. };
  112324. static long _vq_quantlist__8c0_s_p4_0[] = {
  112325. 4,
  112326. 3,
  112327. 5,
  112328. 2,
  112329. 6,
  112330. 1,
  112331. 7,
  112332. 0,
  112333. 8,
  112334. };
  112335. static long _vq_lengthlist__8c0_s_p4_0[] = {
  112336. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  112337. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  112338. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  112339. 8, 8, 0, 0, 0, 0, 0, 0, 0, 9, 8, 0, 0, 0, 0, 0,
  112340. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112341. 0,
  112342. };
  112343. static float _vq_quantthresh__8c0_s_p4_0[] = {
  112344. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  112345. };
  112346. static long _vq_quantmap__8c0_s_p4_0[] = {
  112347. 7, 5, 3, 1, 0, 2, 4, 6,
  112348. 8,
  112349. };
  112350. static encode_aux_threshmatch _vq_auxt__8c0_s_p4_0 = {
  112351. _vq_quantthresh__8c0_s_p4_0,
  112352. _vq_quantmap__8c0_s_p4_0,
  112353. 9,
  112354. 9
  112355. };
  112356. static static_codebook _8c0_s_p4_0 = {
  112357. 2, 81,
  112358. _vq_lengthlist__8c0_s_p4_0,
  112359. 1, -531628032, 1611661312, 4, 0,
  112360. _vq_quantlist__8c0_s_p4_0,
  112361. NULL,
  112362. &_vq_auxt__8c0_s_p4_0,
  112363. NULL,
  112364. 0
  112365. };
  112366. static long _vq_quantlist__8c0_s_p5_0[] = {
  112367. 4,
  112368. 3,
  112369. 5,
  112370. 2,
  112371. 6,
  112372. 1,
  112373. 7,
  112374. 0,
  112375. 8,
  112376. };
  112377. static long _vq_lengthlist__8c0_s_p5_0[] = {
  112378. 1, 3, 3, 5, 5, 7, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  112379. 8, 8, 0, 0, 0, 7, 7, 7, 7, 8, 9, 0, 0, 0, 8, 8,
  112380. 8, 8, 9, 9, 0, 0, 0, 8, 8, 8, 8, 9, 9, 0, 0, 0,
  112381. 9, 9, 8, 8,10,10, 0, 0, 0, 9, 9, 8, 8,10,10, 0,
  112382. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  112383. 10,
  112384. };
  112385. static float _vq_quantthresh__8c0_s_p5_0[] = {
  112386. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  112387. };
  112388. static long _vq_quantmap__8c0_s_p5_0[] = {
  112389. 7, 5, 3, 1, 0, 2, 4, 6,
  112390. 8,
  112391. };
  112392. static encode_aux_threshmatch _vq_auxt__8c0_s_p5_0 = {
  112393. _vq_quantthresh__8c0_s_p5_0,
  112394. _vq_quantmap__8c0_s_p5_0,
  112395. 9,
  112396. 9
  112397. };
  112398. static static_codebook _8c0_s_p5_0 = {
  112399. 2, 81,
  112400. _vq_lengthlist__8c0_s_p5_0,
  112401. 1, -531628032, 1611661312, 4, 0,
  112402. _vq_quantlist__8c0_s_p5_0,
  112403. NULL,
  112404. &_vq_auxt__8c0_s_p5_0,
  112405. NULL,
  112406. 0
  112407. };
  112408. static long _vq_quantlist__8c0_s_p6_0[] = {
  112409. 8,
  112410. 7,
  112411. 9,
  112412. 6,
  112413. 10,
  112414. 5,
  112415. 11,
  112416. 4,
  112417. 12,
  112418. 3,
  112419. 13,
  112420. 2,
  112421. 14,
  112422. 1,
  112423. 15,
  112424. 0,
  112425. 16,
  112426. };
  112427. static long _vq_lengthlist__8c0_s_p6_0[] = {
  112428. 1, 3, 3, 6, 6, 8, 8, 9, 9, 8, 8,10, 9,10,10,11,
  112429. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  112430. 11,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  112431. 11,12,11, 0, 0, 0, 8, 8, 9, 9,10,10, 9, 9,10,10,
  112432. 11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10, 9, 9,11,
  112433. 10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,10,10,
  112434. 11,11,11,12,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,10,
  112435. 10,11,11,12,12,13,13, 0, 0, 0,10,10,10,10,11,11,
  112436. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,10, 9,10,
  112437. 11,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  112438. 10, 9,10,11,12,12,13,13,14,13, 0, 0, 0, 0, 0, 9,
  112439. 9, 9,10,10,10,11,11,13,12,13,13, 0, 0, 0, 0, 0,
  112440. 10,10,10,10,11,11,12,12,13,13,14,14, 0, 0, 0, 0,
  112441. 0, 0, 0,10,10,11,11,12,12,13,13,13,14, 0, 0, 0,
  112442. 0, 0, 0, 0,11,11,11,11,12,12,13,14,14,14, 0, 0,
  112443. 0, 0, 0, 0, 0,11,11,11,11,12,12,13,13,14,13, 0,
  112444. 0, 0, 0, 0, 0, 0,11,11,12,12,13,13,14,14,14,14,
  112445. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  112446. 14,
  112447. };
  112448. static float _vq_quantthresh__8c0_s_p6_0[] = {
  112449. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  112450. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  112451. };
  112452. static long _vq_quantmap__8c0_s_p6_0[] = {
  112453. 15, 13, 11, 9, 7, 5, 3, 1,
  112454. 0, 2, 4, 6, 8, 10, 12, 14,
  112455. 16,
  112456. };
  112457. static encode_aux_threshmatch _vq_auxt__8c0_s_p6_0 = {
  112458. _vq_quantthresh__8c0_s_p6_0,
  112459. _vq_quantmap__8c0_s_p6_0,
  112460. 17,
  112461. 17
  112462. };
  112463. static static_codebook _8c0_s_p6_0 = {
  112464. 2, 289,
  112465. _vq_lengthlist__8c0_s_p6_0,
  112466. 1, -529530880, 1611661312, 5, 0,
  112467. _vq_quantlist__8c0_s_p6_0,
  112468. NULL,
  112469. &_vq_auxt__8c0_s_p6_0,
  112470. NULL,
  112471. 0
  112472. };
  112473. static long _vq_quantlist__8c0_s_p7_0[] = {
  112474. 1,
  112475. 0,
  112476. 2,
  112477. };
  112478. static long _vq_lengthlist__8c0_s_p7_0[] = {
  112479. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,11, 9,10,12,
  112480. 9,10, 4, 7, 7,10,10,10,11, 9, 9, 6,11,10,11,11,
  112481. 12,11,11,11, 6,10,10,11,11,12,11,10,10, 6, 9,10,
  112482. 11,11,11,11,10,10, 7,10,11,12,11,11,12,11,12, 6,
  112483. 9, 9,10, 9, 9,11,10,10, 6, 9, 9,10,10,10,11,10,
  112484. 10,
  112485. };
  112486. static float _vq_quantthresh__8c0_s_p7_0[] = {
  112487. -5.5, 5.5,
  112488. };
  112489. static long _vq_quantmap__8c0_s_p7_0[] = {
  112490. 1, 0, 2,
  112491. };
  112492. static encode_aux_threshmatch _vq_auxt__8c0_s_p7_0 = {
  112493. _vq_quantthresh__8c0_s_p7_0,
  112494. _vq_quantmap__8c0_s_p7_0,
  112495. 3,
  112496. 3
  112497. };
  112498. static static_codebook _8c0_s_p7_0 = {
  112499. 4, 81,
  112500. _vq_lengthlist__8c0_s_p7_0,
  112501. 1, -529137664, 1618345984, 2, 0,
  112502. _vq_quantlist__8c0_s_p7_0,
  112503. NULL,
  112504. &_vq_auxt__8c0_s_p7_0,
  112505. NULL,
  112506. 0
  112507. };
  112508. static long _vq_quantlist__8c0_s_p7_1[] = {
  112509. 5,
  112510. 4,
  112511. 6,
  112512. 3,
  112513. 7,
  112514. 2,
  112515. 8,
  112516. 1,
  112517. 9,
  112518. 0,
  112519. 10,
  112520. };
  112521. static long _vq_lengthlist__8c0_s_p7_1[] = {
  112522. 1, 3, 3, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10, 7, 7,
  112523. 8, 8, 9, 9, 9, 9,10,10, 9, 7, 7, 8, 8, 9, 9, 9,
  112524. 9,10,10,10, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10, 8,
  112525. 8, 9, 9, 9, 9, 8, 9,10,10,10, 8, 8, 9, 9, 9,10,
  112526. 10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,10,11,10,11,
  112527. 9, 9, 9, 9,10,10,10,10,11,11,11,10,10, 9, 9,10,
  112528. 10,10, 9,11,10,10,10,10,10,10, 9, 9,10,10,11,11,
  112529. 10,10,10, 9, 9, 9,10,10,10,
  112530. };
  112531. static float _vq_quantthresh__8c0_s_p7_1[] = {
  112532. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  112533. 3.5, 4.5,
  112534. };
  112535. static long _vq_quantmap__8c0_s_p7_1[] = {
  112536. 9, 7, 5, 3, 1, 0, 2, 4,
  112537. 6, 8, 10,
  112538. };
  112539. static encode_aux_threshmatch _vq_auxt__8c0_s_p7_1 = {
  112540. _vq_quantthresh__8c0_s_p7_1,
  112541. _vq_quantmap__8c0_s_p7_1,
  112542. 11,
  112543. 11
  112544. };
  112545. static static_codebook _8c0_s_p7_1 = {
  112546. 2, 121,
  112547. _vq_lengthlist__8c0_s_p7_1,
  112548. 1, -531365888, 1611661312, 4, 0,
  112549. _vq_quantlist__8c0_s_p7_1,
  112550. NULL,
  112551. &_vq_auxt__8c0_s_p7_1,
  112552. NULL,
  112553. 0
  112554. };
  112555. static long _vq_quantlist__8c0_s_p8_0[] = {
  112556. 6,
  112557. 5,
  112558. 7,
  112559. 4,
  112560. 8,
  112561. 3,
  112562. 9,
  112563. 2,
  112564. 10,
  112565. 1,
  112566. 11,
  112567. 0,
  112568. 12,
  112569. };
  112570. static long _vq_lengthlist__8c0_s_p8_0[] = {
  112571. 1, 4, 4, 7, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 6, 6,
  112572. 7, 7, 8, 8, 7, 7, 8, 9,10,10, 7, 6, 6, 7, 7, 8,
  112573. 7, 7, 7, 9, 9,10,12, 0, 8, 8, 8, 8, 8, 9, 8, 8,
  112574. 9, 9,10,10, 0, 8, 8, 8, 8, 8, 9, 8, 9, 9, 9,11,
  112575. 10, 0, 0,13, 9, 8, 9, 9, 9, 9,10,10,11,11, 0,13,
  112576. 0, 9, 9, 9, 9, 9, 9,11,10,11,11, 0, 0, 0, 8, 9,
  112577. 10, 9,10,10,13,11,12,12, 0, 0, 0, 8, 9, 9, 9,10,
  112578. 10,13,12,12,13, 0, 0, 0,12, 0,10,10,12,11,10,11,
  112579. 12,12, 0, 0, 0,13,13,10,10,10,11,12, 0,13, 0, 0,
  112580. 0, 0, 0, 0,13,11, 0,12,12,12,13,12, 0, 0, 0, 0,
  112581. 0, 0,13,13,11,13,13,11,12,
  112582. };
  112583. static float _vq_quantthresh__8c0_s_p8_0[] = {
  112584. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  112585. 12.5, 17.5, 22.5, 27.5,
  112586. };
  112587. static long _vq_quantmap__8c0_s_p8_0[] = {
  112588. 11, 9, 7, 5, 3, 1, 0, 2,
  112589. 4, 6, 8, 10, 12,
  112590. };
  112591. static encode_aux_threshmatch _vq_auxt__8c0_s_p8_0 = {
  112592. _vq_quantthresh__8c0_s_p8_0,
  112593. _vq_quantmap__8c0_s_p8_0,
  112594. 13,
  112595. 13
  112596. };
  112597. static static_codebook _8c0_s_p8_0 = {
  112598. 2, 169,
  112599. _vq_lengthlist__8c0_s_p8_0,
  112600. 1, -526516224, 1616117760, 4, 0,
  112601. _vq_quantlist__8c0_s_p8_0,
  112602. NULL,
  112603. &_vq_auxt__8c0_s_p8_0,
  112604. NULL,
  112605. 0
  112606. };
  112607. static long _vq_quantlist__8c0_s_p8_1[] = {
  112608. 2,
  112609. 1,
  112610. 3,
  112611. 0,
  112612. 4,
  112613. };
  112614. static long _vq_lengthlist__8c0_s_p8_1[] = {
  112615. 1, 3, 4, 5, 5, 7, 6, 6, 6, 5, 7, 7, 7, 6, 6, 7,
  112616. 7, 7, 6, 6, 7, 7, 7, 6, 6,
  112617. };
  112618. static float _vq_quantthresh__8c0_s_p8_1[] = {
  112619. -1.5, -0.5, 0.5, 1.5,
  112620. };
  112621. static long _vq_quantmap__8c0_s_p8_1[] = {
  112622. 3, 1, 0, 2, 4,
  112623. };
  112624. static encode_aux_threshmatch _vq_auxt__8c0_s_p8_1 = {
  112625. _vq_quantthresh__8c0_s_p8_1,
  112626. _vq_quantmap__8c0_s_p8_1,
  112627. 5,
  112628. 5
  112629. };
  112630. static static_codebook _8c0_s_p8_1 = {
  112631. 2, 25,
  112632. _vq_lengthlist__8c0_s_p8_1,
  112633. 1, -533725184, 1611661312, 3, 0,
  112634. _vq_quantlist__8c0_s_p8_1,
  112635. NULL,
  112636. &_vq_auxt__8c0_s_p8_1,
  112637. NULL,
  112638. 0
  112639. };
  112640. static long _vq_quantlist__8c0_s_p9_0[] = {
  112641. 1,
  112642. 0,
  112643. 2,
  112644. };
  112645. static long _vq_lengthlist__8c0_s_p9_0[] = {
  112646. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  112647. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  112648. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  112649. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  112650. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  112651. 7,
  112652. };
  112653. static float _vq_quantthresh__8c0_s_p9_0[] = {
  112654. -157.5, 157.5,
  112655. };
  112656. static long _vq_quantmap__8c0_s_p9_0[] = {
  112657. 1, 0, 2,
  112658. };
  112659. static encode_aux_threshmatch _vq_auxt__8c0_s_p9_0 = {
  112660. _vq_quantthresh__8c0_s_p9_0,
  112661. _vq_quantmap__8c0_s_p9_0,
  112662. 3,
  112663. 3
  112664. };
  112665. static static_codebook _8c0_s_p9_0 = {
  112666. 4, 81,
  112667. _vq_lengthlist__8c0_s_p9_0,
  112668. 1, -518803456, 1628680192, 2, 0,
  112669. _vq_quantlist__8c0_s_p9_0,
  112670. NULL,
  112671. &_vq_auxt__8c0_s_p9_0,
  112672. NULL,
  112673. 0
  112674. };
  112675. static long _vq_quantlist__8c0_s_p9_1[] = {
  112676. 7,
  112677. 6,
  112678. 8,
  112679. 5,
  112680. 9,
  112681. 4,
  112682. 10,
  112683. 3,
  112684. 11,
  112685. 2,
  112686. 12,
  112687. 1,
  112688. 13,
  112689. 0,
  112690. 14,
  112691. };
  112692. static long _vq_lengthlist__8c0_s_p9_1[] = {
  112693. 1, 4, 4, 5, 5,10, 8,11,11,11,11,11,11,11,11, 6,
  112694. 6, 6, 7, 6,11,10,11,11,11,11,11,11,11,11, 7, 5,
  112695. 6, 6, 6, 8, 7,11,11,11,11,11,11,11,11,11, 7, 8,
  112696. 8, 8, 9, 9,11,11,11,11,11,11,11,11,11, 9, 8, 7,
  112697. 8, 9,11,11,11,11,11,11,11,11,11,11,11,10,11,11,
  112698. 11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,
  112699. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112700. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112701. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112702. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112703. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112704. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112705. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112706. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112707. 11,
  112708. };
  112709. static float _vq_quantthresh__8c0_s_p9_1[] = {
  112710. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  112711. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  112712. };
  112713. static long _vq_quantmap__8c0_s_p9_1[] = {
  112714. 13, 11, 9, 7, 5, 3, 1, 0,
  112715. 2, 4, 6, 8, 10, 12, 14,
  112716. };
  112717. static encode_aux_threshmatch _vq_auxt__8c0_s_p9_1 = {
  112718. _vq_quantthresh__8c0_s_p9_1,
  112719. _vq_quantmap__8c0_s_p9_1,
  112720. 15,
  112721. 15
  112722. };
  112723. static static_codebook _8c0_s_p9_1 = {
  112724. 2, 225,
  112725. _vq_lengthlist__8c0_s_p9_1,
  112726. 1, -520986624, 1620377600, 4, 0,
  112727. _vq_quantlist__8c0_s_p9_1,
  112728. NULL,
  112729. &_vq_auxt__8c0_s_p9_1,
  112730. NULL,
  112731. 0
  112732. };
  112733. static long _vq_quantlist__8c0_s_p9_2[] = {
  112734. 10,
  112735. 9,
  112736. 11,
  112737. 8,
  112738. 12,
  112739. 7,
  112740. 13,
  112741. 6,
  112742. 14,
  112743. 5,
  112744. 15,
  112745. 4,
  112746. 16,
  112747. 3,
  112748. 17,
  112749. 2,
  112750. 18,
  112751. 1,
  112752. 19,
  112753. 0,
  112754. 20,
  112755. };
  112756. static long _vq_lengthlist__8c0_s_p9_2[] = {
  112757. 1, 5, 5, 7, 7, 8, 7, 8, 8,10,10, 9, 9,10,10,10,
  112758. 11,11,10,12,11,12,12,12, 9, 8, 8, 8, 8, 8, 9,10,
  112759. 10,10,10,11,11,11,10,11,11,12,12,11,12, 8, 8, 7,
  112760. 7, 8, 9,10,10,10, 9,10,10, 9,10,10,11,11,11,11,
  112761. 11,11, 9, 9, 9, 9, 8, 9,10,10,11,10,10,11,11,12,
  112762. 10,10,12,12,11,11,10, 9, 9,10, 8, 9,10,10,10, 9,
  112763. 10,10,11,11,10,11,10,10,10,12,12,12, 9,10, 9,10,
  112764. 9, 9,10,10,11,11,11,11,10,10,10,11,12,11,12,11,
  112765. 12,10,11,10,11, 9,10, 9,10, 9,10,10, 9,10,10,11,
  112766. 10,11,11,11,11,12,11, 9,10,10,10,10,11,11,11,11,
  112767. 11,10,11,11,11,11,10,12,10,12,12,11,12,10,10,11,
  112768. 10, 9,11,10,11, 9,10,11,10,10,10,11,11,11,11,12,
  112769. 12,10, 9, 9,11,10, 9,12,11,10,12,12,11,11,11,11,
  112770. 10,11,11,12,11,10,12, 9,11,10,11,10,10,11,10,11,
  112771. 9,10,10,10,11,12,11,11,12,11,10,10,11,11, 9,10,
  112772. 10,12,10,11,10,10,10, 9,10,10,10,10, 9,10,10,11,
  112773. 11,11,11,12,11,10,10,10,10,11,11,10,11,11, 9,11,
  112774. 10,12,10,12,11,10,11,10,10,10,11,10,10,11,11,10,
  112775. 11,10,10,10,10,11,11,12,10,10,10,11,10,11,12,11,
  112776. 10,11,10,10,11,11,10,12,10, 9,10,10,11,11,11,10,
  112777. 12,10,10,11,11,11,10,10,11,10,10,10,11,10,11,10,
  112778. 12,11,11,10,10,10,12,10,10,11, 9,10,11,11,11,10,
  112779. 10,11,10,10, 9,11,11,12,12,11,12,11,11,11,11,11,
  112780. 11, 9,10,11,10,12,10,10,10,10,11,10,10,11,10,10,
  112781. 12,10,10,10,10,10, 9,12,10,10,10,10,12, 9,11,10,
  112782. 10,11,10,12,12,10,12,12,12,10,10,10,10, 9,10,11,
  112783. 10,10,12,10,10,12,11,10,11,10,10,12,11,10,12,10,
  112784. 10,11, 9,11,10, 9,10, 9,10,
  112785. };
  112786. static float _vq_quantthresh__8c0_s_p9_2[] = {
  112787. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  112788. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  112789. 6.5, 7.5, 8.5, 9.5,
  112790. };
  112791. static long _vq_quantmap__8c0_s_p9_2[] = {
  112792. 19, 17, 15, 13, 11, 9, 7, 5,
  112793. 3, 1, 0, 2, 4, 6, 8, 10,
  112794. 12, 14, 16, 18, 20,
  112795. };
  112796. static encode_aux_threshmatch _vq_auxt__8c0_s_p9_2 = {
  112797. _vq_quantthresh__8c0_s_p9_2,
  112798. _vq_quantmap__8c0_s_p9_2,
  112799. 21,
  112800. 21
  112801. };
  112802. static static_codebook _8c0_s_p9_2 = {
  112803. 2, 441,
  112804. _vq_lengthlist__8c0_s_p9_2,
  112805. 1, -529268736, 1611661312, 5, 0,
  112806. _vq_quantlist__8c0_s_p9_2,
  112807. NULL,
  112808. &_vq_auxt__8c0_s_p9_2,
  112809. NULL,
  112810. 0
  112811. };
  112812. static long _huff_lengthlist__8c0_s_single[] = {
  112813. 4, 5,18, 7,10, 6, 7, 8, 9,10, 5, 2,18, 5, 7, 5,
  112814. 6, 7, 8,11,17,17,17,17,17,17,17,17,17,17, 7, 4,
  112815. 17, 6, 9, 6, 8,10,12,15,11, 7,17, 9, 6, 6, 7, 9,
  112816. 11,15, 6, 4,17, 6, 6, 4, 5, 8,11,16, 6, 6,17, 8,
  112817. 6, 5, 6, 9,13,16, 8, 9,17,11, 9, 8, 8,11,13,17,
  112818. 9,12,17,15,14,13,12,13,14,17,12,15,17,17,17,17,
  112819. 17,16,17,17,
  112820. };
  112821. static static_codebook _huff_book__8c0_s_single = {
  112822. 2, 100,
  112823. _huff_lengthlist__8c0_s_single,
  112824. 0, 0, 0, 0, 0,
  112825. NULL,
  112826. NULL,
  112827. NULL,
  112828. NULL,
  112829. 0
  112830. };
  112831. static long _vq_quantlist__8c1_s_p1_0[] = {
  112832. 1,
  112833. 0,
  112834. 2,
  112835. };
  112836. static long _vq_lengthlist__8c1_s_p1_0[] = {
  112837. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  112838. 0, 0, 5, 7, 7, 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, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 8, 9, 0, 0, 0,
  112843. 0, 0, 0, 7, 8, 9, 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, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  112848. 0, 0, 0, 0, 7, 9, 8, 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, 5, 8, 8, 0, 0, 0, 0,
  112883. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  112888. 0, 0, 0, 8, 8,10, 0, 0, 0, 0, 0, 0, 9,10,10, 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, 7, 9, 9, 0, 0,
  112893. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  112929. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  112934. 0, 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  112939. 0, 0, 0, 0, 0, 0, 8,10, 8, 0, 0, 0, 0, 0, 0, 0,
  112940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  113248. };
  113249. static float _vq_quantthresh__8c1_s_p1_0[] = {
  113250. -0.5, 0.5,
  113251. };
  113252. static long _vq_quantmap__8c1_s_p1_0[] = {
  113253. 1, 0, 2,
  113254. };
  113255. static encode_aux_threshmatch _vq_auxt__8c1_s_p1_0 = {
  113256. _vq_quantthresh__8c1_s_p1_0,
  113257. _vq_quantmap__8c1_s_p1_0,
  113258. 3,
  113259. 3
  113260. };
  113261. static static_codebook _8c1_s_p1_0 = {
  113262. 8, 6561,
  113263. _vq_lengthlist__8c1_s_p1_0,
  113264. 1, -535822336, 1611661312, 2, 0,
  113265. _vq_quantlist__8c1_s_p1_0,
  113266. NULL,
  113267. &_vq_auxt__8c1_s_p1_0,
  113268. NULL,
  113269. 0
  113270. };
  113271. static long _vq_quantlist__8c1_s_p2_0[] = {
  113272. 2,
  113273. 1,
  113274. 3,
  113275. 0,
  113276. 4,
  113277. };
  113278. static long _vq_lengthlist__8c1_s_p2_0[] = {
  113279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113318. 0,
  113319. };
  113320. static float _vq_quantthresh__8c1_s_p2_0[] = {
  113321. -1.5, -0.5, 0.5, 1.5,
  113322. };
  113323. static long _vq_quantmap__8c1_s_p2_0[] = {
  113324. 3, 1, 0, 2, 4,
  113325. };
  113326. static encode_aux_threshmatch _vq_auxt__8c1_s_p2_0 = {
  113327. _vq_quantthresh__8c1_s_p2_0,
  113328. _vq_quantmap__8c1_s_p2_0,
  113329. 5,
  113330. 5
  113331. };
  113332. static static_codebook _8c1_s_p2_0 = {
  113333. 4, 625,
  113334. _vq_lengthlist__8c1_s_p2_0,
  113335. 1, -533725184, 1611661312, 3, 0,
  113336. _vq_quantlist__8c1_s_p2_0,
  113337. NULL,
  113338. &_vq_auxt__8c1_s_p2_0,
  113339. NULL,
  113340. 0
  113341. };
  113342. static long _vq_quantlist__8c1_s_p3_0[] = {
  113343. 2,
  113344. 1,
  113345. 3,
  113346. 0,
  113347. 4,
  113348. };
  113349. static long _vq_lengthlist__8c1_s_p3_0[] = {
  113350. 2, 4, 4, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  113352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113353. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 7, 7,
  113355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113356. 0, 0, 0, 0, 6, 6, 6, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  113357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113389. 0,
  113390. };
  113391. static float _vq_quantthresh__8c1_s_p3_0[] = {
  113392. -1.5, -0.5, 0.5, 1.5,
  113393. };
  113394. static long _vq_quantmap__8c1_s_p3_0[] = {
  113395. 3, 1, 0, 2, 4,
  113396. };
  113397. static encode_aux_threshmatch _vq_auxt__8c1_s_p3_0 = {
  113398. _vq_quantthresh__8c1_s_p3_0,
  113399. _vq_quantmap__8c1_s_p3_0,
  113400. 5,
  113401. 5
  113402. };
  113403. static static_codebook _8c1_s_p3_0 = {
  113404. 4, 625,
  113405. _vq_lengthlist__8c1_s_p3_0,
  113406. 1, -533725184, 1611661312, 3, 0,
  113407. _vq_quantlist__8c1_s_p3_0,
  113408. NULL,
  113409. &_vq_auxt__8c1_s_p3_0,
  113410. NULL,
  113411. 0
  113412. };
  113413. static long _vq_quantlist__8c1_s_p4_0[] = {
  113414. 4,
  113415. 3,
  113416. 5,
  113417. 2,
  113418. 6,
  113419. 1,
  113420. 7,
  113421. 0,
  113422. 8,
  113423. };
  113424. static long _vq_lengthlist__8c1_s_p4_0[] = {
  113425. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  113426. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  113427. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  113428. 8, 8, 0, 0, 0, 0, 0, 0, 0, 9, 8, 0, 0, 0, 0, 0,
  113429. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113430. 0,
  113431. };
  113432. static float _vq_quantthresh__8c1_s_p4_0[] = {
  113433. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  113434. };
  113435. static long _vq_quantmap__8c1_s_p4_0[] = {
  113436. 7, 5, 3, 1, 0, 2, 4, 6,
  113437. 8,
  113438. };
  113439. static encode_aux_threshmatch _vq_auxt__8c1_s_p4_0 = {
  113440. _vq_quantthresh__8c1_s_p4_0,
  113441. _vq_quantmap__8c1_s_p4_0,
  113442. 9,
  113443. 9
  113444. };
  113445. static static_codebook _8c1_s_p4_0 = {
  113446. 2, 81,
  113447. _vq_lengthlist__8c1_s_p4_0,
  113448. 1, -531628032, 1611661312, 4, 0,
  113449. _vq_quantlist__8c1_s_p4_0,
  113450. NULL,
  113451. &_vq_auxt__8c1_s_p4_0,
  113452. NULL,
  113453. 0
  113454. };
  113455. static long _vq_quantlist__8c1_s_p5_0[] = {
  113456. 4,
  113457. 3,
  113458. 5,
  113459. 2,
  113460. 6,
  113461. 1,
  113462. 7,
  113463. 0,
  113464. 8,
  113465. };
  113466. static long _vq_lengthlist__8c1_s_p5_0[] = {
  113467. 1, 3, 3, 4, 5, 6, 6, 8, 8, 0, 0, 0, 8, 8, 7, 7,
  113468. 9, 9, 0, 0, 0, 8, 8, 7, 7, 9, 9, 0, 0, 0, 9,10,
  113469. 8, 8, 9, 9, 0, 0, 0,10,10, 8, 8, 9, 9, 0, 0, 0,
  113470. 11,10, 8, 8,10,10, 0, 0, 0,11,11, 8, 8,10,10, 0,
  113471. 0, 0,12,12, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  113472. 10,
  113473. };
  113474. static float _vq_quantthresh__8c1_s_p5_0[] = {
  113475. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  113476. };
  113477. static long _vq_quantmap__8c1_s_p5_0[] = {
  113478. 7, 5, 3, 1, 0, 2, 4, 6,
  113479. 8,
  113480. };
  113481. static encode_aux_threshmatch _vq_auxt__8c1_s_p5_0 = {
  113482. _vq_quantthresh__8c1_s_p5_0,
  113483. _vq_quantmap__8c1_s_p5_0,
  113484. 9,
  113485. 9
  113486. };
  113487. static static_codebook _8c1_s_p5_0 = {
  113488. 2, 81,
  113489. _vq_lengthlist__8c1_s_p5_0,
  113490. 1, -531628032, 1611661312, 4, 0,
  113491. _vq_quantlist__8c1_s_p5_0,
  113492. NULL,
  113493. &_vq_auxt__8c1_s_p5_0,
  113494. NULL,
  113495. 0
  113496. };
  113497. static long _vq_quantlist__8c1_s_p6_0[] = {
  113498. 8,
  113499. 7,
  113500. 9,
  113501. 6,
  113502. 10,
  113503. 5,
  113504. 11,
  113505. 4,
  113506. 12,
  113507. 3,
  113508. 13,
  113509. 2,
  113510. 14,
  113511. 1,
  113512. 15,
  113513. 0,
  113514. 16,
  113515. };
  113516. static long _vq_lengthlist__8c1_s_p6_0[] = {
  113517. 1, 3, 3, 5, 5, 8, 8, 8, 8, 9, 9,10,10,11,11,11,
  113518. 11, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,11,
  113519. 12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  113520. 11,12,12, 0, 0, 0, 9, 9, 8, 8,10,10,10,10,11,11,
  113521. 12,12,12,12, 0, 0, 0, 9, 9, 8, 8,10,10,10,10,11,
  113522. 11,12,12,12,12, 0, 0, 0,10,10, 9, 9,10,10,10,10,
  113523. 11,11,12,12,13,13, 0, 0, 0,10,10, 9, 9,10,10,10,
  113524. 10,11,11,12,12,13,13, 0, 0, 0,11,11, 9, 9,10,10,
  113525. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,10,
  113526. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  113527. 10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0, 0, 9,
  113528. 9,10,10,11,11,12,11,12,12,13,13, 0, 0, 0, 0, 0,
  113529. 10,10,11,11,11,11,12,12,13,12,13,13, 0, 0, 0, 0,
  113530. 0, 0, 0,11,10,11,11,12,12,13,13,13,13, 0, 0, 0,
  113531. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0, 0,
  113532. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,13, 0,
  113533. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  113534. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,13,13,14,
  113535. 14,
  113536. };
  113537. static float _vq_quantthresh__8c1_s_p6_0[] = {
  113538. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  113539. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  113540. };
  113541. static long _vq_quantmap__8c1_s_p6_0[] = {
  113542. 15, 13, 11, 9, 7, 5, 3, 1,
  113543. 0, 2, 4, 6, 8, 10, 12, 14,
  113544. 16,
  113545. };
  113546. static encode_aux_threshmatch _vq_auxt__8c1_s_p6_0 = {
  113547. _vq_quantthresh__8c1_s_p6_0,
  113548. _vq_quantmap__8c1_s_p6_0,
  113549. 17,
  113550. 17
  113551. };
  113552. static static_codebook _8c1_s_p6_0 = {
  113553. 2, 289,
  113554. _vq_lengthlist__8c1_s_p6_0,
  113555. 1, -529530880, 1611661312, 5, 0,
  113556. _vq_quantlist__8c1_s_p6_0,
  113557. NULL,
  113558. &_vq_auxt__8c1_s_p6_0,
  113559. NULL,
  113560. 0
  113561. };
  113562. static long _vq_quantlist__8c1_s_p7_0[] = {
  113563. 1,
  113564. 0,
  113565. 2,
  113566. };
  113567. static long _vq_lengthlist__8c1_s_p7_0[] = {
  113568. 1, 4, 4, 6, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,10,
  113569. 9, 9, 5, 7, 7,10, 9, 9,10, 9, 9, 6,10,10,10,10,
  113570. 10,11,10,10, 6, 9, 9,10, 9,10,11,10,10, 6, 9, 9,
  113571. 10, 9, 9,11, 9,10, 7,10,10,11,11,11,11,10,10, 6,
  113572. 9, 9,10,10,10,11, 9, 9, 6, 9, 9,10,10,10,10, 9,
  113573. 9,
  113574. };
  113575. static float _vq_quantthresh__8c1_s_p7_0[] = {
  113576. -5.5, 5.5,
  113577. };
  113578. static long _vq_quantmap__8c1_s_p7_0[] = {
  113579. 1, 0, 2,
  113580. };
  113581. static encode_aux_threshmatch _vq_auxt__8c1_s_p7_0 = {
  113582. _vq_quantthresh__8c1_s_p7_0,
  113583. _vq_quantmap__8c1_s_p7_0,
  113584. 3,
  113585. 3
  113586. };
  113587. static static_codebook _8c1_s_p7_0 = {
  113588. 4, 81,
  113589. _vq_lengthlist__8c1_s_p7_0,
  113590. 1, -529137664, 1618345984, 2, 0,
  113591. _vq_quantlist__8c1_s_p7_0,
  113592. NULL,
  113593. &_vq_auxt__8c1_s_p7_0,
  113594. NULL,
  113595. 0
  113596. };
  113597. static long _vq_quantlist__8c1_s_p7_1[] = {
  113598. 5,
  113599. 4,
  113600. 6,
  113601. 3,
  113602. 7,
  113603. 2,
  113604. 8,
  113605. 1,
  113606. 9,
  113607. 0,
  113608. 10,
  113609. };
  113610. static long _vq_lengthlist__8c1_s_p7_1[] = {
  113611. 2, 3, 3, 5, 5, 7, 7, 7, 7, 7, 7,10,10, 9, 7, 7,
  113612. 7, 7, 8, 8, 8, 8, 9, 9, 9, 7, 7, 7, 7, 8, 8, 8,
  113613. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  113614. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  113615. 8, 8,10,10,10, 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  113616. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  113617. 8, 8, 8,10,10,10,10,10, 8, 8, 8, 8, 8, 8,10,10,
  113618. 10,10,10, 8, 8, 8, 8, 8, 8,
  113619. };
  113620. static float _vq_quantthresh__8c1_s_p7_1[] = {
  113621. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  113622. 3.5, 4.5,
  113623. };
  113624. static long _vq_quantmap__8c1_s_p7_1[] = {
  113625. 9, 7, 5, 3, 1, 0, 2, 4,
  113626. 6, 8, 10,
  113627. };
  113628. static encode_aux_threshmatch _vq_auxt__8c1_s_p7_1 = {
  113629. _vq_quantthresh__8c1_s_p7_1,
  113630. _vq_quantmap__8c1_s_p7_1,
  113631. 11,
  113632. 11
  113633. };
  113634. static static_codebook _8c1_s_p7_1 = {
  113635. 2, 121,
  113636. _vq_lengthlist__8c1_s_p7_1,
  113637. 1, -531365888, 1611661312, 4, 0,
  113638. _vq_quantlist__8c1_s_p7_1,
  113639. NULL,
  113640. &_vq_auxt__8c1_s_p7_1,
  113641. NULL,
  113642. 0
  113643. };
  113644. static long _vq_quantlist__8c1_s_p8_0[] = {
  113645. 6,
  113646. 5,
  113647. 7,
  113648. 4,
  113649. 8,
  113650. 3,
  113651. 9,
  113652. 2,
  113653. 10,
  113654. 1,
  113655. 11,
  113656. 0,
  113657. 12,
  113658. };
  113659. static long _vq_lengthlist__8c1_s_p8_0[] = {
  113660. 1, 4, 4, 6, 6, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 5,
  113661. 7, 7, 8, 8, 8, 8, 9,10,11,11, 7, 5, 5, 7, 7, 8,
  113662. 8, 9, 9,10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  113663. 9,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  113664. 11, 0,12,12, 9, 9, 9, 9,10, 9,10,11,11,11, 0,13,
  113665. 12, 9, 8, 9, 9,10,10,11,11,12,11, 0, 0, 0, 9, 9,
  113666. 9, 9,10,10,11,11,12,12, 0, 0, 0,10,10, 9, 9,10,
  113667. 10,11,11,12,12, 0, 0, 0,13,13,10,10,11,11,12,11,
  113668. 13,12, 0, 0, 0,14,14,10,10,11,10,11,11,12,12, 0,
  113669. 0, 0, 0, 0,12,12,11,11,12,12,13,13, 0, 0, 0, 0,
  113670. 0,12,12,11,10,12,11,13,12,
  113671. };
  113672. static float _vq_quantthresh__8c1_s_p8_0[] = {
  113673. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  113674. 12.5, 17.5, 22.5, 27.5,
  113675. };
  113676. static long _vq_quantmap__8c1_s_p8_0[] = {
  113677. 11, 9, 7, 5, 3, 1, 0, 2,
  113678. 4, 6, 8, 10, 12,
  113679. };
  113680. static encode_aux_threshmatch _vq_auxt__8c1_s_p8_0 = {
  113681. _vq_quantthresh__8c1_s_p8_0,
  113682. _vq_quantmap__8c1_s_p8_0,
  113683. 13,
  113684. 13
  113685. };
  113686. static static_codebook _8c1_s_p8_0 = {
  113687. 2, 169,
  113688. _vq_lengthlist__8c1_s_p8_0,
  113689. 1, -526516224, 1616117760, 4, 0,
  113690. _vq_quantlist__8c1_s_p8_0,
  113691. NULL,
  113692. &_vq_auxt__8c1_s_p8_0,
  113693. NULL,
  113694. 0
  113695. };
  113696. static long _vq_quantlist__8c1_s_p8_1[] = {
  113697. 2,
  113698. 1,
  113699. 3,
  113700. 0,
  113701. 4,
  113702. };
  113703. static long _vq_lengthlist__8c1_s_p8_1[] = {
  113704. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  113705. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  113706. };
  113707. static float _vq_quantthresh__8c1_s_p8_1[] = {
  113708. -1.5, -0.5, 0.5, 1.5,
  113709. };
  113710. static long _vq_quantmap__8c1_s_p8_1[] = {
  113711. 3, 1, 0, 2, 4,
  113712. };
  113713. static encode_aux_threshmatch _vq_auxt__8c1_s_p8_1 = {
  113714. _vq_quantthresh__8c1_s_p8_1,
  113715. _vq_quantmap__8c1_s_p8_1,
  113716. 5,
  113717. 5
  113718. };
  113719. static static_codebook _8c1_s_p8_1 = {
  113720. 2, 25,
  113721. _vq_lengthlist__8c1_s_p8_1,
  113722. 1, -533725184, 1611661312, 3, 0,
  113723. _vq_quantlist__8c1_s_p8_1,
  113724. NULL,
  113725. &_vq_auxt__8c1_s_p8_1,
  113726. NULL,
  113727. 0
  113728. };
  113729. static long _vq_quantlist__8c1_s_p9_0[] = {
  113730. 6,
  113731. 5,
  113732. 7,
  113733. 4,
  113734. 8,
  113735. 3,
  113736. 9,
  113737. 2,
  113738. 10,
  113739. 1,
  113740. 11,
  113741. 0,
  113742. 12,
  113743. };
  113744. static long _vq_lengthlist__8c1_s_p9_0[] = {
  113745. 1, 3, 3,10,10,10,10,10,10,10,10,10,10, 5, 6, 6,
  113746. 10,10,10,10,10,10,10,10,10,10, 6, 7, 8,10,10,10,
  113747. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113748. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113749. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113750. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113751. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113752. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113753. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113754. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113755. 10,10,10,10,10, 9, 9, 9, 9,
  113756. };
  113757. static float _vq_quantthresh__8c1_s_p9_0[] = {
  113758. -1732.5, -1417.5, -1102.5, -787.5, -472.5, -157.5, 157.5, 472.5,
  113759. 787.5, 1102.5, 1417.5, 1732.5,
  113760. };
  113761. static long _vq_quantmap__8c1_s_p9_0[] = {
  113762. 11, 9, 7, 5, 3, 1, 0, 2,
  113763. 4, 6, 8, 10, 12,
  113764. };
  113765. static encode_aux_threshmatch _vq_auxt__8c1_s_p9_0 = {
  113766. _vq_quantthresh__8c1_s_p9_0,
  113767. _vq_quantmap__8c1_s_p9_0,
  113768. 13,
  113769. 13
  113770. };
  113771. static static_codebook _8c1_s_p9_0 = {
  113772. 2, 169,
  113773. _vq_lengthlist__8c1_s_p9_0,
  113774. 1, -513964032, 1628680192, 4, 0,
  113775. _vq_quantlist__8c1_s_p9_0,
  113776. NULL,
  113777. &_vq_auxt__8c1_s_p9_0,
  113778. NULL,
  113779. 0
  113780. };
  113781. static long _vq_quantlist__8c1_s_p9_1[] = {
  113782. 7,
  113783. 6,
  113784. 8,
  113785. 5,
  113786. 9,
  113787. 4,
  113788. 10,
  113789. 3,
  113790. 11,
  113791. 2,
  113792. 12,
  113793. 1,
  113794. 13,
  113795. 0,
  113796. 14,
  113797. };
  113798. static long _vq_lengthlist__8c1_s_p9_1[] = {
  113799. 1, 4, 4, 5, 5, 7, 7, 9, 9,11,11,12,12,13,13, 6,
  113800. 5, 5, 6, 6, 9, 9,10,10,12,12,12,13,15,14, 6, 5,
  113801. 5, 7, 7, 9, 9,10,10,12,12,12,13,14,13,17, 7, 7,
  113802. 8, 8,10,10,11,11,12,13,13,13,13,13,17, 7, 7, 8,
  113803. 8,10,10,11,11,13,13,13,13,14,14,17,11,11, 9, 9,
  113804. 11,11,12,12,12,13,13,14,15,13,17,12,12, 9, 9,11,
  113805. 11,12,12,13,13,13,13,14,16,17,17,17,11,12,12,12,
  113806. 13,13,13,14,15,14,15,15,17,17,17,12,12,11,11,13,
  113807. 13,14,14,15,14,15,15,17,17,17,15,15,13,13,14,14,
  113808. 15,14,15,15,16,15,17,17,17,15,15,13,13,13,14,14,
  113809. 15,15,15,15,16,17,17,17,17,16,14,15,14,14,15,14,
  113810. 14,15,15,15,17,17,17,17,17,14,14,16,14,15,15,15,
  113811. 15,15,15,17,17,17,17,17,17,16,16,15,17,15,15,14,
  113812. 17,15,17,16,17,17,17,17,16,15,14,15,15,15,15,15,
  113813. 15,
  113814. };
  113815. static float _vq_quantthresh__8c1_s_p9_1[] = {
  113816. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  113817. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  113818. };
  113819. static long _vq_quantmap__8c1_s_p9_1[] = {
  113820. 13, 11, 9, 7, 5, 3, 1, 0,
  113821. 2, 4, 6, 8, 10, 12, 14,
  113822. };
  113823. static encode_aux_threshmatch _vq_auxt__8c1_s_p9_1 = {
  113824. _vq_quantthresh__8c1_s_p9_1,
  113825. _vq_quantmap__8c1_s_p9_1,
  113826. 15,
  113827. 15
  113828. };
  113829. static static_codebook _8c1_s_p9_1 = {
  113830. 2, 225,
  113831. _vq_lengthlist__8c1_s_p9_1,
  113832. 1, -520986624, 1620377600, 4, 0,
  113833. _vq_quantlist__8c1_s_p9_1,
  113834. NULL,
  113835. &_vq_auxt__8c1_s_p9_1,
  113836. NULL,
  113837. 0
  113838. };
  113839. static long _vq_quantlist__8c1_s_p9_2[] = {
  113840. 10,
  113841. 9,
  113842. 11,
  113843. 8,
  113844. 12,
  113845. 7,
  113846. 13,
  113847. 6,
  113848. 14,
  113849. 5,
  113850. 15,
  113851. 4,
  113852. 16,
  113853. 3,
  113854. 17,
  113855. 2,
  113856. 18,
  113857. 1,
  113858. 19,
  113859. 0,
  113860. 20,
  113861. };
  113862. static long _vq_lengthlist__8c1_s_p9_2[] = {
  113863. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 9, 9, 9,
  113864. 9, 9, 9, 9, 9,11,11,12, 7, 7, 7, 7, 8, 8, 9, 9,
  113865. 9, 9,10,10,10,10,10,10,10,10,11,11,11, 7, 7, 7,
  113866. 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,11,
  113867. 11,12, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,10,
  113868. 10,10,10,10,11,11,11, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  113869. 9,10,10,10,10,10,10,10,10,11,11,11, 8, 8, 8, 8,
  113870. 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,11,11,
  113871. 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,10,
  113872. 10,10,10,11,12,11, 9, 9, 8, 9, 9, 9, 9, 9,10,10,
  113873. 10,10,10,10,10,10,10,10,11,11,11,11,11, 8, 8, 9,
  113874. 9, 9, 9,10,10,10,10,10,10,10,10,10,10,11,12,11,
  113875. 12,11, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  113876. 10,10,11,11,11,11,11, 9, 9, 9, 9,10,10,10,10,10,
  113877. 10,10,10,10,10,10,10,12,11,12,11,11, 9, 9, 9,10,
  113878. 10,10,10,10,10,10,10,10,10,10,10,10,12,11,11,11,
  113879. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113880. 11,11,11,12,11,11,12,11,10,10,10,10,10,10,10,10,
  113881. 10,10,10,10,11,10,11,11,11,11,11,11,11,10,10,10,
  113882. 10,10,10,10,10,10,10,10,10,10,10,11,11,12,11,12,
  113883. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113884. 11,11,12,11,12,11,11,11,11,10,10,10,10,10,10,10,
  113885. 10,10,10,10,10,11,11,12,11,11,12,11,11,12,10,10,
  113886. 11,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
  113887. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,12,
  113888. 12,11,12,11,11,12,12,12,11,11,10,10,10,10,10,10,
  113889. 10,10,10,11,12,12,11,12,12,11,12,11,11,11,11,10,
  113890. 10,10,10,10,10,10,10,10,10,
  113891. };
  113892. static float _vq_quantthresh__8c1_s_p9_2[] = {
  113893. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  113894. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  113895. 6.5, 7.5, 8.5, 9.5,
  113896. };
  113897. static long _vq_quantmap__8c1_s_p9_2[] = {
  113898. 19, 17, 15, 13, 11, 9, 7, 5,
  113899. 3, 1, 0, 2, 4, 6, 8, 10,
  113900. 12, 14, 16, 18, 20,
  113901. };
  113902. static encode_aux_threshmatch _vq_auxt__8c1_s_p9_2 = {
  113903. _vq_quantthresh__8c1_s_p9_2,
  113904. _vq_quantmap__8c1_s_p9_2,
  113905. 21,
  113906. 21
  113907. };
  113908. static static_codebook _8c1_s_p9_2 = {
  113909. 2, 441,
  113910. _vq_lengthlist__8c1_s_p9_2,
  113911. 1, -529268736, 1611661312, 5, 0,
  113912. _vq_quantlist__8c1_s_p9_2,
  113913. NULL,
  113914. &_vq_auxt__8c1_s_p9_2,
  113915. NULL,
  113916. 0
  113917. };
  113918. static long _huff_lengthlist__8c1_s_single[] = {
  113919. 4, 6,18, 8,11, 8, 8, 9, 9,10, 4, 4,18, 5, 9, 5,
  113920. 6, 7, 8,10,18,18,18,18,17,17,17,17,17,17, 7, 5,
  113921. 17, 6,11, 6, 7, 8, 9,12,12, 9,17,12, 8, 8, 9,10,
  113922. 10,13, 7, 5,17, 6, 8, 4, 5, 6, 8,10, 6, 5,17, 6,
  113923. 8, 5, 4, 5, 7, 9, 7, 7,17, 8, 9, 6, 5, 5, 6, 8,
  113924. 8, 8,17, 9,11, 8, 6, 6, 6, 7, 9,10,17,12,12,10,
  113925. 9, 7, 7, 8,
  113926. };
  113927. static static_codebook _huff_book__8c1_s_single = {
  113928. 2, 100,
  113929. _huff_lengthlist__8c1_s_single,
  113930. 0, 0, 0, 0, 0,
  113931. NULL,
  113932. NULL,
  113933. NULL,
  113934. NULL,
  113935. 0
  113936. };
  113937. static long _huff_lengthlist__44c2_s_long[] = {
  113938. 6, 6,12,10,10,10, 9,10,12,12, 6, 1,10, 5, 6, 6,
  113939. 7, 9,11,14,12, 9, 8,11, 7, 8, 9,11,13,15,10, 5,
  113940. 12, 7, 8, 7, 9,12,14,15,10, 6, 7, 8, 5, 6, 7, 9,
  113941. 12,14, 9, 6, 8, 7, 6, 6, 7, 9,12,12, 9, 7, 9, 9,
  113942. 7, 6, 6, 7,10,10,10, 9,10,11, 8, 7, 6, 6, 8,10,
  113943. 12,11,13,13,11,10, 8, 8, 8,10,11,13,15,15,14,13,
  113944. 10, 8, 8, 9,
  113945. };
  113946. static static_codebook _huff_book__44c2_s_long = {
  113947. 2, 100,
  113948. _huff_lengthlist__44c2_s_long,
  113949. 0, 0, 0, 0, 0,
  113950. NULL,
  113951. NULL,
  113952. NULL,
  113953. NULL,
  113954. 0
  113955. };
  113956. static long _vq_quantlist__44c2_s_p1_0[] = {
  113957. 1,
  113958. 0,
  113959. 2,
  113960. };
  113961. static long _vq_lengthlist__44c2_s_p1_0[] = {
  113962. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0,
  113963. 0, 0, 5, 6, 7, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  113968. 0, 0, 0, 6, 8, 8, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0,
  113973. 0, 0, 0, 0, 7, 8, 8, 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, 5, 7, 7, 0, 0, 0, 0,
  114008. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 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, 7, 8, 8, 0, 0, 0,
  114013. 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 6, 8, 8, 0, 0,
  114018. 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  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, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  114054. 0, 0, 0, 0, 7, 8, 8, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  114059. 0, 0, 0, 0, 0, 8, 8, 9, 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, 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  114064. 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  114065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114278. 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114286. 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  114373. };
  114374. static float _vq_quantthresh__44c2_s_p1_0[] = {
  114375. -0.5, 0.5,
  114376. };
  114377. static long _vq_quantmap__44c2_s_p1_0[] = {
  114378. 1, 0, 2,
  114379. };
  114380. static encode_aux_threshmatch _vq_auxt__44c2_s_p1_0 = {
  114381. _vq_quantthresh__44c2_s_p1_0,
  114382. _vq_quantmap__44c2_s_p1_0,
  114383. 3,
  114384. 3
  114385. };
  114386. static static_codebook _44c2_s_p1_0 = {
  114387. 8, 6561,
  114388. _vq_lengthlist__44c2_s_p1_0,
  114389. 1, -535822336, 1611661312, 2, 0,
  114390. _vq_quantlist__44c2_s_p1_0,
  114391. NULL,
  114392. &_vq_auxt__44c2_s_p1_0,
  114393. NULL,
  114394. 0
  114395. };
  114396. static long _vq_quantlist__44c2_s_p2_0[] = {
  114397. 2,
  114398. 1,
  114399. 3,
  114400. 0,
  114401. 4,
  114402. };
  114403. static long _vq_lengthlist__44c2_s_p2_0[] = {
  114404. 1, 4, 4, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0,
  114405. 8, 8, 0, 0, 0, 0, 0, 0, 0, 4, 6, 6, 0, 0, 0, 8,
  114406. 8, 0, 0, 0, 8, 8, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0,
  114407. 0, 0, 4, 6, 6, 0, 0, 0, 8, 8, 0, 0, 0, 8, 8, 0,
  114408. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114413. 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,11,11, 0, 0,
  114414. 0,11,11, 0, 0, 0,12,11, 0, 0, 0, 0, 0, 0, 0, 7,
  114415. 8, 8, 0, 0, 0,10,11, 0, 0, 0,11,11, 0, 0, 0,11,
  114416. 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114421. 0, 0, 0, 6, 8, 8, 0, 0, 0,11,11, 0, 0, 0,11,11,
  114422. 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0,
  114423. 0, 0,10,11, 0, 0, 0,10,11, 0, 0, 0,11,11, 0, 0,
  114424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114429. 8, 9, 9, 0, 0, 0,11,12, 0, 0, 0,11,12, 0, 0, 0,
  114430. 12,11, 0, 0, 0, 0, 0, 0, 0, 8,10, 9, 0, 0, 0,12,
  114431. 11, 0, 0, 0,12,11, 0, 0, 0,11,12, 0, 0, 0, 0, 0,
  114432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114443. 0,
  114444. };
  114445. static float _vq_quantthresh__44c2_s_p2_0[] = {
  114446. -1.5, -0.5, 0.5, 1.5,
  114447. };
  114448. static long _vq_quantmap__44c2_s_p2_0[] = {
  114449. 3, 1, 0, 2, 4,
  114450. };
  114451. static encode_aux_threshmatch _vq_auxt__44c2_s_p2_0 = {
  114452. _vq_quantthresh__44c2_s_p2_0,
  114453. _vq_quantmap__44c2_s_p2_0,
  114454. 5,
  114455. 5
  114456. };
  114457. static static_codebook _44c2_s_p2_0 = {
  114458. 4, 625,
  114459. _vq_lengthlist__44c2_s_p2_0,
  114460. 1, -533725184, 1611661312, 3, 0,
  114461. _vq_quantlist__44c2_s_p2_0,
  114462. NULL,
  114463. &_vq_auxt__44c2_s_p2_0,
  114464. NULL,
  114465. 0
  114466. };
  114467. static long _vq_quantlist__44c2_s_p3_0[] = {
  114468. 2,
  114469. 1,
  114470. 3,
  114471. 0,
  114472. 4,
  114473. };
  114474. static long _vq_lengthlist__44c2_s_p3_0[] = {
  114475. 2, 4, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  114477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114478. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  114480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114481. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  114482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114514. 0,
  114515. };
  114516. static float _vq_quantthresh__44c2_s_p3_0[] = {
  114517. -1.5, -0.5, 0.5, 1.5,
  114518. };
  114519. static long _vq_quantmap__44c2_s_p3_0[] = {
  114520. 3, 1, 0, 2, 4,
  114521. };
  114522. static encode_aux_threshmatch _vq_auxt__44c2_s_p3_0 = {
  114523. _vq_quantthresh__44c2_s_p3_0,
  114524. _vq_quantmap__44c2_s_p3_0,
  114525. 5,
  114526. 5
  114527. };
  114528. static static_codebook _44c2_s_p3_0 = {
  114529. 4, 625,
  114530. _vq_lengthlist__44c2_s_p3_0,
  114531. 1, -533725184, 1611661312, 3, 0,
  114532. _vq_quantlist__44c2_s_p3_0,
  114533. NULL,
  114534. &_vq_auxt__44c2_s_p3_0,
  114535. NULL,
  114536. 0
  114537. };
  114538. static long _vq_quantlist__44c2_s_p4_0[] = {
  114539. 4,
  114540. 3,
  114541. 5,
  114542. 2,
  114543. 6,
  114544. 1,
  114545. 7,
  114546. 0,
  114547. 8,
  114548. };
  114549. static long _vq_lengthlist__44c2_s_p4_0[] = {
  114550. 1, 3, 3, 6, 6, 0, 0, 0, 0, 0, 6, 6, 6, 6, 0, 0,
  114551. 0, 0, 0, 6, 6, 6, 6, 0, 0, 0, 0, 0, 7, 7, 6, 6,
  114552. 0, 0, 0, 0, 0, 0, 0, 6, 7, 0, 0, 0, 0, 0, 0, 0,
  114553. 7, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  114554. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114555. 0,
  114556. };
  114557. static float _vq_quantthresh__44c2_s_p4_0[] = {
  114558. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  114559. };
  114560. static long _vq_quantmap__44c2_s_p4_0[] = {
  114561. 7, 5, 3, 1, 0, 2, 4, 6,
  114562. 8,
  114563. };
  114564. static encode_aux_threshmatch _vq_auxt__44c2_s_p4_0 = {
  114565. _vq_quantthresh__44c2_s_p4_0,
  114566. _vq_quantmap__44c2_s_p4_0,
  114567. 9,
  114568. 9
  114569. };
  114570. static static_codebook _44c2_s_p4_0 = {
  114571. 2, 81,
  114572. _vq_lengthlist__44c2_s_p4_0,
  114573. 1, -531628032, 1611661312, 4, 0,
  114574. _vq_quantlist__44c2_s_p4_0,
  114575. NULL,
  114576. &_vq_auxt__44c2_s_p4_0,
  114577. NULL,
  114578. 0
  114579. };
  114580. static long _vq_quantlist__44c2_s_p5_0[] = {
  114581. 4,
  114582. 3,
  114583. 5,
  114584. 2,
  114585. 6,
  114586. 1,
  114587. 7,
  114588. 0,
  114589. 8,
  114590. };
  114591. static long _vq_lengthlist__44c2_s_p5_0[] = {
  114592. 1, 3, 3, 6, 6, 7, 7, 9, 9, 0, 7, 7, 7, 7, 7, 7,
  114593. 9, 9, 0, 7, 7, 7, 7, 7, 7, 9, 9, 0, 8, 8, 7, 7,
  114594. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  114595. 9, 9, 8, 8,10,10, 0, 0, 0, 9, 9, 8, 8,10,10, 0,
  114596. 0, 0,10,10, 9, 9,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  114597. 11,
  114598. };
  114599. static float _vq_quantthresh__44c2_s_p5_0[] = {
  114600. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  114601. };
  114602. static long _vq_quantmap__44c2_s_p5_0[] = {
  114603. 7, 5, 3, 1, 0, 2, 4, 6,
  114604. 8,
  114605. };
  114606. static encode_aux_threshmatch _vq_auxt__44c2_s_p5_0 = {
  114607. _vq_quantthresh__44c2_s_p5_0,
  114608. _vq_quantmap__44c2_s_p5_0,
  114609. 9,
  114610. 9
  114611. };
  114612. static static_codebook _44c2_s_p5_0 = {
  114613. 2, 81,
  114614. _vq_lengthlist__44c2_s_p5_0,
  114615. 1, -531628032, 1611661312, 4, 0,
  114616. _vq_quantlist__44c2_s_p5_0,
  114617. NULL,
  114618. &_vq_auxt__44c2_s_p5_0,
  114619. NULL,
  114620. 0
  114621. };
  114622. static long _vq_quantlist__44c2_s_p6_0[] = {
  114623. 8,
  114624. 7,
  114625. 9,
  114626. 6,
  114627. 10,
  114628. 5,
  114629. 11,
  114630. 4,
  114631. 12,
  114632. 3,
  114633. 13,
  114634. 2,
  114635. 14,
  114636. 1,
  114637. 15,
  114638. 0,
  114639. 16,
  114640. };
  114641. static long _vq_lengthlist__44c2_s_p6_0[] = {
  114642. 1, 4, 3, 6, 6, 8, 8, 9, 9, 9, 9, 9, 9,10,10,11,
  114643. 11, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  114644. 12,11, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  114645. 11,11,12, 0, 8, 8, 7, 7, 9, 9,10,10, 9, 9,10,10,
  114646. 11,11,12,12, 0, 0, 0, 7, 7, 9, 9,10,10,10, 9,10,
  114647. 10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  114648. 11,11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  114649. 10,11,11,12,12,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  114650. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  114651. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  114652. 10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  114653. 9,10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  114654. 10,10,10,10,11,11,12,12,13,12,13,13, 0, 0, 0, 0,
  114655. 0, 0, 0,10,10,11,11,12,12,13,13,13,13, 0, 0, 0,
  114656. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0, 0,
  114657. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0,
  114658. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  114659. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,13,13,14,
  114660. 14,
  114661. };
  114662. static float _vq_quantthresh__44c2_s_p6_0[] = {
  114663. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  114664. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  114665. };
  114666. static long _vq_quantmap__44c2_s_p6_0[] = {
  114667. 15, 13, 11, 9, 7, 5, 3, 1,
  114668. 0, 2, 4, 6, 8, 10, 12, 14,
  114669. 16,
  114670. };
  114671. static encode_aux_threshmatch _vq_auxt__44c2_s_p6_0 = {
  114672. _vq_quantthresh__44c2_s_p6_0,
  114673. _vq_quantmap__44c2_s_p6_0,
  114674. 17,
  114675. 17
  114676. };
  114677. static static_codebook _44c2_s_p6_0 = {
  114678. 2, 289,
  114679. _vq_lengthlist__44c2_s_p6_0,
  114680. 1, -529530880, 1611661312, 5, 0,
  114681. _vq_quantlist__44c2_s_p6_0,
  114682. NULL,
  114683. &_vq_auxt__44c2_s_p6_0,
  114684. NULL,
  114685. 0
  114686. };
  114687. static long _vq_quantlist__44c2_s_p7_0[] = {
  114688. 1,
  114689. 0,
  114690. 2,
  114691. };
  114692. static long _vq_lengthlist__44c2_s_p7_0[] = {
  114693. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  114694. 9, 9, 4, 7, 7,10, 9, 9,10, 9, 9, 7,10,10,11,10,
  114695. 11,11,10,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  114696. 11,10,11,11,10,10, 7,11,10,11,11,11,12,11,11, 6,
  114697. 9, 9,11,10,10,11,11,10, 6, 9, 9,11,10,10,12,10,
  114698. 11,
  114699. };
  114700. static float _vq_quantthresh__44c2_s_p7_0[] = {
  114701. -5.5, 5.5,
  114702. };
  114703. static long _vq_quantmap__44c2_s_p7_0[] = {
  114704. 1, 0, 2,
  114705. };
  114706. static encode_aux_threshmatch _vq_auxt__44c2_s_p7_0 = {
  114707. _vq_quantthresh__44c2_s_p7_0,
  114708. _vq_quantmap__44c2_s_p7_0,
  114709. 3,
  114710. 3
  114711. };
  114712. static static_codebook _44c2_s_p7_0 = {
  114713. 4, 81,
  114714. _vq_lengthlist__44c2_s_p7_0,
  114715. 1, -529137664, 1618345984, 2, 0,
  114716. _vq_quantlist__44c2_s_p7_0,
  114717. NULL,
  114718. &_vq_auxt__44c2_s_p7_0,
  114719. NULL,
  114720. 0
  114721. };
  114722. static long _vq_quantlist__44c2_s_p7_1[] = {
  114723. 5,
  114724. 4,
  114725. 6,
  114726. 3,
  114727. 7,
  114728. 2,
  114729. 8,
  114730. 1,
  114731. 9,
  114732. 0,
  114733. 10,
  114734. };
  114735. static long _vq_lengthlist__44c2_s_p7_1[] = {
  114736. 2, 3, 4, 6, 6, 7, 7, 7, 7, 7, 7, 9, 7, 7, 6, 6,
  114737. 7, 7, 8, 8, 8, 8, 9, 6, 6, 6, 6, 7, 7, 8, 8, 8,
  114738. 8,10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  114739. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  114740. 8, 8,10,10,10, 7, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  114741. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  114742. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  114743. 10,10,10, 8, 8, 8, 8, 8, 8,
  114744. };
  114745. static float _vq_quantthresh__44c2_s_p7_1[] = {
  114746. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  114747. 3.5, 4.5,
  114748. };
  114749. static long _vq_quantmap__44c2_s_p7_1[] = {
  114750. 9, 7, 5, 3, 1, 0, 2, 4,
  114751. 6, 8, 10,
  114752. };
  114753. static encode_aux_threshmatch _vq_auxt__44c2_s_p7_1 = {
  114754. _vq_quantthresh__44c2_s_p7_1,
  114755. _vq_quantmap__44c2_s_p7_1,
  114756. 11,
  114757. 11
  114758. };
  114759. static static_codebook _44c2_s_p7_1 = {
  114760. 2, 121,
  114761. _vq_lengthlist__44c2_s_p7_1,
  114762. 1, -531365888, 1611661312, 4, 0,
  114763. _vq_quantlist__44c2_s_p7_1,
  114764. NULL,
  114765. &_vq_auxt__44c2_s_p7_1,
  114766. NULL,
  114767. 0
  114768. };
  114769. static long _vq_quantlist__44c2_s_p8_0[] = {
  114770. 6,
  114771. 5,
  114772. 7,
  114773. 4,
  114774. 8,
  114775. 3,
  114776. 9,
  114777. 2,
  114778. 10,
  114779. 1,
  114780. 11,
  114781. 0,
  114782. 12,
  114783. };
  114784. static long _vq_lengthlist__44c2_s_p8_0[] = {
  114785. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 6, 5, 5,
  114786. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 6, 5, 7, 7, 8,
  114787. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  114788. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  114789. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  114790. 13, 9, 9,10,10,10,10,11,11,12,12, 0, 0, 0,10,10,
  114791. 10,10,11,11,12,12,12,13, 0, 0, 0,10,10,10,10,11,
  114792. 11,12,12,12,12, 0, 0, 0,14,14,10,11,11,11,12,12,
  114793. 13,13, 0, 0, 0,14,14,11,10,11,11,13,12,13,13, 0,
  114794. 0, 0, 0, 0,12,12,11,12,13,12,14,14, 0, 0, 0, 0,
  114795. 0,12,12,12,12,13,12,14,14,
  114796. };
  114797. static float _vq_quantthresh__44c2_s_p8_0[] = {
  114798. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  114799. 12.5, 17.5, 22.5, 27.5,
  114800. };
  114801. static long _vq_quantmap__44c2_s_p8_0[] = {
  114802. 11, 9, 7, 5, 3, 1, 0, 2,
  114803. 4, 6, 8, 10, 12,
  114804. };
  114805. static encode_aux_threshmatch _vq_auxt__44c2_s_p8_0 = {
  114806. _vq_quantthresh__44c2_s_p8_0,
  114807. _vq_quantmap__44c2_s_p8_0,
  114808. 13,
  114809. 13
  114810. };
  114811. static static_codebook _44c2_s_p8_0 = {
  114812. 2, 169,
  114813. _vq_lengthlist__44c2_s_p8_0,
  114814. 1, -526516224, 1616117760, 4, 0,
  114815. _vq_quantlist__44c2_s_p8_0,
  114816. NULL,
  114817. &_vq_auxt__44c2_s_p8_0,
  114818. NULL,
  114819. 0
  114820. };
  114821. static long _vq_quantlist__44c2_s_p8_1[] = {
  114822. 2,
  114823. 1,
  114824. 3,
  114825. 0,
  114826. 4,
  114827. };
  114828. static long _vq_lengthlist__44c2_s_p8_1[] = {
  114829. 2, 4, 4, 5, 4, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  114830. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  114831. };
  114832. static float _vq_quantthresh__44c2_s_p8_1[] = {
  114833. -1.5, -0.5, 0.5, 1.5,
  114834. };
  114835. static long _vq_quantmap__44c2_s_p8_1[] = {
  114836. 3, 1, 0, 2, 4,
  114837. };
  114838. static encode_aux_threshmatch _vq_auxt__44c2_s_p8_1 = {
  114839. _vq_quantthresh__44c2_s_p8_1,
  114840. _vq_quantmap__44c2_s_p8_1,
  114841. 5,
  114842. 5
  114843. };
  114844. static static_codebook _44c2_s_p8_1 = {
  114845. 2, 25,
  114846. _vq_lengthlist__44c2_s_p8_1,
  114847. 1, -533725184, 1611661312, 3, 0,
  114848. _vq_quantlist__44c2_s_p8_1,
  114849. NULL,
  114850. &_vq_auxt__44c2_s_p8_1,
  114851. NULL,
  114852. 0
  114853. };
  114854. static long _vq_quantlist__44c2_s_p9_0[] = {
  114855. 6,
  114856. 5,
  114857. 7,
  114858. 4,
  114859. 8,
  114860. 3,
  114861. 9,
  114862. 2,
  114863. 10,
  114864. 1,
  114865. 11,
  114866. 0,
  114867. 12,
  114868. };
  114869. static long _vq_lengthlist__44c2_s_p9_0[] = {
  114870. 1, 5, 4,12,12,12,12,12,12,12,12,12,12, 4, 9, 8,
  114871. 11,11,11,11,11,11,11,11,11,11, 2, 8, 7,11,11,11,
  114872. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114873. 11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,
  114874. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114875. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114876. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114877. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114878. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114879. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114880. 11,11,11,11,11,11,11,11,11,
  114881. };
  114882. static float _vq_quantthresh__44c2_s_p9_0[] = {
  114883. -1215.5, -994.5, -773.5, -552.5, -331.5, -110.5, 110.5, 331.5,
  114884. 552.5, 773.5, 994.5, 1215.5,
  114885. };
  114886. static long _vq_quantmap__44c2_s_p9_0[] = {
  114887. 11, 9, 7, 5, 3, 1, 0, 2,
  114888. 4, 6, 8, 10, 12,
  114889. };
  114890. static encode_aux_threshmatch _vq_auxt__44c2_s_p9_0 = {
  114891. _vq_quantthresh__44c2_s_p9_0,
  114892. _vq_quantmap__44c2_s_p9_0,
  114893. 13,
  114894. 13
  114895. };
  114896. static static_codebook _44c2_s_p9_0 = {
  114897. 2, 169,
  114898. _vq_lengthlist__44c2_s_p9_0,
  114899. 1, -514541568, 1627103232, 4, 0,
  114900. _vq_quantlist__44c2_s_p9_0,
  114901. NULL,
  114902. &_vq_auxt__44c2_s_p9_0,
  114903. NULL,
  114904. 0
  114905. };
  114906. static long _vq_quantlist__44c2_s_p9_1[] = {
  114907. 6,
  114908. 5,
  114909. 7,
  114910. 4,
  114911. 8,
  114912. 3,
  114913. 9,
  114914. 2,
  114915. 10,
  114916. 1,
  114917. 11,
  114918. 0,
  114919. 12,
  114920. };
  114921. static long _vq_lengthlist__44c2_s_p9_1[] = {
  114922. 1, 4, 4, 6, 6, 7, 6, 8, 8,10, 9,10,10, 6, 5, 5,
  114923. 7, 7, 8, 7,10, 9,11,11,12,13, 6, 5, 5, 7, 7, 8,
  114924. 8,10,10,11,11,13,13,18, 8, 8, 8, 8, 9, 9,10,10,
  114925. 12,12,12,13,18, 8, 8, 8, 8, 9, 9,10,10,12,12,13,
  114926. 13,18,11,11, 8, 8,10,10,11,11,12,11,13,12,18,11,
  114927. 11, 9, 7,10,10,11,11,11,12,12,13,17,17,17,10,10,
  114928. 11,11,12,12,12,10,12,12,17,17,17,11,10,11,10,13,
  114929. 12,11,12,12,12,17,17,17,15,14,11,11,12,11,13,10,
  114930. 13,12,17,17,17,14,14,12,10,11,11,13,13,13,13,17,
  114931. 17,16,17,16,13,13,12,10,13,10,14,13,17,16,17,16,
  114932. 17,13,12,12,10,13,11,14,14,
  114933. };
  114934. static float _vq_quantthresh__44c2_s_p9_1[] = {
  114935. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  114936. 42.5, 59.5, 76.5, 93.5,
  114937. };
  114938. static long _vq_quantmap__44c2_s_p9_1[] = {
  114939. 11, 9, 7, 5, 3, 1, 0, 2,
  114940. 4, 6, 8, 10, 12,
  114941. };
  114942. static encode_aux_threshmatch _vq_auxt__44c2_s_p9_1 = {
  114943. _vq_quantthresh__44c2_s_p9_1,
  114944. _vq_quantmap__44c2_s_p9_1,
  114945. 13,
  114946. 13
  114947. };
  114948. static static_codebook _44c2_s_p9_1 = {
  114949. 2, 169,
  114950. _vq_lengthlist__44c2_s_p9_1,
  114951. 1, -522616832, 1620115456, 4, 0,
  114952. _vq_quantlist__44c2_s_p9_1,
  114953. NULL,
  114954. &_vq_auxt__44c2_s_p9_1,
  114955. NULL,
  114956. 0
  114957. };
  114958. static long _vq_quantlist__44c2_s_p9_2[] = {
  114959. 8,
  114960. 7,
  114961. 9,
  114962. 6,
  114963. 10,
  114964. 5,
  114965. 11,
  114966. 4,
  114967. 12,
  114968. 3,
  114969. 13,
  114970. 2,
  114971. 14,
  114972. 1,
  114973. 15,
  114974. 0,
  114975. 16,
  114976. };
  114977. static long _vq_lengthlist__44c2_s_p9_2[] = {
  114978. 2, 4, 4, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8,
  114979. 8,10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  114980. 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9,
  114981. 9, 9, 9,10, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,
  114982. 9, 9, 9, 9,10,10,10, 8, 7, 8, 8, 8, 8, 9, 9, 9,
  114983. 9, 9, 9, 9, 9,10,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  114984. 9, 9,10, 9, 9, 9,10,11,10, 8, 8, 8, 8, 9, 9, 9,
  114985. 9, 9, 9, 9,10,10,10,10,11,10, 8, 8, 9, 9, 9, 9,
  114986. 9, 9,10, 9, 9,10, 9,10,11,10,11,11,11, 8, 8, 9,
  114987. 9, 9, 9, 9, 9, 9, 9,10,10,11,11,11,11,11, 9, 9,
  114988. 9, 9, 9, 9,10, 9, 9, 9,10,10,11,11,11,11,11, 9,
  114989. 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,11,11,11,11,11,
  114990. 9, 9, 9, 9,10,10, 9, 9, 9,10,10,10,11,11,11,11,
  114991. 11,11,11, 9, 9, 9,10, 9, 9,10,10,10,10,11,11,10,
  114992. 11,11,11,11,10, 9,10,10, 9, 9, 9, 9,10,10,11,10,
  114993. 11,11,11,11,11, 9, 9, 9, 9,10, 9,10,10,10,10,11,
  114994. 10,11,11,11,11,11,10,10, 9, 9,10, 9,10,10,10,10,
  114995. 10,10,10,11,11,11,11,11,11, 9, 9,10, 9,10, 9,10,
  114996. 10,
  114997. };
  114998. static float _vq_quantthresh__44c2_s_p9_2[] = {
  114999. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  115000. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  115001. };
  115002. static long _vq_quantmap__44c2_s_p9_2[] = {
  115003. 15, 13, 11, 9, 7, 5, 3, 1,
  115004. 0, 2, 4, 6, 8, 10, 12, 14,
  115005. 16,
  115006. };
  115007. static encode_aux_threshmatch _vq_auxt__44c2_s_p9_2 = {
  115008. _vq_quantthresh__44c2_s_p9_2,
  115009. _vq_quantmap__44c2_s_p9_2,
  115010. 17,
  115011. 17
  115012. };
  115013. static static_codebook _44c2_s_p9_2 = {
  115014. 2, 289,
  115015. _vq_lengthlist__44c2_s_p9_2,
  115016. 1, -529530880, 1611661312, 5, 0,
  115017. _vq_quantlist__44c2_s_p9_2,
  115018. NULL,
  115019. &_vq_auxt__44c2_s_p9_2,
  115020. NULL,
  115021. 0
  115022. };
  115023. static long _huff_lengthlist__44c2_s_short[] = {
  115024. 11, 9,13,12,12,11,12,12,13,15, 8, 2,11, 4, 8, 5,
  115025. 7,10,12,15,13, 7,10, 9, 8, 8,10,13,17,17,11, 4,
  115026. 12, 5, 9, 5, 8,11,14,16,12, 6, 8, 7, 6, 6, 8,11,
  115027. 13,16,11, 4, 9, 5, 6, 4, 6,10,13,16,11, 6,11, 7,
  115028. 7, 6, 7,10,13,15,13, 9,12, 9, 8, 6, 8,10,12,14,
  115029. 14,10,10, 8, 6, 5, 6, 9,11,13,15,11,11, 9, 6, 5,
  115030. 6, 8, 9,12,
  115031. };
  115032. static static_codebook _huff_book__44c2_s_short = {
  115033. 2, 100,
  115034. _huff_lengthlist__44c2_s_short,
  115035. 0, 0, 0, 0, 0,
  115036. NULL,
  115037. NULL,
  115038. NULL,
  115039. NULL,
  115040. 0
  115041. };
  115042. static long _huff_lengthlist__44c3_s_long[] = {
  115043. 5, 6,11,11,11,11,10,10,12,11, 5, 2,11, 5, 6, 6,
  115044. 7, 9,11,13,13,10, 7,11, 6, 7, 8, 9,10,12,11, 5,
  115045. 11, 6, 8, 7, 9,11,14,15,11, 6, 6, 8, 4, 5, 7, 8,
  115046. 10,13,10, 5, 7, 7, 5, 5, 6, 8,10,11,10, 7, 7, 8,
  115047. 6, 5, 5, 7, 9, 9,11, 8, 8,11, 8, 7, 6, 6, 7, 9,
  115048. 12,11,10,13, 9, 9, 7, 7, 7, 9,11,13,12,15,12,11,
  115049. 9, 8, 8, 8,
  115050. };
  115051. static static_codebook _huff_book__44c3_s_long = {
  115052. 2, 100,
  115053. _huff_lengthlist__44c3_s_long,
  115054. 0, 0, 0, 0, 0,
  115055. NULL,
  115056. NULL,
  115057. NULL,
  115058. NULL,
  115059. 0
  115060. };
  115061. static long _vq_quantlist__44c3_s_p1_0[] = {
  115062. 1,
  115063. 0,
  115064. 2,
  115065. };
  115066. static long _vq_lengthlist__44c3_s_p1_0[] = {
  115067. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0,
  115068. 0, 0, 5, 6, 6, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  115073. 0, 0, 0, 6, 7, 8, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0,
  115078. 0, 0, 0, 0, 7, 8, 8, 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, 5, 7, 7, 0, 0, 0, 0,
  115113. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 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, 7, 8, 8, 0, 0, 0,
  115118. 0, 0, 0, 8, 8, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 6, 8, 8, 0, 0,
  115123. 0, 0, 0, 0, 7, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  115159. 0, 0, 0, 0, 7, 8, 8, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  115164. 0, 0, 0, 0, 0, 7, 8, 9, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  115169. 0, 0, 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 0,
  115170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115383. 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115391. 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  115478. };
  115479. static float _vq_quantthresh__44c3_s_p1_0[] = {
  115480. -0.5, 0.5,
  115481. };
  115482. static long _vq_quantmap__44c3_s_p1_0[] = {
  115483. 1, 0, 2,
  115484. };
  115485. static encode_aux_threshmatch _vq_auxt__44c3_s_p1_0 = {
  115486. _vq_quantthresh__44c3_s_p1_0,
  115487. _vq_quantmap__44c3_s_p1_0,
  115488. 3,
  115489. 3
  115490. };
  115491. static static_codebook _44c3_s_p1_0 = {
  115492. 8, 6561,
  115493. _vq_lengthlist__44c3_s_p1_0,
  115494. 1, -535822336, 1611661312, 2, 0,
  115495. _vq_quantlist__44c3_s_p1_0,
  115496. NULL,
  115497. &_vq_auxt__44c3_s_p1_0,
  115498. NULL,
  115499. 0
  115500. };
  115501. static long _vq_quantlist__44c3_s_p2_0[] = {
  115502. 2,
  115503. 1,
  115504. 3,
  115505. 0,
  115506. 4,
  115507. };
  115508. static long _vq_lengthlist__44c3_s_p2_0[] = {
  115509. 2, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
  115510. 7, 8, 0, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 7,
  115511. 7, 0, 0, 0, 7, 7, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  115512. 0, 0, 5, 6, 6, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0,
  115513. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115518. 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0,
  115519. 0, 7, 7, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5,
  115520. 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9,
  115521. 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115526. 0, 0, 0, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7,
  115527. 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0,
  115528. 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9, 9, 0, 0,
  115529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115534. 8,10,10, 0, 0, 0, 9, 9, 0, 0, 0, 9, 9, 0, 0, 0,
  115535. 10,10, 0, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0, 0, 9,
  115536. 9, 0, 0, 0, 9, 9, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  115537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115548. 0,
  115549. };
  115550. static float _vq_quantthresh__44c3_s_p2_0[] = {
  115551. -1.5, -0.5, 0.5, 1.5,
  115552. };
  115553. static long _vq_quantmap__44c3_s_p2_0[] = {
  115554. 3, 1, 0, 2, 4,
  115555. };
  115556. static encode_aux_threshmatch _vq_auxt__44c3_s_p2_0 = {
  115557. _vq_quantthresh__44c3_s_p2_0,
  115558. _vq_quantmap__44c3_s_p2_0,
  115559. 5,
  115560. 5
  115561. };
  115562. static static_codebook _44c3_s_p2_0 = {
  115563. 4, 625,
  115564. _vq_lengthlist__44c3_s_p2_0,
  115565. 1, -533725184, 1611661312, 3, 0,
  115566. _vq_quantlist__44c3_s_p2_0,
  115567. NULL,
  115568. &_vq_auxt__44c3_s_p2_0,
  115569. NULL,
  115570. 0
  115571. };
  115572. static long _vq_quantlist__44c3_s_p3_0[] = {
  115573. 2,
  115574. 1,
  115575. 3,
  115576. 0,
  115577. 4,
  115578. };
  115579. static long _vq_lengthlist__44c3_s_p3_0[] = {
  115580. 2, 4, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  115582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115583. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  115585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115586. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  115587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115619. 0,
  115620. };
  115621. static float _vq_quantthresh__44c3_s_p3_0[] = {
  115622. -1.5, -0.5, 0.5, 1.5,
  115623. };
  115624. static long _vq_quantmap__44c3_s_p3_0[] = {
  115625. 3, 1, 0, 2, 4,
  115626. };
  115627. static encode_aux_threshmatch _vq_auxt__44c3_s_p3_0 = {
  115628. _vq_quantthresh__44c3_s_p3_0,
  115629. _vq_quantmap__44c3_s_p3_0,
  115630. 5,
  115631. 5
  115632. };
  115633. static static_codebook _44c3_s_p3_0 = {
  115634. 4, 625,
  115635. _vq_lengthlist__44c3_s_p3_0,
  115636. 1, -533725184, 1611661312, 3, 0,
  115637. _vq_quantlist__44c3_s_p3_0,
  115638. NULL,
  115639. &_vq_auxt__44c3_s_p3_0,
  115640. NULL,
  115641. 0
  115642. };
  115643. static long _vq_quantlist__44c3_s_p4_0[] = {
  115644. 4,
  115645. 3,
  115646. 5,
  115647. 2,
  115648. 6,
  115649. 1,
  115650. 7,
  115651. 0,
  115652. 8,
  115653. };
  115654. static long _vq_lengthlist__44c3_s_p4_0[] = {
  115655. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0,
  115656. 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6,
  115657. 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0,
  115658. 7, 8, 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0,
  115659. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115660. 0,
  115661. };
  115662. static float _vq_quantthresh__44c3_s_p4_0[] = {
  115663. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  115664. };
  115665. static long _vq_quantmap__44c3_s_p4_0[] = {
  115666. 7, 5, 3, 1, 0, 2, 4, 6,
  115667. 8,
  115668. };
  115669. static encode_aux_threshmatch _vq_auxt__44c3_s_p4_0 = {
  115670. _vq_quantthresh__44c3_s_p4_0,
  115671. _vq_quantmap__44c3_s_p4_0,
  115672. 9,
  115673. 9
  115674. };
  115675. static static_codebook _44c3_s_p4_0 = {
  115676. 2, 81,
  115677. _vq_lengthlist__44c3_s_p4_0,
  115678. 1, -531628032, 1611661312, 4, 0,
  115679. _vq_quantlist__44c3_s_p4_0,
  115680. NULL,
  115681. &_vq_auxt__44c3_s_p4_0,
  115682. NULL,
  115683. 0
  115684. };
  115685. static long _vq_quantlist__44c3_s_p5_0[] = {
  115686. 4,
  115687. 3,
  115688. 5,
  115689. 2,
  115690. 6,
  115691. 1,
  115692. 7,
  115693. 0,
  115694. 8,
  115695. };
  115696. static long _vq_lengthlist__44c3_s_p5_0[] = {
  115697. 1, 3, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 7, 8,
  115698. 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  115699. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  115700. 9, 9, 9, 9,10,10, 0, 0, 0, 9, 9, 9, 9,10,10, 0,
  115701. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0,10,10,11,
  115702. 11,
  115703. };
  115704. static float _vq_quantthresh__44c3_s_p5_0[] = {
  115705. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  115706. };
  115707. static long _vq_quantmap__44c3_s_p5_0[] = {
  115708. 7, 5, 3, 1, 0, 2, 4, 6,
  115709. 8,
  115710. };
  115711. static encode_aux_threshmatch _vq_auxt__44c3_s_p5_0 = {
  115712. _vq_quantthresh__44c3_s_p5_0,
  115713. _vq_quantmap__44c3_s_p5_0,
  115714. 9,
  115715. 9
  115716. };
  115717. static static_codebook _44c3_s_p5_0 = {
  115718. 2, 81,
  115719. _vq_lengthlist__44c3_s_p5_0,
  115720. 1, -531628032, 1611661312, 4, 0,
  115721. _vq_quantlist__44c3_s_p5_0,
  115722. NULL,
  115723. &_vq_auxt__44c3_s_p5_0,
  115724. NULL,
  115725. 0
  115726. };
  115727. static long _vq_quantlist__44c3_s_p6_0[] = {
  115728. 8,
  115729. 7,
  115730. 9,
  115731. 6,
  115732. 10,
  115733. 5,
  115734. 11,
  115735. 4,
  115736. 12,
  115737. 3,
  115738. 13,
  115739. 2,
  115740. 14,
  115741. 1,
  115742. 15,
  115743. 0,
  115744. 16,
  115745. };
  115746. static long _vq_lengthlist__44c3_s_p6_0[] = {
  115747. 2, 3, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  115748. 10, 0, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,
  115749. 11,11, 0, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  115750. 10,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  115751. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  115752. 10,11,11,11,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  115753. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9,
  115754. 9,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  115755. 10,10,11,10,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  115756. 10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 8,
  115757. 9, 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 8,
  115758. 8, 9, 9,10,10,11,11,12,11,12,12, 0, 0, 0, 0, 0,
  115759. 9,10,10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0,
  115760. 0, 0, 0,10,10,10,10,11,11,12,12,13,13, 0, 0, 0,
  115761. 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0, 0,
  115762. 0, 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0,
  115763. 0, 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,13,
  115764. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,
  115765. 13,
  115766. };
  115767. static float _vq_quantthresh__44c3_s_p6_0[] = {
  115768. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  115769. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  115770. };
  115771. static long _vq_quantmap__44c3_s_p6_0[] = {
  115772. 15, 13, 11, 9, 7, 5, 3, 1,
  115773. 0, 2, 4, 6, 8, 10, 12, 14,
  115774. 16,
  115775. };
  115776. static encode_aux_threshmatch _vq_auxt__44c3_s_p6_0 = {
  115777. _vq_quantthresh__44c3_s_p6_0,
  115778. _vq_quantmap__44c3_s_p6_0,
  115779. 17,
  115780. 17
  115781. };
  115782. static static_codebook _44c3_s_p6_0 = {
  115783. 2, 289,
  115784. _vq_lengthlist__44c3_s_p6_0,
  115785. 1, -529530880, 1611661312, 5, 0,
  115786. _vq_quantlist__44c3_s_p6_0,
  115787. NULL,
  115788. &_vq_auxt__44c3_s_p6_0,
  115789. NULL,
  115790. 0
  115791. };
  115792. static long _vq_quantlist__44c3_s_p7_0[] = {
  115793. 1,
  115794. 0,
  115795. 2,
  115796. };
  115797. static long _vq_lengthlist__44c3_s_p7_0[] = {
  115798. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  115799. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  115800. 10,12,11,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  115801. 11,10,10,11,10,10, 7,11,11,11,11,11,12,11,11, 6,
  115802. 9, 9,11,10,10,11,10,10, 6, 9, 9,11,10,10,11,10,
  115803. 10,
  115804. };
  115805. static float _vq_quantthresh__44c3_s_p7_0[] = {
  115806. -5.5, 5.5,
  115807. };
  115808. static long _vq_quantmap__44c3_s_p7_0[] = {
  115809. 1, 0, 2,
  115810. };
  115811. static encode_aux_threshmatch _vq_auxt__44c3_s_p7_0 = {
  115812. _vq_quantthresh__44c3_s_p7_0,
  115813. _vq_quantmap__44c3_s_p7_0,
  115814. 3,
  115815. 3
  115816. };
  115817. static static_codebook _44c3_s_p7_0 = {
  115818. 4, 81,
  115819. _vq_lengthlist__44c3_s_p7_0,
  115820. 1, -529137664, 1618345984, 2, 0,
  115821. _vq_quantlist__44c3_s_p7_0,
  115822. NULL,
  115823. &_vq_auxt__44c3_s_p7_0,
  115824. NULL,
  115825. 0
  115826. };
  115827. static long _vq_quantlist__44c3_s_p7_1[] = {
  115828. 5,
  115829. 4,
  115830. 6,
  115831. 3,
  115832. 7,
  115833. 2,
  115834. 8,
  115835. 1,
  115836. 9,
  115837. 0,
  115838. 10,
  115839. };
  115840. static long _vq_lengthlist__44c3_s_p7_1[] = {
  115841. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  115842. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  115843. 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  115844. 7, 8, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  115845. 8, 8,10,10,10, 7, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  115846. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  115847. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 9, 8,10,10,
  115848. 10,10,10, 8, 8, 8, 8, 8, 8,
  115849. };
  115850. static float _vq_quantthresh__44c3_s_p7_1[] = {
  115851. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  115852. 3.5, 4.5,
  115853. };
  115854. static long _vq_quantmap__44c3_s_p7_1[] = {
  115855. 9, 7, 5, 3, 1, 0, 2, 4,
  115856. 6, 8, 10,
  115857. };
  115858. static encode_aux_threshmatch _vq_auxt__44c3_s_p7_1 = {
  115859. _vq_quantthresh__44c3_s_p7_1,
  115860. _vq_quantmap__44c3_s_p7_1,
  115861. 11,
  115862. 11
  115863. };
  115864. static static_codebook _44c3_s_p7_1 = {
  115865. 2, 121,
  115866. _vq_lengthlist__44c3_s_p7_1,
  115867. 1, -531365888, 1611661312, 4, 0,
  115868. _vq_quantlist__44c3_s_p7_1,
  115869. NULL,
  115870. &_vq_auxt__44c3_s_p7_1,
  115871. NULL,
  115872. 0
  115873. };
  115874. static long _vq_quantlist__44c3_s_p8_0[] = {
  115875. 6,
  115876. 5,
  115877. 7,
  115878. 4,
  115879. 8,
  115880. 3,
  115881. 9,
  115882. 2,
  115883. 10,
  115884. 1,
  115885. 11,
  115886. 0,
  115887. 12,
  115888. };
  115889. static long _vq_lengthlist__44c3_s_p8_0[] = {
  115890. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  115891. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 5, 7, 7, 8,
  115892. 8, 8, 8, 9, 9,11,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  115893. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  115894. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,12, 0,13,
  115895. 13, 9, 9,10,10,10,10,11,11,12,12, 0, 0, 0,10,10,
  115896. 10,10,11,11,12,12,12,12, 0, 0, 0,10,10,10,10,11,
  115897. 11,12,12,12,12, 0, 0, 0,14,14,11,11,11,11,12,12,
  115898. 13,13, 0, 0, 0,14,14,11,11,11,11,12,12,13,13, 0,
  115899. 0, 0, 0, 0,12,12,12,12,13,13,14,13, 0, 0, 0, 0,
  115900. 0,13,13,12,12,13,12,14,13,
  115901. };
  115902. static float _vq_quantthresh__44c3_s_p8_0[] = {
  115903. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  115904. 12.5, 17.5, 22.5, 27.5,
  115905. };
  115906. static long _vq_quantmap__44c3_s_p8_0[] = {
  115907. 11, 9, 7, 5, 3, 1, 0, 2,
  115908. 4, 6, 8, 10, 12,
  115909. };
  115910. static encode_aux_threshmatch _vq_auxt__44c3_s_p8_0 = {
  115911. _vq_quantthresh__44c3_s_p8_0,
  115912. _vq_quantmap__44c3_s_p8_0,
  115913. 13,
  115914. 13
  115915. };
  115916. static static_codebook _44c3_s_p8_0 = {
  115917. 2, 169,
  115918. _vq_lengthlist__44c3_s_p8_0,
  115919. 1, -526516224, 1616117760, 4, 0,
  115920. _vq_quantlist__44c3_s_p8_0,
  115921. NULL,
  115922. &_vq_auxt__44c3_s_p8_0,
  115923. NULL,
  115924. 0
  115925. };
  115926. static long _vq_quantlist__44c3_s_p8_1[] = {
  115927. 2,
  115928. 1,
  115929. 3,
  115930. 0,
  115931. 4,
  115932. };
  115933. static long _vq_lengthlist__44c3_s_p8_1[] = {
  115934. 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 4, 5, 5, 5, 6,
  115935. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  115936. };
  115937. static float _vq_quantthresh__44c3_s_p8_1[] = {
  115938. -1.5, -0.5, 0.5, 1.5,
  115939. };
  115940. static long _vq_quantmap__44c3_s_p8_1[] = {
  115941. 3, 1, 0, 2, 4,
  115942. };
  115943. static encode_aux_threshmatch _vq_auxt__44c3_s_p8_1 = {
  115944. _vq_quantthresh__44c3_s_p8_1,
  115945. _vq_quantmap__44c3_s_p8_1,
  115946. 5,
  115947. 5
  115948. };
  115949. static static_codebook _44c3_s_p8_1 = {
  115950. 2, 25,
  115951. _vq_lengthlist__44c3_s_p8_1,
  115952. 1, -533725184, 1611661312, 3, 0,
  115953. _vq_quantlist__44c3_s_p8_1,
  115954. NULL,
  115955. &_vq_auxt__44c3_s_p8_1,
  115956. NULL,
  115957. 0
  115958. };
  115959. static long _vq_quantlist__44c3_s_p9_0[] = {
  115960. 6,
  115961. 5,
  115962. 7,
  115963. 4,
  115964. 8,
  115965. 3,
  115966. 9,
  115967. 2,
  115968. 10,
  115969. 1,
  115970. 11,
  115971. 0,
  115972. 12,
  115973. };
  115974. static long _vq_lengthlist__44c3_s_p9_0[] = {
  115975. 1, 4, 4,12,12,12,12,12,12,12,12,12,12, 4, 9, 8,
  115976. 12,12,12,12,12,12,12,12,12,12, 2, 9, 7,12,12,12,
  115977. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115978. 12,12,12,12,12,12,11,12,12,12,12,12,12,12,12,12,
  115979. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115980. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115981. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115982. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115983. 12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,
  115984. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  115985. 11,11,11,11,11,11,11,11,11,
  115986. };
  115987. static float _vq_quantthresh__44c3_s_p9_0[] = {
  115988. -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5, 382.5,
  115989. 637.5, 892.5, 1147.5, 1402.5,
  115990. };
  115991. static long _vq_quantmap__44c3_s_p9_0[] = {
  115992. 11, 9, 7, 5, 3, 1, 0, 2,
  115993. 4, 6, 8, 10, 12,
  115994. };
  115995. static encode_aux_threshmatch _vq_auxt__44c3_s_p9_0 = {
  115996. _vq_quantthresh__44c3_s_p9_0,
  115997. _vq_quantmap__44c3_s_p9_0,
  115998. 13,
  115999. 13
  116000. };
  116001. static static_codebook _44c3_s_p9_0 = {
  116002. 2, 169,
  116003. _vq_lengthlist__44c3_s_p9_0,
  116004. 1, -514332672, 1627381760, 4, 0,
  116005. _vq_quantlist__44c3_s_p9_0,
  116006. NULL,
  116007. &_vq_auxt__44c3_s_p9_0,
  116008. NULL,
  116009. 0
  116010. };
  116011. static long _vq_quantlist__44c3_s_p9_1[] = {
  116012. 7,
  116013. 6,
  116014. 8,
  116015. 5,
  116016. 9,
  116017. 4,
  116018. 10,
  116019. 3,
  116020. 11,
  116021. 2,
  116022. 12,
  116023. 1,
  116024. 13,
  116025. 0,
  116026. 14,
  116027. };
  116028. static long _vq_lengthlist__44c3_s_p9_1[] = {
  116029. 1, 4, 4, 6, 6, 7, 7, 8, 7, 9, 9,10,10,10,10, 6,
  116030. 5, 5, 7, 7, 8, 8,10, 8,11,10,12,12,13,13, 6, 5,
  116031. 5, 7, 7, 8, 8,10, 9,11,11,12,12,13,12,18, 8, 8,
  116032. 8, 8, 9, 9,10, 9,11,10,12,12,13,13,18, 8, 8, 8,
  116033. 8, 9, 9,10,10,11,11,13,12,14,13,18,11,11, 9, 9,
  116034. 10,10,11,11,11,12,13,12,13,14,18,11,11, 9, 8,11,
  116035. 10,11,11,11,11,12,12,14,13,18,18,18,10,11,10,11,
  116036. 12,12,12,12,13,12,14,13,18,18,18,10,11,11, 9,12,
  116037. 11,12,12,12,13,13,13,18,18,17,14,14,11,11,12,12,
  116038. 13,12,14,12,14,13,18,18,18,14,14,11,10,12, 9,12,
  116039. 13,13,13,13,13,18,18,17,16,18,13,13,12,12,13,11,
  116040. 14,12,14,14,17,18,18,17,18,13,12,13,10,12,11,14,
  116041. 14,14,14,17,18,18,18,18,15,16,12,12,13,10,14,12,
  116042. 14,15,18,18,18,16,17,16,14,12,11,13,10,13,13,14,
  116043. 15,
  116044. };
  116045. static float _vq_quantthresh__44c3_s_p9_1[] = {
  116046. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  116047. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  116048. };
  116049. static long _vq_quantmap__44c3_s_p9_1[] = {
  116050. 13, 11, 9, 7, 5, 3, 1, 0,
  116051. 2, 4, 6, 8, 10, 12, 14,
  116052. };
  116053. static encode_aux_threshmatch _vq_auxt__44c3_s_p9_1 = {
  116054. _vq_quantthresh__44c3_s_p9_1,
  116055. _vq_quantmap__44c3_s_p9_1,
  116056. 15,
  116057. 15
  116058. };
  116059. static static_codebook _44c3_s_p9_1 = {
  116060. 2, 225,
  116061. _vq_lengthlist__44c3_s_p9_1,
  116062. 1, -522338304, 1620115456, 4, 0,
  116063. _vq_quantlist__44c3_s_p9_1,
  116064. NULL,
  116065. &_vq_auxt__44c3_s_p9_1,
  116066. NULL,
  116067. 0
  116068. };
  116069. static long _vq_quantlist__44c3_s_p9_2[] = {
  116070. 8,
  116071. 7,
  116072. 9,
  116073. 6,
  116074. 10,
  116075. 5,
  116076. 11,
  116077. 4,
  116078. 12,
  116079. 3,
  116080. 13,
  116081. 2,
  116082. 14,
  116083. 1,
  116084. 15,
  116085. 0,
  116086. 16,
  116087. };
  116088. static long _vq_lengthlist__44c3_s_p9_2[] = {
  116089. 2, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8,
  116090. 8,10, 6, 6, 7, 7, 8, 7, 8, 8, 8, 8, 8, 9, 9, 9,
  116091. 9, 9,10, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  116092. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  116093. 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 9, 9, 9, 9,
  116094. 9, 9, 9, 9, 9,11,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  116095. 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  116096. 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 9, 9, 9, 9, 9,
  116097. 9, 9, 9, 9, 9, 9,10, 9,10,10,10,11,11, 9, 9, 9,
  116098. 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,11,11,11, 9, 9,
  116099. 9, 9, 9, 9,10,10, 9, 9,10, 9,11,10,11,11,11, 9,
  116100. 9, 9, 9, 9, 9, 9, 9,10,10,10, 9,11,11,11,11,11,
  116101. 9, 9, 9, 9,10,10, 9, 9, 9, 9,10, 9,11,11,11,11,
  116102. 11,11,11, 9, 9, 9, 9, 9, 9,10,10,10,10,11,11,11,
  116103. 11,11,11,11,10, 9,10,10, 9,10, 9, 9,10, 9,11,10,
  116104. 10,11,11,11,11, 9,10, 9, 9, 9, 9,10,10,10,10,11,
  116105. 11,11,11,11,11,10,10,10, 9, 9,10, 9,10, 9,10,10,
  116106. 10,10,11,11,11,11,11,11,11, 9, 9, 9, 9, 9,10,10,
  116107. 10,
  116108. };
  116109. static float _vq_quantthresh__44c3_s_p9_2[] = {
  116110. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  116111. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  116112. };
  116113. static long _vq_quantmap__44c3_s_p9_2[] = {
  116114. 15, 13, 11, 9, 7, 5, 3, 1,
  116115. 0, 2, 4, 6, 8, 10, 12, 14,
  116116. 16,
  116117. };
  116118. static encode_aux_threshmatch _vq_auxt__44c3_s_p9_2 = {
  116119. _vq_quantthresh__44c3_s_p9_2,
  116120. _vq_quantmap__44c3_s_p9_2,
  116121. 17,
  116122. 17
  116123. };
  116124. static static_codebook _44c3_s_p9_2 = {
  116125. 2, 289,
  116126. _vq_lengthlist__44c3_s_p9_2,
  116127. 1, -529530880, 1611661312, 5, 0,
  116128. _vq_quantlist__44c3_s_p9_2,
  116129. NULL,
  116130. &_vq_auxt__44c3_s_p9_2,
  116131. NULL,
  116132. 0
  116133. };
  116134. static long _huff_lengthlist__44c3_s_short[] = {
  116135. 10, 9,13,11,14,10,12,13,13,14, 7, 2,12, 5,10, 5,
  116136. 7,10,12,14,12, 6, 9, 8, 7, 7, 9,11,13,16,10, 4,
  116137. 12, 5,10, 6, 8,12,14,16,12, 6, 8, 7, 6, 5, 7,11,
  116138. 12,16,10, 4, 8, 5, 6, 4, 6, 9,13,16,10, 6,10, 7,
  116139. 7, 6, 7, 9,13,15,12, 9,11, 9, 8, 6, 7,10,12,14,
  116140. 14,11,10, 9, 6, 5, 6, 9,11,13,15,13,11,10, 6, 5,
  116141. 6, 8, 9,11,
  116142. };
  116143. static static_codebook _huff_book__44c3_s_short = {
  116144. 2, 100,
  116145. _huff_lengthlist__44c3_s_short,
  116146. 0, 0, 0, 0, 0,
  116147. NULL,
  116148. NULL,
  116149. NULL,
  116150. NULL,
  116151. 0
  116152. };
  116153. static long _huff_lengthlist__44c4_s_long[] = {
  116154. 4, 7,11,11,11,11,10,11,12,11, 5, 2,11, 5, 6, 6,
  116155. 7, 9,11,12,11, 9, 6,10, 6, 7, 8, 9,10,11,11, 5,
  116156. 11, 7, 8, 8, 9,11,13,14,11, 6, 5, 8, 4, 5, 7, 8,
  116157. 10,11,10, 6, 7, 7, 5, 5, 6, 8, 9,11,10, 7, 8, 9,
  116158. 6, 6, 6, 7, 8, 9,11, 9, 9,11, 7, 7, 6, 6, 7, 9,
  116159. 12,12,10,13, 9, 8, 7, 7, 7, 8,11,13,11,14,11,10,
  116160. 9, 8, 7, 7,
  116161. };
  116162. static static_codebook _huff_book__44c4_s_long = {
  116163. 2, 100,
  116164. _huff_lengthlist__44c4_s_long,
  116165. 0, 0, 0, 0, 0,
  116166. NULL,
  116167. NULL,
  116168. NULL,
  116169. NULL,
  116170. 0
  116171. };
  116172. static long _vq_quantlist__44c4_s_p1_0[] = {
  116173. 1,
  116174. 0,
  116175. 2,
  116176. };
  116177. static long _vq_lengthlist__44c4_s_p1_0[] = {
  116178. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0,
  116179. 0, 0, 5, 6, 7, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  116184. 0, 0, 0, 6, 8, 8, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0,
  116189. 0, 0, 0, 0, 7, 8, 8, 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, 5, 7, 7, 0, 0, 0, 0,
  116224. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 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, 7, 8, 8, 0, 0, 0,
  116229. 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 6, 8, 8, 0, 0,
  116234. 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  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, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  116270. 0, 0, 0, 0, 7, 8, 8, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  116275. 0, 0, 0, 0, 0, 8, 8, 9, 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, 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  116280. 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  116281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116494. 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116502. 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  116589. };
  116590. static float _vq_quantthresh__44c4_s_p1_0[] = {
  116591. -0.5, 0.5,
  116592. };
  116593. static long _vq_quantmap__44c4_s_p1_0[] = {
  116594. 1, 0, 2,
  116595. };
  116596. static encode_aux_threshmatch _vq_auxt__44c4_s_p1_0 = {
  116597. _vq_quantthresh__44c4_s_p1_0,
  116598. _vq_quantmap__44c4_s_p1_0,
  116599. 3,
  116600. 3
  116601. };
  116602. static static_codebook _44c4_s_p1_0 = {
  116603. 8, 6561,
  116604. _vq_lengthlist__44c4_s_p1_0,
  116605. 1, -535822336, 1611661312, 2, 0,
  116606. _vq_quantlist__44c4_s_p1_0,
  116607. NULL,
  116608. &_vq_auxt__44c4_s_p1_0,
  116609. NULL,
  116610. 0
  116611. };
  116612. static long _vq_quantlist__44c4_s_p2_0[] = {
  116613. 2,
  116614. 1,
  116615. 3,
  116616. 0,
  116617. 4,
  116618. };
  116619. static long _vq_lengthlist__44c4_s_p2_0[] = {
  116620. 2, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
  116621. 7, 7, 0, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 7,
  116622. 7, 0, 0, 0, 7, 7, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  116623. 0, 0, 5, 6, 6, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0,
  116624. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116629. 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 7, 7, 0, 0,
  116630. 0, 7, 7, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5,
  116631. 7, 8, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9,
  116632. 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116637. 0, 0, 0, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7,
  116638. 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0,
  116639. 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9, 9, 0, 0,
  116640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116645. 7,10,10, 0, 0, 0, 9, 9, 0, 0, 0, 9, 9, 0, 0, 0,
  116646. 10,10, 0, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0, 0, 9,
  116647. 9, 0, 0, 0, 9, 9, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  116648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116659. 0,
  116660. };
  116661. static float _vq_quantthresh__44c4_s_p2_0[] = {
  116662. -1.5, -0.5, 0.5, 1.5,
  116663. };
  116664. static long _vq_quantmap__44c4_s_p2_0[] = {
  116665. 3, 1, 0, 2, 4,
  116666. };
  116667. static encode_aux_threshmatch _vq_auxt__44c4_s_p2_0 = {
  116668. _vq_quantthresh__44c4_s_p2_0,
  116669. _vq_quantmap__44c4_s_p2_0,
  116670. 5,
  116671. 5
  116672. };
  116673. static static_codebook _44c4_s_p2_0 = {
  116674. 4, 625,
  116675. _vq_lengthlist__44c4_s_p2_0,
  116676. 1, -533725184, 1611661312, 3, 0,
  116677. _vq_quantlist__44c4_s_p2_0,
  116678. NULL,
  116679. &_vq_auxt__44c4_s_p2_0,
  116680. NULL,
  116681. 0
  116682. };
  116683. static long _vq_quantlist__44c4_s_p3_0[] = {
  116684. 2,
  116685. 1,
  116686. 3,
  116687. 0,
  116688. 4,
  116689. };
  116690. static long _vq_lengthlist__44c4_s_p3_0[] = {
  116691. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 4, 6, 6, 0, 0,
  116693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116694. 0, 0, 4, 4, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  116696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116697. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  116698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116730. 0,
  116731. };
  116732. static float _vq_quantthresh__44c4_s_p3_0[] = {
  116733. -1.5, -0.5, 0.5, 1.5,
  116734. };
  116735. static long _vq_quantmap__44c4_s_p3_0[] = {
  116736. 3, 1, 0, 2, 4,
  116737. };
  116738. static encode_aux_threshmatch _vq_auxt__44c4_s_p3_0 = {
  116739. _vq_quantthresh__44c4_s_p3_0,
  116740. _vq_quantmap__44c4_s_p3_0,
  116741. 5,
  116742. 5
  116743. };
  116744. static static_codebook _44c4_s_p3_0 = {
  116745. 4, 625,
  116746. _vq_lengthlist__44c4_s_p3_0,
  116747. 1, -533725184, 1611661312, 3, 0,
  116748. _vq_quantlist__44c4_s_p3_0,
  116749. NULL,
  116750. &_vq_auxt__44c4_s_p3_0,
  116751. NULL,
  116752. 0
  116753. };
  116754. static long _vq_quantlist__44c4_s_p4_0[] = {
  116755. 4,
  116756. 3,
  116757. 5,
  116758. 2,
  116759. 6,
  116760. 1,
  116761. 7,
  116762. 0,
  116763. 8,
  116764. };
  116765. static long _vq_lengthlist__44c4_s_p4_0[] = {
  116766. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0,
  116767. 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6,
  116768. 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0,
  116769. 7, 8, 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0,
  116770. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116771. 0,
  116772. };
  116773. static float _vq_quantthresh__44c4_s_p4_0[] = {
  116774. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  116775. };
  116776. static long _vq_quantmap__44c4_s_p4_0[] = {
  116777. 7, 5, 3, 1, 0, 2, 4, 6,
  116778. 8,
  116779. };
  116780. static encode_aux_threshmatch _vq_auxt__44c4_s_p4_0 = {
  116781. _vq_quantthresh__44c4_s_p4_0,
  116782. _vq_quantmap__44c4_s_p4_0,
  116783. 9,
  116784. 9
  116785. };
  116786. static static_codebook _44c4_s_p4_0 = {
  116787. 2, 81,
  116788. _vq_lengthlist__44c4_s_p4_0,
  116789. 1, -531628032, 1611661312, 4, 0,
  116790. _vq_quantlist__44c4_s_p4_0,
  116791. NULL,
  116792. &_vq_auxt__44c4_s_p4_0,
  116793. NULL,
  116794. 0
  116795. };
  116796. static long _vq_quantlist__44c4_s_p5_0[] = {
  116797. 4,
  116798. 3,
  116799. 5,
  116800. 2,
  116801. 6,
  116802. 1,
  116803. 7,
  116804. 0,
  116805. 8,
  116806. };
  116807. static long _vq_lengthlist__44c4_s_p5_0[] = {
  116808. 2, 3, 3, 6, 6, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  116809. 9, 9, 0, 4, 5, 6, 6, 7, 7, 9, 9, 0, 6, 6, 7, 7,
  116810. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10, 9, 0, 0, 0,
  116811. 9, 8, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  116812. 0, 0,10,10, 9, 9,11,11, 0, 0, 0, 0, 0, 9, 9,10,
  116813. 10,
  116814. };
  116815. static float _vq_quantthresh__44c4_s_p5_0[] = {
  116816. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  116817. };
  116818. static long _vq_quantmap__44c4_s_p5_0[] = {
  116819. 7, 5, 3, 1, 0, 2, 4, 6,
  116820. 8,
  116821. };
  116822. static encode_aux_threshmatch _vq_auxt__44c4_s_p5_0 = {
  116823. _vq_quantthresh__44c4_s_p5_0,
  116824. _vq_quantmap__44c4_s_p5_0,
  116825. 9,
  116826. 9
  116827. };
  116828. static static_codebook _44c4_s_p5_0 = {
  116829. 2, 81,
  116830. _vq_lengthlist__44c4_s_p5_0,
  116831. 1, -531628032, 1611661312, 4, 0,
  116832. _vq_quantlist__44c4_s_p5_0,
  116833. NULL,
  116834. &_vq_auxt__44c4_s_p5_0,
  116835. NULL,
  116836. 0
  116837. };
  116838. static long _vq_quantlist__44c4_s_p6_0[] = {
  116839. 8,
  116840. 7,
  116841. 9,
  116842. 6,
  116843. 10,
  116844. 5,
  116845. 11,
  116846. 4,
  116847. 12,
  116848. 3,
  116849. 13,
  116850. 2,
  116851. 14,
  116852. 1,
  116853. 15,
  116854. 0,
  116855. 16,
  116856. };
  116857. static long _vq_lengthlist__44c4_s_p6_0[] = {
  116858. 2, 4, 4, 6, 6, 8, 8, 9, 9, 8, 8, 9, 9,10,10,11,
  116859. 11, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,11,
  116860. 11,11, 0, 4, 4, 7, 6, 8, 8, 9, 9, 9, 9,10,10,11,
  116861. 11,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  116862. 11,11,11,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  116863. 10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  116864. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9,
  116865. 9,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  116866. 10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  116867. 10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,
  116868. 9,10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9,
  116869. 9, 9, 9,10,10,11,11,11,12,12,12, 0, 0, 0, 0, 0,
  116870. 10,10,10,10,11,11,11,11,12,12,13,12, 0, 0, 0, 0,
  116871. 0, 0, 0,10,10,11,11,11,11,12,12,12,12, 0, 0, 0,
  116872. 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0, 0,
  116873. 0, 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0,
  116874. 0, 0, 0, 0, 0, 0,12,12,12,12,12,12,13,13,13,13,
  116875. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,12,13,13,
  116876. 13,
  116877. };
  116878. static float _vq_quantthresh__44c4_s_p6_0[] = {
  116879. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  116880. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  116881. };
  116882. static long _vq_quantmap__44c4_s_p6_0[] = {
  116883. 15, 13, 11, 9, 7, 5, 3, 1,
  116884. 0, 2, 4, 6, 8, 10, 12, 14,
  116885. 16,
  116886. };
  116887. static encode_aux_threshmatch _vq_auxt__44c4_s_p6_0 = {
  116888. _vq_quantthresh__44c4_s_p6_0,
  116889. _vq_quantmap__44c4_s_p6_0,
  116890. 17,
  116891. 17
  116892. };
  116893. static static_codebook _44c4_s_p6_0 = {
  116894. 2, 289,
  116895. _vq_lengthlist__44c4_s_p6_0,
  116896. 1, -529530880, 1611661312, 5, 0,
  116897. _vq_quantlist__44c4_s_p6_0,
  116898. NULL,
  116899. &_vq_auxt__44c4_s_p6_0,
  116900. NULL,
  116901. 0
  116902. };
  116903. static long _vq_quantlist__44c4_s_p7_0[] = {
  116904. 1,
  116905. 0,
  116906. 2,
  116907. };
  116908. static long _vq_lengthlist__44c4_s_p7_0[] = {
  116909. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  116910. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  116911. 10,11,11,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  116912. 11,10,10,11,10,10, 7,11,11,12,11,11,12,11,11, 6,
  116913. 9, 9,11,10,10,11,10,10, 6, 9, 9,11,10,10,11,10,
  116914. 10,
  116915. };
  116916. static float _vq_quantthresh__44c4_s_p7_0[] = {
  116917. -5.5, 5.5,
  116918. };
  116919. static long _vq_quantmap__44c4_s_p7_0[] = {
  116920. 1, 0, 2,
  116921. };
  116922. static encode_aux_threshmatch _vq_auxt__44c4_s_p7_0 = {
  116923. _vq_quantthresh__44c4_s_p7_0,
  116924. _vq_quantmap__44c4_s_p7_0,
  116925. 3,
  116926. 3
  116927. };
  116928. static static_codebook _44c4_s_p7_0 = {
  116929. 4, 81,
  116930. _vq_lengthlist__44c4_s_p7_0,
  116931. 1, -529137664, 1618345984, 2, 0,
  116932. _vq_quantlist__44c4_s_p7_0,
  116933. NULL,
  116934. &_vq_auxt__44c4_s_p7_0,
  116935. NULL,
  116936. 0
  116937. };
  116938. static long _vq_quantlist__44c4_s_p7_1[] = {
  116939. 5,
  116940. 4,
  116941. 6,
  116942. 3,
  116943. 7,
  116944. 2,
  116945. 8,
  116946. 1,
  116947. 9,
  116948. 0,
  116949. 10,
  116950. };
  116951. static long _vq_lengthlist__44c4_s_p7_1[] = {
  116952. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  116953. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  116954. 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  116955. 7, 8, 8, 8, 8, 8, 8,10,10,10, 8, 7, 8, 8, 8, 8,
  116956. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  116957. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  116958. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 9, 8,10,10,
  116959. 10,10,10, 8, 8, 8, 8, 9, 9,
  116960. };
  116961. static float _vq_quantthresh__44c4_s_p7_1[] = {
  116962. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  116963. 3.5, 4.5,
  116964. };
  116965. static long _vq_quantmap__44c4_s_p7_1[] = {
  116966. 9, 7, 5, 3, 1, 0, 2, 4,
  116967. 6, 8, 10,
  116968. };
  116969. static encode_aux_threshmatch _vq_auxt__44c4_s_p7_1 = {
  116970. _vq_quantthresh__44c4_s_p7_1,
  116971. _vq_quantmap__44c4_s_p7_1,
  116972. 11,
  116973. 11
  116974. };
  116975. static static_codebook _44c4_s_p7_1 = {
  116976. 2, 121,
  116977. _vq_lengthlist__44c4_s_p7_1,
  116978. 1, -531365888, 1611661312, 4, 0,
  116979. _vq_quantlist__44c4_s_p7_1,
  116980. NULL,
  116981. &_vq_auxt__44c4_s_p7_1,
  116982. NULL,
  116983. 0
  116984. };
  116985. static long _vq_quantlist__44c4_s_p8_0[] = {
  116986. 6,
  116987. 5,
  116988. 7,
  116989. 4,
  116990. 8,
  116991. 3,
  116992. 9,
  116993. 2,
  116994. 10,
  116995. 1,
  116996. 11,
  116997. 0,
  116998. 12,
  116999. };
  117000. static long _vq_lengthlist__44c4_s_p8_0[] = {
  117001. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  117002. 7, 7, 8, 8, 8, 8, 9,10,11,11, 7, 5, 5, 7, 7, 8,
  117003. 8, 9, 9,10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  117004. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  117005. 11, 0,12,12, 9, 9, 9, 9,10,10,10,10,11,11, 0,13,
  117006. 13, 9, 9,10, 9,10,10,11,11,11,12, 0, 0, 0,10,10,
  117007. 10,10,10,10,11,11,12,12, 0, 0, 0,10,10,10,10,10,
  117008. 10,11,11,12,12, 0, 0, 0,14,14,11,11,11,11,12,12,
  117009. 12,12, 0, 0, 0,14,14,11,11,11,11,12,12,12,13, 0,
  117010. 0, 0, 0, 0,12,12,12,12,12,12,13,13, 0, 0, 0, 0,
  117011. 0,13,12,12,12,12,12,13,13,
  117012. };
  117013. static float _vq_quantthresh__44c4_s_p8_0[] = {
  117014. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  117015. 12.5, 17.5, 22.5, 27.5,
  117016. };
  117017. static long _vq_quantmap__44c4_s_p8_0[] = {
  117018. 11, 9, 7, 5, 3, 1, 0, 2,
  117019. 4, 6, 8, 10, 12,
  117020. };
  117021. static encode_aux_threshmatch _vq_auxt__44c4_s_p8_0 = {
  117022. _vq_quantthresh__44c4_s_p8_0,
  117023. _vq_quantmap__44c4_s_p8_0,
  117024. 13,
  117025. 13
  117026. };
  117027. static static_codebook _44c4_s_p8_0 = {
  117028. 2, 169,
  117029. _vq_lengthlist__44c4_s_p8_0,
  117030. 1, -526516224, 1616117760, 4, 0,
  117031. _vq_quantlist__44c4_s_p8_0,
  117032. NULL,
  117033. &_vq_auxt__44c4_s_p8_0,
  117034. NULL,
  117035. 0
  117036. };
  117037. static long _vq_quantlist__44c4_s_p8_1[] = {
  117038. 2,
  117039. 1,
  117040. 3,
  117041. 0,
  117042. 4,
  117043. };
  117044. static long _vq_lengthlist__44c4_s_p8_1[] = {
  117045. 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 5, 4, 5, 5, 6,
  117046. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  117047. };
  117048. static float _vq_quantthresh__44c4_s_p8_1[] = {
  117049. -1.5, -0.5, 0.5, 1.5,
  117050. };
  117051. static long _vq_quantmap__44c4_s_p8_1[] = {
  117052. 3, 1, 0, 2, 4,
  117053. };
  117054. static encode_aux_threshmatch _vq_auxt__44c4_s_p8_1 = {
  117055. _vq_quantthresh__44c4_s_p8_1,
  117056. _vq_quantmap__44c4_s_p8_1,
  117057. 5,
  117058. 5
  117059. };
  117060. static static_codebook _44c4_s_p8_1 = {
  117061. 2, 25,
  117062. _vq_lengthlist__44c4_s_p8_1,
  117063. 1, -533725184, 1611661312, 3, 0,
  117064. _vq_quantlist__44c4_s_p8_1,
  117065. NULL,
  117066. &_vq_auxt__44c4_s_p8_1,
  117067. NULL,
  117068. 0
  117069. };
  117070. static long _vq_quantlist__44c4_s_p9_0[] = {
  117071. 6,
  117072. 5,
  117073. 7,
  117074. 4,
  117075. 8,
  117076. 3,
  117077. 9,
  117078. 2,
  117079. 10,
  117080. 1,
  117081. 11,
  117082. 0,
  117083. 12,
  117084. };
  117085. static long _vq_lengthlist__44c4_s_p9_0[] = {
  117086. 1, 3, 3,12,12,12,12,12,12,12,12,12,12, 4, 7, 7,
  117087. 12,12,12,12,12,12,12,12,12,12, 3, 8, 8,12,12,12,
  117088. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  117089. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  117090. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  117091. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  117092. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  117093. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  117094. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  117095. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  117096. 12,12,12,12,12,12,12,12,12,
  117097. };
  117098. static float _vq_quantthresh__44c4_s_p9_0[] = {
  117099. -1732.5, -1417.5, -1102.5, -787.5, -472.5, -157.5, 157.5, 472.5,
  117100. 787.5, 1102.5, 1417.5, 1732.5,
  117101. };
  117102. static long _vq_quantmap__44c4_s_p9_0[] = {
  117103. 11, 9, 7, 5, 3, 1, 0, 2,
  117104. 4, 6, 8, 10, 12,
  117105. };
  117106. static encode_aux_threshmatch _vq_auxt__44c4_s_p9_0 = {
  117107. _vq_quantthresh__44c4_s_p9_0,
  117108. _vq_quantmap__44c4_s_p9_0,
  117109. 13,
  117110. 13
  117111. };
  117112. static static_codebook _44c4_s_p9_0 = {
  117113. 2, 169,
  117114. _vq_lengthlist__44c4_s_p9_0,
  117115. 1, -513964032, 1628680192, 4, 0,
  117116. _vq_quantlist__44c4_s_p9_0,
  117117. NULL,
  117118. &_vq_auxt__44c4_s_p9_0,
  117119. NULL,
  117120. 0
  117121. };
  117122. static long _vq_quantlist__44c4_s_p9_1[] = {
  117123. 7,
  117124. 6,
  117125. 8,
  117126. 5,
  117127. 9,
  117128. 4,
  117129. 10,
  117130. 3,
  117131. 11,
  117132. 2,
  117133. 12,
  117134. 1,
  117135. 13,
  117136. 0,
  117137. 14,
  117138. };
  117139. static long _vq_lengthlist__44c4_s_p9_1[] = {
  117140. 1, 4, 4, 5, 5, 7, 7, 9, 8,10, 9,10,10,10,10, 6,
  117141. 5, 5, 7, 7, 9, 8,10, 9,11,10,12,12,13,13, 6, 5,
  117142. 5, 7, 7, 9, 9,10,10,11,11,12,12,12,13,19, 8, 8,
  117143. 8, 8, 9, 9,10,10,12,11,12,12,13,13,19, 8, 8, 8,
  117144. 8, 9, 9,11,11,12,12,13,13,13,13,19,12,12, 9, 9,
  117145. 11,11,11,11,12,11,13,12,13,13,18,12,12, 9, 9,11,
  117146. 10,11,11,12,12,12,13,13,14,19,18,18,11,11,11,11,
  117147. 12,12,13,12,13,13,14,14,16,18,18,11,11,11,10,12,
  117148. 11,13,13,13,13,13,14,17,18,18,14,15,11,12,12,13,
  117149. 13,13,13,14,14,14,18,18,18,15,15,12,10,13,10,13,
  117150. 13,13,13,13,14,18,17,18,17,18,12,13,12,13,13,13,
  117151. 14,14,16,14,18,17,18,18,17,13,12,13,10,12,12,14,
  117152. 14,14,14,17,18,18,18,18,14,15,12,12,13,12,14,14,
  117153. 15,15,18,18,18,17,18,15,14,12,11,12,12,14,14,14,
  117154. 15,
  117155. };
  117156. static float _vq_quantthresh__44c4_s_p9_1[] = {
  117157. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  117158. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  117159. };
  117160. static long _vq_quantmap__44c4_s_p9_1[] = {
  117161. 13, 11, 9, 7, 5, 3, 1, 0,
  117162. 2, 4, 6, 8, 10, 12, 14,
  117163. };
  117164. static encode_aux_threshmatch _vq_auxt__44c4_s_p9_1 = {
  117165. _vq_quantthresh__44c4_s_p9_1,
  117166. _vq_quantmap__44c4_s_p9_1,
  117167. 15,
  117168. 15
  117169. };
  117170. static static_codebook _44c4_s_p9_1 = {
  117171. 2, 225,
  117172. _vq_lengthlist__44c4_s_p9_1,
  117173. 1, -520986624, 1620377600, 4, 0,
  117174. _vq_quantlist__44c4_s_p9_1,
  117175. NULL,
  117176. &_vq_auxt__44c4_s_p9_1,
  117177. NULL,
  117178. 0
  117179. };
  117180. static long _vq_quantlist__44c4_s_p9_2[] = {
  117181. 10,
  117182. 9,
  117183. 11,
  117184. 8,
  117185. 12,
  117186. 7,
  117187. 13,
  117188. 6,
  117189. 14,
  117190. 5,
  117191. 15,
  117192. 4,
  117193. 16,
  117194. 3,
  117195. 17,
  117196. 2,
  117197. 18,
  117198. 1,
  117199. 19,
  117200. 0,
  117201. 20,
  117202. };
  117203. static long _vq_lengthlist__44c4_s_p9_2[] = {
  117204. 2, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  117205. 8, 9, 9, 9, 9,11, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  117206. 9, 9, 9, 9, 9, 9,10,10,10,10,11, 6, 6, 7, 7, 8,
  117207. 8, 8, 8, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,11,
  117208. 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  117209. 10,10,10,10,12,11,11, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  117210. 9,10,10,10,10,10,10,10,10,12,11,12, 8, 8, 8, 8,
  117211. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,11,11,
  117212. 11, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,10,10,10,10,
  117213. 10,10,10,11,11,12, 9, 9, 9, 9, 9, 9,10, 9,10,10,
  117214. 10,10,10,10,10,10,10,10,11,11,11,11,11, 9, 9, 9,
  117215. 9,10,10,10,10,10,10,10,10,10,10,10,10,11,12,11,
  117216. 11,11, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  117217. 10,10,11,11,11,11,11, 9, 9, 9, 9,10,10,10,10,10,
  117218. 10,10,10,10,10,10,10,11,11,11,12,12,10,10,10,10,
  117219. 10,10,10,10,10,10,10,10,10,10,10,10,11,12,11,12,
  117220. 11,11,11, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  117221. 10,11,12,11,11,11,11,11,10,10,10,10,10,10,10,10,
  117222. 10,10,10,10,10,10,11,11,11,12,11,11,11,10,10,10,
  117223. 10,10,10,10,10,10,10,10,10,10,10,12,11,11,12,11,
  117224. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  117225. 11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
  117226. 10,10,10,10,10,11,11,11,11,12,12,11,11,11,11,11,
  117227. 11,11,10,10,10,10,10,10,10,10,12,12,12,11,11,11,
  117228. 12,11,11,11,10,10,10,10,10,10,10,10,10,10,10,12,
  117229. 11,12,12,12,12,12,11,12,11,11,10,10,10,10,10,10,
  117230. 10,10,10,10,12,12,12,12,11,11,11,11,11,11,11,10,
  117231. 10,10,10,10,10,10,10,10,10,
  117232. };
  117233. static float _vq_quantthresh__44c4_s_p9_2[] = {
  117234. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  117235. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  117236. 6.5, 7.5, 8.5, 9.5,
  117237. };
  117238. static long _vq_quantmap__44c4_s_p9_2[] = {
  117239. 19, 17, 15, 13, 11, 9, 7, 5,
  117240. 3, 1, 0, 2, 4, 6, 8, 10,
  117241. 12, 14, 16, 18, 20,
  117242. };
  117243. static encode_aux_threshmatch _vq_auxt__44c4_s_p9_2 = {
  117244. _vq_quantthresh__44c4_s_p9_2,
  117245. _vq_quantmap__44c4_s_p9_2,
  117246. 21,
  117247. 21
  117248. };
  117249. static static_codebook _44c4_s_p9_2 = {
  117250. 2, 441,
  117251. _vq_lengthlist__44c4_s_p9_2,
  117252. 1, -529268736, 1611661312, 5, 0,
  117253. _vq_quantlist__44c4_s_p9_2,
  117254. NULL,
  117255. &_vq_auxt__44c4_s_p9_2,
  117256. NULL,
  117257. 0
  117258. };
  117259. static long _huff_lengthlist__44c4_s_short[] = {
  117260. 4, 7,14,10,15,10,12,15,16,15, 4, 2,11, 5,10, 6,
  117261. 8,11,14,14,14,10, 7,11, 6, 8,10,11,13,15, 9, 4,
  117262. 11, 5, 9, 6, 9,12,14,15,14, 9, 6, 9, 4, 5, 7,10,
  117263. 12,13, 9, 5, 7, 6, 5, 5, 7,10,13,13,10, 8, 9, 8,
  117264. 7, 6, 8,10,14,14,13,11,10,10, 7, 7, 8,11,14,15,
  117265. 13,12, 9, 9, 6, 5, 7,10,14,17,15,13,11,10, 6, 6,
  117266. 7, 9,12,17,
  117267. };
  117268. static static_codebook _huff_book__44c4_s_short = {
  117269. 2, 100,
  117270. _huff_lengthlist__44c4_s_short,
  117271. 0, 0, 0, 0, 0,
  117272. NULL,
  117273. NULL,
  117274. NULL,
  117275. NULL,
  117276. 0
  117277. };
  117278. static long _huff_lengthlist__44c5_s_long[] = {
  117279. 3, 8, 9,13,10,12,12,12,12,12, 6, 4, 6, 8, 6, 8,
  117280. 10,10,11,12, 8, 5, 4,10, 4, 7, 8, 9,10,11,13, 8,
  117281. 10, 8, 9, 9,11,12,13,14,10, 6, 4, 9, 3, 5, 6, 8,
  117282. 10,11,11, 8, 6, 9, 5, 5, 6, 7, 9,11,12, 9, 7,11,
  117283. 6, 6, 6, 7, 8,10,12,11, 9,12, 7, 7, 6, 6, 7, 9,
  117284. 13,12,10,13, 9, 8, 7, 7, 7, 8,11,15,11,15,11,10,
  117285. 9, 8, 7, 7,
  117286. };
  117287. static static_codebook _huff_book__44c5_s_long = {
  117288. 2, 100,
  117289. _huff_lengthlist__44c5_s_long,
  117290. 0, 0, 0, 0, 0,
  117291. NULL,
  117292. NULL,
  117293. NULL,
  117294. NULL,
  117295. 0
  117296. };
  117297. static long _vq_quantlist__44c5_s_p1_0[] = {
  117298. 1,
  117299. 0,
  117300. 2,
  117301. };
  117302. static long _vq_lengthlist__44c5_s_p1_0[] = {
  117303. 2, 4, 4, 0, 0, 0, 0, 0, 0, 4, 7, 7, 0, 0, 0, 0,
  117304. 0, 0, 4, 6, 7, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  117309. 0, 0, 0, 7, 8, 9, 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, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  117314. 0, 0, 0, 0, 7, 9, 9, 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, 4, 7, 7, 0, 0, 0, 0,
  117349. 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 7, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  117354. 0, 0, 0, 9,10,11, 0, 0, 0, 0, 0, 0, 9,10,10, 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, 7, 9, 9, 0, 0,
  117359. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  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, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  117395. 0, 0, 0, 0, 7, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  117400. 0, 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  117405. 0, 0, 0, 0, 0, 0, 9,11,10, 0, 0, 0, 0, 0, 0, 0,
  117406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117619. 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117627. 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
  117714. };
  117715. static float _vq_quantthresh__44c5_s_p1_0[] = {
  117716. -0.5, 0.5,
  117717. };
  117718. static long _vq_quantmap__44c5_s_p1_0[] = {
  117719. 1, 0, 2,
  117720. };
  117721. static encode_aux_threshmatch _vq_auxt__44c5_s_p1_0 = {
  117722. _vq_quantthresh__44c5_s_p1_0,
  117723. _vq_quantmap__44c5_s_p1_0,
  117724. 3,
  117725. 3
  117726. };
  117727. static static_codebook _44c5_s_p1_0 = {
  117728. 8, 6561,
  117729. _vq_lengthlist__44c5_s_p1_0,
  117730. 1, -535822336, 1611661312, 2, 0,
  117731. _vq_quantlist__44c5_s_p1_0,
  117732. NULL,
  117733. &_vq_auxt__44c5_s_p1_0,
  117734. NULL,
  117735. 0
  117736. };
  117737. static long _vq_quantlist__44c5_s_p2_0[] = {
  117738. 2,
  117739. 1,
  117740. 3,
  117741. 0,
  117742. 4,
  117743. };
  117744. static long _vq_lengthlist__44c5_s_p2_0[] = {
  117745. 2, 4, 4, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
  117746. 8, 7, 0, 0, 0, 0, 0, 0, 0, 4, 6, 6, 0, 0, 0, 8,
  117747. 8, 0, 0, 0, 8, 7, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  117748. 0, 0, 4, 6, 6, 0, 0, 0, 8, 8, 0, 0, 0, 7, 8, 0,
  117749. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117754. 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 8, 8, 0, 0,
  117755. 0, 8, 8, 0, 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 5,
  117756. 7, 8, 0, 0, 0, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0,10,
  117757. 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117762. 0, 0, 0, 5, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 8, 8,
  117763. 0, 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0,
  117764. 0, 0, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0,10,10, 0, 0,
  117765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117770. 8,10,10, 0, 0, 0,10,10, 0, 0, 0, 9,10, 0, 0, 0,
  117771. 11,10, 0, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0, 0,10,
  117772. 10, 0, 0, 0,10,10, 0, 0, 0,10,11, 0, 0, 0, 0, 0,
  117773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117784. 0,
  117785. };
  117786. static float _vq_quantthresh__44c5_s_p2_0[] = {
  117787. -1.5, -0.5, 0.5, 1.5,
  117788. };
  117789. static long _vq_quantmap__44c5_s_p2_0[] = {
  117790. 3, 1, 0, 2, 4,
  117791. };
  117792. static encode_aux_threshmatch _vq_auxt__44c5_s_p2_0 = {
  117793. _vq_quantthresh__44c5_s_p2_0,
  117794. _vq_quantmap__44c5_s_p2_0,
  117795. 5,
  117796. 5
  117797. };
  117798. static static_codebook _44c5_s_p2_0 = {
  117799. 4, 625,
  117800. _vq_lengthlist__44c5_s_p2_0,
  117801. 1, -533725184, 1611661312, 3, 0,
  117802. _vq_quantlist__44c5_s_p2_0,
  117803. NULL,
  117804. &_vq_auxt__44c5_s_p2_0,
  117805. NULL,
  117806. 0
  117807. };
  117808. static long _vq_quantlist__44c5_s_p3_0[] = {
  117809. 2,
  117810. 1,
  117811. 3,
  117812. 0,
  117813. 4,
  117814. };
  117815. static long _vq_lengthlist__44c5_s_p3_0[] = {
  117816. 2, 4, 3, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 6, 6, 0, 0,
  117818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117819. 0, 0, 3, 5, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 8, 8,
  117821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117822. 0, 0, 0, 0, 5, 6, 6, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  117823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117855. 0,
  117856. };
  117857. static float _vq_quantthresh__44c5_s_p3_0[] = {
  117858. -1.5, -0.5, 0.5, 1.5,
  117859. };
  117860. static long _vq_quantmap__44c5_s_p3_0[] = {
  117861. 3, 1, 0, 2, 4,
  117862. };
  117863. static encode_aux_threshmatch _vq_auxt__44c5_s_p3_0 = {
  117864. _vq_quantthresh__44c5_s_p3_0,
  117865. _vq_quantmap__44c5_s_p3_0,
  117866. 5,
  117867. 5
  117868. };
  117869. static static_codebook _44c5_s_p3_0 = {
  117870. 4, 625,
  117871. _vq_lengthlist__44c5_s_p3_0,
  117872. 1, -533725184, 1611661312, 3, 0,
  117873. _vq_quantlist__44c5_s_p3_0,
  117874. NULL,
  117875. &_vq_auxt__44c5_s_p3_0,
  117876. NULL,
  117877. 0
  117878. };
  117879. static long _vq_quantlist__44c5_s_p4_0[] = {
  117880. 4,
  117881. 3,
  117882. 5,
  117883. 2,
  117884. 6,
  117885. 1,
  117886. 7,
  117887. 0,
  117888. 8,
  117889. };
  117890. static long _vq_lengthlist__44c5_s_p4_0[] = {
  117891. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0,
  117892. 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6,
  117893. 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0,
  117894. 7, 7, 0, 0, 0, 0, 0, 0, 0, 8, 7, 0, 0, 0, 0, 0,
  117895. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117896. 0,
  117897. };
  117898. static float _vq_quantthresh__44c5_s_p4_0[] = {
  117899. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  117900. };
  117901. static long _vq_quantmap__44c5_s_p4_0[] = {
  117902. 7, 5, 3, 1, 0, 2, 4, 6,
  117903. 8,
  117904. };
  117905. static encode_aux_threshmatch _vq_auxt__44c5_s_p4_0 = {
  117906. _vq_quantthresh__44c5_s_p4_0,
  117907. _vq_quantmap__44c5_s_p4_0,
  117908. 9,
  117909. 9
  117910. };
  117911. static static_codebook _44c5_s_p4_0 = {
  117912. 2, 81,
  117913. _vq_lengthlist__44c5_s_p4_0,
  117914. 1, -531628032, 1611661312, 4, 0,
  117915. _vq_quantlist__44c5_s_p4_0,
  117916. NULL,
  117917. &_vq_auxt__44c5_s_p4_0,
  117918. NULL,
  117919. 0
  117920. };
  117921. static long _vq_quantlist__44c5_s_p5_0[] = {
  117922. 4,
  117923. 3,
  117924. 5,
  117925. 2,
  117926. 6,
  117927. 1,
  117928. 7,
  117929. 0,
  117930. 8,
  117931. };
  117932. static long _vq_lengthlist__44c5_s_p5_0[] = {
  117933. 2, 4, 3, 6, 6, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  117934. 9, 9, 0, 4, 4, 6, 6, 7, 7, 9, 9, 0, 6, 6, 7, 7,
  117935. 7, 7, 9, 9, 0, 0, 0, 7, 6, 7, 7, 9, 9, 0, 0, 0,
  117936. 8, 8, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  117937. 0, 0, 9, 9, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  117938. 10,
  117939. };
  117940. static float _vq_quantthresh__44c5_s_p5_0[] = {
  117941. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  117942. };
  117943. static long _vq_quantmap__44c5_s_p5_0[] = {
  117944. 7, 5, 3, 1, 0, 2, 4, 6,
  117945. 8,
  117946. };
  117947. static encode_aux_threshmatch _vq_auxt__44c5_s_p5_0 = {
  117948. _vq_quantthresh__44c5_s_p5_0,
  117949. _vq_quantmap__44c5_s_p5_0,
  117950. 9,
  117951. 9
  117952. };
  117953. static static_codebook _44c5_s_p5_0 = {
  117954. 2, 81,
  117955. _vq_lengthlist__44c5_s_p5_0,
  117956. 1, -531628032, 1611661312, 4, 0,
  117957. _vq_quantlist__44c5_s_p5_0,
  117958. NULL,
  117959. &_vq_auxt__44c5_s_p5_0,
  117960. NULL,
  117961. 0
  117962. };
  117963. static long _vq_quantlist__44c5_s_p6_0[] = {
  117964. 8,
  117965. 7,
  117966. 9,
  117967. 6,
  117968. 10,
  117969. 5,
  117970. 11,
  117971. 4,
  117972. 12,
  117973. 3,
  117974. 13,
  117975. 2,
  117976. 14,
  117977. 1,
  117978. 15,
  117979. 0,
  117980. 16,
  117981. };
  117982. static long _vq_lengthlist__44c5_s_p6_0[] = {
  117983. 2, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,10,11,
  117984. 11, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,11,
  117985. 12,12, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,
  117986. 11,12,12, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  117987. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  117988. 10,11,11,12,12, 0, 0, 0, 7, 7, 9, 9,10,10,10,10,
  117989. 11,11,11,11,12,12, 0, 0, 0, 7, 7, 8, 9,10,10,10,
  117990. 10,11,11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,
  117991. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  117992. 10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,
  117993. 10,10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9,
  117994. 9, 9,10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0,
  117995. 10,10,10,10,11,11,11,12,12,12,13,13, 0, 0, 0, 0,
  117996. 0, 0, 0,10,10,11,11,11,11,12,12,13,13, 0, 0, 0,
  117997. 0, 0, 0, 0,11,11,11,11,12,12,12,13,13,13, 0, 0,
  117998. 0, 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0,
  117999. 0, 0, 0, 0, 0, 0,12,12,12,12,13,12,13,13,13,13,
  118000. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,
  118001. 13,
  118002. };
  118003. static float _vq_quantthresh__44c5_s_p6_0[] = {
  118004. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  118005. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  118006. };
  118007. static long _vq_quantmap__44c5_s_p6_0[] = {
  118008. 15, 13, 11, 9, 7, 5, 3, 1,
  118009. 0, 2, 4, 6, 8, 10, 12, 14,
  118010. 16,
  118011. };
  118012. static encode_aux_threshmatch _vq_auxt__44c5_s_p6_0 = {
  118013. _vq_quantthresh__44c5_s_p6_0,
  118014. _vq_quantmap__44c5_s_p6_0,
  118015. 17,
  118016. 17
  118017. };
  118018. static static_codebook _44c5_s_p6_0 = {
  118019. 2, 289,
  118020. _vq_lengthlist__44c5_s_p6_0,
  118021. 1, -529530880, 1611661312, 5, 0,
  118022. _vq_quantlist__44c5_s_p6_0,
  118023. NULL,
  118024. &_vq_auxt__44c5_s_p6_0,
  118025. NULL,
  118026. 0
  118027. };
  118028. static long _vq_quantlist__44c5_s_p7_0[] = {
  118029. 1,
  118030. 0,
  118031. 2,
  118032. };
  118033. static long _vq_lengthlist__44c5_s_p7_0[] = {
  118034. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  118035. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  118036. 10,11,11,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  118037. 11,10,10,11,10,10, 7,11,11,12,11,11,12,11,11, 6,
  118038. 9, 9,11,10,10,11,10,10, 6, 9, 9,11,10,10,11,10,
  118039. 10,
  118040. };
  118041. static float _vq_quantthresh__44c5_s_p7_0[] = {
  118042. -5.5, 5.5,
  118043. };
  118044. static long _vq_quantmap__44c5_s_p7_0[] = {
  118045. 1, 0, 2,
  118046. };
  118047. static encode_aux_threshmatch _vq_auxt__44c5_s_p7_0 = {
  118048. _vq_quantthresh__44c5_s_p7_0,
  118049. _vq_quantmap__44c5_s_p7_0,
  118050. 3,
  118051. 3
  118052. };
  118053. static static_codebook _44c5_s_p7_0 = {
  118054. 4, 81,
  118055. _vq_lengthlist__44c5_s_p7_0,
  118056. 1, -529137664, 1618345984, 2, 0,
  118057. _vq_quantlist__44c5_s_p7_0,
  118058. NULL,
  118059. &_vq_auxt__44c5_s_p7_0,
  118060. NULL,
  118061. 0
  118062. };
  118063. static long _vq_quantlist__44c5_s_p7_1[] = {
  118064. 5,
  118065. 4,
  118066. 6,
  118067. 3,
  118068. 7,
  118069. 2,
  118070. 8,
  118071. 1,
  118072. 9,
  118073. 0,
  118074. 10,
  118075. };
  118076. static long _vq_lengthlist__44c5_s_p7_1[] = {
  118077. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6,
  118078. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  118079. 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  118080. 7, 8, 8, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  118081. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  118082. 8, 8, 8, 8, 8, 8, 8, 9,10,10,10,10,10, 8, 8, 8,
  118083. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  118084. 10,10,10, 8, 8, 8, 8, 8, 8,
  118085. };
  118086. static float _vq_quantthresh__44c5_s_p7_1[] = {
  118087. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  118088. 3.5, 4.5,
  118089. };
  118090. static long _vq_quantmap__44c5_s_p7_1[] = {
  118091. 9, 7, 5, 3, 1, 0, 2, 4,
  118092. 6, 8, 10,
  118093. };
  118094. static encode_aux_threshmatch _vq_auxt__44c5_s_p7_1 = {
  118095. _vq_quantthresh__44c5_s_p7_1,
  118096. _vq_quantmap__44c5_s_p7_1,
  118097. 11,
  118098. 11
  118099. };
  118100. static static_codebook _44c5_s_p7_1 = {
  118101. 2, 121,
  118102. _vq_lengthlist__44c5_s_p7_1,
  118103. 1, -531365888, 1611661312, 4, 0,
  118104. _vq_quantlist__44c5_s_p7_1,
  118105. NULL,
  118106. &_vq_auxt__44c5_s_p7_1,
  118107. NULL,
  118108. 0
  118109. };
  118110. static long _vq_quantlist__44c5_s_p8_0[] = {
  118111. 6,
  118112. 5,
  118113. 7,
  118114. 4,
  118115. 8,
  118116. 3,
  118117. 9,
  118118. 2,
  118119. 10,
  118120. 1,
  118121. 11,
  118122. 0,
  118123. 12,
  118124. };
  118125. static long _vq_lengthlist__44c5_s_p8_0[] = {
  118126. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  118127. 7, 7, 8, 8, 8, 9,10,10,10,10, 7, 5, 5, 7, 7, 8,
  118128. 8, 9, 9,10,10,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  118129. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  118130. 11, 0,12,12, 9, 9, 9,10,10,10,10,10,11,11, 0,13,
  118131. 13, 9, 9, 9, 9,10,10,11,11,11,11, 0, 0, 0,10,10,
  118132. 10,10,10,10,11,11,11,11, 0, 0, 0,10,10,10,10,10,
  118133. 10,11,11,12,12, 0, 0, 0,14,14,11,11,11,11,12,12,
  118134. 12,12, 0, 0, 0,14,14,11,11,11,11,12,12,12,12, 0,
  118135. 0, 0, 0, 0,12,12,12,12,12,12,13,13, 0, 0, 0, 0,
  118136. 0,12,12,12,12,12,12,13,13,
  118137. };
  118138. static float _vq_quantthresh__44c5_s_p8_0[] = {
  118139. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  118140. 12.5, 17.5, 22.5, 27.5,
  118141. };
  118142. static long _vq_quantmap__44c5_s_p8_0[] = {
  118143. 11, 9, 7, 5, 3, 1, 0, 2,
  118144. 4, 6, 8, 10, 12,
  118145. };
  118146. static encode_aux_threshmatch _vq_auxt__44c5_s_p8_0 = {
  118147. _vq_quantthresh__44c5_s_p8_0,
  118148. _vq_quantmap__44c5_s_p8_0,
  118149. 13,
  118150. 13
  118151. };
  118152. static static_codebook _44c5_s_p8_0 = {
  118153. 2, 169,
  118154. _vq_lengthlist__44c5_s_p8_0,
  118155. 1, -526516224, 1616117760, 4, 0,
  118156. _vq_quantlist__44c5_s_p8_0,
  118157. NULL,
  118158. &_vq_auxt__44c5_s_p8_0,
  118159. NULL,
  118160. 0
  118161. };
  118162. static long _vq_quantlist__44c5_s_p8_1[] = {
  118163. 2,
  118164. 1,
  118165. 3,
  118166. 0,
  118167. 4,
  118168. };
  118169. static long _vq_lengthlist__44c5_s_p8_1[] = {
  118170. 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 4, 5, 5, 5, 6,
  118171. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  118172. };
  118173. static float _vq_quantthresh__44c5_s_p8_1[] = {
  118174. -1.5, -0.5, 0.5, 1.5,
  118175. };
  118176. static long _vq_quantmap__44c5_s_p8_1[] = {
  118177. 3, 1, 0, 2, 4,
  118178. };
  118179. static encode_aux_threshmatch _vq_auxt__44c5_s_p8_1 = {
  118180. _vq_quantthresh__44c5_s_p8_1,
  118181. _vq_quantmap__44c5_s_p8_1,
  118182. 5,
  118183. 5
  118184. };
  118185. static static_codebook _44c5_s_p8_1 = {
  118186. 2, 25,
  118187. _vq_lengthlist__44c5_s_p8_1,
  118188. 1, -533725184, 1611661312, 3, 0,
  118189. _vq_quantlist__44c5_s_p8_1,
  118190. NULL,
  118191. &_vq_auxt__44c5_s_p8_1,
  118192. NULL,
  118193. 0
  118194. };
  118195. static long _vq_quantlist__44c5_s_p9_0[] = {
  118196. 7,
  118197. 6,
  118198. 8,
  118199. 5,
  118200. 9,
  118201. 4,
  118202. 10,
  118203. 3,
  118204. 11,
  118205. 2,
  118206. 12,
  118207. 1,
  118208. 13,
  118209. 0,
  118210. 14,
  118211. };
  118212. static long _vq_lengthlist__44c5_s_p9_0[] = {
  118213. 1, 3, 3,13,13,13,13,13,13,13,13,13,13,13,13, 4,
  118214. 7, 7,13,13,13,13,13,13,13,13,13,13,13,13, 3, 8,
  118215. 6,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118216. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118217. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118218. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118219. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118220. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118221. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118222. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118223. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118224. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118225. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118226. 13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,
  118227. 12,
  118228. };
  118229. static float _vq_quantthresh__44c5_s_p9_0[] = {
  118230. -2320.5, -1963.5, -1606.5, -1249.5, -892.5, -535.5, -178.5, 178.5,
  118231. 535.5, 892.5, 1249.5, 1606.5, 1963.5, 2320.5,
  118232. };
  118233. static long _vq_quantmap__44c5_s_p9_0[] = {
  118234. 13, 11, 9, 7, 5, 3, 1, 0,
  118235. 2, 4, 6, 8, 10, 12, 14,
  118236. };
  118237. static encode_aux_threshmatch _vq_auxt__44c5_s_p9_0 = {
  118238. _vq_quantthresh__44c5_s_p9_0,
  118239. _vq_quantmap__44c5_s_p9_0,
  118240. 15,
  118241. 15
  118242. };
  118243. static static_codebook _44c5_s_p9_0 = {
  118244. 2, 225,
  118245. _vq_lengthlist__44c5_s_p9_0,
  118246. 1, -512522752, 1628852224, 4, 0,
  118247. _vq_quantlist__44c5_s_p9_0,
  118248. NULL,
  118249. &_vq_auxt__44c5_s_p9_0,
  118250. NULL,
  118251. 0
  118252. };
  118253. static long _vq_quantlist__44c5_s_p9_1[] = {
  118254. 8,
  118255. 7,
  118256. 9,
  118257. 6,
  118258. 10,
  118259. 5,
  118260. 11,
  118261. 4,
  118262. 12,
  118263. 3,
  118264. 13,
  118265. 2,
  118266. 14,
  118267. 1,
  118268. 15,
  118269. 0,
  118270. 16,
  118271. };
  118272. static long _vq_lengthlist__44c5_s_p9_1[] = {
  118273. 1, 4, 4, 5, 5, 7, 7, 9, 8,10, 9,10,10,11,10,11,
  118274. 11, 6, 5, 5, 7, 7, 8, 9,10,10,11,10,12,11,12,11,
  118275. 13,12, 6, 5, 5, 7, 7, 9, 9,10,10,11,11,12,12,13,
  118276. 12,13,13,18, 8, 8, 8, 8, 9, 9,10,11,11,11,12,11,
  118277. 13,11,13,12,18, 8, 8, 8, 8,10,10,11,11,12,12,13,
  118278. 13,13,13,13,14,18,12,12, 9, 9,11,11,11,11,12,12,
  118279. 13,12,13,12,13,13,20,13,12, 9, 9,11,11,11,11,12,
  118280. 12,13,13,13,14,14,13,20,18,19,11,12,11,11,12,12,
  118281. 13,13,13,13,13,13,14,13,18,19,19,12,11,11,11,12,
  118282. 12,13,12,13,13,13,14,14,13,18,17,19,14,15,12,12,
  118283. 12,13,13,13,14,14,14,14,14,14,19,19,19,16,15,12,
  118284. 11,13,12,14,14,14,13,13,14,14,14,19,18,19,18,19,
  118285. 13,13,13,13,14,14,14,13,14,14,14,14,18,17,19,19,
  118286. 19,13,13,13,11,13,11,13,14,14,14,14,14,19,17,17,
  118287. 18,18,16,16,13,13,13,13,14,13,15,15,14,14,19,19,
  118288. 17,17,18,16,16,13,11,14,10,13,12,14,14,14,14,19,
  118289. 19,19,19,19,18,17,13,14,13,11,14,13,14,14,15,15,
  118290. 19,19,19,17,19,18,18,14,13,12,11,14,11,15,15,15,
  118291. 15,
  118292. };
  118293. static float _vq_quantthresh__44c5_s_p9_1[] = {
  118294. -157.5, -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5,
  118295. 10.5, 31.5, 52.5, 73.5, 94.5, 115.5, 136.5, 157.5,
  118296. };
  118297. static long _vq_quantmap__44c5_s_p9_1[] = {
  118298. 15, 13, 11, 9, 7, 5, 3, 1,
  118299. 0, 2, 4, 6, 8, 10, 12, 14,
  118300. 16,
  118301. };
  118302. static encode_aux_threshmatch _vq_auxt__44c5_s_p9_1 = {
  118303. _vq_quantthresh__44c5_s_p9_1,
  118304. _vq_quantmap__44c5_s_p9_1,
  118305. 17,
  118306. 17
  118307. };
  118308. static static_codebook _44c5_s_p9_1 = {
  118309. 2, 289,
  118310. _vq_lengthlist__44c5_s_p9_1,
  118311. 1, -520814592, 1620377600, 5, 0,
  118312. _vq_quantlist__44c5_s_p9_1,
  118313. NULL,
  118314. &_vq_auxt__44c5_s_p9_1,
  118315. NULL,
  118316. 0
  118317. };
  118318. static long _vq_quantlist__44c5_s_p9_2[] = {
  118319. 10,
  118320. 9,
  118321. 11,
  118322. 8,
  118323. 12,
  118324. 7,
  118325. 13,
  118326. 6,
  118327. 14,
  118328. 5,
  118329. 15,
  118330. 4,
  118331. 16,
  118332. 3,
  118333. 17,
  118334. 2,
  118335. 18,
  118336. 1,
  118337. 19,
  118338. 0,
  118339. 20,
  118340. };
  118341. static long _vq_lengthlist__44c5_s_p9_2[] = {
  118342. 3, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  118343. 8, 8, 8, 8, 9,11, 5, 6, 7, 7, 8, 7, 8, 8, 8, 8,
  118344. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11, 5, 5, 7, 7, 7,
  118345. 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  118346. 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  118347. 9,10, 9,10,11,11,11, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  118348. 9, 9, 9,10,10,10,10,10,10,11,11,11, 8, 8, 8, 8,
  118349. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,11,11,
  118350. 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,10,
  118351. 10,10,10,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  118352. 10,10,10,10,10,10,10,10,11,11,11,11,11, 9, 9, 9,
  118353. 9, 9, 9,10, 9,10,10,10,10,10,10,10,10,11,11,11,
  118354. 11,11, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,
  118355. 10,10,11,11,11,11,11, 9, 9, 9, 9, 9, 9,10,10,10,
  118356. 10,10,10,10,10,10,10,11,11,11,11,11, 9, 9,10, 9,
  118357. 10,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,
  118358. 11,11,11, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  118359. 10,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,
  118360. 10,10,10,10,10,10,11,11,11,11,11,11,11,10,10,10,
  118361. 10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,
  118362. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118363. 11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
  118364. 10,10,10,10,10,11,11,11,11,11,11,11,11,11,10,10,
  118365. 10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
  118366. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,11,
  118367. 11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,
  118368. 10,10,10,10,11,11,11,11,11,11,11,11,11,11,11,10,
  118369. 10,10,10,10,10,10,10,10,10,
  118370. };
  118371. static float _vq_quantthresh__44c5_s_p9_2[] = {
  118372. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  118373. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  118374. 6.5, 7.5, 8.5, 9.5,
  118375. };
  118376. static long _vq_quantmap__44c5_s_p9_2[] = {
  118377. 19, 17, 15, 13, 11, 9, 7, 5,
  118378. 3, 1, 0, 2, 4, 6, 8, 10,
  118379. 12, 14, 16, 18, 20,
  118380. };
  118381. static encode_aux_threshmatch _vq_auxt__44c5_s_p9_2 = {
  118382. _vq_quantthresh__44c5_s_p9_2,
  118383. _vq_quantmap__44c5_s_p9_2,
  118384. 21,
  118385. 21
  118386. };
  118387. static static_codebook _44c5_s_p9_2 = {
  118388. 2, 441,
  118389. _vq_lengthlist__44c5_s_p9_2,
  118390. 1, -529268736, 1611661312, 5, 0,
  118391. _vq_quantlist__44c5_s_p9_2,
  118392. NULL,
  118393. &_vq_auxt__44c5_s_p9_2,
  118394. NULL,
  118395. 0
  118396. };
  118397. static long _huff_lengthlist__44c5_s_short[] = {
  118398. 5, 8,10,14,11,11,12,16,15,17, 5, 5, 7, 9, 7, 8,
  118399. 10,13,17,17, 7, 5, 5,10, 5, 7, 8,11,13,15,10, 8,
  118400. 10, 8, 8, 8,11,15,18,18, 8, 5, 5, 8, 3, 4, 6,10,
  118401. 14,16, 9, 7, 6, 7, 4, 3, 5, 9,14,18,10, 9, 8,10,
  118402. 6, 5, 6, 9,14,18,12,12,11,12, 8, 7, 8,11,14,18,
  118403. 14,13,12,10, 7, 5, 6, 9,14,18,14,14,13,10, 6, 5,
  118404. 6, 8,11,16,
  118405. };
  118406. static static_codebook _huff_book__44c5_s_short = {
  118407. 2, 100,
  118408. _huff_lengthlist__44c5_s_short,
  118409. 0, 0, 0, 0, 0,
  118410. NULL,
  118411. NULL,
  118412. NULL,
  118413. NULL,
  118414. 0
  118415. };
  118416. static long _huff_lengthlist__44c6_s_long[] = {
  118417. 3, 8,11,13,14,14,13,13,16,14, 6, 3, 4, 7, 9, 9,
  118418. 10,11,14,13,10, 4, 3, 5, 7, 7, 9,10,13,15,12, 7,
  118419. 4, 4, 6, 6, 8,10,13,15,12, 8, 6, 6, 6, 6, 8,10,
  118420. 13,14,11, 9, 7, 6, 6, 6, 7, 8,12,11,13,10, 9, 8,
  118421. 7, 6, 6, 7,11,11,13,11,10, 9, 9, 7, 7, 6,10,11,
  118422. 13,13,13,13,13,11, 9, 8,10,12,12,15,15,16,15,12,
  118423. 11,10,10,12,
  118424. };
  118425. static static_codebook _huff_book__44c6_s_long = {
  118426. 2, 100,
  118427. _huff_lengthlist__44c6_s_long,
  118428. 0, 0, 0, 0, 0,
  118429. NULL,
  118430. NULL,
  118431. NULL,
  118432. NULL,
  118433. 0
  118434. };
  118435. static long _vq_quantlist__44c6_s_p1_0[] = {
  118436. 1,
  118437. 0,
  118438. 2,
  118439. };
  118440. static long _vq_lengthlist__44c6_s_p1_0[] = {
  118441. 1, 5, 5, 0, 5, 5, 0, 5, 5, 5, 8, 7, 0, 9, 9, 0,
  118442. 9, 8, 5, 7, 8, 0, 9, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  118443. 0, 0, 0, 0, 5, 9, 8, 0, 8, 8, 0, 8, 8, 5, 8, 9,
  118444. 0, 8, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  118445. 9, 9, 0, 8, 8, 0, 8, 8, 5, 9, 9, 0, 8, 8, 0, 8,
  118446. 8,
  118447. };
  118448. static float _vq_quantthresh__44c6_s_p1_0[] = {
  118449. -0.5, 0.5,
  118450. };
  118451. static long _vq_quantmap__44c6_s_p1_0[] = {
  118452. 1, 0, 2,
  118453. };
  118454. static encode_aux_threshmatch _vq_auxt__44c6_s_p1_0 = {
  118455. _vq_quantthresh__44c6_s_p1_0,
  118456. _vq_quantmap__44c6_s_p1_0,
  118457. 3,
  118458. 3
  118459. };
  118460. static static_codebook _44c6_s_p1_0 = {
  118461. 4, 81,
  118462. _vq_lengthlist__44c6_s_p1_0,
  118463. 1, -535822336, 1611661312, 2, 0,
  118464. _vq_quantlist__44c6_s_p1_0,
  118465. NULL,
  118466. &_vq_auxt__44c6_s_p1_0,
  118467. NULL,
  118468. 0
  118469. };
  118470. static long _vq_quantlist__44c6_s_p2_0[] = {
  118471. 2,
  118472. 1,
  118473. 3,
  118474. 0,
  118475. 4,
  118476. };
  118477. static long _vq_lengthlist__44c6_s_p2_0[] = {
  118478. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  118479. 7, 7, 9, 9, 0, 0, 0, 9, 9, 5, 7, 7, 9, 9, 0, 8,
  118480. 8,10,10, 0, 8, 7,10, 9, 0,10,10,11,11, 0, 0, 0,
  118481. 11,11, 5, 7, 7, 9, 9, 0, 8, 8,10,10, 0, 7, 8, 9,
  118482. 10, 0,10,10,11,11, 0, 0, 0,11,11, 8, 9, 9,11,11,
  118483. 0,11,11,12,12, 0,11,10,12,12, 0,13,14,14,14, 0,
  118484. 0, 0,14,13, 8, 9, 9,11,11, 0,11,11,12,12, 0,10,
  118485. 11,12,12, 0,14,13,14,14, 0, 0, 0,13,14, 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, 5, 8, 7,11,10, 0, 7, 7,10,10,
  118488. 0, 7, 7,10,10, 0, 9, 9,11,10, 0, 0, 0,11,11, 5,
  118489. 7, 8,10,11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9,
  118490. 9,10,11, 0, 0, 0,11,11, 8,10, 9,12,12, 0,10,10,
  118491. 12,12, 0,10,10,12,12, 0,12,12,13,13, 0, 0, 0,13,
  118492. 13, 8, 9,10,12,12, 0,10,10,11,12, 0,10,10,12,12,
  118493. 0,12,12,13,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0,
  118494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118495. 0, 0, 0, 5, 8, 8,11,11, 0, 7, 7,10,10, 0, 7, 7,
  118496. 10,10, 0, 9, 9,10,11, 0, 0, 0,11,10, 5, 8, 8,11,
  118497. 11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9, 9,11,11,
  118498. 0, 0, 0,10,11, 8,10,10,12,12, 0,10,10,12,12, 0,
  118499. 10,10,12,12, 0,12,13,13,13, 0, 0, 0,14,13, 8,10,
  118500. 10,12,12, 0,10,10,12,12, 0,10,10,12,12, 0,13,12,
  118501. 13,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118503. 7,10,10,14,13, 0, 9, 9,13,12, 0, 9, 9,12,12, 0,
  118504. 10,10,12,12, 0, 0, 0,12,12, 7,10,10,13,14, 0, 9,
  118505. 9,12,13, 0, 9, 9,12,12, 0,10,10,12,12, 0, 0, 0,
  118506. 12,12, 9,11,11,14,13, 0,11,10,14,13, 0,11,11,13,
  118507. 13, 0,12,12,13,13, 0, 0, 0,13,13, 9,11,11,13,14,
  118508. 0,10,11,13,14, 0,11,11,13,13, 0,12,12,13,13, 0,
  118509. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  118514. 11,11,14,14, 0,11,11,13,13, 0,11,10,13,13, 0,12,
  118515. 12,13,13, 0, 0, 0,13,13, 9,11,11,14,14, 0,11,11,
  118516. 13,13, 0,10,11,13,13, 0,12,12,14,13, 0, 0, 0,13,
  118517. 13,
  118518. };
  118519. static float _vq_quantthresh__44c6_s_p2_0[] = {
  118520. -1.5, -0.5, 0.5, 1.5,
  118521. };
  118522. static long _vq_quantmap__44c6_s_p2_0[] = {
  118523. 3, 1, 0, 2, 4,
  118524. };
  118525. static encode_aux_threshmatch _vq_auxt__44c6_s_p2_0 = {
  118526. _vq_quantthresh__44c6_s_p2_0,
  118527. _vq_quantmap__44c6_s_p2_0,
  118528. 5,
  118529. 5
  118530. };
  118531. static static_codebook _44c6_s_p2_0 = {
  118532. 4, 625,
  118533. _vq_lengthlist__44c6_s_p2_0,
  118534. 1, -533725184, 1611661312, 3, 0,
  118535. _vq_quantlist__44c6_s_p2_0,
  118536. NULL,
  118537. &_vq_auxt__44c6_s_p2_0,
  118538. NULL,
  118539. 0
  118540. };
  118541. static long _vq_quantlist__44c6_s_p3_0[] = {
  118542. 4,
  118543. 3,
  118544. 5,
  118545. 2,
  118546. 6,
  118547. 1,
  118548. 7,
  118549. 0,
  118550. 8,
  118551. };
  118552. static long _vq_lengthlist__44c6_s_p3_0[] = {
  118553. 2, 3, 4, 6, 6, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  118554. 9,10, 0, 4, 4, 6, 6, 7, 7,10, 9, 0, 5, 5, 7, 7,
  118555. 8, 8,10,10, 0, 0, 0, 7, 6, 8, 8,10,10, 0, 0, 0,
  118556. 7, 7, 9, 9,11,11, 0, 0, 0, 7, 7, 9, 9,11,11, 0,
  118557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118558. 0,
  118559. };
  118560. static float _vq_quantthresh__44c6_s_p3_0[] = {
  118561. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  118562. };
  118563. static long _vq_quantmap__44c6_s_p3_0[] = {
  118564. 7, 5, 3, 1, 0, 2, 4, 6,
  118565. 8,
  118566. };
  118567. static encode_aux_threshmatch _vq_auxt__44c6_s_p3_0 = {
  118568. _vq_quantthresh__44c6_s_p3_0,
  118569. _vq_quantmap__44c6_s_p3_0,
  118570. 9,
  118571. 9
  118572. };
  118573. static static_codebook _44c6_s_p3_0 = {
  118574. 2, 81,
  118575. _vq_lengthlist__44c6_s_p3_0,
  118576. 1, -531628032, 1611661312, 4, 0,
  118577. _vq_quantlist__44c6_s_p3_0,
  118578. NULL,
  118579. &_vq_auxt__44c6_s_p3_0,
  118580. NULL,
  118581. 0
  118582. };
  118583. static long _vq_quantlist__44c6_s_p4_0[] = {
  118584. 8,
  118585. 7,
  118586. 9,
  118587. 6,
  118588. 10,
  118589. 5,
  118590. 11,
  118591. 4,
  118592. 12,
  118593. 3,
  118594. 13,
  118595. 2,
  118596. 14,
  118597. 1,
  118598. 15,
  118599. 0,
  118600. 16,
  118601. };
  118602. static long _vq_lengthlist__44c6_s_p4_0[] = {
  118603. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9,10,10,
  118604. 10, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,10,
  118605. 11,11, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,
  118606. 10,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  118607. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  118608. 10,11,11,11,11, 0, 0, 0, 7, 7, 9, 9,10,10,10,10,
  118609. 11,11,11,11,12,12, 0, 0, 0, 7, 7, 9, 9,10,10,10,
  118610. 10,11,11,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  118611. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 8, 8, 9,
  118612. 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 0, 0,
  118613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118621. 0,
  118622. };
  118623. static float _vq_quantthresh__44c6_s_p4_0[] = {
  118624. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  118625. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  118626. };
  118627. static long _vq_quantmap__44c6_s_p4_0[] = {
  118628. 15, 13, 11, 9, 7, 5, 3, 1,
  118629. 0, 2, 4, 6, 8, 10, 12, 14,
  118630. 16,
  118631. };
  118632. static encode_aux_threshmatch _vq_auxt__44c6_s_p4_0 = {
  118633. _vq_quantthresh__44c6_s_p4_0,
  118634. _vq_quantmap__44c6_s_p4_0,
  118635. 17,
  118636. 17
  118637. };
  118638. static static_codebook _44c6_s_p4_0 = {
  118639. 2, 289,
  118640. _vq_lengthlist__44c6_s_p4_0,
  118641. 1, -529530880, 1611661312, 5, 0,
  118642. _vq_quantlist__44c6_s_p4_0,
  118643. NULL,
  118644. &_vq_auxt__44c6_s_p4_0,
  118645. NULL,
  118646. 0
  118647. };
  118648. static long _vq_quantlist__44c6_s_p5_0[] = {
  118649. 1,
  118650. 0,
  118651. 2,
  118652. };
  118653. static long _vq_lengthlist__44c6_s_p5_0[] = {
  118654. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 6, 6, 9, 9,10,10,
  118655. 10, 9, 4, 6, 6, 9,10, 9,10, 9,10, 6, 9, 9,10,12,
  118656. 11,10,11,11, 7,10, 9,11,12,12,12,12,12, 7,10,10,
  118657. 11,12,12,12,12,12, 6,10,10,10,12,12,11,12,12, 7,
  118658. 9,10,11,12,12,12,12,12, 7,10, 9,12,12,12,12,12,
  118659. 12,
  118660. };
  118661. static float _vq_quantthresh__44c6_s_p5_0[] = {
  118662. -5.5, 5.5,
  118663. };
  118664. static long _vq_quantmap__44c6_s_p5_0[] = {
  118665. 1, 0, 2,
  118666. };
  118667. static encode_aux_threshmatch _vq_auxt__44c6_s_p5_0 = {
  118668. _vq_quantthresh__44c6_s_p5_0,
  118669. _vq_quantmap__44c6_s_p5_0,
  118670. 3,
  118671. 3
  118672. };
  118673. static static_codebook _44c6_s_p5_0 = {
  118674. 4, 81,
  118675. _vq_lengthlist__44c6_s_p5_0,
  118676. 1, -529137664, 1618345984, 2, 0,
  118677. _vq_quantlist__44c6_s_p5_0,
  118678. NULL,
  118679. &_vq_auxt__44c6_s_p5_0,
  118680. NULL,
  118681. 0
  118682. };
  118683. static long _vq_quantlist__44c6_s_p5_1[] = {
  118684. 5,
  118685. 4,
  118686. 6,
  118687. 3,
  118688. 7,
  118689. 2,
  118690. 8,
  118691. 1,
  118692. 9,
  118693. 0,
  118694. 10,
  118695. };
  118696. static long _vq_lengthlist__44c6_s_p5_1[] = {
  118697. 3, 5, 4, 6, 6, 7, 7, 8, 8, 8, 8,11, 4, 4, 6, 6,
  118698. 7, 7, 8, 8, 8, 8,11, 4, 4, 6, 6, 7, 7, 8, 8, 8,
  118699. 8,11, 6, 6, 6, 6, 8, 8, 8, 8, 9, 9,11,11,11, 6,
  118700. 6, 7, 8, 8, 8, 8, 9,11,11,11, 7, 7, 8, 8, 8, 8,
  118701. 8, 8,11,11,11, 7, 7, 8, 8, 8, 8, 8, 8,11,11,11,
  118702. 8, 8, 8, 8, 8, 8, 8, 8,11,11,11,10,10, 8, 8, 8,
  118703. 8, 8, 8,11,11,11,10,10, 8, 8, 8, 8, 8, 8,11,11,
  118704. 11,10,10, 7, 7, 8, 8, 8, 8,
  118705. };
  118706. static float _vq_quantthresh__44c6_s_p5_1[] = {
  118707. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  118708. 3.5, 4.5,
  118709. };
  118710. static long _vq_quantmap__44c6_s_p5_1[] = {
  118711. 9, 7, 5, 3, 1, 0, 2, 4,
  118712. 6, 8, 10,
  118713. };
  118714. static encode_aux_threshmatch _vq_auxt__44c6_s_p5_1 = {
  118715. _vq_quantthresh__44c6_s_p5_1,
  118716. _vq_quantmap__44c6_s_p5_1,
  118717. 11,
  118718. 11
  118719. };
  118720. static static_codebook _44c6_s_p5_1 = {
  118721. 2, 121,
  118722. _vq_lengthlist__44c6_s_p5_1,
  118723. 1, -531365888, 1611661312, 4, 0,
  118724. _vq_quantlist__44c6_s_p5_1,
  118725. NULL,
  118726. &_vq_auxt__44c6_s_p5_1,
  118727. NULL,
  118728. 0
  118729. };
  118730. static long _vq_quantlist__44c6_s_p6_0[] = {
  118731. 6,
  118732. 5,
  118733. 7,
  118734. 4,
  118735. 8,
  118736. 3,
  118737. 9,
  118738. 2,
  118739. 10,
  118740. 1,
  118741. 11,
  118742. 0,
  118743. 12,
  118744. };
  118745. static long _vq_lengthlist__44c6_s_p6_0[] = {
  118746. 1, 4, 4, 6, 6, 8, 8, 8, 8,10, 9,10,10, 6, 5, 5,
  118747. 7, 7, 9, 9, 9, 9,10,10,11,11, 6, 5, 5, 7, 7, 9,
  118748. 9,10, 9,11,10,11,11, 0, 6, 6, 7, 7, 9, 9,10,10,
  118749. 11,11,12,12, 0, 7, 7, 7, 7, 9, 9,10,10,11,11,12,
  118750. 12, 0,11,11, 8, 8,10,10,11,11,12,12,12,12, 0,11,
  118751. 12, 9, 8,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  118752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118756. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118757. };
  118758. static float _vq_quantthresh__44c6_s_p6_0[] = {
  118759. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  118760. 12.5, 17.5, 22.5, 27.5,
  118761. };
  118762. static long _vq_quantmap__44c6_s_p6_0[] = {
  118763. 11, 9, 7, 5, 3, 1, 0, 2,
  118764. 4, 6, 8, 10, 12,
  118765. };
  118766. static encode_aux_threshmatch _vq_auxt__44c6_s_p6_0 = {
  118767. _vq_quantthresh__44c6_s_p6_0,
  118768. _vq_quantmap__44c6_s_p6_0,
  118769. 13,
  118770. 13
  118771. };
  118772. static static_codebook _44c6_s_p6_0 = {
  118773. 2, 169,
  118774. _vq_lengthlist__44c6_s_p6_0,
  118775. 1, -526516224, 1616117760, 4, 0,
  118776. _vq_quantlist__44c6_s_p6_0,
  118777. NULL,
  118778. &_vq_auxt__44c6_s_p6_0,
  118779. NULL,
  118780. 0
  118781. };
  118782. static long _vq_quantlist__44c6_s_p6_1[] = {
  118783. 2,
  118784. 1,
  118785. 3,
  118786. 0,
  118787. 4,
  118788. };
  118789. static long _vq_lengthlist__44c6_s_p6_1[] = {
  118790. 3, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 6,
  118791. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  118792. };
  118793. static float _vq_quantthresh__44c6_s_p6_1[] = {
  118794. -1.5, -0.5, 0.5, 1.5,
  118795. };
  118796. static long _vq_quantmap__44c6_s_p6_1[] = {
  118797. 3, 1, 0, 2, 4,
  118798. };
  118799. static encode_aux_threshmatch _vq_auxt__44c6_s_p6_1 = {
  118800. _vq_quantthresh__44c6_s_p6_1,
  118801. _vq_quantmap__44c6_s_p6_1,
  118802. 5,
  118803. 5
  118804. };
  118805. static static_codebook _44c6_s_p6_1 = {
  118806. 2, 25,
  118807. _vq_lengthlist__44c6_s_p6_1,
  118808. 1, -533725184, 1611661312, 3, 0,
  118809. _vq_quantlist__44c6_s_p6_1,
  118810. NULL,
  118811. &_vq_auxt__44c6_s_p6_1,
  118812. NULL,
  118813. 0
  118814. };
  118815. static long _vq_quantlist__44c6_s_p7_0[] = {
  118816. 6,
  118817. 5,
  118818. 7,
  118819. 4,
  118820. 8,
  118821. 3,
  118822. 9,
  118823. 2,
  118824. 10,
  118825. 1,
  118826. 11,
  118827. 0,
  118828. 12,
  118829. };
  118830. static long _vq_lengthlist__44c6_s_p7_0[] = {
  118831. 1, 4, 4, 6, 6, 8, 8, 8, 8,10,10,11,10, 6, 5, 5,
  118832. 7, 7, 8, 8, 9, 9,10,10,12,11, 6, 5, 5, 7, 7, 8,
  118833. 8, 9, 9,10,10,12,11,21, 7, 7, 7, 7, 9, 9,10,10,
  118834. 11,11,12,12,21, 7, 7, 7, 7, 9, 9,10,10,11,11,12,
  118835. 12,21,12,12, 9, 9,10,10,11,11,11,11,12,12,21,12,
  118836. 12, 9, 9,10,10,11,11,12,12,12,12,21,21,21,11,11,
  118837. 10,10,11,12,12,12,13,13,21,21,21,11,11,10,10,12,
  118838. 12,12,12,13,13,21,21,21,15,15,11,11,12,12,13,13,
  118839. 13,13,21,21,21,15,16,11,11,12,12,13,13,14,14,21,
  118840. 21,21,21,20,13,13,13,13,13,13,14,14,20,20,20,20,
  118841. 20,13,13,13,13,13,13,14,14,
  118842. };
  118843. static float _vq_quantthresh__44c6_s_p7_0[] = {
  118844. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  118845. 27.5, 38.5, 49.5, 60.5,
  118846. };
  118847. static long _vq_quantmap__44c6_s_p7_0[] = {
  118848. 11, 9, 7, 5, 3, 1, 0, 2,
  118849. 4, 6, 8, 10, 12,
  118850. };
  118851. static encode_aux_threshmatch _vq_auxt__44c6_s_p7_0 = {
  118852. _vq_quantthresh__44c6_s_p7_0,
  118853. _vq_quantmap__44c6_s_p7_0,
  118854. 13,
  118855. 13
  118856. };
  118857. static static_codebook _44c6_s_p7_0 = {
  118858. 2, 169,
  118859. _vq_lengthlist__44c6_s_p7_0,
  118860. 1, -523206656, 1618345984, 4, 0,
  118861. _vq_quantlist__44c6_s_p7_0,
  118862. NULL,
  118863. &_vq_auxt__44c6_s_p7_0,
  118864. NULL,
  118865. 0
  118866. };
  118867. static long _vq_quantlist__44c6_s_p7_1[] = {
  118868. 5,
  118869. 4,
  118870. 6,
  118871. 3,
  118872. 7,
  118873. 2,
  118874. 8,
  118875. 1,
  118876. 9,
  118877. 0,
  118878. 10,
  118879. };
  118880. static long _vq_lengthlist__44c6_s_p7_1[] = {
  118881. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 9, 5, 5, 6, 6,
  118882. 7, 7, 7, 7, 8, 7, 8, 5, 5, 6, 6, 7, 7, 7, 7, 7,
  118883. 7, 9, 6, 6, 7, 7, 7, 7, 8, 7, 7, 8, 9, 9, 9, 7,
  118884. 7, 7, 7, 7, 7, 7, 8, 9, 9, 9, 7, 7, 7, 7, 8, 8,
  118885. 8, 8, 9, 9, 9, 7, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9,
  118886. 8, 8, 8, 8, 7, 7, 8, 8, 9, 9, 9, 9, 8, 8, 8, 7,
  118887. 7, 8, 8, 9, 9, 9, 8, 8, 8, 8, 7, 7, 8, 8, 9, 9,
  118888. 9, 8, 8, 7, 7, 7, 7, 8, 8,
  118889. };
  118890. static float _vq_quantthresh__44c6_s_p7_1[] = {
  118891. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  118892. 3.5, 4.5,
  118893. };
  118894. static long _vq_quantmap__44c6_s_p7_1[] = {
  118895. 9, 7, 5, 3, 1, 0, 2, 4,
  118896. 6, 8, 10,
  118897. };
  118898. static encode_aux_threshmatch _vq_auxt__44c6_s_p7_1 = {
  118899. _vq_quantthresh__44c6_s_p7_1,
  118900. _vq_quantmap__44c6_s_p7_1,
  118901. 11,
  118902. 11
  118903. };
  118904. static static_codebook _44c6_s_p7_1 = {
  118905. 2, 121,
  118906. _vq_lengthlist__44c6_s_p7_1,
  118907. 1, -531365888, 1611661312, 4, 0,
  118908. _vq_quantlist__44c6_s_p7_1,
  118909. NULL,
  118910. &_vq_auxt__44c6_s_p7_1,
  118911. NULL,
  118912. 0
  118913. };
  118914. static long _vq_quantlist__44c6_s_p8_0[] = {
  118915. 7,
  118916. 6,
  118917. 8,
  118918. 5,
  118919. 9,
  118920. 4,
  118921. 10,
  118922. 3,
  118923. 11,
  118924. 2,
  118925. 12,
  118926. 1,
  118927. 13,
  118928. 0,
  118929. 14,
  118930. };
  118931. static long _vq_lengthlist__44c6_s_p8_0[] = {
  118932. 1, 4, 4, 7, 7, 8, 8, 7, 7, 8, 7, 9, 8,10, 9, 6,
  118933. 5, 5, 8, 8, 9, 9, 8, 8, 9, 9,11,10,11,10, 6, 5,
  118934. 5, 8, 8, 9, 9, 8, 8, 9, 9,10,10,11,11,18, 8, 8,
  118935. 9, 8,10,10, 9, 9,10,10,10,10,11,10,18, 8, 8, 9,
  118936. 9,10,10, 9, 9,10,10,11,11,12,12,18,12,13, 9,10,
  118937. 10,10, 9,10,10,10,11,11,12,11,18,13,13, 9, 9,10,
  118938. 10,10,10,10,10,11,11,12,12,18,18,18,10,10, 9, 9,
  118939. 11,11,11,11,11,12,12,12,18,18,18,10, 9,10, 9,11,
  118940. 10,11,11,11,11,13,12,18,18,18,14,13,10,10,11,11,
  118941. 12,12,12,12,12,12,18,18,18,14,13,10,10,11,10,12,
  118942. 12,12,12,12,12,18,18,18,18,18,12,12,11,11,12,12,
  118943. 13,13,13,14,18,18,18,18,18,12,12,11,11,12,11,13,
  118944. 13,14,13,18,18,18,18,18,16,16,11,12,12,13,13,13,
  118945. 14,13,18,18,18,18,18,16,15,12,11,12,11,13,11,15,
  118946. 14,
  118947. };
  118948. static float _vq_quantthresh__44c6_s_p8_0[] = {
  118949. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  118950. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  118951. };
  118952. static long _vq_quantmap__44c6_s_p8_0[] = {
  118953. 13, 11, 9, 7, 5, 3, 1, 0,
  118954. 2, 4, 6, 8, 10, 12, 14,
  118955. };
  118956. static encode_aux_threshmatch _vq_auxt__44c6_s_p8_0 = {
  118957. _vq_quantthresh__44c6_s_p8_0,
  118958. _vq_quantmap__44c6_s_p8_0,
  118959. 15,
  118960. 15
  118961. };
  118962. static static_codebook _44c6_s_p8_0 = {
  118963. 2, 225,
  118964. _vq_lengthlist__44c6_s_p8_0,
  118965. 1, -520986624, 1620377600, 4, 0,
  118966. _vq_quantlist__44c6_s_p8_0,
  118967. NULL,
  118968. &_vq_auxt__44c6_s_p8_0,
  118969. NULL,
  118970. 0
  118971. };
  118972. static long _vq_quantlist__44c6_s_p8_1[] = {
  118973. 10,
  118974. 9,
  118975. 11,
  118976. 8,
  118977. 12,
  118978. 7,
  118979. 13,
  118980. 6,
  118981. 14,
  118982. 5,
  118983. 15,
  118984. 4,
  118985. 16,
  118986. 3,
  118987. 17,
  118988. 2,
  118989. 18,
  118990. 1,
  118991. 19,
  118992. 0,
  118993. 20,
  118994. };
  118995. static long _vq_lengthlist__44c6_s_p8_1[] = {
  118996. 3, 5, 5, 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 8, 8, 8,
  118997. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,
  118998. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  118999. 8, 8, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,10,
  119000. 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119001. 9, 9, 9, 9,10,11,11, 8, 7, 8, 8, 8, 9, 9, 9, 9,
  119002. 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,11, 8, 8, 8, 8,
  119003. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,
  119004. 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119005. 9, 9, 9,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119006. 9, 9, 9, 9, 9, 9, 9, 9,11,11,11,11,11, 9, 9, 9,
  119007. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,11,11,11,
  119008. 11,11, 9, 9, 9, 9, 9, 9,10, 9, 9,10, 9,10, 9, 9,
  119009. 10, 9,11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9,10,10,
  119010. 10,10, 9,10,10, 9,10,11,11,11,11,11, 9, 9, 9, 9,
  119011. 10,10,10, 9,10,10,10,10, 9,10,10, 9,11,11,11,11,
  119012. 11,11,11, 9, 9, 9, 9,10,10,10,10, 9,10,10,10,10,
  119013. 10,11,11,11,11,11,11,11,10, 9,10,10,10,10,10,10,
  119014. 10, 9,10, 9,10,10,11,11,11,11,11,11,11,10, 9,10,
  119015. 9,10,10, 9,10,10,10,10,10,10,10,11,11,11,11,11,
  119016. 11,11,10,10,10,10,10,10,10, 9,10,10,10,10,10, 9,
  119017. 11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
  119018. 10,10,10,10,10,11,11,11,11,11,11,11,11,11,10,10,
  119019. 10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
  119020. 11,11,11,10,10,10,10,10,10,10,10,10, 9,10,10,11,
  119021. 11,11,11,11,11,11,11,11,10,10,10, 9,10,10,10,10,
  119022. 10,10,10,10,10,11,11,11,11,11,11,11,11,10,11, 9,
  119023. 10,10,10,10,10,10,10,10,10,
  119024. };
  119025. static float _vq_quantthresh__44c6_s_p8_1[] = {
  119026. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  119027. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  119028. 6.5, 7.5, 8.5, 9.5,
  119029. };
  119030. static long _vq_quantmap__44c6_s_p8_1[] = {
  119031. 19, 17, 15, 13, 11, 9, 7, 5,
  119032. 3, 1, 0, 2, 4, 6, 8, 10,
  119033. 12, 14, 16, 18, 20,
  119034. };
  119035. static encode_aux_threshmatch _vq_auxt__44c6_s_p8_1 = {
  119036. _vq_quantthresh__44c6_s_p8_1,
  119037. _vq_quantmap__44c6_s_p8_1,
  119038. 21,
  119039. 21
  119040. };
  119041. static static_codebook _44c6_s_p8_1 = {
  119042. 2, 441,
  119043. _vq_lengthlist__44c6_s_p8_1,
  119044. 1, -529268736, 1611661312, 5, 0,
  119045. _vq_quantlist__44c6_s_p8_1,
  119046. NULL,
  119047. &_vq_auxt__44c6_s_p8_1,
  119048. NULL,
  119049. 0
  119050. };
  119051. static long _vq_quantlist__44c6_s_p9_0[] = {
  119052. 6,
  119053. 5,
  119054. 7,
  119055. 4,
  119056. 8,
  119057. 3,
  119058. 9,
  119059. 2,
  119060. 10,
  119061. 1,
  119062. 11,
  119063. 0,
  119064. 12,
  119065. };
  119066. static long _vq_lengthlist__44c6_s_p9_0[] = {
  119067. 1, 3, 3,11,11,11,11,11,11,11,11,11,11, 4, 7, 7,
  119068. 11,11,11,11,11,11,11,11,11,11, 5, 8, 9,11,11,11,
  119069. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119070. 11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,10,
  119071. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  119072. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  119073. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  119074. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  119075. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  119076. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  119077. 10,10,10,10,10,10,10,10,10,
  119078. };
  119079. static float _vq_quantthresh__44c6_s_p9_0[] = {
  119080. -3503.5, -2866.5, -2229.5, -1592.5, -955.5, -318.5, 318.5, 955.5,
  119081. 1592.5, 2229.5, 2866.5, 3503.5,
  119082. };
  119083. static long _vq_quantmap__44c6_s_p9_0[] = {
  119084. 11, 9, 7, 5, 3, 1, 0, 2,
  119085. 4, 6, 8, 10, 12,
  119086. };
  119087. static encode_aux_threshmatch _vq_auxt__44c6_s_p9_0 = {
  119088. _vq_quantthresh__44c6_s_p9_0,
  119089. _vq_quantmap__44c6_s_p9_0,
  119090. 13,
  119091. 13
  119092. };
  119093. static static_codebook _44c6_s_p9_0 = {
  119094. 2, 169,
  119095. _vq_lengthlist__44c6_s_p9_0,
  119096. 1, -511845376, 1630791680, 4, 0,
  119097. _vq_quantlist__44c6_s_p9_0,
  119098. NULL,
  119099. &_vq_auxt__44c6_s_p9_0,
  119100. NULL,
  119101. 0
  119102. };
  119103. static long _vq_quantlist__44c6_s_p9_1[] = {
  119104. 6,
  119105. 5,
  119106. 7,
  119107. 4,
  119108. 8,
  119109. 3,
  119110. 9,
  119111. 2,
  119112. 10,
  119113. 1,
  119114. 11,
  119115. 0,
  119116. 12,
  119117. };
  119118. static long _vq_lengthlist__44c6_s_p9_1[] = {
  119119. 1, 4, 4, 7, 7, 7, 7, 7, 6, 8, 8, 8, 8, 6, 6, 6,
  119120. 8, 8, 8, 8, 8, 7, 9, 8,10,10, 5, 6, 6, 8, 8, 9,
  119121. 9, 8, 8,10,10,10,10,16, 9, 9, 9, 9, 9, 9, 9, 8,
  119122. 10, 9,11,11,16, 8, 9, 9, 9, 9, 9, 9, 9,10,10,11,
  119123. 11,16,13,13, 9, 9,10, 9, 9,10,11,11,11,12,16,13,
  119124. 14, 9, 8,10, 8, 9, 9,10,10,12,11,16,14,16, 9, 9,
  119125. 9, 9,11,11,12,11,12,11,16,16,16, 9, 7, 9, 6,11,
  119126. 11,11,10,11,11,16,16,16,11,12, 9,10,11,11,12,11,
  119127. 13,13,16,16,16,12,11,10, 7,12,10,12,12,12,12,16,
  119128. 16,15,16,16,10,11,10,11,13,13,14,12,16,16,16,15,
  119129. 15,12,10,11,11,13,11,12,13,
  119130. };
  119131. static float _vq_quantthresh__44c6_s_p9_1[] = {
  119132. -269.5, -220.5, -171.5, -122.5, -73.5, -24.5, 24.5, 73.5,
  119133. 122.5, 171.5, 220.5, 269.5,
  119134. };
  119135. static long _vq_quantmap__44c6_s_p9_1[] = {
  119136. 11, 9, 7, 5, 3, 1, 0, 2,
  119137. 4, 6, 8, 10, 12,
  119138. };
  119139. static encode_aux_threshmatch _vq_auxt__44c6_s_p9_1 = {
  119140. _vq_quantthresh__44c6_s_p9_1,
  119141. _vq_quantmap__44c6_s_p9_1,
  119142. 13,
  119143. 13
  119144. };
  119145. static static_codebook _44c6_s_p9_1 = {
  119146. 2, 169,
  119147. _vq_lengthlist__44c6_s_p9_1,
  119148. 1, -518889472, 1622704128, 4, 0,
  119149. _vq_quantlist__44c6_s_p9_1,
  119150. NULL,
  119151. &_vq_auxt__44c6_s_p9_1,
  119152. NULL,
  119153. 0
  119154. };
  119155. static long _vq_quantlist__44c6_s_p9_2[] = {
  119156. 24,
  119157. 23,
  119158. 25,
  119159. 22,
  119160. 26,
  119161. 21,
  119162. 27,
  119163. 20,
  119164. 28,
  119165. 19,
  119166. 29,
  119167. 18,
  119168. 30,
  119169. 17,
  119170. 31,
  119171. 16,
  119172. 32,
  119173. 15,
  119174. 33,
  119175. 14,
  119176. 34,
  119177. 13,
  119178. 35,
  119179. 12,
  119180. 36,
  119181. 11,
  119182. 37,
  119183. 10,
  119184. 38,
  119185. 9,
  119186. 39,
  119187. 8,
  119188. 40,
  119189. 7,
  119190. 41,
  119191. 6,
  119192. 42,
  119193. 5,
  119194. 43,
  119195. 4,
  119196. 44,
  119197. 3,
  119198. 45,
  119199. 2,
  119200. 46,
  119201. 1,
  119202. 47,
  119203. 0,
  119204. 48,
  119205. };
  119206. static long _vq_lengthlist__44c6_s_p9_2[] = {
  119207. 2, 4, 3, 4, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  119208. 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  119209. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  119210. 7,
  119211. };
  119212. static float _vq_quantthresh__44c6_s_p9_2[] = {
  119213. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  119214. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  119215. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  119216. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  119217. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  119218. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  119219. };
  119220. static long _vq_quantmap__44c6_s_p9_2[] = {
  119221. 47, 45, 43, 41, 39, 37, 35, 33,
  119222. 31, 29, 27, 25, 23, 21, 19, 17,
  119223. 15, 13, 11, 9, 7, 5, 3, 1,
  119224. 0, 2, 4, 6, 8, 10, 12, 14,
  119225. 16, 18, 20, 22, 24, 26, 28, 30,
  119226. 32, 34, 36, 38, 40, 42, 44, 46,
  119227. 48,
  119228. };
  119229. static encode_aux_threshmatch _vq_auxt__44c6_s_p9_2 = {
  119230. _vq_quantthresh__44c6_s_p9_2,
  119231. _vq_quantmap__44c6_s_p9_2,
  119232. 49,
  119233. 49
  119234. };
  119235. static static_codebook _44c6_s_p9_2 = {
  119236. 1, 49,
  119237. _vq_lengthlist__44c6_s_p9_2,
  119238. 1, -526909440, 1611661312, 6, 0,
  119239. _vq_quantlist__44c6_s_p9_2,
  119240. NULL,
  119241. &_vq_auxt__44c6_s_p9_2,
  119242. NULL,
  119243. 0
  119244. };
  119245. static long _huff_lengthlist__44c6_s_short[] = {
  119246. 3, 9,11,11,13,14,19,17,17,19, 5, 4, 5, 8,10,10,
  119247. 13,16,18,19, 7, 4, 4, 5, 8, 9,12,14,17,19, 8, 6,
  119248. 5, 5, 7, 7,10,13,16,18,10, 8, 7, 6, 5, 5, 8,11,
  119249. 17,19,11, 9, 7, 7, 5, 4, 5, 8,17,19,13,11, 8, 7,
  119250. 7, 5, 5, 7,16,18,14,13, 8, 6, 6, 5, 5, 7,16,18,
  119251. 18,16,10, 8, 8, 7, 7, 9,16,18,18,18,12,10,10, 9,
  119252. 9,10,17,18,
  119253. };
  119254. static static_codebook _huff_book__44c6_s_short = {
  119255. 2, 100,
  119256. _huff_lengthlist__44c6_s_short,
  119257. 0, 0, 0, 0, 0,
  119258. NULL,
  119259. NULL,
  119260. NULL,
  119261. NULL,
  119262. 0
  119263. };
  119264. static long _huff_lengthlist__44c7_s_long[] = {
  119265. 3, 8,11,13,15,14,14,13,15,14, 6, 4, 5, 7, 9,10,
  119266. 11,11,14,13,10, 4, 3, 5, 7, 8, 9,10,13,13,12, 7,
  119267. 4, 4, 5, 6, 8, 9,12,14,13, 9, 6, 5, 5, 6, 8, 9,
  119268. 12,14,12, 9, 7, 6, 5, 5, 6, 8,11,11,12,11, 9, 8,
  119269. 7, 6, 6, 7,10,11,13,11,10, 9, 8, 7, 6, 6, 9,11,
  119270. 13,13,12,12,12,10, 9, 8, 9,11,12,14,15,15,14,12,
  119271. 11,10,10,12,
  119272. };
  119273. static static_codebook _huff_book__44c7_s_long = {
  119274. 2, 100,
  119275. _huff_lengthlist__44c7_s_long,
  119276. 0, 0, 0, 0, 0,
  119277. NULL,
  119278. NULL,
  119279. NULL,
  119280. NULL,
  119281. 0
  119282. };
  119283. static long _vq_quantlist__44c7_s_p1_0[] = {
  119284. 1,
  119285. 0,
  119286. 2,
  119287. };
  119288. static long _vq_lengthlist__44c7_s_p1_0[] = {
  119289. 1, 5, 5, 0, 5, 5, 0, 5, 5, 5, 8, 7, 0, 9, 9, 0,
  119290. 9, 8, 5, 7, 8, 0, 9, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  119291. 0, 0, 0, 0, 5, 9, 9, 0, 8, 8, 0, 8, 8, 5, 8, 9,
  119292. 0, 8, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  119293. 9, 9, 0, 8, 8, 0, 8, 8, 5, 8, 9, 0, 8, 8, 0, 8,
  119294. 8,
  119295. };
  119296. static float _vq_quantthresh__44c7_s_p1_0[] = {
  119297. -0.5, 0.5,
  119298. };
  119299. static long _vq_quantmap__44c7_s_p1_0[] = {
  119300. 1, 0, 2,
  119301. };
  119302. static encode_aux_threshmatch _vq_auxt__44c7_s_p1_0 = {
  119303. _vq_quantthresh__44c7_s_p1_0,
  119304. _vq_quantmap__44c7_s_p1_0,
  119305. 3,
  119306. 3
  119307. };
  119308. static static_codebook _44c7_s_p1_0 = {
  119309. 4, 81,
  119310. _vq_lengthlist__44c7_s_p1_0,
  119311. 1, -535822336, 1611661312, 2, 0,
  119312. _vq_quantlist__44c7_s_p1_0,
  119313. NULL,
  119314. &_vq_auxt__44c7_s_p1_0,
  119315. NULL,
  119316. 0
  119317. };
  119318. static long _vq_quantlist__44c7_s_p2_0[] = {
  119319. 2,
  119320. 1,
  119321. 3,
  119322. 0,
  119323. 4,
  119324. };
  119325. static long _vq_lengthlist__44c7_s_p2_0[] = {
  119326. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  119327. 7, 7, 9, 9, 0, 0, 0, 9, 9, 5, 7, 7, 9, 9, 0, 8,
  119328. 8,10,10, 0, 8, 7,10, 9, 0,10,10,11,11, 0, 0, 0,
  119329. 11,11, 5, 7, 7, 9, 9, 0, 8, 8,10,10, 0, 7, 8, 9,
  119330. 10, 0,10,10,11,11, 0, 0, 0,11,11, 8, 9, 9,11,10,
  119331. 0,11,11,12,12, 0,11,10,12,12, 0,13,14,14,14, 0,
  119332. 0, 0,14,13, 8, 9, 9,10,11, 0,11,11,12,12, 0,10,
  119333. 11,12,12, 0,13,13,14,14, 0, 0, 0,13,14, 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, 5, 8, 7,11,10, 0, 7, 7,10,10,
  119336. 0, 7, 7,10,10, 0, 9, 9,11,10, 0, 0, 0,11,11, 5,
  119337. 7, 8,10,11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9,
  119338. 9,10,11, 0, 0, 0,11,11, 8,10, 9,12,12, 0,10,10,
  119339. 12,12, 0,10,10,12,12, 0,12,12,13,13, 0, 0, 0,13,
  119340. 13, 8, 9,10,12,12, 0,10,10,12,12, 0,10,10,11,12,
  119341. 0,12,12,13,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0,
  119342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119343. 0, 0, 0, 5, 8, 8,11,11, 0, 7, 7,10,10, 0, 7, 7,
  119344. 10,10, 0, 9, 9,10,11, 0, 0, 0,11,10, 5, 8, 8,10,
  119345. 11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9, 9,11,10,
  119346. 0, 0, 0,10,11, 9,10,10,12,12, 0,10,10,12,12, 0,
  119347. 10,10,12,12, 0,12,13,13,13, 0, 0, 0,13,12, 9,10,
  119348. 10,12,12, 0,10,10,12,12, 0,10,10,12,12, 0,13,12,
  119349. 13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119351. 7,10,10,14,13, 0, 9, 9,12,12, 0, 9, 9,12,12, 0,
  119352. 10,10,12,12, 0, 0, 0,12,12, 7,10,10,13,14, 0, 9,
  119353. 9,12,13, 0, 9, 9,12,12, 0,10,10,12,12, 0, 0, 0,
  119354. 12,12, 9,11,11,14,13, 0,11,10,13,12, 0,11,11,13,
  119355. 13, 0,12,12,13,13, 0, 0, 0,13,13, 9,11,11,13,14,
  119356. 0,10,11,12,13, 0,11,11,13,13, 0,12,12,13,13, 0,
  119357. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  119362. 11,11,14,14, 0,10,11,13,13, 0,11,10,13,13, 0,12,
  119363. 12,13,13, 0, 0, 0,13,12, 9,11,11,14,14, 0,11,10,
  119364. 13,13, 0,10,11,13,13, 0,12,12,14,13, 0, 0, 0,13,
  119365. 13,
  119366. };
  119367. static float _vq_quantthresh__44c7_s_p2_0[] = {
  119368. -1.5, -0.5, 0.5, 1.5,
  119369. };
  119370. static long _vq_quantmap__44c7_s_p2_0[] = {
  119371. 3, 1, 0, 2, 4,
  119372. };
  119373. static encode_aux_threshmatch _vq_auxt__44c7_s_p2_0 = {
  119374. _vq_quantthresh__44c7_s_p2_0,
  119375. _vq_quantmap__44c7_s_p2_0,
  119376. 5,
  119377. 5
  119378. };
  119379. static static_codebook _44c7_s_p2_0 = {
  119380. 4, 625,
  119381. _vq_lengthlist__44c7_s_p2_0,
  119382. 1, -533725184, 1611661312, 3, 0,
  119383. _vq_quantlist__44c7_s_p2_0,
  119384. NULL,
  119385. &_vq_auxt__44c7_s_p2_0,
  119386. NULL,
  119387. 0
  119388. };
  119389. static long _vq_quantlist__44c7_s_p3_0[] = {
  119390. 4,
  119391. 3,
  119392. 5,
  119393. 2,
  119394. 6,
  119395. 1,
  119396. 7,
  119397. 0,
  119398. 8,
  119399. };
  119400. static long _vq_lengthlist__44c7_s_p3_0[] = {
  119401. 2, 4, 4, 5, 5, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  119402. 9, 9, 0, 4, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 6, 6,
  119403. 8, 8,10,10, 0, 0, 0, 6, 6, 8, 8,10,10, 0, 0, 0,
  119404. 7, 7, 9, 9,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0,
  119405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119406. 0,
  119407. };
  119408. static float _vq_quantthresh__44c7_s_p3_0[] = {
  119409. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  119410. };
  119411. static long _vq_quantmap__44c7_s_p3_0[] = {
  119412. 7, 5, 3, 1, 0, 2, 4, 6,
  119413. 8,
  119414. };
  119415. static encode_aux_threshmatch _vq_auxt__44c7_s_p3_0 = {
  119416. _vq_quantthresh__44c7_s_p3_0,
  119417. _vq_quantmap__44c7_s_p3_0,
  119418. 9,
  119419. 9
  119420. };
  119421. static static_codebook _44c7_s_p3_0 = {
  119422. 2, 81,
  119423. _vq_lengthlist__44c7_s_p3_0,
  119424. 1, -531628032, 1611661312, 4, 0,
  119425. _vq_quantlist__44c7_s_p3_0,
  119426. NULL,
  119427. &_vq_auxt__44c7_s_p3_0,
  119428. NULL,
  119429. 0
  119430. };
  119431. static long _vq_quantlist__44c7_s_p4_0[] = {
  119432. 8,
  119433. 7,
  119434. 9,
  119435. 6,
  119436. 10,
  119437. 5,
  119438. 11,
  119439. 4,
  119440. 12,
  119441. 3,
  119442. 13,
  119443. 2,
  119444. 14,
  119445. 1,
  119446. 15,
  119447. 0,
  119448. 16,
  119449. };
  119450. static long _vq_lengthlist__44c7_s_p4_0[] = {
  119451. 3, 4, 4, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  119452. 11, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,
  119453. 12,12, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  119454. 11,12,12, 0, 5, 5, 6, 6, 8, 8, 9, 9, 9, 9,10,10,
  119455. 11,12,12,12, 0, 0, 0, 6, 6, 8, 7, 9, 9, 9, 9,10,
  119456. 10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,10,
  119457. 11,11,12,12,13,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,
  119458. 10,11,11,12,12,12,13, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  119459. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 8, 8, 9,
  119460. 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 0, 0,
  119461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119469. 0,
  119470. };
  119471. static float _vq_quantthresh__44c7_s_p4_0[] = {
  119472. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  119473. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  119474. };
  119475. static long _vq_quantmap__44c7_s_p4_0[] = {
  119476. 15, 13, 11, 9, 7, 5, 3, 1,
  119477. 0, 2, 4, 6, 8, 10, 12, 14,
  119478. 16,
  119479. };
  119480. static encode_aux_threshmatch _vq_auxt__44c7_s_p4_0 = {
  119481. _vq_quantthresh__44c7_s_p4_0,
  119482. _vq_quantmap__44c7_s_p4_0,
  119483. 17,
  119484. 17
  119485. };
  119486. static static_codebook _44c7_s_p4_0 = {
  119487. 2, 289,
  119488. _vq_lengthlist__44c7_s_p4_0,
  119489. 1, -529530880, 1611661312, 5, 0,
  119490. _vq_quantlist__44c7_s_p4_0,
  119491. NULL,
  119492. &_vq_auxt__44c7_s_p4_0,
  119493. NULL,
  119494. 0
  119495. };
  119496. static long _vq_quantlist__44c7_s_p5_0[] = {
  119497. 1,
  119498. 0,
  119499. 2,
  119500. };
  119501. static long _vq_lengthlist__44c7_s_p5_0[] = {
  119502. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 6, 7,10,10,10,10,
  119503. 10, 9, 4, 6, 6,10,10,10,10, 9,10, 5,10,10, 9,11,
  119504. 12,10,11,12, 7,10,10,11,12,12,12,12,12, 7,10,10,
  119505. 11,12,12,12,12,12, 6,10,10,10,12,12,11,12,12, 7,
  119506. 10,10,12,12,12,12,11,12, 7,10,10,11,12,12,12,12,
  119507. 12,
  119508. };
  119509. static float _vq_quantthresh__44c7_s_p5_0[] = {
  119510. -5.5, 5.5,
  119511. };
  119512. static long _vq_quantmap__44c7_s_p5_0[] = {
  119513. 1, 0, 2,
  119514. };
  119515. static encode_aux_threshmatch _vq_auxt__44c7_s_p5_0 = {
  119516. _vq_quantthresh__44c7_s_p5_0,
  119517. _vq_quantmap__44c7_s_p5_0,
  119518. 3,
  119519. 3
  119520. };
  119521. static static_codebook _44c7_s_p5_0 = {
  119522. 4, 81,
  119523. _vq_lengthlist__44c7_s_p5_0,
  119524. 1, -529137664, 1618345984, 2, 0,
  119525. _vq_quantlist__44c7_s_p5_0,
  119526. NULL,
  119527. &_vq_auxt__44c7_s_p5_0,
  119528. NULL,
  119529. 0
  119530. };
  119531. static long _vq_quantlist__44c7_s_p5_1[] = {
  119532. 5,
  119533. 4,
  119534. 6,
  119535. 3,
  119536. 7,
  119537. 2,
  119538. 8,
  119539. 1,
  119540. 9,
  119541. 0,
  119542. 10,
  119543. };
  119544. static long _vq_lengthlist__44c7_s_p5_1[] = {
  119545. 3, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8,11, 4, 4, 6, 6,
  119546. 7, 7, 8, 8, 9, 9,11, 4, 4, 6, 6, 7, 7, 8, 8, 9,
  119547. 9,12, 5, 5, 6, 6, 7, 7, 9, 9, 9, 9,12,12,12, 6,
  119548. 6, 7, 7, 9, 9, 9, 9,11,11,11, 7, 7, 7, 7, 8, 8,
  119549. 9, 9,11,11,11, 7, 7, 7, 7, 8, 8, 9, 9,11,11,11,
  119550. 7, 7, 8, 8, 8, 8, 9, 9,11,11,11,11,11, 8, 8, 8,
  119551. 8, 8, 9,11,11,11,11,11, 8, 8, 8, 8, 8, 8,11,11,
  119552. 11,11,11, 7, 7, 8, 8, 8, 8,
  119553. };
  119554. static float _vq_quantthresh__44c7_s_p5_1[] = {
  119555. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  119556. 3.5, 4.5,
  119557. };
  119558. static long _vq_quantmap__44c7_s_p5_1[] = {
  119559. 9, 7, 5, 3, 1, 0, 2, 4,
  119560. 6, 8, 10,
  119561. };
  119562. static encode_aux_threshmatch _vq_auxt__44c7_s_p5_1 = {
  119563. _vq_quantthresh__44c7_s_p5_1,
  119564. _vq_quantmap__44c7_s_p5_1,
  119565. 11,
  119566. 11
  119567. };
  119568. static static_codebook _44c7_s_p5_1 = {
  119569. 2, 121,
  119570. _vq_lengthlist__44c7_s_p5_1,
  119571. 1, -531365888, 1611661312, 4, 0,
  119572. _vq_quantlist__44c7_s_p5_1,
  119573. NULL,
  119574. &_vq_auxt__44c7_s_p5_1,
  119575. NULL,
  119576. 0
  119577. };
  119578. static long _vq_quantlist__44c7_s_p6_0[] = {
  119579. 6,
  119580. 5,
  119581. 7,
  119582. 4,
  119583. 8,
  119584. 3,
  119585. 9,
  119586. 2,
  119587. 10,
  119588. 1,
  119589. 11,
  119590. 0,
  119591. 12,
  119592. };
  119593. static long _vq_lengthlist__44c7_s_p6_0[] = {
  119594. 1, 4, 4, 6, 6, 7, 7, 8, 7, 9, 8,10,10, 6, 5, 5,
  119595. 7, 7, 8, 8, 9, 9, 9,10,11,11, 7, 5, 5, 7, 7, 8,
  119596. 8, 9, 9,10,10,11,11, 0, 7, 7, 7, 7, 9, 8, 9, 9,
  119597. 10,10,11,11, 0, 8, 8, 7, 7, 8, 9, 9, 9,10,10,11,
  119598. 11, 0,11,11, 9, 9,10,10,11,10,11,11,12,12, 0,12,
  119599. 12, 9, 9,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0,
  119600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119604. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119605. };
  119606. static float _vq_quantthresh__44c7_s_p6_0[] = {
  119607. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  119608. 12.5, 17.5, 22.5, 27.5,
  119609. };
  119610. static long _vq_quantmap__44c7_s_p6_0[] = {
  119611. 11, 9, 7, 5, 3, 1, 0, 2,
  119612. 4, 6, 8, 10, 12,
  119613. };
  119614. static encode_aux_threshmatch _vq_auxt__44c7_s_p6_0 = {
  119615. _vq_quantthresh__44c7_s_p6_0,
  119616. _vq_quantmap__44c7_s_p6_0,
  119617. 13,
  119618. 13
  119619. };
  119620. static static_codebook _44c7_s_p6_0 = {
  119621. 2, 169,
  119622. _vq_lengthlist__44c7_s_p6_0,
  119623. 1, -526516224, 1616117760, 4, 0,
  119624. _vq_quantlist__44c7_s_p6_0,
  119625. NULL,
  119626. &_vq_auxt__44c7_s_p6_0,
  119627. NULL,
  119628. 0
  119629. };
  119630. static long _vq_quantlist__44c7_s_p6_1[] = {
  119631. 2,
  119632. 1,
  119633. 3,
  119634. 0,
  119635. 4,
  119636. };
  119637. static long _vq_lengthlist__44c7_s_p6_1[] = {
  119638. 3, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 6,
  119639. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  119640. };
  119641. static float _vq_quantthresh__44c7_s_p6_1[] = {
  119642. -1.5, -0.5, 0.5, 1.5,
  119643. };
  119644. static long _vq_quantmap__44c7_s_p6_1[] = {
  119645. 3, 1, 0, 2, 4,
  119646. };
  119647. static encode_aux_threshmatch _vq_auxt__44c7_s_p6_1 = {
  119648. _vq_quantthresh__44c7_s_p6_1,
  119649. _vq_quantmap__44c7_s_p6_1,
  119650. 5,
  119651. 5
  119652. };
  119653. static static_codebook _44c7_s_p6_1 = {
  119654. 2, 25,
  119655. _vq_lengthlist__44c7_s_p6_1,
  119656. 1, -533725184, 1611661312, 3, 0,
  119657. _vq_quantlist__44c7_s_p6_1,
  119658. NULL,
  119659. &_vq_auxt__44c7_s_p6_1,
  119660. NULL,
  119661. 0
  119662. };
  119663. static long _vq_quantlist__44c7_s_p7_0[] = {
  119664. 6,
  119665. 5,
  119666. 7,
  119667. 4,
  119668. 8,
  119669. 3,
  119670. 9,
  119671. 2,
  119672. 10,
  119673. 1,
  119674. 11,
  119675. 0,
  119676. 12,
  119677. };
  119678. static long _vq_lengthlist__44c7_s_p7_0[] = {
  119679. 1, 4, 4, 6, 6, 7, 8, 9, 9,10,10,12,11, 6, 5, 5,
  119680. 7, 7, 8, 8, 9,10,11,11,12,12, 7, 5, 5, 7, 7, 8,
  119681. 8,10,10,11,11,12,12,20, 7, 7, 7, 7, 8, 9,10,10,
  119682. 11,11,12,13,20, 7, 7, 7, 7, 9, 9,10,10,11,12,13,
  119683. 13,20,11,11, 8, 8, 9, 9,11,11,12,12,13,13,20,11,
  119684. 11, 8, 8, 9, 9,11,11,12,12,13,13,20,20,20,10,10,
  119685. 10,10,12,12,13,13,13,13,20,20,20,10,10,10,10,12,
  119686. 12,13,13,13,14,20,20,20,14,14,11,11,12,12,13,13,
  119687. 14,14,20,20,20,14,14,11,11,12,12,13,13,14,14,20,
  119688. 20,20,20,19,13,13,13,13,14,14,15,14,19,19,19,19,
  119689. 19,13,13,13,13,14,14,15,15,
  119690. };
  119691. static float _vq_quantthresh__44c7_s_p7_0[] = {
  119692. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  119693. 27.5, 38.5, 49.5, 60.5,
  119694. };
  119695. static long _vq_quantmap__44c7_s_p7_0[] = {
  119696. 11, 9, 7, 5, 3, 1, 0, 2,
  119697. 4, 6, 8, 10, 12,
  119698. };
  119699. static encode_aux_threshmatch _vq_auxt__44c7_s_p7_0 = {
  119700. _vq_quantthresh__44c7_s_p7_0,
  119701. _vq_quantmap__44c7_s_p7_0,
  119702. 13,
  119703. 13
  119704. };
  119705. static static_codebook _44c7_s_p7_0 = {
  119706. 2, 169,
  119707. _vq_lengthlist__44c7_s_p7_0,
  119708. 1, -523206656, 1618345984, 4, 0,
  119709. _vq_quantlist__44c7_s_p7_0,
  119710. NULL,
  119711. &_vq_auxt__44c7_s_p7_0,
  119712. NULL,
  119713. 0
  119714. };
  119715. static long _vq_quantlist__44c7_s_p7_1[] = {
  119716. 5,
  119717. 4,
  119718. 6,
  119719. 3,
  119720. 7,
  119721. 2,
  119722. 8,
  119723. 1,
  119724. 9,
  119725. 0,
  119726. 10,
  119727. };
  119728. static long _vq_lengthlist__44c7_s_p7_1[] = {
  119729. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 8, 6, 6, 7, 7,
  119730. 7, 7, 7, 7, 7, 7, 8, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  119731. 7, 8, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7,
  119732. 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  119733. 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  119734. 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  119735. 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 8, 8,
  119736. 8, 8, 8, 7, 7, 7, 7, 7, 7,
  119737. };
  119738. static float _vq_quantthresh__44c7_s_p7_1[] = {
  119739. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  119740. 3.5, 4.5,
  119741. };
  119742. static long _vq_quantmap__44c7_s_p7_1[] = {
  119743. 9, 7, 5, 3, 1, 0, 2, 4,
  119744. 6, 8, 10,
  119745. };
  119746. static encode_aux_threshmatch _vq_auxt__44c7_s_p7_1 = {
  119747. _vq_quantthresh__44c7_s_p7_1,
  119748. _vq_quantmap__44c7_s_p7_1,
  119749. 11,
  119750. 11
  119751. };
  119752. static static_codebook _44c7_s_p7_1 = {
  119753. 2, 121,
  119754. _vq_lengthlist__44c7_s_p7_1,
  119755. 1, -531365888, 1611661312, 4, 0,
  119756. _vq_quantlist__44c7_s_p7_1,
  119757. NULL,
  119758. &_vq_auxt__44c7_s_p7_1,
  119759. NULL,
  119760. 0
  119761. };
  119762. static long _vq_quantlist__44c7_s_p8_0[] = {
  119763. 7,
  119764. 6,
  119765. 8,
  119766. 5,
  119767. 9,
  119768. 4,
  119769. 10,
  119770. 3,
  119771. 11,
  119772. 2,
  119773. 12,
  119774. 1,
  119775. 13,
  119776. 0,
  119777. 14,
  119778. };
  119779. static long _vq_lengthlist__44c7_s_p8_0[] = {
  119780. 1, 4, 4, 7, 7, 8, 8, 8, 7, 9, 8, 9, 9,10,10, 6,
  119781. 5, 5, 7, 7, 9, 9, 8, 8,10, 9,11,10,12,11, 6, 5,
  119782. 5, 8, 7, 9, 9, 8, 8,10,10,11,11,12,11,19, 8, 8,
  119783. 8, 8,10,10, 9, 9,10,10,11,11,12,11,19, 8, 8, 8,
  119784. 8,10,10, 9, 9,10,10,11,11,12,12,19,12,12, 9, 9,
  119785. 10,10, 9,10,10,10,11,11,12,12,19,12,12, 9, 9,10,
  119786. 10,10,10,10,10,12,12,12,12,19,19,19, 9, 9, 9, 9,
  119787. 11,10,11,11,12,11,13,13,19,19,19, 9, 9, 9, 9,11,
  119788. 10,11,11,11,12,13,13,19,19,19,13,13,10,10,11,11,
  119789. 12,12,12,12,13,12,19,19,19,14,13,10,10,11,11,12,
  119790. 12,12,13,13,13,19,19,19,19,19,12,12,12,11,12,13,
  119791. 14,13,13,13,19,19,19,19,19,12,12,12,11,12,12,13,
  119792. 14,13,14,19,19,19,19,19,16,16,12,13,12,13,13,14,
  119793. 15,14,19,18,18,18,18,16,15,12,11,12,11,14,12,14,
  119794. 14,
  119795. };
  119796. static float _vq_quantthresh__44c7_s_p8_0[] = {
  119797. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  119798. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  119799. };
  119800. static long _vq_quantmap__44c7_s_p8_0[] = {
  119801. 13, 11, 9, 7, 5, 3, 1, 0,
  119802. 2, 4, 6, 8, 10, 12, 14,
  119803. };
  119804. static encode_aux_threshmatch _vq_auxt__44c7_s_p8_0 = {
  119805. _vq_quantthresh__44c7_s_p8_0,
  119806. _vq_quantmap__44c7_s_p8_0,
  119807. 15,
  119808. 15
  119809. };
  119810. static static_codebook _44c7_s_p8_0 = {
  119811. 2, 225,
  119812. _vq_lengthlist__44c7_s_p8_0,
  119813. 1, -520986624, 1620377600, 4, 0,
  119814. _vq_quantlist__44c7_s_p8_0,
  119815. NULL,
  119816. &_vq_auxt__44c7_s_p8_0,
  119817. NULL,
  119818. 0
  119819. };
  119820. static long _vq_quantlist__44c7_s_p8_1[] = {
  119821. 10,
  119822. 9,
  119823. 11,
  119824. 8,
  119825. 12,
  119826. 7,
  119827. 13,
  119828. 6,
  119829. 14,
  119830. 5,
  119831. 15,
  119832. 4,
  119833. 16,
  119834. 3,
  119835. 17,
  119836. 2,
  119837. 18,
  119838. 1,
  119839. 19,
  119840. 0,
  119841. 20,
  119842. };
  119843. static long _vq_lengthlist__44c7_s_p8_1[] = {
  119844. 3, 5, 5, 7, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  119845. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  119846. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  119847. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,
  119848. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119849. 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  119850. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 9,
  119851. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  119852. 10, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119853. 9, 9, 9,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119854. 9, 9, 9, 9, 9, 9, 9, 9,10,11,10,10,10, 9, 9, 9,
  119855. 9, 9, 9, 9, 9, 9, 9,10, 9, 9,10, 9, 9,10,11,10,
  119856. 11,10, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9,10, 9, 9,
  119857. 9, 9,11,10,11,10,10, 9, 9, 9, 9, 9, 9,10, 9, 9,
  119858. 10, 9, 9,10, 9, 9,10,11,10,10,11,10, 9, 9, 9, 9,
  119859. 9,10,10, 9,10,10,10,10, 9,10,10,10,10,10,10,11,
  119860. 11,11,10, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,
  119861. 10,10,10,11,11,10,10,10,10,10,10,10,10,10,10,10,
  119862. 10, 9,10,10, 9,10,11,11,10,11,10,11,10, 9,10,10,
  119863. 9,10,10,10,10,10,10,10,10,10,10,11,11,11,11,10,
  119864. 11,11,10,10,10,10,10,10, 9,10, 9,10,10, 9,10, 9,
  119865. 10,10,10,11,10,11,10,11,11,10,10,10,10,10,10, 9,
  119866. 10,10,10,10,10,10,10,11,10,10,10,10,10,10,10,10,
  119867. 10,10,10,10,10,10,10,10,10,10,10,10,10,11,10,11,
  119868. 11,10,10,10,10, 9, 9,10,10, 9, 9,10, 9,10,10,10,
  119869. 10,11,11,10,10,10,10,10,10,10, 9, 9,10,10,10, 9,
  119870. 9,10,10,10,10,10,11,10,11,10,10,10,10,10,10, 9,
  119871. 10,10,10,10,10,10,10,10,10,
  119872. };
  119873. static float _vq_quantthresh__44c7_s_p8_1[] = {
  119874. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  119875. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  119876. 6.5, 7.5, 8.5, 9.5,
  119877. };
  119878. static long _vq_quantmap__44c7_s_p8_1[] = {
  119879. 19, 17, 15, 13, 11, 9, 7, 5,
  119880. 3, 1, 0, 2, 4, 6, 8, 10,
  119881. 12, 14, 16, 18, 20,
  119882. };
  119883. static encode_aux_threshmatch _vq_auxt__44c7_s_p8_1 = {
  119884. _vq_quantthresh__44c7_s_p8_1,
  119885. _vq_quantmap__44c7_s_p8_1,
  119886. 21,
  119887. 21
  119888. };
  119889. static static_codebook _44c7_s_p8_1 = {
  119890. 2, 441,
  119891. _vq_lengthlist__44c7_s_p8_1,
  119892. 1, -529268736, 1611661312, 5, 0,
  119893. _vq_quantlist__44c7_s_p8_1,
  119894. NULL,
  119895. &_vq_auxt__44c7_s_p8_1,
  119896. NULL,
  119897. 0
  119898. };
  119899. static long _vq_quantlist__44c7_s_p9_0[] = {
  119900. 6,
  119901. 5,
  119902. 7,
  119903. 4,
  119904. 8,
  119905. 3,
  119906. 9,
  119907. 2,
  119908. 10,
  119909. 1,
  119910. 11,
  119911. 0,
  119912. 12,
  119913. };
  119914. static long _vq_lengthlist__44c7_s_p9_0[] = {
  119915. 1, 3, 3,11,11,11,11,11,11,11,11,11,11, 4, 6, 6,
  119916. 11,11,11,11,11,11,11,11,11,11, 4, 7, 7,11,11,11,
  119917. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119918. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119919. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119920. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119921. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119922. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119923. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119924. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119925. 11,11,11,11,11,11,11,11,11,
  119926. };
  119927. static float _vq_quantthresh__44c7_s_p9_0[] = {
  119928. -3503.5, -2866.5, -2229.5, -1592.5, -955.5, -318.5, 318.5, 955.5,
  119929. 1592.5, 2229.5, 2866.5, 3503.5,
  119930. };
  119931. static long _vq_quantmap__44c7_s_p9_0[] = {
  119932. 11, 9, 7, 5, 3, 1, 0, 2,
  119933. 4, 6, 8, 10, 12,
  119934. };
  119935. static encode_aux_threshmatch _vq_auxt__44c7_s_p9_0 = {
  119936. _vq_quantthresh__44c7_s_p9_0,
  119937. _vq_quantmap__44c7_s_p9_0,
  119938. 13,
  119939. 13
  119940. };
  119941. static static_codebook _44c7_s_p9_0 = {
  119942. 2, 169,
  119943. _vq_lengthlist__44c7_s_p9_0,
  119944. 1, -511845376, 1630791680, 4, 0,
  119945. _vq_quantlist__44c7_s_p9_0,
  119946. NULL,
  119947. &_vq_auxt__44c7_s_p9_0,
  119948. NULL,
  119949. 0
  119950. };
  119951. static long _vq_quantlist__44c7_s_p9_1[] = {
  119952. 6,
  119953. 5,
  119954. 7,
  119955. 4,
  119956. 8,
  119957. 3,
  119958. 9,
  119959. 2,
  119960. 10,
  119961. 1,
  119962. 11,
  119963. 0,
  119964. 12,
  119965. };
  119966. static long _vq_lengthlist__44c7_s_p9_1[] = {
  119967. 1, 4, 4, 7, 7, 7, 7, 7, 6, 8, 8, 8, 8, 6, 6, 6,
  119968. 8, 8, 9, 8, 8, 7, 9, 8,11,10, 5, 6, 6, 8, 8, 9,
  119969. 8, 8, 8,10, 9,11,11,16, 8, 8, 9, 8, 9, 9, 9, 8,
  119970. 10, 9,11,10,16, 8, 8, 9, 9,10,10, 9, 9,10,10,11,
  119971. 11,16,13,13, 9, 9,10,10, 9,10,11,11,12,11,16,13,
  119972. 13, 9, 8,10, 9,10,10,10,10,11,11,16,14,16, 8, 9,
  119973. 9, 9,11,10,11,11,12,11,16,16,16, 9, 7,10, 7,11,
  119974. 10,11,11,12,11,16,16,16,12,12, 9,10,11,11,12,11,
  119975. 12,12,16,16,16,12,10,10, 7,11, 8,12,11,12,12,16,
  119976. 16,15,16,16,11,12,10,10,12,11,12,12,16,16,16,15,
  119977. 15,11,11,10,10,12,12,12,12,
  119978. };
  119979. static float _vq_quantthresh__44c7_s_p9_1[] = {
  119980. -269.5, -220.5, -171.5, -122.5, -73.5, -24.5, 24.5, 73.5,
  119981. 122.5, 171.5, 220.5, 269.5,
  119982. };
  119983. static long _vq_quantmap__44c7_s_p9_1[] = {
  119984. 11, 9, 7, 5, 3, 1, 0, 2,
  119985. 4, 6, 8, 10, 12,
  119986. };
  119987. static encode_aux_threshmatch _vq_auxt__44c7_s_p9_1 = {
  119988. _vq_quantthresh__44c7_s_p9_1,
  119989. _vq_quantmap__44c7_s_p9_1,
  119990. 13,
  119991. 13
  119992. };
  119993. static static_codebook _44c7_s_p9_1 = {
  119994. 2, 169,
  119995. _vq_lengthlist__44c7_s_p9_1,
  119996. 1, -518889472, 1622704128, 4, 0,
  119997. _vq_quantlist__44c7_s_p9_1,
  119998. NULL,
  119999. &_vq_auxt__44c7_s_p9_1,
  120000. NULL,
  120001. 0
  120002. };
  120003. static long _vq_quantlist__44c7_s_p9_2[] = {
  120004. 24,
  120005. 23,
  120006. 25,
  120007. 22,
  120008. 26,
  120009. 21,
  120010. 27,
  120011. 20,
  120012. 28,
  120013. 19,
  120014. 29,
  120015. 18,
  120016. 30,
  120017. 17,
  120018. 31,
  120019. 16,
  120020. 32,
  120021. 15,
  120022. 33,
  120023. 14,
  120024. 34,
  120025. 13,
  120026. 35,
  120027. 12,
  120028. 36,
  120029. 11,
  120030. 37,
  120031. 10,
  120032. 38,
  120033. 9,
  120034. 39,
  120035. 8,
  120036. 40,
  120037. 7,
  120038. 41,
  120039. 6,
  120040. 42,
  120041. 5,
  120042. 43,
  120043. 4,
  120044. 44,
  120045. 3,
  120046. 45,
  120047. 2,
  120048. 46,
  120049. 1,
  120050. 47,
  120051. 0,
  120052. 48,
  120053. };
  120054. static long _vq_lengthlist__44c7_s_p9_2[] = {
  120055. 2, 4, 3, 4, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  120056. 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  120057. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  120058. 7,
  120059. };
  120060. static float _vq_quantthresh__44c7_s_p9_2[] = {
  120061. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  120062. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  120063. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  120064. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  120065. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  120066. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  120067. };
  120068. static long _vq_quantmap__44c7_s_p9_2[] = {
  120069. 47, 45, 43, 41, 39, 37, 35, 33,
  120070. 31, 29, 27, 25, 23, 21, 19, 17,
  120071. 15, 13, 11, 9, 7, 5, 3, 1,
  120072. 0, 2, 4, 6, 8, 10, 12, 14,
  120073. 16, 18, 20, 22, 24, 26, 28, 30,
  120074. 32, 34, 36, 38, 40, 42, 44, 46,
  120075. 48,
  120076. };
  120077. static encode_aux_threshmatch _vq_auxt__44c7_s_p9_2 = {
  120078. _vq_quantthresh__44c7_s_p9_2,
  120079. _vq_quantmap__44c7_s_p9_2,
  120080. 49,
  120081. 49
  120082. };
  120083. static static_codebook _44c7_s_p9_2 = {
  120084. 1, 49,
  120085. _vq_lengthlist__44c7_s_p9_2,
  120086. 1, -526909440, 1611661312, 6, 0,
  120087. _vq_quantlist__44c7_s_p9_2,
  120088. NULL,
  120089. &_vq_auxt__44c7_s_p9_2,
  120090. NULL,
  120091. 0
  120092. };
  120093. static long _huff_lengthlist__44c7_s_short[] = {
  120094. 4,11,12,14,15,15,17,17,18,18, 5, 6, 6, 8, 9,10,
  120095. 13,17,18,19, 7, 5, 4, 6, 8, 9,11,15,19,19, 8, 6,
  120096. 5, 5, 6, 7,11,14,16,17, 9, 7, 7, 6, 7, 7,10,13,
  120097. 15,19,10, 8, 7, 6, 7, 6, 7, 9,14,16,12,10, 9, 7,
  120098. 7, 6, 4, 5,10,15,14,13,11, 7, 6, 6, 4, 2, 7,13,
  120099. 16,16,15, 9, 8, 8, 8, 6, 9,13,19,19,17,12,11,10,
  120100. 10, 9,11,14,
  120101. };
  120102. static static_codebook _huff_book__44c7_s_short = {
  120103. 2, 100,
  120104. _huff_lengthlist__44c7_s_short,
  120105. 0, 0, 0, 0, 0,
  120106. NULL,
  120107. NULL,
  120108. NULL,
  120109. NULL,
  120110. 0
  120111. };
  120112. static long _huff_lengthlist__44c8_s_long[] = {
  120113. 3, 8,12,13,14,14,14,13,14,14, 6, 4, 5, 8,10,10,
  120114. 11,11,14,13, 9, 5, 4, 5, 7, 8, 9,10,13,13,12, 7,
  120115. 5, 4, 5, 6, 8, 9,12,13,13, 9, 6, 5, 5, 5, 7, 9,
  120116. 11,14,12,10, 7, 6, 5, 4, 6, 7,10,11,12,11, 9, 8,
  120117. 7, 5, 5, 6,10,10,13,12,10, 9, 8, 6, 6, 5, 8,10,
  120118. 14,13,12,12,11,10, 9, 7, 8,10,12,13,14,14,13,12,
  120119. 11, 9, 9,10,
  120120. };
  120121. static static_codebook _huff_book__44c8_s_long = {
  120122. 2, 100,
  120123. _huff_lengthlist__44c8_s_long,
  120124. 0, 0, 0, 0, 0,
  120125. NULL,
  120126. NULL,
  120127. NULL,
  120128. NULL,
  120129. 0
  120130. };
  120131. static long _vq_quantlist__44c8_s_p1_0[] = {
  120132. 1,
  120133. 0,
  120134. 2,
  120135. };
  120136. static long _vq_lengthlist__44c8_s_p1_0[] = {
  120137. 1, 5, 5, 0, 5, 5, 0, 5, 5, 5, 7, 7, 0, 9, 8, 0,
  120138. 9, 8, 6, 7, 7, 0, 8, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  120139. 0, 0, 0, 0, 5, 9, 8, 0, 8, 8, 0, 8, 8, 5, 8, 9,
  120140. 0, 8, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  120141. 9, 8, 0, 8, 8, 0, 8, 8, 5, 8, 9, 0, 8, 8, 0, 8,
  120142. 8,
  120143. };
  120144. static float _vq_quantthresh__44c8_s_p1_0[] = {
  120145. -0.5, 0.5,
  120146. };
  120147. static long _vq_quantmap__44c8_s_p1_0[] = {
  120148. 1, 0, 2,
  120149. };
  120150. static encode_aux_threshmatch _vq_auxt__44c8_s_p1_0 = {
  120151. _vq_quantthresh__44c8_s_p1_0,
  120152. _vq_quantmap__44c8_s_p1_0,
  120153. 3,
  120154. 3
  120155. };
  120156. static static_codebook _44c8_s_p1_0 = {
  120157. 4, 81,
  120158. _vq_lengthlist__44c8_s_p1_0,
  120159. 1, -535822336, 1611661312, 2, 0,
  120160. _vq_quantlist__44c8_s_p1_0,
  120161. NULL,
  120162. &_vq_auxt__44c8_s_p1_0,
  120163. NULL,
  120164. 0
  120165. };
  120166. static long _vq_quantlist__44c8_s_p2_0[] = {
  120167. 2,
  120168. 1,
  120169. 3,
  120170. 0,
  120171. 4,
  120172. };
  120173. static long _vq_lengthlist__44c8_s_p2_0[] = {
  120174. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  120175. 7, 7, 9, 9, 0, 0, 0, 9, 9, 5, 7, 7, 9, 9, 0, 8,
  120176. 7,10, 9, 0, 8, 7,10, 9, 0,10,10,11,11, 0, 0, 0,
  120177. 11,11, 5, 7, 7, 9, 9, 0, 7, 8, 9,10, 0, 7, 8, 9,
  120178. 10, 0,10,10,11,11, 0, 0, 0,11,11, 8, 9, 9,11,10,
  120179. 0,11,10,12,11, 0,11,10,12,12, 0,13,13,14,14, 0,
  120180. 0, 0,14,13, 8, 9, 9,10,11, 0,10,11,12,12, 0,10,
  120181. 11,12,12, 0,13,13,14,14, 0, 0, 0,13,14, 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, 5, 8, 7,11,10, 0, 7, 7,10,10,
  120184. 0, 7, 7,10,10, 0, 9, 9,10,10, 0, 0, 0,11,10, 5,
  120185. 7, 8,10,11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9,
  120186. 9,10,10, 0, 0, 0,10,10, 8,10, 9,12,12, 0,10,10,
  120187. 12,11, 0,10,10,12,12, 0,12,12,13,12, 0, 0, 0,13,
  120188. 12, 8, 9,10,12,12, 0,10,10,11,12, 0,10,10,11,12,
  120189. 0,12,12,13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0,
  120190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120191. 0, 0, 0, 6, 8, 7,11,10, 0, 7, 7,10,10, 0, 7, 7,
  120192. 10,10, 0, 9, 9,10,11, 0, 0, 0,10,10, 6, 7, 8,10,
  120193. 11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9, 9,10,10,
  120194. 0, 0, 0,10,10, 9,10, 9,12,12, 0,10,10,12,12, 0,
  120195. 10,10,12,11, 0,12,12,13,13, 0, 0, 0,13,12, 8, 9,
  120196. 10,12,12, 0,10,10,12,12, 0,10,10,11,12, 0,12,12,
  120197. 13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120199. 7,10,10,13,13, 0, 9, 9,12,12, 0, 9, 9,12,12, 0,
  120200. 10,10,12,12, 0, 0, 0,12,12, 7,10,10,13,13, 0, 9,
  120201. 9,12,12, 0, 9, 9,12,12, 0,10,10,12,12, 0, 0, 0,
  120202. 12,12, 9,11,11,14,13, 0,10,10,13,12, 0,11,10,13,
  120203. 12, 0,12,12,13,12, 0, 0, 0,13,13, 9,11,11,13,14,
  120204. 0,10,11,12,13, 0,10,11,13,13, 0,12,12,12,13, 0,
  120205. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  120210. 11,11,14,14, 0,10,11,13,13, 0,11,10,13,13, 0,11,
  120211. 12,13,13, 0, 0, 0,13,12, 9,11,11,14,14, 0,11,10,
  120212. 13,13, 0,10,11,13,13, 0,12,12,13,13, 0, 0, 0,12,
  120213. 13,
  120214. };
  120215. static float _vq_quantthresh__44c8_s_p2_0[] = {
  120216. -1.5, -0.5, 0.5, 1.5,
  120217. };
  120218. static long _vq_quantmap__44c8_s_p2_0[] = {
  120219. 3, 1, 0, 2, 4,
  120220. };
  120221. static encode_aux_threshmatch _vq_auxt__44c8_s_p2_0 = {
  120222. _vq_quantthresh__44c8_s_p2_0,
  120223. _vq_quantmap__44c8_s_p2_0,
  120224. 5,
  120225. 5
  120226. };
  120227. static static_codebook _44c8_s_p2_0 = {
  120228. 4, 625,
  120229. _vq_lengthlist__44c8_s_p2_0,
  120230. 1, -533725184, 1611661312, 3, 0,
  120231. _vq_quantlist__44c8_s_p2_0,
  120232. NULL,
  120233. &_vq_auxt__44c8_s_p2_0,
  120234. NULL,
  120235. 0
  120236. };
  120237. static long _vq_quantlist__44c8_s_p3_0[] = {
  120238. 4,
  120239. 3,
  120240. 5,
  120241. 2,
  120242. 6,
  120243. 1,
  120244. 7,
  120245. 0,
  120246. 8,
  120247. };
  120248. static long _vq_lengthlist__44c8_s_p3_0[] = {
  120249. 2, 4, 4, 5, 5, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  120250. 9, 9, 0, 4, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 6, 6,
  120251. 8, 8,10,10, 0, 0, 0, 6, 6, 8, 8,10,10, 0, 0, 0,
  120252. 7, 7, 9, 9,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0,
  120253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120254. 0,
  120255. };
  120256. static float _vq_quantthresh__44c8_s_p3_0[] = {
  120257. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  120258. };
  120259. static long _vq_quantmap__44c8_s_p3_0[] = {
  120260. 7, 5, 3, 1, 0, 2, 4, 6,
  120261. 8,
  120262. };
  120263. static encode_aux_threshmatch _vq_auxt__44c8_s_p3_0 = {
  120264. _vq_quantthresh__44c8_s_p3_0,
  120265. _vq_quantmap__44c8_s_p3_0,
  120266. 9,
  120267. 9
  120268. };
  120269. static static_codebook _44c8_s_p3_0 = {
  120270. 2, 81,
  120271. _vq_lengthlist__44c8_s_p3_0,
  120272. 1, -531628032, 1611661312, 4, 0,
  120273. _vq_quantlist__44c8_s_p3_0,
  120274. NULL,
  120275. &_vq_auxt__44c8_s_p3_0,
  120276. NULL,
  120277. 0
  120278. };
  120279. static long _vq_quantlist__44c8_s_p4_0[] = {
  120280. 8,
  120281. 7,
  120282. 9,
  120283. 6,
  120284. 10,
  120285. 5,
  120286. 11,
  120287. 4,
  120288. 12,
  120289. 3,
  120290. 13,
  120291. 2,
  120292. 14,
  120293. 1,
  120294. 15,
  120295. 0,
  120296. 16,
  120297. };
  120298. static long _vq_lengthlist__44c8_s_p4_0[] = {
  120299. 3, 4, 4, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  120300. 11, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 8,10,10,11,11,
  120301. 11,11, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  120302. 11,11,11, 0, 6, 5, 6, 6, 7, 7, 9, 9, 9, 9,10,10,
  120303. 11,11,12,12, 0, 0, 0, 6, 6, 7, 7, 9, 9, 9, 9,10,
  120304. 10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,10,
  120305. 11,11,11,12,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,
  120306. 10,11,11,11,12,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  120307. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 8, 8, 9,
  120308. 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 0, 0,
  120309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120317. 0,
  120318. };
  120319. static float _vq_quantthresh__44c8_s_p4_0[] = {
  120320. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  120321. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  120322. };
  120323. static long _vq_quantmap__44c8_s_p4_0[] = {
  120324. 15, 13, 11, 9, 7, 5, 3, 1,
  120325. 0, 2, 4, 6, 8, 10, 12, 14,
  120326. 16,
  120327. };
  120328. static encode_aux_threshmatch _vq_auxt__44c8_s_p4_0 = {
  120329. _vq_quantthresh__44c8_s_p4_0,
  120330. _vq_quantmap__44c8_s_p4_0,
  120331. 17,
  120332. 17
  120333. };
  120334. static static_codebook _44c8_s_p4_0 = {
  120335. 2, 289,
  120336. _vq_lengthlist__44c8_s_p4_0,
  120337. 1, -529530880, 1611661312, 5, 0,
  120338. _vq_quantlist__44c8_s_p4_0,
  120339. NULL,
  120340. &_vq_auxt__44c8_s_p4_0,
  120341. NULL,
  120342. 0
  120343. };
  120344. static long _vq_quantlist__44c8_s_p5_0[] = {
  120345. 1,
  120346. 0,
  120347. 2,
  120348. };
  120349. static long _vq_lengthlist__44c8_s_p5_0[] = {
  120350. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 7, 6,10,10,10,10,
  120351. 10,10, 4, 6, 6,10,10,10,10, 9,10, 5,10,10, 9,11,
  120352. 11,10,11,11, 7,10,10,11,12,12,12,12,12, 7,10,10,
  120353. 11,12,12,12,12,12, 6,10,10,10,12,12,10,12,12, 7,
  120354. 10,10,11,12,12,12,12,12, 7,10,10,11,12,12,12,12,
  120355. 12,
  120356. };
  120357. static float _vq_quantthresh__44c8_s_p5_0[] = {
  120358. -5.5, 5.5,
  120359. };
  120360. static long _vq_quantmap__44c8_s_p5_0[] = {
  120361. 1, 0, 2,
  120362. };
  120363. static encode_aux_threshmatch _vq_auxt__44c8_s_p5_0 = {
  120364. _vq_quantthresh__44c8_s_p5_0,
  120365. _vq_quantmap__44c8_s_p5_0,
  120366. 3,
  120367. 3
  120368. };
  120369. static static_codebook _44c8_s_p5_0 = {
  120370. 4, 81,
  120371. _vq_lengthlist__44c8_s_p5_0,
  120372. 1, -529137664, 1618345984, 2, 0,
  120373. _vq_quantlist__44c8_s_p5_0,
  120374. NULL,
  120375. &_vq_auxt__44c8_s_p5_0,
  120376. NULL,
  120377. 0
  120378. };
  120379. static long _vq_quantlist__44c8_s_p5_1[] = {
  120380. 5,
  120381. 4,
  120382. 6,
  120383. 3,
  120384. 7,
  120385. 2,
  120386. 8,
  120387. 1,
  120388. 9,
  120389. 0,
  120390. 10,
  120391. };
  120392. static long _vq_lengthlist__44c8_s_p5_1[] = {
  120393. 3, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8,11, 4, 5, 6, 6,
  120394. 7, 7, 8, 8, 8, 8,11, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  120395. 9,12, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,12,12,12, 6,
  120396. 6, 7, 7, 8, 8, 9, 9,11,11,11, 6, 6, 7, 7, 8, 8,
  120397. 8, 8,11,11,11, 6, 6, 7, 7, 8, 8, 8, 8,11,11,11,
  120398. 7, 7, 7, 8, 8, 8, 8, 8,11,11,11,11,11, 7, 7, 8,
  120399. 8, 8, 8,11,11,11,11,11, 7, 7, 7, 7, 8, 8,11,11,
  120400. 11,11,11, 7, 7, 7, 7, 8, 8,
  120401. };
  120402. static float _vq_quantthresh__44c8_s_p5_1[] = {
  120403. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  120404. 3.5, 4.5,
  120405. };
  120406. static long _vq_quantmap__44c8_s_p5_1[] = {
  120407. 9, 7, 5, 3, 1, 0, 2, 4,
  120408. 6, 8, 10,
  120409. };
  120410. static encode_aux_threshmatch _vq_auxt__44c8_s_p5_1 = {
  120411. _vq_quantthresh__44c8_s_p5_1,
  120412. _vq_quantmap__44c8_s_p5_1,
  120413. 11,
  120414. 11
  120415. };
  120416. static static_codebook _44c8_s_p5_1 = {
  120417. 2, 121,
  120418. _vq_lengthlist__44c8_s_p5_1,
  120419. 1, -531365888, 1611661312, 4, 0,
  120420. _vq_quantlist__44c8_s_p5_1,
  120421. NULL,
  120422. &_vq_auxt__44c8_s_p5_1,
  120423. NULL,
  120424. 0
  120425. };
  120426. static long _vq_quantlist__44c8_s_p6_0[] = {
  120427. 6,
  120428. 5,
  120429. 7,
  120430. 4,
  120431. 8,
  120432. 3,
  120433. 9,
  120434. 2,
  120435. 10,
  120436. 1,
  120437. 11,
  120438. 0,
  120439. 12,
  120440. };
  120441. static long _vq_lengthlist__44c8_s_p6_0[] = {
  120442. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  120443. 7, 7, 8, 8, 9, 9,10,10,11,11, 6, 5, 5, 7, 7, 8,
  120444. 8, 9, 9,10,10,11,11, 0, 7, 7, 7, 7, 9, 9,10,10,
  120445. 10,10,11,11, 0, 7, 7, 7, 7, 9, 9,10,10,10,10,11,
  120446. 11, 0,11,11, 9, 9,10,10,11,11,11,11,12,12, 0,12,
  120447. 12, 9, 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0,
  120448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120452. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120453. };
  120454. static float _vq_quantthresh__44c8_s_p6_0[] = {
  120455. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  120456. 12.5, 17.5, 22.5, 27.5,
  120457. };
  120458. static long _vq_quantmap__44c8_s_p6_0[] = {
  120459. 11, 9, 7, 5, 3, 1, 0, 2,
  120460. 4, 6, 8, 10, 12,
  120461. };
  120462. static encode_aux_threshmatch _vq_auxt__44c8_s_p6_0 = {
  120463. _vq_quantthresh__44c8_s_p6_0,
  120464. _vq_quantmap__44c8_s_p6_0,
  120465. 13,
  120466. 13
  120467. };
  120468. static static_codebook _44c8_s_p6_0 = {
  120469. 2, 169,
  120470. _vq_lengthlist__44c8_s_p6_0,
  120471. 1, -526516224, 1616117760, 4, 0,
  120472. _vq_quantlist__44c8_s_p6_0,
  120473. NULL,
  120474. &_vq_auxt__44c8_s_p6_0,
  120475. NULL,
  120476. 0
  120477. };
  120478. static long _vq_quantlist__44c8_s_p6_1[] = {
  120479. 2,
  120480. 1,
  120481. 3,
  120482. 0,
  120483. 4,
  120484. };
  120485. static long _vq_lengthlist__44c8_s_p6_1[] = {
  120486. 3, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 6,
  120487. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  120488. };
  120489. static float _vq_quantthresh__44c8_s_p6_1[] = {
  120490. -1.5, -0.5, 0.5, 1.5,
  120491. };
  120492. static long _vq_quantmap__44c8_s_p6_1[] = {
  120493. 3, 1, 0, 2, 4,
  120494. };
  120495. static encode_aux_threshmatch _vq_auxt__44c8_s_p6_1 = {
  120496. _vq_quantthresh__44c8_s_p6_1,
  120497. _vq_quantmap__44c8_s_p6_1,
  120498. 5,
  120499. 5
  120500. };
  120501. static static_codebook _44c8_s_p6_1 = {
  120502. 2, 25,
  120503. _vq_lengthlist__44c8_s_p6_1,
  120504. 1, -533725184, 1611661312, 3, 0,
  120505. _vq_quantlist__44c8_s_p6_1,
  120506. NULL,
  120507. &_vq_auxt__44c8_s_p6_1,
  120508. NULL,
  120509. 0
  120510. };
  120511. static long _vq_quantlist__44c8_s_p7_0[] = {
  120512. 6,
  120513. 5,
  120514. 7,
  120515. 4,
  120516. 8,
  120517. 3,
  120518. 9,
  120519. 2,
  120520. 10,
  120521. 1,
  120522. 11,
  120523. 0,
  120524. 12,
  120525. };
  120526. static long _vq_lengthlist__44c8_s_p7_0[] = {
  120527. 1, 4, 4, 6, 6, 8, 7, 9, 9,10,10,12,12, 6, 5, 5,
  120528. 7, 7, 8, 8,10,10,11,11,12,12, 7, 5, 5, 7, 7, 8,
  120529. 8,10,10,11,11,12,12,21, 7, 7, 7, 7, 8, 9,10,10,
  120530. 11,11,12,12,21, 7, 7, 7, 7, 9, 9,10,10,12,12,13,
  120531. 13,21,11,11, 8, 8, 9, 9,11,11,12,12,13,13,21,11,
  120532. 11, 8, 8, 9, 9,11,11,12,12,13,13,21,21,21,10,10,
  120533. 10,10,11,11,12,13,13,13,21,21,21,10,10,10,10,11,
  120534. 11,13,13,14,13,21,21,21,13,13,11,11,12,12,13,13,
  120535. 14,14,21,21,21,14,14,11,11,12,12,13,13,14,14,21,
  120536. 21,21,21,20,13,13,13,12,14,14,16,15,20,20,20,20,
  120537. 20,13,13,13,13,14,13,15,15,
  120538. };
  120539. static float _vq_quantthresh__44c8_s_p7_0[] = {
  120540. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  120541. 27.5, 38.5, 49.5, 60.5,
  120542. };
  120543. static long _vq_quantmap__44c8_s_p7_0[] = {
  120544. 11, 9, 7, 5, 3, 1, 0, 2,
  120545. 4, 6, 8, 10, 12,
  120546. };
  120547. static encode_aux_threshmatch _vq_auxt__44c8_s_p7_0 = {
  120548. _vq_quantthresh__44c8_s_p7_0,
  120549. _vq_quantmap__44c8_s_p7_0,
  120550. 13,
  120551. 13
  120552. };
  120553. static static_codebook _44c8_s_p7_0 = {
  120554. 2, 169,
  120555. _vq_lengthlist__44c8_s_p7_0,
  120556. 1, -523206656, 1618345984, 4, 0,
  120557. _vq_quantlist__44c8_s_p7_0,
  120558. NULL,
  120559. &_vq_auxt__44c8_s_p7_0,
  120560. NULL,
  120561. 0
  120562. };
  120563. static long _vq_quantlist__44c8_s_p7_1[] = {
  120564. 5,
  120565. 4,
  120566. 6,
  120567. 3,
  120568. 7,
  120569. 2,
  120570. 8,
  120571. 1,
  120572. 9,
  120573. 0,
  120574. 10,
  120575. };
  120576. static long _vq_lengthlist__44c8_s_p7_1[] = {
  120577. 4, 5, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 6, 6, 6, 7,
  120578. 7, 7, 7, 7, 7, 7, 8, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  120579. 7, 8, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7,
  120580. 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  120581. 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  120582. 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  120583. 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 8, 8,
  120584. 8, 8, 8, 7, 7, 7, 7, 7, 7,
  120585. };
  120586. static float _vq_quantthresh__44c8_s_p7_1[] = {
  120587. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  120588. 3.5, 4.5,
  120589. };
  120590. static long _vq_quantmap__44c8_s_p7_1[] = {
  120591. 9, 7, 5, 3, 1, 0, 2, 4,
  120592. 6, 8, 10,
  120593. };
  120594. static encode_aux_threshmatch _vq_auxt__44c8_s_p7_1 = {
  120595. _vq_quantthresh__44c8_s_p7_1,
  120596. _vq_quantmap__44c8_s_p7_1,
  120597. 11,
  120598. 11
  120599. };
  120600. static static_codebook _44c8_s_p7_1 = {
  120601. 2, 121,
  120602. _vq_lengthlist__44c8_s_p7_1,
  120603. 1, -531365888, 1611661312, 4, 0,
  120604. _vq_quantlist__44c8_s_p7_1,
  120605. NULL,
  120606. &_vq_auxt__44c8_s_p7_1,
  120607. NULL,
  120608. 0
  120609. };
  120610. static long _vq_quantlist__44c8_s_p8_0[] = {
  120611. 7,
  120612. 6,
  120613. 8,
  120614. 5,
  120615. 9,
  120616. 4,
  120617. 10,
  120618. 3,
  120619. 11,
  120620. 2,
  120621. 12,
  120622. 1,
  120623. 13,
  120624. 0,
  120625. 14,
  120626. };
  120627. static long _vq_lengthlist__44c8_s_p8_0[] = {
  120628. 1, 4, 4, 7, 6, 8, 8, 8, 7, 9, 8,10,10,11,10, 6,
  120629. 5, 5, 7, 7, 9, 9, 8, 8,10,10,11,11,12,11, 6, 5,
  120630. 5, 7, 7, 9, 9, 9, 9,10,10,11,11,12,12,20, 8, 8,
  120631. 8, 8, 9, 9, 9, 9,10,10,11,11,12,12,20, 8, 8, 8,
  120632. 8,10, 9, 9, 9,10,10,11,11,12,12,20,12,12, 9, 9,
  120633. 10,10,10,10,10,11,12,12,12,12,20,12,12, 9, 9,10,
  120634. 10,10,10,11,11,12,12,13,13,20,20,20, 9, 9, 9, 9,
  120635. 11,10,11,11,12,12,12,13,20,19,19, 9, 9, 9, 9,11,
  120636. 11,11,12,12,12,13,13,19,19,19,13,13,10,10,11,11,
  120637. 12,12,13,13,13,13,19,19,19,14,13,11,10,11,11,12,
  120638. 12,12,13,13,13,19,19,19,19,19,12,12,12,12,13,13,
  120639. 13,13,14,13,19,19,19,19,19,12,12,12,11,12,12,13,
  120640. 14,14,14,19,19,19,19,19,16,15,13,12,13,13,13,14,
  120641. 14,14,19,19,19,19,19,17,17,13,12,13,11,14,13,15,
  120642. 15,
  120643. };
  120644. static float _vq_quantthresh__44c8_s_p8_0[] = {
  120645. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  120646. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  120647. };
  120648. static long _vq_quantmap__44c8_s_p8_0[] = {
  120649. 13, 11, 9, 7, 5, 3, 1, 0,
  120650. 2, 4, 6, 8, 10, 12, 14,
  120651. };
  120652. static encode_aux_threshmatch _vq_auxt__44c8_s_p8_0 = {
  120653. _vq_quantthresh__44c8_s_p8_0,
  120654. _vq_quantmap__44c8_s_p8_0,
  120655. 15,
  120656. 15
  120657. };
  120658. static static_codebook _44c8_s_p8_0 = {
  120659. 2, 225,
  120660. _vq_lengthlist__44c8_s_p8_0,
  120661. 1, -520986624, 1620377600, 4, 0,
  120662. _vq_quantlist__44c8_s_p8_0,
  120663. NULL,
  120664. &_vq_auxt__44c8_s_p8_0,
  120665. NULL,
  120666. 0
  120667. };
  120668. static long _vq_quantlist__44c8_s_p8_1[] = {
  120669. 10,
  120670. 9,
  120671. 11,
  120672. 8,
  120673. 12,
  120674. 7,
  120675. 13,
  120676. 6,
  120677. 14,
  120678. 5,
  120679. 15,
  120680. 4,
  120681. 16,
  120682. 3,
  120683. 17,
  120684. 2,
  120685. 18,
  120686. 1,
  120687. 19,
  120688. 0,
  120689. 20,
  120690. };
  120691. static long _vq_lengthlist__44c8_s_p8_1[] = {
  120692. 4, 5, 5, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  120693. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  120694. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  120695. 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,
  120696. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120697. 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  120698. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 9,
  120699. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  120700. 10, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120701. 9, 9, 9,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120702. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9,
  120703. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  120704. 10,10, 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9, 9, 9,
  120705. 9, 9,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120706. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9, 9,
  120707. 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,10,10,10,10,
  120708. 10,10,10, 9, 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,
  120709. 9,10,10,10,10,10,10,10, 9,10,10, 9,10,10,10,10,
  120710. 9,10, 9,10,10, 9,10,10,10,10,10,10,10, 9,10,10,
  120711. 10,10,10,10, 9, 9,10,10, 9,10,10,10,10,10,10,10,
  120712. 10,10,10,10,10,10,10,10, 9, 9, 9,10, 9, 9, 9, 9,
  120713. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9,
  120714. 10, 9,10, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  120715. 10,10,10,10, 9, 9,10, 9, 9, 9,10,10,10,10,10,10,
  120716. 10,10,10,10,10, 9, 9, 9, 9, 9, 9,10, 9, 9,10,10,
  120717. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9,10, 9,
  120718. 9,10, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  120719. 10, 9, 9,10,10, 9,10, 9, 9,
  120720. };
  120721. static float _vq_quantthresh__44c8_s_p8_1[] = {
  120722. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  120723. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  120724. 6.5, 7.5, 8.5, 9.5,
  120725. };
  120726. static long _vq_quantmap__44c8_s_p8_1[] = {
  120727. 19, 17, 15, 13, 11, 9, 7, 5,
  120728. 3, 1, 0, 2, 4, 6, 8, 10,
  120729. 12, 14, 16, 18, 20,
  120730. };
  120731. static encode_aux_threshmatch _vq_auxt__44c8_s_p8_1 = {
  120732. _vq_quantthresh__44c8_s_p8_1,
  120733. _vq_quantmap__44c8_s_p8_1,
  120734. 21,
  120735. 21
  120736. };
  120737. static static_codebook _44c8_s_p8_1 = {
  120738. 2, 441,
  120739. _vq_lengthlist__44c8_s_p8_1,
  120740. 1, -529268736, 1611661312, 5, 0,
  120741. _vq_quantlist__44c8_s_p8_1,
  120742. NULL,
  120743. &_vq_auxt__44c8_s_p8_1,
  120744. NULL,
  120745. 0
  120746. };
  120747. static long _vq_quantlist__44c8_s_p9_0[] = {
  120748. 8,
  120749. 7,
  120750. 9,
  120751. 6,
  120752. 10,
  120753. 5,
  120754. 11,
  120755. 4,
  120756. 12,
  120757. 3,
  120758. 13,
  120759. 2,
  120760. 14,
  120761. 1,
  120762. 15,
  120763. 0,
  120764. 16,
  120765. };
  120766. static long _vq_lengthlist__44c8_s_p9_0[] = {
  120767. 1, 4, 3,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120768. 11, 4, 7, 7,11,11,11,11,11,11,11,11,11,11,11,11,
  120769. 11,11, 4, 8,11,11,11,11,11,11,11,11,11,11,11,11,
  120770. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120771. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120772. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120773. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120774. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120775. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120776. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120777. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120778. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120779. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120780. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120781. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120782. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120783. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120784. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120785. 10,
  120786. };
  120787. static float _vq_quantthresh__44c8_s_p9_0[] = {
  120788. -6982.5, -6051.5, -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -465.5,
  120789. 465.5, 1396.5, 2327.5, 3258.5, 4189.5, 5120.5, 6051.5, 6982.5,
  120790. };
  120791. static long _vq_quantmap__44c8_s_p9_0[] = {
  120792. 15, 13, 11, 9, 7, 5, 3, 1,
  120793. 0, 2, 4, 6, 8, 10, 12, 14,
  120794. 16,
  120795. };
  120796. static encode_aux_threshmatch _vq_auxt__44c8_s_p9_0 = {
  120797. _vq_quantthresh__44c8_s_p9_0,
  120798. _vq_quantmap__44c8_s_p9_0,
  120799. 17,
  120800. 17
  120801. };
  120802. static static_codebook _44c8_s_p9_0 = {
  120803. 2, 289,
  120804. _vq_lengthlist__44c8_s_p9_0,
  120805. 1, -509798400, 1631393792, 5, 0,
  120806. _vq_quantlist__44c8_s_p9_0,
  120807. NULL,
  120808. &_vq_auxt__44c8_s_p9_0,
  120809. NULL,
  120810. 0
  120811. };
  120812. static long _vq_quantlist__44c8_s_p9_1[] = {
  120813. 9,
  120814. 8,
  120815. 10,
  120816. 7,
  120817. 11,
  120818. 6,
  120819. 12,
  120820. 5,
  120821. 13,
  120822. 4,
  120823. 14,
  120824. 3,
  120825. 15,
  120826. 2,
  120827. 16,
  120828. 1,
  120829. 17,
  120830. 0,
  120831. 18,
  120832. };
  120833. static long _vq_lengthlist__44c8_s_p9_1[] = {
  120834. 1, 4, 4, 7, 6, 7, 7, 7, 7, 8, 8, 9, 9,10,10,10,
  120835. 10,11,11, 6, 6, 6, 8, 8, 9, 8, 8, 7,10, 8,11,10,
  120836. 12,11,12,12,13,13, 5, 5, 6, 8, 8, 9, 9, 8, 8,10,
  120837. 9,11,11,12,12,13,13,13,13,17, 8, 8, 9, 9, 9, 9,
  120838. 9, 9,10, 9,12,10,12,12,13,12,13,13,17, 9, 8, 9,
  120839. 9, 9, 9, 9, 9,10,10,12,12,12,12,13,13,13,13,17,
  120840. 13,13, 9, 9,10,10,10,10,11,11,12,11,13,12,13,13,
  120841. 14,15,17,13,13, 9, 8,10, 9,10,10,11,11,12,12,14,
  120842. 13,15,13,14,15,17,17,17, 9,10, 9,10,11,11,12,12,
  120843. 12,12,13,13,14,14,15,15,17,17,17, 9, 8, 9, 8,11,
  120844. 11,12,12,12,12,14,13,14,14,14,15,17,17,17,12,14,
  120845. 9,10,11,11,12,12,14,13,13,14,15,13,15,15,17,17,
  120846. 17,13,11,10, 8,11, 9,13,12,13,13,13,13,13,14,14,
  120847. 14,17,17,17,17,17,11,12,11,11,13,13,14,13,15,14,
  120848. 13,15,16,15,17,17,17,17,17,11,11,12, 8,13,12,14,
  120849. 13,17,14,15,14,15,14,17,17,17,17,17,15,15,12,12,
  120850. 12,12,13,14,14,14,15,14,17,14,17,17,17,17,17,16,
  120851. 17,12,12,13,12,13,13,14,14,14,14,14,14,17,17,17,
  120852. 17,17,17,17,14,14,13,12,13,13,15,15,14,13,15,17,
  120853. 17,17,17,17,17,17,17,13,14,13,13,13,13,14,15,15,
  120854. 15,14,15,17,17,17,17,17,17,17,16,15,13,14,13,13,
  120855. 14,14,15,14,14,16,17,17,17,17,17,17,17,16,16,13,
  120856. 14,13,13,14,14,15,14,15,14,
  120857. };
  120858. static float _vq_quantthresh__44c8_s_p9_1[] = {
  120859. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  120860. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  120861. 367.5, 416.5,
  120862. };
  120863. static long _vq_quantmap__44c8_s_p9_1[] = {
  120864. 17, 15, 13, 11, 9, 7, 5, 3,
  120865. 1, 0, 2, 4, 6, 8, 10, 12,
  120866. 14, 16, 18,
  120867. };
  120868. static encode_aux_threshmatch _vq_auxt__44c8_s_p9_1 = {
  120869. _vq_quantthresh__44c8_s_p9_1,
  120870. _vq_quantmap__44c8_s_p9_1,
  120871. 19,
  120872. 19
  120873. };
  120874. static static_codebook _44c8_s_p9_1 = {
  120875. 2, 361,
  120876. _vq_lengthlist__44c8_s_p9_1,
  120877. 1, -518287360, 1622704128, 5, 0,
  120878. _vq_quantlist__44c8_s_p9_1,
  120879. NULL,
  120880. &_vq_auxt__44c8_s_p9_1,
  120881. NULL,
  120882. 0
  120883. };
  120884. static long _vq_quantlist__44c8_s_p9_2[] = {
  120885. 24,
  120886. 23,
  120887. 25,
  120888. 22,
  120889. 26,
  120890. 21,
  120891. 27,
  120892. 20,
  120893. 28,
  120894. 19,
  120895. 29,
  120896. 18,
  120897. 30,
  120898. 17,
  120899. 31,
  120900. 16,
  120901. 32,
  120902. 15,
  120903. 33,
  120904. 14,
  120905. 34,
  120906. 13,
  120907. 35,
  120908. 12,
  120909. 36,
  120910. 11,
  120911. 37,
  120912. 10,
  120913. 38,
  120914. 9,
  120915. 39,
  120916. 8,
  120917. 40,
  120918. 7,
  120919. 41,
  120920. 6,
  120921. 42,
  120922. 5,
  120923. 43,
  120924. 4,
  120925. 44,
  120926. 3,
  120927. 45,
  120928. 2,
  120929. 46,
  120930. 1,
  120931. 47,
  120932. 0,
  120933. 48,
  120934. };
  120935. static long _vq_lengthlist__44c8_s_p9_2[] = {
  120936. 2, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
  120937. 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  120938. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  120939. 7,
  120940. };
  120941. static float _vq_quantthresh__44c8_s_p9_2[] = {
  120942. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  120943. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  120944. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  120945. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  120946. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  120947. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  120948. };
  120949. static long _vq_quantmap__44c8_s_p9_2[] = {
  120950. 47, 45, 43, 41, 39, 37, 35, 33,
  120951. 31, 29, 27, 25, 23, 21, 19, 17,
  120952. 15, 13, 11, 9, 7, 5, 3, 1,
  120953. 0, 2, 4, 6, 8, 10, 12, 14,
  120954. 16, 18, 20, 22, 24, 26, 28, 30,
  120955. 32, 34, 36, 38, 40, 42, 44, 46,
  120956. 48,
  120957. };
  120958. static encode_aux_threshmatch _vq_auxt__44c8_s_p9_2 = {
  120959. _vq_quantthresh__44c8_s_p9_2,
  120960. _vq_quantmap__44c8_s_p9_2,
  120961. 49,
  120962. 49
  120963. };
  120964. static static_codebook _44c8_s_p9_2 = {
  120965. 1, 49,
  120966. _vq_lengthlist__44c8_s_p9_2,
  120967. 1, -526909440, 1611661312, 6, 0,
  120968. _vq_quantlist__44c8_s_p9_2,
  120969. NULL,
  120970. &_vq_auxt__44c8_s_p9_2,
  120971. NULL,
  120972. 0
  120973. };
  120974. static long _huff_lengthlist__44c8_s_short[] = {
  120975. 4,11,13,14,15,15,18,17,19,17, 5, 6, 8, 9,10,10,
  120976. 12,15,19,19, 6, 6, 6, 6, 8, 8,11,14,18,19, 8, 6,
  120977. 5, 4, 6, 7,10,13,16,17, 9, 7, 6, 5, 6, 7, 9,12,
  120978. 15,19,10, 8, 7, 6, 6, 6, 7, 9,13,15,12,10, 9, 8,
  120979. 7, 6, 4, 5,10,15,13,13,11, 8, 6, 6, 4, 2, 7,12,
  120980. 17,15,16,10, 8, 8, 7, 6, 9,12,19,18,17,13,11,10,
  120981. 10, 9,11,14,
  120982. };
  120983. static static_codebook _huff_book__44c8_s_short = {
  120984. 2, 100,
  120985. _huff_lengthlist__44c8_s_short,
  120986. 0, 0, 0, 0, 0,
  120987. NULL,
  120988. NULL,
  120989. NULL,
  120990. NULL,
  120991. 0
  120992. };
  120993. static long _huff_lengthlist__44c9_s_long[] = {
  120994. 3, 8,12,14,15,15,15,13,15,15, 6, 5, 8,10,12,12,
  120995. 13,12,14,13,10, 6, 5, 6, 8, 9,11,11,13,13,13, 8,
  120996. 5, 4, 5, 6, 8,10,11,13,14,10, 7, 5, 4, 5, 7, 9,
  120997. 11,12,13,11, 8, 6, 5, 4, 5, 7, 9,11,12,11,10, 8,
  120998. 7, 5, 4, 5, 9,10,13,13,11,10, 8, 6, 5, 4, 7, 9,
  120999. 15,14,13,12,10, 9, 8, 7, 8, 9,12,12,14,13,12,11,
  121000. 10, 9, 8, 9,
  121001. };
  121002. static static_codebook _huff_book__44c9_s_long = {
  121003. 2, 100,
  121004. _huff_lengthlist__44c9_s_long,
  121005. 0, 0, 0, 0, 0,
  121006. NULL,
  121007. NULL,
  121008. NULL,
  121009. NULL,
  121010. 0
  121011. };
  121012. static long _vq_quantlist__44c9_s_p1_0[] = {
  121013. 1,
  121014. 0,
  121015. 2,
  121016. };
  121017. static long _vq_lengthlist__44c9_s_p1_0[] = {
  121018. 1, 5, 5, 0, 5, 5, 0, 5, 5, 6, 8, 8, 0, 9, 8, 0,
  121019. 9, 8, 6, 8, 8, 0, 8, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  121020. 0, 0, 0, 0, 5, 8, 8, 0, 7, 7, 0, 8, 8, 5, 8, 8,
  121021. 0, 7, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  121022. 9, 8, 0, 8, 8, 0, 7, 7, 5, 8, 9, 0, 8, 8, 0, 7,
  121023. 7,
  121024. };
  121025. static float _vq_quantthresh__44c9_s_p1_0[] = {
  121026. -0.5, 0.5,
  121027. };
  121028. static long _vq_quantmap__44c9_s_p1_0[] = {
  121029. 1, 0, 2,
  121030. };
  121031. static encode_aux_threshmatch _vq_auxt__44c9_s_p1_0 = {
  121032. _vq_quantthresh__44c9_s_p1_0,
  121033. _vq_quantmap__44c9_s_p1_0,
  121034. 3,
  121035. 3
  121036. };
  121037. static static_codebook _44c9_s_p1_0 = {
  121038. 4, 81,
  121039. _vq_lengthlist__44c9_s_p1_0,
  121040. 1, -535822336, 1611661312, 2, 0,
  121041. _vq_quantlist__44c9_s_p1_0,
  121042. NULL,
  121043. &_vq_auxt__44c9_s_p1_0,
  121044. NULL,
  121045. 0
  121046. };
  121047. static long _vq_quantlist__44c9_s_p2_0[] = {
  121048. 2,
  121049. 1,
  121050. 3,
  121051. 0,
  121052. 4,
  121053. };
  121054. static long _vq_lengthlist__44c9_s_p2_0[] = {
  121055. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  121056. 7, 7, 9, 9, 0, 0, 0, 9, 9, 6, 7, 7, 9, 8, 0, 8,
  121057. 8, 9, 9, 0, 8, 7, 9, 9, 0, 9,10,10,10, 0, 0, 0,
  121058. 11,10, 6, 7, 7, 8, 9, 0, 8, 8, 9, 9, 0, 7, 8, 9,
  121059. 9, 0,10, 9,11,10, 0, 0, 0,10,10, 8, 9, 8,10,10,
  121060. 0,10,10,12,11, 0,10,10,11,11, 0,12,13,13,13, 0,
  121061. 0, 0,13,12, 8, 8, 9,10,10, 0,10,10,11,12, 0,10,
  121062. 10,11,11, 0,13,12,13,13, 0, 0, 0,13,13, 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, 6, 8, 7,10,10, 0, 7, 7,10, 9,
  121065. 0, 7, 7,10,10, 0, 9, 9,10,10, 0, 0, 0,10,10, 6,
  121066. 7, 8,10,10, 0, 7, 7, 9,10, 0, 7, 7,10,10, 0, 9,
  121067. 9,10,10, 0, 0, 0,10,10, 8, 9, 9,11,11, 0,10,10,
  121068. 11,11, 0,10,10,11,11, 0,12,12,12,12, 0, 0, 0,12,
  121069. 12, 8, 9,10,11,11, 0, 9,10,11,11, 0,10,10,11,11,
  121070. 0,12,12,12,12, 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0,
  121071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121072. 0, 0, 0, 5, 8, 7,10,10, 0, 7, 7,10,10, 0, 7, 7,
  121073. 10, 9, 0, 9, 9,10,10, 0, 0, 0,10,10, 6, 7, 8,10,
  121074. 10, 0, 7, 7,10,10, 0, 7, 7, 9,10, 0, 9, 9,10,10,
  121075. 0, 0, 0,10,10, 8,10, 9,12,11, 0,10,10,12,11, 0,
  121076. 10, 9,11,11, 0,11,12,12,12, 0, 0, 0,12,12, 8, 9,
  121077. 10,11,12, 0,10,10,11,11, 0, 9,10,11,11, 0,12,11,
  121078. 12,12, 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121080. 7,10, 9,12,12, 0, 9, 9,12,11, 0, 9, 9,11,11, 0,
  121081. 10,10,12,11, 0, 0, 0,11,12, 7, 9,10,12,12, 0, 9,
  121082. 9,11,12, 0, 9, 9,11,11, 0,10,10,11,12, 0, 0, 0,
  121083. 11,11, 9,11,10,13,12, 0,10,10,12,12, 0,10,10,12,
  121084. 12, 0,11,11,12,12, 0, 0, 0,13,12, 9,10,11,12,13,
  121085. 0,10,10,12,12, 0,10,10,12,12, 0,11,12,12,12, 0,
  121086. 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  121091. 11,10,13,13, 0,10,10,12,12, 0,10,10,12,12, 0,11,
  121092. 12,12,12, 0, 0, 0,12,12, 9,10,11,13,13, 0,10,10,
  121093. 12,12, 0,10,10,12,12, 0,12,11,13,12, 0, 0, 0,12,
  121094. 12,
  121095. };
  121096. static float _vq_quantthresh__44c9_s_p2_0[] = {
  121097. -1.5, -0.5, 0.5, 1.5,
  121098. };
  121099. static long _vq_quantmap__44c9_s_p2_0[] = {
  121100. 3, 1, 0, 2, 4,
  121101. };
  121102. static encode_aux_threshmatch _vq_auxt__44c9_s_p2_0 = {
  121103. _vq_quantthresh__44c9_s_p2_0,
  121104. _vq_quantmap__44c9_s_p2_0,
  121105. 5,
  121106. 5
  121107. };
  121108. static static_codebook _44c9_s_p2_0 = {
  121109. 4, 625,
  121110. _vq_lengthlist__44c9_s_p2_0,
  121111. 1, -533725184, 1611661312, 3, 0,
  121112. _vq_quantlist__44c9_s_p2_0,
  121113. NULL,
  121114. &_vq_auxt__44c9_s_p2_0,
  121115. NULL,
  121116. 0
  121117. };
  121118. static long _vq_quantlist__44c9_s_p3_0[] = {
  121119. 4,
  121120. 3,
  121121. 5,
  121122. 2,
  121123. 6,
  121124. 1,
  121125. 7,
  121126. 0,
  121127. 8,
  121128. };
  121129. static long _vq_lengthlist__44c9_s_p3_0[] = {
  121130. 3, 4, 4, 5, 5, 6, 6, 8, 8, 0, 4, 4, 5, 5, 6, 7,
  121131. 8, 8, 0, 4, 4, 5, 5, 7, 7, 8, 8, 0, 5, 5, 6, 6,
  121132. 7, 7, 9, 9, 0, 0, 0, 6, 6, 7, 7, 9, 9, 0, 0, 0,
  121133. 7, 7, 8, 8, 9, 9, 0, 0, 0, 7, 7, 8, 8, 9, 9, 0,
  121134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121135. 0,
  121136. };
  121137. static float _vq_quantthresh__44c9_s_p3_0[] = {
  121138. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  121139. };
  121140. static long _vq_quantmap__44c9_s_p3_0[] = {
  121141. 7, 5, 3, 1, 0, 2, 4, 6,
  121142. 8,
  121143. };
  121144. static encode_aux_threshmatch _vq_auxt__44c9_s_p3_0 = {
  121145. _vq_quantthresh__44c9_s_p3_0,
  121146. _vq_quantmap__44c9_s_p3_0,
  121147. 9,
  121148. 9
  121149. };
  121150. static static_codebook _44c9_s_p3_0 = {
  121151. 2, 81,
  121152. _vq_lengthlist__44c9_s_p3_0,
  121153. 1, -531628032, 1611661312, 4, 0,
  121154. _vq_quantlist__44c9_s_p3_0,
  121155. NULL,
  121156. &_vq_auxt__44c9_s_p3_0,
  121157. NULL,
  121158. 0
  121159. };
  121160. static long _vq_quantlist__44c9_s_p4_0[] = {
  121161. 8,
  121162. 7,
  121163. 9,
  121164. 6,
  121165. 10,
  121166. 5,
  121167. 11,
  121168. 4,
  121169. 12,
  121170. 3,
  121171. 13,
  121172. 2,
  121173. 14,
  121174. 1,
  121175. 15,
  121176. 0,
  121177. 16,
  121178. };
  121179. static long _vq_lengthlist__44c9_s_p4_0[] = {
  121180. 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,10,
  121181. 10, 0, 5, 4, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10,10,
  121182. 11,11, 0, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,
  121183. 10,11,11, 0, 6, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,
  121184. 11,11,11,12, 0, 0, 0, 6, 6, 7, 7, 8, 8, 9, 9,10,
  121185. 10,11,11,12,12, 0, 0, 0, 7, 7, 7, 7, 9, 9, 9, 9,
  121186. 10,10,11,11,12,12, 0, 0, 0, 7, 7, 7, 8, 9, 9, 9,
  121187. 9,10,10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  121188. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 8, 8, 9,
  121189. 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 0, 0,
  121190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121198. 0,
  121199. };
  121200. static float _vq_quantthresh__44c9_s_p4_0[] = {
  121201. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  121202. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  121203. };
  121204. static long _vq_quantmap__44c9_s_p4_0[] = {
  121205. 15, 13, 11, 9, 7, 5, 3, 1,
  121206. 0, 2, 4, 6, 8, 10, 12, 14,
  121207. 16,
  121208. };
  121209. static encode_aux_threshmatch _vq_auxt__44c9_s_p4_0 = {
  121210. _vq_quantthresh__44c9_s_p4_0,
  121211. _vq_quantmap__44c9_s_p4_0,
  121212. 17,
  121213. 17
  121214. };
  121215. static static_codebook _44c9_s_p4_0 = {
  121216. 2, 289,
  121217. _vq_lengthlist__44c9_s_p4_0,
  121218. 1, -529530880, 1611661312, 5, 0,
  121219. _vq_quantlist__44c9_s_p4_0,
  121220. NULL,
  121221. &_vq_auxt__44c9_s_p4_0,
  121222. NULL,
  121223. 0
  121224. };
  121225. static long _vq_quantlist__44c9_s_p5_0[] = {
  121226. 1,
  121227. 0,
  121228. 2,
  121229. };
  121230. static long _vq_lengthlist__44c9_s_p5_0[] = {
  121231. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 7, 6, 9,10,10,10,
  121232. 10, 9, 4, 6, 7, 9,10,10,10, 9,10, 5, 9, 9, 9,11,
  121233. 11,10,11,11, 7,10, 9,11,12,11,12,12,12, 7, 9,10,
  121234. 11,11,12,12,12,12, 6,10,10,10,12,12,10,12,11, 7,
  121235. 10,10,11,12,12,11,12,12, 7,10,10,11,12,12,12,12,
  121236. 12,
  121237. };
  121238. static float _vq_quantthresh__44c9_s_p5_0[] = {
  121239. -5.5, 5.5,
  121240. };
  121241. static long _vq_quantmap__44c9_s_p5_0[] = {
  121242. 1, 0, 2,
  121243. };
  121244. static encode_aux_threshmatch _vq_auxt__44c9_s_p5_0 = {
  121245. _vq_quantthresh__44c9_s_p5_0,
  121246. _vq_quantmap__44c9_s_p5_0,
  121247. 3,
  121248. 3
  121249. };
  121250. static static_codebook _44c9_s_p5_0 = {
  121251. 4, 81,
  121252. _vq_lengthlist__44c9_s_p5_0,
  121253. 1, -529137664, 1618345984, 2, 0,
  121254. _vq_quantlist__44c9_s_p5_0,
  121255. NULL,
  121256. &_vq_auxt__44c9_s_p5_0,
  121257. NULL,
  121258. 0
  121259. };
  121260. static long _vq_quantlist__44c9_s_p5_1[] = {
  121261. 5,
  121262. 4,
  121263. 6,
  121264. 3,
  121265. 7,
  121266. 2,
  121267. 8,
  121268. 1,
  121269. 9,
  121270. 0,
  121271. 10,
  121272. };
  121273. static long _vq_lengthlist__44c9_s_p5_1[] = {
  121274. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7,11, 5, 5, 6, 6,
  121275. 7, 7, 7, 7, 8, 8,11, 5, 5, 6, 6, 7, 7, 7, 7, 8,
  121276. 8,11, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8,11,11,11, 6,
  121277. 6, 7, 7, 7, 8, 8, 8,11,11,11, 6, 6, 7, 7, 7, 8,
  121278. 8, 8,11,11,11, 6, 6, 7, 7, 7, 7, 8, 8,11,11,11,
  121279. 7, 7, 7, 7, 7, 7, 8, 8,11,11,11,10,10, 7, 7, 7,
  121280. 7, 8, 8,11,11,11,11,11, 7, 7, 7, 7, 7, 7,11,11,
  121281. 11,11,11, 7, 7, 7, 7, 7, 7,
  121282. };
  121283. static float _vq_quantthresh__44c9_s_p5_1[] = {
  121284. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  121285. 3.5, 4.5,
  121286. };
  121287. static long _vq_quantmap__44c9_s_p5_1[] = {
  121288. 9, 7, 5, 3, 1, 0, 2, 4,
  121289. 6, 8, 10,
  121290. };
  121291. static encode_aux_threshmatch _vq_auxt__44c9_s_p5_1 = {
  121292. _vq_quantthresh__44c9_s_p5_1,
  121293. _vq_quantmap__44c9_s_p5_1,
  121294. 11,
  121295. 11
  121296. };
  121297. static static_codebook _44c9_s_p5_1 = {
  121298. 2, 121,
  121299. _vq_lengthlist__44c9_s_p5_1,
  121300. 1, -531365888, 1611661312, 4, 0,
  121301. _vq_quantlist__44c9_s_p5_1,
  121302. NULL,
  121303. &_vq_auxt__44c9_s_p5_1,
  121304. NULL,
  121305. 0
  121306. };
  121307. static long _vq_quantlist__44c9_s_p6_0[] = {
  121308. 6,
  121309. 5,
  121310. 7,
  121311. 4,
  121312. 8,
  121313. 3,
  121314. 9,
  121315. 2,
  121316. 10,
  121317. 1,
  121318. 11,
  121319. 0,
  121320. 12,
  121321. };
  121322. static long _vq_lengthlist__44c9_s_p6_0[] = {
  121323. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 5, 4, 4,
  121324. 6, 6, 8, 8, 9, 9, 9, 9,10,10, 6, 4, 4, 6, 6, 8,
  121325. 8, 9, 9, 9, 9,10,10, 0, 6, 6, 7, 7, 8, 8, 9, 9,
  121326. 10,10,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  121327. 11, 0,10,10, 8, 8, 9, 9,10,10,11,11,12,12, 0,11,
  121328. 11, 8, 8, 9, 9,10,10,11,11,12,12, 0, 0, 0, 0, 0,
  121329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121333. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121334. };
  121335. static float _vq_quantthresh__44c9_s_p6_0[] = {
  121336. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  121337. 12.5, 17.5, 22.5, 27.5,
  121338. };
  121339. static long _vq_quantmap__44c9_s_p6_0[] = {
  121340. 11, 9, 7, 5, 3, 1, 0, 2,
  121341. 4, 6, 8, 10, 12,
  121342. };
  121343. static encode_aux_threshmatch _vq_auxt__44c9_s_p6_0 = {
  121344. _vq_quantthresh__44c9_s_p6_0,
  121345. _vq_quantmap__44c9_s_p6_0,
  121346. 13,
  121347. 13
  121348. };
  121349. static static_codebook _44c9_s_p6_0 = {
  121350. 2, 169,
  121351. _vq_lengthlist__44c9_s_p6_0,
  121352. 1, -526516224, 1616117760, 4, 0,
  121353. _vq_quantlist__44c9_s_p6_0,
  121354. NULL,
  121355. &_vq_auxt__44c9_s_p6_0,
  121356. NULL,
  121357. 0
  121358. };
  121359. static long _vq_quantlist__44c9_s_p6_1[] = {
  121360. 2,
  121361. 1,
  121362. 3,
  121363. 0,
  121364. 4,
  121365. };
  121366. static long _vq_lengthlist__44c9_s_p6_1[] = {
  121367. 4, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5,
  121368. 5, 5, 5, 5, 5, 5, 5, 5, 5,
  121369. };
  121370. static float _vq_quantthresh__44c9_s_p6_1[] = {
  121371. -1.5, -0.5, 0.5, 1.5,
  121372. };
  121373. static long _vq_quantmap__44c9_s_p6_1[] = {
  121374. 3, 1, 0, 2, 4,
  121375. };
  121376. static encode_aux_threshmatch _vq_auxt__44c9_s_p6_1 = {
  121377. _vq_quantthresh__44c9_s_p6_1,
  121378. _vq_quantmap__44c9_s_p6_1,
  121379. 5,
  121380. 5
  121381. };
  121382. static static_codebook _44c9_s_p6_1 = {
  121383. 2, 25,
  121384. _vq_lengthlist__44c9_s_p6_1,
  121385. 1, -533725184, 1611661312, 3, 0,
  121386. _vq_quantlist__44c9_s_p6_1,
  121387. NULL,
  121388. &_vq_auxt__44c9_s_p6_1,
  121389. NULL,
  121390. 0
  121391. };
  121392. static long _vq_quantlist__44c9_s_p7_0[] = {
  121393. 6,
  121394. 5,
  121395. 7,
  121396. 4,
  121397. 8,
  121398. 3,
  121399. 9,
  121400. 2,
  121401. 10,
  121402. 1,
  121403. 11,
  121404. 0,
  121405. 12,
  121406. };
  121407. static long _vq_lengthlist__44c9_s_p7_0[] = {
  121408. 2, 4, 4, 6, 6, 7, 7, 8, 8,10,10,11,11, 6, 4, 4,
  121409. 6, 6, 8, 8, 9, 9,10,10,12,12, 6, 4, 5, 6, 6, 8,
  121410. 8, 9, 9,10,10,12,12,20, 6, 6, 6, 6, 8, 8, 9,10,
  121411. 11,11,12,12,20, 6, 6, 6, 6, 8, 8,10,10,11,11,12,
  121412. 12,20,10,10, 7, 7, 9, 9,10,10,11,11,12,12,20,11,
  121413. 11, 7, 7, 9, 9,10,10,11,11,12,12,20,20,20, 9, 9,
  121414. 9, 9,11,11,12,12,13,13,20,20,20, 9, 9, 9, 9,11,
  121415. 11,12,12,13,13,20,20,20,13,13,10,10,11,11,12,13,
  121416. 13,13,20,20,20,13,13,10,10,11,11,12,13,13,13,20,
  121417. 20,20,20,19,12,12,12,12,13,13,14,15,19,19,19,19,
  121418. 19,12,12,12,12,13,13,14,14,
  121419. };
  121420. static float _vq_quantthresh__44c9_s_p7_0[] = {
  121421. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  121422. 27.5, 38.5, 49.5, 60.5,
  121423. };
  121424. static long _vq_quantmap__44c9_s_p7_0[] = {
  121425. 11, 9, 7, 5, 3, 1, 0, 2,
  121426. 4, 6, 8, 10, 12,
  121427. };
  121428. static encode_aux_threshmatch _vq_auxt__44c9_s_p7_0 = {
  121429. _vq_quantthresh__44c9_s_p7_0,
  121430. _vq_quantmap__44c9_s_p7_0,
  121431. 13,
  121432. 13
  121433. };
  121434. static static_codebook _44c9_s_p7_0 = {
  121435. 2, 169,
  121436. _vq_lengthlist__44c9_s_p7_0,
  121437. 1, -523206656, 1618345984, 4, 0,
  121438. _vq_quantlist__44c9_s_p7_0,
  121439. NULL,
  121440. &_vq_auxt__44c9_s_p7_0,
  121441. NULL,
  121442. 0
  121443. };
  121444. static long _vq_quantlist__44c9_s_p7_1[] = {
  121445. 5,
  121446. 4,
  121447. 6,
  121448. 3,
  121449. 7,
  121450. 2,
  121451. 8,
  121452. 1,
  121453. 9,
  121454. 0,
  121455. 10,
  121456. };
  121457. static long _vq_lengthlist__44c9_s_p7_1[] = {
  121458. 5, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6,
  121459. 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  121460. 7, 8, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 6,
  121461. 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  121462. 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  121463. 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  121464. 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 8, 8,
  121465. 8, 8, 8, 7, 7, 7, 7, 7, 7,
  121466. };
  121467. static float _vq_quantthresh__44c9_s_p7_1[] = {
  121468. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  121469. 3.5, 4.5,
  121470. };
  121471. static long _vq_quantmap__44c9_s_p7_1[] = {
  121472. 9, 7, 5, 3, 1, 0, 2, 4,
  121473. 6, 8, 10,
  121474. };
  121475. static encode_aux_threshmatch _vq_auxt__44c9_s_p7_1 = {
  121476. _vq_quantthresh__44c9_s_p7_1,
  121477. _vq_quantmap__44c9_s_p7_1,
  121478. 11,
  121479. 11
  121480. };
  121481. static static_codebook _44c9_s_p7_1 = {
  121482. 2, 121,
  121483. _vq_lengthlist__44c9_s_p7_1,
  121484. 1, -531365888, 1611661312, 4, 0,
  121485. _vq_quantlist__44c9_s_p7_1,
  121486. NULL,
  121487. &_vq_auxt__44c9_s_p7_1,
  121488. NULL,
  121489. 0
  121490. };
  121491. static long _vq_quantlist__44c9_s_p8_0[] = {
  121492. 7,
  121493. 6,
  121494. 8,
  121495. 5,
  121496. 9,
  121497. 4,
  121498. 10,
  121499. 3,
  121500. 11,
  121501. 2,
  121502. 12,
  121503. 1,
  121504. 13,
  121505. 0,
  121506. 14,
  121507. };
  121508. static long _vq_lengthlist__44c9_s_p8_0[] = {
  121509. 1, 4, 4, 7, 6, 8, 8, 8, 8, 9, 9,10,10,11,10, 6,
  121510. 5, 5, 7, 7, 9, 9, 8, 9,10,10,11,11,12,12, 6, 5,
  121511. 5, 7, 7, 9, 9, 9, 9,10,10,11,11,12,12,21, 7, 8,
  121512. 8, 8, 9, 9, 9, 9,10,10,11,11,12,12,21, 8, 8, 8,
  121513. 8, 9, 9, 9, 9,10,10,11,11,12,12,21,11,12, 9, 9,
  121514. 10,10,10,10,10,11,11,12,12,12,21,12,12, 9, 8,10,
  121515. 10,10,10,11,11,12,12,13,13,21,21,21, 9, 9, 9, 9,
  121516. 11,11,11,11,12,12,12,13,21,20,20, 9, 9, 9, 9,10,
  121517. 11,11,11,12,12,13,13,20,20,20,13,13,10,10,11,11,
  121518. 12,12,13,13,13,13,20,20,20,13,13,10,10,11,11,12,
  121519. 12,13,13,13,13,20,20,20,20,20,12,12,12,12,12,12,
  121520. 13,13,14,14,20,20,20,20,20,12,12,12,11,13,12,13,
  121521. 13,14,14,20,20,20,20,20,15,16,13,12,13,13,14,13,
  121522. 14,14,20,20,20,20,20,16,15,12,12,13,12,14,13,14,
  121523. 14,
  121524. };
  121525. static float _vq_quantthresh__44c9_s_p8_0[] = {
  121526. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  121527. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  121528. };
  121529. static long _vq_quantmap__44c9_s_p8_0[] = {
  121530. 13, 11, 9, 7, 5, 3, 1, 0,
  121531. 2, 4, 6, 8, 10, 12, 14,
  121532. };
  121533. static encode_aux_threshmatch _vq_auxt__44c9_s_p8_0 = {
  121534. _vq_quantthresh__44c9_s_p8_0,
  121535. _vq_quantmap__44c9_s_p8_0,
  121536. 15,
  121537. 15
  121538. };
  121539. static static_codebook _44c9_s_p8_0 = {
  121540. 2, 225,
  121541. _vq_lengthlist__44c9_s_p8_0,
  121542. 1, -520986624, 1620377600, 4, 0,
  121543. _vq_quantlist__44c9_s_p8_0,
  121544. NULL,
  121545. &_vq_auxt__44c9_s_p8_0,
  121546. NULL,
  121547. 0
  121548. };
  121549. static long _vq_quantlist__44c9_s_p8_1[] = {
  121550. 10,
  121551. 9,
  121552. 11,
  121553. 8,
  121554. 12,
  121555. 7,
  121556. 13,
  121557. 6,
  121558. 14,
  121559. 5,
  121560. 15,
  121561. 4,
  121562. 16,
  121563. 3,
  121564. 17,
  121565. 2,
  121566. 18,
  121567. 1,
  121568. 19,
  121569. 0,
  121570. 20,
  121571. };
  121572. static long _vq_lengthlist__44c9_s_p8_1[] = {
  121573. 4, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  121574. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  121575. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  121576. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,
  121577. 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121578. 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  121579. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8,
  121580. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  121581. 10, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121582. 9, 9, 9,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121583. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9,
  121584. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  121585. 10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121586. 9, 9,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121587. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9, 9,
  121588. 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,10,10,10,10,
  121589. 10,10,10, 9, 9, 9, 9, 9, 9,10, 9, 9, 9, 9, 9, 9,
  121590. 9,10,10,10,10,10,10,10, 9, 9, 9,10,10,10,10,10,
  121591. 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10, 9, 9,10,
  121592. 9,10, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,
  121593. 10,10,10,10, 9, 9,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  121594. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  121595. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  121596. 10,10, 9, 9,10, 9, 9, 9, 9, 9,10,10,10,10,10,10,
  121597. 10,10,10,10,10, 9, 9,10,10, 9, 9,10, 9, 9, 9,10,
  121598. 10,10,10,10,10,10,10,10,10,10, 9, 9,10, 9, 9, 9,
  121599. 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10, 9,
  121600. 9, 9, 9,10, 9, 9, 9, 9, 9,
  121601. };
  121602. static float _vq_quantthresh__44c9_s_p8_1[] = {
  121603. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  121604. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  121605. 6.5, 7.5, 8.5, 9.5,
  121606. };
  121607. static long _vq_quantmap__44c9_s_p8_1[] = {
  121608. 19, 17, 15, 13, 11, 9, 7, 5,
  121609. 3, 1, 0, 2, 4, 6, 8, 10,
  121610. 12, 14, 16, 18, 20,
  121611. };
  121612. static encode_aux_threshmatch _vq_auxt__44c9_s_p8_1 = {
  121613. _vq_quantthresh__44c9_s_p8_1,
  121614. _vq_quantmap__44c9_s_p8_1,
  121615. 21,
  121616. 21
  121617. };
  121618. static static_codebook _44c9_s_p8_1 = {
  121619. 2, 441,
  121620. _vq_lengthlist__44c9_s_p8_1,
  121621. 1, -529268736, 1611661312, 5, 0,
  121622. _vq_quantlist__44c9_s_p8_1,
  121623. NULL,
  121624. &_vq_auxt__44c9_s_p8_1,
  121625. NULL,
  121626. 0
  121627. };
  121628. static long _vq_quantlist__44c9_s_p9_0[] = {
  121629. 9,
  121630. 8,
  121631. 10,
  121632. 7,
  121633. 11,
  121634. 6,
  121635. 12,
  121636. 5,
  121637. 13,
  121638. 4,
  121639. 14,
  121640. 3,
  121641. 15,
  121642. 2,
  121643. 16,
  121644. 1,
  121645. 17,
  121646. 0,
  121647. 18,
  121648. };
  121649. static long _vq_lengthlist__44c9_s_p9_0[] = {
  121650. 1, 4, 3,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121651. 12,12,12, 4, 5, 6,12,12,12,12,12,12,12,12,12,12,
  121652. 12,12,12,12,12,12, 4, 6, 6,12,12,12,12,12,12,12,
  121653. 12,12,12,12,12,12,12,12,12,12,12,11,12,12,12,12,
  121654. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121655. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121656. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121657. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121658. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121659. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121660. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121661. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121662. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121663. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121664. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121665. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121666. 12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,
  121667. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121668. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121669. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121670. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121671. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121672. 11,11,11,11,11,11,11,11,11,
  121673. };
  121674. static float _vq_quantthresh__44c9_s_p9_0[] = {
  121675. -7913.5, -6982.5, -6051.5, -5120.5, -4189.5, -3258.5, -2327.5, -1396.5,
  121676. -465.5, 465.5, 1396.5, 2327.5, 3258.5, 4189.5, 5120.5, 6051.5,
  121677. 6982.5, 7913.5,
  121678. };
  121679. static long _vq_quantmap__44c9_s_p9_0[] = {
  121680. 17, 15, 13, 11, 9, 7, 5, 3,
  121681. 1, 0, 2, 4, 6, 8, 10, 12,
  121682. 14, 16, 18,
  121683. };
  121684. static encode_aux_threshmatch _vq_auxt__44c9_s_p9_0 = {
  121685. _vq_quantthresh__44c9_s_p9_0,
  121686. _vq_quantmap__44c9_s_p9_0,
  121687. 19,
  121688. 19
  121689. };
  121690. static static_codebook _44c9_s_p9_0 = {
  121691. 2, 361,
  121692. _vq_lengthlist__44c9_s_p9_0,
  121693. 1, -508535424, 1631393792, 5, 0,
  121694. _vq_quantlist__44c9_s_p9_0,
  121695. NULL,
  121696. &_vq_auxt__44c9_s_p9_0,
  121697. NULL,
  121698. 0
  121699. };
  121700. static long _vq_quantlist__44c9_s_p9_1[] = {
  121701. 9,
  121702. 8,
  121703. 10,
  121704. 7,
  121705. 11,
  121706. 6,
  121707. 12,
  121708. 5,
  121709. 13,
  121710. 4,
  121711. 14,
  121712. 3,
  121713. 15,
  121714. 2,
  121715. 16,
  121716. 1,
  121717. 17,
  121718. 0,
  121719. 18,
  121720. };
  121721. static long _vq_lengthlist__44c9_s_p9_1[] = {
  121722. 1, 4, 4, 7, 7, 7, 7, 8, 7, 9, 8, 9, 9,10,10,11,
  121723. 11,11,11, 6, 5, 5, 8, 8, 9, 9, 9, 8,10, 9,11,10,
  121724. 12,12,13,12,13,13, 5, 5, 5, 8, 8, 9, 9, 9, 9,10,
  121725. 10,11,11,12,12,13,12,13,13,17, 8, 8, 9, 9, 9, 9,
  121726. 9, 9,10,10,12,11,13,12,13,13,13,13,18, 8, 8, 9,
  121727. 9, 9, 9, 9, 9,11,11,12,12,13,13,13,13,13,13,17,
  121728. 13,12, 9, 9,10,10,10,10,11,11,12,12,12,13,13,13,
  121729. 14,14,18,13,12, 9, 9,10,10,10,10,11,11,12,12,13,
  121730. 13,13,14,14,14,17,18,18,10,10,10,10,11,11,11,12,
  121731. 12,12,14,13,14,13,13,14,18,18,18,10, 9,10, 9,11,
  121732. 11,12,12,12,12,13,13,15,14,14,14,18,18,16,13,14,
  121733. 10,11,11,11,12,13,13,13,13,14,13,13,14,14,18,18,
  121734. 18,14,12,11, 9,11,10,13,12,13,13,13,14,14,14,13,
  121735. 14,18,18,17,18,18,11,12,12,12,13,13,14,13,14,14,
  121736. 13,14,14,14,18,18,18,18,17,12,10,12, 9,13,11,13,
  121737. 14,14,14,14,14,15,14,18,18,17,17,18,14,15,12,13,
  121738. 13,13,14,13,14,14,15,14,15,14,18,17,18,18,18,15,
  121739. 15,12,10,14,10,14,14,13,13,14,14,14,14,18,16,18,
  121740. 18,18,18,17,14,14,13,14,14,13,13,14,14,14,15,15,
  121741. 18,18,18,18,17,17,17,14,14,14,12,14,13,14,14,15,
  121742. 14,15,14,18,18,18,18,18,18,18,17,16,13,13,13,14,
  121743. 14,14,14,15,16,15,18,18,18,18,18,18,18,17,17,13,
  121744. 13,13,13,14,13,14,15,15,15,
  121745. };
  121746. static float _vq_quantthresh__44c9_s_p9_1[] = {
  121747. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  121748. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  121749. 367.5, 416.5,
  121750. };
  121751. static long _vq_quantmap__44c9_s_p9_1[] = {
  121752. 17, 15, 13, 11, 9, 7, 5, 3,
  121753. 1, 0, 2, 4, 6, 8, 10, 12,
  121754. 14, 16, 18,
  121755. };
  121756. static encode_aux_threshmatch _vq_auxt__44c9_s_p9_1 = {
  121757. _vq_quantthresh__44c9_s_p9_1,
  121758. _vq_quantmap__44c9_s_p9_1,
  121759. 19,
  121760. 19
  121761. };
  121762. static static_codebook _44c9_s_p9_1 = {
  121763. 2, 361,
  121764. _vq_lengthlist__44c9_s_p9_1,
  121765. 1, -518287360, 1622704128, 5, 0,
  121766. _vq_quantlist__44c9_s_p9_1,
  121767. NULL,
  121768. &_vq_auxt__44c9_s_p9_1,
  121769. NULL,
  121770. 0
  121771. };
  121772. static long _vq_quantlist__44c9_s_p9_2[] = {
  121773. 24,
  121774. 23,
  121775. 25,
  121776. 22,
  121777. 26,
  121778. 21,
  121779. 27,
  121780. 20,
  121781. 28,
  121782. 19,
  121783. 29,
  121784. 18,
  121785. 30,
  121786. 17,
  121787. 31,
  121788. 16,
  121789. 32,
  121790. 15,
  121791. 33,
  121792. 14,
  121793. 34,
  121794. 13,
  121795. 35,
  121796. 12,
  121797. 36,
  121798. 11,
  121799. 37,
  121800. 10,
  121801. 38,
  121802. 9,
  121803. 39,
  121804. 8,
  121805. 40,
  121806. 7,
  121807. 41,
  121808. 6,
  121809. 42,
  121810. 5,
  121811. 43,
  121812. 4,
  121813. 44,
  121814. 3,
  121815. 45,
  121816. 2,
  121817. 46,
  121818. 1,
  121819. 47,
  121820. 0,
  121821. 48,
  121822. };
  121823. static long _vq_lengthlist__44c9_s_p9_2[] = {
  121824. 2, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
  121825. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  121826. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  121827. 7,
  121828. };
  121829. static float _vq_quantthresh__44c9_s_p9_2[] = {
  121830. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  121831. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  121832. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  121833. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  121834. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  121835. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  121836. };
  121837. static long _vq_quantmap__44c9_s_p9_2[] = {
  121838. 47, 45, 43, 41, 39, 37, 35, 33,
  121839. 31, 29, 27, 25, 23, 21, 19, 17,
  121840. 15, 13, 11, 9, 7, 5, 3, 1,
  121841. 0, 2, 4, 6, 8, 10, 12, 14,
  121842. 16, 18, 20, 22, 24, 26, 28, 30,
  121843. 32, 34, 36, 38, 40, 42, 44, 46,
  121844. 48,
  121845. };
  121846. static encode_aux_threshmatch _vq_auxt__44c9_s_p9_2 = {
  121847. _vq_quantthresh__44c9_s_p9_2,
  121848. _vq_quantmap__44c9_s_p9_2,
  121849. 49,
  121850. 49
  121851. };
  121852. static static_codebook _44c9_s_p9_2 = {
  121853. 1, 49,
  121854. _vq_lengthlist__44c9_s_p9_2,
  121855. 1, -526909440, 1611661312, 6, 0,
  121856. _vq_quantlist__44c9_s_p9_2,
  121857. NULL,
  121858. &_vq_auxt__44c9_s_p9_2,
  121859. NULL,
  121860. 0
  121861. };
  121862. static long _huff_lengthlist__44c9_s_short[] = {
  121863. 5,13,18,16,17,17,19,18,19,19, 5, 7,10,11,12,12,
  121864. 13,16,17,18, 6, 6, 7, 7, 9, 9,10,14,17,19, 8, 7,
  121865. 6, 5, 6, 7, 9,12,19,17, 8, 7, 7, 6, 5, 6, 8,11,
  121866. 15,19, 9, 8, 7, 6, 5, 5, 6, 8,13,15,11,10, 8, 8,
  121867. 7, 5, 4, 4,10,14,12,13,11, 9, 7, 6, 4, 2, 6,12,
  121868. 18,16,16,13, 8, 7, 7, 5, 8,13,16,17,18,15,11, 9,
  121869. 9, 8,10,13,
  121870. };
  121871. static static_codebook _huff_book__44c9_s_short = {
  121872. 2, 100,
  121873. _huff_lengthlist__44c9_s_short,
  121874. 0, 0, 0, 0, 0,
  121875. NULL,
  121876. NULL,
  121877. NULL,
  121878. NULL,
  121879. 0
  121880. };
  121881. static long _huff_lengthlist__44c0_s_long[] = {
  121882. 5, 4, 8, 9, 8, 9,10,12,15, 4, 1, 5, 5, 6, 8,11,
  121883. 12,12, 8, 5, 8, 9, 9,11,13,12,12, 9, 5, 8, 5, 7,
  121884. 9,12,13,13, 8, 6, 8, 7, 7, 9,11,11,11, 9, 7, 9,
  121885. 7, 7, 7, 7,10,12,10,10,11, 9, 8, 7, 7, 9,11,11,
  121886. 12,13,12,11, 9, 8, 9,11,13,16,16,15,15,12,10,11,
  121887. 12,
  121888. };
  121889. static static_codebook _huff_book__44c0_s_long = {
  121890. 2, 81,
  121891. _huff_lengthlist__44c0_s_long,
  121892. 0, 0, 0, 0, 0,
  121893. NULL,
  121894. NULL,
  121895. NULL,
  121896. NULL,
  121897. 0
  121898. };
  121899. static long _vq_quantlist__44c0_s_p1_0[] = {
  121900. 1,
  121901. 0,
  121902. 2,
  121903. };
  121904. static long _vq_lengthlist__44c0_s_p1_0[] = {
  121905. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  121906. 0, 0, 5, 7, 7, 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, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  121911. 0, 0, 0, 7, 9, 9, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  121916. 0, 0, 0, 0, 7, 9, 9, 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, 5, 7, 7, 0, 0, 0, 0,
  121951. 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 7, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  121956. 0, 0, 0, 9,10,11, 0, 0, 0, 0, 0, 0, 9,11,10, 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, 7, 9, 9, 0, 0,
  121961. 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  121997. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  122002. 0, 0, 0, 0, 0, 9, 9,11, 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, 7, 9,10, 0, 0, 0, 0, 0, 0, 9,10,11,
  122007. 0, 0, 0, 0, 0, 0, 9,11,10, 0, 0, 0, 0, 0, 0, 0,
  122008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122315. 0,
  122316. };
  122317. static float _vq_quantthresh__44c0_s_p1_0[] = {
  122318. -0.5, 0.5,
  122319. };
  122320. static long _vq_quantmap__44c0_s_p1_0[] = {
  122321. 1, 0, 2,
  122322. };
  122323. static encode_aux_threshmatch _vq_auxt__44c0_s_p1_0 = {
  122324. _vq_quantthresh__44c0_s_p1_0,
  122325. _vq_quantmap__44c0_s_p1_0,
  122326. 3,
  122327. 3
  122328. };
  122329. static static_codebook _44c0_s_p1_0 = {
  122330. 8, 6561,
  122331. _vq_lengthlist__44c0_s_p1_0,
  122332. 1, -535822336, 1611661312, 2, 0,
  122333. _vq_quantlist__44c0_s_p1_0,
  122334. NULL,
  122335. &_vq_auxt__44c0_s_p1_0,
  122336. NULL,
  122337. 0
  122338. };
  122339. static long _vq_quantlist__44c0_s_p2_0[] = {
  122340. 2,
  122341. 1,
  122342. 3,
  122343. 0,
  122344. 4,
  122345. };
  122346. static long _vq_lengthlist__44c0_s_p2_0[] = {
  122347. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 6, 0, 0,
  122349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122350. 0, 0, 4, 5, 6, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  122352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122353. 0, 0, 0, 0, 6, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  122354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122386. 0,
  122387. };
  122388. static float _vq_quantthresh__44c0_s_p2_0[] = {
  122389. -1.5, -0.5, 0.5, 1.5,
  122390. };
  122391. static long _vq_quantmap__44c0_s_p2_0[] = {
  122392. 3, 1, 0, 2, 4,
  122393. };
  122394. static encode_aux_threshmatch _vq_auxt__44c0_s_p2_0 = {
  122395. _vq_quantthresh__44c0_s_p2_0,
  122396. _vq_quantmap__44c0_s_p2_0,
  122397. 5,
  122398. 5
  122399. };
  122400. static static_codebook _44c0_s_p2_0 = {
  122401. 4, 625,
  122402. _vq_lengthlist__44c0_s_p2_0,
  122403. 1, -533725184, 1611661312, 3, 0,
  122404. _vq_quantlist__44c0_s_p2_0,
  122405. NULL,
  122406. &_vq_auxt__44c0_s_p2_0,
  122407. NULL,
  122408. 0
  122409. };
  122410. static long _vq_quantlist__44c0_s_p3_0[] = {
  122411. 4,
  122412. 3,
  122413. 5,
  122414. 2,
  122415. 6,
  122416. 1,
  122417. 7,
  122418. 0,
  122419. 8,
  122420. };
  122421. static long _vq_lengthlist__44c0_s_p3_0[] = {
  122422. 1, 3, 2, 8, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  122423. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  122424. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  122425. 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  122426. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122427. 0,
  122428. };
  122429. static float _vq_quantthresh__44c0_s_p3_0[] = {
  122430. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  122431. };
  122432. static long _vq_quantmap__44c0_s_p3_0[] = {
  122433. 7, 5, 3, 1, 0, 2, 4, 6,
  122434. 8,
  122435. };
  122436. static encode_aux_threshmatch _vq_auxt__44c0_s_p3_0 = {
  122437. _vq_quantthresh__44c0_s_p3_0,
  122438. _vq_quantmap__44c0_s_p3_0,
  122439. 9,
  122440. 9
  122441. };
  122442. static static_codebook _44c0_s_p3_0 = {
  122443. 2, 81,
  122444. _vq_lengthlist__44c0_s_p3_0,
  122445. 1, -531628032, 1611661312, 4, 0,
  122446. _vq_quantlist__44c0_s_p3_0,
  122447. NULL,
  122448. &_vq_auxt__44c0_s_p3_0,
  122449. NULL,
  122450. 0
  122451. };
  122452. static long _vq_quantlist__44c0_s_p4_0[] = {
  122453. 4,
  122454. 3,
  122455. 5,
  122456. 2,
  122457. 6,
  122458. 1,
  122459. 7,
  122460. 0,
  122461. 8,
  122462. };
  122463. static long _vq_lengthlist__44c0_s_p4_0[] = {
  122464. 1, 3, 3, 6, 6, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  122465. 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  122466. 7, 8, 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0,
  122467. 9, 9, 8, 8,10,10, 0, 0, 0, 8, 9, 8, 8,10,10, 0,
  122468. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  122469. 10,
  122470. };
  122471. static float _vq_quantthresh__44c0_s_p4_0[] = {
  122472. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  122473. };
  122474. static long _vq_quantmap__44c0_s_p4_0[] = {
  122475. 7, 5, 3, 1, 0, 2, 4, 6,
  122476. 8,
  122477. };
  122478. static encode_aux_threshmatch _vq_auxt__44c0_s_p4_0 = {
  122479. _vq_quantthresh__44c0_s_p4_0,
  122480. _vq_quantmap__44c0_s_p4_0,
  122481. 9,
  122482. 9
  122483. };
  122484. static static_codebook _44c0_s_p4_0 = {
  122485. 2, 81,
  122486. _vq_lengthlist__44c0_s_p4_0,
  122487. 1, -531628032, 1611661312, 4, 0,
  122488. _vq_quantlist__44c0_s_p4_0,
  122489. NULL,
  122490. &_vq_auxt__44c0_s_p4_0,
  122491. NULL,
  122492. 0
  122493. };
  122494. static long _vq_quantlist__44c0_s_p5_0[] = {
  122495. 8,
  122496. 7,
  122497. 9,
  122498. 6,
  122499. 10,
  122500. 5,
  122501. 11,
  122502. 4,
  122503. 12,
  122504. 3,
  122505. 13,
  122506. 2,
  122507. 14,
  122508. 1,
  122509. 15,
  122510. 0,
  122511. 16,
  122512. };
  122513. static long _vq_lengthlist__44c0_s_p5_0[] = {
  122514. 1, 4, 3, 6, 6, 8, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  122515. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9, 9,10,10,10,
  122516. 11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  122517. 10,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  122518. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  122519. 10,11,11,11,11, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,10,
  122520. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,
  122521. 10,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  122522. 10,10,11,11,11,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  122523. 10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,
  122524. 10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  122525. 9,10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  122526. 10,10,11,11,11,11,11,12,12,12,13,13, 0, 0, 0, 0,
  122527. 0, 0, 0,11,10,11,11,11,11,12,12,13,13, 0, 0, 0,
  122528. 0, 0, 0, 0,11,11,12,11,12,12,12,12,13,13, 0, 0,
  122529. 0, 0, 0, 0, 0,11,11,11,12,12,12,12,13,13,13, 0,
  122530. 0, 0, 0, 0, 0, 0,12,12,12,12,12,13,13,13,14,14,
  122531. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  122532. 14,
  122533. };
  122534. static float _vq_quantthresh__44c0_s_p5_0[] = {
  122535. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  122536. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  122537. };
  122538. static long _vq_quantmap__44c0_s_p5_0[] = {
  122539. 15, 13, 11, 9, 7, 5, 3, 1,
  122540. 0, 2, 4, 6, 8, 10, 12, 14,
  122541. 16,
  122542. };
  122543. static encode_aux_threshmatch _vq_auxt__44c0_s_p5_0 = {
  122544. _vq_quantthresh__44c0_s_p5_0,
  122545. _vq_quantmap__44c0_s_p5_0,
  122546. 17,
  122547. 17
  122548. };
  122549. static static_codebook _44c0_s_p5_0 = {
  122550. 2, 289,
  122551. _vq_lengthlist__44c0_s_p5_0,
  122552. 1, -529530880, 1611661312, 5, 0,
  122553. _vq_quantlist__44c0_s_p5_0,
  122554. NULL,
  122555. &_vq_auxt__44c0_s_p5_0,
  122556. NULL,
  122557. 0
  122558. };
  122559. static long _vq_quantlist__44c0_s_p6_0[] = {
  122560. 1,
  122561. 0,
  122562. 2,
  122563. };
  122564. static long _vq_lengthlist__44c0_s_p6_0[] = {
  122565. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,10,
  122566. 9, 9, 4, 6, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  122567. 11,12,10,11, 6, 9, 9,11,10,11,11,10,10, 6, 9, 9,
  122568. 11,10,11,11,10,10, 7,11,10,12,11,11,11,11,11, 7,
  122569. 9, 9,10,10,10,11,11,10, 6, 9, 9,11,10,10,11,10,
  122570. 10,
  122571. };
  122572. static float _vq_quantthresh__44c0_s_p6_0[] = {
  122573. -5.5, 5.5,
  122574. };
  122575. static long _vq_quantmap__44c0_s_p6_0[] = {
  122576. 1, 0, 2,
  122577. };
  122578. static encode_aux_threshmatch _vq_auxt__44c0_s_p6_0 = {
  122579. _vq_quantthresh__44c0_s_p6_0,
  122580. _vq_quantmap__44c0_s_p6_0,
  122581. 3,
  122582. 3
  122583. };
  122584. static static_codebook _44c0_s_p6_0 = {
  122585. 4, 81,
  122586. _vq_lengthlist__44c0_s_p6_0,
  122587. 1, -529137664, 1618345984, 2, 0,
  122588. _vq_quantlist__44c0_s_p6_0,
  122589. NULL,
  122590. &_vq_auxt__44c0_s_p6_0,
  122591. NULL,
  122592. 0
  122593. };
  122594. static long _vq_quantlist__44c0_s_p6_1[] = {
  122595. 5,
  122596. 4,
  122597. 6,
  122598. 3,
  122599. 7,
  122600. 2,
  122601. 8,
  122602. 1,
  122603. 9,
  122604. 0,
  122605. 10,
  122606. };
  122607. static long _vq_lengthlist__44c0_s_p6_1[] = {
  122608. 2, 3, 3, 6, 6, 7, 7, 7, 7, 7, 8,10,10,10, 6, 6,
  122609. 7, 7, 8, 8, 8, 8,10,10,10, 6, 6, 7, 7, 8, 8, 8,
  122610. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  122611. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 7, 8, 8, 8, 8,
  122612. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  122613. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  122614. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  122615. 10,10,10, 8, 8, 8, 8, 8, 8,
  122616. };
  122617. static float _vq_quantthresh__44c0_s_p6_1[] = {
  122618. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  122619. 3.5, 4.5,
  122620. };
  122621. static long _vq_quantmap__44c0_s_p6_1[] = {
  122622. 9, 7, 5, 3, 1, 0, 2, 4,
  122623. 6, 8, 10,
  122624. };
  122625. static encode_aux_threshmatch _vq_auxt__44c0_s_p6_1 = {
  122626. _vq_quantthresh__44c0_s_p6_1,
  122627. _vq_quantmap__44c0_s_p6_1,
  122628. 11,
  122629. 11
  122630. };
  122631. static static_codebook _44c0_s_p6_1 = {
  122632. 2, 121,
  122633. _vq_lengthlist__44c0_s_p6_1,
  122634. 1, -531365888, 1611661312, 4, 0,
  122635. _vq_quantlist__44c0_s_p6_1,
  122636. NULL,
  122637. &_vq_auxt__44c0_s_p6_1,
  122638. NULL,
  122639. 0
  122640. };
  122641. static long _vq_quantlist__44c0_s_p7_0[] = {
  122642. 6,
  122643. 5,
  122644. 7,
  122645. 4,
  122646. 8,
  122647. 3,
  122648. 9,
  122649. 2,
  122650. 10,
  122651. 1,
  122652. 11,
  122653. 0,
  122654. 12,
  122655. };
  122656. static long _vq_lengthlist__44c0_s_p7_0[] = {
  122657. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 5, 5,
  122658. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 6, 7, 7, 8,
  122659. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  122660. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  122661. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  122662. 13, 9, 9, 9, 9,10,10,11,11,11,12, 0, 0, 0,10,10,
  122663. 10,10,11,11,11,11,12,12, 0, 0, 0,10,10, 9, 9,11,
  122664. 11,11,12,12,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  122665. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  122666. 0, 0, 0, 0,11,11,11,11,13,12,13,13, 0, 0, 0, 0,
  122667. 0,12,12,11,11,12,12,13,13,
  122668. };
  122669. static float _vq_quantthresh__44c0_s_p7_0[] = {
  122670. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  122671. 12.5, 17.5, 22.5, 27.5,
  122672. };
  122673. static long _vq_quantmap__44c0_s_p7_0[] = {
  122674. 11, 9, 7, 5, 3, 1, 0, 2,
  122675. 4, 6, 8, 10, 12,
  122676. };
  122677. static encode_aux_threshmatch _vq_auxt__44c0_s_p7_0 = {
  122678. _vq_quantthresh__44c0_s_p7_0,
  122679. _vq_quantmap__44c0_s_p7_0,
  122680. 13,
  122681. 13
  122682. };
  122683. static static_codebook _44c0_s_p7_0 = {
  122684. 2, 169,
  122685. _vq_lengthlist__44c0_s_p7_0,
  122686. 1, -526516224, 1616117760, 4, 0,
  122687. _vq_quantlist__44c0_s_p7_0,
  122688. NULL,
  122689. &_vq_auxt__44c0_s_p7_0,
  122690. NULL,
  122691. 0
  122692. };
  122693. static long _vq_quantlist__44c0_s_p7_1[] = {
  122694. 2,
  122695. 1,
  122696. 3,
  122697. 0,
  122698. 4,
  122699. };
  122700. static long _vq_lengthlist__44c0_s_p7_1[] = {
  122701. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  122702. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  122703. };
  122704. static float _vq_quantthresh__44c0_s_p7_1[] = {
  122705. -1.5, -0.5, 0.5, 1.5,
  122706. };
  122707. static long _vq_quantmap__44c0_s_p7_1[] = {
  122708. 3, 1, 0, 2, 4,
  122709. };
  122710. static encode_aux_threshmatch _vq_auxt__44c0_s_p7_1 = {
  122711. _vq_quantthresh__44c0_s_p7_1,
  122712. _vq_quantmap__44c0_s_p7_1,
  122713. 5,
  122714. 5
  122715. };
  122716. static static_codebook _44c0_s_p7_1 = {
  122717. 2, 25,
  122718. _vq_lengthlist__44c0_s_p7_1,
  122719. 1, -533725184, 1611661312, 3, 0,
  122720. _vq_quantlist__44c0_s_p7_1,
  122721. NULL,
  122722. &_vq_auxt__44c0_s_p7_1,
  122723. NULL,
  122724. 0
  122725. };
  122726. static long _vq_quantlist__44c0_s_p8_0[] = {
  122727. 2,
  122728. 1,
  122729. 3,
  122730. 0,
  122731. 4,
  122732. };
  122733. static long _vq_lengthlist__44c0_s_p8_0[] = {
  122734. 1, 5, 5,10,10, 6, 9, 8,10,10, 6,10, 9,10,10,10,
  122735. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122736. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122737. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122738. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122739. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122740. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122741. 10,10,10,10,10,10,10,10,10,10,10,10,10, 8,10,10,
  122742. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122743. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122744. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122745. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122746. 10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,
  122747. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122748. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122749. 11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,
  122750. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122751. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122752. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122753. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122754. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122755. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122756. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122757. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122758. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122759. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122760. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122761. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122762. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122763. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122764. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122765. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122766. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122767. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122768. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122769. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122770. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122771. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122772. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122773. 11,
  122774. };
  122775. static float _vq_quantthresh__44c0_s_p8_0[] = {
  122776. -331.5, -110.5, 110.5, 331.5,
  122777. };
  122778. static long _vq_quantmap__44c0_s_p8_0[] = {
  122779. 3, 1, 0, 2, 4,
  122780. };
  122781. static encode_aux_threshmatch _vq_auxt__44c0_s_p8_0 = {
  122782. _vq_quantthresh__44c0_s_p8_0,
  122783. _vq_quantmap__44c0_s_p8_0,
  122784. 5,
  122785. 5
  122786. };
  122787. static static_codebook _44c0_s_p8_0 = {
  122788. 4, 625,
  122789. _vq_lengthlist__44c0_s_p8_0,
  122790. 1, -518283264, 1627103232, 3, 0,
  122791. _vq_quantlist__44c0_s_p8_0,
  122792. NULL,
  122793. &_vq_auxt__44c0_s_p8_0,
  122794. NULL,
  122795. 0
  122796. };
  122797. static long _vq_quantlist__44c0_s_p8_1[] = {
  122798. 6,
  122799. 5,
  122800. 7,
  122801. 4,
  122802. 8,
  122803. 3,
  122804. 9,
  122805. 2,
  122806. 10,
  122807. 1,
  122808. 11,
  122809. 0,
  122810. 12,
  122811. };
  122812. static long _vq_lengthlist__44c0_s_p8_1[] = {
  122813. 1, 4, 4, 6, 6, 7, 7, 9, 9,11,12,13,12, 6, 5, 5,
  122814. 7, 7, 8, 8,10, 9,12,12,12,12, 6, 5, 5, 7, 7, 8,
  122815. 8,10, 9,12,11,11,13,16, 7, 7, 8, 8, 9, 9,10,10,
  122816. 12,12,13,12,16, 7, 7, 8, 7, 9, 9,10,10,11,12,12,
  122817. 13,16,10,10, 8, 8,10,10,11,12,12,12,13,13,16,11,
  122818. 10, 8, 7,11,10,11,11,12,11,13,13,16,16,16,10,10,
  122819. 10,10,11,11,13,12,13,13,16,16,16,11, 9,11, 9,15,
  122820. 13,12,13,13,13,16,16,16,15,13,11,11,12,13,12,12,
  122821. 14,13,16,16,16,14,13,11,11,13,12,14,13,13,13,16,
  122822. 16,16,16,16,13,13,13,12,14,13,14,14,16,16,16,16,
  122823. 16,13,13,12,12,14,14,15,13,
  122824. };
  122825. static float _vq_quantthresh__44c0_s_p8_1[] = {
  122826. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  122827. 42.5, 59.5, 76.5, 93.5,
  122828. };
  122829. static long _vq_quantmap__44c0_s_p8_1[] = {
  122830. 11, 9, 7, 5, 3, 1, 0, 2,
  122831. 4, 6, 8, 10, 12,
  122832. };
  122833. static encode_aux_threshmatch _vq_auxt__44c0_s_p8_1 = {
  122834. _vq_quantthresh__44c0_s_p8_1,
  122835. _vq_quantmap__44c0_s_p8_1,
  122836. 13,
  122837. 13
  122838. };
  122839. static static_codebook _44c0_s_p8_1 = {
  122840. 2, 169,
  122841. _vq_lengthlist__44c0_s_p8_1,
  122842. 1, -522616832, 1620115456, 4, 0,
  122843. _vq_quantlist__44c0_s_p8_1,
  122844. NULL,
  122845. &_vq_auxt__44c0_s_p8_1,
  122846. NULL,
  122847. 0
  122848. };
  122849. static long _vq_quantlist__44c0_s_p8_2[] = {
  122850. 8,
  122851. 7,
  122852. 9,
  122853. 6,
  122854. 10,
  122855. 5,
  122856. 11,
  122857. 4,
  122858. 12,
  122859. 3,
  122860. 13,
  122861. 2,
  122862. 14,
  122863. 1,
  122864. 15,
  122865. 0,
  122866. 16,
  122867. };
  122868. static long _vq_lengthlist__44c0_s_p8_2[] = {
  122869. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  122870. 8,10,10,10, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  122871. 9, 9,10,10,10, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  122872. 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  122873. 9,10, 9, 9,10,10,10, 7, 7, 8, 8, 9, 8, 9, 9, 9,
  122874. 9,10, 9, 9,10,10,10,10, 8, 8, 8, 8, 9, 8, 9, 9,
  122875. 9, 9, 9,10, 9,10,10,10,10, 7, 7, 8, 8, 9, 9, 9,
  122876. 9, 9, 9,10, 9,10,10,10,10,10, 8, 8, 8, 9, 9, 9,
  122877. 9, 9, 9, 9,10,10,10, 9,11,10,10,10,10, 8, 8, 9,
  122878. 9, 9, 9, 9,10, 9, 9, 9,10,10,10,10,11,11, 9, 9,
  122879. 9, 9, 9, 9, 9, 9,10, 9, 9,10,11,10,10,11,11, 9,
  122880. 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,11,10,11,11,
  122881. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,10,10,11,
  122882. 11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  122883. 11,11,11,11, 9,10, 9,10, 9, 9, 9, 9,10, 9,10,11,
  122884. 10,11,10,10,10,10,10, 9, 9, 9,10, 9, 9, 9,10,11,
  122885. 11,10,11,11,10,11,10,10,10, 9, 9, 9, 9,10, 9, 9,
  122886. 10,11,10,11,11,11,11,10,11,10,10, 9,10, 9, 9, 9,
  122887. 10,
  122888. };
  122889. static float _vq_quantthresh__44c0_s_p8_2[] = {
  122890. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  122891. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  122892. };
  122893. static long _vq_quantmap__44c0_s_p8_2[] = {
  122894. 15, 13, 11, 9, 7, 5, 3, 1,
  122895. 0, 2, 4, 6, 8, 10, 12, 14,
  122896. 16,
  122897. };
  122898. static encode_aux_threshmatch _vq_auxt__44c0_s_p8_2 = {
  122899. _vq_quantthresh__44c0_s_p8_2,
  122900. _vq_quantmap__44c0_s_p8_2,
  122901. 17,
  122902. 17
  122903. };
  122904. static static_codebook _44c0_s_p8_2 = {
  122905. 2, 289,
  122906. _vq_lengthlist__44c0_s_p8_2,
  122907. 1, -529530880, 1611661312, 5, 0,
  122908. _vq_quantlist__44c0_s_p8_2,
  122909. NULL,
  122910. &_vq_auxt__44c0_s_p8_2,
  122911. NULL,
  122912. 0
  122913. };
  122914. static long _huff_lengthlist__44c0_s_short[] = {
  122915. 9, 8,12,11,12,13,14,14,16, 6, 1, 5, 6, 6, 9,12,
  122916. 14,17, 9, 4, 5, 9, 7, 9,13,15,16, 8, 5, 8, 6, 8,
  122917. 10,13,17,17, 9, 6, 7, 7, 8, 9,13,15,17,11, 8, 9,
  122918. 9, 9,10,12,16,16,13, 7, 8, 7, 7, 9,12,14,15,13,
  122919. 6, 7, 5, 5, 7,10,13,13,14, 7, 8, 5, 6, 7, 9,10,
  122920. 12,
  122921. };
  122922. static static_codebook _huff_book__44c0_s_short = {
  122923. 2, 81,
  122924. _huff_lengthlist__44c0_s_short,
  122925. 0, 0, 0, 0, 0,
  122926. NULL,
  122927. NULL,
  122928. NULL,
  122929. NULL,
  122930. 0
  122931. };
  122932. static long _huff_lengthlist__44c0_sm_long[] = {
  122933. 5, 4, 9,10, 9,10,11,12,13, 4, 1, 5, 7, 7, 9,11,
  122934. 12,14, 8, 5, 7, 9, 8,10,13,13,13,10, 7, 9, 4, 6,
  122935. 7,10,12,14, 9, 6, 7, 6, 6, 7,10,12,12, 9, 8, 9,
  122936. 7, 6, 7, 8,11,12,11,11,11, 9, 8, 7, 8,10,12,12,
  122937. 13,14,12,11, 9, 9, 9,12,12,17,17,15,16,12,10,11,
  122938. 13,
  122939. };
  122940. static static_codebook _huff_book__44c0_sm_long = {
  122941. 2, 81,
  122942. _huff_lengthlist__44c0_sm_long,
  122943. 0, 0, 0, 0, 0,
  122944. NULL,
  122945. NULL,
  122946. NULL,
  122947. NULL,
  122948. 0
  122949. };
  122950. static long _vq_quantlist__44c0_sm_p1_0[] = {
  122951. 1,
  122952. 0,
  122953. 2,
  122954. };
  122955. static long _vq_lengthlist__44c0_sm_p1_0[] = {
  122956. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  122957. 0, 0, 5, 7, 7, 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, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  122962. 0, 0, 0, 7, 8, 9, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  122967. 0, 0, 0, 0, 7, 9, 9, 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, 5, 8, 7, 0, 0, 0, 0,
  123002. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  123007. 0, 0, 0, 9,10,10, 0, 0, 0, 0, 0, 0, 9,10,10, 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, 7, 9, 9, 0, 0,
  123012. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  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, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  123048. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  123053. 0, 0, 0, 0, 0, 9, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  123058. 0, 0, 0, 0, 0, 0, 9,10,10, 0, 0, 0, 0, 0, 0, 0,
  123059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123366. 0,
  123367. };
  123368. static float _vq_quantthresh__44c0_sm_p1_0[] = {
  123369. -0.5, 0.5,
  123370. };
  123371. static long _vq_quantmap__44c0_sm_p1_0[] = {
  123372. 1, 0, 2,
  123373. };
  123374. static encode_aux_threshmatch _vq_auxt__44c0_sm_p1_0 = {
  123375. _vq_quantthresh__44c0_sm_p1_0,
  123376. _vq_quantmap__44c0_sm_p1_0,
  123377. 3,
  123378. 3
  123379. };
  123380. static static_codebook _44c0_sm_p1_0 = {
  123381. 8, 6561,
  123382. _vq_lengthlist__44c0_sm_p1_0,
  123383. 1, -535822336, 1611661312, 2, 0,
  123384. _vq_quantlist__44c0_sm_p1_0,
  123385. NULL,
  123386. &_vq_auxt__44c0_sm_p1_0,
  123387. NULL,
  123388. 0
  123389. };
  123390. static long _vq_quantlist__44c0_sm_p2_0[] = {
  123391. 2,
  123392. 1,
  123393. 3,
  123394. 0,
  123395. 4,
  123396. };
  123397. static long _vq_lengthlist__44c0_sm_p2_0[] = {
  123398. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  123400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123401. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  123403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123404. 0, 0, 0, 0, 7, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  123405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123437. 0,
  123438. };
  123439. static float _vq_quantthresh__44c0_sm_p2_0[] = {
  123440. -1.5, -0.5, 0.5, 1.5,
  123441. };
  123442. static long _vq_quantmap__44c0_sm_p2_0[] = {
  123443. 3, 1, 0, 2, 4,
  123444. };
  123445. static encode_aux_threshmatch _vq_auxt__44c0_sm_p2_0 = {
  123446. _vq_quantthresh__44c0_sm_p2_0,
  123447. _vq_quantmap__44c0_sm_p2_0,
  123448. 5,
  123449. 5
  123450. };
  123451. static static_codebook _44c0_sm_p2_0 = {
  123452. 4, 625,
  123453. _vq_lengthlist__44c0_sm_p2_0,
  123454. 1, -533725184, 1611661312, 3, 0,
  123455. _vq_quantlist__44c0_sm_p2_0,
  123456. NULL,
  123457. &_vq_auxt__44c0_sm_p2_0,
  123458. NULL,
  123459. 0
  123460. };
  123461. static long _vq_quantlist__44c0_sm_p3_0[] = {
  123462. 4,
  123463. 3,
  123464. 5,
  123465. 2,
  123466. 6,
  123467. 1,
  123468. 7,
  123469. 0,
  123470. 8,
  123471. };
  123472. static long _vq_lengthlist__44c0_sm_p3_0[] = {
  123473. 1, 3, 3, 7, 7, 0, 0, 0, 0, 0, 5, 4, 7, 7, 0, 0,
  123474. 0, 0, 0, 5, 5, 7, 7, 0, 0, 0, 0, 0, 6, 7, 8, 8,
  123475. 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  123476. 9,10, 0, 0, 0, 0, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0,
  123477. 0, 0,11,11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123478. 0,
  123479. };
  123480. static float _vq_quantthresh__44c0_sm_p3_0[] = {
  123481. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  123482. };
  123483. static long _vq_quantmap__44c0_sm_p3_0[] = {
  123484. 7, 5, 3, 1, 0, 2, 4, 6,
  123485. 8,
  123486. };
  123487. static encode_aux_threshmatch _vq_auxt__44c0_sm_p3_0 = {
  123488. _vq_quantthresh__44c0_sm_p3_0,
  123489. _vq_quantmap__44c0_sm_p3_0,
  123490. 9,
  123491. 9
  123492. };
  123493. static static_codebook _44c0_sm_p3_0 = {
  123494. 2, 81,
  123495. _vq_lengthlist__44c0_sm_p3_0,
  123496. 1, -531628032, 1611661312, 4, 0,
  123497. _vq_quantlist__44c0_sm_p3_0,
  123498. NULL,
  123499. &_vq_auxt__44c0_sm_p3_0,
  123500. NULL,
  123501. 0
  123502. };
  123503. static long _vq_quantlist__44c0_sm_p4_0[] = {
  123504. 4,
  123505. 3,
  123506. 5,
  123507. 2,
  123508. 6,
  123509. 1,
  123510. 7,
  123511. 0,
  123512. 8,
  123513. };
  123514. static long _vq_lengthlist__44c0_sm_p4_0[] = {
  123515. 1, 4, 3, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 8, 7,
  123516. 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  123517. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  123518. 9, 9, 9, 9,11,11, 0, 0, 0, 9, 9, 9, 9,11,11, 0,
  123519. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  123520. 11,
  123521. };
  123522. static float _vq_quantthresh__44c0_sm_p4_0[] = {
  123523. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  123524. };
  123525. static long _vq_quantmap__44c0_sm_p4_0[] = {
  123526. 7, 5, 3, 1, 0, 2, 4, 6,
  123527. 8,
  123528. };
  123529. static encode_aux_threshmatch _vq_auxt__44c0_sm_p4_0 = {
  123530. _vq_quantthresh__44c0_sm_p4_0,
  123531. _vq_quantmap__44c0_sm_p4_0,
  123532. 9,
  123533. 9
  123534. };
  123535. static static_codebook _44c0_sm_p4_0 = {
  123536. 2, 81,
  123537. _vq_lengthlist__44c0_sm_p4_0,
  123538. 1, -531628032, 1611661312, 4, 0,
  123539. _vq_quantlist__44c0_sm_p4_0,
  123540. NULL,
  123541. &_vq_auxt__44c0_sm_p4_0,
  123542. NULL,
  123543. 0
  123544. };
  123545. static long _vq_quantlist__44c0_sm_p5_0[] = {
  123546. 8,
  123547. 7,
  123548. 9,
  123549. 6,
  123550. 10,
  123551. 5,
  123552. 11,
  123553. 4,
  123554. 12,
  123555. 3,
  123556. 13,
  123557. 2,
  123558. 14,
  123559. 1,
  123560. 15,
  123561. 0,
  123562. 16,
  123563. };
  123564. static long _vq_lengthlist__44c0_sm_p5_0[] = {
  123565. 1, 4, 4, 6, 6, 8, 8, 8, 8, 8, 8, 9, 9,10,10,11,
  123566. 11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,11,
  123567. 11,11, 0, 5, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  123568. 11,11,11, 0, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,
  123569. 11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,
  123570. 10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  123571. 11,11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  123572. 10,11,11,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  123573. 10,10,11,11,12,12,12,13, 0, 0, 0, 0, 0, 9, 9,10,
  123574. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  123575. 10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  123576. 9,10,10,11,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  123577. 10,10,10,10,11,11,12,12,12,13,13,13, 0, 0, 0, 0,
  123578. 0, 0, 0,10,10,11,11,12,12,12,13,13,13, 0, 0, 0,
  123579. 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14, 0, 0,
  123580. 0, 0, 0, 0, 0,11,11,12,11,12,12,13,13,13,13, 0,
  123581. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  123582. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  123583. 14,
  123584. };
  123585. static float _vq_quantthresh__44c0_sm_p5_0[] = {
  123586. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  123587. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  123588. };
  123589. static long _vq_quantmap__44c0_sm_p5_0[] = {
  123590. 15, 13, 11, 9, 7, 5, 3, 1,
  123591. 0, 2, 4, 6, 8, 10, 12, 14,
  123592. 16,
  123593. };
  123594. static encode_aux_threshmatch _vq_auxt__44c0_sm_p5_0 = {
  123595. _vq_quantthresh__44c0_sm_p5_0,
  123596. _vq_quantmap__44c0_sm_p5_0,
  123597. 17,
  123598. 17
  123599. };
  123600. static static_codebook _44c0_sm_p5_0 = {
  123601. 2, 289,
  123602. _vq_lengthlist__44c0_sm_p5_0,
  123603. 1, -529530880, 1611661312, 5, 0,
  123604. _vq_quantlist__44c0_sm_p5_0,
  123605. NULL,
  123606. &_vq_auxt__44c0_sm_p5_0,
  123607. NULL,
  123608. 0
  123609. };
  123610. static long _vq_quantlist__44c0_sm_p6_0[] = {
  123611. 1,
  123612. 0,
  123613. 2,
  123614. };
  123615. static long _vq_lengthlist__44c0_sm_p6_0[] = {
  123616. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  123617. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,10,11,
  123618. 11,11,10,10, 6, 9, 9,11,11,10,11,10,10, 6, 9, 9,
  123619. 11,10,11,11,10,10, 7,11,10,11,11,11,11,11,11, 6,
  123620. 9, 9,11,10,10,11,11,10, 6, 9, 9,11,10,10,11,10,
  123621. 11,
  123622. };
  123623. static float _vq_quantthresh__44c0_sm_p6_0[] = {
  123624. -5.5, 5.5,
  123625. };
  123626. static long _vq_quantmap__44c0_sm_p6_0[] = {
  123627. 1, 0, 2,
  123628. };
  123629. static encode_aux_threshmatch _vq_auxt__44c0_sm_p6_0 = {
  123630. _vq_quantthresh__44c0_sm_p6_0,
  123631. _vq_quantmap__44c0_sm_p6_0,
  123632. 3,
  123633. 3
  123634. };
  123635. static static_codebook _44c0_sm_p6_0 = {
  123636. 4, 81,
  123637. _vq_lengthlist__44c0_sm_p6_0,
  123638. 1, -529137664, 1618345984, 2, 0,
  123639. _vq_quantlist__44c0_sm_p6_0,
  123640. NULL,
  123641. &_vq_auxt__44c0_sm_p6_0,
  123642. NULL,
  123643. 0
  123644. };
  123645. static long _vq_quantlist__44c0_sm_p6_1[] = {
  123646. 5,
  123647. 4,
  123648. 6,
  123649. 3,
  123650. 7,
  123651. 2,
  123652. 8,
  123653. 1,
  123654. 9,
  123655. 0,
  123656. 10,
  123657. };
  123658. static long _vq_lengthlist__44c0_sm_p6_1[] = {
  123659. 2, 4, 4, 6, 6, 7, 7, 7, 7, 7, 8, 9, 5, 5, 6, 6,
  123660. 7, 7, 8, 8, 8, 8, 9, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  123661. 8,10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  123662. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  123663. 8, 8,10,10,10, 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  123664. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  123665. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  123666. 10,10,10, 8, 8, 8, 8, 8, 8,
  123667. };
  123668. static float _vq_quantthresh__44c0_sm_p6_1[] = {
  123669. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  123670. 3.5, 4.5,
  123671. };
  123672. static long _vq_quantmap__44c0_sm_p6_1[] = {
  123673. 9, 7, 5, 3, 1, 0, 2, 4,
  123674. 6, 8, 10,
  123675. };
  123676. static encode_aux_threshmatch _vq_auxt__44c0_sm_p6_1 = {
  123677. _vq_quantthresh__44c0_sm_p6_1,
  123678. _vq_quantmap__44c0_sm_p6_1,
  123679. 11,
  123680. 11
  123681. };
  123682. static static_codebook _44c0_sm_p6_1 = {
  123683. 2, 121,
  123684. _vq_lengthlist__44c0_sm_p6_1,
  123685. 1, -531365888, 1611661312, 4, 0,
  123686. _vq_quantlist__44c0_sm_p6_1,
  123687. NULL,
  123688. &_vq_auxt__44c0_sm_p6_1,
  123689. NULL,
  123690. 0
  123691. };
  123692. static long _vq_quantlist__44c0_sm_p7_0[] = {
  123693. 6,
  123694. 5,
  123695. 7,
  123696. 4,
  123697. 8,
  123698. 3,
  123699. 9,
  123700. 2,
  123701. 10,
  123702. 1,
  123703. 11,
  123704. 0,
  123705. 12,
  123706. };
  123707. static long _vq_lengthlist__44c0_sm_p7_0[] = {
  123708. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 5, 5,
  123709. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 6, 5, 7, 7, 8,
  123710. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  123711. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  123712. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  123713. 13, 9, 9, 9, 9,10,10,11,11,11,12, 0, 0, 0, 9,10,
  123714. 10,10,11,11,12,11,12,12, 0, 0, 0,10,10, 9, 9,11,
  123715. 11,12,12,12,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  123716. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  123717. 0, 0, 0, 0,11,12,11,11,13,12,13,13, 0, 0, 0, 0,
  123718. 0,12,12,11,11,13,12,14,14,
  123719. };
  123720. static float _vq_quantthresh__44c0_sm_p7_0[] = {
  123721. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  123722. 12.5, 17.5, 22.5, 27.5,
  123723. };
  123724. static long _vq_quantmap__44c0_sm_p7_0[] = {
  123725. 11, 9, 7, 5, 3, 1, 0, 2,
  123726. 4, 6, 8, 10, 12,
  123727. };
  123728. static encode_aux_threshmatch _vq_auxt__44c0_sm_p7_0 = {
  123729. _vq_quantthresh__44c0_sm_p7_0,
  123730. _vq_quantmap__44c0_sm_p7_0,
  123731. 13,
  123732. 13
  123733. };
  123734. static static_codebook _44c0_sm_p7_0 = {
  123735. 2, 169,
  123736. _vq_lengthlist__44c0_sm_p7_0,
  123737. 1, -526516224, 1616117760, 4, 0,
  123738. _vq_quantlist__44c0_sm_p7_0,
  123739. NULL,
  123740. &_vq_auxt__44c0_sm_p7_0,
  123741. NULL,
  123742. 0
  123743. };
  123744. static long _vq_quantlist__44c0_sm_p7_1[] = {
  123745. 2,
  123746. 1,
  123747. 3,
  123748. 0,
  123749. 4,
  123750. };
  123751. static long _vq_lengthlist__44c0_sm_p7_1[] = {
  123752. 2, 4, 4, 4, 4, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  123753. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  123754. };
  123755. static float _vq_quantthresh__44c0_sm_p7_1[] = {
  123756. -1.5, -0.5, 0.5, 1.5,
  123757. };
  123758. static long _vq_quantmap__44c0_sm_p7_1[] = {
  123759. 3, 1, 0, 2, 4,
  123760. };
  123761. static encode_aux_threshmatch _vq_auxt__44c0_sm_p7_1 = {
  123762. _vq_quantthresh__44c0_sm_p7_1,
  123763. _vq_quantmap__44c0_sm_p7_1,
  123764. 5,
  123765. 5
  123766. };
  123767. static static_codebook _44c0_sm_p7_1 = {
  123768. 2, 25,
  123769. _vq_lengthlist__44c0_sm_p7_1,
  123770. 1, -533725184, 1611661312, 3, 0,
  123771. _vq_quantlist__44c0_sm_p7_1,
  123772. NULL,
  123773. &_vq_auxt__44c0_sm_p7_1,
  123774. NULL,
  123775. 0
  123776. };
  123777. static long _vq_quantlist__44c0_sm_p8_0[] = {
  123778. 4,
  123779. 3,
  123780. 5,
  123781. 2,
  123782. 6,
  123783. 1,
  123784. 7,
  123785. 0,
  123786. 8,
  123787. };
  123788. static long _vq_lengthlist__44c0_sm_p8_0[] = {
  123789. 1, 3, 3,11,11,11,11,11,11, 3, 7, 6,11,11,11,11,
  123790. 11,11, 4, 8, 7,11,11,11,11,11,11,11,11,11,11,11,
  123791. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123792. 11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  123793. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  123794. 12,
  123795. };
  123796. static float _vq_quantthresh__44c0_sm_p8_0[] = {
  123797. -773.5, -552.5, -331.5, -110.5, 110.5, 331.5, 552.5, 773.5,
  123798. };
  123799. static long _vq_quantmap__44c0_sm_p8_0[] = {
  123800. 7, 5, 3, 1, 0, 2, 4, 6,
  123801. 8,
  123802. };
  123803. static encode_aux_threshmatch _vq_auxt__44c0_sm_p8_0 = {
  123804. _vq_quantthresh__44c0_sm_p8_0,
  123805. _vq_quantmap__44c0_sm_p8_0,
  123806. 9,
  123807. 9
  123808. };
  123809. static static_codebook _44c0_sm_p8_0 = {
  123810. 2, 81,
  123811. _vq_lengthlist__44c0_sm_p8_0,
  123812. 1, -516186112, 1627103232, 4, 0,
  123813. _vq_quantlist__44c0_sm_p8_0,
  123814. NULL,
  123815. &_vq_auxt__44c0_sm_p8_0,
  123816. NULL,
  123817. 0
  123818. };
  123819. static long _vq_quantlist__44c0_sm_p8_1[] = {
  123820. 6,
  123821. 5,
  123822. 7,
  123823. 4,
  123824. 8,
  123825. 3,
  123826. 9,
  123827. 2,
  123828. 10,
  123829. 1,
  123830. 11,
  123831. 0,
  123832. 12,
  123833. };
  123834. static long _vq_lengthlist__44c0_sm_p8_1[] = {
  123835. 1, 4, 4, 6, 6, 7, 7, 9, 9,10,11,12,12, 6, 5, 5,
  123836. 7, 7, 8, 8,10,10,12,11,12,12, 6, 5, 5, 7, 7, 8,
  123837. 8,10,10,12,11,12,12,17, 7, 7, 8, 8, 9, 9,10,10,
  123838. 12,12,13,13,18, 7, 7, 8, 7, 9, 9,10,10,12,12,12,
  123839. 13,19,10,10, 8, 8,10,10,11,11,12,12,13,14,19,11,
  123840. 10, 8, 7,10,10,11,11,12,12,13,12,19,19,19,10,10,
  123841. 10,10,11,11,12,12,13,13,19,19,19,11, 9,11, 9,14,
  123842. 12,13,12,13,13,19,20,18,13,14,11,11,12,12,13,13,
  123843. 14,13,20,20,20,15,13,11,10,13,11,13,13,14,13,20,
  123844. 20,20,20,20,13,14,12,12,13,13,13,13,20,20,20,20,
  123845. 20,13,13,12,12,16,13,15,13,
  123846. };
  123847. static float _vq_quantthresh__44c0_sm_p8_1[] = {
  123848. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  123849. 42.5, 59.5, 76.5, 93.5,
  123850. };
  123851. static long _vq_quantmap__44c0_sm_p8_1[] = {
  123852. 11, 9, 7, 5, 3, 1, 0, 2,
  123853. 4, 6, 8, 10, 12,
  123854. };
  123855. static encode_aux_threshmatch _vq_auxt__44c0_sm_p8_1 = {
  123856. _vq_quantthresh__44c0_sm_p8_1,
  123857. _vq_quantmap__44c0_sm_p8_1,
  123858. 13,
  123859. 13
  123860. };
  123861. static static_codebook _44c0_sm_p8_1 = {
  123862. 2, 169,
  123863. _vq_lengthlist__44c0_sm_p8_1,
  123864. 1, -522616832, 1620115456, 4, 0,
  123865. _vq_quantlist__44c0_sm_p8_1,
  123866. NULL,
  123867. &_vq_auxt__44c0_sm_p8_1,
  123868. NULL,
  123869. 0
  123870. };
  123871. static long _vq_quantlist__44c0_sm_p8_2[] = {
  123872. 8,
  123873. 7,
  123874. 9,
  123875. 6,
  123876. 10,
  123877. 5,
  123878. 11,
  123879. 4,
  123880. 12,
  123881. 3,
  123882. 13,
  123883. 2,
  123884. 14,
  123885. 1,
  123886. 15,
  123887. 0,
  123888. 16,
  123889. };
  123890. static long _vq_lengthlist__44c0_sm_p8_2[] = {
  123891. 2, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  123892. 8,10, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  123893. 9, 9,10, 6, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  123894. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  123895. 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 9, 8, 9, 9, 9,
  123896. 9,10, 9, 9,10,10,10,11, 8, 8, 8, 8, 9, 9, 9, 9,
  123897. 9, 9, 9,10, 9,10,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  123898. 9, 9, 9, 9, 9,10,10,11,10,10, 8, 8, 9, 9, 9, 9,
  123899. 9, 9, 9, 9, 9, 9,10,10,10,10,10,11,11, 8, 8, 9,
  123900. 9, 9, 9, 9, 9, 9, 9, 9,10,11,11,11,11,11, 9, 9,
  123901. 9, 9, 9, 9, 9, 9,10, 9,10, 9,11,11,10,11,11, 9,
  123902. 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,11,10,11,11,
  123903. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,10,11,11,
  123904. 11,11,11, 9, 9,10, 9, 9, 9, 9, 9, 9, 9,10,11,10,
  123905. 11,11,11,11,10,10,10,10, 9, 9, 9, 9, 9, 9,10,11,
  123906. 11,11,11,11,11, 9,10, 9, 9, 9, 9, 9, 9, 9, 9,11,
  123907. 11,10,11,11,11,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  123908. 10,11,10,11,11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9,
  123909. 9,
  123910. };
  123911. static float _vq_quantthresh__44c0_sm_p8_2[] = {
  123912. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  123913. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  123914. };
  123915. static long _vq_quantmap__44c0_sm_p8_2[] = {
  123916. 15, 13, 11, 9, 7, 5, 3, 1,
  123917. 0, 2, 4, 6, 8, 10, 12, 14,
  123918. 16,
  123919. };
  123920. static encode_aux_threshmatch _vq_auxt__44c0_sm_p8_2 = {
  123921. _vq_quantthresh__44c0_sm_p8_2,
  123922. _vq_quantmap__44c0_sm_p8_2,
  123923. 17,
  123924. 17
  123925. };
  123926. static static_codebook _44c0_sm_p8_2 = {
  123927. 2, 289,
  123928. _vq_lengthlist__44c0_sm_p8_2,
  123929. 1, -529530880, 1611661312, 5, 0,
  123930. _vq_quantlist__44c0_sm_p8_2,
  123931. NULL,
  123932. &_vq_auxt__44c0_sm_p8_2,
  123933. NULL,
  123934. 0
  123935. };
  123936. static long _huff_lengthlist__44c0_sm_short[] = {
  123937. 6, 6,12,13,13,14,16,17,17, 4, 2, 5, 8, 7, 9,12,
  123938. 15,15, 9, 4, 5, 9, 7, 9,12,16,18,11, 6, 7, 4, 6,
  123939. 8,11,14,18,10, 5, 6, 5, 5, 7,10,14,17,10, 5, 7,
  123940. 7, 6, 7,10,13,16,11, 5, 7, 7, 7, 8,10,12,15,13,
  123941. 6, 7, 5, 5, 7, 9,12,13,16, 8, 9, 6, 6, 7, 9,10,
  123942. 12,
  123943. };
  123944. static static_codebook _huff_book__44c0_sm_short = {
  123945. 2, 81,
  123946. _huff_lengthlist__44c0_sm_short,
  123947. 0, 0, 0, 0, 0,
  123948. NULL,
  123949. NULL,
  123950. NULL,
  123951. NULL,
  123952. 0
  123953. };
  123954. static long _huff_lengthlist__44c1_s_long[] = {
  123955. 5, 5, 9,10, 9, 9,10,11,12, 5, 1, 5, 6, 6, 7,10,
  123956. 12,14, 9, 5, 6, 8, 8,10,12,14,14,10, 5, 8, 5, 6,
  123957. 8,11,13,14, 9, 5, 7, 6, 6, 8,10,12,11, 9, 7, 9,
  123958. 7, 6, 6, 7,10,10,10, 9,12, 9, 8, 7, 7,10,12,11,
  123959. 11,13,12,10, 9, 8, 9,11,11,14,15,15,13,11, 9, 9,
  123960. 11,
  123961. };
  123962. static static_codebook _huff_book__44c1_s_long = {
  123963. 2, 81,
  123964. _huff_lengthlist__44c1_s_long,
  123965. 0, 0, 0, 0, 0,
  123966. NULL,
  123967. NULL,
  123968. NULL,
  123969. NULL,
  123970. 0
  123971. };
  123972. static long _vq_quantlist__44c1_s_p1_0[] = {
  123973. 1,
  123974. 0,
  123975. 2,
  123976. };
  123977. static long _vq_lengthlist__44c1_s_p1_0[] = {
  123978. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 7, 6, 0, 0, 0, 0,
  123979. 0, 0, 5, 6, 7, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  123984. 0, 0, 0, 7, 8, 8, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  123989. 0, 0, 0, 0, 7, 8, 8, 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, 4, 7, 7, 0, 0, 0, 0,
  124024. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 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, 7, 8, 8, 0, 0, 0,
  124029. 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 6, 8, 8, 0, 0,
  124034. 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  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, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  124070. 0, 0, 0, 0, 7, 8, 9, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8,10, 9, 0,
  124075. 0, 0, 0, 0, 0, 8, 8, 9, 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, 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  124080. 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  124081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124388. 0,
  124389. };
  124390. static float _vq_quantthresh__44c1_s_p1_0[] = {
  124391. -0.5, 0.5,
  124392. };
  124393. static long _vq_quantmap__44c1_s_p1_0[] = {
  124394. 1, 0, 2,
  124395. };
  124396. static encode_aux_threshmatch _vq_auxt__44c1_s_p1_0 = {
  124397. _vq_quantthresh__44c1_s_p1_0,
  124398. _vq_quantmap__44c1_s_p1_0,
  124399. 3,
  124400. 3
  124401. };
  124402. static static_codebook _44c1_s_p1_0 = {
  124403. 8, 6561,
  124404. _vq_lengthlist__44c1_s_p1_0,
  124405. 1, -535822336, 1611661312, 2, 0,
  124406. _vq_quantlist__44c1_s_p1_0,
  124407. NULL,
  124408. &_vq_auxt__44c1_s_p1_0,
  124409. NULL,
  124410. 0
  124411. };
  124412. static long _vq_quantlist__44c1_s_p2_0[] = {
  124413. 2,
  124414. 1,
  124415. 3,
  124416. 0,
  124417. 4,
  124418. };
  124419. static long _vq_lengthlist__44c1_s_p2_0[] = {
  124420. 2, 3, 4, 6, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  124422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124423. 0, 0, 4, 4, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 8, 8,
  124425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124426. 0, 0, 0, 0, 6, 6, 6, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  124427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124459. 0,
  124460. };
  124461. static float _vq_quantthresh__44c1_s_p2_0[] = {
  124462. -1.5, -0.5, 0.5, 1.5,
  124463. };
  124464. static long _vq_quantmap__44c1_s_p2_0[] = {
  124465. 3, 1, 0, 2, 4,
  124466. };
  124467. static encode_aux_threshmatch _vq_auxt__44c1_s_p2_0 = {
  124468. _vq_quantthresh__44c1_s_p2_0,
  124469. _vq_quantmap__44c1_s_p2_0,
  124470. 5,
  124471. 5
  124472. };
  124473. static static_codebook _44c1_s_p2_0 = {
  124474. 4, 625,
  124475. _vq_lengthlist__44c1_s_p2_0,
  124476. 1, -533725184, 1611661312, 3, 0,
  124477. _vq_quantlist__44c1_s_p2_0,
  124478. NULL,
  124479. &_vq_auxt__44c1_s_p2_0,
  124480. NULL,
  124481. 0
  124482. };
  124483. static long _vq_quantlist__44c1_s_p3_0[] = {
  124484. 4,
  124485. 3,
  124486. 5,
  124487. 2,
  124488. 6,
  124489. 1,
  124490. 7,
  124491. 0,
  124492. 8,
  124493. };
  124494. static long _vq_lengthlist__44c1_s_p3_0[] = {
  124495. 1, 3, 2, 7, 7, 0, 0, 0, 0, 0,13,13, 6, 6, 0, 0,
  124496. 0, 0, 0,12, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  124497. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  124498. 8, 9, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  124499. 0, 0,11,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124500. 0,
  124501. };
  124502. static float _vq_quantthresh__44c1_s_p3_0[] = {
  124503. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  124504. };
  124505. static long _vq_quantmap__44c1_s_p3_0[] = {
  124506. 7, 5, 3, 1, 0, 2, 4, 6,
  124507. 8,
  124508. };
  124509. static encode_aux_threshmatch _vq_auxt__44c1_s_p3_0 = {
  124510. _vq_quantthresh__44c1_s_p3_0,
  124511. _vq_quantmap__44c1_s_p3_0,
  124512. 9,
  124513. 9
  124514. };
  124515. static static_codebook _44c1_s_p3_0 = {
  124516. 2, 81,
  124517. _vq_lengthlist__44c1_s_p3_0,
  124518. 1, -531628032, 1611661312, 4, 0,
  124519. _vq_quantlist__44c1_s_p3_0,
  124520. NULL,
  124521. &_vq_auxt__44c1_s_p3_0,
  124522. NULL,
  124523. 0
  124524. };
  124525. static long _vq_quantlist__44c1_s_p4_0[] = {
  124526. 4,
  124527. 3,
  124528. 5,
  124529. 2,
  124530. 6,
  124531. 1,
  124532. 7,
  124533. 0,
  124534. 8,
  124535. };
  124536. static long _vq_lengthlist__44c1_s_p4_0[] = {
  124537. 1, 3, 3, 6, 5, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  124538. 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  124539. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  124540. 9, 9, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  124541. 0, 0,10,10, 9, 9,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  124542. 11,
  124543. };
  124544. static float _vq_quantthresh__44c1_s_p4_0[] = {
  124545. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  124546. };
  124547. static long _vq_quantmap__44c1_s_p4_0[] = {
  124548. 7, 5, 3, 1, 0, 2, 4, 6,
  124549. 8,
  124550. };
  124551. static encode_aux_threshmatch _vq_auxt__44c1_s_p4_0 = {
  124552. _vq_quantthresh__44c1_s_p4_0,
  124553. _vq_quantmap__44c1_s_p4_0,
  124554. 9,
  124555. 9
  124556. };
  124557. static static_codebook _44c1_s_p4_0 = {
  124558. 2, 81,
  124559. _vq_lengthlist__44c1_s_p4_0,
  124560. 1, -531628032, 1611661312, 4, 0,
  124561. _vq_quantlist__44c1_s_p4_0,
  124562. NULL,
  124563. &_vq_auxt__44c1_s_p4_0,
  124564. NULL,
  124565. 0
  124566. };
  124567. static long _vq_quantlist__44c1_s_p5_0[] = {
  124568. 8,
  124569. 7,
  124570. 9,
  124571. 6,
  124572. 10,
  124573. 5,
  124574. 11,
  124575. 4,
  124576. 12,
  124577. 3,
  124578. 13,
  124579. 2,
  124580. 14,
  124581. 1,
  124582. 15,
  124583. 0,
  124584. 16,
  124585. };
  124586. static long _vq_lengthlist__44c1_s_p5_0[] = {
  124587. 1, 4, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  124588. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,
  124589. 11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  124590. 10,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  124591. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  124592. 10,11,11,12,11, 0, 0, 0, 8, 8, 9, 9, 9,10,10,10,
  124593. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10, 9,10,
  124594. 10,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  124595. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  124596. 10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,
  124597. 10,10,10,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  124598. 9,10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  124599. 10,10,10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0,
  124600. 0, 0, 0,10,10,11,11,12,12,12,12,13,13, 0, 0, 0,
  124601. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,13, 0, 0,
  124602. 0, 0, 0, 0, 0,11,11,11,11,12,12,13,13,13,13, 0,
  124603. 0, 0, 0, 0, 0, 0,12,12,12,12,12,12,13,13,14,14,
  124604. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  124605. 14,
  124606. };
  124607. static float _vq_quantthresh__44c1_s_p5_0[] = {
  124608. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  124609. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  124610. };
  124611. static long _vq_quantmap__44c1_s_p5_0[] = {
  124612. 15, 13, 11, 9, 7, 5, 3, 1,
  124613. 0, 2, 4, 6, 8, 10, 12, 14,
  124614. 16,
  124615. };
  124616. static encode_aux_threshmatch _vq_auxt__44c1_s_p5_0 = {
  124617. _vq_quantthresh__44c1_s_p5_0,
  124618. _vq_quantmap__44c1_s_p5_0,
  124619. 17,
  124620. 17
  124621. };
  124622. static static_codebook _44c1_s_p5_0 = {
  124623. 2, 289,
  124624. _vq_lengthlist__44c1_s_p5_0,
  124625. 1, -529530880, 1611661312, 5, 0,
  124626. _vq_quantlist__44c1_s_p5_0,
  124627. NULL,
  124628. &_vq_auxt__44c1_s_p5_0,
  124629. NULL,
  124630. 0
  124631. };
  124632. static long _vq_quantlist__44c1_s_p6_0[] = {
  124633. 1,
  124634. 0,
  124635. 2,
  124636. };
  124637. static long _vq_lengthlist__44c1_s_p6_0[] = {
  124638. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  124639. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 6,10,10,11,11,
  124640. 11,11,10,10, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  124641. 11,10,11,11,10,10, 7,11,10,11,11,11,12,11,11, 7,
  124642. 9, 9,11,10,10,11,11,10, 6, 9, 9,10,10,10,12,10,
  124643. 11,
  124644. };
  124645. static float _vq_quantthresh__44c1_s_p6_0[] = {
  124646. -5.5, 5.5,
  124647. };
  124648. static long _vq_quantmap__44c1_s_p6_0[] = {
  124649. 1, 0, 2,
  124650. };
  124651. static encode_aux_threshmatch _vq_auxt__44c1_s_p6_0 = {
  124652. _vq_quantthresh__44c1_s_p6_0,
  124653. _vq_quantmap__44c1_s_p6_0,
  124654. 3,
  124655. 3
  124656. };
  124657. static static_codebook _44c1_s_p6_0 = {
  124658. 4, 81,
  124659. _vq_lengthlist__44c1_s_p6_0,
  124660. 1, -529137664, 1618345984, 2, 0,
  124661. _vq_quantlist__44c1_s_p6_0,
  124662. NULL,
  124663. &_vq_auxt__44c1_s_p6_0,
  124664. NULL,
  124665. 0
  124666. };
  124667. static long _vq_quantlist__44c1_s_p6_1[] = {
  124668. 5,
  124669. 4,
  124670. 6,
  124671. 3,
  124672. 7,
  124673. 2,
  124674. 8,
  124675. 1,
  124676. 9,
  124677. 0,
  124678. 10,
  124679. };
  124680. static long _vq_lengthlist__44c1_s_p6_1[] = {
  124681. 2, 3, 3, 6, 6, 7, 7, 7, 7, 8, 8,10,10,10, 6, 6,
  124682. 7, 7, 8, 8, 8, 8,10,10,10, 6, 6, 7, 7, 8, 8, 8,
  124683. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  124684. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  124685. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  124686. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  124687. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  124688. 10,10,10, 8, 8, 8, 8, 8, 8,
  124689. };
  124690. static float _vq_quantthresh__44c1_s_p6_1[] = {
  124691. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  124692. 3.5, 4.5,
  124693. };
  124694. static long _vq_quantmap__44c1_s_p6_1[] = {
  124695. 9, 7, 5, 3, 1, 0, 2, 4,
  124696. 6, 8, 10,
  124697. };
  124698. static encode_aux_threshmatch _vq_auxt__44c1_s_p6_1 = {
  124699. _vq_quantthresh__44c1_s_p6_1,
  124700. _vq_quantmap__44c1_s_p6_1,
  124701. 11,
  124702. 11
  124703. };
  124704. static static_codebook _44c1_s_p6_1 = {
  124705. 2, 121,
  124706. _vq_lengthlist__44c1_s_p6_1,
  124707. 1, -531365888, 1611661312, 4, 0,
  124708. _vq_quantlist__44c1_s_p6_1,
  124709. NULL,
  124710. &_vq_auxt__44c1_s_p6_1,
  124711. NULL,
  124712. 0
  124713. };
  124714. static long _vq_quantlist__44c1_s_p7_0[] = {
  124715. 6,
  124716. 5,
  124717. 7,
  124718. 4,
  124719. 8,
  124720. 3,
  124721. 9,
  124722. 2,
  124723. 10,
  124724. 1,
  124725. 11,
  124726. 0,
  124727. 12,
  124728. };
  124729. static long _vq_lengthlist__44c1_s_p7_0[] = {
  124730. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 9, 7, 5, 6,
  124731. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 5, 7, 7, 8,
  124732. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  124733. 10,10,11,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  124734. 11, 0,12,12, 9, 9, 9,10,10,10,11,11,11,11, 0,13,
  124735. 13, 9, 9, 9, 9,10,10,11,11,11,11, 0, 0, 0,10,10,
  124736. 10,10,11,11,12,11,12,12, 0, 0, 0,10,10,10, 9,11,
  124737. 11,12,11,13,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  124738. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  124739. 0, 0, 0, 0,11,12,11,11,12,12,14,13, 0, 0, 0, 0,
  124740. 0,12,11,11,11,13,10,14,13,
  124741. };
  124742. static float _vq_quantthresh__44c1_s_p7_0[] = {
  124743. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  124744. 12.5, 17.5, 22.5, 27.5,
  124745. };
  124746. static long _vq_quantmap__44c1_s_p7_0[] = {
  124747. 11, 9, 7, 5, 3, 1, 0, 2,
  124748. 4, 6, 8, 10, 12,
  124749. };
  124750. static encode_aux_threshmatch _vq_auxt__44c1_s_p7_0 = {
  124751. _vq_quantthresh__44c1_s_p7_0,
  124752. _vq_quantmap__44c1_s_p7_0,
  124753. 13,
  124754. 13
  124755. };
  124756. static static_codebook _44c1_s_p7_0 = {
  124757. 2, 169,
  124758. _vq_lengthlist__44c1_s_p7_0,
  124759. 1, -526516224, 1616117760, 4, 0,
  124760. _vq_quantlist__44c1_s_p7_0,
  124761. NULL,
  124762. &_vq_auxt__44c1_s_p7_0,
  124763. NULL,
  124764. 0
  124765. };
  124766. static long _vq_quantlist__44c1_s_p7_1[] = {
  124767. 2,
  124768. 1,
  124769. 3,
  124770. 0,
  124771. 4,
  124772. };
  124773. static long _vq_lengthlist__44c1_s_p7_1[] = {
  124774. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  124775. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  124776. };
  124777. static float _vq_quantthresh__44c1_s_p7_1[] = {
  124778. -1.5, -0.5, 0.5, 1.5,
  124779. };
  124780. static long _vq_quantmap__44c1_s_p7_1[] = {
  124781. 3, 1, 0, 2, 4,
  124782. };
  124783. static encode_aux_threshmatch _vq_auxt__44c1_s_p7_1 = {
  124784. _vq_quantthresh__44c1_s_p7_1,
  124785. _vq_quantmap__44c1_s_p7_1,
  124786. 5,
  124787. 5
  124788. };
  124789. static static_codebook _44c1_s_p7_1 = {
  124790. 2, 25,
  124791. _vq_lengthlist__44c1_s_p7_1,
  124792. 1, -533725184, 1611661312, 3, 0,
  124793. _vq_quantlist__44c1_s_p7_1,
  124794. NULL,
  124795. &_vq_auxt__44c1_s_p7_1,
  124796. NULL,
  124797. 0
  124798. };
  124799. static long _vq_quantlist__44c1_s_p8_0[] = {
  124800. 6,
  124801. 5,
  124802. 7,
  124803. 4,
  124804. 8,
  124805. 3,
  124806. 9,
  124807. 2,
  124808. 10,
  124809. 1,
  124810. 11,
  124811. 0,
  124812. 12,
  124813. };
  124814. static long _vq_lengthlist__44c1_s_p8_0[] = {
  124815. 1, 4, 3,10,10,10,10,10,10,10,10,10,10, 4, 8, 6,
  124816. 10,10,10,10,10,10,10,10,10,10, 4, 8, 7,10,10,10,
  124817. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124818. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124819. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124820. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124821. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124822. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124823. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124824. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124825. 10,10,10,10,10,10,10,10,10,
  124826. };
  124827. static float _vq_quantthresh__44c1_s_p8_0[] = {
  124828. -1215.5, -994.5, -773.5, -552.5, -331.5, -110.5, 110.5, 331.5,
  124829. 552.5, 773.5, 994.5, 1215.5,
  124830. };
  124831. static long _vq_quantmap__44c1_s_p8_0[] = {
  124832. 11, 9, 7, 5, 3, 1, 0, 2,
  124833. 4, 6, 8, 10, 12,
  124834. };
  124835. static encode_aux_threshmatch _vq_auxt__44c1_s_p8_0 = {
  124836. _vq_quantthresh__44c1_s_p8_0,
  124837. _vq_quantmap__44c1_s_p8_0,
  124838. 13,
  124839. 13
  124840. };
  124841. static static_codebook _44c1_s_p8_0 = {
  124842. 2, 169,
  124843. _vq_lengthlist__44c1_s_p8_0,
  124844. 1, -514541568, 1627103232, 4, 0,
  124845. _vq_quantlist__44c1_s_p8_0,
  124846. NULL,
  124847. &_vq_auxt__44c1_s_p8_0,
  124848. NULL,
  124849. 0
  124850. };
  124851. static long _vq_quantlist__44c1_s_p8_1[] = {
  124852. 6,
  124853. 5,
  124854. 7,
  124855. 4,
  124856. 8,
  124857. 3,
  124858. 9,
  124859. 2,
  124860. 10,
  124861. 1,
  124862. 11,
  124863. 0,
  124864. 12,
  124865. };
  124866. static long _vq_lengthlist__44c1_s_p8_1[] = {
  124867. 1, 4, 4, 6, 5, 7, 7, 9, 9,10,10,12,12, 6, 5, 5,
  124868. 7, 7, 8, 8,10,10,12,11,12,12, 6, 5, 5, 7, 7, 8,
  124869. 8,10,10,11,11,12,12,15, 7, 7, 8, 8, 9, 9,11,11,
  124870. 12,12,13,12,15, 8, 8, 8, 7, 9, 9,10,10,12,12,13,
  124871. 13,16,11,10, 8, 8,10,10,11,11,12,12,13,13,16,11,
  124872. 11, 9, 8,11,10,11,11,12,12,13,12,16,16,16,10,11,
  124873. 10,11,12,12,12,12,13,13,16,16,16,11, 9,11, 9,14,
  124874. 12,12,12,13,13,16,16,16,12,14,11,12,12,12,13,13,
  124875. 14,13,16,16,16,15,13,12,10,13,10,13,14,13,13,16,
  124876. 16,16,16,16,13,14,12,13,13,12,13,13,16,16,16,16,
  124877. 16,13,12,12,11,14,12,15,13,
  124878. };
  124879. static float _vq_quantthresh__44c1_s_p8_1[] = {
  124880. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  124881. 42.5, 59.5, 76.5, 93.5,
  124882. };
  124883. static long _vq_quantmap__44c1_s_p8_1[] = {
  124884. 11, 9, 7, 5, 3, 1, 0, 2,
  124885. 4, 6, 8, 10, 12,
  124886. };
  124887. static encode_aux_threshmatch _vq_auxt__44c1_s_p8_1 = {
  124888. _vq_quantthresh__44c1_s_p8_1,
  124889. _vq_quantmap__44c1_s_p8_1,
  124890. 13,
  124891. 13
  124892. };
  124893. static static_codebook _44c1_s_p8_1 = {
  124894. 2, 169,
  124895. _vq_lengthlist__44c1_s_p8_1,
  124896. 1, -522616832, 1620115456, 4, 0,
  124897. _vq_quantlist__44c1_s_p8_1,
  124898. NULL,
  124899. &_vq_auxt__44c1_s_p8_1,
  124900. NULL,
  124901. 0
  124902. };
  124903. static long _vq_quantlist__44c1_s_p8_2[] = {
  124904. 8,
  124905. 7,
  124906. 9,
  124907. 6,
  124908. 10,
  124909. 5,
  124910. 11,
  124911. 4,
  124912. 12,
  124913. 3,
  124914. 13,
  124915. 2,
  124916. 14,
  124917. 1,
  124918. 15,
  124919. 0,
  124920. 16,
  124921. };
  124922. static long _vq_lengthlist__44c1_s_p8_2[] = {
  124923. 2, 4, 4, 6, 6, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  124924. 8,10,10,10, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  124925. 9, 9,10,10,10, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  124926. 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  124927. 9,10, 9, 9,10,10,10, 7, 7, 8, 8, 9, 8, 9, 9, 9,
  124928. 9,10, 9, 9,10,10,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  124929. 9, 9,10, 9, 9,10,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  124930. 9, 9, 9, 9, 9,10,10,11,11,11, 8, 8, 9, 9, 9, 9,
  124931. 9, 9, 9, 9, 9, 9,10,10,10,10,11,11,11, 8, 8, 9,
  124932. 9, 9, 9,10, 9, 9, 9, 9, 9,11,11,11,11,11, 9, 9,
  124933. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,10,11,11, 9,
  124934. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,11,10,11,11,
  124935. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,10,10,11,11,
  124936. 11,11,11, 9, 9, 9,10, 9, 9, 9, 9, 9, 9,10,11,11,
  124937. 11,11,11,11,10,10,10,10, 9, 9, 9, 9, 9, 9,10,11,
  124938. 11,11,11,11,11, 9,10, 9, 9, 9, 9,10, 9, 9, 9,11,
  124939. 11,11,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9,10, 9,
  124940. 11,11,10,11,11,11,11,10,11, 9, 9, 9, 9, 9, 9, 9,
  124941. 9,
  124942. };
  124943. static float _vq_quantthresh__44c1_s_p8_2[] = {
  124944. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  124945. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  124946. };
  124947. static long _vq_quantmap__44c1_s_p8_2[] = {
  124948. 15, 13, 11, 9, 7, 5, 3, 1,
  124949. 0, 2, 4, 6, 8, 10, 12, 14,
  124950. 16,
  124951. };
  124952. static encode_aux_threshmatch _vq_auxt__44c1_s_p8_2 = {
  124953. _vq_quantthresh__44c1_s_p8_2,
  124954. _vq_quantmap__44c1_s_p8_2,
  124955. 17,
  124956. 17
  124957. };
  124958. static static_codebook _44c1_s_p8_2 = {
  124959. 2, 289,
  124960. _vq_lengthlist__44c1_s_p8_2,
  124961. 1, -529530880, 1611661312, 5, 0,
  124962. _vq_quantlist__44c1_s_p8_2,
  124963. NULL,
  124964. &_vq_auxt__44c1_s_p8_2,
  124965. NULL,
  124966. 0
  124967. };
  124968. static long _huff_lengthlist__44c1_s_short[] = {
  124969. 6, 8,13,12,13,14,15,16,16, 4, 2, 4, 7, 6, 8,11,
  124970. 13,15,10, 4, 4, 8, 6, 8,11,14,17,11, 5, 6, 5, 6,
  124971. 8,12,14,17,11, 5, 5, 6, 5, 7,10,13,16,12, 6, 7,
  124972. 8, 7, 8,10,13,15,13, 8, 8, 7, 7, 8,10,12,15,15,
  124973. 7, 7, 5, 5, 7, 9,12,14,15, 8, 8, 6, 6, 7, 8,10,
  124974. 11,
  124975. };
  124976. static static_codebook _huff_book__44c1_s_short = {
  124977. 2, 81,
  124978. _huff_lengthlist__44c1_s_short,
  124979. 0, 0, 0, 0, 0,
  124980. NULL,
  124981. NULL,
  124982. NULL,
  124983. NULL,
  124984. 0
  124985. };
  124986. static long _huff_lengthlist__44c1_sm_long[] = {
  124987. 5, 4, 8,10, 9, 9,10,11,12, 4, 2, 5, 6, 6, 8,10,
  124988. 11,13, 8, 4, 6, 8, 7, 9,12,12,14,10, 6, 8, 4, 5,
  124989. 6, 9,11,12, 9, 5, 6, 5, 5, 6, 9,11,11, 9, 7, 9,
  124990. 6, 5, 5, 7,10,10,10, 9,11, 8, 7, 6, 7, 9,11,11,
  124991. 12,13,10,10, 9, 8, 9,11,11,15,15,12,13,11, 9,10,
  124992. 11,
  124993. };
  124994. static static_codebook _huff_book__44c1_sm_long = {
  124995. 2, 81,
  124996. _huff_lengthlist__44c1_sm_long,
  124997. 0, 0, 0, 0, 0,
  124998. NULL,
  124999. NULL,
  125000. NULL,
  125001. NULL,
  125002. 0
  125003. };
  125004. static long _vq_quantlist__44c1_sm_p1_0[] = {
  125005. 1,
  125006. 0,
  125007. 2,
  125008. };
  125009. static long _vq_lengthlist__44c1_sm_p1_0[] = {
  125010. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  125011. 0, 0, 5, 7, 7, 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, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  125016. 0, 0, 0, 7, 8, 9, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  125021. 0, 0, 0, 0, 7, 9, 9, 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, 5, 8, 7, 0, 0, 0, 0,
  125056. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  125061. 0, 0, 0, 9, 9,10, 0, 0, 0, 0, 0, 0, 9,10,10, 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, 7, 9, 9, 0, 0,
  125066. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  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, 5, 7, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  125102. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  125107. 0, 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  125112. 0, 0, 0, 0, 0, 0, 9,10, 9, 0, 0, 0, 0, 0, 0, 0,
  125113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125420. 0,
  125421. };
  125422. static float _vq_quantthresh__44c1_sm_p1_0[] = {
  125423. -0.5, 0.5,
  125424. };
  125425. static long _vq_quantmap__44c1_sm_p1_0[] = {
  125426. 1, 0, 2,
  125427. };
  125428. static encode_aux_threshmatch _vq_auxt__44c1_sm_p1_0 = {
  125429. _vq_quantthresh__44c1_sm_p1_0,
  125430. _vq_quantmap__44c1_sm_p1_0,
  125431. 3,
  125432. 3
  125433. };
  125434. static static_codebook _44c1_sm_p1_0 = {
  125435. 8, 6561,
  125436. _vq_lengthlist__44c1_sm_p1_0,
  125437. 1, -535822336, 1611661312, 2, 0,
  125438. _vq_quantlist__44c1_sm_p1_0,
  125439. NULL,
  125440. &_vq_auxt__44c1_sm_p1_0,
  125441. NULL,
  125442. 0
  125443. };
  125444. static long _vq_quantlist__44c1_sm_p2_0[] = {
  125445. 2,
  125446. 1,
  125447. 3,
  125448. 0,
  125449. 4,
  125450. };
  125451. static long _vq_lengthlist__44c1_sm_p2_0[] = {
  125452. 2, 3, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  125454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125455. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  125457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125458. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  125459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125491. 0,
  125492. };
  125493. static float _vq_quantthresh__44c1_sm_p2_0[] = {
  125494. -1.5, -0.5, 0.5, 1.5,
  125495. };
  125496. static long _vq_quantmap__44c1_sm_p2_0[] = {
  125497. 3, 1, 0, 2, 4,
  125498. };
  125499. static encode_aux_threshmatch _vq_auxt__44c1_sm_p2_0 = {
  125500. _vq_quantthresh__44c1_sm_p2_0,
  125501. _vq_quantmap__44c1_sm_p2_0,
  125502. 5,
  125503. 5
  125504. };
  125505. static static_codebook _44c1_sm_p2_0 = {
  125506. 4, 625,
  125507. _vq_lengthlist__44c1_sm_p2_0,
  125508. 1, -533725184, 1611661312, 3, 0,
  125509. _vq_quantlist__44c1_sm_p2_0,
  125510. NULL,
  125511. &_vq_auxt__44c1_sm_p2_0,
  125512. NULL,
  125513. 0
  125514. };
  125515. static long _vq_quantlist__44c1_sm_p3_0[] = {
  125516. 4,
  125517. 3,
  125518. 5,
  125519. 2,
  125520. 6,
  125521. 1,
  125522. 7,
  125523. 0,
  125524. 8,
  125525. };
  125526. static long _vq_lengthlist__44c1_sm_p3_0[] = {
  125527. 1, 3, 3, 7, 7, 0, 0, 0, 0, 0, 5, 5, 6, 6, 0, 0,
  125528. 0, 0, 0, 5, 5, 7, 7, 0, 0, 0, 0, 0, 7, 7, 7, 7,
  125529. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  125530. 8, 9, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  125531. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125532. 0,
  125533. };
  125534. static float _vq_quantthresh__44c1_sm_p3_0[] = {
  125535. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  125536. };
  125537. static long _vq_quantmap__44c1_sm_p3_0[] = {
  125538. 7, 5, 3, 1, 0, 2, 4, 6,
  125539. 8,
  125540. };
  125541. static encode_aux_threshmatch _vq_auxt__44c1_sm_p3_0 = {
  125542. _vq_quantthresh__44c1_sm_p3_0,
  125543. _vq_quantmap__44c1_sm_p3_0,
  125544. 9,
  125545. 9
  125546. };
  125547. static static_codebook _44c1_sm_p3_0 = {
  125548. 2, 81,
  125549. _vq_lengthlist__44c1_sm_p3_0,
  125550. 1, -531628032, 1611661312, 4, 0,
  125551. _vq_quantlist__44c1_sm_p3_0,
  125552. NULL,
  125553. &_vq_auxt__44c1_sm_p3_0,
  125554. NULL,
  125555. 0
  125556. };
  125557. static long _vq_quantlist__44c1_sm_p4_0[] = {
  125558. 4,
  125559. 3,
  125560. 5,
  125561. 2,
  125562. 6,
  125563. 1,
  125564. 7,
  125565. 0,
  125566. 8,
  125567. };
  125568. static long _vq_lengthlist__44c1_sm_p4_0[] = {
  125569. 1, 3, 3, 6, 6, 7, 7, 9, 9, 0, 6, 6, 7, 7, 8, 8,
  125570. 9, 9, 0, 6, 6, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  125571. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  125572. 8, 8, 9, 9,11,11, 0, 0, 0, 9, 9, 9, 9,11,11, 0,
  125573. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  125574. 11,
  125575. };
  125576. static float _vq_quantthresh__44c1_sm_p4_0[] = {
  125577. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  125578. };
  125579. static long _vq_quantmap__44c1_sm_p4_0[] = {
  125580. 7, 5, 3, 1, 0, 2, 4, 6,
  125581. 8,
  125582. };
  125583. static encode_aux_threshmatch _vq_auxt__44c1_sm_p4_0 = {
  125584. _vq_quantthresh__44c1_sm_p4_0,
  125585. _vq_quantmap__44c1_sm_p4_0,
  125586. 9,
  125587. 9
  125588. };
  125589. static static_codebook _44c1_sm_p4_0 = {
  125590. 2, 81,
  125591. _vq_lengthlist__44c1_sm_p4_0,
  125592. 1, -531628032, 1611661312, 4, 0,
  125593. _vq_quantlist__44c1_sm_p4_0,
  125594. NULL,
  125595. &_vq_auxt__44c1_sm_p4_0,
  125596. NULL,
  125597. 0
  125598. };
  125599. static long _vq_quantlist__44c1_sm_p5_0[] = {
  125600. 8,
  125601. 7,
  125602. 9,
  125603. 6,
  125604. 10,
  125605. 5,
  125606. 11,
  125607. 4,
  125608. 12,
  125609. 3,
  125610. 13,
  125611. 2,
  125612. 14,
  125613. 1,
  125614. 15,
  125615. 0,
  125616. 16,
  125617. };
  125618. static long _vq_lengthlist__44c1_sm_p5_0[] = {
  125619. 2, 3, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  125620. 11, 0, 5, 5, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,10,
  125621. 11,11, 0, 5, 5, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,
  125622. 10,11,11, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  125623. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  125624. 10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9,10,10,
  125625. 10,11,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9,10,
  125626. 10,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  125627. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  125628. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  125629. 9, 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  125630. 9, 9, 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  125631. 9, 9,10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0,
  125632. 0, 0, 0,10,10,11,11,12,12,12,12,13,13, 0, 0, 0,
  125633. 0, 0, 0, 0,11,11,11,11,12,12,13,13,13,13, 0, 0,
  125634. 0, 0, 0, 0, 0,11,11,11,11,12,12,13,13,13,13, 0,
  125635. 0, 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14,
  125636. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  125637. 14,
  125638. };
  125639. static float _vq_quantthresh__44c1_sm_p5_0[] = {
  125640. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  125641. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  125642. };
  125643. static long _vq_quantmap__44c1_sm_p5_0[] = {
  125644. 15, 13, 11, 9, 7, 5, 3, 1,
  125645. 0, 2, 4, 6, 8, 10, 12, 14,
  125646. 16,
  125647. };
  125648. static encode_aux_threshmatch _vq_auxt__44c1_sm_p5_0 = {
  125649. _vq_quantthresh__44c1_sm_p5_0,
  125650. _vq_quantmap__44c1_sm_p5_0,
  125651. 17,
  125652. 17
  125653. };
  125654. static static_codebook _44c1_sm_p5_0 = {
  125655. 2, 289,
  125656. _vq_lengthlist__44c1_sm_p5_0,
  125657. 1, -529530880, 1611661312, 5, 0,
  125658. _vq_quantlist__44c1_sm_p5_0,
  125659. NULL,
  125660. &_vq_auxt__44c1_sm_p5_0,
  125661. NULL,
  125662. 0
  125663. };
  125664. static long _vq_quantlist__44c1_sm_p6_0[] = {
  125665. 1,
  125666. 0,
  125667. 2,
  125668. };
  125669. static long _vq_lengthlist__44c1_sm_p6_0[] = {
  125670. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  125671. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,10,11,
  125672. 11,11,10,10, 6, 9, 9,11,11,10,11,10,10, 6, 9, 9,
  125673. 11,10,11,11,10,10, 7,11,11,11,11,11,11,11,11, 6,
  125674. 9, 9,11,10,10,11,11,10, 6, 9, 9,10,10,10,11,10,
  125675. 11,
  125676. };
  125677. static float _vq_quantthresh__44c1_sm_p6_0[] = {
  125678. -5.5, 5.5,
  125679. };
  125680. static long _vq_quantmap__44c1_sm_p6_0[] = {
  125681. 1, 0, 2,
  125682. };
  125683. static encode_aux_threshmatch _vq_auxt__44c1_sm_p6_0 = {
  125684. _vq_quantthresh__44c1_sm_p6_0,
  125685. _vq_quantmap__44c1_sm_p6_0,
  125686. 3,
  125687. 3
  125688. };
  125689. static static_codebook _44c1_sm_p6_0 = {
  125690. 4, 81,
  125691. _vq_lengthlist__44c1_sm_p6_0,
  125692. 1, -529137664, 1618345984, 2, 0,
  125693. _vq_quantlist__44c1_sm_p6_0,
  125694. NULL,
  125695. &_vq_auxt__44c1_sm_p6_0,
  125696. NULL,
  125697. 0
  125698. };
  125699. static long _vq_quantlist__44c1_sm_p6_1[] = {
  125700. 5,
  125701. 4,
  125702. 6,
  125703. 3,
  125704. 7,
  125705. 2,
  125706. 8,
  125707. 1,
  125708. 9,
  125709. 0,
  125710. 10,
  125711. };
  125712. static long _vq_lengthlist__44c1_sm_p6_1[] = {
  125713. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  125714. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  125715. 8,10, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  125716. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  125717. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  125718. 8, 8, 8, 8, 8, 8, 9, 8,10,10,10,10,10, 8, 8, 8,
  125719. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  125720. 10,10,10, 8, 8, 8, 8, 8, 8,
  125721. };
  125722. static float _vq_quantthresh__44c1_sm_p6_1[] = {
  125723. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  125724. 3.5, 4.5,
  125725. };
  125726. static long _vq_quantmap__44c1_sm_p6_1[] = {
  125727. 9, 7, 5, 3, 1, 0, 2, 4,
  125728. 6, 8, 10,
  125729. };
  125730. static encode_aux_threshmatch _vq_auxt__44c1_sm_p6_1 = {
  125731. _vq_quantthresh__44c1_sm_p6_1,
  125732. _vq_quantmap__44c1_sm_p6_1,
  125733. 11,
  125734. 11
  125735. };
  125736. static static_codebook _44c1_sm_p6_1 = {
  125737. 2, 121,
  125738. _vq_lengthlist__44c1_sm_p6_1,
  125739. 1, -531365888, 1611661312, 4, 0,
  125740. _vq_quantlist__44c1_sm_p6_1,
  125741. NULL,
  125742. &_vq_auxt__44c1_sm_p6_1,
  125743. NULL,
  125744. 0
  125745. };
  125746. static long _vq_quantlist__44c1_sm_p7_0[] = {
  125747. 6,
  125748. 5,
  125749. 7,
  125750. 4,
  125751. 8,
  125752. 3,
  125753. 9,
  125754. 2,
  125755. 10,
  125756. 1,
  125757. 11,
  125758. 0,
  125759. 12,
  125760. };
  125761. static long _vq_lengthlist__44c1_sm_p7_0[] = {
  125762. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 5, 5,
  125763. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 6, 7, 7, 8,
  125764. 8, 8, 8, 9, 9,11,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  125765. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  125766. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  125767. 13, 9, 9, 9, 9,10,10,11,11,12,12, 0, 0, 0, 9,10,
  125768. 9,10,11,11,12,11,13,12, 0, 0, 0,10,10, 9, 9,11,
  125769. 11,12,12,13,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  125770. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  125771. 0, 0, 0, 0,11,12,11,11,12,13,14,13, 0, 0, 0, 0,
  125772. 0,12,12,11,11,13,12,14,13,
  125773. };
  125774. static float _vq_quantthresh__44c1_sm_p7_0[] = {
  125775. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  125776. 12.5, 17.5, 22.5, 27.5,
  125777. };
  125778. static long _vq_quantmap__44c1_sm_p7_0[] = {
  125779. 11, 9, 7, 5, 3, 1, 0, 2,
  125780. 4, 6, 8, 10, 12,
  125781. };
  125782. static encode_aux_threshmatch _vq_auxt__44c1_sm_p7_0 = {
  125783. _vq_quantthresh__44c1_sm_p7_0,
  125784. _vq_quantmap__44c1_sm_p7_0,
  125785. 13,
  125786. 13
  125787. };
  125788. static static_codebook _44c1_sm_p7_0 = {
  125789. 2, 169,
  125790. _vq_lengthlist__44c1_sm_p7_0,
  125791. 1, -526516224, 1616117760, 4, 0,
  125792. _vq_quantlist__44c1_sm_p7_0,
  125793. NULL,
  125794. &_vq_auxt__44c1_sm_p7_0,
  125795. NULL,
  125796. 0
  125797. };
  125798. static long _vq_quantlist__44c1_sm_p7_1[] = {
  125799. 2,
  125800. 1,
  125801. 3,
  125802. 0,
  125803. 4,
  125804. };
  125805. static long _vq_lengthlist__44c1_sm_p7_1[] = {
  125806. 2, 4, 4, 4, 5, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  125807. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  125808. };
  125809. static float _vq_quantthresh__44c1_sm_p7_1[] = {
  125810. -1.5, -0.5, 0.5, 1.5,
  125811. };
  125812. static long _vq_quantmap__44c1_sm_p7_1[] = {
  125813. 3, 1, 0, 2, 4,
  125814. };
  125815. static encode_aux_threshmatch _vq_auxt__44c1_sm_p7_1 = {
  125816. _vq_quantthresh__44c1_sm_p7_1,
  125817. _vq_quantmap__44c1_sm_p7_1,
  125818. 5,
  125819. 5
  125820. };
  125821. static static_codebook _44c1_sm_p7_1 = {
  125822. 2, 25,
  125823. _vq_lengthlist__44c1_sm_p7_1,
  125824. 1, -533725184, 1611661312, 3, 0,
  125825. _vq_quantlist__44c1_sm_p7_1,
  125826. NULL,
  125827. &_vq_auxt__44c1_sm_p7_1,
  125828. NULL,
  125829. 0
  125830. };
  125831. static long _vq_quantlist__44c1_sm_p8_0[] = {
  125832. 6,
  125833. 5,
  125834. 7,
  125835. 4,
  125836. 8,
  125837. 3,
  125838. 9,
  125839. 2,
  125840. 10,
  125841. 1,
  125842. 11,
  125843. 0,
  125844. 12,
  125845. };
  125846. static long _vq_lengthlist__44c1_sm_p8_0[] = {
  125847. 1, 3, 3,13,13,13,13,13,13,13,13,13,13, 3, 6, 6,
  125848. 13,13,13,13,13,13,13,13,13,13, 4, 8, 7,13,13,13,
  125849. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125850. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125851. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125852. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125853. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125854. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125855. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125856. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125857. 13,13,13,13,13,13,13,13,13,
  125858. };
  125859. static float _vq_quantthresh__44c1_sm_p8_0[] = {
  125860. -1215.5, -994.5, -773.5, -552.5, -331.5, -110.5, 110.5, 331.5,
  125861. 552.5, 773.5, 994.5, 1215.5,
  125862. };
  125863. static long _vq_quantmap__44c1_sm_p8_0[] = {
  125864. 11, 9, 7, 5, 3, 1, 0, 2,
  125865. 4, 6, 8, 10, 12,
  125866. };
  125867. static encode_aux_threshmatch _vq_auxt__44c1_sm_p8_0 = {
  125868. _vq_quantthresh__44c1_sm_p8_0,
  125869. _vq_quantmap__44c1_sm_p8_0,
  125870. 13,
  125871. 13
  125872. };
  125873. static static_codebook _44c1_sm_p8_0 = {
  125874. 2, 169,
  125875. _vq_lengthlist__44c1_sm_p8_0,
  125876. 1, -514541568, 1627103232, 4, 0,
  125877. _vq_quantlist__44c1_sm_p8_0,
  125878. NULL,
  125879. &_vq_auxt__44c1_sm_p8_0,
  125880. NULL,
  125881. 0
  125882. };
  125883. static long _vq_quantlist__44c1_sm_p8_1[] = {
  125884. 6,
  125885. 5,
  125886. 7,
  125887. 4,
  125888. 8,
  125889. 3,
  125890. 9,
  125891. 2,
  125892. 10,
  125893. 1,
  125894. 11,
  125895. 0,
  125896. 12,
  125897. };
  125898. static long _vq_lengthlist__44c1_sm_p8_1[] = {
  125899. 1, 4, 4, 6, 6, 7, 7, 9, 9,10,11,12,12, 6, 5, 5,
  125900. 7, 7, 8, 7,10,10,11,11,12,12, 6, 5, 5, 7, 7, 8,
  125901. 8,10,10,11,11,12,12,16, 7, 7, 8, 8, 9, 9,11,11,
  125902. 12,12,13,13,17, 7, 7, 8, 7, 9, 9,11,10,12,12,13,
  125903. 13,19,11,10, 8, 8,10,10,11,11,12,12,13,13,19,11,
  125904. 11, 9, 7,11,10,11,11,12,12,13,12,19,19,19,10,10,
  125905. 10,10,11,12,12,12,13,14,18,19,19,11, 9,11, 9,13,
  125906. 12,12,12,13,13,19,20,19,13,15,11,11,12,12,13,13,
  125907. 14,13,18,19,20,15,13,12,10,13,10,13,13,13,14,20,
  125908. 20,20,20,20,13,14,12,12,13,12,13,13,20,20,20,20,
  125909. 20,13,12,12,12,14,12,14,13,
  125910. };
  125911. static float _vq_quantthresh__44c1_sm_p8_1[] = {
  125912. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  125913. 42.5, 59.5, 76.5, 93.5,
  125914. };
  125915. static long _vq_quantmap__44c1_sm_p8_1[] = {
  125916. 11, 9, 7, 5, 3, 1, 0, 2,
  125917. 4, 6, 8, 10, 12,
  125918. };
  125919. static encode_aux_threshmatch _vq_auxt__44c1_sm_p8_1 = {
  125920. _vq_quantthresh__44c1_sm_p8_1,
  125921. _vq_quantmap__44c1_sm_p8_1,
  125922. 13,
  125923. 13
  125924. };
  125925. static static_codebook _44c1_sm_p8_1 = {
  125926. 2, 169,
  125927. _vq_lengthlist__44c1_sm_p8_1,
  125928. 1, -522616832, 1620115456, 4, 0,
  125929. _vq_quantlist__44c1_sm_p8_1,
  125930. NULL,
  125931. &_vq_auxt__44c1_sm_p8_1,
  125932. NULL,
  125933. 0
  125934. };
  125935. static long _vq_quantlist__44c1_sm_p8_2[] = {
  125936. 8,
  125937. 7,
  125938. 9,
  125939. 6,
  125940. 10,
  125941. 5,
  125942. 11,
  125943. 4,
  125944. 12,
  125945. 3,
  125946. 13,
  125947. 2,
  125948. 14,
  125949. 1,
  125950. 15,
  125951. 0,
  125952. 16,
  125953. };
  125954. static long _vq_lengthlist__44c1_sm_p8_2[] = {
  125955. 2, 5, 5, 6, 6, 7, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  125956. 8,10, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  125957. 9, 9,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  125958. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  125959. 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  125960. 9, 9, 9, 9, 9,10,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  125961. 9, 9,10,10, 9,10,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  125962. 9, 9, 9, 9, 9,10,10,11,10,10, 8, 8, 9, 9, 9, 9,
  125963. 9, 9, 9, 9, 9, 9,10, 9,10,10,10,11,11, 8, 8, 9,
  125964. 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,11,11,11, 9, 9,
  125965. 9, 9, 9, 9, 9, 9,10, 9,10, 9,11,11,11,11,11, 9,
  125966. 8, 9, 9, 9, 9, 9, 9, 9,10,10, 9,11,11,10,11,11,
  125967. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,11,11,11,11,
  125968. 11,11,11, 9, 9,10, 9, 9, 9, 9,10, 9,10,10,11,10,
  125969. 11,11,11,11, 9,10,10,10, 9, 9, 9, 9, 9, 9,10,11,
  125970. 11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,
  125971. 11,10,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9,10, 9,
  125972. 10,11,10,11,11,11,11,11,11, 9, 9,10, 9, 9, 9, 9,
  125973. 9,
  125974. };
  125975. static float _vq_quantthresh__44c1_sm_p8_2[] = {
  125976. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  125977. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  125978. };
  125979. static long _vq_quantmap__44c1_sm_p8_2[] = {
  125980. 15, 13, 11, 9, 7, 5, 3, 1,
  125981. 0, 2, 4, 6, 8, 10, 12, 14,
  125982. 16,
  125983. };
  125984. static encode_aux_threshmatch _vq_auxt__44c1_sm_p8_2 = {
  125985. _vq_quantthresh__44c1_sm_p8_2,
  125986. _vq_quantmap__44c1_sm_p8_2,
  125987. 17,
  125988. 17
  125989. };
  125990. static static_codebook _44c1_sm_p8_2 = {
  125991. 2, 289,
  125992. _vq_lengthlist__44c1_sm_p8_2,
  125993. 1, -529530880, 1611661312, 5, 0,
  125994. _vq_quantlist__44c1_sm_p8_2,
  125995. NULL,
  125996. &_vq_auxt__44c1_sm_p8_2,
  125997. NULL,
  125998. 0
  125999. };
  126000. static long _huff_lengthlist__44c1_sm_short[] = {
  126001. 4, 7,13,14,14,15,16,18,18, 4, 2, 5, 8, 7, 9,12,
  126002. 15,15,10, 4, 5,10, 6, 8,11,15,17,12, 5, 7, 5, 6,
  126003. 8,11,14,17,11, 5, 6, 6, 5, 6, 9,13,17,12, 6, 7,
  126004. 6, 5, 6, 8,12,14,14, 7, 8, 6, 6, 7, 9,11,14,14,
  126005. 8, 9, 6, 5, 6, 9,11,13,16,10,10, 7, 6, 7, 8,10,
  126006. 11,
  126007. };
  126008. static static_codebook _huff_book__44c1_sm_short = {
  126009. 2, 81,
  126010. _huff_lengthlist__44c1_sm_short,
  126011. 0, 0, 0, 0, 0,
  126012. NULL,
  126013. NULL,
  126014. NULL,
  126015. NULL,
  126016. 0
  126017. };
  126018. static long _huff_lengthlist__44cn1_s_long[] = {
  126019. 4, 4, 7, 8, 7, 8,10,12,17, 3, 1, 6, 6, 7, 8,10,
  126020. 12,15, 7, 6, 9, 9, 9,11,12,14,17, 8, 6, 9, 6, 7,
  126021. 9,11,13,17, 7, 6, 9, 7, 7, 8, 9,12,15, 8, 8,10,
  126022. 8, 7, 7, 7,10,14, 9,10,12,10, 8, 8, 8,10,14,11,
  126023. 13,15,13,12,11,11,12,16,17,18,18,19,20,18,16,16,
  126024. 20,
  126025. };
  126026. static static_codebook _huff_book__44cn1_s_long = {
  126027. 2, 81,
  126028. _huff_lengthlist__44cn1_s_long,
  126029. 0, 0, 0, 0, 0,
  126030. NULL,
  126031. NULL,
  126032. NULL,
  126033. NULL,
  126034. 0
  126035. };
  126036. static long _vq_quantlist__44cn1_s_p1_0[] = {
  126037. 1,
  126038. 0,
  126039. 2,
  126040. };
  126041. static long _vq_lengthlist__44cn1_s_p1_0[] = {
  126042. 1, 4, 4, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  126043. 0, 0, 5, 7, 7, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0,
  126048. 0, 0, 0, 7, 9,10, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7,10, 9, 0, 0,
  126053. 0, 0, 0, 0, 8,10, 9, 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, 5, 8, 8, 0, 0, 0, 0,
  126088. 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 8, 9,10, 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, 7,10,10, 0, 0, 0,
  126093. 0, 0, 0, 9, 9,11, 0, 0, 0, 0, 0, 0,10,11,11, 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, 7,10,10, 0, 0,
  126098. 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0,10,11,11,
  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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0,
  126134. 0, 0, 0, 0, 8,10,10, 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, 7,10,10, 0, 0, 0, 0, 0, 0,10,11,11, 0,
  126139. 0, 0, 0, 0, 0, 9, 9,11, 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, 7,10,10, 0, 0, 0, 0, 0, 0,10,11,11,
  126144. 0, 0, 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0, 0,
  126145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126452. 0,
  126453. };
  126454. static float _vq_quantthresh__44cn1_s_p1_0[] = {
  126455. -0.5, 0.5,
  126456. };
  126457. static long _vq_quantmap__44cn1_s_p1_0[] = {
  126458. 1, 0, 2,
  126459. };
  126460. static encode_aux_threshmatch _vq_auxt__44cn1_s_p1_0 = {
  126461. _vq_quantthresh__44cn1_s_p1_0,
  126462. _vq_quantmap__44cn1_s_p1_0,
  126463. 3,
  126464. 3
  126465. };
  126466. static static_codebook _44cn1_s_p1_0 = {
  126467. 8, 6561,
  126468. _vq_lengthlist__44cn1_s_p1_0,
  126469. 1, -535822336, 1611661312, 2, 0,
  126470. _vq_quantlist__44cn1_s_p1_0,
  126471. NULL,
  126472. &_vq_auxt__44cn1_s_p1_0,
  126473. NULL,
  126474. 0
  126475. };
  126476. static long _vq_quantlist__44cn1_s_p2_0[] = {
  126477. 2,
  126478. 1,
  126479. 3,
  126480. 0,
  126481. 4,
  126482. };
  126483. static long _vq_lengthlist__44cn1_s_p2_0[] = {
  126484. 1, 4, 4, 7, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  126486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126487. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  126489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126490. 0, 0, 0, 0, 6, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  126491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126523. 0,
  126524. };
  126525. static float _vq_quantthresh__44cn1_s_p2_0[] = {
  126526. -1.5, -0.5, 0.5, 1.5,
  126527. };
  126528. static long _vq_quantmap__44cn1_s_p2_0[] = {
  126529. 3, 1, 0, 2, 4,
  126530. };
  126531. static encode_aux_threshmatch _vq_auxt__44cn1_s_p2_0 = {
  126532. _vq_quantthresh__44cn1_s_p2_0,
  126533. _vq_quantmap__44cn1_s_p2_0,
  126534. 5,
  126535. 5
  126536. };
  126537. static static_codebook _44cn1_s_p2_0 = {
  126538. 4, 625,
  126539. _vq_lengthlist__44cn1_s_p2_0,
  126540. 1, -533725184, 1611661312, 3, 0,
  126541. _vq_quantlist__44cn1_s_p2_0,
  126542. NULL,
  126543. &_vq_auxt__44cn1_s_p2_0,
  126544. NULL,
  126545. 0
  126546. };
  126547. static long _vq_quantlist__44cn1_s_p3_0[] = {
  126548. 4,
  126549. 3,
  126550. 5,
  126551. 2,
  126552. 6,
  126553. 1,
  126554. 7,
  126555. 0,
  126556. 8,
  126557. };
  126558. static long _vq_lengthlist__44cn1_s_p3_0[] = {
  126559. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  126560. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  126561. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  126562. 9, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  126563. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126564. 0,
  126565. };
  126566. static float _vq_quantthresh__44cn1_s_p3_0[] = {
  126567. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  126568. };
  126569. static long _vq_quantmap__44cn1_s_p3_0[] = {
  126570. 7, 5, 3, 1, 0, 2, 4, 6,
  126571. 8,
  126572. };
  126573. static encode_aux_threshmatch _vq_auxt__44cn1_s_p3_0 = {
  126574. _vq_quantthresh__44cn1_s_p3_0,
  126575. _vq_quantmap__44cn1_s_p3_0,
  126576. 9,
  126577. 9
  126578. };
  126579. static static_codebook _44cn1_s_p3_0 = {
  126580. 2, 81,
  126581. _vq_lengthlist__44cn1_s_p3_0,
  126582. 1, -531628032, 1611661312, 4, 0,
  126583. _vq_quantlist__44cn1_s_p3_0,
  126584. NULL,
  126585. &_vq_auxt__44cn1_s_p3_0,
  126586. NULL,
  126587. 0
  126588. };
  126589. static long _vq_quantlist__44cn1_s_p4_0[] = {
  126590. 4,
  126591. 3,
  126592. 5,
  126593. 2,
  126594. 6,
  126595. 1,
  126596. 7,
  126597. 0,
  126598. 8,
  126599. };
  126600. static long _vq_lengthlist__44cn1_s_p4_0[] = {
  126601. 1, 3, 3, 6, 6, 6, 6, 8, 8, 0, 0, 0, 6, 6, 7, 7,
  126602. 9, 9, 0, 0, 0, 6, 6, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  126603. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  126604. 9, 9, 9, 9,10,10, 0, 0, 0, 9, 9, 9, 9,10,10, 0,
  126605. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0,10,10,11,
  126606. 11,
  126607. };
  126608. static float _vq_quantthresh__44cn1_s_p4_0[] = {
  126609. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  126610. };
  126611. static long _vq_quantmap__44cn1_s_p4_0[] = {
  126612. 7, 5, 3, 1, 0, 2, 4, 6,
  126613. 8,
  126614. };
  126615. static encode_aux_threshmatch _vq_auxt__44cn1_s_p4_0 = {
  126616. _vq_quantthresh__44cn1_s_p4_0,
  126617. _vq_quantmap__44cn1_s_p4_0,
  126618. 9,
  126619. 9
  126620. };
  126621. static static_codebook _44cn1_s_p4_0 = {
  126622. 2, 81,
  126623. _vq_lengthlist__44cn1_s_p4_0,
  126624. 1, -531628032, 1611661312, 4, 0,
  126625. _vq_quantlist__44cn1_s_p4_0,
  126626. NULL,
  126627. &_vq_auxt__44cn1_s_p4_0,
  126628. NULL,
  126629. 0
  126630. };
  126631. static long _vq_quantlist__44cn1_s_p5_0[] = {
  126632. 8,
  126633. 7,
  126634. 9,
  126635. 6,
  126636. 10,
  126637. 5,
  126638. 11,
  126639. 4,
  126640. 12,
  126641. 3,
  126642. 13,
  126643. 2,
  126644. 14,
  126645. 1,
  126646. 15,
  126647. 0,
  126648. 16,
  126649. };
  126650. static long _vq_lengthlist__44cn1_s_p5_0[] = {
  126651. 1, 4, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,10,
  126652. 10, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,
  126653. 11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  126654. 10,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  126655. 11,11,11,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  126656. 10,11,11,11,11, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,10,
  126657. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,
  126658. 10,10,11,11,11,12,12, 0, 0, 0, 9, 9,10, 9,10,10,
  126659. 10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  126660. 10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,
  126661. 10,10,10,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  126662. 9,10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  126663. 10,10,11,10,11,11,11,12,13,12,13,13, 0, 0, 0, 0,
  126664. 0, 0, 0,11,10,11,11,12,12,12,12,13,13, 0, 0, 0,
  126665. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0, 0,
  126666. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0,
  126667. 0, 0, 0, 0, 0, 0,12,12,12,13,13,13,13,13,14,14,
  126668. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,12,13,13,14,
  126669. 14,
  126670. };
  126671. static float _vq_quantthresh__44cn1_s_p5_0[] = {
  126672. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  126673. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  126674. };
  126675. static long _vq_quantmap__44cn1_s_p5_0[] = {
  126676. 15, 13, 11, 9, 7, 5, 3, 1,
  126677. 0, 2, 4, 6, 8, 10, 12, 14,
  126678. 16,
  126679. };
  126680. static encode_aux_threshmatch _vq_auxt__44cn1_s_p5_0 = {
  126681. _vq_quantthresh__44cn1_s_p5_0,
  126682. _vq_quantmap__44cn1_s_p5_0,
  126683. 17,
  126684. 17
  126685. };
  126686. static static_codebook _44cn1_s_p5_0 = {
  126687. 2, 289,
  126688. _vq_lengthlist__44cn1_s_p5_0,
  126689. 1, -529530880, 1611661312, 5, 0,
  126690. _vq_quantlist__44cn1_s_p5_0,
  126691. NULL,
  126692. &_vq_auxt__44cn1_s_p5_0,
  126693. NULL,
  126694. 0
  126695. };
  126696. static long _vq_quantlist__44cn1_s_p6_0[] = {
  126697. 1,
  126698. 0,
  126699. 2,
  126700. };
  126701. static long _vq_lengthlist__44cn1_s_p6_0[] = {
  126702. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 6, 6,10, 9, 9,11,
  126703. 9, 9, 4, 6, 6,10, 9, 9,10, 9, 9, 7,10,10,11,11,
  126704. 11,12,11,11, 7, 9, 9,11,11,10,11,10,10, 7, 9, 9,
  126705. 11,10,11,11,10,10, 7,10,10,11,11,11,12,11,11, 7,
  126706. 9, 9,11,10,10,11,10,10, 7, 9, 9,11,10,10,11,10,
  126707. 10,
  126708. };
  126709. static float _vq_quantthresh__44cn1_s_p6_0[] = {
  126710. -5.5, 5.5,
  126711. };
  126712. static long _vq_quantmap__44cn1_s_p6_0[] = {
  126713. 1, 0, 2,
  126714. };
  126715. static encode_aux_threshmatch _vq_auxt__44cn1_s_p6_0 = {
  126716. _vq_quantthresh__44cn1_s_p6_0,
  126717. _vq_quantmap__44cn1_s_p6_0,
  126718. 3,
  126719. 3
  126720. };
  126721. static static_codebook _44cn1_s_p6_0 = {
  126722. 4, 81,
  126723. _vq_lengthlist__44cn1_s_p6_0,
  126724. 1, -529137664, 1618345984, 2, 0,
  126725. _vq_quantlist__44cn1_s_p6_0,
  126726. NULL,
  126727. &_vq_auxt__44cn1_s_p6_0,
  126728. NULL,
  126729. 0
  126730. };
  126731. static long _vq_quantlist__44cn1_s_p6_1[] = {
  126732. 5,
  126733. 4,
  126734. 6,
  126735. 3,
  126736. 7,
  126737. 2,
  126738. 8,
  126739. 1,
  126740. 9,
  126741. 0,
  126742. 10,
  126743. };
  126744. static long _vq_lengthlist__44cn1_s_p6_1[] = {
  126745. 1, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8,10,10,10, 7, 6,
  126746. 8, 8, 8, 8, 8, 8,10,10,10, 7, 6, 7, 7, 8, 8, 8,
  126747. 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  126748. 7, 8, 8, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 9, 9,
  126749. 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,
  126750. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9,
  126751. 9, 9, 9,10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,10,
  126752. 10,10,10, 9, 9, 9, 9, 9, 9,
  126753. };
  126754. static float _vq_quantthresh__44cn1_s_p6_1[] = {
  126755. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  126756. 3.5, 4.5,
  126757. };
  126758. static long _vq_quantmap__44cn1_s_p6_1[] = {
  126759. 9, 7, 5, 3, 1, 0, 2, 4,
  126760. 6, 8, 10,
  126761. };
  126762. static encode_aux_threshmatch _vq_auxt__44cn1_s_p6_1 = {
  126763. _vq_quantthresh__44cn1_s_p6_1,
  126764. _vq_quantmap__44cn1_s_p6_1,
  126765. 11,
  126766. 11
  126767. };
  126768. static static_codebook _44cn1_s_p6_1 = {
  126769. 2, 121,
  126770. _vq_lengthlist__44cn1_s_p6_1,
  126771. 1, -531365888, 1611661312, 4, 0,
  126772. _vq_quantlist__44cn1_s_p6_1,
  126773. NULL,
  126774. &_vq_auxt__44cn1_s_p6_1,
  126775. NULL,
  126776. 0
  126777. };
  126778. static long _vq_quantlist__44cn1_s_p7_0[] = {
  126779. 6,
  126780. 5,
  126781. 7,
  126782. 4,
  126783. 8,
  126784. 3,
  126785. 9,
  126786. 2,
  126787. 10,
  126788. 1,
  126789. 11,
  126790. 0,
  126791. 12,
  126792. };
  126793. static long _vq_lengthlist__44cn1_s_p7_0[] = {
  126794. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  126795. 7, 7, 8, 8, 8, 8, 9, 9,11,11, 7, 5, 5, 7, 7, 8,
  126796. 8, 8, 8, 9,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  126797. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  126798. 11, 0,12,12, 9, 9, 9,10,10,10,11,11,11,12, 0,13,
  126799. 13, 9, 9, 9, 9,10,10,11,11,11,12, 0, 0, 0,10,10,
  126800. 10,10,11,11,12,12,12,13, 0, 0, 0,10,10,10,10,11,
  126801. 11,12,12,13,12, 0, 0, 0,14,14,11,10,11,12,12,13,
  126802. 13,14, 0, 0, 0,15,15,11,11,12,11,12,12,14,13, 0,
  126803. 0, 0, 0, 0,12,12,12,12,13,13,14,14, 0, 0, 0, 0,
  126804. 0,13,13,12,12,13,13,13,14,
  126805. };
  126806. static float _vq_quantthresh__44cn1_s_p7_0[] = {
  126807. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  126808. 12.5, 17.5, 22.5, 27.5,
  126809. };
  126810. static long _vq_quantmap__44cn1_s_p7_0[] = {
  126811. 11, 9, 7, 5, 3, 1, 0, 2,
  126812. 4, 6, 8, 10, 12,
  126813. };
  126814. static encode_aux_threshmatch _vq_auxt__44cn1_s_p7_0 = {
  126815. _vq_quantthresh__44cn1_s_p7_0,
  126816. _vq_quantmap__44cn1_s_p7_0,
  126817. 13,
  126818. 13
  126819. };
  126820. static static_codebook _44cn1_s_p7_0 = {
  126821. 2, 169,
  126822. _vq_lengthlist__44cn1_s_p7_0,
  126823. 1, -526516224, 1616117760, 4, 0,
  126824. _vq_quantlist__44cn1_s_p7_0,
  126825. NULL,
  126826. &_vq_auxt__44cn1_s_p7_0,
  126827. NULL,
  126828. 0
  126829. };
  126830. static long _vq_quantlist__44cn1_s_p7_1[] = {
  126831. 2,
  126832. 1,
  126833. 3,
  126834. 0,
  126835. 4,
  126836. };
  126837. static long _vq_lengthlist__44cn1_s_p7_1[] = {
  126838. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  126839. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  126840. };
  126841. static float _vq_quantthresh__44cn1_s_p7_1[] = {
  126842. -1.5, -0.5, 0.5, 1.5,
  126843. };
  126844. static long _vq_quantmap__44cn1_s_p7_1[] = {
  126845. 3, 1, 0, 2, 4,
  126846. };
  126847. static encode_aux_threshmatch _vq_auxt__44cn1_s_p7_1 = {
  126848. _vq_quantthresh__44cn1_s_p7_1,
  126849. _vq_quantmap__44cn1_s_p7_1,
  126850. 5,
  126851. 5
  126852. };
  126853. static static_codebook _44cn1_s_p7_1 = {
  126854. 2, 25,
  126855. _vq_lengthlist__44cn1_s_p7_1,
  126856. 1, -533725184, 1611661312, 3, 0,
  126857. _vq_quantlist__44cn1_s_p7_1,
  126858. NULL,
  126859. &_vq_auxt__44cn1_s_p7_1,
  126860. NULL,
  126861. 0
  126862. };
  126863. static long _vq_quantlist__44cn1_s_p8_0[] = {
  126864. 2,
  126865. 1,
  126866. 3,
  126867. 0,
  126868. 4,
  126869. };
  126870. static long _vq_lengthlist__44cn1_s_p8_0[] = {
  126871. 1, 7, 7,11,11, 8,11,11,11,11, 4,11, 3,11,11,11,
  126872. 11,11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,
  126873. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126874. 11,11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,
  126875. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126876. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126877. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126878. 11,11,11,11,11,11,11,11,11,11,11,11,11, 7,11,11,
  126879. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126880. 11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,
  126881. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
  126882. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126883. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126884. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126885. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126886. 11,11,11,11,11,11,11,11,11,11, 8,11,11,11,11,11,
  126887. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126888. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126889. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126890. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126891. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126892. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126893. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126894. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126895. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126896. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126897. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126898. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126899. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126900. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126901. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126902. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126903. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126904. 11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,
  126905. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126906. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126907. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126908. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126909. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126910. 12,
  126911. };
  126912. static float _vq_quantthresh__44cn1_s_p8_0[] = {
  126913. -331.5, -110.5, 110.5, 331.5,
  126914. };
  126915. static long _vq_quantmap__44cn1_s_p8_0[] = {
  126916. 3, 1, 0, 2, 4,
  126917. };
  126918. static encode_aux_threshmatch _vq_auxt__44cn1_s_p8_0 = {
  126919. _vq_quantthresh__44cn1_s_p8_0,
  126920. _vq_quantmap__44cn1_s_p8_0,
  126921. 5,
  126922. 5
  126923. };
  126924. static static_codebook _44cn1_s_p8_0 = {
  126925. 4, 625,
  126926. _vq_lengthlist__44cn1_s_p8_0,
  126927. 1, -518283264, 1627103232, 3, 0,
  126928. _vq_quantlist__44cn1_s_p8_0,
  126929. NULL,
  126930. &_vq_auxt__44cn1_s_p8_0,
  126931. NULL,
  126932. 0
  126933. };
  126934. static long _vq_quantlist__44cn1_s_p8_1[] = {
  126935. 6,
  126936. 5,
  126937. 7,
  126938. 4,
  126939. 8,
  126940. 3,
  126941. 9,
  126942. 2,
  126943. 10,
  126944. 1,
  126945. 11,
  126946. 0,
  126947. 12,
  126948. };
  126949. static long _vq_lengthlist__44cn1_s_p8_1[] = {
  126950. 1, 4, 4, 6, 6, 8, 8, 9,10,10,11,11,11, 6, 5, 5,
  126951. 7, 7, 8, 8, 9,10, 9,11,11,12, 5, 5, 5, 7, 7, 8,
  126952. 9,10,10,12,12,14,13,15, 7, 7, 8, 8, 9,10,11,11,
  126953. 10,12,10,11,15, 7, 8, 8, 8, 9, 9,11,11,13,12,12,
  126954. 13,15,10,10, 8, 8,10,10,12,12,11,14,10,10,15,11,
  126955. 11, 8, 8,10,10,12,13,13,14,15,13,15,15,15,10,10,
  126956. 10,10,12,12,13,12,13,10,15,15,15,10,10,11,10,13,
  126957. 11,13,13,15,13,15,15,15,13,13,10,11,11,11,12,10,
  126958. 14,11,15,15,14,14,13,10,10,12,11,13,13,14,14,15,
  126959. 15,15,15,15,11,11,11,11,12,11,15,12,15,15,15,15,
  126960. 15,12,12,11,11,14,12,13,14,
  126961. };
  126962. static float _vq_quantthresh__44cn1_s_p8_1[] = {
  126963. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  126964. 42.5, 59.5, 76.5, 93.5,
  126965. };
  126966. static long _vq_quantmap__44cn1_s_p8_1[] = {
  126967. 11, 9, 7, 5, 3, 1, 0, 2,
  126968. 4, 6, 8, 10, 12,
  126969. };
  126970. static encode_aux_threshmatch _vq_auxt__44cn1_s_p8_1 = {
  126971. _vq_quantthresh__44cn1_s_p8_1,
  126972. _vq_quantmap__44cn1_s_p8_1,
  126973. 13,
  126974. 13
  126975. };
  126976. static static_codebook _44cn1_s_p8_1 = {
  126977. 2, 169,
  126978. _vq_lengthlist__44cn1_s_p8_1,
  126979. 1, -522616832, 1620115456, 4, 0,
  126980. _vq_quantlist__44cn1_s_p8_1,
  126981. NULL,
  126982. &_vq_auxt__44cn1_s_p8_1,
  126983. NULL,
  126984. 0
  126985. };
  126986. static long _vq_quantlist__44cn1_s_p8_2[] = {
  126987. 8,
  126988. 7,
  126989. 9,
  126990. 6,
  126991. 10,
  126992. 5,
  126993. 11,
  126994. 4,
  126995. 12,
  126996. 3,
  126997. 13,
  126998. 2,
  126999. 14,
  127000. 1,
  127001. 15,
  127002. 0,
  127003. 16,
  127004. };
  127005. static long _vq_lengthlist__44cn1_s_p8_2[] = {
  127006. 3, 4, 3, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  127007. 9,10,11,11, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  127008. 9, 9,10,10,10, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  127009. 9, 9, 9,10,10,10, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9,
  127010. 9, 9,10, 9,10,11,10, 7, 6, 7, 7, 8, 8, 9, 9, 9,
  127011. 9, 9, 9, 9,10,10,10,11, 7, 7, 8, 8, 8, 8, 9, 9,
  127012. 9, 9, 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 8, 9,
  127013. 9, 9, 9, 9, 9, 9,10,11,11,11, 8, 8, 8, 8, 8, 8,
  127014. 9, 9, 9, 9, 9, 9, 9, 9,11,10,10,11,11, 8, 8, 8,
  127015. 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,11,11, 9, 9,
  127016. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,10,11,11, 9,
  127017. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,11,10,11,11,
  127018. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,10,11,
  127019. 11,11,11, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,11,11,
  127020. 10,11,11,11, 9,10,10, 9, 9, 9, 9, 9, 9, 9,10,11,
  127021. 11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  127022. 11,11,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  127023. 11,11,11,10,11,11,11,11,11, 9, 9, 9,10, 9, 9, 9,
  127024. 9,
  127025. };
  127026. static float _vq_quantthresh__44cn1_s_p8_2[] = {
  127027. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  127028. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  127029. };
  127030. static long _vq_quantmap__44cn1_s_p8_2[] = {
  127031. 15, 13, 11, 9, 7, 5, 3, 1,
  127032. 0, 2, 4, 6, 8, 10, 12, 14,
  127033. 16,
  127034. };
  127035. static encode_aux_threshmatch _vq_auxt__44cn1_s_p8_2 = {
  127036. _vq_quantthresh__44cn1_s_p8_2,
  127037. _vq_quantmap__44cn1_s_p8_2,
  127038. 17,
  127039. 17
  127040. };
  127041. static static_codebook _44cn1_s_p8_2 = {
  127042. 2, 289,
  127043. _vq_lengthlist__44cn1_s_p8_2,
  127044. 1, -529530880, 1611661312, 5, 0,
  127045. _vq_quantlist__44cn1_s_p8_2,
  127046. NULL,
  127047. &_vq_auxt__44cn1_s_p8_2,
  127048. NULL,
  127049. 0
  127050. };
  127051. static long _huff_lengthlist__44cn1_s_short[] = {
  127052. 10, 9,12,15,12,13,16,14,16, 7, 1, 5,14, 7,10,13,
  127053. 16,16, 9, 4, 6,16, 8,11,16,16,16,14, 4, 7,16, 9,
  127054. 12,14,16,16,10, 5, 7,14, 9,12,14,15,15,13, 8, 9,
  127055. 14,10,12,13,14,15,13, 9, 9, 7, 6, 8,11,12,12,14,
  127056. 8, 8, 5, 4, 5, 8,11,12,16,10,10, 6, 5, 6, 8, 9,
  127057. 10,
  127058. };
  127059. static static_codebook _huff_book__44cn1_s_short = {
  127060. 2, 81,
  127061. _huff_lengthlist__44cn1_s_short,
  127062. 0, 0, 0, 0, 0,
  127063. NULL,
  127064. NULL,
  127065. NULL,
  127066. NULL,
  127067. 0
  127068. };
  127069. static long _huff_lengthlist__44cn1_sm_long[] = {
  127070. 3, 3, 8, 8, 8, 8,10,12,14, 3, 2, 6, 7, 7, 8,10,
  127071. 12,16, 7, 6, 7, 9, 8,10,12,14,16, 8, 6, 8, 4, 5,
  127072. 7, 9,11,13, 7, 6, 8, 5, 6, 7, 9,11,14, 8, 8,10,
  127073. 7, 7, 6, 8,10,13, 9,11,12, 9, 9, 7, 8,10,12,10,
  127074. 13,15,11,11,10, 9,10,13,13,16,17,14,15,14,13,14,
  127075. 17,
  127076. };
  127077. static static_codebook _huff_book__44cn1_sm_long = {
  127078. 2, 81,
  127079. _huff_lengthlist__44cn1_sm_long,
  127080. 0, 0, 0, 0, 0,
  127081. NULL,
  127082. NULL,
  127083. NULL,
  127084. NULL,
  127085. 0
  127086. };
  127087. static long _vq_quantlist__44cn1_sm_p1_0[] = {
  127088. 1,
  127089. 0,
  127090. 2,
  127091. };
  127092. static long _vq_lengthlist__44cn1_sm_p1_0[] = {
  127093. 1, 4, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  127094. 0, 0, 5, 7, 7, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0,
  127099. 0, 0, 0, 7, 8, 9, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  127104. 0, 0, 0, 0, 8, 9, 9, 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, 5, 8, 8, 0, 0, 0, 0,
  127139. 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 7,10, 9, 0, 0, 0,
  127144. 0, 0, 0, 9, 9,10, 0, 0, 0, 0, 0, 0, 9,10,10, 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, 7, 9, 9, 0, 0,
  127149. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  127185. 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  127190. 0, 0, 0, 0, 0, 8, 9,10, 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, 7, 9,10, 0, 0, 0, 0, 0, 0, 9,10,10,
  127195. 0, 0, 0, 0, 0, 0, 9,10, 9, 0, 0, 0, 0, 0, 0, 0,
  127196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127503. 0,
  127504. };
  127505. static float _vq_quantthresh__44cn1_sm_p1_0[] = {
  127506. -0.5, 0.5,
  127507. };
  127508. static long _vq_quantmap__44cn1_sm_p1_0[] = {
  127509. 1, 0, 2,
  127510. };
  127511. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p1_0 = {
  127512. _vq_quantthresh__44cn1_sm_p1_0,
  127513. _vq_quantmap__44cn1_sm_p1_0,
  127514. 3,
  127515. 3
  127516. };
  127517. static static_codebook _44cn1_sm_p1_0 = {
  127518. 8, 6561,
  127519. _vq_lengthlist__44cn1_sm_p1_0,
  127520. 1, -535822336, 1611661312, 2, 0,
  127521. _vq_quantlist__44cn1_sm_p1_0,
  127522. NULL,
  127523. &_vq_auxt__44cn1_sm_p1_0,
  127524. NULL,
  127525. 0
  127526. };
  127527. static long _vq_quantlist__44cn1_sm_p2_0[] = {
  127528. 2,
  127529. 1,
  127530. 3,
  127531. 0,
  127532. 4,
  127533. };
  127534. static long _vq_lengthlist__44cn1_sm_p2_0[] = {
  127535. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  127537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127538. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  127540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127541. 0, 0, 0, 0, 7, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  127542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127574. 0,
  127575. };
  127576. static float _vq_quantthresh__44cn1_sm_p2_0[] = {
  127577. -1.5, -0.5, 0.5, 1.5,
  127578. };
  127579. static long _vq_quantmap__44cn1_sm_p2_0[] = {
  127580. 3, 1, 0, 2, 4,
  127581. };
  127582. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p2_0 = {
  127583. _vq_quantthresh__44cn1_sm_p2_0,
  127584. _vq_quantmap__44cn1_sm_p2_0,
  127585. 5,
  127586. 5
  127587. };
  127588. static static_codebook _44cn1_sm_p2_0 = {
  127589. 4, 625,
  127590. _vq_lengthlist__44cn1_sm_p2_0,
  127591. 1, -533725184, 1611661312, 3, 0,
  127592. _vq_quantlist__44cn1_sm_p2_0,
  127593. NULL,
  127594. &_vq_auxt__44cn1_sm_p2_0,
  127595. NULL,
  127596. 0
  127597. };
  127598. static long _vq_quantlist__44cn1_sm_p3_0[] = {
  127599. 4,
  127600. 3,
  127601. 5,
  127602. 2,
  127603. 6,
  127604. 1,
  127605. 7,
  127606. 0,
  127607. 8,
  127608. };
  127609. static long _vq_lengthlist__44cn1_sm_p3_0[] = {
  127610. 1, 3, 4, 7, 7, 0, 0, 0, 0, 0, 4, 4, 7, 7, 0, 0,
  127611. 0, 0, 0, 4, 5, 7, 7, 0, 0, 0, 0, 0, 6, 7, 8, 8,
  127612. 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  127613. 9, 9, 0, 0, 0, 0, 0, 0, 0,10, 9, 0, 0, 0, 0, 0,
  127614. 0, 0,11,11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127615. 0,
  127616. };
  127617. static float _vq_quantthresh__44cn1_sm_p3_0[] = {
  127618. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  127619. };
  127620. static long _vq_quantmap__44cn1_sm_p3_0[] = {
  127621. 7, 5, 3, 1, 0, 2, 4, 6,
  127622. 8,
  127623. };
  127624. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p3_0 = {
  127625. _vq_quantthresh__44cn1_sm_p3_0,
  127626. _vq_quantmap__44cn1_sm_p3_0,
  127627. 9,
  127628. 9
  127629. };
  127630. static static_codebook _44cn1_sm_p3_0 = {
  127631. 2, 81,
  127632. _vq_lengthlist__44cn1_sm_p3_0,
  127633. 1, -531628032, 1611661312, 4, 0,
  127634. _vq_quantlist__44cn1_sm_p3_0,
  127635. NULL,
  127636. &_vq_auxt__44cn1_sm_p3_0,
  127637. NULL,
  127638. 0
  127639. };
  127640. static long _vq_quantlist__44cn1_sm_p4_0[] = {
  127641. 4,
  127642. 3,
  127643. 5,
  127644. 2,
  127645. 6,
  127646. 1,
  127647. 7,
  127648. 0,
  127649. 8,
  127650. };
  127651. static long _vq_lengthlist__44cn1_sm_p4_0[] = {
  127652. 1, 4, 3, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 8, 7,
  127653. 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  127654. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  127655. 9, 9, 9, 9,10,10, 0, 0, 0, 9, 9, 9, 9,10,10, 0,
  127656. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0,10,10,11,
  127657. 11,
  127658. };
  127659. static float _vq_quantthresh__44cn1_sm_p4_0[] = {
  127660. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  127661. };
  127662. static long _vq_quantmap__44cn1_sm_p4_0[] = {
  127663. 7, 5, 3, 1, 0, 2, 4, 6,
  127664. 8,
  127665. };
  127666. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p4_0 = {
  127667. _vq_quantthresh__44cn1_sm_p4_0,
  127668. _vq_quantmap__44cn1_sm_p4_0,
  127669. 9,
  127670. 9
  127671. };
  127672. static static_codebook _44cn1_sm_p4_0 = {
  127673. 2, 81,
  127674. _vq_lengthlist__44cn1_sm_p4_0,
  127675. 1, -531628032, 1611661312, 4, 0,
  127676. _vq_quantlist__44cn1_sm_p4_0,
  127677. NULL,
  127678. &_vq_auxt__44cn1_sm_p4_0,
  127679. NULL,
  127680. 0
  127681. };
  127682. static long _vq_quantlist__44cn1_sm_p5_0[] = {
  127683. 8,
  127684. 7,
  127685. 9,
  127686. 6,
  127687. 10,
  127688. 5,
  127689. 11,
  127690. 4,
  127691. 12,
  127692. 3,
  127693. 13,
  127694. 2,
  127695. 14,
  127696. 1,
  127697. 15,
  127698. 0,
  127699. 16,
  127700. };
  127701. static long _vq_lengthlist__44cn1_sm_p5_0[] = {
  127702. 1, 4, 4, 6, 6, 8, 8, 9, 9, 8, 8, 9, 9,10,10,11,
  127703. 11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  127704. 12,12, 0, 6, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  127705. 11,12,12, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  127706. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,10,11,
  127707. 11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  127708. 11,11,12,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  127709. 10,11,11,12,12,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  127710. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,10,
  127711. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  127712. 10,10,11,11,12,12,13,13,13,13, 0, 0, 0, 0, 0, 9,
  127713. 9,10,10,11,11,12,12,12,13,13,13, 0, 0, 0, 0, 0,
  127714. 10,10,11,11,11,11,12,12,13,13,14,14, 0, 0, 0, 0,
  127715. 0, 0, 0,11,11,11,11,12,12,13,13,14,14, 0, 0, 0,
  127716. 0, 0, 0, 0,11,11,12,12,13,13,13,13,14,14, 0, 0,
  127717. 0, 0, 0, 0, 0,11,11,12,12,13,13,13,13,14,14, 0,
  127718. 0, 0, 0, 0, 0, 0,12,12,12,13,13,13,14,14,14,14,
  127719. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,14,14,14,
  127720. 14,
  127721. };
  127722. static float _vq_quantthresh__44cn1_sm_p5_0[] = {
  127723. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  127724. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  127725. };
  127726. static long _vq_quantmap__44cn1_sm_p5_0[] = {
  127727. 15, 13, 11, 9, 7, 5, 3, 1,
  127728. 0, 2, 4, 6, 8, 10, 12, 14,
  127729. 16,
  127730. };
  127731. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p5_0 = {
  127732. _vq_quantthresh__44cn1_sm_p5_0,
  127733. _vq_quantmap__44cn1_sm_p5_0,
  127734. 17,
  127735. 17
  127736. };
  127737. static static_codebook _44cn1_sm_p5_0 = {
  127738. 2, 289,
  127739. _vq_lengthlist__44cn1_sm_p5_0,
  127740. 1, -529530880, 1611661312, 5, 0,
  127741. _vq_quantlist__44cn1_sm_p5_0,
  127742. NULL,
  127743. &_vq_auxt__44cn1_sm_p5_0,
  127744. NULL,
  127745. 0
  127746. };
  127747. static long _vq_quantlist__44cn1_sm_p6_0[] = {
  127748. 1,
  127749. 0,
  127750. 2,
  127751. };
  127752. static long _vq_lengthlist__44cn1_sm_p6_0[] = {
  127753. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 6,10, 9, 9,11,
  127754. 9, 9, 4, 6, 7,10, 9, 9,11, 9, 9, 7,10,10,10,11,
  127755. 11,11,11,10, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  127756. 11,10,11,11,10,10, 7,11,11,11,11,11,12,11,11, 7,
  127757. 9, 9,11,10,10,12,10,10, 7, 9, 9,11,10,10,11,10,
  127758. 10,
  127759. };
  127760. static float _vq_quantthresh__44cn1_sm_p6_0[] = {
  127761. -5.5, 5.5,
  127762. };
  127763. static long _vq_quantmap__44cn1_sm_p6_0[] = {
  127764. 1, 0, 2,
  127765. };
  127766. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p6_0 = {
  127767. _vq_quantthresh__44cn1_sm_p6_0,
  127768. _vq_quantmap__44cn1_sm_p6_0,
  127769. 3,
  127770. 3
  127771. };
  127772. static static_codebook _44cn1_sm_p6_0 = {
  127773. 4, 81,
  127774. _vq_lengthlist__44cn1_sm_p6_0,
  127775. 1, -529137664, 1618345984, 2, 0,
  127776. _vq_quantlist__44cn1_sm_p6_0,
  127777. NULL,
  127778. &_vq_auxt__44cn1_sm_p6_0,
  127779. NULL,
  127780. 0
  127781. };
  127782. static long _vq_quantlist__44cn1_sm_p6_1[] = {
  127783. 5,
  127784. 4,
  127785. 6,
  127786. 3,
  127787. 7,
  127788. 2,
  127789. 8,
  127790. 1,
  127791. 9,
  127792. 0,
  127793. 10,
  127794. };
  127795. static long _vq_lengthlist__44cn1_sm_p6_1[] = {
  127796. 2, 4, 4, 5, 5, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  127797. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  127798. 8,10, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  127799. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  127800. 8, 8,10,10,10, 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  127801. 8, 8, 8, 8, 8, 8, 9, 9,10,10,10,10,10, 8, 8, 8,
  127802. 8, 9, 9,10,10,10,10,10, 9, 9, 9, 9, 8, 9,10,10,
  127803. 10,10,10, 8, 9, 8, 8, 9, 8,
  127804. };
  127805. static float _vq_quantthresh__44cn1_sm_p6_1[] = {
  127806. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  127807. 3.5, 4.5,
  127808. };
  127809. static long _vq_quantmap__44cn1_sm_p6_1[] = {
  127810. 9, 7, 5, 3, 1, 0, 2, 4,
  127811. 6, 8, 10,
  127812. };
  127813. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p6_1 = {
  127814. _vq_quantthresh__44cn1_sm_p6_1,
  127815. _vq_quantmap__44cn1_sm_p6_1,
  127816. 11,
  127817. 11
  127818. };
  127819. static static_codebook _44cn1_sm_p6_1 = {
  127820. 2, 121,
  127821. _vq_lengthlist__44cn1_sm_p6_1,
  127822. 1, -531365888, 1611661312, 4, 0,
  127823. _vq_quantlist__44cn1_sm_p6_1,
  127824. NULL,
  127825. &_vq_auxt__44cn1_sm_p6_1,
  127826. NULL,
  127827. 0
  127828. };
  127829. static long _vq_quantlist__44cn1_sm_p7_0[] = {
  127830. 6,
  127831. 5,
  127832. 7,
  127833. 4,
  127834. 8,
  127835. 3,
  127836. 9,
  127837. 2,
  127838. 10,
  127839. 1,
  127840. 11,
  127841. 0,
  127842. 12,
  127843. };
  127844. static long _vq_lengthlist__44cn1_sm_p7_0[] = {
  127845. 1, 4, 4, 6, 6, 7, 7, 7, 7, 9, 9,10,10, 7, 5, 5,
  127846. 7, 7, 8, 8, 8, 8,10, 9,11,10, 7, 5, 5, 7, 7, 8,
  127847. 8, 8, 8, 9,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  127848. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  127849. 11, 0,12,12, 9, 9, 9,10,10,10,11,11,12,12, 0,13,
  127850. 13, 9, 9, 9, 9,10,10,11,11,12,12, 0, 0, 0,10,10,
  127851. 10,10,11,11,12,12,12,13, 0, 0, 0,10,10,10,10,11,
  127852. 11,12,12,12,12, 0, 0, 0,14,14,11,11,11,11,12,13,
  127853. 13,13, 0, 0, 0,14,14,11,10,11,11,12,12,13,13, 0,
  127854. 0, 0, 0, 0,12,12,12,12,13,13,13,14, 0, 0, 0, 0,
  127855. 0,13,12,12,12,13,13,13,14,
  127856. };
  127857. static float _vq_quantthresh__44cn1_sm_p7_0[] = {
  127858. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  127859. 12.5, 17.5, 22.5, 27.5,
  127860. };
  127861. static long _vq_quantmap__44cn1_sm_p7_0[] = {
  127862. 11, 9, 7, 5, 3, 1, 0, 2,
  127863. 4, 6, 8, 10, 12,
  127864. };
  127865. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p7_0 = {
  127866. _vq_quantthresh__44cn1_sm_p7_0,
  127867. _vq_quantmap__44cn1_sm_p7_0,
  127868. 13,
  127869. 13
  127870. };
  127871. static static_codebook _44cn1_sm_p7_0 = {
  127872. 2, 169,
  127873. _vq_lengthlist__44cn1_sm_p7_0,
  127874. 1, -526516224, 1616117760, 4, 0,
  127875. _vq_quantlist__44cn1_sm_p7_0,
  127876. NULL,
  127877. &_vq_auxt__44cn1_sm_p7_0,
  127878. NULL,
  127879. 0
  127880. };
  127881. static long _vq_quantlist__44cn1_sm_p7_1[] = {
  127882. 2,
  127883. 1,
  127884. 3,
  127885. 0,
  127886. 4,
  127887. };
  127888. static long _vq_lengthlist__44cn1_sm_p7_1[] = {
  127889. 2, 4, 4, 4, 5, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  127890. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  127891. };
  127892. static float _vq_quantthresh__44cn1_sm_p7_1[] = {
  127893. -1.5, -0.5, 0.5, 1.5,
  127894. };
  127895. static long _vq_quantmap__44cn1_sm_p7_1[] = {
  127896. 3, 1, 0, 2, 4,
  127897. };
  127898. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p7_1 = {
  127899. _vq_quantthresh__44cn1_sm_p7_1,
  127900. _vq_quantmap__44cn1_sm_p7_1,
  127901. 5,
  127902. 5
  127903. };
  127904. static static_codebook _44cn1_sm_p7_1 = {
  127905. 2, 25,
  127906. _vq_lengthlist__44cn1_sm_p7_1,
  127907. 1, -533725184, 1611661312, 3, 0,
  127908. _vq_quantlist__44cn1_sm_p7_1,
  127909. NULL,
  127910. &_vq_auxt__44cn1_sm_p7_1,
  127911. NULL,
  127912. 0
  127913. };
  127914. static long _vq_quantlist__44cn1_sm_p8_0[] = {
  127915. 4,
  127916. 3,
  127917. 5,
  127918. 2,
  127919. 6,
  127920. 1,
  127921. 7,
  127922. 0,
  127923. 8,
  127924. };
  127925. static long _vq_lengthlist__44cn1_sm_p8_0[] = {
  127926. 1, 4, 4,12,11,13,13,14,14, 4, 7, 7,11,13,14,14,
  127927. 14,14, 3, 8, 3,14,14,14,14,14,14,14,10,12,14,14,
  127928. 14,14,14,14,14,14, 5,14, 8,14,14,14,14,14,12,14,
  127929. 13,14,14,14,14,14,14,14,13,14,10,14,14,14,14,14,
  127930. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  127931. 14,
  127932. };
  127933. static float _vq_quantthresh__44cn1_sm_p8_0[] = {
  127934. -773.5, -552.5, -331.5, -110.5, 110.5, 331.5, 552.5, 773.5,
  127935. };
  127936. static long _vq_quantmap__44cn1_sm_p8_0[] = {
  127937. 7, 5, 3, 1, 0, 2, 4, 6,
  127938. 8,
  127939. };
  127940. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p8_0 = {
  127941. _vq_quantthresh__44cn1_sm_p8_0,
  127942. _vq_quantmap__44cn1_sm_p8_0,
  127943. 9,
  127944. 9
  127945. };
  127946. static static_codebook _44cn1_sm_p8_0 = {
  127947. 2, 81,
  127948. _vq_lengthlist__44cn1_sm_p8_0,
  127949. 1, -516186112, 1627103232, 4, 0,
  127950. _vq_quantlist__44cn1_sm_p8_0,
  127951. NULL,
  127952. &_vq_auxt__44cn1_sm_p8_0,
  127953. NULL,
  127954. 0
  127955. };
  127956. static long _vq_quantlist__44cn1_sm_p8_1[] = {
  127957. 6,
  127958. 5,
  127959. 7,
  127960. 4,
  127961. 8,
  127962. 3,
  127963. 9,
  127964. 2,
  127965. 10,
  127966. 1,
  127967. 11,
  127968. 0,
  127969. 12,
  127970. };
  127971. static long _vq_lengthlist__44cn1_sm_p8_1[] = {
  127972. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,11,11,11, 6, 5, 5,
  127973. 7, 7, 8, 8,10,10,10,11,11,11, 6, 5, 5, 7, 7, 8,
  127974. 8,10,10,11,12,12,12,14, 7, 7, 7, 8, 9, 9,11,11,
  127975. 11,12,11,12,17, 7, 7, 8, 7, 9, 9,11,11,12,12,12,
  127976. 12,14,11,11, 8, 8,10,10,11,12,12,13,11,12,14,11,
  127977. 11, 8, 8,10,10,11,12,12,13,13,12,14,15,14,10,10,
  127978. 10,10,11,12,12,12,12,11,14,13,16,10,10,10, 9,12,
  127979. 11,12,12,13,14,14,15,14,14,13,10,10,11,11,12,11,
  127980. 13,11,14,12,15,13,14,11,10,12,10,12,12,13,13,13,
  127981. 13,14,15,15,12,12,11,11,12,11,13,12,14,14,14,14,
  127982. 17,12,12,11,10,13,11,13,13,
  127983. };
  127984. static float _vq_quantthresh__44cn1_sm_p8_1[] = {
  127985. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  127986. 42.5, 59.5, 76.5, 93.5,
  127987. };
  127988. static long _vq_quantmap__44cn1_sm_p8_1[] = {
  127989. 11, 9, 7, 5, 3, 1, 0, 2,
  127990. 4, 6, 8, 10, 12,
  127991. };
  127992. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p8_1 = {
  127993. _vq_quantthresh__44cn1_sm_p8_1,
  127994. _vq_quantmap__44cn1_sm_p8_1,
  127995. 13,
  127996. 13
  127997. };
  127998. static static_codebook _44cn1_sm_p8_1 = {
  127999. 2, 169,
  128000. _vq_lengthlist__44cn1_sm_p8_1,
  128001. 1, -522616832, 1620115456, 4, 0,
  128002. _vq_quantlist__44cn1_sm_p8_1,
  128003. NULL,
  128004. &_vq_auxt__44cn1_sm_p8_1,
  128005. NULL,
  128006. 0
  128007. };
  128008. static long _vq_quantlist__44cn1_sm_p8_2[] = {
  128009. 8,
  128010. 7,
  128011. 9,
  128012. 6,
  128013. 10,
  128014. 5,
  128015. 11,
  128016. 4,
  128017. 12,
  128018. 3,
  128019. 13,
  128020. 2,
  128021. 14,
  128022. 1,
  128023. 15,
  128024. 0,
  128025. 16,
  128026. };
  128027. static long _vq_lengthlist__44cn1_sm_p8_2[] = {
  128028. 3, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  128029. 9,10, 6, 6, 6, 6, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  128030. 9, 9,10, 6, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  128031. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  128032. 9, 9, 9, 9,10,10,10, 7, 7, 7, 8, 8, 8, 9, 9, 9,
  128033. 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 8, 8, 9, 9,
  128034. 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 8, 8, 9,
  128035. 9, 9, 9, 9, 9, 9, 9,11,10,11, 8, 8, 8, 8, 8, 8,
  128036. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,11,11, 8, 8, 8,
  128037. 8, 9, 9, 9, 9, 9, 9, 9, 9,11,10,11,11,11, 9, 9,
  128038. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,11,10,11,11, 9,
  128039. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,11,11,10,11,11,
  128040. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,11,11,
  128041. 11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,11,11,
  128042. 11,11,11,11, 9,10,10,10, 9, 9, 9, 9, 9, 9,11,10,
  128043. 11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  128044. 11,11,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  128045. 10,11,11,11,11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9,
  128046. 9,
  128047. };
  128048. static float _vq_quantthresh__44cn1_sm_p8_2[] = {
  128049. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  128050. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  128051. };
  128052. static long _vq_quantmap__44cn1_sm_p8_2[] = {
  128053. 15, 13, 11, 9, 7, 5, 3, 1,
  128054. 0, 2, 4, 6, 8, 10, 12, 14,
  128055. 16,
  128056. };
  128057. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p8_2 = {
  128058. _vq_quantthresh__44cn1_sm_p8_2,
  128059. _vq_quantmap__44cn1_sm_p8_2,
  128060. 17,
  128061. 17
  128062. };
  128063. static static_codebook _44cn1_sm_p8_2 = {
  128064. 2, 289,
  128065. _vq_lengthlist__44cn1_sm_p8_2,
  128066. 1, -529530880, 1611661312, 5, 0,
  128067. _vq_quantlist__44cn1_sm_p8_2,
  128068. NULL,
  128069. &_vq_auxt__44cn1_sm_p8_2,
  128070. NULL,
  128071. 0
  128072. };
  128073. static long _huff_lengthlist__44cn1_sm_short[] = {
  128074. 5, 6,12,14,12,14,16,17,18, 4, 2, 5,11, 7,10,12,
  128075. 14,15, 9, 4, 5,11, 7,10,13,15,18,15, 6, 7, 5, 6,
  128076. 8,11,13,16,11, 5, 6, 5, 5, 6, 9,13,15,12, 5, 7,
  128077. 6, 5, 6, 9,12,14,12, 6, 7, 8, 6, 7, 9,12,13,14,
  128078. 8, 8, 7, 5, 5, 8,10,12,16, 9, 9, 8, 6, 6, 7, 9,
  128079. 9,
  128080. };
  128081. static static_codebook _huff_book__44cn1_sm_short = {
  128082. 2, 81,
  128083. _huff_lengthlist__44cn1_sm_short,
  128084. 0, 0, 0, 0, 0,
  128085. NULL,
  128086. NULL,
  128087. NULL,
  128088. NULL,
  128089. 0
  128090. };
  128091. /*** End of inlined file: res_books_stereo.h ***/
  128092. static vorbis_info_residue0 _residue_44_low={
  128093. 0,-1, -1, 9,-1,
  128094. {0},
  128095. {-1},
  128096. { .5, 1.5, 2.5, 2.5, 4.5, 8.5, 16.5, 32.5},
  128097. { .5, .5, .5, 999., 4.5, 8.5, 16.5, 32.5},
  128098. };
  128099. static vorbis_info_residue0 _residue_44_mid={
  128100. 0,-1, -1, 10,-1,
  128101. {0},
  128102. {-1},
  128103. { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 8.5, 16.5, 32.5},
  128104. { .5, .5, 999., .5, 999., 4.5, 8.5, 16.5, 32.5},
  128105. };
  128106. static vorbis_info_residue0 _residue_44_high={
  128107. 0,-1, -1, 10,-1,
  128108. {0},
  128109. {-1},
  128110. { .5, 1.5, 2.5, 4.5, 8.5, 16.5, 32.5, 71.5,157.5},
  128111. { .5, 1.5, 2.5, 3.5, 4.5, 8.5, 16.5, 71.5,157.5},
  128112. };
  128113. static static_bookblock _resbook_44s_n1={
  128114. {
  128115. {0},{0,0,&_44cn1_s_p1_0},{0,0,&_44cn1_s_p2_0},
  128116. {0,0,&_44cn1_s_p3_0},{0,0,&_44cn1_s_p4_0},{0,0,&_44cn1_s_p5_0},
  128117. {&_44cn1_s_p6_0,&_44cn1_s_p6_1},{&_44cn1_s_p7_0,&_44cn1_s_p7_1},
  128118. {&_44cn1_s_p8_0,&_44cn1_s_p8_1,&_44cn1_s_p8_2}
  128119. }
  128120. };
  128121. static static_bookblock _resbook_44sm_n1={
  128122. {
  128123. {0},{0,0,&_44cn1_sm_p1_0},{0,0,&_44cn1_sm_p2_0},
  128124. {0,0,&_44cn1_sm_p3_0},{0,0,&_44cn1_sm_p4_0},{0,0,&_44cn1_sm_p5_0},
  128125. {&_44cn1_sm_p6_0,&_44cn1_sm_p6_1},{&_44cn1_sm_p7_0,&_44cn1_sm_p7_1},
  128126. {&_44cn1_sm_p8_0,&_44cn1_sm_p8_1,&_44cn1_sm_p8_2}
  128127. }
  128128. };
  128129. static static_bookblock _resbook_44s_0={
  128130. {
  128131. {0},{0,0,&_44c0_s_p1_0},{0,0,&_44c0_s_p2_0},
  128132. {0,0,&_44c0_s_p3_0},{0,0,&_44c0_s_p4_0},{0,0,&_44c0_s_p5_0},
  128133. {&_44c0_s_p6_0,&_44c0_s_p6_1},{&_44c0_s_p7_0,&_44c0_s_p7_1},
  128134. {&_44c0_s_p8_0,&_44c0_s_p8_1,&_44c0_s_p8_2}
  128135. }
  128136. };
  128137. static static_bookblock _resbook_44sm_0={
  128138. {
  128139. {0},{0,0,&_44c0_sm_p1_0},{0,0,&_44c0_sm_p2_0},
  128140. {0,0,&_44c0_sm_p3_0},{0,0,&_44c0_sm_p4_0},{0,0,&_44c0_sm_p5_0},
  128141. {&_44c0_sm_p6_0,&_44c0_sm_p6_1},{&_44c0_sm_p7_0,&_44c0_sm_p7_1},
  128142. {&_44c0_sm_p8_0,&_44c0_sm_p8_1,&_44c0_sm_p8_2}
  128143. }
  128144. };
  128145. static static_bookblock _resbook_44s_1={
  128146. {
  128147. {0},{0,0,&_44c1_s_p1_0},{0,0,&_44c1_s_p2_0},
  128148. {0,0,&_44c1_s_p3_0},{0,0,&_44c1_s_p4_0},{0,0,&_44c1_s_p5_0},
  128149. {&_44c1_s_p6_0,&_44c1_s_p6_1},{&_44c1_s_p7_0,&_44c1_s_p7_1},
  128150. {&_44c1_s_p8_0,&_44c1_s_p8_1,&_44c1_s_p8_2}
  128151. }
  128152. };
  128153. static static_bookblock _resbook_44sm_1={
  128154. {
  128155. {0},{0,0,&_44c1_sm_p1_0},{0,0,&_44c1_sm_p2_0},
  128156. {0,0,&_44c1_sm_p3_0},{0,0,&_44c1_sm_p4_0},{0,0,&_44c1_sm_p5_0},
  128157. {&_44c1_sm_p6_0,&_44c1_sm_p6_1},{&_44c1_sm_p7_0,&_44c1_sm_p7_1},
  128158. {&_44c1_sm_p8_0,&_44c1_sm_p8_1,&_44c1_sm_p8_2}
  128159. }
  128160. };
  128161. static static_bookblock _resbook_44s_2={
  128162. {
  128163. {0},{0,0,&_44c2_s_p1_0},{0,0,&_44c2_s_p2_0},{0,0,&_44c2_s_p3_0},
  128164. {0,0,&_44c2_s_p4_0},{0,0,&_44c2_s_p5_0},{0,0,&_44c2_s_p6_0},
  128165. {&_44c2_s_p7_0,&_44c2_s_p7_1},{&_44c2_s_p8_0,&_44c2_s_p8_1},
  128166. {&_44c2_s_p9_0,&_44c2_s_p9_1,&_44c2_s_p9_2}
  128167. }
  128168. };
  128169. static static_bookblock _resbook_44s_3={
  128170. {
  128171. {0},{0,0,&_44c3_s_p1_0},{0,0,&_44c3_s_p2_0},{0,0,&_44c3_s_p3_0},
  128172. {0,0,&_44c3_s_p4_0},{0,0,&_44c3_s_p5_0},{0,0,&_44c3_s_p6_0},
  128173. {&_44c3_s_p7_0,&_44c3_s_p7_1},{&_44c3_s_p8_0,&_44c3_s_p8_1},
  128174. {&_44c3_s_p9_0,&_44c3_s_p9_1,&_44c3_s_p9_2}
  128175. }
  128176. };
  128177. static static_bookblock _resbook_44s_4={
  128178. {
  128179. {0},{0,0,&_44c4_s_p1_0},{0,0,&_44c4_s_p2_0},{0,0,&_44c4_s_p3_0},
  128180. {0,0,&_44c4_s_p4_0},{0,0,&_44c4_s_p5_0},{0,0,&_44c4_s_p6_0},
  128181. {&_44c4_s_p7_0,&_44c4_s_p7_1},{&_44c4_s_p8_0,&_44c4_s_p8_1},
  128182. {&_44c4_s_p9_0,&_44c4_s_p9_1,&_44c4_s_p9_2}
  128183. }
  128184. };
  128185. static static_bookblock _resbook_44s_5={
  128186. {
  128187. {0},{0,0,&_44c5_s_p1_0},{0,0,&_44c5_s_p2_0},{0,0,&_44c5_s_p3_0},
  128188. {0,0,&_44c5_s_p4_0},{0,0,&_44c5_s_p5_0},{0,0,&_44c5_s_p6_0},
  128189. {&_44c5_s_p7_0,&_44c5_s_p7_1},{&_44c5_s_p8_0,&_44c5_s_p8_1},
  128190. {&_44c5_s_p9_0,&_44c5_s_p9_1,&_44c5_s_p9_2}
  128191. }
  128192. };
  128193. static static_bookblock _resbook_44s_6={
  128194. {
  128195. {0},{0,0,&_44c6_s_p1_0},{0,0,&_44c6_s_p2_0},{0,0,&_44c6_s_p3_0},
  128196. {0,0,&_44c6_s_p4_0},
  128197. {&_44c6_s_p5_0,&_44c6_s_p5_1},
  128198. {&_44c6_s_p6_0,&_44c6_s_p6_1},
  128199. {&_44c6_s_p7_0,&_44c6_s_p7_1},
  128200. {&_44c6_s_p8_0,&_44c6_s_p8_1},
  128201. {&_44c6_s_p9_0,&_44c6_s_p9_1,&_44c6_s_p9_2}
  128202. }
  128203. };
  128204. static static_bookblock _resbook_44s_7={
  128205. {
  128206. {0},{0,0,&_44c7_s_p1_0},{0,0,&_44c7_s_p2_0},{0,0,&_44c7_s_p3_0},
  128207. {0,0,&_44c7_s_p4_0},
  128208. {&_44c7_s_p5_0,&_44c7_s_p5_1},
  128209. {&_44c7_s_p6_0,&_44c7_s_p6_1},
  128210. {&_44c7_s_p7_0,&_44c7_s_p7_1},
  128211. {&_44c7_s_p8_0,&_44c7_s_p8_1},
  128212. {&_44c7_s_p9_0,&_44c7_s_p9_1,&_44c7_s_p9_2}
  128213. }
  128214. };
  128215. static static_bookblock _resbook_44s_8={
  128216. {
  128217. {0},{0,0,&_44c8_s_p1_0},{0,0,&_44c8_s_p2_0},{0,0,&_44c8_s_p3_0},
  128218. {0,0,&_44c8_s_p4_0},
  128219. {&_44c8_s_p5_0,&_44c8_s_p5_1},
  128220. {&_44c8_s_p6_0,&_44c8_s_p6_1},
  128221. {&_44c8_s_p7_0,&_44c8_s_p7_1},
  128222. {&_44c8_s_p8_0,&_44c8_s_p8_1},
  128223. {&_44c8_s_p9_0,&_44c8_s_p9_1,&_44c8_s_p9_2}
  128224. }
  128225. };
  128226. static static_bookblock _resbook_44s_9={
  128227. {
  128228. {0},{0,0,&_44c9_s_p1_0},{0,0,&_44c9_s_p2_0},{0,0,&_44c9_s_p3_0},
  128229. {0,0,&_44c9_s_p4_0},
  128230. {&_44c9_s_p5_0,&_44c9_s_p5_1},
  128231. {&_44c9_s_p6_0,&_44c9_s_p6_1},
  128232. {&_44c9_s_p7_0,&_44c9_s_p7_1},
  128233. {&_44c9_s_p8_0,&_44c9_s_p8_1},
  128234. {&_44c9_s_p9_0,&_44c9_s_p9_1,&_44c9_s_p9_2}
  128235. }
  128236. };
  128237. static vorbis_residue_template _res_44s_n1[]={
  128238. {2,0, &_residue_44_low,
  128239. &_huff_book__44cn1_s_short,&_huff_book__44cn1_sm_short,
  128240. &_resbook_44s_n1,&_resbook_44sm_n1},
  128241. {2,0, &_residue_44_low,
  128242. &_huff_book__44cn1_s_long,&_huff_book__44cn1_sm_long,
  128243. &_resbook_44s_n1,&_resbook_44sm_n1}
  128244. };
  128245. static vorbis_residue_template _res_44s_0[]={
  128246. {2,0, &_residue_44_low,
  128247. &_huff_book__44c0_s_short,&_huff_book__44c0_sm_short,
  128248. &_resbook_44s_0,&_resbook_44sm_0},
  128249. {2,0, &_residue_44_low,
  128250. &_huff_book__44c0_s_long,&_huff_book__44c0_sm_long,
  128251. &_resbook_44s_0,&_resbook_44sm_0}
  128252. };
  128253. static vorbis_residue_template _res_44s_1[]={
  128254. {2,0, &_residue_44_low,
  128255. &_huff_book__44c1_s_short,&_huff_book__44c1_sm_short,
  128256. &_resbook_44s_1,&_resbook_44sm_1},
  128257. {2,0, &_residue_44_low,
  128258. &_huff_book__44c1_s_long,&_huff_book__44c1_sm_long,
  128259. &_resbook_44s_1,&_resbook_44sm_1}
  128260. };
  128261. static vorbis_residue_template _res_44s_2[]={
  128262. {2,0, &_residue_44_mid,
  128263. &_huff_book__44c2_s_short,&_huff_book__44c2_s_short,
  128264. &_resbook_44s_2,&_resbook_44s_2},
  128265. {2,0, &_residue_44_mid,
  128266. &_huff_book__44c2_s_long,&_huff_book__44c2_s_long,
  128267. &_resbook_44s_2,&_resbook_44s_2}
  128268. };
  128269. static vorbis_residue_template _res_44s_3[]={
  128270. {2,0, &_residue_44_mid,
  128271. &_huff_book__44c3_s_short,&_huff_book__44c3_s_short,
  128272. &_resbook_44s_3,&_resbook_44s_3},
  128273. {2,0, &_residue_44_mid,
  128274. &_huff_book__44c3_s_long,&_huff_book__44c3_s_long,
  128275. &_resbook_44s_3,&_resbook_44s_3}
  128276. };
  128277. static vorbis_residue_template _res_44s_4[]={
  128278. {2,0, &_residue_44_mid,
  128279. &_huff_book__44c4_s_short,&_huff_book__44c4_s_short,
  128280. &_resbook_44s_4,&_resbook_44s_4},
  128281. {2,0, &_residue_44_mid,
  128282. &_huff_book__44c4_s_long,&_huff_book__44c4_s_long,
  128283. &_resbook_44s_4,&_resbook_44s_4}
  128284. };
  128285. static vorbis_residue_template _res_44s_5[]={
  128286. {2,0, &_residue_44_mid,
  128287. &_huff_book__44c5_s_short,&_huff_book__44c5_s_short,
  128288. &_resbook_44s_5,&_resbook_44s_5},
  128289. {2,0, &_residue_44_mid,
  128290. &_huff_book__44c5_s_long,&_huff_book__44c5_s_long,
  128291. &_resbook_44s_5,&_resbook_44s_5}
  128292. };
  128293. static vorbis_residue_template _res_44s_6[]={
  128294. {2,0, &_residue_44_high,
  128295. &_huff_book__44c6_s_short,&_huff_book__44c6_s_short,
  128296. &_resbook_44s_6,&_resbook_44s_6},
  128297. {2,0, &_residue_44_high,
  128298. &_huff_book__44c6_s_long,&_huff_book__44c6_s_long,
  128299. &_resbook_44s_6,&_resbook_44s_6}
  128300. };
  128301. static vorbis_residue_template _res_44s_7[]={
  128302. {2,0, &_residue_44_high,
  128303. &_huff_book__44c7_s_short,&_huff_book__44c7_s_short,
  128304. &_resbook_44s_7,&_resbook_44s_7},
  128305. {2,0, &_residue_44_high,
  128306. &_huff_book__44c7_s_long,&_huff_book__44c7_s_long,
  128307. &_resbook_44s_7,&_resbook_44s_7}
  128308. };
  128309. static vorbis_residue_template _res_44s_8[]={
  128310. {2,0, &_residue_44_high,
  128311. &_huff_book__44c8_s_short,&_huff_book__44c8_s_short,
  128312. &_resbook_44s_8,&_resbook_44s_8},
  128313. {2,0, &_residue_44_high,
  128314. &_huff_book__44c8_s_long,&_huff_book__44c8_s_long,
  128315. &_resbook_44s_8,&_resbook_44s_8}
  128316. };
  128317. static vorbis_residue_template _res_44s_9[]={
  128318. {2,0, &_residue_44_high,
  128319. &_huff_book__44c9_s_short,&_huff_book__44c9_s_short,
  128320. &_resbook_44s_9,&_resbook_44s_9},
  128321. {2,0, &_residue_44_high,
  128322. &_huff_book__44c9_s_long,&_huff_book__44c9_s_long,
  128323. &_resbook_44s_9,&_resbook_44s_9}
  128324. };
  128325. static vorbis_mapping_template _mapres_template_44_stereo[]={
  128326. { _map_nominal, _res_44s_n1 }, /* -1 */
  128327. { _map_nominal, _res_44s_0 }, /* 0 */
  128328. { _map_nominal, _res_44s_1 }, /* 1 */
  128329. { _map_nominal, _res_44s_2 }, /* 2 */
  128330. { _map_nominal, _res_44s_3 }, /* 3 */
  128331. { _map_nominal, _res_44s_4 }, /* 4 */
  128332. { _map_nominal, _res_44s_5 }, /* 5 */
  128333. { _map_nominal, _res_44s_6 }, /* 6 */
  128334. { _map_nominal, _res_44s_7 }, /* 7 */
  128335. { _map_nominal, _res_44s_8 }, /* 8 */
  128336. { _map_nominal, _res_44s_9 }, /* 9 */
  128337. };
  128338. /*** End of inlined file: residue_44.h ***/
  128339. /*** Start of inlined file: psych_44.h ***/
  128340. static vorbis_info_psy_global _psy_global_44[5]={
  128341. {8, /* lines per eighth octave */
  128342. {20.f,14.f,12.f,12.f,12.f,12.f,12.f},
  128343. {-60.f,-30.f,-40.f,-40.f,-40.f,-40.f,-40.f}, 2,-75.f,
  128344. -6.f,
  128345. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  128346. },
  128347. {8, /* lines per eighth octave */
  128348. {14.f,10.f,10.f,10.f,10.f,10.f,10.f},
  128349. {-40.f,-30.f,-25.f,-25.f,-25.f,-25.f,-25.f}, 2,-80.f,
  128350. -6.f,
  128351. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  128352. },
  128353. {8, /* lines per eighth octave */
  128354. {12.f,10.f,10.f,10.f,10.f,10.f,10.f},
  128355. {-20.f,-20.f,-15.f,-15.f,-15.f,-15.f,-15.f}, 0,-80.f,
  128356. -6.f,
  128357. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  128358. },
  128359. {8, /* lines per eighth octave */
  128360. {10.f,8.f,8.f,8.f,8.f,8.f,8.f},
  128361. {-20.f,-15.f,-12.f,-12.f,-12.f,-12.f,-12.f}, 0,-80.f,
  128362. -6.f,
  128363. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  128364. },
  128365. {8, /* lines per eighth octave */
  128366. {10.f,6.f,6.f,6.f,6.f,6.f,6.f},
  128367. {-15.f,-15.f,-12.f,-12.f,-12.f,-12.f,-12.f}, 0,-85.f,
  128368. -6.f,
  128369. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  128370. },
  128371. };
  128372. static compandblock _psy_compand_44[6]={
  128373. {{
  128374. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  128375. 8, 9,10,11,12,13,14, 15, /* 15dB */
  128376. 16,17,18,19,20,21,22, 23, /* 23dB */
  128377. 24,25,26,27,28,29,30, 31, /* 31dB */
  128378. 32,33,34,35,36,37,38, 39, /* 39dB */
  128379. }},
  128380. {{
  128381. 0, 1, 2, 3, 4, 5, 6, 6, /* 7dB */
  128382. 7, 7, 7, 7, 6, 6, 6, 7, /* 15dB */
  128383. 7, 8, 9,10,11,12,13, 14, /* 23dB */
  128384. 15,16,17,17,17,18,18, 19, /* 31dB */
  128385. 19,19,20,21,22,23,24, 25, /* 39dB */
  128386. }},
  128387. {{
  128388. 0, 1, 2, 3, 4, 5, 5, 5, /* 7dB */
  128389. 6, 6, 6, 5, 4, 4, 4, 4, /* 15dB */
  128390. 4, 4, 5, 5, 5, 6, 6, 6, /* 23dB */
  128391. 7, 7, 7, 8, 8, 8, 9, 10, /* 31dB */
  128392. 11,12,13,14,15,16,17, 18, /* 39dB */
  128393. }},
  128394. {{
  128395. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  128396. 8, 9,10,11,12,13,14, 15, /* 15dB */
  128397. 16,17,18,19,20,21,22, 23, /* 23dB */
  128398. 24,25,26,27,28,29,30, 31, /* 31dB */
  128399. 32,33,34,35,36,37,38, 39, /* 39dB */
  128400. }},
  128401. {{
  128402. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  128403. 8, 9,10,11,12,12,13, 13, /* 15dB */
  128404. 13,14,14,14,15,15,15, 15, /* 23dB */
  128405. 16,16,17,17,17,18,18, 19, /* 31dB */
  128406. 19,19,20,21,22,23,24, 25, /* 39dB */
  128407. }},
  128408. {{
  128409. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  128410. 8, 8, 7, 6, 5, 4, 4, 4, /* 15dB */
  128411. 4, 4, 5, 5, 5, 6, 6, 6, /* 23dB */
  128412. 7, 7, 7, 8, 8, 8, 9, 10, /* 31dB */
  128413. 11,12,13,14,15,16,17, 18, /* 39dB */
  128414. }}
  128415. };
  128416. static vp_adjblock _vp_tonemask_adj_longblock[12]={
  128417. {{ -3, -8,-13,-15,-10,-10,-10,-10,-10,-10,-10, 0, 0, 0, 0, 0, 0}}, /* -1 */
  128418. {{ -4,-10,-14,-16,-15,-14,-13,-12,-12,-12,-11, -1, -1, -1, -1, -1, 0}}, /* 0 */
  128419. {{ -6,-12,-14,-16,-15,-15,-14,-13,-13,-12,-12, -2, -2, -1, -1, -1, 0}}, /* 1 */
  128420. {{-12,-13,-14,-16,-16,-16,-15,-14,-13,-12,-12, -6, -3, -1, -1, -1, 0}}, /* 2 */
  128421. {{-15,-15,-15,-16,-16,-16,-16,-14,-13,-13,-13,-10, -4, -2, -1, -1, 0}}, /* 3 */
  128422. /* 4 */
  128423. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 4 */
  128424. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 5 */
  128425. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -8, -4, -2, -2, 0}}, /* 6 */
  128426. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 7 */
  128427. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 8 */
  128428. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 9 */
  128429. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 10 */
  128430. };
  128431. static vp_adjblock _vp_tonemask_adj_otherblock[12]={
  128432. {{ -3, -8,-13,-15,-10,-10, -9, -9, -9, -9, -9, 1, 1, 1, 1, 1, 1}}, /* -1 */
  128433. {{ -4,-10,-14,-16,-14,-13,-12,-12,-11,-11,-10, 0, 0, 0, 0, 0, 0}}, /* 0 */
  128434. {{ -6,-12,-14,-16,-15,-15,-14,-13,-13,-12,-12, -2, -2, -1, 0, 0, 0}}, /* 1 */
  128435. {{-12,-13,-14,-16,-16,-16,-15,-14,-13,-12,-12, -5, -2, -1, 0, 0, 0}}, /* 2 */
  128436. {{-15,-15,-15,-16,-16,-16,-16,-14,-13,-13,-13,-10, -4, -2, 0, 0, 0}}, /* 3 */
  128437. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 4 */
  128438. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 5 */
  128439. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -8, -4, -2, -2, 0}}, /* 6 */
  128440. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 7 */
  128441. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 8 */
  128442. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 9 */
  128443. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 10 */
  128444. };
  128445. static noise3 _psy_noisebias_trans[12]={
  128446. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  128447. {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2, 2, 2, 3, 6, 6, 15},
  128448. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  128449. {{{-15,-15,-15,-15,-15,-12, -6, -4, 0, 2, 4, 4, 5, 5, 5, 8, 10},
  128450. {-30,-30,-30,-30,-26,-22,-20,-14, -8, -4, 0, 0, 0, 0, 2, 3, 6},
  128451. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -6, -4, -4, -4, -2}}},
  128452. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 5, 8, 10},
  128453. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -2, -2, -2, -2, 0, 1, 4},
  128454. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -6, -6, -6, -4}}},
  128455. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 2, 2, 4, 4, 5, 6, 10},
  128456. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -2, -1, 0, 3},
  128457. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -7, -4}}},
  128458. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 2, 2, 4, 4, 4, 5, 8},
  128459. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -3, -2, 0, 2},
  128460. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
  128461. {{{-20,-20,-20,-20,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  128462. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -3, -2, -1, 1},
  128463. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
  128464. {{{-24,-24,-24,-24,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  128465. {-32,-32,-32,-32,-28,-24,-22,-16,-12, -6, -4, -4, -4, -4, -3, -1, 0},
  128466. {-34,-34,-34,-34,-30,-24,-24,-18,-14,-12,-12,-12,-12,-10,-10, -9, -5}}},
  128467. {{{-24,-24,-24,-24,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  128468. {-32,-32,-32,-32,-28,-24,-24,-18,-14, -8, -6, -6, -6, -6, -5, -2, 0},
  128469. {-34,-34,-34,-34,-30,-26,-26,-24,-22,-19,-19,-19,-19,-18,-17,-16,-12}}},
  128470. {{{-24,-24,-24,-24,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  128471. {-32,-32,-32,-32,-28,-24,-24,-24,-18,-14,-12,-10,-10,-10, -8, -6, -2},
  128472. {-34,-34,-34,-34,-30,-26,-26,-26,-24,-24,-24,-24,-24,-24,-24,-20,-16}}},
  128473. {{{-24,-24,-24,-24,-22,-20,-15,-10, -8, -2, 0, 0, 0, 1, 2, 3, 7},
  128474. {-36,-36,-36,-36,-30,-30,-30,-24,-20,-16,-16,-16,-16,-14,-12,-10, -7},
  128475. {-36,-36,-36,-36,-34,-30,-28,-26,-24,-30,-30,-30,-30,-30,-30,-24,-20}}},
  128476. {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -4, -4, -4, -4, -4, -2, 2},
  128477. {-38,-38,-38,-38,-36,-34,-34,-30,-24,-20,-20,-20,-20,-18,-16,-12,-10},
  128478. {-40,-40,-40,-40,-40,-40,-40,-38,-35,-35,-35,-35,-35,-35,-35,-35,-30}}},
  128479. {{{-30,-30,-30,-30,-30,-30,-30,-28,-20,-14,-14,-14,-14,-14,-14,-12,-10},
  128480. {-40,-40,-40,-40,-40,-40,-40,-40,-35,-30,-30,-30,-30,-30,-30,-30,-20},
  128481. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128482. };
  128483. static noise3 _psy_noisebias_long[12]={
  128484. {{{-10,-10,-10,-10,-10, -4, 0, 0, 0, 6, 6, 6, 6, 10, 10, 12, 20},
  128485. {-20,-20,-20,-20,-20,-20,-10, -2, 0, 0, 0, 0, 0, 2, 4, 6, 15},
  128486. {-20,-20,-20,-20,-20,-20,-20,-10, -6, -6, -6, -6, -6, -4, -4, -4, -2}}},
  128487. {{{-10,-10,-10,-10,-10,-10, -8, 2, 2, 2, 4, 4, 5, 5, 5, 8, 10},
  128488. {-20,-20,-20,-20,-20,-20,-20,-14, -6, 0, 0, 0, 0, 0, 2, 3, 6},
  128489. {-20,-20,-20,-20,-20,-20,-20,-14, -8, -6, -6, -6, -6, -4, -4, -4, -2}}},
  128490. {{{-10,-10,-10,-10,-10,-10, -8, -4, 0, 2, 4, 4, 5, 5, 5, 8, 10},
  128491. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -2, -2, -2, -2, 0, 1, 4},
  128492. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -8, -8, -8, -8, -6, -6, -6, -4}}},
  128493. {{{-10,-10,-10,-10,-10,-10,-10, -8, 0, 2, 2, 2, 4, 4, 5, 6, 10},
  128494. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -2, -1, 0, 3},
  128495. {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
  128496. {{{-10,-10,-10,-10,-10,-10,-10, -8, 0, 2, 2, 2, 4, 4, 4, 5, 8},
  128497. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -3, -2, 0, 2},
  128498. {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -5}}},
  128499. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  128500. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -3, -2, -1, 1},
  128501. {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -7}}},
  128502. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  128503. {-22,-22,-22,-22,-22,-22,-22,-16,-12, -6, -4, -4, -4, -4, -3, -1, 0},
  128504. {-24,-24,-24,-24,-24,-24,-24,-18,-14,-12,-12,-12,-12,-10,-10, -9, -8}}},
  128505. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  128506. {-24,-24,-24,-24,-24,-24,-24,-18,-14, -8, -6, -6, -6, -6, -5, -2, 0},
  128507. {-26,-26,-26,-26,-26,-26,-26,-18,-16,-15,-15,-15,-15,-13,-13,-12,-10}}},
  128508. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  128509. {-24,-24,-24,-24,-24,-24,-24,-18,-14,-10, -8, -8, -8, -8, -6, -4, 0},
  128510. {-26,-26,-26,-26,-26,-26,-26,-22,-20,-19,-19,-19,-19,-18,-17,-16,-12}}},
  128511. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 0, 0, 0, 0, 1, 2, 3, 7},
  128512. {-26,-26,-26,-26,-26,-26,-26,-20,-16,-12,-10,-10,-10,-10, -8, -6, -2},
  128513. {-28,-28,-28,-28,-28,-28,-28,-26,-24,-24,-24,-24,-24,-24,-24,-20,-16}}},
  128514. {{{-22,-22,-22,-22,-22,-22,-22,-18,-14, -8, -4, -4, -4, -4, -4, -2, 2},
  128515. {-26,-26,-26,-26,-26,-26,-26,-22,-18,-16,-16,-16,-16,-14,-12,-10, -7},
  128516. {-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-24,-20}}},
  128517. {{{-24,-24,-24,-24,-24,-24,-24,-24,-24,-18,-14,-14,-14,-14,-14,-12,-10},
  128518. {-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-20},
  128519. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128520. };
  128521. static noise3 _psy_noisebias_impulse[12]={
  128522. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  128523. {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2, 2, 2, 3, 6, 6, 15},
  128524. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  128525. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 4, 8, 8, 8, 10, 12, 14, 20},
  128526. {-30,-30,-30,-30,-26,-22,-20,-14, -6, -2, 0, 0, 0, 0, 2, 3, 6},
  128527. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  128528. {{{-12,-12,-12,-12,-12, -8, -6, -4, 0, 4, 4, 4, 4, 10, 12, 14, 20},
  128529. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -4, -4, -2, -2, -2, -2, 2},
  128530. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8,-10,-10, -8, -8, -8, -6, -4}}},
  128531. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 8, 10, 10, 16},
  128532. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -4, -4, -4, -2, 0},
  128533. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
  128534. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 6, 8, 8, 14},
  128535. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -4, -4, -4, -2, 0},
  128536. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
  128537. {{{-16,-16,-16,-16,-16,-12,-10, -6, -2, 0, 0, 0, 0, 4, 6, 6, 12},
  128538. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -4, -4, -4, -2, 0},
  128539. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
  128540. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 4, 6, 11},
  128541. {-32,-32,-32,-32,-28,-24,-22,-16,-10, -6, -8, -8, -6, -6, -6, -4, -2},
  128542. {-34,-34,-34,-34,-30,-26,-24,-18,-14,-12,-12,-12,-12,-12,-10, -9, -5}}},
  128543. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 4, 6, 11},
  128544. {-34,-34,-34,-34,-30,-30,-30,-24,-16,-16,-16,-16,-16,-16,-14,-14,-12},
  128545. {-36,-36,-36,-36,-36,-34,-28,-24,-20,-20,-20,-20,-20,-20,-20,-18,-16}}},
  128546. {{{-22,-22,-22,-22,-22,-20,-14,-10, -6, 0, 0, 0, 0, 4, 4, 6, 11},
  128547. {-34,-34,-34,-34,-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-24,-22},
  128548. {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-30,-24}}},
  128549. {{{-24,-24,-24,-24,-24,-22,-14,-10, -6, -1, -1, -1, -1, 3, 3, 5, 10},
  128550. {-34,-34,-34,-34,-34,-32,-32,-30,-26,-26,-26,-26,-26,-26,-26,-26,-24},
  128551. {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-30,-24}}},
  128552. {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -4, -4, -4, -4, -4, -2, 2},
  128553. {-36,-36,-36,-36,-34,-32,-32,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26},
  128554. {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-24,-20}}},
  128555. {{{-30,-30,-30,-30,-30,-26,-24,-24,-24,-20,-16,-16,-16,-16,-16,-14,-12},
  128556. {-40,-40,-40,-40,-40,-40,-40,-40,-35,-30,-30,-30,-30,-30,-30,-30,-26},
  128557. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128558. };
  128559. static noise3 _psy_noisebias_padding[12]={
  128560. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  128561. {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2, 2, 2, 3, 6, 6, 15},
  128562. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  128563. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  128564. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -2, 2, 3, 6, 6, 8, 10},
  128565. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -4, -4, -4, -4, -2, 0, 2}}},
  128566. {{{-12,-12,-12,-12,-12, -8, -6, -4, 0, 4, 4, 4, 4, 10, 12, 14, 20},
  128567. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, 0, 0, 0, 2, 2, 4, 8},
  128568. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -6, -6, -4, -2, 0}}},
  128569. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 8, 10, 10, 16},
  128570. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, 0, 0, 2, 6},
  128571. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
  128572. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 6, 8, 8, 14},
  128573. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, 0, 0, 2, 6},
  128574. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
  128575. {{{-16,-16,-16,-16,-16,-12,-10, -6, -2, 0, 0, 0, 0, 4, 6, 6, 12},
  128576. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, -1, 0, 2, 6},
  128577. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
  128578. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 6, 6, 12},
  128579. {-32,-32,-32,-32,-28,-24,-22,-16,-12, -6, -3, -3, -3, -3, -2, 0, 4},
  128580. {-34,-34,-34,-34,-30,-26,-24,-18,-14,-10,-10,-10,-10,-10, -8, -5, -3}}},
  128581. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 6, 6, 12},
  128582. {-34,-34,-34,-34,-30,-30,-24,-20,-14, -8, -4, -4, -4, -4, -3, -1, 4},
  128583. {-34,-34,-34,-34,-34,-30,-26,-20,-16,-13,-13,-13,-13,-13,-11, -8, -6}}},
  128584. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 6, 6, 12},
  128585. {-34,-34,-34,-34,-30,-30,-30,-24,-16,-10, -8, -6, -6, -6, -5, -3, 1},
  128586. {-34,-34,-34,-34,-32,-32,-28,-22,-18,-16,-16,-16,-16,-16,-14,-12,-10}}},
  128587. {{{-22,-22,-22,-22,-22,-20,-14,-10, -4, 0, 0, 0, 0, 3, 5, 5, 11},
  128588. {-34,-34,-34,-34,-30,-30,-30,-24,-16,-12,-10, -8, -8, -8, -7, -5, -2},
  128589. {-36,-36,-36,-36,-36,-34,-28,-22,-20,-20,-20,-20,-20,-20,-20,-16,-14}}},
  128590. {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -2, -2, -2, -2, 0, 2, 6},
  128591. {-36,-36,-36,-36,-34,-32,-32,-24,-16,-12,-12,-12,-12,-12,-10, -8, -5},
  128592. {-40,-40,-40,-40,-40,-40,-40,-32,-26,-24,-24,-24,-24,-24,-24,-20,-18}}},
  128593. {{{-30,-30,-30,-30,-30,-26,-24,-24,-24,-20,-12,-12,-12,-12,-12,-10, -8},
  128594. {-40,-40,-40,-40,-40,-40,-40,-40,-35,-30,-25,-25,-25,-25,-25,-25,-15},
  128595. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128596. };
  128597. static noiseguard _psy_noiseguards_44[4]={
  128598. {3,3,15},
  128599. {3,3,15},
  128600. {10,10,100},
  128601. {10,10,100},
  128602. };
  128603. static int _psy_tone_suppress[12]={
  128604. -20,-20,-20,-20,-20,-24,-30,-40,-40,-45,-45,-45,
  128605. };
  128606. static int _psy_tone_0dB[12]={
  128607. 90,90,95,95,95,95,105,105,105,105,105,105,
  128608. };
  128609. static int _psy_noise_suppress[12]={
  128610. -20,-20,-24,-24,-24,-24,-30,-40,-40,-45,-45,-45,
  128611. };
  128612. static vorbis_info_psy _psy_info_template={
  128613. -1,
  128614. -140.,-140.,
  128615. {0.f,0.f,0.f}, 0.,0., -40.f, {0.},
  128616. 1, -0.f, .5f, .5f, 0,0,0,
  128617. {{-1},{-1},{-1}},{-1},105.f,
  128618. 0,0,-1,-1,0.,
  128619. };
  128620. static int _psy_ath_floater[12]={
  128621. -100,-100,-100,-100,-100,-100,-105,-105,-105,-105,-110,-120,
  128622. };
  128623. static int _psy_ath_abs[12]={
  128624. -130,-130,-130,-130,-140,-140,-140,-140,-140,-140,-140,-150,
  128625. };
  128626. static adj_stereo _psy_stereo_modes_44[12]={
  128627. {{ 4, 4, 4, 4, 4, 4, 4, 3, 2, 2, 1, 0, 0, 0, 0},
  128628. { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 5, 4, 3},
  128629. { 1, 2, 3, 4, 4, 4, 4, 4, 4, 5, 6, 7, 8, 8, 8},
  128630. { 12,12.5, 13,13.5, 14,14.5, 15, 99, 99, 99, 99, 99, 99, 99, 99}},
  128631. {{ 4, 4, 4, 4, 4, 4, 4, 3, 2, 1, 0, 0, 0, 0, 0},
  128632. { 8, 8, 8, 8, 6, 6, 5, 5, 5, 5, 5, 5, 5, 4, 3},
  128633. { 1, 2, 3, 4, 4, 5, 6, 6, 6, 6, 6, 8, 8, 8, 8},
  128634. { 12,12.5, 13,13.5, 14,14.5, 15, 99, 99, 99, 99, 99, 99, 99, 99}},
  128635. {{ 3, 3, 3, 3, 3, 3, 3, 3, 2, 1, 0, 0, 0, 0, 0},
  128636. { 8, 8, 8, 8, 6, 6, 5, 5, 5, 5, 5, 5, 5, 4, 3},
  128637. { 1, 2, 3, 4, 4, 5, 6, 6, 6, 6, 6, 8, 8, 8, 8},
  128638. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128639. {{ 3, 3, 3, 3, 3, 3, 3, 2, 1, 1, 0, 0, 0, 0, 0},
  128640. { 8, 8, 6, 6, 5, 5, 4, 4, 4, 4, 4, 4, 3, 2, 1},
  128641. { 3, 4, 4, 5, 5, 6, 6, 6, 6, 6, 6, 8, 8, 8, 8},
  128642. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128643. {{ 2, 2, 2, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0},
  128644. { 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 2, 1},
  128645. { 4, 4, 5, 6, 6, 6, 6, 6, 8, 8, 10, 10, 10, 10, 10},
  128646. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128647. {{ 2, 2, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128648. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 2, 1, 0},
  128649. { 6, 6, 6, 8, 8, 8, 8, 8, 8, 8, 10, 10, 10, 10, 10},
  128650. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128651. {{ 2, 2, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128652. { 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0},
  128653. { 6, 7, 8, 8, 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12},
  128654. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128655. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128656. { 3, 3, 3, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128657. { 8, 8, 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
  128658. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128659. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128660. { 3, 3, 3, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128661. { 8, 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
  128662. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128663. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128664. { 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128665. { 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
  128666. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128667. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128668. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128669. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  128670. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128671. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128672. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128673. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  128674. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128675. };
  128676. static att3 _psy_tone_masteratt_44[12]={
  128677. {{ 35, 21, 9}, 0, 0}, /* -1 */
  128678. {{ 30, 20, 8}, -2, 1.25}, /* 0 */
  128679. /* 1 */
  128680. {{ 25, 12, 2}, 0, 0}, /* 1 */
  128681. /* 2 */
  128682. {{ 20, 9, -3}, 0, 0}, /* 2 */
  128683. {{ 20, 9, -4}, 0, 0}, /* 3 */
  128684. {{ 20, 9, -4}, 0, 0}, /* 4 */
  128685. {{ 20, 6, -6}, 0, 0}, /* 5 */
  128686. {{ 20, 3, -10}, 0, 0}, /* 6 */
  128687. {{ 18, 1, -14}, 0, 0}, /* 7 */
  128688. {{ 18, 0, -16}, 0, 0}, /* 8 */
  128689. {{ 18, -2, -16}, 0, 0}, /* 9 */
  128690. {{ 12, -2, -20}, 0, 0}, /* 10 */
  128691. };
  128692. static double _psy_lowpass_44[12]={
  128693. 13.9,15.1,15.8,16.5,17.2,18.9,20.1,48.,999.,999.,999.,999.
  128694. };
  128695. static int _noise_start_short_44[11]={
  128696. 32,16,16,16,32,9999,9999,9999,9999,9999,9999
  128697. };
  128698. static int _noise_start_long_44[11]={
  128699. 256,128,128,256,512,9999,9999,9999,9999,9999,9999
  128700. };
  128701. static int _noise_part_short_44[11]={
  128702. 8,8,8,8,8,8,8,8,8,8,8
  128703. };
  128704. static int _noise_part_long_44[11]={
  128705. 32,32,32,32,32,32,32,32,32,32,32
  128706. };
  128707. static double _noise_thresh_44[11]={
  128708. .2,.2,.2,.4,.6,9999.,9999.,9999.,9999.,9999.,9999.,
  128709. };
  128710. static double _noise_thresh_5only[2]={
  128711. .5,.5,
  128712. };
  128713. /*** End of inlined file: psych_44.h ***/
  128714. static double rate_mapping_44_stereo[12]={
  128715. 22500.,32000.,40000.,48000.,56000.,64000.,
  128716. 80000.,96000.,112000.,128000.,160000.,250001.
  128717. };
  128718. static double quality_mapping_44[12]={
  128719. -.1,.0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1.0
  128720. };
  128721. static int blocksize_short_44[11]={
  128722. 512,256,256,256,256,256,256,256,256,256,256
  128723. };
  128724. static int blocksize_long_44[11]={
  128725. 4096,2048,2048,2048,2048,2048,2048,2048,2048,2048,2048
  128726. };
  128727. static double _psy_compand_short_mapping[12]={
  128728. 0.5, 1., 1., 1.3, 1.6, 2., 2., 2., 2., 2., 2., 2.
  128729. };
  128730. static double _psy_compand_long_mapping[12]={
  128731. 3.5, 4., 4., 4.3, 4.6, 5., 5., 5., 5., 5., 5., 5.
  128732. };
  128733. static double _global_mapping_44[12]={
  128734. 0., 1., 1., 1.5, 2., 2., 2.5, 2.7, 3.0, 3.7, 4., 4.
  128735. };
  128736. static int _floor_short_mapping_44[11]={
  128737. 1,0,0,2,2,4,5,5,5,5,5
  128738. };
  128739. static int _floor_long_mapping_44[11]={
  128740. 8,7,7,7,7,7,7,7,7,7,7
  128741. };
  128742. ve_setup_data_template ve_setup_44_stereo={
  128743. 11,
  128744. rate_mapping_44_stereo,
  128745. quality_mapping_44,
  128746. 2,
  128747. 40000,
  128748. 50000,
  128749. blocksize_short_44,
  128750. blocksize_long_44,
  128751. _psy_tone_masteratt_44,
  128752. _psy_tone_0dB,
  128753. _psy_tone_suppress,
  128754. _vp_tonemask_adj_otherblock,
  128755. _vp_tonemask_adj_longblock,
  128756. _vp_tonemask_adj_otherblock,
  128757. _psy_noiseguards_44,
  128758. _psy_noisebias_impulse,
  128759. _psy_noisebias_padding,
  128760. _psy_noisebias_trans,
  128761. _psy_noisebias_long,
  128762. _psy_noise_suppress,
  128763. _psy_compand_44,
  128764. _psy_compand_short_mapping,
  128765. _psy_compand_long_mapping,
  128766. {_noise_start_short_44,_noise_start_long_44},
  128767. {_noise_part_short_44,_noise_part_long_44},
  128768. _noise_thresh_44,
  128769. _psy_ath_floater,
  128770. _psy_ath_abs,
  128771. _psy_lowpass_44,
  128772. _psy_global_44,
  128773. _global_mapping_44,
  128774. _psy_stereo_modes_44,
  128775. _floor_books,
  128776. _floor,
  128777. _floor_short_mapping_44,
  128778. _floor_long_mapping_44,
  128779. _mapres_template_44_stereo
  128780. };
  128781. /*** End of inlined file: setup_44.h ***/
  128782. /*** Start of inlined file: setup_44u.h ***/
  128783. /*** Start of inlined file: residue_44u.h ***/
  128784. /*** Start of inlined file: res_books_uncoupled.h ***/
  128785. static long _vq_quantlist__16u0__p1_0[] = {
  128786. 1,
  128787. 0,
  128788. 2,
  128789. };
  128790. static long _vq_lengthlist__16u0__p1_0[] = {
  128791. 1, 4, 4, 5, 7, 7, 5, 7, 8, 5, 8, 8, 8,10,10, 8,
  128792. 10,11, 5, 8, 8, 8,10,10, 8,10,10, 4, 9, 9, 9,12,
  128793. 11, 8,11,11, 8,12,11,10,12,14,10,13,13, 7,11,11,
  128794. 10,14,12,11,14,14, 4, 9, 9, 8,11,11, 9,11,12, 7,
  128795. 11,11,10,13,14,10,12,14, 8,11,12,10,14,14,10,13,
  128796. 12,
  128797. };
  128798. static float _vq_quantthresh__16u0__p1_0[] = {
  128799. -0.5, 0.5,
  128800. };
  128801. static long _vq_quantmap__16u0__p1_0[] = {
  128802. 1, 0, 2,
  128803. };
  128804. static encode_aux_threshmatch _vq_auxt__16u0__p1_0 = {
  128805. _vq_quantthresh__16u0__p1_0,
  128806. _vq_quantmap__16u0__p1_0,
  128807. 3,
  128808. 3
  128809. };
  128810. static static_codebook _16u0__p1_0 = {
  128811. 4, 81,
  128812. _vq_lengthlist__16u0__p1_0,
  128813. 1, -535822336, 1611661312, 2, 0,
  128814. _vq_quantlist__16u0__p1_0,
  128815. NULL,
  128816. &_vq_auxt__16u0__p1_0,
  128817. NULL,
  128818. 0
  128819. };
  128820. static long _vq_quantlist__16u0__p2_0[] = {
  128821. 1,
  128822. 0,
  128823. 2,
  128824. };
  128825. static long _vq_lengthlist__16u0__p2_0[] = {
  128826. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 9, 7,
  128827. 8, 9, 5, 7, 7, 7, 9, 8, 7, 9, 7, 4, 7, 7, 7, 9,
  128828. 9, 7, 8, 8, 6, 9, 8, 7, 8,11, 9,11,10, 6, 8, 9,
  128829. 8,11, 8, 9,10,11, 4, 7, 7, 7, 8, 8, 7, 9, 9, 6,
  128830. 9, 8, 9,11,10, 8, 8,11, 6, 8, 9, 9,10,11, 8,11,
  128831. 8,
  128832. };
  128833. static float _vq_quantthresh__16u0__p2_0[] = {
  128834. -0.5, 0.5,
  128835. };
  128836. static long _vq_quantmap__16u0__p2_0[] = {
  128837. 1, 0, 2,
  128838. };
  128839. static encode_aux_threshmatch _vq_auxt__16u0__p2_0 = {
  128840. _vq_quantthresh__16u0__p2_0,
  128841. _vq_quantmap__16u0__p2_0,
  128842. 3,
  128843. 3
  128844. };
  128845. static static_codebook _16u0__p2_0 = {
  128846. 4, 81,
  128847. _vq_lengthlist__16u0__p2_0,
  128848. 1, -535822336, 1611661312, 2, 0,
  128849. _vq_quantlist__16u0__p2_0,
  128850. NULL,
  128851. &_vq_auxt__16u0__p2_0,
  128852. NULL,
  128853. 0
  128854. };
  128855. static long _vq_quantlist__16u0__p3_0[] = {
  128856. 2,
  128857. 1,
  128858. 3,
  128859. 0,
  128860. 4,
  128861. };
  128862. static long _vq_lengthlist__16u0__p3_0[] = {
  128863. 1, 5, 5, 7, 7, 6, 7, 7, 8, 8, 6, 7, 8, 8, 8, 8,
  128864. 9, 9,11,11, 8, 9, 9,11,11, 6, 9, 8,10,10, 8,10,
  128865. 10,11,11, 8,10,10,11,11,10,11,10,13,12, 9,11,10,
  128866. 13,13, 6, 8, 9,10,10, 8,10,10,11,11, 8,10,10,11,
  128867. 11, 9,10,11,13,12,10,10,11,12,12, 8,11,11,14,13,
  128868. 10,12,11,15,13, 9,12,11,15,14,12,14,13,16,14,12,
  128869. 13,13,17,14, 8,11,11,13,14, 9,11,12,14,15,10,11,
  128870. 12,13,15,11,13,13,14,16,12,13,14,14,16, 5, 9, 9,
  128871. 11,11, 9,11,11,12,12, 8,11,11,12,12,11,12,12,15,
  128872. 14,10,12,12,15,15, 8,11,11,13,12,10,12,12,13,13,
  128873. 10,12,12,14,13,12,12,13,14,15,11,13,13,17,16, 7,
  128874. 11,11,13,13,10,12,12,14,13,10,12,12,13,14,12,13,
  128875. 12,15,14,11,13,13,15,14, 9,12,12,16,15,11,13,13,
  128876. 17,16,10,13,13,16,16,13,14,15,15,16,13,15,14,19,
  128877. 17, 9,12,12,14,16,11,13,13,15,16,10,13,13,17,16,
  128878. 13,14,13,17,15,12,15,15,16,17, 5, 9, 9,11,11, 8,
  128879. 11,11,13,12, 9,11,11,12,12,10,12,12,14,15,11,12,
  128880. 12,14,14, 7,11,10,13,12,10,12,12,14,13,10,11,12,
  128881. 13,13,11,13,13,15,16,12,12,13,15,15, 7,11,11,13,
  128882. 13,10,13,13,14,14,10,12,12,13,13,11,13,13,16,15,
  128883. 12,13,13,15,14, 9,12,12,15,15,10,13,13,17,16,11,
  128884. 12,13,15,15,12,15,14,18,18,13,14,14,16,17, 9,12,
  128885. 12,15,16,10,13,13,15,16,11,13,13,15,16,13,15,15,
  128886. 17,17,13,15,14,16,15, 7,11,11,15,16,10,13,12,16,
  128887. 17,10,12,13,15,17,15,16,16,18,17,13,15,15,17,18,
  128888. 8,12,12,16,16,11,13,14,17,18,11,13,13,18,16,15,
  128889. 17,16,17,19,14,15,15,17,16, 8,12,12,16,15,11,14,
  128890. 13,18,17,11,13,14,18,17,15,16,16,18,17,13,16,16,
  128891. 18,18,11,15,14,18,17,13,14,15,18, 0,12,15,15, 0,
  128892. 17,17,16,17,17,18,14,16,18,18, 0,11,14,14,17, 0,
  128893. 12,15,14,17,19,12,15,14,18, 0,15,18,16, 0,17,14,
  128894. 18,16,18, 0, 7,11,11,16,15,10,12,12,18,16,10,13,
  128895. 13,16,15,13,15,14,17,17,14,16,16,19,18, 8,12,12,
  128896. 16,16,11,13,13,18,16,11,13,14,17,16,14,15,15,19,
  128897. 18,15,16,16, 0,19, 8,12,12,16,17,11,13,13,17,17,
  128898. 11,14,13,17,17,13,15,15,17,19,15,17,17,19, 0,11,
  128899. 14,15,19,17,12,15,16,18,18,12,14,15,19,17,14,16,
  128900. 17, 0,18,16,16,19,17, 0,11,14,14,18,19,12,15,14,
  128901. 17,17,13,16,14,17,16,14,17,16,18,18,15,18,15, 0,
  128902. 18,
  128903. };
  128904. static float _vq_quantthresh__16u0__p3_0[] = {
  128905. -1.5, -0.5, 0.5, 1.5,
  128906. };
  128907. static long _vq_quantmap__16u0__p3_0[] = {
  128908. 3, 1, 0, 2, 4,
  128909. };
  128910. static encode_aux_threshmatch _vq_auxt__16u0__p3_0 = {
  128911. _vq_quantthresh__16u0__p3_0,
  128912. _vq_quantmap__16u0__p3_0,
  128913. 5,
  128914. 5
  128915. };
  128916. static static_codebook _16u0__p3_0 = {
  128917. 4, 625,
  128918. _vq_lengthlist__16u0__p3_0,
  128919. 1, -533725184, 1611661312, 3, 0,
  128920. _vq_quantlist__16u0__p3_0,
  128921. NULL,
  128922. &_vq_auxt__16u0__p3_0,
  128923. NULL,
  128924. 0
  128925. };
  128926. static long _vq_quantlist__16u0__p4_0[] = {
  128927. 2,
  128928. 1,
  128929. 3,
  128930. 0,
  128931. 4,
  128932. };
  128933. static long _vq_lengthlist__16u0__p4_0[] = {
  128934. 3, 5, 5, 8, 8, 6, 6, 6, 9, 9, 6, 6, 6, 9, 9, 9,
  128935. 10, 9,11,11, 9, 9, 9,11,11, 6, 7, 7,10,10, 7, 7,
  128936. 8,10,10, 7, 7, 8,10,10,10,10,10,11,12, 9,10,10,
  128937. 11,12, 6, 7, 7,10,10, 7, 8, 7,10,10, 7, 8, 7,10,
  128938. 10,10,11,10,12,11,10,10,10,13,10, 9,10,10,12,12,
  128939. 10,11,10,14,12, 9,11,11,13,13,11,12,13,13,13,11,
  128940. 12,12,15,13, 9,10,10,12,13, 9,11,10,12,13,10,10,
  128941. 11,12,13,11,12,12,12,13,11,12,12,13,13, 5, 7, 7,
  128942. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,12,
  128943. 13,10,10,11,12,12, 6, 8, 8,11,10, 7, 8, 9,10,12,
  128944. 8, 9, 9,11,11,11,10,11,11,12,10,11,11,13,12, 7,
  128945. 8, 8,10,11, 8, 9, 8,11,10, 8, 9, 9,11,11,10,12,
  128946. 10,13,11,10,11,11,13,13,10,11,10,14,13,10,10,11,
  128947. 13,13,10,12,11,14,13,12,11,13,12,13,13,12,13,14,
  128948. 14,10,11,11,13,13,10,11,10,12,13,10,12,12,12,14,
  128949. 12,12,12,14,12,12,13,12,17,15, 5, 7, 7,10,10, 7,
  128950. 8, 8,10,10, 7, 8, 8,11,10,10,10,11,12,12,10,11,
  128951. 11,12,13, 6, 8, 8,11,10, 8, 9, 9,11,11, 7, 8, 9,
  128952. 10,11,11,11,11,12,12,10,10,11,12,13, 6, 8, 8,10,
  128953. 11, 8, 9, 9,11,11, 7, 9, 7,11,10,10,12,12,13,13,
  128954. 11,11,10,13,11, 9,11,10,14,13,11,11,11,15,13,10,
  128955. 10,11,13,13,12,13,13,14,14,12,11,12,12,13,10,11,
  128956. 11,12,13,10,11,12,13,13,10,11,10,13,12,12,12,13,
  128957. 14, 0,12,13,11,13,11, 8,10,10,13,13,10,11,11,14,
  128958. 13,10,11,11,13,12,13,14,14,14,15,12,12,12,15,14,
  128959. 9,11,10,13,12,10,10,11,13,14,11,11,11,15,12,13,
  128960. 12,14,15,16,13,13,13,14,13, 9,11,11,12,12,10,12,
  128961. 11,13,13,10,11,11,13,14,13,13,13,15,15,13,13,14,
  128962. 17,15,11,12,12,14,14,10,11,12,13,15,12,13,13, 0,
  128963. 15,13,11,14,12,16,14,16,14, 0,15,11,12,12,14,16,
  128964. 11,13,12,16,15,12,13,13,14,15,12,14,12,15,13,15,
  128965. 14,14,16,16, 8,10,10,13,13,10,11,10,13,14,10,11,
  128966. 11,13,13,13,13,12,14,14,14,13,13,16,17, 9,10,10,
  128967. 12,14,10,12,11,14,13,10,11,12,13,14,12,12,12,15,
  128968. 15,13,13,13,14,14, 9,10,10,13,13,10,11,12,12,14,
  128969. 10,11,10,13,13,13,13,13,14,16,13,13,13,14,14,11,
  128970. 12,13,15,13,12,14,13,14,16,12,12,13,13,14,13,14,
  128971. 14,17,15,13,12,17,13,16,11,12,13,14,15,12,13,14,
  128972. 14,17,11,12,11,14,14,13,16,14,16, 0,14,15,11,15,
  128973. 11,
  128974. };
  128975. static float _vq_quantthresh__16u0__p4_0[] = {
  128976. -1.5, -0.5, 0.5, 1.5,
  128977. };
  128978. static long _vq_quantmap__16u0__p4_0[] = {
  128979. 3, 1, 0, 2, 4,
  128980. };
  128981. static encode_aux_threshmatch _vq_auxt__16u0__p4_0 = {
  128982. _vq_quantthresh__16u0__p4_0,
  128983. _vq_quantmap__16u0__p4_0,
  128984. 5,
  128985. 5
  128986. };
  128987. static static_codebook _16u0__p4_0 = {
  128988. 4, 625,
  128989. _vq_lengthlist__16u0__p4_0,
  128990. 1, -533725184, 1611661312, 3, 0,
  128991. _vq_quantlist__16u0__p4_0,
  128992. NULL,
  128993. &_vq_auxt__16u0__p4_0,
  128994. NULL,
  128995. 0
  128996. };
  128997. static long _vq_quantlist__16u0__p5_0[] = {
  128998. 4,
  128999. 3,
  129000. 5,
  129001. 2,
  129002. 6,
  129003. 1,
  129004. 7,
  129005. 0,
  129006. 8,
  129007. };
  129008. static long _vq_lengthlist__16u0__p5_0[] = {
  129009. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  129010. 9, 9, 4, 6, 6, 8, 8, 8, 8, 9, 9, 7, 8, 8, 9, 9,
  129011. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,11, 7, 8, 8,
  129012. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  129013. 9, 9,10,10,11,11,12,12, 9, 9, 9,10,10,11,11,12,
  129014. 12,
  129015. };
  129016. static float _vq_quantthresh__16u0__p5_0[] = {
  129017. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  129018. };
  129019. static long _vq_quantmap__16u0__p5_0[] = {
  129020. 7, 5, 3, 1, 0, 2, 4, 6,
  129021. 8,
  129022. };
  129023. static encode_aux_threshmatch _vq_auxt__16u0__p5_0 = {
  129024. _vq_quantthresh__16u0__p5_0,
  129025. _vq_quantmap__16u0__p5_0,
  129026. 9,
  129027. 9
  129028. };
  129029. static static_codebook _16u0__p5_0 = {
  129030. 2, 81,
  129031. _vq_lengthlist__16u0__p5_0,
  129032. 1, -531628032, 1611661312, 4, 0,
  129033. _vq_quantlist__16u0__p5_0,
  129034. NULL,
  129035. &_vq_auxt__16u0__p5_0,
  129036. NULL,
  129037. 0
  129038. };
  129039. static long _vq_quantlist__16u0__p6_0[] = {
  129040. 6,
  129041. 5,
  129042. 7,
  129043. 4,
  129044. 8,
  129045. 3,
  129046. 9,
  129047. 2,
  129048. 10,
  129049. 1,
  129050. 11,
  129051. 0,
  129052. 12,
  129053. };
  129054. static long _vq_lengthlist__16u0__p6_0[] = {
  129055. 1, 4, 4, 7, 7,10,10,12,12,13,13,18,17, 3, 6, 6,
  129056. 9, 9,11,11,13,13,14,14,18,17, 3, 6, 6, 9, 9,11,
  129057. 11,13,13,14,14,17,18, 7, 9, 9,11,11,13,13,14,14,
  129058. 15,15, 0, 0, 7, 9, 9,11,11,13,13,14,14,15,16,19,
  129059. 18,10,11,11,13,13,14,14,16,15,17,18, 0, 0,10,11,
  129060. 11,13,13,14,14,15,15,16,18, 0, 0,11,13,13,14,14,
  129061. 15,15,17,17, 0,19, 0, 0,11,13,13,14,14,14,15,16,
  129062. 18, 0,19, 0, 0,13,14,14,15,15,18,17,18,18, 0,19,
  129063. 0, 0,13,14,14,15,16,16,16,18,18,19, 0, 0, 0,16,
  129064. 17,17, 0,17,19,19, 0,19, 0, 0, 0, 0,16,19,16,17,
  129065. 18, 0,19, 0, 0, 0, 0, 0, 0,
  129066. };
  129067. static float _vq_quantthresh__16u0__p6_0[] = {
  129068. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  129069. 12.5, 17.5, 22.5, 27.5,
  129070. };
  129071. static long _vq_quantmap__16u0__p6_0[] = {
  129072. 11, 9, 7, 5, 3, 1, 0, 2,
  129073. 4, 6, 8, 10, 12,
  129074. };
  129075. static encode_aux_threshmatch _vq_auxt__16u0__p6_0 = {
  129076. _vq_quantthresh__16u0__p6_0,
  129077. _vq_quantmap__16u0__p6_0,
  129078. 13,
  129079. 13
  129080. };
  129081. static static_codebook _16u0__p6_0 = {
  129082. 2, 169,
  129083. _vq_lengthlist__16u0__p6_0,
  129084. 1, -526516224, 1616117760, 4, 0,
  129085. _vq_quantlist__16u0__p6_0,
  129086. NULL,
  129087. &_vq_auxt__16u0__p6_0,
  129088. NULL,
  129089. 0
  129090. };
  129091. static long _vq_quantlist__16u0__p6_1[] = {
  129092. 2,
  129093. 1,
  129094. 3,
  129095. 0,
  129096. 4,
  129097. };
  129098. static long _vq_lengthlist__16u0__p6_1[] = {
  129099. 1, 4, 5, 6, 6, 4, 6, 6, 6, 6, 4, 6, 6, 6, 6, 6,
  129100. 6, 6, 7, 7, 6, 6, 6, 7, 7,
  129101. };
  129102. static float _vq_quantthresh__16u0__p6_1[] = {
  129103. -1.5, -0.5, 0.5, 1.5,
  129104. };
  129105. static long _vq_quantmap__16u0__p6_1[] = {
  129106. 3, 1, 0, 2, 4,
  129107. };
  129108. static encode_aux_threshmatch _vq_auxt__16u0__p6_1 = {
  129109. _vq_quantthresh__16u0__p6_1,
  129110. _vq_quantmap__16u0__p6_1,
  129111. 5,
  129112. 5
  129113. };
  129114. static static_codebook _16u0__p6_1 = {
  129115. 2, 25,
  129116. _vq_lengthlist__16u0__p6_1,
  129117. 1, -533725184, 1611661312, 3, 0,
  129118. _vq_quantlist__16u0__p6_1,
  129119. NULL,
  129120. &_vq_auxt__16u0__p6_1,
  129121. NULL,
  129122. 0
  129123. };
  129124. static long _vq_quantlist__16u0__p7_0[] = {
  129125. 1,
  129126. 0,
  129127. 2,
  129128. };
  129129. static long _vq_lengthlist__16u0__p7_0[] = {
  129130. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  129131. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  129132. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  129133. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  129134. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  129135. 7,
  129136. };
  129137. static float _vq_quantthresh__16u0__p7_0[] = {
  129138. -157.5, 157.5,
  129139. };
  129140. static long _vq_quantmap__16u0__p7_0[] = {
  129141. 1, 0, 2,
  129142. };
  129143. static encode_aux_threshmatch _vq_auxt__16u0__p7_0 = {
  129144. _vq_quantthresh__16u0__p7_0,
  129145. _vq_quantmap__16u0__p7_0,
  129146. 3,
  129147. 3
  129148. };
  129149. static static_codebook _16u0__p7_0 = {
  129150. 4, 81,
  129151. _vq_lengthlist__16u0__p7_0,
  129152. 1, -518803456, 1628680192, 2, 0,
  129153. _vq_quantlist__16u0__p7_0,
  129154. NULL,
  129155. &_vq_auxt__16u0__p7_0,
  129156. NULL,
  129157. 0
  129158. };
  129159. static long _vq_quantlist__16u0__p7_1[] = {
  129160. 7,
  129161. 6,
  129162. 8,
  129163. 5,
  129164. 9,
  129165. 4,
  129166. 10,
  129167. 3,
  129168. 11,
  129169. 2,
  129170. 12,
  129171. 1,
  129172. 13,
  129173. 0,
  129174. 14,
  129175. };
  129176. static long _vq_lengthlist__16u0__p7_1[] = {
  129177. 1, 5, 5, 6, 5, 9,10,11,11,10,10,10,10,10,10, 5,
  129178. 8, 8, 8,10,10,10,10,10,10,10,10,10,10,10, 5, 8,
  129179. 9, 9, 9,10,10,10,10,10,10,10,10,10,10, 5,10, 8,
  129180. 10,10,10,10,10,10,10,10,10,10,10,10, 4, 8, 9,10,
  129181. 10,10,10,10,10,10,10,10,10,10,10, 9,10,10,10,10,
  129182. 10,10,10,10,10,10,10,10,10,10, 9,10,10,10,10,10,
  129183. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129184. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129185. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129186. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129187. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129188. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129189. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129190. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129191. 10,
  129192. };
  129193. static float _vq_quantthresh__16u0__p7_1[] = {
  129194. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  129195. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  129196. };
  129197. static long _vq_quantmap__16u0__p7_1[] = {
  129198. 13, 11, 9, 7, 5, 3, 1, 0,
  129199. 2, 4, 6, 8, 10, 12, 14,
  129200. };
  129201. static encode_aux_threshmatch _vq_auxt__16u0__p7_1 = {
  129202. _vq_quantthresh__16u0__p7_1,
  129203. _vq_quantmap__16u0__p7_1,
  129204. 15,
  129205. 15
  129206. };
  129207. static static_codebook _16u0__p7_1 = {
  129208. 2, 225,
  129209. _vq_lengthlist__16u0__p7_1,
  129210. 1, -520986624, 1620377600, 4, 0,
  129211. _vq_quantlist__16u0__p7_1,
  129212. NULL,
  129213. &_vq_auxt__16u0__p7_1,
  129214. NULL,
  129215. 0
  129216. };
  129217. static long _vq_quantlist__16u0__p7_2[] = {
  129218. 10,
  129219. 9,
  129220. 11,
  129221. 8,
  129222. 12,
  129223. 7,
  129224. 13,
  129225. 6,
  129226. 14,
  129227. 5,
  129228. 15,
  129229. 4,
  129230. 16,
  129231. 3,
  129232. 17,
  129233. 2,
  129234. 18,
  129235. 1,
  129236. 19,
  129237. 0,
  129238. 20,
  129239. };
  129240. static long _vq_lengthlist__16u0__p7_2[] = {
  129241. 1, 6, 6, 7, 8, 7, 7,10, 9,10, 9,11,10, 9,11,10,
  129242. 9, 9, 9, 9,10, 6, 8, 7, 9, 9, 8, 8,10,10, 9,11,
  129243. 11,12,12,10, 9,11, 9,12,10, 9, 6, 9, 8, 9,12, 8,
  129244. 8,11, 9,11,11,12,11,12,12,10,11,11,10,10,11, 7,
  129245. 10, 9, 9, 9, 9, 9,10, 9,10, 9,10,10,12,10,10,10,
  129246. 11,12,10,10, 7, 9, 9, 9,10, 9, 9,10,10, 9, 9, 9,
  129247. 11,11,10,10,10,10, 9, 9,12, 7, 9,10, 9,11, 9,10,
  129248. 9,10,11,11,11,10,11,12, 9,12,11,10,10,10, 7, 9,
  129249. 9, 9, 9,10,12,10, 9,11,12,10,11,12,12,11, 9,10,
  129250. 11,10,11, 7, 9,10,10,11,10, 9,10,11,11,11,10,12,
  129251. 12,12,11,11,10,11,11,12, 8, 9,10,12,11,10,10,12,
  129252. 12,12,12,12,10,11,11, 9,11,10,12,11,11, 8, 9,10,
  129253. 10,11,12,11,11,10,10,10,12,12,12, 9,10,12,12,12,
  129254. 12,12, 8,10,11,10,10,12, 9,11,12,12,11,12,12,12,
  129255. 12,10,12,10,10,10,10, 8,12,11,11,11,10,10,11,12,
  129256. 12,12,12,11,12,12,12,11,11,11,12,10, 9,10,10,12,
  129257. 10,12,10,12,12,10,10,10,11,12,12,12,11,12,12,12,
  129258. 11,10,11,12,12,12,11,12,12,11,12,12,11,12,12,12,
  129259. 12,11,12,12,10,10,10,10,11,11,12,11,12,12,12,12,
  129260. 12,12,12,11,12,11,10,11,11,12,11,11, 9,10,10,10,
  129261. 12,10,10,11, 9,11,12,11,12,11,12,12,10,11,10,12,
  129262. 9, 9, 9,12,11,10,11,10,12,10,12,10,12,12,12,11,
  129263. 11,11,11,11,10, 9,10,10,11,10,11,11,12,11,10,11,
  129264. 12,12,12,11,11, 9,12,10,12, 9,10,12,10,10,11,10,
  129265. 11,11,12,11,10,11,10,11,11,11,11,12,11,11,10, 9,
  129266. 10,10,10, 9,11,11,10, 9,12,10,11,12,11,12,12,11,
  129267. 12,11,12,11,10,11,10,12,11,12,11,12,11,12,10,11,
  129268. 10,10,12,11,10,11,11,11,10,
  129269. };
  129270. static float _vq_quantthresh__16u0__p7_2[] = {
  129271. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  129272. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  129273. 6.5, 7.5, 8.5, 9.5,
  129274. };
  129275. static long _vq_quantmap__16u0__p7_2[] = {
  129276. 19, 17, 15, 13, 11, 9, 7, 5,
  129277. 3, 1, 0, 2, 4, 6, 8, 10,
  129278. 12, 14, 16, 18, 20,
  129279. };
  129280. static encode_aux_threshmatch _vq_auxt__16u0__p7_2 = {
  129281. _vq_quantthresh__16u0__p7_2,
  129282. _vq_quantmap__16u0__p7_2,
  129283. 21,
  129284. 21
  129285. };
  129286. static static_codebook _16u0__p7_2 = {
  129287. 2, 441,
  129288. _vq_lengthlist__16u0__p7_2,
  129289. 1, -529268736, 1611661312, 5, 0,
  129290. _vq_quantlist__16u0__p7_2,
  129291. NULL,
  129292. &_vq_auxt__16u0__p7_2,
  129293. NULL,
  129294. 0
  129295. };
  129296. static long _huff_lengthlist__16u0__single[] = {
  129297. 3, 5, 8, 7,14, 8, 9,19, 5, 2, 5, 5, 9, 6, 9,19,
  129298. 8, 4, 5, 7, 8, 9,13,19, 7, 4, 6, 5, 9, 6, 9,19,
  129299. 12, 8, 7, 9,10,11,13,19, 8, 5, 8, 6, 9, 6, 7,19,
  129300. 8, 8,10, 7, 7, 4, 5,19,12,17,19,15,18,13,11,18,
  129301. };
  129302. static static_codebook _huff_book__16u0__single = {
  129303. 2, 64,
  129304. _huff_lengthlist__16u0__single,
  129305. 0, 0, 0, 0, 0,
  129306. NULL,
  129307. NULL,
  129308. NULL,
  129309. NULL,
  129310. 0
  129311. };
  129312. static long _huff_lengthlist__16u1__long[] = {
  129313. 3, 6,10, 8,12, 8,14, 8,14,19, 5, 3, 5, 5, 7, 6,
  129314. 11, 7,16,19, 7, 5, 6, 7, 7, 9,11,12,19,19, 6, 4,
  129315. 7, 5, 7, 6,10, 7,18,18, 8, 6, 7, 7, 7, 7, 8, 9,
  129316. 18,18, 7, 5, 8, 5, 7, 5, 8, 6,18,18,12, 9,10, 9,
  129317. 9, 9, 8, 9,18,18, 8, 7,10, 6, 8, 5, 6, 4,11,18,
  129318. 11,15,16,12,11, 8, 8, 6, 9,18,14,18,18,18,16,16,
  129319. 16,13,16,18,
  129320. };
  129321. static static_codebook _huff_book__16u1__long = {
  129322. 2, 100,
  129323. _huff_lengthlist__16u1__long,
  129324. 0, 0, 0, 0, 0,
  129325. NULL,
  129326. NULL,
  129327. NULL,
  129328. NULL,
  129329. 0
  129330. };
  129331. static long _vq_quantlist__16u1__p1_0[] = {
  129332. 1,
  129333. 0,
  129334. 2,
  129335. };
  129336. static long _vq_lengthlist__16u1__p1_0[] = {
  129337. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 7, 7,10,10, 7,
  129338. 9,10, 5, 7, 8, 7,10, 9, 7,10,10, 5, 8, 8, 8,10,
  129339. 10, 8,10,10, 7,10,10,10,11,12,10,12,13, 7,10,10,
  129340. 9,13,11,10,12,13, 5, 8, 8, 8,10,10, 8,10,10, 7,
  129341. 10,10,10,12,12, 9,11,12, 7,10,11,10,12,12,10,13,
  129342. 11,
  129343. };
  129344. static float _vq_quantthresh__16u1__p1_0[] = {
  129345. -0.5, 0.5,
  129346. };
  129347. static long _vq_quantmap__16u1__p1_0[] = {
  129348. 1, 0, 2,
  129349. };
  129350. static encode_aux_threshmatch _vq_auxt__16u1__p1_0 = {
  129351. _vq_quantthresh__16u1__p1_0,
  129352. _vq_quantmap__16u1__p1_0,
  129353. 3,
  129354. 3
  129355. };
  129356. static static_codebook _16u1__p1_0 = {
  129357. 4, 81,
  129358. _vq_lengthlist__16u1__p1_0,
  129359. 1, -535822336, 1611661312, 2, 0,
  129360. _vq_quantlist__16u1__p1_0,
  129361. NULL,
  129362. &_vq_auxt__16u1__p1_0,
  129363. NULL,
  129364. 0
  129365. };
  129366. static long _vq_quantlist__16u1__p2_0[] = {
  129367. 1,
  129368. 0,
  129369. 2,
  129370. };
  129371. static long _vq_lengthlist__16u1__p2_0[] = {
  129372. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 7, 8, 6,
  129373. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 7, 5, 6, 6, 6, 8,
  129374. 8, 6, 8, 8, 6, 8, 8, 7, 7,10, 8, 9, 9, 6, 8, 8,
  129375. 7, 9, 8, 8, 9,10, 5, 6, 6, 6, 8, 8, 7, 8, 8, 6,
  129376. 8, 8, 8,10, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 7,10,
  129377. 8,
  129378. };
  129379. static float _vq_quantthresh__16u1__p2_0[] = {
  129380. -0.5, 0.5,
  129381. };
  129382. static long _vq_quantmap__16u1__p2_0[] = {
  129383. 1, 0, 2,
  129384. };
  129385. static encode_aux_threshmatch _vq_auxt__16u1__p2_0 = {
  129386. _vq_quantthresh__16u1__p2_0,
  129387. _vq_quantmap__16u1__p2_0,
  129388. 3,
  129389. 3
  129390. };
  129391. static static_codebook _16u1__p2_0 = {
  129392. 4, 81,
  129393. _vq_lengthlist__16u1__p2_0,
  129394. 1, -535822336, 1611661312, 2, 0,
  129395. _vq_quantlist__16u1__p2_0,
  129396. NULL,
  129397. &_vq_auxt__16u1__p2_0,
  129398. NULL,
  129399. 0
  129400. };
  129401. static long _vq_quantlist__16u1__p3_0[] = {
  129402. 2,
  129403. 1,
  129404. 3,
  129405. 0,
  129406. 4,
  129407. };
  129408. static long _vq_lengthlist__16u1__p3_0[] = {
  129409. 1, 5, 5, 8, 8, 6, 7, 7, 9, 9, 5, 7, 7, 9, 9, 9,
  129410. 10, 9,11,11, 9, 9,10,11,11, 6, 8, 8,10,10, 8, 9,
  129411. 10,11,11, 8, 9,10,11,11,10,11,11,12,13,10,11,11,
  129412. 13,13, 6, 8, 8,10,10, 8,10, 9,11,11, 8,10, 9,11,
  129413. 11,10,11,11,13,13,10,11,11,13,12, 9,11,11,14,13,
  129414. 10,12,12,15,14,10,12,11,14,13,12,13,13,15,15,12,
  129415. 13,13,16,14, 9,11,11,13,14,10,11,12,14,14,10,12,
  129416. 12,14,15,12,13,13,14,15,12,13,14,15,16, 5, 8, 8,
  129417. 11,11, 8,10,10,12,12, 8,10,10,12,12,11,12,12,14,
  129418. 14,11,12,12,14,14, 8,10,10,12,12, 9,11,12,12,13,
  129419. 10,12,12,13,13,12,12,13,14,15,11,13,13,15,15, 7,
  129420. 10,10,12,12, 9,12,11,13,12,10,11,12,13,13,12,13,
  129421. 12,15,14,11,12,13,15,15,10,12,12,15,14,11,13,13,
  129422. 16,15,11,13,13,16,15,14,13,14,15,16,13,15,15,17,
  129423. 17,10,12,12,14,15,11,12,12,15,15,11,13,13,15,16,
  129424. 13,15,13,16,15,13,15,15,16,17, 5, 8, 8,11,11, 8,
  129425. 10,10,12,12, 8,10,10,12,12,11,12,12,14,14,11,12,
  129426. 12,14,14, 7,10,10,12,12,10,12,12,14,13, 9,11,12,
  129427. 12,13,12,13,13,15,15,12,12,13,13,15, 7,10,10,12,
  129428. 13,10,11,12,13,13,10,12,11,13,13,11,13,13,15,15,
  129429. 12,13,12,15,14, 9,12,12,15,14,11,13,13,15,15,11,
  129430. 12,13,15,15,13,14,14,17,19,13,13,14,16,16,10,12,
  129431. 12,14,15,11,13,13,15,16,11,13,12,16,15,13,15,15,
  129432. 17,18,14,15,13,16,15, 8,11,11,15,14,10,12,12,16,
  129433. 15,10,12,12,16,16,14,15,15,18,17,13,14,15,16,18,
  129434. 9,12,12,15,15,11,12,14,16,17,11,13,13,16,15,15,
  129435. 15,15,17,18,14,15,16,17,17, 9,12,12,15,15,11,14,
  129436. 13,16,16,11,13,13,16,16,15,16,15,17,18,14,16,15,
  129437. 17,16,12,14,14,17,16,12,14,15,18,17,13,15,15,17,
  129438. 17,15,15,18,16,20,15,16,17,18,18,11,14,14,16,17,
  129439. 13,15,14,18,17,13,15,15,17,17,15,17,15,18,17,15,
  129440. 17,16,19,18, 8,11,11,14,15,10,12,12,15,15,10,12,
  129441. 12,16,16,13,14,14,17,16,14,15,15,17,17, 9,12,12,
  129442. 15,16,11,13,13,16,16,11,12,13,16,16,14,16,15,20,
  129443. 17,14,16,16,17,17, 9,12,12,15,16,11,13,13,16,17,
  129444. 11,13,13,17,16,14,15,15,17,18,15,15,15,18,18,11,
  129445. 14,14,17,16,13,15,15,17,17,13,14,14,18,17,15,16,
  129446. 16,18,19,15,15,17,17,19,11,14,14,16,17,13,15,14,
  129447. 17,19,13,15,14,18,17,15,17,16,18,18,15,17,15,18,
  129448. 16,
  129449. };
  129450. static float _vq_quantthresh__16u1__p3_0[] = {
  129451. -1.5, -0.5, 0.5, 1.5,
  129452. };
  129453. static long _vq_quantmap__16u1__p3_0[] = {
  129454. 3, 1, 0, 2, 4,
  129455. };
  129456. static encode_aux_threshmatch _vq_auxt__16u1__p3_0 = {
  129457. _vq_quantthresh__16u1__p3_0,
  129458. _vq_quantmap__16u1__p3_0,
  129459. 5,
  129460. 5
  129461. };
  129462. static static_codebook _16u1__p3_0 = {
  129463. 4, 625,
  129464. _vq_lengthlist__16u1__p3_0,
  129465. 1, -533725184, 1611661312, 3, 0,
  129466. _vq_quantlist__16u1__p3_0,
  129467. NULL,
  129468. &_vq_auxt__16u1__p3_0,
  129469. NULL,
  129470. 0
  129471. };
  129472. static long _vq_quantlist__16u1__p4_0[] = {
  129473. 2,
  129474. 1,
  129475. 3,
  129476. 0,
  129477. 4,
  129478. };
  129479. static long _vq_lengthlist__16u1__p4_0[] = {
  129480. 4, 5, 5, 8, 8, 6, 6, 7, 9, 9, 6, 6, 6, 9, 9, 9,
  129481. 10, 9,11,11, 9, 9,10,11,11, 6, 7, 7,10, 9, 7, 7,
  129482. 8, 9,10, 7, 7, 8,10,10,10,10,10,10,12, 9, 9,10,
  129483. 11,12, 6, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 7,10,
  129484. 10, 9,10, 9,12,11,10,10, 9,12,10, 9,10,10,12,11,
  129485. 10,10,10,12,12, 9,10,10,12,12,12,11,12,13,13,11,
  129486. 11,12,12,13, 9,10,10,11,12, 9,10,10,12,12,10,10,
  129487. 10,12,12,11,12,11,14,13,11,12,12,14,13, 5, 7, 7,
  129488. 10,10, 7, 8, 8,10,10, 7, 8, 7,10,10,10,10,10,12,
  129489. 12,10,10,10,12,12, 6, 8, 7,10,10, 7, 7, 9,10,11,
  129490. 8, 9, 9,11,10,10,10,11,11,13,10,10,11,12,13, 6,
  129491. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,10,11,10,11,
  129492. 10,13,11,10,11,10,12,12,10,11,10,12,11,10,10,10,
  129493. 12,13,10,11,11,13,12,11,11,13,11,14,12,12,13,14,
  129494. 14, 9,10,10,12,13,10,11,10,13,12,10,11,11,12,13,
  129495. 11,12,11,14,12,12,13,13,15,14, 5, 7, 7,10,10, 7,
  129496. 7, 8,10,10, 7, 8, 8,10,10,10,10,10,11,12,10,10,
  129497. 10,12,12, 7, 8, 8,10,10, 8, 9, 8,11,10, 7, 8, 9,
  129498. 10,11,10,11,11,12,12,10,10,11,11,13, 7, 7, 8,10,
  129499. 10, 8, 8, 9,10,11, 7, 9, 7,11,10,10,11,11,13,12,
  129500. 11,11,10,13,11, 9,10,10,12,12,10,11,11,13,12,10,
  129501. 10,11,12,12,12,13,13,14,14,11,11,12,12,14,10,10,
  129502. 11,12,12,10,11,11,12,13,10,10,10,13,12,12,13,13,
  129503. 15,14,12,13,10,14,11, 8,10,10,12,12,10,11,10,13,
  129504. 13, 9,10,10,12,12,12,13,13,15,14,11,12,12,13,13,
  129505. 9,10,10,13,12,10,10,11,13,13,10,11,10,13,12,12,
  129506. 12,13,14,15,12,13,12,15,13, 9,10,10,12,13,10,11,
  129507. 10,13,12,10,10,11,12,13,12,14,12,15,13,12,12,13,
  129508. 14,15,11,12,11,14,13,11,11,12,14,15,12,13,12,15,
  129509. 14,13,11,15,11,16,13,14,14,16,15,11,12,12,14,14,
  129510. 11,12,11,14,13,12,12,13,14,15,13,14,12,16,12,14,
  129511. 14,14,15,15, 8,10,10,12,12, 9,10,10,12,12,10,10,
  129512. 11,13,13,11,12,12,13,13,12,13,13,14,15, 9,10,10,
  129513. 13,12,10,11,11,13,12,10,10,11,13,13,12,13,12,15,
  129514. 14,12,12,13,13,16, 9, 9,10,12,13,10,10,11,12,13,
  129515. 10,11,10,13,13,12,12,13,13,15,13,13,12,15,13,11,
  129516. 12,12,14,14,12,13,12,15,14,11,11,12,13,14,14,14,
  129517. 14,16,15,13,12,15,12,16,11,11,12,13,14,12,13,13,
  129518. 14,15,10,12,11,14,13,14,15,14,16,16,13,14,11,15,
  129519. 11,
  129520. };
  129521. static float _vq_quantthresh__16u1__p4_0[] = {
  129522. -1.5, -0.5, 0.5, 1.5,
  129523. };
  129524. static long _vq_quantmap__16u1__p4_0[] = {
  129525. 3, 1, 0, 2, 4,
  129526. };
  129527. static encode_aux_threshmatch _vq_auxt__16u1__p4_0 = {
  129528. _vq_quantthresh__16u1__p4_0,
  129529. _vq_quantmap__16u1__p4_0,
  129530. 5,
  129531. 5
  129532. };
  129533. static static_codebook _16u1__p4_0 = {
  129534. 4, 625,
  129535. _vq_lengthlist__16u1__p4_0,
  129536. 1, -533725184, 1611661312, 3, 0,
  129537. _vq_quantlist__16u1__p4_0,
  129538. NULL,
  129539. &_vq_auxt__16u1__p4_0,
  129540. NULL,
  129541. 0
  129542. };
  129543. static long _vq_quantlist__16u1__p5_0[] = {
  129544. 4,
  129545. 3,
  129546. 5,
  129547. 2,
  129548. 6,
  129549. 1,
  129550. 7,
  129551. 0,
  129552. 8,
  129553. };
  129554. static long _vq_lengthlist__16u1__p5_0[] = {
  129555. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  129556. 10,10, 4, 5, 6, 8, 8, 8, 8,10,10, 7, 8, 8, 9, 9,
  129557. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 7, 8, 8,
  129558. 10, 9,11,11,12,11, 7, 8, 8, 9, 9,11,11,12,12, 9,
  129559. 10,10,11,11,12,12,13,12, 9,10,10,11,11,12,12,12,
  129560. 13,
  129561. };
  129562. static float _vq_quantthresh__16u1__p5_0[] = {
  129563. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  129564. };
  129565. static long _vq_quantmap__16u1__p5_0[] = {
  129566. 7, 5, 3, 1, 0, 2, 4, 6,
  129567. 8,
  129568. };
  129569. static encode_aux_threshmatch _vq_auxt__16u1__p5_0 = {
  129570. _vq_quantthresh__16u1__p5_0,
  129571. _vq_quantmap__16u1__p5_0,
  129572. 9,
  129573. 9
  129574. };
  129575. static static_codebook _16u1__p5_0 = {
  129576. 2, 81,
  129577. _vq_lengthlist__16u1__p5_0,
  129578. 1, -531628032, 1611661312, 4, 0,
  129579. _vq_quantlist__16u1__p5_0,
  129580. NULL,
  129581. &_vq_auxt__16u1__p5_0,
  129582. NULL,
  129583. 0
  129584. };
  129585. static long _vq_quantlist__16u1__p6_0[] = {
  129586. 4,
  129587. 3,
  129588. 5,
  129589. 2,
  129590. 6,
  129591. 1,
  129592. 7,
  129593. 0,
  129594. 8,
  129595. };
  129596. static long _vq_lengthlist__16u1__p6_0[] = {
  129597. 3, 4, 4, 6, 6, 7, 7, 9, 9, 4, 4, 4, 6, 6, 8, 8,
  129598. 9, 9, 4, 4, 4, 6, 6, 7, 7, 9, 9, 6, 6, 6, 7, 7,
  129599. 8, 8,10, 9, 6, 6, 6, 7, 7, 8, 8, 9,10, 7, 8, 7,
  129600. 8, 8, 9, 9,10,10, 7, 8, 8, 8, 8, 9, 9,10,10, 9,
  129601. 9, 9,10,10,10,10,11,11, 9, 9, 9,10,10,10,10,11,
  129602. 11,
  129603. };
  129604. static float _vq_quantthresh__16u1__p6_0[] = {
  129605. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  129606. };
  129607. static long _vq_quantmap__16u1__p6_0[] = {
  129608. 7, 5, 3, 1, 0, 2, 4, 6,
  129609. 8,
  129610. };
  129611. static encode_aux_threshmatch _vq_auxt__16u1__p6_0 = {
  129612. _vq_quantthresh__16u1__p6_0,
  129613. _vq_quantmap__16u1__p6_0,
  129614. 9,
  129615. 9
  129616. };
  129617. static static_codebook _16u1__p6_0 = {
  129618. 2, 81,
  129619. _vq_lengthlist__16u1__p6_0,
  129620. 1, -531628032, 1611661312, 4, 0,
  129621. _vq_quantlist__16u1__p6_0,
  129622. NULL,
  129623. &_vq_auxt__16u1__p6_0,
  129624. NULL,
  129625. 0
  129626. };
  129627. static long _vq_quantlist__16u1__p7_0[] = {
  129628. 1,
  129629. 0,
  129630. 2,
  129631. };
  129632. static long _vq_lengthlist__16u1__p7_0[] = {
  129633. 1, 4, 4, 4, 8, 8, 4, 8, 8, 5,11, 9, 8,12,11, 8,
  129634. 12,11, 5,10,11, 8,11,12, 8,11,12, 4,11,11,11,14,
  129635. 13,10,13,13, 8,14,13,12,14,16,12,16,15, 8,14,14,
  129636. 13,16,14,12,15,16, 4,11,11,10,14,13,11,14,14, 8,
  129637. 15,14,12,15,15,12,14,16, 8,14,14,11,16,15,12,15,
  129638. 13,
  129639. };
  129640. static float _vq_quantthresh__16u1__p7_0[] = {
  129641. -5.5, 5.5,
  129642. };
  129643. static long _vq_quantmap__16u1__p7_0[] = {
  129644. 1, 0, 2,
  129645. };
  129646. static encode_aux_threshmatch _vq_auxt__16u1__p7_0 = {
  129647. _vq_quantthresh__16u1__p7_0,
  129648. _vq_quantmap__16u1__p7_0,
  129649. 3,
  129650. 3
  129651. };
  129652. static static_codebook _16u1__p7_0 = {
  129653. 4, 81,
  129654. _vq_lengthlist__16u1__p7_0,
  129655. 1, -529137664, 1618345984, 2, 0,
  129656. _vq_quantlist__16u1__p7_0,
  129657. NULL,
  129658. &_vq_auxt__16u1__p7_0,
  129659. NULL,
  129660. 0
  129661. };
  129662. static long _vq_quantlist__16u1__p7_1[] = {
  129663. 5,
  129664. 4,
  129665. 6,
  129666. 3,
  129667. 7,
  129668. 2,
  129669. 8,
  129670. 1,
  129671. 9,
  129672. 0,
  129673. 10,
  129674. };
  129675. static long _vq_lengthlist__16u1__p7_1[] = {
  129676. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 6, 5, 7, 7,
  129677. 8, 8, 8, 8, 8, 8, 4, 5, 6, 7, 7, 8, 8, 8, 8, 8,
  129678. 8, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8,
  129679. 8, 8, 8, 9, 9, 9, 9, 7, 8, 8, 8, 8, 9, 9, 9,10,
  129680. 9,10, 7, 8, 8, 8, 8, 9, 9, 9, 9,10, 9, 8, 8, 8,
  129681. 9, 9,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9,10,
  129682. 10,10,10, 8, 8, 8, 9, 9, 9,10,10,10,10,10, 8, 8,
  129683. 8, 9, 9,10,10,10,10,10,10,
  129684. };
  129685. static float _vq_quantthresh__16u1__p7_1[] = {
  129686. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  129687. 3.5, 4.5,
  129688. };
  129689. static long _vq_quantmap__16u1__p7_1[] = {
  129690. 9, 7, 5, 3, 1, 0, 2, 4,
  129691. 6, 8, 10,
  129692. };
  129693. static encode_aux_threshmatch _vq_auxt__16u1__p7_1 = {
  129694. _vq_quantthresh__16u1__p7_1,
  129695. _vq_quantmap__16u1__p7_1,
  129696. 11,
  129697. 11
  129698. };
  129699. static static_codebook _16u1__p7_1 = {
  129700. 2, 121,
  129701. _vq_lengthlist__16u1__p7_1,
  129702. 1, -531365888, 1611661312, 4, 0,
  129703. _vq_quantlist__16u1__p7_1,
  129704. NULL,
  129705. &_vq_auxt__16u1__p7_1,
  129706. NULL,
  129707. 0
  129708. };
  129709. static long _vq_quantlist__16u1__p8_0[] = {
  129710. 5,
  129711. 4,
  129712. 6,
  129713. 3,
  129714. 7,
  129715. 2,
  129716. 8,
  129717. 1,
  129718. 9,
  129719. 0,
  129720. 10,
  129721. };
  129722. static long _vq_lengthlist__16u1__p8_0[] = {
  129723. 1, 4, 4, 5, 5, 8, 8,10,10,12,12, 4, 7, 7, 8, 8,
  129724. 9, 9,12,11,14,13, 4, 7, 7, 7, 8, 9,10,11,11,13,
  129725. 12, 5, 8, 8, 9, 9,11,11,12,13,15,14, 5, 7, 8, 9,
  129726. 9,11,11,13,13,17,15, 8, 9,10,11,11,12,13,17,14,
  129727. 17,16, 8,10, 9,11,11,12,12,13,15,15,17,10,11,11,
  129728. 12,13,14,15,15,16,16,17, 9,11,11,12,12,14,15,17,
  129729. 15,15,16,11,14,12,14,15,16,15,16,16,16,15,11,13,
  129730. 13,14,14,15,15,16,16,15,16,
  129731. };
  129732. static float _vq_quantthresh__16u1__p8_0[] = {
  129733. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  129734. 38.5, 49.5,
  129735. };
  129736. static long _vq_quantmap__16u1__p8_0[] = {
  129737. 9, 7, 5, 3, 1, 0, 2, 4,
  129738. 6, 8, 10,
  129739. };
  129740. static encode_aux_threshmatch _vq_auxt__16u1__p8_0 = {
  129741. _vq_quantthresh__16u1__p8_0,
  129742. _vq_quantmap__16u1__p8_0,
  129743. 11,
  129744. 11
  129745. };
  129746. static static_codebook _16u1__p8_0 = {
  129747. 2, 121,
  129748. _vq_lengthlist__16u1__p8_0,
  129749. 1, -524582912, 1618345984, 4, 0,
  129750. _vq_quantlist__16u1__p8_0,
  129751. NULL,
  129752. &_vq_auxt__16u1__p8_0,
  129753. NULL,
  129754. 0
  129755. };
  129756. static long _vq_quantlist__16u1__p8_1[] = {
  129757. 5,
  129758. 4,
  129759. 6,
  129760. 3,
  129761. 7,
  129762. 2,
  129763. 8,
  129764. 1,
  129765. 9,
  129766. 0,
  129767. 10,
  129768. };
  129769. static long _vq_lengthlist__16u1__p8_1[] = {
  129770. 2, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 4, 6, 6, 7, 7,
  129771. 8, 7, 8, 8, 8, 8, 4, 6, 6, 7, 7, 7, 7, 8, 8, 8,
  129772. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 9, 6, 7, 7, 7,
  129773. 7, 8, 8, 8, 8, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9,
  129774. 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8,
  129775. 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9,
  129776. 9, 9, 9, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 8, 8,
  129777. 8, 9, 9, 9, 9, 9, 9, 9, 9,
  129778. };
  129779. static float _vq_quantthresh__16u1__p8_1[] = {
  129780. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  129781. 3.5, 4.5,
  129782. };
  129783. static long _vq_quantmap__16u1__p8_1[] = {
  129784. 9, 7, 5, 3, 1, 0, 2, 4,
  129785. 6, 8, 10,
  129786. };
  129787. static encode_aux_threshmatch _vq_auxt__16u1__p8_1 = {
  129788. _vq_quantthresh__16u1__p8_1,
  129789. _vq_quantmap__16u1__p8_1,
  129790. 11,
  129791. 11
  129792. };
  129793. static static_codebook _16u1__p8_1 = {
  129794. 2, 121,
  129795. _vq_lengthlist__16u1__p8_1,
  129796. 1, -531365888, 1611661312, 4, 0,
  129797. _vq_quantlist__16u1__p8_1,
  129798. NULL,
  129799. &_vq_auxt__16u1__p8_1,
  129800. NULL,
  129801. 0
  129802. };
  129803. static long _vq_quantlist__16u1__p9_0[] = {
  129804. 7,
  129805. 6,
  129806. 8,
  129807. 5,
  129808. 9,
  129809. 4,
  129810. 10,
  129811. 3,
  129812. 11,
  129813. 2,
  129814. 12,
  129815. 1,
  129816. 13,
  129817. 0,
  129818. 14,
  129819. };
  129820. static long _vq_lengthlist__16u1__p9_0[] = {
  129821. 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129822. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129823. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129824. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129825. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129826. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129827. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129828. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129829. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129830. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129831. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129832. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129833. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  129834. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  129835. 8,
  129836. };
  129837. static float _vq_quantthresh__16u1__p9_0[] = {
  129838. -1657.5, -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5,
  129839. 382.5, 637.5, 892.5, 1147.5, 1402.5, 1657.5,
  129840. };
  129841. static long _vq_quantmap__16u1__p9_0[] = {
  129842. 13, 11, 9, 7, 5, 3, 1, 0,
  129843. 2, 4, 6, 8, 10, 12, 14,
  129844. };
  129845. static encode_aux_threshmatch _vq_auxt__16u1__p9_0 = {
  129846. _vq_quantthresh__16u1__p9_0,
  129847. _vq_quantmap__16u1__p9_0,
  129848. 15,
  129849. 15
  129850. };
  129851. static static_codebook _16u1__p9_0 = {
  129852. 2, 225,
  129853. _vq_lengthlist__16u1__p9_0,
  129854. 1, -514071552, 1627381760, 4, 0,
  129855. _vq_quantlist__16u1__p9_0,
  129856. NULL,
  129857. &_vq_auxt__16u1__p9_0,
  129858. NULL,
  129859. 0
  129860. };
  129861. static long _vq_quantlist__16u1__p9_1[] = {
  129862. 7,
  129863. 6,
  129864. 8,
  129865. 5,
  129866. 9,
  129867. 4,
  129868. 10,
  129869. 3,
  129870. 11,
  129871. 2,
  129872. 12,
  129873. 1,
  129874. 13,
  129875. 0,
  129876. 14,
  129877. };
  129878. static long _vq_lengthlist__16u1__p9_1[] = {
  129879. 1, 6, 5, 9, 9,10,10, 6, 7, 9, 9,10,10,10,10, 5,
  129880. 10, 8,10, 8,10,10, 8, 8,10, 9,10,10,10,10, 5, 8,
  129881. 9,10,10,10,10, 8,10,10,10,10,10,10,10, 9,10,10,
  129882. 10,10,10,10, 9, 9,10,10,10,10,10,10, 9, 9, 8, 9,
  129883. 10,10,10, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  129884. 10,10,10,10,10,10,10,10,10,10,10, 8,10,10,10,10,
  129885. 10,10,10,10,10,10,10,10,10, 6, 8, 8,10,10,10, 8,
  129886. 10,10,10,10,10,10,10,10, 5, 8, 8,10,10,10, 9, 9,
  129887. 10,10,10,10,10,10,10,10, 9,10,10,10,10,10,10,10,
  129888. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129889. 10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  129890. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129891. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129892. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129893. 9,
  129894. };
  129895. static float _vq_quantthresh__16u1__p9_1[] = {
  129896. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  129897. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  129898. };
  129899. static long _vq_quantmap__16u1__p9_1[] = {
  129900. 13, 11, 9, 7, 5, 3, 1, 0,
  129901. 2, 4, 6, 8, 10, 12, 14,
  129902. };
  129903. static encode_aux_threshmatch _vq_auxt__16u1__p9_1 = {
  129904. _vq_quantthresh__16u1__p9_1,
  129905. _vq_quantmap__16u1__p9_1,
  129906. 15,
  129907. 15
  129908. };
  129909. static static_codebook _16u1__p9_1 = {
  129910. 2, 225,
  129911. _vq_lengthlist__16u1__p9_1,
  129912. 1, -522338304, 1620115456, 4, 0,
  129913. _vq_quantlist__16u1__p9_1,
  129914. NULL,
  129915. &_vq_auxt__16u1__p9_1,
  129916. NULL,
  129917. 0
  129918. };
  129919. static long _vq_quantlist__16u1__p9_2[] = {
  129920. 8,
  129921. 7,
  129922. 9,
  129923. 6,
  129924. 10,
  129925. 5,
  129926. 11,
  129927. 4,
  129928. 12,
  129929. 3,
  129930. 13,
  129931. 2,
  129932. 14,
  129933. 1,
  129934. 15,
  129935. 0,
  129936. 16,
  129937. };
  129938. static long _vq_lengthlist__16u1__p9_2[] = {
  129939. 1, 6, 6, 7, 8, 8,11,10, 9, 9,11, 9,10, 9,11,11,
  129940. 9, 6, 7, 6,11, 8,11, 9,10,10,11, 9,11,10,10,10,
  129941. 11, 9, 5, 7, 7, 8, 8,10,11, 8, 8,11, 9, 9,10,11,
  129942. 9,10,11, 8, 9, 6, 8, 8, 9, 9,10,10,11,11,11, 9,
  129943. 11,10, 9,11, 8, 8, 8, 9, 8, 9,10,11, 9, 9,11,11,
  129944. 10, 9, 9,11,10, 8,11, 8, 9, 8,11, 9,10, 9,10,11,
  129945. 11,10,10, 9,10,10, 8, 8, 9,10,10,10, 9,11, 9,10,
  129946. 11,11,11,11,10, 9,11, 9, 9,11,11,10, 8,11,11,11,
  129947. 9,10,10,11,10,11,11, 9,11,10, 9,11,10,10,10,10,
  129948. 9,11,10,11,10, 9, 9,10,11, 9, 8,10,11,11,10,10,
  129949. 11, 9,11,10,11,11,10,11, 9, 9, 8,10, 8, 9,11, 9,
  129950. 8,10,10, 9,11,10,11,10,11, 9,11, 8,10,11,11,11,
  129951. 11,10,10,11,11,11,11,10,11,11,10, 9, 8,10,10, 9,
  129952. 11,10,11,11,11, 9, 9, 9,11,11,11,10,10, 9, 9,10,
  129953. 9,11,11,11,11, 8,10,11,10,11,11,10,11,11, 9, 9,
  129954. 9,10, 9,11, 9,11,11,11,11,11,10,11,11,10,11,10,
  129955. 11,11, 9,11,10,11,10, 9,10, 9,10,10,11,11,11,11,
  129956. 9,10, 9,10,11,11,10,11,11,11,11,11,11,10,11,11,
  129957. 10,
  129958. };
  129959. static float _vq_quantthresh__16u1__p9_2[] = {
  129960. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  129961. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  129962. };
  129963. static long _vq_quantmap__16u1__p9_2[] = {
  129964. 15, 13, 11, 9, 7, 5, 3, 1,
  129965. 0, 2, 4, 6, 8, 10, 12, 14,
  129966. 16,
  129967. };
  129968. static encode_aux_threshmatch _vq_auxt__16u1__p9_2 = {
  129969. _vq_quantthresh__16u1__p9_2,
  129970. _vq_quantmap__16u1__p9_2,
  129971. 17,
  129972. 17
  129973. };
  129974. static static_codebook _16u1__p9_2 = {
  129975. 2, 289,
  129976. _vq_lengthlist__16u1__p9_2,
  129977. 1, -529530880, 1611661312, 5, 0,
  129978. _vq_quantlist__16u1__p9_2,
  129979. NULL,
  129980. &_vq_auxt__16u1__p9_2,
  129981. NULL,
  129982. 0
  129983. };
  129984. static long _huff_lengthlist__16u1__short[] = {
  129985. 5, 7,10, 9,11,10,15,11,13,16, 6, 4, 6, 6, 7, 7,
  129986. 10, 9,12,16,10, 6, 5, 6, 6, 7,10,11,16,16, 9, 6,
  129987. 7, 6, 7, 7,10, 8,14,16,11, 6, 5, 4, 5, 6, 8, 9,
  129988. 15,16, 9, 6, 6, 5, 6, 6, 9, 8,14,16,12, 7, 6, 6,
  129989. 5, 6, 6, 7,13,16, 8, 6, 7, 6, 5, 5, 4, 4,11,16,
  129990. 9, 8, 9, 9, 7, 7, 6, 5,13,16,14,14,16,15,16,15,
  129991. 16,16,16,16,
  129992. };
  129993. static static_codebook _huff_book__16u1__short = {
  129994. 2, 100,
  129995. _huff_lengthlist__16u1__short,
  129996. 0, 0, 0, 0, 0,
  129997. NULL,
  129998. NULL,
  129999. NULL,
  130000. NULL,
  130001. 0
  130002. };
  130003. static long _huff_lengthlist__16u2__long[] = {
  130004. 5, 7,10,10,10,11,11,13,18,19, 6, 5, 5, 6, 7, 8,
  130005. 9,12,19,19, 8, 5, 4, 4, 6, 7, 9,13,19,19, 8, 5,
  130006. 4, 4, 5, 6, 8,12,17,19, 7, 5, 5, 4, 4, 5, 7,12,
  130007. 18,18, 8, 7, 7, 6, 5, 5, 6,10,18,18, 9, 9, 9, 8,
  130008. 6, 5, 6, 9,18,18,11,13,13,13, 8, 7, 7, 9,16,18,
  130009. 13,17,18,16,11, 9, 9, 9,17,18,15,18,18,18,15,13,
  130010. 13,14,18,18,
  130011. };
  130012. static static_codebook _huff_book__16u2__long = {
  130013. 2, 100,
  130014. _huff_lengthlist__16u2__long,
  130015. 0, 0, 0, 0, 0,
  130016. NULL,
  130017. NULL,
  130018. NULL,
  130019. NULL,
  130020. 0
  130021. };
  130022. static long _huff_lengthlist__16u2__short[] = {
  130023. 8,11,12,12,14,15,16,16,16,16, 9, 7, 7, 8, 9,11,
  130024. 13,14,16,16,13, 7, 6, 6, 7, 9,12,13,15,16,15, 7,
  130025. 6, 5, 4, 6,10,11,14,16,12, 8, 7, 4, 2, 4, 7,10,
  130026. 14,16,11, 9, 7, 5, 3, 4, 6, 9,14,16,11,10, 9, 7,
  130027. 5, 5, 6, 9,16,16,10,10, 9, 8, 6, 6, 7,10,16,16,
  130028. 11,11,11,10,10,10,11,14,16,16,16,14,14,13,14,16,
  130029. 16,16,16,16,
  130030. };
  130031. static static_codebook _huff_book__16u2__short = {
  130032. 2, 100,
  130033. _huff_lengthlist__16u2__short,
  130034. 0, 0, 0, 0, 0,
  130035. NULL,
  130036. NULL,
  130037. NULL,
  130038. NULL,
  130039. 0
  130040. };
  130041. static long _vq_quantlist__16u2_p1_0[] = {
  130042. 1,
  130043. 0,
  130044. 2,
  130045. };
  130046. static long _vq_lengthlist__16u2_p1_0[] = {
  130047. 1, 5, 5, 5, 7, 7, 5, 7, 7, 5, 7, 7, 7, 9, 9, 7,
  130048. 9, 9, 5, 7, 7, 7, 9, 9, 7, 9, 9, 5, 7, 7, 8, 9,
  130049. 9, 7, 9, 9, 7, 9, 9, 9,10,10, 9,10,10, 7, 9, 9,
  130050. 9,10,10, 9,10,11, 5, 7, 8, 8, 9, 9, 8, 9, 9, 7,
  130051. 9, 9, 9,10,10, 9, 9,10, 7, 9, 9, 9,10,10, 9,11,
  130052. 10,
  130053. };
  130054. static float _vq_quantthresh__16u2_p1_0[] = {
  130055. -0.5, 0.5,
  130056. };
  130057. static long _vq_quantmap__16u2_p1_0[] = {
  130058. 1, 0, 2,
  130059. };
  130060. static encode_aux_threshmatch _vq_auxt__16u2_p1_0 = {
  130061. _vq_quantthresh__16u2_p1_0,
  130062. _vq_quantmap__16u2_p1_0,
  130063. 3,
  130064. 3
  130065. };
  130066. static static_codebook _16u2_p1_0 = {
  130067. 4, 81,
  130068. _vq_lengthlist__16u2_p1_0,
  130069. 1, -535822336, 1611661312, 2, 0,
  130070. _vq_quantlist__16u2_p1_0,
  130071. NULL,
  130072. &_vq_auxt__16u2_p1_0,
  130073. NULL,
  130074. 0
  130075. };
  130076. static long _vq_quantlist__16u2_p2_0[] = {
  130077. 2,
  130078. 1,
  130079. 3,
  130080. 0,
  130081. 4,
  130082. };
  130083. static long _vq_lengthlist__16u2_p2_0[] = {
  130084. 3, 5, 5, 8, 8, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 9,
  130085. 10, 9,11,11, 9, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  130086. 8,10,10, 7, 8, 8,10,10,10,10,10,12,12, 9,10,10,
  130087. 11,12, 5, 7, 7, 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,
  130088. 10, 9,10,10,12,11,10,10,10,12,12, 9,10,10,12,12,
  130089. 10,11,10,13,12, 9,10,10,12,12,12,12,12,14,14,11,
  130090. 12,12,13,14, 9,10,10,12,12, 9,10,10,12,12,10,10,
  130091. 10,12,12,11,12,12,14,13,12,13,12,14,14, 5, 7, 7,
  130092. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,12,
  130093. 12,10,10,11,12,12, 7, 8, 8,10,10, 8, 9, 9,11,11,
  130094. 8, 9, 9,11,11,11,11,11,12,13,10,11,11,12,13, 7,
  130095. 8, 8,10,10, 8, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  130096. 10,13,12,10,11,11,13,13, 9,11,10,13,13,10,11,11,
  130097. 13,13,10,11,11,13,13,12,12,13,13,15,12,12,13,14,
  130098. 15, 9,10,10,12,12,10,11,10,13,12,10,11,11,13,13,
  130099. 11,13,11,14,13,12,13,13,15,15, 5, 7, 7, 9, 9, 7,
  130100. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,12,10,10,
  130101. 11,12,12, 7, 8, 8,10,10, 8, 9, 9,11,11, 8, 8, 9,
  130102. 10,11,10,11,11,13,13,10,10,11,12,13, 7, 8, 8,10,
  130103. 11, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,11,13,12,
  130104. 11,11,11,13,12, 9,10,10,12,12,10,11,11,13,13,10,
  130105. 10,11,12,13,12,13,13,15,14,11,11,13,12,14,10,10,
  130106. 11,13,13,10,11,11,13,13,10,11,11,13,13,12,13,13,
  130107. 14,14,12,13,12,14,13, 8,10, 9,12,12, 9,11,10,13,
  130108. 13, 9,10,10,12,13,12,13,13,14,14,12,12,13,14,14,
  130109. 9,11,10,13,13,10,11,11,13,13,10,11,11,13,13,12,
  130110. 13,13,15,15,13,13,13,14,15, 9,10,10,12,13,10,11,
  130111. 10,13,12,10,11,11,13,13,12,13,12,15,14,13,13,13,
  130112. 14,15,11,12,12,15,14,12,12,13,15,15,12,13,13,15,
  130113. 14,14,13,15,14,16,13,14,15,16,16,11,12,12,14,14,
  130114. 11,12,12,15,14,12,13,13,15,15,13,14,13,16,14,14,
  130115. 14,14,16,16, 8, 9, 9,12,12, 9,10,10,13,12, 9,10,
  130116. 10,13,13,12,12,12,14,14,12,12,13,15,15, 9,10,10,
  130117. 13,12,10,11,11,13,13,10,10,11,13,14,12,13,13,15,
  130118. 15,12,12,13,14,15, 9,10,10,13,13,10,11,11,13,13,
  130119. 10,11,11,13,13,12,13,13,14,14,13,14,13,15,14,11,
  130120. 12,12,14,14,12,13,13,15,14,11,12,12,14,15,14,14,
  130121. 14,16,15,13,12,14,14,16,11,12,13,14,15,12,13,13,
  130122. 14,16,12,13,12,15,14,13,15,14,16,16,14,15,13,16,
  130123. 13,
  130124. };
  130125. static float _vq_quantthresh__16u2_p2_0[] = {
  130126. -1.5, -0.5, 0.5, 1.5,
  130127. };
  130128. static long _vq_quantmap__16u2_p2_0[] = {
  130129. 3, 1, 0, 2, 4,
  130130. };
  130131. static encode_aux_threshmatch _vq_auxt__16u2_p2_0 = {
  130132. _vq_quantthresh__16u2_p2_0,
  130133. _vq_quantmap__16u2_p2_0,
  130134. 5,
  130135. 5
  130136. };
  130137. static static_codebook _16u2_p2_0 = {
  130138. 4, 625,
  130139. _vq_lengthlist__16u2_p2_0,
  130140. 1, -533725184, 1611661312, 3, 0,
  130141. _vq_quantlist__16u2_p2_0,
  130142. NULL,
  130143. &_vq_auxt__16u2_p2_0,
  130144. NULL,
  130145. 0
  130146. };
  130147. static long _vq_quantlist__16u2_p3_0[] = {
  130148. 4,
  130149. 3,
  130150. 5,
  130151. 2,
  130152. 6,
  130153. 1,
  130154. 7,
  130155. 0,
  130156. 8,
  130157. };
  130158. static long _vq_lengthlist__16u2_p3_0[] = {
  130159. 2, 4, 4, 6, 6, 7, 7, 9, 9, 4, 5, 5, 6, 6, 8, 7,
  130160. 9, 9, 4, 5, 5, 6, 6, 7, 8, 9, 9, 6, 6, 6, 7, 7,
  130161. 8, 8,10,10, 6, 6, 6, 7, 7, 8, 8, 9,10, 7, 8, 7,
  130162. 8, 8, 9, 9,10,10, 7, 8, 8, 8, 8, 9, 9,10,10, 9,
  130163. 9, 9,10, 9,10,10,11,11, 9, 9, 9,10,10,10,10,11,
  130164. 11,
  130165. };
  130166. static float _vq_quantthresh__16u2_p3_0[] = {
  130167. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  130168. };
  130169. static long _vq_quantmap__16u2_p3_0[] = {
  130170. 7, 5, 3, 1, 0, 2, 4, 6,
  130171. 8,
  130172. };
  130173. static encode_aux_threshmatch _vq_auxt__16u2_p3_0 = {
  130174. _vq_quantthresh__16u2_p3_0,
  130175. _vq_quantmap__16u2_p3_0,
  130176. 9,
  130177. 9
  130178. };
  130179. static static_codebook _16u2_p3_0 = {
  130180. 2, 81,
  130181. _vq_lengthlist__16u2_p3_0,
  130182. 1, -531628032, 1611661312, 4, 0,
  130183. _vq_quantlist__16u2_p3_0,
  130184. NULL,
  130185. &_vq_auxt__16u2_p3_0,
  130186. NULL,
  130187. 0
  130188. };
  130189. static long _vq_quantlist__16u2_p4_0[] = {
  130190. 8,
  130191. 7,
  130192. 9,
  130193. 6,
  130194. 10,
  130195. 5,
  130196. 11,
  130197. 4,
  130198. 12,
  130199. 3,
  130200. 13,
  130201. 2,
  130202. 14,
  130203. 1,
  130204. 15,
  130205. 0,
  130206. 16,
  130207. };
  130208. static long _vq_lengthlist__16u2_p4_0[] = {
  130209. 2, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,11,
  130210. 11, 5, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  130211. 12,11, 5, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  130212. 11,12,12, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  130213. 11,11,12,12, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,
  130214. 10,11,11,12,12, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,
  130215. 11,11,12,12,12,12, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,
  130216. 10,11,11,11,12,12,12, 9, 9, 9, 9, 9, 9,10,10,10,
  130217. 10,10,11,11,12,12,13,13, 8, 9, 9, 9, 9,10, 9,10,
  130218. 10,10,10,11,11,12,12,13,13, 9, 9, 9, 9, 9,10,10,
  130219. 10,10,11,11,11,12,12,12,13,13, 9, 9, 9, 9, 9,10,
  130220. 10,10,10,11,11,12,11,12,12,13,13,10,10,10,10,10,
  130221. 11,11,11,11,11,12,12,12,12,13,13,14,10,10,10,10,
  130222. 10,11,11,11,11,12,11,12,12,13,12,13,13,11,11,11,
  130223. 11,11,12,12,12,12,12,12,13,13,13,13,14,14,11,11,
  130224. 11,11,11,12,12,12,12,12,12,13,12,13,13,14,14,11,
  130225. 12,12,12,12,12,12,13,13,13,13,13,13,14,14,14,14,
  130226. 11,12,12,12,12,12,12,13,13,13,13,14,13,14,14,14,
  130227. 14,
  130228. };
  130229. static float _vq_quantthresh__16u2_p4_0[] = {
  130230. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  130231. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  130232. };
  130233. static long _vq_quantmap__16u2_p4_0[] = {
  130234. 15, 13, 11, 9, 7, 5, 3, 1,
  130235. 0, 2, 4, 6, 8, 10, 12, 14,
  130236. 16,
  130237. };
  130238. static encode_aux_threshmatch _vq_auxt__16u2_p4_0 = {
  130239. _vq_quantthresh__16u2_p4_0,
  130240. _vq_quantmap__16u2_p4_0,
  130241. 17,
  130242. 17
  130243. };
  130244. static static_codebook _16u2_p4_0 = {
  130245. 2, 289,
  130246. _vq_lengthlist__16u2_p4_0,
  130247. 1, -529530880, 1611661312, 5, 0,
  130248. _vq_quantlist__16u2_p4_0,
  130249. NULL,
  130250. &_vq_auxt__16u2_p4_0,
  130251. NULL,
  130252. 0
  130253. };
  130254. static long _vq_quantlist__16u2_p5_0[] = {
  130255. 1,
  130256. 0,
  130257. 2,
  130258. };
  130259. static long _vq_lengthlist__16u2_p5_0[] = {
  130260. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 8, 7,10, 9, 7,
  130261. 10, 9, 5, 8, 9, 7, 9,10, 7, 9,10, 4, 9, 9, 9,11,
  130262. 11, 8,11,11, 7,11,11,10,10,13,10,14,13, 7,11,11,
  130263. 10,13,11,10,13,14, 5, 9, 9, 8,11,11, 9,11,11, 7,
  130264. 11,11,10,14,13,10,12,14, 7,11,11,10,13,13,10,13,
  130265. 10,
  130266. };
  130267. static float _vq_quantthresh__16u2_p5_0[] = {
  130268. -5.5, 5.5,
  130269. };
  130270. static long _vq_quantmap__16u2_p5_0[] = {
  130271. 1, 0, 2,
  130272. };
  130273. static encode_aux_threshmatch _vq_auxt__16u2_p5_0 = {
  130274. _vq_quantthresh__16u2_p5_0,
  130275. _vq_quantmap__16u2_p5_0,
  130276. 3,
  130277. 3
  130278. };
  130279. static static_codebook _16u2_p5_0 = {
  130280. 4, 81,
  130281. _vq_lengthlist__16u2_p5_0,
  130282. 1, -529137664, 1618345984, 2, 0,
  130283. _vq_quantlist__16u2_p5_0,
  130284. NULL,
  130285. &_vq_auxt__16u2_p5_0,
  130286. NULL,
  130287. 0
  130288. };
  130289. static long _vq_quantlist__16u2_p5_1[] = {
  130290. 5,
  130291. 4,
  130292. 6,
  130293. 3,
  130294. 7,
  130295. 2,
  130296. 8,
  130297. 1,
  130298. 9,
  130299. 0,
  130300. 10,
  130301. };
  130302. static long _vq_lengthlist__16u2_p5_1[] = {
  130303. 2, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 5, 5, 5, 7, 7,
  130304. 7, 7, 8, 8, 8, 8, 5, 5, 6, 7, 7, 7, 7, 8, 8, 8,
  130305. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7,
  130306. 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 9, 9,
  130307. 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8,
  130308. 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9,
  130309. 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8,
  130310. 8, 8, 8, 9, 9, 9, 9, 9, 9,
  130311. };
  130312. static float _vq_quantthresh__16u2_p5_1[] = {
  130313. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  130314. 3.5, 4.5,
  130315. };
  130316. static long _vq_quantmap__16u2_p5_1[] = {
  130317. 9, 7, 5, 3, 1, 0, 2, 4,
  130318. 6, 8, 10,
  130319. };
  130320. static encode_aux_threshmatch _vq_auxt__16u2_p5_1 = {
  130321. _vq_quantthresh__16u2_p5_1,
  130322. _vq_quantmap__16u2_p5_1,
  130323. 11,
  130324. 11
  130325. };
  130326. static static_codebook _16u2_p5_1 = {
  130327. 2, 121,
  130328. _vq_lengthlist__16u2_p5_1,
  130329. 1, -531365888, 1611661312, 4, 0,
  130330. _vq_quantlist__16u2_p5_1,
  130331. NULL,
  130332. &_vq_auxt__16u2_p5_1,
  130333. NULL,
  130334. 0
  130335. };
  130336. static long _vq_quantlist__16u2_p6_0[] = {
  130337. 6,
  130338. 5,
  130339. 7,
  130340. 4,
  130341. 8,
  130342. 3,
  130343. 9,
  130344. 2,
  130345. 10,
  130346. 1,
  130347. 11,
  130348. 0,
  130349. 12,
  130350. };
  130351. static long _vq_lengthlist__16u2_p6_0[] = {
  130352. 1, 4, 4, 7, 7, 8, 8, 8, 8, 9, 9,10,10, 4, 6, 6,
  130353. 8, 8, 9, 9, 9, 9,10,10,12,11, 4, 6, 6, 8, 8, 9,
  130354. 9, 9, 9,10,10,11,12, 7, 8, 8, 9, 9,10,10,10,10,
  130355. 12,12,13,12, 7, 8, 8, 9, 9,10,10,10,10,11,12,12,
  130356. 12, 8, 9, 9,10,10,11,11,11,11,12,12,13,13, 8, 9,
  130357. 9,10,10,11,11,11,11,12,13,13,13, 8, 9, 9,10,10,
  130358. 11,11,12,12,13,13,14,14, 8, 9, 9,10,10,11,11,12,
  130359. 12,13,13,14,14, 9,10,10,11,12,13,12,13,14,14,14,
  130360. 14,14, 9,10,10,11,12,12,13,13,13,14,14,14,14,10,
  130361. 11,11,12,12,13,13,14,14,15,15,15,15,10,11,11,12,
  130362. 12,13,13,14,14,14,14,15,15,
  130363. };
  130364. static float _vq_quantthresh__16u2_p6_0[] = {
  130365. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  130366. 12.5, 17.5, 22.5, 27.5,
  130367. };
  130368. static long _vq_quantmap__16u2_p6_0[] = {
  130369. 11, 9, 7, 5, 3, 1, 0, 2,
  130370. 4, 6, 8, 10, 12,
  130371. };
  130372. static encode_aux_threshmatch _vq_auxt__16u2_p6_0 = {
  130373. _vq_quantthresh__16u2_p6_0,
  130374. _vq_quantmap__16u2_p6_0,
  130375. 13,
  130376. 13
  130377. };
  130378. static static_codebook _16u2_p6_0 = {
  130379. 2, 169,
  130380. _vq_lengthlist__16u2_p6_0,
  130381. 1, -526516224, 1616117760, 4, 0,
  130382. _vq_quantlist__16u2_p6_0,
  130383. NULL,
  130384. &_vq_auxt__16u2_p6_0,
  130385. NULL,
  130386. 0
  130387. };
  130388. static long _vq_quantlist__16u2_p6_1[] = {
  130389. 2,
  130390. 1,
  130391. 3,
  130392. 0,
  130393. 4,
  130394. };
  130395. static long _vq_lengthlist__16u2_p6_1[] = {
  130396. 2, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  130397. 5, 5, 6, 6, 5, 5, 5, 6, 6,
  130398. };
  130399. static float _vq_quantthresh__16u2_p6_1[] = {
  130400. -1.5, -0.5, 0.5, 1.5,
  130401. };
  130402. static long _vq_quantmap__16u2_p6_1[] = {
  130403. 3, 1, 0, 2, 4,
  130404. };
  130405. static encode_aux_threshmatch _vq_auxt__16u2_p6_1 = {
  130406. _vq_quantthresh__16u2_p6_1,
  130407. _vq_quantmap__16u2_p6_1,
  130408. 5,
  130409. 5
  130410. };
  130411. static static_codebook _16u2_p6_1 = {
  130412. 2, 25,
  130413. _vq_lengthlist__16u2_p6_1,
  130414. 1, -533725184, 1611661312, 3, 0,
  130415. _vq_quantlist__16u2_p6_1,
  130416. NULL,
  130417. &_vq_auxt__16u2_p6_1,
  130418. NULL,
  130419. 0
  130420. };
  130421. static long _vq_quantlist__16u2_p7_0[] = {
  130422. 6,
  130423. 5,
  130424. 7,
  130425. 4,
  130426. 8,
  130427. 3,
  130428. 9,
  130429. 2,
  130430. 10,
  130431. 1,
  130432. 11,
  130433. 0,
  130434. 12,
  130435. };
  130436. static long _vq_lengthlist__16u2_p7_0[] = {
  130437. 1, 4, 4, 7, 7, 7, 7, 8, 8, 9, 9,10,10, 4, 6, 6,
  130438. 9, 9, 9, 9, 9, 9,10,10,11,11, 4, 6, 6, 8, 9, 9,
  130439. 9, 9, 9,10,11,12,11, 7, 8, 9,10,10,10,10,11,10,
  130440. 11,12,12,13, 7, 9, 9,10,10,10,10,10,10,11,12,13,
  130441. 13, 7, 9, 8,10,10,11,11,11,12,12,13,13,14, 7, 9,
  130442. 9,10,10,11,11,11,12,13,13,13,13, 8, 9, 9,10,11,
  130443. 11,12,12,12,13,13,13,13, 8, 9, 9,10,11,11,11,12,
  130444. 12,13,13,14,14, 9,10,10,12,11,12,13,13,13,14,13,
  130445. 13,13, 9,10,10,11,11,12,12,13,14,13,13,14,13,10,
  130446. 11,11,12,13,14,14,14,15,14,14,14,14,10,11,11,12,
  130447. 12,13,13,13,14,14,14,15,14,
  130448. };
  130449. static float _vq_quantthresh__16u2_p7_0[] = {
  130450. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  130451. 27.5, 38.5, 49.5, 60.5,
  130452. };
  130453. static long _vq_quantmap__16u2_p7_0[] = {
  130454. 11, 9, 7, 5, 3, 1, 0, 2,
  130455. 4, 6, 8, 10, 12,
  130456. };
  130457. static encode_aux_threshmatch _vq_auxt__16u2_p7_0 = {
  130458. _vq_quantthresh__16u2_p7_0,
  130459. _vq_quantmap__16u2_p7_0,
  130460. 13,
  130461. 13
  130462. };
  130463. static static_codebook _16u2_p7_0 = {
  130464. 2, 169,
  130465. _vq_lengthlist__16u2_p7_0,
  130466. 1, -523206656, 1618345984, 4, 0,
  130467. _vq_quantlist__16u2_p7_0,
  130468. NULL,
  130469. &_vq_auxt__16u2_p7_0,
  130470. NULL,
  130471. 0
  130472. };
  130473. static long _vq_quantlist__16u2_p7_1[] = {
  130474. 5,
  130475. 4,
  130476. 6,
  130477. 3,
  130478. 7,
  130479. 2,
  130480. 8,
  130481. 1,
  130482. 9,
  130483. 0,
  130484. 10,
  130485. };
  130486. static long _vq_lengthlist__16u2_p7_1[] = {
  130487. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7,
  130488. 7, 7, 7, 7, 8, 8, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8,
  130489. 8, 6, 6, 7, 7, 7, 8, 7, 8, 8, 8, 8, 6, 7, 7, 7,
  130490. 7, 7, 7, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8,
  130491. 8, 8, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7,
  130492. 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8,
  130493. 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8,
  130494. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  130495. };
  130496. static float _vq_quantthresh__16u2_p7_1[] = {
  130497. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  130498. 3.5, 4.5,
  130499. };
  130500. static long _vq_quantmap__16u2_p7_1[] = {
  130501. 9, 7, 5, 3, 1, 0, 2, 4,
  130502. 6, 8, 10,
  130503. };
  130504. static encode_aux_threshmatch _vq_auxt__16u2_p7_1 = {
  130505. _vq_quantthresh__16u2_p7_1,
  130506. _vq_quantmap__16u2_p7_1,
  130507. 11,
  130508. 11
  130509. };
  130510. static static_codebook _16u2_p7_1 = {
  130511. 2, 121,
  130512. _vq_lengthlist__16u2_p7_1,
  130513. 1, -531365888, 1611661312, 4, 0,
  130514. _vq_quantlist__16u2_p7_1,
  130515. NULL,
  130516. &_vq_auxt__16u2_p7_1,
  130517. NULL,
  130518. 0
  130519. };
  130520. static long _vq_quantlist__16u2_p8_0[] = {
  130521. 7,
  130522. 6,
  130523. 8,
  130524. 5,
  130525. 9,
  130526. 4,
  130527. 10,
  130528. 3,
  130529. 11,
  130530. 2,
  130531. 12,
  130532. 1,
  130533. 13,
  130534. 0,
  130535. 14,
  130536. };
  130537. static long _vq_lengthlist__16u2_p8_0[] = {
  130538. 1, 5, 5, 7, 7, 8, 8, 7, 7, 8, 8,10, 9,11,11, 4,
  130539. 6, 6, 8, 8,10, 9, 9, 8, 9, 9,10,10,12,14, 4, 6,
  130540. 7, 8, 9, 9,10, 9, 8, 9, 9,10,12,12,11, 7, 8, 8,
  130541. 10,10,10,10, 9, 9,10,10,11,13,13,12, 7, 8, 8, 9,
  130542. 11,11,10, 9, 9,11,10,12,11,11,14, 8, 9, 9,11,10,
  130543. 11,11,10,10,11,11,13,12,14,12, 8, 9, 9,11,12,11,
  130544. 11,10,10,12,11,12,12,12,14, 7, 8, 8, 9, 9,10,10,
  130545. 10,11,12,11,13,13,14,12, 7, 8, 9, 9, 9,10,10,11,
  130546. 11,11,12,12,14,14,14, 8,10, 9,10,11,11,11,11,14,
  130547. 12,12,13,14,14,13, 9, 9, 9,10,11,11,11,12,12,12,
  130548. 14,12,14,13,14,10,10,10,12,11,12,11,14,13,14,13,
  130549. 14,14,13,14, 9,10,10,11,12,11,13,12,13,13,14,14,
  130550. 14,13,14,10,13,13,12,12,11,12,14,13,14,13,14,12,
  130551. 14,13,10,11,11,12,11,12,12,14,14,14,13,14,14,14,
  130552. 14,
  130553. };
  130554. static float _vq_quantthresh__16u2_p8_0[] = {
  130555. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  130556. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  130557. };
  130558. static long _vq_quantmap__16u2_p8_0[] = {
  130559. 13, 11, 9, 7, 5, 3, 1, 0,
  130560. 2, 4, 6, 8, 10, 12, 14,
  130561. };
  130562. static encode_aux_threshmatch _vq_auxt__16u2_p8_0 = {
  130563. _vq_quantthresh__16u2_p8_0,
  130564. _vq_quantmap__16u2_p8_0,
  130565. 15,
  130566. 15
  130567. };
  130568. static static_codebook _16u2_p8_0 = {
  130569. 2, 225,
  130570. _vq_lengthlist__16u2_p8_0,
  130571. 1, -520986624, 1620377600, 4, 0,
  130572. _vq_quantlist__16u2_p8_0,
  130573. NULL,
  130574. &_vq_auxt__16u2_p8_0,
  130575. NULL,
  130576. 0
  130577. };
  130578. static long _vq_quantlist__16u2_p8_1[] = {
  130579. 10,
  130580. 9,
  130581. 11,
  130582. 8,
  130583. 12,
  130584. 7,
  130585. 13,
  130586. 6,
  130587. 14,
  130588. 5,
  130589. 15,
  130590. 4,
  130591. 16,
  130592. 3,
  130593. 17,
  130594. 2,
  130595. 18,
  130596. 1,
  130597. 19,
  130598. 0,
  130599. 20,
  130600. };
  130601. static long _vq_lengthlist__16u2_p8_1[] = {
  130602. 2, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10, 9,10, 9, 9,
  130603. 9,10,10,10,10, 5, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,
  130604. 10, 9,10,10,10,10,10,10,11,10, 5, 6, 6, 7, 7, 8,
  130605. 8, 8, 9, 9,10,10,10,10,10,10,10,10,10,10,10, 7,
  130606. 7, 7, 8, 8, 9, 8, 9, 9,10, 9,10,10,10,10,10,10,
  130607. 11,10,11,10, 7, 7, 7, 8, 8, 8, 9, 9, 9,10, 9,10,
  130608. 10,10,10,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9,
  130609. 10, 9,10,10,10,10,10,10,10,11,10,10,11,10, 8, 8,
  130610. 8, 8, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,11,
  130611. 11,10,10, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,
  130612. 11,10,11,10,11,10,11,10, 8, 9, 9, 9, 9, 9,10,10,
  130613. 10,10,10,10,10,10,10,10,11,11,10,10,10, 9,10, 9,
  130614. 9,10,10,10,11,10,10,10,10,10,10,10,10,11,11,11,
  130615. 11,11, 9, 9, 9,10, 9,10,10,10,10,10,10,11,10,11,
  130616. 10,11,11,11,11,10,10, 9,10, 9,10,10,10,10,11,10,
  130617. 10,10,10,10,11,10,11,10,11,10,10,11, 9,10,10,10,
  130618. 10,10,10,10,10,10,11,10,10,11,11,10,11,11,11,11,
  130619. 11, 9, 9,10,10,10,10,10,11,10,10,11,10,10,11,10,
  130620. 10,11,11,11,11,11, 9,10,10,10,10,10,10,10,11,10,
  130621. 11,10,11,10,11,11,11,11,11,10,11,10,10,10,10,10,
  130622. 10,10,10,10,11,11,11,11,11,11,11,11,11,10,11,11,
  130623. 10,10,10,10,10,11,10,10,10,11,10,11,11,11,11,10,
  130624. 12,11,11,11,10,10,10,10,10,10,11,10,10,10,11,11,
  130625. 12,11,11,11,11,11,11,11,11,11,10,10,10,11,10,11,
  130626. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
  130627. 10,10,11,10,11,10,10,11,11,11,11,11,11,11,11,11,
  130628. 11,11,11,10,10,10,10,10,10,10,11,11,10,11,11,10,
  130629. 11,11,10,11,11,11,10,11,11,
  130630. };
  130631. static float _vq_quantthresh__16u2_p8_1[] = {
  130632. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  130633. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  130634. 6.5, 7.5, 8.5, 9.5,
  130635. };
  130636. static long _vq_quantmap__16u2_p8_1[] = {
  130637. 19, 17, 15, 13, 11, 9, 7, 5,
  130638. 3, 1, 0, 2, 4, 6, 8, 10,
  130639. 12, 14, 16, 18, 20,
  130640. };
  130641. static encode_aux_threshmatch _vq_auxt__16u2_p8_1 = {
  130642. _vq_quantthresh__16u2_p8_1,
  130643. _vq_quantmap__16u2_p8_1,
  130644. 21,
  130645. 21
  130646. };
  130647. static static_codebook _16u2_p8_1 = {
  130648. 2, 441,
  130649. _vq_lengthlist__16u2_p8_1,
  130650. 1, -529268736, 1611661312, 5, 0,
  130651. _vq_quantlist__16u2_p8_1,
  130652. NULL,
  130653. &_vq_auxt__16u2_p8_1,
  130654. NULL,
  130655. 0
  130656. };
  130657. static long _vq_quantlist__16u2_p9_0[] = {
  130658. 5586,
  130659. 4655,
  130660. 6517,
  130661. 3724,
  130662. 7448,
  130663. 2793,
  130664. 8379,
  130665. 1862,
  130666. 9310,
  130667. 931,
  130668. 10241,
  130669. 0,
  130670. 11172,
  130671. 5521,
  130672. 5651,
  130673. };
  130674. static long _vq_lengthlist__16u2_p9_0[] = {
  130675. 1,10,10,10,10,10,10,10,10,10,10,10,10, 5, 4,10,
  130676. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130677. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130678. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130679. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130680. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130681. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130682. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130683. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130684. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130685. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130686. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130687. 10,10,10, 4,10,10,10,10,10,10,10,10,10,10,10,10,
  130688. 6, 6, 5,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 5,
  130689. 5,
  130690. };
  130691. static float _vq_quantthresh__16u2_p9_0[] = {
  130692. -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -498, -32.5, 32.5,
  130693. 498, 1396.5, 2327.5, 3258.5, 4189.5, 5120.5,
  130694. };
  130695. static long _vq_quantmap__16u2_p9_0[] = {
  130696. 11, 9, 7, 5, 3, 1, 13, 0,
  130697. 14, 2, 4, 6, 8, 10, 12,
  130698. };
  130699. static encode_aux_threshmatch _vq_auxt__16u2_p9_0 = {
  130700. _vq_quantthresh__16u2_p9_0,
  130701. _vq_quantmap__16u2_p9_0,
  130702. 15,
  130703. 15
  130704. };
  130705. static static_codebook _16u2_p9_0 = {
  130706. 2, 225,
  130707. _vq_lengthlist__16u2_p9_0,
  130708. 1, -510275072, 1611661312, 14, 0,
  130709. _vq_quantlist__16u2_p9_0,
  130710. NULL,
  130711. &_vq_auxt__16u2_p9_0,
  130712. NULL,
  130713. 0
  130714. };
  130715. static long _vq_quantlist__16u2_p9_1[] = {
  130716. 392,
  130717. 343,
  130718. 441,
  130719. 294,
  130720. 490,
  130721. 245,
  130722. 539,
  130723. 196,
  130724. 588,
  130725. 147,
  130726. 637,
  130727. 98,
  130728. 686,
  130729. 49,
  130730. 735,
  130731. 0,
  130732. 784,
  130733. 388,
  130734. 396,
  130735. };
  130736. static long _vq_lengthlist__16u2_p9_1[] = {
  130737. 1,12,10,12,10,12,10,12,11,12,12,12,12,12,12,12,
  130738. 12, 5, 5, 9,10,12,11,11,12,12,12,12,12,12,12,12,
  130739. 12,12,12,12,10, 9, 9,11, 9,11,11,12,11,12,12,12,
  130740. 12,12,12,12,12,12,12, 8, 8,10,11, 9,12,11,12,12,
  130741. 12,12,12,12,12,12,12,12,12,12, 9, 8,10,11,12,11,
  130742. 12,11,12,12,12,12,12,12,12,12,12,12,12, 8, 9,11,
  130743. 11,10,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130744. 9,10,11,12,11,12,11,12,12,12,12,12,12,12,12,12,
  130745. 12,12,12, 9, 9,11,12,12,12,12,12,12,12,12,12,12,
  130746. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130747. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130748. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130749. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130750. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130751. 12,12,12,12,11,11,11,11,11,11,11,11,11,11,11,11,
  130752. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130753. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130754. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130755. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130756. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130757. 11,11,11, 5, 8, 9, 9, 8,11, 9,11,11,11,11,11,11,
  130758. 11,11,11,11, 5, 5, 4, 8, 8, 8, 8,10, 9,10,10,11,
  130759. 11,11,11,11,11,11,11, 5, 4,
  130760. };
  130761. static float _vq_quantthresh__16u2_p9_1[] = {
  130762. -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5, -26.5,
  130763. -2, 2, 26.5, 73.5, 122.5, 171.5, 220.5, 269.5,
  130764. 318.5, 367.5,
  130765. };
  130766. static long _vq_quantmap__16u2_p9_1[] = {
  130767. 15, 13, 11, 9, 7, 5, 3, 1,
  130768. 17, 0, 18, 2, 4, 6, 8, 10,
  130769. 12, 14, 16,
  130770. };
  130771. static encode_aux_threshmatch _vq_auxt__16u2_p9_1 = {
  130772. _vq_quantthresh__16u2_p9_1,
  130773. _vq_quantmap__16u2_p9_1,
  130774. 19,
  130775. 19
  130776. };
  130777. static static_codebook _16u2_p9_1 = {
  130778. 2, 361,
  130779. _vq_lengthlist__16u2_p9_1,
  130780. 1, -518488064, 1611661312, 10, 0,
  130781. _vq_quantlist__16u2_p9_1,
  130782. NULL,
  130783. &_vq_auxt__16u2_p9_1,
  130784. NULL,
  130785. 0
  130786. };
  130787. static long _vq_quantlist__16u2_p9_2[] = {
  130788. 24,
  130789. 23,
  130790. 25,
  130791. 22,
  130792. 26,
  130793. 21,
  130794. 27,
  130795. 20,
  130796. 28,
  130797. 19,
  130798. 29,
  130799. 18,
  130800. 30,
  130801. 17,
  130802. 31,
  130803. 16,
  130804. 32,
  130805. 15,
  130806. 33,
  130807. 14,
  130808. 34,
  130809. 13,
  130810. 35,
  130811. 12,
  130812. 36,
  130813. 11,
  130814. 37,
  130815. 10,
  130816. 38,
  130817. 9,
  130818. 39,
  130819. 8,
  130820. 40,
  130821. 7,
  130822. 41,
  130823. 6,
  130824. 42,
  130825. 5,
  130826. 43,
  130827. 4,
  130828. 44,
  130829. 3,
  130830. 45,
  130831. 2,
  130832. 46,
  130833. 1,
  130834. 47,
  130835. 0,
  130836. 48,
  130837. };
  130838. static long _vq_lengthlist__16u2_p9_2[] = {
  130839. 1, 3, 3, 4, 7, 7, 7, 8, 7, 7, 7, 7, 8, 8, 8, 8,
  130840. 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 9, 9, 8, 9, 9,
  130841. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,12,12,10,
  130842. 11,
  130843. };
  130844. static float _vq_quantthresh__16u2_p9_2[] = {
  130845. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  130846. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  130847. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  130848. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  130849. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  130850. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  130851. };
  130852. static long _vq_quantmap__16u2_p9_2[] = {
  130853. 47, 45, 43, 41, 39, 37, 35, 33,
  130854. 31, 29, 27, 25, 23, 21, 19, 17,
  130855. 15, 13, 11, 9, 7, 5, 3, 1,
  130856. 0, 2, 4, 6, 8, 10, 12, 14,
  130857. 16, 18, 20, 22, 24, 26, 28, 30,
  130858. 32, 34, 36, 38, 40, 42, 44, 46,
  130859. 48,
  130860. };
  130861. static encode_aux_threshmatch _vq_auxt__16u2_p9_2 = {
  130862. _vq_quantthresh__16u2_p9_2,
  130863. _vq_quantmap__16u2_p9_2,
  130864. 49,
  130865. 49
  130866. };
  130867. static static_codebook _16u2_p9_2 = {
  130868. 1, 49,
  130869. _vq_lengthlist__16u2_p9_2,
  130870. 1, -526909440, 1611661312, 6, 0,
  130871. _vq_quantlist__16u2_p9_2,
  130872. NULL,
  130873. &_vq_auxt__16u2_p9_2,
  130874. NULL,
  130875. 0
  130876. };
  130877. static long _vq_quantlist__8u0__p1_0[] = {
  130878. 1,
  130879. 0,
  130880. 2,
  130881. };
  130882. static long _vq_lengthlist__8u0__p1_0[] = {
  130883. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  130884. 10,10, 5, 8, 8, 7,10,10, 8,10,10, 4, 9, 8, 8,11,
  130885. 11, 8,11,11, 7,11,11,10,11,13,10,13,13, 7,11,11,
  130886. 10,13,12,10,13,13, 5, 9, 8, 8,11,11, 8,11,11, 7,
  130887. 11,11, 9,13,13,10,12,13, 7,11,11,10,13,13,10,13,
  130888. 11,
  130889. };
  130890. static float _vq_quantthresh__8u0__p1_0[] = {
  130891. -0.5, 0.5,
  130892. };
  130893. static long _vq_quantmap__8u0__p1_0[] = {
  130894. 1, 0, 2,
  130895. };
  130896. static encode_aux_threshmatch _vq_auxt__8u0__p1_0 = {
  130897. _vq_quantthresh__8u0__p1_0,
  130898. _vq_quantmap__8u0__p1_0,
  130899. 3,
  130900. 3
  130901. };
  130902. static static_codebook _8u0__p1_0 = {
  130903. 4, 81,
  130904. _vq_lengthlist__8u0__p1_0,
  130905. 1, -535822336, 1611661312, 2, 0,
  130906. _vq_quantlist__8u0__p1_0,
  130907. NULL,
  130908. &_vq_auxt__8u0__p1_0,
  130909. NULL,
  130910. 0
  130911. };
  130912. static long _vq_quantlist__8u0__p2_0[] = {
  130913. 1,
  130914. 0,
  130915. 2,
  130916. };
  130917. static long _vq_lengthlist__8u0__p2_0[] = {
  130918. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 6, 7, 8, 6,
  130919. 7, 8, 5, 7, 7, 6, 8, 8, 7, 9, 7, 5, 7, 7, 7, 9,
  130920. 9, 7, 8, 8, 6, 9, 8, 7, 7,10, 8,10,10, 6, 8, 8,
  130921. 8,10, 8, 8,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 9, 6,
  130922. 8, 8, 8,10,10, 8, 8,10, 6, 8, 9, 8,10,10, 7,10,
  130923. 8,
  130924. };
  130925. static float _vq_quantthresh__8u0__p2_0[] = {
  130926. -0.5, 0.5,
  130927. };
  130928. static long _vq_quantmap__8u0__p2_0[] = {
  130929. 1, 0, 2,
  130930. };
  130931. static encode_aux_threshmatch _vq_auxt__8u0__p2_0 = {
  130932. _vq_quantthresh__8u0__p2_0,
  130933. _vq_quantmap__8u0__p2_0,
  130934. 3,
  130935. 3
  130936. };
  130937. static static_codebook _8u0__p2_0 = {
  130938. 4, 81,
  130939. _vq_lengthlist__8u0__p2_0,
  130940. 1, -535822336, 1611661312, 2, 0,
  130941. _vq_quantlist__8u0__p2_0,
  130942. NULL,
  130943. &_vq_auxt__8u0__p2_0,
  130944. NULL,
  130945. 0
  130946. };
  130947. static long _vq_quantlist__8u0__p3_0[] = {
  130948. 2,
  130949. 1,
  130950. 3,
  130951. 0,
  130952. 4,
  130953. };
  130954. static long _vq_lengthlist__8u0__p3_0[] = {
  130955. 1, 5, 5, 7, 7, 6, 7, 7, 9, 9, 6, 7, 7, 9, 9, 8,
  130956. 10, 9,11,11, 8, 9, 9,11,11, 6, 8, 8,10,10, 8,10,
  130957. 10,11,11, 8,10,10,11,11,10,11,11,12,12,10,11,11,
  130958. 12,13, 6, 8, 8,10,10, 8,10,10,11,11, 8,10,10,11,
  130959. 11, 9,10,11,12,12,10,11,11,12,12, 8,11,11,14,13,
  130960. 10,12,11,15,13,10,12,11,14,14,12,13,12,16,14,12,
  130961. 14,12,16,15, 8,11,11,13,14,10,11,12,13,15,10,11,
  130962. 12,13,15,11,12,13,14,15,12,12,14,14,16, 5, 8, 8,
  130963. 11,11, 9,11,11,12,12, 8,10,11,12,12,11,12,12,15,
  130964. 14,11,12,12,14,14, 7,11,10,13,12,10,11,12,13,14,
  130965. 10,12,12,14,13,12,13,13,14,15,12,13,13,15,15, 7,
  130966. 10,11,12,13,10,12,11,14,13,10,12,13,13,15,12,13,
  130967. 12,14,14,11,13,13,15,16, 9,12,12,15,14,11,13,13,
  130968. 15,16,11,13,13,16,16,13,14,15,15,15,12,14,15,17,
  130969. 16, 9,12,12,14,15,11,13,13,15,16,11,13,13,16,18,
  130970. 13,14,14,17,16,13,15,15,17,18, 5, 8, 9,11,11, 8,
  130971. 11,11,12,12, 8,10,11,12,12,11,12,12,14,14,11,12,
  130972. 12,14,15, 7,11,10,12,13,10,12,12,14,13,10,11,12,
  130973. 13,14,11,13,13,15,14,12,13,13,14,15, 7,10,11,13,
  130974. 13,10,12,12,13,14,10,12,12,13,13,11,13,13,16,16,
  130975. 12,13,13,15,14, 9,12,12,16,15,10,13,13,15,15,11,
  130976. 13,13,17,15,12,15,15,18,17,13,14,14,15,16, 9,12,
  130977. 12,15,15,11,13,13,15,16,11,13,13,15,15,12,15,15,
  130978. 16,16,13,15,14,17,15, 7,11,11,15,15,10,13,13,16,
  130979. 15,10,13,13,15,16,14,15,15,17,19,13,15,14,15,18,
  130980. 9,12,12,16,16,11,13,14,17,16,11,13,13,17,16,15,
  130981. 15,16,17,19,13,15,16, 0,18, 9,12,12,16,15,11,14,
  130982. 13,17,17,11,13,14,16,16,15,16,16,19,18,13,15,15,
  130983. 17,19,11,14,14,19,16,12,14,15, 0,18,12,16,15,18,
  130984. 17,15,15,18,16,19,14,15,17,19,19,11,14,14,18,19,
  130985. 13,15,14,19,19,12,16,15,18,17,15,17,15, 0,16,14,
  130986. 17,16,19, 0, 7,11,11,14,14,10,12,12,15,15,10,13,
  130987. 13,16,15,13,15,15,17, 0,14,15,15,16,19, 9,12,12,
  130988. 16,16,11,14,14,16,16,11,13,13,16,16,14,17,16,19,
  130989. 0,14,18,17,17,19, 9,12,12,15,16,11,13,13,15,17,
  130990. 12,14,13,19,16,13,15,15,17,19,15,17,16,17,19,11,
  130991. 14,14,19,16,12,15,15,19,17,13,14,15,17,19,14,16,
  130992. 17,19,19,16,15,16,17,19,11,15,14,16,16,12,15,15,
  130993. 19, 0,12,14,15,19,19,14,16,16, 0,18,15,19,14,18,
  130994. 16,
  130995. };
  130996. static float _vq_quantthresh__8u0__p3_0[] = {
  130997. -1.5, -0.5, 0.5, 1.5,
  130998. };
  130999. static long _vq_quantmap__8u0__p3_0[] = {
  131000. 3, 1, 0, 2, 4,
  131001. };
  131002. static encode_aux_threshmatch _vq_auxt__8u0__p3_0 = {
  131003. _vq_quantthresh__8u0__p3_0,
  131004. _vq_quantmap__8u0__p3_0,
  131005. 5,
  131006. 5
  131007. };
  131008. static static_codebook _8u0__p3_0 = {
  131009. 4, 625,
  131010. _vq_lengthlist__8u0__p3_0,
  131011. 1, -533725184, 1611661312, 3, 0,
  131012. _vq_quantlist__8u0__p3_0,
  131013. NULL,
  131014. &_vq_auxt__8u0__p3_0,
  131015. NULL,
  131016. 0
  131017. };
  131018. static long _vq_quantlist__8u0__p4_0[] = {
  131019. 2,
  131020. 1,
  131021. 3,
  131022. 0,
  131023. 4,
  131024. };
  131025. static long _vq_lengthlist__8u0__p4_0[] = {
  131026. 3, 5, 5, 8, 8, 5, 6, 7, 9, 9, 6, 7, 6, 9, 9, 9,
  131027. 9, 9,10,11, 9, 9, 9,11,10, 6, 7, 7,10,10, 7, 7,
  131028. 8,10,10, 7, 8, 8,10,10,10,10,10,10,11, 9,10,10,
  131029. 11,12, 6, 7, 7,10,10, 7, 8, 8,10,10, 7, 8, 7,10,
  131030. 10, 9,10,10,12,11,10,10,10,11,10, 9,10,10,12,11,
  131031. 10,10,10,13,11, 9,10,10,12,12,11,11,12,12,13,11,
  131032. 11,11,12,13, 9,10,10,12,12,10,10,11,12,12,10,10,
  131033. 11,12,12,11,11,11,13,13,11,12,12,13,13, 5, 7, 7,
  131034. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,11,12,
  131035. 12,10,11,10,12,12, 7, 8, 8,11,11, 7, 8, 9,10,11,
  131036. 8, 9, 9,11,11,11,10,11,10,12,10,11,11,12,13, 7,
  131037. 8, 8,10,11, 8, 9, 8,12,10, 8, 9, 9,11,12,10,11,
  131038. 10,13,11,10,11,11,13,12, 9,11,10,13,12,10,10,11,
  131039. 12,12,10,11,11,13,13,12,10,13,11,14,11,12,12,15,
  131040. 13, 9,11,11,13,13,10,11,11,13,12,10,11,11,12,14,
  131041. 12,13,11,14,12,12,12,12,14,14, 5, 7, 7,10,10, 7,
  131042. 8, 8,10,10, 7, 8, 8,11,10,10,11,11,12,12,10,11,
  131043. 10,12,12, 7, 8, 8,10,11, 8, 9, 9,12,11, 8, 8, 9,
  131044. 10,11,10,11,11,12,13,11,10,11,11,13, 6, 8, 8,10,
  131045. 11, 8, 9, 9,11,11, 7, 9, 7,11,10,10,11,11,12,12,
  131046. 10,11,10,13,10, 9,11,10,13,12,10,12,11,13,13,10,
  131047. 10,11,12,13,11,12,13,15,14,11,11,13,12,13, 9,10,
  131048. 11,12,13,10,11,11,12,13,10,11,10,13,12,12,13,13,
  131049. 13,14,12,12,11,14,11, 8,10,10,12,13,10,11,11,13,
  131050. 13,10,11,10,13,13,12,13,14,15,14,12,12,12,14,13,
  131051. 9,10,10,13,12,10,10,12,13,13,10,11,11,15,12,12,
  131052. 12,13,15,14,12,13,13,15,13, 9,10,11,12,13,10,12,
  131053. 10,13,12,10,11,11,12,13,12,14,12,15,13,12,12,12,
  131054. 15,14,11,12,11,14,13,11,11,12,14,14,12,13,13,14,
  131055. 13,13,11,15,11,15,14,14,14,16,15,11,12,12,13,14,
  131056. 11,13,11,14,14,12,12,13,14,15,12,14,12,15,12,13,
  131057. 15,14,16,15, 8,10,10,12,12,10,10,10,12,13,10,11,
  131058. 11,13,13,12,12,12,13,14,13,13,13,15,15, 9,10,10,
  131059. 12,12,10,11,11,13,12,10,10,11,13,13,12,12,12,14,
  131060. 14,12,12,13,15,14, 9,10,10,13,12,10,10,12,12,13,
  131061. 10,11,10,13,13,12,13,13,14,14,12,13,12,14,13,11,
  131062. 12,12,14,13,12,13,12,14,14,10,12,12,14,14,14,14,
  131063. 14,16,14,13,12,14,12,15,10,12,12,14,15,12,13,13,
  131064. 14,16,11,12,11,15,14,13,14,14,14,15,13,14,11,14,
  131065. 12,
  131066. };
  131067. static float _vq_quantthresh__8u0__p4_0[] = {
  131068. -1.5, -0.5, 0.5, 1.5,
  131069. };
  131070. static long _vq_quantmap__8u0__p4_0[] = {
  131071. 3, 1, 0, 2, 4,
  131072. };
  131073. static encode_aux_threshmatch _vq_auxt__8u0__p4_0 = {
  131074. _vq_quantthresh__8u0__p4_0,
  131075. _vq_quantmap__8u0__p4_0,
  131076. 5,
  131077. 5
  131078. };
  131079. static static_codebook _8u0__p4_0 = {
  131080. 4, 625,
  131081. _vq_lengthlist__8u0__p4_0,
  131082. 1, -533725184, 1611661312, 3, 0,
  131083. _vq_quantlist__8u0__p4_0,
  131084. NULL,
  131085. &_vq_auxt__8u0__p4_0,
  131086. NULL,
  131087. 0
  131088. };
  131089. static long _vq_quantlist__8u0__p5_0[] = {
  131090. 4,
  131091. 3,
  131092. 5,
  131093. 2,
  131094. 6,
  131095. 1,
  131096. 7,
  131097. 0,
  131098. 8,
  131099. };
  131100. static long _vq_lengthlist__8u0__p5_0[] = {
  131101. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 7, 8, 8,
  131102. 10,10, 4, 6, 6, 8, 8, 8, 8,10,10, 6, 8, 8, 9, 9,
  131103. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 7, 8, 8,
  131104. 9, 9,10,10,12,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  131105. 10,10,11,11,11,12,12,12, 9,10,10,11,11,12,12,12,
  131106. 12,
  131107. };
  131108. static float _vq_quantthresh__8u0__p5_0[] = {
  131109. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  131110. };
  131111. static long _vq_quantmap__8u0__p5_0[] = {
  131112. 7, 5, 3, 1, 0, 2, 4, 6,
  131113. 8,
  131114. };
  131115. static encode_aux_threshmatch _vq_auxt__8u0__p5_0 = {
  131116. _vq_quantthresh__8u0__p5_0,
  131117. _vq_quantmap__8u0__p5_0,
  131118. 9,
  131119. 9
  131120. };
  131121. static static_codebook _8u0__p5_0 = {
  131122. 2, 81,
  131123. _vq_lengthlist__8u0__p5_0,
  131124. 1, -531628032, 1611661312, 4, 0,
  131125. _vq_quantlist__8u0__p5_0,
  131126. NULL,
  131127. &_vq_auxt__8u0__p5_0,
  131128. NULL,
  131129. 0
  131130. };
  131131. static long _vq_quantlist__8u0__p6_0[] = {
  131132. 6,
  131133. 5,
  131134. 7,
  131135. 4,
  131136. 8,
  131137. 3,
  131138. 9,
  131139. 2,
  131140. 10,
  131141. 1,
  131142. 11,
  131143. 0,
  131144. 12,
  131145. };
  131146. static long _vq_lengthlist__8u0__p6_0[] = {
  131147. 1, 4, 4, 7, 7, 9, 9,11,11,12,12,16,16, 3, 6, 6,
  131148. 9, 9,11,11,12,12,13,14,18,16, 3, 6, 7, 9, 9,11,
  131149. 11,13,12,14,14,17,16, 7, 9, 9,11,11,12,12,14,14,
  131150. 14,14,17,16, 7, 9, 9,11,11,13,12,13,13,14,14,17,
  131151. 0, 9,11,11,12,13,14,14,14,13,15,14,17,17, 9,11,
  131152. 11,12,12,14,14,13,14,14,15, 0, 0,11,12,12,15,14,
  131153. 15,14,15,14,15,16,17, 0,11,12,13,13,13,14,14,15,
  131154. 14,15,15, 0, 0,12,14,14,15,15,14,16,15,15,17,16,
  131155. 0,18,13,14,14,15,14,15,14,15,16,17,16, 0, 0,17,
  131156. 17,18, 0,16,18,16, 0, 0, 0,17, 0, 0,16, 0, 0,16,
  131157. 16, 0,15, 0,17, 0, 0, 0, 0,
  131158. };
  131159. static float _vq_quantthresh__8u0__p6_0[] = {
  131160. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  131161. 12.5, 17.5, 22.5, 27.5,
  131162. };
  131163. static long _vq_quantmap__8u0__p6_0[] = {
  131164. 11, 9, 7, 5, 3, 1, 0, 2,
  131165. 4, 6, 8, 10, 12,
  131166. };
  131167. static encode_aux_threshmatch _vq_auxt__8u0__p6_0 = {
  131168. _vq_quantthresh__8u0__p6_0,
  131169. _vq_quantmap__8u0__p6_0,
  131170. 13,
  131171. 13
  131172. };
  131173. static static_codebook _8u0__p6_0 = {
  131174. 2, 169,
  131175. _vq_lengthlist__8u0__p6_0,
  131176. 1, -526516224, 1616117760, 4, 0,
  131177. _vq_quantlist__8u0__p6_0,
  131178. NULL,
  131179. &_vq_auxt__8u0__p6_0,
  131180. NULL,
  131181. 0
  131182. };
  131183. static long _vq_quantlist__8u0__p6_1[] = {
  131184. 2,
  131185. 1,
  131186. 3,
  131187. 0,
  131188. 4,
  131189. };
  131190. static long _vq_lengthlist__8u0__p6_1[] = {
  131191. 1, 4, 4, 6, 6, 4, 6, 5, 7, 7, 4, 5, 6, 7, 7, 6,
  131192. 7, 7, 7, 7, 6, 7, 7, 7, 7,
  131193. };
  131194. static float _vq_quantthresh__8u0__p6_1[] = {
  131195. -1.5, -0.5, 0.5, 1.5,
  131196. };
  131197. static long _vq_quantmap__8u0__p6_1[] = {
  131198. 3, 1, 0, 2, 4,
  131199. };
  131200. static encode_aux_threshmatch _vq_auxt__8u0__p6_1 = {
  131201. _vq_quantthresh__8u0__p6_1,
  131202. _vq_quantmap__8u0__p6_1,
  131203. 5,
  131204. 5
  131205. };
  131206. static static_codebook _8u0__p6_1 = {
  131207. 2, 25,
  131208. _vq_lengthlist__8u0__p6_1,
  131209. 1, -533725184, 1611661312, 3, 0,
  131210. _vq_quantlist__8u0__p6_1,
  131211. NULL,
  131212. &_vq_auxt__8u0__p6_1,
  131213. NULL,
  131214. 0
  131215. };
  131216. static long _vq_quantlist__8u0__p7_0[] = {
  131217. 1,
  131218. 0,
  131219. 2,
  131220. };
  131221. static long _vq_lengthlist__8u0__p7_0[] = {
  131222. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  131223. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  131224. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  131225. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  131226. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  131227. 7,
  131228. };
  131229. static float _vq_quantthresh__8u0__p7_0[] = {
  131230. -157.5, 157.5,
  131231. };
  131232. static long _vq_quantmap__8u0__p7_0[] = {
  131233. 1, 0, 2,
  131234. };
  131235. static encode_aux_threshmatch _vq_auxt__8u0__p7_0 = {
  131236. _vq_quantthresh__8u0__p7_0,
  131237. _vq_quantmap__8u0__p7_0,
  131238. 3,
  131239. 3
  131240. };
  131241. static static_codebook _8u0__p7_0 = {
  131242. 4, 81,
  131243. _vq_lengthlist__8u0__p7_0,
  131244. 1, -518803456, 1628680192, 2, 0,
  131245. _vq_quantlist__8u0__p7_0,
  131246. NULL,
  131247. &_vq_auxt__8u0__p7_0,
  131248. NULL,
  131249. 0
  131250. };
  131251. static long _vq_quantlist__8u0__p7_1[] = {
  131252. 7,
  131253. 6,
  131254. 8,
  131255. 5,
  131256. 9,
  131257. 4,
  131258. 10,
  131259. 3,
  131260. 11,
  131261. 2,
  131262. 12,
  131263. 1,
  131264. 13,
  131265. 0,
  131266. 14,
  131267. };
  131268. static long _vq_lengthlist__8u0__p7_1[] = {
  131269. 1, 5, 5, 5, 5,10,10,11,11,11,11,11,11,11,11, 5,
  131270. 7, 6, 8, 8, 9,10,11,11,11,11,11,11,11,11, 6, 6,
  131271. 7, 9, 7,11,10,11,11,11,11,11,11,11,11, 5, 6, 6,
  131272. 11, 8,11,11,11,11,11,11,11,11,11,11, 5, 6, 6, 9,
  131273. 10,11,10,11,11,11,11,11,11,11,11, 7,10,10,11,11,
  131274. 11,11,11,11,11,11,11,11,11,11, 7,11, 8,11,11,11,
  131275. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131276. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131277. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131278. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131279. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131280. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131281. 11,11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,
  131282. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131283. 10,
  131284. };
  131285. static float _vq_quantthresh__8u0__p7_1[] = {
  131286. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  131287. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  131288. };
  131289. static long _vq_quantmap__8u0__p7_1[] = {
  131290. 13, 11, 9, 7, 5, 3, 1, 0,
  131291. 2, 4, 6, 8, 10, 12, 14,
  131292. };
  131293. static encode_aux_threshmatch _vq_auxt__8u0__p7_1 = {
  131294. _vq_quantthresh__8u0__p7_1,
  131295. _vq_quantmap__8u0__p7_1,
  131296. 15,
  131297. 15
  131298. };
  131299. static static_codebook _8u0__p7_1 = {
  131300. 2, 225,
  131301. _vq_lengthlist__8u0__p7_1,
  131302. 1, -520986624, 1620377600, 4, 0,
  131303. _vq_quantlist__8u0__p7_1,
  131304. NULL,
  131305. &_vq_auxt__8u0__p7_1,
  131306. NULL,
  131307. 0
  131308. };
  131309. static long _vq_quantlist__8u0__p7_2[] = {
  131310. 10,
  131311. 9,
  131312. 11,
  131313. 8,
  131314. 12,
  131315. 7,
  131316. 13,
  131317. 6,
  131318. 14,
  131319. 5,
  131320. 15,
  131321. 4,
  131322. 16,
  131323. 3,
  131324. 17,
  131325. 2,
  131326. 18,
  131327. 1,
  131328. 19,
  131329. 0,
  131330. 20,
  131331. };
  131332. static long _vq_lengthlist__8u0__p7_2[] = {
  131333. 1, 6, 5, 7, 7, 9, 9, 9, 9,10,12,12,10,11,11,10,
  131334. 11,11,11,10,11, 6, 8, 8, 9, 9,10,10, 9,10,11,11,
  131335. 10,11,11,11,11,10,11,11,11,11, 6, 7, 8, 9, 9, 9,
  131336. 10,11,10,11,12,11,10,11,11,11,11,11,11,12,10, 8,
  131337. 9, 9,10, 9,10,10, 9,10,10,10,10,10, 9,10,10,10,
  131338. 10, 9,10,10, 9, 9, 9, 9,10,10, 9, 9,10,10,11,10,
  131339. 9,12,10,11,10, 9,10,10,10, 8, 9, 9,10, 9,10, 9,
  131340. 9,10,10, 9,10, 9,11,10,10,10,10,10, 9,10, 8, 8,
  131341. 9, 9,10, 9,11, 9, 8, 9, 9,10,11,10,10,10,11,12,
  131342. 9, 9,11, 8, 9, 8,11,10,11,10,10, 9,11,10,10,10,
  131343. 10,10,10,10,11,11,11,11, 8, 9, 9, 9,10,10,10,11,
  131344. 11,12,11,12,11,10,10,10,12,11,11,11,10, 8,10, 9,
  131345. 11,10,10,11,12,10,11,12,11,11,12,11,12,12,10,11,
  131346. 11,10, 9, 9,10,11,12,10,10,10,11,10,11,11,10,12,
  131347. 12,10,11,10,11,12,10, 9,10,10,11,10,11,11,11,11,
  131348. 11,12,11,11,11, 9,11,10,11,10,11,10, 9, 9,10,11,
  131349. 11,11,10,10,11,12,12,11,12,11,11,11,12,12,12,12,
  131350. 11, 9,11,11,12,10,11,11,11,11,11,11,12,11,11,12,
  131351. 11,11,11,10,11,11, 9,11,10,11,11,11,10,10,10,11,
  131352. 11,11,12,10,11,10,11,11,11,11,12, 9,11,10,11,11,
  131353. 10,10,11,11, 9,11,11,12,10,10,10,10,10,11,11,10,
  131354. 9,10,11,11,12,11,10,10,12,11,11,12,11,12,11,11,
  131355. 10,10,11,11,10,12,11,10,11,10,11,10,10,10,11,11,
  131356. 10,10,11,11,11,11,10,10,10,12,11,11,11,11,10, 9,
  131357. 10,11,11,11,12,11,11,11,12,10,11,11,11, 9,10,11,
  131358. 11,11,11,11,11,10,10,11,11,12,11,10,11,12,11,10,
  131359. 10,11, 9,10,11,11,11,11,11,10,11,11,10,12,11,11,
  131360. 11,12,11,11,11,10,10,11,11,
  131361. };
  131362. static float _vq_quantthresh__8u0__p7_2[] = {
  131363. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  131364. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  131365. 6.5, 7.5, 8.5, 9.5,
  131366. };
  131367. static long _vq_quantmap__8u0__p7_2[] = {
  131368. 19, 17, 15, 13, 11, 9, 7, 5,
  131369. 3, 1, 0, 2, 4, 6, 8, 10,
  131370. 12, 14, 16, 18, 20,
  131371. };
  131372. static encode_aux_threshmatch _vq_auxt__8u0__p7_2 = {
  131373. _vq_quantthresh__8u0__p7_2,
  131374. _vq_quantmap__8u0__p7_2,
  131375. 21,
  131376. 21
  131377. };
  131378. static static_codebook _8u0__p7_2 = {
  131379. 2, 441,
  131380. _vq_lengthlist__8u0__p7_2,
  131381. 1, -529268736, 1611661312, 5, 0,
  131382. _vq_quantlist__8u0__p7_2,
  131383. NULL,
  131384. &_vq_auxt__8u0__p7_2,
  131385. NULL,
  131386. 0
  131387. };
  131388. static long _huff_lengthlist__8u0__single[] = {
  131389. 4, 7,11, 9,12, 8, 7,10, 6, 4, 5, 5, 7, 5, 6,16,
  131390. 9, 5, 5, 6, 7, 7, 9,16, 7, 4, 6, 5, 7, 5, 7,17,
  131391. 10, 7, 7, 8, 7, 7, 8,18, 7, 5, 6, 4, 5, 4, 5,15,
  131392. 7, 6, 7, 5, 6, 4, 5,15,12,13,18,12,17,11, 9,17,
  131393. };
  131394. static static_codebook _huff_book__8u0__single = {
  131395. 2, 64,
  131396. _huff_lengthlist__8u0__single,
  131397. 0, 0, 0, 0, 0,
  131398. NULL,
  131399. NULL,
  131400. NULL,
  131401. NULL,
  131402. 0
  131403. };
  131404. static long _vq_quantlist__8u1__p1_0[] = {
  131405. 1,
  131406. 0,
  131407. 2,
  131408. };
  131409. static long _vq_lengthlist__8u1__p1_0[] = {
  131410. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 7, 9,10, 7,
  131411. 9, 9, 5, 8, 8, 7,10, 9, 7, 9, 9, 5, 8, 8, 8,10,
  131412. 10, 8,10,10, 7,10,10, 9,10,12,10,12,12, 7,10,10,
  131413. 9,12,11,10,12,12, 5, 8, 8, 8,10,10, 8,10,10, 7,
  131414. 10,10,10,12,12, 9,11,12, 7,10,10,10,12,12, 9,12,
  131415. 10,
  131416. };
  131417. static float _vq_quantthresh__8u1__p1_0[] = {
  131418. -0.5, 0.5,
  131419. };
  131420. static long _vq_quantmap__8u1__p1_0[] = {
  131421. 1, 0, 2,
  131422. };
  131423. static encode_aux_threshmatch _vq_auxt__8u1__p1_0 = {
  131424. _vq_quantthresh__8u1__p1_0,
  131425. _vq_quantmap__8u1__p1_0,
  131426. 3,
  131427. 3
  131428. };
  131429. static static_codebook _8u1__p1_0 = {
  131430. 4, 81,
  131431. _vq_lengthlist__8u1__p1_0,
  131432. 1, -535822336, 1611661312, 2, 0,
  131433. _vq_quantlist__8u1__p1_0,
  131434. NULL,
  131435. &_vq_auxt__8u1__p1_0,
  131436. NULL,
  131437. 0
  131438. };
  131439. static long _vq_quantlist__8u1__p2_0[] = {
  131440. 1,
  131441. 0,
  131442. 2,
  131443. };
  131444. static long _vq_lengthlist__8u1__p2_0[] = {
  131445. 3, 4, 5, 5, 6, 6, 5, 6, 6, 5, 7, 6, 6, 7, 8, 6,
  131446. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 7, 5, 6, 6, 7, 8,
  131447. 8, 6, 7, 7, 6, 8, 7, 7, 7, 9, 8, 9, 9, 6, 7, 8,
  131448. 7, 9, 7, 8, 9, 9, 5, 6, 6, 6, 7, 7, 7, 8, 8, 6,
  131449. 8, 7, 8, 9, 9, 7, 7, 9, 6, 7, 8, 8, 9, 9, 7, 9,
  131450. 7,
  131451. };
  131452. static float _vq_quantthresh__8u1__p2_0[] = {
  131453. -0.5, 0.5,
  131454. };
  131455. static long _vq_quantmap__8u1__p2_0[] = {
  131456. 1, 0, 2,
  131457. };
  131458. static encode_aux_threshmatch _vq_auxt__8u1__p2_0 = {
  131459. _vq_quantthresh__8u1__p2_0,
  131460. _vq_quantmap__8u1__p2_0,
  131461. 3,
  131462. 3
  131463. };
  131464. static static_codebook _8u1__p2_0 = {
  131465. 4, 81,
  131466. _vq_lengthlist__8u1__p2_0,
  131467. 1, -535822336, 1611661312, 2, 0,
  131468. _vq_quantlist__8u1__p2_0,
  131469. NULL,
  131470. &_vq_auxt__8u1__p2_0,
  131471. NULL,
  131472. 0
  131473. };
  131474. static long _vq_quantlist__8u1__p3_0[] = {
  131475. 2,
  131476. 1,
  131477. 3,
  131478. 0,
  131479. 4,
  131480. };
  131481. static long _vq_lengthlist__8u1__p3_0[] = {
  131482. 1, 5, 5, 7, 7, 6, 7, 7, 9, 9, 6, 7, 7, 9, 9, 8,
  131483. 10, 9,11,11, 9, 9, 9,11,11, 6, 8, 8,10,10, 8,10,
  131484. 10,11,11, 8, 9,10,11,11,10,11,11,12,12,10,11,11,
  131485. 12,13, 6, 8, 8,10,10, 8,10, 9,11,11, 8,10, 9,11,
  131486. 11,10,11,11,12,12,10,11,11,12,12, 9,11,11,14,13,
  131487. 10,12,11,14,14,10,12,11,14,13,12,13,13,15,14,12,
  131488. 13,13,15,14, 8,11,11,13,14,10,11,12,13,15,10,11,
  131489. 12,14,14,12,13,13,14,15,12,13,13,14,15, 5, 8, 8,
  131490. 11,11, 8,10,10,12,12, 8,10,10,12,12,11,12,12,14,
  131491. 13,11,12,12,13,14, 8,10,10,12,12, 9,11,12,13,14,
  131492. 10,12,12,13,13,12,12,13,14,14,11,13,13,15,15, 7,
  131493. 10,10,12,12, 9,12,11,14,12,10,11,12,13,14,12,13,
  131494. 12,14,14,12,13,13,15,16,10,12,12,15,14,11,12,13,
  131495. 15,15,11,13,13,15,16,14,14,15,15,16,13,14,15,17,
  131496. 15, 9,12,12,14,15,11,13,12,15,15,11,13,13,15,15,
  131497. 13,14,13,15,14,13,14,14,17, 0, 5, 8, 8,11,11, 8,
  131498. 10,10,12,12, 8,10,10,12,12,11,12,12,14,14,11,12,
  131499. 12,14,14, 7,10,10,12,12,10,12,12,13,13, 9,11,12,
  131500. 12,13,11,12,13,15,15,11,12,13,14,15, 8,10,10,12,
  131501. 12,10,12,11,13,13,10,12,11,13,13,11,13,13,15,14,
  131502. 12,13,12,15,13, 9,12,12,14,14,11,13,13,16,15,11,
  131503. 12,13,16,15,13,14,15,16,16,13,13,15,15,16,10,12,
  131504. 12,15,14,11,13,13,14,16,11,13,13,15,16,13,15,15,
  131505. 16,17,13,15,14,16,15, 8,11,11,14,15,10,12,12,15,
  131506. 15,10,12,12,15,16,14,15,15,16,17,13,14,14,16,16,
  131507. 9,12,12,15,15,11,13,14,15,17,11,13,13,15,16,14,
  131508. 15,16,19,17,13,15,15, 0,17, 9,12,12,15,15,11,14,
  131509. 13,16,15,11,13,13,15,16,15,15,15,18,17,13,15,15,
  131510. 17,17,11,15,14,18,16,12,14,15,17,17,12,15,15,18,
  131511. 18,15,15,16,15,19,14,16,16, 0, 0,11,14,14,16,17,
  131512. 12,15,14,18,17,12,15,15,18,18,15,17,15,18,16,14,
  131513. 16,16,18,18, 7,11,11,14,14,10,12,12,15,15,10,12,
  131514. 13,15,15,13,14,15,16,16,14,15,15,18,18, 9,12,12,
  131515. 15,15,11,13,13,16,15,11,12,13,16,16,14,15,15,17,
  131516. 16,15,16,16,17,17, 9,12,12,15,15,11,13,13,15,17,
  131517. 11,14,13,16,15,13,15,15,17,17,15,15,15,18,17,11,
  131518. 14,14,17,15,12,14,15,17,18,13,13,15,17,17,14,16,
  131519. 16,19,18,16,15,17,17, 0,11,14,14,17,17,12,15,15,
  131520. 18, 0,12,15,14,18,16,14,17,17,19, 0,16,18,15, 0,
  131521. 16,
  131522. };
  131523. static float _vq_quantthresh__8u1__p3_0[] = {
  131524. -1.5, -0.5, 0.5, 1.5,
  131525. };
  131526. static long _vq_quantmap__8u1__p3_0[] = {
  131527. 3, 1, 0, 2, 4,
  131528. };
  131529. static encode_aux_threshmatch _vq_auxt__8u1__p3_0 = {
  131530. _vq_quantthresh__8u1__p3_0,
  131531. _vq_quantmap__8u1__p3_0,
  131532. 5,
  131533. 5
  131534. };
  131535. static static_codebook _8u1__p3_0 = {
  131536. 4, 625,
  131537. _vq_lengthlist__8u1__p3_0,
  131538. 1, -533725184, 1611661312, 3, 0,
  131539. _vq_quantlist__8u1__p3_0,
  131540. NULL,
  131541. &_vq_auxt__8u1__p3_0,
  131542. NULL,
  131543. 0
  131544. };
  131545. static long _vq_quantlist__8u1__p4_0[] = {
  131546. 2,
  131547. 1,
  131548. 3,
  131549. 0,
  131550. 4,
  131551. };
  131552. static long _vq_lengthlist__8u1__p4_0[] = {
  131553. 4, 5, 5, 9, 9, 6, 7, 7, 9, 9, 6, 7, 7, 9, 9, 9,
  131554. 9, 9,11,11, 9, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 7,
  131555. 8, 9,10, 7, 7, 8, 9,10, 9, 9,10,10,11, 9, 9,10,
  131556. 10,12, 6, 7, 7, 9, 9, 7, 8, 7,10, 9, 7, 8, 7,10,
  131557. 9, 9,10, 9,12,11,10,10, 9,12,10, 9,10,10,12,11,
  131558. 9,10,10,12,11, 9,10,10,12,12,11,11,12,12,13,11,
  131559. 11,12,12,13, 9, 9,10,12,11, 9,10,10,12,12,10,10,
  131560. 10,12,12,11,12,11,13,12,11,12,11,13,12, 6, 7, 7,
  131561. 9, 9, 7, 8, 8,10,10, 7, 8, 7,10, 9,10,10,10,12,
  131562. 12,10,10,10,12,11, 7, 8, 7,10,10, 7, 7, 9,10,11,
  131563. 8, 9, 9,11,10,10,10,11,10,12,10,10,11,12,12, 7,
  131564. 8, 8,10,10, 7, 9, 8,11,10, 8, 8, 9,11,11,10,11,
  131565. 10,12,11,10,11,11,12,12, 9,10,10,12,12, 9,10,10,
  131566. 12,12,10,11,11,13,12,11,10,12,10,14,12,12,12,13,
  131567. 14, 9,10,10,12,12, 9,11,10,12,12,10,11,11,12,12,
  131568. 11,12,11,14,12,12,12,12,14,14, 5, 7, 7, 9, 9, 7,
  131569. 7, 7, 9,10, 7, 8, 8,10,10,10,10,10,11,11,10,10,
  131570. 10,12,12, 7, 8, 8,10,10, 8, 9, 8,11,10, 7, 8, 9,
  131571. 10,11,10,10,10,11,12,10,10,11,11,13, 6, 7, 8,10,
  131572. 10, 8, 9, 9,10,10, 7, 9, 7,11,10,10,11,10,12,12,
  131573. 10,11,10,12,10, 9,10,10,12,12,10,11,11,13,12, 9,
  131574. 10,10,12,12,12,12,12,14,13,11,11,12,11,14, 9,10,
  131575. 10,11,12,10,11,11,12,13, 9,10,10,12,12,12,12,12,
  131576. 14,13,11,12,10,14,11, 9, 9,10,11,12, 9,10,10,12,
  131577. 12, 9,10,10,12,12,12,12,12,14,14,11,12,12,13,12,
  131578. 9,10, 9,12,12, 9,10,11,12,13,10,11,10,13,11,12,
  131579. 12,13,13,14,12,12,12,13,13, 9,10,10,12,12,10,11,
  131580. 10,13,12,10,10,11,12,13,12,13,12,14,13,12,12,12,
  131581. 13,14,11,12,11,14,13,10,10,11,13,13,12,12,12,14,
  131582. 13,12,10,14,10,15,13,14,14,14,14,11,11,12,13,14,
  131583. 10,12,11,13,13,12,12,12,13,15,12,13,11,15,12,13,
  131584. 13,14,14,14, 9,10, 9,12,12, 9,10,10,12,12,10,10,
  131585. 10,12,12,11,11,12,12,13,12,12,12,14,14, 9,10,10,
  131586. 12,12,10,11,10,13,12,10,10,11,12,13,12,12,12,14,
  131587. 13,12,12,13,13,14, 9,10,10,12,13,10,10,11,11,12,
  131588. 9,11,10,13,12,12,12,12,13,14,12,13,12,14,13,11,
  131589. 12,11,13,13,12,13,12,14,13,10,11,12,13,13,13,13,
  131590. 13,14,15,12,11,14,12,14,11,11,12,12,13,12,12,12,
  131591. 13,14,10,12,10,14,13,13,13,13,14,15,12,14,11,15,
  131592. 10,
  131593. };
  131594. static float _vq_quantthresh__8u1__p4_0[] = {
  131595. -1.5, -0.5, 0.5, 1.5,
  131596. };
  131597. static long _vq_quantmap__8u1__p4_0[] = {
  131598. 3, 1, 0, 2, 4,
  131599. };
  131600. static encode_aux_threshmatch _vq_auxt__8u1__p4_0 = {
  131601. _vq_quantthresh__8u1__p4_0,
  131602. _vq_quantmap__8u1__p4_0,
  131603. 5,
  131604. 5
  131605. };
  131606. static static_codebook _8u1__p4_0 = {
  131607. 4, 625,
  131608. _vq_lengthlist__8u1__p4_0,
  131609. 1, -533725184, 1611661312, 3, 0,
  131610. _vq_quantlist__8u1__p4_0,
  131611. NULL,
  131612. &_vq_auxt__8u1__p4_0,
  131613. NULL,
  131614. 0
  131615. };
  131616. static long _vq_quantlist__8u1__p5_0[] = {
  131617. 4,
  131618. 3,
  131619. 5,
  131620. 2,
  131621. 6,
  131622. 1,
  131623. 7,
  131624. 0,
  131625. 8,
  131626. };
  131627. static long _vq_lengthlist__8u1__p5_0[] = {
  131628. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 5, 8, 7, 8, 8,
  131629. 10,10, 4, 6, 6, 8, 8, 8, 8,10,10, 7, 8, 8, 9, 9,
  131630. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 8, 8, 8,
  131631. 9, 9,10,10,12,11, 8, 8, 8, 9, 9,10,10,11,11, 9,
  131632. 10,10,11,11,11,11,13,12, 9,10,10,11,11,12,12,12,
  131633. 13,
  131634. };
  131635. static float _vq_quantthresh__8u1__p5_0[] = {
  131636. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  131637. };
  131638. static long _vq_quantmap__8u1__p5_0[] = {
  131639. 7, 5, 3, 1, 0, 2, 4, 6,
  131640. 8,
  131641. };
  131642. static encode_aux_threshmatch _vq_auxt__8u1__p5_0 = {
  131643. _vq_quantthresh__8u1__p5_0,
  131644. _vq_quantmap__8u1__p5_0,
  131645. 9,
  131646. 9
  131647. };
  131648. static static_codebook _8u1__p5_0 = {
  131649. 2, 81,
  131650. _vq_lengthlist__8u1__p5_0,
  131651. 1, -531628032, 1611661312, 4, 0,
  131652. _vq_quantlist__8u1__p5_0,
  131653. NULL,
  131654. &_vq_auxt__8u1__p5_0,
  131655. NULL,
  131656. 0
  131657. };
  131658. static long _vq_quantlist__8u1__p6_0[] = {
  131659. 4,
  131660. 3,
  131661. 5,
  131662. 2,
  131663. 6,
  131664. 1,
  131665. 7,
  131666. 0,
  131667. 8,
  131668. };
  131669. static long _vq_lengthlist__8u1__p6_0[] = {
  131670. 3, 4, 4, 6, 6, 7, 7, 9, 9, 4, 4, 5, 6, 6, 7, 7,
  131671. 9, 9, 4, 4, 4, 6, 6, 7, 7, 9, 9, 6, 6, 6, 7, 7,
  131672. 8, 8, 9, 9, 6, 6, 6, 7, 7, 8, 8, 9, 9, 7, 7, 7,
  131673. 8, 8, 8, 9,10,10, 7, 7, 7, 8, 8, 9, 8,10,10, 9,
  131674. 9, 9, 9, 9,10,10,10,10, 9, 9, 9, 9, 9,10,10,10,
  131675. 10,
  131676. };
  131677. static float _vq_quantthresh__8u1__p6_0[] = {
  131678. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  131679. };
  131680. static long _vq_quantmap__8u1__p6_0[] = {
  131681. 7, 5, 3, 1, 0, 2, 4, 6,
  131682. 8,
  131683. };
  131684. static encode_aux_threshmatch _vq_auxt__8u1__p6_0 = {
  131685. _vq_quantthresh__8u1__p6_0,
  131686. _vq_quantmap__8u1__p6_0,
  131687. 9,
  131688. 9
  131689. };
  131690. static static_codebook _8u1__p6_0 = {
  131691. 2, 81,
  131692. _vq_lengthlist__8u1__p6_0,
  131693. 1, -531628032, 1611661312, 4, 0,
  131694. _vq_quantlist__8u1__p6_0,
  131695. NULL,
  131696. &_vq_auxt__8u1__p6_0,
  131697. NULL,
  131698. 0
  131699. };
  131700. static long _vq_quantlist__8u1__p7_0[] = {
  131701. 1,
  131702. 0,
  131703. 2,
  131704. };
  131705. static long _vq_lengthlist__8u1__p7_0[] = {
  131706. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 9, 8,10,10, 8,
  131707. 10,10, 5, 9, 9, 7,10,10, 8,10,10, 4,10,10, 9,12,
  131708. 12, 9,11,11, 7,12,11,10,11,13,10,13,13, 7,12,12,
  131709. 10,13,12,10,13,13, 4,10,10, 9,12,12, 9,12,12, 7,
  131710. 12,12,10,13,13,10,12,13, 7,11,12,10,13,13,10,13,
  131711. 11,
  131712. };
  131713. static float _vq_quantthresh__8u1__p7_0[] = {
  131714. -5.5, 5.5,
  131715. };
  131716. static long _vq_quantmap__8u1__p7_0[] = {
  131717. 1, 0, 2,
  131718. };
  131719. static encode_aux_threshmatch _vq_auxt__8u1__p7_0 = {
  131720. _vq_quantthresh__8u1__p7_0,
  131721. _vq_quantmap__8u1__p7_0,
  131722. 3,
  131723. 3
  131724. };
  131725. static static_codebook _8u1__p7_0 = {
  131726. 4, 81,
  131727. _vq_lengthlist__8u1__p7_0,
  131728. 1, -529137664, 1618345984, 2, 0,
  131729. _vq_quantlist__8u1__p7_0,
  131730. NULL,
  131731. &_vq_auxt__8u1__p7_0,
  131732. NULL,
  131733. 0
  131734. };
  131735. static long _vq_quantlist__8u1__p7_1[] = {
  131736. 5,
  131737. 4,
  131738. 6,
  131739. 3,
  131740. 7,
  131741. 2,
  131742. 8,
  131743. 1,
  131744. 9,
  131745. 0,
  131746. 10,
  131747. };
  131748. static long _vq_lengthlist__8u1__p7_1[] = {
  131749. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 7, 7,
  131750. 8, 8, 9, 9, 9, 9, 4, 5, 5, 7, 7, 8, 8, 9, 9, 9,
  131751. 9, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8,
  131752. 8, 8, 8, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9,
  131753. 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 9, 9,
  131754. 9, 9, 9, 9,10,10,10,10, 8, 9, 9, 9, 9, 9, 9,10,
  131755. 10,10,10, 8, 9, 9, 9, 9, 9, 9,10,10,10,10, 8, 9,
  131756. 9, 9, 9, 9, 9,10,10,10,10,
  131757. };
  131758. static float _vq_quantthresh__8u1__p7_1[] = {
  131759. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  131760. 3.5, 4.5,
  131761. };
  131762. static long _vq_quantmap__8u1__p7_1[] = {
  131763. 9, 7, 5, 3, 1, 0, 2, 4,
  131764. 6, 8, 10,
  131765. };
  131766. static encode_aux_threshmatch _vq_auxt__8u1__p7_1 = {
  131767. _vq_quantthresh__8u1__p7_1,
  131768. _vq_quantmap__8u1__p7_1,
  131769. 11,
  131770. 11
  131771. };
  131772. static static_codebook _8u1__p7_1 = {
  131773. 2, 121,
  131774. _vq_lengthlist__8u1__p7_1,
  131775. 1, -531365888, 1611661312, 4, 0,
  131776. _vq_quantlist__8u1__p7_1,
  131777. NULL,
  131778. &_vq_auxt__8u1__p7_1,
  131779. NULL,
  131780. 0
  131781. };
  131782. static long _vq_quantlist__8u1__p8_0[] = {
  131783. 5,
  131784. 4,
  131785. 6,
  131786. 3,
  131787. 7,
  131788. 2,
  131789. 8,
  131790. 1,
  131791. 9,
  131792. 0,
  131793. 10,
  131794. };
  131795. static long _vq_lengthlist__8u1__p8_0[] = {
  131796. 1, 4, 4, 6, 6, 8, 8,10,10,11,11, 4, 6, 6, 7, 7,
  131797. 9, 9,11,11,13,12, 4, 6, 6, 7, 7, 9, 9,11,11,12,
  131798. 12, 6, 7, 7, 9, 9,11,11,12,12,13,13, 6, 7, 7, 9,
  131799. 9,11,11,12,12,13,13, 8, 9, 9,11,11,12,12,13,13,
  131800. 14,14, 8, 9, 9,11,11,12,12,13,13,14,14, 9,11,11,
  131801. 12,12,13,13,14,14,15,15, 9,11,11,12,12,13,13,14,
  131802. 14,15,14,11,12,12,13,13,14,14,15,15,16,16,11,12,
  131803. 12,13,13,14,14,15,15,15,15,
  131804. };
  131805. static float _vq_quantthresh__8u1__p8_0[] = {
  131806. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  131807. 38.5, 49.5,
  131808. };
  131809. static long _vq_quantmap__8u1__p8_0[] = {
  131810. 9, 7, 5, 3, 1, 0, 2, 4,
  131811. 6, 8, 10,
  131812. };
  131813. static encode_aux_threshmatch _vq_auxt__8u1__p8_0 = {
  131814. _vq_quantthresh__8u1__p8_0,
  131815. _vq_quantmap__8u1__p8_0,
  131816. 11,
  131817. 11
  131818. };
  131819. static static_codebook _8u1__p8_0 = {
  131820. 2, 121,
  131821. _vq_lengthlist__8u1__p8_0,
  131822. 1, -524582912, 1618345984, 4, 0,
  131823. _vq_quantlist__8u1__p8_0,
  131824. NULL,
  131825. &_vq_auxt__8u1__p8_0,
  131826. NULL,
  131827. 0
  131828. };
  131829. static long _vq_quantlist__8u1__p8_1[] = {
  131830. 5,
  131831. 4,
  131832. 6,
  131833. 3,
  131834. 7,
  131835. 2,
  131836. 8,
  131837. 1,
  131838. 9,
  131839. 0,
  131840. 10,
  131841. };
  131842. static long _vq_lengthlist__8u1__p8_1[] = {
  131843. 2, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 5, 6, 6, 7, 7,
  131844. 7, 7, 8, 8, 8, 8, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8,
  131845. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7,
  131846. 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8,
  131847. 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  131848. 8, 8, 8, 8, 9, 8, 9, 9, 7, 8, 8, 8, 8, 8, 8, 9,
  131849. 8, 9, 9, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8,
  131850. 8, 8, 8, 8, 8, 9, 9, 9, 9,
  131851. };
  131852. static float _vq_quantthresh__8u1__p8_1[] = {
  131853. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  131854. 3.5, 4.5,
  131855. };
  131856. static long _vq_quantmap__8u1__p8_1[] = {
  131857. 9, 7, 5, 3, 1, 0, 2, 4,
  131858. 6, 8, 10,
  131859. };
  131860. static encode_aux_threshmatch _vq_auxt__8u1__p8_1 = {
  131861. _vq_quantthresh__8u1__p8_1,
  131862. _vq_quantmap__8u1__p8_1,
  131863. 11,
  131864. 11
  131865. };
  131866. static static_codebook _8u1__p8_1 = {
  131867. 2, 121,
  131868. _vq_lengthlist__8u1__p8_1,
  131869. 1, -531365888, 1611661312, 4, 0,
  131870. _vq_quantlist__8u1__p8_1,
  131871. NULL,
  131872. &_vq_auxt__8u1__p8_1,
  131873. NULL,
  131874. 0
  131875. };
  131876. static long _vq_quantlist__8u1__p9_0[] = {
  131877. 7,
  131878. 6,
  131879. 8,
  131880. 5,
  131881. 9,
  131882. 4,
  131883. 10,
  131884. 3,
  131885. 11,
  131886. 2,
  131887. 12,
  131888. 1,
  131889. 13,
  131890. 0,
  131891. 14,
  131892. };
  131893. static long _vq_lengthlist__8u1__p9_0[] = {
  131894. 1, 4, 4,11,11,11,11,11,11,11,11,11,11,11,11, 3,
  131895. 11, 8,11,11,11,11,11,11,11,11,11,11,11,11, 3, 9,
  131896. 9,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131897. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131898. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131899. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131900. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131901. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131902. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131903. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131904. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131905. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131906. 11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,
  131907. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131908. 10,
  131909. };
  131910. static float _vq_quantthresh__8u1__p9_0[] = {
  131911. -1657.5, -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5,
  131912. 382.5, 637.5, 892.5, 1147.5, 1402.5, 1657.5,
  131913. };
  131914. static long _vq_quantmap__8u1__p9_0[] = {
  131915. 13, 11, 9, 7, 5, 3, 1, 0,
  131916. 2, 4, 6, 8, 10, 12, 14,
  131917. };
  131918. static encode_aux_threshmatch _vq_auxt__8u1__p9_0 = {
  131919. _vq_quantthresh__8u1__p9_0,
  131920. _vq_quantmap__8u1__p9_0,
  131921. 15,
  131922. 15
  131923. };
  131924. static static_codebook _8u1__p9_0 = {
  131925. 2, 225,
  131926. _vq_lengthlist__8u1__p9_0,
  131927. 1, -514071552, 1627381760, 4, 0,
  131928. _vq_quantlist__8u1__p9_0,
  131929. NULL,
  131930. &_vq_auxt__8u1__p9_0,
  131931. NULL,
  131932. 0
  131933. };
  131934. static long _vq_quantlist__8u1__p9_1[] = {
  131935. 7,
  131936. 6,
  131937. 8,
  131938. 5,
  131939. 9,
  131940. 4,
  131941. 10,
  131942. 3,
  131943. 11,
  131944. 2,
  131945. 12,
  131946. 1,
  131947. 13,
  131948. 0,
  131949. 14,
  131950. };
  131951. static long _vq_lengthlist__8u1__p9_1[] = {
  131952. 1, 4, 4, 7, 7, 9, 9, 7, 7, 8, 8,10,10,11,11, 4,
  131953. 7, 7, 9, 9,10,10, 8, 8,10,10,10,11,10,11, 4, 7,
  131954. 7, 9, 9,10,10, 8, 8,10, 9,11,11,11,11, 7, 9, 9,
  131955. 12,12,11,12,10,10,11,10,12,11,11,11, 7, 9, 9,11,
  131956. 11,13,12, 9, 9,11,10,11,11,12,11, 9,10,10,12,12,
  131957. 14,14,10,10,11,12,12,11,11,11, 9,10,11,11,13,14,
  131958. 13,10,11,11,11,12,11,12,12, 7, 8, 8,10, 9,11,10,
  131959. 11,12,12,11,12,14,12,13, 7, 8, 8, 9,10,10,11,12,
  131960. 12,12,11,12,12,12,13, 9, 9, 9,11,11,13,12,12,12,
  131961. 12,11,12,12,13,12, 8,10,10,11,10,11,12,12,12,12,
  131962. 12,12,14,12,12, 9,11,11,11,12,12,12,12,13,13,12,
  131963. 12,13,13,12,10,11,11,12,11,12,12,12,11,12,13,12,
  131964. 12,12,13,11,11,12,12,12,13,12,12,11,12,13,13,12,
  131965. 12,13,12,11,12,12,13,13,12,13,12,13,13,13,13,14,
  131966. 13,
  131967. };
  131968. static float _vq_quantthresh__8u1__p9_1[] = {
  131969. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  131970. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  131971. };
  131972. static long _vq_quantmap__8u1__p9_1[] = {
  131973. 13, 11, 9, 7, 5, 3, 1, 0,
  131974. 2, 4, 6, 8, 10, 12, 14,
  131975. };
  131976. static encode_aux_threshmatch _vq_auxt__8u1__p9_1 = {
  131977. _vq_quantthresh__8u1__p9_1,
  131978. _vq_quantmap__8u1__p9_1,
  131979. 15,
  131980. 15
  131981. };
  131982. static static_codebook _8u1__p9_1 = {
  131983. 2, 225,
  131984. _vq_lengthlist__8u1__p9_1,
  131985. 1, -522338304, 1620115456, 4, 0,
  131986. _vq_quantlist__8u1__p9_1,
  131987. NULL,
  131988. &_vq_auxt__8u1__p9_1,
  131989. NULL,
  131990. 0
  131991. };
  131992. static long _vq_quantlist__8u1__p9_2[] = {
  131993. 8,
  131994. 7,
  131995. 9,
  131996. 6,
  131997. 10,
  131998. 5,
  131999. 11,
  132000. 4,
  132001. 12,
  132002. 3,
  132003. 13,
  132004. 2,
  132005. 14,
  132006. 1,
  132007. 15,
  132008. 0,
  132009. 16,
  132010. };
  132011. static long _vq_lengthlist__8u1__p9_2[] = {
  132012. 2, 5, 4, 6, 6, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  132013. 9, 5, 6, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  132014. 9, 9, 5, 6, 6, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  132015. 9, 9, 9, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  132016. 9,10,10, 9, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  132017. 9, 9, 9,10,10, 8, 8, 8, 9, 9, 9, 9,10,10,10, 9,
  132018. 10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  132019. 10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,10,
  132020. 10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,10,10,
  132021. 10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,
  132022. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  132023. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,10,
  132024. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  132025. 9,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  132026. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,10,
  132027. 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  132028. 10, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132029. 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132030. 10,
  132031. };
  132032. static float _vq_quantthresh__8u1__p9_2[] = {
  132033. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  132034. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  132035. };
  132036. static long _vq_quantmap__8u1__p9_2[] = {
  132037. 15, 13, 11, 9, 7, 5, 3, 1,
  132038. 0, 2, 4, 6, 8, 10, 12, 14,
  132039. 16,
  132040. };
  132041. static encode_aux_threshmatch _vq_auxt__8u1__p9_2 = {
  132042. _vq_quantthresh__8u1__p9_2,
  132043. _vq_quantmap__8u1__p9_2,
  132044. 17,
  132045. 17
  132046. };
  132047. static static_codebook _8u1__p9_2 = {
  132048. 2, 289,
  132049. _vq_lengthlist__8u1__p9_2,
  132050. 1, -529530880, 1611661312, 5, 0,
  132051. _vq_quantlist__8u1__p9_2,
  132052. NULL,
  132053. &_vq_auxt__8u1__p9_2,
  132054. NULL,
  132055. 0
  132056. };
  132057. static long _huff_lengthlist__8u1__single[] = {
  132058. 4, 7,13, 9,15, 9,16, 8,10,13, 7, 5, 8, 6, 9, 7,
  132059. 10, 7,10,11,11, 6, 7, 8, 8, 9, 9, 9,12,16, 8, 5,
  132060. 8, 6, 8, 6, 9, 7,10,12,11, 7, 7, 7, 6, 7, 7, 7,
  132061. 11,15, 7, 5, 8, 6, 7, 5, 7, 6, 9,13,13, 9, 9, 8,
  132062. 6, 6, 5, 5, 9,14, 8, 6, 8, 6, 6, 4, 5, 3, 5,13,
  132063. 9, 9,11, 8,10, 7, 8, 4, 5,12,11,16,17,15,17,12,
  132064. 13, 8, 8,15,
  132065. };
  132066. static static_codebook _huff_book__8u1__single = {
  132067. 2, 100,
  132068. _huff_lengthlist__8u1__single,
  132069. 0, 0, 0, 0, 0,
  132070. NULL,
  132071. NULL,
  132072. NULL,
  132073. NULL,
  132074. 0
  132075. };
  132076. static long _huff_lengthlist__44u0__long[] = {
  132077. 5, 8,13,10,17,11,11,15, 7, 2, 4, 5, 8, 7, 9,16,
  132078. 13, 4, 3, 5, 6, 8,11,20,10, 4, 5, 5, 7, 6, 8,18,
  132079. 15, 7, 6, 7, 8,10,14,20,10, 6, 7, 6, 9, 7, 8,17,
  132080. 9, 8,10, 8,10, 5, 4,11,12,17,19,14,16,10, 7,12,
  132081. };
  132082. static static_codebook _huff_book__44u0__long = {
  132083. 2, 64,
  132084. _huff_lengthlist__44u0__long,
  132085. 0, 0, 0, 0, 0,
  132086. NULL,
  132087. NULL,
  132088. NULL,
  132089. NULL,
  132090. 0
  132091. };
  132092. static long _vq_quantlist__44u0__p1_0[] = {
  132093. 1,
  132094. 0,
  132095. 2,
  132096. };
  132097. static long _vq_lengthlist__44u0__p1_0[] = {
  132098. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,11,11, 8,
  132099. 10,10, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  132100. 11, 8,11,11, 8,12,11,11,13,13,11,13,14, 7,11,11,
  132101. 10,13,12,11,13,14, 4, 8, 8, 8,11,11, 8,11,12, 8,
  132102. 11,11,11,13,13,10,12,13, 8,11,11,11,14,13,11,14,
  132103. 13,
  132104. };
  132105. static float _vq_quantthresh__44u0__p1_0[] = {
  132106. -0.5, 0.5,
  132107. };
  132108. static long _vq_quantmap__44u0__p1_0[] = {
  132109. 1, 0, 2,
  132110. };
  132111. static encode_aux_threshmatch _vq_auxt__44u0__p1_0 = {
  132112. _vq_quantthresh__44u0__p1_0,
  132113. _vq_quantmap__44u0__p1_0,
  132114. 3,
  132115. 3
  132116. };
  132117. static static_codebook _44u0__p1_0 = {
  132118. 4, 81,
  132119. _vq_lengthlist__44u0__p1_0,
  132120. 1, -535822336, 1611661312, 2, 0,
  132121. _vq_quantlist__44u0__p1_0,
  132122. NULL,
  132123. &_vq_auxt__44u0__p1_0,
  132124. NULL,
  132125. 0
  132126. };
  132127. static long _vq_quantlist__44u0__p2_0[] = {
  132128. 1,
  132129. 0,
  132130. 2,
  132131. };
  132132. static long _vq_lengthlist__44u0__p2_0[] = {
  132133. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 8, 6,
  132134. 8, 8, 5, 7, 7, 6, 8, 8, 7, 8, 8, 4, 7, 7, 7, 8,
  132135. 8, 7, 8, 8, 7, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  132136. 8,10, 8, 8,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 8, 6,
  132137. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  132138. 9,
  132139. };
  132140. static float _vq_quantthresh__44u0__p2_0[] = {
  132141. -0.5, 0.5,
  132142. };
  132143. static long _vq_quantmap__44u0__p2_0[] = {
  132144. 1, 0, 2,
  132145. };
  132146. static encode_aux_threshmatch _vq_auxt__44u0__p2_0 = {
  132147. _vq_quantthresh__44u0__p2_0,
  132148. _vq_quantmap__44u0__p2_0,
  132149. 3,
  132150. 3
  132151. };
  132152. static static_codebook _44u0__p2_0 = {
  132153. 4, 81,
  132154. _vq_lengthlist__44u0__p2_0,
  132155. 1, -535822336, 1611661312, 2, 0,
  132156. _vq_quantlist__44u0__p2_0,
  132157. NULL,
  132158. &_vq_auxt__44u0__p2_0,
  132159. NULL,
  132160. 0
  132161. };
  132162. static long _vq_quantlist__44u0__p3_0[] = {
  132163. 2,
  132164. 1,
  132165. 3,
  132166. 0,
  132167. 4,
  132168. };
  132169. static long _vq_lengthlist__44u0__p3_0[] = {
  132170. 1, 5, 5, 8, 8, 5, 8, 7, 9, 9, 5, 7, 8, 9, 9, 9,
  132171. 10, 9,12,12, 9, 9,10,12,12, 6, 8, 8,11,10, 8,10,
  132172. 10,11,11, 8, 9,10,11,11,10,11,11,14,13,10,11,11,
  132173. 13,13, 5, 8, 8,10,10, 8,10,10,11,11, 8,10,10,11,
  132174. 11,10,11,11,13,13,10,11,11,13,13, 9,11,11,15,14,
  132175. 10,12,12,15,14,10,12,11,15,14,13,14,14,16,16,12,
  132176. 14,13,17,15, 9,11,11,14,15,10,11,12,14,16,10,11,
  132177. 12,14,16,12,13,14,16,16,13,13,15,15,18, 5, 8, 8,
  132178. 11,11, 8,10,10,12,12, 8,10,10,12,13,11,12,12,14,
  132179. 14,11,12,12,15,15, 8,10,10,13,13,10,12,12,13,13,
  132180. 10,12,12,14,14,12,13,13,15,15,12,13,13,16,16, 7,
  132181. 10,10,12,12,10,12,11,13,13,10,12,12,13,14,12,13,
  132182. 12,15,14,12,13,13,16,16,10,12,12,17,16,12,13,13,
  132183. 16,15,11,13,13,17,17,15,15,15,16,17,14,15,15,19,
  132184. 19,10,12,12,15,16,11,13,12,15,18,11,13,13,16,16,
  132185. 14,15,15,17,17,14,15,15,17,19, 5, 8, 8,11,11, 8,
  132186. 10,10,12,12, 8,10,10,12,12,11,12,12,16,15,11,12,
  132187. 12,14,15, 7,10,10,13,13,10,12,12,14,13,10,11,12,
  132188. 13,13,12,13,13,16,16,12,12,13,15,15, 8,10,10,13,
  132189. 13,10,12,12,14,14,10,12,12,13,13,12,13,13,16,16,
  132190. 12,13,13,15,15,10,12,12,16,15,11,13,13,17,16,11,
  132191. 12,13,16,15,13,15,15,19,17,14,15,14,17,16,10,12,
  132192. 12,16,16,11,13,13,16,17,12,13,13,15,17,14,15,15,
  132193. 17,19,14,15,15,17,17, 8,11,11,16,16,10,13,12,17,
  132194. 17,10,12,13,16,16,15,17,16,20,19,14,15,17,18,19,
  132195. 9,12,12,16,17,11,13,14,17,18,11,13,13,19,18,16,
  132196. 17,18,19,19,15,16,16,19,19, 9,12,12,16,17,11,14,
  132197. 13,18,17,11,13,13,17,17,16,17,16,20,19,14,16,16,
  132198. 18,18,12,15,15,19,17,14,15,16, 0,20,13,15,16,20,
  132199. 17,18,16,20, 0, 0,15,16,19,20, 0,12,15,14,18,19,
  132200. 13,16,15,20,19,13,16,15,20,18,17,18,17, 0,20,16,
  132201. 17,16, 0, 0, 8,11,11,16,15,10,12,12,17,17,10,13,
  132202. 13,17,16,14,16,15,18,20,15,16,16,19,19, 9,12,12,
  132203. 16,16,11,13,13,17,16,11,13,14,17,18,15,15,16,20,
  132204. 20,16,16,17,19,19, 9,13,12,16,17,11,14,13,17,17,
  132205. 11,14,14,18,17,14,16,15,18,19,16,17,18,18,19,12,
  132206. 14,15,19,18,13,15,16,18, 0,13,14,15, 0, 0,16,16,
  132207. 17,20, 0,17,17,20,20, 0,12,15,15,19,20,13,15,15,
  132208. 0, 0,14,16,15, 0, 0,15,18,16, 0, 0,17,18,16, 0,
  132209. 19,
  132210. };
  132211. static float _vq_quantthresh__44u0__p3_0[] = {
  132212. -1.5, -0.5, 0.5, 1.5,
  132213. };
  132214. static long _vq_quantmap__44u0__p3_0[] = {
  132215. 3, 1, 0, 2, 4,
  132216. };
  132217. static encode_aux_threshmatch _vq_auxt__44u0__p3_0 = {
  132218. _vq_quantthresh__44u0__p3_0,
  132219. _vq_quantmap__44u0__p3_0,
  132220. 5,
  132221. 5
  132222. };
  132223. static static_codebook _44u0__p3_0 = {
  132224. 4, 625,
  132225. _vq_lengthlist__44u0__p3_0,
  132226. 1, -533725184, 1611661312, 3, 0,
  132227. _vq_quantlist__44u0__p3_0,
  132228. NULL,
  132229. &_vq_auxt__44u0__p3_0,
  132230. NULL,
  132231. 0
  132232. };
  132233. static long _vq_quantlist__44u0__p4_0[] = {
  132234. 2,
  132235. 1,
  132236. 3,
  132237. 0,
  132238. 4,
  132239. };
  132240. static long _vq_lengthlist__44u0__p4_0[] = {
  132241. 4, 5, 5, 9, 9, 5, 6, 6, 9, 9, 5, 6, 6, 9, 9, 9,
  132242. 10, 9,12,12, 9, 9,10,12,12, 5, 7, 7,10,10, 7, 7,
  132243. 8,10,10, 6, 7, 8,10,10,10,10,10,11,13,10, 9,10,
  132244. 12,13, 5, 7, 7,10,10, 6, 8, 7,10,10, 7, 8, 7,10,
  132245. 10, 9,10,10,12,12,10,10,10,13,11, 9,10,10,13,13,
  132246. 10,11,10,13,13,10,10,10,13,13,12,12,13,14,14,12,
  132247. 12,13,14,14, 9,10,10,13,13,10,10,10,13,13,10,10,
  132248. 10,13,13,12,13,12,15,14,12,13,12,15,15, 5, 7, 6,
  132249. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,13,
  132250. 13,10,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,10,11,
  132251. 8, 9, 9,11,11,11,10,11,11,14,11,11,11,13,13, 6,
  132252. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  132253. 10,14,11,10,11,11,13,13,10,11,11,14,13,10,10,11,
  132254. 14,13,10,11,11,14,14,12,11,13,12,16,13,14,14,15,
  132255. 15,10,10,11,13,14,10,11,10,14,13,10,11,11,14,14,
  132256. 12,13,12,15,13,13,13,14,15,16, 5, 7, 7,10,10, 7,
  132257. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,13,13,10,10,
  132258. 11,12,13, 6, 8, 8,11,10, 8, 9, 9,11,11, 7, 8, 9,
  132259. 10,11,10,11,11,13,13,10,10,11,11,13, 6, 8, 8,10,
  132260. 11, 8, 9, 9,11,11, 8, 9, 8,12,10,10,11,11,13,13,
  132261. 10,11,10,14,11,10,10,10,14,13,10,11,11,14,13,10,
  132262. 10,11,13,13,12,14,14,16,16,12,12,13,13,15,10,11,
  132263. 11,13,14,10,11,11,14,15,10,11,10,13,13,13,14,13,
  132264. 16,16,12,13,11,15,12, 9,10,10,13,13,10,11,11,14,
  132265. 13,10,10,11,13,14,13,14,13,16,16,13,13,13,15,16,
  132266. 9,10,10,13,13,10,10,11,13,14,10,11,11,15,13,13,
  132267. 13,14,14,18,13,13,14,16,15, 9,10,10,13,14,10,11,
  132268. 10,14,13,10,11,11,13,14,13,14,13,16,15,13,13,14,
  132269. 15,16,12,13,12,16,14,11,11,13,15,15,13,14,13,16,
  132270. 15,15,12,16,12,17,14,15,15,17,17,12,13,13,14,16,
  132271. 11,13,11,16,15,12,13,14,15,16,14,15,13, 0,14,14,
  132272. 16,16, 0, 0, 9,10,10,13,13,10,11,10,14,14,10,11,
  132273. 11,13,13,12,13,13,14,16,13,14,14,16,16, 9,10,10,
  132274. 14,14,11,11,11,14,13,10,10,11,14,14,13,13,13,16,
  132275. 16,13,13,14,14,17, 9,10,10,13,14,10,11,11,13,15,
  132276. 10,11,10,14,14,13,13,13,14,17,13,14,13,17,14,12,
  132277. 13,13,16,14,13,14,13,16,15,12,12,13,15,16,15,15,
  132278. 16,18,16,15,13,15,14, 0,12,12,13,14,16,13,13,14,
  132279. 15,16,11,12,11,16,14,15,16,16,17,17,14,15,12,17,
  132280. 12,
  132281. };
  132282. static float _vq_quantthresh__44u0__p4_0[] = {
  132283. -1.5, -0.5, 0.5, 1.5,
  132284. };
  132285. static long _vq_quantmap__44u0__p4_0[] = {
  132286. 3, 1, 0, 2, 4,
  132287. };
  132288. static encode_aux_threshmatch _vq_auxt__44u0__p4_0 = {
  132289. _vq_quantthresh__44u0__p4_0,
  132290. _vq_quantmap__44u0__p4_0,
  132291. 5,
  132292. 5
  132293. };
  132294. static static_codebook _44u0__p4_0 = {
  132295. 4, 625,
  132296. _vq_lengthlist__44u0__p4_0,
  132297. 1, -533725184, 1611661312, 3, 0,
  132298. _vq_quantlist__44u0__p4_0,
  132299. NULL,
  132300. &_vq_auxt__44u0__p4_0,
  132301. NULL,
  132302. 0
  132303. };
  132304. static long _vq_quantlist__44u0__p5_0[] = {
  132305. 4,
  132306. 3,
  132307. 5,
  132308. 2,
  132309. 6,
  132310. 1,
  132311. 7,
  132312. 0,
  132313. 8,
  132314. };
  132315. static long _vq_lengthlist__44u0__p5_0[] = {
  132316. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  132317. 9, 9, 4, 6, 6, 8, 8, 8, 8, 9, 9, 7, 8, 8, 9, 9,
  132318. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,10, 7, 8, 8,
  132319. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  132320. 9, 9,10,10,11,11,12,12, 9, 9, 9,10,11,11,11,12,
  132321. 12,
  132322. };
  132323. static float _vq_quantthresh__44u0__p5_0[] = {
  132324. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  132325. };
  132326. static long _vq_quantmap__44u0__p5_0[] = {
  132327. 7, 5, 3, 1, 0, 2, 4, 6,
  132328. 8,
  132329. };
  132330. static encode_aux_threshmatch _vq_auxt__44u0__p5_0 = {
  132331. _vq_quantthresh__44u0__p5_0,
  132332. _vq_quantmap__44u0__p5_0,
  132333. 9,
  132334. 9
  132335. };
  132336. static static_codebook _44u0__p5_0 = {
  132337. 2, 81,
  132338. _vq_lengthlist__44u0__p5_0,
  132339. 1, -531628032, 1611661312, 4, 0,
  132340. _vq_quantlist__44u0__p5_0,
  132341. NULL,
  132342. &_vq_auxt__44u0__p5_0,
  132343. NULL,
  132344. 0
  132345. };
  132346. static long _vq_quantlist__44u0__p6_0[] = {
  132347. 6,
  132348. 5,
  132349. 7,
  132350. 4,
  132351. 8,
  132352. 3,
  132353. 9,
  132354. 2,
  132355. 10,
  132356. 1,
  132357. 11,
  132358. 0,
  132359. 12,
  132360. };
  132361. static long _vq_lengthlist__44u0__p6_0[] = {
  132362. 1, 4, 4, 6, 6, 8, 8,10, 9,11,10,14,13, 4, 6, 5,
  132363. 8, 8, 9, 9,11,10,11,11,14,14, 4, 5, 6, 8, 8, 9,
  132364. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  132365. 12,12,16,15, 7, 8, 8, 9, 9,10,10,11,11,12,12,15,
  132366. 15, 9,10,10,10,10,11,11,12,12,12,12,15,15, 9,10,
  132367. 9,10,11,11,11,12,12,12,13,15,15,10,10,11,11,11,
  132368. 12,12,13,12,13,13,16,15,10,11,11,11,11,12,12,13,
  132369. 12,13,13,16,17,11,11,12,12,12,13,13,13,14,14,15,
  132370. 17,17,11,11,12,12,12,13,13,13,14,14,14,16,18,14,
  132371. 15,15,15,15,16,16,16,16,17,18, 0, 0,14,15,15,15,
  132372. 15,17,16,17,18,17,17,18, 0,
  132373. };
  132374. static float _vq_quantthresh__44u0__p6_0[] = {
  132375. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  132376. 12.5, 17.5, 22.5, 27.5,
  132377. };
  132378. static long _vq_quantmap__44u0__p6_0[] = {
  132379. 11, 9, 7, 5, 3, 1, 0, 2,
  132380. 4, 6, 8, 10, 12,
  132381. };
  132382. static encode_aux_threshmatch _vq_auxt__44u0__p6_0 = {
  132383. _vq_quantthresh__44u0__p6_0,
  132384. _vq_quantmap__44u0__p6_0,
  132385. 13,
  132386. 13
  132387. };
  132388. static static_codebook _44u0__p6_0 = {
  132389. 2, 169,
  132390. _vq_lengthlist__44u0__p6_0,
  132391. 1, -526516224, 1616117760, 4, 0,
  132392. _vq_quantlist__44u0__p6_0,
  132393. NULL,
  132394. &_vq_auxt__44u0__p6_0,
  132395. NULL,
  132396. 0
  132397. };
  132398. static long _vq_quantlist__44u0__p6_1[] = {
  132399. 2,
  132400. 1,
  132401. 3,
  132402. 0,
  132403. 4,
  132404. };
  132405. static long _vq_lengthlist__44u0__p6_1[] = {
  132406. 2, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5,
  132407. 6, 6, 6, 6, 5, 6, 6, 6, 6,
  132408. };
  132409. static float _vq_quantthresh__44u0__p6_1[] = {
  132410. -1.5, -0.5, 0.5, 1.5,
  132411. };
  132412. static long _vq_quantmap__44u0__p6_1[] = {
  132413. 3, 1, 0, 2, 4,
  132414. };
  132415. static encode_aux_threshmatch _vq_auxt__44u0__p6_1 = {
  132416. _vq_quantthresh__44u0__p6_1,
  132417. _vq_quantmap__44u0__p6_1,
  132418. 5,
  132419. 5
  132420. };
  132421. static static_codebook _44u0__p6_1 = {
  132422. 2, 25,
  132423. _vq_lengthlist__44u0__p6_1,
  132424. 1, -533725184, 1611661312, 3, 0,
  132425. _vq_quantlist__44u0__p6_1,
  132426. NULL,
  132427. &_vq_auxt__44u0__p6_1,
  132428. NULL,
  132429. 0
  132430. };
  132431. static long _vq_quantlist__44u0__p7_0[] = {
  132432. 2,
  132433. 1,
  132434. 3,
  132435. 0,
  132436. 4,
  132437. };
  132438. static long _vq_lengthlist__44u0__p7_0[] = {
  132439. 1, 4, 4,11,11, 9,11,11,11,11,11,11,11,11,11,11,
  132440. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132441. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132442. 11,11, 9,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132443. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132444. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132445. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132446. 11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,
  132447. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132448. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132449. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132450. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132451. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132452. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132453. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132454. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132455. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132456. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132457. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132458. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132459. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132460. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132461. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132462. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132463. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132464. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132465. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132466. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132467. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132468. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132469. 11,11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,
  132470. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132471. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132472. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132473. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132474. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132475. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132476. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132477. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132478. 10,
  132479. };
  132480. static float _vq_quantthresh__44u0__p7_0[] = {
  132481. -253.5, -84.5, 84.5, 253.5,
  132482. };
  132483. static long _vq_quantmap__44u0__p7_0[] = {
  132484. 3, 1, 0, 2, 4,
  132485. };
  132486. static encode_aux_threshmatch _vq_auxt__44u0__p7_0 = {
  132487. _vq_quantthresh__44u0__p7_0,
  132488. _vq_quantmap__44u0__p7_0,
  132489. 5,
  132490. 5
  132491. };
  132492. static static_codebook _44u0__p7_0 = {
  132493. 4, 625,
  132494. _vq_lengthlist__44u0__p7_0,
  132495. 1, -518709248, 1626677248, 3, 0,
  132496. _vq_quantlist__44u0__p7_0,
  132497. NULL,
  132498. &_vq_auxt__44u0__p7_0,
  132499. NULL,
  132500. 0
  132501. };
  132502. static long _vq_quantlist__44u0__p7_1[] = {
  132503. 6,
  132504. 5,
  132505. 7,
  132506. 4,
  132507. 8,
  132508. 3,
  132509. 9,
  132510. 2,
  132511. 10,
  132512. 1,
  132513. 11,
  132514. 0,
  132515. 12,
  132516. };
  132517. static long _vq_lengthlist__44u0__p7_1[] = {
  132518. 1, 4, 4, 6, 6, 6, 6, 7, 7, 8, 8, 9, 9, 5, 7, 7,
  132519. 8, 7, 7, 7, 9, 8,10, 9,10,11, 5, 7, 7, 8, 8, 7,
  132520. 7, 8, 9,10,10,11,11, 6, 8, 8, 9, 9, 9, 9,11,10,
  132521. 12,12,15,12, 6, 8, 8, 9, 9, 9, 9,11,11,12,11,14,
  132522. 12, 7, 8, 8,10,10,12,12,13,13,13,15,13,13, 7, 8,
  132523. 8,10,10,11,11,13,12,14,15,15,15, 9,10,10,11,12,
  132524. 13,13,14,15,14,15,14,15, 8,10,10,12,12,14,14,15,
  132525. 14,14,15,15,14,10,12,12,14,14,15,14,15,15,15,14,
  132526. 15,15,10,12,12,13,14,15,14,15,15,14,15,15,15,12,
  132527. 15,13,15,14,15,15,15,15,15,15,15,15,13,13,15,15,
  132528. 15,15,15,15,15,15,15,15,15,
  132529. };
  132530. static float _vq_quantthresh__44u0__p7_1[] = {
  132531. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  132532. 32.5, 45.5, 58.5, 71.5,
  132533. };
  132534. static long _vq_quantmap__44u0__p7_1[] = {
  132535. 11, 9, 7, 5, 3, 1, 0, 2,
  132536. 4, 6, 8, 10, 12,
  132537. };
  132538. static encode_aux_threshmatch _vq_auxt__44u0__p7_1 = {
  132539. _vq_quantthresh__44u0__p7_1,
  132540. _vq_quantmap__44u0__p7_1,
  132541. 13,
  132542. 13
  132543. };
  132544. static static_codebook _44u0__p7_1 = {
  132545. 2, 169,
  132546. _vq_lengthlist__44u0__p7_1,
  132547. 1, -523010048, 1618608128, 4, 0,
  132548. _vq_quantlist__44u0__p7_1,
  132549. NULL,
  132550. &_vq_auxt__44u0__p7_1,
  132551. NULL,
  132552. 0
  132553. };
  132554. static long _vq_quantlist__44u0__p7_2[] = {
  132555. 6,
  132556. 5,
  132557. 7,
  132558. 4,
  132559. 8,
  132560. 3,
  132561. 9,
  132562. 2,
  132563. 10,
  132564. 1,
  132565. 11,
  132566. 0,
  132567. 12,
  132568. };
  132569. static long _vq_lengthlist__44u0__p7_2[] = {
  132570. 2, 5, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 5, 5, 6,
  132571. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 5, 6, 5, 7, 7, 8,
  132572. 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8, 8, 8, 8, 9, 8,
  132573. 9, 9, 9, 9, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  132574. 9, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 7, 8,
  132575. 8, 9, 8, 9, 8, 9, 9, 9, 9, 9, 9, 8, 9, 8, 9, 9,
  132576. 9, 9, 9, 9, 9, 9,10,10, 8, 8, 9, 9, 9, 9, 9, 9,
  132577. 9, 9,10, 9,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132578. 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132579. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,
  132580. 9, 9, 9,10, 9, 9,10,10, 9,
  132581. };
  132582. static float _vq_quantthresh__44u0__p7_2[] = {
  132583. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  132584. 2.5, 3.5, 4.5, 5.5,
  132585. };
  132586. static long _vq_quantmap__44u0__p7_2[] = {
  132587. 11, 9, 7, 5, 3, 1, 0, 2,
  132588. 4, 6, 8, 10, 12,
  132589. };
  132590. static encode_aux_threshmatch _vq_auxt__44u0__p7_2 = {
  132591. _vq_quantthresh__44u0__p7_2,
  132592. _vq_quantmap__44u0__p7_2,
  132593. 13,
  132594. 13
  132595. };
  132596. static static_codebook _44u0__p7_2 = {
  132597. 2, 169,
  132598. _vq_lengthlist__44u0__p7_2,
  132599. 1, -531103744, 1611661312, 4, 0,
  132600. _vq_quantlist__44u0__p7_2,
  132601. NULL,
  132602. &_vq_auxt__44u0__p7_2,
  132603. NULL,
  132604. 0
  132605. };
  132606. static long _huff_lengthlist__44u0__short[] = {
  132607. 12,13,14,13,17,12,15,17, 5, 5, 6,10,10,11,15,16,
  132608. 4, 3, 3, 7, 5, 7,10,16, 7, 7, 7,10, 9,11,12,16,
  132609. 6, 5, 5, 9, 5, 6,10,16, 8, 7, 7, 9, 6, 7, 9,16,
  132610. 11, 7, 3, 6, 4, 5, 8,16,12, 9, 4, 8, 5, 7, 9,16,
  132611. };
  132612. static static_codebook _huff_book__44u0__short = {
  132613. 2, 64,
  132614. _huff_lengthlist__44u0__short,
  132615. 0, 0, 0, 0, 0,
  132616. NULL,
  132617. NULL,
  132618. NULL,
  132619. NULL,
  132620. 0
  132621. };
  132622. static long _huff_lengthlist__44u1__long[] = {
  132623. 5, 8,13,10,17,11,11,15, 7, 2, 4, 5, 8, 7, 9,16,
  132624. 13, 4, 3, 5, 6, 8,11,20,10, 4, 5, 5, 7, 6, 8,18,
  132625. 15, 7, 6, 7, 8,10,14,20,10, 6, 7, 6, 9, 7, 8,17,
  132626. 9, 8,10, 8,10, 5, 4,11,12,17,19,14,16,10, 7,12,
  132627. };
  132628. static static_codebook _huff_book__44u1__long = {
  132629. 2, 64,
  132630. _huff_lengthlist__44u1__long,
  132631. 0, 0, 0, 0, 0,
  132632. NULL,
  132633. NULL,
  132634. NULL,
  132635. NULL,
  132636. 0
  132637. };
  132638. static long _vq_quantlist__44u1__p1_0[] = {
  132639. 1,
  132640. 0,
  132641. 2,
  132642. };
  132643. static long _vq_lengthlist__44u1__p1_0[] = {
  132644. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,11,11, 8,
  132645. 10,10, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  132646. 11, 8,11,11, 8,12,11,11,13,13,11,13,14, 7,11,11,
  132647. 10,13,12,11,13,14, 4, 8, 8, 8,11,11, 8,11,12, 8,
  132648. 11,11,11,13,13,10,12,13, 8,11,11,11,14,13,11,14,
  132649. 13,
  132650. };
  132651. static float _vq_quantthresh__44u1__p1_0[] = {
  132652. -0.5, 0.5,
  132653. };
  132654. static long _vq_quantmap__44u1__p1_0[] = {
  132655. 1, 0, 2,
  132656. };
  132657. static encode_aux_threshmatch _vq_auxt__44u1__p1_0 = {
  132658. _vq_quantthresh__44u1__p1_0,
  132659. _vq_quantmap__44u1__p1_0,
  132660. 3,
  132661. 3
  132662. };
  132663. static static_codebook _44u1__p1_0 = {
  132664. 4, 81,
  132665. _vq_lengthlist__44u1__p1_0,
  132666. 1, -535822336, 1611661312, 2, 0,
  132667. _vq_quantlist__44u1__p1_0,
  132668. NULL,
  132669. &_vq_auxt__44u1__p1_0,
  132670. NULL,
  132671. 0
  132672. };
  132673. static long _vq_quantlist__44u1__p2_0[] = {
  132674. 1,
  132675. 0,
  132676. 2,
  132677. };
  132678. static long _vq_lengthlist__44u1__p2_0[] = {
  132679. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 8, 6,
  132680. 8, 8, 5, 7, 7, 6, 8, 8, 7, 8, 8, 4, 7, 7, 7, 8,
  132681. 8, 7, 8, 8, 7, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  132682. 8,10, 8, 8,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 8, 6,
  132683. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  132684. 9,
  132685. };
  132686. static float _vq_quantthresh__44u1__p2_0[] = {
  132687. -0.5, 0.5,
  132688. };
  132689. static long _vq_quantmap__44u1__p2_0[] = {
  132690. 1, 0, 2,
  132691. };
  132692. static encode_aux_threshmatch _vq_auxt__44u1__p2_0 = {
  132693. _vq_quantthresh__44u1__p2_0,
  132694. _vq_quantmap__44u1__p2_0,
  132695. 3,
  132696. 3
  132697. };
  132698. static static_codebook _44u1__p2_0 = {
  132699. 4, 81,
  132700. _vq_lengthlist__44u1__p2_0,
  132701. 1, -535822336, 1611661312, 2, 0,
  132702. _vq_quantlist__44u1__p2_0,
  132703. NULL,
  132704. &_vq_auxt__44u1__p2_0,
  132705. NULL,
  132706. 0
  132707. };
  132708. static long _vq_quantlist__44u1__p3_0[] = {
  132709. 2,
  132710. 1,
  132711. 3,
  132712. 0,
  132713. 4,
  132714. };
  132715. static long _vq_lengthlist__44u1__p3_0[] = {
  132716. 1, 5, 5, 8, 8, 5, 8, 7, 9, 9, 5, 7, 8, 9, 9, 9,
  132717. 10, 9,12,12, 9, 9,10,12,12, 6, 8, 8,11,10, 8,10,
  132718. 10,11,11, 8, 9,10,11,11,10,11,11,14,13,10,11,11,
  132719. 13,13, 5, 8, 8,10,10, 8,10,10,11,11, 8,10,10,11,
  132720. 11,10,11,11,13,13,10,11,11,13,13, 9,11,11,15,14,
  132721. 10,12,12,15,14,10,12,11,15,14,13,14,14,16,16,12,
  132722. 14,13,17,15, 9,11,11,14,15,10,11,12,14,16,10,11,
  132723. 12,14,16,12,13,14,16,16,13,13,15,15,18, 5, 8, 8,
  132724. 11,11, 8,10,10,12,12, 8,10,10,12,13,11,12,12,14,
  132725. 14,11,12,12,15,15, 8,10,10,13,13,10,12,12,13,13,
  132726. 10,12,12,14,14,12,13,13,15,15,12,13,13,16,16, 7,
  132727. 10,10,12,12,10,12,11,13,13,10,12,12,13,14,12,13,
  132728. 12,15,14,12,13,13,16,16,10,12,12,17,16,12,13,13,
  132729. 16,15,11,13,13,17,17,15,15,15,16,17,14,15,15,19,
  132730. 19,10,12,12,15,16,11,13,12,15,18,11,13,13,16,16,
  132731. 14,15,15,17,17,14,15,15,17,19, 5, 8, 8,11,11, 8,
  132732. 10,10,12,12, 8,10,10,12,12,11,12,12,16,15,11,12,
  132733. 12,14,15, 7,10,10,13,13,10,12,12,14,13,10,11,12,
  132734. 13,13,12,13,13,16,16,12,12,13,15,15, 8,10,10,13,
  132735. 13,10,12,12,14,14,10,12,12,13,13,12,13,13,16,16,
  132736. 12,13,13,15,15,10,12,12,16,15,11,13,13,17,16,11,
  132737. 12,13,16,15,13,15,15,19,17,14,15,14,17,16,10,12,
  132738. 12,16,16,11,13,13,16,17,12,13,13,15,17,14,15,15,
  132739. 17,19,14,15,15,17,17, 8,11,11,16,16,10,13,12,17,
  132740. 17,10,12,13,16,16,15,17,16,20,19,14,15,17,18,19,
  132741. 9,12,12,16,17,11,13,14,17,18,11,13,13,19,18,16,
  132742. 17,18,19,19,15,16,16,19,19, 9,12,12,16,17,11,14,
  132743. 13,18,17,11,13,13,17,17,16,17,16,20,19,14,16,16,
  132744. 18,18,12,15,15,19,17,14,15,16, 0,20,13,15,16,20,
  132745. 17,18,16,20, 0, 0,15,16,19,20, 0,12,15,14,18,19,
  132746. 13,16,15,20,19,13,16,15,20,18,17,18,17, 0,20,16,
  132747. 17,16, 0, 0, 8,11,11,16,15,10,12,12,17,17,10,13,
  132748. 13,17,16,14,16,15,18,20,15,16,16,19,19, 9,12,12,
  132749. 16,16,11,13,13,17,16,11,13,14,17,18,15,15,16,20,
  132750. 20,16,16,17,19,19, 9,13,12,16,17,11,14,13,17,17,
  132751. 11,14,14,18,17,14,16,15,18,19,16,17,18,18,19,12,
  132752. 14,15,19,18,13,15,16,18, 0,13,14,15, 0, 0,16,16,
  132753. 17,20, 0,17,17,20,20, 0,12,15,15,19,20,13,15,15,
  132754. 0, 0,14,16,15, 0, 0,15,18,16, 0, 0,17,18,16, 0,
  132755. 19,
  132756. };
  132757. static float _vq_quantthresh__44u1__p3_0[] = {
  132758. -1.5, -0.5, 0.5, 1.5,
  132759. };
  132760. static long _vq_quantmap__44u1__p3_0[] = {
  132761. 3, 1, 0, 2, 4,
  132762. };
  132763. static encode_aux_threshmatch _vq_auxt__44u1__p3_0 = {
  132764. _vq_quantthresh__44u1__p3_0,
  132765. _vq_quantmap__44u1__p3_0,
  132766. 5,
  132767. 5
  132768. };
  132769. static static_codebook _44u1__p3_0 = {
  132770. 4, 625,
  132771. _vq_lengthlist__44u1__p3_0,
  132772. 1, -533725184, 1611661312, 3, 0,
  132773. _vq_quantlist__44u1__p3_0,
  132774. NULL,
  132775. &_vq_auxt__44u1__p3_0,
  132776. NULL,
  132777. 0
  132778. };
  132779. static long _vq_quantlist__44u1__p4_0[] = {
  132780. 2,
  132781. 1,
  132782. 3,
  132783. 0,
  132784. 4,
  132785. };
  132786. static long _vq_lengthlist__44u1__p4_0[] = {
  132787. 4, 5, 5, 9, 9, 5, 6, 6, 9, 9, 5, 6, 6, 9, 9, 9,
  132788. 10, 9,12,12, 9, 9,10,12,12, 5, 7, 7,10,10, 7, 7,
  132789. 8,10,10, 6, 7, 8,10,10,10,10,10,11,13,10, 9,10,
  132790. 12,13, 5, 7, 7,10,10, 6, 8, 7,10,10, 7, 8, 7,10,
  132791. 10, 9,10,10,12,12,10,10,10,13,11, 9,10,10,13,13,
  132792. 10,11,10,13,13,10,10,10,13,13,12,12,13,14,14,12,
  132793. 12,13,14,14, 9,10,10,13,13,10,10,10,13,13,10,10,
  132794. 10,13,13,12,13,12,15,14,12,13,12,15,15, 5, 7, 6,
  132795. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,13,
  132796. 13,10,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,10,11,
  132797. 8, 9, 9,11,11,11,10,11,11,14,11,11,11,13,13, 6,
  132798. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  132799. 10,14,11,10,11,11,13,13,10,11,11,14,13,10,10,11,
  132800. 14,13,10,11,11,14,14,12,11,13,12,16,13,14,14,15,
  132801. 15,10,10,11,13,14,10,11,10,14,13,10,11,11,14,14,
  132802. 12,13,12,15,13,13,13,14,15,16, 5, 7, 7,10,10, 7,
  132803. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,13,13,10,10,
  132804. 11,12,13, 6, 8, 8,11,10, 8, 9, 9,11,11, 7, 8, 9,
  132805. 10,11,10,11,11,13,13,10,10,11,11,13, 6, 8, 8,10,
  132806. 11, 8, 9, 9,11,11, 8, 9, 8,12,10,10,11,11,13,13,
  132807. 10,11,10,14,11,10,10,10,14,13,10,11,11,14,13,10,
  132808. 10,11,13,13,12,14,14,16,16,12,12,13,13,15,10,11,
  132809. 11,13,14,10,11,11,14,15,10,11,10,13,13,13,14,13,
  132810. 16,16,12,13,11,15,12, 9,10,10,13,13,10,11,11,14,
  132811. 13,10,10,11,13,14,13,14,13,16,16,13,13,13,15,16,
  132812. 9,10,10,13,13,10,10,11,13,14,10,11,11,15,13,13,
  132813. 13,14,14,18,13,13,14,16,15, 9,10,10,13,14,10,11,
  132814. 10,14,13,10,11,11,13,14,13,14,13,16,15,13,13,14,
  132815. 15,16,12,13,12,16,14,11,11,13,15,15,13,14,13,16,
  132816. 15,15,12,16,12,17,14,15,15,17,17,12,13,13,14,16,
  132817. 11,13,11,16,15,12,13,14,15,16,14,15,13, 0,14,14,
  132818. 16,16, 0, 0, 9,10,10,13,13,10,11,10,14,14,10,11,
  132819. 11,13,13,12,13,13,14,16,13,14,14,16,16, 9,10,10,
  132820. 14,14,11,11,11,14,13,10,10,11,14,14,13,13,13,16,
  132821. 16,13,13,14,14,17, 9,10,10,13,14,10,11,11,13,15,
  132822. 10,11,10,14,14,13,13,13,14,17,13,14,13,17,14,12,
  132823. 13,13,16,14,13,14,13,16,15,12,12,13,15,16,15,15,
  132824. 16,18,16,15,13,15,14, 0,12,12,13,14,16,13,13,14,
  132825. 15,16,11,12,11,16,14,15,16,16,17,17,14,15,12,17,
  132826. 12,
  132827. };
  132828. static float _vq_quantthresh__44u1__p4_0[] = {
  132829. -1.5, -0.5, 0.5, 1.5,
  132830. };
  132831. static long _vq_quantmap__44u1__p4_0[] = {
  132832. 3, 1, 0, 2, 4,
  132833. };
  132834. static encode_aux_threshmatch _vq_auxt__44u1__p4_0 = {
  132835. _vq_quantthresh__44u1__p4_0,
  132836. _vq_quantmap__44u1__p4_0,
  132837. 5,
  132838. 5
  132839. };
  132840. static static_codebook _44u1__p4_0 = {
  132841. 4, 625,
  132842. _vq_lengthlist__44u1__p4_0,
  132843. 1, -533725184, 1611661312, 3, 0,
  132844. _vq_quantlist__44u1__p4_0,
  132845. NULL,
  132846. &_vq_auxt__44u1__p4_0,
  132847. NULL,
  132848. 0
  132849. };
  132850. static long _vq_quantlist__44u1__p5_0[] = {
  132851. 4,
  132852. 3,
  132853. 5,
  132854. 2,
  132855. 6,
  132856. 1,
  132857. 7,
  132858. 0,
  132859. 8,
  132860. };
  132861. static long _vq_lengthlist__44u1__p5_0[] = {
  132862. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  132863. 9, 9, 4, 6, 6, 8, 8, 8, 8, 9, 9, 7, 8, 8, 9, 9,
  132864. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,10, 7, 8, 8,
  132865. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  132866. 9, 9,10,10,11,11,12,12, 9, 9, 9,10,11,11,11,12,
  132867. 12,
  132868. };
  132869. static float _vq_quantthresh__44u1__p5_0[] = {
  132870. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  132871. };
  132872. static long _vq_quantmap__44u1__p5_0[] = {
  132873. 7, 5, 3, 1, 0, 2, 4, 6,
  132874. 8,
  132875. };
  132876. static encode_aux_threshmatch _vq_auxt__44u1__p5_0 = {
  132877. _vq_quantthresh__44u1__p5_0,
  132878. _vq_quantmap__44u1__p5_0,
  132879. 9,
  132880. 9
  132881. };
  132882. static static_codebook _44u1__p5_0 = {
  132883. 2, 81,
  132884. _vq_lengthlist__44u1__p5_0,
  132885. 1, -531628032, 1611661312, 4, 0,
  132886. _vq_quantlist__44u1__p5_0,
  132887. NULL,
  132888. &_vq_auxt__44u1__p5_0,
  132889. NULL,
  132890. 0
  132891. };
  132892. static long _vq_quantlist__44u1__p6_0[] = {
  132893. 6,
  132894. 5,
  132895. 7,
  132896. 4,
  132897. 8,
  132898. 3,
  132899. 9,
  132900. 2,
  132901. 10,
  132902. 1,
  132903. 11,
  132904. 0,
  132905. 12,
  132906. };
  132907. static long _vq_lengthlist__44u1__p6_0[] = {
  132908. 1, 4, 4, 6, 6, 8, 8,10, 9,11,10,14,13, 4, 6, 5,
  132909. 8, 8, 9, 9,11,10,11,11,14,14, 4, 5, 6, 8, 8, 9,
  132910. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  132911. 12,12,16,15, 7, 8, 8, 9, 9,10,10,11,11,12,12,15,
  132912. 15, 9,10,10,10,10,11,11,12,12,12,12,15,15, 9,10,
  132913. 9,10,11,11,11,12,12,12,13,15,15,10,10,11,11,11,
  132914. 12,12,13,12,13,13,16,15,10,11,11,11,11,12,12,13,
  132915. 12,13,13,16,17,11,11,12,12,12,13,13,13,14,14,15,
  132916. 17,17,11,11,12,12,12,13,13,13,14,14,14,16,18,14,
  132917. 15,15,15,15,16,16,16,16,17,18, 0, 0,14,15,15,15,
  132918. 15,17,16,17,18,17,17,18, 0,
  132919. };
  132920. static float _vq_quantthresh__44u1__p6_0[] = {
  132921. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  132922. 12.5, 17.5, 22.5, 27.5,
  132923. };
  132924. static long _vq_quantmap__44u1__p6_0[] = {
  132925. 11, 9, 7, 5, 3, 1, 0, 2,
  132926. 4, 6, 8, 10, 12,
  132927. };
  132928. static encode_aux_threshmatch _vq_auxt__44u1__p6_0 = {
  132929. _vq_quantthresh__44u1__p6_0,
  132930. _vq_quantmap__44u1__p6_0,
  132931. 13,
  132932. 13
  132933. };
  132934. static static_codebook _44u1__p6_0 = {
  132935. 2, 169,
  132936. _vq_lengthlist__44u1__p6_0,
  132937. 1, -526516224, 1616117760, 4, 0,
  132938. _vq_quantlist__44u1__p6_0,
  132939. NULL,
  132940. &_vq_auxt__44u1__p6_0,
  132941. NULL,
  132942. 0
  132943. };
  132944. static long _vq_quantlist__44u1__p6_1[] = {
  132945. 2,
  132946. 1,
  132947. 3,
  132948. 0,
  132949. 4,
  132950. };
  132951. static long _vq_lengthlist__44u1__p6_1[] = {
  132952. 2, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5,
  132953. 6, 6, 6, 6, 5, 6, 6, 6, 6,
  132954. };
  132955. static float _vq_quantthresh__44u1__p6_1[] = {
  132956. -1.5, -0.5, 0.5, 1.5,
  132957. };
  132958. static long _vq_quantmap__44u1__p6_1[] = {
  132959. 3, 1, 0, 2, 4,
  132960. };
  132961. static encode_aux_threshmatch _vq_auxt__44u1__p6_1 = {
  132962. _vq_quantthresh__44u1__p6_1,
  132963. _vq_quantmap__44u1__p6_1,
  132964. 5,
  132965. 5
  132966. };
  132967. static static_codebook _44u1__p6_1 = {
  132968. 2, 25,
  132969. _vq_lengthlist__44u1__p6_1,
  132970. 1, -533725184, 1611661312, 3, 0,
  132971. _vq_quantlist__44u1__p6_1,
  132972. NULL,
  132973. &_vq_auxt__44u1__p6_1,
  132974. NULL,
  132975. 0
  132976. };
  132977. static long _vq_quantlist__44u1__p7_0[] = {
  132978. 3,
  132979. 2,
  132980. 4,
  132981. 1,
  132982. 5,
  132983. 0,
  132984. 6,
  132985. };
  132986. static long _vq_lengthlist__44u1__p7_0[] = {
  132987. 1, 3, 2, 9, 9, 7, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132988. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132989. 9, 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  132990. 8,
  132991. };
  132992. static float _vq_quantthresh__44u1__p7_0[] = {
  132993. -422.5, -253.5, -84.5, 84.5, 253.5, 422.5,
  132994. };
  132995. static long _vq_quantmap__44u1__p7_0[] = {
  132996. 5, 3, 1, 0, 2, 4, 6,
  132997. };
  132998. static encode_aux_threshmatch _vq_auxt__44u1__p7_0 = {
  132999. _vq_quantthresh__44u1__p7_0,
  133000. _vq_quantmap__44u1__p7_0,
  133001. 7,
  133002. 7
  133003. };
  133004. static static_codebook _44u1__p7_0 = {
  133005. 2, 49,
  133006. _vq_lengthlist__44u1__p7_0,
  133007. 1, -518017024, 1626677248, 3, 0,
  133008. _vq_quantlist__44u1__p7_0,
  133009. NULL,
  133010. &_vq_auxt__44u1__p7_0,
  133011. NULL,
  133012. 0
  133013. };
  133014. static long _vq_quantlist__44u1__p7_1[] = {
  133015. 6,
  133016. 5,
  133017. 7,
  133018. 4,
  133019. 8,
  133020. 3,
  133021. 9,
  133022. 2,
  133023. 10,
  133024. 1,
  133025. 11,
  133026. 0,
  133027. 12,
  133028. };
  133029. static long _vq_lengthlist__44u1__p7_1[] = {
  133030. 1, 4, 4, 6, 6, 6, 6, 7, 7, 8, 8, 9, 9, 5, 7, 7,
  133031. 8, 7, 7, 7, 9, 8,10, 9,10,11, 5, 7, 7, 8, 8, 7,
  133032. 7, 8, 9,10,10,11,11, 6, 8, 8, 9, 9, 9, 9,11,10,
  133033. 12,12,15,12, 6, 8, 8, 9, 9, 9, 9,11,11,12,11,14,
  133034. 12, 7, 8, 8,10,10,12,12,13,13,13,15,13,13, 7, 8,
  133035. 8,10,10,11,11,13,12,14,15,15,15, 9,10,10,11,12,
  133036. 13,13,14,15,14,15,14,15, 8,10,10,12,12,14,14,15,
  133037. 14,14,15,15,14,10,12,12,14,14,15,14,15,15,15,14,
  133038. 15,15,10,12,12,13,14,15,14,15,15,14,15,15,15,12,
  133039. 15,13,15,14,15,15,15,15,15,15,15,15,13,13,15,15,
  133040. 15,15,15,15,15,15,15,15,15,
  133041. };
  133042. static float _vq_quantthresh__44u1__p7_1[] = {
  133043. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  133044. 32.5, 45.5, 58.5, 71.5,
  133045. };
  133046. static long _vq_quantmap__44u1__p7_1[] = {
  133047. 11, 9, 7, 5, 3, 1, 0, 2,
  133048. 4, 6, 8, 10, 12,
  133049. };
  133050. static encode_aux_threshmatch _vq_auxt__44u1__p7_1 = {
  133051. _vq_quantthresh__44u1__p7_1,
  133052. _vq_quantmap__44u1__p7_1,
  133053. 13,
  133054. 13
  133055. };
  133056. static static_codebook _44u1__p7_1 = {
  133057. 2, 169,
  133058. _vq_lengthlist__44u1__p7_1,
  133059. 1, -523010048, 1618608128, 4, 0,
  133060. _vq_quantlist__44u1__p7_1,
  133061. NULL,
  133062. &_vq_auxt__44u1__p7_1,
  133063. NULL,
  133064. 0
  133065. };
  133066. static long _vq_quantlist__44u1__p7_2[] = {
  133067. 6,
  133068. 5,
  133069. 7,
  133070. 4,
  133071. 8,
  133072. 3,
  133073. 9,
  133074. 2,
  133075. 10,
  133076. 1,
  133077. 11,
  133078. 0,
  133079. 12,
  133080. };
  133081. static long _vq_lengthlist__44u1__p7_2[] = {
  133082. 2, 5, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 5, 5, 6,
  133083. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 5, 6, 5, 7, 7, 8,
  133084. 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8, 8, 8, 8, 9, 8,
  133085. 9, 9, 9, 9, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  133086. 9, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 7, 8,
  133087. 8, 9, 8, 9, 8, 9, 9, 9, 9, 9, 9, 8, 9, 8, 9, 9,
  133088. 9, 9, 9, 9, 9, 9,10,10, 8, 8, 9, 9, 9, 9, 9, 9,
  133089. 9, 9,10, 9,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133090. 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133091. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,
  133092. 9, 9, 9,10, 9, 9,10,10, 9,
  133093. };
  133094. static float _vq_quantthresh__44u1__p7_2[] = {
  133095. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  133096. 2.5, 3.5, 4.5, 5.5,
  133097. };
  133098. static long _vq_quantmap__44u1__p7_2[] = {
  133099. 11, 9, 7, 5, 3, 1, 0, 2,
  133100. 4, 6, 8, 10, 12,
  133101. };
  133102. static encode_aux_threshmatch _vq_auxt__44u1__p7_2 = {
  133103. _vq_quantthresh__44u1__p7_2,
  133104. _vq_quantmap__44u1__p7_2,
  133105. 13,
  133106. 13
  133107. };
  133108. static static_codebook _44u1__p7_2 = {
  133109. 2, 169,
  133110. _vq_lengthlist__44u1__p7_2,
  133111. 1, -531103744, 1611661312, 4, 0,
  133112. _vq_quantlist__44u1__p7_2,
  133113. NULL,
  133114. &_vq_auxt__44u1__p7_2,
  133115. NULL,
  133116. 0
  133117. };
  133118. static long _huff_lengthlist__44u1__short[] = {
  133119. 12,13,14,13,17,12,15,17, 5, 5, 6,10,10,11,15,16,
  133120. 4, 3, 3, 7, 5, 7,10,16, 7, 7, 7,10, 9,11,12,16,
  133121. 6, 5, 5, 9, 5, 6,10,16, 8, 7, 7, 9, 6, 7, 9,16,
  133122. 11, 7, 3, 6, 4, 5, 8,16,12, 9, 4, 8, 5, 7, 9,16,
  133123. };
  133124. static static_codebook _huff_book__44u1__short = {
  133125. 2, 64,
  133126. _huff_lengthlist__44u1__short,
  133127. 0, 0, 0, 0, 0,
  133128. NULL,
  133129. NULL,
  133130. NULL,
  133131. NULL,
  133132. 0
  133133. };
  133134. static long _huff_lengthlist__44u2__long[] = {
  133135. 5, 9,14,12,15,13,10,13, 7, 4, 5, 6, 8, 7, 8,12,
  133136. 13, 4, 3, 5, 5, 6, 9,15,12, 6, 5, 6, 6, 6, 7,14,
  133137. 14, 7, 4, 6, 4, 6, 8,15,12, 6, 6, 5, 5, 5, 6,14,
  133138. 9, 7, 8, 6, 7, 5, 4,10,10,13,14,14,15,10, 6, 8,
  133139. };
  133140. static static_codebook _huff_book__44u2__long = {
  133141. 2, 64,
  133142. _huff_lengthlist__44u2__long,
  133143. 0, 0, 0, 0, 0,
  133144. NULL,
  133145. NULL,
  133146. NULL,
  133147. NULL,
  133148. 0
  133149. };
  133150. static long _vq_quantlist__44u2__p1_0[] = {
  133151. 1,
  133152. 0,
  133153. 2,
  133154. };
  133155. static long _vq_lengthlist__44u2__p1_0[] = {
  133156. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,11,11, 8,
  133157. 10,11, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  133158. 11, 8,11,11, 8,11,11,11,13,14,11,13,13, 7,11,11,
  133159. 10,13,12,11,14,14, 4, 8, 8, 8,11,11, 8,11,11, 8,
  133160. 11,11,11,14,13,10,12,13, 8,11,11,11,13,13,11,13,
  133161. 13,
  133162. };
  133163. static float _vq_quantthresh__44u2__p1_0[] = {
  133164. -0.5, 0.5,
  133165. };
  133166. static long _vq_quantmap__44u2__p1_0[] = {
  133167. 1, 0, 2,
  133168. };
  133169. static encode_aux_threshmatch _vq_auxt__44u2__p1_0 = {
  133170. _vq_quantthresh__44u2__p1_0,
  133171. _vq_quantmap__44u2__p1_0,
  133172. 3,
  133173. 3
  133174. };
  133175. static static_codebook _44u2__p1_0 = {
  133176. 4, 81,
  133177. _vq_lengthlist__44u2__p1_0,
  133178. 1, -535822336, 1611661312, 2, 0,
  133179. _vq_quantlist__44u2__p1_0,
  133180. NULL,
  133181. &_vq_auxt__44u2__p1_0,
  133182. NULL,
  133183. 0
  133184. };
  133185. static long _vq_quantlist__44u2__p2_0[] = {
  133186. 1,
  133187. 0,
  133188. 2,
  133189. };
  133190. static long _vq_lengthlist__44u2__p2_0[] = {
  133191. 2, 5, 5, 5, 6, 6, 5, 6, 6, 5, 6, 6, 7, 8, 8, 6,
  133192. 8, 8, 5, 6, 6, 6, 8, 7, 7, 8, 8, 5, 6, 6, 7, 8,
  133193. 8, 6, 8, 8, 6, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  133194. 7,10, 8, 8,10,10, 5, 6, 6, 6, 8, 8, 7, 8, 8, 6,
  133195. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  133196. 9,
  133197. };
  133198. static float _vq_quantthresh__44u2__p2_0[] = {
  133199. -0.5, 0.5,
  133200. };
  133201. static long _vq_quantmap__44u2__p2_0[] = {
  133202. 1, 0, 2,
  133203. };
  133204. static encode_aux_threshmatch _vq_auxt__44u2__p2_0 = {
  133205. _vq_quantthresh__44u2__p2_0,
  133206. _vq_quantmap__44u2__p2_0,
  133207. 3,
  133208. 3
  133209. };
  133210. static static_codebook _44u2__p2_0 = {
  133211. 4, 81,
  133212. _vq_lengthlist__44u2__p2_0,
  133213. 1, -535822336, 1611661312, 2, 0,
  133214. _vq_quantlist__44u2__p2_0,
  133215. NULL,
  133216. &_vq_auxt__44u2__p2_0,
  133217. NULL,
  133218. 0
  133219. };
  133220. static long _vq_quantlist__44u2__p3_0[] = {
  133221. 2,
  133222. 1,
  133223. 3,
  133224. 0,
  133225. 4,
  133226. };
  133227. static long _vq_lengthlist__44u2__p3_0[] = {
  133228. 2, 4, 4, 7, 8, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 8,
  133229. 9, 9,12,11, 8, 9, 9,11,12, 5, 7, 7,10,10, 7, 9,
  133230. 9,11,11, 7, 9, 9,10,11,10,11,11,13,13, 9,10,11,
  133231. 12,13, 5, 7, 7,10,10, 7, 9, 9,11,10, 7, 9, 9,11,
  133232. 11, 9,11,10,13,13,10,11,11,13,13, 8,10,10,14,13,
  133233. 10,11,11,15,14, 9,11,11,15,14,13,14,13,16,14,12,
  133234. 13,13,15,16, 8,10,10,13,14, 9,11,11,14,15,10,11,
  133235. 11,14,15,12,13,13,15,15,12,13,14,15,16, 5, 7, 7,
  133236. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,12,10,11,11,14,
  133237. 13,10,11,11,14,14, 7, 9, 9,12,12, 9,11,11,13,13,
  133238. 9,11,11,13,13,12,13,12,14,14,11,12,13,15,15, 7,
  133239. 9, 9,12,12, 8,11,10,13,12, 9,11,11,13,13,11,13,
  133240. 12,15,13,11,13,13,15,16, 9,12,11,15,15,11,12,12,
  133241. 16,15,11,12,13,16,16,13,14,15,16,15,13,15,15,17,
  133242. 17, 9,11,11,14,15,10,12,12,15,15,11,13,12,15,16,
  133243. 13,15,14,16,16,13,15,15,17,19, 5, 7, 7,10,10, 7,
  133244. 9, 9,12,11, 7, 9, 9,11,11,10,11,11,14,14,10,11,
  133245. 11,13,14, 7, 9, 9,12,12, 9,11,11,13,13, 9,10,11,
  133246. 12,13,11,13,12,16,15,11,12,12,14,15, 7, 9, 9,12,
  133247. 12, 9,11,11,13,13, 9,11,11,13,12,11,13,12,15,16,
  133248. 12,13,13,15,14, 9,11,11,15,14,11,13,12,16,15,10,
  133249. 11,12,15,15,13,14,14,18,17,13,14,14,15,17,10,11,
  133250. 11,14,15,11,13,12,15,17,11,13,12,15,16,13,15,14,
  133251. 18,17,14,15,15,16,18, 7,10,10,14,14,10,12,12,15,
  133252. 15,10,12,12,15,15,14,15,15,18,17,13,15,15,16,16,
  133253. 9,11,11,16,15,11,13,13,16,18,11,13,13,16,16,15,
  133254. 16,16, 0, 0,14,15,16,18,17, 9,11,11,15,15,10,13,
  133255. 12,17,16,11,12,13,16,17,14,15,16,19,19,14,15,15,
  133256. 0,20,12,14,14, 0, 0,13,14,16,19,18,13,15,16,20,
  133257. 17,16,18, 0, 0, 0,15,16,17,18,19,11,14,14, 0,19,
  133258. 12,15,14,17,17,13,15,15, 0, 0,16,17,15,20,19,15,
  133259. 17,16,19, 0, 8,10,10,14,15,10,12,11,15,15,10,11,
  133260. 12,16,15,13,14,14,19,17,14,15,15, 0, 0, 9,11,11,
  133261. 16,15,11,13,13,17,16,10,12,13,16,17,14,15,15,18,
  133262. 18,14,15,16,20,19, 9,12,12, 0,15,11,13,13,16,17,
  133263. 11,13,13,19,17,14,16,16,18,17,15,16,16,17,19,11,
  133264. 14,14,18,18,13,14,15, 0, 0,12,14,15,19,18,15,16,
  133265. 19, 0,19,15,16,19,19,17,12,14,14,16,19,13,15,15,
  133266. 0,17,13,15,14,18,18,15,16,15, 0,18,16,17,17, 0,
  133267. 0,
  133268. };
  133269. static float _vq_quantthresh__44u2__p3_0[] = {
  133270. -1.5, -0.5, 0.5, 1.5,
  133271. };
  133272. static long _vq_quantmap__44u2__p3_0[] = {
  133273. 3, 1, 0, 2, 4,
  133274. };
  133275. static encode_aux_threshmatch _vq_auxt__44u2__p3_0 = {
  133276. _vq_quantthresh__44u2__p3_0,
  133277. _vq_quantmap__44u2__p3_0,
  133278. 5,
  133279. 5
  133280. };
  133281. static static_codebook _44u2__p3_0 = {
  133282. 4, 625,
  133283. _vq_lengthlist__44u2__p3_0,
  133284. 1, -533725184, 1611661312, 3, 0,
  133285. _vq_quantlist__44u2__p3_0,
  133286. NULL,
  133287. &_vq_auxt__44u2__p3_0,
  133288. NULL,
  133289. 0
  133290. };
  133291. static long _vq_quantlist__44u2__p4_0[] = {
  133292. 2,
  133293. 1,
  133294. 3,
  133295. 0,
  133296. 4,
  133297. };
  133298. static long _vq_lengthlist__44u2__p4_0[] = {
  133299. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 9,
  133300. 9, 9,11,11, 9, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  133301. 8,10,10, 7, 7, 8,10,10,10,10,10,11,12, 9,10,10,
  133302. 11,12, 5, 7, 7, 9, 9, 6, 8, 7,10,10, 7, 8, 8,10,
  133303. 10, 9,10,10,12,11, 9,10,10,12,11, 9,10,10,12,12,
  133304. 10,10,10,13,12, 9,10,10,12,13,12,12,12,14,14,11,
  133305. 12,12,13,14, 9,10,10,12,12, 9,10,10,12,13,10,10,
  133306. 10,12,13,11,12,12,14,13,12,12,12,14,13, 5, 7, 7,
  133307. 10, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,
  133308. 12,10,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,11,11,
  133309. 8, 9, 9,11,11,10,11,11,12,13,10,11,11,13,13, 6,
  133310. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  133311. 10,13,11,10,11,11,13,13, 9,10,10,13,13,10,11,11,
  133312. 13,13,10,11,11,14,13,12,11,13,12,15,12,13,13,15,
  133313. 15, 9,10,10,12,13,10,11,10,13,13,10,11,11,13,13,
  133314. 12,13,11,15,13,12,13,13,15,15, 5, 7, 7, 9,10, 7,
  133315. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,12,10,10,
  133316. 11,12,12, 6, 8, 8,10,10, 8, 9, 9,11,11, 7, 8, 9,
  133317. 10,11,10,11,11,13,13,10,10,11,11,13, 7, 8, 8,10,
  133318. 11, 8, 9, 9,11,11, 8, 9, 8,11,11,10,11,11,13,13,
  133319. 10,11,11,13,12, 9,10,10,13,12,10,11,11,14,13,10,
  133320. 10,11,13,13,12,13,13,15,15,12,11,13,12,14, 9,10,
  133321. 10,12,13,10,11,11,13,14,10,11,11,13,13,12,13,13,
  133322. 15,15,12,13,12,15,12, 8, 9, 9,12,12, 9,11,10,13,
  133323. 13, 9,10,10,13,13,12,13,13,15,15,12,12,12,14,14,
  133324. 9,10,10,13,13,10,11,11,13,14,10,11,11,14,12,13,
  133325. 13,14,14,16,12,13,13,15,14, 9,10,10,13,13,10,11,
  133326. 10,14,13,10,11,11,13,14,12,14,13,16,14,13,13,13,
  133327. 14,15,11,13,12,15,14,11,12,13,14,15,12,13,13,16,
  133328. 15,14,12,15,12,16,14,15,15,17,16,11,12,12,14,15,
  133329. 11,13,11,15,14,12,13,13,15,16,13,15,12,17,13,14,
  133330. 15,15,16,16, 8, 9, 9,12,12, 9,10,10,13,13, 9,10,
  133331. 10,13,13,12,13,12,14,14,12,13,13,15,15, 9,10,10,
  133332. 13,13,10,11,11,14,13,10,10,11,13,14,12,13,13,15,
  133333. 14,12,12,14,14,16, 9,10,10,13,13,10,11,11,13,14,
  133334. 10,11,11,14,13,13,13,13,15,15,13,14,13,16,14,11,
  133335. 12,12,14,14,12,13,13,16,15,11,12,13,14,15,14,15,
  133336. 15,16,16,14,13,15,13,17,11,12,12,14,15,12,13,13,
  133337. 15,16,11,13,12,15,15,14,15,14,16,16,14,15,12,17,
  133338. 13,
  133339. };
  133340. static float _vq_quantthresh__44u2__p4_0[] = {
  133341. -1.5, -0.5, 0.5, 1.5,
  133342. };
  133343. static long _vq_quantmap__44u2__p4_0[] = {
  133344. 3, 1, 0, 2, 4,
  133345. };
  133346. static encode_aux_threshmatch _vq_auxt__44u2__p4_0 = {
  133347. _vq_quantthresh__44u2__p4_0,
  133348. _vq_quantmap__44u2__p4_0,
  133349. 5,
  133350. 5
  133351. };
  133352. static static_codebook _44u2__p4_0 = {
  133353. 4, 625,
  133354. _vq_lengthlist__44u2__p4_0,
  133355. 1, -533725184, 1611661312, 3, 0,
  133356. _vq_quantlist__44u2__p4_0,
  133357. NULL,
  133358. &_vq_auxt__44u2__p4_0,
  133359. NULL,
  133360. 0
  133361. };
  133362. static long _vq_quantlist__44u2__p5_0[] = {
  133363. 4,
  133364. 3,
  133365. 5,
  133366. 2,
  133367. 6,
  133368. 1,
  133369. 7,
  133370. 0,
  133371. 8,
  133372. };
  133373. static long _vq_lengthlist__44u2__p5_0[] = {
  133374. 1, 4, 4, 7, 7, 8, 8, 9, 9, 4, 6, 5, 8, 8, 8, 8,
  133375. 10,10, 4, 5, 6, 8, 8, 8, 8,10,10, 7, 8, 8, 9, 9,
  133376. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 8, 8, 8,
  133377. 9, 9,10,11,12,12, 8, 8, 8, 9, 9,10,10,12,12,10,
  133378. 10,10,11,11,12,12,13,13,10,10,10,11,11,12,12,13,
  133379. 13,
  133380. };
  133381. static float _vq_quantthresh__44u2__p5_0[] = {
  133382. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  133383. };
  133384. static long _vq_quantmap__44u2__p5_0[] = {
  133385. 7, 5, 3, 1, 0, 2, 4, 6,
  133386. 8,
  133387. };
  133388. static encode_aux_threshmatch _vq_auxt__44u2__p5_0 = {
  133389. _vq_quantthresh__44u2__p5_0,
  133390. _vq_quantmap__44u2__p5_0,
  133391. 9,
  133392. 9
  133393. };
  133394. static static_codebook _44u2__p5_0 = {
  133395. 2, 81,
  133396. _vq_lengthlist__44u2__p5_0,
  133397. 1, -531628032, 1611661312, 4, 0,
  133398. _vq_quantlist__44u2__p5_0,
  133399. NULL,
  133400. &_vq_auxt__44u2__p5_0,
  133401. NULL,
  133402. 0
  133403. };
  133404. static long _vq_quantlist__44u2__p6_0[] = {
  133405. 6,
  133406. 5,
  133407. 7,
  133408. 4,
  133409. 8,
  133410. 3,
  133411. 9,
  133412. 2,
  133413. 10,
  133414. 1,
  133415. 11,
  133416. 0,
  133417. 12,
  133418. };
  133419. static long _vq_lengthlist__44u2__p6_0[] = {
  133420. 1, 4, 4, 6, 6, 8, 8,10,10,11,11,14,13, 4, 6, 5,
  133421. 8, 8, 9, 9,11,10,12,11,15,14, 4, 5, 6, 8, 8, 9,
  133422. 9,11,11,11,11,14,14, 6, 8, 8,10, 9,11,11,11,11,
  133423. 12,12,15,15, 6, 8, 8, 9, 9,11,11,11,12,12,12,15,
  133424. 15, 8,10,10,11,11,11,11,12,12,13,13,15,16, 8,10,
  133425. 10,11,11,11,11,12,12,13,13,16,16,10,11,11,12,12,
  133426. 12,12,13,13,13,13,17,16,10,11,11,12,12,12,12,13,
  133427. 13,13,14,16,17,11,12,12,13,13,13,13,14,14,15,14,
  133428. 18,17,11,12,12,13,13,13,13,14,14,14,15,19,18,14,
  133429. 15,15,15,15,16,16,18,19,18,18, 0, 0,14,15,15,16,
  133430. 15,17,17,16,18,17,18, 0, 0,
  133431. };
  133432. static float _vq_quantthresh__44u2__p6_0[] = {
  133433. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  133434. 12.5, 17.5, 22.5, 27.5,
  133435. };
  133436. static long _vq_quantmap__44u2__p6_0[] = {
  133437. 11, 9, 7, 5, 3, 1, 0, 2,
  133438. 4, 6, 8, 10, 12,
  133439. };
  133440. static encode_aux_threshmatch _vq_auxt__44u2__p6_0 = {
  133441. _vq_quantthresh__44u2__p6_0,
  133442. _vq_quantmap__44u2__p6_0,
  133443. 13,
  133444. 13
  133445. };
  133446. static static_codebook _44u2__p6_0 = {
  133447. 2, 169,
  133448. _vq_lengthlist__44u2__p6_0,
  133449. 1, -526516224, 1616117760, 4, 0,
  133450. _vq_quantlist__44u2__p6_0,
  133451. NULL,
  133452. &_vq_auxt__44u2__p6_0,
  133453. NULL,
  133454. 0
  133455. };
  133456. static long _vq_quantlist__44u2__p6_1[] = {
  133457. 2,
  133458. 1,
  133459. 3,
  133460. 0,
  133461. 4,
  133462. };
  133463. static long _vq_lengthlist__44u2__p6_1[] = {
  133464. 2, 4, 4, 5, 5, 4, 5, 5, 6, 5, 4, 5, 5, 5, 6, 5,
  133465. 6, 5, 6, 6, 5, 5, 6, 6, 6,
  133466. };
  133467. static float _vq_quantthresh__44u2__p6_1[] = {
  133468. -1.5, -0.5, 0.5, 1.5,
  133469. };
  133470. static long _vq_quantmap__44u2__p6_1[] = {
  133471. 3, 1, 0, 2, 4,
  133472. };
  133473. static encode_aux_threshmatch _vq_auxt__44u2__p6_1 = {
  133474. _vq_quantthresh__44u2__p6_1,
  133475. _vq_quantmap__44u2__p6_1,
  133476. 5,
  133477. 5
  133478. };
  133479. static static_codebook _44u2__p6_1 = {
  133480. 2, 25,
  133481. _vq_lengthlist__44u2__p6_1,
  133482. 1, -533725184, 1611661312, 3, 0,
  133483. _vq_quantlist__44u2__p6_1,
  133484. NULL,
  133485. &_vq_auxt__44u2__p6_1,
  133486. NULL,
  133487. 0
  133488. };
  133489. static long _vq_quantlist__44u2__p7_0[] = {
  133490. 4,
  133491. 3,
  133492. 5,
  133493. 2,
  133494. 6,
  133495. 1,
  133496. 7,
  133497. 0,
  133498. 8,
  133499. };
  133500. static long _vq_lengthlist__44u2__p7_0[] = {
  133501. 1, 3, 2,12,12,12,12,12,12, 4,12,12,12,12,12,12,
  133502. 12,12, 5,12,12,12,12,12,12,12,12,12,12,11,11,11,
  133503. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133504. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133505. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133506. 11,
  133507. };
  133508. static float _vq_quantthresh__44u2__p7_0[] = {
  133509. -591.5, -422.5, -253.5, -84.5, 84.5, 253.5, 422.5, 591.5,
  133510. };
  133511. static long _vq_quantmap__44u2__p7_0[] = {
  133512. 7, 5, 3, 1, 0, 2, 4, 6,
  133513. 8,
  133514. };
  133515. static encode_aux_threshmatch _vq_auxt__44u2__p7_0 = {
  133516. _vq_quantthresh__44u2__p7_0,
  133517. _vq_quantmap__44u2__p7_0,
  133518. 9,
  133519. 9
  133520. };
  133521. static static_codebook _44u2__p7_0 = {
  133522. 2, 81,
  133523. _vq_lengthlist__44u2__p7_0,
  133524. 1, -516612096, 1626677248, 4, 0,
  133525. _vq_quantlist__44u2__p7_0,
  133526. NULL,
  133527. &_vq_auxt__44u2__p7_0,
  133528. NULL,
  133529. 0
  133530. };
  133531. static long _vq_quantlist__44u2__p7_1[] = {
  133532. 6,
  133533. 5,
  133534. 7,
  133535. 4,
  133536. 8,
  133537. 3,
  133538. 9,
  133539. 2,
  133540. 10,
  133541. 1,
  133542. 11,
  133543. 0,
  133544. 12,
  133545. };
  133546. static long _vq_lengthlist__44u2__p7_1[] = {
  133547. 1, 4, 4, 7, 6, 7, 6, 8, 7, 9, 7, 9, 8, 4, 7, 6,
  133548. 8, 8, 9, 8,10, 9,10,10,11,11, 4, 7, 7, 8, 8, 8,
  133549. 8, 9,10,11,11,11,11, 6, 8, 8,10,10,10,10,11,11,
  133550. 12,12,12,12, 7, 8, 8,10,10,10,10,11,11,12,12,13,
  133551. 13, 7, 9, 9,11,10,12,12,13,13,14,13,14,14, 7, 9,
  133552. 9,10,11,11,12,13,13,13,13,16,14, 9,10,10,12,12,
  133553. 13,13,14,14,15,16,15,16, 9,10,10,12,12,12,13,14,
  133554. 14,14,15,16,15,10,12,12,13,13,15,13,16,16,15,17,
  133555. 17,17,10,11,11,12,14,14,14,15,15,17,17,15,17,11,
  133556. 12,12,14,14,14,15,15,15,17,16,17,17,10,12,12,13,
  133557. 14,14,14,17,15,17,17,17,17,
  133558. };
  133559. static float _vq_quantthresh__44u2__p7_1[] = {
  133560. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  133561. 32.5, 45.5, 58.5, 71.5,
  133562. };
  133563. static long _vq_quantmap__44u2__p7_1[] = {
  133564. 11, 9, 7, 5, 3, 1, 0, 2,
  133565. 4, 6, 8, 10, 12,
  133566. };
  133567. static encode_aux_threshmatch _vq_auxt__44u2__p7_1 = {
  133568. _vq_quantthresh__44u2__p7_1,
  133569. _vq_quantmap__44u2__p7_1,
  133570. 13,
  133571. 13
  133572. };
  133573. static static_codebook _44u2__p7_1 = {
  133574. 2, 169,
  133575. _vq_lengthlist__44u2__p7_1,
  133576. 1, -523010048, 1618608128, 4, 0,
  133577. _vq_quantlist__44u2__p7_1,
  133578. NULL,
  133579. &_vq_auxt__44u2__p7_1,
  133580. NULL,
  133581. 0
  133582. };
  133583. static long _vq_quantlist__44u2__p7_2[] = {
  133584. 6,
  133585. 5,
  133586. 7,
  133587. 4,
  133588. 8,
  133589. 3,
  133590. 9,
  133591. 2,
  133592. 10,
  133593. 1,
  133594. 11,
  133595. 0,
  133596. 12,
  133597. };
  133598. static long _vq_lengthlist__44u2__p7_2[] = {
  133599. 2, 5, 5, 6, 6, 7, 7, 8, 7, 8, 8, 8, 8, 5, 6, 6,
  133600. 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 5, 6, 6, 7, 7, 8,
  133601. 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7, 8, 8, 8, 8, 8,
  133602. 9, 9, 9, 9, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  133603. 9, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 7, 8,
  133604. 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 9,
  133605. 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9,
  133606. 9, 9, 9, 9, 9, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133607. 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8,
  133608. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9, 9,
  133609. 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133610. };
  133611. static float _vq_quantthresh__44u2__p7_2[] = {
  133612. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  133613. 2.5, 3.5, 4.5, 5.5,
  133614. };
  133615. static long _vq_quantmap__44u2__p7_2[] = {
  133616. 11, 9, 7, 5, 3, 1, 0, 2,
  133617. 4, 6, 8, 10, 12,
  133618. };
  133619. static encode_aux_threshmatch _vq_auxt__44u2__p7_2 = {
  133620. _vq_quantthresh__44u2__p7_2,
  133621. _vq_quantmap__44u2__p7_2,
  133622. 13,
  133623. 13
  133624. };
  133625. static static_codebook _44u2__p7_2 = {
  133626. 2, 169,
  133627. _vq_lengthlist__44u2__p7_2,
  133628. 1, -531103744, 1611661312, 4, 0,
  133629. _vq_quantlist__44u2__p7_2,
  133630. NULL,
  133631. &_vq_auxt__44u2__p7_2,
  133632. NULL,
  133633. 0
  133634. };
  133635. static long _huff_lengthlist__44u2__short[] = {
  133636. 13,15,17,17,15,15,12,17,11, 9, 7,10,10, 9,12,17,
  133637. 10, 6, 3, 6, 5, 7,10,17,15,10, 6, 9, 8, 9,11,17,
  133638. 15, 8, 4, 7, 3, 5, 9,16,16,10, 5, 8, 4, 5, 8,16,
  133639. 13,11, 5, 8, 3, 3, 5,14,13,12, 7,10, 5, 5, 7,14,
  133640. };
  133641. static static_codebook _huff_book__44u2__short = {
  133642. 2, 64,
  133643. _huff_lengthlist__44u2__short,
  133644. 0, 0, 0, 0, 0,
  133645. NULL,
  133646. NULL,
  133647. NULL,
  133648. NULL,
  133649. 0
  133650. };
  133651. static long _huff_lengthlist__44u3__long[] = {
  133652. 6, 9,13,12,14,11,10,13, 8, 4, 5, 7, 8, 7, 8,12,
  133653. 11, 4, 3, 5, 5, 7, 9,14,11, 6, 5, 6, 6, 6, 7,13,
  133654. 13, 7, 5, 6, 4, 5, 7,14,11, 7, 6, 6, 5, 5, 6,13,
  133655. 9, 7, 8, 6, 7, 5, 3, 9, 9,12,13,12,14,10, 6, 7,
  133656. };
  133657. static static_codebook _huff_book__44u3__long = {
  133658. 2, 64,
  133659. _huff_lengthlist__44u3__long,
  133660. 0, 0, 0, 0, 0,
  133661. NULL,
  133662. NULL,
  133663. NULL,
  133664. NULL,
  133665. 0
  133666. };
  133667. static long _vq_quantlist__44u3__p1_0[] = {
  133668. 1,
  133669. 0,
  133670. 2,
  133671. };
  133672. static long _vq_lengthlist__44u3__p1_0[] = {
  133673. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,10,11, 8,
  133674. 10,11, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  133675. 11, 8,11,11, 8,11,11,11,13,14,11,14,14, 8,11,11,
  133676. 10,14,12,11,14,14, 4, 8, 8, 8,11,11, 8,11,11, 7,
  133677. 11,11,11,14,14,10,12,14, 8,11,11,11,14,14,11,14,
  133678. 13,
  133679. };
  133680. static float _vq_quantthresh__44u3__p1_0[] = {
  133681. -0.5, 0.5,
  133682. };
  133683. static long _vq_quantmap__44u3__p1_0[] = {
  133684. 1, 0, 2,
  133685. };
  133686. static encode_aux_threshmatch _vq_auxt__44u3__p1_0 = {
  133687. _vq_quantthresh__44u3__p1_0,
  133688. _vq_quantmap__44u3__p1_0,
  133689. 3,
  133690. 3
  133691. };
  133692. static static_codebook _44u3__p1_0 = {
  133693. 4, 81,
  133694. _vq_lengthlist__44u3__p1_0,
  133695. 1, -535822336, 1611661312, 2, 0,
  133696. _vq_quantlist__44u3__p1_0,
  133697. NULL,
  133698. &_vq_auxt__44u3__p1_0,
  133699. NULL,
  133700. 0
  133701. };
  133702. static long _vq_quantlist__44u3__p2_0[] = {
  133703. 1,
  133704. 0,
  133705. 2,
  133706. };
  133707. static long _vq_lengthlist__44u3__p2_0[] = {
  133708. 2, 5, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 7, 8, 8, 6,
  133709. 8, 8, 5, 6, 6, 6, 8, 8, 7, 8, 8, 5, 7, 6, 7, 8,
  133710. 8, 6, 8, 8, 7, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  133711. 8,10, 8, 8,10,10, 5, 6, 6, 6, 8, 8, 7, 8, 8, 6,
  133712. 8, 8, 8,10,10, 8, 8,10, 7, 8, 8, 8,10,10, 8,10,
  133713. 9,
  133714. };
  133715. static float _vq_quantthresh__44u3__p2_0[] = {
  133716. -0.5, 0.5,
  133717. };
  133718. static long _vq_quantmap__44u3__p2_0[] = {
  133719. 1, 0, 2,
  133720. };
  133721. static encode_aux_threshmatch _vq_auxt__44u3__p2_0 = {
  133722. _vq_quantthresh__44u3__p2_0,
  133723. _vq_quantmap__44u3__p2_0,
  133724. 3,
  133725. 3
  133726. };
  133727. static static_codebook _44u3__p2_0 = {
  133728. 4, 81,
  133729. _vq_lengthlist__44u3__p2_0,
  133730. 1, -535822336, 1611661312, 2, 0,
  133731. _vq_quantlist__44u3__p2_0,
  133732. NULL,
  133733. &_vq_auxt__44u3__p2_0,
  133734. NULL,
  133735. 0
  133736. };
  133737. static long _vq_quantlist__44u3__p3_0[] = {
  133738. 2,
  133739. 1,
  133740. 3,
  133741. 0,
  133742. 4,
  133743. };
  133744. static long _vq_lengthlist__44u3__p3_0[] = {
  133745. 2, 4, 4, 7, 7, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 8,
  133746. 9, 9,12,12, 8, 9, 9,11,12, 5, 7, 7,10,10, 7, 9,
  133747. 9,11,11, 7, 9, 9,10,11,10,11,11,13,13, 9,10,11,
  133748. 13,13, 5, 7, 7,10,10, 7, 9, 9,11,10, 7, 9, 9,11,
  133749. 11, 9,11,10,13,13,10,11,11,14,13, 8,10,10,14,13,
  133750. 10,11,11,15,14, 9,11,11,14,14,13,14,13,16,16,12,
  133751. 13,13,15,15, 8,10,10,13,14, 9,11,11,14,14,10,11,
  133752. 11,14,15,12,13,13,15,15,13,14,14,15,16, 5, 7, 7,
  133753. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,12,10,11,11,14,
  133754. 14,10,11,11,14,14, 7, 9, 9,12,12, 9,11,11,13,13,
  133755. 9,11,11,13,13,12,12,13,15,15,11,12,13,15,16, 7,
  133756. 9, 9,11,11, 8,11,10,13,12, 9,11,11,13,13,11,13,
  133757. 12,15,13,11,13,13,15,16, 9,12,11,15,14,11,12,13,
  133758. 16,15,11,13,13,15,16,14,14,15,17,16,13,15,16, 0,
  133759. 17, 9,11,11,15,15,10,13,12,15,15,11,13,13,15,16,
  133760. 13,15,13,16,15,14,16,15, 0,19, 5, 7, 7,10,10, 7,
  133761. 9, 9,11,11, 7, 9, 9,11,11,10,12,11,14,14,10,11,
  133762. 12,14,14, 7, 9, 9,12,12, 9,11,11,14,13, 9,10,11,
  133763. 12,13,11,13,13,16,16,11,12,13,13,16, 7, 9, 9,12,
  133764. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,13,15,15,
  133765. 12,13,12,15,14, 9,11,11,15,14,11,13,12,16,16,10,
  133766. 12,12,15,15,13,15,15,17,19,13,14,15,16,17,10,12,
  133767. 12,15,15,11,13,13,16,16,11,13,13,15,16,13,15,15,
  133768. 0, 0,14,15,15,16,16, 8,10,10,14,14,10,12,12,15,
  133769. 15,10,12,11,15,16,14,15,15,19,20,13,14,14,18,16,
  133770. 9,11,11,15,15,11,13,13,17,16,11,13,13,16,16,15,
  133771. 17,17,20,20,14,15,16,17,20, 9,11,11,15,15,10,13,
  133772. 12,16,15,11,13,13,15,17,14,16,15,18, 0,14,16,15,
  133773. 18,20,12,14,14, 0, 0,14,14,16, 0, 0,13,16,15, 0,
  133774. 0,17,17,18, 0, 0,16,17,19,19, 0,12,14,14,18, 0,
  133775. 12,16,14, 0,17,13,15,15,18, 0,16,18,17, 0,17,16,
  133776. 18,17, 0, 0, 7,10,10,14,14,10,12,11,15,15,10,12,
  133777. 12,16,15,13,15,15,18, 0,14,15,15,17, 0, 9,11,11,
  133778. 15,15,11,13,13,16,16,11,12,13,16,16,14,15,16,17,
  133779. 17,14,16,16,16,18, 9,11,12,16,16,11,13,13,17,17,
  133780. 11,14,13,20,17,15,16,16,19, 0,15,16,17, 0,19,11,
  133781. 13,14,17,16,14,15,15,20,18,13,14,15,17,19,16,18,
  133782. 18, 0,20,16,16,19,17, 0,12,15,14,17, 0,14,15,15,
  133783. 18,19,13,16,15,19,20,15,18,18, 0,20,17, 0,16, 0,
  133784. 0,
  133785. };
  133786. static float _vq_quantthresh__44u3__p3_0[] = {
  133787. -1.5, -0.5, 0.5, 1.5,
  133788. };
  133789. static long _vq_quantmap__44u3__p3_0[] = {
  133790. 3, 1, 0, 2, 4,
  133791. };
  133792. static encode_aux_threshmatch _vq_auxt__44u3__p3_0 = {
  133793. _vq_quantthresh__44u3__p3_0,
  133794. _vq_quantmap__44u3__p3_0,
  133795. 5,
  133796. 5
  133797. };
  133798. static static_codebook _44u3__p3_0 = {
  133799. 4, 625,
  133800. _vq_lengthlist__44u3__p3_0,
  133801. 1, -533725184, 1611661312, 3, 0,
  133802. _vq_quantlist__44u3__p3_0,
  133803. NULL,
  133804. &_vq_auxt__44u3__p3_0,
  133805. NULL,
  133806. 0
  133807. };
  133808. static long _vq_quantlist__44u3__p4_0[] = {
  133809. 2,
  133810. 1,
  133811. 3,
  133812. 0,
  133813. 4,
  133814. };
  133815. static long _vq_lengthlist__44u3__p4_0[] = {
  133816. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 9,
  133817. 9, 9,11,11, 9, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  133818. 8,10,10, 7, 7, 8,10,10, 9,10,10,11,12, 9,10,10,
  133819. 11,12, 5, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 8,10,
  133820. 10, 9,10, 9,12,11, 9,10,10,12,11, 9,10, 9,12,12,
  133821. 9,10,10,13,12, 9,10,10,12,13,12,12,12,14,14,11,
  133822. 12,12,13,14, 9, 9,10,12,12, 9,10,10,12,12, 9,10,
  133823. 10,12,13,11,12,11,14,13,12,12,12,14,13, 5, 7, 7,
  133824. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,
  133825. 12, 9,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,11,11,
  133826. 8, 9, 9,11,11,11,11,11,12,13,10,11,11,13,13, 6,
  133827. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  133828. 10,13,11,10,11,11,13,13, 9,11,10,13,12,10,11,11,
  133829. 13,13,10,11,11,13,13,12,12,13,12,15,12,13,13,15,
  133830. 15, 9,10,10,12,13,10,11,10,13,12,10,11,11,13,14,
  133831. 12,13,11,15,13,12,13,13,15,15, 5, 7, 7, 9, 9, 7,
  133832. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12,10,10,
  133833. 11,12,12, 6, 8, 8,10,10, 8, 9, 9,11,11, 7, 8, 9,
  133834. 10,11,10,11,11,13,13,10,10,11,11,13, 7, 8, 8,10,
  133835. 10, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,11,13,13,
  133836. 11,11,11,13,12, 9,10,10,13,12,10,11,11,14,13,10,
  133837. 10,11,12,13,12,13,13,15,15,12,11,13,13,14, 9,10,
  133838. 11,12,13,10,11,11,13,13,10,11,11,13,13,12,13,13,
  133839. 15,15,12,13,12,15,12, 8, 9, 9,12,12, 9,11,10,13,
  133840. 13, 9,10,10,13,13,12,13,13,15,14,12,12,12,14,13,
  133841. 9,10,10,13,12,10,11,11,13,13,10,11,11,14,12,13,
  133842. 13,14,14,16,12,13,13,15,15, 9,10,10,13,13,10,11,
  133843. 10,14,13,10,11,11,13,14,12,14,13,15,14,13,13,13,
  133844. 15,15,11,13,12,15,14,11,12,13,14,15,12,13,13,16,
  133845. 14,14,12,15,12,16,14,15,15,17,15,11,12,12,14,14,
  133846. 11,13,11,15,14,12,13,13,15,15,13,15,12,17,13,14,
  133847. 15,15,16,16, 8, 9, 9,12,12, 9,10,10,12,13, 9,10,
  133848. 10,13,13,12,12,12,14,14,12,13,13,15,15, 9,10,10,
  133849. 13,12,10,11,11,14,13,10,10,11,13,14,12,13,13,15,
  133850. 15,12,12,13,14,16, 9,10,10,13,13,10,11,11,13,14,
  133851. 10,11,11,14,13,12,13,13,14,15,13,14,13,16,14,11,
  133852. 12,12,14,14,12,13,13,15,14,11,12,13,14,15,14,15,
  133853. 15,16,16,13,13,15,13,16,11,12,12,14,15,12,13,13,
  133854. 14,15,11,13,12,15,14,14,15,15,16,16,14,15,12,16,
  133855. 13,
  133856. };
  133857. static float _vq_quantthresh__44u3__p4_0[] = {
  133858. -1.5, -0.5, 0.5, 1.5,
  133859. };
  133860. static long _vq_quantmap__44u3__p4_0[] = {
  133861. 3, 1, 0, 2, 4,
  133862. };
  133863. static encode_aux_threshmatch _vq_auxt__44u3__p4_0 = {
  133864. _vq_quantthresh__44u3__p4_0,
  133865. _vq_quantmap__44u3__p4_0,
  133866. 5,
  133867. 5
  133868. };
  133869. static static_codebook _44u3__p4_0 = {
  133870. 4, 625,
  133871. _vq_lengthlist__44u3__p4_0,
  133872. 1, -533725184, 1611661312, 3, 0,
  133873. _vq_quantlist__44u3__p4_0,
  133874. NULL,
  133875. &_vq_auxt__44u3__p4_0,
  133876. NULL,
  133877. 0
  133878. };
  133879. static long _vq_quantlist__44u3__p5_0[] = {
  133880. 4,
  133881. 3,
  133882. 5,
  133883. 2,
  133884. 6,
  133885. 1,
  133886. 7,
  133887. 0,
  133888. 8,
  133889. };
  133890. static long _vq_lengthlist__44u3__p5_0[] = {
  133891. 2, 3, 3, 6, 6, 7, 7, 9, 9, 4, 5, 5, 7, 7, 8, 8,
  133892. 10,10, 4, 5, 5, 7, 7, 8, 8,10,10, 6, 7, 7, 8, 8,
  133893. 9, 9,11,10, 6, 7, 7, 8, 8, 9, 9,10,10, 7, 8, 8,
  133894. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  133895. 10,10,11,10,11,11,12,12, 9,10,10,10,10,11,11,12,
  133896. 12,
  133897. };
  133898. static float _vq_quantthresh__44u3__p5_0[] = {
  133899. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  133900. };
  133901. static long _vq_quantmap__44u3__p5_0[] = {
  133902. 7, 5, 3, 1, 0, 2, 4, 6,
  133903. 8,
  133904. };
  133905. static encode_aux_threshmatch _vq_auxt__44u3__p5_0 = {
  133906. _vq_quantthresh__44u3__p5_0,
  133907. _vq_quantmap__44u3__p5_0,
  133908. 9,
  133909. 9
  133910. };
  133911. static static_codebook _44u3__p5_0 = {
  133912. 2, 81,
  133913. _vq_lengthlist__44u3__p5_0,
  133914. 1, -531628032, 1611661312, 4, 0,
  133915. _vq_quantlist__44u3__p5_0,
  133916. NULL,
  133917. &_vq_auxt__44u3__p5_0,
  133918. NULL,
  133919. 0
  133920. };
  133921. static long _vq_quantlist__44u3__p6_0[] = {
  133922. 6,
  133923. 5,
  133924. 7,
  133925. 4,
  133926. 8,
  133927. 3,
  133928. 9,
  133929. 2,
  133930. 10,
  133931. 1,
  133932. 11,
  133933. 0,
  133934. 12,
  133935. };
  133936. static long _vq_lengthlist__44u3__p6_0[] = {
  133937. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,11,13,14, 4, 6, 5,
  133938. 8, 8, 9, 9,10,10,11,11,14,14, 4, 6, 6, 8, 8, 9,
  133939. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  133940. 12,12,15,15, 6, 8, 8, 9, 9,10,11,11,11,12,12,15,
  133941. 15, 8, 9, 9,11,10,11,11,12,12,13,13,15,16, 8, 9,
  133942. 9,10,11,11,11,12,12,13,13,16,16,10,10,11,11,11,
  133943. 12,12,13,13,13,14,17,16, 9,10,11,12,11,12,12,13,
  133944. 13,13,13,16,18,11,12,11,12,12,13,13,13,14,15,14,
  133945. 17,17,11,11,12,12,12,13,13,13,14,14,15,18,17,14,
  133946. 15,15,15,15,16,16,17,17,19,18, 0,20,14,15,14,15,
  133947. 15,16,16,16,17,18,16,20,18,
  133948. };
  133949. static float _vq_quantthresh__44u3__p6_0[] = {
  133950. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  133951. 12.5, 17.5, 22.5, 27.5,
  133952. };
  133953. static long _vq_quantmap__44u3__p6_0[] = {
  133954. 11, 9, 7, 5, 3, 1, 0, 2,
  133955. 4, 6, 8, 10, 12,
  133956. };
  133957. static encode_aux_threshmatch _vq_auxt__44u3__p6_0 = {
  133958. _vq_quantthresh__44u3__p6_0,
  133959. _vq_quantmap__44u3__p6_0,
  133960. 13,
  133961. 13
  133962. };
  133963. static static_codebook _44u3__p6_0 = {
  133964. 2, 169,
  133965. _vq_lengthlist__44u3__p6_0,
  133966. 1, -526516224, 1616117760, 4, 0,
  133967. _vq_quantlist__44u3__p6_0,
  133968. NULL,
  133969. &_vq_auxt__44u3__p6_0,
  133970. NULL,
  133971. 0
  133972. };
  133973. static long _vq_quantlist__44u3__p6_1[] = {
  133974. 2,
  133975. 1,
  133976. 3,
  133977. 0,
  133978. 4,
  133979. };
  133980. static long _vq_lengthlist__44u3__p6_1[] = {
  133981. 2, 4, 4, 5, 5, 4, 5, 5, 6, 5, 4, 5, 5, 5, 6, 5,
  133982. 6, 5, 6, 6, 5, 5, 6, 6, 6,
  133983. };
  133984. static float _vq_quantthresh__44u3__p6_1[] = {
  133985. -1.5, -0.5, 0.5, 1.5,
  133986. };
  133987. static long _vq_quantmap__44u3__p6_1[] = {
  133988. 3, 1, 0, 2, 4,
  133989. };
  133990. static encode_aux_threshmatch _vq_auxt__44u3__p6_1 = {
  133991. _vq_quantthresh__44u3__p6_1,
  133992. _vq_quantmap__44u3__p6_1,
  133993. 5,
  133994. 5
  133995. };
  133996. static static_codebook _44u3__p6_1 = {
  133997. 2, 25,
  133998. _vq_lengthlist__44u3__p6_1,
  133999. 1, -533725184, 1611661312, 3, 0,
  134000. _vq_quantlist__44u3__p6_1,
  134001. NULL,
  134002. &_vq_auxt__44u3__p6_1,
  134003. NULL,
  134004. 0
  134005. };
  134006. static long _vq_quantlist__44u3__p7_0[] = {
  134007. 4,
  134008. 3,
  134009. 5,
  134010. 2,
  134011. 6,
  134012. 1,
  134013. 7,
  134014. 0,
  134015. 8,
  134016. };
  134017. static long _vq_lengthlist__44u3__p7_0[] = {
  134018. 1, 3, 3,10,10,10,10,10,10, 4,10,10,10,10,10,10,
  134019. 10,10, 4,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  134020. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  134021. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  134022. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  134023. 9,
  134024. };
  134025. static float _vq_quantthresh__44u3__p7_0[] = {
  134026. -892.5, -637.5, -382.5, -127.5, 127.5, 382.5, 637.5, 892.5,
  134027. };
  134028. static long _vq_quantmap__44u3__p7_0[] = {
  134029. 7, 5, 3, 1, 0, 2, 4, 6,
  134030. 8,
  134031. };
  134032. static encode_aux_threshmatch _vq_auxt__44u3__p7_0 = {
  134033. _vq_quantthresh__44u3__p7_0,
  134034. _vq_quantmap__44u3__p7_0,
  134035. 9,
  134036. 9
  134037. };
  134038. static static_codebook _44u3__p7_0 = {
  134039. 2, 81,
  134040. _vq_lengthlist__44u3__p7_0,
  134041. 1, -515907584, 1627381760, 4, 0,
  134042. _vq_quantlist__44u3__p7_0,
  134043. NULL,
  134044. &_vq_auxt__44u3__p7_0,
  134045. NULL,
  134046. 0
  134047. };
  134048. static long _vq_quantlist__44u3__p7_1[] = {
  134049. 7,
  134050. 6,
  134051. 8,
  134052. 5,
  134053. 9,
  134054. 4,
  134055. 10,
  134056. 3,
  134057. 11,
  134058. 2,
  134059. 12,
  134060. 1,
  134061. 13,
  134062. 0,
  134063. 14,
  134064. };
  134065. static long _vq_lengthlist__44u3__p7_1[] = {
  134066. 1, 4, 4, 6, 6, 7, 6, 8, 7, 9, 8,10, 9,11,11, 4,
  134067. 7, 7, 8, 7, 9, 9,10,10,11,11,11,11,12,12, 4, 7,
  134068. 7, 7, 7, 9, 9,10,10,11,11,12,12,12,11, 6, 8, 8,
  134069. 9, 9,10,10,11,11,12,12,13,12,13,13, 6, 8, 8, 9,
  134070. 9,10,11,11,11,12,12,13,14,13,13, 8, 9, 9,11,11,
  134071. 12,12,12,13,14,13,14,14,14,15, 8, 9, 9,11,11,11,
  134072. 12,13,14,13,14,15,17,14,15, 9,10,10,12,12,13,13,
  134073. 13,14,15,15,15,16,16,16, 9,11,11,12,12,13,13,14,
  134074. 14,14,15,16,16,16,16,10,12,12,13,13,14,14,15,15,
  134075. 15,16,17,17,17,17,10,12,11,13,13,15,14,15,14,16,
  134076. 17,16,16,16,16,11,13,12,14,14,14,14,15,16,17,16,
  134077. 17,17,17,17,11,13,12,14,14,14,15,17,16,17,17,17,
  134078. 17,17,17,12,13,13,15,16,15,16,17,17,16,16,17,17,
  134079. 17,17,12,13,13,15,15,15,16,17,17,17,16,17,16,17,
  134080. 17,
  134081. };
  134082. static float _vq_quantthresh__44u3__p7_1[] = {
  134083. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  134084. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  134085. };
  134086. static long _vq_quantmap__44u3__p7_1[] = {
  134087. 13, 11, 9, 7, 5, 3, 1, 0,
  134088. 2, 4, 6, 8, 10, 12, 14,
  134089. };
  134090. static encode_aux_threshmatch _vq_auxt__44u3__p7_1 = {
  134091. _vq_quantthresh__44u3__p7_1,
  134092. _vq_quantmap__44u3__p7_1,
  134093. 15,
  134094. 15
  134095. };
  134096. static static_codebook _44u3__p7_1 = {
  134097. 2, 225,
  134098. _vq_lengthlist__44u3__p7_1,
  134099. 1, -522338304, 1620115456, 4, 0,
  134100. _vq_quantlist__44u3__p7_1,
  134101. NULL,
  134102. &_vq_auxt__44u3__p7_1,
  134103. NULL,
  134104. 0
  134105. };
  134106. static long _vq_quantlist__44u3__p7_2[] = {
  134107. 8,
  134108. 7,
  134109. 9,
  134110. 6,
  134111. 10,
  134112. 5,
  134113. 11,
  134114. 4,
  134115. 12,
  134116. 3,
  134117. 13,
  134118. 2,
  134119. 14,
  134120. 1,
  134121. 15,
  134122. 0,
  134123. 16,
  134124. };
  134125. static long _vq_lengthlist__44u3__p7_2[] = {
  134126. 2, 5, 5, 7, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134127. 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134128. 10,10, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 9, 9, 9,
  134129. 9,10, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134130. 10,10,10,10, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,
  134131. 9,10,10,10,10, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134132. 10,10,10,10,10,10, 7, 8, 8, 9, 8, 9, 9, 9, 9,10,
  134133. 9,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134134. 9,10,10,10,10,10,10,10, 8, 9, 8, 9, 9, 9, 9,10,
  134135. 9,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,
  134136. 9,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  134137. 9,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,10, 9,
  134138. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,10,
  134139. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  134140. 10,10,10,10,10,10,10,10,10,10,10,10,10,11, 9,10,
  134141. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,11, 9,
  134142. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  134143. 9,10,10,10,10,10,10,10,10,10,10,10,11,11,11,10,
  134144. 11,
  134145. };
  134146. static float _vq_quantthresh__44u3__p7_2[] = {
  134147. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  134148. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  134149. };
  134150. static long _vq_quantmap__44u3__p7_2[] = {
  134151. 15, 13, 11, 9, 7, 5, 3, 1,
  134152. 0, 2, 4, 6, 8, 10, 12, 14,
  134153. 16,
  134154. };
  134155. static encode_aux_threshmatch _vq_auxt__44u3__p7_2 = {
  134156. _vq_quantthresh__44u3__p7_2,
  134157. _vq_quantmap__44u3__p7_2,
  134158. 17,
  134159. 17
  134160. };
  134161. static static_codebook _44u3__p7_2 = {
  134162. 2, 289,
  134163. _vq_lengthlist__44u3__p7_2,
  134164. 1, -529530880, 1611661312, 5, 0,
  134165. _vq_quantlist__44u3__p7_2,
  134166. NULL,
  134167. &_vq_auxt__44u3__p7_2,
  134168. NULL,
  134169. 0
  134170. };
  134171. static long _huff_lengthlist__44u3__short[] = {
  134172. 14,14,14,15,13,15,12,16,10, 8, 7, 9, 9, 8,12,16,
  134173. 10, 5, 4, 6, 5, 6, 9,16,14, 8, 6, 8, 7, 8,10,16,
  134174. 14, 7, 4, 6, 3, 5, 8,16,15, 9, 5, 7, 4, 4, 7,16,
  134175. 13,10, 6, 7, 4, 3, 4,13,13,12, 7, 9, 5, 5, 6,12,
  134176. };
  134177. static static_codebook _huff_book__44u3__short = {
  134178. 2, 64,
  134179. _huff_lengthlist__44u3__short,
  134180. 0, 0, 0, 0, 0,
  134181. NULL,
  134182. NULL,
  134183. NULL,
  134184. NULL,
  134185. 0
  134186. };
  134187. static long _huff_lengthlist__44u4__long[] = {
  134188. 3, 8,12,12,13,12,11,13, 5, 4, 6, 7, 8, 8, 9,13,
  134189. 9, 5, 4, 5, 5, 7, 9,13, 9, 6, 5, 6, 6, 7, 8,12,
  134190. 12, 7, 5, 6, 4, 5, 8,13,11, 7, 6, 6, 5, 5, 6,12,
  134191. 10, 8, 8, 7, 7, 5, 3, 8,10,12,13,12,12, 9, 6, 7,
  134192. };
  134193. static static_codebook _huff_book__44u4__long = {
  134194. 2, 64,
  134195. _huff_lengthlist__44u4__long,
  134196. 0, 0, 0, 0, 0,
  134197. NULL,
  134198. NULL,
  134199. NULL,
  134200. NULL,
  134201. 0
  134202. };
  134203. static long _vq_quantlist__44u4__p1_0[] = {
  134204. 1,
  134205. 0,
  134206. 2,
  134207. };
  134208. static long _vq_lengthlist__44u4__p1_0[] = {
  134209. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,10,11, 8,
  134210. 10,11, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  134211. 11, 8,11,11, 8,11,11,11,13,14,11,15,14, 8,11,11,
  134212. 10,13,12,11,14,14, 4, 8, 8, 8,11,11, 8,11,11, 7,
  134213. 11,11,11,15,14,10,12,14, 8,11,11,11,14,14,11,14,
  134214. 13,
  134215. };
  134216. static float _vq_quantthresh__44u4__p1_0[] = {
  134217. -0.5, 0.5,
  134218. };
  134219. static long _vq_quantmap__44u4__p1_0[] = {
  134220. 1, 0, 2,
  134221. };
  134222. static encode_aux_threshmatch _vq_auxt__44u4__p1_0 = {
  134223. _vq_quantthresh__44u4__p1_0,
  134224. _vq_quantmap__44u4__p1_0,
  134225. 3,
  134226. 3
  134227. };
  134228. static static_codebook _44u4__p1_0 = {
  134229. 4, 81,
  134230. _vq_lengthlist__44u4__p1_0,
  134231. 1, -535822336, 1611661312, 2, 0,
  134232. _vq_quantlist__44u4__p1_0,
  134233. NULL,
  134234. &_vq_auxt__44u4__p1_0,
  134235. NULL,
  134236. 0
  134237. };
  134238. static long _vq_quantlist__44u4__p2_0[] = {
  134239. 1,
  134240. 0,
  134241. 2,
  134242. };
  134243. static long _vq_lengthlist__44u4__p2_0[] = {
  134244. 2, 5, 5, 5, 6, 6, 5, 6, 6, 5, 6, 6, 7, 8, 8, 6,
  134245. 8, 8, 5, 6, 6, 6, 8, 8, 7, 8, 8, 5, 7, 6, 6, 8,
  134246. 8, 6, 8, 8, 6, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  134247. 8,10, 8, 8,10,10, 5, 6, 6, 6, 8, 8, 6, 8, 8, 6,
  134248. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  134249. 9,
  134250. };
  134251. static float _vq_quantthresh__44u4__p2_0[] = {
  134252. -0.5, 0.5,
  134253. };
  134254. static long _vq_quantmap__44u4__p2_0[] = {
  134255. 1, 0, 2,
  134256. };
  134257. static encode_aux_threshmatch _vq_auxt__44u4__p2_0 = {
  134258. _vq_quantthresh__44u4__p2_0,
  134259. _vq_quantmap__44u4__p2_0,
  134260. 3,
  134261. 3
  134262. };
  134263. static static_codebook _44u4__p2_0 = {
  134264. 4, 81,
  134265. _vq_lengthlist__44u4__p2_0,
  134266. 1, -535822336, 1611661312, 2, 0,
  134267. _vq_quantlist__44u4__p2_0,
  134268. NULL,
  134269. &_vq_auxt__44u4__p2_0,
  134270. NULL,
  134271. 0
  134272. };
  134273. static long _vq_quantlist__44u4__p3_0[] = {
  134274. 2,
  134275. 1,
  134276. 3,
  134277. 0,
  134278. 4,
  134279. };
  134280. static long _vq_lengthlist__44u4__p3_0[] = {
  134281. 2, 4, 4, 8, 8, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 8,
  134282. 10, 9,12,12, 8, 9,10,12,12, 5, 7, 7,10,10, 7, 9,
  134283. 9,11,11, 7, 9, 9,11,11,10,12,11,14,14, 9,10,11,
  134284. 13,14, 5, 7, 7,10,10, 7, 9, 9,11,11, 7, 9, 9,11,
  134285. 11, 9,11,10,14,13,10,11,11,14,14, 8,10,10,14,13,
  134286. 10,12,12,15,14, 9,11,11,15,14,13,14,14,17,17,12,
  134287. 14,14,16,16, 8,10,10,14,14, 9,11,11,14,15,10,12,
  134288. 12,14,15,12,14,13,16,16,13,14,15,15,18, 4, 7, 7,
  134289. 10,10, 7, 9, 9,12,11, 7, 9, 9,11,12,10,12,11,15,
  134290. 14,10,11,12,14,15, 7, 9, 9,12,12, 9,11,12,13,13,
  134291. 9,11,12,13,13,12,13,13,15,16,11,13,13,15,16, 7,
  134292. 9, 9,12,12, 9,11,10,13,12, 9,11,12,13,14,11,13,
  134293. 12,16,14,12,13,13,15,16,10,12,12,16,15,11,13,13,
  134294. 17,16,11,13,13,17,16,14,15,15,17,17,14,16,16,18,
  134295. 20, 9,11,11,15,16,11,13,12,16,16,11,13,13,16,17,
  134296. 14,15,14,18,16,14,16,16,17,20, 5, 7, 7,10,10, 7,
  134297. 9, 9,12,11, 7, 9,10,11,12,10,12,11,15,15,10,12,
  134298. 12,14,14, 7, 9, 9,12,12, 9,12,11,14,13, 9,10,11,
  134299. 12,13,12,13,14,16,16,11,12,13,14,16, 7, 9, 9,12,
  134300. 12, 9,12,11,13,13, 9,12,11,13,13,11,13,13,16,16,
  134301. 12,13,13,16,15, 9,11,11,16,14,11,13,13,16,16,11,
  134302. 12,13,16,16,14,16,16,17,17,13,14,15,16,17,10,12,
  134303. 12,15,15,11,13,13,16,17,11,13,13,16,16,14,16,15,
  134304. 19,19,14,15,15,17,18, 8,10,10,14,14,10,12,12,15,
  134305. 15,10,12,12,16,16,14,16,15,20,19,13,15,15,17,16,
  134306. 9,12,12,16,16,11,13,13,16,18,11,14,13,16,17,16,
  134307. 17,16,20, 0,15,16,18,18,20, 9,11,11,15,15,11,14,
  134308. 12,17,16,11,13,13,17,17,15,17,15,20,20,14,16,16,
  134309. 17, 0,13,15,14,18,16,14,15,16, 0,18,14,16,16, 0,
  134310. 0,18,16, 0, 0,20,16,18,18, 0, 0,12,14,14,17,18,
  134311. 13,15,14,20,18,14,16,15,19,19,16,20,16, 0,18,16,
  134312. 19,17,19, 0, 8,10,10,14,14,10,12,12,16,15,10,12,
  134313. 12,16,16,13,15,15,18,17,14,16,16,19, 0, 9,11,11,
  134314. 16,15,11,14,13,18,17,11,12,13,17,18,14,17,16,18,
  134315. 18,15,16,17,18,18, 9,12,12,16,16,11,13,13,16,18,
  134316. 11,14,13,17,17,15,16,16,18,20,16,17,17,20,20,12,
  134317. 14,14,18,17,14,16,16, 0,19,13,14,15,18, 0,16, 0,
  134318. 0, 0, 0,16,16, 0,19,20,13,15,14, 0, 0,14,16,16,
  134319. 18,19,14,16,15, 0,20,16,20,18, 0,20,17,20,17, 0,
  134320. 0,
  134321. };
  134322. static float _vq_quantthresh__44u4__p3_0[] = {
  134323. -1.5, -0.5, 0.5, 1.5,
  134324. };
  134325. static long _vq_quantmap__44u4__p3_0[] = {
  134326. 3, 1, 0, 2, 4,
  134327. };
  134328. static encode_aux_threshmatch _vq_auxt__44u4__p3_0 = {
  134329. _vq_quantthresh__44u4__p3_0,
  134330. _vq_quantmap__44u4__p3_0,
  134331. 5,
  134332. 5
  134333. };
  134334. static static_codebook _44u4__p3_0 = {
  134335. 4, 625,
  134336. _vq_lengthlist__44u4__p3_0,
  134337. 1, -533725184, 1611661312, 3, 0,
  134338. _vq_quantlist__44u4__p3_0,
  134339. NULL,
  134340. &_vq_auxt__44u4__p3_0,
  134341. NULL,
  134342. 0
  134343. };
  134344. static long _vq_quantlist__44u4__p4_0[] = {
  134345. 2,
  134346. 1,
  134347. 3,
  134348. 0,
  134349. 4,
  134350. };
  134351. static long _vq_lengthlist__44u4__p4_0[] = {
  134352. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 9,
  134353. 9, 9,11,11, 8, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  134354. 8,10,10, 7, 7, 8,10,10, 9,10,10,11,12, 9,10,10,
  134355. 11,12, 5, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 8,10,
  134356. 10, 9,10,10,12,11, 9,10,10,12,11, 9,10, 9,12,12,
  134357. 9,10,10,13,12, 9,10,10,12,12,12,12,12,14,14,11,
  134358. 12,12,13,14, 9, 9,10,12,12, 9,10,10,13,13, 9,10,
  134359. 10,12,13,11,12,12,14,13,11,12,12,14,14, 5, 7, 7,
  134360. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,
  134361. 12, 9,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,11,11,
  134362. 8, 9, 9,11,11,11,11,11,12,13,10,11,11,13,13, 6,
  134363. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  134364. 10,13,11,10,11,11,13,13, 9,11,10,13,12,10,11,11,
  134365. 13,14,10,11,11,14,13,12,12,13,12,15,12,13,13,15,
  134366. 15, 9,10,10,12,13,10,11,10,13,12,10,11,11,13,14,
  134367. 12,13,11,15,13,13,13,13,15,15, 5, 7, 7, 9, 9, 7,
  134368. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12,10,10,
  134369. 11,12,13, 6, 8, 8,10,10, 8, 9, 9,11,11, 7, 8, 9,
  134370. 10,11,10,11,11,13,13,10,10,11,11,13, 7, 8, 8,10,
  134371. 11, 8, 9, 9,11,11, 8, 9, 8,11,11,10,11,11,13,13,
  134372. 11,12,11,13,12, 9,10,10,13,12,10,11,11,14,13,10,
  134373. 10,11,12,13,12,13,13,15,15,12,11,13,13,14, 9,10,
  134374. 11,12,13,10,11,11,13,14,10,11,11,13,13,12,13,13,
  134375. 15,15,12,13,12,15,12, 8, 9, 9,12,12, 9,11,10,13,
  134376. 13, 9,10,10,13,13,12,13,13,15,15,12,12,12,14,14,
  134377. 9,10,10,13,13,10,11,11,13,14,10,11,11,14,13,13,
  134378. 13,14,14,16,13,13,13,15,15, 9,10,10,13,13,10,11,
  134379. 10,14,13,10,11,11,13,14,12,14,13,16,14,12,13,13,
  134380. 14,15,11,12,12,15,14,11,12,13,14,15,12,13,13,16,
  134381. 15,14,12,15,12,16,14,15,15,16,16,11,12,12,14,14,
  134382. 11,13,12,15,14,12,13,13,15,16,13,15,13,17,13,14,
  134383. 15,15,16,17, 8, 9, 9,12,12, 9,10,10,12,13, 9,10,
  134384. 10,13,13,12,12,12,14,14,12,13,13,15,15, 9,10,10,
  134385. 13,12,10,11,11,14,13,10,10,11,13,14,13,13,13,15,
  134386. 15,12,13,14,14,16, 9,10,10,13,13,10,11,11,13,14,
  134387. 10,11,11,14,14,13,13,13,15,15,13,14,13,16,14,11,
  134388. 12,12,15,14,12,13,13,16,15,11,12,13,14,15,14,15,
  134389. 15,17,16,13,13,15,13,16,11,12,13,14,15,13,13,13,
  134390. 15,16,11,13,12,15,14,14,15,15,16,16,14,15,12,17,
  134391. 13,
  134392. };
  134393. static float _vq_quantthresh__44u4__p4_0[] = {
  134394. -1.5, -0.5, 0.5, 1.5,
  134395. };
  134396. static long _vq_quantmap__44u4__p4_0[] = {
  134397. 3, 1, 0, 2, 4,
  134398. };
  134399. static encode_aux_threshmatch _vq_auxt__44u4__p4_0 = {
  134400. _vq_quantthresh__44u4__p4_0,
  134401. _vq_quantmap__44u4__p4_0,
  134402. 5,
  134403. 5
  134404. };
  134405. static static_codebook _44u4__p4_0 = {
  134406. 4, 625,
  134407. _vq_lengthlist__44u4__p4_0,
  134408. 1, -533725184, 1611661312, 3, 0,
  134409. _vq_quantlist__44u4__p4_0,
  134410. NULL,
  134411. &_vq_auxt__44u4__p4_0,
  134412. NULL,
  134413. 0
  134414. };
  134415. static long _vq_quantlist__44u4__p5_0[] = {
  134416. 4,
  134417. 3,
  134418. 5,
  134419. 2,
  134420. 6,
  134421. 1,
  134422. 7,
  134423. 0,
  134424. 8,
  134425. };
  134426. static long _vq_lengthlist__44u4__p5_0[] = {
  134427. 2, 3, 3, 6, 6, 7, 7, 9, 9, 4, 5, 5, 7, 7, 8, 8,
  134428. 10, 9, 4, 5, 5, 7, 7, 8, 8,10,10, 6, 7, 7, 8, 8,
  134429. 9, 9,11,10, 6, 7, 7, 8, 8, 9, 9,10,11, 7, 8, 8,
  134430. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  134431. 10,10,11,10,11,11,12,12, 9,10,10,10,11,11,11,12,
  134432. 12,
  134433. };
  134434. static float _vq_quantthresh__44u4__p5_0[] = {
  134435. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  134436. };
  134437. static long _vq_quantmap__44u4__p5_0[] = {
  134438. 7, 5, 3, 1, 0, 2, 4, 6,
  134439. 8,
  134440. };
  134441. static encode_aux_threshmatch _vq_auxt__44u4__p5_0 = {
  134442. _vq_quantthresh__44u4__p5_0,
  134443. _vq_quantmap__44u4__p5_0,
  134444. 9,
  134445. 9
  134446. };
  134447. static static_codebook _44u4__p5_0 = {
  134448. 2, 81,
  134449. _vq_lengthlist__44u4__p5_0,
  134450. 1, -531628032, 1611661312, 4, 0,
  134451. _vq_quantlist__44u4__p5_0,
  134452. NULL,
  134453. &_vq_auxt__44u4__p5_0,
  134454. NULL,
  134455. 0
  134456. };
  134457. static long _vq_quantlist__44u4__p6_0[] = {
  134458. 6,
  134459. 5,
  134460. 7,
  134461. 4,
  134462. 8,
  134463. 3,
  134464. 9,
  134465. 2,
  134466. 10,
  134467. 1,
  134468. 11,
  134469. 0,
  134470. 12,
  134471. };
  134472. static long _vq_lengthlist__44u4__p6_0[] = {
  134473. 1, 4, 4, 6, 6, 8, 8, 9, 9,11,10,13,13, 4, 6, 5,
  134474. 8, 8, 9, 9,10,10,11,11,14,14, 4, 6, 6, 8, 8, 9,
  134475. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  134476. 12,12,15,15, 6, 8, 8, 9, 9,10,11,11,11,12,12,15,
  134477. 15, 8, 9, 9,11,10,11,11,12,12,13,13,16,16, 8, 9,
  134478. 9,10,10,11,11,12,12,13,13,16,16,10,10,10,12,11,
  134479. 12,12,13,13,14,14,16,16,10,10,10,11,12,12,12,13,
  134480. 13,13,14,16,17,11,12,11,12,12,13,13,14,14,15,14,
  134481. 18,17,11,11,12,12,12,13,13,14,14,14,15,19,18,14,
  134482. 15,14,15,15,17,16,17,17,17,17,21, 0,14,15,15,16,
  134483. 16,16,16,17,17,18,17,20,21,
  134484. };
  134485. static float _vq_quantthresh__44u4__p6_0[] = {
  134486. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  134487. 12.5, 17.5, 22.5, 27.5,
  134488. };
  134489. static long _vq_quantmap__44u4__p6_0[] = {
  134490. 11, 9, 7, 5, 3, 1, 0, 2,
  134491. 4, 6, 8, 10, 12,
  134492. };
  134493. static encode_aux_threshmatch _vq_auxt__44u4__p6_0 = {
  134494. _vq_quantthresh__44u4__p6_0,
  134495. _vq_quantmap__44u4__p6_0,
  134496. 13,
  134497. 13
  134498. };
  134499. static static_codebook _44u4__p6_0 = {
  134500. 2, 169,
  134501. _vq_lengthlist__44u4__p6_0,
  134502. 1, -526516224, 1616117760, 4, 0,
  134503. _vq_quantlist__44u4__p6_0,
  134504. NULL,
  134505. &_vq_auxt__44u4__p6_0,
  134506. NULL,
  134507. 0
  134508. };
  134509. static long _vq_quantlist__44u4__p6_1[] = {
  134510. 2,
  134511. 1,
  134512. 3,
  134513. 0,
  134514. 4,
  134515. };
  134516. static long _vq_lengthlist__44u4__p6_1[] = {
  134517. 2, 4, 4, 5, 5, 4, 5, 5, 6, 5, 4, 5, 5, 5, 6, 5,
  134518. 6, 5, 6, 6, 5, 5, 6, 6, 6,
  134519. };
  134520. static float _vq_quantthresh__44u4__p6_1[] = {
  134521. -1.5, -0.5, 0.5, 1.5,
  134522. };
  134523. static long _vq_quantmap__44u4__p6_1[] = {
  134524. 3, 1, 0, 2, 4,
  134525. };
  134526. static encode_aux_threshmatch _vq_auxt__44u4__p6_1 = {
  134527. _vq_quantthresh__44u4__p6_1,
  134528. _vq_quantmap__44u4__p6_1,
  134529. 5,
  134530. 5
  134531. };
  134532. static static_codebook _44u4__p6_1 = {
  134533. 2, 25,
  134534. _vq_lengthlist__44u4__p6_1,
  134535. 1, -533725184, 1611661312, 3, 0,
  134536. _vq_quantlist__44u4__p6_1,
  134537. NULL,
  134538. &_vq_auxt__44u4__p6_1,
  134539. NULL,
  134540. 0
  134541. };
  134542. static long _vq_quantlist__44u4__p7_0[] = {
  134543. 6,
  134544. 5,
  134545. 7,
  134546. 4,
  134547. 8,
  134548. 3,
  134549. 9,
  134550. 2,
  134551. 10,
  134552. 1,
  134553. 11,
  134554. 0,
  134555. 12,
  134556. };
  134557. static long _vq_lengthlist__44u4__p7_0[] = {
  134558. 1, 3, 3,12,12,12,12,12,12,12,12,12,12, 3,12,11,
  134559. 12,12,12,12,12,12,12,12,12,12, 4,11,10,12,12,12,
  134560. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  134561. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  134562. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  134563. 12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134564. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134565. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134566. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134567. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134568. 11,11,11,11,11,11,11,11,11,
  134569. };
  134570. static float _vq_quantthresh__44u4__p7_0[] = {
  134571. -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5, 382.5,
  134572. 637.5, 892.5, 1147.5, 1402.5,
  134573. };
  134574. static long _vq_quantmap__44u4__p7_0[] = {
  134575. 11, 9, 7, 5, 3, 1, 0, 2,
  134576. 4, 6, 8, 10, 12,
  134577. };
  134578. static encode_aux_threshmatch _vq_auxt__44u4__p7_0 = {
  134579. _vq_quantthresh__44u4__p7_0,
  134580. _vq_quantmap__44u4__p7_0,
  134581. 13,
  134582. 13
  134583. };
  134584. static static_codebook _44u4__p7_0 = {
  134585. 2, 169,
  134586. _vq_lengthlist__44u4__p7_0,
  134587. 1, -514332672, 1627381760, 4, 0,
  134588. _vq_quantlist__44u4__p7_0,
  134589. NULL,
  134590. &_vq_auxt__44u4__p7_0,
  134591. NULL,
  134592. 0
  134593. };
  134594. static long _vq_quantlist__44u4__p7_1[] = {
  134595. 7,
  134596. 6,
  134597. 8,
  134598. 5,
  134599. 9,
  134600. 4,
  134601. 10,
  134602. 3,
  134603. 11,
  134604. 2,
  134605. 12,
  134606. 1,
  134607. 13,
  134608. 0,
  134609. 14,
  134610. };
  134611. static long _vq_lengthlist__44u4__p7_1[] = {
  134612. 1, 4, 4, 6, 6, 7, 7, 9, 8,10, 8,10, 9,11,11, 4,
  134613. 7, 6, 8, 7, 9, 9,10,10,11,10,11,10,12,10, 4, 6,
  134614. 7, 8, 8, 9, 9,10,10,11,11,11,11,12,12, 6, 8, 8,
  134615. 10, 9,11,10,12,11,12,12,12,12,13,13, 6, 8, 8,10,
  134616. 10,10,11,11,11,12,12,13,12,13,13, 8, 9, 9,11,11,
  134617. 12,11,12,12,13,13,13,13,13,13, 8, 9, 9,11,11,11,
  134618. 12,12,12,13,13,13,13,13,13, 9,10,10,12,11,13,13,
  134619. 13,13,14,13,13,14,14,14, 9,10,11,11,12,12,13,13,
  134620. 13,13,13,14,15,14,14,10,11,11,12,12,13,13,14,14,
  134621. 14,14,14,15,16,16,10,11,11,12,13,13,13,13,15,14,
  134622. 14,15,16,15,16,10,12,12,13,13,14,14,14,15,15,15,
  134623. 15,15,15,16,11,12,12,13,13,14,14,14,15,15,15,16,
  134624. 15,17,16,11,12,12,13,13,13,15,15,14,16,16,16,16,
  134625. 16,17,11,12,12,13,13,14,14,15,14,15,15,17,17,16,
  134626. 16,
  134627. };
  134628. static float _vq_quantthresh__44u4__p7_1[] = {
  134629. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  134630. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  134631. };
  134632. static long _vq_quantmap__44u4__p7_1[] = {
  134633. 13, 11, 9, 7, 5, 3, 1, 0,
  134634. 2, 4, 6, 8, 10, 12, 14,
  134635. };
  134636. static encode_aux_threshmatch _vq_auxt__44u4__p7_1 = {
  134637. _vq_quantthresh__44u4__p7_1,
  134638. _vq_quantmap__44u4__p7_1,
  134639. 15,
  134640. 15
  134641. };
  134642. static static_codebook _44u4__p7_1 = {
  134643. 2, 225,
  134644. _vq_lengthlist__44u4__p7_1,
  134645. 1, -522338304, 1620115456, 4, 0,
  134646. _vq_quantlist__44u4__p7_1,
  134647. NULL,
  134648. &_vq_auxt__44u4__p7_1,
  134649. NULL,
  134650. 0
  134651. };
  134652. static long _vq_quantlist__44u4__p7_2[] = {
  134653. 8,
  134654. 7,
  134655. 9,
  134656. 6,
  134657. 10,
  134658. 5,
  134659. 11,
  134660. 4,
  134661. 12,
  134662. 3,
  134663. 13,
  134664. 2,
  134665. 14,
  134666. 1,
  134667. 15,
  134668. 0,
  134669. 16,
  134670. };
  134671. static long _vq_lengthlist__44u4__p7_2[] = {
  134672. 2, 5, 5, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134673. 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134674. 9, 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134675. 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134676. 10,10,10,10, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,
  134677. 9,10, 9,10,10, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134678. 10,10,10,10,10,10, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134679. 9,10,10,10,10,10,10, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  134680. 10,10,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9,
  134681. 10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,10,
  134682. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  134683. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,10,
  134684. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  134685. 10,10,10,10,10,10,10,10,10,11,10,10,10, 9, 9, 9,
  134686. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9,
  134687. 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  134688. 10, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  134689. 9,10, 9,10,10,10,10,10,10,10,10,10,10,11,10,10,
  134690. 10,
  134691. };
  134692. static float _vq_quantthresh__44u4__p7_2[] = {
  134693. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  134694. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  134695. };
  134696. static long _vq_quantmap__44u4__p7_2[] = {
  134697. 15, 13, 11, 9, 7, 5, 3, 1,
  134698. 0, 2, 4, 6, 8, 10, 12, 14,
  134699. 16,
  134700. };
  134701. static encode_aux_threshmatch _vq_auxt__44u4__p7_2 = {
  134702. _vq_quantthresh__44u4__p7_2,
  134703. _vq_quantmap__44u4__p7_2,
  134704. 17,
  134705. 17
  134706. };
  134707. static static_codebook _44u4__p7_2 = {
  134708. 2, 289,
  134709. _vq_lengthlist__44u4__p7_2,
  134710. 1, -529530880, 1611661312, 5, 0,
  134711. _vq_quantlist__44u4__p7_2,
  134712. NULL,
  134713. &_vq_auxt__44u4__p7_2,
  134714. NULL,
  134715. 0
  134716. };
  134717. static long _huff_lengthlist__44u4__short[] = {
  134718. 14,17,15,17,16,14,13,16,10, 7, 7,10,13,10,15,16,
  134719. 9, 4, 4, 6, 5, 7, 9,16,12, 8, 7, 8, 8, 8,11,16,
  134720. 14, 7, 4, 6, 3, 5, 8,15,13, 8, 5, 7, 4, 5, 7,16,
  134721. 12, 9, 6, 8, 3, 3, 5,16,14,13, 7,10, 5, 5, 7,15,
  134722. };
  134723. static static_codebook _huff_book__44u4__short = {
  134724. 2, 64,
  134725. _huff_lengthlist__44u4__short,
  134726. 0, 0, 0, 0, 0,
  134727. NULL,
  134728. NULL,
  134729. NULL,
  134730. NULL,
  134731. 0
  134732. };
  134733. static long _huff_lengthlist__44u5__long[] = {
  134734. 3, 8,13,12,14,12,16,11,13,14, 5, 4, 5, 6, 7, 8,
  134735. 10, 9,12,15,10, 5, 5, 5, 6, 8, 9, 9,13,15,10, 5,
  134736. 5, 6, 6, 7, 8, 8,11,13,12, 7, 5, 6, 4, 6, 7, 7,
  134737. 11,14,11, 7, 7, 6, 6, 6, 7, 6,10,14,14, 9, 8, 8,
  134738. 6, 7, 7, 7,11,16,11, 8, 8, 7, 6, 6, 7, 4, 7,12,
  134739. 10,10,12,10,10, 9,10, 5, 6, 9,10,12,15,13,14,14,
  134740. 14, 8, 7, 8,
  134741. };
  134742. static static_codebook _huff_book__44u5__long = {
  134743. 2, 100,
  134744. _huff_lengthlist__44u5__long,
  134745. 0, 0, 0, 0, 0,
  134746. NULL,
  134747. NULL,
  134748. NULL,
  134749. NULL,
  134750. 0
  134751. };
  134752. static long _vq_quantlist__44u5__p1_0[] = {
  134753. 1,
  134754. 0,
  134755. 2,
  134756. };
  134757. static long _vq_lengthlist__44u5__p1_0[] = {
  134758. 1, 4, 4, 5, 8, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  134759. 9,10, 5, 8, 8, 7,10, 9, 8,10,10, 5, 8, 8, 8,10,
  134760. 10, 8,10,10, 8,10,10,10,12,13,10,13,13, 7,10,10,
  134761. 10,13,11,10,13,13, 4, 8, 8, 8,11,10, 8,10,10, 7,
  134762. 10,10,10,13,13,10,11,13, 8,10,11,10,13,13,10,13,
  134763. 12,
  134764. };
  134765. static float _vq_quantthresh__44u5__p1_0[] = {
  134766. -0.5, 0.5,
  134767. };
  134768. static long _vq_quantmap__44u5__p1_0[] = {
  134769. 1, 0, 2,
  134770. };
  134771. static encode_aux_threshmatch _vq_auxt__44u5__p1_0 = {
  134772. _vq_quantthresh__44u5__p1_0,
  134773. _vq_quantmap__44u5__p1_0,
  134774. 3,
  134775. 3
  134776. };
  134777. static static_codebook _44u5__p1_0 = {
  134778. 4, 81,
  134779. _vq_lengthlist__44u5__p1_0,
  134780. 1, -535822336, 1611661312, 2, 0,
  134781. _vq_quantlist__44u5__p1_0,
  134782. NULL,
  134783. &_vq_auxt__44u5__p1_0,
  134784. NULL,
  134785. 0
  134786. };
  134787. static long _vq_quantlist__44u5__p2_0[] = {
  134788. 1,
  134789. 0,
  134790. 2,
  134791. };
  134792. static long _vq_lengthlist__44u5__p2_0[] = {
  134793. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 8, 8, 6,
  134794. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 8, 5, 6, 6, 6, 8,
  134795. 8, 6, 8, 8, 6, 8, 8, 8, 9, 9, 8, 9, 9, 6, 8, 7,
  134796. 7, 9, 8, 8, 9, 9, 5, 6, 6, 6, 8, 7, 6, 8, 8, 6,
  134797. 8, 7, 8, 9, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 8, 9,
  134798. 9,
  134799. };
  134800. static float _vq_quantthresh__44u5__p2_0[] = {
  134801. -0.5, 0.5,
  134802. };
  134803. static long _vq_quantmap__44u5__p2_0[] = {
  134804. 1, 0, 2,
  134805. };
  134806. static encode_aux_threshmatch _vq_auxt__44u5__p2_0 = {
  134807. _vq_quantthresh__44u5__p2_0,
  134808. _vq_quantmap__44u5__p2_0,
  134809. 3,
  134810. 3
  134811. };
  134812. static static_codebook _44u5__p2_0 = {
  134813. 4, 81,
  134814. _vq_lengthlist__44u5__p2_0,
  134815. 1, -535822336, 1611661312, 2, 0,
  134816. _vq_quantlist__44u5__p2_0,
  134817. NULL,
  134818. &_vq_auxt__44u5__p2_0,
  134819. NULL,
  134820. 0
  134821. };
  134822. static long _vq_quantlist__44u5__p3_0[] = {
  134823. 2,
  134824. 1,
  134825. 3,
  134826. 0,
  134827. 4,
  134828. };
  134829. static long _vq_lengthlist__44u5__p3_0[] = {
  134830. 2, 4, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  134831. 10, 9,13,12, 8, 9,10,12,12, 5, 7, 7,10,10, 7, 9,
  134832. 9,11,11, 6, 8, 9,11,11,10,11,11,14,14, 9,10,11,
  134833. 13,14, 5, 7, 7, 9,10, 7, 9, 8,11,11, 7, 9, 9,11,
  134834. 11, 9,11,10,14,13,10,11,11,14,14, 8,10,10,13,13,
  134835. 10,11,11,15,14, 9,11,11,14,14,13,14,14,17,16,12,
  134836. 13,13,15,16, 8,10,10,13,13, 9,11,11,14,15,10,11,
  134837. 11,14,15,12,14,13,16,16,13,15,14,15,17, 5, 7, 7,
  134838. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,11,10,11,11,14,
  134839. 14,10,11,12,14,14, 7, 9, 9,12,11, 9,11,11,13,13,
  134840. 9,11,11,13,13,12,13,13,15,16,11,12,13,15,16, 6,
  134841. 9, 9,11,11, 8,11,10,13,12, 9,11,11,13,14,11,13,
  134842. 12,16,14,11,13,13,16,17,10,12,11,15,15,11,13,13,
  134843. 16,16,11,13,13,17,16,14,15,15,17,17,14,16,16,17,
  134844. 18, 9,11,11,14,15,10,12,12,15,15,11,13,13,16,17,
  134845. 13,15,13,17,15,14,15,16,18, 0, 5, 7, 7,10,10, 7,
  134846. 9, 9,11,11, 7, 9, 9,11,11,10,11,11,14,14,10,11,
  134847. 12,14,15, 6, 9, 9,12,11, 9,11,11,13,13, 8,10,11,
  134848. 12,13,11,13,13,16,15,11,12,13,14,15, 7, 9, 9,11,
  134849. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,13,15,16,
  134850. 11,13,13,15,14, 9,11,11,15,14,11,13,13,17,15,10,
  134851. 12,12,15,15,14,16,16,17,17,13,13,15,15,17,10,11,
  134852. 12,15,15,11,13,13,16,16,11,13,13,15,15,14,15,15,
  134853. 18,18,14,15,15,17,17, 8,10,10,13,13,10,12,11,15,
  134854. 15,10,11,12,15,15,14,15,15,18,18,13,14,14,18,18,
  134855. 9,11,11,15,16,11,13,13,17,17,11,13,13,16,16,15,
  134856. 15,16,17, 0,14,15,17, 0, 0, 9,11,11,15,15,10,13,
  134857. 12,18,16,11,13,13,15,16,14,16,15,20,20,14,15,16,
  134858. 17, 0,13,14,14,20,16,14,15,16,19,18,14,15,15,19,
  134859. 0,18,16, 0,20,20,16,18,18, 0, 0,12,14,14,18,18,
  134860. 13,15,14,18,16,14,15,16,18,20,16,19,16, 0,17,17,
  134861. 18,18,19, 0, 8,10,10,14,14,10,11,11,14,15,10,11,
  134862. 12,15,15,13,15,14,19,17,13,15,15,17, 0, 9,11,11,
  134863. 16,15,11,13,13,16,16,10,12,13,15,17,14,16,16,18,
  134864. 18,14,15,15,18, 0, 9,11,11,15,15,11,13,13,16,17,
  134865. 11,13,13,18,17,14,18,16,18,18,15,17,17,18, 0,12,
  134866. 14,14,18,18,14,15,15,20, 0,13,14,15,17, 0,16,18,
  134867. 17, 0, 0,16,16, 0,17,20,12,14,14,18,18,14,16,15,
  134868. 0,18,14,16,15,18, 0,16,19,17, 0, 0,17,18,16, 0,
  134869. 0,
  134870. };
  134871. static float _vq_quantthresh__44u5__p3_0[] = {
  134872. -1.5, -0.5, 0.5, 1.5,
  134873. };
  134874. static long _vq_quantmap__44u5__p3_0[] = {
  134875. 3, 1, 0, 2, 4,
  134876. };
  134877. static encode_aux_threshmatch _vq_auxt__44u5__p3_0 = {
  134878. _vq_quantthresh__44u5__p3_0,
  134879. _vq_quantmap__44u5__p3_0,
  134880. 5,
  134881. 5
  134882. };
  134883. static static_codebook _44u5__p3_0 = {
  134884. 4, 625,
  134885. _vq_lengthlist__44u5__p3_0,
  134886. 1, -533725184, 1611661312, 3, 0,
  134887. _vq_quantlist__44u5__p3_0,
  134888. NULL,
  134889. &_vq_auxt__44u5__p3_0,
  134890. NULL,
  134891. 0
  134892. };
  134893. static long _vq_quantlist__44u5__p4_0[] = {
  134894. 2,
  134895. 1,
  134896. 3,
  134897. 0,
  134898. 4,
  134899. };
  134900. static long _vq_lengthlist__44u5__p4_0[] = {
  134901. 4, 5, 5, 8, 8, 6, 7, 6, 9, 9, 6, 6, 7, 9, 9, 8,
  134902. 9, 9,11,11, 8, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 8,
  134903. 8,10,10, 6, 7, 8, 9,10, 9,10,10,11,12, 9, 9,10,
  134904. 11,12, 6, 7, 7, 9, 9, 6, 8, 7,10, 9, 7, 8, 8,10,
  134905. 10, 9,10, 9,12,11, 9,10,10,12,11, 8, 9, 9,12,11,
  134906. 9,10,10,12,12, 9,10,10,12,12,11,12,12,13,14,11,
  134907. 11,12,13,14, 8, 9, 9,11,12, 9,10,10,12,12, 9,10,
  134908. 10,12,12,11,12,11,14,13,11,12,12,13,13, 5, 7, 7,
  134909. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,
  134910. 12, 9,10,10,12,12, 7, 8, 8,10,10, 8, 8, 9,10,11,
  134911. 8, 9, 9,11,11,10,10,11,11,13,10,11,11,12,13, 6,
  134912. 7, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  134913. 10,13,11,10,11,11,12,12, 9,10,10,12,12,10,10,11,
  134914. 12,13,10,11,11,13,13,12,11,13,12,15,12,13,13,14,
  134915. 15, 9,10,10,12,12, 9,11,10,13,12,10,11,11,13,13,
  134916. 11,13,11,14,12,12,13,13,14,15, 5, 7, 7, 9, 9, 7,
  134917. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12, 9,10,
  134918. 10,12,12, 6, 8, 7,10,10, 8, 9, 9,11,11, 7, 8, 9,
  134919. 10,11,10,11,11,12,12,10,10,11,11,13, 7, 8, 8,10,
  134920. 10, 8, 9, 9,11,11, 8, 9, 8,11,10,10,11,11,13,12,
  134921. 10,11,10,13,11, 9,10,10,12,12,10,11,11,13,12, 9,
  134922. 10,10,12,13,12,13,13,14,15,11,11,13,12,14, 9,10,
  134923. 10,12,12,10,11,11,13,13,10,11,10,13,12,12,13,13,
  134924. 14,14,12,13,11,14,12, 8, 9, 9,12,12, 9,10,10,12,
  134925. 12, 9,10,10,12,12,12,12,12,14,14,11,12,12,14,13,
  134926. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,12,12,
  134927. 12,13,14,15,12,13,13,15,14, 9,10,10,12,12,10,11,
  134928. 10,13,12,10,11,11,12,13,12,13,12,15,13,12,13,13,
  134929. 14,15,11,12,12,14,13,11,12,12,14,15,12,13,13,15,
  134930. 14,13,12,14,12,16,13,14,14,15,15,11,11,12,14,14,
  134931. 11,12,11,14,13,12,13,13,14,15,13,14,12,16,12,14,
  134932. 14,15,16,16, 8, 9, 9,11,12, 9,10,10,12,12, 9,10,
  134933. 10,12,13,11,12,12,13,13,12,12,13,14,14, 9,10,10,
  134934. 12,12,10,11,10,13,12,10,10,11,12,13,12,13,13,15,
  134935. 14,12,12,13,13,15, 9,10,10,12,13,10,11,11,12,13,
  134936. 10,11,11,13,13,12,13,13,14,15,12,13,12,15,14,11,
  134937. 12,11,14,13,12,13,13,15,14,11,11,12,13,14,14,15,
  134938. 14,16,15,13,12,14,13,16,11,12,12,13,14,12,13,13,
  134939. 14,15,11,12,11,14,14,14,14,14,15,16,13,15,12,16,
  134940. 12,
  134941. };
  134942. static float _vq_quantthresh__44u5__p4_0[] = {
  134943. -1.5, -0.5, 0.5, 1.5,
  134944. };
  134945. static long _vq_quantmap__44u5__p4_0[] = {
  134946. 3, 1, 0, 2, 4,
  134947. };
  134948. static encode_aux_threshmatch _vq_auxt__44u5__p4_0 = {
  134949. _vq_quantthresh__44u5__p4_0,
  134950. _vq_quantmap__44u5__p4_0,
  134951. 5,
  134952. 5
  134953. };
  134954. static static_codebook _44u5__p4_0 = {
  134955. 4, 625,
  134956. _vq_lengthlist__44u5__p4_0,
  134957. 1, -533725184, 1611661312, 3, 0,
  134958. _vq_quantlist__44u5__p4_0,
  134959. NULL,
  134960. &_vq_auxt__44u5__p4_0,
  134961. NULL,
  134962. 0
  134963. };
  134964. static long _vq_quantlist__44u5__p5_0[] = {
  134965. 4,
  134966. 3,
  134967. 5,
  134968. 2,
  134969. 6,
  134970. 1,
  134971. 7,
  134972. 0,
  134973. 8,
  134974. };
  134975. static long _vq_lengthlist__44u5__p5_0[] = {
  134976. 2, 3, 3, 6, 6, 8, 8,10,10, 4, 5, 5, 8, 7, 8, 8,
  134977. 11,10, 3, 5, 5, 7, 8, 8, 8,10,11, 6, 8, 7,10, 9,
  134978. 10,10,11,11, 6, 7, 8, 9, 9, 9,10,11,12, 8, 8, 8,
  134979. 10,10,11,11,13,12, 8, 8, 9, 9,10,11,11,12,13,10,
  134980. 11,10,12,11,13,12,14,14,10,10,11,11,12,12,13,14,
  134981. 14,
  134982. };
  134983. static float _vq_quantthresh__44u5__p5_0[] = {
  134984. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  134985. };
  134986. static long _vq_quantmap__44u5__p5_0[] = {
  134987. 7, 5, 3, 1, 0, 2, 4, 6,
  134988. 8,
  134989. };
  134990. static encode_aux_threshmatch _vq_auxt__44u5__p5_0 = {
  134991. _vq_quantthresh__44u5__p5_0,
  134992. _vq_quantmap__44u5__p5_0,
  134993. 9,
  134994. 9
  134995. };
  134996. static static_codebook _44u5__p5_0 = {
  134997. 2, 81,
  134998. _vq_lengthlist__44u5__p5_0,
  134999. 1, -531628032, 1611661312, 4, 0,
  135000. _vq_quantlist__44u5__p5_0,
  135001. NULL,
  135002. &_vq_auxt__44u5__p5_0,
  135003. NULL,
  135004. 0
  135005. };
  135006. static long _vq_quantlist__44u5__p6_0[] = {
  135007. 4,
  135008. 3,
  135009. 5,
  135010. 2,
  135011. 6,
  135012. 1,
  135013. 7,
  135014. 0,
  135015. 8,
  135016. };
  135017. static long _vq_lengthlist__44u5__p6_0[] = {
  135018. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 7, 7,
  135019. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  135020. 8, 8,10,10, 6, 6, 6, 7, 7, 8, 8,10,10, 7, 7, 7,
  135021. 8, 8, 9, 9,11,10, 7, 7, 7, 8, 8, 9, 9,10,11, 9,
  135022. 9, 9,10,10,11,10,11,11, 9, 9, 9,10,10,11,10,11,
  135023. 11,
  135024. };
  135025. static float _vq_quantthresh__44u5__p6_0[] = {
  135026. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135027. };
  135028. static long _vq_quantmap__44u5__p6_0[] = {
  135029. 7, 5, 3, 1, 0, 2, 4, 6,
  135030. 8,
  135031. };
  135032. static encode_aux_threshmatch _vq_auxt__44u5__p6_0 = {
  135033. _vq_quantthresh__44u5__p6_0,
  135034. _vq_quantmap__44u5__p6_0,
  135035. 9,
  135036. 9
  135037. };
  135038. static static_codebook _44u5__p6_0 = {
  135039. 2, 81,
  135040. _vq_lengthlist__44u5__p6_0,
  135041. 1, -531628032, 1611661312, 4, 0,
  135042. _vq_quantlist__44u5__p6_0,
  135043. NULL,
  135044. &_vq_auxt__44u5__p6_0,
  135045. NULL,
  135046. 0
  135047. };
  135048. static long _vq_quantlist__44u5__p7_0[] = {
  135049. 1,
  135050. 0,
  135051. 2,
  135052. };
  135053. static long _vq_lengthlist__44u5__p7_0[] = {
  135054. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 9, 8,11,10, 7,
  135055. 11,10, 5, 9, 9, 7,10,10, 8,10,11, 4, 9, 9, 9,12,
  135056. 12, 9,12,12, 8,12,12,11,12,12,10,12,13, 7,12,12,
  135057. 11,12,12,10,12,13, 4, 9, 9, 9,12,12, 9,12,12, 7,
  135058. 12,11,10,13,13,11,12,12, 7,12,12,10,13,13,11,12,
  135059. 12,
  135060. };
  135061. static float _vq_quantthresh__44u5__p7_0[] = {
  135062. -5.5, 5.5,
  135063. };
  135064. static long _vq_quantmap__44u5__p7_0[] = {
  135065. 1, 0, 2,
  135066. };
  135067. static encode_aux_threshmatch _vq_auxt__44u5__p7_0 = {
  135068. _vq_quantthresh__44u5__p7_0,
  135069. _vq_quantmap__44u5__p7_0,
  135070. 3,
  135071. 3
  135072. };
  135073. static static_codebook _44u5__p7_0 = {
  135074. 4, 81,
  135075. _vq_lengthlist__44u5__p7_0,
  135076. 1, -529137664, 1618345984, 2, 0,
  135077. _vq_quantlist__44u5__p7_0,
  135078. NULL,
  135079. &_vq_auxt__44u5__p7_0,
  135080. NULL,
  135081. 0
  135082. };
  135083. static long _vq_quantlist__44u5__p7_1[] = {
  135084. 5,
  135085. 4,
  135086. 6,
  135087. 3,
  135088. 7,
  135089. 2,
  135090. 8,
  135091. 1,
  135092. 9,
  135093. 0,
  135094. 10,
  135095. };
  135096. static long _vq_lengthlist__44u5__p7_1[] = {
  135097. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 7, 7,
  135098. 8, 8, 9, 8, 8, 9, 4, 5, 5, 7, 7, 8, 8, 9, 9, 8,
  135099. 9, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 6, 7, 7, 8,
  135100. 8, 9, 9, 9, 9, 9, 9, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  135101. 9, 9, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9,
  135102. 9, 9, 9, 9,10,10,10,10, 8, 9, 9, 9, 9, 9, 9,10,
  135103. 10,10,10, 8, 9, 9, 9, 9, 9, 9,10,10,10,10, 8, 9,
  135104. 9, 9, 9, 9, 9,10,10,10,10,
  135105. };
  135106. static float _vq_quantthresh__44u5__p7_1[] = {
  135107. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135108. 3.5, 4.5,
  135109. };
  135110. static long _vq_quantmap__44u5__p7_1[] = {
  135111. 9, 7, 5, 3, 1, 0, 2, 4,
  135112. 6, 8, 10,
  135113. };
  135114. static encode_aux_threshmatch _vq_auxt__44u5__p7_1 = {
  135115. _vq_quantthresh__44u5__p7_1,
  135116. _vq_quantmap__44u5__p7_1,
  135117. 11,
  135118. 11
  135119. };
  135120. static static_codebook _44u5__p7_1 = {
  135121. 2, 121,
  135122. _vq_lengthlist__44u5__p7_1,
  135123. 1, -531365888, 1611661312, 4, 0,
  135124. _vq_quantlist__44u5__p7_1,
  135125. NULL,
  135126. &_vq_auxt__44u5__p7_1,
  135127. NULL,
  135128. 0
  135129. };
  135130. static long _vq_quantlist__44u5__p8_0[] = {
  135131. 5,
  135132. 4,
  135133. 6,
  135134. 3,
  135135. 7,
  135136. 2,
  135137. 8,
  135138. 1,
  135139. 9,
  135140. 0,
  135141. 10,
  135142. };
  135143. static long _vq_lengthlist__44u5__p8_0[] = {
  135144. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,10, 4, 6, 6, 7, 7,
  135145. 9, 9,10,10,11,11, 4, 6, 6, 7, 7, 9, 9,10,10,11,
  135146. 11, 6, 8, 7, 9, 9,10,10,11,11,13,12, 6, 8, 8, 9,
  135147. 9,10,10,11,11,12,13, 8, 9, 9,10,10,12,12,13,12,
  135148. 14,13, 8, 9, 9,10,10,12,12,13,13,14,14, 9,11,11,
  135149. 12,12,13,13,14,14,15,14, 9,11,11,12,12,13,13,14,
  135150. 14,15,14,11,12,12,13,13,14,14,15,14,15,14,11,11,
  135151. 12,13,13,14,14,14,14,15,15,
  135152. };
  135153. static float _vq_quantthresh__44u5__p8_0[] = {
  135154. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  135155. 38.5, 49.5,
  135156. };
  135157. static long _vq_quantmap__44u5__p8_0[] = {
  135158. 9, 7, 5, 3, 1, 0, 2, 4,
  135159. 6, 8, 10,
  135160. };
  135161. static encode_aux_threshmatch _vq_auxt__44u5__p8_0 = {
  135162. _vq_quantthresh__44u5__p8_0,
  135163. _vq_quantmap__44u5__p8_0,
  135164. 11,
  135165. 11
  135166. };
  135167. static static_codebook _44u5__p8_0 = {
  135168. 2, 121,
  135169. _vq_lengthlist__44u5__p8_0,
  135170. 1, -524582912, 1618345984, 4, 0,
  135171. _vq_quantlist__44u5__p8_0,
  135172. NULL,
  135173. &_vq_auxt__44u5__p8_0,
  135174. NULL,
  135175. 0
  135176. };
  135177. static long _vq_quantlist__44u5__p8_1[] = {
  135178. 5,
  135179. 4,
  135180. 6,
  135181. 3,
  135182. 7,
  135183. 2,
  135184. 8,
  135185. 1,
  135186. 9,
  135187. 0,
  135188. 10,
  135189. };
  135190. static long _vq_lengthlist__44u5__p8_1[] = {
  135191. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 5, 7, 6,
  135192. 7, 7, 8, 8, 8, 8, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  135193. 8, 6, 7, 6, 7, 7, 8, 8, 8, 8, 8, 8, 6, 6, 7, 7,
  135194. 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8,
  135195. 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8,
  135196. 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8,
  135197. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  135198. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  135199. };
  135200. static float _vq_quantthresh__44u5__p8_1[] = {
  135201. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135202. 3.5, 4.5,
  135203. };
  135204. static long _vq_quantmap__44u5__p8_1[] = {
  135205. 9, 7, 5, 3, 1, 0, 2, 4,
  135206. 6, 8, 10,
  135207. };
  135208. static encode_aux_threshmatch _vq_auxt__44u5__p8_1 = {
  135209. _vq_quantthresh__44u5__p8_1,
  135210. _vq_quantmap__44u5__p8_1,
  135211. 11,
  135212. 11
  135213. };
  135214. static static_codebook _44u5__p8_1 = {
  135215. 2, 121,
  135216. _vq_lengthlist__44u5__p8_1,
  135217. 1, -531365888, 1611661312, 4, 0,
  135218. _vq_quantlist__44u5__p8_1,
  135219. NULL,
  135220. &_vq_auxt__44u5__p8_1,
  135221. NULL,
  135222. 0
  135223. };
  135224. static long _vq_quantlist__44u5__p9_0[] = {
  135225. 6,
  135226. 5,
  135227. 7,
  135228. 4,
  135229. 8,
  135230. 3,
  135231. 9,
  135232. 2,
  135233. 10,
  135234. 1,
  135235. 11,
  135236. 0,
  135237. 12,
  135238. };
  135239. static long _vq_lengthlist__44u5__p9_0[] = {
  135240. 1, 3, 2,12,10,13,13,13,13,13,13,13,13, 4, 9, 9,
  135241. 13,13,13,13,13,13,13,13,13,13, 5,10, 9,13,13,13,
  135242. 13,13,13,13,13,13,13,12,13,13,13,13,13,13,13,13,
  135243. 13,13,13,13,11,13,13,13,13,13,13,13,13,13,13,13,
  135244. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  135245. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  135246. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  135247. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  135248. 13,13,13,13,13,13,13,13,13,13,13,13,13,12,12,12,
  135249. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  135250. 12,12,12,12,12,12,12,12,12,
  135251. };
  135252. static float _vq_quantthresh__44u5__p9_0[] = {
  135253. -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5, 382.5,
  135254. 637.5, 892.5, 1147.5, 1402.5,
  135255. };
  135256. static long _vq_quantmap__44u5__p9_0[] = {
  135257. 11, 9, 7, 5, 3, 1, 0, 2,
  135258. 4, 6, 8, 10, 12,
  135259. };
  135260. static encode_aux_threshmatch _vq_auxt__44u5__p9_0 = {
  135261. _vq_quantthresh__44u5__p9_0,
  135262. _vq_quantmap__44u5__p9_0,
  135263. 13,
  135264. 13
  135265. };
  135266. static static_codebook _44u5__p9_0 = {
  135267. 2, 169,
  135268. _vq_lengthlist__44u5__p9_0,
  135269. 1, -514332672, 1627381760, 4, 0,
  135270. _vq_quantlist__44u5__p9_0,
  135271. NULL,
  135272. &_vq_auxt__44u5__p9_0,
  135273. NULL,
  135274. 0
  135275. };
  135276. static long _vq_quantlist__44u5__p9_1[] = {
  135277. 7,
  135278. 6,
  135279. 8,
  135280. 5,
  135281. 9,
  135282. 4,
  135283. 10,
  135284. 3,
  135285. 11,
  135286. 2,
  135287. 12,
  135288. 1,
  135289. 13,
  135290. 0,
  135291. 14,
  135292. };
  135293. static long _vq_lengthlist__44u5__p9_1[] = {
  135294. 1, 4, 4, 7, 7, 8, 8, 8, 7, 8, 7, 9, 8, 9, 9, 4,
  135295. 7, 6, 9, 8,10,10, 9, 8, 9, 9, 9, 9, 9, 8, 5, 6,
  135296. 6, 8, 9,10,10, 9, 9, 9,10,10,10,10,11, 7, 8, 8,
  135297. 10,10,11,11,10,10,11,11,11,12,11,11, 7, 8, 8,10,
  135298. 10,11,11,10,10,11,11,12,11,11,11, 8, 9, 9,11,11,
  135299. 12,12,11,11,12,11,12,12,12,12, 8, 9,10,11,11,12,
  135300. 12,11,11,12,12,12,12,12,12, 8, 9, 9,10,10,12,11,
  135301. 12,12,12,12,12,12,12,13, 8, 9, 9,11,11,11,11,12,
  135302. 12,12,12,13,12,13,13, 9,10,10,11,11,12,12,12,13,
  135303. 12,13,13,13,14,13, 9,10,10,11,11,12,12,12,13,13,
  135304. 12,13,13,14,13, 9,11,10,12,11,13,12,12,13,13,13,
  135305. 13,13,13,14, 9,10,10,12,12,12,12,12,13,13,13,13,
  135306. 13,14,14,10,11,11,12,12,12,13,13,13,14,14,13,14,
  135307. 14,14,10,11,11,12,12,12,12,13,12,13,14,13,14,14,
  135308. 14,
  135309. };
  135310. static float _vq_quantthresh__44u5__p9_1[] = {
  135311. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  135312. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  135313. };
  135314. static long _vq_quantmap__44u5__p9_1[] = {
  135315. 13, 11, 9, 7, 5, 3, 1, 0,
  135316. 2, 4, 6, 8, 10, 12, 14,
  135317. };
  135318. static encode_aux_threshmatch _vq_auxt__44u5__p9_1 = {
  135319. _vq_quantthresh__44u5__p9_1,
  135320. _vq_quantmap__44u5__p9_1,
  135321. 15,
  135322. 15
  135323. };
  135324. static static_codebook _44u5__p9_1 = {
  135325. 2, 225,
  135326. _vq_lengthlist__44u5__p9_1,
  135327. 1, -522338304, 1620115456, 4, 0,
  135328. _vq_quantlist__44u5__p9_1,
  135329. NULL,
  135330. &_vq_auxt__44u5__p9_1,
  135331. NULL,
  135332. 0
  135333. };
  135334. static long _vq_quantlist__44u5__p9_2[] = {
  135335. 8,
  135336. 7,
  135337. 9,
  135338. 6,
  135339. 10,
  135340. 5,
  135341. 11,
  135342. 4,
  135343. 12,
  135344. 3,
  135345. 13,
  135346. 2,
  135347. 14,
  135348. 1,
  135349. 15,
  135350. 0,
  135351. 16,
  135352. };
  135353. static long _vq_lengthlist__44u5__p9_2[] = {
  135354. 2, 5, 5, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  135355. 9, 5, 6, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  135356. 9, 9, 5, 6, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9,
  135357. 9, 9, 9, 7, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  135358. 9, 9, 9, 9, 7, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9,
  135359. 9, 9, 9, 9, 9, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  135360. 9,10, 9,10,10,10, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9,
  135361. 9, 9,10, 9,10, 9,10, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  135362. 9,10, 9,10,10,10,10,10, 8, 9, 9, 9, 9, 9, 9,10,
  135363. 9,10, 9,10,10,10,10,10,10, 9, 9, 9, 9, 9,10, 9,
  135364. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9,
  135365. 9,10, 9,10, 9,10,10,10,10,10,10, 9, 9, 9, 9, 9,
  135366. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  135367. 9, 9,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  135368. 9,10,10, 9,10,10,10,10,10,10,10,10,10,10, 9, 9,
  135369. 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  135370. 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  135371. 9, 9, 9,10, 9,10,10,10,10,10,10,10,10,10,10,10,
  135372. 10,
  135373. };
  135374. static float _vq_quantthresh__44u5__p9_2[] = {
  135375. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  135376. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  135377. };
  135378. static long _vq_quantmap__44u5__p9_2[] = {
  135379. 15, 13, 11, 9, 7, 5, 3, 1,
  135380. 0, 2, 4, 6, 8, 10, 12, 14,
  135381. 16,
  135382. };
  135383. static encode_aux_threshmatch _vq_auxt__44u5__p9_2 = {
  135384. _vq_quantthresh__44u5__p9_2,
  135385. _vq_quantmap__44u5__p9_2,
  135386. 17,
  135387. 17
  135388. };
  135389. static static_codebook _44u5__p9_2 = {
  135390. 2, 289,
  135391. _vq_lengthlist__44u5__p9_2,
  135392. 1, -529530880, 1611661312, 5, 0,
  135393. _vq_quantlist__44u5__p9_2,
  135394. NULL,
  135395. &_vq_auxt__44u5__p9_2,
  135396. NULL,
  135397. 0
  135398. };
  135399. static long _huff_lengthlist__44u5__short[] = {
  135400. 4,10,17,13,17,13,17,17,17,17, 3, 6, 8, 9,11, 9,
  135401. 15,12,16,17, 6, 5, 5, 7, 7, 8,10,11,17,17, 7, 8,
  135402. 7, 9, 9,10,13,13,17,17, 8, 6, 5, 7, 4, 7, 5, 8,
  135403. 14,17, 9, 9, 8, 9, 7, 9, 8,10,16,17,12,10, 7, 8,
  135404. 4, 7, 4, 7,16,17,12,11, 9,10, 6, 9, 5, 7,14,17,
  135405. 14,13,10,15, 4, 8, 3, 5,14,17,17,14,11,15, 6,10,
  135406. 6, 8,15,17,
  135407. };
  135408. static static_codebook _huff_book__44u5__short = {
  135409. 2, 100,
  135410. _huff_lengthlist__44u5__short,
  135411. 0, 0, 0, 0, 0,
  135412. NULL,
  135413. NULL,
  135414. NULL,
  135415. NULL,
  135416. 0
  135417. };
  135418. static long _huff_lengthlist__44u6__long[] = {
  135419. 3, 9,14,13,14,13,16,12,13,14, 5, 4, 6, 6, 8, 9,
  135420. 11,10,12,15,10, 5, 5, 6, 6, 8,10,10,13,16,10, 6,
  135421. 6, 6, 6, 8, 9, 9,12,14,13, 7, 6, 6, 4, 6, 6, 7,
  135422. 11,14,10, 7, 7, 7, 6, 6, 6, 7,10,13,15,10, 9, 8,
  135423. 5, 6, 5, 6,10,14,10, 9, 8, 8, 6, 6, 5, 4, 6,11,
  135424. 11,11,12,11,10, 9, 9, 5, 5, 9,10,12,15,13,13,13,
  135425. 13, 8, 7, 7,
  135426. };
  135427. static static_codebook _huff_book__44u6__long = {
  135428. 2, 100,
  135429. _huff_lengthlist__44u6__long,
  135430. 0, 0, 0, 0, 0,
  135431. NULL,
  135432. NULL,
  135433. NULL,
  135434. NULL,
  135435. 0
  135436. };
  135437. static long _vq_quantlist__44u6__p1_0[] = {
  135438. 1,
  135439. 0,
  135440. 2,
  135441. };
  135442. static long _vq_lengthlist__44u6__p1_0[] = {
  135443. 1, 4, 4, 4, 8, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  135444. 9,10, 5, 8, 8, 7,10, 9, 8,10,10, 5, 8, 8, 8,10,
  135445. 10, 8,10,10, 8,10,10,10,12,13,10,13,13, 7,10,10,
  135446. 10,13,11,10,13,13, 5, 8, 8, 8,11,10, 8,10,10, 7,
  135447. 10,10,10,13,13,10,11,13, 8,10,11,10,13,13,10,13,
  135448. 12,
  135449. };
  135450. static float _vq_quantthresh__44u6__p1_0[] = {
  135451. -0.5, 0.5,
  135452. };
  135453. static long _vq_quantmap__44u6__p1_0[] = {
  135454. 1, 0, 2,
  135455. };
  135456. static encode_aux_threshmatch _vq_auxt__44u6__p1_0 = {
  135457. _vq_quantthresh__44u6__p1_0,
  135458. _vq_quantmap__44u6__p1_0,
  135459. 3,
  135460. 3
  135461. };
  135462. static static_codebook _44u6__p1_0 = {
  135463. 4, 81,
  135464. _vq_lengthlist__44u6__p1_0,
  135465. 1, -535822336, 1611661312, 2, 0,
  135466. _vq_quantlist__44u6__p1_0,
  135467. NULL,
  135468. &_vq_auxt__44u6__p1_0,
  135469. NULL,
  135470. 0
  135471. };
  135472. static long _vq_quantlist__44u6__p2_0[] = {
  135473. 1,
  135474. 0,
  135475. 2,
  135476. };
  135477. static long _vq_lengthlist__44u6__p2_0[] = {
  135478. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 8, 8, 6,
  135479. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 8, 5, 6, 6, 6, 8,
  135480. 8, 6, 8, 8, 6, 8, 8, 8, 9, 9, 8, 9, 9, 6, 7, 7,
  135481. 7, 9, 8, 8, 9, 9, 5, 6, 6, 6, 8, 7, 6, 8, 8, 6,
  135482. 8, 8, 8, 9, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 8, 9,
  135483. 9,
  135484. };
  135485. static float _vq_quantthresh__44u6__p2_0[] = {
  135486. -0.5, 0.5,
  135487. };
  135488. static long _vq_quantmap__44u6__p2_0[] = {
  135489. 1, 0, 2,
  135490. };
  135491. static encode_aux_threshmatch _vq_auxt__44u6__p2_0 = {
  135492. _vq_quantthresh__44u6__p2_0,
  135493. _vq_quantmap__44u6__p2_0,
  135494. 3,
  135495. 3
  135496. };
  135497. static static_codebook _44u6__p2_0 = {
  135498. 4, 81,
  135499. _vq_lengthlist__44u6__p2_0,
  135500. 1, -535822336, 1611661312, 2, 0,
  135501. _vq_quantlist__44u6__p2_0,
  135502. NULL,
  135503. &_vq_auxt__44u6__p2_0,
  135504. NULL,
  135505. 0
  135506. };
  135507. static long _vq_quantlist__44u6__p3_0[] = {
  135508. 2,
  135509. 1,
  135510. 3,
  135511. 0,
  135512. 4,
  135513. };
  135514. static long _vq_lengthlist__44u6__p3_0[] = {
  135515. 2, 5, 4, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  135516. 9, 9,13,12, 8, 9,10,12,13, 5, 7, 7,10, 9, 7, 9,
  135517. 9,11,11, 7, 8, 9,11,11,10,11,11,14,14, 9,10,11,
  135518. 13,14, 5, 7, 7, 9,10, 6, 9, 8,11,11, 7, 9, 9,11,
  135519. 11, 9,11,10,14,13,10,11,11,14,13, 8,10,10,13,13,
  135520. 10,11,11,15,15, 9,11,11,14,14,13,14,14,17,16,12,
  135521. 13,14,16,16, 8,10,10,13,14, 9,11,11,14,15,10,11,
  135522. 12,14,15,12,14,13,16,15,13,14,14,15,17, 5, 7, 7,
  135523. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,11,10,12,11,14,
  135524. 14,10,11,11,14,14, 7, 9, 9,12,11, 9,11,11,13,13,
  135525. 9,11,11,13,13,11,13,13,14,15,11,12,13,15,16, 6,
  135526. 9, 9,11,12, 8,11,10,13,12, 9,11,11,13,14,11,13,
  135527. 12,16,14,11,13,13,15,16,10,12,11,14,15,11,13,13,
  135528. 15,17,11,13,13,17,16,15,15,16,17,16,14,15,16,18,
  135529. 0, 9,11,11,14,15,10,12,12,16,15,11,13,13,16,16,
  135530. 13,15,14,18,15,14,16,16, 0, 0, 5, 7, 7,10,10, 7,
  135531. 9, 9,11,11, 7, 9, 9,11,11,10,11,11,14,14,10,11,
  135532. 12,14,14, 6, 9, 9,11,11, 9,11,11,13,13, 8,10,11,
  135533. 12,13,11,13,13,16,15,11,12,13,14,16, 7, 9, 9,11,
  135534. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,13,16,15,
  135535. 11,13,12,15,15, 9,11,11,15,14,11,13,13,17,16,10,
  135536. 12,13,15,16,14,16,16, 0,18,14,14,15,15,17,10,11,
  135537. 12,15,15,11,13,13,16,16,11,13,13,16,16,14,16,16,
  135538. 19,17,14,15,15,17,17, 8,10,10,14,14,10,12,11,15,
  135539. 15,10,11,12,16,15,14,15,15,18,20,13,14,16,17,18,
  135540. 9,11,11,15,16,11,13,13,17,17,11,13,13,17,16,15,
  135541. 16,16, 0, 0,15,16,16, 0, 0, 9,11,11,15,15,10,13,
  135542. 12,17,15,11,13,13,17,16,15,17,15,20,19,15,16,16,
  135543. 19, 0,13,15,14, 0,17,14,15,16, 0,20,15,16,16, 0,
  135544. 19,17,18, 0, 0, 0,16,17,18, 0, 0,12,14,14,19,18,
  135545. 13,15,14, 0,17,14,15,16,19,19,16,18,16, 0,19,19,
  135546. 20,17,20, 0, 8,10,10,13,14,10,11,11,15,15,10,12,
  135547. 12,15,16,14,15,14,19,16,14,15,15, 0,18, 9,11,11,
  135548. 16,15,11,13,13, 0,16,11,12,13,16,17,14,16,17, 0,
  135549. 19,15,16,16,18, 0, 9,11,11,15,16,11,13,13,16,16,
  135550. 11,14,13,18,17,15,16,16,18,20,15,17,19, 0, 0,12,
  135551. 14,14,17,17,14,16,15, 0, 0,13,14,15,19, 0,16,18,
  135552. 20, 0, 0,16,16,18,18, 0,12,14,14,17,20,14,16,16,
  135553. 19, 0,14,16,14, 0,20,16,20,17, 0, 0,17, 0,15, 0,
  135554. 19,
  135555. };
  135556. static float _vq_quantthresh__44u6__p3_0[] = {
  135557. -1.5, -0.5, 0.5, 1.5,
  135558. };
  135559. static long _vq_quantmap__44u6__p3_0[] = {
  135560. 3, 1, 0, 2, 4,
  135561. };
  135562. static encode_aux_threshmatch _vq_auxt__44u6__p3_0 = {
  135563. _vq_quantthresh__44u6__p3_0,
  135564. _vq_quantmap__44u6__p3_0,
  135565. 5,
  135566. 5
  135567. };
  135568. static static_codebook _44u6__p3_0 = {
  135569. 4, 625,
  135570. _vq_lengthlist__44u6__p3_0,
  135571. 1, -533725184, 1611661312, 3, 0,
  135572. _vq_quantlist__44u6__p3_0,
  135573. NULL,
  135574. &_vq_auxt__44u6__p3_0,
  135575. NULL,
  135576. 0
  135577. };
  135578. static long _vq_quantlist__44u6__p4_0[] = {
  135579. 2,
  135580. 1,
  135581. 3,
  135582. 0,
  135583. 4,
  135584. };
  135585. static long _vq_lengthlist__44u6__p4_0[] = {
  135586. 4, 5, 5, 8, 8, 6, 7, 6, 9, 9, 6, 6, 7, 9, 9, 8,
  135587. 9, 9,11,11, 8, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 8,
  135588. 8,10,10, 7, 7, 8, 9,10, 9,10,10,11,11, 9, 9,10,
  135589. 11,12, 6, 7, 7, 9, 9, 7, 8, 7,10, 9, 7, 8, 8,10,
  135590. 10, 9,10, 9,12,11, 9,10,10,12,11, 8, 9, 9,11,11,
  135591. 9,10,10,12,12, 9,10,10,12,12,11,12,12,14,13,11,
  135592. 11,12,13,13, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  135593. 10,12,12,11,12,11,13,12,11,12,12,13,13, 5, 7, 7,
  135594. 9, 9, 7, 8, 7,10,10, 7, 7, 8,10,10, 9,10,10,12,
  135595. 11, 9,10,10,11,12, 7, 8, 8,10,10, 8, 8, 9,11,11,
  135596. 8, 9, 9,11,11,10,10,11,12,13,10,10,11,12,12, 6,
  135597. 7, 7,10,10, 7, 9, 8,11,10, 8, 8, 9,10,11,10,11,
  135598. 10,13,11,10,11,11,12,12, 9,10,10,12,12,10,10,11,
  135599. 13,13,10,11,11,12,13,12,12,12,13,14,12,12,13,14,
  135600. 14, 9,10,10,12,12, 9,10,10,13,12,10,11,11,13,13,
  135601. 11,12,11,14,12,12,13,13,14,14, 6, 7, 7, 9, 9, 7,
  135602. 8, 7,10,10, 7, 8, 8,10,10, 9,10,10,12,11, 9,10,
  135603. 10,11,12, 6, 7, 7,10,10, 8, 9, 8,11,10, 7, 8, 9,
  135604. 10,11,10,11,11,12,12,10,10,11,11,13, 7, 8, 8,10,
  135605. 10, 8, 9, 9,11,11, 8, 9, 8,11,11,10,11,10,13,12,
  135606. 10,11,11,13,12, 9,10,10,12,12,10,11,11,13,12, 9,
  135607. 10,10,12,13,12,13,12,14,14,11,11,12,12,14, 9,10,
  135608. 10,12,12,10,11,11,13,13,10,11,10,13,12,12,12,12,
  135609. 14,14,12,13,12,14,13, 8, 9, 9,11,11, 9,10,10,12,
  135610. 12, 9,10,10,12,12,11,12,12,14,13,11,12,12,13,14,
  135611. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,13,12,
  135612. 12,13,14,15,12,12,13,14,14, 9,10,10,12,12, 9,11,
  135613. 10,13,12,10,10,11,12,13,12,13,12,14,13,12,12,13,
  135614. 14,15,11,12,12,14,13,11,12,12,14,14,12,13,13,14,
  135615. 14,13,13,14,14,16,13,14,14,15,15,11,12,11,13,13,
  135616. 11,12,11,14,13,12,12,13,14,15,12,14,12,15,12,13,
  135617. 14,15,15,16, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  135618. 10,12,12,11,12,12,14,13,11,12,12,13,13, 9,10,10,
  135619. 12,12,10,11,10,13,12, 9,10,11,12,13,12,13,12,14,
  135620. 14,12,12,13,13,14, 9,10,10,12,12,10,11,11,13,13,
  135621. 10,11,11,13,13,12,13,12,14,14,12,13,13,14,14,11,
  135622. 11,11,13,13,12,13,12,14,14,11,11,12,13,14,14,14,
  135623. 14,16,15,12,12,14,12,15,11,12,12,13,14,12,13,13,
  135624. 14,15,11,12,12,14,14,13,14,14,16,16,13,14,13,16,
  135625. 13,
  135626. };
  135627. static float _vq_quantthresh__44u6__p4_0[] = {
  135628. -1.5, -0.5, 0.5, 1.5,
  135629. };
  135630. static long _vq_quantmap__44u6__p4_0[] = {
  135631. 3, 1, 0, 2, 4,
  135632. };
  135633. static encode_aux_threshmatch _vq_auxt__44u6__p4_0 = {
  135634. _vq_quantthresh__44u6__p4_0,
  135635. _vq_quantmap__44u6__p4_0,
  135636. 5,
  135637. 5
  135638. };
  135639. static static_codebook _44u6__p4_0 = {
  135640. 4, 625,
  135641. _vq_lengthlist__44u6__p4_0,
  135642. 1, -533725184, 1611661312, 3, 0,
  135643. _vq_quantlist__44u6__p4_0,
  135644. NULL,
  135645. &_vq_auxt__44u6__p4_0,
  135646. NULL,
  135647. 0
  135648. };
  135649. static long _vq_quantlist__44u6__p5_0[] = {
  135650. 4,
  135651. 3,
  135652. 5,
  135653. 2,
  135654. 6,
  135655. 1,
  135656. 7,
  135657. 0,
  135658. 8,
  135659. };
  135660. static long _vq_lengthlist__44u6__p5_0[] = {
  135661. 2, 3, 3, 6, 6, 8, 8,10,10, 4, 5, 5, 8, 7, 8, 8,
  135662. 11,11, 3, 5, 5, 7, 8, 8, 8,11,11, 6, 8, 7, 9, 9,
  135663. 10, 9,12,11, 6, 7, 8, 9, 9, 9,10,11,12, 8, 8, 8,
  135664. 10, 9,12,11,13,13, 8, 8, 9, 9,10,11,12,13,13,10,
  135665. 11,11,12,12,13,13,14,14,10,10,11,11,12,13,13,14,
  135666. 14,
  135667. };
  135668. static float _vq_quantthresh__44u6__p5_0[] = {
  135669. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135670. };
  135671. static long _vq_quantmap__44u6__p5_0[] = {
  135672. 7, 5, 3, 1, 0, 2, 4, 6,
  135673. 8,
  135674. };
  135675. static encode_aux_threshmatch _vq_auxt__44u6__p5_0 = {
  135676. _vq_quantthresh__44u6__p5_0,
  135677. _vq_quantmap__44u6__p5_0,
  135678. 9,
  135679. 9
  135680. };
  135681. static static_codebook _44u6__p5_0 = {
  135682. 2, 81,
  135683. _vq_lengthlist__44u6__p5_0,
  135684. 1, -531628032, 1611661312, 4, 0,
  135685. _vq_quantlist__44u6__p5_0,
  135686. NULL,
  135687. &_vq_auxt__44u6__p5_0,
  135688. NULL,
  135689. 0
  135690. };
  135691. static long _vq_quantlist__44u6__p6_0[] = {
  135692. 4,
  135693. 3,
  135694. 5,
  135695. 2,
  135696. 6,
  135697. 1,
  135698. 7,
  135699. 0,
  135700. 8,
  135701. };
  135702. static long _vq_lengthlist__44u6__p6_0[] = {
  135703. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 7, 7,
  135704. 9, 9, 4, 4, 5, 6, 6, 7, 8, 9, 9, 5, 6, 6, 7, 7,
  135705. 8, 8,10,10, 5, 6, 6, 7, 7, 8, 8,10,10, 7, 8, 7,
  135706. 8, 8,10, 9,11,11, 7, 7, 8, 8, 8, 9,10,10,11, 9,
  135707. 9, 9,10,10,11,11,12,11, 9, 9, 9,10,10,11,11,11,
  135708. 12,
  135709. };
  135710. static float _vq_quantthresh__44u6__p6_0[] = {
  135711. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135712. };
  135713. static long _vq_quantmap__44u6__p6_0[] = {
  135714. 7, 5, 3, 1, 0, 2, 4, 6,
  135715. 8,
  135716. };
  135717. static encode_aux_threshmatch _vq_auxt__44u6__p6_0 = {
  135718. _vq_quantthresh__44u6__p6_0,
  135719. _vq_quantmap__44u6__p6_0,
  135720. 9,
  135721. 9
  135722. };
  135723. static static_codebook _44u6__p6_0 = {
  135724. 2, 81,
  135725. _vq_lengthlist__44u6__p6_0,
  135726. 1, -531628032, 1611661312, 4, 0,
  135727. _vq_quantlist__44u6__p6_0,
  135728. NULL,
  135729. &_vq_auxt__44u6__p6_0,
  135730. NULL,
  135731. 0
  135732. };
  135733. static long _vq_quantlist__44u6__p7_0[] = {
  135734. 1,
  135735. 0,
  135736. 2,
  135737. };
  135738. static long _vq_lengthlist__44u6__p7_0[] = {
  135739. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 8, 7,10,10, 8,
  135740. 10,10, 5, 8, 9, 7,10,10, 7,10, 9, 4, 8, 8, 9,11,
  135741. 11, 8,11,11, 7,11,11,10,10,13,10,13,13, 7,11,11,
  135742. 10,13,12,10,13,13, 5, 9, 8, 8,11,11, 9,11,11, 7,
  135743. 11,11,10,13,13,10,12,13, 7,11,11,10,13,13, 9,13,
  135744. 10,
  135745. };
  135746. static float _vq_quantthresh__44u6__p7_0[] = {
  135747. -5.5, 5.5,
  135748. };
  135749. static long _vq_quantmap__44u6__p7_0[] = {
  135750. 1, 0, 2,
  135751. };
  135752. static encode_aux_threshmatch _vq_auxt__44u6__p7_0 = {
  135753. _vq_quantthresh__44u6__p7_0,
  135754. _vq_quantmap__44u6__p7_0,
  135755. 3,
  135756. 3
  135757. };
  135758. static static_codebook _44u6__p7_0 = {
  135759. 4, 81,
  135760. _vq_lengthlist__44u6__p7_0,
  135761. 1, -529137664, 1618345984, 2, 0,
  135762. _vq_quantlist__44u6__p7_0,
  135763. NULL,
  135764. &_vq_auxt__44u6__p7_0,
  135765. NULL,
  135766. 0
  135767. };
  135768. static long _vq_quantlist__44u6__p7_1[] = {
  135769. 5,
  135770. 4,
  135771. 6,
  135772. 3,
  135773. 7,
  135774. 2,
  135775. 8,
  135776. 1,
  135777. 9,
  135778. 0,
  135779. 10,
  135780. };
  135781. static long _vq_lengthlist__44u6__p7_1[] = {
  135782. 3, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 7, 6,
  135783. 8, 8, 8, 8, 8, 8, 4, 5, 5, 6, 7, 8, 8, 8, 8, 8,
  135784. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7,
  135785. 7, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 9, 9,
  135786. 9, 9, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8,
  135787. 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9,
  135788. 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8,
  135789. 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135790. };
  135791. static float _vq_quantthresh__44u6__p7_1[] = {
  135792. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135793. 3.5, 4.5,
  135794. };
  135795. static long _vq_quantmap__44u6__p7_1[] = {
  135796. 9, 7, 5, 3, 1, 0, 2, 4,
  135797. 6, 8, 10,
  135798. };
  135799. static encode_aux_threshmatch _vq_auxt__44u6__p7_1 = {
  135800. _vq_quantthresh__44u6__p7_1,
  135801. _vq_quantmap__44u6__p7_1,
  135802. 11,
  135803. 11
  135804. };
  135805. static static_codebook _44u6__p7_1 = {
  135806. 2, 121,
  135807. _vq_lengthlist__44u6__p7_1,
  135808. 1, -531365888, 1611661312, 4, 0,
  135809. _vq_quantlist__44u6__p7_1,
  135810. NULL,
  135811. &_vq_auxt__44u6__p7_1,
  135812. NULL,
  135813. 0
  135814. };
  135815. static long _vq_quantlist__44u6__p8_0[] = {
  135816. 5,
  135817. 4,
  135818. 6,
  135819. 3,
  135820. 7,
  135821. 2,
  135822. 8,
  135823. 1,
  135824. 9,
  135825. 0,
  135826. 10,
  135827. };
  135828. static long _vq_lengthlist__44u6__p8_0[] = {
  135829. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,10, 4, 6, 6, 7, 7,
  135830. 9, 9,10,10,11,11, 4, 6, 6, 7, 7, 9, 9,10,10,11,
  135831. 11, 6, 8, 8, 9, 9,10,10,11,11,12,12, 6, 8, 8, 9,
  135832. 9,10,10,11,11,12,12, 8, 9, 9,10,10,11,11,12,12,
  135833. 13,13, 8, 9, 9,10,10,11,11,12,12,13,13,10,10,10,
  135834. 11,11,13,13,13,13,15,14, 9,10,10,12,11,12,13,13,
  135835. 13,14,15,11,12,12,13,13,13,13,15,14,15,15,11,11,
  135836. 12,13,13,14,14,14,15,15,15,
  135837. };
  135838. static float _vq_quantthresh__44u6__p8_0[] = {
  135839. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  135840. 38.5, 49.5,
  135841. };
  135842. static long _vq_quantmap__44u6__p8_0[] = {
  135843. 9, 7, 5, 3, 1, 0, 2, 4,
  135844. 6, 8, 10,
  135845. };
  135846. static encode_aux_threshmatch _vq_auxt__44u6__p8_0 = {
  135847. _vq_quantthresh__44u6__p8_0,
  135848. _vq_quantmap__44u6__p8_0,
  135849. 11,
  135850. 11
  135851. };
  135852. static static_codebook _44u6__p8_0 = {
  135853. 2, 121,
  135854. _vq_lengthlist__44u6__p8_0,
  135855. 1, -524582912, 1618345984, 4, 0,
  135856. _vq_quantlist__44u6__p8_0,
  135857. NULL,
  135858. &_vq_auxt__44u6__p8_0,
  135859. NULL,
  135860. 0
  135861. };
  135862. static long _vq_quantlist__44u6__p8_1[] = {
  135863. 5,
  135864. 4,
  135865. 6,
  135866. 3,
  135867. 7,
  135868. 2,
  135869. 8,
  135870. 1,
  135871. 9,
  135872. 0,
  135873. 10,
  135874. };
  135875. static long _vq_lengthlist__44u6__p8_1[] = {
  135876. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 5, 7, 7,
  135877. 7, 7, 8, 7, 8, 8, 5, 5, 6, 6, 7, 7, 7, 7, 7, 8,
  135878. 8, 6, 7, 7, 7, 7, 8, 7, 8, 8, 8, 8, 6, 6, 7, 7,
  135879. 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8,
  135880. 8, 8, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7,
  135881. 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8,
  135882. 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8,
  135883. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  135884. };
  135885. static float _vq_quantthresh__44u6__p8_1[] = {
  135886. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135887. 3.5, 4.5,
  135888. };
  135889. static long _vq_quantmap__44u6__p8_1[] = {
  135890. 9, 7, 5, 3, 1, 0, 2, 4,
  135891. 6, 8, 10,
  135892. };
  135893. static encode_aux_threshmatch _vq_auxt__44u6__p8_1 = {
  135894. _vq_quantthresh__44u6__p8_1,
  135895. _vq_quantmap__44u6__p8_1,
  135896. 11,
  135897. 11
  135898. };
  135899. static static_codebook _44u6__p8_1 = {
  135900. 2, 121,
  135901. _vq_lengthlist__44u6__p8_1,
  135902. 1, -531365888, 1611661312, 4, 0,
  135903. _vq_quantlist__44u6__p8_1,
  135904. NULL,
  135905. &_vq_auxt__44u6__p8_1,
  135906. NULL,
  135907. 0
  135908. };
  135909. static long _vq_quantlist__44u6__p9_0[] = {
  135910. 7,
  135911. 6,
  135912. 8,
  135913. 5,
  135914. 9,
  135915. 4,
  135916. 10,
  135917. 3,
  135918. 11,
  135919. 2,
  135920. 12,
  135921. 1,
  135922. 13,
  135923. 0,
  135924. 14,
  135925. };
  135926. static long _vq_lengthlist__44u6__p9_0[] = {
  135927. 1, 3, 2, 9, 8,15,15,15,15,15,15,15,15,15,15, 4,
  135928. 8, 9,13,14,14,14,14,14,14,14,14,14,14,14, 5, 8,
  135929. 9,14,14,14,14,14,14,14,14,14,14,14,14,11,14,14,
  135930. 14,14,14,14,14,14,14,14,14,14,14,14,11,14,14,14,
  135931. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135932. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135933. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135934. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135935. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135936. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135937. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135938. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135939. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135940. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135941. 14,
  135942. };
  135943. static float _vq_quantthresh__44u6__p9_0[] = {
  135944. -1657.5, -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5,
  135945. 382.5, 637.5, 892.5, 1147.5, 1402.5, 1657.5,
  135946. };
  135947. static long _vq_quantmap__44u6__p9_0[] = {
  135948. 13, 11, 9, 7, 5, 3, 1, 0,
  135949. 2, 4, 6, 8, 10, 12, 14,
  135950. };
  135951. static encode_aux_threshmatch _vq_auxt__44u6__p9_0 = {
  135952. _vq_quantthresh__44u6__p9_0,
  135953. _vq_quantmap__44u6__p9_0,
  135954. 15,
  135955. 15
  135956. };
  135957. static static_codebook _44u6__p9_0 = {
  135958. 2, 225,
  135959. _vq_lengthlist__44u6__p9_0,
  135960. 1, -514071552, 1627381760, 4, 0,
  135961. _vq_quantlist__44u6__p9_0,
  135962. NULL,
  135963. &_vq_auxt__44u6__p9_0,
  135964. NULL,
  135965. 0
  135966. };
  135967. static long _vq_quantlist__44u6__p9_1[] = {
  135968. 7,
  135969. 6,
  135970. 8,
  135971. 5,
  135972. 9,
  135973. 4,
  135974. 10,
  135975. 3,
  135976. 11,
  135977. 2,
  135978. 12,
  135979. 1,
  135980. 13,
  135981. 0,
  135982. 14,
  135983. };
  135984. static long _vq_lengthlist__44u6__p9_1[] = {
  135985. 1, 4, 4, 7, 7, 8, 9, 8, 8, 9, 8, 9, 8, 9, 9, 4,
  135986. 7, 6, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 4, 7,
  135987. 6, 9, 9,10,10, 9, 9,10,10,10,10,11,11, 7, 9, 8,
  135988. 10,10,11,11,10,10,11,11,11,11,11,11, 7, 8, 9,10,
  135989. 10,11,11,10,10,11,11,11,11,11,12, 8,10,10,11,11,
  135990. 12,12,11,11,12,12,12,12,13,12, 8,10,10,11,11,12,
  135991. 11,11,11,11,12,12,12,12,13, 8, 9, 9,11,10,11,11,
  135992. 12,12,12,12,13,12,13,12, 8, 9, 9,11,11,11,11,12,
  135993. 12,12,12,12,13,13,13, 9,10,10,11,12,12,12,12,12,
  135994. 13,13,13,13,13,13, 9,10,10,11,11,12,12,12,12,13,
  135995. 13,13,13,14,13,10,10,10,12,11,12,12,13,13,13,13,
  135996. 13,13,13,13,10,10,11,11,11,12,12,13,13,13,13,13,
  135997. 13,13,13,10,11,11,12,12,13,12,12,13,13,13,13,13,
  135998. 13,14,10,11,11,12,12,13,12,13,13,13,14,13,13,14,
  135999. 13,
  136000. };
  136001. static float _vq_quantthresh__44u6__p9_1[] = {
  136002. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  136003. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  136004. };
  136005. static long _vq_quantmap__44u6__p9_1[] = {
  136006. 13, 11, 9, 7, 5, 3, 1, 0,
  136007. 2, 4, 6, 8, 10, 12, 14,
  136008. };
  136009. static encode_aux_threshmatch _vq_auxt__44u6__p9_1 = {
  136010. _vq_quantthresh__44u6__p9_1,
  136011. _vq_quantmap__44u6__p9_1,
  136012. 15,
  136013. 15
  136014. };
  136015. static static_codebook _44u6__p9_1 = {
  136016. 2, 225,
  136017. _vq_lengthlist__44u6__p9_1,
  136018. 1, -522338304, 1620115456, 4, 0,
  136019. _vq_quantlist__44u6__p9_1,
  136020. NULL,
  136021. &_vq_auxt__44u6__p9_1,
  136022. NULL,
  136023. 0
  136024. };
  136025. static long _vq_quantlist__44u6__p9_2[] = {
  136026. 8,
  136027. 7,
  136028. 9,
  136029. 6,
  136030. 10,
  136031. 5,
  136032. 11,
  136033. 4,
  136034. 12,
  136035. 3,
  136036. 13,
  136037. 2,
  136038. 14,
  136039. 1,
  136040. 15,
  136041. 0,
  136042. 16,
  136043. };
  136044. static long _vq_lengthlist__44u6__p9_2[] = {
  136045. 3, 5, 5, 7, 7, 8, 8, 8, 8, 8, 8, 9, 8, 8, 9, 9,
  136046. 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,
  136047. 9, 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9,
  136048. 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  136049. 9, 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  136050. 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  136051. 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  136052. 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  136053. 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9,
  136054. 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9, 9, 9, 9, 9,
  136055. 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 8, 9, 9, 9, 9, 9,
  136056. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  136057. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9, 9, 9, 9, 9,
  136058. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,
  136059. 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,10, 9, 9, 9,
  136060. 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,10, 9, 9,10, 9,
  136061. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9,10, 9,10,10,
  136062. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,10,10, 9, 9,
  136063. 10,
  136064. };
  136065. static float _vq_quantthresh__44u6__p9_2[] = {
  136066. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  136067. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  136068. };
  136069. static long _vq_quantmap__44u6__p9_2[] = {
  136070. 15, 13, 11, 9, 7, 5, 3, 1,
  136071. 0, 2, 4, 6, 8, 10, 12, 14,
  136072. 16,
  136073. };
  136074. static encode_aux_threshmatch _vq_auxt__44u6__p9_2 = {
  136075. _vq_quantthresh__44u6__p9_2,
  136076. _vq_quantmap__44u6__p9_2,
  136077. 17,
  136078. 17
  136079. };
  136080. static static_codebook _44u6__p9_2 = {
  136081. 2, 289,
  136082. _vq_lengthlist__44u6__p9_2,
  136083. 1, -529530880, 1611661312, 5, 0,
  136084. _vq_quantlist__44u6__p9_2,
  136085. NULL,
  136086. &_vq_auxt__44u6__p9_2,
  136087. NULL,
  136088. 0
  136089. };
  136090. static long _huff_lengthlist__44u6__short[] = {
  136091. 4,11,16,13,17,13,17,16,17,17, 4, 7, 9, 9,13,10,
  136092. 16,12,16,17, 7, 6, 5, 7, 8, 9,12,12,16,17, 6, 9,
  136093. 7, 9,10,10,15,15,17,17, 6, 7, 5, 7, 5, 7, 7,10,
  136094. 16,17, 7, 9, 8, 9, 8,10,11,11,15,17, 7, 7, 7, 8,
  136095. 5, 8, 8, 9,15,17, 8, 7, 9, 9, 7, 8, 7, 2, 7,15,
  136096. 14,13,13,15, 5,10, 4, 3, 6,17,17,15,13,17, 7,11,
  136097. 7, 6, 9,16,
  136098. };
  136099. static static_codebook _huff_book__44u6__short = {
  136100. 2, 100,
  136101. _huff_lengthlist__44u6__short,
  136102. 0, 0, 0, 0, 0,
  136103. NULL,
  136104. NULL,
  136105. NULL,
  136106. NULL,
  136107. 0
  136108. };
  136109. static long _huff_lengthlist__44u7__long[] = {
  136110. 3, 9,14,13,15,14,16,13,13,14, 5, 5, 7, 7, 8, 9,
  136111. 11,10,12,15,10, 6, 5, 6, 6, 9,10,10,13,16,10, 6,
  136112. 6, 6, 6, 8, 9, 9,12,15,14, 7, 6, 6, 5, 6, 6, 8,
  136113. 12,15,10, 8, 7, 7, 6, 7, 7, 7,11,13,14,10, 9, 8,
  136114. 5, 6, 4, 5, 9,12,10, 9, 9, 8, 6, 6, 5, 3, 6,11,
  136115. 12,11,12,12,10, 9, 8, 5, 5, 8,10,11,15,13,13,13,
  136116. 12, 8, 6, 7,
  136117. };
  136118. static static_codebook _huff_book__44u7__long = {
  136119. 2, 100,
  136120. _huff_lengthlist__44u7__long,
  136121. 0, 0, 0, 0, 0,
  136122. NULL,
  136123. NULL,
  136124. NULL,
  136125. NULL,
  136126. 0
  136127. };
  136128. static long _vq_quantlist__44u7__p1_0[] = {
  136129. 1,
  136130. 0,
  136131. 2,
  136132. };
  136133. static long _vq_lengthlist__44u7__p1_0[] = {
  136134. 1, 4, 4, 4, 7, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  136135. 10,10, 5, 8, 8, 7,10,10, 8,10,10, 5, 8, 8, 8,11,
  136136. 10, 8,10,10, 8,10,10,10,12,13,10,13,13, 7,10,10,
  136137. 10,13,12,10,13,13, 5, 8, 8, 8,11,10, 8,10,11, 7,
  136138. 10,10,10,13,13,10,12,13, 8,11,11,10,13,13,10,13,
  136139. 12,
  136140. };
  136141. static float _vq_quantthresh__44u7__p1_0[] = {
  136142. -0.5, 0.5,
  136143. };
  136144. static long _vq_quantmap__44u7__p1_0[] = {
  136145. 1, 0, 2,
  136146. };
  136147. static encode_aux_threshmatch _vq_auxt__44u7__p1_0 = {
  136148. _vq_quantthresh__44u7__p1_0,
  136149. _vq_quantmap__44u7__p1_0,
  136150. 3,
  136151. 3
  136152. };
  136153. static static_codebook _44u7__p1_0 = {
  136154. 4, 81,
  136155. _vq_lengthlist__44u7__p1_0,
  136156. 1, -535822336, 1611661312, 2, 0,
  136157. _vq_quantlist__44u7__p1_0,
  136158. NULL,
  136159. &_vq_auxt__44u7__p1_0,
  136160. NULL,
  136161. 0
  136162. };
  136163. static long _vq_quantlist__44u7__p2_0[] = {
  136164. 1,
  136165. 0,
  136166. 2,
  136167. };
  136168. static long _vq_lengthlist__44u7__p2_0[] = {
  136169. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 8, 8, 6,
  136170. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 8, 5, 6, 6, 6, 8,
  136171. 7, 6, 8, 8, 6, 8, 8, 8, 9, 9, 8, 9, 9, 6, 8, 7,
  136172. 7, 9, 8, 8, 9, 9, 5, 6, 6, 6, 8, 7, 6, 8, 8, 6,
  136173. 8, 8, 8, 9, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 8, 9,
  136174. 9,
  136175. };
  136176. static float _vq_quantthresh__44u7__p2_0[] = {
  136177. -0.5, 0.5,
  136178. };
  136179. static long _vq_quantmap__44u7__p2_0[] = {
  136180. 1, 0, 2,
  136181. };
  136182. static encode_aux_threshmatch _vq_auxt__44u7__p2_0 = {
  136183. _vq_quantthresh__44u7__p2_0,
  136184. _vq_quantmap__44u7__p2_0,
  136185. 3,
  136186. 3
  136187. };
  136188. static static_codebook _44u7__p2_0 = {
  136189. 4, 81,
  136190. _vq_lengthlist__44u7__p2_0,
  136191. 1, -535822336, 1611661312, 2, 0,
  136192. _vq_quantlist__44u7__p2_0,
  136193. NULL,
  136194. &_vq_auxt__44u7__p2_0,
  136195. NULL,
  136196. 0
  136197. };
  136198. static long _vq_quantlist__44u7__p3_0[] = {
  136199. 2,
  136200. 1,
  136201. 3,
  136202. 0,
  136203. 4,
  136204. };
  136205. static long _vq_lengthlist__44u7__p3_0[] = {
  136206. 2, 5, 4, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  136207. 9, 9,13,12, 8, 9,10,12,13, 5, 7, 7,10, 9, 7, 9,
  136208. 9,11,11, 6, 8, 9,11,11,10,11,11,14,14, 9,10,11,
  136209. 13,14, 5, 7, 7, 9, 9, 7, 9, 8,11,11, 7, 9, 9,11,
  136210. 11, 9,11,10,14,13,10,11,11,14,14, 8,10,10,14,13,
  136211. 10,11,12,15,14, 9,11,11,15,14,13,14,14,16,16,12,
  136212. 13,14,17,16, 8,10,10,13,13, 9,11,11,14,15,10,11,
  136213. 12,14,15,12,14,13,16,16,13,14,15,15,17, 5, 7, 7,
  136214. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,11,10,12,11,15,
  136215. 14,10,11,12,14,14, 7, 9, 9,12,12, 9,11,11,13,13,
  136216. 9,11,11,13,13,11,13,13,14,17,11,13,13,15,16, 6,
  136217. 9, 9,11,11, 8,11,10,13,12, 9,11,11,13,13,11,13,
  136218. 12,16,14,11,13,13,16,16,10,12,12,15,15,11,13,13,
  136219. 16,16,11,13,13,16,15,14,16,17,17,19,14,16,16,18,
  136220. 0, 9,11,11,14,15,10,13,12,16,15,11,13,13,16,16,
  136221. 14,15,14, 0,16,14,16,16,18, 0, 5, 7, 7,10,10, 7,
  136222. 9, 9,12,11, 7, 9, 9,11,12,10,11,11,15,14,10,11,
  136223. 12,14,14, 6, 9, 9,11,11, 9,11,11,13,13, 8,10,11,
  136224. 12,13,11,13,13,17,15,11,12,13,14,15, 7, 9, 9,11,
  136225. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,12,16,16,
  136226. 11,13,13,15,14, 9,11,11,14,15,11,13,13,16,15,10,
  136227. 12,13,16,16,15,16,16, 0, 0,14,13,15,16,18,10,11,
  136228. 11,15,15,11,13,14,16,18,11,13,13,16,15,15,16,16,
  136229. 19, 0,14,15,15,16,16, 8,10,10,13,13,10,12,11,16,
  136230. 15,10,11,11,16,15,13,15,16,18, 0,13,14,15,17,17,
  136231. 9,11,11,15,15,11,13,13,16,18,11,13,13,16,17,15,
  136232. 16,16, 0, 0,15,18,16, 0,17, 9,11,11,15,15,11,13,
  136233. 12,17,15,11,13,14,16,17,15,18,15, 0,17,15,16,16,
  136234. 18,19,13,15,14, 0,18,14,16,16,19,18,14,16,15,19,
  136235. 19,16,18,19, 0, 0,16,17, 0, 0, 0,12,14,14,17,17,
  136236. 13,16,14, 0,18,14,16,15,18, 0,16,18,16,19,17,18,
  136237. 19,17, 0, 0, 8,10,10,14,14, 9,12,11,15,15,10,11,
  136238. 12,15,17,13,15,15,18,16,14,16,15,18,17, 9,11,11,
  136239. 16,15,11,13,13, 0,16,11,12,13,16,15,15,16,16, 0,
  136240. 17,15,15,16,18,17, 9,12,11,15,17,11,13,13,16,16,
  136241. 11,14,13,16,16,15,15,16,18,19,16,18,16, 0, 0,12,
  136242. 14,14, 0,16,14,16,16, 0,18,13,14,15,16, 0,17,16,
  136243. 18, 0, 0,16,16,17,19, 0,13,14,14,17, 0,14,17,16,
  136244. 0,19,14,15,15,18,19,17,16,18, 0, 0,15,19,16, 0,
  136245. 0,
  136246. };
  136247. static float _vq_quantthresh__44u7__p3_0[] = {
  136248. -1.5, -0.5, 0.5, 1.5,
  136249. };
  136250. static long _vq_quantmap__44u7__p3_0[] = {
  136251. 3, 1, 0, 2, 4,
  136252. };
  136253. static encode_aux_threshmatch _vq_auxt__44u7__p3_0 = {
  136254. _vq_quantthresh__44u7__p3_0,
  136255. _vq_quantmap__44u7__p3_0,
  136256. 5,
  136257. 5
  136258. };
  136259. static static_codebook _44u7__p3_0 = {
  136260. 4, 625,
  136261. _vq_lengthlist__44u7__p3_0,
  136262. 1, -533725184, 1611661312, 3, 0,
  136263. _vq_quantlist__44u7__p3_0,
  136264. NULL,
  136265. &_vq_auxt__44u7__p3_0,
  136266. NULL,
  136267. 0
  136268. };
  136269. static long _vq_quantlist__44u7__p4_0[] = {
  136270. 2,
  136271. 1,
  136272. 3,
  136273. 0,
  136274. 4,
  136275. };
  136276. static long _vq_lengthlist__44u7__p4_0[] = {
  136277. 4, 5, 5, 8, 8, 6, 7, 6, 9, 9, 6, 6, 7, 9, 9, 8,
  136278. 9, 9,11,11, 8, 9, 9,10,11, 6, 7, 7, 9, 9, 7, 8,
  136279. 8,10,10, 6, 7, 8, 9,10, 9,10,10,12,12, 9, 9,10,
  136280. 11,12, 6, 7, 7, 9, 9, 6, 8, 7,10, 9, 7, 8, 8,10,
  136281. 10, 9,10, 9,12,11, 9,10,10,12,11, 8, 9, 9,11,11,
  136282. 9,10,10,12,12, 9,10,10,12,12,11,12,12,13,14,11,
  136283. 11,12,13,13, 8, 9, 9,11,11, 9,10,10,12,11, 9,10,
  136284. 10,12,12,11,12,11,13,13,11,12,12,13,13, 6, 7, 7,
  136285. 9, 9, 7, 8, 7,10,10, 7, 7, 8,10,10, 9,10,10,12,
  136286. 11, 9,10,10,12,12, 7, 8, 8,10,10, 8, 8, 9,11,11,
  136287. 8, 9, 9,11,11,10,11,11,12,12,10,10,11,12,13, 6,
  136288. 7, 7,10,10, 7, 9, 8,11,10, 8, 8, 9,10,11,10,11,
  136289. 10,13,11,10,11,11,12,12, 9,10,10,12,12,10,10,11,
  136290. 13,13,10,11,11,13,12,12,12,13,13,14,12,12,13,14,
  136291. 14, 9,10,10,12,12, 9,10,10,12,12,10,11,11,13,13,
  136292. 11,12,11,14,12,12,13,13,14,14, 6, 7, 7, 9, 9, 7,
  136293. 8, 7,10,10, 7, 7, 8,10,10, 9,10,10,12,11, 9,10,
  136294. 10,11,12, 6, 7, 7,10,10, 8, 9, 8,11,10, 7, 8, 9,
  136295. 10,11,10,11,11,13,12,10,10,11,11,13, 7, 8, 8,10,
  136296. 10, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,10,13,12,
  136297. 10,11,11,12,12, 9,10,10,12,12,10,11,11,13,12, 9,
  136298. 10,10,12,13,12,13,12,14,14,11,11,12,12,14, 9,10,
  136299. 10,12,12,10,11,11,13,13,10,11,11,13,13,12,13,12,
  136300. 14,14,12,13,12,14,13, 8, 9, 9,11,11, 9,10,10,12,
  136301. 12, 9,10,10,12,12,11,12,12,14,13,11,12,12,13,13,
  136302. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,12,12,
  136303. 13,13,14,14,12,12,13,14,14, 9,10,10,12,12, 9,11,
  136304. 10,13,12,10,10,11,12,13,11,13,12,14,13,12,12,13,
  136305. 14,14,11,12,12,13,13,11,12,13,14,14,12,13,13,14,
  136306. 14,13,13,14,14,16,13,14,14,16,16,11,11,11,13,13,
  136307. 11,12,11,14,13,12,12,13,14,15,13,14,12,16,13,14,
  136308. 14,14,15,16, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  136309. 10,12,12,11,12,12,14,13,11,12,12,13,14, 9,10,10,
  136310. 12,12,10,11,10,13,12, 9,10,11,12,13,12,13,12,14,
  136311. 14,12,12,13,13,14, 9,10,10,12,12,10,11,11,12,13,
  136312. 10,11,11,13,13,12,13,12,14,14,12,13,13,14,14,11,
  136313. 12,12,13,13,12,13,12,14,14,11,11,12,13,14,13,15,
  136314. 14,16,15,13,12,14,13,16,11,12,12,13,13,12,13,13,
  136315. 14,14,12,12,12,14,14,13,14,14,15,15,13,14,13,16,
  136316. 14,
  136317. };
  136318. static float _vq_quantthresh__44u7__p4_0[] = {
  136319. -1.5, -0.5, 0.5, 1.5,
  136320. };
  136321. static long _vq_quantmap__44u7__p4_0[] = {
  136322. 3, 1, 0, 2, 4,
  136323. };
  136324. static encode_aux_threshmatch _vq_auxt__44u7__p4_0 = {
  136325. _vq_quantthresh__44u7__p4_0,
  136326. _vq_quantmap__44u7__p4_0,
  136327. 5,
  136328. 5
  136329. };
  136330. static static_codebook _44u7__p4_0 = {
  136331. 4, 625,
  136332. _vq_lengthlist__44u7__p4_0,
  136333. 1, -533725184, 1611661312, 3, 0,
  136334. _vq_quantlist__44u7__p4_0,
  136335. NULL,
  136336. &_vq_auxt__44u7__p4_0,
  136337. NULL,
  136338. 0
  136339. };
  136340. static long _vq_quantlist__44u7__p5_0[] = {
  136341. 4,
  136342. 3,
  136343. 5,
  136344. 2,
  136345. 6,
  136346. 1,
  136347. 7,
  136348. 0,
  136349. 8,
  136350. };
  136351. static long _vq_lengthlist__44u7__p5_0[] = {
  136352. 2, 3, 3, 6, 6, 7, 8,10,10, 4, 5, 5, 8, 7, 8, 8,
  136353. 11,11, 3, 5, 5, 7, 7, 8, 9,11,11, 6, 8, 7, 9, 9,
  136354. 10,10,12,12, 6, 7, 8, 9,10,10,10,12,12, 8, 8, 8,
  136355. 10,10,12,11,13,13, 8, 8, 9,10,10,11,11,13,13,10,
  136356. 11,11,12,12,13,13,14,14,10,11,11,12,12,13,13,14,
  136357. 14,
  136358. };
  136359. static float _vq_quantthresh__44u7__p5_0[] = {
  136360. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  136361. };
  136362. static long _vq_quantmap__44u7__p5_0[] = {
  136363. 7, 5, 3, 1, 0, 2, 4, 6,
  136364. 8,
  136365. };
  136366. static encode_aux_threshmatch _vq_auxt__44u7__p5_0 = {
  136367. _vq_quantthresh__44u7__p5_0,
  136368. _vq_quantmap__44u7__p5_0,
  136369. 9,
  136370. 9
  136371. };
  136372. static static_codebook _44u7__p5_0 = {
  136373. 2, 81,
  136374. _vq_lengthlist__44u7__p5_0,
  136375. 1, -531628032, 1611661312, 4, 0,
  136376. _vq_quantlist__44u7__p5_0,
  136377. NULL,
  136378. &_vq_auxt__44u7__p5_0,
  136379. NULL,
  136380. 0
  136381. };
  136382. static long _vq_quantlist__44u7__p6_0[] = {
  136383. 4,
  136384. 3,
  136385. 5,
  136386. 2,
  136387. 6,
  136388. 1,
  136389. 7,
  136390. 0,
  136391. 8,
  136392. };
  136393. static long _vq_lengthlist__44u7__p6_0[] = {
  136394. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 8, 7,
  136395. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  136396. 8, 8,10,10, 5, 6, 6, 7, 7, 8, 8,10,10, 7, 8, 7,
  136397. 8, 8,10, 9,11,11, 7, 7, 8, 8, 8, 9,10,11,11, 9,
  136398. 9, 9,10,10,11,10,12,11, 9, 9, 9,10,10,11,11,11,
  136399. 12,
  136400. };
  136401. static float _vq_quantthresh__44u7__p6_0[] = {
  136402. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  136403. };
  136404. static long _vq_quantmap__44u7__p6_0[] = {
  136405. 7, 5, 3, 1, 0, 2, 4, 6,
  136406. 8,
  136407. };
  136408. static encode_aux_threshmatch _vq_auxt__44u7__p6_0 = {
  136409. _vq_quantthresh__44u7__p6_0,
  136410. _vq_quantmap__44u7__p6_0,
  136411. 9,
  136412. 9
  136413. };
  136414. static static_codebook _44u7__p6_0 = {
  136415. 2, 81,
  136416. _vq_lengthlist__44u7__p6_0,
  136417. 1, -531628032, 1611661312, 4, 0,
  136418. _vq_quantlist__44u7__p6_0,
  136419. NULL,
  136420. &_vq_auxt__44u7__p6_0,
  136421. NULL,
  136422. 0
  136423. };
  136424. static long _vq_quantlist__44u7__p7_0[] = {
  136425. 1,
  136426. 0,
  136427. 2,
  136428. };
  136429. static long _vq_lengthlist__44u7__p7_0[] = {
  136430. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 8, 8, 9, 9, 7,
  136431. 10,10, 5, 8, 9, 7, 9,10, 8, 9, 9, 4, 9, 9, 9,11,
  136432. 10, 8,10,10, 7,11,10,10,10,12,10,12,12, 7,10,10,
  136433. 10,12,11,10,12,12, 5, 9, 9, 8,10,10, 9,11,11, 7,
  136434. 11,10,10,12,12,10,11,12, 7,10,11,10,12,12,10,12,
  136435. 10,
  136436. };
  136437. static float _vq_quantthresh__44u7__p7_0[] = {
  136438. -5.5, 5.5,
  136439. };
  136440. static long _vq_quantmap__44u7__p7_0[] = {
  136441. 1, 0, 2,
  136442. };
  136443. static encode_aux_threshmatch _vq_auxt__44u7__p7_0 = {
  136444. _vq_quantthresh__44u7__p7_0,
  136445. _vq_quantmap__44u7__p7_0,
  136446. 3,
  136447. 3
  136448. };
  136449. static static_codebook _44u7__p7_0 = {
  136450. 4, 81,
  136451. _vq_lengthlist__44u7__p7_0,
  136452. 1, -529137664, 1618345984, 2, 0,
  136453. _vq_quantlist__44u7__p7_0,
  136454. NULL,
  136455. &_vq_auxt__44u7__p7_0,
  136456. NULL,
  136457. 0
  136458. };
  136459. static long _vq_quantlist__44u7__p7_1[] = {
  136460. 5,
  136461. 4,
  136462. 6,
  136463. 3,
  136464. 7,
  136465. 2,
  136466. 8,
  136467. 1,
  136468. 9,
  136469. 0,
  136470. 10,
  136471. };
  136472. static long _vq_lengthlist__44u7__p7_1[] = {
  136473. 3, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 6, 6,
  136474. 8, 7, 8, 8, 8, 8, 4, 5, 5, 6, 6, 7, 8, 8, 8, 8,
  136475. 8, 6, 7, 6, 7, 7, 8, 8, 9, 9, 9, 9, 6, 6, 7, 7,
  136476. 7, 8, 8, 9, 9, 9, 9, 7, 8, 7, 8, 8, 9, 9, 9, 9,
  136477. 9, 9, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8,
  136478. 9, 9, 9, 9,10, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9,
  136479. 9, 9,10, 8, 8, 8, 9, 9, 9, 9,10, 9,10,10, 8, 8,
  136480. 8, 9, 9, 9, 9, 9,10,10,10,
  136481. };
  136482. static float _vq_quantthresh__44u7__p7_1[] = {
  136483. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  136484. 3.5, 4.5,
  136485. };
  136486. static long _vq_quantmap__44u7__p7_1[] = {
  136487. 9, 7, 5, 3, 1, 0, 2, 4,
  136488. 6, 8, 10,
  136489. };
  136490. static encode_aux_threshmatch _vq_auxt__44u7__p7_1 = {
  136491. _vq_quantthresh__44u7__p7_1,
  136492. _vq_quantmap__44u7__p7_1,
  136493. 11,
  136494. 11
  136495. };
  136496. static static_codebook _44u7__p7_1 = {
  136497. 2, 121,
  136498. _vq_lengthlist__44u7__p7_1,
  136499. 1, -531365888, 1611661312, 4, 0,
  136500. _vq_quantlist__44u7__p7_1,
  136501. NULL,
  136502. &_vq_auxt__44u7__p7_1,
  136503. NULL,
  136504. 0
  136505. };
  136506. static long _vq_quantlist__44u7__p8_0[] = {
  136507. 5,
  136508. 4,
  136509. 6,
  136510. 3,
  136511. 7,
  136512. 2,
  136513. 8,
  136514. 1,
  136515. 9,
  136516. 0,
  136517. 10,
  136518. };
  136519. static long _vq_lengthlist__44u7__p8_0[] = {
  136520. 1, 4, 4, 6, 6, 8, 8,10,10,11,11, 4, 6, 6, 7, 7,
  136521. 9, 9,11,10,12,12, 5, 6, 5, 7, 7, 9, 9,10,11,12,
  136522. 12, 6, 7, 7, 8, 8,10,10,11,11,13,13, 6, 7, 7, 8,
  136523. 8,10,10,11,12,13,13, 8, 9, 9,10,10,11,11,12,12,
  136524. 14,14, 8, 9, 9,10,10,11,11,12,12,14,14,10,10,10,
  136525. 11,11,13,12,14,14,15,15,10,10,10,12,12,13,13,14,
  136526. 14,15,15,11,12,12,13,13,14,14,15,14,16,15,11,12,
  136527. 12,13,13,14,14,15,15,15,16,
  136528. };
  136529. static float _vq_quantthresh__44u7__p8_0[] = {
  136530. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  136531. 38.5, 49.5,
  136532. };
  136533. static long _vq_quantmap__44u7__p8_0[] = {
  136534. 9, 7, 5, 3, 1, 0, 2, 4,
  136535. 6, 8, 10,
  136536. };
  136537. static encode_aux_threshmatch _vq_auxt__44u7__p8_0 = {
  136538. _vq_quantthresh__44u7__p8_0,
  136539. _vq_quantmap__44u7__p8_0,
  136540. 11,
  136541. 11
  136542. };
  136543. static static_codebook _44u7__p8_0 = {
  136544. 2, 121,
  136545. _vq_lengthlist__44u7__p8_0,
  136546. 1, -524582912, 1618345984, 4, 0,
  136547. _vq_quantlist__44u7__p8_0,
  136548. NULL,
  136549. &_vq_auxt__44u7__p8_0,
  136550. NULL,
  136551. 0
  136552. };
  136553. static long _vq_quantlist__44u7__p8_1[] = {
  136554. 5,
  136555. 4,
  136556. 6,
  136557. 3,
  136558. 7,
  136559. 2,
  136560. 8,
  136561. 1,
  136562. 9,
  136563. 0,
  136564. 10,
  136565. };
  136566. static long _vq_lengthlist__44u7__p8_1[] = {
  136567. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7,
  136568. 7, 7, 7, 7, 7, 7, 5, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  136569. 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 6, 7, 7, 7,
  136570. 7, 7, 7, 7, 7, 8, 8, 7, 7, 7, 7, 7, 8, 7, 8, 8,
  136571. 8, 8, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  136572. 7, 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8,
  136573. 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7,
  136574. 7, 8, 8, 8, 8, 8, 8, 8, 8,
  136575. };
  136576. static float _vq_quantthresh__44u7__p8_1[] = {
  136577. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  136578. 3.5, 4.5,
  136579. };
  136580. static long _vq_quantmap__44u7__p8_1[] = {
  136581. 9, 7, 5, 3, 1, 0, 2, 4,
  136582. 6, 8, 10,
  136583. };
  136584. static encode_aux_threshmatch _vq_auxt__44u7__p8_1 = {
  136585. _vq_quantthresh__44u7__p8_1,
  136586. _vq_quantmap__44u7__p8_1,
  136587. 11,
  136588. 11
  136589. };
  136590. static static_codebook _44u7__p8_1 = {
  136591. 2, 121,
  136592. _vq_lengthlist__44u7__p8_1,
  136593. 1, -531365888, 1611661312, 4, 0,
  136594. _vq_quantlist__44u7__p8_1,
  136595. NULL,
  136596. &_vq_auxt__44u7__p8_1,
  136597. NULL,
  136598. 0
  136599. };
  136600. static long _vq_quantlist__44u7__p9_0[] = {
  136601. 5,
  136602. 4,
  136603. 6,
  136604. 3,
  136605. 7,
  136606. 2,
  136607. 8,
  136608. 1,
  136609. 9,
  136610. 0,
  136611. 10,
  136612. };
  136613. static long _vq_lengthlist__44u7__p9_0[] = {
  136614. 1, 3, 3,10,10,10,10,10,10,10,10, 4,10,10,10,10,
  136615. 10,10,10,10,10,10, 4,10,10,10,10,10,10,10,10,10,
  136616. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136617. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136618. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136619. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136620. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  136621. 9, 9, 9, 9, 9, 9, 9, 9, 9,
  136622. };
  136623. static float _vq_quantthresh__44u7__p9_0[] = {
  136624. -2866.5, -2229.5, -1592.5, -955.5, -318.5, 318.5, 955.5, 1592.5,
  136625. 2229.5, 2866.5,
  136626. };
  136627. static long _vq_quantmap__44u7__p9_0[] = {
  136628. 9, 7, 5, 3, 1, 0, 2, 4,
  136629. 6, 8, 10,
  136630. };
  136631. static encode_aux_threshmatch _vq_auxt__44u7__p9_0 = {
  136632. _vq_quantthresh__44u7__p9_0,
  136633. _vq_quantmap__44u7__p9_0,
  136634. 11,
  136635. 11
  136636. };
  136637. static static_codebook _44u7__p9_0 = {
  136638. 2, 121,
  136639. _vq_lengthlist__44u7__p9_0,
  136640. 1, -512171520, 1630791680, 4, 0,
  136641. _vq_quantlist__44u7__p9_0,
  136642. NULL,
  136643. &_vq_auxt__44u7__p9_0,
  136644. NULL,
  136645. 0
  136646. };
  136647. static long _vq_quantlist__44u7__p9_1[] = {
  136648. 6,
  136649. 5,
  136650. 7,
  136651. 4,
  136652. 8,
  136653. 3,
  136654. 9,
  136655. 2,
  136656. 10,
  136657. 1,
  136658. 11,
  136659. 0,
  136660. 12,
  136661. };
  136662. static long _vq_lengthlist__44u7__p9_1[] = {
  136663. 1, 4, 4, 6, 5, 8, 6, 9, 8,10, 9,11,10, 4, 6, 6,
  136664. 8, 8, 9, 9,11,10,11,11,11,11, 4, 6, 6, 8, 8,10,
  136665. 9,11,11,11,11,11,12, 6, 8, 8,10,10,11,11,12,12,
  136666. 13,12,13,13, 6, 8, 8,10,10,11,11,12,12,12,13,14,
  136667. 13, 8,10,10,11,11,12,13,14,14,14,14,15,15, 8,10,
  136668. 10,11,12,12,13,13,14,14,14,14,15, 9,11,11,13,13,
  136669. 14,14,15,14,16,15,17,15, 9,11,11,12,13,14,14,15,
  136670. 14,15,15,15,16,10,12,12,13,14,15,15,15,15,16,17,
  136671. 16,17,10,13,12,13,14,14,16,16,16,16,15,16,17,11,
  136672. 13,13,14,15,14,17,15,16,17,17,17,17,11,13,13,14,
  136673. 15,15,15,15,17,17,16,17,16,
  136674. };
  136675. static float _vq_quantthresh__44u7__p9_1[] = {
  136676. -269.5, -220.5, -171.5, -122.5, -73.5, -24.5, 24.5, 73.5,
  136677. 122.5, 171.5, 220.5, 269.5,
  136678. };
  136679. static long _vq_quantmap__44u7__p9_1[] = {
  136680. 11, 9, 7, 5, 3, 1, 0, 2,
  136681. 4, 6, 8, 10, 12,
  136682. };
  136683. static encode_aux_threshmatch _vq_auxt__44u7__p9_1 = {
  136684. _vq_quantthresh__44u7__p9_1,
  136685. _vq_quantmap__44u7__p9_1,
  136686. 13,
  136687. 13
  136688. };
  136689. static static_codebook _44u7__p9_1 = {
  136690. 2, 169,
  136691. _vq_lengthlist__44u7__p9_1,
  136692. 1, -518889472, 1622704128, 4, 0,
  136693. _vq_quantlist__44u7__p9_1,
  136694. NULL,
  136695. &_vq_auxt__44u7__p9_1,
  136696. NULL,
  136697. 0
  136698. };
  136699. static long _vq_quantlist__44u7__p9_2[] = {
  136700. 24,
  136701. 23,
  136702. 25,
  136703. 22,
  136704. 26,
  136705. 21,
  136706. 27,
  136707. 20,
  136708. 28,
  136709. 19,
  136710. 29,
  136711. 18,
  136712. 30,
  136713. 17,
  136714. 31,
  136715. 16,
  136716. 32,
  136717. 15,
  136718. 33,
  136719. 14,
  136720. 34,
  136721. 13,
  136722. 35,
  136723. 12,
  136724. 36,
  136725. 11,
  136726. 37,
  136727. 10,
  136728. 38,
  136729. 9,
  136730. 39,
  136731. 8,
  136732. 40,
  136733. 7,
  136734. 41,
  136735. 6,
  136736. 42,
  136737. 5,
  136738. 43,
  136739. 4,
  136740. 44,
  136741. 3,
  136742. 45,
  136743. 2,
  136744. 46,
  136745. 1,
  136746. 47,
  136747. 0,
  136748. 48,
  136749. };
  136750. static long _vq_lengthlist__44u7__p9_2[] = {
  136751. 2, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6,
  136752. 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  136753. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  136754. 8,
  136755. };
  136756. static float _vq_quantthresh__44u7__p9_2[] = {
  136757. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  136758. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  136759. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  136760. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  136761. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  136762. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  136763. };
  136764. static long _vq_quantmap__44u7__p9_2[] = {
  136765. 47, 45, 43, 41, 39, 37, 35, 33,
  136766. 31, 29, 27, 25, 23, 21, 19, 17,
  136767. 15, 13, 11, 9, 7, 5, 3, 1,
  136768. 0, 2, 4, 6, 8, 10, 12, 14,
  136769. 16, 18, 20, 22, 24, 26, 28, 30,
  136770. 32, 34, 36, 38, 40, 42, 44, 46,
  136771. 48,
  136772. };
  136773. static encode_aux_threshmatch _vq_auxt__44u7__p9_2 = {
  136774. _vq_quantthresh__44u7__p9_2,
  136775. _vq_quantmap__44u7__p9_2,
  136776. 49,
  136777. 49
  136778. };
  136779. static static_codebook _44u7__p9_2 = {
  136780. 1, 49,
  136781. _vq_lengthlist__44u7__p9_2,
  136782. 1, -526909440, 1611661312, 6, 0,
  136783. _vq_quantlist__44u7__p9_2,
  136784. NULL,
  136785. &_vq_auxt__44u7__p9_2,
  136786. NULL,
  136787. 0
  136788. };
  136789. static long _huff_lengthlist__44u7__short[] = {
  136790. 5,12,17,16,16,17,17,17,17,17, 4, 7,11,11,12, 9,
  136791. 17,10,17,17, 7, 7, 8, 9, 7, 9,11,10,15,17, 7, 9,
  136792. 10,11,10,12,14,12,16,17, 7, 8, 5, 7, 4, 7, 7, 8,
  136793. 16,16, 6,10, 9,10, 7,10,11,11,16,17, 6, 8, 8, 9,
  136794. 5, 7, 5, 8,16,17, 5, 5, 8, 7, 6, 7, 7, 6, 6,14,
  136795. 12,10,12,11, 7,11, 4, 4, 2, 7,17,15,15,15, 8,15,
  136796. 6, 8, 5, 9,
  136797. };
  136798. static static_codebook _huff_book__44u7__short = {
  136799. 2, 100,
  136800. _huff_lengthlist__44u7__short,
  136801. 0, 0, 0, 0, 0,
  136802. NULL,
  136803. NULL,
  136804. NULL,
  136805. NULL,
  136806. 0
  136807. };
  136808. static long _huff_lengthlist__44u8__long[] = {
  136809. 3, 9,13,14,14,15,14,14,15,15, 5, 4, 6, 8,10,12,
  136810. 12,14,15,15, 9, 5, 4, 5, 8,10,11,13,16,16,10, 7,
  136811. 4, 3, 5, 7, 9,11,13,13,10, 9, 7, 4, 4, 6, 8,10,
  136812. 12,14,13,11, 9, 6, 5, 5, 6, 8,12,14,13,11,10, 8,
  136813. 7, 6, 6, 7,10,14,13,11,12,10, 8, 7, 6, 6, 9,13,
  136814. 12,11,14,12,11, 9, 8, 7, 9,11,11,12,14,13,14,11,
  136815. 10, 8, 8, 9,
  136816. };
  136817. static static_codebook _huff_book__44u8__long = {
  136818. 2, 100,
  136819. _huff_lengthlist__44u8__long,
  136820. 0, 0, 0, 0, 0,
  136821. NULL,
  136822. NULL,
  136823. NULL,
  136824. NULL,
  136825. 0
  136826. };
  136827. static long _huff_lengthlist__44u8__short[] = {
  136828. 6,14,18,18,17,17,17,17,17,17, 4, 7, 9, 9,10,13,
  136829. 15,17,17,17, 6, 7, 5, 6, 8,11,16,17,16,17, 5, 7,
  136830. 5, 4, 6,10,14,17,17,17, 6, 6, 6, 5, 7,10,13,16,
  136831. 17,17, 7, 6, 7, 7, 7, 8, 7,10,15,16,12, 9, 9, 6,
  136832. 6, 5, 3, 5,11,15,14,14,13, 5, 5, 7, 3, 4, 8,15,
  136833. 17,17,13, 7, 7,10, 6, 6,10,15,17,17,16,10,11,14,
  136834. 10,10,15,17,
  136835. };
  136836. static static_codebook _huff_book__44u8__short = {
  136837. 2, 100,
  136838. _huff_lengthlist__44u8__short,
  136839. 0, 0, 0, 0, 0,
  136840. NULL,
  136841. NULL,
  136842. NULL,
  136843. NULL,
  136844. 0
  136845. };
  136846. static long _vq_quantlist__44u8_p1_0[] = {
  136847. 1,
  136848. 0,
  136849. 2,
  136850. };
  136851. static long _vq_lengthlist__44u8_p1_0[] = {
  136852. 1, 5, 5, 5, 7, 7, 5, 7, 7, 5, 7, 7, 8, 9, 9, 7,
  136853. 9, 9, 5, 7, 7, 7, 9, 9, 8, 9, 9, 5, 7, 7, 7, 9,
  136854. 9, 7, 9, 9, 7, 9, 9, 9,10,11, 9,11,10, 7, 9, 9,
  136855. 9,11,10, 9,10,11, 5, 7, 7, 7, 9, 9, 7, 9, 9, 7,
  136856. 9, 9, 9,11,10, 9,10,10, 8, 9, 9, 9,11,11, 9,11,
  136857. 10,
  136858. };
  136859. static float _vq_quantthresh__44u8_p1_0[] = {
  136860. -0.5, 0.5,
  136861. };
  136862. static long _vq_quantmap__44u8_p1_0[] = {
  136863. 1, 0, 2,
  136864. };
  136865. static encode_aux_threshmatch _vq_auxt__44u8_p1_0 = {
  136866. _vq_quantthresh__44u8_p1_0,
  136867. _vq_quantmap__44u8_p1_0,
  136868. 3,
  136869. 3
  136870. };
  136871. static static_codebook _44u8_p1_0 = {
  136872. 4, 81,
  136873. _vq_lengthlist__44u8_p1_0,
  136874. 1, -535822336, 1611661312, 2, 0,
  136875. _vq_quantlist__44u8_p1_0,
  136876. NULL,
  136877. &_vq_auxt__44u8_p1_0,
  136878. NULL,
  136879. 0
  136880. };
  136881. static long _vq_quantlist__44u8_p2_0[] = {
  136882. 2,
  136883. 1,
  136884. 3,
  136885. 0,
  136886. 4,
  136887. };
  136888. static long _vq_lengthlist__44u8_p2_0[] = {
  136889. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  136890. 9, 9,11,11, 8, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  136891. 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12, 9,10,10,
  136892. 11,12, 5, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 8,10,
  136893. 10, 9,10, 9,12,11, 9,10,10,12,12, 8, 9, 9,12,11,
  136894. 9,10,10,12,12, 9,10,10,12,12,11,12,12,14,14,11,
  136895. 11,12,13,14, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  136896. 10,12,12,11,12,11,13,13,11,12,12,14,14, 5, 7, 7,
  136897. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,
  136898. 12, 9,10,10,11,12, 7, 8, 8,10,10, 8, 9, 9,11,11,
  136899. 8, 9, 9,11,11,10,11,11,12,13,10,11,11,12,13, 6,
  136900. 8, 8,10,10, 8, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  136901. 10,13,12,10,11,11,13,13, 9,10,10,12,12,10,11,11,
  136902. 13,13,10,11,11,13,13,12,12,13,13,14,12,13,13,14,
  136903. 14, 9,10,10,12,12,10,11,10,13,12,10,11,11,13,13,
  136904. 11,13,12,14,13,12,13,13,14,14, 5, 7, 7, 9, 9, 7,
  136905. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12, 9,10,
  136906. 10,12,12, 7, 8, 8,10,10, 8, 9, 9,11,11, 8, 8, 9,
  136907. 10,11,10,11,11,13,13,10,10,11,12,13, 7, 8, 8,10,
  136908. 10, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,11,13,13,
  136909. 10,11,11,13,12, 9,10,10,12,12,10,11,11,13,13,10,
  136910. 10,11,12,13,12,13,13,14,14,12,12,13,13,14, 9,10,
  136911. 10,12,12,10,11,11,13,13,10,11,11,13,13,12,13,13,
  136912. 15,14,12,13,13,14,13, 8, 9, 9,11,11, 9,10,10,12,
  136913. 12, 9,10,10,12,12,12,12,12,14,13,11,12,12,14,14,
  136914. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,13,12,
  136915. 13,13,14,15,12,13,13,14,15, 9,10,10,12,12,10,11,
  136916. 10,13,12,10,11,11,13,13,12,13,12,15,14,12,13,13,
  136917. 14,15,11,12,12,14,14,12,13,13,14,14,12,13,13,15,
  136918. 14,14,14,14,14,16,14,14,15,16,16,11,12,12,14,14,
  136919. 11,12,12,14,14,12,13,13,14,15,13,14,13,16,14,14,
  136920. 14,14,16,16, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  136921. 10,12,12,11,12,12,14,13,11,12,12,14,14, 9,10,10,
  136922. 12,12,10,11,11,13,13,10,10,11,12,13,12,13,13,15,
  136923. 14,12,12,13,13,14, 9,10,10,12,12,10,11,11,13,13,
  136924. 10,11,11,13,13,12,13,13,14,14,12,13,13,15,14,11,
  136925. 12,12,14,13,12,13,13,15,14,11,12,12,13,14,14,15,
  136926. 14,16,15,13,13,14,13,16,11,12,12,14,14,12,13,13,
  136927. 14,15,12,13,12,15,14,14,14,14,16,15,14,15,13,16,
  136928. 14,
  136929. };
  136930. static float _vq_quantthresh__44u8_p2_0[] = {
  136931. -1.5, -0.5, 0.5, 1.5,
  136932. };
  136933. static long _vq_quantmap__44u8_p2_0[] = {
  136934. 3, 1, 0, 2, 4,
  136935. };
  136936. static encode_aux_threshmatch _vq_auxt__44u8_p2_0 = {
  136937. _vq_quantthresh__44u8_p2_0,
  136938. _vq_quantmap__44u8_p2_0,
  136939. 5,
  136940. 5
  136941. };
  136942. static static_codebook _44u8_p2_0 = {
  136943. 4, 625,
  136944. _vq_lengthlist__44u8_p2_0,
  136945. 1, -533725184, 1611661312, 3, 0,
  136946. _vq_quantlist__44u8_p2_0,
  136947. NULL,
  136948. &_vq_auxt__44u8_p2_0,
  136949. NULL,
  136950. 0
  136951. };
  136952. static long _vq_quantlist__44u8_p3_0[] = {
  136953. 4,
  136954. 3,
  136955. 5,
  136956. 2,
  136957. 6,
  136958. 1,
  136959. 7,
  136960. 0,
  136961. 8,
  136962. };
  136963. static long _vq_lengthlist__44u8_p3_0[] = {
  136964. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 7, 7,
  136965. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  136966. 8, 8,10,10, 6, 6, 6, 7, 7, 8, 8,10,10, 7, 7, 7,
  136967. 8, 8, 9, 9,11,10, 7, 7, 7, 8, 8, 9, 9,10,11, 9,
  136968. 9, 9,10,10,11,10,12,11, 9, 9, 9, 9,10,11,11,11,
  136969. 12,
  136970. };
  136971. static float _vq_quantthresh__44u8_p3_0[] = {
  136972. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  136973. };
  136974. static long _vq_quantmap__44u8_p3_0[] = {
  136975. 7, 5, 3, 1, 0, 2, 4, 6,
  136976. 8,
  136977. };
  136978. static encode_aux_threshmatch _vq_auxt__44u8_p3_0 = {
  136979. _vq_quantthresh__44u8_p3_0,
  136980. _vq_quantmap__44u8_p3_0,
  136981. 9,
  136982. 9
  136983. };
  136984. static static_codebook _44u8_p3_0 = {
  136985. 2, 81,
  136986. _vq_lengthlist__44u8_p3_0,
  136987. 1, -531628032, 1611661312, 4, 0,
  136988. _vq_quantlist__44u8_p3_0,
  136989. NULL,
  136990. &_vq_auxt__44u8_p3_0,
  136991. NULL,
  136992. 0
  136993. };
  136994. static long _vq_quantlist__44u8_p4_0[] = {
  136995. 8,
  136996. 7,
  136997. 9,
  136998. 6,
  136999. 10,
  137000. 5,
  137001. 11,
  137002. 4,
  137003. 12,
  137004. 3,
  137005. 13,
  137006. 2,
  137007. 14,
  137008. 1,
  137009. 15,
  137010. 0,
  137011. 16,
  137012. };
  137013. static long _vq_lengthlist__44u8_p4_0[] = {
  137014. 4, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8,10,10,11,11,11,
  137015. 11, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,
  137016. 12,12, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  137017. 11,12,12, 6, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  137018. 11,11,12,12, 6, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,
  137019. 10,11,11,12,12, 7, 7, 7, 8, 8, 9, 8,10, 9,10, 9,
  137020. 11,10,12,11,13,12, 7, 7, 7, 8, 8, 8, 9, 9,10, 9,
  137021. 10,10,11,11,12,12,13, 8, 8, 8, 9, 9, 9, 9,10,10,
  137022. 11,10,11,11,12,12,13,13, 8, 8, 8, 9, 9, 9,10,10,
  137023. 10,10,11,11,11,12,12,12,13, 8, 9, 9, 9, 9,10, 9,
  137024. 11,10,11,11,12,11,13,12,13,13, 8, 9, 9, 9, 9, 9,
  137025. 10,10,11,11,11,11,12,12,13,13,13,10,10,10,10,10,
  137026. 11,10,11,11,12,11,13,12,13,13,14,13,10,10,10,10,
  137027. 10,10,11,11,11,11,12,12,13,13,13,13,14,11,11,11,
  137028. 11,11,12,11,12,12,13,12,13,13,14,13,14,14,11,11,
  137029. 11,11,11,11,12,12,12,12,13,13,13,13,14,14,14,11,
  137030. 12,12,12,12,13,12,13,12,13,13,14,13,14,14,14,14,
  137031. 11,12,12,12,12,12,12,13,13,13,13,13,14,14,14,14,
  137032. 14,
  137033. };
  137034. static float _vq_quantthresh__44u8_p4_0[] = {
  137035. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  137036. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  137037. };
  137038. static long _vq_quantmap__44u8_p4_0[] = {
  137039. 15, 13, 11, 9, 7, 5, 3, 1,
  137040. 0, 2, 4, 6, 8, 10, 12, 14,
  137041. 16,
  137042. };
  137043. static encode_aux_threshmatch _vq_auxt__44u8_p4_0 = {
  137044. _vq_quantthresh__44u8_p4_0,
  137045. _vq_quantmap__44u8_p4_0,
  137046. 17,
  137047. 17
  137048. };
  137049. static static_codebook _44u8_p4_0 = {
  137050. 2, 289,
  137051. _vq_lengthlist__44u8_p4_0,
  137052. 1, -529530880, 1611661312, 5, 0,
  137053. _vq_quantlist__44u8_p4_0,
  137054. NULL,
  137055. &_vq_auxt__44u8_p4_0,
  137056. NULL,
  137057. 0
  137058. };
  137059. static long _vq_quantlist__44u8_p5_0[] = {
  137060. 1,
  137061. 0,
  137062. 2,
  137063. };
  137064. static long _vq_lengthlist__44u8_p5_0[] = {
  137065. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 8, 9, 9, 7,
  137066. 9, 9, 5, 8, 8, 7, 9, 9, 8, 9, 9, 5, 8, 8, 8,10,
  137067. 10, 8,10,10, 7,10,10, 9,10,12, 9,12,11, 7,10,10,
  137068. 9,11,10, 9,11,12, 5, 8, 8, 8,10,10, 8,10,10, 7,
  137069. 10,10, 9,11,11, 9,10,11, 7,10,10, 9,11,11,10,12,
  137070. 10,
  137071. };
  137072. static float _vq_quantthresh__44u8_p5_0[] = {
  137073. -5.5, 5.5,
  137074. };
  137075. static long _vq_quantmap__44u8_p5_0[] = {
  137076. 1, 0, 2,
  137077. };
  137078. static encode_aux_threshmatch _vq_auxt__44u8_p5_0 = {
  137079. _vq_quantthresh__44u8_p5_0,
  137080. _vq_quantmap__44u8_p5_0,
  137081. 3,
  137082. 3
  137083. };
  137084. static static_codebook _44u8_p5_0 = {
  137085. 4, 81,
  137086. _vq_lengthlist__44u8_p5_0,
  137087. 1, -529137664, 1618345984, 2, 0,
  137088. _vq_quantlist__44u8_p5_0,
  137089. NULL,
  137090. &_vq_auxt__44u8_p5_0,
  137091. NULL,
  137092. 0
  137093. };
  137094. static long _vq_quantlist__44u8_p5_1[] = {
  137095. 5,
  137096. 4,
  137097. 6,
  137098. 3,
  137099. 7,
  137100. 2,
  137101. 8,
  137102. 1,
  137103. 9,
  137104. 0,
  137105. 10,
  137106. };
  137107. static long _vq_lengthlist__44u8_p5_1[] = {
  137108. 4, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 5, 5, 5, 6, 6,
  137109. 7, 7, 8, 8, 8, 8, 5, 5, 5, 6, 6, 7, 7, 7, 8, 8,
  137110. 8, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 6, 6, 6, 7,
  137111. 7, 7, 7, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8,
  137112. 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 7, 8, 7,
  137113. 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8,
  137114. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 8, 8,
  137115. 8, 8, 8, 8, 8, 8, 8, 9, 9,
  137116. };
  137117. static float _vq_quantthresh__44u8_p5_1[] = {
  137118. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  137119. 3.5, 4.5,
  137120. };
  137121. static long _vq_quantmap__44u8_p5_1[] = {
  137122. 9, 7, 5, 3, 1, 0, 2, 4,
  137123. 6, 8, 10,
  137124. };
  137125. static encode_aux_threshmatch _vq_auxt__44u8_p5_1 = {
  137126. _vq_quantthresh__44u8_p5_1,
  137127. _vq_quantmap__44u8_p5_1,
  137128. 11,
  137129. 11
  137130. };
  137131. static static_codebook _44u8_p5_1 = {
  137132. 2, 121,
  137133. _vq_lengthlist__44u8_p5_1,
  137134. 1, -531365888, 1611661312, 4, 0,
  137135. _vq_quantlist__44u8_p5_1,
  137136. NULL,
  137137. &_vq_auxt__44u8_p5_1,
  137138. NULL,
  137139. 0
  137140. };
  137141. static long _vq_quantlist__44u8_p6_0[] = {
  137142. 6,
  137143. 5,
  137144. 7,
  137145. 4,
  137146. 8,
  137147. 3,
  137148. 9,
  137149. 2,
  137150. 10,
  137151. 1,
  137152. 11,
  137153. 0,
  137154. 12,
  137155. };
  137156. static long _vq_lengthlist__44u8_p6_0[] = {
  137157. 2, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 4, 6, 5,
  137158. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 4, 6, 6, 7, 7, 8,
  137159. 8, 8, 8, 9, 9,10,10, 6, 7, 7, 7, 8, 8, 8, 8, 9,
  137160. 9,10,10,10, 6, 7, 7, 8, 8, 8, 8, 9, 8,10, 9,11,
  137161. 10, 7, 8, 8, 8, 8, 8, 9, 9, 9,10,10,11,11, 7, 8,
  137162. 8, 8, 8, 9, 8, 9, 9,10,10,11,11, 8, 8, 8, 9, 9,
  137163. 9, 9, 9,10,10,10,11,11, 8, 8, 8, 9, 9, 9, 9,10,
  137164. 9,10,10,11,11, 9, 9, 9, 9,10,10,10,10,10,10,11,
  137165. 11,12, 9, 9, 9,10, 9,10,10,10,10,11,10,12,11,10,
  137166. 10,10,10,10,11,11,11,11,11,12,12,12,10,10,10,10,
  137167. 11,11,11,11,11,12,11,12,12,
  137168. };
  137169. static float _vq_quantthresh__44u8_p6_0[] = {
  137170. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  137171. 12.5, 17.5, 22.5, 27.5,
  137172. };
  137173. static long _vq_quantmap__44u8_p6_0[] = {
  137174. 11, 9, 7, 5, 3, 1, 0, 2,
  137175. 4, 6, 8, 10, 12,
  137176. };
  137177. static encode_aux_threshmatch _vq_auxt__44u8_p6_0 = {
  137178. _vq_quantthresh__44u8_p6_0,
  137179. _vq_quantmap__44u8_p6_0,
  137180. 13,
  137181. 13
  137182. };
  137183. static static_codebook _44u8_p6_0 = {
  137184. 2, 169,
  137185. _vq_lengthlist__44u8_p6_0,
  137186. 1, -526516224, 1616117760, 4, 0,
  137187. _vq_quantlist__44u8_p6_0,
  137188. NULL,
  137189. &_vq_auxt__44u8_p6_0,
  137190. NULL,
  137191. 0
  137192. };
  137193. static long _vq_quantlist__44u8_p6_1[] = {
  137194. 2,
  137195. 1,
  137196. 3,
  137197. 0,
  137198. 4,
  137199. };
  137200. static long _vq_lengthlist__44u8_p6_1[] = {
  137201. 3, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5,
  137202. 5, 5, 5, 5, 5, 5, 5, 5, 5,
  137203. };
  137204. static float _vq_quantthresh__44u8_p6_1[] = {
  137205. -1.5, -0.5, 0.5, 1.5,
  137206. };
  137207. static long _vq_quantmap__44u8_p6_1[] = {
  137208. 3, 1, 0, 2, 4,
  137209. };
  137210. static encode_aux_threshmatch _vq_auxt__44u8_p6_1 = {
  137211. _vq_quantthresh__44u8_p6_1,
  137212. _vq_quantmap__44u8_p6_1,
  137213. 5,
  137214. 5
  137215. };
  137216. static static_codebook _44u8_p6_1 = {
  137217. 2, 25,
  137218. _vq_lengthlist__44u8_p6_1,
  137219. 1, -533725184, 1611661312, 3, 0,
  137220. _vq_quantlist__44u8_p6_1,
  137221. NULL,
  137222. &_vq_auxt__44u8_p6_1,
  137223. NULL,
  137224. 0
  137225. };
  137226. static long _vq_quantlist__44u8_p7_0[] = {
  137227. 6,
  137228. 5,
  137229. 7,
  137230. 4,
  137231. 8,
  137232. 3,
  137233. 9,
  137234. 2,
  137235. 10,
  137236. 1,
  137237. 11,
  137238. 0,
  137239. 12,
  137240. };
  137241. static long _vq_lengthlist__44u8_p7_0[] = {
  137242. 1, 4, 5, 6, 6, 7, 7, 8, 8,10,10,11,11, 5, 6, 6,
  137243. 7, 7, 8, 8, 9, 9,11,10,12,11, 5, 6, 6, 7, 7, 8,
  137244. 8, 9, 9,10,11,11,12, 6, 7, 7, 8, 8, 9, 9,10,10,
  137245. 11,11,12,12, 6, 7, 7, 8, 8, 9, 9,10,10,11,12,13,
  137246. 12, 7, 8, 8, 9, 9,10,10,11,11,12,12,13,13, 8, 8,
  137247. 8, 9, 9,10,10,11,11,12,12,13,13, 9, 9, 9,10,10,
  137248. 11,11,12,12,13,13,14,14, 9, 9, 9,10,10,11,11,12,
  137249. 12,13,13,14,14,10,11,11,12,11,13,12,13,13,14,14,
  137250. 15,15,10,11,11,11,12,12,13,13,14,14,14,15,15,11,
  137251. 12,12,13,13,14,13,15,14,15,15,16,15,11,11,12,13,
  137252. 13,13,14,14,14,15,15,15,16,
  137253. };
  137254. static float _vq_quantthresh__44u8_p7_0[] = {
  137255. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  137256. 27.5, 38.5, 49.5, 60.5,
  137257. };
  137258. static long _vq_quantmap__44u8_p7_0[] = {
  137259. 11, 9, 7, 5, 3, 1, 0, 2,
  137260. 4, 6, 8, 10, 12,
  137261. };
  137262. static encode_aux_threshmatch _vq_auxt__44u8_p7_0 = {
  137263. _vq_quantthresh__44u8_p7_0,
  137264. _vq_quantmap__44u8_p7_0,
  137265. 13,
  137266. 13
  137267. };
  137268. static static_codebook _44u8_p7_0 = {
  137269. 2, 169,
  137270. _vq_lengthlist__44u8_p7_0,
  137271. 1, -523206656, 1618345984, 4, 0,
  137272. _vq_quantlist__44u8_p7_0,
  137273. NULL,
  137274. &_vq_auxt__44u8_p7_0,
  137275. NULL,
  137276. 0
  137277. };
  137278. static long _vq_quantlist__44u8_p7_1[] = {
  137279. 5,
  137280. 4,
  137281. 6,
  137282. 3,
  137283. 7,
  137284. 2,
  137285. 8,
  137286. 1,
  137287. 9,
  137288. 0,
  137289. 10,
  137290. };
  137291. static long _vq_lengthlist__44u8_p7_1[] = {
  137292. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7,
  137293. 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7, 7, 7, 7, 7, 7,
  137294. 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 6, 7, 7, 7,
  137295. 7, 7, 7, 7, 7, 7, 8, 7, 7, 7, 7, 7, 7, 7, 8, 8,
  137296. 8, 8, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 7, 7, 7,
  137297. 8, 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8,
  137298. 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7,
  137299. 7, 8, 8, 8, 8, 8, 8, 8, 8,
  137300. };
  137301. static float _vq_quantthresh__44u8_p7_1[] = {
  137302. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  137303. 3.5, 4.5,
  137304. };
  137305. static long _vq_quantmap__44u8_p7_1[] = {
  137306. 9, 7, 5, 3, 1, 0, 2, 4,
  137307. 6, 8, 10,
  137308. };
  137309. static encode_aux_threshmatch _vq_auxt__44u8_p7_1 = {
  137310. _vq_quantthresh__44u8_p7_1,
  137311. _vq_quantmap__44u8_p7_1,
  137312. 11,
  137313. 11
  137314. };
  137315. static static_codebook _44u8_p7_1 = {
  137316. 2, 121,
  137317. _vq_lengthlist__44u8_p7_1,
  137318. 1, -531365888, 1611661312, 4, 0,
  137319. _vq_quantlist__44u8_p7_1,
  137320. NULL,
  137321. &_vq_auxt__44u8_p7_1,
  137322. NULL,
  137323. 0
  137324. };
  137325. static long _vq_quantlist__44u8_p8_0[] = {
  137326. 7,
  137327. 6,
  137328. 8,
  137329. 5,
  137330. 9,
  137331. 4,
  137332. 10,
  137333. 3,
  137334. 11,
  137335. 2,
  137336. 12,
  137337. 1,
  137338. 13,
  137339. 0,
  137340. 14,
  137341. };
  137342. static long _vq_lengthlist__44u8_p8_0[] = {
  137343. 1, 4, 4, 7, 7, 8, 8, 8, 7, 9, 8,10, 9,11,10, 4,
  137344. 6, 6, 8, 8,10, 9, 9, 9,10,10,11,10,12,10, 4, 6,
  137345. 6, 8, 8,10,10, 9, 9,10,10,11,11,11,12, 7, 8, 8,
  137346. 10,10,11,11,11,10,12,11,12,12,13,11, 7, 8, 8,10,
  137347. 10,11,11,10,10,11,11,12,12,13,13, 8,10,10,11,11,
  137348. 12,11,12,11,13,12,13,12,14,13, 8,10, 9,11,11,12,
  137349. 12,12,12,12,12,13,13,14,13, 8, 9, 9,11,10,12,11,
  137350. 13,12,13,13,14,13,14,13, 8, 9, 9,10,11,12,12,12,
  137351. 12,13,13,14,15,14,14, 9,10,10,12,11,13,12,13,13,
  137352. 14,13,14,14,14,14, 9,10,10,12,12,12,12,13,13,14,
  137353. 14,14,15,14,14,10,11,11,13,12,13,12,14,14,14,14,
  137354. 14,14,15,15,10,11,11,12,12,13,13,14,14,14,15,15,
  137355. 14,16,15,11,12,12,13,12,14,14,14,13,15,14,15,15,
  137356. 15,17,11,12,12,13,13,14,14,14,15,15,14,15,15,14,
  137357. 17,
  137358. };
  137359. static float _vq_quantthresh__44u8_p8_0[] = {
  137360. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  137361. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  137362. };
  137363. static long _vq_quantmap__44u8_p8_0[] = {
  137364. 13, 11, 9, 7, 5, 3, 1, 0,
  137365. 2, 4, 6, 8, 10, 12, 14,
  137366. };
  137367. static encode_aux_threshmatch _vq_auxt__44u8_p8_0 = {
  137368. _vq_quantthresh__44u8_p8_0,
  137369. _vq_quantmap__44u8_p8_0,
  137370. 15,
  137371. 15
  137372. };
  137373. static static_codebook _44u8_p8_0 = {
  137374. 2, 225,
  137375. _vq_lengthlist__44u8_p8_0,
  137376. 1, -520986624, 1620377600, 4, 0,
  137377. _vq_quantlist__44u8_p8_0,
  137378. NULL,
  137379. &_vq_auxt__44u8_p8_0,
  137380. NULL,
  137381. 0
  137382. };
  137383. static long _vq_quantlist__44u8_p8_1[] = {
  137384. 10,
  137385. 9,
  137386. 11,
  137387. 8,
  137388. 12,
  137389. 7,
  137390. 13,
  137391. 6,
  137392. 14,
  137393. 5,
  137394. 15,
  137395. 4,
  137396. 16,
  137397. 3,
  137398. 17,
  137399. 2,
  137400. 18,
  137401. 1,
  137402. 19,
  137403. 0,
  137404. 20,
  137405. };
  137406. static long _vq_lengthlist__44u8_p8_1[] = {
  137407. 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  137408. 9, 9, 9, 9, 9, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  137409. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 5, 6, 6, 7, 7, 8,
  137410. 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 7,
  137411. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137412. 9, 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  137413. 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9,
  137414. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,10, 8, 8,
  137415. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,
  137416. 10, 9,10, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,
  137417. 10,10,10,10,10,10,10,10, 8, 9, 8, 9, 9, 9, 9, 9,
  137418. 9, 9, 9, 9, 9, 9,10,10,10,10, 9,10,10, 9, 9, 9,
  137419. 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,10,10,
  137420. 10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,
  137421. 10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9,10, 9,
  137422. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  137423. 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,
  137424. 10, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  137425. 10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  137426. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,
  137427. 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  137428. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  137429. 10,10,10,10,10, 9, 9, 9,10, 9,10,10,10,10,10,10,
  137430. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  137431. 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  137432. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  137433. 10,10,10,10, 9, 9, 9,10, 9,10, 9,10,10,10,10,10,
  137434. 10,10,10,10,10,10,10,10,10,
  137435. };
  137436. static float _vq_quantthresh__44u8_p8_1[] = {
  137437. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  137438. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  137439. 6.5, 7.5, 8.5, 9.5,
  137440. };
  137441. static long _vq_quantmap__44u8_p8_1[] = {
  137442. 19, 17, 15, 13, 11, 9, 7, 5,
  137443. 3, 1, 0, 2, 4, 6, 8, 10,
  137444. 12, 14, 16, 18, 20,
  137445. };
  137446. static encode_aux_threshmatch _vq_auxt__44u8_p8_1 = {
  137447. _vq_quantthresh__44u8_p8_1,
  137448. _vq_quantmap__44u8_p8_1,
  137449. 21,
  137450. 21
  137451. };
  137452. static static_codebook _44u8_p8_1 = {
  137453. 2, 441,
  137454. _vq_lengthlist__44u8_p8_1,
  137455. 1, -529268736, 1611661312, 5, 0,
  137456. _vq_quantlist__44u8_p8_1,
  137457. NULL,
  137458. &_vq_auxt__44u8_p8_1,
  137459. NULL,
  137460. 0
  137461. };
  137462. static long _vq_quantlist__44u8_p9_0[] = {
  137463. 4,
  137464. 3,
  137465. 5,
  137466. 2,
  137467. 6,
  137468. 1,
  137469. 7,
  137470. 0,
  137471. 8,
  137472. };
  137473. static long _vq_lengthlist__44u8_p9_0[] = {
  137474. 1, 3, 3, 9, 9, 9, 9, 9, 9, 4, 9, 9, 9, 9, 9, 9,
  137475. 9, 9, 5, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137476. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137477. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137478. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8,
  137479. 8,
  137480. };
  137481. static float _vq_quantthresh__44u8_p9_0[] = {
  137482. -3258.5, -2327.5, -1396.5, -465.5, 465.5, 1396.5, 2327.5, 3258.5,
  137483. };
  137484. static long _vq_quantmap__44u8_p9_0[] = {
  137485. 7, 5, 3, 1, 0, 2, 4, 6,
  137486. 8,
  137487. };
  137488. static encode_aux_threshmatch _vq_auxt__44u8_p9_0 = {
  137489. _vq_quantthresh__44u8_p9_0,
  137490. _vq_quantmap__44u8_p9_0,
  137491. 9,
  137492. 9
  137493. };
  137494. static static_codebook _44u8_p9_0 = {
  137495. 2, 81,
  137496. _vq_lengthlist__44u8_p9_0,
  137497. 1, -511895552, 1631393792, 4, 0,
  137498. _vq_quantlist__44u8_p9_0,
  137499. NULL,
  137500. &_vq_auxt__44u8_p9_0,
  137501. NULL,
  137502. 0
  137503. };
  137504. static long _vq_quantlist__44u8_p9_1[] = {
  137505. 9,
  137506. 8,
  137507. 10,
  137508. 7,
  137509. 11,
  137510. 6,
  137511. 12,
  137512. 5,
  137513. 13,
  137514. 4,
  137515. 14,
  137516. 3,
  137517. 15,
  137518. 2,
  137519. 16,
  137520. 1,
  137521. 17,
  137522. 0,
  137523. 18,
  137524. };
  137525. static long _vq_lengthlist__44u8_p9_1[] = {
  137526. 1, 4, 4, 7, 7, 8, 7, 8, 6, 9, 7,10, 8,11,10,11,
  137527. 11,11,11, 4, 7, 6, 9, 9,10, 9, 9, 9,10,10,11,10,
  137528. 11,10,11,11,13,11, 4, 7, 7, 9, 9, 9, 9, 9, 9,10,
  137529. 10,11,10,11,11,11,12,11,12, 7, 9, 8,11,11,11,11,
  137530. 10,10,11,11,12,12,12,12,12,12,14,13, 7, 8, 9,10,
  137531. 11,11,11,10,10,11,11,11,11,12,12,14,12,13,14, 8,
  137532. 9, 9,11,11,11,11,11,11,12,12,14,12,15,14,14,14,
  137533. 15,14, 8, 9, 9,11,11,11,11,12,11,12,12,13,13,13,
  137534. 13,13,13,14,14, 8, 9, 9,11,10,12,11,12,12,13,13,
  137535. 13,13,15,14,14,14,16,16, 8, 9, 9,10,11,11,12,12,
  137536. 12,13,13,13,14,14,14,15,16,15,15, 9,10,10,11,12,
  137537. 12,13,13,13,14,14,16,14,14,16,16,16,16,15, 9,10,
  137538. 10,11,11,12,13,13,14,15,14,16,14,15,16,16,16,16,
  137539. 15,10,11,11,12,13,13,14,15,15,15,15,15,16,15,16,
  137540. 15,16,15,15,10,11,11,13,13,14,13,13,15,14,15,15,
  137541. 16,15,15,15,16,15,16,10,12,12,14,14,14,14,14,16,
  137542. 16,15,15,15,16,16,16,16,16,16,11,12,12,14,14,14,
  137543. 14,15,15,16,15,16,15,16,15,16,16,16,16,12,12,13,
  137544. 14,14,15,16,16,16,16,16,16,15,16,16,16,16,16,16,
  137545. 12,13,13,14,14,14,14,15,16,15,16,16,16,16,16,16,
  137546. 16,16,16,12,13,14,14,14,16,15,16,15,16,16,16,16,
  137547. 16,16,16,16,16,16,12,14,13,14,15,15,15,16,15,16,
  137548. 16,15,16,16,16,16,16,16,16,
  137549. };
  137550. static float _vq_quantthresh__44u8_p9_1[] = {
  137551. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  137552. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  137553. 367.5, 416.5,
  137554. };
  137555. static long _vq_quantmap__44u8_p9_1[] = {
  137556. 17, 15, 13, 11, 9, 7, 5, 3,
  137557. 1, 0, 2, 4, 6, 8, 10, 12,
  137558. 14, 16, 18,
  137559. };
  137560. static encode_aux_threshmatch _vq_auxt__44u8_p9_1 = {
  137561. _vq_quantthresh__44u8_p9_1,
  137562. _vq_quantmap__44u8_p9_1,
  137563. 19,
  137564. 19
  137565. };
  137566. static static_codebook _44u8_p9_1 = {
  137567. 2, 361,
  137568. _vq_lengthlist__44u8_p9_1,
  137569. 1, -518287360, 1622704128, 5, 0,
  137570. _vq_quantlist__44u8_p9_1,
  137571. NULL,
  137572. &_vq_auxt__44u8_p9_1,
  137573. NULL,
  137574. 0
  137575. };
  137576. static long _vq_quantlist__44u8_p9_2[] = {
  137577. 24,
  137578. 23,
  137579. 25,
  137580. 22,
  137581. 26,
  137582. 21,
  137583. 27,
  137584. 20,
  137585. 28,
  137586. 19,
  137587. 29,
  137588. 18,
  137589. 30,
  137590. 17,
  137591. 31,
  137592. 16,
  137593. 32,
  137594. 15,
  137595. 33,
  137596. 14,
  137597. 34,
  137598. 13,
  137599. 35,
  137600. 12,
  137601. 36,
  137602. 11,
  137603. 37,
  137604. 10,
  137605. 38,
  137606. 9,
  137607. 39,
  137608. 8,
  137609. 40,
  137610. 7,
  137611. 41,
  137612. 6,
  137613. 42,
  137614. 5,
  137615. 43,
  137616. 4,
  137617. 44,
  137618. 3,
  137619. 45,
  137620. 2,
  137621. 46,
  137622. 1,
  137623. 47,
  137624. 0,
  137625. 48,
  137626. };
  137627. static long _vq_lengthlist__44u8_p9_2[] = {
  137628. 2, 3, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
  137629. 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137630. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137631. 7,
  137632. };
  137633. static float _vq_quantthresh__44u8_p9_2[] = {
  137634. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  137635. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  137636. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  137637. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  137638. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  137639. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  137640. };
  137641. static long _vq_quantmap__44u8_p9_2[] = {
  137642. 47, 45, 43, 41, 39, 37, 35, 33,
  137643. 31, 29, 27, 25, 23, 21, 19, 17,
  137644. 15, 13, 11, 9, 7, 5, 3, 1,
  137645. 0, 2, 4, 6, 8, 10, 12, 14,
  137646. 16, 18, 20, 22, 24, 26, 28, 30,
  137647. 32, 34, 36, 38, 40, 42, 44, 46,
  137648. 48,
  137649. };
  137650. static encode_aux_threshmatch _vq_auxt__44u8_p9_2 = {
  137651. _vq_quantthresh__44u8_p9_2,
  137652. _vq_quantmap__44u8_p9_2,
  137653. 49,
  137654. 49
  137655. };
  137656. static static_codebook _44u8_p9_2 = {
  137657. 1, 49,
  137658. _vq_lengthlist__44u8_p9_2,
  137659. 1, -526909440, 1611661312, 6, 0,
  137660. _vq_quantlist__44u8_p9_2,
  137661. NULL,
  137662. &_vq_auxt__44u8_p9_2,
  137663. NULL,
  137664. 0
  137665. };
  137666. static long _huff_lengthlist__44u9__long[] = {
  137667. 3, 9,13,13,14,15,14,14,15,15, 5, 5, 9,10,12,12,
  137668. 13,14,16,15,10, 6, 6, 6, 8,11,12,13,16,15,11, 7,
  137669. 5, 3, 5, 8,10,12,15,15,10,10, 7, 4, 3, 5, 8,10,
  137670. 12,12,12,12, 9, 7, 5, 4, 6, 8,10,13,13,12,11, 9,
  137671. 7, 5, 5, 6, 9,12,14,12,12,10, 8, 6, 6, 6, 7,11,
  137672. 13,12,14,13,10, 8, 7, 7, 7,10,11,11,12,13,12,11,
  137673. 10, 8, 8, 9,
  137674. };
  137675. static static_codebook _huff_book__44u9__long = {
  137676. 2, 100,
  137677. _huff_lengthlist__44u9__long,
  137678. 0, 0, 0, 0, 0,
  137679. NULL,
  137680. NULL,
  137681. NULL,
  137682. NULL,
  137683. 0
  137684. };
  137685. static long _huff_lengthlist__44u9__short[] = {
  137686. 9,16,18,18,17,17,17,17,17,17, 5, 8,11,12,11,12,
  137687. 17,17,16,16, 6, 6, 8, 8, 9,10,14,15,16,16, 6, 7,
  137688. 7, 4, 6, 9,13,16,16,16, 6, 6, 7, 4, 5, 8,11,15,
  137689. 17,16, 7, 6, 7, 6, 6, 8, 9,10,14,16,11, 8, 8, 7,
  137690. 6, 6, 3, 4,10,15,14,12,12,10, 5, 6, 3, 3, 8,13,
  137691. 15,17,15,11, 6, 8, 6, 6, 9,14,17,15,15,12, 8,10,
  137692. 9, 9,12,15,
  137693. };
  137694. static static_codebook _huff_book__44u9__short = {
  137695. 2, 100,
  137696. _huff_lengthlist__44u9__short,
  137697. 0, 0, 0, 0, 0,
  137698. NULL,
  137699. NULL,
  137700. NULL,
  137701. NULL,
  137702. 0
  137703. };
  137704. static long _vq_quantlist__44u9_p1_0[] = {
  137705. 1,
  137706. 0,
  137707. 2,
  137708. };
  137709. static long _vq_lengthlist__44u9_p1_0[] = {
  137710. 1, 5, 5, 5, 7, 7, 5, 7, 7, 5, 7, 7, 7, 9, 9, 7,
  137711. 9, 9, 5, 7, 7, 7, 9, 9, 7, 9, 9, 5, 7, 7, 7, 9,
  137712. 9, 7, 9, 9, 8, 9, 9, 9,10,11, 9,11,11, 7, 9, 9,
  137713. 9,11,10, 9,11,11, 5, 7, 7, 7, 9, 9, 8, 9,10, 7,
  137714. 9, 9, 9,11,11, 9,10,11, 7, 9,10, 9,11,11, 9,11,
  137715. 10,
  137716. };
  137717. static float _vq_quantthresh__44u9_p1_0[] = {
  137718. -0.5, 0.5,
  137719. };
  137720. static long _vq_quantmap__44u9_p1_0[] = {
  137721. 1, 0, 2,
  137722. };
  137723. static encode_aux_threshmatch _vq_auxt__44u9_p1_0 = {
  137724. _vq_quantthresh__44u9_p1_0,
  137725. _vq_quantmap__44u9_p1_0,
  137726. 3,
  137727. 3
  137728. };
  137729. static static_codebook _44u9_p1_0 = {
  137730. 4, 81,
  137731. _vq_lengthlist__44u9_p1_0,
  137732. 1, -535822336, 1611661312, 2, 0,
  137733. _vq_quantlist__44u9_p1_0,
  137734. NULL,
  137735. &_vq_auxt__44u9_p1_0,
  137736. NULL,
  137737. 0
  137738. };
  137739. static long _vq_quantlist__44u9_p2_0[] = {
  137740. 2,
  137741. 1,
  137742. 3,
  137743. 0,
  137744. 4,
  137745. };
  137746. static long _vq_lengthlist__44u9_p2_0[] = {
  137747. 3, 5, 5, 8, 8, 5, 7, 7, 9, 9, 6, 7, 7, 9, 9, 8,
  137748. 9, 9,11,10, 8, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 8,
  137749. 8,10,10, 7, 8, 8, 9,10, 9,10,10,11,11, 9, 9,10,
  137750. 11,11, 6, 7, 7, 9, 9, 7, 8, 8,10, 9, 7, 8, 8,10,
  137751. 10, 9,10, 9,11,11, 9,10,10,11,11, 8, 9, 9,11,11,
  137752. 9,10,10,12,11, 9,10,10,11,12,11,11,11,13,13,11,
  137753. 11,11,12,13, 8, 9, 9,11,11, 9,10,10,11,11, 9,10,
  137754. 10,12,11,11,12,11,13,12,11,11,12,13,13, 6, 7, 7,
  137755. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,
  137756. 11, 9,10,10,11,12, 7, 8, 8,10,10, 8, 9, 9,11,11,
  137757. 8, 9, 9,10,10,10,11,11,12,12,10,10,11,12,12, 7,
  137758. 8, 8,10,10, 8, 9, 8,10,10, 8, 9, 9,10,10,10,11,
  137759. 10,12,11,10,10,11,12,12, 9,10,10,11,12,10,11,11,
  137760. 12,12,10,11,10,12,12,12,12,12,13,13,11,12,12,13,
  137761. 13, 9,10,10,11,11, 9,10,10,12,12,10,11,11,12,13,
  137762. 11,12,11,13,12,12,12,12,13,14, 6, 7, 7, 9, 9, 7,
  137763. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,11,11, 9,10,
  137764. 10,11,12, 7, 8, 8,10,10, 8, 9, 9,11,10, 8, 8, 9,
  137765. 10,10,10,11,10,12,12,10,10,11,11,12, 7, 8, 8,10,
  137766. 10, 8, 9, 9,10,10, 8, 9, 9,10,10,10,11,10,12,12,
  137767. 10,11,10,12,12, 9,10,10,12,11,10,11,11,12,12, 9,
  137768. 10,10,12,12,12,12,12,13,13,11,11,12,12,14, 9,10,
  137769. 10,11,12,10,11,11,12,12,10,11,11,12,12,11,12,12,
  137770. 14,14,12,12,12,13,13, 8, 9, 9,11,11, 9,10,10,12,
  137771. 11, 9,10,10,12,12,11,12,11,13,13,11,11,12,13,13,
  137772. 9,10,10,12,12,10,11,11,12,12,10,11,11,12,12,12,
  137773. 12,12,14,14,12,12,12,13,13, 9,10,10,12,11,10,11,
  137774. 10,12,12,10,11,11,12,12,11,12,12,14,13,12,12,12,
  137775. 13,14,11,12,11,13,13,11,12,12,13,13,12,12,12,14,
  137776. 14,13,13,13,13,15,13,13,14,15,15,11,11,11,13,13,
  137777. 11,12,11,13,13,11,12,12,13,13,12,13,12,15,13,13,
  137778. 13,14,14,15, 8, 9, 9,11,11, 9,10,10,11,12, 9,10,
  137779. 10,11,12,11,12,11,13,13,11,12,12,13,13, 9,10,10,
  137780. 11,12,10,11,10,12,12,10,10,11,12,13,12,12,12,14,
  137781. 13,11,12,12,13,14, 9,10,10,12,12,10,11,11,12,12,
  137782. 10,11,11,12,12,12,12,12,14,13,12,12,12,14,13,11,
  137783. 11,11,13,13,11,12,12,14,13,11,11,12,13,13,13,13,
  137784. 13,15,14,12,12,13,13,15,11,12,12,13,13,12,12,12,
  137785. 13,14,11,12,12,13,13,13,13,14,14,15,13,13,13,14,
  137786. 14,
  137787. };
  137788. static float _vq_quantthresh__44u9_p2_0[] = {
  137789. -1.5, -0.5, 0.5, 1.5,
  137790. };
  137791. static long _vq_quantmap__44u9_p2_0[] = {
  137792. 3, 1, 0, 2, 4,
  137793. };
  137794. static encode_aux_threshmatch _vq_auxt__44u9_p2_0 = {
  137795. _vq_quantthresh__44u9_p2_0,
  137796. _vq_quantmap__44u9_p2_0,
  137797. 5,
  137798. 5
  137799. };
  137800. static static_codebook _44u9_p2_0 = {
  137801. 4, 625,
  137802. _vq_lengthlist__44u9_p2_0,
  137803. 1, -533725184, 1611661312, 3, 0,
  137804. _vq_quantlist__44u9_p2_0,
  137805. NULL,
  137806. &_vq_auxt__44u9_p2_0,
  137807. NULL,
  137808. 0
  137809. };
  137810. static long _vq_quantlist__44u9_p3_0[] = {
  137811. 4,
  137812. 3,
  137813. 5,
  137814. 2,
  137815. 6,
  137816. 1,
  137817. 7,
  137818. 0,
  137819. 8,
  137820. };
  137821. static long _vq_lengthlist__44u9_p3_0[] = {
  137822. 3, 4, 4, 5, 5, 7, 7, 8, 8, 4, 5, 5, 6, 6, 7, 7,
  137823. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  137824. 8, 8, 9, 9, 5, 6, 6, 7, 7, 8, 8, 9, 9, 7, 7, 7,
  137825. 8, 8, 9, 9,10,10, 7, 7, 7, 8, 8, 9, 9,10,10, 8,
  137826. 9, 9,10, 9,10,10,11,11, 8, 9, 9, 9,10,10,10,11,
  137827. 11,
  137828. };
  137829. static float _vq_quantthresh__44u9_p3_0[] = {
  137830. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  137831. };
  137832. static long _vq_quantmap__44u9_p3_0[] = {
  137833. 7, 5, 3, 1, 0, 2, 4, 6,
  137834. 8,
  137835. };
  137836. static encode_aux_threshmatch _vq_auxt__44u9_p3_0 = {
  137837. _vq_quantthresh__44u9_p3_0,
  137838. _vq_quantmap__44u9_p3_0,
  137839. 9,
  137840. 9
  137841. };
  137842. static static_codebook _44u9_p3_0 = {
  137843. 2, 81,
  137844. _vq_lengthlist__44u9_p3_0,
  137845. 1, -531628032, 1611661312, 4, 0,
  137846. _vq_quantlist__44u9_p3_0,
  137847. NULL,
  137848. &_vq_auxt__44u9_p3_0,
  137849. NULL,
  137850. 0
  137851. };
  137852. static long _vq_quantlist__44u9_p4_0[] = {
  137853. 8,
  137854. 7,
  137855. 9,
  137856. 6,
  137857. 10,
  137858. 5,
  137859. 11,
  137860. 4,
  137861. 12,
  137862. 3,
  137863. 13,
  137864. 2,
  137865. 14,
  137866. 1,
  137867. 15,
  137868. 0,
  137869. 16,
  137870. };
  137871. static long _vq_lengthlist__44u9_p4_0[] = {
  137872. 4, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  137873. 11, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,
  137874. 11,11, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,
  137875. 10,11,11, 6, 6, 6, 7, 6, 7, 7, 8, 8, 9, 9,10,10,
  137876. 11,11,12,11, 6, 6, 6, 6, 7, 7, 7, 8, 8, 9, 9,10,
  137877. 10,11,11,11,12, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,
  137878. 10,10,11,11,12,12, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9,
  137879. 9,10,10,11,11,12,12, 8, 8, 8, 8, 8, 9, 8,10, 9,
  137880. 10,10,11,10,12,11,13,12, 8, 8, 8, 8, 8, 9, 9, 9,
  137881. 10,10,10,10,11,11,12,12,12, 8, 8, 8, 9, 9, 9, 9,
  137882. 10,10,11,10,12,11,12,12,13,12, 8, 8, 8, 9, 9, 9,
  137883. 9,10,10,10,11,11,11,12,12,12,13, 9, 9, 9,10,10,
  137884. 10,10,11,10,11,11,12,11,13,12,13,13, 9, 9,10,10,
  137885. 10,10,10,10,11,11,11,11,12,12,13,13,13,10,11,10,
  137886. 11,11,11,11,12,11,12,12,13,12,13,13,14,13,10,10,
  137887. 10,11,11,11,11,11,12,12,12,12,13,13,13,13,14,11,
  137888. 11,11,12,11,12,12,12,12,13,13,13,13,14,13,14,14,
  137889. 11,11,11,11,12,12,12,12,12,12,13,13,13,13,14,14,
  137890. 14,
  137891. };
  137892. static float _vq_quantthresh__44u9_p4_0[] = {
  137893. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  137894. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  137895. };
  137896. static long _vq_quantmap__44u9_p4_0[] = {
  137897. 15, 13, 11, 9, 7, 5, 3, 1,
  137898. 0, 2, 4, 6, 8, 10, 12, 14,
  137899. 16,
  137900. };
  137901. static encode_aux_threshmatch _vq_auxt__44u9_p4_0 = {
  137902. _vq_quantthresh__44u9_p4_0,
  137903. _vq_quantmap__44u9_p4_0,
  137904. 17,
  137905. 17
  137906. };
  137907. static static_codebook _44u9_p4_0 = {
  137908. 2, 289,
  137909. _vq_lengthlist__44u9_p4_0,
  137910. 1, -529530880, 1611661312, 5, 0,
  137911. _vq_quantlist__44u9_p4_0,
  137912. NULL,
  137913. &_vq_auxt__44u9_p4_0,
  137914. NULL,
  137915. 0
  137916. };
  137917. static long _vq_quantlist__44u9_p5_0[] = {
  137918. 1,
  137919. 0,
  137920. 2,
  137921. };
  137922. static long _vq_lengthlist__44u9_p5_0[] = {
  137923. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 8, 9, 9, 7,
  137924. 9, 9, 5, 8, 8, 7, 9, 9, 8, 9, 9, 5, 8, 8, 8,10,
  137925. 10, 8,10,10, 7,10,10, 9,10,12, 9,11,11, 7,10,10,
  137926. 9,11,10, 9,11,12, 5, 8, 8, 8,10,10, 8,10,10, 7,
  137927. 10,10, 9,12,11, 9,10,11, 7,10,10, 9,11,11,10,12,
  137928. 10,
  137929. };
  137930. static float _vq_quantthresh__44u9_p5_0[] = {
  137931. -5.5, 5.5,
  137932. };
  137933. static long _vq_quantmap__44u9_p5_0[] = {
  137934. 1, 0, 2,
  137935. };
  137936. static encode_aux_threshmatch _vq_auxt__44u9_p5_0 = {
  137937. _vq_quantthresh__44u9_p5_0,
  137938. _vq_quantmap__44u9_p5_0,
  137939. 3,
  137940. 3
  137941. };
  137942. static static_codebook _44u9_p5_0 = {
  137943. 4, 81,
  137944. _vq_lengthlist__44u9_p5_0,
  137945. 1, -529137664, 1618345984, 2, 0,
  137946. _vq_quantlist__44u9_p5_0,
  137947. NULL,
  137948. &_vq_auxt__44u9_p5_0,
  137949. NULL,
  137950. 0
  137951. };
  137952. static long _vq_quantlist__44u9_p5_1[] = {
  137953. 5,
  137954. 4,
  137955. 6,
  137956. 3,
  137957. 7,
  137958. 2,
  137959. 8,
  137960. 1,
  137961. 9,
  137962. 0,
  137963. 10,
  137964. };
  137965. static long _vq_lengthlist__44u9_p5_1[] = {
  137966. 5, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 6, 6,
  137967. 7, 7, 7, 7, 8, 7, 5, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  137968. 7, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 6, 6, 6, 7,
  137969. 7, 7, 7, 7, 7, 8, 8, 7, 7, 7, 7, 7, 8, 7, 8, 8,
  137970. 8, 8, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  137971. 8, 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 8, 8, 8, 8,
  137972. 8, 8, 8, 7, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8,
  137973. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  137974. };
  137975. static float _vq_quantthresh__44u9_p5_1[] = {
  137976. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  137977. 3.5, 4.5,
  137978. };
  137979. static long _vq_quantmap__44u9_p5_1[] = {
  137980. 9, 7, 5, 3, 1, 0, 2, 4,
  137981. 6, 8, 10,
  137982. };
  137983. static encode_aux_threshmatch _vq_auxt__44u9_p5_1 = {
  137984. _vq_quantthresh__44u9_p5_1,
  137985. _vq_quantmap__44u9_p5_1,
  137986. 11,
  137987. 11
  137988. };
  137989. static static_codebook _44u9_p5_1 = {
  137990. 2, 121,
  137991. _vq_lengthlist__44u9_p5_1,
  137992. 1, -531365888, 1611661312, 4, 0,
  137993. _vq_quantlist__44u9_p5_1,
  137994. NULL,
  137995. &_vq_auxt__44u9_p5_1,
  137996. NULL,
  137997. 0
  137998. };
  137999. static long _vq_quantlist__44u9_p6_0[] = {
  138000. 6,
  138001. 5,
  138002. 7,
  138003. 4,
  138004. 8,
  138005. 3,
  138006. 9,
  138007. 2,
  138008. 10,
  138009. 1,
  138010. 11,
  138011. 0,
  138012. 12,
  138013. };
  138014. static long _vq_lengthlist__44u9_p6_0[] = {
  138015. 2, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 4, 6, 5,
  138016. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 4, 5, 6, 7, 7, 8,
  138017. 8, 8, 8, 9, 9,10,10, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  138018. 10,10,10,10, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,10,
  138019. 10, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,11, 7, 8,
  138020. 8, 8, 8, 9, 9, 9, 9,10,10,11,11, 8, 8, 8, 9, 9,
  138021. 9, 9, 9,10,10,10,11,11, 8, 8, 8, 9, 9, 9, 9,10,
  138022. 9,10,10,11,11, 9, 9, 9,10,10,10,10,10,11,11,11,
  138023. 11,12, 9, 9, 9,10,10,10,10,10,10,11,10,12,11,10,
  138024. 10,10,10,10,11,11,11,11,11,12,12,12,10,10,10,10,
  138025. 10,11,11,11,11,12,11,12,12,
  138026. };
  138027. static float _vq_quantthresh__44u9_p6_0[] = {
  138028. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  138029. 12.5, 17.5, 22.5, 27.5,
  138030. };
  138031. static long _vq_quantmap__44u9_p6_0[] = {
  138032. 11, 9, 7, 5, 3, 1, 0, 2,
  138033. 4, 6, 8, 10, 12,
  138034. };
  138035. static encode_aux_threshmatch _vq_auxt__44u9_p6_0 = {
  138036. _vq_quantthresh__44u9_p6_0,
  138037. _vq_quantmap__44u9_p6_0,
  138038. 13,
  138039. 13
  138040. };
  138041. static static_codebook _44u9_p6_0 = {
  138042. 2, 169,
  138043. _vq_lengthlist__44u9_p6_0,
  138044. 1, -526516224, 1616117760, 4, 0,
  138045. _vq_quantlist__44u9_p6_0,
  138046. NULL,
  138047. &_vq_auxt__44u9_p6_0,
  138048. NULL,
  138049. 0
  138050. };
  138051. static long _vq_quantlist__44u9_p6_1[] = {
  138052. 2,
  138053. 1,
  138054. 3,
  138055. 0,
  138056. 4,
  138057. };
  138058. static long _vq_lengthlist__44u9_p6_1[] = {
  138059. 4, 4, 4, 5, 5, 4, 5, 4, 5, 5, 4, 4, 5, 5, 5, 5,
  138060. 5, 5, 5, 5, 5, 5, 5, 5, 5,
  138061. };
  138062. static float _vq_quantthresh__44u9_p6_1[] = {
  138063. -1.5, -0.5, 0.5, 1.5,
  138064. };
  138065. static long _vq_quantmap__44u9_p6_1[] = {
  138066. 3, 1, 0, 2, 4,
  138067. };
  138068. static encode_aux_threshmatch _vq_auxt__44u9_p6_1 = {
  138069. _vq_quantthresh__44u9_p6_1,
  138070. _vq_quantmap__44u9_p6_1,
  138071. 5,
  138072. 5
  138073. };
  138074. static static_codebook _44u9_p6_1 = {
  138075. 2, 25,
  138076. _vq_lengthlist__44u9_p6_1,
  138077. 1, -533725184, 1611661312, 3, 0,
  138078. _vq_quantlist__44u9_p6_1,
  138079. NULL,
  138080. &_vq_auxt__44u9_p6_1,
  138081. NULL,
  138082. 0
  138083. };
  138084. static long _vq_quantlist__44u9_p7_0[] = {
  138085. 6,
  138086. 5,
  138087. 7,
  138088. 4,
  138089. 8,
  138090. 3,
  138091. 9,
  138092. 2,
  138093. 10,
  138094. 1,
  138095. 11,
  138096. 0,
  138097. 12,
  138098. };
  138099. static long _vq_lengthlist__44u9_p7_0[] = {
  138100. 1, 4, 5, 6, 6, 7, 7, 8, 9,10,10,11,11, 5, 6, 6,
  138101. 7, 7, 8, 8, 9, 9,10,10,11,11, 5, 6, 6, 7, 7, 8,
  138102. 8, 9, 9,10,10,11,11, 6, 7, 7, 8, 8, 9, 9,10,10,
  138103. 11,11,12,12, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,12,
  138104. 12, 8, 8, 8, 9, 9,10,10,11,11,12,12,13,13, 8, 8,
  138105. 8, 9, 9,10,10,11,11,12,12,13,13, 9, 9, 9,10,10,
  138106. 11,11,12,12,13,13,13,13, 9, 9, 9,10,10,11,11,12,
  138107. 12,13,13,14,14,10,10,10,11,11,12,12,13,13,14,13,
  138108. 15,14,10,10,10,11,11,12,12,13,13,14,14,14,14,11,
  138109. 11,12,12,12,13,13,14,14,14,14,15,15,11,11,12,12,
  138110. 12,13,13,14,14,14,15,15,15,
  138111. };
  138112. static float _vq_quantthresh__44u9_p7_0[] = {
  138113. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  138114. 27.5, 38.5, 49.5, 60.5,
  138115. };
  138116. static long _vq_quantmap__44u9_p7_0[] = {
  138117. 11, 9, 7, 5, 3, 1, 0, 2,
  138118. 4, 6, 8, 10, 12,
  138119. };
  138120. static encode_aux_threshmatch _vq_auxt__44u9_p7_0 = {
  138121. _vq_quantthresh__44u9_p7_0,
  138122. _vq_quantmap__44u9_p7_0,
  138123. 13,
  138124. 13
  138125. };
  138126. static static_codebook _44u9_p7_0 = {
  138127. 2, 169,
  138128. _vq_lengthlist__44u9_p7_0,
  138129. 1, -523206656, 1618345984, 4, 0,
  138130. _vq_quantlist__44u9_p7_0,
  138131. NULL,
  138132. &_vq_auxt__44u9_p7_0,
  138133. NULL,
  138134. 0
  138135. };
  138136. static long _vq_quantlist__44u9_p7_1[] = {
  138137. 5,
  138138. 4,
  138139. 6,
  138140. 3,
  138141. 7,
  138142. 2,
  138143. 8,
  138144. 1,
  138145. 9,
  138146. 0,
  138147. 10,
  138148. };
  138149. static long _vq_lengthlist__44u9_p7_1[] = {
  138150. 5, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 7, 7,
  138151. 7, 7, 7, 7, 7, 7, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7,
  138152. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 7, 7, 7,
  138153. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  138154. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  138155. 7, 7, 7, 7, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  138156. 7, 8, 8, 7, 7, 7, 7, 7, 7, 7, 8, 7, 8, 8, 7, 7,
  138157. 7, 7, 7, 7, 7, 8, 8, 8, 8,
  138158. };
  138159. static float _vq_quantthresh__44u9_p7_1[] = {
  138160. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  138161. 3.5, 4.5,
  138162. };
  138163. static long _vq_quantmap__44u9_p7_1[] = {
  138164. 9, 7, 5, 3, 1, 0, 2, 4,
  138165. 6, 8, 10,
  138166. };
  138167. static encode_aux_threshmatch _vq_auxt__44u9_p7_1 = {
  138168. _vq_quantthresh__44u9_p7_1,
  138169. _vq_quantmap__44u9_p7_1,
  138170. 11,
  138171. 11
  138172. };
  138173. static static_codebook _44u9_p7_1 = {
  138174. 2, 121,
  138175. _vq_lengthlist__44u9_p7_1,
  138176. 1, -531365888, 1611661312, 4, 0,
  138177. _vq_quantlist__44u9_p7_1,
  138178. NULL,
  138179. &_vq_auxt__44u9_p7_1,
  138180. NULL,
  138181. 0
  138182. };
  138183. static long _vq_quantlist__44u9_p8_0[] = {
  138184. 7,
  138185. 6,
  138186. 8,
  138187. 5,
  138188. 9,
  138189. 4,
  138190. 10,
  138191. 3,
  138192. 11,
  138193. 2,
  138194. 12,
  138195. 1,
  138196. 13,
  138197. 0,
  138198. 14,
  138199. };
  138200. static long _vq_lengthlist__44u9_p8_0[] = {
  138201. 1, 4, 4, 7, 7, 8, 8, 8, 8, 9, 9,10, 9,11,10, 4,
  138202. 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,10,12,10, 4, 6,
  138203. 6, 8, 8, 9,10, 9, 9,10,10,11,11,12,12, 7, 8, 8,
  138204. 10,10,11,11,10,10,11,11,12,12,13,12, 7, 8, 8,10,
  138205. 10,11,11,10,10,11,11,12,12,12,13, 8,10, 9,11,11,
  138206. 12,12,11,11,12,12,13,13,14,13, 8, 9, 9,11,11,12,
  138207. 12,11,12,12,12,13,13,14,13, 8, 9, 9,10,10,12,11,
  138208. 13,12,13,13,14,13,15,14, 8, 9, 9,10,10,11,12,12,
  138209. 12,13,13,13,14,14,14, 9,10,10,12,11,13,12,13,13,
  138210. 14,13,14,14,14,15, 9,10,10,11,12,12,12,13,13,14,
  138211. 14,14,15,15,15,10,11,11,12,12,13,13,14,14,14,14,
  138212. 15,14,16,15,10,11,11,12,12,13,13,13,14,14,14,14,
  138213. 14,15,16,11,12,12,13,13,14,13,14,14,15,14,15,16,
  138214. 16,16,11,12,12,13,13,14,13,14,14,15,15,15,16,15,
  138215. 15,
  138216. };
  138217. static float _vq_quantthresh__44u9_p8_0[] = {
  138218. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  138219. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  138220. };
  138221. static long _vq_quantmap__44u9_p8_0[] = {
  138222. 13, 11, 9, 7, 5, 3, 1, 0,
  138223. 2, 4, 6, 8, 10, 12, 14,
  138224. };
  138225. static encode_aux_threshmatch _vq_auxt__44u9_p8_0 = {
  138226. _vq_quantthresh__44u9_p8_0,
  138227. _vq_quantmap__44u9_p8_0,
  138228. 15,
  138229. 15
  138230. };
  138231. static static_codebook _44u9_p8_0 = {
  138232. 2, 225,
  138233. _vq_lengthlist__44u9_p8_0,
  138234. 1, -520986624, 1620377600, 4, 0,
  138235. _vq_quantlist__44u9_p8_0,
  138236. NULL,
  138237. &_vq_auxt__44u9_p8_0,
  138238. NULL,
  138239. 0
  138240. };
  138241. static long _vq_quantlist__44u9_p8_1[] = {
  138242. 10,
  138243. 9,
  138244. 11,
  138245. 8,
  138246. 12,
  138247. 7,
  138248. 13,
  138249. 6,
  138250. 14,
  138251. 5,
  138252. 15,
  138253. 4,
  138254. 16,
  138255. 3,
  138256. 17,
  138257. 2,
  138258. 18,
  138259. 1,
  138260. 19,
  138261. 0,
  138262. 20,
  138263. };
  138264. static long _vq_lengthlist__44u9_p8_1[] = {
  138265. 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  138266. 9, 9, 9, 9, 9, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  138267. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 6, 6, 6, 7, 7, 8,
  138268. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 7,
  138269. 7, 7, 8, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  138270. 9, 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  138271. 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9,
  138272. 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10, 8, 8,
  138273. 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  138274. 9,10,10, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  138275. 10, 9,10, 9,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9,
  138276. 9, 9, 9, 9, 9,10,10, 9,10,10,10,10,10, 9, 9, 9,
  138277. 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,10,10,
  138278. 10,10, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  138279. 10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  138280. 9, 9,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  138281. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  138282. 10, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,10,10,
  138283. 10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  138284. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,
  138285. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138286. 9, 9, 9, 9,10, 9, 9,10,10,10,10,10,10,10,10,10,
  138287. 10,10,10,10,10, 9, 9, 9,10, 9,10, 9,10,10,10,10,
  138288. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9,10, 9,10,
  138289. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  138290. 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  138291. 10,10,10,10, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  138292. 10,10,10,10,10,10,10,10,10,
  138293. };
  138294. static float _vq_quantthresh__44u9_p8_1[] = {
  138295. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  138296. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  138297. 6.5, 7.5, 8.5, 9.5,
  138298. };
  138299. static long _vq_quantmap__44u9_p8_1[] = {
  138300. 19, 17, 15, 13, 11, 9, 7, 5,
  138301. 3, 1, 0, 2, 4, 6, 8, 10,
  138302. 12, 14, 16, 18, 20,
  138303. };
  138304. static encode_aux_threshmatch _vq_auxt__44u9_p8_1 = {
  138305. _vq_quantthresh__44u9_p8_1,
  138306. _vq_quantmap__44u9_p8_1,
  138307. 21,
  138308. 21
  138309. };
  138310. static static_codebook _44u9_p8_1 = {
  138311. 2, 441,
  138312. _vq_lengthlist__44u9_p8_1,
  138313. 1, -529268736, 1611661312, 5, 0,
  138314. _vq_quantlist__44u9_p8_1,
  138315. NULL,
  138316. &_vq_auxt__44u9_p8_1,
  138317. NULL,
  138318. 0
  138319. };
  138320. static long _vq_quantlist__44u9_p9_0[] = {
  138321. 7,
  138322. 6,
  138323. 8,
  138324. 5,
  138325. 9,
  138326. 4,
  138327. 10,
  138328. 3,
  138329. 11,
  138330. 2,
  138331. 12,
  138332. 1,
  138333. 13,
  138334. 0,
  138335. 14,
  138336. };
  138337. static long _vq_lengthlist__44u9_p9_0[] = {
  138338. 1, 3, 3,11,11,11,11,11,11,11,11,11,11,11,11, 4,
  138339. 10,11,11,11,11,11,11,11,11,11,11,11,11,11, 4,10,
  138340. 10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138341. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138342. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138343. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138344. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138345. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138346. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138347. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138348. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138349. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138350. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138351. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138352. 10,
  138353. };
  138354. static float _vq_quantthresh__44u9_p9_0[] = {
  138355. -6051.5, -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -465.5, 465.5,
  138356. 1396.5, 2327.5, 3258.5, 4189.5, 5120.5, 6051.5,
  138357. };
  138358. static long _vq_quantmap__44u9_p9_0[] = {
  138359. 13, 11, 9, 7, 5, 3, 1, 0,
  138360. 2, 4, 6, 8, 10, 12, 14,
  138361. };
  138362. static encode_aux_threshmatch _vq_auxt__44u9_p9_0 = {
  138363. _vq_quantthresh__44u9_p9_0,
  138364. _vq_quantmap__44u9_p9_0,
  138365. 15,
  138366. 15
  138367. };
  138368. static static_codebook _44u9_p9_0 = {
  138369. 2, 225,
  138370. _vq_lengthlist__44u9_p9_0,
  138371. 1, -510036736, 1631393792, 4, 0,
  138372. _vq_quantlist__44u9_p9_0,
  138373. NULL,
  138374. &_vq_auxt__44u9_p9_0,
  138375. NULL,
  138376. 0
  138377. };
  138378. static long _vq_quantlist__44u9_p9_1[] = {
  138379. 9,
  138380. 8,
  138381. 10,
  138382. 7,
  138383. 11,
  138384. 6,
  138385. 12,
  138386. 5,
  138387. 13,
  138388. 4,
  138389. 14,
  138390. 3,
  138391. 15,
  138392. 2,
  138393. 16,
  138394. 1,
  138395. 17,
  138396. 0,
  138397. 18,
  138398. };
  138399. static long _vq_lengthlist__44u9_p9_1[] = {
  138400. 1, 4, 4, 7, 7, 8, 7, 8, 7, 9, 8,10, 9,10,10,11,
  138401. 11,12,12, 4, 7, 6, 9, 9,10, 9, 9, 8,10,10,11,10,
  138402. 12,10,13,12,13,12, 4, 6, 6, 9, 9, 9, 9, 9, 9,10,
  138403. 10,11,11,11,12,12,12,12,12, 7, 9, 8,11,10,10,10,
  138404. 11,10,11,11,12,12,13,12,13,13,13,13, 7, 8, 9,10,
  138405. 10,11,11,10,10,11,11,11,12,13,13,13,13,14,14, 8,
  138406. 9, 9,11,11,12,11,12,12,13,12,12,13,13,14,15,14,
  138407. 14,14, 8, 9, 9,10,11,11,11,12,12,13,12,13,13,14,
  138408. 14,14,15,14,16, 8, 9, 9,11,10,12,12,12,12,15,13,
  138409. 13,13,17,14,15,15,15,14, 8, 9, 9,10,11,11,12,13,
  138410. 12,13,13,13,14,15,14,14,14,16,15, 9,11,10,12,12,
  138411. 13,13,13,13,14,14,16,15,14,14,14,15,15,17, 9,10,
  138412. 10,11,11,13,13,13,14,14,13,15,14,15,14,15,16,15,
  138413. 16,10,11,11,12,12,13,14,15,14,15,14,14,15,17,16,
  138414. 15,15,17,17,10,12,11,13,12,14,14,13,14,15,15,15,
  138415. 15,16,17,17,15,17,16,11,12,12,14,13,15,14,15,16,
  138416. 17,15,17,15,17,15,15,16,17,15,11,11,12,14,14,14,
  138417. 14,14,15,15,16,15,17,17,17,16,17,16,15,12,12,13,
  138418. 14,14,14,15,14,15,15,16,16,17,16,17,15,17,17,16,
  138419. 12,14,12,14,14,15,15,15,14,14,16,16,16,15,16,16,
  138420. 15,17,15,12,13,13,14,15,14,15,17,15,17,16,17,17,
  138421. 17,16,17,16,17,17,12,13,13,14,16,15,15,15,16,15,
  138422. 17,17,15,17,15,17,16,16,17,
  138423. };
  138424. static float _vq_quantthresh__44u9_p9_1[] = {
  138425. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  138426. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  138427. 367.5, 416.5,
  138428. };
  138429. static long _vq_quantmap__44u9_p9_1[] = {
  138430. 17, 15, 13, 11, 9, 7, 5, 3,
  138431. 1, 0, 2, 4, 6, 8, 10, 12,
  138432. 14, 16, 18,
  138433. };
  138434. static encode_aux_threshmatch _vq_auxt__44u9_p9_1 = {
  138435. _vq_quantthresh__44u9_p9_1,
  138436. _vq_quantmap__44u9_p9_1,
  138437. 19,
  138438. 19
  138439. };
  138440. static static_codebook _44u9_p9_1 = {
  138441. 2, 361,
  138442. _vq_lengthlist__44u9_p9_1,
  138443. 1, -518287360, 1622704128, 5, 0,
  138444. _vq_quantlist__44u9_p9_1,
  138445. NULL,
  138446. &_vq_auxt__44u9_p9_1,
  138447. NULL,
  138448. 0
  138449. };
  138450. static long _vq_quantlist__44u9_p9_2[] = {
  138451. 24,
  138452. 23,
  138453. 25,
  138454. 22,
  138455. 26,
  138456. 21,
  138457. 27,
  138458. 20,
  138459. 28,
  138460. 19,
  138461. 29,
  138462. 18,
  138463. 30,
  138464. 17,
  138465. 31,
  138466. 16,
  138467. 32,
  138468. 15,
  138469. 33,
  138470. 14,
  138471. 34,
  138472. 13,
  138473. 35,
  138474. 12,
  138475. 36,
  138476. 11,
  138477. 37,
  138478. 10,
  138479. 38,
  138480. 9,
  138481. 39,
  138482. 8,
  138483. 40,
  138484. 7,
  138485. 41,
  138486. 6,
  138487. 42,
  138488. 5,
  138489. 43,
  138490. 4,
  138491. 44,
  138492. 3,
  138493. 45,
  138494. 2,
  138495. 46,
  138496. 1,
  138497. 47,
  138498. 0,
  138499. 48,
  138500. };
  138501. static long _vq_lengthlist__44u9_p9_2[] = {
  138502. 2, 4, 4, 5, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6,
  138503. 6, 6, 6, 7, 6, 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  138504. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  138505. 7,
  138506. };
  138507. static float _vq_quantthresh__44u9_p9_2[] = {
  138508. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  138509. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  138510. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  138511. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  138512. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  138513. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  138514. };
  138515. static long _vq_quantmap__44u9_p9_2[] = {
  138516. 47, 45, 43, 41, 39, 37, 35, 33,
  138517. 31, 29, 27, 25, 23, 21, 19, 17,
  138518. 15, 13, 11, 9, 7, 5, 3, 1,
  138519. 0, 2, 4, 6, 8, 10, 12, 14,
  138520. 16, 18, 20, 22, 24, 26, 28, 30,
  138521. 32, 34, 36, 38, 40, 42, 44, 46,
  138522. 48,
  138523. };
  138524. static encode_aux_threshmatch _vq_auxt__44u9_p9_2 = {
  138525. _vq_quantthresh__44u9_p9_2,
  138526. _vq_quantmap__44u9_p9_2,
  138527. 49,
  138528. 49
  138529. };
  138530. static static_codebook _44u9_p9_2 = {
  138531. 1, 49,
  138532. _vq_lengthlist__44u9_p9_2,
  138533. 1, -526909440, 1611661312, 6, 0,
  138534. _vq_quantlist__44u9_p9_2,
  138535. NULL,
  138536. &_vq_auxt__44u9_p9_2,
  138537. NULL,
  138538. 0
  138539. };
  138540. static long _huff_lengthlist__44un1__long[] = {
  138541. 5, 6,12, 9,14, 9, 9,19, 6, 1, 5, 5, 8, 7, 9,19,
  138542. 12, 4, 4, 7, 7, 9,11,18, 9, 5, 6, 6, 8, 7, 8,17,
  138543. 14, 8, 7, 8, 8,10,12,18, 9, 6, 8, 6, 8, 6, 8,18,
  138544. 9, 8,11, 8,11, 7, 5,15,16,18,18,18,17,15,11,18,
  138545. };
  138546. static static_codebook _huff_book__44un1__long = {
  138547. 2, 64,
  138548. _huff_lengthlist__44un1__long,
  138549. 0, 0, 0, 0, 0,
  138550. NULL,
  138551. NULL,
  138552. NULL,
  138553. NULL,
  138554. 0
  138555. };
  138556. static long _vq_quantlist__44un1__p1_0[] = {
  138557. 1,
  138558. 0,
  138559. 2,
  138560. };
  138561. static long _vq_lengthlist__44un1__p1_0[] = {
  138562. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,10,11, 8,
  138563. 10,11, 5, 8, 8, 8,11,10, 8,11,10, 4, 9, 9, 8,11,
  138564. 11, 8,11,11, 8,12,11,10,12,14,11,13,13, 7,11,11,
  138565. 10,13,11,11,13,14, 4, 8, 9, 8,11,11, 8,11,12, 7,
  138566. 11,11,11,14,13,10,11,13, 8,11,12,11,13,13,10,14,
  138567. 12,
  138568. };
  138569. static float _vq_quantthresh__44un1__p1_0[] = {
  138570. -0.5, 0.5,
  138571. };
  138572. static long _vq_quantmap__44un1__p1_0[] = {
  138573. 1, 0, 2,
  138574. };
  138575. static encode_aux_threshmatch _vq_auxt__44un1__p1_0 = {
  138576. _vq_quantthresh__44un1__p1_0,
  138577. _vq_quantmap__44un1__p1_0,
  138578. 3,
  138579. 3
  138580. };
  138581. static static_codebook _44un1__p1_0 = {
  138582. 4, 81,
  138583. _vq_lengthlist__44un1__p1_0,
  138584. 1, -535822336, 1611661312, 2, 0,
  138585. _vq_quantlist__44un1__p1_0,
  138586. NULL,
  138587. &_vq_auxt__44un1__p1_0,
  138588. NULL,
  138589. 0
  138590. };
  138591. static long _vq_quantlist__44un1__p2_0[] = {
  138592. 1,
  138593. 0,
  138594. 2,
  138595. };
  138596. static long _vq_lengthlist__44un1__p2_0[] = {
  138597. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 8, 6,
  138598. 7, 9, 5, 7, 7, 6, 8, 7, 7, 9, 8, 4, 7, 7, 7, 9,
  138599. 8, 7, 8, 8, 7, 9, 8, 8, 8,10, 9,10,10, 6, 8, 8,
  138600. 7,10, 8, 9,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 9, 6,
  138601. 8, 8, 9,10,10, 7, 8,10, 6, 8, 9, 9,10,10, 8,10,
  138602. 8,
  138603. };
  138604. static float _vq_quantthresh__44un1__p2_0[] = {
  138605. -0.5, 0.5,
  138606. };
  138607. static long _vq_quantmap__44un1__p2_0[] = {
  138608. 1, 0, 2,
  138609. };
  138610. static encode_aux_threshmatch _vq_auxt__44un1__p2_0 = {
  138611. _vq_quantthresh__44un1__p2_0,
  138612. _vq_quantmap__44un1__p2_0,
  138613. 3,
  138614. 3
  138615. };
  138616. static static_codebook _44un1__p2_0 = {
  138617. 4, 81,
  138618. _vq_lengthlist__44un1__p2_0,
  138619. 1, -535822336, 1611661312, 2, 0,
  138620. _vq_quantlist__44un1__p2_0,
  138621. NULL,
  138622. &_vq_auxt__44un1__p2_0,
  138623. NULL,
  138624. 0
  138625. };
  138626. static long _vq_quantlist__44un1__p3_0[] = {
  138627. 2,
  138628. 1,
  138629. 3,
  138630. 0,
  138631. 4,
  138632. };
  138633. static long _vq_lengthlist__44un1__p3_0[] = {
  138634. 1, 5, 5, 8, 8, 5, 8, 7, 9, 9, 5, 7, 8, 9, 9, 9,
  138635. 10, 9,12,12, 9, 9,10,11,12, 6, 8, 8,10,10, 8,10,
  138636. 10,11,11, 8, 9,10,11,11,10,11,11,13,13,10,11,11,
  138637. 12,13, 6, 8, 8,10,10, 8,10, 9,11,11, 8,10,10,11,
  138638. 11,10,11,11,13,12,10,11,11,13,12, 9,11,11,15,13,
  138639. 10,12,11,15,13,10,11,11,15,14,12,14,13,16,15,12,
  138640. 13,13,17,16, 9,11,11,13,15,10,11,12,14,15,10,11,
  138641. 12,14,15,12,13,13,15,16,12,13,13,16,16, 5, 8, 8,
  138642. 11,11, 8,10,10,12,12, 8,10,10,12,12,11,12,12,14,
  138643. 14,11,12,12,14,14, 8,11,10,13,12,10,11,12,12,13,
  138644. 10,12,12,13,13,12,12,13,13,15,11,12,13,15,14, 7,
  138645. 10,10,12,12, 9,12,11,13,12,10,12,12,13,14,12,13,
  138646. 12,15,13,11,13,12,14,15,10,12,12,16,14,11,12,12,
  138647. 16,15,11,13,12,17,16,13,13,15,15,17,13,15,15,20,
  138648. 17,10,12,12,14,16,11,12,12,15,15,11,13,13,15,18,
  138649. 13,14,13,15,15,13,15,14,16,16, 5, 8, 8,11,11, 8,
  138650. 10,10,12,12, 8,10,10,12,12,11,12,12,14,14,11,12,
  138651. 12,14,15, 7,10,10,13,12,10,12,12,14,13, 9,10,12,
  138652. 12,13,11,13,13,15,15,11,12,13,13,15, 8,10,10,12,
  138653. 13,10,12,12,13,13,10,12,11,13,13,11,13,12,15,15,
  138654. 12,13,12,15,13,10,12,12,16,14,11,12,12,16,15,10,
  138655. 12,12,16,14,14,15,14,18,16,13,13,14,15,16,10,12,
  138656. 12,14,16,11,13,13,16,16,11,13,12,14,16,13,15,15,
  138657. 18,18,13,15,13,16,14, 8,11,11,16,16,10,13,13,17,
  138658. 16,10,12,12,16,15,14,16,15,20,17,13,14,14,17,17,
  138659. 9,12,12,16,16,11,13,14,16,17,11,13,13,16,16,15,
  138660. 15,19,18, 0,14,15,15,18,18, 9,12,12,17,16,11,13,
  138661. 12,17,16,11,12,13,15,17,15,16,15, 0,19,14,15,14,
  138662. 19,18,12,14,14, 0,16,13,14,14,19,18,13,15,16,17,
  138663. 16,15,15,17,18, 0,14,16,16,19, 0,12,14,14,16,18,
  138664. 13,15,13,17,18,13,15,14,17,18,15,18,14,18,18,16,
  138665. 17,16, 0,17, 8,11,11,15,15,10,12,12,16,16,10,13,
  138666. 13,16,16,13,15,14,17,17,14,15,17,17,18, 9,12,12,
  138667. 16,15,11,13,13,16,16,11,12,13,17,17,14,14,15,17,
  138668. 17,14,15,16, 0,18, 9,12,12,16,17,11,13,13,16,17,
  138669. 11,14,13,18,17,14,16,14,17,17,15,17,17,18,18,12,
  138670. 14,14, 0,16,13,15,15,19, 0,12,13,15, 0, 0,14,17,
  138671. 16,19, 0,16,15,18,18, 0,12,14,14,17, 0,13,14,14,
  138672. 17, 0,13,15,14, 0,18,15,16,16, 0,18,15,18,15, 0,
  138673. 17,
  138674. };
  138675. static float _vq_quantthresh__44un1__p3_0[] = {
  138676. -1.5, -0.5, 0.5, 1.5,
  138677. };
  138678. static long _vq_quantmap__44un1__p3_0[] = {
  138679. 3, 1, 0, 2, 4,
  138680. };
  138681. static encode_aux_threshmatch _vq_auxt__44un1__p3_0 = {
  138682. _vq_quantthresh__44un1__p3_0,
  138683. _vq_quantmap__44un1__p3_0,
  138684. 5,
  138685. 5
  138686. };
  138687. static static_codebook _44un1__p3_0 = {
  138688. 4, 625,
  138689. _vq_lengthlist__44un1__p3_0,
  138690. 1, -533725184, 1611661312, 3, 0,
  138691. _vq_quantlist__44un1__p3_0,
  138692. NULL,
  138693. &_vq_auxt__44un1__p3_0,
  138694. NULL,
  138695. 0
  138696. };
  138697. static long _vq_quantlist__44un1__p4_0[] = {
  138698. 2,
  138699. 1,
  138700. 3,
  138701. 0,
  138702. 4,
  138703. };
  138704. static long _vq_lengthlist__44un1__p4_0[] = {
  138705. 3, 5, 5, 9, 9, 5, 6, 6,10, 9, 5, 6, 6, 9,10,10,
  138706. 10,10,12,11, 9,10,10,12,12, 5, 7, 7,10,10, 7, 7,
  138707. 8,10,11, 7, 7, 8,10,11,10,10,11,11,13,10,10,11,
  138708. 11,13, 6, 7, 7,10,10, 7, 8, 7,11,10, 7, 8, 7,10,
  138709. 10,10,11, 9,13,11,10,11,10,13,11,10,10,10,14,13,
  138710. 10,11,11,14,13,10,10,11,13,14,12,12,13,15,15,12,
  138711. 12,13,13,14,10,10,10,12,13,10,11,10,13,13,10,11,
  138712. 11,13,13,12,13,12,14,13,12,13,13,14,13, 5, 7, 7,
  138713. 10,10, 7, 8, 8,11,10, 7, 8, 8,10,10,11,11,11,13,
  138714. 13,10,11,11,12,12, 7, 8, 8,11,11, 7, 8, 9,10,12,
  138715. 8, 9, 9,11,11,11,10,12,11,14,11,11,12,13,13, 6,
  138716. 8, 8,10,11, 7, 9, 7,12,10, 8, 9,10,11,12,10,12,
  138717. 10,14,11,11,12,11,13,13,10,11,11,14,14,10,10,11,
  138718. 13,14,11,12,12,15,13,12,11,14,12,16,12,13,14,15,
  138719. 16,10,10,11,13,14,10,11,10,14,12,11,12,12,13,14,
  138720. 12,13,11,15,12,14,14,14,15,15, 5, 7, 7,10,10, 7,
  138721. 8, 8,10,10, 7, 8, 8,10,11,10,11,10,12,12,10,11,
  138722. 11,12,13, 6, 8, 8,11,11, 8, 9, 9,12,11, 7, 7, 9,
  138723. 10,12,11,11,11,12,13,11,10,12,11,15, 7, 8, 8,11,
  138724. 11, 8, 9, 9,11,11, 7, 9, 8,12,10,11,12,11,13,12,
  138725. 11,12,10,15,11,10,11,10,14,12,11,12,11,14,13,10,
  138726. 10,11,13,14,13,13,13,17,15,12,11,14,12,15,10,10,
  138727. 11,13,14,11,12,12,14,14,10,11,10,14,13,13,14,13,
  138728. 16,17,12,14,11,16,12, 9,10,10,14,13,10,11,10,14,
  138729. 14,10,11,11,13,13,13,14,14,16,15,12,13,13,14,14,
  138730. 9,11,10,14,13,10,10,12,13,14,11,12,11,14,13,13,
  138731. 14,14,14,15,13,14,14,15,15, 9,10,11,13,14,10,11,
  138732. 10,15,13,11,11,12,12,15,13,14,12,15,14,13,13,14,
  138733. 14,15,12,13,12,16,14,11,11,12,15,14,13,15,13,16,
  138734. 14,13,12,15,12,17,15,16,15,16,16,12,12,13,13,15,
  138735. 11,13,11,15,14,13,13,14,15,17,13,14,12, 0,13,14,
  138736. 15,14,15, 0, 9,10,10,13,13,10,11,11,13,13,10,11,
  138737. 11,13,13,12,13,12,14,14,13,14,14,15,17, 9,10,10,
  138738. 13,13,11,12,11,15,12,10,10,11,13,16,13,14,13,15,
  138739. 14,13,13,14,15,16,10,10,11,13,14,11,11,12,13,14,
  138740. 10,12,11,14,14,13,13,13,14,15,13,15,13,16,15,12,
  138741. 13,12,15,13,12,15,13,15,15,11,11,13,14,15,15,15,
  138742. 15,15,17,13,12,14,13,17,12,12,14,14,15,13,13,14,
  138743. 14,16,11,13,11,16,15,14,16,16,17, 0,14,13,11,16,
  138744. 12,
  138745. };
  138746. static float _vq_quantthresh__44un1__p4_0[] = {
  138747. -1.5, -0.5, 0.5, 1.5,
  138748. };
  138749. static long _vq_quantmap__44un1__p4_0[] = {
  138750. 3, 1, 0, 2, 4,
  138751. };
  138752. static encode_aux_threshmatch _vq_auxt__44un1__p4_0 = {
  138753. _vq_quantthresh__44un1__p4_0,
  138754. _vq_quantmap__44un1__p4_0,
  138755. 5,
  138756. 5
  138757. };
  138758. static static_codebook _44un1__p4_0 = {
  138759. 4, 625,
  138760. _vq_lengthlist__44un1__p4_0,
  138761. 1, -533725184, 1611661312, 3, 0,
  138762. _vq_quantlist__44un1__p4_0,
  138763. NULL,
  138764. &_vq_auxt__44un1__p4_0,
  138765. NULL,
  138766. 0
  138767. };
  138768. static long _vq_quantlist__44un1__p5_0[] = {
  138769. 4,
  138770. 3,
  138771. 5,
  138772. 2,
  138773. 6,
  138774. 1,
  138775. 7,
  138776. 0,
  138777. 8,
  138778. };
  138779. static long _vq_lengthlist__44un1__p5_0[] = {
  138780. 1, 4, 4, 7, 7, 8, 8, 9, 9, 4, 6, 5, 8, 7, 8, 8,
  138781. 10, 9, 4, 6, 6, 8, 8, 8, 8,10,10, 7, 8, 7, 9, 9,
  138782. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,11, 8, 8, 8,
  138783. 9, 9,10,10,11,11, 8, 8, 8, 9, 9,10,10,11,11, 9,
  138784. 10,10,11,10,11,11,12,12, 9,10,10,10,11,11,11,12,
  138785. 12,
  138786. };
  138787. static float _vq_quantthresh__44un1__p5_0[] = {
  138788. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  138789. };
  138790. static long _vq_quantmap__44un1__p5_0[] = {
  138791. 7, 5, 3, 1, 0, 2, 4, 6,
  138792. 8,
  138793. };
  138794. static encode_aux_threshmatch _vq_auxt__44un1__p5_0 = {
  138795. _vq_quantthresh__44un1__p5_0,
  138796. _vq_quantmap__44un1__p5_0,
  138797. 9,
  138798. 9
  138799. };
  138800. static static_codebook _44un1__p5_0 = {
  138801. 2, 81,
  138802. _vq_lengthlist__44un1__p5_0,
  138803. 1, -531628032, 1611661312, 4, 0,
  138804. _vq_quantlist__44un1__p5_0,
  138805. NULL,
  138806. &_vq_auxt__44un1__p5_0,
  138807. NULL,
  138808. 0
  138809. };
  138810. static long _vq_quantlist__44un1__p6_0[] = {
  138811. 6,
  138812. 5,
  138813. 7,
  138814. 4,
  138815. 8,
  138816. 3,
  138817. 9,
  138818. 2,
  138819. 10,
  138820. 1,
  138821. 11,
  138822. 0,
  138823. 12,
  138824. };
  138825. static long _vq_lengthlist__44un1__p6_0[] = {
  138826. 1, 4, 4, 6, 6, 8, 8,10,10,11,11,15,15, 4, 5, 5,
  138827. 8, 8, 9, 9,11,11,12,12,16,16, 4, 5, 6, 8, 8, 9,
  138828. 9,11,11,12,12,14,14, 7, 8, 8, 9, 9,10,10,11,12,
  138829. 13,13,16,17, 7, 8, 8, 9, 9,10,10,12,12,12,13,15,
  138830. 15, 9,10,10,10,10,11,11,12,12,13,13,15,16, 9, 9,
  138831. 9,10,10,11,11,13,12,13,13,17,17,10,11,11,11,12,
  138832. 12,12,13,13,14,15, 0,18,10,11,11,12,12,12,13,14,
  138833. 13,14,14,17,16,11,12,12,13,13,14,14,14,14,15,16,
  138834. 17,16,11,12,12,13,13,14,14,14,14,15,15,17,17,14,
  138835. 15,15,16,16,16,17,17,16, 0,17, 0,18,14,15,15,16,
  138836. 16, 0,15,18,18, 0,16, 0, 0,
  138837. };
  138838. static float _vq_quantthresh__44un1__p6_0[] = {
  138839. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  138840. 12.5, 17.5, 22.5, 27.5,
  138841. };
  138842. static long _vq_quantmap__44un1__p6_0[] = {
  138843. 11, 9, 7, 5, 3, 1, 0, 2,
  138844. 4, 6, 8, 10, 12,
  138845. };
  138846. static encode_aux_threshmatch _vq_auxt__44un1__p6_0 = {
  138847. _vq_quantthresh__44un1__p6_0,
  138848. _vq_quantmap__44un1__p6_0,
  138849. 13,
  138850. 13
  138851. };
  138852. static static_codebook _44un1__p6_0 = {
  138853. 2, 169,
  138854. _vq_lengthlist__44un1__p6_0,
  138855. 1, -526516224, 1616117760, 4, 0,
  138856. _vq_quantlist__44un1__p6_0,
  138857. NULL,
  138858. &_vq_auxt__44un1__p6_0,
  138859. NULL,
  138860. 0
  138861. };
  138862. static long _vq_quantlist__44un1__p6_1[] = {
  138863. 2,
  138864. 1,
  138865. 3,
  138866. 0,
  138867. 4,
  138868. };
  138869. static long _vq_lengthlist__44un1__p6_1[] = {
  138870. 2, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 6, 5, 5,
  138871. 6, 5, 6, 6, 5, 6, 6, 6, 6,
  138872. };
  138873. static float _vq_quantthresh__44un1__p6_1[] = {
  138874. -1.5, -0.5, 0.5, 1.5,
  138875. };
  138876. static long _vq_quantmap__44un1__p6_1[] = {
  138877. 3, 1, 0, 2, 4,
  138878. };
  138879. static encode_aux_threshmatch _vq_auxt__44un1__p6_1 = {
  138880. _vq_quantthresh__44un1__p6_1,
  138881. _vq_quantmap__44un1__p6_1,
  138882. 5,
  138883. 5
  138884. };
  138885. static static_codebook _44un1__p6_1 = {
  138886. 2, 25,
  138887. _vq_lengthlist__44un1__p6_1,
  138888. 1, -533725184, 1611661312, 3, 0,
  138889. _vq_quantlist__44un1__p6_1,
  138890. NULL,
  138891. &_vq_auxt__44un1__p6_1,
  138892. NULL,
  138893. 0
  138894. };
  138895. static long _vq_quantlist__44un1__p7_0[] = {
  138896. 2,
  138897. 1,
  138898. 3,
  138899. 0,
  138900. 4,
  138901. };
  138902. static long _vq_lengthlist__44un1__p7_0[] = {
  138903. 1, 5, 3,11,11,11,11,11,11,11, 8,11,11,11,11,11,
  138904. 11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,
  138905. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138906. 11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138907. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138908. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138909. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138910. 11,11,11,11,11,11,11,11,11,11,11,11,11, 8,11,11,
  138911. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138912. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138913. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
  138914. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138915. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138916. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138917. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138918. 11,11,11,11,11,11,11,11,11,11, 7,11,11,11,11,11,
  138919. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138920. 11,11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,
  138921. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138922. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138923. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138924. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138925. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138926. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138927. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138928. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138929. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138930. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138931. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138932. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138933. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138934. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138935. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138936. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138937. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138938. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138939. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138940. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138941. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138942. 10,
  138943. };
  138944. static float _vq_quantthresh__44un1__p7_0[] = {
  138945. -253.5, -84.5, 84.5, 253.5,
  138946. };
  138947. static long _vq_quantmap__44un1__p7_0[] = {
  138948. 3, 1, 0, 2, 4,
  138949. };
  138950. static encode_aux_threshmatch _vq_auxt__44un1__p7_0 = {
  138951. _vq_quantthresh__44un1__p7_0,
  138952. _vq_quantmap__44un1__p7_0,
  138953. 5,
  138954. 5
  138955. };
  138956. static static_codebook _44un1__p7_0 = {
  138957. 4, 625,
  138958. _vq_lengthlist__44un1__p7_0,
  138959. 1, -518709248, 1626677248, 3, 0,
  138960. _vq_quantlist__44un1__p7_0,
  138961. NULL,
  138962. &_vq_auxt__44un1__p7_0,
  138963. NULL,
  138964. 0
  138965. };
  138966. static long _vq_quantlist__44un1__p7_1[] = {
  138967. 6,
  138968. 5,
  138969. 7,
  138970. 4,
  138971. 8,
  138972. 3,
  138973. 9,
  138974. 2,
  138975. 10,
  138976. 1,
  138977. 11,
  138978. 0,
  138979. 12,
  138980. };
  138981. static long _vq_lengthlist__44un1__p7_1[] = {
  138982. 1, 4, 4, 6, 6, 6, 6, 9, 8, 9, 8, 8, 8, 5, 7, 7,
  138983. 7, 7, 8, 8, 8,10, 8,10, 8, 9, 5, 7, 7, 8, 7, 7,
  138984. 8,10,10,11,10,12,11, 7, 8, 8, 9, 9, 9,10,11,11,
  138985. 11,11,11,11, 7, 8, 8, 8, 9, 9, 9,10,10,10,11,11,
  138986. 12, 7, 8, 8, 9, 9,10,11,11,12,11,12,11,11, 7, 8,
  138987. 8, 9, 9,10,10,11,11,11,12,12,11, 8,10,10,10,10,
  138988. 11,11,14,11,12,12,12,13, 9,10,10,10,10,12,11,14,
  138989. 11,14,11,12,13,10,11,11,11,11,13,11,14,14,13,13,
  138990. 13,14,11,11,11,12,11,12,12,12,13,14,14,13,14,12,
  138991. 11,12,12,12,12,13,13,13,14,13,14,14,11,12,12,14,
  138992. 12,13,13,12,13,13,14,14,14,
  138993. };
  138994. static float _vq_quantthresh__44un1__p7_1[] = {
  138995. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  138996. 32.5, 45.5, 58.5, 71.5,
  138997. };
  138998. static long _vq_quantmap__44un1__p7_1[] = {
  138999. 11, 9, 7, 5, 3, 1, 0, 2,
  139000. 4, 6, 8, 10, 12,
  139001. };
  139002. static encode_aux_threshmatch _vq_auxt__44un1__p7_1 = {
  139003. _vq_quantthresh__44un1__p7_1,
  139004. _vq_quantmap__44un1__p7_1,
  139005. 13,
  139006. 13
  139007. };
  139008. static static_codebook _44un1__p7_1 = {
  139009. 2, 169,
  139010. _vq_lengthlist__44un1__p7_1,
  139011. 1, -523010048, 1618608128, 4, 0,
  139012. _vq_quantlist__44un1__p7_1,
  139013. NULL,
  139014. &_vq_auxt__44un1__p7_1,
  139015. NULL,
  139016. 0
  139017. };
  139018. static long _vq_quantlist__44un1__p7_2[] = {
  139019. 6,
  139020. 5,
  139021. 7,
  139022. 4,
  139023. 8,
  139024. 3,
  139025. 9,
  139026. 2,
  139027. 10,
  139028. 1,
  139029. 11,
  139030. 0,
  139031. 12,
  139032. };
  139033. static long _vq_lengthlist__44un1__p7_2[] = {
  139034. 3, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9, 9, 8, 4, 5, 5,
  139035. 6, 6, 8, 8, 9, 8, 9, 9, 9, 9, 4, 5, 5, 7, 6, 8,
  139036. 8, 8, 8, 9, 8, 9, 8, 6, 7, 7, 7, 8, 8, 8, 9, 9,
  139037. 9, 9, 9, 9, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  139038. 9, 7, 8, 8, 8, 8, 9, 8, 9, 9,10, 9, 9,10, 7, 8,
  139039. 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10, 8, 9, 9, 9, 9,
  139040. 9, 9, 9, 9,10,10, 9,10, 8, 9, 9, 9, 9, 9, 9, 9,
  139041. 9, 9, 9,10,10, 9, 9, 9,10, 9, 9,10, 9, 9,10,10,
  139042. 10,10, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10, 9,
  139043. 9, 9,10, 9, 9,10,10, 9,10,10,10,10, 9, 9, 9,10,
  139044. 9, 9, 9,10,10,10,10,10,10,
  139045. };
  139046. static float _vq_quantthresh__44un1__p7_2[] = {
  139047. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  139048. 2.5, 3.5, 4.5, 5.5,
  139049. };
  139050. static long _vq_quantmap__44un1__p7_2[] = {
  139051. 11, 9, 7, 5, 3, 1, 0, 2,
  139052. 4, 6, 8, 10, 12,
  139053. };
  139054. static encode_aux_threshmatch _vq_auxt__44un1__p7_2 = {
  139055. _vq_quantthresh__44un1__p7_2,
  139056. _vq_quantmap__44un1__p7_2,
  139057. 13,
  139058. 13
  139059. };
  139060. static static_codebook _44un1__p7_2 = {
  139061. 2, 169,
  139062. _vq_lengthlist__44un1__p7_2,
  139063. 1, -531103744, 1611661312, 4, 0,
  139064. _vq_quantlist__44un1__p7_2,
  139065. NULL,
  139066. &_vq_auxt__44un1__p7_2,
  139067. NULL,
  139068. 0
  139069. };
  139070. static long _huff_lengthlist__44un1__short[] = {
  139071. 12,12,14,12,14,14,14,14,12, 6, 6, 8, 9, 9,11,14,
  139072. 12, 4, 2, 6, 6, 7,11,14,13, 6, 5, 7, 8, 9,11,14,
  139073. 13, 8, 5, 8, 6, 8,12,14,12, 7, 7, 8, 8, 8,10,14,
  139074. 12, 6, 3, 4, 4, 4, 7,14,11, 7, 4, 6, 6, 6, 8,14,
  139075. };
  139076. static static_codebook _huff_book__44un1__short = {
  139077. 2, 64,
  139078. _huff_lengthlist__44un1__short,
  139079. 0, 0, 0, 0, 0,
  139080. NULL,
  139081. NULL,
  139082. NULL,
  139083. NULL,
  139084. 0
  139085. };
  139086. /*** End of inlined file: res_books_uncoupled.h ***/
  139087. static vorbis_info_residue0 _residue_44_low_un={
  139088. 0,-1, -1, 8,-1,
  139089. {0},
  139090. {-1},
  139091. { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 28.5},
  139092. { -1, 25, -1, 45, -1, -1, -1}
  139093. };
  139094. static vorbis_info_residue0 _residue_44_mid_un={
  139095. 0,-1, -1, 10,-1,
  139096. {0},
  139097. {-1},
  139098. { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 4.5, 16.5, 60.5},
  139099. { -1, 30, -1, 50, -1, 80, -1, -1, -1}
  139100. };
  139101. static vorbis_info_residue0 _residue_44_hi_un={
  139102. 0,-1, -1, 10,-1,
  139103. {0},
  139104. {-1},
  139105. { .5, 1.5, 2.5, 4.5, 8.5, 16.5, 32.5, 71.5,157.5},
  139106. { -1, -1, -1, -1, -1, -1, -1, -1, -1}
  139107. };
  139108. static vorbis_info_mapping0 _map_nominal_u[2]={
  139109. {1, {0,0}, {0}, {0}, 0,{0},{0}},
  139110. {1, {0,0}, {1}, {1}, 0,{0},{0}}
  139111. };
  139112. static static_bookblock _resbook_44u_n1={
  139113. {
  139114. {0},
  139115. {0,0,&_44un1__p1_0},
  139116. {0,0,&_44un1__p2_0},
  139117. {0,0,&_44un1__p3_0},
  139118. {0,0,&_44un1__p4_0},
  139119. {0,0,&_44un1__p5_0},
  139120. {&_44un1__p6_0,&_44un1__p6_1},
  139121. {&_44un1__p7_0,&_44un1__p7_1,&_44un1__p7_2}
  139122. }
  139123. };
  139124. static static_bookblock _resbook_44u_0={
  139125. {
  139126. {0},
  139127. {0,0,&_44u0__p1_0},
  139128. {0,0,&_44u0__p2_0},
  139129. {0,0,&_44u0__p3_0},
  139130. {0,0,&_44u0__p4_0},
  139131. {0,0,&_44u0__p5_0},
  139132. {&_44u0__p6_0,&_44u0__p6_1},
  139133. {&_44u0__p7_0,&_44u0__p7_1,&_44u0__p7_2}
  139134. }
  139135. };
  139136. static static_bookblock _resbook_44u_1={
  139137. {
  139138. {0},
  139139. {0,0,&_44u1__p1_0},
  139140. {0,0,&_44u1__p2_0},
  139141. {0,0,&_44u1__p3_0},
  139142. {0,0,&_44u1__p4_0},
  139143. {0,0,&_44u1__p5_0},
  139144. {&_44u1__p6_0,&_44u1__p6_1},
  139145. {&_44u1__p7_0,&_44u1__p7_1,&_44u1__p7_2}
  139146. }
  139147. };
  139148. static static_bookblock _resbook_44u_2={
  139149. {
  139150. {0},
  139151. {0,0,&_44u2__p1_0},
  139152. {0,0,&_44u2__p2_0},
  139153. {0,0,&_44u2__p3_0},
  139154. {0,0,&_44u2__p4_0},
  139155. {0,0,&_44u2__p5_0},
  139156. {&_44u2__p6_0,&_44u2__p6_1},
  139157. {&_44u2__p7_0,&_44u2__p7_1,&_44u2__p7_2}
  139158. }
  139159. };
  139160. static static_bookblock _resbook_44u_3={
  139161. {
  139162. {0},
  139163. {0,0,&_44u3__p1_0},
  139164. {0,0,&_44u3__p2_0},
  139165. {0,0,&_44u3__p3_0},
  139166. {0,0,&_44u3__p4_0},
  139167. {0,0,&_44u3__p5_0},
  139168. {&_44u3__p6_0,&_44u3__p6_1},
  139169. {&_44u3__p7_0,&_44u3__p7_1,&_44u3__p7_2}
  139170. }
  139171. };
  139172. static static_bookblock _resbook_44u_4={
  139173. {
  139174. {0},
  139175. {0,0,&_44u4__p1_0},
  139176. {0,0,&_44u4__p2_0},
  139177. {0,0,&_44u4__p3_0},
  139178. {0,0,&_44u4__p4_0},
  139179. {0,0,&_44u4__p5_0},
  139180. {&_44u4__p6_0,&_44u4__p6_1},
  139181. {&_44u4__p7_0,&_44u4__p7_1,&_44u4__p7_2}
  139182. }
  139183. };
  139184. static static_bookblock _resbook_44u_5={
  139185. {
  139186. {0},
  139187. {0,0,&_44u5__p1_0},
  139188. {0,0,&_44u5__p2_0},
  139189. {0,0,&_44u5__p3_0},
  139190. {0,0,&_44u5__p4_0},
  139191. {0,0,&_44u5__p5_0},
  139192. {0,0,&_44u5__p6_0},
  139193. {&_44u5__p7_0,&_44u5__p7_1},
  139194. {&_44u5__p8_0,&_44u5__p8_1},
  139195. {&_44u5__p9_0,&_44u5__p9_1,&_44u5__p9_2}
  139196. }
  139197. };
  139198. static static_bookblock _resbook_44u_6={
  139199. {
  139200. {0},
  139201. {0,0,&_44u6__p1_0},
  139202. {0,0,&_44u6__p2_0},
  139203. {0,0,&_44u6__p3_0},
  139204. {0,0,&_44u6__p4_0},
  139205. {0,0,&_44u6__p5_0},
  139206. {0,0,&_44u6__p6_0},
  139207. {&_44u6__p7_0,&_44u6__p7_1},
  139208. {&_44u6__p8_0,&_44u6__p8_1},
  139209. {&_44u6__p9_0,&_44u6__p9_1,&_44u6__p9_2}
  139210. }
  139211. };
  139212. static static_bookblock _resbook_44u_7={
  139213. {
  139214. {0},
  139215. {0,0,&_44u7__p1_0},
  139216. {0,0,&_44u7__p2_0},
  139217. {0,0,&_44u7__p3_0},
  139218. {0,0,&_44u7__p4_0},
  139219. {0,0,&_44u7__p5_0},
  139220. {0,0,&_44u7__p6_0},
  139221. {&_44u7__p7_0,&_44u7__p7_1},
  139222. {&_44u7__p8_0,&_44u7__p8_1},
  139223. {&_44u7__p9_0,&_44u7__p9_1,&_44u7__p9_2}
  139224. }
  139225. };
  139226. static static_bookblock _resbook_44u_8={
  139227. {
  139228. {0},
  139229. {0,0,&_44u8_p1_0},
  139230. {0,0,&_44u8_p2_0},
  139231. {0,0,&_44u8_p3_0},
  139232. {0,0,&_44u8_p4_0},
  139233. {&_44u8_p5_0,&_44u8_p5_1},
  139234. {&_44u8_p6_0,&_44u8_p6_1},
  139235. {&_44u8_p7_0,&_44u8_p7_1},
  139236. {&_44u8_p8_0,&_44u8_p8_1},
  139237. {&_44u8_p9_0,&_44u8_p9_1,&_44u8_p9_2}
  139238. }
  139239. };
  139240. static static_bookblock _resbook_44u_9={
  139241. {
  139242. {0},
  139243. {0,0,&_44u9_p1_0},
  139244. {0,0,&_44u9_p2_0},
  139245. {0,0,&_44u9_p3_0},
  139246. {0,0,&_44u9_p4_0},
  139247. {&_44u9_p5_0,&_44u9_p5_1},
  139248. {&_44u9_p6_0,&_44u9_p6_1},
  139249. {&_44u9_p7_0,&_44u9_p7_1},
  139250. {&_44u9_p8_0,&_44u9_p8_1},
  139251. {&_44u9_p9_0,&_44u9_p9_1,&_44u9_p9_2}
  139252. }
  139253. };
  139254. static vorbis_residue_template _res_44u_n1[]={
  139255. {1,0, &_residue_44_low_un,
  139256. &_huff_book__44un1__short,&_huff_book__44un1__short,
  139257. &_resbook_44u_n1,&_resbook_44u_n1},
  139258. {1,0, &_residue_44_low_un,
  139259. &_huff_book__44un1__long,&_huff_book__44un1__long,
  139260. &_resbook_44u_n1,&_resbook_44u_n1}
  139261. };
  139262. static vorbis_residue_template _res_44u_0[]={
  139263. {1,0, &_residue_44_low_un,
  139264. &_huff_book__44u0__short,&_huff_book__44u0__short,
  139265. &_resbook_44u_0,&_resbook_44u_0},
  139266. {1,0, &_residue_44_low_un,
  139267. &_huff_book__44u0__long,&_huff_book__44u0__long,
  139268. &_resbook_44u_0,&_resbook_44u_0}
  139269. };
  139270. static vorbis_residue_template _res_44u_1[]={
  139271. {1,0, &_residue_44_low_un,
  139272. &_huff_book__44u1__short,&_huff_book__44u1__short,
  139273. &_resbook_44u_1,&_resbook_44u_1},
  139274. {1,0, &_residue_44_low_un,
  139275. &_huff_book__44u1__long,&_huff_book__44u1__long,
  139276. &_resbook_44u_1,&_resbook_44u_1}
  139277. };
  139278. static vorbis_residue_template _res_44u_2[]={
  139279. {1,0, &_residue_44_low_un,
  139280. &_huff_book__44u2__short,&_huff_book__44u2__short,
  139281. &_resbook_44u_2,&_resbook_44u_2},
  139282. {1,0, &_residue_44_low_un,
  139283. &_huff_book__44u2__long,&_huff_book__44u2__long,
  139284. &_resbook_44u_2,&_resbook_44u_2}
  139285. };
  139286. static vorbis_residue_template _res_44u_3[]={
  139287. {1,0, &_residue_44_low_un,
  139288. &_huff_book__44u3__short,&_huff_book__44u3__short,
  139289. &_resbook_44u_3,&_resbook_44u_3},
  139290. {1,0, &_residue_44_low_un,
  139291. &_huff_book__44u3__long,&_huff_book__44u3__long,
  139292. &_resbook_44u_3,&_resbook_44u_3}
  139293. };
  139294. static vorbis_residue_template _res_44u_4[]={
  139295. {1,0, &_residue_44_low_un,
  139296. &_huff_book__44u4__short,&_huff_book__44u4__short,
  139297. &_resbook_44u_4,&_resbook_44u_4},
  139298. {1,0, &_residue_44_low_un,
  139299. &_huff_book__44u4__long,&_huff_book__44u4__long,
  139300. &_resbook_44u_4,&_resbook_44u_4}
  139301. };
  139302. static vorbis_residue_template _res_44u_5[]={
  139303. {1,0, &_residue_44_mid_un,
  139304. &_huff_book__44u5__short,&_huff_book__44u5__short,
  139305. &_resbook_44u_5,&_resbook_44u_5},
  139306. {1,0, &_residue_44_mid_un,
  139307. &_huff_book__44u5__long,&_huff_book__44u5__long,
  139308. &_resbook_44u_5,&_resbook_44u_5}
  139309. };
  139310. static vorbis_residue_template _res_44u_6[]={
  139311. {1,0, &_residue_44_mid_un,
  139312. &_huff_book__44u6__short,&_huff_book__44u6__short,
  139313. &_resbook_44u_6,&_resbook_44u_6},
  139314. {1,0, &_residue_44_mid_un,
  139315. &_huff_book__44u6__long,&_huff_book__44u6__long,
  139316. &_resbook_44u_6,&_resbook_44u_6}
  139317. };
  139318. static vorbis_residue_template _res_44u_7[]={
  139319. {1,0, &_residue_44_mid_un,
  139320. &_huff_book__44u7__short,&_huff_book__44u7__short,
  139321. &_resbook_44u_7,&_resbook_44u_7},
  139322. {1,0, &_residue_44_mid_un,
  139323. &_huff_book__44u7__long,&_huff_book__44u7__long,
  139324. &_resbook_44u_7,&_resbook_44u_7}
  139325. };
  139326. static vorbis_residue_template _res_44u_8[]={
  139327. {1,0, &_residue_44_hi_un,
  139328. &_huff_book__44u8__short,&_huff_book__44u8__short,
  139329. &_resbook_44u_8,&_resbook_44u_8},
  139330. {1,0, &_residue_44_hi_un,
  139331. &_huff_book__44u8__long,&_huff_book__44u8__long,
  139332. &_resbook_44u_8,&_resbook_44u_8}
  139333. };
  139334. static vorbis_residue_template _res_44u_9[]={
  139335. {1,0, &_residue_44_hi_un,
  139336. &_huff_book__44u9__short,&_huff_book__44u9__short,
  139337. &_resbook_44u_9,&_resbook_44u_9},
  139338. {1,0, &_residue_44_hi_un,
  139339. &_huff_book__44u9__long,&_huff_book__44u9__long,
  139340. &_resbook_44u_9,&_resbook_44u_9}
  139341. };
  139342. static vorbis_mapping_template _mapres_template_44_uncoupled[]={
  139343. { _map_nominal_u, _res_44u_n1 }, /* -1 */
  139344. { _map_nominal_u, _res_44u_0 }, /* 0 */
  139345. { _map_nominal_u, _res_44u_1 }, /* 1 */
  139346. { _map_nominal_u, _res_44u_2 }, /* 2 */
  139347. { _map_nominal_u, _res_44u_3 }, /* 3 */
  139348. { _map_nominal_u, _res_44u_4 }, /* 4 */
  139349. { _map_nominal_u, _res_44u_5 }, /* 5 */
  139350. { _map_nominal_u, _res_44u_6 }, /* 6 */
  139351. { _map_nominal_u, _res_44u_7 }, /* 7 */
  139352. { _map_nominal_u, _res_44u_8 }, /* 8 */
  139353. { _map_nominal_u, _res_44u_9 }, /* 9 */
  139354. };
  139355. /*** End of inlined file: residue_44u.h ***/
  139356. static double rate_mapping_44_un[12]={
  139357. 32000.,48000.,60000.,70000.,80000.,86000.,
  139358. 96000.,110000.,120000.,140000.,160000.,240001.
  139359. };
  139360. ve_setup_data_template ve_setup_44_uncoupled={
  139361. 11,
  139362. rate_mapping_44_un,
  139363. quality_mapping_44,
  139364. -1,
  139365. 40000,
  139366. 50000,
  139367. blocksize_short_44,
  139368. blocksize_long_44,
  139369. _psy_tone_masteratt_44,
  139370. _psy_tone_0dB,
  139371. _psy_tone_suppress,
  139372. _vp_tonemask_adj_otherblock,
  139373. _vp_tonemask_adj_longblock,
  139374. _vp_tonemask_adj_otherblock,
  139375. _psy_noiseguards_44,
  139376. _psy_noisebias_impulse,
  139377. _psy_noisebias_padding,
  139378. _psy_noisebias_trans,
  139379. _psy_noisebias_long,
  139380. _psy_noise_suppress,
  139381. _psy_compand_44,
  139382. _psy_compand_short_mapping,
  139383. _psy_compand_long_mapping,
  139384. {_noise_start_short_44,_noise_start_long_44},
  139385. {_noise_part_short_44,_noise_part_long_44},
  139386. _noise_thresh_44,
  139387. _psy_ath_floater,
  139388. _psy_ath_abs,
  139389. _psy_lowpass_44,
  139390. _psy_global_44,
  139391. _global_mapping_44,
  139392. NULL,
  139393. _floor_books,
  139394. _floor,
  139395. _floor_short_mapping_44,
  139396. _floor_long_mapping_44,
  139397. _mapres_template_44_uncoupled
  139398. };
  139399. /*** End of inlined file: setup_44u.h ***/
  139400. /*** Start of inlined file: setup_32.h ***/
  139401. static double rate_mapping_32[12]={
  139402. 18000.,28000.,35000.,45000.,56000.,60000.,
  139403. 75000.,90000.,100000.,115000.,150000.,190000.,
  139404. };
  139405. static double rate_mapping_32_un[12]={
  139406. 30000.,42000.,52000.,64000.,72000.,78000.,
  139407. 86000.,92000.,110000.,120000.,140000.,190000.,
  139408. };
  139409. static double _psy_lowpass_32[12]={
  139410. 12.3,13.,13.,14.,15.,99.,99.,99.,99.,99.,99.,99.
  139411. };
  139412. ve_setup_data_template ve_setup_32_stereo={
  139413. 11,
  139414. rate_mapping_32,
  139415. quality_mapping_44,
  139416. 2,
  139417. 26000,
  139418. 40000,
  139419. blocksize_short_44,
  139420. blocksize_long_44,
  139421. _psy_tone_masteratt_44,
  139422. _psy_tone_0dB,
  139423. _psy_tone_suppress,
  139424. _vp_tonemask_adj_otherblock,
  139425. _vp_tonemask_adj_longblock,
  139426. _vp_tonemask_adj_otherblock,
  139427. _psy_noiseguards_44,
  139428. _psy_noisebias_impulse,
  139429. _psy_noisebias_padding,
  139430. _psy_noisebias_trans,
  139431. _psy_noisebias_long,
  139432. _psy_noise_suppress,
  139433. _psy_compand_44,
  139434. _psy_compand_short_mapping,
  139435. _psy_compand_long_mapping,
  139436. {_noise_start_short_44,_noise_start_long_44},
  139437. {_noise_part_short_44,_noise_part_long_44},
  139438. _noise_thresh_44,
  139439. _psy_ath_floater,
  139440. _psy_ath_abs,
  139441. _psy_lowpass_32,
  139442. _psy_global_44,
  139443. _global_mapping_44,
  139444. _psy_stereo_modes_44,
  139445. _floor_books,
  139446. _floor,
  139447. _floor_short_mapping_44,
  139448. _floor_long_mapping_44,
  139449. _mapres_template_44_stereo
  139450. };
  139451. ve_setup_data_template ve_setup_32_uncoupled={
  139452. 11,
  139453. rate_mapping_32_un,
  139454. quality_mapping_44,
  139455. -1,
  139456. 26000,
  139457. 40000,
  139458. blocksize_short_44,
  139459. blocksize_long_44,
  139460. _psy_tone_masteratt_44,
  139461. _psy_tone_0dB,
  139462. _psy_tone_suppress,
  139463. _vp_tonemask_adj_otherblock,
  139464. _vp_tonemask_adj_longblock,
  139465. _vp_tonemask_adj_otherblock,
  139466. _psy_noiseguards_44,
  139467. _psy_noisebias_impulse,
  139468. _psy_noisebias_padding,
  139469. _psy_noisebias_trans,
  139470. _psy_noisebias_long,
  139471. _psy_noise_suppress,
  139472. _psy_compand_44,
  139473. _psy_compand_short_mapping,
  139474. _psy_compand_long_mapping,
  139475. {_noise_start_short_44,_noise_start_long_44},
  139476. {_noise_part_short_44,_noise_part_long_44},
  139477. _noise_thresh_44,
  139478. _psy_ath_floater,
  139479. _psy_ath_abs,
  139480. _psy_lowpass_32,
  139481. _psy_global_44,
  139482. _global_mapping_44,
  139483. NULL,
  139484. _floor_books,
  139485. _floor,
  139486. _floor_short_mapping_44,
  139487. _floor_long_mapping_44,
  139488. _mapres_template_44_uncoupled
  139489. };
  139490. /*** End of inlined file: setup_32.h ***/
  139491. /*** Start of inlined file: setup_8.h ***/
  139492. /*** Start of inlined file: psych_8.h ***/
  139493. static att3 _psy_tone_masteratt_8[3]={
  139494. {{ 32, 25, 12}, 0, 0}, /* 0 */
  139495. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139496. {{ 20, 0, -14}, 0, 0}, /* 0 */
  139497. };
  139498. static vp_adjblock _vp_tonemask_adj_8[3]={
  139499. {{-15,-15,-15,-15,-10,-10, -6, 0, 0, 0, 0,10, 0, 0,99,99,99}}, /* 1 */
  139500. {{-15,-15,-15,-15,-10,-10, -6, 0, 0, 0, 0,10, 0, 0,99,99,99}}, /* 1 */
  139501. {{-15,-15,-15,-15,-10,-10, -6, 0, 0, 0, 0, 0, 0, 0,99,99,99}}, /* 1 */
  139502. };
  139503. static noise3 _psy_noisebias_8[3]={
  139504. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 8, 8, 8, 10, 10, 99, 99, 99},
  139505. {-10,-10,-10,-10, -5, -5, -5, 0, 0, 4, 4, 4, 4, 4, 99, 99, 99},
  139506. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139507. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 8, 8, 8, 10, 10, 99, 99, 99},
  139508. {-10,-10,-10,-10,-10,-10, -5, -5, -5, 0, 0, 0, 0, 0, 99, 99, 99},
  139509. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139510. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 99, 99, 99},
  139511. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10, 99, 99, 99},
  139512. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24, 99, 99, 99}}},
  139513. };
  139514. static adj_stereo _psy_stereo_modes_8[3]={
  139515. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139516. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139517. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  139518. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139519. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139520. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139521. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  139522. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139523. {{ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139524. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139525. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  139526. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139527. };
  139528. static noiseguard _psy_noiseguards_8[2]={
  139529. {10,10,-1},
  139530. {10,10,-1},
  139531. };
  139532. static compandblock _psy_compand_8[2]={
  139533. {{
  139534. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  139535. 8, 8, 9, 9,10,10,11, 11, /* 15dB */
  139536. 12,12,13,13,14,14,15, 15, /* 23dB */
  139537. 16,16,17,17,17,18,18, 19, /* 31dB */
  139538. 19,19,20,21,22,23,24, 25, /* 39dB */
  139539. }},
  139540. {{
  139541. 0, 1, 2, 3, 4, 5, 6, 6, /* 7dB */
  139542. 7, 7, 6, 6, 5, 5, 4, 4, /* 15dB */
  139543. 3, 3, 3, 4, 5, 6, 7, 8, /* 23dB */
  139544. 9,10,11,12,13,14,15, 16, /* 31dB */
  139545. 17,18,19,20,21,22,23, 24, /* 39dB */
  139546. }},
  139547. };
  139548. static double _psy_lowpass_8[3]={3.,4.,4.};
  139549. static int _noise_start_8[2]={
  139550. 64,64,
  139551. };
  139552. static int _noise_part_8[2]={
  139553. 8,8,
  139554. };
  139555. static int _psy_ath_floater_8[3]={
  139556. -100,-100,-105,
  139557. };
  139558. static int _psy_ath_abs_8[3]={
  139559. -130,-130,-140,
  139560. };
  139561. /*** End of inlined file: psych_8.h ***/
  139562. /*** Start of inlined file: residue_8.h ***/
  139563. static static_bookblock _resbook_8s_0={
  139564. {
  139565. {0},{0,0,&_8c0_s_p1_0},{0,0,&_8c0_s_p2_0},{0,0,&_8c0_s_p3_0},
  139566. {0,0,&_8c0_s_p4_0},{0,0,&_8c0_s_p5_0},{0,0,&_8c0_s_p6_0},
  139567. {&_8c0_s_p7_0,&_8c0_s_p7_1},{&_8c0_s_p8_0,&_8c0_s_p8_1},
  139568. {&_8c0_s_p9_0,&_8c0_s_p9_1,&_8c0_s_p9_2}
  139569. }
  139570. };
  139571. static static_bookblock _resbook_8s_1={
  139572. {
  139573. {0},{0,0,&_8c1_s_p1_0},{0,0,&_8c1_s_p2_0},{0,0,&_8c1_s_p3_0},
  139574. {0,0,&_8c1_s_p4_0},{0,0,&_8c1_s_p5_0},{0,0,&_8c1_s_p6_0},
  139575. {&_8c1_s_p7_0,&_8c1_s_p7_1},{&_8c1_s_p8_0,&_8c1_s_p8_1},
  139576. {&_8c1_s_p9_0,&_8c1_s_p9_1,&_8c1_s_p9_2}
  139577. }
  139578. };
  139579. static vorbis_residue_template _res_8s_0[]={
  139580. {2,0, &_residue_44_mid,
  139581. &_huff_book__8c0_s_single,&_huff_book__8c0_s_single,
  139582. &_resbook_8s_0,&_resbook_8s_0},
  139583. };
  139584. static vorbis_residue_template _res_8s_1[]={
  139585. {2,0, &_residue_44_mid,
  139586. &_huff_book__8c1_s_single,&_huff_book__8c1_s_single,
  139587. &_resbook_8s_1,&_resbook_8s_1},
  139588. };
  139589. static vorbis_mapping_template _mapres_template_8_stereo[2]={
  139590. { _map_nominal, _res_8s_0 }, /* 0 */
  139591. { _map_nominal, _res_8s_1 }, /* 1 */
  139592. };
  139593. static static_bookblock _resbook_8u_0={
  139594. {
  139595. {0},
  139596. {0,0,&_8u0__p1_0},
  139597. {0,0,&_8u0__p2_0},
  139598. {0,0,&_8u0__p3_0},
  139599. {0,0,&_8u0__p4_0},
  139600. {0,0,&_8u0__p5_0},
  139601. {&_8u0__p6_0,&_8u0__p6_1},
  139602. {&_8u0__p7_0,&_8u0__p7_1,&_8u0__p7_2}
  139603. }
  139604. };
  139605. static static_bookblock _resbook_8u_1={
  139606. {
  139607. {0},
  139608. {0,0,&_8u1__p1_0},
  139609. {0,0,&_8u1__p2_0},
  139610. {0,0,&_8u1__p3_0},
  139611. {0,0,&_8u1__p4_0},
  139612. {0,0,&_8u1__p5_0},
  139613. {0,0,&_8u1__p6_0},
  139614. {&_8u1__p7_0,&_8u1__p7_1},
  139615. {&_8u1__p8_0,&_8u1__p8_1},
  139616. {&_8u1__p9_0,&_8u1__p9_1,&_8u1__p9_2}
  139617. }
  139618. };
  139619. static vorbis_residue_template _res_8u_0[]={
  139620. {1,0, &_residue_44_low_un,
  139621. &_huff_book__8u0__single,&_huff_book__8u0__single,
  139622. &_resbook_8u_0,&_resbook_8u_0},
  139623. };
  139624. static vorbis_residue_template _res_8u_1[]={
  139625. {1,0, &_residue_44_mid_un,
  139626. &_huff_book__8u1__single,&_huff_book__8u1__single,
  139627. &_resbook_8u_1,&_resbook_8u_1},
  139628. };
  139629. static vorbis_mapping_template _mapres_template_8_uncoupled[2]={
  139630. { _map_nominal_u, _res_8u_0 }, /* 0 */
  139631. { _map_nominal_u, _res_8u_1 }, /* 1 */
  139632. };
  139633. /*** End of inlined file: residue_8.h ***/
  139634. static int blocksize_8[2]={
  139635. 512,512
  139636. };
  139637. static int _floor_mapping_8[2]={
  139638. 6,6,
  139639. };
  139640. static double rate_mapping_8[3]={
  139641. 6000.,9000.,32000.,
  139642. };
  139643. static double rate_mapping_8_uncoupled[3]={
  139644. 8000.,14000.,42000.,
  139645. };
  139646. static double quality_mapping_8[3]={
  139647. -.1,.0,1.
  139648. };
  139649. static double _psy_compand_8_mapping[3]={ 0., 1., 1.};
  139650. static double _global_mapping_8[3]={ 1., 2., 3. };
  139651. ve_setup_data_template ve_setup_8_stereo={
  139652. 2,
  139653. rate_mapping_8,
  139654. quality_mapping_8,
  139655. 2,
  139656. 8000,
  139657. 9000,
  139658. blocksize_8,
  139659. blocksize_8,
  139660. _psy_tone_masteratt_8,
  139661. _psy_tone_0dB,
  139662. _psy_tone_suppress,
  139663. _vp_tonemask_adj_8,
  139664. NULL,
  139665. _vp_tonemask_adj_8,
  139666. _psy_noiseguards_8,
  139667. _psy_noisebias_8,
  139668. _psy_noisebias_8,
  139669. NULL,
  139670. NULL,
  139671. _psy_noise_suppress,
  139672. _psy_compand_8,
  139673. _psy_compand_8_mapping,
  139674. NULL,
  139675. {_noise_start_8,_noise_start_8},
  139676. {_noise_part_8,_noise_part_8},
  139677. _noise_thresh_5only,
  139678. _psy_ath_floater_8,
  139679. _psy_ath_abs_8,
  139680. _psy_lowpass_8,
  139681. _psy_global_44,
  139682. _global_mapping_8,
  139683. _psy_stereo_modes_8,
  139684. _floor_books,
  139685. _floor,
  139686. _floor_mapping_8,
  139687. NULL,
  139688. _mapres_template_8_stereo
  139689. };
  139690. ve_setup_data_template ve_setup_8_uncoupled={
  139691. 2,
  139692. rate_mapping_8_uncoupled,
  139693. quality_mapping_8,
  139694. -1,
  139695. 8000,
  139696. 9000,
  139697. blocksize_8,
  139698. blocksize_8,
  139699. _psy_tone_masteratt_8,
  139700. _psy_tone_0dB,
  139701. _psy_tone_suppress,
  139702. _vp_tonemask_adj_8,
  139703. NULL,
  139704. _vp_tonemask_adj_8,
  139705. _psy_noiseguards_8,
  139706. _psy_noisebias_8,
  139707. _psy_noisebias_8,
  139708. NULL,
  139709. NULL,
  139710. _psy_noise_suppress,
  139711. _psy_compand_8,
  139712. _psy_compand_8_mapping,
  139713. NULL,
  139714. {_noise_start_8,_noise_start_8},
  139715. {_noise_part_8,_noise_part_8},
  139716. _noise_thresh_5only,
  139717. _psy_ath_floater_8,
  139718. _psy_ath_abs_8,
  139719. _psy_lowpass_8,
  139720. _psy_global_44,
  139721. _global_mapping_8,
  139722. _psy_stereo_modes_8,
  139723. _floor_books,
  139724. _floor,
  139725. _floor_mapping_8,
  139726. NULL,
  139727. _mapres_template_8_uncoupled
  139728. };
  139729. /*** End of inlined file: setup_8.h ***/
  139730. /*** Start of inlined file: setup_11.h ***/
  139731. /*** Start of inlined file: psych_11.h ***/
  139732. static double _psy_lowpass_11[3]={4.5,5.5,30.,};
  139733. static att3 _psy_tone_masteratt_11[3]={
  139734. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139735. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139736. {{ 20, 0, -14}, 0, 0}, /* 0 */
  139737. };
  139738. static vp_adjblock _vp_tonemask_adj_11[3]={
  139739. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 2, 0,99,99,99}}, /* 0 */
  139740. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 5, 0, 0,99,99,99}}, /* 1 */
  139741. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 0, 0, 0,99,99,99}}, /* 2 */
  139742. };
  139743. static noise3 _psy_noisebias_11[3]={
  139744. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 10, 10, 12, 12, 12, 99, 99, 99},
  139745. {-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 4, 5, 5, 10, 99, 99, 99},
  139746. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139747. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 10, 10, 12, 12, 12, 99, 99, 99},
  139748. {-15,-15,-15,-15,-10,-10, -5, -5, -5, 0, 0, 0, 0, 0, 99, 99, 99},
  139749. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139750. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 99, 99, 99},
  139751. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10, 99, 99, 99},
  139752. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24, 99, 99, 99}}},
  139753. };
  139754. static double _noise_thresh_11[3]={ .3,.5,.5 };
  139755. /*** End of inlined file: psych_11.h ***/
  139756. static int blocksize_11[2]={
  139757. 512,512
  139758. };
  139759. static int _floor_mapping_11[2]={
  139760. 6,6,
  139761. };
  139762. static double rate_mapping_11[3]={
  139763. 8000.,13000.,44000.,
  139764. };
  139765. static double rate_mapping_11_uncoupled[3]={
  139766. 12000.,20000.,50000.,
  139767. };
  139768. static double quality_mapping_11[3]={
  139769. -.1,.0,1.
  139770. };
  139771. ve_setup_data_template ve_setup_11_stereo={
  139772. 2,
  139773. rate_mapping_11,
  139774. quality_mapping_11,
  139775. 2,
  139776. 9000,
  139777. 15000,
  139778. blocksize_11,
  139779. blocksize_11,
  139780. _psy_tone_masteratt_11,
  139781. _psy_tone_0dB,
  139782. _psy_tone_suppress,
  139783. _vp_tonemask_adj_11,
  139784. NULL,
  139785. _vp_tonemask_adj_11,
  139786. _psy_noiseguards_8,
  139787. _psy_noisebias_11,
  139788. _psy_noisebias_11,
  139789. NULL,
  139790. NULL,
  139791. _psy_noise_suppress,
  139792. _psy_compand_8,
  139793. _psy_compand_8_mapping,
  139794. NULL,
  139795. {_noise_start_8,_noise_start_8},
  139796. {_noise_part_8,_noise_part_8},
  139797. _noise_thresh_11,
  139798. _psy_ath_floater_8,
  139799. _psy_ath_abs_8,
  139800. _psy_lowpass_11,
  139801. _psy_global_44,
  139802. _global_mapping_8,
  139803. _psy_stereo_modes_8,
  139804. _floor_books,
  139805. _floor,
  139806. _floor_mapping_11,
  139807. NULL,
  139808. _mapres_template_8_stereo
  139809. };
  139810. ve_setup_data_template ve_setup_11_uncoupled={
  139811. 2,
  139812. rate_mapping_11_uncoupled,
  139813. quality_mapping_11,
  139814. -1,
  139815. 9000,
  139816. 15000,
  139817. blocksize_11,
  139818. blocksize_11,
  139819. _psy_tone_masteratt_11,
  139820. _psy_tone_0dB,
  139821. _psy_tone_suppress,
  139822. _vp_tonemask_adj_11,
  139823. NULL,
  139824. _vp_tonemask_adj_11,
  139825. _psy_noiseguards_8,
  139826. _psy_noisebias_11,
  139827. _psy_noisebias_11,
  139828. NULL,
  139829. NULL,
  139830. _psy_noise_suppress,
  139831. _psy_compand_8,
  139832. _psy_compand_8_mapping,
  139833. NULL,
  139834. {_noise_start_8,_noise_start_8},
  139835. {_noise_part_8,_noise_part_8},
  139836. _noise_thresh_11,
  139837. _psy_ath_floater_8,
  139838. _psy_ath_abs_8,
  139839. _psy_lowpass_11,
  139840. _psy_global_44,
  139841. _global_mapping_8,
  139842. _psy_stereo_modes_8,
  139843. _floor_books,
  139844. _floor,
  139845. _floor_mapping_11,
  139846. NULL,
  139847. _mapres_template_8_uncoupled
  139848. };
  139849. /*** End of inlined file: setup_11.h ***/
  139850. /*** Start of inlined file: setup_16.h ***/
  139851. /*** Start of inlined file: psych_16.h ***/
  139852. static adj_stereo _psy_stereo_modes_16[4]={
  139853. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139854. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139855. { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 4, 4},
  139856. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139857. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139858. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139859. { 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 4, 4, 4, 4, 4},
  139860. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139861. {{ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139862. { 5, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139863. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139864. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139865. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  139866. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  139867. { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8},
  139868. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139869. };
  139870. static double _psy_lowpass_16[4]={6.5,8,30.,99.};
  139871. static att3 _psy_tone_masteratt_16[4]={
  139872. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139873. {{ 25, 22, 12}, 0, 0}, /* 0 */
  139874. {{ 20, 12, 0}, 0, 0}, /* 0 */
  139875. {{ 15, 0, -14}, 0, 0}, /* 0 */
  139876. };
  139877. static vp_adjblock _vp_tonemask_adj_16[4]={
  139878. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 0, 0, 0, 0, 0}}, /* 0 */
  139879. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 0, 0, 0, 0, 0}}, /* 1 */
  139880. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, /* 2 */
  139881. {{-30,-30,-30,-30,-30,-26,-20,-10, -5, 0, 0, 0, 0, 0, 0, 0, 0}}, /* 2 */
  139882. };
  139883. static noise3 _psy_noisebias_16_short[4]={
  139884. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 10, 10, 10, 10, 12, 12, 14, 20},
  139885. {-15,-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 5, 5, 6, 8, 8, 15},
  139886. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139887. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 6, 6, 6, 6, 8, 10, 12, 20},
  139888. {-15,-15,-15,-15,-15,-15,-15,-10, -5, -5, -5, 4, 5, 6, 8, 8, 15},
  139889. {-30,-30,-30,-30,-30,-24,-20,-14,-10,-10,-10,-10,-10,-10,-10,-10,-10}}},
  139890. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 5, 8, 12},
  139891. {-20,-20,-20,-20,-16,-12,-20,-14,-10,-10, -8, 0, 0, 0, 0, 2, 5},
  139892. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139893. {{{-15,-15,-15,-15,-15,-12,-10, -8, -5, -5, -5, -5, -5, 0, 0, 0, 6},
  139894. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10,-10,-10, -6},
  139895. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139896. };
  139897. static noise3 _psy_noisebias_16_impulse[4]={
  139898. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 10, 10, 10, 10, 12, 12, 14, 20},
  139899. {-15,-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 5, 5, 6, 8, 8, 15},
  139900. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139901. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 4, 4, 4, 5, 5, 6, 8, 15},
  139902. {-15,-15,-15,-15,-15,-15,-15,-10, -5, -5, -5, 0, 0, 0, 0, 4, 10},
  139903. {-30,-30,-30,-30,-30,-24,-20,-14,-10,-10,-10,-10,-10,-10,-10,-10,-10}}},
  139904. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 0, 0, 0, 0, 0, 0, 4, 10},
  139905. {-20,-20,-20,-20,-16,-12,-20,-14,-10,-10,-10,-10,-10,-10,-10, -7, -5},
  139906. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139907. {{{-15,-15,-15,-15,-15,-12,-10, -8, -5, -5, -5, -5, -5, 0, 0, 0, 6},
  139908. {-30,-30,-30,-30,-26,-22,-20,-18,-18,-18,-20,-20,-20,-20,-20,-20,-16},
  139909. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139910. };
  139911. static noise3 _psy_noisebias_16[4]={
  139912. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 6, 8, 8, 10, 10, 10, 14, 20},
  139913. {-10,-10,-10,-10,-10, -5, -2, -2, 0, 0, 0, 4, 5, 6, 8, 8, 15},
  139914. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139915. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 6, 6, 6, 6, 8, 10, 12, 20},
  139916. {-15,-15,-15,-15,-15,-10, -5, -5, 0, 0, 0, 4, 5, 6, 8, 8, 15},
  139917. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139918. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 5, 8, 12},
  139919. {-20,-20,-20,-20,-16,-12,-20,-10, -5, -5, 0, 0, 0, 0, 0, 2, 5},
  139920. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139921. {{{-15,-15,-15,-15,-15,-12,-10, -8, -5, -5, -5, -5, -5, 0, 0, 0, 6},
  139922. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10,-10,-10, -6},
  139923. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139924. };
  139925. static double _noise_thresh_16[4]={ .3,.5,.5,.5 };
  139926. static int _noise_start_16[3]={ 256,256,9999 };
  139927. static int _noise_part_16[4]={ 8,8,8,8 };
  139928. static int _psy_ath_floater_16[4]={
  139929. -100,-100,-100,-105,
  139930. };
  139931. static int _psy_ath_abs_16[4]={
  139932. -130,-130,-130,-140,
  139933. };
  139934. /*** End of inlined file: psych_16.h ***/
  139935. /*** Start of inlined file: residue_16.h ***/
  139936. static static_bookblock _resbook_16s_0={
  139937. {
  139938. {0},
  139939. {0,0,&_16c0_s_p1_0},
  139940. {0,0,&_16c0_s_p2_0},
  139941. {0,0,&_16c0_s_p3_0},
  139942. {0,0,&_16c0_s_p4_0},
  139943. {0,0,&_16c0_s_p5_0},
  139944. {0,0,&_16c0_s_p6_0},
  139945. {&_16c0_s_p7_0,&_16c0_s_p7_1},
  139946. {&_16c0_s_p8_0,&_16c0_s_p8_1},
  139947. {&_16c0_s_p9_0,&_16c0_s_p9_1,&_16c0_s_p9_2}
  139948. }
  139949. };
  139950. static static_bookblock _resbook_16s_1={
  139951. {
  139952. {0},
  139953. {0,0,&_16c1_s_p1_0},
  139954. {0,0,&_16c1_s_p2_0},
  139955. {0,0,&_16c1_s_p3_0},
  139956. {0,0,&_16c1_s_p4_0},
  139957. {0,0,&_16c1_s_p5_0},
  139958. {0,0,&_16c1_s_p6_0},
  139959. {&_16c1_s_p7_0,&_16c1_s_p7_1},
  139960. {&_16c1_s_p8_0,&_16c1_s_p8_1},
  139961. {&_16c1_s_p9_0,&_16c1_s_p9_1,&_16c1_s_p9_2}
  139962. }
  139963. };
  139964. static static_bookblock _resbook_16s_2={
  139965. {
  139966. {0},
  139967. {0,0,&_16c2_s_p1_0},
  139968. {0,0,&_16c2_s_p2_0},
  139969. {0,0,&_16c2_s_p3_0},
  139970. {0,0,&_16c2_s_p4_0},
  139971. {&_16c2_s_p5_0,&_16c2_s_p5_1},
  139972. {&_16c2_s_p6_0,&_16c2_s_p6_1},
  139973. {&_16c2_s_p7_0,&_16c2_s_p7_1},
  139974. {&_16c2_s_p8_0,&_16c2_s_p8_1},
  139975. {&_16c2_s_p9_0,&_16c2_s_p9_1,&_16c2_s_p9_2}
  139976. }
  139977. };
  139978. static vorbis_residue_template _res_16s_0[]={
  139979. {2,0, &_residue_44_mid,
  139980. &_huff_book__16c0_s_single,&_huff_book__16c0_s_single,
  139981. &_resbook_16s_0,&_resbook_16s_0},
  139982. };
  139983. static vorbis_residue_template _res_16s_1[]={
  139984. {2,0, &_residue_44_mid,
  139985. &_huff_book__16c1_s_short,&_huff_book__16c1_s_short,
  139986. &_resbook_16s_1,&_resbook_16s_1},
  139987. {2,0, &_residue_44_mid,
  139988. &_huff_book__16c1_s_long,&_huff_book__16c1_s_long,
  139989. &_resbook_16s_1,&_resbook_16s_1}
  139990. };
  139991. static vorbis_residue_template _res_16s_2[]={
  139992. {2,0, &_residue_44_high,
  139993. &_huff_book__16c2_s_short,&_huff_book__16c2_s_short,
  139994. &_resbook_16s_2,&_resbook_16s_2},
  139995. {2,0, &_residue_44_high,
  139996. &_huff_book__16c2_s_long,&_huff_book__16c2_s_long,
  139997. &_resbook_16s_2,&_resbook_16s_2}
  139998. };
  139999. static vorbis_mapping_template _mapres_template_16_stereo[3]={
  140000. { _map_nominal, _res_16s_0 }, /* 0 */
  140001. { _map_nominal, _res_16s_1 }, /* 1 */
  140002. { _map_nominal, _res_16s_2 }, /* 2 */
  140003. };
  140004. static static_bookblock _resbook_16u_0={
  140005. {
  140006. {0},
  140007. {0,0,&_16u0__p1_0},
  140008. {0,0,&_16u0__p2_0},
  140009. {0,0,&_16u0__p3_0},
  140010. {0,0,&_16u0__p4_0},
  140011. {0,0,&_16u0__p5_0},
  140012. {&_16u0__p6_0,&_16u0__p6_1},
  140013. {&_16u0__p7_0,&_16u0__p7_1,&_16u0__p7_2}
  140014. }
  140015. };
  140016. static static_bookblock _resbook_16u_1={
  140017. {
  140018. {0},
  140019. {0,0,&_16u1__p1_0},
  140020. {0,0,&_16u1__p2_0},
  140021. {0,0,&_16u1__p3_0},
  140022. {0,0,&_16u1__p4_0},
  140023. {0,0,&_16u1__p5_0},
  140024. {0,0,&_16u1__p6_0},
  140025. {&_16u1__p7_0,&_16u1__p7_1},
  140026. {&_16u1__p8_0,&_16u1__p8_1},
  140027. {&_16u1__p9_0,&_16u1__p9_1,&_16u1__p9_2}
  140028. }
  140029. };
  140030. static static_bookblock _resbook_16u_2={
  140031. {
  140032. {0},
  140033. {0,0,&_16u2_p1_0},
  140034. {0,0,&_16u2_p2_0},
  140035. {0,0,&_16u2_p3_0},
  140036. {0,0,&_16u2_p4_0},
  140037. {&_16u2_p5_0,&_16u2_p5_1},
  140038. {&_16u2_p6_0,&_16u2_p6_1},
  140039. {&_16u2_p7_0,&_16u2_p7_1},
  140040. {&_16u2_p8_0,&_16u2_p8_1},
  140041. {&_16u2_p9_0,&_16u2_p9_1,&_16u2_p9_2}
  140042. }
  140043. };
  140044. static vorbis_residue_template _res_16u_0[]={
  140045. {1,0, &_residue_44_low_un,
  140046. &_huff_book__16u0__single,&_huff_book__16u0__single,
  140047. &_resbook_16u_0,&_resbook_16u_0},
  140048. };
  140049. static vorbis_residue_template _res_16u_1[]={
  140050. {1,0, &_residue_44_mid_un,
  140051. &_huff_book__16u1__short,&_huff_book__16u1__short,
  140052. &_resbook_16u_1,&_resbook_16u_1},
  140053. {1,0, &_residue_44_mid_un,
  140054. &_huff_book__16u1__long,&_huff_book__16u1__long,
  140055. &_resbook_16u_1,&_resbook_16u_1}
  140056. };
  140057. static vorbis_residue_template _res_16u_2[]={
  140058. {1,0, &_residue_44_hi_un,
  140059. &_huff_book__16u2__short,&_huff_book__16u2__short,
  140060. &_resbook_16u_2,&_resbook_16u_2},
  140061. {1,0, &_residue_44_hi_un,
  140062. &_huff_book__16u2__long,&_huff_book__16u2__long,
  140063. &_resbook_16u_2,&_resbook_16u_2}
  140064. };
  140065. static vorbis_mapping_template _mapres_template_16_uncoupled[3]={
  140066. { _map_nominal_u, _res_16u_0 }, /* 0 */
  140067. { _map_nominal_u, _res_16u_1 }, /* 1 */
  140068. { _map_nominal_u, _res_16u_2 }, /* 2 */
  140069. };
  140070. /*** End of inlined file: residue_16.h ***/
  140071. static int blocksize_16_short[3]={
  140072. 1024,512,512
  140073. };
  140074. static int blocksize_16_long[3]={
  140075. 1024,1024,1024
  140076. };
  140077. static int _floor_mapping_16_short[3]={
  140078. 9,3,3
  140079. };
  140080. static int _floor_mapping_16[3]={
  140081. 9,9,9
  140082. };
  140083. static double rate_mapping_16[4]={
  140084. 12000.,20000.,44000.,86000.
  140085. };
  140086. static double rate_mapping_16_uncoupled[4]={
  140087. 16000.,28000.,64000.,100000.
  140088. };
  140089. static double _global_mapping_16[4]={ 1., 2., 3., 4. };
  140090. static double quality_mapping_16[4]={ -.1,.05,.5,1. };
  140091. static double _psy_compand_16_mapping[4]={ 0., .8, 1., 1.};
  140092. ve_setup_data_template ve_setup_16_stereo={
  140093. 3,
  140094. rate_mapping_16,
  140095. quality_mapping_16,
  140096. 2,
  140097. 15000,
  140098. 19000,
  140099. blocksize_16_short,
  140100. blocksize_16_long,
  140101. _psy_tone_masteratt_16,
  140102. _psy_tone_0dB,
  140103. _psy_tone_suppress,
  140104. _vp_tonemask_adj_16,
  140105. _vp_tonemask_adj_16,
  140106. _vp_tonemask_adj_16,
  140107. _psy_noiseguards_8,
  140108. _psy_noisebias_16_impulse,
  140109. _psy_noisebias_16_short,
  140110. _psy_noisebias_16_short,
  140111. _psy_noisebias_16,
  140112. _psy_noise_suppress,
  140113. _psy_compand_8,
  140114. _psy_compand_16_mapping,
  140115. _psy_compand_16_mapping,
  140116. {_noise_start_16,_noise_start_16},
  140117. { _noise_part_16, _noise_part_16},
  140118. _noise_thresh_16,
  140119. _psy_ath_floater_16,
  140120. _psy_ath_abs_16,
  140121. _psy_lowpass_16,
  140122. _psy_global_44,
  140123. _global_mapping_16,
  140124. _psy_stereo_modes_16,
  140125. _floor_books,
  140126. _floor,
  140127. _floor_mapping_16_short,
  140128. _floor_mapping_16,
  140129. _mapres_template_16_stereo
  140130. };
  140131. ve_setup_data_template ve_setup_16_uncoupled={
  140132. 3,
  140133. rate_mapping_16_uncoupled,
  140134. quality_mapping_16,
  140135. -1,
  140136. 15000,
  140137. 19000,
  140138. blocksize_16_short,
  140139. blocksize_16_long,
  140140. _psy_tone_masteratt_16,
  140141. _psy_tone_0dB,
  140142. _psy_tone_suppress,
  140143. _vp_tonemask_adj_16,
  140144. _vp_tonemask_adj_16,
  140145. _vp_tonemask_adj_16,
  140146. _psy_noiseguards_8,
  140147. _psy_noisebias_16_impulse,
  140148. _psy_noisebias_16_short,
  140149. _psy_noisebias_16_short,
  140150. _psy_noisebias_16,
  140151. _psy_noise_suppress,
  140152. _psy_compand_8,
  140153. _psy_compand_16_mapping,
  140154. _psy_compand_16_mapping,
  140155. {_noise_start_16,_noise_start_16},
  140156. { _noise_part_16, _noise_part_16},
  140157. _noise_thresh_16,
  140158. _psy_ath_floater_16,
  140159. _psy_ath_abs_16,
  140160. _psy_lowpass_16,
  140161. _psy_global_44,
  140162. _global_mapping_16,
  140163. _psy_stereo_modes_16,
  140164. _floor_books,
  140165. _floor,
  140166. _floor_mapping_16_short,
  140167. _floor_mapping_16,
  140168. _mapres_template_16_uncoupled
  140169. };
  140170. /*** End of inlined file: setup_16.h ***/
  140171. /*** Start of inlined file: setup_22.h ***/
  140172. static double rate_mapping_22[4]={
  140173. 15000.,20000.,44000.,86000.
  140174. };
  140175. static double rate_mapping_22_uncoupled[4]={
  140176. 16000.,28000.,50000.,90000.
  140177. };
  140178. static double _psy_lowpass_22[4]={9.5,11.,30.,99.};
  140179. ve_setup_data_template ve_setup_22_stereo={
  140180. 3,
  140181. rate_mapping_22,
  140182. quality_mapping_16,
  140183. 2,
  140184. 19000,
  140185. 26000,
  140186. blocksize_16_short,
  140187. blocksize_16_long,
  140188. _psy_tone_masteratt_16,
  140189. _psy_tone_0dB,
  140190. _psy_tone_suppress,
  140191. _vp_tonemask_adj_16,
  140192. _vp_tonemask_adj_16,
  140193. _vp_tonemask_adj_16,
  140194. _psy_noiseguards_8,
  140195. _psy_noisebias_16_impulse,
  140196. _psy_noisebias_16_short,
  140197. _psy_noisebias_16_short,
  140198. _psy_noisebias_16,
  140199. _psy_noise_suppress,
  140200. _psy_compand_8,
  140201. _psy_compand_8_mapping,
  140202. _psy_compand_8_mapping,
  140203. {_noise_start_16,_noise_start_16},
  140204. { _noise_part_16, _noise_part_16},
  140205. _noise_thresh_16,
  140206. _psy_ath_floater_16,
  140207. _psy_ath_abs_16,
  140208. _psy_lowpass_22,
  140209. _psy_global_44,
  140210. _global_mapping_16,
  140211. _psy_stereo_modes_16,
  140212. _floor_books,
  140213. _floor,
  140214. _floor_mapping_16_short,
  140215. _floor_mapping_16,
  140216. _mapres_template_16_stereo
  140217. };
  140218. ve_setup_data_template ve_setup_22_uncoupled={
  140219. 3,
  140220. rate_mapping_22_uncoupled,
  140221. quality_mapping_16,
  140222. -1,
  140223. 19000,
  140224. 26000,
  140225. blocksize_16_short,
  140226. blocksize_16_long,
  140227. _psy_tone_masteratt_16,
  140228. _psy_tone_0dB,
  140229. _psy_tone_suppress,
  140230. _vp_tonemask_adj_16,
  140231. _vp_tonemask_adj_16,
  140232. _vp_tonemask_adj_16,
  140233. _psy_noiseguards_8,
  140234. _psy_noisebias_16_impulse,
  140235. _psy_noisebias_16_short,
  140236. _psy_noisebias_16_short,
  140237. _psy_noisebias_16,
  140238. _psy_noise_suppress,
  140239. _psy_compand_8,
  140240. _psy_compand_8_mapping,
  140241. _psy_compand_8_mapping,
  140242. {_noise_start_16,_noise_start_16},
  140243. { _noise_part_16, _noise_part_16},
  140244. _noise_thresh_16,
  140245. _psy_ath_floater_16,
  140246. _psy_ath_abs_16,
  140247. _psy_lowpass_22,
  140248. _psy_global_44,
  140249. _global_mapping_16,
  140250. _psy_stereo_modes_16,
  140251. _floor_books,
  140252. _floor,
  140253. _floor_mapping_16_short,
  140254. _floor_mapping_16,
  140255. _mapres_template_16_uncoupled
  140256. };
  140257. /*** End of inlined file: setup_22.h ***/
  140258. /*** Start of inlined file: setup_X.h ***/
  140259. static double rate_mapping_X[12]={
  140260. -1.,-1.,-1.,-1.,-1.,-1.,
  140261. -1.,-1.,-1.,-1.,-1.,-1.
  140262. };
  140263. ve_setup_data_template ve_setup_X_stereo={
  140264. 11,
  140265. rate_mapping_X,
  140266. quality_mapping_44,
  140267. 2,
  140268. 50000,
  140269. 200000,
  140270. blocksize_short_44,
  140271. blocksize_long_44,
  140272. _psy_tone_masteratt_44,
  140273. _psy_tone_0dB,
  140274. _psy_tone_suppress,
  140275. _vp_tonemask_adj_otherblock,
  140276. _vp_tonemask_adj_longblock,
  140277. _vp_tonemask_adj_otherblock,
  140278. _psy_noiseguards_44,
  140279. _psy_noisebias_impulse,
  140280. _psy_noisebias_padding,
  140281. _psy_noisebias_trans,
  140282. _psy_noisebias_long,
  140283. _psy_noise_suppress,
  140284. _psy_compand_44,
  140285. _psy_compand_short_mapping,
  140286. _psy_compand_long_mapping,
  140287. {_noise_start_short_44,_noise_start_long_44},
  140288. {_noise_part_short_44,_noise_part_long_44},
  140289. _noise_thresh_44,
  140290. _psy_ath_floater,
  140291. _psy_ath_abs,
  140292. _psy_lowpass_44,
  140293. _psy_global_44,
  140294. _global_mapping_44,
  140295. _psy_stereo_modes_44,
  140296. _floor_books,
  140297. _floor,
  140298. _floor_short_mapping_44,
  140299. _floor_long_mapping_44,
  140300. _mapres_template_44_stereo
  140301. };
  140302. ve_setup_data_template ve_setup_X_uncoupled={
  140303. 11,
  140304. rate_mapping_X,
  140305. quality_mapping_44,
  140306. -1,
  140307. 50000,
  140308. 200000,
  140309. blocksize_short_44,
  140310. blocksize_long_44,
  140311. _psy_tone_masteratt_44,
  140312. _psy_tone_0dB,
  140313. _psy_tone_suppress,
  140314. _vp_tonemask_adj_otherblock,
  140315. _vp_tonemask_adj_longblock,
  140316. _vp_tonemask_adj_otherblock,
  140317. _psy_noiseguards_44,
  140318. _psy_noisebias_impulse,
  140319. _psy_noisebias_padding,
  140320. _psy_noisebias_trans,
  140321. _psy_noisebias_long,
  140322. _psy_noise_suppress,
  140323. _psy_compand_44,
  140324. _psy_compand_short_mapping,
  140325. _psy_compand_long_mapping,
  140326. {_noise_start_short_44,_noise_start_long_44},
  140327. {_noise_part_short_44,_noise_part_long_44},
  140328. _noise_thresh_44,
  140329. _psy_ath_floater,
  140330. _psy_ath_abs,
  140331. _psy_lowpass_44,
  140332. _psy_global_44,
  140333. _global_mapping_44,
  140334. NULL,
  140335. _floor_books,
  140336. _floor,
  140337. _floor_short_mapping_44,
  140338. _floor_long_mapping_44,
  140339. _mapres_template_44_uncoupled
  140340. };
  140341. ve_setup_data_template ve_setup_XX_stereo={
  140342. 2,
  140343. rate_mapping_X,
  140344. quality_mapping_8,
  140345. 2,
  140346. 0,
  140347. 8000,
  140348. blocksize_8,
  140349. blocksize_8,
  140350. _psy_tone_masteratt_8,
  140351. _psy_tone_0dB,
  140352. _psy_tone_suppress,
  140353. _vp_tonemask_adj_8,
  140354. NULL,
  140355. _vp_tonemask_adj_8,
  140356. _psy_noiseguards_8,
  140357. _psy_noisebias_8,
  140358. _psy_noisebias_8,
  140359. NULL,
  140360. NULL,
  140361. _psy_noise_suppress,
  140362. _psy_compand_8,
  140363. _psy_compand_8_mapping,
  140364. NULL,
  140365. {_noise_start_8,_noise_start_8},
  140366. {_noise_part_8,_noise_part_8},
  140367. _noise_thresh_5only,
  140368. _psy_ath_floater_8,
  140369. _psy_ath_abs_8,
  140370. _psy_lowpass_8,
  140371. _psy_global_44,
  140372. _global_mapping_8,
  140373. _psy_stereo_modes_8,
  140374. _floor_books,
  140375. _floor,
  140376. _floor_mapping_8,
  140377. NULL,
  140378. _mapres_template_8_stereo
  140379. };
  140380. ve_setup_data_template ve_setup_XX_uncoupled={
  140381. 2,
  140382. rate_mapping_X,
  140383. quality_mapping_8,
  140384. -1,
  140385. 0,
  140386. 8000,
  140387. blocksize_8,
  140388. blocksize_8,
  140389. _psy_tone_masteratt_8,
  140390. _psy_tone_0dB,
  140391. _psy_tone_suppress,
  140392. _vp_tonemask_adj_8,
  140393. NULL,
  140394. _vp_tonemask_adj_8,
  140395. _psy_noiseguards_8,
  140396. _psy_noisebias_8,
  140397. _psy_noisebias_8,
  140398. NULL,
  140399. NULL,
  140400. _psy_noise_suppress,
  140401. _psy_compand_8,
  140402. _psy_compand_8_mapping,
  140403. NULL,
  140404. {_noise_start_8,_noise_start_8},
  140405. {_noise_part_8,_noise_part_8},
  140406. _noise_thresh_5only,
  140407. _psy_ath_floater_8,
  140408. _psy_ath_abs_8,
  140409. _psy_lowpass_8,
  140410. _psy_global_44,
  140411. _global_mapping_8,
  140412. _psy_stereo_modes_8,
  140413. _floor_books,
  140414. _floor,
  140415. _floor_mapping_8,
  140416. NULL,
  140417. _mapres_template_8_uncoupled
  140418. };
  140419. /*** End of inlined file: setup_X.h ***/
  140420. static ve_setup_data_template *setup_list[]={
  140421. &ve_setup_44_stereo,
  140422. &ve_setup_44_uncoupled,
  140423. &ve_setup_32_stereo,
  140424. &ve_setup_32_uncoupled,
  140425. &ve_setup_22_stereo,
  140426. &ve_setup_22_uncoupled,
  140427. &ve_setup_16_stereo,
  140428. &ve_setup_16_uncoupled,
  140429. &ve_setup_11_stereo,
  140430. &ve_setup_11_uncoupled,
  140431. &ve_setup_8_stereo,
  140432. &ve_setup_8_uncoupled,
  140433. &ve_setup_X_stereo,
  140434. &ve_setup_X_uncoupled,
  140435. &ve_setup_XX_stereo,
  140436. &ve_setup_XX_uncoupled,
  140437. 0
  140438. };
  140439. static int vorbis_encode_toplevel_setup(vorbis_info *vi,int ch,long rate){
  140440. if(vi && vi->codec_setup){
  140441. vi->version=0;
  140442. vi->channels=ch;
  140443. vi->rate=rate;
  140444. return(0);
  140445. }
  140446. return(OV_EINVAL);
  140447. }
  140448. static void vorbis_encode_floor_setup(vorbis_info *vi,double s,int block,
  140449. static_codebook ***books,
  140450. vorbis_info_floor1 *in,
  140451. int *x){
  140452. int i,k,is=s;
  140453. vorbis_info_floor1 *f=(vorbis_info_floor1*) _ogg_calloc(1,sizeof(*f));
  140454. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140455. memcpy(f,in+x[is],sizeof(*f));
  140456. f->n=ci->blocksizes[block]>>1;
  140457. {
  140458. int partitions=f->partitions;
  140459. int maxclass=-1;
  140460. int maxbook=-1;
  140461. for(i=0;i<partitions;i++)
  140462. if(f->partitionclass[i]>maxclass)maxclass=f->partitionclass[i];
  140463. for(i=0;i<=maxclass;i++){
  140464. if(f->class_book[i]>maxbook)maxbook=f->class_book[i];
  140465. f->class_book[i]+=ci->books;
  140466. for(k=0;k<(1<<f->class_subs[i]);k++){
  140467. if(f->class_subbook[i][k]>maxbook)maxbook=f->class_subbook[i][k];
  140468. if(f->class_subbook[i][k]>=0)f->class_subbook[i][k]+=ci->books;
  140469. }
  140470. }
  140471. for(i=0;i<=maxbook;i++)
  140472. ci->book_param[ci->books++]=books[x[is]][i];
  140473. }
  140474. ci->floor_type[ci->floors]=1;
  140475. ci->floor_param[ci->floors]=f;
  140476. ci->floors++;
  140477. return;
  140478. }
  140479. static void vorbis_encode_global_psych_setup(vorbis_info *vi,double s,
  140480. vorbis_info_psy_global *in,
  140481. double *x){
  140482. int i,is=s;
  140483. double ds=s-is;
  140484. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140485. vorbis_info_psy_global *g=&ci->psy_g_param;
  140486. memcpy(g,in+(int)x[is],sizeof(*g));
  140487. ds=x[is]*(1.-ds)+x[is+1]*ds;
  140488. is=(int)ds;
  140489. ds-=is;
  140490. if(ds==0 && is>0){
  140491. is--;
  140492. ds=1.;
  140493. }
  140494. for(i=0;i<4;i++){
  140495. g->preecho_thresh[i]=in[is].preecho_thresh[i]*(1.-ds)+in[is+1].preecho_thresh[i]*ds;
  140496. g->postecho_thresh[i]=in[is].postecho_thresh[i]*(1.-ds)+in[is+1].postecho_thresh[i]*ds;
  140497. }
  140498. g->ampmax_att_per_sec=ci->hi.amplitude_track_dBpersec;
  140499. return;
  140500. }
  140501. static void vorbis_encode_global_stereo(vorbis_info *vi,
  140502. highlevel_encode_setup *hi,
  140503. adj_stereo *p){
  140504. float s=hi->stereo_point_setting;
  140505. int i,is=s;
  140506. double ds=s-is;
  140507. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140508. vorbis_info_psy_global *g=&ci->psy_g_param;
  140509. if(p){
  140510. memcpy(g->coupling_prepointamp,p[is].pre,sizeof(*p[is].pre)*PACKETBLOBS);
  140511. memcpy(g->coupling_postpointamp,p[is].post,sizeof(*p[is].post)*PACKETBLOBS);
  140512. if(hi->managed){
  140513. for(i=0;i<PACKETBLOBS;i++){
  140514. float kHz=p[is].kHz[i]*(1.-ds)+p[is+1].kHz[i]*ds;
  140515. g->coupling_pointlimit[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140516. g->coupling_pointlimit[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140517. g->coupling_pkHz[i]=kHz;
  140518. kHz=p[is].lowpasskHz[i]*(1.-ds)+p[is+1].lowpasskHz[i]*ds;
  140519. g->sliding_lowpass[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140520. g->sliding_lowpass[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140521. }
  140522. }else{
  140523. float kHz=p[is].kHz[PACKETBLOBS/2]*(1.-ds)+p[is+1].kHz[PACKETBLOBS/2]*ds;
  140524. for(i=0;i<PACKETBLOBS;i++){
  140525. g->coupling_pointlimit[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140526. g->coupling_pointlimit[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140527. g->coupling_pkHz[i]=kHz;
  140528. }
  140529. kHz=p[is].lowpasskHz[PACKETBLOBS/2]*(1.-ds)+p[is+1].lowpasskHz[PACKETBLOBS/2]*ds;
  140530. for(i=0;i<PACKETBLOBS;i++){
  140531. g->sliding_lowpass[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140532. g->sliding_lowpass[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140533. }
  140534. }
  140535. }else{
  140536. for(i=0;i<PACKETBLOBS;i++){
  140537. g->sliding_lowpass[0][i]=ci->blocksizes[0];
  140538. g->sliding_lowpass[1][i]=ci->blocksizes[1];
  140539. }
  140540. }
  140541. return;
  140542. }
  140543. static void vorbis_encode_psyset_setup(vorbis_info *vi,double s,
  140544. int *nn_start,
  140545. int *nn_partition,
  140546. double *nn_thresh,
  140547. int block){
  140548. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140549. vorbis_info_psy *p=ci->psy_param[block];
  140550. highlevel_encode_setup *hi=&ci->hi;
  140551. int is=s;
  140552. if(block>=ci->psys)
  140553. ci->psys=block+1;
  140554. if(!p){
  140555. p=(vorbis_info_psy*)_ogg_calloc(1,sizeof(*p));
  140556. ci->psy_param[block]=p;
  140557. }
  140558. memcpy(p,&_psy_info_template,sizeof(*p));
  140559. p->blockflag=block>>1;
  140560. if(hi->noise_normalize_p){
  140561. p->normal_channel_p=1;
  140562. p->normal_point_p=1;
  140563. p->normal_start=nn_start[is];
  140564. p->normal_partition=nn_partition[is];
  140565. p->normal_thresh=nn_thresh[is];
  140566. }
  140567. return;
  140568. }
  140569. static void vorbis_encode_tonemask_setup(vorbis_info *vi,double s,int block,
  140570. att3 *att,
  140571. int *max,
  140572. vp_adjblock *in){
  140573. int i,is=s;
  140574. double ds=s-is;
  140575. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140576. vorbis_info_psy *p=ci->psy_param[block];
  140577. p->tone_masteratt[0]=att[is].att[0]*(1.-ds)+att[is+1].att[0]*ds;
  140578. p->tone_masteratt[1]=att[is].att[1]*(1.-ds)+att[is+1].att[1]*ds;
  140579. p->tone_masteratt[2]=att[is].att[2]*(1.-ds)+att[is+1].att[2]*ds;
  140580. p->tone_centerboost=att[is].boost*(1.-ds)+att[is+1].boost*ds;
  140581. p->tone_decay=att[is].decay*(1.-ds)+att[is+1].decay*ds;
  140582. p->max_curve_dB=max[is]*(1.-ds)+max[is+1]*ds;
  140583. for(i=0;i<P_BANDS;i++)
  140584. p->toneatt[i]=in[is].block[i]*(1.-ds)+in[is+1].block[i]*ds;
  140585. return;
  140586. }
  140587. static void vorbis_encode_compand_setup(vorbis_info *vi,double s,int block,
  140588. compandblock *in, double *x){
  140589. int i,is=s;
  140590. double ds=s-is;
  140591. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140592. vorbis_info_psy *p=ci->psy_param[block];
  140593. ds=x[is]*(1.-ds)+x[is+1]*ds;
  140594. is=(int)ds;
  140595. ds-=is;
  140596. if(ds==0 && is>0){
  140597. is--;
  140598. ds=1.;
  140599. }
  140600. for(i=0;i<NOISE_COMPAND_LEVELS;i++)
  140601. p->noisecompand[i]=in[is].data[i]*(1.-ds)+in[is+1].data[i]*ds;
  140602. return;
  140603. }
  140604. static void vorbis_encode_peak_setup(vorbis_info *vi,double s,int block,
  140605. int *suppress){
  140606. int is=s;
  140607. double ds=s-is;
  140608. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140609. vorbis_info_psy *p=ci->psy_param[block];
  140610. p->tone_abs_limit=suppress[is]*(1.-ds)+suppress[is+1]*ds;
  140611. return;
  140612. }
  140613. static void vorbis_encode_noisebias_setup(vorbis_info *vi,double s,int block,
  140614. int *suppress,
  140615. noise3 *in,
  140616. noiseguard *guard,
  140617. double userbias){
  140618. int i,is=s,j;
  140619. double ds=s-is;
  140620. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140621. vorbis_info_psy *p=ci->psy_param[block];
  140622. p->noisemaxsupp=suppress[is]*(1.-ds)+suppress[is+1]*ds;
  140623. p->noisewindowlomin=guard[block].lo;
  140624. p->noisewindowhimin=guard[block].hi;
  140625. p->noisewindowfixed=guard[block].fixed;
  140626. for(j=0;j<P_NOISECURVES;j++)
  140627. for(i=0;i<P_BANDS;i++)
  140628. p->noiseoff[j][i]=in[is].data[j][i]*(1.-ds)+in[is+1].data[j][i]*ds;
  140629. for(j=0;j<P_NOISECURVES;j++){
  140630. float min=p->noiseoff[j][0]+6; /* the lowest it can go */
  140631. for(i=0;i<P_BANDS;i++){
  140632. p->noiseoff[j][i]+=userbias;
  140633. if(p->noiseoff[j][i]<min)p->noiseoff[j][i]=min;
  140634. }
  140635. }
  140636. return;
  140637. }
  140638. static void vorbis_encode_ath_setup(vorbis_info *vi,int block){
  140639. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140640. vorbis_info_psy *p=ci->psy_param[block];
  140641. p->ath_adjatt=ci->hi.ath_floating_dB;
  140642. p->ath_maxatt=ci->hi.ath_absolute_dB;
  140643. return;
  140644. }
  140645. static int book_dup_or_new(codec_setup_info *ci,static_codebook *book){
  140646. int i;
  140647. for(i=0;i<ci->books;i++)
  140648. if(ci->book_param[i]==book)return(i);
  140649. return(ci->books++);
  140650. }
  140651. static void vorbis_encode_blocksize_setup(vorbis_info *vi,double s,
  140652. int *shortb,int *longb){
  140653. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140654. int is=s;
  140655. int blockshort=shortb[is];
  140656. int blocklong=longb[is];
  140657. ci->blocksizes[0]=blockshort;
  140658. ci->blocksizes[1]=blocklong;
  140659. }
  140660. static void vorbis_encode_residue_setup(vorbis_info *vi,
  140661. int number, int block,
  140662. vorbis_residue_template *res){
  140663. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140664. int i,n;
  140665. vorbis_info_residue0 *r=(vorbis_info_residue0*)(ci->residue_param[number]=
  140666. (vorbis_info_residue0*)_ogg_malloc(sizeof(*r)));
  140667. memcpy(r,res->res,sizeof(*r));
  140668. if(ci->residues<=number)ci->residues=number+1;
  140669. switch(ci->blocksizes[block]){
  140670. case 64:case 128:case 256:
  140671. r->grouping=16;
  140672. break;
  140673. default:
  140674. r->grouping=32;
  140675. break;
  140676. }
  140677. ci->residue_type[number]=res->res_type;
  140678. n=r->end=ci->blocksizes[block]>>1;
  140679. if(res->res_type==2)
  140680. n=r->end*=vi->channels;
  140681. {
  140682. int booklist=0,k;
  140683. if(ci->hi.managed){
  140684. for(i=0;i<r->partitions;i++)
  140685. for(k=0;k<3;k++)
  140686. if(res->books_base_managed->books[i][k])
  140687. r->secondstages[i]|=(1<<k);
  140688. r->groupbook=book_dup_or_new(ci,res->book_aux_managed);
  140689. ci->book_param[r->groupbook]=res->book_aux_managed;
  140690. for(i=0;i<r->partitions;i++){
  140691. for(k=0;k<3;k++){
  140692. if(res->books_base_managed->books[i][k]){
  140693. int bookid=book_dup_or_new(ci,res->books_base_managed->books[i][k]);
  140694. r->booklist[booklist++]=bookid;
  140695. ci->book_param[bookid]=res->books_base_managed->books[i][k];
  140696. }
  140697. }
  140698. }
  140699. }else{
  140700. for(i=0;i<r->partitions;i++)
  140701. for(k=0;k<3;k++)
  140702. if(res->books_base->books[i][k])
  140703. r->secondstages[i]|=(1<<k);
  140704. r->groupbook=book_dup_or_new(ci,res->book_aux);
  140705. ci->book_param[r->groupbook]=res->book_aux;
  140706. for(i=0;i<r->partitions;i++){
  140707. for(k=0;k<3;k++){
  140708. if(res->books_base->books[i][k]){
  140709. int bookid=book_dup_or_new(ci,res->books_base->books[i][k]);
  140710. r->booklist[booklist++]=bookid;
  140711. ci->book_param[bookid]=res->books_base->books[i][k];
  140712. }
  140713. }
  140714. }
  140715. }
  140716. }
  140717. {
  140718. double freq=ci->hi.lowpass_kHz*1000.;
  140719. vorbis_info_floor1 *f=(vorbis_info_floor1*)ci->floor_param[block]; /* by convention */
  140720. double nyq=vi->rate/2.;
  140721. long blocksize=ci->blocksizes[block]>>1;
  140722. if(freq>nyq)freq=nyq;
  140723. f->n=freq/nyq*blocksize;
  140724. if(res->limit_type){
  140725. if(ci->hi.managed)
  140726. freq=ci->psy_g_param.coupling_pkHz[PACKETBLOBS-1]*1000.;
  140727. else
  140728. freq=ci->psy_g_param.coupling_pkHz[PACKETBLOBS/2]*1000.;
  140729. if(freq>nyq)freq=nyq;
  140730. }
  140731. if(ci->residue_type[block]==2)
  140732. r->end=(int)((freq/nyq*blocksize*2)/r->grouping+.9)* /* round up only if we're well past */
  140733. r->grouping;
  140734. else
  140735. r->end=(int)((freq/nyq*blocksize)/r->grouping+.9)* /* round up only if we're well past */
  140736. r->grouping;
  140737. }
  140738. }
  140739. static void vorbis_encode_map_n_res_setup(vorbis_info *vi,double s,
  140740. vorbis_mapping_template *maps){
  140741. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140742. int i,j,is=s,modes=2;
  140743. vorbis_info_mapping0 *map=maps[is].map;
  140744. vorbis_info_mode *mode=_mode_template;
  140745. vorbis_residue_template *res=maps[is].res;
  140746. if(ci->blocksizes[0]==ci->blocksizes[1])modes=1;
  140747. for(i=0;i<modes;i++){
  140748. ci->map_param[i]=_ogg_calloc(1,sizeof(*map));
  140749. ci->mode_param[i]=(vorbis_info_mode*)_ogg_calloc(1,sizeof(*mode));
  140750. memcpy(ci->mode_param[i],mode+i,sizeof(*_mode_template));
  140751. if(i>=ci->modes)ci->modes=i+1;
  140752. ci->map_type[i]=0;
  140753. memcpy(ci->map_param[i],map+i,sizeof(*map));
  140754. if(i>=ci->maps)ci->maps=i+1;
  140755. for(j=0;j<map[i].submaps;j++)
  140756. vorbis_encode_residue_setup(vi,map[i].residuesubmap[j],i
  140757. ,res+map[i].residuesubmap[j]);
  140758. }
  140759. }
  140760. static double setting_to_approx_bitrate(vorbis_info *vi){
  140761. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140762. highlevel_encode_setup *hi=&ci->hi;
  140763. ve_setup_data_template *setup=(ve_setup_data_template *)hi->setup;
  140764. int is=hi->base_setting;
  140765. double ds=hi->base_setting-is;
  140766. int ch=vi->channels;
  140767. double *r=setup->rate_mapping;
  140768. if(r==NULL)
  140769. return(-1);
  140770. return((r[is]*(1.-ds)+r[is+1]*ds)*ch);
  140771. }
  140772. static void get_setup_template(vorbis_info *vi,
  140773. long ch,long srate,
  140774. double req,int q_or_bitrate){
  140775. int i=0,j;
  140776. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140777. highlevel_encode_setup *hi=&ci->hi;
  140778. if(q_or_bitrate)req/=ch;
  140779. while(setup_list[i]){
  140780. if(setup_list[i]->coupling_restriction==-1 ||
  140781. setup_list[i]->coupling_restriction==ch){
  140782. if(srate>=setup_list[i]->samplerate_min_restriction &&
  140783. srate<=setup_list[i]->samplerate_max_restriction){
  140784. int mappings=setup_list[i]->mappings;
  140785. double *map=(q_or_bitrate?
  140786. setup_list[i]->rate_mapping:
  140787. setup_list[i]->quality_mapping);
  140788. if(req<map[0]){++i;continue;}
  140789. if(req>map[setup_list[i]->mappings]){++i;continue;}
  140790. for(j=0;j<mappings;j++)
  140791. if(req>=map[j] && req<map[j+1])break;
  140792. hi->setup=setup_list[i];
  140793. if(j==mappings)
  140794. hi->base_setting=j-.001;
  140795. else{
  140796. float low=map[j];
  140797. float high=map[j+1];
  140798. float del=(req-low)/(high-low);
  140799. hi->base_setting=j+del;
  140800. }
  140801. return;
  140802. }
  140803. }
  140804. i++;
  140805. }
  140806. hi->setup=NULL;
  140807. }
  140808. int vorbis_encode_setup_init(vorbis_info *vi){
  140809. int i0=0,singleblock=0;
  140810. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140811. ve_setup_data_template *setup=NULL;
  140812. highlevel_encode_setup *hi=&ci->hi;
  140813. if(ci==NULL)return(OV_EINVAL);
  140814. if(!hi->impulse_block_p)i0=1;
  140815. if(hi->ath_floating_dB>-80)hi->ath_floating_dB=-80;
  140816. if(hi->ath_floating_dB<-200)hi->ath_floating_dB=-200;
  140817. if(hi->amplitude_track_dBpersec>0.)hi->amplitude_track_dBpersec=0.;
  140818. if(hi->amplitude_track_dBpersec<-99999.)hi->amplitude_track_dBpersec=-99999.;
  140819. setup=(ve_setup_data_template *)hi->setup;
  140820. if(setup==NULL)return(OV_EINVAL);
  140821. hi->set_in_stone=1;
  140822. vorbis_encode_blocksize_setup(vi,hi->base_setting,
  140823. setup->blocksize_short,
  140824. setup->blocksize_long);
  140825. if(ci->blocksizes[0]==ci->blocksizes[1])singleblock=1;
  140826. vorbis_encode_floor_setup(vi,hi->short_setting,0,
  140827. setup->floor_books,
  140828. setup->floor_params,
  140829. setup->floor_short_mapping);
  140830. if(!singleblock)
  140831. vorbis_encode_floor_setup(vi,hi->long_setting,1,
  140832. setup->floor_books,
  140833. setup->floor_params,
  140834. setup->floor_long_mapping);
  140835. vorbis_encode_global_psych_setup(vi,hi->trigger_setting,
  140836. setup->global_params,
  140837. setup->global_mapping);
  140838. vorbis_encode_global_stereo(vi,hi,setup->stereo_modes);
  140839. vorbis_encode_psyset_setup(vi,hi->short_setting,
  140840. setup->psy_noise_normal_start[0],
  140841. setup->psy_noise_normal_partition[0],
  140842. setup->psy_noise_normal_thresh,
  140843. 0);
  140844. vorbis_encode_psyset_setup(vi,hi->short_setting,
  140845. setup->psy_noise_normal_start[0],
  140846. setup->psy_noise_normal_partition[0],
  140847. setup->psy_noise_normal_thresh,
  140848. 1);
  140849. if(!singleblock){
  140850. vorbis_encode_psyset_setup(vi,hi->long_setting,
  140851. setup->psy_noise_normal_start[1],
  140852. setup->psy_noise_normal_partition[1],
  140853. setup->psy_noise_normal_thresh,
  140854. 2);
  140855. vorbis_encode_psyset_setup(vi,hi->long_setting,
  140856. setup->psy_noise_normal_start[1],
  140857. setup->psy_noise_normal_partition[1],
  140858. setup->psy_noise_normal_thresh,
  140859. 3);
  140860. }
  140861. vorbis_encode_tonemask_setup(vi,hi->block[i0].tone_mask_setting,0,
  140862. setup->psy_tone_masteratt,
  140863. setup->psy_tone_0dB,
  140864. setup->psy_tone_adj_impulse);
  140865. vorbis_encode_tonemask_setup(vi,hi->block[1].tone_mask_setting,1,
  140866. setup->psy_tone_masteratt,
  140867. setup->psy_tone_0dB,
  140868. setup->psy_tone_adj_other);
  140869. if(!singleblock){
  140870. vorbis_encode_tonemask_setup(vi,hi->block[2].tone_mask_setting,2,
  140871. setup->psy_tone_masteratt,
  140872. setup->psy_tone_0dB,
  140873. setup->psy_tone_adj_other);
  140874. vorbis_encode_tonemask_setup(vi,hi->block[3].tone_mask_setting,3,
  140875. setup->psy_tone_masteratt,
  140876. setup->psy_tone_0dB,
  140877. setup->psy_tone_adj_long);
  140878. }
  140879. vorbis_encode_compand_setup(vi,hi->block[i0].noise_compand_setting,0,
  140880. setup->psy_noise_compand,
  140881. setup->psy_noise_compand_short_mapping);
  140882. vorbis_encode_compand_setup(vi,hi->block[1].noise_compand_setting,1,
  140883. setup->psy_noise_compand,
  140884. setup->psy_noise_compand_short_mapping);
  140885. if(!singleblock){
  140886. vorbis_encode_compand_setup(vi,hi->block[2].noise_compand_setting,2,
  140887. setup->psy_noise_compand,
  140888. setup->psy_noise_compand_long_mapping);
  140889. vorbis_encode_compand_setup(vi,hi->block[3].noise_compand_setting,3,
  140890. setup->psy_noise_compand,
  140891. setup->psy_noise_compand_long_mapping);
  140892. }
  140893. vorbis_encode_peak_setup(vi,hi->block[i0].tone_peaklimit_setting,0,
  140894. setup->psy_tone_dBsuppress);
  140895. vorbis_encode_peak_setup(vi,hi->block[1].tone_peaklimit_setting,1,
  140896. setup->psy_tone_dBsuppress);
  140897. if(!singleblock){
  140898. vorbis_encode_peak_setup(vi,hi->block[2].tone_peaklimit_setting,2,
  140899. setup->psy_tone_dBsuppress);
  140900. vorbis_encode_peak_setup(vi,hi->block[3].tone_peaklimit_setting,3,
  140901. setup->psy_tone_dBsuppress);
  140902. }
  140903. vorbis_encode_noisebias_setup(vi,hi->block[i0].noise_bias_setting,0,
  140904. setup->psy_noise_dBsuppress,
  140905. setup->psy_noise_bias_impulse,
  140906. setup->psy_noiseguards,
  140907. (i0==0?hi->impulse_noisetune:0.));
  140908. vorbis_encode_noisebias_setup(vi,hi->block[1].noise_bias_setting,1,
  140909. setup->psy_noise_dBsuppress,
  140910. setup->psy_noise_bias_padding,
  140911. setup->psy_noiseguards,0.);
  140912. if(!singleblock){
  140913. vorbis_encode_noisebias_setup(vi,hi->block[2].noise_bias_setting,2,
  140914. setup->psy_noise_dBsuppress,
  140915. setup->psy_noise_bias_trans,
  140916. setup->psy_noiseguards,0.);
  140917. vorbis_encode_noisebias_setup(vi,hi->block[3].noise_bias_setting,3,
  140918. setup->psy_noise_dBsuppress,
  140919. setup->psy_noise_bias_long,
  140920. setup->psy_noiseguards,0.);
  140921. }
  140922. vorbis_encode_ath_setup(vi,0);
  140923. vorbis_encode_ath_setup(vi,1);
  140924. if(!singleblock){
  140925. vorbis_encode_ath_setup(vi,2);
  140926. vorbis_encode_ath_setup(vi,3);
  140927. }
  140928. vorbis_encode_map_n_res_setup(vi,hi->base_setting,setup->maps);
  140929. if(hi->bitrate_av>0)
  140930. vi->bitrate_nominal=hi->bitrate_av;
  140931. else{
  140932. vi->bitrate_nominal=setting_to_approx_bitrate(vi);
  140933. }
  140934. vi->bitrate_lower=hi->bitrate_min;
  140935. vi->bitrate_upper=hi->bitrate_max;
  140936. if(hi->bitrate_av)
  140937. vi->bitrate_window=(double)hi->bitrate_reservoir/hi->bitrate_av;
  140938. else
  140939. vi->bitrate_window=0.;
  140940. if(hi->managed){
  140941. ci->bi.avg_rate=hi->bitrate_av;
  140942. ci->bi.min_rate=hi->bitrate_min;
  140943. ci->bi.max_rate=hi->bitrate_max;
  140944. ci->bi.reservoir_bits=hi->bitrate_reservoir;
  140945. ci->bi.reservoir_bias=
  140946. hi->bitrate_reservoir_bias;
  140947. ci->bi.slew_damp=hi->bitrate_av_damp;
  140948. }
  140949. return(0);
  140950. }
  140951. static int vorbis_encode_setup_setting(vorbis_info *vi,
  140952. long channels,
  140953. long rate){
  140954. int ret=0,i,is;
  140955. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140956. highlevel_encode_setup *hi=&ci->hi;
  140957. ve_setup_data_template *setup=(ve_setup_data_template*) hi->setup;
  140958. double ds;
  140959. ret=vorbis_encode_toplevel_setup(vi,channels,rate);
  140960. if(ret)return(ret);
  140961. is=hi->base_setting;
  140962. ds=hi->base_setting-is;
  140963. hi->short_setting=hi->base_setting;
  140964. hi->long_setting=hi->base_setting;
  140965. hi->managed=0;
  140966. hi->impulse_block_p=1;
  140967. hi->noise_normalize_p=1;
  140968. hi->stereo_point_setting=hi->base_setting;
  140969. hi->lowpass_kHz=
  140970. setup->psy_lowpass[is]*(1.-ds)+setup->psy_lowpass[is+1]*ds;
  140971. hi->ath_floating_dB=setup->psy_ath_float[is]*(1.-ds)+
  140972. setup->psy_ath_float[is+1]*ds;
  140973. hi->ath_absolute_dB=setup->psy_ath_abs[is]*(1.-ds)+
  140974. setup->psy_ath_abs[is+1]*ds;
  140975. hi->amplitude_track_dBpersec=-6.;
  140976. hi->trigger_setting=hi->base_setting;
  140977. for(i=0;i<4;i++){
  140978. hi->block[i].tone_mask_setting=hi->base_setting;
  140979. hi->block[i].tone_peaklimit_setting=hi->base_setting;
  140980. hi->block[i].noise_bias_setting=hi->base_setting;
  140981. hi->block[i].noise_compand_setting=hi->base_setting;
  140982. }
  140983. return(ret);
  140984. }
  140985. int vorbis_encode_setup_vbr(vorbis_info *vi,
  140986. long channels,
  140987. long rate,
  140988. float quality){
  140989. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140990. highlevel_encode_setup *hi=&ci->hi;
  140991. quality+=.0000001;
  140992. if(quality>=1.)quality=.9999;
  140993. get_setup_template(vi,channels,rate,quality,0);
  140994. if(!hi->setup)return OV_EIMPL;
  140995. return vorbis_encode_setup_setting(vi,channels,rate);
  140996. }
  140997. int vorbis_encode_init_vbr(vorbis_info *vi,
  140998. long channels,
  140999. long rate,
  141000. float base_quality /* 0. to 1. */
  141001. ){
  141002. int ret=0;
  141003. ret=vorbis_encode_setup_vbr(vi,channels,rate,base_quality);
  141004. if(ret){
  141005. vorbis_info_clear(vi);
  141006. return ret;
  141007. }
  141008. ret=vorbis_encode_setup_init(vi);
  141009. if(ret)
  141010. vorbis_info_clear(vi);
  141011. return(ret);
  141012. }
  141013. int vorbis_encode_setup_managed(vorbis_info *vi,
  141014. long channels,
  141015. long rate,
  141016. long max_bitrate,
  141017. long nominal_bitrate,
  141018. long min_bitrate){
  141019. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  141020. highlevel_encode_setup *hi=&ci->hi;
  141021. double tnominal=nominal_bitrate;
  141022. int ret=0;
  141023. if(nominal_bitrate<=0.){
  141024. if(max_bitrate>0.){
  141025. if(min_bitrate>0.)
  141026. nominal_bitrate=(max_bitrate+min_bitrate)*.5;
  141027. else
  141028. nominal_bitrate=max_bitrate*.875;
  141029. }else{
  141030. if(min_bitrate>0.){
  141031. nominal_bitrate=min_bitrate;
  141032. }else{
  141033. return(OV_EINVAL);
  141034. }
  141035. }
  141036. }
  141037. get_setup_template(vi,channels,rate,nominal_bitrate,1);
  141038. if(!hi->setup)return OV_EIMPL;
  141039. ret=vorbis_encode_setup_setting(vi,channels,rate);
  141040. if(ret){
  141041. vorbis_info_clear(vi);
  141042. return ret;
  141043. }
  141044. hi->managed=1;
  141045. hi->bitrate_min=min_bitrate;
  141046. hi->bitrate_max=max_bitrate;
  141047. hi->bitrate_av=tnominal;
  141048. hi->bitrate_av_damp=1.5f; /* full range in no less than 1.5 second */
  141049. hi->bitrate_reservoir=nominal_bitrate*2;
  141050. hi->bitrate_reservoir_bias=.1; /* bias toward hoarding bits */
  141051. return(ret);
  141052. }
  141053. int vorbis_encode_init(vorbis_info *vi,
  141054. long channels,
  141055. long rate,
  141056. long max_bitrate,
  141057. long nominal_bitrate,
  141058. long min_bitrate){
  141059. int ret=vorbis_encode_setup_managed(vi,channels,rate,
  141060. max_bitrate,
  141061. nominal_bitrate,
  141062. min_bitrate);
  141063. if(ret){
  141064. vorbis_info_clear(vi);
  141065. return(ret);
  141066. }
  141067. ret=vorbis_encode_setup_init(vi);
  141068. if(ret)
  141069. vorbis_info_clear(vi);
  141070. return(ret);
  141071. }
  141072. int vorbis_encode_ctl(vorbis_info *vi,int number,void *arg){
  141073. if(vi){
  141074. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  141075. highlevel_encode_setup *hi=&ci->hi;
  141076. int setp=(number&0xf); /* a read request has a low nibble of 0 */
  141077. if(setp && hi->set_in_stone)return(OV_EINVAL);
  141078. switch(number){
  141079. case OV_ECTL_RATEMANAGE_GET:
  141080. {
  141081. struct ovectl_ratemanage_arg *ai=
  141082. (struct ovectl_ratemanage_arg *)arg;
  141083. ai->management_active=hi->managed;
  141084. ai->bitrate_hard_window=ai->bitrate_av_window=
  141085. (double)hi->bitrate_reservoir/vi->rate;
  141086. ai->bitrate_av_window_center=1.;
  141087. ai->bitrate_hard_min=hi->bitrate_min;
  141088. ai->bitrate_hard_max=hi->bitrate_max;
  141089. ai->bitrate_av_lo=hi->bitrate_av;
  141090. ai->bitrate_av_hi=hi->bitrate_av;
  141091. }
  141092. return(0);
  141093. case OV_ECTL_RATEMANAGE_SET:
  141094. {
  141095. struct ovectl_ratemanage_arg *ai=
  141096. (struct ovectl_ratemanage_arg *)arg;
  141097. if(ai==NULL){
  141098. hi->managed=0;
  141099. }else{
  141100. hi->managed=ai->management_active;
  141101. vorbis_encode_ctl(vi,OV_ECTL_RATEMANAGE_AVG,arg);
  141102. vorbis_encode_ctl(vi,OV_ECTL_RATEMANAGE_HARD,arg);
  141103. }
  141104. }
  141105. return 0;
  141106. case OV_ECTL_RATEMANAGE_AVG:
  141107. {
  141108. struct ovectl_ratemanage_arg *ai=
  141109. (struct ovectl_ratemanage_arg *)arg;
  141110. if(ai==NULL){
  141111. hi->bitrate_av=0;
  141112. }else{
  141113. hi->bitrate_av=(ai->bitrate_av_lo+ai->bitrate_av_hi)*.5;
  141114. }
  141115. }
  141116. return(0);
  141117. case OV_ECTL_RATEMANAGE_HARD:
  141118. {
  141119. struct ovectl_ratemanage_arg *ai=
  141120. (struct ovectl_ratemanage_arg *)arg;
  141121. if(ai==NULL){
  141122. hi->bitrate_min=0;
  141123. hi->bitrate_max=0;
  141124. }else{
  141125. hi->bitrate_min=ai->bitrate_hard_min;
  141126. hi->bitrate_max=ai->bitrate_hard_max;
  141127. hi->bitrate_reservoir=ai->bitrate_hard_window*
  141128. (hi->bitrate_max+hi->bitrate_min)*.5;
  141129. }
  141130. if(hi->bitrate_reservoir<128.)
  141131. hi->bitrate_reservoir=128.;
  141132. }
  141133. return(0);
  141134. case OV_ECTL_RATEMANAGE2_GET:
  141135. {
  141136. struct ovectl_ratemanage2_arg *ai=
  141137. (struct ovectl_ratemanage2_arg *)arg;
  141138. if(ai==NULL)return OV_EINVAL;
  141139. ai->management_active=hi->managed;
  141140. ai->bitrate_limit_min_kbps=hi->bitrate_min/1000;
  141141. ai->bitrate_limit_max_kbps=hi->bitrate_max/1000;
  141142. ai->bitrate_average_kbps=hi->bitrate_av/1000;
  141143. ai->bitrate_average_damping=hi->bitrate_av_damp;
  141144. ai->bitrate_limit_reservoir_bits=hi->bitrate_reservoir;
  141145. ai->bitrate_limit_reservoir_bias=hi->bitrate_reservoir_bias;
  141146. }
  141147. return (0);
  141148. case OV_ECTL_RATEMANAGE2_SET:
  141149. {
  141150. struct ovectl_ratemanage2_arg *ai=
  141151. (struct ovectl_ratemanage2_arg *)arg;
  141152. if(ai==NULL){
  141153. hi->managed=0;
  141154. }else{
  141155. if(ai->bitrate_limit_min_kbps>0 &&
  141156. ai->bitrate_average_kbps>0 &&
  141157. ai->bitrate_limit_min_kbps>ai->bitrate_average_kbps)
  141158. return OV_EINVAL;
  141159. if(ai->bitrate_limit_max_kbps>0 &&
  141160. ai->bitrate_average_kbps>0 &&
  141161. ai->bitrate_limit_max_kbps<ai->bitrate_average_kbps)
  141162. return OV_EINVAL;
  141163. if(ai->bitrate_limit_min_kbps>0 &&
  141164. ai->bitrate_limit_max_kbps>0 &&
  141165. ai->bitrate_limit_min_kbps>ai->bitrate_limit_max_kbps)
  141166. return OV_EINVAL;
  141167. if(ai->bitrate_average_damping <= 0.)
  141168. return OV_EINVAL;
  141169. if(ai->bitrate_limit_reservoir_bits < 0)
  141170. return OV_EINVAL;
  141171. if(ai->bitrate_limit_reservoir_bias < 0.)
  141172. return OV_EINVAL;
  141173. if(ai->bitrate_limit_reservoir_bias > 1.)
  141174. return OV_EINVAL;
  141175. hi->managed=ai->management_active;
  141176. hi->bitrate_min=ai->bitrate_limit_min_kbps * 1000;
  141177. hi->bitrate_max=ai->bitrate_limit_max_kbps * 1000;
  141178. hi->bitrate_av=ai->bitrate_average_kbps * 1000;
  141179. hi->bitrate_av_damp=ai->bitrate_average_damping;
  141180. hi->bitrate_reservoir=ai->bitrate_limit_reservoir_bits;
  141181. hi->bitrate_reservoir_bias=ai->bitrate_limit_reservoir_bias;
  141182. }
  141183. }
  141184. return 0;
  141185. case OV_ECTL_LOWPASS_GET:
  141186. {
  141187. double *farg=(double *)arg;
  141188. *farg=hi->lowpass_kHz;
  141189. }
  141190. return(0);
  141191. case OV_ECTL_LOWPASS_SET:
  141192. {
  141193. double *farg=(double *)arg;
  141194. hi->lowpass_kHz=*farg;
  141195. if(hi->lowpass_kHz<2.)hi->lowpass_kHz=2.;
  141196. if(hi->lowpass_kHz>99.)hi->lowpass_kHz=99.;
  141197. }
  141198. return(0);
  141199. case OV_ECTL_IBLOCK_GET:
  141200. {
  141201. double *farg=(double *)arg;
  141202. *farg=hi->impulse_noisetune;
  141203. }
  141204. return(0);
  141205. case OV_ECTL_IBLOCK_SET:
  141206. {
  141207. double *farg=(double *)arg;
  141208. hi->impulse_noisetune=*farg;
  141209. if(hi->impulse_noisetune>0.)hi->impulse_noisetune=0.;
  141210. if(hi->impulse_noisetune<-15.)hi->impulse_noisetune=-15.;
  141211. }
  141212. return(0);
  141213. }
  141214. return(OV_EIMPL);
  141215. }
  141216. return(OV_EINVAL);
  141217. }
  141218. #endif
  141219. /*** End of inlined file: vorbisenc.c ***/
  141220. /*** Start of inlined file: vorbisfile.c ***/
  141221. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  141222. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  141223. // tasks..
  141224. #if JUCE_MSVC
  141225. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  141226. #endif
  141227. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  141228. #if JUCE_USE_OGGVORBIS
  141229. #include <stdlib.h>
  141230. #include <stdio.h>
  141231. #include <errno.h>
  141232. #include <string.h>
  141233. #include <math.h>
  141234. #define CHUNKSIZE 8500 /* a shade over 8k; anyone using pages well
  141235. over 8k gets what they deserve */
  141236. static long _get_data(OggVorbis_File *vf){
  141237. errno=0;
  141238. if(vf->datasource){
  141239. char *buffer=ogg_sync_buffer(&vf->oy,CHUNKSIZE);
  141240. long bytes=(vf->callbacks.read_func)(buffer,1,CHUNKSIZE,vf->datasource);
  141241. if(bytes>0)ogg_sync_wrote(&vf->oy,bytes);
  141242. if(bytes==0 && errno)return(-1);
  141243. return(bytes);
  141244. }else
  141245. return(0);
  141246. }
  141247. static void _seek_helper(OggVorbis_File *vf,ogg_int64_t offset){
  141248. if(vf->datasource){
  141249. (vf->callbacks.seek_func)(vf->datasource, offset, SEEK_SET);
  141250. vf->offset=offset;
  141251. ogg_sync_reset(&vf->oy);
  141252. }else{
  141253. return;
  141254. }
  141255. }
  141256. static ogg_int64_t _get_next_page(OggVorbis_File *vf,ogg_page *og,
  141257. ogg_int64_t boundary){
  141258. if(boundary>0)boundary+=vf->offset;
  141259. while(1){
  141260. long more;
  141261. if(boundary>0 && vf->offset>=boundary)return(OV_FALSE);
  141262. more=ogg_sync_pageseek(&vf->oy,og);
  141263. if(more<0){
  141264. vf->offset-=more;
  141265. }else{
  141266. if(more==0){
  141267. if(!boundary)return(OV_FALSE);
  141268. {
  141269. long ret=_get_data(vf);
  141270. if(ret==0)return(OV_EOF);
  141271. if(ret<0)return(OV_EREAD);
  141272. }
  141273. }else{
  141274. ogg_int64_t ret=vf->offset;
  141275. vf->offset+=more;
  141276. return(ret);
  141277. }
  141278. }
  141279. }
  141280. }
  141281. static ogg_int64_t _get_prev_page(OggVorbis_File *vf,ogg_page *og){
  141282. ogg_int64_t begin=vf->offset;
  141283. ogg_int64_t end=begin;
  141284. ogg_int64_t ret;
  141285. ogg_int64_t offset=-1;
  141286. while(offset==-1){
  141287. begin-=CHUNKSIZE;
  141288. if(begin<0)
  141289. begin=0;
  141290. _seek_helper(vf,begin);
  141291. while(vf->offset<end){
  141292. ret=_get_next_page(vf,og,end-vf->offset);
  141293. if(ret==OV_EREAD)return(OV_EREAD);
  141294. if(ret<0){
  141295. break;
  141296. }else{
  141297. offset=ret;
  141298. }
  141299. }
  141300. }
  141301. _seek_helper(vf,offset);
  141302. ret=_get_next_page(vf,og,CHUNKSIZE);
  141303. if(ret<0)
  141304. return(OV_EFAULT);
  141305. return(offset);
  141306. }
  141307. static int _bisect_forward_serialno(OggVorbis_File *vf,
  141308. ogg_int64_t begin,
  141309. ogg_int64_t searched,
  141310. ogg_int64_t end,
  141311. long currentno,
  141312. long m){
  141313. ogg_int64_t endsearched=end;
  141314. ogg_int64_t next=end;
  141315. ogg_page og;
  141316. ogg_int64_t ret;
  141317. while(searched<endsearched){
  141318. ogg_int64_t bisect;
  141319. if(endsearched-searched<CHUNKSIZE){
  141320. bisect=searched;
  141321. }else{
  141322. bisect=(searched+endsearched)/2;
  141323. }
  141324. _seek_helper(vf,bisect);
  141325. ret=_get_next_page(vf,&og,-1);
  141326. if(ret==OV_EREAD)return(OV_EREAD);
  141327. if(ret<0 || ogg_page_serialno(&og)!=currentno){
  141328. endsearched=bisect;
  141329. if(ret>=0)next=ret;
  141330. }else{
  141331. searched=ret+og.header_len+og.body_len;
  141332. }
  141333. }
  141334. _seek_helper(vf,next);
  141335. ret=_get_next_page(vf,&og,-1);
  141336. if(ret==OV_EREAD)return(OV_EREAD);
  141337. if(searched>=end || ret<0){
  141338. vf->links=m+1;
  141339. vf->offsets=(ogg_int64_t*)_ogg_malloc((vf->links+1)*sizeof(*vf->offsets));
  141340. vf->serialnos=(long*)_ogg_malloc(vf->links*sizeof(*vf->serialnos));
  141341. vf->offsets[m+1]=searched;
  141342. }else{
  141343. ret=_bisect_forward_serialno(vf,next,vf->offset,
  141344. end,ogg_page_serialno(&og),m+1);
  141345. if(ret==OV_EREAD)return(OV_EREAD);
  141346. }
  141347. vf->offsets[m]=begin;
  141348. vf->serialnos[m]=currentno;
  141349. return(0);
  141350. }
  141351. static int _fetch_headers(OggVorbis_File *vf,vorbis_info *vi,vorbis_comment *vc,
  141352. long *serialno,ogg_page *og_ptr){
  141353. ogg_page og;
  141354. ogg_packet op;
  141355. int i,ret;
  141356. if(!og_ptr){
  141357. ogg_int64_t llret=_get_next_page(vf,&og,CHUNKSIZE);
  141358. if(llret==OV_EREAD)return(OV_EREAD);
  141359. if(llret<0)return OV_ENOTVORBIS;
  141360. og_ptr=&og;
  141361. }
  141362. ogg_stream_reset_serialno(&vf->os,ogg_page_serialno(og_ptr));
  141363. if(serialno)*serialno=vf->os.serialno;
  141364. vf->ready_state=STREAMSET;
  141365. vorbis_info_init(vi);
  141366. vorbis_comment_init(vc);
  141367. i=0;
  141368. while(i<3){
  141369. ogg_stream_pagein(&vf->os,og_ptr);
  141370. while(i<3){
  141371. int result=ogg_stream_packetout(&vf->os,&op);
  141372. if(result==0)break;
  141373. if(result==-1){
  141374. ret=OV_EBADHEADER;
  141375. goto bail_header;
  141376. }
  141377. if((ret=vorbis_synthesis_headerin(vi,vc,&op))){
  141378. goto bail_header;
  141379. }
  141380. i++;
  141381. }
  141382. if(i<3)
  141383. if(_get_next_page(vf,og_ptr,CHUNKSIZE)<0){
  141384. ret=OV_EBADHEADER;
  141385. goto bail_header;
  141386. }
  141387. }
  141388. return 0;
  141389. bail_header:
  141390. vorbis_info_clear(vi);
  141391. vorbis_comment_clear(vc);
  141392. vf->ready_state=OPENED;
  141393. return ret;
  141394. }
  141395. static void _prefetch_all_headers(OggVorbis_File *vf, ogg_int64_t dataoffset){
  141396. ogg_page og;
  141397. int i;
  141398. ogg_int64_t ret;
  141399. vf->vi=(vorbis_info*) _ogg_realloc(vf->vi,vf->links*sizeof(*vf->vi));
  141400. vf->vc=(vorbis_comment*) _ogg_realloc(vf->vc,vf->links*sizeof(*vf->vc));
  141401. vf->dataoffsets=(ogg_int64_t*) _ogg_malloc(vf->links*sizeof(*vf->dataoffsets));
  141402. vf->pcmlengths=(ogg_int64_t*) _ogg_malloc(vf->links*2*sizeof(*vf->pcmlengths));
  141403. for(i=0;i<vf->links;i++){
  141404. if(i==0){
  141405. vf->dataoffsets[i]=dataoffset;
  141406. _seek_helper(vf,dataoffset);
  141407. }else{
  141408. _seek_helper(vf,vf->offsets[i]);
  141409. if(_fetch_headers(vf,vf->vi+i,vf->vc+i,NULL,NULL)<0){
  141410. vf->dataoffsets[i]=-1;
  141411. }else{
  141412. vf->dataoffsets[i]=vf->offset;
  141413. }
  141414. }
  141415. if(vf->dataoffsets[i]!=-1){
  141416. ogg_int64_t accumulated=0;
  141417. long lastblock=-1;
  141418. int result;
  141419. ogg_stream_reset_serialno(&vf->os,vf->serialnos[i]);
  141420. while(1){
  141421. ogg_packet op;
  141422. ret=_get_next_page(vf,&og,-1);
  141423. if(ret<0)
  141424. break;
  141425. if(ogg_page_serialno(&og)!=vf->serialnos[i])
  141426. break;
  141427. ogg_stream_pagein(&vf->os,&og);
  141428. while((result=ogg_stream_packetout(&vf->os,&op))){
  141429. if(result>0){ /* ignore holes */
  141430. long thisblock=vorbis_packet_blocksize(vf->vi+i,&op);
  141431. if(lastblock!=-1)
  141432. accumulated+=(lastblock+thisblock)>>2;
  141433. lastblock=thisblock;
  141434. }
  141435. }
  141436. if(ogg_page_granulepos(&og)!=-1){
  141437. accumulated= ogg_page_granulepos(&og)-accumulated;
  141438. break;
  141439. }
  141440. }
  141441. if(accumulated<0)accumulated=0;
  141442. vf->pcmlengths[i*2]=accumulated;
  141443. }
  141444. {
  141445. ogg_int64_t end=vf->offsets[i+1];
  141446. _seek_helper(vf,end);
  141447. while(1){
  141448. ret=_get_prev_page(vf,&og);
  141449. if(ret<0){
  141450. vorbis_info_clear(vf->vi+i);
  141451. vorbis_comment_clear(vf->vc+i);
  141452. break;
  141453. }
  141454. if(ogg_page_granulepos(&og)!=-1){
  141455. vf->pcmlengths[i*2+1]=ogg_page_granulepos(&og)-vf->pcmlengths[i*2];
  141456. break;
  141457. }
  141458. vf->offset=ret;
  141459. }
  141460. }
  141461. }
  141462. }
  141463. static int _make_decode_ready(OggVorbis_File *vf){
  141464. if(vf->ready_state>STREAMSET)return 0;
  141465. if(vf->ready_state<STREAMSET)return OV_EFAULT;
  141466. if(vf->seekable){
  141467. if(vorbis_synthesis_init(&vf->vd,vf->vi+vf->current_link))
  141468. return OV_EBADLINK;
  141469. }else{
  141470. if(vorbis_synthesis_init(&vf->vd,vf->vi))
  141471. return OV_EBADLINK;
  141472. }
  141473. vorbis_block_init(&vf->vd,&vf->vb);
  141474. vf->ready_state=INITSET;
  141475. vf->bittrack=0.f;
  141476. vf->samptrack=0.f;
  141477. return 0;
  141478. }
  141479. static int _open_seekable2(OggVorbis_File *vf){
  141480. long serialno=vf->current_serialno;
  141481. ogg_int64_t dataoffset=vf->offset, end;
  141482. ogg_page og;
  141483. (vf->callbacks.seek_func)(vf->datasource,0,SEEK_END);
  141484. vf->offset=vf->end=(vf->callbacks.tell_func)(vf->datasource);
  141485. end=_get_prev_page(vf,&og);
  141486. if(end<0)return(end);
  141487. if(ogg_page_serialno(&og)!=serialno){
  141488. if(_bisect_forward_serialno(vf,0,0,end+1,serialno,0)<0)return(OV_EREAD);
  141489. }else{
  141490. if(_bisect_forward_serialno(vf,0,end,end+1,serialno,0))return(OV_EREAD);
  141491. }
  141492. _prefetch_all_headers(vf,dataoffset);
  141493. return(ov_raw_seek(vf,0));
  141494. }
  141495. static void _decode_clear(OggVorbis_File *vf){
  141496. vorbis_dsp_clear(&vf->vd);
  141497. vorbis_block_clear(&vf->vb);
  141498. vf->ready_state=OPENED;
  141499. }
  141500. static int _fetch_and_process_packet(OggVorbis_File *vf,
  141501. ogg_packet *op_in,
  141502. int readp,
  141503. int spanp){
  141504. ogg_page og;
  141505. while(1){
  141506. if(vf->ready_state==INITSET){
  141507. while(1) {
  141508. ogg_packet op;
  141509. ogg_packet *op_ptr=(op_in?op_in:&op);
  141510. int result=ogg_stream_packetout(&vf->os,op_ptr);
  141511. ogg_int64_t granulepos;
  141512. op_in=NULL;
  141513. if(result==-1)return(OV_HOLE); /* hole in the data. */
  141514. if(result>0){
  141515. granulepos=op_ptr->granulepos;
  141516. if(!vorbis_synthesis(&vf->vb,op_ptr)){ /* lazy check for lazy
  141517. header handling. The
  141518. header packets aren't
  141519. audio, so if/when we
  141520. submit them,
  141521. vorbis_synthesis will
  141522. reject them */
  141523. {
  141524. int oldsamples=vorbis_synthesis_pcmout(&vf->vd,NULL);
  141525. if(oldsamples)return(OV_EFAULT);
  141526. vorbis_synthesis_blockin(&vf->vd,&vf->vb);
  141527. vf->samptrack+=vorbis_synthesis_pcmout(&vf->vd,NULL)-oldsamples;
  141528. vf->bittrack+=op_ptr->bytes*8;
  141529. }
  141530. if(granulepos!=-1 && !op_ptr->e_o_s){
  141531. int link=(vf->seekable?vf->current_link:0);
  141532. int i,samples;
  141533. if(vf->seekable && link>0)
  141534. granulepos-=vf->pcmlengths[link*2];
  141535. if(granulepos<0)granulepos=0; /* actually, this
  141536. shouldn't be possible
  141537. here unless the stream
  141538. is very broken */
  141539. samples=vorbis_synthesis_pcmout(&vf->vd,NULL);
  141540. granulepos-=samples;
  141541. for(i=0;i<link;i++)
  141542. granulepos+=vf->pcmlengths[i*2+1];
  141543. vf->pcm_offset=granulepos;
  141544. }
  141545. return(1);
  141546. }
  141547. }
  141548. else
  141549. break;
  141550. }
  141551. }
  141552. if(vf->ready_state>=OPENED){
  141553. ogg_int64_t ret;
  141554. if(!readp)return(0);
  141555. if((ret=_get_next_page(vf,&og,-1))<0){
  141556. return(OV_EOF); /* eof.
  141557. leave unitialized */
  141558. }
  141559. vf->bittrack+=og.header_len*8;
  141560. if(vf->ready_state==INITSET){
  141561. if(vf->current_serialno!=ogg_page_serialno(&og)){
  141562. if(!spanp)
  141563. return(OV_EOF);
  141564. _decode_clear(vf);
  141565. if(!vf->seekable){
  141566. vorbis_info_clear(vf->vi);
  141567. vorbis_comment_clear(vf->vc);
  141568. }
  141569. }
  141570. }
  141571. }
  141572. if(vf->ready_state!=INITSET){
  141573. int link;
  141574. if(vf->ready_state<STREAMSET){
  141575. if(vf->seekable){
  141576. vf->current_serialno=ogg_page_serialno(&og);
  141577. for(link=0;link<vf->links;link++)
  141578. if(vf->serialnos[link]==vf->current_serialno)break;
  141579. if(link==vf->links)return(OV_EBADLINK); /* sign of a bogus
  141580. stream. error out,
  141581. leave machine
  141582. uninitialized */
  141583. vf->current_link=link;
  141584. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141585. vf->ready_state=STREAMSET;
  141586. }else{
  141587. int ret=_fetch_headers(vf,vf->vi,vf->vc,&vf->current_serialno,&og);
  141588. if(ret)return(ret);
  141589. vf->current_link++;
  141590. link=0;
  141591. }
  141592. }
  141593. {
  141594. int ret=_make_decode_ready(vf);
  141595. if(ret<0)return ret;
  141596. }
  141597. }
  141598. ogg_stream_pagein(&vf->os,&og);
  141599. }
  141600. }
  141601. static int _fseek64_wrap(FILE *f,ogg_int64_t off,int whence){
  141602. if(f==NULL)return(-1);
  141603. return fseek(f,off,whence);
  141604. }
  141605. static int _ov_open1(void *f,OggVorbis_File *vf,char *initial,
  141606. long ibytes, ov_callbacks callbacks){
  141607. int offsettest=(f?callbacks.seek_func(f,0,SEEK_CUR):-1);
  141608. int ret;
  141609. memset(vf,0,sizeof(*vf));
  141610. vf->datasource=f;
  141611. vf->callbacks = callbacks;
  141612. ogg_sync_init(&vf->oy);
  141613. if(initial){
  141614. char *buffer=ogg_sync_buffer(&vf->oy,ibytes);
  141615. memcpy(buffer,initial,ibytes);
  141616. ogg_sync_wrote(&vf->oy,ibytes);
  141617. }
  141618. if(offsettest!=-1)vf->seekable=1;
  141619. vf->links=1;
  141620. vf->vi=(vorbis_info*) _ogg_calloc(vf->links,sizeof(*vf->vi));
  141621. vf->vc=(vorbis_comment*) _ogg_calloc(vf->links,sizeof(*vf->vc));
  141622. ogg_stream_init(&vf->os,-1); /* fill in the serialno later */
  141623. if((ret=_fetch_headers(vf,vf->vi,vf->vc,&vf->current_serialno,NULL))<0){
  141624. vf->datasource=NULL;
  141625. ov_clear(vf);
  141626. }else
  141627. vf->ready_state=PARTOPEN;
  141628. return(ret);
  141629. }
  141630. static int _ov_open2(OggVorbis_File *vf){
  141631. if(vf->ready_state != PARTOPEN) return OV_EINVAL;
  141632. vf->ready_state=OPENED;
  141633. if(vf->seekable){
  141634. int ret=_open_seekable2(vf);
  141635. if(ret){
  141636. vf->datasource=NULL;
  141637. ov_clear(vf);
  141638. }
  141639. return(ret);
  141640. }else
  141641. vf->ready_state=STREAMSET;
  141642. return 0;
  141643. }
  141644. int ov_clear(OggVorbis_File *vf){
  141645. if(vf){
  141646. vorbis_block_clear(&vf->vb);
  141647. vorbis_dsp_clear(&vf->vd);
  141648. ogg_stream_clear(&vf->os);
  141649. if(vf->vi && vf->links){
  141650. int i;
  141651. for(i=0;i<vf->links;i++){
  141652. vorbis_info_clear(vf->vi+i);
  141653. vorbis_comment_clear(vf->vc+i);
  141654. }
  141655. _ogg_free(vf->vi);
  141656. _ogg_free(vf->vc);
  141657. }
  141658. if(vf->dataoffsets)_ogg_free(vf->dataoffsets);
  141659. if(vf->pcmlengths)_ogg_free(vf->pcmlengths);
  141660. if(vf->serialnos)_ogg_free(vf->serialnos);
  141661. if(vf->offsets)_ogg_free(vf->offsets);
  141662. ogg_sync_clear(&vf->oy);
  141663. if(vf->datasource)(vf->callbacks.close_func)(vf->datasource);
  141664. memset(vf,0,sizeof(*vf));
  141665. }
  141666. #ifdef DEBUG_LEAKS
  141667. _VDBG_dump();
  141668. #endif
  141669. return(0);
  141670. }
  141671. int ov_open_callbacks(void *f,OggVorbis_File *vf,char *initial,long ibytes,
  141672. ov_callbacks callbacks){
  141673. int ret=_ov_open1(f,vf,initial,ibytes,callbacks);
  141674. if(ret)return ret;
  141675. return _ov_open2(vf);
  141676. }
  141677. int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes){
  141678. ov_callbacks callbacks = {
  141679. (size_t (*)(void *, size_t, size_t, void *)) fread,
  141680. (int (*)(void *, ogg_int64_t, int)) _fseek64_wrap,
  141681. (int (*)(void *)) fclose,
  141682. (long (*)(void *)) ftell
  141683. };
  141684. return ov_open_callbacks((void *)f, vf, initial, ibytes, callbacks);
  141685. }
  141686. int ov_halfrate(OggVorbis_File *vf,int flag){
  141687. int i;
  141688. if(vf->vi==NULL)return OV_EINVAL;
  141689. if(!vf->seekable)return OV_EINVAL;
  141690. if(vf->ready_state>=STREAMSET)
  141691. _decode_clear(vf); /* clear out stream state; later on libvorbis
  141692. will be able to swap this on the fly, but
  141693. for now dumping the decode machine is needed
  141694. to reinit the MDCT lookups. 1.1 libvorbis
  141695. is planned to be able to switch on the fly */
  141696. for(i=0;i<vf->links;i++){
  141697. if(vorbis_synthesis_halfrate(vf->vi+i,flag)){
  141698. ov_halfrate(vf,0);
  141699. return OV_EINVAL;
  141700. }
  141701. }
  141702. return 0;
  141703. }
  141704. int ov_halfrate_p(OggVorbis_File *vf){
  141705. if(vf->vi==NULL)return OV_EINVAL;
  141706. return vorbis_synthesis_halfrate_p(vf->vi);
  141707. }
  141708. int ov_test_callbacks(void *f,OggVorbis_File *vf,char *initial,long ibytes,
  141709. ov_callbacks callbacks)
  141710. {
  141711. return _ov_open1(f,vf,initial,ibytes,callbacks);
  141712. }
  141713. int ov_test(FILE *f,OggVorbis_File *vf,char *initial,long ibytes){
  141714. ov_callbacks callbacks = {
  141715. (size_t (*)(void *, size_t, size_t, void *)) fread,
  141716. (int (*)(void *, ogg_int64_t, int)) _fseek64_wrap,
  141717. (int (*)(void *)) fclose,
  141718. (long (*)(void *)) ftell
  141719. };
  141720. return ov_test_callbacks((void *)f, vf, initial, ibytes, callbacks);
  141721. }
  141722. int ov_test_open(OggVorbis_File *vf){
  141723. if(vf->ready_state!=PARTOPEN)return(OV_EINVAL);
  141724. return _ov_open2(vf);
  141725. }
  141726. long ov_streams(OggVorbis_File *vf){
  141727. return vf->links;
  141728. }
  141729. long ov_seekable(OggVorbis_File *vf){
  141730. return vf->seekable;
  141731. }
  141732. long ov_bitrate(OggVorbis_File *vf,int i){
  141733. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141734. if(i>=vf->links)return(OV_EINVAL);
  141735. if(!vf->seekable && i!=0)return(ov_bitrate(vf,0));
  141736. if(i<0){
  141737. ogg_int64_t bits=0;
  141738. int i;
  141739. float br;
  141740. for(i=0;i<vf->links;i++)
  141741. bits+=(vf->offsets[i+1]-vf->dataoffsets[i])*8;
  141742. br = bits/ov_time_total(vf,-1);
  141743. return(rint(br));
  141744. }else{
  141745. if(vf->seekable){
  141746. return(rint((vf->offsets[i+1]-vf->dataoffsets[i])*8/ov_time_total(vf,i)));
  141747. }else{
  141748. if(vf->vi[i].bitrate_nominal>0){
  141749. return vf->vi[i].bitrate_nominal;
  141750. }else{
  141751. if(vf->vi[i].bitrate_upper>0){
  141752. if(vf->vi[i].bitrate_lower>0){
  141753. return (vf->vi[i].bitrate_upper+vf->vi[i].bitrate_lower)/2;
  141754. }else{
  141755. return vf->vi[i].bitrate_upper;
  141756. }
  141757. }
  141758. return(OV_FALSE);
  141759. }
  141760. }
  141761. }
  141762. }
  141763. long ov_bitrate_instant(OggVorbis_File *vf){
  141764. int link=(vf->seekable?vf->current_link:0);
  141765. long ret;
  141766. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141767. if(vf->samptrack==0)return(OV_FALSE);
  141768. ret=vf->bittrack/vf->samptrack*vf->vi[link].rate+.5;
  141769. vf->bittrack=0.f;
  141770. vf->samptrack=0.f;
  141771. return(ret);
  141772. }
  141773. long ov_serialnumber(OggVorbis_File *vf,int i){
  141774. if(i>=vf->links)return(ov_serialnumber(vf,vf->links-1));
  141775. if(!vf->seekable && i>=0)return(ov_serialnumber(vf,-1));
  141776. if(i<0){
  141777. return(vf->current_serialno);
  141778. }else{
  141779. return(vf->serialnos[i]);
  141780. }
  141781. }
  141782. ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i){
  141783. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141784. if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  141785. if(i<0){
  141786. ogg_int64_t acc=0;
  141787. int i;
  141788. for(i=0;i<vf->links;i++)
  141789. acc+=ov_raw_total(vf,i);
  141790. return(acc);
  141791. }else{
  141792. return(vf->offsets[i+1]-vf->offsets[i]);
  141793. }
  141794. }
  141795. ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i){
  141796. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141797. if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  141798. if(i<0){
  141799. ogg_int64_t acc=0;
  141800. int i;
  141801. for(i=0;i<vf->links;i++)
  141802. acc+=ov_pcm_total(vf,i);
  141803. return(acc);
  141804. }else{
  141805. return(vf->pcmlengths[i*2+1]);
  141806. }
  141807. }
  141808. double ov_time_total(OggVorbis_File *vf,int i){
  141809. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141810. if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  141811. if(i<0){
  141812. double acc=0;
  141813. int i;
  141814. for(i=0;i<vf->links;i++)
  141815. acc+=ov_time_total(vf,i);
  141816. return(acc);
  141817. }else{
  141818. return((double)(vf->pcmlengths[i*2+1])/vf->vi[i].rate);
  141819. }
  141820. }
  141821. int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos){
  141822. ogg_stream_state work_os;
  141823. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141824. if(!vf->seekable)
  141825. return(OV_ENOSEEK); /* don't dump machine if we can't seek */
  141826. if(pos<0 || pos>vf->end)return(OV_EINVAL);
  141827. vf->pcm_offset=-1;
  141828. ogg_stream_reset_serialno(&vf->os,
  141829. vf->current_serialno); /* must set serialno */
  141830. vorbis_synthesis_restart(&vf->vd);
  141831. _seek_helper(vf,pos);
  141832. {
  141833. ogg_page og;
  141834. ogg_packet op;
  141835. int lastblock=0;
  141836. int accblock=0;
  141837. int thisblock;
  141838. int eosflag;
  141839. ogg_stream_init(&work_os,vf->current_serialno); /* get the memory ready */
  141840. ogg_stream_reset(&work_os); /* eliminate the spurious OV_HOLE
  141841. return from not necessarily
  141842. starting from the beginning */
  141843. while(1){
  141844. if(vf->ready_state>=STREAMSET){
  141845. int result=ogg_stream_packetout(&work_os,&op);
  141846. if(result>0){
  141847. if(vf->vi[vf->current_link].codec_setup){
  141848. thisblock=vorbis_packet_blocksize(vf->vi+vf->current_link,&op);
  141849. if(thisblock<0){
  141850. ogg_stream_packetout(&vf->os,NULL);
  141851. thisblock=0;
  141852. }else{
  141853. if(eosflag)
  141854. ogg_stream_packetout(&vf->os,NULL);
  141855. else
  141856. if(lastblock)accblock+=(lastblock+thisblock)>>2;
  141857. }
  141858. if(op.granulepos!=-1){
  141859. int i,link=vf->current_link;
  141860. ogg_int64_t granulepos=op.granulepos-vf->pcmlengths[link*2];
  141861. if(granulepos<0)granulepos=0;
  141862. for(i=0;i<link;i++)
  141863. granulepos+=vf->pcmlengths[i*2+1];
  141864. vf->pcm_offset=granulepos-accblock;
  141865. break;
  141866. }
  141867. lastblock=thisblock;
  141868. continue;
  141869. }else
  141870. ogg_stream_packetout(&vf->os,NULL);
  141871. }
  141872. }
  141873. if(!lastblock){
  141874. if(_get_next_page(vf,&og,-1)<0){
  141875. vf->pcm_offset=ov_pcm_total(vf,-1);
  141876. break;
  141877. }
  141878. }else{
  141879. vf->pcm_offset=-1;
  141880. break;
  141881. }
  141882. if(vf->ready_state>=STREAMSET)
  141883. if(vf->current_serialno!=ogg_page_serialno(&og)){
  141884. _decode_clear(vf); /* clear out stream state */
  141885. ogg_stream_clear(&work_os);
  141886. }
  141887. if(vf->ready_state<STREAMSET){
  141888. int link;
  141889. vf->current_serialno=ogg_page_serialno(&og);
  141890. for(link=0;link<vf->links;link++)
  141891. if(vf->serialnos[link]==vf->current_serialno)break;
  141892. if(link==vf->links)goto seek_error; /* sign of a bogus stream.
  141893. error out, leave
  141894. machine uninitialized */
  141895. vf->current_link=link;
  141896. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141897. ogg_stream_reset_serialno(&work_os,vf->current_serialno);
  141898. vf->ready_state=STREAMSET;
  141899. }
  141900. ogg_stream_pagein(&vf->os,&og);
  141901. ogg_stream_pagein(&work_os,&og);
  141902. eosflag=ogg_page_eos(&og);
  141903. }
  141904. }
  141905. ogg_stream_clear(&work_os);
  141906. vf->bittrack=0.f;
  141907. vf->samptrack=0.f;
  141908. return(0);
  141909. seek_error:
  141910. vf->pcm_offset=-1;
  141911. ogg_stream_clear(&work_os);
  141912. _decode_clear(vf);
  141913. return OV_EBADLINK;
  141914. }
  141915. int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos){
  141916. int link=-1;
  141917. ogg_int64_t result=0;
  141918. ogg_int64_t total=ov_pcm_total(vf,-1);
  141919. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141920. if(!vf->seekable)return(OV_ENOSEEK);
  141921. if(pos<0 || pos>total)return(OV_EINVAL);
  141922. for(link=vf->links-1;link>=0;link--){
  141923. total-=vf->pcmlengths[link*2+1];
  141924. if(pos>=total)break;
  141925. }
  141926. {
  141927. ogg_int64_t end=vf->offsets[link+1];
  141928. ogg_int64_t begin=vf->offsets[link];
  141929. ogg_int64_t begintime = vf->pcmlengths[link*2];
  141930. ogg_int64_t endtime = vf->pcmlengths[link*2+1]+begintime;
  141931. ogg_int64_t target=pos-total+begintime;
  141932. ogg_int64_t best=begin;
  141933. ogg_page og;
  141934. while(begin<end){
  141935. ogg_int64_t bisect;
  141936. if(end-begin<CHUNKSIZE){
  141937. bisect=begin;
  141938. }else{
  141939. bisect=begin +
  141940. (target-begintime)*(end-begin)/(endtime-begintime) - CHUNKSIZE;
  141941. if(bisect<=begin)
  141942. bisect=begin+1;
  141943. }
  141944. _seek_helper(vf,bisect);
  141945. while(begin<end){
  141946. result=_get_next_page(vf,&og,end-vf->offset);
  141947. if(result==OV_EREAD) goto seek_error;
  141948. if(result<0){
  141949. if(bisect<=begin+1)
  141950. end=begin; /* found it */
  141951. else{
  141952. if(bisect==0) goto seek_error;
  141953. bisect-=CHUNKSIZE;
  141954. if(bisect<=begin)bisect=begin+1;
  141955. _seek_helper(vf,bisect);
  141956. }
  141957. }else{
  141958. ogg_int64_t granulepos=ogg_page_granulepos(&og);
  141959. if(granulepos==-1)continue;
  141960. if(granulepos<target){
  141961. best=result; /* raw offset of packet with granulepos */
  141962. begin=vf->offset; /* raw offset of next page */
  141963. begintime=granulepos;
  141964. if(target-begintime>44100)break;
  141965. bisect=begin; /* *not* begin + 1 */
  141966. }else{
  141967. if(bisect<=begin+1)
  141968. end=begin; /* found it */
  141969. else{
  141970. if(end==vf->offset){ /* we're pretty close - we'd be stuck in */
  141971. end=result;
  141972. bisect-=CHUNKSIZE; /* an endless loop otherwise. */
  141973. if(bisect<=begin)bisect=begin+1;
  141974. _seek_helper(vf,bisect);
  141975. }else{
  141976. end=result;
  141977. endtime=granulepos;
  141978. break;
  141979. }
  141980. }
  141981. }
  141982. }
  141983. }
  141984. }
  141985. {
  141986. ogg_page og;
  141987. ogg_packet op;
  141988. _seek_helper(vf,best);
  141989. vf->pcm_offset=-1;
  141990. if(_get_next_page(vf,&og,-1)<0)return(OV_EOF); /* shouldn't happen */
  141991. if(link!=vf->current_link){
  141992. _decode_clear(vf);
  141993. vf->current_link=link;
  141994. vf->current_serialno=ogg_page_serialno(&og);
  141995. vf->ready_state=STREAMSET;
  141996. }else{
  141997. vorbis_synthesis_restart(&vf->vd);
  141998. }
  141999. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  142000. ogg_stream_pagein(&vf->os,&og);
  142001. while(1){
  142002. result=ogg_stream_packetpeek(&vf->os,&op);
  142003. if(result==0){
  142004. _seek_helper(vf,best);
  142005. while(1){
  142006. result=_get_prev_page(vf,&og);
  142007. if(result<0) goto seek_error;
  142008. if(ogg_page_granulepos(&og)>-1 ||
  142009. !ogg_page_continued(&og)){
  142010. return ov_raw_seek(vf,result);
  142011. }
  142012. vf->offset=result;
  142013. }
  142014. }
  142015. if(result<0){
  142016. result = OV_EBADPACKET;
  142017. goto seek_error;
  142018. }
  142019. if(op.granulepos!=-1){
  142020. vf->pcm_offset=op.granulepos-vf->pcmlengths[vf->current_link*2];
  142021. if(vf->pcm_offset<0)vf->pcm_offset=0;
  142022. vf->pcm_offset+=total;
  142023. break;
  142024. }else
  142025. result=ogg_stream_packetout(&vf->os,NULL);
  142026. }
  142027. }
  142028. }
  142029. if(vf->pcm_offset>pos || pos>ov_pcm_total(vf,-1)){
  142030. result=OV_EFAULT;
  142031. goto seek_error;
  142032. }
  142033. vf->bittrack=0.f;
  142034. vf->samptrack=0.f;
  142035. return(0);
  142036. seek_error:
  142037. vf->pcm_offset=-1;
  142038. _decode_clear(vf);
  142039. return (int)result;
  142040. }
  142041. int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos){
  142042. int thisblock,lastblock=0;
  142043. int ret=ov_pcm_seek_page(vf,pos);
  142044. if(ret<0)return(ret);
  142045. if((ret=_make_decode_ready(vf)))return ret;
  142046. while(1){
  142047. ogg_packet op;
  142048. ogg_page og;
  142049. int ret=ogg_stream_packetpeek(&vf->os,&op);
  142050. if(ret>0){
  142051. thisblock=vorbis_packet_blocksize(vf->vi+vf->current_link,&op);
  142052. if(thisblock<0){
  142053. ogg_stream_packetout(&vf->os,NULL);
  142054. continue; /* non audio packet */
  142055. }
  142056. if(lastblock)vf->pcm_offset+=(lastblock+thisblock)>>2;
  142057. if(vf->pcm_offset+((thisblock+
  142058. vorbis_info_blocksize(vf->vi,1))>>2)>=pos)break;
  142059. ogg_stream_packetout(&vf->os,NULL);
  142060. vorbis_synthesis_trackonly(&vf->vb,&op); /* set up a vb with
  142061. only tracking, no
  142062. pcm_decode */
  142063. vorbis_synthesis_blockin(&vf->vd,&vf->vb);
  142064. if(op.granulepos>-1){
  142065. int i;
  142066. vf->pcm_offset=op.granulepos-vf->pcmlengths[vf->current_link*2];
  142067. if(vf->pcm_offset<0)vf->pcm_offset=0;
  142068. for(i=0;i<vf->current_link;i++)
  142069. vf->pcm_offset+=vf->pcmlengths[i*2+1];
  142070. }
  142071. lastblock=thisblock;
  142072. }else{
  142073. if(ret<0 && ret!=OV_HOLE)break;
  142074. if(_get_next_page(vf,&og,-1)<0)break;
  142075. if(vf->current_serialno!=ogg_page_serialno(&og))_decode_clear(vf);
  142076. if(vf->ready_state<STREAMSET){
  142077. int link;
  142078. vf->current_serialno=ogg_page_serialno(&og);
  142079. for(link=0;link<vf->links;link++)
  142080. if(vf->serialnos[link]==vf->current_serialno)break;
  142081. if(link==vf->links)return(OV_EBADLINK);
  142082. vf->current_link=link;
  142083. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  142084. vf->ready_state=STREAMSET;
  142085. ret=_make_decode_ready(vf);
  142086. if(ret)return ret;
  142087. lastblock=0;
  142088. }
  142089. ogg_stream_pagein(&vf->os,&og);
  142090. }
  142091. }
  142092. vf->bittrack=0.f;
  142093. vf->samptrack=0.f;
  142094. while(vf->pcm_offset<pos){
  142095. ogg_int64_t target=pos-vf->pcm_offset;
  142096. long samples=vorbis_synthesis_pcmout(&vf->vd,NULL);
  142097. if(samples>target)samples=target;
  142098. vorbis_synthesis_read(&vf->vd,samples);
  142099. vf->pcm_offset+=samples;
  142100. if(samples<target)
  142101. if(_fetch_and_process_packet(vf,NULL,1,1)<=0)
  142102. vf->pcm_offset=ov_pcm_total(vf,-1); /* eof */
  142103. }
  142104. return 0;
  142105. }
  142106. int ov_time_seek(OggVorbis_File *vf,double seconds){
  142107. int link=-1;
  142108. ogg_int64_t pcm_total=ov_pcm_total(vf,-1);
  142109. double time_total=ov_time_total(vf,-1);
  142110. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142111. if(!vf->seekable)return(OV_ENOSEEK);
  142112. if(seconds<0 || seconds>time_total)return(OV_EINVAL);
  142113. for(link=vf->links-1;link>=0;link--){
  142114. pcm_total-=vf->pcmlengths[link*2+1];
  142115. time_total-=ov_time_total(vf,link);
  142116. if(seconds>=time_total)break;
  142117. }
  142118. {
  142119. ogg_int64_t target=pcm_total+(seconds-time_total)*vf->vi[link].rate;
  142120. return(ov_pcm_seek(vf,target));
  142121. }
  142122. }
  142123. int ov_time_seek_page(OggVorbis_File *vf,double seconds){
  142124. int link=-1;
  142125. ogg_int64_t pcm_total=ov_pcm_total(vf,-1);
  142126. double time_total=ov_time_total(vf,-1);
  142127. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142128. if(!vf->seekable)return(OV_ENOSEEK);
  142129. if(seconds<0 || seconds>time_total)return(OV_EINVAL);
  142130. for(link=vf->links-1;link>=0;link--){
  142131. pcm_total-=vf->pcmlengths[link*2+1];
  142132. time_total-=ov_time_total(vf,link);
  142133. if(seconds>=time_total)break;
  142134. }
  142135. {
  142136. ogg_int64_t target=pcm_total+(seconds-time_total)*vf->vi[link].rate;
  142137. return(ov_pcm_seek_page(vf,target));
  142138. }
  142139. }
  142140. ogg_int64_t ov_raw_tell(OggVorbis_File *vf){
  142141. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142142. return(vf->offset);
  142143. }
  142144. ogg_int64_t ov_pcm_tell(OggVorbis_File *vf){
  142145. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142146. return(vf->pcm_offset);
  142147. }
  142148. double ov_time_tell(OggVorbis_File *vf){
  142149. int link=0;
  142150. ogg_int64_t pcm_total=0;
  142151. double time_total=0.f;
  142152. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142153. if(vf->seekable){
  142154. pcm_total=ov_pcm_total(vf,-1);
  142155. time_total=ov_time_total(vf,-1);
  142156. for(link=vf->links-1;link>=0;link--){
  142157. pcm_total-=vf->pcmlengths[link*2+1];
  142158. time_total-=ov_time_total(vf,link);
  142159. if(vf->pcm_offset>=pcm_total)break;
  142160. }
  142161. }
  142162. return((double)time_total+(double)(vf->pcm_offset-pcm_total)/vf->vi[link].rate);
  142163. }
  142164. vorbis_info *ov_info(OggVorbis_File *vf,int link){
  142165. if(vf->seekable){
  142166. if(link<0)
  142167. if(vf->ready_state>=STREAMSET)
  142168. return vf->vi+vf->current_link;
  142169. else
  142170. return vf->vi;
  142171. else
  142172. if(link>=vf->links)
  142173. return NULL;
  142174. else
  142175. return vf->vi+link;
  142176. }else{
  142177. return vf->vi;
  142178. }
  142179. }
  142180. vorbis_comment *ov_comment(OggVorbis_File *vf,int link){
  142181. if(vf->seekable){
  142182. if(link<0)
  142183. if(vf->ready_state>=STREAMSET)
  142184. return vf->vc+vf->current_link;
  142185. else
  142186. return vf->vc;
  142187. else
  142188. if(link>=vf->links)
  142189. return NULL;
  142190. else
  142191. return vf->vc+link;
  142192. }else{
  142193. return vf->vc;
  142194. }
  142195. }
  142196. static int host_is_big_endian() {
  142197. ogg_int32_t pattern = 0xfeedface; /* deadbeef */
  142198. unsigned char *bytewise = (unsigned char *)&pattern;
  142199. if (bytewise[0] == 0xfe) return 1;
  142200. return 0;
  142201. }
  142202. long ov_read(OggVorbis_File *vf,char *buffer,int length,
  142203. int bigendianp,int word,int sgned,int *bitstream){
  142204. int i,j;
  142205. int host_endian = host_is_big_endian();
  142206. float **pcm;
  142207. long samples;
  142208. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142209. while(1){
  142210. if(vf->ready_state==INITSET){
  142211. samples=vorbis_synthesis_pcmout(&vf->vd,&pcm);
  142212. if(samples)break;
  142213. }
  142214. {
  142215. int ret=_fetch_and_process_packet(vf,NULL,1,1);
  142216. if(ret==OV_EOF)
  142217. return(0);
  142218. if(ret<=0)
  142219. return(ret);
  142220. }
  142221. }
  142222. if(samples>0){
  142223. long channels=ov_info(vf,-1)->channels;
  142224. long bytespersample=word * channels;
  142225. vorbis_fpu_control fpu;
  142226. (void) fpu; // (to avoid a warning about it being unused)
  142227. if(samples>length/bytespersample)samples=length/bytespersample;
  142228. if(samples <= 0)
  142229. return OV_EINVAL;
  142230. {
  142231. int val;
  142232. if(word==1){
  142233. int off=(sgned?0:128);
  142234. vorbis_fpu_setround(&fpu);
  142235. for(j=0;j<samples;j++)
  142236. for(i=0;i<channels;i++){
  142237. val=vorbis_ftoi(pcm[i][j]*128.f);
  142238. if(val>127)val=127;
  142239. else if(val<-128)val=-128;
  142240. *buffer++=val+off;
  142241. }
  142242. vorbis_fpu_restore(fpu);
  142243. }else{
  142244. int off=(sgned?0:32768);
  142245. if(host_endian==bigendianp){
  142246. if(sgned){
  142247. vorbis_fpu_setround(&fpu);
  142248. for(i=0;i<channels;i++) { /* It's faster in this order */
  142249. float *src=pcm[i];
  142250. short *dest=((short *)buffer)+i;
  142251. for(j=0;j<samples;j++) {
  142252. val=vorbis_ftoi(src[j]*32768.f);
  142253. if(val>32767)val=32767;
  142254. else if(val<-32768)val=-32768;
  142255. *dest=val;
  142256. dest+=channels;
  142257. }
  142258. }
  142259. vorbis_fpu_restore(fpu);
  142260. }else{
  142261. vorbis_fpu_setround(&fpu);
  142262. for(i=0;i<channels;i++) {
  142263. float *src=pcm[i];
  142264. short *dest=((short *)buffer)+i;
  142265. for(j=0;j<samples;j++) {
  142266. val=vorbis_ftoi(src[j]*32768.f);
  142267. if(val>32767)val=32767;
  142268. else if(val<-32768)val=-32768;
  142269. *dest=val+off;
  142270. dest+=channels;
  142271. }
  142272. }
  142273. vorbis_fpu_restore(fpu);
  142274. }
  142275. }else if(bigendianp){
  142276. vorbis_fpu_setround(&fpu);
  142277. for(j=0;j<samples;j++)
  142278. for(i=0;i<channels;i++){
  142279. val=vorbis_ftoi(pcm[i][j]*32768.f);
  142280. if(val>32767)val=32767;
  142281. else if(val<-32768)val=-32768;
  142282. val+=off;
  142283. *buffer++=(val>>8);
  142284. *buffer++=(val&0xff);
  142285. }
  142286. vorbis_fpu_restore(fpu);
  142287. }else{
  142288. int val;
  142289. vorbis_fpu_setround(&fpu);
  142290. for(j=0;j<samples;j++)
  142291. for(i=0;i<channels;i++){
  142292. val=vorbis_ftoi(pcm[i][j]*32768.f);
  142293. if(val>32767)val=32767;
  142294. else if(val<-32768)val=-32768;
  142295. val+=off;
  142296. *buffer++=(val&0xff);
  142297. *buffer++=(val>>8);
  142298. }
  142299. vorbis_fpu_restore(fpu);
  142300. }
  142301. }
  142302. }
  142303. vorbis_synthesis_read(&vf->vd,samples);
  142304. vf->pcm_offset+=samples;
  142305. if(bitstream)*bitstream=vf->current_link;
  142306. return(samples*bytespersample);
  142307. }else{
  142308. return(samples);
  142309. }
  142310. }
  142311. long ov_read_float(OggVorbis_File *vf,float ***pcm_channels,int length,
  142312. int *bitstream){
  142313. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142314. while(1){
  142315. if(vf->ready_state==INITSET){
  142316. float **pcm;
  142317. long samples=vorbis_synthesis_pcmout(&vf->vd,&pcm);
  142318. if(samples){
  142319. if(pcm_channels)*pcm_channels=pcm;
  142320. if(samples>length)samples=length;
  142321. vorbis_synthesis_read(&vf->vd,samples);
  142322. vf->pcm_offset+=samples;
  142323. if(bitstream)*bitstream=vf->current_link;
  142324. return samples;
  142325. }
  142326. }
  142327. {
  142328. int ret=_fetch_and_process_packet(vf,NULL,1,1);
  142329. if(ret==OV_EOF)return(0);
  142330. if(ret<=0)return(ret);
  142331. }
  142332. }
  142333. }
  142334. extern float *vorbis_window(vorbis_dsp_state *v,int W);
  142335. extern void _analysis_output_always(const char *base,int i,float *v,int n,int bark,int dB,
  142336. ogg_int64_t off);
  142337. static void _ov_splice(float **pcm,float **lappcm,
  142338. int n1, int n2,
  142339. int ch1, int ch2,
  142340. float *w1, float *w2){
  142341. int i,j;
  142342. float *w=w1;
  142343. int n=n1;
  142344. if(n1>n2){
  142345. n=n2;
  142346. w=w2;
  142347. }
  142348. for(j=0;j<ch1 && j<ch2;j++){
  142349. float *s=lappcm[j];
  142350. float *d=pcm[j];
  142351. for(i=0;i<n;i++){
  142352. float wd=w[i]*w[i];
  142353. float ws=1.-wd;
  142354. d[i]=d[i]*wd + s[i]*ws;
  142355. }
  142356. }
  142357. for(;j<ch2;j++){
  142358. float *d=pcm[j];
  142359. for(i=0;i<n;i++){
  142360. float wd=w[i]*w[i];
  142361. d[i]=d[i]*wd;
  142362. }
  142363. }
  142364. }
  142365. static int _ov_initset(OggVorbis_File *vf){
  142366. while(1){
  142367. if(vf->ready_state==INITSET)break;
  142368. {
  142369. int ret=_fetch_and_process_packet(vf,NULL,1,0);
  142370. if(ret<0 && ret!=OV_HOLE)return(ret);
  142371. }
  142372. }
  142373. return 0;
  142374. }
  142375. static int _ov_initprime(OggVorbis_File *vf){
  142376. vorbis_dsp_state *vd=&vf->vd;
  142377. while(1){
  142378. if(vf->ready_state==INITSET)
  142379. if(vorbis_synthesis_pcmout(vd,NULL))break;
  142380. {
  142381. int ret=_fetch_and_process_packet(vf,NULL,1,0);
  142382. if(ret<0 && ret!=OV_HOLE)return(ret);
  142383. }
  142384. }
  142385. return 0;
  142386. }
  142387. static void _ov_getlap(OggVorbis_File *vf,vorbis_info *vi,vorbis_dsp_state *vd,
  142388. float **lappcm,int lapsize){
  142389. int lapcount=0,i;
  142390. float **pcm;
  142391. while(lapcount<lapsize){
  142392. int samples=vorbis_synthesis_pcmout(vd,&pcm);
  142393. if(samples){
  142394. if(samples>lapsize-lapcount)samples=lapsize-lapcount;
  142395. for(i=0;i<vi->channels;i++)
  142396. memcpy(lappcm[i]+lapcount,pcm[i],sizeof(**pcm)*samples);
  142397. lapcount+=samples;
  142398. vorbis_synthesis_read(vd,samples);
  142399. }else{
  142400. int ret=_fetch_and_process_packet(vf,NULL,1,0); /* do *not* span */
  142401. if(ret==OV_EOF)break;
  142402. }
  142403. }
  142404. if(lapcount<lapsize){
  142405. int samples=vorbis_synthesis_lapout(&vf->vd,&pcm);
  142406. if(samples==0){
  142407. for(i=0;i<vi->channels;i++)
  142408. memset(lappcm[i]+lapcount,0,sizeof(**pcm)*lapsize-lapcount);
  142409. lapcount=lapsize;
  142410. }else{
  142411. if(samples>lapsize-lapcount)samples=lapsize-lapcount;
  142412. for(i=0;i<vi->channels;i++)
  142413. memcpy(lappcm[i]+lapcount,pcm[i],sizeof(**pcm)*samples);
  142414. lapcount+=samples;
  142415. }
  142416. }
  142417. }
  142418. int ov_crosslap(OggVorbis_File *vf1, OggVorbis_File *vf2){
  142419. vorbis_info *vi1,*vi2;
  142420. float **lappcm;
  142421. float **pcm;
  142422. float *w1,*w2;
  142423. int n1,n2,i,ret,hs1,hs2;
  142424. if(vf1==vf2)return(0); /* degenerate case */
  142425. if(vf1->ready_state<OPENED)return(OV_EINVAL);
  142426. if(vf2->ready_state<OPENED)return(OV_EINVAL);
  142427. ret=_ov_initset(vf1);
  142428. if(ret)return(ret);
  142429. ret=_ov_initprime(vf2);
  142430. if(ret)return(ret);
  142431. vi1=ov_info(vf1,-1);
  142432. vi2=ov_info(vf2,-1);
  142433. hs1=ov_halfrate_p(vf1);
  142434. hs2=ov_halfrate_p(vf2);
  142435. lappcm=(float**) alloca(sizeof(*lappcm)*vi1->channels);
  142436. n1=vorbis_info_blocksize(vi1,0)>>(1+hs1);
  142437. n2=vorbis_info_blocksize(vi2,0)>>(1+hs2);
  142438. w1=vorbis_window(&vf1->vd,0);
  142439. w2=vorbis_window(&vf2->vd,0);
  142440. for(i=0;i<vi1->channels;i++)
  142441. lappcm[i]=(float*) alloca(sizeof(**lappcm)*n1);
  142442. _ov_getlap(vf1,vi1,&vf1->vd,lappcm,n1);
  142443. vorbis_synthesis_lapout(&vf2->vd,&pcm);
  142444. _analysis_output_always("pcmL",0,pcm[0],n1*2,0,0,0);
  142445. _analysis_output_always("pcmR",0,pcm[1],n1*2,0,0,0);
  142446. _ov_splice(pcm,lappcm,n1,n2,vi1->channels,vi2->channels,w1,w2);
  142447. return(0);
  142448. }
  142449. static int _ov_64_seek_lap(OggVorbis_File *vf,ogg_int64_t pos,
  142450. int (*localseek)(OggVorbis_File *,ogg_int64_t)){
  142451. vorbis_info *vi;
  142452. float **lappcm;
  142453. float **pcm;
  142454. float *w1,*w2;
  142455. int n1,n2,ch1,ch2,hs;
  142456. int i,ret;
  142457. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142458. ret=_ov_initset(vf);
  142459. if(ret)return(ret);
  142460. vi=ov_info(vf,-1);
  142461. hs=ov_halfrate_p(vf);
  142462. ch1=vi->channels;
  142463. n1=vorbis_info_blocksize(vi,0)>>(1+hs);
  142464. w1=vorbis_window(&vf->vd,0); /* window arrays from libvorbis are
  142465. persistent; even if the decode state
  142466. from this link gets dumped, this
  142467. window array continues to exist */
  142468. lappcm=(float**) alloca(sizeof(*lappcm)*ch1);
  142469. for(i=0;i<ch1;i++)
  142470. lappcm[i]=(float*) alloca(sizeof(**lappcm)*n1);
  142471. _ov_getlap(vf,vi,&vf->vd,lappcm,n1);
  142472. ret=localseek(vf,pos);
  142473. if(ret)return ret;
  142474. ret=_ov_initprime(vf);
  142475. if(ret)return(ret);
  142476. vi=ov_info(vf,-1);
  142477. ch2=vi->channels;
  142478. n2=vorbis_info_blocksize(vi,0)>>(1+hs);
  142479. w2=vorbis_window(&vf->vd,0);
  142480. vorbis_synthesis_lapout(&vf->vd,&pcm);
  142481. _ov_splice(pcm,lappcm,n1,n2,ch1,ch2,w1,w2);
  142482. return(0);
  142483. }
  142484. int ov_raw_seek_lap(OggVorbis_File *vf,ogg_int64_t pos){
  142485. return _ov_64_seek_lap(vf,pos,ov_raw_seek);
  142486. }
  142487. int ov_pcm_seek_lap(OggVorbis_File *vf,ogg_int64_t pos){
  142488. return _ov_64_seek_lap(vf,pos,ov_pcm_seek);
  142489. }
  142490. int ov_pcm_seek_page_lap(OggVorbis_File *vf,ogg_int64_t pos){
  142491. return _ov_64_seek_lap(vf,pos,ov_pcm_seek_page);
  142492. }
  142493. static int _ov_d_seek_lap(OggVorbis_File *vf,double pos,
  142494. int (*localseek)(OggVorbis_File *,double)){
  142495. vorbis_info *vi;
  142496. float **lappcm;
  142497. float **pcm;
  142498. float *w1,*w2;
  142499. int n1,n2,ch1,ch2,hs;
  142500. int i,ret;
  142501. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142502. ret=_ov_initset(vf);
  142503. if(ret)return(ret);
  142504. vi=ov_info(vf,-1);
  142505. hs=ov_halfrate_p(vf);
  142506. ch1=vi->channels;
  142507. n1=vorbis_info_blocksize(vi,0)>>(1+hs);
  142508. w1=vorbis_window(&vf->vd,0); /* window arrays from libvorbis are
  142509. persistent; even if the decode state
  142510. from this link gets dumped, this
  142511. window array continues to exist */
  142512. lappcm=(float**) alloca(sizeof(*lappcm)*ch1);
  142513. for(i=0;i<ch1;i++)
  142514. lappcm[i]=(float*) alloca(sizeof(**lappcm)*n1);
  142515. _ov_getlap(vf,vi,&vf->vd,lappcm,n1);
  142516. ret=localseek(vf,pos);
  142517. if(ret)return ret;
  142518. ret=_ov_initprime(vf);
  142519. if(ret)return(ret);
  142520. vi=ov_info(vf,-1);
  142521. ch2=vi->channels;
  142522. n2=vorbis_info_blocksize(vi,0)>>(1+hs);
  142523. w2=vorbis_window(&vf->vd,0);
  142524. vorbis_synthesis_lapout(&vf->vd,&pcm);
  142525. _ov_splice(pcm,lappcm,n1,n2,ch1,ch2,w1,w2);
  142526. return(0);
  142527. }
  142528. int ov_time_seek_lap(OggVorbis_File *vf,double pos){
  142529. return _ov_d_seek_lap(vf,pos,ov_time_seek);
  142530. }
  142531. int ov_time_seek_page_lap(OggVorbis_File *vf,double pos){
  142532. return _ov_d_seek_lap(vf,pos,ov_time_seek_page);
  142533. }
  142534. #endif
  142535. /*** End of inlined file: vorbisfile.c ***/
  142536. /*** Start of inlined file: window.c ***/
  142537. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  142538. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  142539. // tasks..
  142540. #if JUCE_MSVC
  142541. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  142542. #endif
  142543. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  142544. #if JUCE_USE_OGGVORBIS
  142545. #include <stdlib.h>
  142546. #include <math.h>
  142547. static float vwin64[32] = {
  142548. 0.0009460463F, 0.0085006468F, 0.0235352254F, 0.0458950567F,
  142549. 0.0753351908F, 0.1115073077F, 0.1539457973F, 0.2020557475F,
  142550. 0.2551056759F, 0.3122276645F, 0.3724270287F, 0.4346027792F,
  142551. 0.4975789974F, 0.5601459521F, 0.6211085051F, 0.6793382689F,
  142552. 0.7338252629F, 0.7837245849F, 0.8283939355F, 0.8674186656F,
  142553. 0.9006222429F, 0.9280614787F, 0.9500073081F, 0.9669131782F,
  142554. 0.9793740220F, 0.9880792941F, 0.9937636139F, 0.9971582668F,
  142555. 0.9989462667F, 0.9997230082F, 0.9999638688F, 0.9999995525F,
  142556. };
  142557. static float vwin128[64] = {
  142558. 0.0002365472F, 0.0021280687F, 0.0059065254F, 0.0115626550F,
  142559. 0.0190823442F, 0.0284463735F, 0.0396300935F, 0.0526030430F,
  142560. 0.0673285281F, 0.0837631763F, 0.1018564887F, 0.1215504095F,
  142561. 0.1427789367F, 0.1654677960F, 0.1895342001F, 0.2148867160F,
  142562. 0.2414252576F, 0.2690412240F, 0.2976177952F, 0.3270303960F,
  142563. 0.3571473350F, 0.3878306189F, 0.4189369387F, 0.4503188188F,
  142564. 0.4818259135F, 0.5133064334F, 0.5446086751F, 0.5755826278F,
  142565. 0.6060816248F, 0.6359640047F, 0.6650947483F, 0.6933470543F,
  142566. 0.7206038179F, 0.7467589810F, 0.7717187213F, 0.7954024542F,
  142567. 0.8177436264F, 0.8386902831F, 0.8582053981F, 0.8762669622F,
  142568. 0.8928678298F, 0.9080153310F, 0.9217306608F, 0.9340480615F,
  142569. 0.9450138200F, 0.9546851041F, 0.9631286621F, 0.9704194171F,
  142570. 0.9766389810F, 0.9818741197F, 0.9862151938F, 0.9897546035F,
  142571. 0.9925852598F, 0.9947991032F, 0.9964856900F, 0.9977308602F,
  142572. 0.9986155015F, 0.9992144193F, 0.9995953200F, 0.9998179155F,
  142573. 0.9999331503F, 0.9999825563F, 0.9999977357F, 0.9999999720F,
  142574. };
  142575. static float vwin256[128] = {
  142576. 0.0000591390F, 0.0005321979F, 0.0014780301F, 0.0028960636F,
  142577. 0.0047854363F, 0.0071449926F, 0.0099732775F, 0.0132685298F,
  142578. 0.0170286741F, 0.0212513119F, 0.0259337111F, 0.0310727950F,
  142579. 0.0366651302F, 0.0427069140F, 0.0491939614F, 0.0561216907F,
  142580. 0.0634851102F, 0.0712788035F, 0.0794969160F, 0.0881331402F,
  142581. 0.0971807028F, 0.1066323515F, 0.1164803426F, 0.1267164297F,
  142582. 0.1373318534F, 0.1483173323F, 0.1596630553F, 0.1713586755F,
  142583. 0.1833933062F, 0.1957555184F, 0.2084333404F, 0.2214142599F,
  142584. 0.2346852280F, 0.2482326664F, 0.2620424757F, 0.2761000481F,
  142585. 0.2903902813F, 0.3048975959F, 0.3196059553F, 0.3344988887F,
  142586. 0.3495595160F, 0.3647705766F, 0.3801144597F, 0.3955732382F,
  142587. 0.4111287047F, 0.4267624093F, 0.4424557009F, 0.4581897696F,
  142588. 0.4739456913F, 0.4897044744F, 0.5054471075F, 0.5211546088F,
  142589. 0.5368080763F, 0.5523887395F, 0.5678780103F, 0.5832575361F,
  142590. 0.5985092508F, 0.6136154277F, 0.6285587300F, 0.6433222619F,
  142591. 0.6578896175F, 0.6722449294F, 0.6863729144F, 0.7002589187F,
  142592. 0.7138889597F, 0.7272497662F, 0.7403288154F, 0.7531143679F,
  142593. 0.7655954985F, 0.7777621249F, 0.7896050322F, 0.8011158947F,
  142594. 0.8122872932F, 0.8231127294F, 0.8335866365F, 0.8437043850F,
  142595. 0.8534622861F, 0.8628575905F, 0.8718884835F, 0.8805540765F,
  142596. 0.8888543947F, 0.8967903616F, 0.9043637797F, 0.9115773078F,
  142597. 0.9184344360F, 0.9249394562F, 0.9310974312F, 0.9369141608F,
  142598. 0.9423961446F, 0.9475505439F, 0.9523851406F, 0.9569082947F,
  142599. 0.9611289005F, 0.9650563408F, 0.9687004405F, 0.9720714191F,
  142600. 0.9751798427F, 0.9780365753F, 0.9806527301F, 0.9830396204F,
  142601. 0.9852087111F, 0.9871715701F, 0.9889398207F, 0.9905250941F,
  142602. 0.9919389832F, 0.9931929973F, 0.9942985174F, 0.9952667537F,
  142603. 0.9961087037F, 0.9968351119F, 0.9974564312F, 0.9979827858F,
  142604. 0.9984239359F, 0.9987892441F, 0.9990876435F, 0.9993276081F,
  142605. 0.9995171241F, 0.9996636648F, 0.9997741654F, 0.9998550016F,
  142606. 0.9999119692F, 0.9999502656F, 0.9999744742F, 0.9999885497F,
  142607. 0.9999958064F, 0.9999989077F, 0.9999998584F, 0.9999999983F,
  142608. };
  142609. static float vwin512[256] = {
  142610. 0.0000147849F, 0.0001330607F, 0.0003695946F, 0.0007243509F,
  142611. 0.0011972759F, 0.0017882983F, 0.0024973285F, 0.0033242588F,
  142612. 0.0042689632F, 0.0053312973F, 0.0065110982F, 0.0078081841F,
  142613. 0.0092223540F, 0.0107533880F, 0.0124010466F, 0.0141650703F,
  142614. 0.0160451800F, 0.0180410758F, 0.0201524373F, 0.0223789233F,
  142615. 0.0247201710F, 0.0271757958F, 0.0297453914F, 0.0324285286F,
  142616. 0.0352247556F, 0.0381335972F, 0.0411545545F, 0.0442871045F,
  142617. 0.0475306997F, 0.0508847676F, 0.0543487103F, 0.0579219038F,
  142618. 0.0616036982F, 0.0653934164F, 0.0692903546F, 0.0732937809F,
  142619. 0.0774029356F, 0.0816170305F, 0.0859352485F, 0.0903567428F,
  142620. 0.0948806375F, 0.0995060259F, 0.1042319712F, 0.1090575056F,
  142621. 0.1139816300F, 0.1190033137F, 0.1241214941F, 0.1293350764F,
  142622. 0.1346429333F, 0.1400439046F, 0.1455367974F, 0.1511203852F,
  142623. 0.1567934083F, 0.1625545735F, 0.1684025537F, 0.1743359881F,
  142624. 0.1803534820F, 0.1864536069F, 0.1926349000F, 0.1988958650F,
  142625. 0.2052349715F, 0.2116506555F, 0.2181413191F, 0.2247053313F,
  142626. 0.2313410275F, 0.2380467105F, 0.2448206500F, 0.2516610835F,
  142627. 0.2585662164F, 0.2655342226F, 0.2725632448F, 0.2796513950F,
  142628. 0.2867967551F, 0.2939973773F, 0.3012512852F, 0.3085564739F,
  142629. 0.3159109111F, 0.3233125375F, 0.3307592680F, 0.3382489922F,
  142630. 0.3457795756F, 0.3533488602F, 0.3609546657F, 0.3685947904F,
  142631. 0.3762670121F, 0.3839690896F, 0.3916987634F, 0.3994537572F,
  142632. 0.4072317788F, 0.4150305215F, 0.4228476653F, 0.4306808783F,
  142633. 0.4385278181F, 0.4463861329F, 0.4542534630F, 0.4621274424F,
  142634. 0.4700057001F, 0.4778858615F, 0.4857655502F, 0.4936423891F,
  142635. 0.5015140023F, 0.5093780165F, 0.5172320626F, 0.5250737772F,
  142636. 0.5329008043F, 0.5407107971F, 0.5485014192F, 0.5562703465F,
  142637. 0.5640152688F, 0.5717338914F, 0.5794239366F, 0.5870831457F,
  142638. 0.5947092801F, 0.6023001235F, 0.6098534829F, 0.6173671907F,
  142639. 0.6248391059F, 0.6322671161F, 0.6396491384F, 0.6469831217F,
  142640. 0.6542670475F, 0.6614989319F, 0.6686768267F, 0.6757988210F,
  142641. 0.6828630426F, 0.6898676592F, 0.6968108799F, 0.7036909564F,
  142642. 0.7105061843F, 0.7172549043F, 0.7239355032F, 0.7305464154F,
  142643. 0.7370861235F, 0.7435531598F, 0.7499461068F, 0.7562635986F,
  142644. 0.7625043214F, 0.7686670148F, 0.7747504721F, 0.7807535410F,
  142645. 0.7866751247F, 0.7925141825F, 0.7982697296F, 0.8039408387F,
  142646. 0.8095266395F, 0.8150263196F, 0.8204391248F, 0.8257643590F,
  142647. 0.8310013848F, 0.8361496236F, 0.8412085555F, 0.8461777194F,
  142648. 0.8510567129F, 0.8558451924F, 0.8605428730F, 0.8651495278F,
  142649. 0.8696649882F, 0.8740891432F, 0.8784219392F, 0.8826633797F,
  142650. 0.8868135244F, 0.8908724888F, 0.8948404441F, 0.8987176157F,
  142651. 0.9025042831F, 0.9062007791F, 0.9098074886F, 0.9133248482F,
  142652. 0.9167533451F, 0.9200935163F, 0.9233459472F, 0.9265112712F,
  142653. 0.9295901680F, 0.9325833632F, 0.9354916263F, 0.9383157705F,
  142654. 0.9410566504F, 0.9437151618F, 0.9462922398F, 0.9487888576F,
  142655. 0.9512060252F, 0.9535447882F, 0.9558062262F, 0.9579914516F,
  142656. 0.9601016078F, 0.9621378683F, 0.9641014348F, 0.9659935361F,
  142657. 0.9678154261F, 0.9695683830F, 0.9712537071F, 0.9728727198F,
  142658. 0.9744267618F, 0.9759171916F, 0.9773453842F, 0.9787127293F,
  142659. 0.9800206298F, 0.9812705006F, 0.9824637665F, 0.9836018613F,
  142660. 0.9846862258F, 0.9857183066F, 0.9866995544F, 0.9876314227F,
  142661. 0.9885153662F, 0.9893528393F, 0.9901452948F, 0.9908941823F,
  142662. 0.9916009470F, 0.9922670279F, 0.9928938570F, 0.9934828574F,
  142663. 0.9940354423F, 0.9945530133F, 0.9950369595F, 0.9954886562F,
  142664. 0.9959094633F, 0.9963007242F, 0.9966637649F, 0.9969998925F,
  142665. 0.9973103939F, 0.9975965351F, 0.9978595598F, 0.9981006885F,
  142666. 0.9983211172F, 0.9985220166F, 0.9987045311F, 0.9988697776F,
  142667. 0.9990188449F, 0.9991527924F, 0.9992726499F, 0.9993794157F,
  142668. 0.9994740570F, 0.9995575079F, 0.9996306699F, 0.9996944099F,
  142669. 0.9997495605F, 0.9997969190F, 0.9998372465F, 0.9998712678F,
  142670. 0.9998996704F, 0.9999231041F, 0.9999421807F, 0.9999574732F,
  142671. 0.9999695157F, 0.9999788026F, 0.9999857885F, 0.9999908879F,
  142672. 0.9999944746F, 0.9999968817F, 0.9999984010F, 0.9999992833F,
  142673. 0.9999997377F, 0.9999999317F, 0.9999999911F, 0.9999999999F,
  142674. };
  142675. static float vwin1024[512] = {
  142676. 0.0000036962F, 0.0000332659F, 0.0000924041F, 0.0001811086F,
  142677. 0.0002993761F, 0.0004472021F, 0.0006245811F, 0.0008315063F,
  142678. 0.0010679699F, 0.0013339631F, 0.0016294757F, 0.0019544965F,
  142679. 0.0023090133F, 0.0026930125F, 0.0031064797F, 0.0035493989F,
  142680. 0.0040217533F, 0.0045235250F, 0.0050546946F, 0.0056152418F,
  142681. 0.0062051451F, 0.0068243817F, 0.0074729278F, 0.0081507582F,
  142682. 0.0088578466F, 0.0095941655F, 0.0103596863F, 0.0111543789F,
  142683. 0.0119782122F, 0.0128311538F, 0.0137131701F, 0.0146242260F,
  142684. 0.0155642855F, 0.0165333111F, 0.0175312640F, 0.0185581042F,
  142685. 0.0196137903F, 0.0206982797F, 0.0218115284F, 0.0229534910F,
  142686. 0.0241241208F, 0.0253233698F, 0.0265511886F, 0.0278075263F,
  142687. 0.0290923308F, 0.0304055484F, 0.0317471241F, 0.0331170013F,
  142688. 0.0345151222F, 0.0359414274F, 0.0373958560F, 0.0388783456F,
  142689. 0.0403888325F, 0.0419272511F, 0.0434935347F, 0.0450876148F,
  142690. 0.0467094213F, 0.0483588828F, 0.0500359261F, 0.0517404765F,
  142691. 0.0534724575F, 0.0552317913F, 0.0570183983F, 0.0588321971F,
  142692. 0.0606731048F, 0.0625410369F, 0.0644359070F, 0.0663576272F,
  142693. 0.0683061077F, 0.0702812571F, 0.0722829821F, 0.0743111878F,
  142694. 0.0763657775F, 0.0784466526F, 0.0805537129F, 0.0826868561F,
  142695. 0.0848459782F, 0.0870309736F, 0.0892417345F, 0.0914781514F,
  142696. 0.0937401128F, 0.0960275056F, 0.0983402145F, 0.1006781223F,
  142697. 0.1030411101F, 0.1054290568F, 0.1078418397F, 0.1102793336F,
  142698. 0.1127414119F, 0.1152279457F, 0.1177388042F, 0.1202738544F,
  142699. 0.1228329618F, 0.1254159892F, 0.1280227980F, 0.1306532471F,
  142700. 0.1333071937F, 0.1359844927F, 0.1386849970F, 0.1414085575F,
  142701. 0.1441550230F, 0.1469242403F, 0.1497160539F, 0.1525303063F,
  142702. 0.1553668381F, 0.1582254875F, 0.1611060909F, 0.1640084822F,
  142703. 0.1669324936F, 0.1698779549F, 0.1728446939F, 0.1758325362F,
  142704. 0.1788413055F, 0.1818708232F, 0.1849209084F, 0.1879913785F,
  142705. 0.1910820485F, 0.1941927312F, 0.1973232376F, 0.2004733764F,
  142706. 0.2036429541F, 0.2068317752F, 0.2100396421F, 0.2132663552F,
  142707. 0.2165117125F, 0.2197755102F, 0.2230575422F, 0.2263576007F,
  142708. 0.2296754753F, 0.2330109540F, 0.2363638225F, 0.2397338646F,
  142709. 0.2431208619F, 0.2465245941F, 0.2499448389F, 0.2533813719F,
  142710. 0.2568339669F, 0.2603023956F, 0.2637864277F, 0.2672858312F,
  142711. 0.2708003718F, 0.2743298135F, 0.2778739186F, 0.2814324472F,
  142712. 0.2850051576F, 0.2885918065F, 0.2921921485F, 0.2958059366F,
  142713. 0.2994329219F, 0.3030728538F, 0.3067254799F, 0.3103905462F,
  142714. 0.3140677969F, 0.3177569747F, 0.3214578205F, 0.3251700736F,
  142715. 0.3288934718F, 0.3326277513F, 0.3363726468F, 0.3401278914F,
  142716. 0.3438932168F, 0.3476683533F, 0.3514530297F, 0.3552469734F,
  142717. 0.3590499106F, 0.3628615659F, 0.3666816630F, 0.3705099239F,
  142718. 0.3743460698F, 0.3781898204F, 0.3820408945F, 0.3858990095F,
  142719. 0.3897638820F, 0.3936352274F, 0.3975127601F, 0.4013961936F,
  142720. 0.4052852405F, 0.4091796123F, 0.4130790198F, 0.4169831732F,
  142721. 0.4208917815F, 0.4248045534F, 0.4287211965F, 0.4326414181F,
  142722. 0.4365649248F, 0.4404914225F, 0.4444206167F, 0.4483522125F,
  142723. 0.4522859146F, 0.4562214270F, 0.4601584538F, 0.4640966984F,
  142724. 0.4680358644F, 0.4719756548F, 0.4759157726F, 0.4798559209F,
  142725. 0.4837958024F, 0.4877351199F, 0.4916735765F, 0.4956108751F,
  142726. 0.4995467188F, 0.5034808109F, 0.5074128550F, 0.5113425550F,
  142727. 0.5152696149F, 0.5191937395F, 0.5231146336F, 0.5270320028F,
  142728. 0.5309455530F, 0.5348549910F, 0.5387600239F, 0.5426603597F,
  142729. 0.5465557070F, 0.5504457754F, 0.5543302752F, 0.5582089175F,
  142730. 0.5620814145F, 0.5659474793F, 0.5698068262F, 0.5736591704F,
  142731. 0.5775042283F, 0.5813417176F, 0.5851713571F, 0.5889928670F,
  142732. 0.5928059689F, 0.5966103856F, 0.6004058415F, 0.6041920626F,
  142733. 0.6079687761F, 0.6117357113F, 0.6154925986F, 0.6192391705F,
  142734. 0.6229751612F, 0.6267003064F, 0.6304143441F, 0.6341170137F,
  142735. 0.6378080569F, 0.6414872173F, 0.6451542405F, 0.6488088741F,
  142736. 0.6524508681F, 0.6560799742F, 0.6596959469F, 0.6632985424F,
  142737. 0.6668875197F, 0.6704626398F, 0.6740236662F, 0.6775703649F,
  142738. 0.6811025043F, 0.6846198554F, 0.6881221916F, 0.6916092892F,
  142739. 0.6950809269F, 0.6985368861F, 0.7019769510F, 0.7054009085F,
  142740. 0.7088085484F, 0.7121996632F, 0.7155740484F, 0.7189315023F,
  142741. 0.7222718263F, 0.7255948245F, 0.7289003043F, 0.7321880760F,
  142742. 0.7354579530F, 0.7387097518F, 0.7419432921F, 0.7451583966F,
  142743. 0.7483548915F, 0.7515326059F, 0.7546913723F, 0.7578310265F,
  142744. 0.7609514077F, 0.7640523581F, 0.7671337237F, 0.7701953535F,
  142745. 0.7732371001F, 0.7762588195F, 0.7792603711F, 0.7822416178F,
  142746. 0.7852024259F, 0.7881426654F, 0.7910622097F, 0.7939609356F,
  142747. 0.7968387237F, 0.7996954579F, 0.8025310261F, 0.8053453193F,
  142748. 0.8081382324F, 0.8109096638F, 0.8136595156F, 0.8163876936F,
  142749. 0.8190941071F, 0.8217786690F, 0.8244412960F, 0.8270819086F,
  142750. 0.8297004305F, 0.8322967896F, 0.8348709171F, 0.8374227481F,
  142751. 0.8399522213F, 0.8424592789F, 0.8449438672F, 0.8474059356F,
  142752. 0.8498454378F, 0.8522623306F, 0.8546565748F, 0.8570281348F,
  142753. 0.8593769787F, 0.8617030779F, 0.8640064080F, 0.8662869477F,
  142754. 0.8685446796F, 0.8707795899F, 0.8729916682F, 0.8751809079F,
  142755. 0.8773473059F, 0.8794908626F, 0.8816115819F, 0.8837094713F,
  142756. 0.8857845418F, 0.8878368079F, 0.8898662874F, 0.8918730019F,
  142757. 0.8938569760F, 0.8958182380F, 0.8977568194F, 0.8996727552F,
  142758. 0.9015660837F, 0.9034368465F, 0.9052850885F, 0.9071108577F,
  142759. 0.9089142057F, 0.9106951869F, 0.9124538591F, 0.9141902832F,
  142760. 0.9159045233F, 0.9175966464F, 0.9192667228F, 0.9209148257F,
  142761. 0.9225410313F, 0.9241454187F, 0.9257280701F, 0.9272890704F,
  142762. 0.9288285075F, 0.9303464720F, 0.9318430576F, 0.9333183603F,
  142763. 0.9347724792F, 0.9362055158F, 0.9376175745F, 0.9390087622F,
  142764. 0.9403791881F, 0.9417289644F, 0.9430582055F, 0.9443670283F,
  142765. 0.9456555521F, 0.9469238986F, 0.9481721917F, 0.9494005577F,
  142766. 0.9506091252F, 0.9517980248F, 0.9529673894F, 0.9541173540F,
  142767. 0.9552480557F, 0.9563596334F, 0.9574522282F, 0.9585259830F,
  142768. 0.9595810428F, 0.9606175542F, 0.9616356656F, 0.9626355274F,
  142769. 0.9636172915F, 0.9645811114F, 0.9655271425F, 0.9664555414F,
  142770. 0.9673664664F, 0.9682600774F, 0.9691365355F, 0.9699960034F,
  142771. 0.9708386448F, 0.9716646250F, 0.9724741103F, 0.9732672685F,
  142772. 0.9740442683F, 0.9748052795F, 0.9755504729F, 0.9762800205F,
  142773. 0.9769940950F, 0.9776928703F, 0.9783765210F, 0.9790452223F,
  142774. 0.9796991504F, 0.9803384823F, 0.9809633954F, 0.9815740679F,
  142775. 0.9821706784F, 0.9827534063F, 0.9833224312F, 0.9838779332F,
  142776. 0.9844200928F, 0.9849490910F, 0.9854651087F, 0.9859683274F,
  142777. 0.9864589286F, 0.9869370940F, 0.9874030054F, 0.9878568447F,
  142778. 0.9882987937F, 0.9887290343F, 0.9891477481F, 0.9895551169F,
  142779. 0.9899513220F, 0.9903365446F, 0.9907109658F, 0.9910747662F,
  142780. 0.9914281260F, 0.9917712252F, 0.9921042433F, 0.9924273593F,
  142781. 0.9927407516F, 0.9930445982F, 0.9933390763F, 0.9936243626F,
  142782. 0.9939006331F, 0.9941680631F, 0.9944268269F, 0.9946770982F,
  142783. 0.9949190498F, 0.9951528537F, 0.9953786808F, 0.9955967011F,
  142784. 0.9958070836F, 0.9960099963F, 0.9962056061F, 0.9963940787F,
  142785. 0.9965755786F, 0.9967502693F, 0.9969183129F, 0.9970798704F,
  142786. 0.9972351013F, 0.9973841640F, 0.9975272151F, 0.9976644103F,
  142787. 0.9977959036F, 0.9979218476F, 0.9980423932F, 0.9981576901F,
  142788. 0.9982678862F, 0.9983731278F, 0.9984735596F, 0.9985693247F,
  142789. 0.9986605645F, 0.9987474186F, 0.9988300248F, 0.9989085193F,
  142790. 0.9989830364F, 0.9990537085F, 0.9991206662F, 0.9991840382F,
  142791. 0.9992439513F, 0.9993005303F, 0.9993538982F, 0.9994041757F,
  142792. 0.9994514817F, 0.9994959330F, 0.9995376444F, 0.9995767286F,
  142793. 0.9996132960F, 0.9996474550F, 0.9996793121F, 0.9997089710F,
  142794. 0.9997365339F, 0.9997621003F, 0.9997857677F, 0.9998076311F,
  142795. 0.9998277836F, 0.9998463156F, 0.9998633155F, 0.9998788692F,
  142796. 0.9998930603F, 0.9999059701F, 0.9999176774F, 0.9999282586F,
  142797. 0.9999377880F, 0.9999463370F, 0.9999539749F, 0.9999607685F,
  142798. 0.9999667820F, 0.9999720773F, 0.9999767136F, 0.9999807479F,
  142799. 0.9999842344F, 0.9999872249F, 0.9999897688F, 0.9999919127F,
  142800. 0.9999937009F, 0.9999951749F, 0.9999963738F, 0.9999973342F,
  142801. 0.9999980900F, 0.9999986724F, 0.9999991103F, 0.9999994297F,
  142802. 0.9999996543F, 0.9999998049F, 0.9999999000F, 0.9999999552F,
  142803. 0.9999999836F, 0.9999999957F, 0.9999999994F, 1.0000000000F,
  142804. };
  142805. static float vwin2048[1024] = {
  142806. 0.0000009241F, 0.0000083165F, 0.0000231014F, 0.0000452785F,
  142807. 0.0000748476F, 0.0001118085F, 0.0001561608F, 0.0002079041F,
  142808. 0.0002670379F, 0.0003335617F, 0.0004074748F, 0.0004887765F,
  142809. 0.0005774661F, 0.0006735427F, 0.0007770054F, 0.0008878533F,
  142810. 0.0010060853F, 0.0011317002F, 0.0012646969F, 0.0014050742F,
  142811. 0.0015528307F, 0.0017079650F, 0.0018704756F, 0.0020403610F,
  142812. 0.0022176196F, 0.0024022497F, 0.0025942495F, 0.0027936173F,
  142813. 0.0030003511F, 0.0032144490F, 0.0034359088F, 0.0036647286F,
  142814. 0.0039009061F, 0.0041444391F, 0.0043953253F, 0.0046535621F,
  142815. 0.0049191472F, 0.0051920781F, 0.0054723520F, 0.0057599664F,
  142816. 0.0060549184F, 0.0063572052F, 0.0066668239F, 0.0069837715F,
  142817. 0.0073080449F, 0.0076396410F, 0.0079785566F, 0.0083247884F,
  142818. 0.0086783330F, 0.0090391871F, 0.0094073470F, 0.0097828092F,
  142819. 0.0101655700F, 0.0105556258F, 0.0109529726F, 0.0113576065F,
  142820. 0.0117695237F, 0.0121887200F, 0.0126151913F, 0.0130489335F,
  142821. 0.0134899422F, 0.0139382130F, 0.0143937415F, 0.0148565233F,
  142822. 0.0153265536F, 0.0158038279F, 0.0162883413F, 0.0167800889F,
  142823. 0.0172790660F, 0.0177852675F, 0.0182986882F, 0.0188193231F,
  142824. 0.0193471668F, 0.0198822141F, 0.0204244594F, 0.0209738974F,
  142825. 0.0215305225F, 0.0220943289F, 0.0226653109F, 0.0232434627F,
  142826. 0.0238287784F, 0.0244212519F, 0.0250208772F, 0.0256276481F,
  142827. 0.0262415582F, 0.0268626014F, 0.0274907711F, 0.0281260608F,
  142828. 0.0287684638F, 0.0294179736F, 0.0300745833F, 0.0307382859F,
  142829. 0.0314090747F, 0.0320869424F, 0.0327718819F, 0.0334638860F,
  142830. 0.0341629474F, 0.0348690586F, 0.0355822122F, 0.0363024004F,
  142831. 0.0370296157F, 0.0377638502F, 0.0385050960F, 0.0392533451F,
  142832. 0.0400085896F, 0.0407708211F, 0.0415400315F, 0.0423162123F,
  142833. 0.0430993552F, 0.0438894515F, 0.0446864926F, 0.0454904698F,
  142834. 0.0463013742F, 0.0471191969F, 0.0479439288F, 0.0487755607F,
  142835. 0.0496140836F, 0.0504594879F, 0.0513117642F, 0.0521709031F,
  142836. 0.0530368949F, 0.0539097297F, 0.0547893979F, 0.0556758894F,
  142837. 0.0565691941F, 0.0574693019F, 0.0583762026F, 0.0592898858F,
  142838. 0.0602103410F, 0.0611375576F, 0.0620715250F, 0.0630122324F,
  142839. 0.0639596688F, 0.0649138234F, 0.0658746848F, 0.0668422421F,
  142840. 0.0678164838F, 0.0687973985F, 0.0697849746F, 0.0707792005F,
  142841. 0.0717800645F, 0.0727875547F, 0.0738016591F, 0.0748223656F,
  142842. 0.0758496620F, 0.0768835359F, 0.0779239751F, 0.0789709668F,
  142843. 0.0800244985F, 0.0810845574F, 0.0821511306F, 0.0832242052F,
  142844. 0.0843037679F, 0.0853898056F, 0.0864823050F, 0.0875812525F,
  142845. 0.0886866347F, 0.0897984378F, 0.0909166480F, 0.0920412513F,
  142846. 0.0931722338F, 0.0943095813F, 0.0954532795F, 0.0966033140F,
  142847. 0.0977596702F, 0.0989223336F, 0.1000912894F, 0.1012665227F,
  142848. 0.1024480185F, 0.1036357616F, 0.1048297369F, 0.1060299290F,
  142849. 0.1072363224F, 0.1084489014F, 0.1096676504F, 0.1108925534F,
  142850. 0.1121235946F, 0.1133607577F, 0.1146040267F, 0.1158533850F,
  142851. 0.1171088163F, 0.1183703040F, 0.1196378312F, 0.1209113812F,
  142852. 0.1221909370F, 0.1234764815F, 0.1247679974F, 0.1260654674F,
  142853. 0.1273688740F, 0.1286781995F, 0.1299934263F, 0.1313145365F,
  142854. 0.1326415121F, 0.1339743349F, 0.1353129866F, 0.1366574490F,
  142855. 0.1380077035F, 0.1393637315F, 0.1407255141F, 0.1420930325F,
  142856. 0.1434662677F, 0.1448452004F, 0.1462298115F, 0.1476200814F,
  142857. 0.1490159906F, 0.1504175195F, 0.1518246482F, 0.1532373569F,
  142858. 0.1546556253F, 0.1560794333F, 0.1575087606F, 0.1589435866F,
  142859. 0.1603838909F, 0.1618296526F, 0.1632808509F, 0.1647374648F,
  142860. 0.1661994731F, 0.1676668546F, 0.1691395880F, 0.1706176516F,
  142861. 0.1721010238F, 0.1735896829F, 0.1750836068F, 0.1765827736F,
  142862. 0.1780871610F, 0.1795967468F, 0.1811115084F, 0.1826314234F,
  142863. 0.1841564689F, 0.1856866221F, 0.1872218600F, 0.1887621595F,
  142864. 0.1903074974F, 0.1918578503F, 0.1934131947F, 0.1949735068F,
  142865. 0.1965387630F, 0.1981089393F, 0.1996840117F, 0.2012639560F,
  142866. 0.2028487479F, 0.2044383630F, 0.2060327766F, 0.2076319642F,
  142867. 0.2092359007F, 0.2108445614F, 0.2124579211F, 0.2140759545F,
  142868. 0.2156986364F, 0.2173259411F, 0.2189578432F, 0.2205943168F,
  142869. 0.2222353361F, 0.2238808751F, 0.2255309076F, 0.2271854073F,
  142870. 0.2288443480F, 0.2305077030F, 0.2321754457F, 0.2338475493F,
  142871. 0.2355239869F, 0.2372047315F, 0.2388897560F, 0.2405790329F,
  142872. 0.2422725350F, 0.2439702347F, 0.2456721043F, 0.2473781159F,
  142873. 0.2490882418F, 0.2508024539F, 0.2525207240F, 0.2542430237F,
  142874. 0.2559693248F, 0.2576995986F, 0.2594338166F, 0.2611719498F,
  142875. 0.2629139695F, 0.2646598466F, 0.2664095520F, 0.2681630564F,
  142876. 0.2699203304F, 0.2716813445F, 0.2734460691F, 0.2752144744F,
  142877. 0.2769865307F, 0.2787622079F, 0.2805414760F, 0.2823243047F,
  142878. 0.2841106637F, 0.2859005227F, 0.2876938509F, 0.2894906179F,
  142879. 0.2912907928F, 0.2930943447F, 0.2949012426F, 0.2967114554F,
  142880. 0.2985249520F, 0.3003417009F, 0.3021616708F, 0.3039848301F,
  142881. 0.3058111471F, 0.3076405901F, 0.3094731273F, 0.3113087266F,
  142882. 0.3131473560F, 0.3149889833F, 0.3168335762F, 0.3186811024F,
  142883. 0.3205315294F, 0.3223848245F, 0.3242409552F, 0.3260998886F,
  142884. 0.3279615918F, 0.3298260319F, 0.3316931758F, 0.3335629903F,
  142885. 0.3354354423F, 0.3373104982F, 0.3391881247F, 0.3410682882F,
  142886. 0.3429509551F, 0.3448360917F, 0.3467236642F, 0.3486136387F,
  142887. 0.3505059811F, 0.3524006575F, 0.3542976336F, 0.3561968753F,
  142888. 0.3580983482F, 0.3600020179F, 0.3619078499F, 0.3638158096F,
  142889. 0.3657258625F, 0.3676379737F, 0.3695521086F, 0.3714682321F,
  142890. 0.3733863094F, 0.3753063055F, 0.3772281852F, 0.3791519134F,
  142891. 0.3810774548F, 0.3830047742F, 0.3849338362F, 0.3868646053F,
  142892. 0.3887970459F, 0.3907311227F, 0.3926667998F, 0.3946040417F,
  142893. 0.3965428125F, 0.3984830765F, 0.4004247978F, 0.4023679403F,
  142894. 0.4043124683F, 0.4062583455F, 0.4082055359F, 0.4101540034F,
  142895. 0.4121037117F, 0.4140546246F, 0.4160067058F, 0.4179599190F,
  142896. 0.4199142277F, 0.4218695956F, 0.4238259861F, 0.4257833627F,
  142897. 0.4277416888F, 0.4297009279F, 0.4316610433F, 0.4336219983F,
  142898. 0.4355837562F, 0.4375462803F, 0.4395095337F, 0.4414734797F,
  142899. 0.4434380815F, 0.4454033021F, 0.4473691046F, 0.4493354521F,
  142900. 0.4513023078F, 0.4532696345F, 0.4552373954F, 0.4572055533F,
  142901. 0.4591740713F, 0.4611429123F, 0.4631120393F, 0.4650814151F,
  142902. 0.4670510028F, 0.4690207650F, 0.4709906649F, 0.4729606651F,
  142903. 0.4749307287F, 0.4769008185F, 0.4788708972F, 0.4808409279F,
  142904. 0.4828108732F, 0.4847806962F, 0.4867503597F, 0.4887198264F,
  142905. 0.4906890593F, 0.4926580213F, 0.4946266753F, 0.4965949840F,
  142906. 0.4985629105F, 0.5005304176F, 0.5024974683F, 0.5044640255F,
  142907. 0.5064300522F, 0.5083955114F, 0.5103603659F, 0.5123245790F,
  142908. 0.5142881136F, 0.5162509328F, 0.5182129997F, 0.5201742774F,
  142909. 0.5221347290F, 0.5240943178F, 0.5260530070F, 0.5280107598F,
  142910. 0.5299675395F, 0.5319233095F, 0.5338780330F, 0.5358316736F,
  142911. 0.5377841946F, 0.5397355596F, 0.5416857320F, 0.5436346755F,
  142912. 0.5455823538F, 0.5475287304F, 0.5494737691F, 0.5514174337F,
  142913. 0.5533596881F, 0.5553004962F, 0.5572398218F, 0.5591776291F,
  142914. 0.5611138821F, 0.5630485449F, 0.5649815818F, 0.5669129570F,
  142915. 0.5688426349F, 0.5707705799F, 0.5726967564F, 0.5746211290F,
  142916. 0.5765436624F, 0.5784643212F, 0.5803830702F, 0.5822998743F,
  142917. 0.5842146984F, 0.5861275076F, 0.5880382669F, 0.5899469416F,
  142918. 0.5918534968F, 0.5937578981F, 0.5956601107F, 0.5975601004F,
  142919. 0.5994578326F, 0.6013532732F, 0.6032463880F, 0.6051371429F,
  142920. 0.6070255039F, 0.6089114372F, 0.6107949090F, 0.6126758856F,
  142921. 0.6145543334F, 0.6164302191F, 0.6183035092F, 0.6201741706F,
  142922. 0.6220421700F, 0.6239074745F, 0.6257700513F, 0.6276298674F,
  142923. 0.6294868903F, 0.6313410873F, 0.6331924262F, 0.6350408745F,
  142924. 0.6368864001F, 0.6387289710F, 0.6405685552F, 0.6424051209F,
  142925. 0.6442386364F, 0.6460690702F, 0.6478963910F, 0.6497205673F,
  142926. 0.6515415682F, 0.6533593625F, 0.6551739194F, 0.6569852082F,
  142927. 0.6587931984F, 0.6605978593F, 0.6623991609F, 0.6641970728F,
  142928. 0.6659915652F, 0.6677826081F, 0.6695701718F, 0.6713542268F,
  142929. 0.6731347437F, 0.6749116932F, 0.6766850461F, 0.6784547736F,
  142930. 0.6802208469F, 0.6819832374F, 0.6837419164F, 0.6854968559F,
  142931. 0.6872480275F, 0.6889954034F, 0.6907389556F, 0.6924786566F,
  142932. 0.6942144788F, 0.6959463950F, 0.6976743780F, 0.6993984008F,
  142933. 0.7011184365F, 0.7028344587F, 0.7045464407F, 0.7062543564F,
  142934. 0.7079581796F, 0.7096578844F, 0.7113534450F, 0.7130448359F,
  142935. 0.7147320316F, 0.7164150070F, 0.7180937371F, 0.7197681970F,
  142936. 0.7214383620F, 0.7231042077F, 0.7247657098F, 0.7264228443F,
  142937. 0.7280755871F, 0.7297239147F, 0.7313678035F, 0.7330072301F,
  142938. 0.7346421715F, 0.7362726046F, 0.7378985069F, 0.7395198556F,
  142939. 0.7411366285F, 0.7427488034F, 0.7443563584F, 0.7459592717F,
  142940. 0.7475575218F, 0.7491510873F, 0.7507399471F, 0.7523240803F,
  142941. 0.7539034661F, 0.7554780839F, 0.7570479136F, 0.7586129349F,
  142942. 0.7601731279F, 0.7617284730F, 0.7632789506F, 0.7648245416F,
  142943. 0.7663652267F, 0.7679009872F, 0.7694318044F, 0.7709576599F,
  142944. 0.7724785354F, 0.7739944130F, 0.7755052749F, 0.7770111035F,
  142945. 0.7785118815F, 0.7800075916F, 0.7814982170F, 0.7829837410F,
  142946. 0.7844641472F, 0.7859394191F, 0.7874095408F, 0.7888744965F,
  142947. 0.7903342706F, 0.7917888476F, 0.7932382124F, 0.7946823501F,
  142948. 0.7961212460F, 0.7975548855F, 0.7989832544F, 0.8004063386F,
  142949. 0.8018241244F, 0.8032365981F, 0.8046437463F, 0.8060455560F,
  142950. 0.8074420141F, 0.8088331080F, 0.8102188253F, 0.8115991536F,
  142951. 0.8129740810F, 0.8143435957F, 0.8157076861F, 0.8170663409F,
  142952. 0.8184195489F, 0.8197672994F, 0.8211095817F, 0.8224463853F,
  142953. 0.8237777001F, 0.8251035161F, 0.8264238235F, 0.8277386129F,
  142954. 0.8290478750F, 0.8303516008F, 0.8316497814F, 0.8329424083F,
  142955. 0.8342294731F, 0.8355109677F, 0.8367868841F, 0.8380572148F,
  142956. 0.8393219523F, 0.8405810893F, 0.8418346190F, 0.8430825345F,
  142957. 0.8443248294F, 0.8455614974F, 0.8467925323F, 0.8480179285F,
  142958. 0.8492376802F, 0.8504517822F, 0.8516602292F, 0.8528630164F,
  142959. 0.8540601391F, 0.8552515928F, 0.8564373733F, 0.8576174766F,
  142960. 0.8587918990F, 0.8599606368F, 0.8611236868F, 0.8622810460F,
  142961. 0.8634327113F, 0.8645786802F, 0.8657189504F, 0.8668535195F,
  142962. 0.8679823857F, 0.8691055472F, 0.8702230025F, 0.8713347503F,
  142963. 0.8724407896F, 0.8735411194F, 0.8746357394F, 0.8757246489F,
  142964. 0.8768078479F, 0.8778853364F, 0.8789571146F, 0.8800231832F,
  142965. 0.8810835427F, 0.8821381942F, 0.8831871387F, 0.8842303777F,
  142966. 0.8852679127F, 0.8862997456F, 0.8873258784F, 0.8883463132F,
  142967. 0.8893610527F, 0.8903700994F, 0.8913734562F, 0.8923711263F,
  142968. 0.8933631129F, 0.8943494196F, 0.8953300500F, 0.8963050083F,
  142969. 0.8972742985F, 0.8982379249F, 0.8991958922F, 0.9001482052F,
  142970. 0.9010948688F, 0.9020358883F, 0.9029712690F, 0.9039010165F,
  142971. 0.9048251367F, 0.9057436357F, 0.9066565195F, 0.9075637946F,
  142972. 0.9084654678F, 0.9093615456F, 0.9102520353F, 0.9111369440F,
  142973. 0.9120162792F, 0.9128900484F, 0.9137582595F, 0.9146209204F,
  142974. 0.9154780394F, 0.9163296248F, 0.9171756853F, 0.9180162296F,
  142975. 0.9188512667F, 0.9196808057F, 0.9205048559F, 0.9213234270F,
  142976. 0.9221365285F, 0.9229441704F, 0.9237463629F, 0.9245431160F,
  142977. 0.9253344404F, 0.9261203465F, 0.9269008453F, 0.9276759477F,
  142978. 0.9284456648F, 0.9292100080F, 0.9299689889F, 0.9307226190F,
  142979. 0.9314709103F, 0.9322138747F, 0.9329515245F, 0.9336838721F,
  142980. 0.9344109300F, 0.9351327108F, 0.9358492275F, 0.9365604931F,
  142981. 0.9372665208F, 0.9379673239F, 0.9386629160F, 0.9393533107F,
  142982. 0.9400385220F, 0.9407185637F, 0.9413934501F, 0.9420631954F,
  142983. 0.9427278141F, 0.9433873208F, 0.9440417304F, 0.9446910576F,
  142984. 0.9453353176F, 0.9459745255F, 0.9466086968F, 0.9472378469F,
  142985. 0.9478619915F, 0.9484811463F, 0.9490953274F, 0.9497045506F,
  142986. 0.9503088323F, 0.9509081888F, 0.9515026365F, 0.9520921921F,
  142987. 0.9526768723F, 0.9532566940F, 0.9538316742F, 0.9544018300F,
  142988. 0.9549671786F, 0.9555277375F, 0.9560835241F, 0.9566345562F,
  142989. 0.9571808513F, 0.9577224275F, 0.9582593027F, 0.9587914949F,
  142990. 0.9593190225F, 0.9598419038F, 0.9603601571F, 0.9608738012F,
  142991. 0.9613828546F, 0.9618873361F, 0.9623872646F, 0.9628826591F,
  142992. 0.9633735388F, 0.9638599227F, 0.9643418303F, 0.9648192808F,
  142993. 0.9652922939F, 0.9657608890F, 0.9662250860F, 0.9666849046F,
  142994. 0.9671403646F, 0.9675914861F, 0.9680382891F, 0.9684807937F,
  142995. 0.9689190202F, 0.9693529890F, 0.9697827203F, 0.9702082347F,
  142996. 0.9706295529F, 0.9710466953F, 0.9714596828F, 0.9718685362F,
  142997. 0.9722732762F, 0.9726739240F, 0.9730705005F, 0.9734630267F,
  142998. 0.9738515239F, 0.9742360134F, 0.9746165163F, 0.9749930540F,
  142999. 0.9753656481F, 0.9757343198F, 0.9760990909F, 0.9764599829F,
  143000. 0.9768170175F, 0.9771702164F, 0.9775196013F, 0.9778651941F,
  143001. 0.9782070167F, 0.9785450909F, 0.9788794388F, 0.9792100824F,
  143002. 0.9795370437F, 0.9798603449F, 0.9801800080F, 0.9804960554F,
  143003. 0.9808085092F, 0.9811173916F, 0.9814227251F, 0.9817245318F,
  143004. 0.9820228343F, 0.9823176549F, 0.9826090160F, 0.9828969402F,
  143005. 0.9831814498F, 0.9834625674F, 0.9837403156F, 0.9840147169F,
  143006. 0.9842857939F, 0.9845535692F, 0.9848180654F, 0.9850793052F,
  143007. 0.9853373113F, 0.9855921062F, 0.9858437127F, 0.9860921535F,
  143008. 0.9863374512F, 0.9865796287F, 0.9868187085F, 0.9870547136F,
  143009. 0.9872876664F, 0.9875175899F, 0.9877445067F, 0.9879684396F,
  143010. 0.9881894112F, 0.9884074444F, 0.9886225619F, 0.9888347863F,
  143011. 0.9890441404F, 0.9892506468F, 0.9894543284F, 0.9896552077F,
  143012. 0.9898533074F, 0.9900486502F, 0.9902412587F, 0.9904311555F,
  143013. 0.9906183633F, 0.9908029045F, 0.9909848019F, 0.9911640779F,
  143014. 0.9913407550F, 0.9915148557F, 0.9916864025F, 0.9918554179F,
  143015. 0.9920219241F, 0.9921859437F, 0.9923474989F, 0.9925066120F,
  143016. 0.9926633054F, 0.9928176012F, 0.9929695218F, 0.9931190891F,
  143017. 0.9932663254F, 0.9934112527F, 0.9935538932F, 0.9936942686F,
  143018. 0.9938324012F, 0.9939683126F, 0.9941020248F, 0.9942335597F,
  143019. 0.9943629388F, 0.9944901841F, 0.9946153170F, 0.9947383593F,
  143020. 0.9948593325F, 0.9949782579F, 0.9950951572F, 0.9952100516F,
  143021. 0.9953229625F, 0.9954339111F, 0.9955429186F, 0.9956500062F,
  143022. 0.9957551948F, 0.9958585056F, 0.9959599593F, 0.9960595769F,
  143023. 0.9961573792F, 0.9962533869F, 0.9963476206F, 0.9964401009F,
  143024. 0.9965308483F, 0.9966198833F, 0.9967072261F, 0.9967928971F,
  143025. 0.9968769164F, 0.9969593041F, 0.9970400804F, 0.9971192651F,
  143026. 0.9971968781F, 0.9972729391F, 0.9973474680F, 0.9974204842F,
  143027. 0.9974920074F, 0.9975620569F, 0.9976306521F, 0.9976978122F,
  143028. 0.9977635565F, 0.9978279039F, 0.9978908736F, 0.9979524842F,
  143029. 0.9980127547F, 0.9980717037F, 0.9981293499F, 0.9981857116F,
  143030. 0.9982408073F, 0.9982946554F, 0.9983472739F, 0.9983986810F,
  143031. 0.9984488947F, 0.9984979328F, 0.9985458132F, 0.9985925534F,
  143032. 0.9986381711F, 0.9986826838F, 0.9987261086F, 0.9987684630F,
  143033. 0.9988097640F, 0.9988500286F, 0.9988892738F, 0.9989275163F,
  143034. 0.9989647727F, 0.9990010597F, 0.9990363938F, 0.9990707911F,
  143035. 0.9991042679F, 0.9991368404F, 0.9991685244F, 0.9991993358F,
  143036. 0.9992292905F, 0.9992584038F, 0.9992866914F, 0.9993141686F,
  143037. 0.9993408506F, 0.9993667526F, 0.9993918895F, 0.9994162761F,
  143038. 0.9994399273F, 0.9994628576F, 0.9994850815F, 0.9995066133F,
  143039. 0.9995274672F, 0.9995476574F, 0.9995671978F, 0.9995861021F,
  143040. 0.9996043841F, 0.9996220573F, 0.9996391352F, 0.9996556310F,
  143041. 0.9996715579F, 0.9996869288F, 0.9997017568F, 0.9997160543F,
  143042. 0.9997298342F, 0.9997431088F, 0.9997558905F, 0.9997681914F,
  143043. 0.9997800236F, 0.9997913990F, 0.9998023292F, 0.9998128261F,
  143044. 0.9998229009F, 0.9998325650F, 0.9998418296F, 0.9998507058F,
  143045. 0.9998592044F, 0.9998673362F, 0.9998751117F, 0.9998825415F,
  143046. 0.9998896358F, 0.9998964047F, 0.9999028584F, 0.9999090066F,
  143047. 0.9999148590F, 0.9999204253F, 0.9999257148F, 0.9999307368F,
  143048. 0.9999355003F, 0.9999400144F, 0.9999442878F, 0.9999483293F,
  143049. 0.9999521472F, 0.9999557499F, 0.9999591457F, 0.9999623426F,
  143050. 0.9999653483F, 0.9999681708F, 0.9999708175F, 0.9999732959F,
  143051. 0.9999756132F, 0.9999777765F, 0.9999797928F, 0.9999816688F,
  143052. 0.9999834113F, 0.9999850266F, 0.9999865211F, 0.9999879009F,
  143053. 0.9999891721F, 0.9999903405F, 0.9999914118F, 0.9999923914F,
  143054. 0.9999932849F, 0.9999940972F, 0.9999948336F, 0.9999954989F,
  143055. 0.9999960978F, 0.9999966349F, 0.9999971146F, 0.9999975411F,
  143056. 0.9999979185F, 0.9999982507F, 0.9999985414F, 0.9999987944F,
  143057. 0.9999990129F, 0.9999992003F, 0.9999993596F, 0.9999994939F,
  143058. 0.9999996059F, 0.9999996981F, 0.9999997732F, 0.9999998333F,
  143059. 0.9999998805F, 0.9999999170F, 0.9999999444F, 0.9999999643F,
  143060. 0.9999999784F, 0.9999999878F, 0.9999999937F, 0.9999999972F,
  143061. 0.9999999990F, 0.9999999997F, 1.0000000000F, 1.0000000000F,
  143062. };
  143063. static float vwin4096[2048] = {
  143064. 0.0000002310F, 0.0000020791F, 0.0000057754F, 0.0000113197F,
  143065. 0.0000187121F, 0.0000279526F, 0.0000390412F, 0.0000519777F,
  143066. 0.0000667623F, 0.0000833949F, 0.0001018753F, 0.0001222036F,
  143067. 0.0001443798F, 0.0001684037F, 0.0001942754F, 0.0002219947F,
  143068. 0.0002515616F, 0.0002829761F, 0.0003162380F, 0.0003513472F,
  143069. 0.0003883038F, 0.0004271076F, 0.0004677584F, 0.0005102563F,
  143070. 0.0005546011F, 0.0006007928F, 0.0006488311F, 0.0006987160F,
  143071. 0.0007504474F, 0.0008040251F, 0.0008594490F, 0.0009167191F,
  143072. 0.0009758351F, 0.0010367969F, 0.0010996044F, 0.0011642574F,
  143073. 0.0012307558F, 0.0012990994F, 0.0013692880F, 0.0014413216F,
  143074. 0.0015151998F, 0.0015909226F, 0.0016684898F, 0.0017479011F,
  143075. 0.0018291565F, 0.0019122556F, 0.0019971983F, 0.0020839845F,
  143076. 0.0021726138F, 0.0022630861F, 0.0023554012F, 0.0024495588F,
  143077. 0.0025455588F, 0.0026434008F, 0.0027430847F, 0.0028446103F,
  143078. 0.0029479772F, 0.0030531853F, 0.0031602342F, 0.0032691238F,
  143079. 0.0033798538F, 0.0034924239F, 0.0036068338F, 0.0037230833F,
  143080. 0.0038411721F, 0.0039610999F, 0.0040828664F, 0.0042064714F,
  143081. 0.0043319145F, 0.0044591954F, 0.0045883139F, 0.0047192696F,
  143082. 0.0048520622F, 0.0049866914F, 0.0051231569F, 0.0052614583F,
  143083. 0.0054015953F, 0.0055435676F, 0.0056873748F, 0.0058330166F,
  143084. 0.0059804926F, 0.0061298026F, 0.0062809460F, 0.0064339226F,
  143085. 0.0065887320F, 0.0067453738F, 0.0069038476F, 0.0070641531F,
  143086. 0.0072262899F, 0.0073902575F, 0.0075560556F, 0.0077236838F,
  143087. 0.0078931417F, 0.0080644288F, 0.0082375447F, 0.0084124891F,
  143088. 0.0085892615F, 0.0087678614F, 0.0089482885F, 0.0091305422F,
  143089. 0.0093146223F, 0.0095005281F, 0.0096882592F, 0.0098778153F,
  143090. 0.0100691958F, 0.0102624002F, 0.0104574281F, 0.0106542791F,
  143091. 0.0108529525F, 0.0110534480F, 0.0112557651F, 0.0114599032F,
  143092. 0.0116658618F, 0.0118736405F, 0.0120832387F, 0.0122946560F,
  143093. 0.0125078917F, 0.0127229454F, 0.0129398166F, 0.0131585046F,
  143094. 0.0133790090F, 0.0136013292F, 0.0138254647F, 0.0140514149F,
  143095. 0.0142791792F, 0.0145087572F, 0.0147401481F, 0.0149733515F,
  143096. 0.0152083667F, 0.0154451932F, 0.0156838304F, 0.0159242777F,
  143097. 0.0161665345F, 0.0164106001F, 0.0166564741F, 0.0169041557F,
  143098. 0.0171536443F, 0.0174049393F, 0.0176580401F, 0.0179129461F,
  143099. 0.0181696565F, 0.0184281708F, 0.0186884883F, 0.0189506084F,
  143100. 0.0192145303F, 0.0194802535F, 0.0197477772F, 0.0200171008F,
  143101. 0.0202882236F, 0.0205611449F, 0.0208358639F, 0.0211123801F,
  143102. 0.0213906927F, 0.0216708011F, 0.0219527043F, 0.0222364019F,
  143103. 0.0225218930F, 0.0228091769F, 0.0230982529F, 0.0233891203F,
  143104. 0.0236817782F, 0.0239762259F, 0.0242724628F, 0.0245704880F,
  143105. 0.0248703007F, 0.0251719002F, 0.0254752858F, 0.0257804565F,
  143106. 0.0260874117F, 0.0263961506F, 0.0267066722F, 0.0270189760F,
  143107. 0.0273330609F, 0.0276489263F, 0.0279665712F, 0.0282859949F,
  143108. 0.0286071966F, 0.0289301753F, 0.0292549303F, 0.0295814607F,
  143109. 0.0299097656F, 0.0302398442F, 0.0305716957F, 0.0309053191F,
  143110. 0.0312407135F, 0.0315778782F, 0.0319168122F, 0.0322575145F,
  143111. 0.0325999844F, 0.0329442209F, 0.0332902231F, 0.0336379900F,
  143112. 0.0339875208F, 0.0343388146F, 0.0346918703F, 0.0350466871F,
  143113. 0.0354032640F, 0.0357616000F, 0.0361216943F, 0.0364835458F,
  143114. 0.0368471535F, 0.0372125166F, 0.0375796339F, 0.0379485046F,
  143115. 0.0383191276F, 0.0386915020F, 0.0390656267F, 0.0394415008F,
  143116. 0.0398191231F, 0.0401984927F, 0.0405796086F, 0.0409624698F,
  143117. 0.0413470751F, 0.0417334235F, 0.0421215141F, 0.0425113457F,
  143118. 0.0429029172F, 0.0432962277F, 0.0436912760F, 0.0440880610F,
  143119. 0.0444865817F, 0.0448868370F, 0.0452888257F, 0.0456925468F,
  143120. 0.0460979992F, 0.0465051816F, 0.0469140931F, 0.0473247325F,
  143121. 0.0477370986F, 0.0481511902F, 0.0485670064F, 0.0489845458F,
  143122. 0.0494038074F, 0.0498247899F, 0.0502474922F, 0.0506719131F,
  143123. 0.0510980514F, 0.0515259060F, 0.0519554756F, 0.0523867590F,
  143124. 0.0528197550F, 0.0532544624F, 0.0536908800F, 0.0541290066F,
  143125. 0.0545688408F, 0.0550103815F, 0.0554536274F, 0.0558985772F,
  143126. 0.0563452297F, 0.0567935837F, 0.0572436377F, 0.0576953907F,
  143127. 0.0581488412F, 0.0586039880F, 0.0590608297F, 0.0595193651F,
  143128. 0.0599795929F, 0.0604415117F, 0.0609051202F, 0.0613704170F,
  143129. 0.0618374009F, 0.0623060704F, 0.0627764243F, 0.0632484611F,
  143130. 0.0637221795F, 0.0641975781F, 0.0646746555F, 0.0651534104F,
  143131. 0.0656338413F, 0.0661159469F, 0.0665997257F, 0.0670851763F,
  143132. 0.0675722973F, 0.0680610873F, 0.0685515448F, 0.0690436684F,
  143133. 0.0695374567F, 0.0700329081F, 0.0705300213F, 0.0710287947F,
  143134. 0.0715292269F, 0.0720313163F, 0.0725350616F, 0.0730404612F,
  143135. 0.0735475136F, 0.0740562172F, 0.0745665707F, 0.0750785723F,
  143136. 0.0755922207F, 0.0761075143F, 0.0766244515F, 0.0771430307F,
  143137. 0.0776632505F, 0.0781851092F, 0.0787086052F, 0.0792337371F,
  143138. 0.0797605032F, 0.0802889018F, 0.0808189315F, 0.0813505905F,
  143139. 0.0818838773F, 0.0824187903F, 0.0829553277F, 0.0834934881F,
  143140. 0.0840332697F, 0.0845746708F, 0.0851176899F, 0.0856623252F,
  143141. 0.0862085751F, 0.0867564379F, 0.0873059119F, 0.0878569954F,
  143142. 0.0884096867F, 0.0889639840F, 0.0895198858F, 0.0900773902F,
  143143. 0.0906364955F, 0.0911972000F, 0.0917595019F, 0.0923233995F,
  143144. 0.0928888909F, 0.0934559745F, 0.0940246485F, 0.0945949110F,
  143145. 0.0951667604F, 0.0957401946F, 0.0963152121F, 0.0968918109F,
  143146. 0.0974699893F, 0.0980497454F, 0.0986310773F, 0.0992139832F,
  143147. 0.0997984614F, 0.1003845098F, 0.1009721267F, 0.1015613101F,
  143148. 0.1021520582F, 0.1027443692F, 0.1033382410F, 0.1039336718F,
  143149. 0.1045306597F, 0.1051292027F, 0.1057292990F, 0.1063309466F,
  143150. 0.1069341435F, 0.1075388878F, 0.1081451776F, 0.1087530108F,
  143151. 0.1093623856F, 0.1099732998F, 0.1105857516F, 0.1111997389F,
  143152. 0.1118152597F, 0.1124323121F, 0.1130508939F, 0.1136710032F,
  143153. 0.1142926379F, 0.1149157960F, 0.1155404755F, 0.1161666742F,
  143154. 0.1167943901F, 0.1174236211F, 0.1180543652F, 0.1186866202F,
  143155. 0.1193203841F, 0.1199556548F, 0.1205924300F, 0.1212307078F,
  143156. 0.1218704860F, 0.1225117624F, 0.1231545349F, 0.1237988013F,
  143157. 0.1244445596F, 0.1250918074F, 0.1257405427F, 0.1263907632F,
  143158. 0.1270424667F, 0.1276956512F, 0.1283503142F, 0.1290064537F,
  143159. 0.1296640674F, 0.1303231530F, 0.1309837084F, 0.1316457312F,
  143160. 0.1323092193F, 0.1329741703F, 0.1336405820F, 0.1343084520F,
  143161. 0.1349777782F, 0.1356485582F, 0.1363207897F, 0.1369944704F,
  143162. 0.1376695979F, 0.1383461700F, 0.1390241842F, 0.1397036384F,
  143163. 0.1403845300F, 0.1410668567F, 0.1417506162F, 0.1424358061F,
  143164. 0.1431224240F, 0.1438104674F, 0.1444999341F, 0.1451908216F,
  143165. 0.1458831274F, 0.1465768492F, 0.1472719844F, 0.1479685308F,
  143166. 0.1486664857F, 0.1493658468F, 0.1500666115F, 0.1507687775F,
  143167. 0.1514723422F, 0.1521773031F, 0.1528836577F, 0.1535914035F,
  143168. 0.1543005380F, 0.1550110587F, 0.1557229631F, 0.1564362485F,
  143169. 0.1571509124F, 0.1578669524F, 0.1585843657F, 0.1593031499F,
  143170. 0.1600233024F, 0.1607448205F, 0.1614677017F, 0.1621919433F,
  143171. 0.1629175428F, 0.1636444975F, 0.1643728047F, 0.1651024619F,
  143172. 0.1658334665F, 0.1665658156F, 0.1672995067F, 0.1680345371F,
  143173. 0.1687709041F, 0.1695086050F, 0.1702476372F, 0.1709879978F,
  143174. 0.1717296843F, 0.1724726938F, 0.1732170237F, 0.1739626711F,
  143175. 0.1747096335F, 0.1754579079F, 0.1762074916F, 0.1769583819F,
  143176. 0.1777105760F, 0.1784640710F, 0.1792188642F, 0.1799749529F,
  143177. 0.1807323340F, 0.1814910049F, 0.1822509628F, 0.1830122046F,
  143178. 0.1837747277F, 0.1845385292F, 0.1853036062F, 0.1860699558F,
  143179. 0.1868375751F, 0.1876064613F, 0.1883766114F, 0.1891480226F,
  143180. 0.1899206919F, 0.1906946164F, 0.1914697932F, 0.1922462194F,
  143181. 0.1930238919F, 0.1938028079F, 0.1945829643F, 0.1953643583F,
  143182. 0.1961469868F, 0.1969308468F, 0.1977159353F, 0.1985022494F,
  143183. 0.1992897859F, 0.2000785420F, 0.2008685145F, 0.2016597005F,
  143184. 0.2024520968F, 0.2032457005F, 0.2040405084F, 0.2048365175F,
  143185. 0.2056337247F, 0.2064321269F, 0.2072317211F, 0.2080325041F,
  143186. 0.2088344727F, 0.2096376240F, 0.2104419547F, 0.2112474618F,
  143187. 0.2120541420F, 0.2128619923F, 0.2136710094F, 0.2144811902F,
  143188. 0.2152925315F, 0.2161050301F, 0.2169186829F, 0.2177334866F,
  143189. 0.2185494381F, 0.2193665340F, 0.2201847712F, 0.2210041465F,
  143190. 0.2218246565F, 0.2226462981F, 0.2234690680F, 0.2242929629F,
  143191. 0.2251179796F, 0.2259441147F, 0.2267713650F, 0.2275997272F,
  143192. 0.2284291979F, 0.2292597739F, 0.2300914518F, 0.2309242283F,
  143193. 0.2317581001F, 0.2325930638F, 0.2334291160F, 0.2342662534F,
  143194. 0.2351044727F, 0.2359437703F, 0.2367841431F, 0.2376255875F,
  143195. 0.2384681001F, 0.2393116776F, 0.2401563165F, 0.2410020134F,
  143196. 0.2418487649F, 0.2426965675F, 0.2435454178F, 0.2443953122F,
  143197. 0.2452462474F, 0.2460982199F, 0.2469512262F, 0.2478052628F,
  143198. 0.2486603262F, 0.2495164129F, 0.2503735194F, 0.2512316421F,
  143199. 0.2520907776F, 0.2529509222F, 0.2538120726F, 0.2546742250F,
  143200. 0.2555373760F, 0.2564015219F, 0.2572666593F, 0.2581327845F,
  143201. 0.2589998939F, 0.2598679840F, 0.2607370510F, 0.2616070916F,
  143202. 0.2624781019F, 0.2633500783F, 0.2642230173F, 0.2650969152F,
  143203. 0.2659717684F, 0.2668475731F, 0.2677243257F, 0.2686020226F,
  143204. 0.2694806601F, 0.2703602344F, 0.2712407419F, 0.2721221789F,
  143205. 0.2730045417F, 0.2738878265F, 0.2747720297F, 0.2756571474F,
  143206. 0.2765431760F, 0.2774301117F, 0.2783179508F, 0.2792066895F,
  143207. 0.2800963240F, 0.2809868505F, 0.2818782654F, 0.2827705647F,
  143208. 0.2836637447F, 0.2845578016F, 0.2854527315F, 0.2863485307F,
  143209. 0.2872451953F, 0.2881427215F, 0.2890411055F, 0.2899403433F,
  143210. 0.2908404312F, 0.2917413654F, 0.2926431418F, 0.2935457567F,
  143211. 0.2944492061F, 0.2953534863F, 0.2962585932F, 0.2971645230F,
  143212. 0.2980712717F, 0.2989788356F, 0.2998872105F, 0.3007963927F,
  143213. 0.3017063781F, 0.3026171629F, 0.3035287430F, 0.3044411145F,
  143214. 0.3053542736F, 0.3062682161F, 0.3071829381F, 0.3080984356F,
  143215. 0.3090147047F, 0.3099317413F, 0.3108495414F, 0.3117681011F,
  143216. 0.3126874163F, 0.3136074830F, 0.3145282972F, 0.3154498548F,
  143217. 0.3163721517F, 0.3172951841F, 0.3182189477F, 0.3191434385F,
  143218. 0.3200686525F, 0.3209945856F, 0.3219212336F, 0.3228485927F,
  143219. 0.3237766585F, 0.3247054271F, 0.3256348943F, 0.3265650560F,
  143220. 0.3274959081F, 0.3284274465F, 0.3293596671F, 0.3302925657F,
  143221. 0.3312261382F, 0.3321603804F, 0.3330952882F, 0.3340308574F,
  143222. 0.3349670838F, 0.3359039634F, 0.3368414919F, 0.3377796651F,
  143223. 0.3387184789F, 0.3396579290F, 0.3405980113F, 0.3415387216F,
  143224. 0.3424800556F, 0.3434220091F, 0.3443645779F, 0.3453077578F,
  143225. 0.3462515446F, 0.3471959340F, 0.3481409217F, 0.3490865036F,
  143226. 0.3500326754F, 0.3509794328F, 0.3519267715F, 0.3528746873F,
  143227. 0.3538231759F, 0.3547722330F, 0.3557218544F, 0.3566720357F,
  143228. 0.3576227727F, 0.3585740610F, 0.3595258964F, 0.3604782745F,
  143229. 0.3614311910F, 0.3623846417F, 0.3633386221F, 0.3642931280F,
  143230. 0.3652481549F, 0.3662036987F, 0.3671597548F, 0.3681163191F,
  143231. 0.3690733870F, 0.3700309544F, 0.3709890167F, 0.3719475696F,
  143232. 0.3729066089F, 0.3738661299F, 0.3748261285F, 0.3757866002F,
  143233. 0.3767475406F, 0.3777089453F, 0.3786708100F, 0.3796331302F,
  143234. 0.3805959014F, 0.3815591194F, 0.3825227796F, 0.3834868777F,
  143235. 0.3844514093F, 0.3854163698F, 0.3863817549F, 0.3873475601F,
  143236. 0.3883137810F, 0.3892804131F, 0.3902474521F, 0.3912148933F,
  143237. 0.3921827325F, 0.3931509650F, 0.3941195865F, 0.3950885925F,
  143238. 0.3960579785F, 0.3970277400F, 0.3979978725F, 0.3989683716F,
  143239. 0.3999392328F, 0.4009104516F, 0.4018820234F, 0.4028539438F,
  143240. 0.4038262084F, 0.4047988125F, 0.4057717516F, 0.4067450214F,
  143241. 0.4077186172F, 0.4086925345F, 0.4096667688F, 0.4106413155F,
  143242. 0.4116161703F, 0.4125913284F, 0.4135667854F, 0.4145425368F,
  143243. 0.4155185780F, 0.4164949044F, 0.4174715116F, 0.4184483949F,
  143244. 0.4194255498F, 0.4204029718F, 0.4213806563F, 0.4223585987F,
  143245. 0.4233367946F, 0.4243152392F, 0.4252939281F, 0.4262728566F,
  143246. 0.4272520202F, 0.4282314144F, 0.4292110345F, 0.4301908760F,
  143247. 0.4311709343F, 0.4321512047F, 0.4331316828F, 0.4341123639F,
  143248. 0.4350932435F, 0.4360743168F, 0.4370555794F, 0.4380370267F,
  143249. 0.4390186540F, 0.4400004567F, 0.4409824303F, 0.4419645701F,
  143250. 0.4429468716F, 0.4439293300F, 0.4449119409F, 0.4458946996F,
  143251. 0.4468776014F, 0.4478606418F, 0.4488438162F, 0.4498271199F,
  143252. 0.4508105483F, 0.4517940967F, 0.4527777607F, 0.4537615355F,
  143253. 0.4547454165F, 0.4557293991F, 0.4567134786F, 0.4576976505F,
  143254. 0.4586819101F, 0.4596662527F, 0.4606506738F, 0.4616351687F,
  143255. 0.4626197328F, 0.4636043614F, 0.4645890499F, 0.4655737936F,
  143256. 0.4665585880F, 0.4675434284F, 0.4685283101F, 0.4695132286F,
  143257. 0.4704981791F, 0.4714831570F, 0.4724681577F, 0.4734531766F,
  143258. 0.4744382089F, 0.4754232501F, 0.4764082956F, 0.4773933406F,
  143259. 0.4783783806F, 0.4793634108F, 0.4803484267F, 0.4813334237F,
  143260. 0.4823183969F, 0.4833033419F, 0.4842882540F, 0.4852731285F,
  143261. 0.4862579608F, 0.4872427462F, 0.4882274802F, 0.4892121580F,
  143262. 0.4901967751F, 0.4911813267F, 0.4921658083F, 0.4931502151F,
  143263. 0.4941345427F, 0.4951187863F, 0.4961029412F, 0.4970870029F,
  143264. 0.4980709667F, 0.4990548280F, 0.5000385822F, 0.5010222245F,
  143265. 0.5020057505F, 0.5029891553F, 0.5039724345F, 0.5049555834F,
  143266. 0.5059385973F, 0.5069214716F, 0.5079042018F, 0.5088867831F,
  143267. 0.5098692110F, 0.5108514808F, 0.5118335879F, 0.5128155277F,
  143268. 0.5137972956F, 0.5147788869F, 0.5157602971F, 0.5167415215F,
  143269. 0.5177225555F, 0.5187033945F, 0.5196840339F, 0.5206644692F,
  143270. 0.5216446956F, 0.5226247086F, 0.5236045035F, 0.5245840759F,
  143271. 0.5255634211F, 0.5265425344F, 0.5275214114F, 0.5285000474F,
  143272. 0.5294784378F, 0.5304565781F, 0.5314344637F, 0.5324120899F,
  143273. 0.5333894522F, 0.5343665461F, 0.5353433670F, 0.5363199102F,
  143274. 0.5372961713F, 0.5382721457F, 0.5392478287F, 0.5402232159F,
  143275. 0.5411983027F, 0.5421730845F, 0.5431475569F, 0.5441217151F,
  143276. 0.5450955548F, 0.5460690714F, 0.5470422602F, 0.5480151169F,
  143277. 0.5489876368F, 0.5499598155F, 0.5509316484F, 0.5519031310F,
  143278. 0.5528742587F, 0.5538450271F, 0.5548154317F, 0.5557854680F,
  143279. 0.5567551314F, 0.5577244174F, 0.5586933216F, 0.5596618395F,
  143280. 0.5606299665F, 0.5615976983F, 0.5625650302F, 0.5635319580F,
  143281. 0.5644984770F, 0.5654645828F, 0.5664302709F, 0.5673955370F,
  143282. 0.5683603765F, 0.5693247850F, 0.5702887580F, 0.5712522912F,
  143283. 0.5722153800F, 0.5731780200F, 0.5741402069F, 0.5751019362F,
  143284. 0.5760632034F, 0.5770240042F, 0.5779843341F, 0.5789441889F,
  143285. 0.5799035639F, 0.5808624549F, 0.5818208575F, 0.5827787673F,
  143286. 0.5837361800F, 0.5846930910F, 0.5856494961F, 0.5866053910F,
  143287. 0.5875607712F, 0.5885156324F, 0.5894699703F, 0.5904237804F,
  143288. 0.5913770586F, 0.5923298004F, 0.5932820016F, 0.5942336578F,
  143289. 0.5951847646F, 0.5961353179F, 0.5970853132F, 0.5980347464F,
  143290. 0.5989836131F, 0.5999319090F, 0.6008796298F, 0.6018267713F,
  143291. 0.6027733292F, 0.6037192993F, 0.6046646773F, 0.6056094589F,
  143292. 0.6065536400F, 0.6074972162F, 0.6084401833F, 0.6093825372F,
  143293. 0.6103242736F, 0.6112653884F, 0.6122058772F, 0.6131457359F,
  143294. 0.6140849604F, 0.6150235464F, 0.6159614897F, 0.6168987862F,
  143295. 0.6178354318F, 0.6187714223F, 0.6197067535F, 0.6206414213F,
  143296. 0.6215754215F, 0.6225087501F, 0.6234414028F, 0.6243733757F,
  143297. 0.6253046646F, 0.6262352654F, 0.6271651739F, 0.6280943862F,
  143298. 0.6290228982F, 0.6299507057F, 0.6308778048F, 0.6318041913F,
  143299. 0.6327298612F, 0.6336548105F, 0.6345790352F, 0.6355025312F,
  143300. 0.6364252945F, 0.6373473211F, 0.6382686070F, 0.6391891483F,
  143301. 0.6401089409F, 0.6410279808F, 0.6419462642F, 0.6428637869F,
  143302. 0.6437805452F, 0.6446965350F, 0.6456117524F, 0.6465261935F,
  143303. 0.6474398544F, 0.6483527311F, 0.6492648197F, 0.6501761165F,
  143304. 0.6510866174F, 0.6519963186F, 0.6529052162F, 0.6538133064F,
  143305. 0.6547205854F, 0.6556270492F, 0.6565326941F, 0.6574375162F,
  143306. 0.6583415117F, 0.6592446769F, 0.6601470079F, 0.6610485009F,
  143307. 0.6619491521F, 0.6628489578F, 0.6637479143F, 0.6646460177F,
  143308. 0.6655432643F, 0.6664396505F, 0.6673351724F, 0.6682298264F,
  143309. 0.6691236087F, 0.6700165157F, 0.6709085436F, 0.6717996889F,
  143310. 0.6726899478F, 0.6735793167F, 0.6744677918F, 0.6753553697F,
  143311. 0.6762420466F, 0.6771278190F, 0.6780126832F, 0.6788966357F,
  143312. 0.6797796728F, 0.6806617909F, 0.6815429866F, 0.6824232562F,
  143313. 0.6833025961F, 0.6841810030F, 0.6850584731F, 0.6859350031F,
  143314. 0.6868105894F, 0.6876852284F, 0.6885589168F, 0.6894316510F,
  143315. 0.6903034275F, 0.6911742430F, 0.6920440939F, 0.6929129769F,
  143316. 0.6937808884F, 0.6946478251F, 0.6955137837F, 0.6963787606F,
  143317. 0.6972427525F, 0.6981057560F, 0.6989677678F, 0.6998287845F,
  143318. 0.7006888028F, 0.7015478194F, 0.7024058309F, 0.7032628340F,
  143319. 0.7041188254F, 0.7049738019F, 0.7058277601F, 0.7066806969F,
  143320. 0.7075326089F, 0.7083834929F, 0.7092333457F, 0.7100821640F,
  143321. 0.7109299447F, 0.7117766846F, 0.7126223804F, 0.7134670291F,
  143322. 0.7143106273F, 0.7151531721F, 0.7159946602F, 0.7168350885F,
  143323. 0.7176744539F, 0.7185127534F, 0.7193499837F, 0.7201861418F,
  143324. 0.7210212247F, 0.7218552293F, 0.7226881526F, 0.7235199914F,
  143325. 0.7243507428F, 0.7251804039F, 0.7260089715F, 0.7268364426F,
  143326. 0.7276628144F, 0.7284880839F, 0.7293122481F, 0.7301353040F,
  143327. 0.7309572487F, 0.7317780794F, 0.7325977930F, 0.7334163868F,
  143328. 0.7342338579F, 0.7350502033F, 0.7358654202F, 0.7366795059F,
  143329. 0.7374924573F, 0.7383042718F, 0.7391149465F, 0.7399244787F,
  143330. 0.7407328655F, 0.7415401041F, 0.7423461920F, 0.7431511261F,
  143331. 0.7439549040F, 0.7447575227F, 0.7455589797F, 0.7463592723F,
  143332. 0.7471583976F, 0.7479563532F, 0.7487531363F, 0.7495487443F,
  143333. 0.7503431745F, 0.7511364244F, 0.7519284913F, 0.7527193726F,
  143334. 0.7535090658F, 0.7542975683F, 0.7550848776F, 0.7558709910F,
  143335. 0.7566559062F, 0.7574396205F, 0.7582221314F, 0.7590034366F,
  143336. 0.7597835334F, 0.7605624194F, 0.7613400923F, 0.7621165495F,
  143337. 0.7628917886F, 0.7636658072F, 0.7644386030F, 0.7652101735F,
  143338. 0.7659805164F, 0.7667496292F, 0.7675175098F, 0.7682841556F,
  143339. 0.7690495645F, 0.7698137341F, 0.7705766622F, 0.7713383463F,
  143340. 0.7720987844F, 0.7728579741F, 0.7736159132F, 0.7743725994F,
  143341. 0.7751280306F, 0.7758822046F, 0.7766351192F, 0.7773867722F,
  143342. 0.7781371614F, 0.7788862848F, 0.7796341401F, 0.7803807253F,
  143343. 0.7811260383F, 0.7818700769F, 0.7826128392F, 0.7833543230F,
  143344. 0.7840945263F, 0.7848334471F, 0.7855710833F, 0.7863074330F,
  143345. 0.7870424941F, 0.7877762647F, 0.7885087428F, 0.7892399264F,
  143346. 0.7899698137F, 0.7906984026F, 0.7914256914F, 0.7921516780F,
  143347. 0.7928763607F, 0.7935997375F, 0.7943218065F, 0.7950425661F,
  143348. 0.7957620142F, 0.7964801492F, 0.7971969692F, 0.7979124724F,
  143349. 0.7986266570F, 0.7993395214F, 0.8000510638F, 0.8007612823F,
  143350. 0.8014701754F, 0.8021777413F, 0.8028839784F, 0.8035888849F,
  143351. 0.8042924592F, 0.8049946997F, 0.8056956048F, 0.8063951727F,
  143352. 0.8070934020F, 0.8077902910F, 0.8084858381F, 0.8091800419F,
  143353. 0.8098729007F, 0.8105644130F, 0.8112545774F, 0.8119433922F,
  143354. 0.8126308561F, 0.8133169676F, 0.8140017251F, 0.8146851272F,
  143355. 0.8153671726F, 0.8160478598F, 0.8167271874F, 0.8174051539F,
  143356. 0.8180817582F, 0.8187569986F, 0.8194308741F, 0.8201033831F,
  143357. 0.8207745244F, 0.8214442966F, 0.8221126986F, 0.8227797290F,
  143358. 0.8234453865F, 0.8241096700F, 0.8247725781F, 0.8254341097F,
  143359. 0.8260942636F, 0.8267530385F, 0.8274104334F, 0.8280664470F,
  143360. 0.8287210782F, 0.8293743259F, 0.8300261889F, 0.8306766662F,
  143361. 0.8313257566F, 0.8319734591F, 0.8326197727F, 0.8332646963F,
  143362. 0.8339082288F, 0.8345503692F, 0.8351911167F, 0.8358304700F,
  143363. 0.8364684284F, 0.8371049907F, 0.8377401562F, 0.8383739238F,
  143364. 0.8390062927F, 0.8396372618F, 0.8402668305F, 0.8408949977F,
  143365. 0.8415217626F, 0.8421471245F, 0.8427710823F, 0.8433936354F,
  143366. 0.8440147830F, 0.8446345242F, 0.8452528582F, 0.8458697844F,
  143367. 0.8464853020F, 0.8470994102F, 0.8477121084F, 0.8483233958F,
  143368. 0.8489332718F, 0.8495417356F, 0.8501487866F, 0.8507544243F,
  143369. 0.8513586479F, 0.8519614568F, 0.8525628505F, 0.8531628283F,
  143370. 0.8537613897F, 0.8543585341F, 0.8549542611F, 0.8555485699F,
  143371. 0.8561414603F, 0.8567329315F, 0.8573229832F, 0.8579116149F,
  143372. 0.8584988262F, 0.8590846165F, 0.8596689855F, 0.8602519327F,
  143373. 0.8608334577F, 0.8614135603F, 0.8619922399F, 0.8625694962F,
  143374. 0.8631453289F, 0.8637197377F, 0.8642927222F, 0.8648642821F,
  143375. 0.8654344172F, 0.8660031272F, 0.8665704118F, 0.8671362708F,
  143376. 0.8677007039F, 0.8682637109F, 0.8688252917F, 0.8693854460F,
  143377. 0.8699441737F, 0.8705014745F, 0.8710573485F, 0.8716117953F,
  143378. 0.8721648150F, 0.8727164073F, 0.8732665723F, 0.8738153098F,
  143379. 0.8743626197F, 0.8749085021F, 0.8754529569F, 0.8759959840F,
  143380. 0.8765375835F, 0.8770777553F, 0.8776164996F, 0.8781538162F,
  143381. 0.8786897054F, 0.8792241670F, 0.8797572013F, 0.8802888082F,
  143382. 0.8808189880F, 0.8813477407F, 0.8818750664F, 0.8824009653F,
  143383. 0.8829254375F, 0.8834484833F, 0.8839701028F, 0.8844902961F,
  143384. 0.8850090636F, 0.8855264054F, 0.8860423218F, 0.8865568131F,
  143385. 0.8870698794F, 0.8875815212F, 0.8880917386F, 0.8886005319F,
  143386. 0.8891079016F, 0.8896138479F, 0.8901183712F, 0.8906214719F,
  143387. 0.8911231503F, 0.8916234067F, 0.8921222417F, 0.8926196556F,
  143388. 0.8931156489F, 0.8936102219F, 0.8941033752F, 0.8945951092F,
  143389. 0.8950854244F, 0.8955743212F, 0.8960618003F, 0.8965478621F,
  143390. 0.8970325071F, 0.8975157359F, 0.8979975490F, 0.8984779471F,
  143391. 0.8989569307F, 0.8994345004F, 0.8999106568F, 0.9003854005F,
  143392. 0.9008587323F, 0.9013306526F, 0.9018011623F, 0.9022702619F,
  143393. 0.9027379521F, 0.9032042337F, 0.9036691074F, 0.9041325739F,
  143394. 0.9045946339F, 0.9050552882F, 0.9055145376F, 0.9059723828F,
  143395. 0.9064288246F, 0.9068838638F, 0.9073375013F, 0.9077897379F,
  143396. 0.9082405743F, 0.9086900115F, 0.9091380503F, 0.9095846917F,
  143397. 0.9100299364F, 0.9104737854F, 0.9109162397F, 0.9113573001F,
  143398. 0.9117969675F, 0.9122352430F, 0.9126721275F, 0.9131076219F,
  143399. 0.9135417273F, 0.9139744447F, 0.9144057750F, 0.9148357194F,
  143400. 0.9152642787F, 0.9156914542F, 0.9161172468F, 0.9165416576F,
  143401. 0.9169646877F, 0.9173863382F, 0.9178066102F, 0.9182255048F,
  143402. 0.9186430232F, 0.9190591665F, 0.9194739359F, 0.9198873324F,
  143403. 0.9202993574F, 0.9207100120F, 0.9211192973F, 0.9215272147F,
  143404. 0.9219337653F, 0.9223389504F, 0.9227427713F, 0.9231452290F,
  143405. 0.9235463251F, 0.9239460607F, 0.9243444371F, 0.9247414557F,
  143406. 0.9251371177F, 0.9255314245F, 0.9259243774F, 0.9263159778F,
  143407. 0.9267062270F, 0.9270951264F, 0.9274826774F, 0.9278688814F,
  143408. 0.9282537398F, 0.9286372540F, 0.9290194254F, 0.9294002555F,
  143409. 0.9297797458F, 0.9301578976F, 0.9305347125F, 0.9309101919F,
  143410. 0.9312843373F, 0.9316571503F, 0.9320286323F, 0.9323987849F,
  143411. 0.9327676097F, 0.9331351080F, 0.9335012816F, 0.9338661320F,
  143412. 0.9342296607F, 0.9345918694F, 0.9349527596F, 0.9353123330F,
  143413. 0.9356705911F, 0.9360275357F, 0.9363831683F, 0.9367374905F,
  143414. 0.9370905042F, 0.9374422108F, 0.9377926122F, 0.9381417099F,
  143415. 0.9384895057F, 0.9388360014F, 0.9391811985F, 0.9395250989F,
  143416. 0.9398677043F, 0.9402090165F, 0.9405490371F, 0.9408877680F,
  143417. 0.9412252110F, 0.9415613678F, 0.9418962402F, 0.9422298301F,
  143418. 0.9425621392F, 0.9428931695F, 0.9432229226F, 0.9435514005F,
  143419. 0.9438786050F, 0.9442045381F, 0.9445292014F, 0.9448525971F,
  143420. 0.9451747268F, 0.9454955926F, 0.9458151963F, 0.9461335399F,
  143421. 0.9464506253F, 0.9467664545F, 0.9470810293F, 0.9473943517F,
  143422. 0.9477064238F, 0.9480172474F, 0.9483268246F, 0.9486351573F,
  143423. 0.9489422475F, 0.9492480973F, 0.9495527087F, 0.9498560837F,
  143424. 0.9501582243F, 0.9504591325F, 0.9507588105F, 0.9510572603F,
  143425. 0.9513544839F, 0.9516504834F, 0.9519452609F, 0.9522388186F,
  143426. 0.9525311584F, 0.9528222826F, 0.9531121932F, 0.9534008923F,
  143427. 0.9536883821F, 0.9539746647F, 0.9542597424F, 0.9545436171F,
  143428. 0.9548262912F, 0.9551077667F, 0.9553880459F, 0.9556671309F,
  143429. 0.9559450239F, 0.9562217272F, 0.9564972429F, 0.9567715733F,
  143430. 0.9570447206F, 0.9573166871F, 0.9575874749F, 0.9578570863F,
  143431. 0.9581255236F, 0.9583927890F, 0.9586588849F, 0.9589238134F,
  143432. 0.9591875769F, 0.9594501777F, 0.9597116180F, 0.9599719003F,
  143433. 0.9602310267F, 0.9604889995F, 0.9607458213F, 0.9610014942F,
  143434. 0.9612560206F, 0.9615094028F, 0.9617616433F, 0.9620127443F,
  143435. 0.9622627083F, 0.9625115376F, 0.9627592345F, 0.9630058016F,
  143436. 0.9632512411F, 0.9634955555F, 0.9637387471F, 0.9639808185F,
  143437. 0.9642217720F, 0.9644616100F, 0.9647003349F, 0.9649379493F,
  143438. 0.9651744556F, 0.9654098561F, 0.9656441534F, 0.9658773499F,
  143439. 0.9661094480F, 0.9663404504F, 0.9665703593F, 0.9667991774F,
  143440. 0.9670269071F, 0.9672535509F, 0.9674791114F, 0.9677035909F,
  143441. 0.9679269921F, 0.9681493174F, 0.9683705694F, 0.9685907506F,
  143442. 0.9688098636F, 0.9690279108F, 0.9692448948F, 0.9694608182F,
  143443. 0.9696756836F, 0.9698894934F, 0.9701022503F, 0.9703139569F,
  143444. 0.9705246156F, 0.9707342291F, 0.9709428000F, 0.9711503309F,
  143445. 0.9713568243F, 0.9715622829F, 0.9717667093F, 0.9719701060F,
  143446. 0.9721724757F, 0.9723738210F, 0.9725741446F, 0.9727734490F,
  143447. 0.9729717369F, 0.9731690109F, 0.9733652737F, 0.9735605279F,
  143448. 0.9737547762F, 0.9739480212F, 0.9741402656F, 0.9743315120F,
  143449. 0.9745217631F, 0.9747110216F, 0.9748992901F, 0.9750865714F,
  143450. 0.9752728681F, 0.9754581829F, 0.9756425184F, 0.9758258775F,
  143451. 0.9760082627F, 0.9761896768F, 0.9763701224F, 0.9765496024F,
  143452. 0.9767281193F, 0.9769056760F, 0.9770822751F, 0.9772579193F,
  143453. 0.9774326114F, 0.9776063542F, 0.9777791502F, 0.9779510023F,
  143454. 0.9781219133F, 0.9782918858F, 0.9784609226F, 0.9786290264F,
  143455. 0.9787962000F, 0.9789624461F, 0.9791277676F, 0.9792921671F,
  143456. 0.9794556474F, 0.9796182113F, 0.9797798615F, 0.9799406009F,
  143457. 0.9801004321F, 0.9802593580F, 0.9804173813F, 0.9805745049F,
  143458. 0.9807307314F, 0.9808860637F, 0.9810405046F, 0.9811940568F,
  143459. 0.9813467232F, 0.9814985065F, 0.9816494095F, 0.9817994351F,
  143460. 0.9819485860F, 0.9820968650F, 0.9822442750F, 0.9823908186F,
  143461. 0.9825364988F, 0.9826813184F, 0.9828252801F, 0.9829683868F,
  143462. 0.9831106413F, 0.9832520463F, 0.9833926048F, 0.9835323195F,
  143463. 0.9836711932F, 0.9838092288F, 0.9839464291F, 0.9840827969F,
  143464. 0.9842183351F, 0.9843530464F, 0.9844869337F, 0.9846199998F,
  143465. 0.9847522475F, 0.9848836798F, 0.9850142993F, 0.9851441090F,
  143466. 0.9852731117F, 0.9854013101F, 0.9855287073F, 0.9856553058F,
  143467. 0.9857811087F, 0.9859061188F, 0.9860303388F, 0.9861537717F,
  143468. 0.9862764202F, 0.9863982872F, 0.9865193756F, 0.9866396882F,
  143469. 0.9867592277F, 0.9868779972F, 0.9869959993F, 0.9871132370F,
  143470. 0.9872297131F, 0.9873454304F, 0.9874603918F, 0.9875746001F,
  143471. 0.9876880581F, 0.9878007688F, 0.9879127348F, 0.9880239592F,
  143472. 0.9881344447F, 0.9882441941F, 0.9883532104F, 0.9884614962F,
  143473. 0.9885690546F, 0.9886758883F, 0.9887820001F, 0.9888873930F,
  143474. 0.9889920697F, 0.9890960331F, 0.9891992859F, 0.9893018312F,
  143475. 0.9894036716F, 0.9895048100F, 0.9896052493F, 0.9897049923F,
  143476. 0.9898040418F, 0.9899024006F, 0.9900000717F, 0.9900970577F,
  143477. 0.9901933616F, 0.9902889862F, 0.9903839343F, 0.9904782087F,
  143478. 0.9905718122F, 0.9906647477F, 0.9907570180F, 0.9908486259F,
  143479. 0.9909395742F, 0.9910298658F, 0.9911195034F, 0.9912084899F,
  143480. 0.9912968281F, 0.9913845208F, 0.9914715708F, 0.9915579810F,
  143481. 0.9916437540F, 0.9917288928F, 0.9918134001F, 0.9918972788F,
  143482. 0.9919805316F, 0.9920631613F, 0.9921451707F, 0.9922265626F,
  143483. 0.9923073399F, 0.9923875052F, 0.9924670615F, 0.9925460114F,
  143484. 0.9926243577F, 0.9927021033F, 0.9927792508F, 0.9928558032F,
  143485. 0.9929317631F, 0.9930071333F, 0.9930819167F, 0.9931561158F,
  143486. 0.9932297337F, 0.9933027728F, 0.9933752362F, 0.9934471264F,
  143487. 0.9935184462F, 0.9935891985F, 0.9936593859F, 0.9937290112F,
  143488. 0.9937980771F, 0.9938665864F, 0.9939345418F, 0.9940019460F,
  143489. 0.9940688018F, 0.9941351118F, 0.9942008789F, 0.9942661057F,
  143490. 0.9943307950F, 0.9943949494F, 0.9944585717F, 0.9945216645F,
  143491. 0.9945842307F, 0.9946462728F, 0.9947077936F, 0.9947687957F,
  143492. 0.9948292820F, 0.9948892550F, 0.9949487174F, 0.9950076719F,
  143493. 0.9950661212F, 0.9951240679F, 0.9951815148F, 0.9952384645F,
  143494. 0.9952949196F, 0.9953508828F, 0.9954063568F, 0.9954613442F,
  143495. 0.9955158476F, 0.9955698697F, 0.9956234132F, 0.9956764806F,
  143496. 0.9957290746F, 0.9957811978F, 0.9958328528F, 0.9958840423F,
  143497. 0.9959347688F, 0.9959850351F, 0.9960348435F, 0.9960841969F,
  143498. 0.9961330977F, 0.9961815486F, 0.9962295521F, 0.9962771108F,
  143499. 0.9963242274F, 0.9963709043F, 0.9964171441F, 0.9964629494F,
  143500. 0.9965083228F, 0.9965532668F, 0.9965977840F, 0.9966418768F,
  143501. 0.9966855479F, 0.9967287998F, 0.9967716350F, 0.9968140559F,
  143502. 0.9968560653F, 0.9968976655F, 0.9969388591F, 0.9969796485F,
  143503. 0.9970200363F, 0.9970600250F, 0.9970996170F, 0.9971388149F,
  143504. 0.9971776211F, 0.9972160380F, 0.9972540683F, 0.9972917142F,
  143505. 0.9973289783F, 0.9973658631F, 0.9974023709F, 0.9974385042F,
  143506. 0.9974742655F, 0.9975096571F, 0.9975446816F, 0.9975793413F,
  143507. 0.9976136386F, 0.9976475759F, 0.9976811557F, 0.9977143803F,
  143508. 0.9977472521F, 0.9977797736F, 0.9978119470F, 0.9978437748F,
  143509. 0.9978752593F, 0.9979064029F, 0.9979372079F, 0.9979676768F,
  143510. 0.9979978117F, 0.9980276151F, 0.9980570893F, 0.9980862367F,
  143511. 0.9981150595F, 0.9981435600F, 0.9981717406F, 0.9981996035F,
  143512. 0.9982271511F, 0.9982543856F, 0.9982813093F, 0.9983079246F,
  143513. 0.9983342336F, 0.9983602386F, 0.9983859418F, 0.9984113456F,
  143514. 0.9984364522F, 0.9984612638F, 0.9984857825F, 0.9985100108F,
  143515. 0.9985339507F, 0.9985576044F, 0.9985809743F, 0.9986040624F,
  143516. 0.9986268710F, 0.9986494022F, 0.9986716583F, 0.9986936413F,
  143517. 0.9987153535F, 0.9987367969F, 0.9987579738F, 0.9987788864F,
  143518. 0.9987995366F, 0.9988199267F, 0.9988400587F, 0.9988599348F,
  143519. 0.9988795572F, 0.9988989278F, 0.9989180487F, 0.9989369222F,
  143520. 0.9989555501F, 0.9989739347F, 0.9989920780F, 0.9990099820F,
  143521. 0.9990276487F, 0.9990450803F, 0.9990622787F, 0.9990792460F,
  143522. 0.9990959841F, 0.9991124952F, 0.9991287812F, 0.9991448440F,
  143523. 0.9991606858F, 0.9991763084F, 0.9991917139F, 0.9992069042F,
  143524. 0.9992218813F, 0.9992366471F, 0.9992512035F, 0.9992655525F,
  143525. 0.9992796961F, 0.9992936361F, 0.9993073744F, 0.9993209131F,
  143526. 0.9993342538F, 0.9993473987F, 0.9993603494F, 0.9993731080F,
  143527. 0.9993856762F, 0.9993980559F, 0.9994102490F, 0.9994222573F,
  143528. 0.9994340827F, 0.9994457269F, 0.9994571918F, 0.9994684793F,
  143529. 0.9994795910F, 0.9994905288F, 0.9995012945F, 0.9995118898F,
  143530. 0.9995223165F, 0.9995325765F, 0.9995426713F, 0.9995526029F,
  143531. 0.9995623728F, 0.9995719829F, 0.9995814349F, 0.9995907304F,
  143532. 0.9995998712F, 0.9996088590F, 0.9996176954F, 0.9996263821F,
  143533. 0.9996349208F, 0.9996433132F, 0.9996515609F, 0.9996596656F,
  143534. 0.9996676288F, 0.9996754522F, 0.9996831375F, 0.9996906862F,
  143535. 0.9996981000F, 0.9997053804F, 0.9997125290F, 0.9997195474F,
  143536. 0.9997264371F, 0.9997331998F, 0.9997398369F, 0.9997463500F,
  143537. 0.9997527406F, 0.9997590103F, 0.9997651606F, 0.9997711930F,
  143538. 0.9997771089F, 0.9997829098F, 0.9997885973F, 0.9997941728F,
  143539. 0.9997996378F, 0.9998049936F, 0.9998102419F, 0.9998153839F,
  143540. 0.9998204211F, 0.9998253550F, 0.9998301868F, 0.9998349182F,
  143541. 0.9998395503F, 0.9998440847F, 0.9998485226F, 0.9998528654F,
  143542. 0.9998571146F, 0.9998612713F, 0.9998653370F, 0.9998693130F,
  143543. 0.9998732007F, 0.9998770012F, 0.9998807159F, 0.9998843461F,
  143544. 0.9998878931F, 0.9998913581F, 0.9998947424F, 0.9998980473F,
  143545. 0.9999012740F, 0.9999044237F, 0.9999074976F, 0.9999104971F,
  143546. 0.9999134231F, 0.9999162771F, 0.9999190601F, 0.9999217733F,
  143547. 0.9999244179F, 0.9999269950F, 0.9999295058F, 0.9999319515F,
  143548. 0.9999343332F, 0.9999366519F, 0.9999389088F, 0.9999411050F,
  143549. 0.9999432416F, 0.9999453196F, 0.9999473402F, 0.9999493044F,
  143550. 0.9999512132F, 0.9999530677F, 0.9999548690F, 0.9999566180F,
  143551. 0.9999583157F, 0.9999599633F, 0.9999615616F, 0.9999631116F,
  143552. 0.9999646144F, 0.9999660709F, 0.9999674820F, 0.9999688487F,
  143553. 0.9999701719F, 0.9999714526F, 0.9999726917F, 0.9999738900F,
  143554. 0.9999750486F, 0.9999761682F, 0.9999772497F, 0.9999782941F,
  143555. 0.9999793021F, 0.9999802747F, 0.9999812126F, 0.9999821167F,
  143556. 0.9999829878F, 0.9999838268F, 0.9999846343F, 0.9999854113F,
  143557. 0.9999861584F, 0.9999868765F, 0.9999875664F, 0.9999882287F,
  143558. 0.9999888642F, 0.9999894736F, 0.9999900577F, 0.9999906172F,
  143559. 0.9999911528F, 0.9999916651F, 0.9999921548F, 0.9999926227F,
  143560. 0.9999930693F, 0.9999934954F, 0.9999939015F, 0.9999942883F,
  143561. 0.9999946564F, 0.9999950064F, 0.9999953390F, 0.9999956547F,
  143562. 0.9999959541F, 0.9999962377F, 0.9999965062F, 0.9999967601F,
  143563. 0.9999969998F, 0.9999972260F, 0.9999974392F, 0.9999976399F,
  143564. 0.9999978285F, 0.9999980056F, 0.9999981716F, 0.9999983271F,
  143565. 0.9999984724F, 0.9999986081F, 0.9999987345F, 0.9999988521F,
  143566. 0.9999989613F, 0.9999990625F, 0.9999991562F, 0.9999992426F,
  143567. 0.9999993223F, 0.9999993954F, 0.9999994625F, 0.9999995239F,
  143568. 0.9999995798F, 0.9999996307F, 0.9999996768F, 0.9999997184F,
  143569. 0.9999997559F, 0.9999997895F, 0.9999998195F, 0.9999998462F,
  143570. 0.9999998698F, 0.9999998906F, 0.9999999088F, 0.9999999246F,
  143571. 0.9999999383F, 0.9999999500F, 0.9999999600F, 0.9999999684F,
  143572. 0.9999999754F, 0.9999999811F, 0.9999999858F, 0.9999999896F,
  143573. 0.9999999925F, 0.9999999948F, 0.9999999965F, 0.9999999978F,
  143574. 0.9999999986F, 0.9999999992F, 0.9999999996F, 0.9999999998F,
  143575. 0.9999999999F, 1.0000000000F, 1.0000000000F, 1.0000000000F,
  143576. };
  143577. static float vwin8192[4096] = {
  143578. 0.0000000578F, 0.0000005198F, 0.0000014438F, 0.0000028299F,
  143579. 0.0000046780F, 0.0000069882F, 0.0000097604F, 0.0000129945F,
  143580. 0.0000166908F, 0.0000208490F, 0.0000254692F, 0.0000305515F,
  143581. 0.0000360958F, 0.0000421021F, 0.0000485704F, 0.0000555006F,
  143582. 0.0000628929F, 0.0000707472F, 0.0000790635F, 0.0000878417F,
  143583. 0.0000970820F, 0.0001067842F, 0.0001169483F, 0.0001275744F,
  143584. 0.0001386625F, 0.0001502126F, 0.0001622245F, 0.0001746984F,
  143585. 0.0001876343F, 0.0002010320F, 0.0002148917F, 0.0002292132F,
  143586. 0.0002439967F, 0.0002592421F, 0.0002749493F, 0.0002911184F,
  143587. 0.0003077493F, 0.0003248421F, 0.0003423967F, 0.0003604132F,
  143588. 0.0003788915F, 0.0003978316F, 0.0004172335F, 0.0004370971F,
  143589. 0.0004574226F, 0.0004782098F, 0.0004994587F, 0.0005211694F,
  143590. 0.0005433418F, 0.0005659759F, 0.0005890717F, 0.0006126292F,
  143591. 0.0006366484F, 0.0006611292F, 0.0006860716F, 0.0007114757F,
  143592. 0.0007373414F, 0.0007636687F, 0.0007904576F, 0.0008177080F,
  143593. 0.0008454200F, 0.0008735935F, 0.0009022285F, 0.0009313250F,
  143594. 0.0009608830F, 0.0009909025F, 0.0010213834F, 0.0010523257F,
  143595. 0.0010837295F, 0.0011155946F, 0.0011479211F, 0.0011807090F,
  143596. 0.0012139582F, 0.0012476687F, 0.0012818405F, 0.0013164736F,
  143597. 0.0013515679F, 0.0013871235F, 0.0014231402F, 0.0014596182F,
  143598. 0.0014965573F, 0.0015339576F, 0.0015718190F, 0.0016101415F,
  143599. 0.0016489251F, 0.0016881698F, 0.0017278754F, 0.0017680421F,
  143600. 0.0018086698F, 0.0018497584F, 0.0018913080F, 0.0019333185F,
  143601. 0.0019757898F, 0.0020187221F, 0.0020621151F, 0.0021059690F,
  143602. 0.0021502837F, 0.0021950591F, 0.0022402953F, 0.0022859921F,
  143603. 0.0023321497F, 0.0023787679F, 0.0024258467F, 0.0024733861F,
  143604. 0.0025213861F, 0.0025698466F, 0.0026187676F, 0.0026681491F,
  143605. 0.0027179911F, 0.0027682935F, 0.0028190562F, 0.0028702794F,
  143606. 0.0029219628F, 0.0029741066F, 0.0030267107F, 0.0030797749F,
  143607. 0.0031332994F, 0.0031872841F, 0.0032417289F, 0.0032966338F,
  143608. 0.0033519988F, 0.0034078238F, 0.0034641089F, 0.0035208539F,
  143609. 0.0035780589F, 0.0036357237F, 0.0036938485F, 0.0037524331F,
  143610. 0.0038114775F, 0.0038709817F, 0.0039309456F, 0.0039913692F,
  143611. 0.0040522524F, 0.0041135953F, 0.0041753978F, 0.0042376599F,
  143612. 0.0043003814F, 0.0043635624F, 0.0044272029F, 0.0044913028F,
  143613. 0.0045558620F, 0.0046208806F, 0.0046863585F, 0.0047522955F,
  143614. 0.0048186919F, 0.0048855473F, 0.0049528619F, 0.0050206356F,
  143615. 0.0050888684F, 0.0051575601F, 0.0052267108F, 0.0052963204F,
  143616. 0.0053663890F, 0.0054369163F, 0.0055079025F, 0.0055793474F,
  143617. 0.0056512510F, 0.0057236133F, 0.0057964342F, 0.0058697137F,
  143618. 0.0059434517F, 0.0060176482F, 0.0060923032F, 0.0061674166F,
  143619. 0.0062429883F, 0.0063190183F, 0.0063955066F, 0.0064724532F,
  143620. 0.0065498579F, 0.0066277207F, 0.0067060416F, 0.0067848205F,
  143621. 0.0068640575F, 0.0069437523F, 0.0070239051F, 0.0071045157F,
  143622. 0.0071855840F, 0.0072671102F, 0.0073490940F, 0.0074315355F,
  143623. 0.0075144345F, 0.0075977911F, 0.0076816052F, 0.0077658768F,
  143624. 0.0078506057F, 0.0079357920F, 0.0080214355F, 0.0081075363F,
  143625. 0.0081940943F, 0.0082811094F, 0.0083685816F, 0.0084565108F,
  143626. 0.0085448970F, 0.0086337401F, 0.0087230401F, 0.0088127969F,
  143627. 0.0089030104F, 0.0089936807F, 0.0090848076F, 0.0091763911F,
  143628. 0.0092684311F, 0.0093609276F, 0.0094538805F, 0.0095472898F,
  143629. 0.0096411554F, 0.0097354772F, 0.0098302552F, 0.0099254894F,
  143630. 0.0100211796F, 0.0101173259F, 0.0102139281F, 0.0103109863F,
  143631. 0.0104085002F, 0.0105064700F, 0.0106048955F, 0.0107037766F,
  143632. 0.0108031133F, 0.0109029056F, 0.0110031534F, 0.0111038565F,
  143633. 0.0112050151F, 0.0113066289F, 0.0114086980F, 0.0115112222F,
  143634. 0.0116142015F, 0.0117176359F, 0.0118215252F, 0.0119258695F,
  143635. 0.0120306686F, 0.0121359225F, 0.0122416312F, 0.0123477944F,
  143636. 0.0124544123F, 0.0125614847F, 0.0126690116F, 0.0127769928F,
  143637. 0.0128854284F, 0.0129943182F, 0.0131036623F, 0.0132134604F,
  143638. 0.0133237126F, 0.0134344188F, 0.0135455790F, 0.0136571929F,
  143639. 0.0137692607F, 0.0138817821F, 0.0139947572F, 0.0141081859F,
  143640. 0.0142220681F, 0.0143364037F, 0.0144511927F, 0.0145664350F,
  143641. 0.0146821304F, 0.0147982791F, 0.0149148808F, 0.0150319355F,
  143642. 0.0151494431F, 0.0152674036F, 0.0153858168F, 0.0155046828F,
  143643. 0.0156240014F, 0.0157437726F, 0.0158639962F, 0.0159846723F,
  143644. 0.0161058007F, 0.0162273814F, 0.0163494142F, 0.0164718991F,
  143645. 0.0165948361F, 0.0167182250F, 0.0168420658F, 0.0169663584F,
  143646. 0.0170911027F, 0.0172162987F, 0.0173419462F, 0.0174680452F,
  143647. 0.0175945956F, 0.0177215974F, 0.0178490504F, 0.0179769545F,
  143648. 0.0181053098F, 0.0182341160F, 0.0183633732F, 0.0184930812F,
  143649. 0.0186232399F, 0.0187538494F, 0.0188849094F, 0.0190164200F,
  143650. 0.0191483809F, 0.0192807923F, 0.0194136539F, 0.0195469656F,
  143651. 0.0196807275F, 0.0198149394F, 0.0199496012F, 0.0200847128F,
  143652. 0.0202202742F, 0.0203562853F, 0.0204927460F, 0.0206296561F,
  143653. 0.0207670157F, 0.0209048245F, 0.0210430826F, 0.0211817899F,
  143654. 0.0213209462F, 0.0214605515F, 0.0216006057F, 0.0217411086F,
  143655. 0.0218820603F, 0.0220234605F, 0.0221653093F, 0.0223076066F,
  143656. 0.0224503521F, 0.0225935459F, 0.0227371879F, 0.0228812779F,
  143657. 0.0230258160F, 0.0231708018F, 0.0233162355F, 0.0234621169F,
  143658. 0.0236084459F, 0.0237552224F, 0.0239024462F, 0.0240501175F,
  143659. 0.0241982359F, 0.0243468015F, 0.0244958141F, 0.0246452736F,
  143660. 0.0247951800F, 0.0249455331F, 0.0250963329F, 0.0252475792F,
  143661. 0.0253992720F, 0.0255514111F, 0.0257039965F, 0.0258570281F,
  143662. 0.0260105057F, 0.0261644293F, 0.0263187987F, 0.0264736139F,
  143663. 0.0266288747F, 0.0267845811F, 0.0269407330F, 0.0270973302F,
  143664. 0.0272543727F, 0.0274118604F, 0.0275697930F, 0.0277281707F,
  143665. 0.0278869932F, 0.0280462604F, 0.0282059723F, 0.0283661287F,
  143666. 0.0285267295F, 0.0286877747F, 0.0288492641F, 0.0290111976F,
  143667. 0.0291735751F, 0.0293363965F, 0.0294996617F, 0.0296633706F,
  143668. 0.0298275231F, 0.0299921190F, 0.0301571583F, 0.0303226409F,
  143669. 0.0304885667F, 0.0306549354F, 0.0308217472F, 0.0309890017F,
  143670. 0.0311566989F, 0.0313248388F, 0.0314934211F, 0.0316624459F,
  143671. 0.0318319128F, 0.0320018220F, 0.0321721732F, 0.0323429663F,
  143672. 0.0325142013F, 0.0326858779F, 0.0328579962F, 0.0330305559F,
  143673. 0.0332035570F, 0.0333769994F, 0.0335508829F, 0.0337252074F,
  143674. 0.0338999728F, 0.0340751790F, 0.0342508259F, 0.0344269134F,
  143675. 0.0346034412F, 0.0347804094F, 0.0349578178F, 0.0351356663F,
  143676. 0.0353139548F, 0.0354926831F, 0.0356718511F, 0.0358514588F,
  143677. 0.0360315059F, 0.0362119924F, 0.0363929182F, 0.0365742831F,
  143678. 0.0367560870F, 0.0369383297F, 0.0371210113F, 0.0373041315F,
  143679. 0.0374876902F, 0.0376716873F, 0.0378561226F, 0.0380409961F,
  143680. 0.0382263077F, 0.0384120571F, 0.0385982443F, 0.0387848691F,
  143681. 0.0389719315F, 0.0391594313F, 0.0393473683F, 0.0395357425F,
  143682. 0.0397245537F, 0.0399138017F, 0.0401034866F, 0.0402936080F,
  143683. 0.0404841660F, 0.0406751603F, 0.0408665909F, 0.0410584576F,
  143684. 0.0412507603F, 0.0414434988F, 0.0416366731F, 0.0418302829F,
  143685. 0.0420243282F, 0.0422188088F, 0.0424137246F, 0.0426090755F,
  143686. 0.0428048613F, 0.0430010819F, 0.0431977371F, 0.0433948269F,
  143687. 0.0435923511F, 0.0437903095F, 0.0439887020F, 0.0441875285F,
  143688. 0.0443867889F, 0.0445864830F, 0.0447866106F, 0.0449871717F,
  143689. 0.0451881661F, 0.0453895936F, 0.0455914542F, 0.0457937477F,
  143690. 0.0459964738F, 0.0461996326F, 0.0464032239F, 0.0466072475F,
  143691. 0.0468117032F, 0.0470165910F, 0.0472219107F, 0.0474276622F,
  143692. 0.0476338452F, 0.0478404597F, 0.0480475056F, 0.0482549827F,
  143693. 0.0484628907F, 0.0486712297F, 0.0488799994F, 0.0490891998F,
  143694. 0.0492988306F, 0.0495088917F, 0.0497193830F, 0.0499303043F,
  143695. 0.0501416554F, 0.0503534363F, 0.0505656468F, 0.0507782867F,
  143696. 0.0509913559F, 0.0512048542F, 0.0514187815F, 0.0516331376F,
  143697. 0.0518479225F, 0.0520631358F, 0.0522787775F, 0.0524948475F,
  143698. 0.0527113455F, 0.0529282715F, 0.0531456252F, 0.0533634066F,
  143699. 0.0535816154F, 0.0538002515F, 0.0540193148F, 0.0542388051F,
  143700. 0.0544587222F, 0.0546790660F, 0.0548998364F, 0.0551210331F,
  143701. 0.0553426561F, 0.0555647051F, 0.0557871801F, 0.0560100807F,
  143702. 0.0562334070F, 0.0564571587F, 0.0566813357F, 0.0569059378F,
  143703. 0.0571309649F, 0.0573564168F, 0.0575822933F, 0.0578085942F,
  143704. 0.0580353195F, 0.0582624689F, 0.0584900423F, 0.0587180396F,
  143705. 0.0589464605F, 0.0591753049F, 0.0594045726F, 0.0596342635F,
  143706. 0.0598643774F, 0.0600949141F, 0.0603258735F, 0.0605572555F,
  143707. 0.0607890597F, 0.0610212862F, 0.0612539346F, 0.0614870049F,
  143708. 0.0617204968F, 0.0619544103F, 0.0621887451F, 0.0624235010F,
  143709. 0.0626586780F, 0.0628942758F, 0.0631302942F, 0.0633667331F,
  143710. 0.0636035923F, 0.0638408717F, 0.0640785710F, 0.0643166901F,
  143711. 0.0645552288F, 0.0647941870F, 0.0650335645F, 0.0652733610F,
  143712. 0.0655135765F, 0.0657542108F, 0.0659952636F, 0.0662367348F,
  143713. 0.0664786242F, 0.0667209316F, 0.0669636570F, 0.0672068000F,
  143714. 0.0674503605F, 0.0676943384F, 0.0679387334F, 0.0681835454F,
  143715. 0.0684287742F, 0.0686744196F, 0.0689204814F, 0.0691669595F,
  143716. 0.0694138536F, 0.0696611637F, 0.0699088894F, 0.0701570307F,
  143717. 0.0704055873F, 0.0706545590F, 0.0709039458F, 0.0711537473F,
  143718. 0.0714039634F, 0.0716545939F, 0.0719056387F, 0.0721570975F,
  143719. 0.0724089702F, 0.0726612565F, 0.0729139563F, 0.0731670694F,
  143720. 0.0734205956F, 0.0736745347F, 0.0739288866F, 0.0741836510F,
  143721. 0.0744388277F, 0.0746944166F, 0.0749504175F, 0.0752068301F,
  143722. 0.0754636543F, 0.0757208899F, 0.0759785367F, 0.0762365946F,
  143723. 0.0764950632F, 0.0767539424F, 0.0770132320F, 0.0772729319F,
  143724. 0.0775330418F, 0.0777935616F, 0.0780544909F, 0.0783158298F,
  143725. 0.0785775778F, 0.0788397349F, 0.0791023009F, 0.0793652755F,
  143726. 0.0796286585F, 0.0798924498F, 0.0801566492F, 0.0804212564F,
  143727. 0.0806862712F, 0.0809516935F, 0.0812175231F, 0.0814837597F,
  143728. 0.0817504031F, 0.0820174532F, 0.0822849097F, 0.0825527724F,
  143729. 0.0828210412F, 0.0830897158F, 0.0833587960F, 0.0836282816F,
  143730. 0.0838981724F, 0.0841684682F, 0.0844391688F, 0.0847102740F,
  143731. 0.0849817835F, 0.0852536973F, 0.0855260150F, 0.0857987364F,
  143732. 0.0860718614F, 0.0863453897F, 0.0866193211F, 0.0868936554F,
  143733. 0.0871683924F, 0.0874435319F, 0.0877190737F, 0.0879950175F,
  143734. 0.0882713632F, 0.0885481105F, 0.0888252592F, 0.0891028091F,
  143735. 0.0893807600F, 0.0896591117F, 0.0899378639F, 0.0902170165F,
  143736. 0.0904965692F, 0.0907765218F, 0.0910568740F, 0.0913376258F,
  143737. 0.0916187767F, 0.0919003268F, 0.0921822756F, 0.0924646230F,
  143738. 0.0927473687F, 0.0930305126F, 0.0933140545F, 0.0935979940F,
  143739. 0.0938823310F, 0.0941670653F, 0.0944521966F, 0.0947377247F,
  143740. 0.0950236494F, 0.0953099704F, 0.0955966876F, 0.0958838007F,
  143741. 0.0961713094F, 0.0964592136F, 0.0967475131F, 0.0970362075F,
  143742. 0.0973252967F, 0.0976147805F, 0.0979046585F, 0.0981949307F,
  143743. 0.0984855967F, 0.0987766563F, 0.0990681093F, 0.0993599555F,
  143744. 0.0996521945F, 0.0999448263F, 0.1002378506F, 0.1005312671F,
  143745. 0.1008250755F, 0.1011192757F, 0.1014138675F, 0.1017088505F,
  143746. 0.1020042246F, 0.1022999895F, 0.1025961450F, 0.1028926909F,
  143747. 0.1031896268F, 0.1034869526F, 0.1037846680F, 0.1040827729F,
  143748. 0.1043812668F, 0.1046801497F, 0.1049794213F, 0.1052790813F,
  143749. 0.1055791294F, 0.1058795656F, 0.1061803894F, 0.1064816006F,
  143750. 0.1067831991F, 0.1070851846F, 0.1073875568F, 0.1076903155F,
  143751. 0.1079934604F, 0.1082969913F, 0.1086009079F, 0.1089052101F,
  143752. 0.1092098975F, 0.1095149699F, 0.1098204270F, 0.1101262687F,
  143753. 0.1104324946F, 0.1107391045F, 0.1110460982F, 0.1113534754F,
  143754. 0.1116612359F, 0.1119693793F, 0.1122779055F, 0.1125868142F,
  143755. 0.1128961052F, 0.1132057781F, 0.1135158328F, 0.1138262690F,
  143756. 0.1141370863F, 0.1144482847F, 0.1147598638F, 0.1150718233F,
  143757. 0.1153841631F, 0.1156968828F, 0.1160099822F, 0.1163234610F,
  143758. 0.1166373190F, 0.1169515559F, 0.1172661714F, 0.1175811654F,
  143759. 0.1178965374F, 0.1182122874F, 0.1185284149F, 0.1188449198F,
  143760. 0.1191618018F, 0.1194790606F, 0.1197966960F, 0.1201147076F,
  143761. 0.1204330953F, 0.1207518587F, 0.1210709976F, 0.1213905118F,
  143762. 0.1217104009F, 0.1220306647F, 0.1223513029F, 0.1226723153F,
  143763. 0.1229937016F, 0.1233154615F, 0.1236375948F, 0.1239601011F,
  143764. 0.1242829803F, 0.1246062319F, 0.1249298559F, 0.1252538518F,
  143765. 0.1255782195F, 0.1259029586F, 0.1262280689F, 0.1265535501F,
  143766. 0.1268794019F, 0.1272056241F, 0.1275322163F, 0.1278591784F,
  143767. 0.1281865099F, 0.1285142108F, 0.1288422805F, 0.1291707190F,
  143768. 0.1294995259F, 0.1298287009F, 0.1301582437F, 0.1304881542F,
  143769. 0.1308184319F, 0.1311490766F, 0.1314800881F, 0.1318114660F,
  143770. 0.1321432100F, 0.1324753200F, 0.1328077955F, 0.1331406364F,
  143771. 0.1334738422F, 0.1338074129F, 0.1341413479F, 0.1344756472F,
  143772. 0.1348103103F, 0.1351453370F, 0.1354807270F, 0.1358164801F,
  143773. 0.1361525959F, 0.1364890741F, 0.1368259145F, 0.1371631167F,
  143774. 0.1375006805F, 0.1378386056F, 0.1381768917F, 0.1385155384F,
  143775. 0.1388545456F, 0.1391939129F, 0.1395336400F, 0.1398737266F,
  143776. 0.1402141724F, 0.1405549772F, 0.1408961406F, 0.1412376623F,
  143777. 0.1415795421F, 0.1419217797F, 0.1422643746F, 0.1426073268F,
  143778. 0.1429506358F, 0.1432943013F, 0.1436383231F, 0.1439827008F,
  143779. 0.1443274342F, 0.1446725229F, 0.1450179667F, 0.1453637652F,
  143780. 0.1457099181F, 0.1460564252F, 0.1464032861F, 0.1467505006F,
  143781. 0.1470980682F, 0.1474459888F, 0.1477942620F, 0.1481428875F,
  143782. 0.1484918651F, 0.1488411942F, 0.1491908748F, 0.1495409065F,
  143783. 0.1498912889F, 0.1502420218F, 0.1505931048F, 0.1509445376F,
  143784. 0.1512963200F, 0.1516484516F, 0.1520009321F, 0.1523537612F,
  143785. 0.1527069385F, 0.1530604638F, 0.1534143368F, 0.1537685571F,
  143786. 0.1541231244F, 0.1544780384F, 0.1548332987F, 0.1551889052F,
  143787. 0.1555448574F, 0.1559011550F, 0.1562577978F, 0.1566147853F,
  143788. 0.1569721173F, 0.1573297935F, 0.1576878135F, 0.1580461771F,
  143789. 0.1584048838F, 0.1587639334F, 0.1591233255F, 0.1594830599F,
  143790. 0.1598431361F, 0.1602035540F, 0.1605643131F, 0.1609254131F,
  143791. 0.1612868537F, 0.1616486346F, 0.1620107555F, 0.1623732160F,
  143792. 0.1627360158F, 0.1630991545F, 0.1634626319F, 0.1638264476F,
  143793. 0.1641906013F, 0.1645550926F, 0.1649199212F, 0.1652850869F,
  143794. 0.1656505892F, 0.1660164278F, 0.1663826024F, 0.1667491127F,
  143795. 0.1671159583F, 0.1674831388F, 0.1678506541F, 0.1682185036F,
  143796. 0.1685866872F, 0.1689552044F, 0.1693240549F, 0.1696932384F,
  143797. 0.1700627545F, 0.1704326029F, 0.1708027833F, 0.1711732952F,
  143798. 0.1715441385F, 0.1719153127F, 0.1722868175F, 0.1726586526F,
  143799. 0.1730308176F, 0.1734033121F, 0.1737761359F, 0.1741492886F,
  143800. 0.1745227698F, 0.1748965792F, 0.1752707164F, 0.1756451812F,
  143801. 0.1760199731F, 0.1763950918F, 0.1767705370F, 0.1771463083F,
  143802. 0.1775224054F, 0.1778988279F, 0.1782755754F, 0.1786526477F,
  143803. 0.1790300444F, 0.1794077651F, 0.1797858094F, 0.1801641771F,
  143804. 0.1805428677F, 0.1809218810F, 0.1813012165F, 0.1816808739F,
  143805. 0.1820608528F, 0.1824411530F, 0.1828217739F, 0.1832027154F,
  143806. 0.1835839770F, 0.1839655584F, 0.1843474592F, 0.1847296790F,
  143807. 0.1851122175F, 0.1854950744F, 0.1858782492F, 0.1862617417F,
  143808. 0.1866455514F, 0.1870296780F, 0.1874141211F, 0.1877988804F,
  143809. 0.1881839555F, 0.1885693461F, 0.1889550517F, 0.1893410721F,
  143810. 0.1897274068F, 0.1901140555F, 0.1905010178F, 0.1908882933F,
  143811. 0.1912758818F, 0.1916637828F, 0.1920519959F, 0.1924405208F,
  143812. 0.1928293571F, 0.1932185044F, 0.1936079625F, 0.1939977308F,
  143813. 0.1943878091F, 0.1947781969F, 0.1951688939F, 0.1955598998F,
  143814. 0.1959512141F, 0.1963428364F, 0.1967347665F, 0.1971270038F,
  143815. 0.1975195482F, 0.1979123990F, 0.1983055561F, 0.1986990190F,
  143816. 0.1990927873F, 0.1994868607F, 0.1998812388F, 0.2002759212F,
  143817. 0.2006709075F, 0.2010661974F, 0.2014617904F, 0.2018576862F,
  143818. 0.2022538844F, 0.2026503847F, 0.2030471865F, 0.2034442897F,
  143819. 0.2038416937F, 0.2042393982F, 0.2046374028F, 0.2050357071F,
  143820. 0.2054343107F, 0.2058332133F, 0.2062324145F, 0.2066319138F,
  143821. 0.2070317110F, 0.2074318055F, 0.2078321970F, 0.2082328852F,
  143822. 0.2086338696F, 0.2090351498F, 0.2094367255F, 0.2098385962F,
  143823. 0.2102407617F, 0.2106432213F, 0.2110459749F, 0.2114490220F,
  143824. 0.2118523621F, 0.2122559950F, 0.2126599202F, 0.2130641373F,
  143825. 0.2134686459F, 0.2138734456F, 0.2142785361F, 0.2146839168F,
  143826. 0.2150895875F, 0.2154955478F, 0.2159017972F, 0.2163083353F,
  143827. 0.2167151617F, 0.2171222761F, 0.2175296780F, 0.2179373670F,
  143828. 0.2183453428F, 0.2187536049F, 0.2191621529F, 0.2195709864F,
  143829. 0.2199801051F, 0.2203895085F, 0.2207991961F, 0.2212091677F,
  143830. 0.2216194228F, 0.2220299610F, 0.2224407818F, 0.2228518850F,
  143831. 0.2232632699F, 0.2236749364F, 0.2240868839F, 0.2244991121F,
  143832. 0.2249116204F, 0.2253244086F, 0.2257374763F, 0.2261508229F,
  143833. 0.2265644481F, 0.2269783514F, 0.2273925326F, 0.2278069911F,
  143834. 0.2282217265F, 0.2286367384F, 0.2290520265F, 0.2294675902F,
  143835. 0.2298834292F, 0.2302995431F, 0.2307159314F, 0.2311325937F,
  143836. 0.2315495297F, 0.2319667388F, 0.2323842207F, 0.2328019749F,
  143837. 0.2332200011F, 0.2336382988F, 0.2340568675F, 0.2344757070F,
  143838. 0.2348948166F, 0.2353141961F, 0.2357338450F, 0.2361537629F,
  143839. 0.2365739493F, 0.2369944038F, 0.2374151261F, 0.2378361156F,
  143840. 0.2382573720F, 0.2386788948F, 0.2391006836F, 0.2395227380F,
  143841. 0.2399450575F, 0.2403676417F, 0.2407904902F, 0.2412136026F,
  143842. 0.2416369783F, 0.2420606171F, 0.2424845185F, 0.2429086820F,
  143843. 0.2433331072F, 0.2437577936F, 0.2441827409F, 0.2446079486F,
  143844. 0.2450334163F, 0.2454591435F, 0.2458851298F, 0.2463113747F,
  143845. 0.2467378779F, 0.2471646389F, 0.2475916573F, 0.2480189325F,
  143846. 0.2484464643F, 0.2488742521F, 0.2493022955F, 0.2497305940F,
  143847. 0.2501591473F, 0.2505879549F, 0.2510170163F, 0.2514463311F,
  143848. 0.2518758989F, 0.2523057193F, 0.2527357916F, 0.2531661157F,
  143849. 0.2535966909F, 0.2540275169F, 0.2544585931F, 0.2548899193F,
  143850. 0.2553214948F, 0.2557533193F, 0.2561853924F, 0.2566177135F,
  143851. 0.2570502822F, 0.2574830981F, 0.2579161608F, 0.2583494697F,
  143852. 0.2587830245F, 0.2592168246F, 0.2596508697F, 0.2600851593F,
  143853. 0.2605196929F, 0.2609544701F, 0.2613894904F, 0.2618247534F,
  143854. 0.2622602586F, 0.2626960055F, 0.2631319938F, 0.2635682230F,
  143855. 0.2640046925F, 0.2644414021F, 0.2648783511F, 0.2653155391F,
  143856. 0.2657529657F, 0.2661906305F, 0.2666285329F, 0.2670666725F,
  143857. 0.2675050489F, 0.2679436616F, 0.2683825101F, 0.2688215940F,
  143858. 0.2692609127F, 0.2697004660F, 0.2701402532F, 0.2705802739F,
  143859. 0.2710205278F, 0.2714610142F, 0.2719017327F, 0.2723426830F,
  143860. 0.2727838644F, 0.2732252766F, 0.2736669191F, 0.2741087914F,
  143861. 0.2745508930F, 0.2749932235F, 0.2754357824F, 0.2758785693F,
  143862. 0.2763215837F, 0.2767648251F, 0.2772082930F, 0.2776519870F,
  143863. 0.2780959066F, 0.2785400513F, 0.2789844207F, 0.2794290143F,
  143864. 0.2798738316F, 0.2803188722F, 0.2807641355F, 0.2812096211F,
  143865. 0.2816553286F, 0.2821012574F, 0.2825474071F, 0.2829937773F,
  143866. 0.2834403673F, 0.2838871768F, 0.2843342053F, 0.2847814523F,
  143867. 0.2852289174F, 0.2856765999F, 0.2861244996F, 0.2865726159F,
  143868. 0.2870209482F, 0.2874694962F, 0.2879182594F, 0.2883672372F,
  143869. 0.2888164293F, 0.2892658350F, 0.2897154540F, 0.2901652858F,
  143870. 0.2906153298F, 0.2910655856F, 0.2915160527F, 0.2919667306F,
  143871. 0.2924176189F, 0.2928687171F, 0.2933200246F, 0.2937715409F,
  143872. 0.2942232657F, 0.2946751984F, 0.2951273386F, 0.2955796856F,
  143873. 0.2960322391F, 0.2964849986F, 0.2969379636F, 0.2973911335F,
  143874. 0.2978445080F, 0.2982980864F, 0.2987518684F, 0.2992058534F,
  143875. 0.2996600409F, 0.3001144305F, 0.3005690217F, 0.3010238139F,
  143876. 0.3014788067F, 0.3019339995F, 0.3023893920F, 0.3028449835F,
  143877. 0.3033007736F, 0.3037567618F, 0.3042129477F, 0.3046693306F,
  143878. 0.3051259102F, 0.3055826859F, 0.3060396572F, 0.3064968236F,
  143879. 0.3069541847F, 0.3074117399F, 0.3078694887F, 0.3083274307F,
  143880. 0.3087855653F, 0.3092438920F, 0.3097024104F, 0.3101611199F,
  143881. 0.3106200200F, 0.3110791103F, 0.3115383902F, 0.3119978592F,
  143882. 0.3124575169F, 0.3129173627F, 0.3133773961F, 0.3138376166F,
  143883. 0.3142980238F, 0.3147586170F, 0.3152193959F, 0.3156803598F,
  143884. 0.3161415084F, 0.3166028410F, 0.3170643573F, 0.3175260566F,
  143885. 0.3179879384F, 0.3184500023F, 0.3189122478F, 0.3193746743F,
  143886. 0.3198372814F, 0.3203000685F, 0.3207630351F, 0.3212261807F,
  143887. 0.3216895048F, 0.3221530069F, 0.3226166865F, 0.3230805430F,
  143888. 0.3235445760F, 0.3240087849F, 0.3244731693F, 0.3249377285F,
  143889. 0.3254024622F, 0.3258673698F, 0.3263324507F, 0.3267977045F,
  143890. 0.3272631306F, 0.3277287286F, 0.3281944978F, 0.3286604379F,
  143891. 0.3291265482F, 0.3295928284F, 0.3300592777F, 0.3305258958F,
  143892. 0.3309926821F, 0.3314596361F, 0.3319267573F, 0.3323940451F,
  143893. 0.3328614990F, 0.3333291186F, 0.3337969033F, 0.3342648525F,
  143894. 0.3347329658F, 0.3352012427F, 0.3356696825F, 0.3361382849F,
  143895. 0.3366070492F, 0.3370759749F, 0.3375450616F, 0.3380143087F,
  143896. 0.3384837156F, 0.3389532819F, 0.3394230071F, 0.3398928905F,
  143897. 0.3403629317F, 0.3408331302F, 0.3413034854F, 0.3417739967F,
  143898. 0.3422446638F, 0.3427154860F, 0.3431864628F, 0.3436575938F,
  143899. 0.3441288782F, 0.3446003158F, 0.3450719058F, 0.3455436478F,
  143900. 0.3460155412F, 0.3464875856F, 0.3469597804F, 0.3474321250F,
  143901. 0.3479046189F, 0.3483772617F, 0.3488500527F, 0.3493229914F,
  143902. 0.3497960774F, 0.3502693100F, 0.3507426887F, 0.3512162131F,
  143903. 0.3516898825F, 0.3521636965F, 0.3526376545F, 0.3531117559F,
  143904. 0.3535860003F, 0.3540603870F, 0.3545349157F, 0.3550095856F,
  143905. 0.3554843964F, 0.3559593474F, 0.3564344381F, 0.3569096680F,
  143906. 0.3573850366F, 0.3578605432F, 0.3583361875F, 0.3588119687F,
  143907. 0.3592878865F, 0.3597639402F, 0.3602401293F, 0.3607164533F,
  143908. 0.3611929117F, 0.3616695038F, 0.3621462292F, 0.3626230873F,
  143909. 0.3631000776F, 0.3635771995F, 0.3640544525F, 0.3645318360F,
  143910. 0.3650093496F, 0.3654869926F, 0.3659647645F, 0.3664426648F,
  143911. 0.3669206930F, 0.3673988484F, 0.3678771306F, 0.3683555390F,
  143912. 0.3688340731F, 0.3693127322F, 0.3697915160F, 0.3702704237F,
  143913. 0.3707494549F, 0.3712286091F, 0.3717078857F, 0.3721872840F,
  143914. 0.3726668037F, 0.3731464441F, 0.3736262047F, 0.3741060850F,
  143915. 0.3745860843F, 0.3750662023F, 0.3755464382F, 0.3760267915F,
  143916. 0.3765072618F, 0.3769878484F, 0.3774685509F, 0.3779493686F,
  143917. 0.3784303010F, 0.3789113475F, 0.3793925076F, 0.3798737809F,
  143918. 0.3803551666F, 0.3808366642F, 0.3813182733F, 0.3817999932F,
  143919. 0.3822818234F, 0.3827637633F, 0.3832458124F, 0.3837279702F,
  143920. 0.3842102360F, 0.3846926093F, 0.3851750897F, 0.3856576764F,
  143921. 0.3861403690F, 0.3866231670F, 0.3871060696F, 0.3875890765F,
  143922. 0.3880721870F, 0.3885554007F, 0.3890387168F, 0.3895221349F,
  143923. 0.3900056544F, 0.3904892748F, 0.3909729955F, 0.3914568160F,
  143924. 0.3919407356F, 0.3924247539F, 0.3929088702F, 0.3933930841F,
  143925. 0.3938773949F, 0.3943618021F, 0.3948463052F, 0.3953309035F,
  143926. 0.3958155966F, 0.3963003838F, 0.3967852646F, 0.3972702385F,
  143927. 0.3977553048F, 0.3982404631F, 0.3987257127F, 0.3992110531F,
  143928. 0.3996964838F, 0.4001820041F, 0.4006676136F, 0.4011533116F,
  143929. 0.4016390976F, 0.4021249710F, 0.4026109313F, 0.4030969779F,
  143930. 0.4035831102F, 0.4040693277F, 0.4045556299F, 0.4050420160F,
  143931. 0.4055284857F, 0.4060150383F, 0.4065016732F, 0.4069883899F,
  143932. 0.4074751879F, 0.4079620665F, 0.4084490252F, 0.4089360635F,
  143933. 0.4094231807F, 0.4099103763F, 0.4103976498F, 0.4108850005F,
  143934. 0.4113724280F, 0.4118599315F, 0.4123475107F, 0.4128351648F,
  143935. 0.4133228934F, 0.4138106959F, 0.4142985716F, 0.4147865201F,
  143936. 0.4152745408F, 0.4157626330F, 0.4162507963F, 0.4167390301F,
  143937. 0.4172273337F, 0.4177157067F, 0.4182041484F, 0.4186926583F,
  143938. 0.4191812359F, 0.4196698805F, 0.4201585915F, 0.4206473685F,
  143939. 0.4211362108F, 0.4216251179F, 0.4221140892F, 0.4226031241F,
  143940. 0.4230922221F, 0.4235813826F, 0.4240706050F, 0.4245598887F,
  143941. 0.4250492332F, 0.4255386379F, 0.4260281022F, 0.4265176256F,
  143942. 0.4270072075F, 0.4274968473F, 0.4279865445F, 0.4284762984F,
  143943. 0.4289661086F, 0.4294559743F, 0.4299458951F, 0.4304358704F,
  143944. 0.4309258996F, 0.4314159822F, 0.4319061175F, 0.4323963050F,
  143945. 0.4328865441F, 0.4333768342F, 0.4338671749F, 0.4343575654F,
  143946. 0.4348480052F, 0.4353384938F, 0.4358290306F, 0.4363196149F,
  143947. 0.4368102463F, 0.4373009241F, 0.4377916478F, 0.4382824168F,
  143948. 0.4387732305F, 0.4392640884F, 0.4397549899F, 0.4402459343F,
  143949. 0.4407369212F, 0.4412279499F, 0.4417190198F, 0.4422101305F,
  143950. 0.4427012813F, 0.4431924717F, 0.4436837010F, 0.4441749686F,
  143951. 0.4446662742F, 0.4451576169F, 0.4456489963F, 0.4461404118F,
  143952. 0.4466318628F, 0.4471233487F, 0.4476148690F, 0.4481064230F,
  143953. 0.4485980103F, 0.4490896302F, 0.4495812821F, 0.4500729654F,
  143954. 0.4505646797F, 0.4510564243F, 0.4515481986F, 0.4520400021F,
  143955. 0.4525318341F, 0.4530236942F, 0.4535155816F, 0.4540074959F,
  143956. 0.4544994365F, 0.4549914028F, 0.4554833941F, 0.4559754100F,
  143957. 0.4564674499F, 0.4569595131F, 0.4574515991F, 0.4579437074F,
  143958. 0.4584358372F, 0.4589279881F, 0.4594201595F, 0.4599123508F,
  143959. 0.4604045615F, 0.4608967908F, 0.4613890383F, 0.4618813034F,
  143960. 0.4623735855F, 0.4628658841F, 0.4633581984F, 0.4638505281F,
  143961. 0.4643428724F, 0.4648352308F, 0.4653276028F, 0.4658199877F,
  143962. 0.4663123849F, 0.4668047940F, 0.4672972143F, 0.4677896451F,
  143963. 0.4682820861F, 0.4687745365F, 0.4692669958F, 0.4697594634F,
  143964. 0.4702519387F, 0.4707444211F, 0.4712369102F, 0.4717294052F,
  143965. 0.4722219056F, 0.4727144109F, 0.4732069204F, 0.4736994336F,
  143966. 0.4741919498F, 0.4746844686F, 0.4751769893F, 0.4756695113F,
  143967. 0.4761620341F, 0.4766545571F, 0.4771470797F, 0.4776396013F,
  143968. 0.4781321213F, 0.4786246392F, 0.4791171544F, 0.4796096663F,
  143969. 0.4801021744F, 0.4805946779F, 0.4810871765F, 0.4815796694F,
  143970. 0.4820721561F, 0.4825646360F, 0.4830571086F, 0.4835495732F,
  143971. 0.4840420293F, 0.4845344763F, 0.4850269136F, 0.4855193407F,
  143972. 0.4860117569F, 0.4865041617F, 0.4869965545F, 0.4874889347F,
  143973. 0.4879813018F, 0.4884736551F, 0.4889659941F, 0.4894583182F,
  143974. 0.4899506268F, 0.4904429193F, 0.4909351952F, 0.4914274538F,
  143975. 0.4919196947F, 0.4924119172F, 0.4929041207F, 0.4933963046F,
  143976. 0.4938884685F, 0.4943806116F, 0.4948727335F, 0.4953648335F,
  143977. 0.4958569110F, 0.4963489656F, 0.4968409965F, 0.4973330032F,
  143978. 0.4978249852F, 0.4983169419F, 0.4988088726F, 0.4993007768F,
  143979. 0.4997926539F, 0.5002845034F, 0.5007763247F, 0.5012681171F,
  143980. 0.5017598801F, 0.5022516132F, 0.5027433157F, 0.5032349871F,
  143981. 0.5037266268F, 0.5042182341F, 0.5047098086F, 0.5052013497F,
  143982. 0.5056928567F, 0.5061843292F, 0.5066757664F, 0.5071671679F,
  143983. 0.5076585330F, 0.5081498613F, 0.5086411520F, 0.5091324047F,
  143984. 0.5096236187F, 0.5101147934F, 0.5106059284F, 0.5110970230F,
  143985. 0.5115880766F, 0.5120790887F, 0.5125700587F, 0.5130609860F,
  143986. 0.5135518700F, 0.5140427102F, 0.5145335059F, 0.5150242566F,
  143987. 0.5155149618F, 0.5160056208F, 0.5164962331F, 0.5169867980F,
  143988. 0.5174773151F, 0.5179677837F, 0.5184582033F, 0.5189485733F,
  143989. 0.5194388931F, 0.5199291621F, 0.5204193798F, 0.5209095455F,
  143990. 0.5213996588F, 0.5218897190F, 0.5223797256F, 0.5228696779F,
  143991. 0.5233595755F, 0.5238494177F, 0.5243392039F, 0.5248289337F,
  143992. 0.5253186063F, 0.5258082213F, 0.5262977781F, 0.5267872760F,
  143993. 0.5272767146F, 0.5277660932F, 0.5282554112F, 0.5287446682F,
  143994. 0.5292338635F, 0.5297229965F, 0.5302120667F, 0.5307010736F,
  143995. 0.5311900164F, 0.5316788947F, 0.5321677079F, 0.5326564554F,
  143996. 0.5331451366F, 0.5336337511F, 0.5341222981F, 0.5346107771F,
  143997. 0.5350991876F, 0.5355875290F, 0.5360758007F, 0.5365640021F,
  143998. 0.5370521327F, 0.5375401920F, 0.5380281792F, 0.5385160939F,
  143999. 0.5390039355F, 0.5394917034F, 0.5399793971F, 0.5404670159F,
  144000. 0.5409545594F, 0.5414420269F, 0.5419294179F, 0.5424167318F,
  144001. 0.5429039680F, 0.5433911261F, 0.5438782053F, 0.5443652051F,
  144002. 0.5448521250F, 0.5453389644F, 0.5458257228F, 0.5463123995F,
  144003. 0.5467989940F, 0.5472855057F, 0.5477719341F, 0.5482582786F,
  144004. 0.5487445387F, 0.5492307137F, 0.5497168031F, 0.5502028063F,
  144005. 0.5506887228F, 0.5511745520F, 0.5516602934F, 0.5521459463F,
  144006. 0.5526315103F, 0.5531169847F, 0.5536023690F, 0.5540876626F,
  144007. 0.5545728649F, 0.5550579755F, 0.5555429937F, 0.5560279189F,
  144008. 0.5565127507F, 0.5569974884F, 0.5574821315F, 0.5579666794F,
  144009. 0.5584511316F, 0.5589354875F, 0.5594197465F, 0.5599039080F,
  144010. 0.5603879716F, 0.5608719367F, 0.5613558026F, 0.5618395689F,
  144011. 0.5623232350F, 0.5628068002F, 0.5632902642F, 0.5637736262F,
  144012. 0.5642568858F, 0.5647400423F, 0.5652230953F, 0.5657060442F,
  144013. 0.5661888883F, 0.5666716272F, 0.5671542603F, 0.5676367870F,
  144014. 0.5681192069F, 0.5686015192F, 0.5690837235F, 0.5695658192F,
  144015. 0.5700478058F, 0.5705296827F, 0.5710114494F, 0.5714931052F,
  144016. 0.5719746497F, 0.5724560822F, 0.5729374023F, 0.5734186094F,
  144017. 0.5738997029F, 0.5743806823F, 0.5748615470F, 0.5753422965F,
  144018. 0.5758229301F, 0.5763034475F, 0.5767838480F, 0.5772641310F,
  144019. 0.5777442960F, 0.5782243426F, 0.5787042700F, 0.5791840778F,
  144020. 0.5796637654F, 0.5801433322F, 0.5806227778F, 0.5811021016F,
  144021. 0.5815813029F, 0.5820603814F, 0.5825393363F, 0.5830181673F,
  144022. 0.5834968737F, 0.5839754549F, 0.5844539105F, 0.5849322399F,
  144023. 0.5854104425F, 0.5858885179F, 0.5863664653F, 0.5868442844F,
  144024. 0.5873219746F, 0.5877995353F, 0.5882769660F, 0.5887542661F,
  144025. 0.5892314351F, 0.5897084724F, 0.5901853776F, 0.5906621500F,
  144026. 0.5911387892F, 0.5916152945F, 0.5920916655F, 0.5925679016F,
  144027. 0.5930440022F, 0.5935199669F, 0.5939957950F, 0.5944714861F,
  144028. 0.5949470396F, 0.5954224550F, 0.5958977317F, 0.5963728692F,
  144029. 0.5968478669F, 0.5973227244F, 0.5977974411F, 0.5982720163F,
  144030. 0.5987464497F, 0.5992207407F, 0.5996948887F, 0.6001688932F,
  144031. 0.6006427537F, 0.6011164696F, 0.6015900405F, 0.6020634657F,
  144032. 0.6025367447F, 0.6030098770F, 0.6034828621F, 0.6039556995F,
  144033. 0.6044283885F, 0.6049009288F, 0.6053733196F, 0.6058455606F,
  144034. 0.6063176512F, 0.6067895909F, 0.6072613790F, 0.6077330152F,
  144035. 0.6082044989F, 0.6086758295F, 0.6091470065F, 0.6096180294F,
  144036. 0.6100888977F, 0.6105596108F, 0.6110301682F, 0.6115005694F,
  144037. 0.6119708139F, 0.6124409011F, 0.6129108305F, 0.6133806017F,
  144038. 0.6138502139F, 0.6143196669F, 0.6147889599F, 0.6152580926F,
  144039. 0.6157270643F, 0.6161958746F, 0.6166645230F, 0.6171330088F,
  144040. 0.6176013317F, 0.6180694910F, 0.6185374863F, 0.6190053171F,
  144041. 0.6194729827F, 0.6199404828F, 0.6204078167F, 0.6208749841F,
  144042. 0.6213419842F, 0.6218088168F, 0.6222754811F, 0.6227419768F,
  144043. 0.6232083032F, 0.6236744600F, 0.6241404465F, 0.6246062622F,
  144044. 0.6250719067F, 0.6255373795F, 0.6260026799F, 0.6264678076F,
  144045. 0.6269327619F, 0.6273975425F, 0.6278621487F, 0.6283265800F,
  144046. 0.6287908361F, 0.6292549163F, 0.6297188201F, 0.6301825471F,
  144047. 0.6306460966F, 0.6311094683F, 0.6315726617F, 0.6320356761F,
  144048. 0.6324985111F, 0.6329611662F, 0.6334236410F, 0.6338859348F,
  144049. 0.6343480472F, 0.6348099777F, 0.6352717257F, 0.6357332909F,
  144050. 0.6361946726F, 0.6366558704F, 0.6371168837F, 0.6375777122F,
  144051. 0.6380383552F, 0.6384988123F, 0.6389590830F, 0.6394191668F,
  144052. 0.6398790631F, 0.6403387716F, 0.6407982916F, 0.6412576228F,
  144053. 0.6417167645F, 0.6421757163F, 0.6426344778F, 0.6430930483F,
  144054. 0.6435514275F, 0.6440096149F, 0.6444676098F, 0.6449254119F,
  144055. 0.6453830207F, 0.6458404356F, 0.6462976562F, 0.6467546820F,
  144056. 0.6472115125F, 0.6476681472F, 0.6481245856F, 0.6485808273F,
  144057. 0.6490368717F, 0.6494927183F, 0.6499483667F, 0.6504038164F,
  144058. 0.6508590670F, 0.6513141178F, 0.6517689684F, 0.6522236185F,
  144059. 0.6526780673F, 0.6531323146F, 0.6535863598F, 0.6540402024F,
  144060. 0.6544938419F, 0.6549472779F, 0.6554005099F, 0.6558535373F,
  144061. 0.6563063598F, 0.6567589769F, 0.6572113880F, 0.6576635927F,
  144062. 0.6581155906F, 0.6585673810F, 0.6590189637F, 0.6594703380F,
  144063. 0.6599215035F, 0.6603724598F, 0.6608232064F, 0.6612737427F,
  144064. 0.6617240684F, 0.6621741829F, 0.6626240859F, 0.6630737767F,
  144065. 0.6635232550F, 0.6639725202F, 0.6644215720F, 0.6648704098F,
  144066. 0.6653190332F, 0.6657674417F, 0.6662156348F, 0.6666636121F,
  144067. 0.6671113731F, 0.6675589174F, 0.6680062445F, 0.6684533538F,
  144068. 0.6689002450F, 0.6693469177F, 0.6697933712F, 0.6702396052F,
  144069. 0.6706856193F, 0.6711314129F, 0.6715769855F, 0.6720223369F,
  144070. 0.6724674664F, 0.6729123736F, 0.6733570581F, 0.6738015194F,
  144071. 0.6742457570F, 0.6746897706F, 0.6751335596F, 0.6755771236F,
  144072. 0.6760204621F, 0.6764635747F, 0.6769064609F, 0.6773491204F,
  144073. 0.6777915525F, 0.6782337570F, 0.6786757332F, 0.6791174809F,
  144074. 0.6795589995F, 0.6800002886F, 0.6804413477F, 0.6808821765F,
  144075. 0.6813227743F, 0.6817631409F, 0.6822032758F, 0.6826431785F,
  144076. 0.6830828485F, 0.6835222855F, 0.6839614890F, 0.6844004585F,
  144077. 0.6848391936F, 0.6852776939F, 0.6857159589F, 0.6861539883F,
  144078. 0.6865917815F, 0.6870293381F, 0.6874666576F, 0.6879037398F,
  144079. 0.6883405840F, 0.6887771899F, 0.6892135571F, 0.6896496850F,
  144080. 0.6900855733F, 0.6905212216F, 0.6909566294F, 0.6913917963F,
  144081. 0.6918267218F, 0.6922614055F, 0.6926958471F, 0.6931300459F,
  144082. 0.6935640018F, 0.6939977141F, 0.6944311825F, 0.6948644066F,
  144083. 0.6952973859F, 0.6957301200F, 0.6961626085F, 0.6965948510F,
  144084. 0.6970268470F, 0.6974585961F, 0.6978900980F, 0.6983213521F,
  144085. 0.6987523580F, 0.6991831154F, 0.6996136238F, 0.7000438828F,
  144086. 0.7004738921F, 0.7009036510F, 0.7013331594F, 0.7017624166F,
  144087. 0.7021914224F, 0.7026201763F, 0.7030486779F, 0.7034769268F,
  144088. 0.7039049226F, 0.7043326648F, 0.7047601531F, 0.7051873870F,
  144089. 0.7056143662F, 0.7060410902F, 0.7064675586F, 0.7068937711F,
  144090. 0.7073197271F, 0.7077454264F, 0.7081708684F, 0.7085960529F,
  144091. 0.7090209793F, 0.7094456474F, 0.7098700566F, 0.7102942066F,
  144092. 0.7107180970F, 0.7111417274F, 0.7115650974F, 0.7119882066F,
  144093. 0.7124110545F, 0.7128336409F, 0.7132559653F, 0.7136780272F,
  144094. 0.7140998264F, 0.7145213624F, 0.7149426348F, 0.7153636433F,
  144095. 0.7157843874F, 0.7162048668F, 0.7166250810F, 0.7170450296F,
  144096. 0.7174647124F, 0.7178841289F, 0.7183032786F, 0.7187221613F,
  144097. 0.7191407765F, 0.7195591239F, 0.7199772030F, 0.7203950135F,
  144098. 0.7208125550F, 0.7212298271F, 0.7216468294F, 0.7220635616F,
  144099. 0.7224800233F, 0.7228962140F, 0.7233121335F, 0.7237277813F,
  144100. 0.7241431571F, 0.7245582604F, 0.7249730910F, 0.7253876484F,
  144101. 0.7258019322F, 0.7262159422F, 0.7266296778F, 0.7270431388F,
  144102. 0.7274563247F, 0.7278692353F, 0.7282818700F, 0.7286942287F,
  144103. 0.7291063108F, 0.7295181160F, 0.7299296440F, 0.7303408944F,
  144104. 0.7307518669F, 0.7311625609F, 0.7315729763F, 0.7319831126F,
  144105. 0.7323929695F, 0.7328025466F, 0.7332118435F, 0.7336208600F,
  144106. 0.7340295955F, 0.7344380499F, 0.7348462226F, 0.7352541134F,
  144107. 0.7356617220F, 0.7360690478F, 0.7364760907F, 0.7368828502F,
  144108. 0.7372893259F, 0.7376955176F, 0.7381014249F, 0.7385070475F,
  144109. 0.7389123849F, 0.7393174368F, 0.7397222029F, 0.7401266829F,
  144110. 0.7405308763F, 0.7409347829F, 0.7413384023F, 0.7417417341F,
  144111. 0.7421447780F, 0.7425475338F, 0.7429500009F, 0.7433521791F,
  144112. 0.7437540681F, 0.7441556674F, 0.7445569769F, 0.7449579960F,
  144113. 0.7453587245F, 0.7457591621F, 0.7461593084F, 0.7465591631F,
  144114. 0.7469587259F, 0.7473579963F, 0.7477569741F, 0.7481556590F,
  144115. 0.7485540506F, 0.7489521486F, 0.7493499526F, 0.7497474623F,
  144116. 0.7501446775F, 0.7505415977F, 0.7509382227F, 0.7513345521F,
  144117. 0.7517305856F, 0.7521263229F, 0.7525217636F, 0.7529169074F,
  144118. 0.7533117541F, 0.7537063032F, 0.7541005545F, 0.7544945076F,
  144119. 0.7548881623F, 0.7552815182F, 0.7556745749F, 0.7560673323F,
  144120. 0.7564597899F, 0.7568519474F, 0.7572438046F, 0.7576353611F,
  144121. 0.7580266166F, 0.7584175708F, 0.7588082235F, 0.7591985741F,
  144122. 0.7595886226F, 0.7599783685F, 0.7603678116F, 0.7607569515F,
  144123. 0.7611457879F, 0.7615343206F, 0.7619225493F, 0.7623104735F,
  144124. 0.7626980931F, 0.7630854078F, 0.7634724171F, 0.7638591209F,
  144125. 0.7642455188F, 0.7646316106F, 0.7650173959F, 0.7654028744F,
  144126. 0.7657880459F, 0.7661729100F, 0.7665574664F, 0.7669417150F,
  144127. 0.7673256553F, 0.7677092871F, 0.7680926100F, 0.7684756239F,
  144128. 0.7688583284F, 0.7692407232F, 0.7696228080F, 0.7700045826F,
  144129. 0.7703860467F, 0.7707671999F, 0.7711480420F, 0.7715285728F,
  144130. 0.7719087918F, 0.7722886989F, 0.7726682938F, 0.7730475762F,
  144131. 0.7734265458F, 0.7738052023F, 0.7741835454F, 0.7745615750F,
  144132. 0.7749392906F, 0.7753166921F, 0.7756937791F, 0.7760705514F,
  144133. 0.7764470087F, 0.7768231508F, 0.7771989773F, 0.7775744880F,
  144134. 0.7779496827F, 0.7783245610F, 0.7786991227F, 0.7790733676F,
  144135. 0.7794472953F, 0.7798209056F, 0.7801941982F, 0.7805671729F,
  144136. 0.7809398294F, 0.7813121675F, 0.7816841869F, 0.7820558873F,
  144137. 0.7824272684F, 0.7827983301F, 0.7831690720F, 0.7835394940F,
  144138. 0.7839095957F, 0.7842793768F, 0.7846488373F, 0.7850179767F,
  144139. 0.7853867948F, 0.7857552914F, 0.7861234663F, 0.7864913191F,
  144140. 0.7868588497F, 0.7872260578F, 0.7875929431F, 0.7879595055F,
  144141. 0.7883257445F, 0.7886916601F, 0.7890572520F, 0.7894225198F,
  144142. 0.7897874635F, 0.7901520827F, 0.7905163772F, 0.7908803468F,
  144143. 0.7912439912F, 0.7916073102F, 0.7919703035F, 0.7923329710F,
  144144. 0.7926953124F, 0.7930573274F, 0.7934190158F, 0.7937803774F,
  144145. 0.7941414120F, 0.7945021193F, 0.7948624991F, 0.7952225511F,
  144146. 0.7955822752F, 0.7959416711F, 0.7963007387F, 0.7966594775F,
  144147. 0.7970178875F, 0.7973759685F, 0.7977337201F, 0.7980911422F,
  144148. 0.7984482346F, 0.7988049970F, 0.7991614292F, 0.7995175310F,
  144149. 0.7998733022F, 0.8002287426F, 0.8005838519F, 0.8009386299F,
  144150. 0.8012930765F, 0.8016471914F, 0.8020009744F, 0.8023544253F,
  144151. 0.8027075438F, 0.8030603298F, 0.8034127831F, 0.8037649035F,
  144152. 0.8041166906F, 0.8044681445F, 0.8048192647F, 0.8051700512F,
  144153. 0.8055205038F, 0.8058706222F, 0.8062204062F, 0.8065698556F,
  144154. 0.8069189702F, 0.8072677499F, 0.8076161944F, 0.8079643036F,
  144155. 0.8083120772F, 0.8086595151F, 0.8090066170F, 0.8093533827F,
  144156. 0.8096998122F, 0.8100459051F, 0.8103916613F, 0.8107370806F,
  144157. 0.8110821628F, 0.8114269077F, 0.8117713151F, 0.8121153849F,
  144158. 0.8124591169F, 0.8128025108F, 0.8131455666F, 0.8134882839F,
  144159. 0.8138306627F, 0.8141727027F, 0.8145144038F, 0.8148557658F,
  144160. 0.8151967886F, 0.8155374718F, 0.8158778154F, 0.8162178192F,
  144161. 0.8165574830F, 0.8168968067F, 0.8172357900F, 0.8175744328F,
  144162. 0.8179127349F, 0.8182506962F, 0.8185883164F, 0.8189255955F,
  144163. 0.8192625332F, 0.8195991295F, 0.8199353840F, 0.8202712967F,
  144164. 0.8206068673F, 0.8209420958F, 0.8212769820F, 0.8216115256F,
  144165. 0.8219457266F, 0.8222795848F, 0.8226131000F, 0.8229462721F,
  144166. 0.8232791009F, 0.8236115863F, 0.8239437280F, 0.8242755260F,
  144167. 0.8246069801F, 0.8249380901F, 0.8252688559F, 0.8255992774F,
  144168. 0.8259293544F, 0.8262590867F, 0.8265884741F, 0.8269175167F,
  144169. 0.8272462141F, 0.8275745663F, 0.8279025732F, 0.8282302344F,
  144170. 0.8285575501F, 0.8288845199F, 0.8292111437F, 0.8295374215F,
  144171. 0.8298633530F, 0.8301889382F, 0.8305141768F, 0.8308390688F,
  144172. 0.8311636141F, 0.8314878124F, 0.8318116637F, 0.8321351678F,
  144173. 0.8324583246F, 0.8327811340F, 0.8331035957F, 0.8334257098F,
  144174. 0.8337474761F, 0.8340688944F, 0.8343899647F, 0.8347106867F,
  144175. 0.8350310605F, 0.8353510857F, 0.8356707624F, 0.8359900904F,
  144176. 0.8363090696F, 0.8366276999F, 0.8369459811F, 0.8372639131F,
  144177. 0.8375814958F, 0.8378987292F, 0.8382156130F, 0.8385321472F,
  144178. 0.8388483316F, 0.8391641662F, 0.8394796508F, 0.8397947853F,
  144179. 0.8401095697F, 0.8404240037F, 0.8407380873F, 0.8410518204F,
  144180. 0.8413652029F, 0.8416782347F, 0.8419909156F, 0.8423032456F,
  144181. 0.8426152245F, 0.8429268523F, 0.8432381289F, 0.8435490541F,
  144182. 0.8438596279F, 0.8441698502F, 0.8444797208F, 0.8447892396F,
  144183. 0.8450984067F, 0.8454072218F, 0.8457156849F, 0.8460237959F,
  144184. 0.8463315547F, 0.8466389612F, 0.8469460154F, 0.8472527170F,
  144185. 0.8475590661F, 0.8478650625F, 0.8481707063F, 0.8484759971F,
  144186. 0.8487809351F, 0.8490855201F, 0.8493897521F, 0.8496936308F,
  144187. 0.8499971564F, 0.8503003286F, 0.8506031474F, 0.8509056128F,
  144188. 0.8512077246F, 0.8515094828F, 0.8518108872F, 0.8521119379F,
  144189. 0.8524126348F, 0.8527129777F, 0.8530129666F, 0.8533126015F,
  144190. 0.8536118822F, 0.8539108087F, 0.8542093809F, 0.8545075988F,
  144191. 0.8548054623F, 0.8551029712F, 0.8554001257F, 0.8556969255F,
  144192. 0.8559933707F, 0.8562894611F, 0.8565851968F, 0.8568805775F,
  144193. 0.8571756034F, 0.8574702743F, 0.8577645902F, 0.8580585509F,
  144194. 0.8583521566F, 0.8586454070F, 0.8589383021F, 0.8592308420F,
  144195. 0.8595230265F, 0.8598148556F, 0.8601063292F, 0.8603974473F,
  144196. 0.8606882098F, 0.8609786167F, 0.8612686680F, 0.8615583636F,
  144197. 0.8618477034F, 0.8621366874F, 0.8624253156F, 0.8627135878F,
  144198. 0.8630015042F, 0.8632890646F, 0.8635762690F, 0.8638631173F,
  144199. 0.8641496096F, 0.8644357457F, 0.8647215257F, 0.8650069495F,
  144200. 0.8652920171F, 0.8655767283F, 0.8658610833F, 0.8661450820F,
  144201. 0.8664287243F, 0.8667120102F, 0.8669949397F, 0.8672775127F,
  144202. 0.8675597293F, 0.8678415894F, 0.8681230929F, 0.8684042398F,
  144203. 0.8686850302F, 0.8689654640F, 0.8692455412F, 0.8695252617F,
  144204. 0.8698046255F, 0.8700836327F, 0.8703622831F, 0.8706405768F,
  144205. 0.8709185138F, 0.8711960940F, 0.8714733174F, 0.8717501840F,
  144206. 0.8720266939F, 0.8723028469F, 0.8725786430F, 0.8728540824F,
  144207. 0.8731291648F, 0.8734038905F, 0.8736782592F, 0.8739522711F,
  144208. 0.8742259261F, 0.8744992242F, 0.8747721653F, 0.8750447496F,
  144209. 0.8753169770F, 0.8755888475F, 0.8758603611F, 0.8761315177F,
  144210. 0.8764023175F, 0.8766727603F, 0.8769428462F, 0.8772125752F,
  144211. 0.8774819474F, 0.8777509626F, 0.8780196209F, 0.8782879224F,
  144212. 0.8785558669F, 0.8788234546F, 0.8790906854F, 0.8793575594F,
  144213. 0.8796240765F, 0.8798902368F, 0.8801560403F, 0.8804214870F,
  144214. 0.8806865768F, 0.8809513099F, 0.8812156863F, 0.8814797059F,
  144215. 0.8817433687F, 0.8820066749F, 0.8822696243F, 0.8825322171F,
  144216. 0.8827944532F, 0.8830563327F, 0.8833178556F, 0.8835790219F,
  144217. 0.8838398316F, 0.8841002848F, 0.8843603815F, 0.8846201217F,
  144218. 0.8848795054F, 0.8851385327F, 0.8853972036F, 0.8856555182F,
  144219. 0.8859134764F, 0.8861710783F, 0.8864283239F, 0.8866852133F,
  144220. 0.8869417464F, 0.8871979234F, 0.8874537443F, 0.8877092090F,
  144221. 0.8879643177F, 0.8882190704F, 0.8884734671F, 0.8887275078F,
  144222. 0.8889811927F, 0.8892345216F, 0.8894874948F, 0.8897401122F,
  144223. 0.8899923738F, 0.8902442798F, 0.8904958301F, 0.8907470248F,
  144224. 0.8909978640F, 0.8912483477F, 0.8914984759F, 0.8917482487F,
  144225. 0.8919976662F, 0.8922467284F, 0.8924954353F, 0.8927437871F,
  144226. 0.8929917837F, 0.8932394252F, 0.8934867118F, 0.8937336433F,
  144227. 0.8939802199F, 0.8942264417F, 0.8944723087F, 0.8947178210F,
  144228. 0.8949629785F, 0.8952077815F, 0.8954522299F, 0.8956963239F,
  144229. 0.8959400634F, 0.8961834486F, 0.8964264795F, 0.8966691561F,
  144230. 0.8969114786F, 0.8971534470F, 0.8973950614F, 0.8976363219F,
  144231. 0.8978772284F, 0.8981177812F, 0.8983579802F, 0.8985978256F,
  144232. 0.8988373174F, 0.8990764556F, 0.8993152405F, 0.8995536720F,
  144233. 0.8997917502F, 0.9000294751F, 0.9002668470F, 0.9005038658F,
  144234. 0.9007405317F, 0.9009768446F, 0.9012128048F, 0.9014484123F,
  144235. 0.9016836671F, 0.9019185693F, 0.9021531191F, 0.9023873165F,
  144236. 0.9026211616F, 0.9028546546F, 0.9030877954F, 0.9033205841F,
  144237. 0.9035530210F, 0.9037851059F, 0.9040168392F, 0.9042482207F,
  144238. 0.9044792507F, 0.9047099293F, 0.9049402564F, 0.9051702323F,
  144239. 0.9053998569F, 0.9056291305F, 0.9058580531F, 0.9060866248F,
  144240. 0.9063148457F, 0.9065427159F, 0.9067702355F, 0.9069974046F,
  144241. 0.9072242233F, 0.9074506917F, 0.9076768100F, 0.9079025782F,
  144242. 0.9081279964F, 0.9083530647F, 0.9085777833F, 0.9088021523F,
  144243. 0.9090261717F, 0.9092498417F, 0.9094731623F, 0.9096961338F,
  144244. 0.9099187561F, 0.9101410295F, 0.9103629540F, 0.9105845297F,
  144245. 0.9108057568F, 0.9110266354F, 0.9112471656F, 0.9114673475F,
  144246. 0.9116871812F, 0.9119066668F, 0.9121258046F, 0.9123445945F,
  144247. 0.9125630367F, 0.9127811314F, 0.9129988786F, 0.9132162785F,
  144248. 0.9134333312F, 0.9136500368F, 0.9138663954F, 0.9140824073F,
  144249. 0.9142980724F, 0.9145133910F, 0.9147283632F, 0.9149429890F,
  144250. 0.9151572687F, 0.9153712023F, 0.9155847900F, 0.9157980319F,
  144251. 0.9160109282F, 0.9162234790F, 0.9164356844F, 0.9166475445F,
  144252. 0.9168590595F, 0.9170702296F, 0.9172810548F, 0.9174915354F,
  144253. 0.9177016714F, 0.9179114629F, 0.9181209102F, 0.9183300134F,
  144254. 0.9185387726F, 0.9187471879F, 0.9189552595F, 0.9191629876F,
  144255. 0.9193703723F, 0.9195774136F, 0.9197841119F, 0.9199904672F,
  144256. 0.9201964797F, 0.9204021495F, 0.9206074767F, 0.9208124616F,
  144257. 0.9210171043F, 0.9212214049F, 0.9214253636F, 0.9216289805F,
  144258. 0.9218322558F, 0.9220351896F, 0.9222377821F, 0.9224400335F,
  144259. 0.9226419439F, 0.9228435134F, 0.9230447423F, 0.9232456307F,
  144260. 0.9234461787F, 0.9236463865F, 0.9238462543F, 0.9240457822F,
  144261. 0.9242449704F, 0.9244438190F, 0.9246423282F, 0.9248404983F,
  144262. 0.9250383293F, 0.9252358214F, 0.9254329747F, 0.9256297896F,
  144263. 0.9258262660F, 0.9260224042F, 0.9262182044F, 0.9264136667F,
  144264. 0.9266087913F, 0.9268035783F, 0.9269980280F, 0.9271921405F,
  144265. 0.9273859160F, 0.9275793546F, 0.9277724566F, 0.9279652221F,
  144266. 0.9281576513F, 0.9283497443F, 0.9285415014F, 0.9287329227F,
  144267. 0.9289240084F, 0.9291147586F, 0.9293051737F, 0.9294952536F,
  144268. 0.9296849987F, 0.9298744091F, 0.9300634850F, 0.9302522266F,
  144269. 0.9304406340F, 0.9306287074F, 0.9308164471F, 0.9310038532F,
  144270. 0.9311909259F, 0.9313776654F, 0.9315640719F, 0.9317501455F,
  144271. 0.9319358865F, 0.9321212951F, 0.9323063713F, 0.9324911155F,
  144272. 0.9326755279F, 0.9328596085F, 0.9330433577F, 0.9332267756F,
  144273. 0.9334098623F, 0.9335926182F, 0.9337750434F, 0.9339571380F,
  144274. 0.9341389023F, 0.9343203366F, 0.9345014409F, 0.9346822155F,
  144275. 0.9348626606F, 0.9350427763F, 0.9352225630F, 0.9354020207F,
  144276. 0.9355811498F, 0.9357599503F, 0.9359384226F, 0.9361165667F,
  144277. 0.9362943830F, 0.9364718716F, 0.9366490327F, 0.9368258666F,
  144278. 0.9370023733F, 0.9371785533F, 0.9373544066F, 0.9375299335F,
  144279. 0.9377051341F, 0.9378800087F, 0.9380545576F, 0.9382287809F,
  144280. 0.9384026787F, 0.9385762515F, 0.9387494993F, 0.9389224223F,
  144281. 0.9390950209F, 0.9392672951F, 0.9394392453F, 0.9396108716F,
  144282. 0.9397821743F, 0.9399531536F, 0.9401238096F, 0.9402941427F,
  144283. 0.9404641530F, 0.9406338407F, 0.9408032061F, 0.9409722495F,
  144284. 0.9411409709F, 0.9413093707F, 0.9414774491F, 0.9416452062F,
  144285. 0.9418126424F, 0.9419797579F, 0.9421465528F, 0.9423130274F,
  144286. 0.9424791819F, 0.9426450166F, 0.9428105317F, 0.9429757274F,
  144287. 0.9431406039F, 0.9433051616F, 0.9434694005F, 0.9436333209F,
  144288. 0.9437969232F, 0.9439602074F, 0.9441231739F, 0.9442858229F,
  144289. 0.9444481545F, 0.9446101691F, 0.9447718669F, 0.9449332481F,
  144290. 0.9450943129F, 0.9452550617F, 0.9454154945F, 0.9455756118F,
  144291. 0.9457354136F, 0.9458949003F, 0.9460540721F, 0.9462129292F,
  144292. 0.9463714719F, 0.9465297003F, 0.9466876149F, 0.9468452157F,
  144293. 0.9470025031F, 0.9471594772F, 0.9473161384F, 0.9474724869F,
  144294. 0.9476285229F, 0.9477842466F, 0.9479396584F, 0.9480947585F,
  144295. 0.9482495470F, 0.9484040243F, 0.9485581906F, 0.9487120462F,
  144296. 0.9488655913F, 0.9490188262F, 0.9491717511F, 0.9493243662F,
  144297. 0.9494766718F, 0.9496286683F, 0.9497803557F, 0.9499317345F,
  144298. 0.9500828047F, 0.9502335668F, 0.9503840209F, 0.9505341673F,
  144299. 0.9506840062F, 0.9508335380F, 0.9509827629F, 0.9511316810F,
  144300. 0.9512802928F, 0.9514285984F, 0.9515765982F, 0.9517242923F,
  144301. 0.9518716810F, 0.9520187646F, 0.9521655434F, 0.9523120176F,
  144302. 0.9524581875F, 0.9526040534F, 0.9527496154F, 0.9528948739F,
  144303. 0.9530398292F, 0.9531844814F, 0.9533288310F, 0.9534728780F,
  144304. 0.9536166229F, 0.9537600659F, 0.9539032071F, 0.9540460470F,
  144305. 0.9541885858F, 0.9543308237F, 0.9544727611F, 0.9546143981F,
  144306. 0.9547557351F, 0.9548967723F, 0.9550375100F, 0.9551779485F,
  144307. 0.9553180881F, 0.9554579290F, 0.9555974714F, 0.9557367158F,
  144308. 0.9558756623F, 0.9560143112F, 0.9561526628F, 0.9562907174F,
  144309. 0.9564284752F, 0.9565659366F, 0.9567031017F, 0.9568399710F,
  144310. 0.9569765446F, 0.9571128229F, 0.9572488061F, 0.9573844944F,
  144311. 0.9575198883F, 0.9576549879F, 0.9577897936F, 0.9579243056F,
  144312. 0.9580585242F, 0.9581924497F, 0.9583260824F, 0.9584594226F,
  144313. 0.9585924705F, 0.9587252264F, 0.9588576906F, 0.9589898634F,
  144314. 0.9591217452F, 0.9592533360F, 0.9593846364F, 0.9595156465F,
  144315. 0.9596463666F, 0.9597767971F, 0.9599069382F, 0.9600367901F,
  144316. 0.9601663533F, 0.9602956279F, 0.9604246143F, 0.9605533128F,
  144317. 0.9606817236F, 0.9608098471F, 0.9609376835F, 0.9610652332F,
  144318. 0.9611924963F, 0.9613194733F, 0.9614461644F, 0.9615725699F,
  144319. 0.9616986901F, 0.9618245253F, 0.9619500757F, 0.9620753418F,
  144320. 0.9622003238F, 0.9623250219F, 0.9624494365F, 0.9625735679F,
  144321. 0.9626974163F, 0.9628209821F, 0.9629442656F, 0.9630672671F,
  144322. 0.9631899868F, 0.9633124251F, 0.9634345822F, 0.9635564585F,
  144323. 0.9636780543F, 0.9637993699F, 0.9639204056F, 0.9640411616F,
  144324. 0.9641616383F, 0.9642818359F, 0.9644017549F, 0.9645213955F,
  144325. 0.9646407579F, 0.9647598426F, 0.9648786497F, 0.9649971797F,
  144326. 0.9651154328F, 0.9652334092F, 0.9653511095F, 0.9654685337F,
  144327. 0.9655856823F, 0.9657025556F, 0.9658191538F, 0.9659354773F,
  144328. 0.9660515263F, 0.9661673013F, 0.9662828024F, 0.9663980300F,
  144329. 0.9665129845F, 0.9666276660F, 0.9667420750F, 0.9668562118F,
  144330. 0.9669700766F, 0.9670836698F, 0.9671969917F, 0.9673100425F,
  144331. 0.9674228227F, 0.9675353325F, 0.9676475722F, 0.9677595422F,
  144332. 0.9678712428F, 0.9679826742F, 0.9680938368F, 0.9682047309F,
  144333. 0.9683153569F, 0.9684257150F, 0.9685358056F, 0.9686456289F,
  144334. 0.9687551853F, 0.9688644752F, 0.9689734987F, 0.9690822564F,
  144335. 0.9691907483F, 0.9692989750F, 0.9694069367F, 0.9695146337F,
  144336. 0.9696220663F, 0.9697292349F, 0.9698361398F, 0.9699427813F,
  144337. 0.9700491597F, 0.9701552754F, 0.9702611286F, 0.9703667197F,
  144338. 0.9704720490F, 0.9705771169F, 0.9706819236F, 0.9707864695F,
  144339. 0.9708907549F, 0.9709947802F, 0.9710985456F, 0.9712020514F,
  144340. 0.9713052981F, 0.9714082859F, 0.9715110151F, 0.9716134862F,
  144341. 0.9717156993F, 0.9718176549F, 0.9719193532F, 0.9720207946F,
  144342. 0.9721219794F, 0.9722229080F, 0.9723235806F, 0.9724239976F,
  144343. 0.9725241593F, 0.9726240661F, 0.9727237183F, 0.9728231161F,
  144344. 0.9729222601F, 0.9730211503F, 0.9731197873F, 0.9732181713F,
  144345. 0.9733163027F, 0.9734141817F, 0.9735118088F, 0.9736091842F,
  144346. 0.9737063083F, 0.9738031814F, 0.9738998039F, 0.9739961760F,
  144347. 0.9740922981F, 0.9741881706F, 0.9742837938F, 0.9743791680F,
  144348. 0.9744742935F, 0.9745691707F, 0.9746637999F, 0.9747581814F,
  144349. 0.9748523157F, 0.9749462029F, 0.9750398435F, 0.9751332378F,
  144350. 0.9752263861F, 0.9753192887F, 0.9754119461F, 0.9755043585F,
  144351. 0.9755965262F, 0.9756884496F, 0.9757801291F, 0.9758715650F,
  144352. 0.9759627575F, 0.9760537071F, 0.9761444141F, 0.9762348789F,
  144353. 0.9763251016F, 0.9764150828F, 0.9765048228F, 0.9765943218F,
  144354. 0.9766835802F, 0.9767725984F, 0.9768613767F, 0.9769499154F,
  144355. 0.9770382149F, 0.9771262755F, 0.9772140976F, 0.9773016815F,
  144356. 0.9773890275F, 0.9774761360F, 0.9775630073F, 0.9776496418F,
  144357. 0.9777360398F, 0.9778222016F, 0.9779081277F, 0.9779938182F,
  144358. 0.9780792736F, 0.9781644943F, 0.9782494805F, 0.9783342326F,
  144359. 0.9784187509F, 0.9785030359F, 0.9785870877F, 0.9786709069F,
  144360. 0.9787544936F, 0.9788378484F, 0.9789209714F, 0.9790038631F,
  144361. 0.9790865238F, 0.9791689538F, 0.9792511535F, 0.9793331232F,
  144362. 0.9794148633F, 0.9794963742F, 0.9795776561F, 0.9796587094F,
  144363. 0.9797395345F, 0.9798201316F, 0.9799005013F, 0.9799806437F,
  144364. 0.9800605593F, 0.9801402483F, 0.9802197112F, 0.9802989483F,
  144365. 0.9803779600F, 0.9804567465F, 0.9805353082F, 0.9806136455F,
  144366. 0.9806917587F, 0.9807696482F, 0.9808473143F, 0.9809247574F,
  144367. 0.9810019778F, 0.9810789759F, 0.9811557519F, 0.9812323064F,
  144368. 0.9813086395F, 0.9813847517F, 0.9814606433F, 0.9815363147F,
  144369. 0.9816117662F, 0.9816869981F, 0.9817620108F, 0.9818368047F,
  144370. 0.9819113801F, 0.9819857374F, 0.9820598769F, 0.9821337989F,
  144371. 0.9822075038F, 0.9822809920F, 0.9823542638F, 0.9824273195F,
  144372. 0.9825001596F, 0.9825727843F, 0.9826451940F, 0.9827173891F,
  144373. 0.9827893700F, 0.9828611368F, 0.9829326901F, 0.9830040302F,
  144374. 0.9830751574F, 0.9831460720F, 0.9832167745F, 0.9832872652F,
  144375. 0.9833575444F, 0.9834276124F, 0.9834974697F, 0.9835671166F,
  144376. 0.9836365535F, 0.9837057806F, 0.9837747983F, 0.9838436071F,
  144377. 0.9839122072F, 0.9839805990F, 0.9840487829F, 0.9841167591F,
  144378. 0.9841845282F, 0.9842520903F, 0.9843194459F, 0.9843865953F,
  144379. 0.9844535389F, 0.9845202771F, 0.9845868101F, 0.9846531383F,
  144380. 0.9847192622F, 0.9847851820F, 0.9848508980F, 0.9849164108F,
  144381. 0.9849817205F, 0.9850468276F, 0.9851117324F, 0.9851764352F,
  144382. 0.9852409365F, 0.9853052366F, 0.9853693358F, 0.9854332344F,
  144383. 0.9854969330F, 0.9855604317F, 0.9856237309F, 0.9856868310F,
  144384. 0.9857497325F, 0.9858124355F, 0.9858749404F, 0.9859372477F,
  144385. 0.9859993577F, 0.9860612707F, 0.9861229871F, 0.9861845072F,
  144386. 0.9862458315F, 0.9863069601F, 0.9863678936F, 0.9864286322F,
  144387. 0.9864891764F, 0.9865495264F, 0.9866096826F, 0.9866696454F,
  144388. 0.9867294152F, 0.9867889922F, 0.9868483769F, 0.9869075695F,
  144389. 0.9869665706F, 0.9870253803F, 0.9870839991F, 0.9871424273F,
  144390. 0.9872006653F, 0.9872587135F, 0.9873165721F, 0.9873742415F,
  144391. 0.9874317222F, 0.9874890144F, 0.9875461185F, 0.9876030348F,
  144392. 0.9876597638F, 0.9877163057F, 0.9877726610F, 0.9878288300F,
  144393. 0.9878848130F, 0.9879406104F, 0.9879962225F, 0.9880516497F,
  144394. 0.9881068924F, 0.9881619509F, 0.9882168256F, 0.9882715168F,
  144395. 0.9883260249F, 0.9883803502F, 0.9884344931F, 0.9884884539F,
  144396. 0.9885422331F, 0.9885958309F, 0.9886492477F, 0.9887024838F,
  144397. 0.9887555397F, 0.9888084157F, 0.9888611120F, 0.9889136292F,
  144398. 0.9889659675F, 0.9890181273F, 0.9890701089F, 0.9891219128F,
  144399. 0.9891735392F, 0.9892249885F, 0.9892762610F, 0.9893273572F,
  144400. 0.9893782774F, 0.9894290219F, 0.9894795911F, 0.9895299853F,
  144401. 0.9895802049F, 0.9896302502F, 0.9896801217F, 0.9897298196F,
  144402. 0.9897793443F, 0.9898286961F, 0.9898778755F, 0.9899268828F,
  144403. 0.9899757183F, 0.9900243823F, 0.9900728753F, 0.9901211976F,
  144404. 0.9901693495F, 0.9902173314F, 0.9902651436F, 0.9903127865F,
  144405. 0.9903602605F, 0.9904075659F, 0.9904547031F, 0.9905016723F,
  144406. 0.9905484740F, 0.9905951086F, 0.9906415763F, 0.9906878775F,
  144407. 0.9907340126F, 0.9907799819F, 0.9908257858F, 0.9908714247F,
  144408. 0.9909168988F, 0.9909622086F, 0.9910073543F, 0.9910523364F,
  144409. 0.9910971552F, 0.9911418110F, 0.9911863042F, 0.9912306351F,
  144410. 0.9912748042F, 0.9913188117F, 0.9913626580F, 0.9914063435F,
  144411. 0.9914498684F, 0.9914932333F, 0.9915364383F, 0.9915794839F,
  144412. 0.9916223703F, 0.9916650981F, 0.9917076674F, 0.9917500787F,
  144413. 0.9917923323F, 0.9918344286F, 0.9918763679F, 0.9919181505F,
  144414. 0.9919597769F, 0.9920012473F, 0.9920425621F, 0.9920837217F,
  144415. 0.9921247263F, 0.9921655765F, 0.9922062724F, 0.9922468145F,
  144416. 0.9922872030F, 0.9923274385F, 0.9923675211F, 0.9924074513F,
  144417. 0.9924472294F, 0.9924868557F, 0.9925263306F, 0.9925656544F,
  144418. 0.9926048275F, 0.9926438503F, 0.9926827230F, 0.9927214461F,
  144419. 0.9927600199F, 0.9927984446F, 0.9928367208F, 0.9928748486F,
  144420. 0.9929128285F, 0.9929506608F, 0.9929883459F, 0.9930258841F,
  144421. 0.9930632757F, 0.9931005211F, 0.9931376207F, 0.9931745747F,
  144422. 0.9932113836F, 0.9932480476F, 0.9932845671F, 0.9933209425F,
  144423. 0.9933571742F, 0.9933932623F, 0.9934292074F, 0.9934650097F,
  144424. 0.9935006696F, 0.9935361874F, 0.9935715635F, 0.9936067982F,
  144425. 0.9936418919F, 0.9936768448F, 0.9937116574F, 0.9937463300F,
  144426. 0.9937808629F, 0.9938152565F, 0.9938495111F, 0.9938836271F,
  144427. 0.9939176047F, 0.9939514444F, 0.9939851465F, 0.9940187112F,
  144428. 0.9940521391F, 0.9940854303F, 0.9941185853F, 0.9941516044F,
  144429. 0.9941844879F, 0.9942172361F, 0.9942498495F, 0.9942823283F,
  144430. 0.9943146729F, 0.9943468836F, 0.9943789608F, 0.9944109047F,
  144431. 0.9944427158F, 0.9944743944F, 0.9945059408F, 0.9945373553F,
  144432. 0.9945686384F, 0.9945997902F, 0.9946308112F, 0.9946617017F,
  144433. 0.9946924621F, 0.9947230926F, 0.9947535937F, 0.9947839656F,
  144434. 0.9948142086F, 0.9948443232F, 0.9948743097F, 0.9949041683F,
  144435. 0.9949338995F, 0.9949635035F, 0.9949929807F, 0.9950223315F,
  144436. 0.9950515561F, 0.9950806549F, 0.9951096282F, 0.9951384764F,
  144437. 0.9951671998F, 0.9951957987F, 0.9952242735F, 0.9952526245F,
  144438. 0.9952808520F, 0.9953089564F, 0.9953369380F, 0.9953647971F,
  144439. 0.9953925340F, 0.9954201491F, 0.9954476428F, 0.9954750153F,
  144440. 0.9955022670F, 0.9955293981F, 0.9955564092F, 0.9955833003F,
  144441. 0.9956100720F, 0.9956367245F, 0.9956632582F, 0.9956896733F,
  144442. 0.9957159703F, 0.9957421494F, 0.9957682110F, 0.9957941553F,
  144443. 0.9958199828F, 0.9958456937F, 0.9958712884F, 0.9958967672F,
  144444. 0.9959221305F, 0.9959473784F, 0.9959725115F, 0.9959975300F,
  144445. 0.9960224342F, 0.9960472244F, 0.9960719011F, 0.9960964644F,
  144446. 0.9961209148F, 0.9961452525F, 0.9961694779F, 0.9961935913F,
  144447. 0.9962175930F, 0.9962414834F, 0.9962652627F, 0.9962889313F,
  144448. 0.9963124895F, 0.9963359377F, 0.9963592761F, 0.9963825051F,
  144449. 0.9964056250F, 0.9964286361F, 0.9964515387F, 0.9964743332F,
  144450. 0.9964970198F, 0.9965195990F, 0.9965420709F, 0.9965644360F,
  144451. 0.9965866946F, 0.9966088469F, 0.9966308932F, 0.9966528340F,
  144452. 0.9966746695F, 0.9966964001F, 0.9967180260F, 0.9967395475F,
  144453. 0.9967609651F, 0.9967822789F, 0.9968034894F, 0.9968245968F,
  144454. 0.9968456014F, 0.9968665036F, 0.9968873037F, 0.9969080019F,
  144455. 0.9969285987F, 0.9969490942F, 0.9969694889F, 0.9969897830F,
  144456. 0.9970099769F, 0.9970300708F, 0.9970500651F, 0.9970699601F,
  144457. 0.9970897561F, 0.9971094533F, 0.9971290522F, 0.9971485531F,
  144458. 0.9971679561F, 0.9971872617F, 0.9972064702F, 0.9972255818F,
  144459. 0.9972445968F, 0.9972635157F, 0.9972823386F, 0.9973010659F,
  144460. 0.9973196980F, 0.9973382350F, 0.9973566773F, 0.9973750253F,
  144461. 0.9973932791F, 0.9974114392F, 0.9974295059F, 0.9974474793F,
  144462. 0.9974653599F, 0.9974831480F, 0.9975008438F, 0.9975184476F,
  144463. 0.9975359598F, 0.9975533806F, 0.9975707104F, 0.9975879495F,
  144464. 0.9976050981F, 0.9976221566F, 0.9976391252F, 0.9976560043F,
  144465. 0.9976727941F, 0.9976894950F, 0.9977061073F, 0.9977226312F,
  144466. 0.9977390671F, 0.9977554152F, 0.9977716759F, 0.9977878495F,
  144467. 0.9978039361F, 0.9978199363F, 0.9978358501F, 0.9978516780F,
  144468. 0.9978674202F, 0.9978830771F, 0.9978986488F, 0.9979141358F,
  144469. 0.9979295383F, 0.9979448566F, 0.9979600909F, 0.9979752417F,
  144470. 0.9979903091F, 0.9980052936F, 0.9980201952F, 0.9980350145F,
  144471. 0.9980497515F, 0.9980644067F, 0.9980789804F, 0.9980934727F,
  144472. 0.9981078841F, 0.9981222147F, 0.9981364649F, 0.9981506350F,
  144473. 0.9981647253F, 0.9981787360F, 0.9981926674F, 0.9982065199F,
  144474. 0.9982202936F, 0.9982339890F, 0.9982476062F, 0.9982611456F,
  144475. 0.9982746074F, 0.9982879920F, 0.9983012996F, 0.9983145304F,
  144476. 0.9983276849F, 0.9983407632F, 0.9983537657F, 0.9983666926F,
  144477. 0.9983795442F, 0.9983923208F, 0.9984050226F, 0.9984176501F,
  144478. 0.9984302033F, 0.9984426827F, 0.9984550884F, 0.9984674208F,
  144479. 0.9984796802F, 0.9984918667F, 0.9985039808F, 0.9985160227F,
  144480. 0.9985279926F, 0.9985398909F, 0.9985517177F, 0.9985634734F,
  144481. 0.9985751583F, 0.9985867727F, 0.9985983167F, 0.9986097907F,
  144482. 0.9986211949F, 0.9986325297F, 0.9986437953F, 0.9986549919F,
  144483. 0.9986661199F, 0.9986771795F, 0.9986881710F, 0.9986990946F,
  144484. 0.9987099507F, 0.9987207394F, 0.9987314611F, 0.9987421161F,
  144485. 0.9987527045F, 0.9987632267F, 0.9987736829F, 0.9987840734F,
  144486. 0.9987943985F, 0.9988046584F, 0.9988148534F, 0.9988249838F,
  144487. 0.9988350498F, 0.9988450516F, 0.9988549897F, 0.9988648641F,
  144488. 0.9988746753F, 0.9988844233F, 0.9988941086F, 0.9989037313F,
  144489. 0.9989132918F, 0.9989227902F, 0.9989322269F, 0.9989416021F,
  144490. 0.9989509160F, 0.9989601690F, 0.9989693613F, 0.9989784931F,
  144491. 0.9989875647F, 0.9989965763F, 0.9990055283F, 0.9990144208F,
  144492. 0.9990232541F, 0.9990320286F, 0.9990407443F, 0.9990494016F,
  144493. 0.9990580008F, 0.9990665421F, 0.9990750257F, 0.9990834519F,
  144494. 0.9990918209F, 0.9991001331F, 0.9991083886F, 0.9991165877F,
  144495. 0.9991247307F, 0.9991328177F, 0.9991408491F, 0.9991488251F,
  144496. 0.9991567460F, 0.9991646119F, 0.9991724232F, 0.9991801801F,
  144497. 0.9991878828F, 0.9991955316F, 0.9992031267F, 0.9992106684F,
  144498. 0.9992181569F, 0.9992255925F, 0.9992329753F, 0.9992403057F,
  144499. 0.9992475839F, 0.9992548101F, 0.9992619846F, 0.9992691076F,
  144500. 0.9992761793F, 0.9992832001F, 0.9992901701F, 0.9992970895F,
  144501. 0.9993039587F, 0.9993107777F, 0.9993175470F, 0.9993242667F,
  144502. 0.9993309371F, 0.9993375583F, 0.9993441307F, 0.9993506545F,
  144503. 0.9993571298F, 0.9993635570F, 0.9993699362F, 0.9993762678F,
  144504. 0.9993825519F, 0.9993887887F, 0.9993949785F, 0.9994011216F,
  144505. 0.9994072181F, 0.9994132683F, 0.9994192725F, 0.9994252307F,
  144506. 0.9994311434F, 0.9994370107F, 0.9994428327F, 0.9994486099F,
  144507. 0.9994543423F, 0.9994600303F, 0.9994656739F, 0.9994712736F,
  144508. 0.9994768294F, 0.9994823417F, 0.9994878105F, 0.9994932363F,
  144509. 0.9994986191F, 0.9995039592F, 0.9995092568F, 0.9995145122F,
  144510. 0.9995197256F, 0.9995248971F, 0.9995300270F, 0.9995351156F,
  144511. 0.9995401630F, 0.9995451695F, 0.9995501352F, 0.9995550604F,
  144512. 0.9995599454F, 0.9995647903F, 0.9995695953F, 0.9995743607F,
  144513. 0.9995790866F, 0.9995837734F, 0.9995884211F, 0.9995930300F,
  144514. 0.9995976004F, 0.9996021324F, 0.9996066263F, 0.9996110822F,
  144515. 0.9996155004F, 0.9996198810F, 0.9996242244F, 0.9996285306F,
  144516. 0.9996327999F, 0.9996370326F, 0.9996412287F, 0.9996453886F,
  144517. 0.9996495125F, 0.9996536004F, 0.9996576527F, 0.9996616696F,
  144518. 0.9996656512F, 0.9996695977F, 0.9996735094F, 0.9996773865F,
  144519. 0.9996812291F, 0.9996850374F, 0.9996888118F, 0.9996925523F,
  144520. 0.9996962591F, 0.9996999325F, 0.9997035727F, 0.9997071798F,
  144521. 0.9997107541F, 0.9997142957F, 0.9997178049F, 0.9997212818F,
  144522. 0.9997247266F, 0.9997281396F, 0.9997315209F, 0.9997348708F,
  144523. 0.9997381893F, 0.9997414767F, 0.9997447333F, 0.9997479591F,
  144524. 0.9997511544F, 0.9997543194F, 0.9997574542F, 0.9997605591F,
  144525. 0.9997636342F, 0.9997666797F, 0.9997696958F, 0.9997726828F,
  144526. 0.9997756407F, 0.9997785698F, 0.9997814703F, 0.9997843423F,
  144527. 0.9997871860F, 0.9997900016F, 0.9997927894F, 0.9997955494F,
  144528. 0.9997982818F, 0.9998009869F, 0.9998036648F, 0.9998063157F,
  144529. 0.9998089398F, 0.9998115373F, 0.9998141082F, 0.9998166529F,
  144530. 0.9998191715F, 0.9998216642F, 0.9998241311F, 0.9998265724F,
  144531. 0.9998289884F, 0.9998313790F, 0.9998337447F, 0.9998360854F,
  144532. 0.9998384015F, 0.9998406930F, 0.9998429602F, 0.9998452031F,
  144533. 0.9998474221F, 0.9998496171F, 0.9998517885F, 0.9998539364F,
  144534. 0.9998560610F, 0.9998581624F, 0.9998602407F, 0.9998622962F,
  144535. 0.9998643291F, 0.9998663394F, 0.9998683274F, 0.9998702932F,
  144536. 0.9998722370F, 0.9998741589F, 0.9998760591F, 0.9998779378F,
  144537. 0.9998797952F, 0.9998816313F, 0.9998834464F, 0.9998852406F,
  144538. 0.9998870141F, 0.9998887670F, 0.9998904995F, 0.9998922117F,
  144539. 0.9998939039F, 0.9998955761F, 0.9998972285F, 0.9998988613F,
  144540. 0.9999004746F, 0.9999020686F, 0.9999036434F, 0.9999051992F,
  144541. 0.9999067362F, 0.9999082544F, 0.9999097541F, 0.9999112354F,
  144542. 0.9999126984F, 0.9999141433F, 0.9999155703F, 0.9999169794F,
  144543. 0.9999183709F, 0.9999197449F, 0.9999211014F, 0.9999224408F,
  144544. 0.9999237631F, 0.9999250684F, 0.9999263570F, 0.9999276289F,
  144545. 0.9999288843F, 0.9999301233F, 0.9999313461F, 0.9999325529F,
  144546. 0.9999337437F, 0.9999349187F, 0.9999360780F, 0.9999372218F,
  144547. 0.9999383503F, 0.9999394635F, 0.9999405616F, 0.9999416447F,
  144548. 0.9999427129F, 0.9999437665F, 0.9999448055F, 0.9999458301F,
  144549. 0.9999468404F, 0.9999478365F, 0.9999488185F, 0.9999497867F,
  144550. 0.9999507411F, 0.9999516819F, 0.9999526091F, 0.9999535230F,
  144551. 0.9999544236F, 0.9999553111F, 0.9999561856F, 0.9999570472F,
  144552. 0.9999578960F, 0.9999587323F, 0.9999595560F, 0.9999603674F,
  144553. 0.9999611666F, 0.9999619536F, 0.9999627286F, 0.9999634917F,
  144554. 0.9999642431F, 0.9999649828F, 0.9999657110F, 0.9999664278F,
  144555. 0.9999671334F, 0.9999678278F, 0.9999685111F, 0.9999691835F,
  144556. 0.9999698451F, 0.9999704960F, 0.9999711364F, 0.9999717662F,
  144557. 0.9999723858F, 0.9999729950F, 0.9999735942F, 0.9999741834F,
  144558. 0.9999747626F, 0.9999753321F, 0.9999758919F, 0.9999764421F,
  144559. 0.9999769828F, 0.9999775143F, 0.9999780364F, 0.9999785495F,
  144560. 0.9999790535F, 0.9999795485F, 0.9999800348F, 0.9999805124F,
  144561. 0.9999809813F, 0.9999814417F, 0.9999818938F, 0.9999823375F,
  144562. 0.9999827731F, 0.9999832005F, 0.9999836200F, 0.9999840316F,
  144563. 0.9999844353F, 0.9999848314F, 0.9999852199F, 0.9999856008F,
  144564. 0.9999859744F, 0.9999863407F, 0.9999866997F, 0.9999870516F,
  144565. 0.9999873965F, 0.9999877345F, 0.9999880656F, 0.9999883900F,
  144566. 0.9999887078F, 0.9999890190F, 0.9999893237F, 0.9999896220F,
  144567. 0.9999899140F, 0.9999901999F, 0.9999904796F, 0.9999907533F,
  144568. 0.9999910211F, 0.9999912830F, 0.9999915391F, 0.9999917896F,
  144569. 0.9999920345F, 0.9999922738F, 0.9999925077F, 0.9999927363F,
  144570. 0.9999929596F, 0.9999931777F, 0.9999933907F, 0.9999935987F,
  144571. 0.9999938018F, 0.9999940000F, 0.9999941934F, 0.9999943820F,
  144572. 0.9999945661F, 0.9999947456F, 0.9999949206F, 0.9999950912F,
  144573. 0.9999952575F, 0.9999954195F, 0.9999955773F, 0.9999957311F,
  144574. 0.9999958807F, 0.9999960265F, 0.9999961683F, 0.9999963063F,
  144575. 0.9999964405F, 0.9999965710F, 0.9999966979F, 0.9999968213F,
  144576. 0.9999969412F, 0.9999970576F, 0.9999971707F, 0.9999972805F,
  144577. 0.9999973871F, 0.9999974905F, 0.9999975909F, 0.9999976881F,
  144578. 0.9999977824F, 0.9999978738F, 0.9999979624F, 0.9999980481F,
  144579. 0.9999981311F, 0.9999982115F, 0.9999982892F, 0.9999983644F,
  144580. 0.9999984370F, 0.9999985072F, 0.9999985750F, 0.9999986405F,
  144581. 0.9999987037F, 0.9999987647F, 0.9999988235F, 0.9999988802F,
  144582. 0.9999989348F, 0.9999989873F, 0.9999990379F, 0.9999990866F,
  144583. 0.9999991334F, 0.9999991784F, 0.9999992217F, 0.9999992632F,
  144584. 0.9999993030F, 0.9999993411F, 0.9999993777F, 0.9999994128F,
  144585. 0.9999994463F, 0.9999994784F, 0.9999995091F, 0.9999995384F,
  144586. 0.9999995663F, 0.9999995930F, 0.9999996184F, 0.9999996426F,
  144587. 0.9999996657F, 0.9999996876F, 0.9999997084F, 0.9999997282F,
  144588. 0.9999997469F, 0.9999997647F, 0.9999997815F, 0.9999997973F,
  144589. 0.9999998123F, 0.9999998265F, 0.9999998398F, 0.9999998524F,
  144590. 0.9999998642F, 0.9999998753F, 0.9999998857F, 0.9999998954F,
  144591. 0.9999999045F, 0.9999999130F, 0.9999999209F, 0.9999999282F,
  144592. 0.9999999351F, 0.9999999414F, 0.9999999472F, 0.9999999526F,
  144593. 0.9999999576F, 0.9999999622F, 0.9999999664F, 0.9999999702F,
  144594. 0.9999999737F, 0.9999999769F, 0.9999999798F, 0.9999999824F,
  144595. 0.9999999847F, 0.9999999868F, 0.9999999887F, 0.9999999904F,
  144596. 0.9999999919F, 0.9999999932F, 0.9999999943F, 0.9999999953F,
  144597. 0.9999999961F, 0.9999999969F, 0.9999999975F, 0.9999999980F,
  144598. 0.9999999985F, 0.9999999988F, 0.9999999991F, 0.9999999993F,
  144599. 0.9999999995F, 0.9999999997F, 0.9999999998F, 0.9999999999F,
  144600. 0.9999999999F, 1.0000000000F, 1.0000000000F, 1.0000000000F,
  144601. 1.0000000000F, 1.0000000000F, 1.0000000000F, 1.0000000000F,
  144602. };
  144603. static float *vwin[8] = {
  144604. vwin64,
  144605. vwin128,
  144606. vwin256,
  144607. vwin512,
  144608. vwin1024,
  144609. vwin2048,
  144610. vwin4096,
  144611. vwin8192,
  144612. };
  144613. float *_vorbis_window_get(int n){
  144614. return vwin[n];
  144615. }
  144616. void _vorbis_apply_window(float *d,int *winno,long *blocksizes,
  144617. int lW,int W,int nW){
  144618. lW=(W?lW:0);
  144619. nW=(W?nW:0);
  144620. {
  144621. float *windowLW=vwin[winno[lW]];
  144622. float *windowNW=vwin[winno[nW]];
  144623. long n=blocksizes[W];
  144624. long ln=blocksizes[lW];
  144625. long rn=blocksizes[nW];
  144626. long leftbegin=n/4-ln/4;
  144627. long leftend=leftbegin+ln/2;
  144628. long rightbegin=n/2+n/4-rn/4;
  144629. long rightend=rightbegin+rn/2;
  144630. int i,p;
  144631. for(i=0;i<leftbegin;i++)
  144632. d[i]=0.f;
  144633. for(p=0;i<leftend;i++,p++)
  144634. d[i]*=windowLW[p];
  144635. for(i=rightbegin,p=rn/2-1;i<rightend;i++,p--)
  144636. d[i]*=windowNW[p];
  144637. for(;i<n;i++)
  144638. d[i]=0.f;
  144639. }
  144640. }
  144641. #endif
  144642. /*** End of inlined file: window.c ***/
  144643. #else
  144644. #include <vorbis/vorbisenc.h>
  144645. #include <vorbis/codec.h>
  144646. #include <vorbis/vorbisfile.h>
  144647. #endif
  144648. }
  144649. BEGIN_JUCE_NAMESPACE
  144650. using namespace OggVorbisNamespace;
  144651. static const char* const oggFormatName = "Ogg-Vorbis file";
  144652. static const tchar* const oggExtensions[] = { T(".ogg"), 0 };
  144653. class OggReader : public AudioFormatReader
  144654. {
  144655. OggVorbis_File ovFile;
  144656. ov_callbacks callbacks;
  144657. AudioSampleBuffer reservoir;
  144658. int reservoirStart, samplesInReservoir;
  144659. public:
  144660. OggReader (InputStream* const inp)
  144661. : AudioFormatReader (inp, TRANS (oggFormatName)),
  144662. reservoir (2, 4096),
  144663. reservoirStart (0),
  144664. samplesInReservoir (0)
  144665. {
  144666. sampleRate = 0;
  144667. usesFloatingPointData = true;
  144668. callbacks.read_func = &oggReadCallback;
  144669. callbacks.seek_func = &oggSeekCallback;
  144670. callbacks.close_func = &oggCloseCallback;
  144671. callbacks.tell_func = &oggTellCallback;
  144672. const int err = ov_open_callbacks (input, &ovFile, 0, 0, callbacks);
  144673. if (err == 0)
  144674. {
  144675. vorbis_info* info = ov_info (&ovFile, -1);
  144676. lengthInSamples = (uint32) ov_pcm_total (&ovFile, -1);
  144677. numChannels = info->channels;
  144678. bitsPerSample = 16;
  144679. sampleRate = info->rate;
  144680. reservoir.setSize (numChannels,
  144681. (int) jmin (lengthInSamples, (int64) reservoir.getNumSamples()));
  144682. }
  144683. }
  144684. ~OggReader()
  144685. {
  144686. ov_clear (&ovFile);
  144687. }
  144688. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  144689. int64 startSampleInFile, int numSamples)
  144690. {
  144691. while (numSamples > 0)
  144692. {
  144693. const int numAvailable = reservoirStart + samplesInReservoir - startSampleInFile;
  144694. if (startSampleInFile >= reservoirStart && numAvailable > 0)
  144695. {
  144696. // got a few samples overlapping, so use them before seeking..
  144697. const int numToUse = jmin (numSamples, numAvailable);
  144698. for (int i = jmin (numDestChannels, reservoir.getNumChannels()); --i >= 0;)
  144699. if (destSamples[i] != 0)
  144700. memcpy (destSamples[i] + startOffsetInDestBuffer,
  144701. reservoir.getSampleData (i, (int) (startSampleInFile - reservoirStart)),
  144702. sizeof (float) * numToUse);
  144703. startSampleInFile += numToUse;
  144704. numSamples -= numToUse;
  144705. startOffsetInDestBuffer += numToUse;
  144706. if (numSamples == 0)
  144707. break;
  144708. }
  144709. if (startSampleInFile < reservoirStart
  144710. || startSampleInFile + numSamples > reservoirStart + samplesInReservoir)
  144711. {
  144712. // buffer miss, so refill the reservoir
  144713. int bitStream = 0;
  144714. reservoirStart = jmax (0, (int) startSampleInFile);
  144715. samplesInReservoir = reservoir.getNumSamples();
  144716. if (reservoirStart != (int) ov_pcm_tell (&ovFile))
  144717. ov_pcm_seek (&ovFile, reservoirStart);
  144718. int offset = 0;
  144719. int numToRead = samplesInReservoir;
  144720. while (numToRead > 0)
  144721. {
  144722. float** dataIn = 0;
  144723. const int samps = ov_read_float (&ovFile, &dataIn, numToRead, &bitStream);
  144724. if (samps <= 0)
  144725. break;
  144726. jassert (samps <= numToRead);
  144727. for (int i = jmin ((int) numChannels, reservoir.getNumChannels()); --i >= 0;)
  144728. {
  144729. memcpy (reservoir.getSampleData (i, offset),
  144730. dataIn[i],
  144731. sizeof (float) * samps);
  144732. }
  144733. numToRead -= samps;
  144734. offset += samps;
  144735. }
  144736. if (numToRead > 0)
  144737. reservoir.clear (offset, numToRead);
  144738. }
  144739. }
  144740. if (numSamples > 0)
  144741. {
  144742. for (int i = numDestChannels; --i >= 0;)
  144743. if (destSamples[i] != 0)
  144744. zeromem (destSamples[i] + startOffsetInDestBuffer,
  144745. sizeof (int) * numSamples);
  144746. }
  144747. return true;
  144748. }
  144749. static size_t oggReadCallback (void* ptr, size_t size, size_t nmemb, void* datasource)
  144750. {
  144751. return (size_t) (((InputStream*) datasource)->read (ptr, (int) (size * nmemb)) / size);
  144752. }
  144753. static int oggSeekCallback (void* datasource, ogg_int64_t offset, int whence)
  144754. {
  144755. InputStream* const in = (InputStream*) datasource;
  144756. if (whence == SEEK_CUR)
  144757. offset += in->getPosition();
  144758. else if (whence == SEEK_END)
  144759. offset += in->getTotalLength();
  144760. in->setPosition (offset);
  144761. return 0;
  144762. }
  144763. static int oggCloseCallback (void*)
  144764. {
  144765. return 0;
  144766. }
  144767. static long oggTellCallback (void* datasource)
  144768. {
  144769. return (long) ((InputStream*) datasource)->getPosition();
  144770. }
  144771. juce_UseDebuggingNewOperator
  144772. };
  144773. class OggWriter : public AudioFormatWriter
  144774. {
  144775. ogg_stream_state os;
  144776. ogg_page og;
  144777. ogg_packet op;
  144778. vorbis_info vi;
  144779. vorbis_comment vc;
  144780. vorbis_dsp_state vd;
  144781. vorbis_block vb;
  144782. public:
  144783. bool ok;
  144784. OggWriter (OutputStream* const out,
  144785. const double sampleRate,
  144786. const int numChannels,
  144787. const int bitsPerSample,
  144788. const int qualityIndex)
  144789. : AudioFormatWriter (out, TRANS (oggFormatName),
  144790. sampleRate,
  144791. numChannels,
  144792. bitsPerSample)
  144793. {
  144794. ok = false;
  144795. vorbis_info_init (&vi);
  144796. if (vorbis_encode_init_vbr (&vi,
  144797. numChannels,
  144798. (int) sampleRate,
  144799. jlimit (0.0f, 1.0f, qualityIndex * 0.5f)) == 0)
  144800. {
  144801. vorbis_comment_init (&vc);
  144802. if (JUCEApplication::getInstance() != 0)
  144803. vorbis_comment_add_tag (&vc, "ENCODER",
  144804. (char*) (const char*) JUCEApplication::getInstance()->getApplicationName());
  144805. vorbis_analysis_init (&vd, &vi);
  144806. vorbis_block_init (&vd, &vb);
  144807. ogg_stream_init (&os, Random::getSystemRandom().nextInt());
  144808. ogg_packet header;
  144809. ogg_packet header_comm;
  144810. ogg_packet header_code;
  144811. vorbis_analysis_headerout (&vd, &vc, &header, &header_comm, &header_code);
  144812. ogg_stream_packetin (&os, &header);
  144813. ogg_stream_packetin (&os, &header_comm);
  144814. ogg_stream_packetin (&os, &header_code);
  144815. for (;;)
  144816. {
  144817. if (ogg_stream_flush (&os, &og) == 0)
  144818. break;
  144819. output->write (og.header, og.header_len);
  144820. output->write (og.body, og.body_len);
  144821. }
  144822. ok = true;
  144823. }
  144824. }
  144825. ~OggWriter()
  144826. {
  144827. if (ok)
  144828. {
  144829. // write a zero-length packet to show ogg that we're finished..
  144830. write (0, 0);
  144831. ogg_stream_clear (&os);
  144832. vorbis_block_clear (&vb);
  144833. vorbis_dsp_clear (&vd);
  144834. vorbis_comment_clear (&vc);
  144835. vorbis_info_clear (&vi);
  144836. output->flush();
  144837. }
  144838. else
  144839. {
  144840. vorbis_info_clear (&vi);
  144841. output = 0; // to stop the base class deleting this, as it needs to be returned
  144842. // to the caller of createWriter()
  144843. }
  144844. }
  144845. bool write (const int** samplesToWrite, int numSamples)
  144846. {
  144847. if (! ok)
  144848. return false;
  144849. if (numSamples > 0)
  144850. {
  144851. const double gain = 1.0 / 0x80000000u;
  144852. float** const vorbisBuffer = vorbis_analysis_buffer (&vd, numSamples);
  144853. for (int i = numChannels; --i >= 0;)
  144854. {
  144855. float* const dst = vorbisBuffer[i];
  144856. const int* const src = samplesToWrite [i];
  144857. if (src != 0 && dst != 0)
  144858. {
  144859. for (int j = 0; j < numSamples; ++j)
  144860. dst[j] = (float) (src[j] * gain);
  144861. }
  144862. }
  144863. }
  144864. vorbis_analysis_wrote (&vd, numSamples);
  144865. while (vorbis_analysis_blockout (&vd, &vb) == 1)
  144866. {
  144867. vorbis_analysis (&vb, 0);
  144868. vorbis_bitrate_addblock (&vb);
  144869. while (vorbis_bitrate_flushpacket (&vd, &op))
  144870. {
  144871. ogg_stream_packetin (&os, &op);
  144872. for (;;)
  144873. {
  144874. if (ogg_stream_pageout (&os, &og) == 0)
  144875. break;
  144876. output->write (og.header, og.header_len);
  144877. output->write (og.body, og.body_len);
  144878. if (ogg_page_eos (&og))
  144879. break;
  144880. }
  144881. }
  144882. }
  144883. return true;
  144884. }
  144885. juce_UseDebuggingNewOperator
  144886. };
  144887. OggVorbisAudioFormat::OggVorbisAudioFormat()
  144888. : AudioFormat (TRANS (oggFormatName), (const tchar**) oggExtensions)
  144889. {
  144890. }
  144891. OggVorbisAudioFormat::~OggVorbisAudioFormat()
  144892. {
  144893. }
  144894. const Array <int> OggVorbisAudioFormat::getPossibleSampleRates()
  144895. {
  144896. const int rates[] = { 22050, 32000, 44100, 48000, 0 };
  144897. return Array <int> (rates);
  144898. }
  144899. const Array <int> OggVorbisAudioFormat::getPossibleBitDepths()
  144900. {
  144901. Array <int> depths;
  144902. depths.add (32);
  144903. return depths;
  144904. }
  144905. bool OggVorbisAudioFormat::canDoStereo()
  144906. {
  144907. return true;
  144908. }
  144909. bool OggVorbisAudioFormat::canDoMono()
  144910. {
  144911. return true;
  144912. }
  144913. AudioFormatReader* OggVorbisAudioFormat::createReaderFor (InputStream* in,
  144914. const bool deleteStreamIfOpeningFails)
  144915. {
  144916. ScopedPointer <OggReader> r (new OggReader (in));
  144917. if (r->sampleRate != 0)
  144918. return r.release();
  144919. if (! deleteStreamIfOpeningFails)
  144920. r->input = 0;
  144921. return 0;
  144922. }
  144923. AudioFormatWriter* OggVorbisAudioFormat::createWriterFor (OutputStream* out,
  144924. double sampleRate,
  144925. unsigned int numChannels,
  144926. int bitsPerSample,
  144927. const StringPairArray& /*metadataValues*/,
  144928. int qualityOptionIndex)
  144929. {
  144930. ScopedPointer <OggWriter> w (new OggWriter (out,
  144931. sampleRate,
  144932. numChannels,
  144933. bitsPerSample,
  144934. qualityOptionIndex));
  144935. return w->ok ? w.release() : 0;
  144936. }
  144937. bool OggVorbisAudioFormat::isCompressed()
  144938. {
  144939. return true;
  144940. }
  144941. const StringArray OggVorbisAudioFormat::getQualityOptions()
  144942. {
  144943. StringArray s;
  144944. s.add ("Low Quality");
  144945. s.add ("Medium Quality");
  144946. s.add ("High Quality");
  144947. return s;
  144948. }
  144949. int OggVorbisAudioFormat::estimateOggFileQuality (const File& source)
  144950. {
  144951. FileInputStream* const in = source.createInputStream();
  144952. if (in != 0)
  144953. {
  144954. ScopedPointer <AudioFormatReader> r (createReaderFor (in, true));
  144955. if (r != 0)
  144956. {
  144957. const int64 numSamps = r->lengthInSamples;
  144958. r = 0;
  144959. const int64 fileNumSamps = source.getSize() / 4;
  144960. const double ratio = numSamps / (double) fileNumSamps;
  144961. if (ratio > 12.0)
  144962. return 0;
  144963. else if (ratio > 6.0)
  144964. return 1;
  144965. else
  144966. return 2;
  144967. }
  144968. }
  144969. return 1;
  144970. }
  144971. END_JUCE_NAMESPACE
  144972. #endif
  144973. /*** End of inlined file: juce_OggVorbisAudioFormat.cpp ***/
  144974. #endif
  144975. #if JUCE_BUILD_CORE && ! JUCE_ONLY_BUILD_CORE_LIBRARY // do these in the core section to help balance the sizes
  144976. /*** Start of inlined file: juce_JPEGLoader.cpp ***/
  144977. #if JUCE_MSVC
  144978. #pragma warning (push)
  144979. #endif
  144980. namespace jpeglibNamespace
  144981. {
  144982. #if JUCE_INCLUDE_JPEGLIB_CODE
  144983. #if JUCE_MINGW
  144984. typedef unsigned char boolean;
  144985. #endif
  144986. extern "C"
  144987. {
  144988. #define JPEG_INTERNALS
  144989. #undef FAR
  144990. /*** Start of inlined file: jpeglib.h ***/
  144991. #ifndef JPEGLIB_H
  144992. #define JPEGLIB_H
  144993. #ifndef JCONFIG_INCLUDED /* in case jinclude.h already did */
  144994. /*** Start of inlined file: jconfig.h ***/
  144995. // disable all the warnings under MSVC
  144996. #ifdef _MSC_VER
  144997. #pragma warning (disable: 4996 4267 4100 4127 4702 4244)
  144998. #endif
  144999. #ifdef __BORLANDC__
  145000. #pragma warn -8057
  145001. #pragma warn -8019
  145002. #pragma warn -8004
  145003. #pragma warn -8008
  145004. #endif
  145005. #define HAVE_PROTOTYPES
  145006. #define HAVE_UNSIGNED_CHAR
  145007. #define HAVE_UNSIGNED_SHORT
  145008. #undef CHAR_IS_UNSIGNED
  145009. #define HAVE_STDDEF_H
  145010. #define HAVE_STDLIB_H
  145011. #undef NEED_BSD_STRINGS
  145012. #undef NEED_SYS_TYPES_H
  145013. #undef NEED_FAR_POINTERS /* we presume a 32-bit flat memory model */
  145014. #undef NEED_SHORT_EXTERNAL_NAMES
  145015. #undef INCOMPLETE_TYPES_BROKEN
  145016. #ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
  145017. typedef unsigned char boolean;
  145018. #endif
  145019. #define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
  145020. #ifdef JPEG_INTERNALS
  145021. #undef RIGHT_SHIFT_IS_UNSIGNED
  145022. #endif /* JPEG_INTERNALS */
  145023. #ifdef JPEG_CJPEG_DJPEG
  145024. #define BMP_SUPPORTED /* BMP image file format */
  145025. #define GIF_SUPPORTED /* GIF image file format */
  145026. #define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
  145027. #undef RLE_SUPPORTED /* Utah RLE image file format */
  145028. #define TARGA_SUPPORTED /* Targa image file format */
  145029. #define TWO_FILE_COMMANDLINE /* optional */
  145030. #define USE_SETMODE /* Microsoft has setmode() */
  145031. #undef NEED_SIGNAL_CATCHER
  145032. #undef DONT_USE_B_MODE
  145033. #undef PROGRESS_REPORT /* optional */
  145034. #endif /* JPEG_CJPEG_DJPEG */
  145035. /*** End of inlined file: jconfig.h ***/
  145036. /* widely used configuration options */
  145037. #endif
  145038. /*** Start of inlined file: jmorecfg.h ***/
  145039. #define BITS_IN_JSAMPLE 8 /* use 8 or 12 */
  145040. #define MAX_COMPONENTS 10 /* maximum number of image components */
  145041. #if BITS_IN_JSAMPLE == 8
  145042. #ifdef HAVE_UNSIGNED_CHAR
  145043. typedef unsigned char JSAMPLE;
  145044. #define GETJSAMPLE(value) ((int) (value))
  145045. #else /* not HAVE_UNSIGNED_CHAR */
  145046. typedef char JSAMPLE;
  145047. #ifdef CHAR_IS_UNSIGNED
  145048. #define GETJSAMPLE(value) ((int) (value))
  145049. #else
  145050. #define GETJSAMPLE(value) ((int) (value) & 0xFF)
  145051. #endif /* CHAR_IS_UNSIGNED */
  145052. #endif /* HAVE_UNSIGNED_CHAR */
  145053. #define MAXJSAMPLE 255
  145054. #define CENTERJSAMPLE 128
  145055. #endif /* BITS_IN_JSAMPLE == 8 */
  145056. #if BITS_IN_JSAMPLE == 12
  145057. typedef short JSAMPLE;
  145058. #define GETJSAMPLE(value) ((int) (value))
  145059. #define MAXJSAMPLE 4095
  145060. #define CENTERJSAMPLE 2048
  145061. #endif /* BITS_IN_JSAMPLE == 12 */
  145062. typedef short JCOEF;
  145063. #ifdef HAVE_UNSIGNED_CHAR
  145064. typedef unsigned char JOCTET;
  145065. #define GETJOCTET(value) (value)
  145066. #else /* not HAVE_UNSIGNED_CHAR */
  145067. typedef char JOCTET;
  145068. #ifdef CHAR_IS_UNSIGNED
  145069. #define GETJOCTET(value) (value)
  145070. #else
  145071. #define GETJOCTET(value) ((value) & 0xFF)
  145072. #endif /* CHAR_IS_UNSIGNED */
  145073. #endif /* HAVE_UNSIGNED_CHAR */
  145074. #ifdef HAVE_UNSIGNED_CHAR
  145075. typedef unsigned char UINT8;
  145076. #else /* not HAVE_UNSIGNED_CHAR */
  145077. #ifdef CHAR_IS_UNSIGNED
  145078. typedef char UINT8;
  145079. #else /* not CHAR_IS_UNSIGNED */
  145080. typedef short UINT8;
  145081. #endif /* CHAR_IS_UNSIGNED */
  145082. #endif /* HAVE_UNSIGNED_CHAR */
  145083. #ifdef HAVE_UNSIGNED_SHORT
  145084. typedef unsigned short UINT16;
  145085. #else /* not HAVE_UNSIGNED_SHORT */
  145086. typedef unsigned int UINT16;
  145087. #endif /* HAVE_UNSIGNED_SHORT */
  145088. #ifndef XMD_H /* X11/xmd.h correctly defines INT16 */
  145089. typedef short INT16;
  145090. #endif
  145091. #ifndef XMD_H /* X11/xmd.h correctly defines INT32 */
  145092. typedef long INT32;
  145093. #endif
  145094. typedef unsigned int JDIMENSION;
  145095. #define JPEG_MAX_DIMENSION 65500L /* a tad under 64K to prevent overflows */
  145096. #define METHODDEF(type) static type
  145097. #define LOCAL(type) static type
  145098. #define GLOBAL(type) type
  145099. #define EXTERN(type) extern type
  145100. #ifdef HAVE_PROTOTYPES
  145101. #define JMETHOD(type,methodname,arglist) type (*methodname) arglist
  145102. #else
  145103. #define JMETHOD(type,methodname,arglist) type (*methodname) ()
  145104. #endif
  145105. #ifdef NEED_FAR_POINTERS
  145106. #define FAR far
  145107. #else
  145108. #define FAR
  145109. #endif
  145110. #ifndef HAVE_BOOLEAN
  145111. typedef int boolean;
  145112. #endif
  145113. #ifndef FALSE /* in case these macros already exist */
  145114. #define FALSE 0 /* values of boolean */
  145115. #endif
  145116. #ifndef TRUE
  145117. #define TRUE 1
  145118. #endif
  145119. #ifdef JPEG_INTERNALS
  145120. #define JPEG_INTERNAL_OPTIONS
  145121. #endif
  145122. #ifdef JPEG_INTERNAL_OPTIONS
  145123. #define DCT_ISLOW_SUPPORTED /* slow but accurate integer algorithm */
  145124. #define DCT_IFAST_SUPPORTED /* faster, less accurate integer method */
  145125. #define DCT_FLOAT_SUPPORTED /* floating-point: accurate, fast on fast HW */
  145126. #undef C_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */
  145127. #define C_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
  145128. #define C_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
  145129. #define ENTROPY_OPT_SUPPORTED /* Optimization of entropy coding parms? */
  145130. #define INPUT_SMOOTHING_SUPPORTED /* Input image smoothing option? */
  145131. #undef D_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */
  145132. #define D_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
  145133. #define D_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
  145134. #define SAVE_MARKERS_SUPPORTED /* jpeg_save_markers() needed? */
  145135. #define BLOCK_SMOOTHING_SUPPORTED /* Block smoothing? (Progressive only) */
  145136. #define IDCT_SCALING_SUPPORTED /* Output rescaling via IDCT? */
  145137. #undef UPSAMPLE_SCALING_SUPPORTED /* Output rescaling at upsample stage? */
  145138. #define UPSAMPLE_MERGING_SUPPORTED /* Fast path for sloppy upsampling? */
  145139. #define QUANT_1PASS_SUPPORTED /* 1-pass color quantization? */
  145140. #define QUANT_2PASS_SUPPORTED /* 2-pass color quantization? */
  145141. #define RGB_RED 0 /* Offset of Red in an RGB scanline element */
  145142. #define RGB_GREEN 1 /* Offset of Green */
  145143. #define RGB_BLUE 2 /* Offset of Blue */
  145144. #define RGB_PIXELSIZE 3 /* JSAMPLEs per RGB scanline element */
  145145. #ifndef INLINE
  145146. #ifdef __GNUC__ /* for instance, GNU C knows about inline */
  145147. #define INLINE __inline__
  145148. #endif
  145149. #ifndef INLINE
  145150. #define INLINE /* default is to define it as empty */
  145151. #endif
  145152. #endif
  145153. #ifndef MULTIPLIER
  145154. #define MULTIPLIER int /* type for fastest integer multiply */
  145155. #endif
  145156. #ifndef FAST_FLOAT
  145157. #ifdef HAVE_PROTOTYPES
  145158. #define FAST_FLOAT float
  145159. #else
  145160. #define FAST_FLOAT double
  145161. #endif
  145162. #endif
  145163. #endif /* JPEG_INTERNAL_OPTIONS */
  145164. /*** End of inlined file: jmorecfg.h ***/
  145165. /* seldom changed options */
  145166. #define JPEG_LIB_VERSION 62 /* Version 6b */
  145167. #define DCTSIZE 8 /* The basic DCT block is 8x8 samples */
  145168. #define DCTSIZE2 64 /* DCTSIZE squared; # of elements in a block */
  145169. #define NUM_QUANT_TBLS 4 /* Quantization tables are numbered 0..3 */
  145170. #define NUM_HUFF_TBLS 4 /* Huffman tables are numbered 0..3 */
  145171. #define NUM_ARITH_TBLS 16 /* Arith-coding tables are numbered 0..15 */
  145172. #define MAX_COMPS_IN_SCAN 4 /* JPEG limit on # of components in one scan */
  145173. #define MAX_SAMP_FACTOR 4 /* JPEG limit on sampling factors */
  145174. #define C_MAX_BLOCKS_IN_MCU 10 /* compressor's limit on blocks per MCU */
  145175. #ifndef D_MAX_BLOCKS_IN_MCU
  145176. #define D_MAX_BLOCKS_IN_MCU 10 /* decompressor's limit on blocks per MCU */
  145177. #endif
  145178. typedef JSAMPLE FAR *JSAMPROW; /* ptr to one image row of pixel samples. */
  145179. typedef JSAMPROW *JSAMPARRAY; /* ptr to some rows (a 2-D sample array) */
  145180. typedef JSAMPARRAY *JSAMPIMAGE; /* a 3-D sample array: top index is color */
  145181. typedef JCOEF JBLOCK[DCTSIZE2]; /* one block of coefficients */
  145182. typedef JBLOCK FAR *JBLOCKROW; /* pointer to one row of coefficient blocks */
  145183. typedef JBLOCKROW *JBLOCKARRAY; /* a 2-D array of coefficient blocks */
  145184. typedef JBLOCKARRAY *JBLOCKIMAGE; /* a 3-D array of coefficient blocks */
  145185. typedef JCOEF FAR *JCOEFPTR; /* useful in a couple of places */
  145186. typedef struct {
  145187. UINT16 quantval[DCTSIZE2]; /* quantization step for each coefficient */
  145188. boolean sent_table; /* TRUE when table has been output */
  145189. } JQUANT_TBL;
  145190. typedef struct {
  145191. UINT8 bits[17]; /* bits[k] = # of symbols with codes of */
  145192. UINT8 huffval[256]; /* The symbols, in order of incr code length */
  145193. boolean sent_table; /* TRUE when table has been output */
  145194. } JHUFF_TBL;
  145195. typedef struct {
  145196. int component_id; /* identifier for this component (0..255) */
  145197. int component_index; /* its index in SOF or cinfo->comp_info[] */
  145198. int h_samp_factor; /* horizontal sampling factor (1..4) */
  145199. int v_samp_factor; /* vertical sampling factor (1..4) */
  145200. int quant_tbl_no; /* quantization table selector (0..3) */
  145201. int dc_tbl_no; /* DC entropy table selector (0..3) */
  145202. int ac_tbl_no; /* AC entropy table selector (0..3) */
  145203. JDIMENSION width_in_blocks;
  145204. JDIMENSION height_in_blocks;
  145205. int DCT_scaled_size;
  145206. JDIMENSION downsampled_width; /* actual width in samples */
  145207. JDIMENSION downsampled_height; /* actual height in samples */
  145208. boolean component_needed; /* do we need the value of this component? */
  145209. int MCU_width; /* number of blocks per MCU, horizontally */
  145210. int MCU_height; /* number of blocks per MCU, vertically */
  145211. int MCU_blocks; /* MCU_width * MCU_height */
  145212. int MCU_sample_width; /* MCU width in samples, MCU_width*DCT_scaled_size */
  145213. int last_col_width; /* # of non-dummy blocks across in last MCU */
  145214. int last_row_height; /* # of non-dummy blocks down in last MCU */
  145215. JQUANT_TBL * quant_table;
  145216. void * dct_table;
  145217. } jpeg_component_info;
  145218. typedef struct {
  145219. int comps_in_scan; /* number of components encoded in this scan */
  145220. int component_index[MAX_COMPS_IN_SCAN]; /* their SOF/comp_info[] indexes */
  145221. int Ss, Se; /* progressive JPEG spectral selection parms */
  145222. int Ah, Al; /* progressive JPEG successive approx. parms */
  145223. } jpeg_scan_info;
  145224. typedef struct jpeg_marker_struct FAR * jpeg_saved_marker_ptr;
  145225. struct jpeg_marker_struct {
  145226. jpeg_saved_marker_ptr next; /* next in list, or NULL */
  145227. UINT8 marker; /* marker code: JPEG_COM, or JPEG_APP0+n */
  145228. unsigned int original_length; /* # bytes of data in the file */
  145229. unsigned int data_length; /* # bytes of data saved at data[] */
  145230. JOCTET FAR * data; /* the data contained in the marker */
  145231. };
  145232. typedef enum {
  145233. JCS_UNKNOWN, /* error/unspecified */
  145234. JCS_GRAYSCALE, /* monochrome */
  145235. JCS_RGB, /* red/green/blue */
  145236. JCS_YCbCr, /* Y/Cb/Cr (also known as YUV) */
  145237. JCS_CMYK, /* C/M/Y/K */
  145238. JCS_YCCK /* Y/Cb/Cr/K */
  145239. } J_COLOR_SPACE;
  145240. typedef enum {
  145241. JDCT_ISLOW, /* slow but accurate integer algorithm */
  145242. JDCT_IFAST, /* faster, less accurate integer method */
  145243. JDCT_FLOAT /* floating-point: accurate, fast on fast HW */
  145244. } J_DCT_METHOD;
  145245. #ifndef JDCT_DEFAULT /* may be overridden in jconfig.h */
  145246. #define JDCT_DEFAULT JDCT_ISLOW
  145247. #endif
  145248. #ifndef JDCT_FASTEST /* may be overridden in jconfig.h */
  145249. #define JDCT_FASTEST JDCT_IFAST
  145250. #endif
  145251. typedef enum {
  145252. JDITHER_NONE, /* no dithering */
  145253. JDITHER_ORDERED, /* simple ordered dither */
  145254. JDITHER_FS /* Floyd-Steinberg error diffusion dither */
  145255. } J_DITHER_MODE;
  145256. #define jpeg_common_fields \
  145257. struct jpeg_error_mgr * err; /* Error handler module */\
  145258. struct jpeg_memory_mgr * mem; /* Memory manager module */\
  145259. struct jpeg_progress_mgr * progress; /* Progress monitor, or NULL if none */\
  145260. void * client_data; /* Available for use by application */\
  145261. boolean is_decompressor; /* So common code can tell which is which */\
  145262. int global_state /* For checking call sequence validity */
  145263. struct jpeg_common_struct {
  145264. jpeg_common_fields; /* Fields common to both master struct types */
  145265. };
  145266. typedef struct jpeg_common_struct * j_common_ptr;
  145267. typedef struct jpeg_compress_struct * j_compress_ptr;
  145268. typedef struct jpeg_decompress_struct * j_decompress_ptr;
  145269. struct jpeg_compress_struct {
  145270. jpeg_common_fields; /* Fields shared with jpeg_decompress_struct */
  145271. struct jpeg_destination_mgr * dest;
  145272. JDIMENSION image_width; /* input image width */
  145273. JDIMENSION image_height; /* input image height */
  145274. int input_components; /* # of color components in input image */
  145275. J_COLOR_SPACE in_color_space; /* colorspace of input image */
  145276. double input_gamma; /* image gamma of input image */
  145277. int data_precision; /* bits of precision in image data */
  145278. int num_components; /* # of color components in JPEG image */
  145279. J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */
  145280. jpeg_component_info * comp_info;
  145281. JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS];
  145282. JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
  145283. JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
  145284. UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
  145285. UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
  145286. UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
  145287. int num_scans; /* # of entries in scan_info array */
  145288. const jpeg_scan_info * scan_info; /* script for multi-scan file, or NULL */
  145289. boolean raw_data_in; /* TRUE=caller supplies downsampled data */
  145290. boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */
  145291. boolean optimize_coding; /* TRUE=optimize entropy encoding parms */
  145292. boolean CCIR601_sampling; /* TRUE=first samples are cosited */
  145293. int smoothing_factor; /* 1..100, or 0 for no input smoothing */
  145294. J_DCT_METHOD dct_method; /* DCT algorithm selector */
  145295. unsigned int restart_interval; /* MCUs per restart, or 0 for no restart */
  145296. int restart_in_rows; /* if > 0, MCU rows per restart interval */
  145297. boolean write_JFIF_header; /* should a JFIF marker be written? */
  145298. UINT8 JFIF_major_version; /* What to write for the JFIF version number */
  145299. UINT8 JFIF_minor_version;
  145300. UINT8 density_unit; /* JFIF code for pixel size units */
  145301. UINT16 X_density; /* Horizontal pixel density */
  145302. UINT16 Y_density; /* Vertical pixel density */
  145303. boolean write_Adobe_marker; /* should an Adobe marker be written? */
  145304. JDIMENSION next_scanline; /* 0 .. image_height-1 */
  145305. boolean progressive_mode; /* TRUE if scan script uses progressive mode */
  145306. int max_h_samp_factor; /* largest h_samp_factor */
  145307. int max_v_samp_factor; /* largest v_samp_factor */
  145308. JDIMENSION total_iMCU_rows; /* # of iMCU rows to be input to coef ctlr */
  145309. int comps_in_scan; /* # of JPEG components in this scan */
  145310. jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN];
  145311. JDIMENSION MCUs_per_row; /* # of MCUs across the image */
  145312. JDIMENSION MCU_rows_in_scan; /* # of MCU rows in the image */
  145313. int blocks_in_MCU; /* # of DCT blocks per MCU */
  145314. int MCU_membership[C_MAX_BLOCKS_IN_MCU];
  145315. int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */
  145316. struct jpeg_comp_master * master;
  145317. struct jpeg_c_main_controller * main;
  145318. struct jpeg_c_prep_controller * prep;
  145319. struct jpeg_c_coef_controller * coef;
  145320. struct jpeg_marker_writer * marker;
  145321. struct jpeg_color_converter * cconvert;
  145322. struct jpeg_downsampler * downsample;
  145323. struct jpeg_forward_dct * fdct;
  145324. struct jpeg_entropy_encoder * entropy;
  145325. jpeg_scan_info * script_space; /* workspace for jpeg_simple_progression */
  145326. int script_space_size;
  145327. };
  145328. struct jpeg_decompress_struct {
  145329. jpeg_common_fields; /* Fields shared with jpeg_compress_struct */
  145330. struct jpeg_source_mgr * src;
  145331. JDIMENSION image_width; /* nominal image width (from SOF marker) */
  145332. JDIMENSION image_height; /* nominal image height */
  145333. int num_components; /* # of color components in JPEG image */
  145334. J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */
  145335. J_COLOR_SPACE out_color_space; /* colorspace for output */
  145336. unsigned int scale_num, scale_denom; /* fraction by which to scale image */
  145337. double output_gamma; /* image gamma wanted in output */
  145338. boolean buffered_image; /* TRUE=multiple output passes */
  145339. boolean raw_data_out; /* TRUE=downsampled data wanted */
  145340. J_DCT_METHOD dct_method; /* IDCT algorithm selector */
  145341. boolean do_fancy_upsampling; /* TRUE=apply fancy upsampling */
  145342. boolean do_block_smoothing; /* TRUE=apply interblock smoothing */
  145343. boolean quantize_colors; /* TRUE=colormapped output wanted */
  145344. J_DITHER_MODE dither_mode; /* type of color dithering to use */
  145345. boolean two_pass_quantize; /* TRUE=use two-pass color quantization */
  145346. int desired_number_of_colors; /* max # colors to use in created colormap */
  145347. boolean enable_1pass_quant; /* enable future use of 1-pass quantizer */
  145348. boolean enable_external_quant;/* enable future use of external colormap */
  145349. boolean enable_2pass_quant; /* enable future use of 2-pass quantizer */
  145350. JDIMENSION output_width; /* scaled image width */
  145351. JDIMENSION output_height; /* scaled image height */
  145352. int out_color_components; /* # of color components in out_color_space */
  145353. int output_components; /* # of color components returned */
  145354. int rec_outbuf_height; /* min recommended height of scanline buffer */
  145355. int actual_number_of_colors; /* number of entries in use */
  145356. JSAMPARRAY colormap; /* The color map as a 2-D pixel array */
  145357. JDIMENSION output_scanline; /* 0 .. output_height-1 */
  145358. int input_scan_number; /* Number of SOS markers seen so far */
  145359. JDIMENSION input_iMCU_row; /* Number of iMCU rows completed */
  145360. int output_scan_number; /* Nominal scan number being displayed */
  145361. JDIMENSION output_iMCU_row; /* Number of iMCU rows read */
  145362. int (*coef_bits)[DCTSIZE2]; /* -1 or current Al value for each coef */
  145363. JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS];
  145364. JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
  145365. JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
  145366. int data_precision; /* bits of precision in image data */
  145367. jpeg_component_info * comp_info;
  145368. boolean progressive_mode; /* TRUE if SOFn specifies progressive mode */
  145369. boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */
  145370. UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
  145371. UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
  145372. UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
  145373. unsigned int restart_interval; /* MCUs per restart interval, or 0 for no restart */
  145374. boolean saw_JFIF_marker; /* TRUE iff a JFIF APP0 marker was found */
  145375. UINT8 JFIF_major_version; /* JFIF version number */
  145376. UINT8 JFIF_minor_version;
  145377. UINT8 density_unit; /* JFIF code for pixel size units */
  145378. UINT16 X_density; /* Horizontal pixel density */
  145379. UINT16 Y_density; /* Vertical pixel density */
  145380. boolean saw_Adobe_marker; /* TRUE iff an Adobe APP14 marker was found */
  145381. UINT8 Adobe_transform; /* Color transform code from Adobe marker */
  145382. boolean CCIR601_sampling; /* TRUE=first samples are cosited */
  145383. jpeg_saved_marker_ptr marker_list; /* Head of list of saved markers */
  145384. int max_h_samp_factor; /* largest h_samp_factor */
  145385. int max_v_samp_factor; /* largest v_samp_factor */
  145386. int min_DCT_scaled_size; /* smallest DCT_scaled_size of any component */
  145387. JDIMENSION total_iMCU_rows; /* # of iMCU rows in image */
  145388. JSAMPLE * sample_range_limit; /* table for fast range-limiting */
  145389. int comps_in_scan; /* # of JPEG components in this scan */
  145390. jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN];
  145391. JDIMENSION MCUs_per_row; /* # of MCUs across the image */
  145392. JDIMENSION MCU_rows_in_scan; /* # of MCU rows in the image */
  145393. int blocks_in_MCU; /* # of DCT blocks per MCU */
  145394. int MCU_membership[D_MAX_BLOCKS_IN_MCU];
  145395. int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */
  145396. int unread_marker;
  145397. struct jpeg_decomp_master * master;
  145398. struct jpeg_d_main_controller * main;
  145399. struct jpeg_d_coef_controller * coef;
  145400. struct jpeg_d_post_controller * post;
  145401. struct jpeg_input_controller * inputctl;
  145402. struct jpeg_marker_reader * marker;
  145403. struct jpeg_entropy_decoder * entropy;
  145404. struct jpeg_inverse_dct * idct;
  145405. struct jpeg_upsampler * upsample;
  145406. struct jpeg_color_deconverter * cconvert;
  145407. struct jpeg_color_quantizer * cquantize;
  145408. };
  145409. struct jpeg_error_mgr {
  145410. JMETHOD(void, error_exit, (j_common_ptr cinfo));
  145411. JMETHOD(void, emit_message, (j_common_ptr cinfo, int msg_level));
  145412. JMETHOD(void, output_message, (j_common_ptr cinfo));
  145413. JMETHOD(void, format_message, (j_common_ptr cinfo, char * buffer));
  145414. #define JMSG_LENGTH_MAX 200 /* recommended size of format_message buffer */
  145415. JMETHOD(void, reset_error_mgr, (j_common_ptr cinfo));
  145416. int msg_code;
  145417. #define JMSG_STR_PARM_MAX 80
  145418. union {
  145419. int i[8];
  145420. char s[JMSG_STR_PARM_MAX];
  145421. } msg_parm;
  145422. int trace_level; /* max msg_level that will be displayed */
  145423. long num_warnings; /* number of corrupt-data warnings */
  145424. const char * const * jpeg_message_table; /* Library errors */
  145425. int last_jpeg_message; /* Table contains strings 0..last_jpeg_message */
  145426. const char * const * addon_message_table; /* Non-library errors */
  145427. int first_addon_message; /* code for first string in addon table */
  145428. int last_addon_message; /* code for last string in addon table */
  145429. };
  145430. struct jpeg_progress_mgr {
  145431. JMETHOD(void, progress_monitor, (j_common_ptr cinfo));
  145432. long pass_counter; /* work units completed in this pass */
  145433. long pass_limit; /* total number of work units in this pass */
  145434. int completed_passes; /* passes completed so far */
  145435. int total_passes; /* total number of passes expected */
  145436. };
  145437. struct jpeg_destination_mgr {
  145438. JOCTET * next_output_byte; /* => next byte to write in buffer */
  145439. size_t free_in_buffer; /* # of byte spaces remaining in buffer */
  145440. JMETHOD(void, init_destination, (j_compress_ptr cinfo));
  145441. JMETHOD(boolean, empty_output_buffer, (j_compress_ptr cinfo));
  145442. JMETHOD(void, term_destination, (j_compress_ptr cinfo));
  145443. };
  145444. struct jpeg_source_mgr {
  145445. const JOCTET * next_input_byte; /* => next byte to read from buffer */
  145446. size_t bytes_in_buffer; /* # of bytes remaining in buffer */
  145447. JMETHOD(void, init_source, (j_decompress_ptr cinfo));
  145448. JMETHOD(boolean, fill_input_buffer, (j_decompress_ptr cinfo));
  145449. JMETHOD(void, skip_input_data, (j_decompress_ptr cinfo, long num_bytes));
  145450. JMETHOD(boolean, resync_to_restart, (j_decompress_ptr cinfo, int desired));
  145451. JMETHOD(void, term_source, (j_decompress_ptr cinfo));
  145452. };
  145453. #define JPOOL_PERMANENT 0 /* lasts until master record is destroyed */
  145454. #define JPOOL_IMAGE 1 /* lasts until done with image/datastream */
  145455. #define JPOOL_NUMPOOLS 2
  145456. typedef struct jvirt_sarray_control * jvirt_sarray_ptr;
  145457. typedef struct jvirt_barray_control * jvirt_barray_ptr;
  145458. struct jpeg_memory_mgr {
  145459. JMETHOD(void *, alloc_small, (j_common_ptr cinfo, int pool_id,
  145460. size_t sizeofobject));
  145461. JMETHOD(void FAR *, alloc_large, (j_common_ptr cinfo, int pool_id,
  145462. size_t sizeofobject));
  145463. JMETHOD(JSAMPARRAY, alloc_sarray, (j_common_ptr cinfo, int pool_id,
  145464. JDIMENSION samplesperrow,
  145465. JDIMENSION numrows));
  145466. JMETHOD(JBLOCKARRAY, alloc_barray, (j_common_ptr cinfo, int pool_id,
  145467. JDIMENSION blocksperrow,
  145468. JDIMENSION numrows));
  145469. JMETHOD(jvirt_sarray_ptr, request_virt_sarray, (j_common_ptr cinfo,
  145470. int pool_id,
  145471. boolean pre_zero,
  145472. JDIMENSION samplesperrow,
  145473. JDIMENSION numrows,
  145474. JDIMENSION maxaccess));
  145475. JMETHOD(jvirt_barray_ptr, request_virt_barray, (j_common_ptr cinfo,
  145476. int pool_id,
  145477. boolean pre_zero,
  145478. JDIMENSION blocksperrow,
  145479. JDIMENSION numrows,
  145480. JDIMENSION maxaccess));
  145481. JMETHOD(void, realize_virt_arrays, (j_common_ptr cinfo));
  145482. JMETHOD(JSAMPARRAY, access_virt_sarray, (j_common_ptr cinfo,
  145483. jvirt_sarray_ptr ptr,
  145484. JDIMENSION start_row,
  145485. JDIMENSION num_rows,
  145486. boolean writable));
  145487. JMETHOD(JBLOCKARRAY, access_virt_barray, (j_common_ptr cinfo,
  145488. jvirt_barray_ptr ptr,
  145489. JDIMENSION start_row,
  145490. JDIMENSION num_rows,
  145491. boolean writable));
  145492. JMETHOD(void, free_pool, (j_common_ptr cinfo, int pool_id));
  145493. JMETHOD(void, self_destruct, (j_common_ptr cinfo));
  145494. long max_memory_to_use;
  145495. long max_alloc_chunk;
  145496. };
  145497. typedef JMETHOD(boolean, jpeg_marker_parser_method, (j_decompress_ptr cinfo));
  145498. #ifdef HAVE_PROTOTYPES
  145499. #define JPP(arglist) arglist
  145500. #else
  145501. #define JPP(arglist) ()
  145502. #endif
  145503. #ifdef NEED_SHORT_EXTERNAL_NAMES
  145504. #define jpeg_std_error jStdError
  145505. #define jpeg_CreateCompress jCreaCompress
  145506. #define jpeg_CreateDecompress jCreaDecompress
  145507. #define jpeg_destroy_compress jDestCompress
  145508. #define jpeg_destroy_decompress jDestDecompress
  145509. #define jpeg_stdio_dest jStdDest
  145510. #define jpeg_stdio_src jStdSrc
  145511. #define jpeg_set_defaults jSetDefaults
  145512. #define jpeg_set_colorspace jSetColorspace
  145513. #define jpeg_default_colorspace jDefColorspace
  145514. #define jpeg_set_quality jSetQuality
  145515. #define jpeg_set_linear_quality jSetLQuality
  145516. #define jpeg_add_quant_table jAddQuantTable
  145517. #define jpeg_quality_scaling jQualityScaling
  145518. #define jpeg_simple_progression jSimProgress
  145519. #define jpeg_suppress_tables jSuppressTables
  145520. #define jpeg_alloc_quant_table jAlcQTable
  145521. #define jpeg_alloc_huff_table jAlcHTable
  145522. #define jpeg_start_compress jStrtCompress
  145523. #define jpeg_write_scanlines jWrtScanlines
  145524. #define jpeg_finish_compress jFinCompress
  145525. #define jpeg_write_raw_data jWrtRawData
  145526. #define jpeg_write_marker jWrtMarker
  145527. #define jpeg_write_m_header jWrtMHeader
  145528. #define jpeg_write_m_byte jWrtMByte
  145529. #define jpeg_write_tables jWrtTables
  145530. #define jpeg_read_header jReadHeader
  145531. #define jpeg_start_decompress jStrtDecompress
  145532. #define jpeg_read_scanlines jReadScanlines
  145533. #define jpeg_finish_decompress jFinDecompress
  145534. #define jpeg_read_raw_data jReadRawData
  145535. #define jpeg_has_multiple_scans jHasMultScn
  145536. #define jpeg_start_output jStrtOutput
  145537. #define jpeg_finish_output jFinOutput
  145538. #define jpeg_input_complete jInComplete
  145539. #define jpeg_new_colormap jNewCMap
  145540. #define jpeg_consume_input jConsumeInput
  145541. #define jpeg_calc_output_dimensions jCalcDimensions
  145542. #define jpeg_save_markers jSaveMarkers
  145543. #define jpeg_set_marker_processor jSetMarker
  145544. #define jpeg_read_coefficients jReadCoefs
  145545. #define jpeg_write_coefficients jWrtCoefs
  145546. #define jpeg_copy_critical_parameters jCopyCrit
  145547. #define jpeg_abort_compress jAbrtCompress
  145548. #define jpeg_abort_decompress jAbrtDecompress
  145549. #define jpeg_abort jAbort
  145550. #define jpeg_destroy jDestroy
  145551. #define jpeg_resync_to_restart jResyncRestart
  145552. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  145553. EXTERN(struct jpeg_error_mgr *) jpeg_std_error
  145554. JPP((struct jpeg_error_mgr * err));
  145555. #define jpeg_create_compress(cinfo) \
  145556. jpeg_CreateCompress((cinfo), JPEG_LIB_VERSION, \
  145557. (size_t) sizeof(struct jpeg_compress_struct))
  145558. #define jpeg_create_decompress(cinfo) \
  145559. jpeg_CreateDecompress((cinfo), JPEG_LIB_VERSION, \
  145560. (size_t) sizeof(struct jpeg_decompress_struct))
  145561. EXTERN(void) jpeg_CreateCompress JPP((j_compress_ptr cinfo,
  145562. int version, size_t structsize));
  145563. EXTERN(void) jpeg_CreateDecompress JPP((j_decompress_ptr cinfo,
  145564. int version, size_t structsize));
  145565. EXTERN(void) jpeg_destroy_compress JPP((j_compress_ptr cinfo));
  145566. EXTERN(void) jpeg_destroy_decompress JPP((j_decompress_ptr cinfo));
  145567. EXTERN(void) jpeg_stdio_dest JPP((j_compress_ptr cinfo, FILE * outfile));
  145568. EXTERN(void) jpeg_stdio_src JPP((j_decompress_ptr cinfo, FILE * infile));
  145569. EXTERN(void) jpeg_set_defaults JPP((j_compress_ptr cinfo));
  145570. EXTERN(void) jpeg_set_colorspace JPP((j_compress_ptr cinfo,
  145571. J_COLOR_SPACE colorspace));
  145572. EXTERN(void) jpeg_default_colorspace JPP((j_compress_ptr cinfo));
  145573. EXTERN(void) jpeg_set_quality JPP((j_compress_ptr cinfo, int quality,
  145574. boolean force_baseline));
  145575. EXTERN(void) jpeg_set_linear_quality JPP((j_compress_ptr cinfo,
  145576. int scale_factor,
  145577. boolean force_baseline));
  145578. EXTERN(void) jpeg_add_quant_table JPP((j_compress_ptr cinfo, int which_tbl,
  145579. const unsigned int *basic_table,
  145580. int scale_factor,
  145581. boolean force_baseline));
  145582. EXTERN(int) jpeg_quality_scaling JPP((int quality));
  145583. EXTERN(void) jpeg_simple_progression JPP((j_compress_ptr cinfo));
  145584. EXTERN(void) jpeg_suppress_tables JPP((j_compress_ptr cinfo,
  145585. boolean suppress));
  145586. EXTERN(JQUANT_TBL *) jpeg_alloc_quant_table JPP((j_common_ptr cinfo));
  145587. EXTERN(JHUFF_TBL *) jpeg_alloc_huff_table JPP((j_common_ptr cinfo));
  145588. EXTERN(void) jpeg_start_compress JPP((j_compress_ptr cinfo,
  145589. boolean write_all_tables));
  145590. EXTERN(JDIMENSION) jpeg_write_scanlines JPP((j_compress_ptr cinfo,
  145591. JSAMPARRAY scanlines,
  145592. JDIMENSION num_lines));
  145593. EXTERN(void) jpeg_finish_compress JPP((j_compress_ptr cinfo));
  145594. EXTERN(JDIMENSION) jpeg_write_raw_data JPP((j_compress_ptr cinfo,
  145595. JSAMPIMAGE data,
  145596. JDIMENSION num_lines));
  145597. EXTERN(void) jpeg_write_marker
  145598. JPP((j_compress_ptr cinfo, int marker,
  145599. const JOCTET * dataptr, unsigned int datalen));
  145600. EXTERN(void) jpeg_write_m_header
  145601. JPP((j_compress_ptr cinfo, int marker, unsigned int datalen));
  145602. EXTERN(void) jpeg_write_m_byte
  145603. JPP((j_compress_ptr cinfo, int val));
  145604. EXTERN(void) jpeg_write_tables JPP((j_compress_ptr cinfo));
  145605. EXTERN(int) jpeg_read_header JPP((j_decompress_ptr cinfo,
  145606. boolean require_image));
  145607. #define JPEG_SUSPENDED 0 /* Suspended due to lack of input data */
  145608. #define JPEG_HEADER_OK 1 /* Found valid image datastream */
  145609. #define JPEG_HEADER_TABLES_ONLY 2 /* Found valid table-specs-only datastream */
  145610. EXTERN(boolean) jpeg_start_decompress JPP((j_decompress_ptr cinfo));
  145611. EXTERN(JDIMENSION) jpeg_read_scanlines JPP((j_decompress_ptr cinfo,
  145612. JSAMPARRAY scanlines,
  145613. JDIMENSION max_lines));
  145614. EXTERN(boolean) jpeg_finish_decompress JPP((j_decompress_ptr cinfo));
  145615. EXTERN(JDIMENSION) jpeg_read_raw_data JPP((j_decompress_ptr cinfo,
  145616. JSAMPIMAGE data,
  145617. JDIMENSION max_lines));
  145618. EXTERN(boolean) jpeg_has_multiple_scans JPP((j_decompress_ptr cinfo));
  145619. EXTERN(boolean) jpeg_start_output JPP((j_decompress_ptr cinfo,
  145620. int scan_number));
  145621. EXTERN(boolean) jpeg_finish_output JPP((j_decompress_ptr cinfo));
  145622. EXTERN(boolean) jpeg_input_complete JPP((j_decompress_ptr cinfo));
  145623. EXTERN(void) jpeg_new_colormap JPP((j_decompress_ptr cinfo));
  145624. EXTERN(int) jpeg_consume_input JPP((j_decompress_ptr cinfo));
  145625. #define JPEG_REACHED_SOS 1 /* Reached start of new scan */
  145626. #define JPEG_REACHED_EOI 2 /* Reached end of image */
  145627. #define JPEG_ROW_COMPLETED 3 /* Completed one iMCU row */
  145628. #define JPEG_SCAN_COMPLETED 4 /* Completed last iMCU row of a scan */
  145629. EXTERN(void) jpeg_calc_output_dimensions JPP((j_decompress_ptr cinfo));
  145630. EXTERN(void) jpeg_save_markers
  145631. JPP((j_decompress_ptr cinfo, int marker_code,
  145632. unsigned int length_limit));
  145633. EXTERN(void) jpeg_set_marker_processor
  145634. JPP((j_decompress_ptr cinfo, int marker_code,
  145635. jpeg_marker_parser_method routine));
  145636. EXTERN(jvirt_barray_ptr *) jpeg_read_coefficients JPP((j_decompress_ptr cinfo));
  145637. EXTERN(void) jpeg_write_coefficients JPP((j_compress_ptr cinfo,
  145638. jvirt_barray_ptr * coef_arrays));
  145639. EXTERN(void) jpeg_copy_critical_parameters JPP((j_decompress_ptr srcinfo,
  145640. j_compress_ptr dstinfo));
  145641. EXTERN(void) jpeg_abort_compress JPP((j_compress_ptr cinfo));
  145642. EXTERN(void) jpeg_abort_decompress JPP((j_decompress_ptr cinfo));
  145643. EXTERN(void) jpeg_abort JPP((j_common_ptr cinfo));
  145644. EXTERN(void) jpeg_destroy JPP((j_common_ptr cinfo));
  145645. EXTERN(boolean) jpeg_resync_to_restart JPP((j_decompress_ptr cinfo,
  145646. int desired));
  145647. #define JPEG_RST0 0xD0 /* RST0 marker code */
  145648. #define JPEG_EOI 0xD9 /* EOI marker code */
  145649. #define JPEG_APP0 0xE0 /* APP0 marker code */
  145650. #define JPEG_COM 0xFE /* COM marker code */
  145651. #ifdef INCOMPLETE_TYPES_BROKEN
  145652. #ifndef JPEG_INTERNALS /* will be defined in jpegint.h */
  145653. struct jvirt_sarray_control { long dummy; };
  145654. struct jvirt_barray_control { long dummy; };
  145655. struct jpeg_comp_master { long dummy; };
  145656. struct jpeg_c_main_controller { long dummy; };
  145657. struct jpeg_c_prep_controller { long dummy; };
  145658. struct jpeg_c_coef_controller { long dummy; };
  145659. struct jpeg_marker_writer { long dummy; };
  145660. struct jpeg_color_converter { long dummy; };
  145661. struct jpeg_downsampler { long dummy; };
  145662. struct jpeg_forward_dct { long dummy; };
  145663. struct jpeg_entropy_encoder { long dummy; };
  145664. struct jpeg_decomp_master { long dummy; };
  145665. struct jpeg_d_main_controller { long dummy; };
  145666. struct jpeg_d_coef_controller { long dummy; };
  145667. struct jpeg_d_post_controller { long dummy; };
  145668. struct jpeg_input_controller { long dummy; };
  145669. struct jpeg_marker_reader { long dummy; };
  145670. struct jpeg_entropy_decoder { long dummy; };
  145671. struct jpeg_inverse_dct { long dummy; };
  145672. struct jpeg_upsampler { long dummy; };
  145673. struct jpeg_color_deconverter { long dummy; };
  145674. struct jpeg_color_quantizer { long dummy; };
  145675. #endif /* JPEG_INTERNALS */
  145676. #endif /* INCOMPLETE_TYPES_BROKEN */
  145677. #ifdef JPEG_INTERNALS
  145678. /*** Start of inlined file: jpegint.h ***/
  145679. typedef enum { /* Operating modes for buffer controllers */
  145680. JBUF_PASS_THRU, /* Plain stripwise operation */
  145681. JBUF_SAVE_SOURCE, /* Run source subobject only, save output */
  145682. JBUF_CRANK_DEST, /* Run dest subobject only, using saved data */
  145683. JBUF_SAVE_AND_PASS /* Run both subobjects, save output */
  145684. } J_BUF_MODE;
  145685. #define CSTATE_START 100 /* after create_compress */
  145686. #define CSTATE_SCANNING 101 /* start_compress done, write_scanlines OK */
  145687. #define CSTATE_RAW_OK 102 /* start_compress done, write_raw_data OK */
  145688. #define CSTATE_WRCOEFS 103 /* jpeg_write_coefficients done */
  145689. #define DSTATE_START 200 /* after create_decompress */
  145690. #define DSTATE_INHEADER 201 /* reading header markers, no SOS yet */
  145691. #define DSTATE_READY 202 /* found SOS, ready for start_decompress */
  145692. #define DSTATE_PRELOAD 203 /* reading multiscan file in start_decompress*/
  145693. #define DSTATE_PRESCAN 204 /* performing dummy pass for 2-pass quant */
  145694. #define DSTATE_SCANNING 205 /* start_decompress done, read_scanlines OK */
  145695. #define DSTATE_RAW_OK 206 /* start_decompress done, read_raw_data OK */
  145696. #define DSTATE_BUFIMAGE 207 /* expecting jpeg_start_output */
  145697. #define DSTATE_BUFPOST 208 /* looking for SOS/EOI in jpeg_finish_output */
  145698. #define DSTATE_RDCOEFS 209 /* reading file in jpeg_read_coefficients */
  145699. #define DSTATE_STOPPING 210 /* looking for EOI in jpeg_finish_decompress */
  145700. struct jpeg_comp_master {
  145701. JMETHOD(void, prepare_for_pass, (j_compress_ptr cinfo));
  145702. JMETHOD(void, pass_startup, (j_compress_ptr cinfo));
  145703. JMETHOD(void, finish_pass, (j_compress_ptr cinfo));
  145704. boolean call_pass_startup; /* True if pass_startup must be called */
  145705. boolean is_last_pass; /* True during last pass */
  145706. };
  145707. struct jpeg_c_main_controller {
  145708. JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  145709. JMETHOD(void, process_data, (j_compress_ptr cinfo,
  145710. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  145711. JDIMENSION in_rows_avail));
  145712. };
  145713. struct jpeg_c_prep_controller {
  145714. JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  145715. JMETHOD(void, pre_process_data, (j_compress_ptr cinfo,
  145716. JSAMPARRAY input_buf,
  145717. JDIMENSION *in_row_ctr,
  145718. JDIMENSION in_rows_avail,
  145719. JSAMPIMAGE output_buf,
  145720. JDIMENSION *out_row_group_ctr,
  145721. JDIMENSION out_row_groups_avail));
  145722. };
  145723. struct jpeg_c_coef_controller {
  145724. JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  145725. JMETHOD(boolean, compress_data, (j_compress_ptr cinfo,
  145726. JSAMPIMAGE input_buf));
  145727. };
  145728. struct jpeg_color_converter {
  145729. JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  145730. JMETHOD(void, color_convert, (j_compress_ptr cinfo,
  145731. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  145732. JDIMENSION output_row, int num_rows));
  145733. };
  145734. struct jpeg_downsampler {
  145735. JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  145736. JMETHOD(void, downsample, (j_compress_ptr cinfo,
  145737. JSAMPIMAGE input_buf, JDIMENSION in_row_index,
  145738. JSAMPIMAGE output_buf,
  145739. JDIMENSION out_row_group_index));
  145740. boolean need_context_rows; /* TRUE if need rows above & below */
  145741. };
  145742. struct jpeg_forward_dct {
  145743. JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  145744. JMETHOD(void, forward_DCT, (j_compress_ptr cinfo,
  145745. jpeg_component_info * compptr,
  145746. JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  145747. JDIMENSION start_row, JDIMENSION start_col,
  145748. JDIMENSION num_blocks));
  145749. };
  145750. struct jpeg_entropy_encoder {
  145751. JMETHOD(void, start_pass, (j_compress_ptr cinfo, boolean gather_statistics));
  145752. JMETHOD(boolean, encode_mcu, (j_compress_ptr cinfo, JBLOCKROW *MCU_data));
  145753. JMETHOD(void, finish_pass, (j_compress_ptr cinfo));
  145754. };
  145755. struct jpeg_marker_writer {
  145756. JMETHOD(void, write_file_header, (j_compress_ptr cinfo));
  145757. JMETHOD(void, write_frame_header, (j_compress_ptr cinfo));
  145758. JMETHOD(void, write_scan_header, (j_compress_ptr cinfo));
  145759. JMETHOD(void, write_file_trailer, (j_compress_ptr cinfo));
  145760. JMETHOD(void, write_tables_only, (j_compress_ptr cinfo));
  145761. JMETHOD(void, write_marker_header, (j_compress_ptr cinfo, int marker,
  145762. unsigned int datalen));
  145763. JMETHOD(void, write_marker_byte, (j_compress_ptr cinfo, int val));
  145764. };
  145765. struct jpeg_decomp_master {
  145766. JMETHOD(void, prepare_for_output_pass, (j_decompress_ptr cinfo));
  145767. JMETHOD(void, finish_output_pass, (j_decompress_ptr cinfo));
  145768. boolean is_dummy_pass; /* True during 1st pass for 2-pass quant */
  145769. };
  145770. struct jpeg_input_controller {
  145771. JMETHOD(int, consume_input, (j_decompress_ptr cinfo));
  145772. JMETHOD(void, reset_input_controller, (j_decompress_ptr cinfo));
  145773. JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo));
  145774. JMETHOD(void, finish_input_pass, (j_decompress_ptr cinfo));
  145775. boolean has_multiple_scans; /* True if file has multiple scans */
  145776. boolean eoi_reached; /* True when EOI has been consumed */
  145777. };
  145778. struct jpeg_d_main_controller {
  145779. JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
  145780. JMETHOD(void, process_data, (j_decompress_ptr cinfo,
  145781. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  145782. JDIMENSION out_rows_avail));
  145783. };
  145784. struct jpeg_d_coef_controller {
  145785. JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo));
  145786. JMETHOD(int, consume_data, (j_decompress_ptr cinfo));
  145787. JMETHOD(void, start_output_pass, (j_decompress_ptr cinfo));
  145788. JMETHOD(int, decompress_data, (j_decompress_ptr cinfo,
  145789. JSAMPIMAGE output_buf));
  145790. jvirt_barray_ptr *coef_arrays;
  145791. };
  145792. struct jpeg_d_post_controller {
  145793. JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
  145794. JMETHOD(void, post_process_data, (j_decompress_ptr cinfo,
  145795. JSAMPIMAGE input_buf,
  145796. JDIMENSION *in_row_group_ctr,
  145797. JDIMENSION in_row_groups_avail,
  145798. JSAMPARRAY output_buf,
  145799. JDIMENSION *out_row_ctr,
  145800. JDIMENSION out_rows_avail));
  145801. };
  145802. struct jpeg_marker_reader {
  145803. JMETHOD(void, reset_marker_reader, (j_decompress_ptr cinfo));
  145804. JMETHOD(int, read_markers, (j_decompress_ptr cinfo));
  145805. jpeg_marker_parser_method read_restart_marker;
  145806. boolean saw_SOI; /* found SOI? */
  145807. boolean saw_SOF; /* found SOF? */
  145808. int next_restart_num; /* next restart number expected (0-7) */
  145809. unsigned int discarded_bytes; /* # of bytes skipped looking for a marker */
  145810. };
  145811. struct jpeg_entropy_decoder {
  145812. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145813. JMETHOD(boolean, decode_mcu, (j_decompress_ptr cinfo,
  145814. JBLOCKROW *MCU_data));
  145815. boolean insufficient_data; /* set TRUE after emitting warning */
  145816. };
  145817. typedef JMETHOD(void, inverse_DCT_method_ptr,
  145818. (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  145819. JCOEFPTR coef_block,
  145820. JSAMPARRAY output_buf, JDIMENSION output_col));
  145821. struct jpeg_inverse_dct {
  145822. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145823. inverse_DCT_method_ptr inverse_DCT[MAX_COMPONENTS];
  145824. };
  145825. struct jpeg_upsampler {
  145826. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145827. JMETHOD(void, upsample, (j_decompress_ptr cinfo,
  145828. JSAMPIMAGE input_buf,
  145829. JDIMENSION *in_row_group_ctr,
  145830. JDIMENSION in_row_groups_avail,
  145831. JSAMPARRAY output_buf,
  145832. JDIMENSION *out_row_ctr,
  145833. JDIMENSION out_rows_avail));
  145834. boolean need_context_rows; /* TRUE if need rows above & below */
  145835. };
  145836. struct jpeg_color_deconverter {
  145837. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145838. JMETHOD(void, color_convert, (j_decompress_ptr cinfo,
  145839. JSAMPIMAGE input_buf, JDIMENSION input_row,
  145840. JSAMPARRAY output_buf, int num_rows));
  145841. };
  145842. struct jpeg_color_quantizer {
  145843. JMETHOD(void, start_pass, (j_decompress_ptr cinfo, boolean is_pre_scan));
  145844. JMETHOD(void, color_quantize, (j_decompress_ptr cinfo,
  145845. JSAMPARRAY input_buf, JSAMPARRAY output_buf,
  145846. int num_rows));
  145847. JMETHOD(void, finish_pass, (j_decompress_ptr cinfo));
  145848. JMETHOD(void, new_color_map, (j_decompress_ptr cinfo));
  145849. };
  145850. #undef MAX
  145851. #define MAX(a,b) ((a) > (b) ? (a) : (b))
  145852. #undef MIN
  145853. #define MIN(a,b) ((a) < (b) ? (a) : (b))
  145854. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  145855. #define SHIFT_TEMPS INT32 shift_temp;
  145856. #define RIGHT_SHIFT(x,shft) \
  145857. ((shift_temp = (x)) < 0 ? \
  145858. (shift_temp >> (shft)) | ((~((INT32) 0)) << (32-(shft))) : \
  145859. (shift_temp >> (shft)))
  145860. #else
  145861. #define SHIFT_TEMPS
  145862. #define RIGHT_SHIFT(x,shft) ((x) >> (shft))
  145863. #endif
  145864. #ifdef NEED_SHORT_EXTERNAL_NAMES
  145865. #define jinit_compress_master jICompress
  145866. #define jinit_c_master_control jICMaster
  145867. #define jinit_c_main_controller jICMainC
  145868. #define jinit_c_prep_controller jICPrepC
  145869. #define jinit_c_coef_controller jICCoefC
  145870. #define jinit_color_converter jICColor
  145871. #define jinit_downsampler jIDownsampler
  145872. #define jinit_forward_dct jIFDCT
  145873. #define jinit_huff_encoder jIHEncoder
  145874. #define jinit_phuff_encoder jIPHEncoder
  145875. #define jinit_marker_writer jIMWriter
  145876. #define jinit_master_decompress jIDMaster
  145877. #define jinit_d_main_controller jIDMainC
  145878. #define jinit_d_coef_controller jIDCoefC
  145879. #define jinit_d_post_controller jIDPostC
  145880. #define jinit_input_controller jIInCtlr
  145881. #define jinit_marker_reader jIMReader
  145882. #define jinit_huff_decoder jIHDecoder
  145883. #define jinit_phuff_decoder jIPHDecoder
  145884. #define jinit_inverse_dct jIIDCT
  145885. #define jinit_upsampler jIUpsampler
  145886. #define jinit_color_deconverter jIDColor
  145887. #define jinit_1pass_quantizer jI1Quant
  145888. #define jinit_2pass_quantizer jI2Quant
  145889. #define jinit_merged_upsampler jIMUpsampler
  145890. #define jinit_memory_mgr jIMemMgr
  145891. #define jdiv_round_up jDivRound
  145892. #define jround_up jRound
  145893. #define jcopy_sample_rows jCopySamples
  145894. #define jcopy_block_row jCopyBlocks
  145895. #define jzero_far jZeroFar
  145896. #define jpeg_zigzag_order jZIGTable
  145897. #define jpeg_natural_order jZAGTable
  145898. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  145899. EXTERN(void) jinit_compress_master JPP((j_compress_ptr cinfo));
  145900. EXTERN(void) jinit_c_master_control JPP((j_compress_ptr cinfo,
  145901. boolean transcode_only));
  145902. EXTERN(void) jinit_c_main_controller JPP((j_compress_ptr cinfo,
  145903. boolean need_full_buffer));
  145904. EXTERN(void) jinit_c_prep_controller JPP((j_compress_ptr cinfo,
  145905. boolean need_full_buffer));
  145906. EXTERN(void) jinit_c_coef_controller JPP((j_compress_ptr cinfo,
  145907. boolean need_full_buffer));
  145908. EXTERN(void) jinit_color_converter JPP((j_compress_ptr cinfo));
  145909. EXTERN(void) jinit_downsampler JPP((j_compress_ptr cinfo));
  145910. EXTERN(void) jinit_forward_dct JPP((j_compress_ptr cinfo));
  145911. EXTERN(void) jinit_huff_encoder JPP((j_compress_ptr cinfo));
  145912. EXTERN(void) jinit_phuff_encoder JPP((j_compress_ptr cinfo));
  145913. EXTERN(void) jinit_marker_writer JPP((j_compress_ptr cinfo));
  145914. EXTERN(void) jinit_master_decompress JPP((j_decompress_ptr cinfo));
  145915. EXTERN(void) jinit_d_main_controller JPP((j_decompress_ptr cinfo,
  145916. boolean need_full_buffer));
  145917. EXTERN(void) jinit_d_coef_controller JPP((j_decompress_ptr cinfo,
  145918. boolean need_full_buffer));
  145919. EXTERN(void) jinit_d_post_controller JPP((j_decompress_ptr cinfo,
  145920. boolean need_full_buffer));
  145921. EXTERN(void) jinit_input_controller JPP((j_decompress_ptr cinfo));
  145922. EXTERN(void) jinit_marker_reader JPP((j_decompress_ptr cinfo));
  145923. EXTERN(void) jinit_huff_decoder JPP((j_decompress_ptr cinfo));
  145924. EXTERN(void) jinit_phuff_decoder JPP((j_decompress_ptr cinfo));
  145925. EXTERN(void) jinit_inverse_dct JPP((j_decompress_ptr cinfo));
  145926. EXTERN(void) jinit_upsampler JPP((j_decompress_ptr cinfo));
  145927. EXTERN(void) jinit_color_deconverter JPP((j_decompress_ptr cinfo));
  145928. EXTERN(void) jinit_1pass_quantizer JPP((j_decompress_ptr cinfo));
  145929. EXTERN(void) jinit_2pass_quantizer JPP((j_decompress_ptr cinfo));
  145930. EXTERN(void) jinit_merged_upsampler JPP((j_decompress_ptr cinfo));
  145931. EXTERN(void) jinit_memory_mgr JPP((j_common_ptr cinfo));
  145932. EXTERN(long) jdiv_round_up JPP((long a, long b));
  145933. EXTERN(long) jround_up JPP((long a, long b));
  145934. EXTERN(void) jcopy_sample_rows JPP((JSAMPARRAY input_array, int source_row,
  145935. JSAMPARRAY output_array, int dest_row,
  145936. int num_rows, JDIMENSION num_cols));
  145937. EXTERN(void) jcopy_block_row JPP((JBLOCKROW input_row, JBLOCKROW output_row,
  145938. JDIMENSION num_blocks));
  145939. EXTERN(void) jzero_far JPP((void FAR * target, size_t bytestozero));
  145940. #if 0 /* This table is not actually needed in v6a */
  145941. extern const int jpeg_zigzag_order[]; /* natural coef order to zigzag order */
  145942. #endif
  145943. extern const int jpeg_natural_order[]; /* zigzag coef order to natural order */
  145944. #ifdef INCOMPLETE_TYPES_BROKEN
  145945. #ifndef AM_MEMORY_MANAGER /* only jmemmgr.c defines these */
  145946. struct jvirt_sarray_control { long dummy; };
  145947. struct jvirt_barray_control { long dummy; };
  145948. #endif
  145949. #endif /* INCOMPLETE_TYPES_BROKEN */
  145950. /*** End of inlined file: jpegint.h ***/
  145951. /* fetch private declarations */
  145952. /*** Start of inlined file: jerror.h ***/
  145953. #ifndef JMESSAGE
  145954. #ifndef JERROR_H
  145955. #define JMAKE_ENUM_LIST
  145956. #else
  145957. #define JMESSAGE(code,string)
  145958. #endif /* JERROR_H */
  145959. #endif /* JMESSAGE */
  145960. #ifdef JMAKE_ENUM_LIST
  145961. typedef enum {
  145962. #define JMESSAGE(code,string) code ,
  145963. #endif /* JMAKE_ENUM_LIST */
  145964. JMESSAGE(JMSG_NOMESSAGE, "Bogus message code %d") /* Must be first entry! */
  145965. JMESSAGE(JERR_ARITH_NOTIMPL,
  145966. "Sorry, there are legal restrictions on arithmetic coding")
  145967. JMESSAGE(JERR_BAD_ALIGN_TYPE, "ALIGN_TYPE is wrong, please fix")
  145968. JMESSAGE(JERR_BAD_ALLOC_CHUNK, "MAX_ALLOC_CHUNK is wrong, please fix")
  145969. JMESSAGE(JERR_BAD_BUFFER_MODE, "Bogus buffer control mode")
  145970. JMESSAGE(JERR_BAD_COMPONENT_ID, "Invalid component ID %d in SOS")
  145971. JMESSAGE(JERR_BAD_DCT_COEF, "DCT coefficient out of range")
  145972. JMESSAGE(JERR_BAD_DCTSIZE, "IDCT output block size %d not supported")
  145973. JMESSAGE(JERR_BAD_HUFF_TABLE, "Bogus Huffman table definition")
  145974. JMESSAGE(JERR_BAD_IN_COLORSPACE, "Bogus input colorspace")
  145975. JMESSAGE(JERR_BAD_J_COLORSPACE, "Bogus JPEG colorspace")
  145976. JMESSAGE(JERR_BAD_LENGTH, "Bogus marker length")
  145977. JMESSAGE(JERR_BAD_LIB_VERSION,
  145978. "Wrong JPEG library version: library is %d, caller expects %d")
  145979. JMESSAGE(JERR_BAD_MCU_SIZE, "Sampling factors too large for interleaved scan")
  145980. JMESSAGE(JERR_BAD_POOL_ID, "Invalid memory pool code %d")
  145981. JMESSAGE(JERR_BAD_PRECISION, "Unsupported JPEG data precision %d")
  145982. JMESSAGE(JERR_BAD_PROGRESSION,
  145983. "Invalid progressive parameters Ss=%d Se=%d Ah=%d Al=%d")
  145984. JMESSAGE(JERR_BAD_PROG_SCRIPT,
  145985. "Invalid progressive parameters at scan script entry %d")
  145986. JMESSAGE(JERR_BAD_SAMPLING, "Bogus sampling factors")
  145987. JMESSAGE(JERR_BAD_SCAN_SCRIPT, "Invalid scan script at entry %d")
  145988. JMESSAGE(JERR_BAD_STATE, "Improper call to JPEG library in state %d")
  145989. JMESSAGE(JERR_BAD_STRUCT_SIZE,
  145990. "JPEG parameter struct mismatch: library thinks size is %u, caller expects %u")
  145991. JMESSAGE(JERR_BAD_VIRTUAL_ACCESS, "Bogus virtual array access")
  145992. JMESSAGE(JERR_BUFFER_SIZE, "Buffer passed to JPEG library is too small")
  145993. JMESSAGE(JERR_CANT_SUSPEND, "Suspension not allowed here")
  145994. JMESSAGE(JERR_CCIR601_NOTIMPL, "CCIR601 sampling not implemented yet")
  145995. JMESSAGE(JERR_COMPONENT_COUNT, "Too many color components: %d, max %d")
  145996. JMESSAGE(JERR_CONVERSION_NOTIMPL, "Unsupported color conversion request")
  145997. JMESSAGE(JERR_DAC_INDEX, "Bogus DAC index %d")
  145998. JMESSAGE(JERR_DAC_VALUE, "Bogus DAC value 0x%x")
  145999. JMESSAGE(JERR_DHT_INDEX, "Bogus DHT index %d")
  146000. JMESSAGE(JERR_DQT_INDEX, "Bogus DQT index %d")
  146001. JMESSAGE(JERR_EMPTY_IMAGE, "Empty JPEG image (DNL not supported)")
  146002. JMESSAGE(JERR_EMS_READ, "Read from EMS failed")
  146003. JMESSAGE(JERR_EMS_WRITE, "Write to EMS failed")
  146004. JMESSAGE(JERR_EOI_EXPECTED, "Didn't expect more than one scan")
  146005. JMESSAGE(JERR_FILE_READ, "Input file read error")
  146006. JMESSAGE(JERR_FILE_WRITE, "Output file write error --- out of disk space?")
  146007. JMESSAGE(JERR_FRACT_SAMPLE_NOTIMPL, "Fractional sampling not implemented yet")
  146008. JMESSAGE(JERR_HUFF_CLEN_OVERFLOW, "Huffman code size table overflow")
  146009. JMESSAGE(JERR_HUFF_MISSING_CODE, "Missing Huffman code table entry")
  146010. JMESSAGE(JERR_IMAGE_TOO_BIG, "Maximum supported image dimension is %u pixels")
  146011. JMESSAGE(JERR_INPUT_EMPTY, "Empty input file")
  146012. JMESSAGE(JERR_INPUT_EOF, "Premature end of input file")
  146013. JMESSAGE(JERR_MISMATCHED_QUANT_TABLE,
  146014. "Cannot transcode due to multiple use of quantization table %d")
  146015. JMESSAGE(JERR_MISSING_DATA, "Scan script does not transmit all data")
  146016. JMESSAGE(JERR_MODE_CHANGE, "Invalid color quantization mode change")
  146017. JMESSAGE(JERR_NOTIMPL, "Not implemented yet")
  146018. JMESSAGE(JERR_NOT_COMPILED, "Requested feature was omitted at compile time")
  146019. JMESSAGE(JERR_NO_BACKING_STORE, "Backing store not supported")
  146020. JMESSAGE(JERR_NO_HUFF_TABLE, "Huffman table 0x%02x was not defined")
  146021. JMESSAGE(JERR_NO_IMAGE, "JPEG datastream contains no image")
  146022. JMESSAGE(JERR_NO_QUANT_TABLE, "Quantization table 0x%02x was not defined")
  146023. JMESSAGE(JERR_NO_SOI, "Not a JPEG file: starts with 0x%02x 0x%02x")
  146024. JMESSAGE(JERR_OUT_OF_MEMORY, "Insufficient memory (case %d)")
  146025. JMESSAGE(JERR_QUANT_COMPONENTS,
  146026. "Cannot quantize more than %d color components")
  146027. JMESSAGE(JERR_QUANT_FEW_COLORS, "Cannot quantize to fewer than %d colors")
  146028. JMESSAGE(JERR_QUANT_MANY_COLORS, "Cannot quantize to more than %d colors")
  146029. JMESSAGE(JERR_SOF_DUPLICATE, "Invalid JPEG file structure: two SOF markers")
  146030. JMESSAGE(JERR_SOF_NO_SOS, "Invalid JPEG file structure: missing SOS marker")
  146031. JMESSAGE(JERR_SOF_UNSUPPORTED, "Unsupported JPEG process: SOF type 0x%02x")
  146032. JMESSAGE(JERR_SOI_DUPLICATE, "Invalid JPEG file structure: two SOI markers")
  146033. JMESSAGE(JERR_SOS_NO_SOF, "Invalid JPEG file structure: SOS before SOF")
  146034. JMESSAGE(JERR_TFILE_CREATE, "Failed to create temporary file %s")
  146035. JMESSAGE(JERR_TFILE_READ, "Read failed on temporary file")
  146036. JMESSAGE(JERR_TFILE_SEEK, "Seek failed on temporary file")
  146037. JMESSAGE(JERR_TFILE_WRITE,
  146038. "Write failed on temporary file --- out of disk space?")
  146039. JMESSAGE(JERR_TOO_LITTLE_DATA, "Application transferred too few scanlines")
  146040. JMESSAGE(JERR_UNKNOWN_MARKER, "Unsupported marker type 0x%02x")
  146041. JMESSAGE(JERR_VIRTUAL_BUG, "Virtual array controller messed up")
  146042. JMESSAGE(JERR_WIDTH_OVERFLOW, "Image too wide for this implementation")
  146043. JMESSAGE(JERR_XMS_READ, "Read from XMS failed")
  146044. JMESSAGE(JERR_XMS_WRITE, "Write to XMS failed")
  146045. JMESSAGE(JMSG_COPYRIGHT, JCOPYRIGHT)
  146046. JMESSAGE(JMSG_VERSION, JVERSION)
  146047. JMESSAGE(JTRC_16BIT_TABLES,
  146048. "Caution: quantization tables are too coarse for baseline JPEG")
  146049. JMESSAGE(JTRC_ADOBE,
  146050. "Adobe APP14 marker: version %d, flags 0x%04x 0x%04x, transform %d")
  146051. JMESSAGE(JTRC_APP0, "Unknown APP0 marker (not JFIF), length %u")
  146052. JMESSAGE(JTRC_APP14, "Unknown APP14 marker (not Adobe), length %u")
  146053. JMESSAGE(JTRC_DAC, "Define Arithmetic Table 0x%02x: 0x%02x")
  146054. JMESSAGE(JTRC_DHT, "Define Huffman Table 0x%02x")
  146055. JMESSAGE(JTRC_DQT, "Define Quantization Table %d precision %d")
  146056. JMESSAGE(JTRC_DRI, "Define Restart Interval %u")
  146057. JMESSAGE(JTRC_EMS_CLOSE, "Freed EMS handle %u")
  146058. JMESSAGE(JTRC_EMS_OPEN, "Obtained EMS handle %u")
  146059. JMESSAGE(JTRC_EOI, "End Of Image")
  146060. JMESSAGE(JTRC_HUFFBITS, " %3d %3d %3d %3d %3d %3d %3d %3d")
  146061. JMESSAGE(JTRC_JFIF, "JFIF APP0 marker: version %d.%02d, density %dx%d %d")
  146062. JMESSAGE(JTRC_JFIF_BADTHUMBNAILSIZE,
  146063. "Warning: thumbnail image size does not match data length %u")
  146064. JMESSAGE(JTRC_JFIF_EXTENSION,
  146065. "JFIF extension marker: type 0x%02x, length %u")
  146066. JMESSAGE(JTRC_JFIF_THUMBNAIL, " with %d x %d thumbnail image")
  146067. JMESSAGE(JTRC_MISC_MARKER, "Miscellaneous marker 0x%02x, length %u")
  146068. JMESSAGE(JTRC_PARMLESS_MARKER, "Unexpected marker 0x%02x")
  146069. JMESSAGE(JTRC_QUANTVALS, " %4u %4u %4u %4u %4u %4u %4u %4u")
  146070. JMESSAGE(JTRC_QUANT_3_NCOLORS, "Quantizing to %d = %d*%d*%d colors")
  146071. JMESSAGE(JTRC_QUANT_NCOLORS, "Quantizing to %d colors")
  146072. JMESSAGE(JTRC_QUANT_SELECTED, "Selected %d colors for quantization")
  146073. JMESSAGE(JTRC_RECOVERY_ACTION, "At marker 0x%02x, recovery action %d")
  146074. JMESSAGE(JTRC_RST, "RST%d")
  146075. JMESSAGE(JTRC_SMOOTH_NOTIMPL,
  146076. "Smoothing not supported with nonstandard sampling ratios")
  146077. JMESSAGE(JTRC_SOF, "Start Of Frame 0x%02x: width=%u, height=%u, components=%d")
  146078. JMESSAGE(JTRC_SOF_COMPONENT, " Component %d: %dhx%dv q=%d")
  146079. JMESSAGE(JTRC_SOI, "Start of Image")
  146080. JMESSAGE(JTRC_SOS, "Start Of Scan: %d components")
  146081. JMESSAGE(JTRC_SOS_COMPONENT, " Component %d: dc=%d ac=%d")
  146082. JMESSAGE(JTRC_SOS_PARAMS, " Ss=%d, Se=%d, Ah=%d, Al=%d")
  146083. JMESSAGE(JTRC_TFILE_CLOSE, "Closed temporary file %s")
  146084. JMESSAGE(JTRC_TFILE_OPEN, "Opened temporary file %s")
  146085. JMESSAGE(JTRC_THUMB_JPEG,
  146086. "JFIF extension marker: JPEG-compressed thumbnail image, length %u")
  146087. JMESSAGE(JTRC_THUMB_PALETTE,
  146088. "JFIF extension marker: palette thumbnail image, length %u")
  146089. JMESSAGE(JTRC_THUMB_RGB,
  146090. "JFIF extension marker: RGB thumbnail image, length %u")
  146091. JMESSAGE(JTRC_UNKNOWN_IDS,
  146092. "Unrecognized component IDs %d %d %d, assuming YCbCr")
  146093. JMESSAGE(JTRC_XMS_CLOSE, "Freed XMS handle %u")
  146094. JMESSAGE(JTRC_XMS_OPEN, "Obtained XMS handle %u")
  146095. JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d")
  146096. JMESSAGE(JWRN_BOGUS_PROGRESSION,
  146097. "Inconsistent progression sequence for component %d coefficient %d")
  146098. JMESSAGE(JWRN_EXTRANEOUS_DATA,
  146099. "Corrupt JPEG data: %u extraneous bytes before marker 0x%02x")
  146100. JMESSAGE(JWRN_HIT_MARKER, "Corrupt JPEG data: premature end of data segment")
  146101. JMESSAGE(JWRN_HUFF_BAD_CODE, "Corrupt JPEG data: bad Huffman code")
  146102. JMESSAGE(JWRN_JFIF_MAJOR, "Warning: unknown JFIF revision number %d.%02d")
  146103. JMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file")
  146104. JMESSAGE(JWRN_MUST_RESYNC,
  146105. "Corrupt JPEG data: found marker 0x%02x instead of RST%d")
  146106. JMESSAGE(JWRN_NOT_SEQUENTIAL, "Invalid SOS parameters for sequential JPEG")
  146107. JMESSAGE(JWRN_TOO_MUCH_DATA, "Application transferred too many scanlines")
  146108. #ifdef JMAKE_ENUM_LIST
  146109. JMSG_LASTMSGCODE
  146110. } J_MESSAGE_CODE;
  146111. #undef JMAKE_ENUM_LIST
  146112. #endif /* JMAKE_ENUM_LIST */
  146113. #undef JMESSAGE
  146114. #ifndef JERROR_H
  146115. #define JERROR_H
  146116. #define ERREXIT(cinfo,code) \
  146117. ((cinfo)->err->msg_code = (code), \
  146118. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  146119. #define ERREXIT1(cinfo,code,p1) \
  146120. ((cinfo)->err->msg_code = (code), \
  146121. (cinfo)->err->msg_parm.i[0] = (p1), \
  146122. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  146123. #define ERREXIT2(cinfo,code,p1,p2) \
  146124. ((cinfo)->err->msg_code = (code), \
  146125. (cinfo)->err->msg_parm.i[0] = (p1), \
  146126. (cinfo)->err->msg_parm.i[1] = (p2), \
  146127. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  146128. #define ERREXIT3(cinfo,code,p1,p2,p3) \
  146129. ((cinfo)->err->msg_code = (code), \
  146130. (cinfo)->err->msg_parm.i[0] = (p1), \
  146131. (cinfo)->err->msg_parm.i[1] = (p2), \
  146132. (cinfo)->err->msg_parm.i[2] = (p3), \
  146133. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  146134. #define ERREXIT4(cinfo,code,p1,p2,p3,p4) \
  146135. ((cinfo)->err->msg_code = (code), \
  146136. (cinfo)->err->msg_parm.i[0] = (p1), \
  146137. (cinfo)->err->msg_parm.i[1] = (p2), \
  146138. (cinfo)->err->msg_parm.i[2] = (p3), \
  146139. (cinfo)->err->msg_parm.i[3] = (p4), \
  146140. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  146141. #define ERREXITS(cinfo,code,str) \
  146142. ((cinfo)->err->msg_code = (code), \
  146143. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  146144. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  146145. #define MAKESTMT(stuff) do { stuff } while (0)
  146146. #define WARNMS(cinfo,code) \
  146147. ((cinfo)->err->msg_code = (code), \
  146148. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  146149. #define WARNMS1(cinfo,code,p1) \
  146150. ((cinfo)->err->msg_code = (code), \
  146151. (cinfo)->err->msg_parm.i[0] = (p1), \
  146152. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  146153. #define WARNMS2(cinfo,code,p1,p2) \
  146154. ((cinfo)->err->msg_code = (code), \
  146155. (cinfo)->err->msg_parm.i[0] = (p1), \
  146156. (cinfo)->err->msg_parm.i[1] = (p2), \
  146157. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  146158. #define TRACEMS(cinfo,lvl,code) \
  146159. ((cinfo)->err->msg_code = (code), \
  146160. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  146161. #define TRACEMS1(cinfo,lvl,code,p1) \
  146162. ((cinfo)->err->msg_code = (code), \
  146163. (cinfo)->err->msg_parm.i[0] = (p1), \
  146164. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  146165. #define TRACEMS2(cinfo,lvl,code,p1,p2) \
  146166. ((cinfo)->err->msg_code = (code), \
  146167. (cinfo)->err->msg_parm.i[0] = (p1), \
  146168. (cinfo)->err->msg_parm.i[1] = (p2), \
  146169. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  146170. #define TRACEMS3(cinfo,lvl,code,p1,p2,p3) \
  146171. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  146172. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); \
  146173. (cinfo)->err->msg_code = (code); \
  146174. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  146175. #define TRACEMS4(cinfo,lvl,code,p1,p2,p3,p4) \
  146176. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  146177. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  146178. (cinfo)->err->msg_code = (code); \
  146179. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  146180. #define TRACEMS5(cinfo,lvl,code,p1,p2,p3,p4,p5) \
  146181. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  146182. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  146183. _mp[4] = (p5); \
  146184. (cinfo)->err->msg_code = (code); \
  146185. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  146186. #define TRACEMS8(cinfo,lvl,code,p1,p2,p3,p4,p5,p6,p7,p8) \
  146187. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  146188. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  146189. _mp[4] = (p5); _mp[5] = (p6); _mp[6] = (p7); _mp[7] = (p8); \
  146190. (cinfo)->err->msg_code = (code); \
  146191. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  146192. #define TRACEMSS(cinfo,lvl,code,str) \
  146193. ((cinfo)->err->msg_code = (code), \
  146194. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  146195. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  146196. #endif /* JERROR_H */
  146197. /*** End of inlined file: jerror.h ***/
  146198. /* fetch error codes too */
  146199. #endif
  146200. #endif /* JPEGLIB_H */
  146201. /*** End of inlined file: jpeglib.h ***/
  146202. /*** Start of inlined file: jcapimin.c ***/
  146203. #define JPEG_INTERNALS
  146204. /*** Start of inlined file: jinclude.h ***/
  146205. #ifndef __jinclude_h__
  146206. #define __jinclude_h__
  146207. /*** Start of inlined file: jconfig.h ***/
  146208. // disable all the warnings under MSVC
  146209. #ifdef _MSC_VER
  146210. #pragma warning (disable: 4996 4267 4100 4127 4702 4244)
  146211. #endif
  146212. #ifdef __BORLANDC__
  146213. #pragma warn -8057
  146214. #pragma warn -8019
  146215. #pragma warn -8004
  146216. #pragma warn -8008
  146217. #endif
  146218. #define HAVE_PROTOTYPES
  146219. #define HAVE_UNSIGNED_CHAR
  146220. #define HAVE_UNSIGNED_SHORT
  146221. #undef CHAR_IS_UNSIGNED
  146222. #define HAVE_STDDEF_H
  146223. #define HAVE_STDLIB_H
  146224. #undef NEED_BSD_STRINGS
  146225. #undef NEED_SYS_TYPES_H
  146226. #undef NEED_FAR_POINTERS /* we presume a 32-bit flat memory model */
  146227. #undef NEED_SHORT_EXTERNAL_NAMES
  146228. #undef INCOMPLETE_TYPES_BROKEN
  146229. #ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
  146230. typedef unsigned char boolean;
  146231. #endif
  146232. #define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
  146233. #ifdef JPEG_INTERNALS
  146234. #undef RIGHT_SHIFT_IS_UNSIGNED
  146235. #endif /* JPEG_INTERNALS */
  146236. #ifdef JPEG_CJPEG_DJPEG
  146237. #define BMP_SUPPORTED /* BMP image file format */
  146238. #define GIF_SUPPORTED /* GIF image file format */
  146239. #define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
  146240. #undef RLE_SUPPORTED /* Utah RLE image file format */
  146241. #define TARGA_SUPPORTED /* Targa image file format */
  146242. #define TWO_FILE_COMMANDLINE /* optional */
  146243. #define USE_SETMODE /* Microsoft has setmode() */
  146244. #undef NEED_SIGNAL_CATCHER
  146245. #undef DONT_USE_B_MODE
  146246. #undef PROGRESS_REPORT /* optional */
  146247. #endif /* JPEG_CJPEG_DJPEG */
  146248. /*** End of inlined file: jconfig.h ***/
  146249. /* auto configuration options */
  146250. #define JCONFIG_INCLUDED /* so that jpeglib.h doesn't do it again */
  146251. #ifdef HAVE_STDDEF_H
  146252. #include <stddef.h>
  146253. #endif
  146254. #ifdef HAVE_STDLIB_H
  146255. #include <stdlib.h>
  146256. #endif
  146257. #ifdef NEED_SYS_TYPES_H
  146258. #include <sys/types.h>
  146259. #endif
  146260. #include <stdio.h>
  146261. #ifdef NEED_BSD_STRINGS
  146262. #include <strings.h>
  146263. #define MEMZERO(target,size) bzero((void *)(target), (size_t)(size))
  146264. #define MEMCOPY(dest,src,size) bcopy((const void *)(src), (void *)(dest), (size_t)(size))
  146265. #else /* not BSD, assume ANSI/SysV string lib */
  146266. #include <string.h>
  146267. #define MEMZERO(target,size) memset((void *)(target), 0, (size_t)(size))
  146268. #define MEMCOPY(dest,src,size) memcpy((void *)(dest), (const void *)(src), (size_t)(size))
  146269. #endif
  146270. #define SIZEOF(object) ((size_t) sizeof(object))
  146271. #define JFREAD(file,buf,sizeofbuf) \
  146272. ((size_t) fread((void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
  146273. #define JFWRITE(file,buf,sizeofbuf) \
  146274. ((size_t) fwrite((const void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
  146275. typedef enum { /* JPEG marker codes */
  146276. M_SOF0 = 0xc0,
  146277. M_SOF1 = 0xc1,
  146278. M_SOF2 = 0xc2,
  146279. M_SOF3 = 0xc3,
  146280. M_SOF5 = 0xc5,
  146281. M_SOF6 = 0xc6,
  146282. M_SOF7 = 0xc7,
  146283. M_JPG = 0xc8,
  146284. M_SOF9 = 0xc9,
  146285. M_SOF10 = 0xca,
  146286. M_SOF11 = 0xcb,
  146287. M_SOF13 = 0xcd,
  146288. M_SOF14 = 0xce,
  146289. M_SOF15 = 0xcf,
  146290. M_DHT = 0xc4,
  146291. M_DAC = 0xcc,
  146292. M_RST0 = 0xd0,
  146293. M_RST1 = 0xd1,
  146294. M_RST2 = 0xd2,
  146295. M_RST3 = 0xd3,
  146296. M_RST4 = 0xd4,
  146297. M_RST5 = 0xd5,
  146298. M_RST6 = 0xd6,
  146299. M_RST7 = 0xd7,
  146300. M_SOI = 0xd8,
  146301. M_EOI = 0xd9,
  146302. M_SOS = 0xda,
  146303. M_DQT = 0xdb,
  146304. M_DNL = 0xdc,
  146305. M_DRI = 0xdd,
  146306. M_DHP = 0xde,
  146307. M_EXP = 0xdf,
  146308. M_APP0 = 0xe0,
  146309. M_APP1 = 0xe1,
  146310. M_APP2 = 0xe2,
  146311. M_APP3 = 0xe3,
  146312. M_APP4 = 0xe4,
  146313. M_APP5 = 0xe5,
  146314. M_APP6 = 0xe6,
  146315. M_APP7 = 0xe7,
  146316. M_APP8 = 0xe8,
  146317. M_APP9 = 0xe9,
  146318. M_APP10 = 0xea,
  146319. M_APP11 = 0xeb,
  146320. M_APP12 = 0xec,
  146321. M_APP13 = 0xed,
  146322. M_APP14 = 0xee,
  146323. M_APP15 = 0xef,
  146324. M_JPG0 = 0xf0,
  146325. M_JPG13 = 0xfd,
  146326. M_COM = 0xfe,
  146327. M_TEM = 0x01,
  146328. M_ERROR = 0x100
  146329. } JPEG_MARKER;
  146330. #ifdef AVOID_TABLES
  146331. #define HUFF_EXTEND(x,s) ((x) < (1<<((s)-1)) ? (x) + (((-1)<<(s)) + 1) : (x))
  146332. #else
  146333. #define HUFF_EXTEND(x,s) ((x) < extend_test[s] ? (x) + extend_offset[s] : (x))
  146334. static const int extend_test[16] = /* entry n is 2**(n-1) */
  146335. { 0, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
  146336. 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000 };
  146337. static const int extend_offset[16] = /* entry n is (-1 << n) + 1 */
  146338. { 0, ((-1)<<1) + 1, ((-1)<<2) + 1, ((-1)<<3) + 1, ((-1)<<4) + 1,
  146339. ((-1)<<5) + 1, ((-1)<<6) + 1, ((-1)<<7) + 1, ((-1)<<8) + 1,
  146340. ((-1)<<9) + 1, ((-1)<<10) + 1, ((-1)<<11) + 1, ((-1)<<12) + 1,
  146341. ((-1)<<13) + 1, ((-1)<<14) + 1, ((-1)<<15) + 1 };
  146342. #endif /* AVOID_TABLES */
  146343. #endif
  146344. /*** End of inlined file: jinclude.h ***/
  146345. GLOBAL(void)
  146346. jpeg_CreateCompress (j_compress_ptr cinfo, int version, size_t structsize)
  146347. {
  146348. int i;
  146349. cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */
  146350. if (version != JPEG_LIB_VERSION)
  146351. ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
  146352. if (structsize != SIZEOF(struct jpeg_compress_struct))
  146353. ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
  146354. (int) SIZEOF(struct jpeg_compress_struct), (int) structsize);
  146355. {
  146356. struct jpeg_error_mgr * err = cinfo->err;
  146357. void * client_data = cinfo->client_data; /* ignore Purify complaint here */
  146358. MEMZERO(cinfo, SIZEOF(struct jpeg_compress_struct));
  146359. cinfo->err = err;
  146360. cinfo->client_data = client_data;
  146361. }
  146362. cinfo->is_decompressor = FALSE;
  146363. jinit_memory_mgr((j_common_ptr) cinfo);
  146364. cinfo->progress = NULL;
  146365. cinfo->dest = NULL;
  146366. cinfo->comp_info = NULL;
  146367. for (i = 0; i < NUM_QUANT_TBLS; i++)
  146368. cinfo->quant_tbl_ptrs[i] = NULL;
  146369. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  146370. cinfo->dc_huff_tbl_ptrs[i] = NULL;
  146371. cinfo->ac_huff_tbl_ptrs[i] = NULL;
  146372. }
  146373. cinfo->script_space = NULL;
  146374. cinfo->input_gamma = 1.0; /* in case application forgets */
  146375. cinfo->global_state = CSTATE_START;
  146376. }
  146377. GLOBAL(void)
  146378. jpeg_destroy_compress (j_compress_ptr cinfo)
  146379. {
  146380. jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
  146381. }
  146382. GLOBAL(void)
  146383. jpeg_abort_compress (j_compress_ptr cinfo)
  146384. {
  146385. jpeg_abort((j_common_ptr) cinfo); /* use common routine */
  146386. }
  146387. GLOBAL(void)
  146388. jpeg_suppress_tables (j_compress_ptr cinfo, boolean suppress)
  146389. {
  146390. int i;
  146391. JQUANT_TBL * qtbl;
  146392. JHUFF_TBL * htbl;
  146393. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  146394. if ((qtbl = cinfo->quant_tbl_ptrs[i]) != NULL)
  146395. qtbl->sent_table = suppress;
  146396. }
  146397. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  146398. if ((htbl = cinfo->dc_huff_tbl_ptrs[i]) != NULL)
  146399. htbl->sent_table = suppress;
  146400. if ((htbl = cinfo->ac_huff_tbl_ptrs[i]) != NULL)
  146401. htbl->sent_table = suppress;
  146402. }
  146403. }
  146404. GLOBAL(void)
  146405. jpeg_finish_compress (j_compress_ptr cinfo)
  146406. {
  146407. JDIMENSION iMCU_row;
  146408. if (cinfo->global_state == CSTATE_SCANNING ||
  146409. cinfo->global_state == CSTATE_RAW_OK) {
  146410. if (cinfo->next_scanline < cinfo->image_height)
  146411. ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
  146412. (*cinfo->master->finish_pass) (cinfo);
  146413. } else if (cinfo->global_state != CSTATE_WRCOEFS)
  146414. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146415. while (! cinfo->master->is_last_pass) {
  146416. (*cinfo->master->prepare_for_pass) (cinfo);
  146417. for (iMCU_row = 0; iMCU_row < cinfo->total_iMCU_rows; iMCU_row++) {
  146418. if (cinfo->progress != NULL) {
  146419. cinfo->progress->pass_counter = (long) iMCU_row;
  146420. cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows;
  146421. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  146422. }
  146423. if (! (*cinfo->coef->compress_data) (cinfo, (JSAMPIMAGE) NULL))
  146424. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  146425. }
  146426. (*cinfo->master->finish_pass) (cinfo);
  146427. }
  146428. (*cinfo->marker->write_file_trailer) (cinfo);
  146429. (*cinfo->dest->term_destination) (cinfo);
  146430. jpeg_abort((j_common_ptr) cinfo);
  146431. }
  146432. GLOBAL(void)
  146433. jpeg_write_marker (j_compress_ptr cinfo, int marker,
  146434. const JOCTET *dataptr, unsigned int datalen)
  146435. {
  146436. JMETHOD(void, write_marker_byte, (j_compress_ptr info, int val));
  146437. if (cinfo->next_scanline != 0 ||
  146438. (cinfo->global_state != CSTATE_SCANNING &&
  146439. cinfo->global_state != CSTATE_RAW_OK &&
  146440. cinfo->global_state != CSTATE_WRCOEFS))
  146441. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146442. (*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
  146443. write_marker_byte = cinfo->marker->write_marker_byte; /* copy for speed */
  146444. while (datalen--) {
  146445. (*write_marker_byte) (cinfo, *dataptr);
  146446. dataptr++;
  146447. }
  146448. }
  146449. GLOBAL(void)
  146450. jpeg_write_m_header (j_compress_ptr cinfo, int marker, unsigned int datalen)
  146451. {
  146452. if (cinfo->next_scanline != 0 ||
  146453. (cinfo->global_state != CSTATE_SCANNING &&
  146454. cinfo->global_state != CSTATE_RAW_OK &&
  146455. cinfo->global_state != CSTATE_WRCOEFS))
  146456. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146457. (*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
  146458. }
  146459. GLOBAL(void)
  146460. jpeg_write_m_byte (j_compress_ptr cinfo, int val)
  146461. {
  146462. (*cinfo->marker->write_marker_byte) (cinfo, val);
  146463. }
  146464. GLOBAL(void)
  146465. jpeg_write_tables (j_compress_ptr cinfo)
  146466. {
  146467. if (cinfo->global_state != CSTATE_START)
  146468. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146469. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  146470. (*cinfo->dest->init_destination) (cinfo);
  146471. jinit_marker_writer(cinfo);
  146472. (*cinfo->marker->write_tables_only) (cinfo);
  146473. (*cinfo->dest->term_destination) (cinfo);
  146474. }
  146475. /*** End of inlined file: jcapimin.c ***/
  146476. /*** Start of inlined file: jcapistd.c ***/
  146477. #define JPEG_INTERNALS
  146478. GLOBAL(void)
  146479. jpeg_start_compress (j_compress_ptr cinfo, boolean write_all_tables)
  146480. {
  146481. if (cinfo->global_state != CSTATE_START)
  146482. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146483. if (write_all_tables)
  146484. jpeg_suppress_tables(cinfo, FALSE); /* mark all tables to be written */
  146485. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  146486. (*cinfo->dest->init_destination) (cinfo);
  146487. jinit_compress_master(cinfo);
  146488. (*cinfo->master->prepare_for_pass) (cinfo);
  146489. cinfo->next_scanline = 0;
  146490. cinfo->global_state = (cinfo->raw_data_in ? CSTATE_RAW_OK : CSTATE_SCANNING);
  146491. }
  146492. GLOBAL(JDIMENSION)
  146493. jpeg_write_scanlines (j_compress_ptr cinfo, JSAMPARRAY scanlines,
  146494. JDIMENSION num_lines)
  146495. {
  146496. JDIMENSION row_ctr, rows_left;
  146497. if (cinfo->global_state != CSTATE_SCANNING)
  146498. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146499. if (cinfo->next_scanline >= cinfo->image_height)
  146500. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  146501. if (cinfo->progress != NULL) {
  146502. cinfo->progress->pass_counter = (long) cinfo->next_scanline;
  146503. cinfo->progress->pass_limit = (long) cinfo->image_height;
  146504. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  146505. }
  146506. if (cinfo->master->call_pass_startup)
  146507. (*cinfo->master->pass_startup) (cinfo);
  146508. rows_left = cinfo->image_height - cinfo->next_scanline;
  146509. if (num_lines > rows_left)
  146510. num_lines = rows_left;
  146511. row_ctr = 0;
  146512. (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, num_lines);
  146513. cinfo->next_scanline += row_ctr;
  146514. return row_ctr;
  146515. }
  146516. GLOBAL(JDIMENSION)
  146517. jpeg_write_raw_data (j_compress_ptr cinfo, JSAMPIMAGE data,
  146518. JDIMENSION num_lines)
  146519. {
  146520. JDIMENSION lines_per_iMCU_row;
  146521. if (cinfo->global_state != CSTATE_RAW_OK)
  146522. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146523. if (cinfo->next_scanline >= cinfo->image_height) {
  146524. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  146525. return 0;
  146526. }
  146527. if (cinfo->progress != NULL) {
  146528. cinfo->progress->pass_counter = (long) cinfo->next_scanline;
  146529. cinfo->progress->pass_limit = (long) cinfo->image_height;
  146530. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  146531. }
  146532. if (cinfo->master->call_pass_startup)
  146533. (*cinfo->master->pass_startup) (cinfo);
  146534. lines_per_iMCU_row = cinfo->max_v_samp_factor * DCTSIZE;
  146535. if (num_lines < lines_per_iMCU_row)
  146536. ERREXIT(cinfo, JERR_BUFFER_SIZE);
  146537. if (! (*cinfo->coef->compress_data) (cinfo, data)) {
  146538. return 0;
  146539. }
  146540. cinfo->next_scanline += lines_per_iMCU_row;
  146541. return lines_per_iMCU_row;
  146542. }
  146543. /*** End of inlined file: jcapistd.c ***/
  146544. /*** Start of inlined file: jccoefct.c ***/
  146545. #define JPEG_INTERNALS
  146546. #ifdef ENTROPY_OPT_SUPPORTED
  146547. #define FULL_COEF_BUFFER_SUPPORTED
  146548. #else
  146549. #ifdef C_MULTISCAN_FILES_SUPPORTED
  146550. #define FULL_COEF_BUFFER_SUPPORTED
  146551. #endif
  146552. #endif
  146553. typedef struct {
  146554. struct jpeg_c_coef_controller pub; /* public fields */
  146555. JDIMENSION iMCU_row_num; /* iMCU row # within image */
  146556. JDIMENSION mcu_ctr; /* counts MCUs processed in current row */
  146557. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  146558. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  146559. JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU];
  146560. jvirt_barray_ptr whole_image[MAX_COMPONENTS];
  146561. } my_coef_controller;
  146562. typedef my_coef_controller * my_coef_ptr;
  146563. METHODDEF(boolean) compress_data
  146564. JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
  146565. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146566. METHODDEF(boolean) compress_first_pass
  146567. JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
  146568. METHODDEF(boolean) compress_output
  146569. JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
  146570. #endif
  146571. LOCAL(void)
  146572. start_iMCU_row (j_compress_ptr cinfo)
  146573. {
  146574. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146575. if (cinfo->comps_in_scan > 1) {
  146576. coef->MCU_rows_per_iMCU_row = 1;
  146577. } else {
  146578. if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1))
  146579. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  146580. else
  146581. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  146582. }
  146583. coef->mcu_ctr = 0;
  146584. coef->MCU_vert_offset = 0;
  146585. }
  146586. METHODDEF(void)
  146587. start_pass_coef (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  146588. {
  146589. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146590. coef->iMCU_row_num = 0;
  146591. start_iMCU_row(cinfo);
  146592. switch (pass_mode) {
  146593. case JBUF_PASS_THRU:
  146594. if (coef->whole_image[0] != NULL)
  146595. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146596. coef->pub.compress_data = compress_data;
  146597. break;
  146598. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146599. case JBUF_SAVE_AND_PASS:
  146600. if (coef->whole_image[0] == NULL)
  146601. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146602. coef->pub.compress_data = compress_first_pass;
  146603. break;
  146604. case JBUF_CRANK_DEST:
  146605. if (coef->whole_image[0] == NULL)
  146606. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146607. coef->pub.compress_data = compress_output;
  146608. break;
  146609. #endif
  146610. default:
  146611. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146612. break;
  146613. }
  146614. }
  146615. METHODDEF(boolean)
  146616. compress_data (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  146617. {
  146618. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146619. JDIMENSION MCU_col_num; /* index of current MCU within row */
  146620. JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  146621. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  146622. int blkn, bi, ci, yindex, yoffset, blockcnt;
  146623. JDIMENSION ypos, xpos;
  146624. jpeg_component_info *compptr;
  146625. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  146626. yoffset++) {
  146627. for (MCU_col_num = coef->mcu_ctr; MCU_col_num <= last_MCU_col;
  146628. MCU_col_num++) {
  146629. blkn = 0;
  146630. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  146631. compptr = cinfo->cur_comp_info[ci];
  146632. blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  146633. : compptr->last_col_width;
  146634. xpos = MCU_col_num * compptr->MCU_sample_width;
  146635. ypos = yoffset * DCTSIZE; /* ypos == (yoffset+yindex) * DCTSIZE */
  146636. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  146637. if (coef->iMCU_row_num < last_iMCU_row ||
  146638. yoffset+yindex < compptr->last_row_height) {
  146639. (*cinfo->fdct->forward_DCT) (cinfo, compptr,
  146640. input_buf[compptr->component_index],
  146641. coef->MCU_buffer[blkn],
  146642. ypos, xpos, (JDIMENSION) blockcnt);
  146643. if (blockcnt < compptr->MCU_width) {
  146644. jzero_far((void FAR *) coef->MCU_buffer[blkn + blockcnt],
  146645. (compptr->MCU_width - blockcnt) * SIZEOF(JBLOCK));
  146646. for (bi = blockcnt; bi < compptr->MCU_width; bi++) {
  146647. coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn+bi-1][0][0];
  146648. }
  146649. }
  146650. } else {
  146651. jzero_far((void FAR *) coef->MCU_buffer[blkn],
  146652. compptr->MCU_width * SIZEOF(JBLOCK));
  146653. for (bi = 0; bi < compptr->MCU_width; bi++) {
  146654. coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn-1][0][0];
  146655. }
  146656. }
  146657. blkn += compptr->MCU_width;
  146658. ypos += DCTSIZE;
  146659. }
  146660. }
  146661. if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
  146662. coef->MCU_vert_offset = yoffset;
  146663. coef->mcu_ctr = MCU_col_num;
  146664. return FALSE;
  146665. }
  146666. }
  146667. coef->mcu_ctr = 0;
  146668. }
  146669. coef->iMCU_row_num++;
  146670. start_iMCU_row(cinfo);
  146671. return TRUE;
  146672. }
  146673. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146674. METHODDEF(boolean)
  146675. compress_first_pass (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  146676. {
  146677. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146678. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  146679. JDIMENSION blocks_across, MCUs_across, MCUindex;
  146680. int bi, ci, h_samp_factor, block_row, block_rows, ndummy;
  146681. JCOEF lastDC;
  146682. jpeg_component_info *compptr;
  146683. JBLOCKARRAY buffer;
  146684. JBLOCKROW thisblockrow, lastblockrow;
  146685. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  146686. ci++, compptr++) {
  146687. buffer = (*cinfo->mem->access_virt_barray)
  146688. ((j_common_ptr) cinfo, coef->whole_image[ci],
  146689. coef->iMCU_row_num * compptr->v_samp_factor,
  146690. (JDIMENSION) compptr->v_samp_factor, TRUE);
  146691. if (coef->iMCU_row_num < last_iMCU_row)
  146692. block_rows = compptr->v_samp_factor;
  146693. else {
  146694. block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  146695. if (block_rows == 0) block_rows = compptr->v_samp_factor;
  146696. }
  146697. blocks_across = compptr->width_in_blocks;
  146698. h_samp_factor = compptr->h_samp_factor;
  146699. ndummy = (int) (blocks_across % h_samp_factor);
  146700. if (ndummy > 0)
  146701. ndummy = h_samp_factor - ndummy;
  146702. for (block_row = 0; block_row < block_rows; block_row++) {
  146703. thisblockrow = buffer[block_row];
  146704. (*cinfo->fdct->forward_DCT) (cinfo, compptr,
  146705. input_buf[ci], thisblockrow,
  146706. (JDIMENSION) (block_row * DCTSIZE),
  146707. (JDIMENSION) 0, blocks_across);
  146708. if (ndummy > 0) {
  146709. thisblockrow += blocks_across; /* => first dummy block */
  146710. jzero_far((void FAR *) thisblockrow, ndummy * SIZEOF(JBLOCK));
  146711. lastDC = thisblockrow[-1][0];
  146712. for (bi = 0; bi < ndummy; bi++) {
  146713. thisblockrow[bi][0] = lastDC;
  146714. }
  146715. }
  146716. }
  146717. if (coef->iMCU_row_num == last_iMCU_row) {
  146718. blocks_across += ndummy; /* include lower right corner */
  146719. MCUs_across = blocks_across / h_samp_factor;
  146720. for (block_row = block_rows; block_row < compptr->v_samp_factor;
  146721. block_row++) {
  146722. thisblockrow = buffer[block_row];
  146723. lastblockrow = buffer[block_row-1];
  146724. jzero_far((void FAR *) thisblockrow,
  146725. (size_t) (blocks_across * SIZEOF(JBLOCK)));
  146726. for (MCUindex = 0; MCUindex < MCUs_across; MCUindex++) {
  146727. lastDC = lastblockrow[h_samp_factor-1][0];
  146728. for (bi = 0; bi < h_samp_factor; bi++) {
  146729. thisblockrow[bi][0] = lastDC;
  146730. }
  146731. thisblockrow += h_samp_factor; /* advance to next MCU in row */
  146732. lastblockrow += h_samp_factor;
  146733. }
  146734. }
  146735. }
  146736. }
  146737. return compress_output(cinfo, input_buf);
  146738. }
  146739. METHODDEF(boolean)
  146740. compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  146741. {
  146742. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146743. JDIMENSION MCU_col_num; /* index of current MCU within row */
  146744. int blkn, ci, xindex, yindex, yoffset;
  146745. JDIMENSION start_col;
  146746. JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  146747. JBLOCKROW buffer_ptr;
  146748. jpeg_component_info *compptr;
  146749. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  146750. compptr = cinfo->cur_comp_info[ci];
  146751. buffer[ci] = (*cinfo->mem->access_virt_barray)
  146752. ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  146753. coef->iMCU_row_num * compptr->v_samp_factor,
  146754. (JDIMENSION) compptr->v_samp_factor, FALSE);
  146755. }
  146756. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  146757. yoffset++) {
  146758. for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row;
  146759. MCU_col_num++) {
  146760. blkn = 0; /* index of current DCT block within MCU */
  146761. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  146762. compptr = cinfo->cur_comp_info[ci];
  146763. start_col = MCU_col_num * compptr->MCU_width;
  146764. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  146765. buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  146766. for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
  146767. coef->MCU_buffer[blkn++] = buffer_ptr++;
  146768. }
  146769. }
  146770. }
  146771. if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
  146772. coef->MCU_vert_offset = yoffset;
  146773. coef->mcu_ctr = MCU_col_num;
  146774. return FALSE;
  146775. }
  146776. }
  146777. coef->mcu_ctr = 0;
  146778. }
  146779. coef->iMCU_row_num++;
  146780. start_iMCU_row(cinfo);
  146781. return TRUE;
  146782. }
  146783. #endif /* FULL_COEF_BUFFER_SUPPORTED */
  146784. GLOBAL(void)
  146785. jinit_c_coef_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  146786. {
  146787. my_coef_ptr coef;
  146788. coef = (my_coef_ptr)
  146789. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146790. SIZEOF(my_coef_controller));
  146791. cinfo->coef = (struct jpeg_c_coef_controller *) coef;
  146792. coef->pub.start_pass = start_pass_coef;
  146793. if (need_full_buffer) {
  146794. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146795. int ci;
  146796. jpeg_component_info *compptr;
  146797. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  146798. ci++, compptr++) {
  146799. coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
  146800. ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  146801. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  146802. (long) compptr->h_samp_factor),
  146803. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  146804. (long) compptr->v_samp_factor),
  146805. (JDIMENSION) compptr->v_samp_factor);
  146806. }
  146807. #else
  146808. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146809. #endif
  146810. } else {
  146811. JBLOCKROW buffer;
  146812. int i;
  146813. buffer = (JBLOCKROW)
  146814. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146815. C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  146816. for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) {
  146817. coef->MCU_buffer[i] = buffer + i;
  146818. }
  146819. coef->whole_image[0] = NULL; /* flag for no virtual arrays */
  146820. }
  146821. }
  146822. /*** End of inlined file: jccoefct.c ***/
  146823. /*** Start of inlined file: jccolor.c ***/
  146824. #define JPEG_INTERNALS
  146825. typedef struct {
  146826. struct jpeg_color_converter pub; /* public fields */
  146827. INT32 * rgb_ycc_tab; /* => table for RGB to YCbCr conversion */
  146828. } my_color_converter;
  146829. typedef my_color_converter * my_cconvert_ptr;
  146830. #define SCALEBITS 16 /* speediest right-shift on some machines */
  146831. #define CBCR_OFFSET ((INT32) CENTERJSAMPLE << SCALEBITS)
  146832. #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
  146833. #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
  146834. #define R_Y_OFF 0 /* offset to R => Y section */
  146835. #define G_Y_OFF (1*(MAXJSAMPLE+1)) /* offset to G => Y section */
  146836. #define B_Y_OFF (2*(MAXJSAMPLE+1)) /* etc. */
  146837. #define R_CB_OFF (3*(MAXJSAMPLE+1))
  146838. #define G_CB_OFF (4*(MAXJSAMPLE+1))
  146839. #define B_CB_OFF (5*(MAXJSAMPLE+1))
  146840. #define R_CR_OFF B_CB_OFF /* B=>Cb, R=>Cr are the same */
  146841. #define G_CR_OFF (6*(MAXJSAMPLE+1))
  146842. #define B_CR_OFF (7*(MAXJSAMPLE+1))
  146843. #define TABLE_SIZE (8*(MAXJSAMPLE+1))
  146844. METHODDEF(void)
  146845. rgb_ycc_start (j_compress_ptr cinfo)
  146846. {
  146847. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146848. INT32 * rgb_ycc_tab;
  146849. INT32 i;
  146850. cconvert->rgb_ycc_tab = rgb_ycc_tab = (INT32 *)
  146851. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146852. (TABLE_SIZE * SIZEOF(INT32)));
  146853. for (i = 0; i <= MAXJSAMPLE; i++) {
  146854. rgb_ycc_tab[i+R_Y_OFF] = FIX(0.29900) * i;
  146855. rgb_ycc_tab[i+G_Y_OFF] = FIX(0.58700) * i;
  146856. rgb_ycc_tab[i+B_Y_OFF] = FIX(0.11400) * i + ONE_HALF;
  146857. rgb_ycc_tab[i+R_CB_OFF] = (-FIX(0.16874)) * i;
  146858. rgb_ycc_tab[i+G_CB_OFF] = (-FIX(0.33126)) * i;
  146859. rgb_ycc_tab[i+B_CB_OFF] = FIX(0.50000) * i + CBCR_OFFSET + ONE_HALF-1;
  146860. rgb_ycc_tab[i+G_CR_OFF] = (-FIX(0.41869)) * i;
  146861. rgb_ycc_tab[i+B_CR_OFF] = (-FIX(0.08131)) * i;
  146862. }
  146863. }
  146864. METHODDEF(void)
  146865. rgb_ycc_convert (j_compress_ptr cinfo,
  146866. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146867. JDIMENSION output_row, int num_rows)
  146868. {
  146869. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146870. register int r, g, b;
  146871. register INT32 * ctab = cconvert->rgb_ycc_tab;
  146872. register JSAMPROW inptr;
  146873. register JSAMPROW outptr0, outptr1, outptr2;
  146874. register JDIMENSION col;
  146875. JDIMENSION num_cols = cinfo->image_width;
  146876. while (--num_rows >= 0) {
  146877. inptr = *input_buf++;
  146878. outptr0 = output_buf[0][output_row];
  146879. outptr1 = output_buf[1][output_row];
  146880. outptr2 = output_buf[2][output_row];
  146881. output_row++;
  146882. for (col = 0; col < num_cols; col++) {
  146883. r = GETJSAMPLE(inptr[RGB_RED]);
  146884. g = GETJSAMPLE(inptr[RGB_GREEN]);
  146885. b = GETJSAMPLE(inptr[RGB_BLUE]);
  146886. inptr += RGB_PIXELSIZE;
  146887. outptr0[col] = (JSAMPLE)
  146888. ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  146889. >> SCALEBITS);
  146890. outptr1[col] = (JSAMPLE)
  146891. ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
  146892. >> SCALEBITS);
  146893. outptr2[col] = (JSAMPLE)
  146894. ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
  146895. >> SCALEBITS);
  146896. }
  146897. }
  146898. }
  146899. METHODDEF(void)
  146900. rgb_gray_convert (j_compress_ptr cinfo,
  146901. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146902. JDIMENSION output_row, int num_rows)
  146903. {
  146904. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146905. register int r, g, b;
  146906. register INT32 * ctab = cconvert->rgb_ycc_tab;
  146907. register JSAMPROW inptr;
  146908. register JSAMPROW outptr;
  146909. register JDIMENSION col;
  146910. JDIMENSION num_cols = cinfo->image_width;
  146911. while (--num_rows >= 0) {
  146912. inptr = *input_buf++;
  146913. outptr = output_buf[0][output_row];
  146914. output_row++;
  146915. for (col = 0; col < num_cols; col++) {
  146916. r = GETJSAMPLE(inptr[RGB_RED]);
  146917. g = GETJSAMPLE(inptr[RGB_GREEN]);
  146918. b = GETJSAMPLE(inptr[RGB_BLUE]);
  146919. inptr += RGB_PIXELSIZE;
  146920. outptr[col] = (JSAMPLE)
  146921. ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  146922. >> SCALEBITS);
  146923. }
  146924. }
  146925. }
  146926. METHODDEF(void)
  146927. cmyk_ycck_convert (j_compress_ptr cinfo,
  146928. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146929. JDIMENSION output_row, int num_rows)
  146930. {
  146931. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146932. register int r, g, b;
  146933. register INT32 * ctab = cconvert->rgb_ycc_tab;
  146934. register JSAMPROW inptr;
  146935. register JSAMPROW outptr0, outptr1, outptr2, outptr3;
  146936. register JDIMENSION col;
  146937. JDIMENSION num_cols = cinfo->image_width;
  146938. while (--num_rows >= 0) {
  146939. inptr = *input_buf++;
  146940. outptr0 = output_buf[0][output_row];
  146941. outptr1 = output_buf[1][output_row];
  146942. outptr2 = output_buf[2][output_row];
  146943. outptr3 = output_buf[3][output_row];
  146944. output_row++;
  146945. for (col = 0; col < num_cols; col++) {
  146946. r = MAXJSAMPLE - GETJSAMPLE(inptr[0]);
  146947. g = MAXJSAMPLE - GETJSAMPLE(inptr[1]);
  146948. b = MAXJSAMPLE - GETJSAMPLE(inptr[2]);
  146949. outptr3[col] = inptr[3]; /* don't need GETJSAMPLE here */
  146950. inptr += 4;
  146951. outptr0[col] = (JSAMPLE)
  146952. ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  146953. >> SCALEBITS);
  146954. outptr1[col] = (JSAMPLE)
  146955. ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
  146956. >> SCALEBITS);
  146957. outptr2[col] = (JSAMPLE)
  146958. ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
  146959. >> SCALEBITS);
  146960. }
  146961. }
  146962. }
  146963. METHODDEF(void)
  146964. grayscale_convert (j_compress_ptr cinfo,
  146965. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146966. JDIMENSION output_row, int num_rows)
  146967. {
  146968. register JSAMPROW inptr;
  146969. register JSAMPROW outptr;
  146970. register JDIMENSION col;
  146971. JDIMENSION num_cols = cinfo->image_width;
  146972. int instride = cinfo->input_components;
  146973. while (--num_rows >= 0) {
  146974. inptr = *input_buf++;
  146975. outptr = output_buf[0][output_row];
  146976. output_row++;
  146977. for (col = 0; col < num_cols; col++) {
  146978. outptr[col] = inptr[0]; /* don't need GETJSAMPLE() here */
  146979. inptr += instride;
  146980. }
  146981. }
  146982. }
  146983. METHODDEF(void)
  146984. null_convert (j_compress_ptr cinfo,
  146985. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146986. JDIMENSION output_row, int num_rows)
  146987. {
  146988. register JSAMPROW inptr;
  146989. register JSAMPROW outptr;
  146990. register JDIMENSION col;
  146991. register int ci;
  146992. int nc = cinfo->num_components;
  146993. JDIMENSION num_cols = cinfo->image_width;
  146994. while (--num_rows >= 0) {
  146995. for (ci = 0; ci < nc; ci++) {
  146996. inptr = *input_buf;
  146997. outptr = output_buf[ci][output_row];
  146998. for (col = 0; col < num_cols; col++) {
  146999. outptr[col] = inptr[ci]; /* don't need GETJSAMPLE() here */
  147000. inptr += nc;
  147001. }
  147002. }
  147003. input_buf++;
  147004. output_row++;
  147005. }
  147006. }
  147007. METHODDEF(void)
  147008. null_method (j_compress_ptr cinfo)
  147009. {
  147010. }
  147011. GLOBAL(void)
  147012. jinit_color_converter (j_compress_ptr cinfo)
  147013. {
  147014. my_cconvert_ptr cconvert;
  147015. cconvert = (my_cconvert_ptr)
  147016. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147017. SIZEOF(my_color_converter));
  147018. cinfo->cconvert = (struct jpeg_color_converter *) cconvert;
  147019. cconvert->pub.start_pass = null_method;
  147020. switch (cinfo->in_color_space) {
  147021. case JCS_GRAYSCALE:
  147022. if (cinfo->input_components != 1)
  147023. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  147024. break;
  147025. case JCS_RGB:
  147026. #if RGB_PIXELSIZE != 3
  147027. if (cinfo->input_components != RGB_PIXELSIZE)
  147028. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  147029. break;
  147030. #endif /* else share code with YCbCr */
  147031. case JCS_YCbCr:
  147032. if (cinfo->input_components != 3)
  147033. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  147034. break;
  147035. case JCS_CMYK:
  147036. case JCS_YCCK:
  147037. if (cinfo->input_components != 4)
  147038. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  147039. break;
  147040. default: /* JCS_UNKNOWN can be anything */
  147041. if (cinfo->input_components < 1)
  147042. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  147043. break;
  147044. }
  147045. switch (cinfo->jpeg_color_space) {
  147046. case JCS_GRAYSCALE:
  147047. if (cinfo->num_components != 1)
  147048. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  147049. if (cinfo->in_color_space == JCS_GRAYSCALE)
  147050. cconvert->pub.color_convert = grayscale_convert;
  147051. else if (cinfo->in_color_space == JCS_RGB) {
  147052. cconvert->pub.start_pass = rgb_ycc_start;
  147053. cconvert->pub.color_convert = rgb_gray_convert;
  147054. } else if (cinfo->in_color_space == JCS_YCbCr)
  147055. cconvert->pub.color_convert = grayscale_convert;
  147056. else
  147057. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  147058. break;
  147059. case JCS_RGB:
  147060. if (cinfo->num_components != 3)
  147061. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  147062. if (cinfo->in_color_space == JCS_RGB && RGB_PIXELSIZE == 3)
  147063. cconvert->pub.color_convert = null_convert;
  147064. else
  147065. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  147066. break;
  147067. case JCS_YCbCr:
  147068. if (cinfo->num_components != 3)
  147069. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  147070. if (cinfo->in_color_space == JCS_RGB) {
  147071. cconvert->pub.start_pass = rgb_ycc_start;
  147072. cconvert->pub.color_convert = rgb_ycc_convert;
  147073. } else if (cinfo->in_color_space == JCS_YCbCr)
  147074. cconvert->pub.color_convert = null_convert;
  147075. else
  147076. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  147077. break;
  147078. case JCS_CMYK:
  147079. if (cinfo->num_components != 4)
  147080. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  147081. if (cinfo->in_color_space == JCS_CMYK)
  147082. cconvert->pub.color_convert = null_convert;
  147083. else
  147084. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  147085. break;
  147086. case JCS_YCCK:
  147087. if (cinfo->num_components != 4)
  147088. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  147089. if (cinfo->in_color_space == JCS_CMYK) {
  147090. cconvert->pub.start_pass = rgb_ycc_start;
  147091. cconvert->pub.color_convert = cmyk_ycck_convert;
  147092. } else if (cinfo->in_color_space == JCS_YCCK)
  147093. cconvert->pub.color_convert = null_convert;
  147094. else
  147095. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  147096. break;
  147097. default: /* allow null conversion of JCS_UNKNOWN */
  147098. if (cinfo->jpeg_color_space != cinfo->in_color_space ||
  147099. cinfo->num_components != cinfo->input_components)
  147100. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  147101. cconvert->pub.color_convert = null_convert;
  147102. break;
  147103. }
  147104. }
  147105. /*** End of inlined file: jccolor.c ***/
  147106. #undef FIX
  147107. /*** Start of inlined file: jcdctmgr.c ***/
  147108. #define JPEG_INTERNALS
  147109. /*** Start of inlined file: jdct.h ***/
  147110. #ifndef __jdct_h__
  147111. #define __jdct_h__
  147112. #if BITS_IN_JSAMPLE == 8
  147113. typedef int DCTELEM; /* 16 or 32 bits is fine */
  147114. #else
  147115. typedef INT32 DCTELEM; /* must have 32 bits */
  147116. #endif
  147117. typedef JMETHOD(void, forward_DCT_method_ptr, (DCTELEM * data));
  147118. typedef JMETHOD(void, float_DCT_method_ptr, (FAST_FLOAT * data));
  147119. typedef MULTIPLIER ISLOW_MULT_TYPE; /* short or int, whichever is faster */
  147120. #if BITS_IN_JSAMPLE == 8
  147121. typedef MULTIPLIER IFAST_MULT_TYPE; /* 16 bits is OK, use short if faster */
  147122. #define IFAST_SCALE_BITS 2 /* fractional bits in scale factors */
  147123. #else
  147124. typedef INT32 IFAST_MULT_TYPE; /* need 32 bits for scaled quantizers */
  147125. #define IFAST_SCALE_BITS 13 /* fractional bits in scale factors */
  147126. #endif
  147127. typedef FAST_FLOAT FLOAT_MULT_TYPE; /* preferred floating type */
  147128. #define IDCT_range_limit(cinfo) ((cinfo)->sample_range_limit + CENTERJSAMPLE)
  147129. #define RANGE_MASK (MAXJSAMPLE * 4 + 3) /* 2 bits wider than legal samples */
  147130. #ifdef NEED_SHORT_EXTERNAL_NAMES
  147131. #define jpeg_fdct_islow jFDislow
  147132. #define jpeg_fdct_ifast jFDifast
  147133. #define jpeg_fdct_float jFDfloat
  147134. #define jpeg_idct_islow jRDislow
  147135. #define jpeg_idct_ifast jRDifast
  147136. #define jpeg_idct_float jRDfloat
  147137. #define jpeg_idct_4x4 jRD4x4
  147138. #define jpeg_idct_2x2 jRD2x2
  147139. #define jpeg_idct_1x1 jRD1x1
  147140. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  147141. EXTERN(void) jpeg_fdct_islow JPP((DCTELEM * data));
  147142. EXTERN(void) jpeg_fdct_ifast JPP((DCTELEM * data));
  147143. EXTERN(void) jpeg_fdct_float JPP((FAST_FLOAT * data));
  147144. EXTERN(void) jpeg_idct_islow
  147145. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  147146. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  147147. EXTERN(void) jpeg_idct_ifast
  147148. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  147149. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  147150. EXTERN(void) jpeg_idct_float
  147151. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  147152. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  147153. EXTERN(void) jpeg_idct_4x4
  147154. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  147155. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  147156. EXTERN(void) jpeg_idct_2x2
  147157. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  147158. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  147159. EXTERN(void) jpeg_idct_1x1
  147160. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  147161. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  147162. #define ONE ((INT32) 1)
  147163. #define CONST_SCALE (ONE << CONST_BITS)
  147164. #define FIX(x) ((INT32) ((x) * CONST_SCALE + 0.5))
  147165. #define DESCALE(x,n) RIGHT_SHIFT((x) + (ONE << ((n)-1)), n)
  147166. #ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */
  147167. #define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT16) (const)))
  147168. #endif
  147169. #ifdef SHORTxLCONST_32 /* known to work with Microsoft C 6.0 */
  147170. #define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT32) (const)))
  147171. #endif
  147172. #ifndef MULTIPLY16C16 /* default definition */
  147173. #define MULTIPLY16C16(var,const) ((var) * (const))
  147174. #endif
  147175. #ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */
  147176. #define MULTIPLY16V16(var1,var2) (((INT16) (var1)) * ((INT16) (var2)))
  147177. #endif
  147178. #ifndef MULTIPLY16V16 /* default definition */
  147179. #define MULTIPLY16V16(var1,var2) ((var1) * (var2))
  147180. #endif
  147181. #endif
  147182. /*** End of inlined file: jdct.h ***/
  147183. /* Private declarations for DCT subsystem */
  147184. typedef struct {
  147185. struct jpeg_forward_dct pub; /* public fields */
  147186. forward_DCT_method_ptr do_dct;
  147187. DCTELEM * divisors[NUM_QUANT_TBLS];
  147188. #ifdef DCT_FLOAT_SUPPORTED
  147189. float_DCT_method_ptr do_float_dct;
  147190. FAST_FLOAT * float_divisors[NUM_QUANT_TBLS];
  147191. #endif
  147192. } my_fdct_controller;
  147193. typedef my_fdct_controller * my_fdct_ptr;
  147194. METHODDEF(void)
  147195. start_pass_fdctmgr (j_compress_ptr cinfo)
  147196. {
  147197. my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  147198. int ci, qtblno, i;
  147199. jpeg_component_info *compptr;
  147200. JQUANT_TBL * qtbl;
  147201. DCTELEM * dtbl;
  147202. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147203. ci++, compptr++) {
  147204. qtblno = compptr->quant_tbl_no;
  147205. if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
  147206. cinfo->quant_tbl_ptrs[qtblno] == NULL)
  147207. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
  147208. qtbl = cinfo->quant_tbl_ptrs[qtblno];
  147209. switch (cinfo->dct_method) {
  147210. #ifdef DCT_ISLOW_SUPPORTED
  147211. case JDCT_ISLOW:
  147212. if (fdct->divisors[qtblno] == NULL) {
  147213. fdct->divisors[qtblno] = (DCTELEM *)
  147214. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147215. DCTSIZE2 * SIZEOF(DCTELEM));
  147216. }
  147217. dtbl = fdct->divisors[qtblno];
  147218. for (i = 0; i < DCTSIZE2; i++) {
  147219. dtbl[i] = ((DCTELEM) qtbl->quantval[i]) << 3;
  147220. }
  147221. break;
  147222. #endif
  147223. #ifdef DCT_IFAST_SUPPORTED
  147224. case JDCT_IFAST:
  147225. {
  147226. #define CONST_BITS 14
  147227. static const INT16 aanscales[DCTSIZE2] = {
  147228. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  147229. 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
  147230. 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
  147231. 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
  147232. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  147233. 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
  147234. 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
  147235. 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
  147236. };
  147237. SHIFT_TEMPS
  147238. if (fdct->divisors[qtblno] == NULL) {
  147239. fdct->divisors[qtblno] = (DCTELEM *)
  147240. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147241. DCTSIZE2 * SIZEOF(DCTELEM));
  147242. }
  147243. dtbl = fdct->divisors[qtblno];
  147244. for (i = 0; i < DCTSIZE2; i++) {
  147245. dtbl[i] = (DCTELEM)
  147246. DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
  147247. (INT32) aanscales[i]),
  147248. CONST_BITS-3);
  147249. }
  147250. }
  147251. break;
  147252. #endif
  147253. #ifdef DCT_FLOAT_SUPPORTED
  147254. case JDCT_FLOAT:
  147255. {
  147256. FAST_FLOAT * fdtbl;
  147257. int row, col;
  147258. static const double aanscalefactor[DCTSIZE] = {
  147259. 1.0, 1.387039845, 1.306562965, 1.175875602,
  147260. 1.0, 0.785694958, 0.541196100, 0.275899379
  147261. };
  147262. if (fdct->float_divisors[qtblno] == NULL) {
  147263. fdct->float_divisors[qtblno] = (FAST_FLOAT *)
  147264. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147265. DCTSIZE2 * SIZEOF(FAST_FLOAT));
  147266. }
  147267. fdtbl = fdct->float_divisors[qtblno];
  147268. i = 0;
  147269. for (row = 0; row < DCTSIZE; row++) {
  147270. for (col = 0; col < DCTSIZE; col++) {
  147271. fdtbl[i] = (FAST_FLOAT)
  147272. (1.0 / (((double) qtbl->quantval[i] *
  147273. aanscalefactor[row] * aanscalefactor[col] * 8.0)));
  147274. i++;
  147275. }
  147276. }
  147277. }
  147278. break;
  147279. #endif
  147280. default:
  147281. ERREXIT(cinfo, JERR_NOT_COMPILED);
  147282. break;
  147283. }
  147284. }
  147285. }
  147286. METHODDEF(void)
  147287. forward_DCT (j_compress_ptr cinfo, jpeg_component_info * compptr,
  147288. JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  147289. JDIMENSION start_row, JDIMENSION start_col,
  147290. JDIMENSION num_blocks)
  147291. {
  147292. my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  147293. forward_DCT_method_ptr do_dct = fdct->do_dct;
  147294. DCTELEM * divisors = fdct->divisors[compptr->quant_tbl_no];
  147295. DCTELEM workspace[DCTSIZE2]; /* work area for FDCT subroutine */
  147296. JDIMENSION bi;
  147297. sample_data += start_row; /* fold in the vertical offset once */
  147298. for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
  147299. { register DCTELEM *workspaceptr;
  147300. register JSAMPROW elemptr;
  147301. register int elemr;
  147302. workspaceptr = workspace;
  147303. for (elemr = 0; elemr < DCTSIZE; elemr++) {
  147304. elemptr = sample_data[elemr] + start_col;
  147305. #if DCTSIZE == 8 /* unroll the inner loop */
  147306. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147307. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147308. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147309. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147310. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147311. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147312. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147313. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147314. #else
  147315. { register int elemc;
  147316. for (elemc = DCTSIZE; elemc > 0; elemc--) {
  147317. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147318. }
  147319. }
  147320. #endif
  147321. }
  147322. }
  147323. (*do_dct) (workspace);
  147324. { register DCTELEM temp, qval;
  147325. register int i;
  147326. register JCOEFPTR output_ptr = coef_blocks[bi];
  147327. for (i = 0; i < DCTSIZE2; i++) {
  147328. qval = divisors[i];
  147329. temp = workspace[i];
  147330. #ifdef FAST_DIVIDE
  147331. #define DIVIDE_BY(a,b) a /= b
  147332. #else
  147333. #define DIVIDE_BY(a,b) if (a >= b) a /= b; else a = 0
  147334. #endif
  147335. if (temp < 0) {
  147336. temp = -temp;
  147337. temp += qval>>1; /* for rounding */
  147338. DIVIDE_BY(temp, qval);
  147339. temp = -temp;
  147340. } else {
  147341. temp += qval>>1; /* for rounding */
  147342. DIVIDE_BY(temp, qval);
  147343. }
  147344. output_ptr[i] = (JCOEF) temp;
  147345. }
  147346. }
  147347. }
  147348. }
  147349. #ifdef DCT_FLOAT_SUPPORTED
  147350. METHODDEF(void)
  147351. forward_DCT_float (j_compress_ptr cinfo, jpeg_component_info * compptr,
  147352. JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  147353. JDIMENSION start_row, JDIMENSION start_col,
  147354. JDIMENSION num_blocks)
  147355. {
  147356. my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  147357. float_DCT_method_ptr do_dct = fdct->do_float_dct;
  147358. FAST_FLOAT * divisors = fdct->float_divisors[compptr->quant_tbl_no];
  147359. FAST_FLOAT workspace[DCTSIZE2]; /* work area for FDCT subroutine */
  147360. JDIMENSION bi;
  147361. sample_data += start_row; /* fold in the vertical offset once */
  147362. for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
  147363. { register FAST_FLOAT *workspaceptr;
  147364. register JSAMPROW elemptr;
  147365. register int elemr;
  147366. workspaceptr = workspace;
  147367. for (elemr = 0; elemr < DCTSIZE; elemr++) {
  147368. elemptr = sample_data[elemr] + start_col;
  147369. #if DCTSIZE == 8 /* unroll the inner loop */
  147370. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147371. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147372. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147373. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147374. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147375. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147376. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147377. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147378. #else
  147379. { register int elemc;
  147380. for (elemc = DCTSIZE; elemc > 0; elemc--) {
  147381. *workspaceptr++ = (FAST_FLOAT)
  147382. (GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147383. }
  147384. }
  147385. #endif
  147386. }
  147387. }
  147388. (*do_dct) (workspace);
  147389. { register FAST_FLOAT temp;
  147390. register int i;
  147391. register JCOEFPTR output_ptr = coef_blocks[bi];
  147392. for (i = 0; i < DCTSIZE2; i++) {
  147393. temp = workspace[i] * divisors[i];
  147394. output_ptr[i] = (JCOEF) ((int) (temp + (FAST_FLOAT) 16384.5) - 16384);
  147395. }
  147396. }
  147397. }
  147398. }
  147399. #endif /* DCT_FLOAT_SUPPORTED */
  147400. GLOBAL(void)
  147401. jinit_forward_dct (j_compress_ptr cinfo)
  147402. {
  147403. my_fdct_ptr fdct;
  147404. int i;
  147405. fdct = (my_fdct_ptr)
  147406. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147407. SIZEOF(my_fdct_controller));
  147408. cinfo->fdct = (struct jpeg_forward_dct *) fdct;
  147409. fdct->pub.start_pass = start_pass_fdctmgr;
  147410. switch (cinfo->dct_method) {
  147411. #ifdef DCT_ISLOW_SUPPORTED
  147412. case JDCT_ISLOW:
  147413. fdct->pub.forward_DCT = forward_DCT;
  147414. fdct->do_dct = jpeg_fdct_islow;
  147415. break;
  147416. #endif
  147417. #ifdef DCT_IFAST_SUPPORTED
  147418. case JDCT_IFAST:
  147419. fdct->pub.forward_DCT = forward_DCT;
  147420. fdct->do_dct = jpeg_fdct_ifast;
  147421. break;
  147422. #endif
  147423. #ifdef DCT_FLOAT_SUPPORTED
  147424. case JDCT_FLOAT:
  147425. fdct->pub.forward_DCT = forward_DCT_float;
  147426. fdct->do_float_dct = jpeg_fdct_float;
  147427. break;
  147428. #endif
  147429. default:
  147430. ERREXIT(cinfo, JERR_NOT_COMPILED);
  147431. break;
  147432. }
  147433. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  147434. fdct->divisors[i] = NULL;
  147435. #ifdef DCT_FLOAT_SUPPORTED
  147436. fdct->float_divisors[i] = NULL;
  147437. #endif
  147438. }
  147439. }
  147440. /*** End of inlined file: jcdctmgr.c ***/
  147441. #undef CONST_BITS
  147442. /*** Start of inlined file: jchuff.c ***/
  147443. #define JPEG_INTERNALS
  147444. /*** Start of inlined file: jchuff.h ***/
  147445. #ifndef _jchuff_h_
  147446. #define _jchuff_h_
  147447. #if BITS_IN_JSAMPLE == 8
  147448. #define MAX_COEF_BITS 10
  147449. #else
  147450. #define MAX_COEF_BITS 14
  147451. #endif
  147452. typedef struct {
  147453. unsigned int ehufco[256]; /* code for each symbol */
  147454. char ehufsi[256]; /* length of code for each symbol */
  147455. } c_derived_tbl;
  147456. #ifdef NEED_SHORT_EXTERNAL_NAMES
  147457. #define jpeg_make_c_derived_tbl jMkCDerived
  147458. #define jpeg_gen_optimal_table jGenOptTbl
  147459. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  147460. EXTERN(void) jpeg_make_c_derived_tbl
  147461. JPP((j_compress_ptr cinfo, boolean isDC, int tblno,
  147462. c_derived_tbl ** pdtbl));
  147463. EXTERN(void) jpeg_gen_optimal_table
  147464. JPP((j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[]));
  147465. #endif
  147466. /*** End of inlined file: jchuff.h ***/
  147467. /* Declarations shared with jcphuff.c */
  147468. typedef struct {
  147469. INT32 put_buffer; /* current bit-accumulation buffer */
  147470. int put_bits; /* # of bits now in it */
  147471. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  147472. } savable_state;
  147473. #ifndef NO_STRUCT_ASSIGN
  147474. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  147475. #else
  147476. #if MAX_COMPS_IN_SCAN == 4
  147477. #define ASSIGN_STATE(dest,src) \
  147478. ((dest).put_buffer = (src).put_buffer, \
  147479. (dest).put_bits = (src).put_bits, \
  147480. (dest).last_dc_val[0] = (src).last_dc_val[0], \
  147481. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  147482. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  147483. (dest).last_dc_val[3] = (src).last_dc_val[3])
  147484. #endif
  147485. #endif
  147486. typedef struct {
  147487. struct jpeg_entropy_encoder pub; /* public fields */
  147488. savable_state saved; /* Bit buffer & DC state at start of MCU */
  147489. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  147490. int next_restart_num; /* next restart number to write (0-7) */
  147491. c_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS];
  147492. c_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS];
  147493. #ifdef ENTROPY_OPT_SUPPORTED /* Statistics tables for optimization */
  147494. long * dc_count_ptrs[NUM_HUFF_TBLS];
  147495. long * ac_count_ptrs[NUM_HUFF_TBLS];
  147496. #endif
  147497. } huff_entropy_encoder;
  147498. typedef huff_entropy_encoder * huff_entropy_ptr;
  147499. typedef struct {
  147500. JOCTET * next_output_byte; /* => next byte to write in buffer */
  147501. size_t free_in_buffer; /* # of byte spaces remaining in buffer */
  147502. savable_state cur; /* Current bit buffer & DC state */
  147503. j_compress_ptr cinfo; /* dump_buffer needs access to this */
  147504. } working_state;
  147505. METHODDEF(boolean) encode_mcu_huff JPP((j_compress_ptr cinfo,
  147506. JBLOCKROW *MCU_data));
  147507. METHODDEF(void) finish_pass_huff JPP((j_compress_ptr cinfo));
  147508. #ifdef ENTROPY_OPT_SUPPORTED
  147509. METHODDEF(boolean) encode_mcu_gather JPP((j_compress_ptr cinfo,
  147510. JBLOCKROW *MCU_data));
  147511. METHODDEF(void) finish_pass_gather JPP((j_compress_ptr cinfo));
  147512. #endif
  147513. METHODDEF(void)
  147514. start_pass_huff (j_compress_ptr cinfo, boolean gather_statistics)
  147515. {
  147516. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147517. int ci, dctbl, actbl;
  147518. jpeg_component_info * compptr;
  147519. if (gather_statistics) {
  147520. #ifdef ENTROPY_OPT_SUPPORTED
  147521. entropy->pub.encode_mcu = encode_mcu_gather;
  147522. entropy->pub.finish_pass = finish_pass_gather;
  147523. #else
  147524. ERREXIT(cinfo, JERR_NOT_COMPILED);
  147525. #endif
  147526. } else {
  147527. entropy->pub.encode_mcu = encode_mcu_huff;
  147528. entropy->pub.finish_pass = finish_pass_huff;
  147529. }
  147530. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  147531. compptr = cinfo->cur_comp_info[ci];
  147532. dctbl = compptr->dc_tbl_no;
  147533. actbl = compptr->ac_tbl_no;
  147534. if (gather_statistics) {
  147535. #ifdef ENTROPY_OPT_SUPPORTED
  147536. if (dctbl < 0 || dctbl >= NUM_HUFF_TBLS)
  147537. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, dctbl);
  147538. if (actbl < 0 || actbl >= NUM_HUFF_TBLS)
  147539. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, actbl);
  147540. if (entropy->dc_count_ptrs[dctbl] == NULL)
  147541. entropy->dc_count_ptrs[dctbl] = (long *)
  147542. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147543. 257 * SIZEOF(long));
  147544. MEMZERO(entropy->dc_count_ptrs[dctbl], 257 * SIZEOF(long));
  147545. if (entropy->ac_count_ptrs[actbl] == NULL)
  147546. entropy->ac_count_ptrs[actbl] = (long *)
  147547. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147548. 257 * SIZEOF(long));
  147549. MEMZERO(entropy->ac_count_ptrs[actbl], 257 * SIZEOF(long));
  147550. #endif
  147551. } else {
  147552. jpeg_make_c_derived_tbl(cinfo, TRUE, dctbl,
  147553. & entropy->dc_derived_tbls[dctbl]);
  147554. jpeg_make_c_derived_tbl(cinfo, FALSE, actbl,
  147555. & entropy->ac_derived_tbls[actbl]);
  147556. }
  147557. entropy->saved.last_dc_val[ci] = 0;
  147558. }
  147559. entropy->saved.put_buffer = 0;
  147560. entropy->saved.put_bits = 0;
  147561. entropy->restarts_to_go = cinfo->restart_interval;
  147562. entropy->next_restart_num = 0;
  147563. }
  147564. GLOBAL(void)
  147565. jpeg_make_c_derived_tbl (j_compress_ptr cinfo, boolean isDC, int tblno,
  147566. c_derived_tbl ** pdtbl)
  147567. {
  147568. JHUFF_TBL *htbl;
  147569. c_derived_tbl *dtbl;
  147570. int p, i, l, lastp, si, maxsymbol;
  147571. char huffsize[257];
  147572. unsigned int huffcode[257];
  147573. unsigned int code;
  147574. if (tblno < 0 || tblno >= NUM_HUFF_TBLS)
  147575. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  147576. htbl =
  147577. isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];
  147578. if (htbl == NULL)
  147579. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  147580. if (*pdtbl == NULL)
  147581. *pdtbl = (c_derived_tbl *)
  147582. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147583. SIZEOF(c_derived_tbl));
  147584. dtbl = *pdtbl;
  147585. p = 0;
  147586. for (l = 1; l <= 16; l++) {
  147587. i = (int) htbl->bits[l];
  147588. if (i < 0 || p + i > 256) /* protect against table overrun */
  147589. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  147590. while (i--)
  147591. huffsize[p++] = (char) l;
  147592. }
  147593. huffsize[p] = 0;
  147594. lastp = p;
  147595. code = 0;
  147596. si = huffsize[0];
  147597. p = 0;
  147598. while (huffsize[p]) {
  147599. while (((int) huffsize[p]) == si) {
  147600. huffcode[p++] = code;
  147601. code++;
  147602. }
  147603. if (((INT32) code) >= (((INT32) 1) << si))
  147604. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  147605. code <<= 1;
  147606. si++;
  147607. }
  147608. MEMZERO(dtbl->ehufsi, SIZEOF(dtbl->ehufsi));
  147609. maxsymbol = isDC ? 15 : 255;
  147610. for (p = 0; p < lastp; p++) {
  147611. i = htbl->huffval[p];
  147612. if (i < 0 || i > maxsymbol || dtbl->ehufsi[i])
  147613. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  147614. dtbl->ehufco[i] = huffcode[p];
  147615. dtbl->ehufsi[i] = huffsize[p];
  147616. }
  147617. }
  147618. #define emit_byte(state,val,action) \
  147619. { *(state)->next_output_byte++ = (JOCTET) (val); \
  147620. if (--(state)->free_in_buffer == 0) \
  147621. if (! dump_buffer(state)) \
  147622. { action; } }
  147623. LOCAL(boolean)
  147624. dump_buffer (working_state * state)
  147625. {
  147626. struct jpeg_destination_mgr * dest = state->cinfo->dest;
  147627. if (! (*dest->empty_output_buffer) (state->cinfo))
  147628. return FALSE;
  147629. state->next_output_byte = dest->next_output_byte;
  147630. state->free_in_buffer = dest->free_in_buffer;
  147631. return TRUE;
  147632. }
  147633. INLINE
  147634. LOCAL(boolean)
  147635. emit_bits (working_state * state, unsigned int code, int size)
  147636. {
  147637. register INT32 put_buffer = (INT32) code;
  147638. register int put_bits = state->cur.put_bits;
  147639. if (size == 0)
  147640. ERREXIT(state->cinfo, JERR_HUFF_MISSING_CODE);
  147641. put_buffer &= (((INT32) 1)<<size) - 1; /* mask off any extra bits in code */
  147642. put_bits += size; /* new number of bits in buffer */
  147643. put_buffer <<= 24 - put_bits; /* align incoming bits */
  147644. put_buffer |= state->cur.put_buffer; /* and merge with old buffer contents */
  147645. while (put_bits >= 8) {
  147646. int c = (int) ((put_buffer >> 16) & 0xFF);
  147647. emit_byte(state, c, return FALSE);
  147648. if (c == 0xFF) { /* need to stuff a zero byte? */
  147649. emit_byte(state, 0, return FALSE);
  147650. }
  147651. put_buffer <<= 8;
  147652. put_bits -= 8;
  147653. }
  147654. state->cur.put_buffer = put_buffer; /* update state variables */
  147655. state->cur.put_bits = put_bits;
  147656. return TRUE;
  147657. }
  147658. LOCAL(boolean)
  147659. flush_bits (working_state * state)
  147660. {
  147661. if (! emit_bits(state, 0x7F, 7)) /* fill any partial byte with ones */
  147662. return FALSE;
  147663. state->cur.put_buffer = 0; /* and reset bit-buffer to empty */
  147664. state->cur.put_bits = 0;
  147665. return TRUE;
  147666. }
  147667. LOCAL(boolean)
  147668. encode_one_block (working_state * state, JCOEFPTR block, int last_dc_val,
  147669. c_derived_tbl *dctbl, c_derived_tbl *actbl)
  147670. {
  147671. register int temp, temp2;
  147672. register int nbits;
  147673. register int k, r, i;
  147674. temp = temp2 = block[0] - last_dc_val;
  147675. if (temp < 0) {
  147676. temp = -temp; /* temp is abs value of input */
  147677. temp2--;
  147678. }
  147679. nbits = 0;
  147680. while (temp) {
  147681. nbits++;
  147682. temp >>= 1;
  147683. }
  147684. if (nbits > MAX_COEF_BITS+1)
  147685. ERREXIT(state->cinfo, JERR_BAD_DCT_COEF);
  147686. if (! emit_bits(state, dctbl->ehufco[nbits], dctbl->ehufsi[nbits]))
  147687. return FALSE;
  147688. if (nbits) /* emit_bits rejects calls with size 0 */
  147689. if (! emit_bits(state, (unsigned int) temp2, nbits))
  147690. return FALSE;
  147691. r = 0; /* r = run length of zeros */
  147692. for (k = 1; k < DCTSIZE2; k++) {
  147693. if ((temp = block[jpeg_natural_order[k]]) == 0) {
  147694. r++;
  147695. } else {
  147696. while (r > 15) {
  147697. if (! emit_bits(state, actbl->ehufco[0xF0], actbl->ehufsi[0xF0]))
  147698. return FALSE;
  147699. r -= 16;
  147700. }
  147701. temp2 = temp;
  147702. if (temp < 0) {
  147703. temp = -temp; /* temp is abs value of input */
  147704. temp2--;
  147705. }
  147706. nbits = 1; /* there must be at least one 1 bit */
  147707. while ((temp >>= 1))
  147708. nbits++;
  147709. if (nbits > MAX_COEF_BITS)
  147710. ERREXIT(state->cinfo, JERR_BAD_DCT_COEF);
  147711. i = (r << 4) + nbits;
  147712. if (! emit_bits(state, actbl->ehufco[i], actbl->ehufsi[i]))
  147713. return FALSE;
  147714. if (! emit_bits(state, (unsigned int) temp2, nbits))
  147715. return FALSE;
  147716. r = 0;
  147717. }
  147718. }
  147719. if (r > 0)
  147720. if (! emit_bits(state, actbl->ehufco[0], actbl->ehufsi[0]))
  147721. return FALSE;
  147722. return TRUE;
  147723. }
  147724. LOCAL(boolean)
  147725. emit_restart (working_state * state, int restart_num)
  147726. {
  147727. int ci;
  147728. if (! flush_bits(state))
  147729. return FALSE;
  147730. emit_byte(state, 0xFF, return FALSE);
  147731. emit_byte(state, JPEG_RST0 + restart_num, return FALSE);
  147732. for (ci = 0; ci < state->cinfo->comps_in_scan; ci++)
  147733. state->cur.last_dc_val[ci] = 0;
  147734. return TRUE;
  147735. }
  147736. METHODDEF(boolean)
  147737. encode_mcu_huff (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  147738. {
  147739. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147740. working_state state;
  147741. int blkn, ci;
  147742. jpeg_component_info * compptr;
  147743. state.next_output_byte = cinfo->dest->next_output_byte;
  147744. state.free_in_buffer = cinfo->dest->free_in_buffer;
  147745. ASSIGN_STATE(state.cur, entropy->saved);
  147746. state.cinfo = cinfo;
  147747. if (cinfo->restart_interval) {
  147748. if (entropy->restarts_to_go == 0)
  147749. if (! emit_restart(&state, entropy->next_restart_num))
  147750. return FALSE;
  147751. }
  147752. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  147753. ci = cinfo->MCU_membership[blkn];
  147754. compptr = cinfo->cur_comp_info[ci];
  147755. if (! encode_one_block(&state,
  147756. MCU_data[blkn][0], state.cur.last_dc_val[ci],
  147757. entropy->dc_derived_tbls[compptr->dc_tbl_no],
  147758. entropy->ac_derived_tbls[compptr->ac_tbl_no]))
  147759. return FALSE;
  147760. state.cur.last_dc_val[ci] = MCU_data[blkn][0][0];
  147761. }
  147762. cinfo->dest->next_output_byte = state.next_output_byte;
  147763. cinfo->dest->free_in_buffer = state.free_in_buffer;
  147764. ASSIGN_STATE(entropy->saved, state.cur);
  147765. if (cinfo->restart_interval) {
  147766. if (entropy->restarts_to_go == 0) {
  147767. entropy->restarts_to_go = cinfo->restart_interval;
  147768. entropy->next_restart_num++;
  147769. entropy->next_restart_num &= 7;
  147770. }
  147771. entropy->restarts_to_go--;
  147772. }
  147773. return TRUE;
  147774. }
  147775. METHODDEF(void)
  147776. finish_pass_huff (j_compress_ptr cinfo)
  147777. {
  147778. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147779. working_state state;
  147780. state.next_output_byte = cinfo->dest->next_output_byte;
  147781. state.free_in_buffer = cinfo->dest->free_in_buffer;
  147782. ASSIGN_STATE(state.cur, entropy->saved);
  147783. state.cinfo = cinfo;
  147784. if (! flush_bits(&state))
  147785. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  147786. cinfo->dest->next_output_byte = state.next_output_byte;
  147787. cinfo->dest->free_in_buffer = state.free_in_buffer;
  147788. ASSIGN_STATE(entropy->saved, state.cur);
  147789. }
  147790. #ifdef ENTROPY_OPT_SUPPORTED
  147791. LOCAL(void)
  147792. htest_one_block (j_compress_ptr cinfo, JCOEFPTR block, int last_dc_val,
  147793. long dc_counts[], long ac_counts[])
  147794. {
  147795. register int temp;
  147796. register int nbits;
  147797. register int k, r;
  147798. temp = block[0] - last_dc_val;
  147799. if (temp < 0)
  147800. temp = -temp;
  147801. nbits = 0;
  147802. while (temp) {
  147803. nbits++;
  147804. temp >>= 1;
  147805. }
  147806. if (nbits > MAX_COEF_BITS+1)
  147807. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  147808. dc_counts[nbits]++;
  147809. r = 0; /* r = run length of zeros */
  147810. for (k = 1; k < DCTSIZE2; k++) {
  147811. if ((temp = block[jpeg_natural_order[k]]) == 0) {
  147812. r++;
  147813. } else {
  147814. while (r > 15) {
  147815. ac_counts[0xF0]++;
  147816. r -= 16;
  147817. }
  147818. if (temp < 0)
  147819. temp = -temp;
  147820. nbits = 1; /* there must be at least one 1 bit */
  147821. while ((temp >>= 1))
  147822. nbits++;
  147823. if (nbits > MAX_COEF_BITS)
  147824. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  147825. ac_counts[(r << 4) + nbits]++;
  147826. r = 0;
  147827. }
  147828. }
  147829. if (r > 0)
  147830. ac_counts[0]++;
  147831. }
  147832. METHODDEF(boolean)
  147833. encode_mcu_gather (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  147834. {
  147835. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147836. int blkn, ci;
  147837. jpeg_component_info * compptr;
  147838. if (cinfo->restart_interval) {
  147839. if (entropy->restarts_to_go == 0) {
  147840. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  147841. entropy->saved.last_dc_val[ci] = 0;
  147842. entropy->restarts_to_go = cinfo->restart_interval;
  147843. }
  147844. entropy->restarts_to_go--;
  147845. }
  147846. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  147847. ci = cinfo->MCU_membership[blkn];
  147848. compptr = cinfo->cur_comp_info[ci];
  147849. htest_one_block(cinfo, MCU_data[blkn][0], entropy->saved.last_dc_val[ci],
  147850. entropy->dc_count_ptrs[compptr->dc_tbl_no],
  147851. entropy->ac_count_ptrs[compptr->ac_tbl_no]);
  147852. entropy->saved.last_dc_val[ci] = MCU_data[blkn][0][0];
  147853. }
  147854. return TRUE;
  147855. }
  147856. GLOBAL(void)
  147857. jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[])
  147858. {
  147859. #define MAX_CLEN 32 /* assumed maximum initial code length */
  147860. UINT8 bits[MAX_CLEN+1]; /* bits[k] = # of symbols with code length k */
  147861. int codesize[257]; /* codesize[k] = code length of symbol k */
  147862. int others[257]; /* next symbol in current branch of tree */
  147863. int c1, c2;
  147864. int p, i, j;
  147865. long v;
  147866. MEMZERO(bits, SIZEOF(bits));
  147867. MEMZERO(codesize, SIZEOF(codesize));
  147868. for (i = 0; i < 257; i++)
  147869. others[i] = -1; /* init links to empty */
  147870. freq[256] = 1; /* make sure 256 has a nonzero count */
  147871. for (;;) {
  147872. c1 = -1;
  147873. v = 1000000000L;
  147874. for (i = 0; i <= 256; i++) {
  147875. if (freq[i] && freq[i] <= v) {
  147876. v = freq[i];
  147877. c1 = i;
  147878. }
  147879. }
  147880. c2 = -1;
  147881. v = 1000000000L;
  147882. for (i = 0; i <= 256; i++) {
  147883. if (freq[i] && freq[i] <= v && i != c1) {
  147884. v = freq[i];
  147885. c2 = i;
  147886. }
  147887. }
  147888. if (c2 < 0)
  147889. break;
  147890. freq[c1] += freq[c2];
  147891. freq[c2] = 0;
  147892. codesize[c1]++;
  147893. while (others[c1] >= 0) {
  147894. c1 = others[c1];
  147895. codesize[c1]++;
  147896. }
  147897. others[c1] = c2; /* chain c2 onto c1's tree branch */
  147898. codesize[c2]++;
  147899. while (others[c2] >= 0) {
  147900. c2 = others[c2];
  147901. codesize[c2]++;
  147902. }
  147903. }
  147904. for (i = 0; i <= 256; i++) {
  147905. if (codesize[i]) {
  147906. if (codesize[i] > MAX_CLEN)
  147907. ERREXIT(cinfo, JERR_HUFF_CLEN_OVERFLOW);
  147908. bits[codesize[i]]++;
  147909. }
  147910. }
  147911. for (i = MAX_CLEN; i > 16; i--) {
  147912. while (bits[i] > 0) {
  147913. j = i - 2; /* find length of new prefix to be used */
  147914. while (bits[j] == 0)
  147915. j--;
  147916. bits[i] -= 2; /* remove two symbols */
  147917. bits[i-1]++; /* one goes in this length */
  147918. bits[j+1] += 2; /* two new symbols in this length */
  147919. bits[j]--; /* symbol of this length is now a prefix */
  147920. }
  147921. }
  147922. while (bits[i] == 0) /* find largest codelength still in use */
  147923. i--;
  147924. bits[i]--;
  147925. MEMCOPY(htbl->bits, bits, SIZEOF(htbl->bits));
  147926. p = 0;
  147927. for (i = 1; i <= MAX_CLEN; i++) {
  147928. for (j = 0; j <= 255; j++) {
  147929. if (codesize[j] == i) {
  147930. htbl->huffval[p] = (UINT8) j;
  147931. p++;
  147932. }
  147933. }
  147934. }
  147935. htbl->sent_table = FALSE;
  147936. }
  147937. METHODDEF(void)
  147938. finish_pass_gather (j_compress_ptr cinfo)
  147939. {
  147940. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147941. int ci, dctbl, actbl;
  147942. jpeg_component_info * compptr;
  147943. JHUFF_TBL **htblptr;
  147944. boolean did_dc[NUM_HUFF_TBLS];
  147945. boolean did_ac[NUM_HUFF_TBLS];
  147946. MEMZERO(did_dc, SIZEOF(did_dc));
  147947. MEMZERO(did_ac, SIZEOF(did_ac));
  147948. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  147949. compptr = cinfo->cur_comp_info[ci];
  147950. dctbl = compptr->dc_tbl_no;
  147951. actbl = compptr->ac_tbl_no;
  147952. if (! did_dc[dctbl]) {
  147953. htblptr = & cinfo->dc_huff_tbl_ptrs[dctbl];
  147954. if (*htblptr == NULL)
  147955. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  147956. jpeg_gen_optimal_table(cinfo, *htblptr, entropy->dc_count_ptrs[dctbl]);
  147957. did_dc[dctbl] = TRUE;
  147958. }
  147959. if (! did_ac[actbl]) {
  147960. htblptr = & cinfo->ac_huff_tbl_ptrs[actbl];
  147961. if (*htblptr == NULL)
  147962. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  147963. jpeg_gen_optimal_table(cinfo, *htblptr, entropy->ac_count_ptrs[actbl]);
  147964. did_ac[actbl] = TRUE;
  147965. }
  147966. }
  147967. }
  147968. #endif /* ENTROPY_OPT_SUPPORTED */
  147969. GLOBAL(void)
  147970. jinit_huff_encoder (j_compress_ptr cinfo)
  147971. {
  147972. huff_entropy_ptr entropy;
  147973. int i;
  147974. entropy = (huff_entropy_ptr)
  147975. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147976. SIZEOF(huff_entropy_encoder));
  147977. cinfo->entropy = (struct jpeg_entropy_encoder *) entropy;
  147978. entropy->pub.start_pass = start_pass_huff;
  147979. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  147980. entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL;
  147981. #ifdef ENTROPY_OPT_SUPPORTED
  147982. entropy->dc_count_ptrs[i] = entropy->ac_count_ptrs[i] = NULL;
  147983. #endif
  147984. }
  147985. }
  147986. /*** End of inlined file: jchuff.c ***/
  147987. #undef emit_byte
  147988. /*** Start of inlined file: jcinit.c ***/
  147989. #define JPEG_INTERNALS
  147990. GLOBAL(void)
  147991. jinit_compress_master (j_compress_ptr cinfo)
  147992. {
  147993. jinit_c_master_control(cinfo, FALSE /* full compression */);
  147994. if (! cinfo->raw_data_in) {
  147995. jinit_color_converter(cinfo);
  147996. jinit_downsampler(cinfo);
  147997. jinit_c_prep_controller(cinfo, FALSE /* never need full buffer here */);
  147998. }
  147999. jinit_forward_dct(cinfo);
  148000. if (cinfo->arith_code) {
  148001. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  148002. } else {
  148003. if (cinfo->progressive_mode) {
  148004. #ifdef C_PROGRESSIVE_SUPPORTED
  148005. jinit_phuff_encoder(cinfo);
  148006. #else
  148007. ERREXIT(cinfo, JERR_NOT_COMPILED);
  148008. #endif
  148009. } else
  148010. jinit_huff_encoder(cinfo);
  148011. }
  148012. jinit_c_coef_controller(cinfo,
  148013. (boolean) (cinfo->num_scans > 1 || cinfo->optimize_coding));
  148014. jinit_c_main_controller(cinfo, FALSE /* never need full buffer here */);
  148015. jinit_marker_writer(cinfo);
  148016. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  148017. (*cinfo->marker->write_file_header) (cinfo);
  148018. }
  148019. /*** End of inlined file: jcinit.c ***/
  148020. /*** Start of inlined file: jcmainct.c ***/
  148021. #define JPEG_INTERNALS
  148022. #undef FULL_MAIN_BUFFER_SUPPORTED
  148023. typedef struct {
  148024. struct jpeg_c_main_controller pub; /* public fields */
  148025. JDIMENSION cur_iMCU_row; /* number of current iMCU row */
  148026. JDIMENSION rowgroup_ctr; /* counts row groups received in iMCU row */
  148027. boolean suspended; /* remember if we suspended output */
  148028. J_BUF_MODE pass_mode; /* current operating mode */
  148029. JSAMPARRAY buffer[MAX_COMPONENTS];
  148030. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  148031. jvirt_sarray_ptr whole_image[MAX_COMPONENTS];
  148032. #endif
  148033. } my_main_controller;
  148034. typedef my_main_controller * my_main_ptr;
  148035. METHODDEF(void) process_data_simple_main
  148036. JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,
  148037. JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));
  148038. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  148039. METHODDEF(void) process_data_buffer_main
  148040. JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,
  148041. JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));
  148042. #endif
  148043. METHODDEF(void)
  148044. start_pass_main (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  148045. {
  148046. my_main_ptr main_ = (my_main_ptr) cinfo->main;
  148047. if (cinfo->raw_data_in)
  148048. return;
  148049. main_->cur_iMCU_row = 0; /* initialize counters */
  148050. main_->rowgroup_ctr = 0;
  148051. main_->suspended = FALSE;
  148052. main_->pass_mode = pass_mode; /* save mode for use by process_data */
  148053. switch (pass_mode) {
  148054. case JBUF_PASS_THRU:
  148055. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  148056. if (main_->whole_image[0] != NULL)
  148057. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  148058. #endif
  148059. main_->pub.process_data = process_data_simple_main;
  148060. break;
  148061. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  148062. case JBUF_SAVE_SOURCE:
  148063. case JBUF_CRANK_DEST:
  148064. case JBUF_SAVE_AND_PASS:
  148065. if (main_->whole_image[0] == NULL)
  148066. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  148067. main_->pub.process_data = process_data_buffer_main;
  148068. break;
  148069. #endif
  148070. default:
  148071. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  148072. break;
  148073. }
  148074. }
  148075. METHODDEF(void)
  148076. process_data_simple_main (j_compress_ptr cinfo,
  148077. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  148078. JDIMENSION in_rows_avail)
  148079. {
  148080. my_main_ptr main_ = (my_main_ptr) cinfo->main;
  148081. while (main_->cur_iMCU_row < cinfo->total_iMCU_rows) {
  148082. if (main_->rowgroup_ctr < DCTSIZE)
  148083. (*cinfo->prep->pre_process_data) (cinfo,
  148084. input_buf, in_row_ctr, in_rows_avail,
  148085. main_->buffer, &main_->rowgroup_ctr,
  148086. (JDIMENSION) DCTSIZE);
  148087. if (main_->rowgroup_ctr != DCTSIZE)
  148088. return;
  148089. if (! (*cinfo->coef->compress_data) (cinfo, main_->buffer)) {
  148090. if (! main_->suspended) {
  148091. (*in_row_ctr)--;
  148092. main_->suspended = TRUE;
  148093. }
  148094. return;
  148095. }
  148096. if (main_->suspended) {
  148097. (*in_row_ctr)++;
  148098. main_->suspended = FALSE;
  148099. }
  148100. main_->rowgroup_ctr = 0;
  148101. main_->cur_iMCU_row++;
  148102. }
  148103. }
  148104. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  148105. METHODDEF(void)
  148106. process_data_buffer_main (j_compress_ptr cinfo,
  148107. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  148108. JDIMENSION in_rows_avail)
  148109. {
  148110. my_main_ptr main = (my_main_ptr) cinfo->main;
  148111. int ci;
  148112. jpeg_component_info *compptr;
  148113. boolean writing = (main->pass_mode != JBUF_CRANK_DEST);
  148114. while (main->cur_iMCU_row < cinfo->total_iMCU_rows) {
  148115. if (main->rowgroup_ctr == 0) {
  148116. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148117. ci++, compptr++) {
  148118. main->buffer[ci] = (*cinfo->mem->access_virt_sarray)
  148119. ((j_common_ptr) cinfo, main->whole_image[ci],
  148120. main->cur_iMCU_row * (compptr->v_samp_factor * DCTSIZE),
  148121. (JDIMENSION) (compptr->v_samp_factor * DCTSIZE), writing);
  148122. }
  148123. if (! writing) {
  148124. *in_row_ctr += cinfo->max_v_samp_factor * DCTSIZE;
  148125. main->rowgroup_ctr = DCTSIZE;
  148126. }
  148127. }
  148128. if (writing) {
  148129. (*cinfo->prep->pre_process_data) (cinfo,
  148130. input_buf, in_row_ctr, in_rows_avail,
  148131. main->buffer, &main->rowgroup_ctr,
  148132. (JDIMENSION) DCTSIZE);
  148133. if (main->rowgroup_ctr < DCTSIZE)
  148134. return;
  148135. }
  148136. if (main->pass_mode != JBUF_SAVE_SOURCE) {
  148137. if (! (*cinfo->coef->compress_data) (cinfo, main->buffer)) {
  148138. if (! main->suspended) {
  148139. (*in_row_ctr)--;
  148140. main->suspended = TRUE;
  148141. }
  148142. return;
  148143. }
  148144. if (main->suspended) {
  148145. (*in_row_ctr)++;
  148146. main->suspended = FALSE;
  148147. }
  148148. }
  148149. main->rowgroup_ctr = 0;
  148150. main->cur_iMCU_row++;
  148151. }
  148152. }
  148153. #endif /* FULL_MAIN_BUFFER_SUPPORTED */
  148154. GLOBAL(void)
  148155. jinit_c_main_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  148156. {
  148157. my_main_ptr main_;
  148158. int ci;
  148159. jpeg_component_info *compptr;
  148160. main_ = (my_main_ptr)
  148161. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148162. SIZEOF(my_main_controller));
  148163. cinfo->main = (struct jpeg_c_main_controller *) main_;
  148164. main_->pub.start_pass = start_pass_main;
  148165. if (cinfo->raw_data_in)
  148166. return;
  148167. if (need_full_buffer) {
  148168. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  148169. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148170. ci++, compptr++) {
  148171. main->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
  148172. ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  148173. compptr->width_in_blocks * DCTSIZE,
  148174. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  148175. (long) compptr->v_samp_factor) * DCTSIZE,
  148176. (JDIMENSION) (compptr->v_samp_factor * DCTSIZE));
  148177. }
  148178. #else
  148179. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  148180. #endif
  148181. } else {
  148182. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  148183. main_->whole_image[0] = NULL; /* flag for no virtual arrays */
  148184. #endif
  148185. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148186. ci++, compptr++) {
  148187. main_->buffer[ci] = (*cinfo->mem->alloc_sarray)
  148188. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148189. compptr->width_in_blocks * DCTSIZE,
  148190. (JDIMENSION) (compptr->v_samp_factor * DCTSIZE));
  148191. }
  148192. }
  148193. }
  148194. /*** End of inlined file: jcmainct.c ***/
  148195. /*** Start of inlined file: jcmarker.c ***/
  148196. #define JPEG_INTERNALS
  148197. typedef struct {
  148198. struct jpeg_marker_writer pub; /* public fields */
  148199. unsigned int last_restart_interval; /* last DRI value emitted; 0 after SOI */
  148200. } my_marker_writer;
  148201. typedef my_marker_writer * my_marker_ptr;
  148202. LOCAL(void)
  148203. emit_byte (j_compress_ptr cinfo, int val)
  148204. {
  148205. struct jpeg_destination_mgr * dest = cinfo->dest;
  148206. *(dest->next_output_byte)++ = (JOCTET) val;
  148207. if (--dest->free_in_buffer == 0) {
  148208. if (! (*dest->empty_output_buffer) (cinfo))
  148209. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  148210. }
  148211. }
  148212. LOCAL(void)
  148213. emit_marker (j_compress_ptr cinfo, JPEG_MARKER mark)
  148214. {
  148215. emit_byte(cinfo, 0xFF);
  148216. emit_byte(cinfo, (int) mark);
  148217. }
  148218. LOCAL(void)
  148219. emit_2bytes (j_compress_ptr cinfo, int value)
  148220. {
  148221. emit_byte(cinfo, (value >> 8) & 0xFF);
  148222. emit_byte(cinfo, value & 0xFF);
  148223. }
  148224. LOCAL(int)
  148225. emit_dqt (j_compress_ptr cinfo, int index)
  148226. {
  148227. JQUANT_TBL * qtbl = cinfo->quant_tbl_ptrs[index];
  148228. int prec;
  148229. int i;
  148230. if (qtbl == NULL)
  148231. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, index);
  148232. prec = 0;
  148233. for (i = 0; i < DCTSIZE2; i++) {
  148234. if (qtbl->quantval[i] > 255)
  148235. prec = 1;
  148236. }
  148237. if (! qtbl->sent_table) {
  148238. emit_marker(cinfo, M_DQT);
  148239. emit_2bytes(cinfo, prec ? DCTSIZE2*2 + 1 + 2 : DCTSIZE2 + 1 + 2);
  148240. emit_byte(cinfo, index + (prec<<4));
  148241. for (i = 0; i < DCTSIZE2; i++) {
  148242. unsigned int qval = qtbl->quantval[jpeg_natural_order[i]];
  148243. if (prec)
  148244. emit_byte(cinfo, (int) (qval >> 8));
  148245. emit_byte(cinfo, (int) (qval & 0xFF));
  148246. }
  148247. qtbl->sent_table = TRUE;
  148248. }
  148249. return prec;
  148250. }
  148251. LOCAL(void)
  148252. emit_dht (j_compress_ptr cinfo, int index, boolean is_ac)
  148253. {
  148254. JHUFF_TBL * htbl;
  148255. int length, i;
  148256. if (is_ac) {
  148257. htbl = cinfo->ac_huff_tbl_ptrs[index];
  148258. index += 0x10; /* output index has AC bit set */
  148259. } else {
  148260. htbl = cinfo->dc_huff_tbl_ptrs[index];
  148261. }
  148262. if (htbl == NULL)
  148263. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, index);
  148264. if (! htbl->sent_table) {
  148265. emit_marker(cinfo, M_DHT);
  148266. length = 0;
  148267. for (i = 1; i <= 16; i++)
  148268. length += htbl->bits[i];
  148269. emit_2bytes(cinfo, length + 2 + 1 + 16);
  148270. emit_byte(cinfo, index);
  148271. for (i = 1; i <= 16; i++)
  148272. emit_byte(cinfo, htbl->bits[i]);
  148273. for (i = 0; i < length; i++)
  148274. emit_byte(cinfo, htbl->huffval[i]);
  148275. htbl->sent_table = TRUE;
  148276. }
  148277. }
  148278. LOCAL(void)
  148279. emit_dac (j_compress_ptr cinfo)
  148280. {
  148281. #ifdef C_ARITH_CODING_SUPPORTED
  148282. char dc_in_use[NUM_ARITH_TBLS];
  148283. char ac_in_use[NUM_ARITH_TBLS];
  148284. int length, i;
  148285. jpeg_component_info *compptr;
  148286. for (i = 0; i < NUM_ARITH_TBLS; i++)
  148287. dc_in_use[i] = ac_in_use[i] = 0;
  148288. for (i = 0; i < cinfo->comps_in_scan; i++) {
  148289. compptr = cinfo->cur_comp_info[i];
  148290. dc_in_use[compptr->dc_tbl_no] = 1;
  148291. ac_in_use[compptr->ac_tbl_no] = 1;
  148292. }
  148293. length = 0;
  148294. for (i = 0; i < NUM_ARITH_TBLS; i++)
  148295. length += dc_in_use[i] + ac_in_use[i];
  148296. emit_marker(cinfo, M_DAC);
  148297. emit_2bytes(cinfo, length*2 + 2);
  148298. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  148299. if (dc_in_use[i]) {
  148300. emit_byte(cinfo, i);
  148301. emit_byte(cinfo, cinfo->arith_dc_L[i] + (cinfo->arith_dc_U[i]<<4));
  148302. }
  148303. if (ac_in_use[i]) {
  148304. emit_byte(cinfo, i + 0x10);
  148305. emit_byte(cinfo, cinfo->arith_ac_K[i]);
  148306. }
  148307. }
  148308. #endif /* C_ARITH_CODING_SUPPORTED */
  148309. }
  148310. LOCAL(void)
  148311. emit_dri (j_compress_ptr cinfo)
  148312. {
  148313. emit_marker(cinfo, M_DRI);
  148314. emit_2bytes(cinfo, 4); /* fixed length */
  148315. emit_2bytes(cinfo, (int) cinfo->restart_interval);
  148316. }
  148317. LOCAL(void)
  148318. emit_sof (j_compress_ptr cinfo, JPEG_MARKER code)
  148319. {
  148320. int ci;
  148321. jpeg_component_info *compptr;
  148322. emit_marker(cinfo, code);
  148323. emit_2bytes(cinfo, 3 * cinfo->num_components + 2 + 5 + 1); /* length */
  148324. if ((long) cinfo->image_height > 65535L ||
  148325. (long) cinfo->image_width > 65535L)
  148326. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) 65535);
  148327. emit_byte(cinfo, cinfo->data_precision);
  148328. emit_2bytes(cinfo, (int) cinfo->image_height);
  148329. emit_2bytes(cinfo, (int) cinfo->image_width);
  148330. emit_byte(cinfo, cinfo->num_components);
  148331. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148332. ci++, compptr++) {
  148333. emit_byte(cinfo, compptr->component_id);
  148334. emit_byte(cinfo, (compptr->h_samp_factor << 4) + compptr->v_samp_factor);
  148335. emit_byte(cinfo, compptr->quant_tbl_no);
  148336. }
  148337. }
  148338. LOCAL(void)
  148339. emit_sos (j_compress_ptr cinfo)
  148340. {
  148341. int i, td, ta;
  148342. jpeg_component_info *compptr;
  148343. emit_marker(cinfo, M_SOS);
  148344. emit_2bytes(cinfo, 2 * cinfo->comps_in_scan + 2 + 1 + 3); /* length */
  148345. emit_byte(cinfo, cinfo->comps_in_scan);
  148346. for (i = 0; i < cinfo->comps_in_scan; i++) {
  148347. compptr = cinfo->cur_comp_info[i];
  148348. emit_byte(cinfo, compptr->component_id);
  148349. td = compptr->dc_tbl_no;
  148350. ta = compptr->ac_tbl_no;
  148351. if (cinfo->progressive_mode) {
  148352. if (cinfo->Ss == 0) {
  148353. ta = 0; /* DC scan */
  148354. if (cinfo->Ah != 0 && !cinfo->arith_code)
  148355. td = 0; /* no DC table either */
  148356. } else {
  148357. td = 0; /* AC scan */
  148358. }
  148359. }
  148360. emit_byte(cinfo, (td << 4) + ta);
  148361. }
  148362. emit_byte(cinfo, cinfo->Ss);
  148363. emit_byte(cinfo, cinfo->Se);
  148364. emit_byte(cinfo, (cinfo->Ah << 4) + cinfo->Al);
  148365. }
  148366. LOCAL(void)
  148367. emit_jfif_app0 (j_compress_ptr cinfo)
  148368. {
  148369. emit_marker(cinfo, M_APP0);
  148370. emit_2bytes(cinfo, 2 + 4 + 1 + 2 + 1 + 2 + 2 + 1 + 1); /* length */
  148371. emit_byte(cinfo, 0x4A); /* Identifier: ASCII "JFIF" */
  148372. emit_byte(cinfo, 0x46);
  148373. emit_byte(cinfo, 0x49);
  148374. emit_byte(cinfo, 0x46);
  148375. emit_byte(cinfo, 0);
  148376. emit_byte(cinfo, cinfo->JFIF_major_version); /* Version fields */
  148377. emit_byte(cinfo, cinfo->JFIF_minor_version);
  148378. emit_byte(cinfo, cinfo->density_unit); /* Pixel size information */
  148379. emit_2bytes(cinfo, (int) cinfo->X_density);
  148380. emit_2bytes(cinfo, (int) cinfo->Y_density);
  148381. emit_byte(cinfo, 0); /* No thumbnail image */
  148382. emit_byte(cinfo, 0);
  148383. }
  148384. LOCAL(void)
  148385. emit_adobe_app14 (j_compress_ptr cinfo)
  148386. {
  148387. emit_marker(cinfo, M_APP14);
  148388. emit_2bytes(cinfo, 2 + 5 + 2 + 2 + 2 + 1); /* length */
  148389. emit_byte(cinfo, 0x41); /* Identifier: ASCII "Adobe" */
  148390. emit_byte(cinfo, 0x64);
  148391. emit_byte(cinfo, 0x6F);
  148392. emit_byte(cinfo, 0x62);
  148393. emit_byte(cinfo, 0x65);
  148394. emit_2bytes(cinfo, 100); /* Version */
  148395. emit_2bytes(cinfo, 0); /* Flags0 */
  148396. emit_2bytes(cinfo, 0); /* Flags1 */
  148397. switch (cinfo->jpeg_color_space) {
  148398. case JCS_YCbCr:
  148399. emit_byte(cinfo, 1); /* Color transform = 1 */
  148400. break;
  148401. case JCS_YCCK:
  148402. emit_byte(cinfo, 2); /* Color transform = 2 */
  148403. break;
  148404. default:
  148405. emit_byte(cinfo, 0); /* Color transform = 0 */
  148406. break;
  148407. }
  148408. }
  148409. METHODDEF(void)
  148410. write_marker_header (j_compress_ptr cinfo, int marker, unsigned int datalen)
  148411. {
  148412. if (datalen > (unsigned int) 65533) /* safety check */
  148413. ERREXIT(cinfo, JERR_BAD_LENGTH);
  148414. emit_marker(cinfo, (JPEG_MARKER) marker);
  148415. emit_2bytes(cinfo, (int) (datalen + 2)); /* total length */
  148416. }
  148417. METHODDEF(void)
  148418. write_marker_byte (j_compress_ptr cinfo, int val)
  148419. {
  148420. emit_byte(cinfo, val);
  148421. }
  148422. METHODDEF(void)
  148423. write_file_header (j_compress_ptr cinfo)
  148424. {
  148425. my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
  148426. emit_marker(cinfo, M_SOI); /* first the SOI */
  148427. marker->last_restart_interval = 0;
  148428. if (cinfo->write_JFIF_header) /* next an optional JFIF APP0 */
  148429. emit_jfif_app0(cinfo);
  148430. if (cinfo->write_Adobe_marker) /* next an optional Adobe APP14 */
  148431. emit_adobe_app14(cinfo);
  148432. }
  148433. METHODDEF(void)
  148434. write_frame_header (j_compress_ptr cinfo)
  148435. {
  148436. int ci, prec;
  148437. boolean is_baseline;
  148438. jpeg_component_info *compptr;
  148439. prec = 0;
  148440. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148441. ci++, compptr++) {
  148442. prec += emit_dqt(cinfo, compptr->quant_tbl_no);
  148443. }
  148444. if (cinfo->arith_code || cinfo->progressive_mode ||
  148445. cinfo->data_precision != 8) {
  148446. is_baseline = FALSE;
  148447. } else {
  148448. is_baseline = TRUE;
  148449. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148450. ci++, compptr++) {
  148451. if (compptr->dc_tbl_no > 1 || compptr->ac_tbl_no > 1)
  148452. is_baseline = FALSE;
  148453. }
  148454. if (prec && is_baseline) {
  148455. is_baseline = FALSE;
  148456. TRACEMS(cinfo, 0, JTRC_16BIT_TABLES);
  148457. }
  148458. }
  148459. if (cinfo->arith_code) {
  148460. emit_sof(cinfo, M_SOF9); /* SOF code for arithmetic coding */
  148461. } else {
  148462. if (cinfo->progressive_mode)
  148463. emit_sof(cinfo, M_SOF2); /* SOF code for progressive Huffman */
  148464. else if (is_baseline)
  148465. emit_sof(cinfo, M_SOF0); /* SOF code for baseline implementation */
  148466. else
  148467. emit_sof(cinfo, M_SOF1); /* SOF code for non-baseline Huffman file */
  148468. }
  148469. }
  148470. METHODDEF(void)
  148471. write_scan_header (j_compress_ptr cinfo)
  148472. {
  148473. my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
  148474. int i;
  148475. jpeg_component_info *compptr;
  148476. if (cinfo->arith_code) {
  148477. emit_dac(cinfo);
  148478. } else {
  148479. for (i = 0; i < cinfo->comps_in_scan; i++) {
  148480. compptr = cinfo->cur_comp_info[i];
  148481. if (cinfo->progressive_mode) {
  148482. if (cinfo->Ss == 0) {
  148483. if (cinfo->Ah == 0) /* DC needs no table for refinement scan */
  148484. emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
  148485. } else {
  148486. emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
  148487. }
  148488. } else {
  148489. emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
  148490. emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
  148491. }
  148492. }
  148493. }
  148494. if (cinfo->restart_interval != marker->last_restart_interval) {
  148495. emit_dri(cinfo);
  148496. marker->last_restart_interval = cinfo->restart_interval;
  148497. }
  148498. emit_sos(cinfo);
  148499. }
  148500. METHODDEF(void)
  148501. write_file_trailer (j_compress_ptr cinfo)
  148502. {
  148503. emit_marker(cinfo, M_EOI);
  148504. }
  148505. METHODDEF(void)
  148506. write_tables_only (j_compress_ptr cinfo)
  148507. {
  148508. int i;
  148509. emit_marker(cinfo, M_SOI);
  148510. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  148511. if (cinfo->quant_tbl_ptrs[i] != NULL)
  148512. (void) emit_dqt(cinfo, i);
  148513. }
  148514. if (! cinfo->arith_code) {
  148515. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  148516. if (cinfo->dc_huff_tbl_ptrs[i] != NULL)
  148517. emit_dht(cinfo, i, FALSE);
  148518. if (cinfo->ac_huff_tbl_ptrs[i] != NULL)
  148519. emit_dht(cinfo, i, TRUE);
  148520. }
  148521. }
  148522. emit_marker(cinfo, M_EOI);
  148523. }
  148524. GLOBAL(void)
  148525. jinit_marker_writer (j_compress_ptr cinfo)
  148526. {
  148527. my_marker_ptr marker;
  148528. marker = (my_marker_ptr)
  148529. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148530. SIZEOF(my_marker_writer));
  148531. cinfo->marker = (struct jpeg_marker_writer *) marker;
  148532. marker->pub.write_file_header = write_file_header;
  148533. marker->pub.write_frame_header = write_frame_header;
  148534. marker->pub.write_scan_header = write_scan_header;
  148535. marker->pub.write_file_trailer = write_file_trailer;
  148536. marker->pub.write_tables_only = write_tables_only;
  148537. marker->pub.write_marker_header = write_marker_header;
  148538. marker->pub.write_marker_byte = write_marker_byte;
  148539. marker->last_restart_interval = 0;
  148540. }
  148541. /*** End of inlined file: jcmarker.c ***/
  148542. /*** Start of inlined file: jcmaster.c ***/
  148543. #define JPEG_INTERNALS
  148544. typedef enum {
  148545. main_pass, /* input data, also do first output step */
  148546. huff_opt_pass, /* Huffman code optimization pass */
  148547. output_pass /* data output pass */
  148548. } c_pass_type;
  148549. typedef struct {
  148550. struct jpeg_comp_master pub; /* public fields */
  148551. c_pass_type pass_type; /* the type of the current pass */
  148552. int pass_number; /* # of passes completed */
  148553. int total_passes; /* total # of passes needed */
  148554. int scan_number; /* current index in scan_info[] */
  148555. } my_comp_master;
  148556. typedef my_comp_master * my_master_ptr;
  148557. LOCAL(void)
  148558. initial_setup (j_compress_ptr cinfo)
  148559. {
  148560. int ci;
  148561. jpeg_component_info *compptr;
  148562. long samplesperrow;
  148563. JDIMENSION jd_samplesperrow;
  148564. if (cinfo->image_height <= 0 || cinfo->image_width <= 0
  148565. || cinfo->num_components <= 0 || cinfo->input_components <= 0)
  148566. ERREXIT(cinfo, JERR_EMPTY_IMAGE);
  148567. if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION ||
  148568. (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION)
  148569. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
  148570. samplesperrow = (long) cinfo->image_width * (long) cinfo->input_components;
  148571. jd_samplesperrow = (JDIMENSION) samplesperrow;
  148572. if ((long) jd_samplesperrow != samplesperrow)
  148573. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  148574. if (cinfo->data_precision != BITS_IN_JSAMPLE)
  148575. ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
  148576. if (cinfo->num_components > MAX_COMPONENTS)
  148577. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  148578. MAX_COMPONENTS);
  148579. cinfo->max_h_samp_factor = 1;
  148580. cinfo->max_v_samp_factor = 1;
  148581. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148582. ci++, compptr++) {
  148583. if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||
  148584. compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
  148585. ERREXIT(cinfo, JERR_BAD_SAMPLING);
  148586. cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
  148587. compptr->h_samp_factor);
  148588. cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
  148589. compptr->v_samp_factor);
  148590. }
  148591. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148592. ci++, compptr++) {
  148593. compptr->component_index = ci;
  148594. compptr->DCT_scaled_size = DCTSIZE;
  148595. compptr->width_in_blocks = (JDIMENSION)
  148596. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  148597. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  148598. compptr->height_in_blocks = (JDIMENSION)
  148599. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  148600. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  148601. compptr->downsampled_width = (JDIMENSION)
  148602. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  148603. (long) cinfo->max_h_samp_factor);
  148604. compptr->downsampled_height = (JDIMENSION)
  148605. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  148606. (long) cinfo->max_v_samp_factor);
  148607. compptr->component_needed = TRUE;
  148608. }
  148609. cinfo->total_iMCU_rows = (JDIMENSION)
  148610. jdiv_round_up((long) cinfo->image_height,
  148611. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  148612. }
  148613. #ifdef C_MULTISCAN_FILES_SUPPORTED
  148614. LOCAL(void)
  148615. validate_script (j_compress_ptr cinfo)
  148616. {
  148617. const jpeg_scan_info * scanptr;
  148618. int scanno, ncomps, ci, coefi, thisi;
  148619. int Ss, Se, Ah, Al;
  148620. boolean component_sent[MAX_COMPONENTS];
  148621. #ifdef C_PROGRESSIVE_SUPPORTED
  148622. int * last_bitpos_ptr;
  148623. int last_bitpos[MAX_COMPONENTS][DCTSIZE2];
  148624. #endif
  148625. if (cinfo->num_scans <= 0)
  148626. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, 0);
  148627. scanptr = cinfo->scan_info;
  148628. if (scanptr->Ss != 0 || scanptr->Se != DCTSIZE2-1) {
  148629. #ifdef C_PROGRESSIVE_SUPPORTED
  148630. cinfo->progressive_mode = TRUE;
  148631. last_bitpos_ptr = & last_bitpos[0][0];
  148632. for (ci = 0; ci < cinfo->num_components; ci++)
  148633. for (coefi = 0; coefi < DCTSIZE2; coefi++)
  148634. *last_bitpos_ptr++ = -1;
  148635. #else
  148636. ERREXIT(cinfo, JERR_NOT_COMPILED);
  148637. #endif
  148638. } else {
  148639. cinfo->progressive_mode = FALSE;
  148640. for (ci = 0; ci < cinfo->num_components; ci++)
  148641. component_sent[ci] = FALSE;
  148642. }
  148643. for (scanno = 1; scanno <= cinfo->num_scans; scanptr++, scanno++) {
  148644. ncomps = scanptr->comps_in_scan;
  148645. if (ncomps <= 0 || ncomps > MAX_COMPS_IN_SCAN)
  148646. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, ncomps, MAX_COMPS_IN_SCAN);
  148647. for (ci = 0; ci < ncomps; ci++) {
  148648. thisi = scanptr->component_index[ci];
  148649. if (thisi < 0 || thisi >= cinfo->num_components)
  148650. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  148651. if (ci > 0 && thisi <= scanptr->component_index[ci-1])
  148652. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  148653. }
  148654. Ss = scanptr->Ss;
  148655. Se = scanptr->Se;
  148656. Ah = scanptr->Ah;
  148657. Al = scanptr->Al;
  148658. if (cinfo->progressive_mode) {
  148659. #ifdef C_PROGRESSIVE_SUPPORTED
  148660. #if BITS_IN_JSAMPLE == 8
  148661. #define MAX_AH_AL 10
  148662. #else
  148663. #define MAX_AH_AL 13
  148664. #endif
  148665. if (Ss < 0 || Ss >= DCTSIZE2 || Se < Ss || Se >= DCTSIZE2 ||
  148666. Ah < 0 || Ah > MAX_AH_AL || Al < 0 || Al > MAX_AH_AL)
  148667. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148668. if (Ss == 0) {
  148669. if (Se != 0) /* DC and AC together not OK */
  148670. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148671. } else {
  148672. if (ncomps != 1) /* AC scans must be for only one component */
  148673. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148674. }
  148675. for (ci = 0; ci < ncomps; ci++) {
  148676. last_bitpos_ptr = & last_bitpos[scanptr->component_index[ci]][0];
  148677. if (Ss != 0 && last_bitpos_ptr[0] < 0) /* AC without prior DC scan */
  148678. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148679. for (coefi = Ss; coefi <= Se; coefi++) {
  148680. if (last_bitpos_ptr[coefi] < 0) {
  148681. if (Ah != 0)
  148682. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148683. } else {
  148684. if (Ah != last_bitpos_ptr[coefi] || Al != Ah-1)
  148685. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148686. }
  148687. last_bitpos_ptr[coefi] = Al;
  148688. }
  148689. }
  148690. #endif
  148691. } else {
  148692. if (Ss != 0 || Se != DCTSIZE2-1 || Ah != 0 || Al != 0)
  148693. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148694. for (ci = 0; ci < ncomps; ci++) {
  148695. thisi = scanptr->component_index[ci];
  148696. if (component_sent[thisi])
  148697. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  148698. component_sent[thisi] = TRUE;
  148699. }
  148700. }
  148701. }
  148702. if (cinfo->progressive_mode) {
  148703. #ifdef C_PROGRESSIVE_SUPPORTED
  148704. for (ci = 0; ci < cinfo->num_components; ci++) {
  148705. if (last_bitpos[ci][0] < 0)
  148706. ERREXIT(cinfo, JERR_MISSING_DATA);
  148707. }
  148708. #endif
  148709. } else {
  148710. for (ci = 0; ci < cinfo->num_components; ci++) {
  148711. if (! component_sent[ci])
  148712. ERREXIT(cinfo, JERR_MISSING_DATA);
  148713. }
  148714. }
  148715. }
  148716. #endif /* C_MULTISCAN_FILES_SUPPORTED */
  148717. LOCAL(void)
  148718. select_scan_parameters (j_compress_ptr cinfo)
  148719. {
  148720. int ci;
  148721. #ifdef C_MULTISCAN_FILES_SUPPORTED
  148722. if (cinfo->scan_info != NULL) {
  148723. my_master_ptr master = (my_master_ptr) cinfo->master;
  148724. const jpeg_scan_info * scanptr = cinfo->scan_info + master->scan_number;
  148725. cinfo->comps_in_scan = scanptr->comps_in_scan;
  148726. for (ci = 0; ci < scanptr->comps_in_scan; ci++) {
  148727. cinfo->cur_comp_info[ci] =
  148728. &cinfo->comp_info[scanptr->component_index[ci]];
  148729. }
  148730. cinfo->Ss = scanptr->Ss;
  148731. cinfo->Se = scanptr->Se;
  148732. cinfo->Ah = scanptr->Ah;
  148733. cinfo->Al = scanptr->Al;
  148734. }
  148735. else
  148736. #endif
  148737. {
  148738. if (cinfo->num_components > MAX_COMPS_IN_SCAN)
  148739. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  148740. MAX_COMPS_IN_SCAN);
  148741. cinfo->comps_in_scan = cinfo->num_components;
  148742. for (ci = 0; ci < cinfo->num_components; ci++) {
  148743. cinfo->cur_comp_info[ci] = &cinfo->comp_info[ci];
  148744. }
  148745. cinfo->Ss = 0;
  148746. cinfo->Se = DCTSIZE2-1;
  148747. cinfo->Ah = 0;
  148748. cinfo->Al = 0;
  148749. }
  148750. }
  148751. LOCAL(void)
  148752. per_scan_setup (j_compress_ptr cinfo)
  148753. {
  148754. int ci, mcublks, tmp;
  148755. jpeg_component_info *compptr;
  148756. if (cinfo->comps_in_scan == 1) {
  148757. compptr = cinfo->cur_comp_info[0];
  148758. cinfo->MCUs_per_row = compptr->width_in_blocks;
  148759. cinfo->MCU_rows_in_scan = compptr->height_in_blocks;
  148760. compptr->MCU_width = 1;
  148761. compptr->MCU_height = 1;
  148762. compptr->MCU_blocks = 1;
  148763. compptr->MCU_sample_width = DCTSIZE;
  148764. compptr->last_col_width = 1;
  148765. tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  148766. if (tmp == 0) tmp = compptr->v_samp_factor;
  148767. compptr->last_row_height = tmp;
  148768. cinfo->blocks_in_MCU = 1;
  148769. cinfo->MCU_membership[0] = 0;
  148770. } else {
  148771. if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
  148772. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
  148773. MAX_COMPS_IN_SCAN);
  148774. cinfo->MCUs_per_row = (JDIMENSION)
  148775. jdiv_round_up((long) cinfo->image_width,
  148776. (long) (cinfo->max_h_samp_factor*DCTSIZE));
  148777. cinfo->MCU_rows_in_scan = (JDIMENSION)
  148778. jdiv_round_up((long) cinfo->image_height,
  148779. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  148780. cinfo->blocks_in_MCU = 0;
  148781. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  148782. compptr = cinfo->cur_comp_info[ci];
  148783. compptr->MCU_width = compptr->h_samp_factor;
  148784. compptr->MCU_height = compptr->v_samp_factor;
  148785. compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
  148786. compptr->MCU_sample_width = compptr->MCU_width * DCTSIZE;
  148787. tmp = (int) (compptr->width_in_blocks % compptr->MCU_width);
  148788. if (tmp == 0) tmp = compptr->MCU_width;
  148789. compptr->last_col_width = tmp;
  148790. tmp = (int) (compptr->height_in_blocks % compptr->MCU_height);
  148791. if (tmp == 0) tmp = compptr->MCU_height;
  148792. compptr->last_row_height = tmp;
  148793. mcublks = compptr->MCU_blocks;
  148794. if (cinfo->blocks_in_MCU + mcublks > C_MAX_BLOCKS_IN_MCU)
  148795. ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
  148796. while (mcublks-- > 0) {
  148797. cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
  148798. }
  148799. }
  148800. }
  148801. if (cinfo->restart_in_rows > 0) {
  148802. long nominal = (long) cinfo->restart_in_rows * (long) cinfo->MCUs_per_row;
  148803. cinfo->restart_interval = (unsigned int) MIN(nominal, 65535L);
  148804. }
  148805. }
  148806. METHODDEF(void)
  148807. prepare_for_pass (j_compress_ptr cinfo)
  148808. {
  148809. my_master_ptr master = (my_master_ptr) cinfo->master;
  148810. switch (master->pass_type) {
  148811. case main_pass:
  148812. select_scan_parameters(cinfo);
  148813. per_scan_setup(cinfo);
  148814. if (! cinfo->raw_data_in) {
  148815. (*cinfo->cconvert->start_pass) (cinfo);
  148816. (*cinfo->downsample->start_pass) (cinfo);
  148817. (*cinfo->prep->start_pass) (cinfo, JBUF_PASS_THRU);
  148818. }
  148819. (*cinfo->fdct->start_pass) (cinfo);
  148820. (*cinfo->entropy->start_pass) (cinfo, cinfo->optimize_coding);
  148821. (*cinfo->coef->start_pass) (cinfo,
  148822. (master->total_passes > 1 ?
  148823. JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
  148824. (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
  148825. if (cinfo->optimize_coding) {
  148826. master->pub.call_pass_startup = FALSE;
  148827. } else {
  148828. master->pub.call_pass_startup = TRUE;
  148829. }
  148830. break;
  148831. #ifdef ENTROPY_OPT_SUPPORTED
  148832. case huff_opt_pass:
  148833. select_scan_parameters(cinfo);
  148834. per_scan_setup(cinfo);
  148835. if (cinfo->Ss != 0 || cinfo->Ah == 0 || cinfo->arith_code) {
  148836. (*cinfo->entropy->start_pass) (cinfo, TRUE);
  148837. (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST);
  148838. master->pub.call_pass_startup = FALSE;
  148839. break;
  148840. }
  148841. master->pass_type = output_pass;
  148842. master->pass_number++;
  148843. #endif
  148844. case output_pass:
  148845. if (! cinfo->optimize_coding) {
  148846. select_scan_parameters(cinfo);
  148847. per_scan_setup(cinfo);
  148848. }
  148849. (*cinfo->entropy->start_pass) (cinfo, FALSE);
  148850. (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST);
  148851. if (master->scan_number == 0)
  148852. (*cinfo->marker->write_frame_header) (cinfo);
  148853. (*cinfo->marker->write_scan_header) (cinfo);
  148854. master->pub.call_pass_startup = FALSE;
  148855. break;
  148856. default:
  148857. ERREXIT(cinfo, JERR_NOT_COMPILED);
  148858. }
  148859. master->pub.is_last_pass = (master->pass_number == master->total_passes-1);
  148860. if (cinfo->progress != NULL) {
  148861. cinfo->progress->completed_passes = master->pass_number;
  148862. cinfo->progress->total_passes = master->total_passes;
  148863. }
  148864. }
  148865. METHODDEF(void)
  148866. pass_startup (j_compress_ptr cinfo)
  148867. {
  148868. cinfo->master->call_pass_startup = FALSE; /* reset flag so call only once */
  148869. (*cinfo->marker->write_frame_header) (cinfo);
  148870. (*cinfo->marker->write_scan_header) (cinfo);
  148871. }
  148872. METHODDEF(void)
  148873. finish_pass_master (j_compress_ptr cinfo)
  148874. {
  148875. my_master_ptr master = (my_master_ptr) cinfo->master;
  148876. (*cinfo->entropy->finish_pass) (cinfo);
  148877. switch (master->pass_type) {
  148878. case main_pass:
  148879. master->pass_type = output_pass;
  148880. if (! cinfo->optimize_coding)
  148881. master->scan_number++;
  148882. break;
  148883. case huff_opt_pass:
  148884. master->pass_type = output_pass;
  148885. break;
  148886. case output_pass:
  148887. if (cinfo->optimize_coding)
  148888. master->pass_type = huff_opt_pass;
  148889. master->scan_number++;
  148890. break;
  148891. }
  148892. master->pass_number++;
  148893. }
  148894. GLOBAL(void)
  148895. jinit_c_master_control (j_compress_ptr cinfo, boolean transcode_only)
  148896. {
  148897. my_master_ptr master;
  148898. master = (my_master_ptr)
  148899. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148900. SIZEOF(my_comp_master));
  148901. cinfo->master = (struct jpeg_comp_master *) master;
  148902. master->pub.prepare_for_pass = prepare_for_pass;
  148903. master->pub.pass_startup = pass_startup;
  148904. master->pub.finish_pass = finish_pass_master;
  148905. master->pub.is_last_pass = FALSE;
  148906. initial_setup(cinfo);
  148907. if (cinfo->scan_info != NULL) {
  148908. #ifdef C_MULTISCAN_FILES_SUPPORTED
  148909. validate_script(cinfo);
  148910. #else
  148911. ERREXIT(cinfo, JERR_NOT_COMPILED);
  148912. #endif
  148913. } else {
  148914. cinfo->progressive_mode = FALSE;
  148915. cinfo->num_scans = 1;
  148916. }
  148917. if (cinfo->progressive_mode) /* TEMPORARY HACK ??? */
  148918. cinfo->optimize_coding = TRUE; /* assume default tables no good for progressive mode */
  148919. if (transcode_only) {
  148920. if (cinfo->optimize_coding)
  148921. master->pass_type = huff_opt_pass;
  148922. else
  148923. master->pass_type = output_pass;
  148924. } else {
  148925. master->pass_type = main_pass;
  148926. }
  148927. master->scan_number = 0;
  148928. master->pass_number = 0;
  148929. if (cinfo->optimize_coding)
  148930. master->total_passes = cinfo->num_scans * 2;
  148931. else
  148932. master->total_passes = cinfo->num_scans;
  148933. }
  148934. /*** End of inlined file: jcmaster.c ***/
  148935. /*** Start of inlined file: jcomapi.c ***/
  148936. #define JPEG_INTERNALS
  148937. GLOBAL(void)
  148938. jpeg_abort (j_common_ptr cinfo)
  148939. {
  148940. int pool;
  148941. if (cinfo->mem == NULL)
  148942. return;
  148943. for (pool = JPOOL_NUMPOOLS-1; pool > JPOOL_PERMANENT; pool--) {
  148944. (*cinfo->mem->free_pool) (cinfo, pool);
  148945. }
  148946. if (cinfo->is_decompressor) {
  148947. cinfo->global_state = DSTATE_START;
  148948. ((j_decompress_ptr) cinfo)->marker_list = NULL;
  148949. } else {
  148950. cinfo->global_state = CSTATE_START;
  148951. }
  148952. }
  148953. GLOBAL(void)
  148954. jpeg_destroy (j_common_ptr cinfo)
  148955. {
  148956. if (cinfo->mem != NULL)
  148957. (*cinfo->mem->self_destruct) (cinfo);
  148958. cinfo->mem = NULL; /* be safe if jpeg_destroy is called twice */
  148959. cinfo->global_state = 0; /* mark it destroyed */
  148960. }
  148961. GLOBAL(JQUANT_TBL *)
  148962. jpeg_alloc_quant_table (j_common_ptr cinfo)
  148963. {
  148964. JQUANT_TBL *tbl;
  148965. tbl = (JQUANT_TBL *)
  148966. (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JQUANT_TBL));
  148967. tbl->sent_table = FALSE; /* make sure this is false in any new table */
  148968. return tbl;
  148969. }
  148970. GLOBAL(JHUFF_TBL *)
  148971. jpeg_alloc_huff_table (j_common_ptr cinfo)
  148972. {
  148973. JHUFF_TBL *tbl;
  148974. tbl = (JHUFF_TBL *)
  148975. (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JHUFF_TBL));
  148976. tbl->sent_table = FALSE; /* make sure this is false in any new table */
  148977. return tbl;
  148978. }
  148979. /*** End of inlined file: jcomapi.c ***/
  148980. /*** Start of inlined file: jcparam.c ***/
  148981. #define JPEG_INTERNALS
  148982. GLOBAL(void)
  148983. jpeg_add_quant_table (j_compress_ptr cinfo, int which_tbl,
  148984. const unsigned int *basic_table,
  148985. int scale_factor, boolean force_baseline)
  148986. {
  148987. JQUANT_TBL ** qtblptr;
  148988. int i;
  148989. long temp;
  148990. if (cinfo->global_state != CSTATE_START)
  148991. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  148992. if (which_tbl < 0 || which_tbl >= NUM_QUANT_TBLS)
  148993. ERREXIT1(cinfo, JERR_DQT_INDEX, which_tbl);
  148994. qtblptr = & cinfo->quant_tbl_ptrs[which_tbl];
  148995. if (*qtblptr == NULL)
  148996. *qtblptr = jpeg_alloc_quant_table((j_common_ptr) cinfo);
  148997. for (i = 0; i < DCTSIZE2; i++) {
  148998. temp = ((long) basic_table[i] * scale_factor + 50L) / 100L;
  148999. if (temp <= 0L) temp = 1L;
  149000. if (temp > 32767L) temp = 32767L; /* max quantizer needed for 12 bits */
  149001. if (force_baseline && temp > 255L)
  149002. temp = 255L; /* limit to baseline range if requested */
  149003. (*qtblptr)->quantval[i] = (UINT16) temp;
  149004. }
  149005. (*qtblptr)->sent_table = FALSE;
  149006. }
  149007. GLOBAL(void)
  149008. jpeg_set_linear_quality (j_compress_ptr cinfo, int scale_factor,
  149009. boolean force_baseline)
  149010. {
  149011. static const unsigned int std_luminance_quant_tbl[DCTSIZE2] = {
  149012. 16, 11, 10, 16, 24, 40, 51, 61,
  149013. 12, 12, 14, 19, 26, 58, 60, 55,
  149014. 14, 13, 16, 24, 40, 57, 69, 56,
  149015. 14, 17, 22, 29, 51, 87, 80, 62,
  149016. 18, 22, 37, 56, 68, 109, 103, 77,
  149017. 24, 35, 55, 64, 81, 104, 113, 92,
  149018. 49, 64, 78, 87, 103, 121, 120, 101,
  149019. 72, 92, 95, 98, 112, 100, 103, 99
  149020. };
  149021. static const unsigned int std_chrominance_quant_tbl[DCTSIZE2] = {
  149022. 17, 18, 24, 47, 99, 99, 99, 99,
  149023. 18, 21, 26, 66, 99, 99, 99, 99,
  149024. 24, 26, 56, 99, 99, 99, 99, 99,
  149025. 47, 66, 99, 99, 99, 99, 99, 99,
  149026. 99, 99, 99, 99, 99, 99, 99, 99,
  149027. 99, 99, 99, 99, 99, 99, 99, 99,
  149028. 99, 99, 99, 99, 99, 99, 99, 99,
  149029. 99, 99, 99, 99, 99, 99, 99, 99
  149030. };
  149031. jpeg_add_quant_table(cinfo, 0, std_luminance_quant_tbl,
  149032. scale_factor, force_baseline);
  149033. jpeg_add_quant_table(cinfo, 1, std_chrominance_quant_tbl,
  149034. scale_factor, force_baseline);
  149035. }
  149036. GLOBAL(int)
  149037. jpeg_quality_scaling (int quality)
  149038. {
  149039. if (quality <= 0) quality = 1;
  149040. if (quality > 100) quality = 100;
  149041. if (quality < 50)
  149042. quality = 5000 / quality;
  149043. else
  149044. quality = 200 - quality*2;
  149045. return quality;
  149046. }
  149047. GLOBAL(void)
  149048. jpeg_set_quality (j_compress_ptr cinfo, int quality, boolean force_baseline)
  149049. {
  149050. quality = jpeg_quality_scaling(quality);
  149051. jpeg_set_linear_quality(cinfo, quality, force_baseline);
  149052. }
  149053. LOCAL(void)
  149054. add_huff_table (j_compress_ptr cinfo,
  149055. JHUFF_TBL **htblptr, const UINT8 *bits, const UINT8 *val)
  149056. {
  149057. int nsymbols, len;
  149058. if (*htblptr == NULL)
  149059. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  149060. MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits));
  149061. nsymbols = 0;
  149062. for (len = 1; len <= 16; len++)
  149063. nsymbols += bits[len];
  149064. if (nsymbols < 1 || nsymbols > 256)
  149065. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  149066. MEMCOPY((*htblptr)->huffval, val, nsymbols * SIZEOF(UINT8));
  149067. (*htblptr)->sent_table = FALSE;
  149068. }
  149069. LOCAL(void)
  149070. std_huff_tables (j_compress_ptr cinfo)
  149071. {
  149072. static const UINT8 bits_dc_luminance[17] =
  149073. { /* 0-base */ 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 };
  149074. static const UINT8 val_dc_luminance[] =
  149075. { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
  149076. static const UINT8 bits_dc_chrominance[17] =
  149077. { /* 0-base */ 0, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 };
  149078. static const UINT8 val_dc_chrominance[] =
  149079. { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
  149080. static const UINT8 bits_ac_luminance[17] =
  149081. { /* 0-base */ 0, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d };
  149082. static const UINT8 val_ac_luminance[] =
  149083. { 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12,
  149084. 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07,
  149085. 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08,
  149086. 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0,
  149087. 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16,
  149088. 0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28,
  149089. 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
  149090. 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
  149091. 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,
  149092. 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
  149093. 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79,
  149094. 0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89,
  149095. 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98,
  149096. 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
  149097. 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6,
  149098. 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5,
  149099. 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4,
  149100. 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2,
  149101. 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea,
  149102. 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
  149103. 0xf9, 0xfa };
  149104. static const UINT8 bits_ac_chrominance[17] =
  149105. { /* 0-base */ 0, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77 };
  149106. static const UINT8 val_ac_chrominance[] =
  149107. { 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21,
  149108. 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71,
  149109. 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91,
  149110. 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0,
  149111. 0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34,
  149112. 0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26,
  149113. 0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38,
  149114. 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
  149115. 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
  149116. 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
  149117. 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
  149118. 0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
  149119. 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96,
  149120. 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5,
  149121. 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4,
  149122. 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3,
  149123. 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2,
  149124. 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda,
  149125. 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9,
  149126. 0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
  149127. 0xf9, 0xfa };
  149128. add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[0],
  149129. bits_dc_luminance, val_dc_luminance);
  149130. add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[0],
  149131. bits_ac_luminance, val_ac_luminance);
  149132. add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[1],
  149133. bits_dc_chrominance, val_dc_chrominance);
  149134. add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[1],
  149135. bits_ac_chrominance, val_ac_chrominance);
  149136. }
  149137. GLOBAL(void)
  149138. jpeg_set_defaults (j_compress_ptr cinfo)
  149139. {
  149140. int i;
  149141. if (cinfo->global_state != CSTATE_START)
  149142. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  149143. if (cinfo->comp_info == NULL)
  149144. cinfo->comp_info = (jpeg_component_info *)
  149145. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  149146. MAX_COMPONENTS * SIZEOF(jpeg_component_info));
  149147. cinfo->data_precision = BITS_IN_JSAMPLE;
  149148. jpeg_set_quality(cinfo, 75, TRUE);
  149149. std_huff_tables(cinfo);
  149150. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  149151. cinfo->arith_dc_L[i] = 0;
  149152. cinfo->arith_dc_U[i] = 1;
  149153. cinfo->arith_ac_K[i] = 5;
  149154. }
  149155. cinfo->scan_info = NULL;
  149156. cinfo->num_scans = 0;
  149157. cinfo->raw_data_in = FALSE;
  149158. cinfo->arith_code = FALSE;
  149159. cinfo->optimize_coding = FALSE;
  149160. if (cinfo->data_precision > 8)
  149161. cinfo->optimize_coding = TRUE;
  149162. cinfo->CCIR601_sampling = FALSE;
  149163. cinfo->smoothing_factor = 0;
  149164. cinfo->dct_method = JDCT_DEFAULT;
  149165. cinfo->restart_interval = 0;
  149166. cinfo->restart_in_rows = 0;
  149167. cinfo->JFIF_major_version = 1; /* Default JFIF version = 1.01 */
  149168. cinfo->JFIF_minor_version = 1;
  149169. cinfo->density_unit = 0; /* Pixel size is unknown by default */
  149170. cinfo->X_density = 1; /* Pixel aspect ratio is square by default */
  149171. cinfo->Y_density = 1;
  149172. jpeg_default_colorspace(cinfo);
  149173. }
  149174. GLOBAL(void)
  149175. jpeg_default_colorspace (j_compress_ptr cinfo)
  149176. {
  149177. switch (cinfo->in_color_space) {
  149178. case JCS_GRAYSCALE:
  149179. jpeg_set_colorspace(cinfo, JCS_GRAYSCALE);
  149180. break;
  149181. case JCS_RGB:
  149182. jpeg_set_colorspace(cinfo, JCS_YCbCr);
  149183. break;
  149184. case JCS_YCbCr:
  149185. jpeg_set_colorspace(cinfo, JCS_YCbCr);
  149186. break;
  149187. case JCS_CMYK:
  149188. jpeg_set_colorspace(cinfo, JCS_CMYK); /* By default, no translation */
  149189. break;
  149190. case JCS_YCCK:
  149191. jpeg_set_colorspace(cinfo, JCS_YCCK);
  149192. break;
  149193. case JCS_UNKNOWN:
  149194. jpeg_set_colorspace(cinfo, JCS_UNKNOWN);
  149195. break;
  149196. default:
  149197. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  149198. }
  149199. }
  149200. GLOBAL(void)
  149201. jpeg_set_colorspace (j_compress_ptr cinfo, J_COLOR_SPACE colorspace)
  149202. {
  149203. jpeg_component_info * compptr;
  149204. int ci;
  149205. #define SET_COMP(index,id,hsamp,vsamp,quant,dctbl,actbl) \
  149206. (compptr = &cinfo->comp_info[index], \
  149207. compptr->component_id = (id), \
  149208. compptr->h_samp_factor = (hsamp), \
  149209. compptr->v_samp_factor = (vsamp), \
  149210. compptr->quant_tbl_no = (quant), \
  149211. compptr->dc_tbl_no = (dctbl), \
  149212. compptr->ac_tbl_no = (actbl) )
  149213. if (cinfo->global_state != CSTATE_START)
  149214. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  149215. cinfo->jpeg_color_space = colorspace;
  149216. cinfo->write_JFIF_header = FALSE; /* No marker for non-JFIF colorspaces */
  149217. cinfo->write_Adobe_marker = FALSE; /* write no Adobe marker by default */
  149218. switch (colorspace) {
  149219. case JCS_GRAYSCALE:
  149220. cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
  149221. cinfo->num_components = 1;
  149222. SET_COMP(0, 1, 1,1, 0, 0,0);
  149223. break;
  149224. case JCS_RGB:
  149225. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag RGB */
  149226. cinfo->num_components = 3;
  149227. SET_COMP(0, 0x52 /* 'R' */, 1,1, 0, 0,0);
  149228. SET_COMP(1, 0x47 /* 'G' */, 1,1, 0, 0,0);
  149229. SET_COMP(2, 0x42 /* 'B' */, 1,1, 0, 0,0);
  149230. break;
  149231. case JCS_YCbCr:
  149232. cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
  149233. cinfo->num_components = 3;
  149234. SET_COMP(0, 1, 2,2, 0, 0,0);
  149235. SET_COMP(1, 2, 1,1, 1, 1,1);
  149236. SET_COMP(2, 3, 1,1, 1, 1,1);
  149237. break;
  149238. case JCS_CMYK:
  149239. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag CMYK */
  149240. cinfo->num_components = 4;
  149241. SET_COMP(0, 0x43 /* 'C' */, 1,1, 0, 0,0);
  149242. SET_COMP(1, 0x4D /* 'M' */, 1,1, 0, 0,0);
  149243. SET_COMP(2, 0x59 /* 'Y' */, 1,1, 0, 0,0);
  149244. SET_COMP(3, 0x4B /* 'K' */, 1,1, 0, 0,0);
  149245. break;
  149246. case JCS_YCCK:
  149247. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag YCCK */
  149248. cinfo->num_components = 4;
  149249. SET_COMP(0, 1, 2,2, 0, 0,0);
  149250. SET_COMP(1, 2, 1,1, 1, 1,1);
  149251. SET_COMP(2, 3, 1,1, 1, 1,1);
  149252. SET_COMP(3, 4, 2,2, 0, 0,0);
  149253. break;
  149254. case JCS_UNKNOWN:
  149255. cinfo->num_components = cinfo->input_components;
  149256. if (cinfo->num_components < 1 || cinfo->num_components > MAX_COMPONENTS)
  149257. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  149258. MAX_COMPONENTS);
  149259. for (ci = 0; ci < cinfo->num_components; ci++) {
  149260. SET_COMP(ci, ci, 1,1, 0, 0,0);
  149261. }
  149262. break;
  149263. default:
  149264. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  149265. }
  149266. }
  149267. #ifdef C_PROGRESSIVE_SUPPORTED
  149268. LOCAL(jpeg_scan_info *)
  149269. fill_a_scan (jpeg_scan_info * scanptr, int ci,
  149270. int Ss, int Se, int Ah, int Al)
  149271. {
  149272. scanptr->comps_in_scan = 1;
  149273. scanptr->component_index[0] = ci;
  149274. scanptr->Ss = Ss;
  149275. scanptr->Se = Se;
  149276. scanptr->Ah = Ah;
  149277. scanptr->Al = Al;
  149278. scanptr++;
  149279. return scanptr;
  149280. }
  149281. LOCAL(jpeg_scan_info *)
  149282. fill_scans (jpeg_scan_info * scanptr, int ncomps,
  149283. int Ss, int Se, int Ah, int Al)
  149284. {
  149285. int ci;
  149286. for (ci = 0; ci < ncomps; ci++) {
  149287. scanptr->comps_in_scan = 1;
  149288. scanptr->component_index[0] = ci;
  149289. scanptr->Ss = Ss;
  149290. scanptr->Se = Se;
  149291. scanptr->Ah = Ah;
  149292. scanptr->Al = Al;
  149293. scanptr++;
  149294. }
  149295. return scanptr;
  149296. }
  149297. LOCAL(jpeg_scan_info *)
  149298. fill_dc_scans (jpeg_scan_info * scanptr, int ncomps, int Ah, int Al)
  149299. {
  149300. int ci;
  149301. if (ncomps <= MAX_COMPS_IN_SCAN) {
  149302. scanptr->comps_in_scan = ncomps;
  149303. for (ci = 0; ci < ncomps; ci++)
  149304. scanptr->component_index[ci] = ci;
  149305. scanptr->Ss = scanptr->Se = 0;
  149306. scanptr->Ah = Ah;
  149307. scanptr->Al = Al;
  149308. scanptr++;
  149309. } else {
  149310. scanptr = fill_scans(scanptr, ncomps, 0, 0, Ah, Al);
  149311. }
  149312. return scanptr;
  149313. }
  149314. GLOBAL(void)
  149315. jpeg_simple_progression (j_compress_ptr cinfo)
  149316. {
  149317. int ncomps = cinfo->num_components;
  149318. int nscans;
  149319. jpeg_scan_info * scanptr;
  149320. if (cinfo->global_state != CSTATE_START)
  149321. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  149322. if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
  149323. nscans = 10;
  149324. } else {
  149325. if (ncomps > MAX_COMPS_IN_SCAN)
  149326. nscans = 6 * ncomps; /* 2 DC + 4 AC scans per component */
  149327. else
  149328. nscans = 2 + 4 * ncomps; /* 2 DC scans; 4 AC scans per component */
  149329. }
  149330. if (cinfo->script_space == NULL || cinfo->script_space_size < nscans) {
  149331. cinfo->script_space_size = MAX(nscans, 10);
  149332. cinfo->script_space = (jpeg_scan_info *)
  149333. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  149334. cinfo->script_space_size * SIZEOF(jpeg_scan_info));
  149335. }
  149336. scanptr = cinfo->script_space;
  149337. cinfo->scan_info = scanptr;
  149338. cinfo->num_scans = nscans;
  149339. if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
  149340. scanptr = fill_dc_scans(scanptr, ncomps, 0, 1);
  149341. scanptr = fill_a_scan(scanptr, 0, 1, 5, 0, 2);
  149342. scanptr = fill_a_scan(scanptr, 2, 1, 63, 0, 1);
  149343. scanptr = fill_a_scan(scanptr, 1, 1, 63, 0, 1);
  149344. scanptr = fill_a_scan(scanptr, 0, 6, 63, 0, 2);
  149345. scanptr = fill_a_scan(scanptr, 0, 1, 63, 2, 1);
  149346. scanptr = fill_dc_scans(scanptr, ncomps, 1, 0);
  149347. scanptr = fill_a_scan(scanptr, 2, 1, 63, 1, 0);
  149348. scanptr = fill_a_scan(scanptr, 1, 1, 63, 1, 0);
  149349. scanptr = fill_a_scan(scanptr, 0, 1, 63, 1, 0);
  149350. } else {
  149351. scanptr = fill_dc_scans(scanptr, ncomps, 0, 1);
  149352. scanptr = fill_scans(scanptr, ncomps, 1, 5, 0, 2);
  149353. scanptr = fill_scans(scanptr, ncomps, 6, 63, 0, 2);
  149354. scanptr = fill_scans(scanptr, ncomps, 1, 63, 2, 1);
  149355. scanptr = fill_dc_scans(scanptr, ncomps, 1, 0);
  149356. scanptr = fill_scans(scanptr, ncomps, 1, 63, 1, 0);
  149357. }
  149358. }
  149359. #endif /* C_PROGRESSIVE_SUPPORTED */
  149360. /*** End of inlined file: jcparam.c ***/
  149361. /*** Start of inlined file: jcphuff.c ***/
  149362. #define JPEG_INTERNALS
  149363. #ifdef C_PROGRESSIVE_SUPPORTED
  149364. typedef struct {
  149365. struct jpeg_entropy_encoder pub; /* public fields */
  149366. boolean gather_statistics;
  149367. JOCTET * next_output_byte; /* => next byte to write in buffer */
  149368. size_t free_in_buffer; /* # of byte spaces remaining in buffer */
  149369. INT32 put_buffer; /* current bit-accumulation buffer */
  149370. int put_bits; /* # of bits now in it */
  149371. j_compress_ptr cinfo; /* link to cinfo (needed for dump_buffer) */
  149372. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  149373. int ac_tbl_no; /* the table number of the single component */
  149374. unsigned int EOBRUN; /* run length of EOBs */
  149375. unsigned int BE; /* # of buffered correction bits before MCU */
  149376. char * bit_buffer; /* buffer for correction bits (1 per char) */
  149377. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  149378. int next_restart_num; /* next restart number to write (0-7) */
  149379. c_derived_tbl * derived_tbls[NUM_HUFF_TBLS];
  149380. long * count_ptrs[NUM_HUFF_TBLS];
  149381. } phuff_entropy_encoder;
  149382. typedef phuff_entropy_encoder * phuff_entropy_ptr;
  149383. #define MAX_CORR_BITS 1000 /* Max # of correction bits I can buffer */
  149384. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  149385. #define ISHIFT_TEMPS int ishift_temp;
  149386. #define IRIGHT_SHIFT(x,shft) \
  149387. ((ishift_temp = (x)) < 0 ? \
  149388. (ishift_temp >> (shft)) | ((~0) << (16-(shft))) : \
  149389. (ishift_temp >> (shft)))
  149390. #else
  149391. #define ISHIFT_TEMPS
  149392. #define IRIGHT_SHIFT(x,shft) ((x) >> (shft))
  149393. #endif
  149394. METHODDEF(boolean) encode_mcu_DC_first JPP((j_compress_ptr cinfo,
  149395. JBLOCKROW *MCU_data));
  149396. METHODDEF(boolean) encode_mcu_AC_first JPP((j_compress_ptr cinfo,
  149397. JBLOCKROW *MCU_data));
  149398. METHODDEF(boolean) encode_mcu_DC_refine JPP((j_compress_ptr cinfo,
  149399. JBLOCKROW *MCU_data));
  149400. METHODDEF(boolean) encode_mcu_AC_refine JPP((j_compress_ptr cinfo,
  149401. JBLOCKROW *MCU_data));
  149402. METHODDEF(void) finish_pass_phuff JPP((j_compress_ptr cinfo));
  149403. METHODDEF(void) finish_pass_gather_phuff JPP((j_compress_ptr cinfo));
  149404. METHODDEF(void)
  149405. start_pass_phuff (j_compress_ptr cinfo, boolean gather_statistics)
  149406. {
  149407. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149408. boolean is_DC_band;
  149409. int ci, tbl;
  149410. jpeg_component_info * compptr;
  149411. entropy->cinfo = cinfo;
  149412. entropy->gather_statistics = gather_statistics;
  149413. is_DC_band = (cinfo->Ss == 0);
  149414. if (cinfo->Ah == 0) {
  149415. if (is_DC_band)
  149416. entropy->pub.encode_mcu = encode_mcu_DC_first;
  149417. else
  149418. entropy->pub.encode_mcu = encode_mcu_AC_first;
  149419. } else {
  149420. if (is_DC_band)
  149421. entropy->pub.encode_mcu = encode_mcu_DC_refine;
  149422. else {
  149423. entropy->pub.encode_mcu = encode_mcu_AC_refine;
  149424. if (entropy->bit_buffer == NULL)
  149425. entropy->bit_buffer = (char *)
  149426. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149427. MAX_CORR_BITS * SIZEOF(char));
  149428. }
  149429. }
  149430. if (gather_statistics)
  149431. entropy->pub.finish_pass = finish_pass_gather_phuff;
  149432. else
  149433. entropy->pub.finish_pass = finish_pass_phuff;
  149434. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  149435. compptr = cinfo->cur_comp_info[ci];
  149436. entropy->last_dc_val[ci] = 0;
  149437. if (is_DC_band) {
  149438. if (cinfo->Ah != 0) /* DC refinement needs no table */
  149439. continue;
  149440. tbl = compptr->dc_tbl_no;
  149441. } else {
  149442. entropy->ac_tbl_no = tbl = compptr->ac_tbl_no;
  149443. }
  149444. if (gather_statistics) {
  149445. if (tbl < 0 || tbl >= NUM_HUFF_TBLS)
  149446. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tbl);
  149447. if (entropy->count_ptrs[tbl] == NULL)
  149448. entropy->count_ptrs[tbl] = (long *)
  149449. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149450. 257 * SIZEOF(long));
  149451. MEMZERO(entropy->count_ptrs[tbl], 257 * SIZEOF(long));
  149452. } else {
  149453. jpeg_make_c_derived_tbl(cinfo, is_DC_band, tbl,
  149454. & entropy->derived_tbls[tbl]);
  149455. }
  149456. }
  149457. entropy->EOBRUN = 0;
  149458. entropy->BE = 0;
  149459. entropy->put_buffer = 0;
  149460. entropy->put_bits = 0;
  149461. entropy->restarts_to_go = cinfo->restart_interval;
  149462. entropy->next_restart_num = 0;
  149463. }
  149464. #define emit_byte(entropy,val) \
  149465. { *(entropy)->next_output_byte++ = (JOCTET) (val); \
  149466. if (--(entropy)->free_in_buffer == 0) \
  149467. dump_buffer_p(entropy); }
  149468. LOCAL(void)
  149469. dump_buffer_p (phuff_entropy_ptr entropy)
  149470. {
  149471. struct jpeg_destination_mgr * dest = entropy->cinfo->dest;
  149472. if (! (*dest->empty_output_buffer) (entropy->cinfo))
  149473. ERREXIT(entropy->cinfo, JERR_CANT_SUSPEND);
  149474. entropy->next_output_byte = dest->next_output_byte;
  149475. entropy->free_in_buffer = dest->free_in_buffer;
  149476. }
  149477. INLINE
  149478. LOCAL(void)
  149479. emit_bits_p (phuff_entropy_ptr entropy, unsigned int code, int size)
  149480. {
  149481. register INT32 put_buffer = (INT32) code;
  149482. register int put_bits = entropy->put_bits;
  149483. if (size == 0)
  149484. ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);
  149485. if (entropy->gather_statistics)
  149486. return; /* do nothing if we're only getting stats */
  149487. put_buffer &= (((INT32) 1)<<size) - 1; /* mask off any extra bits in code */
  149488. put_bits += size; /* new number of bits in buffer */
  149489. put_buffer <<= 24 - put_bits; /* align incoming bits */
  149490. put_buffer |= entropy->put_buffer; /* and merge with old buffer contents */
  149491. while (put_bits >= 8) {
  149492. int c = (int) ((put_buffer >> 16) & 0xFF);
  149493. emit_byte(entropy, c);
  149494. if (c == 0xFF) { /* need to stuff a zero byte? */
  149495. emit_byte(entropy, 0);
  149496. }
  149497. put_buffer <<= 8;
  149498. put_bits -= 8;
  149499. }
  149500. entropy->put_buffer = put_buffer; /* update variables */
  149501. entropy->put_bits = put_bits;
  149502. }
  149503. LOCAL(void)
  149504. flush_bits_p (phuff_entropy_ptr entropy)
  149505. {
  149506. emit_bits_p(entropy, 0x7F, 7); /* fill any partial byte with ones */
  149507. entropy->put_buffer = 0; /* and reset bit-buffer to empty */
  149508. entropy->put_bits = 0;
  149509. }
  149510. INLINE
  149511. LOCAL(void)
  149512. emit_symbol (phuff_entropy_ptr entropy, int tbl_no, int symbol)
  149513. {
  149514. if (entropy->gather_statistics)
  149515. entropy->count_ptrs[tbl_no][symbol]++;
  149516. else {
  149517. c_derived_tbl * tbl = entropy->derived_tbls[tbl_no];
  149518. emit_bits_p(entropy, tbl->ehufco[symbol], tbl->ehufsi[symbol]);
  149519. }
  149520. }
  149521. LOCAL(void)
  149522. emit_buffered_bits (phuff_entropy_ptr entropy, char * bufstart,
  149523. unsigned int nbits)
  149524. {
  149525. if (entropy->gather_statistics)
  149526. return; /* no real work */
  149527. while (nbits > 0) {
  149528. emit_bits_p(entropy, (unsigned int) (*bufstart), 1);
  149529. bufstart++;
  149530. nbits--;
  149531. }
  149532. }
  149533. LOCAL(void)
  149534. emit_eobrun (phuff_entropy_ptr entropy)
  149535. {
  149536. register int temp, nbits;
  149537. if (entropy->EOBRUN > 0) { /* if there is any pending EOBRUN */
  149538. temp = entropy->EOBRUN;
  149539. nbits = 0;
  149540. while ((temp >>= 1))
  149541. nbits++;
  149542. if (nbits > 14)
  149543. ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);
  149544. emit_symbol(entropy, entropy->ac_tbl_no, nbits << 4);
  149545. if (nbits)
  149546. emit_bits_p(entropy, entropy->EOBRUN, nbits);
  149547. entropy->EOBRUN = 0;
  149548. emit_buffered_bits(entropy, entropy->bit_buffer, entropy->BE);
  149549. entropy->BE = 0;
  149550. }
  149551. }
  149552. LOCAL(void)
  149553. emit_restart_p (phuff_entropy_ptr entropy, int restart_num)
  149554. {
  149555. int ci;
  149556. emit_eobrun(entropy);
  149557. if (! entropy->gather_statistics) {
  149558. flush_bits_p(entropy);
  149559. emit_byte(entropy, 0xFF);
  149560. emit_byte(entropy, JPEG_RST0 + restart_num);
  149561. }
  149562. if (entropy->cinfo->Ss == 0) {
  149563. for (ci = 0; ci < entropy->cinfo->comps_in_scan; ci++)
  149564. entropy->last_dc_val[ci] = 0;
  149565. } else {
  149566. entropy->EOBRUN = 0;
  149567. entropy->BE = 0;
  149568. }
  149569. }
  149570. METHODDEF(boolean)
  149571. encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149572. {
  149573. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149574. register int temp, temp2;
  149575. register int nbits;
  149576. int blkn, ci;
  149577. int Al = cinfo->Al;
  149578. JBLOCKROW block;
  149579. jpeg_component_info * compptr;
  149580. ISHIFT_TEMPS
  149581. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149582. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149583. if (cinfo->restart_interval)
  149584. if (entropy->restarts_to_go == 0)
  149585. emit_restart_p(entropy, entropy->next_restart_num);
  149586. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  149587. block = MCU_data[blkn];
  149588. ci = cinfo->MCU_membership[blkn];
  149589. compptr = cinfo->cur_comp_info[ci];
  149590. temp2 = IRIGHT_SHIFT((int) ((*block)[0]), Al);
  149591. temp = temp2 - entropy->last_dc_val[ci];
  149592. entropy->last_dc_val[ci] = temp2;
  149593. temp2 = temp;
  149594. if (temp < 0) {
  149595. temp = -temp; /* temp is abs value of input */
  149596. temp2--;
  149597. }
  149598. nbits = 0;
  149599. while (temp) {
  149600. nbits++;
  149601. temp >>= 1;
  149602. }
  149603. if (nbits > MAX_COEF_BITS+1)
  149604. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  149605. emit_symbol(entropy, compptr->dc_tbl_no, nbits);
  149606. if (nbits) /* emit_bits rejects calls with size 0 */
  149607. emit_bits_p(entropy, (unsigned int) temp2, nbits);
  149608. }
  149609. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149610. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149611. if (cinfo->restart_interval) {
  149612. if (entropy->restarts_to_go == 0) {
  149613. entropy->restarts_to_go = cinfo->restart_interval;
  149614. entropy->next_restart_num++;
  149615. entropy->next_restart_num &= 7;
  149616. }
  149617. entropy->restarts_to_go--;
  149618. }
  149619. return TRUE;
  149620. }
  149621. METHODDEF(boolean)
  149622. encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149623. {
  149624. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149625. register int temp, temp2;
  149626. register int nbits;
  149627. register int r, k;
  149628. int Se = cinfo->Se;
  149629. int Al = cinfo->Al;
  149630. JBLOCKROW block;
  149631. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149632. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149633. if (cinfo->restart_interval)
  149634. if (entropy->restarts_to_go == 0)
  149635. emit_restart_p(entropy, entropy->next_restart_num);
  149636. block = MCU_data[0];
  149637. r = 0; /* r = run length of zeros */
  149638. for (k = cinfo->Ss; k <= Se; k++) {
  149639. if ((temp = (*block)[jpeg_natural_order[k]]) == 0) {
  149640. r++;
  149641. continue;
  149642. }
  149643. if (temp < 0) {
  149644. temp = -temp; /* temp is abs value of input */
  149645. temp >>= Al; /* apply the point transform */
  149646. temp2 = ~temp;
  149647. } else {
  149648. temp >>= Al; /* apply the point transform */
  149649. temp2 = temp;
  149650. }
  149651. if (temp == 0) {
  149652. r++;
  149653. continue;
  149654. }
  149655. if (entropy->EOBRUN > 0)
  149656. emit_eobrun(entropy);
  149657. while (r > 15) {
  149658. emit_symbol(entropy, entropy->ac_tbl_no, 0xF0);
  149659. r -= 16;
  149660. }
  149661. nbits = 1; /* there must be at least one 1 bit */
  149662. while ((temp >>= 1))
  149663. nbits++;
  149664. if (nbits > MAX_COEF_BITS)
  149665. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  149666. emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + nbits);
  149667. emit_bits_p(entropy, (unsigned int) temp2, nbits);
  149668. r = 0; /* reset zero run length */
  149669. }
  149670. if (r > 0) { /* If there are trailing zeroes, */
  149671. entropy->EOBRUN++; /* count an EOB */
  149672. if (entropy->EOBRUN == 0x7FFF)
  149673. emit_eobrun(entropy); /* force it out to avoid overflow */
  149674. }
  149675. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149676. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149677. if (cinfo->restart_interval) {
  149678. if (entropy->restarts_to_go == 0) {
  149679. entropy->restarts_to_go = cinfo->restart_interval;
  149680. entropy->next_restart_num++;
  149681. entropy->next_restart_num &= 7;
  149682. }
  149683. entropy->restarts_to_go--;
  149684. }
  149685. return TRUE;
  149686. }
  149687. METHODDEF(boolean)
  149688. encode_mcu_DC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149689. {
  149690. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149691. register int temp;
  149692. int blkn;
  149693. int Al = cinfo->Al;
  149694. JBLOCKROW block;
  149695. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149696. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149697. if (cinfo->restart_interval)
  149698. if (entropy->restarts_to_go == 0)
  149699. emit_restart_p(entropy, entropy->next_restart_num);
  149700. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  149701. block = MCU_data[blkn];
  149702. temp = (*block)[0];
  149703. emit_bits_p(entropy, (unsigned int) (temp >> Al), 1);
  149704. }
  149705. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149706. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149707. if (cinfo->restart_interval) {
  149708. if (entropy->restarts_to_go == 0) {
  149709. entropy->restarts_to_go = cinfo->restart_interval;
  149710. entropy->next_restart_num++;
  149711. entropy->next_restart_num &= 7;
  149712. }
  149713. entropy->restarts_to_go--;
  149714. }
  149715. return TRUE;
  149716. }
  149717. METHODDEF(boolean)
  149718. encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149719. {
  149720. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149721. register int temp;
  149722. register int r, k;
  149723. int EOB;
  149724. char *BR_buffer;
  149725. unsigned int BR;
  149726. int Se = cinfo->Se;
  149727. int Al = cinfo->Al;
  149728. JBLOCKROW block;
  149729. int absvalues[DCTSIZE2];
  149730. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149731. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149732. if (cinfo->restart_interval)
  149733. if (entropy->restarts_to_go == 0)
  149734. emit_restart_p(entropy, entropy->next_restart_num);
  149735. block = MCU_data[0];
  149736. EOB = 0;
  149737. for (k = cinfo->Ss; k <= Se; k++) {
  149738. temp = (*block)[jpeg_natural_order[k]];
  149739. if (temp < 0)
  149740. temp = -temp; /* temp is abs value of input */
  149741. temp >>= Al; /* apply the point transform */
  149742. absvalues[k] = temp; /* save abs value for main pass */
  149743. if (temp == 1)
  149744. EOB = k; /* EOB = index of last newly-nonzero coef */
  149745. }
  149746. r = 0; /* r = run length of zeros */
  149747. BR = 0; /* BR = count of buffered bits added now */
  149748. BR_buffer = entropy->bit_buffer + entropy->BE; /* Append bits to buffer */
  149749. for (k = cinfo->Ss; k <= Se; k++) {
  149750. if ((temp = absvalues[k]) == 0) {
  149751. r++;
  149752. continue;
  149753. }
  149754. while (r > 15 && k <= EOB) {
  149755. emit_eobrun(entropy);
  149756. emit_symbol(entropy, entropy->ac_tbl_no, 0xF0);
  149757. r -= 16;
  149758. emit_buffered_bits(entropy, BR_buffer, BR);
  149759. BR_buffer = entropy->bit_buffer; /* BE bits are gone now */
  149760. BR = 0;
  149761. }
  149762. if (temp > 1) {
  149763. BR_buffer[BR++] = (char) (temp & 1);
  149764. continue;
  149765. }
  149766. emit_eobrun(entropy);
  149767. emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + 1);
  149768. temp = ((*block)[jpeg_natural_order[k]] < 0) ? 0 : 1;
  149769. emit_bits_p(entropy, (unsigned int) temp, 1);
  149770. emit_buffered_bits(entropy, BR_buffer, BR);
  149771. BR_buffer = entropy->bit_buffer; /* BE bits are gone now */
  149772. BR = 0;
  149773. r = 0; /* reset zero run length */
  149774. }
  149775. if (r > 0 || BR > 0) { /* If there are trailing zeroes, */
  149776. entropy->EOBRUN++; /* count an EOB */
  149777. entropy->BE += BR; /* concat my correction bits to older ones */
  149778. if (entropy->EOBRUN == 0x7FFF || entropy->BE > (MAX_CORR_BITS-DCTSIZE2+1))
  149779. emit_eobrun(entropy);
  149780. }
  149781. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149782. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149783. if (cinfo->restart_interval) {
  149784. if (entropy->restarts_to_go == 0) {
  149785. entropy->restarts_to_go = cinfo->restart_interval;
  149786. entropy->next_restart_num++;
  149787. entropy->next_restart_num &= 7;
  149788. }
  149789. entropy->restarts_to_go--;
  149790. }
  149791. return TRUE;
  149792. }
  149793. METHODDEF(void)
  149794. finish_pass_phuff (j_compress_ptr cinfo)
  149795. {
  149796. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149797. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149798. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149799. emit_eobrun(entropy);
  149800. flush_bits_p(entropy);
  149801. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149802. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149803. }
  149804. METHODDEF(void)
  149805. finish_pass_gather_phuff (j_compress_ptr cinfo)
  149806. {
  149807. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149808. boolean is_DC_band;
  149809. int ci, tbl;
  149810. jpeg_component_info * compptr;
  149811. JHUFF_TBL **htblptr;
  149812. boolean did[NUM_HUFF_TBLS];
  149813. emit_eobrun(entropy);
  149814. is_DC_band = (cinfo->Ss == 0);
  149815. MEMZERO(did, SIZEOF(did));
  149816. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  149817. compptr = cinfo->cur_comp_info[ci];
  149818. if (is_DC_band) {
  149819. if (cinfo->Ah != 0) /* DC refinement needs no table */
  149820. continue;
  149821. tbl = compptr->dc_tbl_no;
  149822. } else {
  149823. tbl = compptr->ac_tbl_no;
  149824. }
  149825. if (! did[tbl]) {
  149826. if (is_DC_band)
  149827. htblptr = & cinfo->dc_huff_tbl_ptrs[tbl];
  149828. else
  149829. htblptr = & cinfo->ac_huff_tbl_ptrs[tbl];
  149830. if (*htblptr == NULL)
  149831. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  149832. jpeg_gen_optimal_table(cinfo, *htblptr, entropy->count_ptrs[tbl]);
  149833. did[tbl] = TRUE;
  149834. }
  149835. }
  149836. }
  149837. GLOBAL(void)
  149838. jinit_phuff_encoder (j_compress_ptr cinfo)
  149839. {
  149840. phuff_entropy_ptr entropy;
  149841. int i;
  149842. entropy = (phuff_entropy_ptr)
  149843. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149844. SIZEOF(phuff_entropy_encoder));
  149845. cinfo->entropy = (struct jpeg_entropy_encoder *) entropy;
  149846. entropy->pub.start_pass = start_pass_phuff;
  149847. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  149848. entropy->derived_tbls[i] = NULL;
  149849. entropy->count_ptrs[i] = NULL;
  149850. }
  149851. entropy->bit_buffer = NULL; /* needed only in AC refinement scan */
  149852. }
  149853. #endif /* C_PROGRESSIVE_SUPPORTED */
  149854. /*** End of inlined file: jcphuff.c ***/
  149855. /*** Start of inlined file: jcprepct.c ***/
  149856. #define JPEG_INTERNALS
  149857. #ifdef INPUT_SMOOTHING_SUPPORTED
  149858. #define CONTEXT_ROWS_SUPPORTED
  149859. #endif
  149860. typedef struct {
  149861. struct jpeg_c_prep_controller pub; /* public fields */
  149862. JSAMPARRAY color_buf[MAX_COMPONENTS];
  149863. JDIMENSION rows_to_go; /* counts rows remaining in source image */
  149864. int next_buf_row; /* index of next row to store in color_buf */
  149865. #ifdef CONTEXT_ROWS_SUPPORTED /* only needed for context case */
  149866. int this_row_group; /* starting row index of group to process */
  149867. int next_buf_stop; /* downsample when we reach this index */
  149868. #endif
  149869. } my_prep_controller;
  149870. typedef my_prep_controller * my_prep_ptr;
  149871. METHODDEF(void)
  149872. start_pass_prep (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  149873. {
  149874. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149875. if (pass_mode != JBUF_PASS_THRU)
  149876. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  149877. prep->rows_to_go = cinfo->image_height;
  149878. prep->next_buf_row = 0;
  149879. #ifdef CONTEXT_ROWS_SUPPORTED
  149880. prep->this_row_group = 0;
  149881. prep->next_buf_stop = 2 * cinfo->max_v_samp_factor;
  149882. #endif
  149883. }
  149884. LOCAL(void)
  149885. expand_bottom_edge (JSAMPARRAY image_data, JDIMENSION num_cols,
  149886. int input_rows, int output_rows)
  149887. {
  149888. register int row;
  149889. for (row = input_rows; row < output_rows; row++) {
  149890. jcopy_sample_rows(image_data, input_rows-1, image_data, row,
  149891. 1, num_cols);
  149892. }
  149893. }
  149894. METHODDEF(void)
  149895. pre_process_data (j_compress_ptr cinfo,
  149896. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  149897. JDIMENSION in_rows_avail,
  149898. JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
  149899. JDIMENSION out_row_groups_avail)
  149900. {
  149901. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149902. int numrows, ci;
  149903. JDIMENSION inrows;
  149904. jpeg_component_info * compptr;
  149905. while (*in_row_ctr < in_rows_avail &&
  149906. *out_row_group_ctr < out_row_groups_avail) {
  149907. inrows = in_rows_avail - *in_row_ctr;
  149908. numrows = cinfo->max_v_samp_factor - prep->next_buf_row;
  149909. numrows = (int) MIN((JDIMENSION) numrows, inrows);
  149910. (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
  149911. prep->color_buf,
  149912. (JDIMENSION) prep->next_buf_row,
  149913. numrows);
  149914. *in_row_ctr += numrows;
  149915. prep->next_buf_row += numrows;
  149916. prep->rows_to_go -= numrows;
  149917. if (prep->rows_to_go == 0 &&
  149918. prep->next_buf_row < cinfo->max_v_samp_factor) {
  149919. for (ci = 0; ci < cinfo->num_components; ci++) {
  149920. expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
  149921. prep->next_buf_row, cinfo->max_v_samp_factor);
  149922. }
  149923. prep->next_buf_row = cinfo->max_v_samp_factor;
  149924. }
  149925. if (prep->next_buf_row == cinfo->max_v_samp_factor) {
  149926. (*cinfo->downsample->downsample) (cinfo,
  149927. prep->color_buf, (JDIMENSION) 0,
  149928. output_buf, *out_row_group_ctr);
  149929. prep->next_buf_row = 0;
  149930. (*out_row_group_ctr)++;
  149931. }
  149932. if (prep->rows_to_go == 0 &&
  149933. *out_row_group_ctr < out_row_groups_avail) {
  149934. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149935. ci++, compptr++) {
  149936. expand_bottom_edge(output_buf[ci],
  149937. compptr->width_in_blocks * DCTSIZE,
  149938. (int) (*out_row_group_ctr * compptr->v_samp_factor),
  149939. (int) (out_row_groups_avail * compptr->v_samp_factor));
  149940. }
  149941. *out_row_group_ctr = out_row_groups_avail;
  149942. break; /* can exit outer loop without test */
  149943. }
  149944. }
  149945. }
  149946. #ifdef CONTEXT_ROWS_SUPPORTED
  149947. METHODDEF(void)
  149948. pre_process_context (j_compress_ptr cinfo,
  149949. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  149950. JDIMENSION in_rows_avail,
  149951. JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
  149952. JDIMENSION out_row_groups_avail)
  149953. {
  149954. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149955. int numrows, ci;
  149956. int buf_height = cinfo->max_v_samp_factor * 3;
  149957. JDIMENSION inrows;
  149958. while (*out_row_group_ctr < out_row_groups_avail) {
  149959. if (*in_row_ctr < in_rows_avail) {
  149960. inrows = in_rows_avail - *in_row_ctr;
  149961. numrows = prep->next_buf_stop - prep->next_buf_row;
  149962. numrows = (int) MIN((JDIMENSION) numrows, inrows);
  149963. (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
  149964. prep->color_buf,
  149965. (JDIMENSION) prep->next_buf_row,
  149966. numrows);
  149967. if (prep->rows_to_go == cinfo->image_height) {
  149968. for (ci = 0; ci < cinfo->num_components; ci++) {
  149969. int row;
  149970. for (row = 1; row <= cinfo->max_v_samp_factor; row++) {
  149971. jcopy_sample_rows(prep->color_buf[ci], 0,
  149972. prep->color_buf[ci], -row,
  149973. 1, cinfo->image_width);
  149974. }
  149975. }
  149976. }
  149977. *in_row_ctr += numrows;
  149978. prep->next_buf_row += numrows;
  149979. prep->rows_to_go -= numrows;
  149980. } else {
  149981. if (prep->rows_to_go != 0)
  149982. break;
  149983. if (prep->next_buf_row < prep->next_buf_stop) {
  149984. for (ci = 0; ci < cinfo->num_components; ci++) {
  149985. expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
  149986. prep->next_buf_row, prep->next_buf_stop);
  149987. }
  149988. prep->next_buf_row = prep->next_buf_stop;
  149989. }
  149990. }
  149991. if (prep->next_buf_row == prep->next_buf_stop) {
  149992. (*cinfo->downsample->downsample) (cinfo,
  149993. prep->color_buf,
  149994. (JDIMENSION) prep->this_row_group,
  149995. output_buf, *out_row_group_ctr);
  149996. (*out_row_group_ctr)++;
  149997. prep->this_row_group += cinfo->max_v_samp_factor;
  149998. if (prep->this_row_group >= buf_height)
  149999. prep->this_row_group = 0;
  150000. if (prep->next_buf_row >= buf_height)
  150001. prep->next_buf_row = 0;
  150002. prep->next_buf_stop = prep->next_buf_row + cinfo->max_v_samp_factor;
  150003. }
  150004. }
  150005. }
  150006. LOCAL(void)
  150007. create_context_buffer (j_compress_ptr cinfo)
  150008. {
  150009. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  150010. int rgroup_height = cinfo->max_v_samp_factor;
  150011. int ci, i;
  150012. jpeg_component_info * compptr;
  150013. JSAMPARRAY true_buffer, fake_buffer;
  150014. fake_buffer = (JSAMPARRAY)
  150015. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150016. (cinfo->num_components * 5 * rgroup_height) *
  150017. SIZEOF(JSAMPROW));
  150018. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  150019. ci++, compptr++) {
  150020. true_buffer = (*cinfo->mem->alloc_sarray)
  150021. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150022. (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE *
  150023. cinfo->max_h_samp_factor) / compptr->h_samp_factor),
  150024. (JDIMENSION) (3 * rgroup_height));
  150025. MEMCOPY(fake_buffer + rgroup_height, true_buffer,
  150026. 3 * rgroup_height * SIZEOF(JSAMPROW));
  150027. for (i = 0; i < rgroup_height; i++) {
  150028. fake_buffer[i] = true_buffer[2 * rgroup_height + i];
  150029. fake_buffer[4 * rgroup_height + i] = true_buffer[i];
  150030. }
  150031. prep->color_buf[ci] = fake_buffer + rgroup_height;
  150032. fake_buffer += 5 * rgroup_height; /* point to space for next component */
  150033. }
  150034. }
  150035. #endif /* CONTEXT_ROWS_SUPPORTED */
  150036. GLOBAL(void)
  150037. jinit_c_prep_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  150038. {
  150039. my_prep_ptr prep;
  150040. int ci;
  150041. jpeg_component_info * compptr;
  150042. if (need_full_buffer) /* safety check */
  150043. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  150044. prep = (my_prep_ptr)
  150045. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150046. SIZEOF(my_prep_controller));
  150047. cinfo->prep = (struct jpeg_c_prep_controller *) prep;
  150048. prep->pub.start_pass = start_pass_prep;
  150049. if (cinfo->downsample->need_context_rows) {
  150050. #ifdef CONTEXT_ROWS_SUPPORTED
  150051. prep->pub.pre_process_data = pre_process_context;
  150052. create_context_buffer(cinfo);
  150053. #else
  150054. ERREXIT(cinfo, JERR_NOT_COMPILED);
  150055. #endif
  150056. } else {
  150057. prep->pub.pre_process_data = pre_process_data;
  150058. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  150059. ci++, compptr++) {
  150060. prep->color_buf[ci] = (*cinfo->mem->alloc_sarray)
  150061. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150062. (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE *
  150063. cinfo->max_h_samp_factor) / compptr->h_samp_factor),
  150064. (JDIMENSION) cinfo->max_v_samp_factor);
  150065. }
  150066. }
  150067. }
  150068. /*** End of inlined file: jcprepct.c ***/
  150069. /*** Start of inlined file: jcsample.c ***/
  150070. #define JPEG_INTERNALS
  150071. typedef JMETHOD(void, downsample1_ptr,
  150072. (j_compress_ptr cinfo, jpeg_component_info * compptr,
  150073. JSAMPARRAY input_data, JSAMPARRAY output_data));
  150074. typedef struct {
  150075. struct jpeg_downsampler pub; /* public fields */
  150076. downsample1_ptr methods[MAX_COMPONENTS];
  150077. } my_downsampler;
  150078. typedef my_downsampler * my_downsample_ptr;
  150079. METHODDEF(void)
  150080. start_pass_downsample (j_compress_ptr cinfo)
  150081. {
  150082. }
  150083. LOCAL(void)
  150084. expand_right_edge (JSAMPARRAY image_data, int num_rows,
  150085. JDIMENSION input_cols, JDIMENSION output_cols)
  150086. {
  150087. register JSAMPROW ptr;
  150088. register JSAMPLE pixval;
  150089. register int count;
  150090. int row;
  150091. int numcols = (int) (output_cols - input_cols);
  150092. if (numcols > 0) {
  150093. for (row = 0; row < num_rows; row++) {
  150094. ptr = image_data[row] + input_cols;
  150095. pixval = ptr[-1]; /* don't need GETJSAMPLE() here */
  150096. for (count = numcols; count > 0; count--)
  150097. *ptr++ = pixval;
  150098. }
  150099. }
  150100. }
  150101. METHODDEF(void)
  150102. sep_downsample (j_compress_ptr cinfo,
  150103. JSAMPIMAGE input_buf, JDIMENSION in_row_index,
  150104. JSAMPIMAGE output_buf, JDIMENSION out_row_group_index)
  150105. {
  150106. my_downsample_ptr downsample = (my_downsample_ptr) cinfo->downsample;
  150107. int ci;
  150108. jpeg_component_info * compptr;
  150109. JSAMPARRAY in_ptr, out_ptr;
  150110. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  150111. ci++, compptr++) {
  150112. in_ptr = input_buf[ci] + in_row_index;
  150113. out_ptr = output_buf[ci] + (out_row_group_index * compptr->v_samp_factor);
  150114. (*downsample->methods[ci]) (cinfo, compptr, in_ptr, out_ptr);
  150115. }
  150116. }
  150117. METHODDEF(void)
  150118. int_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  150119. JSAMPARRAY input_data, JSAMPARRAY output_data)
  150120. {
  150121. int inrow, outrow, h_expand, v_expand, numpix, numpix2, h, v;
  150122. JDIMENSION outcol, outcol_h; /* outcol_h == outcol*h_expand */
  150123. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  150124. JSAMPROW inptr, outptr;
  150125. INT32 outvalue;
  150126. h_expand = cinfo->max_h_samp_factor / compptr->h_samp_factor;
  150127. v_expand = cinfo->max_v_samp_factor / compptr->v_samp_factor;
  150128. numpix = h_expand * v_expand;
  150129. numpix2 = numpix/2;
  150130. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  150131. cinfo->image_width, output_cols * h_expand);
  150132. inrow = 0;
  150133. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  150134. outptr = output_data[outrow];
  150135. for (outcol = 0, outcol_h = 0; outcol < output_cols;
  150136. outcol++, outcol_h += h_expand) {
  150137. outvalue = 0;
  150138. for (v = 0; v < v_expand; v++) {
  150139. inptr = input_data[inrow+v] + outcol_h;
  150140. for (h = 0; h < h_expand; h++) {
  150141. outvalue += (INT32) GETJSAMPLE(*inptr++);
  150142. }
  150143. }
  150144. *outptr++ = (JSAMPLE) ((outvalue + numpix2) / numpix);
  150145. }
  150146. inrow += v_expand;
  150147. }
  150148. }
  150149. METHODDEF(void)
  150150. fullsize_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  150151. JSAMPARRAY input_data, JSAMPARRAY output_data)
  150152. {
  150153. jcopy_sample_rows(input_data, 0, output_data, 0,
  150154. cinfo->max_v_samp_factor, cinfo->image_width);
  150155. expand_right_edge(output_data, cinfo->max_v_samp_factor,
  150156. cinfo->image_width, compptr->width_in_blocks * DCTSIZE);
  150157. }
  150158. METHODDEF(void)
  150159. h2v1_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  150160. JSAMPARRAY input_data, JSAMPARRAY output_data)
  150161. {
  150162. int outrow;
  150163. JDIMENSION outcol;
  150164. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  150165. register JSAMPROW inptr, outptr;
  150166. register int bias;
  150167. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  150168. cinfo->image_width, output_cols * 2);
  150169. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  150170. outptr = output_data[outrow];
  150171. inptr = input_data[outrow];
  150172. bias = 0; /* bias = 0,1,0,1,... for successive samples */
  150173. for (outcol = 0; outcol < output_cols; outcol++) {
  150174. *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr) + GETJSAMPLE(inptr[1])
  150175. + bias) >> 1);
  150176. bias ^= 1; /* 0=>1, 1=>0 */
  150177. inptr += 2;
  150178. }
  150179. }
  150180. }
  150181. METHODDEF(void)
  150182. h2v2_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  150183. JSAMPARRAY input_data, JSAMPARRAY output_data)
  150184. {
  150185. int inrow, outrow;
  150186. JDIMENSION outcol;
  150187. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  150188. register JSAMPROW inptr0, inptr1, outptr;
  150189. register int bias;
  150190. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  150191. cinfo->image_width, output_cols * 2);
  150192. inrow = 0;
  150193. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  150194. outptr = output_data[outrow];
  150195. inptr0 = input_data[inrow];
  150196. inptr1 = input_data[inrow+1];
  150197. bias = 1; /* bias = 1,2,1,2,... for successive samples */
  150198. for (outcol = 0; outcol < output_cols; outcol++) {
  150199. *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  150200. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1])
  150201. + bias) >> 2);
  150202. bias ^= 3; /* 1=>2, 2=>1 */
  150203. inptr0 += 2; inptr1 += 2;
  150204. }
  150205. inrow += 2;
  150206. }
  150207. }
  150208. #ifdef INPUT_SMOOTHING_SUPPORTED
  150209. METHODDEF(void)
  150210. h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  150211. JSAMPARRAY input_data, JSAMPARRAY output_data)
  150212. {
  150213. int inrow, outrow;
  150214. JDIMENSION colctr;
  150215. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  150216. register JSAMPROW inptr0, inptr1, above_ptr, below_ptr, outptr;
  150217. INT32 membersum, neighsum, memberscale, neighscale;
  150218. expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
  150219. cinfo->image_width, output_cols * 2);
  150220. memberscale = 16384 - cinfo->smoothing_factor * 80; /* scaled (1-5*SF)/4 */
  150221. neighscale = cinfo->smoothing_factor * 16; /* scaled SF/4 */
  150222. inrow = 0;
  150223. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  150224. outptr = output_data[outrow];
  150225. inptr0 = input_data[inrow];
  150226. inptr1 = input_data[inrow+1];
  150227. above_ptr = input_data[inrow-1];
  150228. below_ptr = input_data[inrow+2];
  150229. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  150230. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  150231. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  150232. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  150233. GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[2]) +
  150234. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[2]);
  150235. neighsum += neighsum;
  150236. neighsum += GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[2]) +
  150237. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[2]);
  150238. membersum = membersum * memberscale + neighsum * neighscale;
  150239. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  150240. inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
  150241. for (colctr = output_cols - 2; colctr > 0; colctr--) {
  150242. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  150243. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  150244. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  150245. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  150246. GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[2]) +
  150247. GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[2]);
  150248. neighsum += neighsum;
  150249. neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[2]) +
  150250. GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[2]);
  150251. membersum = membersum * memberscale + neighsum * neighscale;
  150252. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  150253. inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
  150254. }
  150255. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  150256. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  150257. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  150258. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  150259. GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[1]) +
  150260. GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[1]);
  150261. neighsum += neighsum;
  150262. neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[1]) +
  150263. GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[1]);
  150264. membersum = membersum * memberscale + neighsum * neighscale;
  150265. *outptr = (JSAMPLE) ((membersum + 32768) >> 16);
  150266. inrow += 2;
  150267. }
  150268. }
  150269. METHODDEF(void)
  150270. fullsize_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
  150271. JSAMPARRAY input_data, JSAMPARRAY output_data)
  150272. {
  150273. int outrow;
  150274. JDIMENSION colctr;
  150275. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  150276. register JSAMPROW inptr, above_ptr, below_ptr, outptr;
  150277. INT32 membersum, neighsum, memberscale, neighscale;
  150278. int colsum, lastcolsum, nextcolsum;
  150279. expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
  150280. cinfo->image_width, output_cols);
  150281. memberscale = 65536L - cinfo->smoothing_factor * 512L; /* scaled 1-8*SF */
  150282. neighscale = cinfo->smoothing_factor * 64; /* scaled SF */
  150283. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  150284. outptr = output_data[outrow];
  150285. inptr = input_data[outrow];
  150286. above_ptr = input_data[outrow-1];
  150287. below_ptr = input_data[outrow+1];
  150288. colsum = GETJSAMPLE(*above_ptr++) + GETJSAMPLE(*below_ptr++) +
  150289. GETJSAMPLE(*inptr);
  150290. membersum = GETJSAMPLE(*inptr++);
  150291. nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
  150292. GETJSAMPLE(*inptr);
  150293. neighsum = colsum + (colsum - membersum) + nextcolsum;
  150294. membersum = membersum * memberscale + neighsum * neighscale;
  150295. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  150296. lastcolsum = colsum; colsum = nextcolsum;
  150297. for (colctr = output_cols - 2; colctr > 0; colctr--) {
  150298. membersum = GETJSAMPLE(*inptr++);
  150299. above_ptr++; below_ptr++;
  150300. nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
  150301. GETJSAMPLE(*inptr);
  150302. neighsum = lastcolsum + (colsum - membersum) + nextcolsum;
  150303. membersum = membersum * memberscale + neighsum * neighscale;
  150304. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  150305. lastcolsum = colsum; colsum = nextcolsum;
  150306. }
  150307. membersum = GETJSAMPLE(*inptr);
  150308. neighsum = lastcolsum + (colsum - membersum) + colsum;
  150309. membersum = membersum * memberscale + neighsum * neighscale;
  150310. *outptr = (JSAMPLE) ((membersum + 32768) >> 16);
  150311. }
  150312. }
  150313. #endif /* INPUT_SMOOTHING_SUPPORTED */
  150314. GLOBAL(void)
  150315. jinit_downsampler (j_compress_ptr cinfo)
  150316. {
  150317. my_downsample_ptr downsample;
  150318. int ci;
  150319. jpeg_component_info * compptr;
  150320. boolean smoothok = TRUE;
  150321. downsample = (my_downsample_ptr)
  150322. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150323. SIZEOF(my_downsampler));
  150324. cinfo->downsample = (struct jpeg_downsampler *) downsample;
  150325. downsample->pub.start_pass = start_pass_downsample;
  150326. downsample->pub.downsample = sep_downsample;
  150327. downsample->pub.need_context_rows = FALSE;
  150328. if (cinfo->CCIR601_sampling)
  150329. ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
  150330. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  150331. ci++, compptr++) {
  150332. if (compptr->h_samp_factor == cinfo->max_h_samp_factor &&
  150333. compptr->v_samp_factor == cinfo->max_v_samp_factor) {
  150334. #ifdef INPUT_SMOOTHING_SUPPORTED
  150335. if (cinfo->smoothing_factor) {
  150336. downsample->methods[ci] = fullsize_smooth_downsample;
  150337. downsample->pub.need_context_rows = TRUE;
  150338. } else
  150339. #endif
  150340. downsample->methods[ci] = fullsize_downsample;
  150341. } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
  150342. compptr->v_samp_factor == cinfo->max_v_samp_factor) {
  150343. smoothok = FALSE;
  150344. downsample->methods[ci] = h2v1_downsample;
  150345. } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
  150346. compptr->v_samp_factor * 2 == cinfo->max_v_samp_factor) {
  150347. #ifdef INPUT_SMOOTHING_SUPPORTED
  150348. if (cinfo->smoothing_factor) {
  150349. downsample->methods[ci] = h2v2_smooth_downsample;
  150350. downsample->pub.need_context_rows = TRUE;
  150351. } else
  150352. #endif
  150353. downsample->methods[ci] = h2v2_downsample;
  150354. } else if ((cinfo->max_h_samp_factor % compptr->h_samp_factor) == 0 &&
  150355. (cinfo->max_v_samp_factor % compptr->v_samp_factor) == 0) {
  150356. smoothok = FALSE;
  150357. downsample->methods[ci] = int_downsample;
  150358. } else
  150359. ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
  150360. }
  150361. #ifdef INPUT_SMOOTHING_SUPPORTED
  150362. if (cinfo->smoothing_factor && !smoothok)
  150363. TRACEMS(cinfo, 0, JTRC_SMOOTH_NOTIMPL);
  150364. #endif
  150365. }
  150366. /*** End of inlined file: jcsample.c ***/
  150367. /*** Start of inlined file: jctrans.c ***/
  150368. #define JPEG_INTERNALS
  150369. LOCAL(void) transencode_master_selection
  150370. JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays));
  150371. LOCAL(void) transencode_coef_controller
  150372. JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays));
  150373. GLOBAL(void)
  150374. jpeg_write_coefficients (j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays)
  150375. {
  150376. if (cinfo->global_state != CSTATE_START)
  150377. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150378. jpeg_suppress_tables(cinfo, FALSE);
  150379. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  150380. (*cinfo->dest->init_destination) (cinfo);
  150381. transencode_master_selection(cinfo, coef_arrays);
  150382. cinfo->next_scanline = 0; /* so jpeg_write_marker works */
  150383. cinfo->global_state = CSTATE_WRCOEFS;
  150384. }
  150385. GLOBAL(void)
  150386. jpeg_copy_critical_parameters (j_decompress_ptr srcinfo,
  150387. j_compress_ptr dstinfo)
  150388. {
  150389. JQUANT_TBL ** qtblptr;
  150390. jpeg_component_info *incomp, *outcomp;
  150391. JQUANT_TBL *c_quant, *slot_quant;
  150392. int tblno, ci, coefi;
  150393. if (dstinfo->global_state != CSTATE_START)
  150394. ERREXIT1(dstinfo, JERR_BAD_STATE, dstinfo->global_state);
  150395. dstinfo->image_width = srcinfo->image_width;
  150396. dstinfo->image_height = srcinfo->image_height;
  150397. dstinfo->input_components = srcinfo->num_components;
  150398. dstinfo->in_color_space = srcinfo->jpeg_color_space;
  150399. jpeg_set_defaults(dstinfo);
  150400. jpeg_set_colorspace(dstinfo, srcinfo->jpeg_color_space);
  150401. dstinfo->data_precision = srcinfo->data_precision;
  150402. dstinfo->CCIR601_sampling = srcinfo->CCIR601_sampling;
  150403. for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {
  150404. if (srcinfo->quant_tbl_ptrs[tblno] != NULL) {
  150405. qtblptr = & dstinfo->quant_tbl_ptrs[tblno];
  150406. if (*qtblptr == NULL)
  150407. *qtblptr = jpeg_alloc_quant_table((j_common_ptr) dstinfo);
  150408. MEMCOPY((*qtblptr)->quantval,
  150409. srcinfo->quant_tbl_ptrs[tblno]->quantval,
  150410. SIZEOF((*qtblptr)->quantval));
  150411. (*qtblptr)->sent_table = FALSE;
  150412. }
  150413. }
  150414. dstinfo->num_components = srcinfo->num_components;
  150415. if (dstinfo->num_components < 1 || dstinfo->num_components > MAX_COMPONENTS)
  150416. ERREXIT2(dstinfo, JERR_COMPONENT_COUNT, dstinfo->num_components,
  150417. MAX_COMPONENTS);
  150418. for (ci = 0, incomp = srcinfo->comp_info, outcomp = dstinfo->comp_info;
  150419. ci < dstinfo->num_components; ci++, incomp++, outcomp++) {
  150420. outcomp->component_id = incomp->component_id;
  150421. outcomp->h_samp_factor = incomp->h_samp_factor;
  150422. outcomp->v_samp_factor = incomp->v_samp_factor;
  150423. outcomp->quant_tbl_no = incomp->quant_tbl_no;
  150424. tblno = outcomp->quant_tbl_no;
  150425. if (tblno < 0 || tblno >= NUM_QUANT_TBLS ||
  150426. srcinfo->quant_tbl_ptrs[tblno] == NULL)
  150427. ERREXIT1(dstinfo, JERR_NO_QUANT_TABLE, tblno);
  150428. slot_quant = srcinfo->quant_tbl_ptrs[tblno];
  150429. c_quant = incomp->quant_table;
  150430. if (c_quant != NULL) {
  150431. for (coefi = 0; coefi < DCTSIZE2; coefi++) {
  150432. if (c_quant->quantval[coefi] != slot_quant->quantval[coefi])
  150433. ERREXIT1(dstinfo, JERR_MISMATCHED_QUANT_TABLE, tblno);
  150434. }
  150435. }
  150436. }
  150437. if (srcinfo->saw_JFIF_marker) {
  150438. if (srcinfo->JFIF_major_version == 1) {
  150439. dstinfo->JFIF_major_version = srcinfo->JFIF_major_version;
  150440. dstinfo->JFIF_minor_version = srcinfo->JFIF_minor_version;
  150441. }
  150442. dstinfo->density_unit = srcinfo->density_unit;
  150443. dstinfo->X_density = srcinfo->X_density;
  150444. dstinfo->Y_density = srcinfo->Y_density;
  150445. }
  150446. }
  150447. LOCAL(void)
  150448. transencode_master_selection (j_compress_ptr cinfo,
  150449. jvirt_barray_ptr * coef_arrays)
  150450. {
  150451. cinfo->input_components = 1;
  150452. jinit_c_master_control(cinfo, TRUE /* transcode only */);
  150453. if (cinfo->arith_code) {
  150454. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  150455. } else {
  150456. if (cinfo->progressive_mode) {
  150457. #ifdef C_PROGRESSIVE_SUPPORTED
  150458. jinit_phuff_encoder(cinfo);
  150459. #else
  150460. ERREXIT(cinfo, JERR_NOT_COMPILED);
  150461. #endif
  150462. } else
  150463. jinit_huff_encoder(cinfo);
  150464. }
  150465. transencode_coef_controller(cinfo, coef_arrays);
  150466. jinit_marker_writer(cinfo);
  150467. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  150468. (*cinfo->marker->write_file_header) (cinfo);
  150469. }
  150470. typedef struct {
  150471. struct jpeg_c_coef_controller pub; /* public fields */
  150472. JDIMENSION iMCU_row_num; /* iMCU row # within image */
  150473. JDIMENSION mcu_ctr; /* counts MCUs processed in current row */
  150474. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  150475. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  150476. jvirt_barray_ptr * whole_image;
  150477. JBLOCKROW dummy_buffer[C_MAX_BLOCKS_IN_MCU];
  150478. } my_coef_controller2;
  150479. typedef my_coef_controller2 * my_coef_ptr2;
  150480. LOCAL(void)
  150481. start_iMCU_row2 (j_compress_ptr cinfo)
  150482. {
  150483. my_coef_ptr2 coef = (my_coef_ptr2) cinfo->coef;
  150484. if (cinfo->comps_in_scan > 1) {
  150485. coef->MCU_rows_per_iMCU_row = 1;
  150486. } else {
  150487. if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1))
  150488. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  150489. else
  150490. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  150491. }
  150492. coef->mcu_ctr = 0;
  150493. coef->MCU_vert_offset = 0;
  150494. }
  150495. METHODDEF(void)
  150496. start_pass_coef2 (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  150497. {
  150498. my_coef_ptr2 coef = (my_coef_ptr2) cinfo->coef;
  150499. if (pass_mode != JBUF_CRANK_DEST)
  150500. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  150501. coef->iMCU_row_num = 0;
  150502. start_iMCU_row2(cinfo);
  150503. }
  150504. METHODDEF(boolean)
  150505. compress_output2 (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  150506. {
  150507. my_coef_ptr2 coef = (my_coef_ptr2) cinfo->coef;
  150508. JDIMENSION MCU_col_num; /* index of current MCU within row */
  150509. JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  150510. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  150511. int blkn, ci, xindex, yindex, yoffset, blockcnt;
  150512. JDIMENSION start_col;
  150513. JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  150514. JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU];
  150515. JBLOCKROW buffer_ptr;
  150516. jpeg_component_info *compptr;
  150517. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150518. compptr = cinfo->cur_comp_info[ci];
  150519. buffer[ci] = (*cinfo->mem->access_virt_barray)
  150520. ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  150521. coef->iMCU_row_num * compptr->v_samp_factor,
  150522. (JDIMENSION) compptr->v_samp_factor, FALSE);
  150523. }
  150524. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  150525. yoffset++) {
  150526. for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row;
  150527. MCU_col_num++) {
  150528. blkn = 0; /* index of current DCT block within MCU */
  150529. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150530. compptr = cinfo->cur_comp_info[ci];
  150531. start_col = MCU_col_num * compptr->MCU_width;
  150532. blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  150533. : compptr->last_col_width;
  150534. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  150535. if (coef->iMCU_row_num < last_iMCU_row ||
  150536. yindex+yoffset < compptr->last_row_height) {
  150537. buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  150538. for (xindex = 0; xindex < blockcnt; xindex++)
  150539. MCU_buffer[blkn++] = buffer_ptr++;
  150540. } else {
  150541. xindex = 0;
  150542. }
  150543. for (; xindex < compptr->MCU_width; xindex++) {
  150544. MCU_buffer[blkn] = coef->dummy_buffer[blkn];
  150545. MCU_buffer[blkn][0][0] = MCU_buffer[blkn-1][0][0];
  150546. blkn++;
  150547. }
  150548. }
  150549. }
  150550. if (! (*cinfo->entropy->encode_mcu) (cinfo, MCU_buffer)) {
  150551. coef->MCU_vert_offset = yoffset;
  150552. coef->mcu_ctr = MCU_col_num;
  150553. return FALSE;
  150554. }
  150555. }
  150556. coef->mcu_ctr = 0;
  150557. }
  150558. coef->iMCU_row_num++;
  150559. start_iMCU_row2(cinfo);
  150560. return TRUE;
  150561. }
  150562. LOCAL(void)
  150563. transencode_coef_controller (j_compress_ptr cinfo,
  150564. jvirt_barray_ptr * coef_arrays)
  150565. {
  150566. my_coef_ptr2 coef;
  150567. JBLOCKROW buffer;
  150568. int i;
  150569. coef = (my_coef_ptr2)
  150570. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150571. SIZEOF(my_coef_controller2));
  150572. cinfo->coef = (struct jpeg_c_coef_controller *) coef;
  150573. coef->pub.start_pass = start_pass_coef2;
  150574. coef->pub.compress_data = compress_output2;
  150575. coef->whole_image = coef_arrays;
  150576. buffer = (JBLOCKROW)
  150577. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150578. C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  150579. jzero_far((void FAR *) buffer, C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  150580. for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) {
  150581. coef->dummy_buffer[i] = buffer + i;
  150582. }
  150583. }
  150584. /*** End of inlined file: jctrans.c ***/
  150585. /*** Start of inlined file: jdapistd.c ***/
  150586. #define JPEG_INTERNALS
  150587. LOCAL(boolean) output_pass_setup JPP((j_decompress_ptr cinfo));
  150588. GLOBAL(boolean)
  150589. jpeg_start_decompress (j_decompress_ptr cinfo)
  150590. {
  150591. if (cinfo->global_state == DSTATE_READY) {
  150592. jinit_master_decompress(cinfo);
  150593. if (cinfo->buffered_image) {
  150594. cinfo->global_state = DSTATE_BUFIMAGE;
  150595. return TRUE;
  150596. }
  150597. cinfo->global_state = DSTATE_PRELOAD;
  150598. }
  150599. if (cinfo->global_state == DSTATE_PRELOAD) {
  150600. if (cinfo->inputctl->has_multiple_scans) {
  150601. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150602. for (;;) {
  150603. int retcode;
  150604. if (cinfo->progress != NULL)
  150605. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150606. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  150607. if (retcode == JPEG_SUSPENDED)
  150608. return FALSE;
  150609. if (retcode == JPEG_REACHED_EOI)
  150610. break;
  150611. if (cinfo->progress != NULL &&
  150612. (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
  150613. if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
  150614. cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
  150615. }
  150616. }
  150617. }
  150618. #else
  150619. ERREXIT(cinfo, JERR_NOT_COMPILED);
  150620. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  150621. }
  150622. cinfo->output_scan_number = cinfo->input_scan_number;
  150623. } else if (cinfo->global_state != DSTATE_PRESCAN)
  150624. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150625. return output_pass_setup(cinfo);
  150626. }
  150627. LOCAL(boolean)
  150628. output_pass_setup (j_decompress_ptr cinfo)
  150629. {
  150630. if (cinfo->global_state != DSTATE_PRESCAN) {
  150631. (*cinfo->master->prepare_for_output_pass) (cinfo);
  150632. cinfo->output_scanline = 0;
  150633. cinfo->global_state = DSTATE_PRESCAN;
  150634. }
  150635. while (cinfo->master->is_dummy_pass) {
  150636. #ifdef QUANT_2PASS_SUPPORTED
  150637. while (cinfo->output_scanline < cinfo->output_height) {
  150638. JDIMENSION last_scanline;
  150639. if (cinfo->progress != NULL) {
  150640. cinfo->progress->pass_counter = (long) cinfo->output_scanline;
  150641. cinfo->progress->pass_limit = (long) cinfo->output_height;
  150642. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150643. }
  150644. last_scanline = cinfo->output_scanline;
  150645. (*cinfo->main->process_data) (cinfo, (JSAMPARRAY) NULL,
  150646. &cinfo->output_scanline, (JDIMENSION) 0);
  150647. if (cinfo->output_scanline == last_scanline)
  150648. return FALSE; /* No progress made, must suspend */
  150649. }
  150650. (*cinfo->master->finish_output_pass) (cinfo);
  150651. (*cinfo->master->prepare_for_output_pass) (cinfo);
  150652. cinfo->output_scanline = 0;
  150653. #else
  150654. ERREXIT(cinfo, JERR_NOT_COMPILED);
  150655. #endif /* QUANT_2PASS_SUPPORTED */
  150656. }
  150657. cinfo->global_state = cinfo->raw_data_out ? DSTATE_RAW_OK : DSTATE_SCANNING;
  150658. return TRUE;
  150659. }
  150660. GLOBAL(JDIMENSION)
  150661. jpeg_read_scanlines (j_decompress_ptr cinfo, JSAMPARRAY scanlines,
  150662. JDIMENSION max_lines)
  150663. {
  150664. JDIMENSION row_ctr;
  150665. if (cinfo->global_state != DSTATE_SCANNING)
  150666. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150667. if (cinfo->output_scanline >= cinfo->output_height) {
  150668. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  150669. return 0;
  150670. }
  150671. if (cinfo->progress != NULL) {
  150672. cinfo->progress->pass_counter = (long) cinfo->output_scanline;
  150673. cinfo->progress->pass_limit = (long) cinfo->output_height;
  150674. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150675. }
  150676. row_ctr = 0;
  150677. (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, max_lines);
  150678. cinfo->output_scanline += row_ctr;
  150679. return row_ctr;
  150680. }
  150681. GLOBAL(JDIMENSION)
  150682. jpeg_read_raw_data (j_decompress_ptr cinfo, JSAMPIMAGE data,
  150683. JDIMENSION max_lines)
  150684. {
  150685. JDIMENSION lines_per_iMCU_row;
  150686. if (cinfo->global_state != DSTATE_RAW_OK)
  150687. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150688. if (cinfo->output_scanline >= cinfo->output_height) {
  150689. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  150690. return 0;
  150691. }
  150692. if (cinfo->progress != NULL) {
  150693. cinfo->progress->pass_counter = (long) cinfo->output_scanline;
  150694. cinfo->progress->pass_limit = (long) cinfo->output_height;
  150695. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150696. }
  150697. lines_per_iMCU_row = cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size;
  150698. if (max_lines < lines_per_iMCU_row)
  150699. ERREXIT(cinfo, JERR_BUFFER_SIZE);
  150700. if (! (*cinfo->coef->decompress_data) (cinfo, data))
  150701. return 0; /* suspension forced, can do nothing more */
  150702. cinfo->output_scanline += lines_per_iMCU_row;
  150703. return lines_per_iMCU_row;
  150704. }
  150705. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150706. GLOBAL(boolean)
  150707. jpeg_start_output (j_decompress_ptr cinfo, int scan_number)
  150708. {
  150709. if (cinfo->global_state != DSTATE_BUFIMAGE &&
  150710. cinfo->global_state != DSTATE_PRESCAN)
  150711. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150712. if (scan_number <= 0)
  150713. scan_number = 1;
  150714. if (cinfo->inputctl->eoi_reached &&
  150715. scan_number > cinfo->input_scan_number)
  150716. scan_number = cinfo->input_scan_number;
  150717. cinfo->output_scan_number = scan_number;
  150718. return output_pass_setup(cinfo);
  150719. }
  150720. GLOBAL(boolean)
  150721. jpeg_finish_output (j_decompress_ptr cinfo)
  150722. {
  150723. if ((cinfo->global_state == DSTATE_SCANNING ||
  150724. cinfo->global_state == DSTATE_RAW_OK) && cinfo->buffered_image) {
  150725. (*cinfo->master->finish_output_pass) (cinfo);
  150726. cinfo->global_state = DSTATE_BUFPOST;
  150727. } else if (cinfo->global_state != DSTATE_BUFPOST) {
  150728. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150729. }
  150730. while (cinfo->input_scan_number <= cinfo->output_scan_number &&
  150731. ! cinfo->inputctl->eoi_reached) {
  150732. if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
  150733. return FALSE; /* Suspend, come back later */
  150734. }
  150735. cinfo->global_state = DSTATE_BUFIMAGE;
  150736. return TRUE;
  150737. }
  150738. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  150739. /*** End of inlined file: jdapistd.c ***/
  150740. /*** Start of inlined file: jdapimin.c ***/
  150741. #define JPEG_INTERNALS
  150742. GLOBAL(void)
  150743. jpeg_CreateDecompress (j_decompress_ptr cinfo, int version, size_t structsize)
  150744. {
  150745. int i;
  150746. cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */
  150747. if (version != JPEG_LIB_VERSION)
  150748. ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
  150749. if (structsize != SIZEOF(struct jpeg_decompress_struct))
  150750. ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
  150751. (int) SIZEOF(struct jpeg_decompress_struct), (int) structsize);
  150752. {
  150753. struct jpeg_error_mgr * err = cinfo->err;
  150754. void * client_data = cinfo->client_data; /* ignore Purify complaint here */
  150755. MEMZERO(cinfo, SIZEOF(struct jpeg_decompress_struct));
  150756. cinfo->err = err;
  150757. cinfo->client_data = client_data;
  150758. }
  150759. cinfo->is_decompressor = TRUE;
  150760. jinit_memory_mgr((j_common_ptr) cinfo);
  150761. cinfo->progress = NULL;
  150762. cinfo->src = NULL;
  150763. for (i = 0; i < NUM_QUANT_TBLS; i++)
  150764. cinfo->quant_tbl_ptrs[i] = NULL;
  150765. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  150766. cinfo->dc_huff_tbl_ptrs[i] = NULL;
  150767. cinfo->ac_huff_tbl_ptrs[i] = NULL;
  150768. }
  150769. cinfo->marker_list = NULL;
  150770. jinit_marker_reader(cinfo);
  150771. jinit_input_controller(cinfo);
  150772. cinfo->global_state = DSTATE_START;
  150773. }
  150774. GLOBAL(void)
  150775. jpeg_destroy_decompress (j_decompress_ptr cinfo)
  150776. {
  150777. jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
  150778. }
  150779. GLOBAL(void)
  150780. jpeg_abort_decompress (j_decompress_ptr cinfo)
  150781. {
  150782. jpeg_abort((j_common_ptr) cinfo); /* use common routine */
  150783. }
  150784. LOCAL(void)
  150785. default_decompress_parms (j_decompress_ptr cinfo)
  150786. {
  150787. switch (cinfo->num_components) {
  150788. case 1:
  150789. cinfo->jpeg_color_space = JCS_GRAYSCALE;
  150790. cinfo->out_color_space = JCS_GRAYSCALE;
  150791. break;
  150792. case 3:
  150793. if (cinfo->saw_JFIF_marker) {
  150794. cinfo->jpeg_color_space = JCS_YCbCr; /* JFIF implies YCbCr */
  150795. } else if (cinfo->saw_Adobe_marker) {
  150796. switch (cinfo->Adobe_transform) {
  150797. case 0:
  150798. cinfo->jpeg_color_space = JCS_RGB;
  150799. break;
  150800. case 1:
  150801. cinfo->jpeg_color_space = JCS_YCbCr;
  150802. break;
  150803. default:
  150804. WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
  150805. cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
  150806. break;
  150807. }
  150808. } else {
  150809. int cid0 = cinfo->comp_info[0].component_id;
  150810. int cid1 = cinfo->comp_info[1].component_id;
  150811. int cid2 = cinfo->comp_info[2].component_id;
  150812. if (cid0 == 1 && cid1 == 2 && cid2 == 3)
  150813. cinfo->jpeg_color_space = JCS_YCbCr; /* assume JFIF w/out marker */
  150814. else if (cid0 == 82 && cid1 == 71 && cid2 == 66)
  150815. cinfo->jpeg_color_space = JCS_RGB; /* ASCII 'R', 'G', 'B' */
  150816. else {
  150817. TRACEMS3(cinfo, 1, JTRC_UNKNOWN_IDS, cid0, cid1, cid2);
  150818. cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
  150819. }
  150820. }
  150821. cinfo->out_color_space = JCS_RGB;
  150822. break;
  150823. case 4:
  150824. if (cinfo->saw_Adobe_marker) {
  150825. switch (cinfo->Adobe_transform) {
  150826. case 0:
  150827. cinfo->jpeg_color_space = JCS_CMYK;
  150828. break;
  150829. case 2:
  150830. cinfo->jpeg_color_space = JCS_YCCK;
  150831. break;
  150832. default:
  150833. WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
  150834. cinfo->jpeg_color_space = JCS_YCCK; /* assume it's YCCK */
  150835. break;
  150836. }
  150837. } else {
  150838. cinfo->jpeg_color_space = JCS_CMYK;
  150839. }
  150840. cinfo->out_color_space = JCS_CMYK;
  150841. break;
  150842. default:
  150843. cinfo->jpeg_color_space = JCS_UNKNOWN;
  150844. cinfo->out_color_space = JCS_UNKNOWN;
  150845. break;
  150846. }
  150847. cinfo->scale_num = 1; /* 1:1 scaling */
  150848. cinfo->scale_denom = 1;
  150849. cinfo->output_gamma = 1.0;
  150850. cinfo->buffered_image = FALSE;
  150851. cinfo->raw_data_out = FALSE;
  150852. cinfo->dct_method = JDCT_DEFAULT;
  150853. cinfo->do_fancy_upsampling = TRUE;
  150854. cinfo->do_block_smoothing = TRUE;
  150855. cinfo->quantize_colors = FALSE;
  150856. cinfo->dither_mode = JDITHER_FS;
  150857. #ifdef QUANT_2PASS_SUPPORTED
  150858. cinfo->two_pass_quantize = TRUE;
  150859. #else
  150860. cinfo->two_pass_quantize = FALSE;
  150861. #endif
  150862. cinfo->desired_number_of_colors = 256;
  150863. cinfo->colormap = NULL;
  150864. cinfo->enable_1pass_quant = FALSE;
  150865. cinfo->enable_external_quant = FALSE;
  150866. cinfo->enable_2pass_quant = FALSE;
  150867. }
  150868. GLOBAL(int)
  150869. jpeg_read_header (j_decompress_ptr cinfo, boolean require_image)
  150870. {
  150871. int retcode;
  150872. if (cinfo->global_state != DSTATE_START &&
  150873. cinfo->global_state != DSTATE_INHEADER)
  150874. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150875. retcode = jpeg_consume_input(cinfo);
  150876. switch (retcode) {
  150877. case JPEG_REACHED_SOS:
  150878. retcode = JPEG_HEADER_OK;
  150879. break;
  150880. case JPEG_REACHED_EOI:
  150881. if (require_image) /* Complain if application wanted an image */
  150882. ERREXIT(cinfo, JERR_NO_IMAGE);
  150883. jpeg_abort((j_common_ptr) cinfo); /* sets state = DSTATE_START */
  150884. retcode = JPEG_HEADER_TABLES_ONLY;
  150885. break;
  150886. case JPEG_SUSPENDED:
  150887. break;
  150888. }
  150889. return retcode;
  150890. }
  150891. GLOBAL(int)
  150892. jpeg_consume_input (j_decompress_ptr cinfo)
  150893. {
  150894. int retcode = JPEG_SUSPENDED;
  150895. switch (cinfo->global_state) {
  150896. case DSTATE_START:
  150897. (*cinfo->inputctl->reset_input_controller) (cinfo);
  150898. (*cinfo->src->init_source) (cinfo);
  150899. cinfo->global_state = DSTATE_INHEADER;
  150900. case DSTATE_INHEADER:
  150901. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  150902. if (retcode == JPEG_REACHED_SOS) { /* Found SOS, prepare to decompress */
  150903. default_decompress_parms(cinfo);
  150904. cinfo->global_state = DSTATE_READY;
  150905. }
  150906. break;
  150907. case DSTATE_READY:
  150908. retcode = JPEG_REACHED_SOS;
  150909. break;
  150910. case DSTATE_PRELOAD:
  150911. case DSTATE_PRESCAN:
  150912. case DSTATE_SCANNING:
  150913. case DSTATE_RAW_OK:
  150914. case DSTATE_BUFIMAGE:
  150915. case DSTATE_BUFPOST:
  150916. case DSTATE_STOPPING:
  150917. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  150918. break;
  150919. default:
  150920. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150921. }
  150922. return retcode;
  150923. }
  150924. GLOBAL(boolean)
  150925. jpeg_input_complete (j_decompress_ptr cinfo)
  150926. {
  150927. if (cinfo->global_state < DSTATE_START ||
  150928. cinfo->global_state > DSTATE_STOPPING)
  150929. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150930. return cinfo->inputctl->eoi_reached;
  150931. }
  150932. GLOBAL(boolean)
  150933. jpeg_has_multiple_scans (j_decompress_ptr cinfo)
  150934. {
  150935. if (cinfo->global_state < DSTATE_READY ||
  150936. cinfo->global_state > DSTATE_STOPPING)
  150937. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150938. return cinfo->inputctl->has_multiple_scans;
  150939. }
  150940. GLOBAL(boolean)
  150941. jpeg_finish_decompress (j_decompress_ptr cinfo)
  150942. {
  150943. if ((cinfo->global_state == DSTATE_SCANNING ||
  150944. cinfo->global_state == DSTATE_RAW_OK) && ! cinfo->buffered_image) {
  150945. if (cinfo->output_scanline < cinfo->output_height)
  150946. ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
  150947. (*cinfo->master->finish_output_pass) (cinfo);
  150948. cinfo->global_state = DSTATE_STOPPING;
  150949. } else if (cinfo->global_state == DSTATE_BUFIMAGE) {
  150950. cinfo->global_state = DSTATE_STOPPING;
  150951. } else if (cinfo->global_state != DSTATE_STOPPING) {
  150952. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150953. }
  150954. while (! cinfo->inputctl->eoi_reached) {
  150955. if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
  150956. return FALSE; /* Suspend, come back later */
  150957. }
  150958. (*cinfo->src->term_source) (cinfo);
  150959. jpeg_abort((j_common_ptr) cinfo);
  150960. return TRUE;
  150961. }
  150962. /*** End of inlined file: jdapimin.c ***/
  150963. /*** Start of inlined file: jdatasrc.c ***/
  150964. /*** Start of inlined file: jerror.h ***/
  150965. #ifndef JMESSAGE
  150966. #ifndef JERROR_H
  150967. #define JMAKE_ENUM_LIST
  150968. #else
  150969. #define JMESSAGE(code,string)
  150970. #endif /* JERROR_H */
  150971. #endif /* JMESSAGE */
  150972. #ifdef JMAKE_ENUM_LIST
  150973. typedef enum {
  150974. #define JMESSAGE(code,string) code ,
  150975. #endif /* JMAKE_ENUM_LIST */
  150976. JMESSAGE(JMSG_NOMESSAGE, "Bogus message code %d") /* Must be first entry! */
  150977. JMESSAGE(JERR_ARITH_NOTIMPL,
  150978. "Sorry, there are legal restrictions on arithmetic coding")
  150979. JMESSAGE(JERR_BAD_ALIGN_TYPE, "ALIGN_TYPE is wrong, please fix")
  150980. JMESSAGE(JERR_BAD_ALLOC_CHUNK, "MAX_ALLOC_CHUNK is wrong, please fix")
  150981. JMESSAGE(JERR_BAD_BUFFER_MODE, "Bogus buffer control mode")
  150982. JMESSAGE(JERR_BAD_COMPONENT_ID, "Invalid component ID %d in SOS")
  150983. JMESSAGE(JERR_BAD_DCT_COEF, "DCT coefficient out of range")
  150984. JMESSAGE(JERR_BAD_DCTSIZE, "IDCT output block size %d not supported")
  150985. JMESSAGE(JERR_BAD_HUFF_TABLE, "Bogus Huffman table definition")
  150986. JMESSAGE(JERR_BAD_IN_COLORSPACE, "Bogus input colorspace")
  150987. JMESSAGE(JERR_BAD_J_COLORSPACE, "Bogus JPEG colorspace")
  150988. JMESSAGE(JERR_BAD_LENGTH, "Bogus marker length")
  150989. JMESSAGE(JERR_BAD_LIB_VERSION,
  150990. "Wrong JPEG library version: library is %d, caller expects %d")
  150991. JMESSAGE(JERR_BAD_MCU_SIZE, "Sampling factors too large for interleaved scan")
  150992. JMESSAGE(JERR_BAD_POOL_ID, "Invalid memory pool code %d")
  150993. JMESSAGE(JERR_BAD_PRECISION, "Unsupported JPEG data precision %d")
  150994. JMESSAGE(JERR_BAD_PROGRESSION,
  150995. "Invalid progressive parameters Ss=%d Se=%d Ah=%d Al=%d")
  150996. JMESSAGE(JERR_BAD_PROG_SCRIPT,
  150997. "Invalid progressive parameters at scan script entry %d")
  150998. JMESSAGE(JERR_BAD_SAMPLING, "Bogus sampling factors")
  150999. JMESSAGE(JERR_BAD_SCAN_SCRIPT, "Invalid scan script at entry %d")
  151000. JMESSAGE(JERR_BAD_STATE, "Improper call to JPEG library in state %d")
  151001. JMESSAGE(JERR_BAD_STRUCT_SIZE,
  151002. "JPEG parameter struct mismatch: library thinks size is %u, caller expects %u")
  151003. JMESSAGE(JERR_BAD_VIRTUAL_ACCESS, "Bogus virtual array access")
  151004. JMESSAGE(JERR_BUFFER_SIZE, "Buffer passed to JPEG library is too small")
  151005. JMESSAGE(JERR_CANT_SUSPEND, "Suspension not allowed here")
  151006. JMESSAGE(JERR_CCIR601_NOTIMPL, "CCIR601 sampling not implemented yet")
  151007. JMESSAGE(JERR_COMPONENT_COUNT, "Too many color components: %d, max %d")
  151008. JMESSAGE(JERR_CONVERSION_NOTIMPL, "Unsupported color conversion request")
  151009. JMESSAGE(JERR_DAC_INDEX, "Bogus DAC index %d")
  151010. JMESSAGE(JERR_DAC_VALUE, "Bogus DAC value 0x%x")
  151011. JMESSAGE(JERR_DHT_INDEX, "Bogus DHT index %d")
  151012. JMESSAGE(JERR_DQT_INDEX, "Bogus DQT index %d")
  151013. JMESSAGE(JERR_EMPTY_IMAGE, "Empty JPEG image (DNL not supported)")
  151014. JMESSAGE(JERR_EMS_READ, "Read from EMS failed")
  151015. JMESSAGE(JERR_EMS_WRITE, "Write to EMS failed")
  151016. JMESSAGE(JERR_EOI_EXPECTED, "Didn't expect more than one scan")
  151017. JMESSAGE(JERR_FILE_READ, "Input file read error")
  151018. JMESSAGE(JERR_FILE_WRITE, "Output file write error --- out of disk space?")
  151019. JMESSAGE(JERR_FRACT_SAMPLE_NOTIMPL, "Fractional sampling not implemented yet")
  151020. JMESSAGE(JERR_HUFF_CLEN_OVERFLOW, "Huffman code size table overflow")
  151021. JMESSAGE(JERR_HUFF_MISSING_CODE, "Missing Huffman code table entry")
  151022. JMESSAGE(JERR_IMAGE_TOO_BIG, "Maximum supported image dimension is %u pixels")
  151023. JMESSAGE(JERR_INPUT_EMPTY, "Empty input file")
  151024. JMESSAGE(JERR_INPUT_EOF, "Premature end of input file")
  151025. JMESSAGE(JERR_MISMATCHED_QUANT_TABLE,
  151026. "Cannot transcode due to multiple use of quantization table %d")
  151027. JMESSAGE(JERR_MISSING_DATA, "Scan script does not transmit all data")
  151028. JMESSAGE(JERR_MODE_CHANGE, "Invalid color quantization mode change")
  151029. JMESSAGE(JERR_NOTIMPL, "Not implemented yet")
  151030. JMESSAGE(JERR_NOT_COMPILED, "Requested feature was omitted at compile time")
  151031. JMESSAGE(JERR_NO_BACKING_STORE, "Backing store not supported")
  151032. JMESSAGE(JERR_NO_HUFF_TABLE, "Huffman table 0x%02x was not defined")
  151033. JMESSAGE(JERR_NO_IMAGE, "JPEG datastream contains no image")
  151034. JMESSAGE(JERR_NO_QUANT_TABLE, "Quantization table 0x%02x was not defined")
  151035. JMESSAGE(JERR_NO_SOI, "Not a JPEG file: starts with 0x%02x 0x%02x")
  151036. JMESSAGE(JERR_OUT_OF_MEMORY, "Insufficient memory (case %d)")
  151037. JMESSAGE(JERR_QUANT_COMPONENTS,
  151038. "Cannot quantize more than %d color components")
  151039. JMESSAGE(JERR_QUANT_FEW_COLORS, "Cannot quantize to fewer than %d colors")
  151040. JMESSAGE(JERR_QUANT_MANY_COLORS, "Cannot quantize to more than %d colors")
  151041. JMESSAGE(JERR_SOF_DUPLICATE, "Invalid JPEG file structure: two SOF markers")
  151042. JMESSAGE(JERR_SOF_NO_SOS, "Invalid JPEG file structure: missing SOS marker")
  151043. JMESSAGE(JERR_SOF_UNSUPPORTED, "Unsupported JPEG process: SOF type 0x%02x")
  151044. JMESSAGE(JERR_SOI_DUPLICATE, "Invalid JPEG file structure: two SOI markers")
  151045. JMESSAGE(JERR_SOS_NO_SOF, "Invalid JPEG file structure: SOS before SOF")
  151046. JMESSAGE(JERR_TFILE_CREATE, "Failed to create temporary file %s")
  151047. JMESSAGE(JERR_TFILE_READ, "Read failed on temporary file")
  151048. JMESSAGE(JERR_TFILE_SEEK, "Seek failed on temporary file")
  151049. JMESSAGE(JERR_TFILE_WRITE,
  151050. "Write failed on temporary file --- out of disk space?")
  151051. JMESSAGE(JERR_TOO_LITTLE_DATA, "Application transferred too few scanlines")
  151052. JMESSAGE(JERR_UNKNOWN_MARKER, "Unsupported marker type 0x%02x")
  151053. JMESSAGE(JERR_VIRTUAL_BUG, "Virtual array controller messed up")
  151054. JMESSAGE(JERR_WIDTH_OVERFLOW, "Image too wide for this implementation")
  151055. JMESSAGE(JERR_XMS_READ, "Read from XMS failed")
  151056. JMESSAGE(JERR_XMS_WRITE, "Write to XMS failed")
  151057. JMESSAGE(JMSG_COPYRIGHT, JCOPYRIGHT)
  151058. JMESSAGE(JMSG_VERSION, JVERSION)
  151059. JMESSAGE(JTRC_16BIT_TABLES,
  151060. "Caution: quantization tables are too coarse for baseline JPEG")
  151061. JMESSAGE(JTRC_ADOBE,
  151062. "Adobe APP14 marker: version %d, flags 0x%04x 0x%04x, transform %d")
  151063. JMESSAGE(JTRC_APP0, "Unknown APP0 marker (not JFIF), length %u")
  151064. JMESSAGE(JTRC_APP14, "Unknown APP14 marker (not Adobe), length %u")
  151065. JMESSAGE(JTRC_DAC, "Define Arithmetic Table 0x%02x: 0x%02x")
  151066. JMESSAGE(JTRC_DHT, "Define Huffman Table 0x%02x")
  151067. JMESSAGE(JTRC_DQT, "Define Quantization Table %d precision %d")
  151068. JMESSAGE(JTRC_DRI, "Define Restart Interval %u")
  151069. JMESSAGE(JTRC_EMS_CLOSE, "Freed EMS handle %u")
  151070. JMESSAGE(JTRC_EMS_OPEN, "Obtained EMS handle %u")
  151071. JMESSAGE(JTRC_EOI, "End Of Image")
  151072. JMESSAGE(JTRC_HUFFBITS, " %3d %3d %3d %3d %3d %3d %3d %3d")
  151073. JMESSAGE(JTRC_JFIF, "JFIF APP0 marker: version %d.%02d, density %dx%d %d")
  151074. JMESSAGE(JTRC_JFIF_BADTHUMBNAILSIZE,
  151075. "Warning: thumbnail image size does not match data length %u")
  151076. JMESSAGE(JTRC_JFIF_EXTENSION,
  151077. "JFIF extension marker: type 0x%02x, length %u")
  151078. JMESSAGE(JTRC_JFIF_THUMBNAIL, " with %d x %d thumbnail image")
  151079. JMESSAGE(JTRC_MISC_MARKER, "Miscellaneous marker 0x%02x, length %u")
  151080. JMESSAGE(JTRC_PARMLESS_MARKER, "Unexpected marker 0x%02x")
  151081. JMESSAGE(JTRC_QUANTVALS, " %4u %4u %4u %4u %4u %4u %4u %4u")
  151082. JMESSAGE(JTRC_QUANT_3_NCOLORS, "Quantizing to %d = %d*%d*%d colors")
  151083. JMESSAGE(JTRC_QUANT_NCOLORS, "Quantizing to %d colors")
  151084. JMESSAGE(JTRC_QUANT_SELECTED, "Selected %d colors for quantization")
  151085. JMESSAGE(JTRC_RECOVERY_ACTION, "At marker 0x%02x, recovery action %d")
  151086. JMESSAGE(JTRC_RST, "RST%d")
  151087. JMESSAGE(JTRC_SMOOTH_NOTIMPL,
  151088. "Smoothing not supported with nonstandard sampling ratios")
  151089. JMESSAGE(JTRC_SOF, "Start Of Frame 0x%02x: width=%u, height=%u, components=%d")
  151090. JMESSAGE(JTRC_SOF_COMPONENT, " Component %d: %dhx%dv q=%d")
  151091. JMESSAGE(JTRC_SOI, "Start of Image")
  151092. JMESSAGE(JTRC_SOS, "Start Of Scan: %d components")
  151093. JMESSAGE(JTRC_SOS_COMPONENT, " Component %d: dc=%d ac=%d")
  151094. JMESSAGE(JTRC_SOS_PARAMS, " Ss=%d, Se=%d, Ah=%d, Al=%d")
  151095. JMESSAGE(JTRC_TFILE_CLOSE, "Closed temporary file %s")
  151096. JMESSAGE(JTRC_TFILE_OPEN, "Opened temporary file %s")
  151097. JMESSAGE(JTRC_THUMB_JPEG,
  151098. "JFIF extension marker: JPEG-compressed thumbnail image, length %u")
  151099. JMESSAGE(JTRC_THUMB_PALETTE,
  151100. "JFIF extension marker: palette thumbnail image, length %u")
  151101. JMESSAGE(JTRC_THUMB_RGB,
  151102. "JFIF extension marker: RGB thumbnail image, length %u")
  151103. JMESSAGE(JTRC_UNKNOWN_IDS,
  151104. "Unrecognized component IDs %d %d %d, assuming YCbCr")
  151105. JMESSAGE(JTRC_XMS_CLOSE, "Freed XMS handle %u")
  151106. JMESSAGE(JTRC_XMS_OPEN, "Obtained XMS handle %u")
  151107. JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d")
  151108. JMESSAGE(JWRN_BOGUS_PROGRESSION,
  151109. "Inconsistent progression sequence for component %d coefficient %d")
  151110. JMESSAGE(JWRN_EXTRANEOUS_DATA,
  151111. "Corrupt JPEG data: %u extraneous bytes before marker 0x%02x")
  151112. JMESSAGE(JWRN_HIT_MARKER, "Corrupt JPEG data: premature end of data segment")
  151113. JMESSAGE(JWRN_HUFF_BAD_CODE, "Corrupt JPEG data: bad Huffman code")
  151114. JMESSAGE(JWRN_JFIF_MAJOR, "Warning: unknown JFIF revision number %d.%02d")
  151115. JMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file")
  151116. JMESSAGE(JWRN_MUST_RESYNC,
  151117. "Corrupt JPEG data: found marker 0x%02x instead of RST%d")
  151118. JMESSAGE(JWRN_NOT_SEQUENTIAL, "Invalid SOS parameters for sequential JPEG")
  151119. JMESSAGE(JWRN_TOO_MUCH_DATA, "Application transferred too many scanlines")
  151120. #ifdef JMAKE_ENUM_LIST
  151121. JMSG_LASTMSGCODE
  151122. } J_MESSAGE_CODE;
  151123. #undef JMAKE_ENUM_LIST
  151124. #endif /* JMAKE_ENUM_LIST */
  151125. #undef JMESSAGE
  151126. #ifndef JERROR_H
  151127. #define JERROR_H
  151128. #define ERREXIT(cinfo,code) \
  151129. ((cinfo)->err->msg_code = (code), \
  151130. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  151131. #define ERREXIT1(cinfo,code,p1) \
  151132. ((cinfo)->err->msg_code = (code), \
  151133. (cinfo)->err->msg_parm.i[0] = (p1), \
  151134. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  151135. #define ERREXIT2(cinfo,code,p1,p2) \
  151136. ((cinfo)->err->msg_code = (code), \
  151137. (cinfo)->err->msg_parm.i[0] = (p1), \
  151138. (cinfo)->err->msg_parm.i[1] = (p2), \
  151139. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  151140. #define ERREXIT3(cinfo,code,p1,p2,p3) \
  151141. ((cinfo)->err->msg_code = (code), \
  151142. (cinfo)->err->msg_parm.i[0] = (p1), \
  151143. (cinfo)->err->msg_parm.i[1] = (p2), \
  151144. (cinfo)->err->msg_parm.i[2] = (p3), \
  151145. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  151146. #define ERREXIT4(cinfo,code,p1,p2,p3,p4) \
  151147. ((cinfo)->err->msg_code = (code), \
  151148. (cinfo)->err->msg_parm.i[0] = (p1), \
  151149. (cinfo)->err->msg_parm.i[1] = (p2), \
  151150. (cinfo)->err->msg_parm.i[2] = (p3), \
  151151. (cinfo)->err->msg_parm.i[3] = (p4), \
  151152. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  151153. #define ERREXITS(cinfo,code,str) \
  151154. ((cinfo)->err->msg_code = (code), \
  151155. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  151156. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  151157. #define MAKESTMT(stuff) do { stuff } while (0)
  151158. #define WARNMS(cinfo,code) \
  151159. ((cinfo)->err->msg_code = (code), \
  151160. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  151161. #define WARNMS1(cinfo,code,p1) \
  151162. ((cinfo)->err->msg_code = (code), \
  151163. (cinfo)->err->msg_parm.i[0] = (p1), \
  151164. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  151165. #define WARNMS2(cinfo,code,p1,p2) \
  151166. ((cinfo)->err->msg_code = (code), \
  151167. (cinfo)->err->msg_parm.i[0] = (p1), \
  151168. (cinfo)->err->msg_parm.i[1] = (p2), \
  151169. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  151170. #define TRACEMS(cinfo,lvl,code) \
  151171. ((cinfo)->err->msg_code = (code), \
  151172. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  151173. #define TRACEMS1(cinfo,lvl,code,p1) \
  151174. ((cinfo)->err->msg_code = (code), \
  151175. (cinfo)->err->msg_parm.i[0] = (p1), \
  151176. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  151177. #define TRACEMS2(cinfo,lvl,code,p1,p2) \
  151178. ((cinfo)->err->msg_code = (code), \
  151179. (cinfo)->err->msg_parm.i[0] = (p1), \
  151180. (cinfo)->err->msg_parm.i[1] = (p2), \
  151181. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  151182. #define TRACEMS3(cinfo,lvl,code,p1,p2,p3) \
  151183. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  151184. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); \
  151185. (cinfo)->err->msg_code = (code); \
  151186. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  151187. #define TRACEMS4(cinfo,lvl,code,p1,p2,p3,p4) \
  151188. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  151189. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  151190. (cinfo)->err->msg_code = (code); \
  151191. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  151192. #define TRACEMS5(cinfo,lvl,code,p1,p2,p3,p4,p5) \
  151193. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  151194. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  151195. _mp[4] = (p5); \
  151196. (cinfo)->err->msg_code = (code); \
  151197. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  151198. #define TRACEMS8(cinfo,lvl,code,p1,p2,p3,p4,p5,p6,p7,p8) \
  151199. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  151200. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  151201. _mp[4] = (p5); _mp[5] = (p6); _mp[6] = (p7); _mp[7] = (p8); \
  151202. (cinfo)->err->msg_code = (code); \
  151203. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  151204. #define TRACEMSS(cinfo,lvl,code,str) \
  151205. ((cinfo)->err->msg_code = (code), \
  151206. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  151207. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  151208. #endif /* JERROR_H */
  151209. /*** End of inlined file: jerror.h ***/
  151210. typedef struct {
  151211. struct jpeg_source_mgr pub; /* public fields */
  151212. FILE * infile; /* source stream */
  151213. JOCTET * buffer; /* start of buffer */
  151214. boolean start_of_file; /* have we gotten any data yet? */
  151215. } my_source_mgr;
  151216. typedef my_source_mgr * my_src_ptr;
  151217. #define INPUT_BUF_SIZE 4096 /* choose an efficiently fread'able size */
  151218. METHODDEF(void)
  151219. init_source (j_decompress_ptr cinfo)
  151220. {
  151221. my_src_ptr src = (my_src_ptr) cinfo->src;
  151222. src->start_of_file = TRUE;
  151223. }
  151224. METHODDEF(boolean)
  151225. fill_input_buffer (j_decompress_ptr cinfo)
  151226. {
  151227. my_src_ptr src = (my_src_ptr) cinfo->src;
  151228. size_t nbytes;
  151229. nbytes = JFREAD(src->infile, src->buffer, INPUT_BUF_SIZE);
  151230. if (nbytes <= 0) {
  151231. if (src->start_of_file) /* Treat empty input file as fatal error */
  151232. ERREXIT(cinfo, JERR_INPUT_EMPTY);
  151233. WARNMS(cinfo, JWRN_JPEG_EOF);
  151234. src->buffer[0] = (JOCTET) 0xFF;
  151235. src->buffer[1] = (JOCTET) JPEG_EOI;
  151236. nbytes = 2;
  151237. }
  151238. src->pub.next_input_byte = src->buffer;
  151239. src->pub.bytes_in_buffer = nbytes;
  151240. src->start_of_file = FALSE;
  151241. return TRUE;
  151242. }
  151243. METHODDEF(void)
  151244. skip_input_data (j_decompress_ptr cinfo, long num_bytes)
  151245. {
  151246. my_src_ptr src = (my_src_ptr) cinfo->src;
  151247. if (num_bytes > 0) {
  151248. while (num_bytes > (long) src->pub.bytes_in_buffer) {
  151249. num_bytes -= (long) src->pub.bytes_in_buffer;
  151250. (void) fill_input_buffer(cinfo);
  151251. }
  151252. src->pub.next_input_byte += (size_t) num_bytes;
  151253. src->pub.bytes_in_buffer -= (size_t) num_bytes;
  151254. }
  151255. }
  151256. METHODDEF(void)
  151257. term_source (j_decompress_ptr cinfo)
  151258. {
  151259. }
  151260. GLOBAL(void)
  151261. jpeg_stdio_src (j_decompress_ptr cinfo, FILE * infile)
  151262. {
  151263. my_src_ptr src;
  151264. if (cinfo->src == NULL) { /* first time for this JPEG object? */
  151265. cinfo->src = (struct jpeg_source_mgr *)
  151266. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  151267. SIZEOF(my_source_mgr));
  151268. src = (my_src_ptr) cinfo->src;
  151269. src->buffer = (JOCTET *)
  151270. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  151271. INPUT_BUF_SIZE * SIZEOF(JOCTET));
  151272. }
  151273. src = (my_src_ptr) cinfo->src;
  151274. src->pub.init_source = init_source;
  151275. src->pub.fill_input_buffer = fill_input_buffer;
  151276. src->pub.skip_input_data = skip_input_data;
  151277. src->pub.resync_to_restart = jpeg_resync_to_restart; /* use default method */
  151278. src->pub.term_source = term_source;
  151279. src->infile = infile;
  151280. src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */
  151281. src->pub.next_input_byte = NULL; /* until buffer loaded */
  151282. }
  151283. /*** End of inlined file: jdatasrc.c ***/
  151284. /*** Start of inlined file: jdcoefct.c ***/
  151285. #define JPEG_INTERNALS
  151286. #ifndef D_PROGRESSIVE_SUPPORTED
  151287. #undef BLOCK_SMOOTHING_SUPPORTED
  151288. #endif
  151289. typedef struct {
  151290. struct jpeg_d_coef_controller pub; /* public fields */
  151291. JDIMENSION MCU_ctr; /* counts MCUs processed in current row */
  151292. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  151293. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  151294. JBLOCKROW MCU_buffer[D_MAX_BLOCKS_IN_MCU];
  151295. #ifdef D_MULTISCAN_FILES_SUPPORTED
  151296. jvirt_barray_ptr whole_image[MAX_COMPONENTS];
  151297. #endif
  151298. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151299. int * coef_bits_latch;
  151300. #define SAVED_COEFS 6 /* we save coef_bits[0..5] */
  151301. #endif
  151302. } my_coef_controller3;
  151303. typedef my_coef_controller3 * my_coef_ptr3;
  151304. METHODDEF(int) decompress_onepass
  151305. JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
  151306. #ifdef D_MULTISCAN_FILES_SUPPORTED
  151307. METHODDEF(int) decompress_data
  151308. JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
  151309. #endif
  151310. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151311. LOCAL(boolean) smoothing_ok JPP((j_decompress_ptr cinfo));
  151312. METHODDEF(int) decompress_smooth_data
  151313. JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
  151314. #endif
  151315. LOCAL(void)
  151316. start_iMCU_row3 (j_decompress_ptr cinfo)
  151317. {
  151318. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151319. if (cinfo->comps_in_scan > 1) {
  151320. coef->MCU_rows_per_iMCU_row = 1;
  151321. } else {
  151322. if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
  151323. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  151324. else
  151325. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  151326. }
  151327. coef->MCU_ctr = 0;
  151328. coef->MCU_vert_offset = 0;
  151329. }
  151330. METHODDEF(void)
  151331. start_input_pass (j_decompress_ptr cinfo)
  151332. {
  151333. cinfo->input_iMCU_row = 0;
  151334. start_iMCU_row3(cinfo);
  151335. }
  151336. METHODDEF(void)
  151337. start_output_pass (j_decompress_ptr cinfo)
  151338. {
  151339. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151340. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151341. if (coef->pub.coef_arrays != NULL) {
  151342. if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
  151343. coef->pub.decompress_data = decompress_smooth_data;
  151344. else
  151345. coef->pub.decompress_data = decompress_data;
  151346. }
  151347. #endif
  151348. cinfo->output_iMCU_row = 0;
  151349. }
  151350. METHODDEF(int)
  151351. decompress_onepass (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
  151352. {
  151353. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151354. JDIMENSION MCU_col_num; /* index of current MCU within row */
  151355. JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  151356. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  151357. int blkn, ci, xindex, yindex, yoffset, useful_width;
  151358. JSAMPARRAY output_ptr;
  151359. JDIMENSION start_col, output_col;
  151360. jpeg_component_info *compptr;
  151361. inverse_DCT_method_ptr inverse_DCT;
  151362. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  151363. yoffset++) {
  151364. for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
  151365. MCU_col_num++) {
  151366. jzero_far((void FAR *) coef->MCU_buffer[0],
  151367. (size_t) (cinfo->blocks_in_MCU * SIZEOF(JBLOCK)));
  151368. if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
  151369. coef->MCU_vert_offset = yoffset;
  151370. coef->MCU_ctr = MCU_col_num;
  151371. return JPEG_SUSPENDED;
  151372. }
  151373. blkn = 0; /* index of current DCT block within MCU */
  151374. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  151375. compptr = cinfo->cur_comp_info[ci];
  151376. if (! compptr->component_needed) {
  151377. blkn += compptr->MCU_blocks;
  151378. continue;
  151379. }
  151380. inverse_DCT = cinfo->idct->inverse_DCT[compptr->component_index];
  151381. useful_width = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  151382. : compptr->last_col_width;
  151383. output_ptr = output_buf[compptr->component_index] +
  151384. yoffset * compptr->DCT_scaled_size;
  151385. start_col = MCU_col_num * compptr->MCU_sample_width;
  151386. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  151387. if (cinfo->input_iMCU_row < last_iMCU_row ||
  151388. yoffset+yindex < compptr->last_row_height) {
  151389. output_col = start_col;
  151390. for (xindex = 0; xindex < useful_width; xindex++) {
  151391. (*inverse_DCT) (cinfo, compptr,
  151392. (JCOEFPTR) coef->MCU_buffer[blkn+xindex],
  151393. output_ptr, output_col);
  151394. output_col += compptr->DCT_scaled_size;
  151395. }
  151396. }
  151397. blkn += compptr->MCU_width;
  151398. output_ptr += compptr->DCT_scaled_size;
  151399. }
  151400. }
  151401. }
  151402. coef->MCU_ctr = 0;
  151403. }
  151404. cinfo->output_iMCU_row++;
  151405. if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
  151406. start_iMCU_row3(cinfo);
  151407. return JPEG_ROW_COMPLETED;
  151408. }
  151409. (*cinfo->inputctl->finish_input_pass) (cinfo);
  151410. return JPEG_SCAN_COMPLETED;
  151411. }
  151412. METHODDEF(int)
  151413. dummy_consume_data (j_decompress_ptr cinfo)
  151414. {
  151415. return JPEG_SUSPENDED; /* Always indicate nothing was done */
  151416. }
  151417. #ifdef D_MULTISCAN_FILES_SUPPORTED
  151418. METHODDEF(int)
  151419. consume_data (j_decompress_ptr cinfo)
  151420. {
  151421. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151422. JDIMENSION MCU_col_num; /* index of current MCU within row */
  151423. int blkn, ci, xindex, yindex, yoffset;
  151424. JDIMENSION start_col;
  151425. JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  151426. JBLOCKROW buffer_ptr;
  151427. jpeg_component_info *compptr;
  151428. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  151429. compptr = cinfo->cur_comp_info[ci];
  151430. buffer[ci] = (*cinfo->mem->access_virt_barray)
  151431. ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  151432. cinfo->input_iMCU_row * compptr->v_samp_factor,
  151433. (JDIMENSION) compptr->v_samp_factor, TRUE);
  151434. }
  151435. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  151436. yoffset++) {
  151437. for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
  151438. MCU_col_num++) {
  151439. blkn = 0; /* index of current DCT block within MCU */
  151440. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  151441. compptr = cinfo->cur_comp_info[ci];
  151442. start_col = MCU_col_num * compptr->MCU_width;
  151443. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  151444. buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  151445. for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
  151446. coef->MCU_buffer[blkn++] = buffer_ptr++;
  151447. }
  151448. }
  151449. }
  151450. if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
  151451. coef->MCU_vert_offset = yoffset;
  151452. coef->MCU_ctr = MCU_col_num;
  151453. return JPEG_SUSPENDED;
  151454. }
  151455. }
  151456. coef->MCU_ctr = 0;
  151457. }
  151458. if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
  151459. start_iMCU_row3(cinfo);
  151460. return JPEG_ROW_COMPLETED;
  151461. }
  151462. (*cinfo->inputctl->finish_input_pass) (cinfo);
  151463. return JPEG_SCAN_COMPLETED;
  151464. }
  151465. METHODDEF(int)
  151466. decompress_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
  151467. {
  151468. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151469. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  151470. JDIMENSION block_num;
  151471. int ci, block_row, block_rows;
  151472. JBLOCKARRAY buffer;
  151473. JBLOCKROW buffer_ptr;
  151474. JSAMPARRAY output_ptr;
  151475. JDIMENSION output_col;
  151476. jpeg_component_info *compptr;
  151477. inverse_DCT_method_ptr inverse_DCT;
  151478. while (cinfo->input_scan_number < cinfo->output_scan_number ||
  151479. (cinfo->input_scan_number == cinfo->output_scan_number &&
  151480. cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
  151481. if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED)
  151482. return JPEG_SUSPENDED;
  151483. }
  151484. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151485. ci++, compptr++) {
  151486. if (! compptr->component_needed)
  151487. continue;
  151488. buffer = (*cinfo->mem->access_virt_barray)
  151489. ((j_common_ptr) cinfo, coef->whole_image[ci],
  151490. cinfo->output_iMCU_row * compptr->v_samp_factor,
  151491. (JDIMENSION) compptr->v_samp_factor, FALSE);
  151492. if (cinfo->output_iMCU_row < last_iMCU_row)
  151493. block_rows = compptr->v_samp_factor;
  151494. else {
  151495. block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  151496. if (block_rows == 0) block_rows = compptr->v_samp_factor;
  151497. }
  151498. inverse_DCT = cinfo->idct->inverse_DCT[ci];
  151499. output_ptr = output_buf[ci];
  151500. for (block_row = 0; block_row < block_rows; block_row++) {
  151501. buffer_ptr = buffer[block_row];
  151502. output_col = 0;
  151503. for (block_num = 0; block_num < compptr->width_in_blocks; block_num++) {
  151504. (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) buffer_ptr,
  151505. output_ptr, output_col);
  151506. buffer_ptr++;
  151507. output_col += compptr->DCT_scaled_size;
  151508. }
  151509. output_ptr += compptr->DCT_scaled_size;
  151510. }
  151511. }
  151512. if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
  151513. return JPEG_ROW_COMPLETED;
  151514. return JPEG_SCAN_COMPLETED;
  151515. }
  151516. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  151517. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151518. #define Q01_POS 1
  151519. #define Q10_POS 8
  151520. #define Q20_POS 16
  151521. #define Q11_POS 9
  151522. #define Q02_POS 2
  151523. LOCAL(boolean)
  151524. smoothing_ok (j_decompress_ptr cinfo)
  151525. {
  151526. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151527. boolean smoothing_useful = FALSE;
  151528. int ci, coefi;
  151529. jpeg_component_info *compptr;
  151530. JQUANT_TBL * qtable;
  151531. int * coef_bits;
  151532. int * coef_bits_latch;
  151533. if (! cinfo->progressive_mode || cinfo->coef_bits == NULL)
  151534. return FALSE;
  151535. if (coef->coef_bits_latch == NULL)
  151536. coef->coef_bits_latch = (int *)
  151537. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151538. cinfo->num_components *
  151539. (SAVED_COEFS * SIZEOF(int)));
  151540. coef_bits_latch = coef->coef_bits_latch;
  151541. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151542. ci++, compptr++) {
  151543. if ((qtable = compptr->quant_table) == NULL)
  151544. return FALSE;
  151545. if (qtable->quantval[0] == 0 ||
  151546. qtable->quantval[Q01_POS] == 0 ||
  151547. qtable->quantval[Q10_POS] == 0 ||
  151548. qtable->quantval[Q20_POS] == 0 ||
  151549. qtable->quantval[Q11_POS] == 0 ||
  151550. qtable->quantval[Q02_POS] == 0)
  151551. return FALSE;
  151552. coef_bits = cinfo->coef_bits[ci];
  151553. if (coef_bits[0] < 0)
  151554. return FALSE;
  151555. for (coefi = 1; coefi <= 5; coefi++) {
  151556. coef_bits_latch[coefi] = coef_bits[coefi];
  151557. if (coef_bits[coefi] != 0)
  151558. smoothing_useful = TRUE;
  151559. }
  151560. coef_bits_latch += SAVED_COEFS;
  151561. }
  151562. return smoothing_useful;
  151563. }
  151564. METHODDEF(int)
  151565. decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
  151566. {
  151567. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151568. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  151569. JDIMENSION block_num, last_block_column;
  151570. int ci, block_row, block_rows, access_rows;
  151571. JBLOCKARRAY buffer;
  151572. JBLOCKROW buffer_ptr, prev_block_row, next_block_row;
  151573. JSAMPARRAY output_ptr;
  151574. JDIMENSION output_col;
  151575. jpeg_component_info *compptr;
  151576. inverse_DCT_method_ptr inverse_DCT;
  151577. boolean first_row, last_row;
  151578. JBLOCK workspace;
  151579. int *coef_bits;
  151580. JQUANT_TBL *quanttbl;
  151581. INT32 Q00,Q01,Q02,Q10,Q11,Q20, num;
  151582. int DC1,DC2,DC3,DC4,DC5,DC6,DC7,DC8,DC9;
  151583. int Al, pred;
  151584. while (cinfo->input_scan_number <= cinfo->output_scan_number &&
  151585. ! cinfo->inputctl->eoi_reached) {
  151586. if (cinfo->input_scan_number == cinfo->output_scan_number) {
  151587. JDIMENSION delta = (cinfo->Ss == 0) ? 1 : 0;
  151588. if (cinfo->input_iMCU_row > cinfo->output_iMCU_row+delta)
  151589. break;
  151590. }
  151591. if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED)
  151592. return JPEG_SUSPENDED;
  151593. }
  151594. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151595. ci++, compptr++) {
  151596. if (! compptr->component_needed)
  151597. continue;
  151598. if (cinfo->output_iMCU_row < last_iMCU_row) {
  151599. block_rows = compptr->v_samp_factor;
  151600. access_rows = block_rows * 2; /* this and next iMCU row */
  151601. last_row = FALSE;
  151602. } else {
  151603. block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  151604. if (block_rows == 0) block_rows = compptr->v_samp_factor;
  151605. access_rows = block_rows; /* this iMCU row only */
  151606. last_row = TRUE;
  151607. }
  151608. if (cinfo->output_iMCU_row > 0) {
  151609. access_rows += compptr->v_samp_factor; /* prior iMCU row too */
  151610. buffer = (*cinfo->mem->access_virt_barray)
  151611. ((j_common_ptr) cinfo, coef->whole_image[ci],
  151612. (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
  151613. (JDIMENSION) access_rows, FALSE);
  151614. buffer += compptr->v_samp_factor; /* point to current iMCU row */
  151615. first_row = FALSE;
  151616. } else {
  151617. buffer = (*cinfo->mem->access_virt_barray)
  151618. ((j_common_ptr) cinfo, coef->whole_image[ci],
  151619. (JDIMENSION) 0, (JDIMENSION) access_rows, FALSE);
  151620. first_row = TRUE;
  151621. }
  151622. coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
  151623. quanttbl = compptr->quant_table;
  151624. Q00 = quanttbl->quantval[0];
  151625. Q01 = quanttbl->quantval[Q01_POS];
  151626. Q10 = quanttbl->quantval[Q10_POS];
  151627. Q20 = quanttbl->quantval[Q20_POS];
  151628. Q11 = quanttbl->quantval[Q11_POS];
  151629. Q02 = quanttbl->quantval[Q02_POS];
  151630. inverse_DCT = cinfo->idct->inverse_DCT[ci];
  151631. output_ptr = output_buf[ci];
  151632. for (block_row = 0; block_row < block_rows; block_row++) {
  151633. buffer_ptr = buffer[block_row];
  151634. if (first_row && block_row == 0)
  151635. prev_block_row = buffer_ptr;
  151636. else
  151637. prev_block_row = buffer[block_row-1];
  151638. if (last_row && block_row == block_rows-1)
  151639. next_block_row = buffer_ptr;
  151640. else
  151641. next_block_row = buffer[block_row+1];
  151642. DC1 = DC2 = DC3 = (int) prev_block_row[0][0];
  151643. DC4 = DC5 = DC6 = (int) buffer_ptr[0][0];
  151644. DC7 = DC8 = DC9 = (int) next_block_row[0][0];
  151645. output_col = 0;
  151646. last_block_column = compptr->width_in_blocks - 1;
  151647. for (block_num = 0; block_num <= last_block_column; block_num++) {
  151648. jcopy_block_row(buffer_ptr, (JBLOCKROW) workspace, (JDIMENSION) 1);
  151649. if (block_num < last_block_column) {
  151650. DC3 = (int) prev_block_row[1][0];
  151651. DC6 = (int) buffer_ptr[1][0];
  151652. DC9 = (int) next_block_row[1][0];
  151653. }
  151654. if ((Al=coef_bits[1]) != 0 && workspace[1] == 0) {
  151655. num = 36 * Q00 * (DC4 - DC6);
  151656. if (num >= 0) {
  151657. pred = (int) (((Q01<<7) + num) / (Q01<<8));
  151658. if (Al > 0 && pred >= (1<<Al))
  151659. pred = (1<<Al)-1;
  151660. } else {
  151661. pred = (int) (((Q01<<7) - num) / (Q01<<8));
  151662. if (Al > 0 && pred >= (1<<Al))
  151663. pred = (1<<Al)-1;
  151664. pred = -pred;
  151665. }
  151666. workspace[1] = (JCOEF) pred;
  151667. }
  151668. if ((Al=coef_bits[2]) != 0 && workspace[8] == 0) {
  151669. num = 36 * Q00 * (DC2 - DC8);
  151670. if (num >= 0) {
  151671. pred = (int) (((Q10<<7) + num) / (Q10<<8));
  151672. if (Al > 0 && pred >= (1<<Al))
  151673. pred = (1<<Al)-1;
  151674. } else {
  151675. pred = (int) (((Q10<<7) - num) / (Q10<<8));
  151676. if (Al > 0 && pred >= (1<<Al))
  151677. pred = (1<<Al)-1;
  151678. pred = -pred;
  151679. }
  151680. workspace[8] = (JCOEF) pred;
  151681. }
  151682. if ((Al=coef_bits[3]) != 0 && workspace[16] == 0) {
  151683. num = 9 * Q00 * (DC2 + DC8 - 2*DC5);
  151684. if (num >= 0) {
  151685. pred = (int) (((Q20<<7) + num) / (Q20<<8));
  151686. if (Al > 0 && pred >= (1<<Al))
  151687. pred = (1<<Al)-1;
  151688. } else {
  151689. pred = (int) (((Q20<<7) - num) / (Q20<<8));
  151690. if (Al > 0 && pred >= (1<<Al))
  151691. pred = (1<<Al)-1;
  151692. pred = -pred;
  151693. }
  151694. workspace[16] = (JCOEF) pred;
  151695. }
  151696. if ((Al=coef_bits[4]) != 0 && workspace[9] == 0) {
  151697. num = 5 * Q00 * (DC1 - DC3 - DC7 + DC9);
  151698. if (num >= 0) {
  151699. pred = (int) (((Q11<<7) + num) / (Q11<<8));
  151700. if (Al > 0 && pred >= (1<<Al))
  151701. pred = (1<<Al)-1;
  151702. } else {
  151703. pred = (int) (((Q11<<7) - num) / (Q11<<8));
  151704. if (Al > 0 && pred >= (1<<Al))
  151705. pred = (1<<Al)-1;
  151706. pred = -pred;
  151707. }
  151708. workspace[9] = (JCOEF) pred;
  151709. }
  151710. if ((Al=coef_bits[5]) != 0 && workspace[2] == 0) {
  151711. num = 9 * Q00 * (DC4 + DC6 - 2*DC5);
  151712. if (num >= 0) {
  151713. pred = (int) (((Q02<<7) + num) / (Q02<<8));
  151714. if (Al > 0 && pred >= (1<<Al))
  151715. pred = (1<<Al)-1;
  151716. } else {
  151717. pred = (int) (((Q02<<7) - num) / (Q02<<8));
  151718. if (Al > 0 && pred >= (1<<Al))
  151719. pred = (1<<Al)-1;
  151720. pred = -pred;
  151721. }
  151722. workspace[2] = (JCOEF) pred;
  151723. }
  151724. (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) workspace,
  151725. output_ptr, output_col);
  151726. DC1 = DC2; DC2 = DC3;
  151727. DC4 = DC5; DC5 = DC6;
  151728. DC7 = DC8; DC8 = DC9;
  151729. buffer_ptr++, prev_block_row++, next_block_row++;
  151730. output_col += compptr->DCT_scaled_size;
  151731. }
  151732. output_ptr += compptr->DCT_scaled_size;
  151733. }
  151734. }
  151735. if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
  151736. return JPEG_ROW_COMPLETED;
  151737. return JPEG_SCAN_COMPLETED;
  151738. }
  151739. #endif /* BLOCK_SMOOTHING_SUPPORTED */
  151740. GLOBAL(void)
  151741. jinit_d_coef_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  151742. {
  151743. my_coef_ptr3 coef;
  151744. coef = (my_coef_ptr3)
  151745. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151746. SIZEOF(my_coef_controller3));
  151747. cinfo->coef = (struct jpeg_d_coef_controller *) coef;
  151748. coef->pub.start_input_pass = start_input_pass;
  151749. coef->pub.start_output_pass = start_output_pass;
  151750. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151751. coef->coef_bits_latch = NULL;
  151752. #endif
  151753. if (need_full_buffer) {
  151754. #ifdef D_MULTISCAN_FILES_SUPPORTED
  151755. int ci, access_rows;
  151756. jpeg_component_info *compptr;
  151757. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151758. ci++, compptr++) {
  151759. access_rows = compptr->v_samp_factor;
  151760. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151761. if (cinfo->progressive_mode)
  151762. access_rows *= 3;
  151763. #endif
  151764. coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
  151765. ((j_common_ptr) cinfo, JPOOL_IMAGE, TRUE,
  151766. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  151767. (long) compptr->h_samp_factor),
  151768. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  151769. (long) compptr->v_samp_factor),
  151770. (JDIMENSION) access_rows);
  151771. }
  151772. coef->pub.consume_data = consume_data;
  151773. coef->pub.decompress_data = decompress_data;
  151774. coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
  151775. #else
  151776. ERREXIT(cinfo, JERR_NOT_COMPILED);
  151777. #endif
  151778. } else {
  151779. JBLOCKROW buffer;
  151780. int i;
  151781. buffer = (JBLOCKROW)
  151782. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151783. D_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  151784. for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
  151785. coef->MCU_buffer[i] = buffer + i;
  151786. }
  151787. coef->pub.consume_data = dummy_consume_data;
  151788. coef->pub.decompress_data = decompress_onepass;
  151789. coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
  151790. }
  151791. }
  151792. /*** End of inlined file: jdcoefct.c ***/
  151793. #undef FIX
  151794. /*** Start of inlined file: jdcolor.c ***/
  151795. #define JPEG_INTERNALS
  151796. typedef struct {
  151797. struct jpeg_color_deconverter pub; /* public fields */
  151798. int * Cr_r_tab; /* => table for Cr to R conversion */
  151799. int * Cb_b_tab; /* => table for Cb to B conversion */
  151800. INT32 * Cr_g_tab; /* => table for Cr to G conversion */
  151801. INT32 * Cb_g_tab; /* => table for Cb to G conversion */
  151802. } my_color_deconverter2;
  151803. typedef my_color_deconverter2 * my_cconvert_ptr2;
  151804. #define SCALEBITS 16 /* speediest right-shift on some machines */
  151805. #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
  151806. #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
  151807. LOCAL(void)
  151808. build_ycc_rgb_table (j_decompress_ptr cinfo)
  151809. {
  151810. my_cconvert_ptr2 cconvert = (my_cconvert_ptr2) cinfo->cconvert;
  151811. int i;
  151812. INT32 x;
  151813. SHIFT_TEMPS
  151814. cconvert->Cr_r_tab = (int *)
  151815. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151816. (MAXJSAMPLE+1) * SIZEOF(int));
  151817. cconvert->Cb_b_tab = (int *)
  151818. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151819. (MAXJSAMPLE+1) * SIZEOF(int));
  151820. cconvert->Cr_g_tab = (INT32 *)
  151821. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151822. (MAXJSAMPLE+1) * SIZEOF(INT32));
  151823. cconvert->Cb_g_tab = (INT32 *)
  151824. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151825. (MAXJSAMPLE+1) * SIZEOF(INT32));
  151826. for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
  151827. cconvert->Cr_r_tab[i] = (int)
  151828. RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
  151829. cconvert->Cb_b_tab[i] = (int)
  151830. RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
  151831. cconvert->Cr_g_tab[i] = (- FIX(0.71414)) * x;
  151832. cconvert->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF;
  151833. }
  151834. }
  151835. METHODDEF(void)
  151836. ycc_rgb_convert (j_decompress_ptr cinfo,
  151837. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151838. JSAMPARRAY output_buf, int num_rows)
  151839. {
  151840. my_cconvert_ptr2 cconvert = (my_cconvert_ptr2) cinfo->cconvert;
  151841. register int y, cb, cr;
  151842. register JSAMPROW outptr;
  151843. register JSAMPROW inptr0, inptr1, inptr2;
  151844. register JDIMENSION col;
  151845. JDIMENSION num_cols = cinfo->output_width;
  151846. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  151847. register int * Crrtab = cconvert->Cr_r_tab;
  151848. register int * Cbbtab = cconvert->Cb_b_tab;
  151849. register INT32 * Crgtab = cconvert->Cr_g_tab;
  151850. register INT32 * Cbgtab = cconvert->Cb_g_tab;
  151851. SHIFT_TEMPS
  151852. while (--num_rows >= 0) {
  151853. inptr0 = input_buf[0][input_row];
  151854. inptr1 = input_buf[1][input_row];
  151855. inptr2 = input_buf[2][input_row];
  151856. input_row++;
  151857. outptr = *output_buf++;
  151858. for (col = 0; col < num_cols; col++) {
  151859. y = GETJSAMPLE(inptr0[col]);
  151860. cb = GETJSAMPLE(inptr1[col]);
  151861. cr = GETJSAMPLE(inptr2[col]);
  151862. outptr[RGB_RED] = range_limit[y + Crrtab[cr]];
  151863. outptr[RGB_GREEN] = range_limit[y +
  151864. ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
  151865. SCALEBITS))];
  151866. outptr[RGB_BLUE] = range_limit[y + Cbbtab[cb]];
  151867. outptr += RGB_PIXELSIZE;
  151868. }
  151869. }
  151870. }
  151871. METHODDEF(void)
  151872. null_convert2 (j_decompress_ptr cinfo,
  151873. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151874. JSAMPARRAY output_buf, int num_rows)
  151875. {
  151876. register JSAMPROW inptr, outptr;
  151877. register JDIMENSION count;
  151878. register int num_components = cinfo->num_components;
  151879. JDIMENSION num_cols = cinfo->output_width;
  151880. int ci;
  151881. while (--num_rows >= 0) {
  151882. for (ci = 0; ci < num_components; ci++) {
  151883. inptr = input_buf[ci][input_row];
  151884. outptr = output_buf[0] + ci;
  151885. for (count = num_cols; count > 0; count--) {
  151886. *outptr = *inptr++; /* needn't bother with GETJSAMPLE() here */
  151887. outptr += num_components;
  151888. }
  151889. }
  151890. input_row++;
  151891. output_buf++;
  151892. }
  151893. }
  151894. METHODDEF(void)
  151895. grayscale_convert2 (j_decompress_ptr cinfo,
  151896. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151897. JSAMPARRAY output_buf, int num_rows)
  151898. {
  151899. jcopy_sample_rows(input_buf[0], (int) input_row, output_buf, 0,
  151900. num_rows, cinfo->output_width);
  151901. }
  151902. METHODDEF(void)
  151903. gray_rgb_convert (j_decompress_ptr cinfo,
  151904. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151905. JSAMPARRAY output_buf, int num_rows)
  151906. {
  151907. register JSAMPROW inptr, outptr;
  151908. register JDIMENSION col;
  151909. JDIMENSION num_cols = cinfo->output_width;
  151910. while (--num_rows >= 0) {
  151911. inptr = input_buf[0][input_row++];
  151912. outptr = *output_buf++;
  151913. for (col = 0; col < num_cols; col++) {
  151914. outptr[RGB_RED] = outptr[RGB_GREEN] = outptr[RGB_BLUE] = inptr[col];
  151915. outptr += RGB_PIXELSIZE;
  151916. }
  151917. }
  151918. }
  151919. METHODDEF(void)
  151920. ycck_cmyk_convert (j_decompress_ptr cinfo,
  151921. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151922. JSAMPARRAY output_buf, int num_rows)
  151923. {
  151924. my_cconvert_ptr2 cconvert = (my_cconvert_ptr2) cinfo->cconvert;
  151925. register int y, cb, cr;
  151926. register JSAMPROW outptr;
  151927. register JSAMPROW inptr0, inptr1, inptr2, inptr3;
  151928. register JDIMENSION col;
  151929. JDIMENSION num_cols = cinfo->output_width;
  151930. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  151931. register int * Crrtab = cconvert->Cr_r_tab;
  151932. register int * Cbbtab = cconvert->Cb_b_tab;
  151933. register INT32 * Crgtab = cconvert->Cr_g_tab;
  151934. register INT32 * Cbgtab = cconvert->Cb_g_tab;
  151935. SHIFT_TEMPS
  151936. while (--num_rows >= 0) {
  151937. inptr0 = input_buf[0][input_row];
  151938. inptr1 = input_buf[1][input_row];
  151939. inptr2 = input_buf[2][input_row];
  151940. inptr3 = input_buf[3][input_row];
  151941. input_row++;
  151942. outptr = *output_buf++;
  151943. for (col = 0; col < num_cols; col++) {
  151944. y = GETJSAMPLE(inptr0[col]);
  151945. cb = GETJSAMPLE(inptr1[col]);
  151946. cr = GETJSAMPLE(inptr2[col]);
  151947. outptr[0] = range_limit[MAXJSAMPLE - (y + Crrtab[cr])]; /* red */
  151948. outptr[1] = range_limit[MAXJSAMPLE - (y + /* green */
  151949. ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
  151950. SCALEBITS)))];
  151951. outptr[2] = range_limit[MAXJSAMPLE - (y + Cbbtab[cb])]; /* blue */
  151952. outptr[3] = inptr3[col]; /* don't need GETJSAMPLE here */
  151953. outptr += 4;
  151954. }
  151955. }
  151956. }
  151957. METHODDEF(void)
  151958. start_pass_dcolor (j_decompress_ptr cinfo)
  151959. {
  151960. }
  151961. GLOBAL(void)
  151962. jinit_color_deconverter (j_decompress_ptr cinfo)
  151963. {
  151964. my_cconvert_ptr2 cconvert;
  151965. int ci;
  151966. cconvert = (my_cconvert_ptr2)
  151967. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151968. SIZEOF(my_color_deconverter2));
  151969. cinfo->cconvert = (struct jpeg_color_deconverter *) cconvert;
  151970. cconvert->pub.start_pass = start_pass_dcolor;
  151971. switch (cinfo->jpeg_color_space) {
  151972. case JCS_GRAYSCALE:
  151973. if (cinfo->num_components != 1)
  151974. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151975. break;
  151976. case JCS_RGB:
  151977. case JCS_YCbCr:
  151978. if (cinfo->num_components != 3)
  151979. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151980. break;
  151981. case JCS_CMYK:
  151982. case JCS_YCCK:
  151983. if (cinfo->num_components != 4)
  151984. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151985. break;
  151986. default: /* JCS_UNKNOWN can be anything */
  151987. if (cinfo->num_components < 1)
  151988. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151989. break;
  151990. }
  151991. switch (cinfo->out_color_space) {
  151992. case JCS_GRAYSCALE:
  151993. cinfo->out_color_components = 1;
  151994. if (cinfo->jpeg_color_space == JCS_GRAYSCALE ||
  151995. cinfo->jpeg_color_space == JCS_YCbCr) {
  151996. cconvert->pub.color_convert = grayscale_convert2;
  151997. for (ci = 1; ci < cinfo->num_components; ci++)
  151998. cinfo->comp_info[ci].component_needed = FALSE;
  151999. } else
  152000. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  152001. break;
  152002. case JCS_RGB:
  152003. cinfo->out_color_components = RGB_PIXELSIZE;
  152004. if (cinfo->jpeg_color_space == JCS_YCbCr) {
  152005. cconvert->pub.color_convert = ycc_rgb_convert;
  152006. build_ycc_rgb_table(cinfo);
  152007. } else if (cinfo->jpeg_color_space == JCS_GRAYSCALE) {
  152008. cconvert->pub.color_convert = gray_rgb_convert;
  152009. } else if (cinfo->jpeg_color_space == JCS_RGB && RGB_PIXELSIZE == 3) {
  152010. cconvert->pub.color_convert = null_convert2;
  152011. } else
  152012. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  152013. break;
  152014. case JCS_CMYK:
  152015. cinfo->out_color_components = 4;
  152016. if (cinfo->jpeg_color_space == JCS_YCCK) {
  152017. cconvert->pub.color_convert = ycck_cmyk_convert;
  152018. build_ycc_rgb_table(cinfo);
  152019. } else if (cinfo->jpeg_color_space == JCS_CMYK) {
  152020. cconvert->pub.color_convert = null_convert2;
  152021. } else
  152022. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  152023. break;
  152024. default:
  152025. if (cinfo->out_color_space == cinfo->jpeg_color_space) {
  152026. cinfo->out_color_components = cinfo->num_components;
  152027. cconvert->pub.color_convert = null_convert2;
  152028. } else /* unsupported non-null conversion */
  152029. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  152030. break;
  152031. }
  152032. if (cinfo->quantize_colors)
  152033. cinfo->output_components = 1; /* single colormapped output component */
  152034. else
  152035. cinfo->output_components = cinfo->out_color_components;
  152036. }
  152037. /*** End of inlined file: jdcolor.c ***/
  152038. #undef FIX
  152039. /*** Start of inlined file: jddctmgr.c ***/
  152040. #define JPEG_INTERNALS
  152041. typedef struct {
  152042. struct jpeg_inverse_dct pub; /* public fields */
  152043. int cur_method[MAX_COMPONENTS];
  152044. } my_idct_controller;
  152045. typedef my_idct_controller * my_idct_ptr;
  152046. typedef union {
  152047. ISLOW_MULT_TYPE islow_array[DCTSIZE2];
  152048. #ifdef DCT_IFAST_SUPPORTED
  152049. IFAST_MULT_TYPE ifast_array[DCTSIZE2];
  152050. #endif
  152051. #ifdef DCT_FLOAT_SUPPORTED
  152052. FLOAT_MULT_TYPE float_array[DCTSIZE2];
  152053. #endif
  152054. } multiplier_table;
  152055. #ifdef DCT_ISLOW_SUPPORTED
  152056. #define PROVIDE_ISLOW_TABLES
  152057. #else
  152058. #ifdef IDCT_SCALING_SUPPORTED
  152059. #define PROVIDE_ISLOW_TABLES
  152060. #endif
  152061. #endif
  152062. METHODDEF(void)
  152063. start_pass (j_decompress_ptr cinfo)
  152064. {
  152065. my_idct_ptr idct = (my_idct_ptr) cinfo->idct;
  152066. int ci, i;
  152067. jpeg_component_info *compptr;
  152068. int method = 0;
  152069. inverse_DCT_method_ptr method_ptr = NULL;
  152070. JQUANT_TBL * qtbl;
  152071. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152072. ci++, compptr++) {
  152073. switch (compptr->DCT_scaled_size) {
  152074. #ifdef IDCT_SCALING_SUPPORTED
  152075. case 1:
  152076. method_ptr = jpeg_idct_1x1;
  152077. method = JDCT_ISLOW; /* jidctred uses islow-style table */
  152078. break;
  152079. case 2:
  152080. method_ptr = jpeg_idct_2x2;
  152081. method = JDCT_ISLOW; /* jidctred uses islow-style table */
  152082. break;
  152083. case 4:
  152084. method_ptr = jpeg_idct_4x4;
  152085. method = JDCT_ISLOW; /* jidctred uses islow-style table */
  152086. break;
  152087. #endif
  152088. case DCTSIZE:
  152089. switch (cinfo->dct_method) {
  152090. #ifdef DCT_ISLOW_SUPPORTED
  152091. case JDCT_ISLOW:
  152092. method_ptr = jpeg_idct_islow;
  152093. method = JDCT_ISLOW;
  152094. break;
  152095. #endif
  152096. #ifdef DCT_IFAST_SUPPORTED
  152097. case JDCT_IFAST:
  152098. method_ptr = jpeg_idct_ifast;
  152099. method = JDCT_IFAST;
  152100. break;
  152101. #endif
  152102. #ifdef DCT_FLOAT_SUPPORTED
  152103. case JDCT_FLOAT:
  152104. method_ptr = jpeg_idct_float;
  152105. method = JDCT_FLOAT;
  152106. break;
  152107. #endif
  152108. default:
  152109. ERREXIT(cinfo, JERR_NOT_COMPILED);
  152110. break;
  152111. }
  152112. break;
  152113. default:
  152114. ERREXIT1(cinfo, JERR_BAD_DCTSIZE, compptr->DCT_scaled_size);
  152115. break;
  152116. }
  152117. idct->pub.inverse_DCT[ci] = method_ptr;
  152118. if (! compptr->component_needed || idct->cur_method[ci] == method)
  152119. continue;
  152120. qtbl = compptr->quant_table;
  152121. if (qtbl == NULL) /* happens if no data yet for component */
  152122. continue;
  152123. idct->cur_method[ci] = method;
  152124. switch (method) {
  152125. #ifdef PROVIDE_ISLOW_TABLES
  152126. case JDCT_ISLOW:
  152127. {
  152128. ISLOW_MULT_TYPE * ismtbl = (ISLOW_MULT_TYPE *) compptr->dct_table;
  152129. for (i = 0; i < DCTSIZE2; i++) {
  152130. ismtbl[i] = (ISLOW_MULT_TYPE) qtbl->quantval[i];
  152131. }
  152132. }
  152133. break;
  152134. #endif
  152135. #ifdef DCT_IFAST_SUPPORTED
  152136. case JDCT_IFAST:
  152137. {
  152138. IFAST_MULT_TYPE * ifmtbl = (IFAST_MULT_TYPE *) compptr->dct_table;
  152139. #define CONST_BITS 14
  152140. static const INT16 aanscales[DCTSIZE2] = {
  152141. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  152142. 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
  152143. 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
  152144. 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
  152145. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  152146. 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
  152147. 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
  152148. 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
  152149. };
  152150. SHIFT_TEMPS
  152151. for (i = 0; i < DCTSIZE2; i++) {
  152152. ifmtbl[i] = (IFAST_MULT_TYPE)
  152153. DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
  152154. (INT32) aanscales[i]),
  152155. CONST_BITS-IFAST_SCALE_BITS);
  152156. }
  152157. }
  152158. break;
  152159. #endif
  152160. #ifdef DCT_FLOAT_SUPPORTED
  152161. case JDCT_FLOAT:
  152162. {
  152163. FLOAT_MULT_TYPE * fmtbl = (FLOAT_MULT_TYPE *) compptr->dct_table;
  152164. int row, col;
  152165. static const double aanscalefactor[DCTSIZE] = {
  152166. 1.0, 1.387039845, 1.306562965, 1.175875602,
  152167. 1.0, 0.785694958, 0.541196100, 0.275899379
  152168. };
  152169. i = 0;
  152170. for (row = 0; row < DCTSIZE; row++) {
  152171. for (col = 0; col < DCTSIZE; col++) {
  152172. fmtbl[i] = (FLOAT_MULT_TYPE)
  152173. ((double) qtbl->quantval[i] *
  152174. aanscalefactor[row] * aanscalefactor[col]);
  152175. i++;
  152176. }
  152177. }
  152178. }
  152179. break;
  152180. #endif
  152181. default:
  152182. ERREXIT(cinfo, JERR_NOT_COMPILED);
  152183. break;
  152184. }
  152185. }
  152186. }
  152187. GLOBAL(void)
  152188. jinit_inverse_dct (j_decompress_ptr cinfo)
  152189. {
  152190. my_idct_ptr idct;
  152191. int ci;
  152192. jpeg_component_info *compptr;
  152193. idct = (my_idct_ptr)
  152194. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152195. SIZEOF(my_idct_controller));
  152196. cinfo->idct = (struct jpeg_inverse_dct *) idct;
  152197. idct->pub.start_pass = start_pass;
  152198. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152199. ci++, compptr++) {
  152200. compptr->dct_table =
  152201. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152202. SIZEOF(multiplier_table));
  152203. MEMZERO(compptr->dct_table, SIZEOF(multiplier_table));
  152204. idct->cur_method[ci] = -1;
  152205. }
  152206. }
  152207. /*** End of inlined file: jddctmgr.c ***/
  152208. #undef CONST_BITS
  152209. #undef ASSIGN_STATE
  152210. /*** Start of inlined file: jdhuff.c ***/
  152211. #define JPEG_INTERNALS
  152212. /*** Start of inlined file: jdhuff.h ***/
  152213. #ifndef __jdhuff_h__
  152214. #define __jdhuff_h__
  152215. #ifdef NEED_SHORT_EXTERNAL_NAMES
  152216. #define jpeg_make_d_derived_tbl jMkDDerived
  152217. #define jpeg_fill_bit_buffer jFilBitBuf
  152218. #define jpeg_huff_decode jHufDecode
  152219. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  152220. #define HUFF_LOOKAHEAD 8 /* # of bits of lookahead */
  152221. typedef struct {
  152222. INT32 maxcode[18]; /* largest code of length k (-1 if none) */
  152223. INT32 valoffset[17]; /* huffval[] offset for codes of length k */
  152224. JHUFF_TBL *pub;
  152225. int look_nbits[1<<HUFF_LOOKAHEAD]; /* # bits, or 0 if too long */
  152226. UINT8 look_sym[1<<HUFF_LOOKAHEAD]; /* symbol, or unused */
  152227. } d_derived_tbl;
  152228. EXTERN(void) jpeg_make_d_derived_tbl
  152229. JPP((j_decompress_ptr cinfo, boolean isDC, int tblno,
  152230. d_derived_tbl ** pdtbl));
  152231. typedef INT32 bit_buf_type; /* type of bit-extraction buffer */
  152232. #define BIT_BUF_SIZE 32 /* size of buffer in bits */
  152233. typedef struct { /* Bitreading state saved across MCUs */
  152234. bit_buf_type get_buffer; /* current bit-extraction buffer */
  152235. int bits_left; /* # of unused bits in it */
  152236. } bitread_perm_state;
  152237. typedef struct { /* Bitreading working state within an MCU */
  152238. const JOCTET * next_input_byte; /* => next byte to read from source */
  152239. size_t bytes_in_buffer; /* # of bytes remaining in source buffer */
  152240. bit_buf_type get_buffer; /* current bit-extraction buffer */
  152241. int bits_left; /* # of unused bits in it */
  152242. j_decompress_ptr cinfo; /* back link to decompress master record */
  152243. } bitread_working_state;
  152244. #define BITREAD_STATE_VARS \
  152245. register bit_buf_type get_buffer; \
  152246. register int bits_left; \
  152247. bitread_working_state br_state
  152248. #define BITREAD_LOAD_STATE(cinfop,permstate) \
  152249. br_state.cinfo = cinfop; \
  152250. br_state.next_input_byte = cinfop->src->next_input_byte; \
  152251. br_state.bytes_in_buffer = cinfop->src->bytes_in_buffer; \
  152252. get_buffer = permstate.get_buffer; \
  152253. bits_left = permstate.bits_left;
  152254. #define BITREAD_SAVE_STATE(cinfop,permstate) \
  152255. cinfop->src->next_input_byte = br_state.next_input_byte; \
  152256. cinfop->src->bytes_in_buffer = br_state.bytes_in_buffer; \
  152257. permstate.get_buffer = get_buffer; \
  152258. permstate.bits_left = bits_left
  152259. #define CHECK_BIT_BUFFER(state,nbits,action) \
  152260. { if (bits_left < (nbits)) { \
  152261. if (! jpeg_fill_bit_buffer(&(state),get_buffer,bits_left,nbits)) \
  152262. { action; } \
  152263. get_buffer = (state).get_buffer; bits_left = (state).bits_left; } }
  152264. #define GET_BITS(nbits) \
  152265. (((int) (get_buffer >> (bits_left -= (nbits)))) & ((1<<(nbits))-1))
  152266. #define PEEK_BITS(nbits) \
  152267. (((int) (get_buffer >> (bits_left - (nbits)))) & ((1<<(nbits))-1))
  152268. #define DROP_BITS(nbits) \
  152269. (bits_left -= (nbits))
  152270. EXTERN(boolean) jpeg_fill_bit_buffer
  152271. JPP((bitread_working_state * state, register bit_buf_type get_buffer,
  152272. register int bits_left, int nbits));
  152273. #define HUFF_DECODE(result,state,htbl,failaction,slowlabel) \
  152274. { register int nb, look; \
  152275. if (bits_left < HUFF_LOOKAHEAD) { \
  152276. if (! jpeg_fill_bit_buffer(&state,get_buffer,bits_left, 0)) {failaction;} \
  152277. get_buffer = state.get_buffer; bits_left = state.bits_left; \
  152278. if (bits_left < HUFF_LOOKAHEAD) { \
  152279. nb = 1; goto slowlabel; \
  152280. } \
  152281. } \
  152282. look = PEEK_BITS(HUFF_LOOKAHEAD); \
  152283. if ((nb = htbl->look_nbits[look]) != 0) { \
  152284. DROP_BITS(nb); \
  152285. result = htbl->look_sym[look]; \
  152286. } else { \
  152287. nb = HUFF_LOOKAHEAD+1; \
  152288. slowlabel: \
  152289. if ((result=jpeg_huff_decode(&state,get_buffer,bits_left,htbl,nb)) < 0) \
  152290. { failaction; } \
  152291. get_buffer = state.get_buffer; bits_left = state.bits_left; \
  152292. } \
  152293. }
  152294. EXTERN(int) jpeg_huff_decode
  152295. JPP((bitread_working_state * state, register bit_buf_type get_buffer,
  152296. register int bits_left, d_derived_tbl * htbl, int min_bits));
  152297. #endif
  152298. /*** End of inlined file: jdhuff.h ***/
  152299. /* Declarations shared with jdphuff.c */
  152300. typedef struct {
  152301. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  152302. } savable_state2;
  152303. #ifndef NO_STRUCT_ASSIGN
  152304. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  152305. #else
  152306. #if MAX_COMPS_IN_SCAN == 4
  152307. #define ASSIGN_STATE(dest,src) \
  152308. ((dest).last_dc_val[0] = (src).last_dc_val[0], \
  152309. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  152310. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  152311. (dest).last_dc_val[3] = (src).last_dc_val[3])
  152312. #endif
  152313. #endif
  152314. typedef struct {
  152315. struct jpeg_entropy_decoder pub; /* public fields */
  152316. bitread_perm_state bitstate; /* Bit buffer at start of MCU */
  152317. savable_state2 saved; /* Other state at start of MCU */
  152318. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  152319. d_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS];
  152320. d_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS];
  152321. d_derived_tbl * dc_cur_tbls[D_MAX_BLOCKS_IN_MCU];
  152322. d_derived_tbl * ac_cur_tbls[D_MAX_BLOCKS_IN_MCU];
  152323. boolean dc_needed[D_MAX_BLOCKS_IN_MCU];
  152324. boolean ac_needed[D_MAX_BLOCKS_IN_MCU];
  152325. } huff_entropy_decoder2;
  152326. typedef huff_entropy_decoder2 * huff_entropy_ptr2;
  152327. METHODDEF(void)
  152328. start_pass_huff_decoder (j_decompress_ptr cinfo)
  152329. {
  152330. huff_entropy_ptr2 entropy = (huff_entropy_ptr2) cinfo->entropy;
  152331. int ci, blkn, dctbl, actbl;
  152332. jpeg_component_info * compptr;
  152333. if (cinfo->Ss != 0 || cinfo->Se != DCTSIZE2-1 ||
  152334. cinfo->Ah != 0 || cinfo->Al != 0)
  152335. WARNMS(cinfo, JWRN_NOT_SEQUENTIAL);
  152336. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  152337. compptr = cinfo->cur_comp_info[ci];
  152338. dctbl = compptr->dc_tbl_no;
  152339. actbl = compptr->ac_tbl_no;
  152340. jpeg_make_d_derived_tbl(cinfo, TRUE, dctbl,
  152341. & entropy->dc_derived_tbls[dctbl]);
  152342. jpeg_make_d_derived_tbl(cinfo, FALSE, actbl,
  152343. & entropy->ac_derived_tbls[actbl]);
  152344. entropy->saved.last_dc_val[ci] = 0;
  152345. }
  152346. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  152347. ci = cinfo->MCU_membership[blkn];
  152348. compptr = cinfo->cur_comp_info[ci];
  152349. entropy->dc_cur_tbls[blkn] = entropy->dc_derived_tbls[compptr->dc_tbl_no];
  152350. entropy->ac_cur_tbls[blkn] = entropy->ac_derived_tbls[compptr->ac_tbl_no];
  152351. if (compptr->component_needed) {
  152352. entropy->dc_needed[blkn] = TRUE;
  152353. entropy->ac_needed[blkn] = (compptr->DCT_scaled_size > 1);
  152354. } else {
  152355. entropy->dc_needed[blkn] = entropy->ac_needed[blkn] = FALSE;
  152356. }
  152357. }
  152358. entropy->bitstate.bits_left = 0;
  152359. entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */
  152360. entropy->pub.insufficient_data = FALSE;
  152361. entropy->restarts_to_go = cinfo->restart_interval;
  152362. }
  152363. GLOBAL(void)
  152364. jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, boolean isDC, int tblno,
  152365. d_derived_tbl ** pdtbl)
  152366. {
  152367. JHUFF_TBL *htbl;
  152368. d_derived_tbl *dtbl;
  152369. int p, i, l, si, numsymbols;
  152370. int lookbits, ctr;
  152371. char huffsize[257];
  152372. unsigned int huffcode[257];
  152373. unsigned int code;
  152374. if (tblno < 0 || tblno >= NUM_HUFF_TBLS)
  152375. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  152376. htbl =
  152377. isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];
  152378. if (htbl == NULL)
  152379. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  152380. if (*pdtbl == NULL)
  152381. *pdtbl = (d_derived_tbl *)
  152382. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152383. SIZEOF(d_derived_tbl));
  152384. dtbl = *pdtbl;
  152385. dtbl->pub = htbl; /* fill in back link */
  152386. p = 0;
  152387. for (l = 1; l <= 16; l++) {
  152388. i = (int) htbl->bits[l];
  152389. if (i < 0 || p + i > 256) /* protect against table overrun */
  152390. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  152391. while (i--)
  152392. huffsize[p++] = (char) l;
  152393. }
  152394. huffsize[p] = 0;
  152395. numsymbols = p;
  152396. code = 0;
  152397. si = huffsize[0];
  152398. p = 0;
  152399. while (huffsize[p]) {
  152400. while (((int) huffsize[p]) == si) {
  152401. huffcode[p++] = code;
  152402. code++;
  152403. }
  152404. if (((INT32) code) >= (((INT32) 1) << si))
  152405. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  152406. code <<= 1;
  152407. si++;
  152408. }
  152409. p = 0;
  152410. for (l = 1; l <= 16; l++) {
  152411. if (htbl->bits[l]) {
  152412. dtbl->valoffset[l] = (INT32) p - (INT32) huffcode[p];
  152413. p += htbl->bits[l];
  152414. dtbl->maxcode[l] = huffcode[p-1]; /* maximum code of length l */
  152415. } else {
  152416. dtbl->maxcode[l] = -1; /* -1 if no codes of this length */
  152417. }
  152418. }
  152419. dtbl->maxcode[17] = 0xFFFFFL; /* ensures jpeg_huff_decode terminates */
  152420. MEMZERO(dtbl->look_nbits, SIZEOF(dtbl->look_nbits));
  152421. p = 0;
  152422. for (l = 1; l <= HUFF_LOOKAHEAD; l++) {
  152423. for (i = 1; i <= (int) htbl->bits[l]; i++, p++) {
  152424. lookbits = huffcode[p] << (HUFF_LOOKAHEAD-l);
  152425. for (ctr = 1 << (HUFF_LOOKAHEAD-l); ctr > 0; ctr--) {
  152426. dtbl->look_nbits[lookbits] = l;
  152427. dtbl->look_sym[lookbits] = htbl->huffval[p];
  152428. lookbits++;
  152429. }
  152430. }
  152431. }
  152432. if (isDC) {
  152433. for (i = 0; i < numsymbols; i++) {
  152434. int sym = htbl->huffval[i];
  152435. if (sym < 0 || sym > 15)
  152436. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  152437. }
  152438. }
  152439. }
  152440. #ifdef SLOW_SHIFT_32
  152441. #define MIN_GET_BITS 15 /* minimum allowable value */
  152442. #else
  152443. #define MIN_GET_BITS (BIT_BUF_SIZE-7)
  152444. #endif
  152445. GLOBAL(boolean)
  152446. jpeg_fill_bit_buffer (bitread_working_state * state,
  152447. register bit_buf_type get_buffer, register int bits_left,
  152448. int nbits)
  152449. {
  152450. register const JOCTET * next_input_byte = state->next_input_byte;
  152451. register size_t bytes_in_buffer = state->bytes_in_buffer;
  152452. j_decompress_ptr cinfo = state->cinfo;
  152453. if (cinfo->unread_marker == 0) { /* cannot advance past a marker */
  152454. while (bits_left < MIN_GET_BITS) {
  152455. register int c;
  152456. if (bytes_in_buffer == 0) {
  152457. if (! (*cinfo->src->fill_input_buffer) (cinfo))
  152458. return FALSE;
  152459. next_input_byte = cinfo->src->next_input_byte;
  152460. bytes_in_buffer = cinfo->src->bytes_in_buffer;
  152461. }
  152462. bytes_in_buffer--;
  152463. c = GETJOCTET(*next_input_byte++);
  152464. if (c == 0xFF) {
  152465. do {
  152466. if (bytes_in_buffer == 0) {
  152467. if (! (*cinfo->src->fill_input_buffer) (cinfo))
  152468. return FALSE;
  152469. next_input_byte = cinfo->src->next_input_byte;
  152470. bytes_in_buffer = cinfo->src->bytes_in_buffer;
  152471. }
  152472. bytes_in_buffer--;
  152473. c = GETJOCTET(*next_input_byte++);
  152474. } while (c == 0xFF);
  152475. if (c == 0) {
  152476. c = 0xFF;
  152477. } else {
  152478. cinfo->unread_marker = c;
  152479. goto no_more_bytes;
  152480. }
  152481. }
  152482. get_buffer = (get_buffer << 8) | c;
  152483. bits_left += 8;
  152484. } /* end while */
  152485. } else {
  152486. no_more_bytes:
  152487. if (nbits > bits_left) {
  152488. if (! cinfo->entropy->insufficient_data) {
  152489. WARNMS(cinfo, JWRN_HIT_MARKER);
  152490. cinfo->entropy->insufficient_data = TRUE;
  152491. }
  152492. get_buffer <<= MIN_GET_BITS - bits_left;
  152493. bits_left = MIN_GET_BITS;
  152494. }
  152495. }
  152496. state->next_input_byte = next_input_byte;
  152497. state->bytes_in_buffer = bytes_in_buffer;
  152498. state->get_buffer = get_buffer;
  152499. state->bits_left = bits_left;
  152500. return TRUE;
  152501. }
  152502. GLOBAL(int)
  152503. jpeg_huff_decode (bitread_working_state * state,
  152504. register bit_buf_type get_buffer, register int bits_left,
  152505. d_derived_tbl * htbl, int min_bits)
  152506. {
  152507. register int l = min_bits;
  152508. register INT32 code;
  152509. CHECK_BIT_BUFFER(*state, l, return -1);
  152510. code = GET_BITS(l);
  152511. while (code > htbl->maxcode[l]) {
  152512. code <<= 1;
  152513. CHECK_BIT_BUFFER(*state, 1, return -1);
  152514. code |= GET_BITS(1);
  152515. l++;
  152516. }
  152517. state->get_buffer = get_buffer;
  152518. state->bits_left = bits_left;
  152519. if (l > 16) {
  152520. WARNMS(state->cinfo, JWRN_HUFF_BAD_CODE);
  152521. return 0; /* fake a zero as the safest result */
  152522. }
  152523. return htbl->pub->huffval[ (int) (code + htbl->valoffset[l]) ];
  152524. }
  152525. LOCAL(boolean)
  152526. process_restart (j_decompress_ptr cinfo)
  152527. {
  152528. huff_entropy_ptr2 entropy = (huff_entropy_ptr2) cinfo->entropy;
  152529. int ci;
  152530. cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8;
  152531. entropy->bitstate.bits_left = 0;
  152532. if (! (*cinfo->marker->read_restart_marker) (cinfo))
  152533. return FALSE;
  152534. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  152535. entropy->saved.last_dc_val[ci] = 0;
  152536. entropy->restarts_to_go = cinfo->restart_interval;
  152537. if (cinfo->unread_marker == 0)
  152538. entropy->pub.insufficient_data = FALSE;
  152539. return TRUE;
  152540. }
  152541. METHODDEF(boolean)
  152542. decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  152543. {
  152544. huff_entropy_ptr2 entropy = (huff_entropy_ptr2) cinfo->entropy;
  152545. int blkn;
  152546. BITREAD_STATE_VARS;
  152547. savable_state2 state;
  152548. if (cinfo->restart_interval) {
  152549. if (entropy->restarts_to_go == 0)
  152550. if (! process_restart(cinfo))
  152551. return FALSE;
  152552. }
  152553. if (! entropy->pub.insufficient_data) {
  152554. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  152555. ASSIGN_STATE(state, entropy->saved);
  152556. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  152557. JBLOCKROW block = MCU_data[blkn];
  152558. d_derived_tbl * dctbl = entropy->dc_cur_tbls[blkn];
  152559. d_derived_tbl * actbl = entropy->ac_cur_tbls[blkn];
  152560. register int s, k, r;
  152561. HUFF_DECODE(s, br_state, dctbl, return FALSE, label1);
  152562. if (s) {
  152563. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  152564. r = GET_BITS(s);
  152565. s = HUFF_EXTEND(r, s);
  152566. }
  152567. if (entropy->dc_needed[blkn]) {
  152568. int ci = cinfo->MCU_membership[blkn];
  152569. s += state.last_dc_val[ci];
  152570. state.last_dc_val[ci] = s;
  152571. (*block)[0] = (JCOEF) s;
  152572. }
  152573. if (entropy->ac_needed[blkn]) {
  152574. for (k = 1; k < DCTSIZE2; k++) {
  152575. HUFF_DECODE(s, br_state, actbl, return FALSE, label2);
  152576. r = s >> 4;
  152577. s &= 15;
  152578. if (s) {
  152579. k += r;
  152580. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  152581. r = GET_BITS(s);
  152582. s = HUFF_EXTEND(r, s);
  152583. (*block)[jpeg_natural_order[k]] = (JCOEF) s;
  152584. } else {
  152585. if (r != 15)
  152586. break;
  152587. k += 15;
  152588. }
  152589. }
  152590. } else {
  152591. for (k = 1; k < DCTSIZE2; k++) {
  152592. HUFF_DECODE(s, br_state, actbl, return FALSE, label3);
  152593. r = s >> 4;
  152594. s &= 15;
  152595. if (s) {
  152596. k += r;
  152597. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  152598. DROP_BITS(s);
  152599. } else {
  152600. if (r != 15)
  152601. break;
  152602. k += 15;
  152603. }
  152604. }
  152605. }
  152606. }
  152607. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  152608. ASSIGN_STATE(entropy->saved, state);
  152609. }
  152610. entropy->restarts_to_go--;
  152611. return TRUE;
  152612. }
  152613. GLOBAL(void)
  152614. jinit_huff_decoder (j_decompress_ptr cinfo)
  152615. {
  152616. huff_entropy_ptr2 entropy;
  152617. int i;
  152618. entropy = (huff_entropy_ptr2)
  152619. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152620. SIZEOF(huff_entropy_decoder2));
  152621. cinfo->entropy = (struct jpeg_entropy_decoder *) entropy;
  152622. entropy->pub.start_pass = start_pass_huff_decoder;
  152623. entropy->pub.decode_mcu = decode_mcu;
  152624. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  152625. entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL;
  152626. }
  152627. }
  152628. /*** End of inlined file: jdhuff.c ***/
  152629. /*** Start of inlined file: jdinput.c ***/
  152630. #define JPEG_INTERNALS
  152631. typedef struct {
  152632. struct jpeg_input_controller pub; /* public fields */
  152633. boolean inheaders; /* TRUE until first SOS is reached */
  152634. } my_input_controller;
  152635. typedef my_input_controller * my_inputctl_ptr;
  152636. METHODDEF(int) consume_markers JPP((j_decompress_ptr cinfo));
  152637. LOCAL(void)
  152638. initial_setup2 (j_decompress_ptr cinfo)
  152639. {
  152640. int ci;
  152641. jpeg_component_info *compptr;
  152642. if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION ||
  152643. (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION)
  152644. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
  152645. if (cinfo->data_precision != BITS_IN_JSAMPLE)
  152646. ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
  152647. if (cinfo->num_components > MAX_COMPONENTS)
  152648. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  152649. MAX_COMPONENTS);
  152650. cinfo->max_h_samp_factor = 1;
  152651. cinfo->max_v_samp_factor = 1;
  152652. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152653. ci++, compptr++) {
  152654. if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||
  152655. compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
  152656. ERREXIT(cinfo, JERR_BAD_SAMPLING);
  152657. cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
  152658. compptr->h_samp_factor);
  152659. cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
  152660. compptr->v_samp_factor);
  152661. }
  152662. cinfo->min_DCT_scaled_size = DCTSIZE;
  152663. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152664. ci++, compptr++) {
  152665. compptr->DCT_scaled_size = DCTSIZE;
  152666. compptr->width_in_blocks = (JDIMENSION)
  152667. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  152668. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  152669. compptr->height_in_blocks = (JDIMENSION)
  152670. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  152671. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  152672. compptr->downsampled_width = (JDIMENSION)
  152673. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  152674. (long) cinfo->max_h_samp_factor);
  152675. compptr->downsampled_height = (JDIMENSION)
  152676. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  152677. (long) cinfo->max_v_samp_factor);
  152678. compptr->component_needed = TRUE;
  152679. compptr->quant_table = NULL;
  152680. }
  152681. cinfo->total_iMCU_rows = (JDIMENSION)
  152682. jdiv_round_up((long) cinfo->image_height,
  152683. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  152684. if (cinfo->comps_in_scan < cinfo->num_components || cinfo->progressive_mode)
  152685. cinfo->inputctl->has_multiple_scans = TRUE;
  152686. else
  152687. cinfo->inputctl->has_multiple_scans = FALSE;
  152688. }
  152689. LOCAL(void)
  152690. per_scan_setup2 (j_decompress_ptr cinfo)
  152691. {
  152692. int ci, mcublks, tmp;
  152693. jpeg_component_info *compptr;
  152694. if (cinfo->comps_in_scan == 1) {
  152695. compptr = cinfo->cur_comp_info[0];
  152696. cinfo->MCUs_per_row = compptr->width_in_blocks;
  152697. cinfo->MCU_rows_in_scan = compptr->height_in_blocks;
  152698. compptr->MCU_width = 1;
  152699. compptr->MCU_height = 1;
  152700. compptr->MCU_blocks = 1;
  152701. compptr->MCU_sample_width = compptr->DCT_scaled_size;
  152702. compptr->last_col_width = 1;
  152703. tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  152704. if (tmp == 0) tmp = compptr->v_samp_factor;
  152705. compptr->last_row_height = tmp;
  152706. cinfo->blocks_in_MCU = 1;
  152707. cinfo->MCU_membership[0] = 0;
  152708. } else {
  152709. if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
  152710. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
  152711. MAX_COMPS_IN_SCAN);
  152712. cinfo->MCUs_per_row = (JDIMENSION)
  152713. jdiv_round_up((long) cinfo->image_width,
  152714. (long) (cinfo->max_h_samp_factor*DCTSIZE));
  152715. cinfo->MCU_rows_in_scan = (JDIMENSION)
  152716. jdiv_round_up((long) cinfo->image_height,
  152717. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  152718. cinfo->blocks_in_MCU = 0;
  152719. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  152720. compptr = cinfo->cur_comp_info[ci];
  152721. compptr->MCU_width = compptr->h_samp_factor;
  152722. compptr->MCU_height = compptr->v_samp_factor;
  152723. compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
  152724. compptr->MCU_sample_width = compptr->MCU_width * compptr->DCT_scaled_size;
  152725. tmp = (int) (compptr->width_in_blocks % compptr->MCU_width);
  152726. if (tmp == 0) tmp = compptr->MCU_width;
  152727. compptr->last_col_width = tmp;
  152728. tmp = (int) (compptr->height_in_blocks % compptr->MCU_height);
  152729. if (tmp == 0) tmp = compptr->MCU_height;
  152730. compptr->last_row_height = tmp;
  152731. mcublks = compptr->MCU_blocks;
  152732. if (cinfo->blocks_in_MCU + mcublks > D_MAX_BLOCKS_IN_MCU)
  152733. ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
  152734. while (mcublks-- > 0) {
  152735. cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
  152736. }
  152737. }
  152738. }
  152739. }
  152740. LOCAL(void)
  152741. latch_quant_tables (j_decompress_ptr cinfo)
  152742. {
  152743. int ci, qtblno;
  152744. jpeg_component_info *compptr;
  152745. JQUANT_TBL * qtbl;
  152746. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  152747. compptr = cinfo->cur_comp_info[ci];
  152748. if (compptr->quant_table != NULL)
  152749. continue;
  152750. qtblno = compptr->quant_tbl_no;
  152751. if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
  152752. cinfo->quant_tbl_ptrs[qtblno] == NULL)
  152753. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
  152754. qtbl = (JQUANT_TBL *)
  152755. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152756. SIZEOF(JQUANT_TBL));
  152757. MEMCOPY(qtbl, cinfo->quant_tbl_ptrs[qtblno], SIZEOF(JQUANT_TBL));
  152758. compptr->quant_table = qtbl;
  152759. }
  152760. }
  152761. METHODDEF(void)
  152762. start_input_pass2 (j_decompress_ptr cinfo)
  152763. {
  152764. per_scan_setup2(cinfo);
  152765. latch_quant_tables(cinfo);
  152766. (*cinfo->entropy->start_pass) (cinfo);
  152767. (*cinfo->coef->start_input_pass) (cinfo);
  152768. cinfo->inputctl->consume_input = cinfo->coef->consume_data;
  152769. }
  152770. METHODDEF(void)
  152771. finish_input_pass (j_decompress_ptr cinfo)
  152772. {
  152773. cinfo->inputctl->consume_input = consume_markers;
  152774. }
  152775. METHODDEF(int)
  152776. consume_markers (j_decompress_ptr cinfo)
  152777. {
  152778. my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl;
  152779. int val;
  152780. if (inputctl->pub.eoi_reached) /* After hitting EOI, read no further */
  152781. return JPEG_REACHED_EOI;
  152782. val = (*cinfo->marker->read_markers) (cinfo);
  152783. switch (val) {
  152784. case JPEG_REACHED_SOS: /* Found SOS */
  152785. if (inputctl->inheaders) { /* 1st SOS */
  152786. initial_setup2(cinfo);
  152787. inputctl->inheaders = FALSE;
  152788. } else { /* 2nd or later SOS marker */
  152789. if (! inputctl->pub.has_multiple_scans)
  152790. ERREXIT(cinfo, JERR_EOI_EXPECTED); /* Oops, I wasn't expecting this! */
  152791. start_input_pass2(cinfo);
  152792. }
  152793. break;
  152794. case JPEG_REACHED_EOI: /* Found EOI */
  152795. inputctl->pub.eoi_reached = TRUE;
  152796. if (inputctl->inheaders) { /* Tables-only datastream, apparently */
  152797. if (cinfo->marker->saw_SOF)
  152798. ERREXIT(cinfo, JERR_SOF_NO_SOS);
  152799. } else {
  152800. if (cinfo->output_scan_number > cinfo->input_scan_number)
  152801. cinfo->output_scan_number = cinfo->input_scan_number;
  152802. }
  152803. break;
  152804. case JPEG_SUSPENDED:
  152805. break;
  152806. }
  152807. return val;
  152808. }
  152809. METHODDEF(void)
  152810. reset_input_controller (j_decompress_ptr cinfo)
  152811. {
  152812. my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl;
  152813. inputctl->pub.consume_input = consume_markers;
  152814. inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */
  152815. inputctl->pub.eoi_reached = FALSE;
  152816. inputctl->inheaders = TRUE;
  152817. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  152818. (*cinfo->marker->reset_marker_reader) (cinfo);
  152819. cinfo->coef_bits = NULL;
  152820. }
  152821. GLOBAL(void)
  152822. jinit_input_controller (j_decompress_ptr cinfo)
  152823. {
  152824. my_inputctl_ptr inputctl;
  152825. inputctl = (my_inputctl_ptr)
  152826. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  152827. SIZEOF(my_input_controller));
  152828. cinfo->inputctl = (struct jpeg_input_controller *) inputctl;
  152829. inputctl->pub.consume_input = consume_markers;
  152830. inputctl->pub.reset_input_controller = reset_input_controller;
  152831. inputctl->pub.start_input_pass = start_input_pass2;
  152832. inputctl->pub.finish_input_pass = finish_input_pass;
  152833. inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */
  152834. inputctl->pub.eoi_reached = FALSE;
  152835. inputctl->inheaders = TRUE;
  152836. }
  152837. /*** End of inlined file: jdinput.c ***/
  152838. /*** Start of inlined file: jdmainct.c ***/
  152839. #define JPEG_INTERNALS
  152840. typedef struct {
  152841. struct jpeg_d_main_controller pub; /* public fields */
  152842. JSAMPARRAY buffer[MAX_COMPONENTS];
  152843. boolean buffer_full; /* Have we gotten an iMCU row from decoder? */
  152844. JDIMENSION rowgroup_ctr; /* counts row groups output to postprocessor */
  152845. JSAMPIMAGE xbuffer[2]; /* pointers to weird pointer lists */
  152846. int whichptr; /* indicates which pointer set is now in use */
  152847. int context_state; /* process_data state machine status */
  152848. JDIMENSION rowgroups_avail; /* row groups available to postprocessor */
  152849. JDIMENSION iMCU_row_ctr; /* counts iMCU rows to detect image top/bot */
  152850. } my_main_controller4;
  152851. typedef my_main_controller4 * my_main_ptr4;
  152852. #define CTX_PREPARE_FOR_IMCU 0 /* need to prepare for MCU row */
  152853. #define CTX_PROCESS_IMCU 1 /* feeding iMCU to postprocessor */
  152854. #define CTX_POSTPONED_ROW 2 /* feeding postponed row group */
  152855. METHODDEF(void) process_data_simple_main2
  152856. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  152857. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  152858. METHODDEF(void) process_data_context_main
  152859. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  152860. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  152861. #ifdef QUANT_2PASS_SUPPORTED
  152862. METHODDEF(void) process_data_crank_post
  152863. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  152864. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  152865. #endif
  152866. LOCAL(void)
  152867. alloc_funny_pointers (j_decompress_ptr cinfo)
  152868. {
  152869. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152870. int ci, rgroup;
  152871. int M = cinfo->min_DCT_scaled_size;
  152872. jpeg_component_info *compptr;
  152873. JSAMPARRAY xbuf;
  152874. main_->xbuffer[0] = (JSAMPIMAGE)
  152875. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152876. cinfo->num_components * 2 * SIZEOF(JSAMPARRAY));
  152877. main_->xbuffer[1] = main_->xbuffer[0] + cinfo->num_components;
  152878. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152879. ci++, compptr++) {
  152880. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152881. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152882. xbuf = (JSAMPARRAY)
  152883. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152884. 2 * (rgroup * (M + 4)) * SIZEOF(JSAMPROW));
  152885. xbuf += rgroup; /* want one row group at negative offsets */
  152886. main_->xbuffer[0][ci] = xbuf;
  152887. xbuf += rgroup * (M + 4);
  152888. main_->xbuffer[1][ci] = xbuf;
  152889. }
  152890. }
  152891. LOCAL(void)
  152892. make_funny_pointers (j_decompress_ptr cinfo)
  152893. {
  152894. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152895. int ci, i, rgroup;
  152896. int M = cinfo->min_DCT_scaled_size;
  152897. jpeg_component_info *compptr;
  152898. JSAMPARRAY buf, xbuf0, xbuf1;
  152899. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152900. ci++, compptr++) {
  152901. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152902. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152903. xbuf0 = main_->xbuffer[0][ci];
  152904. xbuf1 = main_->xbuffer[1][ci];
  152905. buf = main_->buffer[ci];
  152906. for (i = 0; i < rgroup * (M + 2); i++) {
  152907. xbuf0[i] = xbuf1[i] = buf[i];
  152908. }
  152909. for (i = 0; i < rgroup * 2; i++) {
  152910. xbuf1[rgroup*(M-2) + i] = buf[rgroup*M + i];
  152911. xbuf1[rgroup*M + i] = buf[rgroup*(M-2) + i];
  152912. }
  152913. for (i = 0; i < rgroup; i++) {
  152914. xbuf0[i - rgroup] = xbuf0[0];
  152915. }
  152916. }
  152917. }
  152918. LOCAL(void)
  152919. set_wraparound_pointers (j_decompress_ptr cinfo)
  152920. {
  152921. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152922. int ci, i, rgroup;
  152923. int M = cinfo->min_DCT_scaled_size;
  152924. jpeg_component_info *compptr;
  152925. JSAMPARRAY xbuf0, xbuf1;
  152926. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152927. ci++, compptr++) {
  152928. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152929. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152930. xbuf0 = main_->xbuffer[0][ci];
  152931. xbuf1 = main_->xbuffer[1][ci];
  152932. for (i = 0; i < rgroup; i++) {
  152933. xbuf0[i - rgroup] = xbuf0[rgroup*(M+1) + i];
  152934. xbuf1[i - rgroup] = xbuf1[rgroup*(M+1) + i];
  152935. xbuf0[rgroup*(M+2) + i] = xbuf0[i];
  152936. xbuf1[rgroup*(M+2) + i] = xbuf1[i];
  152937. }
  152938. }
  152939. }
  152940. LOCAL(void)
  152941. set_bottom_pointers (j_decompress_ptr cinfo)
  152942. {
  152943. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152944. int ci, i, rgroup, iMCUheight, rows_left;
  152945. jpeg_component_info *compptr;
  152946. JSAMPARRAY xbuf;
  152947. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152948. ci++, compptr++) {
  152949. iMCUheight = compptr->v_samp_factor * compptr->DCT_scaled_size;
  152950. rgroup = iMCUheight / cinfo->min_DCT_scaled_size;
  152951. rows_left = (int) (compptr->downsampled_height % (JDIMENSION) iMCUheight);
  152952. if (rows_left == 0) rows_left = iMCUheight;
  152953. if (ci == 0) {
  152954. main_->rowgroups_avail = (JDIMENSION) ((rows_left-1) / rgroup + 1);
  152955. }
  152956. xbuf = main_->xbuffer[main_->whichptr][ci];
  152957. for (i = 0; i < rgroup * 2; i++) {
  152958. xbuf[rows_left + i] = xbuf[rows_left-1];
  152959. }
  152960. }
  152961. }
  152962. METHODDEF(void)
  152963. start_pass_main2 (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
  152964. {
  152965. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152966. switch (pass_mode) {
  152967. case JBUF_PASS_THRU:
  152968. if (cinfo->upsample->need_context_rows) {
  152969. main_->pub.process_data = process_data_context_main;
  152970. make_funny_pointers(cinfo); /* Create the xbuffer[] lists */
  152971. main_->whichptr = 0; /* Read first iMCU row into xbuffer[0] */
  152972. main_->context_state = CTX_PREPARE_FOR_IMCU;
  152973. main_->iMCU_row_ctr = 0;
  152974. } else {
  152975. main_->pub.process_data = process_data_simple_main2;
  152976. }
  152977. main_->buffer_full = FALSE; /* Mark buffer empty */
  152978. main_->rowgroup_ctr = 0;
  152979. break;
  152980. #ifdef QUANT_2PASS_SUPPORTED
  152981. case JBUF_CRANK_DEST:
  152982. main_->pub.process_data = process_data_crank_post;
  152983. break;
  152984. #endif
  152985. default:
  152986. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  152987. break;
  152988. }
  152989. }
  152990. METHODDEF(void)
  152991. process_data_simple_main2 (j_decompress_ptr cinfo,
  152992. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  152993. JDIMENSION out_rows_avail)
  152994. {
  152995. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152996. JDIMENSION rowgroups_avail;
  152997. if (! main_->buffer_full) {
  152998. if (! (*cinfo->coef->decompress_data) (cinfo, main_->buffer))
  152999. return; /* suspension forced, can do nothing more */
  153000. main_->buffer_full = TRUE; /* OK, we have an iMCU row to work with */
  153001. }
  153002. rowgroups_avail = (JDIMENSION) cinfo->min_DCT_scaled_size;
  153003. (*cinfo->post->post_process_data) (cinfo, main_->buffer,
  153004. &main_->rowgroup_ctr, rowgroups_avail,
  153005. output_buf, out_row_ctr, out_rows_avail);
  153006. if (main_->rowgroup_ctr >= rowgroups_avail) {
  153007. main_->buffer_full = FALSE;
  153008. main_->rowgroup_ctr = 0;
  153009. }
  153010. }
  153011. METHODDEF(void)
  153012. process_data_context_main (j_decompress_ptr cinfo,
  153013. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  153014. JDIMENSION out_rows_avail)
  153015. {
  153016. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  153017. if (! main_->buffer_full) {
  153018. if (! (*cinfo->coef->decompress_data) (cinfo,
  153019. main_->xbuffer[main_->whichptr]))
  153020. return; /* suspension forced, can do nothing more */
  153021. main_->buffer_full = TRUE; /* OK, we have an iMCU row to work with */
  153022. main_->iMCU_row_ctr++; /* count rows received */
  153023. }
  153024. switch (main_->context_state) {
  153025. case CTX_POSTPONED_ROW:
  153026. (*cinfo->post->post_process_data) (cinfo, main_->xbuffer[main_->whichptr],
  153027. &main_->rowgroup_ctr, main_->rowgroups_avail,
  153028. output_buf, out_row_ctr, out_rows_avail);
  153029. if (main_->rowgroup_ctr < main_->rowgroups_avail)
  153030. return; /* Need to suspend */
  153031. main_->context_state = CTX_PREPARE_FOR_IMCU;
  153032. if (*out_row_ctr >= out_rows_avail)
  153033. return; /* Postprocessor exactly filled output buf */
  153034. case CTX_PREPARE_FOR_IMCU:
  153035. main_->rowgroup_ctr = 0;
  153036. main_->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_scaled_size - 1);
  153037. if (main_->iMCU_row_ctr == cinfo->total_iMCU_rows)
  153038. set_bottom_pointers(cinfo);
  153039. main_->context_state = CTX_PROCESS_IMCU;
  153040. case CTX_PROCESS_IMCU:
  153041. (*cinfo->post->post_process_data) (cinfo, main_->xbuffer[main_->whichptr],
  153042. &main_->rowgroup_ctr, main_->rowgroups_avail,
  153043. output_buf, out_row_ctr, out_rows_avail);
  153044. if (main_->rowgroup_ctr < main_->rowgroups_avail)
  153045. return; /* Need to suspend */
  153046. if (main_->iMCU_row_ctr == 1)
  153047. set_wraparound_pointers(cinfo);
  153048. main_->whichptr ^= 1; /* 0=>1 or 1=>0 */
  153049. main_->buffer_full = FALSE;
  153050. main_->rowgroup_ctr = (JDIMENSION) (cinfo->min_DCT_scaled_size + 1);
  153051. main_->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_scaled_size + 2);
  153052. main_->context_state = CTX_POSTPONED_ROW;
  153053. }
  153054. }
  153055. #ifdef QUANT_2PASS_SUPPORTED
  153056. METHODDEF(void)
  153057. process_data_crank_post (j_decompress_ptr cinfo,
  153058. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  153059. JDIMENSION out_rows_avail)
  153060. {
  153061. (*cinfo->post->post_process_data) (cinfo, (JSAMPIMAGE) NULL,
  153062. (JDIMENSION *) NULL, (JDIMENSION) 0,
  153063. output_buf, out_row_ctr, out_rows_avail);
  153064. }
  153065. #endif /* QUANT_2PASS_SUPPORTED */
  153066. GLOBAL(void)
  153067. jinit_d_main_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  153068. {
  153069. my_main_ptr4 main_;
  153070. int ci, rgroup, ngroups;
  153071. jpeg_component_info *compptr;
  153072. main_ = (my_main_ptr4)
  153073. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153074. SIZEOF(my_main_controller4));
  153075. cinfo->main = (struct jpeg_d_main_controller *) main_;
  153076. main_->pub.start_pass = start_pass_main2;
  153077. if (need_full_buffer) /* shouldn't happen */
  153078. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  153079. if (cinfo->upsample->need_context_rows) {
  153080. if (cinfo->min_DCT_scaled_size < 2) /* unsupported, see comments above */
  153081. ERREXIT(cinfo, JERR_NOTIMPL);
  153082. alloc_funny_pointers(cinfo); /* Alloc space for xbuffer[] lists */
  153083. ngroups = cinfo->min_DCT_scaled_size + 2;
  153084. } else {
  153085. ngroups = cinfo->min_DCT_scaled_size;
  153086. }
  153087. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153088. ci++, compptr++) {
  153089. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  153090. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  153091. main_->buffer[ci] = (*cinfo->mem->alloc_sarray)
  153092. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153093. compptr->width_in_blocks * compptr->DCT_scaled_size,
  153094. (JDIMENSION) (rgroup * ngroups));
  153095. }
  153096. }
  153097. /*** End of inlined file: jdmainct.c ***/
  153098. /*** Start of inlined file: jdmarker.c ***/
  153099. #define JPEG_INTERNALS
  153100. typedef struct {
  153101. struct jpeg_marker_reader pub; /* public fields */
  153102. jpeg_marker_parser_method process_COM;
  153103. jpeg_marker_parser_method process_APPn[16];
  153104. unsigned int length_limit_COM;
  153105. unsigned int length_limit_APPn[16];
  153106. jpeg_saved_marker_ptr cur_marker; /* NULL if not processing a marker */
  153107. unsigned int bytes_read; /* data bytes read so far in marker */
  153108. } my_marker_reader;
  153109. typedef my_marker_reader * my_marker_ptr2;
  153110. #define INPUT_VARS(cinfo) \
  153111. struct jpeg_source_mgr * datasrc = (cinfo)->src; \
  153112. const JOCTET * next_input_byte = datasrc->next_input_byte; \
  153113. size_t bytes_in_buffer = datasrc->bytes_in_buffer
  153114. #define INPUT_SYNC(cinfo) \
  153115. ( datasrc->next_input_byte = next_input_byte, \
  153116. datasrc->bytes_in_buffer = bytes_in_buffer )
  153117. #define INPUT_RELOAD(cinfo) \
  153118. ( next_input_byte = datasrc->next_input_byte, \
  153119. bytes_in_buffer = datasrc->bytes_in_buffer )
  153120. #define MAKE_BYTE_AVAIL(cinfo,action) \
  153121. if (bytes_in_buffer == 0) { \
  153122. if (! (*datasrc->fill_input_buffer) (cinfo)) \
  153123. { action; } \
  153124. INPUT_RELOAD(cinfo); \
  153125. }
  153126. #define INPUT_BYTE(cinfo,V,action) \
  153127. MAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \
  153128. bytes_in_buffer--; \
  153129. V = GETJOCTET(*next_input_byte++); )
  153130. #define INPUT_2BYTES(cinfo,V,action) \
  153131. MAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \
  153132. bytes_in_buffer--; \
  153133. V = ((unsigned int) GETJOCTET(*next_input_byte++)) << 8; \
  153134. MAKE_BYTE_AVAIL(cinfo,action); \
  153135. bytes_in_buffer--; \
  153136. V += GETJOCTET(*next_input_byte++); )
  153137. LOCAL(boolean)
  153138. get_soi (j_decompress_ptr cinfo)
  153139. {
  153140. int i;
  153141. TRACEMS(cinfo, 1, JTRC_SOI);
  153142. if (cinfo->marker->saw_SOI)
  153143. ERREXIT(cinfo, JERR_SOI_DUPLICATE);
  153144. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  153145. cinfo->arith_dc_L[i] = 0;
  153146. cinfo->arith_dc_U[i] = 1;
  153147. cinfo->arith_ac_K[i] = 5;
  153148. }
  153149. cinfo->restart_interval = 0;
  153150. cinfo->jpeg_color_space = JCS_UNKNOWN;
  153151. cinfo->CCIR601_sampling = FALSE; /* Assume non-CCIR sampling??? */
  153152. cinfo->saw_JFIF_marker = FALSE;
  153153. cinfo->JFIF_major_version = 1; /* set default JFIF APP0 values */
  153154. cinfo->JFIF_minor_version = 1;
  153155. cinfo->density_unit = 0;
  153156. cinfo->X_density = 1;
  153157. cinfo->Y_density = 1;
  153158. cinfo->saw_Adobe_marker = FALSE;
  153159. cinfo->Adobe_transform = 0;
  153160. cinfo->marker->saw_SOI = TRUE;
  153161. return TRUE;
  153162. }
  153163. LOCAL(boolean)
  153164. get_sof (j_decompress_ptr cinfo, boolean is_prog, boolean is_arith)
  153165. {
  153166. INT32 length;
  153167. int c, ci;
  153168. jpeg_component_info * compptr;
  153169. INPUT_VARS(cinfo);
  153170. cinfo->progressive_mode = is_prog;
  153171. cinfo->arith_code = is_arith;
  153172. INPUT_2BYTES(cinfo, length, return FALSE);
  153173. INPUT_BYTE(cinfo, cinfo->data_precision, return FALSE);
  153174. INPUT_2BYTES(cinfo, cinfo->image_height, return FALSE);
  153175. INPUT_2BYTES(cinfo, cinfo->image_width, return FALSE);
  153176. INPUT_BYTE(cinfo, cinfo->num_components, return FALSE);
  153177. length -= 8;
  153178. TRACEMS4(cinfo, 1, JTRC_SOF, cinfo->unread_marker,
  153179. (int) cinfo->image_width, (int) cinfo->image_height,
  153180. cinfo->num_components);
  153181. if (cinfo->marker->saw_SOF)
  153182. ERREXIT(cinfo, JERR_SOF_DUPLICATE);
  153183. if (cinfo->image_height <= 0 || cinfo->image_width <= 0
  153184. || cinfo->num_components <= 0)
  153185. ERREXIT(cinfo, JERR_EMPTY_IMAGE);
  153186. if (length != (cinfo->num_components * 3))
  153187. ERREXIT(cinfo, JERR_BAD_LENGTH);
  153188. if (cinfo->comp_info == NULL) /* do only once, even if suspend */
  153189. cinfo->comp_info = (jpeg_component_info *) (*cinfo->mem->alloc_small)
  153190. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153191. cinfo->num_components * SIZEOF(jpeg_component_info));
  153192. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153193. ci++, compptr++) {
  153194. compptr->component_index = ci;
  153195. INPUT_BYTE(cinfo, compptr->component_id, return FALSE);
  153196. INPUT_BYTE(cinfo, c, return FALSE);
  153197. compptr->h_samp_factor = (c >> 4) & 15;
  153198. compptr->v_samp_factor = (c ) & 15;
  153199. INPUT_BYTE(cinfo, compptr->quant_tbl_no, return FALSE);
  153200. TRACEMS4(cinfo, 1, JTRC_SOF_COMPONENT,
  153201. compptr->component_id, compptr->h_samp_factor,
  153202. compptr->v_samp_factor, compptr->quant_tbl_no);
  153203. }
  153204. cinfo->marker->saw_SOF = TRUE;
  153205. INPUT_SYNC(cinfo);
  153206. return TRUE;
  153207. }
  153208. LOCAL(boolean)
  153209. get_sos (j_decompress_ptr cinfo)
  153210. {
  153211. INT32 length;
  153212. int i, ci, n, c, cc;
  153213. jpeg_component_info * compptr;
  153214. INPUT_VARS(cinfo);
  153215. if (! cinfo->marker->saw_SOF)
  153216. ERREXIT(cinfo, JERR_SOS_NO_SOF);
  153217. INPUT_2BYTES(cinfo, length, return FALSE);
  153218. INPUT_BYTE(cinfo, n, return FALSE); /* Number of components */
  153219. TRACEMS1(cinfo, 1, JTRC_SOS, n);
  153220. if (length != (n * 2 + 6) || n < 1 || n > MAX_COMPS_IN_SCAN)
  153221. ERREXIT(cinfo, JERR_BAD_LENGTH);
  153222. cinfo->comps_in_scan = n;
  153223. for (i = 0; i < n; i++) {
  153224. INPUT_BYTE(cinfo, cc, return FALSE);
  153225. INPUT_BYTE(cinfo, c, return FALSE);
  153226. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153227. ci++, compptr++) {
  153228. if (cc == compptr->component_id)
  153229. goto id_found;
  153230. }
  153231. ERREXIT1(cinfo, JERR_BAD_COMPONENT_ID, cc);
  153232. id_found:
  153233. cinfo->cur_comp_info[i] = compptr;
  153234. compptr->dc_tbl_no = (c >> 4) & 15;
  153235. compptr->ac_tbl_no = (c ) & 15;
  153236. TRACEMS3(cinfo, 1, JTRC_SOS_COMPONENT, cc,
  153237. compptr->dc_tbl_no, compptr->ac_tbl_no);
  153238. }
  153239. INPUT_BYTE(cinfo, c, return FALSE);
  153240. cinfo->Ss = c;
  153241. INPUT_BYTE(cinfo, c, return FALSE);
  153242. cinfo->Se = c;
  153243. INPUT_BYTE(cinfo, c, return FALSE);
  153244. cinfo->Ah = (c >> 4) & 15;
  153245. cinfo->Al = (c ) & 15;
  153246. TRACEMS4(cinfo, 1, JTRC_SOS_PARAMS, cinfo->Ss, cinfo->Se,
  153247. cinfo->Ah, cinfo->Al);
  153248. cinfo->marker->next_restart_num = 0;
  153249. cinfo->input_scan_number++;
  153250. INPUT_SYNC(cinfo);
  153251. return TRUE;
  153252. }
  153253. #ifdef D_ARITH_CODING_SUPPORTED
  153254. LOCAL(boolean)
  153255. get_dac (j_decompress_ptr cinfo)
  153256. {
  153257. INT32 length;
  153258. int index, val;
  153259. INPUT_VARS(cinfo);
  153260. INPUT_2BYTES(cinfo, length, return FALSE);
  153261. length -= 2;
  153262. while (length > 0) {
  153263. INPUT_BYTE(cinfo, index, return FALSE);
  153264. INPUT_BYTE(cinfo, val, return FALSE);
  153265. length -= 2;
  153266. TRACEMS2(cinfo, 1, JTRC_DAC, index, val);
  153267. if (index < 0 || index >= (2*NUM_ARITH_TBLS))
  153268. ERREXIT1(cinfo, JERR_DAC_INDEX, index);
  153269. if (index >= NUM_ARITH_TBLS) { /* define AC table */
  153270. cinfo->arith_ac_K[index-NUM_ARITH_TBLS] = (UINT8) val;
  153271. } else { /* define DC table */
  153272. cinfo->arith_dc_L[index] = (UINT8) (val & 0x0F);
  153273. cinfo->arith_dc_U[index] = (UINT8) (val >> 4);
  153274. if (cinfo->arith_dc_L[index] > cinfo->arith_dc_U[index])
  153275. ERREXIT1(cinfo, JERR_DAC_VALUE, val);
  153276. }
  153277. }
  153278. if (length != 0)
  153279. ERREXIT(cinfo, JERR_BAD_LENGTH);
  153280. INPUT_SYNC(cinfo);
  153281. return TRUE;
  153282. }
  153283. #else /* ! D_ARITH_CODING_SUPPORTED */
  153284. #define get_dac(cinfo) skip_variable(cinfo)
  153285. #endif /* D_ARITH_CODING_SUPPORTED */
  153286. LOCAL(boolean)
  153287. get_dht (j_decompress_ptr cinfo)
  153288. {
  153289. INT32 length;
  153290. UINT8 bits[17];
  153291. UINT8 huffval[256];
  153292. int i, index, count;
  153293. JHUFF_TBL **htblptr;
  153294. INPUT_VARS(cinfo);
  153295. INPUT_2BYTES(cinfo, length, return FALSE);
  153296. length -= 2;
  153297. while (length > 16) {
  153298. INPUT_BYTE(cinfo, index, return FALSE);
  153299. TRACEMS1(cinfo, 1, JTRC_DHT, index);
  153300. bits[0] = 0;
  153301. count = 0;
  153302. for (i = 1; i <= 16; i++) {
  153303. INPUT_BYTE(cinfo, bits[i], return FALSE);
  153304. count += bits[i];
  153305. }
  153306. length -= 1 + 16;
  153307. TRACEMS8(cinfo, 2, JTRC_HUFFBITS,
  153308. bits[1], bits[2], bits[3], bits[4],
  153309. bits[5], bits[6], bits[7], bits[8]);
  153310. TRACEMS8(cinfo, 2, JTRC_HUFFBITS,
  153311. bits[9], bits[10], bits[11], bits[12],
  153312. bits[13], bits[14], bits[15], bits[16]);
  153313. if (count > 256 || ((INT32) count) > length)
  153314. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  153315. for (i = 0; i < count; i++)
  153316. INPUT_BYTE(cinfo, huffval[i], return FALSE);
  153317. length -= count;
  153318. if (index & 0x10) { /* AC table definition */
  153319. index -= 0x10;
  153320. htblptr = &cinfo->ac_huff_tbl_ptrs[index];
  153321. } else { /* DC table definition */
  153322. htblptr = &cinfo->dc_huff_tbl_ptrs[index];
  153323. }
  153324. if (index < 0 || index >= NUM_HUFF_TBLS)
  153325. ERREXIT1(cinfo, JERR_DHT_INDEX, index);
  153326. if (*htblptr == NULL)
  153327. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  153328. MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits));
  153329. MEMCOPY((*htblptr)->huffval, huffval, SIZEOF((*htblptr)->huffval));
  153330. }
  153331. if (length != 0)
  153332. ERREXIT(cinfo, JERR_BAD_LENGTH);
  153333. INPUT_SYNC(cinfo);
  153334. return TRUE;
  153335. }
  153336. LOCAL(boolean)
  153337. get_dqt (j_decompress_ptr cinfo)
  153338. {
  153339. INT32 length;
  153340. int n, i, prec;
  153341. unsigned int tmp;
  153342. JQUANT_TBL *quant_ptr;
  153343. INPUT_VARS(cinfo);
  153344. INPUT_2BYTES(cinfo, length, return FALSE);
  153345. length -= 2;
  153346. while (length > 0) {
  153347. INPUT_BYTE(cinfo, n, return FALSE);
  153348. prec = n >> 4;
  153349. n &= 0x0F;
  153350. TRACEMS2(cinfo, 1, JTRC_DQT, n, prec);
  153351. if (n >= NUM_QUANT_TBLS)
  153352. ERREXIT1(cinfo, JERR_DQT_INDEX, n);
  153353. if (cinfo->quant_tbl_ptrs[n] == NULL)
  153354. cinfo->quant_tbl_ptrs[n] = jpeg_alloc_quant_table((j_common_ptr) cinfo);
  153355. quant_ptr = cinfo->quant_tbl_ptrs[n];
  153356. for (i = 0; i < DCTSIZE2; i++) {
  153357. if (prec)
  153358. INPUT_2BYTES(cinfo, tmp, return FALSE);
  153359. else
  153360. INPUT_BYTE(cinfo, tmp, return FALSE);
  153361. quant_ptr->quantval[jpeg_natural_order[i]] = (UINT16) tmp;
  153362. }
  153363. if (cinfo->err->trace_level >= 2) {
  153364. for (i = 0; i < DCTSIZE2; i += 8) {
  153365. TRACEMS8(cinfo, 2, JTRC_QUANTVALS,
  153366. quant_ptr->quantval[i], quant_ptr->quantval[i+1],
  153367. quant_ptr->quantval[i+2], quant_ptr->quantval[i+3],
  153368. quant_ptr->quantval[i+4], quant_ptr->quantval[i+5],
  153369. quant_ptr->quantval[i+6], quant_ptr->quantval[i+7]);
  153370. }
  153371. }
  153372. length -= DCTSIZE2+1;
  153373. if (prec) length -= DCTSIZE2;
  153374. }
  153375. if (length != 0)
  153376. ERREXIT(cinfo, JERR_BAD_LENGTH);
  153377. INPUT_SYNC(cinfo);
  153378. return TRUE;
  153379. }
  153380. LOCAL(boolean)
  153381. get_dri (j_decompress_ptr cinfo)
  153382. {
  153383. INT32 length;
  153384. unsigned int tmp;
  153385. INPUT_VARS(cinfo);
  153386. INPUT_2BYTES(cinfo, length, return FALSE);
  153387. if (length != 4)
  153388. ERREXIT(cinfo, JERR_BAD_LENGTH);
  153389. INPUT_2BYTES(cinfo, tmp, return FALSE);
  153390. TRACEMS1(cinfo, 1, JTRC_DRI, tmp);
  153391. cinfo->restart_interval = tmp;
  153392. INPUT_SYNC(cinfo);
  153393. return TRUE;
  153394. }
  153395. #define APP0_DATA_LEN 14 /* Length of interesting data in APP0 */
  153396. #define APP14_DATA_LEN 12 /* Length of interesting data in APP14 */
  153397. #define APPN_DATA_LEN 14 /* Must be the largest of the above!! */
  153398. LOCAL(void)
  153399. examine_app0 (j_decompress_ptr cinfo, JOCTET FAR * data,
  153400. unsigned int datalen, INT32 remaining)
  153401. {
  153402. INT32 totallen = (INT32) datalen + remaining;
  153403. if (datalen >= APP0_DATA_LEN &&
  153404. GETJOCTET(data[0]) == 0x4A &&
  153405. GETJOCTET(data[1]) == 0x46 &&
  153406. GETJOCTET(data[2]) == 0x49 &&
  153407. GETJOCTET(data[3]) == 0x46 &&
  153408. GETJOCTET(data[4]) == 0) {
  153409. cinfo->saw_JFIF_marker = TRUE;
  153410. cinfo->JFIF_major_version = GETJOCTET(data[5]);
  153411. cinfo->JFIF_minor_version = GETJOCTET(data[6]);
  153412. cinfo->density_unit = GETJOCTET(data[7]);
  153413. cinfo->X_density = (GETJOCTET(data[8]) << 8) + GETJOCTET(data[9]);
  153414. cinfo->Y_density = (GETJOCTET(data[10]) << 8) + GETJOCTET(data[11]);
  153415. if (cinfo->JFIF_major_version != 1)
  153416. WARNMS2(cinfo, JWRN_JFIF_MAJOR,
  153417. cinfo->JFIF_major_version, cinfo->JFIF_minor_version);
  153418. TRACEMS5(cinfo, 1, JTRC_JFIF,
  153419. cinfo->JFIF_major_version, cinfo->JFIF_minor_version,
  153420. cinfo->X_density, cinfo->Y_density, cinfo->density_unit);
  153421. if (GETJOCTET(data[12]) | GETJOCTET(data[13]))
  153422. TRACEMS2(cinfo, 1, JTRC_JFIF_THUMBNAIL,
  153423. GETJOCTET(data[12]), GETJOCTET(data[13]));
  153424. totallen -= APP0_DATA_LEN;
  153425. if (totallen !=
  153426. ((INT32)GETJOCTET(data[12]) * (INT32)GETJOCTET(data[13]) * (INT32) 3))
  153427. TRACEMS1(cinfo, 1, JTRC_JFIF_BADTHUMBNAILSIZE, (int) totallen);
  153428. } else if (datalen >= 6 &&
  153429. GETJOCTET(data[0]) == 0x4A &&
  153430. GETJOCTET(data[1]) == 0x46 &&
  153431. GETJOCTET(data[2]) == 0x58 &&
  153432. GETJOCTET(data[3]) == 0x58 &&
  153433. GETJOCTET(data[4]) == 0) {
  153434. switch (GETJOCTET(data[5])) {
  153435. case 0x10:
  153436. TRACEMS1(cinfo, 1, JTRC_THUMB_JPEG, (int) totallen);
  153437. break;
  153438. case 0x11:
  153439. TRACEMS1(cinfo, 1, JTRC_THUMB_PALETTE, (int) totallen);
  153440. break;
  153441. case 0x13:
  153442. TRACEMS1(cinfo, 1, JTRC_THUMB_RGB, (int) totallen);
  153443. break;
  153444. default:
  153445. TRACEMS2(cinfo, 1, JTRC_JFIF_EXTENSION,
  153446. GETJOCTET(data[5]), (int) totallen);
  153447. break;
  153448. }
  153449. } else {
  153450. TRACEMS1(cinfo, 1, JTRC_APP0, (int) totallen);
  153451. }
  153452. }
  153453. LOCAL(void)
  153454. examine_app14 (j_decompress_ptr cinfo, JOCTET FAR * data,
  153455. unsigned int datalen, INT32 remaining)
  153456. {
  153457. unsigned int version, flags0, flags1, transform;
  153458. if (datalen >= APP14_DATA_LEN &&
  153459. GETJOCTET(data[0]) == 0x41 &&
  153460. GETJOCTET(data[1]) == 0x64 &&
  153461. GETJOCTET(data[2]) == 0x6F &&
  153462. GETJOCTET(data[3]) == 0x62 &&
  153463. GETJOCTET(data[4]) == 0x65) {
  153464. version = (GETJOCTET(data[5]) << 8) + GETJOCTET(data[6]);
  153465. flags0 = (GETJOCTET(data[7]) << 8) + GETJOCTET(data[8]);
  153466. flags1 = (GETJOCTET(data[9]) << 8) + GETJOCTET(data[10]);
  153467. transform = GETJOCTET(data[11]);
  153468. TRACEMS4(cinfo, 1, JTRC_ADOBE, version, flags0, flags1, transform);
  153469. cinfo->saw_Adobe_marker = TRUE;
  153470. cinfo->Adobe_transform = (UINT8) transform;
  153471. } else {
  153472. TRACEMS1(cinfo, 1, JTRC_APP14, (int) (datalen + remaining));
  153473. }
  153474. }
  153475. METHODDEF(boolean)
  153476. get_interesting_appn (j_decompress_ptr cinfo)
  153477. {
  153478. INT32 length;
  153479. JOCTET b[APPN_DATA_LEN];
  153480. unsigned int i, numtoread;
  153481. INPUT_VARS(cinfo);
  153482. INPUT_2BYTES(cinfo, length, return FALSE);
  153483. length -= 2;
  153484. if (length >= APPN_DATA_LEN)
  153485. numtoread = APPN_DATA_LEN;
  153486. else if (length > 0)
  153487. numtoread = (unsigned int) length;
  153488. else
  153489. numtoread = 0;
  153490. for (i = 0; i < numtoread; i++)
  153491. INPUT_BYTE(cinfo, b[i], return FALSE);
  153492. length -= numtoread;
  153493. switch (cinfo->unread_marker) {
  153494. case M_APP0:
  153495. examine_app0(cinfo, (JOCTET FAR *) b, numtoread, length);
  153496. break;
  153497. case M_APP14:
  153498. examine_app14(cinfo, (JOCTET FAR *) b, numtoread, length);
  153499. break;
  153500. default:
  153501. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo->unread_marker);
  153502. break;
  153503. }
  153504. INPUT_SYNC(cinfo);
  153505. if (length > 0)
  153506. (*cinfo->src->skip_input_data) (cinfo, (long) length);
  153507. return TRUE;
  153508. }
  153509. #ifdef SAVE_MARKERS_SUPPORTED
  153510. METHODDEF(boolean)
  153511. save_marker (j_decompress_ptr cinfo)
  153512. {
  153513. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153514. jpeg_saved_marker_ptr cur_marker = marker->cur_marker;
  153515. unsigned int bytes_read, data_length;
  153516. JOCTET FAR * data;
  153517. INT32 length = 0;
  153518. INPUT_VARS(cinfo);
  153519. if (cur_marker == NULL) {
  153520. INPUT_2BYTES(cinfo, length, return FALSE);
  153521. length -= 2;
  153522. if (length >= 0) { /* watch out for bogus length word */
  153523. unsigned int limit;
  153524. if (cinfo->unread_marker == (int) M_COM)
  153525. limit = marker->length_limit_COM;
  153526. else
  153527. limit = marker->length_limit_APPn[cinfo->unread_marker - (int) M_APP0];
  153528. if ((unsigned int) length < limit)
  153529. limit = (unsigned int) length;
  153530. cur_marker = (jpeg_saved_marker_ptr)
  153531. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153532. SIZEOF(struct jpeg_marker_struct) + limit);
  153533. cur_marker->next = NULL;
  153534. cur_marker->marker = (UINT8) cinfo->unread_marker;
  153535. cur_marker->original_length = (unsigned int) length;
  153536. cur_marker->data_length = limit;
  153537. data = cur_marker->data = (JOCTET FAR *) (cur_marker + 1);
  153538. marker->cur_marker = cur_marker;
  153539. marker->bytes_read = 0;
  153540. bytes_read = 0;
  153541. data_length = limit;
  153542. } else {
  153543. bytes_read = data_length = 0;
  153544. data = NULL;
  153545. }
  153546. } else {
  153547. bytes_read = marker->bytes_read;
  153548. data_length = cur_marker->data_length;
  153549. data = cur_marker->data + bytes_read;
  153550. }
  153551. while (bytes_read < data_length) {
  153552. INPUT_SYNC(cinfo); /* move the restart point to here */
  153553. marker->bytes_read = bytes_read;
  153554. MAKE_BYTE_AVAIL(cinfo, return FALSE);
  153555. while (bytes_read < data_length && bytes_in_buffer > 0) {
  153556. *data++ = *next_input_byte++;
  153557. bytes_in_buffer--;
  153558. bytes_read++;
  153559. }
  153560. }
  153561. if (cur_marker != NULL) { /* will be NULL if bogus length word */
  153562. if (cinfo->marker_list == NULL) {
  153563. cinfo->marker_list = cur_marker;
  153564. } else {
  153565. jpeg_saved_marker_ptr prev = cinfo->marker_list;
  153566. while (prev->next != NULL)
  153567. prev = prev->next;
  153568. prev->next = cur_marker;
  153569. }
  153570. data = cur_marker->data;
  153571. length = cur_marker->original_length - data_length;
  153572. }
  153573. marker->cur_marker = NULL;
  153574. switch (cinfo->unread_marker) {
  153575. case M_APP0:
  153576. examine_app0(cinfo, data, data_length, length);
  153577. break;
  153578. case M_APP14:
  153579. examine_app14(cinfo, data, data_length, length);
  153580. break;
  153581. default:
  153582. TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker,
  153583. (int) (data_length + length));
  153584. break;
  153585. }
  153586. INPUT_SYNC(cinfo); /* do before skip_input_data */
  153587. if (length > 0)
  153588. (*cinfo->src->skip_input_data) (cinfo, (long) length);
  153589. return TRUE;
  153590. }
  153591. #endif /* SAVE_MARKERS_SUPPORTED */
  153592. METHODDEF(boolean)
  153593. skip_variable (j_decompress_ptr cinfo)
  153594. {
  153595. INT32 length;
  153596. INPUT_VARS(cinfo);
  153597. INPUT_2BYTES(cinfo, length, return FALSE);
  153598. length -= 2;
  153599. TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker, (int) length);
  153600. INPUT_SYNC(cinfo); /* do before skip_input_data */
  153601. if (length > 0)
  153602. (*cinfo->src->skip_input_data) (cinfo, (long) length);
  153603. return TRUE;
  153604. }
  153605. LOCAL(boolean)
  153606. next_marker (j_decompress_ptr cinfo)
  153607. {
  153608. int c;
  153609. INPUT_VARS(cinfo);
  153610. for (;;) {
  153611. INPUT_BYTE(cinfo, c, return FALSE);
  153612. while (c != 0xFF) {
  153613. cinfo->marker->discarded_bytes++;
  153614. INPUT_SYNC(cinfo);
  153615. INPUT_BYTE(cinfo, c, return FALSE);
  153616. }
  153617. do {
  153618. INPUT_BYTE(cinfo, c, return FALSE);
  153619. } while (c == 0xFF);
  153620. if (c != 0)
  153621. break; /* found a valid marker, exit loop */
  153622. cinfo->marker->discarded_bytes += 2;
  153623. INPUT_SYNC(cinfo);
  153624. }
  153625. if (cinfo->marker->discarded_bytes != 0) {
  153626. WARNMS2(cinfo, JWRN_EXTRANEOUS_DATA, cinfo->marker->discarded_bytes, c);
  153627. cinfo->marker->discarded_bytes = 0;
  153628. }
  153629. cinfo->unread_marker = c;
  153630. INPUT_SYNC(cinfo);
  153631. return TRUE;
  153632. }
  153633. LOCAL(boolean)
  153634. first_marker (j_decompress_ptr cinfo)
  153635. {
  153636. int c, c2;
  153637. INPUT_VARS(cinfo);
  153638. INPUT_BYTE(cinfo, c, return FALSE);
  153639. INPUT_BYTE(cinfo, c2, return FALSE);
  153640. if (c != 0xFF || c2 != (int) M_SOI)
  153641. ERREXIT2(cinfo, JERR_NO_SOI, c, c2);
  153642. cinfo->unread_marker = c2;
  153643. INPUT_SYNC(cinfo);
  153644. return TRUE;
  153645. }
  153646. METHODDEF(int)
  153647. read_markers (j_decompress_ptr cinfo)
  153648. {
  153649. for (;;) {
  153650. if (cinfo->unread_marker == 0) {
  153651. if (! cinfo->marker->saw_SOI) {
  153652. if (! first_marker(cinfo))
  153653. return JPEG_SUSPENDED;
  153654. } else {
  153655. if (! next_marker(cinfo))
  153656. return JPEG_SUSPENDED;
  153657. }
  153658. }
  153659. switch (cinfo->unread_marker) {
  153660. case M_SOI:
  153661. if (! get_soi(cinfo))
  153662. return JPEG_SUSPENDED;
  153663. break;
  153664. case M_SOF0: /* Baseline */
  153665. case M_SOF1: /* Extended sequential, Huffman */
  153666. if (! get_sof(cinfo, FALSE, FALSE))
  153667. return JPEG_SUSPENDED;
  153668. break;
  153669. case M_SOF2: /* Progressive, Huffman */
  153670. if (! get_sof(cinfo, TRUE, FALSE))
  153671. return JPEG_SUSPENDED;
  153672. break;
  153673. case M_SOF9: /* Extended sequential, arithmetic */
  153674. if (! get_sof(cinfo, FALSE, TRUE))
  153675. return JPEG_SUSPENDED;
  153676. break;
  153677. case M_SOF10: /* Progressive, arithmetic */
  153678. if (! get_sof(cinfo, TRUE, TRUE))
  153679. return JPEG_SUSPENDED;
  153680. break;
  153681. case M_SOF3: /* Lossless, Huffman */
  153682. case M_SOF5: /* Differential sequential, Huffman */
  153683. case M_SOF6: /* Differential progressive, Huffman */
  153684. case M_SOF7: /* Differential lossless, Huffman */
  153685. case M_JPG: /* Reserved for JPEG extensions */
  153686. case M_SOF11: /* Lossless, arithmetic */
  153687. case M_SOF13: /* Differential sequential, arithmetic */
  153688. case M_SOF14: /* Differential progressive, arithmetic */
  153689. case M_SOF15: /* Differential lossless, arithmetic */
  153690. ERREXIT1(cinfo, JERR_SOF_UNSUPPORTED, cinfo->unread_marker);
  153691. break;
  153692. case M_SOS:
  153693. if (! get_sos(cinfo))
  153694. return JPEG_SUSPENDED;
  153695. cinfo->unread_marker = 0; /* processed the marker */
  153696. return JPEG_REACHED_SOS;
  153697. case M_EOI:
  153698. TRACEMS(cinfo, 1, JTRC_EOI);
  153699. cinfo->unread_marker = 0; /* processed the marker */
  153700. return JPEG_REACHED_EOI;
  153701. case M_DAC:
  153702. if (! get_dac(cinfo))
  153703. return JPEG_SUSPENDED;
  153704. break;
  153705. case M_DHT:
  153706. if (! get_dht(cinfo))
  153707. return JPEG_SUSPENDED;
  153708. break;
  153709. case M_DQT:
  153710. if (! get_dqt(cinfo))
  153711. return JPEG_SUSPENDED;
  153712. break;
  153713. case M_DRI:
  153714. if (! get_dri(cinfo))
  153715. return JPEG_SUSPENDED;
  153716. break;
  153717. case M_APP0:
  153718. case M_APP1:
  153719. case M_APP2:
  153720. case M_APP3:
  153721. case M_APP4:
  153722. case M_APP5:
  153723. case M_APP6:
  153724. case M_APP7:
  153725. case M_APP8:
  153726. case M_APP9:
  153727. case M_APP10:
  153728. case M_APP11:
  153729. case M_APP12:
  153730. case M_APP13:
  153731. case M_APP14:
  153732. case M_APP15:
  153733. if (! (*((my_marker_ptr2) cinfo->marker)->process_APPn[
  153734. cinfo->unread_marker - (int) M_APP0]) (cinfo))
  153735. return JPEG_SUSPENDED;
  153736. break;
  153737. case M_COM:
  153738. if (! (*((my_marker_ptr2) cinfo->marker)->process_COM) (cinfo))
  153739. return JPEG_SUSPENDED;
  153740. break;
  153741. case M_RST0: /* these are all parameterless */
  153742. case M_RST1:
  153743. case M_RST2:
  153744. case M_RST3:
  153745. case M_RST4:
  153746. case M_RST5:
  153747. case M_RST6:
  153748. case M_RST7:
  153749. case M_TEM:
  153750. TRACEMS1(cinfo, 1, JTRC_PARMLESS_MARKER, cinfo->unread_marker);
  153751. break;
  153752. case M_DNL: /* Ignore DNL ... perhaps the wrong thing */
  153753. if (! skip_variable(cinfo))
  153754. return JPEG_SUSPENDED;
  153755. break;
  153756. default: /* must be DHP, EXP, JPGn, or RESn */
  153757. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo->unread_marker);
  153758. break;
  153759. }
  153760. cinfo->unread_marker = 0;
  153761. } /* end loop */
  153762. }
  153763. METHODDEF(boolean)
  153764. read_restart_marker (j_decompress_ptr cinfo)
  153765. {
  153766. if (cinfo->unread_marker == 0) {
  153767. if (! next_marker(cinfo))
  153768. return FALSE;
  153769. }
  153770. if (cinfo->unread_marker ==
  153771. ((int) M_RST0 + cinfo->marker->next_restart_num)) {
  153772. TRACEMS1(cinfo, 3, JTRC_RST, cinfo->marker->next_restart_num);
  153773. cinfo->unread_marker = 0;
  153774. } else {
  153775. if (! (*cinfo->src->resync_to_restart) (cinfo,
  153776. cinfo->marker->next_restart_num))
  153777. return FALSE;
  153778. }
  153779. cinfo->marker->next_restart_num = (cinfo->marker->next_restart_num + 1) & 7;
  153780. return TRUE;
  153781. }
  153782. GLOBAL(boolean)
  153783. jpeg_resync_to_restart (j_decompress_ptr cinfo, int desired)
  153784. {
  153785. int marker = cinfo->unread_marker;
  153786. int action = 1;
  153787. WARNMS2(cinfo, JWRN_MUST_RESYNC, marker, desired);
  153788. for (;;) {
  153789. if (marker < (int) M_SOF0)
  153790. action = 2; /* invalid marker */
  153791. else if (marker < (int) M_RST0 || marker > (int) M_RST7)
  153792. action = 3; /* valid non-restart marker */
  153793. else {
  153794. if (marker == ((int) M_RST0 + ((desired+1) & 7)) ||
  153795. marker == ((int) M_RST0 + ((desired+2) & 7)))
  153796. action = 3; /* one of the next two expected restarts */
  153797. else if (marker == ((int) M_RST0 + ((desired-1) & 7)) ||
  153798. marker == ((int) M_RST0 + ((desired-2) & 7)))
  153799. action = 2; /* a prior restart, so advance */
  153800. else
  153801. action = 1; /* desired restart or too far away */
  153802. }
  153803. TRACEMS2(cinfo, 4, JTRC_RECOVERY_ACTION, marker, action);
  153804. switch (action) {
  153805. case 1:
  153806. cinfo->unread_marker = 0;
  153807. return TRUE;
  153808. case 2:
  153809. if (! next_marker(cinfo))
  153810. return FALSE;
  153811. marker = cinfo->unread_marker;
  153812. break;
  153813. case 3:
  153814. return TRUE;
  153815. }
  153816. } /* end loop */
  153817. }
  153818. METHODDEF(void)
  153819. reset_marker_reader (j_decompress_ptr cinfo)
  153820. {
  153821. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153822. cinfo->comp_info = NULL; /* until allocated by get_sof */
  153823. cinfo->input_scan_number = 0; /* no SOS seen yet */
  153824. cinfo->unread_marker = 0; /* no pending marker */
  153825. marker->pub.saw_SOI = FALSE; /* set internal state too */
  153826. marker->pub.saw_SOF = FALSE;
  153827. marker->pub.discarded_bytes = 0;
  153828. marker->cur_marker = NULL;
  153829. }
  153830. GLOBAL(void)
  153831. jinit_marker_reader (j_decompress_ptr cinfo)
  153832. {
  153833. my_marker_ptr2 marker;
  153834. int i;
  153835. marker = (my_marker_ptr2)
  153836. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  153837. SIZEOF(my_marker_reader));
  153838. cinfo->marker = (struct jpeg_marker_reader *) marker;
  153839. marker->pub.reset_marker_reader = reset_marker_reader;
  153840. marker->pub.read_markers = read_markers;
  153841. marker->pub.read_restart_marker = read_restart_marker;
  153842. marker->process_COM = skip_variable;
  153843. marker->length_limit_COM = 0;
  153844. for (i = 0; i < 16; i++) {
  153845. marker->process_APPn[i] = skip_variable;
  153846. marker->length_limit_APPn[i] = 0;
  153847. }
  153848. marker->process_APPn[0] = get_interesting_appn;
  153849. marker->process_APPn[14] = get_interesting_appn;
  153850. reset_marker_reader(cinfo);
  153851. }
  153852. #ifdef SAVE_MARKERS_SUPPORTED
  153853. GLOBAL(void)
  153854. jpeg_save_markers (j_decompress_ptr cinfo, int marker_code,
  153855. unsigned int length_limit)
  153856. {
  153857. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153858. long maxlength;
  153859. jpeg_marker_parser_method processor;
  153860. maxlength = cinfo->mem->max_alloc_chunk - SIZEOF(struct jpeg_marker_struct);
  153861. if (((long) length_limit) > maxlength)
  153862. length_limit = (unsigned int) maxlength;
  153863. if (length_limit) {
  153864. processor = save_marker;
  153865. if (marker_code == (int) M_APP0 && length_limit < APP0_DATA_LEN)
  153866. length_limit = APP0_DATA_LEN;
  153867. else if (marker_code == (int) M_APP14 && length_limit < APP14_DATA_LEN)
  153868. length_limit = APP14_DATA_LEN;
  153869. } else {
  153870. processor = skip_variable;
  153871. if (marker_code == (int) M_APP0 || marker_code == (int) M_APP14)
  153872. processor = get_interesting_appn;
  153873. }
  153874. if (marker_code == (int) M_COM) {
  153875. marker->process_COM = processor;
  153876. marker->length_limit_COM = length_limit;
  153877. } else if (marker_code >= (int) M_APP0 && marker_code <= (int) M_APP15) {
  153878. marker->process_APPn[marker_code - (int) M_APP0] = processor;
  153879. marker->length_limit_APPn[marker_code - (int) M_APP0] = length_limit;
  153880. } else
  153881. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, marker_code);
  153882. }
  153883. #endif /* SAVE_MARKERS_SUPPORTED */
  153884. GLOBAL(void)
  153885. jpeg_set_marker_processor (j_decompress_ptr cinfo, int marker_code,
  153886. jpeg_marker_parser_method routine)
  153887. {
  153888. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153889. if (marker_code == (int) M_COM)
  153890. marker->process_COM = routine;
  153891. else if (marker_code >= (int) M_APP0 && marker_code <= (int) M_APP15)
  153892. marker->process_APPn[marker_code - (int) M_APP0] = routine;
  153893. else
  153894. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, marker_code);
  153895. }
  153896. /*** End of inlined file: jdmarker.c ***/
  153897. /*** Start of inlined file: jdmaster.c ***/
  153898. #define JPEG_INTERNALS
  153899. typedef struct {
  153900. struct jpeg_decomp_master pub; /* public fields */
  153901. int pass_number; /* # of passes completed */
  153902. boolean using_merged_upsample; /* TRUE if using merged upsample/cconvert */
  153903. struct jpeg_color_quantizer * quantizer_1pass;
  153904. struct jpeg_color_quantizer * quantizer_2pass;
  153905. } my_decomp_master;
  153906. typedef my_decomp_master * my_master_ptr6;
  153907. LOCAL(boolean)
  153908. use_merged_upsample (j_decompress_ptr cinfo)
  153909. {
  153910. #ifdef UPSAMPLE_MERGING_SUPPORTED
  153911. if (cinfo->do_fancy_upsampling || cinfo->CCIR601_sampling)
  153912. return FALSE;
  153913. if (cinfo->jpeg_color_space != JCS_YCbCr || cinfo->num_components != 3 ||
  153914. cinfo->out_color_space != JCS_RGB ||
  153915. cinfo->out_color_components != RGB_PIXELSIZE)
  153916. return FALSE;
  153917. if (cinfo->comp_info[0].h_samp_factor != 2 ||
  153918. cinfo->comp_info[1].h_samp_factor != 1 ||
  153919. cinfo->comp_info[2].h_samp_factor != 1 ||
  153920. cinfo->comp_info[0].v_samp_factor > 2 ||
  153921. cinfo->comp_info[1].v_samp_factor != 1 ||
  153922. cinfo->comp_info[2].v_samp_factor != 1)
  153923. return FALSE;
  153924. if (cinfo->comp_info[0].DCT_scaled_size != cinfo->min_DCT_scaled_size ||
  153925. cinfo->comp_info[1].DCT_scaled_size != cinfo->min_DCT_scaled_size ||
  153926. cinfo->comp_info[2].DCT_scaled_size != cinfo->min_DCT_scaled_size)
  153927. return FALSE;
  153928. return TRUE; /* by golly, it'll work... */
  153929. #else
  153930. return FALSE;
  153931. #endif
  153932. }
  153933. GLOBAL(void)
  153934. jpeg_calc_output_dimensions (j_decompress_ptr cinfo)
  153935. {
  153936. #ifdef IDCT_SCALING_SUPPORTED
  153937. int ci;
  153938. jpeg_component_info *compptr;
  153939. #endif
  153940. if (cinfo->global_state != DSTATE_READY)
  153941. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  153942. #ifdef IDCT_SCALING_SUPPORTED
  153943. if (cinfo->scale_num * 8 <= cinfo->scale_denom) {
  153944. cinfo->output_width = (JDIMENSION)
  153945. jdiv_round_up((long) cinfo->image_width, 8L);
  153946. cinfo->output_height = (JDIMENSION)
  153947. jdiv_round_up((long) cinfo->image_height, 8L);
  153948. cinfo->min_DCT_scaled_size = 1;
  153949. } else if (cinfo->scale_num * 4 <= cinfo->scale_denom) {
  153950. cinfo->output_width = (JDIMENSION)
  153951. jdiv_round_up((long) cinfo->image_width, 4L);
  153952. cinfo->output_height = (JDIMENSION)
  153953. jdiv_round_up((long) cinfo->image_height, 4L);
  153954. cinfo->min_DCT_scaled_size = 2;
  153955. } else if (cinfo->scale_num * 2 <= cinfo->scale_denom) {
  153956. cinfo->output_width = (JDIMENSION)
  153957. jdiv_round_up((long) cinfo->image_width, 2L);
  153958. cinfo->output_height = (JDIMENSION)
  153959. jdiv_round_up((long) cinfo->image_height, 2L);
  153960. cinfo->min_DCT_scaled_size = 4;
  153961. } else {
  153962. cinfo->output_width = cinfo->image_width;
  153963. cinfo->output_height = cinfo->image_height;
  153964. cinfo->min_DCT_scaled_size = DCTSIZE;
  153965. }
  153966. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153967. ci++, compptr++) {
  153968. int ssize = cinfo->min_DCT_scaled_size;
  153969. while (ssize < DCTSIZE &&
  153970. (compptr->h_samp_factor * ssize * 2 <=
  153971. cinfo->max_h_samp_factor * cinfo->min_DCT_scaled_size) &&
  153972. (compptr->v_samp_factor * ssize * 2 <=
  153973. cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size)) {
  153974. ssize = ssize * 2;
  153975. }
  153976. compptr->DCT_scaled_size = ssize;
  153977. }
  153978. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153979. ci++, compptr++) {
  153980. compptr->downsampled_width = (JDIMENSION)
  153981. jdiv_round_up((long) cinfo->image_width *
  153982. (long) (compptr->h_samp_factor * compptr->DCT_scaled_size),
  153983. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  153984. compptr->downsampled_height = (JDIMENSION)
  153985. jdiv_round_up((long) cinfo->image_height *
  153986. (long) (compptr->v_samp_factor * compptr->DCT_scaled_size),
  153987. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  153988. }
  153989. #else /* !IDCT_SCALING_SUPPORTED */
  153990. cinfo->output_width = cinfo->image_width;
  153991. cinfo->output_height = cinfo->image_height;
  153992. #endif /* IDCT_SCALING_SUPPORTED */
  153993. switch (cinfo->out_color_space) {
  153994. case JCS_GRAYSCALE:
  153995. cinfo->out_color_components = 1;
  153996. break;
  153997. case JCS_RGB:
  153998. #if RGB_PIXELSIZE != 3
  153999. cinfo->out_color_components = RGB_PIXELSIZE;
  154000. break;
  154001. #endif /* else share code with YCbCr */
  154002. case JCS_YCbCr:
  154003. cinfo->out_color_components = 3;
  154004. break;
  154005. case JCS_CMYK:
  154006. case JCS_YCCK:
  154007. cinfo->out_color_components = 4;
  154008. break;
  154009. default: /* else must be same colorspace as in file */
  154010. cinfo->out_color_components = cinfo->num_components;
  154011. break;
  154012. }
  154013. cinfo->output_components = (cinfo->quantize_colors ? 1 :
  154014. cinfo->out_color_components);
  154015. if (use_merged_upsample(cinfo))
  154016. cinfo->rec_outbuf_height = cinfo->max_v_samp_factor;
  154017. else
  154018. cinfo->rec_outbuf_height = 1;
  154019. }
  154020. LOCAL(void)
  154021. prepare_range_limit_table (j_decompress_ptr cinfo)
  154022. {
  154023. JSAMPLE * table;
  154024. int i;
  154025. table = (JSAMPLE *)
  154026. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154027. (5 * (MAXJSAMPLE+1) + CENTERJSAMPLE) * SIZEOF(JSAMPLE));
  154028. table += (MAXJSAMPLE+1); /* allow negative subscripts of simple table */
  154029. cinfo->sample_range_limit = table;
  154030. MEMZERO(table - (MAXJSAMPLE+1), (MAXJSAMPLE+1) * SIZEOF(JSAMPLE));
  154031. for (i = 0; i <= MAXJSAMPLE; i++)
  154032. table[i] = (JSAMPLE) i;
  154033. table += CENTERJSAMPLE; /* Point to where post-IDCT table starts */
  154034. for (i = CENTERJSAMPLE; i < 2*(MAXJSAMPLE+1); i++)
  154035. table[i] = MAXJSAMPLE;
  154036. MEMZERO(table + (2 * (MAXJSAMPLE+1)),
  154037. (2 * (MAXJSAMPLE+1) - CENTERJSAMPLE) * SIZEOF(JSAMPLE));
  154038. MEMCOPY(table + (4 * (MAXJSAMPLE+1) - CENTERJSAMPLE),
  154039. cinfo->sample_range_limit, CENTERJSAMPLE * SIZEOF(JSAMPLE));
  154040. }
  154041. LOCAL(void)
  154042. master_selection (j_decompress_ptr cinfo)
  154043. {
  154044. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  154045. boolean use_c_buffer;
  154046. long samplesperrow;
  154047. JDIMENSION jd_samplesperrow;
  154048. jpeg_calc_output_dimensions(cinfo);
  154049. prepare_range_limit_table(cinfo);
  154050. samplesperrow = (long) cinfo->output_width * (long) cinfo->out_color_components;
  154051. jd_samplesperrow = (JDIMENSION) samplesperrow;
  154052. if ((long) jd_samplesperrow != samplesperrow)
  154053. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  154054. master->pass_number = 0;
  154055. master->using_merged_upsample = use_merged_upsample(cinfo);
  154056. master->quantizer_1pass = NULL;
  154057. master->quantizer_2pass = NULL;
  154058. if (! cinfo->quantize_colors || ! cinfo->buffered_image) {
  154059. cinfo->enable_1pass_quant = FALSE;
  154060. cinfo->enable_external_quant = FALSE;
  154061. cinfo->enable_2pass_quant = FALSE;
  154062. }
  154063. if (cinfo->quantize_colors) {
  154064. if (cinfo->raw_data_out)
  154065. ERREXIT(cinfo, JERR_NOTIMPL);
  154066. if (cinfo->out_color_components != 3) {
  154067. cinfo->enable_1pass_quant = TRUE;
  154068. cinfo->enable_external_quant = FALSE;
  154069. cinfo->enable_2pass_quant = FALSE;
  154070. cinfo->colormap = NULL;
  154071. } else if (cinfo->colormap != NULL) {
  154072. cinfo->enable_external_quant = TRUE;
  154073. } else if (cinfo->two_pass_quantize) {
  154074. cinfo->enable_2pass_quant = TRUE;
  154075. } else {
  154076. cinfo->enable_1pass_quant = TRUE;
  154077. }
  154078. if (cinfo->enable_1pass_quant) {
  154079. #ifdef QUANT_1PASS_SUPPORTED
  154080. jinit_1pass_quantizer(cinfo);
  154081. master->quantizer_1pass = cinfo->cquantize;
  154082. #else
  154083. ERREXIT(cinfo, JERR_NOT_COMPILED);
  154084. #endif
  154085. }
  154086. if (cinfo->enable_2pass_quant || cinfo->enable_external_quant) {
  154087. #ifdef QUANT_2PASS_SUPPORTED
  154088. jinit_2pass_quantizer(cinfo);
  154089. master->quantizer_2pass = cinfo->cquantize;
  154090. #else
  154091. ERREXIT(cinfo, JERR_NOT_COMPILED);
  154092. #endif
  154093. }
  154094. }
  154095. if (! cinfo->raw_data_out) {
  154096. if (master->using_merged_upsample) {
  154097. #ifdef UPSAMPLE_MERGING_SUPPORTED
  154098. jinit_merged_upsampler(cinfo); /* does color conversion too */
  154099. #else
  154100. ERREXIT(cinfo, JERR_NOT_COMPILED);
  154101. #endif
  154102. } else {
  154103. jinit_color_deconverter(cinfo);
  154104. jinit_upsampler(cinfo);
  154105. }
  154106. jinit_d_post_controller(cinfo, cinfo->enable_2pass_quant);
  154107. }
  154108. jinit_inverse_dct(cinfo);
  154109. if (cinfo->arith_code) {
  154110. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  154111. } else {
  154112. if (cinfo->progressive_mode) {
  154113. #ifdef D_PROGRESSIVE_SUPPORTED
  154114. jinit_phuff_decoder(cinfo);
  154115. #else
  154116. ERREXIT(cinfo, JERR_NOT_COMPILED);
  154117. #endif
  154118. } else
  154119. jinit_huff_decoder(cinfo);
  154120. }
  154121. use_c_buffer = cinfo->inputctl->has_multiple_scans || cinfo->buffered_image;
  154122. jinit_d_coef_controller(cinfo, use_c_buffer);
  154123. if (! cinfo->raw_data_out)
  154124. jinit_d_main_controller(cinfo, FALSE /* never need full buffer here */);
  154125. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  154126. (*cinfo->inputctl->start_input_pass) (cinfo);
  154127. #ifdef D_MULTISCAN_FILES_SUPPORTED
  154128. if (cinfo->progress != NULL && ! cinfo->buffered_image &&
  154129. cinfo->inputctl->has_multiple_scans) {
  154130. int nscans;
  154131. if (cinfo->progressive_mode) {
  154132. nscans = 2 + 3 * cinfo->num_components;
  154133. } else {
  154134. nscans = cinfo->num_components;
  154135. }
  154136. cinfo->progress->pass_counter = 0L;
  154137. cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans;
  154138. cinfo->progress->completed_passes = 0;
  154139. cinfo->progress->total_passes = (cinfo->enable_2pass_quant ? 3 : 2);
  154140. master->pass_number++;
  154141. }
  154142. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  154143. }
  154144. METHODDEF(void)
  154145. prepare_for_output_pass (j_decompress_ptr cinfo)
  154146. {
  154147. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  154148. if (master->pub.is_dummy_pass) {
  154149. #ifdef QUANT_2PASS_SUPPORTED
  154150. master->pub.is_dummy_pass = FALSE;
  154151. (*cinfo->cquantize->start_pass) (cinfo, FALSE);
  154152. (*cinfo->post->start_pass) (cinfo, JBUF_CRANK_DEST);
  154153. (*cinfo->main->start_pass) (cinfo, JBUF_CRANK_DEST);
  154154. #else
  154155. ERREXIT(cinfo, JERR_NOT_COMPILED);
  154156. #endif /* QUANT_2PASS_SUPPORTED */
  154157. } else {
  154158. if (cinfo->quantize_colors && cinfo->colormap == NULL) {
  154159. if (cinfo->two_pass_quantize && cinfo->enable_2pass_quant) {
  154160. cinfo->cquantize = master->quantizer_2pass;
  154161. master->pub.is_dummy_pass = TRUE;
  154162. } else if (cinfo->enable_1pass_quant) {
  154163. cinfo->cquantize = master->quantizer_1pass;
  154164. } else {
  154165. ERREXIT(cinfo, JERR_MODE_CHANGE);
  154166. }
  154167. }
  154168. (*cinfo->idct->start_pass) (cinfo);
  154169. (*cinfo->coef->start_output_pass) (cinfo);
  154170. if (! cinfo->raw_data_out) {
  154171. if (! master->using_merged_upsample)
  154172. (*cinfo->cconvert->start_pass) (cinfo);
  154173. (*cinfo->upsample->start_pass) (cinfo);
  154174. if (cinfo->quantize_colors)
  154175. (*cinfo->cquantize->start_pass) (cinfo, master->pub.is_dummy_pass);
  154176. (*cinfo->post->start_pass) (cinfo,
  154177. (master->pub.is_dummy_pass ? JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
  154178. (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
  154179. }
  154180. }
  154181. if (cinfo->progress != NULL) {
  154182. cinfo->progress->completed_passes = master->pass_number;
  154183. cinfo->progress->total_passes = master->pass_number +
  154184. (master->pub.is_dummy_pass ? 2 : 1);
  154185. if (cinfo->buffered_image && ! cinfo->inputctl->eoi_reached) {
  154186. cinfo->progress->total_passes += (cinfo->enable_2pass_quant ? 2 : 1);
  154187. }
  154188. }
  154189. }
  154190. METHODDEF(void)
  154191. finish_output_pass (j_decompress_ptr cinfo)
  154192. {
  154193. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  154194. if (cinfo->quantize_colors)
  154195. (*cinfo->cquantize->finish_pass) (cinfo);
  154196. master->pass_number++;
  154197. }
  154198. #ifdef D_MULTISCAN_FILES_SUPPORTED
  154199. GLOBAL(void)
  154200. jpeg_new_colormap (j_decompress_ptr cinfo)
  154201. {
  154202. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  154203. if (cinfo->global_state != DSTATE_BUFIMAGE)
  154204. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  154205. if (cinfo->quantize_colors && cinfo->enable_external_quant &&
  154206. cinfo->colormap != NULL) {
  154207. cinfo->cquantize = master->quantizer_2pass;
  154208. (*cinfo->cquantize->new_color_map) (cinfo);
  154209. master->pub.is_dummy_pass = FALSE; /* just in case */
  154210. } else
  154211. ERREXIT(cinfo, JERR_MODE_CHANGE);
  154212. }
  154213. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  154214. GLOBAL(void)
  154215. jinit_master_decompress (j_decompress_ptr cinfo)
  154216. {
  154217. my_master_ptr6 master;
  154218. master = (my_master_ptr6)
  154219. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154220. SIZEOF(my_decomp_master));
  154221. cinfo->master = (struct jpeg_decomp_master *) master;
  154222. master->pub.prepare_for_output_pass = prepare_for_output_pass;
  154223. master->pub.finish_output_pass = finish_output_pass;
  154224. master->pub.is_dummy_pass = FALSE;
  154225. master_selection(cinfo);
  154226. }
  154227. /*** End of inlined file: jdmaster.c ***/
  154228. #undef FIX
  154229. /*** Start of inlined file: jdmerge.c ***/
  154230. #define JPEG_INTERNALS
  154231. #ifdef UPSAMPLE_MERGING_SUPPORTED
  154232. typedef struct {
  154233. struct jpeg_upsampler pub; /* public fields */
  154234. JMETHOD(void, upmethod, (j_decompress_ptr cinfo,
  154235. JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
  154236. JSAMPARRAY output_buf));
  154237. int * Cr_r_tab; /* => table for Cr to R conversion */
  154238. int * Cb_b_tab; /* => table for Cb to B conversion */
  154239. INT32 * Cr_g_tab; /* => table for Cr to G conversion */
  154240. INT32 * Cb_g_tab; /* => table for Cb to G conversion */
  154241. JSAMPROW spare_row;
  154242. boolean spare_full; /* T if spare buffer is occupied */
  154243. JDIMENSION out_row_width; /* samples per output row */
  154244. JDIMENSION rows_to_go; /* counts rows remaining in image */
  154245. } my_upsampler;
  154246. typedef my_upsampler * my_upsample_ptr;
  154247. #define SCALEBITS 16 /* speediest right-shift on some machines */
  154248. #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
  154249. #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
  154250. LOCAL(void)
  154251. build_ycc_rgb_table2 (j_decompress_ptr cinfo)
  154252. {
  154253. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  154254. int i;
  154255. INT32 x;
  154256. SHIFT_TEMPS
  154257. upsample->Cr_r_tab = (int *)
  154258. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154259. (MAXJSAMPLE+1) * SIZEOF(int));
  154260. upsample->Cb_b_tab = (int *)
  154261. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154262. (MAXJSAMPLE+1) * SIZEOF(int));
  154263. upsample->Cr_g_tab = (INT32 *)
  154264. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154265. (MAXJSAMPLE+1) * SIZEOF(INT32));
  154266. upsample->Cb_g_tab = (INT32 *)
  154267. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154268. (MAXJSAMPLE+1) * SIZEOF(INT32));
  154269. for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
  154270. upsample->Cr_r_tab[i] = (int)
  154271. RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
  154272. upsample->Cb_b_tab[i] = (int)
  154273. RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
  154274. upsample->Cr_g_tab[i] = (- FIX(0.71414)) * x;
  154275. upsample->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF;
  154276. }
  154277. }
  154278. METHODDEF(void)
  154279. start_pass_merged_upsample (j_decompress_ptr cinfo)
  154280. {
  154281. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  154282. upsample->spare_full = FALSE;
  154283. upsample->rows_to_go = cinfo->output_height;
  154284. }
  154285. METHODDEF(void)
  154286. merged_2v_upsample (j_decompress_ptr cinfo,
  154287. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154288. JDIMENSION in_row_groups_avail,
  154289. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154290. JDIMENSION out_rows_avail)
  154291. {
  154292. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  154293. JSAMPROW work_ptrs[2];
  154294. JDIMENSION num_rows; /* number of rows returned to caller */
  154295. if (upsample->spare_full) {
  154296. jcopy_sample_rows(& upsample->spare_row, 0, output_buf + *out_row_ctr, 0,
  154297. 1, upsample->out_row_width);
  154298. num_rows = 1;
  154299. upsample->spare_full = FALSE;
  154300. } else {
  154301. num_rows = 2;
  154302. if (num_rows > upsample->rows_to_go)
  154303. num_rows = upsample->rows_to_go;
  154304. out_rows_avail -= *out_row_ctr;
  154305. if (num_rows > out_rows_avail)
  154306. num_rows = out_rows_avail;
  154307. work_ptrs[0] = output_buf[*out_row_ctr];
  154308. if (num_rows > 1) {
  154309. work_ptrs[1] = output_buf[*out_row_ctr + 1];
  154310. } else {
  154311. work_ptrs[1] = upsample->spare_row;
  154312. upsample->spare_full = TRUE;
  154313. }
  154314. (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr, work_ptrs);
  154315. }
  154316. *out_row_ctr += num_rows;
  154317. upsample->rows_to_go -= num_rows;
  154318. if (! upsample->spare_full)
  154319. (*in_row_group_ctr)++;
  154320. }
  154321. METHODDEF(void)
  154322. merged_1v_upsample (j_decompress_ptr cinfo,
  154323. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154324. JDIMENSION in_row_groups_avail,
  154325. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154326. JDIMENSION out_rows_avail)
  154327. {
  154328. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  154329. (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr,
  154330. output_buf + *out_row_ctr);
  154331. (*out_row_ctr)++;
  154332. (*in_row_group_ctr)++;
  154333. }
  154334. METHODDEF(void)
  154335. h2v1_merged_upsample (j_decompress_ptr cinfo,
  154336. JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
  154337. JSAMPARRAY output_buf)
  154338. {
  154339. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  154340. register int y, cred, cgreen, cblue;
  154341. int cb, cr;
  154342. register JSAMPROW outptr;
  154343. JSAMPROW inptr0, inptr1, inptr2;
  154344. JDIMENSION col;
  154345. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  154346. int * Crrtab = upsample->Cr_r_tab;
  154347. int * Cbbtab = upsample->Cb_b_tab;
  154348. INT32 * Crgtab = upsample->Cr_g_tab;
  154349. INT32 * Cbgtab = upsample->Cb_g_tab;
  154350. SHIFT_TEMPS
  154351. inptr0 = input_buf[0][in_row_group_ctr];
  154352. inptr1 = input_buf[1][in_row_group_ctr];
  154353. inptr2 = input_buf[2][in_row_group_ctr];
  154354. outptr = output_buf[0];
  154355. for (col = cinfo->output_width >> 1; col > 0; col--) {
  154356. cb = GETJSAMPLE(*inptr1++);
  154357. cr = GETJSAMPLE(*inptr2++);
  154358. cred = Crrtab[cr];
  154359. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  154360. cblue = Cbbtab[cb];
  154361. y = GETJSAMPLE(*inptr0++);
  154362. outptr[RGB_RED] = range_limit[y + cred];
  154363. outptr[RGB_GREEN] = range_limit[y + cgreen];
  154364. outptr[RGB_BLUE] = range_limit[y + cblue];
  154365. outptr += RGB_PIXELSIZE;
  154366. y = GETJSAMPLE(*inptr0++);
  154367. outptr[RGB_RED] = range_limit[y + cred];
  154368. outptr[RGB_GREEN] = range_limit[y + cgreen];
  154369. outptr[RGB_BLUE] = range_limit[y + cblue];
  154370. outptr += RGB_PIXELSIZE;
  154371. }
  154372. if (cinfo->output_width & 1) {
  154373. cb = GETJSAMPLE(*inptr1);
  154374. cr = GETJSAMPLE(*inptr2);
  154375. cred = Crrtab[cr];
  154376. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  154377. cblue = Cbbtab[cb];
  154378. y = GETJSAMPLE(*inptr0);
  154379. outptr[RGB_RED] = range_limit[y + cred];
  154380. outptr[RGB_GREEN] = range_limit[y + cgreen];
  154381. outptr[RGB_BLUE] = range_limit[y + cblue];
  154382. }
  154383. }
  154384. METHODDEF(void)
  154385. h2v2_merged_upsample (j_decompress_ptr cinfo,
  154386. JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
  154387. JSAMPARRAY output_buf)
  154388. {
  154389. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  154390. register int y, cred, cgreen, cblue;
  154391. int cb, cr;
  154392. register JSAMPROW outptr0, outptr1;
  154393. JSAMPROW inptr00, inptr01, inptr1, inptr2;
  154394. JDIMENSION col;
  154395. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  154396. int * Crrtab = upsample->Cr_r_tab;
  154397. int * Cbbtab = upsample->Cb_b_tab;
  154398. INT32 * Crgtab = upsample->Cr_g_tab;
  154399. INT32 * Cbgtab = upsample->Cb_g_tab;
  154400. SHIFT_TEMPS
  154401. inptr00 = input_buf[0][in_row_group_ctr*2];
  154402. inptr01 = input_buf[0][in_row_group_ctr*2 + 1];
  154403. inptr1 = input_buf[1][in_row_group_ctr];
  154404. inptr2 = input_buf[2][in_row_group_ctr];
  154405. outptr0 = output_buf[0];
  154406. outptr1 = output_buf[1];
  154407. for (col = cinfo->output_width >> 1; col > 0; col--) {
  154408. cb = GETJSAMPLE(*inptr1++);
  154409. cr = GETJSAMPLE(*inptr2++);
  154410. cred = Crrtab[cr];
  154411. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  154412. cblue = Cbbtab[cb];
  154413. y = GETJSAMPLE(*inptr00++);
  154414. outptr0[RGB_RED] = range_limit[y + cred];
  154415. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  154416. outptr0[RGB_BLUE] = range_limit[y + cblue];
  154417. outptr0 += RGB_PIXELSIZE;
  154418. y = GETJSAMPLE(*inptr00++);
  154419. outptr0[RGB_RED] = range_limit[y + cred];
  154420. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  154421. outptr0[RGB_BLUE] = range_limit[y + cblue];
  154422. outptr0 += RGB_PIXELSIZE;
  154423. y = GETJSAMPLE(*inptr01++);
  154424. outptr1[RGB_RED] = range_limit[y + cred];
  154425. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  154426. outptr1[RGB_BLUE] = range_limit[y + cblue];
  154427. outptr1 += RGB_PIXELSIZE;
  154428. y = GETJSAMPLE(*inptr01++);
  154429. outptr1[RGB_RED] = range_limit[y + cred];
  154430. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  154431. outptr1[RGB_BLUE] = range_limit[y + cblue];
  154432. outptr1 += RGB_PIXELSIZE;
  154433. }
  154434. if (cinfo->output_width & 1) {
  154435. cb = GETJSAMPLE(*inptr1);
  154436. cr = GETJSAMPLE(*inptr2);
  154437. cred = Crrtab[cr];
  154438. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  154439. cblue = Cbbtab[cb];
  154440. y = GETJSAMPLE(*inptr00);
  154441. outptr0[RGB_RED] = range_limit[y + cred];
  154442. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  154443. outptr0[RGB_BLUE] = range_limit[y + cblue];
  154444. y = GETJSAMPLE(*inptr01);
  154445. outptr1[RGB_RED] = range_limit[y + cred];
  154446. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  154447. outptr1[RGB_BLUE] = range_limit[y + cblue];
  154448. }
  154449. }
  154450. GLOBAL(void)
  154451. jinit_merged_upsampler (j_decompress_ptr cinfo)
  154452. {
  154453. my_upsample_ptr upsample;
  154454. upsample = (my_upsample_ptr)
  154455. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154456. SIZEOF(my_upsampler));
  154457. cinfo->upsample = (struct jpeg_upsampler *) upsample;
  154458. upsample->pub.start_pass = start_pass_merged_upsample;
  154459. upsample->pub.need_context_rows = FALSE;
  154460. upsample->out_row_width = cinfo->output_width * cinfo->out_color_components;
  154461. if (cinfo->max_v_samp_factor == 2) {
  154462. upsample->pub.upsample = merged_2v_upsample;
  154463. upsample->upmethod = h2v2_merged_upsample;
  154464. upsample->spare_row = (JSAMPROW)
  154465. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154466. (size_t) (upsample->out_row_width * SIZEOF(JSAMPLE)));
  154467. } else {
  154468. upsample->pub.upsample = merged_1v_upsample;
  154469. upsample->upmethod = h2v1_merged_upsample;
  154470. upsample->spare_row = NULL;
  154471. }
  154472. build_ycc_rgb_table2(cinfo);
  154473. }
  154474. #endif /* UPSAMPLE_MERGING_SUPPORTED */
  154475. /*** End of inlined file: jdmerge.c ***/
  154476. #undef ASSIGN_STATE
  154477. /*** Start of inlined file: jdphuff.c ***/
  154478. #define JPEG_INTERNALS
  154479. #ifdef D_PROGRESSIVE_SUPPORTED
  154480. typedef struct {
  154481. unsigned int EOBRUN; /* remaining EOBs in EOBRUN */
  154482. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  154483. } savable_state3;
  154484. #ifndef NO_STRUCT_ASSIGN
  154485. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  154486. #else
  154487. #if MAX_COMPS_IN_SCAN == 4
  154488. #define ASSIGN_STATE(dest,src) \
  154489. ((dest).EOBRUN = (src).EOBRUN, \
  154490. (dest).last_dc_val[0] = (src).last_dc_val[0], \
  154491. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  154492. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  154493. (dest).last_dc_val[3] = (src).last_dc_val[3])
  154494. #endif
  154495. #endif
  154496. typedef struct {
  154497. struct jpeg_entropy_decoder pub; /* public fields */
  154498. bitread_perm_state bitstate; /* Bit buffer at start of MCU */
  154499. savable_state3 saved; /* Other state at start of MCU */
  154500. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  154501. d_derived_tbl * derived_tbls[NUM_HUFF_TBLS];
  154502. d_derived_tbl * ac_derived_tbl; /* active table during an AC scan */
  154503. } phuff_entropy_decoder;
  154504. typedef phuff_entropy_decoder * phuff_entropy_ptr2;
  154505. METHODDEF(boolean) decode_mcu_DC_first JPP((j_decompress_ptr cinfo,
  154506. JBLOCKROW *MCU_data));
  154507. METHODDEF(boolean) decode_mcu_AC_first JPP((j_decompress_ptr cinfo,
  154508. JBLOCKROW *MCU_data));
  154509. METHODDEF(boolean) decode_mcu_DC_refine JPP((j_decompress_ptr cinfo,
  154510. JBLOCKROW *MCU_data));
  154511. METHODDEF(boolean) decode_mcu_AC_refine JPP((j_decompress_ptr cinfo,
  154512. JBLOCKROW *MCU_data));
  154513. METHODDEF(void)
  154514. start_pass_phuff_decoder (j_decompress_ptr cinfo)
  154515. {
  154516. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154517. boolean is_DC_band, bad;
  154518. int ci, coefi, tbl;
  154519. int *coef_bit_ptr;
  154520. jpeg_component_info * compptr;
  154521. is_DC_band = (cinfo->Ss == 0);
  154522. bad = FALSE;
  154523. if (is_DC_band) {
  154524. if (cinfo->Se != 0)
  154525. bad = TRUE;
  154526. } else {
  154527. if (cinfo->Ss > cinfo->Se || cinfo->Se >= DCTSIZE2)
  154528. bad = TRUE;
  154529. if (cinfo->comps_in_scan != 1)
  154530. bad = TRUE;
  154531. }
  154532. if (cinfo->Ah != 0) {
  154533. if (cinfo->Al != cinfo->Ah-1)
  154534. bad = TRUE;
  154535. }
  154536. if (cinfo->Al > 13) /* need not check for < 0 */
  154537. bad = TRUE;
  154538. if (bad)
  154539. ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
  154540. cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
  154541. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  154542. int cindex = cinfo->cur_comp_info[ci]->component_index;
  154543. coef_bit_ptr = & cinfo->coef_bits[cindex][0];
  154544. if (!is_DC_band && coef_bit_ptr[0] < 0) /* AC without prior DC scan */
  154545. WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, 0);
  154546. for (coefi = cinfo->Ss; coefi <= cinfo->Se; coefi++) {
  154547. int expected = (coef_bit_ptr[coefi] < 0) ? 0 : coef_bit_ptr[coefi];
  154548. if (cinfo->Ah != expected)
  154549. WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, coefi);
  154550. coef_bit_ptr[coefi] = cinfo->Al;
  154551. }
  154552. }
  154553. if (cinfo->Ah == 0) {
  154554. if (is_DC_band)
  154555. entropy->pub.decode_mcu = decode_mcu_DC_first;
  154556. else
  154557. entropy->pub.decode_mcu = decode_mcu_AC_first;
  154558. } else {
  154559. if (is_DC_band)
  154560. entropy->pub.decode_mcu = decode_mcu_DC_refine;
  154561. else
  154562. entropy->pub.decode_mcu = decode_mcu_AC_refine;
  154563. }
  154564. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  154565. compptr = cinfo->cur_comp_info[ci];
  154566. if (is_DC_band) {
  154567. if (cinfo->Ah == 0) { /* DC refinement needs no table */
  154568. tbl = compptr->dc_tbl_no;
  154569. jpeg_make_d_derived_tbl(cinfo, TRUE, tbl,
  154570. & entropy->derived_tbls[tbl]);
  154571. }
  154572. } else {
  154573. tbl = compptr->ac_tbl_no;
  154574. jpeg_make_d_derived_tbl(cinfo, FALSE, tbl,
  154575. & entropy->derived_tbls[tbl]);
  154576. entropy->ac_derived_tbl = entropy->derived_tbls[tbl];
  154577. }
  154578. entropy->saved.last_dc_val[ci] = 0;
  154579. }
  154580. entropy->bitstate.bits_left = 0;
  154581. entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */
  154582. entropy->pub.insufficient_data = FALSE;
  154583. entropy->saved.EOBRUN = 0;
  154584. entropy->restarts_to_go = cinfo->restart_interval;
  154585. }
  154586. LOCAL(boolean)
  154587. process_restartp (j_decompress_ptr cinfo)
  154588. {
  154589. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154590. int ci;
  154591. cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8;
  154592. entropy->bitstate.bits_left = 0;
  154593. if (! (*cinfo->marker->read_restart_marker) (cinfo))
  154594. return FALSE;
  154595. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  154596. entropy->saved.last_dc_val[ci] = 0;
  154597. entropy->saved.EOBRUN = 0;
  154598. entropy->restarts_to_go = cinfo->restart_interval;
  154599. if (cinfo->unread_marker == 0)
  154600. entropy->pub.insufficient_data = FALSE;
  154601. return TRUE;
  154602. }
  154603. METHODDEF(boolean)
  154604. decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154605. {
  154606. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154607. int Al = cinfo->Al;
  154608. register int s, r;
  154609. int blkn, ci;
  154610. JBLOCKROW block;
  154611. BITREAD_STATE_VARS;
  154612. savable_state3 state;
  154613. d_derived_tbl * tbl;
  154614. jpeg_component_info * compptr;
  154615. if (cinfo->restart_interval) {
  154616. if (entropy->restarts_to_go == 0)
  154617. if (! process_restartp(cinfo))
  154618. return FALSE;
  154619. }
  154620. if (! entropy->pub.insufficient_data) {
  154621. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154622. ASSIGN_STATE(state, entropy->saved);
  154623. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  154624. block = MCU_data[blkn];
  154625. ci = cinfo->MCU_membership[blkn];
  154626. compptr = cinfo->cur_comp_info[ci];
  154627. tbl = entropy->derived_tbls[compptr->dc_tbl_no];
  154628. HUFF_DECODE(s, br_state, tbl, return FALSE, label1);
  154629. if (s) {
  154630. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  154631. r = GET_BITS(s);
  154632. s = HUFF_EXTEND(r, s);
  154633. }
  154634. s += state.last_dc_val[ci];
  154635. state.last_dc_val[ci] = s;
  154636. (*block)[0] = (JCOEF) (s << Al);
  154637. }
  154638. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154639. ASSIGN_STATE(entropy->saved, state);
  154640. }
  154641. entropy->restarts_to_go--;
  154642. return TRUE;
  154643. }
  154644. METHODDEF(boolean)
  154645. decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154646. {
  154647. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154648. int Se = cinfo->Se;
  154649. int Al = cinfo->Al;
  154650. register int s, k, r;
  154651. unsigned int EOBRUN;
  154652. JBLOCKROW block;
  154653. BITREAD_STATE_VARS;
  154654. d_derived_tbl * tbl;
  154655. if (cinfo->restart_interval) {
  154656. if (entropy->restarts_to_go == 0)
  154657. if (! process_restartp(cinfo))
  154658. return FALSE;
  154659. }
  154660. if (! entropy->pub.insufficient_data) {
  154661. EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we need */
  154662. if (EOBRUN > 0) /* if it's a band of zeroes... */
  154663. EOBRUN--; /* ...process it now (we do nothing) */
  154664. else {
  154665. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154666. block = MCU_data[0];
  154667. tbl = entropy->ac_derived_tbl;
  154668. for (k = cinfo->Ss; k <= Se; k++) {
  154669. HUFF_DECODE(s, br_state, tbl, return FALSE, label2);
  154670. r = s >> 4;
  154671. s &= 15;
  154672. if (s) {
  154673. k += r;
  154674. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  154675. r = GET_BITS(s);
  154676. s = HUFF_EXTEND(r, s);
  154677. (*block)[jpeg_natural_order[k]] = (JCOEF) (s << Al);
  154678. } else {
  154679. if (r == 15) { /* ZRL */
  154680. k += 15; /* skip 15 zeroes in band */
  154681. } else { /* EOBr, run length is 2^r + appended bits */
  154682. EOBRUN = 1 << r;
  154683. if (r) { /* EOBr, r > 0 */
  154684. CHECK_BIT_BUFFER(br_state, r, return FALSE);
  154685. r = GET_BITS(r);
  154686. EOBRUN += r;
  154687. }
  154688. EOBRUN--; /* this band is processed at this moment */
  154689. break; /* force end-of-band */
  154690. }
  154691. }
  154692. }
  154693. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154694. }
  154695. entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */
  154696. }
  154697. entropy->restarts_to_go--;
  154698. return TRUE;
  154699. }
  154700. METHODDEF(boolean)
  154701. decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154702. {
  154703. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154704. int p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
  154705. int blkn;
  154706. JBLOCKROW block;
  154707. BITREAD_STATE_VARS;
  154708. if (cinfo->restart_interval) {
  154709. if (entropy->restarts_to_go == 0)
  154710. if (! process_restartp(cinfo))
  154711. return FALSE;
  154712. }
  154713. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154714. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  154715. block = MCU_data[blkn];
  154716. CHECK_BIT_BUFFER(br_state, 1, return FALSE);
  154717. if (GET_BITS(1))
  154718. (*block)[0] |= p1;
  154719. }
  154720. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154721. entropy->restarts_to_go--;
  154722. return TRUE;
  154723. }
  154724. METHODDEF(boolean)
  154725. decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154726. {
  154727. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154728. int Se = cinfo->Se;
  154729. int p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
  154730. int m1 = (-1) << cinfo->Al; /* -1 in the bit position being coded */
  154731. register int s, k, r;
  154732. unsigned int EOBRUN;
  154733. JBLOCKROW block;
  154734. JCOEFPTR thiscoef;
  154735. BITREAD_STATE_VARS;
  154736. d_derived_tbl * tbl;
  154737. int num_newnz;
  154738. int newnz_pos[DCTSIZE2];
  154739. if (cinfo->restart_interval) {
  154740. if (entropy->restarts_to_go == 0)
  154741. if (! process_restartp(cinfo))
  154742. return FALSE;
  154743. }
  154744. if (! entropy->pub.insufficient_data) {
  154745. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154746. EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we need */
  154747. block = MCU_data[0];
  154748. tbl = entropy->ac_derived_tbl;
  154749. num_newnz = 0;
  154750. k = cinfo->Ss;
  154751. if (EOBRUN == 0) {
  154752. for (; k <= Se; k++) {
  154753. HUFF_DECODE(s, br_state, tbl, goto undoit, label3);
  154754. r = s >> 4;
  154755. s &= 15;
  154756. if (s) {
  154757. if (s != 1) /* size of new coef should always be 1 */
  154758. WARNMS(cinfo, JWRN_HUFF_BAD_CODE);
  154759. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  154760. if (GET_BITS(1))
  154761. s = p1; /* newly nonzero coef is positive */
  154762. else
  154763. s = m1; /* newly nonzero coef is negative */
  154764. } else {
  154765. if (r != 15) {
  154766. EOBRUN = 1 << r; /* EOBr, run length is 2^r + appended bits */
  154767. if (r) {
  154768. CHECK_BIT_BUFFER(br_state, r, goto undoit);
  154769. r = GET_BITS(r);
  154770. EOBRUN += r;
  154771. }
  154772. break; /* rest of block is handled by EOB logic */
  154773. }
  154774. }
  154775. do {
  154776. thiscoef = *block + jpeg_natural_order[k];
  154777. if (*thiscoef != 0) {
  154778. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  154779. if (GET_BITS(1)) {
  154780. if ((*thiscoef & p1) == 0) { /* do nothing if already set it */
  154781. if (*thiscoef >= 0)
  154782. *thiscoef += p1;
  154783. else
  154784. *thiscoef += m1;
  154785. }
  154786. }
  154787. } else {
  154788. if (--r < 0)
  154789. break; /* reached target zero coefficient */
  154790. }
  154791. k++;
  154792. } while (k <= Se);
  154793. if (s) {
  154794. int pos = jpeg_natural_order[k];
  154795. (*block)[pos] = (JCOEF) s;
  154796. newnz_pos[num_newnz++] = pos;
  154797. }
  154798. }
  154799. }
  154800. if (EOBRUN > 0) {
  154801. for (; k <= Se; k++) {
  154802. thiscoef = *block + jpeg_natural_order[k];
  154803. if (*thiscoef != 0) {
  154804. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  154805. if (GET_BITS(1)) {
  154806. if ((*thiscoef & p1) == 0) { /* do nothing if already changed it */
  154807. if (*thiscoef >= 0)
  154808. *thiscoef += p1;
  154809. else
  154810. *thiscoef += m1;
  154811. }
  154812. }
  154813. }
  154814. }
  154815. EOBRUN--;
  154816. }
  154817. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154818. entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */
  154819. }
  154820. entropy->restarts_to_go--;
  154821. return TRUE;
  154822. undoit:
  154823. while (num_newnz > 0)
  154824. (*block)[newnz_pos[--num_newnz]] = 0;
  154825. return FALSE;
  154826. }
  154827. GLOBAL(void)
  154828. jinit_phuff_decoder (j_decompress_ptr cinfo)
  154829. {
  154830. phuff_entropy_ptr2 entropy;
  154831. int *coef_bit_ptr;
  154832. int ci, i;
  154833. entropy = (phuff_entropy_ptr2)
  154834. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154835. SIZEOF(phuff_entropy_decoder));
  154836. cinfo->entropy = (struct jpeg_entropy_decoder *) entropy;
  154837. entropy->pub.start_pass = start_pass_phuff_decoder;
  154838. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  154839. entropy->derived_tbls[i] = NULL;
  154840. }
  154841. cinfo->coef_bits = (int (*)[DCTSIZE2])
  154842. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154843. cinfo->num_components*DCTSIZE2*SIZEOF(int));
  154844. coef_bit_ptr = & cinfo->coef_bits[0][0];
  154845. for (ci = 0; ci < cinfo->num_components; ci++)
  154846. for (i = 0; i < DCTSIZE2; i++)
  154847. *coef_bit_ptr++ = -1;
  154848. }
  154849. #endif /* D_PROGRESSIVE_SUPPORTED */
  154850. /*** End of inlined file: jdphuff.c ***/
  154851. /*** Start of inlined file: jdpostct.c ***/
  154852. #define JPEG_INTERNALS
  154853. typedef struct {
  154854. struct jpeg_d_post_controller pub; /* public fields */
  154855. jvirt_sarray_ptr whole_image; /* virtual array, or NULL if one-pass */
  154856. JSAMPARRAY buffer; /* strip buffer, or current strip of virtual */
  154857. JDIMENSION strip_height; /* buffer size in rows */
  154858. JDIMENSION starting_row; /* row # of first row in current strip */
  154859. JDIMENSION next_row; /* index of next row to fill/empty in strip */
  154860. } my_post_controller;
  154861. typedef my_post_controller * my_post_ptr;
  154862. METHODDEF(void) post_process_1pass
  154863. JPP((j_decompress_ptr cinfo,
  154864. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154865. JDIMENSION in_row_groups_avail,
  154866. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154867. JDIMENSION out_rows_avail));
  154868. #ifdef QUANT_2PASS_SUPPORTED
  154869. METHODDEF(void) post_process_prepass
  154870. JPP((j_decompress_ptr cinfo,
  154871. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154872. JDIMENSION in_row_groups_avail,
  154873. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154874. JDIMENSION out_rows_avail));
  154875. METHODDEF(void) post_process_2pass
  154876. JPP((j_decompress_ptr cinfo,
  154877. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154878. JDIMENSION in_row_groups_avail,
  154879. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154880. JDIMENSION out_rows_avail));
  154881. #endif
  154882. METHODDEF(void)
  154883. start_pass_dpost (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
  154884. {
  154885. my_post_ptr post = (my_post_ptr) cinfo->post;
  154886. switch (pass_mode) {
  154887. case JBUF_PASS_THRU:
  154888. if (cinfo->quantize_colors) {
  154889. post->pub.post_process_data = post_process_1pass;
  154890. if (post->buffer == NULL) {
  154891. post->buffer = (*cinfo->mem->access_virt_sarray)
  154892. ((j_common_ptr) cinfo, post->whole_image,
  154893. (JDIMENSION) 0, post->strip_height, TRUE);
  154894. }
  154895. } else {
  154896. post->pub.post_process_data = cinfo->upsample->upsample;
  154897. }
  154898. break;
  154899. #ifdef QUANT_2PASS_SUPPORTED
  154900. case JBUF_SAVE_AND_PASS:
  154901. if (post->whole_image == NULL)
  154902. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154903. post->pub.post_process_data = post_process_prepass;
  154904. break;
  154905. case JBUF_CRANK_DEST:
  154906. if (post->whole_image == NULL)
  154907. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154908. post->pub.post_process_data = post_process_2pass;
  154909. break;
  154910. #endif /* QUANT_2PASS_SUPPORTED */
  154911. default:
  154912. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154913. break;
  154914. }
  154915. post->starting_row = post->next_row = 0;
  154916. }
  154917. METHODDEF(void)
  154918. post_process_1pass (j_decompress_ptr cinfo,
  154919. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154920. JDIMENSION in_row_groups_avail,
  154921. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154922. JDIMENSION out_rows_avail)
  154923. {
  154924. my_post_ptr post = (my_post_ptr) cinfo->post;
  154925. JDIMENSION num_rows, max_rows;
  154926. max_rows = out_rows_avail - *out_row_ctr;
  154927. if (max_rows > post->strip_height)
  154928. max_rows = post->strip_height;
  154929. num_rows = 0;
  154930. (*cinfo->upsample->upsample) (cinfo,
  154931. input_buf, in_row_group_ctr, in_row_groups_avail,
  154932. post->buffer, &num_rows, max_rows);
  154933. (*cinfo->cquantize->color_quantize) (cinfo,
  154934. post->buffer, output_buf + *out_row_ctr, (int) num_rows);
  154935. *out_row_ctr += num_rows;
  154936. }
  154937. #ifdef QUANT_2PASS_SUPPORTED
  154938. METHODDEF(void)
  154939. post_process_prepass (j_decompress_ptr cinfo,
  154940. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154941. JDIMENSION in_row_groups_avail,
  154942. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154943. JDIMENSION out_rows_avail)
  154944. {
  154945. my_post_ptr post = (my_post_ptr) cinfo->post;
  154946. JDIMENSION old_next_row, num_rows;
  154947. if (post->next_row == 0) {
  154948. post->buffer = (*cinfo->mem->access_virt_sarray)
  154949. ((j_common_ptr) cinfo, post->whole_image,
  154950. post->starting_row, post->strip_height, TRUE);
  154951. }
  154952. old_next_row = post->next_row;
  154953. (*cinfo->upsample->upsample) (cinfo,
  154954. input_buf, in_row_group_ctr, in_row_groups_avail,
  154955. post->buffer, &post->next_row, post->strip_height);
  154956. if (post->next_row > old_next_row) {
  154957. num_rows = post->next_row - old_next_row;
  154958. (*cinfo->cquantize->color_quantize) (cinfo, post->buffer + old_next_row,
  154959. (JSAMPARRAY) NULL, (int) num_rows);
  154960. *out_row_ctr += num_rows;
  154961. }
  154962. if (post->next_row >= post->strip_height) {
  154963. post->starting_row += post->strip_height;
  154964. post->next_row = 0;
  154965. }
  154966. }
  154967. METHODDEF(void)
  154968. post_process_2pass (j_decompress_ptr cinfo,
  154969. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154970. JDIMENSION in_row_groups_avail,
  154971. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154972. JDIMENSION out_rows_avail)
  154973. {
  154974. my_post_ptr post = (my_post_ptr) cinfo->post;
  154975. JDIMENSION num_rows, max_rows;
  154976. if (post->next_row == 0) {
  154977. post->buffer = (*cinfo->mem->access_virt_sarray)
  154978. ((j_common_ptr) cinfo, post->whole_image,
  154979. post->starting_row, post->strip_height, FALSE);
  154980. }
  154981. num_rows = post->strip_height - post->next_row; /* available in strip */
  154982. max_rows = out_rows_avail - *out_row_ctr; /* available in output area */
  154983. if (num_rows > max_rows)
  154984. num_rows = max_rows;
  154985. max_rows = cinfo->output_height - post->starting_row;
  154986. if (num_rows > max_rows)
  154987. num_rows = max_rows;
  154988. (*cinfo->cquantize->color_quantize) (cinfo,
  154989. post->buffer + post->next_row, output_buf + *out_row_ctr,
  154990. (int) num_rows);
  154991. *out_row_ctr += num_rows;
  154992. post->next_row += num_rows;
  154993. if (post->next_row >= post->strip_height) {
  154994. post->starting_row += post->strip_height;
  154995. post->next_row = 0;
  154996. }
  154997. }
  154998. #endif /* QUANT_2PASS_SUPPORTED */
  154999. GLOBAL(void)
  155000. jinit_d_post_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  155001. {
  155002. my_post_ptr post;
  155003. post = (my_post_ptr)
  155004. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  155005. SIZEOF(my_post_controller));
  155006. cinfo->post = (struct jpeg_d_post_controller *) post;
  155007. post->pub.start_pass = start_pass_dpost;
  155008. post->whole_image = NULL; /* flag for no virtual arrays */
  155009. post->buffer = NULL; /* flag for no strip buffer */
  155010. if (cinfo->quantize_colors) {
  155011. post->strip_height = (JDIMENSION) cinfo->max_v_samp_factor;
  155012. if (need_full_buffer) {
  155013. #ifdef QUANT_2PASS_SUPPORTED
  155014. post->whole_image = (*cinfo->mem->request_virt_sarray)
  155015. ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  155016. cinfo->output_width * cinfo->out_color_components,
  155017. (JDIMENSION) jround_up((long) cinfo->output_height,
  155018. (long) post->strip_height),
  155019. post->strip_height);
  155020. #else
  155021. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  155022. #endif /* QUANT_2PASS_SUPPORTED */
  155023. } else {
  155024. post->buffer = (*cinfo->mem->alloc_sarray)
  155025. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  155026. cinfo->output_width * cinfo->out_color_components,
  155027. post->strip_height);
  155028. }
  155029. }
  155030. }
  155031. /*** End of inlined file: jdpostct.c ***/
  155032. #undef FIX
  155033. /*** Start of inlined file: jdsample.c ***/
  155034. #define JPEG_INTERNALS
  155035. typedef JMETHOD(void, upsample1_ptr,
  155036. (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155037. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr));
  155038. typedef struct {
  155039. struct jpeg_upsampler pub; /* public fields */
  155040. JSAMPARRAY color_buf[MAX_COMPONENTS];
  155041. upsample1_ptr methods[MAX_COMPONENTS];
  155042. int next_row_out; /* counts rows emitted from color_buf */
  155043. JDIMENSION rows_to_go; /* counts rows remaining in image */
  155044. int rowgroup_height[MAX_COMPONENTS];
  155045. UINT8 h_expand[MAX_COMPONENTS];
  155046. UINT8 v_expand[MAX_COMPONENTS];
  155047. } my_upsampler2;
  155048. typedef my_upsampler2 * my_upsample_ptr2;
  155049. METHODDEF(void)
  155050. start_pass_upsample (j_decompress_ptr cinfo)
  155051. {
  155052. my_upsample_ptr2 upsample = (my_upsample_ptr2) cinfo->upsample;
  155053. upsample->next_row_out = cinfo->max_v_samp_factor;
  155054. upsample->rows_to_go = cinfo->output_height;
  155055. }
  155056. METHODDEF(void)
  155057. sep_upsample (j_decompress_ptr cinfo,
  155058. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  155059. JDIMENSION in_row_groups_avail,
  155060. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  155061. JDIMENSION out_rows_avail)
  155062. {
  155063. my_upsample_ptr2 upsample = (my_upsample_ptr2) cinfo->upsample;
  155064. int ci;
  155065. jpeg_component_info * compptr;
  155066. JDIMENSION num_rows;
  155067. if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
  155068. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  155069. ci++, compptr++) {
  155070. (*upsample->methods[ci]) (cinfo, compptr,
  155071. input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
  155072. upsample->color_buf + ci);
  155073. }
  155074. upsample->next_row_out = 0;
  155075. }
  155076. num_rows = (JDIMENSION) (cinfo->max_v_samp_factor - upsample->next_row_out);
  155077. if (num_rows > upsample->rows_to_go)
  155078. num_rows = upsample->rows_to_go;
  155079. out_rows_avail -= *out_row_ctr;
  155080. if (num_rows > out_rows_avail)
  155081. num_rows = out_rows_avail;
  155082. (*cinfo->cconvert->color_convert) (cinfo, upsample->color_buf,
  155083. (JDIMENSION) upsample->next_row_out,
  155084. output_buf + *out_row_ctr,
  155085. (int) num_rows);
  155086. *out_row_ctr += num_rows;
  155087. upsample->rows_to_go -= num_rows;
  155088. upsample->next_row_out += num_rows;
  155089. if (upsample->next_row_out >= cinfo->max_v_samp_factor)
  155090. (*in_row_group_ctr)++;
  155091. }
  155092. METHODDEF(void)
  155093. fullsize_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155094. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  155095. {
  155096. *output_data_ptr = input_data;
  155097. }
  155098. METHODDEF(void)
  155099. noop_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155100. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  155101. {
  155102. *output_data_ptr = NULL; /* safety check */
  155103. }
  155104. METHODDEF(void)
  155105. int_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155106. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  155107. {
  155108. my_upsample_ptr2 upsample = (my_upsample_ptr2) cinfo->upsample;
  155109. JSAMPARRAY output_data = *output_data_ptr;
  155110. register JSAMPROW inptr, outptr;
  155111. register JSAMPLE invalue;
  155112. register int h;
  155113. JSAMPROW outend;
  155114. int h_expand, v_expand;
  155115. int inrow, outrow;
  155116. h_expand = upsample->h_expand[compptr->component_index];
  155117. v_expand = upsample->v_expand[compptr->component_index];
  155118. inrow = outrow = 0;
  155119. while (outrow < cinfo->max_v_samp_factor) {
  155120. inptr = input_data[inrow];
  155121. outptr = output_data[outrow];
  155122. outend = outptr + cinfo->output_width;
  155123. while (outptr < outend) {
  155124. invalue = *inptr++; /* don't need GETJSAMPLE() here */
  155125. for (h = h_expand; h > 0; h--) {
  155126. *outptr++ = invalue;
  155127. }
  155128. }
  155129. if (v_expand > 1) {
  155130. jcopy_sample_rows(output_data, outrow, output_data, outrow+1,
  155131. v_expand-1, cinfo->output_width);
  155132. }
  155133. inrow++;
  155134. outrow += v_expand;
  155135. }
  155136. }
  155137. METHODDEF(void)
  155138. h2v1_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155139. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  155140. {
  155141. JSAMPARRAY output_data = *output_data_ptr;
  155142. register JSAMPROW inptr, outptr;
  155143. register JSAMPLE invalue;
  155144. JSAMPROW outend;
  155145. int inrow;
  155146. for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
  155147. inptr = input_data[inrow];
  155148. outptr = output_data[inrow];
  155149. outend = outptr + cinfo->output_width;
  155150. while (outptr < outend) {
  155151. invalue = *inptr++; /* don't need GETJSAMPLE() here */
  155152. *outptr++ = invalue;
  155153. *outptr++ = invalue;
  155154. }
  155155. }
  155156. }
  155157. METHODDEF(void)
  155158. h2v2_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155159. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  155160. {
  155161. JSAMPARRAY output_data = *output_data_ptr;
  155162. register JSAMPROW inptr, outptr;
  155163. register JSAMPLE invalue;
  155164. JSAMPROW outend;
  155165. int inrow, outrow;
  155166. inrow = outrow = 0;
  155167. while (outrow < cinfo->max_v_samp_factor) {
  155168. inptr = input_data[inrow];
  155169. outptr = output_data[outrow];
  155170. outend = outptr + cinfo->output_width;
  155171. while (outptr < outend) {
  155172. invalue = *inptr++; /* don't need GETJSAMPLE() here */
  155173. *outptr++ = invalue;
  155174. *outptr++ = invalue;
  155175. }
  155176. jcopy_sample_rows(output_data, outrow, output_data, outrow+1,
  155177. 1, cinfo->output_width);
  155178. inrow++;
  155179. outrow += 2;
  155180. }
  155181. }
  155182. METHODDEF(void)
  155183. h2v1_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155184. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  155185. {
  155186. JSAMPARRAY output_data = *output_data_ptr;
  155187. register JSAMPROW inptr, outptr;
  155188. register int invalue;
  155189. register JDIMENSION colctr;
  155190. int inrow;
  155191. for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
  155192. inptr = input_data[inrow];
  155193. outptr = output_data[inrow];
  155194. invalue = GETJSAMPLE(*inptr++);
  155195. *outptr++ = (JSAMPLE) invalue;
  155196. *outptr++ = (JSAMPLE) ((invalue * 3 + GETJSAMPLE(*inptr) + 2) >> 2);
  155197. for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
  155198. invalue = GETJSAMPLE(*inptr++) * 3;
  155199. *outptr++ = (JSAMPLE) ((invalue + GETJSAMPLE(inptr[-2]) + 1) >> 2);
  155200. *outptr++ = (JSAMPLE) ((invalue + GETJSAMPLE(*inptr) + 2) >> 2);
  155201. }
  155202. invalue = GETJSAMPLE(*inptr);
  155203. *outptr++ = (JSAMPLE) ((invalue * 3 + GETJSAMPLE(inptr[-1]) + 1) >> 2);
  155204. *outptr++ = (JSAMPLE) invalue;
  155205. }
  155206. }
  155207. METHODDEF(void)
  155208. h2v2_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155209. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  155210. {
  155211. JSAMPARRAY output_data = *output_data_ptr;
  155212. register JSAMPROW inptr0, inptr1, outptr;
  155213. #if BITS_IN_JSAMPLE == 8
  155214. register int thiscolsum, lastcolsum, nextcolsum;
  155215. #else
  155216. register INT32 thiscolsum, lastcolsum, nextcolsum;
  155217. #endif
  155218. register JDIMENSION colctr;
  155219. int inrow, outrow, v;
  155220. inrow = outrow = 0;
  155221. while (outrow < cinfo->max_v_samp_factor) {
  155222. for (v = 0; v < 2; v++) {
  155223. inptr0 = input_data[inrow];
  155224. if (v == 0) /* next nearest is row above */
  155225. inptr1 = input_data[inrow-1];
  155226. else /* next nearest is row below */
  155227. inptr1 = input_data[inrow+1];
  155228. outptr = output_data[outrow++];
  155229. thiscolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
  155230. nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
  155231. *outptr++ = (JSAMPLE) ((thiscolsum * 4 + 8) >> 4);
  155232. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4);
  155233. lastcolsum = thiscolsum; thiscolsum = nextcolsum;
  155234. for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
  155235. nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
  155236. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4);
  155237. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4);
  155238. lastcolsum = thiscolsum; thiscolsum = nextcolsum;
  155239. }
  155240. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4);
  155241. *outptr++ = (JSAMPLE) ((thiscolsum * 4 + 7) >> 4);
  155242. }
  155243. inrow++;
  155244. }
  155245. }
  155246. GLOBAL(void)
  155247. jinit_upsampler (j_decompress_ptr cinfo)
  155248. {
  155249. my_upsample_ptr2 upsample;
  155250. int ci;
  155251. jpeg_component_info * compptr;
  155252. boolean need_buffer, do_fancy;
  155253. int h_in_group, v_in_group, h_out_group, v_out_group;
  155254. upsample = (my_upsample_ptr2)
  155255. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  155256. SIZEOF(my_upsampler2));
  155257. cinfo->upsample = (struct jpeg_upsampler *) upsample;
  155258. upsample->pub.start_pass = start_pass_upsample;
  155259. upsample->pub.upsample = sep_upsample;
  155260. upsample->pub.need_context_rows = FALSE; /* until we find out differently */
  155261. if (cinfo->CCIR601_sampling) /* this isn't supported */
  155262. ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
  155263. do_fancy = cinfo->do_fancy_upsampling && cinfo->min_DCT_scaled_size > 1;
  155264. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  155265. ci++, compptr++) {
  155266. h_in_group = (compptr->h_samp_factor * compptr->DCT_scaled_size) /
  155267. cinfo->min_DCT_scaled_size;
  155268. v_in_group = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  155269. cinfo->min_DCT_scaled_size;
  155270. h_out_group = cinfo->max_h_samp_factor;
  155271. v_out_group = cinfo->max_v_samp_factor;
  155272. upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
  155273. need_buffer = TRUE;
  155274. if (! compptr->component_needed) {
  155275. upsample->methods[ci] = noop_upsample;
  155276. need_buffer = FALSE;
  155277. } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
  155278. upsample->methods[ci] = fullsize_upsample;
  155279. need_buffer = FALSE;
  155280. } else if (h_in_group * 2 == h_out_group &&
  155281. v_in_group == v_out_group) {
  155282. if (do_fancy && compptr->downsampled_width > 2)
  155283. upsample->methods[ci] = h2v1_fancy_upsample;
  155284. else
  155285. upsample->methods[ci] = h2v1_upsample;
  155286. } else if (h_in_group * 2 == h_out_group &&
  155287. v_in_group * 2 == v_out_group) {
  155288. if (do_fancy && compptr->downsampled_width > 2) {
  155289. upsample->methods[ci] = h2v2_fancy_upsample;
  155290. upsample->pub.need_context_rows = TRUE;
  155291. } else
  155292. upsample->methods[ci] = h2v2_upsample;
  155293. } else if ((h_out_group % h_in_group) == 0 &&
  155294. (v_out_group % v_in_group) == 0) {
  155295. upsample->methods[ci] = int_upsample;
  155296. upsample->h_expand[ci] = (UINT8) (h_out_group / h_in_group);
  155297. upsample->v_expand[ci] = (UINT8) (v_out_group / v_in_group);
  155298. } else
  155299. ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
  155300. if (need_buffer) {
  155301. upsample->color_buf[ci] = (*cinfo->mem->alloc_sarray)
  155302. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  155303. (JDIMENSION) jround_up((long) cinfo->output_width,
  155304. (long) cinfo->max_h_samp_factor),
  155305. (JDIMENSION) cinfo->max_v_samp_factor);
  155306. }
  155307. }
  155308. }
  155309. /*** End of inlined file: jdsample.c ***/
  155310. /*** Start of inlined file: jdtrans.c ***/
  155311. #define JPEG_INTERNALS
  155312. LOCAL(void) transdecode_master_selection JPP((j_decompress_ptr cinfo));
  155313. GLOBAL(jvirt_barray_ptr *)
  155314. jpeg_read_coefficients (j_decompress_ptr cinfo)
  155315. {
  155316. if (cinfo->global_state == DSTATE_READY) {
  155317. transdecode_master_selection(cinfo);
  155318. cinfo->global_state = DSTATE_RDCOEFS;
  155319. }
  155320. if (cinfo->global_state == DSTATE_RDCOEFS) {
  155321. for (;;) {
  155322. int retcode;
  155323. if (cinfo->progress != NULL)
  155324. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  155325. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  155326. if (retcode == JPEG_SUSPENDED)
  155327. return NULL;
  155328. if (retcode == JPEG_REACHED_EOI)
  155329. break;
  155330. if (cinfo->progress != NULL &&
  155331. (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
  155332. if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
  155333. cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
  155334. }
  155335. }
  155336. }
  155337. cinfo->global_state = DSTATE_STOPPING;
  155338. }
  155339. if ((cinfo->global_state == DSTATE_STOPPING ||
  155340. cinfo->global_state == DSTATE_BUFIMAGE) && cinfo->buffered_image) {
  155341. return cinfo->coef->coef_arrays;
  155342. }
  155343. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  155344. return NULL; /* keep compiler happy */
  155345. }
  155346. LOCAL(void)
  155347. transdecode_master_selection (j_decompress_ptr cinfo)
  155348. {
  155349. cinfo->buffered_image = TRUE;
  155350. if (cinfo->arith_code) {
  155351. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  155352. } else {
  155353. if (cinfo->progressive_mode) {
  155354. #ifdef D_PROGRESSIVE_SUPPORTED
  155355. jinit_phuff_decoder(cinfo);
  155356. #else
  155357. ERREXIT(cinfo, JERR_NOT_COMPILED);
  155358. #endif
  155359. } else
  155360. jinit_huff_decoder(cinfo);
  155361. }
  155362. jinit_d_coef_controller(cinfo, TRUE);
  155363. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  155364. (*cinfo->inputctl->start_input_pass) (cinfo);
  155365. if (cinfo->progress != NULL) {
  155366. int nscans;
  155367. if (cinfo->progressive_mode) {
  155368. nscans = 2 + 3 * cinfo->num_components;
  155369. } else if (cinfo->inputctl->has_multiple_scans) {
  155370. nscans = cinfo->num_components;
  155371. } else {
  155372. nscans = 1;
  155373. }
  155374. cinfo->progress->pass_counter = 0L;
  155375. cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans;
  155376. cinfo->progress->completed_passes = 0;
  155377. cinfo->progress->total_passes = 1;
  155378. }
  155379. }
  155380. /*** End of inlined file: jdtrans.c ***/
  155381. /*** Start of inlined file: jfdctflt.c ***/
  155382. #define JPEG_INTERNALS
  155383. #ifdef DCT_FLOAT_SUPPORTED
  155384. #if DCTSIZE != 8
  155385. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155386. #endif
  155387. GLOBAL(void)
  155388. jpeg_fdct_float (FAST_FLOAT * data)
  155389. {
  155390. FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155391. FAST_FLOAT tmp10, tmp11, tmp12, tmp13;
  155392. FAST_FLOAT z1, z2, z3, z4, z5, z11, z13;
  155393. FAST_FLOAT *dataptr;
  155394. int ctr;
  155395. dataptr = data;
  155396. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155397. tmp0 = dataptr[0] + dataptr[7];
  155398. tmp7 = dataptr[0] - dataptr[7];
  155399. tmp1 = dataptr[1] + dataptr[6];
  155400. tmp6 = dataptr[1] - dataptr[6];
  155401. tmp2 = dataptr[2] + dataptr[5];
  155402. tmp5 = dataptr[2] - dataptr[5];
  155403. tmp3 = dataptr[3] + dataptr[4];
  155404. tmp4 = dataptr[3] - dataptr[4];
  155405. tmp10 = tmp0 + tmp3; /* phase 2 */
  155406. tmp13 = tmp0 - tmp3;
  155407. tmp11 = tmp1 + tmp2;
  155408. tmp12 = tmp1 - tmp2;
  155409. dataptr[0] = tmp10 + tmp11; /* phase 3 */
  155410. dataptr[4] = tmp10 - tmp11;
  155411. z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */
  155412. dataptr[2] = tmp13 + z1; /* phase 5 */
  155413. dataptr[6] = tmp13 - z1;
  155414. tmp10 = tmp4 + tmp5; /* phase 2 */
  155415. tmp11 = tmp5 + tmp6;
  155416. tmp12 = tmp6 + tmp7;
  155417. z5 = (tmp10 - tmp12) * ((FAST_FLOAT) 0.382683433); /* c6 */
  155418. z2 = ((FAST_FLOAT) 0.541196100) * tmp10 + z5; /* c2-c6 */
  155419. z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */
  155420. z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */
  155421. z11 = tmp7 + z3; /* phase 5 */
  155422. z13 = tmp7 - z3;
  155423. dataptr[5] = z13 + z2; /* phase 6 */
  155424. dataptr[3] = z13 - z2;
  155425. dataptr[1] = z11 + z4;
  155426. dataptr[7] = z11 - z4;
  155427. dataptr += DCTSIZE; /* advance pointer to next row */
  155428. }
  155429. dataptr = data;
  155430. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155431. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  155432. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  155433. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  155434. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  155435. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  155436. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  155437. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  155438. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  155439. tmp10 = tmp0 + tmp3; /* phase 2 */
  155440. tmp13 = tmp0 - tmp3;
  155441. tmp11 = tmp1 + tmp2;
  155442. tmp12 = tmp1 - tmp2;
  155443. dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */
  155444. dataptr[DCTSIZE*4] = tmp10 - tmp11;
  155445. z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */
  155446. dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */
  155447. dataptr[DCTSIZE*6] = tmp13 - z1;
  155448. tmp10 = tmp4 + tmp5; /* phase 2 */
  155449. tmp11 = tmp5 + tmp6;
  155450. tmp12 = tmp6 + tmp7;
  155451. z5 = (tmp10 - tmp12) * ((FAST_FLOAT) 0.382683433); /* c6 */
  155452. z2 = ((FAST_FLOAT) 0.541196100) * tmp10 + z5; /* c2-c6 */
  155453. z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */
  155454. z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */
  155455. z11 = tmp7 + z3; /* phase 5 */
  155456. z13 = tmp7 - z3;
  155457. dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */
  155458. dataptr[DCTSIZE*3] = z13 - z2;
  155459. dataptr[DCTSIZE*1] = z11 + z4;
  155460. dataptr[DCTSIZE*7] = z11 - z4;
  155461. dataptr++; /* advance pointer to next column */
  155462. }
  155463. }
  155464. #endif /* DCT_FLOAT_SUPPORTED */
  155465. /*** End of inlined file: jfdctflt.c ***/
  155466. /*** Start of inlined file: jfdctint.c ***/
  155467. #define JPEG_INTERNALS
  155468. #ifdef DCT_ISLOW_SUPPORTED
  155469. #if DCTSIZE != 8
  155470. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155471. #endif
  155472. #if BITS_IN_JSAMPLE == 8
  155473. #define CONST_BITS 13
  155474. #define PASS1_BITS 2
  155475. #else
  155476. #define CONST_BITS 13
  155477. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  155478. #endif
  155479. #if CONST_BITS == 13
  155480. #define FIX_0_298631336 ((INT32) 2446) /* FIX(0.298631336) */
  155481. #define FIX_0_390180644 ((INT32) 3196) /* FIX(0.390180644) */
  155482. #define FIX_0_541196100 ((INT32) 4433) /* FIX(0.541196100) */
  155483. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  155484. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  155485. #define FIX_1_175875602 ((INT32) 9633) /* FIX(1.175875602) */
  155486. #define FIX_1_501321110 ((INT32) 12299) /* FIX(1.501321110) */
  155487. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  155488. #define FIX_1_961570560 ((INT32) 16069) /* FIX(1.961570560) */
  155489. #define FIX_2_053119869 ((INT32) 16819) /* FIX(2.053119869) */
  155490. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  155491. #define FIX_3_072711026 ((INT32) 25172) /* FIX(3.072711026) */
  155492. #else
  155493. #define FIX_0_298631336 FIX(0.298631336)
  155494. #define FIX_0_390180644 FIX(0.390180644)
  155495. #define FIX_0_541196100 FIX(0.541196100)
  155496. #define FIX_0_765366865 FIX(0.765366865)
  155497. #define FIX_0_899976223 FIX(0.899976223)
  155498. #define FIX_1_175875602 FIX(1.175875602)
  155499. #define FIX_1_501321110 FIX(1.501321110)
  155500. #define FIX_1_847759065 FIX(1.847759065)
  155501. #define FIX_1_961570560 FIX(1.961570560)
  155502. #define FIX_2_053119869 FIX(2.053119869)
  155503. #define FIX_2_562915447 FIX(2.562915447)
  155504. #define FIX_3_072711026 FIX(3.072711026)
  155505. #endif
  155506. #if BITS_IN_JSAMPLE == 8
  155507. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  155508. #else
  155509. #define MULTIPLY(var,const) ((var) * (const))
  155510. #endif
  155511. GLOBAL(void)
  155512. jpeg_fdct_islow (DCTELEM * data)
  155513. {
  155514. INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155515. INT32 tmp10, tmp11, tmp12, tmp13;
  155516. INT32 z1, z2, z3, z4, z5;
  155517. DCTELEM *dataptr;
  155518. int ctr;
  155519. SHIFT_TEMPS
  155520. dataptr = data;
  155521. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155522. tmp0 = dataptr[0] + dataptr[7];
  155523. tmp7 = dataptr[0] - dataptr[7];
  155524. tmp1 = dataptr[1] + dataptr[6];
  155525. tmp6 = dataptr[1] - dataptr[6];
  155526. tmp2 = dataptr[2] + dataptr[5];
  155527. tmp5 = dataptr[2] - dataptr[5];
  155528. tmp3 = dataptr[3] + dataptr[4];
  155529. tmp4 = dataptr[3] - dataptr[4];
  155530. tmp10 = tmp0 + tmp3;
  155531. tmp13 = tmp0 - tmp3;
  155532. tmp11 = tmp1 + tmp2;
  155533. tmp12 = tmp1 - tmp2;
  155534. dataptr[0] = (DCTELEM) ((tmp10 + tmp11) << PASS1_BITS);
  155535. dataptr[4] = (DCTELEM) ((tmp10 - tmp11) << PASS1_BITS);
  155536. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
  155537. dataptr[2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
  155538. CONST_BITS-PASS1_BITS);
  155539. dataptr[6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
  155540. CONST_BITS-PASS1_BITS);
  155541. z1 = tmp4 + tmp7;
  155542. z2 = tmp5 + tmp6;
  155543. z3 = tmp4 + tmp6;
  155544. z4 = tmp5 + tmp7;
  155545. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  155546. tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  155547. tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  155548. tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  155549. tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  155550. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  155551. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  155552. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  155553. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  155554. z3 += z5;
  155555. z4 += z5;
  155556. dataptr[7] = (DCTELEM) DESCALE(tmp4 + z1 + z3, CONST_BITS-PASS1_BITS);
  155557. dataptr[5] = (DCTELEM) DESCALE(tmp5 + z2 + z4, CONST_BITS-PASS1_BITS);
  155558. dataptr[3] = (DCTELEM) DESCALE(tmp6 + z2 + z3, CONST_BITS-PASS1_BITS);
  155559. dataptr[1] = (DCTELEM) DESCALE(tmp7 + z1 + z4, CONST_BITS-PASS1_BITS);
  155560. dataptr += DCTSIZE; /* advance pointer to next row */
  155561. }
  155562. dataptr = data;
  155563. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155564. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  155565. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  155566. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  155567. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  155568. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  155569. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  155570. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  155571. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  155572. tmp10 = tmp0 + tmp3;
  155573. tmp13 = tmp0 - tmp3;
  155574. tmp11 = tmp1 + tmp2;
  155575. tmp12 = tmp1 - tmp2;
  155576. dataptr[DCTSIZE*0] = (DCTELEM) DESCALE(tmp10 + tmp11, PASS1_BITS);
  155577. dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(tmp10 - tmp11, PASS1_BITS);
  155578. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
  155579. dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
  155580. CONST_BITS+PASS1_BITS);
  155581. dataptr[DCTSIZE*6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
  155582. CONST_BITS+PASS1_BITS);
  155583. z1 = tmp4 + tmp7;
  155584. z2 = tmp5 + tmp6;
  155585. z3 = tmp4 + tmp6;
  155586. z4 = tmp5 + tmp7;
  155587. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  155588. tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  155589. tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  155590. tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  155591. tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  155592. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  155593. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  155594. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  155595. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  155596. z3 += z5;
  155597. z4 += z5;
  155598. dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp4 + z1 + z3,
  155599. CONST_BITS+PASS1_BITS);
  155600. dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp5 + z2 + z4,
  155601. CONST_BITS+PASS1_BITS);
  155602. dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp6 + z2 + z3,
  155603. CONST_BITS+PASS1_BITS);
  155604. dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp7 + z1 + z4,
  155605. CONST_BITS+PASS1_BITS);
  155606. dataptr++; /* advance pointer to next column */
  155607. }
  155608. }
  155609. #endif /* DCT_ISLOW_SUPPORTED */
  155610. /*** End of inlined file: jfdctint.c ***/
  155611. #undef CONST_BITS
  155612. #undef MULTIPLY
  155613. #undef FIX_0_541196100
  155614. /*** Start of inlined file: jfdctfst.c ***/
  155615. #define JPEG_INTERNALS
  155616. #ifdef DCT_IFAST_SUPPORTED
  155617. #if DCTSIZE != 8
  155618. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155619. #endif
  155620. #define CONST_BITS 8
  155621. #if CONST_BITS == 8
  155622. #define FIX_0_382683433 ((INT32) 98) /* FIX(0.382683433) */
  155623. #define FIX_0_541196100 ((INT32) 139) /* FIX(0.541196100) */
  155624. #define FIX_0_707106781 ((INT32) 181) /* FIX(0.707106781) */
  155625. #define FIX_1_306562965 ((INT32) 334) /* FIX(1.306562965) */
  155626. #else
  155627. #define FIX_0_382683433 FIX(0.382683433)
  155628. #define FIX_0_541196100 FIX(0.541196100)
  155629. #define FIX_0_707106781 FIX(0.707106781)
  155630. #define FIX_1_306562965 FIX(1.306562965)
  155631. #endif
  155632. #ifndef USE_ACCURATE_ROUNDING
  155633. #undef DESCALE
  155634. #define DESCALE(x,n) RIGHT_SHIFT(x, n)
  155635. #endif
  155636. #define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS))
  155637. GLOBAL(void)
  155638. jpeg_fdct_ifast (DCTELEM * data)
  155639. {
  155640. DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155641. DCTELEM tmp10, tmp11, tmp12, tmp13;
  155642. DCTELEM z1, z2, z3, z4, z5, z11, z13;
  155643. DCTELEM *dataptr;
  155644. int ctr;
  155645. SHIFT_TEMPS
  155646. dataptr = data;
  155647. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155648. tmp0 = dataptr[0] + dataptr[7];
  155649. tmp7 = dataptr[0] - dataptr[7];
  155650. tmp1 = dataptr[1] + dataptr[6];
  155651. tmp6 = dataptr[1] - dataptr[6];
  155652. tmp2 = dataptr[2] + dataptr[5];
  155653. tmp5 = dataptr[2] - dataptr[5];
  155654. tmp3 = dataptr[3] + dataptr[4];
  155655. tmp4 = dataptr[3] - dataptr[4];
  155656. tmp10 = tmp0 + tmp3; /* phase 2 */
  155657. tmp13 = tmp0 - tmp3;
  155658. tmp11 = tmp1 + tmp2;
  155659. tmp12 = tmp1 - tmp2;
  155660. dataptr[0] = tmp10 + tmp11; /* phase 3 */
  155661. dataptr[4] = tmp10 - tmp11;
  155662. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */
  155663. dataptr[2] = tmp13 + z1; /* phase 5 */
  155664. dataptr[6] = tmp13 - z1;
  155665. tmp10 = tmp4 + tmp5; /* phase 2 */
  155666. tmp11 = tmp5 + tmp6;
  155667. tmp12 = tmp6 + tmp7;
  155668. z5 = MULTIPLY(tmp10 - tmp12, FIX_0_382683433); /* c6 */
  155669. z2 = MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */
  155670. z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */
  155671. z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */
  155672. z11 = tmp7 + z3; /* phase 5 */
  155673. z13 = tmp7 - z3;
  155674. dataptr[5] = z13 + z2; /* phase 6 */
  155675. dataptr[3] = z13 - z2;
  155676. dataptr[1] = z11 + z4;
  155677. dataptr[7] = z11 - z4;
  155678. dataptr += DCTSIZE; /* advance pointer to next row */
  155679. }
  155680. dataptr = data;
  155681. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155682. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  155683. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  155684. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  155685. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  155686. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  155687. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  155688. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  155689. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  155690. tmp10 = tmp0 + tmp3; /* phase 2 */
  155691. tmp13 = tmp0 - tmp3;
  155692. tmp11 = tmp1 + tmp2;
  155693. tmp12 = tmp1 - tmp2;
  155694. dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */
  155695. dataptr[DCTSIZE*4] = tmp10 - tmp11;
  155696. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */
  155697. dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */
  155698. dataptr[DCTSIZE*6] = tmp13 - z1;
  155699. tmp10 = tmp4 + tmp5; /* phase 2 */
  155700. tmp11 = tmp5 + tmp6;
  155701. tmp12 = tmp6 + tmp7;
  155702. z5 = MULTIPLY(tmp10 - tmp12, FIX_0_382683433); /* c6 */
  155703. z2 = MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */
  155704. z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */
  155705. z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */
  155706. z11 = tmp7 + z3; /* phase 5 */
  155707. z13 = tmp7 - z3;
  155708. dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */
  155709. dataptr[DCTSIZE*3] = z13 - z2;
  155710. dataptr[DCTSIZE*1] = z11 + z4;
  155711. dataptr[DCTSIZE*7] = z11 - z4;
  155712. dataptr++; /* advance pointer to next column */
  155713. }
  155714. }
  155715. #endif /* DCT_IFAST_SUPPORTED */
  155716. /*** End of inlined file: jfdctfst.c ***/
  155717. #undef FIX_0_541196100
  155718. /*** Start of inlined file: jidctflt.c ***/
  155719. #define JPEG_INTERNALS
  155720. #ifdef DCT_FLOAT_SUPPORTED
  155721. #if DCTSIZE != 8
  155722. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155723. #endif
  155724. #define DEQUANTIZE(coef,quantval) (((FAST_FLOAT) (coef)) * (quantval))
  155725. GLOBAL(void)
  155726. jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155727. JCOEFPTR coef_block,
  155728. JSAMPARRAY output_buf, JDIMENSION output_col)
  155729. {
  155730. FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155731. FAST_FLOAT tmp10, tmp11, tmp12, tmp13;
  155732. FAST_FLOAT z5, z10, z11, z12, z13;
  155733. JCOEFPTR inptr;
  155734. FLOAT_MULT_TYPE * quantptr;
  155735. FAST_FLOAT * wsptr;
  155736. JSAMPROW outptr;
  155737. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155738. int ctr;
  155739. FAST_FLOAT workspace[DCTSIZE2]; /* buffers data between passes */
  155740. SHIFT_TEMPS
  155741. inptr = coef_block;
  155742. quantptr = (FLOAT_MULT_TYPE *) compptr->dct_table;
  155743. wsptr = workspace;
  155744. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  155745. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  155746. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  155747. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  155748. inptr[DCTSIZE*7] == 0) {
  155749. FAST_FLOAT dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155750. wsptr[DCTSIZE*0] = dcval;
  155751. wsptr[DCTSIZE*1] = dcval;
  155752. wsptr[DCTSIZE*2] = dcval;
  155753. wsptr[DCTSIZE*3] = dcval;
  155754. wsptr[DCTSIZE*4] = dcval;
  155755. wsptr[DCTSIZE*5] = dcval;
  155756. wsptr[DCTSIZE*6] = dcval;
  155757. wsptr[DCTSIZE*7] = dcval;
  155758. inptr++; /* advance pointers to next column */
  155759. quantptr++;
  155760. wsptr++;
  155761. continue;
  155762. }
  155763. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155764. tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  155765. tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  155766. tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  155767. tmp10 = tmp0 + tmp2; /* phase 3 */
  155768. tmp11 = tmp0 - tmp2;
  155769. tmp13 = tmp1 + tmp3; /* phases 5-3 */
  155770. tmp12 = (tmp1 - tmp3) * ((FAST_FLOAT) 1.414213562) - tmp13; /* 2*c4 */
  155771. tmp0 = tmp10 + tmp13; /* phase 2 */
  155772. tmp3 = tmp10 - tmp13;
  155773. tmp1 = tmp11 + tmp12;
  155774. tmp2 = tmp11 - tmp12;
  155775. tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155776. tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155777. tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155778. tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155779. z13 = tmp6 + tmp5; /* phase 6 */
  155780. z10 = tmp6 - tmp5;
  155781. z11 = tmp4 + tmp7;
  155782. z12 = tmp4 - tmp7;
  155783. tmp7 = z11 + z13; /* phase 5 */
  155784. tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562); /* 2*c4 */
  155785. z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */
  155786. tmp10 = ((FAST_FLOAT) 1.082392200) * z12 - z5; /* 2*(c2-c6) */
  155787. tmp12 = ((FAST_FLOAT) -2.613125930) * z10 + z5; /* -2*(c2+c6) */
  155788. tmp6 = tmp12 - tmp7; /* phase 2 */
  155789. tmp5 = tmp11 - tmp6;
  155790. tmp4 = tmp10 + tmp5;
  155791. wsptr[DCTSIZE*0] = tmp0 + tmp7;
  155792. wsptr[DCTSIZE*7] = tmp0 - tmp7;
  155793. wsptr[DCTSIZE*1] = tmp1 + tmp6;
  155794. wsptr[DCTSIZE*6] = tmp1 - tmp6;
  155795. wsptr[DCTSIZE*2] = tmp2 + tmp5;
  155796. wsptr[DCTSIZE*5] = tmp2 - tmp5;
  155797. wsptr[DCTSIZE*4] = tmp3 + tmp4;
  155798. wsptr[DCTSIZE*3] = tmp3 - tmp4;
  155799. inptr++; /* advance pointers to next column */
  155800. quantptr++;
  155801. wsptr++;
  155802. }
  155803. wsptr = workspace;
  155804. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  155805. outptr = output_buf[ctr] + output_col;
  155806. tmp10 = wsptr[0] + wsptr[4];
  155807. tmp11 = wsptr[0] - wsptr[4];
  155808. tmp13 = wsptr[2] + wsptr[6];
  155809. tmp12 = (wsptr[2] - wsptr[6]) * ((FAST_FLOAT) 1.414213562) - tmp13;
  155810. tmp0 = tmp10 + tmp13;
  155811. tmp3 = tmp10 - tmp13;
  155812. tmp1 = tmp11 + tmp12;
  155813. tmp2 = tmp11 - tmp12;
  155814. z13 = wsptr[5] + wsptr[3];
  155815. z10 = wsptr[5] - wsptr[3];
  155816. z11 = wsptr[1] + wsptr[7];
  155817. z12 = wsptr[1] - wsptr[7];
  155818. tmp7 = z11 + z13;
  155819. tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562);
  155820. z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */
  155821. tmp10 = ((FAST_FLOAT) 1.082392200) * z12 - z5; /* 2*(c2-c6) */
  155822. tmp12 = ((FAST_FLOAT) -2.613125930) * z10 + z5; /* -2*(c2+c6) */
  155823. tmp6 = tmp12 - tmp7;
  155824. tmp5 = tmp11 - tmp6;
  155825. tmp4 = tmp10 + tmp5;
  155826. outptr[0] = range_limit[(int) DESCALE((INT32) (tmp0 + tmp7), 3)
  155827. & RANGE_MASK];
  155828. outptr[7] = range_limit[(int) DESCALE((INT32) (tmp0 - tmp7), 3)
  155829. & RANGE_MASK];
  155830. outptr[1] = range_limit[(int) DESCALE((INT32) (tmp1 + tmp6), 3)
  155831. & RANGE_MASK];
  155832. outptr[6] = range_limit[(int) DESCALE((INT32) (tmp1 - tmp6), 3)
  155833. & RANGE_MASK];
  155834. outptr[2] = range_limit[(int) DESCALE((INT32) (tmp2 + tmp5), 3)
  155835. & RANGE_MASK];
  155836. outptr[5] = range_limit[(int) DESCALE((INT32) (tmp2 - tmp5), 3)
  155837. & RANGE_MASK];
  155838. outptr[4] = range_limit[(int) DESCALE((INT32) (tmp3 + tmp4), 3)
  155839. & RANGE_MASK];
  155840. outptr[3] = range_limit[(int) DESCALE((INT32) (tmp3 - tmp4), 3)
  155841. & RANGE_MASK];
  155842. wsptr += DCTSIZE; /* advance pointer to next row */
  155843. }
  155844. }
  155845. #endif /* DCT_FLOAT_SUPPORTED */
  155846. /*** End of inlined file: jidctflt.c ***/
  155847. #undef CONST_BITS
  155848. #undef FIX_1_847759065
  155849. #undef MULTIPLY
  155850. #undef DEQUANTIZE
  155851. #undef DESCALE
  155852. /*** Start of inlined file: jidctfst.c ***/
  155853. #define JPEG_INTERNALS
  155854. #ifdef DCT_IFAST_SUPPORTED
  155855. #if DCTSIZE != 8
  155856. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155857. #endif
  155858. #if BITS_IN_JSAMPLE == 8
  155859. #define CONST_BITS 8
  155860. #define PASS1_BITS 2
  155861. #else
  155862. #define CONST_BITS 8
  155863. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  155864. #endif
  155865. #if CONST_BITS == 8
  155866. #define FIX_1_082392200 ((INT32) 277) /* FIX(1.082392200) */
  155867. #define FIX_1_414213562 ((INT32) 362) /* FIX(1.414213562) */
  155868. #define FIX_1_847759065 ((INT32) 473) /* FIX(1.847759065) */
  155869. #define FIX_2_613125930 ((INT32) 669) /* FIX(2.613125930) */
  155870. #else
  155871. #define FIX_1_082392200 FIX(1.082392200)
  155872. #define FIX_1_414213562 FIX(1.414213562)
  155873. #define FIX_1_847759065 FIX(1.847759065)
  155874. #define FIX_2_613125930 FIX(2.613125930)
  155875. #endif
  155876. #ifndef USE_ACCURATE_ROUNDING
  155877. #undef DESCALE
  155878. #define DESCALE(x,n) RIGHT_SHIFT(x, n)
  155879. #endif
  155880. #define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS))
  155881. #if BITS_IN_JSAMPLE == 8
  155882. #define DEQUANTIZE(coef,quantval) (((IFAST_MULT_TYPE) (coef)) * (quantval))
  155883. #else
  155884. #define DEQUANTIZE(coef,quantval) \
  155885. DESCALE((coef)*(quantval), IFAST_SCALE_BITS-PASS1_BITS)
  155886. #endif
  155887. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  155888. #define ISHIFT_TEMPS DCTELEM ishift_temp;
  155889. #if BITS_IN_JSAMPLE == 8
  155890. #define DCTELEMBITS 16 /* DCTELEM may be 16 or 32 bits */
  155891. #else
  155892. #define DCTELEMBITS 32 /* DCTELEM must be 32 bits */
  155893. #endif
  155894. #define IRIGHT_SHIFT(x,shft) \
  155895. ((ishift_temp = (x)) < 0 ? \
  155896. (ishift_temp >> (shft)) | ((~((DCTELEM) 0)) << (DCTELEMBITS-(shft))) : \
  155897. (ishift_temp >> (shft)))
  155898. #else
  155899. #define ISHIFT_TEMPS
  155900. #define IRIGHT_SHIFT(x,shft) ((x) >> (shft))
  155901. #endif
  155902. #ifdef USE_ACCURATE_ROUNDING
  155903. #define IDESCALE(x,n) ((int) IRIGHT_SHIFT((x) + (1 << ((n)-1)), n))
  155904. #else
  155905. #define IDESCALE(x,n) ((int) IRIGHT_SHIFT(x, n))
  155906. #endif
  155907. GLOBAL(void)
  155908. jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155909. JCOEFPTR coef_block,
  155910. JSAMPARRAY output_buf, JDIMENSION output_col)
  155911. {
  155912. DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155913. DCTELEM tmp10, tmp11, tmp12, tmp13;
  155914. DCTELEM z5, z10, z11, z12, z13;
  155915. JCOEFPTR inptr;
  155916. IFAST_MULT_TYPE * quantptr;
  155917. int * wsptr;
  155918. JSAMPROW outptr;
  155919. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155920. int ctr;
  155921. int workspace[DCTSIZE2]; /* buffers data between passes */
  155922. SHIFT_TEMPS /* for DESCALE */
  155923. ISHIFT_TEMPS /* for IDESCALE */
  155924. inptr = coef_block;
  155925. quantptr = (IFAST_MULT_TYPE *) compptr->dct_table;
  155926. wsptr = workspace;
  155927. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  155928. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  155929. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  155930. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  155931. inptr[DCTSIZE*7] == 0) {
  155932. int dcval = (int) DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155933. wsptr[DCTSIZE*0] = dcval;
  155934. wsptr[DCTSIZE*1] = dcval;
  155935. wsptr[DCTSIZE*2] = dcval;
  155936. wsptr[DCTSIZE*3] = dcval;
  155937. wsptr[DCTSIZE*4] = dcval;
  155938. wsptr[DCTSIZE*5] = dcval;
  155939. wsptr[DCTSIZE*6] = dcval;
  155940. wsptr[DCTSIZE*7] = dcval;
  155941. inptr++; /* advance pointers to next column */
  155942. quantptr++;
  155943. wsptr++;
  155944. continue;
  155945. }
  155946. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155947. tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  155948. tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  155949. tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  155950. tmp10 = tmp0 + tmp2; /* phase 3 */
  155951. tmp11 = tmp0 - tmp2;
  155952. tmp13 = tmp1 + tmp3; /* phases 5-3 */
  155953. tmp12 = MULTIPLY(tmp1 - tmp3, FIX_1_414213562) - tmp13; /* 2*c4 */
  155954. tmp0 = tmp10 + tmp13; /* phase 2 */
  155955. tmp3 = tmp10 - tmp13;
  155956. tmp1 = tmp11 + tmp12;
  155957. tmp2 = tmp11 - tmp12;
  155958. tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155959. tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155960. tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155961. tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155962. z13 = tmp6 + tmp5; /* phase 6 */
  155963. z10 = tmp6 - tmp5;
  155964. z11 = tmp4 + tmp7;
  155965. z12 = tmp4 - tmp7;
  155966. tmp7 = z11 + z13; /* phase 5 */
  155967. tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */
  155968. z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */
  155969. tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */
  155970. tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */
  155971. tmp6 = tmp12 - tmp7; /* phase 2 */
  155972. tmp5 = tmp11 - tmp6;
  155973. tmp4 = tmp10 + tmp5;
  155974. wsptr[DCTSIZE*0] = (int) (tmp0 + tmp7);
  155975. wsptr[DCTSIZE*7] = (int) (tmp0 - tmp7);
  155976. wsptr[DCTSIZE*1] = (int) (tmp1 + tmp6);
  155977. wsptr[DCTSIZE*6] = (int) (tmp1 - tmp6);
  155978. wsptr[DCTSIZE*2] = (int) (tmp2 + tmp5);
  155979. wsptr[DCTSIZE*5] = (int) (tmp2 - tmp5);
  155980. wsptr[DCTSIZE*4] = (int) (tmp3 + tmp4);
  155981. wsptr[DCTSIZE*3] = (int) (tmp3 - tmp4);
  155982. inptr++; /* advance pointers to next column */
  155983. quantptr++;
  155984. wsptr++;
  155985. }
  155986. wsptr = workspace;
  155987. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  155988. outptr = output_buf[ctr] + output_col;
  155989. #ifndef NO_ZERO_ROW_TEST
  155990. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 &&
  155991. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  155992. JSAMPLE dcval = range_limit[IDESCALE(wsptr[0], PASS1_BITS+3)
  155993. & RANGE_MASK];
  155994. outptr[0] = dcval;
  155995. outptr[1] = dcval;
  155996. outptr[2] = dcval;
  155997. outptr[3] = dcval;
  155998. outptr[4] = dcval;
  155999. outptr[5] = dcval;
  156000. outptr[6] = dcval;
  156001. outptr[7] = dcval;
  156002. wsptr += DCTSIZE; /* advance pointer to next row */
  156003. continue;
  156004. }
  156005. #endif
  156006. tmp10 = ((DCTELEM) wsptr[0] + (DCTELEM) wsptr[4]);
  156007. tmp11 = ((DCTELEM) wsptr[0] - (DCTELEM) wsptr[4]);
  156008. tmp13 = ((DCTELEM) wsptr[2] + (DCTELEM) wsptr[6]);
  156009. tmp12 = MULTIPLY((DCTELEM) wsptr[2] - (DCTELEM) wsptr[6], FIX_1_414213562)
  156010. - tmp13;
  156011. tmp0 = tmp10 + tmp13;
  156012. tmp3 = tmp10 - tmp13;
  156013. tmp1 = tmp11 + tmp12;
  156014. tmp2 = tmp11 - tmp12;
  156015. z13 = (DCTELEM) wsptr[5] + (DCTELEM) wsptr[3];
  156016. z10 = (DCTELEM) wsptr[5] - (DCTELEM) wsptr[3];
  156017. z11 = (DCTELEM) wsptr[1] + (DCTELEM) wsptr[7];
  156018. z12 = (DCTELEM) wsptr[1] - (DCTELEM) wsptr[7];
  156019. tmp7 = z11 + z13; /* phase 5 */
  156020. tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */
  156021. z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */
  156022. tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */
  156023. tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */
  156024. tmp6 = tmp12 - tmp7; /* phase 2 */
  156025. tmp5 = tmp11 - tmp6;
  156026. tmp4 = tmp10 + tmp5;
  156027. outptr[0] = range_limit[IDESCALE(tmp0 + tmp7, PASS1_BITS+3)
  156028. & RANGE_MASK];
  156029. outptr[7] = range_limit[IDESCALE(tmp0 - tmp7, PASS1_BITS+3)
  156030. & RANGE_MASK];
  156031. outptr[1] = range_limit[IDESCALE(tmp1 + tmp6, PASS1_BITS+3)
  156032. & RANGE_MASK];
  156033. outptr[6] = range_limit[IDESCALE(tmp1 - tmp6, PASS1_BITS+3)
  156034. & RANGE_MASK];
  156035. outptr[2] = range_limit[IDESCALE(tmp2 + tmp5, PASS1_BITS+3)
  156036. & RANGE_MASK];
  156037. outptr[5] = range_limit[IDESCALE(tmp2 - tmp5, PASS1_BITS+3)
  156038. & RANGE_MASK];
  156039. outptr[4] = range_limit[IDESCALE(tmp3 + tmp4, PASS1_BITS+3)
  156040. & RANGE_MASK];
  156041. outptr[3] = range_limit[IDESCALE(tmp3 - tmp4, PASS1_BITS+3)
  156042. & RANGE_MASK];
  156043. wsptr += DCTSIZE; /* advance pointer to next row */
  156044. }
  156045. }
  156046. #endif /* DCT_IFAST_SUPPORTED */
  156047. /*** End of inlined file: jidctfst.c ***/
  156048. #undef CONST_BITS
  156049. #undef FIX_1_847759065
  156050. #undef MULTIPLY
  156051. #undef DEQUANTIZE
  156052. /*** Start of inlined file: jidctint.c ***/
  156053. #define JPEG_INTERNALS
  156054. #ifdef DCT_ISLOW_SUPPORTED
  156055. #if DCTSIZE != 8
  156056. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  156057. #endif
  156058. #if BITS_IN_JSAMPLE == 8
  156059. #define CONST_BITS 13
  156060. #define PASS1_BITS 2
  156061. #else
  156062. #define CONST_BITS 13
  156063. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  156064. #endif
  156065. #if CONST_BITS == 13
  156066. #define FIX_0_298631336 ((INT32) 2446) /* FIX(0.298631336) */
  156067. #define FIX_0_390180644 ((INT32) 3196) /* FIX(0.390180644) */
  156068. #define FIX_0_541196100 ((INT32) 4433) /* FIX(0.541196100) */
  156069. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  156070. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  156071. #define FIX_1_175875602 ((INT32) 9633) /* FIX(1.175875602) */
  156072. #define FIX_1_501321110 ((INT32) 12299) /* FIX(1.501321110) */
  156073. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  156074. #define FIX_1_961570560 ((INT32) 16069) /* FIX(1.961570560) */
  156075. #define FIX_2_053119869 ((INT32) 16819) /* FIX(2.053119869) */
  156076. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  156077. #define FIX_3_072711026 ((INT32) 25172) /* FIX(3.072711026) */
  156078. #else
  156079. #define FIX_0_298631336 FIX(0.298631336)
  156080. #define FIX_0_390180644 FIX(0.390180644)
  156081. #define FIX_0_541196100 FIX(0.541196100)
  156082. #define FIX_0_765366865 FIX(0.765366865)
  156083. #define FIX_0_899976223 FIX(0.899976223)
  156084. #define FIX_1_175875602 FIX(1.175875602)
  156085. #define FIX_1_501321110 FIX(1.501321110)
  156086. #define FIX_1_847759065 FIX(1.847759065)
  156087. #define FIX_1_961570560 FIX(1.961570560)
  156088. #define FIX_2_053119869 FIX(2.053119869)
  156089. #define FIX_2_562915447 FIX(2.562915447)
  156090. #define FIX_3_072711026 FIX(3.072711026)
  156091. #endif
  156092. #if BITS_IN_JSAMPLE == 8
  156093. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  156094. #else
  156095. #define MULTIPLY(var,const) ((var) * (const))
  156096. #endif
  156097. #define DEQUANTIZE(coef,quantval) (((ISLOW_MULT_TYPE) (coef)) * (quantval))
  156098. GLOBAL(void)
  156099. jpeg_idct_islow (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  156100. JCOEFPTR coef_block,
  156101. JSAMPARRAY output_buf, JDIMENSION output_col)
  156102. {
  156103. INT32 tmp0, tmp1, tmp2, tmp3;
  156104. INT32 tmp10, tmp11, tmp12, tmp13;
  156105. INT32 z1, z2, z3, z4, z5;
  156106. JCOEFPTR inptr;
  156107. ISLOW_MULT_TYPE * quantptr;
  156108. int * wsptr;
  156109. JSAMPROW outptr;
  156110. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  156111. int ctr;
  156112. int workspace[DCTSIZE2]; /* buffers data between passes */
  156113. SHIFT_TEMPS
  156114. inptr = coef_block;
  156115. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  156116. wsptr = workspace;
  156117. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  156118. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  156119. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  156120. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  156121. inptr[DCTSIZE*7] == 0) {
  156122. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  156123. wsptr[DCTSIZE*0] = dcval;
  156124. wsptr[DCTSIZE*1] = dcval;
  156125. wsptr[DCTSIZE*2] = dcval;
  156126. wsptr[DCTSIZE*3] = dcval;
  156127. wsptr[DCTSIZE*4] = dcval;
  156128. wsptr[DCTSIZE*5] = dcval;
  156129. wsptr[DCTSIZE*6] = dcval;
  156130. wsptr[DCTSIZE*7] = dcval;
  156131. inptr++; /* advance pointers to next column */
  156132. quantptr++;
  156133. wsptr++;
  156134. continue;
  156135. }
  156136. z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  156137. z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  156138. z1 = MULTIPLY(z2 + z3, FIX_0_541196100);
  156139. tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065);
  156140. tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865);
  156141. z2 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  156142. z3 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  156143. tmp0 = (z2 + z3) << CONST_BITS;
  156144. tmp1 = (z2 - z3) << CONST_BITS;
  156145. tmp10 = tmp0 + tmp3;
  156146. tmp13 = tmp0 - tmp3;
  156147. tmp11 = tmp1 + tmp2;
  156148. tmp12 = tmp1 - tmp2;
  156149. tmp0 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  156150. tmp1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  156151. tmp2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  156152. tmp3 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  156153. z1 = tmp0 + tmp3;
  156154. z2 = tmp1 + tmp2;
  156155. z3 = tmp0 + tmp2;
  156156. z4 = tmp1 + tmp3;
  156157. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  156158. tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  156159. tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  156160. tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  156161. tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  156162. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  156163. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  156164. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  156165. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  156166. z3 += z5;
  156167. z4 += z5;
  156168. tmp0 += z1 + z3;
  156169. tmp1 += z2 + z4;
  156170. tmp2 += z2 + z3;
  156171. tmp3 += z1 + z4;
  156172. wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp3, CONST_BITS-PASS1_BITS);
  156173. wsptr[DCTSIZE*7] = (int) DESCALE(tmp10 - tmp3, CONST_BITS-PASS1_BITS);
  156174. wsptr[DCTSIZE*1] = (int) DESCALE(tmp11 + tmp2, CONST_BITS-PASS1_BITS);
  156175. wsptr[DCTSIZE*6] = (int) DESCALE(tmp11 - tmp2, CONST_BITS-PASS1_BITS);
  156176. wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 + tmp1, CONST_BITS-PASS1_BITS);
  156177. wsptr[DCTSIZE*5] = (int) DESCALE(tmp12 - tmp1, CONST_BITS-PASS1_BITS);
  156178. wsptr[DCTSIZE*3] = (int) DESCALE(tmp13 + tmp0, CONST_BITS-PASS1_BITS);
  156179. wsptr[DCTSIZE*4] = (int) DESCALE(tmp13 - tmp0, CONST_BITS-PASS1_BITS);
  156180. inptr++; /* advance pointers to next column */
  156181. quantptr++;
  156182. wsptr++;
  156183. }
  156184. wsptr = workspace;
  156185. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  156186. outptr = output_buf[ctr] + output_col;
  156187. #ifndef NO_ZERO_ROW_TEST
  156188. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 &&
  156189. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  156190. JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
  156191. & RANGE_MASK];
  156192. outptr[0] = dcval;
  156193. outptr[1] = dcval;
  156194. outptr[2] = dcval;
  156195. outptr[3] = dcval;
  156196. outptr[4] = dcval;
  156197. outptr[5] = dcval;
  156198. outptr[6] = dcval;
  156199. outptr[7] = dcval;
  156200. wsptr += DCTSIZE; /* advance pointer to next row */
  156201. continue;
  156202. }
  156203. #endif
  156204. z2 = (INT32) wsptr[2];
  156205. z3 = (INT32) wsptr[6];
  156206. z1 = MULTIPLY(z2 + z3, FIX_0_541196100);
  156207. tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065);
  156208. tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865);
  156209. tmp0 = ((INT32) wsptr[0] + (INT32) wsptr[4]) << CONST_BITS;
  156210. tmp1 = ((INT32) wsptr[0] - (INT32) wsptr[4]) << CONST_BITS;
  156211. tmp10 = tmp0 + tmp3;
  156212. tmp13 = tmp0 - tmp3;
  156213. tmp11 = tmp1 + tmp2;
  156214. tmp12 = tmp1 - tmp2;
  156215. tmp0 = (INT32) wsptr[7];
  156216. tmp1 = (INT32) wsptr[5];
  156217. tmp2 = (INT32) wsptr[3];
  156218. tmp3 = (INT32) wsptr[1];
  156219. z1 = tmp0 + tmp3;
  156220. z2 = tmp1 + tmp2;
  156221. z3 = tmp0 + tmp2;
  156222. z4 = tmp1 + tmp3;
  156223. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  156224. tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  156225. tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  156226. tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  156227. tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  156228. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  156229. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  156230. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  156231. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  156232. z3 += z5;
  156233. z4 += z5;
  156234. tmp0 += z1 + z3;
  156235. tmp1 += z2 + z4;
  156236. tmp2 += z2 + z3;
  156237. tmp3 += z1 + z4;
  156238. outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp3,
  156239. CONST_BITS+PASS1_BITS+3)
  156240. & RANGE_MASK];
  156241. outptr[7] = range_limit[(int) DESCALE(tmp10 - tmp3,
  156242. CONST_BITS+PASS1_BITS+3)
  156243. & RANGE_MASK];
  156244. outptr[1] = range_limit[(int) DESCALE(tmp11 + tmp2,
  156245. CONST_BITS+PASS1_BITS+3)
  156246. & RANGE_MASK];
  156247. outptr[6] = range_limit[(int) DESCALE(tmp11 - tmp2,
  156248. CONST_BITS+PASS1_BITS+3)
  156249. & RANGE_MASK];
  156250. outptr[2] = range_limit[(int) DESCALE(tmp12 + tmp1,
  156251. CONST_BITS+PASS1_BITS+3)
  156252. & RANGE_MASK];
  156253. outptr[5] = range_limit[(int) DESCALE(tmp12 - tmp1,
  156254. CONST_BITS+PASS1_BITS+3)
  156255. & RANGE_MASK];
  156256. outptr[3] = range_limit[(int) DESCALE(tmp13 + tmp0,
  156257. CONST_BITS+PASS1_BITS+3)
  156258. & RANGE_MASK];
  156259. outptr[4] = range_limit[(int) DESCALE(tmp13 - tmp0,
  156260. CONST_BITS+PASS1_BITS+3)
  156261. & RANGE_MASK];
  156262. wsptr += DCTSIZE; /* advance pointer to next row */
  156263. }
  156264. }
  156265. #endif /* DCT_ISLOW_SUPPORTED */
  156266. /*** End of inlined file: jidctint.c ***/
  156267. /*** Start of inlined file: jidctred.c ***/
  156268. #define JPEG_INTERNALS
  156269. #ifdef IDCT_SCALING_SUPPORTED
  156270. #if DCTSIZE != 8
  156271. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  156272. #endif
  156273. #if BITS_IN_JSAMPLE == 8
  156274. #define CONST_BITS 13
  156275. #define PASS1_BITS 2
  156276. #else
  156277. #define CONST_BITS 13
  156278. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  156279. #endif
  156280. #if CONST_BITS == 13
  156281. #define FIX_0_211164243 ((INT32) 1730) /* FIX(0.211164243) */
  156282. #define FIX_0_509795579 ((INT32) 4176) /* FIX(0.509795579) */
  156283. #define FIX_0_601344887 ((INT32) 4926) /* FIX(0.601344887) */
  156284. #define FIX_0_720959822 ((INT32) 5906) /* FIX(0.720959822) */
  156285. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  156286. #define FIX_0_850430095 ((INT32) 6967) /* FIX(0.850430095) */
  156287. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  156288. #define FIX_1_061594337 ((INT32) 8697) /* FIX(1.061594337) */
  156289. #define FIX_1_272758580 ((INT32) 10426) /* FIX(1.272758580) */
  156290. #define FIX_1_451774981 ((INT32) 11893) /* FIX(1.451774981) */
  156291. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  156292. #define FIX_2_172734803 ((INT32) 17799) /* FIX(2.172734803) */
  156293. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  156294. #define FIX_3_624509785 ((INT32) 29692) /* FIX(3.624509785) */
  156295. #else
  156296. #define FIX_0_211164243 FIX(0.211164243)
  156297. #define FIX_0_509795579 FIX(0.509795579)
  156298. #define FIX_0_601344887 FIX(0.601344887)
  156299. #define FIX_0_720959822 FIX(0.720959822)
  156300. #define FIX_0_765366865 FIX(0.765366865)
  156301. #define FIX_0_850430095 FIX(0.850430095)
  156302. #define FIX_0_899976223 FIX(0.899976223)
  156303. #define FIX_1_061594337 FIX(1.061594337)
  156304. #define FIX_1_272758580 FIX(1.272758580)
  156305. #define FIX_1_451774981 FIX(1.451774981)
  156306. #define FIX_1_847759065 FIX(1.847759065)
  156307. #define FIX_2_172734803 FIX(2.172734803)
  156308. #define FIX_2_562915447 FIX(2.562915447)
  156309. #define FIX_3_624509785 FIX(3.624509785)
  156310. #endif
  156311. #if BITS_IN_JSAMPLE == 8
  156312. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  156313. #else
  156314. #define MULTIPLY(var,const) ((var) * (const))
  156315. #endif
  156316. #define DEQUANTIZE(coef,quantval) (((ISLOW_MULT_TYPE) (coef)) * (quantval))
  156317. GLOBAL(void)
  156318. jpeg_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  156319. JCOEFPTR coef_block,
  156320. JSAMPARRAY output_buf, JDIMENSION output_col)
  156321. {
  156322. INT32 tmp0, tmp2, tmp10, tmp12;
  156323. INT32 z1, z2, z3, z4;
  156324. JCOEFPTR inptr;
  156325. ISLOW_MULT_TYPE * quantptr;
  156326. int * wsptr;
  156327. JSAMPROW outptr;
  156328. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  156329. int ctr;
  156330. int workspace[DCTSIZE*4]; /* buffers data between passes */
  156331. SHIFT_TEMPS
  156332. inptr = coef_block;
  156333. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  156334. wsptr = workspace;
  156335. for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) {
  156336. if (ctr == DCTSIZE-4)
  156337. continue;
  156338. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  156339. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*5] == 0 &&
  156340. inptr[DCTSIZE*6] == 0 && inptr[DCTSIZE*7] == 0) {
  156341. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  156342. wsptr[DCTSIZE*0] = dcval;
  156343. wsptr[DCTSIZE*1] = dcval;
  156344. wsptr[DCTSIZE*2] = dcval;
  156345. wsptr[DCTSIZE*3] = dcval;
  156346. continue;
  156347. }
  156348. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  156349. tmp0 <<= (CONST_BITS+1);
  156350. z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  156351. z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  156352. tmp2 = MULTIPLY(z2, FIX_1_847759065) + MULTIPLY(z3, - FIX_0_765366865);
  156353. tmp10 = tmp0 + tmp2;
  156354. tmp12 = tmp0 - tmp2;
  156355. z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  156356. z2 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  156357. z3 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  156358. z4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  156359. tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */
  156360. + MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */
  156361. + MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */
  156362. + MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */
  156363. tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */
  156364. + MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */
  156365. + MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */
  156366. + MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */
  156367. wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp2, CONST_BITS-PASS1_BITS+1);
  156368. wsptr[DCTSIZE*3] = (int) DESCALE(tmp10 - tmp2, CONST_BITS-PASS1_BITS+1);
  156369. wsptr[DCTSIZE*1] = (int) DESCALE(tmp12 + tmp0, CONST_BITS-PASS1_BITS+1);
  156370. wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 - tmp0, CONST_BITS-PASS1_BITS+1);
  156371. }
  156372. wsptr = workspace;
  156373. for (ctr = 0; ctr < 4; ctr++) {
  156374. outptr = output_buf[ctr] + output_col;
  156375. #ifndef NO_ZERO_ROW_TEST
  156376. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 &&
  156377. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  156378. JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
  156379. & RANGE_MASK];
  156380. outptr[0] = dcval;
  156381. outptr[1] = dcval;
  156382. outptr[2] = dcval;
  156383. outptr[3] = dcval;
  156384. wsptr += DCTSIZE; /* advance pointer to next row */
  156385. continue;
  156386. }
  156387. #endif
  156388. tmp0 = ((INT32) wsptr[0]) << (CONST_BITS+1);
  156389. tmp2 = MULTIPLY((INT32) wsptr[2], FIX_1_847759065)
  156390. + MULTIPLY((INT32) wsptr[6], - FIX_0_765366865);
  156391. tmp10 = tmp0 + tmp2;
  156392. tmp12 = tmp0 - tmp2;
  156393. z1 = (INT32) wsptr[7];
  156394. z2 = (INT32) wsptr[5];
  156395. z3 = (INT32) wsptr[3];
  156396. z4 = (INT32) wsptr[1];
  156397. tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */
  156398. + MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */
  156399. + MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */
  156400. + MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */
  156401. tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */
  156402. + MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */
  156403. + MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */
  156404. + MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */
  156405. outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp2,
  156406. CONST_BITS+PASS1_BITS+3+1)
  156407. & RANGE_MASK];
  156408. outptr[3] = range_limit[(int) DESCALE(tmp10 - tmp2,
  156409. CONST_BITS+PASS1_BITS+3+1)
  156410. & RANGE_MASK];
  156411. outptr[1] = range_limit[(int) DESCALE(tmp12 + tmp0,
  156412. CONST_BITS+PASS1_BITS+3+1)
  156413. & RANGE_MASK];
  156414. outptr[2] = range_limit[(int) DESCALE(tmp12 - tmp0,
  156415. CONST_BITS+PASS1_BITS+3+1)
  156416. & RANGE_MASK];
  156417. wsptr += DCTSIZE; /* advance pointer to next row */
  156418. }
  156419. }
  156420. GLOBAL(void)
  156421. jpeg_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  156422. JCOEFPTR coef_block,
  156423. JSAMPARRAY output_buf, JDIMENSION output_col)
  156424. {
  156425. INT32 tmp0, tmp10, z1;
  156426. JCOEFPTR inptr;
  156427. ISLOW_MULT_TYPE * quantptr;
  156428. int * wsptr;
  156429. JSAMPROW outptr;
  156430. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  156431. int ctr;
  156432. int workspace[DCTSIZE*2]; /* buffers data between passes */
  156433. SHIFT_TEMPS
  156434. inptr = coef_block;
  156435. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  156436. wsptr = workspace;
  156437. for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) {
  156438. if (ctr == DCTSIZE-2 || ctr == DCTSIZE-4 || ctr == DCTSIZE-6)
  156439. continue;
  156440. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*3] == 0 &&
  156441. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*7] == 0) {
  156442. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  156443. wsptr[DCTSIZE*0] = dcval;
  156444. wsptr[DCTSIZE*1] = dcval;
  156445. continue;
  156446. }
  156447. z1 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  156448. tmp10 = z1 << (CONST_BITS+2);
  156449. z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  156450. tmp0 = MULTIPLY(z1, - FIX_0_720959822); /* sqrt(2) * (c7-c5+c3-c1) */
  156451. z1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  156452. tmp0 += MULTIPLY(z1, FIX_0_850430095); /* sqrt(2) * (-c1+c3+c5+c7) */
  156453. z1 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  156454. tmp0 += MULTIPLY(z1, - FIX_1_272758580); /* sqrt(2) * (-c1+c3-c5-c7) */
  156455. z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  156456. tmp0 += MULTIPLY(z1, FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */
  156457. wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp0, CONST_BITS-PASS1_BITS+2);
  156458. wsptr[DCTSIZE*1] = (int) DESCALE(tmp10 - tmp0, CONST_BITS-PASS1_BITS+2);
  156459. }
  156460. wsptr = workspace;
  156461. for (ctr = 0; ctr < 2; ctr++) {
  156462. outptr = output_buf[ctr] + output_col;
  156463. #ifndef NO_ZERO_ROW_TEST
  156464. if (wsptr[1] == 0 && wsptr[3] == 0 && wsptr[5] == 0 && wsptr[7] == 0) {
  156465. JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
  156466. & RANGE_MASK];
  156467. outptr[0] = dcval;
  156468. outptr[1] = dcval;
  156469. wsptr += DCTSIZE; /* advance pointer to next row */
  156470. continue;
  156471. }
  156472. #endif
  156473. tmp10 = ((INT32) wsptr[0]) << (CONST_BITS+2);
  156474. tmp0 = MULTIPLY((INT32) wsptr[7], - FIX_0_720959822) /* sqrt(2) * (c7-c5+c3-c1) */
  156475. + MULTIPLY((INT32) wsptr[5], FIX_0_850430095) /* sqrt(2) * (-c1+c3+c5+c7) */
  156476. + MULTIPLY((INT32) wsptr[3], - FIX_1_272758580) /* sqrt(2) * (-c1+c3-c5-c7) */
  156477. + MULTIPLY((INT32) wsptr[1], FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */
  156478. outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp0,
  156479. CONST_BITS+PASS1_BITS+3+2)
  156480. & RANGE_MASK];
  156481. outptr[1] = range_limit[(int) DESCALE(tmp10 - tmp0,
  156482. CONST_BITS+PASS1_BITS+3+2)
  156483. & RANGE_MASK];
  156484. wsptr += DCTSIZE; /* advance pointer to next row */
  156485. }
  156486. }
  156487. GLOBAL(void)
  156488. jpeg_idct_1x1 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  156489. JCOEFPTR coef_block,
  156490. JSAMPARRAY output_buf, JDIMENSION output_col)
  156491. {
  156492. int dcval;
  156493. ISLOW_MULT_TYPE * quantptr;
  156494. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  156495. SHIFT_TEMPS
  156496. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  156497. dcval = DEQUANTIZE(coef_block[0], quantptr[0]);
  156498. dcval = (int) DESCALE((INT32) dcval, 3);
  156499. output_buf[0][output_col] = range_limit[dcval & RANGE_MASK];
  156500. }
  156501. #endif /* IDCT_SCALING_SUPPORTED */
  156502. /*** End of inlined file: jidctred.c ***/
  156503. /*** Start of inlined file: jmemmgr.c ***/
  156504. #define JPEG_INTERNALS
  156505. #define AM_MEMORY_MANAGER /* we define jvirt_Xarray_control structs */
  156506. /*** Start of inlined file: jmemsys.h ***/
  156507. #ifndef __jmemsys_h__
  156508. #define __jmemsys_h__
  156509. #ifdef NEED_SHORT_EXTERNAL_NAMES
  156510. #define jpeg_get_small jGetSmall
  156511. #define jpeg_free_small jFreeSmall
  156512. #define jpeg_get_large jGetLarge
  156513. #define jpeg_free_large jFreeLarge
  156514. #define jpeg_mem_available jMemAvail
  156515. #define jpeg_open_backing_store jOpenBackStore
  156516. #define jpeg_mem_init jMemInit
  156517. #define jpeg_mem_term jMemTerm
  156518. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  156519. EXTERN(void *) jpeg_get_small JPP((j_common_ptr cinfo, size_t sizeofobject));
  156520. EXTERN(void) jpeg_free_small JPP((j_common_ptr cinfo, void * object,
  156521. size_t sizeofobject));
  156522. EXTERN(void FAR *) jpeg_get_large JPP((j_common_ptr cinfo,
  156523. size_t sizeofobject));
  156524. EXTERN(void) jpeg_free_large JPP((j_common_ptr cinfo, void FAR * object,
  156525. size_t sizeofobject));
  156526. #ifndef MAX_ALLOC_CHUNK /* may be overridden in jconfig.h */
  156527. #define MAX_ALLOC_CHUNK 1000000000L
  156528. #endif
  156529. EXTERN(long) jpeg_mem_available JPP((j_common_ptr cinfo,
  156530. long min_bytes_needed,
  156531. long max_bytes_needed,
  156532. long already_allocated));
  156533. #define TEMP_NAME_LENGTH 64 /* max length of a temporary file's name */
  156534. #ifdef USE_MSDOS_MEMMGR /* DOS-specific junk */
  156535. typedef unsigned short XMSH; /* type of extended-memory handles */
  156536. typedef unsigned short EMSH; /* type of expanded-memory handles */
  156537. typedef union {
  156538. short file_handle; /* DOS file handle if it's a temp file */
  156539. XMSH xms_handle; /* handle if it's a chunk of XMS */
  156540. EMSH ems_handle; /* handle if it's a chunk of EMS */
  156541. } handle_union;
  156542. #endif /* USE_MSDOS_MEMMGR */
  156543. #ifdef USE_MAC_MEMMGR /* Mac-specific junk */
  156544. #include <Files.h>
  156545. #endif /* USE_MAC_MEMMGR */
  156546. //typedef struct backing_store_struct * backing_store_ptr;
  156547. typedef struct backing_store_struct {
  156548. JMETHOD(void, read_backing_store, (j_common_ptr cinfo,
  156549. struct backing_store_struct *info,
  156550. void FAR * buffer_address,
  156551. long file_offset, long byte_count));
  156552. JMETHOD(void, write_backing_store, (j_common_ptr cinfo,
  156553. struct backing_store_struct *info,
  156554. void FAR * buffer_address,
  156555. long file_offset, long byte_count));
  156556. JMETHOD(void, close_backing_store, (j_common_ptr cinfo,
  156557. struct backing_store_struct *info));
  156558. #ifdef USE_MSDOS_MEMMGR
  156559. handle_union handle; /* reference to backing-store storage object */
  156560. char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
  156561. #else
  156562. #ifdef USE_MAC_MEMMGR
  156563. short temp_file; /* file reference number to temp file */
  156564. FSSpec tempSpec; /* the FSSpec for the temp file */
  156565. char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
  156566. #else
  156567. FILE * temp_file; /* stdio reference to temp file */
  156568. char temp_name[TEMP_NAME_LENGTH]; /* name of temp file */
  156569. #endif
  156570. #endif
  156571. } backing_store_info;
  156572. EXTERN(void) jpeg_open_backing_store JPP((j_common_ptr cinfo,
  156573. struct backing_store_struct *info,
  156574. long total_bytes_needed));
  156575. EXTERN(long) jpeg_mem_init JPP((j_common_ptr cinfo));
  156576. EXTERN(void) jpeg_mem_term JPP((j_common_ptr cinfo));
  156577. #endif
  156578. /*** End of inlined file: jmemsys.h ***/
  156579. /* import the system-dependent declarations */
  156580. #ifndef NO_GETENV
  156581. #ifndef HAVE_STDLIB_H /* <stdlib.h> should declare getenv() */
  156582. extern char * getenv JPP((const char * name));
  156583. #endif
  156584. #endif
  156585. #ifndef ALIGN_TYPE /* so can override from jconfig.h */
  156586. #define ALIGN_TYPE double
  156587. #endif
  156588. typedef union small_pool_struct * small_pool_ptr;
  156589. typedef union small_pool_struct {
  156590. struct {
  156591. small_pool_ptr next; /* next in list of pools */
  156592. size_t bytes_used; /* how many bytes already used within pool */
  156593. size_t bytes_left; /* bytes still available in this pool */
  156594. } hdr;
  156595. ALIGN_TYPE dummy; /* included in union to ensure alignment */
  156596. } small_pool_hdr;
  156597. typedef union large_pool_struct FAR * large_pool_ptr;
  156598. typedef union large_pool_struct {
  156599. struct {
  156600. large_pool_ptr next; /* next in list of pools */
  156601. size_t bytes_used; /* how many bytes already used within pool */
  156602. size_t bytes_left; /* bytes still available in this pool */
  156603. } hdr;
  156604. ALIGN_TYPE dummy; /* included in union to ensure alignment */
  156605. } large_pool_hdr;
  156606. typedef struct {
  156607. struct jpeg_memory_mgr pub; /* public fields */
  156608. small_pool_ptr small_list[JPOOL_NUMPOOLS];
  156609. large_pool_ptr large_list[JPOOL_NUMPOOLS];
  156610. jvirt_sarray_ptr virt_sarray_list;
  156611. jvirt_barray_ptr virt_barray_list;
  156612. long total_space_allocated;
  156613. JDIMENSION last_rowsperchunk; /* from most recent alloc_sarray/barray */
  156614. } my_memory_mgr;
  156615. typedef my_memory_mgr * my_mem_ptr;
  156616. struct jvirt_sarray_control {
  156617. JSAMPARRAY mem_buffer; /* => the in-memory buffer */
  156618. JDIMENSION rows_in_array; /* total virtual array height */
  156619. JDIMENSION samplesperrow; /* width of array (and of memory buffer) */
  156620. JDIMENSION maxaccess; /* max rows accessed by access_virt_sarray */
  156621. JDIMENSION rows_in_mem; /* height of memory buffer */
  156622. JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */
  156623. JDIMENSION cur_start_row; /* first logical row # in the buffer */
  156624. JDIMENSION first_undef_row; /* row # of first uninitialized row */
  156625. boolean pre_zero; /* pre-zero mode requested? */
  156626. boolean dirty; /* do current buffer contents need written? */
  156627. boolean b_s_open; /* is backing-store data valid? */
  156628. jvirt_sarray_ptr next; /* link to next virtual sarray control block */
  156629. backing_store_info b_s_info; /* System-dependent control info */
  156630. };
  156631. struct jvirt_barray_control {
  156632. JBLOCKARRAY mem_buffer; /* => the in-memory buffer */
  156633. JDIMENSION rows_in_array; /* total virtual array height */
  156634. JDIMENSION blocksperrow; /* width of array (and of memory buffer) */
  156635. JDIMENSION maxaccess; /* max rows accessed by access_virt_barray */
  156636. JDIMENSION rows_in_mem; /* height of memory buffer */
  156637. JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */
  156638. JDIMENSION cur_start_row; /* first logical row # in the buffer */
  156639. JDIMENSION first_undef_row; /* row # of first uninitialized row */
  156640. boolean pre_zero; /* pre-zero mode requested? */
  156641. boolean dirty; /* do current buffer contents need written? */
  156642. boolean b_s_open; /* is backing-store data valid? */
  156643. jvirt_barray_ptr next; /* link to next virtual barray control block */
  156644. backing_store_info b_s_info; /* System-dependent control info */
  156645. };
  156646. #ifdef MEM_STATS /* optional extra stuff for statistics */
  156647. LOCAL(void)
  156648. print_mem_stats (j_common_ptr cinfo, int pool_id)
  156649. {
  156650. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156651. small_pool_ptr shdr_ptr;
  156652. large_pool_ptr lhdr_ptr;
  156653. fprintf(stderr, "Freeing pool %d, total space = %ld\n",
  156654. pool_id, mem->total_space_allocated);
  156655. for (lhdr_ptr = mem->large_list[pool_id]; lhdr_ptr != NULL;
  156656. lhdr_ptr = lhdr_ptr->hdr.next) {
  156657. fprintf(stderr, " Large chunk used %ld\n",
  156658. (long) lhdr_ptr->hdr.bytes_used);
  156659. }
  156660. for (shdr_ptr = mem->small_list[pool_id]; shdr_ptr != NULL;
  156661. shdr_ptr = shdr_ptr->hdr.next) {
  156662. fprintf(stderr, " Small chunk used %ld free %ld\n",
  156663. (long) shdr_ptr->hdr.bytes_used,
  156664. (long) shdr_ptr->hdr.bytes_left);
  156665. }
  156666. }
  156667. #endif /* MEM_STATS */
  156668. LOCAL(void)
  156669. out_of_memory (j_common_ptr cinfo, int which)
  156670. {
  156671. #ifdef MEM_STATS
  156672. cinfo->err->trace_level = 2; /* force self_destruct to report stats */
  156673. #endif
  156674. ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, which);
  156675. }
  156676. static const size_t first_pool_slop[JPOOL_NUMPOOLS] =
  156677. {
  156678. 1600, /* first PERMANENT pool */
  156679. 16000 /* first IMAGE pool */
  156680. };
  156681. static const size_t extra_pool_slop[JPOOL_NUMPOOLS] =
  156682. {
  156683. 0, /* additional PERMANENT pools */
  156684. 5000 /* additional IMAGE pools */
  156685. };
  156686. #define MIN_SLOP 50 /* greater than 0 to avoid futile looping */
  156687. METHODDEF(void *)
  156688. alloc_small (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
  156689. {
  156690. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156691. small_pool_ptr hdr_ptr, prev_hdr_ptr;
  156692. char * data_ptr;
  156693. size_t odd_bytes, min_request, slop;
  156694. if (sizeofobject > (size_t) (MAX_ALLOC_CHUNK-SIZEOF(small_pool_hdr)))
  156695. out_of_memory(cinfo, 1); /* request exceeds malloc's ability */
  156696. odd_bytes = sizeofobject % SIZEOF(ALIGN_TYPE);
  156697. if (odd_bytes > 0)
  156698. sizeofobject += SIZEOF(ALIGN_TYPE) - odd_bytes;
  156699. if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
  156700. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156701. prev_hdr_ptr = NULL;
  156702. hdr_ptr = mem->small_list[pool_id];
  156703. while (hdr_ptr != NULL) {
  156704. if (hdr_ptr->hdr.bytes_left >= sizeofobject)
  156705. break; /* found pool with enough space */
  156706. prev_hdr_ptr = hdr_ptr;
  156707. hdr_ptr = hdr_ptr->hdr.next;
  156708. }
  156709. if (hdr_ptr == NULL) {
  156710. min_request = sizeofobject + SIZEOF(small_pool_hdr);
  156711. if (prev_hdr_ptr == NULL) /* first pool in class? */
  156712. slop = first_pool_slop[pool_id];
  156713. else
  156714. slop = extra_pool_slop[pool_id];
  156715. if (slop > (size_t) (MAX_ALLOC_CHUNK-min_request))
  156716. slop = (size_t) (MAX_ALLOC_CHUNK-min_request);
  156717. for (;;) {
  156718. hdr_ptr = (small_pool_ptr) jpeg_get_small(cinfo, min_request + slop);
  156719. if (hdr_ptr != NULL)
  156720. break;
  156721. slop /= 2;
  156722. if (slop < MIN_SLOP) /* give up when it gets real small */
  156723. out_of_memory(cinfo, 2); /* jpeg_get_small failed */
  156724. }
  156725. mem->total_space_allocated += min_request + slop;
  156726. hdr_ptr->hdr.next = NULL;
  156727. hdr_ptr->hdr.bytes_used = 0;
  156728. hdr_ptr->hdr.bytes_left = sizeofobject + slop;
  156729. if (prev_hdr_ptr == NULL) /* first pool in class? */
  156730. mem->small_list[pool_id] = hdr_ptr;
  156731. else
  156732. prev_hdr_ptr->hdr.next = hdr_ptr;
  156733. }
  156734. data_ptr = (char *) (hdr_ptr + 1); /* point to first data byte in pool */
  156735. data_ptr += hdr_ptr->hdr.bytes_used; /* point to place for object */
  156736. hdr_ptr->hdr.bytes_used += sizeofobject;
  156737. hdr_ptr->hdr.bytes_left -= sizeofobject;
  156738. return (void *) data_ptr;
  156739. }
  156740. METHODDEF(void FAR *)
  156741. alloc_large (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
  156742. {
  156743. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156744. large_pool_ptr hdr_ptr;
  156745. size_t odd_bytes;
  156746. if (sizeofobject > (size_t) (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)))
  156747. out_of_memory(cinfo, 3); /* request exceeds malloc's ability */
  156748. odd_bytes = sizeofobject % SIZEOF(ALIGN_TYPE);
  156749. if (odd_bytes > 0)
  156750. sizeofobject += SIZEOF(ALIGN_TYPE) - odd_bytes;
  156751. if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
  156752. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156753. hdr_ptr = (large_pool_ptr) jpeg_get_large(cinfo, sizeofobject +
  156754. SIZEOF(large_pool_hdr));
  156755. if (hdr_ptr == NULL)
  156756. out_of_memory(cinfo, 4); /* jpeg_get_large failed */
  156757. mem->total_space_allocated += sizeofobject + SIZEOF(large_pool_hdr);
  156758. hdr_ptr->hdr.next = mem->large_list[pool_id];
  156759. hdr_ptr->hdr.bytes_used = sizeofobject;
  156760. hdr_ptr->hdr.bytes_left = 0;
  156761. mem->large_list[pool_id] = hdr_ptr;
  156762. return (void FAR *) (hdr_ptr + 1); /* point to first data byte in pool */
  156763. }
  156764. METHODDEF(JSAMPARRAY)
  156765. alloc_sarray (j_common_ptr cinfo, int pool_id,
  156766. JDIMENSION samplesperrow, JDIMENSION numrows)
  156767. {
  156768. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156769. JSAMPARRAY result;
  156770. JSAMPROW workspace;
  156771. JDIMENSION rowsperchunk, currow, i;
  156772. long ltemp;
  156773. ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /
  156774. ((long) samplesperrow * SIZEOF(JSAMPLE));
  156775. if (ltemp <= 0)
  156776. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  156777. if (ltemp < (long) numrows)
  156778. rowsperchunk = (JDIMENSION) ltemp;
  156779. else
  156780. rowsperchunk = numrows;
  156781. mem->last_rowsperchunk = rowsperchunk;
  156782. result = (JSAMPARRAY) alloc_small(cinfo, pool_id,
  156783. (size_t) (numrows * SIZEOF(JSAMPROW)));
  156784. currow = 0;
  156785. while (currow < numrows) {
  156786. rowsperchunk = MIN(rowsperchunk, numrows - currow);
  156787. workspace = (JSAMPROW) alloc_large(cinfo, pool_id,
  156788. (size_t) ((size_t) rowsperchunk * (size_t) samplesperrow
  156789. * SIZEOF(JSAMPLE)));
  156790. for (i = rowsperchunk; i > 0; i--) {
  156791. result[currow++] = workspace;
  156792. workspace += samplesperrow;
  156793. }
  156794. }
  156795. return result;
  156796. }
  156797. METHODDEF(JBLOCKARRAY)
  156798. alloc_barray (j_common_ptr cinfo, int pool_id,
  156799. JDIMENSION blocksperrow, JDIMENSION numrows)
  156800. {
  156801. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156802. JBLOCKARRAY result;
  156803. JBLOCKROW workspace;
  156804. JDIMENSION rowsperchunk, currow, i;
  156805. long ltemp;
  156806. ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /
  156807. ((long) blocksperrow * SIZEOF(JBLOCK));
  156808. if (ltemp <= 0)
  156809. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  156810. if (ltemp < (long) numrows)
  156811. rowsperchunk = (JDIMENSION) ltemp;
  156812. else
  156813. rowsperchunk = numrows;
  156814. mem->last_rowsperchunk = rowsperchunk;
  156815. result = (JBLOCKARRAY) alloc_small(cinfo, pool_id,
  156816. (size_t) (numrows * SIZEOF(JBLOCKROW)));
  156817. currow = 0;
  156818. while (currow < numrows) {
  156819. rowsperchunk = MIN(rowsperchunk, numrows - currow);
  156820. workspace = (JBLOCKROW) alloc_large(cinfo, pool_id,
  156821. (size_t) ((size_t) rowsperchunk * (size_t) blocksperrow
  156822. * SIZEOF(JBLOCK)));
  156823. for (i = rowsperchunk; i > 0; i--) {
  156824. result[currow++] = workspace;
  156825. workspace += blocksperrow;
  156826. }
  156827. }
  156828. return result;
  156829. }
  156830. METHODDEF(jvirt_sarray_ptr)
  156831. request_virt_sarray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
  156832. JDIMENSION samplesperrow, JDIMENSION numrows,
  156833. JDIMENSION maxaccess)
  156834. {
  156835. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156836. jvirt_sarray_ptr result;
  156837. if (pool_id != JPOOL_IMAGE)
  156838. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156839. result = (jvirt_sarray_ptr) alloc_small(cinfo, pool_id,
  156840. SIZEOF(struct jvirt_sarray_control));
  156841. result->mem_buffer = NULL; /* marks array not yet realized */
  156842. result->rows_in_array = numrows;
  156843. result->samplesperrow = samplesperrow;
  156844. result->maxaccess = maxaccess;
  156845. result->pre_zero = pre_zero;
  156846. result->b_s_open = FALSE; /* no associated backing-store object */
  156847. result->next = mem->virt_sarray_list; /* add to list of virtual arrays */
  156848. mem->virt_sarray_list = result;
  156849. return result;
  156850. }
  156851. METHODDEF(jvirt_barray_ptr)
  156852. request_virt_barray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
  156853. JDIMENSION blocksperrow, JDIMENSION numrows,
  156854. JDIMENSION maxaccess)
  156855. {
  156856. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156857. jvirt_barray_ptr result;
  156858. if (pool_id != JPOOL_IMAGE)
  156859. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156860. result = (jvirt_barray_ptr) alloc_small(cinfo, pool_id,
  156861. SIZEOF(struct jvirt_barray_control));
  156862. result->mem_buffer = NULL; /* marks array not yet realized */
  156863. result->rows_in_array = numrows;
  156864. result->blocksperrow = blocksperrow;
  156865. result->maxaccess = maxaccess;
  156866. result->pre_zero = pre_zero;
  156867. result->b_s_open = FALSE; /* no associated backing-store object */
  156868. result->next = mem->virt_barray_list; /* add to list of virtual arrays */
  156869. mem->virt_barray_list = result;
  156870. return result;
  156871. }
  156872. METHODDEF(void)
  156873. realize_virt_arrays (j_common_ptr cinfo)
  156874. {
  156875. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156876. long space_per_minheight, maximum_space, avail_mem;
  156877. long minheights, max_minheights;
  156878. jvirt_sarray_ptr sptr;
  156879. jvirt_barray_ptr bptr;
  156880. space_per_minheight = 0;
  156881. maximum_space = 0;
  156882. for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
  156883. if (sptr->mem_buffer == NULL) { /* if not realized yet */
  156884. space_per_minheight += (long) sptr->maxaccess *
  156885. (long) sptr->samplesperrow * SIZEOF(JSAMPLE);
  156886. maximum_space += (long) sptr->rows_in_array *
  156887. (long) sptr->samplesperrow * SIZEOF(JSAMPLE);
  156888. }
  156889. }
  156890. for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
  156891. if (bptr->mem_buffer == NULL) { /* if not realized yet */
  156892. space_per_minheight += (long) bptr->maxaccess *
  156893. (long) bptr->blocksperrow * SIZEOF(JBLOCK);
  156894. maximum_space += (long) bptr->rows_in_array *
  156895. (long) bptr->blocksperrow * SIZEOF(JBLOCK);
  156896. }
  156897. }
  156898. if (space_per_minheight <= 0)
  156899. return; /* no unrealized arrays, no work */
  156900. avail_mem = jpeg_mem_available(cinfo, space_per_minheight, maximum_space,
  156901. mem->total_space_allocated);
  156902. if (avail_mem >= maximum_space)
  156903. max_minheights = 1000000000L;
  156904. else {
  156905. max_minheights = avail_mem / space_per_minheight;
  156906. if (max_minheights <= 0)
  156907. max_minheights = 1;
  156908. }
  156909. for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
  156910. if (sptr->mem_buffer == NULL) { /* if not realized yet */
  156911. minheights = ((long) sptr->rows_in_array - 1L) / sptr->maxaccess + 1L;
  156912. if (minheights <= max_minheights) {
  156913. sptr->rows_in_mem = sptr->rows_in_array;
  156914. } else {
  156915. sptr->rows_in_mem = (JDIMENSION) (max_minheights * sptr->maxaccess);
  156916. jpeg_open_backing_store(cinfo, & sptr->b_s_info,
  156917. (long) sptr->rows_in_array *
  156918. (long) sptr->samplesperrow *
  156919. (long) SIZEOF(JSAMPLE));
  156920. sptr->b_s_open = TRUE;
  156921. }
  156922. sptr->mem_buffer = alloc_sarray(cinfo, JPOOL_IMAGE,
  156923. sptr->samplesperrow, sptr->rows_in_mem);
  156924. sptr->rowsperchunk = mem->last_rowsperchunk;
  156925. sptr->cur_start_row = 0;
  156926. sptr->first_undef_row = 0;
  156927. sptr->dirty = FALSE;
  156928. }
  156929. }
  156930. for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
  156931. if (bptr->mem_buffer == NULL) { /* if not realized yet */
  156932. minheights = ((long) bptr->rows_in_array - 1L) / bptr->maxaccess + 1L;
  156933. if (minheights <= max_minheights) {
  156934. bptr->rows_in_mem = bptr->rows_in_array;
  156935. } else {
  156936. bptr->rows_in_mem = (JDIMENSION) (max_minheights * bptr->maxaccess);
  156937. jpeg_open_backing_store(cinfo, & bptr->b_s_info,
  156938. (long) bptr->rows_in_array *
  156939. (long) bptr->blocksperrow *
  156940. (long) SIZEOF(JBLOCK));
  156941. bptr->b_s_open = TRUE;
  156942. }
  156943. bptr->mem_buffer = alloc_barray(cinfo, JPOOL_IMAGE,
  156944. bptr->blocksperrow, bptr->rows_in_mem);
  156945. bptr->rowsperchunk = mem->last_rowsperchunk;
  156946. bptr->cur_start_row = 0;
  156947. bptr->first_undef_row = 0;
  156948. bptr->dirty = FALSE;
  156949. }
  156950. }
  156951. }
  156952. LOCAL(void)
  156953. do_sarray_io (j_common_ptr cinfo, jvirt_sarray_ptr ptr, boolean writing)
  156954. {
  156955. long bytesperrow, file_offset, byte_count, rows, thisrow, i;
  156956. bytesperrow = (long) ptr->samplesperrow * SIZEOF(JSAMPLE);
  156957. file_offset = ptr->cur_start_row * bytesperrow;
  156958. for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) {
  156959. rows = MIN((long) ptr->rowsperchunk, (long) ptr->rows_in_mem - i);
  156960. thisrow = (long) ptr->cur_start_row + i;
  156961. rows = MIN(rows, (long) ptr->first_undef_row - thisrow);
  156962. rows = MIN(rows, (long) ptr->rows_in_array - thisrow);
  156963. if (rows <= 0) /* this chunk might be past end of file! */
  156964. break;
  156965. byte_count = rows * bytesperrow;
  156966. if (writing)
  156967. (*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info,
  156968. (void FAR *) ptr->mem_buffer[i],
  156969. file_offset, byte_count);
  156970. else
  156971. (*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info,
  156972. (void FAR *) ptr->mem_buffer[i],
  156973. file_offset, byte_count);
  156974. file_offset += byte_count;
  156975. }
  156976. }
  156977. LOCAL(void)
  156978. do_barray_io (j_common_ptr cinfo, jvirt_barray_ptr ptr, boolean writing)
  156979. {
  156980. long bytesperrow, file_offset, byte_count, rows, thisrow, i;
  156981. bytesperrow = (long) ptr->blocksperrow * SIZEOF(JBLOCK);
  156982. file_offset = ptr->cur_start_row * bytesperrow;
  156983. for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) {
  156984. rows = MIN((long) ptr->rowsperchunk, (long) ptr->rows_in_mem - i);
  156985. thisrow = (long) ptr->cur_start_row + i;
  156986. rows = MIN(rows, (long) ptr->first_undef_row - thisrow);
  156987. rows = MIN(rows, (long) ptr->rows_in_array - thisrow);
  156988. if (rows <= 0) /* this chunk might be past end of file! */
  156989. break;
  156990. byte_count = rows * bytesperrow;
  156991. if (writing)
  156992. (*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info,
  156993. (void FAR *) ptr->mem_buffer[i],
  156994. file_offset, byte_count);
  156995. else
  156996. (*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info,
  156997. (void FAR *) ptr->mem_buffer[i],
  156998. file_offset, byte_count);
  156999. file_offset += byte_count;
  157000. }
  157001. }
  157002. METHODDEF(JSAMPARRAY)
  157003. access_virt_sarray (j_common_ptr cinfo, jvirt_sarray_ptr ptr,
  157004. JDIMENSION start_row, JDIMENSION num_rows,
  157005. boolean writable)
  157006. {
  157007. JDIMENSION end_row = start_row + num_rows;
  157008. JDIMENSION undef_row;
  157009. if (end_row > ptr->rows_in_array || num_rows > ptr->maxaccess ||
  157010. ptr->mem_buffer == NULL)
  157011. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  157012. if (start_row < ptr->cur_start_row ||
  157013. end_row > ptr->cur_start_row+ptr->rows_in_mem) {
  157014. if (! ptr->b_s_open)
  157015. ERREXIT(cinfo, JERR_VIRTUAL_BUG);
  157016. if (ptr->dirty) {
  157017. do_sarray_io(cinfo, ptr, TRUE);
  157018. ptr->dirty = FALSE;
  157019. }
  157020. if (start_row > ptr->cur_start_row) {
  157021. ptr->cur_start_row = start_row;
  157022. } else {
  157023. long ltemp;
  157024. ltemp = (long) end_row - (long) ptr->rows_in_mem;
  157025. if (ltemp < 0)
  157026. ltemp = 0; /* don't fall off front end of file */
  157027. ptr->cur_start_row = (JDIMENSION) ltemp;
  157028. }
  157029. do_sarray_io(cinfo, ptr, FALSE);
  157030. }
  157031. if (ptr->first_undef_row < end_row) {
  157032. if (ptr->first_undef_row < start_row) {
  157033. if (writable) /* writer skipped over a section of array */
  157034. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  157035. undef_row = start_row; /* but reader is allowed to read ahead */
  157036. } else {
  157037. undef_row = ptr->first_undef_row;
  157038. }
  157039. if (writable)
  157040. ptr->first_undef_row = end_row;
  157041. if (ptr->pre_zero) {
  157042. size_t bytesperrow = (size_t) ptr->samplesperrow * SIZEOF(JSAMPLE);
  157043. undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
  157044. end_row -= ptr->cur_start_row;
  157045. while (undef_row < end_row) {
  157046. jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
  157047. undef_row++;
  157048. }
  157049. } else {
  157050. if (! writable) /* reader looking at undefined data */
  157051. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  157052. }
  157053. }
  157054. if (writable)
  157055. ptr->dirty = TRUE;
  157056. return ptr->mem_buffer + (start_row - ptr->cur_start_row);
  157057. }
  157058. METHODDEF(JBLOCKARRAY)
  157059. access_virt_barray (j_common_ptr cinfo, jvirt_barray_ptr ptr,
  157060. JDIMENSION start_row, JDIMENSION num_rows,
  157061. boolean writable)
  157062. {
  157063. JDIMENSION end_row = start_row + num_rows;
  157064. JDIMENSION undef_row;
  157065. if (end_row > ptr->rows_in_array || num_rows > ptr->maxaccess ||
  157066. ptr->mem_buffer == NULL)
  157067. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  157068. if (start_row < ptr->cur_start_row ||
  157069. end_row > ptr->cur_start_row+ptr->rows_in_mem) {
  157070. if (! ptr->b_s_open)
  157071. ERREXIT(cinfo, JERR_VIRTUAL_BUG);
  157072. if (ptr->dirty) {
  157073. do_barray_io(cinfo, ptr, TRUE);
  157074. ptr->dirty = FALSE;
  157075. }
  157076. if (start_row > ptr->cur_start_row) {
  157077. ptr->cur_start_row = start_row;
  157078. } else {
  157079. long ltemp;
  157080. ltemp = (long) end_row - (long) ptr->rows_in_mem;
  157081. if (ltemp < 0)
  157082. ltemp = 0; /* don't fall off front end of file */
  157083. ptr->cur_start_row = (JDIMENSION) ltemp;
  157084. }
  157085. do_barray_io(cinfo, ptr, FALSE);
  157086. }
  157087. if (ptr->first_undef_row < end_row) {
  157088. if (ptr->first_undef_row < start_row) {
  157089. if (writable) /* writer skipped over a section of array */
  157090. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  157091. undef_row = start_row; /* but reader is allowed to read ahead */
  157092. } else {
  157093. undef_row = ptr->first_undef_row;
  157094. }
  157095. if (writable)
  157096. ptr->first_undef_row = end_row;
  157097. if (ptr->pre_zero) {
  157098. size_t bytesperrow = (size_t) ptr->blocksperrow * SIZEOF(JBLOCK);
  157099. undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
  157100. end_row -= ptr->cur_start_row;
  157101. while (undef_row < end_row) {
  157102. jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
  157103. undef_row++;
  157104. }
  157105. } else {
  157106. if (! writable) /* reader looking at undefined data */
  157107. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  157108. }
  157109. }
  157110. if (writable)
  157111. ptr->dirty = TRUE;
  157112. return ptr->mem_buffer + (start_row - ptr->cur_start_row);
  157113. }
  157114. METHODDEF(void)
  157115. free_pool (j_common_ptr cinfo, int pool_id)
  157116. {
  157117. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  157118. small_pool_ptr shdr_ptr;
  157119. large_pool_ptr lhdr_ptr;
  157120. size_t space_freed;
  157121. if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
  157122. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  157123. #ifdef MEM_STATS
  157124. if (cinfo->err->trace_level > 1)
  157125. print_mem_stats(cinfo, pool_id); /* print pool's memory usage statistics */
  157126. #endif
  157127. if (pool_id == JPOOL_IMAGE) {
  157128. jvirt_sarray_ptr sptr;
  157129. jvirt_barray_ptr bptr;
  157130. for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
  157131. if (sptr->b_s_open) { /* there may be no backing store */
  157132. sptr->b_s_open = FALSE; /* prevent recursive close if error */
  157133. (*sptr->b_s_info.close_backing_store) (cinfo, & sptr->b_s_info);
  157134. }
  157135. }
  157136. mem->virt_sarray_list = NULL;
  157137. for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
  157138. if (bptr->b_s_open) { /* there may be no backing store */
  157139. bptr->b_s_open = FALSE; /* prevent recursive close if error */
  157140. (*bptr->b_s_info.close_backing_store) (cinfo, & bptr->b_s_info);
  157141. }
  157142. }
  157143. mem->virt_barray_list = NULL;
  157144. }
  157145. lhdr_ptr = mem->large_list[pool_id];
  157146. mem->large_list[pool_id] = NULL;
  157147. while (lhdr_ptr != NULL) {
  157148. large_pool_ptr next_lhdr_ptr = lhdr_ptr->hdr.next;
  157149. space_freed = lhdr_ptr->hdr.bytes_used +
  157150. lhdr_ptr->hdr.bytes_left +
  157151. SIZEOF(large_pool_hdr);
  157152. jpeg_free_large(cinfo, (void FAR *) lhdr_ptr, space_freed);
  157153. mem->total_space_allocated -= space_freed;
  157154. lhdr_ptr = next_lhdr_ptr;
  157155. }
  157156. shdr_ptr = mem->small_list[pool_id];
  157157. mem->small_list[pool_id] = NULL;
  157158. while (shdr_ptr != NULL) {
  157159. small_pool_ptr next_shdr_ptr = shdr_ptr->hdr.next;
  157160. space_freed = shdr_ptr->hdr.bytes_used +
  157161. shdr_ptr->hdr.bytes_left +
  157162. SIZEOF(small_pool_hdr);
  157163. jpeg_free_small(cinfo, (void *) shdr_ptr, space_freed);
  157164. mem->total_space_allocated -= space_freed;
  157165. shdr_ptr = next_shdr_ptr;
  157166. }
  157167. }
  157168. METHODDEF(void)
  157169. self_destruct (j_common_ptr cinfo)
  157170. {
  157171. int pool;
  157172. for (pool = JPOOL_NUMPOOLS-1; pool >= JPOOL_PERMANENT; pool--) {
  157173. free_pool(cinfo, pool);
  157174. }
  157175. jpeg_free_small(cinfo, (void *) cinfo->mem, SIZEOF(my_memory_mgr));
  157176. cinfo->mem = NULL; /* ensures I will be called only once */
  157177. jpeg_mem_term(cinfo); /* system-dependent cleanup */
  157178. }
  157179. GLOBAL(void)
  157180. jinit_memory_mgr (j_common_ptr cinfo)
  157181. {
  157182. my_mem_ptr mem;
  157183. long max_to_use;
  157184. int pool;
  157185. size_t test_mac;
  157186. cinfo->mem = NULL; /* for safety if init fails */
  157187. if ((SIZEOF(ALIGN_TYPE) & (SIZEOF(ALIGN_TYPE)-1)) != 0)
  157188. ERREXIT(cinfo, JERR_BAD_ALIGN_TYPE);
  157189. test_mac = (size_t) MAX_ALLOC_CHUNK;
  157190. if ((long) test_mac != MAX_ALLOC_CHUNK ||
  157191. (MAX_ALLOC_CHUNK % SIZEOF(ALIGN_TYPE)) != 0)
  157192. ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK);
  157193. max_to_use = jpeg_mem_init(cinfo); /* system-dependent initialization */
  157194. mem = (my_mem_ptr) jpeg_get_small(cinfo, SIZEOF(my_memory_mgr));
  157195. if (mem == NULL) {
  157196. jpeg_mem_term(cinfo); /* system-dependent cleanup */
  157197. ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 0);
  157198. }
  157199. mem->pub.alloc_small = alloc_small;
  157200. mem->pub.alloc_large = alloc_large;
  157201. mem->pub.alloc_sarray = alloc_sarray;
  157202. mem->pub.alloc_barray = alloc_barray;
  157203. mem->pub.request_virt_sarray = request_virt_sarray;
  157204. mem->pub.request_virt_barray = request_virt_barray;
  157205. mem->pub.realize_virt_arrays = realize_virt_arrays;
  157206. mem->pub.access_virt_sarray = access_virt_sarray;
  157207. mem->pub.access_virt_barray = access_virt_barray;
  157208. mem->pub.free_pool = free_pool;
  157209. mem->pub.self_destruct = self_destruct;
  157210. mem->pub.max_alloc_chunk = MAX_ALLOC_CHUNK;
  157211. mem->pub.max_memory_to_use = max_to_use;
  157212. for (pool = JPOOL_NUMPOOLS-1; pool >= JPOOL_PERMANENT; pool--) {
  157213. mem->small_list[pool] = NULL;
  157214. mem->large_list[pool] = NULL;
  157215. }
  157216. mem->virt_sarray_list = NULL;
  157217. mem->virt_barray_list = NULL;
  157218. mem->total_space_allocated = SIZEOF(my_memory_mgr);
  157219. cinfo->mem = & mem->pub;
  157220. #ifndef NO_GETENV
  157221. { char * memenv;
  157222. if ((memenv = getenv("JPEGMEM")) != NULL) {
  157223. char ch = 'x';
  157224. if (sscanf(memenv, "%ld%c", &max_to_use, &ch) > 0) {
  157225. if (ch == 'm' || ch == 'M')
  157226. max_to_use *= 1000L;
  157227. mem->pub.max_memory_to_use = max_to_use * 1000L;
  157228. }
  157229. }
  157230. }
  157231. #endif
  157232. }
  157233. /*** End of inlined file: jmemmgr.c ***/
  157234. /*** Start of inlined file: jmemnobs.c ***/
  157235. #define JPEG_INTERNALS
  157236. #ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc(),free() */
  157237. extern void * malloc JPP((size_t size));
  157238. extern void free JPP((void *ptr));
  157239. #endif
  157240. GLOBAL(void *)
  157241. jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject)
  157242. {
  157243. return (void *) malloc(sizeofobject);
  157244. }
  157245. GLOBAL(void)
  157246. jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject)
  157247. {
  157248. free(object);
  157249. }
  157250. GLOBAL(void FAR *)
  157251. jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject)
  157252. {
  157253. return (void FAR *) malloc(sizeofobject);
  157254. }
  157255. GLOBAL(void)
  157256. jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject)
  157257. {
  157258. free(object);
  157259. }
  157260. GLOBAL(long)
  157261. jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,
  157262. long max_bytes_needed, long already_allocated)
  157263. {
  157264. return max_bytes_needed;
  157265. }
  157266. GLOBAL(void)
  157267. jpeg_open_backing_store (j_common_ptr cinfo, struct backing_store_struct *info,
  157268. long total_bytes_needed)
  157269. {
  157270. ERREXIT(cinfo, JERR_NO_BACKING_STORE);
  157271. }
  157272. GLOBAL(long)
  157273. jpeg_mem_init (j_common_ptr cinfo)
  157274. {
  157275. return 0; /* just set max_memory_to_use to 0 */
  157276. }
  157277. GLOBAL(void)
  157278. jpeg_mem_term (j_common_ptr cinfo)
  157279. {
  157280. }
  157281. /*** End of inlined file: jmemnobs.c ***/
  157282. /*** Start of inlined file: jquant1.c ***/
  157283. #define JPEG_INTERNALS
  157284. #ifdef QUANT_1PASS_SUPPORTED
  157285. #define ODITHER_SIZE 16 /* dimension of dither matrix */
  157286. #define ODITHER_CELLS (ODITHER_SIZE*ODITHER_SIZE) /* # cells in matrix */
  157287. #define ODITHER_MASK (ODITHER_SIZE-1) /* mask for wrapping around counters */
  157288. typedef int ODITHER_MATRIX[ODITHER_SIZE][ODITHER_SIZE];
  157289. typedef int (*ODITHER_MATRIX_PTR)[ODITHER_SIZE];
  157290. static const UINT8 base_dither_matrix[ODITHER_SIZE][ODITHER_SIZE] = {
  157291. { 0,192, 48,240, 12,204, 60,252, 3,195, 51,243, 15,207, 63,255 },
  157292. { 128, 64,176,112,140, 76,188,124,131, 67,179,115,143, 79,191,127 },
  157293. { 32,224, 16,208, 44,236, 28,220, 35,227, 19,211, 47,239, 31,223 },
  157294. { 160, 96,144, 80,172,108,156, 92,163, 99,147, 83,175,111,159, 95 },
  157295. { 8,200, 56,248, 4,196, 52,244, 11,203, 59,251, 7,199, 55,247 },
  157296. { 136, 72,184,120,132, 68,180,116,139, 75,187,123,135, 71,183,119 },
  157297. { 40,232, 24,216, 36,228, 20,212, 43,235, 27,219, 39,231, 23,215 },
  157298. { 168,104,152, 88,164,100,148, 84,171,107,155, 91,167,103,151, 87 },
  157299. { 2,194, 50,242, 14,206, 62,254, 1,193, 49,241, 13,205, 61,253 },
  157300. { 130, 66,178,114,142, 78,190,126,129, 65,177,113,141, 77,189,125 },
  157301. { 34,226, 18,210, 46,238, 30,222, 33,225, 17,209, 45,237, 29,221 },
  157302. { 162, 98,146, 82,174,110,158, 94,161, 97,145, 81,173,109,157, 93 },
  157303. { 10,202, 58,250, 6,198, 54,246, 9,201, 57,249, 5,197, 53,245 },
  157304. { 138, 74,186,122,134, 70,182,118,137, 73,185,121,133, 69,181,117 },
  157305. { 42,234, 26,218, 38,230, 22,214, 41,233, 25,217, 37,229, 21,213 },
  157306. { 170,106,154, 90,166,102,150, 86,169,105,153, 89,165,101,149, 85 }
  157307. };
  157308. #if BITS_IN_JSAMPLE == 8
  157309. typedef INT16 FSERROR; /* 16 bits should be enough */
  157310. typedef int LOCFSERROR; /* use 'int' for calculation temps */
  157311. #else
  157312. typedef INT32 FSERROR; /* may need more than 16 bits */
  157313. typedef INT32 LOCFSERROR; /* be sure calculation temps are big enough */
  157314. #endif
  157315. typedef FSERROR FAR *FSERRPTR; /* pointer to error array (in FAR storage!) */
  157316. #define MAX_Q_COMPS 4 /* max components I can handle */
  157317. typedef struct {
  157318. struct jpeg_color_quantizer pub; /* public fields */
  157319. JSAMPARRAY sv_colormap; /* The color map as a 2-D pixel array */
  157320. int sv_actual; /* number of entries in use */
  157321. JSAMPARRAY colorindex; /* Precomputed mapping for speed */
  157322. boolean is_padded; /* is the colorindex padded for odither? */
  157323. int Ncolors[MAX_Q_COMPS]; /* # of values alloced to each component */
  157324. int row_index; /* cur row's vertical index in dither matrix */
  157325. ODITHER_MATRIX_PTR odither[MAX_Q_COMPS]; /* one dither array per component */
  157326. FSERRPTR fserrors[MAX_Q_COMPS]; /* accumulated errors */
  157327. boolean on_odd_row; /* flag to remember which row we are on */
  157328. } my_cquantizer;
  157329. typedef my_cquantizer * my_cquantize_ptr;
  157330. LOCAL(int)
  157331. select_ncolors (j_decompress_ptr cinfo, int Ncolors[])
  157332. {
  157333. int nc = cinfo->out_color_components; /* number of color components */
  157334. int max_colors = cinfo->desired_number_of_colors;
  157335. int total_colors, iroot, i, j;
  157336. boolean changed;
  157337. long temp;
  157338. static const int RGB_order[3] = { RGB_GREEN, RGB_RED, RGB_BLUE };
  157339. iroot = 1;
  157340. do {
  157341. iroot++;
  157342. temp = iroot; /* set temp = iroot ** nc */
  157343. for (i = 1; i < nc; i++)
  157344. temp *= iroot;
  157345. } while (temp <= (long) max_colors); /* repeat till iroot exceeds root */
  157346. iroot--; /* now iroot = floor(root) */
  157347. if (iroot < 2)
  157348. ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, (int) temp);
  157349. total_colors = 1;
  157350. for (i = 0; i < nc; i++) {
  157351. Ncolors[i] = iroot;
  157352. total_colors *= iroot;
  157353. }
  157354. do {
  157355. changed = FALSE;
  157356. for (i = 0; i < nc; i++) {
  157357. j = (cinfo->out_color_space == JCS_RGB ? RGB_order[i] : i);
  157358. temp = total_colors / Ncolors[j];
  157359. temp *= Ncolors[j]+1; /* done in long arith to avoid oflo */
  157360. if (temp > (long) max_colors)
  157361. break; /* won't fit, done with this pass */
  157362. Ncolors[j]++; /* OK, apply the increment */
  157363. total_colors = (int) temp;
  157364. changed = TRUE;
  157365. }
  157366. } while (changed);
  157367. return total_colors;
  157368. }
  157369. LOCAL(int)
  157370. output_value (j_decompress_ptr cinfo, int ci, int j, int maxj)
  157371. {
  157372. return (int) (((INT32) j * MAXJSAMPLE + maxj/2) / maxj);
  157373. }
  157374. LOCAL(int)
  157375. largest_input_value (j_decompress_ptr cinfo, int ci, int j, int maxj)
  157376. {
  157377. return (int) (((INT32) (2*j + 1) * MAXJSAMPLE + maxj) / (2*maxj));
  157378. }
  157379. LOCAL(void)
  157380. create_colormap (j_decompress_ptr cinfo)
  157381. {
  157382. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157383. JSAMPARRAY colormap; /* Created colormap */
  157384. int total_colors; /* Number of distinct output colors */
  157385. int i,j,k, nci, blksize, blkdist, ptr, val;
  157386. total_colors = select_ncolors(cinfo, cquantize->Ncolors);
  157387. if (cinfo->out_color_components == 3)
  157388. TRACEMS4(cinfo, 1, JTRC_QUANT_3_NCOLORS,
  157389. total_colors, cquantize->Ncolors[0],
  157390. cquantize->Ncolors[1], cquantize->Ncolors[2]);
  157391. else
  157392. TRACEMS1(cinfo, 1, JTRC_QUANT_NCOLORS, total_colors);
  157393. colormap = (*cinfo->mem->alloc_sarray)
  157394. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157395. (JDIMENSION) total_colors, (JDIMENSION) cinfo->out_color_components);
  157396. blkdist = total_colors;
  157397. for (i = 0; i < cinfo->out_color_components; i++) {
  157398. nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
  157399. blksize = blkdist / nci;
  157400. for (j = 0; j < nci; j++) {
  157401. val = output_value(cinfo, i, j, nci-1);
  157402. for (ptr = j * blksize; ptr < total_colors; ptr += blkdist) {
  157403. for (k = 0; k < blksize; k++)
  157404. colormap[i][ptr+k] = (JSAMPLE) val;
  157405. }
  157406. }
  157407. blkdist = blksize; /* blksize of this color is blkdist of next */
  157408. }
  157409. cquantize->sv_colormap = colormap;
  157410. cquantize->sv_actual = total_colors;
  157411. }
  157412. LOCAL(void)
  157413. create_colorindex (j_decompress_ptr cinfo)
  157414. {
  157415. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157416. JSAMPROW indexptr;
  157417. int i,j,k, nci, blksize, val, pad;
  157418. if (cinfo->dither_mode == JDITHER_ORDERED) {
  157419. pad = MAXJSAMPLE*2;
  157420. cquantize->is_padded = TRUE;
  157421. } else {
  157422. pad = 0;
  157423. cquantize->is_padded = FALSE;
  157424. }
  157425. cquantize->colorindex = (*cinfo->mem->alloc_sarray)
  157426. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157427. (JDIMENSION) (MAXJSAMPLE+1 + pad),
  157428. (JDIMENSION) cinfo->out_color_components);
  157429. blksize = cquantize->sv_actual;
  157430. for (i = 0; i < cinfo->out_color_components; i++) {
  157431. nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
  157432. blksize = blksize / nci;
  157433. if (pad)
  157434. cquantize->colorindex[i] += MAXJSAMPLE;
  157435. indexptr = cquantize->colorindex[i];
  157436. val = 0;
  157437. k = largest_input_value(cinfo, i, 0, nci-1);
  157438. for (j = 0; j <= MAXJSAMPLE; j++) {
  157439. while (j > k) /* advance val if past boundary */
  157440. k = largest_input_value(cinfo, i, ++val, nci-1);
  157441. indexptr[j] = (JSAMPLE) (val * blksize);
  157442. }
  157443. if (pad)
  157444. for (j = 1; j <= MAXJSAMPLE; j++) {
  157445. indexptr[-j] = indexptr[0];
  157446. indexptr[MAXJSAMPLE+j] = indexptr[MAXJSAMPLE];
  157447. }
  157448. }
  157449. }
  157450. LOCAL(ODITHER_MATRIX_PTR)
  157451. make_odither_array (j_decompress_ptr cinfo, int ncolors)
  157452. {
  157453. ODITHER_MATRIX_PTR odither;
  157454. int j,k;
  157455. INT32 num,den;
  157456. odither = (ODITHER_MATRIX_PTR)
  157457. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157458. SIZEOF(ODITHER_MATRIX));
  157459. den = 2 * ODITHER_CELLS * ((INT32) (ncolors - 1));
  157460. for (j = 0; j < ODITHER_SIZE; j++) {
  157461. for (k = 0; k < ODITHER_SIZE; k++) {
  157462. num = ((INT32) (ODITHER_CELLS-1 - 2*((int)base_dither_matrix[j][k])))
  157463. * MAXJSAMPLE;
  157464. odither[j][k] = (int) (num<0 ? -((-num)/den) : num/den);
  157465. }
  157466. }
  157467. return odither;
  157468. }
  157469. LOCAL(void)
  157470. create_odither_tables (j_decompress_ptr cinfo)
  157471. {
  157472. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157473. ODITHER_MATRIX_PTR odither;
  157474. int i, j, nci;
  157475. for (i = 0; i < cinfo->out_color_components; i++) {
  157476. nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
  157477. odither = NULL; /* search for matching prior component */
  157478. for (j = 0; j < i; j++) {
  157479. if (nci == cquantize->Ncolors[j]) {
  157480. odither = cquantize->odither[j];
  157481. break;
  157482. }
  157483. }
  157484. if (odither == NULL) /* need a new table? */
  157485. odither = make_odither_array(cinfo, nci);
  157486. cquantize->odither[i] = odither;
  157487. }
  157488. }
  157489. METHODDEF(void)
  157490. color_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157491. JSAMPARRAY output_buf, int num_rows)
  157492. {
  157493. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157494. JSAMPARRAY colorindex = cquantize->colorindex;
  157495. register int pixcode, ci;
  157496. register JSAMPROW ptrin, ptrout;
  157497. int row;
  157498. JDIMENSION col;
  157499. JDIMENSION width = cinfo->output_width;
  157500. register int nc = cinfo->out_color_components;
  157501. for (row = 0; row < num_rows; row++) {
  157502. ptrin = input_buf[row];
  157503. ptrout = output_buf[row];
  157504. for (col = width; col > 0; col--) {
  157505. pixcode = 0;
  157506. for (ci = 0; ci < nc; ci++) {
  157507. pixcode += GETJSAMPLE(colorindex[ci][GETJSAMPLE(*ptrin++)]);
  157508. }
  157509. *ptrout++ = (JSAMPLE) pixcode;
  157510. }
  157511. }
  157512. }
  157513. METHODDEF(void)
  157514. color_quantize3 (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157515. JSAMPARRAY output_buf, int num_rows)
  157516. {
  157517. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157518. register int pixcode;
  157519. register JSAMPROW ptrin, ptrout;
  157520. JSAMPROW colorindex0 = cquantize->colorindex[0];
  157521. JSAMPROW colorindex1 = cquantize->colorindex[1];
  157522. JSAMPROW colorindex2 = cquantize->colorindex[2];
  157523. int row;
  157524. JDIMENSION col;
  157525. JDIMENSION width = cinfo->output_width;
  157526. for (row = 0; row < num_rows; row++) {
  157527. ptrin = input_buf[row];
  157528. ptrout = output_buf[row];
  157529. for (col = width; col > 0; col--) {
  157530. pixcode = GETJSAMPLE(colorindex0[GETJSAMPLE(*ptrin++)]);
  157531. pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*ptrin++)]);
  157532. pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*ptrin++)]);
  157533. *ptrout++ = (JSAMPLE) pixcode;
  157534. }
  157535. }
  157536. }
  157537. METHODDEF(void)
  157538. quantize_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157539. JSAMPARRAY output_buf, int num_rows)
  157540. {
  157541. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157542. register JSAMPROW input_ptr;
  157543. register JSAMPROW output_ptr;
  157544. JSAMPROW colorindex_ci;
  157545. int * dither; /* points to active row of dither matrix */
  157546. int row_index, col_index; /* current indexes into dither matrix */
  157547. int nc = cinfo->out_color_components;
  157548. int ci;
  157549. int row;
  157550. JDIMENSION col;
  157551. JDIMENSION width = cinfo->output_width;
  157552. for (row = 0; row < num_rows; row++) {
  157553. jzero_far((void FAR *) output_buf[row],
  157554. (size_t) (width * SIZEOF(JSAMPLE)));
  157555. row_index = cquantize->row_index;
  157556. for (ci = 0; ci < nc; ci++) {
  157557. input_ptr = input_buf[row] + ci;
  157558. output_ptr = output_buf[row];
  157559. colorindex_ci = cquantize->colorindex[ci];
  157560. dither = cquantize->odither[ci][row_index];
  157561. col_index = 0;
  157562. for (col = width; col > 0; col--) {
  157563. *output_ptr += colorindex_ci[GETJSAMPLE(*input_ptr)+dither[col_index]];
  157564. input_ptr += nc;
  157565. output_ptr++;
  157566. col_index = (col_index + 1) & ODITHER_MASK;
  157567. }
  157568. }
  157569. row_index = (row_index + 1) & ODITHER_MASK;
  157570. cquantize->row_index = row_index;
  157571. }
  157572. }
  157573. METHODDEF(void)
  157574. quantize3_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157575. JSAMPARRAY output_buf, int num_rows)
  157576. {
  157577. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157578. register int pixcode;
  157579. register JSAMPROW input_ptr;
  157580. register JSAMPROW output_ptr;
  157581. JSAMPROW colorindex0 = cquantize->colorindex[0];
  157582. JSAMPROW colorindex1 = cquantize->colorindex[1];
  157583. JSAMPROW colorindex2 = cquantize->colorindex[2];
  157584. int * dither0; /* points to active row of dither matrix */
  157585. int * dither1;
  157586. int * dither2;
  157587. int row_index, col_index; /* current indexes into dither matrix */
  157588. int row;
  157589. JDIMENSION col;
  157590. JDIMENSION width = cinfo->output_width;
  157591. for (row = 0; row < num_rows; row++) {
  157592. row_index = cquantize->row_index;
  157593. input_ptr = input_buf[row];
  157594. output_ptr = output_buf[row];
  157595. dither0 = cquantize->odither[0][row_index];
  157596. dither1 = cquantize->odither[1][row_index];
  157597. dither2 = cquantize->odither[2][row_index];
  157598. col_index = 0;
  157599. for (col = width; col > 0; col--) {
  157600. pixcode = GETJSAMPLE(colorindex0[GETJSAMPLE(*input_ptr++) +
  157601. dither0[col_index]]);
  157602. pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*input_ptr++) +
  157603. dither1[col_index]]);
  157604. pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*input_ptr++) +
  157605. dither2[col_index]]);
  157606. *output_ptr++ = (JSAMPLE) pixcode;
  157607. col_index = (col_index + 1) & ODITHER_MASK;
  157608. }
  157609. row_index = (row_index + 1) & ODITHER_MASK;
  157610. cquantize->row_index = row_index;
  157611. }
  157612. }
  157613. METHODDEF(void)
  157614. quantize_fs_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157615. JSAMPARRAY output_buf, int num_rows)
  157616. {
  157617. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157618. register LOCFSERROR cur; /* current error or pixel value */
  157619. LOCFSERROR belowerr; /* error for pixel below cur */
  157620. LOCFSERROR bpreverr; /* error for below/prev col */
  157621. LOCFSERROR bnexterr; /* error for below/next col */
  157622. LOCFSERROR delta;
  157623. register FSERRPTR errorptr; /* => fserrors[] at column before current */
  157624. register JSAMPROW input_ptr;
  157625. register JSAMPROW output_ptr;
  157626. JSAMPROW colorindex_ci;
  157627. JSAMPROW colormap_ci;
  157628. int pixcode;
  157629. int nc = cinfo->out_color_components;
  157630. int dir; /* 1 for left-to-right, -1 for right-to-left */
  157631. int dirnc; /* dir * nc */
  157632. int ci;
  157633. int row;
  157634. JDIMENSION col;
  157635. JDIMENSION width = cinfo->output_width;
  157636. JSAMPLE *range_limit = cinfo->sample_range_limit;
  157637. SHIFT_TEMPS
  157638. for (row = 0; row < num_rows; row++) {
  157639. jzero_far((void FAR *) output_buf[row],
  157640. (size_t) (width * SIZEOF(JSAMPLE)));
  157641. for (ci = 0; ci < nc; ci++) {
  157642. input_ptr = input_buf[row] + ci;
  157643. output_ptr = output_buf[row];
  157644. if (cquantize->on_odd_row) {
  157645. input_ptr += (width-1) * nc; /* so point to rightmost pixel */
  157646. output_ptr += width-1;
  157647. dir = -1;
  157648. dirnc = -nc;
  157649. errorptr = cquantize->fserrors[ci] + (width+1); /* => entry after last column */
  157650. } else {
  157651. dir = 1;
  157652. dirnc = nc;
  157653. errorptr = cquantize->fserrors[ci]; /* => entry before first column */
  157654. }
  157655. colorindex_ci = cquantize->colorindex[ci];
  157656. colormap_ci = cquantize->sv_colormap[ci];
  157657. cur = 0;
  157658. belowerr = bpreverr = 0;
  157659. for (col = width; col > 0; col--) {
  157660. cur = RIGHT_SHIFT(cur + errorptr[dir] + 8, 4);
  157661. cur += GETJSAMPLE(*input_ptr);
  157662. cur = GETJSAMPLE(range_limit[cur]);
  157663. pixcode = GETJSAMPLE(colorindex_ci[cur]);
  157664. *output_ptr += (JSAMPLE) pixcode;
  157665. cur -= GETJSAMPLE(colormap_ci[pixcode]);
  157666. bnexterr = cur;
  157667. delta = cur * 2;
  157668. cur += delta; /* form error * 3 */
  157669. errorptr[0] = (FSERROR) (bpreverr + cur);
  157670. cur += delta; /* form error * 5 */
  157671. bpreverr = belowerr + cur;
  157672. belowerr = bnexterr;
  157673. cur += delta; /* form error * 7 */
  157674. input_ptr += dirnc; /* advance input ptr to next column */
  157675. output_ptr += dir; /* advance output ptr to next column */
  157676. errorptr += dir; /* advance errorptr to current column */
  157677. }
  157678. errorptr[0] = (FSERROR) bpreverr; /* unload prev err into array */
  157679. }
  157680. cquantize->on_odd_row = (cquantize->on_odd_row ? FALSE : TRUE);
  157681. }
  157682. }
  157683. LOCAL(void)
  157684. alloc_fs_workspace (j_decompress_ptr cinfo)
  157685. {
  157686. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157687. size_t arraysize;
  157688. int i;
  157689. arraysize = (size_t) ((cinfo->output_width + 2) * SIZEOF(FSERROR));
  157690. for (i = 0; i < cinfo->out_color_components; i++) {
  157691. cquantize->fserrors[i] = (FSERRPTR)
  157692. (*cinfo->mem->alloc_large)((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize);
  157693. }
  157694. }
  157695. METHODDEF(void)
  157696. start_pass_1_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
  157697. {
  157698. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157699. size_t arraysize;
  157700. int i;
  157701. cinfo->colormap = cquantize->sv_colormap;
  157702. cinfo->actual_number_of_colors = cquantize->sv_actual;
  157703. switch (cinfo->dither_mode) {
  157704. case JDITHER_NONE:
  157705. if (cinfo->out_color_components == 3)
  157706. cquantize->pub.color_quantize = color_quantize3;
  157707. else
  157708. cquantize->pub.color_quantize = color_quantize;
  157709. break;
  157710. case JDITHER_ORDERED:
  157711. if (cinfo->out_color_components == 3)
  157712. cquantize->pub.color_quantize = quantize3_ord_dither;
  157713. else
  157714. cquantize->pub.color_quantize = quantize_ord_dither;
  157715. cquantize->row_index = 0; /* initialize state for ordered dither */
  157716. if (! cquantize->is_padded)
  157717. create_colorindex(cinfo);
  157718. if (cquantize->odither[0] == NULL)
  157719. create_odither_tables(cinfo);
  157720. break;
  157721. case JDITHER_FS:
  157722. cquantize->pub.color_quantize = quantize_fs_dither;
  157723. cquantize->on_odd_row = FALSE; /* initialize state for F-S dither */
  157724. if (cquantize->fserrors[0] == NULL)
  157725. alloc_fs_workspace(cinfo);
  157726. arraysize = (size_t) ((cinfo->output_width + 2) * SIZEOF(FSERROR));
  157727. for (i = 0; i < cinfo->out_color_components; i++)
  157728. jzero_far((void FAR *) cquantize->fserrors[i], arraysize);
  157729. break;
  157730. default:
  157731. ERREXIT(cinfo, JERR_NOT_COMPILED);
  157732. break;
  157733. }
  157734. }
  157735. METHODDEF(void)
  157736. finish_pass_1_quant (j_decompress_ptr cinfo)
  157737. {
  157738. }
  157739. METHODDEF(void)
  157740. new_color_map_1_quant (j_decompress_ptr cinfo)
  157741. {
  157742. ERREXIT(cinfo, JERR_MODE_CHANGE);
  157743. }
  157744. GLOBAL(void)
  157745. jinit_1pass_quantizer (j_decompress_ptr cinfo)
  157746. {
  157747. my_cquantize_ptr cquantize;
  157748. cquantize = (my_cquantize_ptr)
  157749. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157750. SIZEOF(my_cquantizer));
  157751. cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize;
  157752. cquantize->pub.start_pass = start_pass_1_quant;
  157753. cquantize->pub.finish_pass = finish_pass_1_quant;
  157754. cquantize->pub.new_color_map = new_color_map_1_quant;
  157755. cquantize->fserrors[0] = NULL; /* Flag FS workspace not allocated */
  157756. cquantize->odither[0] = NULL; /* Also flag odither arrays not allocated */
  157757. if (cinfo->out_color_components > MAX_Q_COMPS)
  157758. ERREXIT1(cinfo, JERR_QUANT_COMPONENTS, MAX_Q_COMPS);
  157759. if (cinfo->desired_number_of_colors > (MAXJSAMPLE+1))
  157760. ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXJSAMPLE+1);
  157761. create_colormap(cinfo);
  157762. create_colorindex(cinfo);
  157763. if (cinfo->dither_mode == JDITHER_FS)
  157764. alloc_fs_workspace(cinfo);
  157765. }
  157766. #endif /* QUANT_1PASS_SUPPORTED */
  157767. /*** End of inlined file: jquant1.c ***/
  157768. /*** Start of inlined file: jquant2.c ***/
  157769. #define JPEG_INTERNALS
  157770. #ifdef QUANT_2PASS_SUPPORTED
  157771. #define R_SCALE 2 /* scale R distances by this much */
  157772. #define G_SCALE 3 /* scale G distances by this much */
  157773. #define B_SCALE 1 /* and B by this much */
  157774. #if RGB_RED == 0
  157775. #define C0_SCALE R_SCALE
  157776. #endif
  157777. #if RGB_BLUE == 0
  157778. #define C0_SCALE B_SCALE
  157779. #endif
  157780. #if RGB_GREEN == 1
  157781. #define C1_SCALE G_SCALE
  157782. #endif
  157783. #if RGB_RED == 2
  157784. #define C2_SCALE R_SCALE
  157785. #endif
  157786. #if RGB_BLUE == 2
  157787. #define C2_SCALE B_SCALE
  157788. #endif
  157789. #define MAXNUMCOLORS (MAXJSAMPLE+1) /* maximum size of colormap */
  157790. #define HIST_C0_BITS 5 /* bits of precision in R/B histogram */
  157791. #define HIST_C1_BITS 6 /* bits of precision in G histogram */
  157792. #define HIST_C2_BITS 5 /* bits of precision in B/R histogram */
  157793. #define HIST_C0_ELEMS (1<<HIST_C0_BITS)
  157794. #define HIST_C1_ELEMS (1<<HIST_C1_BITS)
  157795. #define HIST_C2_ELEMS (1<<HIST_C2_BITS)
  157796. #define C0_SHIFT (BITS_IN_JSAMPLE-HIST_C0_BITS)
  157797. #define C1_SHIFT (BITS_IN_JSAMPLE-HIST_C1_BITS)
  157798. #define C2_SHIFT (BITS_IN_JSAMPLE-HIST_C2_BITS)
  157799. typedef UINT16 histcell; /* histogram cell; prefer an unsigned type */
  157800. typedef histcell FAR * histptr; /* for pointers to histogram cells */
  157801. typedef histcell hist1d[HIST_C2_ELEMS]; /* typedefs for the array */
  157802. typedef hist1d FAR * hist2d; /* type for the 2nd-level pointers */
  157803. typedef hist2d * hist3d; /* type for top-level pointer */
  157804. #if BITS_IN_JSAMPLE == 8
  157805. typedef INT16 FSERROR; /* 16 bits should be enough */
  157806. typedef int LOCFSERROR; /* use 'int' for calculation temps */
  157807. #else
  157808. typedef INT32 FSERROR; /* may need more than 16 bits */
  157809. typedef INT32 LOCFSERROR; /* be sure calculation temps are big enough */
  157810. #endif
  157811. typedef FSERROR FAR *FSERRPTR; /* pointer to error array (in FAR storage!) */
  157812. typedef struct {
  157813. struct jpeg_color_quantizer pub; /* public fields */
  157814. JSAMPARRAY sv_colormap; /* colormap allocated at init time */
  157815. int desired; /* desired # of colors = size of colormap */
  157816. hist3d histogram; /* pointer to the histogram */
  157817. boolean needs_zeroed; /* TRUE if next pass must zero histogram */
  157818. FSERRPTR fserrors; /* accumulated errors */
  157819. boolean on_odd_row; /* flag to remember which row we are on */
  157820. int * error_limiter; /* table for clamping the applied error */
  157821. } my_cquantizer2;
  157822. typedef my_cquantizer2 * my_cquantize_ptr2;
  157823. METHODDEF(void)
  157824. prescan_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157825. JSAMPARRAY output_buf, int num_rows)
  157826. {
  157827. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157828. register JSAMPROW ptr;
  157829. register histptr histp;
  157830. register hist3d histogram = cquantize->histogram;
  157831. int row;
  157832. JDIMENSION col;
  157833. JDIMENSION width = cinfo->output_width;
  157834. for (row = 0; row < num_rows; row++) {
  157835. ptr = input_buf[row];
  157836. for (col = width; col > 0; col--) {
  157837. histp = & histogram[GETJSAMPLE(ptr[0]) >> C0_SHIFT]
  157838. [GETJSAMPLE(ptr[1]) >> C1_SHIFT]
  157839. [GETJSAMPLE(ptr[2]) >> C2_SHIFT];
  157840. if (++(*histp) <= 0)
  157841. (*histp)--;
  157842. ptr += 3;
  157843. }
  157844. }
  157845. }
  157846. typedef struct {
  157847. int c0min, c0max;
  157848. int c1min, c1max;
  157849. int c2min, c2max;
  157850. INT32 volume;
  157851. long colorcount;
  157852. } box;
  157853. typedef box * boxptr;
  157854. LOCAL(boxptr)
  157855. find_biggest_color_pop (boxptr boxlist, int numboxes)
  157856. {
  157857. register boxptr boxp;
  157858. register int i;
  157859. register long maxc = 0;
  157860. boxptr which = NULL;
  157861. for (i = 0, boxp = boxlist; i < numboxes; i++, boxp++) {
  157862. if (boxp->colorcount > maxc && boxp->volume > 0) {
  157863. which = boxp;
  157864. maxc = boxp->colorcount;
  157865. }
  157866. }
  157867. return which;
  157868. }
  157869. LOCAL(boxptr)
  157870. find_biggest_volume (boxptr boxlist, int numboxes)
  157871. {
  157872. register boxptr boxp;
  157873. register int i;
  157874. register INT32 maxv = 0;
  157875. boxptr which = NULL;
  157876. for (i = 0, boxp = boxlist; i < numboxes; i++, boxp++) {
  157877. if (boxp->volume > maxv) {
  157878. which = boxp;
  157879. maxv = boxp->volume;
  157880. }
  157881. }
  157882. return which;
  157883. }
  157884. LOCAL(void)
  157885. update_box (j_decompress_ptr cinfo, boxptr boxp)
  157886. {
  157887. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157888. hist3d histogram = cquantize->histogram;
  157889. histptr histp;
  157890. int c0,c1,c2;
  157891. int c0min,c0max,c1min,c1max,c2min,c2max;
  157892. INT32 dist0,dist1,dist2;
  157893. long ccount;
  157894. c0min = boxp->c0min; c0max = boxp->c0max;
  157895. c1min = boxp->c1min; c1max = boxp->c1max;
  157896. c2min = boxp->c2min; c2max = boxp->c2max;
  157897. if (c0max > c0min)
  157898. for (c0 = c0min; c0 <= c0max; c0++)
  157899. for (c1 = c1min; c1 <= c1max; c1++) {
  157900. histp = & histogram[c0][c1][c2min];
  157901. for (c2 = c2min; c2 <= c2max; c2++)
  157902. if (*histp++ != 0) {
  157903. boxp->c0min = c0min = c0;
  157904. goto have_c0min;
  157905. }
  157906. }
  157907. have_c0min:
  157908. if (c0max > c0min)
  157909. for (c0 = c0max; c0 >= c0min; c0--)
  157910. for (c1 = c1min; c1 <= c1max; c1++) {
  157911. histp = & histogram[c0][c1][c2min];
  157912. for (c2 = c2min; c2 <= c2max; c2++)
  157913. if (*histp++ != 0) {
  157914. boxp->c0max = c0max = c0;
  157915. goto have_c0max;
  157916. }
  157917. }
  157918. have_c0max:
  157919. if (c1max > c1min)
  157920. for (c1 = c1min; c1 <= c1max; c1++)
  157921. for (c0 = c0min; c0 <= c0max; c0++) {
  157922. histp = & histogram[c0][c1][c2min];
  157923. for (c2 = c2min; c2 <= c2max; c2++)
  157924. if (*histp++ != 0) {
  157925. boxp->c1min = c1min = c1;
  157926. goto have_c1min;
  157927. }
  157928. }
  157929. have_c1min:
  157930. if (c1max > c1min)
  157931. for (c1 = c1max; c1 >= c1min; c1--)
  157932. for (c0 = c0min; c0 <= c0max; c0++) {
  157933. histp = & histogram[c0][c1][c2min];
  157934. for (c2 = c2min; c2 <= c2max; c2++)
  157935. if (*histp++ != 0) {
  157936. boxp->c1max = c1max = c1;
  157937. goto have_c1max;
  157938. }
  157939. }
  157940. have_c1max:
  157941. if (c2max > c2min)
  157942. for (c2 = c2min; c2 <= c2max; c2++)
  157943. for (c0 = c0min; c0 <= c0max; c0++) {
  157944. histp = & histogram[c0][c1min][c2];
  157945. for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS)
  157946. if (*histp != 0) {
  157947. boxp->c2min = c2min = c2;
  157948. goto have_c2min;
  157949. }
  157950. }
  157951. have_c2min:
  157952. if (c2max > c2min)
  157953. for (c2 = c2max; c2 >= c2min; c2--)
  157954. for (c0 = c0min; c0 <= c0max; c0++) {
  157955. histp = & histogram[c0][c1min][c2];
  157956. for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS)
  157957. if (*histp != 0) {
  157958. boxp->c2max = c2max = c2;
  157959. goto have_c2max;
  157960. }
  157961. }
  157962. have_c2max:
  157963. dist0 = ((c0max - c0min) << C0_SHIFT) * C0_SCALE;
  157964. dist1 = ((c1max - c1min) << C1_SHIFT) * C1_SCALE;
  157965. dist2 = ((c2max - c2min) << C2_SHIFT) * C2_SCALE;
  157966. boxp->volume = dist0*dist0 + dist1*dist1 + dist2*dist2;
  157967. ccount = 0;
  157968. for (c0 = c0min; c0 <= c0max; c0++)
  157969. for (c1 = c1min; c1 <= c1max; c1++) {
  157970. histp = & histogram[c0][c1][c2min];
  157971. for (c2 = c2min; c2 <= c2max; c2++, histp++)
  157972. if (*histp != 0) {
  157973. ccount++;
  157974. }
  157975. }
  157976. boxp->colorcount = ccount;
  157977. }
  157978. LOCAL(int)
  157979. median_cut (j_decompress_ptr cinfo, boxptr boxlist, int numboxes,
  157980. int desired_colors)
  157981. {
  157982. int n,lb;
  157983. int c0,c1,c2,cmax;
  157984. register boxptr b1,b2;
  157985. while (numboxes < desired_colors) {
  157986. if (numboxes*2 <= desired_colors) {
  157987. b1 = find_biggest_color_pop(boxlist, numboxes);
  157988. } else {
  157989. b1 = find_biggest_volume(boxlist, numboxes);
  157990. }
  157991. if (b1 == NULL) /* no splittable boxes left! */
  157992. break;
  157993. b2 = &boxlist[numboxes]; /* where new box will go */
  157994. b2->c0max = b1->c0max; b2->c1max = b1->c1max; b2->c2max = b1->c2max;
  157995. b2->c0min = b1->c0min; b2->c1min = b1->c1min; b2->c2min = b1->c2min;
  157996. c0 = ((b1->c0max - b1->c0min) << C0_SHIFT) * C0_SCALE;
  157997. c1 = ((b1->c1max - b1->c1min) << C1_SHIFT) * C1_SCALE;
  157998. c2 = ((b1->c2max - b1->c2min) << C2_SHIFT) * C2_SCALE;
  157999. #if RGB_RED == 0
  158000. cmax = c1; n = 1;
  158001. if (c0 > cmax) { cmax = c0; n = 0; }
  158002. if (c2 > cmax) { n = 2; }
  158003. #else
  158004. cmax = c1; n = 1;
  158005. if (c2 > cmax) { cmax = c2; n = 2; }
  158006. if (c0 > cmax) { n = 0; }
  158007. #endif
  158008. switch (n) {
  158009. case 0:
  158010. lb = (b1->c0max + b1->c0min) / 2;
  158011. b1->c0max = lb;
  158012. b2->c0min = lb+1;
  158013. break;
  158014. case 1:
  158015. lb = (b1->c1max + b1->c1min) / 2;
  158016. b1->c1max = lb;
  158017. b2->c1min = lb+1;
  158018. break;
  158019. case 2:
  158020. lb = (b1->c2max + b1->c2min) / 2;
  158021. b1->c2max = lb;
  158022. b2->c2min = lb+1;
  158023. break;
  158024. }
  158025. update_box(cinfo, b1);
  158026. update_box(cinfo, b2);
  158027. numboxes++;
  158028. }
  158029. return numboxes;
  158030. }
  158031. LOCAL(void)
  158032. compute_color (j_decompress_ptr cinfo, boxptr boxp, int icolor)
  158033. {
  158034. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158035. hist3d histogram = cquantize->histogram;
  158036. histptr histp;
  158037. int c0,c1,c2;
  158038. int c0min,c0max,c1min,c1max,c2min,c2max;
  158039. long count;
  158040. long total = 0;
  158041. long c0total = 0;
  158042. long c1total = 0;
  158043. long c2total = 0;
  158044. c0min = boxp->c0min; c0max = boxp->c0max;
  158045. c1min = boxp->c1min; c1max = boxp->c1max;
  158046. c2min = boxp->c2min; c2max = boxp->c2max;
  158047. for (c0 = c0min; c0 <= c0max; c0++)
  158048. for (c1 = c1min; c1 <= c1max; c1++) {
  158049. histp = & histogram[c0][c1][c2min];
  158050. for (c2 = c2min; c2 <= c2max; c2++) {
  158051. if ((count = *histp++) != 0) {
  158052. total += count;
  158053. c0total += ((c0 << C0_SHIFT) + ((1<<C0_SHIFT)>>1)) * count;
  158054. c1total += ((c1 << C1_SHIFT) + ((1<<C1_SHIFT)>>1)) * count;
  158055. c2total += ((c2 << C2_SHIFT) + ((1<<C2_SHIFT)>>1)) * count;
  158056. }
  158057. }
  158058. }
  158059. cinfo->colormap[0][icolor] = (JSAMPLE) ((c0total + (total>>1)) / total);
  158060. cinfo->colormap[1][icolor] = (JSAMPLE) ((c1total + (total>>1)) / total);
  158061. cinfo->colormap[2][icolor] = (JSAMPLE) ((c2total + (total>>1)) / total);
  158062. }
  158063. LOCAL(void)
  158064. select_colors (j_decompress_ptr cinfo, int desired_colors)
  158065. {
  158066. boxptr boxlist;
  158067. int numboxes;
  158068. int i;
  158069. boxlist = (boxptr) (*cinfo->mem->alloc_small)
  158070. ((j_common_ptr) cinfo, JPOOL_IMAGE, desired_colors * SIZEOF(box));
  158071. numboxes = 1;
  158072. boxlist[0].c0min = 0;
  158073. boxlist[0].c0max = MAXJSAMPLE >> C0_SHIFT;
  158074. boxlist[0].c1min = 0;
  158075. boxlist[0].c1max = MAXJSAMPLE >> C1_SHIFT;
  158076. boxlist[0].c2min = 0;
  158077. boxlist[0].c2max = MAXJSAMPLE >> C2_SHIFT;
  158078. update_box(cinfo, & boxlist[0]);
  158079. numboxes = median_cut(cinfo, boxlist, numboxes, desired_colors);
  158080. for (i = 0; i < numboxes; i++)
  158081. compute_color(cinfo, & boxlist[i], i);
  158082. cinfo->actual_number_of_colors = numboxes;
  158083. TRACEMS1(cinfo, 1, JTRC_QUANT_SELECTED, numboxes);
  158084. }
  158085. #define BOX_C0_LOG (HIST_C0_BITS-3)
  158086. #define BOX_C1_LOG (HIST_C1_BITS-3)
  158087. #define BOX_C2_LOG (HIST_C2_BITS-3)
  158088. #define BOX_C0_ELEMS (1<<BOX_C0_LOG) /* # of hist cells in update box */
  158089. #define BOX_C1_ELEMS (1<<BOX_C1_LOG)
  158090. #define BOX_C2_ELEMS (1<<BOX_C2_LOG)
  158091. #define BOX_C0_SHIFT (C0_SHIFT + BOX_C0_LOG)
  158092. #define BOX_C1_SHIFT (C1_SHIFT + BOX_C1_LOG)
  158093. #define BOX_C2_SHIFT (C2_SHIFT + BOX_C2_LOG)
  158094. LOCAL(int)
  158095. find_nearby_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
  158096. JSAMPLE colorlist[])
  158097. {
  158098. int numcolors = cinfo->actual_number_of_colors;
  158099. int maxc0, maxc1, maxc2;
  158100. int centerc0, centerc1, centerc2;
  158101. int i, x, ncolors;
  158102. INT32 minmaxdist, min_dist, max_dist, tdist;
  158103. INT32 mindist[MAXNUMCOLORS]; /* min distance to colormap entry i */
  158104. maxc0 = minc0 + ((1 << BOX_C0_SHIFT) - (1 << C0_SHIFT));
  158105. centerc0 = (minc0 + maxc0) >> 1;
  158106. maxc1 = minc1 + ((1 << BOX_C1_SHIFT) - (1 << C1_SHIFT));
  158107. centerc1 = (minc1 + maxc1) >> 1;
  158108. maxc2 = minc2 + ((1 << BOX_C2_SHIFT) - (1 << C2_SHIFT));
  158109. centerc2 = (minc2 + maxc2) >> 1;
  158110. minmaxdist = 0x7FFFFFFFL;
  158111. for (i = 0; i < numcolors; i++) {
  158112. x = GETJSAMPLE(cinfo->colormap[0][i]);
  158113. if (x < minc0) {
  158114. tdist = (x - minc0) * C0_SCALE;
  158115. min_dist = tdist*tdist;
  158116. tdist = (x - maxc0) * C0_SCALE;
  158117. max_dist = tdist*tdist;
  158118. } else if (x > maxc0) {
  158119. tdist = (x - maxc0) * C0_SCALE;
  158120. min_dist = tdist*tdist;
  158121. tdist = (x - minc0) * C0_SCALE;
  158122. max_dist = tdist*tdist;
  158123. } else {
  158124. min_dist = 0;
  158125. if (x <= centerc0) {
  158126. tdist = (x - maxc0) * C0_SCALE;
  158127. max_dist = tdist*tdist;
  158128. } else {
  158129. tdist = (x - minc0) * C0_SCALE;
  158130. max_dist = tdist*tdist;
  158131. }
  158132. }
  158133. x = GETJSAMPLE(cinfo->colormap[1][i]);
  158134. if (x < minc1) {
  158135. tdist = (x - minc1) * C1_SCALE;
  158136. min_dist += tdist*tdist;
  158137. tdist = (x - maxc1) * C1_SCALE;
  158138. max_dist += tdist*tdist;
  158139. } else if (x > maxc1) {
  158140. tdist = (x - maxc1) * C1_SCALE;
  158141. min_dist += tdist*tdist;
  158142. tdist = (x - minc1) * C1_SCALE;
  158143. max_dist += tdist*tdist;
  158144. } else {
  158145. if (x <= centerc1) {
  158146. tdist = (x - maxc1) * C1_SCALE;
  158147. max_dist += tdist*tdist;
  158148. } else {
  158149. tdist = (x - minc1) * C1_SCALE;
  158150. max_dist += tdist*tdist;
  158151. }
  158152. }
  158153. x = GETJSAMPLE(cinfo->colormap[2][i]);
  158154. if (x < minc2) {
  158155. tdist = (x - minc2) * C2_SCALE;
  158156. min_dist += tdist*tdist;
  158157. tdist = (x - maxc2) * C2_SCALE;
  158158. max_dist += tdist*tdist;
  158159. } else if (x > maxc2) {
  158160. tdist = (x - maxc2) * C2_SCALE;
  158161. min_dist += tdist*tdist;
  158162. tdist = (x - minc2) * C2_SCALE;
  158163. max_dist += tdist*tdist;
  158164. } else {
  158165. if (x <= centerc2) {
  158166. tdist = (x - maxc2) * C2_SCALE;
  158167. max_dist += tdist*tdist;
  158168. } else {
  158169. tdist = (x - minc2) * C2_SCALE;
  158170. max_dist += tdist*tdist;
  158171. }
  158172. }
  158173. mindist[i] = min_dist; /* save away the results */
  158174. if (max_dist < minmaxdist)
  158175. minmaxdist = max_dist;
  158176. }
  158177. ncolors = 0;
  158178. for (i = 0; i < numcolors; i++) {
  158179. if (mindist[i] <= minmaxdist)
  158180. colorlist[ncolors++] = (JSAMPLE) i;
  158181. }
  158182. return ncolors;
  158183. }
  158184. LOCAL(void)
  158185. find_best_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
  158186. int numcolors, JSAMPLE colorlist[], JSAMPLE bestcolor[])
  158187. {
  158188. int ic0, ic1, ic2;
  158189. int i, icolor;
  158190. register INT32 * bptr; /* pointer into bestdist[] array */
  158191. JSAMPLE * cptr; /* pointer into bestcolor[] array */
  158192. INT32 dist0, dist1; /* initial distance values */
  158193. register INT32 dist2; /* current distance in inner loop */
  158194. INT32 xx0, xx1; /* distance increments */
  158195. register INT32 xx2;
  158196. INT32 inc0, inc1, inc2; /* initial values for increments */
  158197. INT32 bestdist[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS];
  158198. bptr = bestdist;
  158199. for (i = BOX_C0_ELEMS*BOX_C1_ELEMS*BOX_C2_ELEMS-1; i >= 0; i--)
  158200. *bptr++ = 0x7FFFFFFFL;
  158201. #define STEP_C0 ((1 << C0_SHIFT) * C0_SCALE)
  158202. #define STEP_C1 ((1 << C1_SHIFT) * C1_SCALE)
  158203. #define STEP_C2 ((1 << C2_SHIFT) * C2_SCALE)
  158204. for (i = 0; i < numcolors; i++) {
  158205. icolor = GETJSAMPLE(colorlist[i]);
  158206. inc0 = (minc0 - GETJSAMPLE(cinfo->colormap[0][icolor])) * C0_SCALE;
  158207. dist0 = inc0*inc0;
  158208. inc1 = (minc1 - GETJSAMPLE(cinfo->colormap[1][icolor])) * C1_SCALE;
  158209. dist0 += inc1*inc1;
  158210. inc2 = (minc2 - GETJSAMPLE(cinfo->colormap[2][icolor])) * C2_SCALE;
  158211. dist0 += inc2*inc2;
  158212. inc0 = inc0 * (2 * STEP_C0) + STEP_C0 * STEP_C0;
  158213. inc1 = inc1 * (2 * STEP_C1) + STEP_C1 * STEP_C1;
  158214. inc2 = inc2 * (2 * STEP_C2) + STEP_C2 * STEP_C2;
  158215. bptr = bestdist;
  158216. cptr = bestcolor;
  158217. xx0 = inc0;
  158218. for (ic0 = BOX_C0_ELEMS-1; ic0 >= 0; ic0--) {
  158219. dist1 = dist0;
  158220. xx1 = inc1;
  158221. for (ic1 = BOX_C1_ELEMS-1; ic1 >= 0; ic1--) {
  158222. dist2 = dist1;
  158223. xx2 = inc2;
  158224. for (ic2 = BOX_C2_ELEMS-1; ic2 >= 0; ic2--) {
  158225. if (dist2 < *bptr) {
  158226. *bptr = dist2;
  158227. *cptr = (JSAMPLE) icolor;
  158228. }
  158229. dist2 += xx2;
  158230. xx2 += 2 * STEP_C2 * STEP_C2;
  158231. bptr++;
  158232. cptr++;
  158233. }
  158234. dist1 += xx1;
  158235. xx1 += 2 * STEP_C1 * STEP_C1;
  158236. }
  158237. dist0 += xx0;
  158238. xx0 += 2 * STEP_C0 * STEP_C0;
  158239. }
  158240. }
  158241. }
  158242. LOCAL(void)
  158243. fill_inverse_cmap (j_decompress_ptr cinfo, int c0, int c1, int c2)
  158244. {
  158245. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158246. hist3d histogram = cquantize->histogram;
  158247. int minc0, minc1, minc2; /* lower left corner of update box */
  158248. int ic0, ic1, ic2;
  158249. register JSAMPLE * cptr; /* pointer into bestcolor[] array */
  158250. register histptr cachep; /* pointer into main cache array */
  158251. JSAMPLE colorlist[MAXNUMCOLORS];
  158252. int numcolors; /* number of candidate colors */
  158253. JSAMPLE bestcolor[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS];
  158254. c0 >>= BOX_C0_LOG;
  158255. c1 >>= BOX_C1_LOG;
  158256. c2 >>= BOX_C2_LOG;
  158257. minc0 = (c0 << BOX_C0_SHIFT) + ((1 << C0_SHIFT) >> 1);
  158258. minc1 = (c1 << BOX_C1_SHIFT) + ((1 << C1_SHIFT) >> 1);
  158259. minc2 = (c2 << BOX_C2_SHIFT) + ((1 << C2_SHIFT) >> 1);
  158260. numcolors = find_nearby_colors(cinfo, minc0, minc1, minc2, colorlist);
  158261. find_best_colors(cinfo, minc0, minc1, minc2, numcolors, colorlist,
  158262. bestcolor);
  158263. c0 <<= BOX_C0_LOG; /* convert ID back to base cell indexes */
  158264. c1 <<= BOX_C1_LOG;
  158265. c2 <<= BOX_C2_LOG;
  158266. cptr = bestcolor;
  158267. for (ic0 = 0; ic0 < BOX_C0_ELEMS; ic0++) {
  158268. for (ic1 = 0; ic1 < BOX_C1_ELEMS; ic1++) {
  158269. cachep = & histogram[c0+ic0][c1+ic1][c2];
  158270. for (ic2 = 0; ic2 < BOX_C2_ELEMS; ic2++) {
  158271. *cachep++ = (histcell) (GETJSAMPLE(*cptr++) + 1);
  158272. }
  158273. }
  158274. }
  158275. }
  158276. METHODDEF(void)
  158277. pass2_no_dither (j_decompress_ptr cinfo,
  158278. JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
  158279. {
  158280. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158281. hist3d histogram = cquantize->histogram;
  158282. register JSAMPROW inptr, outptr;
  158283. register histptr cachep;
  158284. register int c0, c1, c2;
  158285. int row;
  158286. JDIMENSION col;
  158287. JDIMENSION width = cinfo->output_width;
  158288. for (row = 0; row < num_rows; row++) {
  158289. inptr = input_buf[row];
  158290. outptr = output_buf[row];
  158291. for (col = width; col > 0; col--) {
  158292. c0 = GETJSAMPLE(*inptr++) >> C0_SHIFT;
  158293. c1 = GETJSAMPLE(*inptr++) >> C1_SHIFT;
  158294. c2 = GETJSAMPLE(*inptr++) >> C2_SHIFT;
  158295. cachep = & histogram[c0][c1][c2];
  158296. if (*cachep == 0)
  158297. fill_inverse_cmap(cinfo, c0,c1,c2);
  158298. *outptr++ = (JSAMPLE) (*cachep - 1);
  158299. }
  158300. }
  158301. }
  158302. METHODDEF(void)
  158303. pass2_fs_dither (j_decompress_ptr cinfo,
  158304. JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
  158305. {
  158306. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158307. hist3d histogram = cquantize->histogram;
  158308. register LOCFSERROR cur0, cur1, cur2; /* current error or pixel value */
  158309. LOCFSERROR belowerr0, belowerr1, belowerr2; /* error for pixel below cur */
  158310. LOCFSERROR bpreverr0, bpreverr1, bpreverr2; /* error for below/prev col */
  158311. register FSERRPTR errorptr; /* => fserrors[] at column before current */
  158312. JSAMPROW inptr; /* => current input pixel */
  158313. JSAMPROW outptr; /* => current output pixel */
  158314. histptr cachep;
  158315. int dir; /* +1 or -1 depending on direction */
  158316. int dir3; /* 3*dir, for advancing inptr & errorptr */
  158317. int row;
  158318. JDIMENSION col;
  158319. JDIMENSION width = cinfo->output_width;
  158320. JSAMPLE *range_limit = cinfo->sample_range_limit;
  158321. int *error_limit = cquantize->error_limiter;
  158322. JSAMPROW colormap0 = cinfo->colormap[0];
  158323. JSAMPROW colormap1 = cinfo->colormap[1];
  158324. JSAMPROW colormap2 = cinfo->colormap[2];
  158325. SHIFT_TEMPS
  158326. for (row = 0; row < num_rows; row++) {
  158327. inptr = input_buf[row];
  158328. outptr = output_buf[row];
  158329. if (cquantize->on_odd_row) {
  158330. inptr += (width-1) * 3; /* so point to rightmost pixel */
  158331. outptr += width-1;
  158332. dir = -1;
  158333. dir3 = -3;
  158334. errorptr = cquantize->fserrors + (width+1)*3; /* => entry after last column */
  158335. cquantize->on_odd_row = FALSE; /* flip for next time */
  158336. } else {
  158337. dir = 1;
  158338. dir3 = 3;
  158339. errorptr = cquantize->fserrors; /* => entry before first real column */
  158340. cquantize->on_odd_row = TRUE; /* flip for next time */
  158341. }
  158342. cur0 = cur1 = cur2 = 0;
  158343. belowerr0 = belowerr1 = belowerr2 = 0;
  158344. bpreverr0 = bpreverr1 = bpreverr2 = 0;
  158345. for (col = width; col > 0; col--) {
  158346. cur0 = RIGHT_SHIFT(cur0 + errorptr[dir3+0] + 8, 4);
  158347. cur1 = RIGHT_SHIFT(cur1 + errorptr[dir3+1] + 8, 4);
  158348. cur2 = RIGHT_SHIFT(cur2 + errorptr[dir3+2] + 8, 4);
  158349. cur0 = error_limit[cur0];
  158350. cur1 = error_limit[cur1];
  158351. cur2 = error_limit[cur2];
  158352. cur0 += GETJSAMPLE(inptr[0]);
  158353. cur1 += GETJSAMPLE(inptr[1]);
  158354. cur2 += GETJSAMPLE(inptr[2]);
  158355. cur0 = GETJSAMPLE(range_limit[cur0]);
  158356. cur1 = GETJSAMPLE(range_limit[cur1]);
  158357. cur2 = GETJSAMPLE(range_limit[cur2]);
  158358. cachep = & histogram[cur0>>C0_SHIFT][cur1>>C1_SHIFT][cur2>>C2_SHIFT];
  158359. if (*cachep == 0)
  158360. fill_inverse_cmap(cinfo, cur0>>C0_SHIFT,cur1>>C1_SHIFT,cur2>>C2_SHIFT);
  158361. { register int pixcode = *cachep - 1;
  158362. *outptr = (JSAMPLE) pixcode;
  158363. cur0 -= GETJSAMPLE(colormap0[pixcode]);
  158364. cur1 -= GETJSAMPLE(colormap1[pixcode]);
  158365. cur2 -= GETJSAMPLE(colormap2[pixcode]);
  158366. }
  158367. { register LOCFSERROR bnexterr, delta;
  158368. bnexterr = cur0; /* Process component 0 */
  158369. delta = cur0 * 2;
  158370. cur0 += delta; /* form error * 3 */
  158371. errorptr[0] = (FSERROR) (bpreverr0 + cur0);
  158372. cur0 += delta; /* form error * 5 */
  158373. bpreverr0 = belowerr0 + cur0;
  158374. belowerr0 = bnexterr;
  158375. cur0 += delta; /* form error * 7 */
  158376. bnexterr = cur1; /* Process component 1 */
  158377. delta = cur1 * 2;
  158378. cur1 += delta; /* form error * 3 */
  158379. errorptr[1] = (FSERROR) (bpreverr1 + cur1);
  158380. cur1 += delta; /* form error * 5 */
  158381. bpreverr1 = belowerr1 + cur1;
  158382. belowerr1 = bnexterr;
  158383. cur1 += delta; /* form error * 7 */
  158384. bnexterr = cur2; /* Process component 2 */
  158385. delta = cur2 * 2;
  158386. cur2 += delta; /* form error * 3 */
  158387. errorptr[2] = (FSERROR) (bpreverr2 + cur2);
  158388. cur2 += delta; /* form error * 5 */
  158389. bpreverr2 = belowerr2 + cur2;
  158390. belowerr2 = bnexterr;
  158391. cur2 += delta; /* form error * 7 */
  158392. }
  158393. inptr += dir3; /* Advance pixel pointers to next column */
  158394. outptr += dir;
  158395. errorptr += dir3; /* advance errorptr to current column */
  158396. }
  158397. errorptr[0] = (FSERROR) bpreverr0; /* unload prev errs into array */
  158398. errorptr[1] = (FSERROR) bpreverr1;
  158399. errorptr[2] = (FSERROR) bpreverr2;
  158400. }
  158401. }
  158402. LOCAL(void)
  158403. init_error_limit (j_decompress_ptr cinfo)
  158404. {
  158405. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158406. int * table;
  158407. int in, out;
  158408. table = (int *) (*cinfo->mem->alloc_small)
  158409. ((j_common_ptr) cinfo, JPOOL_IMAGE, (MAXJSAMPLE*2+1) * SIZEOF(int));
  158410. table += MAXJSAMPLE; /* so can index -MAXJSAMPLE .. +MAXJSAMPLE */
  158411. cquantize->error_limiter = table;
  158412. #define STEPSIZE ((MAXJSAMPLE+1)/16)
  158413. out = 0;
  158414. for (in = 0; in < STEPSIZE; in++, out++) {
  158415. table[in] = out; table[-in] = -out;
  158416. }
  158417. for (; in < STEPSIZE*3; in++, out += (in&1) ? 0 : 1) {
  158418. table[in] = out; table[-in] = -out;
  158419. }
  158420. for (; in <= MAXJSAMPLE; in++) {
  158421. table[in] = out; table[-in] = -out;
  158422. }
  158423. #undef STEPSIZE
  158424. }
  158425. METHODDEF(void)
  158426. finish_pass1 (j_decompress_ptr cinfo)
  158427. {
  158428. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158429. cinfo->colormap = cquantize->sv_colormap;
  158430. select_colors(cinfo, cquantize->desired);
  158431. cquantize->needs_zeroed = TRUE;
  158432. }
  158433. METHODDEF(void)
  158434. finish_pass2 (j_decompress_ptr cinfo)
  158435. {
  158436. }
  158437. METHODDEF(void)
  158438. start_pass_2_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
  158439. {
  158440. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158441. hist3d histogram = cquantize->histogram;
  158442. int i;
  158443. if (cinfo->dither_mode != JDITHER_NONE)
  158444. cinfo->dither_mode = JDITHER_FS;
  158445. if (is_pre_scan) {
  158446. cquantize->pub.color_quantize = prescan_quantize;
  158447. cquantize->pub.finish_pass = finish_pass1;
  158448. cquantize->needs_zeroed = TRUE; /* Always zero histogram */
  158449. } else {
  158450. if (cinfo->dither_mode == JDITHER_FS)
  158451. cquantize->pub.color_quantize = pass2_fs_dither;
  158452. else
  158453. cquantize->pub.color_quantize = pass2_no_dither;
  158454. cquantize->pub.finish_pass = finish_pass2;
  158455. i = cinfo->actual_number_of_colors;
  158456. if (i < 1)
  158457. ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, 1);
  158458. if (i > MAXNUMCOLORS)
  158459. ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);
  158460. if (cinfo->dither_mode == JDITHER_FS) {
  158461. size_t arraysize = (size_t) ((cinfo->output_width + 2) *
  158462. (3 * SIZEOF(FSERROR)));
  158463. if (cquantize->fserrors == NULL)
  158464. cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large)
  158465. ((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize);
  158466. jzero_far((void FAR *) cquantize->fserrors, arraysize);
  158467. if (cquantize->error_limiter == NULL)
  158468. init_error_limit(cinfo);
  158469. cquantize->on_odd_row = FALSE;
  158470. }
  158471. }
  158472. if (cquantize->needs_zeroed) {
  158473. for (i = 0; i < HIST_C0_ELEMS; i++) {
  158474. jzero_far((void FAR *) histogram[i],
  158475. HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell));
  158476. }
  158477. cquantize->needs_zeroed = FALSE;
  158478. }
  158479. }
  158480. METHODDEF(void)
  158481. new_color_map_2_quant (j_decompress_ptr cinfo)
  158482. {
  158483. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158484. cquantize->needs_zeroed = TRUE;
  158485. }
  158486. GLOBAL(void)
  158487. jinit_2pass_quantizer (j_decompress_ptr cinfo)
  158488. {
  158489. my_cquantize_ptr2 cquantize;
  158490. int i;
  158491. cquantize = (my_cquantize_ptr2)
  158492. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  158493. SIZEOF(my_cquantizer2));
  158494. cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize;
  158495. cquantize->pub.start_pass = start_pass_2_quant;
  158496. cquantize->pub.new_color_map = new_color_map_2_quant;
  158497. cquantize->fserrors = NULL; /* flag optional arrays not allocated */
  158498. cquantize->error_limiter = NULL;
  158499. if (cinfo->out_color_components != 3)
  158500. ERREXIT(cinfo, JERR_NOTIMPL);
  158501. cquantize->histogram = (hist3d) (*cinfo->mem->alloc_small)
  158502. ((j_common_ptr) cinfo, JPOOL_IMAGE, HIST_C0_ELEMS * SIZEOF(hist2d));
  158503. for (i = 0; i < HIST_C0_ELEMS; i++) {
  158504. cquantize->histogram[i] = (hist2d) (*cinfo->mem->alloc_large)
  158505. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  158506. HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell));
  158507. }
  158508. cquantize->needs_zeroed = TRUE; /* histogram is garbage now */
  158509. if (cinfo->enable_2pass_quant) {
  158510. int desired = cinfo->desired_number_of_colors;
  158511. if (desired < 8)
  158512. ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, 8);
  158513. if (desired > MAXNUMCOLORS)
  158514. ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);
  158515. cquantize->sv_colormap = (*cinfo->mem->alloc_sarray)
  158516. ((j_common_ptr) cinfo,JPOOL_IMAGE, (JDIMENSION) desired, (JDIMENSION) 3);
  158517. cquantize->desired = desired;
  158518. } else
  158519. cquantize->sv_colormap = NULL;
  158520. if (cinfo->dither_mode != JDITHER_NONE)
  158521. cinfo->dither_mode = JDITHER_FS;
  158522. if (cinfo->dither_mode == JDITHER_FS) {
  158523. cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large)
  158524. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  158525. (size_t) ((cinfo->output_width + 2) * (3 * SIZEOF(FSERROR))));
  158526. init_error_limit(cinfo);
  158527. }
  158528. }
  158529. #endif /* QUANT_2PASS_SUPPORTED */
  158530. /*** End of inlined file: jquant2.c ***/
  158531. /*** Start of inlined file: jutils.c ***/
  158532. #define JPEG_INTERNALS
  158533. #if 0 /* This table is not actually needed in v6a */
  158534. const int jpeg_zigzag_order[DCTSIZE2] = {
  158535. 0, 1, 5, 6, 14, 15, 27, 28,
  158536. 2, 4, 7, 13, 16, 26, 29, 42,
  158537. 3, 8, 12, 17, 25, 30, 41, 43,
  158538. 9, 11, 18, 24, 31, 40, 44, 53,
  158539. 10, 19, 23, 32, 39, 45, 52, 54,
  158540. 20, 22, 33, 38, 46, 51, 55, 60,
  158541. 21, 34, 37, 47, 50, 56, 59, 61,
  158542. 35, 36, 48, 49, 57, 58, 62, 63
  158543. };
  158544. #endif
  158545. const int jpeg_natural_order[DCTSIZE2+16] = {
  158546. 0, 1, 8, 16, 9, 2, 3, 10,
  158547. 17, 24, 32, 25, 18, 11, 4, 5,
  158548. 12, 19, 26, 33, 40, 48, 41, 34,
  158549. 27, 20, 13, 6, 7, 14, 21, 28,
  158550. 35, 42, 49, 56, 57, 50, 43, 36,
  158551. 29, 22, 15, 23, 30, 37, 44, 51,
  158552. 58, 59, 52, 45, 38, 31, 39, 46,
  158553. 53, 60, 61, 54, 47, 55, 62, 63,
  158554. 63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */
  158555. 63, 63, 63, 63, 63, 63, 63, 63
  158556. };
  158557. GLOBAL(long)
  158558. jdiv_round_up (long a, long b)
  158559. {
  158560. return (a + b - 1L) / b;
  158561. }
  158562. GLOBAL(long)
  158563. jround_up (long a, long b)
  158564. {
  158565. a += b - 1L;
  158566. return a - (a % b);
  158567. }
  158568. #ifndef NEED_FAR_POINTERS /* normal case, same as regular macros */
  158569. #define FMEMCOPY(dest,src,size) MEMCOPY(dest,src,size)
  158570. #define FMEMZERO(target,size) MEMZERO(target,size)
  158571. #else /* 80x86 case, define if we can */
  158572. #ifdef USE_FMEM
  158573. #define FMEMCOPY(dest,src,size) _fmemcpy((void FAR *)(dest), (const void FAR *)(src), (size_t)(size))
  158574. #define FMEMZERO(target,size) _fmemset((void FAR *)(target), 0, (size_t)(size))
  158575. #endif
  158576. #endif
  158577. GLOBAL(void)
  158578. jcopy_sample_rows (JSAMPARRAY input_array, int source_row,
  158579. JSAMPARRAY output_array, int dest_row,
  158580. int num_rows, JDIMENSION num_cols)
  158581. {
  158582. register JSAMPROW inptr, outptr;
  158583. #ifdef FMEMCOPY
  158584. register size_t count = (size_t) (num_cols * SIZEOF(JSAMPLE));
  158585. #else
  158586. register JDIMENSION count;
  158587. #endif
  158588. register int row;
  158589. input_array += source_row;
  158590. output_array += dest_row;
  158591. for (row = num_rows; row > 0; row--) {
  158592. inptr = *input_array++;
  158593. outptr = *output_array++;
  158594. #ifdef FMEMCOPY
  158595. FMEMCOPY(outptr, inptr, count);
  158596. #else
  158597. for (count = num_cols; count > 0; count--)
  158598. *outptr++ = *inptr++; /* needn't bother with GETJSAMPLE() here */
  158599. #endif
  158600. }
  158601. }
  158602. GLOBAL(void)
  158603. jcopy_block_row (JBLOCKROW input_row, JBLOCKROW output_row,
  158604. JDIMENSION num_blocks)
  158605. {
  158606. #ifdef FMEMCOPY
  158607. FMEMCOPY(output_row, input_row, num_blocks * (DCTSIZE2 * SIZEOF(JCOEF)));
  158608. #else
  158609. register JCOEFPTR inptr, outptr;
  158610. register long count;
  158611. inptr = (JCOEFPTR) input_row;
  158612. outptr = (JCOEFPTR) output_row;
  158613. for (count = (long) num_blocks * DCTSIZE2; count > 0; count--) {
  158614. *outptr++ = *inptr++;
  158615. }
  158616. #endif
  158617. }
  158618. GLOBAL(void)
  158619. jzero_far (void FAR * target, size_t bytestozero)
  158620. {
  158621. #ifdef FMEMZERO
  158622. FMEMZERO(target, bytestozero);
  158623. #else
  158624. register char FAR * ptr = (char FAR *) target;
  158625. register size_t count;
  158626. for (count = bytestozero; count > 0; count--) {
  158627. *ptr++ = 0;
  158628. }
  158629. #endif
  158630. }
  158631. /*** End of inlined file: jutils.c ***/
  158632. /*** Start of inlined file: transupp.c ***/
  158633. #define JPEG_INTERNALS
  158634. /*** Start of inlined file: transupp.h ***/
  158635. #ifndef TRANSFORMS_SUPPORTED
  158636. #define TRANSFORMS_SUPPORTED 1 /* 0 disables transform code */
  158637. #endif
  158638. #ifdef NEED_SHORT_EXTERNAL_NAMES
  158639. #define jtransform_request_workspace jTrRequest
  158640. #define jtransform_adjust_parameters jTrAdjust
  158641. #define jtransform_execute_transformation jTrExec
  158642. #define jcopy_markers_setup jCMrkSetup
  158643. #define jcopy_markers_execute jCMrkExec
  158644. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  158645. typedef enum {
  158646. JXFORM_NONE, /* no transformation */
  158647. JXFORM_FLIP_H, /* horizontal flip */
  158648. JXFORM_FLIP_V, /* vertical flip */
  158649. JXFORM_TRANSPOSE, /* transpose across UL-to-LR axis */
  158650. JXFORM_TRANSVERSE, /* transpose across UR-to-LL axis */
  158651. JXFORM_ROT_90, /* 90-degree clockwise rotation */
  158652. JXFORM_ROT_180, /* 180-degree rotation */
  158653. JXFORM_ROT_270 /* 270-degree clockwise (or 90 ccw) */
  158654. } JXFORM_CODE;
  158655. typedef struct {
  158656. JXFORM_CODE transform; /* image transform operator */
  158657. boolean trim; /* if TRUE, trim partial MCUs as needed */
  158658. boolean force_grayscale; /* if TRUE, convert color image to grayscale */
  158659. int num_components; /* # of components in workspace */
  158660. jvirt_barray_ptr * workspace_coef_arrays; /* workspace for transformations */
  158661. } jpeg_transform_info;
  158662. #if TRANSFORMS_SUPPORTED
  158663. EXTERN(void) jtransform_request_workspace
  158664. JPP((j_decompress_ptr srcinfo, jpeg_transform_info *info));
  158665. EXTERN(jvirt_barray_ptr *) jtransform_adjust_parameters
  158666. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158667. jvirt_barray_ptr *src_coef_arrays,
  158668. jpeg_transform_info *info));
  158669. EXTERN(void) jtransform_execute_transformation
  158670. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158671. jvirt_barray_ptr *src_coef_arrays,
  158672. jpeg_transform_info *info));
  158673. #endif /* TRANSFORMS_SUPPORTED */
  158674. typedef enum {
  158675. JCOPYOPT_NONE, /* copy no optional markers */
  158676. JCOPYOPT_COMMENTS, /* copy only comment (COM) markers */
  158677. JCOPYOPT_ALL /* copy all optional markers */
  158678. } JCOPY_OPTION;
  158679. #define JCOPYOPT_DEFAULT JCOPYOPT_COMMENTS /* recommended default */
  158680. EXTERN(void) jcopy_markers_setup
  158681. JPP((j_decompress_ptr srcinfo, JCOPY_OPTION option));
  158682. EXTERN(void) jcopy_markers_execute
  158683. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158684. JCOPY_OPTION option));
  158685. /*** End of inlined file: transupp.h ***/
  158686. /* My own external interface */
  158687. #if TRANSFORMS_SUPPORTED
  158688. LOCAL(void)
  158689. do_flip_h (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158690. jvirt_barray_ptr *src_coef_arrays)
  158691. {
  158692. JDIMENSION MCU_cols, comp_width, blk_x, blk_y;
  158693. int ci, k, offset_y;
  158694. JBLOCKARRAY buffer;
  158695. JCOEFPTR ptr1, ptr2;
  158696. JCOEF temp1, temp2;
  158697. jpeg_component_info *compptr;
  158698. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158699. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158700. compptr = dstinfo->comp_info + ci;
  158701. comp_width = MCU_cols * compptr->h_samp_factor;
  158702. for (blk_y = 0; blk_y < compptr->height_in_blocks;
  158703. blk_y += compptr->v_samp_factor) {
  158704. buffer = (*srcinfo->mem->access_virt_barray)
  158705. ((j_common_ptr) srcinfo, src_coef_arrays[ci], blk_y,
  158706. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158707. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158708. for (blk_x = 0; blk_x * 2 < comp_width; blk_x++) {
  158709. ptr1 = buffer[offset_y][blk_x];
  158710. ptr2 = buffer[offset_y][comp_width - blk_x - 1];
  158711. for (k = 0; k < DCTSIZE2; k += 2) {
  158712. temp1 = *ptr1; /* swap even column */
  158713. temp2 = *ptr2;
  158714. *ptr1++ = temp2;
  158715. *ptr2++ = temp1;
  158716. temp1 = *ptr1; /* swap odd column with sign change */
  158717. temp2 = *ptr2;
  158718. *ptr1++ = -temp2;
  158719. *ptr2++ = -temp1;
  158720. }
  158721. }
  158722. }
  158723. }
  158724. }
  158725. }
  158726. LOCAL(void)
  158727. do_flip_v (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158728. jvirt_barray_ptr *src_coef_arrays,
  158729. jvirt_barray_ptr *dst_coef_arrays)
  158730. {
  158731. JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y;
  158732. int ci, i, j, offset_y;
  158733. JBLOCKARRAY src_buffer, dst_buffer;
  158734. JBLOCKROW src_row_ptr, dst_row_ptr;
  158735. JCOEFPTR src_ptr, dst_ptr;
  158736. jpeg_component_info *compptr;
  158737. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158738. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158739. compptr = dstinfo->comp_info + ci;
  158740. comp_height = MCU_rows * compptr->v_samp_factor;
  158741. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158742. dst_blk_y += compptr->v_samp_factor) {
  158743. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158744. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158745. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158746. if (dst_blk_y < comp_height) {
  158747. src_buffer = (*srcinfo->mem->access_virt_barray)
  158748. ((j_common_ptr) srcinfo, src_coef_arrays[ci],
  158749. comp_height - dst_blk_y - (JDIMENSION) compptr->v_samp_factor,
  158750. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158751. } else {
  158752. src_buffer = (*srcinfo->mem->access_virt_barray)
  158753. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_y,
  158754. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158755. }
  158756. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158757. if (dst_blk_y < comp_height) {
  158758. dst_row_ptr = dst_buffer[offset_y];
  158759. src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1];
  158760. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158761. dst_blk_x++) {
  158762. dst_ptr = dst_row_ptr[dst_blk_x];
  158763. src_ptr = src_row_ptr[dst_blk_x];
  158764. for (i = 0; i < DCTSIZE; i += 2) {
  158765. for (j = 0; j < DCTSIZE; j++)
  158766. *dst_ptr++ = *src_ptr++;
  158767. for (j = 0; j < DCTSIZE; j++)
  158768. *dst_ptr++ = - *src_ptr++;
  158769. }
  158770. }
  158771. } else {
  158772. jcopy_block_row(src_buffer[offset_y], dst_buffer[offset_y],
  158773. compptr->width_in_blocks);
  158774. }
  158775. }
  158776. }
  158777. }
  158778. }
  158779. LOCAL(void)
  158780. do_transpose (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158781. jvirt_barray_ptr *src_coef_arrays,
  158782. jvirt_barray_ptr *dst_coef_arrays)
  158783. {
  158784. JDIMENSION dst_blk_x, dst_blk_y;
  158785. int ci, i, j, offset_x, offset_y;
  158786. JBLOCKARRAY src_buffer, dst_buffer;
  158787. JCOEFPTR src_ptr, dst_ptr;
  158788. jpeg_component_info *compptr;
  158789. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158790. compptr = dstinfo->comp_info + ci;
  158791. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158792. dst_blk_y += compptr->v_samp_factor) {
  158793. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158794. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158795. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158796. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158797. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158798. dst_blk_x += compptr->h_samp_factor) {
  158799. src_buffer = (*srcinfo->mem->access_virt_barray)
  158800. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158801. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158802. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158803. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158804. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158805. for (i = 0; i < DCTSIZE; i++)
  158806. for (j = 0; j < DCTSIZE; j++)
  158807. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158808. }
  158809. }
  158810. }
  158811. }
  158812. }
  158813. }
  158814. LOCAL(void)
  158815. do_rot_90 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158816. jvirt_barray_ptr *src_coef_arrays,
  158817. jvirt_barray_ptr *dst_coef_arrays)
  158818. {
  158819. JDIMENSION MCU_cols, comp_width, dst_blk_x, dst_blk_y;
  158820. int ci, i, j, offset_x, offset_y;
  158821. JBLOCKARRAY src_buffer, dst_buffer;
  158822. JCOEFPTR src_ptr, dst_ptr;
  158823. jpeg_component_info *compptr;
  158824. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158825. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158826. compptr = dstinfo->comp_info + ci;
  158827. comp_width = MCU_cols * compptr->h_samp_factor;
  158828. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158829. dst_blk_y += compptr->v_samp_factor) {
  158830. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158831. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158832. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158833. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158834. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158835. dst_blk_x += compptr->h_samp_factor) {
  158836. src_buffer = (*srcinfo->mem->access_virt_barray)
  158837. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158838. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158839. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158840. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158841. if (dst_blk_x < comp_width) {
  158842. dst_ptr = dst_buffer[offset_y]
  158843. [comp_width - dst_blk_x - offset_x - 1];
  158844. for (i = 0; i < DCTSIZE; i++) {
  158845. for (j = 0; j < DCTSIZE; j++)
  158846. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158847. i++;
  158848. for (j = 0; j < DCTSIZE; j++)
  158849. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158850. }
  158851. } else {
  158852. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158853. for (i = 0; i < DCTSIZE; i++)
  158854. for (j = 0; j < DCTSIZE; j++)
  158855. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158856. }
  158857. }
  158858. }
  158859. }
  158860. }
  158861. }
  158862. }
  158863. LOCAL(void)
  158864. do_rot_270 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158865. jvirt_barray_ptr *src_coef_arrays,
  158866. jvirt_barray_ptr *dst_coef_arrays)
  158867. {
  158868. JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y;
  158869. int ci, i, j, offset_x, offset_y;
  158870. JBLOCKARRAY src_buffer, dst_buffer;
  158871. JCOEFPTR src_ptr, dst_ptr;
  158872. jpeg_component_info *compptr;
  158873. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158874. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158875. compptr = dstinfo->comp_info + ci;
  158876. comp_height = MCU_rows * compptr->v_samp_factor;
  158877. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158878. dst_blk_y += compptr->v_samp_factor) {
  158879. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158880. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158881. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158882. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158883. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158884. dst_blk_x += compptr->h_samp_factor) {
  158885. src_buffer = (*srcinfo->mem->access_virt_barray)
  158886. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158887. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158888. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158889. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158890. if (dst_blk_y < comp_height) {
  158891. src_ptr = src_buffer[offset_x]
  158892. [comp_height - dst_blk_y - offset_y - 1];
  158893. for (i = 0; i < DCTSIZE; i++) {
  158894. for (j = 0; j < DCTSIZE; j++) {
  158895. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158896. j++;
  158897. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158898. }
  158899. }
  158900. } else {
  158901. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158902. for (i = 0; i < DCTSIZE; i++)
  158903. for (j = 0; j < DCTSIZE; j++)
  158904. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158905. }
  158906. }
  158907. }
  158908. }
  158909. }
  158910. }
  158911. }
  158912. LOCAL(void)
  158913. do_rot_180 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158914. jvirt_barray_ptr *src_coef_arrays,
  158915. jvirt_barray_ptr *dst_coef_arrays)
  158916. {
  158917. JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y;
  158918. int ci, i, j, offset_y;
  158919. JBLOCKARRAY src_buffer, dst_buffer;
  158920. JBLOCKROW src_row_ptr, dst_row_ptr;
  158921. JCOEFPTR src_ptr, dst_ptr;
  158922. jpeg_component_info *compptr;
  158923. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158924. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158925. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158926. compptr = dstinfo->comp_info + ci;
  158927. comp_width = MCU_cols * compptr->h_samp_factor;
  158928. comp_height = MCU_rows * compptr->v_samp_factor;
  158929. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158930. dst_blk_y += compptr->v_samp_factor) {
  158931. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158932. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158933. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158934. if (dst_blk_y < comp_height) {
  158935. src_buffer = (*srcinfo->mem->access_virt_barray)
  158936. ((j_common_ptr) srcinfo, src_coef_arrays[ci],
  158937. comp_height - dst_blk_y - (JDIMENSION) compptr->v_samp_factor,
  158938. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158939. } else {
  158940. src_buffer = (*srcinfo->mem->access_virt_barray)
  158941. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_y,
  158942. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158943. }
  158944. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158945. if (dst_blk_y < comp_height) {
  158946. dst_row_ptr = dst_buffer[offset_y];
  158947. src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1];
  158948. for (dst_blk_x = 0; dst_blk_x < comp_width; dst_blk_x++) {
  158949. dst_ptr = dst_row_ptr[dst_blk_x];
  158950. src_ptr = src_row_ptr[comp_width - dst_blk_x - 1];
  158951. for (i = 0; i < DCTSIZE; i += 2) {
  158952. for (j = 0; j < DCTSIZE; j += 2) {
  158953. *dst_ptr++ = *src_ptr++;
  158954. *dst_ptr++ = - *src_ptr++;
  158955. }
  158956. for (j = 0; j < DCTSIZE; j += 2) {
  158957. *dst_ptr++ = - *src_ptr++;
  158958. *dst_ptr++ = *src_ptr++;
  158959. }
  158960. }
  158961. }
  158962. for (; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) {
  158963. dst_ptr = dst_row_ptr[dst_blk_x];
  158964. src_ptr = src_row_ptr[dst_blk_x];
  158965. for (i = 0; i < DCTSIZE; i += 2) {
  158966. for (j = 0; j < DCTSIZE; j++)
  158967. *dst_ptr++ = *src_ptr++;
  158968. for (j = 0; j < DCTSIZE; j++)
  158969. *dst_ptr++ = - *src_ptr++;
  158970. }
  158971. }
  158972. } else {
  158973. dst_row_ptr = dst_buffer[offset_y];
  158974. src_row_ptr = src_buffer[offset_y];
  158975. for (dst_blk_x = 0; dst_blk_x < comp_width; dst_blk_x++) {
  158976. dst_ptr = dst_row_ptr[dst_blk_x];
  158977. src_ptr = src_row_ptr[comp_width - dst_blk_x - 1];
  158978. for (i = 0; i < DCTSIZE2; i += 2) {
  158979. *dst_ptr++ = *src_ptr++;
  158980. *dst_ptr++ = - *src_ptr++;
  158981. }
  158982. }
  158983. for (; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) {
  158984. dst_ptr = dst_row_ptr[dst_blk_x];
  158985. src_ptr = src_row_ptr[dst_blk_x];
  158986. for (i = 0; i < DCTSIZE2; i++)
  158987. *dst_ptr++ = *src_ptr++;
  158988. }
  158989. }
  158990. }
  158991. }
  158992. }
  158993. }
  158994. LOCAL(void)
  158995. do_transverse (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158996. jvirt_barray_ptr *src_coef_arrays,
  158997. jvirt_barray_ptr *dst_coef_arrays)
  158998. {
  158999. JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y;
  159000. int ci, i, j, offset_x, offset_y;
  159001. JBLOCKARRAY src_buffer, dst_buffer;
  159002. JCOEFPTR src_ptr, dst_ptr;
  159003. jpeg_component_info *compptr;
  159004. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  159005. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  159006. for (ci = 0; ci < dstinfo->num_components; ci++) {
  159007. compptr = dstinfo->comp_info + ci;
  159008. comp_width = MCU_cols * compptr->h_samp_factor;
  159009. comp_height = MCU_rows * compptr->v_samp_factor;
  159010. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  159011. dst_blk_y += compptr->v_samp_factor) {
  159012. dst_buffer = (*srcinfo->mem->access_virt_barray)
  159013. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  159014. (JDIMENSION) compptr->v_samp_factor, TRUE);
  159015. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  159016. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  159017. dst_blk_x += compptr->h_samp_factor) {
  159018. src_buffer = (*srcinfo->mem->access_virt_barray)
  159019. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  159020. (JDIMENSION) compptr->h_samp_factor, FALSE);
  159021. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  159022. if (dst_blk_y < comp_height) {
  159023. src_ptr = src_buffer[offset_x]
  159024. [comp_height - dst_blk_y - offset_y - 1];
  159025. if (dst_blk_x < comp_width) {
  159026. dst_ptr = dst_buffer[offset_y]
  159027. [comp_width - dst_blk_x - offset_x - 1];
  159028. for (i = 0; i < DCTSIZE; i++) {
  159029. for (j = 0; j < DCTSIZE; j++) {
  159030. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  159031. j++;
  159032. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  159033. }
  159034. i++;
  159035. for (j = 0; j < DCTSIZE; j++) {
  159036. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  159037. j++;
  159038. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  159039. }
  159040. }
  159041. } else {
  159042. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  159043. for (i = 0; i < DCTSIZE; i++) {
  159044. for (j = 0; j < DCTSIZE; j++) {
  159045. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  159046. j++;
  159047. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  159048. }
  159049. }
  159050. }
  159051. } else {
  159052. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  159053. if (dst_blk_x < comp_width) {
  159054. dst_ptr = dst_buffer[offset_y]
  159055. [comp_width - dst_blk_x - offset_x - 1];
  159056. for (i = 0; i < DCTSIZE; i++) {
  159057. for (j = 0; j < DCTSIZE; j++)
  159058. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  159059. i++;
  159060. for (j = 0; j < DCTSIZE; j++)
  159061. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  159062. }
  159063. } else {
  159064. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  159065. for (i = 0; i < DCTSIZE; i++)
  159066. for (j = 0; j < DCTSIZE; j++)
  159067. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  159068. }
  159069. }
  159070. }
  159071. }
  159072. }
  159073. }
  159074. }
  159075. }
  159076. GLOBAL(void)
  159077. jtransform_request_workspace (j_decompress_ptr srcinfo,
  159078. jpeg_transform_info *info)
  159079. {
  159080. jvirt_barray_ptr *coef_arrays = NULL;
  159081. jpeg_component_info *compptr;
  159082. int ci;
  159083. if (info->force_grayscale &&
  159084. srcinfo->jpeg_color_space == JCS_YCbCr &&
  159085. srcinfo->num_components == 3) {
  159086. info->num_components = 1;
  159087. } else {
  159088. info->num_components = srcinfo->num_components;
  159089. }
  159090. switch (info->transform) {
  159091. case JXFORM_NONE:
  159092. case JXFORM_FLIP_H:
  159093. break;
  159094. case JXFORM_FLIP_V:
  159095. case JXFORM_ROT_180:
  159096. coef_arrays = (jvirt_barray_ptr *)
  159097. (*srcinfo->mem->alloc_small) ((j_common_ptr) srcinfo, JPOOL_IMAGE,
  159098. SIZEOF(jvirt_barray_ptr) * info->num_components);
  159099. for (ci = 0; ci < info->num_components; ci++) {
  159100. compptr = srcinfo->comp_info + ci;
  159101. coef_arrays[ci] = (*srcinfo->mem->request_virt_barray)
  159102. ((j_common_ptr) srcinfo, JPOOL_IMAGE, FALSE,
  159103. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  159104. (long) compptr->h_samp_factor),
  159105. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  159106. (long) compptr->v_samp_factor),
  159107. (JDIMENSION) compptr->v_samp_factor);
  159108. }
  159109. break;
  159110. case JXFORM_TRANSPOSE:
  159111. case JXFORM_TRANSVERSE:
  159112. case JXFORM_ROT_90:
  159113. case JXFORM_ROT_270:
  159114. coef_arrays = (jvirt_barray_ptr *)
  159115. (*srcinfo->mem->alloc_small) ((j_common_ptr) srcinfo, JPOOL_IMAGE,
  159116. SIZEOF(jvirt_barray_ptr) * info->num_components);
  159117. for (ci = 0; ci < info->num_components; ci++) {
  159118. compptr = srcinfo->comp_info + ci;
  159119. coef_arrays[ci] = (*srcinfo->mem->request_virt_barray)
  159120. ((j_common_ptr) srcinfo, JPOOL_IMAGE, FALSE,
  159121. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  159122. (long) compptr->v_samp_factor),
  159123. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  159124. (long) compptr->h_samp_factor),
  159125. (JDIMENSION) compptr->h_samp_factor);
  159126. }
  159127. break;
  159128. }
  159129. info->workspace_coef_arrays = coef_arrays;
  159130. }
  159131. LOCAL(void)
  159132. transpose_critical_parameters (j_compress_ptr dstinfo)
  159133. {
  159134. int tblno, i, j, ci, itemp;
  159135. jpeg_component_info *compptr;
  159136. JQUANT_TBL *qtblptr;
  159137. JDIMENSION dtemp;
  159138. UINT16 qtemp;
  159139. dtemp = dstinfo->image_width;
  159140. dstinfo->image_width = dstinfo->image_height;
  159141. dstinfo->image_height = dtemp;
  159142. for (ci = 0; ci < dstinfo->num_components; ci++) {
  159143. compptr = dstinfo->comp_info + ci;
  159144. itemp = compptr->h_samp_factor;
  159145. compptr->h_samp_factor = compptr->v_samp_factor;
  159146. compptr->v_samp_factor = itemp;
  159147. }
  159148. for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {
  159149. qtblptr = dstinfo->quant_tbl_ptrs[tblno];
  159150. if (qtblptr != NULL) {
  159151. for (i = 0; i < DCTSIZE; i++) {
  159152. for (j = 0; j < i; j++) {
  159153. qtemp = qtblptr->quantval[i*DCTSIZE+j];
  159154. qtblptr->quantval[i*DCTSIZE+j] = qtblptr->quantval[j*DCTSIZE+i];
  159155. qtblptr->quantval[j*DCTSIZE+i] = qtemp;
  159156. }
  159157. }
  159158. }
  159159. }
  159160. }
  159161. LOCAL(void)
  159162. trim_right_edge (j_compress_ptr dstinfo)
  159163. {
  159164. int ci, max_h_samp_factor;
  159165. JDIMENSION MCU_cols;
  159166. max_h_samp_factor = 1;
  159167. for (ci = 0; ci < dstinfo->num_components; ci++) {
  159168. int h_samp_factor = dstinfo->comp_info[ci].h_samp_factor;
  159169. max_h_samp_factor = MAX(max_h_samp_factor, h_samp_factor);
  159170. }
  159171. MCU_cols = dstinfo->image_width / (max_h_samp_factor * DCTSIZE);
  159172. if (MCU_cols > 0) /* can't trim to 0 pixels */
  159173. dstinfo->image_width = MCU_cols * (max_h_samp_factor * DCTSIZE);
  159174. }
  159175. LOCAL(void)
  159176. trim_bottom_edge (j_compress_ptr dstinfo)
  159177. {
  159178. int ci, max_v_samp_factor;
  159179. JDIMENSION MCU_rows;
  159180. max_v_samp_factor = 1;
  159181. for (ci = 0; ci < dstinfo->num_components; ci++) {
  159182. int v_samp_factor = dstinfo->comp_info[ci].v_samp_factor;
  159183. max_v_samp_factor = MAX(max_v_samp_factor, v_samp_factor);
  159184. }
  159185. MCU_rows = dstinfo->image_height / (max_v_samp_factor * DCTSIZE);
  159186. if (MCU_rows > 0) /* can't trim to 0 pixels */
  159187. dstinfo->image_height = MCU_rows * (max_v_samp_factor * DCTSIZE);
  159188. }
  159189. GLOBAL(jvirt_barray_ptr *)
  159190. jtransform_adjust_parameters (j_decompress_ptr srcinfo,
  159191. j_compress_ptr dstinfo,
  159192. jvirt_barray_ptr *src_coef_arrays,
  159193. jpeg_transform_info *info)
  159194. {
  159195. if (info->force_grayscale) {
  159196. if ((dstinfo->jpeg_color_space == JCS_YCbCr &&
  159197. dstinfo->num_components == 3) ||
  159198. (dstinfo->jpeg_color_space == JCS_GRAYSCALE &&
  159199. dstinfo->num_components == 1)) {
  159200. int sv_quant_tbl_no = dstinfo->comp_info[0].quant_tbl_no;
  159201. jpeg_set_colorspace(dstinfo, JCS_GRAYSCALE);
  159202. dstinfo->comp_info[0].quant_tbl_no = sv_quant_tbl_no;
  159203. } else {
  159204. ERREXIT(dstinfo, JERR_CONVERSION_NOTIMPL);
  159205. }
  159206. }
  159207. switch (info->transform) {
  159208. case JXFORM_NONE:
  159209. break;
  159210. case JXFORM_FLIP_H:
  159211. if (info->trim)
  159212. trim_right_edge(dstinfo);
  159213. break;
  159214. case JXFORM_FLIP_V:
  159215. if (info->trim)
  159216. trim_bottom_edge(dstinfo);
  159217. break;
  159218. case JXFORM_TRANSPOSE:
  159219. transpose_critical_parameters(dstinfo);
  159220. break;
  159221. case JXFORM_TRANSVERSE:
  159222. transpose_critical_parameters(dstinfo);
  159223. if (info->trim) {
  159224. trim_right_edge(dstinfo);
  159225. trim_bottom_edge(dstinfo);
  159226. }
  159227. break;
  159228. case JXFORM_ROT_90:
  159229. transpose_critical_parameters(dstinfo);
  159230. if (info->trim)
  159231. trim_right_edge(dstinfo);
  159232. break;
  159233. case JXFORM_ROT_180:
  159234. if (info->trim) {
  159235. trim_right_edge(dstinfo);
  159236. trim_bottom_edge(dstinfo);
  159237. }
  159238. break;
  159239. case JXFORM_ROT_270:
  159240. transpose_critical_parameters(dstinfo);
  159241. if (info->trim)
  159242. trim_bottom_edge(dstinfo);
  159243. break;
  159244. }
  159245. if (info->workspace_coef_arrays != NULL)
  159246. return info->workspace_coef_arrays;
  159247. return src_coef_arrays;
  159248. }
  159249. GLOBAL(void)
  159250. jtransform_execute_transformation (j_decompress_ptr srcinfo,
  159251. j_compress_ptr dstinfo,
  159252. jvirt_barray_ptr *src_coef_arrays,
  159253. jpeg_transform_info *info)
  159254. {
  159255. jvirt_barray_ptr *dst_coef_arrays = info->workspace_coef_arrays;
  159256. switch (info->transform) {
  159257. case JXFORM_NONE:
  159258. break;
  159259. case JXFORM_FLIP_H:
  159260. do_flip_h(srcinfo, dstinfo, src_coef_arrays);
  159261. break;
  159262. case JXFORM_FLIP_V:
  159263. do_flip_v(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  159264. break;
  159265. case JXFORM_TRANSPOSE:
  159266. do_transpose(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  159267. break;
  159268. case JXFORM_TRANSVERSE:
  159269. do_transverse(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  159270. break;
  159271. case JXFORM_ROT_90:
  159272. do_rot_90(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  159273. break;
  159274. case JXFORM_ROT_180:
  159275. do_rot_180(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  159276. break;
  159277. case JXFORM_ROT_270:
  159278. do_rot_270(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  159279. break;
  159280. }
  159281. }
  159282. #endif /* TRANSFORMS_SUPPORTED */
  159283. GLOBAL(void)
  159284. jcopy_markers_setup (j_decompress_ptr srcinfo, JCOPY_OPTION option)
  159285. {
  159286. #ifdef SAVE_MARKERS_SUPPORTED
  159287. int m;
  159288. if (option != JCOPYOPT_NONE) {
  159289. jpeg_save_markers(srcinfo, JPEG_COM, 0xFFFF);
  159290. }
  159291. if (option == JCOPYOPT_ALL) {
  159292. for (m = 0; m < 16; m++)
  159293. jpeg_save_markers(srcinfo, JPEG_APP0 + m, 0xFFFF);
  159294. }
  159295. #endif /* SAVE_MARKERS_SUPPORTED */
  159296. }
  159297. GLOBAL(void)
  159298. jcopy_markers_execute (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  159299. JCOPY_OPTION option)
  159300. {
  159301. jpeg_saved_marker_ptr marker;
  159302. for (marker = srcinfo->marker_list; marker != NULL; marker = marker->next) {
  159303. if (dstinfo->write_JFIF_header &&
  159304. marker->marker == JPEG_APP0 &&
  159305. marker->data_length >= 5 &&
  159306. GETJOCTET(marker->data[0]) == 0x4A &&
  159307. GETJOCTET(marker->data[1]) == 0x46 &&
  159308. GETJOCTET(marker->data[2]) == 0x49 &&
  159309. GETJOCTET(marker->data[3]) == 0x46 &&
  159310. GETJOCTET(marker->data[4]) == 0)
  159311. continue; /* reject duplicate JFIF */
  159312. if (dstinfo->write_Adobe_marker &&
  159313. marker->marker == JPEG_APP0+14 &&
  159314. marker->data_length >= 5 &&
  159315. GETJOCTET(marker->data[0]) == 0x41 &&
  159316. GETJOCTET(marker->data[1]) == 0x64 &&
  159317. GETJOCTET(marker->data[2]) == 0x6F &&
  159318. GETJOCTET(marker->data[3]) == 0x62 &&
  159319. GETJOCTET(marker->data[4]) == 0x65)
  159320. continue; /* reject duplicate Adobe */
  159321. #ifdef NEED_FAR_POINTERS
  159322. {
  159323. unsigned int i;
  159324. jpeg_write_m_header(dstinfo, marker->marker, marker->data_length);
  159325. for (i = 0; i < marker->data_length; i++)
  159326. jpeg_write_m_byte(dstinfo, marker->data[i]);
  159327. }
  159328. #else
  159329. jpeg_write_marker(dstinfo, marker->marker,
  159330. marker->data, marker->data_length);
  159331. #endif
  159332. }
  159333. }
  159334. /*** End of inlined file: transupp.c ***/
  159335. }
  159336. #else
  159337. #define JPEG_INTERNALS
  159338. #undef FAR
  159339. #include <jpeglib.h>
  159340. #endif
  159341. }
  159342. #if JUCE_MSVC
  159343. #pragma warning (pop)
  159344. #endif
  159345. BEGIN_JUCE_NAMESPACE
  159346. using namespace jpeglibNamespace;
  159347. #if ! JUCE_MSVC
  159348. using jpeglibNamespace::boolean;
  159349. #endif
  159350. struct JPEGDecodingFailure {};
  159351. static void fatalErrorHandler (j_common_ptr)
  159352. {
  159353. throw JPEGDecodingFailure();
  159354. }
  159355. static void silentErrorCallback1 (j_common_ptr) {}
  159356. static void silentErrorCallback2 (j_common_ptr, int) {}
  159357. static void silentErrorCallback3 (j_common_ptr, char*) {}
  159358. static void setupSilentErrorHandler (struct jpeg_error_mgr& err)
  159359. {
  159360. zerostruct (err);
  159361. err.error_exit = fatalErrorHandler;
  159362. err.emit_message = silentErrorCallback2;
  159363. err.output_message = silentErrorCallback1;
  159364. err.format_message = silentErrorCallback3;
  159365. err.reset_error_mgr = silentErrorCallback1;
  159366. }
  159367. static void dummyCallback1 (j_decompress_ptr)
  159368. {
  159369. }
  159370. static void jpegSkip (j_decompress_ptr decompStruct, long num)
  159371. {
  159372. decompStruct->src->next_input_byte += num;
  159373. num = jmin (num, (long) decompStruct->src->bytes_in_buffer);
  159374. decompStruct->src->bytes_in_buffer -= num;
  159375. }
  159376. static boolean jpegFill (j_decompress_ptr)
  159377. {
  159378. return 0;
  159379. }
  159380. Image* juce_loadJPEGImageFromStream (InputStream& in)
  159381. {
  159382. MemoryBlock mb;
  159383. in.readIntoMemoryBlock (mb);
  159384. Image* image = 0;
  159385. if (mb.getSize() > 16)
  159386. {
  159387. struct jpeg_decompress_struct jpegDecompStruct;
  159388. struct jpeg_error_mgr jerr;
  159389. setupSilentErrorHandler (jerr);
  159390. jpegDecompStruct.err = &jerr;
  159391. jpeg_create_decompress (&jpegDecompStruct);
  159392. jpegDecompStruct.src = (jpeg_source_mgr*)(jpegDecompStruct.mem->alloc_small)
  159393. ((j_common_ptr)(&jpegDecompStruct), JPOOL_PERMANENT, sizeof (jpeg_source_mgr));
  159394. jpegDecompStruct.src->init_source = dummyCallback1;
  159395. jpegDecompStruct.src->fill_input_buffer = jpegFill;
  159396. jpegDecompStruct.src->skip_input_data = jpegSkip;
  159397. jpegDecompStruct.src->resync_to_restart = jpeg_resync_to_restart;
  159398. jpegDecompStruct.src->term_source = dummyCallback1;
  159399. jpegDecompStruct.src->next_input_byte = (const unsigned char*) mb.getData();
  159400. jpegDecompStruct.src->bytes_in_buffer = mb.getSize();
  159401. try
  159402. {
  159403. jpeg_read_header (&jpegDecompStruct, TRUE);
  159404. jpeg_calc_output_dimensions (&jpegDecompStruct);
  159405. const int width = jpegDecompStruct.output_width;
  159406. const int height = jpegDecompStruct.output_height;
  159407. jpegDecompStruct.out_color_space = JCS_RGB;
  159408. JSAMPARRAY buffer
  159409. = (*jpegDecompStruct.mem->alloc_sarray) ((j_common_ptr) &jpegDecompStruct,
  159410. JPOOL_IMAGE,
  159411. width * 3, 1);
  159412. if (jpeg_start_decompress (&jpegDecompStruct))
  159413. {
  159414. image = Image::createNativeImage (Image::RGB, width, height, false);
  159415. const bool hasAlphaChan = image->hasAlphaChannel();
  159416. const Image::BitmapData destData (*image, 0, 0, width, height, true);
  159417. for (int y = 0; y < height; ++y)
  159418. {
  159419. jpeg_read_scanlines (&jpegDecompStruct, buffer, 1);
  159420. const uint8* src = *buffer;
  159421. uint8* dest = destData.getLinePointer (y);
  159422. if (hasAlphaChan)
  159423. {
  159424. for (int i = width; --i >= 0;)
  159425. {
  159426. ((PixelARGB*) dest)->setARGB (0xff, src[0], src[1], src[2]);
  159427. ((PixelARGB*) dest)->premultiply();
  159428. dest += destData.pixelStride;
  159429. src += 3;
  159430. }
  159431. }
  159432. else
  159433. {
  159434. for (int i = width; --i >= 0;)
  159435. {
  159436. ((PixelRGB*) dest)->setARGB (0xff, src[0], src[1], src[2]);
  159437. dest += destData.pixelStride;
  159438. src += 3;
  159439. }
  159440. }
  159441. }
  159442. jpeg_finish_decompress (&jpegDecompStruct);
  159443. in.setPosition (((char*) jpegDecompStruct.src->next_input_byte) - (char*) mb.getData());
  159444. }
  159445. jpeg_destroy_decompress (&jpegDecompStruct);
  159446. }
  159447. catch (...)
  159448. {}
  159449. }
  159450. return image;
  159451. }
  159452. static const int jpegBufferSize = 512;
  159453. struct JuceJpegDest : public jpeg_destination_mgr
  159454. {
  159455. OutputStream* output;
  159456. char* buffer;
  159457. };
  159458. static void jpegWriteInit (j_compress_ptr)
  159459. {
  159460. }
  159461. static void jpegWriteTerminate (j_compress_ptr cinfo)
  159462. {
  159463. JuceJpegDest* const dest = (JuceJpegDest*) cinfo->dest;
  159464. const size_t numToWrite = jpegBufferSize - dest->free_in_buffer;
  159465. dest->output->write (dest->buffer, (int) numToWrite);
  159466. }
  159467. static boolean jpegWriteFlush (j_compress_ptr cinfo)
  159468. {
  159469. JuceJpegDest* const dest = (JuceJpegDest*) cinfo->dest;
  159470. const int numToWrite = jpegBufferSize;
  159471. dest->next_output_byte = (JOCTET*) dest->buffer;
  159472. dest->free_in_buffer = jpegBufferSize;
  159473. return dest->output->write (dest->buffer, numToWrite);
  159474. }
  159475. bool juce_writeJPEGImageToStream (const Image& image,
  159476. OutputStream& out,
  159477. float quality)
  159478. {
  159479. if (image.hasAlphaChannel())
  159480. {
  159481. // this method could fill the background in white and still save the image..
  159482. jassertfalse
  159483. return true;
  159484. }
  159485. struct jpeg_compress_struct jpegCompStruct;
  159486. struct jpeg_error_mgr jerr;
  159487. setupSilentErrorHandler (jerr);
  159488. jpegCompStruct.err = &jerr;
  159489. jpeg_create_compress (&jpegCompStruct);
  159490. JuceJpegDest dest;
  159491. jpegCompStruct.dest = &dest;
  159492. dest.output = &out;
  159493. HeapBlock <char> tempBuffer (jpegBufferSize);
  159494. dest.buffer = (char*) tempBuffer;
  159495. dest.next_output_byte = (JOCTET*) dest.buffer;
  159496. dest.free_in_buffer = jpegBufferSize;
  159497. dest.init_destination = jpegWriteInit;
  159498. dest.empty_output_buffer = jpegWriteFlush;
  159499. dest.term_destination = jpegWriteTerminate;
  159500. jpegCompStruct.image_width = image.getWidth();
  159501. jpegCompStruct.image_height = image.getHeight();
  159502. jpegCompStruct.input_components = 3;
  159503. jpegCompStruct.in_color_space = JCS_RGB;
  159504. jpegCompStruct.write_JFIF_header = 1;
  159505. jpegCompStruct.X_density = 72;
  159506. jpegCompStruct.Y_density = 72;
  159507. jpeg_set_defaults (&jpegCompStruct);
  159508. jpegCompStruct.dct_method = JDCT_FLOAT;
  159509. jpegCompStruct.optimize_coding = 1;
  159510. // jpegCompStruct.smoothing_factor = 10;
  159511. if (quality < 0.0f)
  159512. quality = 0.85f;
  159513. jpeg_set_quality (&jpegCompStruct, jlimit (0, 100, roundToInt (quality * 100.0f)), TRUE);
  159514. jpeg_start_compress (&jpegCompStruct, TRUE);
  159515. const int strideBytes = jpegCompStruct.image_width * jpegCompStruct.input_components;
  159516. JSAMPARRAY buffer = (*jpegCompStruct.mem->alloc_sarray) ((j_common_ptr) &jpegCompStruct,
  159517. JPOOL_IMAGE,
  159518. strideBytes, 1);
  159519. const Image::BitmapData srcData (image, 0, 0, jpegCompStruct.image_width, jpegCompStruct.image_height);
  159520. while (jpegCompStruct.next_scanline < jpegCompStruct.image_height)
  159521. {
  159522. const uint8* src = srcData.getLinePointer (jpegCompStruct.next_scanline);
  159523. uint8* dst = *buffer;
  159524. for (int i = jpegCompStruct.image_width; --i >= 0;)
  159525. {
  159526. *dst++ = ((const PixelRGB*) src)->getRed();
  159527. *dst++ = ((const PixelRGB*) src)->getGreen();
  159528. *dst++ = ((const PixelRGB*) src)->getBlue();
  159529. src += srcData.pixelStride;
  159530. }
  159531. jpeg_write_scanlines (&jpegCompStruct, buffer, 1);
  159532. }
  159533. jpeg_finish_compress (&jpegCompStruct);
  159534. jpeg_destroy_compress (&jpegCompStruct);
  159535. out.flush();
  159536. return true;
  159537. }
  159538. END_JUCE_NAMESPACE
  159539. /*** End of inlined file: juce_JPEGLoader.cpp ***/
  159540. /*** Start of inlined file: juce_PNGLoader.cpp ***/
  159541. #ifdef _MSC_VER
  159542. #pragma warning (push)
  159543. #pragma warning (disable: 4390 4611)
  159544. #endif
  159545. namespace zlibNamespace
  159546. {
  159547. #if JUCE_INCLUDE_ZLIB_CODE
  159548. #undef OS_CODE
  159549. #undef fdopen
  159550. #undef OS_CODE
  159551. #else
  159552. #include <zlib.h>
  159553. #endif
  159554. }
  159555. namespace pnglibNamespace
  159556. {
  159557. using namespace zlibNamespace;
  159558. #if JUCE_INCLUDE_PNGLIB_CODE
  159559. #if _MSC_VER != 1310
  159560. using ::calloc; // (causes conflict in VS.NET 2003)
  159561. using ::malloc;
  159562. using ::free;
  159563. #endif
  159564. extern "C"
  159565. {
  159566. using ::abs;
  159567. #define PNG_INTERNAL
  159568. #define NO_DUMMY_DECL
  159569. #define PNG_SETJMP_NOT_SUPPORTED
  159570. /*** Start of inlined file: png.h ***/
  159571. #ifndef PNG_H
  159572. #define PNG_H
  159573. #define PNG_LIBPNG_VER_STRING "1.2.21"
  159574. #define PNG_HEADER_VERSION_STRING \
  159575. " libpng version 1.2.21 - October 4, 2007\n"
  159576. #define PNG_LIBPNG_VER_SONUM 0
  159577. #define PNG_LIBPNG_VER_DLLNUM 13
  159578. #define PNG_LIBPNG_VER_MAJOR 1
  159579. #define PNG_LIBPNG_VER_MINOR 2
  159580. #define PNG_LIBPNG_VER_RELEASE 21
  159581. #define PNG_LIBPNG_VER_BUILD 0
  159582. #define PNG_LIBPNG_BUILD_ALPHA 1
  159583. #define PNG_LIBPNG_BUILD_BETA 2
  159584. #define PNG_LIBPNG_BUILD_RC 3
  159585. #define PNG_LIBPNG_BUILD_STABLE 4
  159586. #define PNG_LIBPNG_BUILD_RELEASE_STATUS_MASK 7
  159587. #define PNG_LIBPNG_BUILD_PATCH 8 /* Can be OR'ed with
  159588. PNG_LIBPNG_BUILD_STABLE only */
  159589. #define PNG_LIBPNG_BUILD_PRIVATE 16 /* Cannot be OR'ed with
  159590. PNG_LIBPNG_BUILD_SPECIAL */
  159591. #define PNG_LIBPNG_BUILD_SPECIAL 32 /* Cannot be OR'ed with
  159592. PNG_LIBPNG_BUILD_PRIVATE */
  159593. #define PNG_LIBPNG_BUILD_BASE_TYPE PNG_LIBPNG_BUILD_STABLE
  159594. #define PNG_LIBPNG_VER 10221 /* 1.2.21 */
  159595. #ifndef PNG_VERSION_INFO_ONLY
  159596. #endif
  159597. /*** Start of inlined file: pngconf.h ***/
  159598. #ifndef PNGCONF_H
  159599. #define PNGCONF_H
  159600. #define PNG_1_2_X
  159601. // These are some Juce config settings that should remove any unnecessary code bloat..
  159602. #define PNG_NO_STDIO 1
  159603. #define PNG_DEBUG 0
  159604. #define PNG_NO_WARNINGS 1
  159605. #define PNG_NO_ERROR_TEXT 1
  159606. #define PNG_NO_ERROR_NUMBERS 1
  159607. #define PNG_NO_USER_MEM 1
  159608. #define PNG_NO_READ_iCCP 1
  159609. #define PNG_NO_READ_UNKNOWN_CHUNKS 1
  159610. #define PNG_NO_READ_USER_CHUNKS 1
  159611. #define PNG_NO_READ_iTXt 1
  159612. #define PNG_NO_READ_sCAL 1
  159613. #define PNG_NO_READ_sPLT 1
  159614. #define png_error(a, b) png_err(a)
  159615. #define png_warning(a, b)
  159616. #define png_chunk_error(a, b) png_err(a)
  159617. #define png_chunk_warning(a, b)
  159618. #ifdef PNG_USER_CONFIG
  159619. # ifndef PNG_USER_PRIVATEBUILD
  159620. # define PNG_USER_PRIVATEBUILD
  159621. # endif
  159622. #include "pngusr.h"
  159623. #endif
  159624. #ifdef PNG_CONFIGURE_LIBPNG
  159625. #ifdef HAVE_CONFIG_H
  159626. #include "config.h"
  159627. #endif
  159628. #endif
  159629. #ifdef __STDC__
  159630. #ifdef SPECIALBUILD
  159631. # pragma message("PNG_LIBPNG_SPECIALBUILD (and deprecated SPECIALBUILD)\
  159632. are now LIBPNG reserved macros. Use PNG_USER_PRIVATEBUILD instead.")
  159633. #endif
  159634. #ifdef PRIVATEBUILD
  159635. # pragma message("PRIVATEBUILD is deprecated.\
  159636. Use PNG_USER_PRIVATEBUILD instead.")
  159637. # define PNG_USER_PRIVATEBUILD PRIVATEBUILD
  159638. #endif
  159639. #endif /* __STDC__ */
  159640. #ifndef PNG_VERSION_INFO_ONLY
  159641. # define PNG_WARN_UNINITIALIZED_ROW 1
  159642. #ifndef PNG_ZBUF_SIZE
  159643. # define PNG_ZBUF_SIZE 8192
  159644. #endif
  159645. #ifndef PNG_NO_READ_SUPPORTED
  159646. # define PNG_READ_SUPPORTED
  159647. #endif
  159648. #ifndef PNG_NO_WRITE_SUPPORTED
  159649. # define PNG_WRITE_SUPPORTED
  159650. #endif
  159651. #if !defined(PNG_1_0_X) && !defined(PNG_NO_MNG_FEATURES)
  159652. # ifndef PNG_MNG_FEATURES_SUPPORTED
  159653. # define PNG_MNG_FEATURES_SUPPORTED
  159654. # endif
  159655. #endif
  159656. #ifndef PNG_NO_FLOATING_POINT_SUPPORTED
  159657. # ifndef PNG_FLOATING_POINT_SUPPORTED
  159658. # define PNG_FLOATING_POINT_SUPPORTED
  159659. # endif
  159660. #endif
  159661. #if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K)
  159662. # define PNG_MAX_MALLOC_64K
  159663. #endif
  159664. #if defined(__CYGWIN__)
  159665. # if defined(ALL_STATIC)
  159666. # if defined(PNG_BUILD_DLL)
  159667. # undef PNG_BUILD_DLL
  159668. # endif
  159669. # if defined(PNG_USE_DLL)
  159670. # undef PNG_USE_DLL
  159671. # endif
  159672. # if defined(PNG_DLL)
  159673. # undef PNG_DLL
  159674. # endif
  159675. # if !defined(PNG_STATIC)
  159676. # define PNG_STATIC
  159677. # endif
  159678. # else
  159679. # if defined (PNG_BUILD_DLL)
  159680. # if defined(PNG_STATIC)
  159681. # undef PNG_STATIC
  159682. # endif
  159683. # if defined(PNG_USE_DLL)
  159684. # undef PNG_USE_DLL
  159685. # endif
  159686. # if !defined(PNG_DLL)
  159687. # define PNG_DLL
  159688. # endif
  159689. # else
  159690. # if defined(PNG_STATIC)
  159691. # if defined(PNG_USE_DLL)
  159692. # undef PNG_USE_DLL
  159693. # endif
  159694. # if defined(PNG_DLL)
  159695. # undef PNG_DLL
  159696. # endif
  159697. # else
  159698. # if !defined(PNG_USE_DLL)
  159699. # define PNG_USE_DLL
  159700. # endif
  159701. # if !defined(PNG_DLL)
  159702. # define PNG_DLL
  159703. # endif
  159704. # endif
  159705. # endif
  159706. # endif
  159707. #endif
  159708. #if defined(_WIN32_WCE)
  159709. # include <windows.h>
  159710. # define PNG_NO_CONSOLE_IO
  159711. # ifdef PNG_DEBUG
  159712. # undef PNG_DEBUG
  159713. # endif
  159714. #endif
  159715. #ifdef PNG_BUILD_DLL
  159716. # ifndef PNG_CONSOLE_IO_SUPPORTED
  159717. # ifndef PNG_NO_CONSOLE_IO
  159718. # define PNG_NO_CONSOLE_IO
  159719. # endif
  159720. # endif
  159721. #endif
  159722. # ifdef PNG_NO_STDIO
  159723. # ifndef PNG_NO_CONSOLE_IO
  159724. # define PNG_NO_CONSOLE_IO
  159725. # endif
  159726. # ifdef PNG_DEBUG
  159727. # if (PNG_DEBUG > 0)
  159728. # include <stdio.h>
  159729. # endif
  159730. # endif
  159731. # else
  159732. # if !defined(_WIN32_WCE)
  159733. # include <stdio.h>
  159734. # endif
  159735. # endif
  159736. #ifndef PNGARG
  159737. #ifdef OF /* zlib prototype munger */
  159738. # define PNGARG(arglist) OF(arglist)
  159739. #else
  159740. #ifdef _NO_PROTO
  159741. # define PNGARG(arglist) ()
  159742. # ifndef PNG_TYPECAST_NULL
  159743. # define PNG_TYPECAST_NULL
  159744. # endif
  159745. #else
  159746. # define PNGARG(arglist) arglist
  159747. #endif /* _NO_PROTO */
  159748. #endif /* OF */
  159749. #endif /* PNGARG */
  159750. #ifndef MACOS
  159751. # if (defined(__MWERKS__) && defined(macintosh)) || defined(applec) || \
  159752. defined(THINK_C) || defined(__SC__) || defined(TARGET_OS_MAC)
  159753. # define MACOS
  159754. # endif
  159755. #endif
  159756. #if !defined(MACOS) && !defined(RISCOS) && !defined(_WIN32_WCE)
  159757. # include <sys/types.h>
  159758. #endif
  159759. #if !defined(PNG_SETJMP_NOT_SUPPORTED) && !defined(PNG_NO_SETJMP_SUPPORTED)
  159760. # define PNG_SETJMP_SUPPORTED
  159761. #endif
  159762. #ifdef PNG_SETJMP_SUPPORTED
  159763. # ifdef __linux__
  159764. # ifdef _BSD_SOURCE
  159765. # define PNG_SAVE_BSD_SOURCE
  159766. # undef _BSD_SOURCE
  159767. # endif
  159768. # ifdef _SETJMP_H
  159769. __png.h__ already includes setjmp.h;
  159770. __dont__ include it again.;
  159771. # endif
  159772. # endif /* __linux__ */
  159773. # include <setjmp.h>
  159774. # ifdef __linux__
  159775. # ifdef PNG_SAVE_BSD_SOURCE
  159776. # define _BSD_SOURCE
  159777. # undef PNG_SAVE_BSD_SOURCE
  159778. # endif
  159779. # endif /* __linux__ */
  159780. #endif /* PNG_SETJMP_SUPPORTED */
  159781. #ifdef BSD
  159782. #if ! JUCE_MAC
  159783. # include <strings.h>
  159784. #endif
  159785. #else
  159786. # include <string.h>
  159787. #endif
  159788. #ifdef PNG_INTERNAL
  159789. #include <stdlib.h>
  159790. #define PNG_EXTERN
  159791. #if defined(PNG_FLOATING_POINT_SUPPORTED)
  159792. # if defined(MACOS)
  159793. # if !defined(__MATH_H__) && !defined(__MATH_H) && !defined(__cmath__)
  159794. # include <fp.h>
  159795. # endif
  159796. # else
  159797. # include <math.h>
  159798. # endif
  159799. # if defined(_AMIGA) && defined(__SASC) && defined(_M68881)
  159800. # include <m68881.h>
  159801. # endif
  159802. #endif
  159803. #if (defined(__MWERKS__) && defined(WIN32)) || defined(__STDC__)
  159804. # define PNG_ALWAYS_EXTERN
  159805. #endif
  159806. #if defined(__TURBOC__) && defined(__MSDOS__)
  159807. # include <mem.h>
  159808. # include <alloc.h>
  159809. #endif
  159810. #if defined(_MSC_VER) && (defined(WIN32) || defined(_Windows) || \
  159811. defined(_WINDOWS) || defined(_WIN32) || defined(__WIN32__))
  159812. # include <malloc.h>
  159813. #endif
  159814. #ifndef PNG_DITHER_RED_BITS
  159815. # define PNG_DITHER_RED_BITS 5
  159816. #endif
  159817. #ifndef PNG_DITHER_GREEN_BITS
  159818. # define PNG_DITHER_GREEN_BITS 5
  159819. #endif
  159820. #ifndef PNG_DITHER_BLUE_BITS
  159821. # define PNG_DITHER_BLUE_BITS 5
  159822. #endif
  159823. #ifndef PNG_MAX_GAMMA_8
  159824. # define PNG_MAX_GAMMA_8 11
  159825. #endif
  159826. #ifndef PNG_GAMMA_THRESHOLD
  159827. # define PNG_GAMMA_THRESHOLD 0.05
  159828. #endif
  159829. #endif /* PNG_INTERNAL */
  159830. #ifndef PNG_NO_CONST
  159831. # define PNG_CONST const
  159832. #else
  159833. # define PNG_CONST
  159834. #endif
  159835. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  159836. # ifndef PNG_NO_iTXt_SUPPORTED
  159837. # define PNG_NO_iTXt_SUPPORTED
  159838. # endif
  159839. # ifndef PNG_NO_READ_iTXt
  159840. # define PNG_NO_READ_iTXt
  159841. # endif
  159842. # ifndef PNG_NO_WRITE_iTXt
  159843. # define PNG_NO_WRITE_iTXt
  159844. # endif
  159845. #endif
  159846. #if !defined(PNG_NO_iTXt_SUPPORTED)
  159847. # if !defined(PNG_READ_iTXt_SUPPORTED) && !defined(PNG_NO_READ_iTXt)
  159848. # define PNG_READ_iTXt
  159849. # endif
  159850. # if !defined(PNG_WRITE_iTXt_SUPPORTED) && !defined(PNG_NO_WRITE_iTXt)
  159851. # define PNG_WRITE_iTXt
  159852. # endif
  159853. #endif
  159854. #ifdef PNG_LEGACY_SUPPORTED
  159855. # define PNG_NO_FREE_ME
  159856. # define PNG_NO_READ_UNKNOWN_CHUNKS
  159857. # define PNG_NO_WRITE_UNKNOWN_CHUNKS
  159858. # define PNG_NO_READ_USER_CHUNKS
  159859. # define PNG_NO_READ_iCCP
  159860. # define PNG_NO_WRITE_iCCP
  159861. # define PNG_NO_READ_iTXt
  159862. # define PNG_NO_WRITE_iTXt
  159863. # define PNG_NO_READ_sCAL
  159864. # define PNG_NO_WRITE_sCAL
  159865. # define PNG_NO_READ_sPLT
  159866. # define PNG_NO_WRITE_sPLT
  159867. # define PNG_NO_INFO_IMAGE
  159868. # define PNG_NO_READ_RGB_TO_GRAY
  159869. # define PNG_NO_READ_USER_TRANSFORM
  159870. # define PNG_NO_WRITE_USER_TRANSFORM
  159871. # define PNG_NO_USER_MEM
  159872. # define PNG_NO_READ_EMPTY_PLTE
  159873. # define PNG_NO_MNG_FEATURES
  159874. # define PNG_NO_FIXED_POINT_SUPPORTED
  159875. #endif
  159876. #if !defined(PNG_FLOATING_POINT_SUPPORTED) || \
  159877. !defined(PNG_NO_FIXED_POINT_SUPPORTED)
  159878. # define PNG_FIXED_POINT_SUPPORTED
  159879. #endif
  159880. #ifndef PNG_NO_FREE_ME
  159881. # define PNG_FREE_ME_SUPPORTED
  159882. #endif
  159883. #if defined(PNG_READ_SUPPORTED)
  159884. #if !defined(PNG_READ_TRANSFORMS_NOT_SUPPORTED) && \
  159885. !defined(PNG_NO_READ_TRANSFORMS)
  159886. # define PNG_READ_TRANSFORMS_SUPPORTED
  159887. #endif
  159888. #ifdef PNG_READ_TRANSFORMS_SUPPORTED
  159889. # ifndef PNG_NO_READ_EXPAND
  159890. # define PNG_READ_EXPAND_SUPPORTED
  159891. # endif
  159892. # ifndef PNG_NO_READ_SHIFT
  159893. # define PNG_READ_SHIFT_SUPPORTED
  159894. # endif
  159895. # ifndef PNG_NO_READ_PACK
  159896. # define PNG_READ_PACK_SUPPORTED
  159897. # endif
  159898. # ifndef PNG_NO_READ_BGR
  159899. # define PNG_READ_BGR_SUPPORTED
  159900. # endif
  159901. # ifndef PNG_NO_READ_SWAP
  159902. # define PNG_READ_SWAP_SUPPORTED
  159903. # endif
  159904. # ifndef PNG_NO_READ_PACKSWAP
  159905. # define PNG_READ_PACKSWAP_SUPPORTED
  159906. # endif
  159907. # ifndef PNG_NO_READ_INVERT
  159908. # define PNG_READ_INVERT_SUPPORTED
  159909. # endif
  159910. # ifndef PNG_NO_READ_DITHER
  159911. # define PNG_READ_DITHER_SUPPORTED
  159912. # endif
  159913. # ifndef PNG_NO_READ_BACKGROUND
  159914. # define PNG_READ_BACKGROUND_SUPPORTED
  159915. # endif
  159916. # ifndef PNG_NO_READ_16_TO_8
  159917. # define PNG_READ_16_TO_8_SUPPORTED
  159918. # endif
  159919. # ifndef PNG_NO_READ_FILLER
  159920. # define PNG_READ_FILLER_SUPPORTED
  159921. # endif
  159922. # ifndef PNG_NO_READ_GAMMA
  159923. # define PNG_READ_GAMMA_SUPPORTED
  159924. # endif
  159925. # ifndef PNG_NO_READ_GRAY_TO_RGB
  159926. # define PNG_READ_GRAY_TO_RGB_SUPPORTED
  159927. # endif
  159928. # ifndef PNG_NO_READ_SWAP_ALPHA
  159929. # define PNG_READ_SWAP_ALPHA_SUPPORTED
  159930. # endif
  159931. # ifndef PNG_NO_READ_INVERT_ALPHA
  159932. # define PNG_READ_INVERT_ALPHA_SUPPORTED
  159933. # endif
  159934. # ifndef PNG_NO_READ_STRIP_ALPHA
  159935. # define PNG_READ_STRIP_ALPHA_SUPPORTED
  159936. # endif
  159937. # ifndef PNG_NO_READ_USER_TRANSFORM
  159938. # define PNG_READ_USER_TRANSFORM_SUPPORTED
  159939. # endif
  159940. # ifndef PNG_NO_READ_RGB_TO_GRAY
  159941. # define PNG_READ_RGB_TO_GRAY_SUPPORTED
  159942. # endif
  159943. #endif /* PNG_READ_TRANSFORMS_SUPPORTED */
  159944. #if !defined(PNG_NO_PROGRESSIVE_READ) && \
  159945. !defined(PNG_PROGRESSIVE_READ_SUPPORTED) /* if you don't do progressive */
  159946. # define PNG_PROGRESSIVE_READ_SUPPORTED /* reading. This is not talking */
  159947. #endif /* about interlacing capability! You'll */
  159948. #define PNG_READ_INTERLACING_SUPPORTED /* required in PNG-compliant decoders */
  159949. #ifndef PNG_NO_READ_COMPOSITE_NODIV
  159950. # ifndef PNG_NO_READ_COMPOSITED_NODIV /* libpng-1.0.x misspelling */
  159951. # define PNG_READ_COMPOSITE_NODIV_SUPPORTED /* well tested on Intel, SGI */
  159952. # endif
  159953. #endif
  159954. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  159955. #ifndef PNG_NO_READ_EMPTY_PLTE
  159956. # define PNG_READ_EMPTY_PLTE_SUPPORTED
  159957. #endif
  159958. #endif
  159959. #endif /* PNG_READ_SUPPORTED */
  159960. #if defined(PNG_WRITE_SUPPORTED)
  159961. # if !defined(PNG_WRITE_TRANSFORMS_NOT_SUPPORTED) && \
  159962. !defined(PNG_NO_WRITE_TRANSFORMS)
  159963. # define PNG_WRITE_TRANSFORMS_SUPPORTED
  159964. #endif
  159965. #ifdef PNG_WRITE_TRANSFORMS_SUPPORTED
  159966. # ifndef PNG_NO_WRITE_SHIFT
  159967. # define PNG_WRITE_SHIFT_SUPPORTED
  159968. # endif
  159969. # ifndef PNG_NO_WRITE_PACK
  159970. # define PNG_WRITE_PACK_SUPPORTED
  159971. # endif
  159972. # ifndef PNG_NO_WRITE_BGR
  159973. # define PNG_WRITE_BGR_SUPPORTED
  159974. # endif
  159975. # ifndef PNG_NO_WRITE_SWAP
  159976. # define PNG_WRITE_SWAP_SUPPORTED
  159977. # endif
  159978. # ifndef PNG_NO_WRITE_PACKSWAP
  159979. # define PNG_WRITE_PACKSWAP_SUPPORTED
  159980. # endif
  159981. # ifndef PNG_NO_WRITE_INVERT
  159982. # define PNG_WRITE_INVERT_SUPPORTED
  159983. # endif
  159984. # ifndef PNG_NO_WRITE_FILLER
  159985. # define PNG_WRITE_FILLER_SUPPORTED /* same as WRITE_STRIP_ALPHA */
  159986. # endif
  159987. # ifndef PNG_NO_WRITE_SWAP_ALPHA
  159988. # define PNG_WRITE_SWAP_ALPHA_SUPPORTED
  159989. # endif
  159990. # ifndef PNG_NO_WRITE_INVERT_ALPHA
  159991. # define PNG_WRITE_INVERT_ALPHA_SUPPORTED
  159992. # endif
  159993. # ifndef PNG_NO_WRITE_USER_TRANSFORM
  159994. # define PNG_WRITE_USER_TRANSFORM_SUPPORTED
  159995. # endif
  159996. #endif /* PNG_WRITE_TRANSFORMS_SUPPORTED */
  159997. #if !defined(PNG_NO_WRITE_INTERLACING_SUPPORTED) && \
  159998. !defined(PNG_WRITE_INTERLACING_SUPPORTED)
  159999. #define PNG_WRITE_INTERLACING_SUPPORTED /* not required for PNG-compliant
  160000. encoders, but can cause trouble
  160001. if left undefined */
  160002. #endif
  160003. #if !defined(PNG_NO_WRITE_WEIGHTED_FILTER) && \
  160004. !defined(PNG_WRITE_WEIGHTED_FILTER) && \
  160005. defined(PNG_FLOATING_POINT_SUPPORTED)
  160006. # define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
  160007. #endif
  160008. #ifndef PNG_NO_WRITE_FLUSH
  160009. # define PNG_WRITE_FLUSH_SUPPORTED
  160010. #endif
  160011. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  160012. #ifndef PNG_NO_WRITE_EMPTY_PLTE
  160013. # define PNG_WRITE_EMPTY_PLTE_SUPPORTED
  160014. #endif
  160015. #endif
  160016. #endif /* PNG_WRITE_SUPPORTED */
  160017. #ifndef PNG_1_0_X
  160018. # ifndef PNG_NO_ERROR_NUMBERS
  160019. # define PNG_ERROR_NUMBERS_SUPPORTED
  160020. # endif
  160021. #endif /* PNG_1_0_X */
  160022. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  160023. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  160024. # ifndef PNG_NO_USER_TRANSFORM_PTR
  160025. # define PNG_USER_TRANSFORM_PTR_SUPPORTED
  160026. # endif
  160027. #endif
  160028. #ifndef PNG_NO_STDIO
  160029. # define PNG_TIME_RFC1123_SUPPORTED
  160030. #endif
  160031. #if !defined(PNG_NO_EASY_ACCESS) && !defined(PNG_EASY_ACCESS_SUPPORTED)
  160032. # define PNG_EASY_ACCESS_SUPPORTED
  160033. #endif
  160034. #if defined(PNG_READ_SUPPORTED) && !defined(PNG_NO_OPTIMIZED_CODE)
  160035. # ifndef PNG_OPTIMIZED_CODE_SUPPORTED
  160036. # define PNG_OPTIMIZED_CODE_SUPPORTED
  160037. # endif
  160038. #endif
  160039. #if defined(PNG_READ_SUPPORTED) && !defined(PNG_NO_ASSEMBLER_CODE)
  160040. # ifndef PNG_ASSEMBLER_CODE_SUPPORTED
  160041. # define PNG_ASSEMBLER_CODE_SUPPORTED
  160042. # endif
  160043. # if defined(__GNUC__) && defined(__x86_64__) && (__GNUC__ < 4)
  160044. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  160045. # define PNG_NO_MMX_CODE
  160046. # endif
  160047. # endif
  160048. # if defined(__APPLE__)
  160049. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  160050. # define PNG_NO_MMX_CODE
  160051. # endif
  160052. # endif
  160053. # if (defined(__MWERKS__) && ((__MWERKS__ < 0x0900) || macintosh))
  160054. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  160055. # define PNG_NO_MMX_CODE
  160056. # endif
  160057. # endif
  160058. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  160059. # define PNG_MMX_CODE_SUPPORTED
  160060. # endif
  160061. #endif
  160062. #if !defined(PNG_1_0_X)
  160063. #if !defined(PNG_NO_USER_MEM) && !defined(PNG_USER_MEM_SUPPORTED)
  160064. # define PNG_USER_MEM_SUPPORTED
  160065. #endif
  160066. #endif /* PNG_1_0_X */
  160067. #if !defined(PNG_1_0_X)
  160068. #ifndef PNG_SET_USER_LIMITS_SUPPORTED
  160069. #if !defined(PNG_NO_SET_USER_LIMITS) && !defined(PNG_SET_USER_LIMITS_SUPPORTED)
  160070. # define PNG_SET_USER_LIMITS_SUPPORTED
  160071. #endif
  160072. #endif
  160073. #endif /* PNG_1_0_X */
  160074. #ifndef PNG_USER_WIDTH_MAX
  160075. # define PNG_USER_WIDTH_MAX 1000000L
  160076. #endif
  160077. #ifndef PNG_USER_HEIGHT_MAX
  160078. # define PNG_USER_HEIGHT_MAX 1000000L
  160079. #endif
  160080. #if defined(PNG_READ_SUPPORTED) && \
  160081. !defined(PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \
  160082. !defined(PNG_NO_READ_ANCILLARY_CHUNKS)
  160083. # define PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
  160084. #endif
  160085. #if defined(PNG_WRITE_SUPPORTED) && \
  160086. !defined(PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \
  160087. !defined(PNG_NO_WRITE_ANCILLARY_CHUNKS)
  160088. # define PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
  160089. #endif
  160090. #ifdef PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
  160091. #ifdef PNG_NO_READ_TEXT
  160092. # define PNG_NO_READ_iTXt
  160093. # define PNG_NO_READ_tEXt
  160094. # define PNG_NO_READ_zTXt
  160095. #endif
  160096. #ifndef PNG_NO_READ_bKGD
  160097. # define PNG_READ_bKGD_SUPPORTED
  160098. # define PNG_bKGD_SUPPORTED
  160099. #endif
  160100. #ifndef PNG_NO_READ_cHRM
  160101. # define PNG_READ_cHRM_SUPPORTED
  160102. # define PNG_cHRM_SUPPORTED
  160103. #endif
  160104. #ifndef PNG_NO_READ_gAMA
  160105. # define PNG_READ_gAMA_SUPPORTED
  160106. # define PNG_gAMA_SUPPORTED
  160107. #endif
  160108. #ifndef PNG_NO_READ_hIST
  160109. # define PNG_READ_hIST_SUPPORTED
  160110. # define PNG_hIST_SUPPORTED
  160111. #endif
  160112. #ifndef PNG_NO_READ_iCCP
  160113. # define PNG_READ_iCCP_SUPPORTED
  160114. # define PNG_iCCP_SUPPORTED
  160115. #endif
  160116. #ifndef PNG_NO_READ_iTXt
  160117. # ifndef PNG_READ_iTXt_SUPPORTED
  160118. # define PNG_READ_iTXt_SUPPORTED
  160119. # endif
  160120. # ifndef PNG_iTXt_SUPPORTED
  160121. # define PNG_iTXt_SUPPORTED
  160122. # endif
  160123. #endif
  160124. #ifndef PNG_NO_READ_oFFs
  160125. # define PNG_READ_oFFs_SUPPORTED
  160126. # define PNG_oFFs_SUPPORTED
  160127. #endif
  160128. #ifndef PNG_NO_READ_pCAL
  160129. # define PNG_READ_pCAL_SUPPORTED
  160130. # define PNG_pCAL_SUPPORTED
  160131. #endif
  160132. #ifndef PNG_NO_READ_sCAL
  160133. # define PNG_READ_sCAL_SUPPORTED
  160134. # define PNG_sCAL_SUPPORTED
  160135. #endif
  160136. #ifndef PNG_NO_READ_pHYs
  160137. # define PNG_READ_pHYs_SUPPORTED
  160138. # define PNG_pHYs_SUPPORTED
  160139. #endif
  160140. #ifndef PNG_NO_READ_sBIT
  160141. # define PNG_READ_sBIT_SUPPORTED
  160142. # define PNG_sBIT_SUPPORTED
  160143. #endif
  160144. #ifndef PNG_NO_READ_sPLT
  160145. # define PNG_READ_sPLT_SUPPORTED
  160146. # define PNG_sPLT_SUPPORTED
  160147. #endif
  160148. #ifndef PNG_NO_READ_sRGB
  160149. # define PNG_READ_sRGB_SUPPORTED
  160150. # define PNG_sRGB_SUPPORTED
  160151. #endif
  160152. #ifndef PNG_NO_READ_tEXt
  160153. # define PNG_READ_tEXt_SUPPORTED
  160154. # define PNG_tEXt_SUPPORTED
  160155. #endif
  160156. #ifndef PNG_NO_READ_tIME
  160157. # define PNG_READ_tIME_SUPPORTED
  160158. # define PNG_tIME_SUPPORTED
  160159. #endif
  160160. #ifndef PNG_NO_READ_tRNS
  160161. # define PNG_READ_tRNS_SUPPORTED
  160162. # define PNG_tRNS_SUPPORTED
  160163. #endif
  160164. #ifndef PNG_NO_READ_zTXt
  160165. # define PNG_READ_zTXt_SUPPORTED
  160166. # define PNG_zTXt_SUPPORTED
  160167. #endif
  160168. #ifndef PNG_NO_READ_UNKNOWN_CHUNKS
  160169. # define PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
  160170. # ifndef PNG_UNKNOWN_CHUNKS_SUPPORTED
  160171. # define PNG_UNKNOWN_CHUNKS_SUPPORTED
  160172. # endif
  160173. # ifndef PNG_NO_HANDLE_AS_UNKNOWN
  160174. # define PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  160175. # endif
  160176. #endif
  160177. #if !defined(PNG_NO_READ_USER_CHUNKS) && \
  160178. defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  160179. # define PNG_READ_USER_CHUNKS_SUPPORTED
  160180. # define PNG_USER_CHUNKS_SUPPORTED
  160181. # ifdef PNG_NO_READ_UNKNOWN_CHUNKS
  160182. # undef PNG_NO_READ_UNKNOWN_CHUNKS
  160183. # endif
  160184. # ifdef PNG_NO_HANDLE_AS_UNKNOWN
  160185. # undef PNG_NO_HANDLE_AS_UNKNOWN
  160186. # endif
  160187. #endif
  160188. #ifndef PNG_NO_READ_OPT_PLTE
  160189. # define PNG_READ_OPT_PLTE_SUPPORTED /* only affects support of the */
  160190. #endif /* optional PLTE chunk in RGB and RGBA images */
  160191. #if defined(PNG_READ_iTXt_SUPPORTED) || defined(PNG_READ_tEXt_SUPPORTED) || \
  160192. defined(PNG_READ_zTXt_SUPPORTED)
  160193. # define PNG_READ_TEXT_SUPPORTED
  160194. # define PNG_TEXT_SUPPORTED
  160195. #endif
  160196. #endif /* PNG_READ_ANCILLARY_CHUNKS_SUPPORTED */
  160197. #ifdef PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
  160198. #ifdef PNG_NO_WRITE_TEXT
  160199. # define PNG_NO_WRITE_iTXt
  160200. # define PNG_NO_WRITE_tEXt
  160201. # define PNG_NO_WRITE_zTXt
  160202. #endif
  160203. #ifndef PNG_NO_WRITE_bKGD
  160204. # define PNG_WRITE_bKGD_SUPPORTED
  160205. # ifndef PNG_bKGD_SUPPORTED
  160206. # define PNG_bKGD_SUPPORTED
  160207. # endif
  160208. #endif
  160209. #ifndef PNG_NO_WRITE_cHRM
  160210. # define PNG_WRITE_cHRM_SUPPORTED
  160211. # ifndef PNG_cHRM_SUPPORTED
  160212. # define PNG_cHRM_SUPPORTED
  160213. # endif
  160214. #endif
  160215. #ifndef PNG_NO_WRITE_gAMA
  160216. # define PNG_WRITE_gAMA_SUPPORTED
  160217. # ifndef PNG_gAMA_SUPPORTED
  160218. # define PNG_gAMA_SUPPORTED
  160219. # endif
  160220. #endif
  160221. #ifndef PNG_NO_WRITE_hIST
  160222. # define PNG_WRITE_hIST_SUPPORTED
  160223. # ifndef PNG_hIST_SUPPORTED
  160224. # define PNG_hIST_SUPPORTED
  160225. # endif
  160226. #endif
  160227. #ifndef PNG_NO_WRITE_iCCP
  160228. # define PNG_WRITE_iCCP_SUPPORTED
  160229. # ifndef PNG_iCCP_SUPPORTED
  160230. # define PNG_iCCP_SUPPORTED
  160231. # endif
  160232. #endif
  160233. #ifndef PNG_NO_WRITE_iTXt
  160234. # ifndef PNG_WRITE_iTXt_SUPPORTED
  160235. # define PNG_WRITE_iTXt_SUPPORTED
  160236. # endif
  160237. # ifndef PNG_iTXt_SUPPORTED
  160238. # define PNG_iTXt_SUPPORTED
  160239. # endif
  160240. #endif
  160241. #ifndef PNG_NO_WRITE_oFFs
  160242. # define PNG_WRITE_oFFs_SUPPORTED
  160243. # ifndef PNG_oFFs_SUPPORTED
  160244. # define PNG_oFFs_SUPPORTED
  160245. # endif
  160246. #endif
  160247. #ifndef PNG_NO_WRITE_pCAL
  160248. # define PNG_WRITE_pCAL_SUPPORTED
  160249. # ifndef PNG_pCAL_SUPPORTED
  160250. # define PNG_pCAL_SUPPORTED
  160251. # endif
  160252. #endif
  160253. #ifndef PNG_NO_WRITE_sCAL
  160254. # define PNG_WRITE_sCAL_SUPPORTED
  160255. # ifndef PNG_sCAL_SUPPORTED
  160256. # define PNG_sCAL_SUPPORTED
  160257. # endif
  160258. #endif
  160259. #ifndef PNG_NO_WRITE_pHYs
  160260. # define PNG_WRITE_pHYs_SUPPORTED
  160261. # ifndef PNG_pHYs_SUPPORTED
  160262. # define PNG_pHYs_SUPPORTED
  160263. # endif
  160264. #endif
  160265. #ifndef PNG_NO_WRITE_sBIT
  160266. # define PNG_WRITE_sBIT_SUPPORTED
  160267. # ifndef PNG_sBIT_SUPPORTED
  160268. # define PNG_sBIT_SUPPORTED
  160269. # endif
  160270. #endif
  160271. #ifndef PNG_NO_WRITE_sPLT
  160272. # define PNG_WRITE_sPLT_SUPPORTED
  160273. # ifndef PNG_sPLT_SUPPORTED
  160274. # define PNG_sPLT_SUPPORTED
  160275. # endif
  160276. #endif
  160277. #ifndef PNG_NO_WRITE_sRGB
  160278. # define PNG_WRITE_sRGB_SUPPORTED
  160279. # ifndef PNG_sRGB_SUPPORTED
  160280. # define PNG_sRGB_SUPPORTED
  160281. # endif
  160282. #endif
  160283. #ifndef PNG_NO_WRITE_tEXt
  160284. # define PNG_WRITE_tEXt_SUPPORTED
  160285. # ifndef PNG_tEXt_SUPPORTED
  160286. # define PNG_tEXt_SUPPORTED
  160287. # endif
  160288. #endif
  160289. #ifndef PNG_NO_WRITE_tIME
  160290. # define PNG_WRITE_tIME_SUPPORTED
  160291. # ifndef PNG_tIME_SUPPORTED
  160292. # define PNG_tIME_SUPPORTED
  160293. # endif
  160294. #endif
  160295. #ifndef PNG_NO_WRITE_tRNS
  160296. # define PNG_WRITE_tRNS_SUPPORTED
  160297. # ifndef PNG_tRNS_SUPPORTED
  160298. # define PNG_tRNS_SUPPORTED
  160299. # endif
  160300. #endif
  160301. #ifndef PNG_NO_WRITE_zTXt
  160302. # define PNG_WRITE_zTXt_SUPPORTED
  160303. # ifndef PNG_zTXt_SUPPORTED
  160304. # define PNG_zTXt_SUPPORTED
  160305. # endif
  160306. #endif
  160307. #ifndef PNG_NO_WRITE_UNKNOWN_CHUNKS
  160308. # define PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
  160309. # ifndef PNG_UNKNOWN_CHUNKS_SUPPORTED
  160310. # define PNG_UNKNOWN_CHUNKS_SUPPORTED
  160311. # endif
  160312. # ifndef PNG_NO_HANDLE_AS_UNKNOWN
  160313. # ifndef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  160314. # define PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  160315. # endif
  160316. # endif
  160317. #endif
  160318. #if defined(PNG_WRITE_iTXt_SUPPORTED) || defined(PNG_WRITE_tEXt_SUPPORTED) || \
  160319. defined(PNG_WRITE_zTXt_SUPPORTED)
  160320. # define PNG_WRITE_TEXT_SUPPORTED
  160321. # ifndef PNG_TEXT_SUPPORTED
  160322. # define PNG_TEXT_SUPPORTED
  160323. # endif
  160324. #endif
  160325. #endif /* PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED */
  160326. #ifndef PNG_NO_INFO_IMAGE
  160327. # define PNG_INFO_IMAGE_SUPPORTED
  160328. #endif
  160329. #if defined(PNG_tIME_SUPPORTED)
  160330. # if !defined(_WIN32_WCE)
  160331. # include <time.h>
  160332. # endif
  160333. #endif
  160334. typedef unsigned long png_uint_32;
  160335. typedef long png_int_32;
  160336. typedef unsigned short png_uint_16;
  160337. typedef short png_int_16;
  160338. typedef unsigned char png_byte;
  160339. #ifdef PNG_SIZE_T
  160340. typedef PNG_SIZE_T png_size_t;
  160341. # define png_sizeof(x) png_convert_size(sizeof (x))
  160342. #else
  160343. typedef size_t png_size_t;
  160344. # define png_sizeof(x) sizeof (x)
  160345. #endif
  160346. #ifdef __BORLANDC__
  160347. # if defined(__LARGE__) || defined(__HUGE__) || defined(__COMPACT__)
  160348. # define LDATA 1
  160349. # else
  160350. # define LDATA 0
  160351. # endif
  160352. # if !defined(__WIN32__) && !defined(__FLAT__) && !defined(__CYGWIN__)
  160353. # define PNG_MAX_MALLOC_64K
  160354. # if (LDATA != 1)
  160355. # ifndef FAR
  160356. # define FAR __far
  160357. # endif
  160358. # define USE_FAR_KEYWORD
  160359. # endif /* LDATA != 1 */
  160360. # endif /* __WIN32__, __FLAT__, __CYGWIN__ */
  160361. #endif /* __BORLANDC__ */
  160362. #if defined(FAR)
  160363. # if defined(M_I86MM)
  160364. # define USE_FAR_KEYWORD
  160365. # define FARDATA FAR
  160366. # include <dos.h>
  160367. # endif
  160368. #endif
  160369. #ifndef FAR
  160370. # define FAR
  160371. #endif
  160372. #ifndef FARDATA
  160373. # define FARDATA
  160374. #endif
  160375. typedef png_int_32 png_fixed_point;
  160376. typedef void FAR * png_voidp;
  160377. typedef png_byte FAR * png_bytep;
  160378. typedef png_uint_32 FAR * png_uint_32p;
  160379. typedef png_int_32 FAR * png_int_32p;
  160380. typedef png_uint_16 FAR * png_uint_16p;
  160381. typedef png_int_16 FAR * png_int_16p;
  160382. typedef PNG_CONST char FAR * png_const_charp;
  160383. typedef char FAR * png_charp;
  160384. typedef png_fixed_point FAR * png_fixed_point_p;
  160385. #ifndef PNG_NO_STDIO
  160386. #if defined(_WIN32_WCE)
  160387. typedef HANDLE png_FILE_p;
  160388. #else
  160389. typedef FILE * png_FILE_p;
  160390. #endif
  160391. #endif
  160392. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160393. typedef double FAR * png_doublep;
  160394. #endif
  160395. typedef png_byte FAR * FAR * png_bytepp;
  160396. typedef png_uint_32 FAR * FAR * png_uint_32pp;
  160397. typedef png_int_32 FAR * FAR * png_int_32pp;
  160398. typedef png_uint_16 FAR * FAR * png_uint_16pp;
  160399. typedef png_int_16 FAR * FAR * png_int_16pp;
  160400. typedef PNG_CONST char FAR * FAR * png_const_charpp;
  160401. typedef char FAR * FAR * png_charpp;
  160402. typedef png_fixed_point FAR * FAR * png_fixed_point_pp;
  160403. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160404. typedef double FAR * FAR * png_doublepp;
  160405. #endif
  160406. typedef char FAR * FAR * FAR * png_charppp;
  160407. #if 0
  160408. typedef charf * png_zcharp;
  160409. typedef charf * FAR * png_zcharpp;
  160410. typedef z_stream FAR * png_zstreamp;
  160411. #endif /* (PNG_1_0_X) || defined(PNG_1_2_X) */
  160412. #if !defined(PNG_DLL) && (defined(PNG_BUILD_DLL) || defined(PNG_USE_DLL))
  160413. # define PNG_DLL
  160414. #endif
  160415. #if defined(__CYGWIN__)
  160416. # if !defined(PNG_STATIC)
  160417. # if defined(PNG_USE_GLOBAL_ARRAYS)
  160418. # undef PNG_USE_GLOBAL_ARRAYS
  160419. # endif
  160420. # if !defined(PNG_USE_LOCAL_ARRAYS)
  160421. # define PNG_USE_LOCAL_ARRAYS
  160422. # endif
  160423. # else
  160424. # if defined(PNG_USE_LOCAL_ARRAYS) || defined(PNG_NO_GLOBAL_ARRAYS)
  160425. # if defined(PNG_USE_GLOBAL_ARRAYS)
  160426. # undef PNG_USE_GLOBAL_ARRAYS
  160427. # endif
  160428. # endif
  160429. # endif
  160430. # if !defined(PNG_USE_LOCAL_ARRAYS) && !defined(PNG_USE_GLOBAL_ARRAYS)
  160431. # define PNG_USE_LOCAL_ARRAYS
  160432. # endif
  160433. #endif
  160434. #if !defined(PNG_USE_LOCAL_ARRAYS) && !defined(PNG_USE_GLOBAL_ARRAYS)
  160435. # if defined(PNG_NO_GLOBAL_ARRAYS) || \
  160436. (defined(__GNUC__) && defined(PNG_DLL)) || defined(_MSC_VER)
  160437. # define PNG_USE_LOCAL_ARRAYS
  160438. # else
  160439. # define PNG_USE_GLOBAL_ARRAYS
  160440. # endif
  160441. #endif
  160442. #if defined(__CYGWIN__)
  160443. # undef PNGAPI
  160444. # define PNGAPI __cdecl
  160445. # undef PNG_IMPEXP
  160446. # define PNG_IMPEXP
  160447. #endif
  160448. #if defined(__MINGW32__) && !defined(PNG_MODULEDEF)
  160449. # ifndef PNG_NO_MODULEDEF
  160450. # define PNG_NO_MODULEDEF
  160451. # endif
  160452. #endif
  160453. #if !defined(PNG_IMPEXP) && defined(PNG_BUILD_DLL) && !defined(PNG_NO_MODULEDEF)
  160454. # define PNG_IMPEXP
  160455. #endif
  160456. #if defined(PNG_DLL) || defined(_DLL) || defined(__DLL__ ) || \
  160457. (( defined(_Windows) || defined(_WINDOWS) || \
  160458. defined(WIN32) || defined(_WIN32) || defined(__WIN32__) ))
  160459. # ifndef PNGAPI
  160460. # if defined(__GNUC__) || (defined (_MSC_VER) && (_MSC_VER >= 800))
  160461. # define PNGAPI __cdecl
  160462. # else
  160463. # define PNGAPI _cdecl
  160464. # endif
  160465. # endif
  160466. # if !defined(PNG_IMPEXP) && (!defined(PNG_DLL) || \
  160467. 0 /* WINCOMPILER_WITH_NO_SUPPORT_FOR_DECLIMPEXP */)
  160468. # define PNG_IMPEXP
  160469. # endif
  160470. # if !defined(PNG_IMPEXP)
  160471. # define PNG_EXPORT_TYPE1(type,symbol) PNG_IMPEXP type PNGAPI symbol
  160472. # define PNG_EXPORT_TYPE2(type,symbol) type PNG_IMPEXP PNGAPI symbol
  160473. # if defined(_MSC_VER) || defined(__BORLANDC__)
  160474. # if (_MSC_VER >= 800) || (__BORLANDC__ >= 0x500)
  160475. # define PNG_EXPORT PNG_EXPORT_TYPE1
  160476. # else
  160477. # define PNG_EXPORT PNG_EXPORT_TYPE2
  160478. # if defined(PNG_BUILD_DLL)
  160479. # define PNG_IMPEXP __export
  160480. # else
  160481. # define PNG_IMPEXP /*__import */ /* doesn't exist AFAIK in
  160482. VC++ */
  160483. # endif /* Exists in Borland C++ for
  160484. C++ classes (== huge) */
  160485. # endif
  160486. # endif
  160487. # if !defined(PNG_IMPEXP)
  160488. # if defined(PNG_BUILD_DLL)
  160489. # define PNG_IMPEXP __declspec(dllexport)
  160490. # else
  160491. # define PNG_IMPEXP __declspec(dllimport)
  160492. # endif
  160493. # endif
  160494. # endif /* PNG_IMPEXP */
  160495. #else /* !(DLL || non-cygwin WINDOWS) */
  160496. # if (defined(__IBMC__) || defined(__IBMCPP__)) && defined(__OS2__)
  160497. # ifndef PNGAPI
  160498. # define PNGAPI _System
  160499. # endif
  160500. # else
  160501. # if 0 /* ... other platforms, with other meanings */
  160502. # endif
  160503. # endif
  160504. #endif
  160505. #ifndef PNGAPI
  160506. # define PNGAPI
  160507. #endif
  160508. #ifndef PNG_IMPEXP
  160509. # define PNG_IMPEXP
  160510. #endif
  160511. #ifdef PNG_BUILDSYMS
  160512. # ifndef PNG_EXPORT
  160513. # define PNG_EXPORT(type,symbol) PNG_FUNCTION_EXPORT symbol END
  160514. # endif
  160515. # ifdef PNG_USE_GLOBAL_ARRAYS
  160516. # ifndef PNG_EXPORT_VAR
  160517. # define PNG_EXPORT_VAR(type) PNG_DATA_EXPORT
  160518. # endif
  160519. # endif
  160520. #endif
  160521. #ifndef PNG_EXPORT
  160522. # define PNG_EXPORT(type,symbol) PNG_IMPEXP type PNGAPI symbol
  160523. #endif
  160524. #ifdef PNG_USE_GLOBAL_ARRAYS
  160525. # ifndef PNG_EXPORT_VAR
  160526. # define PNG_EXPORT_VAR(type) extern PNG_IMPEXP type
  160527. # endif
  160528. #endif
  160529. #ifndef PNG_ABORT
  160530. # define PNG_ABORT() abort()
  160531. #endif
  160532. #ifdef PNG_SETJMP_SUPPORTED
  160533. # define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf)
  160534. #else
  160535. # define png_jmpbuf(png_ptr) \
  160536. (LIBPNG_WAS_COMPILED_WITH__PNG_SETJMP_NOT_SUPPORTED)
  160537. #endif
  160538. #if defined(USE_FAR_KEYWORD) /* memory model independent fns */
  160539. # define CHECK 1
  160540. # define NOCHECK 0
  160541. # define CVT_PTR(ptr) (png_far_to_near(png_ptr,ptr,CHECK))
  160542. # define CVT_PTR_NOCHECK(ptr) (png_far_to_near(png_ptr,ptr,NOCHECK))
  160543. # define png_snprintf _fsnprintf /* Added to v 1.2.19 */
  160544. # define png_strcpy _fstrcpy
  160545. # define png_strncpy _fstrncpy /* Added to v 1.2.6 */
  160546. # define png_strlen _fstrlen
  160547. # define png_memcmp _fmemcmp /* SJT: added */
  160548. # define png_memcpy _fmemcpy
  160549. # define png_memset _fmemset
  160550. #else /* use the usual functions */
  160551. # define CVT_PTR(ptr) (ptr)
  160552. # define CVT_PTR_NOCHECK(ptr) (ptr)
  160553. # ifndef PNG_NO_SNPRINTF
  160554. # ifdef _MSC_VER
  160555. # define png_snprintf _snprintf /* Added to v 1.2.19 */
  160556. # define png_snprintf2 _snprintf
  160557. # define png_snprintf6 _snprintf
  160558. # else
  160559. # define png_snprintf snprintf /* Added to v 1.2.19 */
  160560. # define png_snprintf2 snprintf
  160561. # define png_snprintf6 snprintf
  160562. # endif
  160563. # else
  160564. # define png_snprintf(s1,n,fmt,x1) sprintf(s1,fmt,x1)
  160565. # define png_snprintf2(s1,n,fmt,x1,x2) sprintf(s1,fmt,x1,x2)
  160566. # define png_snprintf6(s1,n,fmt,x1,x2,x3,x4,x5,x6) \
  160567. sprintf(s1,fmt,x1,x2,x3,x4,x5,x6)
  160568. # endif
  160569. # define png_strcpy strcpy
  160570. # define png_strncpy strncpy /* Added to v 1.2.6 */
  160571. # define png_strlen strlen
  160572. # define png_memcmp memcmp /* SJT: added */
  160573. # define png_memcpy memcpy
  160574. # define png_memset memset
  160575. #endif
  160576. #if (PNG_ZBUF_SIZE > 65536L) && defined(PNG_MAX_MALLOC_64K)
  160577. # undef PNG_ZBUF_SIZE
  160578. # define PNG_ZBUF_SIZE 65536L
  160579. #endif
  160580. #endif /* PNG_VERSION_INFO_ONLY */
  160581. #endif /* PNGCONF_H */
  160582. /*** End of inlined file: pngconf.h ***/
  160583. #ifdef _MSC_VER
  160584. #pragma warning (disable: 4996 4100)
  160585. #endif
  160586. #if defined(PNG_USER_PRIVATEBUILD)
  160587. # define PNG_LIBPNG_BUILD_TYPE \
  160588. (PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_PRIVATE)
  160589. #else
  160590. # if defined(PNG_LIBPNG_SPECIALBUILD)
  160591. # define PNG_LIBPNG_BUILD_TYPE \
  160592. (PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_SPECIAL)
  160593. # else
  160594. # define PNG_LIBPNG_BUILD_TYPE (PNG_LIBPNG_BUILD_BASE_TYPE)
  160595. # endif
  160596. #endif
  160597. #ifndef PNG_VERSION_INFO_ONLY
  160598. #ifdef __cplusplus
  160599. extern "C" {
  160600. #endif /* __cplusplus */
  160601. #ifndef PNG_NO_TYPECAST_NULL
  160602. #define int_p_NULL (int *)NULL
  160603. #define png_bytep_NULL (png_bytep)NULL
  160604. #define png_bytepp_NULL (png_bytepp)NULL
  160605. #define png_doublep_NULL (png_doublep)NULL
  160606. #define png_error_ptr_NULL (png_error_ptr)NULL
  160607. #define png_flush_ptr_NULL (png_flush_ptr)NULL
  160608. #define png_free_ptr_NULL (png_free_ptr)NULL
  160609. #define png_infopp_NULL (png_infopp)NULL
  160610. #define png_malloc_ptr_NULL (png_malloc_ptr)NULL
  160611. #define png_read_status_ptr_NULL (png_read_status_ptr)NULL
  160612. #define png_rw_ptr_NULL (png_rw_ptr)NULL
  160613. #define png_structp_NULL (png_structp)NULL
  160614. #define png_uint_16p_NULL (png_uint_16p)NULL
  160615. #define png_voidp_NULL (png_voidp)NULL
  160616. #define png_write_status_ptr_NULL (png_write_status_ptr)NULL
  160617. #else
  160618. #define int_p_NULL NULL
  160619. #define png_bytep_NULL NULL
  160620. #define png_bytepp_NULL NULL
  160621. #define png_doublep_NULL NULL
  160622. #define png_error_ptr_NULL NULL
  160623. #define png_flush_ptr_NULL NULL
  160624. #define png_free_ptr_NULL NULL
  160625. #define png_infopp_NULL NULL
  160626. #define png_malloc_ptr_NULL NULL
  160627. #define png_read_status_ptr_NULL NULL
  160628. #define png_rw_ptr_NULL NULL
  160629. #define png_structp_NULL NULL
  160630. #define png_uint_16p_NULL NULL
  160631. #define png_voidp_NULL NULL
  160632. #define png_write_status_ptr_NULL NULL
  160633. #endif
  160634. #if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN)
  160635. #ifdef PNG_USE_GLOBAL_ARRAYS
  160636. PNG_EXPORT_VAR (PNG_CONST char) png_libpng_ver[18];
  160637. #else
  160638. #define png_libpng_ver png_get_header_ver(NULL)
  160639. #endif
  160640. #ifdef PNG_USE_GLOBAL_ARRAYS
  160641. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_start[7];
  160642. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_inc[7];
  160643. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_ystart[7];
  160644. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_yinc[7];
  160645. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_mask[7];
  160646. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_dsp_mask[7];
  160647. #endif
  160648. #endif /* PNG_NO_EXTERN */
  160649. typedef struct png_color_struct
  160650. {
  160651. png_byte red;
  160652. png_byte green;
  160653. png_byte blue;
  160654. } png_color;
  160655. typedef png_color FAR * png_colorp;
  160656. typedef png_color FAR * FAR * png_colorpp;
  160657. typedef struct png_color_16_struct
  160658. {
  160659. png_byte index; /* used for palette files */
  160660. png_uint_16 red; /* for use in red green blue files */
  160661. png_uint_16 green;
  160662. png_uint_16 blue;
  160663. png_uint_16 gray; /* for use in grayscale files */
  160664. } png_color_16;
  160665. typedef png_color_16 FAR * png_color_16p;
  160666. typedef png_color_16 FAR * FAR * png_color_16pp;
  160667. typedef struct png_color_8_struct
  160668. {
  160669. png_byte red; /* for use in red green blue files */
  160670. png_byte green;
  160671. png_byte blue;
  160672. png_byte gray; /* for use in grayscale files */
  160673. png_byte alpha; /* for alpha channel files */
  160674. } png_color_8;
  160675. typedef png_color_8 FAR * png_color_8p;
  160676. typedef png_color_8 FAR * FAR * png_color_8pp;
  160677. typedef struct png_sPLT_entry_struct
  160678. {
  160679. png_uint_16 red;
  160680. png_uint_16 green;
  160681. png_uint_16 blue;
  160682. png_uint_16 alpha;
  160683. png_uint_16 frequency;
  160684. } png_sPLT_entry;
  160685. typedef png_sPLT_entry FAR * png_sPLT_entryp;
  160686. typedef png_sPLT_entry FAR * FAR * png_sPLT_entrypp;
  160687. typedef struct png_sPLT_struct
  160688. {
  160689. png_charp name; /* palette name */
  160690. png_byte depth; /* depth of palette samples */
  160691. png_sPLT_entryp entries; /* palette entries */
  160692. png_int_32 nentries; /* number of palette entries */
  160693. } png_sPLT_t;
  160694. typedef png_sPLT_t FAR * png_sPLT_tp;
  160695. typedef png_sPLT_t FAR * FAR * png_sPLT_tpp;
  160696. #ifdef PNG_TEXT_SUPPORTED
  160697. typedef struct png_text_struct
  160698. {
  160699. int compression; /* compression value:
  160700. -1: tEXt, none
  160701. 0: zTXt, deflate
  160702. 1: iTXt, none
  160703. 2: iTXt, deflate */
  160704. png_charp key; /* keyword, 1-79 character description of "text" */
  160705. png_charp text; /* comment, may be an empty string (ie "")
  160706. or a NULL pointer */
  160707. png_size_t text_length; /* length of the text string */
  160708. #ifdef PNG_iTXt_SUPPORTED
  160709. png_size_t itxt_length; /* length of the itxt string */
  160710. png_charp lang; /* language code, 0-79 characters
  160711. or a NULL pointer */
  160712. png_charp lang_key; /* keyword translated UTF-8 string, 0 or more
  160713. chars or a NULL pointer */
  160714. #endif
  160715. } png_text;
  160716. typedef png_text FAR * png_textp;
  160717. typedef png_text FAR * FAR * png_textpp;
  160718. #endif
  160719. #define PNG_TEXT_COMPRESSION_NONE_WR -3
  160720. #define PNG_TEXT_COMPRESSION_zTXt_WR -2
  160721. #define PNG_TEXT_COMPRESSION_NONE -1
  160722. #define PNG_TEXT_COMPRESSION_zTXt 0
  160723. #define PNG_ITXT_COMPRESSION_NONE 1
  160724. #define PNG_ITXT_COMPRESSION_zTXt 2
  160725. #define PNG_TEXT_COMPRESSION_LAST 3 /* Not a valid value */
  160726. typedef struct png_time_struct
  160727. {
  160728. png_uint_16 year; /* full year, as in, 1995 */
  160729. png_byte month; /* month of year, 1 - 12 */
  160730. png_byte day; /* day of month, 1 - 31 */
  160731. png_byte hour; /* hour of day, 0 - 23 */
  160732. png_byte minute; /* minute of hour, 0 - 59 */
  160733. png_byte second; /* second of minute, 0 - 60 (for leap seconds) */
  160734. } png_time;
  160735. typedef png_time FAR * png_timep;
  160736. typedef png_time FAR * FAR * png_timepp;
  160737. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160738. typedef struct png_unknown_chunk_t
  160739. {
  160740. png_byte name[5];
  160741. png_byte *data;
  160742. png_size_t size;
  160743. png_byte location; /* mode of operation at read time */
  160744. }
  160745. png_unknown_chunk;
  160746. typedef png_unknown_chunk FAR * png_unknown_chunkp;
  160747. typedef png_unknown_chunk FAR * FAR * png_unknown_chunkpp;
  160748. #endif
  160749. typedef struct png_info_struct
  160750. {
  160751. png_uint_32 width; /* width of image in pixels (from IHDR) */
  160752. png_uint_32 height; /* height of image in pixels (from IHDR) */
  160753. png_uint_32 valid; /* valid chunk data (see PNG_INFO_ below) */
  160754. png_uint_32 rowbytes; /* bytes needed to hold an untransformed row */
  160755. png_colorp palette; /* array of color values (valid & PNG_INFO_PLTE) */
  160756. png_uint_16 num_palette; /* number of color entries in "palette" (PLTE) */
  160757. png_uint_16 num_trans; /* number of transparent palette color (tRNS) */
  160758. png_byte bit_depth; /* 1, 2, 4, 8, or 16 bits/channel (from IHDR) */
  160759. png_byte color_type; /* see PNG_COLOR_TYPE_ below (from IHDR) */
  160760. png_byte compression_type; /* must be PNG_COMPRESSION_TYPE_BASE (IHDR) */
  160761. png_byte filter_type; /* must be PNG_FILTER_TYPE_BASE (from IHDR) */
  160762. png_byte interlace_type; /* One of PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
  160763. png_byte channels; /* number of data channels per pixel (1, 2, 3, 4) */
  160764. png_byte pixel_depth; /* number of bits per pixel */
  160765. png_byte spare_byte; /* to align the data, and for future use */
  160766. png_byte signature[8]; /* magic bytes read by libpng from start of file */
  160767. #if defined(PNG_gAMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  160768. float gamma; /* gamma value of image, if (valid & PNG_INFO_gAMA) */
  160769. #endif
  160770. #if defined(PNG_sRGB_SUPPORTED)
  160771. png_byte srgb_intent; /* sRGB rendering intent [0, 1, 2, or 3] */
  160772. #endif
  160773. #if defined(PNG_TEXT_SUPPORTED)
  160774. int num_text; /* number of comments read/to write */
  160775. int max_text; /* current size of text array */
  160776. png_textp text; /* array of comments read/to write */
  160777. #endif /* PNG_TEXT_SUPPORTED */
  160778. #if defined(PNG_tIME_SUPPORTED)
  160779. png_time mod_time;
  160780. #endif
  160781. #if defined(PNG_sBIT_SUPPORTED)
  160782. png_color_8 sig_bit; /* significant bits in color channels */
  160783. #endif
  160784. #if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_EXPAND_SUPPORTED) || \
  160785. defined(PNG_READ_BACKGROUND_SUPPORTED)
  160786. png_bytep trans; /* transparent values for paletted image */
  160787. png_color_16 trans_values; /* transparent color for non-palette image */
  160788. #endif
  160789. #if defined(PNG_bKGD_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160790. png_color_16 background;
  160791. #endif
  160792. #if defined(PNG_oFFs_SUPPORTED)
  160793. png_int_32 x_offset; /* x offset on page */
  160794. png_int_32 y_offset; /* y offset on page */
  160795. png_byte offset_unit_type; /* offset units type */
  160796. #endif
  160797. #if defined(PNG_pHYs_SUPPORTED)
  160798. png_uint_32 x_pixels_per_unit; /* horizontal pixel density */
  160799. png_uint_32 y_pixels_per_unit; /* vertical pixel density */
  160800. png_byte phys_unit_type; /* resolution type (see PNG_RESOLUTION_ below) */
  160801. #endif
  160802. #if defined(PNG_hIST_SUPPORTED)
  160803. png_uint_16p hist;
  160804. #endif
  160805. #ifdef PNG_cHRM_SUPPORTED
  160806. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160807. float x_white;
  160808. float y_white;
  160809. float x_red;
  160810. float y_red;
  160811. float x_green;
  160812. float y_green;
  160813. float x_blue;
  160814. float y_blue;
  160815. #endif
  160816. #endif
  160817. #if defined(PNG_pCAL_SUPPORTED)
  160818. png_charp pcal_purpose; /* pCAL chunk description string */
  160819. png_int_32 pcal_X0; /* minimum value */
  160820. png_int_32 pcal_X1; /* maximum value */
  160821. png_charp pcal_units; /* Latin-1 string giving physical units */
  160822. png_charpp pcal_params; /* ASCII strings containing parameter values */
  160823. png_byte pcal_type; /* equation type (see PNG_EQUATION_ below) */
  160824. png_byte pcal_nparams; /* number of parameters given in pcal_params */
  160825. #endif
  160826. #ifdef PNG_FREE_ME_SUPPORTED
  160827. png_uint_32 free_me; /* flags items libpng is responsible for freeing */
  160828. #endif
  160829. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160830. png_unknown_chunkp unknown_chunks;
  160831. png_size_t unknown_chunks_num;
  160832. #endif
  160833. #if defined(PNG_iCCP_SUPPORTED)
  160834. png_charp iccp_name; /* profile name */
  160835. png_charp iccp_profile; /* International Color Consortium profile data */
  160836. png_uint_32 iccp_proflen; /* ICC profile data length */
  160837. png_byte iccp_compression; /* Always zero */
  160838. #endif
  160839. #if defined(PNG_sPLT_SUPPORTED)
  160840. png_sPLT_tp splt_palettes;
  160841. png_uint_32 splt_palettes_num;
  160842. #endif
  160843. #if defined(PNG_sCAL_SUPPORTED)
  160844. png_byte scal_unit; /* unit of physical scale */
  160845. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160846. double scal_pixel_width; /* width of one pixel */
  160847. double scal_pixel_height; /* height of one pixel */
  160848. #endif
  160849. #ifdef PNG_FIXED_POINT_SUPPORTED
  160850. png_charp scal_s_width; /* string containing height */
  160851. png_charp scal_s_height; /* string containing width */
  160852. #endif
  160853. #endif
  160854. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  160855. png_bytepp row_pointers; /* the image bits */
  160856. #endif
  160857. #if defined(PNG_FIXED_POINT_SUPPORTED) && defined(PNG_gAMA_SUPPORTED)
  160858. png_fixed_point int_gamma; /* gamma of image, if (valid & PNG_INFO_gAMA) */
  160859. #endif
  160860. #if defined(PNG_cHRM_SUPPORTED) && defined(PNG_FIXED_POINT_SUPPORTED)
  160861. png_fixed_point int_x_white;
  160862. png_fixed_point int_y_white;
  160863. png_fixed_point int_x_red;
  160864. png_fixed_point int_y_red;
  160865. png_fixed_point int_x_green;
  160866. png_fixed_point int_y_green;
  160867. png_fixed_point int_x_blue;
  160868. png_fixed_point int_y_blue;
  160869. #endif
  160870. } png_info;
  160871. typedef png_info FAR * png_infop;
  160872. typedef png_info FAR * FAR * png_infopp;
  160873. #define PNG_UINT_31_MAX ((png_uint_32)0x7fffffffL)
  160874. #define PNG_UINT_32_MAX ((png_uint_32)(-1))
  160875. #define PNG_SIZE_MAX ((png_size_t)(-1))
  160876. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  160877. #define PNG_MAX_UINT PNG_UINT_31_MAX
  160878. #endif
  160879. #define PNG_COLOR_MASK_PALETTE 1
  160880. #define PNG_COLOR_MASK_COLOR 2
  160881. #define PNG_COLOR_MASK_ALPHA 4
  160882. #define PNG_COLOR_TYPE_GRAY 0
  160883. #define PNG_COLOR_TYPE_PALETTE (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_PALETTE)
  160884. #define PNG_COLOR_TYPE_RGB (PNG_COLOR_MASK_COLOR)
  160885. #define PNG_COLOR_TYPE_RGB_ALPHA (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_ALPHA)
  160886. #define PNG_COLOR_TYPE_GRAY_ALPHA (PNG_COLOR_MASK_ALPHA)
  160887. #define PNG_COLOR_TYPE_RGBA PNG_COLOR_TYPE_RGB_ALPHA
  160888. #define PNG_COLOR_TYPE_GA PNG_COLOR_TYPE_GRAY_ALPHA
  160889. #define PNG_COMPRESSION_TYPE_BASE 0 /* Deflate method 8, 32K window */
  160890. #define PNG_COMPRESSION_TYPE_DEFAULT PNG_COMPRESSION_TYPE_BASE
  160891. #define PNG_FILTER_TYPE_BASE 0 /* Single row per-byte filtering */
  160892. #define PNG_INTRAPIXEL_DIFFERENCING 64 /* Used only in MNG datastreams */
  160893. #define PNG_FILTER_TYPE_DEFAULT PNG_FILTER_TYPE_BASE
  160894. #define PNG_INTERLACE_NONE 0 /* Non-interlaced image */
  160895. #define PNG_INTERLACE_ADAM7 1 /* Adam7 interlacing */
  160896. #define PNG_INTERLACE_LAST 2 /* Not a valid value */
  160897. #define PNG_OFFSET_PIXEL 0 /* Offset in pixels */
  160898. #define PNG_OFFSET_MICROMETER 1 /* Offset in micrometers (1/10^6 meter) */
  160899. #define PNG_OFFSET_LAST 2 /* Not a valid value */
  160900. #define PNG_EQUATION_LINEAR 0 /* Linear transformation */
  160901. #define PNG_EQUATION_BASE_E 1 /* Exponential base e transform */
  160902. #define PNG_EQUATION_ARBITRARY 2 /* Arbitrary base exponential transform */
  160903. #define PNG_EQUATION_HYPERBOLIC 3 /* Hyperbolic sine transformation */
  160904. #define PNG_EQUATION_LAST 4 /* Not a valid value */
  160905. #define PNG_SCALE_UNKNOWN 0 /* unknown unit (image scale) */
  160906. #define PNG_SCALE_METER 1 /* meters per pixel */
  160907. #define PNG_SCALE_RADIAN 2 /* radians per pixel */
  160908. #define PNG_SCALE_LAST 3 /* Not a valid value */
  160909. #define PNG_RESOLUTION_UNKNOWN 0 /* pixels/unknown unit (aspect ratio) */
  160910. #define PNG_RESOLUTION_METER 1 /* pixels/meter */
  160911. #define PNG_RESOLUTION_LAST 2 /* Not a valid value */
  160912. #define PNG_sRGB_INTENT_PERCEPTUAL 0
  160913. #define PNG_sRGB_INTENT_RELATIVE 1
  160914. #define PNG_sRGB_INTENT_SATURATION 2
  160915. #define PNG_sRGB_INTENT_ABSOLUTE 3
  160916. #define PNG_sRGB_INTENT_LAST 4 /* Not a valid value */
  160917. #define PNG_KEYWORD_MAX_LENGTH 79
  160918. #define PNG_MAX_PALETTE_LENGTH 256
  160919. #define PNG_INFO_gAMA 0x0001
  160920. #define PNG_INFO_sBIT 0x0002
  160921. #define PNG_INFO_cHRM 0x0004
  160922. #define PNG_INFO_PLTE 0x0008
  160923. #define PNG_INFO_tRNS 0x0010
  160924. #define PNG_INFO_bKGD 0x0020
  160925. #define PNG_INFO_hIST 0x0040
  160926. #define PNG_INFO_pHYs 0x0080
  160927. #define PNG_INFO_oFFs 0x0100
  160928. #define PNG_INFO_tIME 0x0200
  160929. #define PNG_INFO_pCAL 0x0400
  160930. #define PNG_INFO_sRGB 0x0800 /* GR-P, 0.96a */
  160931. #define PNG_INFO_iCCP 0x1000 /* ESR, 1.0.6 */
  160932. #define PNG_INFO_sPLT 0x2000 /* ESR, 1.0.6 */
  160933. #define PNG_INFO_sCAL 0x4000 /* ESR, 1.0.6 */
  160934. #define PNG_INFO_IDAT 0x8000L /* ESR, 1.0.6 */
  160935. typedef struct png_row_info_struct
  160936. {
  160937. png_uint_32 width; /* width of row */
  160938. png_uint_32 rowbytes; /* number of bytes in row */
  160939. png_byte color_type; /* color type of row */
  160940. png_byte bit_depth; /* bit depth of row */
  160941. png_byte channels; /* number of channels (1, 2, 3, or 4) */
  160942. png_byte pixel_depth; /* bits per pixel (depth * channels) */
  160943. } png_row_info;
  160944. typedef png_row_info FAR * png_row_infop;
  160945. typedef png_row_info FAR * FAR * png_row_infopp;
  160946. typedef struct png_struct_def png_struct;
  160947. typedef png_struct FAR * png_structp;
  160948. typedef void (PNGAPI *png_error_ptr) PNGARG((png_structp, png_const_charp));
  160949. typedef void (PNGAPI *png_rw_ptr) PNGARG((png_structp, png_bytep, png_size_t));
  160950. typedef void (PNGAPI *png_flush_ptr) PNGARG((png_structp));
  160951. typedef void (PNGAPI *png_read_status_ptr) PNGARG((png_structp, png_uint_32,
  160952. int));
  160953. typedef void (PNGAPI *png_write_status_ptr) PNGARG((png_structp, png_uint_32,
  160954. int));
  160955. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  160956. typedef void (PNGAPI *png_progressive_info_ptr) PNGARG((png_structp, png_infop));
  160957. typedef void (PNGAPI *png_progressive_end_ptr) PNGARG((png_structp, png_infop));
  160958. typedef void (PNGAPI *png_progressive_row_ptr) PNGARG((png_structp, png_bytep,
  160959. png_uint_32, int));
  160960. #endif
  160961. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  160962. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  160963. defined(PNG_LEGACY_SUPPORTED)
  160964. typedef void (PNGAPI *png_user_transform_ptr) PNGARG((png_structp,
  160965. png_row_infop, png_bytep));
  160966. #endif
  160967. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  160968. typedef int (PNGAPI *png_user_chunk_ptr) PNGARG((png_structp, png_unknown_chunkp));
  160969. #endif
  160970. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160971. typedef void (PNGAPI *png_unknown_chunk_ptr) PNGARG((png_structp));
  160972. #endif
  160973. #define PNG_TRANSFORM_IDENTITY 0x0000 /* read and write */
  160974. #define PNG_TRANSFORM_STRIP_16 0x0001 /* read only */
  160975. #define PNG_TRANSFORM_STRIP_ALPHA 0x0002 /* read only */
  160976. #define PNG_TRANSFORM_PACKING 0x0004 /* read and write */
  160977. #define PNG_TRANSFORM_PACKSWAP 0x0008 /* read and write */
  160978. #define PNG_TRANSFORM_EXPAND 0x0010 /* read only */
  160979. #define PNG_TRANSFORM_INVERT_MONO 0x0020 /* read and write */
  160980. #define PNG_TRANSFORM_SHIFT 0x0040 /* read and write */
  160981. #define PNG_TRANSFORM_BGR 0x0080 /* read and write */
  160982. #define PNG_TRANSFORM_SWAP_ALPHA 0x0100 /* read and write */
  160983. #define PNG_TRANSFORM_SWAP_ENDIAN 0x0200 /* read and write */
  160984. #define PNG_TRANSFORM_INVERT_ALPHA 0x0400 /* read and write */
  160985. #define PNG_TRANSFORM_STRIP_FILLER 0x0800 /* WRITE only */
  160986. #define PNG_FLAG_MNG_EMPTY_PLTE 0x01
  160987. #define PNG_FLAG_MNG_FILTER_64 0x04
  160988. #define PNG_ALL_MNG_FEATURES 0x05
  160989. typedef png_voidp (*png_malloc_ptr) PNGARG((png_structp, png_size_t));
  160990. typedef void (*png_free_ptr) PNGARG((png_structp, png_voidp));
  160991. struct png_struct_def
  160992. {
  160993. #ifdef PNG_SETJMP_SUPPORTED
  160994. jmp_buf jmpbuf; /* used in png_error */
  160995. #endif
  160996. png_error_ptr error_fn; /* function for printing errors and aborting */
  160997. png_error_ptr warning_fn; /* function for printing warnings */
  160998. png_voidp error_ptr; /* user supplied struct for error functions */
  160999. png_rw_ptr write_data_fn; /* function for writing output data */
  161000. png_rw_ptr read_data_fn; /* function for reading input data */
  161001. png_voidp io_ptr; /* ptr to application struct for I/O functions */
  161002. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  161003. png_user_transform_ptr read_user_transform_fn; /* user read transform */
  161004. #endif
  161005. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  161006. png_user_transform_ptr write_user_transform_fn; /* user write transform */
  161007. #endif
  161008. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  161009. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  161010. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  161011. png_voidp user_transform_ptr; /* user supplied struct for user transform */
  161012. png_byte user_transform_depth; /* bit depth of user transformed pixels */
  161013. png_byte user_transform_channels; /* channels in user transformed pixels */
  161014. #endif
  161015. #endif
  161016. png_uint_32 mode; /* tells us where we are in the PNG file */
  161017. png_uint_32 flags; /* flags indicating various things to libpng */
  161018. png_uint_32 transformations; /* which transformations to perform */
  161019. z_stream zstream; /* pointer to decompression structure (below) */
  161020. png_bytep zbuf; /* buffer for zlib */
  161021. png_size_t zbuf_size; /* size of zbuf */
  161022. int zlib_level; /* holds zlib compression level */
  161023. int zlib_method; /* holds zlib compression method */
  161024. int zlib_window_bits; /* holds zlib compression window bits */
  161025. int zlib_mem_level; /* holds zlib compression memory level */
  161026. int zlib_strategy; /* holds zlib compression strategy */
  161027. png_uint_32 width; /* width of image in pixels */
  161028. png_uint_32 height; /* height of image in pixels */
  161029. png_uint_32 num_rows; /* number of rows in current pass */
  161030. png_uint_32 usr_width; /* width of row at start of write */
  161031. png_uint_32 rowbytes; /* size of row in bytes */
  161032. png_uint_32 irowbytes; /* size of current interlaced row in bytes */
  161033. png_uint_32 iwidth; /* width of current interlaced row in pixels */
  161034. png_uint_32 row_number; /* current row in interlace pass */
  161035. png_bytep prev_row; /* buffer to save previous (unfiltered) row */
  161036. png_bytep row_buf; /* buffer to save current (unfiltered) row */
  161037. png_bytep sub_row; /* buffer to save "sub" row when filtering */
  161038. png_bytep up_row; /* buffer to save "up" row when filtering */
  161039. png_bytep avg_row; /* buffer to save "avg" row when filtering */
  161040. png_bytep paeth_row; /* buffer to save "Paeth" row when filtering */
  161041. png_row_info row_info; /* used for transformation routines */
  161042. png_uint_32 idat_size; /* current IDAT size for read */
  161043. png_uint_32 crc; /* current chunk CRC value */
  161044. png_colorp palette; /* palette from the input file */
  161045. png_uint_16 num_palette; /* number of color entries in palette */
  161046. png_uint_16 num_trans; /* number of transparency values */
  161047. png_byte chunk_name[5]; /* null-terminated name of current chunk */
  161048. png_byte compression; /* file compression type (always 0) */
  161049. png_byte filter; /* file filter type (always 0) */
  161050. png_byte interlaced; /* PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
  161051. png_byte pass; /* current interlace pass (0 - 6) */
  161052. png_byte do_filter; /* row filter flags (see PNG_FILTER_ below ) */
  161053. png_byte color_type; /* color type of file */
  161054. png_byte bit_depth; /* bit depth of file */
  161055. png_byte usr_bit_depth; /* bit depth of users row */
  161056. png_byte pixel_depth; /* number of bits per pixel */
  161057. png_byte channels; /* number of channels in file */
  161058. png_byte usr_channels; /* channels at start of write */
  161059. png_byte sig_bytes; /* magic bytes read/written from start of file */
  161060. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  161061. #ifdef PNG_LEGACY_SUPPORTED
  161062. png_byte filler; /* filler byte for pixel expansion */
  161063. #else
  161064. png_uint_16 filler; /* filler bytes for pixel expansion */
  161065. #endif
  161066. #endif
  161067. #if defined(PNG_bKGD_SUPPORTED)
  161068. png_byte background_gamma_type;
  161069. # ifdef PNG_FLOATING_POINT_SUPPORTED
  161070. float background_gamma;
  161071. # endif
  161072. png_color_16 background; /* background color in screen gamma space */
  161073. #if defined(PNG_READ_GAMMA_SUPPORTED)
  161074. png_color_16 background_1; /* background normalized to gamma 1.0 */
  161075. #endif
  161076. #endif /* PNG_bKGD_SUPPORTED */
  161077. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  161078. png_flush_ptr output_flush_fn;/* Function for flushing output */
  161079. png_uint_32 flush_dist; /* how many rows apart to flush, 0 - no flush */
  161080. png_uint_32 flush_rows; /* number of rows written since last flush */
  161081. #endif
  161082. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  161083. int gamma_shift; /* number of "insignificant" bits 16-bit gamma */
  161084. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161085. float gamma; /* file gamma value */
  161086. float screen_gamma; /* screen gamma value (display_exponent) */
  161087. #endif
  161088. #endif
  161089. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  161090. png_bytep gamma_table; /* gamma table for 8-bit depth files */
  161091. png_bytep gamma_from_1; /* converts from 1.0 to screen */
  161092. png_bytep gamma_to_1; /* converts from file to 1.0 */
  161093. png_uint_16pp gamma_16_table; /* gamma table for 16-bit depth files */
  161094. png_uint_16pp gamma_16_from_1; /* converts from 1.0 to screen */
  161095. png_uint_16pp gamma_16_to_1; /* converts from file to 1.0 */
  161096. #endif
  161097. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_sBIT_SUPPORTED)
  161098. png_color_8 sig_bit; /* significant bits in each available channel */
  161099. #endif
  161100. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  161101. png_color_8 shift; /* shift for significant bit tranformation */
  161102. #endif
  161103. #if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) \
  161104. || defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  161105. png_bytep trans; /* transparency values for paletted files */
  161106. png_color_16 trans_values; /* transparency values for non-paletted files */
  161107. #endif
  161108. png_read_status_ptr read_row_fn; /* called after each row is decoded */
  161109. png_write_status_ptr write_row_fn; /* called after each row is encoded */
  161110. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  161111. png_progressive_info_ptr info_fn; /* called after header data fully read */
  161112. png_progressive_row_ptr row_fn; /* called after each prog. row is decoded */
  161113. png_progressive_end_ptr end_fn; /* called after image is complete */
  161114. png_bytep save_buffer_ptr; /* current location in save_buffer */
  161115. png_bytep save_buffer; /* buffer for previously read data */
  161116. png_bytep current_buffer_ptr; /* current location in current_buffer */
  161117. png_bytep current_buffer; /* buffer for recently used data */
  161118. png_uint_32 push_length; /* size of current input chunk */
  161119. png_uint_32 skip_length; /* bytes to skip in input data */
  161120. png_size_t save_buffer_size; /* amount of data now in save_buffer */
  161121. png_size_t save_buffer_max; /* total size of save_buffer */
  161122. png_size_t buffer_size; /* total amount of available input data */
  161123. png_size_t current_buffer_size; /* amount of data now in current_buffer */
  161124. int process_mode; /* what push library is currently doing */
  161125. int cur_palette; /* current push library palette index */
  161126. # if defined(PNG_TEXT_SUPPORTED)
  161127. png_size_t current_text_size; /* current size of text input data */
  161128. png_size_t current_text_left; /* how much text left to read in input */
  161129. png_charp current_text; /* current text chunk buffer */
  161130. png_charp current_text_ptr; /* current location in current_text */
  161131. # endif /* PNG_TEXT_SUPPORTED */
  161132. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  161133. #if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
  161134. png_bytepp offset_table_ptr;
  161135. png_bytep offset_table;
  161136. png_uint_16 offset_table_number;
  161137. png_uint_16 offset_table_count;
  161138. png_uint_16 offset_table_count_free;
  161139. #endif
  161140. #if defined(PNG_READ_DITHER_SUPPORTED)
  161141. png_bytep palette_lookup; /* lookup table for dithering */
  161142. png_bytep dither_index; /* index translation for palette files */
  161143. #endif
  161144. #if defined(PNG_READ_DITHER_SUPPORTED) || defined(PNG_hIST_SUPPORTED)
  161145. png_uint_16p hist; /* histogram */
  161146. #endif
  161147. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  161148. png_byte heuristic_method; /* heuristic for row filter selection */
  161149. png_byte num_prev_filters; /* number of weights for previous rows */
  161150. png_bytep prev_filters; /* filter type(s) of previous row(s) */
  161151. png_uint_16p filter_weights; /* weight(s) for previous line(s) */
  161152. png_uint_16p inv_filter_weights; /* 1/weight(s) for previous line(s) */
  161153. png_uint_16p filter_costs; /* relative filter calculation cost */
  161154. png_uint_16p inv_filter_costs; /* 1/relative filter calculation cost */
  161155. #endif
  161156. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  161157. png_charp time_buffer; /* String to hold RFC 1123 time text */
  161158. #endif
  161159. #ifdef PNG_FREE_ME_SUPPORTED
  161160. png_uint_32 free_me; /* flags items libpng is responsible for freeing */
  161161. #endif
  161162. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  161163. png_voidp user_chunk_ptr;
  161164. png_user_chunk_ptr read_user_chunk_fn; /* user read chunk handler */
  161165. #endif
  161166. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  161167. int num_chunk_list;
  161168. png_bytep chunk_list;
  161169. #endif
  161170. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  161171. png_byte rgb_to_gray_status;
  161172. png_uint_16 rgb_to_gray_red_coeff;
  161173. png_uint_16 rgb_to_gray_green_coeff;
  161174. png_uint_16 rgb_to_gray_blue_coeff;
  161175. #endif
  161176. #if defined(PNG_MNG_FEATURES_SUPPORTED) || \
  161177. defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  161178. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  161179. #ifdef PNG_1_0_X
  161180. png_byte mng_features_permitted;
  161181. #else
  161182. png_uint_32 mng_features_permitted;
  161183. #endif /* PNG_1_0_X */
  161184. #endif
  161185. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  161186. png_fixed_point int_gamma;
  161187. #endif
  161188. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  161189. png_byte filter_type;
  161190. #endif
  161191. #if defined(PNG_1_0_X)
  161192. png_uint_32 row_buf_size;
  161193. #endif
  161194. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  161195. # if !defined(PNG_1_0_X)
  161196. # if defined(PNG_MMX_CODE_SUPPORTED)
  161197. png_byte mmx_bitdepth_threshold;
  161198. png_uint_32 mmx_rowbytes_threshold;
  161199. # endif
  161200. png_uint_32 asm_flags;
  161201. # endif
  161202. #endif
  161203. #ifdef PNG_USER_MEM_SUPPORTED
  161204. png_voidp mem_ptr; /* user supplied struct for mem functions */
  161205. png_malloc_ptr malloc_fn; /* function for allocating memory */
  161206. png_free_ptr free_fn; /* function for freeing memory */
  161207. #endif
  161208. png_bytep big_row_buf; /* buffer to save current (unfiltered) row */
  161209. #if defined(PNG_READ_DITHER_SUPPORTED)
  161210. png_bytep dither_sort; /* working sort array */
  161211. png_bytep index_to_palette; /* where the original index currently is */
  161212. png_bytep palette_to_index; /* which original index points to this */
  161213. #endif
  161214. png_byte compression_type;
  161215. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  161216. png_uint_32 user_width_max;
  161217. png_uint_32 user_height_max;
  161218. #endif
  161219. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  161220. png_unknown_chunk unknown_chunk;
  161221. #endif
  161222. };
  161223. typedef png_structp version_1_2_21;
  161224. typedef png_struct FAR * FAR * png_structpp;
  161225. extern PNG_EXPORT(png_uint_32,png_access_version_number) PNGARG((void));
  161226. extern PNG_EXPORT(void,png_set_sig_bytes) PNGARG((png_structp png_ptr,
  161227. int num_bytes));
  161228. extern PNG_EXPORT(int,png_sig_cmp) PNGARG((png_bytep sig, png_size_t start,
  161229. png_size_t num_to_check));
  161230. extern PNG_EXPORT(int,png_check_sig) PNGARG((png_bytep sig, int num));
  161231. extern PNG_EXPORT(png_structp,png_create_read_struct)
  161232. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  161233. png_error_ptr error_fn, png_error_ptr warn_fn));
  161234. extern PNG_EXPORT(png_structp,png_create_write_struct)
  161235. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  161236. png_error_ptr error_fn, png_error_ptr warn_fn));
  161237. #ifdef PNG_WRITE_SUPPORTED
  161238. extern PNG_EXPORT(png_uint_32,png_get_compression_buffer_size)
  161239. PNGARG((png_structp png_ptr));
  161240. #endif
  161241. #ifdef PNG_WRITE_SUPPORTED
  161242. extern PNG_EXPORT(void,png_set_compression_buffer_size)
  161243. PNGARG((png_structp png_ptr, png_uint_32 size));
  161244. #endif
  161245. extern PNG_EXPORT(int,png_reset_zstream) PNGARG((png_structp png_ptr));
  161246. #ifdef PNG_USER_MEM_SUPPORTED
  161247. extern PNG_EXPORT(png_structp,png_create_read_struct_2)
  161248. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  161249. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  161250. png_malloc_ptr malloc_fn, png_free_ptr free_fn));
  161251. extern PNG_EXPORT(png_structp,png_create_write_struct_2)
  161252. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  161253. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  161254. png_malloc_ptr malloc_fn, png_free_ptr free_fn));
  161255. #endif
  161256. extern PNG_EXPORT(void,png_write_chunk) PNGARG((png_structp png_ptr,
  161257. png_bytep chunk_name, png_bytep data, png_size_t length));
  161258. extern PNG_EXPORT(void,png_write_chunk_start) PNGARG((png_structp png_ptr,
  161259. png_bytep chunk_name, png_uint_32 length));
  161260. extern PNG_EXPORT(void,png_write_chunk_data) PNGARG((png_structp png_ptr,
  161261. png_bytep data, png_size_t length));
  161262. extern PNG_EXPORT(void,png_write_chunk_end) PNGARG((png_structp png_ptr));
  161263. extern PNG_EXPORT(png_infop,png_create_info_struct)
  161264. PNGARG((png_structp png_ptr));
  161265. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161266. extern PNG_EXPORT(void,png_info_init) PNGARG((png_infop info_ptr));
  161267. #undef png_info_init
  161268. #define png_info_init(info_ptr) png_info_init_3(&info_ptr,\
  161269. png_sizeof(png_info));
  161270. #endif
  161271. extern PNG_EXPORT(void,png_info_init_3) PNGARG((png_infopp info_ptr,
  161272. png_size_t png_info_struct_size));
  161273. extern PNG_EXPORT(void,png_write_info_before_PLTE) PNGARG((png_structp png_ptr,
  161274. png_infop info_ptr));
  161275. extern PNG_EXPORT(void,png_write_info) PNGARG((png_structp png_ptr,
  161276. png_infop info_ptr));
  161277. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  161278. extern PNG_EXPORT(void,png_read_info) PNGARG((png_structp png_ptr,
  161279. png_infop info_ptr));
  161280. #endif
  161281. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  161282. extern PNG_EXPORT(png_charp,png_convert_to_rfc1123)
  161283. PNGARG((png_structp png_ptr, png_timep ptime));
  161284. #endif
  161285. #if !defined(_WIN32_WCE)
  161286. #if defined(PNG_WRITE_tIME_SUPPORTED)
  161287. extern PNG_EXPORT(void,png_convert_from_struct_tm) PNGARG((png_timep ptime,
  161288. struct tm FAR * ttime));
  161289. extern PNG_EXPORT(void,png_convert_from_time_t) PNGARG((png_timep ptime,
  161290. time_t ttime));
  161291. #endif /* PNG_WRITE_tIME_SUPPORTED */
  161292. #endif /* _WIN32_WCE */
  161293. #if defined(PNG_READ_EXPAND_SUPPORTED)
  161294. extern PNG_EXPORT(void,png_set_expand) PNGARG((png_structp png_ptr));
  161295. #if !defined(PNG_1_0_X)
  161296. extern PNG_EXPORT(void,png_set_expand_gray_1_2_4_to_8) PNGARG((png_structp
  161297. png_ptr));
  161298. #endif
  161299. extern PNG_EXPORT(void,png_set_palette_to_rgb) PNGARG((png_structp png_ptr));
  161300. extern PNG_EXPORT(void,png_set_tRNS_to_alpha) PNGARG((png_structp png_ptr));
  161301. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161302. extern PNG_EXPORT(void,png_set_gray_1_2_4_to_8) PNGARG((png_structp png_ptr));
  161303. #endif
  161304. #endif
  161305. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  161306. extern PNG_EXPORT(void,png_set_bgr) PNGARG((png_structp png_ptr));
  161307. #endif
  161308. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  161309. extern PNG_EXPORT(void,png_set_gray_to_rgb) PNGARG((png_structp png_ptr));
  161310. #endif
  161311. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  161312. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161313. extern PNG_EXPORT(void,png_set_rgb_to_gray) PNGARG((png_structp png_ptr,
  161314. int error_action, double red, double green ));
  161315. #endif
  161316. extern PNG_EXPORT(void,png_set_rgb_to_gray_fixed) PNGARG((png_structp png_ptr,
  161317. int error_action, png_fixed_point red, png_fixed_point green ));
  161318. extern PNG_EXPORT(png_byte,png_get_rgb_to_gray_status) PNGARG((png_structp
  161319. png_ptr));
  161320. #endif
  161321. extern PNG_EXPORT(void,png_build_grayscale_palette) PNGARG((int bit_depth,
  161322. png_colorp palette));
  161323. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  161324. extern PNG_EXPORT(void,png_set_strip_alpha) PNGARG((png_structp png_ptr));
  161325. #endif
  161326. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \
  161327. defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  161328. extern PNG_EXPORT(void,png_set_swap_alpha) PNGARG((png_structp png_ptr));
  161329. #endif
  161330. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \
  161331. defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  161332. extern PNG_EXPORT(void,png_set_invert_alpha) PNGARG((png_structp png_ptr));
  161333. #endif
  161334. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  161335. extern PNG_EXPORT(void,png_set_filler) PNGARG((png_structp png_ptr,
  161336. png_uint_32 filler, int flags));
  161337. #define PNG_FILLER_BEFORE 0
  161338. #define PNG_FILLER_AFTER 1
  161339. #if !defined(PNG_1_0_X)
  161340. extern PNG_EXPORT(void,png_set_add_alpha) PNGARG((png_structp png_ptr,
  161341. png_uint_32 filler, int flags));
  161342. #endif
  161343. #endif /* PNG_READ_FILLER_SUPPORTED || PNG_WRITE_FILLER_SUPPORTED */
  161344. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  161345. extern PNG_EXPORT(void,png_set_swap) PNGARG((png_structp png_ptr));
  161346. #endif
  161347. #if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
  161348. extern PNG_EXPORT(void,png_set_packing) PNGARG((png_structp png_ptr));
  161349. #endif
  161350. #if defined(PNG_READ_PACKSWAP_SUPPORTED) || defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  161351. extern PNG_EXPORT(void,png_set_packswap) PNGARG((png_structp png_ptr));
  161352. #endif
  161353. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  161354. extern PNG_EXPORT(void,png_set_shift) PNGARG((png_structp png_ptr,
  161355. png_color_8p true_bits));
  161356. #endif
  161357. #if defined(PNG_READ_INTERLACING_SUPPORTED) || \
  161358. defined(PNG_WRITE_INTERLACING_SUPPORTED)
  161359. extern PNG_EXPORT(int,png_set_interlace_handling) PNGARG((png_structp png_ptr));
  161360. #endif
  161361. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  161362. extern PNG_EXPORT(void,png_set_invert_mono) PNGARG((png_structp png_ptr));
  161363. #endif
  161364. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  161365. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161366. extern PNG_EXPORT(void,png_set_background) PNGARG((png_structp png_ptr,
  161367. png_color_16p background_color, int background_gamma_code,
  161368. int need_expand, double background_gamma));
  161369. #endif
  161370. #define PNG_BACKGROUND_GAMMA_UNKNOWN 0
  161371. #define PNG_BACKGROUND_GAMMA_SCREEN 1
  161372. #define PNG_BACKGROUND_GAMMA_FILE 2
  161373. #define PNG_BACKGROUND_GAMMA_UNIQUE 3
  161374. #endif
  161375. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  161376. extern PNG_EXPORT(void,png_set_strip_16) PNGARG((png_structp png_ptr));
  161377. #endif
  161378. #if defined(PNG_READ_DITHER_SUPPORTED)
  161379. extern PNG_EXPORT(void,png_set_dither) PNGARG((png_structp png_ptr,
  161380. png_colorp palette, int num_palette, int maximum_colors,
  161381. png_uint_16p histogram, int full_dither));
  161382. #endif
  161383. #if defined(PNG_READ_GAMMA_SUPPORTED)
  161384. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161385. extern PNG_EXPORT(void,png_set_gamma) PNGARG((png_structp png_ptr,
  161386. double screen_gamma, double default_file_gamma));
  161387. #endif
  161388. #endif
  161389. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161390. #if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  161391. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  161392. extern PNG_EXPORT(void,png_permit_empty_plte) PNGARG((png_structp png_ptr,
  161393. int empty_plte_permitted));
  161394. #endif
  161395. #endif
  161396. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  161397. extern PNG_EXPORT(void,png_set_flush) PNGARG((png_structp png_ptr, int nrows));
  161398. extern PNG_EXPORT(void,png_write_flush) PNGARG((png_structp png_ptr));
  161399. #endif
  161400. extern PNG_EXPORT(void,png_start_read_image) PNGARG((png_structp png_ptr));
  161401. extern PNG_EXPORT(void,png_read_update_info) PNGARG((png_structp png_ptr,
  161402. png_infop info_ptr));
  161403. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  161404. extern PNG_EXPORT(void,png_read_rows) PNGARG((png_structp png_ptr,
  161405. png_bytepp row, png_bytepp display_row, png_uint_32 num_rows));
  161406. #endif
  161407. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  161408. extern PNG_EXPORT(void,png_read_row) PNGARG((png_structp png_ptr,
  161409. png_bytep row,
  161410. png_bytep display_row));
  161411. #endif
  161412. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  161413. extern PNG_EXPORT(void,png_read_image) PNGARG((png_structp png_ptr,
  161414. png_bytepp image));
  161415. #endif
  161416. extern PNG_EXPORT(void,png_write_row) PNGARG((png_structp png_ptr,
  161417. png_bytep row));
  161418. extern PNG_EXPORT(void,png_write_rows) PNGARG((png_structp png_ptr,
  161419. png_bytepp row, png_uint_32 num_rows));
  161420. extern PNG_EXPORT(void,png_write_image) PNGARG((png_structp png_ptr,
  161421. png_bytepp image));
  161422. extern PNG_EXPORT(void,png_write_end) PNGARG((png_structp png_ptr,
  161423. png_infop info_ptr));
  161424. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  161425. extern PNG_EXPORT(void,png_read_end) PNGARG((png_structp png_ptr,
  161426. png_infop info_ptr));
  161427. #endif
  161428. extern PNG_EXPORT(void,png_destroy_info_struct) PNGARG((png_structp png_ptr,
  161429. png_infopp info_ptr_ptr));
  161430. extern PNG_EXPORT(void,png_destroy_read_struct) PNGARG((png_structpp
  161431. png_ptr_ptr, png_infopp info_ptr_ptr, png_infopp end_info_ptr_ptr));
  161432. extern void png_read_destroy PNGARG((png_structp png_ptr, png_infop info_ptr,
  161433. png_infop end_info_ptr));
  161434. extern PNG_EXPORT(void,png_destroy_write_struct)
  161435. PNGARG((png_structpp png_ptr_ptr, png_infopp info_ptr_ptr));
  161436. extern void png_write_destroy PNGARG((png_structp png_ptr));
  161437. extern PNG_EXPORT(void,png_set_crc_action) PNGARG((png_structp png_ptr,
  161438. int crit_action, int ancil_action));
  161439. #define PNG_CRC_DEFAULT 0 /* error/quit warn/discard data */
  161440. #define PNG_CRC_ERROR_QUIT 1 /* error/quit error/quit */
  161441. #define PNG_CRC_WARN_DISCARD 2 /* (INVALID) warn/discard data */
  161442. #define PNG_CRC_WARN_USE 3 /* warn/use data warn/use data */
  161443. #define PNG_CRC_QUIET_USE 4 /* quiet/use data quiet/use data */
  161444. #define PNG_CRC_NO_CHANGE 5 /* use current value use current value */
  161445. extern PNG_EXPORT(void,png_set_filter) PNGARG((png_structp png_ptr, int method,
  161446. int filters));
  161447. #define PNG_NO_FILTERS 0x00
  161448. #define PNG_FILTER_NONE 0x08
  161449. #define PNG_FILTER_SUB 0x10
  161450. #define PNG_FILTER_UP 0x20
  161451. #define PNG_FILTER_AVG 0x40
  161452. #define PNG_FILTER_PAETH 0x80
  161453. #define PNG_ALL_FILTERS (PNG_FILTER_NONE | PNG_FILTER_SUB | PNG_FILTER_UP | \
  161454. PNG_FILTER_AVG | PNG_FILTER_PAETH)
  161455. #define PNG_FILTER_VALUE_NONE 0
  161456. #define PNG_FILTER_VALUE_SUB 1
  161457. #define PNG_FILTER_VALUE_UP 2
  161458. #define PNG_FILTER_VALUE_AVG 3
  161459. #define PNG_FILTER_VALUE_PAETH 4
  161460. #define PNG_FILTER_VALUE_LAST 5
  161461. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* EXPERIMENTAL */
  161462. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161463. extern PNG_EXPORT(void,png_set_filter_heuristics) PNGARG((png_structp png_ptr,
  161464. int heuristic_method, int num_weights, png_doublep filter_weights,
  161465. png_doublep filter_costs));
  161466. #endif
  161467. #endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
  161468. #define PNG_FILTER_HEURISTIC_DEFAULT 0 /* Currently "UNWEIGHTED" */
  161469. #define PNG_FILTER_HEURISTIC_UNWEIGHTED 1 /* Used by libpng < 0.95 */
  161470. #define PNG_FILTER_HEURISTIC_WEIGHTED 2 /* Experimental feature */
  161471. #define PNG_FILTER_HEURISTIC_LAST 3 /* Not a valid value */
  161472. extern PNG_EXPORT(void,png_set_compression_level) PNGARG((png_structp png_ptr,
  161473. int level));
  161474. extern PNG_EXPORT(void,png_set_compression_mem_level)
  161475. PNGARG((png_structp png_ptr, int mem_level));
  161476. extern PNG_EXPORT(void,png_set_compression_strategy)
  161477. PNGARG((png_structp png_ptr, int strategy));
  161478. extern PNG_EXPORT(void,png_set_compression_window_bits)
  161479. PNGARG((png_structp png_ptr, int window_bits));
  161480. extern PNG_EXPORT(void,png_set_compression_method) PNGARG((png_structp png_ptr,
  161481. int method));
  161482. #if !defined(PNG_NO_STDIO)
  161483. extern PNG_EXPORT(void,png_init_io) PNGARG((png_structp png_ptr, png_FILE_p fp));
  161484. #endif
  161485. extern PNG_EXPORT(void,png_set_error_fn) PNGARG((png_structp png_ptr,
  161486. png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warning_fn));
  161487. extern PNG_EXPORT(png_voidp,png_get_error_ptr) PNGARG((png_structp png_ptr));
  161488. extern PNG_EXPORT(void,png_set_write_fn) PNGARG((png_structp png_ptr,
  161489. png_voidp io_ptr, png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn));
  161490. extern PNG_EXPORT(void,png_set_read_fn) PNGARG((png_structp png_ptr,
  161491. png_voidp io_ptr, png_rw_ptr read_data_fn));
  161492. extern PNG_EXPORT(png_voidp,png_get_io_ptr) PNGARG((png_structp png_ptr));
  161493. extern PNG_EXPORT(void,png_set_read_status_fn) PNGARG((png_structp png_ptr,
  161494. png_read_status_ptr read_row_fn));
  161495. extern PNG_EXPORT(void,png_set_write_status_fn) PNGARG((png_structp png_ptr,
  161496. png_write_status_ptr write_row_fn));
  161497. #ifdef PNG_USER_MEM_SUPPORTED
  161498. extern PNG_EXPORT(void,png_set_mem_fn) PNGARG((png_structp png_ptr,
  161499. png_voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn));
  161500. extern PNG_EXPORT(png_voidp,png_get_mem_ptr) PNGARG((png_structp png_ptr));
  161501. #endif
  161502. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  161503. defined(PNG_LEGACY_SUPPORTED)
  161504. extern PNG_EXPORT(void,png_set_read_user_transform_fn) PNGARG((png_structp
  161505. png_ptr, png_user_transform_ptr read_user_transform_fn));
  161506. #endif
  161507. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  161508. defined(PNG_LEGACY_SUPPORTED)
  161509. extern PNG_EXPORT(void,png_set_write_user_transform_fn) PNGARG((png_structp
  161510. png_ptr, png_user_transform_ptr write_user_transform_fn));
  161511. #endif
  161512. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  161513. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  161514. defined(PNG_LEGACY_SUPPORTED)
  161515. extern PNG_EXPORT(void,png_set_user_transform_info) PNGARG((png_structp
  161516. png_ptr, png_voidp user_transform_ptr, int user_transform_depth,
  161517. int user_transform_channels));
  161518. extern PNG_EXPORT(png_voidp,png_get_user_transform_ptr)
  161519. PNGARG((png_structp png_ptr));
  161520. #endif
  161521. #ifdef PNG_USER_CHUNKS_SUPPORTED
  161522. extern PNG_EXPORT(void,png_set_read_user_chunk_fn) PNGARG((png_structp png_ptr,
  161523. png_voidp user_chunk_ptr, png_user_chunk_ptr read_user_chunk_fn));
  161524. extern PNG_EXPORT(png_voidp,png_get_user_chunk_ptr) PNGARG((png_structp
  161525. png_ptr));
  161526. #endif
  161527. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  161528. extern PNG_EXPORT(void,png_set_progressive_read_fn) PNGARG((png_structp png_ptr,
  161529. png_voidp progressive_ptr,
  161530. png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,
  161531. png_progressive_end_ptr end_fn));
  161532. extern PNG_EXPORT(png_voidp,png_get_progressive_ptr)
  161533. PNGARG((png_structp png_ptr));
  161534. extern PNG_EXPORT(void,png_process_data) PNGARG((png_structp png_ptr,
  161535. png_infop info_ptr, png_bytep buffer, png_size_t buffer_size));
  161536. extern PNG_EXPORT(void,png_progressive_combine_row) PNGARG((png_structp png_ptr,
  161537. png_bytep old_row, png_bytep new_row));
  161538. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  161539. extern PNG_EXPORT(png_voidp,png_malloc) PNGARG((png_structp png_ptr,
  161540. png_uint_32 size));
  161541. #if defined(PNG_1_0_X)
  161542. # define png_malloc_warn png_malloc
  161543. #else
  161544. extern PNG_EXPORT(png_voidp,png_malloc_warn) PNGARG((png_structp png_ptr,
  161545. png_uint_32 size));
  161546. #endif
  161547. extern PNG_EXPORT(void,png_free) PNGARG((png_structp png_ptr, png_voidp ptr));
  161548. #if defined(PNG_1_0_X)
  161549. extern PNG_EXPORT(voidpf,png_zalloc) PNGARG((voidpf png_ptr, uInt items,
  161550. uInt size));
  161551. extern PNG_EXPORT(void,png_zfree) PNGARG((voidpf png_ptr, voidpf ptr));
  161552. #endif
  161553. extern PNG_EXPORT(void,png_free_data) PNGARG((png_structp png_ptr,
  161554. png_infop info_ptr, png_uint_32 free_me, int num));
  161555. #ifdef PNG_FREE_ME_SUPPORTED
  161556. extern PNG_EXPORT(void,png_data_freer) PNGARG((png_structp png_ptr,
  161557. png_infop info_ptr, int freer, png_uint_32 mask));
  161558. #endif
  161559. #define PNG_DESTROY_WILL_FREE_DATA 1
  161560. #define PNG_SET_WILL_FREE_DATA 1
  161561. #define PNG_USER_WILL_FREE_DATA 2
  161562. #define PNG_FREE_HIST 0x0008
  161563. #define PNG_FREE_ICCP 0x0010
  161564. #define PNG_FREE_SPLT 0x0020
  161565. #define PNG_FREE_ROWS 0x0040
  161566. #define PNG_FREE_PCAL 0x0080
  161567. #define PNG_FREE_SCAL 0x0100
  161568. #define PNG_FREE_UNKN 0x0200
  161569. #define PNG_FREE_LIST 0x0400
  161570. #define PNG_FREE_PLTE 0x1000
  161571. #define PNG_FREE_TRNS 0x2000
  161572. #define PNG_FREE_TEXT 0x4000
  161573. #define PNG_FREE_ALL 0x7fff
  161574. #define PNG_FREE_MUL 0x4220 /* PNG_FREE_SPLT|PNG_FREE_TEXT|PNG_FREE_UNKN */
  161575. #ifdef PNG_USER_MEM_SUPPORTED
  161576. extern PNG_EXPORT(png_voidp,png_malloc_default) PNGARG((png_structp png_ptr,
  161577. png_uint_32 size));
  161578. extern PNG_EXPORT(void,png_free_default) PNGARG((png_structp png_ptr,
  161579. png_voidp ptr));
  161580. #endif
  161581. extern PNG_EXPORT(png_voidp,png_memcpy_check) PNGARG((png_structp png_ptr,
  161582. png_voidp s1, png_voidp s2, png_uint_32 size));
  161583. extern PNG_EXPORT(png_voidp,png_memset_check) PNGARG((png_structp png_ptr,
  161584. png_voidp s1, int value, png_uint_32 size));
  161585. #if defined(USE_FAR_KEYWORD) /* memory model conversion function */
  161586. extern void *png_far_to_near PNGARG((png_structp png_ptr,png_voidp ptr,
  161587. int check));
  161588. #endif /* USE_FAR_KEYWORD */
  161589. #ifndef PNG_NO_ERROR_TEXT
  161590. extern PNG_EXPORT(void,png_error) PNGARG((png_structp png_ptr,
  161591. png_const_charp error_message));
  161592. extern PNG_EXPORT(void,png_chunk_error) PNGARG((png_structp png_ptr,
  161593. png_const_charp error_message));
  161594. #else
  161595. extern PNG_EXPORT(void,png_err) PNGARG((png_structp png_ptr));
  161596. #endif
  161597. #ifndef PNG_NO_WARNINGS
  161598. extern PNG_EXPORT(void,png_warning) PNGARG((png_structp png_ptr,
  161599. png_const_charp warning_message));
  161600. #ifdef PNG_READ_SUPPORTED
  161601. extern PNG_EXPORT(void,png_chunk_warning) PNGARG((png_structp png_ptr,
  161602. png_const_charp warning_message));
  161603. #endif /* PNG_READ_SUPPORTED */
  161604. #endif /* PNG_NO_WARNINGS */
  161605. extern PNG_EXPORT(png_uint_32,png_get_valid) PNGARG((png_structp png_ptr,
  161606. png_infop info_ptr, png_uint_32 flag));
  161607. extern PNG_EXPORT(png_uint_32,png_get_rowbytes) PNGARG((png_structp png_ptr,
  161608. png_infop info_ptr));
  161609. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  161610. extern PNG_EXPORT(png_bytepp,png_get_rows) PNGARG((png_structp png_ptr,
  161611. png_infop info_ptr));
  161612. extern PNG_EXPORT(void,png_set_rows) PNGARG((png_structp png_ptr,
  161613. png_infop info_ptr, png_bytepp row_pointers));
  161614. #endif
  161615. extern PNG_EXPORT(png_byte,png_get_channels) PNGARG((png_structp png_ptr,
  161616. png_infop info_ptr));
  161617. #ifdef PNG_EASY_ACCESS_SUPPORTED
  161618. extern PNG_EXPORT(png_uint_32, png_get_image_width) PNGARG((png_structp
  161619. png_ptr, png_infop info_ptr));
  161620. extern PNG_EXPORT(png_uint_32, png_get_image_height) PNGARG((png_structp
  161621. png_ptr, png_infop info_ptr));
  161622. extern PNG_EXPORT(png_byte, png_get_bit_depth) PNGARG((png_structp
  161623. png_ptr, png_infop info_ptr));
  161624. extern PNG_EXPORT(png_byte, png_get_color_type) PNGARG((png_structp
  161625. png_ptr, png_infop info_ptr));
  161626. extern PNG_EXPORT(png_byte, png_get_filter_type) PNGARG((png_structp
  161627. png_ptr, png_infop info_ptr));
  161628. extern PNG_EXPORT(png_byte, png_get_interlace_type) PNGARG((png_structp
  161629. png_ptr, png_infop info_ptr));
  161630. extern PNG_EXPORT(png_byte, png_get_compression_type) PNGARG((png_structp
  161631. png_ptr, png_infop info_ptr));
  161632. extern PNG_EXPORT(png_uint_32, png_get_pixels_per_meter) PNGARG((png_structp
  161633. png_ptr, png_infop info_ptr));
  161634. extern PNG_EXPORT(png_uint_32, png_get_x_pixels_per_meter) PNGARG((png_structp
  161635. png_ptr, png_infop info_ptr));
  161636. extern PNG_EXPORT(png_uint_32, png_get_y_pixels_per_meter) PNGARG((png_structp
  161637. png_ptr, png_infop info_ptr));
  161638. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161639. extern PNG_EXPORT(float, png_get_pixel_aspect_ratio) PNGARG((png_structp
  161640. png_ptr, png_infop info_ptr));
  161641. #endif
  161642. extern PNG_EXPORT(png_int_32, png_get_x_offset_pixels) PNGARG((png_structp
  161643. png_ptr, png_infop info_ptr));
  161644. extern PNG_EXPORT(png_int_32, png_get_y_offset_pixels) PNGARG((png_structp
  161645. png_ptr, png_infop info_ptr));
  161646. extern PNG_EXPORT(png_int_32, png_get_x_offset_microns) PNGARG((png_structp
  161647. png_ptr, png_infop info_ptr));
  161648. extern PNG_EXPORT(png_int_32, png_get_y_offset_microns) PNGARG((png_structp
  161649. png_ptr, png_infop info_ptr));
  161650. #endif /* PNG_EASY_ACCESS_SUPPORTED */
  161651. extern PNG_EXPORT(png_bytep,png_get_signature) PNGARG((png_structp png_ptr,
  161652. png_infop info_ptr));
  161653. #if defined(PNG_bKGD_SUPPORTED)
  161654. extern PNG_EXPORT(png_uint_32,png_get_bKGD) PNGARG((png_structp png_ptr,
  161655. png_infop info_ptr, png_color_16p *background));
  161656. #endif
  161657. #if defined(PNG_bKGD_SUPPORTED)
  161658. extern PNG_EXPORT(void,png_set_bKGD) PNGARG((png_structp png_ptr,
  161659. png_infop info_ptr, png_color_16p background));
  161660. #endif
  161661. #if defined(PNG_cHRM_SUPPORTED)
  161662. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161663. extern PNG_EXPORT(png_uint_32,png_get_cHRM) PNGARG((png_structp png_ptr,
  161664. png_infop info_ptr, double *white_x, double *white_y, double *red_x,
  161665. double *red_y, double *green_x, double *green_y, double *blue_x,
  161666. double *blue_y));
  161667. #endif
  161668. #ifdef PNG_FIXED_POINT_SUPPORTED
  161669. extern PNG_EXPORT(png_uint_32,png_get_cHRM_fixed) PNGARG((png_structp png_ptr,
  161670. png_infop info_ptr, png_fixed_point *int_white_x, png_fixed_point
  161671. *int_white_y, png_fixed_point *int_red_x, png_fixed_point *int_red_y,
  161672. png_fixed_point *int_green_x, png_fixed_point *int_green_y, png_fixed_point
  161673. *int_blue_x, png_fixed_point *int_blue_y));
  161674. #endif
  161675. #endif
  161676. #if defined(PNG_cHRM_SUPPORTED)
  161677. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161678. extern PNG_EXPORT(void,png_set_cHRM) PNGARG((png_structp png_ptr,
  161679. png_infop info_ptr, double white_x, double white_y, double red_x,
  161680. double red_y, double green_x, double green_y, double blue_x, double blue_y));
  161681. #endif
  161682. #ifdef PNG_FIXED_POINT_SUPPORTED
  161683. extern PNG_EXPORT(void,png_set_cHRM_fixed) PNGARG((png_structp png_ptr,
  161684. png_infop info_ptr, png_fixed_point int_white_x, png_fixed_point int_white_y,
  161685. png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point
  161686. int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x,
  161687. png_fixed_point int_blue_y));
  161688. #endif
  161689. #endif
  161690. #if defined(PNG_gAMA_SUPPORTED)
  161691. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161692. extern PNG_EXPORT(png_uint_32,png_get_gAMA) PNGARG((png_structp png_ptr,
  161693. png_infop info_ptr, double *file_gamma));
  161694. #endif
  161695. extern PNG_EXPORT(png_uint_32,png_get_gAMA_fixed) PNGARG((png_structp png_ptr,
  161696. png_infop info_ptr, png_fixed_point *int_file_gamma));
  161697. #endif
  161698. #if defined(PNG_gAMA_SUPPORTED)
  161699. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161700. extern PNG_EXPORT(void,png_set_gAMA) PNGARG((png_structp png_ptr,
  161701. png_infop info_ptr, double file_gamma));
  161702. #endif
  161703. extern PNG_EXPORT(void,png_set_gAMA_fixed) PNGARG((png_structp png_ptr,
  161704. png_infop info_ptr, png_fixed_point int_file_gamma));
  161705. #endif
  161706. #if defined(PNG_hIST_SUPPORTED)
  161707. extern PNG_EXPORT(png_uint_32,png_get_hIST) PNGARG((png_structp png_ptr,
  161708. png_infop info_ptr, png_uint_16p *hist));
  161709. #endif
  161710. #if defined(PNG_hIST_SUPPORTED)
  161711. extern PNG_EXPORT(void,png_set_hIST) PNGARG((png_structp png_ptr,
  161712. png_infop info_ptr, png_uint_16p hist));
  161713. #endif
  161714. extern PNG_EXPORT(png_uint_32,png_get_IHDR) PNGARG((png_structp png_ptr,
  161715. png_infop info_ptr, png_uint_32 *width, png_uint_32 *height,
  161716. int *bit_depth, int *color_type, int *interlace_method,
  161717. int *compression_method, int *filter_method));
  161718. extern PNG_EXPORT(void,png_set_IHDR) PNGARG((png_structp png_ptr,
  161719. png_infop info_ptr, png_uint_32 width, png_uint_32 height, int bit_depth,
  161720. int color_type, int interlace_method, int compression_method,
  161721. int filter_method));
  161722. #if defined(PNG_oFFs_SUPPORTED)
  161723. extern PNG_EXPORT(png_uint_32,png_get_oFFs) PNGARG((png_structp png_ptr,
  161724. png_infop info_ptr, png_int_32 *offset_x, png_int_32 *offset_y,
  161725. int *unit_type));
  161726. #endif
  161727. #if defined(PNG_oFFs_SUPPORTED)
  161728. extern PNG_EXPORT(void,png_set_oFFs) PNGARG((png_structp png_ptr,
  161729. png_infop info_ptr, png_int_32 offset_x, png_int_32 offset_y,
  161730. int unit_type));
  161731. #endif
  161732. #if defined(PNG_pCAL_SUPPORTED)
  161733. extern PNG_EXPORT(png_uint_32,png_get_pCAL) PNGARG((png_structp png_ptr,
  161734. png_infop info_ptr, png_charp *purpose, png_int_32 *X0, png_int_32 *X1,
  161735. int *type, int *nparams, png_charp *units, png_charpp *params));
  161736. #endif
  161737. #if defined(PNG_pCAL_SUPPORTED)
  161738. extern PNG_EXPORT(void,png_set_pCAL) PNGARG((png_structp png_ptr,
  161739. png_infop info_ptr, png_charp purpose, png_int_32 X0, png_int_32 X1,
  161740. int type, int nparams, png_charp units, png_charpp params));
  161741. #endif
  161742. #if defined(PNG_pHYs_SUPPORTED)
  161743. extern PNG_EXPORT(png_uint_32,png_get_pHYs) PNGARG((png_structp png_ptr,
  161744. png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type));
  161745. #endif
  161746. #if defined(PNG_pHYs_SUPPORTED)
  161747. extern PNG_EXPORT(void,png_set_pHYs) PNGARG((png_structp png_ptr,
  161748. png_infop info_ptr, png_uint_32 res_x, png_uint_32 res_y, int unit_type));
  161749. #endif
  161750. extern PNG_EXPORT(png_uint_32,png_get_PLTE) PNGARG((png_structp png_ptr,
  161751. png_infop info_ptr, png_colorp *palette, int *num_palette));
  161752. extern PNG_EXPORT(void,png_set_PLTE) PNGARG((png_structp png_ptr,
  161753. png_infop info_ptr, png_colorp palette, int num_palette));
  161754. #if defined(PNG_sBIT_SUPPORTED)
  161755. extern PNG_EXPORT(png_uint_32,png_get_sBIT) PNGARG((png_structp png_ptr,
  161756. png_infop info_ptr, png_color_8p *sig_bit));
  161757. #endif
  161758. #if defined(PNG_sBIT_SUPPORTED)
  161759. extern PNG_EXPORT(void,png_set_sBIT) PNGARG((png_structp png_ptr,
  161760. png_infop info_ptr, png_color_8p sig_bit));
  161761. #endif
  161762. #if defined(PNG_sRGB_SUPPORTED)
  161763. extern PNG_EXPORT(png_uint_32,png_get_sRGB) PNGARG((png_structp png_ptr,
  161764. png_infop info_ptr, int *intent));
  161765. #endif
  161766. #if defined(PNG_sRGB_SUPPORTED)
  161767. extern PNG_EXPORT(void,png_set_sRGB) PNGARG((png_structp png_ptr,
  161768. png_infop info_ptr, int intent));
  161769. extern PNG_EXPORT(void,png_set_sRGB_gAMA_and_cHRM) PNGARG((png_structp png_ptr,
  161770. png_infop info_ptr, int intent));
  161771. #endif
  161772. #if defined(PNG_iCCP_SUPPORTED)
  161773. extern PNG_EXPORT(png_uint_32,png_get_iCCP) PNGARG((png_structp png_ptr,
  161774. png_infop info_ptr, png_charpp name, int *compression_type,
  161775. png_charpp profile, png_uint_32 *proflen));
  161776. #endif
  161777. #if defined(PNG_iCCP_SUPPORTED)
  161778. extern PNG_EXPORT(void,png_set_iCCP) PNGARG((png_structp png_ptr,
  161779. png_infop info_ptr, png_charp name, int compression_type,
  161780. png_charp profile, png_uint_32 proflen));
  161781. #endif
  161782. #if defined(PNG_sPLT_SUPPORTED)
  161783. extern PNG_EXPORT(png_uint_32,png_get_sPLT) PNGARG((png_structp png_ptr,
  161784. png_infop info_ptr, png_sPLT_tpp entries));
  161785. #endif
  161786. #if defined(PNG_sPLT_SUPPORTED)
  161787. extern PNG_EXPORT(void,png_set_sPLT) PNGARG((png_structp png_ptr,
  161788. png_infop info_ptr, png_sPLT_tp entries, int nentries));
  161789. #endif
  161790. #if defined(PNG_TEXT_SUPPORTED)
  161791. extern PNG_EXPORT(png_uint_32,png_get_text) PNGARG((png_structp png_ptr,
  161792. png_infop info_ptr, png_textp *text_ptr, int *num_text));
  161793. #endif
  161794. #if defined(PNG_TEXT_SUPPORTED)
  161795. extern PNG_EXPORT(void,png_set_text) PNGARG((png_structp png_ptr,
  161796. png_infop info_ptr, png_textp text_ptr, int num_text));
  161797. #endif
  161798. #if defined(PNG_tIME_SUPPORTED)
  161799. extern PNG_EXPORT(png_uint_32,png_get_tIME) PNGARG((png_structp png_ptr,
  161800. png_infop info_ptr, png_timep *mod_time));
  161801. #endif
  161802. #if defined(PNG_tIME_SUPPORTED)
  161803. extern PNG_EXPORT(void,png_set_tIME) PNGARG((png_structp png_ptr,
  161804. png_infop info_ptr, png_timep mod_time));
  161805. #endif
  161806. #if defined(PNG_tRNS_SUPPORTED)
  161807. extern PNG_EXPORT(png_uint_32,png_get_tRNS) PNGARG((png_structp png_ptr,
  161808. png_infop info_ptr, png_bytep *trans, int *num_trans,
  161809. png_color_16p *trans_values));
  161810. #endif
  161811. #if defined(PNG_tRNS_SUPPORTED)
  161812. extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr,
  161813. png_infop info_ptr, png_bytep trans, int num_trans,
  161814. png_color_16p trans_values));
  161815. #endif
  161816. #if defined(PNG_tRNS_SUPPORTED)
  161817. #endif
  161818. #if defined(PNG_sCAL_SUPPORTED)
  161819. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161820. extern PNG_EXPORT(png_uint_32,png_get_sCAL) PNGARG((png_structp png_ptr,
  161821. png_infop info_ptr, int *unit, double *width, double *height));
  161822. #else
  161823. #ifdef PNG_FIXED_POINT_SUPPORTED
  161824. extern PNG_EXPORT(png_uint_32,png_get_sCAL_s) PNGARG((png_structp png_ptr,
  161825. png_infop info_ptr, int *unit, png_charpp swidth, png_charpp sheight));
  161826. #endif
  161827. #endif
  161828. #endif /* PNG_sCAL_SUPPORTED */
  161829. #if defined(PNG_sCAL_SUPPORTED)
  161830. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161831. extern PNG_EXPORT(void,png_set_sCAL) PNGARG((png_structp png_ptr,
  161832. png_infop info_ptr, int unit, double width, double height));
  161833. #else
  161834. #ifdef PNG_FIXED_POINT_SUPPORTED
  161835. extern PNG_EXPORT(void,png_set_sCAL_s) PNGARG((png_structp png_ptr,
  161836. png_infop info_ptr, int unit, png_charp swidth, png_charp sheight));
  161837. #endif
  161838. #endif
  161839. #endif /* PNG_sCAL_SUPPORTED || PNG_WRITE_sCAL_SUPPORTED */
  161840. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  161841. extern PNG_EXPORT(void, png_set_keep_unknown_chunks) PNGARG((png_structp
  161842. png_ptr, int keep, png_bytep chunk_list, int num_chunks));
  161843. extern PNG_EXPORT(void, png_set_unknown_chunks) PNGARG((png_structp png_ptr,
  161844. png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns));
  161845. extern PNG_EXPORT(void, png_set_unknown_chunk_location)
  161846. PNGARG((png_structp png_ptr, png_infop info_ptr, int chunk, int location));
  161847. extern PNG_EXPORT(png_uint_32,png_get_unknown_chunks) PNGARG((png_structp
  161848. png_ptr, png_infop info_ptr, png_unknown_chunkpp entries));
  161849. #endif
  161850. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  161851. PNG_EXPORT(int,png_handle_as_unknown) PNGARG((png_structp png_ptr, png_bytep
  161852. chunk_name));
  161853. #endif
  161854. extern PNG_EXPORT(void, png_set_invalid) PNGARG((png_structp png_ptr,
  161855. png_infop info_ptr, int mask));
  161856. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  161857. extern PNG_EXPORT(void, png_read_png) PNGARG((png_structp png_ptr,
  161858. png_infop info_ptr,
  161859. int transforms,
  161860. png_voidp params));
  161861. extern PNG_EXPORT(void, png_write_png) PNGARG((png_structp png_ptr,
  161862. png_infop info_ptr,
  161863. int transforms,
  161864. png_voidp params));
  161865. #endif
  161866. #ifdef PNG_DEBUG
  161867. #if (PNG_DEBUG > 0)
  161868. #if !defined(PNG_DEBUG_FILE) && defined(_MSC_VER)
  161869. #include <crtdbg.h>
  161870. #if (PNG_DEBUG > 1)
  161871. #define png_debug(l,m) _RPT0(_CRT_WARN,m)
  161872. #define png_debug1(l,m,p1) _RPT1(_CRT_WARN,m,p1)
  161873. #define png_debug2(l,m,p1,p2) _RPT2(_CRT_WARN,m,p1,p2)
  161874. #endif
  161875. #else /* PNG_DEBUG_FILE || !_MSC_VER */
  161876. #ifndef PNG_DEBUG_FILE
  161877. #define PNG_DEBUG_FILE stderr
  161878. #endif /* PNG_DEBUG_FILE */
  161879. #if (PNG_DEBUG > 1)
  161880. #define png_debug(l,m) \
  161881. { \
  161882. int num_tabs=l; \
  161883. fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
  161884. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":"")))); \
  161885. }
  161886. #define png_debug1(l,m,p1) \
  161887. { \
  161888. int num_tabs=l; \
  161889. fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
  161890. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1); \
  161891. }
  161892. #define png_debug2(l,m,p1,p2) \
  161893. { \
  161894. int num_tabs=l; \
  161895. fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
  161896. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1,p2); \
  161897. }
  161898. #endif /* (PNG_DEBUG > 1) */
  161899. #endif /* _MSC_VER */
  161900. #endif /* (PNG_DEBUG > 0) */
  161901. #endif /* PNG_DEBUG */
  161902. #ifndef png_debug
  161903. #define png_debug(l, m)
  161904. #endif
  161905. #ifndef png_debug1
  161906. #define png_debug1(l, m, p1)
  161907. #endif
  161908. #ifndef png_debug2
  161909. #define png_debug2(l, m, p1, p2)
  161910. #endif
  161911. extern PNG_EXPORT(png_charp,png_get_copyright) PNGARG((png_structp png_ptr));
  161912. extern PNG_EXPORT(png_charp,png_get_header_ver) PNGARG((png_structp png_ptr));
  161913. extern PNG_EXPORT(png_charp,png_get_header_version) PNGARG((png_structp png_ptr));
  161914. extern PNG_EXPORT(png_charp,png_get_libpng_ver) PNGARG((png_structp png_ptr));
  161915. #ifdef PNG_MNG_FEATURES_SUPPORTED
  161916. extern PNG_EXPORT(png_uint_32,png_permit_mng_features) PNGARG((png_structp
  161917. png_ptr, png_uint_32 mng_features_permitted));
  161918. #endif
  161919. #define PNG_HANDLE_CHUNK_AS_DEFAULT 0
  161920. #define PNG_HANDLE_CHUNK_NEVER 1
  161921. #define PNG_HANDLE_CHUNK_IF_SAFE 2
  161922. #define PNG_HANDLE_CHUNK_ALWAYS 3
  161923. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  161924. #if defined(PNG_MMX_CODE_SUPPORTED)
  161925. #define PNG_ASM_FLAG_MMX_SUPPORT_COMPILED 0x01 /* not user-settable */
  161926. #define PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU 0x02 /* not user-settable */
  161927. #define PNG_ASM_FLAG_MMX_READ_COMBINE_ROW 0x04
  161928. #define PNG_ASM_FLAG_MMX_READ_INTERLACE 0x08
  161929. #define PNG_ASM_FLAG_MMX_READ_FILTER_SUB 0x10
  161930. #define PNG_ASM_FLAG_MMX_READ_FILTER_UP 0x20
  161931. #define PNG_ASM_FLAG_MMX_READ_FILTER_AVG 0x40
  161932. #define PNG_ASM_FLAG_MMX_READ_FILTER_PAETH 0x80
  161933. #define PNG_ASM_FLAGS_INITIALIZED 0x80000000 /* not user-settable */
  161934. #define PNG_MMX_READ_FLAGS ( PNG_ASM_FLAG_MMX_READ_COMBINE_ROW \
  161935. | PNG_ASM_FLAG_MMX_READ_INTERLACE \
  161936. | PNG_ASM_FLAG_MMX_READ_FILTER_SUB \
  161937. | PNG_ASM_FLAG_MMX_READ_FILTER_UP \
  161938. | PNG_ASM_FLAG_MMX_READ_FILTER_AVG \
  161939. | PNG_ASM_FLAG_MMX_READ_FILTER_PAETH )
  161940. #define PNG_MMX_WRITE_FLAGS ( 0 )
  161941. #define PNG_MMX_FLAGS ( PNG_ASM_FLAG_MMX_SUPPORT_COMPILED \
  161942. | PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU \
  161943. | PNG_MMX_READ_FLAGS \
  161944. | PNG_MMX_WRITE_FLAGS )
  161945. #define PNG_SELECT_READ 1
  161946. #define PNG_SELECT_WRITE 2
  161947. #endif /* PNG_MMX_CODE_SUPPORTED */
  161948. #if !defined(PNG_1_0_X)
  161949. extern PNG_EXPORT(png_uint_32,png_get_mmx_flagmask)
  161950. PNGARG((int flag_select, int *compilerID));
  161951. extern PNG_EXPORT(png_uint_32,png_get_asm_flagmask)
  161952. PNGARG((int flag_select));
  161953. extern PNG_EXPORT(png_uint_32,png_get_asm_flags)
  161954. PNGARG((png_structp png_ptr));
  161955. extern PNG_EXPORT(png_byte,png_get_mmx_bitdepth_threshold)
  161956. PNGARG((png_structp png_ptr));
  161957. extern PNG_EXPORT(png_uint_32,png_get_mmx_rowbytes_threshold)
  161958. PNGARG((png_structp png_ptr));
  161959. extern PNG_EXPORT(void,png_set_asm_flags)
  161960. PNGARG((png_structp png_ptr, png_uint_32 asm_flags));
  161961. extern PNG_EXPORT(void,png_set_mmx_thresholds)
  161962. PNGARG((png_structp png_ptr, png_byte mmx_bitdepth_threshold,
  161963. png_uint_32 mmx_rowbytes_threshold));
  161964. #endif /* PNG_1_0_X */
  161965. #if !defined(PNG_1_0_X)
  161966. extern PNG_EXPORT(int,png_mmx_support) PNGARG((void));
  161967. #endif /* PNG_ASSEMBLER_CODE_SUPPORTED */
  161968. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  161969. extern PNG_EXPORT(void,png_set_strip_error_numbers) PNGARG((png_structp
  161970. png_ptr, png_uint_32 strip_mode));
  161971. #endif
  161972. #endif /* PNG_1_0_X */
  161973. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  161974. extern PNG_EXPORT(void,png_set_user_limits) PNGARG((png_structp
  161975. png_ptr, png_uint_32 user_width_max, png_uint_32 user_height_max));
  161976. extern PNG_EXPORT(png_uint_32,png_get_user_width_max) PNGARG((png_structp
  161977. png_ptr));
  161978. extern PNG_EXPORT(png_uint_32,png_get_user_height_max) PNGARG((png_structp
  161979. png_ptr));
  161980. #endif
  161981. #ifdef PNG_READ_COMPOSITE_NODIV_SUPPORTED
  161982. # define png_composite(composite, fg, alpha, bg) \
  161983. { png_uint_16 temp = (png_uint_16)((png_uint_16)(fg) * (png_uint_16)(alpha) \
  161984. + (png_uint_16)(bg)*(png_uint_16)(255 - \
  161985. (png_uint_16)(alpha)) + (png_uint_16)128); \
  161986. (composite) = (png_byte)((temp + (temp >> 8)) >> 8); }
  161987. # define png_composite_16(composite, fg, alpha, bg) \
  161988. { png_uint_32 temp = (png_uint_32)((png_uint_32)(fg) * (png_uint_32)(alpha) \
  161989. + (png_uint_32)(bg)*(png_uint_32)(65535L - \
  161990. (png_uint_32)(alpha)) + (png_uint_32)32768L); \
  161991. (composite) = (png_uint_16)((temp + (temp >> 16)) >> 16); }
  161992. #else /* standard method using integer division */
  161993. # define png_composite(composite, fg, alpha, bg) \
  161994. (composite) = (png_byte)(((png_uint_16)(fg) * (png_uint_16)(alpha) + \
  161995. (png_uint_16)(bg) * (png_uint_16)(255 - (png_uint_16)(alpha)) + \
  161996. (png_uint_16)127) / 255)
  161997. # define png_composite_16(composite, fg, alpha, bg) \
  161998. (composite) = (png_uint_16)(((png_uint_32)(fg) * (png_uint_32)(alpha) + \
  161999. (png_uint_32)(bg)*(png_uint_32)(65535L - (png_uint_32)(alpha)) + \
  162000. (png_uint_32)32767) / (png_uint_32)65535L)
  162001. #endif /* PNG_READ_COMPOSITE_NODIV_SUPPORTED */
  162002. #if defined(PNG_READ_BIG_ENDIAN_SUPPORTED)
  162003. # define png_get_uint_32(buf) ( *((png_uint_32p) (buf)))
  162004. # define png_get_uint_16(buf) ( *((png_uint_16p) (buf)))
  162005. # define png_get_int_32(buf) ( *((png_int_32p) (buf)))
  162006. #else
  162007. extern PNG_EXPORT(png_uint_32,png_get_uint_32) PNGARG((png_bytep buf));
  162008. extern PNG_EXPORT(png_uint_16,png_get_uint_16) PNGARG((png_bytep buf));
  162009. extern PNG_EXPORT(png_int_32,png_get_int_32) PNGARG((png_bytep buf));
  162010. #endif /* !PNG_READ_BIG_ENDIAN_SUPPORTED */
  162011. extern PNG_EXPORT(png_uint_32,png_get_uint_31)
  162012. PNGARG((png_structp png_ptr, png_bytep buf));
  162013. extern PNG_EXPORT(void,png_save_uint_32)
  162014. PNGARG((png_bytep buf, png_uint_32 i));
  162015. extern PNG_EXPORT(void,png_save_int_32)
  162016. PNGARG((png_bytep buf, png_int_32 i));
  162017. extern PNG_EXPORT(void,png_save_uint_16)
  162018. PNGARG((png_bytep buf, unsigned int i));
  162019. #define PNG_HAVE_IHDR 0x01
  162020. #define PNG_HAVE_PLTE 0x02
  162021. #define PNG_HAVE_IDAT 0x04
  162022. #define PNG_AFTER_IDAT 0x08 /* Have complete zlib datastream */
  162023. #define PNG_HAVE_IEND 0x10
  162024. #if defined(PNG_INTERNAL)
  162025. #define PNG_HAVE_gAMA 0x20
  162026. #define PNG_HAVE_cHRM 0x40
  162027. #define PNG_HAVE_sRGB 0x80
  162028. #define PNG_HAVE_CHUNK_HEADER 0x100
  162029. #define PNG_WROTE_tIME 0x200
  162030. #define PNG_WROTE_INFO_BEFORE_PLTE 0x400
  162031. #define PNG_BACKGROUND_IS_GRAY 0x800
  162032. #define PNG_HAVE_PNG_SIGNATURE 0x1000
  162033. #define PNG_HAVE_CHUNK_AFTER_IDAT 0x2000 /* Have another chunk after IDAT */
  162034. #define PNG_BGR 0x0001
  162035. #define PNG_INTERLACE 0x0002
  162036. #define PNG_PACK 0x0004
  162037. #define PNG_SHIFT 0x0008
  162038. #define PNG_SWAP_BYTES 0x0010
  162039. #define PNG_INVERT_MONO 0x0020
  162040. #define PNG_DITHER 0x0040
  162041. #define PNG_BACKGROUND 0x0080
  162042. #define PNG_BACKGROUND_EXPAND 0x0100
  162043. #define PNG_16_TO_8 0x0400
  162044. #define PNG_RGBA 0x0800
  162045. #define PNG_EXPAND 0x1000
  162046. #define PNG_GAMMA 0x2000
  162047. #define PNG_GRAY_TO_RGB 0x4000
  162048. #define PNG_FILLER 0x8000L
  162049. #define PNG_PACKSWAP 0x10000L
  162050. #define PNG_SWAP_ALPHA 0x20000L
  162051. #define PNG_STRIP_ALPHA 0x40000L
  162052. #define PNG_INVERT_ALPHA 0x80000L
  162053. #define PNG_USER_TRANSFORM 0x100000L
  162054. #define PNG_RGB_TO_GRAY_ERR 0x200000L
  162055. #define PNG_RGB_TO_GRAY_WARN 0x400000L
  162056. #define PNG_RGB_TO_GRAY 0x600000L /* two bits, RGB_TO_GRAY_ERR|WARN */
  162057. #define PNG_ADD_ALPHA 0x1000000L /* Added to libpng-1.2.7 */
  162058. #define PNG_EXPAND_tRNS 0x2000000L /* Added to libpng-1.2.9 */
  162059. #define PNG_STRUCT_PNG 0x0001
  162060. #define PNG_STRUCT_INFO 0x0002
  162061. #define PNG_WEIGHT_SHIFT 8
  162062. #define PNG_WEIGHT_FACTOR (1<<(PNG_WEIGHT_SHIFT))
  162063. #define PNG_COST_SHIFT 3
  162064. #define PNG_COST_FACTOR (1<<(PNG_COST_SHIFT))
  162065. #define PNG_FLAG_ZLIB_CUSTOM_STRATEGY 0x0001
  162066. #define PNG_FLAG_ZLIB_CUSTOM_LEVEL 0x0002
  162067. #define PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL 0x0004
  162068. #define PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS 0x0008
  162069. #define PNG_FLAG_ZLIB_CUSTOM_METHOD 0x0010
  162070. #define PNG_FLAG_ZLIB_FINISHED 0x0020
  162071. #define PNG_FLAG_ROW_INIT 0x0040
  162072. #define PNG_FLAG_FILLER_AFTER 0x0080
  162073. #define PNG_FLAG_CRC_ANCILLARY_USE 0x0100
  162074. #define PNG_FLAG_CRC_ANCILLARY_NOWARN 0x0200
  162075. #define PNG_FLAG_CRC_CRITICAL_USE 0x0400
  162076. #define PNG_FLAG_CRC_CRITICAL_IGNORE 0x0800
  162077. #define PNG_FLAG_FREE_PLTE 0x1000
  162078. #define PNG_FLAG_FREE_TRNS 0x2000
  162079. #define PNG_FLAG_FREE_HIST 0x4000
  162080. #define PNG_FLAG_KEEP_UNKNOWN_CHUNKS 0x8000L
  162081. #define PNG_FLAG_KEEP_UNSAFE_CHUNKS 0x10000L
  162082. #define PNG_FLAG_LIBRARY_MISMATCH 0x20000L
  162083. #define PNG_FLAG_STRIP_ERROR_NUMBERS 0x40000L
  162084. #define PNG_FLAG_STRIP_ERROR_TEXT 0x80000L
  162085. #define PNG_FLAG_MALLOC_NULL_MEM_OK 0x100000L
  162086. #define PNG_FLAG_ADD_ALPHA 0x200000L /* Added to libpng-1.2.8 */
  162087. #define PNG_FLAG_STRIP_ALPHA 0x400000L /* Added to libpng-1.2.8 */
  162088. #define PNG_FLAG_CRC_ANCILLARY_MASK (PNG_FLAG_CRC_ANCILLARY_USE | \
  162089. PNG_FLAG_CRC_ANCILLARY_NOWARN)
  162090. #define PNG_FLAG_CRC_CRITICAL_MASK (PNG_FLAG_CRC_CRITICAL_USE | \
  162091. PNG_FLAG_CRC_CRITICAL_IGNORE)
  162092. #define PNG_FLAG_CRC_MASK (PNG_FLAG_CRC_ANCILLARY_MASK | \
  162093. PNG_FLAG_CRC_CRITICAL_MASK)
  162094. #define PNG_COLOR_DIST(c1, c2) (abs((int)((c1).red) - (int)((c2).red)) + \
  162095. abs((int)((c1).green) - (int)((c2).green)) + \
  162096. abs((int)((c1).blue) - (int)((c2).blue)))
  162097. #define PNG_ROWBYTES(pixel_bits, width) \
  162098. ((pixel_bits) >= 8 ? \
  162099. ((width) * (((png_uint_32)(pixel_bits)) >> 3)) : \
  162100. (( ((width) * ((png_uint_32)(pixel_bits))) + 7) >> 3) )
  162101. #define PNG_OUT_OF_RANGE(value, ideal, delta) \
  162102. ( (value) < (ideal)-(delta) || (value) > (ideal)+(delta) )
  162103. #if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN)
  162104. #ifdef PNG_USE_GLOBAL_ARRAYS
  162105. PNG_EXPORT_VAR (PNG_CONST png_byte FARDATA) png_sig[8];
  162106. #else
  162107. #endif
  162108. #endif /* PNG_NO_EXTERN */
  162109. #define PNG_IHDR png_byte png_IHDR[5] = { 73, 72, 68, 82, '\0'}
  162110. #define PNG_IDAT png_byte png_IDAT[5] = { 73, 68, 65, 84, '\0'}
  162111. #define PNG_IEND png_byte png_IEND[5] = { 73, 69, 78, 68, '\0'}
  162112. #define PNG_PLTE png_byte png_PLTE[5] = { 80, 76, 84, 69, '\0'}
  162113. #define PNG_bKGD png_byte png_bKGD[5] = { 98, 75, 71, 68, '\0'}
  162114. #define PNG_cHRM png_byte png_cHRM[5] = { 99, 72, 82, 77, '\0'}
  162115. #define PNG_gAMA png_byte png_gAMA[5] = {103, 65, 77, 65, '\0'}
  162116. #define PNG_hIST png_byte png_hIST[5] = {104, 73, 83, 84, '\0'}
  162117. #define PNG_iCCP png_byte png_iCCP[5] = {105, 67, 67, 80, '\0'}
  162118. #define PNG_iTXt png_byte png_iTXt[5] = {105, 84, 88, 116, '\0'}
  162119. #define PNG_oFFs png_byte png_oFFs[5] = {111, 70, 70, 115, '\0'}
  162120. #define PNG_pCAL png_byte png_pCAL[5] = {112, 67, 65, 76, '\0'}
  162121. #define PNG_sCAL png_byte png_sCAL[5] = {115, 67, 65, 76, '\0'}
  162122. #define PNG_pHYs png_byte png_pHYs[5] = {112, 72, 89, 115, '\0'}
  162123. #define PNG_sBIT png_byte png_sBIT[5] = {115, 66, 73, 84, '\0'}
  162124. #define PNG_sPLT png_byte png_sPLT[5] = {115, 80, 76, 84, '\0'}
  162125. #define PNG_sRGB png_byte png_sRGB[5] = {115, 82, 71, 66, '\0'}
  162126. #define PNG_tEXt png_byte png_tEXt[5] = {116, 69, 88, 116, '\0'}
  162127. #define PNG_tIME png_byte png_tIME[5] = {116, 73, 77, 69, '\0'}
  162128. #define PNG_tRNS png_byte png_tRNS[5] = {116, 82, 78, 83, '\0'}
  162129. #define PNG_zTXt png_byte png_zTXt[5] = {122, 84, 88, 116, '\0'}
  162130. #ifdef PNG_USE_GLOBAL_ARRAYS
  162131. PNG_EXPORT_VAR (png_byte FARDATA) png_IHDR[5];
  162132. PNG_EXPORT_VAR (png_byte FARDATA) png_IDAT[5];
  162133. PNG_EXPORT_VAR (png_byte FARDATA) png_IEND[5];
  162134. PNG_EXPORT_VAR (png_byte FARDATA) png_PLTE[5];
  162135. PNG_EXPORT_VAR (png_byte FARDATA) png_bKGD[5];
  162136. PNG_EXPORT_VAR (png_byte FARDATA) png_cHRM[5];
  162137. PNG_EXPORT_VAR (png_byte FARDATA) png_gAMA[5];
  162138. PNG_EXPORT_VAR (png_byte FARDATA) png_hIST[5];
  162139. PNG_EXPORT_VAR (png_byte FARDATA) png_iCCP[5];
  162140. PNG_EXPORT_VAR (png_byte FARDATA) png_iTXt[5];
  162141. PNG_EXPORT_VAR (png_byte FARDATA) png_oFFs[5];
  162142. PNG_EXPORT_VAR (png_byte FARDATA) png_pCAL[5];
  162143. PNG_EXPORT_VAR (png_byte FARDATA) png_sCAL[5];
  162144. PNG_EXPORT_VAR (png_byte FARDATA) png_pHYs[5];
  162145. PNG_EXPORT_VAR (png_byte FARDATA) png_sBIT[5];
  162146. PNG_EXPORT_VAR (png_byte FARDATA) png_sPLT[5];
  162147. PNG_EXPORT_VAR (png_byte FARDATA) png_sRGB[5];
  162148. PNG_EXPORT_VAR (png_byte FARDATA) png_tEXt[5];
  162149. PNG_EXPORT_VAR (png_byte FARDATA) png_tIME[5];
  162150. PNG_EXPORT_VAR (png_byte FARDATA) png_tRNS[5];
  162151. PNG_EXPORT_VAR (png_byte FARDATA) png_zTXt[5];
  162152. #endif /* PNG_USE_GLOBAL_ARRAYS */
  162153. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  162154. extern PNG_EXPORT(void,png_read_init) PNGARG((png_structp png_ptr));
  162155. #undef png_read_init
  162156. #define png_read_init(png_ptr) png_read_init_3(&png_ptr, \
  162157. PNG_LIBPNG_VER_STRING, png_sizeof(png_struct));
  162158. #endif
  162159. extern PNG_EXPORT(void,png_read_init_3) PNGARG((png_structpp ptr_ptr,
  162160. png_const_charp user_png_ver, png_size_t png_struct_size));
  162161. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  162162. extern PNG_EXPORT(void,png_read_init_2) PNGARG((png_structp png_ptr,
  162163. png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t
  162164. png_info_size));
  162165. #endif
  162166. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  162167. extern PNG_EXPORT(void,png_write_init) PNGARG((png_structp png_ptr));
  162168. #undef png_write_init
  162169. #define png_write_init(png_ptr) png_write_init_3(&png_ptr, \
  162170. PNG_LIBPNG_VER_STRING, png_sizeof(png_struct));
  162171. #endif
  162172. extern PNG_EXPORT(void,png_write_init_3) PNGARG((png_structpp ptr_ptr,
  162173. png_const_charp user_png_ver, png_size_t png_struct_size));
  162174. extern PNG_EXPORT(void,png_write_init_2) PNGARG((png_structp png_ptr,
  162175. png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t
  162176. png_info_size));
  162177. PNG_EXTERN png_voidp png_create_struct PNGARG((int type));
  162178. PNG_EXTERN void png_destroy_struct PNGARG((png_voidp struct_ptr));
  162179. PNG_EXTERN png_voidp png_create_struct_2 PNGARG((int type, png_malloc_ptr
  162180. malloc_fn, png_voidp mem_ptr));
  162181. PNG_EXTERN void png_destroy_struct_2 PNGARG((png_voidp struct_ptr,
  162182. png_free_ptr free_fn, png_voidp mem_ptr));
  162183. PNG_EXTERN void png_info_destroy PNGARG((png_structp png_ptr,
  162184. png_infop info_ptr));
  162185. #ifndef PNG_1_0_X
  162186. PNG_EXTERN voidpf png_zalloc PNGARG((voidpf png_ptr, uInt items, uInt size));
  162187. PNG_EXTERN void png_zfree PNGARG((voidpf png_ptr, voidpf ptr));
  162188. #ifdef PNG_SIZE_T
  162189. PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size));
  162190. #endif
  162191. PNG_EXTERN void PNGAPI png_default_read_data PNGARG((png_structp png_ptr,
  162192. png_bytep data, png_size_t length));
  162193. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  162194. PNG_EXTERN void PNGAPI png_push_fill_buffer PNGARG((png_structp png_ptr,
  162195. png_bytep buffer, png_size_t length));
  162196. #endif
  162197. PNG_EXTERN void PNGAPI png_default_write_data PNGARG((png_structp png_ptr,
  162198. png_bytep data, png_size_t length));
  162199. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  162200. #if !defined(PNG_NO_STDIO)
  162201. PNG_EXTERN void PNGAPI png_default_flush PNGARG((png_structp png_ptr));
  162202. #endif
  162203. #endif
  162204. #else /* PNG_1_0_X */
  162205. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  162206. PNG_EXTERN void png_push_fill_buffer PNGARG((png_structp png_ptr,
  162207. png_bytep buffer, png_size_t length));
  162208. #endif
  162209. #endif /* PNG_1_0_X */
  162210. PNG_EXTERN void png_reset_crc PNGARG((png_structp png_ptr));
  162211. PNG_EXTERN void png_write_data PNGARG((png_structp png_ptr, png_bytep data,
  162212. png_size_t length));
  162213. PNG_EXTERN void png_read_data PNGARG((png_structp png_ptr, png_bytep data,
  162214. png_size_t length));
  162215. PNG_EXTERN void png_crc_read PNGARG((png_structp png_ptr, png_bytep buf,
  162216. png_size_t length));
  162217. #if defined(PNG_zTXt_SUPPORTED) || defined(PNG_iTXt_SUPPORTED) || \
  162218. defined(PNG_iCCP_SUPPORTED) || defined(PNG_sPLT_SUPPORTED)
  162219. PNG_EXTERN png_charp png_decompress_chunk PNGARG((png_structp png_ptr,
  162220. int comp_type, png_charp chunkdata, png_size_t chunklength,
  162221. png_size_t prefix_length, png_size_t *data_length));
  162222. #endif
  162223. PNG_EXTERN int png_crc_finish PNGARG((png_structp png_ptr, png_uint_32 skip));
  162224. PNG_EXTERN int png_crc_error PNGARG((png_structp png_ptr));
  162225. PNG_EXTERN void png_calculate_crc PNGARG((png_structp png_ptr, png_bytep ptr,
  162226. png_size_t length));
  162227. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  162228. PNG_EXTERN void png_flush PNGARG((png_structp png_ptr));
  162229. #endif
  162230. PNG_EXTERN void png_write_sig PNGARG((png_structp png_ptr));
  162231. PNG_EXTERN void png_write_IHDR PNGARG((png_structp png_ptr, png_uint_32 width,
  162232. png_uint_32 height,
  162233. int bit_depth, int color_type, int compression_method, int filter_method,
  162234. int interlace_method));
  162235. PNG_EXTERN void png_write_PLTE PNGARG((png_structp png_ptr, png_colorp palette,
  162236. png_uint_32 num_pal));
  162237. PNG_EXTERN void png_write_IDAT PNGARG((png_structp png_ptr, png_bytep data,
  162238. png_size_t length));
  162239. PNG_EXTERN void png_write_IEND PNGARG((png_structp png_ptr));
  162240. #if defined(PNG_WRITE_gAMA_SUPPORTED)
  162241. #ifdef PNG_FLOATING_POINT_SUPPORTED
  162242. PNG_EXTERN void png_write_gAMA PNGARG((png_structp png_ptr, double file_gamma));
  162243. #endif
  162244. #ifdef PNG_FIXED_POINT_SUPPORTED
  162245. PNG_EXTERN void png_write_gAMA_fixed PNGARG((png_structp png_ptr, png_fixed_point
  162246. file_gamma));
  162247. #endif
  162248. #endif
  162249. #if defined(PNG_WRITE_sBIT_SUPPORTED)
  162250. PNG_EXTERN void png_write_sBIT PNGARG((png_structp png_ptr, png_color_8p sbit,
  162251. int color_type));
  162252. #endif
  162253. #if defined(PNG_WRITE_cHRM_SUPPORTED)
  162254. #ifdef PNG_FLOATING_POINT_SUPPORTED
  162255. PNG_EXTERN void png_write_cHRM PNGARG((png_structp png_ptr,
  162256. double white_x, double white_y,
  162257. double red_x, double red_y, double green_x, double green_y,
  162258. double blue_x, double blue_y));
  162259. #endif
  162260. #ifdef PNG_FIXED_POINT_SUPPORTED
  162261. PNG_EXTERN void png_write_cHRM_fixed PNGARG((png_structp png_ptr,
  162262. png_fixed_point int_white_x, png_fixed_point int_white_y,
  162263. png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point
  162264. int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x,
  162265. png_fixed_point int_blue_y));
  162266. #endif
  162267. #endif
  162268. #if defined(PNG_WRITE_sRGB_SUPPORTED)
  162269. PNG_EXTERN void png_write_sRGB PNGARG((png_structp png_ptr,
  162270. int intent));
  162271. #endif
  162272. #if defined(PNG_WRITE_iCCP_SUPPORTED)
  162273. PNG_EXTERN void png_write_iCCP PNGARG((png_structp png_ptr,
  162274. png_charp name, int compression_type,
  162275. png_charp profile, int proflen));
  162276. #endif
  162277. #if defined(PNG_WRITE_sPLT_SUPPORTED)
  162278. PNG_EXTERN void png_write_sPLT PNGARG((png_structp png_ptr,
  162279. png_sPLT_tp palette));
  162280. #endif
  162281. #if defined(PNG_WRITE_tRNS_SUPPORTED)
  162282. PNG_EXTERN void png_write_tRNS PNGARG((png_structp png_ptr, png_bytep trans,
  162283. png_color_16p values, int number, int color_type));
  162284. #endif
  162285. #if defined(PNG_WRITE_bKGD_SUPPORTED)
  162286. PNG_EXTERN void png_write_bKGD PNGARG((png_structp png_ptr,
  162287. png_color_16p values, int color_type));
  162288. #endif
  162289. #if defined(PNG_WRITE_hIST_SUPPORTED)
  162290. PNG_EXTERN void png_write_hIST PNGARG((png_structp png_ptr, png_uint_16p hist,
  162291. int num_hist));
  162292. #endif
  162293. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \
  162294. defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  162295. PNG_EXTERN png_size_t png_check_keyword PNGARG((png_structp png_ptr,
  162296. png_charp key, png_charpp new_key));
  162297. #endif
  162298. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  162299. PNG_EXTERN void png_write_tEXt PNGARG((png_structp png_ptr, png_charp key,
  162300. png_charp text, png_size_t text_len));
  162301. #endif
  162302. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  162303. PNG_EXTERN void png_write_zTXt PNGARG((png_structp png_ptr, png_charp key,
  162304. png_charp text, png_size_t text_len, int compression));
  162305. #endif
  162306. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  162307. PNG_EXTERN void png_write_iTXt PNGARG((png_structp png_ptr,
  162308. int compression, png_charp key, png_charp lang, png_charp lang_key,
  162309. png_charp text));
  162310. #endif
  162311. #if defined(PNG_TEXT_SUPPORTED) /* Added at version 1.0.14 and 1.2.4 */
  162312. PNG_EXTERN int png_set_text_2 PNGARG((png_structp png_ptr,
  162313. png_infop info_ptr, png_textp text_ptr, int num_text));
  162314. #endif
  162315. #if defined(PNG_WRITE_oFFs_SUPPORTED)
  162316. PNG_EXTERN void png_write_oFFs PNGARG((png_structp png_ptr,
  162317. png_int_32 x_offset, png_int_32 y_offset, int unit_type));
  162318. #endif
  162319. #if defined(PNG_WRITE_pCAL_SUPPORTED)
  162320. PNG_EXTERN void png_write_pCAL PNGARG((png_structp png_ptr, png_charp purpose,
  162321. png_int_32 X0, png_int_32 X1, int type, int nparams,
  162322. png_charp units, png_charpp params));
  162323. #endif
  162324. #if defined(PNG_WRITE_pHYs_SUPPORTED)
  162325. PNG_EXTERN void png_write_pHYs PNGARG((png_structp png_ptr,
  162326. png_uint_32 x_pixels_per_unit, png_uint_32 y_pixels_per_unit,
  162327. int unit_type));
  162328. #endif
  162329. #if defined(PNG_WRITE_tIME_SUPPORTED)
  162330. PNG_EXTERN void png_write_tIME PNGARG((png_structp png_ptr,
  162331. png_timep mod_time));
  162332. #endif
  162333. #if defined(PNG_WRITE_sCAL_SUPPORTED)
  162334. #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
  162335. PNG_EXTERN void png_write_sCAL PNGARG((png_structp png_ptr,
  162336. int unit, double width, double height));
  162337. #else
  162338. #ifdef PNG_FIXED_POINT_SUPPORTED
  162339. PNG_EXTERN void png_write_sCAL_s PNGARG((png_structp png_ptr,
  162340. int unit, png_charp width, png_charp height));
  162341. #endif
  162342. #endif
  162343. #endif
  162344. PNG_EXTERN void png_write_finish_row PNGARG((png_structp png_ptr));
  162345. PNG_EXTERN void png_write_start_row PNGARG((png_structp png_ptr));
  162346. #if defined(PNG_READ_GAMMA_SUPPORTED)
  162347. PNG_EXTERN void png_build_gamma_table PNGARG((png_structp png_ptr));
  162348. #endif
  162349. PNG_EXTERN void png_combine_row PNGARG((png_structp png_ptr, png_bytep row,
  162350. int mask));
  162351. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  162352. PNG_EXTERN void png_do_read_interlace PNGARG((png_structp png_ptr));
  162353. #endif
  162354. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  162355. PNG_EXTERN void png_do_write_interlace PNGARG((png_row_infop row_info,
  162356. png_bytep row, int pass));
  162357. #endif
  162358. PNG_EXTERN void png_read_filter_row PNGARG((png_structp png_ptr,
  162359. png_row_infop row_info, png_bytep row, png_bytep prev_row, int filter));
  162360. PNG_EXTERN void png_write_find_filter PNGARG((png_structp png_ptr,
  162361. png_row_infop row_info));
  162362. PNG_EXTERN void png_write_filtered_row PNGARG((png_structp png_ptr,
  162363. png_bytep filtered_row));
  162364. PNG_EXTERN void png_read_finish_row PNGARG((png_structp png_ptr));
  162365. PNG_EXTERN void png_read_start_row PNGARG((png_structp png_ptr));
  162366. PNG_EXTERN void png_read_transform_info PNGARG((png_structp png_ptr,
  162367. png_infop info_ptr));
  162368. #if defined(PNG_READ_FILLER_SUPPORTED)
  162369. PNG_EXTERN void png_do_read_filler PNGARG((png_row_infop row_info,
  162370. png_bytep row, png_uint_32 filler, png_uint_32 flags));
  162371. #endif
  162372. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  162373. PNG_EXTERN void png_do_read_swap_alpha PNGARG((png_row_infop row_info,
  162374. png_bytep row));
  162375. #endif
  162376. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  162377. PNG_EXTERN void png_do_write_swap_alpha PNGARG((png_row_infop row_info,
  162378. png_bytep row));
  162379. #endif
  162380. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  162381. PNG_EXTERN void png_do_read_invert_alpha PNGARG((png_row_infop row_info,
  162382. png_bytep row));
  162383. #endif
  162384. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  162385. PNG_EXTERN void png_do_write_invert_alpha PNGARG((png_row_infop row_info,
  162386. png_bytep row));
  162387. #endif
  162388. #if defined(PNG_WRITE_FILLER_SUPPORTED) || \
  162389. defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  162390. PNG_EXTERN void png_do_strip_filler PNGARG((png_row_infop row_info,
  162391. png_bytep row, png_uint_32 flags));
  162392. #endif
  162393. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  162394. PNG_EXTERN void png_do_swap PNGARG((png_row_infop row_info, png_bytep row));
  162395. #endif
  162396. #if defined(PNG_READ_PACKSWAP_SUPPORTED) || defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  162397. PNG_EXTERN void png_do_packswap PNGARG((png_row_infop row_info, png_bytep row));
  162398. #endif
  162399. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  162400. PNG_EXTERN int png_do_rgb_to_gray PNGARG((png_structp png_ptr, png_row_infop
  162401. row_info, png_bytep row));
  162402. #endif
  162403. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  162404. PNG_EXTERN void png_do_gray_to_rgb PNGARG((png_row_infop row_info,
  162405. png_bytep row));
  162406. #endif
  162407. #if defined(PNG_READ_PACK_SUPPORTED)
  162408. PNG_EXTERN void png_do_unpack PNGARG((png_row_infop row_info, png_bytep row));
  162409. #endif
  162410. #if defined(PNG_READ_SHIFT_SUPPORTED)
  162411. PNG_EXTERN void png_do_unshift PNGARG((png_row_infop row_info, png_bytep row,
  162412. png_color_8p sig_bits));
  162413. #endif
  162414. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  162415. PNG_EXTERN void png_do_invert PNGARG((png_row_infop row_info, png_bytep row));
  162416. #endif
  162417. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  162418. PNG_EXTERN void png_do_chop PNGARG((png_row_infop row_info, png_bytep row));
  162419. #endif
  162420. #if defined(PNG_READ_DITHER_SUPPORTED)
  162421. PNG_EXTERN void png_do_dither PNGARG((png_row_infop row_info,
  162422. png_bytep row, png_bytep palette_lookup, png_bytep dither_lookup));
  162423. # if defined(PNG_CORRECT_PALETTE_SUPPORTED)
  162424. PNG_EXTERN void png_correct_palette PNGARG((png_structp png_ptr,
  162425. png_colorp palette, int num_palette));
  162426. # endif
  162427. #endif
  162428. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  162429. PNG_EXTERN void png_do_bgr PNGARG((png_row_infop row_info, png_bytep row));
  162430. #endif
  162431. #if defined(PNG_WRITE_PACK_SUPPORTED)
  162432. PNG_EXTERN void png_do_pack PNGARG((png_row_infop row_info,
  162433. png_bytep row, png_uint_32 bit_depth));
  162434. #endif
  162435. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  162436. PNG_EXTERN void png_do_shift PNGARG((png_row_infop row_info, png_bytep row,
  162437. png_color_8p bit_depth));
  162438. #endif
  162439. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  162440. #if defined(PNG_READ_GAMMA_SUPPORTED)
  162441. PNG_EXTERN void png_do_background PNGARG((png_row_infop row_info, png_bytep row,
  162442. png_color_16p trans_values, png_color_16p background,
  162443. png_color_16p background_1,
  162444. png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1,
  162445. png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1,
  162446. png_uint_16pp gamma_16_to_1, int gamma_shift));
  162447. #else
  162448. PNG_EXTERN void png_do_background PNGARG((png_row_infop row_info, png_bytep row,
  162449. png_color_16p trans_values, png_color_16p background));
  162450. #endif
  162451. #endif
  162452. #if defined(PNG_READ_GAMMA_SUPPORTED)
  162453. PNG_EXTERN void png_do_gamma PNGARG((png_row_infop row_info, png_bytep row,
  162454. png_bytep gamma_table, png_uint_16pp gamma_16_table,
  162455. int gamma_shift));
  162456. #endif
  162457. #if defined(PNG_READ_EXPAND_SUPPORTED)
  162458. PNG_EXTERN void png_do_expand_palette PNGARG((png_row_infop row_info,
  162459. png_bytep row, png_colorp palette, png_bytep trans, int num_trans));
  162460. PNG_EXTERN void png_do_expand PNGARG((png_row_infop row_info,
  162461. png_bytep row, png_color_16p trans_value));
  162462. #endif
  162463. PNG_EXTERN void png_handle_IHDR PNGARG((png_structp png_ptr, png_infop info_ptr,
  162464. png_uint_32 length));
  162465. PNG_EXTERN void png_handle_PLTE PNGARG((png_structp png_ptr, png_infop info_ptr,
  162466. png_uint_32 length));
  162467. PNG_EXTERN void png_handle_IEND PNGARG((png_structp png_ptr, png_infop info_ptr,
  162468. png_uint_32 length));
  162469. #if defined(PNG_READ_bKGD_SUPPORTED)
  162470. PNG_EXTERN void png_handle_bKGD PNGARG((png_structp png_ptr, png_infop info_ptr,
  162471. png_uint_32 length));
  162472. #endif
  162473. #if defined(PNG_READ_cHRM_SUPPORTED)
  162474. PNG_EXTERN void png_handle_cHRM PNGARG((png_structp png_ptr, png_infop info_ptr,
  162475. png_uint_32 length));
  162476. #endif
  162477. #if defined(PNG_READ_gAMA_SUPPORTED)
  162478. PNG_EXTERN void png_handle_gAMA PNGARG((png_structp png_ptr, png_infop info_ptr,
  162479. png_uint_32 length));
  162480. #endif
  162481. #if defined(PNG_READ_hIST_SUPPORTED)
  162482. PNG_EXTERN void png_handle_hIST PNGARG((png_structp png_ptr, png_infop info_ptr,
  162483. png_uint_32 length));
  162484. #endif
  162485. #if defined(PNG_READ_iCCP_SUPPORTED)
  162486. extern void png_handle_iCCP PNGARG((png_structp png_ptr, png_infop info_ptr,
  162487. png_uint_32 length));
  162488. #endif /* PNG_READ_iCCP_SUPPORTED */
  162489. #if defined(PNG_READ_iTXt_SUPPORTED)
  162490. PNG_EXTERN void png_handle_iTXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  162491. png_uint_32 length));
  162492. #endif
  162493. #if defined(PNG_READ_oFFs_SUPPORTED)
  162494. PNG_EXTERN void png_handle_oFFs PNGARG((png_structp png_ptr, png_infop info_ptr,
  162495. png_uint_32 length));
  162496. #endif
  162497. #if defined(PNG_READ_pCAL_SUPPORTED)
  162498. PNG_EXTERN void png_handle_pCAL PNGARG((png_structp png_ptr, png_infop info_ptr,
  162499. png_uint_32 length));
  162500. #endif
  162501. #if defined(PNG_READ_pHYs_SUPPORTED)
  162502. PNG_EXTERN void png_handle_pHYs PNGARG((png_structp png_ptr, png_infop info_ptr,
  162503. png_uint_32 length));
  162504. #endif
  162505. #if defined(PNG_READ_sBIT_SUPPORTED)
  162506. PNG_EXTERN void png_handle_sBIT PNGARG((png_structp png_ptr, png_infop info_ptr,
  162507. png_uint_32 length));
  162508. #endif
  162509. #if defined(PNG_READ_sCAL_SUPPORTED)
  162510. PNG_EXTERN void png_handle_sCAL PNGARG((png_structp png_ptr, png_infop info_ptr,
  162511. png_uint_32 length));
  162512. #endif
  162513. #if defined(PNG_READ_sPLT_SUPPORTED)
  162514. extern void png_handle_sPLT PNGARG((png_structp png_ptr, png_infop info_ptr,
  162515. png_uint_32 length));
  162516. #endif /* PNG_READ_sPLT_SUPPORTED */
  162517. #if defined(PNG_READ_sRGB_SUPPORTED)
  162518. PNG_EXTERN void png_handle_sRGB PNGARG((png_structp png_ptr, png_infop info_ptr,
  162519. png_uint_32 length));
  162520. #endif
  162521. #if defined(PNG_READ_tEXt_SUPPORTED)
  162522. PNG_EXTERN void png_handle_tEXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  162523. png_uint_32 length));
  162524. #endif
  162525. #if defined(PNG_READ_tIME_SUPPORTED)
  162526. PNG_EXTERN void png_handle_tIME PNGARG((png_structp png_ptr, png_infop info_ptr,
  162527. png_uint_32 length));
  162528. #endif
  162529. #if defined(PNG_READ_tRNS_SUPPORTED)
  162530. PNG_EXTERN void png_handle_tRNS PNGARG((png_structp png_ptr, png_infop info_ptr,
  162531. png_uint_32 length));
  162532. #endif
  162533. #if defined(PNG_READ_zTXt_SUPPORTED)
  162534. PNG_EXTERN void png_handle_zTXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  162535. png_uint_32 length));
  162536. #endif
  162537. PNG_EXTERN void png_handle_unknown PNGARG((png_structp png_ptr,
  162538. png_infop info_ptr, png_uint_32 length));
  162539. PNG_EXTERN void png_check_chunk_name PNGARG((png_structp png_ptr,
  162540. png_bytep chunk_name));
  162541. PNG_EXTERN void png_do_read_transformations PNGARG((png_structp png_ptr));
  162542. PNG_EXTERN void png_do_write_transformations PNGARG((png_structp png_ptr));
  162543. PNG_EXTERN void png_init_read_transformations PNGARG((png_structp png_ptr));
  162544. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  162545. PNG_EXTERN void png_push_read_chunk PNGARG((png_structp png_ptr,
  162546. png_infop info_ptr));
  162547. PNG_EXTERN void png_push_read_sig PNGARG((png_structp png_ptr,
  162548. png_infop info_ptr));
  162549. PNG_EXTERN void png_push_check_crc PNGARG((png_structp png_ptr));
  162550. PNG_EXTERN void png_push_crc_skip PNGARG((png_structp png_ptr,
  162551. png_uint_32 length));
  162552. PNG_EXTERN void png_push_crc_finish PNGARG((png_structp png_ptr));
  162553. PNG_EXTERN void png_push_save_buffer PNGARG((png_structp png_ptr));
  162554. PNG_EXTERN void png_push_restore_buffer PNGARG((png_structp png_ptr,
  162555. png_bytep buffer, png_size_t buffer_length));
  162556. PNG_EXTERN void png_push_read_IDAT PNGARG((png_structp png_ptr));
  162557. PNG_EXTERN void png_process_IDAT_data PNGARG((png_structp png_ptr,
  162558. png_bytep buffer, png_size_t buffer_length));
  162559. PNG_EXTERN void png_push_process_row PNGARG((png_structp png_ptr));
  162560. PNG_EXTERN void png_push_handle_unknown PNGARG((png_structp png_ptr,
  162561. png_infop info_ptr, png_uint_32 length));
  162562. PNG_EXTERN void png_push_have_info PNGARG((png_structp png_ptr,
  162563. png_infop info_ptr));
  162564. PNG_EXTERN void png_push_have_end PNGARG((png_structp png_ptr,
  162565. png_infop info_ptr));
  162566. PNG_EXTERN void png_push_have_row PNGARG((png_structp png_ptr, png_bytep row));
  162567. PNG_EXTERN void png_push_read_end PNGARG((png_structp png_ptr,
  162568. png_infop info_ptr));
  162569. PNG_EXTERN void png_process_some_data PNGARG((png_structp png_ptr,
  162570. png_infop info_ptr));
  162571. PNG_EXTERN void png_read_push_finish_row PNGARG((png_structp png_ptr));
  162572. #if defined(PNG_READ_tEXt_SUPPORTED)
  162573. PNG_EXTERN void png_push_handle_tEXt PNGARG((png_structp png_ptr,
  162574. png_infop info_ptr, png_uint_32 length));
  162575. PNG_EXTERN void png_push_read_tEXt PNGARG((png_structp png_ptr,
  162576. png_infop info_ptr));
  162577. #endif
  162578. #if defined(PNG_READ_zTXt_SUPPORTED)
  162579. PNG_EXTERN void png_push_handle_zTXt PNGARG((png_structp png_ptr,
  162580. png_infop info_ptr, png_uint_32 length));
  162581. PNG_EXTERN void png_push_read_zTXt PNGARG((png_structp png_ptr,
  162582. png_infop info_ptr));
  162583. #endif
  162584. #if defined(PNG_READ_iTXt_SUPPORTED)
  162585. PNG_EXTERN void png_push_handle_iTXt PNGARG((png_structp png_ptr,
  162586. png_infop info_ptr, png_uint_32 length));
  162587. PNG_EXTERN void png_push_read_iTXt PNGARG((png_structp png_ptr,
  162588. png_infop info_ptr));
  162589. #endif
  162590. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  162591. #ifdef PNG_MNG_FEATURES_SUPPORTED
  162592. PNG_EXTERN void png_do_read_intrapixel PNGARG((png_row_infop row_info,
  162593. png_bytep row));
  162594. PNG_EXTERN void png_do_write_intrapixel PNGARG((png_row_infop row_info,
  162595. png_bytep row));
  162596. #endif
  162597. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  162598. #if defined(PNG_MMX_CODE_SUPPORTED)
  162599. /* PRIVATE */
  162600. PNG_EXTERN void png_init_mmx_flags PNGARG((png_structp png_ptr));
  162601. #endif
  162602. #endif
  162603. #if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED)
  162604. PNG_EXTERN png_uint_32 png_get_pixels_per_inch PNGARG((png_structp png_ptr,
  162605. png_infop info_ptr));
  162606. PNG_EXTERN png_uint_32 png_get_x_pixels_per_inch PNGARG((png_structp png_ptr,
  162607. png_infop info_ptr));
  162608. PNG_EXTERN png_uint_32 png_get_y_pixels_per_inch PNGARG((png_structp png_ptr,
  162609. png_infop info_ptr));
  162610. PNG_EXTERN float png_get_x_offset_inches PNGARG((png_structp png_ptr,
  162611. png_infop info_ptr));
  162612. PNG_EXTERN float png_get_y_offset_inches PNGARG((png_structp png_ptr,
  162613. png_infop info_ptr));
  162614. #if defined(PNG_pHYs_SUPPORTED)
  162615. PNG_EXTERN png_uint_32 png_get_pHYs_dpi PNGARG((png_structp png_ptr,
  162616. png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type));
  162617. #endif /* PNG_pHYs_SUPPORTED */
  162618. #endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */
  162619. #endif /* PNG_INTERNAL */
  162620. #ifdef __cplusplus
  162621. }
  162622. #endif
  162623. #endif /* PNG_VERSION_INFO_ONLY */
  162624. #endif /* PNG_H */
  162625. /*** End of inlined file: png.h ***/
  162626. #define PNG_NO_EXTERN
  162627. /*** Start of inlined file: png.c ***/
  162628. #define PNG_INTERNAL
  162629. #define PNG_NO_EXTERN
  162630. typedef version_1_2_21 Your_png_h_is_not_version_1_2_21;
  162631. #ifdef PNG_USE_GLOBAL_ARRAYS
  162632. PNG_CONST char png_libpng_ver[18] = PNG_LIBPNG_VER_STRING;
  162633. #ifdef PNG_READ_SUPPORTED
  162634. PNG_CONST png_byte FARDATA png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  162635. #endif /* PNG_READ_SUPPORTED */
  162636. PNG_IHDR;
  162637. PNG_IDAT;
  162638. PNG_IEND;
  162639. PNG_PLTE;
  162640. PNG_bKGD;
  162641. PNG_cHRM;
  162642. PNG_gAMA;
  162643. PNG_hIST;
  162644. PNG_iCCP;
  162645. PNG_iTXt;
  162646. PNG_oFFs;
  162647. PNG_pCAL;
  162648. PNG_sCAL;
  162649. PNG_pHYs;
  162650. PNG_sBIT;
  162651. PNG_sPLT;
  162652. PNG_sRGB;
  162653. PNG_tEXt;
  162654. PNG_tIME;
  162655. PNG_tRNS;
  162656. PNG_zTXt;
  162657. #ifdef PNG_READ_SUPPORTED
  162658. PNG_CONST int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
  162659. PNG_CONST int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
  162660. PNG_CONST int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
  162661. PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
  162662. PNG_CONST int FARDATA png_pass_mask[] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
  162663. PNG_CONST int FARDATA png_pass_dsp_mask[]
  162664. = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
  162665. #endif /* PNG_READ_SUPPORTED */
  162666. #endif /* PNG_USE_GLOBAL_ARRAYS */
  162667. #ifdef PNG_READ_SUPPORTED
  162668. void PNGAPI
  162669. png_set_sig_bytes(png_structp png_ptr, int num_bytes)
  162670. {
  162671. if(png_ptr == NULL) return;
  162672. png_debug(1, "in png_set_sig_bytes\n");
  162673. if (num_bytes > 8)
  162674. png_error(png_ptr, "Too many bytes for PNG signature.");
  162675. png_ptr->sig_bytes = (png_byte)(num_bytes < 0 ? 0 : num_bytes);
  162676. }
  162677. int PNGAPI
  162678. png_sig_cmp(png_bytep sig, png_size_t start, png_size_t num_to_check)
  162679. {
  162680. png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  162681. if (num_to_check > 8)
  162682. num_to_check = 8;
  162683. else if (num_to_check < 1)
  162684. return (-1);
  162685. if (start > 7)
  162686. return (-1);
  162687. if (start + num_to_check > 8)
  162688. num_to_check = 8 - start;
  162689. return ((int)(png_memcmp(&sig[start], &png_signature[start], num_to_check)));
  162690. }
  162691. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  162692. int PNGAPI
  162693. png_check_sig(png_bytep sig, int num)
  162694. {
  162695. return ((int)!png_sig_cmp(sig, (png_size_t)0, (png_size_t)num));
  162696. }
  162697. #endif
  162698. #endif /* PNG_READ_SUPPORTED */
  162699. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162700. #ifdef PNG_1_0_X
  162701. voidpf PNGAPI
  162702. #else
  162703. voidpf /* private */
  162704. #endif
  162705. png_zalloc(voidpf png_ptr, uInt items, uInt size)
  162706. {
  162707. png_voidp ptr;
  162708. png_structp p=(png_structp)png_ptr;
  162709. png_uint_32 save_flags=p->flags;
  162710. png_uint_32 num_bytes;
  162711. if(png_ptr == NULL) return (NULL);
  162712. if (items > PNG_UINT_32_MAX/size)
  162713. {
  162714. png_warning (p, "Potential overflow in png_zalloc()");
  162715. return (NULL);
  162716. }
  162717. num_bytes = (png_uint_32)items * size;
  162718. p->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
  162719. ptr = (png_voidp)png_malloc((png_structp)png_ptr, num_bytes);
  162720. p->flags=save_flags;
  162721. #if defined(PNG_1_0_X) && !defined(PNG_NO_ZALLOC_ZERO)
  162722. if (ptr == NULL)
  162723. return ((voidpf)ptr);
  162724. if (num_bytes > (png_uint_32)0x8000L)
  162725. {
  162726. png_memset(ptr, 0, (png_size_t)0x8000L);
  162727. png_memset((png_bytep)ptr + (png_size_t)0x8000L, 0,
  162728. (png_size_t)(num_bytes - (png_uint_32)0x8000L));
  162729. }
  162730. else
  162731. {
  162732. png_memset(ptr, 0, (png_size_t)num_bytes);
  162733. }
  162734. #endif
  162735. return ((voidpf)ptr);
  162736. }
  162737. #ifdef PNG_1_0_X
  162738. void PNGAPI
  162739. #else
  162740. void /* private */
  162741. #endif
  162742. png_zfree(voidpf png_ptr, voidpf ptr)
  162743. {
  162744. png_free((png_structp)png_ptr, (png_voidp)ptr);
  162745. }
  162746. void /* PRIVATE */
  162747. png_reset_crc(png_structp png_ptr)
  162748. {
  162749. png_ptr->crc = crc32(0, Z_NULL, 0);
  162750. }
  162751. void /* PRIVATE */
  162752. png_calculate_crc(png_structp png_ptr, png_bytep ptr, png_size_t length)
  162753. {
  162754. int need_crc = 1;
  162755. if (png_ptr->chunk_name[0] & 0x20) /* ancillary */
  162756. {
  162757. if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
  162758. (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
  162759. need_crc = 0;
  162760. }
  162761. else /* critical */
  162762. {
  162763. if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE)
  162764. need_crc = 0;
  162765. }
  162766. if (need_crc)
  162767. png_ptr->crc = crc32(png_ptr->crc, ptr, (uInt)length);
  162768. }
  162769. png_infop PNGAPI
  162770. png_create_info_struct(png_structp png_ptr)
  162771. {
  162772. png_infop info_ptr;
  162773. png_debug(1, "in png_create_info_struct\n");
  162774. if(png_ptr == NULL) return (NULL);
  162775. #ifdef PNG_USER_MEM_SUPPORTED
  162776. info_ptr = (png_infop)png_create_struct_2(PNG_STRUCT_INFO,
  162777. png_ptr->malloc_fn, png_ptr->mem_ptr);
  162778. #else
  162779. info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
  162780. #endif
  162781. if (info_ptr != NULL)
  162782. png_info_init_3(&info_ptr, png_sizeof(png_info));
  162783. return (info_ptr);
  162784. }
  162785. void PNGAPI
  162786. png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr)
  162787. {
  162788. png_infop info_ptr = NULL;
  162789. if(png_ptr == NULL) return;
  162790. png_debug(1, "in png_destroy_info_struct\n");
  162791. if (info_ptr_ptr != NULL)
  162792. info_ptr = *info_ptr_ptr;
  162793. if (info_ptr != NULL)
  162794. {
  162795. png_info_destroy(png_ptr, info_ptr);
  162796. #ifdef PNG_USER_MEM_SUPPORTED
  162797. png_destroy_struct_2((png_voidp)info_ptr, png_ptr->free_fn,
  162798. png_ptr->mem_ptr);
  162799. #else
  162800. png_destroy_struct((png_voidp)info_ptr);
  162801. #endif
  162802. *info_ptr_ptr = NULL;
  162803. }
  162804. }
  162805. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  162806. #undef png_info_init
  162807. void PNGAPI
  162808. png_info_init(png_infop info_ptr)
  162809. {
  162810. png_info_init_3(&info_ptr, 0);
  162811. }
  162812. #endif
  162813. void PNGAPI
  162814. png_info_init_3(png_infopp ptr_ptr, png_size_t png_info_struct_size)
  162815. {
  162816. png_infop info_ptr = *ptr_ptr;
  162817. if(info_ptr == NULL) return;
  162818. png_debug(1, "in png_info_init_3\n");
  162819. if(png_sizeof(png_info) > png_info_struct_size)
  162820. {
  162821. png_destroy_struct(info_ptr);
  162822. info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
  162823. *ptr_ptr = info_ptr;
  162824. }
  162825. png_memset(info_ptr, 0, png_sizeof (png_info));
  162826. }
  162827. #ifdef PNG_FREE_ME_SUPPORTED
  162828. void PNGAPI
  162829. png_data_freer(png_structp png_ptr, png_infop info_ptr,
  162830. int freer, png_uint_32 mask)
  162831. {
  162832. png_debug(1, "in png_data_freer\n");
  162833. if (png_ptr == NULL || info_ptr == NULL)
  162834. return;
  162835. if(freer == PNG_DESTROY_WILL_FREE_DATA)
  162836. info_ptr->free_me |= mask;
  162837. else if(freer == PNG_USER_WILL_FREE_DATA)
  162838. info_ptr->free_me &= ~mask;
  162839. else
  162840. png_warning(png_ptr,
  162841. "Unknown freer parameter in png_data_freer.");
  162842. }
  162843. #endif
  162844. void PNGAPI
  162845. png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask,
  162846. int num)
  162847. {
  162848. png_debug(1, "in png_free_data\n");
  162849. if (png_ptr == NULL || info_ptr == NULL)
  162850. return;
  162851. #if defined(PNG_TEXT_SUPPORTED)
  162852. #ifdef PNG_FREE_ME_SUPPORTED
  162853. if ((mask & PNG_FREE_TEXT) & info_ptr->free_me)
  162854. #else
  162855. if (mask & PNG_FREE_TEXT)
  162856. #endif
  162857. {
  162858. if (num != -1)
  162859. {
  162860. if (info_ptr->text && info_ptr->text[num].key)
  162861. {
  162862. png_free(png_ptr, info_ptr->text[num].key);
  162863. info_ptr->text[num].key = NULL;
  162864. }
  162865. }
  162866. else
  162867. {
  162868. int i;
  162869. for (i = 0; i < info_ptr->num_text; i++)
  162870. png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, i);
  162871. png_free(png_ptr, info_ptr->text);
  162872. info_ptr->text = NULL;
  162873. info_ptr->num_text=0;
  162874. }
  162875. }
  162876. #endif
  162877. #if defined(PNG_tRNS_SUPPORTED)
  162878. #ifdef PNG_FREE_ME_SUPPORTED
  162879. if ((mask & PNG_FREE_TRNS) & info_ptr->free_me)
  162880. #else
  162881. if ((mask & PNG_FREE_TRNS) && (png_ptr->flags & PNG_FLAG_FREE_TRNS))
  162882. #endif
  162883. {
  162884. png_free(png_ptr, info_ptr->trans);
  162885. info_ptr->valid &= ~PNG_INFO_tRNS;
  162886. #ifndef PNG_FREE_ME_SUPPORTED
  162887. png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
  162888. #endif
  162889. info_ptr->trans = NULL;
  162890. }
  162891. #endif
  162892. #if defined(PNG_sCAL_SUPPORTED)
  162893. #ifdef PNG_FREE_ME_SUPPORTED
  162894. if ((mask & PNG_FREE_SCAL) & info_ptr->free_me)
  162895. #else
  162896. if (mask & PNG_FREE_SCAL)
  162897. #endif
  162898. {
  162899. #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
  162900. png_free(png_ptr, info_ptr->scal_s_width);
  162901. png_free(png_ptr, info_ptr->scal_s_height);
  162902. info_ptr->scal_s_width = NULL;
  162903. info_ptr->scal_s_height = NULL;
  162904. #endif
  162905. info_ptr->valid &= ~PNG_INFO_sCAL;
  162906. }
  162907. #endif
  162908. #if defined(PNG_pCAL_SUPPORTED)
  162909. #ifdef PNG_FREE_ME_SUPPORTED
  162910. if ((mask & PNG_FREE_PCAL) & info_ptr->free_me)
  162911. #else
  162912. if (mask & PNG_FREE_PCAL)
  162913. #endif
  162914. {
  162915. png_free(png_ptr, info_ptr->pcal_purpose);
  162916. png_free(png_ptr, info_ptr->pcal_units);
  162917. info_ptr->pcal_purpose = NULL;
  162918. info_ptr->pcal_units = NULL;
  162919. if (info_ptr->pcal_params != NULL)
  162920. {
  162921. int i;
  162922. for (i = 0; i < (int)info_ptr->pcal_nparams; i++)
  162923. {
  162924. png_free(png_ptr, info_ptr->pcal_params[i]);
  162925. info_ptr->pcal_params[i]=NULL;
  162926. }
  162927. png_free(png_ptr, info_ptr->pcal_params);
  162928. info_ptr->pcal_params = NULL;
  162929. }
  162930. info_ptr->valid &= ~PNG_INFO_pCAL;
  162931. }
  162932. #endif
  162933. #if defined(PNG_iCCP_SUPPORTED)
  162934. #ifdef PNG_FREE_ME_SUPPORTED
  162935. if ((mask & PNG_FREE_ICCP) & info_ptr->free_me)
  162936. #else
  162937. if (mask & PNG_FREE_ICCP)
  162938. #endif
  162939. {
  162940. png_free(png_ptr, info_ptr->iccp_name);
  162941. png_free(png_ptr, info_ptr->iccp_profile);
  162942. info_ptr->iccp_name = NULL;
  162943. info_ptr->iccp_profile = NULL;
  162944. info_ptr->valid &= ~PNG_INFO_iCCP;
  162945. }
  162946. #endif
  162947. #if defined(PNG_sPLT_SUPPORTED)
  162948. #ifdef PNG_FREE_ME_SUPPORTED
  162949. if ((mask & PNG_FREE_SPLT) & info_ptr->free_me)
  162950. #else
  162951. if (mask & PNG_FREE_SPLT)
  162952. #endif
  162953. {
  162954. if (num != -1)
  162955. {
  162956. if(info_ptr->splt_palettes)
  162957. {
  162958. png_free(png_ptr, info_ptr->splt_palettes[num].name);
  162959. png_free(png_ptr, info_ptr->splt_palettes[num].entries);
  162960. info_ptr->splt_palettes[num].name = NULL;
  162961. info_ptr->splt_palettes[num].entries = NULL;
  162962. }
  162963. }
  162964. else
  162965. {
  162966. if(info_ptr->splt_palettes_num)
  162967. {
  162968. int i;
  162969. for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
  162970. png_free_data(png_ptr, info_ptr, PNG_FREE_SPLT, i);
  162971. png_free(png_ptr, info_ptr->splt_palettes);
  162972. info_ptr->splt_palettes = NULL;
  162973. info_ptr->splt_palettes_num = 0;
  162974. }
  162975. info_ptr->valid &= ~PNG_INFO_sPLT;
  162976. }
  162977. }
  162978. #endif
  162979. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  162980. if(png_ptr->unknown_chunk.data)
  162981. {
  162982. png_free(png_ptr, png_ptr->unknown_chunk.data);
  162983. png_ptr->unknown_chunk.data = NULL;
  162984. }
  162985. #ifdef PNG_FREE_ME_SUPPORTED
  162986. if ((mask & PNG_FREE_UNKN) & info_ptr->free_me)
  162987. #else
  162988. if (mask & PNG_FREE_UNKN)
  162989. #endif
  162990. {
  162991. if (num != -1)
  162992. {
  162993. if(info_ptr->unknown_chunks)
  162994. {
  162995. png_free(png_ptr, info_ptr->unknown_chunks[num].data);
  162996. info_ptr->unknown_chunks[num].data = NULL;
  162997. }
  162998. }
  162999. else
  163000. {
  163001. int i;
  163002. if(info_ptr->unknown_chunks_num)
  163003. {
  163004. for (i = 0; i < (int)info_ptr->unknown_chunks_num; i++)
  163005. png_free_data(png_ptr, info_ptr, PNG_FREE_UNKN, i);
  163006. png_free(png_ptr, info_ptr->unknown_chunks);
  163007. info_ptr->unknown_chunks = NULL;
  163008. info_ptr->unknown_chunks_num = 0;
  163009. }
  163010. }
  163011. }
  163012. #endif
  163013. #if defined(PNG_hIST_SUPPORTED)
  163014. #ifdef PNG_FREE_ME_SUPPORTED
  163015. if ((mask & PNG_FREE_HIST) & info_ptr->free_me)
  163016. #else
  163017. if ((mask & PNG_FREE_HIST) && (png_ptr->flags & PNG_FLAG_FREE_HIST))
  163018. #endif
  163019. {
  163020. png_free(png_ptr, info_ptr->hist);
  163021. info_ptr->hist = NULL;
  163022. info_ptr->valid &= ~PNG_INFO_hIST;
  163023. #ifndef PNG_FREE_ME_SUPPORTED
  163024. png_ptr->flags &= ~PNG_FLAG_FREE_HIST;
  163025. #endif
  163026. }
  163027. #endif
  163028. #ifdef PNG_FREE_ME_SUPPORTED
  163029. if ((mask & PNG_FREE_PLTE) & info_ptr->free_me)
  163030. #else
  163031. if ((mask & PNG_FREE_PLTE) && (png_ptr->flags & PNG_FLAG_FREE_PLTE))
  163032. #endif
  163033. {
  163034. png_zfree(png_ptr, info_ptr->palette);
  163035. info_ptr->palette = NULL;
  163036. info_ptr->valid &= ~PNG_INFO_PLTE;
  163037. #ifndef PNG_FREE_ME_SUPPORTED
  163038. png_ptr->flags &= ~PNG_FLAG_FREE_PLTE;
  163039. #endif
  163040. info_ptr->num_palette = 0;
  163041. }
  163042. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  163043. #ifdef PNG_FREE_ME_SUPPORTED
  163044. if ((mask & PNG_FREE_ROWS) & info_ptr->free_me)
  163045. #else
  163046. if (mask & PNG_FREE_ROWS)
  163047. #endif
  163048. {
  163049. if(info_ptr->row_pointers)
  163050. {
  163051. int row;
  163052. for (row = 0; row < (int)info_ptr->height; row++)
  163053. {
  163054. png_free(png_ptr, info_ptr->row_pointers[row]);
  163055. info_ptr->row_pointers[row]=NULL;
  163056. }
  163057. png_free(png_ptr, info_ptr->row_pointers);
  163058. info_ptr->row_pointers=NULL;
  163059. }
  163060. info_ptr->valid &= ~PNG_INFO_IDAT;
  163061. }
  163062. #endif
  163063. #ifdef PNG_FREE_ME_SUPPORTED
  163064. if(num == -1)
  163065. info_ptr->free_me &= ~mask;
  163066. else
  163067. info_ptr->free_me &= ~(mask & ~PNG_FREE_MUL);
  163068. #endif
  163069. }
  163070. void /* PRIVATE */
  163071. png_info_destroy(png_structp png_ptr, png_infop info_ptr)
  163072. {
  163073. png_debug(1, "in png_info_destroy\n");
  163074. png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
  163075. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  163076. if (png_ptr->num_chunk_list)
  163077. {
  163078. png_free(png_ptr, png_ptr->chunk_list);
  163079. png_ptr->chunk_list=NULL;
  163080. png_ptr->num_chunk_list=0;
  163081. }
  163082. #endif
  163083. png_info_init_3(&info_ptr, png_sizeof(png_info));
  163084. }
  163085. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  163086. png_voidp PNGAPI
  163087. png_get_io_ptr(png_structp png_ptr)
  163088. {
  163089. if(png_ptr == NULL) return (NULL);
  163090. return (png_ptr->io_ptr);
  163091. }
  163092. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  163093. #if !defined(PNG_NO_STDIO)
  163094. void PNGAPI
  163095. png_init_io(png_structp png_ptr, png_FILE_p fp)
  163096. {
  163097. png_debug(1, "in png_init_io\n");
  163098. if(png_ptr == NULL) return;
  163099. png_ptr->io_ptr = (png_voidp)fp;
  163100. }
  163101. #endif
  163102. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  163103. png_charp PNGAPI
  163104. png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime)
  163105. {
  163106. static PNG_CONST char short_months[12][4] =
  163107. {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
  163108. "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
  163109. if(png_ptr == NULL) return (NULL);
  163110. if (png_ptr->time_buffer == NULL)
  163111. {
  163112. png_ptr->time_buffer = (png_charp)png_malloc(png_ptr, (png_uint_32)(29*
  163113. png_sizeof(char)));
  163114. }
  163115. #if defined(_WIN32_WCE)
  163116. {
  163117. wchar_t time_buf[29];
  163118. wsprintf(time_buf, TEXT("%d %S %d %02d:%02d:%02d +0000"),
  163119. ptime->day % 32, short_months[(ptime->month - 1) % 12],
  163120. ptime->year, ptime->hour % 24, ptime->minute % 60,
  163121. ptime->second % 61);
  163122. WideCharToMultiByte(CP_ACP, 0, time_buf, -1, png_ptr->time_buffer, 29,
  163123. NULL, NULL);
  163124. }
  163125. #else
  163126. #ifdef USE_FAR_KEYWORD
  163127. {
  163128. char near_time_buf[29];
  163129. png_snprintf6(near_time_buf,29,"%d %s %d %02d:%02d:%02d +0000",
  163130. ptime->day % 32, short_months[(ptime->month - 1) % 12],
  163131. ptime->year, ptime->hour % 24, ptime->minute % 60,
  163132. ptime->second % 61);
  163133. png_memcpy(png_ptr->time_buffer, near_time_buf,
  163134. 29*png_sizeof(char));
  163135. }
  163136. #else
  163137. png_snprintf6(png_ptr->time_buffer,29,"%d %s %d %02d:%02d:%02d +0000",
  163138. ptime->day % 32, short_months[(ptime->month - 1) % 12],
  163139. ptime->year, ptime->hour % 24, ptime->minute % 60,
  163140. ptime->second % 61);
  163141. #endif
  163142. #endif /* _WIN32_WCE */
  163143. return ((png_charp)png_ptr->time_buffer);
  163144. }
  163145. #endif /* PNG_TIME_RFC1123_SUPPORTED */
  163146. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  163147. png_charp PNGAPI
  163148. png_get_copyright(png_structp png_ptr)
  163149. {
  163150. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  163151. return ((png_charp) "\n libpng version 1.2.21 - October 4, 2007\n\
  163152. Copyright (c) 1998-2007 Glenn Randers-Pehrson\n\
  163153. Copyright (c) 1996-1997 Andreas Dilger\n\
  163154. Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.\n");
  163155. }
  163156. png_charp PNGAPI
  163157. png_get_libpng_ver(png_structp png_ptr)
  163158. {
  163159. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  163160. return ((png_charp) PNG_LIBPNG_VER_STRING);
  163161. }
  163162. png_charp PNGAPI
  163163. png_get_header_ver(png_structp png_ptr)
  163164. {
  163165. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  163166. return ((png_charp) PNG_LIBPNG_VER_STRING);
  163167. }
  163168. png_charp PNGAPI
  163169. png_get_header_version(png_structp png_ptr)
  163170. {
  163171. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  163172. return ((png_charp) PNG_HEADER_VERSION_STRING
  163173. #ifndef PNG_READ_SUPPORTED
  163174. " (NO READ SUPPORT)"
  163175. #endif
  163176. "\n");
  163177. }
  163178. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  163179. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  163180. int PNGAPI
  163181. png_handle_as_unknown(png_structp png_ptr, png_bytep chunk_name)
  163182. {
  163183. int i;
  163184. png_bytep p;
  163185. if(png_ptr == NULL || chunk_name == NULL || png_ptr->num_chunk_list<=0)
  163186. return 0;
  163187. p=png_ptr->chunk_list+png_ptr->num_chunk_list*5-5;
  163188. for (i = png_ptr->num_chunk_list; i; i--, p-=5)
  163189. if (!png_memcmp(chunk_name, p, 4))
  163190. return ((int)*(p+4));
  163191. return 0;
  163192. }
  163193. #endif
  163194. int PNGAPI
  163195. png_reset_zstream(png_structp png_ptr)
  163196. {
  163197. if (png_ptr == NULL) return Z_STREAM_ERROR;
  163198. return (inflateReset(&png_ptr->zstream));
  163199. }
  163200. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  163201. png_uint_32 PNGAPI
  163202. png_access_version_number(void)
  163203. {
  163204. return((png_uint_32) PNG_LIBPNG_VER);
  163205. }
  163206. #if defined(PNG_READ_SUPPORTED) && defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  163207. #if !defined(PNG_1_0_X)
  163208. int PNGAPI
  163209. png_mmx_support(void)
  163210. {
  163211. return -1;
  163212. }
  163213. #endif /* PNG_1_0_X */
  163214. #endif /* PNG_READ_SUPPORTED && PNG_ASSEMBLER_CODE_SUPPORTED */
  163215. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  163216. #ifdef PNG_SIZE_T
  163217. PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size));
  163218. png_size_t PNGAPI
  163219. png_convert_size(size_t size)
  163220. {
  163221. if (size > (png_size_t)-1)
  163222. PNG_ABORT(); /* We haven't got access to png_ptr, so no png_error() */
  163223. return ((png_size_t)size);
  163224. }
  163225. #endif /* PNG_SIZE_T */
  163226. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  163227. /*** End of inlined file: png.c ***/
  163228. /*** Start of inlined file: pngerror.c ***/
  163229. #define PNG_INTERNAL
  163230. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  163231. static void /* PRIVATE */
  163232. png_default_error PNGARG((png_structp png_ptr,
  163233. png_const_charp error_message));
  163234. #ifndef PNG_NO_WARNINGS
  163235. static void /* PRIVATE */
  163236. png_default_warning PNGARG((png_structp png_ptr,
  163237. png_const_charp warning_message));
  163238. #endif /* PNG_NO_WARNINGS */
  163239. #ifndef PNG_NO_ERROR_TEXT
  163240. void PNGAPI
  163241. png_error(png_structp png_ptr, png_const_charp error_message)
  163242. {
  163243. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  163244. char msg[16];
  163245. if (png_ptr != NULL)
  163246. {
  163247. if (png_ptr->flags&
  163248. (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
  163249. {
  163250. if (*error_message == '#')
  163251. {
  163252. int offset;
  163253. for (offset=1; offset<15; offset++)
  163254. if (*(error_message+offset) == ' ')
  163255. break;
  163256. if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
  163257. {
  163258. int i;
  163259. for (i=0; i<offset-1; i++)
  163260. msg[i]=error_message[i+1];
  163261. msg[i]='\0';
  163262. error_message=msg;
  163263. }
  163264. else
  163265. error_message+=offset;
  163266. }
  163267. else
  163268. {
  163269. if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
  163270. {
  163271. msg[0]='0';
  163272. msg[1]='\0';
  163273. error_message=msg;
  163274. }
  163275. }
  163276. }
  163277. }
  163278. #endif
  163279. if (png_ptr != NULL && png_ptr->error_fn != NULL)
  163280. (*(png_ptr->error_fn))(png_ptr, error_message);
  163281. png_default_error(png_ptr, error_message);
  163282. }
  163283. #else
  163284. void PNGAPI
  163285. png_err(png_structp png_ptr)
  163286. {
  163287. if (png_ptr != NULL && png_ptr->error_fn != NULL)
  163288. (*(png_ptr->error_fn))(png_ptr, '\0');
  163289. png_default_error(png_ptr, '\0');
  163290. }
  163291. #endif /* PNG_NO_ERROR_TEXT */
  163292. #ifndef PNG_NO_WARNINGS
  163293. void PNGAPI
  163294. png_warning(png_structp png_ptr, png_const_charp warning_message)
  163295. {
  163296. int offset = 0;
  163297. if (png_ptr != NULL)
  163298. {
  163299. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  163300. if (png_ptr->flags&
  163301. (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
  163302. #endif
  163303. {
  163304. if (*warning_message == '#')
  163305. {
  163306. for (offset=1; offset<15; offset++)
  163307. if (*(warning_message+offset) == ' ')
  163308. break;
  163309. }
  163310. }
  163311. if (png_ptr != NULL && png_ptr->warning_fn != NULL)
  163312. (*(png_ptr->warning_fn))(png_ptr, warning_message+offset);
  163313. }
  163314. else
  163315. png_default_warning(png_ptr, warning_message+offset);
  163316. }
  163317. #endif /* PNG_NO_WARNINGS */
  163318. #define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
  163319. #if !defined(PNG_NO_WARNINGS) || !defined(PNG_NO_ERROR_TEXT)
  163320. static void /* PRIVATE */
  163321. png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp
  163322. error_message)
  163323. {
  163324. int iout = 0, iin = 0;
  163325. while (iin < 4)
  163326. {
  163327. int c = png_ptr->chunk_name[iin++];
  163328. if (isnonalpha(c))
  163329. {
  163330. buffer[iout++] = '[';
  163331. buffer[iout++] = png_digit[(c & 0xf0) >> 4];
  163332. buffer[iout++] = png_digit[c & 0x0f];
  163333. buffer[iout++] = ']';
  163334. }
  163335. else
  163336. {
  163337. buffer[iout++] = (png_byte)c;
  163338. }
  163339. }
  163340. if (error_message == NULL)
  163341. buffer[iout] = 0;
  163342. else
  163343. {
  163344. buffer[iout++] = ':';
  163345. buffer[iout++] = ' ';
  163346. png_strncpy(buffer+iout, error_message, 63);
  163347. buffer[iout+63] = 0;
  163348. }
  163349. }
  163350. #ifdef PNG_READ_SUPPORTED
  163351. void PNGAPI
  163352. png_chunk_error(png_structp png_ptr, png_const_charp error_message)
  163353. {
  163354. char msg[18+64];
  163355. if (png_ptr == NULL)
  163356. png_error(png_ptr, error_message);
  163357. else
  163358. {
  163359. png_format_buffer(png_ptr, msg, error_message);
  163360. png_error(png_ptr, msg);
  163361. }
  163362. }
  163363. #endif /* PNG_READ_SUPPORTED */
  163364. #endif /* !defined(PNG_NO_WARNINGS) || !defined(PNG_NO_ERROR_TEXT) */
  163365. #ifndef PNG_NO_WARNINGS
  163366. void PNGAPI
  163367. png_chunk_warning(png_structp png_ptr, png_const_charp warning_message)
  163368. {
  163369. char msg[18+64];
  163370. if (png_ptr == NULL)
  163371. png_warning(png_ptr, warning_message);
  163372. else
  163373. {
  163374. png_format_buffer(png_ptr, msg, warning_message);
  163375. png_warning(png_ptr, msg);
  163376. }
  163377. }
  163378. #endif /* PNG_NO_WARNINGS */
  163379. static void /* PRIVATE */
  163380. png_default_error(png_structp png_ptr, png_const_charp error_message)
  163381. {
  163382. #ifndef PNG_NO_CONSOLE_IO
  163383. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  163384. if (*error_message == '#')
  163385. {
  163386. int offset;
  163387. char error_number[16];
  163388. for (offset=0; offset<15; offset++)
  163389. {
  163390. error_number[offset] = *(error_message+offset+1);
  163391. if (*(error_message+offset) == ' ')
  163392. break;
  163393. }
  163394. if((offset > 1) && (offset < 15))
  163395. {
  163396. error_number[offset-1]='\0';
  163397. fprintf(stderr, "libpng error no. %s: %s\n", error_number,
  163398. error_message+offset);
  163399. }
  163400. else
  163401. fprintf(stderr, "libpng error: %s, offset=%d\n", error_message,offset);
  163402. }
  163403. else
  163404. #endif
  163405. fprintf(stderr, "libpng error: %s\n", error_message);
  163406. #endif
  163407. #ifdef PNG_SETJMP_SUPPORTED
  163408. if (png_ptr)
  163409. {
  163410. # ifdef USE_FAR_KEYWORD
  163411. {
  163412. jmp_buf jmpbuf;
  163413. png_memcpy(jmpbuf, png_ptr->jmpbuf, png_sizeof(jmp_buf));
  163414. longjmp(jmpbuf, 1);
  163415. }
  163416. # else
  163417. longjmp(png_ptr->jmpbuf, 1);
  163418. # endif
  163419. }
  163420. #else
  163421. PNG_ABORT();
  163422. #endif
  163423. #ifdef PNG_NO_CONSOLE_IO
  163424. error_message = error_message; /* make compiler happy */
  163425. #endif
  163426. }
  163427. #ifndef PNG_NO_WARNINGS
  163428. static void /* PRIVATE */
  163429. png_default_warning(png_structp png_ptr, png_const_charp warning_message)
  163430. {
  163431. #ifndef PNG_NO_CONSOLE_IO
  163432. # ifdef PNG_ERROR_NUMBERS_SUPPORTED
  163433. if (*warning_message == '#')
  163434. {
  163435. int offset;
  163436. char warning_number[16];
  163437. for (offset=0; offset<15; offset++)
  163438. {
  163439. warning_number[offset]=*(warning_message+offset+1);
  163440. if (*(warning_message+offset) == ' ')
  163441. break;
  163442. }
  163443. if((offset > 1) && (offset < 15))
  163444. {
  163445. warning_number[offset-1]='\0';
  163446. fprintf(stderr, "libpng warning no. %s: %s\n", warning_number,
  163447. warning_message+offset);
  163448. }
  163449. else
  163450. fprintf(stderr, "libpng warning: %s\n", warning_message);
  163451. }
  163452. else
  163453. # endif
  163454. fprintf(stderr, "libpng warning: %s\n", warning_message);
  163455. #else
  163456. warning_message = warning_message; /* make compiler happy */
  163457. #endif
  163458. png_ptr = png_ptr; /* make compiler happy */
  163459. }
  163460. #endif /* PNG_NO_WARNINGS */
  163461. void PNGAPI
  163462. png_set_error_fn(png_structp png_ptr, png_voidp error_ptr,
  163463. png_error_ptr error_fn, png_error_ptr warning_fn)
  163464. {
  163465. if (png_ptr == NULL)
  163466. return;
  163467. png_ptr->error_ptr = error_ptr;
  163468. png_ptr->error_fn = error_fn;
  163469. png_ptr->warning_fn = warning_fn;
  163470. }
  163471. png_voidp PNGAPI
  163472. png_get_error_ptr(png_structp png_ptr)
  163473. {
  163474. if (png_ptr == NULL)
  163475. return NULL;
  163476. return ((png_voidp)png_ptr->error_ptr);
  163477. }
  163478. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  163479. void PNGAPI
  163480. png_set_strip_error_numbers(png_structp png_ptr, png_uint_32 strip_mode)
  163481. {
  163482. if(png_ptr != NULL)
  163483. {
  163484. png_ptr->flags &=
  163485. ((~(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))&strip_mode);
  163486. }
  163487. }
  163488. #endif
  163489. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  163490. /*** End of inlined file: pngerror.c ***/
  163491. /*** Start of inlined file: pngget.c ***/
  163492. #define PNG_INTERNAL
  163493. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  163494. png_uint_32 PNGAPI
  163495. png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flag)
  163496. {
  163497. if (png_ptr != NULL && info_ptr != NULL)
  163498. return(info_ptr->valid & flag);
  163499. else
  163500. return(0);
  163501. }
  163502. png_uint_32 PNGAPI
  163503. png_get_rowbytes(png_structp png_ptr, png_infop info_ptr)
  163504. {
  163505. if (png_ptr != NULL && info_ptr != NULL)
  163506. return(info_ptr->rowbytes);
  163507. else
  163508. return(0);
  163509. }
  163510. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  163511. png_bytepp PNGAPI
  163512. png_get_rows(png_structp png_ptr, png_infop info_ptr)
  163513. {
  163514. if (png_ptr != NULL && info_ptr != NULL)
  163515. return(info_ptr->row_pointers);
  163516. else
  163517. return(0);
  163518. }
  163519. #endif
  163520. #ifdef PNG_EASY_ACCESS_SUPPORTED
  163521. png_uint_32 PNGAPI
  163522. png_get_image_width(png_structp png_ptr, png_infop info_ptr)
  163523. {
  163524. if (png_ptr != NULL && info_ptr != NULL)
  163525. {
  163526. return info_ptr->width;
  163527. }
  163528. return (0);
  163529. }
  163530. png_uint_32 PNGAPI
  163531. png_get_image_height(png_structp png_ptr, png_infop info_ptr)
  163532. {
  163533. if (png_ptr != NULL && info_ptr != NULL)
  163534. {
  163535. return info_ptr->height;
  163536. }
  163537. return (0);
  163538. }
  163539. png_byte PNGAPI
  163540. png_get_bit_depth(png_structp png_ptr, png_infop info_ptr)
  163541. {
  163542. if (png_ptr != NULL && info_ptr != NULL)
  163543. {
  163544. return info_ptr->bit_depth;
  163545. }
  163546. return (0);
  163547. }
  163548. png_byte PNGAPI
  163549. png_get_color_type(png_structp png_ptr, png_infop info_ptr)
  163550. {
  163551. if (png_ptr != NULL && info_ptr != NULL)
  163552. {
  163553. return info_ptr->color_type;
  163554. }
  163555. return (0);
  163556. }
  163557. png_byte PNGAPI
  163558. png_get_filter_type(png_structp png_ptr, png_infop info_ptr)
  163559. {
  163560. if (png_ptr != NULL && info_ptr != NULL)
  163561. {
  163562. return info_ptr->filter_type;
  163563. }
  163564. return (0);
  163565. }
  163566. png_byte PNGAPI
  163567. png_get_interlace_type(png_structp png_ptr, png_infop info_ptr)
  163568. {
  163569. if (png_ptr != NULL && info_ptr != NULL)
  163570. {
  163571. return info_ptr->interlace_type;
  163572. }
  163573. return (0);
  163574. }
  163575. png_byte PNGAPI
  163576. png_get_compression_type(png_structp png_ptr, png_infop info_ptr)
  163577. {
  163578. if (png_ptr != NULL && info_ptr != NULL)
  163579. {
  163580. return info_ptr->compression_type;
  163581. }
  163582. return (0);
  163583. }
  163584. png_uint_32 PNGAPI
  163585. png_get_x_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  163586. {
  163587. if (png_ptr != NULL && info_ptr != NULL)
  163588. #if defined(PNG_pHYs_SUPPORTED)
  163589. if (info_ptr->valid & PNG_INFO_pHYs)
  163590. {
  163591. png_debug1(1, "in %s retrieval function\n", "png_get_x_pixels_per_meter");
  163592. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
  163593. return (0);
  163594. else return (info_ptr->x_pixels_per_unit);
  163595. }
  163596. #else
  163597. return (0);
  163598. #endif
  163599. return (0);
  163600. }
  163601. png_uint_32 PNGAPI
  163602. png_get_y_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  163603. {
  163604. if (png_ptr != NULL && info_ptr != NULL)
  163605. #if defined(PNG_pHYs_SUPPORTED)
  163606. if (info_ptr->valid & PNG_INFO_pHYs)
  163607. {
  163608. png_debug1(1, "in %s retrieval function\n", "png_get_y_pixels_per_meter");
  163609. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
  163610. return (0);
  163611. else return (info_ptr->y_pixels_per_unit);
  163612. }
  163613. #else
  163614. return (0);
  163615. #endif
  163616. return (0);
  163617. }
  163618. png_uint_32 PNGAPI
  163619. png_get_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  163620. {
  163621. if (png_ptr != NULL && info_ptr != NULL)
  163622. #if defined(PNG_pHYs_SUPPORTED)
  163623. if (info_ptr->valid & PNG_INFO_pHYs)
  163624. {
  163625. png_debug1(1, "in %s retrieval function\n", "png_get_pixels_per_meter");
  163626. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER ||
  163627. info_ptr->x_pixels_per_unit != info_ptr->y_pixels_per_unit)
  163628. return (0);
  163629. else return (info_ptr->x_pixels_per_unit);
  163630. }
  163631. #else
  163632. return (0);
  163633. #endif
  163634. return (0);
  163635. }
  163636. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163637. float PNGAPI
  163638. png_get_pixel_aspect_ratio(png_structp png_ptr, png_infop info_ptr)
  163639. {
  163640. if (png_ptr != NULL && info_ptr != NULL)
  163641. #if defined(PNG_pHYs_SUPPORTED)
  163642. if (info_ptr->valid & PNG_INFO_pHYs)
  163643. {
  163644. png_debug1(1, "in %s retrieval function\n", "png_get_aspect_ratio");
  163645. if (info_ptr->x_pixels_per_unit == 0)
  163646. return ((float)0.0);
  163647. else
  163648. return ((float)((float)info_ptr->y_pixels_per_unit
  163649. /(float)info_ptr->x_pixels_per_unit));
  163650. }
  163651. #else
  163652. return (0.0);
  163653. #endif
  163654. return ((float)0.0);
  163655. }
  163656. #endif
  163657. png_int_32 PNGAPI
  163658. png_get_x_offset_microns(png_structp png_ptr, png_infop info_ptr)
  163659. {
  163660. if (png_ptr != NULL && info_ptr != NULL)
  163661. #if defined(PNG_oFFs_SUPPORTED)
  163662. if (info_ptr->valid & PNG_INFO_oFFs)
  163663. {
  163664. png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
  163665. if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
  163666. return (0);
  163667. else return (info_ptr->x_offset);
  163668. }
  163669. #else
  163670. return (0);
  163671. #endif
  163672. return (0);
  163673. }
  163674. png_int_32 PNGAPI
  163675. png_get_y_offset_microns(png_structp png_ptr, png_infop info_ptr)
  163676. {
  163677. if (png_ptr != NULL && info_ptr != NULL)
  163678. #if defined(PNG_oFFs_SUPPORTED)
  163679. if (info_ptr->valid & PNG_INFO_oFFs)
  163680. {
  163681. png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
  163682. if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
  163683. return (0);
  163684. else return (info_ptr->y_offset);
  163685. }
  163686. #else
  163687. return (0);
  163688. #endif
  163689. return (0);
  163690. }
  163691. png_int_32 PNGAPI
  163692. png_get_x_offset_pixels(png_structp png_ptr, png_infop info_ptr)
  163693. {
  163694. if (png_ptr != NULL && info_ptr != NULL)
  163695. #if defined(PNG_oFFs_SUPPORTED)
  163696. if (info_ptr->valid & PNG_INFO_oFFs)
  163697. {
  163698. png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
  163699. if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
  163700. return (0);
  163701. else return (info_ptr->x_offset);
  163702. }
  163703. #else
  163704. return (0);
  163705. #endif
  163706. return (0);
  163707. }
  163708. png_int_32 PNGAPI
  163709. png_get_y_offset_pixels(png_structp png_ptr, png_infop info_ptr)
  163710. {
  163711. if (png_ptr != NULL && info_ptr != NULL)
  163712. #if defined(PNG_oFFs_SUPPORTED)
  163713. if (info_ptr->valid & PNG_INFO_oFFs)
  163714. {
  163715. png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
  163716. if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
  163717. return (0);
  163718. else return (info_ptr->y_offset);
  163719. }
  163720. #else
  163721. return (0);
  163722. #endif
  163723. return (0);
  163724. }
  163725. #if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED)
  163726. png_uint_32 PNGAPI
  163727. png_get_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  163728. {
  163729. return ((png_uint_32)((float)png_get_pixels_per_meter(png_ptr, info_ptr)
  163730. *.0254 +.5));
  163731. }
  163732. png_uint_32 PNGAPI
  163733. png_get_x_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  163734. {
  163735. return ((png_uint_32)((float)png_get_x_pixels_per_meter(png_ptr, info_ptr)
  163736. *.0254 +.5));
  163737. }
  163738. png_uint_32 PNGAPI
  163739. png_get_y_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  163740. {
  163741. return ((png_uint_32)((float)png_get_y_pixels_per_meter(png_ptr, info_ptr)
  163742. *.0254 +.5));
  163743. }
  163744. float PNGAPI
  163745. png_get_x_offset_inches(png_structp png_ptr, png_infop info_ptr)
  163746. {
  163747. return ((float)png_get_x_offset_microns(png_ptr, info_ptr)
  163748. *.00003937);
  163749. }
  163750. float PNGAPI
  163751. png_get_y_offset_inches(png_structp png_ptr, png_infop info_ptr)
  163752. {
  163753. return ((float)png_get_y_offset_microns(png_ptr, info_ptr)
  163754. *.00003937);
  163755. }
  163756. #if defined(PNG_pHYs_SUPPORTED)
  163757. png_uint_32 PNGAPI
  163758. png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr,
  163759. png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
  163760. {
  163761. png_uint_32 retval = 0;
  163762. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
  163763. {
  163764. png_debug1(1, "in %s retrieval function\n", "pHYs");
  163765. if (res_x != NULL)
  163766. {
  163767. *res_x = info_ptr->x_pixels_per_unit;
  163768. retval |= PNG_INFO_pHYs;
  163769. }
  163770. if (res_y != NULL)
  163771. {
  163772. *res_y = info_ptr->y_pixels_per_unit;
  163773. retval |= PNG_INFO_pHYs;
  163774. }
  163775. if (unit_type != NULL)
  163776. {
  163777. *unit_type = (int)info_ptr->phys_unit_type;
  163778. retval |= PNG_INFO_pHYs;
  163779. if(*unit_type == 1)
  163780. {
  163781. if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50);
  163782. if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50);
  163783. }
  163784. }
  163785. }
  163786. return (retval);
  163787. }
  163788. #endif /* PNG_pHYs_SUPPORTED */
  163789. #endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */
  163790. #endif /* PNG_EASY_ACCESS_SUPPORTED */
  163791. png_byte PNGAPI
  163792. png_get_channels(png_structp png_ptr, png_infop info_ptr)
  163793. {
  163794. if (png_ptr != NULL && info_ptr != NULL)
  163795. return(info_ptr->channels);
  163796. else
  163797. return (0);
  163798. }
  163799. png_bytep PNGAPI
  163800. png_get_signature(png_structp png_ptr, png_infop info_ptr)
  163801. {
  163802. if (png_ptr != NULL && info_ptr != NULL)
  163803. return(info_ptr->signature);
  163804. else
  163805. return (NULL);
  163806. }
  163807. #if defined(PNG_bKGD_SUPPORTED)
  163808. png_uint_32 PNGAPI
  163809. png_get_bKGD(png_structp png_ptr, png_infop info_ptr,
  163810. png_color_16p *background)
  163811. {
  163812. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD)
  163813. && background != NULL)
  163814. {
  163815. png_debug1(1, "in %s retrieval function\n", "bKGD");
  163816. *background = &(info_ptr->background);
  163817. return (PNG_INFO_bKGD);
  163818. }
  163819. return (0);
  163820. }
  163821. #endif
  163822. #if defined(PNG_cHRM_SUPPORTED)
  163823. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163824. png_uint_32 PNGAPI
  163825. png_get_cHRM(png_structp png_ptr, png_infop info_ptr,
  163826. double *white_x, double *white_y, double *red_x, double *red_y,
  163827. double *green_x, double *green_y, double *blue_x, double *blue_y)
  163828. {
  163829. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  163830. {
  163831. png_debug1(1, "in %s retrieval function\n", "cHRM");
  163832. if (white_x != NULL)
  163833. *white_x = (double)info_ptr->x_white;
  163834. if (white_y != NULL)
  163835. *white_y = (double)info_ptr->y_white;
  163836. if (red_x != NULL)
  163837. *red_x = (double)info_ptr->x_red;
  163838. if (red_y != NULL)
  163839. *red_y = (double)info_ptr->y_red;
  163840. if (green_x != NULL)
  163841. *green_x = (double)info_ptr->x_green;
  163842. if (green_y != NULL)
  163843. *green_y = (double)info_ptr->y_green;
  163844. if (blue_x != NULL)
  163845. *blue_x = (double)info_ptr->x_blue;
  163846. if (blue_y != NULL)
  163847. *blue_y = (double)info_ptr->y_blue;
  163848. return (PNG_INFO_cHRM);
  163849. }
  163850. return (0);
  163851. }
  163852. #endif
  163853. #ifdef PNG_FIXED_POINT_SUPPORTED
  163854. png_uint_32 PNGAPI
  163855. png_get_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
  163856. png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x,
  163857. png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y,
  163858. png_fixed_point *blue_x, png_fixed_point *blue_y)
  163859. {
  163860. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  163861. {
  163862. png_debug1(1, "in %s retrieval function\n", "cHRM");
  163863. if (white_x != NULL)
  163864. *white_x = info_ptr->int_x_white;
  163865. if (white_y != NULL)
  163866. *white_y = info_ptr->int_y_white;
  163867. if (red_x != NULL)
  163868. *red_x = info_ptr->int_x_red;
  163869. if (red_y != NULL)
  163870. *red_y = info_ptr->int_y_red;
  163871. if (green_x != NULL)
  163872. *green_x = info_ptr->int_x_green;
  163873. if (green_y != NULL)
  163874. *green_y = info_ptr->int_y_green;
  163875. if (blue_x != NULL)
  163876. *blue_x = info_ptr->int_x_blue;
  163877. if (blue_y != NULL)
  163878. *blue_y = info_ptr->int_y_blue;
  163879. return (PNG_INFO_cHRM);
  163880. }
  163881. return (0);
  163882. }
  163883. #endif
  163884. #endif
  163885. #if defined(PNG_gAMA_SUPPORTED)
  163886. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163887. png_uint_32 PNGAPI
  163888. png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma)
  163889. {
  163890. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  163891. && file_gamma != NULL)
  163892. {
  163893. png_debug1(1, "in %s retrieval function\n", "gAMA");
  163894. *file_gamma = (double)info_ptr->gamma;
  163895. return (PNG_INFO_gAMA);
  163896. }
  163897. return (0);
  163898. }
  163899. #endif
  163900. #ifdef PNG_FIXED_POINT_SUPPORTED
  163901. png_uint_32 PNGAPI
  163902. png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr,
  163903. png_fixed_point *int_file_gamma)
  163904. {
  163905. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  163906. && int_file_gamma != NULL)
  163907. {
  163908. png_debug1(1, "in %s retrieval function\n", "gAMA");
  163909. *int_file_gamma = info_ptr->int_gamma;
  163910. return (PNG_INFO_gAMA);
  163911. }
  163912. return (0);
  163913. }
  163914. #endif
  163915. #endif
  163916. #if defined(PNG_sRGB_SUPPORTED)
  163917. png_uint_32 PNGAPI
  163918. png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent)
  163919. {
  163920. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)
  163921. && file_srgb_intent != NULL)
  163922. {
  163923. png_debug1(1, "in %s retrieval function\n", "sRGB");
  163924. *file_srgb_intent = (int)info_ptr->srgb_intent;
  163925. return (PNG_INFO_sRGB);
  163926. }
  163927. return (0);
  163928. }
  163929. #endif
  163930. #if defined(PNG_iCCP_SUPPORTED)
  163931. png_uint_32 PNGAPI
  163932. png_get_iCCP(png_structp png_ptr, png_infop info_ptr,
  163933. png_charpp name, int *compression_type,
  163934. png_charpp profile, png_uint_32 *proflen)
  163935. {
  163936. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP)
  163937. && name != NULL && profile != NULL && proflen != NULL)
  163938. {
  163939. png_debug1(1, "in %s retrieval function\n", "iCCP");
  163940. *name = info_ptr->iccp_name;
  163941. *profile = info_ptr->iccp_profile;
  163942. *proflen = (int)info_ptr->iccp_proflen;
  163943. *compression_type = (int)info_ptr->iccp_compression;
  163944. return (PNG_INFO_iCCP);
  163945. }
  163946. return (0);
  163947. }
  163948. #endif
  163949. #if defined(PNG_sPLT_SUPPORTED)
  163950. png_uint_32 PNGAPI
  163951. png_get_sPLT(png_structp png_ptr, png_infop info_ptr,
  163952. png_sPLT_tpp spalettes)
  163953. {
  163954. if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)
  163955. {
  163956. *spalettes = info_ptr->splt_palettes;
  163957. return ((png_uint_32)info_ptr->splt_palettes_num);
  163958. }
  163959. return (0);
  163960. }
  163961. #endif
  163962. #if defined(PNG_hIST_SUPPORTED)
  163963. png_uint_32 PNGAPI
  163964. png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist)
  163965. {
  163966. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)
  163967. && hist != NULL)
  163968. {
  163969. png_debug1(1, "in %s retrieval function\n", "hIST");
  163970. *hist = info_ptr->hist;
  163971. return (PNG_INFO_hIST);
  163972. }
  163973. return (0);
  163974. }
  163975. #endif
  163976. png_uint_32 PNGAPI
  163977. png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
  163978. png_uint_32 *width, png_uint_32 *height, int *bit_depth,
  163979. int *color_type, int *interlace_type, int *compression_type,
  163980. int *filter_type)
  163981. {
  163982. if (png_ptr != NULL && info_ptr != NULL && width != NULL && height != NULL &&
  163983. bit_depth != NULL && color_type != NULL)
  163984. {
  163985. png_debug1(1, "in %s retrieval function\n", "IHDR");
  163986. *width = info_ptr->width;
  163987. *height = info_ptr->height;
  163988. *bit_depth = info_ptr->bit_depth;
  163989. if (info_ptr->bit_depth < 1 || info_ptr->bit_depth > 16)
  163990. png_error(png_ptr, "Invalid bit depth");
  163991. *color_type = info_ptr->color_type;
  163992. if (info_ptr->color_type > 6)
  163993. png_error(png_ptr, "Invalid color type");
  163994. if (compression_type != NULL)
  163995. *compression_type = info_ptr->compression_type;
  163996. if (filter_type != NULL)
  163997. *filter_type = info_ptr->filter_type;
  163998. if (interlace_type != NULL)
  163999. *interlace_type = info_ptr->interlace_type;
  164000. if (*width == 0 || *width > PNG_UINT_31_MAX)
  164001. png_error(png_ptr, "Invalid image width");
  164002. if (*height == 0 || *height > PNG_UINT_31_MAX)
  164003. png_error(png_ptr, "Invalid image height");
  164004. if (info_ptr->width > (PNG_UINT_32_MAX
  164005. >> 3) /* 8-byte RGBA pixels */
  164006. - 64 /* bigrowbuf hack */
  164007. - 1 /* filter byte */
  164008. - 7*8 /* rounding of width to multiple of 8 pixels */
  164009. - 8) /* extra max_pixel_depth pad */
  164010. {
  164011. png_warning(png_ptr,
  164012. "Width too large for libpng to process image data.");
  164013. }
  164014. return (1);
  164015. }
  164016. return (0);
  164017. }
  164018. #if defined(PNG_oFFs_SUPPORTED)
  164019. png_uint_32 PNGAPI
  164020. png_get_oFFs(png_structp png_ptr, png_infop info_ptr,
  164021. png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
  164022. {
  164023. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)
  164024. && offset_x != NULL && offset_y != NULL && unit_type != NULL)
  164025. {
  164026. png_debug1(1, "in %s retrieval function\n", "oFFs");
  164027. *offset_x = info_ptr->x_offset;
  164028. *offset_y = info_ptr->y_offset;
  164029. *unit_type = (int)info_ptr->offset_unit_type;
  164030. return (PNG_INFO_oFFs);
  164031. }
  164032. return (0);
  164033. }
  164034. #endif
  164035. #if defined(PNG_pCAL_SUPPORTED)
  164036. png_uint_32 PNGAPI
  164037. png_get_pCAL(png_structp png_ptr, png_infop info_ptr,
  164038. png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
  164039. png_charp *units, png_charpp *params)
  164040. {
  164041. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL)
  164042. && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
  164043. nparams != NULL && units != NULL && params != NULL)
  164044. {
  164045. png_debug1(1, "in %s retrieval function\n", "pCAL");
  164046. *purpose = info_ptr->pcal_purpose;
  164047. *X0 = info_ptr->pcal_X0;
  164048. *X1 = info_ptr->pcal_X1;
  164049. *type = (int)info_ptr->pcal_type;
  164050. *nparams = (int)info_ptr->pcal_nparams;
  164051. *units = info_ptr->pcal_units;
  164052. *params = info_ptr->pcal_params;
  164053. return (PNG_INFO_pCAL);
  164054. }
  164055. return (0);
  164056. }
  164057. #endif
  164058. #if defined(PNG_sCAL_SUPPORTED)
  164059. #ifdef PNG_FLOATING_POINT_SUPPORTED
  164060. png_uint_32 PNGAPI
  164061. png_get_sCAL(png_structp png_ptr, png_infop info_ptr,
  164062. int *unit, double *width, double *height)
  164063. {
  164064. if (png_ptr != NULL && info_ptr != NULL &&
  164065. (info_ptr->valid & PNG_INFO_sCAL))
  164066. {
  164067. *unit = info_ptr->scal_unit;
  164068. *width = info_ptr->scal_pixel_width;
  164069. *height = info_ptr->scal_pixel_height;
  164070. return (PNG_INFO_sCAL);
  164071. }
  164072. return(0);
  164073. }
  164074. #else
  164075. #ifdef PNG_FIXED_POINT_SUPPORTED
  164076. png_uint_32 PNGAPI
  164077. png_get_sCAL_s(png_structp png_ptr, png_infop info_ptr,
  164078. int *unit, png_charpp width, png_charpp height)
  164079. {
  164080. if (png_ptr != NULL && info_ptr != NULL &&
  164081. (info_ptr->valid & PNG_INFO_sCAL))
  164082. {
  164083. *unit = info_ptr->scal_unit;
  164084. *width = info_ptr->scal_s_width;
  164085. *height = info_ptr->scal_s_height;
  164086. return (PNG_INFO_sCAL);
  164087. }
  164088. return(0);
  164089. }
  164090. #endif
  164091. #endif
  164092. #endif
  164093. #if defined(PNG_pHYs_SUPPORTED)
  164094. png_uint_32 PNGAPI
  164095. png_get_pHYs(png_structp png_ptr, png_infop info_ptr,
  164096. png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
  164097. {
  164098. png_uint_32 retval = 0;
  164099. if (png_ptr != NULL && info_ptr != NULL &&
  164100. (info_ptr->valid & PNG_INFO_pHYs))
  164101. {
  164102. png_debug1(1, "in %s retrieval function\n", "pHYs");
  164103. if (res_x != NULL)
  164104. {
  164105. *res_x = info_ptr->x_pixels_per_unit;
  164106. retval |= PNG_INFO_pHYs;
  164107. }
  164108. if (res_y != NULL)
  164109. {
  164110. *res_y = info_ptr->y_pixels_per_unit;
  164111. retval |= PNG_INFO_pHYs;
  164112. }
  164113. if (unit_type != NULL)
  164114. {
  164115. *unit_type = (int)info_ptr->phys_unit_type;
  164116. retval |= PNG_INFO_pHYs;
  164117. }
  164118. }
  164119. return (retval);
  164120. }
  164121. #endif
  164122. png_uint_32 PNGAPI
  164123. png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette,
  164124. int *num_palette)
  164125. {
  164126. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE)
  164127. && palette != NULL)
  164128. {
  164129. png_debug1(1, "in %s retrieval function\n", "PLTE");
  164130. *palette = info_ptr->palette;
  164131. *num_palette = info_ptr->num_palette;
  164132. png_debug1(3, "num_palette = %d\n", *num_palette);
  164133. return (PNG_INFO_PLTE);
  164134. }
  164135. return (0);
  164136. }
  164137. #if defined(PNG_sBIT_SUPPORTED)
  164138. png_uint_32 PNGAPI
  164139. png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit)
  164140. {
  164141. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT)
  164142. && sig_bit != NULL)
  164143. {
  164144. png_debug1(1, "in %s retrieval function\n", "sBIT");
  164145. *sig_bit = &(info_ptr->sig_bit);
  164146. return (PNG_INFO_sBIT);
  164147. }
  164148. return (0);
  164149. }
  164150. #endif
  164151. #if defined(PNG_TEXT_SUPPORTED)
  164152. png_uint_32 PNGAPI
  164153. png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr,
  164154. int *num_text)
  164155. {
  164156. if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0)
  164157. {
  164158. png_debug1(1, "in %s retrieval function\n",
  164159. (png_ptr->chunk_name[0] == '\0' ? "text"
  164160. : (png_const_charp)png_ptr->chunk_name));
  164161. if (text_ptr != NULL)
  164162. *text_ptr = info_ptr->text;
  164163. if (num_text != NULL)
  164164. *num_text = info_ptr->num_text;
  164165. return ((png_uint_32)info_ptr->num_text);
  164166. }
  164167. if (num_text != NULL)
  164168. *num_text = 0;
  164169. return(0);
  164170. }
  164171. #endif
  164172. #if defined(PNG_tIME_SUPPORTED)
  164173. png_uint_32 PNGAPI
  164174. png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time)
  164175. {
  164176. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME)
  164177. && mod_time != NULL)
  164178. {
  164179. png_debug1(1, "in %s retrieval function\n", "tIME");
  164180. *mod_time = &(info_ptr->mod_time);
  164181. return (PNG_INFO_tIME);
  164182. }
  164183. return (0);
  164184. }
  164185. #endif
  164186. #if defined(PNG_tRNS_SUPPORTED)
  164187. png_uint_32 PNGAPI
  164188. png_get_tRNS(png_structp png_ptr, png_infop info_ptr,
  164189. png_bytep *trans, int *num_trans, png_color_16p *trans_values)
  164190. {
  164191. png_uint_32 retval = 0;
  164192. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  164193. {
  164194. png_debug1(1, "in %s retrieval function\n", "tRNS");
  164195. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  164196. {
  164197. if (trans != NULL)
  164198. {
  164199. *trans = info_ptr->trans;
  164200. retval |= PNG_INFO_tRNS;
  164201. }
  164202. if (trans_values != NULL)
  164203. *trans_values = &(info_ptr->trans_values);
  164204. }
  164205. else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */
  164206. {
  164207. if (trans_values != NULL)
  164208. {
  164209. *trans_values = &(info_ptr->trans_values);
  164210. retval |= PNG_INFO_tRNS;
  164211. }
  164212. if(trans != NULL)
  164213. *trans = NULL;
  164214. }
  164215. if(num_trans != NULL)
  164216. {
  164217. *num_trans = info_ptr->num_trans;
  164218. retval |= PNG_INFO_tRNS;
  164219. }
  164220. }
  164221. return (retval);
  164222. }
  164223. #endif
  164224. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  164225. png_uint_32 PNGAPI
  164226. png_get_unknown_chunks(png_structp png_ptr, png_infop info_ptr,
  164227. png_unknown_chunkpp unknowns)
  164228. {
  164229. if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL)
  164230. {
  164231. *unknowns = info_ptr->unknown_chunks;
  164232. return ((png_uint_32)info_ptr->unknown_chunks_num);
  164233. }
  164234. return (0);
  164235. }
  164236. #endif
  164237. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  164238. png_byte PNGAPI
  164239. png_get_rgb_to_gray_status (png_structp png_ptr)
  164240. {
  164241. return (png_byte)(png_ptr? png_ptr->rgb_to_gray_status : 0);
  164242. }
  164243. #endif
  164244. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  164245. png_voidp PNGAPI
  164246. png_get_user_chunk_ptr(png_structp png_ptr)
  164247. {
  164248. return (png_ptr? png_ptr->user_chunk_ptr : NULL);
  164249. }
  164250. #endif
  164251. #ifdef PNG_WRITE_SUPPORTED
  164252. png_uint_32 PNGAPI
  164253. png_get_compression_buffer_size(png_structp png_ptr)
  164254. {
  164255. return (png_uint_32)(png_ptr? png_ptr->zbuf_size : 0L);
  164256. }
  164257. #endif
  164258. #ifdef PNG_ASSEMBLER_CODE_SUPPORTED
  164259. #ifndef PNG_1_0_X
  164260. png_uint_32 PNGAPI
  164261. png_get_asm_flags (png_structp png_ptr)
  164262. {
  164263. return (png_ptr? 0L: 0L);
  164264. }
  164265. png_uint_32 PNGAPI
  164266. png_get_asm_flagmask (int flag_select)
  164267. {
  164268. flag_select=flag_select;
  164269. return 0L;
  164270. }
  164271. png_uint_32 PNGAPI
  164272. png_get_mmx_flagmask (int flag_select, int *compilerID)
  164273. {
  164274. flag_select=flag_select;
  164275. *compilerID = -1; /* unknown (i.e., no asm/MMX code compiled) */
  164276. return 0L;
  164277. }
  164278. png_byte PNGAPI
  164279. png_get_mmx_bitdepth_threshold (png_structp png_ptr)
  164280. {
  164281. return (png_ptr? 0: 0);
  164282. }
  164283. png_uint_32 PNGAPI
  164284. png_get_mmx_rowbytes_threshold (png_structp png_ptr)
  164285. {
  164286. return (png_ptr? 0L: 0L);
  164287. }
  164288. #endif /* ?PNG_1_0_X */
  164289. #endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
  164290. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  164291. png_uint_32 PNGAPI
  164292. png_get_user_width_max (png_structp png_ptr)
  164293. {
  164294. return (png_ptr? png_ptr->user_width_max : 0);
  164295. }
  164296. png_uint_32 PNGAPI
  164297. png_get_user_height_max (png_structp png_ptr)
  164298. {
  164299. return (png_ptr? png_ptr->user_height_max : 0);
  164300. }
  164301. #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
  164302. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  164303. /*** End of inlined file: pngget.c ***/
  164304. /*** Start of inlined file: pngmem.c ***/
  164305. #define PNG_INTERNAL
  164306. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  164307. #if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
  164308. png_voidp /* PRIVATE */
  164309. png_create_struct(int type)
  164310. {
  164311. #ifdef PNG_USER_MEM_SUPPORTED
  164312. return (png_create_struct_2(type, png_malloc_ptr_NULL, png_voidp_NULL));
  164313. }
  164314. png_voidp /* PRIVATE */
  164315. png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
  164316. {
  164317. #endif /* PNG_USER_MEM_SUPPORTED */
  164318. png_size_t size;
  164319. png_voidp struct_ptr;
  164320. if (type == PNG_STRUCT_INFO)
  164321. size = png_sizeof(png_info);
  164322. else if (type == PNG_STRUCT_PNG)
  164323. size = png_sizeof(png_struct);
  164324. else
  164325. return (png_get_copyright(NULL));
  164326. #ifdef PNG_USER_MEM_SUPPORTED
  164327. if(malloc_fn != NULL)
  164328. {
  164329. png_struct dummy_struct;
  164330. png_structp png_ptr = &dummy_struct;
  164331. png_ptr->mem_ptr=mem_ptr;
  164332. struct_ptr = (*(malloc_fn))(png_ptr, (png_uint_32)size);
  164333. }
  164334. else
  164335. #endif /* PNG_USER_MEM_SUPPORTED */
  164336. struct_ptr = (png_voidp)farmalloc(size);
  164337. if (struct_ptr != NULL)
  164338. png_memset(struct_ptr, 0, size);
  164339. return (struct_ptr);
  164340. }
  164341. void /* PRIVATE */
  164342. png_destroy_struct(png_voidp struct_ptr)
  164343. {
  164344. #ifdef PNG_USER_MEM_SUPPORTED
  164345. png_destroy_struct_2(struct_ptr, png_free_ptr_NULL, png_voidp_NULL);
  164346. }
  164347. void /* PRIVATE */
  164348. png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
  164349. png_voidp mem_ptr)
  164350. {
  164351. #endif
  164352. if (struct_ptr != NULL)
  164353. {
  164354. #ifdef PNG_USER_MEM_SUPPORTED
  164355. if(free_fn != NULL)
  164356. {
  164357. png_struct dummy_struct;
  164358. png_structp png_ptr = &dummy_struct;
  164359. png_ptr->mem_ptr=mem_ptr;
  164360. (*(free_fn))(png_ptr, struct_ptr);
  164361. return;
  164362. }
  164363. #endif /* PNG_USER_MEM_SUPPORTED */
  164364. farfree (struct_ptr);
  164365. }
  164366. }
  164367. png_voidp PNGAPI
  164368. png_malloc(png_structp png_ptr, png_uint_32 size)
  164369. {
  164370. png_voidp ret;
  164371. if (png_ptr == NULL || size == 0)
  164372. return (NULL);
  164373. #ifdef PNG_USER_MEM_SUPPORTED
  164374. if(png_ptr->malloc_fn != NULL)
  164375. ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size));
  164376. else
  164377. ret = (png_malloc_default(png_ptr, size));
  164378. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164379. png_error(png_ptr, "Out of memory!");
  164380. return (ret);
  164381. }
  164382. png_voidp PNGAPI
  164383. png_malloc_default(png_structp png_ptr, png_uint_32 size)
  164384. {
  164385. png_voidp ret;
  164386. #endif /* PNG_USER_MEM_SUPPORTED */
  164387. if (png_ptr == NULL || size == 0)
  164388. return (NULL);
  164389. #ifdef PNG_MAX_MALLOC_64K
  164390. if (size > (png_uint_32)65536L)
  164391. {
  164392. png_warning(png_ptr, "Cannot Allocate > 64K");
  164393. ret = NULL;
  164394. }
  164395. else
  164396. #endif
  164397. if (size != (size_t)size)
  164398. ret = NULL;
  164399. else if (size == (png_uint_32)65536L)
  164400. {
  164401. if (png_ptr->offset_table == NULL)
  164402. {
  164403. ret = farmalloc(size);
  164404. if (ret == NULL || ((png_size_t)ret & 0xffff))
  164405. {
  164406. int num_blocks;
  164407. png_uint_32 total_size;
  164408. png_bytep table;
  164409. int i;
  164410. png_byte huge * hptr;
  164411. if (ret != NULL)
  164412. {
  164413. farfree(ret);
  164414. ret = NULL;
  164415. }
  164416. if(png_ptr->zlib_window_bits > 14)
  164417. num_blocks = (int)(1 << (png_ptr->zlib_window_bits - 14));
  164418. else
  164419. num_blocks = 1;
  164420. if (png_ptr->zlib_mem_level >= 7)
  164421. num_blocks += (int)(1 << (png_ptr->zlib_mem_level - 7));
  164422. else
  164423. num_blocks++;
  164424. total_size = ((png_uint_32)65536L) * (png_uint_32)num_blocks+16;
  164425. table = farmalloc(total_size);
  164426. if (table == NULL)
  164427. {
  164428. #ifndef PNG_USER_MEM_SUPPORTED
  164429. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164430. png_error(png_ptr, "Out Of Memory."); /* Note "O" and "M" */
  164431. else
  164432. png_warning(png_ptr, "Out Of Memory.");
  164433. #endif
  164434. return (NULL);
  164435. }
  164436. if ((png_size_t)table & 0xfff0)
  164437. {
  164438. #ifndef PNG_USER_MEM_SUPPORTED
  164439. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164440. png_error(png_ptr,
  164441. "Farmalloc didn't return normalized pointer");
  164442. else
  164443. png_warning(png_ptr,
  164444. "Farmalloc didn't return normalized pointer");
  164445. #endif
  164446. return (NULL);
  164447. }
  164448. png_ptr->offset_table = table;
  164449. png_ptr->offset_table_ptr = farmalloc(num_blocks *
  164450. png_sizeof (png_bytep));
  164451. if (png_ptr->offset_table_ptr == NULL)
  164452. {
  164453. #ifndef PNG_USER_MEM_SUPPORTED
  164454. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164455. png_error(png_ptr, "Out Of memory."); /* Note "O" and "M" */
  164456. else
  164457. png_warning(png_ptr, "Out Of memory.");
  164458. #endif
  164459. return (NULL);
  164460. }
  164461. hptr = (png_byte huge *)table;
  164462. if ((png_size_t)hptr & 0xf)
  164463. {
  164464. hptr = (png_byte huge *)((long)(hptr) & 0xfffffff0L);
  164465. hptr = hptr + 16L; /* "hptr += 16L" fails on Turbo C++ 3.0 */
  164466. }
  164467. for (i = 0; i < num_blocks; i++)
  164468. {
  164469. png_ptr->offset_table_ptr[i] = (png_bytep)hptr;
  164470. hptr = hptr + (png_uint_32)65536L; /* "+=" fails on TC++3.0 */
  164471. }
  164472. png_ptr->offset_table_number = num_blocks;
  164473. png_ptr->offset_table_count = 0;
  164474. png_ptr->offset_table_count_free = 0;
  164475. }
  164476. }
  164477. if (png_ptr->offset_table_count >= png_ptr->offset_table_number)
  164478. {
  164479. #ifndef PNG_USER_MEM_SUPPORTED
  164480. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164481. png_error(png_ptr, "Out of Memory."); /* Note "o" and "M" */
  164482. else
  164483. png_warning(png_ptr, "Out of Memory.");
  164484. #endif
  164485. return (NULL);
  164486. }
  164487. ret = png_ptr->offset_table_ptr[png_ptr->offset_table_count++];
  164488. }
  164489. else
  164490. ret = farmalloc(size);
  164491. #ifndef PNG_USER_MEM_SUPPORTED
  164492. if (ret == NULL)
  164493. {
  164494. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164495. png_error(png_ptr, "Out of memory."); /* Note "o" and "m" */
  164496. else
  164497. png_warning(png_ptr, "Out of memory."); /* Note "o" and "m" */
  164498. }
  164499. #endif
  164500. return (ret);
  164501. }
  164502. void PNGAPI
  164503. png_free(png_structp png_ptr, png_voidp ptr)
  164504. {
  164505. if (png_ptr == NULL || ptr == NULL)
  164506. return;
  164507. #ifdef PNG_USER_MEM_SUPPORTED
  164508. if (png_ptr->free_fn != NULL)
  164509. {
  164510. (*(png_ptr->free_fn))(png_ptr, ptr);
  164511. return;
  164512. }
  164513. else png_free_default(png_ptr, ptr);
  164514. }
  164515. void PNGAPI
  164516. png_free_default(png_structp png_ptr, png_voidp ptr)
  164517. {
  164518. #endif /* PNG_USER_MEM_SUPPORTED */
  164519. if(png_ptr == NULL) return;
  164520. if (png_ptr->offset_table != NULL)
  164521. {
  164522. int i;
  164523. for (i = 0; i < png_ptr->offset_table_count; i++)
  164524. {
  164525. if (ptr == png_ptr->offset_table_ptr[i])
  164526. {
  164527. ptr = NULL;
  164528. png_ptr->offset_table_count_free++;
  164529. break;
  164530. }
  164531. }
  164532. if (png_ptr->offset_table_count_free == png_ptr->offset_table_count)
  164533. {
  164534. farfree(png_ptr->offset_table);
  164535. farfree(png_ptr->offset_table_ptr);
  164536. png_ptr->offset_table = NULL;
  164537. png_ptr->offset_table_ptr = NULL;
  164538. }
  164539. }
  164540. if (ptr != NULL)
  164541. {
  164542. farfree(ptr);
  164543. }
  164544. }
  164545. #else /* Not the Borland DOS special memory handler */
  164546. png_voidp /* PRIVATE */
  164547. png_create_struct(int type)
  164548. {
  164549. #ifdef PNG_USER_MEM_SUPPORTED
  164550. return (png_create_struct_2(type, png_malloc_ptr_NULL, png_voidp_NULL));
  164551. }
  164552. png_voidp /* PRIVATE */
  164553. png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
  164554. {
  164555. #endif /* PNG_USER_MEM_SUPPORTED */
  164556. png_size_t size;
  164557. png_voidp struct_ptr;
  164558. if (type == PNG_STRUCT_INFO)
  164559. size = png_sizeof(png_info);
  164560. else if (type == PNG_STRUCT_PNG)
  164561. size = png_sizeof(png_struct);
  164562. else
  164563. return (NULL);
  164564. #ifdef PNG_USER_MEM_SUPPORTED
  164565. if(malloc_fn != NULL)
  164566. {
  164567. png_struct dummy_struct;
  164568. png_structp png_ptr = &dummy_struct;
  164569. png_ptr->mem_ptr=mem_ptr;
  164570. struct_ptr = (*(malloc_fn))(png_ptr, size);
  164571. if (struct_ptr != NULL)
  164572. png_memset(struct_ptr, 0, size);
  164573. return (struct_ptr);
  164574. }
  164575. #endif /* PNG_USER_MEM_SUPPORTED */
  164576. #if defined(__TURBOC__) && !defined(__FLAT__)
  164577. struct_ptr = (png_voidp)farmalloc(size);
  164578. #else
  164579. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164580. struct_ptr = (png_voidp)halloc(size,1);
  164581. # else
  164582. struct_ptr = (png_voidp)malloc(size);
  164583. # endif
  164584. #endif
  164585. if (struct_ptr != NULL)
  164586. png_memset(struct_ptr, 0, size);
  164587. return (struct_ptr);
  164588. }
  164589. void /* PRIVATE */
  164590. png_destroy_struct(png_voidp struct_ptr)
  164591. {
  164592. #ifdef PNG_USER_MEM_SUPPORTED
  164593. png_destroy_struct_2(struct_ptr, png_free_ptr_NULL, png_voidp_NULL);
  164594. }
  164595. void /* PRIVATE */
  164596. png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
  164597. png_voidp mem_ptr)
  164598. {
  164599. #endif /* PNG_USER_MEM_SUPPORTED */
  164600. if (struct_ptr != NULL)
  164601. {
  164602. #ifdef PNG_USER_MEM_SUPPORTED
  164603. if(free_fn != NULL)
  164604. {
  164605. png_struct dummy_struct;
  164606. png_structp png_ptr = &dummy_struct;
  164607. png_ptr->mem_ptr=mem_ptr;
  164608. (*(free_fn))(png_ptr, struct_ptr);
  164609. return;
  164610. }
  164611. #endif /* PNG_USER_MEM_SUPPORTED */
  164612. #if defined(__TURBOC__) && !defined(__FLAT__)
  164613. farfree(struct_ptr);
  164614. #else
  164615. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164616. hfree(struct_ptr);
  164617. # else
  164618. free(struct_ptr);
  164619. # endif
  164620. #endif
  164621. }
  164622. }
  164623. png_voidp PNGAPI
  164624. png_malloc(png_structp png_ptr, png_uint_32 size)
  164625. {
  164626. png_voidp ret;
  164627. #ifdef PNG_USER_MEM_SUPPORTED
  164628. if (png_ptr == NULL || size == 0)
  164629. return (NULL);
  164630. if(png_ptr->malloc_fn != NULL)
  164631. ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size));
  164632. else
  164633. ret = (png_malloc_default(png_ptr, size));
  164634. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164635. png_error(png_ptr, "Out of Memory!");
  164636. return (ret);
  164637. }
  164638. png_voidp PNGAPI
  164639. png_malloc_default(png_structp png_ptr, png_uint_32 size)
  164640. {
  164641. png_voidp ret;
  164642. #endif /* PNG_USER_MEM_SUPPORTED */
  164643. if (png_ptr == NULL || size == 0)
  164644. return (NULL);
  164645. #ifdef PNG_MAX_MALLOC_64K
  164646. if (size > (png_uint_32)65536L)
  164647. {
  164648. #ifndef PNG_USER_MEM_SUPPORTED
  164649. if(png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164650. png_error(png_ptr, "Cannot Allocate > 64K");
  164651. else
  164652. #endif
  164653. return NULL;
  164654. }
  164655. #endif
  164656. #if defined(__TURBOC__) && !defined(__FLAT__)
  164657. if (size != (unsigned long)size)
  164658. ret = NULL;
  164659. else
  164660. ret = farmalloc(size);
  164661. #else
  164662. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164663. if (size != (unsigned long)size)
  164664. ret = NULL;
  164665. else
  164666. ret = halloc(size, 1);
  164667. # else
  164668. if (size != (size_t)size)
  164669. ret = NULL;
  164670. else
  164671. ret = malloc((size_t)size);
  164672. # endif
  164673. #endif
  164674. #ifndef PNG_USER_MEM_SUPPORTED
  164675. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164676. png_error(png_ptr, "Out of Memory");
  164677. #endif
  164678. return (ret);
  164679. }
  164680. void PNGAPI
  164681. png_free(png_structp png_ptr, png_voidp ptr)
  164682. {
  164683. if (png_ptr == NULL || ptr == NULL)
  164684. return;
  164685. #ifdef PNG_USER_MEM_SUPPORTED
  164686. if (png_ptr->free_fn != NULL)
  164687. {
  164688. (*(png_ptr->free_fn))(png_ptr, ptr);
  164689. return;
  164690. }
  164691. else png_free_default(png_ptr, ptr);
  164692. }
  164693. void PNGAPI
  164694. png_free_default(png_structp png_ptr, png_voidp ptr)
  164695. {
  164696. if (png_ptr == NULL || ptr == NULL)
  164697. return;
  164698. #endif /* PNG_USER_MEM_SUPPORTED */
  164699. #if defined(__TURBOC__) && !defined(__FLAT__)
  164700. farfree(ptr);
  164701. #else
  164702. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164703. hfree(ptr);
  164704. # else
  164705. free(ptr);
  164706. # endif
  164707. #endif
  164708. }
  164709. #endif /* Not Borland DOS special memory handler */
  164710. #if defined(PNG_1_0_X)
  164711. # define png_malloc_warn png_malloc
  164712. #else
  164713. png_voidp PNGAPI
  164714. png_malloc_warn(png_structp png_ptr, png_uint_32 size)
  164715. {
  164716. png_voidp ptr;
  164717. png_uint_32 save_flags;
  164718. if(png_ptr == NULL) return (NULL);
  164719. save_flags=png_ptr->flags;
  164720. png_ptr->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
  164721. ptr = (png_voidp)png_malloc((png_structp)png_ptr, size);
  164722. png_ptr->flags=save_flags;
  164723. return(ptr);
  164724. }
  164725. #endif
  164726. png_voidp PNGAPI
  164727. png_memcpy_check (png_structp png_ptr, png_voidp s1, png_voidp s2,
  164728. png_uint_32 length)
  164729. {
  164730. png_size_t size;
  164731. size = (png_size_t)length;
  164732. if ((png_uint_32)size != length)
  164733. png_error(png_ptr,"Overflow in png_memcpy_check.");
  164734. return(png_memcpy (s1, s2, size));
  164735. }
  164736. png_voidp PNGAPI
  164737. png_memset_check (png_structp png_ptr, png_voidp s1, int value,
  164738. png_uint_32 length)
  164739. {
  164740. png_size_t size;
  164741. size = (png_size_t)length;
  164742. if ((png_uint_32)size != length)
  164743. png_error(png_ptr,"Overflow in png_memset_check.");
  164744. return (png_memset (s1, value, size));
  164745. }
  164746. #ifdef PNG_USER_MEM_SUPPORTED
  164747. void PNGAPI
  164748. png_set_mem_fn(png_structp png_ptr, png_voidp mem_ptr, png_malloc_ptr
  164749. malloc_fn, png_free_ptr free_fn)
  164750. {
  164751. if(png_ptr != NULL) {
  164752. png_ptr->mem_ptr = mem_ptr;
  164753. png_ptr->malloc_fn = malloc_fn;
  164754. png_ptr->free_fn = free_fn;
  164755. }
  164756. }
  164757. png_voidp PNGAPI
  164758. png_get_mem_ptr(png_structp png_ptr)
  164759. {
  164760. if(png_ptr == NULL) return (NULL);
  164761. return ((png_voidp)png_ptr->mem_ptr);
  164762. }
  164763. #endif /* PNG_USER_MEM_SUPPORTED */
  164764. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  164765. /*** End of inlined file: pngmem.c ***/
  164766. /*** Start of inlined file: pngread.c ***/
  164767. #define PNG_INTERNAL
  164768. #if defined(PNG_READ_SUPPORTED)
  164769. png_structp PNGAPI
  164770. png_create_read_struct(png_const_charp user_png_ver, png_voidp error_ptr,
  164771. png_error_ptr error_fn, png_error_ptr warn_fn)
  164772. {
  164773. #ifdef PNG_USER_MEM_SUPPORTED
  164774. return (png_create_read_struct_2(user_png_ver, error_ptr, error_fn,
  164775. warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL));
  164776. }
  164777. png_structp PNGAPI
  164778. png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
  164779. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  164780. png_malloc_ptr malloc_fn, png_free_ptr free_fn)
  164781. {
  164782. #endif /* PNG_USER_MEM_SUPPORTED */
  164783. png_structp png_ptr;
  164784. #ifdef PNG_SETJMP_SUPPORTED
  164785. #ifdef USE_FAR_KEYWORD
  164786. jmp_buf jmpbuf;
  164787. #endif
  164788. #endif
  164789. int i;
  164790. png_debug(1, "in png_create_read_struct\n");
  164791. #ifdef PNG_USER_MEM_SUPPORTED
  164792. png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
  164793. (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr);
  164794. #else
  164795. png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  164796. #endif
  164797. if (png_ptr == NULL)
  164798. return (NULL);
  164799. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  164800. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  164801. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  164802. #endif
  164803. #ifdef PNG_SETJMP_SUPPORTED
  164804. #ifdef USE_FAR_KEYWORD
  164805. if (setjmp(jmpbuf))
  164806. #else
  164807. if (setjmp(png_ptr->jmpbuf))
  164808. #endif
  164809. {
  164810. png_free(png_ptr, png_ptr->zbuf);
  164811. png_ptr->zbuf=NULL;
  164812. #ifdef PNG_USER_MEM_SUPPORTED
  164813. png_destroy_struct_2((png_voidp)png_ptr,
  164814. (png_free_ptr)free_fn, (png_voidp)mem_ptr);
  164815. #else
  164816. png_destroy_struct((png_voidp)png_ptr);
  164817. #endif
  164818. return (NULL);
  164819. }
  164820. #ifdef USE_FAR_KEYWORD
  164821. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  164822. #endif
  164823. #endif
  164824. #ifdef PNG_USER_MEM_SUPPORTED
  164825. png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
  164826. #endif
  164827. png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
  164828. i=0;
  164829. do
  164830. {
  164831. if(user_png_ver[i] != png_libpng_ver[i])
  164832. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  164833. } while (png_libpng_ver[i++]);
  164834. if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
  164835. {
  164836. if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
  164837. (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
  164838. (user_png_ver[0] == '0' && user_png_ver[2] < '9'))
  164839. {
  164840. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  164841. char msg[80];
  164842. if (user_png_ver)
  164843. {
  164844. png_snprintf(msg, 80,
  164845. "Application was compiled with png.h from libpng-%.20s",
  164846. user_png_ver);
  164847. png_warning(png_ptr, msg);
  164848. }
  164849. png_snprintf(msg, 80,
  164850. "Application is running with png.c from libpng-%.20s",
  164851. png_libpng_ver);
  164852. png_warning(png_ptr, msg);
  164853. #endif
  164854. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  164855. png_ptr->flags=0;
  164856. #endif
  164857. png_error(png_ptr,
  164858. "Incompatible libpng version in application and library");
  164859. }
  164860. }
  164861. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  164862. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  164863. (png_uint_32)png_ptr->zbuf_size);
  164864. png_ptr->zstream.zalloc = png_zalloc;
  164865. png_ptr->zstream.zfree = png_zfree;
  164866. png_ptr->zstream.opaque = (voidpf)png_ptr;
  164867. switch (inflateInit(&png_ptr->zstream))
  164868. {
  164869. case Z_OK: /* Do nothing */ break;
  164870. case Z_MEM_ERROR:
  164871. case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory error"); break;
  164872. case Z_VERSION_ERROR: png_error(png_ptr, "zlib version error"); break;
  164873. default: png_error(png_ptr, "Unknown zlib error");
  164874. }
  164875. png_ptr->zstream.next_out = png_ptr->zbuf;
  164876. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  164877. png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL);
  164878. #ifdef PNG_SETJMP_SUPPORTED
  164879. #ifdef USE_FAR_KEYWORD
  164880. if (setjmp(jmpbuf))
  164881. PNG_ABORT();
  164882. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  164883. #else
  164884. if (setjmp(png_ptr->jmpbuf))
  164885. PNG_ABORT();
  164886. #endif
  164887. #endif
  164888. return (png_ptr);
  164889. }
  164890. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  164891. #undef png_read_init
  164892. void PNGAPI
  164893. png_read_init(png_structp png_ptr)
  164894. {
  164895. png_read_init_2(png_ptr, "1.0.6 or earlier", 0, 0);
  164896. }
  164897. void PNGAPI
  164898. png_read_init_2(png_structp png_ptr, png_const_charp user_png_ver,
  164899. png_size_t png_struct_size, png_size_t png_info_size)
  164900. {
  164901. if(png_ptr == NULL) return;
  164902. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  164903. if(png_sizeof(png_struct) > png_struct_size ||
  164904. png_sizeof(png_info) > png_info_size)
  164905. {
  164906. char msg[80];
  164907. png_ptr->warning_fn=NULL;
  164908. if (user_png_ver)
  164909. {
  164910. png_snprintf(msg, 80,
  164911. "Application was compiled with png.h from libpng-%.20s",
  164912. user_png_ver);
  164913. png_warning(png_ptr, msg);
  164914. }
  164915. png_snprintf(msg, 80,
  164916. "Application is running with png.c from libpng-%.20s",
  164917. png_libpng_ver);
  164918. png_warning(png_ptr, msg);
  164919. }
  164920. #endif
  164921. if(png_sizeof(png_struct) > png_struct_size)
  164922. {
  164923. png_ptr->error_fn=NULL;
  164924. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  164925. png_ptr->flags=0;
  164926. #endif
  164927. png_error(png_ptr,
  164928. "The png struct allocated by the application for reading is too small.");
  164929. }
  164930. if(png_sizeof(png_info) > png_info_size)
  164931. {
  164932. png_ptr->error_fn=NULL;
  164933. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  164934. png_ptr->flags=0;
  164935. #endif
  164936. png_error(png_ptr,
  164937. "The info struct allocated by application for reading is too small.");
  164938. }
  164939. png_read_init_3(&png_ptr, user_png_ver, png_struct_size);
  164940. }
  164941. #endif /* PNG_1_0_X || PNG_1_2_X */
  164942. void PNGAPI
  164943. png_read_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
  164944. png_size_t png_struct_size)
  164945. {
  164946. #ifdef PNG_SETJMP_SUPPORTED
  164947. jmp_buf tmp_jmp; /* to save current jump buffer */
  164948. #endif
  164949. int i=0;
  164950. png_structp png_ptr=*ptr_ptr;
  164951. if(png_ptr == NULL) return;
  164952. do
  164953. {
  164954. if(user_png_ver[i] != png_libpng_ver[i])
  164955. {
  164956. #ifdef PNG_LEGACY_SUPPORTED
  164957. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  164958. #else
  164959. png_ptr->warning_fn=NULL;
  164960. png_warning(png_ptr,
  164961. "Application uses deprecated png_read_init() and should be recompiled.");
  164962. break;
  164963. #endif
  164964. }
  164965. } while (png_libpng_ver[i++]);
  164966. png_debug(1, "in png_read_init_3\n");
  164967. #ifdef PNG_SETJMP_SUPPORTED
  164968. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  164969. #endif
  164970. if(png_sizeof(png_struct) > png_struct_size)
  164971. {
  164972. png_destroy_struct(png_ptr);
  164973. *ptr_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  164974. png_ptr = *ptr_ptr;
  164975. }
  164976. png_memset(png_ptr, 0, png_sizeof (png_struct));
  164977. #ifdef PNG_SETJMP_SUPPORTED
  164978. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  164979. #endif
  164980. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  164981. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  164982. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  164983. #endif
  164984. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  164985. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  164986. (png_uint_32)png_ptr->zbuf_size);
  164987. png_ptr->zstream.zalloc = png_zalloc;
  164988. png_ptr->zstream.zfree = png_zfree;
  164989. png_ptr->zstream.opaque = (voidpf)png_ptr;
  164990. switch (inflateInit(&png_ptr->zstream))
  164991. {
  164992. case Z_OK: /* Do nothing */ break;
  164993. case Z_MEM_ERROR:
  164994. case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory"); break;
  164995. case Z_VERSION_ERROR: png_error(png_ptr, "zlib version"); break;
  164996. default: png_error(png_ptr, "Unknown zlib error");
  164997. }
  164998. png_ptr->zstream.next_out = png_ptr->zbuf;
  164999. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  165000. png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL);
  165001. }
  165002. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165003. void PNGAPI
  165004. png_read_info(png_structp png_ptr, png_infop info_ptr)
  165005. {
  165006. if(png_ptr == NULL) return;
  165007. png_debug(1, "in png_read_info\n");
  165008. if (png_ptr->sig_bytes < 8)
  165009. {
  165010. png_size_t num_checked = png_ptr->sig_bytes,
  165011. num_to_check = 8 - num_checked;
  165012. png_read_data(png_ptr, &(info_ptr->signature[num_checked]), num_to_check);
  165013. png_ptr->sig_bytes = 8;
  165014. if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
  165015. {
  165016. if (num_checked < 4 &&
  165017. png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
  165018. png_error(png_ptr, "Not a PNG file");
  165019. else
  165020. png_error(png_ptr, "PNG file corrupted by ASCII conversion");
  165021. }
  165022. if (num_checked < 3)
  165023. png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
  165024. }
  165025. for(;;)
  165026. {
  165027. #ifdef PNG_USE_LOCAL_ARRAYS
  165028. PNG_CONST PNG_IHDR;
  165029. PNG_CONST PNG_IDAT;
  165030. PNG_CONST PNG_IEND;
  165031. PNG_CONST PNG_PLTE;
  165032. #if defined(PNG_READ_bKGD_SUPPORTED)
  165033. PNG_CONST PNG_bKGD;
  165034. #endif
  165035. #if defined(PNG_READ_cHRM_SUPPORTED)
  165036. PNG_CONST PNG_cHRM;
  165037. #endif
  165038. #if defined(PNG_READ_gAMA_SUPPORTED)
  165039. PNG_CONST PNG_gAMA;
  165040. #endif
  165041. #if defined(PNG_READ_hIST_SUPPORTED)
  165042. PNG_CONST PNG_hIST;
  165043. #endif
  165044. #if defined(PNG_READ_iCCP_SUPPORTED)
  165045. PNG_CONST PNG_iCCP;
  165046. #endif
  165047. #if defined(PNG_READ_iTXt_SUPPORTED)
  165048. PNG_CONST PNG_iTXt;
  165049. #endif
  165050. #if defined(PNG_READ_oFFs_SUPPORTED)
  165051. PNG_CONST PNG_oFFs;
  165052. #endif
  165053. #if defined(PNG_READ_pCAL_SUPPORTED)
  165054. PNG_CONST PNG_pCAL;
  165055. #endif
  165056. #if defined(PNG_READ_pHYs_SUPPORTED)
  165057. PNG_CONST PNG_pHYs;
  165058. #endif
  165059. #if defined(PNG_READ_sBIT_SUPPORTED)
  165060. PNG_CONST PNG_sBIT;
  165061. #endif
  165062. #if defined(PNG_READ_sCAL_SUPPORTED)
  165063. PNG_CONST PNG_sCAL;
  165064. #endif
  165065. #if defined(PNG_READ_sPLT_SUPPORTED)
  165066. PNG_CONST PNG_sPLT;
  165067. #endif
  165068. #if defined(PNG_READ_sRGB_SUPPORTED)
  165069. PNG_CONST PNG_sRGB;
  165070. #endif
  165071. #if defined(PNG_READ_tEXt_SUPPORTED)
  165072. PNG_CONST PNG_tEXt;
  165073. #endif
  165074. #if defined(PNG_READ_tIME_SUPPORTED)
  165075. PNG_CONST PNG_tIME;
  165076. #endif
  165077. #if defined(PNG_READ_tRNS_SUPPORTED)
  165078. PNG_CONST PNG_tRNS;
  165079. #endif
  165080. #if defined(PNG_READ_zTXt_SUPPORTED)
  165081. PNG_CONST PNG_zTXt;
  165082. #endif
  165083. #endif /* PNG_USE_LOCAL_ARRAYS */
  165084. png_byte chunk_length[4];
  165085. png_uint_32 length;
  165086. png_read_data(png_ptr, chunk_length, 4);
  165087. length = png_get_uint_31(png_ptr,chunk_length);
  165088. png_reset_crc(png_ptr);
  165089. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  165090. png_debug2(0, "Reading %s chunk, length=%lu.\n", png_ptr->chunk_name,
  165091. length);
  165092. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165093. if(png_ptr->mode & PNG_AFTER_IDAT)
  165094. png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
  165095. if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
  165096. png_handle_IHDR(png_ptr, info_ptr, length);
  165097. else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
  165098. png_handle_IEND(png_ptr, info_ptr, length);
  165099. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  165100. else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
  165101. {
  165102. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165103. png_ptr->mode |= PNG_HAVE_IDAT;
  165104. png_handle_unknown(png_ptr, info_ptr, length);
  165105. if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165106. png_ptr->mode |= PNG_HAVE_PLTE;
  165107. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165108. {
  165109. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  165110. png_error(png_ptr, "Missing IHDR before IDAT");
  165111. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  165112. !(png_ptr->mode & PNG_HAVE_PLTE))
  165113. png_error(png_ptr, "Missing PLTE before IDAT");
  165114. break;
  165115. }
  165116. }
  165117. #endif
  165118. else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165119. png_handle_PLTE(png_ptr, info_ptr, length);
  165120. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165121. {
  165122. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  165123. png_error(png_ptr, "Missing IHDR before IDAT");
  165124. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  165125. !(png_ptr->mode & PNG_HAVE_PLTE))
  165126. png_error(png_ptr, "Missing PLTE before IDAT");
  165127. png_ptr->idat_size = length;
  165128. png_ptr->mode |= PNG_HAVE_IDAT;
  165129. break;
  165130. }
  165131. #if defined(PNG_READ_bKGD_SUPPORTED)
  165132. else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
  165133. png_handle_bKGD(png_ptr, info_ptr, length);
  165134. #endif
  165135. #if defined(PNG_READ_cHRM_SUPPORTED)
  165136. else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
  165137. png_handle_cHRM(png_ptr, info_ptr, length);
  165138. #endif
  165139. #if defined(PNG_READ_gAMA_SUPPORTED)
  165140. else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
  165141. png_handle_gAMA(png_ptr, info_ptr, length);
  165142. #endif
  165143. #if defined(PNG_READ_hIST_SUPPORTED)
  165144. else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
  165145. png_handle_hIST(png_ptr, info_ptr, length);
  165146. #endif
  165147. #if defined(PNG_READ_oFFs_SUPPORTED)
  165148. else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
  165149. png_handle_oFFs(png_ptr, info_ptr, length);
  165150. #endif
  165151. #if defined(PNG_READ_pCAL_SUPPORTED)
  165152. else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
  165153. png_handle_pCAL(png_ptr, info_ptr, length);
  165154. #endif
  165155. #if defined(PNG_READ_sCAL_SUPPORTED)
  165156. else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
  165157. png_handle_sCAL(png_ptr, info_ptr, length);
  165158. #endif
  165159. #if defined(PNG_READ_pHYs_SUPPORTED)
  165160. else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
  165161. png_handle_pHYs(png_ptr, info_ptr, length);
  165162. #endif
  165163. #if defined(PNG_READ_sBIT_SUPPORTED)
  165164. else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
  165165. png_handle_sBIT(png_ptr, info_ptr, length);
  165166. #endif
  165167. #if defined(PNG_READ_sRGB_SUPPORTED)
  165168. else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
  165169. png_handle_sRGB(png_ptr, info_ptr, length);
  165170. #endif
  165171. #if defined(PNG_READ_iCCP_SUPPORTED)
  165172. else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
  165173. png_handle_iCCP(png_ptr, info_ptr, length);
  165174. #endif
  165175. #if defined(PNG_READ_sPLT_SUPPORTED)
  165176. else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
  165177. png_handle_sPLT(png_ptr, info_ptr, length);
  165178. #endif
  165179. #if defined(PNG_READ_tEXt_SUPPORTED)
  165180. else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
  165181. png_handle_tEXt(png_ptr, info_ptr, length);
  165182. #endif
  165183. #if defined(PNG_READ_tIME_SUPPORTED)
  165184. else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
  165185. png_handle_tIME(png_ptr, info_ptr, length);
  165186. #endif
  165187. #if defined(PNG_READ_tRNS_SUPPORTED)
  165188. else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
  165189. png_handle_tRNS(png_ptr, info_ptr, length);
  165190. #endif
  165191. #if defined(PNG_READ_zTXt_SUPPORTED)
  165192. else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
  165193. png_handle_zTXt(png_ptr, info_ptr, length);
  165194. #endif
  165195. #if defined(PNG_READ_iTXt_SUPPORTED)
  165196. else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
  165197. png_handle_iTXt(png_ptr, info_ptr, length);
  165198. #endif
  165199. else
  165200. png_handle_unknown(png_ptr, info_ptr, length);
  165201. }
  165202. }
  165203. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165204. void PNGAPI
  165205. png_read_update_info(png_structp png_ptr, png_infop info_ptr)
  165206. {
  165207. png_debug(1, "in png_read_update_info\n");
  165208. if(png_ptr == NULL) return;
  165209. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  165210. png_read_start_row(png_ptr);
  165211. else
  165212. png_warning(png_ptr,
  165213. "Ignoring extra png_read_update_info() call; row buffer not reallocated");
  165214. png_read_transform_info(png_ptr, info_ptr);
  165215. }
  165216. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165217. void PNGAPI
  165218. png_start_read_image(png_structp png_ptr)
  165219. {
  165220. png_debug(1, "in png_start_read_image\n");
  165221. if(png_ptr == NULL) return;
  165222. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  165223. png_read_start_row(png_ptr);
  165224. }
  165225. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165226. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165227. void PNGAPI
  165228. png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
  165229. {
  165230. #ifdef PNG_USE_LOCAL_ARRAYS
  165231. PNG_CONST PNG_IDAT;
  165232. PNG_CONST int png_pass_dsp_mask[7] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55,
  165233. 0xff};
  165234. PNG_CONST int png_pass_mask[7] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
  165235. #endif
  165236. int ret;
  165237. if(png_ptr == NULL) return;
  165238. png_debug2(1, "in png_read_row (row %lu, pass %d)\n",
  165239. png_ptr->row_number, png_ptr->pass);
  165240. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  165241. png_read_start_row(png_ptr);
  165242. if (png_ptr->row_number == 0 && png_ptr->pass == 0)
  165243. {
  165244. #if defined(PNG_WRITE_INVERT_SUPPORTED) && !defined(PNG_READ_INVERT_SUPPORTED)
  165245. if (png_ptr->transformations & PNG_INVERT_MONO)
  165246. png_warning(png_ptr, "PNG_READ_INVERT_SUPPORTED is not defined.");
  165247. #endif
  165248. #if defined(PNG_WRITE_FILLER_SUPPORTED) && !defined(PNG_READ_FILLER_SUPPORTED)
  165249. if (png_ptr->transformations & PNG_FILLER)
  165250. png_warning(png_ptr, "PNG_READ_FILLER_SUPPORTED is not defined.");
  165251. #endif
  165252. #if defined(PNG_WRITE_PACKSWAP_SUPPORTED) && !defined(PNG_READ_PACKSWAP_SUPPORTED)
  165253. if (png_ptr->transformations & PNG_PACKSWAP)
  165254. png_warning(png_ptr, "PNG_READ_PACKSWAP_SUPPORTED is not defined.");
  165255. #endif
  165256. #if defined(PNG_WRITE_PACK_SUPPORTED) && !defined(PNG_READ_PACK_SUPPORTED)
  165257. if (png_ptr->transformations & PNG_PACK)
  165258. png_warning(png_ptr, "PNG_READ_PACK_SUPPORTED is not defined.");
  165259. #endif
  165260. #if defined(PNG_WRITE_SHIFT_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED)
  165261. if (png_ptr->transformations & PNG_SHIFT)
  165262. png_warning(png_ptr, "PNG_READ_SHIFT_SUPPORTED is not defined.");
  165263. #endif
  165264. #if defined(PNG_WRITE_BGR_SUPPORTED) && !defined(PNG_READ_BGR_SUPPORTED)
  165265. if (png_ptr->transformations & PNG_BGR)
  165266. png_warning(png_ptr, "PNG_READ_BGR_SUPPORTED is not defined.");
  165267. #endif
  165268. #if defined(PNG_WRITE_SWAP_SUPPORTED) && !defined(PNG_READ_SWAP_SUPPORTED)
  165269. if (png_ptr->transformations & PNG_SWAP_BYTES)
  165270. png_warning(png_ptr, "PNG_READ_SWAP_SUPPORTED is not defined.");
  165271. #endif
  165272. }
  165273. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  165274. if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
  165275. {
  165276. switch (png_ptr->pass)
  165277. {
  165278. case 0:
  165279. if (png_ptr->row_number & 0x07)
  165280. {
  165281. if (dsp_row != NULL)
  165282. png_combine_row(png_ptr, dsp_row,
  165283. png_pass_dsp_mask[png_ptr->pass]);
  165284. png_read_finish_row(png_ptr);
  165285. return;
  165286. }
  165287. break;
  165288. case 1:
  165289. if ((png_ptr->row_number & 0x07) || png_ptr->width < 5)
  165290. {
  165291. if (dsp_row != NULL)
  165292. png_combine_row(png_ptr, dsp_row,
  165293. png_pass_dsp_mask[png_ptr->pass]);
  165294. png_read_finish_row(png_ptr);
  165295. return;
  165296. }
  165297. break;
  165298. case 2:
  165299. if ((png_ptr->row_number & 0x07) != 4)
  165300. {
  165301. if (dsp_row != NULL && (png_ptr->row_number & 4))
  165302. png_combine_row(png_ptr, dsp_row,
  165303. png_pass_dsp_mask[png_ptr->pass]);
  165304. png_read_finish_row(png_ptr);
  165305. return;
  165306. }
  165307. break;
  165308. case 3:
  165309. if ((png_ptr->row_number & 3) || png_ptr->width < 3)
  165310. {
  165311. if (dsp_row != NULL)
  165312. png_combine_row(png_ptr, dsp_row,
  165313. png_pass_dsp_mask[png_ptr->pass]);
  165314. png_read_finish_row(png_ptr);
  165315. return;
  165316. }
  165317. break;
  165318. case 4:
  165319. if ((png_ptr->row_number & 3) != 2)
  165320. {
  165321. if (dsp_row != NULL && (png_ptr->row_number & 2))
  165322. png_combine_row(png_ptr, dsp_row,
  165323. png_pass_dsp_mask[png_ptr->pass]);
  165324. png_read_finish_row(png_ptr);
  165325. return;
  165326. }
  165327. break;
  165328. case 5:
  165329. if ((png_ptr->row_number & 1) || png_ptr->width < 2)
  165330. {
  165331. if (dsp_row != NULL)
  165332. png_combine_row(png_ptr, dsp_row,
  165333. png_pass_dsp_mask[png_ptr->pass]);
  165334. png_read_finish_row(png_ptr);
  165335. return;
  165336. }
  165337. break;
  165338. case 6:
  165339. if (!(png_ptr->row_number & 1))
  165340. {
  165341. png_read_finish_row(png_ptr);
  165342. return;
  165343. }
  165344. break;
  165345. }
  165346. }
  165347. #endif
  165348. if (!(png_ptr->mode & PNG_HAVE_IDAT))
  165349. png_error(png_ptr, "Invalid attempt to read row data");
  165350. png_ptr->zstream.next_out = png_ptr->row_buf;
  165351. png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
  165352. do
  165353. {
  165354. if (!(png_ptr->zstream.avail_in))
  165355. {
  165356. while (!png_ptr->idat_size)
  165357. {
  165358. png_byte chunk_length[4];
  165359. png_crc_finish(png_ptr, 0);
  165360. png_read_data(png_ptr, chunk_length, 4);
  165361. png_ptr->idat_size = png_get_uint_31(png_ptr,chunk_length);
  165362. png_reset_crc(png_ptr);
  165363. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  165364. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165365. png_error(png_ptr, "Not enough image data");
  165366. }
  165367. png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size;
  165368. png_ptr->zstream.next_in = png_ptr->zbuf;
  165369. if (png_ptr->zbuf_size > png_ptr->idat_size)
  165370. png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size;
  165371. png_crc_read(png_ptr, png_ptr->zbuf,
  165372. (png_size_t)png_ptr->zstream.avail_in);
  165373. png_ptr->idat_size -= png_ptr->zstream.avail_in;
  165374. }
  165375. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  165376. if (ret == Z_STREAM_END)
  165377. {
  165378. if (png_ptr->zstream.avail_out || png_ptr->zstream.avail_in ||
  165379. png_ptr->idat_size)
  165380. png_error(png_ptr, "Extra compressed data");
  165381. png_ptr->mode |= PNG_AFTER_IDAT;
  165382. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  165383. break;
  165384. }
  165385. if (ret != Z_OK)
  165386. png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg :
  165387. "Decompression error");
  165388. } while (png_ptr->zstream.avail_out);
  165389. png_ptr->row_info.color_type = png_ptr->color_type;
  165390. png_ptr->row_info.width = png_ptr->iwidth;
  165391. png_ptr->row_info.channels = png_ptr->channels;
  165392. png_ptr->row_info.bit_depth = png_ptr->bit_depth;
  165393. png_ptr->row_info.pixel_depth = png_ptr->pixel_depth;
  165394. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  165395. png_ptr->row_info.width);
  165396. if(png_ptr->row_buf[0])
  165397. png_read_filter_row(png_ptr, &(png_ptr->row_info),
  165398. png_ptr->row_buf + 1, png_ptr->prev_row + 1,
  165399. (int)(png_ptr->row_buf[0]));
  165400. png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf,
  165401. png_ptr->rowbytes + 1);
  165402. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  165403. if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  165404. (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
  165405. {
  165406. png_do_read_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1);
  165407. }
  165408. #endif
  165409. if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
  165410. png_do_read_transformations(png_ptr);
  165411. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  165412. if (png_ptr->interlaced &&
  165413. (png_ptr->transformations & PNG_INTERLACE))
  165414. {
  165415. if (png_ptr->pass < 6)
  165416. png_do_read_interlace(png_ptr);
  165417. if (dsp_row != NULL)
  165418. png_combine_row(png_ptr, dsp_row,
  165419. png_pass_dsp_mask[png_ptr->pass]);
  165420. if (row != NULL)
  165421. png_combine_row(png_ptr, row,
  165422. png_pass_mask[png_ptr->pass]);
  165423. }
  165424. else
  165425. #endif
  165426. {
  165427. if (row != NULL)
  165428. png_combine_row(png_ptr, row, 0xff);
  165429. if (dsp_row != NULL)
  165430. png_combine_row(png_ptr, dsp_row, 0xff);
  165431. }
  165432. png_read_finish_row(png_ptr);
  165433. if (png_ptr->read_row_fn != NULL)
  165434. (*(png_ptr->read_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
  165435. }
  165436. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165437. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165438. void PNGAPI
  165439. png_read_rows(png_structp png_ptr, png_bytepp row,
  165440. png_bytepp display_row, png_uint_32 num_rows)
  165441. {
  165442. png_uint_32 i;
  165443. png_bytepp rp;
  165444. png_bytepp dp;
  165445. png_debug(1, "in png_read_rows\n");
  165446. if(png_ptr == NULL) return;
  165447. rp = row;
  165448. dp = display_row;
  165449. if (rp != NULL && dp != NULL)
  165450. for (i = 0; i < num_rows; i++)
  165451. {
  165452. png_bytep rptr = *rp++;
  165453. png_bytep dptr = *dp++;
  165454. png_read_row(png_ptr, rptr, dptr);
  165455. }
  165456. else if(rp != NULL)
  165457. for (i = 0; i < num_rows; i++)
  165458. {
  165459. png_bytep rptr = *rp;
  165460. png_read_row(png_ptr, rptr, png_bytep_NULL);
  165461. rp++;
  165462. }
  165463. else if(dp != NULL)
  165464. for (i = 0; i < num_rows; i++)
  165465. {
  165466. png_bytep dptr = *dp;
  165467. png_read_row(png_ptr, png_bytep_NULL, dptr);
  165468. dp++;
  165469. }
  165470. }
  165471. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165472. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165473. void PNGAPI
  165474. png_read_image(png_structp png_ptr, png_bytepp image)
  165475. {
  165476. png_uint_32 i,image_height;
  165477. int pass, j;
  165478. png_bytepp rp;
  165479. png_debug(1, "in png_read_image\n");
  165480. if(png_ptr == NULL) return;
  165481. #ifdef PNG_READ_INTERLACING_SUPPORTED
  165482. pass = png_set_interlace_handling(png_ptr);
  165483. #else
  165484. if (png_ptr->interlaced)
  165485. png_error(png_ptr,
  165486. "Cannot read interlaced image -- interlace handler disabled.");
  165487. pass = 1;
  165488. #endif
  165489. image_height=png_ptr->height;
  165490. png_ptr->num_rows = image_height; /* Make sure this is set correctly */
  165491. for (j = 0; j < pass; j++)
  165492. {
  165493. rp = image;
  165494. for (i = 0; i < image_height; i++)
  165495. {
  165496. png_read_row(png_ptr, *rp, png_bytep_NULL);
  165497. rp++;
  165498. }
  165499. }
  165500. }
  165501. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165502. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165503. void PNGAPI
  165504. png_read_end(png_structp png_ptr, png_infop info_ptr)
  165505. {
  165506. png_byte chunk_length[4];
  165507. png_uint_32 length;
  165508. png_debug(1, "in png_read_end\n");
  165509. if(png_ptr == NULL) return;
  165510. png_crc_finish(png_ptr, 0); /* Finish off CRC from last IDAT chunk */
  165511. do
  165512. {
  165513. #ifdef PNG_USE_LOCAL_ARRAYS
  165514. PNG_CONST PNG_IHDR;
  165515. PNG_CONST PNG_IDAT;
  165516. PNG_CONST PNG_IEND;
  165517. PNG_CONST PNG_PLTE;
  165518. #if defined(PNG_READ_bKGD_SUPPORTED)
  165519. PNG_CONST PNG_bKGD;
  165520. #endif
  165521. #if defined(PNG_READ_cHRM_SUPPORTED)
  165522. PNG_CONST PNG_cHRM;
  165523. #endif
  165524. #if defined(PNG_READ_gAMA_SUPPORTED)
  165525. PNG_CONST PNG_gAMA;
  165526. #endif
  165527. #if defined(PNG_READ_hIST_SUPPORTED)
  165528. PNG_CONST PNG_hIST;
  165529. #endif
  165530. #if defined(PNG_READ_iCCP_SUPPORTED)
  165531. PNG_CONST PNG_iCCP;
  165532. #endif
  165533. #if defined(PNG_READ_iTXt_SUPPORTED)
  165534. PNG_CONST PNG_iTXt;
  165535. #endif
  165536. #if defined(PNG_READ_oFFs_SUPPORTED)
  165537. PNG_CONST PNG_oFFs;
  165538. #endif
  165539. #if defined(PNG_READ_pCAL_SUPPORTED)
  165540. PNG_CONST PNG_pCAL;
  165541. #endif
  165542. #if defined(PNG_READ_pHYs_SUPPORTED)
  165543. PNG_CONST PNG_pHYs;
  165544. #endif
  165545. #if defined(PNG_READ_sBIT_SUPPORTED)
  165546. PNG_CONST PNG_sBIT;
  165547. #endif
  165548. #if defined(PNG_READ_sCAL_SUPPORTED)
  165549. PNG_CONST PNG_sCAL;
  165550. #endif
  165551. #if defined(PNG_READ_sPLT_SUPPORTED)
  165552. PNG_CONST PNG_sPLT;
  165553. #endif
  165554. #if defined(PNG_READ_sRGB_SUPPORTED)
  165555. PNG_CONST PNG_sRGB;
  165556. #endif
  165557. #if defined(PNG_READ_tEXt_SUPPORTED)
  165558. PNG_CONST PNG_tEXt;
  165559. #endif
  165560. #if defined(PNG_READ_tIME_SUPPORTED)
  165561. PNG_CONST PNG_tIME;
  165562. #endif
  165563. #if defined(PNG_READ_tRNS_SUPPORTED)
  165564. PNG_CONST PNG_tRNS;
  165565. #endif
  165566. #if defined(PNG_READ_zTXt_SUPPORTED)
  165567. PNG_CONST PNG_zTXt;
  165568. #endif
  165569. #endif /* PNG_USE_LOCAL_ARRAYS */
  165570. png_read_data(png_ptr, chunk_length, 4);
  165571. length = png_get_uint_31(png_ptr,chunk_length);
  165572. png_reset_crc(png_ptr);
  165573. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  165574. png_debug1(0, "Reading %s chunk.\n", png_ptr->chunk_name);
  165575. if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
  165576. png_handle_IHDR(png_ptr, info_ptr, length);
  165577. else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
  165578. png_handle_IEND(png_ptr, info_ptr, length);
  165579. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  165580. else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
  165581. {
  165582. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165583. {
  165584. if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  165585. png_error(png_ptr, "Too many IDAT's found");
  165586. }
  165587. png_handle_unknown(png_ptr, info_ptr, length);
  165588. if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165589. png_ptr->mode |= PNG_HAVE_PLTE;
  165590. }
  165591. #endif
  165592. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165593. {
  165594. if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  165595. png_error(png_ptr, "Too many IDAT's found");
  165596. png_crc_finish(png_ptr, length);
  165597. }
  165598. else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165599. png_handle_PLTE(png_ptr, info_ptr, length);
  165600. #if defined(PNG_READ_bKGD_SUPPORTED)
  165601. else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
  165602. png_handle_bKGD(png_ptr, info_ptr, length);
  165603. #endif
  165604. #if defined(PNG_READ_cHRM_SUPPORTED)
  165605. else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
  165606. png_handle_cHRM(png_ptr, info_ptr, length);
  165607. #endif
  165608. #if defined(PNG_READ_gAMA_SUPPORTED)
  165609. else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
  165610. png_handle_gAMA(png_ptr, info_ptr, length);
  165611. #endif
  165612. #if defined(PNG_READ_hIST_SUPPORTED)
  165613. else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
  165614. png_handle_hIST(png_ptr, info_ptr, length);
  165615. #endif
  165616. #if defined(PNG_READ_oFFs_SUPPORTED)
  165617. else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
  165618. png_handle_oFFs(png_ptr, info_ptr, length);
  165619. #endif
  165620. #if defined(PNG_READ_pCAL_SUPPORTED)
  165621. else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
  165622. png_handle_pCAL(png_ptr, info_ptr, length);
  165623. #endif
  165624. #if defined(PNG_READ_sCAL_SUPPORTED)
  165625. else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
  165626. png_handle_sCAL(png_ptr, info_ptr, length);
  165627. #endif
  165628. #if defined(PNG_READ_pHYs_SUPPORTED)
  165629. else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
  165630. png_handle_pHYs(png_ptr, info_ptr, length);
  165631. #endif
  165632. #if defined(PNG_READ_sBIT_SUPPORTED)
  165633. else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
  165634. png_handle_sBIT(png_ptr, info_ptr, length);
  165635. #endif
  165636. #if defined(PNG_READ_sRGB_SUPPORTED)
  165637. else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
  165638. png_handle_sRGB(png_ptr, info_ptr, length);
  165639. #endif
  165640. #if defined(PNG_READ_iCCP_SUPPORTED)
  165641. else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
  165642. png_handle_iCCP(png_ptr, info_ptr, length);
  165643. #endif
  165644. #if defined(PNG_READ_sPLT_SUPPORTED)
  165645. else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
  165646. png_handle_sPLT(png_ptr, info_ptr, length);
  165647. #endif
  165648. #if defined(PNG_READ_tEXt_SUPPORTED)
  165649. else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
  165650. png_handle_tEXt(png_ptr, info_ptr, length);
  165651. #endif
  165652. #if defined(PNG_READ_tIME_SUPPORTED)
  165653. else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
  165654. png_handle_tIME(png_ptr, info_ptr, length);
  165655. #endif
  165656. #if defined(PNG_READ_tRNS_SUPPORTED)
  165657. else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
  165658. png_handle_tRNS(png_ptr, info_ptr, length);
  165659. #endif
  165660. #if defined(PNG_READ_zTXt_SUPPORTED)
  165661. else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
  165662. png_handle_zTXt(png_ptr, info_ptr, length);
  165663. #endif
  165664. #if defined(PNG_READ_iTXt_SUPPORTED)
  165665. else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
  165666. png_handle_iTXt(png_ptr, info_ptr, length);
  165667. #endif
  165668. else
  165669. png_handle_unknown(png_ptr, info_ptr, length);
  165670. } while (!(png_ptr->mode & PNG_HAVE_IEND));
  165671. }
  165672. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165673. void PNGAPI
  165674. png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
  165675. png_infopp end_info_ptr_ptr)
  165676. {
  165677. png_structp png_ptr = NULL;
  165678. png_infop info_ptr = NULL, end_info_ptr = NULL;
  165679. #ifdef PNG_USER_MEM_SUPPORTED
  165680. png_free_ptr free_fn;
  165681. png_voidp mem_ptr;
  165682. #endif
  165683. png_debug(1, "in png_destroy_read_struct\n");
  165684. if (png_ptr_ptr != NULL)
  165685. png_ptr = *png_ptr_ptr;
  165686. if (info_ptr_ptr != NULL)
  165687. info_ptr = *info_ptr_ptr;
  165688. if (end_info_ptr_ptr != NULL)
  165689. end_info_ptr = *end_info_ptr_ptr;
  165690. #ifdef PNG_USER_MEM_SUPPORTED
  165691. free_fn = png_ptr->free_fn;
  165692. mem_ptr = png_ptr->mem_ptr;
  165693. #endif
  165694. png_read_destroy(png_ptr, info_ptr, end_info_ptr);
  165695. if (info_ptr != NULL)
  165696. {
  165697. #if defined(PNG_TEXT_SUPPORTED)
  165698. png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, -1);
  165699. #endif
  165700. #ifdef PNG_USER_MEM_SUPPORTED
  165701. png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn,
  165702. (png_voidp)mem_ptr);
  165703. #else
  165704. png_destroy_struct((png_voidp)info_ptr);
  165705. #endif
  165706. *info_ptr_ptr = NULL;
  165707. }
  165708. if (end_info_ptr != NULL)
  165709. {
  165710. #if defined(PNG_READ_TEXT_SUPPORTED)
  165711. png_free_data(png_ptr, end_info_ptr, PNG_FREE_TEXT, -1);
  165712. #endif
  165713. #ifdef PNG_USER_MEM_SUPPORTED
  165714. png_destroy_struct_2((png_voidp)end_info_ptr, (png_free_ptr)free_fn,
  165715. (png_voidp)mem_ptr);
  165716. #else
  165717. png_destroy_struct((png_voidp)end_info_ptr);
  165718. #endif
  165719. *end_info_ptr_ptr = NULL;
  165720. }
  165721. if (png_ptr != NULL)
  165722. {
  165723. #ifdef PNG_USER_MEM_SUPPORTED
  165724. png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn,
  165725. (png_voidp)mem_ptr);
  165726. #else
  165727. png_destroy_struct((png_voidp)png_ptr);
  165728. #endif
  165729. *png_ptr_ptr = NULL;
  165730. }
  165731. }
  165732. void /* PRIVATE */
  165733. png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr)
  165734. {
  165735. #ifdef PNG_SETJMP_SUPPORTED
  165736. jmp_buf tmp_jmp;
  165737. #endif
  165738. png_error_ptr error_fn;
  165739. png_error_ptr warning_fn;
  165740. png_voidp error_ptr;
  165741. #ifdef PNG_USER_MEM_SUPPORTED
  165742. png_free_ptr free_fn;
  165743. #endif
  165744. png_debug(1, "in png_read_destroy\n");
  165745. if (info_ptr != NULL)
  165746. png_info_destroy(png_ptr, info_ptr);
  165747. if (end_info_ptr != NULL)
  165748. png_info_destroy(png_ptr, end_info_ptr);
  165749. png_free(png_ptr, png_ptr->zbuf);
  165750. png_free(png_ptr, png_ptr->big_row_buf);
  165751. png_free(png_ptr, png_ptr->prev_row);
  165752. #if defined(PNG_READ_DITHER_SUPPORTED)
  165753. png_free(png_ptr, png_ptr->palette_lookup);
  165754. png_free(png_ptr, png_ptr->dither_index);
  165755. #endif
  165756. #if defined(PNG_READ_GAMMA_SUPPORTED)
  165757. png_free(png_ptr, png_ptr->gamma_table);
  165758. #endif
  165759. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  165760. png_free(png_ptr, png_ptr->gamma_from_1);
  165761. png_free(png_ptr, png_ptr->gamma_to_1);
  165762. #endif
  165763. #ifdef PNG_FREE_ME_SUPPORTED
  165764. if (png_ptr->free_me & PNG_FREE_PLTE)
  165765. png_zfree(png_ptr, png_ptr->palette);
  165766. png_ptr->free_me &= ~PNG_FREE_PLTE;
  165767. #else
  165768. if (png_ptr->flags & PNG_FLAG_FREE_PLTE)
  165769. png_zfree(png_ptr, png_ptr->palette);
  165770. png_ptr->flags &= ~PNG_FLAG_FREE_PLTE;
  165771. #endif
  165772. #if defined(PNG_tRNS_SUPPORTED) || \
  165773. defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  165774. #ifdef PNG_FREE_ME_SUPPORTED
  165775. if (png_ptr->free_me & PNG_FREE_TRNS)
  165776. png_free(png_ptr, png_ptr->trans);
  165777. png_ptr->free_me &= ~PNG_FREE_TRNS;
  165778. #else
  165779. if (png_ptr->flags & PNG_FLAG_FREE_TRNS)
  165780. png_free(png_ptr, png_ptr->trans);
  165781. png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
  165782. #endif
  165783. #endif
  165784. #if defined(PNG_READ_hIST_SUPPORTED)
  165785. #ifdef PNG_FREE_ME_SUPPORTED
  165786. if (png_ptr->free_me & PNG_FREE_HIST)
  165787. png_free(png_ptr, png_ptr->hist);
  165788. png_ptr->free_me &= ~PNG_FREE_HIST;
  165789. #else
  165790. if (png_ptr->flags & PNG_FLAG_FREE_HIST)
  165791. png_free(png_ptr, png_ptr->hist);
  165792. png_ptr->flags &= ~PNG_FLAG_FREE_HIST;
  165793. #endif
  165794. #endif
  165795. #if defined(PNG_READ_GAMMA_SUPPORTED)
  165796. if (png_ptr->gamma_16_table != NULL)
  165797. {
  165798. int i;
  165799. int istop = (1 << (8 - png_ptr->gamma_shift));
  165800. for (i = 0; i < istop; i++)
  165801. {
  165802. png_free(png_ptr, png_ptr->gamma_16_table[i]);
  165803. }
  165804. png_free(png_ptr, png_ptr->gamma_16_table);
  165805. }
  165806. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  165807. if (png_ptr->gamma_16_from_1 != NULL)
  165808. {
  165809. int i;
  165810. int istop = (1 << (8 - png_ptr->gamma_shift));
  165811. for (i = 0; i < istop; i++)
  165812. {
  165813. png_free(png_ptr, png_ptr->gamma_16_from_1[i]);
  165814. }
  165815. png_free(png_ptr, png_ptr->gamma_16_from_1);
  165816. }
  165817. if (png_ptr->gamma_16_to_1 != NULL)
  165818. {
  165819. int i;
  165820. int istop = (1 << (8 - png_ptr->gamma_shift));
  165821. for (i = 0; i < istop; i++)
  165822. {
  165823. png_free(png_ptr, png_ptr->gamma_16_to_1[i]);
  165824. }
  165825. png_free(png_ptr, png_ptr->gamma_16_to_1);
  165826. }
  165827. #endif
  165828. #endif
  165829. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  165830. png_free(png_ptr, png_ptr->time_buffer);
  165831. #endif
  165832. inflateEnd(&png_ptr->zstream);
  165833. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  165834. png_free(png_ptr, png_ptr->save_buffer);
  165835. #endif
  165836. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  165837. #ifdef PNG_TEXT_SUPPORTED
  165838. png_free(png_ptr, png_ptr->current_text);
  165839. #endif /* PNG_TEXT_SUPPORTED */
  165840. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  165841. #ifdef PNG_SETJMP_SUPPORTED
  165842. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  165843. #endif
  165844. error_fn = png_ptr->error_fn;
  165845. warning_fn = png_ptr->warning_fn;
  165846. error_ptr = png_ptr->error_ptr;
  165847. #ifdef PNG_USER_MEM_SUPPORTED
  165848. free_fn = png_ptr->free_fn;
  165849. #endif
  165850. png_memset(png_ptr, 0, png_sizeof (png_struct));
  165851. png_ptr->error_fn = error_fn;
  165852. png_ptr->warning_fn = warning_fn;
  165853. png_ptr->error_ptr = error_ptr;
  165854. #ifdef PNG_USER_MEM_SUPPORTED
  165855. png_ptr->free_fn = free_fn;
  165856. #endif
  165857. #ifdef PNG_SETJMP_SUPPORTED
  165858. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  165859. #endif
  165860. }
  165861. void PNGAPI
  165862. png_set_read_status_fn(png_structp png_ptr, png_read_status_ptr read_row_fn)
  165863. {
  165864. if(png_ptr == NULL) return;
  165865. png_ptr->read_row_fn = read_row_fn;
  165866. }
  165867. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165868. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  165869. void PNGAPI
  165870. png_read_png(png_structp png_ptr, png_infop info_ptr,
  165871. int transforms,
  165872. voidp params)
  165873. {
  165874. int row;
  165875. if(png_ptr == NULL) return;
  165876. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  165877. if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
  165878. png_set_invert_alpha(png_ptr);
  165879. #endif
  165880. png_read_info(png_ptr, info_ptr);
  165881. if (info_ptr->height > PNG_UINT_32_MAX/png_sizeof(png_bytep))
  165882. png_error(png_ptr,"Image is too high to process with png_read_png()");
  165883. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  165884. if (transforms & PNG_TRANSFORM_STRIP_16)
  165885. png_set_strip_16(png_ptr);
  165886. #endif
  165887. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  165888. if (transforms & PNG_TRANSFORM_STRIP_ALPHA)
  165889. png_set_strip_alpha(png_ptr);
  165890. #endif
  165891. #if defined(PNG_READ_PACK_SUPPORTED) && !defined(PNG_READ_EXPAND_SUPPORTED)
  165892. if (transforms & PNG_TRANSFORM_PACKING)
  165893. png_set_packing(png_ptr);
  165894. #endif
  165895. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  165896. if (transforms & PNG_TRANSFORM_PACKSWAP)
  165897. png_set_packswap(png_ptr);
  165898. #endif
  165899. #if defined(PNG_READ_EXPAND_SUPPORTED)
  165900. if (transforms & PNG_TRANSFORM_EXPAND)
  165901. if ((png_ptr->bit_depth < 8) ||
  165902. (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ||
  165903. (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)))
  165904. png_set_expand(png_ptr);
  165905. #endif
  165906. #if defined(PNG_READ_INVERT_SUPPORTED)
  165907. if (transforms & PNG_TRANSFORM_INVERT_MONO)
  165908. png_set_invert_mono(png_ptr);
  165909. #endif
  165910. #if defined(PNG_READ_SHIFT_SUPPORTED)
  165911. if ((transforms & PNG_TRANSFORM_SHIFT)
  165912. && png_get_valid(png_ptr, info_ptr, PNG_INFO_sBIT))
  165913. {
  165914. png_color_8p sig_bit;
  165915. png_get_sBIT(png_ptr, info_ptr, &sig_bit);
  165916. png_set_shift(png_ptr, sig_bit);
  165917. }
  165918. #endif
  165919. #if defined(PNG_READ_BGR_SUPPORTED)
  165920. if (transforms & PNG_TRANSFORM_BGR)
  165921. png_set_bgr(png_ptr);
  165922. #endif
  165923. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  165924. if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
  165925. png_set_swap_alpha(png_ptr);
  165926. #endif
  165927. #if defined(PNG_READ_SWAP_SUPPORTED)
  165928. if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
  165929. png_set_swap(png_ptr);
  165930. #endif
  165931. png_read_update_info(png_ptr, info_ptr);
  165932. #ifdef PNG_FREE_ME_SUPPORTED
  165933. png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
  165934. #endif
  165935. if(info_ptr->row_pointers == NULL)
  165936. {
  165937. info_ptr->row_pointers = (png_bytepp)png_malloc(png_ptr,
  165938. info_ptr->height * png_sizeof(png_bytep));
  165939. #ifdef PNG_FREE_ME_SUPPORTED
  165940. info_ptr->free_me |= PNG_FREE_ROWS;
  165941. #endif
  165942. for (row = 0; row < (int)info_ptr->height; row++)
  165943. {
  165944. info_ptr->row_pointers[row] = (png_bytep)png_malloc(png_ptr,
  165945. png_get_rowbytes(png_ptr, info_ptr));
  165946. }
  165947. }
  165948. png_read_image(png_ptr, info_ptr->row_pointers);
  165949. info_ptr->valid |= PNG_INFO_IDAT;
  165950. png_read_end(png_ptr, info_ptr);
  165951. transforms = transforms; /* quiet compiler warnings */
  165952. params = params;
  165953. }
  165954. #endif /* PNG_INFO_IMAGE_SUPPORTED */
  165955. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165956. #endif /* PNG_READ_SUPPORTED */
  165957. /*** End of inlined file: pngread.c ***/
  165958. /*** Start of inlined file: pngpread.c ***/
  165959. #define PNG_INTERNAL
  165960. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  165961. #define PNG_READ_SIG_MODE 0
  165962. #define PNG_READ_CHUNK_MODE 1
  165963. #define PNG_READ_IDAT_MODE 2
  165964. #define PNG_SKIP_MODE 3
  165965. #define PNG_READ_tEXt_MODE 4
  165966. #define PNG_READ_zTXt_MODE 5
  165967. #define PNG_READ_DONE_MODE 6
  165968. #define PNG_READ_iTXt_MODE 7
  165969. #define PNG_ERROR_MODE 8
  165970. void PNGAPI
  165971. png_process_data(png_structp png_ptr, png_infop info_ptr,
  165972. png_bytep buffer, png_size_t buffer_size)
  165973. {
  165974. if(png_ptr == NULL) return;
  165975. png_push_restore_buffer(png_ptr, buffer, buffer_size);
  165976. while (png_ptr->buffer_size)
  165977. {
  165978. png_process_some_data(png_ptr, info_ptr);
  165979. }
  165980. }
  165981. void /* PRIVATE */
  165982. png_process_some_data(png_structp png_ptr, png_infop info_ptr)
  165983. {
  165984. if(png_ptr == NULL) return;
  165985. switch (png_ptr->process_mode)
  165986. {
  165987. case PNG_READ_SIG_MODE:
  165988. {
  165989. png_push_read_sig(png_ptr, info_ptr);
  165990. break;
  165991. }
  165992. case PNG_READ_CHUNK_MODE:
  165993. {
  165994. png_push_read_chunk(png_ptr, info_ptr);
  165995. break;
  165996. }
  165997. case PNG_READ_IDAT_MODE:
  165998. {
  165999. png_push_read_IDAT(png_ptr);
  166000. break;
  166001. }
  166002. #if defined(PNG_READ_tEXt_SUPPORTED)
  166003. case PNG_READ_tEXt_MODE:
  166004. {
  166005. png_push_read_tEXt(png_ptr, info_ptr);
  166006. break;
  166007. }
  166008. #endif
  166009. #if defined(PNG_READ_zTXt_SUPPORTED)
  166010. case PNG_READ_zTXt_MODE:
  166011. {
  166012. png_push_read_zTXt(png_ptr, info_ptr);
  166013. break;
  166014. }
  166015. #endif
  166016. #if defined(PNG_READ_iTXt_SUPPORTED)
  166017. case PNG_READ_iTXt_MODE:
  166018. {
  166019. png_push_read_iTXt(png_ptr, info_ptr);
  166020. break;
  166021. }
  166022. #endif
  166023. case PNG_SKIP_MODE:
  166024. {
  166025. png_push_crc_finish(png_ptr);
  166026. break;
  166027. }
  166028. default:
  166029. {
  166030. png_ptr->buffer_size = 0;
  166031. break;
  166032. }
  166033. }
  166034. }
  166035. void /* PRIVATE */
  166036. png_push_read_sig(png_structp png_ptr, png_infop info_ptr)
  166037. {
  166038. png_size_t num_checked = png_ptr->sig_bytes,
  166039. num_to_check = 8 - num_checked;
  166040. if (png_ptr->buffer_size < num_to_check)
  166041. {
  166042. num_to_check = png_ptr->buffer_size;
  166043. }
  166044. png_push_fill_buffer(png_ptr, &(info_ptr->signature[num_checked]),
  166045. num_to_check);
  166046. png_ptr->sig_bytes = (png_byte)(png_ptr->sig_bytes+num_to_check);
  166047. if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
  166048. {
  166049. if (num_checked < 4 &&
  166050. png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
  166051. png_error(png_ptr, "Not a PNG file");
  166052. else
  166053. png_error(png_ptr, "PNG file corrupted by ASCII conversion");
  166054. }
  166055. else
  166056. {
  166057. if (png_ptr->sig_bytes >= 8)
  166058. {
  166059. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  166060. }
  166061. }
  166062. }
  166063. void /* PRIVATE */
  166064. png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
  166065. {
  166066. #ifdef PNG_USE_LOCAL_ARRAYS
  166067. PNG_CONST PNG_IHDR;
  166068. PNG_CONST PNG_IDAT;
  166069. PNG_CONST PNG_IEND;
  166070. PNG_CONST PNG_PLTE;
  166071. #if defined(PNG_READ_bKGD_SUPPORTED)
  166072. PNG_CONST PNG_bKGD;
  166073. #endif
  166074. #if defined(PNG_READ_cHRM_SUPPORTED)
  166075. PNG_CONST PNG_cHRM;
  166076. #endif
  166077. #if defined(PNG_READ_gAMA_SUPPORTED)
  166078. PNG_CONST PNG_gAMA;
  166079. #endif
  166080. #if defined(PNG_READ_hIST_SUPPORTED)
  166081. PNG_CONST PNG_hIST;
  166082. #endif
  166083. #if defined(PNG_READ_iCCP_SUPPORTED)
  166084. PNG_CONST PNG_iCCP;
  166085. #endif
  166086. #if defined(PNG_READ_iTXt_SUPPORTED)
  166087. PNG_CONST PNG_iTXt;
  166088. #endif
  166089. #if defined(PNG_READ_oFFs_SUPPORTED)
  166090. PNG_CONST PNG_oFFs;
  166091. #endif
  166092. #if defined(PNG_READ_pCAL_SUPPORTED)
  166093. PNG_CONST PNG_pCAL;
  166094. #endif
  166095. #if defined(PNG_READ_pHYs_SUPPORTED)
  166096. PNG_CONST PNG_pHYs;
  166097. #endif
  166098. #if defined(PNG_READ_sBIT_SUPPORTED)
  166099. PNG_CONST PNG_sBIT;
  166100. #endif
  166101. #if defined(PNG_READ_sCAL_SUPPORTED)
  166102. PNG_CONST PNG_sCAL;
  166103. #endif
  166104. #if defined(PNG_READ_sRGB_SUPPORTED)
  166105. PNG_CONST PNG_sRGB;
  166106. #endif
  166107. #if defined(PNG_READ_sPLT_SUPPORTED)
  166108. PNG_CONST PNG_sPLT;
  166109. #endif
  166110. #if defined(PNG_READ_tEXt_SUPPORTED)
  166111. PNG_CONST PNG_tEXt;
  166112. #endif
  166113. #if defined(PNG_READ_tIME_SUPPORTED)
  166114. PNG_CONST PNG_tIME;
  166115. #endif
  166116. #if defined(PNG_READ_tRNS_SUPPORTED)
  166117. PNG_CONST PNG_tRNS;
  166118. #endif
  166119. #if defined(PNG_READ_zTXt_SUPPORTED)
  166120. PNG_CONST PNG_zTXt;
  166121. #endif
  166122. #endif /* PNG_USE_LOCAL_ARRAYS */
  166123. if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
  166124. {
  166125. png_byte chunk_length[4];
  166126. if (png_ptr->buffer_size < 8)
  166127. {
  166128. png_push_save_buffer(png_ptr);
  166129. return;
  166130. }
  166131. png_push_fill_buffer(png_ptr, chunk_length, 4);
  166132. png_ptr->push_length = png_get_uint_31(png_ptr,chunk_length);
  166133. png_reset_crc(png_ptr);
  166134. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  166135. png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
  166136. }
  166137. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  166138. if(png_ptr->mode & PNG_AFTER_IDAT)
  166139. png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
  166140. if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
  166141. {
  166142. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166143. {
  166144. png_push_save_buffer(png_ptr);
  166145. return;
  166146. }
  166147. png_handle_IHDR(png_ptr, info_ptr, png_ptr->push_length);
  166148. }
  166149. else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
  166150. {
  166151. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166152. {
  166153. png_push_save_buffer(png_ptr);
  166154. return;
  166155. }
  166156. png_handle_IEND(png_ptr, info_ptr, png_ptr->push_length);
  166157. png_ptr->process_mode = PNG_READ_DONE_MODE;
  166158. png_push_have_end(png_ptr, info_ptr);
  166159. }
  166160. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  166161. else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
  166162. {
  166163. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166164. {
  166165. png_push_save_buffer(png_ptr);
  166166. return;
  166167. }
  166168. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  166169. png_ptr->mode |= PNG_HAVE_IDAT;
  166170. png_handle_unknown(png_ptr, info_ptr, png_ptr->push_length);
  166171. if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  166172. png_ptr->mode |= PNG_HAVE_PLTE;
  166173. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  166174. {
  166175. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  166176. png_error(png_ptr, "Missing IHDR before IDAT");
  166177. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  166178. !(png_ptr->mode & PNG_HAVE_PLTE))
  166179. png_error(png_ptr, "Missing PLTE before IDAT");
  166180. }
  166181. }
  166182. #endif
  166183. else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  166184. {
  166185. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166186. {
  166187. png_push_save_buffer(png_ptr);
  166188. return;
  166189. }
  166190. png_handle_PLTE(png_ptr, info_ptr, png_ptr->push_length);
  166191. }
  166192. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  166193. {
  166194. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  166195. png_error(png_ptr, "Missing IHDR before IDAT");
  166196. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  166197. !(png_ptr->mode & PNG_HAVE_PLTE))
  166198. png_error(png_ptr, "Missing PLTE before IDAT");
  166199. if (png_ptr->mode & PNG_HAVE_IDAT)
  166200. {
  166201. if (!(png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  166202. if (png_ptr->push_length == 0)
  166203. return;
  166204. if (png_ptr->mode & PNG_AFTER_IDAT)
  166205. png_error(png_ptr, "Too many IDAT's found");
  166206. }
  166207. png_ptr->idat_size = png_ptr->push_length;
  166208. png_ptr->mode |= PNG_HAVE_IDAT;
  166209. png_ptr->process_mode = PNG_READ_IDAT_MODE;
  166210. png_push_have_info(png_ptr, info_ptr);
  166211. png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
  166212. png_ptr->zstream.next_out = png_ptr->row_buf;
  166213. return;
  166214. }
  166215. #if defined(PNG_READ_gAMA_SUPPORTED)
  166216. else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
  166217. {
  166218. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166219. {
  166220. png_push_save_buffer(png_ptr);
  166221. return;
  166222. }
  166223. png_handle_gAMA(png_ptr, info_ptr, png_ptr->push_length);
  166224. }
  166225. #endif
  166226. #if defined(PNG_READ_sBIT_SUPPORTED)
  166227. else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
  166228. {
  166229. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166230. {
  166231. png_push_save_buffer(png_ptr);
  166232. return;
  166233. }
  166234. png_handle_sBIT(png_ptr, info_ptr, png_ptr->push_length);
  166235. }
  166236. #endif
  166237. #if defined(PNG_READ_cHRM_SUPPORTED)
  166238. else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
  166239. {
  166240. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166241. {
  166242. png_push_save_buffer(png_ptr);
  166243. return;
  166244. }
  166245. png_handle_cHRM(png_ptr, info_ptr, png_ptr->push_length);
  166246. }
  166247. #endif
  166248. #if defined(PNG_READ_sRGB_SUPPORTED)
  166249. else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
  166250. {
  166251. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166252. {
  166253. png_push_save_buffer(png_ptr);
  166254. return;
  166255. }
  166256. png_handle_sRGB(png_ptr, info_ptr, png_ptr->push_length);
  166257. }
  166258. #endif
  166259. #if defined(PNG_READ_iCCP_SUPPORTED)
  166260. else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
  166261. {
  166262. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166263. {
  166264. png_push_save_buffer(png_ptr);
  166265. return;
  166266. }
  166267. png_handle_iCCP(png_ptr, info_ptr, png_ptr->push_length);
  166268. }
  166269. #endif
  166270. #if defined(PNG_READ_sPLT_SUPPORTED)
  166271. else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
  166272. {
  166273. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166274. {
  166275. png_push_save_buffer(png_ptr);
  166276. return;
  166277. }
  166278. png_handle_sPLT(png_ptr, info_ptr, png_ptr->push_length);
  166279. }
  166280. #endif
  166281. #if defined(PNG_READ_tRNS_SUPPORTED)
  166282. else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
  166283. {
  166284. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166285. {
  166286. png_push_save_buffer(png_ptr);
  166287. return;
  166288. }
  166289. png_handle_tRNS(png_ptr, info_ptr, png_ptr->push_length);
  166290. }
  166291. #endif
  166292. #if defined(PNG_READ_bKGD_SUPPORTED)
  166293. else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
  166294. {
  166295. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166296. {
  166297. png_push_save_buffer(png_ptr);
  166298. return;
  166299. }
  166300. png_handle_bKGD(png_ptr, info_ptr, png_ptr->push_length);
  166301. }
  166302. #endif
  166303. #if defined(PNG_READ_hIST_SUPPORTED)
  166304. else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
  166305. {
  166306. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166307. {
  166308. png_push_save_buffer(png_ptr);
  166309. return;
  166310. }
  166311. png_handle_hIST(png_ptr, info_ptr, png_ptr->push_length);
  166312. }
  166313. #endif
  166314. #if defined(PNG_READ_pHYs_SUPPORTED)
  166315. else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
  166316. {
  166317. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166318. {
  166319. png_push_save_buffer(png_ptr);
  166320. return;
  166321. }
  166322. png_handle_pHYs(png_ptr, info_ptr, png_ptr->push_length);
  166323. }
  166324. #endif
  166325. #if defined(PNG_READ_oFFs_SUPPORTED)
  166326. else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
  166327. {
  166328. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166329. {
  166330. png_push_save_buffer(png_ptr);
  166331. return;
  166332. }
  166333. png_handle_oFFs(png_ptr, info_ptr, png_ptr->push_length);
  166334. }
  166335. #endif
  166336. #if defined(PNG_READ_pCAL_SUPPORTED)
  166337. else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
  166338. {
  166339. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166340. {
  166341. png_push_save_buffer(png_ptr);
  166342. return;
  166343. }
  166344. png_handle_pCAL(png_ptr, info_ptr, png_ptr->push_length);
  166345. }
  166346. #endif
  166347. #if defined(PNG_READ_sCAL_SUPPORTED)
  166348. else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
  166349. {
  166350. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166351. {
  166352. png_push_save_buffer(png_ptr);
  166353. return;
  166354. }
  166355. png_handle_sCAL(png_ptr, info_ptr, png_ptr->push_length);
  166356. }
  166357. #endif
  166358. #if defined(PNG_READ_tIME_SUPPORTED)
  166359. else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
  166360. {
  166361. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166362. {
  166363. png_push_save_buffer(png_ptr);
  166364. return;
  166365. }
  166366. png_handle_tIME(png_ptr, info_ptr, png_ptr->push_length);
  166367. }
  166368. #endif
  166369. #if defined(PNG_READ_tEXt_SUPPORTED)
  166370. else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
  166371. {
  166372. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166373. {
  166374. png_push_save_buffer(png_ptr);
  166375. return;
  166376. }
  166377. png_push_handle_tEXt(png_ptr, info_ptr, png_ptr->push_length);
  166378. }
  166379. #endif
  166380. #if defined(PNG_READ_zTXt_SUPPORTED)
  166381. else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
  166382. {
  166383. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166384. {
  166385. png_push_save_buffer(png_ptr);
  166386. return;
  166387. }
  166388. png_push_handle_zTXt(png_ptr, info_ptr, png_ptr->push_length);
  166389. }
  166390. #endif
  166391. #if defined(PNG_READ_iTXt_SUPPORTED)
  166392. else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
  166393. {
  166394. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166395. {
  166396. png_push_save_buffer(png_ptr);
  166397. return;
  166398. }
  166399. png_push_handle_iTXt(png_ptr, info_ptr, png_ptr->push_length);
  166400. }
  166401. #endif
  166402. else
  166403. {
  166404. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166405. {
  166406. png_push_save_buffer(png_ptr);
  166407. return;
  166408. }
  166409. png_push_handle_unknown(png_ptr, info_ptr, png_ptr->push_length);
  166410. }
  166411. png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
  166412. }
  166413. void /* PRIVATE */
  166414. png_push_crc_skip(png_structp png_ptr, png_uint_32 skip)
  166415. {
  166416. png_ptr->process_mode = PNG_SKIP_MODE;
  166417. png_ptr->skip_length = skip;
  166418. }
  166419. void /* PRIVATE */
  166420. png_push_crc_finish(png_structp png_ptr)
  166421. {
  166422. if (png_ptr->skip_length && png_ptr->save_buffer_size)
  166423. {
  166424. png_size_t save_size;
  166425. if (png_ptr->skip_length < (png_uint_32)png_ptr->save_buffer_size)
  166426. save_size = (png_size_t)png_ptr->skip_length;
  166427. else
  166428. save_size = png_ptr->save_buffer_size;
  166429. png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size);
  166430. png_ptr->skip_length -= save_size;
  166431. png_ptr->buffer_size -= save_size;
  166432. png_ptr->save_buffer_size -= save_size;
  166433. png_ptr->save_buffer_ptr += save_size;
  166434. }
  166435. if (png_ptr->skip_length && png_ptr->current_buffer_size)
  166436. {
  166437. png_size_t save_size;
  166438. if (png_ptr->skip_length < (png_uint_32)png_ptr->current_buffer_size)
  166439. save_size = (png_size_t)png_ptr->skip_length;
  166440. else
  166441. save_size = png_ptr->current_buffer_size;
  166442. png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size);
  166443. png_ptr->skip_length -= save_size;
  166444. png_ptr->buffer_size -= save_size;
  166445. png_ptr->current_buffer_size -= save_size;
  166446. png_ptr->current_buffer_ptr += save_size;
  166447. }
  166448. if (!png_ptr->skip_length)
  166449. {
  166450. if (png_ptr->buffer_size < 4)
  166451. {
  166452. png_push_save_buffer(png_ptr);
  166453. return;
  166454. }
  166455. png_crc_finish(png_ptr, 0);
  166456. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  166457. }
  166458. }
  166459. void PNGAPI
  166460. png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length)
  166461. {
  166462. png_bytep ptr;
  166463. if(png_ptr == NULL) return;
  166464. ptr = buffer;
  166465. if (png_ptr->save_buffer_size)
  166466. {
  166467. png_size_t save_size;
  166468. if (length < png_ptr->save_buffer_size)
  166469. save_size = length;
  166470. else
  166471. save_size = png_ptr->save_buffer_size;
  166472. png_memcpy(ptr, png_ptr->save_buffer_ptr, save_size);
  166473. length -= save_size;
  166474. ptr += save_size;
  166475. png_ptr->buffer_size -= save_size;
  166476. png_ptr->save_buffer_size -= save_size;
  166477. png_ptr->save_buffer_ptr += save_size;
  166478. }
  166479. if (length && png_ptr->current_buffer_size)
  166480. {
  166481. png_size_t save_size;
  166482. if (length < png_ptr->current_buffer_size)
  166483. save_size = length;
  166484. else
  166485. save_size = png_ptr->current_buffer_size;
  166486. png_memcpy(ptr, png_ptr->current_buffer_ptr, save_size);
  166487. png_ptr->buffer_size -= save_size;
  166488. png_ptr->current_buffer_size -= save_size;
  166489. png_ptr->current_buffer_ptr += save_size;
  166490. }
  166491. }
  166492. void /* PRIVATE */
  166493. png_push_save_buffer(png_structp png_ptr)
  166494. {
  166495. if (png_ptr->save_buffer_size)
  166496. {
  166497. if (png_ptr->save_buffer_ptr != png_ptr->save_buffer)
  166498. {
  166499. png_size_t i,istop;
  166500. png_bytep sp;
  166501. png_bytep dp;
  166502. istop = png_ptr->save_buffer_size;
  166503. for (i = 0, sp = png_ptr->save_buffer_ptr, dp = png_ptr->save_buffer;
  166504. i < istop; i++, sp++, dp++)
  166505. {
  166506. *dp = *sp;
  166507. }
  166508. }
  166509. }
  166510. if (png_ptr->save_buffer_size + png_ptr->current_buffer_size >
  166511. png_ptr->save_buffer_max)
  166512. {
  166513. png_size_t new_max;
  166514. png_bytep old_buffer;
  166515. if (png_ptr->save_buffer_size > PNG_SIZE_MAX -
  166516. (png_ptr->current_buffer_size + 256))
  166517. {
  166518. png_error(png_ptr, "Potential overflow of save_buffer");
  166519. }
  166520. new_max = png_ptr->save_buffer_size + png_ptr->current_buffer_size + 256;
  166521. old_buffer = png_ptr->save_buffer;
  166522. png_ptr->save_buffer = (png_bytep)png_malloc(png_ptr,
  166523. (png_uint_32)new_max);
  166524. png_memcpy(png_ptr->save_buffer, old_buffer, png_ptr->save_buffer_size);
  166525. png_free(png_ptr, old_buffer);
  166526. png_ptr->save_buffer_max = new_max;
  166527. }
  166528. if (png_ptr->current_buffer_size)
  166529. {
  166530. png_memcpy(png_ptr->save_buffer + png_ptr->save_buffer_size,
  166531. png_ptr->current_buffer_ptr, png_ptr->current_buffer_size);
  166532. png_ptr->save_buffer_size += png_ptr->current_buffer_size;
  166533. png_ptr->current_buffer_size = 0;
  166534. }
  166535. png_ptr->save_buffer_ptr = png_ptr->save_buffer;
  166536. png_ptr->buffer_size = 0;
  166537. }
  166538. void /* PRIVATE */
  166539. png_push_restore_buffer(png_structp png_ptr, png_bytep buffer,
  166540. png_size_t buffer_length)
  166541. {
  166542. png_ptr->current_buffer = buffer;
  166543. png_ptr->current_buffer_size = buffer_length;
  166544. png_ptr->buffer_size = buffer_length + png_ptr->save_buffer_size;
  166545. png_ptr->current_buffer_ptr = png_ptr->current_buffer;
  166546. }
  166547. void /* PRIVATE */
  166548. png_push_read_IDAT(png_structp png_ptr)
  166549. {
  166550. #ifdef PNG_USE_LOCAL_ARRAYS
  166551. PNG_CONST PNG_IDAT;
  166552. #endif
  166553. if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
  166554. {
  166555. png_byte chunk_length[4];
  166556. if (png_ptr->buffer_size < 8)
  166557. {
  166558. png_push_save_buffer(png_ptr);
  166559. return;
  166560. }
  166561. png_push_fill_buffer(png_ptr, chunk_length, 4);
  166562. png_ptr->push_length = png_get_uint_31(png_ptr,chunk_length);
  166563. png_reset_crc(png_ptr);
  166564. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  166565. png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
  166566. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  166567. {
  166568. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  166569. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  166570. png_error(png_ptr, "Not enough compressed data");
  166571. return;
  166572. }
  166573. png_ptr->idat_size = png_ptr->push_length;
  166574. }
  166575. if (png_ptr->idat_size && png_ptr->save_buffer_size)
  166576. {
  166577. png_size_t save_size;
  166578. if (png_ptr->idat_size < (png_uint_32)png_ptr->save_buffer_size)
  166579. {
  166580. save_size = (png_size_t)png_ptr->idat_size;
  166581. if((png_uint_32)save_size != png_ptr->idat_size)
  166582. png_error(png_ptr, "save_size overflowed in pngpread");
  166583. }
  166584. else
  166585. save_size = png_ptr->save_buffer_size;
  166586. png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size);
  166587. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  166588. png_process_IDAT_data(png_ptr, png_ptr->save_buffer_ptr, save_size);
  166589. png_ptr->idat_size -= save_size;
  166590. png_ptr->buffer_size -= save_size;
  166591. png_ptr->save_buffer_size -= save_size;
  166592. png_ptr->save_buffer_ptr += save_size;
  166593. }
  166594. if (png_ptr->idat_size && png_ptr->current_buffer_size)
  166595. {
  166596. png_size_t save_size;
  166597. if (png_ptr->idat_size < (png_uint_32)png_ptr->current_buffer_size)
  166598. {
  166599. save_size = (png_size_t)png_ptr->idat_size;
  166600. if((png_uint_32)save_size != png_ptr->idat_size)
  166601. png_error(png_ptr, "save_size overflowed in pngpread");
  166602. }
  166603. else
  166604. save_size = png_ptr->current_buffer_size;
  166605. png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size);
  166606. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  166607. png_process_IDAT_data(png_ptr, png_ptr->current_buffer_ptr, save_size);
  166608. png_ptr->idat_size -= save_size;
  166609. png_ptr->buffer_size -= save_size;
  166610. png_ptr->current_buffer_size -= save_size;
  166611. png_ptr->current_buffer_ptr += save_size;
  166612. }
  166613. if (!png_ptr->idat_size)
  166614. {
  166615. if (png_ptr->buffer_size < 4)
  166616. {
  166617. png_push_save_buffer(png_ptr);
  166618. return;
  166619. }
  166620. png_crc_finish(png_ptr, 0);
  166621. png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
  166622. png_ptr->mode |= PNG_AFTER_IDAT;
  166623. }
  166624. }
  166625. void /* PRIVATE */
  166626. png_process_IDAT_data(png_structp png_ptr, png_bytep buffer,
  166627. png_size_t buffer_length)
  166628. {
  166629. int ret;
  166630. if ((png_ptr->flags & PNG_FLAG_ZLIB_FINISHED) && buffer_length)
  166631. png_error(png_ptr, "Extra compression data");
  166632. png_ptr->zstream.next_in = buffer;
  166633. png_ptr->zstream.avail_in = (uInt)buffer_length;
  166634. for(;;)
  166635. {
  166636. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  166637. if (ret != Z_OK)
  166638. {
  166639. if (ret == Z_STREAM_END)
  166640. {
  166641. if (png_ptr->zstream.avail_in)
  166642. png_error(png_ptr, "Extra compressed data");
  166643. if (!(png_ptr->zstream.avail_out))
  166644. {
  166645. png_push_process_row(png_ptr);
  166646. }
  166647. png_ptr->mode |= PNG_AFTER_IDAT;
  166648. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  166649. break;
  166650. }
  166651. else if (ret == Z_BUF_ERROR)
  166652. break;
  166653. else
  166654. png_error(png_ptr, "Decompression Error");
  166655. }
  166656. if (!(png_ptr->zstream.avail_out))
  166657. {
  166658. if ((
  166659. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  166660. png_ptr->interlaced && png_ptr->pass > 6) ||
  166661. (!png_ptr->interlaced &&
  166662. #endif
  166663. png_ptr->row_number == png_ptr->num_rows))
  166664. {
  166665. if (png_ptr->zstream.avail_in)
  166666. {
  166667. png_warning(png_ptr, "Too much data in IDAT chunks");
  166668. }
  166669. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  166670. break;
  166671. }
  166672. png_push_process_row(png_ptr);
  166673. png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
  166674. png_ptr->zstream.next_out = png_ptr->row_buf;
  166675. }
  166676. else
  166677. break;
  166678. }
  166679. }
  166680. void /* PRIVATE */
  166681. png_push_process_row(png_structp png_ptr)
  166682. {
  166683. png_ptr->row_info.color_type = png_ptr->color_type;
  166684. png_ptr->row_info.width = png_ptr->iwidth;
  166685. png_ptr->row_info.channels = png_ptr->channels;
  166686. png_ptr->row_info.bit_depth = png_ptr->bit_depth;
  166687. png_ptr->row_info.pixel_depth = png_ptr->pixel_depth;
  166688. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  166689. png_ptr->row_info.width);
  166690. png_read_filter_row(png_ptr, &(png_ptr->row_info),
  166691. png_ptr->row_buf + 1, png_ptr->prev_row + 1,
  166692. (int)(png_ptr->row_buf[0]));
  166693. png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf,
  166694. png_ptr->rowbytes + 1);
  166695. if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
  166696. png_do_read_transformations(png_ptr);
  166697. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  166698. if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
  166699. {
  166700. if (png_ptr->pass < 6)
  166701. png_do_read_interlace(png_ptr);
  166702. switch (png_ptr->pass)
  166703. {
  166704. case 0:
  166705. {
  166706. int i;
  166707. for (i = 0; i < 8 && png_ptr->pass == 0; i++)
  166708. {
  166709. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166710. png_read_push_finish_row(png_ptr); /* updates png_ptr->pass */
  166711. }
  166712. if (png_ptr->pass == 2) /* pass 1 might be empty */
  166713. {
  166714. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166715. {
  166716. png_push_have_row(png_ptr, png_bytep_NULL);
  166717. png_read_push_finish_row(png_ptr);
  166718. }
  166719. }
  166720. if (png_ptr->pass == 4 && png_ptr->height <= 4)
  166721. {
  166722. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166723. {
  166724. png_push_have_row(png_ptr, png_bytep_NULL);
  166725. png_read_push_finish_row(png_ptr);
  166726. }
  166727. }
  166728. if (png_ptr->pass == 6 && png_ptr->height <= 4)
  166729. {
  166730. png_push_have_row(png_ptr, png_bytep_NULL);
  166731. png_read_push_finish_row(png_ptr);
  166732. }
  166733. break;
  166734. }
  166735. case 1:
  166736. {
  166737. int i;
  166738. for (i = 0; i < 8 && png_ptr->pass == 1; i++)
  166739. {
  166740. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166741. png_read_push_finish_row(png_ptr);
  166742. }
  166743. if (png_ptr->pass == 2) /* skip top 4 generated rows */
  166744. {
  166745. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166746. {
  166747. png_push_have_row(png_ptr, png_bytep_NULL);
  166748. png_read_push_finish_row(png_ptr);
  166749. }
  166750. }
  166751. break;
  166752. }
  166753. case 2:
  166754. {
  166755. int i;
  166756. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166757. {
  166758. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166759. png_read_push_finish_row(png_ptr);
  166760. }
  166761. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166762. {
  166763. png_push_have_row(png_ptr, png_bytep_NULL);
  166764. png_read_push_finish_row(png_ptr);
  166765. }
  166766. if (png_ptr->pass == 4) /* pass 3 might be empty */
  166767. {
  166768. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166769. {
  166770. png_push_have_row(png_ptr, png_bytep_NULL);
  166771. png_read_push_finish_row(png_ptr);
  166772. }
  166773. }
  166774. break;
  166775. }
  166776. case 3:
  166777. {
  166778. int i;
  166779. for (i = 0; i < 4 && png_ptr->pass == 3; i++)
  166780. {
  166781. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166782. png_read_push_finish_row(png_ptr);
  166783. }
  166784. if (png_ptr->pass == 4) /* skip top two generated rows */
  166785. {
  166786. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166787. {
  166788. png_push_have_row(png_ptr, png_bytep_NULL);
  166789. png_read_push_finish_row(png_ptr);
  166790. }
  166791. }
  166792. break;
  166793. }
  166794. case 4:
  166795. {
  166796. int i;
  166797. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166798. {
  166799. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166800. png_read_push_finish_row(png_ptr);
  166801. }
  166802. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166803. {
  166804. png_push_have_row(png_ptr, png_bytep_NULL);
  166805. png_read_push_finish_row(png_ptr);
  166806. }
  166807. if (png_ptr->pass == 6) /* pass 5 might be empty */
  166808. {
  166809. png_push_have_row(png_ptr, png_bytep_NULL);
  166810. png_read_push_finish_row(png_ptr);
  166811. }
  166812. break;
  166813. }
  166814. case 5:
  166815. {
  166816. int i;
  166817. for (i = 0; i < 2 && png_ptr->pass == 5; i++)
  166818. {
  166819. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166820. png_read_push_finish_row(png_ptr);
  166821. }
  166822. if (png_ptr->pass == 6) /* skip top generated row */
  166823. {
  166824. png_push_have_row(png_ptr, png_bytep_NULL);
  166825. png_read_push_finish_row(png_ptr);
  166826. }
  166827. break;
  166828. }
  166829. case 6:
  166830. {
  166831. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166832. png_read_push_finish_row(png_ptr);
  166833. if (png_ptr->pass != 6)
  166834. break;
  166835. png_push_have_row(png_ptr, png_bytep_NULL);
  166836. png_read_push_finish_row(png_ptr);
  166837. }
  166838. }
  166839. }
  166840. else
  166841. #endif
  166842. {
  166843. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166844. png_read_push_finish_row(png_ptr);
  166845. }
  166846. }
  166847. void /* PRIVATE */
  166848. png_read_push_finish_row(png_structp png_ptr)
  166849. {
  166850. #ifdef PNG_USE_LOCAL_ARRAYS
  166851. PNG_CONST int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
  166852. PNG_CONST int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
  166853. PNG_CONST int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
  166854. PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
  166855. #endif
  166856. png_ptr->row_number++;
  166857. if (png_ptr->row_number < png_ptr->num_rows)
  166858. return;
  166859. if (png_ptr->interlaced)
  166860. {
  166861. png_ptr->row_number = 0;
  166862. png_memset_check(png_ptr, png_ptr->prev_row, 0,
  166863. png_ptr->rowbytes + 1);
  166864. do
  166865. {
  166866. png_ptr->pass++;
  166867. if ((png_ptr->pass == 1 && png_ptr->width < 5) ||
  166868. (png_ptr->pass == 3 && png_ptr->width < 3) ||
  166869. (png_ptr->pass == 5 && png_ptr->width < 2))
  166870. png_ptr->pass++;
  166871. if (png_ptr->pass > 7)
  166872. png_ptr->pass--;
  166873. if (png_ptr->pass >= 7)
  166874. break;
  166875. png_ptr->iwidth = (png_ptr->width +
  166876. png_pass_inc[png_ptr->pass] - 1 -
  166877. png_pass_start[png_ptr->pass]) /
  166878. png_pass_inc[png_ptr->pass];
  166879. png_ptr->irowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,
  166880. png_ptr->iwidth) + 1;
  166881. if (png_ptr->transformations & PNG_INTERLACE)
  166882. break;
  166883. png_ptr->num_rows = (png_ptr->height +
  166884. png_pass_yinc[png_ptr->pass] - 1 -
  166885. png_pass_ystart[png_ptr->pass]) /
  166886. png_pass_yinc[png_ptr->pass];
  166887. } while (png_ptr->iwidth == 0 || png_ptr->num_rows == 0);
  166888. }
  166889. }
  166890. #if defined(PNG_READ_tEXt_SUPPORTED)
  166891. void /* PRIVATE */
  166892. png_push_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
  166893. length)
  166894. {
  166895. if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
  166896. {
  166897. png_error(png_ptr, "Out of place tEXt");
  166898. info_ptr = info_ptr; /* to quiet some compiler warnings */
  166899. }
  166900. #ifdef PNG_MAX_MALLOC_64K
  166901. png_ptr->skip_length = 0; /* This may not be necessary */
  166902. if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */
  166903. {
  166904. png_warning(png_ptr, "tEXt chunk too large to fit in memory");
  166905. png_ptr->skip_length = length - (png_uint_32)65535L;
  166906. length = (png_uint_32)65535L;
  166907. }
  166908. #endif
  166909. png_ptr->current_text = (png_charp)png_malloc(png_ptr,
  166910. (png_uint_32)(length+1));
  166911. png_ptr->current_text[length] = '\0';
  166912. png_ptr->current_text_ptr = png_ptr->current_text;
  166913. png_ptr->current_text_size = (png_size_t)length;
  166914. png_ptr->current_text_left = (png_size_t)length;
  166915. png_ptr->process_mode = PNG_READ_tEXt_MODE;
  166916. }
  166917. void /* PRIVATE */
  166918. png_push_read_tEXt(png_structp png_ptr, png_infop info_ptr)
  166919. {
  166920. if (png_ptr->buffer_size && png_ptr->current_text_left)
  166921. {
  166922. png_size_t text_size;
  166923. if (png_ptr->buffer_size < png_ptr->current_text_left)
  166924. text_size = png_ptr->buffer_size;
  166925. else
  166926. text_size = png_ptr->current_text_left;
  166927. png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
  166928. png_ptr->current_text_left -= text_size;
  166929. png_ptr->current_text_ptr += text_size;
  166930. }
  166931. if (!(png_ptr->current_text_left))
  166932. {
  166933. png_textp text_ptr;
  166934. png_charp text;
  166935. png_charp key;
  166936. int ret;
  166937. if (png_ptr->buffer_size < 4)
  166938. {
  166939. png_push_save_buffer(png_ptr);
  166940. return;
  166941. }
  166942. png_push_crc_finish(png_ptr);
  166943. #if defined(PNG_MAX_MALLOC_64K)
  166944. if (png_ptr->skip_length)
  166945. return;
  166946. #endif
  166947. key = png_ptr->current_text;
  166948. for (text = key; *text; text++)
  166949. ;
  166950. if (text < key + png_ptr->current_text_size)
  166951. text++;
  166952. text_ptr = (png_textp)png_malloc(png_ptr,
  166953. (png_uint_32)png_sizeof(png_text));
  166954. text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
  166955. text_ptr->key = key;
  166956. #ifdef PNG_iTXt_SUPPORTED
  166957. text_ptr->lang = NULL;
  166958. text_ptr->lang_key = NULL;
  166959. #endif
  166960. text_ptr->text = text;
  166961. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  166962. png_free(png_ptr, key);
  166963. png_free(png_ptr, text_ptr);
  166964. png_ptr->current_text = NULL;
  166965. if (ret)
  166966. png_warning(png_ptr, "Insufficient memory to store text chunk.");
  166967. }
  166968. }
  166969. #endif
  166970. #if defined(PNG_READ_zTXt_SUPPORTED)
  166971. void /* PRIVATE */
  166972. png_push_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
  166973. length)
  166974. {
  166975. if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
  166976. {
  166977. png_error(png_ptr, "Out of place zTXt");
  166978. info_ptr = info_ptr; /* to quiet some compiler warnings */
  166979. }
  166980. #ifdef PNG_MAX_MALLOC_64K
  166981. if (length > (png_uint_32)65535L)
  166982. {
  166983. png_warning(png_ptr, "zTXt chunk too large to fit in memory");
  166984. png_push_crc_skip(png_ptr, length);
  166985. return;
  166986. }
  166987. #endif
  166988. png_ptr->current_text = (png_charp)png_malloc(png_ptr,
  166989. (png_uint_32)(length+1));
  166990. png_ptr->current_text[length] = '\0';
  166991. png_ptr->current_text_ptr = png_ptr->current_text;
  166992. png_ptr->current_text_size = (png_size_t)length;
  166993. png_ptr->current_text_left = (png_size_t)length;
  166994. png_ptr->process_mode = PNG_READ_zTXt_MODE;
  166995. }
  166996. void /* PRIVATE */
  166997. png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
  166998. {
  166999. if (png_ptr->buffer_size && png_ptr->current_text_left)
  167000. {
  167001. png_size_t text_size;
  167002. if (png_ptr->buffer_size < (png_uint_32)png_ptr->current_text_left)
  167003. text_size = png_ptr->buffer_size;
  167004. else
  167005. text_size = png_ptr->current_text_left;
  167006. png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
  167007. png_ptr->current_text_left -= text_size;
  167008. png_ptr->current_text_ptr += text_size;
  167009. }
  167010. if (!(png_ptr->current_text_left))
  167011. {
  167012. png_textp text_ptr;
  167013. png_charp text;
  167014. png_charp key;
  167015. int ret;
  167016. png_size_t text_size, key_size;
  167017. if (png_ptr->buffer_size < 4)
  167018. {
  167019. png_push_save_buffer(png_ptr);
  167020. return;
  167021. }
  167022. png_push_crc_finish(png_ptr);
  167023. key = png_ptr->current_text;
  167024. for (text = key; *text; text++)
  167025. ;
  167026. if (text >= key + png_ptr->current_text_size)
  167027. {
  167028. png_ptr->current_text = NULL;
  167029. png_free(png_ptr, key);
  167030. return;
  167031. }
  167032. text++;
  167033. if (*text != PNG_TEXT_COMPRESSION_zTXt) /* check compression byte */
  167034. {
  167035. png_ptr->current_text = NULL;
  167036. png_free(png_ptr, key);
  167037. return;
  167038. }
  167039. text++;
  167040. png_ptr->zstream.next_in = (png_bytep )text;
  167041. png_ptr->zstream.avail_in = (uInt)(png_ptr->current_text_size -
  167042. (text - key));
  167043. png_ptr->zstream.next_out = png_ptr->zbuf;
  167044. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  167045. key_size = text - key;
  167046. text_size = 0;
  167047. text = NULL;
  167048. ret = Z_STREAM_END;
  167049. while (png_ptr->zstream.avail_in)
  167050. {
  167051. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  167052. if (ret != Z_OK && ret != Z_STREAM_END)
  167053. {
  167054. inflateReset(&png_ptr->zstream);
  167055. png_ptr->zstream.avail_in = 0;
  167056. png_ptr->current_text = NULL;
  167057. png_free(png_ptr, key);
  167058. png_free(png_ptr, text);
  167059. return;
  167060. }
  167061. if (!(png_ptr->zstream.avail_out) || ret == Z_STREAM_END)
  167062. {
  167063. if (text == NULL)
  167064. {
  167065. text = (png_charp)png_malloc(png_ptr,
  167066. (png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out
  167067. + key_size + 1));
  167068. png_memcpy(text + key_size, png_ptr->zbuf,
  167069. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  167070. png_memcpy(text, key, key_size);
  167071. text_size = key_size + png_ptr->zbuf_size -
  167072. png_ptr->zstream.avail_out;
  167073. *(text + text_size) = '\0';
  167074. }
  167075. else
  167076. {
  167077. png_charp tmp;
  167078. tmp = text;
  167079. text = (png_charp)png_malloc(png_ptr, text_size +
  167080. (png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out
  167081. + 1));
  167082. png_memcpy(text, tmp, text_size);
  167083. png_free(png_ptr, tmp);
  167084. png_memcpy(text + text_size, png_ptr->zbuf,
  167085. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  167086. text_size += png_ptr->zbuf_size - png_ptr->zstream.avail_out;
  167087. *(text + text_size) = '\0';
  167088. }
  167089. if (ret != Z_STREAM_END)
  167090. {
  167091. png_ptr->zstream.next_out = png_ptr->zbuf;
  167092. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  167093. }
  167094. }
  167095. else
  167096. {
  167097. break;
  167098. }
  167099. if (ret == Z_STREAM_END)
  167100. break;
  167101. }
  167102. inflateReset(&png_ptr->zstream);
  167103. png_ptr->zstream.avail_in = 0;
  167104. if (ret != Z_STREAM_END)
  167105. {
  167106. png_ptr->current_text = NULL;
  167107. png_free(png_ptr, key);
  167108. png_free(png_ptr, text);
  167109. return;
  167110. }
  167111. png_ptr->current_text = NULL;
  167112. png_free(png_ptr, key);
  167113. key = text;
  167114. text += key_size;
  167115. text_ptr = (png_textp)png_malloc(png_ptr,
  167116. (png_uint_32)png_sizeof(png_text));
  167117. text_ptr->compression = PNG_TEXT_COMPRESSION_zTXt;
  167118. text_ptr->key = key;
  167119. #ifdef PNG_iTXt_SUPPORTED
  167120. text_ptr->lang = NULL;
  167121. text_ptr->lang_key = NULL;
  167122. #endif
  167123. text_ptr->text = text;
  167124. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  167125. png_free(png_ptr, key);
  167126. png_free(png_ptr, text_ptr);
  167127. if (ret)
  167128. png_warning(png_ptr, "Insufficient memory to store text chunk.");
  167129. }
  167130. }
  167131. #endif
  167132. #if defined(PNG_READ_iTXt_SUPPORTED)
  167133. void /* PRIVATE */
  167134. png_push_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
  167135. length)
  167136. {
  167137. if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
  167138. {
  167139. png_error(png_ptr, "Out of place iTXt");
  167140. info_ptr = info_ptr; /* to quiet some compiler warnings */
  167141. }
  167142. #ifdef PNG_MAX_MALLOC_64K
  167143. png_ptr->skip_length = 0; /* This may not be necessary */
  167144. if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */
  167145. {
  167146. png_warning(png_ptr, "iTXt chunk too large to fit in memory");
  167147. png_ptr->skip_length = length - (png_uint_32)65535L;
  167148. length = (png_uint_32)65535L;
  167149. }
  167150. #endif
  167151. png_ptr->current_text = (png_charp)png_malloc(png_ptr,
  167152. (png_uint_32)(length+1));
  167153. png_ptr->current_text[length] = '\0';
  167154. png_ptr->current_text_ptr = png_ptr->current_text;
  167155. png_ptr->current_text_size = (png_size_t)length;
  167156. png_ptr->current_text_left = (png_size_t)length;
  167157. png_ptr->process_mode = PNG_READ_iTXt_MODE;
  167158. }
  167159. void /* PRIVATE */
  167160. png_push_read_iTXt(png_structp png_ptr, png_infop info_ptr)
  167161. {
  167162. if (png_ptr->buffer_size && png_ptr->current_text_left)
  167163. {
  167164. png_size_t text_size;
  167165. if (png_ptr->buffer_size < png_ptr->current_text_left)
  167166. text_size = png_ptr->buffer_size;
  167167. else
  167168. text_size = png_ptr->current_text_left;
  167169. png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
  167170. png_ptr->current_text_left -= text_size;
  167171. png_ptr->current_text_ptr += text_size;
  167172. }
  167173. if (!(png_ptr->current_text_left))
  167174. {
  167175. png_textp text_ptr;
  167176. png_charp key;
  167177. int comp_flag;
  167178. png_charp lang;
  167179. png_charp lang_key;
  167180. png_charp text;
  167181. int ret;
  167182. if (png_ptr->buffer_size < 4)
  167183. {
  167184. png_push_save_buffer(png_ptr);
  167185. return;
  167186. }
  167187. png_push_crc_finish(png_ptr);
  167188. #if defined(PNG_MAX_MALLOC_64K)
  167189. if (png_ptr->skip_length)
  167190. return;
  167191. #endif
  167192. key = png_ptr->current_text;
  167193. for (lang = key; *lang; lang++)
  167194. ;
  167195. if (lang < key + png_ptr->current_text_size - 3)
  167196. lang++;
  167197. comp_flag = *lang++;
  167198. lang++; /* skip comp_type, always zero */
  167199. for (lang_key = lang; *lang_key; lang_key++)
  167200. ;
  167201. lang_key++; /* skip NUL separator */
  167202. text=lang_key;
  167203. if (lang_key < key + png_ptr->current_text_size - 1)
  167204. {
  167205. for (; *text; text++)
  167206. ;
  167207. }
  167208. if (text < key + png_ptr->current_text_size)
  167209. text++;
  167210. text_ptr = (png_textp)png_malloc(png_ptr,
  167211. (png_uint_32)png_sizeof(png_text));
  167212. text_ptr->compression = comp_flag + 2;
  167213. text_ptr->key = key;
  167214. text_ptr->lang = lang;
  167215. text_ptr->lang_key = lang_key;
  167216. text_ptr->text = text;
  167217. text_ptr->text_length = 0;
  167218. text_ptr->itxt_length = png_strlen(text);
  167219. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  167220. png_ptr->current_text = NULL;
  167221. png_free(png_ptr, text_ptr);
  167222. if (ret)
  167223. png_warning(png_ptr, "Insufficient memory to store iTXt chunk.");
  167224. }
  167225. }
  167226. #endif
  167227. void /* PRIVATE */
  167228. png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32
  167229. length)
  167230. {
  167231. png_uint_32 skip=0;
  167232. png_check_chunk_name(png_ptr, png_ptr->chunk_name);
  167233. if (!(png_ptr->chunk_name[0] & 0x20))
  167234. {
  167235. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  167236. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  167237. PNG_HANDLE_CHUNK_ALWAYS
  167238. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  167239. && png_ptr->read_user_chunk_fn == NULL
  167240. #endif
  167241. )
  167242. #endif
  167243. png_chunk_error(png_ptr, "unknown critical chunk");
  167244. info_ptr = info_ptr; /* to quiet some compiler warnings */
  167245. }
  167246. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  167247. if (png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS)
  167248. {
  167249. #ifdef PNG_MAX_MALLOC_64K
  167250. if (length > (png_uint_32)65535L)
  167251. {
  167252. png_warning(png_ptr, "unknown chunk too large to fit in memory");
  167253. skip = length - (png_uint_32)65535L;
  167254. length = (png_uint_32)65535L;
  167255. }
  167256. #endif
  167257. png_strncpy((png_charp)png_ptr->unknown_chunk.name,
  167258. (png_charp)png_ptr->chunk_name, 5);
  167259. png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length);
  167260. png_ptr->unknown_chunk.size = (png_size_t)length;
  167261. png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
  167262. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  167263. if(png_ptr->read_user_chunk_fn != NULL)
  167264. {
  167265. int ret;
  167266. ret = (*(png_ptr->read_user_chunk_fn))
  167267. (png_ptr, &png_ptr->unknown_chunk);
  167268. if (ret < 0)
  167269. png_chunk_error(png_ptr, "error in user chunk");
  167270. if (ret == 0)
  167271. {
  167272. if (!(png_ptr->chunk_name[0] & 0x20))
  167273. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  167274. PNG_HANDLE_CHUNK_ALWAYS)
  167275. png_chunk_error(png_ptr, "unknown critical chunk");
  167276. png_set_unknown_chunks(png_ptr, info_ptr,
  167277. &png_ptr->unknown_chunk, 1);
  167278. }
  167279. }
  167280. #else
  167281. png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1);
  167282. #endif
  167283. png_free(png_ptr, png_ptr->unknown_chunk.data);
  167284. png_ptr->unknown_chunk.data = NULL;
  167285. }
  167286. else
  167287. #endif
  167288. skip=length;
  167289. png_push_crc_skip(png_ptr, skip);
  167290. }
  167291. void /* PRIVATE */
  167292. png_push_have_info(png_structp png_ptr, png_infop info_ptr)
  167293. {
  167294. if (png_ptr->info_fn != NULL)
  167295. (*(png_ptr->info_fn))(png_ptr, info_ptr);
  167296. }
  167297. void /* PRIVATE */
  167298. png_push_have_end(png_structp png_ptr, png_infop info_ptr)
  167299. {
  167300. if (png_ptr->end_fn != NULL)
  167301. (*(png_ptr->end_fn))(png_ptr, info_ptr);
  167302. }
  167303. void /* PRIVATE */
  167304. png_push_have_row(png_structp png_ptr, png_bytep row)
  167305. {
  167306. if (png_ptr->row_fn != NULL)
  167307. (*(png_ptr->row_fn))(png_ptr, row, png_ptr->row_number,
  167308. (int)png_ptr->pass);
  167309. }
  167310. void PNGAPI
  167311. png_progressive_combine_row (png_structp png_ptr,
  167312. png_bytep old_row, png_bytep new_row)
  167313. {
  167314. #ifdef PNG_USE_LOCAL_ARRAYS
  167315. PNG_CONST int FARDATA png_pass_dsp_mask[7] =
  167316. {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
  167317. #endif
  167318. if(png_ptr == NULL) return;
  167319. if (new_row != NULL) /* new_row must == png_ptr->row_buf here. */
  167320. png_combine_row(png_ptr, old_row, png_pass_dsp_mask[png_ptr->pass]);
  167321. }
  167322. void PNGAPI
  167323. png_set_progressive_read_fn(png_structp png_ptr, png_voidp progressive_ptr,
  167324. png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,
  167325. png_progressive_end_ptr end_fn)
  167326. {
  167327. if(png_ptr == NULL) return;
  167328. png_ptr->info_fn = info_fn;
  167329. png_ptr->row_fn = row_fn;
  167330. png_ptr->end_fn = end_fn;
  167331. png_set_read_fn(png_ptr, progressive_ptr, png_push_fill_buffer);
  167332. }
  167333. png_voidp PNGAPI
  167334. png_get_progressive_ptr(png_structp png_ptr)
  167335. {
  167336. if(png_ptr == NULL) return (NULL);
  167337. return png_ptr->io_ptr;
  167338. }
  167339. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  167340. /*** End of inlined file: pngpread.c ***/
  167341. /*** Start of inlined file: pngrio.c ***/
  167342. #define PNG_INTERNAL
  167343. #if defined(PNG_READ_SUPPORTED)
  167344. void /* PRIVATE */
  167345. png_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  167346. {
  167347. png_debug1(4,"reading %d bytes\n", (int)length);
  167348. if (png_ptr->read_data_fn != NULL)
  167349. (*(png_ptr->read_data_fn))(png_ptr, data, length);
  167350. else
  167351. png_error(png_ptr, "Call to NULL read function");
  167352. }
  167353. #if !defined(PNG_NO_STDIO)
  167354. #ifndef USE_FAR_KEYWORD
  167355. void PNGAPI
  167356. png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  167357. {
  167358. png_size_t check;
  167359. if(png_ptr == NULL) return;
  167360. #if defined(_WIN32_WCE)
  167361. if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  167362. check = 0;
  167363. #else
  167364. check = (png_size_t)fread(data, (png_size_t)1, length,
  167365. (png_FILE_p)png_ptr->io_ptr);
  167366. #endif
  167367. if (check != length)
  167368. png_error(png_ptr, "Read Error");
  167369. }
  167370. #else
  167371. #define NEAR_BUF_SIZE 1024
  167372. #define MIN(a,b) (a <= b ? a : b)
  167373. static void PNGAPI
  167374. png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  167375. {
  167376. int check;
  167377. png_byte *n_data;
  167378. png_FILE_p io_ptr;
  167379. if(png_ptr == NULL) return;
  167380. n_data = (png_byte *)CVT_PTR_NOCHECK(data);
  167381. io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
  167382. if ((png_bytep)n_data == data)
  167383. {
  167384. #if defined(_WIN32_WCE)
  167385. if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  167386. check = 0;
  167387. #else
  167388. check = fread(n_data, 1, length, io_ptr);
  167389. #endif
  167390. }
  167391. else
  167392. {
  167393. png_byte buf[NEAR_BUF_SIZE];
  167394. png_size_t read, remaining, err;
  167395. check = 0;
  167396. remaining = length;
  167397. do
  167398. {
  167399. read = MIN(NEAR_BUF_SIZE, remaining);
  167400. #if defined(_WIN32_WCE)
  167401. if ( !ReadFile((HANDLE)(io_ptr), buf, read, &err, NULL) )
  167402. err = 0;
  167403. #else
  167404. err = fread(buf, (png_size_t)1, read, io_ptr);
  167405. #endif
  167406. png_memcpy(data, buf, read); /* copy far buffer to near buffer */
  167407. if(err != read)
  167408. break;
  167409. else
  167410. check += err;
  167411. data += read;
  167412. remaining -= read;
  167413. }
  167414. while (remaining != 0);
  167415. }
  167416. if ((png_uint_32)check != (png_uint_32)length)
  167417. png_error(png_ptr, "read Error");
  167418. }
  167419. #endif
  167420. #endif
  167421. void PNGAPI
  167422. png_set_read_fn(png_structp png_ptr, png_voidp io_ptr,
  167423. png_rw_ptr read_data_fn)
  167424. {
  167425. if(png_ptr == NULL) return;
  167426. png_ptr->io_ptr = io_ptr;
  167427. #if !defined(PNG_NO_STDIO)
  167428. if (read_data_fn != NULL)
  167429. png_ptr->read_data_fn = read_data_fn;
  167430. else
  167431. png_ptr->read_data_fn = png_default_read_data;
  167432. #else
  167433. png_ptr->read_data_fn = read_data_fn;
  167434. #endif
  167435. if (png_ptr->write_data_fn != NULL)
  167436. {
  167437. png_ptr->write_data_fn = NULL;
  167438. png_warning(png_ptr,
  167439. "It's an error to set both read_data_fn and write_data_fn in the ");
  167440. png_warning(png_ptr,
  167441. "same structure. Resetting write_data_fn to NULL.");
  167442. }
  167443. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  167444. png_ptr->output_flush_fn = NULL;
  167445. #endif
  167446. }
  167447. #endif /* PNG_READ_SUPPORTED */
  167448. /*** End of inlined file: pngrio.c ***/
  167449. /*** Start of inlined file: pngrtran.c ***/
  167450. #define PNG_INTERNAL
  167451. #if defined(PNG_READ_SUPPORTED)
  167452. void PNGAPI
  167453. png_set_crc_action(png_structp png_ptr, int crit_action, int ancil_action)
  167454. {
  167455. png_debug(1, "in png_set_crc_action\n");
  167456. if(png_ptr == NULL) return;
  167457. switch (crit_action)
  167458. {
  167459. case PNG_CRC_NO_CHANGE: /* leave setting as is */
  167460. break;
  167461. case PNG_CRC_WARN_USE: /* warn/use data */
  167462. png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  167463. png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE;
  167464. break;
  167465. case PNG_CRC_QUIET_USE: /* quiet/use data */
  167466. png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  167467. png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE |
  167468. PNG_FLAG_CRC_CRITICAL_IGNORE;
  167469. break;
  167470. case PNG_CRC_WARN_DISCARD: /* not a valid action for critical data */
  167471. png_warning(png_ptr, "Can't discard critical data on CRC error.");
  167472. case PNG_CRC_ERROR_QUIT: /* error/quit */
  167473. case PNG_CRC_DEFAULT:
  167474. default:
  167475. png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  167476. break;
  167477. }
  167478. switch (ancil_action)
  167479. {
  167480. case PNG_CRC_NO_CHANGE: /* leave setting as is */
  167481. break;
  167482. case PNG_CRC_WARN_USE: /* warn/use data */
  167483. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  167484. png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE;
  167485. break;
  167486. case PNG_CRC_QUIET_USE: /* quiet/use data */
  167487. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  167488. png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE |
  167489. PNG_FLAG_CRC_ANCILLARY_NOWARN;
  167490. break;
  167491. case PNG_CRC_ERROR_QUIT: /* error/quit */
  167492. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  167493. png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_NOWARN;
  167494. break;
  167495. case PNG_CRC_WARN_DISCARD: /* warn/discard data */
  167496. case PNG_CRC_DEFAULT:
  167497. default:
  167498. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  167499. break;
  167500. }
  167501. }
  167502. #if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
  167503. defined(PNG_FLOATING_POINT_SUPPORTED)
  167504. void PNGAPI
  167505. png_set_background(png_structp png_ptr,
  167506. png_color_16p background_color, int background_gamma_code,
  167507. int need_expand, double background_gamma)
  167508. {
  167509. png_debug(1, "in png_set_background\n");
  167510. if(png_ptr == NULL) return;
  167511. if (background_gamma_code == PNG_BACKGROUND_GAMMA_UNKNOWN)
  167512. {
  167513. png_warning(png_ptr, "Application must supply a known background gamma");
  167514. return;
  167515. }
  167516. png_ptr->transformations |= PNG_BACKGROUND;
  167517. png_memcpy(&(png_ptr->background), background_color,
  167518. png_sizeof(png_color_16));
  167519. png_ptr->background_gamma = (float)background_gamma;
  167520. png_ptr->background_gamma_type = (png_byte)(background_gamma_code);
  167521. png_ptr->transformations |= (need_expand ? PNG_BACKGROUND_EXPAND : 0);
  167522. }
  167523. #endif
  167524. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  167525. void PNGAPI
  167526. png_set_strip_16(png_structp png_ptr)
  167527. {
  167528. png_debug(1, "in png_set_strip_16\n");
  167529. if(png_ptr == NULL) return;
  167530. png_ptr->transformations |= PNG_16_TO_8;
  167531. }
  167532. #endif
  167533. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  167534. void PNGAPI
  167535. png_set_strip_alpha(png_structp png_ptr)
  167536. {
  167537. png_debug(1, "in png_set_strip_alpha\n");
  167538. if(png_ptr == NULL) return;
  167539. png_ptr->flags |= PNG_FLAG_STRIP_ALPHA;
  167540. }
  167541. #endif
  167542. #if defined(PNG_READ_DITHER_SUPPORTED)
  167543. typedef struct png_dsort_struct
  167544. {
  167545. struct png_dsort_struct FAR * next;
  167546. png_byte left;
  167547. png_byte right;
  167548. } png_dsort;
  167549. typedef png_dsort FAR * png_dsortp;
  167550. typedef png_dsort FAR * FAR * png_dsortpp;
  167551. void PNGAPI
  167552. png_set_dither(png_structp png_ptr, png_colorp palette,
  167553. int num_palette, int maximum_colors, png_uint_16p histogram,
  167554. int full_dither)
  167555. {
  167556. png_debug(1, "in png_set_dither\n");
  167557. if(png_ptr == NULL) return;
  167558. png_ptr->transformations |= PNG_DITHER;
  167559. if (!full_dither)
  167560. {
  167561. int i;
  167562. png_ptr->dither_index = (png_bytep)png_malloc(png_ptr,
  167563. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167564. for (i = 0; i < num_palette; i++)
  167565. png_ptr->dither_index[i] = (png_byte)i;
  167566. }
  167567. if (num_palette > maximum_colors)
  167568. {
  167569. if (histogram != NULL)
  167570. {
  167571. int i;
  167572. png_ptr->dither_sort = (png_bytep)png_malloc(png_ptr,
  167573. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167574. for (i = 0; i < num_palette; i++)
  167575. png_ptr->dither_sort[i] = (png_byte)i;
  167576. for (i = num_palette - 1; i >= maximum_colors; i--)
  167577. {
  167578. int done; /* to stop early if the list is pre-sorted */
  167579. int j;
  167580. done = 1;
  167581. for (j = 0; j < i; j++)
  167582. {
  167583. if (histogram[png_ptr->dither_sort[j]]
  167584. < histogram[png_ptr->dither_sort[j + 1]])
  167585. {
  167586. png_byte t;
  167587. t = png_ptr->dither_sort[j];
  167588. png_ptr->dither_sort[j] = png_ptr->dither_sort[j + 1];
  167589. png_ptr->dither_sort[j + 1] = t;
  167590. done = 0;
  167591. }
  167592. }
  167593. if (done)
  167594. break;
  167595. }
  167596. if (full_dither)
  167597. {
  167598. int j = num_palette;
  167599. for (i = 0; i < maximum_colors; i++)
  167600. {
  167601. if ((int)png_ptr->dither_sort[i] >= maximum_colors)
  167602. {
  167603. do
  167604. j--;
  167605. while ((int)png_ptr->dither_sort[j] >= maximum_colors);
  167606. palette[i] = palette[j];
  167607. }
  167608. }
  167609. }
  167610. else
  167611. {
  167612. int j = num_palette;
  167613. for (i = 0; i < maximum_colors; i++)
  167614. {
  167615. if ((int)png_ptr->dither_sort[i] >= maximum_colors)
  167616. {
  167617. png_color tmp_color;
  167618. do
  167619. j--;
  167620. while ((int)png_ptr->dither_sort[j] >= maximum_colors);
  167621. tmp_color = palette[j];
  167622. palette[j] = palette[i];
  167623. palette[i] = tmp_color;
  167624. png_ptr->dither_index[j] = (png_byte)i;
  167625. png_ptr->dither_index[i] = (png_byte)j;
  167626. }
  167627. }
  167628. for (i = 0; i < num_palette; i++)
  167629. {
  167630. if ((int)png_ptr->dither_index[i] >= maximum_colors)
  167631. {
  167632. int min_d, k, min_k, d_index;
  167633. d_index = png_ptr->dither_index[i];
  167634. min_d = PNG_COLOR_DIST(palette[d_index], palette[0]);
  167635. for (k = 1, min_k = 0; k < maximum_colors; k++)
  167636. {
  167637. int d;
  167638. d = PNG_COLOR_DIST(palette[d_index], palette[k]);
  167639. if (d < min_d)
  167640. {
  167641. min_d = d;
  167642. min_k = k;
  167643. }
  167644. }
  167645. png_ptr->dither_index[i] = (png_byte)min_k;
  167646. }
  167647. }
  167648. }
  167649. png_free(png_ptr, png_ptr->dither_sort);
  167650. png_ptr->dither_sort=NULL;
  167651. }
  167652. else
  167653. {
  167654. int i;
  167655. int max_d;
  167656. int num_new_palette;
  167657. png_dsortp t;
  167658. png_dsortpp hash;
  167659. t=NULL;
  167660. png_ptr->index_to_palette = (png_bytep)png_malloc(png_ptr,
  167661. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167662. png_ptr->palette_to_index = (png_bytep)png_malloc(png_ptr,
  167663. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167664. for (i = 0; i < num_palette; i++)
  167665. {
  167666. png_ptr->index_to_palette[i] = (png_byte)i;
  167667. png_ptr->palette_to_index[i] = (png_byte)i;
  167668. }
  167669. hash = (png_dsortpp)png_malloc(png_ptr, (png_uint_32)(769 *
  167670. png_sizeof (png_dsortp)));
  167671. for (i = 0; i < 769; i++)
  167672. hash[i] = NULL;
  167673. num_new_palette = num_palette;
  167674. max_d = 96;
  167675. while (num_new_palette > maximum_colors)
  167676. {
  167677. for (i = 0; i < num_new_palette - 1; i++)
  167678. {
  167679. int j;
  167680. for (j = i + 1; j < num_new_palette; j++)
  167681. {
  167682. int d;
  167683. d = PNG_COLOR_DIST(palette[i], palette[j]);
  167684. if (d <= max_d)
  167685. {
  167686. t = (png_dsortp)png_malloc_warn(png_ptr,
  167687. (png_uint_32)(png_sizeof(png_dsort)));
  167688. if (t == NULL)
  167689. break;
  167690. t->next = hash[d];
  167691. t->left = (png_byte)i;
  167692. t->right = (png_byte)j;
  167693. hash[d] = t;
  167694. }
  167695. }
  167696. if (t == NULL)
  167697. break;
  167698. }
  167699. if (t != NULL)
  167700. for (i = 0; i <= max_d; i++)
  167701. {
  167702. if (hash[i] != NULL)
  167703. {
  167704. png_dsortp p;
  167705. for (p = hash[i]; p; p = p->next)
  167706. {
  167707. if ((int)png_ptr->index_to_palette[p->left]
  167708. < num_new_palette &&
  167709. (int)png_ptr->index_to_palette[p->right]
  167710. < num_new_palette)
  167711. {
  167712. int j, next_j;
  167713. if (num_new_palette & 0x01)
  167714. {
  167715. j = p->left;
  167716. next_j = p->right;
  167717. }
  167718. else
  167719. {
  167720. j = p->right;
  167721. next_j = p->left;
  167722. }
  167723. num_new_palette--;
  167724. palette[png_ptr->index_to_palette[j]]
  167725. = palette[num_new_palette];
  167726. if (!full_dither)
  167727. {
  167728. int k;
  167729. for (k = 0; k < num_palette; k++)
  167730. {
  167731. if (png_ptr->dither_index[k] ==
  167732. png_ptr->index_to_palette[j])
  167733. png_ptr->dither_index[k] =
  167734. png_ptr->index_to_palette[next_j];
  167735. if ((int)png_ptr->dither_index[k] ==
  167736. num_new_palette)
  167737. png_ptr->dither_index[k] =
  167738. png_ptr->index_to_palette[j];
  167739. }
  167740. }
  167741. png_ptr->index_to_palette[png_ptr->palette_to_index
  167742. [num_new_palette]] = png_ptr->index_to_palette[j];
  167743. png_ptr->palette_to_index[png_ptr->index_to_palette[j]]
  167744. = png_ptr->palette_to_index[num_new_palette];
  167745. png_ptr->index_to_palette[j] = (png_byte)num_new_palette;
  167746. png_ptr->palette_to_index[num_new_palette] = (png_byte)j;
  167747. }
  167748. if (num_new_palette <= maximum_colors)
  167749. break;
  167750. }
  167751. if (num_new_palette <= maximum_colors)
  167752. break;
  167753. }
  167754. }
  167755. for (i = 0; i < 769; i++)
  167756. {
  167757. if (hash[i] != NULL)
  167758. {
  167759. png_dsortp p = hash[i];
  167760. while (p)
  167761. {
  167762. t = p->next;
  167763. png_free(png_ptr, p);
  167764. p = t;
  167765. }
  167766. }
  167767. hash[i] = 0;
  167768. }
  167769. max_d += 96;
  167770. }
  167771. png_free(png_ptr, hash);
  167772. png_free(png_ptr, png_ptr->palette_to_index);
  167773. png_free(png_ptr, png_ptr->index_to_palette);
  167774. png_ptr->palette_to_index=NULL;
  167775. png_ptr->index_to_palette=NULL;
  167776. }
  167777. num_palette = maximum_colors;
  167778. }
  167779. if (png_ptr->palette == NULL)
  167780. {
  167781. png_ptr->palette = palette;
  167782. }
  167783. png_ptr->num_palette = (png_uint_16)num_palette;
  167784. if (full_dither)
  167785. {
  167786. int i;
  167787. png_bytep distance;
  167788. int total_bits = PNG_DITHER_RED_BITS + PNG_DITHER_GREEN_BITS +
  167789. PNG_DITHER_BLUE_BITS;
  167790. int num_red = (1 << PNG_DITHER_RED_BITS);
  167791. int num_green = (1 << PNG_DITHER_GREEN_BITS);
  167792. int num_blue = (1 << PNG_DITHER_BLUE_BITS);
  167793. png_size_t num_entries = ((png_size_t)1 << total_bits);
  167794. png_ptr->palette_lookup = (png_bytep )png_malloc(png_ptr,
  167795. (png_uint_32)(num_entries * png_sizeof (png_byte)));
  167796. png_memset(png_ptr->palette_lookup, 0, num_entries *
  167797. png_sizeof (png_byte));
  167798. distance = (png_bytep)png_malloc(png_ptr, (png_uint_32)(num_entries *
  167799. png_sizeof(png_byte)));
  167800. png_memset(distance, 0xff, num_entries * png_sizeof(png_byte));
  167801. for (i = 0; i < num_palette; i++)
  167802. {
  167803. int ir, ig, ib;
  167804. int r = (palette[i].red >> (8 - PNG_DITHER_RED_BITS));
  167805. int g = (palette[i].green >> (8 - PNG_DITHER_GREEN_BITS));
  167806. int b = (palette[i].blue >> (8 - PNG_DITHER_BLUE_BITS));
  167807. for (ir = 0; ir < num_red; ir++)
  167808. {
  167809. int dr = ((ir > r) ? ir - r : r - ir);
  167810. int index_r = (ir << (PNG_DITHER_BLUE_BITS + PNG_DITHER_GREEN_BITS));
  167811. for (ig = 0; ig < num_green; ig++)
  167812. {
  167813. int dg = ((ig > g) ? ig - g : g - ig);
  167814. int dt = dr + dg;
  167815. int dm = ((dr > dg) ? dr : dg);
  167816. int index_g = index_r | (ig << PNG_DITHER_BLUE_BITS);
  167817. for (ib = 0; ib < num_blue; ib++)
  167818. {
  167819. int d_index = index_g | ib;
  167820. int db = ((ib > b) ? ib - b : b - ib);
  167821. int dmax = ((dm > db) ? dm : db);
  167822. int d = dmax + dt + db;
  167823. if (d < (int)distance[d_index])
  167824. {
  167825. distance[d_index] = (png_byte)d;
  167826. png_ptr->palette_lookup[d_index] = (png_byte)i;
  167827. }
  167828. }
  167829. }
  167830. }
  167831. }
  167832. png_free(png_ptr, distance);
  167833. }
  167834. }
  167835. #endif
  167836. #if defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  167837. void PNGAPI
  167838. png_set_gamma(png_structp png_ptr, double scrn_gamma, double file_gamma)
  167839. {
  167840. png_debug(1, "in png_set_gamma\n");
  167841. if(png_ptr == NULL) return;
  167842. if ((fabs(scrn_gamma * file_gamma - 1.0) > PNG_GAMMA_THRESHOLD) ||
  167843. (png_ptr->color_type & PNG_COLOR_MASK_ALPHA) ||
  167844. (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE))
  167845. png_ptr->transformations |= PNG_GAMMA;
  167846. png_ptr->gamma = (float)file_gamma;
  167847. png_ptr->screen_gamma = (float)scrn_gamma;
  167848. }
  167849. #endif
  167850. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167851. void PNGAPI
  167852. png_set_expand(png_structp png_ptr)
  167853. {
  167854. png_debug(1, "in png_set_expand\n");
  167855. if(png_ptr == NULL) return;
  167856. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167857. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167858. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167859. #endif
  167860. }
  167861. void PNGAPI
  167862. png_set_palette_to_rgb(png_structp png_ptr)
  167863. {
  167864. png_debug(1, "in png_set_palette_to_rgb\n");
  167865. if(png_ptr == NULL) return;
  167866. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167867. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167868. png_ptr->flags &= !(PNG_FLAG_ROW_INIT);
  167869. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167870. #endif
  167871. }
  167872. #if !defined(PNG_1_0_X)
  167873. void PNGAPI
  167874. png_set_expand_gray_1_2_4_to_8(png_structp png_ptr)
  167875. {
  167876. png_debug(1, "in png_set_expand_gray_1_2_4_to_8\n");
  167877. if(png_ptr == NULL) return;
  167878. png_ptr->transformations |= PNG_EXPAND;
  167879. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167880. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167881. #endif
  167882. }
  167883. #endif
  167884. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  167885. void PNGAPI
  167886. png_set_gray_1_2_4_to_8(png_structp png_ptr)
  167887. {
  167888. png_debug(1, "in png_set_gray_1_2_4_to_8\n");
  167889. if(png_ptr == NULL) return;
  167890. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167891. }
  167892. #endif
  167893. void PNGAPI
  167894. png_set_tRNS_to_alpha(png_structp png_ptr)
  167895. {
  167896. png_debug(1, "in png_set_tRNS_to_alpha\n");
  167897. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167898. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167899. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167900. #endif
  167901. }
  167902. #endif /* defined(PNG_READ_EXPAND_SUPPORTED) */
  167903. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  167904. void PNGAPI
  167905. png_set_gray_to_rgb(png_structp png_ptr)
  167906. {
  167907. png_debug(1, "in png_set_gray_to_rgb\n");
  167908. png_ptr->transformations |= PNG_GRAY_TO_RGB;
  167909. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167910. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167911. #endif
  167912. }
  167913. #endif
  167914. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  167915. #if defined(PNG_FLOATING_POINT_SUPPORTED)
  167916. void PNGAPI
  167917. png_set_rgb_to_gray(png_structp png_ptr, int error_action, double red,
  167918. double green)
  167919. {
  167920. int red_fixed = (int)((float)red*100000.0 + 0.5);
  167921. int green_fixed = (int)((float)green*100000.0 + 0.5);
  167922. if(png_ptr == NULL) return;
  167923. png_set_rgb_to_gray_fixed(png_ptr, error_action, red_fixed, green_fixed);
  167924. }
  167925. #endif
  167926. void PNGAPI
  167927. png_set_rgb_to_gray_fixed(png_structp png_ptr, int error_action,
  167928. png_fixed_point red, png_fixed_point green)
  167929. {
  167930. png_debug(1, "in png_set_rgb_to_gray\n");
  167931. if(png_ptr == NULL) return;
  167932. switch(error_action)
  167933. {
  167934. case 1: png_ptr->transformations |= PNG_RGB_TO_GRAY;
  167935. break;
  167936. case 2: png_ptr->transformations |= PNG_RGB_TO_GRAY_WARN;
  167937. break;
  167938. case 3: png_ptr->transformations |= PNG_RGB_TO_GRAY_ERR;
  167939. }
  167940. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  167941. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167942. png_ptr->transformations |= PNG_EXPAND;
  167943. #else
  167944. {
  167945. png_warning(png_ptr, "Cannot do RGB_TO_GRAY without EXPAND_SUPPORTED.");
  167946. png_ptr->transformations &= ~PNG_RGB_TO_GRAY;
  167947. }
  167948. #endif
  167949. {
  167950. png_uint_16 red_int, green_int;
  167951. if(red < 0 || green < 0)
  167952. {
  167953. red_int = 6968; /* .212671 * 32768 + .5 */
  167954. green_int = 23434; /* .715160 * 32768 + .5 */
  167955. }
  167956. else if(red + green < 100000L)
  167957. {
  167958. red_int = (png_uint_16)(((png_uint_32)red*32768L)/100000L);
  167959. green_int = (png_uint_16)(((png_uint_32)green*32768L)/100000L);
  167960. }
  167961. else
  167962. {
  167963. png_warning(png_ptr, "ignoring out of range rgb_to_gray coefficients");
  167964. red_int = 6968;
  167965. green_int = 23434;
  167966. }
  167967. png_ptr->rgb_to_gray_red_coeff = red_int;
  167968. png_ptr->rgb_to_gray_green_coeff = green_int;
  167969. png_ptr->rgb_to_gray_blue_coeff = (png_uint_16)(32768-red_int-green_int);
  167970. }
  167971. }
  167972. #endif
  167973. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  167974. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  167975. defined(PNG_LEGACY_SUPPORTED)
  167976. void PNGAPI
  167977. png_set_read_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
  167978. read_user_transform_fn)
  167979. {
  167980. png_debug(1, "in png_set_read_user_transform_fn\n");
  167981. if(png_ptr == NULL) return;
  167982. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  167983. png_ptr->transformations |= PNG_USER_TRANSFORM;
  167984. png_ptr->read_user_transform_fn = read_user_transform_fn;
  167985. #endif
  167986. #ifdef PNG_LEGACY_SUPPORTED
  167987. if(read_user_transform_fn)
  167988. png_warning(png_ptr,
  167989. "This version of libpng does not support user transforms");
  167990. #endif
  167991. }
  167992. #endif
  167993. void /* PRIVATE */
  167994. png_init_read_transformations(png_structp png_ptr)
  167995. {
  167996. png_debug(1, "in png_init_read_transformations\n");
  167997. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  167998. if(png_ptr != NULL)
  167999. #endif
  168000. {
  168001. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || defined(PNG_READ_SHIFT_SUPPORTED) \
  168002. || defined(PNG_READ_GAMMA_SUPPORTED)
  168003. int color_type = png_ptr->color_type;
  168004. #endif
  168005. #if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED)
  168006. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168007. if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
  168008. !(color_type & PNG_COLOR_MASK_COLOR))
  168009. {
  168010. png_ptr->mode |= PNG_BACKGROUND_IS_GRAY;
  168011. } else if ((png_ptr->transformations & PNG_BACKGROUND) &&
  168012. !(png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
  168013. (png_ptr->transformations & PNG_GRAY_TO_RGB) &&
  168014. png_ptr->background.red == png_ptr->background.green &&
  168015. png_ptr->background.red == png_ptr->background.blue)
  168016. {
  168017. png_ptr->mode |= PNG_BACKGROUND_IS_GRAY;
  168018. png_ptr->background.gray = png_ptr->background.red;
  168019. }
  168020. #endif
  168021. if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
  168022. (png_ptr->transformations & PNG_EXPAND))
  168023. {
  168024. if (!(color_type & PNG_COLOR_MASK_COLOR)) /* i.e., GRAY or GRAY_ALPHA */
  168025. {
  168026. switch (png_ptr->bit_depth)
  168027. {
  168028. case 1:
  168029. png_ptr->background.gray *= (png_uint_16)0xff;
  168030. png_ptr->background.red = png_ptr->background.green
  168031. = png_ptr->background.blue = png_ptr->background.gray;
  168032. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  168033. {
  168034. png_ptr->trans_values.gray *= (png_uint_16)0xff;
  168035. png_ptr->trans_values.red = png_ptr->trans_values.green
  168036. = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
  168037. }
  168038. break;
  168039. case 2:
  168040. png_ptr->background.gray *= (png_uint_16)0x55;
  168041. png_ptr->background.red = png_ptr->background.green
  168042. = png_ptr->background.blue = png_ptr->background.gray;
  168043. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  168044. {
  168045. png_ptr->trans_values.gray *= (png_uint_16)0x55;
  168046. png_ptr->trans_values.red = png_ptr->trans_values.green
  168047. = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
  168048. }
  168049. break;
  168050. case 4:
  168051. png_ptr->background.gray *= (png_uint_16)0x11;
  168052. png_ptr->background.red = png_ptr->background.green
  168053. = png_ptr->background.blue = png_ptr->background.gray;
  168054. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  168055. {
  168056. png_ptr->trans_values.gray *= (png_uint_16)0x11;
  168057. png_ptr->trans_values.red = png_ptr->trans_values.green
  168058. = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
  168059. }
  168060. break;
  168061. case 8:
  168062. case 16:
  168063. png_ptr->background.red = png_ptr->background.green
  168064. = png_ptr->background.blue = png_ptr->background.gray;
  168065. break;
  168066. }
  168067. }
  168068. else if (color_type == PNG_COLOR_TYPE_PALETTE)
  168069. {
  168070. png_ptr->background.red =
  168071. png_ptr->palette[png_ptr->background.index].red;
  168072. png_ptr->background.green =
  168073. png_ptr->palette[png_ptr->background.index].green;
  168074. png_ptr->background.blue =
  168075. png_ptr->palette[png_ptr->background.index].blue;
  168076. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  168077. if (png_ptr->transformations & PNG_INVERT_ALPHA)
  168078. {
  168079. #if defined(PNG_READ_EXPAND_SUPPORTED)
  168080. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  168081. #endif
  168082. {
  168083. int i,istop;
  168084. istop=(int)png_ptr->num_trans;
  168085. for (i=0; i<istop; i++)
  168086. png_ptr->trans[i] = (png_byte)(255 - png_ptr->trans[i]);
  168087. }
  168088. }
  168089. #endif
  168090. }
  168091. }
  168092. #endif
  168093. #if defined(PNG_READ_BACKGROUND_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED)
  168094. png_ptr->background_1 = png_ptr->background;
  168095. #endif
  168096. #if defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  168097. if ((color_type == PNG_COLOR_TYPE_PALETTE && png_ptr->num_trans != 0)
  168098. && (fabs(png_ptr->screen_gamma * png_ptr->gamma - 1.0)
  168099. < PNG_GAMMA_THRESHOLD))
  168100. {
  168101. int i,k;
  168102. k=0;
  168103. for (i=0; i<png_ptr->num_trans; i++)
  168104. {
  168105. if (png_ptr->trans[i] != 0 && png_ptr->trans[i] != 0xff)
  168106. k=1; /* partial transparency is present */
  168107. }
  168108. if (k == 0)
  168109. png_ptr->transformations &= (~PNG_GAMMA);
  168110. }
  168111. if ((png_ptr->transformations & (PNG_GAMMA | PNG_RGB_TO_GRAY)) &&
  168112. png_ptr->gamma != 0.0)
  168113. {
  168114. png_build_gamma_table(png_ptr);
  168115. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168116. if (png_ptr->transformations & PNG_BACKGROUND)
  168117. {
  168118. if (color_type == PNG_COLOR_TYPE_PALETTE)
  168119. {
  168120. png_color back, back_1;
  168121. png_colorp palette = png_ptr->palette;
  168122. int num_palette = png_ptr->num_palette;
  168123. int i;
  168124. if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE)
  168125. {
  168126. back.red = png_ptr->gamma_table[png_ptr->background.red];
  168127. back.green = png_ptr->gamma_table[png_ptr->background.green];
  168128. back.blue = png_ptr->gamma_table[png_ptr->background.blue];
  168129. back_1.red = png_ptr->gamma_to_1[png_ptr->background.red];
  168130. back_1.green = png_ptr->gamma_to_1[png_ptr->background.green];
  168131. back_1.blue = png_ptr->gamma_to_1[png_ptr->background.blue];
  168132. }
  168133. else
  168134. {
  168135. double g, gs;
  168136. switch (png_ptr->background_gamma_type)
  168137. {
  168138. case PNG_BACKGROUND_GAMMA_SCREEN:
  168139. g = (png_ptr->screen_gamma);
  168140. gs = 1.0;
  168141. break;
  168142. case PNG_BACKGROUND_GAMMA_FILE:
  168143. g = 1.0 / (png_ptr->gamma);
  168144. gs = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  168145. break;
  168146. case PNG_BACKGROUND_GAMMA_UNIQUE:
  168147. g = 1.0 / (png_ptr->background_gamma);
  168148. gs = 1.0 / (png_ptr->background_gamma *
  168149. png_ptr->screen_gamma);
  168150. break;
  168151. default:
  168152. g = 1.0; /* back_1 */
  168153. gs = 1.0; /* back */
  168154. }
  168155. if ( fabs(gs - 1.0) < PNG_GAMMA_THRESHOLD)
  168156. {
  168157. back.red = (png_byte)png_ptr->background.red;
  168158. back.green = (png_byte)png_ptr->background.green;
  168159. back.blue = (png_byte)png_ptr->background.blue;
  168160. }
  168161. else
  168162. {
  168163. back.red = (png_byte)(pow(
  168164. (double)png_ptr->background.red/255, gs) * 255.0 + .5);
  168165. back.green = (png_byte)(pow(
  168166. (double)png_ptr->background.green/255, gs) * 255.0 + .5);
  168167. back.blue = (png_byte)(pow(
  168168. (double)png_ptr->background.blue/255, gs) * 255.0 + .5);
  168169. }
  168170. back_1.red = (png_byte)(pow(
  168171. (double)png_ptr->background.red/255, g) * 255.0 + .5);
  168172. back_1.green = (png_byte)(pow(
  168173. (double)png_ptr->background.green/255, g) * 255.0 + .5);
  168174. back_1.blue = (png_byte)(pow(
  168175. (double)png_ptr->background.blue/255, g) * 255.0 + .5);
  168176. }
  168177. for (i = 0; i < num_palette; i++)
  168178. {
  168179. if (i < (int)png_ptr->num_trans && png_ptr->trans[i] != 0xff)
  168180. {
  168181. if (png_ptr->trans[i] == 0)
  168182. {
  168183. palette[i] = back;
  168184. }
  168185. else /* if (png_ptr->trans[i] != 0xff) */
  168186. {
  168187. png_byte v, w;
  168188. v = png_ptr->gamma_to_1[palette[i].red];
  168189. png_composite(w, v, png_ptr->trans[i], back_1.red);
  168190. palette[i].red = png_ptr->gamma_from_1[w];
  168191. v = png_ptr->gamma_to_1[palette[i].green];
  168192. png_composite(w, v, png_ptr->trans[i], back_1.green);
  168193. palette[i].green = png_ptr->gamma_from_1[w];
  168194. v = png_ptr->gamma_to_1[palette[i].blue];
  168195. png_composite(w, v, png_ptr->trans[i], back_1.blue);
  168196. palette[i].blue = png_ptr->gamma_from_1[w];
  168197. }
  168198. }
  168199. else
  168200. {
  168201. palette[i].red = png_ptr->gamma_table[palette[i].red];
  168202. palette[i].green = png_ptr->gamma_table[palette[i].green];
  168203. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  168204. }
  168205. }
  168206. }
  168207. else
  168208. {
  168209. double m = (double)(((png_uint_32)1 << png_ptr->bit_depth) - 1);
  168210. double g = 1.0;
  168211. double gs = 1.0;
  168212. switch (png_ptr->background_gamma_type)
  168213. {
  168214. case PNG_BACKGROUND_GAMMA_SCREEN:
  168215. g = (png_ptr->screen_gamma);
  168216. gs = 1.0;
  168217. break;
  168218. case PNG_BACKGROUND_GAMMA_FILE:
  168219. g = 1.0 / (png_ptr->gamma);
  168220. gs = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  168221. break;
  168222. case PNG_BACKGROUND_GAMMA_UNIQUE:
  168223. g = 1.0 / (png_ptr->background_gamma);
  168224. gs = 1.0 / (png_ptr->background_gamma *
  168225. png_ptr->screen_gamma);
  168226. break;
  168227. }
  168228. png_ptr->background_1.gray = (png_uint_16)(pow(
  168229. (double)png_ptr->background.gray / m, g) * m + .5);
  168230. png_ptr->background.gray = (png_uint_16)(pow(
  168231. (double)png_ptr->background.gray / m, gs) * m + .5);
  168232. if ((png_ptr->background.red != png_ptr->background.green) ||
  168233. (png_ptr->background.red != png_ptr->background.blue) ||
  168234. (png_ptr->background.red != png_ptr->background.gray))
  168235. {
  168236. png_ptr->background_1.red = (png_uint_16)(pow(
  168237. (double)png_ptr->background.red / m, g) * m + .5);
  168238. png_ptr->background_1.green = (png_uint_16)(pow(
  168239. (double)png_ptr->background.green / m, g) * m + .5);
  168240. png_ptr->background_1.blue = (png_uint_16)(pow(
  168241. (double)png_ptr->background.blue / m, g) * m + .5);
  168242. png_ptr->background.red = (png_uint_16)(pow(
  168243. (double)png_ptr->background.red / m, gs) * m + .5);
  168244. png_ptr->background.green = (png_uint_16)(pow(
  168245. (double)png_ptr->background.green / m, gs) * m + .5);
  168246. png_ptr->background.blue = (png_uint_16)(pow(
  168247. (double)png_ptr->background.blue / m, gs) * m + .5);
  168248. }
  168249. else
  168250. {
  168251. png_ptr->background_1.red = png_ptr->background_1.green
  168252. = png_ptr->background_1.blue = png_ptr->background_1.gray;
  168253. png_ptr->background.red = png_ptr->background.green
  168254. = png_ptr->background.blue = png_ptr->background.gray;
  168255. }
  168256. }
  168257. }
  168258. else
  168259. #endif /* PNG_READ_BACKGROUND_SUPPORTED */
  168260. if (color_type == PNG_COLOR_TYPE_PALETTE)
  168261. {
  168262. png_colorp palette = png_ptr->palette;
  168263. int num_palette = png_ptr->num_palette;
  168264. int i;
  168265. for (i = 0; i < num_palette; i++)
  168266. {
  168267. palette[i].red = png_ptr->gamma_table[palette[i].red];
  168268. palette[i].green = png_ptr->gamma_table[palette[i].green];
  168269. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  168270. }
  168271. }
  168272. }
  168273. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168274. else
  168275. #endif
  168276. #endif /* PNG_READ_GAMMA_SUPPORTED && PNG_FLOATING_POINT_SUPPORTED */
  168277. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168278. if ((png_ptr->transformations & PNG_BACKGROUND) &&
  168279. (color_type == PNG_COLOR_TYPE_PALETTE))
  168280. {
  168281. int i;
  168282. int istop = (int)png_ptr->num_trans;
  168283. png_color back;
  168284. png_colorp palette = png_ptr->palette;
  168285. back.red = (png_byte)png_ptr->background.red;
  168286. back.green = (png_byte)png_ptr->background.green;
  168287. back.blue = (png_byte)png_ptr->background.blue;
  168288. for (i = 0; i < istop; i++)
  168289. {
  168290. if (png_ptr->trans[i] == 0)
  168291. {
  168292. palette[i] = back;
  168293. }
  168294. else if (png_ptr->trans[i] != 0xff)
  168295. {
  168296. png_composite(palette[i].red, palette[i].red,
  168297. png_ptr->trans[i], back.red);
  168298. png_composite(palette[i].green, palette[i].green,
  168299. png_ptr->trans[i], back.green);
  168300. png_composite(palette[i].blue, palette[i].blue,
  168301. png_ptr->trans[i], back.blue);
  168302. }
  168303. }
  168304. }
  168305. #endif /* PNG_READ_BACKGROUND_SUPPORTED */
  168306. #if defined(PNG_READ_SHIFT_SUPPORTED)
  168307. if ((png_ptr->transformations & PNG_SHIFT) &&
  168308. (color_type == PNG_COLOR_TYPE_PALETTE))
  168309. {
  168310. png_uint_16 i;
  168311. png_uint_16 istop = png_ptr->num_palette;
  168312. int sr = 8 - png_ptr->sig_bit.red;
  168313. int sg = 8 - png_ptr->sig_bit.green;
  168314. int sb = 8 - png_ptr->sig_bit.blue;
  168315. if (sr < 0 || sr > 8)
  168316. sr = 0;
  168317. if (sg < 0 || sg > 8)
  168318. sg = 0;
  168319. if (sb < 0 || sb > 8)
  168320. sb = 0;
  168321. for (i = 0; i < istop; i++)
  168322. {
  168323. png_ptr->palette[i].red >>= sr;
  168324. png_ptr->palette[i].green >>= sg;
  168325. png_ptr->palette[i].blue >>= sb;
  168326. }
  168327. }
  168328. #endif /* PNG_READ_SHIFT_SUPPORTED */
  168329. }
  168330. #if !defined(PNG_READ_GAMMA_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED) \
  168331. && !defined(PNG_READ_BACKGROUND_SUPPORTED)
  168332. if(png_ptr)
  168333. return;
  168334. #endif
  168335. }
  168336. void /* PRIVATE */
  168337. png_read_transform_info(png_structp png_ptr, png_infop info_ptr)
  168338. {
  168339. png_debug(1, "in png_read_transform_info\n");
  168340. #if defined(PNG_READ_EXPAND_SUPPORTED)
  168341. if (png_ptr->transformations & PNG_EXPAND)
  168342. {
  168343. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  168344. {
  168345. if (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND_tRNS))
  168346. info_ptr->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
  168347. else
  168348. info_ptr->color_type = PNG_COLOR_TYPE_RGB;
  168349. info_ptr->bit_depth = 8;
  168350. info_ptr->num_trans = 0;
  168351. }
  168352. else
  168353. {
  168354. if (png_ptr->num_trans)
  168355. {
  168356. if (png_ptr->transformations & PNG_EXPAND_tRNS)
  168357. info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
  168358. else
  168359. info_ptr->color_type |= PNG_COLOR_MASK_COLOR;
  168360. }
  168361. if (info_ptr->bit_depth < 8)
  168362. info_ptr->bit_depth = 8;
  168363. info_ptr->num_trans = 0;
  168364. }
  168365. }
  168366. #endif
  168367. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168368. if (png_ptr->transformations & PNG_BACKGROUND)
  168369. {
  168370. info_ptr->color_type &= ~PNG_COLOR_MASK_ALPHA;
  168371. info_ptr->num_trans = 0;
  168372. info_ptr->background = png_ptr->background;
  168373. }
  168374. #endif
  168375. #if defined(PNG_READ_GAMMA_SUPPORTED)
  168376. if (png_ptr->transformations & PNG_GAMMA)
  168377. {
  168378. #ifdef PNG_FLOATING_POINT_SUPPORTED
  168379. info_ptr->gamma = png_ptr->gamma;
  168380. #endif
  168381. #ifdef PNG_FIXED_POINT_SUPPORTED
  168382. info_ptr->int_gamma = png_ptr->int_gamma;
  168383. #endif
  168384. }
  168385. #endif
  168386. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  168387. if ((png_ptr->transformations & PNG_16_TO_8) && (info_ptr->bit_depth == 16))
  168388. info_ptr->bit_depth = 8;
  168389. #endif
  168390. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168391. if (png_ptr->transformations & PNG_GRAY_TO_RGB)
  168392. info_ptr->color_type |= PNG_COLOR_MASK_COLOR;
  168393. #endif
  168394. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  168395. if (png_ptr->transformations & PNG_RGB_TO_GRAY)
  168396. info_ptr->color_type &= ~PNG_COLOR_MASK_COLOR;
  168397. #endif
  168398. #if defined(PNG_READ_DITHER_SUPPORTED)
  168399. if (png_ptr->transformations & PNG_DITHER)
  168400. {
  168401. if (((info_ptr->color_type == PNG_COLOR_TYPE_RGB) ||
  168402. (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)) &&
  168403. png_ptr->palette_lookup && info_ptr->bit_depth == 8)
  168404. {
  168405. info_ptr->color_type = PNG_COLOR_TYPE_PALETTE;
  168406. }
  168407. }
  168408. #endif
  168409. #if defined(PNG_READ_PACK_SUPPORTED)
  168410. if ((png_ptr->transformations & PNG_PACK) && (info_ptr->bit_depth < 8))
  168411. info_ptr->bit_depth = 8;
  168412. #endif
  168413. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  168414. info_ptr->channels = 1;
  168415. else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
  168416. info_ptr->channels = 3;
  168417. else
  168418. info_ptr->channels = 1;
  168419. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  168420. if (png_ptr->flags & PNG_FLAG_STRIP_ALPHA)
  168421. info_ptr->color_type &= ~PNG_COLOR_MASK_ALPHA;
  168422. #endif
  168423. if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
  168424. info_ptr->channels++;
  168425. #if defined(PNG_READ_FILLER_SUPPORTED)
  168426. if ((png_ptr->transformations & PNG_FILLER) &&
  168427. ((info_ptr->color_type == PNG_COLOR_TYPE_RGB) ||
  168428. (info_ptr->color_type == PNG_COLOR_TYPE_GRAY)))
  168429. {
  168430. info_ptr->channels++;
  168431. #if !defined(PNG_1_0_X)
  168432. if (png_ptr->transformations & PNG_ADD_ALPHA)
  168433. info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
  168434. #endif
  168435. }
  168436. #endif
  168437. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) && \
  168438. defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  168439. if(png_ptr->transformations & PNG_USER_TRANSFORM)
  168440. {
  168441. if(info_ptr->bit_depth < png_ptr->user_transform_depth)
  168442. info_ptr->bit_depth = png_ptr->user_transform_depth;
  168443. if(info_ptr->channels < png_ptr->user_transform_channels)
  168444. info_ptr->channels = png_ptr->user_transform_channels;
  168445. }
  168446. #endif
  168447. info_ptr->pixel_depth = (png_byte)(info_ptr->channels *
  168448. info_ptr->bit_depth);
  168449. info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth,info_ptr->width);
  168450. #if !defined(PNG_READ_EXPAND_SUPPORTED)
  168451. if(png_ptr)
  168452. return;
  168453. #endif
  168454. }
  168455. void /* PRIVATE */
  168456. png_do_read_transformations(png_structp png_ptr)
  168457. {
  168458. png_debug(1, "in png_do_read_transformations\n");
  168459. if (png_ptr->row_buf == NULL)
  168460. {
  168461. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  168462. char msg[50];
  168463. png_snprintf2(msg, 50,
  168464. "NULL row buffer for row %ld, pass %d", png_ptr->row_number,
  168465. png_ptr->pass);
  168466. png_error(png_ptr, msg);
  168467. #else
  168468. png_error(png_ptr, "NULL row buffer");
  168469. #endif
  168470. }
  168471. #ifdef PNG_WARN_UNINITIALIZED_ROW
  168472. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  168473. #if (PNG_WARN_UNINITIALIZED_ROW==1)
  168474. png_error(png_ptr, "Uninitialized row");
  168475. #else
  168476. png_warning(png_ptr, "Uninitialized row");
  168477. #endif
  168478. #endif
  168479. #if defined(PNG_READ_EXPAND_SUPPORTED)
  168480. if (png_ptr->transformations & PNG_EXPAND)
  168481. {
  168482. if (png_ptr->row_info.color_type == PNG_COLOR_TYPE_PALETTE)
  168483. {
  168484. png_do_expand_palette(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168485. png_ptr->palette, png_ptr->trans, png_ptr->num_trans);
  168486. }
  168487. else
  168488. {
  168489. if (png_ptr->num_trans &&
  168490. (png_ptr->transformations & PNG_EXPAND_tRNS))
  168491. png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168492. &(png_ptr->trans_values));
  168493. else
  168494. png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168495. NULL);
  168496. }
  168497. }
  168498. #endif
  168499. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  168500. if (png_ptr->flags & PNG_FLAG_STRIP_ALPHA)
  168501. png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168502. PNG_FLAG_FILLER_AFTER | (png_ptr->flags & PNG_FLAG_STRIP_ALPHA));
  168503. #endif
  168504. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  168505. if (png_ptr->transformations & PNG_RGB_TO_GRAY)
  168506. {
  168507. int rgb_error =
  168508. png_do_rgb_to_gray(png_ptr, &(png_ptr->row_info), png_ptr->row_buf + 1);
  168509. if(rgb_error)
  168510. {
  168511. png_ptr->rgb_to_gray_status=1;
  168512. if((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
  168513. PNG_RGB_TO_GRAY_WARN)
  168514. png_warning(png_ptr, "png_do_rgb_to_gray found nongray pixel");
  168515. if((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
  168516. PNG_RGB_TO_GRAY_ERR)
  168517. png_error(png_ptr, "png_do_rgb_to_gray found nongray pixel");
  168518. }
  168519. }
  168520. #endif
  168521. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168522. if ((png_ptr->transformations & PNG_GRAY_TO_RGB) &&
  168523. !(png_ptr->mode & PNG_BACKGROUND_IS_GRAY))
  168524. png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168525. #endif
  168526. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168527. if ((png_ptr->transformations & PNG_BACKGROUND) &&
  168528. ((png_ptr->num_trans != 0 ) ||
  168529. (png_ptr->color_type & PNG_COLOR_MASK_ALPHA)))
  168530. png_do_background(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168531. &(png_ptr->trans_values), &(png_ptr->background)
  168532. #if defined(PNG_READ_GAMMA_SUPPORTED)
  168533. , &(png_ptr->background_1),
  168534. png_ptr->gamma_table, png_ptr->gamma_from_1,
  168535. png_ptr->gamma_to_1, png_ptr->gamma_16_table,
  168536. png_ptr->gamma_16_from_1, png_ptr->gamma_16_to_1,
  168537. png_ptr->gamma_shift
  168538. #endif
  168539. );
  168540. #endif
  168541. #if defined(PNG_READ_GAMMA_SUPPORTED)
  168542. if ((png_ptr->transformations & PNG_GAMMA) &&
  168543. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168544. !((png_ptr->transformations & PNG_BACKGROUND) &&
  168545. ((png_ptr->num_trans != 0) ||
  168546. (png_ptr->color_type & PNG_COLOR_MASK_ALPHA))) &&
  168547. #endif
  168548. (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE))
  168549. png_do_gamma(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168550. png_ptr->gamma_table, png_ptr->gamma_16_table,
  168551. png_ptr->gamma_shift);
  168552. #endif
  168553. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  168554. if (png_ptr->transformations & PNG_16_TO_8)
  168555. png_do_chop(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168556. #endif
  168557. #if defined(PNG_READ_DITHER_SUPPORTED)
  168558. if (png_ptr->transformations & PNG_DITHER)
  168559. {
  168560. png_do_dither((png_row_infop)&(png_ptr->row_info), png_ptr->row_buf + 1,
  168561. png_ptr->palette_lookup, png_ptr->dither_index);
  168562. if(png_ptr->row_info.rowbytes == (png_uint_32)0)
  168563. png_error(png_ptr, "png_do_dither returned rowbytes=0");
  168564. }
  168565. #endif
  168566. #if defined(PNG_READ_INVERT_SUPPORTED)
  168567. if (png_ptr->transformations & PNG_INVERT_MONO)
  168568. png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168569. #endif
  168570. #if defined(PNG_READ_SHIFT_SUPPORTED)
  168571. if (png_ptr->transformations & PNG_SHIFT)
  168572. png_do_unshift(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168573. &(png_ptr->shift));
  168574. #endif
  168575. #if defined(PNG_READ_PACK_SUPPORTED)
  168576. if (png_ptr->transformations & PNG_PACK)
  168577. png_do_unpack(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168578. #endif
  168579. #if defined(PNG_READ_BGR_SUPPORTED)
  168580. if (png_ptr->transformations & PNG_BGR)
  168581. png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168582. #endif
  168583. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  168584. if (png_ptr->transformations & PNG_PACKSWAP)
  168585. png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168586. #endif
  168587. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168588. if ((png_ptr->transformations & PNG_GRAY_TO_RGB) &&
  168589. (png_ptr->mode & PNG_BACKGROUND_IS_GRAY))
  168590. png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168591. #endif
  168592. #if defined(PNG_READ_FILLER_SUPPORTED)
  168593. if (png_ptr->transformations & PNG_FILLER)
  168594. png_do_read_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168595. (png_uint_32)png_ptr->filler, png_ptr->flags);
  168596. #endif
  168597. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  168598. if (png_ptr->transformations & PNG_INVERT_ALPHA)
  168599. png_do_read_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168600. #endif
  168601. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  168602. if (png_ptr->transformations & PNG_SWAP_ALPHA)
  168603. png_do_read_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168604. #endif
  168605. #if defined(PNG_READ_SWAP_SUPPORTED)
  168606. if (png_ptr->transformations & PNG_SWAP_BYTES)
  168607. png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168608. #endif
  168609. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  168610. if (png_ptr->transformations & PNG_USER_TRANSFORM)
  168611. {
  168612. if(png_ptr->read_user_transform_fn != NULL)
  168613. (*(png_ptr->read_user_transform_fn)) /* user read transform function */
  168614. (png_ptr, /* png_ptr */
  168615. &(png_ptr->row_info), /* row_info: */
  168616. png_ptr->row_buf + 1); /* start of pixel data for row */
  168617. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  168618. if(png_ptr->user_transform_depth)
  168619. png_ptr->row_info.bit_depth = png_ptr->user_transform_depth;
  168620. if(png_ptr->user_transform_channels)
  168621. png_ptr->row_info.channels = png_ptr->user_transform_channels;
  168622. #endif
  168623. png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth *
  168624. png_ptr->row_info.channels);
  168625. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  168626. png_ptr->row_info.width);
  168627. }
  168628. #endif
  168629. }
  168630. #if defined(PNG_READ_PACK_SUPPORTED)
  168631. void /* PRIVATE */
  168632. png_do_unpack(png_row_infop row_info, png_bytep row)
  168633. {
  168634. png_debug(1, "in png_do_unpack\n");
  168635. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168636. if (row != NULL && row_info != NULL && row_info->bit_depth < 8)
  168637. #else
  168638. if (row_info->bit_depth < 8)
  168639. #endif
  168640. {
  168641. png_uint_32 i;
  168642. png_uint_32 row_width=row_info->width;
  168643. switch (row_info->bit_depth)
  168644. {
  168645. case 1:
  168646. {
  168647. png_bytep sp = row + (png_size_t)((row_width - 1) >> 3);
  168648. png_bytep dp = row + (png_size_t)row_width - 1;
  168649. png_uint_32 shift = 7 - (int)((row_width + 7) & 0x07);
  168650. for (i = 0; i < row_width; i++)
  168651. {
  168652. *dp = (png_byte)((*sp >> shift) & 0x01);
  168653. if (shift == 7)
  168654. {
  168655. shift = 0;
  168656. sp--;
  168657. }
  168658. else
  168659. shift++;
  168660. dp--;
  168661. }
  168662. break;
  168663. }
  168664. case 2:
  168665. {
  168666. png_bytep sp = row + (png_size_t)((row_width - 1) >> 2);
  168667. png_bytep dp = row + (png_size_t)row_width - 1;
  168668. png_uint_32 shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
  168669. for (i = 0; i < row_width; i++)
  168670. {
  168671. *dp = (png_byte)((*sp >> shift) & 0x03);
  168672. if (shift == 6)
  168673. {
  168674. shift = 0;
  168675. sp--;
  168676. }
  168677. else
  168678. shift += 2;
  168679. dp--;
  168680. }
  168681. break;
  168682. }
  168683. case 4:
  168684. {
  168685. png_bytep sp = row + (png_size_t)((row_width - 1) >> 1);
  168686. png_bytep dp = row + (png_size_t)row_width - 1;
  168687. png_uint_32 shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);
  168688. for (i = 0; i < row_width; i++)
  168689. {
  168690. *dp = (png_byte)((*sp >> shift) & 0x0f);
  168691. if (shift == 4)
  168692. {
  168693. shift = 0;
  168694. sp--;
  168695. }
  168696. else
  168697. shift = 4;
  168698. dp--;
  168699. }
  168700. break;
  168701. }
  168702. }
  168703. row_info->bit_depth = 8;
  168704. row_info->pixel_depth = (png_byte)(8 * row_info->channels);
  168705. row_info->rowbytes = row_width * row_info->channels;
  168706. }
  168707. }
  168708. #endif
  168709. #if defined(PNG_READ_SHIFT_SUPPORTED)
  168710. void /* PRIVATE */
  168711. png_do_unshift(png_row_infop row_info, png_bytep row, png_color_8p sig_bits)
  168712. {
  168713. png_debug(1, "in png_do_unshift\n");
  168714. if (
  168715. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168716. row != NULL && row_info != NULL && sig_bits != NULL &&
  168717. #endif
  168718. row_info->color_type != PNG_COLOR_TYPE_PALETTE)
  168719. {
  168720. int shift[4];
  168721. int channels = 0;
  168722. int c;
  168723. png_uint_16 value = 0;
  168724. png_uint_32 row_width = row_info->width;
  168725. if (row_info->color_type & PNG_COLOR_MASK_COLOR)
  168726. {
  168727. shift[channels++] = row_info->bit_depth - sig_bits->red;
  168728. shift[channels++] = row_info->bit_depth - sig_bits->green;
  168729. shift[channels++] = row_info->bit_depth - sig_bits->blue;
  168730. }
  168731. else
  168732. {
  168733. shift[channels++] = row_info->bit_depth - sig_bits->gray;
  168734. }
  168735. if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
  168736. {
  168737. shift[channels++] = row_info->bit_depth - sig_bits->alpha;
  168738. }
  168739. for (c = 0; c < channels; c++)
  168740. {
  168741. if (shift[c] <= 0)
  168742. shift[c] = 0;
  168743. else
  168744. value = 1;
  168745. }
  168746. if (!value)
  168747. return;
  168748. switch (row_info->bit_depth)
  168749. {
  168750. case 2:
  168751. {
  168752. png_bytep bp;
  168753. png_uint_32 i;
  168754. png_uint_32 istop = row_info->rowbytes;
  168755. for (bp = row, i = 0; i < istop; i++)
  168756. {
  168757. *bp >>= 1;
  168758. *bp++ &= 0x55;
  168759. }
  168760. break;
  168761. }
  168762. case 4:
  168763. {
  168764. png_bytep bp = row;
  168765. png_uint_32 i;
  168766. png_uint_32 istop = row_info->rowbytes;
  168767. png_byte mask = (png_byte)((((int)0xf0 >> shift[0]) & (int)0xf0) |
  168768. (png_byte)((int)0xf >> shift[0]));
  168769. for (i = 0; i < istop; i++)
  168770. {
  168771. *bp >>= shift[0];
  168772. *bp++ &= mask;
  168773. }
  168774. break;
  168775. }
  168776. case 8:
  168777. {
  168778. png_bytep bp = row;
  168779. png_uint_32 i;
  168780. png_uint_32 istop = row_width * channels;
  168781. for (i = 0; i < istop; i++)
  168782. {
  168783. *bp++ >>= shift[i%channels];
  168784. }
  168785. break;
  168786. }
  168787. case 16:
  168788. {
  168789. png_bytep bp = row;
  168790. png_uint_32 i;
  168791. png_uint_32 istop = channels * row_width;
  168792. for (i = 0; i < istop; i++)
  168793. {
  168794. value = (png_uint_16)((*bp << 8) + *(bp + 1));
  168795. value >>= shift[i%channels];
  168796. *bp++ = (png_byte)(value >> 8);
  168797. *bp++ = (png_byte)(value & 0xff);
  168798. }
  168799. break;
  168800. }
  168801. }
  168802. }
  168803. }
  168804. #endif
  168805. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  168806. void /* PRIVATE */
  168807. png_do_chop(png_row_infop row_info, png_bytep row)
  168808. {
  168809. png_debug(1, "in png_do_chop\n");
  168810. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168811. if (row != NULL && row_info != NULL && row_info->bit_depth == 16)
  168812. #else
  168813. if (row_info->bit_depth == 16)
  168814. #endif
  168815. {
  168816. png_bytep sp = row;
  168817. png_bytep dp = row;
  168818. png_uint_32 i;
  168819. png_uint_32 istop = row_info->width * row_info->channels;
  168820. for (i = 0; i<istop; i++, sp += 2, dp++)
  168821. {
  168822. #if defined(PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED)
  168823. *dp = *sp + ((((int)(*(sp + 1)) - *sp) > 128) ? 1 : 0);
  168824. #else
  168825. *dp = *sp;
  168826. #endif
  168827. }
  168828. row_info->bit_depth = 8;
  168829. row_info->pixel_depth = (png_byte)(8 * row_info->channels);
  168830. row_info->rowbytes = row_info->width * row_info->channels;
  168831. }
  168832. }
  168833. #endif
  168834. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  168835. void /* PRIVATE */
  168836. png_do_read_swap_alpha(png_row_infop row_info, png_bytep row)
  168837. {
  168838. png_debug(1, "in png_do_read_swap_alpha\n");
  168839. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168840. if (row != NULL && row_info != NULL)
  168841. #endif
  168842. {
  168843. png_uint_32 row_width = row_info->width;
  168844. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  168845. {
  168846. if (row_info->bit_depth == 8)
  168847. {
  168848. png_bytep sp = row + row_info->rowbytes;
  168849. png_bytep dp = sp;
  168850. png_byte save;
  168851. png_uint_32 i;
  168852. for (i = 0; i < row_width; i++)
  168853. {
  168854. save = *(--sp);
  168855. *(--dp) = *(--sp);
  168856. *(--dp) = *(--sp);
  168857. *(--dp) = *(--sp);
  168858. *(--dp) = save;
  168859. }
  168860. }
  168861. else
  168862. {
  168863. png_bytep sp = row + row_info->rowbytes;
  168864. png_bytep dp = sp;
  168865. png_byte save[2];
  168866. png_uint_32 i;
  168867. for (i = 0; i < row_width; i++)
  168868. {
  168869. save[0] = *(--sp);
  168870. save[1] = *(--sp);
  168871. *(--dp) = *(--sp);
  168872. *(--dp) = *(--sp);
  168873. *(--dp) = *(--sp);
  168874. *(--dp) = *(--sp);
  168875. *(--dp) = *(--sp);
  168876. *(--dp) = *(--sp);
  168877. *(--dp) = save[0];
  168878. *(--dp) = save[1];
  168879. }
  168880. }
  168881. }
  168882. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  168883. {
  168884. if (row_info->bit_depth == 8)
  168885. {
  168886. png_bytep sp = row + row_info->rowbytes;
  168887. png_bytep dp = sp;
  168888. png_byte save;
  168889. png_uint_32 i;
  168890. for (i = 0; i < row_width; i++)
  168891. {
  168892. save = *(--sp);
  168893. *(--dp) = *(--sp);
  168894. *(--dp) = save;
  168895. }
  168896. }
  168897. else
  168898. {
  168899. png_bytep sp = row + row_info->rowbytes;
  168900. png_bytep dp = sp;
  168901. png_byte save[2];
  168902. png_uint_32 i;
  168903. for (i = 0; i < row_width; i++)
  168904. {
  168905. save[0] = *(--sp);
  168906. save[1] = *(--sp);
  168907. *(--dp) = *(--sp);
  168908. *(--dp) = *(--sp);
  168909. *(--dp) = save[0];
  168910. *(--dp) = save[1];
  168911. }
  168912. }
  168913. }
  168914. }
  168915. }
  168916. #endif
  168917. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  168918. void /* PRIVATE */
  168919. png_do_read_invert_alpha(png_row_infop row_info, png_bytep row)
  168920. {
  168921. png_debug(1, "in png_do_read_invert_alpha\n");
  168922. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168923. if (row != NULL && row_info != NULL)
  168924. #endif
  168925. {
  168926. png_uint_32 row_width = row_info->width;
  168927. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  168928. {
  168929. if (row_info->bit_depth == 8)
  168930. {
  168931. png_bytep sp = row + row_info->rowbytes;
  168932. png_bytep dp = sp;
  168933. png_uint_32 i;
  168934. for (i = 0; i < row_width; i++)
  168935. {
  168936. *(--dp) = (png_byte)(255 - *(--sp));
  168937. sp-=3;
  168938. dp=sp;
  168939. }
  168940. }
  168941. else
  168942. {
  168943. png_bytep sp = row + row_info->rowbytes;
  168944. png_bytep dp = sp;
  168945. png_uint_32 i;
  168946. for (i = 0; i < row_width; i++)
  168947. {
  168948. *(--dp) = (png_byte)(255 - *(--sp));
  168949. *(--dp) = (png_byte)(255 - *(--sp));
  168950. sp-=6;
  168951. dp=sp;
  168952. }
  168953. }
  168954. }
  168955. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  168956. {
  168957. if (row_info->bit_depth == 8)
  168958. {
  168959. png_bytep sp = row + row_info->rowbytes;
  168960. png_bytep dp = sp;
  168961. png_uint_32 i;
  168962. for (i = 0; i < row_width; i++)
  168963. {
  168964. *(--dp) = (png_byte)(255 - *(--sp));
  168965. *(--dp) = *(--sp);
  168966. }
  168967. }
  168968. else
  168969. {
  168970. png_bytep sp = row + row_info->rowbytes;
  168971. png_bytep dp = sp;
  168972. png_uint_32 i;
  168973. for (i = 0; i < row_width; i++)
  168974. {
  168975. *(--dp) = (png_byte)(255 - *(--sp));
  168976. *(--dp) = (png_byte)(255 - *(--sp));
  168977. sp-=2;
  168978. dp=sp;
  168979. }
  168980. }
  168981. }
  168982. }
  168983. }
  168984. #endif
  168985. #if defined(PNG_READ_FILLER_SUPPORTED)
  168986. void /* PRIVATE */
  168987. png_do_read_filler(png_row_infop row_info, png_bytep row,
  168988. png_uint_32 filler, png_uint_32 flags)
  168989. {
  168990. png_uint_32 i;
  168991. png_uint_32 row_width = row_info->width;
  168992. png_byte hi_filler = (png_byte)((filler>>8) & 0xff);
  168993. png_byte lo_filler = (png_byte)(filler & 0xff);
  168994. png_debug(1, "in png_do_read_filler\n");
  168995. if (
  168996. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168997. row != NULL && row_info != NULL &&
  168998. #endif
  168999. row_info->color_type == PNG_COLOR_TYPE_GRAY)
  169000. {
  169001. if(row_info->bit_depth == 8)
  169002. {
  169003. if (flags & PNG_FLAG_FILLER_AFTER)
  169004. {
  169005. png_bytep sp = row + (png_size_t)row_width;
  169006. png_bytep dp = sp + (png_size_t)row_width;
  169007. for (i = 1; i < row_width; i++)
  169008. {
  169009. *(--dp) = lo_filler;
  169010. *(--dp) = *(--sp);
  169011. }
  169012. *(--dp) = lo_filler;
  169013. row_info->channels = 2;
  169014. row_info->pixel_depth = 16;
  169015. row_info->rowbytes = row_width * 2;
  169016. }
  169017. else
  169018. {
  169019. png_bytep sp = row + (png_size_t)row_width;
  169020. png_bytep dp = sp + (png_size_t)row_width;
  169021. for (i = 0; i < row_width; i++)
  169022. {
  169023. *(--dp) = *(--sp);
  169024. *(--dp) = lo_filler;
  169025. }
  169026. row_info->channels = 2;
  169027. row_info->pixel_depth = 16;
  169028. row_info->rowbytes = row_width * 2;
  169029. }
  169030. }
  169031. else if(row_info->bit_depth == 16)
  169032. {
  169033. if (flags & PNG_FLAG_FILLER_AFTER)
  169034. {
  169035. png_bytep sp = row + (png_size_t)row_width * 2;
  169036. png_bytep dp = sp + (png_size_t)row_width * 2;
  169037. for (i = 1; i < row_width; i++)
  169038. {
  169039. *(--dp) = hi_filler;
  169040. *(--dp) = lo_filler;
  169041. *(--dp) = *(--sp);
  169042. *(--dp) = *(--sp);
  169043. }
  169044. *(--dp) = hi_filler;
  169045. *(--dp) = lo_filler;
  169046. row_info->channels = 2;
  169047. row_info->pixel_depth = 32;
  169048. row_info->rowbytes = row_width * 4;
  169049. }
  169050. else
  169051. {
  169052. png_bytep sp = row + (png_size_t)row_width * 2;
  169053. png_bytep dp = sp + (png_size_t)row_width * 2;
  169054. for (i = 0; i < row_width; i++)
  169055. {
  169056. *(--dp) = *(--sp);
  169057. *(--dp) = *(--sp);
  169058. *(--dp) = hi_filler;
  169059. *(--dp) = lo_filler;
  169060. }
  169061. row_info->channels = 2;
  169062. row_info->pixel_depth = 32;
  169063. row_info->rowbytes = row_width * 4;
  169064. }
  169065. }
  169066. } /* COLOR_TYPE == GRAY */
  169067. else if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  169068. {
  169069. if(row_info->bit_depth == 8)
  169070. {
  169071. if (flags & PNG_FLAG_FILLER_AFTER)
  169072. {
  169073. png_bytep sp = row + (png_size_t)row_width * 3;
  169074. png_bytep dp = sp + (png_size_t)row_width;
  169075. for (i = 1; i < row_width; i++)
  169076. {
  169077. *(--dp) = lo_filler;
  169078. *(--dp) = *(--sp);
  169079. *(--dp) = *(--sp);
  169080. *(--dp) = *(--sp);
  169081. }
  169082. *(--dp) = lo_filler;
  169083. row_info->channels = 4;
  169084. row_info->pixel_depth = 32;
  169085. row_info->rowbytes = row_width * 4;
  169086. }
  169087. else
  169088. {
  169089. png_bytep sp = row + (png_size_t)row_width * 3;
  169090. png_bytep dp = sp + (png_size_t)row_width;
  169091. for (i = 0; i < row_width; i++)
  169092. {
  169093. *(--dp) = *(--sp);
  169094. *(--dp) = *(--sp);
  169095. *(--dp) = *(--sp);
  169096. *(--dp) = lo_filler;
  169097. }
  169098. row_info->channels = 4;
  169099. row_info->pixel_depth = 32;
  169100. row_info->rowbytes = row_width * 4;
  169101. }
  169102. }
  169103. else if(row_info->bit_depth == 16)
  169104. {
  169105. if (flags & PNG_FLAG_FILLER_AFTER)
  169106. {
  169107. png_bytep sp = row + (png_size_t)row_width * 6;
  169108. png_bytep dp = sp + (png_size_t)row_width * 2;
  169109. for (i = 1; i < row_width; i++)
  169110. {
  169111. *(--dp) = hi_filler;
  169112. *(--dp) = lo_filler;
  169113. *(--dp) = *(--sp);
  169114. *(--dp) = *(--sp);
  169115. *(--dp) = *(--sp);
  169116. *(--dp) = *(--sp);
  169117. *(--dp) = *(--sp);
  169118. *(--dp) = *(--sp);
  169119. }
  169120. *(--dp) = hi_filler;
  169121. *(--dp) = lo_filler;
  169122. row_info->channels = 4;
  169123. row_info->pixel_depth = 64;
  169124. row_info->rowbytes = row_width * 8;
  169125. }
  169126. else
  169127. {
  169128. png_bytep sp = row + (png_size_t)row_width * 6;
  169129. png_bytep dp = sp + (png_size_t)row_width * 2;
  169130. for (i = 0; i < row_width; i++)
  169131. {
  169132. *(--dp) = *(--sp);
  169133. *(--dp) = *(--sp);
  169134. *(--dp) = *(--sp);
  169135. *(--dp) = *(--sp);
  169136. *(--dp) = *(--sp);
  169137. *(--dp) = *(--sp);
  169138. *(--dp) = hi_filler;
  169139. *(--dp) = lo_filler;
  169140. }
  169141. row_info->channels = 4;
  169142. row_info->pixel_depth = 64;
  169143. row_info->rowbytes = row_width * 8;
  169144. }
  169145. }
  169146. } /* COLOR_TYPE == RGB */
  169147. }
  169148. #endif
  169149. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  169150. void /* PRIVATE */
  169151. png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
  169152. {
  169153. png_uint_32 i;
  169154. png_uint_32 row_width = row_info->width;
  169155. png_debug(1, "in png_do_gray_to_rgb\n");
  169156. if (row_info->bit_depth >= 8 &&
  169157. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169158. row != NULL && row_info != NULL &&
  169159. #endif
  169160. !(row_info->color_type & PNG_COLOR_MASK_COLOR))
  169161. {
  169162. if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  169163. {
  169164. if (row_info->bit_depth == 8)
  169165. {
  169166. png_bytep sp = row + (png_size_t)row_width - 1;
  169167. png_bytep dp = sp + (png_size_t)row_width * 2;
  169168. for (i = 0; i < row_width; i++)
  169169. {
  169170. *(dp--) = *sp;
  169171. *(dp--) = *sp;
  169172. *(dp--) = *(sp--);
  169173. }
  169174. }
  169175. else
  169176. {
  169177. png_bytep sp = row + (png_size_t)row_width * 2 - 1;
  169178. png_bytep dp = sp + (png_size_t)row_width * 4;
  169179. for (i = 0; i < row_width; i++)
  169180. {
  169181. *(dp--) = *sp;
  169182. *(dp--) = *(sp - 1);
  169183. *(dp--) = *sp;
  169184. *(dp--) = *(sp - 1);
  169185. *(dp--) = *(sp--);
  169186. *(dp--) = *(sp--);
  169187. }
  169188. }
  169189. }
  169190. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  169191. {
  169192. if (row_info->bit_depth == 8)
  169193. {
  169194. png_bytep sp = row + (png_size_t)row_width * 2 - 1;
  169195. png_bytep dp = sp + (png_size_t)row_width * 2;
  169196. for (i = 0; i < row_width; i++)
  169197. {
  169198. *(dp--) = *(sp--);
  169199. *(dp--) = *sp;
  169200. *(dp--) = *sp;
  169201. *(dp--) = *(sp--);
  169202. }
  169203. }
  169204. else
  169205. {
  169206. png_bytep sp = row + (png_size_t)row_width * 4 - 1;
  169207. png_bytep dp = sp + (png_size_t)row_width * 4;
  169208. for (i = 0; i < row_width; i++)
  169209. {
  169210. *(dp--) = *(sp--);
  169211. *(dp--) = *(sp--);
  169212. *(dp--) = *sp;
  169213. *(dp--) = *(sp - 1);
  169214. *(dp--) = *sp;
  169215. *(dp--) = *(sp - 1);
  169216. *(dp--) = *(sp--);
  169217. *(dp--) = *(sp--);
  169218. }
  169219. }
  169220. }
  169221. row_info->channels += (png_byte)2;
  169222. row_info->color_type |= PNG_COLOR_MASK_COLOR;
  169223. row_info->pixel_depth = (png_byte)(row_info->channels *
  169224. row_info->bit_depth);
  169225. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  169226. }
  169227. }
  169228. #endif
  169229. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  169230. int /* PRIVATE */
  169231. png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
  169232. {
  169233. png_uint_32 i;
  169234. png_uint_32 row_width = row_info->width;
  169235. int rgb_error = 0;
  169236. png_debug(1, "in png_do_rgb_to_gray\n");
  169237. if (
  169238. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169239. row != NULL && row_info != NULL &&
  169240. #endif
  169241. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  169242. {
  169243. png_uint_32 rc = png_ptr->rgb_to_gray_red_coeff;
  169244. png_uint_32 gc = png_ptr->rgb_to_gray_green_coeff;
  169245. png_uint_32 bc = png_ptr->rgb_to_gray_blue_coeff;
  169246. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  169247. {
  169248. if (row_info->bit_depth == 8)
  169249. {
  169250. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  169251. if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL)
  169252. {
  169253. png_bytep sp = row;
  169254. png_bytep dp = row;
  169255. for (i = 0; i < row_width; i++)
  169256. {
  169257. png_byte red = png_ptr->gamma_to_1[*(sp++)];
  169258. png_byte green = png_ptr->gamma_to_1[*(sp++)];
  169259. png_byte blue = png_ptr->gamma_to_1[*(sp++)];
  169260. if(red != green || red != blue)
  169261. {
  169262. rgb_error |= 1;
  169263. *(dp++) = png_ptr->gamma_from_1[
  169264. (rc*red+gc*green+bc*blue)>>15];
  169265. }
  169266. else
  169267. *(dp++) = *(sp-1);
  169268. }
  169269. }
  169270. else
  169271. #endif
  169272. {
  169273. png_bytep sp = row;
  169274. png_bytep dp = row;
  169275. for (i = 0; i < row_width; i++)
  169276. {
  169277. png_byte red = *(sp++);
  169278. png_byte green = *(sp++);
  169279. png_byte blue = *(sp++);
  169280. if(red != green || red != blue)
  169281. {
  169282. rgb_error |= 1;
  169283. *(dp++) = (png_byte)((rc*red+gc*green+bc*blue)>>15);
  169284. }
  169285. else
  169286. *(dp++) = *(sp-1);
  169287. }
  169288. }
  169289. }
  169290. else /* RGB bit_depth == 16 */
  169291. {
  169292. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  169293. if (png_ptr->gamma_16_to_1 != NULL &&
  169294. png_ptr->gamma_16_from_1 != NULL)
  169295. {
  169296. png_bytep sp = row;
  169297. png_bytep dp = row;
  169298. for (i = 0; i < row_width; i++)
  169299. {
  169300. png_uint_16 red, green, blue, w;
  169301. red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169302. green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169303. blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169304. if(red == green && red == blue)
  169305. w = red;
  169306. else
  169307. {
  169308. png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff) >>
  169309. png_ptr->gamma_shift][red>>8];
  169310. png_uint_16 green_1 = png_ptr->gamma_16_to_1[(green&0xff) >>
  169311. png_ptr->gamma_shift][green>>8];
  169312. png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >>
  169313. png_ptr->gamma_shift][blue>>8];
  169314. png_uint_16 gray16 = (png_uint_16)((rc*red_1 + gc*green_1
  169315. + bc*blue_1)>>15);
  169316. w = png_ptr->gamma_16_from_1[(gray16&0xff) >>
  169317. png_ptr->gamma_shift][gray16 >> 8];
  169318. rgb_error |= 1;
  169319. }
  169320. *(dp++) = (png_byte)((w>>8) & 0xff);
  169321. *(dp++) = (png_byte)(w & 0xff);
  169322. }
  169323. }
  169324. else
  169325. #endif
  169326. {
  169327. png_bytep sp = row;
  169328. png_bytep dp = row;
  169329. for (i = 0; i < row_width; i++)
  169330. {
  169331. png_uint_16 red, green, blue, gray16;
  169332. red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169333. green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169334. blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169335. if(red != green || red != blue)
  169336. rgb_error |= 1;
  169337. gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>15);
  169338. *(dp++) = (png_byte)((gray16>>8) & 0xff);
  169339. *(dp++) = (png_byte)(gray16 & 0xff);
  169340. }
  169341. }
  169342. }
  169343. }
  169344. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  169345. {
  169346. if (row_info->bit_depth == 8)
  169347. {
  169348. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  169349. if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL)
  169350. {
  169351. png_bytep sp = row;
  169352. png_bytep dp = row;
  169353. for (i = 0; i < row_width; i++)
  169354. {
  169355. png_byte red = png_ptr->gamma_to_1[*(sp++)];
  169356. png_byte green = png_ptr->gamma_to_1[*(sp++)];
  169357. png_byte blue = png_ptr->gamma_to_1[*(sp++)];
  169358. if(red != green || red != blue)
  169359. rgb_error |= 1;
  169360. *(dp++) = png_ptr->gamma_from_1
  169361. [(rc*red + gc*green + bc*blue)>>15];
  169362. *(dp++) = *(sp++); /* alpha */
  169363. }
  169364. }
  169365. else
  169366. #endif
  169367. {
  169368. png_bytep sp = row;
  169369. png_bytep dp = row;
  169370. for (i = 0; i < row_width; i++)
  169371. {
  169372. png_byte red = *(sp++);
  169373. png_byte green = *(sp++);
  169374. png_byte blue = *(sp++);
  169375. if(red != green || red != blue)
  169376. rgb_error |= 1;
  169377. *(dp++) = (png_byte)((rc*red + gc*green + bc*blue)>>15);
  169378. *(dp++) = *(sp++); /* alpha */
  169379. }
  169380. }
  169381. }
  169382. else /* RGBA bit_depth == 16 */
  169383. {
  169384. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  169385. if (png_ptr->gamma_16_to_1 != NULL &&
  169386. png_ptr->gamma_16_from_1 != NULL)
  169387. {
  169388. png_bytep sp = row;
  169389. png_bytep dp = row;
  169390. for (i = 0; i < row_width; i++)
  169391. {
  169392. png_uint_16 red, green, blue, w;
  169393. red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169394. green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169395. blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169396. if(red == green && red == blue)
  169397. w = red;
  169398. else
  169399. {
  169400. png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff) >>
  169401. png_ptr->gamma_shift][red>>8];
  169402. png_uint_16 green_1 = png_ptr->gamma_16_to_1[(green&0xff) >>
  169403. png_ptr->gamma_shift][green>>8];
  169404. png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >>
  169405. png_ptr->gamma_shift][blue>>8];
  169406. png_uint_16 gray16 = (png_uint_16)((rc * red_1
  169407. + gc * green_1 + bc * blue_1)>>15);
  169408. w = png_ptr->gamma_16_from_1[(gray16&0xff) >>
  169409. png_ptr->gamma_shift][gray16 >> 8];
  169410. rgb_error |= 1;
  169411. }
  169412. *(dp++) = (png_byte)((w>>8) & 0xff);
  169413. *(dp++) = (png_byte)(w & 0xff);
  169414. *(dp++) = *(sp++); /* alpha */
  169415. *(dp++) = *(sp++);
  169416. }
  169417. }
  169418. else
  169419. #endif
  169420. {
  169421. png_bytep sp = row;
  169422. png_bytep dp = row;
  169423. for (i = 0; i < row_width; i++)
  169424. {
  169425. png_uint_16 red, green, blue, gray16;
  169426. red = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
  169427. green = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
  169428. blue = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
  169429. if(red != green || red != blue)
  169430. rgb_error |= 1;
  169431. gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>15);
  169432. *(dp++) = (png_byte)((gray16>>8) & 0xff);
  169433. *(dp++) = (png_byte)(gray16 & 0xff);
  169434. *(dp++) = *(sp++); /* alpha */
  169435. *(dp++) = *(sp++);
  169436. }
  169437. }
  169438. }
  169439. }
  169440. row_info->channels -= (png_byte)2;
  169441. row_info->color_type &= ~PNG_COLOR_MASK_COLOR;
  169442. row_info->pixel_depth = (png_byte)(row_info->channels *
  169443. row_info->bit_depth);
  169444. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  169445. }
  169446. return rgb_error;
  169447. }
  169448. #endif
  169449. void PNGAPI
  169450. png_build_grayscale_palette(int bit_depth, png_colorp palette)
  169451. {
  169452. int num_palette;
  169453. int color_inc;
  169454. int i;
  169455. int v;
  169456. png_debug(1, "in png_do_build_grayscale_palette\n");
  169457. if (palette == NULL)
  169458. return;
  169459. switch (bit_depth)
  169460. {
  169461. case 1:
  169462. num_palette = 2;
  169463. color_inc = 0xff;
  169464. break;
  169465. case 2:
  169466. num_palette = 4;
  169467. color_inc = 0x55;
  169468. break;
  169469. case 4:
  169470. num_palette = 16;
  169471. color_inc = 0x11;
  169472. break;
  169473. case 8:
  169474. num_palette = 256;
  169475. color_inc = 1;
  169476. break;
  169477. default:
  169478. num_palette = 0;
  169479. color_inc = 0;
  169480. break;
  169481. }
  169482. for (i = 0, v = 0; i < num_palette; i++, v += color_inc)
  169483. {
  169484. palette[i].red = (png_byte)v;
  169485. palette[i].green = (png_byte)v;
  169486. palette[i].blue = (png_byte)v;
  169487. }
  169488. }
  169489. #if defined(PNG_READ_DITHER_SUPPORTED) && defined(PNG_CORRECT_PALETTE_SUPPORTED)
  169490. void /* PRIVATE */
  169491. png_correct_palette(png_structp png_ptr, png_colorp palette,
  169492. int num_palette)
  169493. {
  169494. png_debug(1, "in png_correct_palette\n");
  169495. #if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
  169496. defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  169497. if (png_ptr->transformations & (PNG_GAMMA | PNG_BACKGROUND))
  169498. {
  169499. png_color back, back_1;
  169500. if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE)
  169501. {
  169502. back.red = png_ptr->gamma_table[png_ptr->background.red];
  169503. back.green = png_ptr->gamma_table[png_ptr->background.green];
  169504. back.blue = png_ptr->gamma_table[png_ptr->background.blue];
  169505. back_1.red = png_ptr->gamma_to_1[png_ptr->background.red];
  169506. back_1.green = png_ptr->gamma_to_1[png_ptr->background.green];
  169507. back_1.blue = png_ptr->gamma_to_1[png_ptr->background.blue];
  169508. }
  169509. else
  169510. {
  169511. double g;
  169512. g = 1.0 / (png_ptr->background_gamma * png_ptr->screen_gamma);
  169513. if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_SCREEN ||
  169514. fabs(g - 1.0) < PNG_GAMMA_THRESHOLD)
  169515. {
  169516. back.red = png_ptr->background.red;
  169517. back.green = png_ptr->background.green;
  169518. back.blue = png_ptr->background.blue;
  169519. }
  169520. else
  169521. {
  169522. back.red =
  169523. (png_byte)(pow((double)png_ptr->background.red/255, g) *
  169524. 255.0 + 0.5);
  169525. back.green =
  169526. (png_byte)(pow((double)png_ptr->background.green/255, g) *
  169527. 255.0 + 0.5);
  169528. back.blue =
  169529. (png_byte)(pow((double)png_ptr->background.blue/255, g) *
  169530. 255.0 + 0.5);
  169531. }
  169532. g = 1.0 / png_ptr->background_gamma;
  169533. back_1.red =
  169534. (png_byte)(pow((double)png_ptr->background.red/255, g) *
  169535. 255.0 + 0.5);
  169536. back_1.green =
  169537. (png_byte)(pow((double)png_ptr->background.green/255, g) *
  169538. 255.0 + 0.5);
  169539. back_1.blue =
  169540. (png_byte)(pow((double)png_ptr->background.blue/255, g) *
  169541. 255.0 + 0.5);
  169542. }
  169543. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  169544. {
  169545. png_uint_32 i;
  169546. for (i = 0; i < (png_uint_32)num_palette; i++)
  169547. {
  169548. if (i < png_ptr->num_trans && png_ptr->trans[i] == 0)
  169549. {
  169550. palette[i] = back;
  169551. }
  169552. else if (i < png_ptr->num_trans && png_ptr->trans[i] != 0xff)
  169553. {
  169554. png_byte v, w;
  169555. v = png_ptr->gamma_to_1[png_ptr->palette[i].red];
  169556. png_composite(w, v, png_ptr->trans[i], back_1.red);
  169557. palette[i].red = png_ptr->gamma_from_1[w];
  169558. v = png_ptr->gamma_to_1[png_ptr->palette[i].green];
  169559. png_composite(w, v, png_ptr->trans[i], back_1.green);
  169560. palette[i].green = png_ptr->gamma_from_1[w];
  169561. v = png_ptr->gamma_to_1[png_ptr->palette[i].blue];
  169562. png_composite(w, v, png_ptr->trans[i], back_1.blue);
  169563. palette[i].blue = png_ptr->gamma_from_1[w];
  169564. }
  169565. else
  169566. {
  169567. palette[i].red = png_ptr->gamma_table[palette[i].red];
  169568. palette[i].green = png_ptr->gamma_table[palette[i].green];
  169569. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  169570. }
  169571. }
  169572. }
  169573. else
  169574. {
  169575. int i;
  169576. for (i = 0; i < num_palette; i++)
  169577. {
  169578. if (palette[i].red == (png_byte)png_ptr->trans_values.gray)
  169579. {
  169580. palette[i] = back;
  169581. }
  169582. else
  169583. {
  169584. palette[i].red = png_ptr->gamma_table[palette[i].red];
  169585. palette[i].green = png_ptr->gamma_table[palette[i].green];
  169586. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  169587. }
  169588. }
  169589. }
  169590. }
  169591. else
  169592. #endif
  169593. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169594. if (png_ptr->transformations & PNG_GAMMA)
  169595. {
  169596. int i;
  169597. for (i = 0; i < num_palette; i++)
  169598. {
  169599. palette[i].red = png_ptr->gamma_table[palette[i].red];
  169600. palette[i].green = png_ptr->gamma_table[palette[i].green];
  169601. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  169602. }
  169603. }
  169604. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  169605. else
  169606. #endif
  169607. #endif
  169608. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  169609. if (png_ptr->transformations & PNG_BACKGROUND)
  169610. {
  169611. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  169612. {
  169613. png_color back;
  169614. back.red = (png_byte)png_ptr->background.red;
  169615. back.green = (png_byte)png_ptr->background.green;
  169616. back.blue = (png_byte)png_ptr->background.blue;
  169617. for (i = 0; i < (int)png_ptr->num_trans; i++)
  169618. {
  169619. if (png_ptr->trans[i] == 0)
  169620. {
  169621. palette[i].red = back.red;
  169622. palette[i].green = back.green;
  169623. palette[i].blue = back.blue;
  169624. }
  169625. else if (png_ptr->trans[i] != 0xff)
  169626. {
  169627. png_composite(palette[i].red, png_ptr->palette[i].red,
  169628. png_ptr->trans[i], back.red);
  169629. png_composite(palette[i].green, png_ptr->palette[i].green,
  169630. png_ptr->trans[i], back.green);
  169631. png_composite(palette[i].blue, png_ptr->palette[i].blue,
  169632. png_ptr->trans[i], back.blue);
  169633. }
  169634. }
  169635. }
  169636. else /* assume grayscale palette (what else could it be?) */
  169637. {
  169638. int i;
  169639. for (i = 0; i < num_palette; i++)
  169640. {
  169641. if (i == (png_byte)png_ptr->trans_values.gray)
  169642. {
  169643. palette[i].red = (png_byte)png_ptr->background.red;
  169644. palette[i].green = (png_byte)png_ptr->background.green;
  169645. palette[i].blue = (png_byte)png_ptr->background.blue;
  169646. }
  169647. }
  169648. }
  169649. }
  169650. #endif
  169651. }
  169652. #endif
  169653. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  169654. void /* PRIVATE */
  169655. png_do_background(png_row_infop row_info, png_bytep row,
  169656. png_color_16p trans_values, png_color_16p background
  169657. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169658. , png_color_16p background_1,
  169659. png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1,
  169660. png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1,
  169661. png_uint_16pp gamma_16_to_1, int gamma_shift
  169662. #endif
  169663. )
  169664. {
  169665. png_bytep sp, dp;
  169666. png_uint_32 i;
  169667. png_uint_32 row_width=row_info->width;
  169668. int shift;
  169669. png_debug(1, "in png_do_background\n");
  169670. if (background != NULL &&
  169671. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169672. row != NULL && row_info != NULL &&
  169673. #endif
  169674. (!(row_info->color_type & PNG_COLOR_MASK_ALPHA) ||
  169675. (row_info->color_type != PNG_COLOR_TYPE_PALETTE && trans_values)))
  169676. {
  169677. switch (row_info->color_type)
  169678. {
  169679. case PNG_COLOR_TYPE_GRAY:
  169680. {
  169681. switch (row_info->bit_depth)
  169682. {
  169683. case 1:
  169684. {
  169685. sp = row;
  169686. shift = 7;
  169687. for (i = 0; i < row_width; i++)
  169688. {
  169689. if ((png_uint_16)((*sp >> shift) & 0x01)
  169690. == trans_values->gray)
  169691. {
  169692. *sp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff);
  169693. *sp |= (png_byte)(background->gray << shift);
  169694. }
  169695. if (!shift)
  169696. {
  169697. shift = 7;
  169698. sp++;
  169699. }
  169700. else
  169701. shift--;
  169702. }
  169703. break;
  169704. }
  169705. case 2:
  169706. {
  169707. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169708. if (gamma_table != NULL)
  169709. {
  169710. sp = row;
  169711. shift = 6;
  169712. for (i = 0; i < row_width; i++)
  169713. {
  169714. if ((png_uint_16)((*sp >> shift) & 0x03)
  169715. == trans_values->gray)
  169716. {
  169717. *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  169718. *sp |= (png_byte)(background->gray << shift);
  169719. }
  169720. else
  169721. {
  169722. png_byte p = (png_byte)((*sp >> shift) & 0x03);
  169723. png_byte g = (png_byte)((gamma_table [p | (p << 2) |
  169724. (p << 4) | (p << 6)] >> 6) & 0x03);
  169725. *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  169726. *sp |= (png_byte)(g << shift);
  169727. }
  169728. if (!shift)
  169729. {
  169730. shift = 6;
  169731. sp++;
  169732. }
  169733. else
  169734. shift -= 2;
  169735. }
  169736. }
  169737. else
  169738. #endif
  169739. {
  169740. sp = row;
  169741. shift = 6;
  169742. for (i = 0; i < row_width; i++)
  169743. {
  169744. if ((png_uint_16)((*sp >> shift) & 0x03)
  169745. == trans_values->gray)
  169746. {
  169747. *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  169748. *sp |= (png_byte)(background->gray << shift);
  169749. }
  169750. if (!shift)
  169751. {
  169752. shift = 6;
  169753. sp++;
  169754. }
  169755. else
  169756. shift -= 2;
  169757. }
  169758. }
  169759. break;
  169760. }
  169761. case 4:
  169762. {
  169763. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169764. if (gamma_table != NULL)
  169765. {
  169766. sp = row;
  169767. shift = 4;
  169768. for (i = 0; i < row_width; i++)
  169769. {
  169770. if ((png_uint_16)((*sp >> shift) & 0x0f)
  169771. == trans_values->gray)
  169772. {
  169773. *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  169774. *sp |= (png_byte)(background->gray << shift);
  169775. }
  169776. else
  169777. {
  169778. png_byte p = (png_byte)((*sp >> shift) & 0x0f);
  169779. png_byte g = (png_byte)((gamma_table[p |
  169780. (p << 4)] >> 4) & 0x0f);
  169781. *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  169782. *sp |= (png_byte)(g << shift);
  169783. }
  169784. if (!shift)
  169785. {
  169786. shift = 4;
  169787. sp++;
  169788. }
  169789. else
  169790. shift -= 4;
  169791. }
  169792. }
  169793. else
  169794. #endif
  169795. {
  169796. sp = row;
  169797. shift = 4;
  169798. for (i = 0; i < row_width; i++)
  169799. {
  169800. if ((png_uint_16)((*sp >> shift) & 0x0f)
  169801. == trans_values->gray)
  169802. {
  169803. *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  169804. *sp |= (png_byte)(background->gray << shift);
  169805. }
  169806. if (!shift)
  169807. {
  169808. shift = 4;
  169809. sp++;
  169810. }
  169811. else
  169812. shift -= 4;
  169813. }
  169814. }
  169815. break;
  169816. }
  169817. case 8:
  169818. {
  169819. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169820. if (gamma_table != NULL)
  169821. {
  169822. sp = row;
  169823. for (i = 0; i < row_width; i++, sp++)
  169824. {
  169825. if (*sp == trans_values->gray)
  169826. {
  169827. *sp = (png_byte)background->gray;
  169828. }
  169829. else
  169830. {
  169831. *sp = gamma_table[*sp];
  169832. }
  169833. }
  169834. }
  169835. else
  169836. #endif
  169837. {
  169838. sp = row;
  169839. for (i = 0; i < row_width; i++, sp++)
  169840. {
  169841. if (*sp == trans_values->gray)
  169842. {
  169843. *sp = (png_byte)background->gray;
  169844. }
  169845. }
  169846. }
  169847. break;
  169848. }
  169849. case 16:
  169850. {
  169851. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169852. if (gamma_16 != NULL)
  169853. {
  169854. sp = row;
  169855. for (i = 0; i < row_width; i++, sp += 2)
  169856. {
  169857. png_uint_16 v;
  169858. v = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169859. if (v == trans_values->gray)
  169860. {
  169861. *sp = (png_byte)((background->gray >> 8) & 0xff);
  169862. *(sp + 1) = (png_byte)(background->gray & 0xff);
  169863. }
  169864. else
  169865. {
  169866. v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169867. *sp = (png_byte)((v >> 8) & 0xff);
  169868. *(sp + 1) = (png_byte)(v & 0xff);
  169869. }
  169870. }
  169871. }
  169872. else
  169873. #endif
  169874. {
  169875. sp = row;
  169876. for (i = 0; i < row_width; i++, sp += 2)
  169877. {
  169878. png_uint_16 v;
  169879. v = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169880. if (v == trans_values->gray)
  169881. {
  169882. *sp = (png_byte)((background->gray >> 8) & 0xff);
  169883. *(sp + 1) = (png_byte)(background->gray & 0xff);
  169884. }
  169885. }
  169886. }
  169887. break;
  169888. }
  169889. }
  169890. break;
  169891. }
  169892. case PNG_COLOR_TYPE_RGB:
  169893. {
  169894. if (row_info->bit_depth == 8)
  169895. {
  169896. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169897. if (gamma_table != NULL)
  169898. {
  169899. sp = row;
  169900. for (i = 0; i < row_width; i++, sp += 3)
  169901. {
  169902. if (*sp == trans_values->red &&
  169903. *(sp + 1) == trans_values->green &&
  169904. *(sp + 2) == trans_values->blue)
  169905. {
  169906. *sp = (png_byte)background->red;
  169907. *(sp + 1) = (png_byte)background->green;
  169908. *(sp + 2) = (png_byte)background->blue;
  169909. }
  169910. else
  169911. {
  169912. *sp = gamma_table[*sp];
  169913. *(sp + 1) = gamma_table[*(sp + 1)];
  169914. *(sp + 2) = gamma_table[*(sp + 2)];
  169915. }
  169916. }
  169917. }
  169918. else
  169919. #endif
  169920. {
  169921. sp = row;
  169922. for (i = 0; i < row_width; i++, sp += 3)
  169923. {
  169924. if (*sp == trans_values->red &&
  169925. *(sp + 1) == trans_values->green &&
  169926. *(sp + 2) == trans_values->blue)
  169927. {
  169928. *sp = (png_byte)background->red;
  169929. *(sp + 1) = (png_byte)background->green;
  169930. *(sp + 2) = (png_byte)background->blue;
  169931. }
  169932. }
  169933. }
  169934. }
  169935. else /* if (row_info->bit_depth == 16) */
  169936. {
  169937. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169938. if (gamma_16 != NULL)
  169939. {
  169940. sp = row;
  169941. for (i = 0; i < row_width; i++, sp += 6)
  169942. {
  169943. png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169944. png_uint_16 g = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169945. png_uint_16 b = (png_uint_16)(((*(sp+4)) << 8) + *(sp+5));
  169946. if (r == trans_values->red && g == trans_values->green &&
  169947. b == trans_values->blue)
  169948. {
  169949. *sp = (png_byte)((background->red >> 8) & 0xff);
  169950. *(sp + 1) = (png_byte)(background->red & 0xff);
  169951. *(sp + 2) = (png_byte)((background->green >> 8) & 0xff);
  169952. *(sp + 3) = (png_byte)(background->green & 0xff);
  169953. *(sp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  169954. *(sp + 5) = (png_byte)(background->blue & 0xff);
  169955. }
  169956. else
  169957. {
  169958. png_uint_16 v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169959. *sp = (png_byte)((v >> 8) & 0xff);
  169960. *(sp + 1) = (png_byte)(v & 0xff);
  169961. v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)];
  169962. *(sp + 2) = (png_byte)((v >> 8) & 0xff);
  169963. *(sp + 3) = (png_byte)(v & 0xff);
  169964. v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)];
  169965. *(sp + 4) = (png_byte)((v >> 8) & 0xff);
  169966. *(sp + 5) = (png_byte)(v & 0xff);
  169967. }
  169968. }
  169969. }
  169970. else
  169971. #endif
  169972. {
  169973. sp = row;
  169974. for (i = 0; i < row_width; i++, sp += 6)
  169975. {
  169976. png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp+1));
  169977. png_uint_16 g = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169978. png_uint_16 b = (png_uint_16)(((*(sp+4)) << 8) + *(sp+5));
  169979. if (r == trans_values->red && g == trans_values->green &&
  169980. b == trans_values->blue)
  169981. {
  169982. *sp = (png_byte)((background->red >> 8) & 0xff);
  169983. *(sp + 1) = (png_byte)(background->red & 0xff);
  169984. *(sp + 2) = (png_byte)((background->green >> 8) & 0xff);
  169985. *(sp + 3) = (png_byte)(background->green & 0xff);
  169986. *(sp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  169987. *(sp + 5) = (png_byte)(background->blue & 0xff);
  169988. }
  169989. }
  169990. }
  169991. }
  169992. break;
  169993. }
  169994. case PNG_COLOR_TYPE_GRAY_ALPHA:
  169995. {
  169996. if (row_info->bit_depth == 8)
  169997. {
  169998. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169999. if (gamma_to_1 != NULL && gamma_from_1 != NULL &&
  170000. gamma_table != NULL)
  170001. {
  170002. sp = row;
  170003. dp = row;
  170004. for (i = 0; i < row_width; i++, sp += 2, dp++)
  170005. {
  170006. png_uint_16 a = *(sp + 1);
  170007. if (a == 0xff)
  170008. {
  170009. *dp = gamma_table[*sp];
  170010. }
  170011. else if (a == 0)
  170012. {
  170013. *dp = (png_byte)background->gray;
  170014. }
  170015. else
  170016. {
  170017. png_byte v, w;
  170018. v = gamma_to_1[*sp];
  170019. png_composite(w, v, a, background_1->gray);
  170020. *dp = gamma_from_1[w];
  170021. }
  170022. }
  170023. }
  170024. else
  170025. #endif
  170026. {
  170027. sp = row;
  170028. dp = row;
  170029. for (i = 0; i < row_width; i++, sp += 2, dp++)
  170030. {
  170031. png_byte a = *(sp + 1);
  170032. if (a == 0xff)
  170033. {
  170034. *dp = *sp;
  170035. }
  170036. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170037. else if (a == 0)
  170038. {
  170039. *dp = (png_byte)background->gray;
  170040. }
  170041. else
  170042. {
  170043. png_composite(*dp, *sp, a, background_1->gray);
  170044. }
  170045. #else
  170046. *dp = (png_byte)background->gray;
  170047. #endif
  170048. }
  170049. }
  170050. }
  170051. else /* if (png_ptr->bit_depth == 16) */
  170052. {
  170053. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170054. if (gamma_16 != NULL && gamma_16_from_1 != NULL &&
  170055. gamma_16_to_1 != NULL)
  170056. {
  170057. sp = row;
  170058. dp = row;
  170059. for (i = 0; i < row_width; i++, sp += 4, dp += 2)
  170060. {
  170061. png_uint_16 a = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  170062. if (a == (png_uint_16)0xffff)
  170063. {
  170064. png_uint_16 v;
  170065. v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  170066. *dp = (png_byte)((v >> 8) & 0xff);
  170067. *(dp + 1) = (png_byte)(v & 0xff);
  170068. }
  170069. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170070. else if (a == 0)
  170071. #else
  170072. else
  170073. #endif
  170074. {
  170075. *dp = (png_byte)((background->gray >> 8) & 0xff);
  170076. *(dp + 1) = (png_byte)(background->gray & 0xff);
  170077. }
  170078. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170079. else
  170080. {
  170081. png_uint_16 g, v, w;
  170082. g = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp];
  170083. png_composite_16(v, g, a, background_1->gray);
  170084. w = gamma_16_from_1[(v&0xff) >> gamma_shift][v >> 8];
  170085. *dp = (png_byte)((w >> 8) & 0xff);
  170086. *(dp + 1) = (png_byte)(w & 0xff);
  170087. }
  170088. #endif
  170089. }
  170090. }
  170091. else
  170092. #endif
  170093. {
  170094. sp = row;
  170095. dp = row;
  170096. for (i = 0; i < row_width; i++, sp += 4, dp += 2)
  170097. {
  170098. png_uint_16 a = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  170099. if (a == (png_uint_16)0xffff)
  170100. {
  170101. png_memcpy(dp, sp, 2);
  170102. }
  170103. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170104. else if (a == 0)
  170105. #else
  170106. else
  170107. #endif
  170108. {
  170109. *dp = (png_byte)((background->gray >> 8) & 0xff);
  170110. *(dp + 1) = (png_byte)(background->gray & 0xff);
  170111. }
  170112. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170113. else
  170114. {
  170115. png_uint_16 g, v;
  170116. g = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  170117. png_composite_16(v, g, a, background_1->gray);
  170118. *dp = (png_byte)((v >> 8) & 0xff);
  170119. *(dp + 1) = (png_byte)(v & 0xff);
  170120. }
  170121. #endif
  170122. }
  170123. }
  170124. }
  170125. break;
  170126. }
  170127. case PNG_COLOR_TYPE_RGB_ALPHA:
  170128. {
  170129. if (row_info->bit_depth == 8)
  170130. {
  170131. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170132. if (gamma_to_1 != NULL && gamma_from_1 != NULL &&
  170133. gamma_table != NULL)
  170134. {
  170135. sp = row;
  170136. dp = row;
  170137. for (i = 0; i < row_width; i++, sp += 4, dp += 3)
  170138. {
  170139. png_byte a = *(sp + 3);
  170140. if (a == 0xff)
  170141. {
  170142. *dp = gamma_table[*sp];
  170143. *(dp + 1) = gamma_table[*(sp + 1)];
  170144. *(dp + 2) = gamma_table[*(sp + 2)];
  170145. }
  170146. else if (a == 0)
  170147. {
  170148. *dp = (png_byte)background->red;
  170149. *(dp + 1) = (png_byte)background->green;
  170150. *(dp + 2) = (png_byte)background->blue;
  170151. }
  170152. else
  170153. {
  170154. png_byte v, w;
  170155. v = gamma_to_1[*sp];
  170156. png_composite(w, v, a, background_1->red);
  170157. *dp = gamma_from_1[w];
  170158. v = gamma_to_1[*(sp + 1)];
  170159. png_composite(w, v, a, background_1->green);
  170160. *(dp + 1) = gamma_from_1[w];
  170161. v = gamma_to_1[*(sp + 2)];
  170162. png_composite(w, v, a, background_1->blue);
  170163. *(dp + 2) = gamma_from_1[w];
  170164. }
  170165. }
  170166. }
  170167. else
  170168. #endif
  170169. {
  170170. sp = row;
  170171. dp = row;
  170172. for (i = 0; i < row_width; i++, sp += 4, dp += 3)
  170173. {
  170174. png_byte a = *(sp + 3);
  170175. if (a == 0xff)
  170176. {
  170177. *dp = *sp;
  170178. *(dp + 1) = *(sp + 1);
  170179. *(dp + 2) = *(sp + 2);
  170180. }
  170181. else if (a == 0)
  170182. {
  170183. *dp = (png_byte)background->red;
  170184. *(dp + 1) = (png_byte)background->green;
  170185. *(dp + 2) = (png_byte)background->blue;
  170186. }
  170187. else
  170188. {
  170189. png_composite(*dp, *sp, a, background->red);
  170190. png_composite(*(dp + 1), *(sp + 1), a,
  170191. background->green);
  170192. png_composite(*(dp + 2), *(sp + 2), a,
  170193. background->blue);
  170194. }
  170195. }
  170196. }
  170197. }
  170198. else /* if (row_info->bit_depth == 16) */
  170199. {
  170200. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170201. if (gamma_16 != NULL && gamma_16_from_1 != NULL &&
  170202. gamma_16_to_1 != NULL)
  170203. {
  170204. sp = row;
  170205. dp = row;
  170206. for (i = 0; i < row_width; i++, sp += 8, dp += 6)
  170207. {
  170208. png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
  170209. << 8) + (png_uint_16)(*(sp + 7)));
  170210. if (a == (png_uint_16)0xffff)
  170211. {
  170212. png_uint_16 v;
  170213. v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  170214. *dp = (png_byte)((v >> 8) & 0xff);
  170215. *(dp + 1) = (png_byte)(v & 0xff);
  170216. v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)];
  170217. *(dp + 2) = (png_byte)((v >> 8) & 0xff);
  170218. *(dp + 3) = (png_byte)(v & 0xff);
  170219. v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)];
  170220. *(dp + 4) = (png_byte)((v >> 8) & 0xff);
  170221. *(dp + 5) = (png_byte)(v & 0xff);
  170222. }
  170223. else if (a == 0)
  170224. {
  170225. *dp = (png_byte)((background->red >> 8) & 0xff);
  170226. *(dp + 1) = (png_byte)(background->red & 0xff);
  170227. *(dp + 2) = (png_byte)((background->green >> 8) & 0xff);
  170228. *(dp + 3) = (png_byte)(background->green & 0xff);
  170229. *(dp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  170230. *(dp + 5) = (png_byte)(background->blue & 0xff);
  170231. }
  170232. else
  170233. {
  170234. png_uint_16 v, w, x;
  170235. v = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp];
  170236. png_composite_16(w, v, a, background_1->red);
  170237. x = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8];
  170238. *dp = (png_byte)((x >> 8) & 0xff);
  170239. *(dp + 1) = (png_byte)(x & 0xff);
  170240. v = gamma_16_to_1[*(sp + 3) >> gamma_shift][*(sp + 2)];
  170241. png_composite_16(w, v, a, background_1->green);
  170242. x = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8];
  170243. *(dp + 2) = (png_byte)((x >> 8) & 0xff);
  170244. *(dp + 3) = (png_byte)(x & 0xff);
  170245. v = gamma_16_to_1[*(sp + 5) >> gamma_shift][*(sp + 4)];
  170246. png_composite_16(w, v, a, background_1->blue);
  170247. x = gamma_16_from_1[(w & 0xff) >> gamma_shift][w >> 8];
  170248. *(dp + 4) = (png_byte)((x >> 8) & 0xff);
  170249. *(dp + 5) = (png_byte)(x & 0xff);
  170250. }
  170251. }
  170252. }
  170253. else
  170254. #endif
  170255. {
  170256. sp = row;
  170257. dp = row;
  170258. for (i = 0; i < row_width; i++, sp += 8, dp += 6)
  170259. {
  170260. png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
  170261. << 8) + (png_uint_16)(*(sp + 7)));
  170262. if (a == (png_uint_16)0xffff)
  170263. {
  170264. png_memcpy(dp, sp, 6);
  170265. }
  170266. else if (a == 0)
  170267. {
  170268. *dp = (png_byte)((background->red >> 8) & 0xff);
  170269. *(dp + 1) = (png_byte)(background->red & 0xff);
  170270. *(dp + 2) = (png_byte)((background->green >> 8) & 0xff);
  170271. *(dp + 3) = (png_byte)(background->green & 0xff);
  170272. *(dp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  170273. *(dp + 5) = (png_byte)(background->blue & 0xff);
  170274. }
  170275. else
  170276. {
  170277. png_uint_16 v;
  170278. png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  170279. png_uint_16 g = (png_uint_16)(((*(sp + 2)) << 8)
  170280. + *(sp + 3));
  170281. png_uint_16 b = (png_uint_16)(((*(sp + 4)) << 8)
  170282. + *(sp + 5));
  170283. png_composite_16(v, r, a, background->red);
  170284. *dp = (png_byte)((v >> 8) & 0xff);
  170285. *(dp + 1) = (png_byte)(v & 0xff);
  170286. png_composite_16(v, g, a, background->green);
  170287. *(dp + 2) = (png_byte)((v >> 8) & 0xff);
  170288. *(dp + 3) = (png_byte)(v & 0xff);
  170289. png_composite_16(v, b, a, background->blue);
  170290. *(dp + 4) = (png_byte)((v >> 8) & 0xff);
  170291. *(dp + 5) = (png_byte)(v & 0xff);
  170292. }
  170293. }
  170294. }
  170295. }
  170296. break;
  170297. }
  170298. }
  170299. if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
  170300. {
  170301. row_info->color_type &= ~PNG_COLOR_MASK_ALPHA;
  170302. row_info->channels--;
  170303. row_info->pixel_depth = (png_byte)(row_info->channels *
  170304. row_info->bit_depth);
  170305. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170306. }
  170307. }
  170308. }
  170309. #endif
  170310. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170311. void /* PRIVATE */
  170312. png_do_gamma(png_row_infop row_info, png_bytep row,
  170313. png_bytep gamma_table, png_uint_16pp gamma_16_table,
  170314. int gamma_shift)
  170315. {
  170316. png_bytep sp;
  170317. png_uint_32 i;
  170318. png_uint_32 row_width=row_info->width;
  170319. png_debug(1, "in png_do_gamma\n");
  170320. if (
  170321. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170322. row != NULL && row_info != NULL &&
  170323. #endif
  170324. ((row_info->bit_depth <= 8 && gamma_table != NULL) ||
  170325. (row_info->bit_depth == 16 && gamma_16_table != NULL)))
  170326. {
  170327. switch (row_info->color_type)
  170328. {
  170329. case PNG_COLOR_TYPE_RGB:
  170330. {
  170331. if (row_info->bit_depth == 8)
  170332. {
  170333. sp = row;
  170334. for (i = 0; i < row_width; i++)
  170335. {
  170336. *sp = gamma_table[*sp];
  170337. sp++;
  170338. *sp = gamma_table[*sp];
  170339. sp++;
  170340. *sp = gamma_table[*sp];
  170341. sp++;
  170342. }
  170343. }
  170344. else /* if (row_info->bit_depth == 16) */
  170345. {
  170346. sp = row;
  170347. for (i = 0; i < row_width; i++)
  170348. {
  170349. png_uint_16 v;
  170350. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170351. *sp = (png_byte)((v >> 8) & 0xff);
  170352. *(sp + 1) = (png_byte)(v & 0xff);
  170353. sp += 2;
  170354. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170355. *sp = (png_byte)((v >> 8) & 0xff);
  170356. *(sp + 1) = (png_byte)(v & 0xff);
  170357. sp += 2;
  170358. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170359. *sp = (png_byte)((v >> 8) & 0xff);
  170360. *(sp + 1) = (png_byte)(v & 0xff);
  170361. sp += 2;
  170362. }
  170363. }
  170364. break;
  170365. }
  170366. case PNG_COLOR_TYPE_RGB_ALPHA:
  170367. {
  170368. if (row_info->bit_depth == 8)
  170369. {
  170370. sp = row;
  170371. for (i = 0; i < row_width; i++)
  170372. {
  170373. *sp = gamma_table[*sp];
  170374. sp++;
  170375. *sp = gamma_table[*sp];
  170376. sp++;
  170377. *sp = gamma_table[*sp];
  170378. sp++;
  170379. sp++;
  170380. }
  170381. }
  170382. else /* if (row_info->bit_depth == 16) */
  170383. {
  170384. sp = row;
  170385. for (i = 0; i < row_width; i++)
  170386. {
  170387. png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170388. *sp = (png_byte)((v >> 8) & 0xff);
  170389. *(sp + 1) = (png_byte)(v & 0xff);
  170390. sp += 2;
  170391. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170392. *sp = (png_byte)((v >> 8) & 0xff);
  170393. *(sp + 1) = (png_byte)(v & 0xff);
  170394. sp += 2;
  170395. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170396. *sp = (png_byte)((v >> 8) & 0xff);
  170397. *(sp + 1) = (png_byte)(v & 0xff);
  170398. sp += 4;
  170399. }
  170400. }
  170401. break;
  170402. }
  170403. case PNG_COLOR_TYPE_GRAY_ALPHA:
  170404. {
  170405. if (row_info->bit_depth == 8)
  170406. {
  170407. sp = row;
  170408. for (i = 0; i < row_width; i++)
  170409. {
  170410. *sp = gamma_table[*sp];
  170411. sp += 2;
  170412. }
  170413. }
  170414. else /* if (row_info->bit_depth == 16) */
  170415. {
  170416. sp = row;
  170417. for (i = 0; i < row_width; i++)
  170418. {
  170419. png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170420. *sp = (png_byte)((v >> 8) & 0xff);
  170421. *(sp + 1) = (png_byte)(v & 0xff);
  170422. sp += 4;
  170423. }
  170424. }
  170425. break;
  170426. }
  170427. case PNG_COLOR_TYPE_GRAY:
  170428. {
  170429. if (row_info->bit_depth == 2)
  170430. {
  170431. sp = row;
  170432. for (i = 0; i < row_width; i += 4)
  170433. {
  170434. int a = *sp & 0xc0;
  170435. int b = *sp & 0x30;
  170436. int c = *sp & 0x0c;
  170437. int d = *sp & 0x03;
  170438. *sp = (png_byte)(
  170439. ((((int)gamma_table[a|(a>>2)|(a>>4)|(a>>6)]) ) & 0xc0)|
  170440. ((((int)gamma_table[(b<<2)|b|(b>>2)|(b>>4)])>>2) & 0x30)|
  170441. ((((int)gamma_table[(c<<4)|(c<<2)|c|(c>>2)])>>4) & 0x0c)|
  170442. ((((int)gamma_table[(d<<6)|(d<<4)|(d<<2)|d])>>6) ));
  170443. sp++;
  170444. }
  170445. }
  170446. if (row_info->bit_depth == 4)
  170447. {
  170448. sp = row;
  170449. for (i = 0; i < row_width; i += 2)
  170450. {
  170451. int msb = *sp & 0xf0;
  170452. int lsb = *sp & 0x0f;
  170453. *sp = (png_byte)((((int)gamma_table[msb | (msb >> 4)]) & 0xf0)
  170454. | (((int)gamma_table[(lsb << 4) | lsb]) >> 4));
  170455. sp++;
  170456. }
  170457. }
  170458. else if (row_info->bit_depth == 8)
  170459. {
  170460. sp = row;
  170461. for (i = 0; i < row_width; i++)
  170462. {
  170463. *sp = gamma_table[*sp];
  170464. sp++;
  170465. }
  170466. }
  170467. else if (row_info->bit_depth == 16)
  170468. {
  170469. sp = row;
  170470. for (i = 0; i < row_width; i++)
  170471. {
  170472. png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170473. *sp = (png_byte)((v >> 8) & 0xff);
  170474. *(sp + 1) = (png_byte)(v & 0xff);
  170475. sp += 2;
  170476. }
  170477. }
  170478. break;
  170479. }
  170480. }
  170481. }
  170482. }
  170483. #endif
  170484. #if defined(PNG_READ_EXPAND_SUPPORTED)
  170485. void /* PRIVATE */
  170486. png_do_expand_palette(png_row_infop row_info, png_bytep row,
  170487. png_colorp palette, png_bytep trans, int num_trans)
  170488. {
  170489. int shift, value;
  170490. png_bytep sp, dp;
  170491. png_uint_32 i;
  170492. png_uint_32 row_width=row_info->width;
  170493. png_debug(1, "in png_do_expand_palette\n");
  170494. if (
  170495. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170496. row != NULL && row_info != NULL &&
  170497. #endif
  170498. row_info->color_type == PNG_COLOR_TYPE_PALETTE)
  170499. {
  170500. if (row_info->bit_depth < 8)
  170501. {
  170502. switch (row_info->bit_depth)
  170503. {
  170504. case 1:
  170505. {
  170506. sp = row + (png_size_t)((row_width - 1) >> 3);
  170507. dp = row + (png_size_t)row_width - 1;
  170508. shift = 7 - (int)((row_width + 7) & 0x07);
  170509. for (i = 0; i < row_width; i++)
  170510. {
  170511. if ((*sp >> shift) & 0x01)
  170512. *dp = 1;
  170513. else
  170514. *dp = 0;
  170515. if (shift == 7)
  170516. {
  170517. shift = 0;
  170518. sp--;
  170519. }
  170520. else
  170521. shift++;
  170522. dp--;
  170523. }
  170524. break;
  170525. }
  170526. case 2:
  170527. {
  170528. sp = row + (png_size_t)((row_width - 1) >> 2);
  170529. dp = row + (png_size_t)row_width - 1;
  170530. shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
  170531. for (i = 0; i < row_width; i++)
  170532. {
  170533. value = (*sp >> shift) & 0x03;
  170534. *dp = (png_byte)value;
  170535. if (shift == 6)
  170536. {
  170537. shift = 0;
  170538. sp--;
  170539. }
  170540. else
  170541. shift += 2;
  170542. dp--;
  170543. }
  170544. break;
  170545. }
  170546. case 4:
  170547. {
  170548. sp = row + (png_size_t)((row_width - 1) >> 1);
  170549. dp = row + (png_size_t)row_width - 1;
  170550. shift = (int)((row_width & 0x01) << 2);
  170551. for (i = 0; i < row_width; i++)
  170552. {
  170553. value = (*sp >> shift) & 0x0f;
  170554. *dp = (png_byte)value;
  170555. if (shift == 4)
  170556. {
  170557. shift = 0;
  170558. sp--;
  170559. }
  170560. else
  170561. shift += 4;
  170562. dp--;
  170563. }
  170564. break;
  170565. }
  170566. }
  170567. row_info->bit_depth = 8;
  170568. row_info->pixel_depth = 8;
  170569. row_info->rowbytes = row_width;
  170570. }
  170571. switch (row_info->bit_depth)
  170572. {
  170573. case 8:
  170574. {
  170575. if (trans != NULL)
  170576. {
  170577. sp = row + (png_size_t)row_width - 1;
  170578. dp = row + (png_size_t)(row_width << 2) - 1;
  170579. for (i = 0; i < row_width; i++)
  170580. {
  170581. if ((int)(*sp) >= num_trans)
  170582. *dp-- = 0xff;
  170583. else
  170584. *dp-- = trans[*sp];
  170585. *dp-- = palette[*sp].blue;
  170586. *dp-- = palette[*sp].green;
  170587. *dp-- = palette[*sp].red;
  170588. sp--;
  170589. }
  170590. row_info->bit_depth = 8;
  170591. row_info->pixel_depth = 32;
  170592. row_info->rowbytes = row_width * 4;
  170593. row_info->color_type = 6;
  170594. row_info->channels = 4;
  170595. }
  170596. else
  170597. {
  170598. sp = row + (png_size_t)row_width - 1;
  170599. dp = row + (png_size_t)(row_width * 3) - 1;
  170600. for (i = 0; i < row_width; i++)
  170601. {
  170602. *dp-- = palette[*sp].blue;
  170603. *dp-- = palette[*sp].green;
  170604. *dp-- = palette[*sp].red;
  170605. sp--;
  170606. }
  170607. row_info->bit_depth = 8;
  170608. row_info->pixel_depth = 24;
  170609. row_info->rowbytes = row_width * 3;
  170610. row_info->color_type = 2;
  170611. row_info->channels = 3;
  170612. }
  170613. break;
  170614. }
  170615. }
  170616. }
  170617. }
  170618. void /* PRIVATE */
  170619. png_do_expand(png_row_infop row_info, png_bytep row,
  170620. png_color_16p trans_value)
  170621. {
  170622. int shift, value;
  170623. png_bytep sp, dp;
  170624. png_uint_32 i;
  170625. png_uint_32 row_width=row_info->width;
  170626. png_debug(1, "in png_do_expand\n");
  170627. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170628. if (row != NULL && row_info != NULL)
  170629. #endif
  170630. {
  170631. if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  170632. {
  170633. png_uint_16 gray = (png_uint_16)(trans_value ? trans_value->gray : 0);
  170634. if (row_info->bit_depth < 8)
  170635. {
  170636. switch (row_info->bit_depth)
  170637. {
  170638. case 1:
  170639. {
  170640. gray = (png_uint_16)((gray&0x01)*0xff);
  170641. sp = row + (png_size_t)((row_width - 1) >> 3);
  170642. dp = row + (png_size_t)row_width - 1;
  170643. shift = 7 - (int)((row_width + 7) & 0x07);
  170644. for (i = 0; i < row_width; i++)
  170645. {
  170646. if ((*sp >> shift) & 0x01)
  170647. *dp = 0xff;
  170648. else
  170649. *dp = 0;
  170650. if (shift == 7)
  170651. {
  170652. shift = 0;
  170653. sp--;
  170654. }
  170655. else
  170656. shift++;
  170657. dp--;
  170658. }
  170659. break;
  170660. }
  170661. case 2:
  170662. {
  170663. gray = (png_uint_16)((gray&0x03)*0x55);
  170664. sp = row + (png_size_t)((row_width - 1) >> 2);
  170665. dp = row + (png_size_t)row_width - 1;
  170666. shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
  170667. for (i = 0; i < row_width; i++)
  170668. {
  170669. value = (*sp >> shift) & 0x03;
  170670. *dp = (png_byte)(value | (value << 2) | (value << 4) |
  170671. (value << 6));
  170672. if (shift == 6)
  170673. {
  170674. shift = 0;
  170675. sp--;
  170676. }
  170677. else
  170678. shift += 2;
  170679. dp--;
  170680. }
  170681. break;
  170682. }
  170683. case 4:
  170684. {
  170685. gray = (png_uint_16)((gray&0x0f)*0x11);
  170686. sp = row + (png_size_t)((row_width - 1) >> 1);
  170687. dp = row + (png_size_t)row_width - 1;
  170688. shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);
  170689. for (i = 0; i < row_width; i++)
  170690. {
  170691. value = (*sp >> shift) & 0x0f;
  170692. *dp = (png_byte)(value | (value << 4));
  170693. if (shift == 4)
  170694. {
  170695. shift = 0;
  170696. sp--;
  170697. }
  170698. else
  170699. shift = 4;
  170700. dp--;
  170701. }
  170702. break;
  170703. }
  170704. }
  170705. row_info->bit_depth = 8;
  170706. row_info->pixel_depth = 8;
  170707. row_info->rowbytes = row_width;
  170708. }
  170709. if (trans_value != NULL)
  170710. {
  170711. if (row_info->bit_depth == 8)
  170712. {
  170713. gray = gray & 0xff;
  170714. sp = row + (png_size_t)row_width - 1;
  170715. dp = row + (png_size_t)(row_width << 1) - 1;
  170716. for (i = 0; i < row_width; i++)
  170717. {
  170718. if (*sp == gray)
  170719. *dp-- = 0;
  170720. else
  170721. *dp-- = 0xff;
  170722. *dp-- = *sp--;
  170723. }
  170724. }
  170725. else if (row_info->bit_depth == 16)
  170726. {
  170727. png_byte gray_high = (gray >> 8) & 0xff;
  170728. png_byte gray_low = gray & 0xff;
  170729. sp = row + row_info->rowbytes - 1;
  170730. dp = row + (row_info->rowbytes << 1) - 1;
  170731. for (i = 0; i < row_width; i++)
  170732. {
  170733. if (*(sp-1) == gray_high && *(sp) == gray_low)
  170734. {
  170735. *dp-- = 0;
  170736. *dp-- = 0;
  170737. }
  170738. else
  170739. {
  170740. *dp-- = 0xff;
  170741. *dp-- = 0xff;
  170742. }
  170743. *dp-- = *sp--;
  170744. *dp-- = *sp--;
  170745. }
  170746. }
  170747. row_info->color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
  170748. row_info->channels = 2;
  170749. row_info->pixel_depth = (png_byte)(row_info->bit_depth << 1);
  170750. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
  170751. row_width);
  170752. }
  170753. }
  170754. else if (row_info->color_type == PNG_COLOR_TYPE_RGB && trans_value)
  170755. {
  170756. if (row_info->bit_depth == 8)
  170757. {
  170758. png_byte red = trans_value->red & 0xff;
  170759. png_byte green = trans_value->green & 0xff;
  170760. png_byte blue = trans_value->blue & 0xff;
  170761. sp = row + (png_size_t)row_info->rowbytes - 1;
  170762. dp = row + (png_size_t)(row_width << 2) - 1;
  170763. for (i = 0; i < row_width; i++)
  170764. {
  170765. if (*(sp - 2) == red && *(sp - 1) == green && *(sp) == blue)
  170766. *dp-- = 0;
  170767. else
  170768. *dp-- = 0xff;
  170769. *dp-- = *sp--;
  170770. *dp-- = *sp--;
  170771. *dp-- = *sp--;
  170772. }
  170773. }
  170774. else if (row_info->bit_depth == 16)
  170775. {
  170776. png_byte red_high = (trans_value->red >> 8) & 0xff;
  170777. png_byte green_high = (trans_value->green >> 8) & 0xff;
  170778. png_byte blue_high = (trans_value->blue >> 8) & 0xff;
  170779. png_byte red_low = trans_value->red & 0xff;
  170780. png_byte green_low = trans_value->green & 0xff;
  170781. png_byte blue_low = trans_value->blue & 0xff;
  170782. sp = row + row_info->rowbytes - 1;
  170783. dp = row + (png_size_t)(row_width << 3) - 1;
  170784. for (i = 0; i < row_width; i++)
  170785. {
  170786. if (*(sp - 5) == red_high &&
  170787. *(sp - 4) == red_low &&
  170788. *(sp - 3) == green_high &&
  170789. *(sp - 2) == green_low &&
  170790. *(sp - 1) == blue_high &&
  170791. *(sp ) == blue_low)
  170792. {
  170793. *dp-- = 0;
  170794. *dp-- = 0;
  170795. }
  170796. else
  170797. {
  170798. *dp-- = 0xff;
  170799. *dp-- = 0xff;
  170800. }
  170801. *dp-- = *sp--;
  170802. *dp-- = *sp--;
  170803. *dp-- = *sp--;
  170804. *dp-- = *sp--;
  170805. *dp-- = *sp--;
  170806. *dp-- = *sp--;
  170807. }
  170808. }
  170809. row_info->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
  170810. row_info->channels = 4;
  170811. row_info->pixel_depth = (png_byte)(row_info->bit_depth << 2);
  170812. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170813. }
  170814. }
  170815. }
  170816. #endif
  170817. #if defined(PNG_READ_DITHER_SUPPORTED)
  170818. void /* PRIVATE */
  170819. png_do_dither(png_row_infop row_info, png_bytep row,
  170820. png_bytep palette_lookup, png_bytep dither_lookup)
  170821. {
  170822. png_bytep sp, dp;
  170823. png_uint_32 i;
  170824. png_uint_32 row_width=row_info->width;
  170825. png_debug(1, "in png_do_dither\n");
  170826. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170827. if (row != NULL && row_info != NULL)
  170828. #endif
  170829. {
  170830. if (row_info->color_type == PNG_COLOR_TYPE_RGB &&
  170831. palette_lookup && row_info->bit_depth == 8)
  170832. {
  170833. int r, g, b, p;
  170834. sp = row;
  170835. dp = row;
  170836. for (i = 0; i < row_width; i++)
  170837. {
  170838. r = *sp++;
  170839. g = *sp++;
  170840. b = *sp++;
  170841. p = (((r >> (8 - PNG_DITHER_RED_BITS)) &
  170842. ((1 << PNG_DITHER_RED_BITS) - 1)) <<
  170843. (PNG_DITHER_GREEN_BITS + PNG_DITHER_BLUE_BITS)) |
  170844. (((g >> (8 - PNG_DITHER_GREEN_BITS)) &
  170845. ((1 << PNG_DITHER_GREEN_BITS) - 1)) <<
  170846. (PNG_DITHER_BLUE_BITS)) |
  170847. ((b >> (8 - PNG_DITHER_BLUE_BITS)) &
  170848. ((1 << PNG_DITHER_BLUE_BITS) - 1));
  170849. *dp++ = palette_lookup[p];
  170850. }
  170851. row_info->color_type = PNG_COLOR_TYPE_PALETTE;
  170852. row_info->channels = 1;
  170853. row_info->pixel_depth = row_info->bit_depth;
  170854. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170855. }
  170856. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA &&
  170857. palette_lookup != NULL && row_info->bit_depth == 8)
  170858. {
  170859. int r, g, b, p;
  170860. sp = row;
  170861. dp = row;
  170862. for (i = 0; i < row_width; i++)
  170863. {
  170864. r = *sp++;
  170865. g = *sp++;
  170866. b = *sp++;
  170867. sp++;
  170868. p = (((r >> (8 - PNG_DITHER_RED_BITS)) &
  170869. ((1 << PNG_DITHER_RED_BITS) - 1)) <<
  170870. (PNG_DITHER_GREEN_BITS + PNG_DITHER_BLUE_BITS)) |
  170871. (((g >> (8 - PNG_DITHER_GREEN_BITS)) &
  170872. ((1 << PNG_DITHER_GREEN_BITS) - 1)) <<
  170873. (PNG_DITHER_BLUE_BITS)) |
  170874. ((b >> (8 - PNG_DITHER_BLUE_BITS)) &
  170875. ((1 << PNG_DITHER_BLUE_BITS) - 1));
  170876. *dp++ = palette_lookup[p];
  170877. }
  170878. row_info->color_type = PNG_COLOR_TYPE_PALETTE;
  170879. row_info->channels = 1;
  170880. row_info->pixel_depth = row_info->bit_depth;
  170881. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170882. }
  170883. else if (row_info->color_type == PNG_COLOR_TYPE_PALETTE &&
  170884. dither_lookup && row_info->bit_depth == 8)
  170885. {
  170886. sp = row;
  170887. for (i = 0; i < row_width; i++, sp++)
  170888. {
  170889. *sp = dither_lookup[*sp];
  170890. }
  170891. }
  170892. }
  170893. }
  170894. #endif
  170895. #ifdef PNG_FLOATING_POINT_SUPPORTED
  170896. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170897. static PNG_CONST int png_gamma_shift[] =
  170898. {0x10, 0x21, 0x42, 0x84, 0x110, 0x248, 0x550, 0xff0, 0x00};
  170899. void /* PRIVATE */
  170900. png_build_gamma_table(png_structp png_ptr)
  170901. {
  170902. png_debug(1, "in png_build_gamma_table\n");
  170903. if (png_ptr->bit_depth <= 8)
  170904. {
  170905. int i;
  170906. double g;
  170907. if (png_ptr->screen_gamma > .000001)
  170908. g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  170909. else
  170910. g = 1.0;
  170911. png_ptr->gamma_table = (png_bytep)png_malloc(png_ptr,
  170912. (png_uint_32)256);
  170913. for (i = 0; i < 256; i++)
  170914. {
  170915. png_ptr->gamma_table[i] = (png_byte)(pow((double)i / 255.0,
  170916. g) * 255.0 + .5);
  170917. }
  170918. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
  170919. defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  170920. if (png_ptr->transformations & ((PNG_BACKGROUND) | PNG_RGB_TO_GRAY))
  170921. {
  170922. g = 1.0 / (png_ptr->gamma);
  170923. png_ptr->gamma_to_1 = (png_bytep)png_malloc(png_ptr,
  170924. (png_uint_32)256);
  170925. for (i = 0; i < 256; i++)
  170926. {
  170927. png_ptr->gamma_to_1[i] = (png_byte)(pow((double)i / 255.0,
  170928. g) * 255.0 + .5);
  170929. }
  170930. png_ptr->gamma_from_1 = (png_bytep)png_malloc(png_ptr,
  170931. (png_uint_32)256);
  170932. if(png_ptr->screen_gamma > 0.000001)
  170933. g = 1.0 / png_ptr->screen_gamma;
  170934. else
  170935. g = png_ptr->gamma; /* probably doing rgb_to_gray */
  170936. for (i = 0; i < 256; i++)
  170937. {
  170938. png_ptr->gamma_from_1[i] = (png_byte)(pow((double)i / 255.0,
  170939. g) * 255.0 + .5);
  170940. }
  170941. }
  170942. #endif /* PNG_READ_BACKGROUND_SUPPORTED || PNG_RGB_TO_GRAY_SUPPORTED */
  170943. }
  170944. else
  170945. {
  170946. double g;
  170947. int i, j, shift, num;
  170948. int sig_bit;
  170949. png_uint_32 ig;
  170950. if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
  170951. {
  170952. sig_bit = (int)png_ptr->sig_bit.red;
  170953. if ((int)png_ptr->sig_bit.green > sig_bit)
  170954. sig_bit = png_ptr->sig_bit.green;
  170955. if ((int)png_ptr->sig_bit.blue > sig_bit)
  170956. sig_bit = png_ptr->sig_bit.blue;
  170957. }
  170958. else
  170959. {
  170960. sig_bit = (int)png_ptr->sig_bit.gray;
  170961. }
  170962. if (sig_bit > 0)
  170963. shift = 16 - sig_bit;
  170964. else
  170965. shift = 0;
  170966. if (png_ptr->transformations & PNG_16_TO_8)
  170967. {
  170968. if (shift < (16 - PNG_MAX_GAMMA_8))
  170969. shift = (16 - PNG_MAX_GAMMA_8);
  170970. }
  170971. if (shift > 8)
  170972. shift = 8;
  170973. if (shift < 0)
  170974. shift = 0;
  170975. png_ptr->gamma_shift = (png_byte)shift;
  170976. num = (1 << (8 - shift));
  170977. if (png_ptr->screen_gamma > .000001)
  170978. g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  170979. else
  170980. g = 1.0;
  170981. png_ptr->gamma_16_table = (png_uint_16pp)png_malloc(png_ptr,
  170982. (png_uint_32)(num * png_sizeof (png_uint_16p)));
  170983. if (png_ptr->transformations & (PNG_16_TO_8 | PNG_BACKGROUND))
  170984. {
  170985. double fin, fout;
  170986. png_uint_32 last, max;
  170987. for (i = 0; i < num; i++)
  170988. {
  170989. png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr,
  170990. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170991. }
  170992. g = 1.0 / g;
  170993. last = 0;
  170994. for (i = 0; i < 256; i++)
  170995. {
  170996. fout = ((double)i + 0.5) / 256.0;
  170997. fin = pow(fout, g);
  170998. max = (png_uint_32)(fin * (double)((png_uint_32)num << 8));
  170999. while (last <= max)
  171000. {
  171001. png_ptr->gamma_16_table[(int)(last & (0xff >> shift))]
  171002. [(int)(last >> (8 - shift))] = (png_uint_16)(
  171003. (png_uint_16)i | ((png_uint_16)i << 8));
  171004. last++;
  171005. }
  171006. }
  171007. while (last < ((png_uint_32)num << 8))
  171008. {
  171009. png_ptr->gamma_16_table[(int)(last & (0xff >> shift))]
  171010. [(int)(last >> (8 - shift))] = (png_uint_16)65535L;
  171011. last++;
  171012. }
  171013. }
  171014. else
  171015. {
  171016. for (i = 0; i < num; i++)
  171017. {
  171018. png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr,
  171019. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  171020. ig = (((png_uint_32)i * (png_uint_32)png_gamma_shift[shift]) >> 4);
  171021. for (j = 0; j < 256; j++)
  171022. {
  171023. png_ptr->gamma_16_table[i][j] =
  171024. (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
  171025. 65535.0, g) * 65535.0 + .5);
  171026. }
  171027. }
  171028. }
  171029. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
  171030. defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  171031. if (png_ptr->transformations & (PNG_BACKGROUND | PNG_RGB_TO_GRAY))
  171032. {
  171033. g = 1.0 / (png_ptr->gamma);
  171034. png_ptr->gamma_16_to_1 = (png_uint_16pp)png_malloc(png_ptr,
  171035. (png_uint_32)(num * png_sizeof (png_uint_16p )));
  171036. for (i = 0; i < num; i++)
  171037. {
  171038. png_ptr->gamma_16_to_1[i] = (png_uint_16p)png_malloc(png_ptr,
  171039. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  171040. ig = (((png_uint_32)i *
  171041. (png_uint_32)png_gamma_shift[shift]) >> 4);
  171042. for (j = 0; j < 256; j++)
  171043. {
  171044. png_ptr->gamma_16_to_1[i][j] =
  171045. (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
  171046. 65535.0, g) * 65535.0 + .5);
  171047. }
  171048. }
  171049. if(png_ptr->screen_gamma > 0.000001)
  171050. g = 1.0 / png_ptr->screen_gamma;
  171051. else
  171052. g = png_ptr->gamma; /* probably doing rgb_to_gray */
  171053. png_ptr->gamma_16_from_1 = (png_uint_16pp)png_malloc(png_ptr,
  171054. (png_uint_32)(num * png_sizeof (png_uint_16p)));
  171055. for (i = 0; i < num; i++)
  171056. {
  171057. png_ptr->gamma_16_from_1[i] = (png_uint_16p)png_malloc(png_ptr,
  171058. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  171059. ig = (((png_uint_32)i *
  171060. (png_uint_32)png_gamma_shift[shift]) >> 4);
  171061. for (j = 0; j < 256; j++)
  171062. {
  171063. png_ptr->gamma_16_from_1[i][j] =
  171064. (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
  171065. 65535.0, g) * 65535.0 + .5);
  171066. }
  171067. }
  171068. }
  171069. #endif /* PNG_READ_BACKGROUND_SUPPORTED || PNG_RGB_TO_GRAY_SUPPORTED */
  171070. }
  171071. }
  171072. #endif
  171073. #endif
  171074. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  171075. void /* PRIVATE */
  171076. png_do_read_intrapixel(png_row_infop row_info, png_bytep row)
  171077. {
  171078. png_debug(1, "in png_do_read_intrapixel\n");
  171079. if (
  171080. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  171081. row != NULL && row_info != NULL &&
  171082. #endif
  171083. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  171084. {
  171085. int bytes_per_pixel;
  171086. png_uint_32 row_width = row_info->width;
  171087. if (row_info->bit_depth == 8)
  171088. {
  171089. png_bytep rp;
  171090. png_uint_32 i;
  171091. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  171092. bytes_per_pixel = 3;
  171093. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  171094. bytes_per_pixel = 4;
  171095. else
  171096. return;
  171097. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  171098. {
  171099. *(rp) = (png_byte)((256 + *rp + *(rp+1))&0xff);
  171100. *(rp+2) = (png_byte)((256 + *(rp+2) + *(rp+1))&0xff);
  171101. }
  171102. }
  171103. else if (row_info->bit_depth == 16)
  171104. {
  171105. png_bytep rp;
  171106. png_uint_32 i;
  171107. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  171108. bytes_per_pixel = 6;
  171109. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  171110. bytes_per_pixel = 8;
  171111. else
  171112. return;
  171113. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  171114. {
  171115. png_uint_32 s0 = (*(rp ) << 8) | *(rp+1);
  171116. png_uint_32 s1 = (*(rp+2) << 8) | *(rp+3);
  171117. png_uint_32 s2 = (*(rp+4) << 8) | *(rp+5);
  171118. png_uint_32 red = (png_uint_32)((s0+s1+65536L) & 0xffffL);
  171119. png_uint_32 blue = (png_uint_32)((s2+s1+65536L) & 0xffffL);
  171120. *(rp ) = (png_byte)((red >> 8) & 0xff);
  171121. *(rp+1) = (png_byte)(red & 0xff);
  171122. *(rp+4) = (png_byte)((blue >> 8) & 0xff);
  171123. *(rp+5) = (png_byte)(blue & 0xff);
  171124. }
  171125. }
  171126. }
  171127. }
  171128. #endif /* PNG_MNG_FEATURES_SUPPORTED */
  171129. #endif /* PNG_READ_SUPPORTED */
  171130. /*** End of inlined file: pngrtran.c ***/
  171131. /*** Start of inlined file: pngrutil.c ***/
  171132. #define PNG_INTERNAL
  171133. #if defined(PNG_READ_SUPPORTED)
  171134. #if defined(_WIN32_WCE) && (_WIN32_WCE<0x500)
  171135. # define WIN32_WCE_OLD
  171136. #endif
  171137. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171138. # if defined(WIN32_WCE_OLD)
  171139. __inline double png_strtod(png_structp png_ptr, PNG_CONST char *nptr, char **endptr)
  171140. {
  171141. double result = 0;
  171142. int len;
  171143. wchar_t *str, *end;
  171144. len = MultiByteToWideChar(CP_ACP, 0, nptr, -1, NULL, 0);
  171145. str = (wchar_t *)png_malloc(png_ptr, len * sizeof(wchar_t));
  171146. if ( NULL != str )
  171147. {
  171148. MultiByteToWideChar(CP_ACP, 0, nptr, -1, str, len);
  171149. result = wcstod(str, &end);
  171150. len = WideCharToMultiByte(CP_ACP, 0, end, -1, NULL, 0, NULL, NULL);
  171151. *endptr = (char *)nptr + (png_strlen(nptr) - len + 1);
  171152. png_free(png_ptr, str);
  171153. }
  171154. return result;
  171155. }
  171156. # else
  171157. # define png_strtod(p,a,b) strtod(a,b)
  171158. # endif
  171159. #endif
  171160. png_uint_32 PNGAPI
  171161. png_get_uint_31(png_structp png_ptr, png_bytep buf)
  171162. {
  171163. png_uint_32 i = png_get_uint_32(buf);
  171164. if (i > PNG_UINT_31_MAX)
  171165. png_error(png_ptr, "PNG unsigned integer out of range.");
  171166. return (i);
  171167. }
  171168. #ifndef PNG_READ_BIG_ENDIAN_SUPPORTED
  171169. png_uint_32 PNGAPI
  171170. png_get_uint_32(png_bytep buf)
  171171. {
  171172. png_uint_32 i = ((png_uint_32)(*buf) << 24) +
  171173. ((png_uint_32)(*(buf + 1)) << 16) +
  171174. ((png_uint_32)(*(buf + 2)) << 8) +
  171175. (png_uint_32)(*(buf + 3));
  171176. return (i);
  171177. }
  171178. png_int_32 PNGAPI
  171179. png_get_int_32(png_bytep buf)
  171180. {
  171181. png_int_32 i = ((png_int_32)(*buf) << 24) +
  171182. ((png_int_32)(*(buf + 1)) << 16) +
  171183. ((png_int_32)(*(buf + 2)) << 8) +
  171184. (png_int_32)(*(buf + 3));
  171185. return (i);
  171186. }
  171187. png_uint_16 PNGAPI
  171188. png_get_uint_16(png_bytep buf)
  171189. {
  171190. png_uint_16 i = (png_uint_16)(((png_uint_16)(*buf) << 8) +
  171191. (png_uint_16)(*(buf + 1)));
  171192. return (i);
  171193. }
  171194. #endif /* PNG_READ_BIG_ENDIAN_SUPPORTED */
  171195. void /* PRIVATE */
  171196. png_crc_read(png_structp png_ptr, png_bytep buf, png_size_t length)
  171197. {
  171198. if(png_ptr == NULL) return;
  171199. png_read_data(png_ptr, buf, length);
  171200. png_calculate_crc(png_ptr, buf, length);
  171201. }
  171202. int /* PRIVATE */
  171203. png_crc_finish(png_structp png_ptr, png_uint_32 skip)
  171204. {
  171205. png_size_t i;
  171206. png_size_t istop = png_ptr->zbuf_size;
  171207. for (i = (png_size_t)skip; i > istop; i -= istop)
  171208. {
  171209. png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
  171210. }
  171211. if (i)
  171212. {
  171213. png_crc_read(png_ptr, png_ptr->zbuf, i);
  171214. }
  171215. if (png_crc_error(png_ptr))
  171216. {
  171217. if (((png_ptr->chunk_name[0] & 0x20) && /* Ancillary */
  171218. !(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)) ||
  171219. (!(png_ptr->chunk_name[0] & 0x20) && /* Critical */
  171220. (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_USE)))
  171221. {
  171222. png_chunk_warning(png_ptr, "CRC error");
  171223. }
  171224. else
  171225. {
  171226. png_chunk_error(png_ptr, "CRC error");
  171227. }
  171228. return (1);
  171229. }
  171230. return (0);
  171231. }
  171232. int /* PRIVATE */
  171233. png_crc_error(png_structp png_ptr)
  171234. {
  171235. png_byte crc_bytes[4];
  171236. png_uint_32 crc;
  171237. int need_crc = 1;
  171238. if (png_ptr->chunk_name[0] & 0x20) /* ancillary */
  171239. {
  171240. if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
  171241. (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
  171242. need_crc = 0;
  171243. }
  171244. else /* critical */
  171245. {
  171246. if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE)
  171247. need_crc = 0;
  171248. }
  171249. png_read_data(png_ptr, crc_bytes, 4);
  171250. if (need_crc)
  171251. {
  171252. crc = png_get_uint_32(crc_bytes);
  171253. return ((int)(crc != png_ptr->crc));
  171254. }
  171255. else
  171256. return (0);
  171257. }
  171258. #if defined(PNG_READ_zTXt_SUPPORTED) || defined(PNG_READ_iTXt_SUPPORTED) || \
  171259. defined(PNG_READ_iCCP_SUPPORTED)
  171260. png_charp /* PRIVATE */
  171261. png_decompress_chunk(png_structp png_ptr, int comp_type,
  171262. png_charp chunkdata, png_size_t chunklength,
  171263. png_size_t prefix_size, png_size_t *newlength)
  171264. {
  171265. static PNG_CONST char msg[] = "Error decoding compressed text";
  171266. png_charp text;
  171267. png_size_t text_size;
  171268. if (comp_type == PNG_COMPRESSION_TYPE_BASE)
  171269. {
  171270. int ret = Z_OK;
  171271. png_ptr->zstream.next_in = (png_bytep)(chunkdata + prefix_size);
  171272. png_ptr->zstream.avail_in = (uInt)(chunklength - prefix_size);
  171273. png_ptr->zstream.next_out = png_ptr->zbuf;
  171274. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  171275. text_size = 0;
  171276. text = NULL;
  171277. while (png_ptr->zstream.avail_in)
  171278. {
  171279. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  171280. if (ret != Z_OK && ret != Z_STREAM_END)
  171281. {
  171282. if (png_ptr->zstream.msg != NULL)
  171283. png_warning(png_ptr, png_ptr->zstream.msg);
  171284. else
  171285. png_warning(png_ptr, msg);
  171286. inflateReset(&png_ptr->zstream);
  171287. png_ptr->zstream.avail_in = 0;
  171288. if (text == NULL)
  171289. {
  171290. text_size = prefix_size + png_sizeof(msg) + 1;
  171291. text = (png_charp)png_malloc_warn(png_ptr, text_size);
  171292. if (text == NULL)
  171293. {
  171294. png_free(png_ptr,chunkdata);
  171295. png_error(png_ptr,"Not enough memory to decompress chunk");
  171296. }
  171297. png_memcpy(text, chunkdata, prefix_size);
  171298. }
  171299. text[text_size - 1] = 0x00;
  171300. text_size = (png_size_t)(chunklength - (text - chunkdata) - 1);
  171301. text_size = png_sizeof(msg) > text_size ? text_size :
  171302. png_sizeof(msg);
  171303. png_memcpy(text + prefix_size, msg, text_size + 1);
  171304. break;
  171305. }
  171306. if (!png_ptr->zstream.avail_out || ret == Z_STREAM_END)
  171307. {
  171308. if (text == NULL)
  171309. {
  171310. text_size = prefix_size +
  171311. png_ptr->zbuf_size - png_ptr->zstream.avail_out;
  171312. text = (png_charp)png_malloc_warn(png_ptr, text_size + 1);
  171313. if (text == NULL)
  171314. {
  171315. png_free(png_ptr,chunkdata);
  171316. png_error(png_ptr,"Not enough memory to decompress chunk.");
  171317. }
  171318. png_memcpy(text + prefix_size, png_ptr->zbuf,
  171319. text_size - prefix_size);
  171320. png_memcpy(text, chunkdata, prefix_size);
  171321. *(text + text_size) = 0x00;
  171322. }
  171323. else
  171324. {
  171325. png_charp tmp;
  171326. tmp = text;
  171327. text = (png_charp)png_malloc_warn(png_ptr,
  171328. (png_uint_32)(text_size +
  171329. png_ptr->zbuf_size - png_ptr->zstream.avail_out + 1));
  171330. if (text == NULL)
  171331. {
  171332. png_free(png_ptr, tmp);
  171333. png_free(png_ptr, chunkdata);
  171334. png_error(png_ptr,"Not enough memory to decompress chunk..");
  171335. }
  171336. png_memcpy(text, tmp, text_size);
  171337. png_free(png_ptr, tmp);
  171338. png_memcpy(text + text_size, png_ptr->zbuf,
  171339. (png_ptr->zbuf_size - png_ptr->zstream.avail_out));
  171340. text_size += png_ptr->zbuf_size - png_ptr->zstream.avail_out;
  171341. *(text + text_size) = 0x00;
  171342. }
  171343. if (ret == Z_STREAM_END)
  171344. break;
  171345. else
  171346. {
  171347. png_ptr->zstream.next_out = png_ptr->zbuf;
  171348. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  171349. }
  171350. }
  171351. }
  171352. if (ret != Z_STREAM_END)
  171353. {
  171354. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  171355. char umsg[52];
  171356. if (ret == Z_BUF_ERROR)
  171357. png_snprintf(umsg, 52,
  171358. "Buffer error in compressed datastream in %s chunk",
  171359. png_ptr->chunk_name);
  171360. else if (ret == Z_DATA_ERROR)
  171361. png_snprintf(umsg, 52,
  171362. "Data error in compressed datastream in %s chunk",
  171363. png_ptr->chunk_name);
  171364. else
  171365. png_snprintf(umsg, 52,
  171366. "Incomplete compressed datastream in %s chunk",
  171367. png_ptr->chunk_name);
  171368. png_warning(png_ptr, umsg);
  171369. #else
  171370. png_warning(png_ptr,
  171371. "Incomplete compressed datastream in chunk other than IDAT");
  171372. #endif
  171373. text_size=prefix_size;
  171374. if (text == NULL)
  171375. {
  171376. text = (png_charp)png_malloc_warn(png_ptr, text_size+1);
  171377. if (text == NULL)
  171378. {
  171379. png_free(png_ptr, chunkdata);
  171380. png_error(png_ptr,"Not enough memory for text.");
  171381. }
  171382. png_memcpy(text, chunkdata, prefix_size);
  171383. }
  171384. *(text + text_size) = 0x00;
  171385. }
  171386. inflateReset(&png_ptr->zstream);
  171387. png_ptr->zstream.avail_in = 0;
  171388. png_free(png_ptr, chunkdata);
  171389. chunkdata = text;
  171390. *newlength=text_size;
  171391. }
  171392. else /* if (comp_type != PNG_COMPRESSION_TYPE_BASE) */
  171393. {
  171394. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  171395. char umsg[50];
  171396. png_snprintf(umsg, 50,
  171397. "Unknown zTXt compression type %d", comp_type);
  171398. png_warning(png_ptr, umsg);
  171399. #else
  171400. png_warning(png_ptr, "Unknown zTXt compression type");
  171401. #endif
  171402. *(chunkdata + prefix_size) = 0x00;
  171403. *newlength=prefix_size;
  171404. }
  171405. return chunkdata;
  171406. }
  171407. #endif
  171408. void /* PRIVATE */
  171409. png_handle_IHDR(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171410. {
  171411. png_byte buf[13];
  171412. png_uint_32 width, height;
  171413. int bit_depth, color_type, compression_type, filter_type;
  171414. int interlace_type;
  171415. png_debug(1, "in png_handle_IHDR\n");
  171416. if (png_ptr->mode & PNG_HAVE_IHDR)
  171417. png_error(png_ptr, "Out of place IHDR");
  171418. if (length != 13)
  171419. png_error(png_ptr, "Invalid IHDR chunk");
  171420. png_ptr->mode |= PNG_HAVE_IHDR;
  171421. png_crc_read(png_ptr, buf, 13);
  171422. png_crc_finish(png_ptr, 0);
  171423. width = png_get_uint_31(png_ptr, buf);
  171424. height = png_get_uint_31(png_ptr, buf + 4);
  171425. bit_depth = buf[8];
  171426. color_type = buf[9];
  171427. compression_type = buf[10];
  171428. filter_type = buf[11];
  171429. interlace_type = buf[12];
  171430. png_ptr->width = width;
  171431. png_ptr->height = height;
  171432. png_ptr->bit_depth = (png_byte)bit_depth;
  171433. png_ptr->interlaced = (png_byte)interlace_type;
  171434. png_ptr->color_type = (png_byte)color_type;
  171435. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  171436. png_ptr->filter_type = (png_byte)filter_type;
  171437. #endif
  171438. png_ptr->compression_type = (png_byte)compression_type;
  171439. switch (png_ptr->color_type)
  171440. {
  171441. case PNG_COLOR_TYPE_GRAY:
  171442. case PNG_COLOR_TYPE_PALETTE:
  171443. png_ptr->channels = 1;
  171444. break;
  171445. case PNG_COLOR_TYPE_RGB:
  171446. png_ptr->channels = 3;
  171447. break;
  171448. case PNG_COLOR_TYPE_GRAY_ALPHA:
  171449. png_ptr->channels = 2;
  171450. break;
  171451. case PNG_COLOR_TYPE_RGB_ALPHA:
  171452. png_ptr->channels = 4;
  171453. break;
  171454. }
  171455. png_ptr->pixel_depth = (png_byte)(png_ptr->bit_depth *
  171456. png_ptr->channels);
  171457. png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->width);
  171458. png_debug1(3,"bit_depth = %d\n", png_ptr->bit_depth);
  171459. png_debug1(3,"channels = %d\n", png_ptr->channels);
  171460. png_debug1(3,"rowbytes = %lu\n", png_ptr->rowbytes);
  171461. png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth,
  171462. color_type, interlace_type, compression_type, filter_type);
  171463. }
  171464. void /* PRIVATE */
  171465. png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171466. {
  171467. png_color palette[PNG_MAX_PALETTE_LENGTH];
  171468. int num, i;
  171469. #ifndef PNG_NO_POINTER_INDEXING
  171470. png_colorp pal_ptr;
  171471. #endif
  171472. png_debug(1, "in png_handle_PLTE\n");
  171473. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171474. png_error(png_ptr, "Missing IHDR before PLTE");
  171475. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171476. {
  171477. png_warning(png_ptr, "Invalid PLTE after IDAT");
  171478. png_crc_finish(png_ptr, length);
  171479. return;
  171480. }
  171481. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171482. png_error(png_ptr, "Duplicate PLTE chunk");
  171483. png_ptr->mode |= PNG_HAVE_PLTE;
  171484. if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR))
  171485. {
  171486. png_warning(png_ptr,
  171487. "Ignoring PLTE chunk in grayscale PNG");
  171488. png_crc_finish(png_ptr, length);
  171489. return;
  171490. }
  171491. #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
  171492. if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
  171493. {
  171494. png_crc_finish(png_ptr, length);
  171495. return;
  171496. }
  171497. #endif
  171498. if (length > 3*PNG_MAX_PALETTE_LENGTH || length % 3)
  171499. {
  171500. if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
  171501. {
  171502. png_warning(png_ptr, "Invalid palette chunk");
  171503. png_crc_finish(png_ptr, length);
  171504. return;
  171505. }
  171506. else
  171507. {
  171508. png_error(png_ptr, "Invalid palette chunk");
  171509. }
  171510. }
  171511. num = (int)length / 3;
  171512. #ifndef PNG_NO_POINTER_INDEXING
  171513. for (i = 0, pal_ptr = palette; i < num; i++, pal_ptr++)
  171514. {
  171515. png_byte buf[3];
  171516. png_crc_read(png_ptr, buf, 3);
  171517. pal_ptr->red = buf[0];
  171518. pal_ptr->green = buf[1];
  171519. pal_ptr->blue = buf[2];
  171520. }
  171521. #else
  171522. for (i = 0; i < num; i++)
  171523. {
  171524. png_byte buf[3];
  171525. png_crc_read(png_ptr, buf, 3);
  171526. palette[i].red = buf[0];
  171527. palette[i].green = buf[1];
  171528. palette[i].blue = buf[2];
  171529. }
  171530. #endif
  171531. #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
  171532. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171533. #endif
  171534. {
  171535. png_crc_finish(png_ptr, 0);
  171536. }
  171537. #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
  171538. else if (png_crc_error(png_ptr)) /* Only if we have a CRC error */
  171539. {
  171540. if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_USE))
  171541. {
  171542. if (png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)
  171543. {
  171544. png_chunk_error(png_ptr, "CRC error");
  171545. }
  171546. else
  171547. {
  171548. png_chunk_warning(png_ptr, "CRC error");
  171549. return;
  171550. }
  171551. }
  171552. else if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN))
  171553. {
  171554. png_chunk_warning(png_ptr, "CRC error");
  171555. }
  171556. }
  171557. #endif
  171558. png_set_PLTE(png_ptr, info_ptr, palette, num);
  171559. #if defined(PNG_READ_tRNS_SUPPORTED)
  171560. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171561. {
  171562. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  171563. {
  171564. if (png_ptr->num_trans > (png_uint_16)num)
  171565. {
  171566. png_warning(png_ptr, "Truncating incorrect tRNS chunk length");
  171567. png_ptr->num_trans = (png_uint_16)num;
  171568. }
  171569. if (info_ptr->num_trans > (png_uint_16)num)
  171570. {
  171571. png_warning(png_ptr, "Truncating incorrect info tRNS chunk length");
  171572. info_ptr->num_trans = (png_uint_16)num;
  171573. }
  171574. }
  171575. }
  171576. #endif
  171577. }
  171578. void /* PRIVATE */
  171579. png_handle_IEND(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171580. {
  171581. png_debug(1, "in png_handle_IEND\n");
  171582. if (!(png_ptr->mode & PNG_HAVE_IHDR) || !(png_ptr->mode & PNG_HAVE_IDAT))
  171583. {
  171584. png_error(png_ptr, "No image in file");
  171585. }
  171586. png_ptr->mode |= (PNG_AFTER_IDAT | PNG_HAVE_IEND);
  171587. if (length != 0)
  171588. {
  171589. png_warning(png_ptr, "Incorrect IEND chunk length");
  171590. }
  171591. png_crc_finish(png_ptr, length);
  171592. info_ptr =info_ptr; /* quiet compiler warnings about unused info_ptr */
  171593. }
  171594. #if defined(PNG_READ_gAMA_SUPPORTED)
  171595. void /* PRIVATE */
  171596. png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171597. {
  171598. png_fixed_point igamma;
  171599. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171600. float file_gamma;
  171601. #endif
  171602. png_byte buf[4];
  171603. png_debug(1, "in png_handle_gAMA\n");
  171604. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171605. png_error(png_ptr, "Missing IHDR before gAMA");
  171606. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171607. {
  171608. png_warning(png_ptr, "Invalid gAMA after IDAT");
  171609. png_crc_finish(png_ptr, length);
  171610. return;
  171611. }
  171612. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171613. png_warning(png_ptr, "Out of place gAMA chunk");
  171614. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  171615. #if defined(PNG_READ_sRGB_SUPPORTED)
  171616. && !(info_ptr->valid & PNG_INFO_sRGB)
  171617. #endif
  171618. )
  171619. {
  171620. png_warning(png_ptr, "Duplicate gAMA chunk");
  171621. png_crc_finish(png_ptr, length);
  171622. return;
  171623. }
  171624. if (length != 4)
  171625. {
  171626. png_warning(png_ptr, "Incorrect gAMA chunk length");
  171627. png_crc_finish(png_ptr, length);
  171628. return;
  171629. }
  171630. png_crc_read(png_ptr, buf, 4);
  171631. if (png_crc_finish(png_ptr, 0))
  171632. return;
  171633. igamma = (png_fixed_point)png_get_uint_32(buf);
  171634. if (igamma == 0)
  171635. {
  171636. png_warning(png_ptr,
  171637. "Ignoring gAMA chunk with gamma=0");
  171638. return;
  171639. }
  171640. #if defined(PNG_READ_sRGB_SUPPORTED)
  171641. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB))
  171642. if (PNG_OUT_OF_RANGE(igamma, 45500L, 500))
  171643. {
  171644. png_warning(png_ptr,
  171645. "Ignoring incorrect gAMA value when sRGB is also present");
  171646. #ifndef PNG_NO_CONSOLE_IO
  171647. fprintf(stderr, "gamma = (%d/100000)\n", (int)igamma);
  171648. #endif
  171649. return;
  171650. }
  171651. #endif /* PNG_READ_sRGB_SUPPORTED */
  171652. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171653. file_gamma = (float)igamma / (float)100000.0;
  171654. # ifdef PNG_READ_GAMMA_SUPPORTED
  171655. png_ptr->gamma = file_gamma;
  171656. # endif
  171657. png_set_gAMA(png_ptr, info_ptr, file_gamma);
  171658. #endif
  171659. #ifdef PNG_FIXED_POINT_SUPPORTED
  171660. png_set_gAMA_fixed(png_ptr, info_ptr, igamma);
  171661. #endif
  171662. }
  171663. #endif
  171664. #if defined(PNG_READ_sBIT_SUPPORTED)
  171665. void /* PRIVATE */
  171666. png_handle_sBIT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171667. {
  171668. png_size_t truelen;
  171669. png_byte buf[4];
  171670. png_debug(1, "in png_handle_sBIT\n");
  171671. buf[0] = buf[1] = buf[2] = buf[3] = 0;
  171672. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171673. png_error(png_ptr, "Missing IHDR before sBIT");
  171674. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171675. {
  171676. png_warning(png_ptr, "Invalid sBIT after IDAT");
  171677. png_crc_finish(png_ptr, length);
  171678. return;
  171679. }
  171680. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171681. {
  171682. png_warning(png_ptr, "Out of place sBIT chunk");
  171683. }
  171684. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT))
  171685. {
  171686. png_warning(png_ptr, "Duplicate sBIT chunk");
  171687. png_crc_finish(png_ptr, length);
  171688. return;
  171689. }
  171690. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171691. truelen = 3;
  171692. else
  171693. truelen = (png_size_t)png_ptr->channels;
  171694. if (length != truelen || length > 4)
  171695. {
  171696. png_warning(png_ptr, "Incorrect sBIT chunk length");
  171697. png_crc_finish(png_ptr, length);
  171698. return;
  171699. }
  171700. png_crc_read(png_ptr, buf, truelen);
  171701. if (png_crc_finish(png_ptr, 0))
  171702. return;
  171703. if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
  171704. {
  171705. png_ptr->sig_bit.red = buf[0];
  171706. png_ptr->sig_bit.green = buf[1];
  171707. png_ptr->sig_bit.blue = buf[2];
  171708. png_ptr->sig_bit.alpha = buf[3];
  171709. }
  171710. else
  171711. {
  171712. png_ptr->sig_bit.gray = buf[0];
  171713. png_ptr->sig_bit.red = buf[0];
  171714. png_ptr->sig_bit.green = buf[0];
  171715. png_ptr->sig_bit.blue = buf[0];
  171716. png_ptr->sig_bit.alpha = buf[1];
  171717. }
  171718. png_set_sBIT(png_ptr, info_ptr, &(png_ptr->sig_bit));
  171719. }
  171720. #endif
  171721. #if defined(PNG_READ_cHRM_SUPPORTED)
  171722. void /* PRIVATE */
  171723. png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171724. {
  171725. png_byte buf[4];
  171726. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171727. float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
  171728. #endif
  171729. png_fixed_point int_x_white, int_y_white, int_x_red, int_y_red, int_x_green,
  171730. int_y_green, int_x_blue, int_y_blue;
  171731. png_uint_32 uint_x, uint_y;
  171732. png_debug(1, "in png_handle_cHRM\n");
  171733. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171734. png_error(png_ptr, "Missing IHDR before cHRM");
  171735. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171736. {
  171737. png_warning(png_ptr, "Invalid cHRM after IDAT");
  171738. png_crc_finish(png_ptr, length);
  171739. return;
  171740. }
  171741. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171742. png_warning(png_ptr, "Missing PLTE before cHRM");
  171743. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM)
  171744. #if defined(PNG_READ_sRGB_SUPPORTED)
  171745. && !(info_ptr->valid & PNG_INFO_sRGB)
  171746. #endif
  171747. )
  171748. {
  171749. png_warning(png_ptr, "Duplicate cHRM chunk");
  171750. png_crc_finish(png_ptr, length);
  171751. return;
  171752. }
  171753. if (length != 32)
  171754. {
  171755. png_warning(png_ptr, "Incorrect cHRM chunk length");
  171756. png_crc_finish(png_ptr, length);
  171757. return;
  171758. }
  171759. png_crc_read(png_ptr, buf, 4);
  171760. uint_x = png_get_uint_32(buf);
  171761. png_crc_read(png_ptr, buf, 4);
  171762. uint_y = png_get_uint_32(buf);
  171763. if (uint_x > 80000L || uint_y > 80000L ||
  171764. uint_x + uint_y > 100000L)
  171765. {
  171766. png_warning(png_ptr, "Invalid cHRM white point");
  171767. png_crc_finish(png_ptr, 24);
  171768. return;
  171769. }
  171770. int_x_white = (png_fixed_point)uint_x;
  171771. int_y_white = (png_fixed_point)uint_y;
  171772. png_crc_read(png_ptr, buf, 4);
  171773. uint_x = png_get_uint_32(buf);
  171774. png_crc_read(png_ptr, buf, 4);
  171775. uint_y = png_get_uint_32(buf);
  171776. if (uint_x + uint_y > 100000L)
  171777. {
  171778. png_warning(png_ptr, "Invalid cHRM red point");
  171779. png_crc_finish(png_ptr, 16);
  171780. return;
  171781. }
  171782. int_x_red = (png_fixed_point)uint_x;
  171783. int_y_red = (png_fixed_point)uint_y;
  171784. png_crc_read(png_ptr, buf, 4);
  171785. uint_x = png_get_uint_32(buf);
  171786. png_crc_read(png_ptr, buf, 4);
  171787. uint_y = png_get_uint_32(buf);
  171788. if (uint_x + uint_y > 100000L)
  171789. {
  171790. png_warning(png_ptr, "Invalid cHRM green point");
  171791. png_crc_finish(png_ptr, 8);
  171792. return;
  171793. }
  171794. int_x_green = (png_fixed_point)uint_x;
  171795. int_y_green = (png_fixed_point)uint_y;
  171796. png_crc_read(png_ptr, buf, 4);
  171797. uint_x = png_get_uint_32(buf);
  171798. png_crc_read(png_ptr, buf, 4);
  171799. uint_y = png_get_uint_32(buf);
  171800. if (uint_x + uint_y > 100000L)
  171801. {
  171802. png_warning(png_ptr, "Invalid cHRM blue point");
  171803. png_crc_finish(png_ptr, 0);
  171804. return;
  171805. }
  171806. int_x_blue = (png_fixed_point)uint_x;
  171807. int_y_blue = (png_fixed_point)uint_y;
  171808. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171809. white_x = (float)int_x_white / (float)100000.0;
  171810. white_y = (float)int_y_white / (float)100000.0;
  171811. red_x = (float)int_x_red / (float)100000.0;
  171812. red_y = (float)int_y_red / (float)100000.0;
  171813. green_x = (float)int_x_green / (float)100000.0;
  171814. green_y = (float)int_y_green / (float)100000.0;
  171815. blue_x = (float)int_x_blue / (float)100000.0;
  171816. blue_y = (float)int_y_blue / (float)100000.0;
  171817. #endif
  171818. #if defined(PNG_READ_sRGB_SUPPORTED)
  171819. if ((info_ptr != NULL) && (info_ptr->valid & PNG_INFO_sRGB))
  171820. {
  171821. if (PNG_OUT_OF_RANGE(int_x_white, 31270, 1000) ||
  171822. PNG_OUT_OF_RANGE(int_y_white, 32900, 1000) ||
  171823. PNG_OUT_OF_RANGE(int_x_red, 64000L, 1000) ||
  171824. PNG_OUT_OF_RANGE(int_y_red, 33000, 1000) ||
  171825. PNG_OUT_OF_RANGE(int_x_green, 30000, 1000) ||
  171826. PNG_OUT_OF_RANGE(int_y_green, 60000L, 1000) ||
  171827. PNG_OUT_OF_RANGE(int_x_blue, 15000, 1000) ||
  171828. PNG_OUT_OF_RANGE(int_y_blue, 6000, 1000))
  171829. {
  171830. png_warning(png_ptr,
  171831. "Ignoring incorrect cHRM value when sRGB is also present");
  171832. #ifndef PNG_NO_CONSOLE_IO
  171833. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171834. fprintf(stderr,"wx=%f, wy=%f, rx=%f, ry=%f\n",
  171835. white_x, white_y, red_x, red_y);
  171836. fprintf(stderr,"gx=%f, gy=%f, bx=%f, by=%f\n",
  171837. green_x, green_y, blue_x, blue_y);
  171838. #else
  171839. fprintf(stderr,"wx=%ld, wy=%ld, rx=%ld, ry=%ld\n",
  171840. int_x_white, int_y_white, int_x_red, int_y_red);
  171841. fprintf(stderr,"gx=%ld, gy=%ld, bx=%ld, by=%ld\n",
  171842. int_x_green, int_y_green, int_x_blue, int_y_blue);
  171843. #endif
  171844. #endif /* PNG_NO_CONSOLE_IO */
  171845. }
  171846. png_crc_finish(png_ptr, 0);
  171847. return;
  171848. }
  171849. #endif /* PNG_READ_sRGB_SUPPORTED */
  171850. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171851. png_set_cHRM(png_ptr, info_ptr,
  171852. white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
  171853. #endif
  171854. #ifdef PNG_FIXED_POINT_SUPPORTED
  171855. png_set_cHRM_fixed(png_ptr, info_ptr,
  171856. int_x_white, int_y_white, int_x_red, int_y_red, int_x_green,
  171857. int_y_green, int_x_blue, int_y_blue);
  171858. #endif
  171859. if (png_crc_finish(png_ptr, 0))
  171860. return;
  171861. }
  171862. #endif
  171863. #if defined(PNG_READ_sRGB_SUPPORTED)
  171864. void /* PRIVATE */
  171865. png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171866. {
  171867. int intent;
  171868. png_byte buf[1];
  171869. png_debug(1, "in png_handle_sRGB\n");
  171870. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171871. png_error(png_ptr, "Missing IHDR before sRGB");
  171872. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171873. {
  171874. png_warning(png_ptr, "Invalid sRGB after IDAT");
  171875. png_crc_finish(png_ptr, length);
  171876. return;
  171877. }
  171878. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171879. png_warning(png_ptr, "Out of place sRGB chunk");
  171880. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB))
  171881. {
  171882. png_warning(png_ptr, "Duplicate sRGB chunk");
  171883. png_crc_finish(png_ptr, length);
  171884. return;
  171885. }
  171886. if (length != 1)
  171887. {
  171888. png_warning(png_ptr, "Incorrect sRGB chunk length");
  171889. png_crc_finish(png_ptr, length);
  171890. return;
  171891. }
  171892. png_crc_read(png_ptr, buf, 1);
  171893. if (png_crc_finish(png_ptr, 0))
  171894. return;
  171895. intent = buf[0];
  171896. if (intent >= PNG_sRGB_INTENT_LAST)
  171897. {
  171898. png_warning(png_ptr, "Unknown sRGB intent");
  171899. return;
  171900. }
  171901. #if defined(PNG_READ_gAMA_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED)
  171902. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA))
  171903. {
  171904. png_fixed_point igamma;
  171905. #ifdef PNG_FIXED_POINT_SUPPORTED
  171906. igamma=info_ptr->int_gamma;
  171907. #else
  171908. # ifdef PNG_FLOATING_POINT_SUPPORTED
  171909. igamma=(png_fixed_point)(info_ptr->gamma * 100000.);
  171910. # endif
  171911. #endif
  171912. if (PNG_OUT_OF_RANGE(igamma, 45500L, 500))
  171913. {
  171914. png_warning(png_ptr,
  171915. "Ignoring incorrect gAMA value when sRGB is also present");
  171916. #ifndef PNG_NO_CONSOLE_IO
  171917. # ifdef PNG_FIXED_POINT_SUPPORTED
  171918. fprintf(stderr,"incorrect gamma=(%d/100000)\n",(int)png_ptr->int_gamma);
  171919. # else
  171920. # ifdef PNG_FLOATING_POINT_SUPPORTED
  171921. fprintf(stderr,"incorrect gamma=%f\n",png_ptr->gamma);
  171922. # endif
  171923. # endif
  171924. #endif
  171925. }
  171926. }
  171927. #endif /* PNG_READ_gAMA_SUPPORTED */
  171928. #ifdef PNG_READ_cHRM_SUPPORTED
  171929. #ifdef PNG_FIXED_POINT_SUPPORTED
  171930. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  171931. if (PNG_OUT_OF_RANGE(info_ptr->int_x_white, 31270, 1000) ||
  171932. PNG_OUT_OF_RANGE(info_ptr->int_y_white, 32900, 1000) ||
  171933. PNG_OUT_OF_RANGE(info_ptr->int_x_red, 64000L, 1000) ||
  171934. PNG_OUT_OF_RANGE(info_ptr->int_y_red, 33000, 1000) ||
  171935. PNG_OUT_OF_RANGE(info_ptr->int_x_green, 30000, 1000) ||
  171936. PNG_OUT_OF_RANGE(info_ptr->int_y_green, 60000L, 1000) ||
  171937. PNG_OUT_OF_RANGE(info_ptr->int_x_blue, 15000, 1000) ||
  171938. PNG_OUT_OF_RANGE(info_ptr->int_y_blue, 6000, 1000))
  171939. {
  171940. png_warning(png_ptr,
  171941. "Ignoring incorrect cHRM value when sRGB is also present");
  171942. }
  171943. #endif /* PNG_FIXED_POINT_SUPPORTED */
  171944. #endif /* PNG_READ_cHRM_SUPPORTED */
  171945. png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr, intent);
  171946. }
  171947. #endif /* PNG_READ_sRGB_SUPPORTED */
  171948. #if defined(PNG_READ_iCCP_SUPPORTED)
  171949. void /* PRIVATE */
  171950. png_handle_iCCP(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171951. {
  171952. png_charp chunkdata;
  171953. png_byte compression_type;
  171954. png_bytep pC;
  171955. png_charp profile;
  171956. png_uint_32 skip = 0;
  171957. png_uint_32 profile_size, profile_length;
  171958. png_size_t slength, prefix_length, data_length;
  171959. png_debug(1, "in png_handle_iCCP\n");
  171960. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171961. png_error(png_ptr, "Missing IHDR before iCCP");
  171962. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171963. {
  171964. png_warning(png_ptr, "Invalid iCCP after IDAT");
  171965. png_crc_finish(png_ptr, length);
  171966. return;
  171967. }
  171968. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171969. png_warning(png_ptr, "Out of place iCCP chunk");
  171970. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP))
  171971. {
  171972. png_warning(png_ptr, "Duplicate iCCP chunk");
  171973. png_crc_finish(png_ptr, length);
  171974. return;
  171975. }
  171976. #ifdef PNG_MAX_MALLOC_64K
  171977. if (length > (png_uint_32)65535L)
  171978. {
  171979. png_warning(png_ptr, "iCCP chunk too large to fit in memory");
  171980. skip = length - (png_uint_32)65535L;
  171981. length = (png_uint_32)65535L;
  171982. }
  171983. #endif
  171984. chunkdata = (png_charp)png_malloc(png_ptr, length + 1);
  171985. slength = (png_size_t)length;
  171986. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  171987. if (png_crc_finish(png_ptr, skip))
  171988. {
  171989. png_free(png_ptr, chunkdata);
  171990. return;
  171991. }
  171992. chunkdata[slength] = 0x00;
  171993. for (profile = chunkdata; *profile; profile++)
  171994. ;
  171995. ++profile;
  171996. if ( profile >= chunkdata + slength - 1)
  171997. {
  171998. png_free(png_ptr, chunkdata);
  171999. png_warning(png_ptr, "Malformed iCCP chunk");
  172000. return;
  172001. }
  172002. compression_type = *profile++;
  172003. if (compression_type)
  172004. {
  172005. png_warning(png_ptr, "Ignoring nonzero compression type in iCCP chunk");
  172006. compression_type=0x00; /* Reset it to zero (libpng-1.0.6 through 1.0.8
  172007. wrote nonzero) */
  172008. }
  172009. prefix_length = profile - chunkdata;
  172010. chunkdata = png_decompress_chunk(png_ptr, compression_type, chunkdata,
  172011. slength, prefix_length, &data_length);
  172012. profile_length = data_length - prefix_length;
  172013. if ( prefix_length > data_length || profile_length < 4)
  172014. {
  172015. png_free(png_ptr, chunkdata);
  172016. png_warning(png_ptr, "Profile size field missing from iCCP chunk");
  172017. return;
  172018. }
  172019. pC = (png_bytep)(chunkdata+prefix_length);
  172020. profile_size = ((*(pC ))<<24) |
  172021. ((*(pC+1))<<16) |
  172022. ((*(pC+2))<< 8) |
  172023. ((*(pC+3)) );
  172024. if(profile_size < profile_length)
  172025. profile_length = profile_size;
  172026. if(profile_size > profile_length)
  172027. {
  172028. png_free(png_ptr, chunkdata);
  172029. png_warning(png_ptr, "Ignoring truncated iCCP profile.");
  172030. return;
  172031. }
  172032. png_set_iCCP(png_ptr, info_ptr, chunkdata, compression_type,
  172033. chunkdata + prefix_length, profile_length);
  172034. png_free(png_ptr, chunkdata);
  172035. }
  172036. #endif /* PNG_READ_iCCP_SUPPORTED */
  172037. #if defined(PNG_READ_sPLT_SUPPORTED)
  172038. void /* PRIVATE */
  172039. png_handle_sPLT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172040. {
  172041. png_bytep chunkdata;
  172042. png_bytep entry_start;
  172043. png_sPLT_t new_palette;
  172044. #ifdef PNG_NO_POINTER_INDEXING
  172045. png_sPLT_entryp pp;
  172046. #endif
  172047. int data_length, entry_size, i;
  172048. png_uint_32 skip = 0;
  172049. png_size_t slength;
  172050. png_debug(1, "in png_handle_sPLT\n");
  172051. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172052. png_error(png_ptr, "Missing IHDR before sPLT");
  172053. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172054. {
  172055. png_warning(png_ptr, "Invalid sPLT after IDAT");
  172056. png_crc_finish(png_ptr, length);
  172057. return;
  172058. }
  172059. #ifdef PNG_MAX_MALLOC_64K
  172060. if (length > (png_uint_32)65535L)
  172061. {
  172062. png_warning(png_ptr, "sPLT chunk too large to fit in memory");
  172063. skip = length - (png_uint_32)65535L;
  172064. length = (png_uint_32)65535L;
  172065. }
  172066. #endif
  172067. chunkdata = (png_bytep)png_malloc(png_ptr, length + 1);
  172068. slength = (png_size_t)length;
  172069. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  172070. if (png_crc_finish(png_ptr, skip))
  172071. {
  172072. png_free(png_ptr, chunkdata);
  172073. return;
  172074. }
  172075. chunkdata[slength] = 0x00;
  172076. for (entry_start = chunkdata; *entry_start; entry_start++)
  172077. ;
  172078. ++entry_start;
  172079. if (entry_start > chunkdata + slength - 2)
  172080. {
  172081. png_free(png_ptr, chunkdata);
  172082. png_warning(png_ptr, "malformed sPLT chunk");
  172083. return;
  172084. }
  172085. new_palette.depth = *entry_start++;
  172086. entry_size = (new_palette.depth == 8 ? 6 : 10);
  172087. data_length = (slength - (entry_start - chunkdata));
  172088. if (data_length % entry_size)
  172089. {
  172090. png_free(png_ptr, chunkdata);
  172091. png_warning(png_ptr, "sPLT chunk has bad length");
  172092. return;
  172093. }
  172094. new_palette.nentries = (png_int_32) ( data_length / entry_size);
  172095. if ((png_uint_32) new_palette.nentries > (png_uint_32) (PNG_SIZE_MAX /
  172096. png_sizeof(png_sPLT_entry)))
  172097. {
  172098. png_warning(png_ptr, "sPLT chunk too long");
  172099. return;
  172100. }
  172101. new_palette.entries = (png_sPLT_entryp)png_malloc_warn(
  172102. png_ptr, new_palette.nentries * png_sizeof(png_sPLT_entry));
  172103. if (new_palette.entries == NULL)
  172104. {
  172105. png_warning(png_ptr, "sPLT chunk requires too much memory");
  172106. return;
  172107. }
  172108. #ifndef PNG_NO_POINTER_INDEXING
  172109. for (i = 0; i < new_palette.nentries; i++)
  172110. {
  172111. png_sPLT_entryp pp = new_palette.entries + i;
  172112. if (new_palette.depth == 8)
  172113. {
  172114. pp->red = *entry_start++;
  172115. pp->green = *entry_start++;
  172116. pp->blue = *entry_start++;
  172117. pp->alpha = *entry_start++;
  172118. }
  172119. else
  172120. {
  172121. pp->red = png_get_uint_16(entry_start); entry_start += 2;
  172122. pp->green = png_get_uint_16(entry_start); entry_start += 2;
  172123. pp->blue = png_get_uint_16(entry_start); entry_start += 2;
  172124. pp->alpha = png_get_uint_16(entry_start); entry_start += 2;
  172125. }
  172126. pp->frequency = png_get_uint_16(entry_start); entry_start += 2;
  172127. }
  172128. #else
  172129. pp = new_palette.entries;
  172130. for (i = 0; i < new_palette.nentries; i++)
  172131. {
  172132. if (new_palette.depth == 8)
  172133. {
  172134. pp[i].red = *entry_start++;
  172135. pp[i].green = *entry_start++;
  172136. pp[i].blue = *entry_start++;
  172137. pp[i].alpha = *entry_start++;
  172138. }
  172139. else
  172140. {
  172141. pp[i].red = png_get_uint_16(entry_start); entry_start += 2;
  172142. pp[i].green = png_get_uint_16(entry_start); entry_start += 2;
  172143. pp[i].blue = png_get_uint_16(entry_start); entry_start += 2;
  172144. pp[i].alpha = png_get_uint_16(entry_start); entry_start += 2;
  172145. }
  172146. pp->frequency = png_get_uint_16(entry_start); entry_start += 2;
  172147. }
  172148. #endif
  172149. new_palette.name = (png_charp)chunkdata;
  172150. png_set_sPLT(png_ptr, info_ptr, &new_palette, 1);
  172151. png_free(png_ptr, chunkdata);
  172152. png_free(png_ptr, new_palette.entries);
  172153. }
  172154. #endif /* PNG_READ_sPLT_SUPPORTED */
  172155. #if defined(PNG_READ_tRNS_SUPPORTED)
  172156. void /* PRIVATE */
  172157. png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172158. {
  172159. png_byte readbuf[PNG_MAX_PALETTE_LENGTH];
  172160. int bit_mask;
  172161. png_debug(1, "in png_handle_tRNS\n");
  172162. bit_mask = (1 << png_ptr->bit_depth) - 1;
  172163. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172164. png_error(png_ptr, "Missing IHDR before tRNS");
  172165. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172166. {
  172167. png_warning(png_ptr, "Invalid tRNS after IDAT");
  172168. png_crc_finish(png_ptr, length);
  172169. return;
  172170. }
  172171. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  172172. {
  172173. png_warning(png_ptr, "Duplicate tRNS chunk");
  172174. png_crc_finish(png_ptr, length);
  172175. return;
  172176. }
  172177. if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
  172178. {
  172179. png_byte buf[2];
  172180. if (length != 2)
  172181. {
  172182. png_warning(png_ptr, "Incorrect tRNS chunk length");
  172183. png_crc_finish(png_ptr, length);
  172184. return;
  172185. }
  172186. png_crc_read(png_ptr, buf, 2);
  172187. png_ptr->num_trans = 1;
  172188. png_ptr->trans_values.gray = png_get_uint_16(buf) & bit_mask;
  172189. }
  172190. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  172191. {
  172192. png_byte buf[6];
  172193. if (length != 6)
  172194. {
  172195. png_warning(png_ptr, "Incorrect tRNS chunk length");
  172196. png_crc_finish(png_ptr, length);
  172197. return;
  172198. }
  172199. png_crc_read(png_ptr, buf, (png_size_t)length);
  172200. png_ptr->num_trans = 1;
  172201. png_ptr->trans_values.red = png_get_uint_16(buf) & bit_mask;
  172202. png_ptr->trans_values.green = png_get_uint_16(buf + 2) & bit_mask;
  172203. png_ptr->trans_values.blue = png_get_uint_16(buf + 4) & bit_mask;
  172204. }
  172205. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  172206. {
  172207. if (!(png_ptr->mode & PNG_HAVE_PLTE))
  172208. {
  172209. png_warning(png_ptr, "Missing PLTE before tRNS");
  172210. }
  172211. if (length > (png_uint_32)png_ptr->num_palette ||
  172212. length > PNG_MAX_PALETTE_LENGTH)
  172213. {
  172214. png_warning(png_ptr, "Incorrect tRNS chunk length");
  172215. png_crc_finish(png_ptr, length);
  172216. return;
  172217. }
  172218. if (length == 0)
  172219. {
  172220. png_warning(png_ptr, "Zero length tRNS chunk");
  172221. png_crc_finish(png_ptr, length);
  172222. return;
  172223. }
  172224. png_crc_read(png_ptr, readbuf, (png_size_t)length);
  172225. png_ptr->num_trans = (png_uint_16)length;
  172226. }
  172227. else
  172228. {
  172229. png_warning(png_ptr, "tRNS chunk not allowed with alpha channel");
  172230. png_crc_finish(png_ptr, length);
  172231. return;
  172232. }
  172233. if (png_crc_finish(png_ptr, 0))
  172234. {
  172235. png_ptr->num_trans = 0;
  172236. return;
  172237. }
  172238. png_set_tRNS(png_ptr, info_ptr, readbuf, png_ptr->num_trans,
  172239. &(png_ptr->trans_values));
  172240. }
  172241. #endif
  172242. #if defined(PNG_READ_bKGD_SUPPORTED)
  172243. void /* PRIVATE */
  172244. png_handle_bKGD(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172245. {
  172246. png_size_t truelen;
  172247. png_byte buf[6];
  172248. png_debug(1, "in png_handle_bKGD\n");
  172249. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172250. png_error(png_ptr, "Missing IHDR before bKGD");
  172251. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172252. {
  172253. png_warning(png_ptr, "Invalid bKGD after IDAT");
  172254. png_crc_finish(png_ptr, length);
  172255. return;
  172256. }
  172257. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  172258. !(png_ptr->mode & PNG_HAVE_PLTE))
  172259. {
  172260. png_warning(png_ptr, "Missing PLTE before bKGD");
  172261. png_crc_finish(png_ptr, length);
  172262. return;
  172263. }
  172264. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD))
  172265. {
  172266. png_warning(png_ptr, "Duplicate bKGD chunk");
  172267. png_crc_finish(png_ptr, length);
  172268. return;
  172269. }
  172270. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  172271. truelen = 1;
  172272. else if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
  172273. truelen = 6;
  172274. else
  172275. truelen = 2;
  172276. if (length != truelen)
  172277. {
  172278. png_warning(png_ptr, "Incorrect bKGD chunk length");
  172279. png_crc_finish(png_ptr, length);
  172280. return;
  172281. }
  172282. png_crc_read(png_ptr, buf, truelen);
  172283. if (png_crc_finish(png_ptr, 0))
  172284. return;
  172285. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  172286. {
  172287. png_ptr->background.index = buf[0];
  172288. if(info_ptr->num_palette)
  172289. {
  172290. if(buf[0] > info_ptr->num_palette)
  172291. {
  172292. png_warning(png_ptr, "Incorrect bKGD chunk index value");
  172293. return;
  172294. }
  172295. png_ptr->background.red =
  172296. (png_uint_16)png_ptr->palette[buf[0]].red;
  172297. png_ptr->background.green =
  172298. (png_uint_16)png_ptr->palette[buf[0]].green;
  172299. png_ptr->background.blue =
  172300. (png_uint_16)png_ptr->palette[buf[0]].blue;
  172301. }
  172302. }
  172303. else if (!(png_ptr->color_type & PNG_COLOR_MASK_COLOR)) /* GRAY */
  172304. {
  172305. png_ptr->background.red =
  172306. png_ptr->background.green =
  172307. png_ptr->background.blue =
  172308. png_ptr->background.gray = png_get_uint_16(buf);
  172309. }
  172310. else
  172311. {
  172312. png_ptr->background.red = png_get_uint_16(buf);
  172313. png_ptr->background.green = png_get_uint_16(buf + 2);
  172314. png_ptr->background.blue = png_get_uint_16(buf + 4);
  172315. }
  172316. png_set_bKGD(png_ptr, info_ptr, &(png_ptr->background));
  172317. }
  172318. #endif
  172319. #if defined(PNG_READ_hIST_SUPPORTED)
  172320. void /* PRIVATE */
  172321. png_handle_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172322. {
  172323. unsigned int num, i;
  172324. png_uint_16 readbuf[PNG_MAX_PALETTE_LENGTH];
  172325. png_debug(1, "in png_handle_hIST\n");
  172326. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172327. png_error(png_ptr, "Missing IHDR before hIST");
  172328. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172329. {
  172330. png_warning(png_ptr, "Invalid hIST after IDAT");
  172331. png_crc_finish(png_ptr, length);
  172332. return;
  172333. }
  172334. else if (!(png_ptr->mode & PNG_HAVE_PLTE))
  172335. {
  172336. png_warning(png_ptr, "Missing PLTE before hIST");
  172337. png_crc_finish(png_ptr, length);
  172338. return;
  172339. }
  172340. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST))
  172341. {
  172342. png_warning(png_ptr, "Duplicate hIST chunk");
  172343. png_crc_finish(png_ptr, length);
  172344. return;
  172345. }
  172346. num = length / 2 ;
  172347. if (num != (unsigned int) png_ptr->num_palette || num >
  172348. (unsigned int) PNG_MAX_PALETTE_LENGTH)
  172349. {
  172350. png_warning(png_ptr, "Incorrect hIST chunk length");
  172351. png_crc_finish(png_ptr, length);
  172352. return;
  172353. }
  172354. for (i = 0; i < num; i++)
  172355. {
  172356. png_byte buf[2];
  172357. png_crc_read(png_ptr, buf, 2);
  172358. readbuf[i] = png_get_uint_16(buf);
  172359. }
  172360. if (png_crc_finish(png_ptr, 0))
  172361. return;
  172362. png_set_hIST(png_ptr, info_ptr, readbuf);
  172363. }
  172364. #endif
  172365. #if defined(PNG_READ_pHYs_SUPPORTED)
  172366. void /* PRIVATE */
  172367. png_handle_pHYs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172368. {
  172369. png_byte buf[9];
  172370. png_uint_32 res_x, res_y;
  172371. int unit_type;
  172372. png_debug(1, "in png_handle_pHYs\n");
  172373. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172374. png_error(png_ptr, "Missing IHDR before pHYs");
  172375. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172376. {
  172377. png_warning(png_ptr, "Invalid pHYs after IDAT");
  172378. png_crc_finish(png_ptr, length);
  172379. return;
  172380. }
  172381. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
  172382. {
  172383. png_warning(png_ptr, "Duplicate pHYs chunk");
  172384. png_crc_finish(png_ptr, length);
  172385. return;
  172386. }
  172387. if (length != 9)
  172388. {
  172389. png_warning(png_ptr, "Incorrect pHYs chunk length");
  172390. png_crc_finish(png_ptr, length);
  172391. return;
  172392. }
  172393. png_crc_read(png_ptr, buf, 9);
  172394. if (png_crc_finish(png_ptr, 0))
  172395. return;
  172396. res_x = png_get_uint_32(buf);
  172397. res_y = png_get_uint_32(buf + 4);
  172398. unit_type = buf[8];
  172399. png_set_pHYs(png_ptr, info_ptr, res_x, res_y, unit_type);
  172400. }
  172401. #endif
  172402. #if defined(PNG_READ_oFFs_SUPPORTED)
  172403. void /* PRIVATE */
  172404. png_handle_oFFs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172405. {
  172406. png_byte buf[9];
  172407. png_int_32 offset_x, offset_y;
  172408. int unit_type;
  172409. png_debug(1, "in png_handle_oFFs\n");
  172410. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172411. png_error(png_ptr, "Missing IHDR before oFFs");
  172412. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172413. {
  172414. png_warning(png_ptr, "Invalid oFFs after IDAT");
  172415. png_crc_finish(png_ptr, length);
  172416. return;
  172417. }
  172418. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
  172419. {
  172420. png_warning(png_ptr, "Duplicate oFFs chunk");
  172421. png_crc_finish(png_ptr, length);
  172422. return;
  172423. }
  172424. if (length != 9)
  172425. {
  172426. png_warning(png_ptr, "Incorrect oFFs chunk length");
  172427. png_crc_finish(png_ptr, length);
  172428. return;
  172429. }
  172430. png_crc_read(png_ptr, buf, 9);
  172431. if (png_crc_finish(png_ptr, 0))
  172432. return;
  172433. offset_x = png_get_int_32(buf);
  172434. offset_y = png_get_int_32(buf + 4);
  172435. unit_type = buf[8];
  172436. png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y, unit_type);
  172437. }
  172438. #endif
  172439. #if defined(PNG_READ_pCAL_SUPPORTED)
  172440. void /* PRIVATE */
  172441. png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172442. {
  172443. png_charp purpose;
  172444. png_int_32 X0, X1;
  172445. png_byte type, nparams;
  172446. png_charp buf, units, endptr;
  172447. png_charpp params;
  172448. png_size_t slength;
  172449. int i;
  172450. png_debug(1, "in png_handle_pCAL\n");
  172451. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172452. png_error(png_ptr, "Missing IHDR before pCAL");
  172453. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172454. {
  172455. png_warning(png_ptr, "Invalid pCAL after IDAT");
  172456. png_crc_finish(png_ptr, length);
  172457. return;
  172458. }
  172459. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL))
  172460. {
  172461. png_warning(png_ptr, "Duplicate pCAL chunk");
  172462. png_crc_finish(png_ptr, length);
  172463. return;
  172464. }
  172465. png_debug1(2, "Allocating and reading pCAL chunk data (%lu bytes)\n",
  172466. length + 1);
  172467. purpose = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172468. if (purpose == NULL)
  172469. {
  172470. png_warning(png_ptr, "No memory for pCAL purpose.");
  172471. return;
  172472. }
  172473. slength = (png_size_t)length;
  172474. png_crc_read(png_ptr, (png_bytep)purpose, slength);
  172475. if (png_crc_finish(png_ptr, 0))
  172476. {
  172477. png_free(png_ptr, purpose);
  172478. return;
  172479. }
  172480. purpose[slength] = 0x00; /* null terminate the last string */
  172481. png_debug(3, "Finding end of pCAL purpose string\n");
  172482. for (buf = purpose; *buf; buf++)
  172483. ;
  172484. endptr = purpose + slength;
  172485. if (endptr <= buf + 12)
  172486. {
  172487. png_warning(png_ptr, "Invalid pCAL data");
  172488. png_free(png_ptr, purpose);
  172489. return;
  172490. }
  172491. png_debug(3, "Reading pCAL X0, X1, type, nparams, and units\n");
  172492. X0 = png_get_int_32((png_bytep)buf+1);
  172493. X1 = png_get_int_32((png_bytep)buf+5);
  172494. type = buf[9];
  172495. nparams = buf[10];
  172496. units = buf + 11;
  172497. png_debug(3, "Checking pCAL equation type and number of parameters\n");
  172498. if ((type == PNG_EQUATION_LINEAR && nparams != 2) ||
  172499. (type == PNG_EQUATION_BASE_E && nparams != 3) ||
  172500. (type == PNG_EQUATION_ARBITRARY && nparams != 3) ||
  172501. (type == PNG_EQUATION_HYPERBOLIC && nparams != 4))
  172502. {
  172503. png_warning(png_ptr, "Invalid pCAL parameters for equation type");
  172504. png_free(png_ptr, purpose);
  172505. return;
  172506. }
  172507. else if (type >= PNG_EQUATION_LAST)
  172508. {
  172509. png_warning(png_ptr, "Unrecognized equation type for pCAL chunk");
  172510. }
  172511. for (buf = units; *buf; buf++)
  172512. ;
  172513. png_debug(3, "Allocating pCAL parameters array\n");
  172514. params = (png_charpp)png_malloc_warn(png_ptr, (png_uint_32)(nparams
  172515. *png_sizeof(png_charp))) ;
  172516. if (params == NULL)
  172517. {
  172518. png_free(png_ptr, purpose);
  172519. png_warning(png_ptr, "No memory for pCAL params.");
  172520. return;
  172521. }
  172522. for (i = 0; i < (int)nparams; i++)
  172523. {
  172524. buf++; /* Skip the null string terminator from previous parameter. */
  172525. png_debug1(3, "Reading pCAL parameter %d\n", i);
  172526. for (params[i] = buf; buf <= endptr && *buf != 0x00; buf++)
  172527. ;
  172528. if (buf > endptr)
  172529. {
  172530. png_warning(png_ptr, "Invalid pCAL data");
  172531. png_free(png_ptr, purpose);
  172532. png_free(png_ptr, params);
  172533. return;
  172534. }
  172535. }
  172536. png_set_pCAL(png_ptr, info_ptr, purpose, X0, X1, type, nparams,
  172537. units, params);
  172538. png_free(png_ptr, purpose);
  172539. png_free(png_ptr, params);
  172540. }
  172541. #endif
  172542. #if defined(PNG_READ_sCAL_SUPPORTED)
  172543. void /* PRIVATE */
  172544. png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172545. {
  172546. png_charp buffer, ep;
  172547. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172548. double width, height;
  172549. png_charp vp;
  172550. #else
  172551. #ifdef PNG_FIXED_POINT_SUPPORTED
  172552. png_charp swidth, sheight;
  172553. #endif
  172554. #endif
  172555. png_size_t slength;
  172556. png_debug(1, "in png_handle_sCAL\n");
  172557. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172558. png_error(png_ptr, "Missing IHDR before sCAL");
  172559. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172560. {
  172561. png_warning(png_ptr, "Invalid sCAL after IDAT");
  172562. png_crc_finish(png_ptr, length);
  172563. return;
  172564. }
  172565. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sCAL))
  172566. {
  172567. png_warning(png_ptr, "Duplicate sCAL chunk");
  172568. png_crc_finish(png_ptr, length);
  172569. return;
  172570. }
  172571. png_debug1(2, "Allocating and reading sCAL chunk data (%lu bytes)\n",
  172572. length + 1);
  172573. buffer = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172574. if (buffer == NULL)
  172575. {
  172576. png_warning(png_ptr, "Out of memory while processing sCAL chunk");
  172577. return;
  172578. }
  172579. slength = (png_size_t)length;
  172580. png_crc_read(png_ptr, (png_bytep)buffer, slength);
  172581. if (png_crc_finish(png_ptr, 0))
  172582. {
  172583. png_free(png_ptr, buffer);
  172584. return;
  172585. }
  172586. buffer[slength] = 0x00; /* null terminate the last string */
  172587. ep = buffer + 1; /* skip unit byte */
  172588. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172589. width = png_strtod(png_ptr, ep, &vp);
  172590. if (*vp)
  172591. {
  172592. png_warning(png_ptr, "malformed width string in sCAL chunk");
  172593. return;
  172594. }
  172595. #else
  172596. #ifdef PNG_FIXED_POINT_SUPPORTED
  172597. swidth = (png_charp)png_malloc_warn(png_ptr, png_strlen(ep) + 1);
  172598. if (swidth == NULL)
  172599. {
  172600. png_warning(png_ptr, "Out of memory while processing sCAL chunk width");
  172601. return;
  172602. }
  172603. png_memcpy(swidth, ep, (png_size_t)png_strlen(ep));
  172604. #endif
  172605. #endif
  172606. for (ep = buffer; *ep; ep++)
  172607. ;
  172608. ep++;
  172609. if (buffer + slength < ep)
  172610. {
  172611. png_warning(png_ptr, "Truncated sCAL chunk");
  172612. #if defined(PNG_FIXED_POINT_SUPPORTED) && \
  172613. !defined(PNG_FLOATING_POINT_SUPPORTED)
  172614. png_free(png_ptr, swidth);
  172615. #endif
  172616. png_free(png_ptr, buffer);
  172617. return;
  172618. }
  172619. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172620. height = png_strtod(png_ptr, ep, &vp);
  172621. if (*vp)
  172622. {
  172623. png_warning(png_ptr, "malformed height string in sCAL chunk");
  172624. return;
  172625. }
  172626. #else
  172627. #ifdef PNG_FIXED_POINT_SUPPORTED
  172628. sheight = (png_charp)png_malloc_warn(png_ptr, png_strlen(ep) + 1);
  172629. if (swidth == NULL)
  172630. {
  172631. png_warning(png_ptr, "Out of memory while processing sCAL chunk height");
  172632. return;
  172633. }
  172634. png_memcpy(sheight, ep, (png_size_t)png_strlen(ep));
  172635. #endif
  172636. #endif
  172637. if (buffer + slength < ep
  172638. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172639. || width <= 0. || height <= 0.
  172640. #endif
  172641. )
  172642. {
  172643. png_warning(png_ptr, "Invalid sCAL data");
  172644. png_free(png_ptr, buffer);
  172645. #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
  172646. png_free(png_ptr, swidth);
  172647. png_free(png_ptr, sheight);
  172648. #endif
  172649. return;
  172650. }
  172651. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172652. png_set_sCAL(png_ptr, info_ptr, buffer[0], width, height);
  172653. #else
  172654. #ifdef PNG_FIXED_POINT_SUPPORTED
  172655. png_set_sCAL_s(png_ptr, info_ptr, buffer[0], swidth, sheight);
  172656. #endif
  172657. #endif
  172658. png_free(png_ptr, buffer);
  172659. #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
  172660. png_free(png_ptr, swidth);
  172661. png_free(png_ptr, sheight);
  172662. #endif
  172663. }
  172664. #endif
  172665. #if defined(PNG_READ_tIME_SUPPORTED)
  172666. void /* PRIVATE */
  172667. png_handle_tIME(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172668. {
  172669. png_byte buf[7];
  172670. png_time mod_time;
  172671. png_debug(1, "in png_handle_tIME\n");
  172672. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172673. png_error(png_ptr, "Out of place tIME chunk");
  172674. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME))
  172675. {
  172676. png_warning(png_ptr, "Duplicate tIME chunk");
  172677. png_crc_finish(png_ptr, length);
  172678. return;
  172679. }
  172680. if (png_ptr->mode & PNG_HAVE_IDAT)
  172681. png_ptr->mode |= PNG_AFTER_IDAT;
  172682. if (length != 7)
  172683. {
  172684. png_warning(png_ptr, "Incorrect tIME chunk length");
  172685. png_crc_finish(png_ptr, length);
  172686. return;
  172687. }
  172688. png_crc_read(png_ptr, buf, 7);
  172689. if (png_crc_finish(png_ptr, 0))
  172690. return;
  172691. mod_time.second = buf[6];
  172692. mod_time.minute = buf[5];
  172693. mod_time.hour = buf[4];
  172694. mod_time.day = buf[3];
  172695. mod_time.month = buf[2];
  172696. mod_time.year = png_get_uint_16(buf);
  172697. png_set_tIME(png_ptr, info_ptr, &mod_time);
  172698. }
  172699. #endif
  172700. #if defined(PNG_READ_tEXt_SUPPORTED)
  172701. void /* PRIVATE */
  172702. png_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172703. {
  172704. png_textp text_ptr;
  172705. png_charp key;
  172706. png_charp text;
  172707. png_uint_32 skip = 0;
  172708. png_size_t slength;
  172709. int ret;
  172710. png_debug(1, "in png_handle_tEXt\n");
  172711. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172712. png_error(png_ptr, "Missing IHDR before tEXt");
  172713. if (png_ptr->mode & PNG_HAVE_IDAT)
  172714. png_ptr->mode |= PNG_AFTER_IDAT;
  172715. #ifdef PNG_MAX_MALLOC_64K
  172716. if (length > (png_uint_32)65535L)
  172717. {
  172718. png_warning(png_ptr, "tEXt chunk too large to fit in memory");
  172719. skip = length - (png_uint_32)65535L;
  172720. length = (png_uint_32)65535L;
  172721. }
  172722. #endif
  172723. key = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172724. if (key == NULL)
  172725. {
  172726. png_warning(png_ptr, "No memory to process text chunk.");
  172727. return;
  172728. }
  172729. slength = (png_size_t)length;
  172730. png_crc_read(png_ptr, (png_bytep)key, slength);
  172731. if (png_crc_finish(png_ptr, skip))
  172732. {
  172733. png_free(png_ptr, key);
  172734. return;
  172735. }
  172736. key[slength] = 0x00;
  172737. for (text = key; *text; text++)
  172738. ;
  172739. if (text != key + slength)
  172740. text++;
  172741. text_ptr = (png_textp)png_malloc_warn(png_ptr,
  172742. (png_uint_32)png_sizeof(png_text));
  172743. if (text_ptr == NULL)
  172744. {
  172745. png_warning(png_ptr, "Not enough memory to process text chunk.");
  172746. png_free(png_ptr, key);
  172747. return;
  172748. }
  172749. text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
  172750. text_ptr->key = key;
  172751. #ifdef PNG_iTXt_SUPPORTED
  172752. text_ptr->lang = NULL;
  172753. text_ptr->lang_key = NULL;
  172754. text_ptr->itxt_length = 0;
  172755. #endif
  172756. text_ptr->text = text;
  172757. text_ptr->text_length = png_strlen(text);
  172758. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  172759. png_free(png_ptr, key);
  172760. png_free(png_ptr, text_ptr);
  172761. if (ret)
  172762. png_warning(png_ptr, "Insufficient memory to process text chunk.");
  172763. }
  172764. #endif
  172765. #if defined(PNG_READ_zTXt_SUPPORTED)
  172766. void /* PRIVATE */
  172767. png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172768. {
  172769. png_textp text_ptr;
  172770. png_charp chunkdata;
  172771. png_charp text;
  172772. int comp_type;
  172773. int ret;
  172774. png_size_t slength, prefix_len, data_len;
  172775. png_debug(1, "in png_handle_zTXt\n");
  172776. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172777. png_error(png_ptr, "Missing IHDR before zTXt");
  172778. if (png_ptr->mode & PNG_HAVE_IDAT)
  172779. png_ptr->mode |= PNG_AFTER_IDAT;
  172780. #ifdef PNG_MAX_MALLOC_64K
  172781. if (length > (png_uint_32)65535L)
  172782. {
  172783. png_warning(png_ptr,"zTXt chunk too large to fit in memory");
  172784. png_crc_finish(png_ptr, length);
  172785. return;
  172786. }
  172787. #endif
  172788. chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172789. if (chunkdata == NULL)
  172790. {
  172791. png_warning(png_ptr,"Out of memory processing zTXt chunk.");
  172792. return;
  172793. }
  172794. slength = (png_size_t)length;
  172795. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  172796. if (png_crc_finish(png_ptr, 0))
  172797. {
  172798. png_free(png_ptr, chunkdata);
  172799. return;
  172800. }
  172801. chunkdata[slength] = 0x00;
  172802. for (text = chunkdata; *text; text++)
  172803. ;
  172804. if (text >= chunkdata + slength - 2)
  172805. {
  172806. png_warning(png_ptr, "Truncated zTXt chunk");
  172807. png_free(png_ptr, chunkdata);
  172808. return;
  172809. }
  172810. else
  172811. {
  172812. comp_type = *(++text);
  172813. if (comp_type != PNG_TEXT_COMPRESSION_zTXt)
  172814. {
  172815. png_warning(png_ptr, "Unknown compression type in zTXt chunk");
  172816. comp_type = PNG_TEXT_COMPRESSION_zTXt;
  172817. }
  172818. text++; /* skip the compression_method byte */
  172819. }
  172820. prefix_len = text - chunkdata;
  172821. chunkdata = (png_charp)png_decompress_chunk(png_ptr, comp_type, chunkdata,
  172822. (png_size_t)length, prefix_len, &data_len);
  172823. text_ptr = (png_textp)png_malloc_warn(png_ptr,
  172824. (png_uint_32)png_sizeof(png_text));
  172825. if (text_ptr == NULL)
  172826. {
  172827. png_warning(png_ptr,"Not enough memory to process zTXt chunk.");
  172828. png_free(png_ptr, chunkdata);
  172829. return;
  172830. }
  172831. text_ptr->compression = comp_type;
  172832. text_ptr->key = chunkdata;
  172833. #ifdef PNG_iTXt_SUPPORTED
  172834. text_ptr->lang = NULL;
  172835. text_ptr->lang_key = NULL;
  172836. text_ptr->itxt_length = 0;
  172837. #endif
  172838. text_ptr->text = chunkdata + prefix_len;
  172839. text_ptr->text_length = data_len;
  172840. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  172841. png_free(png_ptr, text_ptr);
  172842. png_free(png_ptr, chunkdata);
  172843. if (ret)
  172844. png_error(png_ptr, "Insufficient memory to store zTXt chunk.");
  172845. }
  172846. #endif
  172847. #if defined(PNG_READ_iTXt_SUPPORTED)
  172848. void /* PRIVATE */
  172849. png_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172850. {
  172851. png_textp text_ptr;
  172852. png_charp chunkdata;
  172853. png_charp key, lang, text, lang_key;
  172854. int comp_flag;
  172855. int comp_type = 0;
  172856. int ret;
  172857. png_size_t slength, prefix_len, data_len;
  172858. png_debug(1, "in png_handle_iTXt\n");
  172859. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172860. png_error(png_ptr, "Missing IHDR before iTXt");
  172861. if (png_ptr->mode & PNG_HAVE_IDAT)
  172862. png_ptr->mode |= PNG_AFTER_IDAT;
  172863. #ifdef PNG_MAX_MALLOC_64K
  172864. if (length > (png_uint_32)65535L)
  172865. {
  172866. png_warning(png_ptr,"iTXt chunk too large to fit in memory");
  172867. png_crc_finish(png_ptr, length);
  172868. return;
  172869. }
  172870. #endif
  172871. chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172872. if (chunkdata == NULL)
  172873. {
  172874. png_warning(png_ptr, "No memory to process iTXt chunk.");
  172875. return;
  172876. }
  172877. slength = (png_size_t)length;
  172878. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  172879. if (png_crc_finish(png_ptr, 0))
  172880. {
  172881. png_free(png_ptr, chunkdata);
  172882. return;
  172883. }
  172884. chunkdata[slength] = 0x00;
  172885. for (lang = chunkdata; *lang; lang++)
  172886. ;
  172887. lang++; /* skip NUL separator */
  172888. if (lang >= chunkdata + slength - 3)
  172889. {
  172890. png_warning(png_ptr, "Truncated iTXt chunk");
  172891. png_free(png_ptr, chunkdata);
  172892. return;
  172893. }
  172894. else
  172895. {
  172896. comp_flag = *lang++;
  172897. comp_type = *lang++;
  172898. }
  172899. for (lang_key = lang; *lang_key; lang_key++)
  172900. ;
  172901. lang_key++; /* skip NUL separator */
  172902. if (lang_key >= chunkdata + slength)
  172903. {
  172904. png_warning(png_ptr, "Truncated iTXt chunk");
  172905. png_free(png_ptr, chunkdata);
  172906. return;
  172907. }
  172908. for (text = lang_key; *text; text++)
  172909. ;
  172910. text++; /* skip NUL separator */
  172911. if (text >= chunkdata + slength)
  172912. {
  172913. png_warning(png_ptr, "Malformed iTXt chunk");
  172914. png_free(png_ptr, chunkdata);
  172915. return;
  172916. }
  172917. prefix_len = text - chunkdata;
  172918. key=chunkdata;
  172919. if (comp_flag)
  172920. chunkdata = png_decompress_chunk(png_ptr, comp_type, chunkdata,
  172921. (size_t)length, prefix_len, &data_len);
  172922. else
  172923. data_len=png_strlen(chunkdata + prefix_len);
  172924. text_ptr = (png_textp)png_malloc_warn(png_ptr,
  172925. (png_uint_32)png_sizeof(png_text));
  172926. if (text_ptr == NULL)
  172927. {
  172928. png_warning(png_ptr,"Not enough memory to process iTXt chunk.");
  172929. png_free(png_ptr, chunkdata);
  172930. return;
  172931. }
  172932. text_ptr->compression = (int)comp_flag + 1;
  172933. text_ptr->lang_key = chunkdata+(lang_key-key);
  172934. text_ptr->lang = chunkdata+(lang-key);
  172935. text_ptr->itxt_length = data_len;
  172936. text_ptr->text_length = 0;
  172937. text_ptr->key = chunkdata;
  172938. text_ptr->text = chunkdata + prefix_len;
  172939. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  172940. png_free(png_ptr, text_ptr);
  172941. png_free(png_ptr, chunkdata);
  172942. if (ret)
  172943. png_error(png_ptr, "Insufficient memory to store iTXt chunk.");
  172944. }
  172945. #endif
  172946. void /* PRIVATE */
  172947. png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172948. {
  172949. png_uint_32 skip = 0;
  172950. png_debug(1, "in png_handle_unknown\n");
  172951. if (png_ptr->mode & PNG_HAVE_IDAT)
  172952. {
  172953. #ifdef PNG_USE_LOCAL_ARRAYS
  172954. PNG_CONST PNG_IDAT;
  172955. #endif
  172956. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) /* not an IDAT */
  172957. png_ptr->mode |= PNG_AFTER_IDAT;
  172958. }
  172959. png_check_chunk_name(png_ptr, png_ptr->chunk_name);
  172960. if (!(png_ptr->chunk_name[0] & 0x20))
  172961. {
  172962. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  172963. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  172964. PNG_HANDLE_CHUNK_ALWAYS
  172965. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  172966. && png_ptr->read_user_chunk_fn == NULL
  172967. #endif
  172968. )
  172969. #endif
  172970. png_chunk_error(png_ptr, "unknown critical chunk");
  172971. }
  172972. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  172973. if ((png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS) ||
  172974. (png_ptr->read_user_chunk_fn != NULL))
  172975. {
  172976. #ifdef PNG_MAX_MALLOC_64K
  172977. if (length > (png_uint_32)65535L)
  172978. {
  172979. png_warning(png_ptr, "unknown chunk too large to fit in memory");
  172980. skip = length - (png_uint_32)65535L;
  172981. length = (png_uint_32)65535L;
  172982. }
  172983. #endif
  172984. png_strncpy((png_charp)png_ptr->unknown_chunk.name,
  172985. (png_charp)png_ptr->chunk_name, 5);
  172986. png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length);
  172987. png_ptr->unknown_chunk.size = (png_size_t)length;
  172988. png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
  172989. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  172990. if(png_ptr->read_user_chunk_fn != NULL)
  172991. {
  172992. int ret;
  172993. ret = (*(png_ptr->read_user_chunk_fn))
  172994. (png_ptr, &png_ptr->unknown_chunk);
  172995. if (ret < 0)
  172996. png_chunk_error(png_ptr, "error in user chunk");
  172997. if (ret == 0)
  172998. {
  172999. if (!(png_ptr->chunk_name[0] & 0x20))
  173000. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  173001. PNG_HANDLE_CHUNK_ALWAYS)
  173002. png_chunk_error(png_ptr, "unknown critical chunk");
  173003. png_set_unknown_chunks(png_ptr, info_ptr,
  173004. &png_ptr->unknown_chunk, 1);
  173005. }
  173006. }
  173007. #else
  173008. png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1);
  173009. #endif
  173010. png_free(png_ptr, png_ptr->unknown_chunk.data);
  173011. png_ptr->unknown_chunk.data = NULL;
  173012. }
  173013. else
  173014. #endif
  173015. skip = length;
  173016. png_crc_finish(png_ptr, skip);
  173017. #if !defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  173018. info_ptr = info_ptr; /* quiet compiler warnings about unused info_ptr */
  173019. #endif
  173020. }
  173021. #define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
  173022. void /* PRIVATE */
  173023. png_check_chunk_name(png_structp png_ptr, png_bytep chunk_name)
  173024. {
  173025. png_debug(1, "in png_check_chunk_name\n");
  173026. if (isnonalpha(chunk_name[0]) || isnonalpha(chunk_name[1]) ||
  173027. isnonalpha(chunk_name[2]) || isnonalpha(chunk_name[3]))
  173028. {
  173029. png_chunk_error(png_ptr, "invalid chunk type");
  173030. }
  173031. }
  173032. void /* PRIVATE */
  173033. png_combine_row(png_structp png_ptr, png_bytep row, int mask)
  173034. {
  173035. png_debug(1,"in png_combine_row\n");
  173036. if (mask == 0xff)
  173037. {
  173038. png_memcpy(row, png_ptr->row_buf + 1,
  173039. PNG_ROWBYTES(png_ptr->row_info.pixel_depth, png_ptr->width));
  173040. }
  173041. else
  173042. {
  173043. switch (png_ptr->row_info.pixel_depth)
  173044. {
  173045. case 1:
  173046. {
  173047. png_bytep sp = png_ptr->row_buf + 1;
  173048. png_bytep dp = row;
  173049. int s_inc, s_start, s_end;
  173050. int m = 0x80;
  173051. int shift;
  173052. png_uint_32 i;
  173053. png_uint_32 row_width = png_ptr->width;
  173054. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  173055. if (png_ptr->transformations & PNG_PACKSWAP)
  173056. {
  173057. s_start = 0;
  173058. s_end = 7;
  173059. s_inc = 1;
  173060. }
  173061. else
  173062. #endif
  173063. {
  173064. s_start = 7;
  173065. s_end = 0;
  173066. s_inc = -1;
  173067. }
  173068. shift = s_start;
  173069. for (i = 0; i < row_width; i++)
  173070. {
  173071. if (m & mask)
  173072. {
  173073. int value;
  173074. value = (*sp >> shift) & 0x01;
  173075. *dp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff);
  173076. *dp |= (png_byte)(value << shift);
  173077. }
  173078. if (shift == s_end)
  173079. {
  173080. shift = s_start;
  173081. sp++;
  173082. dp++;
  173083. }
  173084. else
  173085. shift += s_inc;
  173086. if (m == 1)
  173087. m = 0x80;
  173088. else
  173089. m >>= 1;
  173090. }
  173091. break;
  173092. }
  173093. case 2:
  173094. {
  173095. png_bytep sp = png_ptr->row_buf + 1;
  173096. png_bytep dp = row;
  173097. int s_start, s_end, s_inc;
  173098. int m = 0x80;
  173099. int shift;
  173100. png_uint_32 i;
  173101. png_uint_32 row_width = png_ptr->width;
  173102. int value;
  173103. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  173104. if (png_ptr->transformations & PNG_PACKSWAP)
  173105. {
  173106. s_start = 0;
  173107. s_end = 6;
  173108. s_inc = 2;
  173109. }
  173110. else
  173111. #endif
  173112. {
  173113. s_start = 6;
  173114. s_end = 0;
  173115. s_inc = -2;
  173116. }
  173117. shift = s_start;
  173118. for (i = 0; i < row_width; i++)
  173119. {
  173120. if (m & mask)
  173121. {
  173122. value = (*sp >> shift) & 0x03;
  173123. *dp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  173124. *dp |= (png_byte)(value << shift);
  173125. }
  173126. if (shift == s_end)
  173127. {
  173128. shift = s_start;
  173129. sp++;
  173130. dp++;
  173131. }
  173132. else
  173133. shift += s_inc;
  173134. if (m == 1)
  173135. m = 0x80;
  173136. else
  173137. m >>= 1;
  173138. }
  173139. break;
  173140. }
  173141. case 4:
  173142. {
  173143. png_bytep sp = png_ptr->row_buf + 1;
  173144. png_bytep dp = row;
  173145. int s_start, s_end, s_inc;
  173146. int m = 0x80;
  173147. int shift;
  173148. png_uint_32 i;
  173149. png_uint_32 row_width = png_ptr->width;
  173150. int value;
  173151. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  173152. if (png_ptr->transformations & PNG_PACKSWAP)
  173153. {
  173154. s_start = 0;
  173155. s_end = 4;
  173156. s_inc = 4;
  173157. }
  173158. else
  173159. #endif
  173160. {
  173161. s_start = 4;
  173162. s_end = 0;
  173163. s_inc = -4;
  173164. }
  173165. shift = s_start;
  173166. for (i = 0; i < row_width; i++)
  173167. {
  173168. if (m & mask)
  173169. {
  173170. value = (*sp >> shift) & 0xf;
  173171. *dp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  173172. *dp |= (png_byte)(value << shift);
  173173. }
  173174. if (shift == s_end)
  173175. {
  173176. shift = s_start;
  173177. sp++;
  173178. dp++;
  173179. }
  173180. else
  173181. shift += s_inc;
  173182. if (m == 1)
  173183. m = 0x80;
  173184. else
  173185. m >>= 1;
  173186. }
  173187. break;
  173188. }
  173189. default:
  173190. {
  173191. png_bytep sp = png_ptr->row_buf + 1;
  173192. png_bytep dp = row;
  173193. png_size_t pixel_bytes = (png_ptr->row_info.pixel_depth >> 3);
  173194. png_uint_32 i;
  173195. png_uint_32 row_width = png_ptr->width;
  173196. png_byte m = 0x80;
  173197. for (i = 0; i < row_width; i++)
  173198. {
  173199. if (m & mask)
  173200. {
  173201. png_memcpy(dp, sp, pixel_bytes);
  173202. }
  173203. sp += pixel_bytes;
  173204. dp += pixel_bytes;
  173205. if (m == 1)
  173206. m = 0x80;
  173207. else
  173208. m >>= 1;
  173209. }
  173210. break;
  173211. }
  173212. }
  173213. }
  173214. }
  173215. #ifdef PNG_READ_INTERLACING_SUPPORTED
  173216. void /* PRIVATE */
  173217. png_do_read_interlace(png_structp png_ptr)
  173218. {
  173219. png_row_infop row_info = &(png_ptr->row_info);
  173220. png_bytep row = png_ptr->row_buf + 1;
  173221. int pass = png_ptr->pass;
  173222. png_uint_32 transformations = png_ptr->transformations;
  173223. #ifdef PNG_USE_LOCAL_ARRAYS
  173224. PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  173225. #endif
  173226. png_debug(1,"in png_do_read_interlace\n");
  173227. if (row != NULL && row_info != NULL)
  173228. {
  173229. png_uint_32 final_width;
  173230. final_width = row_info->width * png_pass_inc[pass];
  173231. switch (row_info->pixel_depth)
  173232. {
  173233. case 1:
  173234. {
  173235. png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 3);
  173236. png_bytep dp = row + (png_size_t)((final_width - 1) >> 3);
  173237. int sshift, dshift;
  173238. int s_start, s_end, s_inc;
  173239. int jstop = png_pass_inc[pass];
  173240. png_byte v;
  173241. png_uint_32 i;
  173242. int j;
  173243. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  173244. if (transformations & PNG_PACKSWAP)
  173245. {
  173246. sshift = (int)((row_info->width + 7) & 0x07);
  173247. dshift = (int)((final_width + 7) & 0x07);
  173248. s_start = 7;
  173249. s_end = 0;
  173250. s_inc = -1;
  173251. }
  173252. else
  173253. #endif
  173254. {
  173255. sshift = 7 - (int)((row_info->width + 7) & 0x07);
  173256. dshift = 7 - (int)((final_width + 7) & 0x07);
  173257. s_start = 0;
  173258. s_end = 7;
  173259. s_inc = 1;
  173260. }
  173261. for (i = 0; i < row_info->width; i++)
  173262. {
  173263. v = (png_byte)((*sp >> sshift) & 0x01);
  173264. for (j = 0; j < jstop; j++)
  173265. {
  173266. *dp &= (png_byte)((0x7f7f >> (7 - dshift)) & 0xff);
  173267. *dp |= (png_byte)(v << dshift);
  173268. if (dshift == s_end)
  173269. {
  173270. dshift = s_start;
  173271. dp--;
  173272. }
  173273. else
  173274. dshift += s_inc;
  173275. }
  173276. if (sshift == s_end)
  173277. {
  173278. sshift = s_start;
  173279. sp--;
  173280. }
  173281. else
  173282. sshift += s_inc;
  173283. }
  173284. break;
  173285. }
  173286. case 2:
  173287. {
  173288. png_bytep sp = row + (png_uint_32)((row_info->width - 1) >> 2);
  173289. png_bytep dp = row + (png_uint_32)((final_width - 1) >> 2);
  173290. int sshift, dshift;
  173291. int s_start, s_end, s_inc;
  173292. int jstop = png_pass_inc[pass];
  173293. png_uint_32 i;
  173294. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  173295. if (transformations & PNG_PACKSWAP)
  173296. {
  173297. sshift = (int)(((row_info->width + 3) & 0x03) << 1);
  173298. dshift = (int)(((final_width + 3) & 0x03) << 1);
  173299. s_start = 6;
  173300. s_end = 0;
  173301. s_inc = -2;
  173302. }
  173303. else
  173304. #endif
  173305. {
  173306. sshift = (int)((3 - ((row_info->width + 3) & 0x03)) << 1);
  173307. dshift = (int)((3 - ((final_width + 3) & 0x03)) << 1);
  173308. s_start = 0;
  173309. s_end = 6;
  173310. s_inc = 2;
  173311. }
  173312. for (i = 0; i < row_info->width; i++)
  173313. {
  173314. png_byte v;
  173315. int j;
  173316. v = (png_byte)((*sp >> sshift) & 0x03);
  173317. for (j = 0; j < jstop; j++)
  173318. {
  173319. *dp &= (png_byte)((0x3f3f >> (6 - dshift)) & 0xff);
  173320. *dp |= (png_byte)(v << dshift);
  173321. if (dshift == s_end)
  173322. {
  173323. dshift = s_start;
  173324. dp--;
  173325. }
  173326. else
  173327. dshift += s_inc;
  173328. }
  173329. if (sshift == s_end)
  173330. {
  173331. sshift = s_start;
  173332. sp--;
  173333. }
  173334. else
  173335. sshift += s_inc;
  173336. }
  173337. break;
  173338. }
  173339. case 4:
  173340. {
  173341. png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 1);
  173342. png_bytep dp = row + (png_size_t)((final_width - 1) >> 1);
  173343. int sshift, dshift;
  173344. int s_start, s_end, s_inc;
  173345. png_uint_32 i;
  173346. int jstop = png_pass_inc[pass];
  173347. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  173348. if (transformations & PNG_PACKSWAP)
  173349. {
  173350. sshift = (int)(((row_info->width + 1) & 0x01) << 2);
  173351. dshift = (int)(((final_width + 1) & 0x01) << 2);
  173352. s_start = 4;
  173353. s_end = 0;
  173354. s_inc = -4;
  173355. }
  173356. else
  173357. #endif
  173358. {
  173359. sshift = (int)((1 - ((row_info->width + 1) & 0x01)) << 2);
  173360. dshift = (int)((1 - ((final_width + 1) & 0x01)) << 2);
  173361. s_start = 0;
  173362. s_end = 4;
  173363. s_inc = 4;
  173364. }
  173365. for (i = 0; i < row_info->width; i++)
  173366. {
  173367. png_byte v = (png_byte)((*sp >> sshift) & 0xf);
  173368. int j;
  173369. for (j = 0; j < jstop; j++)
  173370. {
  173371. *dp &= (png_byte)((0xf0f >> (4 - dshift)) & 0xff);
  173372. *dp |= (png_byte)(v << dshift);
  173373. if (dshift == s_end)
  173374. {
  173375. dshift = s_start;
  173376. dp--;
  173377. }
  173378. else
  173379. dshift += s_inc;
  173380. }
  173381. if (sshift == s_end)
  173382. {
  173383. sshift = s_start;
  173384. sp--;
  173385. }
  173386. else
  173387. sshift += s_inc;
  173388. }
  173389. break;
  173390. }
  173391. default:
  173392. {
  173393. png_size_t pixel_bytes = (row_info->pixel_depth >> 3);
  173394. png_bytep sp = row + (png_size_t)(row_info->width - 1) * pixel_bytes;
  173395. png_bytep dp = row + (png_size_t)(final_width - 1) * pixel_bytes;
  173396. int jstop = png_pass_inc[pass];
  173397. png_uint_32 i;
  173398. for (i = 0; i < row_info->width; i++)
  173399. {
  173400. png_byte v[8];
  173401. int j;
  173402. png_memcpy(v, sp, pixel_bytes);
  173403. for (j = 0; j < jstop; j++)
  173404. {
  173405. png_memcpy(dp, v, pixel_bytes);
  173406. dp -= pixel_bytes;
  173407. }
  173408. sp -= pixel_bytes;
  173409. }
  173410. break;
  173411. }
  173412. }
  173413. row_info->width = final_width;
  173414. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,final_width);
  173415. }
  173416. #if !defined(PNG_READ_PACKSWAP_SUPPORTED)
  173417. transformations = transformations; /* silence compiler warning */
  173418. #endif
  173419. }
  173420. #endif /* PNG_READ_INTERLACING_SUPPORTED */
  173421. void /* PRIVATE */
  173422. png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep row,
  173423. png_bytep prev_row, int filter)
  173424. {
  173425. png_debug(1, "in png_read_filter_row\n");
  173426. png_debug2(2,"row = %lu, filter = %d\n", png_ptr->row_number, filter);
  173427. switch (filter)
  173428. {
  173429. case PNG_FILTER_VALUE_NONE:
  173430. break;
  173431. case PNG_FILTER_VALUE_SUB:
  173432. {
  173433. png_uint_32 i;
  173434. png_uint_32 istop = row_info->rowbytes;
  173435. png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
  173436. png_bytep rp = row + bpp;
  173437. png_bytep lp = row;
  173438. for (i = bpp; i < istop; i++)
  173439. {
  173440. *rp = (png_byte)(((int)(*rp) + (int)(*lp++)) & 0xff);
  173441. rp++;
  173442. }
  173443. break;
  173444. }
  173445. case PNG_FILTER_VALUE_UP:
  173446. {
  173447. png_uint_32 i;
  173448. png_uint_32 istop = row_info->rowbytes;
  173449. png_bytep rp = row;
  173450. png_bytep pp = prev_row;
  173451. for (i = 0; i < istop; i++)
  173452. {
  173453. *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
  173454. rp++;
  173455. }
  173456. break;
  173457. }
  173458. case PNG_FILTER_VALUE_AVG:
  173459. {
  173460. png_uint_32 i;
  173461. png_bytep rp = row;
  173462. png_bytep pp = prev_row;
  173463. png_bytep lp = row;
  173464. png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
  173465. png_uint_32 istop = row_info->rowbytes - bpp;
  173466. for (i = 0; i < bpp; i++)
  173467. {
  173468. *rp = (png_byte)(((int)(*rp) +
  173469. ((int)(*pp++) / 2 )) & 0xff);
  173470. rp++;
  173471. }
  173472. for (i = 0; i < istop; i++)
  173473. {
  173474. *rp = (png_byte)(((int)(*rp) +
  173475. (int)(*pp++ + *lp++) / 2 ) & 0xff);
  173476. rp++;
  173477. }
  173478. break;
  173479. }
  173480. case PNG_FILTER_VALUE_PAETH:
  173481. {
  173482. png_uint_32 i;
  173483. png_bytep rp = row;
  173484. png_bytep pp = prev_row;
  173485. png_bytep lp = row;
  173486. png_bytep cp = prev_row;
  173487. png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
  173488. png_uint_32 istop=row_info->rowbytes - bpp;
  173489. for (i = 0; i < bpp; i++)
  173490. {
  173491. *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
  173492. rp++;
  173493. }
  173494. for (i = 0; i < istop; i++) /* use leftover rp,pp */
  173495. {
  173496. int a, b, c, pa, pb, pc, p;
  173497. a = *lp++;
  173498. b = *pp++;
  173499. c = *cp++;
  173500. p = b - c;
  173501. pc = a - c;
  173502. #ifdef PNG_USE_ABS
  173503. pa = abs(p);
  173504. pb = abs(pc);
  173505. pc = abs(p + pc);
  173506. #else
  173507. pa = p < 0 ? -p : p;
  173508. pb = pc < 0 ? -pc : pc;
  173509. pc = (p + pc) < 0 ? -(p + pc) : p + pc;
  173510. #endif
  173511. p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
  173512. *rp = (png_byte)(((int)(*rp) + p) & 0xff);
  173513. rp++;
  173514. }
  173515. break;
  173516. }
  173517. default:
  173518. png_warning(png_ptr, "Ignoring bad adaptive filter type");
  173519. *row=0;
  173520. break;
  173521. }
  173522. }
  173523. void /* PRIVATE */
  173524. png_read_finish_row(png_structp png_ptr)
  173525. {
  173526. #ifdef PNG_USE_LOCAL_ARRAYS
  173527. PNG_CONST int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  173528. PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  173529. PNG_CONST int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  173530. PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  173531. #endif
  173532. png_debug(1, "in png_read_finish_row\n");
  173533. png_ptr->row_number++;
  173534. if (png_ptr->row_number < png_ptr->num_rows)
  173535. return;
  173536. if (png_ptr->interlaced)
  173537. {
  173538. png_ptr->row_number = 0;
  173539. png_memset_check(png_ptr, png_ptr->prev_row, 0,
  173540. png_ptr->rowbytes + 1);
  173541. do
  173542. {
  173543. png_ptr->pass++;
  173544. if (png_ptr->pass >= 7)
  173545. break;
  173546. png_ptr->iwidth = (png_ptr->width +
  173547. png_pass_inc[png_ptr->pass] - 1 -
  173548. png_pass_start[png_ptr->pass]) /
  173549. png_pass_inc[png_ptr->pass];
  173550. png_ptr->irowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,
  173551. png_ptr->iwidth) + 1;
  173552. if (!(png_ptr->transformations & PNG_INTERLACE))
  173553. {
  173554. png_ptr->num_rows = (png_ptr->height +
  173555. png_pass_yinc[png_ptr->pass] - 1 -
  173556. png_pass_ystart[png_ptr->pass]) /
  173557. png_pass_yinc[png_ptr->pass];
  173558. if (!(png_ptr->num_rows))
  173559. continue;
  173560. }
  173561. else /* if (png_ptr->transformations & PNG_INTERLACE) */
  173562. break;
  173563. } while (png_ptr->iwidth == 0);
  173564. if (png_ptr->pass < 7)
  173565. return;
  173566. }
  173567. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  173568. {
  173569. #ifdef PNG_USE_LOCAL_ARRAYS
  173570. PNG_CONST PNG_IDAT;
  173571. #endif
  173572. char extra;
  173573. int ret;
  173574. png_ptr->zstream.next_out = (Bytef *)&extra;
  173575. png_ptr->zstream.avail_out = (uInt)1;
  173576. for(;;)
  173577. {
  173578. if (!(png_ptr->zstream.avail_in))
  173579. {
  173580. while (!png_ptr->idat_size)
  173581. {
  173582. png_byte chunk_length[4];
  173583. png_crc_finish(png_ptr, 0);
  173584. png_read_data(png_ptr, chunk_length, 4);
  173585. png_ptr->idat_size = png_get_uint_31(png_ptr, chunk_length);
  173586. png_reset_crc(png_ptr);
  173587. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  173588. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  173589. png_error(png_ptr, "Not enough image data");
  173590. }
  173591. png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size;
  173592. png_ptr->zstream.next_in = png_ptr->zbuf;
  173593. if (png_ptr->zbuf_size > png_ptr->idat_size)
  173594. png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size;
  173595. png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zstream.avail_in);
  173596. png_ptr->idat_size -= png_ptr->zstream.avail_in;
  173597. }
  173598. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  173599. if (ret == Z_STREAM_END)
  173600. {
  173601. if (!(png_ptr->zstream.avail_out) || png_ptr->zstream.avail_in ||
  173602. png_ptr->idat_size)
  173603. png_warning(png_ptr, "Extra compressed data");
  173604. png_ptr->mode |= PNG_AFTER_IDAT;
  173605. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  173606. break;
  173607. }
  173608. if (ret != Z_OK)
  173609. png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg :
  173610. "Decompression Error");
  173611. if (!(png_ptr->zstream.avail_out))
  173612. {
  173613. png_warning(png_ptr, "Extra compressed data.");
  173614. png_ptr->mode |= PNG_AFTER_IDAT;
  173615. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  173616. break;
  173617. }
  173618. }
  173619. png_ptr->zstream.avail_out = 0;
  173620. }
  173621. if (png_ptr->idat_size || png_ptr->zstream.avail_in)
  173622. png_warning(png_ptr, "Extra compression data");
  173623. inflateReset(&png_ptr->zstream);
  173624. png_ptr->mode |= PNG_AFTER_IDAT;
  173625. }
  173626. void /* PRIVATE */
  173627. png_read_start_row(png_structp png_ptr)
  173628. {
  173629. #ifdef PNG_USE_LOCAL_ARRAYS
  173630. PNG_CONST int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  173631. PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  173632. PNG_CONST int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  173633. PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  173634. #endif
  173635. int max_pixel_depth;
  173636. png_uint_32 row_bytes;
  173637. png_debug(1, "in png_read_start_row\n");
  173638. png_ptr->zstream.avail_in = 0;
  173639. png_init_read_transformations(png_ptr);
  173640. if (png_ptr->interlaced)
  173641. {
  173642. if (!(png_ptr->transformations & PNG_INTERLACE))
  173643. png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
  173644. png_pass_ystart[0]) / png_pass_yinc[0];
  173645. else
  173646. png_ptr->num_rows = png_ptr->height;
  173647. png_ptr->iwidth = (png_ptr->width +
  173648. png_pass_inc[png_ptr->pass] - 1 -
  173649. png_pass_start[png_ptr->pass]) /
  173650. png_pass_inc[png_ptr->pass];
  173651. row_bytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->iwidth) + 1;
  173652. png_ptr->irowbytes = (png_size_t)row_bytes;
  173653. if((png_uint_32)png_ptr->irowbytes != row_bytes)
  173654. png_error(png_ptr, "Rowbytes overflow in png_read_start_row");
  173655. }
  173656. else
  173657. {
  173658. png_ptr->num_rows = png_ptr->height;
  173659. png_ptr->iwidth = png_ptr->width;
  173660. png_ptr->irowbytes = png_ptr->rowbytes + 1;
  173661. }
  173662. max_pixel_depth = png_ptr->pixel_depth;
  173663. #if defined(PNG_READ_PACK_SUPPORTED)
  173664. if ((png_ptr->transformations & PNG_PACK) && png_ptr->bit_depth < 8)
  173665. max_pixel_depth = 8;
  173666. #endif
  173667. #if defined(PNG_READ_EXPAND_SUPPORTED)
  173668. if (png_ptr->transformations & PNG_EXPAND)
  173669. {
  173670. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173671. {
  173672. if (png_ptr->num_trans)
  173673. max_pixel_depth = 32;
  173674. else
  173675. max_pixel_depth = 24;
  173676. }
  173677. else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
  173678. {
  173679. if (max_pixel_depth < 8)
  173680. max_pixel_depth = 8;
  173681. if (png_ptr->num_trans)
  173682. max_pixel_depth *= 2;
  173683. }
  173684. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  173685. {
  173686. if (png_ptr->num_trans)
  173687. {
  173688. max_pixel_depth *= 4;
  173689. max_pixel_depth /= 3;
  173690. }
  173691. }
  173692. }
  173693. #endif
  173694. #if defined(PNG_READ_FILLER_SUPPORTED)
  173695. if (png_ptr->transformations & (PNG_FILLER))
  173696. {
  173697. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173698. max_pixel_depth = 32;
  173699. else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
  173700. {
  173701. if (max_pixel_depth <= 8)
  173702. max_pixel_depth = 16;
  173703. else
  173704. max_pixel_depth = 32;
  173705. }
  173706. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  173707. {
  173708. if (max_pixel_depth <= 32)
  173709. max_pixel_depth = 32;
  173710. else
  173711. max_pixel_depth = 64;
  173712. }
  173713. }
  173714. #endif
  173715. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  173716. if (png_ptr->transformations & PNG_GRAY_TO_RGB)
  173717. {
  173718. if (
  173719. #if defined(PNG_READ_EXPAND_SUPPORTED)
  173720. (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND)) ||
  173721. #endif
  173722. #if defined(PNG_READ_FILLER_SUPPORTED)
  173723. (png_ptr->transformations & (PNG_FILLER)) ||
  173724. #endif
  173725. png_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  173726. {
  173727. if (max_pixel_depth <= 16)
  173728. max_pixel_depth = 32;
  173729. else
  173730. max_pixel_depth = 64;
  173731. }
  173732. else
  173733. {
  173734. if (max_pixel_depth <= 8)
  173735. {
  173736. if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  173737. max_pixel_depth = 32;
  173738. else
  173739. max_pixel_depth = 24;
  173740. }
  173741. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  173742. max_pixel_depth = 64;
  173743. else
  173744. max_pixel_depth = 48;
  173745. }
  173746. }
  173747. #endif
  173748. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) && \
  173749. defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  173750. if(png_ptr->transformations & PNG_USER_TRANSFORM)
  173751. {
  173752. int user_pixel_depth=png_ptr->user_transform_depth*
  173753. png_ptr->user_transform_channels;
  173754. if(user_pixel_depth > max_pixel_depth)
  173755. max_pixel_depth=user_pixel_depth;
  173756. }
  173757. #endif
  173758. row_bytes = ((png_ptr->width + 7) & ~((png_uint_32)7));
  173759. row_bytes = PNG_ROWBYTES(max_pixel_depth,row_bytes) +
  173760. 1 + ((max_pixel_depth + 7) >> 3);
  173761. #ifdef PNG_MAX_MALLOC_64K
  173762. if (row_bytes > (png_uint_32)65536L)
  173763. png_error(png_ptr, "This image requires a row greater than 64KB");
  173764. #endif
  173765. png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr, row_bytes+64);
  173766. png_ptr->row_buf = png_ptr->big_row_buf+32;
  173767. #ifdef PNG_MAX_MALLOC_64K
  173768. if ((png_uint_32)png_ptr->rowbytes + 1 > (png_uint_32)65536L)
  173769. png_error(png_ptr, "This image requires a row greater than 64KB");
  173770. #endif
  173771. if ((png_uint_32)png_ptr->rowbytes > (png_uint_32)(PNG_SIZE_MAX - 1))
  173772. png_error(png_ptr, "Row has too many bytes to allocate in memory.");
  173773. png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)(
  173774. png_ptr->rowbytes + 1));
  173775. png_memset_check(png_ptr, png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
  173776. png_debug1(3, "width = %lu,\n", png_ptr->width);
  173777. png_debug1(3, "height = %lu,\n", png_ptr->height);
  173778. png_debug1(3, "iwidth = %lu,\n", png_ptr->iwidth);
  173779. png_debug1(3, "num_rows = %lu\n", png_ptr->num_rows);
  173780. png_debug1(3, "rowbytes = %lu,\n", png_ptr->rowbytes);
  173781. png_debug1(3, "irowbytes = %lu,\n", png_ptr->irowbytes);
  173782. png_ptr->flags |= PNG_FLAG_ROW_INIT;
  173783. }
  173784. #endif /* PNG_READ_SUPPORTED */
  173785. /*** End of inlined file: pngrutil.c ***/
  173786. /*** Start of inlined file: pngset.c ***/
  173787. #define PNG_INTERNAL
  173788. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  173789. #if defined(PNG_bKGD_SUPPORTED)
  173790. void PNGAPI
  173791. png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background)
  173792. {
  173793. png_debug1(1, "in %s storage function\n", "bKGD");
  173794. if (png_ptr == NULL || info_ptr == NULL)
  173795. return;
  173796. png_memcpy(&(info_ptr->background), background, png_sizeof(png_color_16));
  173797. info_ptr->valid |= PNG_INFO_bKGD;
  173798. }
  173799. #endif
  173800. #if defined(PNG_cHRM_SUPPORTED)
  173801. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173802. void PNGAPI
  173803. png_set_cHRM(png_structp png_ptr, png_infop info_ptr,
  173804. double white_x, double white_y, double red_x, double red_y,
  173805. double green_x, double green_y, double blue_x, double blue_y)
  173806. {
  173807. png_debug1(1, "in %s storage function\n", "cHRM");
  173808. if (png_ptr == NULL || info_ptr == NULL)
  173809. return;
  173810. if (white_x < 0.0 || white_y < 0.0 ||
  173811. red_x < 0.0 || red_y < 0.0 ||
  173812. green_x < 0.0 || green_y < 0.0 ||
  173813. blue_x < 0.0 || blue_y < 0.0)
  173814. {
  173815. png_warning(png_ptr,
  173816. "Ignoring attempt to set negative chromaticity value");
  173817. return;
  173818. }
  173819. if (white_x > 21474.83 || white_y > 21474.83 ||
  173820. red_x > 21474.83 || red_y > 21474.83 ||
  173821. green_x > 21474.83 || green_y > 21474.83 ||
  173822. blue_x > 21474.83 || blue_y > 21474.83)
  173823. {
  173824. png_warning(png_ptr,
  173825. "Ignoring attempt to set chromaticity value exceeding 21474.83");
  173826. return;
  173827. }
  173828. info_ptr->x_white = (float)white_x;
  173829. info_ptr->y_white = (float)white_y;
  173830. info_ptr->x_red = (float)red_x;
  173831. info_ptr->y_red = (float)red_y;
  173832. info_ptr->x_green = (float)green_x;
  173833. info_ptr->y_green = (float)green_y;
  173834. info_ptr->x_blue = (float)blue_x;
  173835. info_ptr->y_blue = (float)blue_y;
  173836. #ifdef PNG_FIXED_POINT_SUPPORTED
  173837. info_ptr->int_x_white = (png_fixed_point)(white_x*100000.+0.5);
  173838. info_ptr->int_y_white = (png_fixed_point)(white_y*100000.+0.5);
  173839. info_ptr->int_x_red = (png_fixed_point)( red_x*100000.+0.5);
  173840. info_ptr->int_y_red = (png_fixed_point)( red_y*100000.+0.5);
  173841. info_ptr->int_x_green = (png_fixed_point)(green_x*100000.+0.5);
  173842. info_ptr->int_y_green = (png_fixed_point)(green_y*100000.+0.5);
  173843. info_ptr->int_x_blue = (png_fixed_point)( blue_x*100000.+0.5);
  173844. info_ptr->int_y_blue = (png_fixed_point)( blue_y*100000.+0.5);
  173845. #endif
  173846. info_ptr->valid |= PNG_INFO_cHRM;
  173847. }
  173848. #endif
  173849. #ifdef PNG_FIXED_POINT_SUPPORTED
  173850. void PNGAPI
  173851. png_set_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
  173852. png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x,
  173853. png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y,
  173854. png_fixed_point blue_x, png_fixed_point blue_y)
  173855. {
  173856. png_debug1(1, "in %s storage function\n", "cHRM");
  173857. if (png_ptr == NULL || info_ptr == NULL)
  173858. return;
  173859. if (white_x < 0 || white_y < 0 ||
  173860. red_x < 0 || red_y < 0 ||
  173861. green_x < 0 || green_y < 0 ||
  173862. blue_x < 0 || blue_y < 0)
  173863. {
  173864. png_warning(png_ptr,
  173865. "Ignoring attempt to set negative chromaticity value");
  173866. return;
  173867. }
  173868. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173869. if (white_x > (double) PNG_UINT_31_MAX ||
  173870. white_y > (double) PNG_UINT_31_MAX ||
  173871. red_x > (double) PNG_UINT_31_MAX ||
  173872. red_y > (double) PNG_UINT_31_MAX ||
  173873. green_x > (double) PNG_UINT_31_MAX ||
  173874. green_y > (double) PNG_UINT_31_MAX ||
  173875. blue_x > (double) PNG_UINT_31_MAX ||
  173876. blue_y > (double) PNG_UINT_31_MAX)
  173877. #else
  173878. if (white_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173879. white_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173880. red_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173881. red_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173882. green_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173883. green_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173884. blue_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173885. blue_y > (png_fixed_point) PNG_UINT_31_MAX/100000L)
  173886. #endif
  173887. {
  173888. png_warning(png_ptr,
  173889. "Ignoring attempt to set chromaticity value exceeding 21474.83");
  173890. return;
  173891. }
  173892. info_ptr->int_x_white = white_x;
  173893. info_ptr->int_y_white = white_y;
  173894. info_ptr->int_x_red = red_x;
  173895. info_ptr->int_y_red = red_y;
  173896. info_ptr->int_x_green = green_x;
  173897. info_ptr->int_y_green = green_y;
  173898. info_ptr->int_x_blue = blue_x;
  173899. info_ptr->int_y_blue = blue_y;
  173900. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173901. info_ptr->x_white = (float)(white_x/100000.);
  173902. info_ptr->y_white = (float)(white_y/100000.);
  173903. info_ptr->x_red = (float)( red_x/100000.);
  173904. info_ptr->y_red = (float)( red_y/100000.);
  173905. info_ptr->x_green = (float)(green_x/100000.);
  173906. info_ptr->y_green = (float)(green_y/100000.);
  173907. info_ptr->x_blue = (float)( blue_x/100000.);
  173908. info_ptr->y_blue = (float)( blue_y/100000.);
  173909. #endif
  173910. info_ptr->valid |= PNG_INFO_cHRM;
  173911. }
  173912. #endif
  173913. #endif
  173914. #if defined(PNG_gAMA_SUPPORTED)
  173915. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173916. void PNGAPI
  173917. png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma)
  173918. {
  173919. double gamma;
  173920. png_debug1(1, "in %s storage function\n", "gAMA");
  173921. if (png_ptr == NULL || info_ptr == NULL)
  173922. return;
  173923. if (file_gamma > 21474.83)
  173924. {
  173925. png_warning(png_ptr, "Limiting gamma to 21474.83");
  173926. gamma=21474.83;
  173927. }
  173928. else
  173929. gamma=file_gamma;
  173930. info_ptr->gamma = (float)gamma;
  173931. #ifdef PNG_FIXED_POINT_SUPPORTED
  173932. info_ptr->int_gamma = (int)(gamma*100000.+.5);
  173933. #endif
  173934. info_ptr->valid |= PNG_INFO_gAMA;
  173935. if(gamma == 0.0)
  173936. png_warning(png_ptr, "Setting gamma=0");
  173937. }
  173938. #endif
  173939. void PNGAPI
  173940. png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point
  173941. int_gamma)
  173942. {
  173943. png_fixed_point gamma;
  173944. png_debug1(1, "in %s storage function\n", "gAMA");
  173945. if (png_ptr == NULL || info_ptr == NULL)
  173946. return;
  173947. if (int_gamma > (png_fixed_point) PNG_UINT_31_MAX)
  173948. {
  173949. png_warning(png_ptr, "Limiting gamma to 21474.83");
  173950. gamma=PNG_UINT_31_MAX;
  173951. }
  173952. else
  173953. {
  173954. if (int_gamma < 0)
  173955. {
  173956. png_warning(png_ptr, "Setting negative gamma to zero");
  173957. gamma=0;
  173958. }
  173959. else
  173960. gamma=int_gamma;
  173961. }
  173962. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173963. info_ptr->gamma = (float)(gamma/100000.);
  173964. #endif
  173965. #ifdef PNG_FIXED_POINT_SUPPORTED
  173966. info_ptr->int_gamma = gamma;
  173967. #endif
  173968. info_ptr->valid |= PNG_INFO_gAMA;
  173969. if(gamma == 0)
  173970. png_warning(png_ptr, "Setting gamma=0");
  173971. }
  173972. #endif
  173973. #if defined(PNG_hIST_SUPPORTED)
  173974. void PNGAPI
  173975. png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist)
  173976. {
  173977. int i;
  173978. png_debug1(1, "in %s storage function\n", "hIST");
  173979. if (png_ptr == NULL || info_ptr == NULL)
  173980. return;
  173981. if (info_ptr->num_palette == 0 || info_ptr->num_palette
  173982. > PNG_MAX_PALETTE_LENGTH)
  173983. {
  173984. png_warning(png_ptr,
  173985. "Invalid palette size, hIST allocation skipped.");
  173986. return;
  173987. }
  173988. #ifdef PNG_FREE_ME_SUPPORTED
  173989. png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0);
  173990. #endif
  173991. png_ptr->hist = (png_uint_16p)png_malloc_warn(png_ptr,
  173992. (png_uint_32)(PNG_MAX_PALETTE_LENGTH * png_sizeof (png_uint_16)));
  173993. if (png_ptr->hist == NULL)
  173994. {
  173995. png_warning(png_ptr, "Insufficient memory for hIST chunk data.");
  173996. return;
  173997. }
  173998. for (i = 0; i < info_ptr->num_palette; i++)
  173999. png_ptr->hist[i] = hist[i];
  174000. info_ptr->hist = png_ptr->hist;
  174001. info_ptr->valid |= PNG_INFO_hIST;
  174002. #ifdef PNG_FREE_ME_SUPPORTED
  174003. info_ptr->free_me |= PNG_FREE_HIST;
  174004. #else
  174005. png_ptr->flags |= PNG_FLAG_FREE_HIST;
  174006. #endif
  174007. }
  174008. #endif
  174009. void PNGAPI
  174010. png_set_IHDR(png_structp png_ptr, png_infop info_ptr,
  174011. png_uint_32 width, png_uint_32 height, int bit_depth,
  174012. int color_type, int interlace_type, int compression_type,
  174013. int filter_type)
  174014. {
  174015. png_debug1(1, "in %s storage function\n", "IHDR");
  174016. if (png_ptr == NULL || info_ptr == NULL)
  174017. return;
  174018. if (width == 0 || height == 0)
  174019. png_error(png_ptr, "Image width or height is zero in IHDR");
  174020. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  174021. if (width > png_ptr->user_width_max || height > png_ptr->user_height_max)
  174022. png_error(png_ptr, "image size exceeds user limits in IHDR");
  174023. #else
  174024. if (width > PNG_USER_WIDTH_MAX || height > PNG_USER_HEIGHT_MAX)
  174025. png_error(png_ptr, "image size exceeds user limits in IHDR");
  174026. #endif
  174027. if (width > PNG_UINT_31_MAX || height > PNG_UINT_31_MAX)
  174028. png_error(png_ptr, "Invalid image size in IHDR");
  174029. if ( width > (PNG_UINT_32_MAX
  174030. >> 3) /* 8-byte RGBA pixels */
  174031. - 64 /* bigrowbuf hack */
  174032. - 1 /* filter byte */
  174033. - 7*8 /* rounding of width to multiple of 8 pixels */
  174034. - 8) /* extra max_pixel_depth pad */
  174035. png_warning(png_ptr, "Width is too large for libpng to process pixels");
  174036. if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 &&
  174037. bit_depth != 8 && bit_depth != 16)
  174038. png_error(png_ptr, "Invalid bit depth in IHDR");
  174039. if (color_type < 0 || color_type == 1 ||
  174040. color_type == 5 || color_type > 6)
  174041. png_error(png_ptr, "Invalid color type in IHDR");
  174042. if (((color_type == PNG_COLOR_TYPE_PALETTE) && bit_depth > 8) ||
  174043. ((color_type == PNG_COLOR_TYPE_RGB ||
  174044. color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
  174045. color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8))
  174046. png_error(png_ptr, "Invalid color type/bit depth combination in IHDR");
  174047. if (interlace_type >= PNG_INTERLACE_LAST)
  174048. png_error(png_ptr, "Unknown interlace method in IHDR");
  174049. if (compression_type != PNG_COMPRESSION_TYPE_BASE)
  174050. png_error(png_ptr, "Unknown compression method in IHDR");
  174051. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  174052. if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&png_ptr->mng_features_permitted)
  174053. png_warning(png_ptr,"MNG features are not allowed in a PNG datastream");
  174054. if(filter_type != PNG_FILTER_TYPE_BASE)
  174055. {
  174056. if(!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  174057. (filter_type == PNG_INTRAPIXEL_DIFFERENCING) &&
  174058. ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
  174059. (color_type == PNG_COLOR_TYPE_RGB ||
  174060. color_type == PNG_COLOR_TYPE_RGB_ALPHA)))
  174061. png_error(png_ptr, "Unknown filter method in IHDR");
  174062. if(png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)
  174063. png_warning(png_ptr, "Invalid filter method in IHDR");
  174064. }
  174065. #else
  174066. if(filter_type != PNG_FILTER_TYPE_BASE)
  174067. png_error(png_ptr, "Unknown filter method in IHDR");
  174068. #endif
  174069. info_ptr->width = width;
  174070. info_ptr->height = height;
  174071. info_ptr->bit_depth = (png_byte)bit_depth;
  174072. info_ptr->color_type =(png_byte) color_type;
  174073. info_ptr->compression_type = (png_byte)compression_type;
  174074. info_ptr->filter_type = (png_byte)filter_type;
  174075. info_ptr->interlace_type = (png_byte)interlace_type;
  174076. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  174077. info_ptr->channels = 1;
  174078. else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
  174079. info_ptr->channels = 3;
  174080. else
  174081. info_ptr->channels = 1;
  174082. if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
  174083. info_ptr->channels++;
  174084. info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth);
  174085. if (width > (PNG_UINT_32_MAX
  174086. >> 3) /* 8-byte RGBA pixels */
  174087. - 64 /* bigrowbuf hack */
  174088. - 1 /* filter byte */
  174089. - 7*8 /* rounding of width to multiple of 8 pixels */
  174090. - 8) /* extra max_pixel_depth pad */
  174091. info_ptr->rowbytes = (png_size_t)0;
  174092. else
  174093. info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth,width);
  174094. }
  174095. #if defined(PNG_oFFs_SUPPORTED)
  174096. void PNGAPI
  174097. png_set_oFFs(png_structp png_ptr, png_infop info_ptr,
  174098. png_int_32 offset_x, png_int_32 offset_y, int unit_type)
  174099. {
  174100. png_debug1(1, "in %s storage function\n", "oFFs");
  174101. if (png_ptr == NULL || info_ptr == NULL)
  174102. return;
  174103. info_ptr->x_offset = offset_x;
  174104. info_ptr->y_offset = offset_y;
  174105. info_ptr->offset_unit_type = (png_byte)unit_type;
  174106. info_ptr->valid |= PNG_INFO_oFFs;
  174107. }
  174108. #endif
  174109. #if defined(PNG_pCAL_SUPPORTED)
  174110. void PNGAPI
  174111. png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
  174112. png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams,
  174113. png_charp units, png_charpp params)
  174114. {
  174115. png_uint_32 length;
  174116. int i;
  174117. png_debug1(1, "in %s storage function\n", "pCAL");
  174118. if (png_ptr == NULL || info_ptr == NULL)
  174119. return;
  174120. length = png_strlen(purpose) + 1;
  174121. png_debug1(3, "allocating purpose for info (%lu bytes)\n", length);
  174122. info_ptr->pcal_purpose = (png_charp)png_malloc_warn(png_ptr, length);
  174123. if (info_ptr->pcal_purpose == NULL)
  174124. {
  174125. png_warning(png_ptr, "Insufficient memory for pCAL purpose.");
  174126. return;
  174127. }
  174128. png_memcpy(info_ptr->pcal_purpose, purpose, (png_size_t)length);
  174129. png_debug(3, "storing X0, X1, type, and nparams in info\n");
  174130. info_ptr->pcal_X0 = X0;
  174131. info_ptr->pcal_X1 = X1;
  174132. info_ptr->pcal_type = (png_byte)type;
  174133. info_ptr->pcal_nparams = (png_byte)nparams;
  174134. length = png_strlen(units) + 1;
  174135. png_debug1(3, "allocating units for info (%lu bytes)\n", length);
  174136. info_ptr->pcal_units = (png_charp)png_malloc_warn(png_ptr, length);
  174137. if (info_ptr->pcal_units == NULL)
  174138. {
  174139. png_warning(png_ptr, "Insufficient memory for pCAL units.");
  174140. return;
  174141. }
  174142. png_memcpy(info_ptr->pcal_units, units, (png_size_t)length);
  174143. info_ptr->pcal_params = (png_charpp)png_malloc_warn(png_ptr,
  174144. (png_uint_32)((nparams + 1) * png_sizeof(png_charp)));
  174145. if (info_ptr->pcal_params == NULL)
  174146. {
  174147. png_warning(png_ptr, "Insufficient memory for pCAL params.");
  174148. return;
  174149. }
  174150. info_ptr->pcal_params[nparams] = NULL;
  174151. for (i = 0; i < nparams; i++)
  174152. {
  174153. length = png_strlen(params[i]) + 1;
  174154. png_debug2(3, "allocating parameter %d for info (%lu bytes)\n", i, length);
  174155. info_ptr->pcal_params[i] = (png_charp)png_malloc_warn(png_ptr, length);
  174156. if (info_ptr->pcal_params[i] == NULL)
  174157. {
  174158. png_warning(png_ptr, "Insufficient memory for pCAL parameter.");
  174159. return;
  174160. }
  174161. png_memcpy(info_ptr->pcal_params[i], params[i], (png_size_t)length);
  174162. }
  174163. info_ptr->valid |= PNG_INFO_pCAL;
  174164. #ifdef PNG_FREE_ME_SUPPORTED
  174165. info_ptr->free_me |= PNG_FREE_PCAL;
  174166. #endif
  174167. }
  174168. #endif
  174169. #if defined(PNG_READ_sCAL_SUPPORTED) || defined(PNG_WRITE_sCAL_SUPPORTED)
  174170. #ifdef PNG_FLOATING_POINT_SUPPORTED
  174171. void PNGAPI
  174172. png_set_sCAL(png_structp png_ptr, png_infop info_ptr,
  174173. int unit, double width, double height)
  174174. {
  174175. png_debug1(1, "in %s storage function\n", "sCAL");
  174176. if (png_ptr == NULL || info_ptr == NULL)
  174177. return;
  174178. info_ptr->scal_unit = (png_byte)unit;
  174179. info_ptr->scal_pixel_width = width;
  174180. info_ptr->scal_pixel_height = height;
  174181. info_ptr->valid |= PNG_INFO_sCAL;
  174182. }
  174183. #else
  174184. #ifdef PNG_FIXED_POINT_SUPPORTED
  174185. void PNGAPI
  174186. png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr,
  174187. int unit, png_charp swidth, png_charp sheight)
  174188. {
  174189. png_uint_32 length;
  174190. png_debug1(1, "in %s storage function\n", "sCAL");
  174191. if (png_ptr == NULL || info_ptr == NULL)
  174192. return;
  174193. info_ptr->scal_unit = (png_byte)unit;
  174194. length = png_strlen(swidth) + 1;
  174195. png_debug1(3, "allocating unit for info (%d bytes)\n", length);
  174196. info_ptr->scal_s_width = (png_charp)png_malloc_warn(png_ptr, length);
  174197. if (info_ptr->scal_s_width == NULL)
  174198. {
  174199. png_warning(png_ptr,
  174200. "Memory allocation failed while processing sCAL.");
  174201. }
  174202. png_memcpy(info_ptr->scal_s_width, swidth, (png_size_t)length);
  174203. length = png_strlen(sheight) + 1;
  174204. png_debug1(3, "allocating unit for info (%d bytes)\n", length);
  174205. info_ptr->scal_s_height = (png_charp)png_malloc_warn(png_ptr, length);
  174206. if (info_ptr->scal_s_height == NULL)
  174207. {
  174208. png_free (png_ptr, info_ptr->scal_s_width);
  174209. png_warning(png_ptr,
  174210. "Memory allocation failed while processing sCAL.");
  174211. }
  174212. png_memcpy(info_ptr->scal_s_height, sheight, (png_size_t)length);
  174213. info_ptr->valid |= PNG_INFO_sCAL;
  174214. #ifdef PNG_FREE_ME_SUPPORTED
  174215. info_ptr->free_me |= PNG_FREE_SCAL;
  174216. #endif
  174217. }
  174218. #endif
  174219. #endif
  174220. #endif
  174221. #if defined(PNG_pHYs_SUPPORTED)
  174222. void PNGAPI
  174223. png_set_pHYs(png_structp png_ptr, png_infop info_ptr,
  174224. png_uint_32 res_x, png_uint_32 res_y, int unit_type)
  174225. {
  174226. png_debug1(1, "in %s storage function\n", "pHYs");
  174227. if (png_ptr == NULL || info_ptr == NULL)
  174228. return;
  174229. info_ptr->x_pixels_per_unit = res_x;
  174230. info_ptr->y_pixels_per_unit = res_y;
  174231. info_ptr->phys_unit_type = (png_byte)unit_type;
  174232. info_ptr->valid |= PNG_INFO_pHYs;
  174233. }
  174234. #endif
  174235. void PNGAPI
  174236. png_set_PLTE(png_structp png_ptr, png_infop info_ptr,
  174237. png_colorp palette, int num_palette)
  174238. {
  174239. png_debug1(1, "in %s storage function\n", "PLTE");
  174240. if (png_ptr == NULL || info_ptr == NULL)
  174241. return;
  174242. if (num_palette < 0 || num_palette > PNG_MAX_PALETTE_LENGTH)
  174243. {
  174244. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  174245. png_error(png_ptr, "Invalid palette length");
  174246. else
  174247. {
  174248. png_warning(png_ptr, "Invalid palette length");
  174249. return;
  174250. }
  174251. }
  174252. #ifdef PNG_FREE_ME_SUPPORTED
  174253. png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0);
  174254. #endif
  174255. png_ptr->palette = (png_colorp)png_malloc(png_ptr,
  174256. PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color));
  174257. png_memset(png_ptr->palette, 0, PNG_MAX_PALETTE_LENGTH *
  174258. png_sizeof(png_color));
  174259. png_memcpy(png_ptr->palette, palette, num_palette * png_sizeof (png_color));
  174260. info_ptr->palette = png_ptr->palette;
  174261. info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette;
  174262. #ifdef PNG_FREE_ME_SUPPORTED
  174263. info_ptr->free_me |= PNG_FREE_PLTE;
  174264. #else
  174265. png_ptr->flags |= PNG_FLAG_FREE_PLTE;
  174266. #endif
  174267. info_ptr->valid |= PNG_INFO_PLTE;
  174268. }
  174269. #if defined(PNG_sBIT_SUPPORTED)
  174270. void PNGAPI
  174271. png_set_sBIT(png_structp png_ptr, png_infop info_ptr,
  174272. png_color_8p sig_bit)
  174273. {
  174274. png_debug1(1, "in %s storage function\n", "sBIT");
  174275. if (png_ptr == NULL || info_ptr == NULL)
  174276. return;
  174277. png_memcpy(&(info_ptr->sig_bit), sig_bit, png_sizeof (png_color_8));
  174278. info_ptr->valid |= PNG_INFO_sBIT;
  174279. }
  174280. #endif
  174281. #if defined(PNG_sRGB_SUPPORTED)
  174282. void PNGAPI
  174283. png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int intent)
  174284. {
  174285. png_debug1(1, "in %s storage function\n", "sRGB");
  174286. if (png_ptr == NULL || info_ptr == NULL)
  174287. return;
  174288. info_ptr->srgb_intent = (png_byte)intent;
  174289. info_ptr->valid |= PNG_INFO_sRGB;
  174290. }
  174291. void PNGAPI
  174292. png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr,
  174293. int intent)
  174294. {
  174295. #if defined(PNG_gAMA_SUPPORTED)
  174296. #ifdef PNG_FLOATING_POINT_SUPPORTED
  174297. float file_gamma;
  174298. #endif
  174299. #ifdef PNG_FIXED_POINT_SUPPORTED
  174300. png_fixed_point int_file_gamma;
  174301. #endif
  174302. #endif
  174303. #if defined(PNG_cHRM_SUPPORTED)
  174304. #ifdef PNG_FLOATING_POINT_SUPPORTED
  174305. float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
  174306. #endif
  174307. #ifdef PNG_FIXED_POINT_SUPPORTED
  174308. png_fixed_point int_white_x, int_white_y, int_red_x, int_red_y, int_green_x,
  174309. int_green_y, int_blue_x, int_blue_y;
  174310. #endif
  174311. #endif
  174312. png_debug1(1, "in %s storage function\n", "sRGB_gAMA_and_cHRM");
  174313. if (png_ptr == NULL || info_ptr == NULL)
  174314. return;
  174315. png_set_sRGB(png_ptr, info_ptr, intent);
  174316. #if defined(PNG_gAMA_SUPPORTED)
  174317. #ifdef PNG_FLOATING_POINT_SUPPORTED
  174318. file_gamma = (float).45455;
  174319. png_set_gAMA(png_ptr, info_ptr, file_gamma);
  174320. #endif
  174321. #ifdef PNG_FIXED_POINT_SUPPORTED
  174322. int_file_gamma = 45455L;
  174323. png_set_gAMA_fixed(png_ptr, info_ptr, int_file_gamma);
  174324. #endif
  174325. #endif
  174326. #if defined(PNG_cHRM_SUPPORTED)
  174327. #ifdef PNG_FIXED_POINT_SUPPORTED
  174328. int_white_x = 31270L;
  174329. int_white_y = 32900L;
  174330. int_red_x = 64000L;
  174331. int_red_y = 33000L;
  174332. int_green_x = 30000L;
  174333. int_green_y = 60000L;
  174334. int_blue_x = 15000L;
  174335. int_blue_y = 6000L;
  174336. png_set_cHRM_fixed(png_ptr, info_ptr,
  174337. int_white_x, int_white_y, int_red_x, int_red_y, int_green_x, int_green_y,
  174338. int_blue_x, int_blue_y);
  174339. #endif
  174340. #ifdef PNG_FLOATING_POINT_SUPPORTED
  174341. white_x = (float).3127;
  174342. white_y = (float).3290;
  174343. red_x = (float).64;
  174344. red_y = (float).33;
  174345. green_x = (float).30;
  174346. green_y = (float).60;
  174347. blue_x = (float).15;
  174348. blue_y = (float).06;
  174349. png_set_cHRM(png_ptr, info_ptr,
  174350. white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
  174351. #endif
  174352. #endif
  174353. }
  174354. #endif
  174355. #if defined(PNG_iCCP_SUPPORTED)
  174356. void PNGAPI
  174357. png_set_iCCP(png_structp png_ptr, png_infop info_ptr,
  174358. png_charp name, int compression_type,
  174359. png_charp profile, png_uint_32 proflen)
  174360. {
  174361. png_charp new_iccp_name;
  174362. png_charp new_iccp_profile;
  174363. png_debug1(1, "in %s storage function\n", "iCCP");
  174364. if (png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL)
  174365. return;
  174366. new_iccp_name = (png_charp)png_malloc_warn(png_ptr, png_strlen(name)+1);
  174367. if (new_iccp_name == NULL)
  174368. {
  174369. png_warning(png_ptr, "Insufficient memory to process iCCP chunk.");
  174370. return;
  174371. }
  174372. png_strncpy(new_iccp_name, name, png_strlen(name)+1);
  174373. new_iccp_profile = (png_charp)png_malloc_warn(png_ptr, proflen);
  174374. if (new_iccp_profile == NULL)
  174375. {
  174376. png_free (png_ptr, new_iccp_name);
  174377. png_warning(png_ptr, "Insufficient memory to process iCCP profile.");
  174378. return;
  174379. }
  174380. png_memcpy(new_iccp_profile, profile, (png_size_t)proflen);
  174381. png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, 0);
  174382. info_ptr->iccp_proflen = proflen;
  174383. info_ptr->iccp_name = new_iccp_name;
  174384. info_ptr->iccp_profile = new_iccp_profile;
  174385. info_ptr->iccp_compression = (png_byte)compression_type;
  174386. #ifdef PNG_FREE_ME_SUPPORTED
  174387. info_ptr->free_me |= PNG_FREE_ICCP;
  174388. #endif
  174389. info_ptr->valid |= PNG_INFO_iCCP;
  174390. }
  174391. #endif
  174392. #if defined(PNG_TEXT_SUPPORTED)
  174393. void PNGAPI
  174394. png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
  174395. int num_text)
  174396. {
  174397. int ret;
  174398. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, num_text);
  174399. if (ret)
  174400. png_error(png_ptr, "Insufficient memory to store text");
  174401. }
  174402. int /* PRIVATE */
  174403. png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
  174404. int num_text)
  174405. {
  174406. int i;
  174407. png_debug1(1, "in %s storage function\n", (png_ptr->chunk_name[0] == '\0' ?
  174408. "text" : (png_const_charp)png_ptr->chunk_name));
  174409. if (png_ptr == NULL || info_ptr == NULL || num_text == 0)
  174410. return(0);
  174411. if (info_ptr->num_text + num_text > info_ptr->max_text)
  174412. {
  174413. if (info_ptr->text != NULL)
  174414. {
  174415. png_textp old_text;
  174416. int old_max;
  174417. old_max = info_ptr->max_text;
  174418. info_ptr->max_text = info_ptr->num_text + num_text + 8;
  174419. old_text = info_ptr->text;
  174420. info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
  174421. (png_uint_32)(info_ptr->max_text * png_sizeof (png_text)));
  174422. if (info_ptr->text == NULL)
  174423. {
  174424. png_free(png_ptr, old_text);
  174425. return(1);
  174426. }
  174427. png_memcpy(info_ptr->text, old_text, (png_size_t)(old_max *
  174428. png_sizeof(png_text)));
  174429. png_free(png_ptr, old_text);
  174430. }
  174431. else
  174432. {
  174433. info_ptr->max_text = num_text + 8;
  174434. info_ptr->num_text = 0;
  174435. info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
  174436. (png_uint_32)(info_ptr->max_text * png_sizeof (png_text)));
  174437. if (info_ptr->text == NULL)
  174438. return(1);
  174439. #ifdef PNG_FREE_ME_SUPPORTED
  174440. info_ptr->free_me |= PNG_FREE_TEXT;
  174441. #endif
  174442. }
  174443. png_debug1(3, "allocated %d entries for info_ptr->text\n",
  174444. info_ptr->max_text);
  174445. }
  174446. for (i = 0; i < num_text; i++)
  174447. {
  174448. png_size_t text_length,key_len;
  174449. png_size_t lang_len,lang_key_len;
  174450. png_textp textp = &(info_ptr->text[info_ptr->num_text]);
  174451. if (text_ptr[i].key == NULL)
  174452. continue;
  174453. key_len = png_strlen(text_ptr[i].key);
  174454. if(text_ptr[i].compression <= 0)
  174455. {
  174456. lang_len = 0;
  174457. lang_key_len = 0;
  174458. }
  174459. else
  174460. #ifdef PNG_iTXt_SUPPORTED
  174461. {
  174462. if (text_ptr[i].lang != NULL)
  174463. lang_len = png_strlen(text_ptr[i].lang);
  174464. else
  174465. lang_len = 0;
  174466. if (text_ptr[i].lang_key != NULL)
  174467. lang_key_len = png_strlen(text_ptr[i].lang_key);
  174468. else
  174469. lang_key_len = 0;
  174470. }
  174471. #else
  174472. {
  174473. png_warning(png_ptr, "iTXt chunk not supported.");
  174474. continue;
  174475. }
  174476. #endif
  174477. if (text_ptr[i].text == NULL || text_ptr[i].text[0] == '\0')
  174478. {
  174479. text_length = 0;
  174480. #ifdef PNG_iTXt_SUPPORTED
  174481. if(text_ptr[i].compression > 0)
  174482. textp->compression = PNG_ITXT_COMPRESSION_NONE;
  174483. else
  174484. #endif
  174485. textp->compression = PNG_TEXT_COMPRESSION_NONE;
  174486. }
  174487. else
  174488. {
  174489. text_length = png_strlen(text_ptr[i].text);
  174490. textp->compression = text_ptr[i].compression;
  174491. }
  174492. textp->key = (png_charp)png_malloc_warn(png_ptr,
  174493. (png_uint_32)(key_len + text_length + lang_len + lang_key_len + 4));
  174494. if (textp->key == NULL)
  174495. return(1);
  174496. png_debug2(2, "Allocated %lu bytes at %x in png_set_text\n",
  174497. (png_uint_32)(key_len + lang_len + lang_key_len + text_length + 4),
  174498. (int)textp->key);
  174499. png_memcpy(textp->key, text_ptr[i].key,
  174500. (png_size_t)(key_len));
  174501. *(textp->key+key_len) = '\0';
  174502. #ifdef PNG_iTXt_SUPPORTED
  174503. if (text_ptr[i].compression > 0)
  174504. {
  174505. textp->lang=textp->key + key_len + 1;
  174506. png_memcpy(textp->lang, text_ptr[i].lang, lang_len);
  174507. *(textp->lang+lang_len) = '\0';
  174508. textp->lang_key=textp->lang + lang_len + 1;
  174509. png_memcpy(textp->lang_key, text_ptr[i].lang_key, lang_key_len);
  174510. *(textp->lang_key+lang_key_len) = '\0';
  174511. textp->text=textp->lang_key + lang_key_len + 1;
  174512. }
  174513. else
  174514. #endif
  174515. {
  174516. #ifdef PNG_iTXt_SUPPORTED
  174517. textp->lang=NULL;
  174518. textp->lang_key=NULL;
  174519. #endif
  174520. textp->text=textp->key + key_len + 1;
  174521. }
  174522. if(text_length)
  174523. png_memcpy(textp->text, text_ptr[i].text,
  174524. (png_size_t)(text_length));
  174525. *(textp->text+text_length) = '\0';
  174526. #ifdef PNG_iTXt_SUPPORTED
  174527. if(textp->compression > 0)
  174528. {
  174529. textp->text_length = 0;
  174530. textp->itxt_length = text_length;
  174531. }
  174532. else
  174533. #endif
  174534. {
  174535. textp->text_length = text_length;
  174536. #ifdef PNG_iTXt_SUPPORTED
  174537. textp->itxt_length = 0;
  174538. #endif
  174539. }
  174540. info_ptr->num_text++;
  174541. png_debug1(3, "transferred text chunk %d\n", info_ptr->num_text);
  174542. }
  174543. return(0);
  174544. }
  174545. #endif
  174546. #if defined(PNG_tIME_SUPPORTED)
  174547. void PNGAPI
  174548. png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_timep mod_time)
  174549. {
  174550. png_debug1(1, "in %s storage function\n", "tIME");
  174551. if (png_ptr == NULL || info_ptr == NULL ||
  174552. (png_ptr->mode & PNG_WROTE_tIME))
  174553. return;
  174554. png_memcpy(&(info_ptr->mod_time), mod_time, png_sizeof (png_time));
  174555. info_ptr->valid |= PNG_INFO_tIME;
  174556. }
  174557. #endif
  174558. #if defined(PNG_tRNS_SUPPORTED)
  174559. void PNGAPI
  174560. png_set_tRNS(png_structp png_ptr, png_infop info_ptr,
  174561. png_bytep trans, int num_trans, png_color_16p trans_values)
  174562. {
  174563. png_debug1(1, "in %s storage function\n", "tRNS");
  174564. if (png_ptr == NULL || info_ptr == NULL)
  174565. return;
  174566. if (trans != NULL)
  174567. {
  174568. #ifdef PNG_FREE_ME_SUPPORTED
  174569. png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0);
  174570. #endif
  174571. png_ptr->trans = info_ptr->trans = (png_bytep)png_malloc(png_ptr,
  174572. (png_uint_32)PNG_MAX_PALETTE_LENGTH);
  174573. if (num_trans <= PNG_MAX_PALETTE_LENGTH)
  174574. png_memcpy(info_ptr->trans, trans, (png_size_t)num_trans);
  174575. #ifdef PNG_FREE_ME_SUPPORTED
  174576. info_ptr->free_me |= PNG_FREE_TRNS;
  174577. #else
  174578. png_ptr->flags |= PNG_FLAG_FREE_TRNS;
  174579. #endif
  174580. }
  174581. if (trans_values != NULL)
  174582. {
  174583. png_memcpy(&(info_ptr->trans_values), trans_values,
  174584. png_sizeof(png_color_16));
  174585. if (num_trans == 0)
  174586. num_trans = 1;
  174587. }
  174588. info_ptr->num_trans = (png_uint_16)num_trans;
  174589. info_ptr->valid |= PNG_INFO_tRNS;
  174590. }
  174591. #endif
  174592. #if defined(PNG_sPLT_SUPPORTED)
  174593. void PNGAPI
  174594. png_set_sPLT(png_structp png_ptr,
  174595. png_infop info_ptr, png_sPLT_tp entries, int nentries)
  174596. {
  174597. png_sPLT_tp np;
  174598. int i;
  174599. if (png_ptr == NULL || info_ptr == NULL)
  174600. return;
  174601. np = (png_sPLT_tp)png_malloc_warn(png_ptr,
  174602. (info_ptr->splt_palettes_num + nentries) * png_sizeof(png_sPLT_t));
  174603. if (np == NULL)
  174604. {
  174605. png_warning(png_ptr, "No memory for sPLT palettes.");
  174606. return;
  174607. }
  174608. png_memcpy(np, info_ptr->splt_palettes,
  174609. info_ptr->splt_palettes_num * png_sizeof(png_sPLT_t));
  174610. png_free(png_ptr, info_ptr->splt_palettes);
  174611. info_ptr->splt_palettes=NULL;
  174612. for (i = 0; i < nentries; i++)
  174613. {
  174614. png_sPLT_tp to = np + info_ptr->splt_palettes_num + i;
  174615. png_sPLT_tp from = entries + i;
  174616. to->name = (png_charp)png_malloc_warn(png_ptr,
  174617. png_strlen(from->name) + 1);
  174618. if (to->name == NULL)
  174619. {
  174620. png_warning(png_ptr,
  174621. "Out of memory while processing sPLT chunk");
  174622. }
  174623. png_strncpy(to->name, from->name, png_strlen(from->name)+1);
  174624. to->entries = (png_sPLT_entryp)png_malloc_warn(png_ptr,
  174625. from->nentries * png_sizeof(png_sPLT_entry));
  174626. png_memcpy(to->entries, from->entries,
  174627. from->nentries * png_sizeof(png_sPLT_entry));
  174628. if (to->entries == NULL)
  174629. {
  174630. png_warning(png_ptr,
  174631. "Out of memory while processing sPLT chunk");
  174632. png_free(png_ptr,to->name);
  174633. to->name = NULL;
  174634. }
  174635. to->nentries = from->nentries;
  174636. to->depth = from->depth;
  174637. }
  174638. info_ptr->splt_palettes = np;
  174639. info_ptr->splt_palettes_num += nentries;
  174640. info_ptr->valid |= PNG_INFO_sPLT;
  174641. #ifdef PNG_FREE_ME_SUPPORTED
  174642. info_ptr->free_me |= PNG_FREE_SPLT;
  174643. #endif
  174644. }
  174645. #endif /* PNG_sPLT_SUPPORTED */
  174646. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  174647. void PNGAPI
  174648. png_set_unknown_chunks(png_structp png_ptr,
  174649. png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns)
  174650. {
  174651. png_unknown_chunkp np;
  174652. int i;
  174653. if (png_ptr == NULL || info_ptr == NULL || num_unknowns == 0)
  174654. return;
  174655. np = (png_unknown_chunkp)png_malloc_warn(png_ptr,
  174656. (info_ptr->unknown_chunks_num + num_unknowns) *
  174657. png_sizeof(png_unknown_chunk));
  174658. if (np == NULL)
  174659. {
  174660. png_warning(png_ptr,
  174661. "Out of memory while processing unknown chunk.");
  174662. return;
  174663. }
  174664. png_memcpy(np, info_ptr->unknown_chunks,
  174665. info_ptr->unknown_chunks_num * png_sizeof(png_unknown_chunk));
  174666. png_free(png_ptr, info_ptr->unknown_chunks);
  174667. info_ptr->unknown_chunks=NULL;
  174668. for (i = 0; i < num_unknowns; i++)
  174669. {
  174670. png_unknown_chunkp to = np + info_ptr->unknown_chunks_num + i;
  174671. png_unknown_chunkp from = unknowns + i;
  174672. png_strncpy((png_charp)to->name, (png_charp)from->name, 5);
  174673. to->data = (png_bytep)png_malloc_warn(png_ptr, from->size);
  174674. if (to->data == NULL)
  174675. {
  174676. png_warning(png_ptr,
  174677. "Out of memory while processing unknown chunk.");
  174678. }
  174679. else
  174680. {
  174681. png_memcpy(to->data, from->data, from->size);
  174682. to->size = from->size;
  174683. to->location = (png_byte)(png_ptr->mode & 0xff);
  174684. }
  174685. }
  174686. info_ptr->unknown_chunks = np;
  174687. info_ptr->unknown_chunks_num += num_unknowns;
  174688. #ifdef PNG_FREE_ME_SUPPORTED
  174689. info_ptr->free_me |= PNG_FREE_UNKN;
  174690. #endif
  174691. }
  174692. void PNGAPI
  174693. png_set_unknown_chunk_location(png_structp png_ptr, png_infop info_ptr,
  174694. int chunk, int location)
  174695. {
  174696. if(png_ptr != NULL && info_ptr != NULL && chunk >= 0 && chunk <
  174697. (int)info_ptr->unknown_chunks_num)
  174698. info_ptr->unknown_chunks[chunk].location = (png_byte)location;
  174699. }
  174700. #endif
  174701. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  174702. #if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  174703. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  174704. void PNGAPI
  174705. png_permit_empty_plte (png_structp png_ptr, int empty_plte_permitted)
  174706. {
  174707. png_debug(1, "in png_permit_empty_plte, DEPRECATED.\n");
  174708. if (png_ptr == NULL)
  174709. return;
  174710. png_ptr->mng_features_permitted = (png_byte)
  174711. ((png_ptr->mng_features_permitted & (~(PNG_FLAG_MNG_EMPTY_PLTE))) |
  174712. ((empty_plte_permitted & PNG_FLAG_MNG_EMPTY_PLTE)));
  174713. }
  174714. #endif
  174715. #endif
  174716. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  174717. png_uint_32 PNGAPI
  174718. png_permit_mng_features (png_structp png_ptr, png_uint_32 mng_features)
  174719. {
  174720. png_debug(1, "in png_permit_mng_features\n");
  174721. if (png_ptr == NULL)
  174722. return (png_uint_32)0;
  174723. png_ptr->mng_features_permitted =
  174724. (png_byte)(mng_features & PNG_ALL_MNG_FEATURES);
  174725. return (png_uint_32)png_ptr->mng_features_permitted;
  174726. }
  174727. #endif
  174728. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  174729. void PNGAPI
  174730. png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep
  174731. chunk_list, int num_chunks)
  174732. {
  174733. png_bytep new_list, p;
  174734. int i, old_num_chunks;
  174735. if (png_ptr == NULL)
  174736. return;
  174737. if (num_chunks == 0)
  174738. {
  174739. if(keep == PNG_HANDLE_CHUNK_ALWAYS || keep == PNG_HANDLE_CHUNK_IF_SAFE)
  174740. png_ptr->flags |= PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
  174741. else
  174742. png_ptr->flags &= ~PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
  174743. if(keep == PNG_HANDLE_CHUNK_ALWAYS)
  174744. png_ptr->flags |= PNG_FLAG_KEEP_UNSAFE_CHUNKS;
  174745. else
  174746. png_ptr->flags &= ~PNG_FLAG_KEEP_UNSAFE_CHUNKS;
  174747. return;
  174748. }
  174749. if (chunk_list == NULL)
  174750. return;
  174751. old_num_chunks=png_ptr->num_chunk_list;
  174752. new_list=(png_bytep)png_malloc(png_ptr,
  174753. (png_uint_32)(5*(num_chunks+old_num_chunks)));
  174754. if(png_ptr->chunk_list != NULL)
  174755. {
  174756. png_memcpy(new_list, png_ptr->chunk_list,
  174757. (png_size_t)(5*old_num_chunks));
  174758. png_free(png_ptr, png_ptr->chunk_list);
  174759. png_ptr->chunk_list=NULL;
  174760. }
  174761. png_memcpy(new_list+5*old_num_chunks, chunk_list,
  174762. (png_size_t)(5*num_chunks));
  174763. for (p=new_list+5*old_num_chunks+4, i=0; i<num_chunks; i++, p+=5)
  174764. *p=(png_byte)keep;
  174765. png_ptr->num_chunk_list=old_num_chunks+num_chunks;
  174766. png_ptr->chunk_list=new_list;
  174767. #ifdef PNG_FREE_ME_SUPPORTED
  174768. png_ptr->free_me |= PNG_FREE_LIST;
  174769. #endif
  174770. }
  174771. #endif
  174772. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  174773. void PNGAPI
  174774. png_set_read_user_chunk_fn(png_structp png_ptr, png_voidp user_chunk_ptr,
  174775. png_user_chunk_ptr read_user_chunk_fn)
  174776. {
  174777. png_debug(1, "in png_set_read_user_chunk_fn\n");
  174778. if (png_ptr == NULL)
  174779. return;
  174780. png_ptr->read_user_chunk_fn = read_user_chunk_fn;
  174781. png_ptr->user_chunk_ptr = user_chunk_ptr;
  174782. }
  174783. #endif
  174784. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  174785. void PNGAPI
  174786. png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers)
  174787. {
  174788. png_debug1(1, "in %s storage function\n", "rows");
  174789. if (png_ptr == NULL || info_ptr == NULL)
  174790. return;
  174791. if(info_ptr->row_pointers && (info_ptr->row_pointers != row_pointers))
  174792. png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
  174793. info_ptr->row_pointers = row_pointers;
  174794. if(row_pointers)
  174795. info_ptr->valid |= PNG_INFO_IDAT;
  174796. }
  174797. #endif
  174798. #ifdef PNG_WRITE_SUPPORTED
  174799. void PNGAPI
  174800. png_set_compression_buffer_size(png_structp png_ptr, png_uint_32 size)
  174801. {
  174802. if (png_ptr == NULL)
  174803. return;
  174804. if(png_ptr->zbuf)
  174805. png_free(png_ptr, png_ptr->zbuf);
  174806. png_ptr->zbuf_size = (png_size_t)size;
  174807. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, size);
  174808. png_ptr->zstream.next_out = png_ptr->zbuf;
  174809. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  174810. }
  174811. #endif
  174812. void PNGAPI
  174813. png_set_invalid(png_structp png_ptr, png_infop info_ptr, int mask)
  174814. {
  174815. if (png_ptr && info_ptr)
  174816. info_ptr->valid &= ~(mask);
  174817. }
  174818. #ifndef PNG_1_0_X
  174819. #ifdef PNG_ASSEMBLER_CODE_SUPPORTED
  174820. void PNGAPI
  174821. png_set_asm_flags (png_structp png_ptr, png_uint_32 asm_flags)
  174822. {
  174823. if (png_ptr != NULL)
  174824. png_ptr->asm_flags = 0;
  174825. }
  174826. void PNGAPI
  174827. png_set_mmx_thresholds (png_structp png_ptr,
  174828. png_byte mmx_bitdepth_threshold,
  174829. png_uint_32 mmx_rowbytes_threshold)
  174830. {
  174831. if (png_ptr == NULL)
  174832. return;
  174833. }
  174834. #endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
  174835. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  174836. void PNGAPI
  174837. png_set_user_limits (png_structp png_ptr, png_uint_32 user_width_max,
  174838. png_uint_32 user_height_max)
  174839. {
  174840. if(png_ptr == NULL) return;
  174841. png_ptr->user_width_max = user_width_max;
  174842. png_ptr->user_height_max = user_height_max;
  174843. }
  174844. #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
  174845. #endif /* ?PNG_1_0_X */
  174846. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  174847. /*** End of inlined file: pngset.c ***/
  174848. /*** Start of inlined file: pngtrans.c ***/
  174849. #define PNG_INTERNAL
  174850. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  174851. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  174852. void PNGAPI
  174853. png_set_bgr(png_structp png_ptr)
  174854. {
  174855. png_debug(1, "in png_set_bgr\n");
  174856. if(png_ptr == NULL) return;
  174857. png_ptr->transformations |= PNG_BGR;
  174858. }
  174859. #endif
  174860. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  174861. void PNGAPI
  174862. png_set_swap(png_structp png_ptr)
  174863. {
  174864. png_debug(1, "in png_set_swap\n");
  174865. if(png_ptr == NULL) return;
  174866. if (png_ptr->bit_depth == 16)
  174867. png_ptr->transformations |= PNG_SWAP_BYTES;
  174868. }
  174869. #endif
  174870. #if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
  174871. void PNGAPI
  174872. png_set_packing(png_structp png_ptr)
  174873. {
  174874. png_debug(1, "in png_set_packing\n");
  174875. if(png_ptr == NULL) return;
  174876. if (png_ptr->bit_depth < 8)
  174877. {
  174878. png_ptr->transformations |= PNG_PACK;
  174879. png_ptr->usr_bit_depth = 8;
  174880. }
  174881. }
  174882. #endif
  174883. #if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  174884. void PNGAPI
  174885. png_set_packswap(png_structp png_ptr)
  174886. {
  174887. png_debug(1, "in png_set_packswap\n");
  174888. if(png_ptr == NULL) return;
  174889. if (png_ptr->bit_depth < 8)
  174890. png_ptr->transformations |= PNG_PACKSWAP;
  174891. }
  174892. #endif
  174893. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  174894. void PNGAPI
  174895. png_set_shift(png_structp png_ptr, png_color_8p true_bits)
  174896. {
  174897. png_debug(1, "in png_set_shift\n");
  174898. if(png_ptr == NULL) return;
  174899. png_ptr->transformations |= PNG_SHIFT;
  174900. png_ptr->shift = *true_bits;
  174901. }
  174902. #endif
  174903. #if defined(PNG_READ_INTERLACING_SUPPORTED) || \
  174904. defined(PNG_WRITE_INTERLACING_SUPPORTED)
  174905. int PNGAPI
  174906. png_set_interlace_handling(png_structp png_ptr)
  174907. {
  174908. png_debug(1, "in png_set_interlace handling\n");
  174909. if (png_ptr && png_ptr->interlaced)
  174910. {
  174911. png_ptr->transformations |= PNG_INTERLACE;
  174912. return (7);
  174913. }
  174914. return (1);
  174915. }
  174916. #endif
  174917. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  174918. void PNGAPI
  174919. png_set_filler(png_structp png_ptr, png_uint_32 filler, int filler_loc)
  174920. {
  174921. png_debug(1, "in png_set_filler\n");
  174922. if(png_ptr == NULL) return;
  174923. png_ptr->transformations |= PNG_FILLER;
  174924. png_ptr->filler = (png_byte)filler;
  174925. if (filler_loc == PNG_FILLER_AFTER)
  174926. png_ptr->flags |= PNG_FLAG_FILLER_AFTER;
  174927. else
  174928. png_ptr->flags &= ~PNG_FLAG_FILLER_AFTER;
  174929. if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  174930. {
  174931. png_ptr->usr_channels = 4;
  174932. }
  174933. if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY && png_ptr->bit_depth >= 8)
  174934. {
  174935. png_ptr->usr_channels = 2;
  174936. }
  174937. }
  174938. #if !defined(PNG_1_0_X)
  174939. void PNGAPI
  174940. png_set_add_alpha(png_structp png_ptr, png_uint_32 filler, int filler_loc)
  174941. {
  174942. png_debug(1, "in png_set_add_alpha\n");
  174943. if(png_ptr == NULL) return;
  174944. png_set_filler(png_ptr, filler, filler_loc);
  174945. png_ptr->transformations |= PNG_ADD_ALPHA;
  174946. }
  174947. #endif
  174948. #endif
  174949. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \
  174950. defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  174951. void PNGAPI
  174952. png_set_swap_alpha(png_structp png_ptr)
  174953. {
  174954. png_debug(1, "in png_set_swap_alpha\n");
  174955. if(png_ptr == NULL) return;
  174956. png_ptr->transformations |= PNG_SWAP_ALPHA;
  174957. }
  174958. #endif
  174959. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \
  174960. defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  174961. void PNGAPI
  174962. png_set_invert_alpha(png_structp png_ptr)
  174963. {
  174964. png_debug(1, "in png_set_invert_alpha\n");
  174965. if(png_ptr == NULL) return;
  174966. png_ptr->transformations |= PNG_INVERT_ALPHA;
  174967. }
  174968. #endif
  174969. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  174970. void PNGAPI
  174971. png_set_invert_mono(png_structp png_ptr)
  174972. {
  174973. png_debug(1, "in png_set_invert_mono\n");
  174974. if(png_ptr == NULL) return;
  174975. png_ptr->transformations |= PNG_INVERT_MONO;
  174976. }
  174977. void /* PRIVATE */
  174978. png_do_invert(png_row_infop row_info, png_bytep row)
  174979. {
  174980. png_debug(1, "in png_do_invert\n");
  174981. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174982. if (row == NULL || row_info == NULL)
  174983. return;
  174984. #endif
  174985. if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  174986. {
  174987. png_bytep rp = row;
  174988. png_uint_32 i;
  174989. png_uint_32 istop = row_info->rowbytes;
  174990. for (i = 0; i < istop; i++)
  174991. {
  174992. *rp = (png_byte)(~(*rp));
  174993. rp++;
  174994. }
  174995. }
  174996. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  174997. row_info->bit_depth == 8)
  174998. {
  174999. png_bytep rp = row;
  175000. png_uint_32 i;
  175001. png_uint_32 istop = row_info->rowbytes;
  175002. for (i = 0; i < istop; i+=2)
  175003. {
  175004. *rp = (png_byte)(~(*rp));
  175005. rp+=2;
  175006. }
  175007. }
  175008. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  175009. row_info->bit_depth == 16)
  175010. {
  175011. png_bytep rp = row;
  175012. png_uint_32 i;
  175013. png_uint_32 istop = row_info->rowbytes;
  175014. for (i = 0; i < istop; i+=4)
  175015. {
  175016. *rp = (png_byte)(~(*rp));
  175017. *(rp+1) = (png_byte)(~(*(rp+1)));
  175018. rp+=4;
  175019. }
  175020. }
  175021. }
  175022. #endif
  175023. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  175024. void /* PRIVATE */
  175025. png_do_swap(png_row_infop row_info, png_bytep row)
  175026. {
  175027. png_debug(1, "in png_do_swap\n");
  175028. if (
  175029. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  175030. row != NULL && row_info != NULL &&
  175031. #endif
  175032. row_info->bit_depth == 16)
  175033. {
  175034. png_bytep rp = row;
  175035. png_uint_32 i;
  175036. png_uint_32 istop= row_info->width * row_info->channels;
  175037. for (i = 0; i < istop; i++, rp += 2)
  175038. {
  175039. png_byte t = *rp;
  175040. *rp = *(rp + 1);
  175041. *(rp + 1) = t;
  175042. }
  175043. }
  175044. }
  175045. #endif
  175046. #if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  175047. static PNG_CONST png_byte onebppswaptable[256] = {
  175048. 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0,
  175049. 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
  175050. 0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8,
  175051. 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8,
  175052. 0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4,
  175053. 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4,
  175054. 0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC,
  175055. 0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC,
  175056. 0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2,
  175057. 0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2,
  175058. 0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA,
  175059. 0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,
  175060. 0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6,
  175061. 0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6,
  175062. 0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE,
  175063. 0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE,
  175064. 0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1,
  175065. 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,
  175066. 0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9,
  175067. 0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9,
  175068. 0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5,
  175069. 0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5,
  175070. 0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED,
  175071. 0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD,
  175072. 0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3,
  175073. 0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3,
  175074. 0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB,
  175075. 0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB,
  175076. 0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7,
  175077. 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,
  175078. 0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF,
  175079. 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF
  175080. };
  175081. static PNG_CONST png_byte twobppswaptable[256] = {
  175082. 0x00, 0x40, 0x80, 0xC0, 0x10, 0x50, 0x90, 0xD0,
  175083. 0x20, 0x60, 0xA0, 0xE0, 0x30, 0x70, 0xB0, 0xF0,
  175084. 0x04, 0x44, 0x84, 0xC4, 0x14, 0x54, 0x94, 0xD4,
  175085. 0x24, 0x64, 0xA4, 0xE4, 0x34, 0x74, 0xB4, 0xF4,
  175086. 0x08, 0x48, 0x88, 0xC8, 0x18, 0x58, 0x98, 0xD8,
  175087. 0x28, 0x68, 0xA8, 0xE8, 0x38, 0x78, 0xB8, 0xF8,
  175088. 0x0C, 0x4C, 0x8C, 0xCC, 0x1C, 0x5C, 0x9C, 0xDC,
  175089. 0x2C, 0x6C, 0xAC, 0xEC, 0x3C, 0x7C, 0xBC, 0xFC,
  175090. 0x01, 0x41, 0x81, 0xC1, 0x11, 0x51, 0x91, 0xD1,
  175091. 0x21, 0x61, 0xA1, 0xE1, 0x31, 0x71, 0xB1, 0xF1,
  175092. 0x05, 0x45, 0x85, 0xC5, 0x15, 0x55, 0x95, 0xD5,
  175093. 0x25, 0x65, 0xA5, 0xE5, 0x35, 0x75, 0xB5, 0xF5,
  175094. 0x09, 0x49, 0x89, 0xC9, 0x19, 0x59, 0x99, 0xD9,
  175095. 0x29, 0x69, 0xA9, 0xE9, 0x39, 0x79, 0xB9, 0xF9,
  175096. 0x0D, 0x4D, 0x8D, 0xCD, 0x1D, 0x5D, 0x9D, 0xDD,
  175097. 0x2D, 0x6D, 0xAD, 0xED, 0x3D, 0x7D, 0xBD, 0xFD,
  175098. 0x02, 0x42, 0x82, 0xC2, 0x12, 0x52, 0x92, 0xD2,
  175099. 0x22, 0x62, 0xA2, 0xE2, 0x32, 0x72, 0xB2, 0xF2,
  175100. 0x06, 0x46, 0x86, 0xC6, 0x16, 0x56, 0x96, 0xD6,
  175101. 0x26, 0x66, 0xA6, 0xE6, 0x36, 0x76, 0xB6, 0xF6,
  175102. 0x0A, 0x4A, 0x8A, 0xCA, 0x1A, 0x5A, 0x9A, 0xDA,
  175103. 0x2A, 0x6A, 0xAA, 0xEA, 0x3A, 0x7A, 0xBA, 0xFA,
  175104. 0x0E, 0x4E, 0x8E, 0xCE, 0x1E, 0x5E, 0x9E, 0xDE,
  175105. 0x2E, 0x6E, 0xAE, 0xEE, 0x3E, 0x7E, 0xBE, 0xFE,
  175106. 0x03, 0x43, 0x83, 0xC3, 0x13, 0x53, 0x93, 0xD3,
  175107. 0x23, 0x63, 0xA3, 0xE3, 0x33, 0x73, 0xB3, 0xF3,
  175108. 0x07, 0x47, 0x87, 0xC7, 0x17, 0x57, 0x97, 0xD7,
  175109. 0x27, 0x67, 0xA7, 0xE7, 0x37, 0x77, 0xB7, 0xF7,
  175110. 0x0B, 0x4B, 0x8B, 0xCB, 0x1B, 0x5B, 0x9B, 0xDB,
  175111. 0x2B, 0x6B, 0xAB, 0xEB, 0x3B, 0x7B, 0xBB, 0xFB,
  175112. 0x0F, 0x4F, 0x8F, 0xCF, 0x1F, 0x5F, 0x9F, 0xDF,
  175113. 0x2F, 0x6F, 0xAF, 0xEF, 0x3F, 0x7F, 0xBF, 0xFF
  175114. };
  175115. static PNG_CONST png_byte fourbppswaptable[256] = {
  175116. 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70,
  175117. 0x80, 0x90, 0xA0, 0xB0, 0xC0, 0xD0, 0xE0, 0xF0,
  175118. 0x01, 0x11, 0x21, 0x31, 0x41, 0x51, 0x61, 0x71,
  175119. 0x81, 0x91, 0xA1, 0xB1, 0xC1, 0xD1, 0xE1, 0xF1,
  175120. 0x02, 0x12, 0x22, 0x32, 0x42, 0x52, 0x62, 0x72,
  175121. 0x82, 0x92, 0xA2, 0xB2, 0xC2, 0xD2, 0xE2, 0xF2,
  175122. 0x03, 0x13, 0x23, 0x33, 0x43, 0x53, 0x63, 0x73,
  175123. 0x83, 0x93, 0xA3, 0xB3, 0xC3, 0xD3, 0xE3, 0xF3,
  175124. 0x04, 0x14, 0x24, 0x34, 0x44, 0x54, 0x64, 0x74,
  175125. 0x84, 0x94, 0xA4, 0xB4, 0xC4, 0xD4, 0xE4, 0xF4,
  175126. 0x05, 0x15, 0x25, 0x35, 0x45, 0x55, 0x65, 0x75,
  175127. 0x85, 0x95, 0xA5, 0xB5, 0xC5, 0xD5, 0xE5, 0xF5,
  175128. 0x06, 0x16, 0x26, 0x36, 0x46, 0x56, 0x66, 0x76,
  175129. 0x86, 0x96, 0xA6, 0xB6, 0xC6, 0xD6, 0xE6, 0xF6,
  175130. 0x07, 0x17, 0x27, 0x37, 0x47, 0x57, 0x67, 0x77,
  175131. 0x87, 0x97, 0xA7, 0xB7, 0xC7, 0xD7, 0xE7, 0xF7,
  175132. 0x08, 0x18, 0x28, 0x38, 0x48, 0x58, 0x68, 0x78,
  175133. 0x88, 0x98, 0xA8, 0xB8, 0xC8, 0xD8, 0xE8, 0xF8,
  175134. 0x09, 0x19, 0x29, 0x39, 0x49, 0x59, 0x69, 0x79,
  175135. 0x89, 0x99, 0xA9, 0xB9, 0xC9, 0xD9, 0xE9, 0xF9,
  175136. 0x0A, 0x1A, 0x2A, 0x3A, 0x4A, 0x5A, 0x6A, 0x7A,
  175137. 0x8A, 0x9A, 0xAA, 0xBA, 0xCA, 0xDA, 0xEA, 0xFA,
  175138. 0x0B, 0x1B, 0x2B, 0x3B, 0x4B, 0x5B, 0x6B, 0x7B,
  175139. 0x8B, 0x9B, 0xAB, 0xBB, 0xCB, 0xDB, 0xEB, 0xFB,
  175140. 0x0C, 0x1C, 0x2C, 0x3C, 0x4C, 0x5C, 0x6C, 0x7C,
  175141. 0x8C, 0x9C, 0xAC, 0xBC, 0xCC, 0xDC, 0xEC, 0xFC,
  175142. 0x0D, 0x1D, 0x2D, 0x3D, 0x4D, 0x5D, 0x6D, 0x7D,
  175143. 0x8D, 0x9D, 0xAD, 0xBD, 0xCD, 0xDD, 0xED, 0xFD,
  175144. 0x0E, 0x1E, 0x2E, 0x3E, 0x4E, 0x5E, 0x6E, 0x7E,
  175145. 0x8E, 0x9E, 0xAE, 0xBE, 0xCE, 0xDE, 0xEE, 0xFE,
  175146. 0x0F, 0x1F, 0x2F, 0x3F, 0x4F, 0x5F, 0x6F, 0x7F,
  175147. 0x8F, 0x9F, 0xAF, 0xBF, 0xCF, 0xDF, 0xEF, 0xFF
  175148. };
  175149. void /* PRIVATE */
  175150. png_do_packswap(png_row_infop row_info, png_bytep row)
  175151. {
  175152. png_debug(1, "in png_do_packswap\n");
  175153. if (
  175154. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  175155. row != NULL && row_info != NULL &&
  175156. #endif
  175157. row_info->bit_depth < 8)
  175158. {
  175159. png_bytep rp, end, table;
  175160. end = row + row_info->rowbytes;
  175161. if (row_info->bit_depth == 1)
  175162. table = (png_bytep)onebppswaptable;
  175163. else if (row_info->bit_depth == 2)
  175164. table = (png_bytep)twobppswaptable;
  175165. else if (row_info->bit_depth == 4)
  175166. table = (png_bytep)fourbppswaptable;
  175167. else
  175168. return;
  175169. for (rp = row; rp < end; rp++)
  175170. *rp = table[*rp];
  175171. }
  175172. }
  175173. #endif /* PNG_READ_PACKSWAP_SUPPORTED or PNG_WRITE_PACKSWAP_SUPPORTED */
  175174. #if defined(PNG_WRITE_FILLER_SUPPORTED) || \
  175175. defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  175176. void /* PRIVATE */
  175177. png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags)
  175178. {
  175179. png_debug(1, "in png_do_strip_filler\n");
  175180. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  175181. if (row != NULL && row_info != NULL)
  175182. #endif
  175183. {
  175184. png_bytep sp=row;
  175185. png_bytep dp=row;
  175186. png_uint_32 row_width=row_info->width;
  175187. png_uint_32 i;
  175188. if ((row_info->color_type == PNG_COLOR_TYPE_RGB ||
  175189. (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA &&
  175190. (flags & PNG_FLAG_STRIP_ALPHA))) &&
  175191. row_info->channels == 4)
  175192. {
  175193. if (row_info->bit_depth == 8)
  175194. {
  175195. if (flags & PNG_FLAG_FILLER_AFTER)
  175196. {
  175197. dp+=3; sp+=4;
  175198. for (i = 1; i < row_width; i++)
  175199. {
  175200. *dp++ = *sp++;
  175201. *dp++ = *sp++;
  175202. *dp++ = *sp++;
  175203. sp++;
  175204. }
  175205. }
  175206. else
  175207. {
  175208. for (i = 0; i < row_width; i++)
  175209. {
  175210. sp++;
  175211. *dp++ = *sp++;
  175212. *dp++ = *sp++;
  175213. *dp++ = *sp++;
  175214. }
  175215. }
  175216. row_info->pixel_depth = 24;
  175217. row_info->rowbytes = row_width * 3;
  175218. }
  175219. else /* if (row_info->bit_depth == 16) */
  175220. {
  175221. if (flags & PNG_FLAG_FILLER_AFTER)
  175222. {
  175223. sp += 8; dp += 6;
  175224. for (i = 1; i < row_width; i++)
  175225. {
  175226. *dp++ = *sp++;
  175227. *dp++ = *sp++;
  175228. *dp++ = *sp++;
  175229. *dp++ = *sp++;
  175230. *dp++ = *sp++;
  175231. *dp++ = *sp++;
  175232. sp += 2;
  175233. }
  175234. }
  175235. else
  175236. {
  175237. for (i = 0; i < row_width; i++)
  175238. {
  175239. sp+=2;
  175240. *dp++ = *sp++;
  175241. *dp++ = *sp++;
  175242. *dp++ = *sp++;
  175243. *dp++ = *sp++;
  175244. *dp++ = *sp++;
  175245. *dp++ = *sp++;
  175246. }
  175247. }
  175248. row_info->pixel_depth = 48;
  175249. row_info->rowbytes = row_width * 6;
  175250. }
  175251. row_info->channels = 3;
  175252. }
  175253. else if ((row_info->color_type == PNG_COLOR_TYPE_GRAY ||
  175254. (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  175255. (flags & PNG_FLAG_STRIP_ALPHA))) &&
  175256. row_info->channels == 2)
  175257. {
  175258. if (row_info->bit_depth == 8)
  175259. {
  175260. if (flags & PNG_FLAG_FILLER_AFTER)
  175261. {
  175262. for (i = 0; i < row_width; i++)
  175263. {
  175264. *dp++ = *sp++;
  175265. sp++;
  175266. }
  175267. }
  175268. else
  175269. {
  175270. for (i = 0; i < row_width; i++)
  175271. {
  175272. sp++;
  175273. *dp++ = *sp++;
  175274. }
  175275. }
  175276. row_info->pixel_depth = 8;
  175277. row_info->rowbytes = row_width;
  175278. }
  175279. else /* if (row_info->bit_depth == 16) */
  175280. {
  175281. if (flags & PNG_FLAG_FILLER_AFTER)
  175282. {
  175283. sp += 4; dp += 2;
  175284. for (i = 1; i < row_width; i++)
  175285. {
  175286. *dp++ = *sp++;
  175287. *dp++ = *sp++;
  175288. sp += 2;
  175289. }
  175290. }
  175291. else
  175292. {
  175293. for (i = 0; i < row_width; i++)
  175294. {
  175295. sp += 2;
  175296. *dp++ = *sp++;
  175297. *dp++ = *sp++;
  175298. }
  175299. }
  175300. row_info->pixel_depth = 16;
  175301. row_info->rowbytes = row_width * 2;
  175302. }
  175303. row_info->channels = 1;
  175304. }
  175305. if (flags & PNG_FLAG_STRIP_ALPHA)
  175306. row_info->color_type &= ~PNG_COLOR_MASK_ALPHA;
  175307. }
  175308. }
  175309. #endif
  175310. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  175311. void /* PRIVATE */
  175312. png_do_bgr(png_row_infop row_info, png_bytep row)
  175313. {
  175314. png_debug(1, "in png_do_bgr\n");
  175315. if (
  175316. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  175317. row != NULL && row_info != NULL &&
  175318. #endif
  175319. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  175320. {
  175321. png_uint_32 row_width = row_info->width;
  175322. if (row_info->bit_depth == 8)
  175323. {
  175324. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  175325. {
  175326. png_bytep rp;
  175327. png_uint_32 i;
  175328. for (i = 0, rp = row; i < row_width; i++, rp += 3)
  175329. {
  175330. png_byte save = *rp;
  175331. *rp = *(rp + 2);
  175332. *(rp + 2) = save;
  175333. }
  175334. }
  175335. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  175336. {
  175337. png_bytep rp;
  175338. png_uint_32 i;
  175339. for (i = 0, rp = row; i < row_width; i++, rp += 4)
  175340. {
  175341. png_byte save = *rp;
  175342. *rp = *(rp + 2);
  175343. *(rp + 2) = save;
  175344. }
  175345. }
  175346. }
  175347. else if (row_info->bit_depth == 16)
  175348. {
  175349. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  175350. {
  175351. png_bytep rp;
  175352. png_uint_32 i;
  175353. for (i = 0, rp = row; i < row_width; i++, rp += 6)
  175354. {
  175355. png_byte save = *rp;
  175356. *rp = *(rp + 4);
  175357. *(rp + 4) = save;
  175358. save = *(rp + 1);
  175359. *(rp + 1) = *(rp + 5);
  175360. *(rp + 5) = save;
  175361. }
  175362. }
  175363. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  175364. {
  175365. png_bytep rp;
  175366. png_uint_32 i;
  175367. for (i = 0, rp = row; i < row_width; i++, rp += 8)
  175368. {
  175369. png_byte save = *rp;
  175370. *rp = *(rp + 4);
  175371. *(rp + 4) = save;
  175372. save = *(rp + 1);
  175373. *(rp + 1) = *(rp + 5);
  175374. *(rp + 5) = save;
  175375. }
  175376. }
  175377. }
  175378. }
  175379. }
  175380. #endif /* PNG_READ_BGR_SUPPORTED or PNG_WRITE_BGR_SUPPORTED */
  175381. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  175382. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  175383. defined(PNG_LEGACY_SUPPORTED)
  175384. void PNGAPI
  175385. png_set_user_transform_info(png_structp png_ptr, png_voidp
  175386. user_transform_ptr, int user_transform_depth, int user_transform_channels)
  175387. {
  175388. png_debug(1, "in png_set_user_transform_info\n");
  175389. if(png_ptr == NULL) return;
  175390. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  175391. png_ptr->user_transform_ptr = user_transform_ptr;
  175392. png_ptr->user_transform_depth = (png_byte)user_transform_depth;
  175393. png_ptr->user_transform_channels = (png_byte)user_transform_channels;
  175394. #else
  175395. if(user_transform_ptr || user_transform_depth || user_transform_channels)
  175396. png_warning(png_ptr,
  175397. "This version of libpng does not support user transform info");
  175398. #endif
  175399. }
  175400. #endif
  175401. png_voidp PNGAPI
  175402. png_get_user_transform_ptr(png_structp png_ptr)
  175403. {
  175404. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  175405. if (png_ptr == NULL) return (NULL);
  175406. return ((png_voidp)png_ptr->user_transform_ptr);
  175407. #else
  175408. return (NULL);
  175409. #endif
  175410. }
  175411. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  175412. /*** End of inlined file: pngtrans.c ***/
  175413. /*** Start of inlined file: pngwio.c ***/
  175414. #define PNG_INTERNAL
  175415. #ifdef PNG_WRITE_SUPPORTED
  175416. void /* PRIVATE */
  175417. png_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  175418. {
  175419. if (png_ptr->write_data_fn != NULL )
  175420. (*(png_ptr->write_data_fn))(png_ptr, data, length);
  175421. else
  175422. png_error(png_ptr, "Call to NULL write function");
  175423. }
  175424. #if !defined(PNG_NO_STDIO)
  175425. #ifndef USE_FAR_KEYWORD
  175426. void PNGAPI
  175427. png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  175428. {
  175429. png_uint_32 check;
  175430. if(png_ptr == NULL) return;
  175431. #if defined(_WIN32_WCE)
  175432. if ( !WriteFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  175433. check = 0;
  175434. #else
  175435. check = fwrite(data, 1, length, (png_FILE_p)(png_ptr->io_ptr));
  175436. #endif
  175437. if (check != length)
  175438. png_error(png_ptr, "Write Error");
  175439. }
  175440. #else
  175441. #define NEAR_BUF_SIZE 1024
  175442. #define MIN(a,b) (a <= b ? a : b)
  175443. void PNGAPI
  175444. png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  175445. {
  175446. png_uint_32 check;
  175447. png_byte *near_data; /* Needs to be "png_byte *" instead of "png_bytep" */
  175448. png_FILE_p io_ptr;
  175449. if(png_ptr == NULL) return;
  175450. near_data = (png_byte *)CVT_PTR_NOCHECK(data);
  175451. io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
  175452. if ((png_bytep)near_data == data)
  175453. {
  175454. #if defined(_WIN32_WCE)
  175455. if ( !WriteFile(io_ptr, near_data, length, &check, NULL) )
  175456. check = 0;
  175457. #else
  175458. check = fwrite(near_data, 1, length, io_ptr);
  175459. #endif
  175460. }
  175461. else
  175462. {
  175463. png_byte buf[NEAR_BUF_SIZE];
  175464. png_size_t written, remaining, err;
  175465. check = 0;
  175466. remaining = length;
  175467. do
  175468. {
  175469. written = MIN(NEAR_BUF_SIZE, remaining);
  175470. png_memcpy(buf, data, written); /* copy far buffer to near buffer */
  175471. #if defined(_WIN32_WCE)
  175472. if ( !WriteFile(io_ptr, buf, written, &err, NULL) )
  175473. err = 0;
  175474. #else
  175475. err = fwrite(buf, 1, written, io_ptr);
  175476. #endif
  175477. if (err != written)
  175478. break;
  175479. else
  175480. check += err;
  175481. data += written;
  175482. remaining -= written;
  175483. }
  175484. while (remaining != 0);
  175485. }
  175486. if (check != length)
  175487. png_error(png_ptr, "Write Error");
  175488. }
  175489. #endif
  175490. #endif
  175491. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  175492. void /* PRIVATE */
  175493. png_flush(png_structp png_ptr)
  175494. {
  175495. if (png_ptr->output_flush_fn != NULL)
  175496. (*(png_ptr->output_flush_fn))(png_ptr);
  175497. }
  175498. #if !defined(PNG_NO_STDIO)
  175499. void PNGAPI
  175500. png_default_flush(png_structp png_ptr)
  175501. {
  175502. #if !defined(_WIN32_WCE)
  175503. png_FILE_p io_ptr;
  175504. #endif
  175505. if(png_ptr == NULL) return;
  175506. #if !defined(_WIN32_WCE)
  175507. io_ptr = (png_FILE_p)CVT_PTR((png_ptr->io_ptr));
  175508. if (io_ptr != NULL)
  175509. fflush(io_ptr);
  175510. #endif
  175511. }
  175512. #endif
  175513. #endif
  175514. void PNGAPI
  175515. png_set_write_fn(png_structp png_ptr, png_voidp io_ptr,
  175516. png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn)
  175517. {
  175518. if(png_ptr == NULL) return;
  175519. png_ptr->io_ptr = io_ptr;
  175520. #if !defined(PNG_NO_STDIO)
  175521. if (write_data_fn != NULL)
  175522. png_ptr->write_data_fn = write_data_fn;
  175523. else
  175524. png_ptr->write_data_fn = png_default_write_data;
  175525. #else
  175526. png_ptr->write_data_fn = write_data_fn;
  175527. #endif
  175528. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  175529. #if !defined(PNG_NO_STDIO)
  175530. if (output_flush_fn != NULL)
  175531. png_ptr->output_flush_fn = output_flush_fn;
  175532. else
  175533. png_ptr->output_flush_fn = png_default_flush;
  175534. #else
  175535. png_ptr->output_flush_fn = output_flush_fn;
  175536. #endif
  175537. #endif /* PNG_WRITE_FLUSH_SUPPORTED */
  175538. if (png_ptr->read_data_fn != NULL)
  175539. {
  175540. png_ptr->read_data_fn = NULL;
  175541. png_warning(png_ptr,
  175542. "Attempted to set both read_data_fn and write_data_fn in");
  175543. png_warning(png_ptr,
  175544. "the same structure. Resetting read_data_fn to NULL.");
  175545. }
  175546. }
  175547. #if defined(USE_FAR_KEYWORD)
  175548. #if defined(_MSC_VER)
  175549. void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check)
  175550. {
  175551. void *near_ptr;
  175552. void FAR *far_ptr;
  175553. FP_OFF(near_ptr) = FP_OFF(ptr);
  175554. far_ptr = (void FAR *)near_ptr;
  175555. if(check != 0)
  175556. if(FP_SEG(ptr) != FP_SEG(far_ptr))
  175557. png_error(png_ptr,"segment lost in conversion");
  175558. return(near_ptr);
  175559. }
  175560. # else
  175561. void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check)
  175562. {
  175563. void *near_ptr;
  175564. void FAR *far_ptr;
  175565. near_ptr = (void FAR *)ptr;
  175566. far_ptr = (void FAR *)near_ptr;
  175567. if(check != 0)
  175568. if(far_ptr != ptr)
  175569. png_error(png_ptr,"segment lost in conversion");
  175570. return(near_ptr);
  175571. }
  175572. # endif
  175573. # endif
  175574. #endif /* PNG_WRITE_SUPPORTED */
  175575. /*** End of inlined file: pngwio.c ***/
  175576. /*** Start of inlined file: pngwrite.c ***/
  175577. #define PNG_INTERNAL
  175578. #ifdef PNG_WRITE_SUPPORTED
  175579. void PNGAPI
  175580. png_write_info_before_PLTE(png_structp png_ptr, png_infop info_ptr)
  175581. {
  175582. png_debug(1, "in png_write_info_before_PLTE\n");
  175583. if (png_ptr == NULL || info_ptr == NULL)
  175584. return;
  175585. if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
  175586. {
  175587. png_write_sig(png_ptr); /* write PNG signature */
  175588. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  175589. if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&(png_ptr->mng_features_permitted))
  175590. {
  175591. png_warning(png_ptr,"MNG features are not allowed in a PNG datastream");
  175592. png_ptr->mng_features_permitted=0;
  175593. }
  175594. #endif
  175595. png_write_IHDR(png_ptr, info_ptr->width, info_ptr->height,
  175596. info_ptr->bit_depth, info_ptr->color_type, info_ptr->compression_type,
  175597. info_ptr->filter_type,
  175598. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  175599. info_ptr->interlace_type);
  175600. #else
  175601. 0);
  175602. #endif
  175603. #if defined(PNG_WRITE_gAMA_SUPPORTED)
  175604. if (info_ptr->valid & PNG_INFO_gAMA)
  175605. {
  175606. # ifdef PNG_FLOATING_POINT_SUPPORTED
  175607. png_write_gAMA(png_ptr, info_ptr->gamma);
  175608. #else
  175609. #ifdef PNG_FIXED_POINT_SUPPORTED
  175610. png_write_gAMA_fixed(png_ptr, info_ptr->int_gamma);
  175611. # endif
  175612. #endif
  175613. }
  175614. #endif
  175615. #if defined(PNG_WRITE_sRGB_SUPPORTED)
  175616. if (info_ptr->valid & PNG_INFO_sRGB)
  175617. png_write_sRGB(png_ptr, (int)info_ptr->srgb_intent);
  175618. #endif
  175619. #if defined(PNG_WRITE_iCCP_SUPPORTED)
  175620. if (info_ptr->valid & PNG_INFO_iCCP)
  175621. png_write_iCCP(png_ptr, info_ptr->iccp_name, PNG_COMPRESSION_TYPE_BASE,
  175622. info_ptr->iccp_profile, (int)info_ptr->iccp_proflen);
  175623. #endif
  175624. #if defined(PNG_WRITE_sBIT_SUPPORTED)
  175625. if (info_ptr->valid & PNG_INFO_sBIT)
  175626. png_write_sBIT(png_ptr, &(info_ptr->sig_bit), info_ptr->color_type);
  175627. #endif
  175628. #if defined(PNG_WRITE_cHRM_SUPPORTED)
  175629. if (info_ptr->valid & PNG_INFO_cHRM)
  175630. {
  175631. #ifdef PNG_FLOATING_POINT_SUPPORTED
  175632. png_write_cHRM(png_ptr,
  175633. info_ptr->x_white, info_ptr->y_white,
  175634. info_ptr->x_red, info_ptr->y_red,
  175635. info_ptr->x_green, info_ptr->y_green,
  175636. info_ptr->x_blue, info_ptr->y_blue);
  175637. #else
  175638. # ifdef PNG_FIXED_POINT_SUPPORTED
  175639. png_write_cHRM_fixed(png_ptr,
  175640. info_ptr->int_x_white, info_ptr->int_y_white,
  175641. info_ptr->int_x_red, info_ptr->int_y_red,
  175642. info_ptr->int_x_green, info_ptr->int_y_green,
  175643. info_ptr->int_x_blue, info_ptr->int_y_blue);
  175644. # endif
  175645. #endif
  175646. }
  175647. #endif
  175648. #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
  175649. if (info_ptr->unknown_chunks_num)
  175650. {
  175651. png_unknown_chunk *up;
  175652. png_debug(5, "writing extra chunks\n");
  175653. for (up = info_ptr->unknown_chunks;
  175654. up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
  175655. up++)
  175656. {
  175657. int keep=png_handle_as_unknown(png_ptr, up->name);
  175658. if (keep != PNG_HANDLE_CHUNK_NEVER &&
  175659. up->location && !(up->location & PNG_HAVE_PLTE) &&
  175660. !(up->location & PNG_HAVE_IDAT) &&
  175661. ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
  175662. (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
  175663. {
  175664. png_write_chunk(png_ptr, up->name, up->data, up->size);
  175665. }
  175666. }
  175667. }
  175668. #endif
  175669. png_ptr->mode |= PNG_WROTE_INFO_BEFORE_PLTE;
  175670. }
  175671. }
  175672. void PNGAPI
  175673. png_write_info(png_structp png_ptr, png_infop info_ptr)
  175674. {
  175675. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  175676. int i;
  175677. #endif
  175678. png_debug(1, "in png_write_info\n");
  175679. if (png_ptr == NULL || info_ptr == NULL)
  175680. return;
  175681. png_write_info_before_PLTE(png_ptr, info_ptr);
  175682. if (info_ptr->valid & PNG_INFO_PLTE)
  175683. png_write_PLTE(png_ptr, info_ptr->palette,
  175684. (png_uint_32)info_ptr->num_palette);
  175685. else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  175686. png_error(png_ptr, "Valid palette required for paletted images");
  175687. #if defined(PNG_WRITE_tRNS_SUPPORTED)
  175688. if (info_ptr->valid & PNG_INFO_tRNS)
  175689. {
  175690. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  175691. if ((png_ptr->transformations & PNG_INVERT_ALPHA) &&
  175692. info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  175693. {
  175694. int j;
  175695. for (j=0; j<(int)info_ptr->num_trans; j++)
  175696. info_ptr->trans[j] = (png_byte)(255 - info_ptr->trans[j]);
  175697. }
  175698. #endif
  175699. png_write_tRNS(png_ptr, info_ptr->trans, &(info_ptr->trans_values),
  175700. info_ptr->num_trans, info_ptr->color_type);
  175701. }
  175702. #endif
  175703. #if defined(PNG_WRITE_bKGD_SUPPORTED)
  175704. if (info_ptr->valid & PNG_INFO_bKGD)
  175705. png_write_bKGD(png_ptr, &(info_ptr->background), info_ptr->color_type);
  175706. #endif
  175707. #if defined(PNG_WRITE_hIST_SUPPORTED)
  175708. if (info_ptr->valid & PNG_INFO_hIST)
  175709. png_write_hIST(png_ptr, info_ptr->hist, info_ptr->num_palette);
  175710. #endif
  175711. #if defined(PNG_WRITE_oFFs_SUPPORTED)
  175712. if (info_ptr->valid & PNG_INFO_oFFs)
  175713. png_write_oFFs(png_ptr, info_ptr->x_offset, info_ptr->y_offset,
  175714. info_ptr->offset_unit_type);
  175715. #endif
  175716. #if defined(PNG_WRITE_pCAL_SUPPORTED)
  175717. if (info_ptr->valid & PNG_INFO_pCAL)
  175718. png_write_pCAL(png_ptr, info_ptr->pcal_purpose, info_ptr->pcal_X0,
  175719. info_ptr->pcal_X1, info_ptr->pcal_type, info_ptr->pcal_nparams,
  175720. info_ptr->pcal_units, info_ptr->pcal_params);
  175721. #endif
  175722. #if defined(PNG_WRITE_sCAL_SUPPORTED)
  175723. if (info_ptr->valid & PNG_INFO_sCAL)
  175724. #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
  175725. png_write_sCAL(png_ptr, (int)info_ptr->scal_unit,
  175726. info_ptr->scal_pixel_width, info_ptr->scal_pixel_height);
  175727. #else
  175728. #ifdef PNG_FIXED_POINT_SUPPORTED
  175729. png_write_sCAL_s(png_ptr, (int)info_ptr->scal_unit,
  175730. info_ptr->scal_s_width, info_ptr->scal_s_height);
  175731. #else
  175732. png_warning(png_ptr,
  175733. "png_write_sCAL not supported; sCAL chunk not written.");
  175734. #endif
  175735. #endif
  175736. #endif
  175737. #if defined(PNG_WRITE_pHYs_SUPPORTED)
  175738. if (info_ptr->valid & PNG_INFO_pHYs)
  175739. png_write_pHYs(png_ptr, info_ptr->x_pixels_per_unit,
  175740. info_ptr->y_pixels_per_unit, info_ptr->phys_unit_type);
  175741. #endif
  175742. #if defined(PNG_WRITE_tIME_SUPPORTED)
  175743. if (info_ptr->valid & PNG_INFO_tIME)
  175744. {
  175745. png_write_tIME(png_ptr, &(info_ptr->mod_time));
  175746. png_ptr->mode |= PNG_WROTE_tIME;
  175747. }
  175748. #endif
  175749. #if defined(PNG_WRITE_sPLT_SUPPORTED)
  175750. if (info_ptr->valid & PNG_INFO_sPLT)
  175751. for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
  175752. png_write_sPLT(png_ptr, info_ptr->splt_palettes + i);
  175753. #endif
  175754. #if defined(PNG_WRITE_TEXT_SUPPORTED)
  175755. for (i = 0; i < info_ptr->num_text; i++)
  175756. {
  175757. png_debug2(2, "Writing header text chunk %d, type %d\n", i,
  175758. info_ptr->text[i].compression);
  175759. if (info_ptr->text[i].compression > 0)
  175760. {
  175761. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  175762. png_write_iTXt(png_ptr,
  175763. info_ptr->text[i].compression,
  175764. info_ptr->text[i].key,
  175765. info_ptr->text[i].lang,
  175766. info_ptr->text[i].lang_key,
  175767. info_ptr->text[i].text);
  175768. #else
  175769. png_warning(png_ptr, "Unable to write international text");
  175770. #endif
  175771. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175772. }
  175773. else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_zTXt)
  175774. {
  175775. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  175776. png_write_zTXt(png_ptr, info_ptr->text[i].key,
  175777. info_ptr->text[i].text, 0,
  175778. info_ptr->text[i].compression);
  175779. #else
  175780. png_warning(png_ptr, "Unable to write compressed text");
  175781. #endif
  175782. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;
  175783. }
  175784. else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
  175785. {
  175786. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  175787. png_write_tEXt(png_ptr, info_ptr->text[i].key,
  175788. info_ptr->text[i].text,
  175789. 0);
  175790. #else
  175791. png_warning(png_ptr, "Unable to write uncompressed text");
  175792. #endif
  175793. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175794. }
  175795. }
  175796. #endif
  175797. #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
  175798. if (info_ptr->unknown_chunks_num)
  175799. {
  175800. png_unknown_chunk *up;
  175801. png_debug(5, "writing extra chunks\n");
  175802. for (up = info_ptr->unknown_chunks;
  175803. up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
  175804. up++)
  175805. {
  175806. int keep=png_handle_as_unknown(png_ptr, up->name);
  175807. if (keep != PNG_HANDLE_CHUNK_NEVER &&
  175808. up->location && (up->location & PNG_HAVE_PLTE) &&
  175809. !(up->location & PNG_HAVE_IDAT) &&
  175810. ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
  175811. (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
  175812. {
  175813. png_write_chunk(png_ptr, up->name, up->data, up->size);
  175814. }
  175815. }
  175816. }
  175817. #endif
  175818. }
  175819. void PNGAPI
  175820. png_write_end(png_structp png_ptr, png_infop info_ptr)
  175821. {
  175822. png_debug(1, "in png_write_end\n");
  175823. if (png_ptr == NULL)
  175824. return;
  175825. if (!(png_ptr->mode & PNG_HAVE_IDAT))
  175826. png_error(png_ptr, "No IDATs written into file");
  175827. if (info_ptr != NULL)
  175828. {
  175829. #if defined(PNG_WRITE_TEXT_SUPPORTED)
  175830. int i; /* local index variable */
  175831. #endif
  175832. #if defined(PNG_WRITE_tIME_SUPPORTED)
  175833. if ((info_ptr->valid & PNG_INFO_tIME) &&
  175834. !(png_ptr->mode & PNG_WROTE_tIME))
  175835. png_write_tIME(png_ptr, &(info_ptr->mod_time));
  175836. #endif
  175837. #if defined(PNG_WRITE_TEXT_SUPPORTED)
  175838. for (i = 0; i < info_ptr->num_text; i++)
  175839. {
  175840. png_debug2(2, "Writing trailer text chunk %d, type %d\n", i,
  175841. info_ptr->text[i].compression);
  175842. if (info_ptr->text[i].compression > 0)
  175843. {
  175844. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  175845. png_write_iTXt(png_ptr,
  175846. info_ptr->text[i].compression,
  175847. info_ptr->text[i].key,
  175848. info_ptr->text[i].lang,
  175849. info_ptr->text[i].lang_key,
  175850. info_ptr->text[i].text);
  175851. #else
  175852. png_warning(png_ptr, "Unable to write international text");
  175853. #endif
  175854. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175855. }
  175856. else if (info_ptr->text[i].compression >= PNG_TEXT_COMPRESSION_zTXt)
  175857. {
  175858. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  175859. png_write_zTXt(png_ptr, info_ptr->text[i].key,
  175860. info_ptr->text[i].text, 0,
  175861. info_ptr->text[i].compression);
  175862. #else
  175863. png_warning(png_ptr, "Unable to write compressed text");
  175864. #endif
  175865. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;
  175866. }
  175867. else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
  175868. {
  175869. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  175870. png_write_tEXt(png_ptr, info_ptr->text[i].key,
  175871. info_ptr->text[i].text, 0);
  175872. #else
  175873. png_warning(png_ptr, "Unable to write uncompressed text");
  175874. #endif
  175875. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175876. }
  175877. }
  175878. #endif
  175879. #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
  175880. if (info_ptr->unknown_chunks_num)
  175881. {
  175882. png_unknown_chunk *up;
  175883. png_debug(5, "writing extra chunks\n");
  175884. for (up = info_ptr->unknown_chunks;
  175885. up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
  175886. up++)
  175887. {
  175888. int keep=png_handle_as_unknown(png_ptr, up->name);
  175889. if (keep != PNG_HANDLE_CHUNK_NEVER &&
  175890. up->location && (up->location & PNG_AFTER_IDAT) &&
  175891. ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
  175892. (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
  175893. {
  175894. png_write_chunk(png_ptr, up->name, up->data, up->size);
  175895. }
  175896. }
  175897. }
  175898. #endif
  175899. }
  175900. png_ptr->mode |= PNG_AFTER_IDAT;
  175901. png_write_IEND(png_ptr);
  175902. }
  175903. #if defined(PNG_WRITE_tIME_SUPPORTED)
  175904. #if !defined(_WIN32_WCE)
  175905. void PNGAPI
  175906. png_convert_from_struct_tm(png_timep ptime, struct tm FAR * ttime)
  175907. {
  175908. png_debug(1, "in png_convert_from_struct_tm\n");
  175909. ptime->year = (png_uint_16)(1900 + ttime->tm_year);
  175910. ptime->month = (png_byte)(ttime->tm_mon + 1);
  175911. ptime->day = (png_byte)ttime->tm_mday;
  175912. ptime->hour = (png_byte)ttime->tm_hour;
  175913. ptime->minute = (png_byte)ttime->tm_min;
  175914. ptime->second = (png_byte)ttime->tm_sec;
  175915. }
  175916. void PNGAPI
  175917. png_convert_from_time_t(png_timep ptime, time_t ttime)
  175918. {
  175919. struct tm *tbuf;
  175920. png_debug(1, "in png_convert_from_time_t\n");
  175921. tbuf = gmtime(&ttime);
  175922. png_convert_from_struct_tm(ptime, tbuf);
  175923. }
  175924. #endif
  175925. #endif
  175926. png_structp PNGAPI
  175927. png_create_write_struct(png_const_charp user_png_ver, png_voidp error_ptr,
  175928. png_error_ptr error_fn, png_error_ptr warn_fn)
  175929. {
  175930. #ifdef PNG_USER_MEM_SUPPORTED
  175931. return (png_create_write_struct_2(user_png_ver, error_ptr, error_fn,
  175932. warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL));
  175933. }
  175934. png_structp PNGAPI
  175935. png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
  175936. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  175937. png_malloc_ptr malloc_fn, png_free_ptr free_fn)
  175938. {
  175939. #endif /* PNG_USER_MEM_SUPPORTED */
  175940. png_structp png_ptr;
  175941. #ifdef PNG_SETJMP_SUPPORTED
  175942. #ifdef USE_FAR_KEYWORD
  175943. jmp_buf jmpbuf;
  175944. #endif
  175945. #endif
  175946. int i;
  175947. png_debug(1, "in png_create_write_struct\n");
  175948. #ifdef PNG_USER_MEM_SUPPORTED
  175949. png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
  175950. (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr);
  175951. #else
  175952. png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  175953. #endif /* PNG_USER_MEM_SUPPORTED */
  175954. if (png_ptr == NULL)
  175955. return (NULL);
  175956. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  175957. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  175958. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  175959. #endif
  175960. #ifdef PNG_SETJMP_SUPPORTED
  175961. #ifdef USE_FAR_KEYWORD
  175962. if (setjmp(jmpbuf))
  175963. #else
  175964. if (setjmp(png_ptr->jmpbuf))
  175965. #endif
  175966. {
  175967. png_free(png_ptr, png_ptr->zbuf);
  175968. png_ptr->zbuf=NULL;
  175969. png_destroy_struct(png_ptr);
  175970. return (NULL);
  175971. }
  175972. #ifdef USE_FAR_KEYWORD
  175973. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  175974. #endif
  175975. #endif
  175976. #ifdef PNG_USER_MEM_SUPPORTED
  175977. png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
  175978. #endif /* PNG_USER_MEM_SUPPORTED */
  175979. png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
  175980. i=0;
  175981. do
  175982. {
  175983. if(user_png_ver[i] != png_libpng_ver[i])
  175984. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  175985. } while (png_libpng_ver[i++]);
  175986. if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
  175987. {
  175988. if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
  175989. (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
  175990. (user_png_ver[0] == '0' && user_png_ver[2] < '9'))
  175991. {
  175992. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  175993. char msg[80];
  175994. if (user_png_ver)
  175995. {
  175996. png_snprintf(msg, 80,
  175997. "Application was compiled with png.h from libpng-%.20s",
  175998. user_png_ver);
  175999. png_warning(png_ptr, msg);
  176000. }
  176001. png_snprintf(msg, 80,
  176002. "Application is running with png.c from libpng-%.20s",
  176003. png_libpng_ver);
  176004. png_warning(png_ptr, msg);
  176005. #endif
  176006. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  176007. png_ptr->flags=0;
  176008. #endif
  176009. png_error(png_ptr,
  176010. "Incompatible libpng version in application and library");
  176011. }
  176012. }
  176013. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  176014. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  176015. (png_uint_32)png_ptr->zbuf_size);
  176016. png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL,
  176017. png_flush_ptr_NULL);
  176018. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  176019. png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
  176020. 1, png_doublep_NULL, png_doublep_NULL);
  176021. #endif
  176022. #ifdef PNG_SETJMP_SUPPORTED
  176023. #ifdef USE_FAR_KEYWORD
  176024. if (setjmp(jmpbuf))
  176025. PNG_ABORT();
  176026. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  176027. #else
  176028. if (setjmp(png_ptr->jmpbuf))
  176029. PNG_ABORT();
  176030. #endif
  176031. #endif
  176032. return (png_ptr);
  176033. }
  176034. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  176035. #undef png_write_init
  176036. void PNGAPI
  176037. png_write_init(png_structp png_ptr)
  176038. {
  176039. png_write_init_2(png_ptr, "1.0.6 or earlier", 0, 0);
  176040. }
  176041. void PNGAPI
  176042. png_write_init_2(png_structp png_ptr, png_const_charp user_png_ver,
  176043. png_size_t png_struct_size, png_size_t png_info_size)
  176044. {
  176045. if(png_ptr == NULL) return;
  176046. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  176047. if(png_sizeof(png_struct) > png_struct_size ||
  176048. png_sizeof(png_info) > png_info_size)
  176049. {
  176050. char msg[80];
  176051. png_ptr->warning_fn=NULL;
  176052. if (user_png_ver)
  176053. {
  176054. png_snprintf(msg, 80,
  176055. "Application was compiled with png.h from libpng-%.20s",
  176056. user_png_ver);
  176057. png_warning(png_ptr, msg);
  176058. }
  176059. png_snprintf(msg, 80,
  176060. "Application is running with png.c from libpng-%.20s",
  176061. png_libpng_ver);
  176062. png_warning(png_ptr, msg);
  176063. }
  176064. #endif
  176065. if(png_sizeof(png_struct) > png_struct_size)
  176066. {
  176067. png_ptr->error_fn=NULL;
  176068. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  176069. png_ptr->flags=0;
  176070. #endif
  176071. png_error(png_ptr,
  176072. "The png struct allocated by the application for writing is too small.");
  176073. }
  176074. if(png_sizeof(png_info) > png_info_size)
  176075. {
  176076. png_ptr->error_fn=NULL;
  176077. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  176078. png_ptr->flags=0;
  176079. #endif
  176080. png_error(png_ptr,
  176081. "The info struct allocated by the application for writing is too small.");
  176082. }
  176083. png_write_init_3(&png_ptr, user_png_ver, png_struct_size);
  176084. }
  176085. #endif /* PNG_1_0_X || PNG_1_2_X */
  176086. void PNGAPI
  176087. png_write_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
  176088. png_size_t png_struct_size)
  176089. {
  176090. png_structp png_ptr=*ptr_ptr;
  176091. #ifdef PNG_SETJMP_SUPPORTED
  176092. jmp_buf tmp_jmp; /* to save current jump buffer */
  176093. #endif
  176094. int i = 0;
  176095. if (png_ptr == NULL)
  176096. return;
  176097. do
  176098. {
  176099. if (user_png_ver[i] != png_libpng_ver[i])
  176100. {
  176101. #ifdef PNG_LEGACY_SUPPORTED
  176102. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  176103. #else
  176104. png_ptr->warning_fn=NULL;
  176105. png_warning(png_ptr,
  176106. "Application uses deprecated png_write_init() and should be recompiled.");
  176107. break;
  176108. #endif
  176109. }
  176110. } while (png_libpng_ver[i++]);
  176111. png_debug(1, "in png_write_init_3\n");
  176112. #ifdef PNG_SETJMP_SUPPORTED
  176113. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  176114. #endif
  176115. if (png_sizeof(png_struct) > png_struct_size)
  176116. {
  176117. png_destroy_struct(png_ptr);
  176118. png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  176119. *ptr_ptr = png_ptr;
  176120. }
  176121. png_memset(png_ptr, 0, png_sizeof (png_struct));
  176122. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  176123. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  176124. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  176125. #endif
  176126. #ifdef PNG_SETJMP_SUPPORTED
  176127. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  176128. #endif
  176129. png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL,
  176130. png_flush_ptr_NULL);
  176131. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  176132. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  176133. (png_uint_32)png_ptr->zbuf_size);
  176134. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  176135. png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
  176136. 1, png_doublep_NULL, png_doublep_NULL);
  176137. #endif
  176138. }
  176139. void PNGAPI
  176140. png_write_rows(png_structp png_ptr, png_bytepp row,
  176141. png_uint_32 num_rows)
  176142. {
  176143. png_uint_32 i; /* row counter */
  176144. png_bytepp rp; /* row pointer */
  176145. png_debug(1, "in png_write_rows\n");
  176146. if (png_ptr == NULL)
  176147. return;
  176148. for (i = 0, rp = row; i < num_rows; i++, rp++)
  176149. {
  176150. png_write_row(png_ptr, *rp);
  176151. }
  176152. }
  176153. void PNGAPI
  176154. png_write_image(png_structp png_ptr, png_bytepp image)
  176155. {
  176156. png_uint_32 i; /* row index */
  176157. int pass, num_pass; /* pass variables */
  176158. png_bytepp rp; /* points to current row */
  176159. if (png_ptr == NULL)
  176160. return;
  176161. png_debug(1, "in png_write_image\n");
  176162. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  176163. num_pass = png_set_interlace_handling(png_ptr);
  176164. #else
  176165. num_pass = 1;
  176166. #endif
  176167. for (pass = 0; pass < num_pass; pass++)
  176168. {
  176169. for (i = 0, rp = image; i < png_ptr->height; i++, rp++)
  176170. {
  176171. png_write_row(png_ptr, *rp);
  176172. }
  176173. }
  176174. }
  176175. void PNGAPI
  176176. png_write_row(png_structp png_ptr, png_bytep row)
  176177. {
  176178. if (png_ptr == NULL)
  176179. return;
  176180. png_debug2(1, "in png_write_row (row %ld, pass %d)\n",
  176181. png_ptr->row_number, png_ptr->pass);
  176182. if (png_ptr->row_number == 0 && png_ptr->pass == 0)
  176183. {
  176184. if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
  176185. png_error(png_ptr,
  176186. "png_write_info was never called before png_write_row.");
  176187. #if !defined(PNG_WRITE_INVERT_SUPPORTED) && defined(PNG_READ_INVERT_SUPPORTED)
  176188. if (png_ptr->transformations & PNG_INVERT_MONO)
  176189. png_warning(png_ptr, "PNG_WRITE_INVERT_SUPPORTED is not defined.");
  176190. #endif
  176191. #if !defined(PNG_WRITE_FILLER_SUPPORTED) && defined(PNG_READ_FILLER_SUPPORTED)
  176192. if (png_ptr->transformations & PNG_FILLER)
  176193. png_warning(png_ptr, "PNG_WRITE_FILLER_SUPPORTED is not defined.");
  176194. #endif
  176195. #if !defined(PNG_WRITE_PACKSWAP_SUPPORTED) && defined(PNG_READ_PACKSWAP_SUPPORTED)
  176196. if (png_ptr->transformations & PNG_PACKSWAP)
  176197. png_warning(png_ptr, "PNG_WRITE_PACKSWAP_SUPPORTED is not defined.");
  176198. #endif
  176199. #if !defined(PNG_WRITE_PACK_SUPPORTED) && defined(PNG_READ_PACK_SUPPORTED)
  176200. if (png_ptr->transformations & PNG_PACK)
  176201. png_warning(png_ptr, "PNG_WRITE_PACK_SUPPORTED is not defined.");
  176202. #endif
  176203. #if !defined(PNG_WRITE_SHIFT_SUPPORTED) && defined(PNG_READ_SHIFT_SUPPORTED)
  176204. if (png_ptr->transformations & PNG_SHIFT)
  176205. png_warning(png_ptr, "PNG_WRITE_SHIFT_SUPPORTED is not defined.");
  176206. #endif
  176207. #if !defined(PNG_WRITE_BGR_SUPPORTED) && defined(PNG_READ_BGR_SUPPORTED)
  176208. if (png_ptr->transformations & PNG_BGR)
  176209. png_warning(png_ptr, "PNG_WRITE_BGR_SUPPORTED is not defined.");
  176210. #endif
  176211. #if !defined(PNG_WRITE_SWAP_SUPPORTED) && defined(PNG_READ_SWAP_SUPPORTED)
  176212. if (png_ptr->transformations & PNG_SWAP_BYTES)
  176213. png_warning(png_ptr, "PNG_WRITE_SWAP_SUPPORTED is not defined.");
  176214. #endif
  176215. png_write_start_row(png_ptr);
  176216. }
  176217. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  176218. if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
  176219. {
  176220. switch (png_ptr->pass)
  176221. {
  176222. case 0:
  176223. if (png_ptr->row_number & 0x07)
  176224. {
  176225. png_write_finish_row(png_ptr);
  176226. return;
  176227. }
  176228. break;
  176229. case 1:
  176230. if ((png_ptr->row_number & 0x07) || png_ptr->width < 5)
  176231. {
  176232. png_write_finish_row(png_ptr);
  176233. return;
  176234. }
  176235. break;
  176236. case 2:
  176237. if ((png_ptr->row_number & 0x07) != 4)
  176238. {
  176239. png_write_finish_row(png_ptr);
  176240. return;
  176241. }
  176242. break;
  176243. case 3:
  176244. if ((png_ptr->row_number & 0x03) || png_ptr->width < 3)
  176245. {
  176246. png_write_finish_row(png_ptr);
  176247. return;
  176248. }
  176249. break;
  176250. case 4:
  176251. if ((png_ptr->row_number & 0x03) != 2)
  176252. {
  176253. png_write_finish_row(png_ptr);
  176254. return;
  176255. }
  176256. break;
  176257. case 5:
  176258. if ((png_ptr->row_number & 0x01) || png_ptr->width < 2)
  176259. {
  176260. png_write_finish_row(png_ptr);
  176261. return;
  176262. }
  176263. break;
  176264. case 6:
  176265. if (!(png_ptr->row_number & 0x01))
  176266. {
  176267. png_write_finish_row(png_ptr);
  176268. return;
  176269. }
  176270. break;
  176271. }
  176272. }
  176273. #endif
  176274. png_ptr->row_info.color_type = png_ptr->color_type;
  176275. png_ptr->row_info.width = png_ptr->usr_width;
  176276. png_ptr->row_info.channels = png_ptr->usr_channels;
  176277. png_ptr->row_info.bit_depth = png_ptr->usr_bit_depth;
  176278. png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth *
  176279. png_ptr->row_info.channels);
  176280. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  176281. png_ptr->row_info.width);
  176282. png_debug1(3, "row_info->color_type = %d\n", png_ptr->row_info.color_type);
  176283. png_debug1(3, "row_info->width = %lu\n", png_ptr->row_info.width);
  176284. png_debug1(3, "row_info->channels = %d\n", png_ptr->row_info.channels);
  176285. png_debug1(3, "row_info->bit_depth = %d\n", png_ptr->row_info.bit_depth);
  176286. png_debug1(3, "row_info->pixel_depth = %d\n", png_ptr->row_info.pixel_depth);
  176287. png_debug1(3, "row_info->rowbytes = %lu\n", png_ptr->row_info.rowbytes);
  176288. png_memcpy_check(png_ptr, png_ptr->row_buf + 1, row,
  176289. png_ptr->row_info.rowbytes);
  176290. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  176291. if (png_ptr->interlaced && png_ptr->pass < 6 &&
  176292. (png_ptr->transformations & PNG_INTERLACE))
  176293. {
  176294. png_do_write_interlace(&(png_ptr->row_info),
  176295. png_ptr->row_buf + 1, png_ptr->pass);
  176296. if (!(png_ptr->row_info.width))
  176297. {
  176298. png_write_finish_row(png_ptr);
  176299. return;
  176300. }
  176301. }
  176302. #endif
  176303. if (png_ptr->transformations)
  176304. png_do_write_transformations(png_ptr);
  176305. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  176306. if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  176307. (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
  176308. {
  176309. png_do_write_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176310. }
  176311. #endif
  176312. png_write_find_filter(png_ptr, &(png_ptr->row_info));
  176313. if (png_ptr->write_row_fn != NULL)
  176314. (*(png_ptr->write_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
  176315. }
  176316. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  176317. void PNGAPI
  176318. png_set_flush(png_structp png_ptr, int nrows)
  176319. {
  176320. png_debug(1, "in png_set_flush\n");
  176321. if (png_ptr == NULL)
  176322. return;
  176323. png_ptr->flush_dist = (nrows < 0 ? 0 : nrows);
  176324. }
  176325. void PNGAPI
  176326. png_write_flush(png_structp png_ptr)
  176327. {
  176328. int wrote_IDAT;
  176329. png_debug(1, "in png_write_flush\n");
  176330. if (png_ptr == NULL)
  176331. return;
  176332. if (png_ptr->row_number >= png_ptr->num_rows)
  176333. return;
  176334. do
  176335. {
  176336. int ret;
  176337. ret = deflate(&png_ptr->zstream, Z_SYNC_FLUSH);
  176338. wrote_IDAT = 0;
  176339. if (ret != Z_OK)
  176340. {
  176341. if (png_ptr->zstream.msg != NULL)
  176342. png_error(png_ptr, png_ptr->zstream.msg);
  176343. else
  176344. png_error(png_ptr, "zlib error");
  176345. }
  176346. if (!(png_ptr->zstream.avail_out))
  176347. {
  176348. png_write_IDAT(png_ptr, png_ptr->zbuf,
  176349. png_ptr->zbuf_size);
  176350. png_ptr->zstream.next_out = png_ptr->zbuf;
  176351. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  176352. wrote_IDAT = 1;
  176353. }
  176354. } while(wrote_IDAT == 1);
  176355. if (png_ptr->zbuf_size != png_ptr->zstream.avail_out)
  176356. {
  176357. png_write_IDAT(png_ptr, png_ptr->zbuf,
  176358. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  176359. png_ptr->zstream.next_out = png_ptr->zbuf;
  176360. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  176361. }
  176362. png_ptr->flush_rows = 0;
  176363. png_flush(png_ptr);
  176364. }
  176365. #endif /* PNG_WRITE_FLUSH_SUPPORTED */
  176366. void PNGAPI
  176367. png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)
  176368. {
  176369. png_structp png_ptr = NULL;
  176370. png_infop info_ptr = NULL;
  176371. #ifdef PNG_USER_MEM_SUPPORTED
  176372. png_free_ptr free_fn = NULL;
  176373. png_voidp mem_ptr = NULL;
  176374. #endif
  176375. png_debug(1, "in png_destroy_write_struct\n");
  176376. if (png_ptr_ptr != NULL)
  176377. {
  176378. png_ptr = *png_ptr_ptr;
  176379. #ifdef PNG_USER_MEM_SUPPORTED
  176380. free_fn = png_ptr->free_fn;
  176381. mem_ptr = png_ptr->mem_ptr;
  176382. #endif
  176383. }
  176384. if (info_ptr_ptr != NULL)
  176385. info_ptr = *info_ptr_ptr;
  176386. if (info_ptr != NULL)
  176387. {
  176388. png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
  176389. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  176390. if (png_ptr->num_chunk_list)
  176391. {
  176392. png_free(png_ptr, png_ptr->chunk_list);
  176393. png_ptr->chunk_list=NULL;
  176394. png_ptr->num_chunk_list=0;
  176395. }
  176396. #endif
  176397. #ifdef PNG_USER_MEM_SUPPORTED
  176398. png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn,
  176399. (png_voidp)mem_ptr);
  176400. #else
  176401. png_destroy_struct((png_voidp)info_ptr);
  176402. #endif
  176403. *info_ptr_ptr = NULL;
  176404. }
  176405. if (png_ptr != NULL)
  176406. {
  176407. png_write_destroy(png_ptr);
  176408. #ifdef PNG_USER_MEM_SUPPORTED
  176409. png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn,
  176410. (png_voidp)mem_ptr);
  176411. #else
  176412. png_destroy_struct((png_voidp)png_ptr);
  176413. #endif
  176414. *png_ptr_ptr = NULL;
  176415. }
  176416. }
  176417. void /* PRIVATE */
  176418. png_write_destroy(png_structp png_ptr)
  176419. {
  176420. #ifdef PNG_SETJMP_SUPPORTED
  176421. jmp_buf tmp_jmp; /* save jump buffer */
  176422. #endif
  176423. png_error_ptr error_fn;
  176424. png_error_ptr warning_fn;
  176425. png_voidp error_ptr;
  176426. #ifdef PNG_USER_MEM_SUPPORTED
  176427. png_free_ptr free_fn;
  176428. #endif
  176429. png_debug(1, "in png_write_destroy\n");
  176430. deflateEnd(&png_ptr->zstream);
  176431. png_free(png_ptr, png_ptr->zbuf);
  176432. png_free(png_ptr, png_ptr->row_buf);
  176433. png_free(png_ptr, png_ptr->prev_row);
  176434. png_free(png_ptr, png_ptr->sub_row);
  176435. png_free(png_ptr, png_ptr->up_row);
  176436. png_free(png_ptr, png_ptr->avg_row);
  176437. png_free(png_ptr, png_ptr->paeth_row);
  176438. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  176439. png_free(png_ptr, png_ptr->time_buffer);
  176440. #endif
  176441. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  176442. png_free(png_ptr, png_ptr->prev_filters);
  176443. png_free(png_ptr, png_ptr->filter_weights);
  176444. png_free(png_ptr, png_ptr->inv_filter_weights);
  176445. png_free(png_ptr, png_ptr->filter_costs);
  176446. png_free(png_ptr, png_ptr->inv_filter_costs);
  176447. #endif
  176448. #ifdef PNG_SETJMP_SUPPORTED
  176449. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  176450. #endif
  176451. error_fn = png_ptr->error_fn;
  176452. warning_fn = png_ptr->warning_fn;
  176453. error_ptr = png_ptr->error_ptr;
  176454. #ifdef PNG_USER_MEM_SUPPORTED
  176455. free_fn = png_ptr->free_fn;
  176456. #endif
  176457. png_memset(png_ptr, 0, png_sizeof (png_struct));
  176458. png_ptr->error_fn = error_fn;
  176459. png_ptr->warning_fn = warning_fn;
  176460. png_ptr->error_ptr = error_ptr;
  176461. #ifdef PNG_USER_MEM_SUPPORTED
  176462. png_ptr->free_fn = free_fn;
  176463. #endif
  176464. #ifdef PNG_SETJMP_SUPPORTED
  176465. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  176466. #endif
  176467. }
  176468. void PNGAPI
  176469. png_set_filter(png_structp png_ptr, int method, int filters)
  176470. {
  176471. png_debug(1, "in png_set_filter\n");
  176472. if (png_ptr == NULL)
  176473. return;
  176474. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  176475. if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  176476. (method == PNG_INTRAPIXEL_DIFFERENCING))
  176477. method = PNG_FILTER_TYPE_BASE;
  176478. #endif
  176479. if (method == PNG_FILTER_TYPE_BASE)
  176480. {
  176481. switch (filters & (PNG_ALL_FILTERS | 0x07))
  176482. {
  176483. #ifndef PNG_NO_WRITE_FILTER
  176484. case 5:
  176485. case 6:
  176486. case 7: png_warning(png_ptr, "Unknown row filter for method 0");
  176487. #endif /* PNG_NO_WRITE_FILTER */
  176488. case PNG_FILTER_VALUE_NONE:
  176489. png_ptr->do_filter=PNG_FILTER_NONE; break;
  176490. #ifndef PNG_NO_WRITE_FILTER
  176491. case PNG_FILTER_VALUE_SUB:
  176492. png_ptr->do_filter=PNG_FILTER_SUB; break;
  176493. case PNG_FILTER_VALUE_UP:
  176494. png_ptr->do_filter=PNG_FILTER_UP; break;
  176495. case PNG_FILTER_VALUE_AVG:
  176496. png_ptr->do_filter=PNG_FILTER_AVG; break;
  176497. case PNG_FILTER_VALUE_PAETH:
  176498. png_ptr->do_filter=PNG_FILTER_PAETH; break;
  176499. default: png_ptr->do_filter = (png_byte)filters; break;
  176500. #else
  176501. default: png_warning(png_ptr, "Unknown row filter for method 0");
  176502. #endif /* PNG_NO_WRITE_FILTER */
  176503. }
  176504. if (png_ptr->row_buf != NULL)
  176505. {
  176506. #ifndef PNG_NO_WRITE_FILTER
  176507. if ((png_ptr->do_filter & PNG_FILTER_SUB) && png_ptr->sub_row == NULL)
  176508. {
  176509. png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
  176510. (png_ptr->rowbytes + 1));
  176511. png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
  176512. }
  176513. if ((png_ptr->do_filter & PNG_FILTER_UP) && png_ptr->up_row == NULL)
  176514. {
  176515. if (png_ptr->prev_row == NULL)
  176516. {
  176517. png_warning(png_ptr, "Can't add Up filter after starting");
  176518. png_ptr->do_filter &= ~PNG_FILTER_UP;
  176519. }
  176520. else
  176521. {
  176522. png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
  176523. (png_ptr->rowbytes + 1));
  176524. png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
  176525. }
  176526. }
  176527. if ((png_ptr->do_filter & PNG_FILTER_AVG) && png_ptr->avg_row == NULL)
  176528. {
  176529. if (png_ptr->prev_row == NULL)
  176530. {
  176531. png_warning(png_ptr, "Can't add Average filter after starting");
  176532. png_ptr->do_filter &= ~PNG_FILTER_AVG;
  176533. }
  176534. else
  176535. {
  176536. png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
  176537. (png_ptr->rowbytes + 1));
  176538. png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
  176539. }
  176540. }
  176541. if ((png_ptr->do_filter & PNG_FILTER_PAETH) &&
  176542. png_ptr->paeth_row == NULL)
  176543. {
  176544. if (png_ptr->prev_row == NULL)
  176545. {
  176546. png_warning(png_ptr, "Can't add Paeth filter after starting");
  176547. png_ptr->do_filter &= (png_byte)(~PNG_FILTER_PAETH);
  176548. }
  176549. else
  176550. {
  176551. png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
  176552. (png_ptr->rowbytes + 1));
  176553. png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
  176554. }
  176555. }
  176556. if (png_ptr->do_filter == PNG_NO_FILTERS)
  176557. #endif /* PNG_NO_WRITE_FILTER */
  176558. png_ptr->do_filter = PNG_FILTER_NONE;
  176559. }
  176560. }
  176561. else
  176562. png_error(png_ptr, "Unknown custom filter method");
  176563. }
  176564. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* GRR 970116 */
  176565. void PNGAPI
  176566. png_set_filter_heuristics(png_structp png_ptr, int heuristic_method,
  176567. int num_weights, png_doublep filter_weights,
  176568. png_doublep filter_costs)
  176569. {
  176570. int i;
  176571. png_debug(1, "in png_set_filter_heuristics\n");
  176572. if (png_ptr == NULL)
  176573. return;
  176574. if (heuristic_method >= PNG_FILTER_HEURISTIC_LAST)
  176575. {
  176576. png_warning(png_ptr, "Unknown filter heuristic method");
  176577. return;
  176578. }
  176579. if (heuristic_method == PNG_FILTER_HEURISTIC_DEFAULT)
  176580. {
  176581. heuristic_method = PNG_FILTER_HEURISTIC_UNWEIGHTED;
  176582. }
  176583. if (num_weights < 0 || filter_weights == NULL ||
  176584. heuristic_method == PNG_FILTER_HEURISTIC_UNWEIGHTED)
  176585. {
  176586. num_weights = 0;
  176587. }
  176588. png_ptr->num_prev_filters = (png_byte)num_weights;
  176589. png_ptr->heuristic_method = (png_byte)heuristic_method;
  176590. if (num_weights > 0)
  176591. {
  176592. if (png_ptr->prev_filters == NULL)
  176593. {
  176594. png_ptr->prev_filters = (png_bytep)png_malloc(png_ptr,
  176595. (png_uint_32)(png_sizeof(png_byte) * num_weights));
  176596. for (i = 0; i < num_weights; i++)
  176597. {
  176598. png_ptr->prev_filters[i] = 255;
  176599. }
  176600. }
  176601. if (png_ptr->filter_weights == NULL)
  176602. {
  176603. png_ptr->filter_weights = (png_uint_16p)png_malloc(png_ptr,
  176604. (png_uint_32)(png_sizeof(png_uint_16) * num_weights));
  176605. png_ptr->inv_filter_weights = (png_uint_16p)png_malloc(png_ptr,
  176606. (png_uint_32)(png_sizeof(png_uint_16) * num_weights));
  176607. for (i = 0; i < num_weights; i++)
  176608. {
  176609. png_ptr->inv_filter_weights[i] =
  176610. png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR;
  176611. }
  176612. }
  176613. for (i = 0; i < num_weights; i++)
  176614. {
  176615. if (filter_weights[i] < 0.0)
  176616. {
  176617. png_ptr->inv_filter_weights[i] =
  176618. png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR;
  176619. }
  176620. else
  176621. {
  176622. png_ptr->inv_filter_weights[i] =
  176623. (png_uint_16)((double)PNG_WEIGHT_FACTOR*filter_weights[i]+0.5);
  176624. png_ptr->filter_weights[i] =
  176625. (png_uint_16)((double)PNG_WEIGHT_FACTOR/filter_weights[i]+0.5);
  176626. }
  176627. }
  176628. }
  176629. if (png_ptr->filter_costs == NULL)
  176630. {
  176631. png_ptr->filter_costs = (png_uint_16p)png_malloc(png_ptr,
  176632. (png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
  176633. png_ptr->inv_filter_costs = (png_uint_16p)png_malloc(png_ptr,
  176634. (png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
  176635. for (i = 0; i < PNG_FILTER_VALUE_LAST; i++)
  176636. {
  176637. png_ptr->inv_filter_costs[i] =
  176638. png_ptr->filter_costs[i] = PNG_COST_FACTOR;
  176639. }
  176640. }
  176641. for (i = 0; i < PNG_FILTER_VALUE_LAST; i++)
  176642. {
  176643. if (filter_costs == NULL || filter_costs[i] < 0.0)
  176644. {
  176645. png_ptr->inv_filter_costs[i] =
  176646. png_ptr->filter_costs[i] = PNG_COST_FACTOR;
  176647. }
  176648. else if (filter_costs[i] >= 1.0)
  176649. {
  176650. png_ptr->inv_filter_costs[i] =
  176651. (png_uint_16)((double)PNG_COST_FACTOR / filter_costs[i] + 0.5);
  176652. png_ptr->filter_costs[i] =
  176653. (png_uint_16)((double)PNG_COST_FACTOR * filter_costs[i] + 0.5);
  176654. }
  176655. }
  176656. }
  176657. #endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
  176658. void PNGAPI
  176659. png_set_compression_level(png_structp png_ptr, int level)
  176660. {
  176661. png_debug(1, "in png_set_compression_level\n");
  176662. if (png_ptr == NULL)
  176663. return;
  176664. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_LEVEL;
  176665. png_ptr->zlib_level = level;
  176666. }
  176667. void PNGAPI
  176668. png_set_compression_mem_level(png_structp png_ptr, int mem_level)
  176669. {
  176670. png_debug(1, "in png_set_compression_mem_level\n");
  176671. if (png_ptr == NULL)
  176672. return;
  176673. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL;
  176674. png_ptr->zlib_mem_level = mem_level;
  176675. }
  176676. void PNGAPI
  176677. png_set_compression_strategy(png_structp png_ptr, int strategy)
  176678. {
  176679. png_debug(1, "in png_set_compression_strategy\n");
  176680. if (png_ptr == NULL)
  176681. return;
  176682. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_STRATEGY;
  176683. png_ptr->zlib_strategy = strategy;
  176684. }
  176685. void PNGAPI
  176686. png_set_compression_window_bits(png_structp png_ptr, int window_bits)
  176687. {
  176688. if (png_ptr == NULL)
  176689. return;
  176690. if (window_bits > 15)
  176691. png_warning(png_ptr, "Only compression windows <= 32k supported by PNG");
  176692. else if (window_bits < 8)
  176693. png_warning(png_ptr, "Only compression windows >= 256 supported by PNG");
  176694. #ifndef WBITS_8_OK
  176695. if (window_bits == 8)
  176696. {
  176697. png_warning(png_ptr, "Compression window is being reset to 512");
  176698. window_bits=9;
  176699. }
  176700. #endif
  176701. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS;
  176702. png_ptr->zlib_window_bits = window_bits;
  176703. }
  176704. void PNGAPI
  176705. png_set_compression_method(png_structp png_ptr, int method)
  176706. {
  176707. png_debug(1, "in png_set_compression_method\n");
  176708. if (png_ptr == NULL)
  176709. return;
  176710. if (method != 8)
  176711. png_warning(png_ptr, "Only compression method 8 is supported by PNG");
  176712. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_METHOD;
  176713. png_ptr->zlib_method = method;
  176714. }
  176715. void PNGAPI
  176716. png_set_write_status_fn(png_structp png_ptr, png_write_status_ptr write_row_fn)
  176717. {
  176718. if (png_ptr == NULL)
  176719. return;
  176720. png_ptr->write_row_fn = write_row_fn;
  176721. }
  176722. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  176723. void PNGAPI
  176724. png_set_write_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
  176725. write_user_transform_fn)
  176726. {
  176727. png_debug(1, "in png_set_write_user_transform_fn\n");
  176728. if (png_ptr == NULL)
  176729. return;
  176730. png_ptr->transformations |= PNG_USER_TRANSFORM;
  176731. png_ptr->write_user_transform_fn = write_user_transform_fn;
  176732. }
  176733. #endif
  176734. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  176735. void PNGAPI
  176736. png_write_png(png_structp png_ptr, png_infop info_ptr,
  176737. int transforms, voidp params)
  176738. {
  176739. if (png_ptr == NULL || info_ptr == NULL)
  176740. return;
  176741. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  176742. if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
  176743. png_set_invert_alpha(png_ptr);
  176744. #endif
  176745. png_write_info(png_ptr, info_ptr);
  176746. #if defined(PNG_WRITE_INVERT_SUPPORTED)
  176747. if (transforms & PNG_TRANSFORM_INVERT_MONO)
  176748. png_set_invert_mono(png_ptr);
  176749. #endif
  176750. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  176751. if ((transforms & PNG_TRANSFORM_SHIFT)
  176752. && (info_ptr->valid & PNG_INFO_sBIT))
  176753. png_set_shift(png_ptr, &info_ptr->sig_bit);
  176754. #endif
  176755. #if defined(PNG_WRITE_PACK_SUPPORTED)
  176756. if (transforms & PNG_TRANSFORM_PACKING)
  176757. png_set_packing(png_ptr);
  176758. #endif
  176759. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  176760. if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
  176761. png_set_swap_alpha(png_ptr);
  176762. #endif
  176763. #if defined(PNG_WRITE_FILLER_SUPPORTED)
  176764. if (transforms & PNG_TRANSFORM_STRIP_FILLER)
  176765. png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
  176766. #endif
  176767. #if defined(PNG_WRITE_BGR_SUPPORTED)
  176768. if (transforms & PNG_TRANSFORM_BGR)
  176769. png_set_bgr(png_ptr);
  176770. #endif
  176771. #if defined(PNG_WRITE_SWAP_SUPPORTED)
  176772. if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
  176773. png_set_swap(png_ptr);
  176774. #endif
  176775. #if defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  176776. if (transforms & PNG_TRANSFORM_PACKSWAP)
  176777. png_set_packswap(png_ptr);
  176778. #endif
  176779. if (info_ptr->valid & PNG_INFO_IDAT)
  176780. png_write_image(png_ptr, info_ptr->row_pointers);
  176781. png_write_end(png_ptr, info_ptr);
  176782. transforms = transforms; /* quiet compiler warnings */
  176783. params = params;
  176784. }
  176785. #endif
  176786. #endif /* PNG_WRITE_SUPPORTED */
  176787. /*** End of inlined file: pngwrite.c ***/
  176788. /*** Start of inlined file: pngwtran.c ***/
  176789. #define PNG_INTERNAL
  176790. #ifdef PNG_WRITE_SUPPORTED
  176791. void /* PRIVATE */
  176792. png_do_write_transformations(png_structp png_ptr)
  176793. {
  176794. png_debug(1, "in png_do_write_transformations\n");
  176795. if (png_ptr == NULL)
  176796. return;
  176797. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  176798. if (png_ptr->transformations & PNG_USER_TRANSFORM)
  176799. if(png_ptr->write_user_transform_fn != NULL)
  176800. (*(png_ptr->write_user_transform_fn)) /* user write transform function */
  176801. (png_ptr, /* png_ptr */
  176802. &(png_ptr->row_info), /* row_info: */
  176803. png_ptr->row_buf + 1); /* start of pixel data for row */
  176804. #endif
  176805. #if defined(PNG_WRITE_FILLER_SUPPORTED)
  176806. if (png_ptr->transformations & PNG_FILLER)
  176807. png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  176808. png_ptr->flags);
  176809. #endif
  176810. #if defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  176811. if (png_ptr->transformations & PNG_PACKSWAP)
  176812. png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176813. #endif
  176814. #if defined(PNG_WRITE_PACK_SUPPORTED)
  176815. if (png_ptr->transformations & PNG_PACK)
  176816. png_do_pack(&(png_ptr->row_info), png_ptr->row_buf + 1,
  176817. (png_uint_32)png_ptr->bit_depth);
  176818. #endif
  176819. #if defined(PNG_WRITE_SWAP_SUPPORTED)
  176820. if (png_ptr->transformations & PNG_SWAP_BYTES)
  176821. png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176822. #endif
  176823. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  176824. if (png_ptr->transformations & PNG_SHIFT)
  176825. png_do_shift(&(png_ptr->row_info), png_ptr->row_buf + 1,
  176826. &(png_ptr->shift));
  176827. #endif
  176828. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  176829. if (png_ptr->transformations & PNG_SWAP_ALPHA)
  176830. png_do_write_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176831. #endif
  176832. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  176833. if (png_ptr->transformations & PNG_INVERT_ALPHA)
  176834. png_do_write_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176835. #endif
  176836. #if defined(PNG_WRITE_BGR_SUPPORTED)
  176837. if (png_ptr->transformations & PNG_BGR)
  176838. png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176839. #endif
  176840. #if defined(PNG_WRITE_INVERT_SUPPORTED)
  176841. if (png_ptr->transformations & PNG_INVERT_MONO)
  176842. png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176843. #endif
  176844. }
  176845. #if defined(PNG_WRITE_PACK_SUPPORTED)
  176846. void /* PRIVATE */
  176847. png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth)
  176848. {
  176849. png_debug(1, "in png_do_pack\n");
  176850. if (row_info->bit_depth == 8 &&
  176851. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176852. row != NULL && row_info != NULL &&
  176853. #endif
  176854. row_info->channels == 1)
  176855. {
  176856. switch ((int)bit_depth)
  176857. {
  176858. case 1:
  176859. {
  176860. png_bytep sp, dp;
  176861. int mask, v;
  176862. png_uint_32 i;
  176863. png_uint_32 row_width = row_info->width;
  176864. sp = row;
  176865. dp = row;
  176866. mask = 0x80;
  176867. v = 0;
  176868. for (i = 0; i < row_width; i++)
  176869. {
  176870. if (*sp != 0)
  176871. v |= mask;
  176872. sp++;
  176873. if (mask > 1)
  176874. mask >>= 1;
  176875. else
  176876. {
  176877. mask = 0x80;
  176878. *dp = (png_byte)v;
  176879. dp++;
  176880. v = 0;
  176881. }
  176882. }
  176883. if (mask != 0x80)
  176884. *dp = (png_byte)v;
  176885. break;
  176886. }
  176887. case 2:
  176888. {
  176889. png_bytep sp, dp;
  176890. int shift, v;
  176891. png_uint_32 i;
  176892. png_uint_32 row_width = row_info->width;
  176893. sp = row;
  176894. dp = row;
  176895. shift = 6;
  176896. v = 0;
  176897. for (i = 0; i < row_width; i++)
  176898. {
  176899. png_byte value;
  176900. value = (png_byte)(*sp & 0x03);
  176901. v |= (value << shift);
  176902. if (shift == 0)
  176903. {
  176904. shift = 6;
  176905. *dp = (png_byte)v;
  176906. dp++;
  176907. v = 0;
  176908. }
  176909. else
  176910. shift -= 2;
  176911. sp++;
  176912. }
  176913. if (shift != 6)
  176914. *dp = (png_byte)v;
  176915. break;
  176916. }
  176917. case 4:
  176918. {
  176919. png_bytep sp, dp;
  176920. int shift, v;
  176921. png_uint_32 i;
  176922. png_uint_32 row_width = row_info->width;
  176923. sp = row;
  176924. dp = row;
  176925. shift = 4;
  176926. v = 0;
  176927. for (i = 0; i < row_width; i++)
  176928. {
  176929. png_byte value;
  176930. value = (png_byte)(*sp & 0x0f);
  176931. v |= (value << shift);
  176932. if (shift == 0)
  176933. {
  176934. shift = 4;
  176935. *dp = (png_byte)v;
  176936. dp++;
  176937. v = 0;
  176938. }
  176939. else
  176940. shift -= 4;
  176941. sp++;
  176942. }
  176943. if (shift != 4)
  176944. *dp = (png_byte)v;
  176945. break;
  176946. }
  176947. }
  176948. row_info->bit_depth = (png_byte)bit_depth;
  176949. row_info->pixel_depth = (png_byte)(bit_depth * row_info->channels);
  176950. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
  176951. row_info->width);
  176952. }
  176953. }
  176954. #endif
  176955. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  176956. void /* PRIVATE */
  176957. png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth)
  176958. {
  176959. png_debug(1, "in png_do_shift\n");
  176960. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176961. if (row != NULL && row_info != NULL &&
  176962. #else
  176963. if (
  176964. #endif
  176965. row_info->color_type != PNG_COLOR_TYPE_PALETTE)
  176966. {
  176967. int shift_start[4], shift_dec[4];
  176968. int channels = 0;
  176969. if (row_info->color_type & PNG_COLOR_MASK_COLOR)
  176970. {
  176971. shift_start[channels] = row_info->bit_depth - bit_depth->red;
  176972. shift_dec[channels] = bit_depth->red;
  176973. channels++;
  176974. shift_start[channels] = row_info->bit_depth - bit_depth->green;
  176975. shift_dec[channels] = bit_depth->green;
  176976. channels++;
  176977. shift_start[channels] = row_info->bit_depth - bit_depth->blue;
  176978. shift_dec[channels] = bit_depth->blue;
  176979. channels++;
  176980. }
  176981. else
  176982. {
  176983. shift_start[channels] = row_info->bit_depth - bit_depth->gray;
  176984. shift_dec[channels] = bit_depth->gray;
  176985. channels++;
  176986. }
  176987. if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
  176988. {
  176989. shift_start[channels] = row_info->bit_depth - bit_depth->alpha;
  176990. shift_dec[channels] = bit_depth->alpha;
  176991. channels++;
  176992. }
  176993. if (row_info->bit_depth < 8)
  176994. {
  176995. png_bytep bp = row;
  176996. png_uint_32 i;
  176997. png_byte mask;
  176998. png_uint_32 row_bytes = row_info->rowbytes;
  176999. if (bit_depth->gray == 1 && row_info->bit_depth == 2)
  177000. mask = 0x55;
  177001. else if (row_info->bit_depth == 4 && bit_depth->gray == 3)
  177002. mask = 0x11;
  177003. else
  177004. mask = 0xff;
  177005. for (i = 0; i < row_bytes; i++, bp++)
  177006. {
  177007. png_uint_16 v;
  177008. int j;
  177009. v = *bp;
  177010. *bp = 0;
  177011. for (j = shift_start[0]; j > -shift_dec[0]; j -= shift_dec[0])
  177012. {
  177013. if (j > 0)
  177014. *bp |= (png_byte)((v << j) & 0xff);
  177015. else
  177016. *bp |= (png_byte)((v >> (-j)) & mask);
  177017. }
  177018. }
  177019. }
  177020. else if (row_info->bit_depth == 8)
  177021. {
  177022. png_bytep bp = row;
  177023. png_uint_32 i;
  177024. png_uint_32 istop = channels * row_info->width;
  177025. for (i = 0; i < istop; i++, bp++)
  177026. {
  177027. png_uint_16 v;
  177028. int j;
  177029. int c = (int)(i%channels);
  177030. v = *bp;
  177031. *bp = 0;
  177032. for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
  177033. {
  177034. if (j > 0)
  177035. *bp |= (png_byte)((v << j) & 0xff);
  177036. else
  177037. *bp |= (png_byte)((v >> (-j)) & 0xff);
  177038. }
  177039. }
  177040. }
  177041. else
  177042. {
  177043. png_bytep bp;
  177044. png_uint_32 i;
  177045. png_uint_32 istop = channels * row_info->width;
  177046. for (bp = row, i = 0; i < istop; i++)
  177047. {
  177048. int c = (int)(i%channels);
  177049. png_uint_16 value, v;
  177050. int j;
  177051. v = (png_uint_16)(((png_uint_16)(*bp) << 8) + *(bp + 1));
  177052. value = 0;
  177053. for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
  177054. {
  177055. if (j > 0)
  177056. value |= (png_uint_16)((v << j) & (png_uint_16)0xffff);
  177057. else
  177058. value |= (png_uint_16)((v >> (-j)) & (png_uint_16)0xffff);
  177059. }
  177060. *bp++ = (png_byte)(value >> 8);
  177061. *bp++ = (png_byte)(value & 0xff);
  177062. }
  177063. }
  177064. }
  177065. }
  177066. #endif
  177067. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  177068. void /* PRIVATE */
  177069. png_do_write_swap_alpha(png_row_infop row_info, png_bytep row)
  177070. {
  177071. png_debug(1, "in png_do_write_swap_alpha\n");
  177072. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  177073. if (row != NULL && row_info != NULL)
  177074. #endif
  177075. {
  177076. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  177077. {
  177078. if (row_info->bit_depth == 8)
  177079. {
  177080. png_bytep sp, dp;
  177081. png_uint_32 i;
  177082. png_uint_32 row_width = row_info->width;
  177083. for (i = 0, sp = dp = row; i < row_width; i++)
  177084. {
  177085. png_byte save = *(sp++);
  177086. *(dp++) = *(sp++);
  177087. *(dp++) = *(sp++);
  177088. *(dp++) = *(sp++);
  177089. *(dp++) = save;
  177090. }
  177091. }
  177092. else
  177093. {
  177094. png_bytep sp, dp;
  177095. png_uint_32 i;
  177096. png_uint_32 row_width = row_info->width;
  177097. for (i = 0, sp = dp = row; i < row_width; i++)
  177098. {
  177099. png_byte save[2];
  177100. save[0] = *(sp++);
  177101. save[1] = *(sp++);
  177102. *(dp++) = *(sp++);
  177103. *(dp++) = *(sp++);
  177104. *(dp++) = *(sp++);
  177105. *(dp++) = *(sp++);
  177106. *(dp++) = *(sp++);
  177107. *(dp++) = *(sp++);
  177108. *(dp++) = save[0];
  177109. *(dp++) = save[1];
  177110. }
  177111. }
  177112. }
  177113. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  177114. {
  177115. if (row_info->bit_depth == 8)
  177116. {
  177117. png_bytep sp, dp;
  177118. png_uint_32 i;
  177119. png_uint_32 row_width = row_info->width;
  177120. for (i = 0, sp = dp = row; i < row_width; i++)
  177121. {
  177122. png_byte save = *(sp++);
  177123. *(dp++) = *(sp++);
  177124. *(dp++) = save;
  177125. }
  177126. }
  177127. else
  177128. {
  177129. png_bytep sp, dp;
  177130. png_uint_32 i;
  177131. png_uint_32 row_width = row_info->width;
  177132. for (i = 0, sp = dp = row; i < row_width; i++)
  177133. {
  177134. png_byte save[2];
  177135. save[0] = *(sp++);
  177136. save[1] = *(sp++);
  177137. *(dp++) = *(sp++);
  177138. *(dp++) = *(sp++);
  177139. *(dp++) = save[0];
  177140. *(dp++) = save[1];
  177141. }
  177142. }
  177143. }
  177144. }
  177145. }
  177146. #endif
  177147. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  177148. void /* PRIVATE */
  177149. png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
  177150. {
  177151. png_debug(1, "in png_do_write_invert_alpha\n");
  177152. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  177153. if (row != NULL && row_info != NULL)
  177154. #endif
  177155. {
  177156. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  177157. {
  177158. if (row_info->bit_depth == 8)
  177159. {
  177160. png_bytep sp, dp;
  177161. png_uint_32 i;
  177162. png_uint_32 row_width = row_info->width;
  177163. for (i = 0, sp = dp = row; i < row_width; i++)
  177164. {
  177165. sp+=3; dp = sp;
  177166. *(dp++) = (png_byte)(255 - *(sp++));
  177167. }
  177168. }
  177169. else
  177170. {
  177171. png_bytep sp, dp;
  177172. png_uint_32 i;
  177173. png_uint_32 row_width = row_info->width;
  177174. for (i = 0, sp = dp = row; i < row_width; i++)
  177175. {
  177176. sp+=6; dp = sp;
  177177. *(dp++) = (png_byte)(255 - *(sp++));
  177178. *(dp++) = (png_byte)(255 - *(sp++));
  177179. }
  177180. }
  177181. }
  177182. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  177183. {
  177184. if (row_info->bit_depth == 8)
  177185. {
  177186. png_bytep sp, dp;
  177187. png_uint_32 i;
  177188. png_uint_32 row_width = row_info->width;
  177189. for (i = 0, sp = dp = row; i < row_width; i++)
  177190. {
  177191. *(dp++) = *(sp++);
  177192. *(dp++) = (png_byte)(255 - *(sp++));
  177193. }
  177194. }
  177195. else
  177196. {
  177197. png_bytep sp, dp;
  177198. png_uint_32 i;
  177199. png_uint_32 row_width = row_info->width;
  177200. for (i = 0, sp = dp = row; i < row_width; i++)
  177201. {
  177202. sp+=2; dp = sp;
  177203. *(dp++) = (png_byte)(255 - *(sp++));
  177204. *(dp++) = (png_byte)(255 - *(sp++));
  177205. }
  177206. }
  177207. }
  177208. }
  177209. }
  177210. #endif
  177211. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177212. void /* PRIVATE */
  177213. png_do_write_intrapixel(png_row_infop row_info, png_bytep row)
  177214. {
  177215. png_debug(1, "in png_do_write_intrapixel\n");
  177216. if (
  177217. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  177218. row != NULL && row_info != NULL &&
  177219. #endif
  177220. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  177221. {
  177222. int bytes_per_pixel;
  177223. png_uint_32 row_width = row_info->width;
  177224. if (row_info->bit_depth == 8)
  177225. {
  177226. png_bytep rp;
  177227. png_uint_32 i;
  177228. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  177229. bytes_per_pixel = 3;
  177230. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  177231. bytes_per_pixel = 4;
  177232. else
  177233. return;
  177234. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  177235. {
  177236. *(rp) = (png_byte)((*rp - *(rp+1))&0xff);
  177237. *(rp+2) = (png_byte)((*(rp+2) - *(rp+1))&0xff);
  177238. }
  177239. }
  177240. else if (row_info->bit_depth == 16)
  177241. {
  177242. png_bytep rp;
  177243. png_uint_32 i;
  177244. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  177245. bytes_per_pixel = 6;
  177246. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  177247. bytes_per_pixel = 8;
  177248. else
  177249. return;
  177250. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  177251. {
  177252. png_uint_32 s0 = (*(rp ) << 8) | *(rp+1);
  177253. png_uint_32 s1 = (*(rp+2) << 8) | *(rp+3);
  177254. png_uint_32 s2 = (*(rp+4) << 8) | *(rp+5);
  177255. png_uint_32 red = (png_uint_32)((s0-s1) & 0xffffL);
  177256. png_uint_32 blue = (png_uint_32)((s2-s1) & 0xffffL);
  177257. *(rp ) = (png_byte)((red >> 8) & 0xff);
  177258. *(rp+1) = (png_byte)(red & 0xff);
  177259. *(rp+4) = (png_byte)((blue >> 8) & 0xff);
  177260. *(rp+5) = (png_byte)(blue & 0xff);
  177261. }
  177262. }
  177263. }
  177264. }
  177265. #endif /* PNG_MNG_FEATURES_SUPPORTED */
  177266. #endif /* PNG_WRITE_SUPPORTED */
  177267. /*** End of inlined file: pngwtran.c ***/
  177268. /*** Start of inlined file: pngwutil.c ***/
  177269. #define PNG_INTERNAL
  177270. #ifdef PNG_WRITE_SUPPORTED
  177271. void PNGAPI
  177272. png_save_uint_32(png_bytep buf, png_uint_32 i)
  177273. {
  177274. buf[0] = (png_byte)((i >> 24) & 0xff);
  177275. buf[1] = (png_byte)((i >> 16) & 0xff);
  177276. buf[2] = (png_byte)((i >> 8) & 0xff);
  177277. buf[3] = (png_byte)(i & 0xff);
  177278. }
  177279. void PNGAPI
  177280. png_save_int_32(png_bytep buf, png_int_32 i)
  177281. {
  177282. buf[0] = (png_byte)((i >> 24) & 0xff);
  177283. buf[1] = (png_byte)((i >> 16) & 0xff);
  177284. buf[2] = (png_byte)((i >> 8) & 0xff);
  177285. buf[3] = (png_byte)(i & 0xff);
  177286. }
  177287. void PNGAPI
  177288. png_save_uint_16(png_bytep buf, unsigned int i)
  177289. {
  177290. buf[0] = (png_byte)((i >> 8) & 0xff);
  177291. buf[1] = (png_byte)(i & 0xff);
  177292. }
  177293. void PNGAPI
  177294. png_write_chunk(png_structp png_ptr, png_bytep chunk_name,
  177295. png_bytep data, png_size_t length)
  177296. {
  177297. if(png_ptr == NULL) return;
  177298. png_write_chunk_start(png_ptr, chunk_name, (png_uint_32)length);
  177299. png_write_chunk_data(png_ptr, data, length);
  177300. png_write_chunk_end(png_ptr);
  177301. }
  177302. void PNGAPI
  177303. png_write_chunk_start(png_structp png_ptr, png_bytep chunk_name,
  177304. png_uint_32 length)
  177305. {
  177306. png_byte buf[4];
  177307. png_debug2(0, "Writing %s chunk (%lu bytes)\n", chunk_name, length);
  177308. if(png_ptr == NULL) return;
  177309. png_save_uint_32(buf, length);
  177310. png_write_data(png_ptr, buf, (png_size_t)4);
  177311. png_write_data(png_ptr, chunk_name, (png_size_t)4);
  177312. png_reset_crc(png_ptr);
  177313. png_calculate_crc(png_ptr, chunk_name, (png_size_t)4);
  177314. }
  177315. void PNGAPI
  177316. png_write_chunk_data(png_structp png_ptr, png_bytep data, png_size_t length)
  177317. {
  177318. if(png_ptr == NULL) return;
  177319. if (data != NULL && length > 0)
  177320. {
  177321. png_calculate_crc(png_ptr, data, length);
  177322. png_write_data(png_ptr, data, length);
  177323. }
  177324. }
  177325. void PNGAPI
  177326. png_write_chunk_end(png_structp png_ptr)
  177327. {
  177328. png_byte buf[4];
  177329. if(png_ptr == NULL) return;
  177330. png_save_uint_32(buf, png_ptr->crc);
  177331. png_write_data(png_ptr, buf, (png_size_t)4);
  177332. }
  177333. void /* PRIVATE */
  177334. png_write_sig(png_structp png_ptr)
  177335. {
  177336. png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  177337. png_write_data(png_ptr, &png_signature[png_ptr->sig_bytes],
  177338. (png_size_t)8 - png_ptr->sig_bytes);
  177339. if(png_ptr->sig_bytes < 3)
  177340. png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
  177341. }
  177342. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_iCCP_SUPPORTED)
  177343. typedef struct
  177344. {
  177345. char *input; /* the uncompressed input data */
  177346. int input_len; /* its length */
  177347. int num_output_ptr; /* number of output pointers used */
  177348. int max_output_ptr; /* size of output_ptr */
  177349. png_charpp output_ptr; /* array of pointers to output */
  177350. } compression_state;
  177351. static int /* PRIVATE */
  177352. png_text_compress(png_structp png_ptr,
  177353. png_charp text, png_size_t text_len, int compression,
  177354. compression_state *comp)
  177355. {
  177356. int ret;
  177357. comp->num_output_ptr = 0;
  177358. comp->max_output_ptr = 0;
  177359. comp->output_ptr = NULL;
  177360. comp->input = NULL;
  177361. comp->input_len = 0;
  177362. if (compression == PNG_TEXT_COMPRESSION_NONE)
  177363. {
  177364. comp->input = text;
  177365. comp->input_len = text_len;
  177366. return((int)text_len);
  177367. }
  177368. if (compression >= PNG_TEXT_COMPRESSION_LAST)
  177369. {
  177370. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  177371. char msg[50];
  177372. png_snprintf(msg, 50, "Unknown compression type %d", compression);
  177373. png_warning(png_ptr, msg);
  177374. #else
  177375. png_warning(png_ptr, "Unknown compression type");
  177376. #endif
  177377. }
  177378. png_ptr->zstream.avail_in = (uInt)text_len;
  177379. png_ptr->zstream.next_in = (Bytef *)text;
  177380. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  177381. png_ptr->zstream.next_out = (Bytef *)png_ptr->zbuf;
  177382. do
  177383. {
  177384. ret = deflate(&png_ptr->zstream, Z_NO_FLUSH);
  177385. if (ret != Z_OK)
  177386. {
  177387. if (png_ptr->zstream.msg != NULL)
  177388. png_error(png_ptr, png_ptr->zstream.msg);
  177389. else
  177390. png_error(png_ptr, "zlib error");
  177391. }
  177392. if (!(png_ptr->zstream.avail_out))
  177393. {
  177394. if (comp->num_output_ptr >= comp->max_output_ptr)
  177395. {
  177396. int old_max;
  177397. old_max = comp->max_output_ptr;
  177398. comp->max_output_ptr = comp->num_output_ptr + 4;
  177399. if (comp->output_ptr != NULL)
  177400. {
  177401. png_charpp old_ptr;
  177402. old_ptr = comp->output_ptr;
  177403. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  177404. (png_uint_32)(comp->max_output_ptr *
  177405. png_sizeof (png_charpp)));
  177406. png_memcpy(comp->output_ptr, old_ptr, old_max
  177407. * png_sizeof (png_charp));
  177408. png_free(png_ptr, old_ptr);
  177409. }
  177410. else
  177411. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  177412. (png_uint_32)(comp->max_output_ptr *
  177413. png_sizeof (png_charp)));
  177414. }
  177415. comp->output_ptr[comp->num_output_ptr] = (png_charp)png_malloc(png_ptr,
  177416. (png_uint_32)png_ptr->zbuf_size);
  177417. png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf,
  177418. png_ptr->zbuf_size);
  177419. comp->num_output_ptr++;
  177420. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  177421. png_ptr->zstream.next_out = png_ptr->zbuf;
  177422. }
  177423. } while (png_ptr->zstream.avail_in);
  177424. do
  177425. {
  177426. ret = deflate(&png_ptr->zstream, Z_FINISH);
  177427. if (ret == Z_OK)
  177428. {
  177429. if (!(png_ptr->zstream.avail_out))
  177430. {
  177431. if (comp->num_output_ptr >= comp->max_output_ptr)
  177432. {
  177433. int old_max;
  177434. old_max = comp->max_output_ptr;
  177435. comp->max_output_ptr = comp->num_output_ptr + 4;
  177436. if (comp->output_ptr != NULL)
  177437. {
  177438. png_charpp old_ptr;
  177439. old_ptr = comp->output_ptr;
  177440. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  177441. (png_uint_32)(comp->max_output_ptr *
  177442. png_sizeof (png_charpp)));
  177443. png_memcpy(comp->output_ptr, old_ptr,
  177444. old_max * png_sizeof (png_charp));
  177445. png_free(png_ptr, old_ptr);
  177446. }
  177447. else
  177448. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  177449. (png_uint_32)(comp->max_output_ptr *
  177450. png_sizeof (png_charp)));
  177451. }
  177452. comp->output_ptr[comp->num_output_ptr] =
  177453. (png_charp)png_malloc(png_ptr, (png_uint_32)png_ptr->zbuf_size);
  177454. png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf,
  177455. png_ptr->zbuf_size);
  177456. comp->num_output_ptr++;
  177457. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  177458. png_ptr->zstream.next_out = png_ptr->zbuf;
  177459. }
  177460. }
  177461. else if (ret != Z_STREAM_END)
  177462. {
  177463. if (png_ptr->zstream.msg != NULL)
  177464. png_error(png_ptr, png_ptr->zstream.msg);
  177465. else
  177466. png_error(png_ptr, "zlib error");
  177467. }
  177468. } while (ret != Z_STREAM_END);
  177469. text_len = png_ptr->zbuf_size * comp->num_output_ptr;
  177470. if (png_ptr->zstream.avail_out < png_ptr->zbuf_size)
  177471. text_len += png_ptr->zbuf_size - (png_size_t)png_ptr->zstream.avail_out;
  177472. return((int)text_len);
  177473. }
  177474. static void /* PRIVATE */
  177475. png_write_compressed_data_out(png_structp png_ptr, compression_state *comp)
  177476. {
  177477. int i;
  177478. if (comp->input)
  177479. {
  177480. png_write_chunk_data(png_ptr, (png_bytep)comp->input,
  177481. (png_size_t)comp->input_len);
  177482. return;
  177483. }
  177484. for (i = 0; i < comp->num_output_ptr; i++)
  177485. {
  177486. png_write_chunk_data(png_ptr,(png_bytep)comp->output_ptr[i],
  177487. png_ptr->zbuf_size);
  177488. png_free(png_ptr, comp->output_ptr[i]);
  177489. comp->output_ptr[i]=NULL;
  177490. }
  177491. if (comp->max_output_ptr != 0)
  177492. png_free(png_ptr, comp->output_ptr);
  177493. comp->output_ptr=NULL;
  177494. if (png_ptr->zstream.avail_out < (png_uint_32)png_ptr->zbuf_size)
  177495. png_write_chunk_data(png_ptr, png_ptr->zbuf,
  177496. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  177497. deflateReset(&png_ptr->zstream);
  177498. png_ptr->zstream.data_type = Z_BINARY;
  177499. }
  177500. #endif
  177501. void /* PRIVATE */
  177502. png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height,
  177503. int bit_depth, int color_type, int compression_type, int filter_type,
  177504. int interlace_type)
  177505. {
  177506. #ifdef PNG_USE_LOCAL_ARRAYS
  177507. PNG_IHDR;
  177508. #endif
  177509. png_byte buf[13]; /* buffer to store the IHDR info */
  177510. png_debug(1, "in png_write_IHDR\n");
  177511. switch (color_type)
  177512. {
  177513. case PNG_COLOR_TYPE_GRAY:
  177514. switch (bit_depth)
  177515. {
  177516. case 1:
  177517. case 2:
  177518. case 4:
  177519. case 8:
  177520. case 16: png_ptr->channels = 1; break;
  177521. default: png_error(png_ptr,"Invalid bit depth for grayscale image");
  177522. }
  177523. break;
  177524. case PNG_COLOR_TYPE_RGB:
  177525. if (bit_depth != 8 && bit_depth != 16)
  177526. png_error(png_ptr, "Invalid bit depth for RGB image");
  177527. png_ptr->channels = 3;
  177528. break;
  177529. case PNG_COLOR_TYPE_PALETTE:
  177530. switch (bit_depth)
  177531. {
  177532. case 1:
  177533. case 2:
  177534. case 4:
  177535. case 8: png_ptr->channels = 1; break;
  177536. default: png_error(png_ptr, "Invalid bit depth for paletted image");
  177537. }
  177538. break;
  177539. case PNG_COLOR_TYPE_GRAY_ALPHA:
  177540. if (bit_depth != 8 && bit_depth != 16)
  177541. png_error(png_ptr, "Invalid bit depth for grayscale+alpha image");
  177542. png_ptr->channels = 2;
  177543. break;
  177544. case PNG_COLOR_TYPE_RGB_ALPHA:
  177545. if (bit_depth != 8 && bit_depth != 16)
  177546. png_error(png_ptr, "Invalid bit depth for RGBA image");
  177547. png_ptr->channels = 4;
  177548. break;
  177549. default:
  177550. png_error(png_ptr, "Invalid image color type specified");
  177551. }
  177552. if (compression_type != PNG_COMPRESSION_TYPE_BASE)
  177553. {
  177554. png_warning(png_ptr, "Invalid compression type specified");
  177555. compression_type = PNG_COMPRESSION_TYPE_BASE;
  177556. }
  177557. if (
  177558. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177559. !((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  177560. ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
  177561. (color_type == PNG_COLOR_TYPE_RGB ||
  177562. color_type == PNG_COLOR_TYPE_RGB_ALPHA) &&
  177563. (filter_type == PNG_INTRAPIXEL_DIFFERENCING)) &&
  177564. #endif
  177565. filter_type != PNG_FILTER_TYPE_BASE)
  177566. {
  177567. png_warning(png_ptr, "Invalid filter type specified");
  177568. filter_type = PNG_FILTER_TYPE_BASE;
  177569. }
  177570. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  177571. if (interlace_type != PNG_INTERLACE_NONE &&
  177572. interlace_type != PNG_INTERLACE_ADAM7)
  177573. {
  177574. png_warning(png_ptr, "Invalid interlace type specified");
  177575. interlace_type = PNG_INTERLACE_ADAM7;
  177576. }
  177577. #else
  177578. interlace_type=PNG_INTERLACE_NONE;
  177579. #endif
  177580. png_ptr->bit_depth = (png_byte)bit_depth;
  177581. png_ptr->color_type = (png_byte)color_type;
  177582. png_ptr->interlaced = (png_byte)interlace_type;
  177583. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177584. png_ptr->filter_type = (png_byte)filter_type;
  177585. #endif
  177586. png_ptr->compression_type = (png_byte)compression_type;
  177587. png_ptr->width = width;
  177588. png_ptr->height = height;
  177589. png_ptr->pixel_depth = (png_byte)(bit_depth * png_ptr->channels);
  177590. png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, width);
  177591. png_ptr->usr_width = png_ptr->width;
  177592. png_ptr->usr_bit_depth = png_ptr->bit_depth;
  177593. png_ptr->usr_channels = png_ptr->channels;
  177594. png_save_uint_32(buf, width);
  177595. png_save_uint_32(buf + 4, height);
  177596. buf[8] = (png_byte)bit_depth;
  177597. buf[9] = (png_byte)color_type;
  177598. buf[10] = (png_byte)compression_type;
  177599. buf[11] = (png_byte)filter_type;
  177600. buf[12] = (png_byte)interlace_type;
  177601. png_write_chunk(png_ptr, png_IHDR, buf, (png_size_t)13);
  177602. png_ptr->zstream.zalloc = png_zalloc;
  177603. png_ptr->zstream.zfree = png_zfree;
  177604. png_ptr->zstream.opaque = (voidpf)png_ptr;
  177605. if (!(png_ptr->do_filter))
  177606. {
  177607. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE ||
  177608. png_ptr->bit_depth < 8)
  177609. png_ptr->do_filter = PNG_FILTER_NONE;
  177610. else
  177611. png_ptr->do_filter = PNG_ALL_FILTERS;
  177612. }
  177613. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_STRATEGY))
  177614. {
  177615. if (png_ptr->do_filter != PNG_FILTER_NONE)
  177616. png_ptr->zlib_strategy = Z_FILTERED;
  177617. else
  177618. png_ptr->zlib_strategy = Z_DEFAULT_STRATEGY;
  177619. }
  177620. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_LEVEL))
  177621. png_ptr->zlib_level = Z_DEFAULT_COMPRESSION;
  177622. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL))
  177623. png_ptr->zlib_mem_level = 8;
  177624. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS))
  177625. png_ptr->zlib_window_bits = 15;
  177626. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_METHOD))
  177627. png_ptr->zlib_method = 8;
  177628. if (deflateInit2(&png_ptr->zstream, png_ptr->zlib_level,
  177629. png_ptr->zlib_method, png_ptr->zlib_window_bits,
  177630. png_ptr->zlib_mem_level, png_ptr->zlib_strategy) != Z_OK)
  177631. png_error(png_ptr, "zlib failed to initialize compressor");
  177632. png_ptr->zstream.next_out = png_ptr->zbuf;
  177633. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  177634. png_ptr->zstream.data_type = Z_BINARY;
  177635. png_ptr->mode = PNG_HAVE_IHDR;
  177636. }
  177637. void /* PRIVATE */
  177638. png_write_PLTE(png_structp png_ptr, png_colorp palette, png_uint_32 num_pal)
  177639. {
  177640. #ifdef PNG_USE_LOCAL_ARRAYS
  177641. PNG_PLTE;
  177642. #endif
  177643. png_uint_32 i;
  177644. png_colorp pal_ptr;
  177645. png_byte buf[3];
  177646. png_debug(1, "in png_write_PLTE\n");
  177647. if ((
  177648. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177649. !(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) &&
  177650. #endif
  177651. num_pal == 0) || num_pal > 256)
  177652. {
  177653. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  177654. {
  177655. png_error(png_ptr, "Invalid number of colors in palette");
  177656. }
  177657. else
  177658. {
  177659. png_warning(png_ptr, "Invalid number of colors in palette");
  177660. return;
  177661. }
  177662. }
  177663. if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR))
  177664. {
  177665. png_warning(png_ptr,
  177666. "Ignoring request to write a PLTE chunk in grayscale PNG");
  177667. return;
  177668. }
  177669. png_ptr->num_palette = (png_uint_16)num_pal;
  177670. png_debug1(3, "num_palette = %d\n", png_ptr->num_palette);
  177671. png_write_chunk_start(png_ptr, png_PLTE, num_pal * 3);
  177672. #ifndef PNG_NO_POINTER_INDEXING
  177673. for (i = 0, pal_ptr = palette; i < num_pal; i++, pal_ptr++)
  177674. {
  177675. buf[0] = pal_ptr->red;
  177676. buf[1] = pal_ptr->green;
  177677. buf[2] = pal_ptr->blue;
  177678. png_write_chunk_data(png_ptr, buf, (png_size_t)3);
  177679. }
  177680. #else
  177681. pal_ptr=palette;
  177682. for (i = 0; i < num_pal; i++)
  177683. {
  177684. buf[0] = pal_ptr[i].red;
  177685. buf[1] = pal_ptr[i].green;
  177686. buf[2] = pal_ptr[i].blue;
  177687. png_write_chunk_data(png_ptr, buf, (png_size_t)3);
  177688. }
  177689. #endif
  177690. png_write_chunk_end(png_ptr);
  177691. png_ptr->mode |= PNG_HAVE_PLTE;
  177692. }
  177693. void /* PRIVATE */
  177694. png_write_IDAT(png_structp png_ptr, png_bytep data, png_size_t length)
  177695. {
  177696. #ifdef PNG_USE_LOCAL_ARRAYS
  177697. PNG_IDAT;
  177698. #endif
  177699. png_debug(1, "in png_write_IDAT\n");
  177700. if (!(png_ptr->mode & PNG_HAVE_IDAT) &&
  177701. png_ptr->compression_type == PNG_COMPRESSION_TYPE_BASE)
  177702. {
  177703. unsigned int z_cmf = data[0]; /* zlib compression method and flags */
  177704. if ((z_cmf & 0x0f) == 8 && (z_cmf & 0xf0) <= 0x70)
  177705. {
  177706. if (length >= 2 &&
  177707. png_ptr->height < 16384 && png_ptr->width < 16384)
  177708. {
  177709. png_uint_32 uncompressed_idat_size = png_ptr->height *
  177710. ((png_ptr->width *
  177711. png_ptr->channels * png_ptr->bit_depth + 15) >> 3);
  177712. unsigned int z_cinfo = z_cmf >> 4;
  177713. unsigned int half_z_window_size = 1 << (z_cinfo + 7);
  177714. while (uncompressed_idat_size <= half_z_window_size &&
  177715. half_z_window_size >= 256)
  177716. {
  177717. z_cinfo--;
  177718. half_z_window_size >>= 1;
  177719. }
  177720. z_cmf = (z_cmf & 0x0f) | (z_cinfo << 4);
  177721. if (data[0] != (png_byte)z_cmf)
  177722. {
  177723. data[0] = (png_byte)z_cmf;
  177724. data[1] &= 0xe0;
  177725. data[1] += (png_byte)(0x1f - ((z_cmf << 8) + data[1]) % 0x1f);
  177726. }
  177727. }
  177728. }
  177729. else
  177730. png_error(png_ptr,
  177731. "Invalid zlib compression method or flags in IDAT");
  177732. }
  177733. png_write_chunk(png_ptr, png_IDAT, data, length);
  177734. png_ptr->mode |= PNG_HAVE_IDAT;
  177735. }
  177736. void /* PRIVATE */
  177737. png_write_IEND(png_structp png_ptr)
  177738. {
  177739. #ifdef PNG_USE_LOCAL_ARRAYS
  177740. PNG_IEND;
  177741. #endif
  177742. png_debug(1, "in png_write_IEND\n");
  177743. png_write_chunk(png_ptr, png_IEND, png_bytep_NULL,
  177744. (png_size_t)0);
  177745. png_ptr->mode |= PNG_HAVE_IEND;
  177746. }
  177747. #if defined(PNG_WRITE_gAMA_SUPPORTED)
  177748. #ifdef PNG_FLOATING_POINT_SUPPORTED
  177749. void /* PRIVATE */
  177750. png_write_gAMA(png_structp png_ptr, double file_gamma)
  177751. {
  177752. #ifdef PNG_USE_LOCAL_ARRAYS
  177753. PNG_gAMA;
  177754. #endif
  177755. png_uint_32 igamma;
  177756. png_byte buf[4];
  177757. png_debug(1, "in png_write_gAMA\n");
  177758. igamma = (png_uint_32)(file_gamma * 100000.0 + 0.5);
  177759. png_save_uint_32(buf, igamma);
  177760. png_write_chunk(png_ptr, png_gAMA, buf, (png_size_t)4);
  177761. }
  177762. #endif
  177763. #ifdef PNG_FIXED_POINT_SUPPORTED
  177764. void /* PRIVATE */
  177765. png_write_gAMA_fixed(png_structp png_ptr, png_fixed_point file_gamma)
  177766. {
  177767. #ifdef PNG_USE_LOCAL_ARRAYS
  177768. PNG_gAMA;
  177769. #endif
  177770. png_byte buf[4];
  177771. png_debug(1, "in png_write_gAMA\n");
  177772. png_save_uint_32(buf, (png_uint_32)file_gamma);
  177773. png_write_chunk(png_ptr, png_gAMA, buf, (png_size_t)4);
  177774. }
  177775. #endif
  177776. #endif
  177777. #if defined(PNG_WRITE_sRGB_SUPPORTED)
  177778. void /* PRIVATE */
  177779. png_write_sRGB(png_structp png_ptr, int srgb_intent)
  177780. {
  177781. #ifdef PNG_USE_LOCAL_ARRAYS
  177782. PNG_sRGB;
  177783. #endif
  177784. png_byte buf[1];
  177785. png_debug(1, "in png_write_sRGB\n");
  177786. if(srgb_intent >= PNG_sRGB_INTENT_LAST)
  177787. png_warning(png_ptr,
  177788. "Invalid sRGB rendering intent specified");
  177789. buf[0]=(png_byte)srgb_intent;
  177790. png_write_chunk(png_ptr, png_sRGB, buf, (png_size_t)1);
  177791. }
  177792. #endif
  177793. #if defined(PNG_WRITE_iCCP_SUPPORTED)
  177794. void /* PRIVATE */
  177795. png_write_iCCP(png_structp png_ptr, png_charp name, int compression_type,
  177796. png_charp profile, int profile_len)
  177797. {
  177798. #ifdef PNG_USE_LOCAL_ARRAYS
  177799. PNG_iCCP;
  177800. #endif
  177801. png_size_t name_len;
  177802. png_charp new_name;
  177803. compression_state comp;
  177804. int embedded_profile_len = 0;
  177805. png_debug(1, "in png_write_iCCP\n");
  177806. comp.num_output_ptr = 0;
  177807. comp.max_output_ptr = 0;
  177808. comp.output_ptr = NULL;
  177809. comp.input = NULL;
  177810. comp.input_len = 0;
  177811. if (name == NULL || (name_len = png_check_keyword(png_ptr, name,
  177812. &new_name)) == 0)
  177813. {
  177814. png_warning(png_ptr, "Empty keyword in iCCP chunk");
  177815. return;
  177816. }
  177817. if (compression_type != PNG_COMPRESSION_TYPE_BASE)
  177818. png_warning(png_ptr, "Unknown compression type in iCCP chunk");
  177819. if (profile == NULL)
  177820. profile_len = 0;
  177821. if (profile_len > 3)
  177822. embedded_profile_len =
  177823. ((*( (png_bytep)profile ))<<24) |
  177824. ((*( (png_bytep)profile+1))<<16) |
  177825. ((*( (png_bytep)profile+2))<< 8) |
  177826. ((*( (png_bytep)profile+3)) );
  177827. if (profile_len < embedded_profile_len)
  177828. {
  177829. png_warning(png_ptr,
  177830. "Embedded profile length too large in iCCP chunk");
  177831. return;
  177832. }
  177833. if (profile_len > embedded_profile_len)
  177834. {
  177835. png_warning(png_ptr,
  177836. "Truncating profile to actual length in iCCP chunk");
  177837. profile_len = embedded_profile_len;
  177838. }
  177839. if (profile_len)
  177840. profile_len = png_text_compress(png_ptr, profile, (png_size_t)profile_len,
  177841. PNG_COMPRESSION_TYPE_BASE, &comp);
  177842. png_write_chunk_start(png_ptr, png_iCCP,
  177843. (png_uint_32)name_len+profile_len+2);
  177844. new_name[name_len+1]=0x00;
  177845. png_write_chunk_data(png_ptr, (png_bytep)new_name, name_len + 2);
  177846. if (profile_len)
  177847. png_write_compressed_data_out(png_ptr, &comp);
  177848. png_write_chunk_end(png_ptr);
  177849. png_free(png_ptr, new_name);
  177850. }
  177851. #endif
  177852. #if defined(PNG_WRITE_sPLT_SUPPORTED)
  177853. void /* PRIVATE */
  177854. png_write_sPLT(png_structp png_ptr, png_sPLT_tp spalette)
  177855. {
  177856. #ifdef PNG_USE_LOCAL_ARRAYS
  177857. PNG_sPLT;
  177858. #endif
  177859. png_size_t name_len;
  177860. png_charp new_name;
  177861. png_byte entrybuf[10];
  177862. int entry_size = (spalette->depth == 8 ? 6 : 10);
  177863. int palette_size = entry_size * spalette->nentries;
  177864. png_sPLT_entryp ep;
  177865. #ifdef PNG_NO_POINTER_INDEXING
  177866. int i;
  177867. #endif
  177868. png_debug(1, "in png_write_sPLT\n");
  177869. if (spalette->name == NULL || (name_len = png_check_keyword(png_ptr,
  177870. spalette->name, &new_name))==0)
  177871. {
  177872. png_warning(png_ptr, "Empty keyword in sPLT chunk");
  177873. return;
  177874. }
  177875. png_write_chunk_start(png_ptr, png_sPLT,
  177876. (png_uint_32)(name_len + 2 + palette_size));
  177877. png_write_chunk_data(png_ptr, (png_bytep)new_name, name_len + 1);
  177878. png_write_chunk_data(png_ptr, (png_bytep)&spalette->depth, 1);
  177879. #ifndef PNG_NO_POINTER_INDEXING
  177880. for (ep = spalette->entries; ep<spalette->entries+spalette->nentries; ep++)
  177881. {
  177882. if (spalette->depth == 8)
  177883. {
  177884. entrybuf[0] = (png_byte)ep->red;
  177885. entrybuf[1] = (png_byte)ep->green;
  177886. entrybuf[2] = (png_byte)ep->blue;
  177887. entrybuf[3] = (png_byte)ep->alpha;
  177888. png_save_uint_16(entrybuf + 4, ep->frequency);
  177889. }
  177890. else
  177891. {
  177892. png_save_uint_16(entrybuf + 0, ep->red);
  177893. png_save_uint_16(entrybuf + 2, ep->green);
  177894. png_save_uint_16(entrybuf + 4, ep->blue);
  177895. png_save_uint_16(entrybuf + 6, ep->alpha);
  177896. png_save_uint_16(entrybuf + 8, ep->frequency);
  177897. }
  177898. png_write_chunk_data(png_ptr, entrybuf, (png_size_t)entry_size);
  177899. }
  177900. #else
  177901. ep=spalette->entries;
  177902. for (i=0; i>spalette->nentries; i++)
  177903. {
  177904. if (spalette->depth == 8)
  177905. {
  177906. entrybuf[0] = (png_byte)ep[i].red;
  177907. entrybuf[1] = (png_byte)ep[i].green;
  177908. entrybuf[2] = (png_byte)ep[i].blue;
  177909. entrybuf[3] = (png_byte)ep[i].alpha;
  177910. png_save_uint_16(entrybuf + 4, ep[i].frequency);
  177911. }
  177912. else
  177913. {
  177914. png_save_uint_16(entrybuf + 0, ep[i].red);
  177915. png_save_uint_16(entrybuf + 2, ep[i].green);
  177916. png_save_uint_16(entrybuf + 4, ep[i].blue);
  177917. png_save_uint_16(entrybuf + 6, ep[i].alpha);
  177918. png_save_uint_16(entrybuf + 8, ep[i].frequency);
  177919. }
  177920. png_write_chunk_data(png_ptr, entrybuf, entry_size);
  177921. }
  177922. #endif
  177923. png_write_chunk_end(png_ptr);
  177924. png_free(png_ptr, new_name);
  177925. }
  177926. #endif
  177927. #if defined(PNG_WRITE_sBIT_SUPPORTED)
  177928. void /* PRIVATE */
  177929. png_write_sBIT(png_structp png_ptr, png_color_8p sbit, int color_type)
  177930. {
  177931. #ifdef PNG_USE_LOCAL_ARRAYS
  177932. PNG_sBIT;
  177933. #endif
  177934. png_byte buf[4];
  177935. png_size_t size;
  177936. png_debug(1, "in png_write_sBIT\n");
  177937. if (color_type & PNG_COLOR_MASK_COLOR)
  177938. {
  177939. png_byte maxbits;
  177940. maxbits = (png_byte)(color_type==PNG_COLOR_TYPE_PALETTE ? 8 :
  177941. png_ptr->usr_bit_depth);
  177942. if (sbit->red == 0 || sbit->red > maxbits ||
  177943. sbit->green == 0 || sbit->green > maxbits ||
  177944. sbit->blue == 0 || sbit->blue > maxbits)
  177945. {
  177946. png_warning(png_ptr, "Invalid sBIT depth specified");
  177947. return;
  177948. }
  177949. buf[0] = sbit->red;
  177950. buf[1] = sbit->green;
  177951. buf[2] = sbit->blue;
  177952. size = 3;
  177953. }
  177954. else
  177955. {
  177956. if (sbit->gray == 0 || sbit->gray > png_ptr->usr_bit_depth)
  177957. {
  177958. png_warning(png_ptr, "Invalid sBIT depth specified");
  177959. return;
  177960. }
  177961. buf[0] = sbit->gray;
  177962. size = 1;
  177963. }
  177964. if (color_type & PNG_COLOR_MASK_ALPHA)
  177965. {
  177966. if (sbit->alpha == 0 || sbit->alpha > png_ptr->usr_bit_depth)
  177967. {
  177968. png_warning(png_ptr, "Invalid sBIT depth specified");
  177969. return;
  177970. }
  177971. buf[size++] = sbit->alpha;
  177972. }
  177973. png_write_chunk(png_ptr, png_sBIT, buf, size);
  177974. }
  177975. #endif
  177976. #if defined(PNG_WRITE_cHRM_SUPPORTED)
  177977. #ifdef PNG_FLOATING_POINT_SUPPORTED
  177978. void /* PRIVATE */
  177979. png_write_cHRM(png_structp png_ptr, double white_x, double white_y,
  177980. double red_x, double red_y, double green_x, double green_y,
  177981. double blue_x, double blue_y)
  177982. {
  177983. #ifdef PNG_USE_LOCAL_ARRAYS
  177984. PNG_cHRM;
  177985. #endif
  177986. png_byte buf[32];
  177987. png_uint_32 itemp;
  177988. png_debug(1, "in png_write_cHRM\n");
  177989. if (white_x < 0 || white_x > 0.8 || white_y < 0 || white_y > 0.8 ||
  177990. white_x + white_y > 1.0)
  177991. {
  177992. png_warning(png_ptr, "Invalid cHRM white point specified");
  177993. #if !defined(PNG_NO_CONSOLE_IO)
  177994. fprintf(stderr,"white_x=%f, white_y=%f\n",white_x, white_y);
  177995. #endif
  177996. return;
  177997. }
  177998. itemp = (png_uint_32)(white_x * 100000.0 + 0.5);
  177999. png_save_uint_32(buf, itemp);
  178000. itemp = (png_uint_32)(white_y * 100000.0 + 0.5);
  178001. png_save_uint_32(buf + 4, itemp);
  178002. if (red_x < 0 || red_y < 0 || red_x + red_y > 1.0)
  178003. {
  178004. png_warning(png_ptr, "Invalid cHRM red point specified");
  178005. return;
  178006. }
  178007. itemp = (png_uint_32)(red_x * 100000.0 + 0.5);
  178008. png_save_uint_32(buf + 8, itemp);
  178009. itemp = (png_uint_32)(red_y * 100000.0 + 0.5);
  178010. png_save_uint_32(buf + 12, itemp);
  178011. if (green_x < 0 || green_y < 0 || green_x + green_y > 1.0)
  178012. {
  178013. png_warning(png_ptr, "Invalid cHRM green point specified");
  178014. return;
  178015. }
  178016. itemp = (png_uint_32)(green_x * 100000.0 + 0.5);
  178017. png_save_uint_32(buf + 16, itemp);
  178018. itemp = (png_uint_32)(green_y * 100000.0 + 0.5);
  178019. png_save_uint_32(buf + 20, itemp);
  178020. if (blue_x < 0 || blue_y < 0 || blue_x + blue_y > 1.0)
  178021. {
  178022. png_warning(png_ptr, "Invalid cHRM blue point specified");
  178023. return;
  178024. }
  178025. itemp = (png_uint_32)(blue_x * 100000.0 + 0.5);
  178026. png_save_uint_32(buf + 24, itemp);
  178027. itemp = (png_uint_32)(blue_y * 100000.0 + 0.5);
  178028. png_save_uint_32(buf + 28, itemp);
  178029. png_write_chunk(png_ptr, png_cHRM, buf, (png_size_t)32);
  178030. }
  178031. #endif
  178032. #ifdef PNG_FIXED_POINT_SUPPORTED
  178033. void /* PRIVATE */
  178034. png_write_cHRM_fixed(png_structp png_ptr, png_fixed_point white_x,
  178035. png_fixed_point white_y, png_fixed_point red_x, png_fixed_point red_y,
  178036. png_fixed_point green_x, png_fixed_point green_y, png_fixed_point blue_x,
  178037. png_fixed_point blue_y)
  178038. {
  178039. #ifdef PNG_USE_LOCAL_ARRAYS
  178040. PNG_cHRM;
  178041. #endif
  178042. png_byte buf[32];
  178043. png_debug(1, "in png_write_cHRM\n");
  178044. if (white_x > 80000L || white_y > 80000L || white_x + white_y > 100000L)
  178045. {
  178046. png_warning(png_ptr, "Invalid fixed cHRM white point specified");
  178047. #if !defined(PNG_NO_CONSOLE_IO)
  178048. fprintf(stderr,"white_x=%ld, white_y=%ld\n",white_x, white_y);
  178049. #endif
  178050. return;
  178051. }
  178052. png_save_uint_32(buf, (png_uint_32)white_x);
  178053. png_save_uint_32(buf + 4, (png_uint_32)white_y);
  178054. if (red_x + red_y > 100000L)
  178055. {
  178056. png_warning(png_ptr, "Invalid cHRM fixed red point specified");
  178057. return;
  178058. }
  178059. png_save_uint_32(buf + 8, (png_uint_32)red_x);
  178060. png_save_uint_32(buf + 12, (png_uint_32)red_y);
  178061. if (green_x + green_y > 100000L)
  178062. {
  178063. png_warning(png_ptr, "Invalid fixed cHRM green point specified");
  178064. return;
  178065. }
  178066. png_save_uint_32(buf + 16, (png_uint_32)green_x);
  178067. png_save_uint_32(buf + 20, (png_uint_32)green_y);
  178068. if (blue_x + blue_y > 100000L)
  178069. {
  178070. png_warning(png_ptr, "Invalid fixed cHRM blue point specified");
  178071. return;
  178072. }
  178073. png_save_uint_32(buf + 24, (png_uint_32)blue_x);
  178074. png_save_uint_32(buf + 28, (png_uint_32)blue_y);
  178075. png_write_chunk(png_ptr, png_cHRM, buf, (png_size_t)32);
  178076. }
  178077. #endif
  178078. #endif
  178079. #if defined(PNG_WRITE_tRNS_SUPPORTED)
  178080. void /* PRIVATE */
  178081. png_write_tRNS(png_structp png_ptr, png_bytep trans, png_color_16p tran,
  178082. int num_trans, int color_type)
  178083. {
  178084. #ifdef PNG_USE_LOCAL_ARRAYS
  178085. PNG_tRNS;
  178086. #endif
  178087. png_byte buf[6];
  178088. png_debug(1, "in png_write_tRNS\n");
  178089. if (color_type == PNG_COLOR_TYPE_PALETTE)
  178090. {
  178091. if (num_trans <= 0 || num_trans > (int)png_ptr->num_palette)
  178092. {
  178093. png_warning(png_ptr,"Invalid number of transparent colors specified");
  178094. return;
  178095. }
  178096. png_write_chunk(png_ptr, png_tRNS, trans, (png_size_t)num_trans);
  178097. }
  178098. else if (color_type == PNG_COLOR_TYPE_GRAY)
  178099. {
  178100. if(tran->gray >= (1 << png_ptr->bit_depth))
  178101. {
  178102. png_warning(png_ptr,
  178103. "Ignoring attempt to write tRNS chunk out-of-range for bit_depth");
  178104. return;
  178105. }
  178106. png_save_uint_16(buf, tran->gray);
  178107. png_write_chunk(png_ptr, png_tRNS, buf, (png_size_t)2);
  178108. }
  178109. else if (color_type == PNG_COLOR_TYPE_RGB)
  178110. {
  178111. png_save_uint_16(buf, tran->red);
  178112. png_save_uint_16(buf + 2, tran->green);
  178113. png_save_uint_16(buf + 4, tran->blue);
  178114. if(png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
  178115. {
  178116. png_warning(png_ptr,
  178117. "Ignoring attempt to write 16-bit tRNS chunk when bit_depth is 8");
  178118. return;
  178119. }
  178120. png_write_chunk(png_ptr, png_tRNS, buf, (png_size_t)6);
  178121. }
  178122. else
  178123. {
  178124. png_warning(png_ptr, "Can't write tRNS with an alpha channel");
  178125. }
  178126. }
  178127. #endif
  178128. #if defined(PNG_WRITE_bKGD_SUPPORTED)
  178129. void /* PRIVATE */
  178130. png_write_bKGD(png_structp png_ptr, png_color_16p back, int color_type)
  178131. {
  178132. #ifdef PNG_USE_LOCAL_ARRAYS
  178133. PNG_bKGD;
  178134. #endif
  178135. png_byte buf[6];
  178136. png_debug(1, "in png_write_bKGD\n");
  178137. if (color_type == PNG_COLOR_TYPE_PALETTE)
  178138. {
  178139. if (
  178140. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  178141. (png_ptr->num_palette ||
  178142. (!(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE))) &&
  178143. #endif
  178144. back->index > png_ptr->num_palette)
  178145. {
  178146. png_warning(png_ptr, "Invalid background palette index");
  178147. return;
  178148. }
  178149. buf[0] = back->index;
  178150. png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)1);
  178151. }
  178152. else if (color_type & PNG_COLOR_MASK_COLOR)
  178153. {
  178154. png_save_uint_16(buf, back->red);
  178155. png_save_uint_16(buf + 2, back->green);
  178156. png_save_uint_16(buf + 4, back->blue);
  178157. if(png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
  178158. {
  178159. png_warning(png_ptr,
  178160. "Ignoring attempt to write 16-bit bKGD chunk when bit_depth is 8");
  178161. return;
  178162. }
  178163. png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)6);
  178164. }
  178165. else
  178166. {
  178167. if(back->gray >= (1 << png_ptr->bit_depth))
  178168. {
  178169. png_warning(png_ptr,
  178170. "Ignoring attempt to write bKGD chunk out-of-range for bit_depth");
  178171. return;
  178172. }
  178173. png_save_uint_16(buf, back->gray);
  178174. png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)2);
  178175. }
  178176. }
  178177. #endif
  178178. #if defined(PNG_WRITE_hIST_SUPPORTED)
  178179. void /* PRIVATE */
  178180. png_write_hIST(png_structp png_ptr, png_uint_16p hist, int num_hist)
  178181. {
  178182. #ifdef PNG_USE_LOCAL_ARRAYS
  178183. PNG_hIST;
  178184. #endif
  178185. int i;
  178186. png_byte buf[3];
  178187. png_debug(1, "in png_write_hIST\n");
  178188. if (num_hist > (int)png_ptr->num_palette)
  178189. {
  178190. png_debug2(3, "num_hist = %d, num_palette = %d\n", num_hist,
  178191. png_ptr->num_palette);
  178192. png_warning(png_ptr, "Invalid number of histogram entries specified");
  178193. return;
  178194. }
  178195. png_write_chunk_start(png_ptr, png_hIST, (png_uint_32)(num_hist * 2));
  178196. for (i = 0; i < num_hist; i++)
  178197. {
  178198. png_save_uint_16(buf, hist[i]);
  178199. png_write_chunk_data(png_ptr, buf, (png_size_t)2);
  178200. }
  178201. png_write_chunk_end(png_ptr);
  178202. }
  178203. #endif
  178204. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \
  178205. defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  178206. png_size_t /* PRIVATE */
  178207. png_check_keyword(png_structp png_ptr, png_charp key, png_charpp new_key)
  178208. {
  178209. png_size_t key_len;
  178210. png_charp kp, dp;
  178211. int kflag;
  178212. int kwarn=0;
  178213. png_debug(1, "in png_check_keyword\n");
  178214. *new_key = NULL;
  178215. if (key == NULL || (key_len = png_strlen(key)) == 0)
  178216. {
  178217. png_warning(png_ptr, "zero length keyword");
  178218. return ((png_size_t)0);
  178219. }
  178220. png_debug1(2, "Keyword to be checked is '%s'\n", key);
  178221. *new_key = (png_charp)png_malloc_warn(png_ptr, (png_uint_32)(key_len + 2));
  178222. if (*new_key == NULL)
  178223. {
  178224. png_warning(png_ptr, "Out of memory while procesing keyword");
  178225. return ((png_size_t)0);
  178226. }
  178227. for (kp = key, dp = *new_key; *kp != '\0'; kp++, dp++)
  178228. {
  178229. if ((png_byte)*kp < 0x20 ||
  178230. ((png_byte)*kp > 0x7E && (png_byte)*kp < 0xA1))
  178231. {
  178232. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  178233. char msg[40];
  178234. png_snprintf(msg, 40,
  178235. "invalid keyword character 0x%02X", (png_byte)*kp);
  178236. png_warning(png_ptr, msg);
  178237. #else
  178238. png_warning(png_ptr, "invalid character in keyword");
  178239. #endif
  178240. *dp = ' ';
  178241. }
  178242. else
  178243. {
  178244. *dp = *kp;
  178245. }
  178246. }
  178247. *dp = '\0';
  178248. kp = *new_key + key_len - 1;
  178249. if (*kp == ' ')
  178250. {
  178251. png_warning(png_ptr, "trailing spaces removed from keyword");
  178252. while (*kp == ' ')
  178253. {
  178254. *(kp--) = '\0';
  178255. key_len--;
  178256. }
  178257. }
  178258. kp = *new_key;
  178259. if (*kp == ' ')
  178260. {
  178261. png_warning(png_ptr, "leading spaces removed from keyword");
  178262. while (*kp == ' ')
  178263. {
  178264. kp++;
  178265. key_len--;
  178266. }
  178267. }
  178268. png_debug1(2, "Checking for multiple internal spaces in '%s'\n", kp);
  178269. for (kflag = 0, dp = *new_key; *kp != '\0'; kp++)
  178270. {
  178271. if (*kp == ' ' && kflag == 0)
  178272. {
  178273. *(dp++) = *kp;
  178274. kflag = 1;
  178275. }
  178276. else if (*kp == ' ')
  178277. {
  178278. key_len--;
  178279. kwarn=1;
  178280. }
  178281. else
  178282. {
  178283. *(dp++) = *kp;
  178284. kflag = 0;
  178285. }
  178286. }
  178287. *dp = '\0';
  178288. if(kwarn)
  178289. png_warning(png_ptr, "extra interior spaces removed from keyword");
  178290. if (key_len == 0)
  178291. {
  178292. png_free(png_ptr, *new_key);
  178293. *new_key=NULL;
  178294. png_warning(png_ptr, "Zero length keyword");
  178295. }
  178296. if (key_len > 79)
  178297. {
  178298. png_warning(png_ptr, "keyword length must be 1 - 79 characters");
  178299. new_key[79] = '\0';
  178300. key_len = 79;
  178301. }
  178302. return (key_len);
  178303. }
  178304. #endif
  178305. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  178306. void /* PRIVATE */
  178307. png_write_tEXt(png_structp png_ptr, png_charp key, png_charp text,
  178308. png_size_t text_len)
  178309. {
  178310. #ifdef PNG_USE_LOCAL_ARRAYS
  178311. PNG_tEXt;
  178312. #endif
  178313. png_size_t key_len;
  178314. png_charp new_key;
  178315. png_debug(1, "in png_write_tEXt\n");
  178316. if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
  178317. {
  178318. png_warning(png_ptr, "Empty keyword in tEXt chunk");
  178319. return;
  178320. }
  178321. if (text == NULL || *text == '\0')
  178322. text_len = 0;
  178323. else
  178324. text_len = png_strlen(text);
  178325. png_write_chunk_start(png_ptr, png_tEXt, (png_uint_32)key_len+text_len+1);
  178326. png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
  178327. if (text_len)
  178328. png_write_chunk_data(png_ptr, (png_bytep)text, text_len);
  178329. png_write_chunk_end(png_ptr);
  178330. png_free(png_ptr, new_key);
  178331. }
  178332. #endif
  178333. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  178334. void /* PRIVATE */
  178335. png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text,
  178336. png_size_t text_len, int compression)
  178337. {
  178338. #ifdef PNG_USE_LOCAL_ARRAYS
  178339. PNG_zTXt;
  178340. #endif
  178341. png_size_t key_len;
  178342. char buf[1];
  178343. png_charp new_key;
  178344. compression_state comp;
  178345. png_debug(1, "in png_write_zTXt\n");
  178346. comp.num_output_ptr = 0;
  178347. comp.max_output_ptr = 0;
  178348. comp.output_ptr = NULL;
  178349. comp.input = NULL;
  178350. comp.input_len = 0;
  178351. if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
  178352. {
  178353. png_warning(png_ptr, "Empty keyword in zTXt chunk");
  178354. return;
  178355. }
  178356. if (text == NULL || *text == '\0' || compression==PNG_TEXT_COMPRESSION_NONE)
  178357. {
  178358. png_write_tEXt(png_ptr, new_key, text, (png_size_t)0);
  178359. png_free(png_ptr, new_key);
  178360. return;
  178361. }
  178362. text_len = png_strlen(text);
  178363. text_len = png_text_compress(png_ptr, text, text_len, compression,
  178364. &comp);
  178365. png_write_chunk_start(png_ptr, png_zTXt, (png_uint_32)
  178366. (key_len+text_len+2));
  178367. png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
  178368. png_free(png_ptr, new_key);
  178369. buf[0] = (png_byte)compression;
  178370. png_write_chunk_data(png_ptr, (png_bytep)buf, (png_size_t)1);
  178371. png_write_compressed_data_out(png_ptr, &comp);
  178372. png_write_chunk_end(png_ptr);
  178373. }
  178374. #endif
  178375. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  178376. void /* PRIVATE */
  178377. png_write_iTXt(png_structp png_ptr, int compression, png_charp key,
  178378. png_charp lang, png_charp lang_key, png_charp text)
  178379. {
  178380. #ifdef PNG_USE_LOCAL_ARRAYS
  178381. PNG_iTXt;
  178382. #endif
  178383. png_size_t lang_len, key_len, lang_key_len, text_len;
  178384. png_charp new_lang, new_key;
  178385. png_byte cbuf[2];
  178386. compression_state comp;
  178387. png_debug(1, "in png_write_iTXt\n");
  178388. comp.num_output_ptr = 0;
  178389. comp.max_output_ptr = 0;
  178390. comp.output_ptr = NULL;
  178391. comp.input = NULL;
  178392. if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
  178393. {
  178394. png_warning(png_ptr, "Empty keyword in iTXt chunk");
  178395. return;
  178396. }
  178397. if (lang == NULL || (lang_len = png_check_keyword(png_ptr, lang, &new_lang))==0)
  178398. {
  178399. png_warning(png_ptr, "Empty language field in iTXt chunk");
  178400. new_lang = NULL;
  178401. lang_len = 0;
  178402. }
  178403. if (lang_key == NULL)
  178404. lang_key_len = 0;
  178405. else
  178406. lang_key_len = png_strlen(lang_key);
  178407. if (text == NULL)
  178408. text_len = 0;
  178409. else
  178410. text_len = png_strlen(text);
  178411. text_len = png_text_compress(png_ptr, text, text_len, compression-2,
  178412. &comp);
  178413. png_write_chunk_start(png_ptr, png_iTXt,
  178414. (png_uint_32)(
  178415. 5 /* comp byte, comp flag, terminators for key, lang and lang_key */
  178416. + key_len
  178417. + lang_len
  178418. + lang_key_len
  178419. + text_len));
  178420. png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
  178421. if (compression == PNG_ITXT_COMPRESSION_NONE || \
  178422. compression == PNG_TEXT_COMPRESSION_NONE)
  178423. cbuf[0] = 0;
  178424. else /* compression == PNG_ITXT_COMPRESSION_zTXt */
  178425. cbuf[0] = 1;
  178426. cbuf[1] = 0;
  178427. png_write_chunk_data(png_ptr, cbuf, 2);
  178428. cbuf[0] = 0;
  178429. png_write_chunk_data(png_ptr, (new_lang ? (png_bytep)new_lang : cbuf), lang_len + 1);
  178430. png_write_chunk_data(png_ptr, (lang_key ? (png_bytep)lang_key : cbuf), lang_key_len + 1);
  178431. png_write_compressed_data_out(png_ptr, &comp);
  178432. png_write_chunk_end(png_ptr);
  178433. png_free(png_ptr, new_key);
  178434. if (new_lang)
  178435. png_free(png_ptr, new_lang);
  178436. }
  178437. #endif
  178438. #if defined(PNG_WRITE_oFFs_SUPPORTED)
  178439. void /* PRIVATE */
  178440. png_write_oFFs(png_structp png_ptr, png_int_32 x_offset, png_int_32 y_offset,
  178441. int unit_type)
  178442. {
  178443. #ifdef PNG_USE_LOCAL_ARRAYS
  178444. PNG_oFFs;
  178445. #endif
  178446. png_byte buf[9];
  178447. png_debug(1, "in png_write_oFFs\n");
  178448. if (unit_type >= PNG_OFFSET_LAST)
  178449. png_warning(png_ptr, "Unrecognized unit type for oFFs chunk");
  178450. png_save_int_32(buf, x_offset);
  178451. png_save_int_32(buf + 4, y_offset);
  178452. buf[8] = (png_byte)unit_type;
  178453. png_write_chunk(png_ptr, png_oFFs, buf, (png_size_t)9);
  178454. }
  178455. #endif
  178456. #if defined(PNG_WRITE_pCAL_SUPPORTED)
  178457. void /* PRIVATE */
  178458. png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0,
  178459. png_int_32 X1, int type, int nparams, png_charp units, png_charpp params)
  178460. {
  178461. #ifdef PNG_USE_LOCAL_ARRAYS
  178462. PNG_pCAL;
  178463. #endif
  178464. png_size_t purpose_len, units_len, total_len;
  178465. png_uint_32p params_len;
  178466. png_byte buf[10];
  178467. png_charp new_purpose;
  178468. int i;
  178469. png_debug1(1, "in png_write_pCAL (%d parameters)\n", nparams);
  178470. if (type >= PNG_EQUATION_LAST)
  178471. png_warning(png_ptr, "Unrecognized equation type for pCAL chunk");
  178472. purpose_len = png_check_keyword(png_ptr, purpose, &new_purpose) + 1;
  178473. png_debug1(3, "pCAL purpose length = %d\n", (int)purpose_len);
  178474. units_len = png_strlen(units) + (nparams == 0 ? 0 : 1);
  178475. png_debug1(3, "pCAL units length = %d\n", (int)units_len);
  178476. total_len = purpose_len + units_len + 10;
  178477. params_len = (png_uint_32p)png_malloc(png_ptr, (png_uint_32)(nparams
  178478. *png_sizeof(png_uint_32)));
  178479. for (i = 0; i < nparams; i++)
  178480. {
  178481. params_len[i] = png_strlen(params[i]) + (i == nparams - 1 ? 0 : 1);
  178482. png_debug2(3, "pCAL parameter %d length = %lu\n", i, params_len[i]);
  178483. total_len += (png_size_t)params_len[i];
  178484. }
  178485. png_debug1(3, "pCAL total length = %d\n", (int)total_len);
  178486. png_write_chunk_start(png_ptr, png_pCAL, (png_uint_32)total_len);
  178487. png_write_chunk_data(png_ptr, (png_bytep)new_purpose, purpose_len);
  178488. png_save_int_32(buf, X0);
  178489. png_save_int_32(buf + 4, X1);
  178490. buf[8] = (png_byte)type;
  178491. buf[9] = (png_byte)nparams;
  178492. png_write_chunk_data(png_ptr, buf, (png_size_t)10);
  178493. png_write_chunk_data(png_ptr, (png_bytep)units, (png_size_t)units_len);
  178494. png_free(png_ptr, new_purpose);
  178495. for (i = 0; i < nparams; i++)
  178496. {
  178497. png_write_chunk_data(png_ptr, (png_bytep)params[i],
  178498. (png_size_t)params_len[i]);
  178499. }
  178500. png_free(png_ptr, params_len);
  178501. png_write_chunk_end(png_ptr);
  178502. }
  178503. #endif
  178504. #if defined(PNG_WRITE_sCAL_SUPPORTED)
  178505. #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
  178506. void /* PRIVATE */
  178507. png_write_sCAL(png_structp png_ptr, int unit, double width, double height)
  178508. {
  178509. #ifdef PNG_USE_LOCAL_ARRAYS
  178510. PNG_sCAL;
  178511. #endif
  178512. char buf[64];
  178513. png_size_t total_len;
  178514. png_debug(1, "in png_write_sCAL\n");
  178515. buf[0] = (char)unit;
  178516. #if defined(_WIN32_WCE)
  178517. {
  178518. wchar_t wc_buf[32];
  178519. size_t wc_len;
  178520. swprintf(wc_buf, TEXT("%12.12e"), width);
  178521. wc_len = wcslen(wc_buf);
  178522. WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, buf + 1, wc_len, NULL, NULL);
  178523. total_len = wc_len + 2;
  178524. swprintf(wc_buf, TEXT("%12.12e"), height);
  178525. wc_len = wcslen(wc_buf);
  178526. WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, buf + total_len, wc_len,
  178527. NULL, NULL);
  178528. total_len += wc_len;
  178529. }
  178530. #else
  178531. png_snprintf(buf + 1, 63, "%12.12e", width);
  178532. total_len = 1 + png_strlen(buf + 1) + 1;
  178533. png_snprintf(buf + total_len, 64-total_len, "%12.12e", height);
  178534. total_len += png_strlen(buf + total_len);
  178535. #endif
  178536. png_debug1(3, "sCAL total length = %u\n", (unsigned int)total_len);
  178537. png_write_chunk(png_ptr, png_sCAL, (png_bytep)buf, total_len);
  178538. }
  178539. #else
  178540. #ifdef PNG_FIXED_POINT_SUPPORTED
  178541. void /* PRIVATE */
  178542. png_write_sCAL_s(png_structp png_ptr, int unit, png_charp width,
  178543. png_charp height)
  178544. {
  178545. #ifdef PNG_USE_LOCAL_ARRAYS
  178546. PNG_sCAL;
  178547. #endif
  178548. png_byte buf[64];
  178549. png_size_t wlen, hlen, total_len;
  178550. png_debug(1, "in png_write_sCAL_s\n");
  178551. wlen = png_strlen(width);
  178552. hlen = png_strlen(height);
  178553. total_len = wlen + hlen + 2;
  178554. if (total_len > 64)
  178555. {
  178556. png_warning(png_ptr, "Can't write sCAL (buffer too small)");
  178557. return;
  178558. }
  178559. buf[0] = (png_byte)unit;
  178560. png_memcpy(buf + 1, width, wlen + 1); /* append the '\0' here */
  178561. png_memcpy(buf + wlen + 2, height, hlen); /* do NOT append the '\0' here */
  178562. png_debug1(3, "sCAL total length = %u\n", (unsigned int)total_len);
  178563. png_write_chunk(png_ptr, png_sCAL, buf, total_len);
  178564. }
  178565. #endif
  178566. #endif
  178567. #endif
  178568. #if defined(PNG_WRITE_pHYs_SUPPORTED)
  178569. void /* PRIVATE */
  178570. png_write_pHYs(png_structp png_ptr, png_uint_32 x_pixels_per_unit,
  178571. png_uint_32 y_pixels_per_unit,
  178572. int unit_type)
  178573. {
  178574. #ifdef PNG_USE_LOCAL_ARRAYS
  178575. PNG_pHYs;
  178576. #endif
  178577. png_byte buf[9];
  178578. png_debug(1, "in png_write_pHYs\n");
  178579. if (unit_type >= PNG_RESOLUTION_LAST)
  178580. png_warning(png_ptr, "Unrecognized unit type for pHYs chunk");
  178581. png_save_uint_32(buf, x_pixels_per_unit);
  178582. png_save_uint_32(buf + 4, y_pixels_per_unit);
  178583. buf[8] = (png_byte)unit_type;
  178584. png_write_chunk(png_ptr, png_pHYs, buf, (png_size_t)9);
  178585. }
  178586. #endif
  178587. #if defined(PNG_WRITE_tIME_SUPPORTED)
  178588. void /* PRIVATE */
  178589. png_write_tIME(png_structp png_ptr, png_timep mod_time)
  178590. {
  178591. #ifdef PNG_USE_LOCAL_ARRAYS
  178592. PNG_tIME;
  178593. #endif
  178594. png_byte buf[7];
  178595. png_debug(1, "in png_write_tIME\n");
  178596. if (mod_time->month > 12 || mod_time->month < 1 ||
  178597. mod_time->day > 31 || mod_time->day < 1 ||
  178598. mod_time->hour > 23 || mod_time->second > 60)
  178599. {
  178600. png_warning(png_ptr, "Invalid time specified for tIME chunk");
  178601. return;
  178602. }
  178603. png_save_uint_16(buf, mod_time->year);
  178604. buf[2] = mod_time->month;
  178605. buf[3] = mod_time->day;
  178606. buf[4] = mod_time->hour;
  178607. buf[5] = mod_time->minute;
  178608. buf[6] = mod_time->second;
  178609. png_write_chunk(png_ptr, png_tIME, buf, (png_size_t)7);
  178610. }
  178611. #endif
  178612. void /* PRIVATE */
  178613. png_write_start_row(png_structp png_ptr)
  178614. {
  178615. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178616. #ifdef PNG_USE_LOCAL_ARRAYS
  178617. int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  178618. int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  178619. int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  178620. int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  178621. #endif
  178622. #endif
  178623. png_size_t buf_size;
  178624. png_debug(1, "in png_write_start_row\n");
  178625. buf_size = (png_size_t)(PNG_ROWBYTES(
  178626. png_ptr->usr_channels*png_ptr->usr_bit_depth,png_ptr->width)+1);
  178627. png_ptr->row_buf = (png_bytep)png_malloc(png_ptr, (png_uint_32)buf_size);
  178628. png_ptr->row_buf[0] = PNG_FILTER_VALUE_NONE;
  178629. #ifndef PNG_NO_WRITE_FILTERING
  178630. if (png_ptr->do_filter & PNG_FILTER_SUB)
  178631. {
  178632. png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
  178633. (png_ptr->rowbytes + 1));
  178634. png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
  178635. }
  178636. if (png_ptr->do_filter & (PNG_FILTER_AVG | PNG_FILTER_UP | PNG_FILTER_PAETH))
  178637. {
  178638. png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)buf_size);
  178639. png_memset(png_ptr->prev_row, 0, buf_size);
  178640. if (png_ptr->do_filter & PNG_FILTER_UP)
  178641. {
  178642. png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
  178643. (png_ptr->rowbytes + 1));
  178644. png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
  178645. }
  178646. if (png_ptr->do_filter & PNG_FILTER_AVG)
  178647. {
  178648. png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
  178649. (png_ptr->rowbytes + 1));
  178650. png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
  178651. }
  178652. if (png_ptr->do_filter & PNG_FILTER_PAETH)
  178653. {
  178654. png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
  178655. (png_ptr->rowbytes + 1));
  178656. png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
  178657. }
  178658. #endif /* PNG_NO_WRITE_FILTERING */
  178659. }
  178660. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178661. if (png_ptr->interlaced)
  178662. {
  178663. if (!(png_ptr->transformations & PNG_INTERLACE))
  178664. {
  178665. png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
  178666. png_pass_ystart[0]) / png_pass_yinc[0];
  178667. png_ptr->usr_width = (png_ptr->width + png_pass_inc[0] - 1 -
  178668. png_pass_start[0]) / png_pass_inc[0];
  178669. }
  178670. else
  178671. {
  178672. png_ptr->num_rows = png_ptr->height;
  178673. png_ptr->usr_width = png_ptr->width;
  178674. }
  178675. }
  178676. else
  178677. #endif
  178678. {
  178679. png_ptr->num_rows = png_ptr->height;
  178680. png_ptr->usr_width = png_ptr->width;
  178681. }
  178682. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  178683. png_ptr->zstream.next_out = png_ptr->zbuf;
  178684. }
  178685. void /* PRIVATE */
  178686. png_write_finish_row(png_structp png_ptr)
  178687. {
  178688. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178689. #ifdef PNG_USE_LOCAL_ARRAYS
  178690. int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  178691. int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  178692. int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  178693. int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  178694. #endif
  178695. #endif
  178696. int ret;
  178697. png_debug(1, "in png_write_finish_row\n");
  178698. png_ptr->row_number++;
  178699. if (png_ptr->row_number < png_ptr->num_rows)
  178700. return;
  178701. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178702. if (png_ptr->interlaced)
  178703. {
  178704. png_ptr->row_number = 0;
  178705. if (png_ptr->transformations & PNG_INTERLACE)
  178706. {
  178707. png_ptr->pass++;
  178708. }
  178709. else
  178710. {
  178711. do
  178712. {
  178713. png_ptr->pass++;
  178714. if (png_ptr->pass >= 7)
  178715. break;
  178716. png_ptr->usr_width = (png_ptr->width +
  178717. png_pass_inc[png_ptr->pass] - 1 -
  178718. png_pass_start[png_ptr->pass]) /
  178719. png_pass_inc[png_ptr->pass];
  178720. png_ptr->num_rows = (png_ptr->height +
  178721. png_pass_yinc[png_ptr->pass] - 1 -
  178722. png_pass_ystart[png_ptr->pass]) /
  178723. png_pass_yinc[png_ptr->pass];
  178724. if (png_ptr->transformations & PNG_INTERLACE)
  178725. break;
  178726. } while (png_ptr->usr_width == 0 || png_ptr->num_rows == 0);
  178727. }
  178728. if (png_ptr->pass < 7)
  178729. {
  178730. if (png_ptr->prev_row != NULL)
  178731. png_memset(png_ptr->prev_row, 0,
  178732. (png_size_t)(PNG_ROWBYTES(png_ptr->usr_channels*
  178733. png_ptr->usr_bit_depth,png_ptr->width))+1);
  178734. return;
  178735. }
  178736. }
  178737. #endif
  178738. do
  178739. {
  178740. ret = deflate(&png_ptr->zstream, Z_FINISH);
  178741. if (ret == Z_OK)
  178742. {
  178743. if (!(png_ptr->zstream.avail_out))
  178744. {
  178745. png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
  178746. png_ptr->zstream.next_out = png_ptr->zbuf;
  178747. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  178748. }
  178749. }
  178750. else if (ret != Z_STREAM_END)
  178751. {
  178752. if (png_ptr->zstream.msg != NULL)
  178753. png_error(png_ptr, png_ptr->zstream.msg);
  178754. else
  178755. png_error(png_ptr, "zlib error");
  178756. }
  178757. } while (ret != Z_STREAM_END);
  178758. if (png_ptr->zstream.avail_out < png_ptr->zbuf_size)
  178759. {
  178760. png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size -
  178761. png_ptr->zstream.avail_out);
  178762. }
  178763. deflateReset(&png_ptr->zstream);
  178764. png_ptr->zstream.data_type = Z_BINARY;
  178765. }
  178766. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  178767. void /* PRIVATE */
  178768. png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
  178769. {
  178770. #ifdef PNG_USE_LOCAL_ARRAYS
  178771. int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  178772. int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  178773. #endif
  178774. png_debug(1, "in png_do_write_interlace\n");
  178775. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  178776. if (row != NULL && row_info != NULL && pass < 6)
  178777. #else
  178778. if (pass < 6)
  178779. #endif
  178780. {
  178781. switch (row_info->pixel_depth)
  178782. {
  178783. case 1:
  178784. {
  178785. png_bytep sp;
  178786. png_bytep dp;
  178787. int shift;
  178788. int d;
  178789. int value;
  178790. png_uint_32 i;
  178791. png_uint_32 row_width = row_info->width;
  178792. dp = row;
  178793. d = 0;
  178794. shift = 7;
  178795. for (i = png_pass_start[pass]; i < row_width;
  178796. i += png_pass_inc[pass])
  178797. {
  178798. sp = row + (png_size_t)(i >> 3);
  178799. value = (int)(*sp >> (7 - (int)(i & 0x07))) & 0x01;
  178800. d |= (value << shift);
  178801. if (shift == 0)
  178802. {
  178803. shift = 7;
  178804. *dp++ = (png_byte)d;
  178805. d = 0;
  178806. }
  178807. else
  178808. shift--;
  178809. }
  178810. if (shift != 7)
  178811. *dp = (png_byte)d;
  178812. break;
  178813. }
  178814. case 2:
  178815. {
  178816. png_bytep sp;
  178817. png_bytep dp;
  178818. int shift;
  178819. int d;
  178820. int value;
  178821. png_uint_32 i;
  178822. png_uint_32 row_width = row_info->width;
  178823. dp = row;
  178824. shift = 6;
  178825. d = 0;
  178826. for (i = png_pass_start[pass]; i < row_width;
  178827. i += png_pass_inc[pass])
  178828. {
  178829. sp = row + (png_size_t)(i >> 2);
  178830. value = (*sp >> ((3 - (int)(i & 0x03)) << 1)) & 0x03;
  178831. d |= (value << shift);
  178832. if (shift == 0)
  178833. {
  178834. shift = 6;
  178835. *dp++ = (png_byte)d;
  178836. d = 0;
  178837. }
  178838. else
  178839. shift -= 2;
  178840. }
  178841. if (shift != 6)
  178842. *dp = (png_byte)d;
  178843. break;
  178844. }
  178845. case 4:
  178846. {
  178847. png_bytep sp;
  178848. png_bytep dp;
  178849. int shift;
  178850. int d;
  178851. int value;
  178852. png_uint_32 i;
  178853. png_uint_32 row_width = row_info->width;
  178854. dp = row;
  178855. shift = 4;
  178856. d = 0;
  178857. for (i = png_pass_start[pass]; i < row_width;
  178858. i += png_pass_inc[pass])
  178859. {
  178860. sp = row + (png_size_t)(i >> 1);
  178861. value = (*sp >> ((1 - (int)(i & 0x01)) << 2)) & 0x0f;
  178862. d |= (value << shift);
  178863. if (shift == 0)
  178864. {
  178865. shift = 4;
  178866. *dp++ = (png_byte)d;
  178867. d = 0;
  178868. }
  178869. else
  178870. shift -= 4;
  178871. }
  178872. if (shift != 4)
  178873. *dp = (png_byte)d;
  178874. break;
  178875. }
  178876. default:
  178877. {
  178878. png_bytep sp;
  178879. png_bytep dp;
  178880. png_uint_32 i;
  178881. png_uint_32 row_width = row_info->width;
  178882. png_size_t pixel_bytes;
  178883. dp = row;
  178884. pixel_bytes = (row_info->pixel_depth >> 3);
  178885. for (i = png_pass_start[pass]; i < row_width;
  178886. i += png_pass_inc[pass])
  178887. {
  178888. sp = row + (png_size_t)i * pixel_bytes;
  178889. if (dp != sp)
  178890. png_memcpy(dp, sp, pixel_bytes);
  178891. dp += pixel_bytes;
  178892. }
  178893. break;
  178894. }
  178895. }
  178896. row_info->width = (row_info->width +
  178897. png_pass_inc[pass] - 1 -
  178898. png_pass_start[pass]) /
  178899. png_pass_inc[pass];
  178900. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
  178901. row_info->width);
  178902. }
  178903. }
  178904. #endif
  178905. #define PNG_MAXSUM (((png_uint_32)(-1)) >> 1)
  178906. #define PNG_HISHIFT 10
  178907. #define PNG_LOMASK ((png_uint_32)0xffffL)
  178908. #define PNG_HIMASK ((png_uint_32)(~PNG_LOMASK >> PNG_HISHIFT))
  178909. void /* PRIVATE */
  178910. png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
  178911. {
  178912. png_bytep best_row;
  178913. #ifndef PNG_NO_WRITE_FILTER
  178914. png_bytep prev_row, row_buf;
  178915. png_uint_32 mins, bpp;
  178916. png_byte filter_to_do = png_ptr->do_filter;
  178917. png_uint_32 row_bytes = row_info->rowbytes;
  178918. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178919. int num_p_filters = (int)png_ptr->num_prev_filters;
  178920. #endif
  178921. png_debug(1, "in png_write_find_filter\n");
  178922. bpp = (row_info->pixel_depth + 7) >> 3;
  178923. prev_row = png_ptr->prev_row;
  178924. #endif
  178925. best_row = png_ptr->row_buf;
  178926. #ifndef PNG_NO_WRITE_FILTER
  178927. row_buf = best_row;
  178928. mins = PNG_MAXSUM;
  178929. if ((filter_to_do & PNG_FILTER_NONE) &&
  178930. filter_to_do != PNG_FILTER_NONE)
  178931. {
  178932. png_bytep rp;
  178933. png_uint_32 sum = 0;
  178934. png_uint_32 i;
  178935. int v;
  178936. for (i = 0, rp = row_buf + 1; i < row_bytes; i++, rp++)
  178937. {
  178938. v = *rp;
  178939. sum += (v < 128) ? v : 256 - v;
  178940. }
  178941. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178942. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178943. {
  178944. png_uint_32 sumhi, sumlo;
  178945. int j;
  178946. sumlo = sum & PNG_LOMASK;
  178947. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK; /* Gives us some footroom */
  178948. for (j = 0; j < num_p_filters; j++)
  178949. {
  178950. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE)
  178951. {
  178952. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  178953. PNG_WEIGHT_SHIFT;
  178954. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  178955. PNG_WEIGHT_SHIFT;
  178956. }
  178957. }
  178958. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >>
  178959. PNG_COST_SHIFT;
  178960. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >>
  178961. PNG_COST_SHIFT;
  178962. if (sumhi > PNG_HIMASK)
  178963. sum = PNG_MAXSUM;
  178964. else
  178965. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178966. }
  178967. #endif
  178968. mins = sum;
  178969. }
  178970. if (filter_to_do == PNG_FILTER_SUB)
  178971. {
  178972. png_bytep rp, lp, dp;
  178973. png_uint_32 i;
  178974. for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp;
  178975. i++, rp++, dp++)
  178976. {
  178977. *dp = *rp;
  178978. }
  178979. for (lp = row_buf + 1; i < row_bytes;
  178980. i++, rp++, lp++, dp++)
  178981. {
  178982. *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff);
  178983. }
  178984. best_row = png_ptr->sub_row;
  178985. }
  178986. else if (filter_to_do & PNG_FILTER_SUB)
  178987. {
  178988. png_bytep rp, dp, lp;
  178989. png_uint_32 sum = 0, lmins = mins;
  178990. png_uint_32 i;
  178991. int v;
  178992. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178993. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178994. {
  178995. int j;
  178996. png_uint_32 lmhi, lmlo;
  178997. lmlo = lmins & PNG_LOMASK;
  178998. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  178999. for (j = 0; j < num_p_filters; j++)
  179000. {
  179001. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB)
  179002. {
  179003. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  179004. PNG_WEIGHT_SHIFT;
  179005. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  179006. PNG_WEIGHT_SHIFT;
  179007. }
  179008. }
  179009. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  179010. PNG_COST_SHIFT;
  179011. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  179012. PNG_COST_SHIFT;
  179013. if (lmhi > PNG_HIMASK)
  179014. lmins = PNG_MAXSUM;
  179015. else
  179016. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  179017. }
  179018. #endif
  179019. for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp;
  179020. i++, rp++, dp++)
  179021. {
  179022. v = *dp = *rp;
  179023. sum += (v < 128) ? v : 256 - v;
  179024. }
  179025. for (lp = row_buf + 1; i < row_bytes;
  179026. i++, rp++, lp++, dp++)
  179027. {
  179028. v = *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff);
  179029. sum += (v < 128) ? v : 256 - v;
  179030. if (sum > lmins) /* We are already worse, don't continue. */
  179031. break;
  179032. }
  179033. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179034. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  179035. {
  179036. int j;
  179037. png_uint_32 sumhi, sumlo;
  179038. sumlo = sum & PNG_LOMASK;
  179039. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  179040. for (j = 0; j < num_p_filters; j++)
  179041. {
  179042. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB)
  179043. {
  179044. sumlo = (sumlo * png_ptr->inv_filter_weights[j]) >>
  179045. PNG_WEIGHT_SHIFT;
  179046. sumhi = (sumhi * png_ptr->inv_filter_weights[j]) >>
  179047. PNG_WEIGHT_SHIFT;
  179048. }
  179049. }
  179050. sumlo = (sumlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  179051. PNG_COST_SHIFT;
  179052. sumhi = (sumhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  179053. PNG_COST_SHIFT;
  179054. if (sumhi > PNG_HIMASK)
  179055. sum = PNG_MAXSUM;
  179056. else
  179057. sum = (sumhi << PNG_HISHIFT) + sumlo;
  179058. }
  179059. #endif
  179060. if (sum < mins)
  179061. {
  179062. mins = sum;
  179063. best_row = png_ptr->sub_row;
  179064. }
  179065. }
  179066. if (filter_to_do == PNG_FILTER_UP)
  179067. {
  179068. png_bytep rp, dp, pp;
  179069. png_uint_32 i;
  179070. for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
  179071. pp = prev_row + 1; i < row_bytes;
  179072. i++, rp++, pp++, dp++)
  179073. {
  179074. *dp = (png_byte)(((int)*rp - (int)*pp) & 0xff);
  179075. }
  179076. best_row = png_ptr->up_row;
  179077. }
  179078. else if (filter_to_do & PNG_FILTER_UP)
  179079. {
  179080. png_bytep rp, dp, pp;
  179081. png_uint_32 sum = 0, lmins = mins;
  179082. png_uint_32 i;
  179083. int v;
  179084. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179085. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  179086. {
  179087. int j;
  179088. png_uint_32 lmhi, lmlo;
  179089. lmlo = lmins & PNG_LOMASK;
  179090. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  179091. for (j = 0; j < num_p_filters; j++)
  179092. {
  179093. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP)
  179094. {
  179095. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  179096. PNG_WEIGHT_SHIFT;
  179097. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  179098. PNG_WEIGHT_SHIFT;
  179099. }
  179100. }
  179101. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >>
  179102. PNG_COST_SHIFT;
  179103. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >>
  179104. PNG_COST_SHIFT;
  179105. if (lmhi > PNG_HIMASK)
  179106. lmins = PNG_MAXSUM;
  179107. else
  179108. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  179109. }
  179110. #endif
  179111. for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
  179112. pp = prev_row + 1; i < row_bytes; i++)
  179113. {
  179114. v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
  179115. sum += (v < 128) ? v : 256 - v;
  179116. if (sum > lmins) /* We are already worse, don't continue. */
  179117. break;
  179118. }
  179119. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179120. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  179121. {
  179122. int j;
  179123. png_uint_32 sumhi, sumlo;
  179124. sumlo = sum & PNG_LOMASK;
  179125. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  179126. for (j = 0; j < num_p_filters; j++)
  179127. {
  179128. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP)
  179129. {
  179130. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  179131. PNG_WEIGHT_SHIFT;
  179132. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  179133. PNG_WEIGHT_SHIFT;
  179134. }
  179135. }
  179136. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >>
  179137. PNG_COST_SHIFT;
  179138. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >>
  179139. PNG_COST_SHIFT;
  179140. if (sumhi > PNG_HIMASK)
  179141. sum = PNG_MAXSUM;
  179142. else
  179143. sum = (sumhi << PNG_HISHIFT) + sumlo;
  179144. }
  179145. #endif
  179146. if (sum < mins)
  179147. {
  179148. mins = sum;
  179149. best_row = png_ptr->up_row;
  179150. }
  179151. }
  179152. if (filter_to_do == PNG_FILTER_AVG)
  179153. {
  179154. png_bytep rp, dp, pp, lp;
  179155. png_uint_32 i;
  179156. for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1,
  179157. pp = prev_row + 1; i < bpp; i++)
  179158. {
  179159. *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff);
  179160. }
  179161. for (lp = row_buf + 1; i < row_bytes; i++)
  179162. {
  179163. *dp++ = (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2))
  179164. & 0xff);
  179165. }
  179166. best_row = png_ptr->avg_row;
  179167. }
  179168. else if (filter_to_do & PNG_FILTER_AVG)
  179169. {
  179170. png_bytep rp, dp, pp, lp;
  179171. png_uint_32 sum = 0, lmins = mins;
  179172. png_uint_32 i;
  179173. int v;
  179174. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179175. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  179176. {
  179177. int j;
  179178. png_uint_32 lmhi, lmlo;
  179179. lmlo = lmins & PNG_LOMASK;
  179180. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  179181. for (j = 0; j < num_p_filters; j++)
  179182. {
  179183. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_AVG)
  179184. {
  179185. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  179186. PNG_WEIGHT_SHIFT;
  179187. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  179188. PNG_WEIGHT_SHIFT;
  179189. }
  179190. }
  179191. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >>
  179192. PNG_COST_SHIFT;
  179193. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >>
  179194. PNG_COST_SHIFT;
  179195. if (lmhi > PNG_HIMASK)
  179196. lmins = PNG_MAXSUM;
  179197. else
  179198. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  179199. }
  179200. #endif
  179201. for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1,
  179202. pp = prev_row + 1; i < bpp; i++)
  179203. {
  179204. v = *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff);
  179205. sum += (v < 128) ? v : 256 - v;
  179206. }
  179207. for (lp = row_buf + 1; i < row_bytes; i++)
  179208. {
  179209. v = *dp++ =
  179210. (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2)) & 0xff);
  179211. sum += (v < 128) ? v : 256 - v;
  179212. if (sum > lmins) /* We are already worse, don't continue. */
  179213. break;
  179214. }
  179215. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179216. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  179217. {
  179218. int j;
  179219. png_uint_32 sumhi, sumlo;
  179220. sumlo = sum & PNG_LOMASK;
  179221. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  179222. for (j = 0; j < num_p_filters; j++)
  179223. {
  179224. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE)
  179225. {
  179226. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  179227. PNG_WEIGHT_SHIFT;
  179228. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  179229. PNG_WEIGHT_SHIFT;
  179230. }
  179231. }
  179232. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >>
  179233. PNG_COST_SHIFT;
  179234. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >>
  179235. PNG_COST_SHIFT;
  179236. if (sumhi > PNG_HIMASK)
  179237. sum = PNG_MAXSUM;
  179238. else
  179239. sum = (sumhi << PNG_HISHIFT) + sumlo;
  179240. }
  179241. #endif
  179242. if (sum < mins)
  179243. {
  179244. mins = sum;
  179245. best_row = png_ptr->avg_row;
  179246. }
  179247. }
  179248. if (filter_to_do == PNG_FILTER_PAETH)
  179249. {
  179250. png_bytep rp, dp, pp, cp, lp;
  179251. png_uint_32 i;
  179252. for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
  179253. pp = prev_row + 1; i < bpp; i++)
  179254. {
  179255. *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
  179256. }
  179257. for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++)
  179258. {
  179259. int a, b, c, pa, pb, pc, p;
  179260. b = *pp++;
  179261. c = *cp++;
  179262. a = *lp++;
  179263. p = b - c;
  179264. pc = a - c;
  179265. #ifdef PNG_USE_ABS
  179266. pa = abs(p);
  179267. pb = abs(pc);
  179268. pc = abs(p + pc);
  179269. #else
  179270. pa = p < 0 ? -p : p;
  179271. pb = pc < 0 ? -pc : pc;
  179272. pc = (p + pc) < 0 ? -(p + pc) : p + pc;
  179273. #endif
  179274. p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
  179275. *dp++ = (png_byte)(((int)*rp++ - p) & 0xff);
  179276. }
  179277. best_row = png_ptr->paeth_row;
  179278. }
  179279. else if (filter_to_do & PNG_FILTER_PAETH)
  179280. {
  179281. png_bytep rp, dp, pp, cp, lp;
  179282. png_uint_32 sum = 0, lmins = mins;
  179283. png_uint_32 i;
  179284. int v;
  179285. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179286. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  179287. {
  179288. int j;
  179289. png_uint_32 lmhi, lmlo;
  179290. lmlo = lmins & PNG_LOMASK;
  179291. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  179292. for (j = 0; j < num_p_filters; j++)
  179293. {
  179294. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH)
  179295. {
  179296. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  179297. PNG_WEIGHT_SHIFT;
  179298. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  179299. PNG_WEIGHT_SHIFT;
  179300. }
  179301. }
  179302. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  179303. PNG_COST_SHIFT;
  179304. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  179305. PNG_COST_SHIFT;
  179306. if (lmhi > PNG_HIMASK)
  179307. lmins = PNG_MAXSUM;
  179308. else
  179309. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  179310. }
  179311. #endif
  179312. for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
  179313. pp = prev_row + 1; i < bpp; i++)
  179314. {
  179315. v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
  179316. sum += (v < 128) ? v : 256 - v;
  179317. }
  179318. for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++)
  179319. {
  179320. int a, b, c, pa, pb, pc, p;
  179321. b = *pp++;
  179322. c = *cp++;
  179323. a = *lp++;
  179324. #ifndef PNG_SLOW_PAETH
  179325. p = b - c;
  179326. pc = a - c;
  179327. #ifdef PNG_USE_ABS
  179328. pa = abs(p);
  179329. pb = abs(pc);
  179330. pc = abs(p + pc);
  179331. #else
  179332. pa = p < 0 ? -p : p;
  179333. pb = pc < 0 ? -pc : pc;
  179334. pc = (p + pc) < 0 ? -(p + pc) : p + pc;
  179335. #endif
  179336. p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
  179337. #else /* PNG_SLOW_PAETH */
  179338. p = a + b - c;
  179339. pa = abs(p - a);
  179340. pb = abs(p - b);
  179341. pc = abs(p - c);
  179342. if (pa <= pb && pa <= pc)
  179343. p = a;
  179344. else if (pb <= pc)
  179345. p = b;
  179346. else
  179347. p = c;
  179348. #endif /* PNG_SLOW_PAETH */
  179349. v = *dp++ = (png_byte)(((int)*rp++ - p) & 0xff);
  179350. sum += (v < 128) ? v : 256 - v;
  179351. if (sum > lmins) /* We are already worse, don't continue. */
  179352. break;
  179353. }
  179354. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179355. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  179356. {
  179357. int j;
  179358. png_uint_32 sumhi, sumlo;
  179359. sumlo = sum & PNG_LOMASK;
  179360. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  179361. for (j = 0; j < num_p_filters; j++)
  179362. {
  179363. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH)
  179364. {
  179365. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  179366. PNG_WEIGHT_SHIFT;
  179367. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  179368. PNG_WEIGHT_SHIFT;
  179369. }
  179370. }
  179371. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  179372. PNG_COST_SHIFT;
  179373. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  179374. PNG_COST_SHIFT;
  179375. if (sumhi > PNG_HIMASK)
  179376. sum = PNG_MAXSUM;
  179377. else
  179378. sum = (sumhi << PNG_HISHIFT) + sumlo;
  179379. }
  179380. #endif
  179381. if (sum < mins)
  179382. {
  179383. best_row = png_ptr->paeth_row;
  179384. }
  179385. }
  179386. #endif /* PNG_NO_WRITE_FILTER */
  179387. png_write_filtered_row(png_ptr, best_row);
  179388. #ifndef PNG_NO_WRITE_FILTER
  179389. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179390. if (png_ptr->num_prev_filters > 0)
  179391. {
  179392. int j;
  179393. for (j = 1; j < num_p_filters; j++)
  179394. {
  179395. png_ptr->prev_filters[j] = png_ptr->prev_filters[j - 1];
  179396. }
  179397. png_ptr->prev_filters[j] = best_row[0];
  179398. }
  179399. #endif
  179400. #endif /* PNG_NO_WRITE_FILTER */
  179401. }
  179402. void /* PRIVATE */
  179403. png_write_filtered_row(png_structp png_ptr, png_bytep filtered_row)
  179404. {
  179405. png_debug(1, "in png_write_filtered_row\n");
  179406. png_debug1(2, "filter = %d\n", filtered_row[0]);
  179407. png_ptr->zstream.next_in = filtered_row;
  179408. png_ptr->zstream.avail_in = (uInt)png_ptr->row_info.rowbytes + 1;
  179409. do
  179410. {
  179411. int ret; /* return of zlib */
  179412. ret = deflate(&png_ptr->zstream, Z_NO_FLUSH);
  179413. if (ret != Z_OK)
  179414. {
  179415. if (png_ptr->zstream.msg != NULL)
  179416. png_error(png_ptr, png_ptr->zstream.msg);
  179417. else
  179418. png_error(png_ptr, "zlib error");
  179419. }
  179420. if (!(png_ptr->zstream.avail_out))
  179421. {
  179422. png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
  179423. png_ptr->zstream.next_out = png_ptr->zbuf;
  179424. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  179425. }
  179426. } while (png_ptr->zstream.avail_in);
  179427. if (png_ptr->prev_row != NULL)
  179428. {
  179429. png_bytep tptr;
  179430. tptr = png_ptr->prev_row;
  179431. png_ptr->prev_row = png_ptr->row_buf;
  179432. png_ptr->row_buf = tptr;
  179433. }
  179434. png_write_finish_row(png_ptr);
  179435. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  179436. png_ptr->flush_rows++;
  179437. if (png_ptr->flush_dist > 0 &&
  179438. png_ptr->flush_rows >= png_ptr->flush_dist)
  179439. {
  179440. png_write_flush(png_ptr);
  179441. }
  179442. #endif
  179443. }
  179444. #endif /* PNG_WRITE_SUPPORTED */
  179445. /*** End of inlined file: pngwutil.c ***/
  179446. }
  179447. #else
  179448. #define PNG_INTERNAL
  179449. #define PNG_SETJMP_NOT_SUPPORTED
  179450. #include <png.h>
  179451. #include <pngconf.h>
  179452. #endif
  179453. }
  179454. #ifdef _MSC_VER
  179455. #pragma warning (pop)
  179456. #endif
  179457. BEGIN_JUCE_NAMESPACE
  179458. using namespace pnglibNamespace;
  179459. using ::calloc;
  179460. using ::malloc;
  179461. using ::free;
  179462. static void pngReadCallback (png_structp pngReadStruct, png_bytep data, png_size_t length)
  179463. {
  179464. InputStream* const in = (InputStream*) png_get_io_ptr (pngReadStruct);
  179465. in->read (data, (int) length);
  179466. }
  179467. struct PNGErrorStruct {};
  179468. static void pngErrorCallback (png_structp, png_const_charp)
  179469. {
  179470. throw PNGErrorStruct();
  179471. }
  179472. Image* juce_loadPNGImageFromStream (InputStream& in)
  179473. {
  179474. Image* image = 0;
  179475. png_structp pngReadStruct;
  179476. png_infop pngInfoStruct;
  179477. pngReadStruct = png_create_read_struct (PNG_LIBPNG_VER_STRING, 0, 0, 0);
  179478. if (pngReadStruct != 0)
  179479. {
  179480. pngInfoStruct = png_create_info_struct (pngReadStruct);
  179481. if (pngInfoStruct == 0)
  179482. {
  179483. png_destroy_read_struct (&pngReadStruct, 0, 0);
  179484. return 0;
  179485. }
  179486. png_set_error_fn (pngReadStruct, 0, pngErrorCallback, pngErrorCallback);
  179487. // read the header..
  179488. png_set_read_fn (pngReadStruct, &in, pngReadCallback);
  179489. png_uint_32 width, height;
  179490. int bitDepth, colorType, interlaceType;
  179491. png_read_info (pngReadStruct, pngInfoStruct);
  179492. png_get_IHDR (pngReadStruct, pngInfoStruct,
  179493. &width, &height,
  179494. &bitDepth, &colorType,
  179495. &interlaceType, 0, 0);
  179496. if (bitDepth == 16)
  179497. png_set_strip_16 (pngReadStruct);
  179498. if (colorType == PNG_COLOR_TYPE_PALETTE)
  179499. png_set_expand (pngReadStruct);
  179500. if (bitDepth < 8)
  179501. png_set_expand (pngReadStruct);
  179502. if (png_get_valid (pngReadStruct, pngInfoStruct, PNG_INFO_tRNS))
  179503. png_set_expand (pngReadStruct);
  179504. if (colorType == PNG_COLOR_TYPE_GRAY || colorType == PNG_COLOR_TYPE_GRAY_ALPHA)
  179505. png_set_gray_to_rgb (pngReadStruct);
  179506. png_set_add_alpha (pngReadStruct, 0xff, PNG_FILLER_AFTER);
  179507. bool hasAlphaChan = (colorType & PNG_COLOR_MASK_ALPHA) != 0
  179508. || pngInfoStruct->num_trans > 0;
  179509. // Load the image into a temp buffer in the pnglib format..
  179510. HeapBlock <uint8> tempBuffer (height * (width << 2));
  179511. {
  179512. HeapBlock <png_bytep> rows (height);
  179513. for (int y = (int) height; --y >= 0;)
  179514. rows[y] = (png_bytep) (tempBuffer + (width << 2) * y);
  179515. png_read_image (pngReadStruct, rows);
  179516. png_read_end (pngReadStruct, pngInfoStruct);
  179517. }
  179518. png_destroy_read_struct (&pngReadStruct, &pngInfoStruct, 0);
  179519. // now convert the data to a juce image format..
  179520. image = Image::createNativeImage (hasAlphaChan ? Image::ARGB : Image::RGB,
  179521. (int) width, (int) height, hasAlphaChan);
  179522. hasAlphaChan = image->hasAlphaChannel(); // (the native image creator may not give back what we expect)
  179523. const Image::BitmapData destData (*image, 0, 0, (int) width, (int) height, true);
  179524. uint8* srcRow = tempBuffer;
  179525. uint8* destRow = destData.data;
  179526. for (int y = 0; y < (int) height; ++y)
  179527. {
  179528. const uint8* src = srcRow;
  179529. srcRow += (width << 2);
  179530. uint8* dest = destRow;
  179531. destRow += destData.lineStride;
  179532. if (hasAlphaChan)
  179533. {
  179534. for (int i = (int) width; --i >= 0;)
  179535. {
  179536. ((PixelARGB*) dest)->setARGB (src[3], src[0], src[1], src[2]);
  179537. ((PixelARGB*) dest)->premultiply();
  179538. dest += destData.pixelStride;
  179539. src += 4;
  179540. }
  179541. }
  179542. else
  179543. {
  179544. for (int i = (int) width; --i >= 0;)
  179545. {
  179546. ((PixelRGB*) dest)->setARGB (0, src[0], src[1], src[2]);
  179547. dest += destData.pixelStride;
  179548. src += 4;
  179549. }
  179550. }
  179551. }
  179552. }
  179553. return image;
  179554. }
  179555. static void pngWriteDataCallback (png_structp png_ptr, png_bytep data, png_size_t length)
  179556. {
  179557. OutputStream* const out = (OutputStream*) png_ptr->io_ptr;
  179558. const bool ok = out->write (data, (int) length);
  179559. (void) ok;
  179560. jassert (ok);
  179561. }
  179562. bool juce_writePNGImageToStream (const Image& image, OutputStream& out)
  179563. {
  179564. const int width = image.getWidth();
  179565. const int height = image.getHeight();
  179566. png_structp pngWriteStruct = png_create_write_struct (PNG_LIBPNG_VER_STRING, 0, 0, 0);
  179567. if (pngWriteStruct == 0)
  179568. return false;
  179569. png_infop pngInfoStruct = png_create_info_struct (pngWriteStruct);
  179570. if (pngInfoStruct == 0)
  179571. {
  179572. png_destroy_write_struct (&pngWriteStruct, (png_infopp) 0);
  179573. return false;
  179574. }
  179575. png_set_write_fn (pngWriteStruct, &out, pngWriteDataCallback, 0);
  179576. png_set_IHDR (pngWriteStruct, pngInfoStruct, width, height, 8,
  179577. image.hasAlphaChannel() ? PNG_COLOR_TYPE_RGB_ALPHA
  179578. : PNG_COLOR_TYPE_RGB,
  179579. PNG_INTERLACE_NONE,
  179580. PNG_COMPRESSION_TYPE_BASE,
  179581. PNG_FILTER_TYPE_BASE);
  179582. HeapBlock <png_byte> rowData (width * 4);
  179583. png_color_8 sig_bit;
  179584. sig_bit.red = 8;
  179585. sig_bit.green = 8;
  179586. sig_bit.blue = 8;
  179587. sig_bit.alpha = 8;
  179588. png_set_sBIT (pngWriteStruct, pngInfoStruct, &sig_bit);
  179589. png_write_info (pngWriteStruct, pngInfoStruct);
  179590. png_set_shift (pngWriteStruct, &sig_bit);
  179591. png_set_packing (pngWriteStruct);
  179592. const Image::BitmapData srcData (image, 0, 0, width, height);
  179593. for (int y = 0; y < height; ++y)
  179594. {
  179595. uint8* dst = (uint8*) rowData;
  179596. const uint8* src = srcData.getLinePointer (y);
  179597. if (image.hasAlphaChannel())
  179598. {
  179599. for (int i = width; --i >= 0;)
  179600. {
  179601. PixelARGB p (*(const PixelARGB*) src);
  179602. p.unpremultiply();
  179603. *dst++ = p.getRed();
  179604. *dst++ = p.getGreen();
  179605. *dst++ = p.getBlue();
  179606. *dst++ = p.getAlpha();
  179607. src += srcData.pixelStride;
  179608. }
  179609. }
  179610. else
  179611. {
  179612. for (int i = width; --i >= 0;)
  179613. {
  179614. *dst++ = ((const PixelRGB*) src)->getRed();
  179615. *dst++ = ((const PixelRGB*) src)->getGreen();
  179616. *dst++ = ((const PixelRGB*) src)->getBlue();
  179617. src += srcData.pixelStride;
  179618. }
  179619. }
  179620. png_write_rows (pngWriteStruct, &rowData, 1);
  179621. }
  179622. png_write_end (pngWriteStruct, pngInfoStruct);
  179623. png_destroy_write_struct (&pngWriteStruct, &pngInfoStruct);
  179624. out.flush();
  179625. return true;
  179626. }
  179627. END_JUCE_NAMESPACE
  179628. /*** End of inlined file: juce_PNGLoader.cpp ***/
  179629. #endif
  179630. //==============================================================================
  179631. #if JUCE_BUILD_NATIVE
  179632. #if JUCE_WINDOWS
  179633. /*** Start of inlined file: juce_win32_NativeCode.cpp ***/
  179634. BEGIN_JUCE_NAMESPACE
  179635. #define JUCE_INCLUDED_FILE 1
  179636. // Now include the actual code files..
  179637. /*** Start of inlined file: juce_win32_DynamicLibraryLoader.cpp ***/
  179638. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179639. // compiled on its own).
  179640. #if JUCE_INCLUDED_FILE
  179641. /*** Start of inlined file: juce_win32_DynamicLibraryLoader.h ***/
  179642. #ifndef __JUCE_WIN32_DYNAMICLIBRARYLOADER_JUCEHEADER__
  179643. #define __JUCE_WIN32_DYNAMICLIBRARYLOADER_JUCEHEADER__
  179644. #ifndef DOXYGEN
  179645. // use with DynamicLibraryLoader to simplify importing functions
  179646. //
  179647. // functionName: function to import
  179648. // localFunctionName: name you want to use to actually call it (must be different)
  179649. // returnType: the return type
  179650. // object: the DynamicLibraryLoader to use
  179651. // params: list of params (bracketed)
  179652. //
  179653. #define DynamicLibraryImport(functionName, localFunctionName, returnType, object, params) \
  179654. typedef returnType (WINAPI *type##localFunctionName) params; \
  179655. type##localFunctionName localFunctionName \
  179656. = (type##localFunctionName)object.findProcAddress (#functionName);
  179657. // loads and unloads a DLL automatically
  179658. class JUCE_API DynamicLibraryLoader
  179659. {
  179660. public:
  179661. DynamicLibraryLoader (const String& name);
  179662. ~DynamicLibraryLoader();
  179663. void* findProcAddress (const String& functionName);
  179664. private:
  179665. void* libHandle;
  179666. };
  179667. #endif
  179668. #endif // __JUCE_WIN32_DYNAMICLIBRARYLOADER_JUCEHEADER__
  179669. /*** End of inlined file: juce_win32_DynamicLibraryLoader.h ***/
  179670. DynamicLibraryLoader::DynamicLibraryLoader (const String& name)
  179671. {
  179672. libHandle = LoadLibrary (name);
  179673. }
  179674. DynamicLibraryLoader::~DynamicLibraryLoader()
  179675. {
  179676. FreeLibrary ((HMODULE) libHandle);
  179677. }
  179678. void* DynamicLibraryLoader::findProcAddress (const String& functionName)
  179679. {
  179680. return (void*) GetProcAddress ((HMODULE) libHandle, functionName);
  179681. }
  179682. #endif
  179683. /*** End of inlined file: juce_win32_DynamicLibraryLoader.cpp ***/
  179684. /*** Start of inlined file: juce_win32_SystemStats.cpp ***/
  179685. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179686. // compiled on its own).
  179687. #if JUCE_INCLUDED_FILE
  179688. extern void juce_initialiseThreadEvents();
  179689. void Logger::outputDebugString (const String& text) throw()
  179690. {
  179691. OutputDebugString (text + T("\n"));
  179692. }
  179693. void Logger::outputDebugPrintf (const tchar* format, ...) throw()
  179694. {
  179695. String text;
  179696. va_list args;
  179697. va_start (args, format);
  179698. text.vprintf(format, args);
  179699. outputDebugString (text);
  179700. }
  179701. static int64 hiResTicksPerSecond;
  179702. static double hiResTicksScaleFactor;
  179703. #if JUCE_USE_INTRINSICS
  179704. // CPU info functions using intrinsics...
  179705. #pragma intrinsic (__cpuid)
  179706. #pragma intrinsic (__rdtsc)
  179707. const String SystemStats::getCpuVendor() throw()
  179708. {
  179709. int info [4];
  179710. __cpuid (info, 0);
  179711. char v [12];
  179712. memcpy (v, info + 1, 4);
  179713. memcpy (v + 4, info + 3, 4);
  179714. memcpy (v + 8, info + 2, 4);
  179715. return String (v, 12);
  179716. }
  179717. #else
  179718. // CPU info functions using old fashioned inline asm...
  179719. static void juce_getCpuVendor (char* const v)
  179720. {
  179721. int vendor[4];
  179722. zeromem (vendor, 16);
  179723. #ifdef JUCE_64BIT
  179724. #else
  179725. #ifndef __MINGW32__
  179726. __try
  179727. #endif
  179728. {
  179729. #if JUCE_GCC
  179730. unsigned int dummy = 0;
  179731. __asm__ ("cpuid" : "=a" (dummy), "=b" (vendor[0]), "=c" (vendor[2]),"=d" (vendor[1]) : "a" (0));
  179732. #else
  179733. __asm
  179734. {
  179735. mov eax, 0
  179736. cpuid
  179737. mov [vendor], ebx
  179738. mov [vendor + 4], edx
  179739. mov [vendor + 8], ecx
  179740. }
  179741. #endif
  179742. }
  179743. #ifndef __MINGW32__
  179744. __except (EXCEPTION_EXECUTE_HANDLER)
  179745. {
  179746. *v = 0;
  179747. }
  179748. #endif
  179749. #endif
  179750. memcpy (v, vendor, 16);
  179751. }
  179752. const String SystemStats::getCpuVendor() throw()
  179753. {
  179754. char v [16];
  179755. juce_getCpuVendor (v);
  179756. return String (v, 16);
  179757. }
  179758. #endif
  179759. struct CPUFlags
  179760. {
  179761. bool hasMMX : 1;
  179762. bool hasSSE : 1;
  179763. bool hasSSE2 : 1;
  179764. bool has3DNow : 1;
  179765. };
  179766. static CPUFlags cpuFlags;
  179767. bool SystemStats::hasMMX() throw()
  179768. {
  179769. return cpuFlags.hasMMX;
  179770. }
  179771. bool SystemStats::hasSSE() throw()
  179772. {
  179773. return cpuFlags.hasSSE;
  179774. }
  179775. bool SystemStats::hasSSE2() throw()
  179776. {
  179777. return cpuFlags.hasSSE2;
  179778. }
  179779. bool SystemStats::has3DNow() throw()
  179780. {
  179781. return cpuFlags.has3DNow;
  179782. }
  179783. void SystemStats::initialiseStats() throw()
  179784. {
  179785. juce_initialiseThreadEvents();
  179786. cpuFlags.hasMMX = IsProcessorFeaturePresent (PF_MMX_INSTRUCTIONS_AVAILABLE) != 0;
  179787. cpuFlags.hasSSE = IsProcessorFeaturePresent (PF_XMMI_INSTRUCTIONS_AVAILABLE) != 0;
  179788. cpuFlags.hasSSE2 = IsProcessorFeaturePresent (PF_XMMI64_INSTRUCTIONS_AVAILABLE) != 0;
  179789. #ifdef PF_AMD3D_INSTRUCTIONS_AVAILABLE
  179790. cpuFlags.has3DNow = IsProcessorFeaturePresent (PF_AMD3D_INSTRUCTIONS_AVAILABLE) != 0;
  179791. #else
  179792. cpuFlags.has3DNow = IsProcessorFeaturePresent (PF_3DNOW_INSTRUCTIONS_AVAILABLE) != 0;
  179793. #endif
  179794. LARGE_INTEGER f;
  179795. QueryPerformanceFrequency (&f);
  179796. hiResTicksPerSecond = f.QuadPart;
  179797. hiResTicksScaleFactor = 1000.0 / hiResTicksPerSecond;
  179798. String s (SystemStats::getJUCEVersion());
  179799. #ifdef JUCE_DEBUG
  179800. const MMRESULT res = timeBeginPeriod (1);
  179801. jassert (res == TIMERR_NOERROR);
  179802. #else
  179803. timeBeginPeriod (1);
  179804. #endif
  179805. #if defined (JUCE_DEBUG) && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS
  179806. _CrtSetDbgFlag (_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
  179807. #endif
  179808. }
  179809. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  179810. {
  179811. OSVERSIONINFO info;
  179812. info.dwOSVersionInfoSize = sizeof (info);
  179813. GetVersionEx (&info);
  179814. if (info.dwPlatformId == VER_PLATFORM_WIN32_NT)
  179815. {
  179816. switch (info.dwMajorVersion)
  179817. {
  179818. case 5: return (info.dwMinorVersion == 0) ? Win2000 : WinXP;
  179819. case 6: return (info.dwMinorVersion == 0) ? WinVista : Windows7;
  179820. default: jassertfalse; break; // !! not a supported OS!
  179821. }
  179822. }
  179823. else if (info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
  179824. {
  179825. jassert (info.dwMinorVersion != 0); // !! still running on Windows 95??
  179826. return Win98;
  179827. }
  179828. return UnknownOS;
  179829. }
  179830. const String SystemStats::getOperatingSystemName() throw()
  179831. {
  179832. const char* name = "Unknown OS";
  179833. switch (getOperatingSystemType())
  179834. {
  179835. case Windows7: name = "Windows 7"; break;
  179836. case WinVista: name = "Windows Vista"; break;
  179837. case WinXP: name = "Windows XP"; break;
  179838. case Win2000: name = "Windows 2000"; break;
  179839. case Win98: name = "Windows 98"; break;
  179840. default: jassertfalse; break; // !! new type of OS?
  179841. }
  179842. return name;
  179843. }
  179844. bool SystemStats::isOperatingSystem64Bit() throw()
  179845. {
  179846. #ifdef _WIN64
  179847. return true;
  179848. #else
  179849. typedef BOOL (WINAPI* LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
  179850. LPFN_ISWOW64PROCESS fnIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress (GetModuleHandle (L"kernel32"), "IsWow64Process");
  179851. BOOL isWow64 = FALSE;
  179852. return (fnIsWow64Process != 0)
  179853. && fnIsWow64Process (GetCurrentProcess(), &isWow64)
  179854. && (isWow64 != FALSE);
  179855. #endif
  179856. }
  179857. int SystemStats::getMemorySizeInMegabytes() throw()
  179858. {
  179859. MEMORYSTATUSEX mem;
  179860. mem.dwLength = sizeof (mem);
  179861. GlobalMemoryStatusEx (&mem);
  179862. return (int) (mem.ullTotalPhys / (1024 * 1024)) + 1;
  179863. }
  179864. int SystemStats::getNumCpus() throw()
  179865. {
  179866. SYSTEM_INFO systemInfo;
  179867. GetSystemInfo (&systemInfo);
  179868. return systemInfo.dwNumberOfProcessors;
  179869. }
  179870. uint32 juce_millisecondsSinceStartup() throw()
  179871. {
  179872. return (uint32) GetTickCount();
  179873. }
  179874. int64 Time::getHighResolutionTicks() throw()
  179875. {
  179876. LARGE_INTEGER ticks;
  179877. QueryPerformanceCounter (&ticks);
  179878. const int64 mainCounterAsHiResTicks = (GetTickCount() * hiResTicksPerSecond) / 1000;
  179879. const int64 newOffset = mainCounterAsHiResTicks - ticks.QuadPart;
  179880. // fix for a very obscure PCI hardware bug that can make the counter
  179881. // sometimes jump forwards by a few seconds..
  179882. static int64 hiResTicksOffset = 0;
  179883. const int64 offsetDrift = abs64 (newOffset - hiResTicksOffset);
  179884. if (offsetDrift > (hiResTicksPerSecond >> 1))
  179885. hiResTicksOffset = newOffset;
  179886. return ticks.QuadPart + hiResTicksOffset;
  179887. }
  179888. double Time::getMillisecondCounterHiRes() throw()
  179889. {
  179890. return getHighResolutionTicks() * hiResTicksScaleFactor;
  179891. }
  179892. int64 Time::getHighResolutionTicksPerSecond() throw()
  179893. {
  179894. return hiResTicksPerSecond;
  179895. }
  179896. int64 SystemStats::getClockCycleCounter() throw()
  179897. {
  179898. #if JUCE_USE_INTRINSICS
  179899. // MS intrinsics version...
  179900. return __rdtsc();
  179901. #elif JUCE_GCC
  179902. // GNU inline asm version...
  179903. unsigned int hi = 0, lo = 0;
  179904. __asm__ __volatile__ (
  179905. "xor %%eax, %%eax \n\
  179906. xor %%edx, %%edx \n\
  179907. rdtsc \n\
  179908. movl %%eax, %[lo] \n\
  179909. movl %%edx, %[hi]"
  179910. :
  179911. : [hi] "m" (hi),
  179912. [lo] "m" (lo)
  179913. : "cc", "eax", "ebx", "ecx", "edx", "memory");
  179914. return (int64) ((((uint64) hi) << 32) | lo);
  179915. #else
  179916. // MSVC inline asm version...
  179917. unsigned int hi = 0, lo = 0;
  179918. __asm
  179919. {
  179920. xor eax, eax
  179921. xor edx, edx
  179922. rdtsc
  179923. mov lo, eax
  179924. mov hi, edx
  179925. }
  179926. return (int64) ((((uint64) hi) << 32) | lo);
  179927. #endif
  179928. }
  179929. int SystemStats::getCpuSpeedInMegaherz() throw()
  179930. {
  179931. const int64 cycles = SystemStats::getClockCycleCounter();
  179932. const uint32 millis = Time::getMillisecondCounter();
  179933. int lastResult = 0;
  179934. for (;;)
  179935. {
  179936. int n = 1000000;
  179937. while (--n > 0) {}
  179938. const uint32 millisElapsed = Time::getMillisecondCounter() - millis;
  179939. const int64 cyclesNow = SystemStats::getClockCycleCounter();
  179940. if (millisElapsed > 80)
  179941. {
  179942. const int newResult = (int) (((cyclesNow - cycles) / millisElapsed) / 1000);
  179943. if (millisElapsed > 500 || (lastResult == newResult && newResult > 100))
  179944. return newResult;
  179945. lastResult = newResult;
  179946. }
  179947. }
  179948. }
  179949. bool Time::setSystemTimeToThisTime() const throw()
  179950. {
  179951. SYSTEMTIME st;
  179952. st.wDayOfWeek = 0;
  179953. st.wYear = (WORD) getYear();
  179954. st.wMonth = (WORD) (getMonth() + 1);
  179955. st.wDay = (WORD) getDayOfMonth();
  179956. st.wHour = (WORD) getHours();
  179957. st.wMinute = (WORD) getMinutes();
  179958. st.wSecond = (WORD) getSeconds();
  179959. st.wMilliseconds = (WORD) (millisSinceEpoch % 1000);
  179960. // do this twice because of daylight saving conversion problems - the
  179961. // first one sets it up, the second one kicks it in.
  179962. return SetLocalTime (&st) != 0
  179963. && SetLocalTime (&st) != 0;
  179964. }
  179965. int SystemStats::getPageSize() throw()
  179966. {
  179967. SYSTEM_INFO systemInfo;
  179968. GetSystemInfo (&systemInfo);
  179969. return systemInfo.dwPageSize;
  179970. }
  179971. const String SystemStats::getLogonName()
  179972. {
  179973. TCHAR text [256];
  179974. DWORD len = numElementsInArray (text) - 2;
  179975. zerostruct (text);
  179976. GetUserName (text, &len);
  179977. return String (text, len);
  179978. }
  179979. const String SystemStats::getFullUserName()
  179980. {
  179981. return getLogonName();
  179982. }
  179983. #endif
  179984. /*** End of inlined file: juce_win32_SystemStats.cpp ***/
  179985. /*** Start of inlined file: juce_win32_Threads.cpp ***/
  179986. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179987. // compiled on its own).
  179988. #if JUCE_INCLUDED_FILE
  179989. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  179990. extern HWND juce_messageWindowHandle;
  179991. #endif
  179992. #if ! JUCE_USE_INTRINSICS
  179993. // In newer compilers, the inline versions of these are used (in juce_Atomic.h), but in
  179994. // older ones we have to actually call the ops as win32 functions..
  179995. void Atomic::increment (int32& variable) { InterlockedIncrement (reinterpret_cast <volatile long*> (&variable)); }
  179996. int32 Atomic::incrementAndReturn (int32& variable) { return InterlockedIncrement (reinterpret_cast <volatile long*> (&variable)); }
  179997. void Atomic::decrement (int32& variable) { InterlockedDecrement (reinterpret_cast <volatile long*> (&variable)); }
  179998. int32 Atomic::decrementAndReturn (int32& variable) { return InterlockedDecrement (reinterpret_cast <volatile long*> (&variable)); }
  179999. int32 Atomic::compareAndExchange (int32& destination, int32 newValue, int32 oldValue)
  180000. { return InterlockedCompareExchange (reinterpret_cast <volatile long*> (&destination), newValue, oldValue); }
  180001. #endif
  180002. void* Atomic::swapPointers (void* volatile* value1, void* volatile value2) { return InterlockedExchangePointer (value1, value2); }
  180003. CriticalSection::CriticalSection() throw()
  180004. {
  180005. // (just to check the MS haven't changed this structure and broken things...)
  180006. #if _MSC_VER >= 1400
  180007. static_jassert (sizeof (CRITICAL_SECTION) <= sizeof (internal));
  180008. #else
  180009. static_jassert (sizeof (CRITICAL_SECTION) <= 24);
  180010. #endif
  180011. InitializeCriticalSection ((CRITICAL_SECTION*) internal);
  180012. }
  180013. CriticalSection::~CriticalSection() throw()
  180014. {
  180015. DeleteCriticalSection ((CRITICAL_SECTION*) internal);
  180016. }
  180017. void CriticalSection::enter() const throw()
  180018. {
  180019. EnterCriticalSection ((CRITICAL_SECTION*) internal);
  180020. }
  180021. bool CriticalSection::tryEnter() const throw()
  180022. {
  180023. return TryEnterCriticalSection ((CRITICAL_SECTION*) internal) != FALSE;
  180024. }
  180025. void CriticalSection::exit() const throw()
  180026. {
  180027. LeaveCriticalSection ((CRITICAL_SECTION*) internal);
  180028. }
  180029. WaitableEvent::WaitableEvent() throw()
  180030. : internal (CreateEvent (0, FALSE, FALSE, 0))
  180031. {
  180032. }
  180033. WaitableEvent::~WaitableEvent() throw()
  180034. {
  180035. CloseHandle (internal);
  180036. }
  180037. bool WaitableEvent::wait (const int timeOutMillisecs) const throw()
  180038. {
  180039. return WaitForSingleObject (internal, timeOutMillisecs) == WAIT_OBJECT_0;
  180040. }
  180041. void WaitableEvent::signal() const throw()
  180042. {
  180043. SetEvent (internal);
  180044. }
  180045. void WaitableEvent::reset() const throw()
  180046. {
  180047. ResetEvent (internal);
  180048. }
  180049. void JUCE_API juce_threadEntryPoint (void*);
  180050. static unsigned int __stdcall threadEntryProc (void* userData)
  180051. {
  180052. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  180053. AttachThreadInput (GetWindowThreadProcessId (juce_messageWindowHandle, 0),
  180054. GetCurrentThreadId(), TRUE);
  180055. #endif
  180056. juce_threadEntryPoint (userData);
  180057. _endthreadex (0);
  180058. return 0;
  180059. }
  180060. void juce_CloseThreadHandle (void* handle)
  180061. {
  180062. CloseHandle ((HANDLE) handle);
  180063. }
  180064. void* juce_createThread (void* userData)
  180065. {
  180066. unsigned int threadId;
  180067. return (void*) _beginthreadex (0, 0,
  180068. &threadEntryProc,
  180069. userData,
  180070. 0, &threadId);
  180071. }
  180072. void juce_killThread (void* handle)
  180073. {
  180074. if (handle != 0)
  180075. {
  180076. #ifdef JUCE_DEBUG
  180077. OutputDebugString (_T("** Warning - Forced thread termination **\n"));
  180078. #endif
  180079. TerminateThread (handle, 0);
  180080. }
  180081. }
  180082. void juce_setCurrentThreadName (const String& name)
  180083. {
  180084. #if defined (JUCE_DEBUG) && JUCE_MSVC
  180085. struct
  180086. {
  180087. DWORD dwType;
  180088. LPCSTR szName;
  180089. DWORD dwThreadID;
  180090. DWORD dwFlags;
  180091. } info;
  180092. info.dwType = 0x1000;
  180093. info.szName = name;
  180094. info.dwThreadID = GetCurrentThreadId();
  180095. info.dwFlags = 0;
  180096. #define MS_VC_EXCEPTION 0x406d1388
  180097. __try
  180098. {
  180099. RaiseException (MS_VC_EXCEPTION, 0, sizeof (info) / sizeof (ULONG_PTR), (ULONG_PTR*) &info);
  180100. }
  180101. __except (EXCEPTION_CONTINUE_EXECUTION)
  180102. {}
  180103. #else
  180104. (void) name;
  180105. #endif
  180106. }
  180107. Thread::ThreadID Thread::getCurrentThreadId()
  180108. {
  180109. return (ThreadID) (pointer_sized_int) GetCurrentThreadId();
  180110. }
  180111. // priority 1 to 10 where 5=normal, 1=low
  180112. bool juce_setThreadPriority (void* threadHandle, int priority)
  180113. {
  180114. int pri = THREAD_PRIORITY_TIME_CRITICAL;
  180115. if (priority < 1)
  180116. pri = THREAD_PRIORITY_IDLE;
  180117. else if (priority < 2)
  180118. pri = THREAD_PRIORITY_LOWEST;
  180119. else if (priority < 5)
  180120. pri = THREAD_PRIORITY_BELOW_NORMAL;
  180121. else if (priority < 7)
  180122. pri = THREAD_PRIORITY_NORMAL;
  180123. else if (priority < 9)
  180124. pri = THREAD_PRIORITY_ABOVE_NORMAL;
  180125. else if (priority < 10)
  180126. pri = THREAD_PRIORITY_HIGHEST;
  180127. if (threadHandle == 0)
  180128. threadHandle = GetCurrentThread();
  180129. return SetThreadPriority (threadHandle, pri) != FALSE;
  180130. }
  180131. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
  180132. {
  180133. SetThreadAffinityMask (GetCurrentThread(), affinityMask);
  180134. }
  180135. static HANDLE sleepEvent = 0;
  180136. void juce_initialiseThreadEvents()
  180137. {
  180138. if (sleepEvent == 0)
  180139. #ifdef JUCE_DEBUG
  180140. sleepEvent = CreateEvent (0, 0, 0, _T("Juce Sleep Event"));
  180141. #else
  180142. sleepEvent = CreateEvent (0, 0, 0, 0);
  180143. #endif
  180144. }
  180145. void Thread::yield()
  180146. {
  180147. Sleep (0);
  180148. }
  180149. void JUCE_CALLTYPE Thread::sleep (const int millisecs)
  180150. {
  180151. if (millisecs >= 10)
  180152. {
  180153. Sleep (millisecs);
  180154. }
  180155. else
  180156. {
  180157. jassert (sleepEvent != 0);
  180158. // unlike Sleep() this is guaranteed to return to the current thread after
  180159. // the time expires, so we'll use this for short waits, which are more likely
  180160. // to need to be accurate
  180161. WaitForSingleObject (sleepEvent, millisecs);
  180162. }
  180163. }
  180164. static int lastProcessPriority = -1;
  180165. // called by WindowDriver because Windows does wierd things to process priority
  180166. // when you swap apps, and this forces an update when the app is brought to the front.
  180167. void juce_repeatLastProcessPriority()
  180168. {
  180169. if (lastProcessPriority >= 0) // (avoid changing this if it's not been explicitly set by the app..)
  180170. {
  180171. DWORD p;
  180172. switch (lastProcessPriority)
  180173. {
  180174. case Process::LowPriority:
  180175. p = IDLE_PRIORITY_CLASS;
  180176. break;
  180177. case Process::NormalPriority:
  180178. p = NORMAL_PRIORITY_CLASS;
  180179. break;
  180180. case Process::HighPriority:
  180181. p = HIGH_PRIORITY_CLASS;
  180182. break;
  180183. case Process::RealtimePriority:
  180184. p = REALTIME_PRIORITY_CLASS;
  180185. break;
  180186. default:
  180187. jassertfalse // bad priority value
  180188. return;
  180189. }
  180190. SetPriorityClass (GetCurrentProcess(), p);
  180191. }
  180192. }
  180193. void Process::setPriority (ProcessPriority prior)
  180194. {
  180195. if (lastProcessPriority != (int) prior)
  180196. {
  180197. lastProcessPriority = (int) prior;
  180198. juce_repeatLastProcessPriority();
  180199. }
  180200. }
  180201. bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger()
  180202. {
  180203. return IsDebuggerPresent() != FALSE;
  180204. }
  180205. bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
  180206. {
  180207. return juce_isRunningUnderDebugger();
  180208. }
  180209. void Process::raisePrivilege()
  180210. {
  180211. jassertfalse // xxx not implemented
  180212. }
  180213. void Process::lowerPrivilege()
  180214. {
  180215. jassertfalse // xxx not implemented
  180216. }
  180217. void Process::terminate()
  180218. {
  180219. #if defined (JUCE_DEBUG) && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS
  180220. _CrtDumpMemoryLeaks();
  180221. #endif
  180222. // bullet in the head in case there's a problem shutting down..
  180223. ExitProcess (0);
  180224. }
  180225. void* PlatformUtilities::loadDynamicLibrary (const String& name)
  180226. {
  180227. void* result = 0;
  180228. JUCE_TRY
  180229. {
  180230. result = (void*) LoadLibrary (name);
  180231. }
  180232. JUCE_CATCH_ALL
  180233. return result;
  180234. }
  180235. void PlatformUtilities::freeDynamicLibrary (void* h)
  180236. {
  180237. JUCE_TRY
  180238. {
  180239. if (h != 0)
  180240. FreeLibrary ((HMODULE) h);
  180241. }
  180242. JUCE_CATCH_ALL
  180243. }
  180244. void* PlatformUtilities::getProcedureEntryPoint (void* h, const String& name)
  180245. {
  180246. return (h != 0) ? (void*) GetProcAddress ((HMODULE) h, name)
  180247. : 0;
  180248. }
  180249. InterProcessLock::InterProcessLock (const String& name_)
  180250. : internal (0),
  180251. name (name_),
  180252. reentrancyLevel (0)
  180253. {
  180254. }
  180255. InterProcessLock::~InterProcessLock()
  180256. {
  180257. exit();
  180258. }
  180259. bool InterProcessLock::enter (const int timeOutMillisecs)
  180260. {
  180261. if (reentrancyLevel++ == 0)
  180262. {
  180263. internal = CreateMutex (0, TRUE, "Global\\" + name);
  180264. if (internal != 0 && GetLastError() == ERROR_ALREADY_EXISTS)
  180265. {
  180266. if (timeOutMillisecs == 0
  180267. || WaitForSingleObject (internal, (timeOutMillisecs < 0) ? INFINITE : timeOutMillisecs)
  180268. == WAIT_TIMEOUT)
  180269. {
  180270. ReleaseMutex (internal);
  180271. CloseHandle (internal);
  180272. internal = 0;
  180273. }
  180274. }
  180275. }
  180276. return (internal != 0);
  180277. }
  180278. void InterProcessLock::exit()
  180279. {
  180280. if (--reentrancyLevel == 0 && internal != 0)
  180281. {
  180282. ReleaseMutex (internal);
  180283. CloseHandle (internal);
  180284. internal = 0;
  180285. }
  180286. }
  180287. #endif
  180288. /*** End of inlined file: juce_win32_Threads.cpp ***/
  180289. /*** Start of inlined file: juce_win32_Files.cpp ***/
  180290. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  180291. // compiled on its own).
  180292. #if JUCE_INCLUDED_FILE
  180293. #ifndef CSIDL_MYMUSIC
  180294. #define CSIDL_MYMUSIC 0x000d
  180295. #endif
  180296. #ifndef CSIDL_MYVIDEO
  180297. #define CSIDL_MYVIDEO 0x000e
  180298. #endif
  180299. const tchar File::separator = T('\\');
  180300. const tchar* File::separatorString = T("\\");
  180301. bool juce_fileExists (const String& fileName, const bool dontCountDirectories)
  180302. {
  180303. if (fileName.isEmpty())
  180304. return false;
  180305. const DWORD attr = GetFileAttributes (fileName);
  180306. return dontCountDirectories ? ((attr & FILE_ATTRIBUTE_DIRECTORY) == 0)
  180307. : (attr != 0xffffffff);
  180308. }
  180309. bool juce_isDirectory (const String& fileName)
  180310. {
  180311. const DWORD attr = GetFileAttributes (fileName);
  180312. return (attr != 0xffffffff)
  180313. && ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0);
  180314. }
  180315. bool juce_canWriteToFile (const String& fileName)
  180316. {
  180317. const DWORD attr = GetFileAttributes (fileName);
  180318. return ((attr & FILE_ATTRIBUTE_READONLY) == 0);
  180319. }
  180320. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly)
  180321. {
  180322. DWORD attr = GetFileAttributes (fileName);
  180323. if (attr == 0xffffffff)
  180324. return false;
  180325. if (isReadOnly != juce_canWriteToFile (fileName))
  180326. return true;
  180327. if (isReadOnly)
  180328. attr |= FILE_ATTRIBUTE_READONLY;
  180329. else
  180330. attr &= ~FILE_ATTRIBUTE_READONLY;
  180331. return SetFileAttributes (fileName, attr) != FALSE;
  180332. }
  180333. bool File::isHidden() const
  180334. {
  180335. return (GetFileAttributes (getFullPathName()) & FILE_ATTRIBUTE_HIDDEN) != 0;
  180336. }
  180337. bool juce_deleteFile (const String& fileName)
  180338. {
  180339. if (juce_isDirectory (fileName))
  180340. return RemoveDirectory (fileName) != 0;
  180341. return DeleteFile (fileName) != 0;
  180342. }
  180343. bool File::moveToTrash() const
  180344. {
  180345. if (! exists())
  180346. return true;
  180347. SHFILEOPSTRUCT fos;
  180348. zerostruct (fos);
  180349. // The string we pass in must be double null terminated..
  180350. String doubleNullTermPath (getFullPathName() + " ");
  180351. TCHAR* p = (TCHAR*) (const TCHAR*) doubleNullTermPath;
  180352. p [getFullPathName().length()] = 0;
  180353. fos.wFunc = FO_DELETE;
  180354. fos.hwnd = (HWND) 0;
  180355. fos.pFrom = p;
  180356. fos.pTo = NULL;
  180357. fos.fFlags = FOF_ALLOWUNDO | FOF_NOERRORUI | FOF_SILENT | FOF_NOCONFIRMATION
  180358. | FOF_NOCONFIRMMKDIR | FOF_RENAMEONCOLLISION;
  180359. return SHFileOperation (&fos) == 0;
  180360. }
  180361. bool juce_moveFile (const String& source, const String& dest)
  180362. {
  180363. return MoveFile (source, dest) != 0;
  180364. }
  180365. bool juce_copyFile (const String& source, const String& dest)
  180366. {
  180367. return CopyFile (source, dest, false) != 0;
  180368. }
  180369. void juce_createDirectory (const String& fileName)
  180370. {
  180371. if (! juce_fileExists (fileName, true))
  180372. {
  180373. CreateDirectory (fileName, 0);
  180374. }
  180375. }
  180376. // return 0 if not possible
  180377. void* juce_fileOpen (const String& fileName, bool forWriting)
  180378. {
  180379. HANDLE h;
  180380. if (forWriting)
  180381. {
  180382. h = CreateFile (fileName, GENERIC_WRITE, FILE_SHARE_READ, 0,
  180383. OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
  180384. if (h != INVALID_HANDLE_VALUE)
  180385. SetFilePointer (h, 0, 0, FILE_END);
  180386. else
  180387. h = 0;
  180388. }
  180389. else
  180390. {
  180391. h = CreateFile (fileName, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 0,
  180392. OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, 0);
  180393. if (h == INVALID_HANDLE_VALUE)
  180394. h = 0;
  180395. }
  180396. return (void*) h;
  180397. }
  180398. void juce_fileClose (void* handle)
  180399. {
  180400. CloseHandle (handle);
  180401. }
  180402. int juce_fileRead (void* handle, void* buffer, int size)
  180403. {
  180404. DWORD num = 0;
  180405. ReadFile ((HANDLE) handle, buffer, size, &num, 0);
  180406. return num;
  180407. }
  180408. int juce_fileWrite (void* handle, const void* buffer, int size)
  180409. {
  180410. DWORD num;
  180411. WriteFile ((HANDLE) handle,
  180412. buffer, size,
  180413. &num, 0);
  180414. return num;
  180415. }
  180416. int64 juce_fileSetPosition (void* handle, int64 pos)
  180417. {
  180418. LARGE_INTEGER li;
  180419. li.QuadPart = pos;
  180420. li.LowPart = SetFilePointer ((HANDLE) handle,
  180421. li.LowPart,
  180422. &li.HighPart,
  180423. FILE_BEGIN); // (returns -1 if it fails)
  180424. return li.QuadPart;
  180425. }
  180426. int64 juce_fileGetPosition (void* handle)
  180427. {
  180428. LARGE_INTEGER li;
  180429. li.QuadPart = 0;
  180430. li.LowPart = SetFilePointer ((HANDLE) handle,
  180431. 0, &li.HighPart,
  180432. FILE_CURRENT); // (returns -1 if it fails)
  180433. return jmax ((int64) 0, li.QuadPart);
  180434. }
  180435. void juce_fileFlush (void* handle)
  180436. {
  180437. FlushFileBuffers ((HANDLE) handle);
  180438. }
  180439. int64 juce_getFileSize (const String& fileName)
  180440. {
  180441. WIN32_FILE_ATTRIBUTE_DATA attributes;
  180442. if (GetFileAttributesEx (fileName, GetFileExInfoStandard, &attributes))
  180443. {
  180444. return (((int64) attributes.nFileSizeHigh) << 32)
  180445. | attributes.nFileSizeLow;
  180446. }
  180447. return 0;
  180448. }
  180449. static int64 fileTimeToTime (const FILETIME* const ft)
  180450. {
  180451. // tell me if this fails!
  180452. static_jassert (sizeof (ULARGE_INTEGER) == sizeof (FILETIME));
  180453. #if JUCE_GCC
  180454. return (((const ULARGE_INTEGER*) ft)->QuadPart - 116444736000000000LL) / 10000;
  180455. #else
  180456. return (((const ULARGE_INTEGER*) ft)->QuadPart - 116444736000000000) / 10000;
  180457. #endif
  180458. }
  180459. static void timeToFileTime (const int64 time, FILETIME* const ft)
  180460. {
  180461. #if JUCE_GCC
  180462. ((ULARGE_INTEGER*) ft)->QuadPart = time * 10000 + 116444736000000000LL;
  180463. #else
  180464. ((ULARGE_INTEGER*) ft)->QuadPart = time * 10000 + 116444736000000000;
  180465. #endif
  180466. }
  180467. void juce_getFileTimes (const String& fileName,
  180468. int64& modificationTime,
  180469. int64& accessTime,
  180470. int64& creationTime)
  180471. {
  180472. WIN32_FILE_ATTRIBUTE_DATA attributes;
  180473. if (GetFileAttributesEx (fileName, GetFileExInfoStandard, &attributes))
  180474. {
  180475. modificationTime = fileTimeToTime (&attributes.ftLastWriteTime);
  180476. creationTime = fileTimeToTime (&attributes.ftCreationTime);
  180477. accessTime = fileTimeToTime (&attributes.ftLastAccessTime);
  180478. }
  180479. else
  180480. {
  180481. creationTime = accessTime = modificationTime = 0;
  180482. }
  180483. }
  180484. bool juce_setFileTimes (const String& fileName,
  180485. int64 modificationTime,
  180486. int64 accessTime,
  180487. int64 creationTime)
  180488. {
  180489. FILETIME m, a, c;
  180490. if (modificationTime > 0)
  180491. timeToFileTime (modificationTime, &m);
  180492. if (accessTime > 0)
  180493. timeToFileTime (accessTime, &a);
  180494. if (creationTime > 0)
  180495. timeToFileTime (creationTime, &c);
  180496. void* const h = juce_fileOpen (fileName, true);
  180497. bool ok = false;
  180498. if (h != 0)
  180499. {
  180500. ok = SetFileTime ((HANDLE) h,
  180501. (creationTime > 0) ? &c : 0,
  180502. (accessTime > 0) ? &a : 0,
  180503. (modificationTime > 0) ? &m : 0) != 0;
  180504. juce_fileClose (h);
  180505. }
  180506. return ok;
  180507. }
  180508. // return '\0' separated list of strings
  180509. const StringArray juce_getFileSystemRoots()
  180510. {
  180511. TCHAR buffer [2048];
  180512. buffer[0] = 0;
  180513. buffer[1] = 0;
  180514. GetLogicalDriveStrings (2048, buffer);
  180515. TCHAR* n = buffer;
  180516. StringArray roots;
  180517. while (*n != 0)
  180518. {
  180519. roots.add (String (n));
  180520. while (*n++ != 0)
  180521. {
  180522. }
  180523. }
  180524. roots.sort (true);
  180525. return roots;
  180526. }
  180527. const String juce_getVolumeLabel (const String& filenameOnVolume,
  180528. int& volumeSerialNumber)
  180529. {
  180530. TCHAR n [4];
  180531. n[0] = *(const TCHAR*) filenameOnVolume;
  180532. n[1] = L':';
  180533. n[2] = L'\\';
  180534. n[3] = 0;
  180535. TCHAR dest [64];
  180536. DWORD serialNum;
  180537. if (! GetVolumeInformation (n, dest, 64, (DWORD*) &serialNum, 0, 0, 0, 0))
  180538. {
  180539. dest[0] = 0;
  180540. serialNum = 0;
  180541. }
  180542. volumeSerialNumber = serialNum;
  180543. return String (dest);
  180544. }
  180545. static int64 getDiskSpaceInfo (String fn, const bool total)
  180546. {
  180547. if (fn[1] == T(':'))
  180548. fn = fn.substring (0, 2) + T("\\");
  180549. ULARGE_INTEGER spc, tot, totFree;
  180550. if (GetDiskFreeSpaceEx (fn, &spc, &tot, &totFree))
  180551. return (int64) (total ? tot.QuadPart
  180552. : spc.QuadPart);
  180553. return 0;
  180554. }
  180555. int64 File::getBytesFreeOnVolume() const
  180556. {
  180557. return getDiskSpaceInfo (getFullPathName(), false);
  180558. }
  180559. int64 File::getVolumeTotalSize() const
  180560. {
  180561. return getDiskSpaceInfo (getFullPathName(), true);
  180562. }
  180563. static unsigned int getWindowsDriveType (const String& fileName)
  180564. {
  180565. TCHAR n[4];
  180566. n[0] = *(const TCHAR*) fileName;
  180567. n[1] = L':';
  180568. n[2] = L'\\';
  180569. n[3] = 0;
  180570. return GetDriveType (n);
  180571. }
  180572. bool File::isOnCDRomDrive() const
  180573. {
  180574. return getWindowsDriveType (getFullPathName()) == DRIVE_CDROM;
  180575. }
  180576. bool File::isOnHardDisk() const
  180577. {
  180578. if (fullPath.isEmpty())
  180579. return false;
  180580. const unsigned int n = getWindowsDriveType (getFullPathName());
  180581. if (fullPath.toLowerCase()[0] <= 'b'
  180582. && fullPath[1] == T(':'))
  180583. {
  180584. return n != DRIVE_REMOVABLE;
  180585. }
  180586. else
  180587. {
  180588. return n != DRIVE_CDROM && n != DRIVE_REMOTE;
  180589. }
  180590. }
  180591. bool File::isOnRemovableDrive() const
  180592. {
  180593. if (fullPath.isEmpty())
  180594. return false;
  180595. const unsigned int n = getWindowsDriveType (getFullPathName());
  180596. return n == DRIVE_CDROM
  180597. || n == DRIVE_REMOTE
  180598. || n == DRIVE_REMOVABLE
  180599. || n == DRIVE_RAMDISK;
  180600. }
  180601. #define MAX_PATH_CHARS (MAX_PATH + 256)
  180602. static const File juce_getSpecialFolderPath (int type)
  180603. {
  180604. WCHAR path [MAX_PATH_CHARS];
  180605. if (SHGetSpecialFolderPath (0, path, type, 0))
  180606. return File (String (path));
  180607. return File::nonexistent;
  180608. }
  180609. const File JUCE_CALLTYPE File::getSpecialLocation (const SpecialLocationType type)
  180610. {
  180611. int csidlType = 0;
  180612. switch (type)
  180613. {
  180614. case userHomeDirectory:
  180615. csidlType = CSIDL_PROFILE;
  180616. break;
  180617. case userDocumentsDirectory:
  180618. csidlType = CSIDL_PERSONAL;
  180619. break;
  180620. case userDesktopDirectory:
  180621. csidlType = CSIDL_DESKTOP;
  180622. break;
  180623. case userApplicationDataDirectory:
  180624. csidlType = CSIDL_APPDATA;
  180625. break;
  180626. case commonApplicationDataDirectory:
  180627. csidlType = CSIDL_COMMON_APPDATA;
  180628. break;
  180629. case globalApplicationsDirectory:
  180630. csidlType = CSIDL_PROGRAM_FILES;
  180631. break;
  180632. case userMusicDirectory:
  180633. csidlType = CSIDL_MYMUSIC;
  180634. break;
  180635. case userMoviesDirectory:
  180636. csidlType = CSIDL_MYVIDEO;
  180637. break;
  180638. case tempDirectory:
  180639. {
  180640. WCHAR dest [2048];
  180641. dest[0] = 0;
  180642. GetTempPath (2048, dest);
  180643. return File (String (dest));
  180644. }
  180645. case invokedExecutableFile:
  180646. case currentExecutableFile:
  180647. case currentApplicationFile:
  180648. {
  180649. HINSTANCE moduleHandle = (HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle();
  180650. WCHAR dest [MAX_PATH_CHARS];
  180651. dest[0] = 0;
  180652. GetModuleFileName (moduleHandle, dest, MAX_PATH_CHARS);
  180653. return File (String (dest));
  180654. }
  180655. break;
  180656. default:
  180657. jassertfalse // unknown type?
  180658. return File::nonexistent;
  180659. }
  180660. return juce_getSpecialFolderPath (csidlType);
  180661. }
  180662. const File File::getCurrentWorkingDirectory()
  180663. {
  180664. WCHAR dest [MAX_PATH_CHARS];
  180665. dest[0] = 0;
  180666. GetCurrentDirectory (MAX_PATH_CHARS, dest);
  180667. return File (String (dest));
  180668. }
  180669. bool File::setAsCurrentWorkingDirectory() const
  180670. {
  180671. return SetCurrentDirectory (getFullPathName()) != FALSE;
  180672. }
  180673. const String File::getVersion() const
  180674. {
  180675. String result;
  180676. DWORD handle = 0;
  180677. DWORD bufferSize = GetFileVersionInfoSize (getFullPathName(), &handle);
  180678. HeapBlock <char> buffer;
  180679. buffer.calloc (bufferSize);
  180680. if (GetFileVersionInfo (getFullPathName(), 0, bufferSize, buffer))
  180681. {
  180682. VS_FIXEDFILEINFO* vffi;
  180683. UINT len = 0;
  180684. if (VerQueryValue (buffer, (LPTSTR) _T("\\"), (LPVOID*) &vffi, &len))
  180685. {
  180686. result << (int) HIWORD (vffi->dwFileVersionMS) << "."
  180687. << (int) LOWORD (vffi->dwFileVersionMS) << "."
  180688. << (int) HIWORD (vffi->dwFileVersionLS) << "."
  180689. << (int) LOWORD (vffi->dwFileVersionLS);
  180690. }
  180691. }
  180692. return result;
  180693. }
  180694. const File File::getLinkedTarget() const
  180695. {
  180696. File result (*this);
  180697. String p (getFullPathName());
  180698. if (! exists())
  180699. p += T(".lnk");
  180700. else if (getFileExtension() != T(".lnk"))
  180701. return result;
  180702. ComSmartPtr <IShellLink> shellLink;
  180703. if (SUCCEEDED (shellLink.CoCreateInstance (CLSID_ShellLink, CLSCTX_INPROC_SERVER)))
  180704. {
  180705. ComSmartPtr <IPersistFile> persistFile;
  180706. if (SUCCEEDED (shellLink->QueryInterface (IID_IPersistFile, (LPVOID*) &persistFile)))
  180707. {
  180708. if (SUCCEEDED (persistFile->Load ((const WCHAR*) p, STGM_READ))
  180709. && SUCCEEDED (shellLink->Resolve (0, SLR_ANY_MATCH | SLR_NO_UI)))
  180710. {
  180711. WIN32_FIND_DATA winFindData;
  180712. WCHAR resolvedPath [MAX_PATH];
  180713. if (SUCCEEDED (shellLink->GetPath (resolvedPath, MAX_PATH, &winFindData, SLGP_UNCPRIORITY)))
  180714. result = File (resolvedPath);
  180715. }
  180716. }
  180717. }
  180718. return result;
  180719. }
  180720. template <class FindDataType>
  180721. static void getFindFileInfo (FindDataType& findData,
  180722. String& filename, bool* const isDir, bool* const isHidden,
  180723. int64* const fileSize, Time* const modTime, Time* const creationTime,
  180724. bool* const isReadOnly)
  180725. {
  180726. filename = findData.cFileName;
  180727. if (isDir != 0)
  180728. *isDir = ((findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0);
  180729. if (isHidden != 0)
  180730. *isHidden = ((findData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) != 0);
  180731. if (fileSize != 0)
  180732. *fileSize = findData.nFileSizeLow + (((int64) findData.nFileSizeHigh) << 32);
  180733. if (modTime != 0)
  180734. *modTime = fileTimeToTime (&findData.ftLastWriteTime);
  180735. if (creationTime != 0)
  180736. *creationTime = fileTimeToTime (&findData.ftCreationTime);
  180737. if (isReadOnly != 0)
  180738. *isReadOnly = ((findData.dwFileAttributes & FILE_ATTRIBUTE_READONLY) != 0);
  180739. }
  180740. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResult,
  180741. bool* isDir, bool* isHidden, int64* fileSize,
  180742. Time* modTime, Time* creationTime, bool* isReadOnly)
  180743. {
  180744. String wc (directory);
  180745. if (! wc.endsWithChar (File::separator))
  180746. wc += File::separator;
  180747. wc += wildCard;
  180748. WIN32_FIND_DATA findData;
  180749. HANDLE h = FindFirstFile (wc, &findData);
  180750. if (h != INVALID_HANDLE_VALUE)
  180751. {
  180752. getFindFileInfo (findData, firstResult, isDir, isHidden, fileSize,
  180753. modTime, creationTime, isReadOnly);
  180754. return h;
  180755. }
  180756. firstResult = String::empty;
  180757. return 0;
  180758. }
  180759. bool juce_findFileNext (void* handle, String& resultFile,
  180760. bool* isDir, bool* isHidden, int64* fileSize,
  180761. Time* modTime, Time* creationTime, bool* isReadOnly)
  180762. {
  180763. WIN32_FIND_DATA findData;
  180764. if (handle != 0 && FindNextFile ((HANDLE) handle, &findData) != 0)
  180765. {
  180766. getFindFileInfo (findData, resultFile, isDir, isHidden, fileSize,
  180767. modTime, creationTime, isReadOnly);
  180768. return true;
  180769. }
  180770. resultFile = String::empty;
  180771. return false;
  180772. }
  180773. void juce_findFileClose (void* handle)
  180774. {
  180775. FindClose (handle);
  180776. }
  180777. bool juce_launchFile (const String& fileName,
  180778. const String& parameters)
  180779. {
  180780. HINSTANCE hInstance = 0;
  180781. JUCE_TRY
  180782. {
  180783. hInstance = ShellExecute (0, 0, fileName, parameters, 0, SW_SHOWDEFAULT);
  180784. }
  180785. JUCE_CATCH_ALL
  180786. return hInstance > (HINSTANCE) 32;
  180787. }
  180788. void File::revealToUser() const
  180789. {
  180790. if (isDirectory())
  180791. startAsProcess();
  180792. else if (getParentDirectory().exists())
  180793. getParentDirectory().startAsProcess();
  180794. }
  180795. struct NamedPipeInternal
  180796. {
  180797. HANDLE pipeH;
  180798. HANDLE cancelEvent;
  180799. bool connected, createdPipe;
  180800. NamedPipeInternal()
  180801. : pipeH (0),
  180802. cancelEvent (0),
  180803. connected (false),
  180804. createdPipe (false)
  180805. {
  180806. cancelEvent = CreateEvent (0, FALSE, FALSE, 0);
  180807. }
  180808. ~NamedPipeInternal()
  180809. {
  180810. disconnect();
  180811. if (pipeH != 0)
  180812. CloseHandle (pipeH);
  180813. CloseHandle (cancelEvent);
  180814. }
  180815. bool connect (const int timeOutMs)
  180816. {
  180817. if (! createdPipe)
  180818. return true;
  180819. if (! connected)
  180820. {
  180821. OVERLAPPED over;
  180822. zerostruct (over);
  180823. over.hEvent = CreateEvent (0, TRUE, FALSE, 0);
  180824. if (ConnectNamedPipe (pipeH, &over))
  180825. {
  180826. connected = false; // yes, you read that right. In overlapped mode it should always return 0.
  180827. }
  180828. else
  180829. {
  180830. const int err = GetLastError();
  180831. if (err == ERROR_IO_PENDING || err == ERROR_PIPE_LISTENING)
  180832. {
  180833. HANDLE handles[] = { over.hEvent, cancelEvent };
  180834. if (WaitForMultipleObjects (2, handles, FALSE,
  180835. timeOutMs >= 0 ? timeOutMs : INFINITE) == WAIT_OBJECT_0)
  180836. connected = true;
  180837. }
  180838. else if (err == ERROR_PIPE_CONNECTED)
  180839. {
  180840. connected = true;
  180841. }
  180842. }
  180843. CloseHandle (over.hEvent);
  180844. }
  180845. return connected;
  180846. }
  180847. void disconnect()
  180848. {
  180849. if (connected)
  180850. {
  180851. DisconnectNamedPipe (pipeH);
  180852. connected = false;
  180853. }
  180854. }
  180855. };
  180856. void NamedPipe::close()
  180857. {
  180858. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  180859. delete intern;
  180860. internal = 0;
  180861. }
  180862. bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
  180863. {
  180864. close();
  180865. NamedPipeInternal* const intern = new NamedPipeInternal();
  180866. String file ("\\\\.\\pipe\\");
  180867. file += pipeName;
  180868. intern->createdPipe = createPipe;
  180869. if (createPipe)
  180870. {
  180871. intern->pipeH = CreateNamedPipe (file, PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED, 0,
  180872. PIPE_UNLIMITED_INSTANCES,
  180873. 4096, 4096, 0, NULL);
  180874. }
  180875. else
  180876. {
  180877. intern->pipeH = CreateFile (file, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING,
  180878. FILE_FLAG_OVERLAPPED, 0);
  180879. }
  180880. if (intern->pipeH != INVALID_HANDLE_VALUE)
  180881. {
  180882. internal = intern;
  180883. return true;
  180884. }
  180885. delete intern;
  180886. return false;
  180887. }
  180888. int NamedPipe::read (void* destBuffer, int maxBytesToRead, int timeOutMilliseconds)
  180889. {
  180890. int bytesRead = -1;
  180891. bool waitAgain = true;
  180892. while (waitAgain && internal != 0)
  180893. {
  180894. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  180895. waitAgain = false;
  180896. if (! intern->connect (timeOutMilliseconds))
  180897. break;
  180898. if (maxBytesToRead <= 0)
  180899. return 0;
  180900. OVERLAPPED over;
  180901. zerostruct (over);
  180902. over.hEvent = CreateEvent (0, TRUE, FALSE, 0);
  180903. unsigned long numRead;
  180904. if (ReadFile (intern->pipeH, destBuffer, maxBytesToRead, &numRead, &over))
  180905. {
  180906. bytesRead = (int) numRead;
  180907. }
  180908. else if (GetLastError() == ERROR_IO_PENDING)
  180909. {
  180910. HANDLE handles[] = { over.hEvent, intern->cancelEvent };
  180911. DWORD waitResult = WaitForMultipleObjects (2, handles, FALSE,
  180912. timeOutMilliseconds >= 0 ? timeOutMilliseconds
  180913. : INFINITE);
  180914. if (waitResult != WAIT_OBJECT_0)
  180915. {
  180916. // if the operation timed out, let's cancel it...
  180917. CancelIo (intern->pipeH);
  180918. WaitForSingleObject (over.hEvent, INFINITE); // makes sure cancel is complete
  180919. }
  180920. if (GetOverlappedResult (intern->pipeH, &over, &numRead, FALSE))
  180921. {
  180922. bytesRead = (int) numRead;
  180923. }
  180924. else if (GetLastError() == ERROR_BROKEN_PIPE && intern->createdPipe)
  180925. {
  180926. intern->disconnect();
  180927. waitAgain = true;
  180928. }
  180929. }
  180930. else
  180931. {
  180932. waitAgain = internal != 0;
  180933. Sleep (5);
  180934. }
  180935. CloseHandle (over.hEvent);
  180936. }
  180937. return bytesRead;
  180938. }
  180939. int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
  180940. {
  180941. int bytesWritten = -1;
  180942. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  180943. if (intern != 0 && intern->connect (timeOutMilliseconds))
  180944. {
  180945. if (numBytesToWrite <= 0)
  180946. return 0;
  180947. OVERLAPPED over;
  180948. zerostruct (over);
  180949. over.hEvent = CreateEvent (0, TRUE, FALSE, 0);
  180950. unsigned long numWritten;
  180951. if (WriteFile (intern->pipeH, sourceBuffer, numBytesToWrite, &numWritten, &over))
  180952. {
  180953. bytesWritten = (int) numWritten;
  180954. }
  180955. else if (GetLastError() == ERROR_IO_PENDING)
  180956. {
  180957. HANDLE handles[] = { over.hEvent, intern->cancelEvent };
  180958. DWORD waitResult;
  180959. waitResult = WaitForMultipleObjects (2, handles, FALSE,
  180960. timeOutMilliseconds >= 0 ? timeOutMilliseconds
  180961. : INFINITE);
  180962. if (waitResult != WAIT_OBJECT_0)
  180963. {
  180964. CancelIo (intern->pipeH);
  180965. WaitForSingleObject (over.hEvent, INFINITE);
  180966. }
  180967. if (GetOverlappedResult (intern->pipeH, &over, &numWritten, FALSE))
  180968. {
  180969. bytesWritten = (int) numWritten;
  180970. }
  180971. else if (GetLastError() == ERROR_BROKEN_PIPE && intern->createdPipe)
  180972. {
  180973. intern->disconnect();
  180974. }
  180975. }
  180976. CloseHandle (over.hEvent);
  180977. }
  180978. return bytesWritten;
  180979. }
  180980. void NamedPipe::cancelPendingReads()
  180981. {
  180982. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  180983. if (intern != 0)
  180984. SetEvent (intern->cancelEvent);
  180985. }
  180986. #endif
  180987. /*** End of inlined file: juce_win32_Files.cpp ***/
  180988. /*** Start of inlined file: juce_win32_Network.cpp ***/
  180989. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  180990. // compiled on its own).
  180991. #if JUCE_INCLUDED_FILE
  180992. #ifndef INTERNET_FLAG_NEED_FILE
  180993. #define INTERNET_FLAG_NEED_FILE 0x00000010
  180994. #endif
  180995. #ifndef INTERNET_OPTION_DISABLE_AUTODIAL
  180996. #define INTERNET_OPTION_DISABLE_AUTODIAL 70
  180997. #endif
  180998. bool juce_isOnLine()
  180999. {
  181000. DWORD connectionType;
  181001. return InternetGetConnectedState (&connectionType, 0) != 0
  181002. || (connectionType & (INTERNET_CONNECTION_LAN | INTERNET_CONNECTION_PROXY)) != 0;
  181003. }
  181004. struct ConnectionAndRequestStruct
  181005. {
  181006. HINTERNET connection, request;
  181007. };
  181008. static HINTERNET sessionHandle = 0;
  181009. #ifndef WORKAROUND_TIMEOUT_BUG
  181010. //#define WORKAROUND_TIMEOUT_BUG 1
  181011. #endif
  181012. #if WORKAROUND_TIMEOUT_BUG
  181013. // Required because of a Microsoft bug in setting a timeout
  181014. class InternetConnectThread : public Thread
  181015. {
  181016. public:
  181017. InternetConnectThread (URL_COMPONENTS& uc_, HINTERNET& connection_, const bool isFtp_)
  181018. : Thread ("Internet"), uc (uc_), connection (connection_), isFtp (isFtp_)
  181019. {
  181020. startThread();
  181021. }
  181022. ~InternetConnectThread()
  181023. {
  181024. stopThread (60000);
  181025. }
  181026. void run()
  181027. {
  181028. connection = InternetConnect (sessionHandle, uc.lpszHostName,
  181029. uc.nPort, _T(""), _T(""),
  181030. isFtp ? INTERNET_SERVICE_FTP
  181031. : INTERNET_SERVICE_HTTP,
  181032. 0, 0);
  181033. notify();
  181034. }
  181035. juce_UseDebuggingNewOperator
  181036. private:
  181037. URL_COMPONENTS& uc;
  181038. HINTERNET& connection;
  181039. const bool isFtp;
  181040. InternetConnectThread (const InternetConnectThread&);
  181041. InternetConnectThread& operator= (const InternetConnectThread&);
  181042. };
  181043. #endif
  181044. void* juce_openInternetFile (const String& url,
  181045. const String& headers,
  181046. const MemoryBlock& postData,
  181047. const bool isPost,
  181048. URL::OpenStreamProgressCallback* callback,
  181049. void* callbackContext,
  181050. int timeOutMs)
  181051. {
  181052. if (sessionHandle == 0)
  181053. sessionHandle = InternetOpen (_T("juce"),
  181054. INTERNET_OPEN_TYPE_PRECONFIG,
  181055. 0, 0, 0);
  181056. if (sessionHandle != 0)
  181057. {
  181058. // break up the url..
  181059. TCHAR file[1024], server[1024];
  181060. URL_COMPONENTS uc;
  181061. zerostruct (uc);
  181062. uc.dwStructSize = sizeof (uc);
  181063. uc.dwUrlPathLength = sizeof (file);
  181064. uc.dwHostNameLength = sizeof (server);
  181065. uc.lpszUrlPath = file;
  181066. uc.lpszHostName = server;
  181067. if (InternetCrackUrl (url, 0, 0, &uc))
  181068. {
  181069. int disable = 1;
  181070. InternetSetOption (sessionHandle, INTERNET_OPTION_DISABLE_AUTODIAL, &disable, sizeof (disable));
  181071. if (timeOutMs == 0)
  181072. timeOutMs = 30000;
  181073. else if (timeOutMs < 0)
  181074. timeOutMs = -1;
  181075. InternetSetOption (sessionHandle, INTERNET_OPTION_CONNECT_TIMEOUT, &timeOutMs, sizeof (timeOutMs));
  181076. const bool isFtp = url.startsWithIgnoreCase (T("ftp:"));
  181077. #if WORKAROUND_TIMEOUT_BUG
  181078. HINTERNET connection = 0;
  181079. {
  181080. InternetConnectThread connectThread (uc, connection, isFtp);
  181081. connectThread.wait (timeOutMs);
  181082. if (connection == 0)
  181083. {
  181084. InternetCloseHandle (sessionHandle);
  181085. sessionHandle = 0;
  181086. }
  181087. }
  181088. #else
  181089. HINTERNET connection = InternetConnect (sessionHandle,
  181090. uc.lpszHostName,
  181091. uc.nPort,
  181092. _T(""), _T(""),
  181093. isFtp ? INTERNET_SERVICE_FTP
  181094. : INTERNET_SERVICE_HTTP,
  181095. 0, 0);
  181096. #endif
  181097. if (connection != 0)
  181098. {
  181099. if (isFtp)
  181100. {
  181101. HINTERNET request = FtpOpenFile (connection,
  181102. uc.lpszUrlPath,
  181103. GENERIC_READ,
  181104. FTP_TRANSFER_TYPE_BINARY | INTERNET_FLAG_NEED_FILE,
  181105. 0);
  181106. ConnectionAndRequestStruct* const result = new ConnectionAndRequestStruct();
  181107. result->connection = connection;
  181108. result->request = request;
  181109. return result;
  181110. }
  181111. else
  181112. {
  181113. const TCHAR* mimeTypes[] = { _T("*/*"), 0 };
  181114. DWORD flags = INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_CACHE_WRITE;
  181115. if (url.startsWithIgnoreCase (T("https:")))
  181116. flags |= INTERNET_FLAG_SECURE; // (this flag only seems necessary if the OS is running IE6 -
  181117. // IE7 seems to automatically work out when it's https)
  181118. HINTERNET request = HttpOpenRequest (connection,
  181119. isPost ? _T("POST")
  181120. : _T("GET"),
  181121. uc.lpszUrlPath,
  181122. 0, 0, mimeTypes, flags, 0);
  181123. if (request != 0)
  181124. {
  181125. INTERNET_BUFFERS buffers;
  181126. zerostruct (buffers);
  181127. buffers.dwStructSize = sizeof (INTERNET_BUFFERS);
  181128. buffers.lpcszHeader = (LPCTSTR) headers;
  181129. buffers.dwHeadersLength = headers.length();
  181130. buffers.dwBufferTotal = (DWORD) postData.getSize();
  181131. ConnectionAndRequestStruct* result = 0;
  181132. if (HttpSendRequestEx (request, &buffers, 0, HSR_INITIATE, 0))
  181133. {
  181134. int bytesSent = 0;
  181135. for (;;)
  181136. {
  181137. const int bytesToDo = jmin (1024, (int) postData.getSize() - bytesSent);
  181138. DWORD bytesDone = 0;
  181139. if (bytesToDo > 0
  181140. && ! InternetWriteFile (request,
  181141. ((const char*) postData.getData()) + bytesSent,
  181142. bytesToDo, &bytesDone))
  181143. {
  181144. break;
  181145. }
  181146. if (bytesToDo == 0 || (int) bytesDone < bytesToDo)
  181147. {
  181148. result = new ConnectionAndRequestStruct();
  181149. result->connection = connection;
  181150. result->request = request;
  181151. HttpEndRequest (request, 0, 0, 0);
  181152. return result;
  181153. }
  181154. bytesSent += bytesDone;
  181155. if (callback != 0 && ! callback (callbackContext, bytesSent, postData.getSize()))
  181156. break;
  181157. }
  181158. }
  181159. InternetCloseHandle (request);
  181160. }
  181161. InternetCloseHandle (connection);
  181162. }
  181163. }
  181164. }
  181165. }
  181166. return 0;
  181167. }
  181168. int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead)
  181169. {
  181170. DWORD bytesRead = 0;
  181171. const ConnectionAndRequestStruct* const crs = (const ConnectionAndRequestStruct*) handle;
  181172. if (crs != 0)
  181173. InternetReadFile (crs->request,
  181174. buffer, bytesToRead,
  181175. &bytesRead);
  181176. return bytesRead;
  181177. }
  181178. int juce_seekInInternetFile (void* handle, int newPosition)
  181179. {
  181180. if (handle != 0)
  181181. {
  181182. const ConnectionAndRequestStruct* const crs = (const ConnectionAndRequestStruct*) handle;
  181183. return InternetSetFilePointer (crs->request,
  181184. newPosition, 0,
  181185. FILE_BEGIN, 0);
  181186. }
  181187. else
  181188. {
  181189. return -1;
  181190. }
  181191. }
  181192. int64 juce_getInternetFileContentLength (void* handle)
  181193. {
  181194. const ConnectionAndRequestStruct* const crs = (const ConnectionAndRequestStruct*) handle;
  181195. if (crs != 0)
  181196. {
  181197. DWORD index = 0;
  181198. DWORD result = 0;
  181199. DWORD size = sizeof (result);
  181200. if (HttpQueryInfo (crs->request,
  181201. HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER,
  181202. &result,
  181203. &size,
  181204. &index))
  181205. {
  181206. return (int64) result;
  181207. }
  181208. }
  181209. return -1;
  181210. }
  181211. void juce_closeInternetFile (void* handle)
  181212. {
  181213. if (handle != 0)
  181214. {
  181215. ConnectionAndRequestStruct* const crs = (ConnectionAndRequestStruct*) handle;
  181216. InternetCloseHandle (crs->request);
  181217. InternetCloseHandle (crs->connection);
  181218. delete crs;
  181219. }
  181220. }
  181221. static int getMACAddressViaGetAdaptersInfo (int64* addresses, int maxNum, const bool littleEndian) throw()
  181222. {
  181223. int numFound = 0;
  181224. DynamicLibraryLoader dll ("iphlpapi.dll");
  181225. DynamicLibraryImport (GetAdaptersInfo, getAdaptersInfo, DWORD, dll, (PIP_ADAPTER_INFO, PULONG))
  181226. if (getAdaptersInfo != 0)
  181227. {
  181228. ULONG len = sizeof (IP_ADAPTER_INFO);
  181229. MemoryBlock mb;
  181230. PIP_ADAPTER_INFO adapterInfo = (PIP_ADAPTER_INFO) mb.getData();
  181231. if (getAdaptersInfo (adapterInfo, &len) == ERROR_BUFFER_OVERFLOW)
  181232. {
  181233. mb.setSize (len);
  181234. adapterInfo = (PIP_ADAPTER_INFO) mb.getData();
  181235. }
  181236. if (getAdaptersInfo (adapterInfo, &len) == NO_ERROR)
  181237. {
  181238. PIP_ADAPTER_INFO adapter = adapterInfo;
  181239. while (adapter != 0)
  181240. {
  181241. int64 mac = 0;
  181242. for (unsigned int i = 0; i < adapter->AddressLength; ++i)
  181243. mac = (mac << 8) | adapter->Address[i];
  181244. if (littleEndian)
  181245. mac = (int64) ByteOrder::swap ((uint64) mac);
  181246. if (numFound < maxNum && mac != 0)
  181247. addresses [numFound++] = mac;
  181248. adapter = adapter->Next;
  181249. }
  181250. }
  181251. }
  181252. return numFound;
  181253. }
  181254. struct ASTAT
  181255. {
  181256. ADAPTER_STATUS adapt;
  181257. NAME_BUFFER NameBuff [30];
  181258. };
  181259. static int getMACAddressesViaNetBios (int64* addresses, int maxNum, const bool littleEndian) throw()
  181260. {
  181261. int numFound = 0;
  181262. DynamicLibraryLoader dll ("netapi32.dll");
  181263. DynamicLibraryImport (Netbios, NetbiosCall, UCHAR, dll, (PNCB))
  181264. if (NetbiosCall != 0)
  181265. {
  181266. NCB ncb;
  181267. zerostruct (ncb);
  181268. ASTAT astat;
  181269. zerostruct (astat);
  181270. LANA_ENUM enums;
  181271. zerostruct (enums);
  181272. ncb.ncb_command = NCBENUM;
  181273. ncb.ncb_buffer = (unsigned char*) &enums;
  181274. ncb.ncb_length = sizeof (LANA_ENUM);
  181275. NetbiosCall (&ncb);
  181276. for (int i = 0; i < enums.length; ++i)
  181277. {
  181278. zerostruct (ncb);
  181279. ncb.ncb_command = NCBRESET;
  181280. ncb.ncb_lana_num = enums.lana[i];
  181281. if (NetbiosCall (&ncb) == 0)
  181282. {
  181283. zerostruct (ncb);
  181284. memcpy (ncb.ncb_callname, "* ", NCBNAMSZ);
  181285. ncb.ncb_command = NCBASTAT;
  181286. ncb.ncb_lana_num = enums.lana[i];
  181287. ncb.ncb_buffer = (unsigned char*) &astat;
  181288. ncb.ncb_length = sizeof (ASTAT);
  181289. if (NetbiosCall (&ncb) == 0)
  181290. {
  181291. if (astat.adapt.adapter_type == 0xfe)
  181292. {
  181293. uint64 mac = 0;
  181294. for (int i = 6; --i >= 0;)
  181295. mac = (mac << 8) | astat.adapt.adapter_address [littleEndian ? i : (5 - i)];
  181296. if (numFound < maxNum && mac != 0)
  181297. addresses [numFound++] = mac;
  181298. }
  181299. }
  181300. }
  181301. }
  181302. }
  181303. return numFound;
  181304. }
  181305. int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian) throw()
  181306. {
  181307. int numFound = getMACAddressViaGetAdaptersInfo (addresses, maxNum, littleEndian);
  181308. if (numFound == 0)
  181309. numFound = getMACAddressesViaNetBios (addresses, maxNum, littleEndian);
  181310. return numFound;
  181311. }
  181312. typedef ULONG (WINAPI *MAPISendMailType) (LHANDLE, ULONG, lpMapiMessage, ::FLAGS, ULONG);
  181313. bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
  181314. const String& emailSubject,
  181315. const String& bodyText,
  181316. const StringArray& filesToAttach)
  181317. {
  181318. HMODULE h = LoadLibraryA ("MAPI32.dll");
  181319. MAPISendMailType mapiSendMail = (MAPISendMailType) GetProcAddress (h, "MAPISendMail");
  181320. bool ok = false;
  181321. if (mapiSendMail != 0)
  181322. {
  181323. MapiMessage message;
  181324. zerostruct (message);
  181325. message.lpszSubject = (LPSTR) (LPCSTR) emailSubject;
  181326. message.lpszNoteText = (LPSTR) (LPCSTR) bodyText;
  181327. MapiRecipDesc recip;
  181328. zerostruct (recip);
  181329. recip.ulRecipClass = MAPI_TO;
  181330. String targetEmailAddress_ (targetEmailAddress);
  181331. if (targetEmailAddress_.isEmpty())
  181332. targetEmailAddress_ = " "; // (Windows Mail can't deal with a blank address)
  181333. recip.lpszName = (LPSTR) (LPCSTR) targetEmailAddress_;
  181334. message.nRecipCount = 1;
  181335. message.lpRecips = &recip;
  181336. MemoryBlock mb (sizeof (MapiFileDesc) * filesToAttach.size());
  181337. mb.fillWith (0);
  181338. MapiFileDesc* files = (MapiFileDesc*) mb.getData();
  181339. message.nFileCount = filesToAttach.size();
  181340. message.lpFiles = files;
  181341. for (int i = 0; i < filesToAttach.size(); ++i)
  181342. {
  181343. files[i].nPosition = (ULONG) -1;
  181344. files[i].lpszPathName = (LPSTR) (LPCSTR) filesToAttach [i];
  181345. }
  181346. ok = (mapiSendMail (0, 0, &message, MAPI_DIALOG | MAPI_LOGON_UI, 0) == SUCCESS_SUCCESS);
  181347. }
  181348. FreeLibrary (h);
  181349. return ok;
  181350. }
  181351. #endif
  181352. /*** End of inlined file: juce_win32_Network.cpp ***/
  181353. /*** Start of inlined file: juce_win32_PlatformUtils.cpp ***/
  181354. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  181355. // compiled on its own).
  181356. #if JUCE_INCLUDED_FILE
  181357. static HKEY findKeyForPath (String name,
  181358. const bool createForWriting,
  181359. String& valueName)
  181360. {
  181361. HKEY rootKey = 0;
  181362. if (name.startsWithIgnoreCase (T("HKEY_CURRENT_USER\\")))
  181363. rootKey = HKEY_CURRENT_USER;
  181364. else if (name.startsWithIgnoreCase (T("HKEY_LOCAL_MACHINE\\")))
  181365. rootKey = HKEY_LOCAL_MACHINE;
  181366. else if (name.startsWithIgnoreCase (T("HKEY_CLASSES_ROOT\\")))
  181367. rootKey = HKEY_CLASSES_ROOT;
  181368. if (rootKey != 0)
  181369. {
  181370. name = name.substring (name.indexOfChar (T('\\')) + 1);
  181371. const int lastSlash = name.lastIndexOfChar (T('\\'));
  181372. valueName = name.substring (lastSlash + 1);
  181373. name = name.substring (0, lastSlash);
  181374. HKEY key;
  181375. DWORD result;
  181376. if (createForWriting)
  181377. {
  181378. if (RegCreateKeyEx (rootKey, name, 0, 0, REG_OPTION_NON_VOLATILE,
  181379. (KEY_WRITE | KEY_QUERY_VALUE), 0, &key, &result) == ERROR_SUCCESS)
  181380. return key;
  181381. }
  181382. else
  181383. {
  181384. if (RegOpenKeyEx (rootKey, name, 0, KEY_READ, &key) == ERROR_SUCCESS)
  181385. return key;
  181386. }
  181387. }
  181388. return 0;
  181389. }
  181390. const String PlatformUtilities::getRegistryValue (const String& regValuePath,
  181391. const String& defaultValue)
  181392. {
  181393. String valueName, result (defaultValue);
  181394. HKEY k = findKeyForPath (regValuePath, false, valueName);
  181395. if (k != 0)
  181396. {
  181397. WCHAR buffer [2048];
  181398. unsigned long bufferSize = sizeof (buffer);
  181399. DWORD type = REG_SZ;
  181400. if (RegQueryValueEx (k, valueName, 0, &type, (LPBYTE) buffer, &bufferSize) == ERROR_SUCCESS)
  181401. {
  181402. if (type == REG_SZ)
  181403. result = buffer;
  181404. else if (type == REG_DWORD)
  181405. result = String ((int) *(DWORD*) buffer);
  181406. }
  181407. RegCloseKey (k);
  181408. }
  181409. return result;
  181410. }
  181411. void PlatformUtilities::setRegistryValue (const String& regValuePath,
  181412. const String& value)
  181413. {
  181414. String valueName;
  181415. HKEY k = findKeyForPath (regValuePath, true, valueName);
  181416. if (k != 0)
  181417. {
  181418. RegSetValueEx (k, valueName, 0, REG_SZ,
  181419. (const BYTE*) (const WCHAR*) value,
  181420. sizeof (WCHAR) * (value.length() + 1));
  181421. RegCloseKey (k);
  181422. }
  181423. }
  181424. bool PlatformUtilities::registryValueExists (const String& regValuePath)
  181425. {
  181426. bool exists = false;
  181427. String valueName;
  181428. HKEY k = findKeyForPath (regValuePath, false, valueName);
  181429. if (k != 0)
  181430. {
  181431. unsigned char buffer [2048];
  181432. unsigned long bufferSize = sizeof (buffer);
  181433. DWORD type = 0;
  181434. if (RegQueryValueEx (k, valueName, 0, &type, buffer, &bufferSize) == ERROR_SUCCESS)
  181435. exists = true;
  181436. RegCloseKey (k);
  181437. }
  181438. return exists;
  181439. }
  181440. void PlatformUtilities::deleteRegistryValue (const String& regValuePath)
  181441. {
  181442. String valueName;
  181443. HKEY k = findKeyForPath (regValuePath, true, valueName);
  181444. if (k != 0)
  181445. {
  181446. RegDeleteValue (k, valueName);
  181447. RegCloseKey (k);
  181448. }
  181449. }
  181450. void PlatformUtilities::deleteRegistryKey (const String& regKeyPath)
  181451. {
  181452. String valueName;
  181453. HKEY k = findKeyForPath (regKeyPath, true, valueName);
  181454. if (k != 0)
  181455. {
  181456. RegDeleteKey (k, valueName);
  181457. RegCloseKey (k);
  181458. }
  181459. }
  181460. void PlatformUtilities::registerFileAssociation (const String& fileExtension,
  181461. const String& symbolicDescription,
  181462. const String& fullDescription,
  181463. const File& targetExecutable,
  181464. int iconResourceNumber)
  181465. {
  181466. setRegistryValue ("HKEY_CLASSES_ROOT\\" + fileExtension + "\\", symbolicDescription);
  181467. const String key ("HKEY_CLASSES_ROOT\\" + symbolicDescription);
  181468. if (iconResourceNumber != 0)
  181469. setRegistryValue (key + "\\DefaultIcon\\",
  181470. targetExecutable.getFullPathName() + "," + String (-iconResourceNumber));
  181471. setRegistryValue (key + "\\", fullDescription);
  181472. setRegistryValue (key + "\\shell\\open\\command\\",
  181473. targetExecutable.getFullPathName() + " %1");
  181474. }
  181475. bool juce_IsRunningInWine()
  181476. {
  181477. HKEY key;
  181478. if (RegOpenKeyEx (HKEY_CURRENT_USER, _T("Software\\Wine"), 0, KEY_READ, &key) == ERROR_SUCCESS)
  181479. {
  181480. RegCloseKey (key);
  181481. return true;
  181482. }
  181483. return false;
  181484. }
  181485. const String JUCE_CALLTYPE PlatformUtilities::getCurrentCommandLineParams() throw()
  181486. {
  181487. String s (::GetCommandLineW());
  181488. StringArray tokens;
  181489. tokens.addTokens (s, true); // tokenise so that we can remove the initial filename argument
  181490. return tokens.joinIntoString (T(" "), 1);
  181491. }
  181492. static void* currentModuleHandle = 0;
  181493. void* PlatformUtilities::getCurrentModuleInstanceHandle() throw()
  181494. {
  181495. if (currentModuleHandle == 0)
  181496. currentModuleHandle = GetModuleHandle (0);
  181497. return currentModuleHandle;
  181498. }
  181499. void PlatformUtilities::setCurrentModuleInstanceHandle (void* const newHandle) throw()
  181500. {
  181501. currentModuleHandle = newHandle;
  181502. }
  181503. void PlatformUtilities::fpuReset()
  181504. {
  181505. #if JUCE_MSVC
  181506. _clearfp();
  181507. #endif
  181508. }
  181509. void PlatformUtilities::beep()
  181510. {
  181511. MessageBeep (MB_OK);
  181512. }
  181513. #endif
  181514. /*** End of inlined file: juce_win32_PlatformUtils.cpp ***/
  181515. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  181516. /*** Start of inlined file: juce_win32_Messaging.cpp ***/
  181517. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  181518. // compiled on its own).
  181519. #if JUCE_INCLUDED_FILE
  181520. static const unsigned int specialId = WM_APP + 0x4400;
  181521. static const unsigned int broadcastId = WM_APP + 0x4403;
  181522. static const unsigned int specialCallbackId = WM_APP + 0x4402;
  181523. static const TCHAR* const messageWindowName = _T("JUCEWindow");
  181524. HWND juce_messageWindowHandle = 0;
  181525. extern long improbableWindowNumber; // defined in windowing.cpp
  181526. #ifndef WM_APPCOMMAND
  181527. #define WM_APPCOMMAND 0x0319
  181528. #endif
  181529. static LRESULT CALLBACK juce_MessageWndProc (HWND h,
  181530. const UINT message,
  181531. const WPARAM wParam,
  181532. const LPARAM lParam) throw()
  181533. {
  181534. JUCE_TRY
  181535. {
  181536. if (h == juce_messageWindowHandle)
  181537. {
  181538. if (message == specialCallbackId)
  181539. {
  181540. MessageCallbackFunction* const func = (MessageCallbackFunction*) wParam;
  181541. return (LRESULT) (*func) ((void*) lParam);
  181542. }
  181543. else if (message == specialId)
  181544. {
  181545. // these are trapped early in the dispatch call, but must also be checked
  181546. // here in case there are windows modal dialog boxes doing their own
  181547. // dispatch loop and not calling our version
  181548. MessageManager::getInstance()->deliverMessage ((void*) lParam);
  181549. return 0;
  181550. }
  181551. else if (message == broadcastId)
  181552. {
  181553. const ScopedPointer <String> messageString ((String*) lParam);
  181554. MessageManager::getInstance()->deliverBroadcastMessage (*messageString);
  181555. return 0;
  181556. }
  181557. else if (message == WM_COPYDATA && ((const COPYDATASTRUCT*) lParam)->dwData == broadcastId)
  181558. {
  181559. const String messageString ((const juce_wchar*) ((const COPYDATASTRUCT*) lParam)->lpData,
  181560. ((const COPYDATASTRUCT*) lParam)->cbData / sizeof (juce_wchar));
  181561. PostMessage (juce_messageWindowHandle, broadcastId, 0, (LPARAM) new String (messageString));
  181562. return 0;
  181563. }
  181564. }
  181565. }
  181566. JUCE_CATCH_EXCEPTION
  181567. return DefWindowProc (h, message, wParam, lParam);
  181568. }
  181569. static bool isEventBlockedByModalComps (MSG& m)
  181570. {
  181571. if (Component::getNumCurrentlyModalComponents() == 0
  181572. || GetWindowLong (m.hwnd, GWLP_USERDATA) == improbableWindowNumber)
  181573. return false;
  181574. switch (m.message)
  181575. {
  181576. case WM_MOUSEMOVE:
  181577. case WM_NCMOUSEMOVE:
  181578. case 0x020A: /* WM_MOUSEWHEEL */
  181579. case 0x020E: /* WM_MOUSEHWHEEL */
  181580. case WM_KEYUP:
  181581. case WM_SYSKEYUP:
  181582. case WM_CHAR:
  181583. case WM_APPCOMMAND:
  181584. case WM_LBUTTONUP:
  181585. case WM_MBUTTONUP:
  181586. case WM_RBUTTONUP:
  181587. case WM_MOUSEACTIVATE:
  181588. case WM_NCMOUSEHOVER:
  181589. case WM_MOUSEHOVER:
  181590. return true;
  181591. case WM_NCLBUTTONDOWN:
  181592. case WM_NCLBUTTONDBLCLK:
  181593. case WM_NCRBUTTONDOWN:
  181594. case WM_NCRBUTTONDBLCLK:
  181595. case WM_NCMBUTTONDOWN:
  181596. case WM_NCMBUTTONDBLCLK:
  181597. case WM_LBUTTONDOWN:
  181598. case WM_LBUTTONDBLCLK:
  181599. case WM_MBUTTONDOWN:
  181600. case WM_MBUTTONDBLCLK:
  181601. case WM_RBUTTONDOWN:
  181602. case WM_RBUTTONDBLCLK:
  181603. case WM_KEYDOWN:
  181604. case WM_SYSKEYDOWN:
  181605. {
  181606. Component* const modal = Component::getCurrentlyModalComponent (0);
  181607. if (modal != 0)
  181608. modal->inputAttemptWhenModal();
  181609. return true;
  181610. }
  181611. default:
  181612. break;
  181613. }
  181614. return false;
  181615. }
  181616. bool juce_dispatchNextMessageOnSystemQueue (const bool returnIfNoPendingMessages)
  181617. {
  181618. MSG m;
  181619. if (returnIfNoPendingMessages && ! PeekMessage (&m, (HWND) 0, 0, 0, 0))
  181620. return false;
  181621. if (GetMessage (&m, (HWND) 0, 0, 0) >= 0)
  181622. {
  181623. if (m.message == specialId && m.hwnd == juce_messageWindowHandle)
  181624. {
  181625. MessageManager::getInstance()->deliverMessage ((void*) m.lParam);
  181626. }
  181627. else if (m.message == WM_QUIT)
  181628. {
  181629. if (JUCEApplication::getInstance())
  181630. JUCEApplication::getInstance()->systemRequestedQuit();
  181631. }
  181632. else if (! isEventBlockedByModalComps (m))
  181633. {
  181634. if ((m.message == WM_LBUTTONDOWN || m.message == WM_RBUTTONDOWN)
  181635. && GetWindowLong (m.hwnd, GWLP_USERDATA) != improbableWindowNumber)
  181636. {
  181637. // if it's someone else's window being clicked on, and the focus is
  181638. // currently on a juce window, pass the kb focus over..
  181639. HWND currentFocus = GetFocus();
  181640. if (currentFocus == 0 || GetWindowLong (currentFocus, GWLP_USERDATA) == improbableWindowNumber)
  181641. SetFocus (m.hwnd);
  181642. }
  181643. TranslateMessage (&m);
  181644. DispatchMessage (&m);
  181645. }
  181646. }
  181647. return true;
  181648. }
  181649. bool juce_postMessageToSystemQueue (void* message)
  181650. {
  181651. return PostMessage (juce_messageWindowHandle, specialId, 0, (LPARAM) message) != 0;
  181652. }
  181653. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
  181654. void* userData)
  181655. {
  181656. if (MessageManager::getInstance()->isThisTheMessageThread())
  181657. {
  181658. return (*callback) (userData);
  181659. }
  181660. else
  181661. {
  181662. // If a thread has a MessageManagerLock and then tries to call this method, it'll
  181663. // deadlock because the message manager is blocked from running, and can't
  181664. // call your function..
  181665. jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  181666. return (void*) SendMessage (juce_messageWindowHandle,
  181667. specialCallbackId,
  181668. (WPARAM) callback,
  181669. (LPARAM) userData);
  181670. }
  181671. }
  181672. static BOOL CALLBACK BroadcastEnumWindowProc (HWND hwnd, LPARAM lParam)
  181673. {
  181674. if (hwnd != juce_messageWindowHandle)
  181675. (reinterpret_cast <VoidArray*> (lParam))->add ((void*) hwnd);
  181676. return TRUE;
  181677. }
  181678. void MessageManager::broadcastMessage (const String& value) throw()
  181679. {
  181680. VoidArray windows;
  181681. EnumWindows (&BroadcastEnumWindowProc, (LPARAM) &windows);
  181682. const String localCopy (value);
  181683. COPYDATASTRUCT data;
  181684. data.dwData = broadcastId;
  181685. data.cbData = (localCopy.length() + 1) * sizeof (juce_wchar);
  181686. data.lpData = (void*) (const juce_wchar*) localCopy;
  181687. for (int i = windows.size(); --i >= 0;)
  181688. {
  181689. HWND hwnd = (HWND) windows.getUnchecked(i);
  181690. TCHAR windowName [64]; // no need to read longer strings than this
  181691. GetWindowText (hwnd, windowName, 64);
  181692. windowName [63] = 0;
  181693. if (String (windowName) == String (messageWindowName))
  181694. {
  181695. DWORD_PTR result;
  181696. SendMessageTimeout (hwnd, WM_COPYDATA,
  181697. (WPARAM) juce_messageWindowHandle,
  181698. (LPARAM) &data,
  181699. SMTO_BLOCK | SMTO_ABORTIFHUNG,
  181700. 8000,
  181701. &result);
  181702. }
  181703. }
  181704. }
  181705. static const String getMessageWindowClassName()
  181706. {
  181707. // this name has to be different for each app/dll instance because otherwise
  181708. // poor old Win32 can get a bit confused (even despite it not being a process-global
  181709. // window class).
  181710. static int number = 0;
  181711. if (number == 0)
  181712. number = 0x7fffffff & (int) Time::getHighResolutionTicks();
  181713. return T("JUCEcs_") + String (number);
  181714. }
  181715. void MessageManager::doPlatformSpecificInitialisation()
  181716. {
  181717. OleInitialize (0);
  181718. const String className (getMessageWindowClassName());
  181719. HMODULE hmod = (HMODULE) PlatformUtilities::getCurrentModuleInstanceHandle();
  181720. WNDCLASSEX wc;
  181721. zerostruct (wc);
  181722. wc.cbSize = sizeof (wc);
  181723. wc.lpfnWndProc = (WNDPROC) juce_MessageWndProc;
  181724. wc.cbWndExtra = 4;
  181725. wc.hInstance = hmod;
  181726. wc.lpszClassName = className;
  181727. RegisterClassEx (&wc);
  181728. juce_messageWindowHandle = CreateWindow (wc.lpszClassName,
  181729. messageWindowName,
  181730. 0, 0, 0, 0, 0, 0, 0,
  181731. hmod, 0);
  181732. }
  181733. void MessageManager::doPlatformSpecificShutdown()
  181734. {
  181735. DestroyWindow (juce_messageWindowHandle);
  181736. UnregisterClass (getMessageWindowClassName(), 0);
  181737. OleUninitialize();
  181738. }
  181739. #endif
  181740. /*** End of inlined file: juce_win32_Messaging.cpp ***/
  181741. /*** Start of inlined file: juce_win32_Windowing.cpp ***/
  181742. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  181743. // compiled on its own).
  181744. #if JUCE_INCLUDED_FILE
  181745. #undef GetSystemMetrics // multimon overrides this for some reason and causes a mess..
  181746. // these are in the windows SDK, but need to be repeated here for GCC..
  181747. #ifndef GET_APPCOMMAND_LPARAM
  181748. #define FAPPCOMMAND_MASK 0xF000
  181749. #define GET_APPCOMMAND_LPARAM(lParam) ((short) (HIWORD (lParam) & ~FAPPCOMMAND_MASK))
  181750. #define APPCOMMAND_MEDIA_NEXTTRACK 11
  181751. #define APPCOMMAND_MEDIA_PREVIOUSTRACK 12
  181752. #define APPCOMMAND_MEDIA_STOP 13
  181753. #define APPCOMMAND_MEDIA_PLAY_PAUSE 14
  181754. #define WM_APPCOMMAND 0x0319
  181755. #endif
  181756. extern void juce_repeatLastProcessPriority(); // in juce_win32_Threads.cpp
  181757. extern void juce_CheckCurrentlyFocusedTopLevelWindow(); // in juce_TopLevelWindow.cpp
  181758. extern bool juce_IsRunningInWine();
  181759. #ifndef ULW_ALPHA
  181760. #define ULW_ALPHA 0x00000002
  181761. #endif
  181762. #ifndef AC_SRC_ALPHA
  181763. #define AC_SRC_ALPHA 0x01
  181764. #endif
  181765. #define DEBUG_REPAINT_TIMES 0
  181766. static HPALETTE palette = 0;
  181767. static bool createPaletteIfNeeded = true;
  181768. static bool shouldDeactivateTitleBar = true;
  181769. static HICON createHICONFromImage (const Image& image, const BOOL isIcon, int hotspotX, int hotspotY) throw();
  181770. #define WM_TRAYNOTIFY WM_USER + 100
  181771. using ::abs;
  181772. typedef BOOL (WINAPI* UpdateLayeredWinFunc) (HWND, HDC, POINT*, SIZE*, HDC, POINT*, COLORREF, BLENDFUNCTION*, DWORD);
  181773. static UpdateLayeredWinFunc updateLayeredWindow = 0;
  181774. bool Desktop::canUseSemiTransparentWindows() throw()
  181775. {
  181776. if (updateLayeredWindow == 0)
  181777. {
  181778. if (! juce_IsRunningInWine())
  181779. {
  181780. HMODULE user32Mod = GetModuleHandle (_T("user32.dll"));
  181781. updateLayeredWindow = (UpdateLayeredWinFunc) GetProcAddress (user32Mod, "UpdateLayeredWindow");
  181782. }
  181783. }
  181784. return updateLayeredWindow != 0;
  181785. }
  181786. #undef DefWindowProc
  181787. #define DefWindowProc DefWindowProcW
  181788. const int extendedKeyModifier = 0x10000;
  181789. const int KeyPress::spaceKey = VK_SPACE;
  181790. const int KeyPress::returnKey = VK_RETURN;
  181791. const int KeyPress::escapeKey = VK_ESCAPE;
  181792. const int KeyPress::backspaceKey = VK_BACK;
  181793. const int KeyPress::deleteKey = VK_DELETE | extendedKeyModifier;
  181794. const int KeyPress::insertKey = VK_INSERT | extendedKeyModifier;
  181795. const int KeyPress::tabKey = VK_TAB;
  181796. const int KeyPress::leftKey = VK_LEFT | extendedKeyModifier;
  181797. const int KeyPress::rightKey = VK_RIGHT | extendedKeyModifier;
  181798. const int KeyPress::upKey = VK_UP | extendedKeyModifier;
  181799. const int KeyPress::downKey = VK_DOWN | extendedKeyModifier;
  181800. const int KeyPress::homeKey = VK_HOME | extendedKeyModifier;
  181801. const int KeyPress::endKey = VK_END | extendedKeyModifier;
  181802. const int KeyPress::pageUpKey = VK_PRIOR | extendedKeyModifier;
  181803. const int KeyPress::pageDownKey = VK_NEXT | extendedKeyModifier;
  181804. const int KeyPress::F1Key = VK_F1 | extendedKeyModifier;
  181805. const int KeyPress::F2Key = VK_F2 | extendedKeyModifier;
  181806. const int KeyPress::F3Key = VK_F3 | extendedKeyModifier;
  181807. const int KeyPress::F4Key = VK_F4 | extendedKeyModifier;
  181808. const int KeyPress::F5Key = VK_F5 | extendedKeyModifier;
  181809. const int KeyPress::F6Key = VK_F6 | extendedKeyModifier;
  181810. const int KeyPress::F7Key = VK_F7 | extendedKeyModifier;
  181811. const int KeyPress::F8Key = VK_F8 | extendedKeyModifier;
  181812. const int KeyPress::F9Key = VK_F9 | extendedKeyModifier;
  181813. const int KeyPress::F10Key = VK_F10 | extendedKeyModifier;
  181814. const int KeyPress::F11Key = VK_F11 | extendedKeyModifier;
  181815. const int KeyPress::F12Key = VK_F12 | extendedKeyModifier;
  181816. const int KeyPress::F13Key = VK_F13 | extendedKeyModifier;
  181817. const int KeyPress::F14Key = VK_F14 | extendedKeyModifier;
  181818. const int KeyPress::F15Key = VK_F15 | extendedKeyModifier;
  181819. const int KeyPress::F16Key = VK_F16 | extendedKeyModifier;
  181820. const int KeyPress::numberPad0 = VK_NUMPAD0 | extendedKeyModifier;
  181821. const int KeyPress::numberPad1 = VK_NUMPAD1 | extendedKeyModifier;
  181822. const int KeyPress::numberPad2 = VK_NUMPAD2 | extendedKeyModifier;
  181823. const int KeyPress::numberPad3 = VK_NUMPAD3 | extendedKeyModifier;
  181824. const int KeyPress::numberPad4 = VK_NUMPAD4 | extendedKeyModifier;
  181825. const int KeyPress::numberPad5 = VK_NUMPAD5 | extendedKeyModifier;
  181826. const int KeyPress::numberPad6 = VK_NUMPAD6 | extendedKeyModifier;
  181827. const int KeyPress::numberPad7 = VK_NUMPAD7 | extendedKeyModifier;
  181828. const int KeyPress::numberPad8 = VK_NUMPAD8 | extendedKeyModifier;
  181829. const int KeyPress::numberPad9 = VK_NUMPAD9 | extendedKeyModifier;
  181830. const int KeyPress::numberPadAdd = VK_ADD | extendedKeyModifier;
  181831. const int KeyPress::numberPadSubtract = VK_SUBTRACT | extendedKeyModifier;
  181832. const int KeyPress::numberPadMultiply = VK_MULTIPLY | extendedKeyModifier;
  181833. const int KeyPress::numberPadDivide = VK_DIVIDE | extendedKeyModifier;
  181834. const int KeyPress::numberPadSeparator = VK_SEPARATOR | extendedKeyModifier;
  181835. const int KeyPress::numberPadDecimalPoint = VK_DECIMAL | extendedKeyModifier;
  181836. const int KeyPress::numberPadEquals = 0x92 /*VK_OEM_NEC_EQUAL*/ | extendedKeyModifier;
  181837. const int KeyPress::numberPadDelete = VK_DELETE | extendedKeyModifier;
  181838. const int KeyPress::playKey = 0x30000;
  181839. const int KeyPress::stopKey = 0x30001;
  181840. const int KeyPress::fastForwardKey = 0x30002;
  181841. const int KeyPress::rewindKey = 0x30003;
  181842. class WindowsBitmapImage : public Image
  181843. {
  181844. public:
  181845. HBITMAP hBitmap;
  181846. BITMAPV4HEADER bitmapInfo;
  181847. HDC hdc;
  181848. unsigned char* bitmapData;
  181849. WindowsBitmapImage (const PixelFormat format_,
  181850. const int w, const int h, const bool clearImage)
  181851. : Image (format_, w, h)
  181852. {
  181853. jassert (format_ == RGB || format_ == ARGB);
  181854. pixelStride = (format_ == RGB) ? 3 : 4;
  181855. zerostruct (bitmapInfo);
  181856. bitmapInfo.bV4Size = sizeof (BITMAPV4HEADER);
  181857. bitmapInfo.bV4Width = w;
  181858. bitmapInfo.bV4Height = h;
  181859. bitmapInfo.bV4Planes = 1;
  181860. bitmapInfo.bV4CSType = 1;
  181861. bitmapInfo.bV4BitCount = (unsigned short) (pixelStride * 8);
  181862. if (format_ == ARGB)
  181863. {
  181864. bitmapInfo.bV4AlphaMask = 0xff000000;
  181865. bitmapInfo.bV4RedMask = 0xff0000;
  181866. bitmapInfo.bV4GreenMask = 0xff00;
  181867. bitmapInfo.bV4BlueMask = 0xff;
  181868. bitmapInfo.bV4V4Compression = BI_BITFIELDS;
  181869. }
  181870. else
  181871. {
  181872. bitmapInfo.bV4V4Compression = BI_RGB;
  181873. }
  181874. lineStride = -((w * pixelStride + 3) & ~3);
  181875. HDC dc = GetDC (0);
  181876. hdc = CreateCompatibleDC (dc);
  181877. ReleaseDC (0, dc);
  181878. SetMapMode (hdc, MM_TEXT);
  181879. hBitmap = CreateDIBSection (hdc,
  181880. (BITMAPINFO*) &(bitmapInfo),
  181881. DIB_RGB_COLORS,
  181882. (void**) &bitmapData,
  181883. 0, 0);
  181884. SelectObject (hdc, hBitmap);
  181885. if (format_ == ARGB && clearImage)
  181886. zeromem (bitmapData, abs (h * lineStride));
  181887. imageData = bitmapData - (lineStride * (h - 1));
  181888. }
  181889. ~WindowsBitmapImage()
  181890. {
  181891. DeleteDC (hdc);
  181892. DeleteObject (hBitmap);
  181893. }
  181894. void blitToWindow (HWND hwnd, HDC dc, const bool transparent,
  181895. const int x, const int y,
  181896. const RectangleList& maskedRegion) throw()
  181897. {
  181898. static HDRAWDIB hdd = 0;
  181899. static bool needToCreateDrawDib = true;
  181900. if (needToCreateDrawDib)
  181901. {
  181902. needToCreateDrawDib = false;
  181903. HDC dc = GetDC (0);
  181904. const int n = GetDeviceCaps (dc, BITSPIXEL);
  181905. ReleaseDC (0, dc);
  181906. // only open if we're not palettised
  181907. if (n > 8)
  181908. hdd = DrawDibOpen();
  181909. }
  181910. if (createPaletteIfNeeded)
  181911. {
  181912. HDC dc = GetDC (0);
  181913. const int n = GetDeviceCaps (dc, BITSPIXEL);
  181914. ReleaseDC (0, dc);
  181915. if (n <= 8)
  181916. palette = CreateHalftonePalette (dc);
  181917. createPaletteIfNeeded = false;
  181918. }
  181919. if (palette != 0)
  181920. {
  181921. SelectPalette (dc, palette, FALSE);
  181922. RealizePalette (dc);
  181923. SetStretchBltMode (dc, HALFTONE);
  181924. }
  181925. SetMapMode (dc, MM_TEXT);
  181926. if (transparent)
  181927. {
  181928. POINT p, pos;
  181929. SIZE size;
  181930. RECT windowBounds;
  181931. GetWindowRect (hwnd, &windowBounds);
  181932. p.x = -x;
  181933. p.y = -y;
  181934. pos.x = windowBounds.left;
  181935. pos.y = windowBounds.top;
  181936. size.cx = windowBounds.right - windowBounds.left;
  181937. size.cy = windowBounds.bottom - windowBounds.top;
  181938. BLENDFUNCTION bf;
  181939. bf.AlphaFormat = AC_SRC_ALPHA;
  181940. bf.BlendFlags = 0;
  181941. bf.BlendOp = AC_SRC_OVER;
  181942. bf.SourceConstantAlpha = 0xff;
  181943. if (! maskedRegion.isEmpty())
  181944. {
  181945. for (RectangleList::Iterator i (maskedRegion); i.next();)
  181946. {
  181947. const Rectangle<int>& r = *i.getRectangle();
  181948. ExcludeClipRect (hdc, r.getX(), r.getY(), r.getRight(), r.getBottom());
  181949. }
  181950. }
  181951. updateLayeredWindow (hwnd, 0, &pos, &size, hdc, &p, 0, &bf, ULW_ALPHA);
  181952. }
  181953. else
  181954. {
  181955. int savedDC = 0;
  181956. if (! maskedRegion.isEmpty())
  181957. {
  181958. savedDC = SaveDC (dc);
  181959. for (RectangleList::Iterator i (maskedRegion); i.next();)
  181960. {
  181961. const Rectangle<int>& r = *i.getRectangle();
  181962. ExcludeClipRect (dc, r.getX(), r.getY(), r.getRight(), r.getBottom());
  181963. }
  181964. }
  181965. const int w = getWidth();
  181966. const int h = getHeight();
  181967. if (hdd == 0)
  181968. {
  181969. StretchDIBits (dc,
  181970. x, y, w, h,
  181971. 0, 0, w, h,
  181972. bitmapData, (const BITMAPINFO*) &bitmapInfo,
  181973. DIB_RGB_COLORS, SRCCOPY);
  181974. }
  181975. else
  181976. {
  181977. DrawDibDraw (hdd, dc, x, y, -1, -1,
  181978. (BITMAPINFOHEADER*) &bitmapInfo, bitmapData,
  181979. 0, 0, w, h, 0);
  181980. }
  181981. if (! maskedRegion.isEmpty())
  181982. RestoreDC (dc, savedDC);
  181983. }
  181984. }
  181985. juce_UseDebuggingNewOperator
  181986. private:
  181987. WindowsBitmapImage (const WindowsBitmapImage&);
  181988. const WindowsBitmapImage& operator= (const WindowsBitmapImage&);
  181989. };
  181990. long improbableWindowNumber = 0xf965aa01; // also referenced by messaging.cpp
  181991. static int currentModifiers = 0;
  181992. static int modifiersAtLastCallback = 0;
  181993. static void updateKeyModifiers() throw()
  181994. {
  181995. currentModifiers &= ~(ModifierKeys::shiftModifier
  181996. | ModifierKeys::ctrlModifier
  181997. | ModifierKeys::altModifier);
  181998. if ((GetKeyState (VK_SHIFT) & 0x8000) != 0)
  181999. currentModifiers |= ModifierKeys::shiftModifier;
  182000. if ((GetKeyState (VK_CONTROL) & 0x8000) != 0)
  182001. currentModifiers |= ModifierKeys::ctrlModifier;
  182002. if ((GetKeyState (VK_MENU) & 0x8000) != 0)
  182003. currentModifiers |= ModifierKeys::altModifier;
  182004. if ((GetKeyState (VK_RMENU) & 0x8000) != 0)
  182005. currentModifiers &= ~(ModifierKeys::ctrlModifier | ModifierKeys::altModifier);
  182006. }
  182007. void ModifierKeys::updateCurrentModifiers() throw()
  182008. {
  182009. currentModifierFlags = currentModifiers;
  182010. }
  182011. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  182012. {
  182013. SHORT k = (SHORT) keyCode;
  182014. if ((keyCode & extendedKeyModifier) == 0
  182015. && (k >= (SHORT) T('a') && k <= (SHORT) T('z')))
  182016. k += (SHORT) T('A') - (SHORT) T('a');
  182017. const SHORT translatedValues[] = { (SHORT) ',', VK_OEM_COMMA,
  182018. (SHORT) '+', VK_OEM_PLUS,
  182019. (SHORT) '-', VK_OEM_MINUS,
  182020. (SHORT) '.', VK_OEM_PERIOD,
  182021. (SHORT) ';', VK_OEM_1,
  182022. (SHORT) ':', VK_OEM_1,
  182023. (SHORT) '/', VK_OEM_2,
  182024. (SHORT) '?', VK_OEM_2,
  182025. (SHORT) '[', VK_OEM_4,
  182026. (SHORT) ']', VK_OEM_6 };
  182027. for (int i = 0; i < numElementsInArray (translatedValues); i += 2)
  182028. if (k == translatedValues [i])
  182029. k = translatedValues [i + 1];
  182030. return (GetKeyState (k) & 0x8000) != 0;
  182031. }
  182032. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  182033. {
  182034. updateKeyModifiers();
  182035. currentModifiers &= ~ModifierKeys::allMouseButtonModifiers;
  182036. if ((GetKeyState (VK_LBUTTON) & 0x8000) != 0)
  182037. currentModifiers |= ModifierKeys::leftButtonModifier;
  182038. if ((GetKeyState (VK_RBUTTON) & 0x8000) != 0)
  182039. currentModifiers |= ModifierKeys::rightButtonModifier;
  182040. if ((GetKeyState (VK_MBUTTON) & 0x8000) != 0)
  182041. currentModifiers |= ModifierKeys::middleButtonModifier;
  182042. return ModifierKeys (currentModifiers);
  182043. }
  182044. static int64 getMouseEventTime() throw()
  182045. {
  182046. static int64 eventTimeOffset = 0;
  182047. static DWORD lastMessageTime = 0;
  182048. const DWORD thisMessageTime = GetMessageTime();
  182049. if (thisMessageTime < lastMessageTime || lastMessageTime == 0)
  182050. {
  182051. lastMessageTime = thisMessageTime;
  182052. eventTimeOffset = Time::currentTimeMillis() - thisMessageTime;
  182053. }
  182054. return eventTimeOffset + thisMessageTime;
  182055. }
  182056. static void* callFunctionIfNotLocked (MessageCallbackFunction* callback, void* userData)
  182057. {
  182058. if (MessageManager::getInstance()->currentThreadHasLockedMessageManager())
  182059. return callback (userData);
  182060. else
  182061. return MessageManager::getInstance()->callFunctionOnMessageThread (callback, userData);
  182062. }
  182063. class Win32ComponentPeer : public ComponentPeer
  182064. {
  182065. public:
  182066. Win32ComponentPeer (Component* const component,
  182067. const int windowStyleFlags)
  182068. : ComponentPeer (component, windowStyleFlags),
  182069. dontRepaint (false),
  182070. fullScreen (false),
  182071. isDragging (false),
  182072. isMouseOver (false),
  182073. hasCreatedCaret (false),
  182074. currentWindowIcon (0),
  182075. taskBarIcon (0),
  182076. dropTarget (0)
  182077. {
  182078. callFunctionIfNotLocked (&createWindowCallback, (void*) this);
  182079. setTitle (component->getName());
  182080. if ((windowStyleFlags & windowHasDropShadow) != 0
  182081. && Desktop::canUseSemiTransparentWindows())
  182082. {
  182083. shadower = component->getLookAndFeel().createDropShadowerForComponent (component);
  182084. if (shadower != 0)
  182085. shadower->setOwner (component);
  182086. }
  182087. else
  182088. {
  182089. shadower = 0;
  182090. }
  182091. }
  182092. ~Win32ComponentPeer()
  182093. {
  182094. setTaskBarIcon (0);
  182095. deleteAndZero (shadower);
  182096. // do this before the next bit to avoid messages arriving for this window
  182097. // before it's destroyed
  182098. SetWindowLongPtr (hwnd, GWLP_USERDATA, 0);
  182099. callFunctionIfNotLocked (&destroyWindowCallback, (void*) hwnd);
  182100. if (currentWindowIcon != 0)
  182101. DestroyIcon (currentWindowIcon);
  182102. if (dropTarget != 0)
  182103. {
  182104. dropTarget->Release();
  182105. dropTarget = 0;
  182106. }
  182107. }
  182108. void* getNativeHandle() const
  182109. {
  182110. return (void*) hwnd;
  182111. }
  182112. void setVisible (bool shouldBeVisible)
  182113. {
  182114. ShowWindow (hwnd, shouldBeVisible ? SW_SHOWNA : SW_HIDE);
  182115. if (shouldBeVisible)
  182116. InvalidateRect (hwnd, 0, 0);
  182117. else
  182118. lastPaintTime = 0;
  182119. }
  182120. void setTitle (const String& title)
  182121. {
  182122. SetWindowText (hwnd, title);
  182123. }
  182124. void setPosition (int x, int y)
  182125. {
  182126. offsetWithinParent (x, y);
  182127. SetWindowPos (hwnd, 0,
  182128. x - windowBorder.getLeft(),
  182129. y - windowBorder.getTop(),
  182130. 0, 0,
  182131. SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  182132. }
  182133. void repaintNowIfTransparent()
  182134. {
  182135. if (isTransparent() && lastPaintTime > 0 && Time::getMillisecondCounter() > lastPaintTime + 30)
  182136. handlePaintMessage();
  182137. }
  182138. void updateBorderSize()
  182139. {
  182140. WINDOWINFO info;
  182141. info.cbSize = sizeof (info);
  182142. if (GetWindowInfo (hwnd, &info))
  182143. {
  182144. windowBorder = BorderSize (info.rcClient.top - info.rcWindow.top,
  182145. info.rcClient.left - info.rcWindow.left,
  182146. info.rcWindow.bottom - info.rcClient.bottom,
  182147. info.rcWindow.right - info.rcClient.right);
  182148. }
  182149. }
  182150. void setSize (int w, int h)
  182151. {
  182152. SetWindowPos (hwnd, 0, 0, 0,
  182153. w + windowBorder.getLeftAndRight(),
  182154. h + windowBorder.getTopAndBottom(),
  182155. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  182156. updateBorderSize();
  182157. repaintNowIfTransparent();
  182158. }
  182159. void setBounds (int x, int y, int w, int h, const bool isNowFullScreen)
  182160. {
  182161. fullScreen = isNowFullScreen;
  182162. offsetWithinParent (x, y);
  182163. SetWindowPos (hwnd, 0,
  182164. x - windowBorder.getLeft(),
  182165. y - windowBorder.getTop(),
  182166. w + windowBorder.getLeftAndRight(),
  182167. h + windowBorder.getTopAndBottom(),
  182168. SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  182169. updateBorderSize();
  182170. repaintNowIfTransparent();
  182171. }
  182172. void getBounds (int& x, int& y, int& w, int& h) const
  182173. {
  182174. RECT r;
  182175. GetWindowRect (hwnd, &r);
  182176. x = r.left;
  182177. y = r.top;
  182178. w = r.right - x;
  182179. h = r.bottom - y;
  182180. HWND parentH = GetParent (hwnd);
  182181. if (parentH != 0)
  182182. {
  182183. GetWindowRect (parentH, &r);
  182184. x -= r.left;
  182185. y -= r.top;
  182186. }
  182187. x += windowBorder.getLeft();
  182188. y += windowBorder.getTop();
  182189. w -= windowBorder.getLeftAndRight();
  182190. h -= windowBorder.getTopAndBottom();
  182191. }
  182192. int getScreenX() const
  182193. {
  182194. RECT r;
  182195. GetWindowRect (hwnd, &r);
  182196. return r.left + windowBorder.getLeft();
  182197. }
  182198. int getScreenY() const
  182199. {
  182200. RECT r;
  182201. GetWindowRect (hwnd, &r);
  182202. return r.top + windowBorder.getTop();
  182203. }
  182204. void relativePositionToGlobal (int& x, int& y)
  182205. {
  182206. RECT r;
  182207. GetWindowRect (hwnd, &r);
  182208. x += r.left + windowBorder.getLeft();
  182209. y += r.top + windowBorder.getTop();
  182210. }
  182211. void globalPositionToRelative (int& x, int& y)
  182212. {
  182213. RECT r;
  182214. GetWindowRect (hwnd, &r);
  182215. x -= r.left + windowBorder.getLeft();
  182216. y -= r.top + windowBorder.getTop();
  182217. }
  182218. void setMinimised (bool shouldBeMinimised)
  182219. {
  182220. if (shouldBeMinimised != isMinimised())
  182221. ShowWindow (hwnd, shouldBeMinimised ? SW_MINIMIZE : SW_SHOWNORMAL);
  182222. }
  182223. bool isMinimised() const
  182224. {
  182225. WINDOWPLACEMENT wp;
  182226. wp.length = sizeof (WINDOWPLACEMENT);
  182227. GetWindowPlacement (hwnd, &wp);
  182228. return wp.showCmd == SW_SHOWMINIMIZED;
  182229. }
  182230. void setFullScreen (bool shouldBeFullScreen)
  182231. {
  182232. setMinimised (false);
  182233. if (fullScreen != shouldBeFullScreen)
  182234. {
  182235. fullScreen = shouldBeFullScreen;
  182236. const ComponentDeletionWatcher deletionChecker (component);
  182237. if (! fullScreen)
  182238. {
  182239. const Rectangle<int> boundsCopy (lastNonFullscreenBounds);
  182240. if (hasTitleBar())
  182241. ShowWindow (hwnd, SW_SHOWNORMAL);
  182242. if (! boundsCopy.isEmpty())
  182243. {
  182244. setBounds (boundsCopy.getX(),
  182245. boundsCopy.getY(),
  182246. boundsCopy.getWidth(),
  182247. boundsCopy.getHeight(),
  182248. false);
  182249. }
  182250. }
  182251. else
  182252. {
  182253. if (hasTitleBar())
  182254. ShowWindow (hwnd, SW_SHOWMAXIMIZED);
  182255. else
  182256. SendMessageW (hwnd, WM_SETTINGCHANGE, 0, 0);
  182257. }
  182258. if (! deletionChecker.hasBeenDeleted())
  182259. handleMovedOrResized();
  182260. }
  182261. }
  182262. bool isFullScreen() const
  182263. {
  182264. if (! hasTitleBar())
  182265. return fullScreen;
  182266. WINDOWPLACEMENT wp;
  182267. wp.length = sizeof (wp);
  182268. GetWindowPlacement (hwnd, &wp);
  182269. return wp.showCmd == SW_SHOWMAXIMIZED;
  182270. }
  182271. bool contains (int x, int y, bool trueIfInAChildWindow) const
  182272. {
  182273. RECT r;
  182274. GetWindowRect (hwnd, &r);
  182275. POINT p;
  182276. p.x = x + r.left + windowBorder.getLeft();
  182277. p.y = y + r.top + windowBorder.getTop();
  182278. HWND w = WindowFromPoint (p);
  182279. return w == hwnd || (trueIfInAChildWindow && (IsChild (hwnd, w) != 0));
  182280. }
  182281. const BorderSize getFrameSize() const
  182282. {
  182283. return windowBorder;
  182284. }
  182285. bool setAlwaysOnTop (bool alwaysOnTop)
  182286. {
  182287. const bool oldDeactivate = shouldDeactivateTitleBar;
  182288. shouldDeactivateTitleBar = ((styleFlags & windowIsTemporary) == 0);
  182289. SetWindowPos (hwnd, alwaysOnTop ? HWND_TOPMOST : HWND_NOTOPMOST,
  182290. 0, 0, 0, 0,
  182291. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  182292. shouldDeactivateTitleBar = oldDeactivate;
  182293. if (shadower != 0)
  182294. shadower->componentBroughtToFront (*component);
  182295. return true;
  182296. }
  182297. void toFront (bool makeActive)
  182298. {
  182299. setMinimised (false);
  182300. const bool oldDeactivate = shouldDeactivateTitleBar;
  182301. shouldDeactivateTitleBar = ((styleFlags & windowIsTemporary) == 0);
  182302. callFunctionIfNotLocked (makeActive ? &toFrontCallback1
  182303. : &toFrontCallback2,
  182304. (void*) hwnd);
  182305. shouldDeactivateTitleBar = oldDeactivate;
  182306. if (! makeActive)
  182307. {
  182308. // in this case a broughttofront call won't have occured, so do it now..
  182309. handleBroughtToFront();
  182310. }
  182311. }
  182312. void toBehind (ComponentPeer* other)
  182313. {
  182314. Win32ComponentPeer* const otherPeer = dynamic_cast <Win32ComponentPeer*> (other);
  182315. jassert (otherPeer != 0); // wrong type of window?
  182316. if (otherPeer != 0)
  182317. {
  182318. setMinimised (false);
  182319. // must be careful not to try to put a topmost window behind a normal one, or win32
  182320. // promotes the normal one to be topmost!
  182321. if (getComponent()->isAlwaysOnTop() == otherPeer->getComponent()->isAlwaysOnTop())
  182322. SetWindowPos (hwnd, otherPeer->hwnd, 0, 0, 0, 0,
  182323. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  182324. else if (otherPeer->getComponent()->isAlwaysOnTop())
  182325. SetWindowPos (hwnd, HWND_TOP, 0, 0, 0, 0,
  182326. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  182327. }
  182328. }
  182329. bool isFocused() const
  182330. {
  182331. return callFunctionIfNotLocked (&getFocusCallback, 0) == (void*) hwnd;
  182332. }
  182333. void grabFocus()
  182334. {
  182335. const bool oldDeactivate = shouldDeactivateTitleBar;
  182336. shouldDeactivateTitleBar = ((styleFlags & windowIsTemporary) == 0);
  182337. callFunctionIfNotLocked (&setFocusCallback, (void*) hwnd);
  182338. shouldDeactivateTitleBar = oldDeactivate;
  182339. }
  182340. void textInputRequired (int /*x*/, int /*y*/)
  182341. {
  182342. if (! hasCreatedCaret)
  182343. {
  182344. hasCreatedCaret = true;
  182345. CreateCaret (hwnd, (HBITMAP) 1, 0, 0);
  182346. }
  182347. ShowCaret (hwnd);
  182348. SetCaretPos (0, 0);
  182349. }
  182350. void repaint (int x, int y, int w, int h)
  182351. {
  182352. const RECT r = { x, y, x + w, y + h };
  182353. InvalidateRect (hwnd, &r, FALSE);
  182354. }
  182355. void performAnyPendingRepaintsNow()
  182356. {
  182357. MSG m;
  182358. if (component->isVisible() && PeekMessage (&m, hwnd, WM_PAINT, WM_PAINT, PM_REMOVE))
  182359. DispatchMessage (&m);
  182360. }
  182361. static Win32ComponentPeer* getOwnerOfWindow (HWND h) throw()
  182362. {
  182363. if (h != 0 && GetWindowLongPtr (h, GWLP_USERDATA) == improbableWindowNumber)
  182364. return (Win32ComponentPeer*) (pointer_sized_int) GetWindowLongPtr (h, 8);
  182365. return 0;
  182366. }
  182367. void setTaskBarIcon (const Image* const image)
  182368. {
  182369. if (image != 0)
  182370. {
  182371. HICON hicon = createHICONFromImage (*image, TRUE, 0, 0);
  182372. if (taskBarIcon == 0)
  182373. {
  182374. taskBarIcon = new NOTIFYICONDATA();
  182375. taskBarIcon->cbSize = sizeof (NOTIFYICONDATA);
  182376. taskBarIcon->hWnd = (HWND) hwnd;
  182377. taskBarIcon->uID = (int) (pointer_sized_int) hwnd;
  182378. taskBarIcon->uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
  182379. taskBarIcon->uCallbackMessage = WM_TRAYNOTIFY;
  182380. taskBarIcon->hIcon = hicon;
  182381. taskBarIcon->szTip[0] = 0;
  182382. Shell_NotifyIcon (NIM_ADD, taskBarIcon);
  182383. }
  182384. else
  182385. {
  182386. HICON oldIcon = taskBarIcon->hIcon;
  182387. taskBarIcon->hIcon = hicon;
  182388. taskBarIcon->uFlags = NIF_ICON;
  182389. Shell_NotifyIcon (NIM_MODIFY, taskBarIcon);
  182390. DestroyIcon (oldIcon);
  182391. }
  182392. DestroyIcon (hicon);
  182393. }
  182394. else if (taskBarIcon != 0)
  182395. {
  182396. taskBarIcon->uFlags = 0;
  182397. Shell_NotifyIcon (NIM_DELETE, taskBarIcon);
  182398. DestroyIcon (taskBarIcon->hIcon);
  182399. deleteAndZero (taskBarIcon);
  182400. }
  182401. }
  182402. void setTaskBarIconToolTip (const String& toolTip) const
  182403. {
  182404. if (taskBarIcon != 0)
  182405. {
  182406. taskBarIcon->uFlags = NIF_TIP;
  182407. toolTip.copyToBuffer (taskBarIcon->szTip, sizeof (taskBarIcon->szTip) - 1);
  182408. Shell_NotifyIcon (NIM_MODIFY, taskBarIcon);
  182409. }
  182410. }
  182411. bool isInside (HWND h) const
  182412. {
  182413. return GetAncestor (hwnd, GA_ROOT) == h;
  182414. }
  182415. juce_UseDebuggingNewOperator
  182416. bool dontRepaint;
  182417. private:
  182418. HWND hwnd;
  182419. DropShadower* shadower;
  182420. bool fullScreen, isDragging, isMouseOver, hasCreatedCaret;
  182421. BorderSize windowBorder;
  182422. HICON currentWindowIcon;
  182423. NOTIFYICONDATA* taskBarIcon;
  182424. IDropTarget* dropTarget;
  182425. class TemporaryImage : public Timer
  182426. {
  182427. public:
  182428. TemporaryImage()
  182429. : image (0)
  182430. {
  182431. }
  182432. ~TemporaryImage()
  182433. {
  182434. delete image;
  182435. }
  182436. WindowsBitmapImage* getImage (const bool transparent, const int w, const int h) throw()
  182437. {
  182438. const Image::PixelFormat format = transparent ? Image::ARGB : Image::RGB;
  182439. if (image == 0 || image->getWidth() < w || image->getHeight() < h || image->getFormat() != format)
  182440. {
  182441. delete image;
  182442. image = new WindowsBitmapImage (format, (w + 31) & ~31, (h + 31) & ~31, false);
  182443. }
  182444. startTimer (3000);
  182445. return image;
  182446. }
  182447. void timerCallback()
  182448. {
  182449. stopTimer();
  182450. deleteAndZero (image);
  182451. }
  182452. private:
  182453. WindowsBitmapImage* image;
  182454. TemporaryImage (const TemporaryImage&);
  182455. const TemporaryImage& operator= (const TemporaryImage&);
  182456. };
  182457. TemporaryImage offscreenImageGenerator;
  182458. class WindowClassHolder : public DeletedAtShutdown
  182459. {
  182460. public:
  182461. WindowClassHolder()
  182462. : windowClassName ("JUCE_")
  182463. {
  182464. // this name has to be different for each app/dll instance because otherwise
  182465. // poor old Win32 can get a bit confused (even despite it not being a process-global
  182466. // window class).
  182467. windowClassName << (int) (Time::currentTimeMillis() & 0x7fffffff);
  182468. HINSTANCE moduleHandle = (HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle();
  182469. TCHAR moduleFile [1024];
  182470. moduleFile[0] = 0;
  182471. GetModuleFileName (moduleHandle, moduleFile, 1024);
  182472. WORD iconNum = 0;
  182473. WNDCLASSEX wcex;
  182474. wcex.cbSize = sizeof (wcex);
  182475. wcex.style = CS_OWNDC;
  182476. wcex.lpfnWndProc = (WNDPROC) windowProc;
  182477. wcex.lpszClassName = windowClassName;
  182478. wcex.cbClsExtra = 0;
  182479. wcex.cbWndExtra = 32;
  182480. wcex.hInstance = moduleHandle;
  182481. wcex.hIcon = ExtractAssociatedIcon (moduleHandle, moduleFile, &iconNum);
  182482. iconNum = 1;
  182483. wcex.hIconSm = ExtractAssociatedIcon (moduleHandle, moduleFile, &iconNum);
  182484. wcex.hCursor = 0;
  182485. wcex.hbrBackground = 0;
  182486. wcex.lpszMenuName = 0;
  182487. RegisterClassEx (&wcex);
  182488. }
  182489. ~WindowClassHolder()
  182490. {
  182491. if (ComponentPeer::getNumPeers() == 0)
  182492. UnregisterClass (windowClassName, (HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle());
  182493. clearSingletonInstance();
  182494. }
  182495. String windowClassName;
  182496. juce_DeclareSingleton_SingleThreaded_Minimal (WindowClassHolder);
  182497. };
  182498. static void* createWindowCallback (void* userData)
  182499. {
  182500. ((Win32ComponentPeer*) userData)->createWindow();
  182501. return 0;
  182502. }
  182503. void createWindow()
  182504. {
  182505. DWORD exstyle = WS_EX_ACCEPTFILES;
  182506. DWORD type = WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
  182507. if (hasTitleBar())
  182508. {
  182509. type |= WS_OVERLAPPED;
  182510. exstyle |= WS_EX_APPWINDOW;
  182511. if ((styleFlags & windowHasCloseButton) != 0)
  182512. {
  182513. type |= WS_SYSMENU;
  182514. }
  182515. else
  182516. {
  182517. // annoyingly, windows won't let you have a min/max button without a close button
  182518. jassert ((styleFlags & (windowHasMinimiseButton | windowHasMaximiseButton)) == 0);
  182519. }
  182520. if ((styleFlags & windowIsResizable) != 0)
  182521. type |= WS_THICKFRAME;
  182522. }
  182523. else
  182524. {
  182525. type |= WS_POPUP | WS_SYSMENU;
  182526. if ((styleFlags & windowAppearsOnTaskbar) == 0)
  182527. exstyle |= WS_EX_TOOLWINDOW;
  182528. else
  182529. exstyle |= WS_EX_APPWINDOW;
  182530. }
  182531. if ((styleFlags & windowHasMinimiseButton) != 0)
  182532. type |= WS_MINIMIZEBOX;
  182533. if ((styleFlags & windowHasMaximiseButton) != 0)
  182534. type |= WS_MAXIMIZEBOX;
  182535. if ((styleFlags & windowIgnoresMouseClicks) != 0)
  182536. exstyle |= WS_EX_TRANSPARENT;
  182537. if ((styleFlags & windowIsSemiTransparent) != 0
  182538. && Desktop::canUseSemiTransparentWindows())
  182539. exstyle |= WS_EX_LAYERED;
  182540. hwnd = CreateWindowEx (exstyle, WindowClassHolder::getInstance()->windowClassName, L"", type, 0, 0, 0, 0, 0, 0, 0, 0);
  182541. if (hwnd != 0)
  182542. {
  182543. SetWindowLongPtr (hwnd, 0, 0);
  182544. SetWindowLongPtr (hwnd, 8, (LONG_PTR) this);
  182545. SetWindowLongPtr (hwnd, GWLP_USERDATA, improbableWindowNumber);
  182546. if (dropTarget == 0)
  182547. dropTarget = new JuceDropTarget (this);
  182548. RegisterDragDrop (hwnd, dropTarget);
  182549. updateBorderSize();
  182550. // Calling this function here is (for some reason) necessary to make Windows
  182551. // correctly enable the menu items that we specify in the wm_initmenu message.
  182552. GetSystemMenu (hwnd, false);
  182553. }
  182554. else
  182555. {
  182556. jassertfalse
  182557. }
  182558. }
  182559. static void* destroyWindowCallback (void* handle)
  182560. {
  182561. RevokeDragDrop ((HWND) handle);
  182562. DestroyWindow ((HWND) handle);
  182563. return 0;
  182564. }
  182565. static void* toFrontCallback1 (void* h)
  182566. {
  182567. SetForegroundWindow ((HWND) h);
  182568. return 0;
  182569. }
  182570. static void* toFrontCallback2 (void* h)
  182571. {
  182572. SetWindowPos ((HWND) h, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  182573. return 0;
  182574. }
  182575. static void* setFocusCallback (void* h)
  182576. {
  182577. SetFocus ((HWND) h);
  182578. return 0;
  182579. }
  182580. static void* getFocusCallback (void*)
  182581. {
  182582. return (void*) GetFocus();
  182583. }
  182584. void offsetWithinParent (int& x, int& y) const
  182585. {
  182586. if (isTransparent())
  182587. {
  182588. HWND parentHwnd = GetParent (hwnd);
  182589. if (parentHwnd != 0)
  182590. {
  182591. RECT parentRect;
  182592. GetWindowRect (parentHwnd, &parentRect);
  182593. x += parentRect.left;
  182594. y += parentRect.top;
  182595. }
  182596. }
  182597. }
  182598. bool isTransparent() const
  182599. {
  182600. return (GetWindowLong (hwnd, GWL_EXSTYLE) & WS_EX_LAYERED) != 0;
  182601. }
  182602. inline bool hasTitleBar() const throw() { return (styleFlags & windowHasTitleBar) != 0; }
  182603. void setIcon (const Image& newIcon)
  182604. {
  182605. HICON hicon = createHICONFromImage (newIcon, TRUE, 0, 0);
  182606. if (hicon != 0)
  182607. {
  182608. SendMessage (hwnd, WM_SETICON, ICON_BIG, (LPARAM) hicon);
  182609. SendMessage (hwnd, WM_SETICON, ICON_SMALL, (LPARAM) hicon);
  182610. if (currentWindowIcon != 0)
  182611. DestroyIcon (currentWindowIcon);
  182612. currentWindowIcon = hicon;
  182613. }
  182614. }
  182615. void handlePaintMessage()
  182616. {
  182617. #if DEBUG_REPAINT_TIMES
  182618. const double paintStart = Time::getMillisecondCounterHiRes();
  182619. #endif
  182620. HRGN rgn = CreateRectRgn (0, 0, 0, 0);
  182621. const int regionType = GetUpdateRgn (hwnd, rgn, false);
  182622. PAINTSTRUCT paintStruct;
  182623. HDC dc = BeginPaint (hwnd, &paintStruct); // Note this can immediately generate a WM_NCPAINT
  182624. // message and become re-entrant, but that's OK
  182625. // if something in a paint handler calls, e.g. a message box, this can become reentrant and
  182626. // corrupt the image it's using to paint into, so do a check here.
  182627. static bool reentrant = false;
  182628. if (reentrant)
  182629. {
  182630. DeleteObject (rgn);
  182631. EndPaint (hwnd, &paintStruct);
  182632. return;
  182633. }
  182634. reentrant = true;
  182635. // this is the rectangle to update..
  182636. int x = paintStruct.rcPaint.left;
  182637. int y = paintStruct.rcPaint.top;
  182638. int w = paintStruct.rcPaint.right - x;
  182639. int h = paintStruct.rcPaint.bottom - y;
  182640. const bool transparent = isTransparent();
  182641. if (transparent)
  182642. {
  182643. // it's not possible to have a transparent window with a title bar at the moment!
  182644. jassert (! hasTitleBar());
  182645. RECT r;
  182646. GetWindowRect (hwnd, &r);
  182647. x = y = 0;
  182648. w = r.right - r.left;
  182649. h = r.bottom - r.top;
  182650. }
  182651. if (w > 0 && h > 0)
  182652. {
  182653. clearMaskedRegion();
  182654. WindowsBitmapImage* const offscreenImage = offscreenImageGenerator.getImage (transparent, w, h);
  182655. RectangleList contextClip;
  182656. bool needToPaintAll = true;
  182657. if (regionType == COMPLEXREGION && ! transparent)
  182658. {
  182659. HRGN clipRgn = CreateRectRgnIndirect (&paintStruct.rcPaint);
  182660. CombineRgn (rgn, rgn, clipRgn, RGN_AND);
  182661. DeleteObject (clipRgn);
  182662. char rgnData [8192];
  182663. const DWORD res = GetRegionData (rgn, sizeof (rgnData), (RGNDATA*) rgnData);
  182664. if (res > 0 && res <= sizeof (rgnData))
  182665. {
  182666. const RGNDATAHEADER* const hdr = &(((const RGNDATA*) rgnData)->rdh);
  182667. if (hdr->iType == RDH_RECTANGLES
  182668. && hdr->rcBound.right - hdr->rcBound.left >= w
  182669. && hdr->rcBound.bottom - hdr->rcBound.top >= h)
  182670. {
  182671. needToPaintAll = false;
  182672. const RECT* rects = (const RECT*) (rgnData + sizeof (RGNDATAHEADER));
  182673. int num = ((RGNDATA*) rgnData)->rdh.nCount;
  182674. while (--num >= 0)
  182675. {
  182676. // (need to move this one pixel to the left because of a win32 bug)
  182677. const int cx = jmax (x, (int) rects->left - 1);
  182678. const int cy = rects->top;
  182679. const int cw = rects->right - cx;
  182680. const int ch = rects->bottom - rects->top;
  182681. if (cx + cw - x <= w && cy + ch - y <= h)
  182682. {
  182683. contextClip.addWithoutMerging (Rectangle<int> (cx - x, cy - y, cw, ch));
  182684. }
  182685. else
  182686. {
  182687. needToPaintAll = true;
  182688. break;
  182689. }
  182690. ++rects;
  182691. }
  182692. }
  182693. }
  182694. }
  182695. if (needToPaintAll)
  182696. {
  182697. contextClip.clear();
  182698. contextClip.addWithoutMerging (Rectangle<int> (0, 0, w, h));
  182699. }
  182700. if (transparent)
  182701. {
  182702. RectangleList::Iterator i (contextClip);
  182703. while (i.next())
  182704. {
  182705. const Rectangle<int>& r = *i.getRectangle();
  182706. offscreenImage->clear (r.getX(), r.getY(), r.getWidth(), r.getHeight());
  182707. }
  182708. }
  182709. // if the component's not opaque, this won't draw properly unless the platform can support this
  182710. jassert (Desktop::canUseSemiTransparentWindows() || component->isOpaque());
  182711. updateCurrentModifiers();
  182712. LowLevelGraphicsSoftwareRenderer context (*offscreenImage);
  182713. context.clipToRectangleList (contextClip);
  182714. context.setOrigin (-x, -y);
  182715. handlePaint (context);
  182716. if (! dontRepaint)
  182717. offscreenImage->blitToWindow (hwnd, dc, transparent, x, y, maskedRegion);
  182718. }
  182719. DeleteObject (rgn);
  182720. EndPaint (hwnd, &paintStruct);
  182721. reentrant = false;
  182722. #ifndef JUCE_GCC //xxx should add this fn for gcc..
  182723. _fpreset(); // because some graphics cards can unmask FP exceptions
  182724. #endif
  182725. lastPaintTime = Time::getMillisecondCounter();
  182726. #if DEBUG_REPAINT_TIMES
  182727. const double elapsed = Time::getMillisecondCounterHiRes() - paintStart;
  182728. Logger::outputDebugString (T("repaint time: ") + String (elapsed, 2));
  182729. #endif
  182730. }
  182731. void doMouseMove (const int x, const int y)
  182732. {
  182733. static uint32 lastMouseTime = 0;
  182734. // this can be set to throttle the mouse-messages to less than a
  182735. // certain number per second, as things can get unresponsive
  182736. // if each drag or move callback has to do a lot of work.
  182737. const int maxMouseMovesPerSecond = 60;
  182738. const int64 mouseEventTime = getMouseEventTime();
  182739. if (! isMouseOver)
  182740. {
  182741. isMouseOver = true;
  182742. TRACKMOUSEEVENT tme;
  182743. tme.cbSize = sizeof (tme);
  182744. tme.dwFlags = TME_LEAVE;
  182745. tme.hwndTrack = hwnd;
  182746. tme.dwHoverTime = 0;
  182747. if (! TrackMouseEvent (&tme))
  182748. {
  182749. jassertfalse;
  182750. }
  182751. updateKeyModifiers();
  182752. handleMouseEnter (x, y, mouseEventTime);
  182753. }
  182754. else if (! isDragging)
  182755. {
  182756. if (((unsigned int) x) < (unsigned int) component->getWidth()
  182757. && ((unsigned int) y) < (unsigned int) component->getHeight())
  182758. {
  182759. RECT r;
  182760. GetWindowRect (hwnd, &r);
  182761. POINT p;
  182762. p.x = x + r.left + windowBorder.getLeft();
  182763. p.y = y + r.top + windowBorder.getTop();
  182764. if (WindowFromPoint (p) == hwnd)
  182765. {
  182766. const uint32 now = Time::getMillisecondCounter();
  182767. if (now > lastMouseTime + 1000 / maxMouseMovesPerSecond)
  182768. {
  182769. lastMouseTime = now;
  182770. handleMouseMove (x, y, mouseEventTime);
  182771. }
  182772. }
  182773. }
  182774. }
  182775. else
  182776. {
  182777. const uint32 now = Time::getMillisecondCounter();
  182778. if (now > lastMouseTime + 1000 / maxMouseMovesPerSecond)
  182779. {
  182780. lastMouseTime = now;
  182781. handleMouseDrag (x, y, mouseEventTime);
  182782. }
  182783. }
  182784. }
  182785. void doMouseDown (const int x, const int y, const WPARAM wParam)
  182786. {
  182787. if (GetCapture() != hwnd)
  182788. SetCapture (hwnd);
  182789. doMouseMove (x, y);
  182790. currentModifiers &= ~ModifierKeys::allMouseButtonModifiers;
  182791. if ((wParam & MK_LBUTTON) != 0)
  182792. currentModifiers |= ModifierKeys::leftButtonModifier;
  182793. if ((wParam & MK_RBUTTON) != 0)
  182794. currentModifiers |= ModifierKeys::rightButtonModifier;
  182795. if ((wParam & MK_MBUTTON) != 0)
  182796. currentModifiers |= ModifierKeys::middleButtonModifier;
  182797. updateKeyModifiers();
  182798. isDragging = true;
  182799. handleMouseDown (x, y, getMouseEventTime());
  182800. }
  182801. void doMouseUp (const int x, const int y, const WPARAM wParam)
  182802. {
  182803. int numButtons = 0;
  182804. if ((wParam & MK_LBUTTON) != 0)
  182805. ++numButtons;
  182806. if ((wParam & MK_RBUTTON) != 0)
  182807. ++numButtons;
  182808. if ((wParam & MK_MBUTTON) != 0)
  182809. ++numButtons;
  182810. const int oldModifiers = currentModifiers;
  182811. // update the currentmodifiers only after the callback, so the callback
  182812. // knows which button was released.
  182813. currentModifiers &= ~ModifierKeys::allMouseButtonModifiers;
  182814. if ((wParam & MK_LBUTTON) != 0)
  182815. currentModifiers |= ModifierKeys::leftButtonModifier;
  182816. if ((wParam & MK_RBUTTON) != 0)
  182817. currentModifiers |= ModifierKeys::rightButtonModifier;
  182818. if ((wParam & MK_MBUTTON) != 0)
  182819. currentModifiers |= ModifierKeys::middleButtonModifier;
  182820. updateKeyModifiers();
  182821. isDragging = false;
  182822. // release the mouse capture if the user's not still got a button down
  182823. if (numButtons == 0 && hwnd == GetCapture())
  182824. ReleaseCapture();
  182825. handleMouseUp (oldModifiers, x, y, getMouseEventTime());
  182826. }
  182827. void doCaptureChanged()
  182828. {
  182829. if (isDragging)
  182830. {
  182831. RECT wr;
  182832. GetWindowRect (hwnd, &wr);
  182833. const DWORD mp = GetMessagePos();
  182834. doMouseUp (GET_X_LPARAM (mp) - wr.left - windowBorder.getLeft(),
  182835. GET_Y_LPARAM (mp) - wr.top - windowBorder.getTop(),
  182836. (WPARAM) getMouseEventTime());
  182837. }
  182838. }
  182839. void doMouseExit()
  182840. {
  182841. if (isMouseOver)
  182842. {
  182843. isMouseOver = false;
  182844. RECT wr;
  182845. GetWindowRect (hwnd, &wr);
  182846. const DWORD mp = GetMessagePos();
  182847. handleMouseExit (GET_X_LPARAM (mp) - wr.left - windowBorder.getLeft(),
  182848. GET_Y_LPARAM (mp) - wr.top - windowBorder.getTop(),
  182849. getMouseEventTime());
  182850. }
  182851. }
  182852. void doMouseWheel (const WPARAM wParam, const bool isVertical)
  182853. {
  182854. updateKeyModifiers();
  182855. const int amount = jlimit (-1000, 1000, (int) (0.75f * (short) HIWORD (wParam)));
  182856. handleMouseWheel (isVertical ? 0 : amount,
  182857. isVertical ? amount : 0,
  182858. getMouseEventTime());
  182859. }
  182860. void sendModifierKeyChangeIfNeeded()
  182861. {
  182862. if (modifiersAtLastCallback != currentModifiers)
  182863. {
  182864. modifiersAtLastCallback = currentModifiers;
  182865. handleModifierKeysChange();
  182866. }
  182867. }
  182868. bool doKeyUp (const WPARAM key)
  182869. {
  182870. updateKeyModifiers();
  182871. switch (key)
  182872. {
  182873. case VK_SHIFT:
  182874. case VK_CONTROL:
  182875. case VK_MENU:
  182876. case VK_CAPITAL:
  182877. case VK_LWIN:
  182878. case VK_RWIN:
  182879. case VK_APPS:
  182880. case VK_NUMLOCK:
  182881. case VK_SCROLL:
  182882. case VK_LSHIFT:
  182883. case VK_RSHIFT:
  182884. case VK_LCONTROL:
  182885. case VK_LMENU:
  182886. case VK_RCONTROL:
  182887. case VK_RMENU:
  182888. sendModifierKeyChangeIfNeeded();
  182889. }
  182890. return handleKeyUpOrDown (false)
  182891. || Component::getCurrentlyModalComponent() != 0;
  182892. }
  182893. bool doKeyDown (const WPARAM key)
  182894. {
  182895. updateKeyModifiers();
  182896. bool used = false;
  182897. switch (key)
  182898. {
  182899. case VK_SHIFT:
  182900. case VK_LSHIFT:
  182901. case VK_RSHIFT:
  182902. case VK_CONTROL:
  182903. case VK_LCONTROL:
  182904. case VK_RCONTROL:
  182905. case VK_MENU:
  182906. case VK_LMENU:
  182907. case VK_RMENU:
  182908. case VK_LWIN:
  182909. case VK_RWIN:
  182910. case VK_CAPITAL:
  182911. case VK_NUMLOCK:
  182912. case VK_SCROLL:
  182913. case VK_APPS:
  182914. sendModifierKeyChangeIfNeeded();
  182915. break;
  182916. case VK_LEFT:
  182917. case VK_RIGHT:
  182918. case VK_UP:
  182919. case VK_DOWN:
  182920. case VK_PRIOR:
  182921. case VK_NEXT:
  182922. case VK_HOME:
  182923. case VK_END:
  182924. case VK_DELETE:
  182925. case VK_INSERT:
  182926. case VK_F1:
  182927. case VK_F2:
  182928. case VK_F3:
  182929. case VK_F4:
  182930. case VK_F5:
  182931. case VK_F6:
  182932. case VK_F7:
  182933. case VK_F8:
  182934. case VK_F9:
  182935. case VK_F10:
  182936. case VK_F11:
  182937. case VK_F12:
  182938. case VK_F13:
  182939. case VK_F14:
  182940. case VK_F15:
  182941. case VK_F16:
  182942. used = handleKeyUpOrDown (true);
  182943. used = handleKeyPress (extendedKeyModifier | (int) key, 0) || used;
  182944. break;
  182945. case VK_ADD:
  182946. case VK_SUBTRACT:
  182947. case VK_MULTIPLY:
  182948. case VK_DIVIDE:
  182949. case VK_SEPARATOR:
  182950. case VK_DECIMAL:
  182951. used = handleKeyUpOrDown (true);
  182952. break;
  182953. default:
  182954. used = handleKeyUpOrDown (true);
  182955. {
  182956. MSG msg;
  182957. if (! PeekMessage (&msg, hwnd, WM_CHAR, WM_DEADCHAR, PM_NOREMOVE))
  182958. {
  182959. // if there isn't a WM_CHAR or WM_DEADCHAR message pending, we need to
  182960. // manually generate the key-press event that matches this key-down.
  182961. const UINT keyChar = MapVirtualKey (key, 2);
  182962. used = handleKeyPress ((int) LOWORD (keyChar), 0) || used;
  182963. }
  182964. }
  182965. break;
  182966. }
  182967. if (Component::getCurrentlyModalComponent() != 0)
  182968. used = true;
  182969. return used;
  182970. }
  182971. bool doKeyChar (int key, const LPARAM flags)
  182972. {
  182973. updateKeyModifiers();
  182974. juce_wchar textChar = (juce_wchar) key;
  182975. const int virtualScanCode = (flags >> 16) & 0xff;
  182976. if (key >= '0' && key <= '9')
  182977. {
  182978. switch (virtualScanCode) // check for a numeric keypad scan-code
  182979. {
  182980. case 0x52:
  182981. case 0x4f:
  182982. case 0x50:
  182983. case 0x51:
  182984. case 0x4b:
  182985. case 0x4c:
  182986. case 0x4d:
  182987. case 0x47:
  182988. case 0x48:
  182989. case 0x49:
  182990. key = (key - '0') + KeyPress::numberPad0;
  182991. break;
  182992. default:
  182993. break;
  182994. }
  182995. }
  182996. else
  182997. {
  182998. // convert the scan code to an unmodified character code..
  182999. const UINT virtualKey = MapVirtualKey (virtualScanCode, 1);
  183000. UINT keyChar = MapVirtualKey (virtualKey, 2);
  183001. keyChar = LOWORD (keyChar);
  183002. if (keyChar != 0)
  183003. key = (int) keyChar;
  183004. // avoid sending junk text characters for some control-key combinations
  183005. if (textChar < ' ' && (currentModifiers & (ModifierKeys::ctrlModifier | ModifierKeys::altModifier)) != 0)
  183006. textChar = 0;
  183007. }
  183008. return handleKeyPress (key, textChar);
  183009. }
  183010. bool doAppCommand (const LPARAM lParam)
  183011. {
  183012. int key = 0;
  183013. switch (GET_APPCOMMAND_LPARAM (lParam))
  183014. {
  183015. case APPCOMMAND_MEDIA_PLAY_PAUSE:
  183016. key = KeyPress::playKey;
  183017. break;
  183018. case APPCOMMAND_MEDIA_STOP:
  183019. key = KeyPress::stopKey;
  183020. break;
  183021. case APPCOMMAND_MEDIA_NEXTTRACK:
  183022. key = KeyPress::fastForwardKey;
  183023. break;
  183024. case APPCOMMAND_MEDIA_PREVIOUSTRACK:
  183025. key = KeyPress::rewindKey;
  183026. break;
  183027. }
  183028. if (key != 0)
  183029. {
  183030. updateKeyModifiers();
  183031. if (hwnd == GetActiveWindow())
  183032. {
  183033. handleKeyPress (key, 0);
  183034. return true;
  183035. }
  183036. }
  183037. return false;
  183038. }
  183039. class JuceDropTarget : public IDropTarget
  183040. {
  183041. public:
  183042. JuceDropTarget (Win32ComponentPeer* const owner_)
  183043. : owner (owner_),
  183044. refCount (1)
  183045. {
  183046. }
  183047. virtual ~JuceDropTarget()
  183048. {
  183049. jassert (refCount == 0);
  183050. }
  183051. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  183052. {
  183053. if (id == IID_IUnknown || id == IID_IDropTarget)
  183054. {
  183055. AddRef();
  183056. *result = this;
  183057. return S_OK;
  183058. }
  183059. *result = 0;
  183060. return E_NOINTERFACE;
  183061. }
  183062. ULONG __stdcall AddRef() { return ++refCount; }
  183063. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  183064. HRESULT __stdcall DragEnter (IDataObject* pDataObject, DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect)
  183065. {
  183066. updateFileList (pDataObject);
  183067. int x = mousePos.x, y = mousePos.y;
  183068. owner->globalPositionToRelative (x, y);
  183069. owner->handleFileDragMove (files, x, y);
  183070. *pdwEffect = DROPEFFECT_COPY;
  183071. return S_OK;
  183072. }
  183073. HRESULT __stdcall DragLeave()
  183074. {
  183075. owner->handleFileDragExit (files);
  183076. return S_OK;
  183077. }
  183078. HRESULT __stdcall DragOver (DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect)
  183079. {
  183080. int x = mousePos.x, y = mousePos.y;
  183081. owner->globalPositionToRelative (x, y);
  183082. owner->handleFileDragMove (files, x, y);
  183083. *pdwEffect = DROPEFFECT_COPY;
  183084. return S_OK;
  183085. }
  183086. HRESULT __stdcall Drop (IDataObject* pDataObject, DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect)
  183087. {
  183088. updateFileList (pDataObject);
  183089. int x = mousePos.x, y = mousePos.y;
  183090. owner->globalPositionToRelative (x, y);
  183091. owner->handleFileDragDrop (files, x, y);
  183092. *pdwEffect = DROPEFFECT_COPY;
  183093. return S_OK;
  183094. }
  183095. private:
  183096. Win32ComponentPeer* const owner;
  183097. int refCount;
  183098. StringArray files;
  183099. void updateFileList (IDataObject* const pDataObject)
  183100. {
  183101. files.clear();
  183102. FORMATETC format = { CF_HDROP, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  183103. STGMEDIUM medium = { TYMED_HGLOBAL, { 0 }, 0 };
  183104. if (pDataObject->GetData (&format, &medium) == S_OK)
  183105. {
  183106. const SIZE_T totalLen = GlobalSize (medium.hGlobal);
  183107. const LPDROPFILES pDropFiles = (const LPDROPFILES) GlobalLock (medium.hGlobal);
  183108. unsigned int i = 0;
  183109. if (pDropFiles->fWide)
  183110. {
  183111. const WCHAR* const fname = (WCHAR*) (((const char*) pDropFiles) + sizeof (DROPFILES));
  183112. for (;;)
  183113. {
  183114. unsigned int len = 0;
  183115. while (i + len < totalLen && fname [i + len] != 0)
  183116. ++len;
  183117. if (len == 0)
  183118. break;
  183119. files.add (String (fname + i, len));
  183120. i += len + 1;
  183121. }
  183122. }
  183123. else
  183124. {
  183125. const char* const fname = ((const char*) pDropFiles) + sizeof (DROPFILES);
  183126. for (;;)
  183127. {
  183128. unsigned int len = 0;
  183129. while (i + len < totalLen && fname [i + len] != 0)
  183130. ++len;
  183131. if (len == 0)
  183132. break;
  183133. files.add (String (fname + i, len));
  183134. i += len + 1;
  183135. }
  183136. }
  183137. GlobalUnlock (medium.hGlobal);
  183138. }
  183139. }
  183140. JuceDropTarget (const JuceDropTarget&);
  183141. const JuceDropTarget& operator= (const JuceDropTarget&);
  183142. };
  183143. void doSettingChange()
  183144. {
  183145. Desktop::getInstance().refreshMonitorSizes();
  183146. if (fullScreen && ! isMinimised())
  183147. {
  183148. const Rectangle<int> r (component->getParentMonitorArea());
  183149. SetWindowPos (hwnd, 0,
  183150. r.getX(), r.getY(), r.getWidth(), r.getHeight(),
  183151. SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_NOSENDCHANGING);
  183152. }
  183153. }
  183154. public:
  183155. static LRESULT CALLBACK windowProc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
  183156. {
  183157. Win32ComponentPeer* const peer = getOwnerOfWindow (h);
  183158. if (peer != 0)
  183159. return peer->peerWindowProc (h, message, wParam, lParam);
  183160. return DefWindowProc (h, message, wParam, lParam);
  183161. }
  183162. private:
  183163. LRESULT peerWindowProc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
  183164. {
  183165. if (isValidPeer (this))
  183166. {
  183167. switch (message)
  183168. {
  183169. case WM_NCHITTEST:
  183170. if ((styleFlags & windowIgnoresMouseClicks) != 0)
  183171. return HTTRANSPARENT;
  183172. if (hasTitleBar())
  183173. break;
  183174. return HTCLIENT;
  183175. case WM_PAINT:
  183176. handlePaintMessage();
  183177. return 0;
  183178. case WM_NCPAINT:
  183179. if (wParam != 1)
  183180. handlePaintMessage();
  183181. if (hasTitleBar())
  183182. break;
  183183. return 0;
  183184. case WM_ERASEBKGND:
  183185. case WM_NCCALCSIZE:
  183186. if (hasTitleBar())
  183187. break;
  183188. return 1;
  183189. case WM_MOUSEMOVE:
  183190. doMouseMove (GET_X_LPARAM (lParam), GET_Y_LPARAM (lParam));
  183191. return 0;
  183192. case WM_MOUSELEAVE:
  183193. doMouseExit();
  183194. return 0;
  183195. case WM_LBUTTONDOWN:
  183196. case WM_MBUTTONDOWN:
  183197. case WM_RBUTTONDOWN:
  183198. doMouseDown (GET_X_LPARAM (lParam), GET_Y_LPARAM (lParam), wParam);
  183199. return 0;
  183200. case WM_LBUTTONUP:
  183201. case WM_MBUTTONUP:
  183202. case WM_RBUTTONUP:
  183203. doMouseUp (GET_X_LPARAM (lParam), GET_Y_LPARAM (lParam), wParam);
  183204. return 0;
  183205. case WM_CAPTURECHANGED:
  183206. doCaptureChanged();
  183207. return 0;
  183208. case WM_NCMOUSEMOVE:
  183209. if (hasTitleBar())
  183210. break;
  183211. return 0;
  183212. case 0x020A: /* WM_MOUSEWHEEL */
  183213. doMouseWheel (wParam, true);
  183214. return 0;
  183215. case 0x020E: /* WM_MOUSEHWHEEL */
  183216. doMouseWheel (wParam, false);
  183217. return 0;
  183218. case WM_WINDOWPOSCHANGING:
  183219. if ((styleFlags & (windowHasTitleBar | windowIsResizable)) == (windowHasTitleBar | windowIsResizable))
  183220. {
  183221. WINDOWPOS* const wp = (WINDOWPOS*) lParam;
  183222. if ((wp->flags & (SWP_NOMOVE | SWP_NOSIZE)) != (SWP_NOMOVE | SWP_NOSIZE))
  183223. {
  183224. if (constrainer != 0)
  183225. {
  183226. const Rectangle<int> current (component->getX() - windowBorder.getLeft(),
  183227. component->getY() - windowBorder.getTop(),
  183228. component->getWidth() + windowBorder.getLeftAndRight(),
  183229. component->getHeight() + windowBorder.getTopAndBottom());
  183230. Rectangle<int> pos (wp->x, wp->y, wp->cx, wp->cy);
  183231. constrainer->checkBounds (pos, current,
  183232. Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(),
  183233. pos.getY() != current.getY() && pos.getBottom() == current.getBottom(),
  183234. pos.getX() != current.getX() && pos.getRight() == current.getRight(),
  183235. pos.getY() == current.getY() && pos.getBottom() != current.getBottom(),
  183236. pos.getX() == current.getX() && pos.getRight() != current.getRight());
  183237. wp->x = pos.getX();
  183238. wp->y = pos.getY();
  183239. wp->cx = pos.getWidth();
  183240. wp->cy = pos.getHeight();
  183241. }
  183242. }
  183243. }
  183244. return 0;
  183245. case WM_WINDOWPOSCHANGED:
  183246. handleMovedOrResized();
  183247. if (dontRepaint)
  183248. break; // needed for non-accelerated openGL windows to draw themselves correctly..
  183249. return 0;
  183250. case WM_KEYDOWN:
  183251. case WM_SYSKEYDOWN:
  183252. if (doKeyDown (wParam))
  183253. return 0;
  183254. break;
  183255. case WM_KEYUP:
  183256. case WM_SYSKEYUP:
  183257. if (doKeyUp (wParam))
  183258. return 0;
  183259. break;
  183260. case WM_CHAR:
  183261. if (doKeyChar ((int) wParam, lParam))
  183262. return 0;
  183263. break;
  183264. case WM_APPCOMMAND:
  183265. if (doAppCommand (lParam))
  183266. return TRUE;
  183267. break;
  183268. case WM_SETFOCUS:
  183269. updateKeyModifiers();
  183270. handleFocusGain();
  183271. break;
  183272. case WM_KILLFOCUS:
  183273. if (hasCreatedCaret)
  183274. {
  183275. hasCreatedCaret = false;
  183276. DestroyCaret();
  183277. }
  183278. handleFocusLoss();
  183279. break;
  183280. case WM_ACTIVATEAPP:
  183281. // Windows does weird things to process priority when you swap apps,
  183282. // so this forces an update when the app is brought to the front
  183283. if (wParam != FALSE)
  183284. juce_repeatLastProcessPriority();
  183285. else
  183286. Desktop::getInstance().setKioskModeComponent (0); // turn kiosk mode off if we lose focus
  183287. juce_CheckCurrentlyFocusedTopLevelWindow();
  183288. modifiersAtLastCallback = -1;
  183289. return 0;
  183290. case WM_ACTIVATE:
  183291. if (LOWORD (wParam) == WA_ACTIVE || LOWORD (wParam) == WA_CLICKACTIVE)
  183292. {
  183293. modifiersAtLastCallback = -1;
  183294. updateKeyModifiers();
  183295. if (isMinimised())
  183296. {
  183297. component->repaint();
  183298. handleMovedOrResized();
  183299. if (! isValidMessageListener())
  183300. return 0;
  183301. }
  183302. if (LOWORD (wParam) == WA_CLICKACTIVE
  183303. && component->isCurrentlyBlockedByAnotherModalComponent())
  183304. {
  183305. int mx, my;
  183306. component->getMouseXYRelative (mx, my);
  183307. Component* const underMouse = component->getComponentAt (mx, my);
  183308. if (underMouse != 0 && underMouse->isCurrentlyBlockedByAnotherModalComponent())
  183309. Component::getCurrentlyModalComponent()->inputAttemptWhenModal();
  183310. return 0;
  183311. }
  183312. handleBroughtToFront();
  183313. if (component->isCurrentlyBlockedByAnotherModalComponent())
  183314. Component::getCurrentlyModalComponent()->toFront (true);
  183315. return 0;
  183316. }
  183317. break;
  183318. case WM_NCACTIVATE:
  183319. // while a temporary window is being shown, prevent Windows from deactivating the
  183320. // title bars of our main windows.
  183321. if (wParam == 0 && ! shouldDeactivateTitleBar)
  183322. wParam = TRUE; // change this and let it get passed to the DefWindowProc.
  183323. break;
  183324. case WM_MOUSEACTIVATE:
  183325. if (! component->getMouseClickGrabsKeyboardFocus())
  183326. return MA_NOACTIVATE;
  183327. break;
  183328. case WM_SHOWWINDOW:
  183329. if (wParam != 0)
  183330. handleBroughtToFront();
  183331. break;
  183332. case WM_CLOSE:
  183333. if (! component->isCurrentlyBlockedByAnotherModalComponent())
  183334. handleUserClosingWindow();
  183335. return 0;
  183336. case WM_QUERYENDSESSION:
  183337. if (JUCEApplication::getInstance() != 0)
  183338. {
  183339. JUCEApplication::getInstance()->systemRequestedQuit();
  183340. return MessageManager::getInstance()->hasStopMessageBeenSent();
  183341. }
  183342. return TRUE;
  183343. case WM_TRAYNOTIFY:
  183344. if (component->isCurrentlyBlockedByAnotherModalComponent())
  183345. {
  183346. if (lParam == WM_LBUTTONDOWN || lParam == WM_RBUTTONDOWN
  183347. || lParam == WM_LBUTTONDBLCLK || lParam == WM_LBUTTONDBLCLK)
  183348. {
  183349. Component* const current = Component::getCurrentlyModalComponent();
  183350. if (current != 0)
  183351. current->inputAttemptWhenModal();
  183352. }
  183353. }
  183354. else
  183355. {
  183356. const int oldModifiers = currentModifiers;
  183357. MouseEvent e (0, 0, ModifierKeys::getCurrentModifiersRealtime(), component,
  183358. getMouseEventTime(), 0, 0, getMouseEventTime(), 1, false);
  183359. if (lParam == WM_LBUTTONDOWN || lParam == WM_LBUTTONDBLCLK)
  183360. e.mods = ModifierKeys (e.mods.getRawFlags() | ModifierKeys::leftButtonModifier);
  183361. else if (lParam == WM_RBUTTONDOWN || lParam == WM_RBUTTONDBLCLK)
  183362. e.mods = ModifierKeys (e.mods.getRawFlags() | ModifierKeys::rightButtonModifier);
  183363. if (lParam == WM_LBUTTONDOWN || lParam == WM_RBUTTONDOWN)
  183364. {
  183365. SetFocus (hwnd);
  183366. SetForegroundWindow (hwnd);
  183367. component->mouseDown (e);
  183368. }
  183369. else if (lParam == WM_LBUTTONUP || lParam == WM_RBUTTONUP)
  183370. {
  183371. e.mods = ModifierKeys (oldModifiers);
  183372. component->mouseUp (e);
  183373. }
  183374. else if (lParam == WM_LBUTTONDBLCLK || lParam == WM_LBUTTONDBLCLK)
  183375. {
  183376. e.mods = ModifierKeys (oldModifiers);
  183377. component->mouseDoubleClick (e);
  183378. }
  183379. else if (lParam == WM_MOUSEMOVE)
  183380. {
  183381. component->mouseMove (e);
  183382. }
  183383. }
  183384. break;
  183385. case WM_SYNCPAINT:
  183386. return 0;
  183387. case WM_PALETTECHANGED:
  183388. InvalidateRect (h, 0, 0);
  183389. break;
  183390. case WM_DISPLAYCHANGE:
  183391. InvalidateRect (h, 0, 0);
  183392. createPaletteIfNeeded = true;
  183393. // intentional fall-through...
  183394. case WM_SETTINGCHANGE: // note the fall-through in the previous case!
  183395. doSettingChange();
  183396. break;
  183397. case WM_INITMENU:
  183398. if (! hasTitleBar())
  183399. {
  183400. if (isFullScreen())
  183401. {
  183402. EnableMenuItem ((HMENU) wParam, SC_RESTORE, MF_BYCOMMAND | MF_ENABLED);
  183403. EnableMenuItem ((HMENU) wParam, SC_MOVE, MF_BYCOMMAND | MF_GRAYED);
  183404. }
  183405. else if (! isMinimised())
  183406. {
  183407. EnableMenuItem ((HMENU) wParam, SC_MAXIMIZE, MF_BYCOMMAND | MF_GRAYED);
  183408. }
  183409. }
  183410. break;
  183411. case WM_SYSCOMMAND:
  183412. switch (wParam & 0xfff0)
  183413. {
  183414. case SC_CLOSE:
  183415. if (sendInputAttemptWhenModalMessage())
  183416. return 0;
  183417. if (hasTitleBar())
  183418. {
  183419. PostMessage (h, WM_CLOSE, 0, 0);
  183420. return 0;
  183421. }
  183422. break;
  183423. case SC_KEYMENU:
  183424. // (NB mustn't call sendInputAttemptWhenModalMessage() here because of very
  183425. // obscure situations that can arise if a modal loop is started from an alt-key
  183426. // keypress).
  183427. if (hasTitleBar() && h == GetCapture())
  183428. ReleaseCapture();
  183429. break;
  183430. case SC_MAXIMIZE:
  183431. if (sendInputAttemptWhenModalMessage())
  183432. return 0;
  183433. setFullScreen (true);
  183434. return 0;
  183435. case SC_MINIMIZE:
  183436. if (sendInputAttemptWhenModalMessage())
  183437. return 0;
  183438. if (! hasTitleBar())
  183439. {
  183440. setMinimised (true);
  183441. return 0;
  183442. }
  183443. break;
  183444. case SC_RESTORE:
  183445. if (sendInputAttemptWhenModalMessage())
  183446. return 0;
  183447. if (hasTitleBar())
  183448. {
  183449. if (isFullScreen())
  183450. {
  183451. setFullScreen (false);
  183452. return 0;
  183453. }
  183454. }
  183455. else
  183456. {
  183457. if (isMinimised())
  183458. setMinimised (false);
  183459. else if (isFullScreen())
  183460. setFullScreen (false);
  183461. return 0;
  183462. }
  183463. break;
  183464. }
  183465. break;
  183466. case WM_NCLBUTTONDOWN:
  183467. case WM_NCRBUTTONDOWN:
  183468. case WM_NCMBUTTONDOWN:
  183469. sendInputAttemptWhenModalMessage();
  183470. break;
  183471. //case WM_IME_STARTCOMPOSITION;
  183472. // return 0;
  183473. case WM_GETDLGCODE:
  183474. return DLGC_WANTALLKEYS;
  183475. default:
  183476. break;
  183477. }
  183478. }
  183479. return DefWindowProc (h, message, wParam, lParam);
  183480. }
  183481. bool sendInputAttemptWhenModalMessage()
  183482. {
  183483. if (component->isCurrentlyBlockedByAnotherModalComponent())
  183484. {
  183485. Component* const current = Component::getCurrentlyModalComponent();
  183486. if (current != 0)
  183487. current->inputAttemptWhenModal();
  183488. return true;
  183489. }
  183490. return false;
  183491. }
  183492. Win32ComponentPeer (const Win32ComponentPeer&);
  183493. const Win32ComponentPeer& operator= (const Win32ComponentPeer&);
  183494. };
  183495. ComponentPeer* Component::createNewPeer (int styleFlags, void* /*nativeWindowToAttachTo*/)
  183496. {
  183497. return new Win32ComponentPeer (this, styleFlags);
  183498. }
  183499. juce_ImplementSingleton_SingleThreaded (Win32ComponentPeer::WindowClassHolder);
  183500. void SystemTrayIconComponent::setIconImage (const Image& newImage)
  183501. {
  183502. Win32ComponentPeer* const wp = dynamic_cast <Win32ComponentPeer*> (getPeer());
  183503. if (wp != 0)
  183504. wp->setTaskBarIcon (&newImage);
  183505. }
  183506. void SystemTrayIconComponent::setIconTooltip (const String& tooltip)
  183507. {
  183508. Win32ComponentPeer* const wp = dynamic_cast <Win32ComponentPeer*> (getPeer());
  183509. if (wp != 0)
  183510. wp->setTaskBarIconToolTip (tooltip);
  183511. }
  183512. void juce_setWindowStyleBit (HWND h, const int styleType, const int feature, const bool bitIsSet) throw()
  183513. {
  183514. DWORD val = GetWindowLong (h, styleType);
  183515. if (bitIsSet)
  183516. val |= feature;
  183517. else
  183518. val &= ~feature;
  183519. SetWindowLongPtr (h, styleType, val);
  183520. SetWindowPos (h, 0, 0, 0, 0, 0,
  183521. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER
  183522. | SWP_NOOWNERZORDER | SWP_FRAMECHANGED | SWP_NOSENDCHANGING);
  183523. }
  183524. bool Process::isForegroundProcess()
  183525. {
  183526. HWND fg = GetForegroundWindow();
  183527. if (fg == 0)
  183528. return true;
  183529. // when running as a plugin in IE8, the browser UI runs in a different process to the plugin, so
  183530. // process ID isn't a reliable way to check if the foreground window belongs to us - instead, we
  183531. // have to see if any of our windows are children of the foreground window
  183532. fg = GetAncestor (fg, GA_ROOT);
  183533. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  183534. {
  183535. Win32ComponentPeer* const wp = dynamic_cast <Win32ComponentPeer*> (ComponentPeer::getPeer (i));
  183536. if (wp != 0 && wp->isInside (fg))
  183537. return true;
  183538. }
  183539. return false;
  183540. }
  183541. bool AlertWindow::showNativeDialogBox (const String& title,
  183542. const String& bodyText,
  183543. bool isOkCancel)
  183544. {
  183545. return MessageBox (0, bodyText, title,
  183546. MB_SETFOREGROUND | (isOkCancel ? MB_OKCANCEL
  183547. : MB_OK)) == IDOK;
  183548. }
  183549. void Desktop::getMousePosition (int& x, int& y) throw()
  183550. {
  183551. POINT mousePos;
  183552. GetCursorPos (&mousePos);
  183553. x = mousePos.x;
  183554. y = mousePos.y;
  183555. }
  183556. void Desktop::setMousePosition (int x, int y) throw()
  183557. {
  183558. SetCursorPos (x, y);
  183559. }
  183560. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  183561. {
  183562. return new Image (format, imageWidth, imageHeight, clearImage);
  183563. }
  183564. class ScreenSaverDefeater : public Timer,
  183565. public DeletedAtShutdown
  183566. {
  183567. public:
  183568. ScreenSaverDefeater() throw()
  183569. {
  183570. startTimer (10000);
  183571. timerCallback();
  183572. }
  183573. ~ScreenSaverDefeater() {}
  183574. void timerCallback()
  183575. {
  183576. if (Process::isForegroundProcess())
  183577. {
  183578. // simulate a shift key getting pressed..
  183579. INPUT input[2];
  183580. input[0].type = INPUT_KEYBOARD;
  183581. input[0].ki.wVk = VK_SHIFT;
  183582. input[0].ki.dwFlags = 0;
  183583. input[0].ki.dwExtraInfo = 0;
  183584. input[1].type = INPUT_KEYBOARD;
  183585. input[1].ki.wVk = VK_SHIFT;
  183586. input[1].ki.dwFlags = KEYEVENTF_KEYUP;
  183587. input[1].ki.dwExtraInfo = 0;
  183588. SendInput (2, input, sizeof (INPUT));
  183589. }
  183590. }
  183591. };
  183592. static ScreenSaverDefeater* screenSaverDefeater = 0;
  183593. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  183594. {
  183595. if (isEnabled)
  183596. {
  183597. deleteAndZero (screenSaverDefeater);
  183598. }
  183599. else if (screenSaverDefeater == 0)
  183600. {
  183601. screenSaverDefeater = new ScreenSaverDefeater();
  183602. }
  183603. }
  183604. bool Desktop::isScreenSaverEnabled() throw()
  183605. {
  183606. return screenSaverDefeater == 0;
  183607. }
  183608. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool /*allowMenusAndBars*/)
  183609. {
  183610. if (enableOrDisable)
  183611. kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));
  183612. }
  183613. static BOOL CALLBACK enumMonitorsProc (HMONITOR, HDC, LPRECT r, LPARAM userInfo)
  183614. {
  183615. Array <Rectangle<int> >* const monitorCoords = (Array <Rectangle<int> >*) userInfo;
  183616. monitorCoords->add (Rectangle<int> (r->left, r->top, r->right - r->left, r->bottom - r->top));
  183617. return TRUE;
  183618. }
  183619. void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords, const bool clipToWorkArea)
  183620. {
  183621. EnumDisplayMonitors (0, 0, &enumMonitorsProc, (LPARAM) &monitorCoords);
  183622. // make sure the first in the list is the main monitor
  183623. for (int i = 1; i < monitorCoords.size(); ++i)
  183624. if (monitorCoords[i].getX() == 0 && monitorCoords[i].getY() == 0)
  183625. monitorCoords.swap (i, 0);
  183626. if (monitorCoords.size() == 0)
  183627. {
  183628. RECT r;
  183629. GetWindowRect (GetDesktopWindow(), &r);
  183630. monitorCoords.add (Rectangle<int> (r.left, r.top, r.right - r.left, r.bottom - r.top));
  183631. }
  183632. if (clipToWorkArea)
  183633. {
  183634. // clip the main monitor to the active non-taskbar area
  183635. RECT r;
  183636. SystemParametersInfo (SPI_GETWORKAREA, 0, &r, 0);
  183637. Rectangle<int>& screen = monitorCoords.getReference (0);
  183638. screen.setPosition (jmax (screen.getX(), (int) r.left),
  183639. jmax (screen.getY(), (int) r.top));
  183640. screen.setSize (jmin (screen.getRight(), (int) r.right) - screen.getX(),
  183641. jmin (screen.getBottom(), (int) r.bottom) - screen.getY());
  183642. }
  183643. }
  183644. static Image* createImageFromHBITMAP (HBITMAP bitmap) throw()
  183645. {
  183646. Image* im = 0;
  183647. if (bitmap != 0)
  183648. {
  183649. BITMAP bm;
  183650. if (GetObject (bitmap, sizeof (BITMAP), &bm)
  183651. && bm.bmWidth > 0 && bm.bmHeight > 0)
  183652. {
  183653. HDC tempDC = GetDC (0);
  183654. HDC dc = CreateCompatibleDC (tempDC);
  183655. ReleaseDC (0, tempDC);
  183656. SelectObject (dc, bitmap);
  183657. im = new Image (Image::ARGB, bm.bmWidth, bm.bmHeight, true);
  183658. for (int y = bm.bmHeight; --y >= 0;)
  183659. {
  183660. for (int x = bm.bmWidth; --x >= 0;)
  183661. {
  183662. COLORREF col = GetPixel (dc, x, y);
  183663. im->setPixelAt (x, y, Colour ((uint8) GetRValue (col),
  183664. (uint8) GetGValue (col),
  183665. (uint8) GetBValue (col)));
  183666. }
  183667. }
  183668. DeleteDC (dc);
  183669. }
  183670. }
  183671. return im;
  183672. }
  183673. static Image* createImageFromHICON (HICON icon) throw()
  183674. {
  183675. ICONINFO info;
  183676. if (GetIconInfo (icon, &info))
  183677. {
  183678. Image* const mask = createImageFromHBITMAP (info.hbmMask);
  183679. if (mask == 0)
  183680. return 0;
  183681. Image* const image = createImageFromHBITMAP (info.hbmColor);
  183682. if (image == 0)
  183683. return mask;
  183684. for (int y = image->getHeight(); --y >= 0;)
  183685. {
  183686. for (int x = image->getWidth(); --x >= 0;)
  183687. {
  183688. const float brightness = mask->getPixelAt (x, y).getBrightness();
  183689. if (brightness > 0.0f)
  183690. image->multiplyAlphaAt (x, y, 1.0f - brightness);
  183691. }
  183692. }
  183693. delete mask;
  183694. return image;
  183695. }
  183696. return 0;
  183697. }
  183698. static HICON createHICONFromImage (const Image& image, const BOOL isIcon, int hotspotX, int hotspotY) throw()
  183699. {
  183700. HBITMAP mask = CreateBitmap (image.getWidth(), image.getHeight(), 1, 1, 0);
  183701. ICONINFO info;
  183702. info.fIcon = isIcon;
  183703. info.xHotspot = hotspotX;
  183704. info.yHotspot = hotspotY;
  183705. info.hbmMask = mask;
  183706. HICON hi = 0;
  183707. if (SystemStats::getOperatingSystemType() >= SystemStats::WinXP)
  183708. {
  183709. WindowsBitmapImage bitmap (Image::ARGB, image.getWidth(), image.getHeight(), true);
  183710. Graphics g (bitmap);
  183711. g.drawImageAt (&image, 0, 0);
  183712. info.hbmColor = bitmap.hBitmap;
  183713. hi = CreateIconIndirect (&info);
  183714. }
  183715. else
  183716. {
  183717. HBITMAP colour = CreateCompatibleBitmap (GetDC (0), image.getWidth(), image.getHeight());
  183718. HDC colDC = CreateCompatibleDC (GetDC (0));
  183719. HDC alphaDC = CreateCompatibleDC (GetDC (0));
  183720. SelectObject (colDC, colour);
  183721. SelectObject (alphaDC, mask);
  183722. for (int y = image.getHeight(); --y >= 0;)
  183723. {
  183724. for (int x = image.getWidth(); --x >= 0;)
  183725. {
  183726. const Colour c (image.getPixelAt (x, y));
  183727. SetPixel (colDC, x, y, COLORREF (c.getRed() | (c.getGreen() << 8) | (c.getBlue() << 16)));
  183728. SetPixel (alphaDC, x, y, COLORREF (0xffffff - (c.getAlpha() | (c.getAlpha() << 8) | (c.getAlpha() << 16))));
  183729. }
  183730. }
  183731. DeleteDC (colDC);
  183732. DeleteDC (alphaDC);
  183733. info.hbmColor = colour;
  183734. hi = CreateIconIndirect (&info);
  183735. DeleteObject (colour);
  183736. }
  183737. DeleteObject (mask);
  183738. return hi;
  183739. }
  183740. Image* juce_createIconForFile (const File& file)
  183741. {
  183742. Image* image = 0;
  183743. TCHAR filename [1024];
  183744. file.getFullPathName().copyToBuffer (filename, 1023);
  183745. WORD iconNum = 0;
  183746. HICON icon = ExtractAssociatedIcon ((HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle(),
  183747. filename, &iconNum);
  183748. if (icon != 0)
  183749. {
  183750. image = createImageFromHICON (icon);
  183751. DestroyIcon (icon);
  183752. }
  183753. return image;
  183754. }
  183755. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  183756. {
  183757. const int maxW = GetSystemMetrics (SM_CXCURSOR);
  183758. const int maxH = GetSystemMetrics (SM_CYCURSOR);
  183759. const Image* im = &image;
  183760. Image* newIm = 0;
  183761. if (image.getWidth() > maxW || image.getHeight() > maxH)
  183762. {
  183763. im = newIm = image.createCopy (maxW, maxH);
  183764. hotspotX = (hotspotX * maxW) / image.getWidth();
  183765. hotspotY = (hotspotY * maxH) / image.getHeight();
  183766. }
  183767. void* cursorH = 0;
  183768. const SystemStats::OperatingSystemType os = SystemStats::getOperatingSystemType();
  183769. if (os == SystemStats::WinXP)
  183770. {
  183771. cursorH = (void*) createHICONFromImage (*im, FALSE, hotspotX, hotspotY);
  183772. }
  183773. else
  183774. {
  183775. const int stride = (maxW + 7) >> 3;
  183776. HeapBlock <uint8> andPlane, xorPlane;
  183777. andPlane.calloc (stride * maxH);
  183778. xorPlane.calloc (stride * maxH);
  183779. int index = 0;
  183780. for (int y = 0; y < maxH; ++y)
  183781. {
  183782. for (int x = 0; x < maxW; ++x)
  183783. {
  183784. const unsigned char bit = (unsigned char) (1 << (7 - (x & 7)));
  183785. const Colour pixelColour (im->getPixelAt (x, y));
  183786. if (pixelColour.getAlpha() < 127)
  183787. andPlane [index + (x >> 3)] |= bit;
  183788. else if (pixelColour.getBrightness() >= 0.5f)
  183789. xorPlane [index + (x >> 3)] |= bit;
  183790. }
  183791. index += stride;
  183792. }
  183793. cursorH = CreateCursor (0, hotspotX, hotspotY, maxW, maxH, andPlane, xorPlane);
  183794. }
  183795. delete newIm;
  183796. return cursorH;
  183797. }
  183798. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw()
  183799. {
  183800. if (cursorHandle != 0 && ! isStandard)
  183801. DestroyCursor ((HCURSOR) cursorHandle);
  183802. }
  183803. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  183804. {
  183805. LPCTSTR cursorName = IDC_ARROW;
  183806. switch (type)
  183807. {
  183808. case MouseCursor::NormalCursor:
  183809. cursorName = IDC_ARROW;
  183810. break;
  183811. case MouseCursor::NoCursor:
  183812. return 0;
  183813. case MouseCursor::DraggingHandCursor:
  183814. {
  183815. static void* dragHandCursor = 0;
  183816. if (dragHandCursor == 0)
  183817. {
  183818. static const unsigned char dragHandData[] =
  183819. { 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,
  183820. 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,
  183821. 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 };
  183822. const ScopedPointer <Image> image (ImageFileFormat::loadFrom ((const char*) dragHandData, sizeof (dragHandData)));
  183823. dragHandCursor = juce_createMouseCursorFromImage (*image, 8, 7);
  183824. }
  183825. return dragHandCursor;
  183826. }
  183827. case MouseCursor::WaitCursor:
  183828. cursorName = IDC_WAIT;
  183829. break;
  183830. case MouseCursor::IBeamCursor:
  183831. cursorName = IDC_IBEAM;
  183832. break;
  183833. case MouseCursor::PointingHandCursor:
  183834. cursorName = MAKEINTRESOURCE(32649);
  183835. break;
  183836. case MouseCursor::LeftRightResizeCursor:
  183837. case MouseCursor::LeftEdgeResizeCursor:
  183838. case MouseCursor::RightEdgeResizeCursor:
  183839. cursorName = IDC_SIZEWE;
  183840. break;
  183841. case MouseCursor::UpDownResizeCursor:
  183842. case MouseCursor::TopEdgeResizeCursor:
  183843. case MouseCursor::BottomEdgeResizeCursor:
  183844. cursorName = IDC_SIZENS;
  183845. break;
  183846. case MouseCursor::TopLeftCornerResizeCursor:
  183847. case MouseCursor::BottomRightCornerResizeCursor:
  183848. cursorName = IDC_SIZENWSE;
  183849. break;
  183850. case MouseCursor::TopRightCornerResizeCursor:
  183851. case MouseCursor::BottomLeftCornerResizeCursor:
  183852. cursorName = IDC_SIZENESW;
  183853. break;
  183854. case MouseCursor::UpDownLeftRightResizeCursor:
  183855. cursorName = IDC_SIZEALL;
  183856. break;
  183857. case MouseCursor::CrosshairCursor:
  183858. cursorName = IDC_CROSS;
  183859. break;
  183860. case MouseCursor::CopyingCursor:
  183861. // can't seem to find one of these in the win32 list..
  183862. break;
  183863. }
  183864. HCURSOR cursorH = LoadCursor (0, cursorName);
  183865. if (cursorH == 0)
  183866. cursorH = LoadCursor (0, IDC_ARROW);
  183867. return (void*) cursorH;
  183868. }
  183869. void MouseCursor::showInWindow (ComponentPeer*) const throw()
  183870. {
  183871. SetCursor ((HCURSOR) getHandle());
  183872. }
  183873. void MouseCursor::showInAllWindows() const throw()
  183874. {
  183875. showInWindow (0);
  183876. }
  183877. class JuceDropSource : public IDropSource
  183878. {
  183879. int refCount;
  183880. public:
  183881. JuceDropSource()
  183882. : refCount (1)
  183883. {
  183884. }
  183885. virtual ~JuceDropSource()
  183886. {
  183887. jassert (refCount == 0);
  183888. }
  183889. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  183890. {
  183891. if (id == IID_IUnknown || id == IID_IDropSource)
  183892. {
  183893. AddRef();
  183894. *result = this;
  183895. return S_OK;
  183896. }
  183897. *result = 0;
  183898. return E_NOINTERFACE;
  183899. }
  183900. ULONG __stdcall AddRef() { return ++refCount; }
  183901. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  183902. HRESULT __stdcall QueryContinueDrag (BOOL escapePressed, DWORD keys)
  183903. {
  183904. if (escapePressed)
  183905. return DRAGDROP_S_CANCEL;
  183906. if ((keys & (MK_LBUTTON | MK_RBUTTON)) == 0)
  183907. return DRAGDROP_S_DROP;
  183908. return S_OK;
  183909. }
  183910. HRESULT __stdcall GiveFeedback (DWORD)
  183911. {
  183912. return DRAGDROP_S_USEDEFAULTCURSORS;
  183913. }
  183914. };
  183915. class JuceEnumFormatEtc : public IEnumFORMATETC
  183916. {
  183917. public:
  183918. JuceEnumFormatEtc (const FORMATETC* const format_)
  183919. : refCount (1),
  183920. format (format_),
  183921. index (0)
  183922. {
  183923. }
  183924. virtual ~JuceEnumFormatEtc()
  183925. {
  183926. jassert (refCount == 0);
  183927. }
  183928. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  183929. {
  183930. if (id == IID_IUnknown || id == IID_IEnumFORMATETC)
  183931. {
  183932. AddRef();
  183933. *result = this;
  183934. return S_OK;
  183935. }
  183936. *result = 0;
  183937. return E_NOINTERFACE;
  183938. }
  183939. ULONG __stdcall AddRef() { return ++refCount; }
  183940. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  183941. HRESULT __stdcall Clone (IEnumFORMATETC** result)
  183942. {
  183943. if (result == 0)
  183944. return E_POINTER;
  183945. JuceEnumFormatEtc* const newOne = new JuceEnumFormatEtc (format);
  183946. newOne->index = index;
  183947. *result = newOne;
  183948. return S_OK;
  183949. }
  183950. HRESULT __stdcall Next (ULONG celt, LPFORMATETC lpFormatEtc, ULONG* pceltFetched)
  183951. {
  183952. if (pceltFetched != 0)
  183953. *pceltFetched = 0;
  183954. else if (celt != 1)
  183955. return S_FALSE;
  183956. if (index == 0 && celt > 0 && lpFormatEtc != 0)
  183957. {
  183958. copyFormatEtc (lpFormatEtc [0], *format);
  183959. ++index;
  183960. if (pceltFetched != 0)
  183961. *pceltFetched = 1;
  183962. return S_OK;
  183963. }
  183964. return S_FALSE;
  183965. }
  183966. HRESULT __stdcall Skip (ULONG celt)
  183967. {
  183968. if (index + (int) celt >= 1)
  183969. return S_FALSE;
  183970. index += celt;
  183971. return S_OK;
  183972. }
  183973. HRESULT __stdcall Reset()
  183974. {
  183975. index = 0;
  183976. return S_OK;
  183977. }
  183978. private:
  183979. int refCount;
  183980. const FORMATETC* const format;
  183981. int index;
  183982. static void copyFormatEtc (FORMATETC& dest, const FORMATETC& source)
  183983. {
  183984. dest = source;
  183985. if (source.ptd != 0)
  183986. {
  183987. dest.ptd = (DVTARGETDEVICE*) CoTaskMemAlloc (sizeof (DVTARGETDEVICE));
  183988. *(dest.ptd) = *(source.ptd);
  183989. }
  183990. }
  183991. JuceEnumFormatEtc (const JuceEnumFormatEtc&);
  183992. const JuceEnumFormatEtc& operator= (const JuceEnumFormatEtc&);
  183993. };
  183994. class JuceDataObject : public IDataObject
  183995. {
  183996. JuceDropSource* const dropSource;
  183997. const FORMATETC* const format;
  183998. const STGMEDIUM* const medium;
  183999. int refCount;
  184000. JuceDataObject (const JuceDataObject&);
  184001. const JuceDataObject& operator= (const JuceDataObject&);
  184002. public:
  184003. JuceDataObject (JuceDropSource* const dropSource_,
  184004. const FORMATETC* const format_,
  184005. const STGMEDIUM* const medium_)
  184006. : dropSource (dropSource_),
  184007. format (format_),
  184008. medium (medium_),
  184009. refCount (1)
  184010. {
  184011. }
  184012. virtual ~JuceDataObject()
  184013. {
  184014. jassert (refCount == 0);
  184015. }
  184016. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184017. {
  184018. if (id == IID_IUnknown || id == IID_IDataObject)
  184019. {
  184020. AddRef();
  184021. *result = this;
  184022. return S_OK;
  184023. }
  184024. *result = 0;
  184025. return E_NOINTERFACE;
  184026. }
  184027. ULONG __stdcall AddRef() { return ++refCount; }
  184028. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  184029. HRESULT __stdcall GetData (FORMATETC __RPC_FAR* pFormatEtc, STGMEDIUM __RPC_FAR* pMedium)
  184030. {
  184031. if (pFormatEtc->tymed == format->tymed
  184032. && pFormatEtc->cfFormat == format->cfFormat
  184033. && pFormatEtc->dwAspect == format->dwAspect)
  184034. {
  184035. pMedium->tymed = format->tymed;
  184036. pMedium->pUnkForRelease = 0;
  184037. if (format->tymed == TYMED_HGLOBAL)
  184038. {
  184039. const SIZE_T len = GlobalSize (medium->hGlobal);
  184040. void* const src = GlobalLock (medium->hGlobal);
  184041. void* const dst = GlobalAlloc (GMEM_FIXED, len);
  184042. memcpy (dst, src, len);
  184043. GlobalUnlock (medium->hGlobal);
  184044. pMedium->hGlobal = dst;
  184045. return S_OK;
  184046. }
  184047. }
  184048. return DV_E_FORMATETC;
  184049. }
  184050. HRESULT __stdcall QueryGetData (FORMATETC __RPC_FAR* f)
  184051. {
  184052. if (f == 0)
  184053. return E_INVALIDARG;
  184054. if (f->tymed == format->tymed
  184055. && f->cfFormat == format->cfFormat
  184056. && f->dwAspect == format->dwAspect)
  184057. return S_OK;
  184058. return DV_E_FORMATETC;
  184059. }
  184060. HRESULT __stdcall GetCanonicalFormatEtc (FORMATETC __RPC_FAR*, FORMATETC __RPC_FAR* pFormatEtcOut)
  184061. {
  184062. pFormatEtcOut->ptd = 0;
  184063. return E_NOTIMPL;
  184064. }
  184065. HRESULT __stdcall EnumFormatEtc (DWORD direction, IEnumFORMATETC __RPC_FAR *__RPC_FAR *result)
  184066. {
  184067. if (result == 0)
  184068. return E_POINTER;
  184069. if (direction == DATADIR_GET)
  184070. {
  184071. *result = new JuceEnumFormatEtc (format);
  184072. return S_OK;
  184073. }
  184074. *result = 0;
  184075. return E_NOTIMPL;
  184076. }
  184077. HRESULT __stdcall GetDataHere (FORMATETC __RPC_FAR*, STGMEDIUM __RPC_FAR*) { return DATA_E_FORMATETC; }
  184078. HRESULT __stdcall SetData (FORMATETC __RPC_FAR*, STGMEDIUM __RPC_FAR*, BOOL) { return E_NOTIMPL; }
  184079. HRESULT __stdcall DAdvise (FORMATETC __RPC_FAR*, DWORD, IAdviseSink __RPC_FAR*, DWORD __RPC_FAR*) { return OLE_E_ADVISENOTSUPPORTED; }
  184080. HRESULT __stdcall DUnadvise (DWORD) { return E_NOTIMPL; }
  184081. HRESULT __stdcall EnumDAdvise (IEnumSTATDATA __RPC_FAR *__RPC_FAR *) { return OLE_E_ADVISENOTSUPPORTED; }
  184082. };
  184083. static HDROP createHDrop (const StringArray& fileNames) throw()
  184084. {
  184085. int totalChars = 0;
  184086. for (int i = fileNames.size(); --i >= 0;)
  184087. totalChars += fileNames[i].length() + 1;
  184088. HDROP hDrop = (HDROP) GlobalAlloc (GMEM_MOVEABLE | GMEM_ZEROINIT,
  184089. sizeof (DROPFILES)
  184090. + sizeof (WCHAR) * (totalChars + 2));
  184091. if (hDrop != 0)
  184092. {
  184093. LPDROPFILES pDropFiles = (LPDROPFILES) GlobalLock (hDrop);
  184094. pDropFiles->pFiles = sizeof (DROPFILES);
  184095. pDropFiles->fWide = true;
  184096. WCHAR* fname = (WCHAR*) (((char*) pDropFiles) + sizeof (DROPFILES));
  184097. for (int i = 0; i < fileNames.size(); ++i)
  184098. {
  184099. fileNames[i].copyToBuffer (fname, 2048);
  184100. fname += fileNames[i].length() + 1;
  184101. }
  184102. *fname = 0;
  184103. GlobalUnlock (hDrop);
  184104. }
  184105. return hDrop;
  184106. }
  184107. static bool performDragDrop (FORMATETC* const format, STGMEDIUM* const medium, const DWORD whatToDo) throw()
  184108. {
  184109. JuceDropSource* const source = new JuceDropSource();
  184110. JuceDataObject* const data = new JuceDataObject (source, format, medium);
  184111. DWORD effect;
  184112. const HRESULT res = DoDragDrop (data, source, whatToDo, &effect);
  184113. data->Release();
  184114. source->Release();
  184115. return res == DRAGDROP_S_DROP;
  184116. }
  184117. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMove)
  184118. {
  184119. FORMATETC format = { CF_HDROP, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  184120. STGMEDIUM medium = { TYMED_HGLOBAL, { 0 }, 0 };
  184121. medium.hGlobal = createHDrop (files);
  184122. return performDragDrop (&format, &medium, canMove ? (DROPEFFECT_COPY | DROPEFFECT_MOVE)
  184123. : DROPEFFECT_COPY);
  184124. }
  184125. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  184126. {
  184127. FORMATETC format = { CF_TEXT, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  184128. STGMEDIUM medium = { TYMED_HGLOBAL, { 0 }, 0 };
  184129. const int numChars = text.length();
  184130. medium.hGlobal = GlobalAlloc (GMEM_MOVEABLE | GMEM_ZEROINIT, (numChars + 2) * sizeof (WCHAR));
  184131. char* d = (char*) GlobalLock (medium.hGlobal);
  184132. text.copyToBuffer ((WCHAR*) d, numChars + 1);
  184133. format.cfFormat = CF_UNICODETEXT;
  184134. GlobalUnlock (medium.hGlobal);
  184135. return performDragDrop (&format, &medium, DROPEFFECT_COPY | DROPEFFECT_MOVE);
  184136. }
  184137. #endif
  184138. /*** End of inlined file: juce_win32_Windowing.cpp ***/
  184139. /*** Start of inlined file: juce_win32_Fonts.cpp ***/
  184140. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184141. // compiled on its own).
  184142. #if JUCE_INCLUDED_FILE
  184143. static int CALLBACK wfontEnum2 (ENUMLOGFONTEXW* lpelfe,
  184144. NEWTEXTMETRICEXW*,
  184145. int type,
  184146. LPARAM lParam)
  184147. {
  184148. if (lpelfe != 0 && (type & RASTER_FONTTYPE) == 0)
  184149. {
  184150. const String fontName (lpelfe->elfLogFont.lfFaceName);
  184151. ((StringArray*) lParam)->addIfNotAlreadyThere (fontName.removeCharacters (T("@")));
  184152. }
  184153. return 1;
  184154. }
  184155. static int CALLBACK wfontEnum1 (ENUMLOGFONTEXW* lpelfe,
  184156. NEWTEXTMETRICEXW*,
  184157. int type,
  184158. LPARAM lParam)
  184159. {
  184160. if (lpelfe != 0 && (type & RASTER_FONTTYPE) == 0)
  184161. {
  184162. LOGFONTW lf;
  184163. zerostruct (lf);
  184164. lf.lfWeight = FW_DONTCARE;
  184165. lf.lfOutPrecision = OUT_OUTLINE_PRECIS;
  184166. lf.lfQuality = DEFAULT_QUALITY;
  184167. lf.lfCharSet = DEFAULT_CHARSET;
  184168. lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  184169. lf.lfPitchAndFamily = FF_DONTCARE;
  184170. const String fontName (lpelfe->elfLogFont.lfFaceName);
  184171. fontName.copyToBuffer (lf.lfFaceName, LF_FACESIZE - 1);
  184172. HDC dc = CreateCompatibleDC (0);
  184173. EnumFontFamiliesEx (dc, &lf,
  184174. (FONTENUMPROCW) &wfontEnum2,
  184175. lParam, 0);
  184176. DeleteDC (dc);
  184177. }
  184178. return 1;
  184179. }
  184180. const StringArray Font::findAllTypefaceNames() throw()
  184181. {
  184182. StringArray results;
  184183. HDC dc = CreateCompatibleDC (0);
  184184. {
  184185. LOGFONTW lf;
  184186. zerostruct (lf);
  184187. lf.lfWeight = FW_DONTCARE;
  184188. lf.lfOutPrecision = OUT_OUTLINE_PRECIS;
  184189. lf.lfQuality = DEFAULT_QUALITY;
  184190. lf.lfCharSet = DEFAULT_CHARSET;
  184191. lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  184192. lf.lfPitchAndFamily = FF_DONTCARE;
  184193. lf.lfFaceName[0] = 0;
  184194. EnumFontFamiliesEx (dc, &lf,
  184195. (FONTENUMPROCW) &wfontEnum1,
  184196. (LPARAM) &results, 0);
  184197. }
  184198. DeleteDC (dc);
  184199. results.sort (true);
  184200. return results;
  184201. }
  184202. extern bool juce_IsRunningInWine();
  184203. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw()
  184204. {
  184205. if (juce_IsRunningInWine())
  184206. {
  184207. // If we're running in Wine, then use fonts that might be available on Linux..
  184208. defaultSans = "Bitstream Vera Sans";
  184209. defaultSerif = "Bitstream Vera Serif";
  184210. defaultFixed = "Bitstream Vera Sans Mono";
  184211. }
  184212. else
  184213. {
  184214. defaultSans = "Verdana";
  184215. defaultSerif = "Times";
  184216. defaultFixed = "Lucida Console";
  184217. }
  184218. }
  184219. class FontDCHolder : private DeletedAtShutdown
  184220. {
  184221. public:
  184222. FontDCHolder() throw()
  184223. : dc (0), numKPs (0), size (0),
  184224. bold (false), italic (false)
  184225. {
  184226. }
  184227. ~FontDCHolder() throw()
  184228. {
  184229. if (dc != 0)
  184230. {
  184231. DeleteDC (dc);
  184232. DeleteObject (fontH);
  184233. }
  184234. clearSingletonInstance();
  184235. }
  184236. juce_DeclareSingleton_SingleThreaded_Minimal (FontDCHolder);
  184237. HDC loadFont (const String& fontName_, const bool bold_, const bool italic_, const int size_) throw()
  184238. {
  184239. if (fontName != fontName_ || bold != bold_ || italic != italic_ || size != size_)
  184240. {
  184241. fontName = fontName_;
  184242. bold = bold_;
  184243. italic = italic_;
  184244. size = size_;
  184245. if (dc != 0)
  184246. {
  184247. DeleteDC (dc);
  184248. DeleteObject (fontH);
  184249. kps.free();
  184250. }
  184251. fontH = 0;
  184252. dc = CreateCompatibleDC (0);
  184253. SetMapperFlags (dc, 0);
  184254. SetMapMode (dc, MM_TEXT);
  184255. LOGFONTW lfw;
  184256. zerostruct (lfw);
  184257. lfw.lfCharSet = DEFAULT_CHARSET;
  184258. lfw.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  184259. lfw.lfOutPrecision = OUT_OUTLINE_PRECIS;
  184260. lfw.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
  184261. lfw.lfQuality = PROOF_QUALITY;
  184262. lfw.lfItalic = (BYTE) (italic ? TRUE : FALSE);
  184263. lfw.lfWeight = bold ? FW_BOLD : FW_NORMAL;
  184264. fontName.copyToBuffer (lfw.lfFaceName, LF_FACESIZE - 1);
  184265. lfw.lfHeight = size > 0 ? size : -256;
  184266. HFONT standardSizedFont = CreateFontIndirect (&lfw);
  184267. if (standardSizedFont != 0)
  184268. {
  184269. if (SelectObject (dc, standardSizedFont) != 0)
  184270. {
  184271. fontH = standardSizedFont;
  184272. if (size == 0)
  184273. {
  184274. OUTLINETEXTMETRIC otm;
  184275. if (GetOutlineTextMetrics (dc, sizeof (otm), &otm) != 0)
  184276. {
  184277. lfw.lfHeight = -(int) otm.otmEMSquare;
  184278. fontH = CreateFontIndirect (&lfw);
  184279. SelectObject (dc, fontH);
  184280. DeleteObject (standardSizedFont);
  184281. }
  184282. }
  184283. }
  184284. else
  184285. {
  184286. jassertfalse
  184287. }
  184288. }
  184289. else
  184290. {
  184291. jassertfalse
  184292. }
  184293. }
  184294. return dc;
  184295. }
  184296. KERNINGPAIR* getKerningPairs (int& numKPs_) throw()
  184297. {
  184298. if (kps == 0)
  184299. {
  184300. numKPs = GetKerningPairs (dc, 0, 0);
  184301. kps.calloc (numKPs);
  184302. GetKerningPairs (dc, numKPs, kps);
  184303. }
  184304. numKPs_ = numKPs;
  184305. return kps;
  184306. }
  184307. private:
  184308. HFONT fontH;
  184309. HDC dc;
  184310. String fontName;
  184311. HeapBlock <KERNINGPAIR> kps;
  184312. int numKPs, size;
  184313. bool bold, italic;
  184314. FontDCHolder (const FontDCHolder&);
  184315. const FontDCHolder& operator= (const FontDCHolder&);
  184316. };
  184317. juce_ImplementSingleton_SingleThreaded (FontDCHolder);
  184318. class WindowsTypeface : public CustomTypeface
  184319. {
  184320. public:
  184321. WindowsTypeface (const Font& font)
  184322. {
  184323. HDC dc = FontDCHolder::getInstance()->loadFont (font.getTypefaceName(),
  184324. font.isBold(), font.isItalic(), 0);
  184325. TEXTMETRIC tm;
  184326. tm.tmAscent = tm.tmHeight = 1;
  184327. tm.tmDefaultChar = 0;
  184328. GetTextMetrics (dc, &tm);
  184329. setCharacteristics (font.getTypefaceName(),
  184330. tm.tmAscent / (float) tm.tmHeight,
  184331. font.isBold(), font.isItalic(),
  184332. tm.tmDefaultChar);
  184333. }
  184334. bool loadGlyphIfPossible (const juce_wchar character)
  184335. {
  184336. HDC dc = FontDCHolder::getInstance()->loadFont (name, isBold, isItalic, 0);
  184337. GLYPHMETRICS gm;
  184338. {
  184339. const WCHAR charToTest[] = { (WCHAR) character, 0 };
  184340. WORD index = 0;
  184341. if (GetGlyphIndices (dc, charToTest, 1, &index, GGI_MARK_NONEXISTING_GLYPHS) != GDI_ERROR
  184342. && index == 0xffff)
  184343. {
  184344. return false;
  184345. }
  184346. }
  184347. Path glyphPath;
  184348. TEXTMETRIC tm;
  184349. if (! GetTextMetrics (dc, &tm))
  184350. {
  184351. addGlyph (character, glyphPath, 0);
  184352. return true;
  184353. }
  184354. const float height = (float) tm.tmHeight;
  184355. static const MAT2 identityMatrix = { { 0, 1 }, { 0, 0 }, { 0, 0 }, { 0, 1 } };
  184356. const int bufSize = GetGlyphOutline (dc, character, GGO_NATIVE,
  184357. &gm, 0, 0, &identityMatrix);
  184358. if (bufSize > 0)
  184359. {
  184360. HeapBlock <char> data (bufSize);
  184361. GetGlyphOutline (dc, character, GGO_NATIVE, &gm,
  184362. bufSize, data, &identityMatrix);
  184363. const TTPOLYGONHEADER* pheader = (TTPOLYGONHEADER*) data;
  184364. const float scaleX = 1.0f / height;
  184365. const float scaleY = -1.0f / height;
  184366. while ((char*) pheader < data + bufSize)
  184367. {
  184368. #define remapX(v) (scaleX * (v).x.value)
  184369. #define remapY(v) (scaleY * (v).y.value)
  184370. float x = remapX (pheader->pfxStart);
  184371. float y = remapY (pheader->pfxStart);
  184372. glyphPath.startNewSubPath (x, y);
  184373. const TTPOLYCURVE* curve = (const TTPOLYCURVE*) ((const char*) pheader + sizeof (TTPOLYGONHEADER));
  184374. const char* const curveEnd = ((const char*) pheader) + pheader->cb;
  184375. while ((const char*) curve < curveEnd)
  184376. {
  184377. if (curve->wType == TT_PRIM_LINE)
  184378. {
  184379. for (int i = 0; i < curve->cpfx; ++i)
  184380. {
  184381. x = remapX (curve->apfx [i]);
  184382. y = remapY (curve->apfx [i]);
  184383. glyphPath.lineTo (x, y);
  184384. }
  184385. }
  184386. else if (curve->wType == TT_PRIM_QSPLINE)
  184387. {
  184388. for (int i = 0; i < curve->cpfx - 1; ++i)
  184389. {
  184390. const float x2 = remapX (curve->apfx [i]);
  184391. const float y2 = remapY (curve->apfx [i]);
  184392. float x3, y3;
  184393. if (i < curve->cpfx - 2)
  184394. {
  184395. x3 = 0.5f * (x2 + remapX (curve->apfx [i + 1]));
  184396. y3 = 0.5f * (y2 + remapY (curve->apfx [i + 1]));
  184397. }
  184398. else
  184399. {
  184400. x3 = remapX (curve->apfx [i + 1]);
  184401. y3 = remapY (curve->apfx [i + 1]);
  184402. }
  184403. glyphPath.quadraticTo (x2, y2, x3, y3);
  184404. x = x3;
  184405. y = y3;
  184406. }
  184407. }
  184408. curve = (const TTPOLYCURVE*) &(curve->apfx [curve->cpfx]);
  184409. }
  184410. pheader = (const TTPOLYGONHEADER*) curve;
  184411. glyphPath.closeSubPath();
  184412. }
  184413. }
  184414. addGlyph (character, glyphPath, gm.gmCellIncX / height);
  184415. int numKPs;
  184416. const KERNINGPAIR* const kps = FontDCHolder::getInstance()->getKerningPairs (numKPs);
  184417. for (int i = 0; i < numKPs; ++i)
  184418. {
  184419. if (kps[i].wFirst == character)
  184420. addKerningPair (kps[i].wFirst, kps[i].wSecond,
  184421. kps[i].iKernAmount / height);
  184422. }
  184423. return true;
  184424. }
  184425. };
  184426. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  184427. {
  184428. return new WindowsTypeface (font);
  184429. }
  184430. #endif
  184431. /*** End of inlined file: juce_win32_Fonts.cpp ***/
  184432. /*** Start of inlined file: juce_win32_FileChooser.cpp ***/
  184433. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184434. // compiled on its own).
  184435. #if JUCE_INCLUDED_FILE
  184436. static const void* defaultDirPath = 0;
  184437. static String returnedString; // need this to get non-existent pathnames from the directory chooser
  184438. static Component* currentExtraFileWin = 0;
  184439. static bool areThereAnyAlwaysOnTopWindows()
  184440. {
  184441. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  184442. {
  184443. Component* c = Desktop::getInstance().getComponent (i);
  184444. if (c != 0 && c->isAlwaysOnTop() && c->isShowing())
  184445. return true;
  184446. }
  184447. return false;
  184448. }
  184449. static int CALLBACK browseCallbackProc (HWND hWnd, UINT msg, LPARAM lParam, LPARAM /*lpData*/)
  184450. {
  184451. if (msg == BFFM_INITIALIZED)
  184452. {
  184453. SendMessage (hWnd, BFFM_SETSELECTIONW, TRUE, (LPARAM) defaultDirPath);
  184454. }
  184455. else if (msg == BFFM_VALIDATEFAILEDW)
  184456. {
  184457. returnedString = (LPCWSTR) lParam;
  184458. }
  184459. else if (msg == BFFM_VALIDATEFAILEDA)
  184460. {
  184461. returnedString = (const char*) lParam;
  184462. }
  184463. return 0;
  184464. }
  184465. void juce_setWindowStyleBit (HWND h, const int styleType, const int feature, const bool bitIsSet) throw();
  184466. static UINT_PTR CALLBACK openCallback (HWND hdlg, UINT uiMsg, WPARAM /*wParam*/, LPARAM lParam)
  184467. {
  184468. if (currentExtraFileWin != 0)
  184469. {
  184470. if (uiMsg == WM_INITDIALOG)
  184471. {
  184472. HWND dialogH = GetParent (hdlg);
  184473. jassert (dialogH != 0);
  184474. if (dialogH == 0)
  184475. dialogH = hdlg;
  184476. RECT r, cr;
  184477. GetWindowRect (dialogH, &r);
  184478. GetClientRect (dialogH, &cr);
  184479. SetWindowPos (dialogH, 0,
  184480. r.left, r.top,
  184481. currentExtraFileWin->getWidth() + jmax (150, (int) (r.right - r.left)),
  184482. jmax (150, (int) (r.bottom - r.top)),
  184483. SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
  184484. currentExtraFileWin->setBounds (cr.right, cr.top, currentExtraFileWin->getWidth(), cr.bottom - cr.top);
  184485. currentExtraFileWin->getChildComponent(0)->setBounds (0, 0, currentExtraFileWin->getWidth(), currentExtraFileWin->getHeight());
  184486. SetParent ((HWND) currentExtraFileWin->getWindowHandle(), (HWND) dialogH);
  184487. juce_setWindowStyleBit ((HWND)currentExtraFileWin->getWindowHandle(), GWL_STYLE, WS_CHILD, (dialogH != 0));
  184488. juce_setWindowStyleBit ((HWND)currentExtraFileWin->getWindowHandle(), GWL_STYLE, WS_POPUP, (dialogH == 0));
  184489. }
  184490. else if (uiMsg == WM_NOTIFY)
  184491. {
  184492. LPOFNOTIFY ofn = (LPOFNOTIFY) lParam;
  184493. if (ofn->hdr.code == CDN_SELCHANGE)
  184494. {
  184495. FilePreviewComponent* comp = (FilePreviewComponent*) currentExtraFileWin->getChildComponent(0);
  184496. if (comp != 0)
  184497. {
  184498. TCHAR path [MAX_PATH * 2];
  184499. path[0] = 0;
  184500. CommDlg_OpenSave_GetFilePath (GetParent (hdlg), (LPARAM) &path, MAX_PATH);
  184501. const String fn ((const WCHAR*) path);
  184502. comp->selectedFileChanged (File (fn));
  184503. }
  184504. }
  184505. }
  184506. }
  184507. return 0;
  184508. }
  184509. class FPComponentHolder : public Component
  184510. {
  184511. public:
  184512. FPComponentHolder()
  184513. {
  184514. setVisible (true);
  184515. setOpaque (true);
  184516. }
  184517. ~FPComponentHolder()
  184518. {
  184519. }
  184520. void paint (Graphics& g)
  184521. {
  184522. g.fillAll (Colours::lightgrey);
  184523. }
  184524. private:
  184525. FPComponentHolder (const FPComponentHolder&);
  184526. const FPComponentHolder& operator= (const FPComponentHolder&);
  184527. };
  184528. void FileChooser::showPlatformDialog (Array<File>& results,
  184529. const String& title,
  184530. const File& currentFileOrDirectory,
  184531. const String& filter,
  184532. bool selectsDirectory,
  184533. bool /*selectsFiles*/,
  184534. bool isSaveDialogue,
  184535. bool warnAboutOverwritingExistingFiles,
  184536. bool selectMultipleFiles,
  184537. FilePreviewComponent* extraInfoComponent)
  184538. {
  184539. const int numCharsAvailable = 32768;
  184540. MemoryBlock filenameSpace ((numCharsAvailable + 1) * sizeof (WCHAR), true);
  184541. WCHAR* const fname = (WCHAR*) filenameSpace.getData();
  184542. int fnameIdx = 0;
  184543. JUCE_TRY
  184544. {
  184545. // use a modal window as the parent for this dialog box
  184546. // to block input from other app windows
  184547. const Rectangle<int> mainMon (Desktop::getInstance().getMainMonitorArea());
  184548. Component w (String::empty);
  184549. w.setBounds (mainMon.getX() + mainMon.getWidth() / 4,
  184550. mainMon.getY() + mainMon.getHeight() / 4,
  184551. 0, 0);
  184552. w.setOpaque (true);
  184553. w.setAlwaysOnTop (areThereAnyAlwaysOnTopWindows());
  184554. w.addToDesktop (0);
  184555. if (extraInfoComponent == 0)
  184556. w.enterModalState();
  184557. String initialDir;
  184558. if (currentFileOrDirectory.isDirectory())
  184559. {
  184560. initialDir = currentFileOrDirectory.getFullPathName();
  184561. }
  184562. else
  184563. {
  184564. currentFileOrDirectory.getFileName().copyToBuffer (fname, numCharsAvailable);
  184565. initialDir = currentFileOrDirectory.getParentDirectory().getFullPathName();
  184566. }
  184567. if (currentExtraFileWin->isValidComponent())
  184568. {
  184569. jassertfalse
  184570. return;
  184571. }
  184572. if (selectsDirectory)
  184573. {
  184574. LPITEMIDLIST list = 0;
  184575. filenameSpace.fillWith (0);
  184576. {
  184577. BROWSEINFO bi;
  184578. zerostruct (bi);
  184579. bi.hwndOwner = (HWND) w.getWindowHandle();
  184580. bi.pszDisplayName = fname;
  184581. bi.lpszTitle = title;
  184582. bi.lpfn = browseCallbackProc;
  184583. #ifdef BIF_USENEWUI
  184584. bi.ulFlags = BIF_USENEWUI | BIF_VALIDATE;
  184585. #else
  184586. bi.ulFlags = 0x50;
  184587. #endif
  184588. defaultDirPath = (const WCHAR*) initialDir;
  184589. list = SHBrowseForFolder (&bi);
  184590. if (! SHGetPathFromIDListW (list, fname))
  184591. {
  184592. fname[0] = 0;
  184593. returnedString = String::empty;
  184594. }
  184595. }
  184596. LPMALLOC al;
  184597. if (list != 0 && SUCCEEDED (SHGetMalloc (&al)))
  184598. al->Free (list);
  184599. defaultDirPath = 0;
  184600. if (returnedString.isNotEmpty())
  184601. {
  184602. const String stringFName (fname);
  184603. results.add (File (stringFName).getSiblingFile (returnedString));
  184604. returnedString = String::empty;
  184605. return;
  184606. }
  184607. }
  184608. else
  184609. {
  184610. DWORD flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
  184611. if (warnAboutOverwritingExistingFiles)
  184612. flags |= OFN_OVERWRITEPROMPT;
  184613. if (selectMultipleFiles)
  184614. flags |= OFN_ALLOWMULTISELECT;
  184615. if (extraInfoComponent != 0)
  184616. {
  184617. flags |= OFN_ENABLEHOOK;
  184618. currentExtraFileWin = new FPComponentHolder();
  184619. currentExtraFileWin->addAndMakeVisible (extraInfoComponent);
  184620. currentExtraFileWin->setSize (jlimit (20, 800, extraInfoComponent->getWidth()),
  184621. extraInfoComponent->getHeight());
  184622. currentExtraFileWin->addToDesktop (0);
  184623. currentExtraFileWin->enterModalState();
  184624. }
  184625. {
  184626. WCHAR filters [1024];
  184627. zeromem (filters, sizeof (filters));
  184628. filter.copyToBuffer (filters, 1024);
  184629. filter.copyToBuffer (filters + filter.length() + 1,
  184630. 1022 - filter.length());
  184631. OPENFILENAMEW of;
  184632. zerostruct (of);
  184633. #ifdef OPENFILENAME_SIZE_VERSION_400W
  184634. of.lStructSize = OPENFILENAME_SIZE_VERSION_400W;
  184635. #else
  184636. of.lStructSize = sizeof (of);
  184637. #endif
  184638. of.hwndOwner = (HWND) w.getWindowHandle();
  184639. of.lpstrFilter = filters;
  184640. of.nFilterIndex = 1;
  184641. of.lpstrFile = fname;
  184642. of.nMaxFile = numCharsAvailable;
  184643. of.lpstrInitialDir = initialDir;
  184644. of.lpstrTitle = title;
  184645. of.Flags = flags;
  184646. if (extraInfoComponent != 0)
  184647. of.lpfnHook = &openCallback;
  184648. if (isSaveDialogue)
  184649. {
  184650. if (! GetSaveFileName (&of))
  184651. fname[0] = 0;
  184652. else
  184653. fnameIdx = of.nFileOffset;
  184654. }
  184655. else
  184656. {
  184657. if (! GetOpenFileName (&of))
  184658. fname[0] = 0;
  184659. else
  184660. fnameIdx = of.nFileOffset;
  184661. }
  184662. }
  184663. }
  184664. }
  184665. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  184666. catch (...)
  184667. {
  184668. fname[0] = 0;
  184669. }
  184670. #endif
  184671. deleteAndZero (currentExtraFileWin);
  184672. const WCHAR* const files = fname;
  184673. if (selectMultipleFiles && fnameIdx > 0 && files [fnameIdx - 1] == 0)
  184674. {
  184675. const WCHAR* filename = files + fnameIdx;
  184676. while (*filename != 0)
  184677. {
  184678. const String filepath (String (files) + T("\\") + String (filename));
  184679. results.add (File (filepath));
  184680. filename += CharacterFunctions::length (filename) + 1;
  184681. }
  184682. }
  184683. else if (files[0] != 0)
  184684. {
  184685. results.add (File (files));
  184686. }
  184687. }
  184688. #endif
  184689. /*** End of inlined file: juce_win32_FileChooser.cpp ***/
  184690. /*** Start of inlined file: juce_win32_Misc.cpp ***/
  184691. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184692. // compiled on its own).
  184693. #if JUCE_INCLUDED_FILE
  184694. void SystemClipboard::copyTextToClipboard (const String& text) throw()
  184695. {
  184696. if (OpenClipboard (0) != 0)
  184697. {
  184698. if (EmptyClipboard() != 0)
  184699. {
  184700. const int len = text.length();
  184701. if (len > 0)
  184702. {
  184703. HGLOBAL bufH = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE,
  184704. (len + 1) * sizeof (wchar_t));
  184705. if (bufH != 0)
  184706. {
  184707. wchar_t* const data = (wchar_t*) GlobalLock (bufH);
  184708. text.copyToBuffer (data, len);
  184709. GlobalUnlock (bufH);
  184710. SetClipboardData (CF_UNICODETEXT, bufH);
  184711. }
  184712. }
  184713. }
  184714. CloseClipboard();
  184715. }
  184716. }
  184717. const String SystemClipboard::getTextFromClipboard() throw()
  184718. {
  184719. String result;
  184720. if (OpenClipboard (0) != 0)
  184721. {
  184722. HANDLE bufH = GetClipboardData (CF_UNICODETEXT);
  184723. if (bufH != 0)
  184724. {
  184725. const wchar_t* const data = (const wchar_t*) GlobalLock (bufH);
  184726. if (data != 0)
  184727. {
  184728. result = String (data, (int) (GlobalSize (bufH) / sizeof (tchar)));
  184729. GlobalUnlock (bufH);
  184730. }
  184731. }
  184732. CloseClipboard();
  184733. }
  184734. return result;
  184735. }
  184736. #endif
  184737. /*** End of inlined file: juce_win32_Misc.cpp ***/
  184738. /*** Start of inlined file: juce_win32_ActiveXComponent.cpp ***/
  184739. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184740. // compiled on its own).
  184741. #if JUCE_INCLUDED_FILE
  184742. class JuceIStorage : public IStorage
  184743. {
  184744. int refCount;
  184745. public:
  184746. JuceIStorage() : refCount (1) {}
  184747. virtual ~JuceIStorage()
  184748. {
  184749. jassert (refCount == 0);
  184750. }
  184751. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184752. {
  184753. if (id == IID_IUnknown || id == IID_IStorage)
  184754. {
  184755. AddRef();
  184756. *result = this;
  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 CreateStream (const WCHAR*, DWORD, DWORD, DWORD, IStream**) { return E_NOTIMPL; }
  184765. HRESULT __stdcall OpenStream (const WCHAR*, void*, DWORD, DWORD, IStream**) { return E_NOTIMPL; }
  184766. HRESULT __stdcall CreateStorage (const WCHAR*, DWORD, DWORD, DWORD, IStorage**) { return E_NOTIMPL; }
  184767. HRESULT __stdcall OpenStorage (const WCHAR*, IStorage*, DWORD, SNB, DWORD, IStorage**) { return E_NOTIMPL; }
  184768. HRESULT __stdcall CopyTo (DWORD, IID const*, SNB, IStorage*) { return E_NOTIMPL; }
  184769. HRESULT __stdcall MoveElementTo (const OLECHAR*,IStorage*, const OLECHAR*, DWORD) { return E_NOTIMPL; }
  184770. HRESULT __stdcall Commit (DWORD) { return E_NOTIMPL; }
  184771. HRESULT __stdcall Revert() { return E_NOTIMPL; }
  184772. HRESULT __stdcall EnumElements (DWORD, void*, DWORD, IEnumSTATSTG**) { return E_NOTIMPL; }
  184773. HRESULT __stdcall DestroyElement (const OLECHAR*) { return E_NOTIMPL; }
  184774. HRESULT __stdcall RenameElement (const WCHAR*, const WCHAR*) { return E_NOTIMPL; }
  184775. HRESULT __stdcall SetElementTimes (const WCHAR*, FILETIME const*, FILETIME const*, FILETIME const*) { return E_NOTIMPL; }
  184776. HRESULT __stdcall SetClass (REFCLSID) { return S_OK; }
  184777. HRESULT __stdcall SetStateBits (DWORD, DWORD) { return E_NOTIMPL; }
  184778. HRESULT __stdcall Stat (STATSTG*, DWORD) { return E_NOTIMPL; }
  184779. juce_UseDebuggingNewOperator
  184780. };
  184781. class JuceOleInPlaceFrame : public IOleInPlaceFrame
  184782. {
  184783. int refCount;
  184784. HWND window;
  184785. public:
  184786. JuceOleInPlaceFrame (HWND window_)
  184787. : refCount (1),
  184788. window (window_)
  184789. {
  184790. }
  184791. virtual ~JuceOleInPlaceFrame()
  184792. {
  184793. jassert (refCount == 0);
  184794. }
  184795. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184796. {
  184797. if (id == IID_IUnknown || id == IID_IOleInPlaceFrame)
  184798. {
  184799. AddRef();
  184800. *result = this;
  184801. return S_OK;
  184802. }
  184803. *result = 0;
  184804. return E_NOINTERFACE;
  184805. }
  184806. ULONG __stdcall AddRef() { return ++refCount; }
  184807. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184808. HRESULT __stdcall GetWindow (HWND* lphwnd) { *lphwnd = window; return S_OK; }
  184809. HRESULT __stdcall ContextSensitiveHelp (BOOL) { return E_NOTIMPL; }
  184810. HRESULT __stdcall GetBorder (LPRECT) { return E_NOTIMPL; }
  184811. HRESULT __stdcall RequestBorderSpace (LPCBORDERWIDTHS) { return E_NOTIMPL; }
  184812. HRESULT __stdcall SetBorderSpace (LPCBORDERWIDTHS) { return E_NOTIMPL; }
  184813. HRESULT __stdcall SetActiveObject (IOleInPlaceActiveObject*, LPCOLESTR) { return S_OK; }
  184814. HRESULT __stdcall InsertMenus (HMENU, LPOLEMENUGROUPWIDTHS) { return E_NOTIMPL; }
  184815. HRESULT __stdcall SetMenu (HMENU, HOLEMENU, HWND) { return S_OK; }
  184816. HRESULT __stdcall RemoveMenus (HMENU) { return E_NOTIMPL; }
  184817. HRESULT __stdcall SetStatusText (LPCOLESTR) { return S_OK; }
  184818. HRESULT __stdcall EnableModeless (BOOL) { return S_OK; }
  184819. HRESULT __stdcall TranslateAccelerator(LPMSG, WORD) { return E_NOTIMPL; }
  184820. juce_UseDebuggingNewOperator
  184821. };
  184822. class JuceIOleInPlaceSite : public IOleInPlaceSite
  184823. {
  184824. int refCount;
  184825. HWND window;
  184826. JuceOleInPlaceFrame* frame;
  184827. public:
  184828. JuceIOleInPlaceSite (HWND window_)
  184829. : refCount (1),
  184830. window (window_)
  184831. {
  184832. frame = new JuceOleInPlaceFrame (window);
  184833. }
  184834. virtual ~JuceIOleInPlaceSite()
  184835. {
  184836. jassert (refCount == 0);
  184837. frame->Release();
  184838. }
  184839. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184840. {
  184841. if (id == IID_IUnknown || id == IID_IOleInPlaceSite)
  184842. {
  184843. AddRef();
  184844. *result = this;
  184845. return S_OK;
  184846. }
  184847. *result = 0;
  184848. return E_NOINTERFACE;
  184849. }
  184850. ULONG __stdcall AddRef() { return ++refCount; }
  184851. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184852. HRESULT __stdcall GetWindow (HWND* lphwnd) { *lphwnd = window; return S_OK; }
  184853. HRESULT __stdcall ContextSensitiveHelp (BOOL) { return E_NOTIMPL; }
  184854. HRESULT __stdcall CanInPlaceActivate() { return S_OK; }
  184855. HRESULT __stdcall OnInPlaceActivate() { return S_OK; }
  184856. HRESULT __stdcall OnUIActivate() { return S_OK; }
  184857. HRESULT __stdcall GetWindowContext (LPOLEINPLACEFRAME* lplpFrame, LPOLEINPLACEUIWINDOW* lplpDoc, LPRECT, LPRECT, LPOLEINPLACEFRAMEINFO lpFrameInfo)
  184858. {
  184859. // frame->AddRef(); // MS docs are unclear about whether this is needed, but it seems to lead to a memory leak..
  184860. *lplpFrame = frame;
  184861. *lplpDoc = 0;
  184862. lpFrameInfo->fMDIApp = FALSE;
  184863. lpFrameInfo->hwndFrame = window;
  184864. lpFrameInfo->haccel = 0;
  184865. lpFrameInfo->cAccelEntries = 0;
  184866. return S_OK;
  184867. }
  184868. HRESULT __stdcall Scroll (SIZE) { return E_NOTIMPL; }
  184869. HRESULT __stdcall OnUIDeactivate (BOOL) { return S_OK; }
  184870. HRESULT __stdcall OnInPlaceDeactivate() { return S_OK; }
  184871. HRESULT __stdcall DiscardUndoState() { return E_NOTIMPL; }
  184872. HRESULT __stdcall DeactivateAndUndo() { return E_NOTIMPL; }
  184873. HRESULT __stdcall OnPosRectChange (LPCRECT) { return S_OK; }
  184874. juce_UseDebuggingNewOperator
  184875. };
  184876. class JuceIOleClientSite : public IOleClientSite
  184877. {
  184878. int refCount;
  184879. JuceIOleInPlaceSite* inplaceSite;
  184880. public:
  184881. JuceIOleClientSite (HWND window)
  184882. : refCount (1)
  184883. {
  184884. inplaceSite = new JuceIOleInPlaceSite (window);
  184885. }
  184886. virtual ~JuceIOleClientSite()
  184887. {
  184888. jassert (refCount == 0);
  184889. inplaceSite->Release();
  184890. }
  184891. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184892. {
  184893. if (id == IID_IUnknown || id == IID_IOleClientSite)
  184894. {
  184895. AddRef();
  184896. *result = this;
  184897. return S_OK;
  184898. }
  184899. else if (id == IID_IOleInPlaceSite)
  184900. {
  184901. inplaceSite->AddRef();
  184902. *result = inplaceSite;
  184903. return S_OK;
  184904. }
  184905. *result = 0;
  184906. return E_NOINTERFACE;
  184907. }
  184908. ULONG __stdcall AddRef() { return ++refCount; }
  184909. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184910. HRESULT __stdcall SaveObject() { return E_NOTIMPL; }
  184911. HRESULT __stdcall GetMoniker (DWORD, DWORD, IMoniker**) { return E_NOTIMPL; }
  184912. HRESULT __stdcall GetContainer (LPOLECONTAINER* ppContainer) { *ppContainer = 0; return E_NOINTERFACE; }
  184913. HRESULT __stdcall ShowObject() { return S_OK; }
  184914. HRESULT __stdcall OnShowWindow (BOOL) { return E_NOTIMPL; }
  184915. HRESULT __stdcall RequestNewObjectLayout() { return E_NOTIMPL; }
  184916. juce_UseDebuggingNewOperator
  184917. };
  184918. class ActiveXControlData : public ComponentMovementWatcher
  184919. {
  184920. ActiveXControlComponent* const owner;
  184921. bool wasShowing;
  184922. public:
  184923. HWND controlHWND;
  184924. IStorage* storage;
  184925. IOleClientSite* clientSite;
  184926. IOleObject* control;
  184927. ActiveXControlData (HWND hwnd,
  184928. ActiveXControlComponent* const owner_)
  184929. : ComponentMovementWatcher (owner_),
  184930. owner (owner_),
  184931. wasShowing (owner_ != 0 && owner_->isShowing()),
  184932. controlHWND (0),
  184933. storage (new JuceIStorage()),
  184934. clientSite (new JuceIOleClientSite (hwnd)),
  184935. control (0)
  184936. {
  184937. }
  184938. ~ActiveXControlData()
  184939. {
  184940. if (control != 0)
  184941. {
  184942. control->Close (OLECLOSE_NOSAVE);
  184943. control->Release();
  184944. }
  184945. clientSite->Release();
  184946. storage->Release();
  184947. }
  184948. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  184949. {
  184950. Component* const topComp = owner->getTopLevelComponent();
  184951. if (topComp->getPeer() != 0)
  184952. {
  184953. int x = 0, y = 0;
  184954. owner->relativePositionToOtherComponent (topComp, x, y);
  184955. owner->setControlBounds (Rectangle<int> (x, y, owner->getWidth(), owner->getHeight()));
  184956. }
  184957. }
  184958. void componentPeerChanged()
  184959. {
  184960. const bool isShowingNow = owner->isShowing();
  184961. if (wasShowing != isShowingNow)
  184962. {
  184963. wasShowing = isShowingNow;
  184964. owner->setControlVisible (isShowingNow);
  184965. }
  184966. componentMovedOrResized (true, true);
  184967. }
  184968. void componentVisibilityChanged (Component&)
  184969. {
  184970. componentPeerChanged();
  184971. }
  184972. static bool doesWindowMatch (const ActiveXControlComponent* const ax, HWND hwnd)
  184973. {
  184974. return ((ActiveXControlData*) ax->control) != 0
  184975. && ((ActiveXControlData*) ax->control)->controlHWND == hwnd;
  184976. }
  184977. };
  184978. static VoidArray activeXComps;
  184979. static HWND getHWND (const ActiveXControlComponent* const component)
  184980. {
  184981. HWND hwnd = 0;
  184982. const IID iid = IID_IOleWindow;
  184983. IOleWindow* const window = (IOleWindow*) component->queryInterface (&iid);
  184984. if (window != 0)
  184985. {
  184986. window->GetWindow (&hwnd);
  184987. window->Release();
  184988. }
  184989. return hwnd;
  184990. }
  184991. static void offerActiveXMouseEventToPeer (ComponentPeer* const peer, HWND hwnd, UINT message, LPARAM lParam)
  184992. {
  184993. RECT activeXRect, peerRect;
  184994. GetWindowRect (hwnd, &activeXRect);
  184995. GetWindowRect ((HWND) peer->getNativeHandle(), &peerRect);
  184996. const int mx = GET_X_LPARAM (lParam) + activeXRect.left - peerRect.left;
  184997. const int my = GET_Y_LPARAM (lParam) + activeXRect.top - peerRect.top;
  184998. const int64 mouseEventTime = getMouseEventTime();
  184999. const int oldModifiers = currentModifiers;
  185000. ModifierKeys::getCurrentModifiersRealtime(); // to update the mouse button flags
  185001. switch (message)
  185002. {
  185003. case WM_MOUSEMOVE:
  185004. if (ModifierKeys (currentModifiers).isAnyMouseButtonDown())
  185005. peer->handleMouseDrag (mx, my, mouseEventTime);
  185006. else
  185007. peer->handleMouseMove (mx, my, mouseEventTime);
  185008. break;
  185009. case WM_LBUTTONDOWN:
  185010. case WM_MBUTTONDOWN:
  185011. case WM_RBUTTONDOWN:
  185012. peer->handleMouseDown (mx, my, mouseEventTime);
  185013. break;
  185014. case WM_LBUTTONUP:
  185015. case WM_MBUTTONUP:
  185016. case WM_RBUTTONUP:
  185017. peer->handleMouseUp (oldModifiers, mx, my, mouseEventTime);
  185018. break;
  185019. default:
  185020. break;
  185021. }
  185022. }
  185023. // intercepts events going to an activeX control, so we can sneakily use the mouse events
  185024. static LRESULT CALLBACK activeXHookWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  185025. {
  185026. for (int i = activeXComps.size(); --i >= 0;)
  185027. {
  185028. const ActiveXControlComponent* const ax = (const ActiveXControlComponent*) activeXComps.getUnchecked(i);
  185029. if (ActiveXControlData::doesWindowMatch (ax, hwnd))
  185030. {
  185031. switch (message)
  185032. {
  185033. case WM_MOUSEMOVE:
  185034. case WM_LBUTTONDOWN:
  185035. case WM_MBUTTONDOWN:
  185036. case WM_RBUTTONDOWN:
  185037. case WM_LBUTTONUP:
  185038. case WM_MBUTTONUP:
  185039. case WM_RBUTTONUP:
  185040. case WM_LBUTTONDBLCLK:
  185041. case WM_MBUTTONDBLCLK:
  185042. case WM_RBUTTONDBLCLK:
  185043. if (ax->isShowing())
  185044. {
  185045. ComponentPeer* const peer = ax->getPeer();
  185046. if (peer != 0)
  185047. {
  185048. offerActiveXMouseEventToPeer (peer, hwnd, message, lParam);
  185049. if (! ax->areMouseEventsAllowed())
  185050. return 0;
  185051. }
  185052. }
  185053. break;
  185054. default:
  185055. break;
  185056. }
  185057. return CallWindowProc ((WNDPROC) (ax->originalWndProc), hwnd, message, wParam, lParam);
  185058. }
  185059. }
  185060. return DefWindowProc (hwnd, message, wParam, lParam);
  185061. }
  185062. ActiveXControlComponent::ActiveXControlComponent()
  185063. : originalWndProc (0),
  185064. control (0),
  185065. mouseEventsAllowed (true)
  185066. {
  185067. activeXComps.add (this);
  185068. }
  185069. ActiveXControlComponent::~ActiveXControlComponent()
  185070. {
  185071. deleteControl();
  185072. activeXComps.removeValue (this);
  185073. }
  185074. void ActiveXControlComponent::paint (Graphics& g)
  185075. {
  185076. if (control == 0)
  185077. g.fillAll (Colours::lightgrey);
  185078. }
  185079. bool ActiveXControlComponent::createControl (const void* controlIID)
  185080. {
  185081. deleteControl();
  185082. ComponentPeer* const peer = getPeer();
  185083. // the component must have already been added to a real window when you call this!
  185084. jassert (dynamic_cast <Win32ComponentPeer*> (peer) != 0);
  185085. if (dynamic_cast <Win32ComponentPeer*> (peer) != 0)
  185086. {
  185087. int x = 0, y = 0;
  185088. relativePositionToOtherComponent (getTopLevelComponent(), x, y);
  185089. HWND hwnd = (HWND) peer->getNativeHandle();
  185090. ScopedPointer <ActiveXControlData> info (new ActiveXControlData (hwnd, this));
  185091. HRESULT hr;
  185092. if ((hr = OleCreate (*(const IID*) controlIID, IID_IOleObject, 1 /*OLERENDER_DRAW*/, 0,
  185093. info->clientSite, info->storage,
  185094. (void**) &(info->control))) == S_OK)
  185095. {
  185096. info->control->SetHostNames (L"Juce", 0);
  185097. if (OleSetContainedObject (info->control, TRUE) == S_OK)
  185098. {
  185099. RECT rect;
  185100. rect.left = x;
  185101. rect.top = y;
  185102. rect.right = x + getWidth();
  185103. rect.bottom = y + getHeight();
  185104. if (info->control->DoVerb (OLEIVERB_SHOW, 0, info->clientSite, 0, hwnd, &rect) == S_OK)
  185105. {
  185106. control = info.release();
  185107. setControlBounds (Rectangle<int> (x, y, getWidth(), getHeight()));
  185108. ((ActiveXControlData*) control)->controlHWND = getHWND (this);
  185109. if (((ActiveXControlData*) control)->controlHWND != 0)
  185110. {
  185111. originalWndProc = (void*) (pointer_sized_int) GetWindowLongPtr ((HWND) ((ActiveXControlData*) control)->controlHWND, GWLP_WNDPROC);
  185112. SetWindowLongPtr ((HWND) ((ActiveXControlData*) control)->controlHWND, GWLP_WNDPROC, (LONG_PTR) activeXHookWndProc);
  185113. }
  185114. return true;
  185115. }
  185116. }
  185117. }
  185118. }
  185119. return false;
  185120. }
  185121. void ActiveXControlComponent::deleteControl()
  185122. {
  185123. ActiveXControlData* const info = (ActiveXControlData*) control;
  185124. if (info != 0)
  185125. {
  185126. delete info;
  185127. control = 0;
  185128. originalWndProc = 0;
  185129. }
  185130. }
  185131. void* ActiveXControlComponent::queryInterface (const void* iid) const
  185132. {
  185133. ActiveXControlData* const info = (ActiveXControlData*) control;
  185134. void* result = 0;
  185135. if (info != 0 && info->control != 0
  185136. && info->control->QueryInterface (*(const IID*) iid, &result) == S_OK)
  185137. return result;
  185138. return 0;
  185139. }
  185140. void ActiveXControlComponent::setControlBounds (const Rectangle<int>& newBounds) const
  185141. {
  185142. HWND hwnd = ((ActiveXControlData*) control)->controlHWND;
  185143. if (hwnd != 0)
  185144. MoveWindow (hwnd, newBounds.getX(), newBounds.getY(), newBounds.getWidth(), newBounds.getHeight(), TRUE);
  185145. }
  185146. void ActiveXControlComponent::setControlVisible (const bool shouldBeVisible) const
  185147. {
  185148. HWND hwnd = ((ActiveXControlData*) control)->controlHWND;
  185149. if (hwnd != 0)
  185150. ShowWindow (hwnd, shouldBeVisible ? SW_SHOWNA : SW_HIDE);
  185151. }
  185152. void ActiveXControlComponent::setMouseEventsAllowed (const bool eventsCanReachControl)
  185153. {
  185154. mouseEventsAllowed = eventsCanReachControl;
  185155. }
  185156. #endif
  185157. /*** End of inlined file: juce_win32_ActiveXComponent.cpp ***/
  185158. /*** Start of inlined file: juce_win32_QuickTimeMovieComponent.cpp ***/
  185159. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  185160. // compiled on its own).
  185161. #if JUCE_INCLUDED_FILE && JUCE_QUICKTIME
  185162. using namespace QTOLibrary;
  185163. using namespace QTOControlLib;
  185164. bool juce_OpenQuickTimeMovieFromStream (InputStream* input, Movie& movie, Handle& dataHandle);
  185165. static bool isQTAvailable = false;
  185166. struct QTMovieCompInternal
  185167. {
  185168. QTMovieCompInternal()
  185169. : dataHandle (0)
  185170. {
  185171. }
  185172. ~QTMovieCompInternal()
  185173. {
  185174. clearHandle();
  185175. }
  185176. IQTControlPtr qtControlInternal;
  185177. IQTMoviePtr qtMovieInternal;
  185178. Handle dataHandle;
  185179. void clearHandle()
  185180. {
  185181. if (dataHandle != 0)
  185182. {
  185183. DisposeHandle (dataHandle);
  185184. dataHandle = 0;
  185185. }
  185186. }
  185187. };
  185188. #define qtControl (((QTMovieCompInternal*) internal)->qtControlInternal)
  185189. #define qtMovie (((QTMovieCompInternal*) internal)->qtMovieInternal)
  185190. QuickTimeMovieComponent::QuickTimeMovieComponent()
  185191. : movieLoaded (false),
  185192. controllerVisible (true)
  185193. {
  185194. internal = new QTMovieCompInternal();
  185195. setMouseEventsAllowed (false);
  185196. }
  185197. QuickTimeMovieComponent::~QuickTimeMovieComponent()
  185198. {
  185199. closeMovie();
  185200. qtControl = 0;
  185201. deleteControl();
  185202. delete internal;
  185203. internal = 0;
  185204. }
  185205. bool QuickTimeMovieComponent::isQuickTimeAvailable() throw()
  185206. {
  185207. if (! isQTAvailable)
  185208. {
  185209. isQTAvailable = (InitializeQTML (0) == noErr)
  185210. && (EnterMovies() == noErr);
  185211. }
  185212. return isQTAvailable;
  185213. }
  185214. void QuickTimeMovieComponent::createControlIfNeeded()
  185215. {
  185216. if (isShowing() && ! isControlCreated())
  185217. {
  185218. const IID qtIID = __uuidof (QTControl);
  185219. if (createControl (&qtIID))
  185220. {
  185221. const IID qtInterfaceIID = __uuidof (IQTControl);
  185222. qtControl = (IQTControl*) queryInterface (&qtInterfaceIID);
  185223. if (qtControl != 0)
  185224. {
  185225. qtControl->Release(); // it has one ref too many at this point
  185226. qtControl->QuickTimeInitialize();
  185227. qtControl->PutSizing (qtMovieFitsControl);
  185228. if (movieFile != File::nonexistent)
  185229. loadMovie (movieFile, controllerVisible);
  185230. }
  185231. }
  185232. }
  185233. }
  185234. bool QuickTimeMovieComponent::isControlCreated() const
  185235. {
  185236. return isControlOpen();
  185237. }
  185238. bool QuickTimeMovieComponent::loadMovie (InputStream* movieStream,
  185239. const bool isControllerVisible)
  185240. {
  185241. movieFile = File::nonexistent;
  185242. movieLoaded = false;
  185243. qtMovie = 0;
  185244. controllerVisible = isControllerVisible;
  185245. createControlIfNeeded();
  185246. if (isControlCreated())
  185247. {
  185248. if (qtControl != 0)
  185249. {
  185250. qtControl->Put_MovieHandle (0);
  185251. ((QTMovieCompInternal*) internal)->clearHandle();
  185252. Movie movie;
  185253. if (juce_OpenQuickTimeMovieFromStream (movieStream, movie, ((QTMovieCompInternal*) internal)->dataHandle))
  185254. {
  185255. qtControl->Put_MovieHandle ((long) (pointer_sized_int) movie);
  185256. qtMovie = qtControl->GetMovie();
  185257. if (qtMovie != 0)
  185258. qtMovie->PutMovieControllerType (isControllerVisible ? qtMovieControllerTypeStandard
  185259. : qtMovieControllerTypeNone);
  185260. }
  185261. if (movie == 0)
  185262. ((QTMovieCompInternal*) internal)->clearHandle();
  185263. }
  185264. movieLoaded = (qtMovie != 0);
  185265. }
  185266. else
  185267. {
  185268. // You're trying to open a movie when the control hasn't yet been created, probably because
  185269. // you've not yet added this component to a Window and made the whole component hierarchy visible.
  185270. jassertfalse
  185271. }
  185272. delete movieStream;
  185273. return movieLoaded;
  185274. }
  185275. void QuickTimeMovieComponent::closeMovie()
  185276. {
  185277. stop();
  185278. movieFile = File::nonexistent;
  185279. movieLoaded = false;
  185280. qtMovie = 0;
  185281. if (qtControl != 0)
  185282. qtControl->Put_MovieHandle (0);
  185283. ((QTMovieCompInternal*) internal)->clearHandle();
  185284. }
  185285. const File QuickTimeMovieComponent::getCurrentMovieFile() const
  185286. {
  185287. return movieFile;
  185288. }
  185289. bool QuickTimeMovieComponent::isMovieOpen() const
  185290. {
  185291. return movieLoaded;
  185292. }
  185293. double QuickTimeMovieComponent::getMovieDuration() const
  185294. {
  185295. if (qtMovie != 0)
  185296. return qtMovie->GetDuration() / (double) qtMovie->GetTimeScale();
  185297. return 0.0;
  185298. }
  185299. void QuickTimeMovieComponent::getMovieNormalSize (int& width, int& height) const
  185300. {
  185301. if (qtMovie != 0)
  185302. {
  185303. struct QTRECT r = qtMovie->GetNaturalRect();
  185304. width = r.right - r.left;
  185305. height = r.bottom - r.top;
  185306. }
  185307. else
  185308. {
  185309. width = height = 0;
  185310. }
  185311. }
  185312. void QuickTimeMovieComponent::play()
  185313. {
  185314. if (qtMovie != 0)
  185315. qtMovie->Play();
  185316. }
  185317. void QuickTimeMovieComponent::stop()
  185318. {
  185319. if (qtMovie != 0)
  185320. qtMovie->Stop();
  185321. }
  185322. bool QuickTimeMovieComponent::isPlaying() const
  185323. {
  185324. return qtMovie != 0 && qtMovie->GetRate() != 0.0f;
  185325. }
  185326. void QuickTimeMovieComponent::setPosition (const double seconds)
  185327. {
  185328. if (qtMovie != 0)
  185329. qtMovie->PutTime ((long) (seconds * qtMovie->GetTimeScale()));
  185330. }
  185331. double QuickTimeMovieComponent::getPosition() const
  185332. {
  185333. if (qtMovie != 0)
  185334. return qtMovie->GetTime() / (double) qtMovie->GetTimeScale();
  185335. return 0.0;
  185336. }
  185337. void QuickTimeMovieComponent::setSpeed (const float newSpeed)
  185338. {
  185339. if (qtMovie != 0)
  185340. qtMovie->PutRate (newSpeed);
  185341. }
  185342. void QuickTimeMovieComponent::setMovieVolume (const float newVolume)
  185343. {
  185344. if (qtMovie != 0)
  185345. {
  185346. qtMovie->PutAudioVolume (newVolume);
  185347. qtMovie->PutAudioMute (newVolume <= 0);
  185348. }
  185349. }
  185350. float QuickTimeMovieComponent::getMovieVolume() const
  185351. {
  185352. if (qtMovie != 0)
  185353. return qtMovie->GetAudioVolume();
  185354. return 0.0f;
  185355. }
  185356. void QuickTimeMovieComponent::setLooping (const bool shouldLoop)
  185357. {
  185358. if (qtMovie != 0)
  185359. qtMovie->PutLoop (shouldLoop);
  185360. }
  185361. bool QuickTimeMovieComponent::isLooping() const
  185362. {
  185363. return qtMovie != 0 && qtMovie->GetLoop();
  185364. }
  185365. bool QuickTimeMovieComponent::isControllerVisible() const
  185366. {
  185367. return controllerVisible;
  185368. }
  185369. void QuickTimeMovieComponent::parentHierarchyChanged()
  185370. {
  185371. createControlIfNeeded();
  185372. QTCompBaseClass::parentHierarchyChanged();
  185373. }
  185374. void QuickTimeMovieComponent::visibilityChanged()
  185375. {
  185376. createControlIfNeeded();
  185377. QTCompBaseClass::visibilityChanged();
  185378. }
  185379. void QuickTimeMovieComponent::paint (Graphics& g)
  185380. {
  185381. if (! isControlCreated())
  185382. g.fillAll (Colours::black);
  185383. }
  185384. static Handle createHandleDataRef (Handle dataHandle, const char* fileName)
  185385. {
  185386. Handle dataRef = 0;
  185387. OSStatus err = PtrToHand (&dataHandle, &dataRef, sizeof (Handle));
  185388. if (err == noErr)
  185389. {
  185390. Str255 suffix;
  185391. CharacterFunctions::copy ((char*) suffix, fileName, 128);
  185392. StringPtr name = suffix;
  185393. err = PtrAndHand (name, dataRef, name[0] + 1);
  185394. if (err == noErr)
  185395. {
  185396. long atoms[3];
  185397. atoms[0] = EndianU32_NtoB (3 * sizeof (long));
  185398. atoms[1] = EndianU32_NtoB (kDataRefExtensionMacOSFileType);
  185399. atoms[2] = EndianU32_NtoB (MovieFileType);
  185400. err = PtrAndHand (atoms, dataRef, 3 * sizeof (long));
  185401. if (err == noErr)
  185402. return dataRef;
  185403. }
  185404. DisposeHandle (dataRef);
  185405. }
  185406. return 0;
  185407. }
  185408. static CFStringRef juceStringToCFString (const String& s)
  185409. {
  185410. const int len = s.length();
  185411. const juce_wchar* const t = (const juce_wchar*) s;
  185412. HeapBlock <UniChar> temp (len + 2);
  185413. for (int i = 0; i <= len; ++i)
  185414. temp[i] = t[i];
  185415. return CFStringCreateWithCharacters (kCFAllocatorDefault, temp, len);
  185416. }
  185417. static bool openMovie (QTNewMoviePropertyElement* props, int prop, Movie& movie)
  185418. {
  185419. Boolean trueBool = true;
  185420. props[prop].propClass = kQTPropertyClass_MovieInstantiation;
  185421. props[prop].propID = kQTMovieInstantiationPropertyID_DontResolveDataRefs;
  185422. props[prop].propValueSize = sizeof (trueBool);
  185423. props[prop].propValueAddress = &trueBool;
  185424. ++prop;
  185425. props[prop].propClass = kQTPropertyClass_MovieInstantiation;
  185426. props[prop].propID = kQTMovieInstantiationPropertyID_AsyncOK;
  185427. props[prop].propValueSize = sizeof (trueBool);
  185428. props[prop].propValueAddress = &trueBool;
  185429. ++prop;
  185430. Boolean isActive = true;
  185431. props[prop].propClass = kQTPropertyClass_NewMovieProperty;
  185432. props[prop].propID = kQTNewMoviePropertyID_Active;
  185433. props[prop].propValueSize = sizeof (isActive);
  185434. props[prop].propValueAddress = &isActive;
  185435. ++prop;
  185436. MacSetPort (0);
  185437. jassert (prop <= 5);
  185438. OSStatus err = NewMovieFromProperties (prop, props, 0, 0, &movie);
  185439. return err == noErr;
  185440. }
  185441. bool juce_OpenQuickTimeMovieFromStream (InputStream* input, Movie& movie, Handle& dataHandle)
  185442. {
  185443. if (input == 0)
  185444. return false;
  185445. dataHandle = 0;
  185446. bool ok = false;
  185447. QTNewMoviePropertyElement props[5];
  185448. zeromem (props, sizeof (props));
  185449. int prop = 0;
  185450. DataReferenceRecord dr;
  185451. props[prop].propClass = kQTPropertyClass_DataLocation;
  185452. props[prop].propID = kQTDataLocationPropertyID_DataReference;
  185453. props[prop].propValueSize = sizeof (dr);
  185454. props[prop].propValueAddress = (void*) &dr;
  185455. ++prop;
  185456. FileInputStream* const fin = dynamic_cast <FileInputStream*> (input);
  185457. if (fin != 0)
  185458. {
  185459. CFStringRef filePath = juceStringToCFString (fin->getFile().getFullPathName());
  185460. QTNewDataReferenceFromFullPathCFString (filePath, (QTPathStyle) kQTNativeDefaultPathStyle, 0,
  185461. &dr.dataRef, &dr.dataRefType);
  185462. ok = openMovie (props, prop, movie);
  185463. DisposeHandle (dr.dataRef);
  185464. CFRelease (filePath);
  185465. }
  185466. else
  185467. {
  185468. // sanity-check because this currently needs to load the whole stream into memory..
  185469. jassert (input->getTotalLength() < 50 * 1024 * 1024);
  185470. dataHandle = NewHandle ((Size) input->getTotalLength());
  185471. HLock (dataHandle);
  185472. // read the entire stream into memory - this is a pain, but can't get it to work
  185473. // properly using a custom callback to supply the data.
  185474. input->read (*dataHandle, (int) input->getTotalLength());
  185475. HUnlock (dataHandle);
  185476. // different types to get QT to try. (We should really be a bit smarter here by
  185477. // working out in advance which one the stream contains, rather than just trying
  185478. // each one)
  185479. const char* const suffixesToTry[] = { "\04.mov", "\04.mp3",
  185480. "\04.avi", "\04.m4a" };
  185481. for (int i = 0; i < numElementsInArray (suffixesToTry) && ! ok; ++i)
  185482. {
  185483. dr.dataRef = createHandleDataRef (dataHandle, suffixesToTry [i]);
  185484. dr.dataRefType = HandleDataHandlerSubType;
  185485. ok = openMovie (props, prop, movie);
  185486. DisposeHandle (dr.dataRef);
  185487. }
  185488. }
  185489. return ok;
  185490. }
  185491. bool QuickTimeMovieComponent::loadMovie (const File& movieFile_,
  185492. const bool isControllerVisible)
  185493. {
  185494. const bool ok = loadMovie ((InputStream*) movieFile_.createInputStream(), isControllerVisible);
  185495. movieFile = movieFile_;
  185496. return ok;
  185497. }
  185498. bool QuickTimeMovieComponent::loadMovie (const URL& movieURL,
  185499. const bool isControllerVisible)
  185500. {
  185501. return loadMovie ((InputStream*) movieURL.createInputStream (false), isControllerVisible);
  185502. }
  185503. void QuickTimeMovieComponent::goToStart()
  185504. {
  185505. setPosition (0.0);
  185506. }
  185507. void QuickTimeMovieComponent::setBoundsWithCorrectAspectRatio (const Rectangle<int>& spaceToFitWithin,
  185508. const RectanglePlacement& placement)
  185509. {
  185510. int normalWidth, normalHeight;
  185511. getMovieNormalSize (normalWidth, normalHeight);
  185512. if (normalWidth > 0 && normalHeight > 0 && ! spaceToFitWithin.isEmpty())
  185513. {
  185514. double x = 0.0, y = 0.0, w = normalWidth, h = normalHeight;
  185515. placement.applyTo (x, y, w, h,
  185516. spaceToFitWithin.getX(), spaceToFitWithin.getY(),
  185517. spaceToFitWithin.getWidth(), spaceToFitWithin.getHeight());
  185518. if (w > 0 && h > 0)
  185519. {
  185520. setBounds (roundToInt (x), roundToInt (y),
  185521. roundToInt (w), roundToInt (h));
  185522. }
  185523. }
  185524. else
  185525. {
  185526. setBounds (spaceToFitWithin);
  185527. }
  185528. }
  185529. #endif
  185530. /*** End of inlined file: juce_win32_QuickTimeMovieComponent.cpp ***/
  185531. /*** Start of inlined file: juce_win32_WebBrowserComponent.cpp ***/
  185532. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  185533. // compiled on its own).
  185534. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  185535. class WebBrowserComponentInternal : public ActiveXControlComponent
  185536. {
  185537. public:
  185538. WebBrowserComponentInternal()
  185539. : browser (0),
  185540. connectionPoint (0),
  185541. adviseCookie (0)
  185542. {
  185543. }
  185544. ~WebBrowserComponentInternal()
  185545. {
  185546. if (connectionPoint != 0)
  185547. connectionPoint->Unadvise (adviseCookie);
  185548. if (browser != 0)
  185549. browser->Release();
  185550. }
  185551. void createBrowser()
  185552. {
  185553. createControl (&CLSID_WebBrowser);
  185554. browser = (IWebBrowser2*) queryInterface (&IID_IWebBrowser2);
  185555. IConnectionPointContainer* connectionPointContainer = (IConnectionPointContainer*) queryInterface (&IID_IConnectionPointContainer);
  185556. if (connectionPointContainer != 0)
  185557. {
  185558. connectionPointContainer->FindConnectionPoint (DIID_DWebBrowserEvents2,
  185559. &connectionPoint);
  185560. if (connectionPoint != 0)
  185561. {
  185562. WebBrowserComponent* const owner = dynamic_cast <WebBrowserComponent*> (getParentComponent());
  185563. jassert (owner != 0);
  185564. EventHandler* handler = new EventHandler (owner);
  185565. connectionPoint->Advise (handler, &adviseCookie);
  185566. }
  185567. }
  185568. }
  185569. void goToURL (const String& url,
  185570. const StringArray* headers,
  185571. const MemoryBlock* postData)
  185572. {
  185573. if (browser != 0)
  185574. {
  185575. LPSAFEARRAY sa = 0;
  185576. VARIANT flags, frame, postDataVar, headersVar; // (_variant_t isn't available in all compilers)
  185577. VariantInit (&flags);
  185578. VariantInit (&frame);
  185579. VariantInit (&postDataVar);
  185580. VariantInit (&headersVar);
  185581. if (headers != 0)
  185582. {
  185583. V_VT (&headersVar) = VT_BSTR;
  185584. V_BSTR (&headersVar) = SysAllocString ((const tchar*) headers->joinIntoString ("\r\n"));
  185585. }
  185586. if (postData != 0 && postData->getSize() > 0)
  185587. {
  185588. LPSAFEARRAY sa = SafeArrayCreateVector (VT_UI1, 0, postData->getSize());
  185589. if (sa != 0)
  185590. {
  185591. void* data = 0;
  185592. SafeArrayAccessData (sa, &data);
  185593. jassert (data != 0);
  185594. if (data != 0)
  185595. {
  185596. postData->copyTo (data, 0, postData->getSize());
  185597. SafeArrayUnaccessData (sa);
  185598. VARIANT postDataVar2;
  185599. VariantInit (&postDataVar2);
  185600. V_VT (&postDataVar2) = VT_ARRAY | VT_UI1;
  185601. V_ARRAY (&postDataVar2) = sa;
  185602. postDataVar = postDataVar2;
  185603. }
  185604. }
  185605. }
  185606. browser->Navigate ((BSTR) (const OLECHAR*) url,
  185607. &flags, &frame,
  185608. &postDataVar, &headersVar);
  185609. if (sa != 0)
  185610. SafeArrayDestroy (sa);
  185611. VariantClear (&flags);
  185612. VariantClear (&frame);
  185613. VariantClear (&postDataVar);
  185614. VariantClear (&headersVar);
  185615. }
  185616. }
  185617. IWebBrowser2* browser;
  185618. juce_UseDebuggingNewOperator
  185619. private:
  185620. IConnectionPoint* connectionPoint;
  185621. DWORD adviseCookie;
  185622. class EventHandler : public IDispatch,
  185623. public ComponentMovementWatcher
  185624. {
  185625. public:
  185626. EventHandler (WebBrowserComponent* owner_)
  185627. : ComponentMovementWatcher (owner_),
  185628. owner (owner_),
  185629. refCount (0)
  185630. {
  185631. }
  185632. ~EventHandler()
  185633. {
  185634. }
  185635. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  185636. {
  185637. if (id == IID_IUnknown || id == IID_IDispatch || id == DIID_DWebBrowserEvents2)
  185638. {
  185639. AddRef();
  185640. *result = this;
  185641. return S_OK;
  185642. }
  185643. *result = 0;
  185644. return E_NOINTERFACE;
  185645. }
  185646. ULONG __stdcall AddRef() { return ++refCount; }
  185647. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  185648. HRESULT __stdcall GetTypeInfoCount (UINT __RPC_FAR*) { return E_NOTIMPL; }
  185649. HRESULT __stdcall GetTypeInfo (UINT, LCID, ITypeInfo __RPC_FAR *__RPC_FAR*) { return E_NOTIMPL; }
  185650. HRESULT __stdcall GetIDsOfNames (REFIID, LPOLESTR __RPC_FAR*, UINT, LCID, DISPID __RPC_FAR*) { return E_NOTIMPL; }
  185651. HRESULT __stdcall Invoke (DISPID dispIdMember, REFIID /*riid*/, LCID /*lcid*/,
  185652. WORD /*wFlags*/, DISPPARAMS __RPC_FAR* pDispParams,
  185653. VARIANT __RPC_FAR* /*pVarResult*/, EXCEPINFO __RPC_FAR* /*pExcepInfo*/,
  185654. UINT __RPC_FAR* /*puArgErr*/)
  185655. {
  185656. switch (dispIdMember)
  185657. {
  185658. case DISPID_BEFORENAVIGATE2:
  185659. {
  185660. VARIANT* const vurl = pDispParams->rgvarg[5].pvarVal;
  185661. String url;
  185662. if ((vurl->vt & VT_BYREF) != 0)
  185663. url = *vurl->pbstrVal;
  185664. else
  185665. url = vurl->bstrVal;
  185666. *pDispParams->rgvarg->pboolVal
  185667. = owner->pageAboutToLoad (url) ? VARIANT_FALSE
  185668. : VARIANT_TRUE;
  185669. return S_OK;
  185670. }
  185671. default:
  185672. break;
  185673. }
  185674. return E_NOTIMPL;
  185675. }
  185676. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/) {}
  185677. void componentPeerChanged() {}
  185678. void componentVisibilityChanged (Component&)
  185679. {
  185680. owner->visibilityChanged();
  185681. }
  185682. juce_UseDebuggingNewOperator
  185683. private:
  185684. WebBrowserComponent* const owner;
  185685. int refCount;
  185686. EventHandler (const EventHandler&);
  185687. const EventHandler& operator= (const EventHandler&);
  185688. };
  185689. };
  185690. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  185691. : browser (0),
  185692. blankPageShown (false),
  185693. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  185694. {
  185695. setOpaque (true);
  185696. addAndMakeVisible (browser = new WebBrowserComponentInternal());
  185697. }
  185698. WebBrowserComponent::~WebBrowserComponent()
  185699. {
  185700. delete browser;
  185701. }
  185702. void WebBrowserComponent::goToURL (const String& url,
  185703. const StringArray* headers,
  185704. const MemoryBlock* postData)
  185705. {
  185706. lastURL = url;
  185707. lastHeaders.clear();
  185708. if (headers != 0)
  185709. lastHeaders = *headers;
  185710. lastPostData.setSize (0);
  185711. if (postData != 0)
  185712. lastPostData = *postData;
  185713. blankPageShown = false;
  185714. browser->goToURL (url, headers, postData);
  185715. }
  185716. void WebBrowserComponent::stop()
  185717. {
  185718. if (browser->browser != 0)
  185719. browser->browser->Stop();
  185720. }
  185721. void WebBrowserComponent::goBack()
  185722. {
  185723. lastURL = String::empty;
  185724. blankPageShown = false;
  185725. if (browser->browser != 0)
  185726. browser->browser->GoBack();
  185727. }
  185728. void WebBrowserComponent::goForward()
  185729. {
  185730. lastURL = String::empty;
  185731. if (browser->browser != 0)
  185732. browser->browser->GoForward();
  185733. }
  185734. void WebBrowserComponent::refresh()
  185735. {
  185736. if (browser->browser != 0)
  185737. browser->browser->Refresh();
  185738. }
  185739. void WebBrowserComponent::paint (Graphics& g)
  185740. {
  185741. if (browser->browser == 0)
  185742. g.fillAll (Colours::white);
  185743. }
  185744. void WebBrowserComponent::checkWindowAssociation()
  185745. {
  185746. if (isShowing())
  185747. {
  185748. if (browser->browser == 0 && getPeer() != 0)
  185749. {
  185750. browser->createBrowser();
  185751. reloadLastURL();
  185752. }
  185753. else
  185754. {
  185755. if (blankPageShown)
  185756. goBack();
  185757. }
  185758. }
  185759. else
  185760. {
  185761. if (browser != 0 && unloadPageWhenBrowserIsHidden && ! blankPageShown)
  185762. {
  185763. // when the component becomes invisible, some stuff like flash
  185764. // carries on playing audio, so we need to force it onto a blank
  185765. // page to avoid this..
  185766. blankPageShown = true;
  185767. browser->goToURL ("about:blank", 0, 0);
  185768. }
  185769. }
  185770. }
  185771. void WebBrowserComponent::reloadLastURL()
  185772. {
  185773. if (lastURL.isNotEmpty())
  185774. {
  185775. goToURL (lastURL, &lastHeaders, &lastPostData);
  185776. lastURL = String::empty;
  185777. }
  185778. }
  185779. void WebBrowserComponent::parentHierarchyChanged()
  185780. {
  185781. checkWindowAssociation();
  185782. }
  185783. void WebBrowserComponent::resized()
  185784. {
  185785. browser->setSize (getWidth(), getHeight());
  185786. }
  185787. void WebBrowserComponent::visibilityChanged()
  185788. {
  185789. checkWindowAssociation();
  185790. }
  185791. bool WebBrowserComponent::pageAboutToLoad (const String&)
  185792. {
  185793. return true;
  185794. }
  185795. #endif
  185796. /*** End of inlined file: juce_win32_WebBrowserComponent.cpp ***/
  185797. /*** Start of inlined file: juce_win32_OpenGLComponent.cpp ***/
  185798. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  185799. // compiled on its own).
  185800. #if JUCE_INCLUDED_FILE && JUCE_OPENGL
  185801. #define WGL_EXT_FUNCTION_INIT(extType, extFunc) \
  185802. ((extFunc = (extType) wglGetProcAddress (#extFunc)) != 0)
  185803. typedef const char* (WINAPI* PFNWGLGETEXTENSIONSSTRINGARBPROC) (HDC hdc);
  185804. typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBIVARBPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues);
  185805. typedef BOOL (WINAPI * PFNWGLCHOOSEPIXELFORMATARBPROC) (HDC hdc, const int* piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats);
  185806. typedef BOOL (WINAPI * PFNWGLSWAPINTERVALEXTPROC) (int interval);
  185807. typedef int (WINAPI * PFNWGLGETSWAPINTERVALEXTPROC) (void);
  185808. #define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000
  185809. #define WGL_DRAW_TO_WINDOW_ARB 0x2001
  185810. #define WGL_ACCELERATION_ARB 0x2003
  185811. #define WGL_SWAP_METHOD_ARB 0x2007
  185812. #define WGL_SUPPORT_OPENGL_ARB 0x2010
  185813. #define WGL_PIXEL_TYPE_ARB 0x2013
  185814. #define WGL_DOUBLE_BUFFER_ARB 0x2011
  185815. #define WGL_COLOR_BITS_ARB 0x2014
  185816. #define WGL_RED_BITS_ARB 0x2015
  185817. #define WGL_GREEN_BITS_ARB 0x2017
  185818. #define WGL_BLUE_BITS_ARB 0x2019
  185819. #define WGL_ALPHA_BITS_ARB 0x201B
  185820. #define WGL_DEPTH_BITS_ARB 0x2022
  185821. #define WGL_STENCIL_BITS_ARB 0x2023
  185822. #define WGL_FULL_ACCELERATION_ARB 0x2027
  185823. #define WGL_ACCUM_RED_BITS_ARB 0x201E
  185824. #define WGL_ACCUM_GREEN_BITS_ARB 0x201F
  185825. #define WGL_ACCUM_BLUE_BITS_ARB 0x2020
  185826. #define WGL_ACCUM_ALPHA_BITS_ARB 0x2021
  185827. #define WGL_STEREO_ARB 0x2012
  185828. #define WGL_SAMPLE_BUFFERS_ARB 0x2041
  185829. #define WGL_SAMPLES_ARB 0x2042
  185830. #define WGL_TYPE_RGBA_ARB 0x202B
  185831. static void getWglExtensions (HDC dc, StringArray& result) throw()
  185832. {
  185833. PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB = 0;
  185834. if (WGL_EXT_FUNCTION_INIT (PFNWGLGETEXTENSIONSSTRINGARBPROC, wglGetExtensionsStringARB))
  185835. result.addTokens (String (wglGetExtensionsStringARB (dc)), false);
  185836. else
  185837. jassertfalse // If this fails, it may be because you didn't activate the openGL context
  185838. }
  185839. class WindowedGLContext : public OpenGLContext
  185840. {
  185841. public:
  185842. WindowedGLContext (Component* const component_,
  185843. HGLRC contextToShareWith,
  185844. const OpenGLPixelFormat& pixelFormat)
  185845. : renderContext (0),
  185846. nativeWindow (0),
  185847. dc (0),
  185848. component (component_)
  185849. {
  185850. jassert (component != 0);
  185851. createNativeWindow();
  185852. // Use a default pixel format that should be supported everywhere
  185853. PIXELFORMATDESCRIPTOR pfd;
  185854. zerostruct (pfd);
  185855. pfd.nSize = sizeof (pfd);
  185856. pfd.nVersion = 1;
  185857. pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
  185858. pfd.iPixelType = PFD_TYPE_RGBA;
  185859. pfd.cColorBits = 24;
  185860. pfd.cDepthBits = 16;
  185861. const int format = ChoosePixelFormat (dc, &pfd);
  185862. if (format != 0)
  185863. SetPixelFormat (dc, format, &pfd);
  185864. renderContext = wglCreateContext (dc);
  185865. makeActive();
  185866. setPixelFormat (pixelFormat);
  185867. if (contextToShareWith != 0 && renderContext != 0)
  185868. wglShareLists (contextToShareWith, renderContext);
  185869. }
  185870. ~WindowedGLContext()
  185871. {
  185872. makeInactive();
  185873. wglDeleteContext (renderContext);
  185874. ReleaseDC ((HWND) nativeWindow->getNativeHandle(), dc);
  185875. delete nativeWindow;
  185876. }
  185877. bool makeActive() const throw()
  185878. {
  185879. jassert (renderContext != 0);
  185880. return wglMakeCurrent (dc, renderContext) != 0;
  185881. }
  185882. bool makeInactive() const throw()
  185883. {
  185884. return (! isActive()) || (wglMakeCurrent (0, 0) != 0);
  185885. }
  185886. bool isActive() const throw()
  185887. {
  185888. return wglGetCurrentContext() == renderContext;
  185889. }
  185890. const OpenGLPixelFormat getPixelFormat() const
  185891. {
  185892. OpenGLPixelFormat pf;
  185893. makeActive();
  185894. StringArray availableExtensions;
  185895. getWglExtensions (dc, availableExtensions);
  185896. fillInPixelFormatDetails (GetPixelFormat (dc), pf, availableExtensions);
  185897. return pf;
  185898. }
  185899. void* getRawContext() const throw()
  185900. {
  185901. return renderContext;
  185902. }
  185903. bool setPixelFormat (const OpenGLPixelFormat& pixelFormat)
  185904. {
  185905. makeActive();
  185906. PIXELFORMATDESCRIPTOR pfd;
  185907. zerostruct (pfd);
  185908. pfd.nSize = sizeof (pfd);
  185909. pfd.nVersion = 1;
  185910. pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER;
  185911. pfd.iPixelType = PFD_TYPE_RGBA;
  185912. pfd.iLayerType = PFD_MAIN_PLANE;
  185913. pfd.cColorBits = (BYTE) (pixelFormat.redBits + pixelFormat.greenBits + pixelFormat.blueBits);
  185914. pfd.cRedBits = (BYTE) pixelFormat.redBits;
  185915. pfd.cGreenBits = (BYTE) pixelFormat.greenBits;
  185916. pfd.cBlueBits = (BYTE) pixelFormat.blueBits;
  185917. pfd.cAlphaBits = (BYTE) pixelFormat.alphaBits;
  185918. pfd.cDepthBits = (BYTE) pixelFormat.depthBufferBits;
  185919. pfd.cStencilBits = (BYTE) pixelFormat.stencilBufferBits;
  185920. pfd.cAccumBits = (BYTE) (pixelFormat.accumulationBufferRedBits + pixelFormat.accumulationBufferGreenBits
  185921. + pixelFormat.accumulationBufferBlueBits + pixelFormat.accumulationBufferAlphaBits);
  185922. pfd.cAccumRedBits = (BYTE) pixelFormat.accumulationBufferRedBits;
  185923. pfd.cAccumGreenBits = (BYTE) pixelFormat.accumulationBufferGreenBits;
  185924. pfd.cAccumBlueBits = (BYTE) pixelFormat.accumulationBufferBlueBits;
  185925. pfd.cAccumAlphaBits = (BYTE) pixelFormat.accumulationBufferAlphaBits;
  185926. int format = 0;
  185927. PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB = 0;
  185928. StringArray availableExtensions;
  185929. getWglExtensions (dc, availableExtensions);
  185930. if (availableExtensions.contains ("WGL_ARB_pixel_format")
  185931. && WGL_EXT_FUNCTION_INIT (PFNWGLCHOOSEPIXELFORMATARBPROC, wglChoosePixelFormatARB))
  185932. {
  185933. int attributes[64];
  185934. int n = 0;
  185935. attributes[n++] = WGL_DRAW_TO_WINDOW_ARB;
  185936. attributes[n++] = GL_TRUE;
  185937. attributes[n++] = WGL_SUPPORT_OPENGL_ARB;
  185938. attributes[n++] = GL_TRUE;
  185939. attributes[n++] = WGL_ACCELERATION_ARB;
  185940. attributes[n++] = WGL_FULL_ACCELERATION_ARB;
  185941. attributes[n++] = WGL_DOUBLE_BUFFER_ARB;
  185942. attributes[n++] = GL_TRUE;
  185943. attributes[n++] = WGL_PIXEL_TYPE_ARB;
  185944. attributes[n++] = WGL_TYPE_RGBA_ARB;
  185945. attributes[n++] = WGL_COLOR_BITS_ARB;
  185946. attributes[n++] = pfd.cColorBits;
  185947. attributes[n++] = WGL_RED_BITS_ARB;
  185948. attributes[n++] = pixelFormat.redBits;
  185949. attributes[n++] = WGL_GREEN_BITS_ARB;
  185950. attributes[n++] = pixelFormat.greenBits;
  185951. attributes[n++] = WGL_BLUE_BITS_ARB;
  185952. attributes[n++] = pixelFormat.blueBits;
  185953. attributes[n++] = WGL_ALPHA_BITS_ARB;
  185954. attributes[n++] = pixelFormat.alphaBits;
  185955. attributes[n++] = WGL_DEPTH_BITS_ARB;
  185956. attributes[n++] = pixelFormat.depthBufferBits;
  185957. if (pixelFormat.stencilBufferBits > 0)
  185958. {
  185959. attributes[n++] = WGL_STENCIL_BITS_ARB;
  185960. attributes[n++] = pixelFormat.stencilBufferBits;
  185961. }
  185962. attributes[n++] = WGL_ACCUM_RED_BITS_ARB;
  185963. attributes[n++] = pixelFormat.accumulationBufferRedBits;
  185964. attributes[n++] = WGL_ACCUM_GREEN_BITS_ARB;
  185965. attributes[n++] = pixelFormat.accumulationBufferGreenBits;
  185966. attributes[n++] = WGL_ACCUM_BLUE_BITS_ARB;
  185967. attributes[n++] = pixelFormat.accumulationBufferBlueBits;
  185968. attributes[n++] = WGL_ACCUM_ALPHA_BITS_ARB;
  185969. attributes[n++] = pixelFormat.accumulationBufferAlphaBits;
  185970. if (availableExtensions.contains ("WGL_ARB_multisample")
  185971. && pixelFormat.fullSceneAntiAliasingNumSamples > 0)
  185972. {
  185973. attributes[n++] = WGL_SAMPLE_BUFFERS_ARB;
  185974. attributes[n++] = 1;
  185975. attributes[n++] = WGL_SAMPLES_ARB;
  185976. attributes[n++] = pixelFormat.fullSceneAntiAliasingNumSamples;
  185977. }
  185978. attributes[n++] = 0;
  185979. UINT formatsCount;
  185980. const BOOL ok = wglChoosePixelFormatARB (dc, attributes, 0, 1, &format, &formatsCount);
  185981. (void) ok;
  185982. jassert (ok);
  185983. }
  185984. else
  185985. {
  185986. format = ChoosePixelFormat (dc, &pfd);
  185987. }
  185988. if (format != 0)
  185989. {
  185990. makeInactive();
  185991. // win32 can't change the pixel format of a window, so need to delete the
  185992. // old one and create a new one..
  185993. jassert (nativeWindow != 0);
  185994. ReleaseDC ((HWND) nativeWindow->getNativeHandle(), dc);
  185995. delete nativeWindow;
  185996. createNativeWindow();
  185997. if (SetPixelFormat (dc, format, &pfd))
  185998. {
  185999. wglDeleteContext (renderContext);
  186000. renderContext = wglCreateContext (dc);
  186001. jassert (renderContext != 0);
  186002. return renderContext != 0;
  186003. }
  186004. }
  186005. return false;
  186006. }
  186007. void updateWindowPosition (int x, int y, int w, int h, int)
  186008. {
  186009. SetWindowPos ((HWND) nativeWindow->getNativeHandle(), 0,
  186010. x, y, w, h,
  186011. SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  186012. }
  186013. void repaint()
  186014. {
  186015. int x, y, w, h;
  186016. nativeWindow->getBounds (x, y, w, h);
  186017. nativeWindow->repaint (0, 0, w, h);
  186018. }
  186019. void swapBuffers()
  186020. {
  186021. SwapBuffers (dc);
  186022. }
  186023. bool setSwapInterval (const int numFramesPerSwap)
  186024. {
  186025. makeActive();
  186026. StringArray availableExtensions;
  186027. getWglExtensions (dc, availableExtensions);
  186028. PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = 0;
  186029. return availableExtensions.contains ("WGL_EXT_swap_control")
  186030. && WGL_EXT_FUNCTION_INIT (PFNWGLSWAPINTERVALEXTPROC, wglSwapIntervalEXT)
  186031. && wglSwapIntervalEXT (numFramesPerSwap) != FALSE;
  186032. }
  186033. int getSwapInterval() const
  186034. {
  186035. makeActive();
  186036. StringArray availableExtensions;
  186037. getWglExtensions (dc, availableExtensions);
  186038. PFNWGLGETSWAPINTERVALEXTPROC wglGetSwapIntervalEXT = 0;
  186039. if (availableExtensions.contains ("WGL_EXT_swap_control")
  186040. && WGL_EXT_FUNCTION_INIT (PFNWGLGETSWAPINTERVALEXTPROC, wglGetSwapIntervalEXT))
  186041. return wglGetSwapIntervalEXT();
  186042. return 0;
  186043. }
  186044. void findAlternativeOpenGLPixelFormats (OwnedArray <OpenGLPixelFormat>& results)
  186045. {
  186046. jassert (isActive());
  186047. StringArray availableExtensions;
  186048. getWglExtensions (dc, availableExtensions);
  186049. PFNWGLGETPIXELFORMATATTRIBIVARBPROC wglGetPixelFormatAttribivARB = 0;
  186050. int numTypes = 0;
  186051. if (availableExtensions.contains("WGL_ARB_pixel_format")
  186052. && WGL_EXT_FUNCTION_INIT (PFNWGLGETPIXELFORMATATTRIBIVARBPROC, wglGetPixelFormatAttribivARB))
  186053. {
  186054. int attributes = WGL_NUMBER_PIXEL_FORMATS_ARB;
  186055. if (! wglGetPixelFormatAttribivARB (dc, 1, 0, 1, &attributes, &numTypes))
  186056. jassertfalse
  186057. }
  186058. else
  186059. {
  186060. numTypes = DescribePixelFormat (dc, 0, 0, 0);
  186061. }
  186062. OpenGLPixelFormat pf;
  186063. for (int i = 0; i < numTypes; ++i)
  186064. {
  186065. if (fillInPixelFormatDetails (i + 1, pf, availableExtensions))
  186066. {
  186067. bool alreadyListed = false;
  186068. for (int j = results.size(); --j >= 0;)
  186069. if (pf == *results.getUnchecked(j))
  186070. alreadyListed = true;
  186071. if (! alreadyListed)
  186072. results.add (new OpenGLPixelFormat (pf));
  186073. }
  186074. }
  186075. }
  186076. void* getNativeWindowHandle() const
  186077. {
  186078. return nativeWindow != 0 ? nativeWindow->getNativeHandle() : 0;
  186079. }
  186080. juce_UseDebuggingNewOperator
  186081. HGLRC renderContext;
  186082. private:
  186083. Win32ComponentPeer* nativeWindow;
  186084. Component* const component;
  186085. HDC dc;
  186086. void createNativeWindow()
  186087. {
  186088. nativeWindow = new Win32ComponentPeer (component, 0);
  186089. nativeWindow->dontRepaint = true;
  186090. nativeWindow->setVisible (true);
  186091. HWND hwnd = (HWND) nativeWindow->getNativeHandle();
  186092. Win32ComponentPeer* const peer = dynamic_cast <Win32ComponentPeer*> (component->getTopLevelComponent()->getPeer());
  186093. if (peer != 0)
  186094. {
  186095. SetParent (hwnd, (HWND) peer->getNativeHandle());
  186096. juce_setWindowStyleBit (hwnd, GWL_STYLE, WS_CHILD, true);
  186097. juce_setWindowStyleBit (hwnd, GWL_STYLE, WS_POPUP, false);
  186098. }
  186099. dc = GetDC (hwnd);
  186100. }
  186101. bool fillInPixelFormatDetails (const int pixelFormatIndex,
  186102. OpenGLPixelFormat& result,
  186103. const StringArray& availableExtensions) const throw()
  186104. {
  186105. PFNWGLGETPIXELFORMATATTRIBIVARBPROC wglGetPixelFormatAttribivARB = 0;
  186106. if (availableExtensions.contains ("WGL_ARB_pixel_format")
  186107. && WGL_EXT_FUNCTION_INIT (PFNWGLGETPIXELFORMATATTRIBIVARBPROC, wglGetPixelFormatAttribivARB))
  186108. {
  186109. int attributes[32];
  186110. int numAttributes = 0;
  186111. attributes[numAttributes++] = WGL_DRAW_TO_WINDOW_ARB;
  186112. attributes[numAttributes++] = WGL_SUPPORT_OPENGL_ARB;
  186113. attributes[numAttributes++] = WGL_ACCELERATION_ARB;
  186114. attributes[numAttributes++] = WGL_DOUBLE_BUFFER_ARB;
  186115. attributes[numAttributes++] = WGL_PIXEL_TYPE_ARB;
  186116. attributes[numAttributes++] = WGL_RED_BITS_ARB;
  186117. attributes[numAttributes++] = WGL_GREEN_BITS_ARB;
  186118. attributes[numAttributes++] = WGL_BLUE_BITS_ARB;
  186119. attributes[numAttributes++] = WGL_ALPHA_BITS_ARB;
  186120. attributes[numAttributes++] = WGL_DEPTH_BITS_ARB;
  186121. attributes[numAttributes++] = WGL_STENCIL_BITS_ARB;
  186122. attributes[numAttributes++] = WGL_ACCUM_RED_BITS_ARB;
  186123. attributes[numAttributes++] = WGL_ACCUM_GREEN_BITS_ARB;
  186124. attributes[numAttributes++] = WGL_ACCUM_BLUE_BITS_ARB;
  186125. attributes[numAttributes++] = WGL_ACCUM_ALPHA_BITS_ARB;
  186126. if (availableExtensions.contains ("WGL_ARB_multisample"))
  186127. attributes[numAttributes++] = WGL_SAMPLES_ARB;
  186128. int values[32];
  186129. zeromem (values, sizeof (values));
  186130. if (wglGetPixelFormatAttribivARB (dc, pixelFormatIndex, 0, numAttributes, attributes, values))
  186131. {
  186132. int n = 0;
  186133. bool isValidFormat = (values[n++] == GL_TRUE); // WGL_DRAW_TO_WINDOW_ARB
  186134. isValidFormat = (values[n++] == GL_TRUE) && isValidFormat; // WGL_SUPPORT_OPENGL_ARB
  186135. isValidFormat = (values[n++] == WGL_FULL_ACCELERATION_ARB) && isValidFormat; // WGL_ACCELERATION_ARB
  186136. isValidFormat = (values[n++] == GL_TRUE) && isValidFormat; // WGL_DOUBLE_BUFFER_ARB:
  186137. isValidFormat = (values[n++] == WGL_TYPE_RGBA_ARB) && isValidFormat; // WGL_PIXEL_TYPE_ARB
  186138. result.redBits = values[n++]; // WGL_RED_BITS_ARB
  186139. result.greenBits = values[n++]; // WGL_GREEN_BITS_ARB
  186140. result.blueBits = values[n++]; // WGL_BLUE_BITS_ARB
  186141. result.alphaBits = values[n++]; // WGL_ALPHA_BITS_ARB
  186142. result.depthBufferBits = values[n++]; // WGL_DEPTH_BITS_ARB
  186143. result.stencilBufferBits = values[n++]; // WGL_STENCIL_BITS_ARB
  186144. result.accumulationBufferRedBits = values[n++]; // WGL_ACCUM_RED_BITS_ARB
  186145. result.accumulationBufferGreenBits = values[n++]; // WGL_ACCUM_GREEN_BITS_ARB
  186146. result.accumulationBufferBlueBits = values[n++]; // WGL_ACCUM_BLUE_BITS_ARB
  186147. result.accumulationBufferAlphaBits = values[n++]; // WGL_ACCUM_ALPHA_BITS_ARB
  186148. result.fullSceneAntiAliasingNumSamples = (uint8) values[n++]; // WGL_SAMPLES_ARB
  186149. return isValidFormat;
  186150. }
  186151. else
  186152. {
  186153. jassertfalse
  186154. }
  186155. }
  186156. else
  186157. {
  186158. PIXELFORMATDESCRIPTOR pfd;
  186159. if (DescribePixelFormat (dc, pixelFormatIndex, sizeof (pfd), &pfd))
  186160. {
  186161. result.redBits = pfd.cRedBits;
  186162. result.greenBits = pfd.cGreenBits;
  186163. result.blueBits = pfd.cBlueBits;
  186164. result.alphaBits = pfd.cAlphaBits;
  186165. result.depthBufferBits = pfd.cDepthBits;
  186166. result.stencilBufferBits = pfd.cStencilBits;
  186167. result.accumulationBufferRedBits = pfd.cAccumRedBits;
  186168. result.accumulationBufferGreenBits = pfd.cAccumGreenBits;
  186169. result.accumulationBufferBlueBits = pfd.cAccumBlueBits;
  186170. result.accumulationBufferAlphaBits = pfd.cAccumAlphaBits;
  186171. result.fullSceneAntiAliasingNumSamples = 0;
  186172. return true;
  186173. }
  186174. else
  186175. {
  186176. jassertfalse
  186177. }
  186178. }
  186179. return false;
  186180. }
  186181. WindowedGLContext (const WindowedGLContext&);
  186182. const WindowedGLContext& operator= (const WindowedGLContext&);
  186183. };
  186184. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  186185. const OpenGLPixelFormat& pixelFormat,
  186186. const OpenGLContext* const contextToShareWith)
  186187. {
  186188. WindowedGLContext* c = new WindowedGLContext (component,
  186189. contextToShareWith != 0 ? (HGLRC) contextToShareWith->getRawContext() : 0,
  186190. pixelFormat);
  186191. if (c->renderContext == 0)
  186192. deleteAndZero (c);
  186193. return c;
  186194. }
  186195. void* OpenGLComponent::getNativeWindowHandle() const
  186196. {
  186197. return context != 0 ? ((WindowedGLContext*) context)->getNativeWindowHandle() : 0;
  186198. }
  186199. void juce_glViewport (const int w, const int h)
  186200. {
  186201. glViewport (0, 0, w, h);
  186202. }
  186203. void OpenGLPixelFormat::getAvailablePixelFormats (Component* component,
  186204. OwnedArray <OpenGLPixelFormat>& results)
  186205. {
  186206. Component tempComp;
  186207. {
  186208. WindowedGLContext wc (component, 0, OpenGLPixelFormat (8, 8, 16, 0));
  186209. wc.makeActive();
  186210. wc.findAlternativeOpenGLPixelFormats (results);
  186211. }
  186212. }
  186213. #endif
  186214. /*** End of inlined file: juce_win32_OpenGLComponent.cpp ***/
  186215. /*** Start of inlined file: juce_win32_AudioCDReader.cpp ***/
  186216. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  186217. // compiled on its own).
  186218. #if JUCE_INCLUDED_FILE
  186219. #if JUCE_USE_CDREADER
  186220. //***************************************************************************
  186221. // %%% TARGET STATUS VALUES %%%
  186222. //***************************************************************************
  186223. #define STATUS_GOOD 0x00 // Status Good
  186224. #define STATUS_CHKCOND 0x02 // Check Condition
  186225. #define STATUS_CONDMET 0x04 // Condition Met
  186226. #define STATUS_BUSY 0x08 // Busy
  186227. #define STATUS_INTERM 0x10 // Intermediate
  186228. #define STATUS_INTCDMET 0x14 // Intermediate-condition met
  186229. #define STATUS_RESCONF 0x18 // Reservation conflict
  186230. #define STATUS_COMTERM 0x22 // Command Terminated
  186231. #define STATUS_QFULL 0x28 // Queue full
  186232. //***************************************************************************
  186233. // %%% SCSI MISCELLANEOUS EQUATES %%%
  186234. //***************************************************************************
  186235. #define MAXLUN 7 // Maximum Logical Unit Id
  186236. #define MAXTARG 7 // Maximum Target Id
  186237. #define MAX_SCSI_LUNS 64 // Maximum Number of SCSI LUNs
  186238. #define MAX_NUM_HA 8 // Maximum Number of SCSI HA's
  186239. //***************************************************************************
  186240. // %%% Commands for all Device Types %%%
  186241. //***************************************************************************
  186242. #define SCSI_CHANGE_DEF 0x40 // Change Definition (Optional)
  186243. #define SCSI_COMPARE 0x39 // Compare (O)
  186244. #define SCSI_COPY 0x18 // Copy (O)
  186245. #define SCSI_COP_VERIFY 0x3A // Copy and Verify (O)
  186246. #define SCSI_INQUIRY 0x12 // Inquiry (MANDATORY)
  186247. #define SCSI_LOG_SELECT 0x4C // Log Select (O)
  186248. #define SCSI_LOG_SENSE 0x4D // Log Sense (O)
  186249. #define SCSI_MODE_SEL6 0x15 // Mode Select 6-byte (Device Specific)
  186250. #define SCSI_MODE_SEL10 0x55 // Mode Select 10-byte (Device Specific)
  186251. #define SCSI_MODE_SEN6 0x1A // Mode Sense 6-byte (Device Specific)
  186252. #define SCSI_MODE_SEN10 0x5A // Mode Sense 10-byte (Device Specific)
  186253. #define SCSI_READ_BUFF 0x3C // Read Buffer (O)
  186254. #define SCSI_REQ_SENSE 0x03 // Request Sense (MANDATORY)
  186255. #define SCSI_SEND_DIAG 0x1D // Send Diagnostic (O)
  186256. #define SCSI_TST_U_RDY 0x00 // Test Unit Ready (MANDATORY)
  186257. #define SCSI_WRITE_BUFF 0x3B // Write Buffer (O)
  186258. //***************************************************************************
  186259. // %%% Commands Unique to Direct Access Devices %%%
  186260. //***************************************************************************
  186261. #define SCSI_COMPARE 0x39 // Compare (O)
  186262. #define SCSI_FORMAT 0x04 // Format Unit (MANDATORY)
  186263. #define SCSI_LCK_UN_CAC 0x36 // Lock Unlock Cache (O)
  186264. #define SCSI_PREFETCH 0x34 // Prefetch (O)
  186265. #define SCSI_MED_REMOVL 0x1E // Prevent/Allow medium Removal (O)
  186266. #define SCSI_READ6 0x08 // Read 6-byte (MANDATORY)
  186267. #define SCSI_READ10 0x28 // Read 10-byte (MANDATORY)
  186268. #define SCSI_RD_CAPAC 0x25 // Read Capacity (MANDATORY)
  186269. #define SCSI_RD_DEFECT 0x37 // Read Defect Data (O)
  186270. #define SCSI_READ_LONG 0x3E // Read Long (O)
  186271. #define SCSI_REASS_BLK 0x07 // Reassign Blocks (O)
  186272. #define SCSI_RCV_DIAG 0x1C // Receive Diagnostic Results (O)
  186273. #define SCSI_RELEASE 0x17 // Release Unit (MANDATORY)
  186274. #define SCSI_REZERO 0x01 // Rezero Unit (O)
  186275. #define SCSI_SRCH_DAT_E 0x31 // Search Data Equal (O)
  186276. #define SCSI_SRCH_DAT_H 0x30 // Search Data High (O)
  186277. #define SCSI_SRCH_DAT_L 0x32 // Search Data Low (O)
  186278. #define SCSI_SEEK6 0x0B // Seek 6-Byte (O)
  186279. #define SCSI_SEEK10 0x2B // Seek 10-Byte (O)
  186280. #define SCSI_SEND_DIAG 0x1D // Send Diagnostics (MANDATORY)
  186281. #define SCSI_SET_LIMIT 0x33 // Set Limits (O)
  186282. #define SCSI_START_STP 0x1B // Start/Stop Unit (O)
  186283. #define SCSI_SYNC_CACHE 0x35 // Synchronize Cache (O)
  186284. #define SCSI_VERIFY 0x2F // Verify (O)
  186285. #define SCSI_WRITE6 0x0A // Write 6-Byte (MANDATORY)
  186286. #define SCSI_WRITE10 0x2A // Write 10-Byte (MANDATORY)
  186287. #define SCSI_WRT_VERIFY 0x2E // Write and Verify (O)
  186288. #define SCSI_WRITE_LONG 0x3F // Write Long (O)
  186289. #define SCSI_WRITE_SAME 0x41 // Write Same (O)
  186290. //***************************************************************************
  186291. // %%% Commands Unique to Sequential Access Devices %%%
  186292. //***************************************************************************
  186293. #define SCSI_ERASE 0x19 // Erase (MANDATORY)
  186294. #define SCSI_LOAD_UN 0x1b // Load/Unload (O)
  186295. #define SCSI_LOCATE 0x2B // Locate (O)
  186296. #define SCSI_RD_BLK_LIM 0x05 // Read Block Limits (MANDATORY)
  186297. #define SCSI_READ_POS 0x34 // Read Position (O)
  186298. #define SCSI_READ_REV 0x0F // Read Reverse (O)
  186299. #define SCSI_REC_BF_DAT 0x14 // Recover Buffer Data (O)
  186300. #define SCSI_RESERVE 0x16 // Reserve Unit (MANDATORY)
  186301. #define SCSI_REWIND 0x01 // Rewind (MANDATORY)
  186302. #define SCSI_SPACE 0x11 // Space (MANDATORY)
  186303. #define SCSI_VERIFY_T 0x13 // Verify (Tape) (O)
  186304. #define SCSI_WRT_FILE 0x10 // Write Filemarks (MANDATORY)
  186305. //***************************************************************************
  186306. // %%% Commands Unique to Printer Devices %%%
  186307. //***************************************************************************
  186308. #define SCSI_PRINT 0x0A // Print (MANDATORY)
  186309. #define SCSI_SLEW_PNT 0x0B // Slew and Print (O)
  186310. #define SCSI_STOP_PNT 0x1B // Stop Print (O)
  186311. #define SCSI_SYNC_BUFF 0x10 // Synchronize Buffer (O)
  186312. //***************************************************************************
  186313. // %%% Commands Unique to Processor Devices %%%
  186314. //***************************************************************************
  186315. #define SCSI_RECEIVE 0x08 // Receive (O)
  186316. #define SCSI_SEND 0x0A // Send (O)
  186317. //***************************************************************************
  186318. // %%% Commands Unique to Write-Once Devices %%%
  186319. //***************************************************************************
  186320. #define SCSI_MEDIUM_SCN 0x38 // Medium Scan (O)
  186321. #define SCSI_SRCHDATE10 0x31 // Search Data Equal 10-Byte (O)
  186322. #define SCSI_SRCHDATE12 0xB1 // Search Data Equal 12-Byte (O)
  186323. #define SCSI_SRCHDATH10 0x30 // Search Data High 10-Byte (O)
  186324. #define SCSI_SRCHDATH12 0xB0 // Search Data High 12-Byte (O)
  186325. #define SCSI_SRCHDATL10 0x32 // Search Data Low 10-Byte (O)
  186326. #define SCSI_SRCHDATL12 0xB2 // Search Data Low 12-Byte (O)
  186327. #define SCSI_SET_LIM_10 0x33 // Set Limits 10-Byte (O)
  186328. #define SCSI_SET_LIM_12 0xB3 // Set Limits 10-Byte (O)
  186329. #define SCSI_VERIFY10 0x2F // Verify 10-Byte (O)
  186330. #define SCSI_VERIFY12 0xAF // Verify 12-Byte (O)
  186331. #define SCSI_WRITE12 0xAA // Write 12-Byte (O)
  186332. #define SCSI_WRT_VER10 0x2E // Write and Verify 10-Byte (O)
  186333. #define SCSI_WRT_VER12 0xAE // Write and Verify 12-Byte (O)
  186334. //***************************************************************************
  186335. // %%% Commands Unique to CD-ROM Devices %%%
  186336. //***************************************************************************
  186337. #define SCSI_PLAYAUD_10 0x45 // Play Audio 10-Byte (O)
  186338. #define SCSI_PLAYAUD_12 0xA5 // Play Audio 12-Byte 12-Byte (O)
  186339. #define SCSI_PLAYAUDMSF 0x47 // Play Audio MSF (O)
  186340. #define SCSI_PLAYA_TKIN 0x48 // Play Audio Track/Index (O)
  186341. #define SCSI_PLYTKREL10 0x49 // Play Track Relative 10-Byte (O)
  186342. #define SCSI_PLYTKREL12 0xA9 // Play Track Relative 12-Byte (O)
  186343. #define SCSI_READCDCAP 0x25 // Read CD-ROM Capacity (MANDATORY)
  186344. #define SCSI_READHEADER 0x44 // Read Header (O)
  186345. #define SCSI_SUBCHANNEL 0x42 // Read Subchannel (O)
  186346. #define SCSI_READ_TOC 0x43 // Read TOC (O)
  186347. //***************************************************************************
  186348. // %%% Commands Unique to Scanner Devices %%%
  186349. //***************************************************************************
  186350. #define SCSI_GETDBSTAT 0x34 // Get Data Buffer Status (O)
  186351. #define SCSI_GETWINDOW 0x25 // Get Window (O)
  186352. #define SCSI_OBJECTPOS 0x31 // Object Postion (O)
  186353. #define SCSI_SCAN 0x1B // Scan (O)
  186354. #define SCSI_SETWINDOW 0x24 // Set Window (MANDATORY)
  186355. //***************************************************************************
  186356. // %%% Commands Unique to Optical Memory Devices %%%
  186357. //***************************************************************************
  186358. #define SCSI_UpdateBlk 0x3D // Update Block (O)
  186359. //***************************************************************************
  186360. // %%% Commands Unique to Medium Changer Devices %%%
  186361. //***************************************************************************
  186362. #define SCSI_EXCHMEDIUM 0xA6 // Exchange Medium (O)
  186363. #define SCSI_INITELSTAT 0x07 // Initialize Element Status (O)
  186364. #define SCSI_POSTOELEM 0x2B // Position to Element (O)
  186365. #define SCSI_REQ_VE_ADD 0xB5 // Request Volume Element Address (O)
  186366. #define SCSI_SENDVOLTAG 0xB6 // Send Volume Tag (O)
  186367. //***************************************************************************
  186368. // %%% Commands Unique to Communication Devices %%%
  186369. //***************************************************************************
  186370. #define SCSI_GET_MSG_6 0x08 // Get Message 6-Byte (MANDATORY)
  186371. #define SCSI_GET_MSG_10 0x28 // Get Message 10-Byte (O)
  186372. #define SCSI_GET_MSG_12 0xA8 // Get Message 12-Byte (O)
  186373. #define SCSI_SND_MSG_6 0x0A // Send Message 6-Byte (MANDATORY)
  186374. #define SCSI_SND_MSG_10 0x2A // Send Message 10-Byte (O)
  186375. #define SCSI_SND_MSG_12 0xAA // Send Message 12-Byte (O)
  186376. //***************************************************************************
  186377. // %%% Request Sense Data Format %%%
  186378. //***************************************************************************
  186379. typedef struct {
  186380. BYTE ErrorCode; // Error Code (70H or 71H)
  186381. BYTE SegmentNum; // Number of current segment descriptor
  186382. BYTE SenseKey; // Sense Key(See bit definitions too)
  186383. BYTE InfoByte0; // Information MSB
  186384. BYTE InfoByte1; // Information MID
  186385. BYTE InfoByte2; // Information MID
  186386. BYTE InfoByte3; // Information LSB
  186387. BYTE AddSenLen; // Additional Sense Length
  186388. BYTE ComSpecInf0; // Command Specific Information MSB
  186389. BYTE ComSpecInf1; // Command Specific Information MID
  186390. BYTE ComSpecInf2; // Command Specific Information MID
  186391. BYTE ComSpecInf3; // Command Specific Information LSB
  186392. BYTE AddSenseCode; // Additional Sense Code
  186393. BYTE AddSenQual; // Additional Sense Code Qualifier
  186394. BYTE FieldRepUCode; // Field Replaceable Unit Code
  186395. BYTE SenKeySpec15; // Sense Key Specific 15th byte
  186396. BYTE SenKeySpec16; // Sense Key Specific 16th byte
  186397. BYTE SenKeySpec17; // Sense Key Specific 17th byte
  186398. BYTE AddSenseBytes; // Additional Sense Bytes
  186399. } SENSE_DATA_FMT;
  186400. //***************************************************************************
  186401. // %%% REQUEST SENSE ERROR CODE %%%
  186402. //***************************************************************************
  186403. #define SERROR_CURRENT 0x70 // Current Errors
  186404. #define SERROR_DEFERED 0x71 // Deferred Errors
  186405. //***************************************************************************
  186406. // %%% REQUEST SENSE BIT DEFINITIONS %%%
  186407. //***************************************************************************
  186408. #define SENSE_VALID 0x80 // Byte 0 Bit 7
  186409. #define SENSE_FILEMRK 0x80 // Byte 2 Bit 7
  186410. #define SENSE_EOM 0x40 // Byte 2 Bit 6
  186411. #define SENSE_ILI 0x20 // Byte 2 Bit 5
  186412. //***************************************************************************
  186413. // %%% REQUEST SENSE SENSE KEY DEFINITIONS %%%
  186414. //***************************************************************************
  186415. #define KEY_NOSENSE 0x00 // No Sense
  186416. #define KEY_RECERROR 0x01 // Recovered Error
  186417. #define KEY_NOTREADY 0x02 // Not Ready
  186418. #define KEY_MEDIUMERR 0x03 // Medium Error
  186419. #define KEY_HARDERROR 0x04 // Hardware Error
  186420. #define KEY_ILLGLREQ 0x05 // Illegal Request
  186421. #define KEY_UNITATT 0x06 // Unit Attention
  186422. #define KEY_DATAPROT 0x07 // Data Protect
  186423. #define KEY_BLANKCHK 0x08 // Blank Check
  186424. #define KEY_VENDSPEC 0x09 // Vendor Specific
  186425. #define KEY_COPYABORT 0x0A // Copy Abort
  186426. #define KEY_EQUAL 0x0C // Equal (Search)
  186427. #define KEY_VOLOVRFLW 0x0D // Volume Overflow
  186428. #define KEY_MISCOMP 0x0E // Miscompare (Search)
  186429. #define KEY_RESERVED 0x0F // Reserved
  186430. //***************************************************************************
  186431. // %%% PERIPHERAL DEVICE TYPE DEFINITIONS %%%
  186432. //***************************************************************************
  186433. #define DTYPE_DASD 0x00 // Disk Device
  186434. #define DTYPE_SEQD 0x01 // Tape Device
  186435. #define DTYPE_PRNT 0x02 // Printer
  186436. #define DTYPE_PROC 0x03 // Processor
  186437. #define DTYPE_WORM 0x04 // Write-once read-multiple
  186438. #define DTYPE_CROM 0x05 // CD-ROM device
  186439. #define DTYPE_SCAN 0x06 // Scanner device
  186440. #define DTYPE_OPTI 0x07 // Optical memory device
  186441. #define DTYPE_JUKE 0x08 // Medium Changer device
  186442. #define DTYPE_COMM 0x09 // Communications device
  186443. #define DTYPE_RESL 0x0A // Reserved (low)
  186444. #define DTYPE_RESH 0x1E // Reserved (high)
  186445. #define DTYPE_UNKNOWN 0x1F // Unknown or no device type
  186446. //***************************************************************************
  186447. // %%% ANSI APPROVED VERSION DEFINITIONS %%%
  186448. //***************************************************************************
  186449. #define ANSI_MAYBE 0x0 // Device may or may not be ANSI approved stand
  186450. #define ANSI_SCSI1 0x1 // Device complies to ANSI X3.131-1986 (SCSI-1)
  186451. #define ANSI_SCSI2 0x2 // Device complies to SCSI-2
  186452. #define ANSI_RESLO 0x3 // Reserved (low)
  186453. #define ANSI_RESHI 0x7 // Reserved (high)
  186454. typedef struct
  186455. {
  186456. USHORT Length;
  186457. UCHAR ScsiStatus;
  186458. UCHAR PathId;
  186459. UCHAR TargetId;
  186460. UCHAR Lun;
  186461. UCHAR CdbLength;
  186462. UCHAR SenseInfoLength;
  186463. UCHAR DataIn;
  186464. ULONG DataTransferLength;
  186465. ULONG TimeOutValue;
  186466. ULONG DataBufferOffset;
  186467. ULONG SenseInfoOffset;
  186468. UCHAR Cdb[16];
  186469. } SCSI_PASS_THROUGH, *PSCSI_PASS_THROUGH;
  186470. typedef struct
  186471. {
  186472. USHORT Length;
  186473. UCHAR ScsiStatus;
  186474. UCHAR PathId;
  186475. UCHAR TargetId;
  186476. UCHAR Lun;
  186477. UCHAR CdbLength;
  186478. UCHAR SenseInfoLength;
  186479. UCHAR DataIn;
  186480. ULONG DataTransferLength;
  186481. ULONG TimeOutValue;
  186482. PVOID DataBuffer;
  186483. ULONG SenseInfoOffset;
  186484. UCHAR Cdb[16];
  186485. } SCSI_PASS_THROUGH_DIRECT, *PSCSI_PASS_THROUGH_DIRECT;
  186486. typedef struct
  186487. {
  186488. SCSI_PASS_THROUGH_DIRECT spt;
  186489. ULONG Filler;
  186490. UCHAR ucSenseBuf[32];
  186491. } SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, *PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER;
  186492. typedef struct
  186493. {
  186494. ULONG Length;
  186495. UCHAR PortNumber;
  186496. UCHAR PathId;
  186497. UCHAR TargetId;
  186498. UCHAR Lun;
  186499. } SCSI_ADDRESS, *PSCSI_ADDRESS;
  186500. #define METHOD_BUFFERED 0
  186501. #define METHOD_IN_DIRECT 1
  186502. #define METHOD_OUT_DIRECT 2
  186503. #define METHOD_NEITHER 3
  186504. #define FILE_ANY_ACCESS 0
  186505. #ifndef FILE_READ_ACCESS
  186506. #define FILE_READ_ACCESS (0x0001)
  186507. #endif
  186508. #ifndef FILE_WRITE_ACCESS
  186509. #define FILE_WRITE_ACCESS (0x0002)
  186510. #endif
  186511. #define IOCTL_SCSI_BASE 0x00000004
  186512. #define SCSI_IOCTL_DATA_OUT 0
  186513. #define SCSI_IOCTL_DATA_IN 1
  186514. #define SCSI_IOCTL_DATA_UNSPECIFIED 2
  186515. #define CTL_CODE2( DevType, Function, Method, Access ) ( \
  186516. ((DevType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) \
  186517. )
  186518. #define IOCTL_SCSI_PASS_THROUGH CTL_CODE2( IOCTL_SCSI_BASE, 0x0401, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS )
  186519. #define IOCTL_SCSI_GET_CAPABILITIES CTL_CODE2( IOCTL_SCSI_BASE, 0x0404, METHOD_BUFFERED, FILE_ANY_ACCESS)
  186520. #define IOCTL_SCSI_PASS_THROUGH_DIRECT CTL_CODE2( IOCTL_SCSI_BASE, 0x0405, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS )
  186521. #define IOCTL_SCSI_GET_ADDRESS CTL_CODE2( IOCTL_SCSI_BASE, 0x0406, METHOD_BUFFERED, FILE_ANY_ACCESS )
  186522. #define SENSE_LEN 14
  186523. #define SRB_DIR_SCSI 0x00
  186524. #define SRB_POSTING 0x01
  186525. #define SRB_ENABLE_RESIDUAL_COUNT 0x04
  186526. #define SRB_DIR_IN 0x08
  186527. #define SRB_DIR_OUT 0x10
  186528. #define SRB_EVENT_NOTIFY 0x40
  186529. #define RESIDUAL_COUNT_SUPPORTED 0x02
  186530. #define MAX_SRB_TIMEOUT 1080001u
  186531. #define DEFAULT_SRB_TIMEOUT 1080001u
  186532. #define SC_HA_INQUIRY 0x00
  186533. #define SC_GET_DEV_TYPE 0x01
  186534. #define SC_EXEC_SCSI_CMD 0x02
  186535. #define SC_ABORT_SRB 0x03
  186536. #define SC_RESET_DEV 0x04
  186537. #define SC_SET_HA_PARMS 0x05
  186538. #define SC_GET_DISK_INFO 0x06
  186539. #define SC_RESCAN_SCSI_BUS 0x07
  186540. #define SC_GETSET_TIMEOUTS 0x08
  186541. #define SS_PENDING 0x00
  186542. #define SS_COMP 0x01
  186543. #define SS_ABORTED 0x02
  186544. #define SS_ABORT_FAIL 0x03
  186545. #define SS_ERR 0x04
  186546. #define SS_INVALID_CMD 0x80
  186547. #define SS_INVALID_HA 0x81
  186548. #define SS_NO_DEVICE 0x82
  186549. #define SS_INVALID_SRB 0xE0
  186550. #define SS_OLD_MANAGER 0xE1
  186551. #define SS_BUFFER_ALIGN 0xE1
  186552. #define SS_ILLEGAL_MODE 0xE2
  186553. #define SS_NO_ASPI 0xE3
  186554. #define SS_FAILED_INIT 0xE4
  186555. #define SS_ASPI_IS_BUSY 0xE5
  186556. #define SS_BUFFER_TO_BIG 0xE6
  186557. #define SS_BUFFER_TOO_BIG 0xE6
  186558. #define SS_MISMATCHED_COMPONENTS 0xE7
  186559. #define SS_NO_ADAPTERS 0xE8
  186560. #define SS_INSUFFICIENT_RESOURCES 0xE9
  186561. #define SS_ASPI_IS_SHUTDOWN 0xEA
  186562. #define SS_BAD_INSTALL 0xEB
  186563. #define HASTAT_OK 0x00
  186564. #define HASTAT_SEL_TO 0x11
  186565. #define HASTAT_DO_DU 0x12
  186566. #define HASTAT_BUS_FREE 0x13
  186567. #define HASTAT_PHASE_ERR 0x14
  186568. #define HASTAT_TIMEOUT 0x09
  186569. #define HASTAT_COMMAND_TIMEOUT 0x0B
  186570. #define HASTAT_MESSAGE_REJECT 0x0D
  186571. #define HASTAT_BUS_RESET 0x0E
  186572. #define HASTAT_PARITY_ERROR 0x0F
  186573. #define HASTAT_REQUEST_SENSE_FAILED 0x10
  186574. #define PACKED
  186575. #pragma pack(1)
  186576. typedef struct
  186577. {
  186578. BYTE SRB_Cmd;
  186579. BYTE SRB_Status;
  186580. BYTE SRB_HaID;
  186581. BYTE SRB_Flags;
  186582. DWORD SRB_Hdr_Rsvd;
  186583. BYTE HA_Count;
  186584. BYTE HA_SCSI_ID;
  186585. BYTE HA_ManagerId[16];
  186586. BYTE HA_Identifier[16];
  186587. BYTE HA_Unique[16];
  186588. WORD HA_Rsvd1;
  186589. BYTE pad[20];
  186590. } PACKED SRB_HAInquiry, *PSRB_HAInquiry, FAR *LPSRB_HAInquiry;
  186591. typedef struct
  186592. {
  186593. BYTE SRB_Cmd;
  186594. BYTE SRB_Status;
  186595. BYTE SRB_HaID;
  186596. BYTE SRB_Flags;
  186597. DWORD SRB_Hdr_Rsvd;
  186598. BYTE SRB_Target;
  186599. BYTE SRB_Lun;
  186600. BYTE SRB_DeviceType;
  186601. BYTE SRB_Rsvd1;
  186602. BYTE pad[68];
  186603. } PACKED SRB_GDEVBlock, *PSRB_GDEVBlock, FAR *LPSRB_GDEVBlock;
  186604. typedef struct
  186605. {
  186606. BYTE SRB_Cmd;
  186607. BYTE SRB_Status;
  186608. BYTE SRB_HaID;
  186609. BYTE SRB_Flags;
  186610. DWORD SRB_Hdr_Rsvd;
  186611. BYTE SRB_Target;
  186612. BYTE SRB_Lun;
  186613. WORD SRB_Rsvd1;
  186614. DWORD SRB_BufLen;
  186615. BYTE FAR *SRB_BufPointer;
  186616. BYTE SRB_SenseLen;
  186617. BYTE SRB_CDBLen;
  186618. BYTE SRB_HaStat;
  186619. BYTE SRB_TargStat;
  186620. VOID FAR *SRB_PostProc;
  186621. BYTE SRB_Rsvd2[20];
  186622. BYTE CDBByte[16];
  186623. BYTE SenseArea[SENSE_LEN+2];
  186624. } PACKED SRB_ExecSCSICmd, *PSRB_ExecSCSICmd, FAR *LPSRB_ExecSCSICmd;
  186625. typedef struct
  186626. {
  186627. BYTE SRB_Cmd;
  186628. BYTE SRB_Status;
  186629. BYTE SRB_HaId;
  186630. BYTE SRB_Flags;
  186631. DWORD SRB_Hdr_Rsvd;
  186632. } PACKED SRB, *PSRB, FAR *LPSRB;
  186633. #pragma pack()
  186634. struct CDDeviceInfo
  186635. {
  186636. char vendor[9];
  186637. char productId[17];
  186638. char rev[5];
  186639. char vendorSpec[21];
  186640. BYTE ha;
  186641. BYTE tgt;
  186642. BYTE lun;
  186643. char scsiDriveLetter; // will be 0 if not using scsi
  186644. };
  186645. class CDReadBuffer
  186646. {
  186647. public:
  186648. int startFrame;
  186649. int numFrames;
  186650. int dataStartOffset;
  186651. int dataLength;
  186652. BYTE* buffer;
  186653. int bufferSize;
  186654. int index;
  186655. bool wantsIndex;
  186656. CDReadBuffer (const int numberOfFrames)
  186657. : startFrame (0),
  186658. numFrames (0),
  186659. dataStartOffset (0),
  186660. dataLength (0),
  186661. index (0),
  186662. wantsIndex (false)
  186663. {
  186664. bufferSize = 2352 * numberOfFrames;
  186665. buffer = (BYTE*) malloc (bufferSize);
  186666. }
  186667. ~CDReadBuffer()
  186668. {
  186669. free (buffer);
  186670. }
  186671. bool isZero() const
  186672. {
  186673. BYTE* p = buffer + dataStartOffset;
  186674. for (int i = dataLength; --i >= 0;)
  186675. if (*p++ != 0)
  186676. return false;
  186677. return true;
  186678. }
  186679. };
  186680. class CDDeviceHandle;
  186681. class CDController
  186682. {
  186683. public:
  186684. CDController();
  186685. virtual ~CDController();
  186686. virtual bool read (CDReadBuffer* t) = 0;
  186687. virtual void shutDown();
  186688. bool readAudio (CDReadBuffer* t, CDReadBuffer* overlapBuffer = 0);
  186689. int getLastIndex();
  186690. public:
  186691. bool initialised;
  186692. CDDeviceHandle* deviceInfo;
  186693. int framesToCheck, framesOverlap;
  186694. void prepare (SRB_ExecSCSICmd& s);
  186695. void perform (SRB_ExecSCSICmd& s);
  186696. void setPaused (bool paused);
  186697. };
  186698. #pragma pack(1)
  186699. struct TOCTRACK
  186700. {
  186701. BYTE rsvd;
  186702. BYTE ADR;
  186703. BYTE trackNumber;
  186704. BYTE rsvd2;
  186705. BYTE addr[4];
  186706. };
  186707. struct TOC
  186708. {
  186709. WORD tocLen;
  186710. BYTE firstTrack;
  186711. BYTE lastTrack;
  186712. TOCTRACK tracks[100];
  186713. };
  186714. #pragma pack()
  186715. enum
  186716. {
  186717. READTYPE_ANY = 0,
  186718. READTYPE_ATAPI1 = 1,
  186719. READTYPE_ATAPI2 = 2,
  186720. READTYPE_READ6 = 3,
  186721. READTYPE_READ10 = 4,
  186722. READTYPE_READ_D8 = 5,
  186723. READTYPE_READ_D4 = 6,
  186724. READTYPE_READ_D4_1 = 7,
  186725. READTYPE_READ10_2 = 8
  186726. };
  186727. class CDDeviceHandle
  186728. {
  186729. public:
  186730. CDDeviceHandle (const CDDeviceInfo* const device)
  186731. : scsiHandle (0),
  186732. readType (READTYPE_ANY),
  186733. controller (0)
  186734. {
  186735. memcpy (&info, device, sizeof (info));
  186736. }
  186737. ~CDDeviceHandle()
  186738. {
  186739. if (controller != 0)
  186740. {
  186741. controller->shutDown();
  186742. delete controller;
  186743. }
  186744. if (scsiHandle != 0)
  186745. CloseHandle (scsiHandle);
  186746. }
  186747. bool readTOC (TOC* lpToc, bool useMSF);
  186748. bool readAudio (CDReadBuffer* buffer, CDReadBuffer* overlapBuffer = 0);
  186749. void openDrawer (bool shouldBeOpen);
  186750. CDDeviceInfo info;
  186751. HANDLE scsiHandle;
  186752. BYTE readType;
  186753. private:
  186754. CDController* controller;
  186755. bool testController (const int readType,
  186756. CDController* const newController,
  186757. CDReadBuffer* const bufferToUse);
  186758. };
  186759. DWORD (*fGetASPI32SupportInfo)(void);
  186760. DWORD (*fSendASPI32Command)(LPSRB);
  186761. static HINSTANCE winAspiLib = 0;
  186762. static bool usingScsi = false;
  186763. static bool initialised = false;
  186764. static bool InitialiseCDRipper()
  186765. {
  186766. if (! initialised)
  186767. {
  186768. initialised = true;
  186769. OSVERSIONINFO info;
  186770. info.dwOSVersionInfoSize = sizeof (info);
  186771. GetVersionEx (&info);
  186772. usingScsi = (info.dwPlatformId == VER_PLATFORM_WIN32_NT) && (info.dwMajorVersion > 4);
  186773. if (! usingScsi)
  186774. {
  186775. fGetASPI32SupportInfo = 0;
  186776. fSendASPI32Command = 0;
  186777. winAspiLib = LoadLibrary (_T("WNASPI32.DLL"));
  186778. if (winAspiLib != 0)
  186779. {
  186780. fGetASPI32SupportInfo = (DWORD(*)(void)) GetProcAddress (winAspiLib, "GetASPI32SupportInfo");
  186781. fSendASPI32Command = (DWORD(*)(LPSRB)) GetProcAddress (winAspiLib, "SendASPI32Command");
  186782. if (fGetASPI32SupportInfo == 0 || fSendASPI32Command == 0)
  186783. return false;
  186784. }
  186785. else
  186786. {
  186787. usingScsi = true;
  186788. }
  186789. }
  186790. }
  186791. return true;
  186792. }
  186793. static void DeinitialiseCDRipper()
  186794. {
  186795. if (winAspiLib != 0)
  186796. {
  186797. fGetASPI32SupportInfo = 0;
  186798. fSendASPI32Command = 0;
  186799. FreeLibrary (winAspiLib);
  186800. winAspiLib = 0;
  186801. }
  186802. initialised = false;
  186803. }
  186804. static HANDLE CreateSCSIDeviceHandle (char driveLetter)
  186805. {
  186806. TCHAR devicePath[8];
  186807. devicePath[0] = '\\';
  186808. devicePath[1] = '\\';
  186809. devicePath[2] = '.';
  186810. devicePath[3] = '\\';
  186811. devicePath[4] = driveLetter;
  186812. devicePath[5] = ':';
  186813. devicePath[6] = 0;
  186814. OSVERSIONINFO info;
  186815. info.dwOSVersionInfoSize = sizeof (info);
  186816. GetVersionEx (&info);
  186817. DWORD flags = GENERIC_READ;
  186818. if ((info.dwPlatformId == VER_PLATFORM_WIN32_NT) && (info.dwMajorVersion > 4))
  186819. flags = GENERIC_READ | GENERIC_WRITE;
  186820. HANDLE h = CreateFile (devicePath, flags, FILE_SHARE_WRITE | FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  186821. if (h == INVALID_HANDLE_VALUE)
  186822. {
  186823. flags ^= GENERIC_WRITE;
  186824. h = CreateFile (devicePath, flags, FILE_SHARE_WRITE | FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  186825. }
  186826. return h;
  186827. }
  186828. static DWORD performScsiPassThroughCommand (const LPSRB_ExecSCSICmd srb,
  186829. const char driveLetter,
  186830. HANDLE& deviceHandle,
  186831. const bool retryOnFailure = true)
  186832. {
  186833. SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER s;
  186834. zerostruct (s);
  186835. s.spt.Length = sizeof (SCSI_PASS_THROUGH);
  186836. s.spt.CdbLength = srb->SRB_CDBLen;
  186837. s.spt.DataIn = (BYTE) ((srb->SRB_Flags & SRB_DIR_IN)
  186838. ? SCSI_IOCTL_DATA_IN
  186839. : ((srb->SRB_Flags & SRB_DIR_OUT)
  186840. ? SCSI_IOCTL_DATA_OUT
  186841. : SCSI_IOCTL_DATA_UNSPECIFIED));
  186842. s.spt.DataTransferLength = srb->SRB_BufLen;
  186843. s.spt.TimeOutValue = 5;
  186844. s.spt.DataBuffer = srb->SRB_BufPointer;
  186845. s.spt.SenseInfoOffset = offsetof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, ucSenseBuf);
  186846. memcpy (s.spt.Cdb, srb->CDBByte, srb->SRB_CDBLen);
  186847. srb->SRB_Status = SS_ERR;
  186848. srb->SRB_TargStat = 0x0004;
  186849. DWORD bytesReturned = 0;
  186850. if (DeviceIoControl (deviceHandle, IOCTL_SCSI_PASS_THROUGH_DIRECT,
  186851. &s, sizeof (s),
  186852. &s, sizeof (s),
  186853. &bytesReturned, 0) != 0)
  186854. {
  186855. srb->SRB_Status = SS_COMP;
  186856. }
  186857. else if (retryOnFailure)
  186858. {
  186859. const DWORD error = GetLastError();
  186860. if ((error == ERROR_MEDIA_CHANGED) || (error == ERROR_INVALID_HANDLE))
  186861. {
  186862. if (error != ERROR_INVALID_HANDLE)
  186863. CloseHandle (deviceHandle);
  186864. deviceHandle = CreateSCSIDeviceHandle (driveLetter);
  186865. return performScsiPassThroughCommand (srb, driveLetter, deviceHandle, false);
  186866. }
  186867. }
  186868. return srb->SRB_Status;
  186869. }
  186870. // Controller types..
  186871. class ControllerType1 : public CDController
  186872. {
  186873. public:
  186874. ControllerType1() {}
  186875. ~ControllerType1() {}
  186876. bool read (CDReadBuffer* rb)
  186877. {
  186878. if (rb->numFrames * 2352 > rb->bufferSize)
  186879. return false;
  186880. SRB_ExecSCSICmd s;
  186881. prepare (s);
  186882. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186883. s.SRB_BufLen = rb->bufferSize;
  186884. s.SRB_BufPointer = rb->buffer;
  186885. s.SRB_CDBLen = 12;
  186886. s.CDBByte[0] = 0xBE;
  186887. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186888. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186889. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186890. s.CDBByte[8] = (BYTE)(rb->numFrames & 0xFF);
  186891. s.CDBByte[9] = (BYTE)((deviceInfo->readType == READTYPE_ATAPI1) ? 0x10 : 0xF0);
  186892. perform (s);
  186893. if (s.SRB_Status != SS_COMP)
  186894. return false;
  186895. rb->dataLength = rb->numFrames * 2352;
  186896. rb->dataStartOffset = 0;
  186897. return true;
  186898. }
  186899. };
  186900. class ControllerType2 : public CDController
  186901. {
  186902. public:
  186903. ControllerType2() {}
  186904. ~ControllerType2() {}
  186905. void shutDown()
  186906. {
  186907. if (initialised)
  186908. {
  186909. BYTE bufPointer[] = { 0, 0, 0, 8, 83, 0, 0, 0, 0, 0, 8, 0 };
  186910. SRB_ExecSCSICmd s;
  186911. prepare (s);
  186912. s.SRB_Flags = SRB_EVENT_NOTIFY | SRB_ENABLE_RESIDUAL_COUNT;
  186913. s.SRB_BufLen = 0x0C;
  186914. s.SRB_BufPointer = bufPointer;
  186915. s.SRB_CDBLen = 6;
  186916. s.CDBByte[0] = 0x15;
  186917. s.CDBByte[4] = 0x0C;
  186918. perform (s);
  186919. }
  186920. }
  186921. bool init()
  186922. {
  186923. SRB_ExecSCSICmd s;
  186924. s.SRB_Status = SS_ERR;
  186925. if (deviceInfo->readType == READTYPE_READ10_2)
  186926. {
  186927. BYTE bufPointer1[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48, 35, 6, 0, 0, 0, 0, 0, 128 };
  186928. BYTE bufPointer2[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48, 1, 6, 32, 7, 0, 0, 0, 0 };
  186929. for (int i = 0; i < 2; ++i)
  186930. {
  186931. prepare (s);
  186932. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186933. s.SRB_BufLen = 0x14;
  186934. s.SRB_BufPointer = (i == 0) ? bufPointer1 : bufPointer2;
  186935. s.SRB_CDBLen = 6;
  186936. s.CDBByte[0] = 0x15;
  186937. s.CDBByte[1] = 0x10;
  186938. s.CDBByte[4] = 0x14;
  186939. perform (s);
  186940. if (s.SRB_Status != SS_COMP)
  186941. return false;
  186942. }
  186943. }
  186944. else
  186945. {
  186946. BYTE bufPointer[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48 };
  186947. prepare (s);
  186948. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186949. s.SRB_BufLen = 0x0C;
  186950. s.SRB_BufPointer = bufPointer;
  186951. s.SRB_CDBLen = 6;
  186952. s.CDBByte[0] = 0x15;
  186953. s.CDBByte[4] = 0x0C;
  186954. perform (s);
  186955. }
  186956. return s.SRB_Status == SS_COMP;
  186957. }
  186958. bool read (CDReadBuffer* rb)
  186959. {
  186960. if (rb->numFrames * 2352 > rb->bufferSize)
  186961. return false;
  186962. if (!initialised)
  186963. {
  186964. initialised = init();
  186965. if (!initialised)
  186966. return false;
  186967. }
  186968. SRB_ExecSCSICmd s;
  186969. prepare (s);
  186970. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186971. s.SRB_BufLen = rb->bufferSize;
  186972. s.SRB_BufPointer = rb->buffer;
  186973. s.SRB_CDBLen = 10;
  186974. s.CDBByte[0] = 0x28;
  186975. s.CDBByte[1] = (BYTE)(deviceInfo->info.lun << 5);
  186976. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186977. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186978. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186979. s.CDBByte[8] = (BYTE)(rb->numFrames & 0xFF);
  186980. perform (s);
  186981. if (s.SRB_Status != SS_COMP)
  186982. return false;
  186983. rb->dataLength = rb->numFrames * 2352;
  186984. rb->dataStartOffset = 0;
  186985. return true;
  186986. }
  186987. };
  186988. class ControllerType3 : public CDController
  186989. {
  186990. public:
  186991. ControllerType3() {}
  186992. ~ControllerType3() {}
  186993. bool read (CDReadBuffer* rb)
  186994. {
  186995. if (rb->numFrames * 2352 > rb->bufferSize)
  186996. return false;
  186997. if (!initialised)
  186998. {
  186999. setPaused (false);
  187000. initialised = true;
  187001. }
  187002. SRB_ExecSCSICmd s;
  187003. prepare (s);
  187004. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  187005. s.SRB_BufLen = rb->numFrames * 2352;
  187006. s.SRB_BufPointer = rb->buffer;
  187007. s.SRB_CDBLen = 12;
  187008. s.CDBByte[0] = 0xD8;
  187009. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  187010. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  187011. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  187012. s.CDBByte[9] = (BYTE)(rb->numFrames & 0xFF);
  187013. perform (s);
  187014. if (s.SRB_Status != SS_COMP)
  187015. return false;
  187016. rb->dataLength = rb->numFrames * 2352;
  187017. rb->dataStartOffset = 0;
  187018. return true;
  187019. }
  187020. };
  187021. class ControllerType4 : public CDController
  187022. {
  187023. public:
  187024. ControllerType4() {}
  187025. ~ControllerType4() {}
  187026. bool selectD4Mode()
  187027. {
  187028. BYTE bufPointer[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 48 };
  187029. SRB_ExecSCSICmd s;
  187030. prepare (s);
  187031. s.SRB_Flags = SRB_EVENT_NOTIFY;
  187032. s.SRB_CDBLen = 6;
  187033. s.SRB_BufLen = 12;
  187034. s.SRB_BufPointer = bufPointer;
  187035. s.CDBByte[0] = 0x15;
  187036. s.CDBByte[1] = 0x10;
  187037. s.CDBByte[4] = 0x08;
  187038. perform (s);
  187039. return s.SRB_Status == SS_COMP;
  187040. }
  187041. bool read (CDReadBuffer* rb)
  187042. {
  187043. if (rb->numFrames * 2352 > rb->bufferSize)
  187044. return false;
  187045. if (!initialised)
  187046. {
  187047. setPaused (true);
  187048. if (deviceInfo->readType == READTYPE_READ_D4_1)
  187049. selectD4Mode();
  187050. initialised = true;
  187051. }
  187052. SRB_ExecSCSICmd s;
  187053. prepare (s);
  187054. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  187055. s.SRB_BufLen = rb->bufferSize;
  187056. s.SRB_BufPointer = rb->buffer;
  187057. s.SRB_CDBLen = 10;
  187058. s.CDBByte[0] = 0xD4;
  187059. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  187060. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  187061. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  187062. s.CDBByte[8] = (BYTE)(rb->numFrames & 0xFF);
  187063. perform (s);
  187064. if (s.SRB_Status != SS_COMP)
  187065. return false;
  187066. rb->dataLength = rb->numFrames * 2352;
  187067. rb->dataStartOffset = 0;
  187068. return true;
  187069. }
  187070. };
  187071. CDController::CDController() : initialised (false)
  187072. {
  187073. }
  187074. CDController::~CDController()
  187075. {
  187076. }
  187077. void CDController::prepare (SRB_ExecSCSICmd& s)
  187078. {
  187079. zerostruct (s);
  187080. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  187081. s.SRB_HaID = deviceInfo->info.ha;
  187082. s.SRB_Target = deviceInfo->info.tgt;
  187083. s.SRB_Lun = deviceInfo->info.lun;
  187084. s.SRB_SenseLen = SENSE_LEN;
  187085. }
  187086. void CDController::perform (SRB_ExecSCSICmd& s)
  187087. {
  187088. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  187089. s.SRB_PostProc = (void*)event;
  187090. ResetEvent (event);
  187091. DWORD status = (usingScsi) ? performScsiPassThroughCommand ((LPSRB_ExecSCSICmd)&s,
  187092. deviceInfo->info.scsiDriveLetter,
  187093. deviceInfo->scsiHandle)
  187094. : fSendASPI32Command ((LPSRB)&s);
  187095. if (status == SS_PENDING)
  187096. WaitForSingleObject (event, 4000);
  187097. CloseHandle (event);
  187098. }
  187099. void CDController::setPaused (bool paused)
  187100. {
  187101. SRB_ExecSCSICmd s;
  187102. prepare (s);
  187103. s.SRB_Flags = SRB_EVENT_NOTIFY;
  187104. s.SRB_CDBLen = 10;
  187105. s.CDBByte[0] = 0x4B;
  187106. s.CDBByte[8] = (BYTE) (paused ? 0 : 1);
  187107. perform (s);
  187108. }
  187109. void CDController::shutDown()
  187110. {
  187111. }
  187112. bool CDController::readAudio (CDReadBuffer* rb, CDReadBuffer* overlapBuffer)
  187113. {
  187114. if (overlapBuffer != 0)
  187115. {
  187116. const bool canDoJitter = (overlapBuffer->bufferSize >= 2352 * framesToCheck);
  187117. const bool doJitter = canDoJitter && ! overlapBuffer->isZero();
  187118. if (doJitter
  187119. && overlapBuffer->startFrame > 0
  187120. && overlapBuffer->numFrames > 0
  187121. && overlapBuffer->dataLength > 0)
  187122. {
  187123. const int numFrames = rb->numFrames;
  187124. if (overlapBuffer->startFrame == (rb->startFrame - framesToCheck))
  187125. {
  187126. rb->startFrame -= framesOverlap;
  187127. if (framesToCheck < framesOverlap
  187128. && numFrames + framesOverlap <= rb->bufferSize / 2352)
  187129. rb->numFrames += framesOverlap;
  187130. }
  187131. else
  187132. {
  187133. overlapBuffer->dataLength = 0;
  187134. overlapBuffer->startFrame = 0;
  187135. overlapBuffer->numFrames = 0;
  187136. }
  187137. }
  187138. if (! read (rb))
  187139. return false;
  187140. if (doJitter)
  187141. {
  187142. const int checkLen = framesToCheck * 2352;
  187143. const int maxToCheck = rb->dataLength - checkLen;
  187144. if (overlapBuffer->dataLength == 0 || overlapBuffer->isZero())
  187145. return true;
  187146. BYTE* const p = overlapBuffer->buffer + overlapBuffer->dataStartOffset;
  187147. bool found = false;
  187148. for (int i = 0; i < maxToCheck; ++i)
  187149. {
  187150. if (!memcmp (p, rb->buffer + i, checkLen))
  187151. {
  187152. i += checkLen;
  187153. rb->dataStartOffset = i;
  187154. rb->dataLength -= i;
  187155. rb->startFrame = overlapBuffer->startFrame + framesToCheck;
  187156. found = true;
  187157. break;
  187158. }
  187159. }
  187160. rb->numFrames = rb->dataLength / 2352;
  187161. rb->dataLength = 2352 * rb->numFrames;
  187162. if (!found)
  187163. return false;
  187164. }
  187165. if (canDoJitter)
  187166. {
  187167. memcpy (overlapBuffer->buffer,
  187168. rb->buffer + rb->dataStartOffset + 2352 * (rb->numFrames - framesToCheck),
  187169. 2352 * framesToCheck);
  187170. overlapBuffer->startFrame = rb->startFrame + rb->numFrames - framesToCheck;
  187171. overlapBuffer->numFrames = framesToCheck;
  187172. overlapBuffer->dataLength = 2352 * framesToCheck;
  187173. overlapBuffer->dataStartOffset = 0;
  187174. }
  187175. else
  187176. {
  187177. overlapBuffer->startFrame = 0;
  187178. overlapBuffer->numFrames = 0;
  187179. overlapBuffer->dataLength = 0;
  187180. }
  187181. return true;
  187182. }
  187183. else
  187184. {
  187185. return read (rb);
  187186. }
  187187. }
  187188. int CDController::getLastIndex()
  187189. {
  187190. char qdata[100];
  187191. SRB_ExecSCSICmd s;
  187192. prepare (s);
  187193. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  187194. s.SRB_BufLen = sizeof (qdata);
  187195. s.SRB_BufPointer = (BYTE*)qdata;
  187196. s.SRB_CDBLen = 12;
  187197. s.CDBByte[0] = 0x42;
  187198. s.CDBByte[1] = (BYTE)(deviceInfo->info.lun << 5);
  187199. s.CDBByte[2] = 64;
  187200. s.CDBByte[3] = 1; // get current position
  187201. s.CDBByte[7] = 0;
  187202. s.CDBByte[8] = (BYTE)sizeof (qdata);
  187203. perform (s);
  187204. if (s.SRB_Status == SS_COMP)
  187205. return qdata[7];
  187206. return 0;
  187207. }
  187208. bool CDDeviceHandle::readTOC (TOC* lpToc, bool useMSF)
  187209. {
  187210. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  187211. SRB_ExecSCSICmd s;
  187212. zerostruct (s);
  187213. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  187214. s.SRB_HaID = info.ha;
  187215. s.SRB_Target = info.tgt;
  187216. s.SRB_Lun = info.lun;
  187217. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  187218. s.SRB_BufLen = 0x324;
  187219. s.SRB_BufPointer = (BYTE*)lpToc;
  187220. s.SRB_SenseLen = 0x0E;
  187221. s.SRB_CDBLen = 0x0A;
  187222. s.SRB_PostProc = (void*)event;
  187223. s.CDBByte[0] = 0x43;
  187224. s.CDBByte[1] = (BYTE)(useMSF ? 0x02 : 0x00);
  187225. s.CDBByte[7] = 0x03;
  187226. s.CDBByte[8] = 0x24;
  187227. ResetEvent (event);
  187228. DWORD status = (usingScsi) ? performScsiPassThroughCommand ((LPSRB_ExecSCSICmd)&s, info.scsiDriveLetter, scsiHandle)
  187229. : fSendASPI32Command ((LPSRB)&s);
  187230. if (status == SS_PENDING)
  187231. WaitForSingleObject (event, 4000);
  187232. CloseHandle (event);
  187233. return (s.SRB_Status == SS_COMP);
  187234. }
  187235. bool CDDeviceHandle::readAudio (CDReadBuffer* const buffer,
  187236. CDReadBuffer* const overlapBuffer)
  187237. {
  187238. if (controller == 0)
  187239. {
  187240. testController (READTYPE_ATAPI2, new ControllerType1(), buffer)
  187241. || testController (READTYPE_ATAPI1, new ControllerType1(), buffer)
  187242. || testController (READTYPE_READ10_2, new ControllerType2(), buffer)
  187243. || testController (READTYPE_READ10, new ControllerType2(), buffer)
  187244. || testController (READTYPE_READ_D8, new ControllerType3(), buffer)
  187245. || testController (READTYPE_READ_D4, new ControllerType4(), buffer)
  187246. || testController (READTYPE_READ_D4_1, new ControllerType4(), buffer);
  187247. }
  187248. buffer->index = 0;
  187249. if ((controller != 0)
  187250. && controller->readAudio (buffer, overlapBuffer))
  187251. {
  187252. if (buffer->wantsIndex)
  187253. buffer->index = controller->getLastIndex();
  187254. return true;
  187255. }
  187256. return false;
  187257. }
  187258. void CDDeviceHandle::openDrawer (bool shouldBeOpen)
  187259. {
  187260. if (shouldBeOpen)
  187261. {
  187262. if (controller != 0)
  187263. {
  187264. controller->shutDown();
  187265. delete controller;
  187266. controller = 0;
  187267. }
  187268. if (scsiHandle != 0)
  187269. {
  187270. CloseHandle (scsiHandle);
  187271. scsiHandle = 0;
  187272. }
  187273. }
  187274. SRB_ExecSCSICmd s;
  187275. zerostruct (s);
  187276. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  187277. s.SRB_HaID = info.ha;
  187278. s.SRB_Target = info.tgt;
  187279. s.SRB_Lun = info.lun;
  187280. s.SRB_SenseLen = SENSE_LEN;
  187281. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  187282. s.SRB_BufLen = 0;
  187283. s.SRB_BufPointer = 0;
  187284. s.SRB_CDBLen = 12;
  187285. s.CDBByte[0] = 0x1b;
  187286. s.CDBByte[1] = (BYTE)(info.lun << 5);
  187287. s.CDBByte[4] = (BYTE)((shouldBeOpen) ? 2 : 3);
  187288. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  187289. s.SRB_PostProc = (void*)event;
  187290. ResetEvent (event);
  187291. DWORD status = (usingScsi) ? performScsiPassThroughCommand ((LPSRB_ExecSCSICmd)&s, info.scsiDriveLetter, scsiHandle)
  187292. : fSendASPI32Command ((LPSRB)&s);
  187293. if (status == SS_PENDING)
  187294. WaitForSingleObject (event, 4000);
  187295. CloseHandle (event);
  187296. }
  187297. bool CDDeviceHandle::testController (const int type,
  187298. CDController* const newController,
  187299. CDReadBuffer* const rb)
  187300. {
  187301. controller = newController;
  187302. readType = (BYTE)type;
  187303. controller->deviceInfo = this;
  187304. controller->framesToCheck = 1;
  187305. controller->framesOverlap = 3;
  187306. bool passed = false;
  187307. memset (rb->buffer, 0xcd, rb->bufferSize);
  187308. if (controller->read (rb))
  187309. {
  187310. passed = true;
  187311. int* p = (int*) (rb->buffer + rb->dataStartOffset);
  187312. int wrong = 0;
  187313. for (int i = rb->dataLength / 4; --i >= 0;)
  187314. {
  187315. if (*p++ == (int) 0xcdcdcdcd)
  187316. {
  187317. if (++wrong == 4)
  187318. {
  187319. passed = false;
  187320. break;
  187321. }
  187322. }
  187323. else
  187324. {
  187325. wrong = 0;
  187326. }
  187327. }
  187328. }
  187329. if (! passed)
  187330. {
  187331. controller->shutDown();
  187332. delete controller;
  187333. controller = 0;
  187334. }
  187335. return passed;
  187336. }
  187337. static void GetAspiDeviceInfo (CDDeviceInfo* dev, BYTE ha, BYTE tgt, BYTE lun)
  187338. {
  187339. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  187340. const int bufSize = 128;
  187341. BYTE buffer[bufSize];
  187342. zeromem (buffer, bufSize);
  187343. SRB_ExecSCSICmd s;
  187344. zerostruct (s);
  187345. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  187346. s.SRB_HaID = ha;
  187347. s.SRB_Target = tgt;
  187348. s.SRB_Lun = lun;
  187349. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  187350. s.SRB_BufLen = bufSize;
  187351. s.SRB_BufPointer = buffer;
  187352. s.SRB_SenseLen = SENSE_LEN;
  187353. s.SRB_CDBLen = 6;
  187354. s.SRB_PostProc = (void*)event;
  187355. s.CDBByte[0] = SCSI_INQUIRY;
  187356. s.CDBByte[4] = 100;
  187357. ResetEvent (event);
  187358. if (fSendASPI32Command ((LPSRB)&s) == SS_PENDING)
  187359. WaitForSingleObject (event, 4000);
  187360. CloseHandle (event);
  187361. if (s.SRB_Status == SS_COMP)
  187362. {
  187363. memcpy (dev->vendor, &buffer[8], 8);
  187364. memcpy (dev->productId, &buffer[16], 16);
  187365. memcpy (dev->rev, &buffer[32], 4);
  187366. memcpy (dev->vendorSpec, &buffer[36], 20);
  187367. }
  187368. }
  187369. static int FindCDDevices (CDDeviceInfo* const list,
  187370. int maxItems)
  187371. {
  187372. int count = 0;
  187373. if (usingScsi)
  187374. {
  187375. for (char driveLetter = 'b'; driveLetter <= 'z'; ++driveLetter)
  187376. {
  187377. TCHAR drivePath[8];
  187378. drivePath[0] = driveLetter;
  187379. drivePath[1] = ':';
  187380. drivePath[2] = '\\';
  187381. drivePath[3] = 0;
  187382. if (GetDriveType (drivePath) == DRIVE_CDROM)
  187383. {
  187384. HANDLE h = CreateSCSIDeviceHandle (driveLetter);
  187385. if (h != INVALID_HANDLE_VALUE)
  187386. {
  187387. BYTE buffer[100], passThroughStruct[1024];
  187388. zeromem (buffer, sizeof (buffer));
  187389. zeromem (passThroughStruct, sizeof (passThroughStruct));
  187390. PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER p = (PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER)passThroughStruct;
  187391. p->spt.Length = sizeof (SCSI_PASS_THROUGH);
  187392. p->spt.CdbLength = 6;
  187393. p->spt.SenseInfoLength = 24;
  187394. p->spt.DataIn = SCSI_IOCTL_DATA_IN;
  187395. p->spt.DataTransferLength = 100;
  187396. p->spt.TimeOutValue = 2;
  187397. p->spt.DataBuffer = buffer;
  187398. p->spt.SenseInfoOffset = offsetof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, ucSenseBuf);
  187399. p->spt.Cdb[0] = 0x12;
  187400. p->spt.Cdb[4] = 100;
  187401. DWORD bytesReturned = 0;
  187402. if (DeviceIoControl (h, IOCTL_SCSI_PASS_THROUGH_DIRECT,
  187403. p, sizeof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER),
  187404. p, sizeof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER),
  187405. &bytesReturned, 0) != 0)
  187406. {
  187407. zeromem (&list[count], sizeof (CDDeviceInfo));
  187408. list[count].scsiDriveLetter = driveLetter;
  187409. memcpy (list[count].vendor, &buffer[8], 8);
  187410. memcpy (list[count].productId, &buffer[16], 16);
  187411. memcpy (list[count].rev, &buffer[32], 4);
  187412. memcpy (list[count].vendorSpec, &buffer[36], 20);
  187413. zeromem (passThroughStruct, sizeof (passThroughStruct));
  187414. PSCSI_ADDRESS scsiAddr = (PSCSI_ADDRESS)passThroughStruct;
  187415. scsiAddr->Length = sizeof (SCSI_ADDRESS);
  187416. if (DeviceIoControl (h, IOCTL_SCSI_GET_ADDRESS,
  187417. 0, 0, scsiAddr, sizeof (SCSI_ADDRESS),
  187418. &bytesReturned, 0) != 0)
  187419. {
  187420. list[count].ha = scsiAddr->PortNumber;
  187421. list[count].tgt = scsiAddr->TargetId;
  187422. list[count].lun = scsiAddr->Lun;
  187423. ++count;
  187424. }
  187425. }
  187426. CloseHandle (h);
  187427. }
  187428. }
  187429. }
  187430. }
  187431. else
  187432. {
  187433. const DWORD d = fGetASPI32SupportInfo();
  187434. BYTE status = HIBYTE (LOWORD (d));
  187435. if (status != SS_COMP || status == SS_NO_ADAPTERS)
  187436. return 0;
  187437. const int numAdapters = LOBYTE (LOWORD (d));
  187438. for (BYTE ha = 0; ha < numAdapters; ++ha)
  187439. {
  187440. SRB_HAInquiry s;
  187441. zerostruct (s);
  187442. s.SRB_Cmd = SC_HA_INQUIRY;
  187443. s.SRB_HaID = ha;
  187444. fSendASPI32Command ((LPSRB)&s);
  187445. if (s.SRB_Status == SS_COMP)
  187446. {
  187447. maxItems = (int)s.HA_Unique[3];
  187448. if (maxItems == 0)
  187449. maxItems = 8;
  187450. for (BYTE tgt = 0; tgt < maxItems; ++tgt)
  187451. {
  187452. for (BYTE lun = 0; lun < 8; ++lun)
  187453. {
  187454. SRB_GDEVBlock sb;
  187455. zerostruct (sb);
  187456. sb.SRB_Cmd = SC_GET_DEV_TYPE;
  187457. sb.SRB_HaID = ha;
  187458. sb.SRB_Target = tgt;
  187459. sb.SRB_Lun = lun;
  187460. fSendASPI32Command ((LPSRB) &sb);
  187461. if (sb.SRB_Status == SS_COMP
  187462. && sb.SRB_DeviceType == DTYPE_CROM)
  187463. {
  187464. zeromem (&list[count], sizeof (CDDeviceInfo));
  187465. list[count].ha = ha;
  187466. list[count].tgt = tgt;
  187467. list[count].lun = lun;
  187468. GetAspiDeviceInfo (&(list[count]), ha, tgt, lun);
  187469. ++count;
  187470. }
  187471. }
  187472. }
  187473. }
  187474. }
  187475. }
  187476. return count;
  187477. }
  187478. static int ripperUsers = 0;
  187479. static bool initialisedOk = false;
  187480. class DeinitialiseTimer : private Timer,
  187481. private DeletedAtShutdown
  187482. {
  187483. DeinitialiseTimer (const DeinitialiseTimer&);
  187484. const DeinitialiseTimer& operator= (const DeinitialiseTimer&);
  187485. public:
  187486. DeinitialiseTimer()
  187487. {
  187488. startTimer (4000);
  187489. }
  187490. ~DeinitialiseTimer()
  187491. {
  187492. if (--ripperUsers == 0)
  187493. DeinitialiseCDRipper();
  187494. }
  187495. void timerCallback()
  187496. {
  187497. delete this;
  187498. }
  187499. juce_UseDebuggingNewOperator
  187500. };
  187501. static void incUserCount()
  187502. {
  187503. if (ripperUsers++ == 0)
  187504. initialisedOk = InitialiseCDRipper();
  187505. }
  187506. static void decUserCount()
  187507. {
  187508. new DeinitialiseTimer();
  187509. }
  187510. struct CDDeviceWrapper
  187511. {
  187512. CDDeviceHandle* cdH;
  187513. CDReadBuffer* overlapBuffer;
  187514. bool jitter;
  187515. };
  187516. static int getAddressOf (const TOCTRACK* const t)
  187517. {
  187518. return (((DWORD)t->addr[0]) << 24) + (((DWORD)t->addr[1]) << 16) +
  187519. (((DWORD)t->addr[2]) << 8) + ((DWORD)t->addr[3]);
  187520. }
  187521. static int getMSFAddressOf (const TOCTRACK* const t)
  187522. {
  187523. return 60 * t->addr[1] + t->addr[2];
  187524. }
  187525. static const int samplesPerFrame = 44100 / 75;
  187526. static const int bytesPerFrame = samplesPerFrame * 4;
  187527. const StringArray AudioCDReader::getAvailableCDNames()
  187528. {
  187529. StringArray results;
  187530. incUserCount();
  187531. if (initialisedOk)
  187532. {
  187533. CDDeviceInfo list[8];
  187534. const int num = FindCDDevices (list, 8);
  187535. decUserCount();
  187536. for (int i = 0; i < num; ++i)
  187537. {
  187538. String s;
  187539. if (list[i].scsiDriveLetter > 0)
  187540. s << String::charToString (list[i].scsiDriveLetter).toUpperCase() << T(": ");
  187541. s << String (list[i].vendor).trim()
  187542. << T(" ") << String (list[i].productId).trim()
  187543. << T(" ") << String (list[i].rev).trim();
  187544. results.add (s);
  187545. }
  187546. }
  187547. return results;
  187548. }
  187549. static CDDeviceHandle* openHandle (const CDDeviceInfo* const device)
  187550. {
  187551. SRB_GDEVBlock s;
  187552. zerostruct (s);
  187553. s.SRB_Cmd = SC_GET_DEV_TYPE;
  187554. s.SRB_HaID = device->ha;
  187555. s.SRB_Target = device->tgt;
  187556. s.SRB_Lun = device->lun;
  187557. if (usingScsi)
  187558. {
  187559. HANDLE h = CreateSCSIDeviceHandle (device->scsiDriveLetter);
  187560. if (h != INVALID_HANDLE_VALUE)
  187561. {
  187562. CDDeviceHandle* cdh = new CDDeviceHandle (device);
  187563. cdh->scsiHandle = h;
  187564. return cdh;
  187565. }
  187566. }
  187567. else
  187568. {
  187569. if (fSendASPI32Command ((LPSRB)&s) == SS_COMP
  187570. && s.SRB_DeviceType == DTYPE_CROM)
  187571. {
  187572. return new CDDeviceHandle (device);
  187573. }
  187574. }
  187575. return 0;
  187576. }
  187577. AudioCDReader* AudioCDReader::createReaderForCD (const int deviceIndex)
  187578. {
  187579. incUserCount();
  187580. if (initialisedOk)
  187581. {
  187582. CDDeviceInfo list[8];
  187583. const int num = FindCDDevices (list, 8);
  187584. if (((unsigned int) deviceIndex) < (unsigned int) num)
  187585. {
  187586. CDDeviceHandle* const handle = openHandle (&(list[deviceIndex]));
  187587. if (handle != 0)
  187588. {
  187589. CDDeviceWrapper* const d = new CDDeviceWrapper();
  187590. d->cdH = handle;
  187591. d->overlapBuffer = new CDReadBuffer(3);
  187592. return new AudioCDReader (d);
  187593. }
  187594. }
  187595. }
  187596. decUserCount();
  187597. return 0;
  187598. }
  187599. AudioCDReader::AudioCDReader (void* handle_)
  187600. : AudioFormatReader (0, T("CD Audio")),
  187601. handle (handle_),
  187602. indexingEnabled (false),
  187603. lastIndex (0),
  187604. firstFrameInBuffer (0),
  187605. samplesInBuffer (0)
  187606. {
  187607. jassert (handle_ != 0);
  187608. refreshTrackLengths();
  187609. sampleRate = 44100.0;
  187610. bitsPerSample = 16;
  187611. lengthInSamples = getPositionOfTrackStart (numTracks);
  187612. numChannels = 2;
  187613. usesFloatingPointData = false;
  187614. buffer.setSize (4 * bytesPerFrame, true);
  187615. }
  187616. AudioCDReader::~AudioCDReader()
  187617. {
  187618. CDDeviceWrapper* const device = (CDDeviceWrapper*)handle;
  187619. delete device->cdH;
  187620. delete device->overlapBuffer;
  187621. delete device;
  187622. decUserCount();
  187623. }
  187624. bool AudioCDReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  187625. int64 startSampleInFile, int numSamples)
  187626. {
  187627. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  187628. bool ok = true;
  187629. while (numSamples > 0)
  187630. {
  187631. const int bufferStartSample = firstFrameInBuffer * samplesPerFrame;
  187632. const int bufferEndSample = bufferStartSample + samplesInBuffer;
  187633. if (startSampleInFile >= bufferStartSample
  187634. && startSampleInFile < bufferEndSample)
  187635. {
  187636. const int toDo = (int) jmin ((int64) numSamples, bufferEndSample - startSampleInFile);
  187637. int* const l = destSamples[0] + startOffsetInDestBuffer;
  187638. int* const r = numDestChannels > 1 ? (destSamples[1] + startOffsetInDestBuffer) : 0;
  187639. const short* src = (const short*) buffer.getData();
  187640. src += 2 * (startSampleInFile - bufferStartSample);
  187641. for (int i = 0; i < toDo; ++i)
  187642. {
  187643. l[i] = src [i << 1] << 16;
  187644. if (r != 0)
  187645. r[i] = src [(i << 1) + 1] << 16;
  187646. }
  187647. startOffsetInDestBuffer += toDo;
  187648. startSampleInFile += toDo;
  187649. numSamples -= toDo;
  187650. }
  187651. else
  187652. {
  187653. const int framesInBuffer = buffer.getSize() / bytesPerFrame;
  187654. const int frameNeeded = (int) (startSampleInFile / samplesPerFrame);
  187655. if (firstFrameInBuffer + framesInBuffer != frameNeeded)
  187656. {
  187657. device->overlapBuffer->dataLength = 0;
  187658. device->overlapBuffer->startFrame = 0;
  187659. device->overlapBuffer->numFrames = 0;
  187660. device->jitter = false;
  187661. }
  187662. firstFrameInBuffer = frameNeeded;
  187663. lastIndex = 0;
  187664. CDReadBuffer readBuffer (framesInBuffer + 4);
  187665. readBuffer.wantsIndex = indexingEnabled;
  187666. int i;
  187667. for (i = 5; --i >= 0;)
  187668. {
  187669. readBuffer.startFrame = frameNeeded;
  187670. readBuffer.numFrames = framesInBuffer;
  187671. if (device->cdH->readAudio (&readBuffer, (device->jitter) ? device->overlapBuffer : 0))
  187672. break;
  187673. else
  187674. device->overlapBuffer->dataLength = 0;
  187675. }
  187676. if (i >= 0)
  187677. {
  187678. memcpy ((char*) buffer.getData(),
  187679. readBuffer.buffer + readBuffer.dataStartOffset,
  187680. readBuffer.dataLength);
  187681. samplesInBuffer = readBuffer.dataLength >> 2;
  187682. lastIndex = readBuffer.index;
  187683. }
  187684. else
  187685. {
  187686. int* l = destSamples[0] + startOffsetInDestBuffer;
  187687. int* r = numDestChannels > 1 ? (destSamples[1] + startOffsetInDestBuffer) : 0;
  187688. while (--numSamples >= 0)
  187689. {
  187690. *l++ = 0;
  187691. if (r != 0)
  187692. *r++ = 0;
  187693. }
  187694. // sometimes the read fails for just the very last couple of blocks, so
  187695. // we'll ignore and errors in the last half-second of the disk..
  187696. ok = startSampleInFile > (trackStarts [numTracks] - 20000);
  187697. break;
  187698. }
  187699. }
  187700. }
  187701. return ok;
  187702. }
  187703. bool AudioCDReader::isCDStillPresent() const
  187704. {
  187705. TOC toc;
  187706. zerostruct (toc);
  187707. return ((CDDeviceWrapper*)handle)->cdH->readTOC (&toc, false);
  187708. }
  187709. int AudioCDReader::getNumTracks() const
  187710. {
  187711. return numTracks;
  187712. }
  187713. int AudioCDReader::getPositionOfTrackStart (int trackNum) const
  187714. {
  187715. return (trackNum >= 0 && trackNum <= numTracks) ? trackStarts [trackNum] * samplesPerFrame
  187716. : 0;
  187717. }
  187718. void AudioCDReader::refreshTrackLengths()
  187719. {
  187720. zeromem (trackStarts, sizeof (trackStarts));
  187721. zeromem (audioTracks, sizeof (audioTracks));
  187722. TOC toc;
  187723. zerostruct (toc);
  187724. if (((CDDeviceWrapper*)handle)->cdH->readTOC (&toc, false))
  187725. {
  187726. numTracks = 1 + toc.lastTrack - toc.firstTrack;
  187727. for (int i = 0; i <= numTracks; ++i)
  187728. {
  187729. trackStarts[i] = getAddressOf (&toc.tracks[i]);
  187730. audioTracks[i] = ((toc.tracks[i].ADR & 4) == 0);
  187731. }
  187732. }
  187733. else
  187734. {
  187735. numTracks = 0;
  187736. }
  187737. }
  187738. bool AudioCDReader::isTrackAudio (int trackNum) const
  187739. {
  187740. return (trackNum >= 0 && trackNum <= numTracks) ? audioTracks [trackNum]
  187741. : false;
  187742. }
  187743. void AudioCDReader::enableIndexScanning (bool b)
  187744. {
  187745. indexingEnabled = b;
  187746. }
  187747. int AudioCDReader::getLastIndex() const
  187748. {
  187749. return lastIndex;
  187750. }
  187751. const int framesPerIndexRead = 4;
  187752. int AudioCDReader::getIndexAt (int samplePos)
  187753. {
  187754. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  187755. const int frameNeeded = samplePos / samplesPerFrame;
  187756. device->overlapBuffer->dataLength = 0;
  187757. device->overlapBuffer->startFrame = 0;
  187758. device->overlapBuffer->numFrames = 0;
  187759. device->jitter = false;
  187760. firstFrameInBuffer = 0;
  187761. lastIndex = 0;
  187762. CDReadBuffer readBuffer (4 + framesPerIndexRead);
  187763. readBuffer.wantsIndex = true;
  187764. int i;
  187765. for (i = 5; --i >= 0;)
  187766. {
  187767. readBuffer.startFrame = frameNeeded;
  187768. readBuffer.numFrames = framesPerIndexRead;
  187769. if (device->cdH->readAudio (&readBuffer, (false) ? device->overlapBuffer : 0))
  187770. break;
  187771. }
  187772. if (i >= 0)
  187773. return readBuffer.index;
  187774. return -1;
  187775. }
  187776. const Array <int> AudioCDReader::findIndexesInTrack (const int trackNumber)
  187777. {
  187778. Array <int> indexes;
  187779. const int trackStart = getPositionOfTrackStart (trackNumber);
  187780. const int trackEnd = getPositionOfTrackStart (trackNumber + 1);
  187781. bool needToScan = true;
  187782. if (trackEnd - trackStart > 20 * 44100)
  187783. {
  187784. // check the end of the track for indexes before scanning the whole thing
  187785. needToScan = false;
  187786. int pos = jmax (trackStart, trackEnd - 44100 * 5);
  187787. bool seenAnIndex = false;
  187788. while (pos <= trackEnd - samplesPerFrame)
  187789. {
  187790. const int index = getIndexAt (pos);
  187791. if (index == 0)
  187792. {
  187793. // lead-out, so skip back a bit if we've not found any indexes yet..
  187794. if (seenAnIndex)
  187795. break;
  187796. pos -= 44100 * 5;
  187797. if (pos < trackStart)
  187798. break;
  187799. }
  187800. else
  187801. {
  187802. if (index > 0)
  187803. seenAnIndex = true;
  187804. if (index > 1)
  187805. {
  187806. needToScan = true;
  187807. break;
  187808. }
  187809. pos += samplesPerFrame * framesPerIndexRead;
  187810. }
  187811. }
  187812. }
  187813. if (needToScan)
  187814. {
  187815. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  187816. int pos = trackStart;
  187817. int last = -1;
  187818. while (pos < trackEnd - samplesPerFrame * 10)
  187819. {
  187820. const int frameNeeded = pos / samplesPerFrame;
  187821. device->overlapBuffer->dataLength = 0;
  187822. device->overlapBuffer->startFrame = 0;
  187823. device->overlapBuffer->numFrames = 0;
  187824. device->jitter = false;
  187825. firstFrameInBuffer = 0;
  187826. CDReadBuffer readBuffer (4);
  187827. readBuffer.wantsIndex = true;
  187828. int i;
  187829. for (i = 5; --i >= 0;)
  187830. {
  187831. readBuffer.startFrame = frameNeeded;
  187832. readBuffer.numFrames = framesPerIndexRead;
  187833. if (device->cdH->readAudio (&readBuffer, (false) ? device->overlapBuffer : 0))
  187834. break;
  187835. }
  187836. if (i < 0)
  187837. break;
  187838. if (readBuffer.index > last && readBuffer.index > 1)
  187839. {
  187840. last = readBuffer.index;
  187841. indexes.add (pos);
  187842. }
  187843. pos += samplesPerFrame * framesPerIndexRead;
  187844. }
  187845. indexes.removeValue (trackStart);
  187846. }
  187847. return indexes;
  187848. }
  187849. int AudioCDReader::getCDDBId()
  187850. {
  187851. refreshTrackLengths();
  187852. if (numTracks > 0)
  187853. {
  187854. TOC toc;
  187855. zerostruct (toc);
  187856. if (((CDDeviceWrapper*) handle)->cdH->readTOC (&toc, true))
  187857. {
  187858. int n = 0;
  187859. for (int i = numTracks; --i >= 0;)
  187860. {
  187861. int j = getMSFAddressOf (&toc.tracks[i]);
  187862. while (j > 0)
  187863. {
  187864. n += (j % 10);
  187865. j /= 10;
  187866. }
  187867. }
  187868. if (n != 0)
  187869. {
  187870. const int t = getMSFAddressOf (&toc.tracks[numTracks])
  187871. - getMSFAddressOf (&toc.tracks[0]);
  187872. return ((n % 0xff) << 24) | (t << 8) | numTracks;
  187873. }
  187874. }
  187875. }
  187876. return 0;
  187877. }
  187878. void AudioCDReader::ejectDisk()
  187879. {
  187880. ((CDDeviceWrapper*) handle)->cdH->openDrawer (true);
  187881. }
  187882. #endif
  187883. #if JUCE_USE_CDBURNER
  187884. static IDiscRecorder* enumCDBurners (StringArray* list, int indexToOpen, IDiscMaster** master)
  187885. {
  187886. CoInitialize (0);
  187887. IDiscMaster* dm;
  187888. IDiscRecorder* result = 0;
  187889. if (SUCCEEDED (CoCreateInstance (CLSID_MSDiscMasterObj, 0,
  187890. CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER,
  187891. IID_IDiscMaster,
  187892. (void**) &dm)))
  187893. {
  187894. if (SUCCEEDED (dm->Open()))
  187895. {
  187896. IEnumDiscRecorders* drEnum = 0;
  187897. if (SUCCEEDED (dm->EnumDiscRecorders (&drEnum)))
  187898. {
  187899. IDiscRecorder* dr = 0;
  187900. DWORD dummy;
  187901. int index = 0;
  187902. while (drEnum->Next (1, &dr, &dummy) == S_OK)
  187903. {
  187904. if (indexToOpen == index)
  187905. {
  187906. result = dr;
  187907. break;
  187908. }
  187909. else if (list != 0)
  187910. {
  187911. BSTR path;
  187912. if (SUCCEEDED (dr->GetPath (&path)))
  187913. list->add ((const WCHAR*) path);
  187914. }
  187915. ++index;
  187916. dr->Release();
  187917. }
  187918. drEnum->Release();
  187919. }
  187920. if (master == 0)
  187921. dm->Close();
  187922. }
  187923. if (master != 0)
  187924. *master = dm;
  187925. else
  187926. dm->Release();
  187927. }
  187928. return result;
  187929. }
  187930. const StringArray AudioCDBurner::findAvailableDevices()
  187931. {
  187932. StringArray devs;
  187933. enumCDBurners (&devs, -1, 0);
  187934. return devs;
  187935. }
  187936. AudioCDBurner* AudioCDBurner::openDevice (const int deviceIndex)
  187937. {
  187938. AudioCDBurner* b = new AudioCDBurner (deviceIndex);
  187939. if (b->internal == 0)
  187940. deleteAndZero (b);
  187941. return b;
  187942. }
  187943. class CDBurnerInfo : public IDiscMasterProgressEvents
  187944. {
  187945. public:
  187946. CDBurnerInfo()
  187947. : refCount (1),
  187948. progress (0),
  187949. shouldCancel (false),
  187950. listener (0)
  187951. {
  187952. }
  187953. ~CDBurnerInfo()
  187954. {
  187955. }
  187956. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  187957. {
  187958. if (result == 0)
  187959. return E_POINTER;
  187960. if (id == IID_IUnknown || id == IID_IDiscMasterProgressEvents)
  187961. {
  187962. AddRef();
  187963. *result = this;
  187964. return S_OK;
  187965. }
  187966. *result = 0;
  187967. return E_NOINTERFACE;
  187968. }
  187969. ULONG __stdcall AddRef() { return ++refCount; }
  187970. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  187971. HRESULT __stdcall QueryCancel (boolean* pbCancel)
  187972. {
  187973. if (listener != 0 && ! shouldCancel)
  187974. shouldCancel = listener->audioCDBurnProgress (progress);
  187975. *pbCancel = shouldCancel;
  187976. return S_OK;
  187977. }
  187978. HRESULT __stdcall NotifyBlockProgress (long nCompleted, long nTotal)
  187979. {
  187980. progress = nCompleted / (float) nTotal;
  187981. shouldCancel = listener != 0 && listener->audioCDBurnProgress (progress);
  187982. return E_NOTIMPL;
  187983. }
  187984. HRESULT __stdcall NotifyPnPActivity (void) { return E_NOTIMPL; }
  187985. HRESULT __stdcall NotifyAddProgress (long /*nCompletedSteps*/, long /*nTotalSteps*/) { return E_NOTIMPL; }
  187986. HRESULT __stdcall NotifyTrackProgress (long /*nCurrentTrack*/, long /*nTotalTracks*/) { return E_NOTIMPL; }
  187987. HRESULT __stdcall NotifyPreparingBurn (long /*nEstimatedSeconds*/) { return E_NOTIMPL; }
  187988. HRESULT __stdcall NotifyClosingDisc (long /*nEstimatedSeconds*/) { return E_NOTIMPL; }
  187989. HRESULT __stdcall NotifyBurnComplete (HRESULT /*status*/) { return E_NOTIMPL; }
  187990. HRESULT __stdcall NotifyEraseComplete (HRESULT /*status*/) { return E_NOTIMPL; }
  187991. IDiscMaster* discMaster;
  187992. IDiscRecorder* discRecorder;
  187993. IRedbookDiscMaster* redbook;
  187994. AudioCDBurner::BurnProgressListener* listener;
  187995. float progress;
  187996. bool shouldCancel;
  187997. private:
  187998. int refCount;
  187999. };
  188000. AudioCDBurner::AudioCDBurner (const int deviceIndex)
  188001. : internal (0)
  188002. {
  188003. IDiscMaster* discMaster;
  188004. IDiscRecorder* dr = enumCDBurners (0, deviceIndex, &discMaster);
  188005. if (dr != 0)
  188006. {
  188007. IRedbookDiscMaster* redbook;
  188008. HRESULT hr = discMaster->SetActiveDiscMasterFormat (IID_IRedbookDiscMaster, (void**) &redbook);
  188009. hr = discMaster->SetActiveDiscRecorder (dr);
  188010. CDBurnerInfo* const info = new CDBurnerInfo();
  188011. internal = info;
  188012. info->discMaster = discMaster;
  188013. info->discRecorder = dr;
  188014. info->redbook = redbook;
  188015. }
  188016. }
  188017. AudioCDBurner::~AudioCDBurner()
  188018. {
  188019. CDBurnerInfo* const info = (CDBurnerInfo*) internal;
  188020. if (info != 0)
  188021. {
  188022. info->discRecorder->Close();
  188023. info->redbook->Release();
  188024. info->discRecorder->Release();
  188025. info->discMaster->Release();
  188026. info->Release();
  188027. }
  188028. }
  188029. bool AudioCDBurner::isDiskPresent() const
  188030. {
  188031. CDBurnerInfo* const info = (CDBurnerInfo*) internal;
  188032. HRESULT hr = info->discRecorder->OpenExclusive();
  188033. long type, flags;
  188034. hr = info->discRecorder->QueryMediaType (&type, &flags);
  188035. info->discRecorder->Close();
  188036. return hr == S_OK && type != 0 && (flags & MEDIA_WRITABLE) != 0;
  188037. }
  188038. int AudioCDBurner::getNumAvailableAudioBlocks() const
  188039. {
  188040. CDBurnerInfo* const info = (CDBurnerInfo*) internal;
  188041. long blocksFree = 0;
  188042. info->redbook->GetAvailableAudioTrackBlocks (&blocksFree);
  188043. return blocksFree;
  188044. }
  188045. const String AudioCDBurner::burn (AudioCDBurner::BurnProgressListener* listener,
  188046. const bool ejectDiscAfterwards,
  188047. const bool performFakeBurnForTesting)
  188048. {
  188049. CDBurnerInfo* const info = (CDBurnerInfo*) internal;
  188050. info->listener = listener;
  188051. info->progress = 0;
  188052. info->shouldCancel = false;
  188053. UINT_PTR cookie;
  188054. HRESULT hr = info->discMaster->ProgressAdvise (info, &cookie);
  188055. hr = info->discMaster->RecordDisc (performFakeBurnForTesting,
  188056. ejectDiscAfterwards);
  188057. String error;
  188058. if (hr != S_OK)
  188059. {
  188060. const char* e = "Couldn't open or write to the CD device";
  188061. if (hr == IMAPI_E_USERABORT)
  188062. e = "User cancelled the write operation";
  188063. else if (hr == IMAPI_E_MEDIUM_NOTPRESENT || hr == IMAPI_E_TRACKOPEN)
  188064. e = "No Disk present";
  188065. error = e;
  188066. }
  188067. info->discMaster->ProgressUnadvise (cookie);
  188068. info->listener = 0;
  188069. return error;
  188070. }
  188071. bool AudioCDBurner::addAudioTrack (AudioSource* source, int numSamples)
  188072. {
  188073. if (source == 0)
  188074. return false;
  188075. CDBurnerInfo* const info = (CDBurnerInfo*) internal;
  188076. long bytesPerBlock;
  188077. HRESULT hr = info->redbook->GetAudioBlockSize (&bytesPerBlock);
  188078. const int samplesPerBlock = bytesPerBlock / 4;
  188079. bool ok = true;
  188080. hr = info->redbook->CreateAudioTrack ((long) numSamples / (bytesPerBlock * 4));
  188081. HeapBlock <byte> buffer (bytesPerBlock);
  188082. AudioSampleBuffer sourceBuffer (2, samplesPerBlock);
  188083. int samplesDone = 0;
  188084. source->prepareToPlay (samplesPerBlock, 44100.0);
  188085. while (ok)
  188086. {
  188087. {
  188088. AudioSourceChannelInfo info;
  188089. info.buffer = &sourceBuffer;
  188090. info.numSamples = samplesPerBlock;
  188091. info.startSample = 0;
  188092. sourceBuffer.clear();
  188093. source->getNextAudioBlock (info);
  188094. }
  188095. zeromem (buffer, bytesPerBlock);
  188096. AudioDataConverters::convertFloatToInt16LE (sourceBuffer.getSampleData (0, 0),
  188097. buffer, samplesPerBlock, 4);
  188098. AudioDataConverters::convertFloatToInt16LE (sourceBuffer.getSampleData (1, 0),
  188099. buffer + 2, samplesPerBlock, 4);
  188100. hr = info->redbook->AddAudioTrackBlocks (buffer, bytesPerBlock);
  188101. if (hr != S_OK)
  188102. ok = false;
  188103. samplesDone += samplesPerBlock;
  188104. if (samplesDone >= numSamples)
  188105. break;
  188106. }
  188107. hr = info->redbook->CloseAudioTrack();
  188108. delete source;
  188109. return ok && hr == S_OK;
  188110. }
  188111. #endif
  188112. #endif
  188113. /*** End of inlined file: juce_win32_AudioCDReader.cpp ***/
  188114. /*** Start of inlined file: juce_win32_Midi.cpp ***/
  188115. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  188116. // compiled on its own).
  188117. #if JUCE_INCLUDED_FILE
  188118. static const int midiBufferSize = 1024 * 10;
  188119. static const int numInHeaders = 32;
  188120. static const int inBufferSize = 256;
  188121. static Array <void*, CriticalSection> activeMidiThreads;
  188122. using ::free;
  188123. class MidiInThread : public Thread
  188124. {
  188125. public:
  188126. MidiInThread (MidiInput* const input_,
  188127. MidiInputCallback* const callback_)
  188128. : Thread ("Juce Midi"),
  188129. hIn (0),
  188130. input (input_),
  188131. callback (callback_),
  188132. isStarted (false),
  188133. startTime (0),
  188134. pendingLength(0)
  188135. {
  188136. for (int i = numInHeaders; --i >= 0;)
  188137. {
  188138. zeromem (&hdr[i], sizeof (MIDIHDR));
  188139. hdr[i].lpData = inData[i];
  188140. hdr[i].dwBufferLength = inBufferSize;
  188141. }
  188142. };
  188143. ~MidiInThread()
  188144. {
  188145. stop();
  188146. if (hIn != 0)
  188147. {
  188148. int count = 5;
  188149. while (--count >= 0)
  188150. {
  188151. if (midiInClose (hIn) == MMSYSERR_NOERROR)
  188152. break;
  188153. Sleep (20);
  188154. }
  188155. }
  188156. }
  188157. void handle (const uint32 message, const uint32 timeStamp) throw()
  188158. {
  188159. const int byte = message & 0xff;
  188160. if (byte < 0x80)
  188161. return;
  188162. const int numBytes = MidiMessage::getMessageLengthFromFirstByte ((uint8) byte);
  188163. const double time = timeStampToTime (timeStamp);
  188164. lock.enter();
  188165. if (pendingLength < midiBufferSize - 12)
  188166. {
  188167. char* const p = pending + pendingLength;
  188168. *(double*) p = time;
  188169. *(uint32*) (p + 8) = numBytes;
  188170. *(uint32*) (p + 12) = message;
  188171. pendingLength += 12 + numBytes;
  188172. }
  188173. else
  188174. {
  188175. jassertfalse // midi buffer overflow! You might need to increase the size..
  188176. }
  188177. lock.exit();
  188178. notify();
  188179. }
  188180. void handleSysEx (MIDIHDR* const hdr, const uint32 timeStamp) throw()
  188181. {
  188182. const int num = hdr->dwBytesRecorded;
  188183. if (num > 0)
  188184. {
  188185. const double time = timeStampToTime (timeStamp);
  188186. lock.enter();
  188187. if (pendingLength < midiBufferSize - (8 + num))
  188188. {
  188189. char* const p = pending + pendingLength;
  188190. *(double*) p = time;
  188191. *(uint32*) (p + 8) = num;
  188192. memcpy (p + 12, hdr->lpData, num);
  188193. pendingLength += 12 + num;
  188194. }
  188195. else
  188196. {
  188197. jassertfalse // midi buffer overflow! You might need to increase the size..
  188198. }
  188199. lock.exit();
  188200. notify();
  188201. }
  188202. }
  188203. void writeBlock (const int i) throw()
  188204. {
  188205. hdr[i].dwBytesRecorded = 0;
  188206. MMRESULT res = midiInPrepareHeader (hIn, &hdr[i], sizeof (MIDIHDR));
  188207. jassert (res == MMSYSERR_NOERROR);
  188208. res = midiInAddBuffer (hIn, &hdr[i], sizeof (MIDIHDR));
  188209. jassert (res == MMSYSERR_NOERROR);
  188210. }
  188211. void run()
  188212. {
  188213. MemoryBlock pendingCopy (64);
  188214. while (! threadShouldExit())
  188215. {
  188216. for (int i = 0; i < numInHeaders; ++i)
  188217. {
  188218. if ((hdr[i].dwFlags & WHDR_DONE) != 0)
  188219. {
  188220. MMRESULT res = midiInUnprepareHeader (hIn, &hdr[i], sizeof (MIDIHDR));
  188221. (void) res;
  188222. jassert (res == MMSYSERR_NOERROR);
  188223. writeBlock (i);
  188224. }
  188225. }
  188226. lock.enter();
  188227. int len = pendingLength;
  188228. if (len > 0)
  188229. {
  188230. pendingCopy.ensureSize (len);
  188231. pendingCopy.copyFrom (pending, 0, len);
  188232. pendingLength = 0;
  188233. }
  188234. lock.exit();
  188235. //xxx needs to figure out if blocks are broken up or not
  188236. if (len == 0)
  188237. {
  188238. wait (500);
  188239. }
  188240. else
  188241. {
  188242. const char* p = (const char*) pendingCopy.getData();
  188243. while (len > 0)
  188244. {
  188245. const double time = *(const double*) p;
  188246. const int messageLen = *(const int*) (p + 8);
  188247. const MidiMessage message ((const uint8*) (p + 12), messageLen, time);
  188248. callback->handleIncomingMidiMessage (input, message);
  188249. p += 12 + messageLen;
  188250. len -= 12 + messageLen;
  188251. }
  188252. }
  188253. }
  188254. }
  188255. void start() throw()
  188256. {
  188257. jassert (hIn != 0);
  188258. if (hIn != 0 && ! isStarted)
  188259. {
  188260. stop();
  188261. activeMidiThreads.addIfNotAlreadyThere (this);
  188262. int i;
  188263. for (i = 0; i < numInHeaders; ++i)
  188264. writeBlock (i);
  188265. startTime = Time::getMillisecondCounter();
  188266. MMRESULT res = midiInStart (hIn);
  188267. jassert (res == MMSYSERR_NOERROR);
  188268. if (res == MMSYSERR_NOERROR)
  188269. {
  188270. isStarted = true;
  188271. pendingLength = 0;
  188272. startThread (6);
  188273. }
  188274. }
  188275. }
  188276. void stop() throw()
  188277. {
  188278. if (isStarted)
  188279. {
  188280. stopThread (5000);
  188281. midiInReset (hIn);
  188282. midiInStop (hIn);
  188283. activeMidiThreads.removeValue (this);
  188284. lock.enter();
  188285. lock.exit();
  188286. for (int i = numInHeaders; --i >= 0;)
  188287. {
  188288. if ((hdr[i].dwFlags & WHDR_DONE) != 0)
  188289. {
  188290. int c = 10;
  188291. while (--c >= 0 && midiInUnprepareHeader (hIn, &hdr[i], sizeof (MIDIHDR)) == MIDIERR_STILLPLAYING)
  188292. Sleep (20);
  188293. jassert (c >= 0);
  188294. }
  188295. }
  188296. isStarted = false;
  188297. pendingLength = 0;
  188298. }
  188299. }
  188300. juce_UseDebuggingNewOperator
  188301. HMIDIIN hIn;
  188302. private:
  188303. MidiInput* input;
  188304. MidiInputCallback* callback;
  188305. bool isStarted;
  188306. uint32 startTime;
  188307. CriticalSection lock;
  188308. MIDIHDR hdr [numInHeaders];
  188309. char inData [numInHeaders] [inBufferSize];
  188310. int pendingLength;
  188311. char pending [midiBufferSize];
  188312. double timeStampToTime (uint32 timeStamp) throw()
  188313. {
  188314. timeStamp += startTime;
  188315. const uint32 now = Time::getMillisecondCounter();
  188316. if (timeStamp > now)
  188317. {
  188318. if (timeStamp > now + 2)
  188319. --startTime;
  188320. timeStamp = now;
  188321. }
  188322. return 0.001 * timeStamp;
  188323. }
  188324. MidiInThread (const MidiInThread&);
  188325. const MidiInThread& operator= (const MidiInThread&);
  188326. };
  188327. static void CALLBACK midiInCallback (HMIDIIN,
  188328. UINT uMsg,
  188329. DWORD_PTR dwInstance,
  188330. DWORD_PTR midiMessage,
  188331. DWORD_PTR timeStamp)
  188332. {
  188333. MidiInThread* const thread = (MidiInThread*) dwInstance;
  188334. if (thread != 0 && activeMidiThreads.contains (thread))
  188335. {
  188336. if (uMsg == MIM_DATA)
  188337. thread->handle ((uint32) midiMessage, (uint32) timeStamp);
  188338. else if (uMsg == MIM_LONGDATA)
  188339. thread->handleSysEx ((MIDIHDR*) midiMessage, (uint32) timeStamp);
  188340. }
  188341. }
  188342. const StringArray MidiInput::getDevices()
  188343. {
  188344. StringArray s;
  188345. const int num = midiInGetNumDevs();
  188346. for (int i = 0; i < num; ++i)
  188347. {
  188348. MIDIINCAPS mc;
  188349. zerostruct (mc);
  188350. if (midiInGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  188351. s.add (String (mc.szPname, sizeof (mc.szPname)));
  188352. }
  188353. return s;
  188354. }
  188355. int MidiInput::getDefaultDeviceIndex()
  188356. {
  188357. return 0;
  188358. }
  188359. MidiInput* MidiInput::openDevice (const int index, MidiInputCallback* const callback)
  188360. {
  188361. if (callback == 0)
  188362. return 0;
  188363. UINT deviceId = MIDI_MAPPER;
  188364. int n = 0;
  188365. String name;
  188366. const int num = midiInGetNumDevs();
  188367. for (int i = 0; i < num; ++i)
  188368. {
  188369. MIDIINCAPS mc;
  188370. zerostruct (mc);
  188371. if (midiInGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  188372. {
  188373. if (index == n)
  188374. {
  188375. deviceId = i;
  188376. name = String (mc.szPname, sizeof (mc.szPname));
  188377. break;
  188378. }
  188379. ++n;
  188380. }
  188381. }
  188382. ScopedPointer <MidiInput> in (new MidiInput (name));
  188383. ScopedPointer <MidiInThread> thread (new MidiInThread (in, callback));
  188384. HMIDIIN h;
  188385. HRESULT err = midiInOpen (&h, deviceId,
  188386. (DWORD_PTR) &midiInCallback,
  188387. (DWORD_PTR) (MidiInThread*) thread,
  188388. CALLBACK_FUNCTION);
  188389. if (err == MMSYSERR_NOERROR)
  188390. {
  188391. thread->hIn = h;
  188392. in->internal = (void*) thread.release();
  188393. return in.release();
  188394. }
  188395. return 0;
  188396. }
  188397. MidiInput::MidiInput (const String& name_)
  188398. : name (name_),
  188399. internal (0)
  188400. {
  188401. }
  188402. MidiInput::~MidiInput()
  188403. {
  188404. if (internal != 0)
  188405. {
  188406. MidiInThread* const thread = (MidiInThread*) internal;
  188407. delete thread;
  188408. }
  188409. }
  188410. void MidiInput::start()
  188411. {
  188412. ((MidiInThread*) internal)->start();
  188413. }
  188414. void MidiInput::stop()
  188415. {
  188416. ((MidiInThread*) internal)->stop();
  188417. }
  188418. struct MidiOutHandle
  188419. {
  188420. int refCount;
  188421. UINT deviceId;
  188422. HMIDIOUT handle;
  188423. juce_UseDebuggingNewOperator
  188424. };
  188425. static Array <MidiOutHandle*> midiOutputHandles;
  188426. const StringArray MidiOutput::getDevices()
  188427. {
  188428. StringArray s;
  188429. const int num = midiOutGetNumDevs();
  188430. for (int i = 0; i < num; ++i)
  188431. {
  188432. MIDIOUTCAPS mc;
  188433. zerostruct (mc);
  188434. if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  188435. s.add (String (mc.szPname, sizeof (mc.szPname)));
  188436. }
  188437. return s;
  188438. }
  188439. int MidiOutput::getDefaultDeviceIndex()
  188440. {
  188441. const int num = midiOutGetNumDevs();
  188442. int n = 0;
  188443. for (int i = 0; i < num; ++i)
  188444. {
  188445. MIDIOUTCAPS mc;
  188446. zerostruct (mc);
  188447. if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  188448. {
  188449. if ((mc.wTechnology & MOD_MAPPER) != 0)
  188450. return n;
  188451. ++n;
  188452. }
  188453. }
  188454. return 0;
  188455. }
  188456. MidiOutput* MidiOutput::openDevice (int index)
  188457. {
  188458. UINT deviceId = MIDI_MAPPER;
  188459. const int num = midiOutGetNumDevs();
  188460. int i, n = 0;
  188461. for (i = 0; i < num; ++i)
  188462. {
  188463. MIDIOUTCAPS mc;
  188464. zerostruct (mc);
  188465. if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  188466. {
  188467. // use the microsoft sw synth as a default - best not to allow deviceId
  188468. // to be MIDI_MAPPER, or else device sharing breaks
  188469. if (String (mc.szPname, sizeof (mc.szPname)).containsIgnoreCase (T("microsoft")))
  188470. deviceId = i;
  188471. if (index == n)
  188472. {
  188473. deviceId = i;
  188474. break;
  188475. }
  188476. ++n;
  188477. }
  188478. }
  188479. for (i = midiOutputHandles.size(); --i >= 0;)
  188480. {
  188481. MidiOutHandle* const han = midiOutputHandles.getUnchecked(i);
  188482. if (han != 0 && han->deviceId == deviceId)
  188483. {
  188484. han->refCount++;
  188485. MidiOutput* const out = new MidiOutput();
  188486. out->internal = (void*) han;
  188487. return out;
  188488. }
  188489. }
  188490. for (i = 4; --i >= 0;)
  188491. {
  188492. HMIDIOUT h = 0;
  188493. MMRESULT res = midiOutOpen (&h, deviceId, 0, 0, CALLBACK_NULL);
  188494. if (res == MMSYSERR_NOERROR)
  188495. {
  188496. MidiOutHandle* const han = new MidiOutHandle();
  188497. han->deviceId = deviceId;
  188498. han->refCount = 1;
  188499. han->handle = h;
  188500. midiOutputHandles.add (han);
  188501. MidiOutput* const out = new MidiOutput();
  188502. out->internal = (void*) han;
  188503. return out;
  188504. }
  188505. else if (res == MMSYSERR_ALLOCATED)
  188506. {
  188507. Sleep (100);
  188508. }
  188509. else
  188510. {
  188511. break;
  188512. }
  188513. }
  188514. return 0;
  188515. }
  188516. MidiOutput::~MidiOutput()
  188517. {
  188518. MidiOutHandle* const h = (MidiOutHandle*) internal;
  188519. if (midiOutputHandles.contains (h) && --(h->refCount) == 0)
  188520. {
  188521. midiOutClose (h->handle);
  188522. midiOutputHandles.removeValue (h);
  188523. delete h;
  188524. }
  188525. }
  188526. void MidiOutput::reset()
  188527. {
  188528. const MidiOutHandle* const h = (MidiOutHandle*) internal;
  188529. midiOutReset (h->handle);
  188530. }
  188531. bool MidiOutput::getVolume (float& leftVol,
  188532. float& rightVol)
  188533. {
  188534. const MidiOutHandle* const handle = (const MidiOutHandle*) internal;
  188535. DWORD n;
  188536. if (midiOutGetVolume (handle->handle, &n) == MMSYSERR_NOERROR)
  188537. {
  188538. const unsigned short* const nn = (const unsigned short*) &n;
  188539. rightVol = nn[0] / (float) 0xffff;
  188540. leftVol = nn[1] / (float) 0xffff;
  188541. return true;
  188542. }
  188543. else
  188544. {
  188545. rightVol = leftVol = 1.0f;
  188546. return false;
  188547. }
  188548. }
  188549. void MidiOutput::setVolume (float leftVol,
  188550. float rightVol)
  188551. {
  188552. const MidiOutHandle* const handle = (MidiOutHandle*) internal;
  188553. DWORD n;
  188554. unsigned short* const nn = (unsigned short*) &n;
  188555. nn[0] = (unsigned short) jlimit (0, 0xffff, (int)(rightVol * 0xffff));
  188556. nn[1] = (unsigned short) jlimit (0, 0xffff, (int)(leftVol * 0xffff));
  188557. midiOutSetVolume (handle->handle, n);
  188558. }
  188559. void MidiOutput::sendMessageNow (const MidiMessage& message)
  188560. {
  188561. const MidiOutHandle* const handle = (const MidiOutHandle*) internal;
  188562. if (message.getRawDataSize() > 3
  188563. || message.isSysEx())
  188564. {
  188565. MIDIHDR h;
  188566. zerostruct (h);
  188567. h.lpData = (char*) message.getRawData();
  188568. h.dwBufferLength = message.getRawDataSize();
  188569. h.dwBytesRecorded = message.getRawDataSize();
  188570. if (midiOutPrepareHeader (handle->handle, &h, sizeof (MIDIHDR)) == MMSYSERR_NOERROR)
  188571. {
  188572. MMRESULT res = midiOutLongMsg (handle->handle, &h, sizeof (MIDIHDR));
  188573. if (res == MMSYSERR_NOERROR)
  188574. {
  188575. while ((h.dwFlags & MHDR_DONE) == 0)
  188576. Sleep (1);
  188577. int count = 500; // 1 sec timeout
  188578. while (--count >= 0)
  188579. {
  188580. res = midiOutUnprepareHeader (handle->handle, &h, sizeof (MIDIHDR));
  188581. if (res == MIDIERR_STILLPLAYING)
  188582. Sleep (2);
  188583. else
  188584. break;
  188585. }
  188586. }
  188587. }
  188588. }
  188589. else
  188590. {
  188591. midiOutShortMsg (handle->handle,
  188592. *(unsigned int*) message.getRawData());
  188593. }
  188594. }
  188595. #endif
  188596. /*** End of inlined file: juce_win32_Midi.cpp ***/
  188597. /*** Start of inlined file: juce_win32_ASIO.cpp ***/
  188598. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  188599. // compiled on its own).
  188600. #if JUCE_INCLUDED_FILE && JUCE_ASIO
  188601. #undef WINDOWS
  188602. // #define ASIO_DEBUGGING
  188603. #ifdef ASIO_DEBUGGING
  188604. #define log(a) { Logger::writeToLog (a); DBG (a) }
  188605. #else
  188606. #define log(a) {}
  188607. #endif
  188608. #ifdef ASIO_DEBUGGING
  188609. static void logError (const String& context, long error)
  188610. {
  188611. String err ("unknown error");
  188612. if (error == ASE_NotPresent)
  188613. err = "Not Present";
  188614. else if (error == ASE_HWMalfunction)
  188615. err = "Hardware Malfunction";
  188616. else if (error == ASE_InvalidParameter)
  188617. err = "Invalid Parameter";
  188618. else if (error == ASE_InvalidMode)
  188619. err = "Invalid Mode";
  188620. else if (error == ASE_SPNotAdvancing)
  188621. err = "Sample position not advancing";
  188622. else if (error == ASE_NoClock)
  188623. err = "No Clock";
  188624. else if (error == ASE_NoMemory)
  188625. err = "Out of memory";
  188626. log (T("!!error: ") + context + T(" - ") + err);
  188627. }
  188628. #else
  188629. #define logError(a, b) {}
  188630. #endif
  188631. class ASIOAudioIODevice;
  188632. static ASIOAudioIODevice* volatile currentASIODev[3] = { 0, 0, 0 };
  188633. static const int maxASIOChannels = 160;
  188634. class JUCE_API ASIOAudioIODevice : public AudioIODevice,
  188635. private Timer
  188636. {
  188637. public:
  188638. Component ourWindow;
  188639. ASIOAudioIODevice (const String& name_, const CLSID classId_, const int slotNumber,
  188640. const String& optionalDllForDirectLoading_)
  188641. : AudioIODevice (name_, T("ASIO")),
  188642. asioObject (0),
  188643. classId (classId_),
  188644. optionalDllForDirectLoading (optionalDllForDirectLoading_),
  188645. currentBitDepth (16),
  188646. currentSampleRate (0),
  188647. isOpen_ (false),
  188648. isStarted (false),
  188649. postOutput (true),
  188650. insideControlPanelModalLoop (false),
  188651. shouldUsePreferredSize (false)
  188652. {
  188653. name = name_;
  188654. ourWindow.addToDesktop (0);
  188655. windowHandle = ourWindow.getWindowHandle();
  188656. jassert (currentASIODev [slotNumber] == 0);
  188657. currentASIODev [slotNumber] = this;
  188658. openDevice();
  188659. }
  188660. ~ASIOAudioIODevice()
  188661. {
  188662. for (int i = 0; i < numElementsInArray (currentASIODev); ++i)
  188663. if (currentASIODev[i] == this)
  188664. currentASIODev[i] = 0;
  188665. close();
  188666. log ("ASIO - exiting");
  188667. removeCurrentDriver();
  188668. }
  188669. void updateSampleRates()
  188670. {
  188671. // find a list of sample rates..
  188672. const double possibleSampleRates[] = { 44100.0, 48000.0, 88200.0, 96000.0, 176400.0, 192000.0 };
  188673. sampleRates.clear();
  188674. if (asioObject != 0)
  188675. {
  188676. for (int index = 0; index < numElementsInArray (possibleSampleRates); ++index)
  188677. {
  188678. const long err = asioObject->canSampleRate (possibleSampleRates[index]);
  188679. if (err == 0)
  188680. {
  188681. sampleRates.add ((int) possibleSampleRates[index]);
  188682. log (T("rate: ") + String ((int) possibleSampleRates[index]));
  188683. }
  188684. else if (err != ASE_NoClock)
  188685. {
  188686. logError (T("CanSampleRate"), err);
  188687. }
  188688. }
  188689. if (sampleRates.size() == 0)
  188690. {
  188691. double cr = 0;
  188692. const long err = asioObject->getSampleRate (&cr);
  188693. log (T("No sample rates supported - current rate: ") + String ((int) cr));
  188694. if (err == 0)
  188695. sampleRates.add ((int) cr);
  188696. }
  188697. }
  188698. }
  188699. const StringArray getOutputChannelNames()
  188700. {
  188701. return outputChannelNames;
  188702. }
  188703. const StringArray getInputChannelNames()
  188704. {
  188705. return inputChannelNames;
  188706. }
  188707. int getNumSampleRates()
  188708. {
  188709. return sampleRates.size();
  188710. }
  188711. double getSampleRate (int index)
  188712. {
  188713. return sampleRates [index];
  188714. }
  188715. int getNumBufferSizesAvailable()
  188716. {
  188717. return bufferSizes.size();
  188718. }
  188719. int getBufferSizeSamples (int index)
  188720. {
  188721. return bufferSizes [index];
  188722. }
  188723. int getDefaultBufferSize()
  188724. {
  188725. return preferredSize;
  188726. }
  188727. const String open (const BitArray& inputChannels,
  188728. const BitArray& outputChannels,
  188729. double sr,
  188730. int bufferSizeSamples)
  188731. {
  188732. close();
  188733. currentCallback = 0;
  188734. if (bufferSizeSamples <= 0)
  188735. shouldUsePreferredSize = true;
  188736. if (asioObject == 0 || ! isASIOOpen)
  188737. {
  188738. log ("Warning: device not open");
  188739. const String err (openDevice());
  188740. if (asioObject == 0 || ! isASIOOpen)
  188741. return err;
  188742. }
  188743. isStarted = false;
  188744. bufferIndex = -1;
  188745. long err = 0;
  188746. long newPreferredSize = 0;
  188747. // if the preferred size has just changed, assume it's a control panel thing and use it as the new value.
  188748. minSize = 0;
  188749. maxSize = 0;
  188750. newPreferredSize = 0;
  188751. granularity = 0;
  188752. if (asioObject->getBufferSize (&minSize, &maxSize, &newPreferredSize, &granularity) == 0)
  188753. {
  188754. if (preferredSize != 0 && newPreferredSize != 0 && newPreferredSize != preferredSize)
  188755. shouldUsePreferredSize = true;
  188756. preferredSize = newPreferredSize;
  188757. }
  188758. // unfortunate workaround for certain manufacturers whose drivers crash horribly if you make
  188759. // dynamic changes to the buffer size...
  188760. shouldUsePreferredSize = shouldUsePreferredSize
  188761. || getName().containsIgnoreCase (T("Digidesign"));
  188762. if (shouldUsePreferredSize)
  188763. {
  188764. log ("Using preferred size for buffer..");
  188765. if ((err = asioObject->getBufferSize (&minSize, &maxSize, &preferredSize, &granularity)) == 0)
  188766. {
  188767. bufferSizeSamples = preferredSize;
  188768. }
  188769. else
  188770. {
  188771. bufferSizeSamples = 1024;
  188772. logError ("GetBufferSize1", err);
  188773. }
  188774. shouldUsePreferredSize = false;
  188775. }
  188776. int sampleRate = roundDoubleToInt (sr);
  188777. currentSampleRate = sampleRate;
  188778. currentBlockSizeSamples = bufferSizeSamples;
  188779. currentChansOut.clear();
  188780. currentChansIn.clear();
  188781. zeromem (inBuffers, sizeof (inBuffers));
  188782. zeromem (outBuffers, sizeof (outBuffers));
  188783. updateSampleRates();
  188784. if (sampleRate == 0 || (sampleRates.size() > 0 && ! sampleRates.contains (sampleRate)))
  188785. sampleRate = sampleRates[0];
  188786. jassert (sampleRate != 0);
  188787. if (sampleRate == 0)
  188788. sampleRate = 44100;
  188789. long numSources = 32;
  188790. ASIOClockSource clocks[32];
  188791. zeromem (clocks, sizeof (clocks));
  188792. asioObject->getClockSources (clocks, &numSources);
  188793. bool isSourceSet = false;
  188794. // careful not to remove this loop because it does more than just logging!
  188795. int i;
  188796. for (i = 0; i < numSources; ++i)
  188797. {
  188798. String s ("clock: ");
  188799. s += clocks[i].name;
  188800. if (clocks[i].isCurrentSource)
  188801. {
  188802. isSourceSet = true;
  188803. s << " (cur)";
  188804. }
  188805. log (s);
  188806. }
  188807. if (numSources > 1 && ! isSourceSet)
  188808. {
  188809. log ("setting clock source");
  188810. asioObject->setClockSource (clocks[0].index);
  188811. Thread::sleep (20);
  188812. }
  188813. else
  188814. {
  188815. if (numSources == 0)
  188816. {
  188817. log ("ASIO - no clock sources!");
  188818. }
  188819. }
  188820. double cr = 0;
  188821. err = asioObject->getSampleRate (&cr);
  188822. if (err == 0)
  188823. {
  188824. currentSampleRate = cr;
  188825. }
  188826. else
  188827. {
  188828. logError ("GetSampleRate", err);
  188829. currentSampleRate = 0;
  188830. }
  188831. error = String::empty;
  188832. needToReset = false;
  188833. isReSync = false;
  188834. err = 0;
  188835. bool buffersCreated = false;
  188836. if (currentSampleRate != sampleRate)
  188837. {
  188838. log (T("ASIO samplerate: ") + String (currentSampleRate) + T(" to ") + String (sampleRate));
  188839. err = asioObject->setSampleRate (sampleRate);
  188840. if (err == ASE_NoClock && numSources > 0)
  188841. {
  188842. log ("trying to set a clock source..");
  188843. Thread::sleep (10);
  188844. err = asioObject->setClockSource (clocks[0].index);
  188845. if (err != 0)
  188846. {
  188847. logError ("SetClock", err);
  188848. }
  188849. Thread::sleep (10);
  188850. err = asioObject->setSampleRate (sampleRate);
  188851. }
  188852. }
  188853. if (err == 0)
  188854. {
  188855. currentSampleRate = sampleRate;
  188856. if (needToReset)
  188857. {
  188858. if (isReSync)
  188859. {
  188860. log ("Resync request");
  188861. }
  188862. log ("! Resetting ASIO after sample rate change");
  188863. removeCurrentDriver();
  188864. loadDriver();
  188865. const String error (initDriver());
  188866. if (error.isNotEmpty())
  188867. {
  188868. log (T("ASIOInit: ") + error);
  188869. }
  188870. needToReset = false;
  188871. isReSync = false;
  188872. }
  188873. numActiveInputChans = 0;
  188874. numActiveOutputChans = 0;
  188875. ASIOBufferInfo* info = bufferInfos;
  188876. int i;
  188877. for (i = 0; i < totalNumInputChans; ++i)
  188878. {
  188879. if (inputChannels[i])
  188880. {
  188881. currentChansIn.setBit (i);
  188882. info->isInput = 1;
  188883. info->channelNum = i;
  188884. info->buffers[0] = info->buffers[1] = 0;
  188885. ++info;
  188886. ++numActiveInputChans;
  188887. }
  188888. }
  188889. for (i = 0; i < totalNumOutputChans; ++i)
  188890. {
  188891. if (outputChannels[i])
  188892. {
  188893. currentChansOut.setBit (i);
  188894. info->isInput = 0;
  188895. info->channelNum = i;
  188896. info->buffers[0] = info->buffers[1] = 0;
  188897. ++info;
  188898. ++numActiveOutputChans;
  188899. }
  188900. }
  188901. const int totalBuffers = numActiveInputChans + numActiveOutputChans;
  188902. callbacks.sampleRateDidChange = &sampleRateChangedCallback;
  188903. if (currentASIODev[0] == this)
  188904. {
  188905. callbacks.bufferSwitch = &bufferSwitchCallback0;
  188906. callbacks.asioMessage = &asioMessagesCallback0;
  188907. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback0;
  188908. }
  188909. else if (currentASIODev[1] == this)
  188910. {
  188911. callbacks.bufferSwitch = &bufferSwitchCallback1;
  188912. callbacks.asioMessage = &asioMessagesCallback1;
  188913. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback1;
  188914. }
  188915. else if (currentASIODev[2] == this)
  188916. {
  188917. callbacks.bufferSwitch = &bufferSwitchCallback2;
  188918. callbacks.asioMessage = &asioMessagesCallback2;
  188919. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback2;
  188920. }
  188921. else
  188922. {
  188923. jassertfalse
  188924. }
  188925. log ("disposing buffers");
  188926. err = asioObject->disposeBuffers();
  188927. log (T("creating buffers: ") + String (totalBuffers) + T(", ") + String (currentBlockSizeSamples));
  188928. err = asioObject->createBuffers (bufferInfos,
  188929. totalBuffers,
  188930. currentBlockSizeSamples,
  188931. &callbacks);
  188932. if (err != 0)
  188933. {
  188934. currentBlockSizeSamples = preferredSize;
  188935. logError ("create buffers 2", err);
  188936. asioObject->disposeBuffers();
  188937. err = asioObject->createBuffers (bufferInfos,
  188938. totalBuffers,
  188939. currentBlockSizeSamples,
  188940. &callbacks);
  188941. }
  188942. if (err == 0)
  188943. {
  188944. buffersCreated = true;
  188945. tempBuffer.calloc (totalBuffers * currentBlockSizeSamples + 32);
  188946. int n = 0;
  188947. Array <int> types;
  188948. currentBitDepth = 16;
  188949. for (i = 0; i < jmin ((int) totalNumInputChans, maxASIOChannels); ++i)
  188950. {
  188951. if (inputChannels[i])
  188952. {
  188953. inBuffers[n] = tempBuffer + (currentBlockSizeSamples * n);
  188954. ASIOChannelInfo channelInfo;
  188955. zerostruct (channelInfo);
  188956. channelInfo.channel = i;
  188957. channelInfo.isInput = 1;
  188958. asioObject->getChannelInfo (&channelInfo);
  188959. types.addIfNotAlreadyThere (channelInfo.type);
  188960. typeToFormatParameters (channelInfo.type,
  188961. inputChannelBitDepths[n],
  188962. inputChannelBytesPerSample[n],
  188963. inputChannelIsFloat[n],
  188964. inputChannelLittleEndian[n]);
  188965. currentBitDepth = jmax (currentBitDepth, inputChannelBitDepths[n]);
  188966. ++n;
  188967. }
  188968. }
  188969. jassert (numActiveInputChans == n);
  188970. n = 0;
  188971. for (i = 0; i < jmin ((int) totalNumOutputChans, maxASIOChannels); ++i)
  188972. {
  188973. if (outputChannels[i])
  188974. {
  188975. outBuffers[n] = tempBuffer + (currentBlockSizeSamples * (numActiveInputChans + n));
  188976. ASIOChannelInfo channelInfo;
  188977. zerostruct (channelInfo);
  188978. channelInfo.channel = i;
  188979. channelInfo.isInput = 0;
  188980. asioObject->getChannelInfo (&channelInfo);
  188981. types.addIfNotAlreadyThere (channelInfo.type);
  188982. typeToFormatParameters (channelInfo.type,
  188983. outputChannelBitDepths[n],
  188984. outputChannelBytesPerSample[n],
  188985. outputChannelIsFloat[n],
  188986. outputChannelLittleEndian[n]);
  188987. currentBitDepth = jmax (currentBitDepth, outputChannelBitDepths[n]);
  188988. ++n;
  188989. }
  188990. }
  188991. jassert (numActiveOutputChans == n);
  188992. for (i = types.size(); --i >= 0;)
  188993. {
  188994. log (T("channel format: ") + String (types[i]));
  188995. }
  188996. jassert (n <= totalBuffers);
  188997. for (i = 0; i < numActiveOutputChans; ++i)
  188998. {
  188999. const int size = currentBlockSizeSamples * (outputChannelBitDepths[i] >> 3);
  189000. if (bufferInfos [numActiveInputChans + i].buffers[0] == 0
  189001. || bufferInfos [numActiveInputChans + i].buffers[1] == 0)
  189002. {
  189003. log ("!! Null buffers");
  189004. }
  189005. else
  189006. {
  189007. zeromem (bufferInfos[numActiveInputChans + i].buffers[0], size);
  189008. zeromem (bufferInfos[numActiveInputChans + i].buffers[1], size);
  189009. }
  189010. }
  189011. inputLatency = outputLatency = 0;
  189012. if (asioObject->getLatencies (&inputLatency, &outputLatency) != 0)
  189013. {
  189014. log ("ASIO - no latencies");
  189015. }
  189016. else
  189017. {
  189018. log (T("ASIO latencies: ")
  189019. + String ((int) outputLatency)
  189020. + T(", ")
  189021. + String ((int) inputLatency));
  189022. }
  189023. isOpen_ = true;
  189024. log ("starting ASIO");
  189025. calledback = false;
  189026. err = asioObject->start();
  189027. if (err != 0)
  189028. {
  189029. isOpen_ = false;
  189030. log ("ASIO - stop on failure");
  189031. Thread::sleep (10);
  189032. asioObject->stop();
  189033. error = "Can't start device";
  189034. Thread::sleep (10);
  189035. }
  189036. else
  189037. {
  189038. int count = 300;
  189039. while (--count > 0 && ! calledback)
  189040. Thread::sleep (10);
  189041. isStarted = true;
  189042. if (! calledback)
  189043. {
  189044. error = "Device didn't start correctly";
  189045. log ("ASIO didn't callback - stopping..");
  189046. asioObject->stop();
  189047. }
  189048. }
  189049. }
  189050. else
  189051. {
  189052. error = "Can't create i/o buffers";
  189053. }
  189054. }
  189055. else
  189056. {
  189057. error = "Can't set sample rate: ";
  189058. error << sampleRate;
  189059. }
  189060. if (error.isNotEmpty())
  189061. {
  189062. logError (error, err);
  189063. if (asioObject != 0 && buffersCreated)
  189064. asioObject->disposeBuffers();
  189065. Thread::sleep (20);
  189066. isStarted = false;
  189067. isOpen_ = false;
  189068. close();
  189069. }
  189070. needToReset = false;
  189071. isReSync = false;
  189072. return error;
  189073. }
  189074. void close()
  189075. {
  189076. error = String::empty;
  189077. stopTimer();
  189078. stop();
  189079. if (isASIOOpen && isOpen_)
  189080. {
  189081. const ScopedLock sl (callbackLock);
  189082. isOpen_ = false;
  189083. isStarted = false;
  189084. needToReset = false;
  189085. isReSync = false;
  189086. log ("ASIO - stopping");
  189087. if (asioObject != 0)
  189088. {
  189089. Thread::sleep (20);
  189090. asioObject->stop();
  189091. Thread::sleep (10);
  189092. asioObject->disposeBuffers();
  189093. }
  189094. Thread::sleep (10);
  189095. }
  189096. }
  189097. bool isOpen()
  189098. {
  189099. return isOpen_ || insideControlPanelModalLoop;
  189100. }
  189101. int getCurrentBufferSizeSamples()
  189102. {
  189103. return currentBlockSizeSamples;
  189104. }
  189105. double getCurrentSampleRate()
  189106. {
  189107. return currentSampleRate;
  189108. }
  189109. const BitArray getActiveOutputChannels() const
  189110. {
  189111. return currentChansOut;
  189112. }
  189113. const BitArray getActiveInputChannels() const
  189114. {
  189115. return currentChansIn;
  189116. }
  189117. int getCurrentBitDepth()
  189118. {
  189119. return currentBitDepth;
  189120. }
  189121. int getOutputLatencyInSamples()
  189122. {
  189123. return outputLatency + currentBlockSizeSamples / 4;
  189124. }
  189125. int getInputLatencyInSamples()
  189126. {
  189127. return inputLatency + currentBlockSizeSamples / 4;
  189128. }
  189129. void start (AudioIODeviceCallback* callback)
  189130. {
  189131. if (callback != 0)
  189132. {
  189133. callback->audioDeviceAboutToStart (this);
  189134. const ScopedLock sl (callbackLock);
  189135. currentCallback = callback;
  189136. }
  189137. }
  189138. void stop()
  189139. {
  189140. AudioIODeviceCallback* const lastCallback = currentCallback;
  189141. {
  189142. const ScopedLock sl (callbackLock);
  189143. currentCallback = 0;
  189144. }
  189145. if (lastCallback != 0)
  189146. lastCallback->audioDeviceStopped();
  189147. }
  189148. bool isPlaying()
  189149. {
  189150. return isASIOOpen && (currentCallback != 0);
  189151. }
  189152. const String getLastError()
  189153. {
  189154. return error;
  189155. }
  189156. bool hasControlPanel() const
  189157. {
  189158. return true;
  189159. }
  189160. bool showControlPanel()
  189161. {
  189162. log ("ASIO - showing control panel");
  189163. Component modalWindow (String::empty);
  189164. modalWindow.setOpaque (true);
  189165. modalWindow.addToDesktop (0);
  189166. modalWindow.enterModalState();
  189167. bool done = false;
  189168. JUCE_TRY
  189169. {
  189170. // are there are devices that need to be closed before showing their control panel?
  189171. // close();
  189172. insideControlPanelModalLoop = true;
  189173. const uint32 started = Time::getMillisecondCounter();
  189174. if (asioObject != 0)
  189175. {
  189176. asioObject->controlPanel();
  189177. const int spent = (int) Time::getMillisecondCounter() - (int) started;
  189178. log (T("spent: ") + String (spent));
  189179. if (spent > 300)
  189180. {
  189181. shouldUsePreferredSize = true;
  189182. done = true;
  189183. }
  189184. }
  189185. }
  189186. JUCE_CATCH_ALL
  189187. insideControlPanelModalLoop = false;
  189188. return done;
  189189. }
  189190. void resetRequest() throw()
  189191. {
  189192. needToReset = true;
  189193. }
  189194. void resyncRequest() throw()
  189195. {
  189196. needToReset = true;
  189197. isReSync = true;
  189198. }
  189199. void timerCallback()
  189200. {
  189201. if (! insideControlPanelModalLoop)
  189202. {
  189203. stopTimer();
  189204. // used to cause a reset
  189205. log ("! ASIO restart request!");
  189206. if (isOpen_)
  189207. {
  189208. AudioIODeviceCallback* const oldCallback = currentCallback;
  189209. close();
  189210. open (BitArray (currentChansIn), BitArray (currentChansOut),
  189211. currentSampleRate, currentBlockSizeSamples);
  189212. if (oldCallback != 0)
  189213. start (oldCallback);
  189214. }
  189215. }
  189216. else
  189217. {
  189218. startTimer (100);
  189219. }
  189220. }
  189221. juce_UseDebuggingNewOperator
  189222. private:
  189223. IASIO* volatile asioObject;
  189224. ASIOCallbacks callbacks;
  189225. void* windowHandle;
  189226. CLSID classId;
  189227. const String optionalDllForDirectLoading;
  189228. String error;
  189229. long totalNumInputChans, totalNumOutputChans;
  189230. StringArray inputChannelNames, outputChannelNames;
  189231. Array<int> sampleRates, bufferSizes;
  189232. long inputLatency, outputLatency;
  189233. long minSize, maxSize, preferredSize, granularity;
  189234. int volatile currentBlockSizeSamples;
  189235. int volatile currentBitDepth;
  189236. double volatile currentSampleRate;
  189237. BitArray currentChansOut, currentChansIn;
  189238. AudioIODeviceCallback* volatile currentCallback;
  189239. CriticalSection callbackLock;
  189240. ASIOBufferInfo bufferInfos [maxASIOChannels];
  189241. float* inBuffers [maxASIOChannels];
  189242. float* outBuffers [maxASIOChannels];
  189243. int inputChannelBitDepths [maxASIOChannels];
  189244. int outputChannelBitDepths [maxASIOChannels];
  189245. int inputChannelBytesPerSample [maxASIOChannels];
  189246. int outputChannelBytesPerSample [maxASIOChannels];
  189247. bool inputChannelIsFloat [maxASIOChannels];
  189248. bool outputChannelIsFloat [maxASIOChannels];
  189249. bool inputChannelLittleEndian [maxASIOChannels];
  189250. bool outputChannelLittleEndian [maxASIOChannels];
  189251. WaitableEvent event1;
  189252. HeapBlock <float> tempBuffer;
  189253. int volatile bufferIndex, numActiveInputChans, numActiveOutputChans;
  189254. bool isOpen_, isStarted;
  189255. bool volatile isASIOOpen;
  189256. bool volatile calledback;
  189257. bool volatile littleEndian, postOutput, needToReset, isReSync;
  189258. bool volatile insideControlPanelModalLoop;
  189259. bool volatile shouldUsePreferredSize;
  189260. void removeCurrentDriver()
  189261. {
  189262. if (asioObject != 0)
  189263. {
  189264. asioObject->Release();
  189265. asioObject = 0;
  189266. }
  189267. }
  189268. bool loadDriver()
  189269. {
  189270. removeCurrentDriver();
  189271. JUCE_TRY
  189272. {
  189273. if (CoCreateInstance (classId, 0, CLSCTX_INPROC_SERVER,
  189274. classId, (void**) &asioObject) == S_OK)
  189275. {
  189276. return true;
  189277. }
  189278. // If a class isn't registered but we have a path for it, we can fallback to
  189279. // doing a direct load of the COM object (only available via the juce_createASIOAudioIODeviceForGUID function).
  189280. if (optionalDllForDirectLoading.isNotEmpty())
  189281. {
  189282. HMODULE h = LoadLibrary (optionalDllForDirectLoading);
  189283. if (h != 0)
  189284. {
  189285. typedef HRESULT (CALLBACK* DllGetClassObjectFunc) (REFCLSID clsid, REFIID iid, LPVOID* ppv);
  189286. DllGetClassObjectFunc dllGetClassObject = (DllGetClassObjectFunc) GetProcAddress (h, "DllGetClassObject");
  189287. if (dllGetClassObject != 0)
  189288. {
  189289. IClassFactory* classFactory = 0;
  189290. HRESULT hr = dllGetClassObject (classId, IID_IClassFactory, (void**) &classFactory);
  189291. if (classFactory != 0)
  189292. {
  189293. hr = classFactory->CreateInstance (0, classId, (void**) &asioObject);
  189294. classFactory->Release();
  189295. }
  189296. return asioObject != 0;
  189297. }
  189298. }
  189299. }
  189300. }
  189301. JUCE_CATCH_ALL
  189302. asioObject = 0;
  189303. return false;
  189304. }
  189305. const String initDriver()
  189306. {
  189307. if (asioObject != 0)
  189308. {
  189309. char buffer [256];
  189310. zeromem (buffer, sizeof (buffer));
  189311. if (! asioObject->init (windowHandle))
  189312. {
  189313. asioObject->getErrorMessage (buffer);
  189314. return String (buffer, sizeof (buffer) - 1);
  189315. }
  189316. // just in case any daft drivers expect this to be called..
  189317. asioObject->getDriverName (buffer);
  189318. return String::empty;
  189319. }
  189320. return "No Driver";
  189321. }
  189322. const String openDevice()
  189323. {
  189324. // use this in case the driver starts opening dialog boxes..
  189325. Component modalWindow (String::empty);
  189326. modalWindow.setOpaque (true);
  189327. modalWindow.addToDesktop (0);
  189328. modalWindow.enterModalState();
  189329. // open the device and get its info..
  189330. log (T("opening ASIO device: ") + getName());
  189331. needToReset = false;
  189332. isReSync = false;
  189333. outputChannelNames.clear();
  189334. inputChannelNames.clear();
  189335. bufferSizes.clear();
  189336. sampleRates.clear();
  189337. isASIOOpen = false;
  189338. isOpen_ = false;
  189339. totalNumInputChans = 0;
  189340. totalNumOutputChans = 0;
  189341. numActiveInputChans = 0;
  189342. numActiveOutputChans = 0;
  189343. currentCallback = 0;
  189344. error = String::empty;
  189345. if (getName().isEmpty())
  189346. return error;
  189347. long err = 0;
  189348. if (loadDriver())
  189349. {
  189350. if ((error = initDriver()).isEmpty())
  189351. {
  189352. numActiveInputChans = 0;
  189353. numActiveOutputChans = 0;
  189354. totalNumInputChans = 0;
  189355. totalNumOutputChans = 0;
  189356. if (asioObject != 0
  189357. && (err = asioObject->getChannels (&totalNumInputChans, &totalNumOutputChans)) == 0)
  189358. {
  189359. log (String ((int) totalNumInputChans) + T(" in, ") + String ((int) totalNumOutputChans) + T(" out"));
  189360. if ((err = asioObject->getBufferSize (&minSize, &maxSize, &preferredSize, &granularity)) == 0)
  189361. {
  189362. // find a list of buffer sizes..
  189363. log (String ((int) minSize) + T(" ") + String ((int) maxSize) + T(" ") + String ((int)preferredSize) + T(" ") + String ((int)granularity));
  189364. if (granularity >= 0)
  189365. {
  189366. granularity = jmax (1, (int) granularity);
  189367. for (int i = jmax ((int) minSize, (int) granularity); i < jmin (6400, (int) maxSize); i += granularity)
  189368. bufferSizes.addIfNotAlreadyThere (granularity * (i / granularity));
  189369. }
  189370. else if (granularity < 0)
  189371. {
  189372. for (int i = 0; i < 18; ++i)
  189373. {
  189374. const int s = (1 << i);
  189375. if (s >= minSize && s <= maxSize)
  189376. bufferSizes.add (s);
  189377. }
  189378. }
  189379. if (! bufferSizes.contains (preferredSize))
  189380. bufferSizes.insert (0, preferredSize);
  189381. double currentRate = 0;
  189382. asioObject->getSampleRate (&currentRate);
  189383. if (currentRate <= 0.0 || currentRate > 192001.0)
  189384. {
  189385. log ("setting sample rate");
  189386. err = asioObject->setSampleRate (44100.0);
  189387. if (err != 0)
  189388. {
  189389. logError ("setting sample rate", err);
  189390. }
  189391. asioObject->getSampleRate (&currentRate);
  189392. }
  189393. currentSampleRate = currentRate;
  189394. postOutput = (asioObject->outputReady() == 0);
  189395. if (postOutput)
  189396. {
  189397. log ("ASIO outputReady = ok");
  189398. }
  189399. updateSampleRates();
  189400. // ..because cubase does it at this point
  189401. inputLatency = outputLatency = 0;
  189402. if (asioObject->getLatencies (&inputLatency, &outputLatency) != 0)
  189403. {
  189404. log ("ASIO - no latencies");
  189405. }
  189406. log (String ("latencies: ")
  189407. + String ((int) inputLatency)
  189408. + T(", ") + String ((int) outputLatency));
  189409. // create some dummy buffers now.. because cubase does..
  189410. numActiveInputChans = 0;
  189411. numActiveOutputChans = 0;
  189412. ASIOBufferInfo* info = bufferInfos;
  189413. int i, numChans = 0;
  189414. for (i = 0; i < jmin (2, (int) totalNumInputChans); ++i)
  189415. {
  189416. info->isInput = 1;
  189417. info->channelNum = i;
  189418. info->buffers[0] = info->buffers[1] = 0;
  189419. ++info;
  189420. ++numChans;
  189421. }
  189422. const int outputBufferIndex = numChans;
  189423. for (i = 0; i < jmin (2, (int) totalNumOutputChans); ++i)
  189424. {
  189425. info->isInput = 0;
  189426. info->channelNum = i;
  189427. info->buffers[0] = info->buffers[1] = 0;
  189428. ++info;
  189429. ++numChans;
  189430. }
  189431. callbacks.sampleRateDidChange = &sampleRateChangedCallback;
  189432. if (currentASIODev[0] == this)
  189433. {
  189434. callbacks.bufferSwitch = &bufferSwitchCallback0;
  189435. callbacks.asioMessage = &asioMessagesCallback0;
  189436. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback0;
  189437. }
  189438. else if (currentASIODev[1] == this)
  189439. {
  189440. callbacks.bufferSwitch = &bufferSwitchCallback1;
  189441. callbacks.asioMessage = &asioMessagesCallback1;
  189442. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback1;
  189443. }
  189444. else if (currentASIODev[2] == this)
  189445. {
  189446. callbacks.bufferSwitch = &bufferSwitchCallback2;
  189447. callbacks.asioMessage = &asioMessagesCallback2;
  189448. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback2;
  189449. }
  189450. else
  189451. {
  189452. jassertfalse
  189453. }
  189454. log (T("creating buffers (dummy): ") + String (numChans)
  189455. + T(", ") + String ((int) preferredSize));
  189456. if (preferredSize > 0)
  189457. {
  189458. err = asioObject->createBuffers (bufferInfos, numChans, preferredSize, &callbacks);
  189459. if (err != 0)
  189460. {
  189461. logError ("dummy buffers", err);
  189462. }
  189463. }
  189464. long newInps = 0, newOuts = 0;
  189465. asioObject->getChannels (&newInps, &newOuts);
  189466. if (totalNumInputChans != newInps || totalNumOutputChans != newOuts)
  189467. {
  189468. totalNumInputChans = newInps;
  189469. totalNumOutputChans = newOuts;
  189470. log (String ((int) totalNumInputChans) + T(" in; ")
  189471. + String ((int) totalNumOutputChans) + T(" out"));
  189472. }
  189473. updateSampleRates();
  189474. ASIOChannelInfo channelInfo;
  189475. channelInfo.type = 0;
  189476. for (i = 0; i < totalNumInputChans; ++i)
  189477. {
  189478. zerostruct (channelInfo);
  189479. channelInfo.channel = i;
  189480. channelInfo.isInput = 1;
  189481. asioObject->getChannelInfo (&channelInfo);
  189482. inputChannelNames.add (String (channelInfo.name));
  189483. }
  189484. for (i = 0; i < totalNumOutputChans; ++i)
  189485. {
  189486. zerostruct (channelInfo);
  189487. channelInfo.channel = i;
  189488. channelInfo.isInput = 0;
  189489. asioObject->getChannelInfo (&channelInfo);
  189490. outputChannelNames.add (String (channelInfo.name));
  189491. typeToFormatParameters (channelInfo.type,
  189492. outputChannelBitDepths[i],
  189493. outputChannelBytesPerSample[i],
  189494. outputChannelIsFloat[i],
  189495. outputChannelLittleEndian[i]);
  189496. if (i < 2)
  189497. {
  189498. // clear the channels that are used with the dummy stuff
  189499. const int bytesPerBuffer = preferredSize * (outputChannelBitDepths[i] >> 3);
  189500. zeromem (bufferInfos [outputBufferIndex + i].buffers[0], bytesPerBuffer);
  189501. zeromem (bufferInfos [outputBufferIndex + i].buffers[1], bytesPerBuffer);
  189502. }
  189503. }
  189504. outputChannelNames.trim();
  189505. inputChannelNames.trim();
  189506. outputChannelNames.appendNumbersToDuplicates (false, true);
  189507. inputChannelNames.appendNumbersToDuplicates (false, true);
  189508. // start and stop because cubase does it..
  189509. asioObject->getLatencies (&inputLatency, &outputLatency);
  189510. if ((err = asioObject->start()) != 0)
  189511. {
  189512. // ignore an error here, as it might start later after setting other stuff up
  189513. logError ("ASIO start", err);
  189514. }
  189515. Thread::sleep (100);
  189516. asioObject->stop();
  189517. }
  189518. else
  189519. {
  189520. error = "Can't detect buffer sizes";
  189521. }
  189522. }
  189523. else
  189524. {
  189525. error = "Can't detect asio channels";
  189526. }
  189527. }
  189528. }
  189529. else
  189530. {
  189531. error = "No such device";
  189532. }
  189533. if (error.isNotEmpty())
  189534. {
  189535. logError (error, err);
  189536. if (asioObject != 0)
  189537. asioObject->disposeBuffers();
  189538. removeCurrentDriver();
  189539. isASIOOpen = false;
  189540. }
  189541. else
  189542. {
  189543. isASIOOpen = true;
  189544. log ("ASIO device open");
  189545. }
  189546. isOpen_ = false;
  189547. needToReset = false;
  189548. isReSync = false;
  189549. return error;
  189550. }
  189551. void callback (const long index) throw()
  189552. {
  189553. if (isStarted)
  189554. {
  189555. bufferIndex = index;
  189556. processBuffer();
  189557. }
  189558. else
  189559. {
  189560. if (postOutput && (asioObject != 0))
  189561. asioObject->outputReady();
  189562. }
  189563. calledback = true;
  189564. }
  189565. void processBuffer() throw()
  189566. {
  189567. const ASIOBufferInfo* const infos = bufferInfos;
  189568. const int bi = bufferIndex;
  189569. const ScopedLock sl (callbackLock);
  189570. if (needToReset)
  189571. {
  189572. needToReset = false;
  189573. if (isReSync)
  189574. {
  189575. log ("! ASIO resync");
  189576. isReSync = false;
  189577. }
  189578. else
  189579. {
  189580. startTimer (20);
  189581. }
  189582. }
  189583. if (bi >= 0)
  189584. {
  189585. const int samps = currentBlockSizeSamples;
  189586. if (currentCallback != 0)
  189587. {
  189588. int i;
  189589. for (i = 0; i < numActiveInputChans; ++i)
  189590. {
  189591. float* const dst = inBuffers[i];
  189592. jassert (dst != 0);
  189593. const char* const src = (const char*) (infos[i].buffers[bi]);
  189594. if (inputChannelIsFloat[i])
  189595. {
  189596. memcpy (dst, src, samps * sizeof (float));
  189597. }
  189598. else
  189599. {
  189600. jassert (dst == tempBuffer + (samps * i));
  189601. switch (inputChannelBitDepths[i])
  189602. {
  189603. case 16:
  189604. convertInt16ToFloat (src, dst, inputChannelBytesPerSample[i],
  189605. samps, inputChannelLittleEndian[i]);
  189606. break;
  189607. case 24:
  189608. convertInt24ToFloat (src, dst, inputChannelBytesPerSample[i],
  189609. samps, inputChannelLittleEndian[i]);
  189610. break;
  189611. case 32:
  189612. convertInt32ToFloat (src, dst, inputChannelBytesPerSample[i],
  189613. samps, inputChannelLittleEndian[i]);
  189614. break;
  189615. case 64:
  189616. jassertfalse
  189617. break;
  189618. }
  189619. }
  189620. }
  189621. currentCallback->audioDeviceIOCallback ((const float**) inBuffers,
  189622. numActiveInputChans,
  189623. outBuffers,
  189624. numActiveOutputChans,
  189625. samps);
  189626. for (i = 0; i < numActiveOutputChans; ++i)
  189627. {
  189628. float* const src = outBuffers[i];
  189629. jassert (src != 0);
  189630. char* const dst = (char*) (infos [numActiveInputChans + i].buffers[bi]);
  189631. if (outputChannelIsFloat[i])
  189632. {
  189633. memcpy (dst, src, samps * sizeof (float));
  189634. }
  189635. else
  189636. {
  189637. jassert (src == tempBuffer + (samps * (numActiveInputChans + i)));
  189638. switch (outputChannelBitDepths[i])
  189639. {
  189640. case 16:
  189641. convertFloatToInt16 (src, dst, outputChannelBytesPerSample[i],
  189642. samps, outputChannelLittleEndian[i]);
  189643. break;
  189644. case 24:
  189645. convertFloatToInt24 (src, dst, outputChannelBytesPerSample[i],
  189646. samps, outputChannelLittleEndian[i]);
  189647. break;
  189648. case 32:
  189649. convertFloatToInt32 (src, dst, outputChannelBytesPerSample[i],
  189650. samps, outputChannelLittleEndian[i]);
  189651. break;
  189652. case 64:
  189653. jassertfalse
  189654. break;
  189655. }
  189656. }
  189657. }
  189658. }
  189659. else
  189660. {
  189661. for (int i = 0; i < numActiveOutputChans; ++i)
  189662. {
  189663. const int bytesPerBuffer = samps * (outputChannelBitDepths[i] >> 3);
  189664. zeromem (infos[numActiveInputChans + i].buffers[bi], bytesPerBuffer);
  189665. }
  189666. }
  189667. }
  189668. if (postOutput)
  189669. asioObject->outputReady();
  189670. }
  189671. static ASIOTime* bufferSwitchTimeInfoCallback0 (ASIOTime*, long index, long) throw()
  189672. {
  189673. if (currentASIODev[0] != 0)
  189674. currentASIODev[0]->callback (index);
  189675. return 0;
  189676. }
  189677. static ASIOTime* bufferSwitchTimeInfoCallback1 (ASIOTime*, long index, long) throw()
  189678. {
  189679. if (currentASIODev[1] != 0)
  189680. currentASIODev[1]->callback (index);
  189681. return 0;
  189682. }
  189683. static ASIOTime* bufferSwitchTimeInfoCallback2 (ASIOTime*, long index, long) throw()
  189684. {
  189685. if (currentASIODev[2] != 0)
  189686. currentASIODev[2]->callback (index);
  189687. return 0;
  189688. }
  189689. static void bufferSwitchCallback0 (long index, long) throw()
  189690. {
  189691. if (currentASIODev[0] != 0)
  189692. currentASIODev[0]->callback (index);
  189693. }
  189694. static void bufferSwitchCallback1 (long index, long) throw()
  189695. {
  189696. if (currentASIODev[1] != 0)
  189697. currentASIODev[1]->callback (index);
  189698. }
  189699. static void bufferSwitchCallback2 (long index, long) throw()
  189700. {
  189701. if (currentASIODev[2] != 0)
  189702. currentASIODev[2]->callback (index);
  189703. }
  189704. static long asioMessagesCallback0 (long selector, long value, void*, double*) throw()
  189705. {
  189706. return asioMessagesCallback (selector, value, 0);
  189707. }
  189708. static long asioMessagesCallback1 (long selector, long value, void*, double*) throw()
  189709. {
  189710. return asioMessagesCallback (selector, value, 1);
  189711. }
  189712. static long asioMessagesCallback2 (long selector, long value, void*, double*) throw()
  189713. {
  189714. return asioMessagesCallback (selector, value, 2);
  189715. }
  189716. static long asioMessagesCallback (long selector, long value, const int deviceIndex) throw()
  189717. {
  189718. switch (selector)
  189719. {
  189720. case kAsioSelectorSupported:
  189721. if (value == kAsioResetRequest
  189722. || value == kAsioEngineVersion
  189723. || value == kAsioResyncRequest
  189724. || value == kAsioLatenciesChanged
  189725. || value == kAsioSupportsInputMonitor)
  189726. return 1;
  189727. break;
  189728. case kAsioBufferSizeChange:
  189729. break;
  189730. case kAsioResetRequest:
  189731. if (currentASIODev[deviceIndex] != 0)
  189732. currentASIODev[deviceIndex]->resetRequest();
  189733. return 1;
  189734. case kAsioResyncRequest:
  189735. if (currentASIODev[deviceIndex] != 0)
  189736. currentASIODev[deviceIndex]->resyncRequest();
  189737. return 1;
  189738. case kAsioLatenciesChanged:
  189739. return 1;
  189740. case kAsioEngineVersion:
  189741. return 2;
  189742. case kAsioSupportsTimeInfo:
  189743. case kAsioSupportsTimeCode:
  189744. return 0;
  189745. }
  189746. return 0;
  189747. }
  189748. static void sampleRateChangedCallback (ASIOSampleRate) throw()
  189749. {
  189750. }
  189751. static void convertInt16ToFloat (const char* src,
  189752. float* dest,
  189753. const int srcStrideBytes,
  189754. int numSamples,
  189755. const bool littleEndian) throw()
  189756. {
  189757. const double g = 1.0 / 32768.0;
  189758. if (littleEndian)
  189759. {
  189760. while (--numSamples >= 0)
  189761. {
  189762. *dest++ = (float) (g * (short) ByteOrder::littleEndianShort (src));
  189763. src += srcStrideBytes;
  189764. }
  189765. }
  189766. else
  189767. {
  189768. while (--numSamples >= 0)
  189769. {
  189770. *dest++ = (float) (g * (short) ByteOrder::bigEndianShort (src));
  189771. src += srcStrideBytes;
  189772. }
  189773. }
  189774. }
  189775. static void convertFloatToInt16 (const float* src,
  189776. char* dest,
  189777. const int dstStrideBytes,
  189778. int numSamples,
  189779. const bool littleEndian) throw()
  189780. {
  189781. const double maxVal = (double) 0x7fff;
  189782. if (littleEndian)
  189783. {
  189784. while (--numSamples >= 0)
  189785. {
  189786. *(uint16*) dest = ByteOrder::swapIfBigEndian ((uint16) (short) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189787. dest += dstStrideBytes;
  189788. }
  189789. }
  189790. else
  189791. {
  189792. while (--numSamples >= 0)
  189793. {
  189794. *(uint16*) dest = ByteOrder::swapIfLittleEndian ((uint16) (short) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189795. dest += dstStrideBytes;
  189796. }
  189797. }
  189798. }
  189799. static void convertInt24ToFloat (const char* src,
  189800. float* dest,
  189801. const int srcStrideBytes,
  189802. int numSamples,
  189803. const bool littleEndian) throw()
  189804. {
  189805. const double g = 1.0 / 0x7fffff;
  189806. if (littleEndian)
  189807. {
  189808. while (--numSamples >= 0)
  189809. {
  189810. *dest++ = (float) (g * ByteOrder::littleEndian24Bit (src));
  189811. src += srcStrideBytes;
  189812. }
  189813. }
  189814. else
  189815. {
  189816. while (--numSamples >= 0)
  189817. {
  189818. *dest++ = (float) (g * ByteOrder::bigEndian24Bit (src));
  189819. src += srcStrideBytes;
  189820. }
  189821. }
  189822. }
  189823. static void convertFloatToInt24 (const float* src,
  189824. char* dest,
  189825. const int dstStrideBytes,
  189826. int numSamples,
  189827. const bool littleEndian) throw()
  189828. {
  189829. const double maxVal = (double) 0x7fffff;
  189830. if (littleEndian)
  189831. {
  189832. while (--numSamples >= 0)
  189833. {
  189834. ByteOrder::littleEndian24BitToChars ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)), dest);
  189835. dest += dstStrideBytes;
  189836. }
  189837. }
  189838. else
  189839. {
  189840. while (--numSamples >= 0)
  189841. {
  189842. ByteOrder::bigEndian24BitToChars ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)), dest);
  189843. dest += dstStrideBytes;
  189844. }
  189845. }
  189846. }
  189847. static void convertInt32ToFloat (const char* src,
  189848. float* dest,
  189849. const int srcStrideBytes,
  189850. int numSamples,
  189851. const bool littleEndian) throw()
  189852. {
  189853. const double g = 1.0 / 0x7fffffff;
  189854. if (littleEndian)
  189855. {
  189856. while (--numSamples >= 0)
  189857. {
  189858. *dest++ = (float) (g * (int) ByteOrder::littleEndianInt (src));
  189859. src += srcStrideBytes;
  189860. }
  189861. }
  189862. else
  189863. {
  189864. while (--numSamples >= 0)
  189865. {
  189866. *dest++ = (float) (g * (int) ByteOrder::bigEndianInt (src));
  189867. src += srcStrideBytes;
  189868. }
  189869. }
  189870. }
  189871. static void convertFloatToInt32 (const float* src,
  189872. char* dest,
  189873. const int dstStrideBytes,
  189874. int numSamples,
  189875. const bool littleEndian) throw()
  189876. {
  189877. const double maxVal = (double) 0x7fffffff;
  189878. if (littleEndian)
  189879. {
  189880. while (--numSamples >= 0)
  189881. {
  189882. *(uint32*) dest = ByteOrder::swapIfBigEndian ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189883. dest += dstStrideBytes;
  189884. }
  189885. }
  189886. else
  189887. {
  189888. while (--numSamples >= 0)
  189889. {
  189890. *(uint32*) dest = ByteOrder::swapIfLittleEndian ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189891. dest += dstStrideBytes;
  189892. }
  189893. }
  189894. }
  189895. static void typeToFormatParameters (const long type,
  189896. int& bitDepth,
  189897. int& byteStride,
  189898. bool& formatIsFloat,
  189899. bool& littleEndian) throw()
  189900. {
  189901. bitDepth = 0;
  189902. littleEndian = false;
  189903. formatIsFloat = false;
  189904. switch (type)
  189905. {
  189906. case ASIOSTInt16MSB:
  189907. case ASIOSTInt16LSB:
  189908. case ASIOSTInt32MSB16:
  189909. case ASIOSTInt32LSB16:
  189910. bitDepth = 16; break;
  189911. case ASIOSTFloat32MSB:
  189912. case ASIOSTFloat32LSB:
  189913. formatIsFloat = true;
  189914. bitDepth = 32; break;
  189915. case ASIOSTInt32MSB:
  189916. case ASIOSTInt32LSB:
  189917. bitDepth = 32; break;
  189918. case ASIOSTInt24MSB:
  189919. case ASIOSTInt24LSB:
  189920. case ASIOSTInt32MSB24:
  189921. case ASIOSTInt32LSB24:
  189922. case ASIOSTInt32MSB18:
  189923. case ASIOSTInt32MSB20:
  189924. case ASIOSTInt32LSB18:
  189925. case ASIOSTInt32LSB20:
  189926. bitDepth = 24; break;
  189927. case ASIOSTFloat64MSB:
  189928. case ASIOSTFloat64LSB:
  189929. default:
  189930. bitDepth = 64;
  189931. break;
  189932. }
  189933. switch (type)
  189934. {
  189935. case ASIOSTInt16MSB:
  189936. case ASIOSTInt32MSB16:
  189937. case ASIOSTFloat32MSB:
  189938. case ASIOSTFloat64MSB:
  189939. case ASIOSTInt32MSB:
  189940. case ASIOSTInt32MSB18:
  189941. case ASIOSTInt32MSB20:
  189942. case ASIOSTInt32MSB24:
  189943. case ASIOSTInt24MSB:
  189944. littleEndian = false; break;
  189945. case ASIOSTInt16LSB:
  189946. case ASIOSTInt32LSB16:
  189947. case ASIOSTFloat32LSB:
  189948. case ASIOSTFloat64LSB:
  189949. case ASIOSTInt32LSB:
  189950. case ASIOSTInt32LSB18:
  189951. case ASIOSTInt32LSB20:
  189952. case ASIOSTInt32LSB24:
  189953. case ASIOSTInt24LSB:
  189954. littleEndian = true; break;
  189955. default:
  189956. break;
  189957. }
  189958. switch (type)
  189959. {
  189960. case ASIOSTInt16LSB:
  189961. case ASIOSTInt16MSB:
  189962. byteStride = 2; break;
  189963. case ASIOSTInt24LSB:
  189964. case ASIOSTInt24MSB:
  189965. byteStride = 3; break;
  189966. case ASIOSTInt32MSB16:
  189967. case ASIOSTInt32LSB16:
  189968. case ASIOSTInt32MSB:
  189969. case ASIOSTInt32MSB18:
  189970. case ASIOSTInt32MSB20:
  189971. case ASIOSTInt32MSB24:
  189972. case ASIOSTInt32LSB:
  189973. case ASIOSTInt32LSB18:
  189974. case ASIOSTInt32LSB20:
  189975. case ASIOSTInt32LSB24:
  189976. case ASIOSTFloat32LSB:
  189977. case ASIOSTFloat32MSB:
  189978. byteStride = 4; break;
  189979. case ASIOSTFloat64MSB:
  189980. case ASIOSTFloat64LSB:
  189981. byteStride = 8; break;
  189982. default:
  189983. break;
  189984. }
  189985. }
  189986. };
  189987. class ASIOAudioIODeviceType : public AudioIODeviceType
  189988. {
  189989. public:
  189990. ASIOAudioIODeviceType()
  189991. : AudioIODeviceType (T("ASIO")),
  189992. hasScanned (false)
  189993. {
  189994. CoInitialize (0);
  189995. }
  189996. ~ASIOAudioIODeviceType()
  189997. {
  189998. }
  189999. void scanForDevices()
  190000. {
  190001. hasScanned = true;
  190002. deviceNames.clear();
  190003. classIds.clear();
  190004. HKEY hk = 0;
  190005. int index = 0;
  190006. if (RegOpenKeyA (HKEY_LOCAL_MACHINE, "software\\asio", &hk) == ERROR_SUCCESS)
  190007. {
  190008. for (;;)
  190009. {
  190010. char name [256];
  190011. if (RegEnumKeyA (hk, index++, name, 256) == ERROR_SUCCESS)
  190012. {
  190013. addDriverInfo (name, hk);
  190014. }
  190015. else
  190016. {
  190017. break;
  190018. }
  190019. }
  190020. RegCloseKey (hk);
  190021. }
  190022. }
  190023. const StringArray getDeviceNames (const bool /*wantInputNames*/) const
  190024. {
  190025. jassert (hasScanned); // need to call scanForDevices() before doing this
  190026. return deviceNames;
  190027. }
  190028. int getDefaultDeviceIndex (const bool) const
  190029. {
  190030. jassert (hasScanned); // need to call scanForDevices() before doing this
  190031. for (int i = deviceNames.size(); --i >= 0;)
  190032. if (deviceNames[i].containsIgnoreCase (T("asio4all")))
  190033. return i; // asio4all is a safe choice for a default..
  190034. #if JUCE_DEBUG
  190035. if (deviceNames.size() > 1 && deviceNames[0].containsIgnoreCase (T("digidesign")))
  190036. return 1; // (the digi m-box driver crashes the app when you run
  190037. // it in the debugger, which can be a bit annoying)
  190038. #endif
  190039. return 0;
  190040. }
  190041. static int findFreeSlot()
  190042. {
  190043. for (int i = 0; i < numElementsInArray (currentASIODev); ++i)
  190044. if (currentASIODev[i] == 0)
  190045. return i;
  190046. jassertfalse; // unfortunately you can only have a finite number
  190047. // of ASIO devices open at the same time..
  190048. return -1;
  190049. }
  190050. int getIndexOfDevice (AudioIODevice* d, const bool /*asInput*/) const
  190051. {
  190052. jassert (hasScanned); // need to call scanForDevices() before doing this
  190053. return d == 0 ? -1 : deviceNames.indexOf (d->getName());
  190054. }
  190055. bool hasSeparateInputsAndOutputs() const { return false; }
  190056. AudioIODevice* createDevice (const String& outputDeviceName,
  190057. const String& inputDeviceName)
  190058. {
  190059. // ASIO can't open two different devices for input and output - they must be the same one.
  190060. jassert (inputDeviceName == outputDeviceName || outputDeviceName.isEmpty() || inputDeviceName.isEmpty());
  190061. jassert (hasScanned); // need to call scanForDevices() before doing this
  190062. const int index = deviceNames.indexOf (outputDeviceName.isNotEmpty() ? outputDeviceName
  190063. : inputDeviceName);
  190064. if (index >= 0)
  190065. {
  190066. const int freeSlot = findFreeSlot();
  190067. if (freeSlot >= 0)
  190068. return new ASIOAudioIODevice (outputDeviceName, *(classIds [index]), freeSlot, String::empty);
  190069. }
  190070. return 0;
  190071. }
  190072. juce_UseDebuggingNewOperator
  190073. private:
  190074. StringArray deviceNames;
  190075. OwnedArray <CLSID> classIds;
  190076. bool hasScanned;
  190077. static bool checkClassIsOk (const String& classId)
  190078. {
  190079. HKEY hk = 0;
  190080. bool ok = false;
  190081. if (RegOpenKeyA (HKEY_CLASSES_ROOT, "clsid", &hk) == ERROR_SUCCESS)
  190082. {
  190083. int index = 0;
  190084. for (;;)
  190085. {
  190086. char buf [512];
  190087. if (RegEnumKeyA (hk, index++, buf, 512) == ERROR_SUCCESS)
  190088. {
  190089. if (classId.equalsIgnoreCase (buf))
  190090. {
  190091. HKEY subKey, pathKey;
  190092. if (RegOpenKeyExA (hk, buf, 0, KEY_READ, &subKey) == ERROR_SUCCESS)
  190093. {
  190094. if (RegOpenKeyExA (subKey, "InprocServer32", 0, KEY_READ, &pathKey) == ERROR_SUCCESS)
  190095. {
  190096. char pathName [600];
  190097. DWORD dtype = REG_SZ;
  190098. DWORD dsize = sizeof (pathName);
  190099. if (RegQueryValueExA (pathKey, 0, 0, &dtype,
  190100. (LPBYTE) pathName, &dsize) == ERROR_SUCCESS)
  190101. {
  190102. OFSTRUCT of;
  190103. zerostruct (of);
  190104. of.cBytes = sizeof (of);
  190105. ok = (OpenFile (String (pathName), &of, OF_EXIST) != 0);
  190106. }
  190107. RegCloseKey (pathKey);
  190108. }
  190109. RegCloseKey (subKey);
  190110. }
  190111. break;
  190112. }
  190113. }
  190114. else
  190115. {
  190116. break;
  190117. }
  190118. }
  190119. RegCloseKey (hk);
  190120. }
  190121. return ok;
  190122. }
  190123. void addDriverInfo (const String& keyName, HKEY hk)
  190124. {
  190125. HKEY subKey;
  190126. if (RegOpenKeyExA (hk, keyName, 0, KEY_READ, &subKey) == ERROR_SUCCESS)
  190127. {
  190128. char buf [256];
  190129. DWORD dtype = REG_SZ;
  190130. DWORD dsize = sizeof (buf);
  190131. zeromem (buf, dsize);
  190132. if (RegQueryValueExA (subKey, "clsid", 0, &dtype, (LPBYTE) buf, &dsize) == ERROR_SUCCESS)
  190133. {
  190134. if (dsize > 0 && checkClassIsOk (buf))
  190135. {
  190136. wchar_t classIdStr [130];
  190137. MultiByteToWideChar (CP_ACP, 0, buf, -1, classIdStr, 128);
  190138. String deviceName;
  190139. CLSID classId;
  190140. if (CLSIDFromString ((LPOLESTR) classIdStr, &classId) == S_OK)
  190141. {
  190142. dtype = REG_SZ;
  190143. dsize = sizeof (buf);
  190144. if (RegQueryValueExA (subKey, "description", 0, &dtype, (LPBYTE) buf, &dsize) == ERROR_SUCCESS)
  190145. deviceName = buf;
  190146. else
  190147. deviceName = keyName;
  190148. log (T("found ") + deviceName);
  190149. deviceNames.add (deviceName);
  190150. classIds.add (new CLSID (classId));
  190151. }
  190152. }
  190153. RegCloseKey (subKey);
  190154. }
  190155. }
  190156. }
  190157. ASIOAudioIODeviceType (const ASIOAudioIODeviceType&);
  190158. const ASIOAudioIODeviceType& operator= (const ASIOAudioIODeviceType&);
  190159. };
  190160. AudioIODeviceType* juce_createAudioIODeviceType_ASIO()
  190161. {
  190162. return new ASIOAudioIODeviceType();
  190163. }
  190164. AudioIODevice* juce_createASIOAudioIODeviceForGUID (const String& name,
  190165. void* guid,
  190166. const String& optionalDllForDirectLoading)
  190167. {
  190168. const int freeSlot = ASIOAudioIODeviceType::findFreeSlot();
  190169. if (freeSlot < 0)
  190170. return 0;
  190171. return new ASIOAudioIODevice (name, *(CLSID*) guid, freeSlot, optionalDllForDirectLoading);
  190172. }
  190173. #undef log
  190174. #endif
  190175. /*** End of inlined file: juce_win32_ASIO.cpp ***/
  190176. /*** Start of inlined file: juce_win32_DirectSound.cpp ***/
  190177. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  190178. // compiled on its own).
  190179. #if JUCE_INCLUDED_FILE && JUCE_DIRECTSOUND
  190180. END_JUCE_NAMESPACE
  190181. extern "C"
  190182. {
  190183. // Declare just the minimum number of interfaces for the DSound objects that we need..
  190184. typedef struct typeDSBUFFERDESC
  190185. {
  190186. DWORD dwSize;
  190187. DWORD dwFlags;
  190188. DWORD dwBufferBytes;
  190189. DWORD dwReserved;
  190190. LPWAVEFORMATEX lpwfxFormat;
  190191. GUID guid3DAlgorithm;
  190192. } DSBUFFERDESC;
  190193. struct IDirectSoundBuffer;
  190194. #undef INTERFACE
  190195. #define INTERFACE IDirectSound
  190196. DECLARE_INTERFACE_(IDirectSound, IUnknown)
  190197. {
  190198. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  190199. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  190200. STDMETHOD_(ULONG,Release) (THIS) PURE;
  190201. STDMETHOD(CreateSoundBuffer) (THIS_ DSBUFFERDESC*, IDirectSoundBuffer**, LPUNKNOWN) PURE;
  190202. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  190203. STDMETHOD(DuplicateSoundBuffer) (THIS_ IDirectSoundBuffer*, IDirectSoundBuffer**) PURE;
  190204. STDMETHOD(SetCooperativeLevel) (THIS_ HWND, DWORD) PURE;
  190205. STDMETHOD(Compact) (THIS) PURE;
  190206. STDMETHOD(GetSpeakerConfig) (THIS_ LPDWORD) PURE;
  190207. STDMETHOD(SetSpeakerConfig) (THIS_ DWORD) PURE;
  190208. STDMETHOD(Initialize) (THIS_ const GUID*) PURE;
  190209. };
  190210. #undef INTERFACE
  190211. #define INTERFACE IDirectSoundBuffer
  190212. DECLARE_INTERFACE_(IDirectSoundBuffer, IUnknown)
  190213. {
  190214. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  190215. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  190216. STDMETHOD_(ULONG,Release) (THIS) PURE;
  190217. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  190218. STDMETHOD(GetCurrentPosition) (THIS_ LPDWORD, LPDWORD) PURE;
  190219. STDMETHOD(GetFormat) (THIS_ LPWAVEFORMATEX, DWORD, LPDWORD) PURE;
  190220. STDMETHOD(GetVolume) (THIS_ LPLONG) PURE;
  190221. STDMETHOD(GetPan) (THIS_ LPLONG) PURE;
  190222. STDMETHOD(GetFrequency) (THIS_ LPDWORD) PURE;
  190223. STDMETHOD(GetStatus) (THIS_ LPDWORD) PURE;
  190224. STDMETHOD(Initialize) (THIS_ IDirectSound*, DSBUFFERDESC*) PURE;
  190225. STDMETHOD(Lock) (THIS_ DWORD, DWORD, LPVOID*, LPDWORD, LPVOID*, LPDWORD, DWORD) PURE;
  190226. STDMETHOD(Play) (THIS_ DWORD, DWORD, DWORD) PURE;
  190227. STDMETHOD(SetCurrentPosition) (THIS_ DWORD) PURE;
  190228. STDMETHOD(SetFormat) (THIS_ const WAVEFORMATEX*) PURE;
  190229. STDMETHOD(SetVolume) (THIS_ LONG) PURE;
  190230. STDMETHOD(SetPan) (THIS_ LONG) PURE;
  190231. STDMETHOD(SetFrequency) (THIS_ DWORD) PURE;
  190232. STDMETHOD(Stop) (THIS) PURE;
  190233. STDMETHOD(Unlock) (THIS_ LPVOID, DWORD, LPVOID, DWORD) PURE;
  190234. STDMETHOD(Restore) (THIS) PURE;
  190235. };
  190236. typedef struct typeDSCBUFFERDESC
  190237. {
  190238. DWORD dwSize;
  190239. DWORD dwFlags;
  190240. DWORD dwBufferBytes;
  190241. DWORD dwReserved;
  190242. LPWAVEFORMATEX lpwfxFormat;
  190243. } DSCBUFFERDESC;
  190244. struct IDirectSoundCaptureBuffer;
  190245. #undef INTERFACE
  190246. #define INTERFACE IDirectSoundCapture
  190247. DECLARE_INTERFACE_(IDirectSoundCapture, IUnknown)
  190248. {
  190249. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  190250. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  190251. STDMETHOD_(ULONG,Release) (THIS) PURE;
  190252. STDMETHOD(CreateCaptureBuffer) (THIS_ DSCBUFFERDESC*, IDirectSoundCaptureBuffer**, LPUNKNOWN) PURE;
  190253. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  190254. STDMETHOD(Initialize) (THIS_ const GUID*) PURE;
  190255. };
  190256. #undef INTERFACE
  190257. #define INTERFACE IDirectSoundCaptureBuffer
  190258. DECLARE_INTERFACE_(IDirectSoundCaptureBuffer, IUnknown)
  190259. {
  190260. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  190261. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  190262. STDMETHOD_(ULONG,Release) (THIS) PURE;
  190263. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  190264. STDMETHOD(GetCurrentPosition) (THIS_ LPDWORD, LPDWORD) PURE;
  190265. STDMETHOD(GetFormat) (THIS_ LPWAVEFORMATEX, DWORD, LPDWORD) PURE;
  190266. STDMETHOD(GetStatus) (THIS_ LPDWORD) PURE;
  190267. STDMETHOD(Initialize) (THIS_ IDirectSoundCapture*, DSCBUFFERDESC*) PURE;
  190268. STDMETHOD(Lock) (THIS_ DWORD, DWORD, LPVOID*, LPDWORD, LPVOID*, LPDWORD, DWORD) PURE;
  190269. STDMETHOD(Start) (THIS_ DWORD) PURE;
  190270. STDMETHOD(Stop) (THIS) PURE;
  190271. STDMETHOD(Unlock) (THIS_ LPVOID, DWORD, LPVOID, DWORD) PURE;
  190272. };
  190273. };
  190274. BEGIN_JUCE_NAMESPACE
  190275. static const String getDSErrorMessage (HRESULT hr)
  190276. {
  190277. const char* result = 0;
  190278. switch (hr)
  190279. {
  190280. case MAKE_HRESULT(1, 0x878, 10):
  190281. result = "Device already allocated";
  190282. break;
  190283. case MAKE_HRESULT(1, 0x878, 30):
  190284. result = "Control unavailable";
  190285. break;
  190286. case E_INVALIDARG:
  190287. result = "Invalid parameter";
  190288. break;
  190289. case MAKE_HRESULT(1, 0x878, 50):
  190290. result = "Invalid call";
  190291. break;
  190292. case E_FAIL:
  190293. result = "Generic error";
  190294. break;
  190295. case MAKE_HRESULT(1, 0x878, 70):
  190296. result = "Priority level error";
  190297. break;
  190298. case E_OUTOFMEMORY:
  190299. result = "Out of memory";
  190300. break;
  190301. case MAKE_HRESULT(1, 0x878, 100):
  190302. result = "Bad format";
  190303. break;
  190304. case E_NOTIMPL:
  190305. result = "Unsupported function";
  190306. break;
  190307. case MAKE_HRESULT(1, 0x878, 120):
  190308. result = "No driver";
  190309. break;
  190310. case MAKE_HRESULT(1, 0x878, 130):
  190311. result = "Already initialised";
  190312. break;
  190313. case CLASS_E_NOAGGREGATION:
  190314. result = "No aggregation";
  190315. break;
  190316. case MAKE_HRESULT(1, 0x878, 150):
  190317. result = "Buffer lost";
  190318. break;
  190319. case MAKE_HRESULT(1, 0x878, 160):
  190320. result = "Another app has priority";
  190321. break;
  190322. case MAKE_HRESULT(1, 0x878, 170):
  190323. result = "Uninitialised";
  190324. break;
  190325. case E_NOINTERFACE:
  190326. result = "No interface";
  190327. break;
  190328. case S_OK:
  190329. result = "No error";
  190330. break;
  190331. default:
  190332. return "Unknown error: " + String ((int) hr);
  190333. }
  190334. return result;
  190335. }
  190336. #define DS_DEBUGGING 1
  190337. #ifdef DS_DEBUGGING
  190338. #define CATCH JUCE_CATCH_EXCEPTION
  190339. #undef log
  190340. #define log(a) Logger::writeToLog(a);
  190341. #undef logError
  190342. #define logError(a) logDSError(a, __LINE__);
  190343. static void logDSError (HRESULT hr, int lineNum)
  190344. {
  190345. if (hr != S_OK)
  190346. {
  190347. String error ("DS error at line ");
  190348. error << lineNum << T(" - ") << getDSErrorMessage (hr);
  190349. log (error);
  190350. }
  190351. }
  190352. #else
  190353. #define CATCH JUCE_CATCH_ALL
  190354. #define log(a)
  190355. #define logError(a)
  190356. #endif
  190357. #define DSOUND_FUNCTION(functionName, params) \
  190358. typedef HRESULT (WINAPI *type##functionName) params; \
  190359. static type##functionName ds##functionName = 0;
  190360. #define DSOUND_FUNCTION_LOAD(functionName) \
  190361. ds##functionName = (type##functionName) GetProcAddress (h, #functionName); \
  190362. jassert (ds##functionName != 0);
  190363. typedef BOOL (CALLBACK *LPDSENUMCALLBACKW) (LPGUID, LPCWSTR, LPCWSTR, LPVOID);
  190364. typedef BOOL (CALLBACK *LPDSENUMCALLBACKA) (LPGUID, LPCSTR, LPCSTR, LPVOID);
  190365. DSOUND_FUNCTION (DirectSoundCreate, (const GUID*, IDirectSound**, LPUNKNOWN))
  190366. DSOUND_FUNCTION (DirectSoundCaptureCreate, (const GUID*, IDirectSoundCapture**, LPUNKNOWN))
  190367. DSOUND_FUNCTION (DirectSoundEnumerateW, (LPDSENUMCALLBACKW, LPVOID))
  190368. DSOUND_FUNCTION (DirectSoundCaptureEnumerateW, (LPDSENUMCALLBACKW, LPVOID))
  190369. static void initialiseDSoundFunctions()
  190370. {
  190371. if (dsDirectSoundCreate == 0)
  190372. {
  190373. HMODULE h = LoadLibraryA ("dsound.dll");
  190374. DSOUND_FUNCTION_LOAD (DirectSoundCreate)
  190375. DSOUND_FUNCTION_LOAD (DirectSoundCaptureCreate)
  190376. DSOUND_FUNCTION_LOAD (DirectSoundEnumerateW)
  190377. DSOUND_FUNCTION_LOAD (DirectSoundCaptureEnumerateW)
  190378. }
  190379. }
  190380. class DSoundInternalOutChannel
  190381. {
  190382. String name;
  190383. LPGUID guid;
  190384. int sampleRate, bufferSizeSamples;
  190385. float* leftBuffer;
  190386. float* rightBuffer;
  190387. IDirectSound* pDirectSound;
  190388. IDirectSoundBuffer* pOutputBuffer;
  190389. DWORD writeOffset;
  190390. int totalBytesPerBuffer;
  190391. int bytesPerBuffer;
  190392. unsigned int lastPlayCursor;
  190393. public:
  190394. int bitDepth;
  190395. bool doneFlag;
  190396. DSoundInternalOutChannel (const String& name_,
  190397. LPGUID guid_,
  190398. int rate,
  190399. int bufferSize,
  190400. float* left,
  190401. float* right)
  190402. : name (name_),
  190403. guid (guid_),
  190404. sampleRate (rate),
  190405. bufferSizeSamples (bufferSize),
  190406. leftBuffer (left),
  190407. rightBuffer (right),
  190408. pDirectSound (0),
  190409. pOutputBuffer (0),
  190410. bitDepth (16)
  190411. {
  190412. }
  190413. ~DSoundInternalOutChannel()
  190414. {
  190415. close();
  190416. }
  190417. void close()
  190418. {
  190419. HRESULT hr;
  190420. if (pOutputBuffer != 0)
  190421. {
  190422. JUCE_TRY
  190423. {
  190424. log (T("closing dsound out: ") + name);
  190425. hr = pOutputBuffer->Stop();
  190426. logError (hr);
  190427. }
  190428. CATCH
  190429. JUCE_TRY
  190430. {
  190431. hr = pOutputBuffer->Release();
  190432. logError (hr);
  190433. }
  190434. CATCH
  190435. pOutputBuffer = 0;
  190436. }
  190437. if (pDirectSound != 0)
  190438. {
  190439. JUCE_TRY
  190440. {
  190441. hr = pDirectSound->Release();
  190442. logError (hr);
  190443. }
  190444. CATCH
  190445. pDirectSound = 0;
  190446. }
  190447. }
  190448. const String open()
  190449. {
  190450. log (T("opening dsound out device: ") + name
  190451. + T(" rate=") + String (sampleRate)
  190452. + T(" bits=") + String (bitDepth)
  190453. + T(" buf=") + String (bufferSizeSamples));
  190454. pDirectSound = 0;
  190455. pOutputBuffer = 0;
  190456. writeOffset = 0;
  190457. String error;
  190458. HRESULT hr = E_NOINTERFACE;
  190459. if (dsDirectSoundCreate != 0)
  190460. hr = dsDirectSoundCreate (guid, &pDirectSound, 0);
  190461. if (hr == S_OK)
  190462. {
  190463. bytesPerBuffer = (bufferSizeSamples * (bitDepth >> 2)) & ~15;
  190464. totalBytesPerBuffer = (3 * bytesPerBuffer) & ~15;
  190465. const int numChannels = 2;
  190466. hr = pDirectSound->SetCooperativeLevel (GetDesktopWindow(), 2 /* DSSCL_PRIORITY */);
  190467. logError (hr);
  190468. if (hr == S_OK)
  190469. {
  190470. IDirectSoundBuffer* pPrimaryBuffer;
  190471. DSBUFFERDESC primaryDesc;
  190472. zerostruct (primaryDesc);
  190473. primaryDesc.dwSize = sizeof (DSBUFFERDESC);
  190474. primaryDesc.dwFlags = 1 /* DSBCAPS_PRIMARYBUFFER */;
  190475. primaryDesc.dwBufferBytes = 0;
  190476. primaryDesc.lpwfxFormat = 0;
  190477. log ("opening dsound out step 2");
  190478. hr = pDirectSound->CreateSoundBuffer (&primaryDesc, &pPrimaryBuffer, 0);
  190479. logError (hr);
  190480. if (hr == S_OK)
  190481. {
  190482. WAVEFORMATEX wfFormat;
  190483. wfFormat.wFormatTag = WAVE_FORMAT_PCM;
  190484. wfFormat.nChannels = (unsigned short) numChannels;
  190485. wfFormat.nSamplesPerSec = sampleRate;
  190486. wfFormat.wBitsPerSample = (unsigned short) bitDepth;
  190487. wfFormat.nBlockAlign = (unsigned short) (wfFormat.nChannels * wfFormat.wBitsPerSample / 8);
  190488. wfFormat.nAvgBytesPerSec = wfFormat.nSamplesPerSec * wfFormat.nBlockAlign;
  190489. wfFormat.cbSize = 0;
  190490. hr = pPrimaryBuffer->SetFormat (&wfFormat);
  190491. logError (hr);
  190492. if (hr == S_OK)
  190493. {
  190494. DSBUFFERDESC secondaryDesc;
  190495. zerostruct (secondaryDesc);
  190496. secondaryDesc.dwSize = sizeof (DSBUFFERDESC);
  190497. secondaryDesc.dwFlags = 0x8000 /* DSBCAPS_GLOBALFOCUS */
  190498. | 0x10000 /* DSBCAPS_GETCURRENTPOSITION2 */;
  190499. secondaryDesc.dwBufferBytes = totalBytesPerBuffer;
  190500. secondaryDesc.lpwfxFormat = &wfFormat;
  190501. hr = pDirectSound->CreateSoundBuffer (&secondaryDesc, &pOutputBuffer, 0);
  190502. logError (hr);
  190503. if (hr == S_OK)
  190504. {
  190505. log ("opening dsound out step 3");
  190506. DWORD dwDataLen;
  190507. unsigned char* pDSBuffData;
  190508. hr = pOutputBuffer->Lock (0, totalBytesPerBuffer,
  190509. (LPVOID*) &pDSBuffData, &dwDataLen, 0, 0, 0);
  190510. logError (hr);
  190511. if (hr == S_OK)
  190512. {
  190513. zeromem (pDSBuffData, dwDataLen);
  190514. hr = pOutputBuffer->Unlock (pDSBuffData, dwDataLen, 0, 0);
  190515. if (hr == S_OK)
  190516. {
  190517. hr = pOutputBuffer->SetCurrentPosition (0);
  190518. if (hr == S_OK)
  190519. {
  190520. hr = pOutputBuffer->Play (0, 0, 1 /* DSBPLAY_LOOPING */);
  190521. if (hr == S_OK)
  190522. return String::empty;
  190523. }
  190524. }
  190525. }
  190526. }
  190527. }
  190528. }
  190529. }
  190530. }
  190531. error = getDSErrorMessage (hr);
  190532. close();
  190533. return error;
  190534. }
  190535. void synchronisePosition()
  190536. {
  190537. if (pOutputBuffer != 0)
  190538. {
  190539. DWORD playCursor;
  190540. pOutputBuffer->GetCurrentPosition (&playCursor, &writeOffset);
  190541. }
  190542. }
  190543. bool service()
  190544. {
  190545. if (pOutputBuffer == 0)
  190546. return true;
  190547. DWORD playCursor, writeCursor;
  190548. for (;;)
  190549. {
  190550. HRESULT hr = pOutputBuffer->GetCurrentPosition (&playCursor, &writeCursor);
  190551. if (hr == MAKE_HRESULT (1, 0x878, 150)) // DSERR_BUFFERLOST
  190552. {
  190553. pOutputBuffer->Restore();
  190554. continue;
  190555. }
  190556. if (hr == S_OK)
  190557. break;
  190558. logError (hr);
  190559. jassertfalse
  190560. return true;
  190561. }
  190562. int playWriteGap = writeCursor - playCursor;
  190563. if (playWriteGap < 0)
  190564. playWriteGap += totalBytesPerBuffer;
  190565. int bytesEmpty = playCursor - writeOffset;
  190566. if (bytesEmpty < 0)
  190567. bytesEmpty += totalBytesPerBuffer;
  190568. if (bytesEmpty > (totalBytesPerBuffer - playWriteGap))
  190569. {
  190570. writeOffset = writeCursor;
  190571. bytesEmpty = totalBytesPerBuffer - playWriteGap;
  190572. }
  190573. if (bytesEmpty >= bytesPerBuffer)
  190574. {
  190575. LPBYTE lpbuf1 = 0;
  190576. LPBYTE lpbuf2 = 0;
  190577. DWORD dwSize1 = 0;
  190578. DWORD dwSize2 = 0;
  190579. HRESULT hr = pOutputBuffer->Lock (writeOffset,
  190580. bytesPerBuffer,
  190581. (void**) &lpbuf1, &dwSize1,
  190582. (void**) &lpbuf2, &dwSize2, 0);
  190583. if (hr == MAKE_HRESULT (1, 0x878, 150)) // DSERR_BUFFERLOST
  190584. {
  190585. pOutputBuffer->Restore();
  190586. hr = pOutputBuffer->Lock (writeOffset,
  190587. bytesPerBuffer,
  190588. (void**) &lpbuf1, &dwSize1,
  190589. (void**) &lpbuf2, &dwSize2, 0);
  190590. }
  190591. if (hr == S_OK)
  190592. {
  190593. if (bitDepth == 16)
  190594. {
  190595. const float gainL = 32767.0f;
  190596. const float gainR = 32767.0f;
  190597. int* dest = (int*)lpbuf1;
  190598. const float* left = leftBuffer;
  190599. const float* right = rightBuffer;
  190600. int samples1 = dwSize1 >> 2;
  190601. int samples2 = dwSize2 >> 2;
  190602. if (left == 0)
  190603. {
  190604. while (--samples1 >= 0)
  190605. {
  190606. int r = roundToInt (gainR * *right++);
  190607. if (r < -32768)
  190608. r = -32768;
  190609. else if (r > 32767)
  190610. r = 32767;
  190611. *dest++ = (r << 16);
  190612. }
  190613. dest = (int*)lpbuf2;
  190614. while (--samples2 >= 0)
  190615. {
  190616. int r = roundToInt (gainR * *right++);
  190617. if (r < -32768)
  190618. r = -32768;
  190619. else if (r > 32767)
  190620. r = 32767;
  190621. *dest++ = (r << 16);
  190622. }
  190623. }
  190624. else if (right == 0)
  190625. {
  190626. while (--samples1 >= 0)
  190627. {
  190628. int l = roundToInt (gainL * *left++);
  190629. if (l < -32768)
  190630. l = -32768;
  190631. else if (l > 32767)
  190632. l = 32767;
  190633. l &= 0xffff;
  190634. *dest++ = l;
  190635. }
  190636. dest = (int*)lpbuf2;
  190637. while (--samples2 >= 0)
  190638. {
  190639. int l = roundToInt (gainL * *left++);
  190640. if (l < -32768)
  190641. l = -32768;
  190642. else if (l > 32767)
  190643. l = 32767;
  190644. l &= 0xffff;
  190645. *dest++ = l;
  190646. }
  190647. }
  190648. else
  190649. {
  190650. while (--samples1 >= 0)
  190651. {
  190652. int l = roundToInt (gainL * *left++);
  190653. if (l < -32768)
  190654. l = -32768;
  190655. else if (l > 32767)
  190656. l = 32767;
  190657. l &= 0xffff;
  190658. int r = roundToInt (gainR * *right++);
  190659. if (r < -32768)
  190660. r = -32768;
  190661. else if (r > 32767)
  190662. r = 32767;
  190663. *dest++ = (r << 16) | l;
  190664. }
  190665. dest = (int*)lpbuf2;
  190666. while (--samples2 >= 0)
  190667. {
  190668. int l = roundToInt (gainL * *left++);
  190669. if (l < -32768)
  190670. l = -32768;
  190671. else if (l > 32767)
  190672. l = 32767;
  190673. l &= 0xffff;
  190674. int r = roundToInt (gainR * *right++);
  190675. if (r < -32768)
  190676. r = -32768;
  190677. else if (r > 32767)
  190678. r = 32767;
  190679. *dest++ = (r << 16) | l;
  190680. }
  190681. }
  190682. }
  190683. else
  190684. {
  190685. jassertfalse
  190686. }
  190687. writeOffset = (writeOffset + dwSize1 + dwSize2) % totalBytesPerBuffer;
  190688. pOutputBuffer->Unlock (lpbuf1, dwSize1, lpbuf2, dwSize2);
  190689. }
  190690. else
  190691. {
  190692. jassertfalse
  190693. logError (hr);
  190694. }
  190695. bytesEmpty -= bytesPerBuffer;
  190696. return true;
  190697. }
  190698. else
  190699. {
  190700. return false;
  190701. }
  190702. }
  190703. };
  190704. struct DSoundInternalInChannel
  190705. {
  190706. String name;
  190707. LPGUID guid;
  190708. int sampleRate, bufferSizeSamples;
  190709. float* leftBuffer;
  190710. float* rightBuffer;
  190711. IDirectSound* pDirectSound;
  190712. IDirectSoundCapture* pDirectSoundCapture;
  190713. IDirectSoundCaptureBuffer* pInputBuffer;
  190714. public:
  190715. unsigned int readOffset;
  190716. int bytesPerBuffer, totalBytesPerBuffer;
  190717. int bitDepth;
  190718. bool doneFlag;
  190719. DSoundInternalInChannel (const String& name_,
  190720. LPGUID guid_,
  190721. int rate,
  190722. int bufferSize,
  190723. float* left,
  190724. float* right)
  190725. : name (name_),
  190726. guid (guid_),
  190727. sampleRate (rate),
  190728. bufferSizeSamples (bufferSize),
  190729. leftBuffer (left),
  190730. rightBuffer (right),
  190731. pDirectSound (0),
  190732. pDirectSoundCapture (0),
  190733. pInputBuffer (0),
  190734. bitDepth (16)
  190735. {
  190736. }
  190737. ~DSoundInternalInChannel()
  190738. {
  190739. close();
  190740. }
  190741. void close()
  190742. {
  190743. HRESULT hr;
  190744. if (pInputBuffer != 0)
  190745. {
  190746. JUCE_TRY
  190747. {
  190748. log (T("closing dsound in: ") + name);
  190749. hr = pInputBuffer->Stop();
  190750. logError (hr);
  190751. }
  190752. CATCH
  190753. JUCE_TRY
  190754. {
  190755. hr = pInputBuffer->Release();
  190756. logError (hr);
  190757. }
  190758. CATCH
  190759. pInputBuffer = 0;
  190760. }
  190761. if (pDirectSoundCapture != 0)
  190762. {
  190763. JUCE_TRY
  190764. {
  190765. hr = pDirectSoundCapture->Release();
  190766. logError (hr);
  190767. }
  190768. CATCH
  190769. pDirectSoundCapture = 0;
  190770. }
  190771. if (pDirectSound != 0)
  190772. {
  190773. JUCE_TRY
  190774. {
  190775. hr = pDirectSound->Release();
  190776. logError (hr);
  190777. }
  190778. CATCH
  190779. pDirectSound = 0;
  190780. }
  190781. }
  190782. const String open()
  190783. {
  190784. log (T("opening dsound in device: ") + name
  190785. + T(" rate=") + String (sampleRate) + T(" bits=") + String (bitDepth) + T(" buf=") + String (bufferSizeSamples));
  190786. pDirectSound = 0;
  190787. pDirectSoundCapture = 0;
  190788. pInputBuffer = 0;
  190789. readOffset = 0;
  190790. totalBytesPerBuffer = 0;
  190791. String error;
  190792. HRESULT hr = E_NOINTERFACE;
  190793. if (dsDirectSoundCaptureCreate != 0)
  190794. hr = dsDirectSoundCaptureCreate (guid, &pDirectSoundCapture, 0);
  190795. logError (hr);
  190796. if (hr == S_OK)
  190797. {
  190798. const int numChannels = 2;
  190799. bytesPerBuffer = (bufferSizeSamples * (bitDepth >> 2)) & ~15;
  190800. totalBytesPerBuffer = (3 * bytesPerBuffer) & ~15;
  190801. WAVEFORMATEX wfFormat;
  190802. wfFormat.wFormatTag = WAVE_FORMAT_PCM;
  190803. wfFormat.nChannels = (unsigned short)numChannels;
  190804. wfFormat.nSamplesPerSec = sampleRate;
  190805. wfFormat.wBitsPerSample = (unsigned short)bitDepth;
  190806. wfFormat.nBlockAlign = (unsigned short)(wfFormat.nChannels * (wfFormat.wBitsPerSample / 8));
  190807. wfFormat.nAvgBytesPerSec = wfFormat.nSamplesPerSec * wfFormat.nBlockAlign;
  190808. wfFormat.cbSize = 0;
  190809. DSCBUFFERDESC captureDesc;
  190810. zerostruct (captureDesc);
  190811. captureDesc.dwSize = sizeof (DSCBUFFERDESC);
  190812. captureDesc.dwFlags = 0;
  190813. captureDesc.dwBufferBytes = totalBytesPerBuffer;
  190814. captureDesc.lpwfxFormat = &wfFormat;
  190815. log (T("opening dsound in step 2"));
  190816. hr = pDirectSoundCapture->CreateCaptureBuffer (&captureDesc, &pInputBuffer, 0);
  190817. logError (hr);
  190818. if (hr == S_OK)
  190819. {
  190820. hr = pInputBuffer->Start (1 /* DSCBSTART_LOOPING */);
  190821. logError (hr);
  190822. if (hr == S_OK)
  190823. return String::empty;
  190824. }
  190825. }
  190826. error = getDSErrorMessage (hr);
  190827. close();
  190828. return error;
  190829. }
  190830. void synchronisePosition()
  190831. {
  190832. if (pInputBuffer != 0)
  190833. {
  190834. DWORD capturePos;
  190835. pInputBuffer->GetCurrentPosition (&capturePos, (DWORD*)&readOffset);
  190836. }
  190837. }
  190838. bool service()
  190839. {
  190840. if (pInputBuffer == 0)
  190841. return true;
  190842. DWORD capturePos, readPos;
  190843. HRESULT hr = pInputBuffer->GetCurrentPosition (&capturePos, &readPos);
  190844. logError (hr);
  190845. if (hr != S_OK)
  190846. return true;
  190847. int bytesFilled = readPos - readOffset;
  190848. if (bytesFilled < 0)
  190849. bytesFilled += totalBytesPerBuffer;
  190850. if (bytesFilled >= bytesPerBuffer)
  190851. {
  190852. LPBYTE lpbuf1 = 0;
  190853. LPBYTE lpbuf2 = 0;
  190854. DWORD dwsize1 = 0;
  190855. DWORD dwsize2 = 0;
  190856. HRESULT hr = pInputBuffer->Lock (readOffset,
  190857. bytesPerBuffer,
  190858. (void**) &lpbuf1, &dwsize1,
  190859. (void**) &lpbuf2, &dwsize2, 0);
  190860. if (hr == S_OK)
  190861. {
  190862. if (bitDepth == 16)
  190863. {
  190864. const float g = 1.0f / 32768.0f;
  190865. float* destL = leftBuffer;
  190866. float* destR = rightBuffer;
  190867. int samples1 = dwsize1 >> 2;
  190868. int samples2 = dwsize2 >> 2;
  190869. const short* src = (const short*)lpbuf1;
  190870. if (destL == 0)
  190871. {
  190872. while (--samples1 >= 0)
  190873. {
  190874. ++src;
  190875. *destR++ = *src++ * g;
  190876. }
  190877. src = (const short*)lpbuf2;
  190878. while (--samples2 >= 0)
  190879. {
  190880. ++src;
  190881. *destR++ = *src++ * g;
  190882. }
  190883. }
  190884. else if (destR == 0)
  190885. {
  190886. while (--samples1 >= 0)
  190887. {
  190888. *destL++ = *src++ * g;
  190889. ++src;
  190890. }
  190891. src = (const short*)lpbuf2;
  190892. while (--samples2 >= 0)
  190893. {
  190894. *destL++ = *src++ * g;
  190895. ++src;
  190896. }
  190897. }
  190898. else
  190899. {
  190900. while (--samples1 >= 0)
  190901. {
  190902. *destL++ = *src++ * g;
  190903. *destR++ = *src++ * g;
  190904. }
  190905. src = (const short*)lpbuf2;
  190906. while (--samples2 >= 0)
  190907. {
  190908. *destL++ = *src++ * g;
  190909. *destR++ = *src++ * g;
  190910. }
  190911. }
  190912. }
  190913. else
  190914. {
  190915. jassertfalse
  190916. }
  190917. readOffset = (readOffset + dwsize1 + dwsize2) % totalBytesPerBuffer;
  190918. pInputBuffer->Unlock (lpbuf1, dwsize1, lpbuf2, dwsize2);
  190919. }
  190920. else
  190921. {
  190922. logError (hr);
  190923. jassertfalse
  190924. }
  190925. bytesFilled -= bytesPerBuffer;
  190926. return true;
  190927. }
  190928. else
  190929. {
  190930. return false;
  190931. }
  190932. }
  190933. };
  190934. class DSoundAudioIODevice : public AudioIODevice,
  190935. public Thread
  190936. {
  190937. public:
  190938. DSoundAudioIODevice (const String& deviceName,
  190939. const int outputDeviceIndex_,
  190940. const int inputDeviceIndex_)
  190941. : AudioIODevice (deviceName, "DirectSound"),
  190942. Thread ("Juce DSound"),
  190943. isOpen_ (false),
  190944. isStarted (false),
  190945. outputDeviceIndex (outputDeviceIndex_),
  190946. inputDeviceIndex (inputDeviceIndex_),
  190947. numInputBuffers (0),
  190948. numOutputBuffers (0),
  190949. totalSamplesOut (0),
  190950. sampleRate (0.0),
  190951. inputBuffers (0),
  190952. outputBuffers (0),
  190953. callback (0),
  190954. bufferSizeSamples (0)
  190955. {
  190956. if (outputDeviceIndex_ >= 0)
  190957. {
  190958. outChannels.add (TRANS("Left"));
  190959. outChannels.add (TRANS("Right"));
  190960. }
  190961. if (inputDeviceIndex_ >= 0)
  190962. {
  190963. inChannels.add (TRANS("Left"));
  190964. inChannels.add (TRANS("Right"));
  190965. }
  190966. }
  190967. ~DSoundAudioIODevice()
  190968. {
  190969. close();
  190970. }
  190971. const StringArray getOutputChannelNames()
  190972. {
  190973. return outChannels;
  190974. }
  190975. const StringArray getInputChannelNames()
  190976. {
  190977. return inChannels;
  190978. }
  190979. int getNumSampleRates()
  190980. {
  190981. return 4;
  190982. }
  190983. double getSampleRate (int index)
  190984. {
  190985. const double samps[] = { 44100.0, 48000.0, 88200.0, 96000.0 };
  190986. return samps [jlimit (0, 3, index)];
  190987. }
  190988. int getNumBufferSizesAvailable()
  190989. {
  190990. return 50;
  190991. }
  190992. int getBufferSizeSamples (int index)
  190993. {
  190994. int n = 64;
  190995. for (int i = 0; i < index; ++i)
  190996. n += (n < 512) ? 32
  190997. : ((n < 1024) ? 64
  190998. : ((n < 2048) ? 128 : 256));
  190999. return n;
  191000. }
  191001. int getDefaultBufferSize()
  191002. {
  191003. return 2560;
  191004. }
  191005. const String open (const BitArray& inputChannels,
  191006. const BitArray& outputChannels,
  191007. double sampleRate,
  191008. int bufferSizeSamples)
  191009. {
  191010. lastError = openDevice (inputChannels, outputChannels, sampleRate, bufferSizeSamples);
  191011. isOpen_ = lastError.isEmpty();
  191012. return lastError;
  191013. }
  191014. void close()
  191015. {
  191016. stop();
  191017. if (isOpen_)
  191018. {
  191019. closeDevice();
  191020. isOpen_ = false;
  191021. }
  191022. }
  191023. bool isOpen()
  191024. {
  191025. return isOpen_ && isThreadRunning();
  191026. }
  191027. int getCurrentBufferSizeSamples()
  191028. {
  191029. return bufferSizeSamples;
  191030. }
  191031. double getCurrentSampleRate()
  191032. {
  191033. return sampleRate;
  191034. }
  191035. int getCurrentBitDepth()
  191036. {
  191037. int i, bits = 256;
  191038. for (i = inChans.size(); --i >= 0;)
  191039. bits = jmin (bits, inChans[i]->bitDepth);
  191040. for (i = outChans.size(); --i >= 0;)
  191041. bits = jmin (bits, outChans[i]->bitDepth);
  191042. if (bits > 32)
  191043. bits = 16;
  191044. return bits;
  191045. }
  191046. const BitArray getActiveOutputChannels() const
  191047. {
  191048. return enabledOutputs;
  191049. }
  191050. const BitArray getActiveInputChannels() const
  191051. {
  191052. return enabledInputs;
  191053. }
  191054. int getOutputLatencyInSamples()
  191055. {
  191056. return (int) (getCurrentBufferSizeSamples() * 1.5);
  191057. }
  191058. int getInputLatencyInSamples()
  191059. {
  191060. return getOutputLatencyInSamples();
  191061. }
  191062. void start (AudioIODeviceCallback* call)
  191063. {
  191064. if (isOpen_ && call != 0 && ! isStarted)
  191065. {
  191066. if (! isThreadRunning())
  191067. {
  191068. // something gone wrong and the thread's stopped..
  191069. isOpen_ = false;
  191070. return;
  191071. }
  191072. call->audioDeviceAboutToStart (this);
  191073. const ScopedLock sl (startStopLock);
  191074. callback = call;
  191075. isStarted = true;
  191076. }
  191077. }
  191078. void stop()
  191079. {
  191080. if (isStarted)
  191081. {
  191082. AudioIODeviceCallback* const callbackLocal = callback;
  191083. {
  191084. const ScopedLock sl (startStopLock);
  191085. isStarted = false;
  191086. }
  191087. if (callbackLocal != 0)
  191088. callbackLocal->audioDeviceStopped();
  191089. }
  191090. }
  191091. bool isPlaying()
  191092. {
  191093. return isStarted && isOpen_ && isThreadRunning();
  191094. }
  191095. const String getLastError()
  191096. {
  191097. return lastError;
  191098. }
  191099. juce_UseDebuggingNewOperator
  191100. StringArray inChannels, outChannels;
  191101. int outputDeviceIndex, inputDeviceIndex;
  191102. private:
  191103. bool isOpen_;
  191104. bool isStarted;
  191105. String lastError;
  191106. OwnedArray <DSoundInternalInChannel> inChans;
  191107. OwnedArray <DSoundInternalOutChannel> outChans;
  191108. WaitableEvent startEvent;
  191109. int numInputBuffers, numOutputBuffers, bufferSizeSamples;
  191110. int volatile totalSamplesOut;
  191111. int64 volatile lastBlockTime;
  191112. double sampleRate;
  191113. BitArray enabledInputs, enabledOutputs;
  191114. HeapBlock <float*> inputBuffers, outputBuffers;
  191115. AudioIODeviceCallback* callback;
  191116. CriticalSection startStopLock;
  191117. DSoundAudioIODevice (const DSoundAudioIODevice&);
  191118. const DSoundAudioIODevice& operator= (const DSoundAudioIODevice&);
  191119. const String openDevice (const BitArray& inputChannels,
  191120. const BitArray& outputChannels,
  191121. double sampleRate_,
  191122. int bufferSizeSamples_);
  191123. void closeDevice()
  191124. {
  191125. isStarted = false;
  191126. stopThread (5000);
  191127. inChans.clear();
  191128. outChans.clear();
  191129. int i;
  191130. for (i = 0; i < numInputBuffers; ++i)
  191131. juce_free (inputBuffers[i]);
  191132. inputBuffers.free();
  191133. numInputBuffers = 0;
  191134. for (i = 0; i < numOutputBuffers; ++i)
  191135. juce_free (outputBuffers[i]);
  191136. outputBuffers.free();
  191137. numOutputBuffers = 0;
  191138. }
  191139. void resync()
  191140. {
  191141. if (! threadShouldExit())
  191142. {
  191143. sleep (5);
  191144. int i;
  191145. for (i = 0; i < outChans.size(); ++i)
  191146. outChans.getUnchecked(i)->synchronisePosition();
  191147. for (i = 0; i < inChans.size(); ++i)
  191148. inChans.getUnchecked(i)->synchronisePosition();
  191149. }
  191150. }
  191151. public:
  191152. void run()
  191153. {
  191154. while (! threadShouldExit())
  191155. {
  191156. if (wait (100))
  191157. break;
  191158. }
  191159. const int latencyMs = (int) (bufferSizeSamples * 1000.0 / sampleRate);
  191160. const int maxTimeMS = jmax (5, 3 * latencyMs);
  191161. while (! threadShouldExit())
  191162. {
  191163. int numToDo = 0;
  191164. uint32 startTime = Time::getMillisecondCounter();
  191165. int i;
  191166. for (i = inChans.size(); --i >= 0;)
  191167. {
  191168. inChans.getUnchecked(i)->doneFlag = false;
  191169. ++numToDo;
  191170. }
  191171. for (i = outChans.size(); --i >= 0;)
  191172. {
  191173. outChans.getUnchecked(i)->doneFlag = false;
  191174. ++numToDo;
  191175. }
  191176. if (numToDo > 0)
  191177. {
  191178. const int maxCount = 3;
  191179. int count = maxCount;
  191180. for (;;)
  191181. {
  191182. for (i = inChans.size(); --i >= 0;)
  191183. {
  191184. DSoundInternalInChannel* const in = inChans.getUnchecked(i);
  191185. if ((! in->doneFlag) && in->service())
  191186. {
  191187. in->doneFlag = true;
  191188. --numToDo;
  191189. }
  191190. }
  191191. for (i = outChans.size(); --i >= 0;)
  191192. {
  191193. DSoundInternalOutChannel* const out = outChans.getUnchecked(i);
  191194. if ((! out->doneFlag) && out->service())
  191195. {
  191196. out->doneFlag = true;
  191197. --numToDo;
  191198. }
  191199. }
  191200. if (numToDo <= 0)
  191201. break;
  191202. if (Time::getMillisecondCounter() > startTime + maxTimeMS)
  191203. {
  191204. resync();
  191205. break;
  191206. }
  191207. if (--count <= 0)
  191208. {
  191209. Sleep (1);
  191210. count = maxCount;
  191211. }
  191212. if (threadShouldExit())
  191213. return;
  191214. }
  191215. }
  191216. else
  191217. {
  191218. sleep (1);
  191219. }
  191220. const ScopedLock sl (startStopLock);
  191221. if (isStarted)
  191222. {
  191223. JUCE_TRY
  191224. {
  191225. callback->audioDeviceIOCallback ((const float**) inputBuffers,
  191226. numInputBuffers,
  191227. outputBuffers,
  191228. numOutputBuffers,
  191229. bufferSizeSamples);
  191230. }
  191231. JUCE_CATCH_EXCEPTION
  191232. totalSamplesOut += bufferSizeSamples;
  191233. }
  191234. else
  191235. {
  191236. for (i = 0; i < numOutputBuffers; ++i)
  191237. if (outputBuffers[i] != 0)
  191238. zeromem (outputBuffers[i], bufferSizeSamples * sizeof (float));
  191239. totalSamplesOut = 0;
  191240. sleep (1);
  191241. }
  191242. }
  191243. }
  191244. };
  191245. class DSoundAudioIODeviceType : public AudioIODeviceType
  191246. {
  191247. public:
  191248. DSoundAudioIODeviceType()
  191249. : AudioIODeviceType (T("DirectSound")),
  191250. hasScanned (false)
  191251. {
  191252. initialiseDSoundFunctions();
  191253. }
  191254. ~DSoundAudioIODeviceType()
  191255. {
  191256. }
  191257. void scanForDevices()
  191258. {
  191259. hasScanned = true;
  191260. outputDeviceNames.clear();
  191261. outputGuids.clear();
  191262. inputDeviceNames.clear();
  191263. inputGuids.clear();
  191264. if (dsDirectSoundEnumerateW != 0)
  191265. {
  191266. dsDirectSoundEnumerateW (outputEnumProcW, this);
  191267. dsDirectSoundCaptureEnumerateW (inputEnumProcW, this);
  191268. }
  191269. }
  191270. const StringArray getDeviceNames (const bool wantInputNames) const
  191271. {
  191272. jassert (hasScanned); // need to call scanForDevices() before doing this
  191273. return wantInputNames ? inputDeviceNames
  191274. : outputDeviceNames;
  191275. }
  191276. int getDefaultDeviceIndex (const bool /*forInput*/) const
  191277. {
  191278. jassert (hasScanned); // need to call scanForDevices() before doing this
  191279. return 0;
  191280. }
  191281. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  191282. {
  191283. jassert (hasScanned); // need to call scanForDevices() before doing this
  191284. DSoundAudioIODevice* const d = dynamic_cast <DSoundAudioIODevice*> (device);
  191285. if (d == 0)
  191286. return -1;
  191287. return asInput ? d->inputDeviceIndex
  191288. : d->outputDeviceIndex;
  191289. }
  191290. bool hasSeparateInputsAndOutputs() const { return true; }
  191291. AudioIODevice* createDevice (const String& outputDeviceName,
  191292. const String& inputDeviceName)
  191293. {
  191294. jassert (hasScanned); // need to call scanForDevices() before doing this
  191295. const int outputIndex = outputDeviceNames.indexOf (outputDeviceName);
  191296. const int inputIndex = inputDeviceNames.indexOf (inputDeviceName);
  191297. if (outputIndex >= 0 || inputIndex >= 0)
  191298. return new DSoundAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  191299. : inputDeviceName,
  191300. outputIndex, inputIndex);
  191301. return 0;
  191302. }
  191303. juce_UseDebuggingNewOperator
  191304. StringArray outputDeviceNames;
  191305. OwnedArray <GUID> outputGuids;
  191306. StringArray inputDeviceNames;
  191307. OwnedArray <GUID> inputGuids;
  191308. private:
  191309. bool hasScanned;
  191310. BOOL outputEnumProc (LPGUID lpGUID, String desc)
  191311. {
  191312. desc = desc.trim();
  191313. if (desc.isNotEmpty())
  191314. {
  191315. const String origDesc (desc);
  191316. int n = 2;
  191317. while (outputDeviceNames.contains (desc))
  191318. desc = origDesc + T(" (") + String (n++) + T(")");
  191319. outputDeviceNames.add (desc);
  191320. if (lpGUID != 0)
  191321. outputGuids.add (new GUID (*lpGUID));
  191322. else
  191323. outputGuids.add (0);
  191324. }
  191325. return TRUE;
  191326. }
  191327. static BOOL CALLBACK outputEnumProcW (LPGUID lpGUID, LPCWSTR description, LPCWSTR, LPVOID object)
  191328. {
  191329. return ((DSoundAudioIODeviceType*) object)
  191330. ->outputEnumProc (lpGUID, String (description));
  191331. }
  191332. static BOOL CALLBACK outputEnumProcA (LPGUID lpGUID, LPCTSTR description, LPCTSTR, LPVOID object)
  191333. {
  191334. return ((DSoundAudioIODeviceType*) object)
  191335. ->outputEnumProc (lpGUID, String (description));
  191336. }
  191337. BOOL CALLBACK inputEnumProc (LPGUID lpGUID, String desc)
  191338. {
  191339. desc = desc.trim();
  191340. if (desc.isNotEmpty())
  191341. {
  191342. const String origDesc (desc);
  191343. int n = 2;
  191344. while (inputDeviceNames.contains (desc))
  191345. desc = origDesc + T(" (") + String (n++) + T(")");
  191346. inputDeviceNames.add (desc);
  191347. if (lpGUID != 0)
  191348. inputGuids.add (new GUID (*lpGUID));
  191349. else
  191350. inputGuids.add (0);
  191351. }
  191352. return TRUE;
  191353. }
  191354. static BOOL CALLBACK inputEnumProcW (LPGUID lpGUID, LPCWSTR description, LPCWSTR, LPVOID object)
  191355. {
  191356. return ((DSoundAudioIODeviceType*) object)
  191357. ->inputEnumProc (lpGUID, String (description));
  191358. }
  191359. static BOOL CALLBACK inputEnumProcA (LPGUID lpGUID, LPCTSTR description, LPCTSTR, LPVOID object)
  191360. {
  191361. return ((DSoundAudioIODeviceType*) object)
  191362. ->inputEnumProc (lpGUID, String (description));
  191363. }
  191364. DSoundAudioIODeviceType (const DSoundAudioIODeviceType&);
  191365. const DSoundAudioIODeviceType& operator= (const DSoundAudioIODeviceType&);
  191366. };
  191367. const String DSoundAudioIODevice::openDevice (const BitArray& inputChannels,
  191368. const BitArray& outputChannels,
  191369. double sampleRate_,
  191370. int bufferSizeSamples_)
  191371. {
  191372. closeDevice();
  191373. totalSamplesOut = 0;
  191374. sampleRate = sampleRate_;
  191375. if (bufferSizeSamples_ <= 0)
  191376. bufferSizeSamples_ = 960; // use as a default size if none is set.
  191377. bufferSizeSamples = bufferSizeSamples_ & ~7;
  191378. DSoundAudioIODeviceType dlh;
  191379. dlh.scanForDevices();
  191380. enabledInputs = inputChannels;
  191381. enabledInputs.setRange (inChannels.size(),
  191382. enabledInputs.getHighestBit() + 1 - inChannels.size(),
  191383. false);
  191384. numInputBuffers = enabledInputs.countNumberOfSetBits();
  191385. inputBuffers.calloc (numInputBuffers + 2);
  191386. int i, numIns = 0;
  191387. for (i = 0; i <= enabledInputs.getHighestBit(); i += 2)
  191388. {
  191389. float* left = 0;
  191390. float* right = 0;
  191391. if (enabledInputs[i])
  191392. left = inputBuffers[numIns++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  191393. if (enabledInputs[i + 1])
  191394. right = inputBuffers[numIns++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  191395. if (left != 0 || right != 0)
  191396. inChans.add (new DSoundInternalInChannel (dlh.inputDeviceNames [inputDeviceIndex],
  191397. dlh.inputGuids [inputDeviceIndex],
  191398. (int) sampleRate, bufferSizeSamples,
  191399. left, right));
  191400. }
  191401. enabledOutputs = outputChannels;
  191402. enabledOutputs.setRange (outChannels.size(),
  191403. enabledOutputs.getHighestBit() + 1 - outChannels.size(),
  191404. false);
  191405. numOutputBuffers = enabledOutputs.countNumberOfSetBits();
  191406. outputBuffers.calloc (numOutputBuffers + 2);
  191407. int numOuts = 0;
  191408. for (i = 0; i <= enabledOutputs.getHighestBit(); i += 2)
  191409. {
  191410. float* left = 0;
  191411. float* right = 0;
  191412. if (enabledOutputs[i])
  191413. left = outputBuffers[numOuts++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  191414. if (enabledOutputs[i + 1])
  191415. right = outputBuffers[numOuts++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  191416. if (left != 0 || right != 0)
  191417. outChans.add (new DSoundInternalOutChannel (dlh.outputDeviceNames[outputDeviceIndex],
  191418. dlh.outputGuids [outputDeviceIndex],
  191419. (int) sampleRate, bufferSizeSamples,
  191420. left, right));
  191421. }
  191422. String error;
  191423. // boost our priority while opening the devices to try to get better sync between them
  191424. const int oldThreadPri = GetThreadPriority (GetCurrentThread());
  191425. const int oldProcPri = GetPriorityClass (GetCurrentProcess());
  191426. SetThreadPriority (GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
  191427. SetPriorityClass (GetCurrentProcess(), REALTIME_PRIORITY_CLASS);
  191428. for (i = 0; i < outChans.size(); ++i)
  191429. {
  191430. error = outChans[i]->open();
  191431. if (error.isNotEmpty())
  191432. {
  191433. error = T("Error opening ") + dlh.outputDeviceNames[i]
  191434. + T(": \"") + error + T("\"");
  191435. break;
  191436. }
  191437. }
  191438. if (error.isEmpty())
  191439. {
  191440. for (i = 0; i < inChans.size(); ++i)
  191441. {
  191442. error = inChans[i]->open();
  191443. if (error.isNotEmpty())
  191444. {
  191445. error = T("Error opening ") + dlh.inputDeviceNames[i]
  191446. + T(": \"") + error + T("\"");
  191447. break;
  191448. }
  191449. }
  191450. }
  191451. if (error.isEmpty())
  191452. {
  191453. totalSamplesOut = 0;
  191454. for (i = 0; i < outChans.size(); ++i)
  191455. outChans.getUnchecked(i)->synchronisePosition();
  191456. for (i = 0; i < inChans.size(); ++i)
  191457. inChans.getUnchecked(i)->synchronisePosition();
  191458. startThread (9);
  191459. sleep (10);
  191460. notify();
  191461. }
  191462. else
  191463. {
  191464. log (error);
  191465. }
  191466. SetThreadPriority (GetCurrentThread(), oldThreadPri);
  191467. SetPriorityClass (GetCurrentProcess(), oldProcPri);
  191468. return error;
  191469. }
  191470. AudioIODeviceType* juce_createAudioIODeviceType_DirectSound()
  191471. {
  191472. return new DSoundAudioIODeviceType();
  191473. }
  191474. #undef log
  191475. #endif
  191476. /*** End of inlined file: juce_win32_DirectSound.cpp ***/
  191477. /*** Start of inlined file: juce_win32_WASAPI.cpp ***/
  191478. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  191479. // compiled on its own).
  191480. #if JUCE_INCLUDED_FILE && JUCE_WASAPI
  191481. #if 1
  191482. const String getAudioErrorDesc (HRESULT hr)
  191483. {
  191484. const char* e = 0;
  191485. switch (hr)
  191486. {
  191487. case E_POINTER: e = "E_POINTER"; break;
  191488. case E_INVALIDARG: e = "E_INVALIDARG"; break;
  191489. case AUDCLNT_E_NOT_INITIALIZED: e = "AUDCLNT_E_NOT_INITIALIZED"; break;
  191490. case AUDCLNT_E_ALREADY_INITIALIZED: e = "AUDCLNT_E_ALREADY_INITIALIZED"; break;
  191491. case AUDCLNT_E_WRONG_ENDPOINT_TYPE: e = "AUDCLNT_E_WRONG_ENDPOINT_TYPE"; break;
  191492. case AUDCLNT_E_DEVICE_INVALIDATED: e = "AUDCLNT_E_DEVICE_INVALIDATED"; break;
  191493. case AUDCLNT_E_NOT_STOPPED: e = "AUDCLNT_E_NOT_STOPPED"; break;
  191494. case AUDCLNT_E_BUFFER_TOO_LARGE: e = "AUDCLNT_E_BUFFER_TOO_LARGE"; break;
  191495. case AUDCLNT_E_OUT_OF_ORDER: e = "AUDCLNT_E_OUT_OF_ORDER"; break;
  191496. case AUDCLNT_E_UNSUPPORTED_FORMAT: e = "AUDCLNT_E_UNSUPPORTED_FORMAT"; break;
  191497. case AUDCLNT_E_INVALID_SIZE: e = "AUDCLNT_E_INVALID_SIZE"; break;
  191498. case AUDCLNT_E_DEVICE_IN_USE: e = "AUDCLNT_E_DEVICE_IN_USE"; break;
  191499. case AUDCLNT_E_BUFFER_OPERATION_PENDING: e = "AUDCLNT_E_BUFFER_OPERATION_PENDING"; break;
  191500. case AUDCLNT_E_THREAD_NOT_REGISTERED: e = "AUDCLNT_E_THREAD_NOT_REGISTERED"; break;
  191501. case AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED: e = "AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED"; break;
  191502. case AUDCLNT_E_ENDPOINT_CREATE_FAILED: e = "AUDCLNT_E_ENDPOINT_CREATE_FAILED"; break;
  191503. case AUDCLNT_E_SERVICE_NOT_RUNNING: e = "AUDCLNT_E_SERVICE_NOT_RUNNING"; break;
  191504. case AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED: e = "AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED"; break;
  191505. case AUDCLNT_E_EXCLUSIVE_MODE_ONLY: e = "AUDCLNT_E_EXCLUSIVE_MODE_ONLY"; break;
  191506. case AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL: e = "AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL"; break;
  191507. case AUDCLNT_E_EVENTHANDLE_NOT_SET: e = "AUDCLNT_E_EVENTHANDLE_NOT_SET"; break;
  191508. case AUDCLNT_E_INCORRECT_BUFFER_SIZE: e = "AUDCLNT_E_INCORRECT_BUFFER_SIZE"; break;
  191509. case AUDCLNT_E_BUFFER_SIZE_ERROR: e = "AUDCLNT_E_BUFFER_SIZE_ERROR"; break;
  191510. case AUDCLNT_S_BUFFER_EMPTY: e = "AUDCLNT_S_BUFFER_EMPTY"; break;
  191511. case AUDCLNT_S_THREAD_ALREADY_REGISTERED: e = "AUDCLNT_S_THREAD_ALREADY_REGISTERED"; break;
  191512. default: return String::toHexString ((int) hr);
  191513. }
  191514. return e;
  191515. }
  191516. #define logFailure(hr) { if (FAILED (hr)) { DBG ("WASAPI FAIL! " + getAudioErrorDesc (hr)); jassertfalse } }
  191517. #define OK(a) wasapi_checkResult(a)
  191518. static bool wasapi_checkResult (HRESULT hr)
  191519. {
  191520. logFailure (hr);
  191521. return SUCCEEDED (hr);
  191522. }
  191523. #else
  191524. #define logFailure(hr) {}
  191525. #define OK(a) SUCCEEDED(a)
  191526. #endif
  191527. static const String wasapi_getDeviceID (IMMDevice* const device)
  191528. {
  191529. String s;
  191530. WCHAR* deviceId = 0;
  191531. if (OK (device->GetId (&deviceId)))
  191532. {
  191533. s = String (deviceId);
  191534. CoTaskMemFree (deviceId);
  191535. }
  191536. return s;
  191537. }
  191538. static EDataFlow wasapi_getDataFlow (IMMDevice* const device)
  191539. {
  191540. EDataFlow flow = eRender;
  191541. ComSmartPtr <IMMEndpoint> endPoint;
  191542. if (OK (device->QueryInterface (__uuidof (IMMEndpoint), (void**) &endPoint)))
  191543. (void) OK (endPoint->GetDataFlow (&flow));
  191544. return flow;
  191545. }
  191546. static int wasapi_refTimeToSamples (const REFERENCE_TIME& t, const double sampleRate) throw()
  191547. {
  191548. return roundDoubleToInt (sampleRate * ((double) t) * 0.0000001);
  191549. }
  191550. static void wasapi_copyWavFormat (WAVEFORMATEXTENSIBLE& dest, const WAVEFORMATEX* const src) throw()
  191551. {
  191552. memcpy (&dest, src, src->wFormatTag == WAVE_FORMAT_EXTENSIBLE ? sizeof (WAVEFORMATEXTENSIBLE)
  191553. : sizeof (WAVEFORMATEX));
  191554. }
  191555. class WASAPIDeviceBase
  191556. {
  191557. public:
  191558. WASAPIDeviceBase (const ComSmartPtr <IMMDevice>& device_, const bool useExclusiveMode_)
  191559. : device (device_),
  191560. sampleRate (0),
  191561. numChannels (0),
  191562. actualNumChannels (0),
  191563. defaultSampleRate (0),
  191564. minBufferSize (0),
  191565. defaultBufferSize (0),
  191566. latencySamples (0),
  191567. useExclusiveMode (useExclusiveMode_)
  191568. {
  191569. clientEvent = CreateEvent (0, false, false, _T("JuceWASAPI"));
  191570. ComSmartPtr <IAudioClient> tempClient (createClient());
  191571. if (tempClient == 0)
  191572. return;
  191573. REFERENCE_TIME defaultPeriod, minPeriod;
  191574. if (! OK (tempClient->GetDevicePeriod (&defaultPeriod, &minPeriod)))
  191575. return;
  191576. WAVEFORMATEX* mixFormat = 0;
  191577. if (! OK (tempClient->GetMixFormat (&mixFormat)))
  191578. return;
  191579. WAVEFORMATEXTENSIBLE format;
  191580. wasapi_copyWavFormat (format, mixFormat);
  191581. CoTaskMemFree (mixFormat);
  191582. actualNumChannels = numChannels = format.Format.nChannels;
  191583. defaultSampleRate = format.Format.nSamplesPerSec;
  191584. minBufferSize = wasapi_refTimeToSamples (minPeriod, defaultSampleRate);
  191585. defaultBufferSize = wasapi_refTimeToSamples (defaultPeriod, defaultSampleRate);
  191586. FloatElementComparator<double> comparator;
  191587. rates.addSorted (comparator, defaultSampleRate);
  191588. static const double ratesToTest[] = { 44100.0, 48000.0, 88200.0, 96000.0 };
  191589. for (int i = 0; i < numElementsInArray (ratesToTest); ++i)
  191590. {
  191591. if (ratesToTest[i] == defaultSampleRate)
  191592. continue;
  191593. format.Format.nSamplesPerSec = roundDoubleToInt (ratesToTest[i]);
  191594. if (SUCCEEDED (tempClient->IsFormatSupported (useExclusiveMode ? AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE_SHARED,
  191595. (WAVEFORMATEX*) &format, 0)))
  191596. if (! rates.contains (ratesToTest[i]))
  191597. rates.addSorted (comparator, ratesToTest[i]);
  191598. }
  191599. }
  191600. ~WASAPIDeviceBase()
  191601. {
  191602. device = 0;
  191603. CloseHandle (clientEvent);
  191604. }
  191605. bool isOk() const throw() { return defaultBufferSize > 0 && defaultSampleRate > 0; }
  191606. bool openClient (const double newSampleRate, const BitArray& newChannels)
  191607. {
  191608. sampleRate = newSampleRate;
  191609. channels = newChannels;
  191610. channels.setRange (actualNumChannels, channels.getHighestBit() + 1 - actualNumChannels, false);
  191611. numChannels = channels.getHighestBit() + 1;
  191612. if (numChannels == 0)
  191613. return true;
  191614. client = createClient();
  191615. if (client != 0
  191616. && (tryInitialisingWithFormat (true, 4) || tryInitialisingWithFormat (false, 4)
  191617. || tryInitialisingWithFormat (false, 3) || tryInitialisingWithFormat (false, 2)))
  191618. {
  191619. channelMaps.clear();
  191620. for (int i = 0; i <= channels.getHighestBit(); ++i)
  191621. if (channels[i])
  191622. channelMaps.add (i);
  191623. REFERENCE_TIME latency;
  191624. if (OK (client->GetStreamLatency (&latency)))
  191625. latencySamples = wasapi_refTimeToSamples (latency, sampleRate);
  191626. (void) OK (client->GetBufferSize (&actualBufferSize));
  191627. return OK (client->SetEventHandle (clientEvent));
  191628. }
  191629. return false;
  191630. }
  191631. void closeClient()
  191632. {
  191633. if (client != 0)
  191634. client->Stop();
  191635. client = 0;
  191636. ResetEvent (clientEvent);
  191637. }
  191638. ComSmartPtr <IMMDevice> device;
  191639. ComSmartPtr <IAudioClient> client;
  191640. double sampleRate, defaultSampleRate;
  191641. int numChannels, actualNumChannels;
  191642. int minBufferSize, defaultBufferSize, latencySamples;
  191643. const bool useExclusiveMode;
  191644. Array <double> rates;
  191645. HANDLE clientEvent;
  191646. BitArray channels;
  191647. AudioDataConverters::DataFormat dataFormat;
  191648. Array <int> channelMaps;
  191649. UINT32 actualBufferSize;
  191650. int bytesPerSample;
  191651. private:
  191652. const ComSmartPtr <IAudioClient> createClient()
  191653. {
  191654. ComSmartPtr <IAudioClient> client;
  191655. if (device != 0)
  191656. {
  191657. HRESULT hr = device->Activate (__uuidof (IAudioClient), CLSCTX_INPROC_SERVER, 0, (void**) &client);
  191658. logFailure (hr);
  191659. }
  191660. return client;
  191661. }
  191662. bool tryInitialisingWithFormat (const bool useFloat, const int bytesPerSampleToTry)
  191663. {
  191664. WAVEFORMATEXTENSIBLE format;
  191665. zerostruct (format);
  191666. if (numChannels <= 2 && bytesPerSampleToTry <= 2)
  191667. {
  191668. format.Format.wFormatTag = WAVE_FORMAT_PCM;
  191669. }
  191670. else
  191671. {
  191672. format.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
  191673. format.Format.cbSize = sizeof (WAVEFORMATEXTENSIBLE) - sizeof (WAVEFORMATEX);
  191674. }
  191675. format.Format.nSamplesPerSec = roundDoubleToInt (sampleRate);
  191676. format.Format.nChannels = (WORD) numChannels;
  191677. format.Format.wBitsPerSample = (WORD) (8 * bytesPerSampleToTry);
  191678. format.Format.nAvgBytesPerSec = (DWORD) (format.Format.nSamplesPerSec * numChannels * bytesPerSampleToTry);
  191679. format.Format.nBlockAlign = (WORD) (numChannels * bytesPerSampleToTry);
  191680. format.SubFormat = useFloat ? KSDATAFORMAT_SUBTYPE_IEEE_FLOAT : KSDATAFORMAT_SUBTYPE_PCM;
  191681. format.Samples.wValidBitsPerSample = format.Format.wBitsPerSample;
  191682. switch (numChannels)
  191683. {
  191684. case 1: format.dwChannelMask = SPEAKER_FRONT_CENTER; break;
  191685. case 2: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT; break;
  191686. case 4: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT; break;
  191687. case 6: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | SPEAKER_LOW_FREQUENCY | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT; break;
  191688. 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;
  191689. default: break;
  191690. }
  191691. WAVEFORMATEXTENSIBLE* nearestFormat = 0;
  191692. HRESULT hr = client->IsFormatSupported (useExclusiveMode ? AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE_SHARED,
  191693. (WAVEFORMATEX*) &format, useExclusiveMode ? 0 : (WAVEFORMATEX**) &nearestFormat);
  191694. logFailure (hr);
  191695. if (hr == S_FALSE && format.Format.nSamplesPerSec == nearestFormat->Format.nSamplesPerSec)
  191696. {
  191697. wasapi_copyWavFormat (format, (WAVEFORMATEX*) nearestFormat);
  191698. hr = S_OK;
  191699. }
  191700. CoTaskMemFree (nearestFormat);
  191701. REFERENCE_TIME defaultPeriod = 0, minPeriod = 0;
  191702. if (useExclusiveMode)
  191703. OK (client->GetDevicePeriod (&defaultPeriod, &minPeriod));
  191704. GUID session;
  191705. if (hr == S_OK
  191706. && OK (client->Initialize (useExclusiveMode ? AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE_SHARED,
  191707. AUDCLNT_STREAMFLAGS_EVENTCALLBACK,
  191708. defaultPeriod, defaultPeriod, (WAVEFORMATEX*) &format, &session)))
  191709. {
  191710. actualNumChannels = format.Format.nChannels;
  191711. const bool isFloat = format.Format.wFormatTag == WAVE_FORMAT_EXTENSIBLE && format.SubFormat == KSDATAFORMAT_SUBTYPE_IEEE_FLOAT;
  191712. bytesPerSample = format.Format.wBitsPerSample / 8;
  191713. dataFormat = isFloat ? AudioDataConverters::float32LE
  191714. : (bytesPerSample == 4 ? AudioDataConverters::int32LE
  191715. : ((bytesPerSample == 3 ? AudioDataConverters::int24LE
  191716. : AudioDataConverters::int16LE)));
  191717. return true;
  191718. }
  191719. return false;
  191720. }
  191721. };
  191722. class WASAPIInputDevice : public WASAPIDeviceBase
  191723. {
  191724. public:
  191725. WASAPIInputDevice (const ComSmartPtr <IMMDevice>& device_, const bool useExclusiveMode_)
  191726. : WASAPIDeviceBase (device_, useExclusiveMode_),
  191727. reservoir (1, 1)
  191728. {
  191729. }
  191730. ~WASAPIInputDevice()
  191731. {
  191732. close();
  191733. }
  191734. bool open (const double newSampleRate, const BitArray& newChannels)
  191735. {
  191736. reservoirSize = 0;
  191737. reservoirCapacity = 16384;
  191738. reservoir.setSize (actualNumChannels * reservoirCapacity * sizeof (float));
  191739. return openClient (newSampleRate, newChannels)
  191740. && (numChannels == 0 || OK (client->GetService (__uuidof (IAudioCaptureClient), (void**) &captureClient)));
  191741. }
  191742. void close()
  191743. {
  191744. closeClient();
  191745. captureClient = 0;
  191746. reservoir.setSize (0);
  191747. }
  191748. void copyBuffers (float** destBuffers, int numDestBuffers, int bufferSize, Thread& thread)
  191749. {
  191750. if (numChannels <= 0)
  191751. return;
  191752. int offset = 0;
  191753. while (bufferSize > 0)
  191754. {
  191755. if (reservoirSize > 0) // There's stuff in the reservoir, so use that...
  191756. {
  191757. const int samplesToDo = jmin (bufferSize, (int) reservoirSize);
  191758. for (int i = 0; i < numDestBuffers; ++i)
  191759. {
  191760. float* const dest = destBuffers[i] + offset;
  191761. const int srcChan = channelMaps.getUnchecked(i);
  191762. switch (dataFormat)
  191763. {
  191764. case AudioDataConverters::float32LE:
  191765. AudioDataConverters::convertFloat32LEToFloat (((uint8*) reservoir.getData()) + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191766. break;
  191767. case AudioDataConverters::int32LE:
  191768. AudioDataConverters::convertInt32LEToFloat (((uint8*) reservoir.getData()) + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191769. break;
  191770. case AudioDataConverters::int24LE:
  191771. AudioDataConverters::convertInt24LEToFloat (((uint8*) reservoir.getData()) + 3 * srcChan, dest, samplesToDo, 3 * actualNumChannels);
  191772. break;
  191773. case AudioDataConverters::int16LE:
  191774. AudioDataConverters::convertInt16LEToFloat (((uint8*) reservoir.getData()) + 2 * srcChan, dest, samplesToDo, 2 * actualNumChannels);
  191775. break;
  191776. default: jassertfalse; break;
  191777. }
  191778. }
  191779. bufferSize -= samplesToDo;
  191780. offset += samplesToDo;
  191781. reservoirSize -= samplesToDo;
  191782. }
  191783. else
  191784. {
  191785. UINT32 packetLength = 0;
  191786. if (! OK (captureClient->GetNextPacketSize (&packetLength)))
  191787. break;
  191788. if (packetLength == 0)
  191789. {
  191790. if (thread.threadShouldExit())
  191791. break;
  191792. Thread::sleep (1);
  191793. continue;
  191794. }
  191795. uint8* inputData = 0;
  191796. UINT32 numSamplesAvailable;
  191797. DWORD flags;
  191798. if (OK (captureClient->GetBuffer (&inputData, &numSamplesAvailable, &flags, 0, 0)))
  191799. {
  191800. const int samplesToDo = jmin (bufferSize, (int) numSamplesAvailable);
  191801. for (int i = 0; i < numDestBuffers; ++i)
  191802. {
  191803. float* const dest = destBuffers[i] + offset;
  191804. const int srcChan = channelMaps.getUnchecked(i);
  191805. switch (dataFormat)
  191806. {
  191807. case AudioDataConverters::float32LE:
  191808. AudioDataConverters::convertFloat32LEToFloat (inputData + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191809. break;
  191810. case AudioDataConverters::int32LE:
  191811. AudioDataConverters::convertInt32LEToFloat (inputData + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191812. break;
  191813. case AudioDataConverters::int24LE:
  191814. AudioDataConverters::convertInt24LEToFloat (inputData + 3 * srcChan, dest, samplesToDo, 3 * actualNumChannels);
  191815. break;
  191816. case AudioDataConverters::int16LE:
  191817. AudioDataConverters::convertInt16LEToFloat (inputData + 2 * srcChan, dest, samplesToDo, 2 * actualNumChannels);
  191818. break;
  191819. default: jassertfalse; break;
  191820. }
  191821. }
  191822. bufferSize -= samplesToDo;
  191823. offset += samplesToDo;
  191824. if (samplesToDo < (int) numSamplesAvailable)
  191825. {
  191826. reservoirSize = jmin ((int) (numSamplesAvailable - samplesToDo), reservoirCapacity);
  191827. memcpy ((uint8*) reservoir.getData(), inputData + bytesPerSample * actualNumChannels * samplesToDo,
  191828. bytesPerSample * actualNumChannels * reservoirSize);
  191829. }
  191830. captureClient->ReleaseBuffer (numSamplesAvailable);
  191831. }
  191832. }
  191833. }
  191834. }
  191835. ComSmartPtr <IAudioCaptureClient> captureClient;
  191836. MemoryBlock reservoir;
  191837. int reservoirSize, reservoirCapacity;
  191838. };
  191839. class WASAPIOutputDevice : public WASAPIDeviceBase
  191840. {
  191841. public:
  191842. WASAPIOutputDevice (const ComSmartPtr <IMMDevice>& device_, const bool useExclusiveMode_)
  191843. : WASAPIDeviceBase (device_, useExclusiveMode_)
  191844. {
  191845. }
  191846. ~WASAPIOutputDevice()
  191847. {
  191848. close();
  191849. }
  191850. bool open (const double newSampleRate, const BitArray& newChannels)
  191851. {
  191852. return openClient (newSampleRate, newChannels)
  191853. && (numChannels == 0 || OK (client->GetService (__uuidof (IAudioRenderClient), (void**) &renderClient)));
  191854. }
  191855. void close()
  191856. {
  191857. closeClient();
  191858. renderClient = 0;
  191859. }
  191860. void copyBuffers (const float** const srcBuffers, const int numSrcBuffers, int bufferSize, Thread& thread)
  191861. {
  191862. if (numChannels <= 0)
  191863. return;
  191864. int offset = 0;
  191865. while (bufferSize > 0)
  191866. {
  191867. UINT32 padding = 0;
  191868. if (! OK (client->GetCurrentPadding (&padding)))
  191869. return;
  191870. int samplesToDo = useExclusiveMode ? bufferSize
  191871. : jmin ((int) (actualBufferSize - padding), bufferSize);
  191872. if (samplesToDo <= 0)
  191873. {
  191874. if (thread.threadShouldExit())
  191875. break;
  191876. Thread::sleep (0);
  191877. continue;
  191878. }
  191879. uint8* outputData = 0;
  191880. if (OK (renderClient->GetBuffer (samplesToDo, &outputData)))
  191881. {
  191882. for (int i = 0; i < numSrcBuffers; ++i)
  191883. {
  191884. const float* const source = srcBuffers[i] + offset;
  191885. const int destChan = channelMaps.getUnchecked(i);
  191886. switch (dataFormat)
  191887. {
  191888. case AudioDataConverters::float32LE:
  191889. AudioDataConverters::convertFloatToFloat32LE (source, outputData + 4 * destChan, samplesToDo, 4 * actualNumChannels);
  191890. break;
  191891. case AudioDataConverters::int32LE:
  191892. AudioDataConverters::convertFloatToInt32LE (source, outputData + 4 * destChan, samplesToDo, 4 * actualNumChannels);
  191893. break;
  191894. case AudioDataConverters::int24LE:
  191895. AudioDataConverters::convertFloatToInt24LE (source, outputData + 3 * destChan, samplesToDo, 3 * actualNumChannels);
  191896. break;
  191897. case AudioDataConverters::int16LE:
  191898. AudioDataConverters::convertFloatToInt16LE (source, outputData + 2 * destChan, samplesToDo, 2 * actualNumChannels);
  191899. break;
  191900. default: jassertfalse; break;
  191901. }
  191902. }
  191903. renderClient->ReleaseBuffer (samplesToDo, 0);
  191904. offset += samplesToDo;
  191905. bufferSize -= samplesToDo;
  191906. }
  191907. }
  191908. }
  191909. ComSmartPtr <IAudioRenderClient> renderClient;
  191910. };
  191911. class WASAPIAudioIODevice : public AudioIODevice,
  191912. public Thread
  191913. {
  191914. public:
  191915. WASAPIAudioIODevice (const String& deviceName,
  191916. const String& outputDeviceId_,
  191917. const String& inputDeviceId_,
  191918. const bool useExclusiveMode_)
  191919. : AudioIODevice (deviceName, "Windows Audio"),
  191920. Thread ("Juce WASAPI"),
  191921. isOpen_ (false),
  191922. isStarted (false),
  191923. outputDevice (0),
  191924. outputDeviceId (outputDeviceId_),
  191925. inputDevice (0),
  191926. inputDeviceId (inputDeviceId_),
  191927. useExclusiveMode (useExclusiveMode_),
  191928. currentBufferSizeSamples (0),
  191929. currentSampleRate (0),
  191930. callback (0)
  191931. {
  191932. }
  191933. ~WASAPIAudioIODevice()
  191934. {
  191935. close();
  191936. deleteAndZero (inputDevice);
  191937. deleteAndZero (outputDevice);
  191938. }
  191939. bool initialise()
  191940. {
  191941. double defaultSampleRateIn = 0, defaultSampleRateOut = 0;
  191942. int minBufferSizeIn = 0, defaultBufferSizeIn = 0, minBufferSizeOut = 0, defaultBufferSizeOut = 0;
  191943. latencyIn = latencyOut = 0;
  191944. Array <double> ratesIn, ratesOut;
  191945. if (createDevices())
  191946. {
  191947. jassert (inputDevice != 0 || outputDevice != 0);
  191948. if (inputDevice != 0 && outputDevice != 0)
  191949. {
  191950. defaultSampleRate = jmin (inputDevice->defaultSampleRate, outputDevice->defaultSampleRate);
  191951. minBufferSize = jmin (inputDevice->minBufferSize, outputDevice->minBufferSize);
  191952. defaultBufferSize = jmax (inputDevice->defaultBufferSize, outputDevice->defaultBufferSize);
  191953. sampleRates = inputDevice->rates;
  191954. sampleRates.removeValuesNotIn (outputDevice->rates);
  191955. }
  191956. else
  191957. {
  191958. WASAPIDeviceBase* const d = inputDevice != 0 ? (WASAPIDeviceBase*) inputDevice : (WASAPIDeviceBase*) outputDevice;
  191959. defaultSampleRate = d->defaultSampleRate;
  191960. minBufferSize = d->minBufferSize;
  191961. defaultBufferSize = d->defaultBufferSize;
  191962. sampleRates = d->rates;
  191963. }
  191964. IntegerElementComparator<int> comparator;
  191965. bufferSizes.addSorted (comparator, defaultBufferSize);
  191966. if (minBufferSize != defaultBufferSize)
  191967. bufferSizes.addSorted (comparator, minBufferSize);
  191968. int n = 64;
  191969. for (int i = 0; i < 40; ++i)
  191970. {
  191971. if (n >= minBufferSize && n <= 2048 && ! bufferSizes.contains (n))
  191972. bufferSizes.addSorted (comparator, n);
  191973. n += (n < 512) ? 32 : (n < 1024 ? 64 : 128);
  191974. }
  191975. return true;
  191976. }
  191977. return false;
  191978. }
  191979. const StringArray getOutputChannelNames()
  191980. {
  191981. StringArray outChannels;
  191982. if (outputDevice != 0)
  191983. for (int i = 1; i <= outputDevice->actualNumChannels; ++i)
  191984. outChannels.add ("Output channel " + String (i));
  191985. return outChannels;
  191986. }
  191987. const StringArray getInputChannelNames()
  191988. {
  191989. StringArray inChannels;
  191990. if (inputDevice != 0)
  191991. for (int i = 1; i <= inputDevice->actualNumChannels; ++i)
  191992. inChannels.add ("Input channel " + String (i));
  191993. return inChannels;
  191994. }
  191995. int getNumSampleRates() { return sampleRates.size(); }
  191996. double getSampleRate (int index) { return sampleRates [index]; }
  191997. int getNumBufferSizesAvailable() { return bufferSizes.size(); }
  191998. int getBufferSizeSamples (int index) { return bufferSizes [index]; }
  191999. int getDefaultBufferSize() { return defaultBufferSize; }
  192000. int getCurrentBufferSizeSamples() { return currentBufferSizeSamples; }
  192001. double getCurrentSampleRate() { return currentSampleRate; }
  192002. int getCurrentBitDepth() { return 32; }
  192003. int getOutputLatencyInSamples() { return latencyOut; }
  192004. int getInputLatencyInSamples() { return latencyIn; }
  192005. const BitArray getActiveOutputChannels() const { return outputDevice != 0 ? outputDevice->channels : BitArray(); }
  192006. const BitArray getActiveInputChannels() const { return inputDevice != 0 ? inputDevice->channels : BitArray(); }
  192007. const String getLastError() { return lastError; }
  192008. const String open (const BitArray& inputChannels, const BitArray& outputChannels,
  192009. double sampleRate, int bufferSizeSamples)
  192010. {
  192011. close();
  192012. lastError = String::empty;
  192013. if (sampleRates.size() == 0 && inputDevice != 0 && outputDevice != 0)
  192014. {
  192015. lastError = "The input and output devices don't share a common sample rate!";
  192016. return lastError;
  192017. }
  192018. currentBufferSizeSamples = bufferSizeSamples <= 0 ? defaultBufferSize : jmax (bufferSizeSamples, minBufferSize);
  192019. currentSampleRate = sampleRate > 0 ? sampleRate : defaultSampleRate;
  192020. if (inputDevice != 0 && ! inputDevice->open (currentSampleRate, inputChannels))
  192021. {
  192022. lastError = "Couldn't open the input device!";
  192023. return lastError;
  192024. }
  192025. if (outputDevice != 0 && ! outputDevice->open (currentSampleRate, outputChannels))
  192026. {
  192027. close();
  192028. lastError = "Couldn't open the output device!";
  192029. return lastError;
  192030. }
  192031. if (inputDevice != 0)
  192032. ResetEvent (inputDevice->clientEvent);
  192033. if (outputDevice != 0)
  192034. ResetEvent (outputDevice->clientEvent);
  192035. startThread (8);
  192036. Thread::sleep (5);
  192037. if (inputDevice != 0 && inputDevice->client != 0)
  192038. {
  192039. latencyIn = inputDevice->latencySamples + inputDevice->actualBufferSize + inputDevice->minBufferSize;
  192040. HRESULT hr = inputDevice->client->Start();
  192041. logFailure (hr); //xxx handle this
  192042. }
  192043. if (outputDevice != 0 && outputDevice->client != 0)
  192044. {
  192045. latencyOut = outputDevice->latencySamples + outputDevice->actualBufferSize + outputDevice->minBufferSize;
  192046. HRESULT hr = outputDevice->client->Start();
  192047. logFailure (hr); //xxx handle this
  192048. }
  192049. isOpen_ = true;
  192050. return lastError;
  192051. }
  192052. void close()
  192053. {
  192054. stop();
  192055. if (inputDevice != 0)
  192056. SetEvent (inputDevice->clientEvent);
  192057. if (outputDevice != 0)
  192058. SetEvent (outputDevice->clientEvent);
  192059. stopThread (5000);
  192060. if (inputDevice != 0)
  192061. inputDevice->close();
  192062. if (outputDevice != 0)
  192063. outputDevice->close();
  192064. isOpen_ = false;
  192065. }
  192066. bool isOpen() { return isOpen_ && isThreadRunning(); }
  192067. bool isPlaying() { return isStarted && isOpen_ && isThreadRunning(); }
  192068. void start (AudioIODeviceCallback* call)
  192069. {
  192070. if (isOpen_ && call != 0 && ! isStarted)
  192071. {
  192072. if (! isThreadRunning())
  192073. {
  192074. // something's gone wrong and the thread's stopped..
  192075. isOpen_ = false;
  192076. return;
  192077. }
  192078. call->audioDeviceAboutToStart (this);
  192079. const ScopedLock sl (startStopLock);
  192080. callback = call;
  192081. isStarted = true;
  192082. }
  192083. }
  192084. void stop()
  192085. {
  192086. if (isStarted)
  192087. {
  192088. AudioIODeviceCallback* const callbackLocal = callback;
  192089. {
  192090. const ScopedLock sl (startStopLock);
  192091. isStarted = false;
  192092. }
  192093. if (callbackLocal != 0)
  192094. callbackLocal->audioDeviceStopped();
  192095. }
  192096. }
  192097. void setMMThreadPriority()
  192098. {
  192099. DynamicLibraryLoader dll ("avrt.dll");
  192100. DynamicLibraryImport (AvSetMmThreadCharacteristics, avSetMmThreadCharacteristics, HANDLE, dll, (LPCTSTR, LPDWORD))
  192101. DynamicLibraryImport (AvSetMmThreadPriority, avSetMmThreadPriority, HANDLE, dll, (HANDLE, AVRT_PRIORITY))
  192102. if (avSetMmThreadCharacteristics != 0 && avSetMmThreadPriority != 0)
  192103. {
  192104. DWORD dummy = 0;
  192105. HANDLE h = avSetMmThreadCharacteristics (_T("Pro Audio"), &dummy);
  192106. if (h != 0)
  192107. avSetMmThreadPriority (h, AVRT_PRIORITY_NORMAL);
  192108. }
  192109. }
  192110. void run()
  192111. {
  192112. setMMThreadPriority();
  192113. const int bufferSize = currentBufferSizeSamples;
  192114. HANDLE events[2];
  192115. int numEvents = 0;
  192116. if (inputDevice != 0)
  192117. events [numEvents++] = inputDevice->clientEvent;
  192118. if (outputDevice != 0)
  192119. events [numEvents++] = outputDevice->clientEvent;
  192120. const int numInputBuffers = getActiveInputChannels().countNumberOfSetBits();
  192121. const int numOutputBuffers = getActiveOutputChannels().countNumberOfSetBits();
  192122. AudioSampleBuffer ins (jmax (1, numInputBuffers), bufferSize + 32);
  192123. AudioSampleBuffer outs (jmax (1, numOutputBuffers), bufferSize + 32);
  192124. float** const inputBuffers = ins.getArrayOfChannels();
  192125. float** const outputBuffers = outs.getArrayOfChannels();
  192126. ins.clear();
  192127. while (! threadShouldExit())
  192128. {
  192129. const DWORD result = useExclusiveMode ? WaitForSingleObject (inputDevice->clientEvent, 1000)
  192130. : WaitForMultipleObjects (numEvents, events, true, 1000);
  192131. if (result == WAIT_TIMEOUT)
  192132. continue;
  192133. if (threadShouldExit())
  192134. break;
  192135. if (inputDevice != 0)
  192136. inputDevice->copyBuffers (inputBuffers, numInputBuffers, bufferSize, *this);
  192137. // Make the callback..
  192138. {
  192139. const ScopedLock sl (startStopLock);
  192140. if (isStarted)
  192141. {
  192142. JUCE_TRY
  192143. {
  192144. callback->audioDeviceIOCallback ((const float**) inputBuffers,
  192145. numInputBuffers,
  192146. outputBuffers,
  192147. numOutputBuffers,
  192148. bufferSize);
  192149. }
  192150. JUCE_CATCH_EXCEPTION
  192151. }
  192152. else
  192153. {
  192154. outs.clear();
  192155. }
  192156. }
  192157. if (useExclusiveMode && WaitForSingleObject (outputDevice->clientEvent, 1000) == WAIT_TIMEOUT)
  192158. continue;
  192159. if (outputDevice != 0)
  192160. outputDevice->copyBuffers ((const float**) outputBuffers, numOutputBuffers, bufferSize, *this);
  192161. }
  192162. }
  192163. juce_UseDebuggingNewOperator
  192164. String outputDeviceId, inputDeviceId;
  192165. String lastError;
  192166. private:
  192167. // Device stats...
  192168. WASAPIInputDevice* inputDevice;
  192169. WASAPIOutputDevice* outputDevice;
  192170. const bool useExclusiveMode;
  192171. double defaultSampleRate;
  192172. int minBufferSize, defaultBufferSize;
  192173. int latencyIn, latencyOut;
  192174. Array <double> sampleRates;
  192175. Array <int> bufferSizes;
  192176. // Active state...
  192177. bool isOpen_, isStarted;
  192178. int currentBufferSizeSamples;
  192179. double currentSampleRate;
  192180. AudioIODeviceCallback* callback;
  192181. CriticalSection startStopLock;
  192182. bool createDevices()
  192183. {
  192184. ComSmartPtr <IMMDeviceEnumerator> enumerator;
  192185. if (! OK (enumerator.CoCreateInstance (__uuidof (MMDeviceEnumerator), CLSCTX_INPROC_SERVER)))
  192186. return false;
  192187. ComSmartPtr <IMMDeviceCollection> deviceCollection;
  192188. if (! OK (enumerator->EnumAudioEndpoints (eAll, DEVICE_STATE_ACTIVE, &deviceCollection)))
  192189. return false;
  192190. UINT32 numDevices = 0;
  192191. if (! OK (deviceCollection->GetCount (&numDevices)))
  192192. return false;
  192193. for (UINT32 i = 0; i < numDevices; ++i)
  192194. {
  192195. ComSmartPtr <IMMDevice> device;
  192196. if (! OK (deviceCollection->Item (i, &device)))
  192197. continue;
  192198. const String deviceId (wasapi_getDeviceID (device));
  192199. if (deviceId.isEmpty())
  192200. continue;
  192201. const EDataFlow flow = wasapi_getDataFlow (device);
  192202. if (deviceId == inputDeviceId && flow == eCapture)
  192203. inputDevice = new WASAPIInputDevice (device, useExclusiveMode);
  192204. else if (deviceId == outputDeviceId && flow == eRender)
  192205. outputDevice = new WASAPIOutputDevice (device, useExclusiveMode);
  192206. }
  192207. return (outputDeviceId.isEmpty() || (outputDevice != 0 && outputDevice->isOk()))
  192208. && (inputDeviceId.isEmpty() || (inputDevice != 0 && inputDevice->isOk()));
  192209. }
  192210. WASAPIAudioIODevice (const WASAPIAudioIODevice&);
  192211. const WASAPIAudioIODevice& operator= (const WASAPIAudioIODevice&);
  192212. };
  192213. class WASAPIAudioIODeviceType : public AudioIODeviceType
  192214. {
  192215. public:
  192216. WASAPIAudioIODeviceType()
  192217. : AudioIODeviceType (T("Windows Audio")),
  192218. hasScanned (false)
  192219. {
  192220. }
  192221. ~WASAPIAudioIODeviceType()
  192222. {
  192223. }
  192224. void scanForDevices()
  192225. {
  192226. hasScanned = true;
  192227. outputDeviceNames.clear();
  192228. inputDeviceNames.clear();
  192229. outputDeviceIds.clear();
  192230. inputDeviceIds.clear();
  192231. ComSmartPtr <IMMDeviceEnumerator> enumerator;
  192232. if (! OK (enumerator.CoCreateInstance (__uuidof (MMDeviceEnumerator), CLSCTX_INPROC_SERVER)))
  192233. return;
  192234. const String defaultRenderer = getDefaultEndpoint (enumerator, false);
  192235. const String defaultCapture = getDefaultEndpoint (enumerator, true);
  192236. ComSmartPtr <IMMDeviceCollection> deviceCollection;
  192237. UINT32 numDevices = 0;
  192238. if (! (OK (enumerator->EnumAudioEndpoints (eAll, DEVICE_STATE_ACTIVE, &deviceCollection))
  192239. && OK (deviceCollection->GetCount (&numDevices))))
  192240. return;
  192241. for (UINT32 i = 0; i < numDevices; ++i)
  192242. {
  192243. ComSmartPtr <IMMDevice> device;
  192244. if (! OK (deviceCollection->Item (i, &device)))
  192245. continue;
  192246. const String deviceId (wasapi_getDeviceID (device));
  192247. DWORD state = 0;
  192248. if (! OK (device->GetState (&state)))
  192249. continue;
  192250. if (state != DEVICE_STATE_ACTIVE)
  192251. continue;
  192252. String name;
  192253. {
  192254. ComSmartPtr <IPropertyStore> properties;
  192255. if (! OK (device->OpenPropertyStore (STGM_READ, &properties)))
  192256. continue;
  192257. PROPVARIANT value;
  192258. PropVariantInit (&value);
  192259. if (OK (properties->GetValue (PKEY_Device_FriendlyName, &value)))
  192260. name = value.pwszVal;
  192261. PropVariantClear (&value);
  192262. }
  192263. const EDataFlow flow = wasapi_getDataFlow (device);
  192264. if (flow == eRender)
  192265. {
  192266. const int index = (deviceId == defaultRenderer) ? 0 : -1;
  192267. outputDeviceIds.insert (index, deviceId);
  192268. outputDeviceNames.insert (index, name);
  192269. }
  192270. else if (flow == eCapture)
  192271. {
  192272. const int index = (deviceId == defaultCapture) ? 0 : -1;
  192273. inputDeviceIds.insert (index, deviceId);
  192274. inputDeviceNames.insert (index, name);
  192275. }
  192276. }
  192277. inputDeviceNames.appendNumbersToDuplicates (false, false);
  192278. outputDeviceNames.appendNumbersToDuplicates (false, false);
  192279. }
  192280. const StringArray getDeviceNames (const bool wantInputNames) const
  192281. {
  192282. jassert (hasScanned); // need to call scanForDevices() before doing this
  192283. return wantInputNames ? inputDeviceNames
  192284. : outputDeviceNames;
  192285. }
  192286. int getDefaultDeviceIndex (const bool /*forInput*/) const
  192287. {
  192288. jassert (hasScanned); // need to call scanForDevices() before doing this
  192289. return 0;
  192290. }
  192291. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  192292. {
  192293. jassert (hasScanned); // need to call scanForDevices() before doing this
  192294. WASAPIAudioIODevice* const d = dynamic_cast <WASAPIAudioIODevice*> (device);
  192295. return d == 0 ? -1 : (asInput ? inputDeviceIds.indexOf (d->inputDeviceId)
  192296. : outputDeviceIds.indexOf (d->outputDeviceId));
  192297. }
  192298. bool hasSeparateInputsAndOutputs() const { return true; }
  192299. AudioIODevice* createDevice (const String& outputDeviceName,
  192300. const String& inputDeviceName)
  192301. {
  192302. jassert (hasScanned); // need to call scanForDevices() before doing this
  192303. const bool useExclusiveMode = false;
  192304. WASAPIAudioIODevice* d = 0;
  192305. const int outputIndex = outputDeviceNames.indexOf (outputDeviceName);
  192306. const int inputIndex = inputDeviceNames.indexOf (inputDeviceName);
  192307. if (outputIndex >= 0 || inputIndex >= 0)
  192308. {
  192309. d = new WASAPIAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  192310. : inputDeviceName,
  192311. outputDeviceIds [outputIndex],
  192312. inputDeviceIds [inputIndex],
  192313. useExclusiveMode);
  192314. if (! d->initialise())
  192315. deleteAndZero (d);
  192316. }
  192317. return d;
  192318. }
  192319. juce_UseDebuggingNewOperator
  192320. StringArray outputDeviceNames, outputDeviceIds;
  192321. StringArray inputDeviceNames, inputDeviceIds;
  192322. private:
  192323. bool hasScanned;
  192324. static const String getDefaultEndpoint (IMMDeviceEnumerator* const enumerator, const bool forCapture)
  192325. {
  192326. String s;
  192327. IMMDevice* dev = 0;
  192328. if (OK (enumerator->GetDefaultAudioEndpoint (forCapture ? eCapture : eRender,
  192329. eMultimedia, &dev)))
  192330. {
  192331. WCHAR* deviceId = 0;
  192332. if (OK (dev->GetId (&deviceId)))
  192333. {
  192334. s = String (deviceId);
  192335. CoTaskMemFree (deviceId);
  192336. }
  192337. dev->Release();
  192338. }
  192339. return s;
  192340. }
  192341. WASAPIAudioIODeviceType (const WASAPIAudioIODeviceType&);
  192342. const WASAPIAudioIODeviceType& operator= (const WASAPIAudioIODeviceType&);
  192343. };
  192344. AudioIODeviceType* juce_createAudioIODeviceType_WASAPI()
  192345. {
  192346. return new WASAPIAudioIODeviceType();
  192347. }
  192348. #undef logFailure
  192349. #undef OK
  192350. #endif
  192351. /*** End of inlined file: juce_win32_WASAPI.cpp ***/
  192352. /*** Start of inlined file: juce_win32_CameraDevice.cpp ***/
  192353. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  192354. // compiled on its own).
  192355. #if JUCE_INCLUDED_FILE && JUCE_USE_CAMERA
  192356. class DShowCameraDeviceInteral : public ChangeBroadcaster
  192357. {
  192358. public:
  192359. DShowCameraDeviceInteral (CameraDevice* const owner_,
  192360. const ComSmartPtr <ICaptureGraphBuilder2>& captureGraphBuilder_,
  192361. const ComSmartPtr <IBaseFilter>& filter_,
  192362. int minWidth, int minHeight,
  192363. int maxWidth, int maxHeight)
  192364. : owner (owner_),
  192365. captureGraphBuilder (captureGraphBuilder_),
  192366. filter (filter_),
  192367. ok (false),
  192368. imageNeedsFlipping (false),
  192369. width (0),
  192370. height (0),
  192371. activeUsers (0),
  192372. recordNextFrameTime (false),
  192373. activeImage (0),
  192374. loadingImage (0)
  192375. {
  192376. HRESULT hr = graphBuilder.CoCreateInstance (CLSID_FilterGraph, CLSCTX_INPROC);
  192377. if (FAILED (hr))
  192378. return;
  192379. hr = captureGraphBuilder->SetFiltergraph (graphBuilder);
  192380. if (FAILED (hr))
  192381. return;
  192382. hr = graphBuilder->QueryInterface (IID_IMediaControl, (void**) &mediaControl);
  192383. if (FAILED (hr))
  192384. return;
  192385. {
  192386. ComSmartPtr <IAMStreamConfig> streamConfig;
  192387. hr = captureGraphBuilder->FindInterface (&PIN_CATEGORY_CAPTURE,
  192388. 0,
  192389. filter,
  192390. IID_IAMStreamConfig,
  192391. (void**) &streamConfig);
  192392. if (streamConfig != 0)
  192393. {
  192394. getVideoSizes (streamConfig);
  192395. if (! selectVideoSize (streamConfig, minWidth, minHeight, maxWidth, maxHeight))
  192396. return;
  192397. }
  192398. }
  192399. hr = graphBuilder->AddFilter (filter, _T("Video Capture"));
  192400. if (FAILED (hr))
  192401. return;
  192402. hr = smartTee.CoCreateInstance (CLSID_SmartTee, CLSCTX_INPROC_SERVER);
  192403. if (FAILED (hr))
  192404. return;
  192405. hr = graphBuilder->AddFilter (smartTee, _T("Smart Tee"));
  192406. if (FAILED (hr))
  192407. return;
  192408. if (! connectFilters (filter, smartTee))
  192409. return;
  192410. ComSmartPtr <IBaseFilter> sampleGrabberBase;
  192411. hr = sampleGrabberBase.CoCreateInstance (CLSID_SampleGrabber, CLSCTX_INPROC_SERVER);
  192412. if (FAILED (hr))
  192413. return;
  192414. hr = sampleGrabberBase->QueryInterface (IID_ISampleGrabber, (void**) &sampleGrabber);
  192415. if (FAILED (hr))
  192416. return;
  192417. AM_MEDIA_TYPE mt;
  192418. zerostruct (mt);
  192419. mt.majortype = MEDIATYPE_Video;
  192420. mt.subtype = MEDIASUBTYPE_RGB24;
  192421. mt.formattype = FORMAT_VideoInfo;
  192422. sampleGrabber->SetMediaType (&mt);
  192423. callback = new GrabberCallback (*this);
  192424. sampleGrabber->SetCallback (callback, 1);
  192425. hr = graphBuilder->AddFilter (sampleGrabberBase, _T("Sample Grabber"));
  192426. if (FAILED (hr))
  192427. return;
  192428. ComSmartPtr <IPin> grabberInputPin;
  192429. if (! (getPin (smartTee, PINDIR_OUTPUT, &smartTeeCaptureOutputPin, "capture")
  192430. && getPin (smartTee, PINDIR_OUTPUT, &smartTeePreviewOutputPin, "preview")
  192431. && getPin (sampleGrabberBase, PINDIR_INPUT, &grabberInputPin)))
  192432. return;
  192433. hr = graphBuilder->Connect (smartTeePreviewOutputPin, grabberInputPin);
  192434. if (FAILED (hr))
  192435. return;
  192436. zerostruct (mt);
  192437. hr = sampleGrabber->GetConnectedMediaType (&mt);
  192438. VIDEOINFOHEADER* pVih = (VIDEOINFOHEADER*) (mt.pbFormat);
  192439. width = pVih->bmiHeader.biWidth;
  192440. height = pVih->bmiHeader.biHeight;
  192441. ComSmartPtr <IBaseFilter> nullFilter;
  192442. hr = nullFilter.CoCreateInstance (CLSID_NullRenderer, CLSCTX_INPROC_SERVER);
  192443. hr = graphBuilder->AddFilter (nullFilter, _T("Null Renderer"));
  192444. if (connectFilters (sampleGrabberBase, nullFilter)
  192445. && addGraphToRot())
  192446. {
  192447. activeImage = new Image (Image::RGB, width, height, true);
  192448. loadingImage = new Image (Image::RGB, width, height, true);
  192449. ok = true;
  192450. }
  192451. }
  192452. ~DShowCameraDeviceInteral()
  192453. {
  192454. if (mediaControl != 0)
  192455. mediaControl->Stop();
  192456. removeGraphFromRot();
  192457. for (int i = viewerComps.size(); --i >= 0;)
  192458. ((DShowCaptureViewerComp*) viewerComps.getUnchecked(i))->ownerDeleted();
  192459. callback = 0;
  192460. graphBuilder = 0;
  192461. sampleGrabber = 0;
  192462. mediaControl = 0;
  192463. filter = 0;
  192464. captureGraphBuilder = 0;
  192465. smartTee = 0;
  192466. smartTeePreviewOutputPin = 0;
  192467. smartTeeCaptureOutputPin = 0;
  192468. mux = 0;
  192469. fileWriter = 0;
  192470. delete activeImage;
  192471. delete loadingImage;
  192472. }
  192473. void addUser()
  192474. {
  192475. if (ok && activeUsers++ == 0)
  192476. mediaControl->Run();
  192477. }
  192478. void removeUser()
  192479. {
  192480. if (ok && --activeUsers == 0)
  192481. mediaControl->Stop();
  192482. }
  192483. void handleFrame (double /*time*/, BYTE* buffer, long /*bufferSize*/)
  192484. {
  192485. if (recordNextFrameTime)
  192486. {
  192487. const double defaultCameraLatency = 0.1;
  192488. firstRecordedTime = Time::getCurrentTime() - RelativeTime (defaultCameraLatency);
  192489. recordNextFrameTime = false;
  192490. ComSmartPtr <IPin> pin;
  192491. if (getPin (filter, PINDIR_OUTPUT, &pin))
  192492. {
  192493. ComSmartPtr <IAMPushSource> pushSource;
  192494. HRESULT hr = pin->QueryInterface (IID_IAMPushSource, (void**) &pushSource);
  192495. if (pushSource != 0)
  192496. {
  192497. REFERENCE_TIME latency = 0;
  192498. hr = pushSource->GetLatency (&latency);
  192499. firstRecordedTime = firstRecordedTime - RelativeTime ((double) latency);
  192500. }
  192501. }
  192502. }
  192503. imageSwapLock.enter();
  192504. const int lineStride = width * 3;
  192505. const Image::BitmapData destData (*loadingImage, 0, 0, width, height, true);
  192506. for (int i = 0; i < height; ++i)
  192507. memcpy (destData.getLinePointer ((height - 1) - i),
  192508. buffer + lineStride * i,
  192509. lineStride);
  192510. imageNeedsFlipping = true;
  192511. imageSwapLock.exit();
  192512. callListeners (*loadingImage);
  192513. sendChangeMessage (this);
  192514. }
  192515. void drawCurrentImage (Graphics& g, int x, int y, int w, int h)
  192516. {
  192517. if (imageNeedsFlipping)
  192518. {
  192519. imageSwapLock.enter();
  192520. swapVariables (loadingImage, activeImage);
  192521. imageNeedsFlipping = false;
  192522. imageSwapLock.exit();
  192523. }
  192524. RectanglePlacement rp (RectanglePlacement::centred);
  192525. double dx = 0, dy = 0, dw = width, dh = height;
  192526. rp.applyTo (dx, dy, dw, dh, x, y, w, h);
  192527. const int rx = roundToInt (dx), ry = roundToInt (dy);
  192528. const int rw = roundToInt (dw), rh = roundToInt (dh);
  192529. g.saveState();
  192530. g.excludeClipRegion (rx, ry, rw, rh);
  192531. g.fillAll (Colours::black);
  192532. g.restoreState();
  192533. g.drawImage (activeImage, rx, ry, rw, rh, 0, 0, width, height);
  192534. }
  192535. bool createFileCaptureFilter (const File& file)
  192536. {
  192537. removeFileCaptureFilter();
  192538. file.deleteFile();
  192539. mediaControl->Stop();
  192540. firstRecordedTime = Time();
  192541. recordNextFrameTime = true;
  192542. HRESULT hr = mux.CoCreateInstance (CLSID_AviDest, CLSCTX_INPROC_SERVER);
  192543. if (SUCCEEDED (hr))
  192544. {
  192545. hr = graphBuilder->AddFilter (mux, _T("AVI Mux"));
  192546. if (SUCCEEDED (hr))
  192547. {
  192548. fileWriter.CoCreateInstance (CLSID_FileWriter, CLSCTX_INPROC_SERVER);
  192549. if (SUCCEEDED (hr))
  192550. {
  192551. ComSmartPtr <IFileSinkFilter> fileSink;
  192552. hr = fileWriter->QueryInterface (IID_IFileSinkFilter, (void**) &fileSink);
  192553. if (SUCCEEDED (hr))
  192554. {
  192555. AM_MEDIA_TYPE mt;
  192556. zerostruct (mt);
  192557. mt.majortype = MEDIATYPE_Stream;
  192558. mt.subtype = MEDIASUBTYPE_Avi;
  192559. mt.formattype = FORMAT_VideoInfo;
  192560. hr = fileSink->SetFileName (file.getFullPathName(), &mt);
  192561. if (SUCCEEDED (hr))
  192562. {
  192563. hr = graphBuilder->AddFilter (fileWriter, _T("File Writer"));
  192564. if (SUCCEEDED (hr))
  192565. {
  192566. ComSmartPtr <IPin> muxInputPin, muxOutputPin, writerInput;
  192567. if (getPin (mux, PINDIR_INPUT, &muxInputPin)
  192568. && getPin (mux, PINDIR_OUTPUT, &muxOutputPin)
  192569. && getPin (fileWriter, PINDIR_INPUT, &writerInput))
  192570. {
  192571. hr = graphBuilder->Connect (smartTeeCaptureOutputPin, muxInputPin);
  192572. if (SUCCEEDED (hr))
  192573. {
  192574. hr = graphBuilder->Connect (muxOutputPin, writerInput);
  192575. if (SUCCEEDED (hr))
  192576. {
  192577. if (ok && activeUsers > 0)
  192578. mediaControl->Run();
  192579. return true;
  192580. }
  192581. }
  192582. }
  192583. }
  192584. }
  192585. }
  192586. }
  192587. }
  192588. }
  192589. removeFileCaptureFilter();
  192590. if (ok && activeUsers > 0)
  192591. mediaControl->Run();
  192592. return false;
  192593. }
  192594. void removeFileCaptureFilter()
  192595. {
  192596. mediaControl->Stop();
  192597. if (mux != 0)
  192598. {
  192599. graphBuilder->RemoveFilter (mux);
  192600. mux = 0;
  192601. }
  192602. if (fileWriter != 0)
  192603. {
  192604. graphBuilder->RemoveFilter (fileWriter);
  192605. fileWriter = 0;
  192606. }
  192607. if (ok && activeUsers > 0)
  192608. mediaControl->Run();
  192609. }
  192610. void addListener (CameraImageListener* listenerToAdd)
  192611. {
  192612. const ScopedLock sl (listenerLock);
  192613. if (listeners.size() == 0)
  192614. addUser();
  192615. listeners.addIfNotAlreadyThere (listenerToAdd);
  192616. }
  192617. void removeListener (CameraImageListener* listenerToRemove)
  192618. {
  192619. const ScopedLock sl (listenerLock);
  192620. listeners.removeValue (listenerToRemove);
  192621. if (listeners.size() == 0)
  192622. removeUser();
  192623. }
  192624. void callListeners (Image& image)
  192625. {
  192626. const ScopedLock sl (listenerLock);
  192627. for (int i = listeners.size(); --i >= 0;)
  192628. {
  192629. CameraImageListener* l = (CameraImageListener*) listeners[i];
  192630. if (l != 0)
  192631. l->imageReceived (image);
  192632. }
  192633. }
  192634. class DShowCaptureViewerComp : public Component,
  192635. public ChangeListener
  192636. {
  192637. public:
  192638. DShowCaptureViewerComp (DShowCameraDeviceInteral* const owner_)
  192639. : owner (owner_)
  192640. {
  192641. setOpaque (true);
  192642. owner->addChangeListener (this);
  192643. owner->addUser();
  192644. owner->viewerComps.add (this);
  192645. setSize (owner_->width, owner_->height);
  192646. }
  192647. ~DShowCaptureViewerComp()
  192648. {
  192649. if (owner != 0)
  192650. {
  192651. owner->viewerComps.removeValue (this);
  192652. owner->removeUser();
  192653. owner->removeChangeListener (this);
  192654. }
  192655. }
  192656. void ownerDeleted()
  192657. {
  192658. owner = 0;
  192659. }
  192660. void paint (Graphics& g)
  192661. {
  192662. g.setColour (Colours::black);
  192663. g.setImageResamplingQuality (Graphics::lowResamplingQuality);
  192664. if (owner != 0)
  192665. owner->drawCurrentImage (g, 0, 0, getWidth(), getHeight());
  192666. else
  192667. g.fillAll (Colours::black);
  192668. }
  192669. void changeListenerCallback (void*)
  192670. {
  192671. repaint();
  192672. }
  192673. private:
  192674. DShowCameraDeviceInteral* owner;
  192675. };
  192676. bool ok;
  192677. int width, height;
  192678. Time firstRecordedTime;
  192679. VoidArray viewerComps;
  192680. private:
  192681. CameraDevice* const owner;
  192682. ComSmartPtr <ICaptureGraphBuilder2> captureGraphBuilder;
  192683. ComSmartPtr <IBaseFilter> filter;
  192684. ComSmartPtr <IBaseFilter> smartTee;
  192685. ComSmartPtr <IGraphBuilder> graphBuilder;
  192686. ComSmartPtr <ISampleGrabber> sampleGrabber;
  192687. ComSmartPtr <IMediaControl> mediaControl;
  192688. ComSmartPtr <IPin> smartTeePreviewOutputPin;
  192689. ComSmartPtr <IPin> smartTeeCaptureOutputPin;
  192690. ComSmartPtr <IBaseFilter> mux, fileWriter;
  192691. int activeUsers;
  192692. Array <int> widths, heights;
  192693. DWORD graphRegistrationID;
  192694. CriticalSection imageSwapLock;
  192695. bool imageNeedsFlipping;
  192696. Image* loadingImage;
  192697. Image* activeImage;
  192698. bool recordNextFrameTime;
  192699. void getVideoSizes (IAMStreamConfig* const streamConfig)
  192700. {
  192701. widths.clear();
  192702. heights.clear();
  192703. int count = 0, size = 0;
  192704. streamConfig->GetNumberOfCapabilities (&count, &size);
  192705. if (size == sizeof (VIDEO_STREAM_CONFIG_CAPS))
  192706. {
  192707. for (int i = 0; i < count; ++i)
  192708. {
  192709. VIDEO_STREAM_CONFIG_CAPS scc;
  192710. AM_MEDIA_TYPE* config;
  192711. HRESULT hr = streamConfig->GetStreamCaps (i, &config, (BYTE*) &scc);
  192712. if (SUCCEEDED (hr))
  192713. {
  192714. const int w = scc.InputSize.cx;
  192715. const int h = scc.InputSize.cy;
  192716. bool duplicate = false;
  192717. for (int j = widths.size(); --j >= 0;)
  192718. {
  192719. if (w == widths.getUnchecked (j) && h == heights.getUnchecked (j))
  192720. {
  192721. duplicate = true;
  192722. break;
  192723. }
  192724. }
  192725. if (! duplicate)
  192726. {
  192727. DBG ("Camera capture size: " + String (w) + ", " + String (h));
  192728. widths.add (w);
  192729. heights.add (h);
  192730. }
  192731. deleteMediaType (config);
  192732. }
  192733. }
  192734. }
  192735. }
  192736. bool selectVideoSize (IAMStreamConfig* const streamConfig,
  192737. const int minWidth, const int minHeight,
  192738. const int maxWidth, const int maxHeight)
  192739. {
  192740. int count = 0, size = 0;
  192741. streamConfig->GetNumberOfCapabilities (&count, &size);
  192742. if (size == sizeof (VIDEO_STREAM_CONFIG_CAPS))
  192743. {
  192744. for (int i = 0; i < count; ++i)
  192745. {
  192746. VIDEO_STREAM_CONFIG_CAPS scc;
  192747. AM_MEDIA_TYPE* config;
  192748. HRESULT hr = streamConfig->GetStreamCaps (i, &config, (BYTE*) &scc);
  192749. if (SUCCEEDED (hr))
  192750. {
  192751. if (scc.InputSize.cx >= minWidth
  192752. && scc.InputSize.cy >= minHeight
  192753. && scc.InputSize.cx <= maxWidth
  192754. && scc.InputSize.cy <= maxHeight)
  192755. {
  192756. hr = streamConfig->SetFormat (config);
  192757. deleteMediaType (config);
  192758. return SUCCEEDED (hr);
  192759. }
  192760. deleteMediaType (config);
  192761. }
  192762. }
  192763. }
  192764. return false;
  192765. }
  192766. static bool getPin (IBaseFilter* filter, const PIN_DIRECTION wantedDirection, IPin** result, const char* pinName = 0)
  192767. {
  192768. ComSmartPtr <IEnumPins> enumerator;
  192769. ComSmartPtr <IPin> pin;
  192770. filter->EnumPins (&enumerator);
  192771. while (enumerator->Next (1, &pin, 0) == S_OK)
  192772. {
  192773. PIN_DIRECTION dir;
  192774. pin->QueryDirection (&dir);
  192775. if (wantedDirection == dir)
  192776. {
  192777. PIN_INFO info;
  192778. zerostruct (info);
  192779. pin->QueryPinInfo (&info);
  192780. if (pinName == 0 || String (pinName).equalsIgnoreCase (String (info.achName)))
  192781. {
  192782. pin.p->AddRef();
  192783. *result = pin;
  192784. return true;
  192785. }
  192786. }
  192787. }
  192788. return false;
  192789. }
  192790. bool connectFilters (IBaseFilter* const first, IBaseFilter* const second) const
  192791. {
  192792. ComSmartPtr <IPin> in, out;
  192793. return getPin (first, PINDIR_OUTPUT, &out)
  192794. && getPin (second, PINDIR_INPUT, &in)
  192795. && SUCCEEDED (graphBuilder->Connect (out, in));
  192796. }
  192797. bool addGraphToRot()
  192798. {
  192799. ComSmartPtr <IRunningObjectTable> rot;
  192800. if (FAILED (GetRunningObjectTable (0, &rot)))
  192801. return false;
  192802. ComSmartPtr <IMoniker> moniker;
  192803. WCHAR buffer[128];
  192804. HRESULT hr = CreateItemMoniker (_T("!"), buffer, &moniker);
  192805. if (FAILED (hr))
  192806. return false;
  192807. graphRegistrationID = 0;
  192808. return SUCCEEDED (rot->Register (0, graphBuilder, moniker, &graphRegistrationID));
  192809. }
  192810. void removeGraphFromRot()
  192811. {
  192812. ComSmartPtr <IRunningObjectTable> rot;
  192813. if (SUCCEEDED (GetRunningObjectTable (0, &rot)))
  192814. rot->Revoke (graphRegistrationID);
  192815. }
  192816. static void deleteMediaType (AM_MEDIA_TYPE* const pmt)
  192817. {
  192818. if (pmt->cbFormat != 0)
  192819. CoTaskMemFree ((PVOID) pmt->pbFormat);
  192820. if (pmt->pUnk != 0)
  192821. pmt->pUnk->Release();
  192822. CoTaskMemFree (pmt);
  192823. }
  192824. class GrabberCallback : public ISampleGrabberCB
  192825. {
  192826. public:
  192827. GrabberCallback (DShowCameraDeviceInteral& owner_)
  192828. : owner (owner_)
  192829. {
  192830. }
  192831. HRESULT __stdcall QueryInterface (REFIID id, void** result)
  192832. {
  192833. if (id == IID_IUnknown)
  192834. *result = dynamic_cast <IUnknown*> (this);
  192835. else if (id == IID_ISampleGrabberCB)
  192836. *result = dynamic_cast <ISampleGrabberCB*> (this);
  192837. else
  192838. {
  192839. *result = 0;
  192840. return E_NOINTERFACE;
  192841. }
  192842. AddRef();
  192843. return S_OK;
  192844. }
  192845. ULONG __stdcall AddRef() { return ++refCount; }
  192846. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  192847. STDMETHODIMP SampleCB (double /*SampleTime*/, IMediaSample* /*pSample*/)
  192848. {
  192849. return E_FAIL;
  192850. }
  192851. STDMETHODIMP BufferCB (double time, BYTE* buffer, long bufferSize)
  192852. {
  192853. owner.handleFrame (time, buffer, bufferSize);
  192854. return S_OK;
  192855. }
  192856. private:
  192857. int refCount;
  192858. DShowCameraDeviceInteral& owner;
  192859. GrabberCallback (const GrabberCallback&);
  192860. const GrabberCallback& operator= (const GrabberCallback&);
  192861. };
  192862. ComSmartPtr <GrabberCallback> callback;
  192863. VoidArray listeners;
  192864. CriticalSection listenerLock;
  192865. DShowCameraDeviceInteral (const DShowCameraDeviceInteral&);
  192866. const DShowCameraDeviceInteral& operator= (const DShowCameraDeviceInteral&);
  192867. };
  192868. CameraDevice::CameraDevice (const String& name_, int /*index*/)
  192869. : name (name_)
  192870. {
  192871. isRecording = false;
  192872. }
  192873. CameraDevice::~CameraDevice()
  192874. {
  192875. stopRecording();
  192876. delete (DShowCameraDeviceInteral*) internal;
  192877. internal = 0;
  192878. }
  192879. Component* CameraDevice::createViewerComponent()
  192880. {
  192881. return new DShowCameraDeviceInteral::DShowCaptureViewerComp ((DShowCameraDeviceInteral*) internal);
  192882. }
  192883. const String CameraDevice::getFileExtension()
  192884. {
  192885. return ".avi";
  192886. }
  192887. void CameraDevice::startRecordingToFile (const File& file)
  192888. {
  192889. stopRecording();
  192890. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192891. d->addUser();
  192892. isRecording = d->createFileCaptureFilter (file);
  192893. }
  192894. const Time CameraDevice::getTimeOfFirstRecordedFrame() const
  192895. {
  192896. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192897. return d->firstRecordedTime;
  192898. }
  192899. void CameraDevice::stopRecording()
  192900. {
  192901. if (isRecording)
  192902. {
  192903. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192904. d->removeFileCaptureFilter();
  192905. d->removeUser();
  192906. isRecording = false;
  192907. }
  192908. }
  192909. void CameraDevice::addListener (CameraImageListener* listenerToAdd)
  192910. {
  192911. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192912. if (listenerToAdd != 0)
  192913. d->addListener (listenerToAdd);
  192914. }
  192915. void CameraDevice::removeListener (CameraImageListener* listenerToRemove)
  192916. {
  192917. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192918. if (listenerToRemove != 0)
  192919. d->removeListener (listenerToRemove);
  192920. }
  192921. static ComSmartPtr <IBaseFilter> enumerateCameras (StringArray* const names,
  192922. const int deviceIndexToOpen,
  192923. String& name)
  192924. {
  192925. int index = 0;
  192926. ComSmartPtr <IBaseFilter> result;
  192927. ComSmartPtr <ICreateDevEnum> pDevEnum;
  192928. HRESULT hr = pDevEnum.CoCreateInstance (CLSID_SystemDeviceEnum, CLSCTX_INPROC);
  192929. if (SUCCEEDED (hr))
  192930. {
  192931. ComSmartPtr <IEnumMoniker> enumerator;
  192932. hr = pDevEnum->CreateClassEnumerator (CLSID_VideoInputDeviceCategory, &enumerator, 0);
  192933. if (SUCCEEDED (hr) && enumerator != 0)
  192934. {
  192935. ComSmartPtr <IBaseFilter> captureFilter;
  192936. ComSmartPtr <IMoniker> moniker;
  192937. ULONG fetched;
  192938. while (enumerator->Next (1, &moniker, &fetched) == S_OK)
  192939. {
  192940. hr = moniker->BindToObject (0, 0, IID_IBaseFilter, (void**) &captureFilter);
  192941. if (SUCCEEDED (hr))
  192942. {
  192943. ComSmartPtr <IPropertyBag> propertyBag;
  192944. hr = moniker->BindToStorage (0, 0, IID_IPropertyBag, (void**) &propertyBag);
  192945. if (SUCCEEDED (hr))
  192946. {
  192947. VARIANT var;
  192948. var.vt = VT_BSTR;
  192949. hr = propertyBag->Read (_T("FriendlyName"), &var, 0);
  192950. propertyBag = 0;
  192951. if (SUCCEEDED (hr))
  192952. {
  192953. if (names != 0)
  192954. names->add (var.bstrVal);
  192955. if (index == deviceIndexToOpen)
  192956. {
  192957. name = var.bstrVal;
  192958. result = captureFilter;
  192959. captureFilter = 0;
  192960. break;
  192961. }
  192962. ++index;
  192963. }
  192964. moniker = 0;
  192965. }
  192966. captureFilter = 0;
  192967. }
  192968. }
  192969. }
  192970. }
  192971. return result;
  192972. }
  192973. const StringArray CameraDevice::getAvailableDevices()
  192974. {
  192975. StringArray devs;
  192976. String dummy;
  192977. enumerateCameras (&devs, -1, dummy);
  192978. return devs;
  192979. }
  192980. CameraDevice* CameraDevice::openDevice (int index,
  192981. int minWidth, int minHeight,
  192982. int maxWidth, int maxHeight)
  192983. {
  192984. ComSmartPtr <ICaptureGraphBuilder2> captureGraphBuilder;
  192985. HRESULT hr = captureGraphBuilder.CoCreateInstance (CLSID_CaptureGraphBuilder2, CLSCTX_INPROC);
  192986. if (SUCCEEDED (hr))
  192987. {
  192988. String name;
  192989. const ComSmartPtr <IBaseFilter> filter (enumerateCameras (0, index, name));
  192990. if (filter != 0)
  192991. {
  192992. CameraDevice* const cam = new CameraDevice (name, index);
  192993. DShowCameraDeviceInteral* const intern
  192994. = new DShowCameraDeviceInteral (cam, captureGraphBuilder, filter,
  192995. minWidth, minHeight, maxWidth, maxHeight);
  192996. cam->internal = intern;
  192997. if (intern->ok)
  192998. return cam;
  192999. else
  193000. delete cam;
  193001. }
  193002. }
  193003. return 0;
  193004. }
  193005. #endif
  193006. /*** End of inlined file: juce_win32_CameraDevice.cpp ***/
  193007. #endif
  193008. // Auto-link the other win32 libs that are needed by library calls..
  193009. #if (JUCE_AMALGAMATED_TEMPLATE || defined (JUCE_DLL_BUILD)) && JUCE_MSVC && ! DONT_AUTOLINK_TO_WIN32_LIBRARIES
  193010. /*** Start of inlined file: juce_win32_AutoLinkLibraries.h ***/
  193011. // Auto-links to various win32 libs that are needed by library calls..
  193012. #pragma comment(lib, "kernel32.lib")
  193013. #pragma comment(lib, "user32.lib")
  193014. #pragma comment(lib, "shell32.lib")
  193015. #pragma comment(lib, "gdi32.lib")
  193016. #pragma comment(lib, "vfw32.lib")
  193017. #pragma comment(lib, "comdlg32.lib")
  193018. #pragma comment(lib, "winmm.lib")
  193019. #pragma comment(lib, "wininet.lib")
  193020. #pragma comment(lib, "ole32.lib")
  193021. #pragma comment(lib, "oleaut32.lib")
  193022. #pragma comment(lib, "advapi32.lib")
  193023. #pragma comment(lib, "ws2_32.lib")
  193024. #pragma comment(lib, "comsupp.lib")
  193025. #pragma comment(lib, "version.lib")
  193026. #if JUCE_OPENGL
  193027. #pragma comment(lib, "OpenGL32.Lib")
  193028. #pragma comment(lib, "GlU32.Lib")
  193029. #endif
  193030. #if JUCE_QUICKTIME
  193031. #pragma comment (lib, "QTMLClient.lib")
  193032. #endif
  193033. #if JUCE_USE_CAMERA
  193034. #pragma comment (lib, "Strmiids.lib")
  193035. #endif
  193036. /*** End of inlined file: juce_win32_AutoLinkLibraries.h ***/
  193037. #endif
  193038. END_JUCE_NAMESPACE
  193039. /*** End of inlined file: juce_win32_NativeCode.cpp ***/
  193040. #endif
  193041. #if JUCE_LINUX
  193042. /*** Start of inlined file: juce_linux_NativeCode.cpp ***/
  193043. BEGIN_JUCE_NAMESPACE
  193044. #if defined (CPU_ISSET) && ! defined (SUPPORT_AFFINITIES)
  193045. #define SUPPORT_AFFINITIES 1
  193046. #endif
  193047. #define JUCE_INCLUDED_FILE 1
  193048. // Now include the actual code files..
  193049. /*** Start of inlined file: juce_posix_SharedCode.h ***/
  193050. CriticalSection::CriticalSection() throw()
  193051. {
  193052. pthread_mutexattr_t atts;
  193053. pthread_mutexattr_init (&atts);
  193054. pthread_mutexattr_settype (&atts, PTHREAD_MUTEX_RECURSIVE);
  193055. pthread_mutex_init (&internal, &atts);
  193056. }
  193057. CriticalSection::~CriticalSection() throw()
  193058. {
  193059. pthread_mutex_destroy (&internal);
  193060. }
  193061. void CriticalSection::enter() const throw()
  193062. {
  193063. pthread_mutex_lock (&internal);
  193064. }
  193065. bool CriticalSection::tryEnter() const throw()
  193066. {
  193067. return pthread_mutex_trylock (&internal) == 0;
  193068. }
  193069. void CriticalSection::exit() const throw()
  193070. {
  193071. pthread_mutex_unlock (&internal);
  193072. }
  193073. struct EventStruct
  193074. {
  193075. pthread_cond_t condition;
  193076. pthread_mutex_t mutex;
  193077. bool triggered;
  193078. };
  193079. WaitableEvent::WaitableEvent() throw()
  193080. {
  193081. EventStruct* const es = new EventStruct();
  193082. es->triggered = false;
  193083. pthread_cond_init (&es->condition, 0);
  193084. pthread_mutex_init (&es->mutex, 0);
  193085. internal = es;
  193086. }
  193087. WaitableEvent::~WaitableEvent() throw()
  193088. {
  193089. EventStruct* const es = (EventStruct*) internal;
  193090. pthread_cond_destroy (&es->condition);
  193091. pthread_mutex_destroy (&es->mutex);
  193092. delete es;
  193093. }
  193094. bool WaitableEvent::wait (const int timeOutMillisecs) const throw()
  193095. {
  193096. EventStruct* const es = (EventStruct*) internal;
  193097. pthread_mutex_lock (&es->mutex);
  193098. if (timeOutMillisecs < 0)
  193099. {
  193100. while (! es->triggered)
  193101. pthread_cond_wait (&es->condition, &es->mutex);
  193102. }
  193103. else
  193104. {
  193105. while (! es->triggered)
  193106. {
  193107. struct timeval t;
  193108. gettimeofday (&t, 0);
  193109. struct timespec time;
  193110. time.tv_sec = t.tv_sec + (timeOutMillisecs / 1000);
  193111. time.tv_nsec = (t.tv_usec + ((timeOutMillisecs % 1000) * 1000)) * 1000;
  193112. if (time.tv_nsec >= 1000000000)
  193113. {
  193114. time.tv_nsec -= 1000000000;
  193115. time.tv_sec++;
  193116. }
  193117. if (pthread_cond_timedwait (&es->condition, &es->mutex, &time) == ETIMEDOUT)
  193118. {
  193119. pthread_mutex_unlock (&es->mutex);
  193120. return false;
  193121. }
  193122. }
  193123. }
  193124. es->triggered = false;
  193125. pthread_mutex_unlock (&es->mutex);
  193126. return true;
  193127. }
  193128. void WaitableEvent::signal() const throw()
  193129. {
  193130. EventStruct* const es = (EventStruct*) internal;
  193131. pthread_mutex_lock (&es->mutex);
  193132. es->triggered = true;
  193133. pthread_cond_broadcast (&es->condition);
  193134. pthread_mutex_unlock (&es->mutex);
  193135. }
  193136. void WaitableEvent::reset() const throw()
  193137. {
  193138. EventStruct* const es = (EventStruct*) internal;
  193139. pthread_mutex_lock (&es->mutex);
  193140. es->triggered = false;
  193141. pthread_mutex_unlock (&es->mutex);
  193142. }
  193143. void JUCE_CALLTYPE Thread::sleep (int millisecs)
  193144. {
  193145. struct timespec time;
  193146. time.tv_sec = millisecs / 1000;
  193147. time.tv_nsec = (millisecs % 1000) * 1000000;
  193148. nanosleep (&time, 0);
  193149. }
  193150. const tchar File::separator = T('/');
  193151. const tchar* File::separatorString = T("/");
  193152. bool juce_copyFile (const String& s, const String& d);
  193153. static bool juce_stat (const String& fileName, struct stat& info)
  193154. {
  193155. return fileName.isNotEmpty()
  193156. && (stat (fileName.toUTF8(), &info) == 0);
  193157. }
  193158. bool juce_isDirectory (const String& fileName)
  193159. {
  193160. struct stat info;
  193161. return fileName.isEmpty()
  193162. || (juce_stat (fileName, info)
  193163. && ((info.st_mode & S_IFDIR) != 0));
  193164. }
  193165. bool juce_fileExists (const String& fileName, const bool dontCountDirectories)
  193166. {
  193167. if (fileName.isEmpty())
  193168. return false;
  193169. const char* const fileNameUTF8 = fileName.toUTF8();
  193170. bool exists = access (fileNameUTF8, F_OK) == 0;
  193171. if (exists && dontCountDirectories)
  193172. {
  193173. struct stat info;
  193174. const int res = stat (fileNameUTF8, &info);
  193175. if (res == 0 && (info.st_mode & S_IFDIR) != 0)
  193176. exists = false;
  193177. }
  193178. return exists;
  193179. }
  193180. int64 juce_getFileSize (const String& fileName)
  193181. {
  193182. struct stat info;
  193183. return juce_stat (fileName, info) ? info.st_size : 0;
  193184. }
  193185. bool juce_canWriteToFile (const String& fileName)
  193186. {
  193187. return access (fileName.toUTF8(), W_OK) == 0;
  193188. }
  193189. bool juce_deleteFile (const String& fileName)
  193190. {
  193191. if (juce_isDirectory (fileName))
  193192. return rmdir ((const char*) fileName.toUTF8()) == 0;
  193193. else
  193194. return remove ((const char*) fileName.toUTF8()) == 0;
  193195. }
  193196. bool juce_moveFile (const String& source, const String& dest)
  193197. {
  193198. if (rename (source.toUTF8(), dest.toUTF8()) == 0)
  193199. return true;
  193200. if (juce_canWriteToFile (source)
  193201. && juce_copyFile (source, dest))
  193202. {
  193203. if (juce_deleteFile (source))
  193204. return true;
  193205. juce_deleteFile (dest);
  193206. }
  193207. return false;
  193208. }
  193209. void juce_createDirectory (const String& fileName)
  193210. {
  193211. mkdir (fileName.toUTF8(), 0777);
  193212. }
  193213. void* juce_fileOpen (const String& fileName, bool forWriting)
  193214. {
  193215. int flags = O_RDONLY;
  193216. if (forWriting)
  193217. {
  193218. if (juce_fileExists (fileName, false))
  193219. {
  193220. const int f = open ((const char*) fileName.toUTF8(), O_RDWR, 00644);
  193221. if (f != -1)
  193222. lseek (f, 0, SEEK_END);
  193223. return (void*) f;
  193224. }
  193225. else
  193226. {
  193227. flags = O_RDWR + O_CREAT;
  193228. }
  193229. }
  193230. return (void*) open ((const char*) fileName.toUTF8(), flags, 00644);
  193231. }
  193232. void juce_fileClose (void* handle)
  193233. {
  193234. if (handle != 0)
  193235. close ((int) (pointer_sized_int) handle);
  193236. }
  193237. int juce_fileRead (void* handle, void* buffer, int size)
  193238. {
  193239. if (handle != 0)
  193240. return (int) read ((int) (pointer_sized_int) handle, buffer, size);
  193241. return 0;
  193242. }
  193243. int juce_fileWrite (void* handle, const void* buffer, int size)
  193244. {
  193245. if (handle != 0)
  193246. return (int) write ((int) (pointer_sized_int) handle, buffer, size);
  193247. return 0;
  193248. }
  193249. int64 juce_fileSetPosition (void* handle, int64 pos)
  193250. {
  193251. if (handle != 0 && lseek ((int) (pointer_sized_int) handle, pos, SEEK_SET) == pos)
  193252. return pos;
  193253. return -1;
  193254. }
  193255. int64 juce_fileGetPosition (void* handle)
  193256. {
  193257. if (handle != 0)
  193258. return lseek ((int) (pointer_sized_int) handle, 0, SEEK_CUR);
  193259. else
  193260. return -1;
  193261. }
  193262. void juce_fileFlush (void* handle)
  193263. {
  193264. if (handle != 0)
  193265. fsync ((int) (pointer_sized_int) handle);
  193266. }
  193267. const File juce_getExecutableFile()
  193268. {
  193269. Dl_info exeInfo;
  193270. dladdr ((const void*) juce_getExecutableFile, &exeInfo);
  193271. return File (exeInfo.dli_fname);
  193272. }
  193273. // if this file doesn't exist, find a parent of it that does..
  193274. static bool doStatFS (const File* file, struct statfs& result)
  193275. {
  193276. File f (*file);
  193277. for (int i = 5; --i >= 0;)
  193278. {
  193279. if (f.exists())
  193280. break;
  193281. f = f.getParentDirectory();
  193282. }
  193283. return statfs (f.getFullPathName().toUTF8(), &result) == 0;
  193284. }
  193285. int64 File::getBytesFreeOnVolume() const
  193286. {
  193287. struct statfs buf;
  193288. if (doStatFS (this, buf))
  193289. return (int64) buf.f_bsize * (int64) buf.f_bavail; // Note: this returns space available to non-super user
  193290. return 0;
  193291. }
  193292. int64 File::getVolumeTotalSize() const
  193293. {
  193294. struct statfs buf;
  193295. if (doStatFS (this, buf))
  193296. return (int64) buf.f_bsize * (int64) buf.f_blocks;
  193297. return 0;
  193298. }
  193299. const String juce_getVolumeLabel (const String& filenameOnVolume,
  193300. int& volumeSerialNumber)
  193301. {
  193302. volumeSerialNumber = 0;
  193303. #if JUCE_MAC
  193304. struct VolAttrBuf
  193305. {
  193306. u_int32_t length;
  193307. attrreference_t mountPointRef;
  193308. char mountPointSpace [MAXPATHLEN];
  193309. } attrBuf;
  193310. struct attrlist attrList;
  193311. zerostruct (attrList);
  193312. attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
  193313. attrList.volattr = ATTR_VOL_INFO | ATTR_VOL_NAME;
  193314. File f (filenameOnVolume);
  193315. for (;;)
  193316. {
  193317. if (getattrlist ((const char*) f.getFullPathName().toUTF8(),
  193318. &attrList, &attrBuf, sizeof(attrBuf), 0) == 0)
  193319. {
  193320. return String::fromUTF8 (((const uint8*) &attrBuf.mountPointRef) + attrBuf.mountPointRef.attr_dataoffset,
  193321. (int) attrBuf.mountPointRef.attr_length);
  193322. }
  193323. const File parent (f.getParentDirectory());
  193324. if (f == parent)
  193325. break;
  193326. f = parent;
  193327. }
  193328. #endif
  193329. return String::empty;
  193330. }
  193331. void juce_runSystemCommand (const String& command)
  193332. {
  193333. int result = system ((const char*) command.toUTF8());
  193334. (void) result;
  193335. }
  193336. const String juce_getOutputFromCommand (const String& command)
  193337. {
  193338. // slight bodge here, as we just pipe the output into a temp file and read it...
  193339. const File tempFile (File::getSpecialLocation (File::tempDirectory)
  193340. .getNonexistentChildFile (String::toHexString (Random::getSystemRandom().nextInt()), ".tmp", false));
  193341. juce_runSystemCommand (command + " > " + tempFile.getFullPathName());
  193342. String result (tempFile.loadFileAsString());
  193343. tempFile.deleteFile();
  193344. return result;
  193345. }
  193346. InterProcessLock::InterProcessLock (const String& name_)
  193347. : internal (0),
  193348. name (name_),
  193349. reentrancyLevel (0)
  193350. {
  193351. #if JUCE_MAC
  193352. // (don't use getSpecialLocation() to avoid the temp folder being different for each app)
  193353. const File temp (File (T("~/Library/Caches/Juce")).getChildFile (name));
  193354. #else
  193355. const File temp (File::getSpecialLocation (File::tempDirectory).getChildFile (name));
  193356. #endif
  193357. temp.create();
  193358. internal = open (temp.getFullPathName().toUTF8(), O_RDWR);
  193359. }
  193360. InterProcessLock::~InterProcessLock()
  193361. {
  193362. while (reentrancyLevel > 0)
  193363. this->exit();
  193364. close (internal);
  193365. }
  193366. bool InterProcessLock::enter (const int timeOutMillisecs)
  193367. {
  193368. if (internal == 0)
  193369. return false;
  193370. if (reentrancyLevel != 0)
  193371. return true;
  193372. const int64 endTime = Time::currentTimeMillis() + timeOutMillisecs;
  193373. struct flock fl;
  193374. zerostruct (fl);
  193375. fl.l_whence = SEEK_SET;
  193376. fl.l_type = F_WRLCK;
  193377. for (;;)
  193378. {
  193379. const int result = fcntl (internal, F_SETLK, &fl);
  193380. if (result >= 0)
  193381. {
  193382. ++reentrancyLevel;
  193383. return true;
  193384. }
  193385. if (errno != EINTR)
  193386. {
  193387. if (timeOutMillisecs == 0
  193388. || (timeOutMillisecs > 0 && Time::currentTimeMillis() >= endTime))
  193389. break;
  193390. Thread::sleep (10);
  193391. }
  193392. }
  193393. return false;
  193394. }
  193395. void InterProcessLock::exit()
  193396. {
  193397. if (reentrancyLevel > 0 && internal != 0)
  193398. {
  193399. --reentrancyLevel;
  193400. struct flock fl;
  193401. zerostruct (fl);
  193402. fl.l_whence = SEEK_SET;
  193403. fl.l_type = F_UNLCK;
  193404. for (;;)
  193405. {
  193406. const int result = fcntl (internal, F_SETLKW, &fl);
  193407. if (result >= 0 || errno != EINTR)
  193408. break;
  193409. }
  193410. }
  193411. }
  193412. /*** End of inlined file: juce_posix_SharedCode.h ***/
  193413. /*** Start of inlined file: juce_linux_Files.cpp ***/
  193414. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  193415. // compiled on its own).
  193416. #if JUCE_INCLUDED_FILE
  193417. #define U_ISOFS_SUPER_MAGIC (short) 0x9660 // linux/iso_fs.h
  193418. #define U_MSDOS_SUPER_MAGIC (short) 0x4d44 // linux/msdos_fs.h
  193419. #define U_NFS_SUPER_MAGIC (short) 0x6969 // linux/nfs_fs.h
  193420. #define U_SMB_SUPER_MAGIC (short) 0x517B // linux/smb_fs.h
  193421. void juce_getFileTimes (const String& fileName,
  193422. int64& modificationTime,
  193423. int64& accessTime,
  193424. int64& creationTime)
  193425. {
  193426. modificationTime = 0;
  193427. accessTime = 0;
  193428. creationTime = 0;
  193429. struct stat info;
  193430. const int res = stat (fileName.toUTF8(), &info);
  193431. if (res == 0)
  193432. {
  193433. modificationTime = (int64) info.st_mtime * 1000;
  193434. accessTime = (int64) info.st_atime * 1000;
  193435. creationTime = (int64) info.st_ctime * 1000;
  193436. }
  193437. }
  193438. bool juce_setFileTimes (const String& fileName,
  193439. int64 modificationTime,
  193440. int64 accessTime,
  193441. int64 creationTime)
  193442. {
  193443. struct utimbuf times;
  193444. times.actime = (time_t) (accessTime / 1000);
  193445. times.modtime = (time_t) (modificationTime / 1000);
  193446. return utime (fileName.toUTF8(), &times) == 0;
  193447. }
  193448. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly)
  193449. {
  193450. struct stat info;
  193451. const int res = stat (fileName.toUTF8(), &info);
  193452. if (res != 0)
  193453. return false;
  193454. info.st_mode &= 0777; // Just permissions
  193455. if( isReadOnly )
  193456. info.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
  193457. else
  193458. // Give everybody write permission?
  193459. info.st_mode |= S_IWUSR | S_IWGRP | S_IWOTH;
  193460. return chmod (fileName.toUTF8(), info.st_mode) == 0;
  193461. }
  193462. bool juce_copyFile (const String& s, const String& d)
  193463. {
  193464. const File source (s), dest (d);
  193465. FileInputStream* in = source.createInputStream();
  193466. bool ok = false;
  193467. if (in != 0)
  193468. {
  193469. if (dest.deleteFile())
  193470. {
  193471. FileOutputStream* const out = dest.createOutputStream();
  193472. if (out != 0)
  193473. {
  193474. const int bytesCopied = out->writeFromInputStream (*in, -1);
  193475. delete out;
  193476. ok = (bytesCopied == source.getSize());
  193477. if (! ok)
  193478. dest.deleteFile();
  193479. }
  193480. }
  193481. delete in;
  193482. }
  193483. return ok;
  193484. }
  193485. const StringArray juce_getFileSystemRoots()
  193486. {
  193487. StringArray s;
  193488. s.add (T("/"));
  193489. return s;
  193490. }
  193491. bool File::isOnCDRomDrive() const
  193492. {
  193493. struct statfs buf;
  193494. if (statfs (getFullPathName().toUTF8(), &buf) == 0)
  193495. return (buf.f_type == U_ISOFS_SUPER_MAGIC);
  193496. // Assume not if this fails for some reason
  193497. return false;
  193498. }
  193499. bool File::isOnHardDisk() const
  193500. {
  193501. struct statfs buf;
  193502. if (statfs (getFullPathName().toUTF8(), &buf) == 0)
  193503. {
  193504. switch (buf.f_type)
  193505. {
  193506. case U_ISOFS_SUPER_MAGIC: // CD-ROM
  193507. case U_MSDOS_SUPER_MAGIC: // Probably floppy (but could be mounted FAT filesystem)
  193508. case U_NFS_SUPER_MAGIC: // Network NFS
  193509. case U_SMB_SUPER_MAGIC: // Network Samba
  193510. return false;
  193511. default:
  193512. // Assume anything else is a hard-disk (but note it could
  193513. // be a RAM disk. There isn't a good way of determining
  193514. // this for sure)
  193515. return true;
  193516. }
  193517. }
  193518. // Assume so if this fails for some reason
  193519. return true;
  193520. }
  193521. bool File::isOnRemovableDrive() const
  193522. {
  193523. jassertfalse // xxx not implemented for linux!
  193524. return false;
  193525. }
  193526. bool File::isHidden() const
  193527. {
  193528. return getFileName().startsWithChar (T('.'));
  193529. }
  193530. const char* juce_Argv0 = 0; // referenced from juce_Application.cpp
  193531. const File File::getSpecialLocation (const SpecialLocationType type)
  193532. {
  193533. switch (type)
  193534. {
  193535. case userHomeDirectory:
  193536. {
  193537. const char* homeDir = getenv ("HOME");
  193538. if (homeDir == 0)
  193539. {
  193540. struct passwd* const pw = getpwuid (getuid());
  193541. if (pw != 0)
  193542. homeDir = pw->pw_dir;
  193543. }
  193544. return File (String::fromUTF8 ((const uint8*) homeDir));
  193545. }
  193546. case userDocumentsDirectory:
  193547. case userMusicDirectory:
  193548. case userMoviesDirectory:
  193549. case userApplicationDataDirectory:
  193550. return File ("~");
  193551. case userDesktopDirectory:
  193552. return File ("~/Desktop");
  193553. case commonApplicationDataDirectory:
  193554. return File ("/var");
  193555. case globalApplicationsDirectory:
  193556. return File ("/usr");
  193557. case tempDirectory:
  193558. {
  193559. File tmp ("/var/tmp");
  193560. if (! tmp.isDirectory())
  193561. {
  193562. tmp = T("/tmp");
  193563. if (! tmp.isDirectory())
  193564. tmp = File::getCurrentWorkingDirectory();
  193565. }
  193566. return tmp;
  193567. }
  193568. case invokedExecutableFile:
  193569. if (juce_Argv0 != 0)
  193570. return File (String::fromUTF8 ((const uint8*) juce_Argv0));
  193571. // deliberate fall-through...
  193572. case currentExecutableFile:
  193573. case currentApplicationFile:
  193574. return juce_getExecutableFile();
  193575. default:
  193576. jassertfalse // unknown type?
  193577. break;
  193578. }
  193579. return File::nonexistent;
  193580. }
  193581. const File File::getCurrentWorkingDirectory()
  193582. {
  193583. char buf [2048];
  193584. return File (String::fromUTF8 ((const uint8*) getcwd (buf, sizeof (buf))));
  193585. }
  193586. bool File::setAsCurrentWorkingDirectory() const
  193587. {
  193588. return chdir (getFullPathName().toUTF8()) == 0;
  193589. }
  193590. const String File::getVersion() const
  193591. {
  193592. return String::empty; // xxx not yet implemented
  193593. }
  193594. const File File::getLinkedTarget() const
  193595. {
  193596. char buffer [4096];
  193597. size_t numChars = readlink ((const char*) getFullPathName().toUTF8(),
  193598. buffer, sizeof (buffer));
  193599. if (numChars > 0 && numChars <= sizeof (buffer))
  193600. return File (String::fromUTF8 ((const uint8*) buffer, (int) numChars));
  193601. return *this;
  193602. }
  193603. bool File::moveToTrash() const
  193604. {
  193605. if (! exists())
  193606. return true;
  193607. File trashCan (T("~/.Trash"));
  193608. if (! trashCan.isDirectory())
  193609. trashCan = T("~/.local/share/Trash/files");
  193610. if (! trashCan.isDirectory())
  193611. return false;
  193612. return moveFileTo (trashCan.getNonexistentChildFile (getFileNameWithoutExtension(),
  193613. getFileExtension()));
  193614. }
  193615. struct FindFileStruct
  193616. {
  193617. String parentDir, wildCard;
  193618. DIR* dir;
  193619. bool getNextMatch (String& result, bool* const isDir, bool* const isHidden, int64* const fileSize,
  193620. Time* const modTime, Time* const creationTime, bool* const isReadOnly)
  193621. {
  193622. const char* const wildcardUTF8 = wildCard.toUTF8();
  193623. for (;;)
  193624. {
  193625. struct dirent* const de = readdir (dir);
  193626. if (de == 0)
  193627. break;
  193628. if (fnmatch (wildcardUTF8, de->d_name, FNM_CASEFOLD) == 0)
  193629. {
  193630. result = String::fromUTF8 ((const uint8*) de->d_name);
  193631. const String path (parentDir + result);
  193632. if (isDir != 0 || fileSize != 0)
  193633. {
  193634. struct stat info;
  193635. const bool statOk = (stat (path.toUTF8(), &info) == 0);
  193636. if (isDir != 0)
  193637. *isDir = path.isEmpty() || (statOk && ((info.st_mode & S_IFDIR) != 0));
  193638. if (isHidden != 0)
  193639. *isHidden = (de->d_name[0] == '.');
  193640. if (fileSize != 0)
  193641. *fileSize = statOk ? info.st_size : 0;
  193642. }
  193643. if (modTime != 0 || creationTime != 0)
  193644. {
  193645. int64 m, a, c;
  193646. juce_getFileTimes (path, m, a, c);
  193647. if (modTime != 0)
  193648. *modTime = m;
  193649. if (creationTime != 0)
  193650. *creationTime = c;
  193651. }
  193652. if (isReadOnly != 0)
  193653. *isReadOnly = ! juce_canWriteToFile (path);
  193654. return true;
  193655. }
  193656. }
  193657. return false;
  193658. }
  193659. };
  193660. // returns 0 on failure
  193661. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  193662. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime,
  193663. Time* creationTime, bool* isReadOnly)
  193664. {
  193665. DIR* d = opendir (directory.toUTF8());
  193666. if (d != 0)
  193667. {
  193668. FindFileStruct* ff = new FindFileStruct();
  193669. ff->parentDir = directory;
  193670. if (!ff->parentDir.endsWithChar (File::separator))
  193671. ff->parentDir += File::separator;
  193672. ff->wildCard = wildCard;
  193673. if (wildCard == T("*.*"))
  193674. ff->wildCard = T("*");
  193675. ff->dir = d;
  193676. if (ff->getNextMatch (firstResultFile, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly))
  193677. {
  193678. return ff;
  193679. }
  193680. else
  193681. {
  193682. firstResultFile = String::empty;
  193683. isDir = false;
  193684. isHidden = false;
  193685. closedir (d);
  193686. delete ff;
  193687. }
  193688. }
  193689. return 0;
  193690. }
  193691. bool juce_findFileNext (void* handle, String& resultFile,
  193692. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime, Time* creationTime, bool* isReadOnly)
  193693. {
  193694. FindFileStruct* const ff = (FindFileStruct*) handle;
  193695. if (ff != 0)
  193696. return ff->getNextMatch (resultFile, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly);
  193697. return false;
  193698. }
  193699. void juce_findFileClose (void* handle)
  193700. {
  193701. FindFileStruct* const ff = (FindFileStruct*) handle;
  193702. if (ff != 0)
  193703. {
  193704. closedir (ff->dir);
  193705. delete ff;
  193706. }
  193707. }
  193708. bool juce_launchFile (const String& fileName,
  193709. const String& parameters)
  193710. {
  193711. String cmdString (fileName.replace (T(" "), T("\\ "),false));
  193712. cmdString << " " << parameters;
  193713. if (URL::isProbablyAWebsiteURL (fileName)
  193714. || cmdString.startsWithIgnoreCase (T("file:"))
  193715. || URL::isProbablyAnEmailAddress (fileName))
  193716. {
  193717. // create a command that tries to launch a bunch of likely browsers
  193718. const char* const browserNames[] = { "xdg-open", "/etc/alternatives/x-www-browser", "firefox", "mozilla", "konqueror", "opera" };
  193719. StringArray cmdLines;
  193720. for (int i = 0; i < numElementsInArray (browserNames); ++i)
  193721. cmdLines.add (String (browserNames[i]) + T(" ") + cmdString.trim().quoted());
  193722. cmdString = cmdLines.joinIntoString (T(" || "));
  193723. }
  193724. const char* const argv[4] = { "/bin/sh", "-c", (const char*) cmdString.toUTF8(), 0 };
  193725. const int cpid = fork();
  193726. if (cpid == 0)
  193727. {
  193728. setsid();
  193729. // Child process
  193730. execve (argv[0], (char**) argv, environ);
  193731. exit (0);
  193732. }
  193733. return cpid >= 0;
  193734. }
  193735. void File::revealToUser() const
  193736. {
  193737. if (isDirectory())
  193738. startAsProcess();
  193739. else if (getParentDirectory().exists())
  193740. getParentDirectory().startAsProcess();
  193741. }
  193742. #endif
  193743. /*** End of inlined file: juce_linux_Files.cpp ***/
  193744. /*** Start of inlined file: juce_posix_NamedPipe.cpp ***/
  193745. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  193746. // compiled on its own).
  193747. #if JUCE_INCLUDED_FILE
  193748. struct NamedPipeInternal
  193749. {
  193750. String pipeInName, pipeOutName;
  193751. int pipeIn, pipeOut;
  193752. bool volatile createdPipe, blocked, stopReadOperation;
  193753. static void signalHandler (int) {}
  193754. };
  193755. void NamedPipe::cancelPendingReads()
  193756. {
  193757. while (internal != 0 && ((NamedPipeInternal*) internal)->blocked)
  193758. {
  193759. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193760. intern->stopReadOperation = true;
  193761. char buffer [1] = { 0 };
  193762. int bytesWritten = (int) ::write (intern->pipeIn, buffer, 1);
  193763. (void) bytesWritten;
  193764. int timeout = 2000;
  193765. while (intern->blocked && --timeout >= 0)
  193766. Thread::sleep (2);
  193767. intern->stopReadOperation = false;
  193768. }
  193769. }
  193770. void NamedPipe::close()
  193771. {
  193772. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193773. if (intern != 0)
  193774. {
  193775. internal = 0;
  193776. if (intern->pipeIn != -1)
  193777. ::close (intern->pipeIn);
  193778. if (intern->pipeOut != -1)
  193779. ::close (intern->pipeOut);
  193780. if (intern->createdPipe)
  193781. {
  193782. unlink (intern->pipeInName);
  193783. unlink (intern->pipeOutName);
  193784. }
  193785. delete intern;
  193786. }
  193787. }
  193788. bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
  193789. {
  193790. close();
  193791. NamedPipeInternal* const intern = new NamedPipeInternal();
  193792. internal = intern;
  193793. intern->createdPipe = createPipe;
  193794. intern->blocked = false;
  193795. intern->stopReadOperation = false;
  193796. signal (SIGPIPE, NamedPipeInternal::signalHandler);
  193797. siginterrupt (SIGPIPE, 1);
  193798. const String pipePath (T("/tmp/") + File::createLegalFileName (pipeName));
  193799. intern->pipeInName = pipePath + T("_in");
  193800. intern->pipeOutName = pipePath + T("_out");
  193801. intern->pipeIn = -1;
  193802. intern->pipeOut = -1;
  193803. if (createPipe)
  193804. {
  193805. if ((mkfifo (intern->pipeInName, 0666) && errno != EEXIST)
  193806. || (mkfifo (intern->pipeOutName, 0666) && errno != EEXIST))
  193807. {
  193808. delete intern;
  193809. internal = 0;
  193810. return false;
  193811. }
  193812. }
  193813. return true;
  193814. }
  193815. int NamedPipe::read (void* destBuffer, int maxBytesToRead, int /*timeOutMilliseconds*/)
  193816. {
  193817. int bytesRead = -1;
  193818. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193819. if (intern != 0)
  193820. {
  193821. intern->blocked = true;
  193822. if (intern->pipeIn == -1)
  193823. {
  193824. if (intern->createdPipe)
  193825. intern->pipeIn = ::open (intern->pipeInName, O_RDWR);
  193826. else
  193827. intern->pipeIn = ::open (intern->pipeOutName, O_RDWR);
  193828. if (intern->pipeIn == -1)
  193829. {
  193830. intern->blocked = false;
  193831. return -1;
  193832. }
  193833. }
  193834. bytesRead = 0;
  193835. char* p = (char*) destBuffer;
  193836. while (bytesRead < maxBytesToRead)
  193837. {
  193838. const int bytesThisTime = maxBytesToRead - bytesRead;
  193839. const int numRead = (int) ::read (intern->pipeIn, p, bytesThisTime);
  193840. if (numRead <= 0 || intern->stopReadOperation)
  193841. {
  193842. bytesRead = -1;
  193843. break;
  193844. }
  193845. bytesRead += numRead;
  193846. p += bytesRead;
  193847. }
  193848. intern->blocked = false;
  193849. }
  193850. return bytesRead;
  193851. }
  193852. int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
  193853. {
  193854. int bytesWritten = -1;
  193855. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193856. if (intern != 0)
  193857. {
  193858. if (intern->pipeOut == -1)
  193859. {
  193860. if (intern->createdPipe)
  193861. intern->pipeOut = ::open (intern->pipeOutName, O_WRONLY);
  193862. else
  193863. intern->pipeOut = ::open (intern->pipeInName, O_WRONLY);
  193864. if (intern->pipeOut == -1)
  193865. {
  193866. return -1;
  193867. }
  193868. }
  193869. const char* p = (const char*) sourceBuffer;
  193870. bytesWritten = 0;
  193871. const uint32 timeOutTime = Time::getMillisecondCounter() + timeOutMilliseconds;
  193872. while (bytesWritten < numBytesToWrite
  193873. && (timeOutMilliseconds < 0 || Time::getMillisecondCounter() < timeOutTime))
  193874. {
  193875. const int bytesThisTime = numBytesToWrite - bytesWritten;
  193876. const int numWritten = (int) ::write (intern->pipeOut, p, bytesThisTime);
  193877. if (numWritten <= 0)
  193878. {
  193879. bytesWritten = -1;
  193880. break;
  193881. }
  193882. bytesWritten += numWritten;
  193883. p += bytesWritten;
  193884. }
  193885. }
  193886. return bytesWritten;
  193887. }
  193888. #endif
  193889. /*** End of inlined file: juce_posix_NamedPipe.cpp ***/
  193890. /*** Start of inlined file: juce_linux_Network.cpp ***/
  193891. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  193892. // compiled on its own).
  193893. #if JUCE_INCLUDED_FILE
  193894. int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian) throw()
  193895. {
  193896. int numResults = 0;
  193897. const int s = socket (AF_INET, SOCK_DGRAM, 0);
  193898. if (s != -1)
  193899. {
  193900. char buf [1024];
  193901. struct ifconf ifc;
  193902. ifc.ifc_len = sizeof (buf);
  193903. ifc.ifc_buf = buf;
  193904. ioctl (s, SIOCGIFCONF, &ifc);
  193905. for (unsigned int i = 0; i < ifc.ifc_len / sizeof (struct ifreq); ++i)
  193906. {
  193907. struct ifreq ifr;
  193908. strcpy (ifr.ifr_name, ifc.ifc_req[i].ifr_name);
  193909. if (ioctl (s, SIOCGIFFLAGS, &ifr) == 0
  193910. && (ifr.ifr_flags & IFF_LOOPBACK) == 0
  193911. && ioctl (s, SIOCGIFHWADDR, &ifr) == 0
  193912. && numResults < maxNum)
  193913. {
  193914. int64 a = 0;
  193915. for (int j = 6; --j >= 0;)
  193916. a = (a << 8) | (uint8) ifr.ifr_hwaddr.sa_data [littleEndian ? j : (5 - j)];
  193917. *addresses++ = a;
  193918. ++numResults;
  193919. }
  193920. }
  193921. close (s);
  193922. }
  193923. return numResults;
  193924. }
  193925. bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
  193926. const String& emailSubject,
  193927. const String& bodyText,
  193928. const StringArray& filesToAttach)
  193929. {
  193930. jassertfalse // xxx todo
  193931. return false;
  193932. }
  193933. class JUCE_HTTPSocketStream
  193934. {
  193935. public:
  193936. JUCE_HTTPSocketStream()
  193937. : readPosition (0),
  193938. socketHandle (-1),
  193939. levelsOfRedirection (0),
  193940. timeoutSeconds (15)
  193941. {
  193942. }
  193943. ~JUCE_HTTPSocketStream()
  193944. {
  193945. closeSocket();
  193946. }
  193947. bool open (const String& url,
  193948. const String& headers,
  193949. const MemoryBlock& postData,
  193950. const bool isPost,
  193951. URL::OpenStreamProgressCallback* callback,
  193952. void* callbackContext,
  193953. int timeOutMs)
  193954. {
  193955. closeSocket();
  193956. uint32 timeOutTime = Time::getMillisecondCounter();
  193957. if (timeOutMs == 0)
  193958. timeOutTime += 60000;
  193959. else if (timeOutMs < 0)
  193960. timeOutTime = 0xffffffff;
  193961. else
  193962. timeOutTime += timeOutMs;
  193963. String hostName, hostPath;
  193964. int hostPort;
  193965. if (! decomposeURL (url, hostName, hostPath, hostPort))
  193966. return false;
  193967. const struct hostent* host = 0;
  193968. int port = 0;
  193969. String proxyName, proxyPath;
  193970. int proxyPort = 0;
  193971. String proxyURL (getenv ("http_proxy"));
  193972. if (proxyURL.startsWithIgnoreCase (T("http://")))
  193973. {
  193974. if (! decomposeURL (proxyURL, proxyName, proxyPath, proxyPort))
  193975. return false;
  193976. host = gethostbyname ((const char*) proxyName.toUTF8());
  193977. port = proxyPort;
  193978. }
  193979. else
  193980. {
  193981. host = gethostbyname ((const char*) hostName.toUTF8());
  193982. port = hostPort;
  193983. }
  193984. if (host == 0)
  193985. return false;
  193986. struct sockaddr_in address;
  193987. zerostruct (address);
  193988. memcpy ((void*) &address.sin_addr, (const void*) host->h_addr, host->h_length);
  193989. address.sin_family = host->h_addrtype;
  193990. address.sin_port = htons (port);
  193991. socketHandle = socket (host->h_addrtype, SOCK_STREAM, 0);
  193992. if (socketHandle == -1)
  193993. return false;
  193994. int receiveBufferSize = 16384;
  193995. setsockopt (socketHandle, SOL_SOCKET, SO_RCVBUF, (char*) &receiveBufferSize, sizeof (receiveBufferSize));
  193996. setsockopt (socketHandle, SOL_SOCKET, SO_KEEPALIVE, 0, 0);
  193997. #if JUCE_MAC
  193998. setsockopt (socketHandle, SOL_SOCKET, SO_NOSIGPIPE, 0, 0);
  193999. #endif
  194000. if (connect (socketHandle, (struct sockaddr*) &address, sizeof (address)) == -1)
  194001. {
  194002. closeSocket();
  194003. return false;
  194004. }
  194005. const MemoryBlock requestHeader (createRequestHeader (hostName, hostPort,
  194006. proxyName, proxyPort,
  194007. hostPath, url,
  194008. headers, postData,
  194009. isPost));
  194010. size_t totalHeaderSent = 0;
  194011. while (totalHeaderSent < requestHeader.getSize())
  194012. {
  194013. if (Time::getMillisecondCounter() > timeOutTime)
  194014. {
  194015. closeSocket();
  194016. return false;
  194017. }
  194018. const int numToSend = jmin (1024, (int) (requestHeader.getSize() - totalHeaderSent));
  194019. if (send (socketHandle,
  194020. ((const char*) requestHeader.getData()) + totalHeaderSent,
  194021. numToSend, 0)
  194022. != numToSend)
  194023. {
  194024. closeSocket();
  194025. return false;
  194026. }
  194027. totalHeaderSent += numToSend;
  194028. if (callback != 0 && ! callback (callbackContext, totalHeaderSent, requestHeader.getSize()))
  194029. {
  194030. closeSocket();
  194031. return false;
  194032. }
  194033. }
  194034. const String responseHeader (readResponse (timeOutTime));
  194035. if (responseHeader.isNotEmpty())
  194036. {
  194037. //DBG (responseHeader);
  194038. StringArray lines;
  194039. lines.addLines (responseHeader);
  194040. // NB - using charToString() here instead of just T(" "), because that was
  194041. // causing a mysterious gcc internal compiler error...
  194042. const int statusCode = responseHeader.fromFirstOccurrenceOf (String::charToString (T(' ')), false, false)
  194043. .substring (0, 3).getIntValue();
  194044. //int contentLength = findHeaderItem (lines, T("Content-Length:")).getIntValue();
  194045. //bool isChunked = findHeaderItem (lines, T("Transfer-Encoding:")).equalsIgnoreCase ("chunked");
  194046. String location (findHeaderItem (lines, T("Location:")));
  194047. if (statusCode >= 300 && statusCode < 400
  194048. && location.isNotEmpty())
  194049. {
  194050. if (! location.startsWithIgnoreCase (T("http://")))
  194051. location = T("http://") + location;
  194052. if (levelsOfRedirection++ < 3)
  194053. return open (location, headers, postData, isPost, callback, callbackContext, timeOutMs);
  194054. }
  194055. else
  194056. {
  194057. levelsOfRedirection = 0;
  194058. return true;
  194059. }
  194060. }
  194061. closeSocket();
  194062. return false;
  194063. }
  194064. int read (void* buffer, int bytesToRead)
  194065. {
  194066. fd_set readbits;
  194067. FD_ZERO (&readbits);
  194068. FD_SET (socketHandle, &readbits);
  194069. struct timeval tv;
  194070. tv.tv_sec = timeoutSeconds;
  194071. tv.tv_usec = 0;
  194072. if (select (socketHandle + 1, &readbits, 0, 0, &tv) <= 0)
  194073. return 0; // (timeout)
  194074. const int bytesRead = jmax (0, (int) recv (socketHandle, buffer, bytesToRead, MSG_WAITALL));
  194075. readPosition += bytesRead;
  194076. return bytesRead;
  194077. }
  194078. int readPosition;
  194079. juce_UseDebuggingNewOperator
  194080. private:
  194081. int socketHandle, levelsOfRedirection;
  194082. const int timeoutSeconds;
  194083. void closeSocket()
  194084. {
  194085. if (socketHandle >= 0)
  194086. close (socketHandle);
  194087. socketHandle = -1;
  194088. }
  194089. const MemoryBlock createRequestHeader (const String& hostName,
  194090. const int hostPort,
  194091. const String& proxyName,
  194092. const int proxyPort,
  194093. const String& hostPath,
  194094. const String& originalURL,
  194095. const String& headers,
  194096. const MemoryBlock& postData,
  194097. const bool isPost)
  194098. {
  194099. String header (isPost ? "POST " : "GET ");
  194100. if (proxyName.isEmpty())
  194101. {
  194102. header << hostPath << " HTTP/1.0\r\nHost: "
  194103. << hostName << ':' << hostPort;
  194104. }
  194105. else
  194106. {
  194107. header << originalURL << " HTTP/1.0\r\nHost: "
  194108. << proxyName << ':' << proxyPort;
  194109. }
  194110. header << "\r\nUser-Agent: JUCE/"
  194111. << JUCE_MAJOR_VERSION << '.' << JUCE_MINOR_VERSION
  194112. << "\r\nConnection: Close\r\nContent-Length: "
  194113. << postData.getSize() << "\r\n"
  194114. << headers << "\r\n";
  194115. MemoryBlock mb;
  194116. mb.append (header.toUTF8(), (int) strlen (header.toUTF8()));
  194117. mb.append (postData.getData(), postData.getSize());
  194118. return mb;
  194119. }
  194120. const String readResponse (const uint32 timeOutTime)
  194121. {
  194122. int bytesRead = 0, numConsecutiveLFs = 0;
  194123. MemoryBlock buffer (1024, true);
  194124. while (numConsecutiveLFs < 2 && bytesRead < 32768
  194125. && Time::getMillisecondCounter() <= timeOutTime)
  194126. {
  194127. fd_set readbits;
  194128. FD_ZERO (&readbits);
  194129. FD_SET (socketHandle, &readbits);
  194130. struct timeval tv;
  194131. tv.tv_sec = timeoutSeconds;
  194132. tv.tv_usec = 0;
  194133. if (select (socketHandle + 1, &readbits, 0, 0, &tv) <= 0)
  194134. return String::empty; // (timeout)
  194135. buffer.ensureSize (bytesRead + 8, true);
  194136. char* const dest = (char*) buffer.getData() + bytesRead;
  194137. if (recv (socketHandle, dest, 1, 0) == -1)
  194138. return String::empty;
  194139. const char lastByte = *dest;
  194140. ++bytesRead;
  194141. if (lastByte == '\n')
  194142. ++numConsecutiveLFs;
  194143. else if (lastByte != '\r')
  194144. numConsecutiveLFs = 0;
  194145. }
  194146. const String header (String::fromUTF8 ((const uint8*) buffer.getData()));
  194147. if (header.startsWithIgnoreCase (T("HTTP/")))
  194148. return header.trimEnd();
  194149. return String::empty;
  194150. }
  194151. static bool decomposeURL (const String& url,
  194152. String& host, String& path, int& port)
  194153. {
  194154. if (! url.startsWithIgnoreCase (T("http://")))
  194155. return false;
  194156. const int nextSlash = url.indexOfChar (7, '/');
  194157. int nextColon = url.indexOfChar (7, ':');
  194158. if (nextColon > nextSlash && nextSlash > 0)
  194159. nextColon = -1;
  194160. if (nextColon >= 0)
  194161. {
  194162. host = url.substring (7, nextColon);
  194163. if (nextSlash >= 0)
  194164. port = url.substring (nextColon + 1, nextSlash).getIntValue();
  194165. else
  194166. port = url.substring (nextColon + 1).getIntValue();
  194167. }
  194168. else
  194169. {
  194170. port = 80;
  194171. if (nextSlash >= 0)
  194172. host = url.substring (7, nextSlash);
  194173. else
  194174. host = url.substring (7);
  194175. }
  194176. if (nextSlash >= 0)
  194177. path = url.substring (nextSlash);
  194178. else
  194179. path = T("/");
  194180. return true;
  194181. }
  194182. static const String findHeaderItem (const StringArray& lines, const String& itemName)
  194183. {
  194184. for (int i = 0; i < lines.size(); ++i)
  194185. if (lines[i].startsWithIgnoreCase (itemName))
  194186. return lines[i].substring (itemName.length()).trim();
  194187. return String::empty;
  194188. }
  194189. };
  194190. bool juce_isOnLine()
  194191. {
  194192. return true;
  194193. }
  194194. void* juce_openInternetFile (const String& url,
  194195. const String& headers,
  194196. const MemoryBlock& postData,
  194197. const bool isPost,
  194198. URL::OpenStreamProgressCallback* callback,
  194199. void* callbackContext,
  194200. int timeOutMs)
  194201. {
  194202. JUCE_HTTPSocketStream* const s = new JUCE_HTTPSocketStream();
  194203. if (s->open (url, headers, postData, isPost,
  194204. callback, callbackContext, timeOutMs))
  194205. return s;
  194206. delete s;
  194207. return 0;
  194208. }
  194209. void juce_closeInternetFile (void* handle)
  194210. {
  194211. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  194212. if (s != 0)
  194213. delete s;
  194214. }
  194215. int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead)
  194216. {
  194217. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  194218. if (s != 0)
  194219. return s->read (buffer, bytesToRead);
  194220. return 0;
  194221. }
  194222. int64 juce_getInternetFileContentLength (void* handle)
  194223. {
  194224. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  194225. if (s != 0)
  194226. {
  194227. //xxx todo
  194228. jassertfalse
  194229. }
  194230. return -1;
  194231. }
  194232. int juce_seekInInternetFile (void* handle, int newPosition)
  194233. {
  194234. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  194235. if (s != 0)
  194236. return s->readPosition;
  194237. return 0;
  194238. }
  194239. #endif
  194240. /*** End of inlined file: juce_linux_Network.cpp ***/
  194241. /*** Start of inlined file: juce_linux_SystemStats.cpp ***/
  194242. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194243. // compiled on its own).
  194244. #if JUCE_INCLUDED_FILE
  194245. void Logger::outputDebugString (const String& text) throw()
  194246. {
  194247. fputs (text.toUTF8(), stdout);
  194248. fputs ("\n", stdout);
  194249. }
  194250. void Logger::outputDebugPrintf (const tchar* format, ...) throw()
  194251. {
  194252. String text;
  194253. va_list args;
  194254. va_start (args, format);
  194255. text.vprintf(format, args);
  194256. outputDebugString(text);
  194257. }
  194258. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  194259. {
  194260. return Linux;
  194261. }
  194262. const String SystemStats::getOperatingSystemName() throw()
  194263. {
  194264. return T("Linux");
  194265. }
  194266. bool SystemStats::isOperatingSystem64Bit() throw()
  194267. {
  194268. #if JUCE_64BIT
  194269. return true;
  194270. #else
  194271. //xxx not sure how to find this out?..
  194272. return false;
  194273. #endif
  194274. }
  194275. static const String getCpuInfo (const char* key, bool lastOne = false) throw()
  194276. {
  194277. String info;
  194278. char buf [256];
  194279. FILE* f = fopen ("/proc/cpuinfo", "r");
  194280. while (f != 0 && fgets (buf, sizeof(buf), f))
  194281. {
  194282. if (strncmp (buf, key, strlen (key)) == 0)
  194283. {
  194284. char* p = buf;
  194285. while (*p && *p != '\n')
  194286. ++p;
  194287. if (*p != 0)
  194288. *p = 0;
  194289. p = buf;
  194290. while (*p != 0 && *p != ':')
  194291. ++p;
  194292. if (*p != 0 && *(p + 1) != 0)
  194293. info = p + 2;
  194294. if (! lastOne)
  194295. break;
  194296. }
  194297. }
  194298. fclose (f);
  194299. return info;
  194300. }
  194301. bool SystemStats::hasMMX() throw()
  194302. {
  194303. return getCpuInfo ("flags").contains (T("mmx"));
  194304. }
  194305. bool SystemStats::hasSSE() throw()
  194306. {
  194307. return getCpuInfo ("flags").contains (T("sse"));
  194308. }
  194309. bool SystemStats::hasSSE2() throw()
  194310. {
  194311. return getCpuInfo ("flags").contains (T("sse2"));
  194312. }
  194313. bool SystemStats::has3DNow() throw()
  194314. {
  194315. return getCpuInfo ("flags").contains (T("3dnow"));
  194316. }
  194317. const String SystemStats::getCpuVendor() throw()
  194318. {
  194319. return getCpuInfo ("vendor_id");
  194320. }
  194321. int SystemStats::getCpuSpeedInMegaherz() throw()
  194322. {
  194323. const String speed (getCpuInfo ("cpu MHz"));
  194324. return (int) (speed.getFloatValue() + 0.5f);
  194325. }
  194326. int SystemStats::getMemorySizeInMegabytes() throw()
  194327. {
  194328. struct sysinfo sysi;
  194329. if (sysinfo (&sysi) == 0)
  194330. return (sysi.totalram * sysi.mem_unit / (1024 * 1024));
  194331. return 0;
  194332. }
  194333. uint32 juce_millisecondsSinceStartup() throw()
  194334. {
  194335. static unsigned int calibrate = 0;
  194336. static bool calibrated = false;
  194337. timeval t;
  194338. unsigned int ret = 0;
  194339. if (! gettimeofday (&t, 0))
  194340. {
  194341. if (! calibrated)
  194342. {
  194343. struct sysinfo sysi;
  194344. if (sysinfo (&sysi) == 0)
  194345. // Safe to assume system was not brought up earlier than 1970!
  194346. calibrate = t.tv_sec - sysi.uptime;
  194347. calibrated = true;
  194348. }
  194349. ret = 1000 * (t.tv_sec - calibrate) + (t.tv_usec / 1000);
  194350. }
  194351. return ret;
  194352. }
  194353. double Time::getMillisecondCounterHiRes() throw()
  194354. {
  194355. return getHighResolutionTicks() * 0.001;
  194356. }
  194357. int64 Time::getHighResolutionTicks() throw()
  194358. {
  194359. timeval t;
  194360. if (gettimeofday (&t, 0))
  194361. return 0;
  194362. return ((int64) t.tv_sec * (int64) 1000000) + (int64) t.tv_usec;
  194363. }
  194364. int64 Time::getHighResolutionTicksPerSecond() throw()
  194365. {
  194366. // Microseconds
  194367. return 1000000;
  194368. }
  194369. bool Time::setSystemTimeToThisTime() const throw()
  194370. {
  194371. timeval t;
  194372. t.tv_sec = millisSinceEpoch % 1000000;
  194373. t.tv_usec = millisSinceEpoch - t.tv_sec;
  194374. return settimeofday (&t, NULL) ? false : true;
  194375. }
  194376. int SystemStats::getPageSize() throw()
  194377. {
  194378. static int systemPageSize = 0;
  194379. if (systemPageSize == 0)
  194380. systemPageSize = sysconf (_SC_PAGESIZE);
  194381. return systemPageSize;
  194382. }
  194383. int SystemStats::getNumCpus() throw()
  194384. {
  194385. const int lastCpu = getCpuInfo ("processor", true).getIntValue();
  194386. return lastCpu + 1;
  194387. }
  194388. const String SystemStats::getLogonName()
  194389. {
  194390. const char* user = getenv ("USER");
  194391. if (user == 0)
  194392. {
  194393. struct passwd* const pw = getpwuid (getuid());
  194394. if (pw != 0)
  194395. user = pw->pw_name;
  194396. }
  194397. return String::fromUTF8 ((const uint8*) user);
  194398. }
  194399. const String SystemStats::getFullUserName()
  194400. {
  194401. return getLogonName();
  194402. }
  194403. void SystemStats::initialiseStats() throw()
  194404. {
  194405. // Process starts off as root when running suid
  194406. Process::lowerPrivilege();
  194407. String s (SystemStats::getJUCEVersion());
  194408. }
  194409. void PlatformUtilities::fpuReset()
  194410. {
  194411. }
  194412. #endif
  194413. /*** End of inlined file: juce_linux_SystemStats.cpp ***/
  194414. /*** Start of inlined file: juce_linux_Threads.cpp ***/
  194415. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194416. // compiled on its own).
  194417. #if JUCE_INCLUDED_FILE
  194418. void JUCE_API juce_threadEntryPoint (void*);
  194419. void* threadEntryProc (void* value)
  194420. {
  194421. // New threads start off as root when running suid
  194422. Process::lowerPrivilege();
  194423. juce_threadEntryPoint (value);
  194424. return 0;
  194425. }
  194426. void* juce_createThread (void* userData)
  194427. {
  194428. pthread_t handle = 0;
  194429. if (pthread_create (&handle, 0, threadEntryProc, userData) == 0)
  194430. {
  194431. pthread_detach (handle);
  194432. return (void*)handle;
  194433. }
  194434. return 0;
  194435. }
  194436. void juce_killThread (void* handle)
  194437. {
  194438. if (handle != 0)
  194439. pthread_cancel ((pthread_t)handle);
  194440. }
  194441. void juce_setCurrentThreadName (const String& /*name*/)
  194442. {
  194443. }
  194444. Thread::ThreadID Thread::getCurrentThreadId()
  194445. {
  194446. return (ThreadID) pthread_self();
  194447. }
  194448. // priority 1 to 10 where 5=normal, 1=low. If the handle is 0, sets the
  194449. // priority of the current thread
  194450. bool juce_setThreadPriority (void* handle, int priority)
  194451. {
  194452. struct sched_param param;
  194453. int policy, maxp, minp, pri;
  194454. if (handle == 0)
  194455. handle = (void*) pthread_self();
  194456. if (pthread_getschedparam ((pthread_t) handle, &policy, &param) == 0
  194457. && policy != SCHED_OTHER)
  194458. {
  194459. minp = sched_get_priority_min(policy);
  194460. maxp = sched_get_priority_max(policy);
  194461. pri = ((maxp - minp) / 2) * (priority - 1) / 9;
  194462. if (param.__sched_priority >= (minp + (maxp - minp) / 2))
  194463. // Realtime process priority
  194464. param.__sched_priority = minp + ((maxp - minp) / 2) + pri;
  194465. else
  194466. // High process priority
  194467. param.__sched_priority = minp + pri;
  194468. param.sched_priority = jlimit (1, 127, 1 + (priority * 126) / 11);
  194469. return pthread_setschedparam ((pthread_t) handle, policy, &param) == 0;
  194470. }
  194471. return false;
  194472. }
  194473. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
  194474. {
  194475. #if SUPPORT_AFFINITIES
  194476. cpu_set_t affinity;
  194477. CPU_ZERO (&affinity);
  194478. for (int i = 0; i < 32; ++i)
  194479. if ((affinityMask & (1 << i)) != 0)
  194480. CPU_SET (i, &affinity);
  194481. sched_setaffinity (getpid(), sizeof (cpu_set_t), &affinity);
  194482. sched_yield();
  194483. #else
  194484. /* affinities aren't supported because either the appropriate header files weren't found,
  194485. or the SUPPORT_AFFINITIES macro was turned off in linuxheaders.h
  194486. */
  194487. jassertfalse
  194488. #endif
  194489. }
  194490. void Thread::yield()
  194491. {
  194492. sched_yield();
  194493. }
  194494. // sets the process to 0=low priority, 1=normal, 2=high, 3=realtime
  194495. void Process::setPriority (ProcessPriority prior)
  194496. {
  194497. struct sched_param param;
  194498. int policy, maxp, minp;
  194499. const int p = (int) prior;
  194500. if (p <= 1)
  194501. policy = SCHED_OTHER;
  194502. else
  194503. policy = SCHED_RR;
  194504. minp = sched_get_priority_min (policy);
  194505. maxp = sched_get_priority_max (policy);
  194506. if (p < 2)
  194507. param.__sched_priority = 0;
  194508. else if (p == 2 )
  194509. // Set to middle of lower realtime priority range
  194510. param.__sched_priority = minp + (maxp - minp) / 4;
  194511. else
  194512. // Set to middle of higher realtime priority range
  194513. param.__sched_priority = minp + (3 * (maxp - minp) / 4);
  194514. pthread_setschedparam (pthread_self(), policy, &param);
  194515. }
  194516. void Process::terminate()
  194517. {
  194518. exit (0);
  194519. }
  194520. bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger()
  194521. {
  194522. static char testResult = 0;
  194523. if (testResult == 0)
  194524. {
  194525. testResult = (char) ptrace (PT_TRACE_ME, 0, 0, 0);
  194526. if (testResult >= 0)
  194527. {
  194528. ptrace (PT_DETACH, 0, (caddr_t) 1, 0);
  194529. testResult = 1;
  194530. }
  194531. }
  194532. return testResult < 0;
  194533. }
  194534. bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
  194535. {
  194536. return juce_isRunningUnderDebugger();
  194537. }
  194538. void Process::raisePrivilege()
  194539. {
  194540. // If running suid root, change effective user
  194541. // to root
  194542. if (geteuid() != 0 && getuid() == 0)
  194543. {
  194544. setreuid (geteuid(), getuid());
  194545. setregid (getegid(), getgid());
  194546. }
  194547. }
  194548. void Process::lowerPrivilege()
  194549. {
  194550. // If runing suid root, change effective user
  194551. // back to real user
  194552. if (geteuid() == 0 && getuid() != 0)
  194553. {
  194554. setreuid (geteuid(), getuid());
  194555. setregid (getegid(), getgid());
  194556. }
  194557. }
  194558. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  194559. void* PlatformUtilities::loadDynamicLibrary (const String& name)
  194560. {
  194561. return dlopen ((const char*) name.toUTF8(), RTLD_LOCAL | RTLD_NOW);
  194562. }
  194563. void PlatformUtilities::freeDynamicLibrary (void* handle)
  194564. {
  194565. dlclose(handle);
  194566. }
  194567. void* PlatformUtilities::getProcedureEntryPoint (void* libraryHandle, const String& procedureName)
  194568. {
  194569. return dlsym (libraryHandle, (const char*) procedureName);
  194570. }
  194571. #endif
  194572. #endif
  194573. /*** End of inlined file: juce_linux_Threads.cpp ***/
  194574. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  194575. /*** Start of inlined file: juce_linux_Clipboard.cpp ***/
  194576. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194577. // compiled on its own).
  194578. #if JUCE_INCLUDED_FILE
  194579. #ifdef JUCE_DEBUG
  194580. #define JUCE_DEBUG_XERRORS 1
  194581. #endif
  194582. extern Display* display;
  194583. extern Window juce_messageWindowHandle;
  194584. static String localClipboardContent;
  194585. static Atom atom_UTF8_STRING;
  194586. static Atom atom_CLIPBOARD;
  194587. static Atom atom_TARGETS;
  194588. static void initSelectionAtoms()
  194589. {
  194590. static bool isInitialised = false;
  194591. if (! isInitialised)
  194592. {
  194593. atom_UTF8_STRING = XInternAtom (display, "UTF8_STRING", False);
  194594. atom_CLIPBOARD = XInternAtom (display, "CLIPBOARD", False);
  194595. atom_TARGETS = XInternAtom (display, "TARGETS", False);
  194596. }
  194597. }
  194598. // Read the content of a window property as either a locale-dependent string or an utf8 string
  194599. // works only for strings shorter than 1000000 bytes
  194600. static String juce_readWindowProperty (Window window, Atom prop,
  194601. Atom fmt, // XA_STRING or UTF8_STRING
  194602. bool deleteAfterReading)
  194603. {
  194604. String returnData;
  194605. uint8 *clipData;
  194606. Atom actualType;
  194607. int actualFormat;
  194608. unsigned long numItems, bytesLeft;
  194609. if (XGetWindowProperty (display, window, prop,
  194610. 0L /* offset */, 1000000 /* length (max) */, False,
  194611. AnyPropertyType /* format */,
  194612. &actualType, &actualFormat, &numItems, &bytesLeft,
  194613. &clipData) == Success)
  194614. {
  194615. if (actualType == atom_UTF8_STRING && actualFormat == 8)
  194616. {
  194617. returnData = String::fromUTF8 (clipData, numItems);
  194618. }
  194619. else if (actualType == XA_STRING && actualFormat == 8)
  194620. {
  194621. returnData = String ((const char*) clipData, numItems);
  194622. }
  194623. if (clipData != 0)
  194624. XFree (clipData);
  194625. jassert (bytesLeft == 0 || numItems == 1000000);
  194626. }
  194627. if (deleteAfterReading)
  194628. XDeleteProperty (display, window, prop);
  194629. return returnData;
  194630. }
  194631. // Send a SelectionRequest to the window owning the selection and waits for its answer (with a timeout) */
  194632. static bool juce_requestSelectionContent (String &selection_content, Atom selection, Atom requested_format)
  194633. {
  194634. Atom property_name = XInternAtom (display, "JUCE_SEL", false);
  194635. // The selection owner will be asked to set the JUCE_SEL property on the
  194636. // juce_messageWindowHandle with the selection content
  194637. XConvertSelection (display, selection, requested_format, property_name,
  194638. juce_messageWindowHandle, CurrentTime);
  194639. int timeoutMs = 200; // will wait at most for 200 ms
  194640. do
  194641. {
  194642. XEvent event;
  194643. if (XCheckTypedWindowEvent (display, juce_messageWindowHandle, SelectionNotify, &event))
  194644. {
  194645. if (event.xselection.property == property_name)
  194646. {
  194647. jassert (event.xselection.requestor == juce_messageWindowHandle);
  194648. selection_content = juce_readWindowProperty (event.xselection.requestor,
  194649. event.xselection.property,
  194650. requested_format, true);
  194651. return true;
  194652. }
  194653. else
  194654. {
  194655. return false; // the format we asked for was denied.. (event.xselection.property == None)
  194656. }
  194657. }
  194658. // not very elegant.. we could do a select() or something like that...
  194659. // however clipboard content requesting is inherently slow on x11, it
  194660. // often takes 50ms or more so...
  194661. Thread::sleep (4);
  194662. timeoutMs -= 4;
  194663. }
  194664. while (timeoutMs > 0);
  194665. DBG("timeout for juce_requestSelectionContent");
  194666. return false;
  194667. }
  194668. // Called from the event loop in juce_linux_Messaging in response to SelectionRequest events
  194669. void juce_handleSelectionRequest (XSelectionRequestEvent &evt)
  194670. {
  194671. initSelectionAtoms();
  194672. // the selection content is sent to the target window as a window property
  194673. XSelectionEvent reply;
  194674. reply.type = SelectionNotify;
  194675. reply.display = evt.display;
  194676. reply.requestor = evt.requestor;
  194677. reply.selection = evt.selection;
  194678. reply.target = evt.target;
  194679. reply.property = None; // == "fail"
  194680. reply.time = evt.time;
  194681. HeapBlock <char> data;
  194682. int propertyFormat = 0, numDataItems = 0;
  194683. if (evt.selection == XA_PRIMARY || evt.selection == atom_CLIPBOARD)
  194684. {
  194685. if (evt.target == XA_STRING)
  194686. {
  194687. // format data according to system locale
  194688. numDataItems = localClipboardContent.length();
  194689. data.calloc (numDataItems + 2);
  194690. localClipboardContent.copyToBuffer ((char*) data, numDataItems + 1);
  194691. propertyFormat = 8; // bits/item
  194692. }
  194693. else if (evt.target == atom_UTF8_STRING)
  194694. {
  194695. // translate to utf8
  194696. numDataItems = localClipboardContent.copyToUTF8 (0);
  194697. data.calloc (numDataItems + 2);
  194698. localClipboardContent.copyToUTF8 (data, numDataItems + 1);
  194699. propertyFormat = 8; // bits/item
  194700. }
  194701. else if (evt.target == atom_TARGETS)
  194702. {
  194703. // another application wants to know what we are able to send
  194704. numDataItems = 2;
  194705. propertyFormat = 32; // atoms are 32-bit
  194706. data.calloc (numDataItems * 4);
  194707. ((Atom*) data)[0] = atom_UTF8_STRING;
  194708. ((Atom*) data)[1] = XA_STRING;
  194709. }
  194710. }
  194711. else
  194712. {
  194713. DBG ("requested unsupported clipboard");
  194714. }
  194715. if (data != 0)
  194716. {
  194717. const int maxReasonableSelectionSize = 1000000;
  194718. // for very big chunks of data, we should use the "INCR" protocol , which is a pain in the *ss
  194719. if (evt.property != None && numDataItems < maxReasonableSelectionSize)
  194720. {
  194721. XChangeProperty (evt.display, evt.requestor,
  194722. evt.property, evt.target,
  194723. propertyFormat /* 8 or 32 */, PropModeReplace,
  194724. (const unsigned char*) data, numDataItems);
  194725. reply.property = evt.property; // " == success"
  194726. }
  194727. }
  194728. XSendEvent (evt.display, evt.requestor, 0, NoEventMask, (XEvent*) &reply);
  194729. }
  194730. void SystemClipboard::copyTextToClipboard (const String& clipText) throw()
  194731. {
  194732. initSelectionAtoms();
  194733. localClipboardContent = clipText;
  194734. XSetSelectionOwner (display, XA_PRIMARY, juce_messageWindowHandle, CurrentTime);
  194735. XSetSelectionOwner (display, atom_CLIPBOARD, juce_messageWindowHandle, CurrentTime);
  194736. }
  194737. const String SystemClipboard::getTextFromClipboard() throw()
  194738. {
  194739. initSelectionAtoms();
  194740. String content;
  194741. Atom selection = XA_PRIMARY;
  194742. Window selectionOwner = None;
  194743. if ((selectionOwner = XGetSelectionOwner (display, selection)) == None)
  194744. {
  194745. selection = atom_CLIPBOARD;
  194746. selectionOwner = XGetSelectionOwner (display, selection);
  194747. }
  194748. if (selectionOwner != None)
  194749. {
  194750. if (selectionOwner == juce_messageWindowHandle)
  194751. {
  194752. content = localClipboardContent;
  194753. }
  194754. else
  194755. {
  194756. // first try: we want an utf8 string
  194757. bool ok = juce_requestSelectionContent (content, selection, atom_UTF8_STRING);
  194758. if (! ok)
  194759. {
  194760. // second chance, ask for a good old locale-dependent string ..
  194761. ok = juce_requestSelectionContent (content, selection, XA_STRING);
  194762. }
  194763. }
  194764. }
  194765. return content;
  194766. }
  194767. #endif
  194768. /*** End of inlined file: juce_linux_Clipboard.cpp ***/
  194769. /*** Start of inlined file: juce_linux_Messaging.cpp ***/
  194770. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194771. // compiled on its own).
  194772. #if JUCE_INCLUDED_FILE
  194773. #ifdef JUCE_DEBUG
  194774. #define JUCE_DEBUG_XERRORS 1
  194775. #endif
  194776. Display* display = 0; // This is also referenced from WindowDriver.cpp
  194777. Window juce_messageWindowHandle = None;
  194778. #define SpecialAtom "JUCESpecialAtom"
  194779. #define BroadcastAtom "JUCEBroadcastAtom"
  194780. #define SpecialCallbackAtom "JUCESpecialCallbackAtom"
  194781. static Atom specialId;
  194782. static Atom broadcastId;
  194783. static Atom specialCallbackId;
  194784. // This is referenced from Windowing.cpp
  194785. XContext improbableNumber;
  194786. // Defined in Windowing.cpp
  194787. extern void juce_windowMessageReceive (XEvent* event);
  194788. // Defined in Clipboard.cpp
  194789. extern void juce_handleSelectionRequest (XSelectionRequestEvent &evt);
  194790. ScopedXLock::ScopedXLock() { XLockDisplay (display); }
  194791. ScopedXLock::~ScopedXLock() { XUnlockDisplay (display); }
  194792. class InternalMessageQueue
  194793. {
  194794. public:
  194795. InternalMessageQueue()
  194796. : bytesInSocket (0)
  194797. {
  194798. int ret = ::socketpair (AF_LOCAL, SOCK_STREAM, 0, fd);
  194799. (void) ret; jassert (ret == 0);
  194800. setNonBlocking (fd[0]);
  194801. setNonBlocking (fd[1]);
  194802. }
  194803. ~InternalMessageQueue()
  194804. {
  194805. close (fd[0]);
  194806. close (fd[1]);
  194807. }
  194808. void postMessage (Message* msg)
  194809. {
  194810. const int maxBytesInSocketQueue = 128;
  194811. ScopedLock sl (lock);
  194812. queue.add (msg);
  194813. if (bytesInSocket < maxBytesInSocketQueue)
  194814. {
  194815. ++bytesInSocket;
  194816. ScopedUnlock ul (lock);
  194817. const unsigned char x = 0xff;
  194818. size_t bytesWritten = write (fd[0], &x, 1);
  194819. (void) bytesWritten;
  194820. }
  194821. }
  194822. bool isEmpty() const
  194823. {
  194824. ScopedLock sl (lock);
  194825. return queue.size() == 0;
  194826. }
  194827. Message* popNextMessage()
  194828. {
  194829. ScopedLock sl (lock);
  194830. if (bytesInSocket > 0)
  194831. {
  194832. --bytesInSocket;
  194833. ScopedUnlock ul (lock);
  194834. unsigned char x;
  194835. size_t numBytes = read (fd[1], &x, 1);
  194836. (void) numBytes;
  194837. }
  194838. Message* m = queue[0];
  194839. queue.remove (0, false /* deleteObject */);
  194840. return m;
  194841. }
  194842. int getWaitHandle() const { return fd[1]; }
  194843. private:
  194844. CriticalSection lock;
  194845. OwnedArray <Message> queue;
  194846. int fd[2];
  194847. int bytesInSocket;
  194848. static bool setNonBlocking (int handle)
  194849. {
  194850. int socketFlags = fcntl (handle, F_GETFL, 0);
  194851. if (socketFlags == -1)
  194852. return false;
  194853. socketFlags |= O_NONBLOCK;
  194854. return fcntl (handle, F_SETFL, socketFlags) == 0;
  194855. }
  194856. };
  194857. struct MessageThreadFuncCall
  194858. {
  194859. enum { uniqueID = 0x73774623 };
  194860. MessageCallbackFunction* func;
  194861. void* parameter;
  194862. void* result;
  194863. CriticalSection lock;
  194864. WaitableEvent event;
  194865. };
  194866. static InternalMessageQueue* juce_internalMessageQueue = 0;
  194867. // error handling in X11
  194868. static bool errorOccurred = false;
  194869. static bool keyboardBreakOccurred = false;
  194870. static XErrorHandler oldErrorHandler = (XErrorHandler) 0;
  194871. static XIOErrorHandler oldIOErrorHandler = (XIOErrorHandler) 0;
  194872. // Usually happens when client-server connection is broken
  194873. static int ioErrorHandler (Display* display)
  194874. {
  194875. DBG (T("ERROR: connection to X server broken.. terminating."));
  194876. errorOccurred = true;
  194877. if (JUCEApplication::getInstance() != 0)
  194878. Process::terminate();
  194879. return 0;
  194880. }
  194881. // A protocol error has occurred
  194882. static int errorHandler (Display* display, XErrorEvent* event)
  194883. {
  194884. #ifdef JUCE_DEBUG_XERRORS
  194885. char errorStr[64] = { 0 };
  194886. char requestStr[64] = { 0 };
  194887. XGetErrorText (display, event->error_code, errorStr, 64);
  194888. XGetErrorDatabaseText (display,
  194889. "XRequest",
  194890. (const char*) String (event->request_code),
  194891. "Unknown",
  194892. requestStr,
  194893. 64);
  194894. DBG (T("ERROR: X returned ") + String (errorStr) + T(" for operation ") + String (requestStr));
  194895. #endif
  194896. return 0;
  194897. }
  194898. // Breakin from keyboard
  194899. static void signalHandler (int sig)
  194900. {
  194901. if (sig == SIGINT)
  194902. {
  194903. keyboardBreakOccurred = true;
  194904. return;
  194905. }
  194906. static bool reentrant = false;
  194907. if (! reentrant)
  194908. {
  194909. reentrant = true;
  194910. // Illegal instruction
  194911. fflush (stdout);
  194912. Logger::outputDebugString ("ERROR: Program executed illegal instruction.. terminating");
  194913. errorOccurred = true;
  194914. if (JUCEApplication::getInstance() != 0)
  194915. Process::terminate();
  194916. }
  194917. else
  194918. {
  194919. if (JUCEApplication::getInstance() != 0)
  194920. exit(0);
  194921. }
  194922. }
  194923. void MessageManager::doPlatformSpecificInitialisation()
  194924. {
  194925. // Initialise xlib for multiple thread support
  194926. static bool initThreadCalled = false;
  194927. if (! initThreadCalled)
  194928. {
  194929. if (! XInitThreads())
  194930. {
  194931. // This is fatal! Print error and closedown
  194932. Logger::outputDebugString ("Failed to initialise xlib thread support.");
  194933. if (JUCEApplication::getInstance() != 0)
  194934. Process::terminate();
  194935. return;
  194936. }
  194937. initThreadCalled = true;
  194938. }
  194939. // This is called if the client/server connection is broken
  194940. oldIOErrorHandler = XSetIOErrorHandler (ioErrorHandler);
  194941. // This is called if a protocol error occurs
  194942. oldErrorHandler = XSetErrorHandler (errorHandler);
  194943. // Install signal handler for break-in
  194944. struct sigaction saction;
  194945. sigset_t maskSet;
  194946. sigemptyset (&maskSet);
  194947. saction.sa_handler = signalHandler;
  194948. saction.sa_mask = maskSet;
  194949. saction.sa_flags = 0;
  194950. sigaction (SIGINT, &saction, NULL);
  194951. #ifndef _DEBUG
  194952. // Setup signal handlers for various fatal errors
  194953. sigaction (SIGILL, &saction, NULL);
  194954. sigaction (SIGBUS, &saction, NULL);
  194955. sigaction (SIGFPE, &saction, NULL);
  194956. sigaction (SIGSEGV, &saction, NULL);
  194957. sigaction (SIGSYS, &saction, NULL);
  194958. #endif
  194959. // Create the internal message queue
  194960. juce_internalMessageQueue = new InternalMessageQueue();
  194961. // Try to connect to a display
  194962. String displayName (getenv ("DISPLAY"));
  194963. if (displayName.isEmpty())
  194964. displayName = T(":0.0");
  194965. display = XOpenDisplay (displayName);
  194966. if (display == 0)
  194967. {
  194968. // This is not fatal! we can run headless.
  194969. return;
  194970. }
  194971. // Get defaults for various properties
  194972. int screen = DefaultScreen (display);
  194973. Window root = RootWindow (display, screen);
  194974. Visual* visual = DefaultVisual (display, screen);
  194975. // Create atoms for our ClientMessages (these cannot be deleted)
  194976. specialId = XInternAtom (display, SpecialAtom, false);
  194977. broadcastId = XInternAtom (display, BroadcastAtom, false);
  194978. specialCallbackId = XInternAtom (display, SpecialCallbackAtom, false);
  194979. // Create a context to store user data associated with Windows we
  194980. // create in WindowDriver
  194981. improbableNumber = XUniqueContext();
  194982. // We're only interested in client messages for this window
  194983. // which are always sent
  194984. XSetWindowAttributes swa;
  194985. swa.event_mask = NoEventMask;
  194986. // Create our message window (this will never be mapped)
  194987. juce_messageWindowHandle = XCreateWindow (display, root,
  194988. 0, 0, 1, 1, 0, 0, InputOnly,
  194989. visual, CWEventMask, &swa);
  194990. }
  194991. void MessageManager::doPlatformSpecificShutdown()
  194992. {
  194993. deleteAndZero (juce_internalMessageQueue);
  194994. if (display != 0 && ! errorOccurred)
  194995. {
  194996. XDestroyWindow (display, juce_messageWindowHandle);
  194997. XCloseDisplay (display);
  194998. // reset pointers
  194999. juce_messageWindowHandle = 0;
  195000. display = 0;
  195001. // Restore original error handlers
  195002. XSetIOErrorHandler (oldIOErrorHandler);
  195003. oldIOErrorHandler = 0;
  195004. XSetErrorHandler (oldErrorHandler);
  195005. oldErrorHandler = 0;
  195006. }
  195007. }
  195008. bool juce_postMessageToSystemQueue (void* message)
  195009. {
  195010. if (errorOccurred)
  195011. return false;
  195012. juce_internalMessageQueue->postMessage ((Message*) message);
  195013. return true;
  195014. }
  195015. void MessageManager::broadcastMessage (const String& value) throw()
  195016. {
  195017. }
  195018. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* func,
  195019. void* parameter)
  195020. {
  195021. if (errorOccurred)
  195022. return 0;
  195023. if (! isThisTheMessageThread())
  195024. {
  195025. MessageThreadFuncCall messageCallContext;
  195026. messageCallContext.func = func;
  195027. messageCallContext.parameter = parameter;
  195028. juce_internalMessageQueue->postMessage (new Message (MessageThreadFuncCall::uniqueID,
  195029. 0, 0, &messageCallContext));
  195030. // Wait for it to complete before continuing
  195031. messageCallContext.event.wait();
  195032. return messageCallContext.result;
  195033. }
  195034. else
  195035. {
  195036. // Just call the function directly
  195037. return func (parameter);
  195038. }
  195039. }
  195040. // Wait for an event (either XEvent, or an internal Message)
  195041. static bool juce_sleepUntilEvent (const int timeoutMs)
  195042. {
  195043. if (! juce_internalMessageQueue->isEmpty())
  195044. return true;
  195045. if (display != 0)
  195046. {
  195047. ScopedXLock xlock;
  195048. if (XPending (display))
  195049. return true;
  195050. }
  195051. struct timeval tv;
  195052. tv.tv_sec = 0;
  195053. tv.tv_usec = timeoutMs * 1000;
  195054. int fd0 = juce_internalMessageQueue->getWaitHandle();
  195055. int fdmax = fd0;
  195056. fd_set readset;
  195057. FD_ZERO (&readset);
  195058. FD_SET (fd0, &readset);
  195059. if (display != 0)
  195060. {
  195061. ScopedXLock xlock;
  195062. int fd1 = XConnectionNumber (display);
  195063. FD_SET (fd1, &readset);
  195064. fdmax = jmax (fd0, fd1);
  195065. }
  195066. const int ret = select (fdmax + 1, &readset, 0, 0, &tv);
  195067. return (ret > 0); // ret <= 0 if error or timeout
  195068. }
  195069. // Handle next XEvent (if any)
  195070. static bool juce_dispatchNextXEvent()
  195071. {
  195072. if (display == 0)
  195073. return false;
  195074. XEvent evt;
  195075. {
  195076. ScopedXLock xlock;
  195077. if (! XPending (display))
  195078. return false;
  195079. XNextEvent (display, &evt);
  195080. }
  195081. if (evt.type == SelectionRequest && evt.xany.window == juce_messageWindowHandle)
  195082. {
  195083. juce_handleSelectionRequest (evt.xselectionrequest);
  195084. }
  195085. else if (evt.xany.window != juce_messageWindowHandle)
  195086. {
  195087. juce_windowMessageReceive (&evt);
  195088. }
  195089. return true;
  195090. }
  195091. // Handle next internal Message (if any)
  195092. static bool juce_dispatchNextInternalMessage()
  195093. {
  195094. ScopedPointer <Message> msg (juce_internalMessageQueue->popNextMessage());
  195095. if (msg == 0)
  195096. return false;
  195097. if (msg->intParameter1 == MessageThreadFuncCall::uniqueID)
  195098. {
  195099. // Handle callback message
  195100. MessageThreadFuncCall* const call = (MessageThreadFuncCall*) msg->pointerParameter;
  195101. call->result = (*(call->func)) (call->parameter);
  195102. call->event.signal();
  195103. }
  195104. else
  195105. {
  195106. // Handle "normal" messages
  195107. MessageManager::getInstance()->deliverMessage (msg.release());
  195108. }
  195109. return true;
  195110. }
  195111. // this function expects that it will NEVER be called simultaneously for two concurrent threads
  195112. bool juce_dispatchNextMessageOnSystemQueue (bool returnIfNoPendingMessages)
  195113. {
  195114. for (;;)
  195115. {
  195116. if (errorOccurred)
  195117. break;
  195118. if (keyboardBreakOccurred)
  195119. {
  195120. errorOccurred = true;
  195121. if (JUCEApplication::getInstance() != 0)
  195122. Process::terminate();
  195123. break;
  195124. }
  195125. static int totalEventCount = 0;
  195126. ++totalEventCount;
  195127. // The purpose here is to give either priority to XEvents or
  195128. // to internal messages This is necessary to keep a "good"
  195129. // behaviour when the cpu is overloaded
  195130. if (totalEventCount & 1)
  195131. {
  195132. if (juce_dispatchNextXEvent() || juce_dispatchNextInternalMessage())
  195133. return true;
  195134. }
  195135. else
  195136. {
  195137. if (juce_dispatchNextInternalMessage() || juce_dispatchNextXEvent())
  195138. return true;
  195139. }
  195140. if (returnIfNoPendingMessages) // early exit
  195141. break;
  195142. // the timeout is to be on the safe side, but it does not seem to be useful
  195143. juce_sleepUntilEvent (2000);
  195144. }
  195145. return false;
  195146. }
  195147. #endif
  195148. /*** End of inlined file: juce_linux_Messaging.cpp ***/
  195149. /*** Start of inlined file: juce_linux_Fonts.cpp ***/
  195150. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  195151. // compiled on its own).
  195152. #if JUCE_INCLUDED_FILE
  195153. class FreeTypeFontFace
  195154. {
  195155. public:
  195156. enum FontStyle
  195157. {
  195158. Plain = 0,
  195159. Bold = 1,
  195160. Italic = 2
  195161. };
  195162. struct FontNameIndex
  195163. {
  195164. String fileName;
  195165. int faceIndex;
  195166. };
  195167. FreeTypeFontFace (const String& familyName) throw()
  195168. : hasSerif (false),
  195169. monospaced (false)
  195170. {
  195171. family = familyName;
  195172. }
  195173. void setFileName (const String& name, const int faceIndex, FontStyle style) throw()
  195174. {
  195175. if (names [(int) style].fileName.isEmpty())
  195176. {
  195177. names [(int) style].fileName = name;
  195178. names [(int) style].faceIndex = faceIndex;
  195179. }
  195180. }
  195181. const String& getFamilyName() const throw() { return family; }
  195182. const String& getFileName (const int style, int& faceIndex) const throw()
  195183. {
  195184. faceIndex = names[style].faceIndex;
  195185. return names[style].fileName;
  195186. }
  195187. void setMonospaced (bool mono) throw() { monospaced = mono; }
  195188. bool getMonospaced() const throw() { return monospaced; }
  195189. void setSerif (const bool serif) throw() { hasSerif = serif; }
  195190. bool getSerif() const throw() { return hasSerif; }
  195191. private:
  195192. String family;
  195193. FontNameIndex names[4];
  195194. bool hasSerif, monospaced;
  195195. };
  195196. class FreeTypeInterface : public DeletedAtShutdown
  195197. {
  195198. public:
  195199. FreeTypeInterface() throw()
  195200. : lastFace (0),
  195201. lastBold (false),
  195202. lastItalic (false)
  195203. {
  195204. if (FT_Init_FreeType (&ftLib) != 0)
  195205. {
  195206. ftLib = 0;
  195207. DBG (T("Failed to initialize FreeType"));
  195208. }
  195209. StringArray fontDirs;
  195210. fontDirs.addTokens (String (getenv ("JUCE_FONT_PATH")), T(";,"), 0);
  195211. fontDirs.removeEmptyStrings (true);
  195212. if (fontDirs.size() == 0)
  195213. {
  195214. XmlDocument fontsConfig (File ("/etc/fonts/fonts.conf"));
  195215. XmlElement* const fontsInfo = fontsConfig.getDocumentElement();
  195216. if (fontsInfo != 0)
  195217. {
  195218. forEachXmlChildElementWithTagName (*fontsInfo, e, T("dir"))
  195219. {
  195220. fontDirs.add (e->getAllSubText().trim());
  195221. }
  195222. delete fontsInfo;
  195223. }
  195224. }
  195225. if (fontDirs.size() == 0)
  195226. fontDirs.add ("/usr/X11R6/lib/X11/fonts");
  195227. for (int i = 0; i < fontDirs.size(); ++i)
  195228. enumerateFaces (fontDirs[i]);
  195229. }
  195230. ~FreeTypeInterface() throw()
  195231. {
  195232. if (lastFace != 0)
  195233. FT_Done_Face (lastFace);
  195234. if (ftLib != 0)
  195235. FT_Done_FreeType (ftLib);
  195236. clearSingletonInstance();
  195237. }
  195238. FreeTypeFontFace* findOrCreate (const String& familyName,
  195239. const bool create = false) throw()
  195240. {
  195241. for (int i = 0; i < faces.size(); i++)
  195242. if (faces[i]->getFamilyName() == familyName)
  195243. return faces[i];
  195244. if (! create)
  195245. return NULL;
  195246. FreeTypeFontFace* newFace = new FreeTypeFontFace (familyName);
  195247. faces.add (newFace);
  195248. return newFace;
  195249. }
  195250. // Enumerate all font faces available in a given directory
  195251. void enumerateFaces (const String& path) throw()
  195252. {
  195253. File dirPath (path);
  195254. if (path.isEmpty() || ! dirPath.isDirectory())
  195255. return;
  195256. DirectoryIterator di (dirPath, true);
  195257. while (di.next())
  195258. {
  195259. File possible (di.getFile());
  195260. if (possible.hasFileExtension (T("ttf"))
  195261. || possible.hasFileExtension (T("pfb"))
  195262. || possible.hasFileExtension (T("pcf")))
  195263. {
  195264. FT_Face face;
  195265. int faceIndex = 0;
  195266. int numFaces = 0;
  195267. do
  195268. {
  195269. if (FT_New_Face (ftLib,
  195270. possible.getFullPathName(),
  195271. faceIndex,
  195272. &face) == 0)
  195273. {
  195274. if (faceIndex == 0)
  195275. numFaces = face->num_faces;
  195276. if ((face->face_flags & FT_FACE_FLAG_SCALABLE) != 0)
  195277. {
  195278. FreeTypeFontFace* const newFace = findOrCreate (face->family_name, true);
  195279. int style = (int) FreeTypeFontFace::Plain;
  195280. if ((face->style_flags & FT_STYLE_FLAG_BOLD) != 0)
  195281. style |= (int) FreeTypeFontFace::Bold;
  195282. if ((face->style_flags & FT_STYLE_FLAG_ITALIC) != 0)
  195283. style |= (int) FreeTypeFontFace::Italic;
  195284. newFace->setFileName (possible.getFullPathName(), faceIndex, (FreeTypeFontFace::FontStyle) style);
  195285. newFace->setMonospaced ((face->face_flags & FT_FACE_FLAG_FIXED_WIDTH) != 0);
  195286. // Surely there must be a better way to do this?
  195287. const String name (face->family_name);
  195288. newFace->setSerif (! (name.containsIgnoreCase (T("Sans"))
  195289. || name.containsIgnoreCase (T("Verdana"))
  195290. || name.containsIgnoreCase (T("Arial"))));
  195291. }
  195292. FT_Done_Face (face);
  195293. }
  195294. ++faceIndex;
  195295. }
  195296. while (faceIndex < numFaces);
  195297. }
  195298. }
  195299. }
  195300. // Create a FreeType face object for a given font
  195301. FT_Face createFT_Face (const String& fontName,
  195302. const bool bold,
  195303. const bool italic) throw()
  195304. {
  195305. FT_Face face = 0;
  195306. if (fontName == lastFontName && bold == lastBold && italic == lastItalic)
  195307. {
  195308. face = lastFace;
  195309. }
  195310. else
  195311. {
  195312. if (lastFace != 0)
  195313. {
  195314. FT_Done_Face (lastFace);
  195315. lastFace = 0;
  195316. }
  195317. lastFontName = fontName;
  195318. lastBold = bold;
  195319. lastItalic = italic;
  195320. FreeTypeFontFace* const ftFace = findOrCreate (fontName);
  195321. if (ftFace != 0)
  195322. {
  195323. int style = (int) FreeTypeFontFace::Plain;
  195324. if (bold)
  195325. style |= (int) FreeTypeFontFace::Bold;
  195326. if (italic)
  195327. style |= (int) FreeTypeFontFace::Italic;
  195328. int faceIndex;
  195329. String fileName (ftFace->getFileName (style, faceIndex));
  195330. if (fileName.isEmpty())
  195331. {
  195332. style ^= (int) FreeTypeFontFace::Bold;
  195333. fileName = ftFace->getFileName (style, faceIndex);
  195334. if (fileName.isEmpty())
  195335. {
  195336. style ^= (int) FreeTypeFontFace::Bold;
  195337. style ^= (int) FreeTypeFontFace::Italic;
  195338. fileName = ftFace->getFileName (style, faceIndex);
  195339. if (! fileName.length())
  195340. {
  195341. style ^= (int) FreeTypeFontFace::Bold;
  195342. fileName = ftFace->getFileName (style, faceIndex);
  195343. }
  195344. }
  195345. }
  195346. if (! FT_New_Face (ftLib, (const char*) fileName, faceIndex, &lastFace))
  195347. {
  195348. face = lastFace;
  195349. // If there isn't a unicode charmap then select the first one.
  195350. if (FT_Select_Charmap (face, ft_encoding_unicode))
  195351. FT_Set_Charmap (face, face->charmaps[0]);
  195352. }
  195353. }
  195354. }
  195355. return face;
  195356. }
  195357. bool addGlyph (FT_Face face, CustomTypeface& dest, uint32 character) throw()
  195358. {
  195359. const unsigned int glyphIndex = FT_Get_Char_Index (face, character);
  195360. const float height = (float) (face->ascender - face->descender);
  195361. const float scaleX = 1.0f / height;
  195362. const float scaleY = -1.0f / height;
  195363. Path destShape;
  195364. #define CONVERTX(val) (scaleX * (val).x)
  195365. #define CONVERTY(val) (scaleY * (val).y)
  195366. if (FT_Load_Glyph (face, glyphIndex, FT_LOAD_NO_SCALE | FT_LOAD_NO_BITMAP | FT_LOAD_IGNORE_TRANSFORM) != 0
  195367. || face->glyph->format != ft_glyph_format_outline)
  195368. {
  195369. return false;
  195370. }
  195371. const FT_Outline* const outline = &face->glyph->outline;
  195372. const short* const contours = outline->contours;
  195373. const char* const tags = outline->tags;
  195374. FT_Vector* const points = outline->points;
  195375. for (int c = 0; c < outline->n_contours; c++)
  195376. {
  195377. const int startPoint = (c == 0) ? 0 : contours [c - 1] + 1;
  195378. const int endPoint = contours[c];
  195379. for (int p = startPoint; p <= endPoint; p++)
  195380. {
  195381. const float x = CONVERTX (points[p]);
  195382. const float y = CONVERTY (points[p]);
  195383. if (p == startPoint)
  195384. {
  195385. if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_Conic)
  195386. {
  195387. float x2 = CONVERTX (points [endPoint]);
  195388. float y2 = CONVERTY (points [endPoint]);
  195389. if (FT_CURVE_TAG (tags[endPoint]) != FT_Curve_Tag_On)
  195390. {
  195391. x2 = (x + x2) * 0.5f;
  195392. y2 = (y + y2) * 0.5f;
  195393. }
  195394. destShape.startNewSubPath (x2, y2);
  195395. }
  195396. else
  195397. {
  195398. destShape.startNewSubPath (x, y);
  195399. }
  195400. }
  195401. if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_On)
  195402. {
  195403. if (p != startPoint)
  195404. destShape.lineTo (x, y);
  195405. }
  195406. else if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_Conic)
  195407. {
  195408. const int nextIndex = (p == endPoint) ? startPoint : p + 1;
  195409. float x2 = CONVERTX (points [nextIndex]);
  195410. float y2 = CONVERTY (points [nextIndex]);
  195411. if (FT_CURVE_TAG (tags [nextIndex]) == FT_Curve_Tag_Conic)
  195412. {
  195413. x2 = (x + x2) * 0.5f;
  195414. y2 = (y + y2) * 0.5f;
  195415. }
  195416. else
  195417. {
  195418. ++p;
  195419. }
  195420. destShape.quadraticTo (x, y, x2, y2);
  195421. }
  195422. else if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_Cubic)
  195423. {
  195424. if (p >= endPoint)
  195425. return false;
  195426. const int next1 = p + 1;
  195427. const int next2 = (p == (endPoint - 1)) ? startPoint : p + 2;
  195428. const float x2 = CONVERTX (points [next1]);
  195429. const float y2 = CONVERTY (points [next1]);
  195430. const float x3 = CONVERTX (points [next2]);
  195431. const float y3 = CONVERTY (points [next2]);
  195432. if (FT_CURVE_TAG (tags[next1]) != FT_Curve_Tag_Cubic
  195433. || FT_CURVE_TAG (tags[next2]) != FT_Curve_Tag_On)
  195434. return false;
  195435. destShape.cubicTo (x, y, x2, y2, x3, y3);
  195436. p += 2;
  195437. }
  195438. }
  195439. destShape.closeSubPath();
  195440. }
  195441. dest.addGlyph (character, destShape, face->glyph->metrics.horiAdvance / height);
  195442. if ((face->face_flags & FT_FACE_FLAG_KERNING) != 0)
  195443. addKerning (face, dest, character, glyphIndex);
  195444. return true;
  195445. }
  195446. void addKerning (FT_Face face, CustomTypeface& dest, const uint32 character, const uint32 glyphIndex) throw()
  195447. {
  195448. const float height = (float) (face->ascender - face->descender);
  195449. uint32 rightGlyphIndex;
  195450. uint32 rightCharCode = FT_Get_First_Char (face, &rightGlyphIndex);
  195451. while (rightGlyphIndex != 0)
  195452. {
  195453. FT_Vector kerning;
  195454. if (FT_Get_Kerning (face, glyphIndex, rightGlyphIndex, ft_kerning_unscaled, &kerning) == 0)
  195455. {
  195456. if (kerning.x != 0)
  195457. dest.addKerningPair (character, rightCharCode, kerning.x / height);
  195458. }
  195459. rightCharCode = FT_Get_Next_Char (face, rightCharCode, &rightGlyphIndex);
  195460. }
  195461. }
  195462. // Add a glyph to a font
  195463. bool addGlyphToFont (const uint32 character,
  195464. const tchar* fontName, bool bold, bool italic,
  195465. CustomTypeface& dest) throw()
  195466. {
  195467. FT_Face face = createFT_Face (fontName, bold, italic);
  195468. if (face != 0)
  195469. return addGlyph (face, dest, character);
  195470. return false;
  195471. }
  195472. void getFamilyNames (StringArray& familyNames) const throw()
  195473. {
  195474. for (int i = 0; i < faces.size(); i++)
  195475. familyNames.add (faces[i]->getFamilyName());
  195476. }
  195477. void getMonospacedNames (StringArray& monoSpaced) const throw()
  195478. {
  195479. for (int i = 0; i < faces.size(); i++)
  195480. if (faces[i]->getMonospaced())
  195481. monoSpaced.add (faces[i]->getFamilyName());
  195482. }
  195483. void getSerifNames (StringArray& serif) const throw()
  195484. {
  195485. for (int i = 0; i < faces.size(); i++)
  195486. if (faces[i]->getSerif())
  195487. serif.add (faces[i]->getFamilyName());
  195488. }
  195489. void getSansSerifNames (StringArray& sansSerif) const throw()
  195490. {
  195491. for (int i = 0; i < faces.size(); i++)
  195492. if (! faces[i]->getSerif())
  195493. sansSerif.add (faces[i]->getFamilyName());
  195494. }
  195495. juce_DeclareSingleton_SingleThreaded_Minimal (FreeTypeInterface)
  195496. private:
  195497. FT_Library ftLib;
  195498. FT_Face lastFace;
  195499. String lastFontName;
  195500. bool lastBold, lastItalic;
  195501. OwnedArray<FreeTypeFontFace> faces;
  195502. };
  195503. juce_ImplementSingleton_SingleThreaded (FreeTypeInterface)
  195504. class FreetypeTypeface : public CustomTypeface
  195505. {
  195506. public:
  195507. FreetypeTypeface (const Font& font)
  195508. {
  195509. FT_Face face = FreeTypeInterface::getInstance()
  195510. ->createFT_Face (font.getTypefaceName(), font.isBold(), font.isItalic());
  195511. if (face == 0)
  195512. {
  195513. #ifdef JUCE_DEBUG
  195514. String msg (T("Failed to create typeface: "));
  195515. msg << font.getTypefaceName() << " " << (font.isBold() ? 'B' : ' ') << (font.isItalic() ? 'I' : ' ');
  195516. DBG (msg);
  195517. #endif
  195518. }
  195519. else
  195520. {
  195521. setCharacteristics (font.getTypefaceName(),
  195522. face->ascender / (float) (face->ascender - face->descender),
  195523. font.isBold(), font.isItalic(),
  195524. L' ');
  195525. }
  195526. }
  195527. bool loadGlyphIfPossible (const juce_wchar character)
  195528. {
  195529. return FreeTypeInterface::getInstance()
  195530. ->addGlyphToFont (character, name, isBold, isItalic, *this);
  195531. }
  195532. };
  195533. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  195534. {
  195535. return new FreetypeTypeface (font);
  195536. }
  195537. const StringArray Font::findAllTypefaceNames() throw()
  195538. {
  195539. StringArray s;
  195540. FreeTypeInterface::getInstance()->getFamilyNames (s);
  195541. s.sort (true);
  195542. return s;
  195543. }
  195544. static const String pickBestFont (const StringArray& names,
  195545. const char* const choicesString)
  195546. {
  195547. StringArray choices;
  195548. choices.addTokens (String (choicesString), T(","), 0);
  195549. choices.trim();
  195550. choices.removeEmptyStrings();
  195551. int i, j;
  195552. for (j = 0; j < choices.size(); ++j)
  195553. if (names.contains (choices[j], true))
  195554. return choices[j];
  195555. for (j = 0; j < choices.size(); ++j)
  195556. for (i = 0; i < names.size(); i++)
  195557. if (names[i].startsWithIgnoreCase (choices[j]))
  195558. return names[i];
  195559. for (j = 0; j < choices.size(); ++j)
  195560. for (i = 0; i < names.size(); i++)
  195561. if (names[i].containsIgnoreCase (choices[j]))
  195562. return names[i];
  195563. return names[0];
  195564. }
  195565. static const String linux_getDefaultSansSerifFontName()
  195566. {
  195567. StringArray allFonts;
  195568. FreeTypeInterface::getInstance()->getSansSerifNames (allFonts);
  195569. return pickBestFont (allFonts, "Verdana, Bitstream Vera Sans, Luxi Sans, Sans");
  195570. }
  195571. static const String linux_getDefaultSerifFontName()
  195572. {
  195573. StringArray allFonts;
  195574. FreeTypeInterface::getInstance()->getSerifNames (allFonts);
  195575. return pickBestFont (allFonts, "Bitstream Vera Serif, Times, Nimbus Roman, Serif");
  195576. }
  195577. static const String linux_getDefaultMonospacedFontName()
  195578. {
  195579. StringArray allFonts;
  195580. FreeTypeInterface::getInstance()->getMonospacedNames (allFonts);
  195581. return pickBestFont (allFonts, "Bitstream Vera Sans Mono, Courier, Sans Mono, Mono");
  195582. }
  195583. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw()
  195584. {
  195585. defaultSans = linux_getDefaultSansSerifFontName();
  195586. defaultSerif = linux_getDefaultSerifFontName();
  195587. defaultFixed = linux_getDefaultMonospacedFontName();
  195588. }
  195589. #endif
  195590. /*** End of inlined file: juce_linux_Fonts.cpp ***/
  195591. /*** Start of inlined file: juce_linux_Windowing.cpp ***/
  195592. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  195593. // compiled on its own).
  195594. #if JUCE_INCLUDED_FILE
  195595. #define TAKE_FOCUS 0
  195596. #define DELETE_WINDOW 1
  195597. #define SYSTEM_TRAY_REQUEST_DOCK 0
  195598. #define SYSTEM_TRAY_BEGIN_MESSAGE 1
  195599. #define SYSTEM_TRAY_CANCEL_MESSAGE 2
  195600. static const int repaintTimerPeriod = 1000 / 100; // 100 fps maximum
  195601. static Atom wm_ChangeState = None;
  195602. static Atom wm_State = None;
  195603. static Atom wm_Protocols = None;
  195604. static Atom wm_ProtocolList [2] = { None, None };
  195605. static Atom wm_ActiveWin = None;
  195606. #define ourDndVersion 3
  195607. static Atom XA_XdndAware = None;
  195608. static Atom XA_XdndEnter = None;
  195609. static Atom XA_XdndLeave = None;
  195610. static Atom XA_XdndPosition = None;
  195611. static Atom XA_XdndStatus = None;
  195612. static Atom XA_XdndDrop = None;
  195613. static Atom XA_XdndFinished = None;
  195614. static Atom XA_XdndSelection = None;
  195615. static Atom XA_XdndProxy = None;
  195616. static Atom XA_XdndTypeList = None;
  195617. static Atom XA_XdndActionList = None;
  195618. static Atom XA_XdndActionDescription = None;
  195619. static Atom XA_XdndActionCopy = None;
  195620. static Atom XA_XdndActionMove = None;
  195621. static Atom XA_XdndActionLink = None;
  195622. static Atom XA_XdndActionAsk = None;
  195623. static Atom XA_XdndActionPrivate = None;
  195624. static Atom XA_JXSelectionWindowProperty = None;
  195625. static Atom XA_MimeTextPlain = None;
  195626. static Atom XA_MimeTextUriList = None;
  195627. static Atom XA_MimeRootDrop = None;
  195628. static XErrorHandler oldHandler = 0;
  195629. static int trappedErrorCode = 0;
  195630. extern "C" int errorTrapHandler (Display* dpy, XErrorEvent* err)
  195631. {
  195632. trappedErrorCode = err->error_code;
  195633. return 0;
  195634. }
  195635. static void trapErrors()
  195636. {
  195637. trappedErrorCode = 0;
  195638. oldHandler = XSetErrorHandler (errorTrapHandler);
  195639. }
  195640. static bool untrapErrors()
  195641. {
  195642. XSetErrorHandler (oldHandler);
  195643. return (trappedErrorCode == 0);
  195644. }
  195645. static bool isActiveApplication = false;
  195646. bool Process::isForegroundProcess()
  195647. {
  195648. return isActiveApplication;
  195649. }
  195650. // These are defined in juce_linux_Messaging.cpp
  195651. extern Display* display;
  195652. extern XContext improbableNumber;
  195653. static const int eventMask = NoEventMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask
  195654. | EnterWindowMask | LeaveWindowMask | PointerMotionMask | KeymapStateMask
  195655. | ExposureMask | StructureNotifyMask | FocusChangeMask;
  195656. static int pointerMap[5];
  195657. static int lastMousePosX = 0, lastMousePosY = 0;
  195658. enum MouseButtons
  195659. {
  195660. NoButton = 0,
  195661. LeftButton = 1,
  195662. MiddleButton = 2,
  195663. RightButton = 3,
  195664. WheelUp = 4,
  195665. WheelDown = 5
  195666. };
  195667. static void getMousePos (int& x, int& y, int& mouseMods) throw()
  195668. {
  195669. Window root, child;
  195670. int winx, winy;
  195671. unsigned int mask;
  195672. mouseMods = 0;
  195673. ScopedXLock xlock;
  195674. if (XQueryPointer (display,
  195675. RootWindow (display, DefaultScreen (display)),
  195676. &root, &child,
  195677. &x, &y, &winx, &winy, &mask) == False)
  195678. {
  195679. // Pointer not on the default screen
  195680. x = y = -1;
  195681. }
  195682. else
  195683. {
  195684. if ((mask & Button1Mask) != 0)
  195685. mouseMods |= ModifierKeys::leftButtonModifier;
  195686. if ((mask & Button2Mask) != 0)
  195687. mouseMods |= ModifierKeys::middleButtonModifier;
  195688. if ((mask & Button3Mask) != 0)
  195689. mouseMods |= ModifierKeys::rightButtonModifier;
  195690. }
  195691. }
  195692. static int AltMask = 0;
  195693. static int NumLockMask = 0;
  195694. static bool numLock = 0;
  195695. static bool capsLock = 0;
  195696. static char keyStates [32];
  195697. static void updateKeyStates (const int keycode, const bool press) throw()
  195698. {
  195699. const int keybyte = keycode >> 3;
  195700. const int keybit = (1 << (keycode & 7));
  195701. if (press)
  195702. keyStates [keybyte] |= keybit;
  195703. else
  195704. keyStates [keybyte] &= ~keybit;
  195705. }
  195706. static bool keyDown (const int keycode) throw()
  195707. {
  195708. const int keybyte = keycode >> 3;
  195709. const int keybit = (1 << (keycode & 7));
  195710. return (keyStates [keybyte] & keybit) != 0;
  195711. }
  195712. static const int extendedKeyModifier = 0x10000000;
  195713. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  195714. {
  195715. int keysym;
  195716. if (keyCode & extendedKeyModifier)
  195717. {
  195718. keysym = 0xff00 | (keyCode & 0xff);
  195719. }
  195720. else
  195721. {
  195722. keysym = keyCode;
  195723. if (keysym == (XK_Tab & 0xff)
  195724. || keysym == (XK_Return & 0xff)
  195725. || keysym == (XK_Escape & 0xff)
  195726. || keysym == (XK_BackSpace & 0xff))
  195727. {
  195728. keysym |= 0xff00;
  195729. }
  195730. }
  195731. ScopedXLock xlock;
  195732. return keyDown (XKeysymToKeycode (display, keysym));
  195733. }
  195734. // Alt and Num lock are not defined by standard X
  195735. // modifier constants: check what they're mapped to
  195736. static void getModifierMapping() throw()
  195737. {
  195738. ScopedXLock xlock;
  195739. const int altLeftCode = XKeysymToKeycode (display, XK_Alt_L);
  195740. const int numLockCode = XKeysymToKeycode (display, XK_Num_Lock);
  195741. AltMask = 0;
  195742. NumLockMask = 0;
  195743. XModifierKeymap* mapping = XGetModifierMapping (display);
  195744. if (mapping)
  195745. {
  195746. for (int i = 0; i < 8; i++)
  195747. {
  195748. if (mapping->modifiermap [i << 1] == altLeftCode)
  195749. AltMask = 1 << i;
  195750. else if (mapping->modifiermap [i << 1] == numLockCode)
  195751. NumLockMask = 1 << i;
  195752. }
  195753. XFreeModifiermap (mapping);
  195754. }
  195755. }
  195756. static int currentModifiers = 0;
  195757. void ModifierKeys::updateCurrentModifiers() throw()
  195758. {
  195759. currentModifierFlags = currentModifiers;
  195760. }
  195761. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  195762. {
  195763. int x, y, mouseMods;
  195764. getMousePos (x, y, mouseMods);
  195765. currentModifiers &= ~ModifierKeys::allMouseButtonModifiers;
  195766. currentModifiers |= mouseMods;
  195767. return ModifierKeys (currentModifiers);
  195768. }
  195769. static void updateKeyModifiers (const int status) throw()
  195770. {
  195771. currentModifiers &= ~(ModifierKeys::shiftModifier
  195772. | ModifierKeys::ctrlModifier
  195773. | ModifierKeys::altModifier);
  195774. if (status & ShiftMask)
  195775. currentModifiers |= ModifierKeys::shiftModifier;
  195776. if (status & ControlMask)
  195777. currentModifiers |= ModifierKeys::ctrlModifier;
  195778. if (status & AltMask)
  195779. currentModifiers |= ModifierKeys::altModifier;
  195780. numLock = ((status & NumLockMask) != 0);
  195781. capsLock = ((status & LockMask) != 0);
  195782. }
  195783. static bool updateKeyModifiersFromSym (KeySym sym, const bool press) throw()
  195784. {
  195785. int modifier = 0;
  195786. bool isModifier = true;
  195787. switch (sym)
  195788. {
  195789. case XK_Shift_L:
  195790. case XK_Shift_R:
  195791. modifier = ModifierKeys::shiftModifier;
  195792. break;
  195793. case XK_Control_L:
  195794. case XK_Control_R:
  195795. modifier = ModifierKeys::ctrlModifier;
  195796. break;
  195797. case XK_Alt_L:
  195798. case XK_Alt_R:
  195799. modifier = ModifierKeys::altModifier;
  195800. break;
  195801. case XK_Num_Lock:
  195802. if (press)
  195803. numLock = ! numLock;
  195804. break;
  195805. case XK_Caps_Lock:
  195806. if (press)
  195807. capsLock = ! capsLock;
  195808. break;
  195809. case XK_Scroll_Lock:
  195810. break;
  195811. default:
  195812. isModifier = false;
  195813. break;
  195814. }
  195815. if (modifier != 0)
  195816. {
  195817. if (press)
  195818. currentModifiers |= modifier;
  195819. else
  195820. currentModifiers &= ~modifier;
  195821. }
  195822. return isModifier;
  195823. }
  195824. #if JUCE_USE_XSHM
  195825. static bool isShmAvailable() throw()
  195826. {
  195827. ScopedXLock xlock;
  195828. static bool isChecked = false;
  195829. static bool isAvailable = false;
  195830. if (! isChecked)
  195831. {
  195832. isChecked = true;
  195833. int major, minor;
  195834. Bool pixmaps;
  195835. if (XShmQueryVersion (display, &major, &minor, &pixmaps))
  195836. {
  195837. trapErrors();
  195838. XShmSegmentInfo segmentInfo;
  195839. zerostruct (segmentInfo);
  195840. XImage* xImage = XShmCreateImage (display, DefaultVisual (display, DefaultScreen (display)),
  195841. 24, ZPixmap, 0, &segmentInfo, 50, 50);
  195842. if ((segmentInfo.shmid = shmget (IPC_PRIVATE,
  195843. xImage->bytes_per_line * xImage->height,
  195844. IPC_CREAT | 0777)) >= 0)
  195845. {
  195846. segmentInfo.shmaddr = (char*) shmat (segmentInfo.shmid, 0, 0);
  195847. if (segmentInfo.shmaddr != (void*) -1)
  195848. {
  195849. segmentInfo.readOnly = False;
  195850. xImage->data = segmentInfo.shmaddr;
  195851. XSync (display, False);
  195852. if (XShmAttach (display, &segmentInfo) != 0)
  195853. {
  195854. XSync (display, False);
  195855. XShmDetach (display, &segmentInfo);
  195856. isAvailable = true;
  195857. }
  195858. }
  195859. XFlush (display);
  195860. XDestroyImage (xImage);
  195861. shmdt (segmentInfo.shmaddr);
  195862. }
  195863. shmctl (segmentInfo.shmid, IPC_RMID, 0);
  195864. isAvailable &= untrapErrors();
  195865. }
  195866. }
  195867. return isAvailable;
  195868. }
  195869. #endif
  195870. static Pixmap juce_createColourPixmapFromImage (Display* display, const Image& image)
  195871. {
  195872. ScopedXLock xlock;
  195873. const int width = image.getWidth();
  195874. const int height = image.getHeight();
  195875. HeapBlock <uint32> colour (width * height);
  195876. int index = 0;
  195877. for (int y = 0; y < height; ++y)
  195878. for (int x = 0; x < width; ++x)
  195879. colour[index++] = image.getPixelAt (x, y).getARGB();
  195880. XImage* ximage = XCreateImage (display, CopyFromParent, 24, ZPixmap,
  195881. 0, (char*) colour, width, height, 32, 0);
  195882. Pixmap pixmap = XCreatePixmap (display, DefaultRootWindow (display),
  195883. width, height, 24);
  195884. GC gc = XCreateGC (display, pixmap, 0, 0);
  195885. XPutImage (display, pixmap, gc, ximage, 0, 0, 0, 0, width, height);
  195886. XFreeGC (display, gc);
  195887. return pixmap;
  195888. }
  195889. static Pixmap juce_createMaskPixmapFromImage (Display* display, const Image& image)
  195890. {
  195891. ScopedXLock xlock;
  195892. const int width = image.getWidth();
  195893. const int height = image.getHeight();
  195894. const int stride = (width + 7) >> 3;
  195895. HeapBlock <uint8> mask;
  195896. mask.calloc (stride * height);
  195897. const bool msbfirst = (BitmapBitOrder (display) == MSBFirst);
  195898. for (int y = 0; y < height; ++y)
  195899. {
  195900. for (int x = 0; x < width; ++x)
  195901. {
  195902. const uint8 bit = (uint8) (1 << (msbfirst ? (7 - (x & 7)) : (x & 7)));
  195903. const int offset = y * stride + (x >> 3);
  195904. if (image.getPixelAt (x, y).getAlpha() >= 128)
  195905. mask[offset] |= bit;
  195906. }
  195907. }
  195908. return XCreatePixmapFromBitmapData (display, DefaultRootWindow (display),
  195909. (char*) mask, width, height, 1, 0, 1);
  195910. }
  195911. class XBitmapImage : public Image
  195912. {
  195913. public:
  195914. XBitmapImage (const PixelFormat format_, const int w, const int h,
  195915. const bool clearImage, const bool is16Bit_)
  195916. : Image (format_, w, h),
  195917. is16Bit (is16Bit_)
  195918. {
  195919. jassert (format_ == RGB || format_ == ARGB);
  195920. pixelStride = (format_ == RGB) ? 3 : 4;
  195921. lineStride = ((w * pixelStride + 3) & ~3);
  195922. ScopedXLock xlock;
  195923. Visual* const visual = DefaultVisual (display, DefaultScreen (display));
  195924. #if JUCE_USE_XSHM
  195925. usingXShm = false;
  195926. if ((! is16Bit) && isShmAvailable())
  195927. {
  195928. zerostruct (segmentInfo);
  195929. xImage = XShmCreateImage (display, visual, 24, ZPixmap, 0, &segmentInfo, w, h);
  195930. if (xImage != 0)
  195931. {
  195932. if ((segmentInfo.shmid = shmget (IPC_PRIVATE,
  195933. xImage->bytes_per_line * xImage->height,
  195934. IPC_CREAT | 0777)) >= 0)
  195935. {
  195936. segmentInfo.shmaddr = (char*) shmat (segmentInfo.shmid, 0, 0);
  195937. if (segmentInfo.shmaddr != (void*) -1)
  195938. {
  195939. segmentInfo.readOnly = False;
  195940. xImage->data = segmentInfo.shmaddr;
  195941. imageData = (uint8*) segmentInfo.shmaddr;
  195942. XSync (display, False);
  195943. if (XShmAttach (display, &segmentInfo) != 0)
  195944. {
  195945. XSync (display, False);
  195946. usingXShm = true;
  195947. }
  195948. else
  195949. {
  195950. jassertfalse
  195951. }
  195952. }
  195953. else
  195954. {
  195955. shmctl (segmentInfo.shmid, IPC_RMID, 0);
  195956. }
  195957. }
  195958. }
  195959. }
  195960. if (! usingXShm)
  195961. #endif
  195962. {
  195963. imageDataAllocated.malloc (lineStride * h);
  195964. imageData = imageDataAllocated;
  195965. if (format_ == ARGB && clearImage)
  195966. zeromem (imageData, h * lineStride);
  195967. xImage = (XImage*) juce_calloc (sizeof (XImage));
  195968. xImage->width = w;
  195969. xImage->height = h;
  195970. xImage->xoffset = 0;
  195971. xImage->format = ZPixmap;
  195972. xImage->data = (char*) imageData;
  195973. xImage->byte_order = ImageByteOrder (display);
  195974. xImage->bitmap_unit = BitmapUnit (display);
  195975. xImage->bitmap_bit_order = BitmapBitOrder (display);
  195976. xImage->bitmap_pad = 32;
  195977. xImage->depth = pixelStride * 8;
  195978. xImage->bytes_per_line = lineStride;
  195979. xImage->bits_per_pixel = pixelStride * 8;
  195980. xImage->red_mask = 0x00FF0000;
  195981. xImage->green_mask = 0x0000FF00;
  195982. xImage->blue_mask = 0x000000FF;
  195983. if (is16Bit)
  195984. {
  195985. const int pixelStride = 2;
  195986. const int lineStride = ((w * pixelStride + 3) & ~3);
  195987. imageData16Bit.malloc (lineStride * h);
  195988. xImage->data = imageData16Bit;
  195989. xImage->bitmap_pad = 16;
  195990. xImage->depth = pixelStride * 8;
  195991. xImage->bytes_per_line = lineStride;
  195992. xImage->bits_per_pixel = pixelStride * 8;
  195993. xImage->red_mask = visual->red_mask;
  195994. xImage->green_mask = visual->green_mask;
  195995. xImage->blue_mask = visual->blue_mask;
  195996. }
  195997. if (! XInitImage (xImage))
  195998. {
  195999. jassertfalse
  196000. }
  196001. }
  196002. }
  196003. ~XBitmapImage()
  196004. {
  196005. ScopedXLock xlock;
  196006. #if JUCE_USE_XSHM
  196007. if (usingXShm)
  196008. {
  196009. XShmDetach (display, &segmentInfo);
  196010. XFlush (display);
  196011. XDestroyImage (xImage);
  196012. shmdt (segmentInfo.shmaddr);
  196013. shmctl (segmentInfo.shmid, IPC_RMID, 0);
  196014. }
  196015. else
  196016. #endif
  196017. {
  196018. xImage->data = 0;
  196019. XDestroyImage (xImage);
  196020. }
  196021. }
  196022. void blitToWindow (Window window, int dx, int dy, int dw, int dh, int sx, int sy)
  196023. {
  196024. ScopedXLock xlock;
  196025. static GC gc = 0;
  196026. if (gc == 0)
  196027. gc = DefaultGC (display, DefaultScreen (display));
  196028. if (is16Bit)
  196029. {
  196030. const uint32 rMask = xImage->red_mask;
  196031. const uint32 rShiftL = jmax (0, getShiftNeeded (rMask));
  196032. const uint32 rShiftR = jmax (0, -getShiftNeeded (rMask));
  196033. const uint32 gMask = xImage->green_mask;
  196034. const uint32 gShiftL = jmax (0, getShiftNeeded (gMask));
  196035. const uint32 gShiftR = jmax (0, -getShiftNeeded (gMask));
  196036. const uint32 bMask = xImage->blue_mask;
  196037. const uint32 bShiftL = jmax (0, getShiftNeeded (bMask));
  196038. const uint32 bShiftR = jmax (0, -getShiftNeeded (bMask));
  196039. const Image::BitmapData srcData (*this, 0, 0, getWidth(), getHeight());
  196040. for (int y = sy; y < sy + dh; ++y)
  196041. {
  196042. const uint8* p = srcData.getPixelPointer (sx, y);
  196043. for (int x = sx; x < sx + dw; ++x)
  196044. {
  196045. const PixelRGB* const pixel = (const PixelRGB*) p;
  196046. p += srcData.pixelStride;
  196047. XPutPixel (xImage, x, y,
  196048. (((((uint32) pixel->getRed()) << rShiftL) >> rShiftR) & rMask)
  196049. | (((((uint32) pixel->getGreen()) << gShiftL) >> gShiftR) & gMask)
  196050. | (((((uint32) pixel->getBlue()) << bShiftL) >> bShiftR) & bMask));
  196051. }
  196052. }
  196053. }
  196054. // blit results to screen.
  196055. #if JUCE_USE_XSHM
  196056. if (usingXShm)
  196057. XShmPutImage (display, (::Drawable) window, gc, xImage, sx, sy, dx, dy, dw, dh, True);
  196058. else
  196059. #endif
  196060. XPutImage (display, (::Drawable) window, gc, xImage, sx, sy, dx, dy, dw, dh);
  196061. }
  196062. juce_UseDebuggingNewOperator
  196063. private:
  196064. XImage* xImage;
  196065. const bool is16Bit;
  196066. HeapBlock <char> imageData16Bit;
  196067. #if JUCE_USE_XSHM
  196068. XShmSegmentInfo segmentInfo;
  196069. bool usingXShm;
  196070. #endif
  196071. static int getShiftNeeded (const uint32 mask) throw()
  196072. {
  196073. for (int i = 32; --i >= 0;)
  196074. if (((mask >> i) & 1) != 0)
  196075. return i - 7;
  196076. jassertfalse
  196077. return 0;
  196078. }
  196079. };
  196080. #define checkMessageManagerIsLocked jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  196081. class LinuxComponentPeer : public ComponentPeer
  196082. {
  196083. public:
  196084. LinuxComponentPeer (Component* const component, const int windowStyleFlags)
  196085. : ComponentPeer (component, windowStyleFlags),
  196086. windowH (0),
  196087. parentWindow (0),
  196088. wx (0),
  196089. wy (0),
  196090. ww (0),
  196091. wh (0),
  196092. taskbarImage (0),
  196093. fullScreen (false),
  196094. entered (false),
  196095. mapped (false)
  196096. {
  196097. // it's dangerous to create a window on a thread other than the message thread..
  196098. checkMessageManagerIsLocked
  196099. repainter = new LinuxRepaintManager (this);
  196100. createWindow();
  196101. setTitle (component->getName());
  196102. }
  196103. ~LinuxComponentPeer()
  196104. {
  196105. // it's dangerous to delete a window on a thread other than the message thread..
  196106. checkMessageManagerIsLocked
  196107. deleteTaskBarIcon();
  196108. deleteIconPixmaps();
  196109. destroyWindow();
  196110. windowH = 0;
  196111. }
  196112. void* getNativeHandle() const
  196113. {
  196114. return (void*) windowH;
  196115. }
  196116. static LinuxComponentPeer* getPeerFor (Window windowHandle) throw()
  196117. {
  196118. XPointer peer = 0;
  196119. ScopedXLock xlock;
  196120. if (! XFindContext (display, (XID) windowHandle, improbableNumber, &peer))
  196121. {
  196122. if (peer != 0 && ! ((LinuxComponentPeer*) peer)->isValidMessageListener())
  196123. peer = 0;
  196124. }
  196125. return (LinuxComponentPeer*) peer;
  196126. }
  196127. void setVisible (bool shouldBeVisible)
  196128. {
  196129. ScopedXLock xlock;
  196130. if (shouldBeVisible)
  196131. XMapWindow (display, windowH);
  196132. else
  196133. XUnmapWindow (display, windowH);
  196134. }
  196135. void setTitle (const String& title)
  196136. {
  196137. setWindowTitle (windowH, title);
  196138. }
  196139. void setPosition (int x, int y)
  196140. {
  196141. setBounds (x, y, ww, wh, false);
  196142. }
  196143. void setSize (int w, int h)
  196144. {
  196145. setBounds (wx, wy, w, h, false);
  196146. }
  196147. void setBounds (int x, int y, int w, int h, const bool isNowFullScreen)
  196148. {
  196149. fullScreen = isNowFullScreen;
  196150. if (windowH != 0)
  196151. {
  196152. const ComponentDeletionWatcher deletionChecker (component);
  196153. wx = x;
  196154. wy = y;
  196155. ww = jmax (1, w);
  196156. wh = jmax (1, h);
  196157. ScopedXLock xlock;
  196158. // Make sure the Window manager does what we want
  196159. XSizeHints* hints = XAllocSizeHints();
  196160. hints->flags = USSize | USPosition;
  196161. hints->width = ww;
  196162. hints->height = wh;
  196163. hints->x = wx;
  196164. hints->y = wy;
  196165. if ((getStyleFlags() & (windowHasTitleBar | windowIsResizable)) == windowHasTitleBar)
  196166. {
  196167. hints->min_width = hints->max_width = hints->width;
  196168. hints->min_height = hints->max_height = hints->height;
  196169. hints->flags |= PMinSize | PMaxSize;
  196170. }
  196171. XSetWMNormalHints (display, windowH, hints);
  196172. XFree (hints);
  196173. XMoveResizeWindow (display, windowH,
  196174. wx - windowBorder.getLeft(),
  196175. wy - windowBorder.getTop(), ww, wh);
  196176. if (! deletionChecker.hasBeenDeleted())
  196177. {
  196178. updateBorderSize();
  196179. handleMovedOrResized();
  196180. }
  196181. }
  196182. }
  196183. void getBounds (int& x, int& y, int& w, int& h) const
  196184. {
  196185. x = wx;
  196186. y = wy;
  196187. w = ww;
  196188. h = wh;
  196189. }
  196190. int getScreenX() const
  196191. {
  196192. return wx;
  196193. }
  196194. int getScreenY() const
  196195. {
  196196. return wy;
  196197. }
  196198. void relativePositionToGlobal (int& x, int& y)
  196199. {
  196200. x += wx;
  196201. y += wy;
  196202. }
  196203. void globalPositionToRelative (int& x, int& y)
  196204. {
  196205. x -= wx;
  196206. y -= wy;
  196207. }
  196208. void setMinimised (bool shouldBeMinimised)
  196209. {
  196210. if (shouldBeMinimised)
  196211. {
  196212. Window root = RootWindow (display, DefaultScreen (display));
  196213. XClientMessageEvent clientMsg;
  196214. clientMsg.display = display;
  196215. clientMsg.window = windowH;
  196216. clientMsg.type = ClientMessage;
  196217. clientMsg.format = 32;
  196218. clientMsg.message_type = wm_ChangeState;
  196219. clientMsg.data.l[0] = IconicState;
  196220. ScopedXLock xlock;
  196221. XSendEvent (display, root, false,
  196222. SubstructureRedirectMask | SubstructureNotifyMask,
  196223. (XEvent*) &clientMsg);
  196224. }
  196225. else
  196226. {
  196227. setVisible (true);
  196228. }
  196229. }
  196230. bool isMinimised() const
  196231. {
  196232. bool minimised = false;
  196233. unsigned char* stateProp;
  196234. unsigned long nitems, bytesLeft;
  196235. Atom actualType;
  196236. int actualFormat;
  196237. ScopedXLock xlock;
  196238. if (XGetWindowProperty (display, windowH, wm_State, 0, 64, False,
  196239. wm_State, &actualType, &actualFormat, &nitems, &bytesLeft,
  196240. &stateProp) == Success
  196241. && actualType == wm_State
  196242. && actualFormat == 32
  196243. && nitems > 0)
  196244. {
  196245. if (((unsigned long*) stateProp)[0] == IconicState)
  196246. minimised = true;
  196247. XFree (stateProp);
  196248. }
  196249. return minimised;
  196250. }
  196251. void setFullScreen (const bool shouldBeFullScreen)
  196252. {
  196253. Rectangle<int> r (lastNonFullscreenBounds); // (get a copy of this before de-minimising)
  196254. setMinimised (false);
  196255. if (fullScreen != shouldBeFullScreen)
  196256. {
  196257. if (shouldBeFullScreen)
  196258. r = Desktop::getInstance().getMainMonitorArea();
  196259. if (! r.isEmpty())
  196260. setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight(), shouldBeFullScreen);
  196261. getComponent()->repaint();
  196262. }
  196263. }
  196264. bool isFullScreen() const
  196265. {
  196266. return fullScreen;
  196267. }
  196268. bool isChildWindowOf (Window possibleParent) const
  196269. {
  196270. Window* windowList = 0;
  196271. uint32 windowListSize = 0;
  196272. Window parent, root;
  196273. ScopedXLock xlock;
  196274. if (XQueryTree (display, windowH, &root, &parent, &windowList, &windowListSize) != 0)
  196275. {
  196276. if (windowList != 0)
  196277. XFree (windowList);
  196278. return parent == possibleParent;
  196279. }
  196280. return false;
  196281. }
  196282. bool isFrontWindow() const
  196283. {
  196284. Window* windowList = 0;
  196285. uint32 windowListSize = 0;
  196286. bool result = false;
  196287. ScopedXLock xlock;
  196288. Window parent, root = RootWindow (display, DefaultScreen (display));
  196289. if (XQueryTree (display, root, &root, &parent, &windowList, &windowListSize) != 0)
  196290. {
  196291. for (int i = windowListSize; --i >= 0;)
  196292. {
  196293. LinuxComponentPeer* const peer = LinuxComponentPeer::getPeerFor (windowList[i]);
  196294. if (peer != 0)
  196295. {
  196296. result = (peer == this);
  196297. break;
  196298. }
  196299. }
  196300. }
  196301. if (windowList != 0)
  196302. XFree (windowList);
  196303. return result;
  196304. }
  196305. bool contains (int x, int y, bool trueIfInAChildWindow) const
  196306. {
  196307. jassert (x >= 0 && y >= 0 && x < ww && y < wh); // should only be called for points that are actually inside the bounds
  196308. if (((unsigned int) x) >= (unsigned int) ww
  196309. || ((unsigned int) y) >= (unsigned int) wh)
  196310. return false;
  196311. bool inFront = false;
  196312. for (int i = 0; i < Desktop::getInstance().getNumComponents(); ++i)
  196313. {
  196314. Component* const c = Desktop::getInstance().getComponent (i);
  196315. if (inFront)
  196316. {
  196317. if (c->contains (x + wx - c->getScreenX(),
  196318. y + wy - c->getScreenY()))
  196319. {
  196320. return false;
  196321. }
  196322. }
  196323. else if (c == getComponent())
  196324. {
  196325. inFront = true;
  196326. }
  196327. }
  196328. if (trueIfInAChildWindow)
  196329. return true;
  196330. ::Window root, child;
  196331. unsigned int bw, depth;
  196332. int wx, wy, w, h;
  196333. ScopedXLock xlock;
  196334. if (! XGetGeometry (display, (::Drawable) windowH, &root,
  196335. &wx, &wy, (unsigned int*) &w, (unsigned int*) &h,
  196336. &bw, &depth))
  196337. {
  196338. return false;
  196339. }
  196340. if (! XTranslateCoordinates (display, windowH, windowH, x, y, &wx, &wy, &child))
  196341. return false;
  196342. return child == None;
  196343. }
  196344. const BorderSize getFrameSize() const
  196345. {
  196346. return BorderSize();
  196347. }
  196348. bool setAlwaysOnTop (bool alwaysOnTop)
  196349. {
  196350. if (windowH != 0)
  196351. {
  196352. const bool wasVisible = component->isVisible();
  196353. if (wasVisible)
  196354. setVisible (false); // doesn't always seem to work if the window is visible when this is done..
  196355. {
  196356. ScopedXLock xlock;
  196357. XSetWindowAttributes swa;
  196358. swa.override_redirect = alwaysOnTop ? True : False;
  196359. XChangeWindowAttributes (display, windowH, CWOverrideRedirect, &swa);
  196360. }
  196361. if (wasVisible)
  196362. setVisible (true);
  196363. }
  196364. return true;
  196365. }
  196366. void toFront (bool makeActive)
  196367. {
  196368. if (makeActive)
  196369. {
  196370. setVisible (true);
  196371. grabFocus();
  196372. }
  196373. XEvent ev;
  196374. ev.xclient.type = ClientMessage;
  196375. ev.xclient.serial = 0;
  196376. ev.xclient.send_event = True;
  196377. ev.xclient.message_type = wm_ActiveWin;
  196378. ev.xclient.window = windowH;
  196379. ev.xclient.format = 32;
  196380. ev.xclient.data.l[0] = 2;
  196381. ev.xclient.data.l[1] = CurrentTime;
  196382. ev.xclient.data.l[2] = 0;
  196383. ev.xclient.data.l[3] = 0;
  196384. ev.xclient.data.l[4] = 0;
  196385. {
  196386. ScopedXLock xlock;
  196387. XSendEvent (display, RootWindow (display, DefaultScreen (display)),
  196388. False,
  196389. SubstructureRedirectMask | SubstructureNotifyMask,
  196390. &ev);
  196391. XWindowAttributes attr;
  196392. XGetWindowAttributes (display, windowH, &attr);
  196393. if (attr.override_redirect)
  196394. XRaiseWindow (display, windowH);
  196395. XSync (display, False);
  196396. }
  196397. handleBroughtToFront();
  196398. }
  196399. void toBehind (ComponentPeer* other)
  196400. {
  196401. LinuxComponentPeer* const otherPeer = dynamic_cast <LinuxComponentPeer*> (other);
  196402. jassert (otherPeer != 0); // wrong type of window?
  196403. if (otherPeer != 0)
  196404. {
  196405. setMinimised (false);
  196406. Window newStack[] = { otherPeer->windowH, windowH };
  196407. ScopedXLock xlock;
  196408. XRestackWindows (display, newStack, 2);
  196409. }
  196410. }
  196411. bool isFocused() const
  196412. {
  196413. int revert;
  196414. Window focusedWindow = 0;
  196415. ScopedXLock xlock;
  196416. XGetInputFocus (display, &focusedWindow, &revert);
  196417. return focusedWindow == windowH;
  196418. }
  196419. void grabFocus()
  196420. {
  196421. XWindowAttributes atts;
  196422. ScopedXLock xlock;
  196423. if (windowH != 0
  196424. && XGetWindowAttributes (display, windowH, &atts)
  196425. && atts.map_state == IsViewable
  196426. && ! isFocused())
  196427. {
  196428. XSetInputFocus (display, windowH, RevertToParent, CurrentTime);
  196429. isActiveApplication = true;
  196430. }
  196431. }
  196432. void textInputRequired (int /*x*/, int /*y*/)
  196433. {
  196434. }
  196435. void repaint (int x, int y, int w, int h)
  196436. {
  196437. if (Rectangle<int>::intersectRectangles (x, y, w, h,
  196438. 0, 0,
  196439. getComponent()->getWidth(),
  196440. getComponent()->getHeight()))
  196441. {
  196442. repainter->repaint (x, y, w, h);
  196443. }
  196444. }
  196445. void performAnyPendingRepaintsNow()
  196446. {
  196447. repainter->performAnyPendingRepaintsNow();
  196448. }
  196449. void setIcon (const Image& newIcon)
  196450. {
  196451. const int dataSize = newIcon.getWidth() * newIcon.getHeight() + 2;
  196452. HeapBlock <unsigned long> data (dataSize);
  196453. int index = 0;
  196454. data[index++] = newIcon.getWidth();
  196455. data[index++] = newIcon.getHeight();
  196456. for (int y = 0; y < newIcon.getHeight(); ++y)
  196457. for (int x = 0; x < newIcon.getWidth(); ++x)
  196458. data[index++] = newIcon.getPixelAt (x, y).getARGB();
  196459. ScopedXLock xlock;
  196460. XChangeProperty (display, windowH,
  196461. XInternAtom (display, "_NET_WM_ICON", False),
  196462. XA_CARDINAL, 32, PropModeReplace,
  196463. (unsigned char*) data, dataSize);
  196464. deleteIconPixmaps();
  196465. XWMHints* wmHints = XGetWMHints (display, windowH);
  196466. if (wmHints == 0)
  196467. wmHints = XAllocWMHints();
  196468. wmHints->flags |= IconPixmapHint | IconMaskHint;
  196469. wmHints->icon_pixmap = juce_createColourPixmapFromImage (display, newIcon);
  196470. wmHints->icon_mask = juce_createMaskPixmapFromImage (display, newIcon);
  196471. XSetWMHints (display, windowH, wmHints);
  196472. XFree (wmHints);
  196473. XSync (display, False);
  196474. }
  196475. void deleteIconPixmaps()
  196476. {
  196477. ScopedXLock xlock;
  196478. XWMHints* wmHints = XGetWMHints (display, windowH);
  196479. if (wmHints != 0)
  196480. {
  196481. if ((wmHints->flags & IconPixmapHint) != 0)
  196482. {
  196483. wmHints->flags &= ~IconPixmapHint;
  196484. XFreePixmap (display, wmHints->icon_pixmap);
  196485. }
  196486. if ((wmHints->flags & IconMaskHint) != 0)
  196487. {
  196488. wmHints->flags &= ~IconMaskHint;
  196489. XFreePixmap (display, wmHints->icon_mask);
  196490. }
  196491. XSetWMHints (display, windowH, wmHints);
  196492. XFree (wmHints);
  196493. }
  196494. }
  196495. void handleWindowMessage (XEvent* event)
  196496. {
  196497. switch (event->xany.type)
  196498. {
  196499. case 2: // 'KeyPress'
  196500. {
  196501. ScopedXLock xlock;
  196502. XKeyEvent* const keyEvent = (XKeyEvent*) &event->xkey;
  196503. updateKeyStates (keyEvent->keycode, true);
  196504. char utf8 [64];
  196505. zeromem (utf8, sizeof (utf8));
  196506. KeySym sym;
  196507. XLookupString (keyEvent, utf8, sizeof (utf8), &sym, 0);
  196508. const juce_wchar unicodeChar = *(const juce_wchar*) String::fromUTF8 ((const uint8*) utf8, sizeof (utf8) - 1);
  196509. int keyCode = (int) unicodeChar;
  196510. if (keyCode < 0x20)
  196511. keyCode = XKeycodeToKeysym (display, keyEvent->keycode,
  196512. (currentModifiers & ModifierKeys::shiftModifier) != 0 ? 1 : 0);
  196513. const int oldMods = currentModifiers;
  196514. bool keyPressed = false;
  196515. const bool keyDownChange = (sym != NoSymbol) && ! updateKeyModifiersFromSym (sym, true);
  196516. if ((sym & 0xff00) == 0xff00)
  196517. {
  196518. // Translate keypad
  196519. if (sym == XK_KP_Divide)
  196520. keyCode = XK_slash;
  196521. else if (sym == XK_KP_Multiply)
  196522. keyCode = XK_asterisk;
  196523. else if (sym == XK_KP_Subtract)
  196524. keyCode = XK_hyphen;
  196525. else if (sym == XK_KP_Add)
  196526. keyCode = XK_plus;
  196527. else if (sym == XK_KP_Enter)
  196528. keyCode = XK_Return;
  196529. else if (sym == XK_KP_Decimal)
  196530. keyCode = numLock ? XK_period : XK_Delete;
  196531. else if (sym == XK_KP_0)
  196532. keyCode = numLock ? XK_0 : XK_Insert;
  196533. else if (sym == XK_KP_1)
  196534. keyCode = numLock ? XK_1 : XK_End;
  196535. else if (sym == XK_KP_2)
  196536. keyCode = numLock ? XK_2 : XK_Down;
  196537. else if (sym == XK_KP_3)
  196538. keyCode = numLock ? XK_3 : XK_Page_Down;
  196539. else if (sym == XK_KP_4)
  196540. keyCode = numLock ? XK_4 : XK_Left;
  196541. else if (sym == XK_KP_5)
  196542. keyCode = XK_5;
  196543. else if (sym == XK_KP_6)
  196544. keyCode = numLock ? XK_6 : XK_Right;
  196545. else if (sym == XK_KP_7)
  196546. keyCode = numLock ? XK_7 : XK_Home;
  196547. else if (sym == XK_KP_8)
  196548. keyCode = numLock ? XK_8 : XK_Up;
  196549. else if (sym == XK_KP_9)
  196550. keyCode = numLock ? XK_9 : XK_Page_Up;
  196551. switch (sym)
  196552. {
  196553. case XK_Left:
  196554. case XK_Right:
  196555. case XK_Up:
  196556. case XK_Down:
  196557. case XK_Page_Up:
  196558. case XK_Page_Down:
  196559. case XK_End:
  196560. case XK_Home:
  196561. case XK_Delete:
  196562. case XK_Insert:
  196563. keyPressed = true;
  196564. keyCode = (sym & 0xff) | extendedKeyModifier;
  196565. break;
  196566. case XK_Tab:
  196567. case XK_Return:
  196568. case XK_Escape:
  196569. case XK_BackSpace:
  196570. keyPressed = true;
  196571. keyCode &= 0xff;
  196572. break;
  196573. default:
  196574. {
  196575. if (sym >= XK_F1 && sym <= XK_F16)
  196576. {
  196577. keyPressed = true;
  196578. keyCode = (sym & 0xff) | extendedKeyModifier;
  196579. }
  196580. break;
  196581. }
  196582. }
  196583. }
  196584. if (utf8[0] != 0 || ((sym & 0xff00) == 0 && sym >= 8))
  196585. keyPressed = true;
  196586. if (oldMods != currentModifiers)
  196587. handleModifierKeysChange();
  196588. if (keyDownChange)
  196589. handleKeyUpOrDown (true);
  196590. if (keyPressed)
  196591. handleKeyPress (keyCode, unicodeChar);
  196592. break;
  196593. }
  196594. case KeyRelease:
  196595. {
  196596. const XKeyEvent* const keyEvent = (const XKeyEvent*) &event->xkey;
  196597. updateKeyStates (keyEvent->keycode, false);
  196598. ScopedXLock xlock;
  196599. KeySym sym = XKeycodeToKeysym (display, keyEvent->keycode, 0);
  196600. const int oldMods = currentModifiers;
  196601. const bool keyDownChange = (sym != NoSymbol) && ! updateKeyModifiersFromSym (sym, false);
  196602. if (oldMods != currentModifiers)
  196603. handleModifierKeysChange();
  196604. if (keyDownChange)
  196605. handleKeyUpOrDown (false);
  196606. break;
  196607. }
  196608. case ButtonPress:
  196609. {
  196610. const XButtonPressedEvent* const buttonPressEvent = (const XButtonPressedEvent*) &event->xbutton;
  196611. bool buttonMsg = false;
  196612. bool wheelUpMsg = false;
  196613. bool wheelDownMsg = false;
  196614. const int map = pointerMap [buttonPressEvent->button - Button1];
  196615. if (map == LeftButton)
  196616. {
  196617. currentModifiers |= ModifierKeys::leftButtonModifier;
  196618. buttonMsg = true;
  196619. }
  196620. else if (map == RightButton)
  196621. {
  196622. currentModifiers |= ModifierKeys::rightButtonModifier;
  196623. buttonMsg = true;
  196624. }
  196625. else if (map == MiddleButton)
  196626. {
  196627. currentModifiers |= ModifierKeys::middleButtonModifier;
  196628. buttonMsg = true;
  196629. }
  196630. else if (map == WheelUp)
  196631. {
  196632. wheelUpMsg = true;
  196633. }
  196634. else if (map == WheelDown)
  196635. {
  196636. wheelDownMsg = true;
  196637. }
  196638. updateKeyModifiers (buttonPressEvent->state);
  196639. if (buttonMsg)
  196640. {
  196641. toFront (true);
  196642. handleMouseDown (buttonPressEvent->x, buttonPressEvent->y,
  196643. getEventTime (buttonPressEvent->time));
  196644. }
  196645. else if (wheelUpMsg || wheelDownMsg)
  196646. {
  196647. handleMouseWheel (0, wheelDownMsg ? -84 : 84,
  196648. getEventTime (buttonPressEvent->time));
  196649. }
  196650. lastMousePosX = lastMousePosY = 0x100000;
  196651. break;
  196652. }
  196653. case ButtonRelease:
  196654. {
  196655. const XButtonReleasedEvent* const buttonRelEvent = (const XButtonReleasedEvent*) &event->xbutton;
  196656. const int oldModifiers = currentModifiers;
  196657. const int map = pointerMap [buttonRelEvent->button - Button1];
  196658. if (map == LeftButton)
  196659. currentModifiers &= ~ModifierKeys::leftButtonModifier;
  196660. else if (map == RightButton)
  196661. currentModifiers &= ~ModifierKeys::rightButtonModifier;
  196662. else if (map == MiddleButton)
  196663. currentModifiers &= ~ModifierKeys::middleButtonModifier;
  196664. updateKeyModifiers (buttonRelEvent->state);
  196665. handleMouseUp (oldModifiers,
  196666. buttonRelEvent->x, buttonRelEvent->y,
  196667. getEventTime (buttonRelEvent->time));
  196668. lastMousePosX = lastMousePosY = 0x100000;
  196669. break;
  196670. }
  196671. case MotionNotify:
  196672. {
  196673. const XPointerMovedEvent* const movedEvent = (const XPointerMovedEvent*) &event->xmotion;
  196674. updateKeyModifiers (movedEvent->state);
  196675. int x, y, mouseMods;
  196676. getMousePos (x, y, mouseMods);
  196677. if (lastMousePosX != x || lastMousePosY != y)
  196678. {
  196679. lastMousePosX = x;
  196680. lastMousePosY = y;
  196681. if (parentWindow != 0 && (styleFlags & windowHasTitleBar) == 0)
  196682. {
  196683. Window wRoot = 0, wParent = 0;
  196684. Window* wChild = 0;
  196685. unsigned int numChildren;
  196686. {
  196687. ScopedXLock xlock;
  196688. XQueryTree (display, windowH, &wRoot, &wParent, &wChild, &numChildren);
  196689. }
  196690. if (wParent != 0
  196691. && wParent != windowH
  196692. && wParent != wRoot)
  196693. {
  196694. parentWindow = wParent;
  196695. updateBounds();
  196696. x -= getScreenX();
  196697. y -= getScreenY();
  196698. }
  196699. else
  196700. {
  196701. parentWindow = 0;
  196702. x -= getScreenX();
  196703. y -= getScreenY();
  196704. }
  196705. }
  196706. else
  196707. {
  196708. x -= getScreenX();
  196709. y -= getScreenY();
  196710. }
  196711. if ((currentModifiers & ModifierKeys::allMouseButtonModifiers) == 0)
  196712. handleMouseMove (x, y, getEventTime (movedEvent->time));
  196713. else
  196714. handleMouseDrag (x, y, getEventTime (movedEvent->time));
  196715. }
  196716. break;
  196717. }
  196718. case EnterNotify:
  196719. {
  196720. lastMousePosX = lastMousePosY = 0x100000;
  196721. const XEnterWindowEvent* const enterEvent = (const XEnterWindowEvent*) &event->xcrossing;
  196722. if ((currentModifiers & ModifierKeys::allMouseButtonModifiers) == 0
  196723. && ! entered)
  196724. {
  196725. updateKeyModifiers (enterEvent->state);
  196726. handleMouseEnter (enterEvent->x, enterEvent->y, getEventTime (enterEvent->time));
  196727. entered = true;
  196728. }
  196729. break;
  196730. }
  196731. case LeaveNotify:
  196732. {
  196733. const XLeaveWindowEvent* const leaveEvent = (const XLeaveWindowEvent*) &event->xcrossing;
  196734. // Suppress the normal leave if we've got a pointer grab, or if
  196735. // it's a bogus one caused by clicking a mouse button when running
  196736. // in a Window manager
  196737. if (((currentModifiers & ModifierKeys::allMouseButtonModifiers) == 0
  196738. && leaveEvent->mode == NotifyNormal)
  196739. || leaveEvent->mode == NotifyUngrab)
  196740. {
  196741. updateKeyModifiers (leaveEvent->state);
  196742. handleMouseExit (leaveEvent->x, leaveEvent->y, getEventTime (leaveEvent->time));
  196743. entered = false;
  196744. }
  196745. break;
  196746. }
  196747. case FocusIn:
  196748. {
  196749. isActiveApplication = true;
  196750. if (isFocused())
  196751. handleFocusGain();
  196752. break;
  196753. }
  196754. case FocusOut:
  196755. {
  196756. isActiveApplication = false;
  196757. if (! isFocused())
  196758. handleFocusLoss();
  196759. break;
  196760. }
  196761. case Expose:
  196762. {
  196763. // Batch together all pending expose events
  196764. XExposeEvent* exposeEvent = (XExposeEvent*) &event->xexpose;
  196765. XEvent nextEvent;
  196766. ScopedXLock xlock;
  196767. if (exposeEvent->window != windowH)
  196768. {
  196769. Window child;
  196770. XTranslateCoordinates (display, exposeEvent->window, windowH,
  196771. exposeEvent->x, exposeEvent->y, &exposeEvent->x, &exposeEvent->y,
  196772. &child);
  196773. }
  196774. repaint (exposeEvent->x, exposeEvent->y,
  196775. exposeEvent->width, exposeEvent->height);
  196776. while (XEventsQueued (display, QueuedAfterFlush) > 0)
  196777. {
  196778. XPeekEvent (display, (XEvent*) &nextEvent);
  196779. if (nextEvent.type != Expose || nextEvent.xany.window != event->xany.window)
  196780. break;
  196781. XNextEvent (display, (XEvent*) &nextEvent);
  196782. XExposeEvent* nextExposeEvent = (XExposeEvent*) &nextEvent.xexpose;
  196783. repaint (nextExposeEvent->x, nextExposeEvent->y,
  196784. nextExposeEvent->width, nextExposeEvent->height);
  196785. }
  196786. break;
  196787. }
  196788. case CirculateNotify:
  196789. case CreateNotify:
  196790. case DestroyNotify:
  196791. // Think we can ignore these
  196792. break;
  196793. case ConfigureNotify:
  196794. {
  196795. updateBounds();
  196796. updateBorderSize();
  196797. handleMovedOrResized();
  196798. // if the native title bar is dragged, need to tell any active menus, etc.
  196799. if ((styleFlags & windowHasTitleBar) != 0
  196800. && component->isCurrentlyBlockedByAnotherModalComponent())
  196801. {
  196802. Component* const currentModalComp = Component::getCurrentlyModalComponent();
  196803. if (currentModalComp != 0)
  196804. currentModalComp->inputAttemptWhenModal();
  196805. }
  196806. XConfigureEvent* const confEvent = (XConfigureEvent*) &event->xconfigure;
  196807. if (confEvent->window == windowH
  196808. && confEvent->above != 0
  196809. && isFrontWindow())
  196810. {
  196811. handleBroughtToFront();
  196812. }
  196813. break;
  196814. }
  196815. case ReparentNotify:
  196816. case GravityNotify:
  196817. {
  196818. parentWindow = 0;
  196819. Window wRoot = 0;
  196820. Window* wChild = 0;
  196821. unsigned int numChildren;
  196822. {
  196823. ScopedXLock xlock;
  196824. XQueryTree (display, windowH, &wRoot, &parentWindow, &wChild, &numChildren);
  196825. }
  196826. if (parentWindow == windowH || parentWindow == wRoot)
  196827. parentWindow = 0;
  196828. updateBounds();
  196829. updateBorderSize();
  196830. handleMovedOrResized();
  196831. break;
  196832. }
  196833. case MapNotify:
  196834. mapped = true;
  196835. handleBroughtToFront();
  196836. break;
  196837. case UnmapNotify:
  196838. mapped = false;
  196839. break;
  196840. case MappingNotify:
  196841. {
  196842. XMappingEvent* mappingEvent = (XMappingEvent*) &event->xmapping;
  196843. if (mappingEvent->request != MappingPointer)
  196844. {
  196845. // Deal with modifier/keyboard mapping
  196846. ScopedXLock xlock;
  196847. XRefreshKeyboardMapping (mappingEvent);
  196848. getModifierMapping();
  196849. }
  196850. break;
  196851. }
  196852. case ClientMessage:
  196853. {
  196854. const XClientMessageEvent* const clientMsg = (const XClientMessageEvent*) &event->xclient;
  196855. if (clientMsg->message_type == wm_Protocols && clientMsg->format == 32)
  196856. {
  196857. const Atom atom = (Atom) clientMsg->data.l[0];
  196858. if (atom == wm_ProtocolList [TAKE_FOCUS])
  196859. {
  196860. XWindowAttributes atts;
  196861. ScopedXLock xlock;
  196862. if (clientMsg->window != 0
  196863. && XGetWindowAttributes (display, clientMsg->window, &atts))
  196864. {
  196865. if (atts.map_state == IsViewable)
  196866. XSetInputFocus (display, clientMsg->window, RevertToParent, clientMsg->data.l[1]);
  196867. }
  196868. }
  196869. else if (atom == wm_ProtocolList [DELETE_WINDOW])
  196870. {
  196871. handleUserClosingWindow();
  196872. }
  196873. }
  196874. else if (clientMsg->message_type == XA_XdndEnter)
  196875. {
  196876. handleDragAndDropEnter (clientMsg);
  196877. }
  196878. else if (clientMsg->message_type == XA_XdndLeave)
  196879. {
  196880. resetDragAndDrop();
  196881. }
  196882. else if (clientMsg->message_type == XA_XdndPosition)
  196883. {
  196884. handleDragAndDropPosition (clientMsg);
  196885. }
  196886. else if (clientMsg->message_type == XA_XdndDrop)
  196887. {
  196888. handleDragAndDropDrop (clientMsg);
  196889. }
  196890. else if (clientMsg->message_type == XA_XdndStatus)
  196891. {
  196892. handleDragAndDropStatus (clientMsg);
  196893. }
  196894. else if (clientMsg->message_type == XA_XdndFinished)
  196895. {
  196896. resetDragAndDrop();
  196897. }
  196898. break;
  196899. }
  196900. case SelectionNotify:
  196901. handleDragAndDropSelection (event);
  196902. break;
  196903. case SelectionClear:
  196904. case SelectionRequest:
  196905. break;
  196906. default:
  196907. #if JUCE_USE_XSHM
  196908. {
  196909. ScopedXLock xlock;
  196910. if (event->xany.type == XShmGetEventBase (display))
  196911. repainter->notifyPaintCompleted();
  196912. }
  196913. #endif
  196914. break;
  196915. }
  196916. }
  196917. void showMouseCursor (Cursor cursor) throw()
  196918. {
  196919. ScopedXLock xlock;
  196920. XDefineCursor (display, windowH, cursor);
  196921. }
  196922. void setTaskBarIcon (const Image& image)
  196923. {
  196924. ScopedXLock xlock;
  196925. deleteTaskBarIcon();
  196926. taskbarImage = image.createCopy();
  196927. Screen* const screen = XDefaultScreenOfDisplay (display);
  196928. const int screenNumber = XScreenNumberOfScreen (screen);
  196929. String screenAtom ("_NET_SYSTEM_TRAY_S");
  196930. screenAtom << screenNumber;
  196931. Atom selectionAtom = XInternAtom (display, (const char*) screenAtom, false);
  196932. XGrabServer (display);
  196933. Window managerWin = XGetSelectionOwner (display, selectionAtom);
  196934. if (managerWin != None)
  196935. XSelectInput (display, managerWin, StructureNotifyMask);
  196936. XUngrabServer (display);
  196937. XFlush (display);
  196938. if (managerWin != None)
  196939. {
  196940. XEvent ev;
  196941. zerostruct (ev);
  196942. ev.xclient.type = ClientMessage;
  196943. ev.xclient.window = managerWin;
  196944. ev.xclient.message_type = XInternAtom (display, "_NET_SYSTEM_TRAY_OPCODE", False);
  196945. ev.xclient.format = 32;
  196946. ev.xclient.data.l[0] = CurrentTime;
  196947. ev.xclient.data.l[1] = SYSTEM_TRAY_REQUEST_DOCK;
  196948. ev.xclient.data.l[2] = windowH;
  196949. ev.xclient.data.l[3] = 0;
  196950. ev.xclient.data.l[4] = 0;
  196951. XSendEvent (display, managerWin, False, NoEventMask, &ev);
  196952. XSync (display, False);
  196953. }
  196954. // For older KDE's ...
  196955. long atomData = 1;
  196956. Atom trayAtom = XInternAtom (display, "KWM_DOCKWINDOW", false);
  196957. XChangeProperty (display, windowH, trayAtom, trayAtom, 32, PropModeReplace, (unsigned char*) &atomData, 1);
  196958. // For more recent KDE's...
  196959. trayAtom = XInternAtom (display, "_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR", false);
  196960. XChangeProperty (display, windowH, trayAtom, XA_WINDOW, 32, PropModeReplace, (unsigned char*) &windowH, 1);
  196961. // a minimum size must be specified for GNOME and Xfce, otherwise the icon is displayed with a width of 1
  196962. XSizeHints* hints = XAllocSizeHints();
  196963. hints->flags = PMinSize;
  196964. hints->min_width = 22;
  196965. hints->min_height = 22;
  196966. XSetWMNormalHints (display, windowH, hints);
  196967. XFree (hints);
  196968. }
  196969. void deleteTaskBarIcon()
  196970. {
  196971. deleteAndZero (taskbarImage);
  196972. }
  196973. const Image* getTaskbarIcon() const throw() { return taskbarImage; }
  196974. juce_UseDebuggingNewOperator
  196975. bool dontRepaint;
  196976. private:
  196977. class LinuxRepaintManager : public Timer
  196978. {
  196979. public:
  196980. LinuxRepaintManager (LinuxComponentPeer* const peer_)
  196981. : peer (peer_),
  196982. lastTimeImageUsed (0)
  196983. {
  196984. #if JUCE_USE_XSHM
  196985. shmCompletedDrawing = true;
  196986. useARGBImagesForRendering = isShmAvailable();
  196987. if (useARGBImagesForRendering)
  196988. {
  196989. ScopedXLock xlock;
  196990. XShmSegmentInfo segmentinfo;
  196991. XImage* const testImage
  196992. = XShmCreateImage (display, DefaultVisual (display, DefaultScreen (display)),
  196993. 24, ZPixmap, 0, &segmentinfo, 64, 64);
  196994. useARGBImagesForRendering = (testImage->bits_per_pixel == 32);
  196995. XDestroyImage (testImage);
  196996. }
  196997. #endif
  196998. }
  196999. ~LinuxRepaintManager()
  197000. {
  197001. }
  197002. void timerCallback()
  197003. {
  197004. #if JUCE_USE_XSHM
  197005. if (! shmCompletedDrawing)
  197006. return;
  197007. #endif
  197008. if (! regionsNeedingRepaint.isEmpty())
  197009. {
  197010. stopTimer();
  197011. performAnyPendingRepaintsNow();
  197012. }
  197013. else if (Time::getApproximateMillisecondCounter() > lastTimeImageUsed + 3000)
  197014. {
  197015. stopTimer();
  197016. image = 0;
  197017. }
  197018. }
  197019. void repaint (int x, int y, int w, int h)
  197020. {
  197021. if (! isTimerRunning())
  197022. startTimer (repaintTimerPeriod);
  197023. regionsNeedingRepaint.add (x, y, w, h);
  197024. }
  197025. void performAnyPendingRepaintsNow()
  197026. {
  197027. #if JUCE_USE_XSHM
  197028. if (! shmCompletedDrawing)
  197029. {
  197030. startTimer (repaintTimerPeriod);
  197031. return;
  197032. }
  197033. #endif
  197034. peer->clearMaskedRegion();
  197035. RectangleList originalRepaintRegion (regionsNeedingRepaint);
  197036. regionsNeedingRepaint.clear();
  197037. const Rectangle<int> totalArea (originalRepaintRegion.getBounds());
  197038. if (! totalArea.isEmpty())
  197039. {
  197040. if (image == 0 || image->getWidth() < totalArea.getWidth()
  197041. || image->getHeight() < totalArea.getHeight())
  197042. {
  197043. #if JUCE_USE_XSHM
  197044. image = new XBitmapImage (useARGBImagesForRendering ? Image::ARGB
  197045. : Image::RGB,
  197046. #else
  197047. image = new XBitmapImage (Image::RGB,
  197048. #endif
  197049. (totalArea.getWidth() + 31) & ~31,
  197050. (totalArea.getHeight() + 31) & ~31,
  197051. false,
  197052. peer->depthIs16Bit);
  197053. }
  197054. startTimer (repaintTimerPeriod);
  197055. LowLevelGraphicsSoftwareRenderer context (*image);
  197056. context.setOrigin (-totalArea.getX(), -totalArea.getY());
  197057. if (context.clipToRectangleList (originalRepaintRegion))
  197058. peer->handlePaint (context);
  197059. if (! peer->maskedRegion.isEmpty())
  197060. originalRepaintRegion.subtract (peer->maskedRegion);
  197061. for (RectangleList::Iterator i (originalRepaintRegion); i.next();)
  197062. {
  197063. #if JUCE_USE_XSHM
  197064. shmCompletedDrawing = false;
  197065. #endif
  197066. const Rectangle<int>& r = *i.getRectangle();
  197067. image->blitToWindow (peer->windowH,
  197068. r.getX(), r.getY(), r.getWidth(), r.getHeight(),
  197069. r.getX() - totalArea.getX(), r.getY() - totalArea.getY());
  197070. }
  197071. }
  197072. lastTimeImageUsed = Time::getApproximateMillisecondCounter();
  197073. startTimer (repaintTimerPeriod);
  197074. }
  197075. #if JUCE_USE_XSHM
  197076. void notifyPaintCompleted() { shmCompletedDrawing = true; }
  197077. #endif
  197078. private:
  197079. LinuxComponentPeer* const peer;
  197080. ScopedPointer <XBitmapImage> image;
  197081. uint32 lastTimeImageUsed;
  197082. RectangleList regionsNeedingRepaint;
  197083. #if JUCE_USE_XSHM
  197084. bool useARGBImagesForRendering, shmCompletedDrawing;
  197085. #endif
  197086. LinuxRepaintManager (const LinuxRepaintManager&);
  197087. const LinuxRepaintManager& operator= (const LinuxRepaintManager&);
  197088. };
  197089. ScopedPointer <LinuxRepaintManager> repainter;
  197090. friend class LinuxRepaintManager;
  197091. Window windowH, parentWindow;
  197092. int wx, wy, ww, wh;
  197093. Image* taskbarImage;
  197094. bool fullScreen, entered, mapped, depthIs16Bit;
  197095. BorderSize windowBorder;
  197096. struct MotifWmHints
  197097. {
  197098. unsigned long flags;
  197099. unsigned long functions;
  197100. unsigned long decorations;
  197101. long input_mode;
  197102. unsigned long status;
  197103. };
  197104. void removeWindowDecorations (Window wndH)
  197105. {
  197106. Atom hints = XInternAtom (display, "_MOTIF_WM_HINTS", True);
  197107. if (hints != None)
  197108. {
  197109. MotifWmHints motifHints;
  197110. zerostruct (motifHints);
  197111. motifHints.flags = 2; /* MWM_HINTS_DECORATIONS */
  197112. motifHints.decorations = 0;
  197113. ScopedXLock xlock;
  197114. XChangeProperty (display, wndH, hints, hints, 32, PropModeReplace,
  197115. (unsigned char*) &motifHints, 4);
  197116. }
  197117. hints = XInternAtom (display, "_WIN_HINTS", True);
  197118. if (hints != None)
  197119. {
  197120. long gnomeHints = 0;
  197121. ScopedXLock xlock;
  197122. XChangeProperty (display, wndH, hints, hints, 32, PropModeReplace,
  197123. (unsigned char*) &gnomeHints, 1);
  197124. }
  197125. hints = XInternAtom (display, "KWM_WIN_DECORATION", True);
  197126. if (hints != None)
  197127. {
  197128. long kwmHints = 2; /*KDE_tinyDecoration*/
  197129. ScopedXLock xlock;
  197130. XChangeProperty (display, wndH, hints, hints, 32, PropModeReplace,
  197131. (unsigned char*) &kwmHints, 1);
  197132. }
  197133. hints = XInternAtom (display, "_NET_WM_WINDOW_TYPE", True);
  197134. if (hints != None)
  197135. {
  197136. ScopedXLock xlock;
  197137. int netHints [2];
  197138. int numHints = 0;
  197139. if ((styleFlags & windowIsTemporary) != 0)
  197140. netHints [numHints] = XInternAtom (display, "_NET_WM_WINDOW_TYPE_MENU", True);
  197141. else
  197142. netHints [numHints] = XInternAtom (display, "_NET_WM_WINDOW_TYPE_NORMAL", True);
  197143. if (netHints [numHints] != 0)
  197144. ++numHints;
  197145. netHints[numHints] = XInternAtom (display, "_KDE_NET_WM_WINDOW_TYPE_OVERRIDE", True);
  197146. if (netHints [numHints] != 0)
  197147. ++numHints;
  197148. XChangeProperty (display, wndH, hints, XA_ATOM, 32, PropModeReplace,
  197149. (unsigned char*) &netHints, numHints);
  197150. }
  197151. }
  197152. void addWindowButtons (Window wndH)
  197153. {
  197154. ScopedXLock xlock;
  197155. Atom hints = XInternAtom (display, "_MOTIF_WM_HINTS", True);
  197156. if (hints != None)
  197157. {
  197158. MotifWmHints motifHints;
  197159. zerostruct (motifHints);
  197160. motifHints.flags = 1 | 2; /* MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS */
  197161. motifHints.decorations = 2 /* MWM_DECOR_BORDER */ | 8 /* MWM_DECOR_TITLE */ | 16; /* MWM_DECOR_MENU */
  197162. motifHints.functions = 4 /* MWM_FUNC_MOVE */;
  197163. if ((styleFlags & windowHasCloseButton) != 0)
  197164. motifHints.functions |= 32; /* MWM_FUNC_CLOSE */
  197165. if ((styleFlags & windowHasMinimiseButton) != 0)
  197166. {
  197167. motifHints.functions |= 8; /* MWM_FUNC_MINIMIZE */
  197168. motifHints.decorations |= 0x20; /* MWM_DECOR_MINIMIZE */
  197169. }
  197170. if ((styleFlags & windowHasMaximiseButton) != 0)
  197171. {
  197172. motifHints.functions |= 0x10; /* MWM_FUNC_MAXIMIZE */
  197173. motifHints.decorations |= 0x40; /* MWM_DECOR_MAXIMIZE */
  197174. }
  197175. if ((styleFlags & windowIsResizable) != 0)
  197176. {
  197177. motifHints.functions |= 2; /* MWM_FUNC_RESIZE */
  197178. motifHints.decorations |= 0x4; /* MWM_DECOR_RESIZEH */
  197179. }
  197180. XChangeProperty (display, wndH, hints, hints, 32, 0, (unsigned char*) &motifHints, 5);
  197181. }
  197182. hints = XInternAtom (display, "_NET_WM_ALLOWED_ACTIONS", True);
  197183. if (hints != None)
  197184. {
  197185. int netHints [6];
  197186. int num = 0;
  197187. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_RESIZE", (styleFlags & windowIsResizable) ? True : False);
  197188. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_FULLSCREEN", (styleFlags & windowHasMaximiseButton) ? True : False);
  197189. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_MINIMIZE", (styleFlags & windowHasMinimiseButton) ? True : False);
  197190. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_CLOSE", (styleFlags & windowHasCloseButton) ? True : False);
  197191. XChangeProperty (display, wndH, hints, XA_ATOM, 32, PropModeReplace,
  197192. (unsigned char*) &netHints, num);
  197193. }
  197194. }
  197195. void createWindow()
  197196. {
  197197. ScopedXLock xlock;
  197198. static bool atomsInitialised = false;
  197199. if (! atomsInitialised)
  197200. {
  197201. atomsInitialised = true;
  197202. wm_Protocols = XInternAtom (display, "WM_PROTOCOLS", 1);
  197203. wm_ProtocolList [TAKE_FOCUS] = XInternAtom (display, "WM_TAKE_FOCUS", 1);
  197204. wm_ProtocolList [DELETE_WINDOW] = XInternAtom (display, "WM_DELETE_WINDOW", 1);
  197205. wm_ChangeState = XInternAtom (display, "WM_CHANGE_STATE", 1);
  197206. wm_State = XInternAtom (display, "WM_STATE", 1);
  197207. wm_ActiveWin = XInternAtom (display, "_NET_ACTIVE_WINDOW", False);
  197208. XA_XdndAware = XInternAtom (display, "XdndAware", 0);
  197209. XA_XdndEnter = XInternAtom (display, "XdndEnter", 0);
  197210. XA_XdndLeave = XInternAtom (display, "XdndLeave", 0);
  197211. XA_XdndPosition = XInternAtom (display, "XdndPosition", 0);
  197212. XA_XdndStatus = XInternAtom (display, "XdndStatus", 0);
  197213. XA_XdndDrop = XInternAtom (display, "XdndDrop", 0);
  197214. XA_XdndFinished = XInternAtom (display, "XdndFinished", 0);
  197215. XA_XdndSelection = XInternAtom (display, "XdndSelection", 0);
  197216. XA_XdndProxy = XInternAtom (display, "XdndProxy", 0);
  197217. XA_XdndTypeList = XInternAtom (display, "XdndTypeList", 0);
  197218. XA_XdndActionList = XInternAtom (display, "XdndActionList", 0);
  197219. XA_XdndActionCopy = XInternAtom (display, "XdndActionCopy", 0);
  197220. XA_XdndActionMove = XInternAtom (display, "XdndActionMove", 0);
  197221. XA_XdndActionLink = XInternAtom (display, "XdndActionLink", 0);
  197222. XA_XdndActionAsk = XInternAtom (display, "XdndActionAsk", 0);
  197223. XA_XdndActionPrivate = XInternAtom (display, "XdndActionPrivate", 0);
  197224. XA_XdndActionDescription = XInternAtom (display, "XdndActionDescription", 0);
  197225. XA_JXSelectionWindowProperty = XInternAtom (display, "JXSelectionWindowProperty", 0);
  197226. XA_MimeTextPlain = XInternAtom (display, "text/plain", 0);
  197227. XA_MimeTextUriList = XInternAtom (display, "text/uri-list", 0);
  197228. XA_MimeRootDrop = XInternAtom (display, "application/x-rootwindow-drop", 0);
  197229. }
  197230. resetDragAndDrop();
  197231. XA_OtherMime = XA_MimeTextPlain; // xxx why??
  197232. allowedMimeTypeAtoms [0] = XA_MimeTextPlain;
  197233. allowedMimeTypeAtoms [1] = XA_OtherMime;
  197234. allowedMimeTypeAtoms [2] = XA_MimeTextUriList;
  197235. allowedActions [0] = XA_XdndActionMove;
  197236. allowedActions [1] = XA_XdndActionCopy;
  197237. allowedActions [2] = XA_XdndActionLink;
  197238. allowedActions [3] = XA_XdndActionAsk;
  197239. allowedActions [4] = XA_XdndActionPrivate;
  197240. // Get defaults for various properties
  197241. const int screen = DefaultScreen (display);
  197242. Window root = RootWindow (display, screen);
  197243. // Attempt to create a 24-bit window on the default screen. If this is not
  197244. // possible then exit
  197245. XVisualInfo desiredVisual;
  197246. desiredVisual.screen = screen;
  197247. desiredVisual.depth = 24;
  197248. depthIs16Bit = false;
  197249. int numVisuals;
  197250. XVisualInfo* visuals = XGetVisualInfo (display, VisualScreenMask | VisualDepthMask,
  197251. &desiredVisual, &numVisuals);
  197252. if (numVisuals < 1 || visuals == 0)
  197253. {
  197254. XFree (visuals);
  197255. desiredVisual.depth = 16;
  197256. visuals = XGetVisualInfo (display, VisualScreenMask | VisualDepthMask,
  197257. &desiredVisual, &numVisuals);
  197258. if (numVisuals < 1 || visuals == 0)
  197259. {
  197260. Logger::outputDebugString ("ERROR: System doesn't support 24 or 16 bit RGB display.\n");
  197261. Process::terminate();
  197262. }
  197263. depthIs16Bit = true;
  197264. }
  197265. XFree (visuals);
  197266. // Set up the window attributes
  197267. XSetWindowAttributes swa;
  197268. swa.border_pixel = 0;
  197269. swa.background_pixmap = None;
  197270. swa.colormap = DefaultColormap (display, screen);
  197271. swa.override_redirect = getComponent()->isAlwaysOnTop() ? True : False;
  197272. swa.event_mask = eventMask;
  197273. Window wndH = XCreateWindow (display, root,
  197274. 0, 0, 1, 1,
  197275. 0, 0, InputOutput, (Visual*) CopyFromParent,
  197276. CWBorderPixel | CWColormap | CWBackPixmap | CWEventMask | CWOverrideRedirect,
  197277. &swa);
  197278. XGrabButton (display, AnyButton, AnyModifier, wndH, False,
  197279. ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
  197280. GrabModeAsync, GrabModeAsync, None, None);
  197281. // Set the window context to identify the window handle object
  197282. if (XSaveContext (display, (XID) wndH, improbableNumber, (XPointer) this))
  197283. {
  197284. // Failed
  197285. jassertfalse
  197286. Logger::outputDebugString ("Failed to create context information for window.\n");
  197287. XDestroyWindow (display, wndH);
  197288. wndH = 0;
  197289. }
  197290. // Set window manager hints
  197291. XWMHints* wmHints = XAllocWMHints();
  197292. wmHints->flags = InputHint | StateHint;
  197293. wmHints->input = True; // Locally active input model
  197294. wmHints->initial_state = NormalState;
  197295. XSetWMHints (display, wndH, wmHints);
  197296. XFree (wmHints);
  197297. if ((styleFlags & windowIsSemiTransparent) != 0)
  197298. {
  197299. //xxx
  197300. }
  197301. if ((styleFlags & windowAppearsOnTaskbar) != 0)
  197302. {
  197303. //xxx
  197304. }
  197305. //XSetTransientForHint (display, wndH, RootWindow (display, DefaultScreen (display)));
  197306. if ((styleFlags & windowHasTitleBar) == 0)
  197307. removeWindowDecorations (wndH);
  197308. else
  197309. addWindowButtons (wndH);
  197310. // Set window manager protocols
  197311. XChangeProperty (display, wndH, wm_Protocols, XA_ATOM, 32, PropModeReplace,
  197312. (unsigned char*) wm_ProtocolList, 2);
  197313. // Set drag and drop flags
  197314. XChangeProperty (display, wndH, XA_XdndTypeList, XA_ATOM, 32, PropModeReplace,
  197315. (const unsigned char*) allowedMimeTypeAtoms, numElementsInArray (allowedMimeTypeAtoms));
  197316. XChangeProperty (display, wndH, XA_XdndActionList, XA_ATOM, 32, PropModeReplace,
  197317. (const unsigned char*) allowedActions, numElementsInArray (allowedActions));
  197318. XChangeProperty (display, wndH, XA_XdndActionDescription, XA_STRING, 8, PropModeReplace,
  197319. (const unsigned char*) "", 0);
  197320. unsigned long dndVersion = ourDndVersion;
  197321. XChangeProperty (display, wndH, XA_XdndAware, XA_ATOM, 32, PropModeReplace,
  197322. (const unsigned char*) &dndVersion, 1);
  197323. // Set window name
  197324. setWindowTitle (wndH, getComponent()->getName());
  197325. // Initialise the pointer and keyboard mapping
  197326. // This is not the same as the logical pointer mapping the X server uses:
  197327. // we don't mess with this.
  197328. static bool mappingInitialised = false;
  197329. if (! mappingInitialised)
  197330. {
  197331. mappingInitialised = true;
  197332. const int numButtons = XGetPointerMapping (display, 0, 0);
  197333. if (numButtons == 2)
  197334. {
  197335. pointerMap[0] = LeftButton;
  197336. pointerMap[1] = RightButton;
  197337. pointerMap[2] = pointerMap[3] = pointerMap[4] = NoButton;
  197338. }
  197339. else if (numButtons >= 3)
  197340. {
  197341. pointerMap[0] = LeftButton;
  197342. pointerMap[1] = MiddleButton;
  197343. pointerMap[2] = RightButton;
  197344. if (numButtons >= 5)
  197345. {
  197346. pointerMap[3] = WheelUp;
  197347. pointerMap[4] = WheelDown;
  197348. }
  197349. }
  197350. getModifierMapping();
  197351. }
  197352. windowH = wndH;
  197353. }
  197354. void destroyWindow()
  197355. {
  197356. ScopedXLock xlock;
  197357. XPointer handlePointer;
  197358. if (! XFindContext (display, (XID) windowH, improbableNumber, &handlePointer))
  197359. XDeleteContext (display, (XID) windowH, improbableNumber);
  197360. XDestroyWindow (display, windowH);
  197361. // Wait for it to complete and then remove any events for this
  197362. // window from the event queue.
  197363. XSync (display, false);
  197364. XEvent event;
  197365. while (XCheckWindowEvent (display, windowH, eventMask, &event) == True)
  197366. {}
  197367. }
  197368. static int64 getEventTime (::Time t) throw()
  197369. {
  197370. static int64 eventTimeOffset = 0x12345678;
  197371. const int64 thisMessageTime = t;
  197372. if (eventTimeOffset == 0x12345678)
  197373. eventTimeOffset = Time::currentTimeMillis() - thisMessageTime;
  197374. return eventTimeOffset + thisMessageTime;
  197375. }
  197376. static void setWindowTitle (Window xwin, const char* const title) throw()
  197377. {
  197378. XTextProperty nameProperty;
  197379. char* strings[] = { (char*) title };
  197380. ScopedXLock xlock;
  197381. if (XStringListToTextProperty (strings, 1, &nameProperty))
  197382. {
  197383. XSetWMName (display, xwin, &nameProperty);
  197384. XSetWMIconName (display, xwin, &nameProperty);
  197385. XFree (nameProperty.value);
  197386. }
  197387. }
  197388. void updateBorderSize()
  197389. {
  197390. if ((styleFlags & windowHasTitleBar) == 0)
  197391. {
  197392. windowBorder = BorderSize (0);
  197393. }
  197394. else if (windowBorder.getTopAndBottom() == 0 && windowBorder.getLeftAndRight() == 0)
  197395. {
  197396. ScopedXLock xlock;
  197397. Atom hints = XInternAtom (display, "_NET_FRAME_EXTENTS", True);
  197398. if (hints != None)
  197399. {
  197400. unsigned char* data = 0;
  197401. unsigned long nitems, bytesLeft;
  197402. Atom actualType;
  197403. int actualFormat;
  197404. if (XGetWindowProperty (display, windowH, hints, 0, 4, False,
  197405. XA_CARDINAL, &actualType, &actualFormat, &nitems, &bytesLeft,
  197406. &data) == Success)
  197407. {
  197408. const unsigned long* const sizes = (const unsigned long*) data;
  197409. if (actualFormat == 32)
  197410. windowBorder = BorderSize ((int) sizes[2], (int) sizes[0],
  197411. (int) sizes[3], (int) sizes[1]);
  197412. XFree (data);
  197413. }
  197414. }
  197415. }
  197416. }
  197417. void updateBounds()
  197418. {
  197419. jassert (windowH != 0);
  197420. if (windowH != 0)
  197421. {
  197422. Window root, child;
  197423. unsigned int bw, depth;
  197424. ScopedXLock xlock;
  197425. if (! XGetGeometry (display, (::Drawable) windowH, &root,
  197426. &wx, &wy, (unsigned int*) &ww, (unsigned int*) &wh,
  197427. &bw, &depth))
  197428. {
  197429. wx = wy = ww = wh = 0;
  197430. }
  197431. else if (! XTranslateCoordinates (display, windowH, root, 0, 0, &wx, &wy, &child))
  197432. {
  197433. wx = wy = 0;
  197434. }
  197435. }
  197436. }
  197437. void resetDragAndDrop()
  197438. {
  197439. dragAndDropFiles.clear();
  197440. lastDropX = lastDropY = -1;
  197441. dragAndDropCurrentMimeType = 0;
  197442. dragAndDropSourceWindow = 0;
  197443. srcMimeTypeAtomList.clear();
  197444. }
  197445. void sendDragAndDropMessage (XClientMessageEvent& msg)
  197446. {
  197447. msg.type = ClientMessage;
  197448. msg.display = display;
  197449. msg.window = dragAndDropSourceWindow;
  197450. msg.format = 32;
  197451. msg.data.l[0] = windowH;
  197452. ScopedXLock xlock;
  197453. XSendEvent (display, dragAndDropSourceWindow, False, 0, (XEvent*) &msg);
  197454. }
  197455. void sendDragAndDropStatus (const bool acceptDrop, Atom dropAction)
  197456. {
  197457. XClientMessageEvent msg;
  197458. zerostruct (msg);
  197459. msg.message_type = XA_XdndStatus;
  197460. msg.data.l[1] = (acceptDrop ? 1 : 0) | 2; // 2 indicates that we want to receive position messages
  197461. msg.data.l[4] = dropAction;
  197462. sendDragAndDropMessage (msg);
  197463. }
  197464. void sendDragAndDropLeave()
  197465. {
  197466. XClientMessageEvent msg;
  197467. zerostruct (msg);
  197468. msg.message_type = XA_XdndLeave;
  197469. sendDragAndDropMessage (msg);
  197470. }
  197471. void sendDragAndDropFinish()
  197472. {
  197473. XClientMessageEvent msg;
  197474. zerostruct (msg);
  197475. msg.message_type = XA_XdndFinished;
  197476. sendDragAndDropMessage (msg);
  197477. }
  197478. void handleDragAndDropStatus (const XClientMessageEvent* const clientMsg)
  197479. {
  197480. if ((clientMsg->data.l[1] & 1) == 0)
  197481. {
  197482. sendDragAndDropLeave();
  197483. if (dragAndDropFiles.size() > 0)
  197484. handleFileDragExit (dragAndDropFiles);
  197485. dragAndDropFiles.clear();
  197486. }
  197487. }
  197488. void handleDragAndDropPosition (const XClientMessageEvent* const clientMsg)
  197489. {
  197490. if (dragAndDropSourceWindow == 0)
  197491. return;
  197492. dragAndDropSourceWindow = clientMsg->data.l[0];
  197493. const int dropX = ((int) clientMsg->data.l[2] >> 16) - getScreenX();
  197494. const int dropY = ((int) clientMsg->data.l[2] & 0xffff) - getScreenY();
  197495. if (lastDropX != dropX || lastDropY != dropY)
  197496. {
  197497. lastDropX = dropX;
  197498. lastDropY = dropY;
  197499. dragAndDropTimestamp = clientMsg->data.l[3];
  197500. Atom targetAction = XA_XdndActionCopy;
  197501. for (int i = numElementsInArray (allowedActions); --i >= 0;)
  197502. {
  197503. if ((Atom) clientMsg->data.l[4] == allowedActions[i])
  197504. {
  197505. targetAction = allowedActions[i];
  197506. break;
  197507. }
  197508. }
  197509. sendDragAndDropStatus (true, targetAction);
  197510. if (dragAndDropFiles.size() == 0)
  197511. updateDraggedFileList (clientMsg);
  197512. if (dragAndDropFiles.size() > 0)
  197513. handleFileDragMove (dragAndDropFiles, dropX, dropY);
  197514. }
  197515. }
  197516. void handleDragAndDropDrop (const XClientMessageEvent* const clientMsg)
  197517. {
  197518. if (dragAndDropFiles.size() == 0)
  197519. updateDraggedFileList (clientMsg);
  197520. const StringArray files (dragAndDropFiles);
  197521. const int lastX = lastDropX, lastY = lastDropY;
  197522. sendDragAndDropFinish();
  197523. resetDragAndDrop();
  197524. if (files.size() > 0)
  197525. handleFileDragDrop (files, lastX, lastY);
  197526. }
  197527. void handleDragAndDropEnter (const XClientMessageEvent* const clientMsg)
  197528. {
  197529. dragAndDropFiles.clear();
  197530. srcMimeTypeAtomList.clear();
  197531. dragAndDropCurrentMimeType = 0;
  197532. const int dndCurrentVersion = (int) (clientMsg->data.l[1] & 0xff000000) >> 24;
  197533. if (dndCurrentVersion < 3 || dndCurrentVersion > ourDndVersion)
  197534. {
  197535. dragAndDropSourceWindow = 0;
  197536. return;
  197537. }
  197538. dragAndDropSourceWindow = clientMsg->data.l[0];
  197539. if ((clientMsg->data.l[1] & 1) != 0)
  197540. {
  197541. Atom actual;
  197542. int format;
  197543. unsigned long count = 0, remaining = 0;
  197544. unsigned char* data = 0;
  197545. ScopedXLock xlock;
  197546. XGetWindowProperty (display, dragAndDropSourceWindow, XA_XdndTypeList,
  197547. 0, 0x8000000L, False, XA_ATOM, &actual, &format,
  197548. &count, &remaining, &data);
  197549. if (data != 0)
  197550. {
  197551. if (actual == XA_ATOM && format == 32 && count != 0)
  197552. {
  197553. const unsigned long* const types = (const unsigned long*) data;
  197554. for (unsigned int i = 0; i < count; ++i)
  197555. if (types[i] != None)
  197556. srcMimeTypeAtomList.add (types[i]);
  197557. }
  197558. XFree (data);
  197559. }
  197560. }
  197561. if (srcMimeTypeAtomList.size() == 0)
  197562. {
  197563. for (int i = 2; i < 5; ++i)
  197564. if (clientMsg->data.l[i] != None)
  197565. srcMimeTypeAtomList.add (clientMsg->data.l[i]);
  197566. if (srcMimeTypeAtomList.size() == 0)
  197567. {
  197568. dragAndDropSourceWindow = 0;
  197569. return;
  197570. }
  197571. }
  197572. for (int i = 0; i < srcMimeTypeAtomList.size() && dragAndDropCurrentMimeType == 0; ++i)
  197573. for (int j = 0; j < numElementsInArray (allowedMimeTypeAtoms); ++j)
  197574. if (srcMimeTypeAtomList[i] == allowedMimeTypeAtoms[j])
  197575. dragAndDropCurrentMimeType = allowedMimeTypeAtoms[j];
  197576. handleDragAndDropPosition (clientMsg);
  197577. }
  197578. void handleDragAndDropSelection (const XEvent* const evt)
  197579. {
  197580. dragAndDropFiles.clear();
  197581. if (evt->xselection.property != 0)
  197582. {
  197583. StringArray lines;
  197584. {
  197585. MemoryBlock dropData;
  197586. for (;;)
  197587. {
  197588. Atom actual;
  197589. uint8* data = 0;
  197590. unsigned long count = 0, remaining = 0;
  197591. int format = 0;
  197592. ScopedXLock xlock;
  197593. if (XGetWindowProperty (display, evt->xany.window, evt->xselection.property,
  197594. dropData.getSize() / 4, 65536, 1, AnyPropertyType, &actual,
  197595. &format, &count, &remaining, &data) == Success)
  197596. {
  197597. dropData.append (data, count * format / 8);
  197598. XFree (data);
  197599. if (remaining == 0)
  197600. break;
  197601. }
  197602. else
  197603. {
  197604. XFree (data);
  197605. break;
  197606. }
  197607. }
  197608. lines.addLines (dropData.toString());
  197609. }
  197610. for (int i = 0; i < lines.size(); ++i)
  197611. dragAndDropFiles.add (URL::removeEscapeChars (lines[i].fromFirstOccurrenceOf (T("file://"), false, true)));
  197612. dragAndDropFiles.trim();
  197613. dragAndDropFiles.removeEmptyStrings();
  197614. }
  197615. }
  197616. void updateDraggedFileList (const XClientMessageEvent* const clientMsg)
  197617. {
  197618. dragAndDropFiles.clear();
  197619. if (dragAndDropSourceWindow != None
  197620. && dragAndDropCurrentMimeType != 0)
  197621. {
  197622. dragAndDropTimestamp = clientMsg->data.l[2];
  197623. ScopedXLock xlock;
  197624. XConvertSelection (display,
  197625. XA_XdndSelection,
  197626. dragAndDropCurrentMimeType,
  197627. XA_JXSelectionWindowProperty,
  197628. windowH,
  197629. dragAndDropTimestamp);
  197630. }
  197631. }
  197632. StringArray dragAndDropFiles;
  197633. int dragAndDropTimestamp, lastDropX, lastDropY;
  197634. Atom XA_OtherMime, dragAndDropCurrentMimeType;
  197635. Window dragAndDropSourceWindow;
  197636. unsigned int allowedActions [5];
  197637. unsigned int allowedMimeTypeAtoms [3];
  197638. Array <Atom> srcMimeTypeAtomList;
  197639. };
  197640. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  197641. {
  197642. if (enableOrDisable)
  197643. kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));
  197644. }
  197645. ComponentPeer* Component::createNewPeer (int styleFlags, void* /*nativeWindowToAttachTo*/)
  197646. {
  197647. return new LinuxComponentPeer (this, styleFlags);
  197648. }
  197649. // (this callback is hooked up in the messaging code)
  197650. void juce_windowMessageReceive (XEvent* event)
  197651. {
  197652. if (event->xany.window != None)
  197653. {
  197654. LinuxComponentPeer* const peer = LinuxComponentPeer::getPeerFor (event->xany.window);
  197655. if (ComponentPeer::isValidPeer (peer))
  197656. peer->handleWindowMessage (event);
  197657. }
  197658. else
  197659. {
  197660. switch (event->xany.type)
  197661. {
  197662. case KeymapNotify:
  197663. {
  197664. const XKeymapEvent* const keymapEvent = (const XKeymapEvent*) &event->xkeymap;
  197665. memcpy (keyStates, keymapEvent->key_vector, 32);
  197666. break;
  197667. }
  197668. default:
  197669. break;
  197670. }
  197671. }
  197672. }
  197673. void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords, const bool /*clipToWorkArea*/)
  197674. {
  197675. if (display == 0)
  197676. return;
  197677. #if JUCE_USE_XINERAMA
  197678. int major_opcode, first_event, first_error;
  197679. ScopedXLock xlock;
  197680. if (XQueryExtension (display, "XINERAMA", &major_opcode, &first_event, &first_error))
  197681. {
  197682. typedef Bool (*tXineramaIsActive) (Display*);
  197683. typedef XineramaScreenInfo* (*tXineramaQueryScreens) (Display*, int*);
  197684. static tXineramaIsActive xXineramaIsActive = 0;
  197685. static tXineramaQueryScreens xXineramaQueryScreens = 0;
  197686. if (xXineramaIsActive == 0 || xXineramaQueryScreens == 0)
  197687. {
  197688. void* h = dlopen ("libXinerama.so", RTLD_GLOBAL | RTLD_NOW);
  197689. if (h != 0)
  197690. {
  197691. xXineramaIsActive = (tXineramaIsActive) dlsym (h, "XineramaIsActive");
  197692. xXineramaQueryScreens = (tXineramaQueryScreens) dlsym (h, "XineramaQueryScreens");
  197693. }
  197694. }
  197695. if (xXineramaIsActive != 0
  197696. && xXineramaQueryScreens != 0
  197697. && xXineramaIsActive (display))
  197698. {
  197699. int numMonitors = 0;
  197700. XineramaScreenInfo* const screens = xXineramaQueryScreens (display, &numMonitors);
  197701. if (screens != 0)
  197702. {
  197703. for (int i = numMonitors; --i >= 0;)
  197704. {
  197705. int index = screens[i].screen_number;
  197706. if (index >= 0)
  197707. {
  197708. while (monitorCoords.size() < index)
  197709. monitorCoords.add (Rectangle<int>());
  197710. monitorCoords.set (index, Rectangle<int> (screens[i].x_org,
  197711. screens[i].y_org,
  197712. screens[i].width,
  197713. screens[i].height));
  197714. }
  197715. }
  197716. XFree (screens);
  197717. }
  197718. }
  197719. }
  197720. if (monitorCoords.size() == 0)
  197721. #endif
  197722. {
  197723. Atom hints = XInternAtom (display, "_NET_WORKAREA", True);
  197724. if (hints != None)
  197725. {
  197726. const int numMonitors = ScreenCount (display);
  197727. for (int i = 0; i < numMonitors; ++i)
  197728. {
  197729. Window root = RootWindow (display, i);
  197730. unsigned long nitems, bytesLeft;
  197731. Atom actualType;
  197732. int actualFormat;
  197733. unsigned char* data = 0;
  197734. if (XGetWindowProperty (display, root, hints, 0, 4, False,
  197735. XA_CARDINAL, &actualType, &actualFormat, &nitems, &bytesLeft,
  197736. &data) == Success)
  197737. {
  197738. const long* const position = (const long*) data;
  197739. if (actualType == XA_CARDINAL && actualFormat == 32 && nitems == 4)
  197740. monitorCoords.add (Rectangle<int> (position[0], position[1],
  197741. position[2], position[3]));
  197742. XFree (data);
  197743. }
  197744. }
  197745. }
  197746. if (monitorCoords.size() == 0)
  197747. {
  197748. monitorCoords.add (Rectangle<int> (0, 0,
  197749. DisplayWidth (display, DefaultScreen (display)),
  197750. DisplayHeight (display, DefaultScreen (display))));
  197751. }
  197752. }
  197753. }
  197754. bool Desktop::canUseSemiTransparentWindows() throw()
  197755. {
  197756. return false;
  197757. }
  197758. void Desktop::getMousePosition (int& x, int& y) throw()
  197759. {
  197760. int mouseMods;
  197761. getMousePos (x, y, mouseMods);
  197762. }
  197763. void Desktop::setMousePosition (int x, int y) throw()
  197764. {
  197765. ScopedXLock xlock;
  197766. Window root = RootWindow (display, DefaultScreen (display));
  197767. XWarpPointer (display, None, root, 0, 0, 0, 0, x, y);
  197768. }
  197769. static bool screenSaverAllowed = true;
  197770. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  197771. {
  197772. if (screenSaverAllowed != isEnabled)
  197773. {
  197774. screenSaverAllowed = isEnabled;
  197775. typedef void (*tXScreenSaverSuspend) (Display*, Bool);
  197776. static tXScreenSaverSuspend xScreenSaverSuspend = 0;
  197777. if (xScreenSaverSuspend == 0)
  197778. {
  197779. void* h = dlopen ("libXss.so", RTLD_GLOBAL | RTLD_NOW);
  197780. if (h != 0)
  197781. xScreenSaverSuspend = (tXScreenSaverSuspend) dlsym (h, "XScreenSaverSuspend");
  197782. }
  197783. ScopedXLock xlock;
  197784. if (xScreenSaverSuspend != 0)
  197785. xScreenSaverSuspend (display, ! isEnabled);
  197786. }
  197787. }
  197788. bool Desktop::isScreenSaverEnabled() throw()
  197789. {
  197790. return screenSaverAllowed;
  197791. }
  197792. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  197793. {
  197794. ScopedXLock xlock;
  197795. Window root = RootWindow (display, DefaultScreen (display));
  197796. const unsigned int imageW = image.getWidth();
  197797. const unsigned int imageH = image.getHeight();
  197798. unsigned int cursorW, cursorH;
  197799. if (! XQueryBestCursor (display, root, imageW, imageH, &cursorW, &cursorH))
  197800. return 0;
  197801. Image im (Image::ARGB, cursorW, cursorH, true);
  197802. Graphics g (im);
  197803. if (imageW > cursorW || imageH > cursorH)
  197804. {
  197805. hotspotX = (hotspotX * cursorW) / imageW;
  197806. hotspotY = (hotspotY * cursorH) / imageH;
  197807. g.drawImageWithin (&image, 0, 0, imageW, imageH,
  197808. RectanglePlacement::xLeft | RectanglePlacement::yTop | RectanglePlacement::onlyReduceInSize,
  197809. false);
  197810. }
  197811. else
  197812. {
  197813. g.drawImageAt (&image, 0, 0);
  197814. }
  197815. const int stride = (cursorW + 7) >> 3;
  197816. HeapBlock <uint8> maskPlane, sourcePlane;
  197817. maskPlane.calloc (stride * cursorH);
  197818. sourcePlane.calloc (stride * cursorH);
  197819. const bool msbfirst = (BitmapBitOrder (display) == MSBFirst);
  197820. for (int y = cursorH; --y >= 0;)
  197821. {
  197822. for (int x = cursorW; --x >= 0;)
  197823. {
  197824. const uint8 mask = (uint8) (1 << (msbfirst ? (7 - (x & 7)) : (x & 7)));
  197825. const int offset = y * stride + (x >> 3);
  197826. const Colour c (im.getPixelAt (x, y));
  197827. if (c.getAlpha() >= 128)
  197828. maskPlane[offset] |= mask;
  197829. if (c.getBrightness() >= 0.5f)
  197830. sourcePlane[offset] |= mask;
  197831. }
  197832. }
  197833. Pixmap sourcePixmap = XCreatePixmapFromBitmapData (display, root, (char*) sourcePlane, cursorW, cursorH, 0xffff, 0, 1);
  197834. Pixmap maskPixmap = XCreatePixmapFromBitmapData (display, root, (char*) maskPlane, cursorW, cursorH, 0xffff, 0, 1);
  197835. XColor white, black;
  197836. black.red = black.green = black.blue = 0;
  197837. white.red = white.green = white.blue = 0xffff;
  197838. void* result = (void*) XCreatePixmapCursor (display, sourcePixmap, maskPixmap, &white, &black, hotspotX, hotspotY);
  197839. XFreePixmap (display, sourcePixmap);
  197840. XFreePixmap (display, maskPixmap);
  197841. return result;
  197842. }
  197843. void juce_deleteMouseCursor (void* const cursorHandle, const bool) throw()
  197844. {
  197845. ScopedXLock xlock;
  197846. if (cursorHandle != None)
  197847. XFreeCursor (display, (Cursor) cursorHandle);
  197848. }
  197849. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  197850. {
  197851. unsigned int shape;
  197852. switch (type)
  197853. {
  197854. case MouseCursor::NoCursor:
  197855. {
  197856. const Image im (Image::ARGB, 16, 16, true);
  197857. return juce_createMouseCursorFromImage (im, 0, 0);
  197858. }
  197859. case MouseCursor::NormalCursor:
  197860. return (void*) None; // Use parent cursor
  197861. case MouseCursor::DraggingHandCursor:
  197862. {
  197863. static unsigned char dragHandData[] = {71,73,70,56,57,97,16,0,16,0,145,2,0,0,0,0,255,255,255,0,
  197864. 0,0,0,0,0,33,249,4,1,0,0,2,0,44,0,0,0,0,16,0,
  197865. 16,0,0,2,52,148,47,0,200,185,16,130,90,12,74,139,107,84,123,39,
  197866. 132,117,151,116,132,146,248,60,209,138,98,22,203,114,34,236,37,52,77,217,
  197867. 247,154,191,119,110,240,193,128,193,95,163,56,60,234,98,135,2,0,59 };
  197868. const int dragHandDataSize = 99;
  197869. const ScopedPointer <Image> im (ImageFileFormat::loadFrom ((const char*) dragHandData, dragHandDataSize));
  197870. return juce_createMouseCursorFromImage (*im, 8, 7);
  197871. }
  197872. case MouseCursor::CopyingCursor:
  197873. {
  197874. static unsigned char copyCursorData[] = {71,73,70,56,57,97,21,0,21,0,145,0,0,0,0,0,255,255,255,0,
  197875. 128,128,255,255,255,33,249,4,1,0,0,3,0,44,0,0,0,0,21,0,
  197876. 21,0,0,2,72,4,134,169,171,16,199,98,11,79,90,71,161,93,56,111,
  197877. 78,133,218,215,137,31,82,154,100,200,86,91,202,142,12,108,212,87,235,174,
  197878. 15,54,214,126,237,226,37,96,59,141,16,37,18,201,142,157,230,204,51,112,
  197879. 252,114,147,74,83,5,50,68,147,208,217,16,71,149,252,124,5,0,59,0,0 };
  197880. const int copyCursorSize = 119;
  197881. const ScopedPointer <Image> im (ImageFileFormat::loadFrom ((const char*) copyCursorData, copyCursorSize));
  197882. return juce_createMouseCursorFromImage (*im, 1, 3);
  197883. }
  197884. case MouseCursor::WaitCursor:
  197885. shape = XC_watch;
  197886. break;
  197887. case MouseCursor::IBeamCursor:
  197888. shape = XC_xterm;
  197889. break;
  197890. case MouseCursor::PointingHandCursor:
  197891. shape = XC_hand2;
  197892. break;
  197893. case MouseCursor::LeftRightResizeCursor:
  197894. shape = XC_sb_h_double_arrow;
  197895. break;
  197896. case MouseCursor::UpDownResizeCursor:
  197897. shape = XC_sb_v_double_arrow;
  197898. break;
  197899. case MouseCursor::UpDownLeftRightResizeCursor:
  197900. shape = XC_fleur;
  197901. break;
  197902. case MouseCursor::TopEdgeResizeCursor:
  197903. shape = XC_top_side;
  197904. break;
  197905. case MouseCursor::BottomEdgeResizeCursor:
  197906. shape = XC_bottom_side;
  197907. break;
  197908. case MouseCursor::LeftEdgeResizeCursor:
  197909. shape = XC_left_side;
  197910. break;
  197911. case MouseCursor::RightEdgeResizeCursor:
  197912. shape = XC_right_side;
  197913. break;
  197914. case MouseCursor::TopLeftCornerResizeCursor:
  197915. shape = XC_top_left_corner;
  197916. break;
  197917. case MouseCursor::TopRightCornerResizeCursor:
  197918. shape = XC_top_right_corner;
  197919. break;
  197920. case MouseCursor::BottomLeftCornerResizeCursor:
  197921. shape = XC_bottom_left_corner;
  197922. break;
  197923. case MouseCursor::BottomRightCornerResizeCursor:
  197924. shape = XC_bottom_right_corner;
  197925. break;
  197926. case MouseCursor::CrosshairCursor:
  197927. shape = XC_crosshair;
  197928. break;
  197929. default:
  197930. return (void*) None; // Use parent cursor
  197931. }
  197932. ScopedXLock xlock;
  197933. return (void*) XCreateFontCursor (display, shape);
  197934. }
  197935. void MouseCursor::showInWindow (ComponentPeer* peer) const throw()
  197936. {
  197937. LinuxComponentPeer* const lp = dynamic_cast <LinuxComponentPeer*> (peer);
  197938. if (lp != 0)
  197939. lp->showMouseCursor ((Cursor) getHandle());
  197940. }
  197941. void MouseCursor::showInAllWindows() const throw()
  197942. {
  197943. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  197944. showInWindow (ComponentPeer::getPeer (i));
  197945. }
  197946. Image* juce_createIconForFile (const File& file)
  197947. {
  197948. return 0;
  197949. }
  197950. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  197951. {
  197952. return new Image (format, imageWidth, imageHeight, clearImage);
  197953. }
  197954. #if JUCE_OPENGL
  197955. class WindowedGLContext : public OpenGLContext
  197956. {
  197957. public:
  197958. WindowedGLContext (Component* const component,
  197959. const OpenGLPixelFormat& pixelFormat_,
  197960. GLXContext sharedContext)
  197961. : renderContext (0),
  197962. embeddedWindow (0),
  197963. pixelFormat (pixelFormat_)
  197964. {
  197965. jassert (component != 0);
  197966. LinuxComponentPeer* const peer = dynamic_cast <LinuxComponentPeer*> (component->getTopLevelComponent()->getPeer());
  197967. if (peer == 0)
  197968. return;
  197969. ScopedXLock xlock;
  197970. XSync (display, False);
  197971. GLint attribs [64];
  197972. int n = 0;
  197973. attribs[n++] = GLX_RGBA;
  197974. attribs[n++] = GLX_DOUBLEBUFFER;
  197975. attribs[n++] = GLX_RED_SIZE;
  197976. attribs[n++] = pixelFormat.redBits;
  197977. attribs[n++] = GLX_GREEN_SIZE;
  197978. attribs[n++] = pixelFormat.greenBits;
  197979. attribs[n++] = GLX_BLUE_SIZE;
  197980. attribs[n++] = pixelFormat.blueBits;
  197981. attribs[n++] = GLX_ALPHA_SIZE;
  197982. attribs[n++] = pixelFormat.alphaBits;
  197983. attribs[n++] = GLX_DEPTH_SIZE;
  197984. attribs[n++] = pixelFormat.depthBufferBits;
  197985. attribs[n++] = GLX_STENCIL_SIZE;
  197986. attribs[n++] = pixelFormat.stencilBufferBits;
  197987. attribs[n++] = GLX_ACCUM_RED_SIZE;
  197988. attribs[n++] = pixelFormat.accumulationBufferRedBits;
  197989. attribs[n++] = GLX_ACCUM_GREEN_SIZE;
  197990. attribs[n++] = pixelFormat.accumulationBufferGreenBits;
  197991. attribs[n++] = GLX_ACCUM_BLUE_SIZE;
  197992. attribs[n++] = pixelFormat.accumulationBufferBlueBits;
  197993. attribs[n++] = GLX_ACCUM_ALPHA_SIZE;
  197994. attribs[n++] = pixelFormat.accumulationBufferAlphaBits;
  197995. // xxx not sure how to do fullSceneAntiAliasingNumSamples on linux..
  197996. attribs[n++] = None;
  197997. XVisualInfo* const bestVisual = glXChooseVisual (display, DefaultScreen (display), attribs);
  197998. if (bestVisual == 0)
  197999. return;
  198000. renderContext = glXCreateContext (display, bestVisual, sharedContext, GL_TRUE);
  198001. Window windowH = (Window) peer->getNativeHandle();
  198002. Colormap colourMap = XCreateColormap (display, windowH, bestVisual->visual, AllocNone);
  198003. XSetWindowAttributes swa;
  198004. swa.colormap = colourMap;
  198005. swa.border_pixel = 0;
  198006. swa.event_mask = ExposureMask | StructureNotifyMask;
  198007. embeddedWindow = XCreateWindow (display, windowH,
  198008. 0, 0, 1, 1, 0,
  198009. bestVisual->depth,
  198010. InputOutput,
  198011. bestVisual->visual,
  198012. CWBorderPixel | CWColormap | CWEventMask,
  198013. &swa);
  198014. XSaveContext (display, (XID) embeddedWindow, improbableNumber, (XPointer) peer);
  198015. XMapWindow (display, embeddedWindow);
  198016. XFreeColormap (display, colourMap);
  198017. XFree (bestVisual);
  198018. XSync (display, False);
  198019. }
  198020. ~WindowedGLContext()
  198021. {
  198022. makeInactive();
  198023. ScopedXLock xlock;
  198024. glXDestroyContext (display, renderContext);
  198025. XUnmapWindow (display, embeddedWindow);
  198026. XDestroyWindow (display, embeddedWindow);
  198027. }
  198028. bool makeActive() const throw()
  198029. {
  198030. jassert (renderContext != 0);
  198031. ScopedXLock xlock;
  198032. return glXMakeCurrent (display, embeddedWindow, renderContext)
  198033. && XSync (display, False);
  198034. }
  198035. bool makeInactive() const throw()
  198036. {
  198037. ScopedXLock xlock;
  198038. return (! isActive()) || glXMakeCurrent (display, None, 0);
  198039. }
  198040. bool isActive() const throw()
  198041. {
  198042. ScopedXLock xlock;
  198043. return glXGetCurrentContext() == renderContext;
  198044. }
  198045. const OpenGLPixelFormat getPixelFormat() const
  198046. {
  198047. return pixelFormat;
  198048. }
  198049. void* getRawContext() const throw()
  198050. {
  198051. return renderContext;
  198052. }
  198053. void updateWindowPosition (int x, int y, int w, int h, int)
  198054. {
  198055. ScopedXLock xlock;
  198056. XMoveResizeWindow (display, embeddedWindow,
  198057. x, y, jmax (1, w), jmax (1, h));
  198058. }
  198059. void swapBuffers()
  198060. {
  198061. ScopedXLock xlock;
  198062. glXSwapBuffers (display, embeddedWindow);
  198063. }
  198064. bool setSwapInterval (const int numFramesPerSwap)
  198065. {
  198066. // xxx needs doing..
  198067. return false;
  198068. }
  198069. int getSwapInterval() const
  198070. {
  198071. // xxx needs doing..
  198072. return 0;
  198073. }
  198074. void repaint()
  198075. {
  198076. }
  198077. juce_UseDebuggingNewOperator
  198078. GLXContext renderContext;
  198079. private:
  198080. Window embeddedWindow;
  198081. OpenGLPixelFormat pixelFormat;
  198082. WindowedGLContext (const WindowedGLContext&);
  198083. const WindowedGLContext& operator= (const WindowedGLContext&);
  198084. };
  198085. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  198086. const OpenGLPixelFormat& pixelFormat,
  198087. const OpenGLContext* const contextToShareWith)
  198088. {
  198089. WindowedGLContext* c = new WindowedGLContext (component, pixelFormat,
  198090. contextToShareWith != 0 ? (GLXContext) contextToShareWith->getRawContext() : 0);
  198091. if (c->renderContext == 0)
  198092. deleteAndZero (c);
  198093. return c;
  198094. }
  198095. void juce_glViewport (const int w, const int h)
  198096. {
  198097. glViewport (0, 0, w, h);
  198098. }
  198099. void OpenGLPixelFormat::getAvailablePixelFormats (Component* component,
  198100. OwnedArray <OpenGLPixelFormat>& results)
  198101. {
  198102. results.add (new OpenGLPixelFormat()); // xxx
  198103. }
  198104. #endif
  198105. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  198106. {
  198107. jassertfalse // not implemented!
  198108. return false;
  198109. }
  198110. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  198111. {
  198112. jassertfalse // not implemented!
  198113. return false;
  198114. }
  198115. void SystemTrayIconComponent::setIconImage (const Image& newImage)
  198116. {
  198117. if (! isOnDesktop ())
  198118. addToDesktop (0);
  198119. LinuxComponentPeer* const wp = dynamic_cast <LinuxComponentPeer*> (getPeer());
  198120. if (wp != 0)
  198121. {
  198122. wp->setTaskBarIcon (newImage);
  198123. setVisible (true);
  198124. toFront (false);
  198125. repaint();
  198126. }
  198127. }
  198128. void SystemTrayIconComponent::paint (Graphics& g)
  198129. {
  198130. LinuxComponentPeer* const wp = dynamic_cast <LinuxComponentPeer*> (getPeer());
  198131. if (wp != 0)
  198132. {
  198133. const Image* const image = wp->getTaskbarIcon();
  198134. if (image != 0)
  198135. {
  198136. g.drawImageWithin (image, 0, 0, getWidth(), getHeight(),
  198137. RectanglePlacement::xLeft | RectanglePlacement::yTop | RectanglePlacement::onlyReduceInSize,
  198138. false);
  198139. }
  198140. }
  198141. }
  198142. void SystemTrayIconComponent::setIconTooltip (const String& tooltip)
  198143. {
  198144. // xxx not yet implemented!
  198145. }
  198146. void PlatformUtilities::beep()
  198147. {
  198148. std::cout << "\a" << std::flush;
  198149. }
  198150. bool AlertWindow::showNativeDialogBox (const String& title,
  198151. const String& bodyText,
  198152. bool isOkCancel)
  198153. {
  198154. // xxx this is supposed to pop up an alert!
  198155. Logger::outputDebugString (title + ": " + bodyText);
  198156. // use a non-native one for the time being..
  198157. if (isOkCancel)
  198158. return AlertWindow::showOkCancelBox (AlertWindow::NoIcon, title, bodyText);
  198159. else
  198160. AlertWindow::showMessageBox (AlertWindow::NoIcon, title, bodyText);
  198161. return true;
  198162. }
  198163. const int KeyPress::spaceKey = XK_space & 0xff;
  198164. const int KeyPress::returnKey = XK_Return & 0xff;
  198165. const int KeyPress::escapeKey = XK_Escape & 0xff;
  198166. const int KeyPress::backspaceKey = XK_BackSpace & 0xff;
  198167. const int KeyPress::leftKey = (XK_Left & 0xff) | extendedKeyModifier;
  198168. const int KeyPress::rightKey = (XK_Right & 0xff) | extendedKeyModifier;
  198169. const int KeyPress::upKey = (XK_Up & 0xff) | extendedKeyModifier;
  198170. const int KeyPress::downKey = (XK_Down & 0xff) | extendedKeyModifier;
  198171. const int KeyPress::pageUpKey = (XK_Page_Up & 0xff) | extendedKeyModifier;
  198172. const int KeyPress::pageDownKey = (XK_Page_Down & 0xff) | extendedKeyModifier;
  198173. const int KeyPress::endKey = (XK_End & 0xff) | extendedKeyModifier;
  198174. const int KeyPress::homeKey = (XK_Home & 0xff) | extendedKeyModifier;
  198175. const int KeyPress::insertKey = (XK_Insert & 0xff) | extendedKeyModifier;
  198176. const int KeyPress::deleteKey = (XK_Delete & 0xff) | extendedKeyModifier;
  198177. const int KeyPress::tabKey = XK_Tab & 0xff;
  198178. const int KeyPress::F1Key = (XK_F1 & 0xff) | extendedKeyModifier;
  198179. const int KeyPress::F2Key = (XK_F2 & 0xff) | extendedKeyModifier;
  198180. const int KeyPress::F3Key = (XK_F3 & 0xff) | extendedKeyModifier;
  198181. const int KeyPress::F4Key = (XK_F4 & 0xff) | extendedKeyModifier;
  198182. const int KeyPress::F5Key = (XK_F5 & 0xff) | extendedKeyModifier;
  198183. const int KeyPress::F6Key = (XK_F6 & 0xff) | extendedKeyModifier;
  198184. const int KeyPress::F7Key = (XK_F7 & 0xff) | extendedKeyModifier;
  198185. const int KeyPress::F8Key = (XK_F8 & 0xff) | extendedKeyModifier;
  198186. const int KeyPress::F9Key = (XK_F9 & 0xff) | extendedKeyModifier;
  198187. const int KeyPress::F10Key = (XK_F10 & 0xff) | extendedKeyModifier;
  198188. const int KeyPress::F11Key = (XK_F11 & 0xff) | extendedKeyModifier;
  198189. const int KeyPress::F12Key = (XK_F12 & 0xff) | extendedKeyModifier;
  198190. const int KeyPress::F13Key = (XK_F13 & 0xff) | extendedKeyModifier;
  198191. const int KeyPress::F14Key = (XK_F14 & 0xff) | extendedKeyModifier;
  198192. const int KeyPress::F15Key = (XK_F15 & 0xff) | extendedKeyModifier;
  198193. const int KeyPress::F16Key = (XK_F16 & 0xff) | extendedKeyModifier;
  198194. const int KeyPress::numberPad0 = (XK_KP_0 & 0xff) | extendedKeyModifier;
  198195. const int KeyPress::numberPad1 = (XK_KP_1 & 0xff) | extendedKeyModifier;
  198196. const int KeyPress::numberPad2 = (XK_KP_2 & 0xff) | extendedKeyModifier;
  198197. const int KeyPress::numberPad3 = (XK_KP_3 & 0xff) | extendedKeyModifier;
  198198. const int KeyPress::numberPad4 = (XK_KP_4 & 0xff) | extendedKeyModifier;
  198199. const int KeyPress::numberPad5 = (XK_KP_5 & 0xff) | extendedKeyModifier;
  198200. const int KeyPress::numberPad6 = (XK_KP_6 & 0xff) | extendedKeyModifier;
  198201. const int KeyPress::numberPad7 = (XK_KP_7 & 0xff)| extendedKeyModifier;
  198202. const int KeyPress::numberPad8 = (XK_KP_8 & 0xff)| extendedKeyModifier;
  198203. const int KeyPress::numberPad9 = (XK_KP_9 & 0xff)| extendedKeyModifier;
  198204. const int KeyPress::numberPadAdd = (XK_KP_Add & 0xff)| extendedKeyModifier;
  198205. const int KeyPress::numberPadSubtract = (XK_KP_Subtract & 0xff)| extendedKeyModifier;
  198206. const int KeyPress::numberPadMultiply = (XK_KP_Multiply & 0xff)| extendedKeyModifier;
  198207. const int KeyPress::numberPadDivide = (XK_KP_Divide & 0xff)| extendedKeyModifier;
  198208. const int KeyPress::numberPadSeparator = (XK_KP_Separator & 0xff)| extendedKeyModifier;
  198209. const int KeyPress::numberPadDecimalPoint = (XK_KP_Decimal & 0xff)| extendedKeyModifier;
  198210. const int KeyPress::numberPadEquals = (XK_KP_Equal & 0xff)| extendedKeyModifier;
  198211. const int KeyPress::numberPadDelete = (XK_KP_Delete & 0xff)| extendedKeyModifier;
  198212. const int KeyPress::playKey = (0xffeeff00) | extendedKeyModifier;
  198213. const int KeyPress::stopKey = (0xffeeff01) | extendedKeyModifier;
  198214. const int KeyPress::fastForwardKey = (0xffeeff02) | extendedKeyModifier;
  198215. const int KeyPress::rewindKey = (0xffeeff03) | extendedKeyModifier;
  198216. #endif
  198217. /*** End of inlined file: juce_linux_Windowing.cpp ***/
  198218. /*** Start of inlined file: juce_linux_Audio.cpp ***/
  198219. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  198220. // compiled on its own).
  198221. #if JUCE_INCLUDED_FILE && JUCE_ALSA
  198222. static const int maxNumChans = 64;
  198223. static void getDeviceSampleRates (snd_pcm_t* handle, Array <int>& rates)
  198224. {
  198225. const int ratesToTry[] = { 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000, 0 };
  198226. snd_pcm_hw_params_t* hwParams;
  198227. snd_pcm_hw_params_alloca (&hwParams);
  198228. for (int i = 0; ratesToTry[i] != 0; ++i)
  198229. {
  198230. if (snd_pcm_hw_params_any (handle, hwParams) >= 0
  198231. && snd_pcm_hw_params_test_rate (handle, hwParams, ratesToTry[i], 0) == 0)
  198232. {
  198233. rates.addIfNotAlreadyThere (ratesToTry[i]);
  198234. }
  198235. }
  198236. }
  198237. static void getDeviceNumChannels (snd_pcm_t* handle, unsigned int* minChans, unsigned int* maxChans)
  198238. {
  198239. snd_pcm_hw_params_t *params;
  198240. snd_pcm_hw_params_alloca (&params);
  198241. if (snd_pcm_hw_params_any (handle, params) >= 0)
  198242. {
  198243. snd_pcm_hw_params_get_channels_min (params, minChans);
  198244. snd_pcm_hw_params_get_channels_max (params, maxChans);
  198245. }
  198246. }
  198247. static void getDeviceProperties (const String& id,
  198248. unsigned int& minChansOut,
  198249. unsigned int& maxChansOut,
  198250. unsigned int& minChansIn,
  198251. unsigned int& maxChansIn,
  198252. Array <int>& rates)
  198253. {
  198254. if (id.isEmpty())
  198255. return;
  198256. snd_ctl_t* handle;
  198257. if (snd_ctl_open (&handle, id.upToLastOccurrenceOf (T(","), false, false), SND_CTL_NONBLOCK) >= 0)
  198258. {
  198259. snd_pcm_info_t* info;
  198260. snd_pcm_info_alloca (&info);
  198261. snd_pcm_info_set_stream (info, SND_PCM_STREAM_PLAYBACK);
  198262. snd_pcm_info_set_device (info, id.fromLastOccurrenceOf (T(","), false, false).getIntValue());
  198263. snd_pcm_info_set_subdevice (info, 0);
  198264. if (snd_ctl_pcm_info (handle, info) >= 0)
  198265. {
  198266. snd_pcm_t* pcmHandle;
  198267. if (snd_pcm_open (&pcmHandle, id, SND_PCM_STREAM_PLAYBACK, SND_PCM_ASYNC | SND_PCM_NONBLOCK ) >= 0)
  198268. {
  198269. getDeviceNumChannels (pcmHandle, &minChansOut, &maxChansOut);
  198270. getDeviceSampleRates (pcmHandle, rates);
  198271. snd_pcm_close (pcmHandle);
  198272. }
  198273. }
  198274. snd_pcm_info_set_stream (info, SND_PCM_STREAM_CAPTURE);
  198275. if (snd_ctl_pcm_info (handle, info) >= 0)
  198276. {
  198277. snd_pcm_t* pcmHandle;
  198278. if (snd_pcm_open (&pcmHandle, id, SND_PCM_STREAM_CAPTURE, SND_PCM_ASYNC | SND_PCM_NONBLOCK ) >= 0)
  198279. {
  198280. getDeviceNumChannels (pcmHandle, &minChansIn, &maxChansIn);
  198281. if (rates.size() == 0)
  198282. getDeviceSampleRates (pcmHandle, rates);
  198283. snd_pcm_close (pcmHandle);
  198284. }
  198285. }
  198286. snd_ctl_close (handle);
  198287. }
  198288. }
  198289. class ALSADevice
  198290. {
  198291. public:
  198292. ALSADevice (const String& id,
  198293. const bool forInput)
  198294. : handle (0),
  198295. bitDepth (16),
  198296. numChannelsRunning (0),
  198297. isInput (forInput),
  198298. sampleFormat (AudioDataConverters::int16LE)
  198299. {
  198300. failed (snd_pcm_open (&handle, id,
  198301. forInput ? SND_PCM_STREAM_CAPTURE : SND_PCM_STREAM_PLAYBACK,
  198302. SND_PCM_ASYNC));
  198303. }
  198304. ~ALSADevice()
  198305. {
  198306. if (handle != 0)
  198307. snd_pcm_close (handle);
  198308. }
  198309. bool setParameters (unsigned int sampleRate, int numChannels, int bufferSize)
  198310. {
  198311. if (handle == 0)
  198312. return false;
  198313. snd_pcm_hw_params_t* hwParams;
  198314. snd_pcm_hw_params_alloca (&hwParams);
  198315. if (failed (snd_pcm_hw_params_any (handle, hwParams)))
  198316. return false;
  198317. if (snd_pcm_hw_params_set_access (handle, hwParams, SND_PCM_ACCESS_RW_NONINTERLEAVED) >= 0)
  198318. isInterleaved = false;
  198319. else if (snd_pcm_hw_params_set_access (handle, hwParams, SND_PCM_ACCESS_RW_INTERLEAVED) >= 0)
  198320. isInterleaved = true;
  198321. else
  198322. {
  198323. jassertfalse
  198324. return false;
  198325. }
  198326. const int formatsToTry[] = { SND_PCM_FORMAT_FLOAT_LE, 32, AudioDataConverters::float32LE,
  198327. SND_PCM_FORMAT_FLOAT_BE, 32, AudioDataConverters::float32BE,
  198328. SND_PCM_FORMAT_S32_LE, 32, AudioDataConverters::int32LE,
  198329. SND_PCM_FORMAT_S32_BE, 32, AudioDataConverters::int32BE,
  198330. SND_PCM_FORMAT_S24_3LE, 24, AudioDataConverters::int24LE,
  198331. SND_PCM_FORMAT_S24_3BE, 24, AudioDataConverters::int24BE,
  198332. SND_PCM_FORMAT_S16_LE, 16, AudioDataConverters::int16LE,
  198333. SND_PCM_FORMAT_S16_BE, 16, AudioDataConverters::int16BE };
  198334. bitDepth = 0;
  198335. for (int i = 0; i < numElementsInArray (formatsToTry); i += 3)
  198336. {
  198337. if (snd_pcm_hw_params_set_format (handle, hwParams, (_snd_pcm_format) formatsToTry [i]) >= 0)
  198338. {
  198339. bitDepth = formatsToTry [i + 1];
  198340. sampleFormat = (AudioDataConverters::DataFormat) formatsToTry [i + 2];
  198341. break;
  198342. }
  198343. }
  198344. if (bitDepth == 0)
  198345. {
  198346. error = "device doesn't support a compatible PCM format";
  198347. DBG (T("ALSA error: ") + error + T("\n"));
  198348. return false;
  198349. }
  198350. int dir = 0;
  198351. unsigned int periods = 4;
  198352. snd_pcm_uframes_t samplesPerPeriod = bufferSize;
  198353. if (failed (snd_pcm_hw_params_set_rate_near (handle, hwParams, &sampleRate, 0))
  198354. || failed (snd_pcm_hw_params_set_channels (handle, hwParams, numChannels))
  198355. || failed (snd_pcm_hw_params_set_periods_near (handle, hwParams, &periods, &dir))
  198356. || failed (snd_pcm_hw_params_set_period_size_near (handle, hwParams, &samplesPerPeriod, &dir))
  198357. || failed (snd_pcm_hw_params (handle, hwParams)))
  198358. {
  198359. return false;
  198360. }
  198361. snd_pcm_sw_params_t* swParams;
  198362. snd_pcm_sw_params_alloca (&swParams);
  198363. snd_pcm_uframes_t boundary;
  198364. if (failed (snd_pcm_sw_params_current (handle, swParams))
  198365. || failed (snd_pcm_sw_params_get_boundary (swParams, &boundary))
  198366. || failed (snd_pcm_sw_params_set_silence_threshold (handle, swParams, 0))
  198367. || failed (snd_pcm_sw_params_set_silence_size (handle, swParams, boundary))
  198368. || failed (snd_pcm_sw_params_set_start_threshold (handle, swParams, samplesPerPeriod))
  198369. || failed (snd_pcm_sw_params_set_stop_threshold (handle, swParams, boundary))
  198370. || failed (snd_pcm_sw_params (handle, swParams)))
  198371. {
  198372. return false;
  198373. }
  198374. numChannelsRunning = numChannels;
  198375. return true;
  198376. }
  198377. bool write (float** const data, const int numSamples)
  198378. {
  198379. if (isInterleaved)
  198380. {
  198381. scratch.ensureSize (sizeof (float) * numSamples * numChannelsRunning, false);
  198382. float* interleaved = (float*) scratch;
  198383. AudioDataConverters::interleaveSamples ((const float**) data, interleaved, numSamples, numChannelsRunning);
  198384. AudioDataConverters::convertFloatToFormat (sampleFormat, interleaved, interleaved, numSamples * numChannelsRunning);
  198385. snd_pcm_sframes_t num = snd_pcm_writei (handle, (void*) interleaved, numSamples);
  198386. if (failed (num) && num != -EPIPE && num != -ESTRPIPE)
  198387. return false;
  198388. }
  198389. else
  198390. {
  198391. for (int i = 0; i < numChannelsRunning; ++i)
  198392. if (data[i] != 0)
  198393. AudioDataConverters::convertFloatToFormat (sampleFormat, data[i], data[i], numSamples);
  198394. snd_pcm_sframes_t num = snd_pcm_writen (handle, (void**) data, numSamples);
  198395. if (failed (num))
  198396. {
  198397. if (num == -EPIPE)
  198398. {
  198399. if (failed (snd_pcm_prepare (handle)))
  198400. return false;
  198401. }
  198402. else if (num != -ESTRPIPE)
  198403. return false;
  198404. }
  198405. }
  198406. return true;
  198407. }
  198408. bool read (float** const data, const int numSamples)
  198409. {
  198410. if (isInterleaved)
  198411. {
  198412. scratch.ensureSize (sizeof (float) * numSamples * numChannelsRunning, false);
  198413. float* interleaved = (float*) scratch;
  198414. snd_pcm_sframes_t num = snd_pcm_readi (handle, (void*) interleaved, numSamples);
  198415. if (failed (num))
  198416. {
  198417. if (num == -EPIPE)
  198418. {
  198419. if (failed (snd_pcm_prepare (handle)))
  198420. return false;
  198421. }
  198422. else if (num != -ESTRPIPE)
  198423. return false;
  198424. }
  198425. AudioDataConverters::convertFormatToFloat (sampleFormat, interleaved, interleaved, numSamples * numChannelsRunning);
  198426. AudioDataConverters::deinterleaveSamples (interleaved, data, numSamples, numChannelsRunning);
  198427. }
  198428. else
  198429. {
  198430. snd_pcm_sframes_t num = snd_pcm_readn (handle, (void**) data, numSamples);
  198431. if (failed (num) && num != -EPIPE && num != -ESTRPIPE)
  198432. return false;
  198433. for (int i = 0; i < numChannelsRunning; ++i)
  198434. if (data[i] != 0)
  198435. AudioDataConverters::convertFormatToFloat (sampleFormat, data[i], data[i], numSamples);
  198436. }
  198437. return true;
  198438. }
  198439. juce_UseDebuggingNewOperator
  198440. snd_pcm_t* handle;
  198441. String error;
  198442. int bitDepth, numChannelsRunning;
  198443. private:
  198444. const bool isInput;
  198445. bool isInterleaved;
  198446. MemoryBlock scratch;
  198447. AudioDataConverters::DataFormat sampleFormat;
  198448. bool failed (const int errorNum)
  198449. {
  198450. if (errorNum >= 0)
  198451. return false;
  198452. error = snd_strerror (errorNum);
  198453. DBG (T("ALSA error: ") + error + T("\n"));
  198454. return true;
  198455. }
  198456. };
  198457. class ALSAThread : public Thread
  198458. {
  198459. public:
  198460. ALSAThread (const String& inputId_,
  198461. const String& outputId_)
  198462. : Thread ("Juce ALSA"),
  198463. sampleRate (0),
  198464. bufferSize (0),
  198465. callback (0),
  198466. inputId (inputId_),
  198467. outputId (outputId_),
  198468. outputDevice (0),
  198469. inputDevice (0),
  198470. numCallbacks (0),
  198471. totalNumInputChannels (0),
  198472. totalNumOutputChannels (0)
  198473. {
  198474. zeromem (outputChannelData, sizeof (outputChannelData));
  198475. zeromem (outputChannelDataForCallback, sizeof (outputChannelDataForCallback));
  198476. zeromem (inputChannelData, sizeof (inputChannelData));
  198477. zeromem (inputChannelDataForCallback, sizeof (inputChannelDataForCallback));
  198478. initialiseRatesAndChannels();
  198479. }
  198480. ~ALSAThread()
  198481. {
  198482. close();
  198483. }
  198484. void open (BitArray inputChannels,
  198485. BitArray outputChannels,
  198486. const double sampleRate_,
  198487. const int bufferSize_)
  198488. {
  198489. close();
  198490. error = String::empty;
  198491. sampleRate = sampleRate_;
  198492. bufferSize = bufferSize_;
  198493. currentInputChans.clear();
  198494. currentOutputChans.clear();
  198495. if (inputChannels.getHighestBit() >= 0)
  198496. {
  198497. for (int i = 0; i <= jmax (inputChannels.getHighestBit(), (int) minChansIn); ++i)
  198498. {
  198499. inputChannelData [i] = (float*) juce_calloc (sizeof (float) * bufferSize);
  198500. if (inputChannels[i])
  198501. {
  198502. inputChannelDataForCallback [totalNumInputChannels++] = inputChannelData [i];
  198503. currentInputChans.setBit (i);
  198504. }
  198505. }
  198506. }
  198507. if (outputChannels.getHighestBit() >= 0)
  198508. {
  198509. for (int i = 0; i <= jmax (outputChannels.getHighestBit(), (int) minChansOut); ++i)
  198510. {
  198511. outputChannelData [i] = (float*) juce_calloc (sizeof (float) * bufferSize);
  198512. if (outputChannels[i])
  198513. {
  198514. outputChannelDataForCallback [totalNumOutputChannels++] = outputChannelData [i];
  198515. currentOutputChans.setBit (i);
  198516. }
  198517. }
  198518. }
  198519. if (totalNumOutputChannels > 0 && outputId.isNotEmpty())
  198520. {
  198521. outputDevice = new ALSADevice (outputId, false);
  198522. if (outputDevice->error.isNotEmpty())
  198523. {
  198524. error = outputDevice->error;
  198525. deleteAndZero (outputDevice);
  198526. return;
  198527. }
  198528. currentOutputChans.setRange (0, minChansOut, true);
  198529. if (! outputDevice->setParameters ((unsigned int) sampleRate,
  198530. jlimit ((int) minChansOut, (int) maxChansOut, currentOutputChans.getHighestBit() + 1),
  198531. bufferSize))
  198532. {
  198533. error = outputDevice->error;
  198534. deleteAndZero (outputDevice);
  198535. return;
  198536. }
  198537. }
  198538. if (totalNumInputChannels > 0 && inputId.isNotEmpty())
  198539. {
  198540. inputDevice = new ALSADevice (inputId, true);
  198541. if (inputDevice->error.isNotEmpty())
  198542. {
  198543. error = inputDevice->error;
  198544. deleteAndZero (inputDevice);
  198545. return;
  198546. }
  198547. currentInputChans.setRange (0, minChansIn, true);
  198548. if (! inputDevice->setParameters ((unsigned int) sampleRate,
  198549. jlimit ((int) minChansIn, (int) maxChansIn, currentInputChans.getHighestBit() + 1),
  198550. bufferSize))
  198551. {
  198552. error = inputDevice->error;
  198553. deleteAndZero (inputDevice);
  198554. return;
  198555. }
  198556. }
  198557. if (outputDevice == 0 && inputDevice == 0)
  198558. {
  198559. error = "no channels";
  198560. return;
  198561. }
  198562. if (outputDevice != 0 && inputDevice != 0)
  198563. {
  198564. snd_pcm_link (outputDevice->handle, inputDevice->handle);
  198565. }
  198566. if (inputDevice != 0 && failed (snd_pcm_prepare (inputDevice->handle)))
  198567. return;
  198568. if (outputDevice != 0 && failed (snd_pcm_prepare (outputDevice->handle)))
  198569. return;
  198570. startThread (9);
  198571. int count = 1000;
  198572. while (numCallbacks == 0)
  198573. {
  198574. sleep (5);
  198575. if (--count < 0 || ! isThreadRunning())
  198576. {
  198577. error = "device didn't start";
  198578. break;
  198579. }
  198580. }
  198581. }
  198582. void close()
  198583. {
  198584. stopThread (6000);
  198585. deleteAndZero (inputDevice);
  198586. deleteAndZero (outputDevice);
  198587. for (int i = 0; i < maxNumChans; ++i)
  198588. {
  198589. juce_free (inputChannelData [i]);
  198590. juce_free (outputChannelData [i]);
  198591. }
  198592. zeromem (outputChannelData, sizeof (outputChannelData));
  198593. zeromem (outputChannelDataForCallback, sizeof (outputChannelDataForCallback));
  198594. zeromem (inputChannelData, sizeof (inputChannelData));
  198595. zeromem (inputChannelDataForCallback, sizeof (inputChannelDataForCallback));
  198596. totalNumOutputChannels = 0;
  198597. totalNumInputChannels = 0;
  198598. numCallbacks = 0;
  198599. }
  198600. void setCallback (AudioIODeviceCallback* const newCallback) throw()
  198601. {
  198602. const ScopedLock sl (callbackLock);
  198603. callback = newCallback;
  198604. }
  198605. void run()
  198606. {
  198607. while (! threadShouldExit())
  198608. {
  198609. if (inputDevice != 0)
  198610. {
  198611. if (! inputDevice->read (inputChannelData, bufferSize))
  198612. {
  198613. DBG ("ALSA: read failure");
  198614. break;
  198615. }
  198616. }
  198617. if (threadShouldExit())
  198618. break;
  198619. {
  198620. const ScopedLock sl (callbackLock);
  198621. ++numCallbacks;
  198622. if (callback != 0)
  198623. {
  198624. callback->audioDeviceIOCallback ((const float**) inputChannelDataForCallback,
  198625. totalNumInputChannels,
  198626. outputChannelDataForCallback,
  198627. totalNumOutputChannels,
  198628. bufferSize);
  198629. }
  198630. else
  198631. {
  198632. for (int i = 0; i < totalNumOutputChannels; ++i)
  198633. zeromem (outputChannelDataForCallback[i], sizeof (float) * bufferSize);
  198634. }
  198635. }
  198636. if (outputDevice != 0)
  198637. {
  198638. failed (snd_pcm_wait (outputDevice->handle, 2000));
  198639. if (threadShouldExit())
  198640. break;
  198641. failed (snd_pcm_avail_update (outputDevice->handle));
  198642. if (! outputDevice->write (outputChannelData, bufferSize))
  198643. {
  198644. DBG ("ALSA: write failure");
  198645. break;
  198646. }
  198647. }
  198648. }
  198649. }
  198650. int getBitDepth() const throw()
  198651. {
  198652. if (outputDevice != 0)
  198653. return outputDevice->bitDepth;
  198654. if (inputDevice != 0)
  198655. return inputDevice->bitDepth;
  198656. return 16;
  198657. }
  198658. juce_UseDebuggingNewOperator
  198659. String error;
  198660. double sampleRate;
  198661. int bufferSize;
  198662. BitArray currentInputChans, currentOutputChans;
  198663. Array <int> sampleRates;
  198664. StringArray channelNamesOut, channelNamesIn;
  198665. AudioIODeviceCallback* callback;
  198666. private:
  198667. const String inputId, outputId;
  198668. ALSADevice* outputDevice;
  198669. ALSADevice* inputDevice;
  198670. int numCallbacks;
  198671. CriticalSection callbackLock;
  198672. float* outputChannelData [maxNumChans];
  198673. float* outputChannelDataForCallback [maxNumChans];
  198674. int totalNumInputChannels;
  198675. float* inputChannelData [maxNumChans];
  198676. float* inputChannelDataForCallback [maxNumChans];
  198677. int totalNumOutputChannels;
  198678. unsigned int minChansOut, maxChansOut;
  198679. unsigned int minChansIn, maxChansIn;
  198680. bool failed (const int errorNum) throw()
  198681. {
  198682. if (errorNum >= 0)
  198683. return false;
  198684. error = snd_strerror (errorNum);
  198685. DBG (T("ALSA error: ") + error + T("\n"));
  198686. return true;
  198687. }
  198688. void initialiseRatesAndChannels() throw()
  198689. {
  198690. sampleRates.clear();
  198691. channelNamesOut.clear();
  198692. channelNamesIn.clear();
  198693. minChansOut = 0;
  198694. maxChansOut = 0;
  198695. minChansIn = 0;
  198696. maxChansIn = 0;
  198697. unsigned int dummy = 0;
  198698. getDeviceProperties (inputId, dummy, dummy, minChansIn, maxChansIn, sampleRates);
  198699. getDeviceProperties (outputId, minChansOut, maxChansOut, dummy, dummy, sampleRates);
  198700. unsigned int i;
  198701. for (i = 0; i < maxChansOut; ++i)
  198702. channelNamesOut.add (T("channel ") + String ((int) i + 1));
  198703. for (i = 0; i < maxChansIn; ++i)
  198704. channelNamesIn.add (T("channel ") + String ((int) i + 1));
  198705. }
  198706. };
  198707. class ALSAAudioIODevice : public AudioIODevice
  198708. {
  198709. public:
  198710. ALSAAudioIODevice (const String& deviceName,
  198711. const String& inputId_,
  198712. const String& outputId_)
  198713. : AudioIODevice (deviceName, T("ALSA")),
  198714. inputId (inputId_),
  198715. outputId (outputId_),
  198716. isOpen_ (false),
  198717. isStarted (false),
  198718. internal (0)
  198719. {
  198720. internal = new ALSAThread (inputId, outputId);
  198721. }
  198722. ~ALSAAudioIODevice()
  198723. {
  198724. delete internal;
  198725. }
  198726. const StringArray getOutputChannelNames()
  198727. {
  198728. return internal->channelNamesOut;
  198729. }
  198730. const StringArray getInputChannelNames()
  198731. {
  198732. return internal->channelNamesIn;
  198733. }
  198734. int getNumSampleRates()
  198735. {
  198736. return internal->sampleRates.size();
  198737. }
  198738. double getSampleRate (int index)
  198739. {
  198740. return internal->sampleRates [index];
  198741. }
  198742. int getNumBufferSizesAvailable()
  198743. {
  198744. return 50;
  198745. }
  198746. int getBufferSizeSamples (int index)
  198747. {
  198748. int n = 16;
  198749. for (int i = 0; i < index; ++i)
  198750. n += n < 64 ? 16
  198751. : (n < 512 ? 32
  198752. : (n < 1024 ? 64
  198753. : (n < 2048 ? 128 : 256)));
  198754. return n;
  198755. }
  198756. int getDefaultBufferSize()
  198757. {
  198758. return 512;
  198759. }
  198760. const String open (const BitArray& inputChannels,
  198761. const BitArray& outputChannels,
  198762. double sampleRate,
  198763. int bufferSizeSamples)
  198764. {
  198765. close();
  198766. if (bufferSizeSamples <= 0)
  198767. bufferSizeSamples = getDefaultBufferSize();
  198768. if (sampleRate <= 0)
  198769. {
  198770. for (int i = 0; i < getNumSampleRates(); ++i)
  198771. {
  198772. if (getSampleRate (i) >= 44100)
  198773. {
  198774. sampleRate = getSampleRate (i);
  198775. break;
  198776. }
  198777. }
  198778. }
  198779. internal->open (inputChannels, outputChannels,
  198780. sampleRate, bufferSizeSamples);
  198781. isOpen_ = internal->error.isEmpty();
  198782. return internal->error;
  198783. }
  198784. void close()
  198785. {
  198786. stop();
  198787. internal->close();
  198788. isOpen_ = false;
  198789. }
  198790. bool isOpen()
  198791. {
  198792. return isOpen_;
  198793. }
  198794. int getCurrentBufferSizeSamples()
  198795. {
  198796. return internal->bufferSize;
  198797. }
  198798. double getCurrentSampleRate()
  198799. {
  198800. return internal->sampleRate;
  198801. }
  198802. int getCurrentBitDepth()
  198803. {
  198804. return internal->getBitDepth();
  198805. }
  198806. const BitArray getActiveOutputChannels() const
  198807. {
  198808. return internal->currentOutputChans;
  198809. }
  198810. const BitArray getActiveInputChannels() const
  198811. {
  198812. return internal->currentInputChans;
  198813. }
  198814. int getOutputLatencyInSamples()
  198815. {
  198816. return 0;
  198817. }
  198818. int getInputLatencyInSamples()
  198819. {
  198820. return 0;
  198821. }
  198822. void start (AudioIODeviceCallback* callback)
  198823. {
  198824. if (! isOpen_)
  198825. callback = 0;
  198826. internal->setCallback (callback);
  198827. if (callback != 0)
  198828. callback->audioDeviceAboutToStart (this);
  198829. isStarted = (callback != 0);
  198830. }
  198831. void stop()
  198832. {
  198833. AudioIODeviceCallback* const oldCallback = internal->callback;
  198834. start (0);
  198835. if (oldCallback != 0)
  198836. oldCallback->audioDeviceStopped();
  198837. }
  198838. bool isPlaying()
  198839. {
  198840. return isStarted && internal->error.isEmpty();
  198841. }
  198842. const String getLastError()
  198843. {
  198844. return internal->error;
  198845. }
  198846. String inputId, outputId;
  198847. private:
  198848. bool isOpen_, isStarted;
  198849. ALSAThread* internal;
  198850. };
  198851. class ALSAAudioIODeviceType : public AudioIODeviceType
  198852. {
  198853. public:
  198854. ALSAAudioIODeviceType()
  198855. : AudioIODeviceType (T("ALSA")),
  198856. hasScanned (false)
  198857. {
  198858. }
  198859. ~ALSAAudioIODeviceType()
  198860. {
  198861. }
  198862. void scanForDevices()
  198863. {
  198864. if (hasScanned)
  198865. return;
  198866. hasScanned = true;
  198867. inputNames.clear();
  198868. inputIds.clear();
  198869. outputNames.clear();
  198870. outputIds.clear();
  198871. snd_ctl_t* handle;
  198872. snd_ctl_card_info_t* info;
  198873. snd_ctl_card_info_alloca (&info);
  198874. int cardNum = -1;
  198875. while (outputIds.size() + inputIds.size() <= 32)
  198876. {
  198877. snd_card_next (&cardNum);
  198878. if (cardNum < 0)
  198879. break;
  198880. if (snd_ctl_open (&handle, T("hw:") + String (cardNum), SND_CTL_NONBLOCK) >= 0)
  198881. {
  198882. if (snd_ctl_card_info (handle, info) >= 0)
  198883. {
  198884. String cardId (snd_ctl_card_info_get_id (info));
  198885. if (cardId.removeCharacters (T("0123456789")).isEmpty())
  198886. cardId = String (cardNum);
  198887. int device = -1;
  198888. for (;;)
  198889. {
  198890. if (snd_ctl_pcm_next_device (handle, &device) < 0 || device < 0)
  198891. break;
  198892. String id, name;
  198893. id << "hw:" << cardId << ',' << device;
  198894. bool isInput, isOutput;
  198895. if (testDevice (id, isInput, isOutput))
  198896. {
  198897. name << snd_ctl_card_info_get_name (info);
  198898. if (name.isEmpty())
  198899. name = id;
  198900. if (isInput)
  198901. {
  198902. inputNames.add (name);
  198903. inputIds.add (id);
  198904. }
  198905. if (isOutput)
  198906. {
  198907. outputNames.add (name);
  198908. outputIds.add (id);
  198909. }
  198910. }
  198911. }
  198912. }
  198913. snd_ctl_close (handle);
  198914. }
  198915. }
  198916. inputNames.appendNumbersToDuplicates (false, true);
  198917. outputNames.appendNumbersToDuplicates (false, true);
  198918. }
  198919. const StringArray getDeviceNames (const bool wantInputNames) const
  198920. {
  198921. jassert (hasScanned); // need to call scanForDevices() before doing this
  198922. return wantInputNames ? inputNames : outputNames;
  198923. }
  198924. int getDefaultDeviceIndex (const bool forInput) const
  198925. {
  198926. jassert (hasScanned); // need to call scanForDevices() before doing this
  198927. return 0;
  198928. }
  198929. bool hasSeparateInputsAndOutputs() const { return true; }
  198930. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  198931. {
  198932. jassert (hasScanned); // need to call scanForDevices() before doing this
  198933. ALSAAudioIODevice* const d = dynamic_cast <ALSAAudioIODevice*> (device);
  198934. if (d == 0)
  198935. return -1;
  198936. return asInput ? inputIds.indexOf (d->inputId)
  198937. : outputIds.indexOf (d->outputId);
  198938. }
  198939. AudioIODevice* createDevice (const String& outputDeviceName,
  198940. const String& inputDeviceName)
  198941. {
  198942. jassert (hasScanned); // need to call scanForDevices() before doing this
  198943. const int inputIndex = inputNames.indexOf (inputDeviceName);
  198944. const int outputIndex = outputNames.indexOf (outputDeviceName);
  198945. String deviceName (outputIndex >= 0 ? outputDeviceName
  198946. : inputDeviceName);
  198947. if (inputIndex >= 0 || outputIndex >= 0)
  198948. return new ALSAAudioIODevice (deviceName,
  198949. inputIds [inputIndex],
  198950. outputIds [outputIndex]);
  198951. return 0;
  198952. }
  198953. juce_UseDebuggingNewOperator
  198954. private:
  198955. StringArray inputNames, outputNames, inputIds, outputIds;
  198956. bool hasScanned;
  198957. static bool testDevice (const String& id, bool& isInput, bool& isOutput)
  198958. {
  198959. unsigned int minChansOut = 0, maxChansOut = 0;
  198960. unsigned int minChansIn = 0, maxChansIn = 0;
  198961. Array <int> rates;
  198962. getDeviceProperties (id, minChansOut, maxChansOut, minChansIn, maxChansIn, rates);
  198963. DBG (T("ALSA device: ") + id
  198964. + T(" outs=") + String ((int) minChansOut) + T("-") + String ((int) maxChansOut)
  198965. + T(" ins=") + String ((int) minChansIn) + T("-") + String ((int) maxChansIn)
  198966. + T(" rates=") + String (rates.size()));
  198967. isInput = maxChansIn > 0;
  198968. isOutput = maxChansOut > 0;
  198969. return (isInput || isOutput) && rates.size() > 0;
  198970. }
  198971. ALSAAudioIODeviceType (const ALSAAudioIODeviceType&);
  198972. const ALSAAudioIODeviceType& operator= (const ALSAAudioIODeviceType&);
  198973. };
  198974. AudioIODeviceType* juce_createAudioIODeviceType_ALSA()
  198975. {
  198976. return new ALSAAudioIODeviceType();
  198977. }
  198978. #endif
  198979. /*** End of inlined file: juce_linux_Audio.cpp ***/
  198980. /*** Start of inlined file: juce_linux_JackAudio.cpp ***/
  198981. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  198982. // compiled on its own).
  198983. #ifdef JUCE_INCLUDED_FILE
  198984. #if JUCE_JACK
  198985. static void* juce_libjack_handle = 0;
  198986. void* juce_load_jack_function (const char* const name)
  198987. {
  198988. if (juce_libjack_handle == 0)
  198989. return 0;
  198990. return dlsym (juce_libjack_handle, name);
  198991. }
  198992. #define JUCE_DECL_JACK_FUNCTION(return_type, fn_name, argument_types, arguments) \
  198993. typedef return_type (*fn_name##_ptr_t)argument_types; \
  198994. return_type fn_name argument_types { \
  198995. static fn_name##_ptr_t fn = 0; \
  198996. if (fn == 0) { fn = (fn_name##_ptr_t)juce_load_jack_function(#fn_name); } \
  198997. if (fn) return (*fn)arguments; \
  198998. else return 0; \
  198999. }
  199000. #define JUCE_DECL_VOID_JACK_FUNCTION(fn_name, argument_types, arguments) \
  199001. typedef void (*fn_name##_ptr_t)argument_types; \
  199002. void fn_name argument_types { \
  199003. static fn_name##_ptr_t fn = 0; \
  199004. if (fn == 0) { fn = (fn_name##_ptr_t)juce_load_jack_function(#fn_name); } \
  199005. if (fn) (*fn)arguments; \
  199006. }
  199007. 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));
  199008. JUCE_DECL_JACK_FUNCTION (int, jack_client_close, (jack_client_t *client), (client));
  199009. JUCE_DECL_JACK_FUNCTION (int, jack_activate, (jack_client_t* client), (client));
  199010. JUCE_DECL_JACK_FUNCTION (int, jack_deactivate, (jack_client_t* client), (client));
  199011. JUCE_DECL_JACK_FUNCTION (jack_nframes_t, jack_get_buffer_size, (jack_client_t* client), (client));
  199012. JUCE_DECL_JACK_FUNCTION (jack_nframes_t, jack_get_sample_rate, (jack_client_t* client), (client));
  199013. JUCE_DECL_VOID_JACK_FUNCTION (jack_on_shutdown, (jack_client_t* client, void (*function)(void* arg), void* arg), (client, function, arg));
  199014. JUCE_DECL_JACK_FUNCTION (void* , jack_port_get_buffer, (jack_port_t* port, jack_nframes_t nframes), (port, nframes));
  199015. JUCE_DECL_JACK_FUNCTION (jack_nframes_t, jack_port_get_total_latency, (jack_client_t* client, jack_port_t* port), (client, port));
  199016. 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));
  199017. JUCE_DECL_VOID_JACK_FUNCTION (jack_set_error_function, (void (*func)(const char*)), (func));
  199018. JUCE_DECL_JACK_FUNCTION (int, jack_set_process_callback, (jack_client_t* client, JackProcessCallback process_callback, void* arg), (client, process_callback, arg));
  199019. 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));
  199020. JUCE_DECL_JACK_FUNCTION (int, jack_connect, (jack_client_t* client, const char* source_port, const char* destination_port), (client, source_port, destination_port));
  199021. JUCE_DECL_JACK_FUNCTION (const char*, jack_port_name, (const jack_port_t* port), (port));
  199022. JUCE_DECL_JACK_FUNCTION (int, jack_set_port_connect_callback, (jack_client_t* client, JackPortConnectCallback connect_callback, void* arg), (client, connect_callback, arg));
  199023. JUCE_DECL_JACK_FUNCTION (jack_port_t* , jack_port_by_id, (jack_client_t* client, jack_port_id_t port_id), (client, port_id));
  199024. JUCE_DECL_JACK_FUNCTION (int, jack_port_connected, (const jack_port_t* port), (port));
  199025. JUCE_DECL_JACK_FUNCTION (int, jack_port_connected_to, (const jack_port_t* port, const char* port_name), (port, port_name));
  199026. #if JUCE_DEBUG
  199027. #define JACK_LOGGING_ENABLED 1
  199028. #endif
  199029. #if JACK_LOGGING_ENABLED
  199030. static void jack_Log (const String& s)
  199031. {
  199032. puts (s);
  199033. }
  199034. static void dumpJackErrorMessage (const jack_status_t status) throw()
  199035. {
  199036. if (status & JackServerFailed || status & JackServerError)
  199037. jack_Log ("Unable to connect to JACK server");
  199038. if (status & JackVersionError)
  199039. jack_Log ("Client's protocol version does not match");
  199040. if (status & JackInvalidOption)
  199041. jack_Log ("The operation contained an invalid or unsupported option");
  199042. if (status & JackNameNotUnique)
  199043. jack_Log ("The desired client name was not unique");
  199044. if (status & JackNoSuchClient)
  199045. jack_Log ("Requested client does not exist");
  199046. if (status & JackInitFailure)
  199047. jack_Log ("Unable to initialize client");
  199048. }
  199049. #else
  199050. #define dumpJackErrorMessage(a) {}
  199051. #define jack_Log(...) {}
  199052. #endif
  199053. #ifndef JUCE_JACK_CLIENT_NAME
  199054. #define JUCE_JACK_CLIENT_NAME "JuceJack"
  199055. #endif
  199056. class JackAudioIODevice : public AudioIODevice
  199057. {
  199058. public:
  199059. JackAudioIODevice (const String& deviceName,
  199060. const String& inputId_,
  199061. const String& outputId_)
  199062. : AudioIODevice (deviceName, T("JACK")),
  199063. inputId (inputId_),
  199064. outputId (outputId_),
  199065. isOpen_ (false),
  199066. callback (0),
  199067. totalNumberOfInputChannels (0),
  199068. totalNumberOfOutputChannels (0)
  199069. {
  199070. jassert (deviceName.isNotEmpty());
  199071. jack_status_t status;
  199072. client = JUCE_NAMESPACE::jack_client_open (JUCE_JACK_CLIENT_NAME, JackNoStartServer, &status);
  199073. if (client == 0)
  199074. {
  199075. dumpJackErrorMessage (status);
  199076. }
  199077. else
  199078. {
  199079. JUCE_NAMESPACE::jack_set_error_function (errorCallback);
  199080. // open input ports
  199081. const StringArray inputChannels (getInputChannelNames());
  199082. for (int i = 0; i < inputChannels.size(); i++)
  199083. {
  199084. String inputName;
  199085. inputName << "in_" << (++totalNumberOfInputChannels);
  199086. inputPorts.add (JUCE_NAMESPACE::jack_port_register (client, (const char*) inputName,
  199087. JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0));
  199088. }
  199089. // open output ports
  199090. const StringArray outputChannels (getOutputChannelNames());
  199091. for (int i = 0; i < outputChannels.size (); i++)
  199092. {
  199093. String outputName;
  199094. outputName << "out_" << (++totalNumberOfOutputChannels);
  199095. outputPorts.add (JUCE_NAMESPACE::jack_port_register (client, (const char*) outputName,
  199096. JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0));
  199097. }
  199098. inChans.calloc (totalNumberOfInputChannels + 2);
  199099. outChans.calloc (totalNumberOfOutputChannels + 2);
  199100. }
  199101. }
  199102. ~JackAudioIODevice()
  199103. {
  199104. close();
  199105. if (client != 0)
  199106. {
  199107. JUCE_NAMESPACE::jack_client_close (client);
  199108. client = 0;
  199109. }
  199110. }
  199111. const StringArray getChannelNames (bool forInput) const
  199112. {
  199113. StringArray names;
  199114. const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */
  199115. forInput ? JackPortIsInput : JackPortIsOutput);
  199116. if (ports != 0)
  199117. {
  199118. int j = 0;
  199119. while (ports[j] != 0)
  199120. {
  199121. const String portName (ports [j++]);
  199122. if (portName.upToFirstOccurrenceOf (T(":"), false, false) == getName())
  199123. names.add (portName.fromFirstOccurrenceOf (T(":"), false, false));
  199124. }
  199125. free (ports);
  199126. }
  199127. return names;
  199128. }
  199129. const StringArray getOutputChannelNames() { return getChannelNames (false); }
  199130. const StringArray getInputChannelNames() { return getChannelNames (true); }
  199131. int getNumSampleRates() { return client != 0 ? 1 : 0; }
  199132. double getSampleRate (int index) { return client != 0 ? JUCE_NAMESPACE::jack_get_sample_rate (client) : 0; }
  199133. int getNumBufferSizesAvailable() { return client != 0 ? 1 : 0; }
  199134. int getBufferSizeSamples (int index) { return getDefaultBufferSize(); }
  199135. int getDefaultBufferSize() { return client != 0 ? JUCE_NAMESPACE::jack_get_buffer_size (client) : 0; }
  199136. const String open (const BitArray& inputChannels, const BitArray& outputChannels,
  199137. double sampleRate, int bufferSizeSamples)
  199138. {
  199139. if (client == 0)
  199140. {
  199141. lastError = T("No JACK client running");
  199142. return lastError;
  199143. }
  199144. lastError = String::empty;
  199145. close();
  199146. JUCE_NAMESPACE::jack_set_process_callback (client, processCallback, this);
  199147. JUCE_NAMESPACE::jack_on_shutdown (client, shutdownCallback, this);
  199148. JUCE_NAMESPACE::jack_activate (client);
  199149. isOpen_ = true;
  199150. if (! inputChannels.isEmpty())
  199151. {
  199152. const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsOutput);
  199153. if (ports != 0)
  199154. {
  199155. const int numInputChannels = inputChannels.getHighestBit () + 1;
  199156. for (int i = 0; i < numInputChannels; ++i)
  199157. {
  199158. const String portName (ports[i]);
  199159. if (inputChannels[i] && portName.upToFirstOccurrenceOf (T(":"), false, false) == getName())
  199160. {
  199161. int error = JUCE_NAMESPACE::jack_connect (client, ports[i], JUCE_NAMESPACE::jack_port_name ((jack_port_t*) inputPorts[i]));
  199162. if (error != 0)
  199163. jack_Log ("Cannot connect input port " + String (i) + " (" + String (ports[i]) + "), error " + String (error));
  199164. }
  199165. }
  199166. free (ports);
  199167. }
  199168. }
  199169. if (! outputChannels.isEmpty())
  199170. {
  199171. const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsInput);
  199172. if (ports != 0)
  199173. {
  199174. const int numOutputChannels = outputChannels.getHighestBit () + 1;
  199175. for (int i = 0; i < numOutputChannels; ++i)
  199176. {
  199177. const String portName (ports[i]);
  199178. if (outputChannels[i] && portName.upToFirstOccurrenceOf (T(":"), false, false) == getName())
  199179. {
  199180. int error = JUCE_NAMESPACE::jack_connect (client, JUCE_NAMESPACE::jack_port_name ((jack_port_t*) outputPorts[i]), ports[i]);
  199181. if (error != 0)
  199182. jack_Log ("Cannot connect output port " + String (i) + " (" + String (ports[i]) + "), error " + String (error));
  199183. }
  199184. }
  199185. free (ports);
  199186. }
  199187. }
  199188. return lastError;
  199189. }
  199190. void close()
  199191. {
  199192. stop();
  199193. if (client != 0)
  199194. {
  199195. JUCE_NAMESPACE::jack_deactivate (client);
  199196. JUCE_NAMESPACE::jack_set_process_callback (client, processCallback, 0);
  199197. JUCE_NAMESPACE::jack_on_shutdown (client, shutdownCallback, 0);
  199198. }
  199199. isOpen_ = false;
  199200. }
  199201. void start (AudioIODeviceCallback* newCallback)
  199202. {
  199203. if (isOpen_ && newCallback != callback)
  199204. {
  199205. if (newCallback != 0)
  199206. newCallback->audioDeviceAboutToStart (this);
  199207. AudioIODeviceCallback* const oldCallback = callback;
  199208. {
  199209. const ScopedLock sl (callbackLock);
  199210. callback = newCallback;
  199211. }
  199212. if (oldCallback != 0)
  199213. oldCallback->audioDeviceStopped();
  199214. }
  199215. }
  199216. void stop()
  199217. {
  199218. start (0);
  199219. }
  199220. bool isOpen() { return isOpen_; }
  199221. bool isPlaying() { return callback != 0; }
  199222. int getCurrentBufferSizeSamples() { return getBufferSizeSamples (0); }
  199223. double getCurrentSampleRate() { return getSampleRate (0); }
  199224. int getCurrentBitDepth() { return 32; }
  199225. const String getLastError() { return lastError; }
  199226. const BitArray getActiveOutputChannels() const
  199227. {
  199228. BitArray outputBits;
  199229. for (int i = 0; i < outputPorts.size(); i++)
  199230. if (JUCE_NAMESPACE::jack_port_connected ((jack_port_t*) outputPorts [i]))
  199231. outputBits.setBit (i);
  199232. return outputBits;
  199233. }
  199234. const BitArray getActiveInputChannels() const
  199235. {
  199236. BitArray inputBits;
  199237. for (int i = 0; i < inputPorts.size(); i++)
  199238. if (JUCE_NAMESPACE::jack_port_connected ((jack_port_t*) inputPorts [i]))
  199239. inputBits.setBit (i);
  199240. return inputBits;
  199241. }
  199242. int getOutputLatencyInSamples()
  199243. {
  199244. int latency = 0;
  199245. for (int i = 0; i < outputPorts.size(); i++)
  199246. latency = jmax (latency, (int) JUCE_NAMESPACE::jack_port_get_total_latency (client, (jack_port_t*) outputPorts [i]));
  199247. return latency;
  199248. }
  199249. int getInputLatencyInSamples()
  199250. {
  199251. int latency = 0;
  199252. for (int i = 0; i < inputPorts.size(); i++)
  199253. latency = jmax (latency, (int) JUCE_NAMESPACE::jack_port_get_total_latency (client, (jack_port_t*) inputPorts [i]));
  199254. return latency;
  199255. }
  199256. String inputId, outputId;
  199257. private:
  199258. void process (const int numSamples)
  199259. {
  199260. int i, numActiveInChans = 0, numActiveOutChans = 0;
  199261. for (i = 0; i < totalNumberOfInputChannels; ++i)
  199262. {
  199263. jack_default_audio_sample_t* in
  199264. = (jack_default_audio_sample_t*) JUCE_NAMESPACE::jack_port_get_buffer ((jack_port_t*) inputPorts.getUnchecked(i), numSamples);
  199265. if (in != 0)
  199266. inChans [numActiveInChans++] = (float*) in;
  199267. }
  199268. for (i = 0; i < totalNumberOfOutputChannels; ++i)
  199269. {
  199270. jack_default_audio_sample_t* out
  199271. = (jack_default_audio_sample_t*) JUCE_NAMESPACE::jack_port_get_buffer ((jack_port_t*) outputPorts.getUnchecked(i), numSamples);
  199272. if (out != 0)
  199273. outChans [numActiveOutChans++] = (float*) out;
  199274. }
  199275. const ScopedLock sl (callbackLock);
  199276. if (callback != 0)
  199277. {
  199278. callback->audioDeviceIOCallback ((const float**) inChans, numActiveInChans,
  199279. outChans, numActiveOutChans, numSamples);
  199280. }
  199281. else
  199282. {
  199283. for (i = 0; i < numActiveOutChans; ++i)
  199284. zeromem (outChans[i], sizeof (float) * numSamples);
  199285. }
  199286. }
  199287. static int processCallback (jack_nframes_t nframes, void* callbackArgument)
  199288. {
  199289. if (callbackArgument != 0)
  199290. ((JackAudioIODevice*) callbackArgument)->process (nframes);
  199291. return 0;
  199292. }
  199293. static void threadInitCallback (void* callbackArgument)
  199294. {
  199295. jack_Log ("JackAudioIODevice::initialise");
  199296. }
  199297. static void shutdownCallback (void* callbackArgument)
  199298. {
  199299. jack_Log ("JackAudioIODevice::shutdown");
  199300. JackAudioIODevice* device = (JackAudioIODevice*) callbackArgument;
  199301. if (device != 0)
  199302. {
  199303. device->client = 0;
  199304. device->close();
  199305. }
  199306. }
  199307. static void errorCallback (const char* msg)
  199308. {
  199309. jack_Log ("JackAudioIODevice::errorCallback " + String (msg));
  199310. }
  199311. bool isOpen_;
  199312. jack_client_t* client;
  199313. String lastError;
  199314. AudioIODeviceCallback* callback;
  199315. CriticalSection callbackLock;
  199316. HeapBlock <float*> inChans, outChans;
  199317. int totalNumberOfInputChannels;
  199318. int totalNumberOfOutputChannels;
  199319. VoidArray inputPorts, outputPorts;
  199320. };
  199321. class JackAudioIODeviceType : public AudioIODeviceType
  199322. {
  199323. public:
  199324. JackAudioIODeviceType()
  199325. : AudioIODeviceType (T("JACK")),
  199326. hasScanned (false)
  199327. {
  199328. }
  199329. ~JackAudioIODeviceType()
  199330. {
  199331. }
  199332. void scanForDevices()
  199333. {
  199334. hasScanned = true;
  199335. inputNames.clear();
  199336. inputIds.clear();
  199337. outputNames.clear();
  199338. outputIds.clear();
  199339. if (juce_libjack_handle == 0)
  199340. {
  199341. juce_libjack_handle = dlopen ("libjack.so", RTLD_LAZY);
  199342. if (juce_libjack_handle == 0)
  199343. return;
  199344. }
  199345. // open a dummy client
  199346. jack_status_t status;
  199347. jack_client_t* client = JUCE_NAMESPACE::jack_client_open ("JuceJackDummy", JackNoStartServer, &status);
  199348. if (client == 0)
  199349. {
  199350. dumpJackErrorMessage (status);
  199351. }
  199352. else
  199353. {
  199354. // scan for output devices
  199355. const char** ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsOutput);
  199356. if (ports != 0)
  199357. {
  199358. int j = 0;
  199359. while (ports[j] != 0)
  199360. {
  199361. String clientName (ports[j]);
  199362. clientName = clientName.upToFirstOccurrenceOf (T(":"), false, false);
  199363. if (clientName != String (JUCE_JACK_CLIENT_NAME)
  199364. && ! inputNames.contains (clientName))
  199365. {
  199366. inputNames.add (clientName);
  199367. inputIds.add (ports [j]);
  199368. }
  199369. ++j;
  199370. }
  199371. free (ports);
  199372. }
  199373. // scan for input devices
  199374. ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsInput);
  199375. if (ports != 0)
  199376. {
  199377. int j = 0;
  199378. while (ports[j] != 0)
  199379. {
  199380. String clientName (ports[j]);
  199381. clientName = clientName.upToFirstOccurrenceOf (T(":"), false, false);
  199382. if (clientName != String (JUCE_JACK_CLIENT_NAME)
  199383. && ! outputNames.contains (clientName))
  199384. {
  199385. outputNames.add (clientName);
  199386. outputIds.add (ports [j]);
  199387. }
  199388. ++j;
  199389. }
  199390. free (ports);
  199391. }
  199392. JUCE_NAMESPACE::jack_client_close (client);
  199393. }
  199394. }
  199395. const StringArray getDeviceNames (const bool wantInputNames) const
  199396. {
  199397. jassert (hasScanned); // need to call scanForDevices() before doing this
  199398. return wantInputNames ? inputNames : outputNames;
  199399. }
  199400. int getDefaultDeviceIndex (const bool forInput) const
  199401. {
  199402. jassert (hasScanned); // need to call scanForDevices() before doing this
  199403. return 0;
  199404. }
  199405. bool hasSeparateInputsAndOutputs() const { return true; }
  199406. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  199407. {
  199408. jassert (hasScanned); // need to call scanForDevices() before doing this
  199409. JackAudioIODevice* const d = dynamic_cast <JackAudioIODevice*> (device);
  199410. if (d == 0)
  199411. return -1;
  199412. return asInput ? inputIds.indexOf (d->inputId)
  199413. : outputIds.indexOf (d->outputId);
  199414. }
  199415. AudioIODevice* createDevice (const String& outputDeviceName,
  199416. const String& inputDeviceName)
  199417. {
  199418. jassert (hasScanned); // need to call scanForDevices() before doing this
  199419. const int inputIndex = inputNames.indexOf (inputDeviceName);
  199420. const int outputIndex = outputNames.indexOf (outputDeviceName);
  199421. if (inputIndex >= 0 || outputIndex >= 0)
  199422. return new JackAudioIODevice (outputIndex >= 0 ? outputDeviceName
  199423. : inputDeviceName,
  199424. inputIds [inputIndex],
  199425. outputIds [outputIndex]);
  199426. return 0;
  199427. }
  199428. juce_UseDebuggingNewOperator
  199429. private:
  199430. StringArray inputNames, outputNames, inputIds, outputIds;
  199431. bool hasScanned;
  199432. JackAudioIODeviceType (const JackAudioIODeviceType&);
  199433. const JackAudioIODeviceType& operator= (const JackAudioIODeviceType&);
  199434. };
  199435. AudioIODeviceType* juce_createAudioIODeviceType_JACK()
  199436. {
  199437. return new JackAudioIODeviceType();
  199438. }
  199439. #else // if JACK is turned off..
  199440. AudioIODeviceType* juce_createAudioIODeviceType_JACK() { return 0; }
  199441. #endif
  199442. #endif
  199443. /*** End of inlined file: juce_linux_JackAudio.cpp ***/
  199444. /*** Start of inlined file: juce_linux_Midi.cpp ***/
  199445. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199446. // compiled on its own).
  199447. #if JUCE_INCLUDED_FILE
  199448. #if JUCE_ALSA
  199449. static snd_seq_t* iterateDevices (const bool forInput,
  199450. StringArray& deviceNamesFound,
  199451. const int deviceIndexToOpen)
  199452. {
  199453. snd_seq_t* returnedHandle = 0;
  199454. snd_seq_t* seqHandle;
  199455. if (snd_seq_open (&seqHandle, "default", forInput ? SND_SEQ_OPEN_INPUT
  199456. : SND_SEQ_OPEN_OUTPUT, 0) == 0)
  199457. {
  199458. snd_seq_system_info_t* systemInfo;
  199459. snd_seq_client_info_t* clientInfo;
  199460. if (snd_seq_system_info_malloc (&systemInfo) == 0)
  199461. {
  199462. if (snd_seq_system_info (seqHandle, systemInfo) == 0
  199463. && snd_seq_client_info_malloc (&clientInfo) == 0)
  199464. {
  199465. int numClients = snd_seq_system_info_get_cur_clients (systemInfo);
  199466. while (--numClients >= 0 && returnedHandle == 0)
  199467. {
  199468. if (snd_seq_query_next_client (seqHandle, clientInfo) == 0)
  199469. {
  199470. snd_seq_port_info_t* portInfo;
  199471. if (snd_seq_port_info_malloc (&portInfo) == 0)
  199472. {
  199473. int numPorts = snd_seq_client_info_get_num_ports (clientInfo);
  199474. const int client = snd_seq_client_info_get_client (clientInfo);
  199475. snd_seq_port_info_set_client (portInfo, client);
  199476. snd_seq_port_info_set_port (portInfo, -1);
  199477. while (--numPorts >= 0)
  199478. {
  199479. if (snd_seq_query_next_port (seqHandle, portInfo) == 0
  199480. && (snd_seq_port_info_get_capability (portInfo)
  199481. & (forInput ? SND_SEQ_PORT_CAP_READ
  199482. : SND_SEQ_PORT_CAP_WRITE)) != 0)
  199483. {
  199484. deviceNamesFound.add (snd_seq_client_info_get_name (clientInfo));
  199485. if (deviceNamesFound.size() == deviceIndexToOpen + 1)
  199486. {
  199487. const int sourcePort = snd_seq_port_info_get_port (portInfo);
  199488. const int sourceClient = snd_seq_client_info_get_client (clientInfo);
  199489. if (sourcePort != -1)
  199490. {
  199491. snd_seq_set_client_name (seqHandle,
  199492. forInput ? "Juce Midi Input"
  199493. : "Juce Midi Output");
  199494. const int portId
  199495. = snd_seq_create_simple_port (seqHandle,
  199496. forInput ? "Juce Midi In Port"
  199497. : "Juce Midi Out Port",
  199498. forInput ? (SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_WRITE)
  199499. : (SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ),
  199500. SND_SEQ_PORT_TYPE_MIDI_GENERIC);
  199501. snd_seq_connect_from (seqHandle, portId, sourceClient, sourcePort);
  199502. returnedHandle = seqHandle;
  199503. }
  199504. }
  199505. }
  199506. }
  199507. snd_seq_port_info_free (portInfo);
  199508. }
  199509. }
  199510. }
  199511. snd_seq_client_info_free (clientInfo);
  199512. }
  199513. snd_seq_system_info_free (systemInfo);
  199514. }
  199515. if (returnedHandle == 0)
  199516. snd_seq_close (seqHandle);
  199517. }
  199518. deviceNamesFound.appendNumbersToDuplicates (true, true);
  199519. return returnedHandle;
  199520. }
  199521. static snd_seq_t* createDevice (const bool forInput,
  199522. const String& deviceNameToOpen)
  199523. {
  199524. snd_seq_t* seqHandle = 0;
  199525. if (snd_seq_open (&seqHandle, "default", forInput ? SND_SEQ_OPEN_INPUT
  199526. : SND_SEQ_OPEN_OUTPUT, 0) == 0)
  199527. {
  199528. snd_seq_set_client_name (seqHandle,
  199529. (const char*) (forInput ? (deviceNameToOpen + T(" Input"))
  199530. : (deviceNameToOpen + T(" Output"))));
  199531. const int portId
  199532. = snd_seq_create_simple_port (seqHandle,
  199533. forInput ? "in"
  199534. : "out",
  199535. forInput ? (SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_WRITE)
  199536. : (SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ),
  199537. forInput ? SND_SEQ_PORT_TYPE_APPLICATION
  199538. : SND_SEQ_PORT_TYPE_MIDI_GENERIC);
  199539. if (portId < 0)
  199540. {
  199541. snd_seq_close (seqHandle);
  199542. seqHandle = 0;
  199543. }
  199544. }
  199545. return seqHandle;
  199546. }
  199547. class MidiOutputDevice
  199548. {
  199549. public:
  199550. MidiOutputDevice (MidiOutput* const midiOutput_,
  199551. snd_seq_t* const seqHandle_)
  199552. :
  199553. midiOutput (midiOutput_),
  199554. seqHandle (seqHandle_),
  199555. maxEventSize (16 * 1024)
  199556. {
  199557. jassert (seqHandle != 0 && midiOutput != 0);
  199558. snd_midi_event_new (maxEventSize, &midiParser);
  199559. }
  199560. ~MidiOutputDevice()
  199561. {
  199562. snd_midi_event_free (midiParser);
  199563. snd_seq_close (seqHandle);
  199564. }
  199565. void sendMessageNow (const MidiMessage& message)
  199566. {
  199567. if (message.getRawDataSize() > maxEventSize)
  199568. {
  199569. maxEventSize = message.getRawDataSize();
  199570. snd_midi_event_free (midiParser);
  199571. snd_midi_event_new (maxEventSize, &midiParser);
  199572. }
  199573. snd_seq_event_t event;
  199574. snd_seq_ev_clear (&event);
  199575. snd_midi_event_encode (midiParser,
  199576. message.getRawData(),
  199577. message.getRawDataSize(),
  199578. &event);
  199579. snd_midi_event_reset_encode (midiParser);
  199580. snd_seq_ev_set_source (&event, 0);
  199581. snd_seq_ev_set_subs (&event);
  199582. snd_seq_ev_set_direct (&event);
  199583. snd_seq_event_output (seqHandle, &event);
  199584. snd_seq_drain_output (seqHandle);
  199585. }
  199586. juce_UseDebuggingNewOperator
  199587. private:
  199588. MidiOutput* const midiOutput;
  199589. snd_seq_t* const seqHandle;
  199590. snd_midi_event_t* midiParser;
  199591. int maxEventSize;
  199592. };
  199593. const StringArray MidiOutput::getDevices()
  199594. {
  199595. StringArray devices;
  199596. iterateDevices (false, devices, -1);
  199597. return devices;
  199598. }
  199599. int MidiOutput::getDefaultDeviceIndex()
  199600. {
  199601. return 0;
  199602. }
  199603. MidiOutput* MidiOutput::openDevice (int deviceIndex)
  199604. {
  199605. MidiOutput* newDevice = 0;
  199606. StringArray devices;
  199607. snd_seq_t* const handle = iterateDevices (false, devices, deviceIndex);
  199608. if (handle != 0)
  199609. {
  199610. newDevice = new MidiOutput();
  199611. newDevice->internal = new MidiOutputDevice (newDevice, handle);
  199612. }
  199613. return newDevice;
  199614. }
  199615. MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
  199616. {
  199617. MidiOutput* newDevice = 0;
  199618. snd_seq_t* const handle = createDevice (false, deviceName);
  199619. if (handle != 0)
  199620. {
  199621. newDevice = new MidiOutput();
  199622. newDevice->internal = new MidiOutputDevice (newDevice, handle);
  199623. }
  199624. return newDevice;
  199625. }
  199626. MidiOutput::~MidiOutput()
  199627. {
  199628. MidiOutputDevice* const device = (MidiOutputDevice*) internal;
  199629. delete device;
  199630. }
  199631. void MidiOutput::reset()
  199632. {
  199633. }
  199634. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  199635. {
  199636. return false;
  199637. }
  199638. void MidiOutput::setVolume (float leftVol, float rightVol)
  199639. {
  199640. }
  199641. void MidiOutput::sendMessageNow (const MidiMessage& message)
  199642. {
  199643. ((MidiOutputDevice*) internal)->sendMessageNow (message);
  199644. }
  199645. class MidiInputThread : public Thread
  199646. {
  199647. public:
  199648. MidiInputThread (MidiInput* const midiInput_,
  199649. snd_seq_t* const seqHandle_,
  199650. MidiInputCallback* const callback_)
  199651. : Thread (T("Juce MIDI Input")),
  199652. midiInput (midiInput_),
  199653. seqHandle (seqHandle_),
  199654. callback (callback_)
  199655. {
  199656. jassert (seqHandle != 0 && callback != 0 && midiInput != 0);
  199657. }
  199658. ~MidiInputThread()
  199659. {
  199660. snd_seq_close (seqHandle);
  199661. }
  199662. void run()
  199663. {
  199664. const int maxEventSize = 16 * 1024;
  199665. snd_midi_event_t* midiParser;
  199666. if (snd_midi_event_new (maxEventSize, &midiParser) >= 0)
  199667. {
  199668. HeapBlock <uint8> buffer (maxEventSize);
  199669. const int numPfds = snd_seq_poll_descriptors_count (seqHandle, POLLIN);
  199670. struct pollfd* const pfd = (struct pollfd*) alloca (numPfds * sizeof (struct pollfd));
  199671. snd_seq_poll_descriptors (seqHandle, pfd, numPfds, POLLIN);
  199672. while (! threadShouldExit())
  199673. {
  199674. if (poll (pfd, numPfds, 500) > 0)
  199675. {
  199676. snd_seq_event_t* inputEvent = 0;
  199677. snd_seq_nonblock (seqHandle, 1);
  199678. do
  199679. {
  199680. if (snd_seq_event_input (seqHandle, &inputEvent) >= 0)
  199681. {
  199682. // xxx what about SYSEXes that are too big for the buffer?
  199683. const int numBytes = snd_midi_event_decode (midiParser, buffer, maxEventSize, inputEvent);
  199684. snd_midi_event_reset_decode (midiParser);
  199685. if (numBytes > 0)
  199686. {
  199687. const MidiMessage message ((const uint8*) buffer,
  199688. numBytes,
  199689. Time::getMillisecondCounter() * 0.001);
  199690. callback->handleIncomingMidiMessage (midiInput, message);
  199691. }
  199692. snd_seq_free_event (inputEvent);
  199693. }
  199694. }
  199695. while (snd_seq_event_input_pending (seqHandle, 0) > 0);
  199696. snd_seq_free_event (inputEvent);
  199697. }
  199698. }
  199699. snd_midi_event_free (midiParser);
  199700. }
  199701. };
  199702. juce_UseDebuggingNewOperator
  199703. private:
  199704. MidiInput* const midiInput;
  199705. snd_seq_t* const seqHandle;
  199706. MidiInputCallback* const callback;
  199707. };
  199708. MidiInput::MidiInput (const String& name_)
  199709. : name (name_),
  199710. internal (0)
  199711. {
  199712. }
  199713. MidiInput::~MidiInput()
  199714. {
  199715. stop();
  199716. MidiInputThread* const thread = (MidiInputThread*) internal;
  199717. delete thread;
  199718. }
  199719. void MidiInput::start()
  199720. {
  199721. ((MidiInputThread*) internal)->startThread();
  199722. }
  199723. void MidiInput::stop()
  199724. {
  199725. ((MidiInputThread*) internal)->stopThread (3000);
  199726. }
  199727. int MidiInput::getDefaultDeviceIndex()
  199728. {
  199729. return 0;
  199730. }
  199731. const StringArray MidiInput::getDevices()
  199732. {
  199733. StringArray devices;
  199734. iterateDevices (true, devices, -1);
  199735. return devices;
  199736. }
  199737. MidiInput* MidiInput::openDevice (int deviceIndex, MidiInputCallback* callback)
  199738. {
  199739. MidiInput* newDevice = 0;
  199740. StringArray devices;
  199741. snd_seq_t* const handle = iterateDevices (true, devices, deviceIndex);
  199742. if (handle != 0)
  199743. {
  199744. newDevice = new MidiInput (devices [deviceIndex]);
  199745. newDevice->internal = new MidiInputThread (newDevice, handle, callback);
  199746. }
  199747. return newDevice;
  199748. }
  199749. MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
  199750. {
  199751. MidiInput* newDevice = 0;
  199752. snd_seq_t* const handle = createDevice (true, deviceName);
  199753. if (handle != 0)
  199754. {
  199755. newDevice = new MidiInput (deviceName);
  199756. newDevice->internal = new MidiInputThread (newDevice, handle, callback);
  199757. }
  199758. return newDevice;
  199759. }
  199760. #else
  199761. // (These are just stub functions if ALSA is unavailable...)
  199762. const StringArray MidiOutput::getDevices() { return StringArray(); }
  199763. int MidiOutput::getDefaultDeviceIndex() { return 0; }
  199764. MidiOutput* MidiOutput::openDevice (int) { return 0; }
  199765. MidiOutput* MidiOutput::createNewDevice (const String&) { return 0; }
  199766. MidiOutput::~MidiOutput() {}
  199767. void MidiOutput::reset() {}
  199768. bool MidiOutput::getVolume (float&, float&) { return false; }
  199769. void MidiOutput::setVolume (float, float) {}
  199770. void MidiOutput::sendMessageNow (const MidiMessage&) {}
  199771. MidiInput::MidiInput (const String& name_) : name (name_), internal (0) {}
  199772. MidiInput::~MidiInput() {}
  199773. void MidiInput::start() {}
  199774. void MidiInput::stop() {}
  199775. int MidiInput::getDefaultDeviceIndex() { return 0; }
  199776. const StringArray MidiInput::getDevices() { return StringArray(); }
  199777. MidiInput* MidiInput::openDevice (int, MidiInputCallback*) { return 0; }
  199778. MidiInput* MidiInput::createNewDevice (const String&, MidiInputCallback*) { return 0; }
  199779. #endif
  199780. #endif
  199781. /*** End of inlined file: juce_linux_Midi.cpp ***/
  199782. /*** Start of inlined file: juce_linux_AudioCDReader.cpp ***/
  199783. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199784. // compiled on its own).
  199785. #if JUCE_INCLUDED_FILE && JUCE_USE_CDREADER
  199786. AudioCDReader::AudioCDReader()
  199787. : AudioFormatReader (0, T("CD Audio"))
  199788. {
  199789. }
  199790. const StringArray AudioCDReader::getAvailableCDNames()
  199791. {
  199792. StringArray names;
  199793. return names;
  199794. }
  199795. AudioCDReader* AudioCDReader::createReaderForCD (const int index)
  199796. {
  199797. return 0;
  199798. }
  199799. AudioCDReader::~AudioCDReader()
  199800. {
  199801. }
  199802. void AudioCDReader::refreshTrackLengths()
  199803. {
  199804. }
  199805. bool AudioCDReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  199806. int64 startSampleInFile, int numSamples)
  199807. {
  199808. return false;
  199809. }
  199810. bool AudioCDReader::isCDStillPresent() const
  199811. {
  199812. return false;
  199813. }
  199814. int AudioCDReader::getNumTracks() const
  199815. {
  199816. return 0;
  199817. }
  199818. int AudioCDReader::getPositionOfTrackStart (int trackNum) const
  199819. {
  199820. return 0;
  199821. }
  199822. bool AudioCDReader::isTrackAudio (int trackNum) const
  199823. {
  199824. return false;
  199825. }
  199826. void AudioCDReader::enableIndexScanning (bool b)
  199827. {
  199828. }
  199829. int AudioCDReader::getLastIndex() const
  199830. {
  199831. return 0;
  199832. }
  199833. const Array<int> AudioCDReader::findIndexesInTrack (const int trackNumber)
  199834. {
  199835. return Array<int>();
  199836. }
  199837. int AudioCDReader::getCDDBId()
  199838. {
  199839. return 0;
  199840. }
  199841. #endif
  199842. /*** End of inlined file: juce_linux_AudioCDReader.cpp ***/
  199843. /*** Start of inlined file: juce_linux_FileChooser.cpp ***/
  199844. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199845. // compiled on its own).
  199846. #if JUCE_INCLUDED_FILE
  199847. void FileChooser::showPlatformDialog (Array<File>& results,
  199848. const String& title,
  199849. const File& file,
  199850. const String& filters,
  199851. bool isDirectory,
  199852. bool selectsFiles,
  199853. bool isSave,
  199854. bool warnAboutOverwritingExistingFiles,
  199855. bool selectMultipleFiles,
  199856. FilePreviewComponent* previewComponent)
  199857. {
  199858. const tchar* const separator = T(":");
  199859. String command ("zenity --file-selection");
  199860. if (title.isNotEmpty())
  199861. command << " --title=\"" << title << "\"";
  199862. if (file != File::nonexistent)
  199863. command << " --filename=\"" << file.getFullPathName () << "\"";
  199864. if (isDirectory)
  199865. command << " --directory";
  199866. if (isSave)
  199867. command << " --save";
  199868. if (selectMultipleFiles)
  199869. command << " --multiple --separator=\"" << separator << "\"";
  199870. command << " 2>&1";
  199871. MemoryOutputStream result;
  199872. int status = -1;
  199873. FILE* stream = popen ((const char*) command.toUTF8(), "r");
  199874. if (stream != 0)
  199875. {
  199876. for (;;)
  199877. {
  199878. char buffer [1024];
  199879. const int bytesRead = fread (buffer, 1, sizeof (buffer), stream);
  199880. if (bytesRead <= 0)
  199881. break;
  199882. result.write (buffer, bytesRead);
  199883. }
  199884. status = pclose (stream);
  199885. }
  199886. if (status == 0)
  199887. {
  199888. String resultString (String::fromUTF8 ((const uint8*) result.getData(), result.getDataSize()));
  199889. StringArray tokens;
  199890. if (selectMultipleFiles)
  199891. tokens.addTokens (resultString, separator, 0);
  199892. else
  199893. tokens.add (resultString);
  199894. for (int i = 0; i < tokens.size(); i++)
  199895. results.add (File (tokens[i]));
  199896. return;
  199897. }
  199898. //xxx ain't got one!
  199899. jassertfalse
  199900. }
  199901. #endif
  199902. /*** End of inlined file: juce_linux_FileChooser.cpp ***/
  199903. /*** Start of inlined file: juce_linux_WebBrowserComponent.cpp ***/
  199904. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199905. // compiled on its own).
  199906. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  199907. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  199908. : browser (0),
  199909. blankPageShown (false),
  199910. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  199911. {
  199912. setOpaque (true);
  199913. }
  199914. WebBrowserComponent::~WebBrowserComponent()
  199915. {
  199916. }
  199917. void WebBrowserComponent::goToURL (const String& url,
  199918. const StringArray* headers,
  199919. const MemoryBlock* postData)
  199920. {
  199921. lastURL = url;
  199922. lastHeaders.clear();
  199923. if (headers != 0)
  199924. lastHeaders = *headers;
  199925. lastPostData.setSize (0);
  199926. if (postData != 0)
  199927. lastPostData = *postData;
  199928. blankPageShown = false;
  199929. }
  199930. void WebBrowserComponent::stop()
  199931. {
  199932. }
  199933. void WebBrowserComponent::goBack()
  199934. {
  199935. lastURL = String::empty;
  199936. blankPageShown = false;
  199937. }
  199938. void WebBrowserComponent::goForward()
  199939. {
  199940. lastURL = String::empty;
  199941. }
  199942. void WebBrowserComponent::refresh()
  199943. {
  199944. }
  199945. void WebBrowserComponent::paint (Graphics& g)
  199946. {
  199947. g.fillAll (Colours::white);
  199948. }
  199949. void WebBrowserComponent::checkWindowAssociation()
  199950. {
  199951. }
  199952. void WebBrowserComponent::reloadLastURL()
  199953. {
  199954. if (lastURL.isNotEmpty())
  199955. {
  199956. goToURL (lastURL, &lastHeaders, &lastPostData);
  199957. lastURL = String::empty;
  199958. }
  199959. }
  199960. void WebBrowserComponent::parentHierarchyChanged()
  199961. {
  199962. checkWindowAssociation();
  199963. }
  199964. void WebBrowserComponent::resized()
  199965. {
  199966. }
  199967. void WebBrowserComponent::visibilityChanged()
  199968. {
  199969. checkWindowAssociation();
  199970. }
  199971. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  199972. {
  199973. return true;
  199974. }
  199975. #endif
  199976. /*** End of inlined file: juce_linux_WebBrowserComponent.cpp ***/
  199977. #endif
  199978. END_JUCE_NAMESPACE
  199979. /*** End of inlined file: juce_linux_NativeCode.cpp ***/
  199980. #endif
  199981. #if JUCE_MAC || JUCE_IPHONE
  199982. /*** Start of inlined file: juce_mac_NativeCode.mm ***/
  199983. BEGIN_JUCE_NAMESPACE
  199984. #undef Point
  199985. #define JUCE_INCLUDED_FILE 1
  199986. // Now include the actual code files..
  199987. /*** Start of inlined file: juce_mac_ObjCSuffix.h ***/
  199988. #ifndef JUCE_ObjCExtraSuffix
  199989. #define JUCE_ObjCExtraSuffix 3
  199990. #endif
  199991. #define appendMacro1(a, b, c, d) a ## _ ## b ## _ ## c ## _ ## d
  199992. #define appendMacro2(a, b, c, d) appendMacro1(a, b, c, d)
  199993. #define MakeObjCClassName(rootName) appendMacro2 (rootName, JUCE_MAJOR_VERSION, JUCE_MINOR_VERSION, JUCE_ObjCExtraSuffix)
  199994. /*** End of inlined file: juce_mac_ObjCSuffix.h ***/
  199995. /*** Start of inlined file: juce_mac_Strings.mm ***/
  199996. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  199997. // compiled on its own).
  199998. #if JUCE_INCLUDED_FILE
  199999. static const String nsStringToJuce (NSString* s)
  200000. {
  200001. return String::fromUTF8 ((uint8*) [s UTF8String]);
  200002. }
  200003. static NSString* juceStringToNS (const String& s)
  200004. {
  200005. return [NSString stringWithUTF8String: (const char*) s.toUTF8()];
  200006. }
  200007. static const String convertUTF16ToString (const UniChar* utf16)
  200008. {
  200009. String s;
  200010. while (*utf16 != 0)
  200011. s += (juce_wchar) *utf16++;
  200012. return s;
  200013. }
  200014. const String PlatformUtilities::cfStringToJuceString (CFStringRef cfString)
  200015. {
  200016. String result;
  200017. if (cfString != 0)
  200018. {
  200019. #if JUCE_STRINGS_ARE_UNICODE
  200020. CFRange range = { 0, CFStringGetLength (cfString) };
  200021. HeapBlock <UniChar> u (range.length + 1);
  200022. CFStringGetCharacters (cfString, range, u);
  200023. u[range.length] = 0;
  200024. result = convertUTF16ToString (u);
  200025. #else
  200026. const int len = CFStringGetLength (cfString);
  200027. HeapBlock <char> buffer (len + 1);
  200028. CFStringGetCString (cfString, buffer, len + 1, CFStringGetSystemEncoding());
  200029. result = buffer;
  200030. #endif
  200031. }
  200032. return result;
  200033. }
  200034. CFStringRef PlatformUtilities::juceStringToCFString (const String& s)
  200035. {
  200036. #if JUCE_STRINGS_ARE_UNICODE
  200037. const int len = s.length();
  200038. const juce_wchar* t = (const juce_wchar*) s;
  200039. HeapBlock <UniChar> temp (len + 2);
  200040. for (int i = 0; i <= len; ++i)
  200041. temp[i] = t[i];
  200042. return CFStringCreateWithCharacters (kCFAllocatorDefault, temp, len);
  200043. #else
  200044. return CFStringCreateWithCString (kCFAllocatorDefault,
  200045. (const char*) s,
  200046. CFStringGetSystemEncoding());
  200047. #endif
  200048. }
  200049. const String PlatformUtilities::convertToPrecomposedUnicode (const String& s)
  200050. {
  200051. #if JUCE_IPHONE
  200052. const ScopedAutoReleasePool pool;
  200053. return nsStringToJuce ([juceStringToNS (s) precomposedStringWithCanonicalMapping]);
  200054. #else
  200055. UnicodeMapping map;
  200056. map.unicodeEncoding = CreateTextEncoding (kTextEncodingUnicodeDefault,
  200057. kUnicodeNoSubset,
  200058. kTextEncodingDefaultFormat);
  200059. map.otherEncoding = CreateTextEncoding (kTextEncodingUnicodeDefault,
  200060. kUnicodeCanonicalCompVariant,
  200061. kTextEncodingDefaultFormat);
  200062. map.mappingVersion = kUnicodeUseLatestMapping;
  200063. UnicodeToTextInfo conversionInfo = 0;
  200064. String result;
  200065. if (CreateUnicodeToTextInfo (&map, &conversionInfo) == noErr)
  200066. {
  200067. const int len = s.length();
  200068. HeapBlock <UniChar> tempIn, tempOut;
  200069. tempIn.calloc (len + 2);
  200070. tempOut.calloc (len + 2);
  200071. for (int i = 0; i <= len; ++i)
  200072. tempIn[i] = s[i];
  200073. ByteCount bytesRead = 0;
  200074. ByteCount outputBufferSize = 0;
  200075. if (ConvertFromUnicodeToText (conversionInfo,
  200076. len * sizeof (UniChar), tempIn,
  200077. kUnicodeDefaultDirectionMask,
  200078. 0, 0, 0, 0,
  200079. len * sizeof (UniChar), &bytesRead,
  200080. &outputBufferSize, tempOut) == noErr)
  200081. {
  200082. result.preallocateStorage (bytesRead / sizeof (UniChar) + 2);
  200083. tchar* t = const_cast <tchar*> ((const tchar*) result);
  200084. unsigned int i;
  200085. for (i = 0; i < bytesRead / sizeof (UniChar); ++i)
  200086. t[i] = (tchar) tempOut[i];
  200087. t[i] = 0;
  200088. }
  200089. DisposeUnicodeToTextInfo (&conversionInfo);
  200090. }
  200091. return result;
  200092. #endif
  200093. }
  200094. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  200095. void SystemClipboard::copyTextToClipboard (const String& text) throw()
  200096. {
  200097. #if JUCE_IPHONE
  200098. [[UIPasteboard generalPasteboard] setValue: juceStringToNS (text)
  200099. forPasteboardType: @"public.text"];
  200100. #else
  200101. [[NSPasteboard generalPasteboard] declareTypes: [NSArray arrayWithObject: NSStringPboardType]
  200102. owner: nil];
  200103. [[NSPasteboard generalPasteboard] setString: juceStringToNS (text)
  200104. forType: NSStringPboardType];
  200105. #endif
  200106. }
  200107. const String SystemClipboard::getTextFromClipboard() throw()
  200108. {
  200109. #if JUCE_IPHONE
  200110. NSString* text = [[UIPasteboard generalPasteboard] valueForPasteboardType: @"public.text"];
  200111. #else
  200112. NSString* text = [[NSPasteboard generalPasteboard] stringForType: NSStringPboardType];
  200113. #endif
  200114. return text == 0 ? String::empty
  200115. : nsStringToJuce (text);
  200116. }
  200117. #endif
  200118. #endif
  200119. /*** End of inlined file: juce_mac_Strings.mm ***/
  200120. /*** Start of inlined file: juce_mac_SystemStats.mm ***/
  200121. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200122. // compiled on its own).
  200123. #if JUCE_INCLUDED_FILE
  200124. static int64 highResTimerFrequency = 0;
  200125. static double highResTimerToMillisecRatio = 0;
  200126. #if JUCE_INTEL
  200127. static void juce_getCpuVendor (char* const v) throw()
  200128. {
  200129. int vendor[4];
  200130. zerostruct (vendor);
  200131. int dummy = 0;
  200132. asm ("mov %%ebx, %%esi \n\t"
  200133. "cpuid \n\t"
  200134. "xchg %%esi, %%ebx"
  200135. : "=a" (dummy), "=S" (vendor[0]), "=c" (vendor[2]), "=d" (vendor[1]) : "a" (0));
  200136. memcpy (v, vendor, 16);
  200137. }
  200138. static unsigned int getCPUIDWord (unsigned int& familyModel, unsigned int& extFeatures)
  200139. {
  200140. unsigned int cpu = 0;
  200141. unsigned int ext = 0;
  200142. unsigned int family = 0;
  200143. unsigned int dummy = 0;
  200144. asm ("mov %%ebx, %%esi \n\t"
  200145. "cpuid \n\t"
  200146. "xchg %%esi, %%ebx"
  200147. : "=a" (family), "=S" (ext), "=c" (dummy), "=d" (cpu) : "a" (1));
  200148. familyModel = family;
  200149. extFeatures = ext;
  200150. return cpu;
  200151. }
  200152. struct CPUFlags
  200153. {
  200154. bool hasMMX : 1;
  200155. bool hasSSE : 1;
  200156. bool hasSSE2 : 1;
  200157. bool has3DNow : 1;
  200158. };
  200159. static CPUFlags cpuFlags;
  200160. #endif
  200161. void SystemStats::initialiseStats() throw()
  200162. {
  200163. static bool initialised = false;
  200164. if (! initialised)
  200165. {
  200166. initialised = true;
  200167. #if JUCE_MAC
  200168. // extremely annoying: adding this line stops the apple menu items from working. Of
  200169. // course, not adding it means that carbon windows (e.g. in plugins) won't get
  200170. // any events.
  200171. //NSApplicationLoad();
  200172. [NSApplication sharedApplication];
  200173. #endif
  200174. #if JUCE_INTEL
  200175. {
  200176. unsigned int familyModel, extFeatures;
  200177. const unsigned int features = getCPUIDWord (familyModel, extFeatures);
  200178. cpuFlags.hasMMX = ((features & (1 << 23)) != 0);
  200179. cpuFlags.hasSSE = ((features & (1 << 25)) != 0);
  200180. cpuFlags.hasSSE2 = ((features & (1 << 26)) != 0);
  200181. cpuFlags.has3DNow = ((extFeatures & (1 << 31)) != 0);
  200182. }
  200183. #endif
  200184. mach_timebase_info_data_t timebase;
  200185. (void) mach_timebase_info (&timebase);
  200186. highResTimerFrequency = (int64) (1.0e9 * timebase.denom / timebase.numer);
  200187. highResTimerToMillisecRatio = timebase.numer / (1.0e6 * timebase.denom);
  200188. String s (SystemStats::getJUCEVersion());
  200189. rlimit lim;
  200190. getrlimit (RLIMIT_NOFILE, &lim);
  200191. lim.rlim_cur = lim.rlim_max = RLIM_INFINITY;
  200192. setrlimit (RLIMIT_NOFILE, &lim);
  200193. }
  200194. }
  200195. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  200196. {
  200197. return MacOSX;
  200198. }
  200199. const String SystemStats::getOperatingSystemName() throw()
  200200. {
  200201. return T("Mac OS X");
  200202. }
  200203. bool SystemStats::isOperatingSystem64Bit() throw()
  200204. {
  200205. #if JUCE_64BIT
  200206. return true;
  200207. #else
  200208. //xxx not sure how to find this out?..
  200209. return false;
  200210. #endif
  200211. }
  200212. int SystemStats::getMemorySizeInMegabytes() throw()
  200213. {
  200214. uint64 mem = 0;
  200215. size_t memSize = sizeof (mem);
  200216. int mib[] = { CTL_HW, HW_MEMSIZE };
  200217. sysctl (mib, 2, &mem, &memSize, 0, 0);
  200218. return (int) (mem / (1024 * 1024));
  200219. }
  200220. bool SystemStats::hasMMX() throw()
  200221. {
  200222. #if JUCE_INTEL
  200223. return cpuFlags.hasMMX;
  200224. #else
  200225. return false;
  200226. #endif
  200227. }
  200228. bool SystemStats::hasSSE() throw()
  200229. {
  200230. #if JUCE_INTEL
  200231. return cpuFlags.hasSSE;
  200232. #else
  200233. return false;
  200234. #endif
  200235. }
  200236. bool SystemStats::hasSSE2() throw()
  200237. {
  200238. #if JUCE_INTEL
  200239. return cpuFlags.hasSSE2;
  200240. #else
  200241. return false;
  200242. #endif
  200243. }
  200244. bool SystemStats::has3DNow() throw()
  200245. {
  200246. #if JUCE_INTEL
  200247. return cpuFlags.has3DNow;
  200248. #else
  200249. return false;
  200250. #endif
  200251. }
  200252. const String SystemStats::getCpuVendor() throw()
  200253. {
  200254. #if JUCE_INTEL
  200255. char v [16];
  200256. juce_getCpuVendor (v);
  200257. return String (v, 16);
  200258. #else
  200259. return String::empty;
  200260. #endif
  200261. }
  200262. int SystemStats::getCpuSpeedInMegaherz() throw()
  200263. {
  200264. uint64 speedHz = 0;
  200265. size_t speedSize = sizeof (speedHz);
  200266. int mib[] = { CTL_HW, HW_CPU_FREQ };
  200267. sysctl (mib, 2, &speedHz, &speedSize, 0, 0);
  200268. #if JUCE_BIG_ENDIAN
  200269. if (speedSize == 4)
  200270. speedHz >>= 32;
  200271. #endif
  200272. return (int) (speedHz / 1000000);
  200273. }
  200274. int SystemStats::getNumCpus() throw()
  200275. {
  200276. #if JUCE_IPHONE || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5)
  200277. return (int) [[NSProcessInfo processInfo] activeProcessorCount];
  200278. #else
  200279. return MPProcessors();
  200280. #endif
  200281. }
  200282. const String SystemStats::getLogonName()
  200283. {
  200284. return nsStringToJuce (NSUserName());
  200285. }
  200286. const String SystemStats::getFullUserName()
  200287. {
  200288. return nsStringToJuce (NSFullUserName());
  200289. }
  200290. uint32 juce_millisecondsSinceStartup() throw()
  200291. {
  200292. return (uint32) (mach_absolute_time() * highResTimerToMillisecRatio);
  200293. }
  200294. double Time::getMillisecondCounterHiRes() throw()
  200295. {
  200296. return mach_absolute_time() * highResTimerToMillisecRatio;
  200297. }
  200298. int64 Time::getHighResolutionTicks() throw()
  200299. {
  200300. return (int64) mach_absolute_time();
  200301. }
  200302. int64 Time::getHighResolutionTicksPerSecond() throw()
  200303. {
  200304. return highResTimerFrequency;
  200305. }
  200306. int64 SystemStats::getClockCycleCounter() throw()
  200307. {
  200308. return (int64) mach_absolute_time();
  200309. }
  200310. bool Time::setSystemTimeToThisTime() const throw()
  200311. {
  200312. jassertfalse
  200313. return false;
  200314. }
  200315. int SystemStats::getPageSize() throw()
  200316. {
  200317. return (int) NSPageSize();
  200318. }
  200319. void PlatformUtilities::fpuReset()
  200320. {
  200321. }
  200322. #endif
  200323. /*** End of inlined file: juce_mac_SystemStats.mm ***/
  200324. /*** Start of inlined file: juce_mac_Network.mm ***/
  200325. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200326. // compiled on its own).
  200327. #if JUCE_INCLUDED_FILE
  200328. int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian) throw()
  200329. {
  200330. #ifndef IFT_ETHER
  200331. #define IFT_ETHER 6
  200332. #endif
  200333. ifaddrs* addrs = 0;
  200334. int numResults = 0;
  200335. if (getifaddrs (&addrs) == 0)
  200336. {
  200337. const ifaddrs* cursor = addrs;
  200338. while (cursor != 0 && numResults < maxNum)
  200339. {
  200340. sockaddr_storage* sto = (sockaddr_storage*) cursor->ifa_addr;
  200341. if (sto->ss_family == AF_LINK)
  200342. {
  200343. const sockaddr_dl* const sadd = (const sockaddr_dl*) cursor->ifa_addr;
  200344. if (sadd->sdl_type == IFT_ETHER)
  200345. {
  200346. const uint8* const addr = ((const uint8*) sadd->sdl_data) + sadd->sdl_nlen;
  200347. uint64 a = 0;
  200348. for (int i = 6; --i >= 0;)
  200349. a = (a << 8) | addr [littleEndian ? i : (5 - i)];
  200350. *addresses++ = (int64) a;
  200351. ++numResults;
  200352. }
  200353. }
  200354. cursor = cursor->ifa_next;
  200355. }
  200356. freeifaddrs (addrs);
  200357. }
  200358. return numResults;
  200359. }
  200360. bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
  200361. const String& emailSubject,
  200362. const String& bodyText,
  200363. const StringArray& filesToAttach)
  200364. {
  200365. #if JUCE_IPHONE
  200366. //xxx probably need to use MFMailComposeViewController
  200367. jassertfalse
  200368. return false;
  200369. #else
  200370. const ScopedAutoReleasePool pool;
  200371. String script;
  200372. script << "tell application \"Mail\"\r\n"
  200373. "set newMessage to make new outgoing message with properties {subject:\""
  200374. << emailSubject.replace (T("\""), T("\\\""))
  200375. << "\", content:\""
  200376. << bodyText.replace (T("\""), T("\\\""))
  200377. << "\" & return & return}\r\n"
  200378. "tell newMessage\r\n"
  200379. "set visible to true\r\n"
  200380. "set sender to \"sdfsdfsdfewf\"\r\n"
  200381. "make new to recipient at end of to recipients with properties {address:\""
  200382. << targetEmailAddress
  200383. << "\"}\r\n";
  200384. for (int i = 0; i < filesToAttach.size(); ++i)
  200385. {
  200386. script << "tell content\r\n"
  200387. "make new attachment with properties {file name:\""
  200388. << filesToAttach[i].replace (T("\""), T("\\\""))
  200389. << "\"} at after the last paragraph\r\n"
  200390. "end tell\r\n";
  200391. }
  200392. script << "end tell\r\n"
  200393. "end tell\r\n";
  200394. NSAppleScript* s = [[NSAppleScript alloc]
  200395. initWithSource: juceStringToNS (script)];
  200396. NSDictionary* error = 0;
  200397. const bool ok = [s executeAndReturnError: &error] != nil;
  200398. [s release];
  200399. return ok;
  200400. #endif
  200401. }
  200402. END_JUCE_NAMESPACE
  200403. using namespace JUCE_NAMESPACE;
  200404. #define JuceURLConnection MakeObjCClassName(JuceURLConnection)
  200405. @interface JuceURLConnection : NSObject
  200406. {
  200407. @public
  200408. NSURLRequest* request;
  200409. NSURLConnection* connection;
  200410. NSMutableData* data;
  200411. Thread* runLoopThread;
  200412. bool initialised, hasFailed, hasFinished;
  200413. int position;
  200414. int64 contentLength;
  200415. NSLock* dataLock;
  200416. }
  200417. - (JuceURLConnection*) initWithRequest: (NSURLRequest*) req withCallback: (URL::OpenStreamProgressCallback*) callback withContext: (void*) context;
  200418. - (void) dealloc;
  200419. - (void) connection: (NSURLConnection*) connection didReceiveResponse: (NSURLResponse*) response;
  200420. - (void) connection: (NSURLConnection*) connection didFailWithError: (NSError*) error;
  200421. - (void) connection: (NSURLConnection*) connection didReceiveData: (NSData*) data;
  200422. - (void) connectionDidFinishLoading: (NSURLConnection*) connection;
  200423. - (BOOL) isOpen;
  200424. - (int) read: (char*) dest numBytes: (int) num;
  200425. - (int) readPosition;
  200426. - (void) stop;
  200427. - (void) createConnection;
  200428. @end
  200429. class JuceURLConnectionMessageThread : public Thread
  200430. {
  200431. JuceURLConnection* owner;
  200432. public:
  200433. JuceURLConnectionMessageThread (JuceURLConnection* owner_)
  200434. : Thread (T("http connection")),
  200435. owner (owner_)
  200436. {
  200437. }
  200438. ~JuceURLConnectionMessageThread()
  200439. {
  200440. stopThread (10000);
  200441. }
  200442. void run()
  200443. {
  200444. [owner createConnection];
  200445. while (! threadShouldExit())
  200446. {
  200447. const ScopedAutoReleasePool pool;
  200448. [[NSRunLoop currentRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.01]];
  200449. }
  200450. }
  200451. };
  200452. @implementation JuceURLConnection
  200453. - (JuceURLConnection*) initWithRequest: (NSURLRequest*) req
  200454. withCallback: (URL::OpenStreamProgressCallback*) callback
  200455. withContext: (void*) context;
  200456. {
  200457. [super init];
  200458. request = req;
  200459. [request retain];
  200460. data = [[NSMutableData data] retain];
  200461. dataLock = [[NSLock alloc] init];
  200462. connection = 0;
  200463. initialised = false;
  200464. hasFailed = false;
  200465. hasFinished = false;
  200466. contentLength = -1;
  200467. runLoopThread = new JuceURLConnectionMessageThread (self);
  200468. runLoopThread->startThread();
  200469. while (runLoopThread->isThreadRunning() && ! initialised)
  200470. {
  200471. if (callback != 0)
  200472. callback (context, -1, (int) [[request HTTPBody] length]);
  200473. Thread::sleep (1);
  200474. }
  200475. return self;
  200476. }
  200477. - (void) dealloc
  200478. {
  200479. [self stop];
  200480. delete runLoopThread;
  200481. [connection release];
  200482. [data release];
  200483. [dataLock release];
  200484. [request release];
  200485. [super dealloc];
  200486. }
  200487. - (void) createConnection
  200488. {
  200489. connection = [[NSURLConnection alloc] initWithRequest: request
  200490. delegate: [self retain]];
  200491. if (connection == nil)
  200492. runLoopThread->signalThreadShouldExit();
  200493. }
  200494. - (void) connection: (NSURLConnection*) connection didReceiveResponse: (NSURLResponse*) response
  200495. {
  200496. [dataLock lock];
  200497. [data setLength: 0];
  200498. [dataLock unlock];
  200499. initialised = true;
  200500. contentLength = [response expectedContentLength];
  200501. }
  200502. - (void) connection: (NSURLConnection*) connection didFailWithError: (NSError*) error
  200503. {
  200504. DBG (nsStringToJuce ([error description]));
  200505. hasFailed = true;
  200506. initialised = true;
  200507. runLoopThread->signalThreadShouldExit();
  200508. }
  200509. - (void) connection: (NSURLConnection*) connection didReceiveData: (NSData*) newData
  200510. {
  200511. [dataLock lock];
  200512. [data appendData: newData];
  200513. [dataLock unlock];
  200514. initialised = true;
  200515. }
  200516. - (void) connectionDidFinishLoading: (NSURLConnection*) connection
  200517. {
  200518. hasFinished = true;
  200519. initialised = true;
  200520. runLoopThread->signalThreadShouldExit();
  200521. }
  200522. - (BOOL) isOpen
  200523. {
  200524. return connection != 0 && ! hasFailed;
  200525. }
  200526. - (int) readPosition
  200527. {
  200528. return position;
  200529. }
  200530. - (int) read: (char*) dest numBytes: (int) numNeeded
  200531. {
  200532. int numDone = 0;
  200533. while (numNeeded > 0)
  200534. {
  200535. int available = jmin (numNeeded, (int) [data length]);
  200536. if (available > 0)
  200537. {
  200538. [dataLock lock];
  200539. [data getBytes: dest length: available];
  200540. [data replaceBytesInRange: NSMakeRange (0, available) withBytes: nil length: 0];
  200541. [dataLock unlock];
  200542. numDone += available;
  200543. numNeeded -= available;
  200544. dest += available;
  200545. }
  200546. else
  200547. {
  200548. if (hasFailed || hasFinished)
  200549. break;
  200550. Thread::sleep (1);
  200551. }
  200552. }
  200553. position += numDone;
  200554. return numDone;
  200555. }
  200556. - (void) stop
  200557. {
  200558. [connection cancel];
  200559. runLoopThread->stopThread (10000);
  200560. }
  200561. @end
  200562. BEGIN_JUCE_NAMESPACE
  200563. bool juce_isOnLine()
  200564. {
  200565. return true;
  200566. }
  200567. void* juce_openInternetFile (const String& url,
  200568. const String& headers,
  200569. const MemoryBlock& postData,
  200570. const bool isPost,
  200571. URL::OpenStreamProgressCallback* callback,
  200572. void* callbackContext,
  200573. int timeOutMs)
  200574. {
  200575. const ScopedAutoReleasePool pool;
  200576. NSMutableURLRequest* req = [NSMutableURLRequest
  200577. requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
  200578. cachePolicy: NSURLRequestUseProtocolCachePolicy
  200579. timeoutInterval: timeOutMs <= 0 ? 60.0 : (timeOutMs / 1000.0)];
  200580. if (req == nil)
  200581. return 0;
  200582. [req setHTTPMethod: isPost ? @"POST" : @"GET"];
  200583. //[req setCachePolicy: NSURLRequestReloadIgnoringLocalAndRemoteCacheData];
  200584. StringArray headerLines;
  200585. headerLines.addLines (headers);
  200586. headerLines.removeEmptyStrings (true);
  200587. for (int i = 0; i < headerLines.size(); ++i)
  200588. {
  200589. const String key (headerLines[i].upToFirstOccurrenceOf (T(":"), false, false).trim());
  200590. const String value (headerLines[i].fromFirstOccurrenceOf (T(":"), false, false).trim());
  200591. if (key.isNotEmpty() && value.isNotEmpty())
  200592. [req addValue: juceStringToNS (value) forHTTPHeaderField: juceStringToNS (key)];
  200593. }
  200594. if (isPost && postData.getSize() > 0)
  200595. {
  200596. [req setHTTPBody: [NSData dataWithBytes: postData.getData()
  200597. length: postData.getSize()]];
  200598. }
  200599. JuceURLConnection* const s = [[JuceURLConnection alloc] initWithRequest: req
  200600. withCallback: callback
  200601. withContext: callbackContext];
  200602. if ([s isOpen])
  200603. return s;
  200604. [s release];
  200605. return 0;
  200606. }
  200607. void juce_closeInternetFile (void* handle)
  200608. {
  200609. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200610. if (s != 0)
  200611. {
  200612. const ScopedAutoReleasePool pool;
  200613. [s stop];
  200614. [s release];
  200615. }
  200616. }
  200617. int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead)
  200618. {
  200619. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200620. if (s != 0)
  200621. {
  200622. const ScopedAutoReleasePool pool;
  200623. return [s read: (char*) buffer numBytes: bytesToRead];
  200624. }
  200625. return 0;
  200626. }
  200627. int64 juce_getInternetFileContentLength (void* handle)
  200628. {
  200629. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200630. if (s != 0)
  200631. return s->contentLength;
  200632. return -1;
  200633. }
  200634. int juce_seekInInternetFile (void* handle, int newPosition)
  200635. {
  200636. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200637. if (s != 0)
  200638. return [s readPosition];
  200639. return 0;
  200640. }
  200641. #endif
  200642. /*** End of inlined file: juce_mac_Network.mm ***/
  200643. /*** Start of inlined file: juce_posix_NamedPipe.cpp ***/
  200644. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200645. // compiled on its own).
  200646. #if JUCE_INCLUDED_FILE
  200647. struct NamedPipeInternal
  200648. {
  200649. String pipeInName, pipeOutName;
  200650. int pipeIn, pipeOut;
  200651. bool volatile createdPipe, blocked, stopReadOperation;
  200652. static void signalHandler (int) {}
  200653. };
  200654. void NamedPipe::cancelPendingReads()
  200655. {
  200656. while (internal != 0 && ((NamedPipeInternal*) internal)->blocked)
  200657. {
  200658. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200659. intern->stopReadOperation = true;
  200660. char buffer [1] = { 0 };
  200661. int bytesWritten = (int) ::write (intern->pipeIn, buffer, 1);
  200662. (void) bytesWritten;
  200663. int timeout = 2000;
  200664. while (intern->blocked && --timeout >= 0)
  200665. Thread::sleep (2);
  200666. intern->stopReadOperation = false;
  200667. }
  200668. }
  200669. void NamedPipe::close()
  200670. {
  200671. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200672. if (intern != 0)
  200673. {
  200674. internal = 0;
  200675. if (intern->pipeIn != -1)
  200676. ::close (intern->pipeIn);
  200677. if (intern->pipeOut != -1)
  200678. ::close (intern->pipeOut);
  200679. if (intern->createdPipe)
  200680. {
  200681. unlink (intern->pipeInName);
  200682. unlink (intern->pipeOutName);
  200683. }
  200684. delete intern;
  200685. }
  200686. }
  200687. bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
  200688. {
  200689. close();
  200690. NamedPipeInternal* const intern = new NamedPipeInternal();
  200691. internal = intern;
  200692. intern->createdPipe = createPipe;
  200693. intern->blocked = false;
  200694. intern->stopReadOperation = false;
  200695. signal (SIGPIPE, NamedPipeInternal::signalHandler);
  200696. siginterrupt (SIGPIPE, 1);
  200697. const String pipePath (T("/tmp/") + File::createLegalFileName (pipeName));
  200698. intern->pipeInName = pipePath + T("_in");
  200699. intern->pipeOutName = pipePath + T("_out");
  200700. intern->pipeIn = -1;
  200701. intern->pipeOut = -1;
  200702. if (createPipe)
  200703. {
  200704. if ((mkfifo (intern->pipeInName, 0666) && errno != EEXIST)
  200705. || (mkfifo (intern->pipeOutName, 0666) && errno != EEXIST))
  200706. {
  200707. delete intern;
  200708. internal = 0;
  200709. return false;
  200710. }
  200711. }
  200712. return true;
  200713. }
  200714. int NamedPipe::read (void* destBuffer, int maxBytesToRead, int /*timeOutMilliseconds*/)
  200715. {
  200716. int bytesRead = -1;
  200717. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200718. if (intern != 0)
  200719. {
  200720. intern->blocked = true;
  200721. if (intern->pipeIn == -1)
  200722. {
  200723. if (intern->createdPipe)
  200724. intern->pipeIn = ::open (intern->pipeInName, O_RDWR);
  200725. else
  200726. intern->pipeIn = ::open (intern->pipeOutName, O_RDWR);
  200727. if (intern->pipeIn == -1)
  200728. {
  200729. intern->blocked = false;
  200730. return -1;
  200731. }
  200732. }
  200733. bytesRead = 0;
  200734. char* p = (char*) destBuffer;
  200735. while (bytesRead < maxBytesToRead)
  200736. {
  200737. const int bytesThisTime = maxBytesToRead - bytesRead;
  200738. const int numRead = (int) ::read (intern->pipeIn, p, bytesThisTime);
  200739. if (numRead <= 0 || intern->stopReadOperation)
  200740. {
  200741. bytesRead = -1;
  200742. break;
  200743. }
  200744. bytesRead += numRead;
  200745. p += bytesRead;
  200746. }
  200747. intern->blocked = false;
  200748. }
  200749. return bytesRead;
  200750. }
  200751. int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
  200752. {
  200753. int bytesWritten = -1;
  200754. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200755. if (intern != 0)
  200756. {
  200757. if (intern->pipeOut == -1)
  200758. {
  200759. if (intern->createdPipe)
  200760. intern->pipeOut = ::open (intern->pipeOutName, O_WRONLY);
  200761. else
  200762. intern->pipeOut = ::open (intern->pipeInName, O_WRONLY);
  200763. if (intern->pipeOut == -1)
  200764. {
  200765. return -1;
  200766. }
  200767. }
  200768. const char* p = (const char*) sourceBuffer;
  200769. bytesWritten = 0;
  200770. const uint32 timeOutTime = Time::getMillisecondCounter() + timeOutMilliseconds;
  200771. while (bytesWritten < numBytesToWrite
  200772. && (timeOutMilliseconds < 0 || Time::getMillisecondCounter() < timeOutTime))
  200773. {
  200774. const int bytesThisTime = numBytesToWrite - bytesWritten;
  200775. const int numWritten = (int) ::write (intern->pipeOut, p, bytesThisTime);
  200776. if (numWritten <= 0)
  200777. {
  200778. bytesWritten = -1;
  200779. break;
  200780. }
  200781. bytesWritten += numWritten;
  200782. p += bytesWritten;
  200783. }
  200784. }
  200785. return bytesWritten;
  200786. }
  200787. #endif
  200788. /*** End of inlined file: juce_posix_NamedPipe.cpp ***/
  200789. /*** Start of inlined file: juce_mac_Threads.mm ***/
  200790. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200791. // compiled on its own).
  200792. #if JUCE_INCLUDED_FILE
  200793. void JUCE_API juce_threadEntryPoint (void*);
  200794. void* threadEntryProc (void* userData)
  200795. {
  200796. const ScopedAutoReleasePool pool;
  200797. juce_threadEntryPoint (userData);
  200798. return 0;
  200799. }
  200800. void* juce_createThread (void* userData)
  200801. {
  200802. pthread_t handle = 0;
  200803. if (pthread_create (&handle, 0, threadEntryProc, userData) == 0)
  200804. {
  200805. pthread_detach (handle);
  200806. return (void*) handle;
  200807. }
  200808. return 0;
  200809. }
  200810. void juce_killThread (void* handle)
  200811. {
  200812. if (handle != 0)
  200813. pthread_cancel ((pthread_t) handle);
  200814. }
  200815. void juce_setCurrentThreadName (const String& /*name*/)
  200816. {
  200817. }
  200818. Thread::ThreadID Thread::getCurrentThreadId()
  200819. {
  200820. return (ThreadID) pthread_self();
  200821. }
  200822. bool juce_setThreadPriority (void* handle, int priority)
  200823. {
  200824. if (handle == 0)
  200825. handle = (void*) pthread_self();
  200826. struct sched_param param;
  200827. int policy;
  200828. pthread_getschedparam ((pthread_t) handle, &policy, &param);
  200829. param.sched_priority = jlimit (1, 127, 1 + (priority * 126) / 11);
  200830. return pthread_setschedparam ((pthread_t) handle, policy, &param) == 0;
  200831. }
  200832. void Thread::yield()
  200833. {
  200834. sched_yield();
  200835. }
  200836. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
  200837. {
  200838. // xxx
  200839. jassertfalse
  200840. }
  200841. bool Process::isForegroundProcess()
  200842. {
  200843. #if JUCE_MAC
  200844. return [NSApp isActive];
  200845. #else
  200846. return true; // xxx change this if more than one app is ever possible on the iPhone!
  200847. #endif
  200848. }
  200849. void Process::raisePrivilege()
  200850. {
  200851. jassertfalse
  200852. }
  200853. void Process::lowerPrivilege()
  200854. {
  200855. jassertfalse
  200856. }
  200857. void Process::terminate()
  200858. {
  200859. exit (0);
  200860. }
  200861. void Process::setPriority (ProcessPriority p)
  200862. {
  200863. // xxx
  200864. }
  200865. #endif
  200866. /*** End of inlined file: juce_mac_Threads.mm ***/
  200867. /*** Start of inlined file: juce_posix_SharedCode.h ***/
  200868. CriticalSection::CriticalSection() throw()
  200869. {
  200870. pthread_mutexattr_t atts;
  200871. pthread_mutexattr_init (&atts);
  200872. pthread_mutexattr_settype (&atts, PTHREAD_MUTEX_RECURSIVE);
  200873. pthread_mutex_init (&internal, &atts);
  200874. }
  200875. CriticalSection::~CriticalSection() throw()
  200876. {
  200877. pthread_mutex_destroy (&internal);
  200878. }
  200879. void CriticalSection::enter() const throw()
  200880. {
  200881. pthread_mutex_lock (&internal);
  200882. }
  200883. bool CriticalSection::tryEnter() const throw()
  200884. {
  200885. return pthread_mutex_trylock (&internal) == 0;
  200886. }
  200887. void CriticalSection::exit() const throw()
  200888. {
  200889. pthread_mutex_unlock (&internal);
  200890. }
  200891. struct EventStruct
  200892. {
  200893. pthread_cond_t condition;
  200894. pthread_mutex_t mutex;
  200895. bool triggered;
  200896. };
  200897. WaitableEvent::WaitableEvent() throw()
  200898. {
  200899. EventStruct* const es = new EventStruct();
  200900. es->triggered = false;
  200901. pthread_cond_init (&es->condition, 0);
  200902. pthread_mutex_init (&es->mutex, 0);
  200903. internal = es;
  200904. }
  200905. WaitableEvent::~WaitableEvent() throw()
  200906. {
  200907. EventStruct* const es = (EventStruct*) internal;
  200908. pthread_cond_destroy (&es->condition);
  200909. pthread_mutex_destroy (&es->mutex);
  200910. delete es;
  200911. }
  200912. bool WaitableEvent::wait (const int timeOutMillisecs) const throw()
  200913. {
  200914. EventStruct* const es = (EventStruct*) internal;
  200915. pthread_mutex_lock (&es->mutex);
  200916. if (timeOutMillisecs < 0)
  200917. {
  200918. while (! es->triggered)
  200919. pthread_cond_wait (&es->condition, &es->mutex);
  200920. }
  200921. else
  200922. {
  200923. while (! es->triggered)
  200924. {
  200925. struct timeval t;
  200926. gettimeofday (&t, 0);
  200927. struct timespec time;
  200928. time.tv_sec = t.tv_sec + (timeOutMillisecs / 1000);
  200929. time.tv_nsec = (t.tv_usec + ((timeOutMillisecs % 1000) * 1000)) * 1000;
  200930. if (time.tv_nsec >= 1000000000)
  200931. {
  200932. time.tv_nsec -= 1000000000;
  200933. time.tv_sec++;
  200934. }
  200935. if (pthread_cond_timedwait (&es->condition, &es->mutex, &time) == ETIMEDOUT)
  200936. {
  200937. pthread_mutex_unlock (&es->mutex);
  200938. return false;
  200939. }
  200940. }
  200941. }
  200942. es->triggered = false;
  200943. pthread_mutex_unlock (&es->mutex);
  200944. return true;
  200945. }
  200946. void WaitableEvent::signal() const throw()
  200947. {
  200948. EventStruct* const es = (EventStruct*) internal;
  200949. pthread_mutex_lock (&es->mutex);
  200950. es->triggered = true;
  200951. pthread_cond_broadcast (&es->condition);
  200952. pthread_mutex_unlock (&es->mutex);
  200953. }
  200954. void WaitableEvent::reset() const throw()
  200955. {
  200956. EventStruct* const es = (EventStruct*) internal;
  200957. pthread_mutex_lock (&es->mutex);
  200958. es->triggered = false;
  200959. pthread_mutex_unlock (&es->mutex);
  200960. }
  200961. void JUCE_CALLTYPE Thread::sleep (int millisecs)
  200962. {
  200963. struct timespec time;
  200964. time.tv_sec = millisecs / 1000;
  200965. time.tv_nsec = (millisecs % 1000) * 1000000;
  200966. nanosleep (&time, 0);
  200967. }
  200968. const tchar File::separator = T('/');
  200969. const tchar* File::separatorString = T("/");
  200970. bool juce_copyFile (const String& s, const String& d);
  200971. static bool juce_stat (const String& fileName, struct stat& info)
  200972. {
  200973. return fileName.isNotEmpty()
  200974. && (stat (fileName.toUTF8(), &info) == 0);
  200975. }
  200976. bool juce_isDirectory (const String& fileName)
  200977. {
  200978. struct stat info;
  200979. return fileName.isEmpty()
  200980. || (juce_stat (fileName, info)
  200981. && ((info.st_mode & S_IFDIR) != 0));
  200982. }
  200983. bool juce_fileExists (const String& fileName, const bool dontCountDirectories)
  200984. {
  200985. if (fileName.isEmpty())
  200986. return false;
  200987. const char* const fileNameUTF8 = fileName.toUTF8();
  200988. bool exists = access (fileNameUTF8, F_OK) == 0;
  200989. if (exists && dontCountDirectories)
  200990. {
  200991. struct stat info;
  200992. const int res = stat (fileNameUTF8, &info);
  200993. if (res == 0 && (info.st_mode & S_IFDIR) != 0)
  200994. exists = false;
  200995. }
  200996. return exists;
  200997. }
  200998. int64 juce_getFileSize (const String& fileName)
  200999. {
  201000. struct stat info;
  201001. return juce_stat (fileName, info) ? info.st_size : 0;
  201002. }
  201003. bool juce_canWriteToFile (const String& fileName)
  201004. {
  201005. return access (fileName.toUTF8(), W_OK) == 0;
  201006. }
  201007. bool juce_deleteFile (const String& fileName)
  201008. {
  201009. if (juce_isDirectory (fileName))
  201010. return rmdir ((const char*) fileName.toUTF8()) == 0;
  201011. else
  201012. return remove ((const char*) fileName.toUTF8()) == 0;
  201013. }
  201014. bool juce_moveFile (const String& source, const String& dest)
  201015. {
  201016. if (rename (source.toUTF8(), dest.toUTF8()) == 0)
  201017. return true;
  201018. if (juce_canWriteToFile (source)
  201019. && juce_copyFile (source, dest))
  201020. {
  201021. if (juce_deleteFile (source))
  201022. return true;
  201023. juce_deleteFile (dest);
  201024. }
  201025. return false;
  201026. }
  201027. void juce_createDirectory (const String& fileName)
  201028. {
  201029. mkdir (fileName.toUTF8(), 0777);
  201030. }
  201031. void* juce_fileOpen (const String& fileName, bool forWriting)
  201032. {
  201033. int flags = O_RDONLY;
  201034. if (forWriting)
  201035. {
  201036. if (juce_fileExists (fileName, false))
  201037. {
  201038. const int f = open ((const char*) fileName.toUTF8(), O_RDWR, 00644);
  201039. if (f != -1)
  201040. lseek (f, 0, SEEK_END);
  201041. return (void*) f;
  201042. }
  201043. else
  201044. {
  201045. flags = O_RDWR + O_CREAT;
  201046. }
  201047. }
  201048. return (void*) open ((const char*) fileName.toUTF8(), flags, 00644);
  201049. }
  201050. void juce_fileClose (void* handle)
  201051. {
  201052. if (handle != 0)
  201053. close ((int) (pointer_sized_int) handle);
  201054. }
  201055. int juce_fileRead (void* handle, void* buffer, int size)
  201056. {
  201057. if (handle != 0)
  201058. return (int) read ((int) (pointer_sized_int) handle, buffer, size);
  201059. return 0;
  201060. }
  201061. int juce_fileWrite (void* handle, const void* buffer, int size)
  201062. {
  201063. if (handle != 0)
  201064. return (int) write ((int) (pointer_sized_int) handle, buffer, size);
  201065. return 0;
  201066. }
  201067. int64 juce_fileSetPosition (void* handle, int64 pos)
  201068. {
  201069. if (handle != 0 && lseek ((int) (pointer_sized_int) handle, pos, SEEK_SET) == pos)
  201070. return pos;
  201071. return -1;
  201072. }
  201073. int64 juce_fileGetPosition (void* handle)
  201074. {
  201075. if (handle != 0)
  201076. return lseek ((int) (pointer_sized_int) handle, 0, SEEK_CUR);
  201077. else
  201078. return -1;
  201079. }
  201080. void juce_fileFlush (void* handle)
  201081. {
  201082. if (handle != 0)
  201083. fsync ((int) (pointer_sized_int) handle);
  201084. }
  201085. const File juce_getExecutableFile()
  201086. {
  201087. Dl_info exeInfo;
  201088. dladdr ((const void*) juce_getExecutableFile, &exeInfo);
  201089. return File (exeInfo.dli_fname);
  201090. }
  201091. // if this file doesn't exist, find a parent of it that does..
  201092. static bool doStatFS (const File* file, struct statfs& result)
  201093. {
  201094. File f (*file);
  201095. for (int i = 5; --i >= 0;)
  201096. {
  201097. if (f.exists())
  201098. break;
  201099. f = f.getParentDirectory();
  201100. }
  201101. return statfs (f.getFullPathName().toUTF8(), &result) == 0;
  201102. }
  201103. int64 File::getBytesFreeOnVolume() const
  201104. {
  201105. struct statfs buf;
  201106. if (doStatFS (this, buf))
  201107. return (int64) buf.f_bsize * (int64) buf.f_bavail; // Note: this returns space available to non-super user
  201108. return 0;
  201109. }
  201110. int64 File::getVolumeTotalSize() const
  201111. {
  201112. struct statfs buf;
  201113. if (doStatFS (this, buf))
  201114. return (int64) buf.f_bsize * (int64) buf.f_blocks;
  201115. return 0;
  201116. }
  201117. const String juce_getVolumeLabel (const String& filenameOnVolume,
  201118. int& volumeSerialNumber)
  201119. {
  201120. volumeSerialNumber = 0;
  201121. #if JUCE_MAC
  201122. struct VolAttrBuf
  201123. {
  201124. u_int32_t length;
  201125. attrreference_t mountPointRef;
  201126. char mountPointSpace [MAXPATHLEN];
  201127. } attrBuf;
  201128. struct attrlist attrList;
  201129. zerostruct (attrList);
  201130. attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
  201131. attrList.volattr = ATTR_VOL_INFO | ATTR_VOL_NAME;
  201132. File f (filenameOnVolume);
  201133. for (;;)
  201134. {
  201135. if (getattrlist ((const char*) f.getFullPathName().toUTF8(),
  201136. &attrList, &attrBuf, sizeof(attrBuf), 0) == 0)
  201137. {
  201138. return String::fromUTF8 (((const uint8*) &attrBuf.mountPointRef) + attrBuf.mountPointRef.attr_dataoffset,
  201139. (int) attrBuf.mountPointRef.attr_length);
  201140. }
  201141. const File parent (f.getParentDirectory());
  201142. if (f == parent)
  201143. break;
  201144. f = parent;
  201145. }
  201146. #endif
  201147. return String::empty;
  201148. }
  201149. void juce_runSystemCommand (const String& command)
  201150. {
  201151. int result = system ((const char*) command.toUTF8());
  201152. (void) result;
  201153. }
  201154. const String juce_getOutputFromCommand (const String& command)
  201155. {
  201156. // slight bodge here, as we just pipe the output into a temp file and read it...
  201157. const File tempFile (File::getSpecialLocation (File::tempDirectory)
  201158. .getNonexistentChildFile (String::toHexString (Random::getSystemRandom().nextInt()), ".tmp", false));
  201159. juce_runSystemCommand (command + " > " + tempFile.getFullPathName());
  201160. String result (tempFile.loadFileAsString());
  201161. tempFile.deleteFile();
  201162. return result;
  201163. }
  201164. InterProcessLock::InterProcessLock (const String& name_)
  201165. : internal (0),
  201166. name (name_),
  201167. reentrancyLevel (0)
  201168. {
  201169. #if JUCE_MAC
  201170. // (don't use getSpecialLocation() to avoid the temp folder being different for each app)
  201171. const File temp (File (T("~/Library/Caches/Juce")).getChildFile (name));
  201172. #else
  201173. const File temp (File::getSpecialLocation (File::tempDirectory).getChildFile (name));
  201174. #endif
  201175. temp.create();
  201176. internal = open (temp.getFullPathName().toUTF8(), O_RDWR);
  201177. }
  201178. InterProcessLock::~InterProcessLock()
  201179. {
  201180. while (reentrancyLevel > 0)
  201181. this->exit();
  201182. close (internal);
  201183. }
  201184. bool InterProcessLock::enter (const int timeOutMillisecs)
  201185. {
  201186. if (internal == 0)
  201187. return false;
  201188. if (reentrancyLevel != 0)
  201189. return true;
  201190. const int64 endTime = Time::currentTimeMillis() + timeOutMillisecs;
  201191. struct flock fl;
  201192. zerostruct (fl);
  201193. fl.l_whence = SEEK_SET;
  201194. fl.l_type = F_WRLCK;
  201195. for (;;)
  201196. {
  201197. const int result = fcntl (internal, F_SETLK, &fl);
  201198. if (result >= 0)
  201199. {
  201200. ++reentrancyLevel;
  201201. return true;
  201202. }
  201203. if (errno != EINTR)
  201204. {
  201205. if (timeOutMillisecs == 0
  201206. || (timeOutMillisecs > 0 && Time::currentTimeMillis() >= endTime))
  201207. break;
  201208. Thread::sleep (10);
  201209. }
  201210. }
  201211. return false;
  201212. }
  201213. void InterProcessLock::exit()
  201214. {
  201215. if (reentrancyLevel > 0 && internal != 0)
  201216. {
  201217. --reentrancyLevel;
  201218. struct flock fl;
  201219. zerostruct (fl);
  201220. fl.l_whence = SEEK_SET;
  201221. fl.l_type = F_UNLCK;
  201222. for (;;)
  201223. {
  201224. const int result = fcntl (internal, F_SETLKW, &fl);
  201225. if (result >= 0 || errno != EINTR)
  201226. break;
  201227. }
  201228. }
  201229. }
  201230. /*** End of inlined file: juce_posix_SharedCode.h ***/
  201231. /*** Start of inlined file: juce_mac_Files.mm ***/
  201232. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201233. // compiled on its own).
  201234. #if JUCE_INCLUDED_FILE
  201235. void juce_getFileTimes (const String& fileName,
  201236. int64& modificationTime,
  201237. int64& accessTime,
  201238. int64& creationTime)
  201239. {
  201240. modificationTime = 0;
  201241. accessTime = 0;
  201242. creationTime = 0;
  201243. struct stat info;
  201244. const int res = stat (fileName.toUTF8(), &info);
  201245. if (res == 0)
  201246. {
  201247. modificationTime = (int64) info.st_mtime * 1000;
  201248. accessTime = (int64) info.st_atime * 1000;
  201249. creationTime = (int64) info.st_ctime * 1000;
  201250. }
  201251. }
  201252. bool juce_setFileTimes (const String& fileName,
  201253. int64 modificationTime,
  201254. int64 accessTime,
  201255. int64 creationTime)
  201256. {
  201257. struct utimbuf times;
  201258. times.actime = (time_t) (accessTime / 1000);
  201259. times.modtime = (time_t) (modificationTime / 1000);
  201260. return utime (fileName.toUTF8(), &times) == 0;
  201261. }
  201262. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly)
  201263. {
  201264. struct stat info;
  201265. const int res = stat (fileName.toUTF8(), &info);
  201266. if (res != 0)
  201267. return false;
  201268. info.st_mode &= 0777; // Just permissions
  201269. if (isReadOnly)
  201270. info.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
  201271. else
  201272. // Give everybody write permission?
  201273. info.st_mode |= S_IWUSR | S_IWGRP | S_IWOTH;
  201274. return chmod (fileName.toUTF8(), info.st_mode) == 0;
  201275. }
  201276. bool juce_copyFile (const String& src, const String& dst)
  201277. {
  201278. const ScopedAutoReleasePool pool;
  201279. NSFileManager* fm = [NSFileManager defaultManager];
  201280. return [fm fileExistsAtPath: juceStringToNS (src)]
  201281. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  201282. && [fm copyItemAtPath: juceStringToNS (src)
  201283. toPath: juceStringToNS (dst)
  201284. error: nil];
  201285. #else
  201286. && [fm copyPath: juceStringToNS (src)
  201287. toPath: juceStringToNS (dst)
  201288. handler: nil];
  201289. #endif
  201290. }
  201291. const StringArray juce_getFileSystemRoots()
  201292. {
  201293. StringArray s;
  201294. s.add (T("/"));
  201295. return s;
  201296. }
  201297. static bool isFileOnDriveType (const File* const f, const char** types)
  201298. {
  201299. struct statfs buf;
  201300. if (doStatFS (f, buf))
  201301. {
  201302. const String type (buf.f_fstypename);
  201303. while (*types != 0)
  201304. if (type.equalsIgnoreCase (*types++))
  201305. return true;
  201306. }
  201307. return false;
  201308. }
  201309. bool File::isOnCDRomDrive() const
  201310. {
  201311. static const char* const cdTypes[] = { "cd9660", "cdfs", "cddafs", "udf", 0 };
  201312. return isFileOnDriveType (this, (const char**) cdTypes);
  201313. }
  201314. bool File::isOnHardDisk() const
  201315. {
  201316. static const char* const nonHDTypes[] = { "nfs", "smbfs", "ramfs", 0 };
  201317. return ! (isOnCDRomDrive() || isFileOnDriveType (this, (const char**) nonHDTypes));
  201318. }
  201319. bool File::isOnRemovableDrive() const
  201320. {
  201321. #if JUCE_IPHONE
  201322. return false; // xxx is this possible?
  201323. #else
  201324. const ScopedAutoReleasePool pool;
  201325. BOOL removable = false;
  201326. [[NSWorkspace sharedWorkspace]
  201327. getFileSystemInfoForPath: juceStringToNS (getFullPathName())
  201328. isRemovable: &removable
  201329. isWritable: nil
  201330. isUnmountable: nil
  201331. description: nil
  201332. type: nil];
  201333. return removable;
  201334. #endif
  201335. }
  201336. static bool juce_isHiddenFile (const String& path)
  201337. {
  201338. #if JUCE_IPHONE
  201339. return File (path).getFileName().startsWithChar (T('.'));
  201340. #else
  201341. FSRef ref;
  201342. if (! PlatformUtilities::makeFSRefFromPath (&ref, path))
  201343. return false;
  201344. FSCatalogInfo info;
  201345. FSGetCatalogInfo (&ref, kFSCatInfoNodeFlags | kFSCatInfoFinderInfo, &info, 0, 0, 0);
  201346. if ((info.nodeFlags & kFSNodeIsDirectoryBit) != 0)
  201347. return (((FolderInfo*) &info.finderInfo)->finderFlags & kIsInvisible) != 0;
  201348. return (((FileInfo*) &info.finderInfo)->finderFlags & kIsInvisible) != 0;
  201349. #endif
  201350. }
  201351. bool File::isHidden() const
  201352. {
  201353. return juce_isHiddenFile (getFullPathName());
  201354. }
  201355. const char* juce_Argv0 = 0; // referenced from juce_Application.cpp
  201356. const File File::getSpecialLocation (const SpecialLocationType type)
  201357. {
  201358. const ScopedAutoReleasePool pool;
  201359. String resultPath;
  201360. switch (type)
  201361. {
  201362. case userHomeDirectory:
  201363. resultPath = nsStringToJuce (NSHomeDirectory());
  201364. break;
  201365. case userDocumentsDirectory:
  201366. resultPath = "~/Documents";
  201367. break;
  201368. case userDesktopDirectory:
  201369. resultPath = "~/Desktop";
  201370. break;
  201371. case userApplicationDataDirectory:
  201372. resultPath = "~/Library";
  201373. break;
  201374. case commonApplicationDataDirectory:
  201375. resultPath = "/Library";
  201376. break;
  201377. case globalApplicationsDirectory:
  201378. resultPath = "/Applications";
  201379. break;
  201380. case userMusicDirectory:
  201381. resultPath = "~/Music";
  201382. break;
  201383. case userMoviesDirectory:
  201384. resultPath = "~/Movies";
  201385. break;
  201386. case tempDirectory:
  201387. {
  201388. File tmp (T("~/Library/Caches/") + juce_getExecutableFile().getFileNameWithoutExtension());
  201389. tmp.createDirectory();
  201390. return tmp.getFullPathName();
  201391. }
  201392. case invokedExecutableFile:
  201393. if (juce_Argv0 != 0)
  201394. return File (String::fromUTF8 ((const uint8*) juce_Argv0));
  201395. // deliberate fall-through...
  201396. case currentExecutableFile:
  201397. return juce_getExecutableFile();
  201398. case currentApplicationFile:
  201399. {
  201400. const File exe (juce_getExecutableFile());
  201401. const File parent (exe.getParentDirectory());
  201402. return parent.getFullPathName().endsWithIgnoreCase (T("Contents/MacOS"))
  201403. ? parent.getParentDirectory().getParentDirectory()
  201404. : exe;
  201405. }
  201406. default:
  201407. jassertfalse // unknown type?
  201408. break;
  201409. }
  201410. if (resultPath != 0)
  201411. return File (PlatformUtilities::convertToPrecomposedUnicode (resultPath));
  201412. return File::nonexistent;
  201413. }
  201414. const File File::getCurrentWorkingDirectory()
  201415. {
  201416. char buf [2048];
  201417. getcwd (buf, sizeof(buf));
  201418. return File (PlatformUtilities::convertToPrecomposedUnicode (buf));
  201419. }
  201420. bool File::setAsCurrentWorkingDirectory() const
  201421. {
  201422. return chdir (getFullPathName().toUTF8()) == 0;
  201423. }
  201424. const String File::getVersion() const
  201425. {
  201426. const ScopedAutoReleasePool pool;
  201427. String result;
  201428. NSBundle* bundle = [NSBundle bundleWithPath: juceStringToNS (getFullPathName())];
  201429. if (bundle != 0)
  201430. {
  201431. NSDictionary* info = [bundle infoDictionary];
  201432. if (info != 0)
  201433. {
  201434. NSString* name = [info valueForKey: @"CFBundleShortVersionString"];
  201435. if (name != nil)
  201436. result = nsStringToJuce (name);
  201437. }
  201438. }
  201439. return result;
  201440. }
  201441. const File File::getLinkedTarget() const
  201442. {
  201443. #if JUCE_IPHONE || (defined (MAC_OS_X_VERSION_10_5) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
  201444. NSString* dest = [[NSFileManager defaultManager] destinationOfSymbolicLinkAtPath: juceStringToNS (getFullPathName()) error: nil];
  201445. #else
  201446. NSString* dest = [[NSFileManager defaultManager] pathContentOfSymbolicLinkAtPath: juceStringToNS (getFullPathName())];
  201447. #endif
  201448. if (dest != nil)
  201449. return File (nsStringToJuce (dest));
  201450. return *this;
  201451. }
  201452. bool File::moveToTrash() const
  201453. {
  201454. if (! exists())
  201455. return true;
  201456. #if JUCE_IPHONE
  201457. return deleteFile(); //xxx is there a trashcan on the iPhone?
  201458. #else
  201459. const ScopedAutoReleasePool pool;
  201460. NSString* p = juceStringToNS (getFullPathName());
  201461. return [[NSWorkspace sharedWorkspace]
  201462. performFileOperation: NSWorkspaceRecycleOperation
  201463. source: [p stringByDeletingLastPathComponent]
  201464. destination: @""
  201465. files: [NSArray arrayWithObject: [p lastPathComponent]]
  201466. tag: nil ];
  201467. #endif
  201468. }
  201469. struct FindFileStruct
  201470. {
  201471. NSDirectoryEnumerator* enumerator;
  201472. String parentDir, wildCard;
  201473. };
  201474. bool juce_findFileNext (void* handle, String& resultFile,
  201475. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime, Time* creationTime, bool* isReadOnly)
  201476. {
  201477. ScopedAutoReleasePool pool;
  201478. FindFileStruct* ff = (FindFileStruct*) handle;
  201479. NSString* file;
  201480. const char* const wildcardUTF8 = ff->wildCard.toUTF8();
  201481. for (;;)
  201482. {
  201483. if (ff == 0 || (file = [ff->enumerator nextObject]) == 0)
  201484. return false;
  201485. [ff->enumerator skipDescendents];
  201486. resultFile = nsStringToJuce (file);
  201487. if (fnmatch (wildcardUTF8, resultFile.toUTF8(), FNM_CASEFOLD) != 0)
  201488. continue;
  201489. const String path (ff->parentDir + resultFile);
  201490. if (isDir != 0 || fileSize != 0)
  201491. {
  201492. struct stat info;
  201493. const bool statOk = juce_stat (path, info);
  201494. if (isDir != 0)
  201495. *isDir = statOk && ((info.st_mode & S_IFDIR) != 0);
  201496. if (isHidden != 0)
  201497. *isHidden = juce_isHiddenFile (path);
  201498. if (fileSize != 0)
  201499. *fileSize = statOk ? info.st_size : 0;
  201500. }
  201501. if (modTime != 0 || creationTime != 0)
  201502. {
  201503. int64 m, a, c;
  201504. juce_getFileTimes (path, m, a, c);
  201505. if (modTime != 0)
  201506. *modTime = m;
  201507. if (creationTime != 0)
  201508. *creationTime = c;
  201509. }
  201510. if (isReadOnly != 0)
  201511. *isReadOnly = ! juce_canWriteToFile (path);
  201512. return true;
  201513. }
  201514. }
  201515. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  201516. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime,
  201517. Time* creationTime, bool* isReadOnly)
  201518. {
  201519. ScopedAutoReleasePool pool;
  201520. NSDirectoryEnumerator* e = [[NSFileManager defaultManager] enumeratorAtPath: juceStringToNS (directory)];
  201521. if (e != 0)
  201522. {
  201523. ScopedPointer <FindFileStruct> ff (new FindFileStruct());
  201524. ff->enumerator = [e retain];
  201525. ff->parentDir = directory;
  201526. ff->wildCard = wildCard;
  201527. if (! ff->parentDir.endsWithChar (File::separator))
  201528. ff->parentDir += File::separator;
  201529. if (juce_findFileNext (ff, firstResultFile, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly))
  201530. return ff.release();
  201531. [e release];
  201532. }
  201533. return 0;
  201534. }
  201535. void juce_findFileClose (void* handle)
  201536. {
  201537. ScopedAutoReleasePool pool;
  201538. ScopedPointer <FindFileStruct> ff ((FindFileStruct*) handle);
  201539. [ff->enumerator release];
  201540. }
  201541. bool juce_launchExecutable (const String& pathAndArguments)
  201542. {
  201543. const char* const argv[4] = { "/bin/sh", "-c", (const char*) pathAndArguments, 0 };
  201544. const int cpid = fork();
  201545. if (cpid == 0)
  201546. {
  201547. // Child process
  201548. if (execve (argv[0], (char**) argv, 0) < 0)
  201549. exit (0);
  201550. }
  201551. else
  201552. {
  201553. if (cpid < 0)
  201554. return false;
  201555. }
  201556. return true;
  201557. }
  201558. bool juce_launchFile (const String& fileName, const String& parameters)
  201559. {
  201560. #if JUCE_IPHONE
  201561. return [[UIApplication sharedApplication] openURL: [NSURL fileURLWithPath: juceStringToNS (fileName)]];
  201562. #else
  201563. const ScopedAutoReleasePool pool;
  201564. if (parameters.isEmpty())
  201565. {
  201566. return [[NSWorkspace sharedWorkspace] openFile: juceStringToNS (fileName)]
  201567. || [[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: juceStringToNS (fileName)]];
  201568. }
  201569. bool ok = false;
  201570. FSRef ref;
  201571. if (PlatformUtilities::makeFSRefFromPath (&ref, fileName))
  201572. {
  201573. if (PlatformUtilities::isBundle (fileName))
  201574. {
  201575. NSMutableArray* urls = [NSMutableArray array];
  201576. StringArray docs;
  201577. docs.addTokens (parameters, true);
  201578. for (int i = 0; i < docs.size(); ++i)
  201579. [urls addObject: juceStringToNS (docs[i])];
  201580. ok = [[NSWorkspace sharedWorkspace] openURLs: urls
  201581. withAppBundleIdentifier: [[NSBundle bundleWithPath: juceStringToNS (fileName)] bundleIdentifier]
  201582. options: 0
  201583. additionalEventParamDescriptor: nil
  201584. launchIdentifiers: nil];
  201585. }
  201586. else
  201587. {
  201588. ok = juce_launchExecutable (T("\"") + fileName + T("\" ") + parameters);
  201589. }
  201590. }
  201591. return ok;
  201592. #endif
  201593. }
  201594. void File::revealToUser() const
  201595. {
  201596. #if ! JUCE_IPHONE
  201597. if (exists())
  201598. [[NSWorkspace sharedWorkspace] selectFile: juceStringToNS (getFullPathName()) inFileViewerRootedAtPath: @""];
  201599. else if (getParentDirectory().exists())
  201600. getParentDirectory().revealToUser();
  201601. #endif
  201602. }
  201603. #if ! JUCE_IPHONE
  201604. bool PlatformUtilities::makeFSRefFromPath (FSRef* destFSRef, const String& path)
  201605. {
  201606. return FSPathMakeRef ((const UInt8*) path.toUTF8(), destFSRef, 0) == noErr;
  201607. }
  201608. const String PlatformUtilities::makePathFromFSRef (FSRef* file)
  201609. {
  201610. uint8 path [2048];
  201611. zeromem (path, sizeof (path));
  201612. String result;
  201613. if (FSRefMakePath (file, (UInt8*) path, sizeof (path) - 1) == noErr)
  201614. result = String::fromUTF8 (path);
  201615. return PlatformUtilities::convertToPrecomposedUnicode (result);
  201616. }
  201617. #endif
  201618. OSType PlatformUtilities::getTypeOfFile (const String& filename)
  201619. {
  201620. const ScopedAutoReleasePool pool;
  201621. #if JUCE_IPHONE || (defined (MAC_OS_X_VERSION_10_5) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
  201622. NSDictionary* fileDict = [[NSFileManager defaultManager] attributesOfItemAtPath: juceStringToNS (filename) error: nil];
  201623. #else
  201624. NSDictionary* fileDict = [[NSFileManager defaultManager] fileAttributesAtPath: juceStringToNS (filename) traverseLink: NO];
  201625. #endif
  201626. //return (OSType) [fileDict objectForKey: NSFileHFSTypeCode];
  201627. return [fileDict fileHFSTypeCode];
  201628. }
  201629. bool PlatformUtilities::isBundle (const String& filename)
  201630. {
  201631. #if JUCE_IPHONE
  201632. return false; // xxx can't find a sensible way to do this without trying to open the bundle..
  201633. #else
  201634. const ScopedAutoReleasePool pool;
  201635. return [[NSWorkspace sharedWorkspace] isFilePackageAtPath: juceStringToNS (filename)];
  201636. #endif
  201637. }
  201638. #endif
  201639. /*** End of inlined file: juce_mac_Files.mm ***/
  201640. #if JUCE_IPHONE
  201641. /*** Start of inlined file: juce_iphone_MiscUtilities.mm ***/
  201642. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201643. // compiled on its own).
  201644. #if JUCE_INCLUDED_FILE
  201645. static JUCEApplication* juce_intialisingApp;
  201646. END_JUCE_NAMESPACE
  201647. @interface JuceAppStartupDelegate : NSObject <UIApplicationDelegate>
  201648. {
  201649. }
  201650. - (void) applicationDidFinishLaunching: (UIApplication*) application;
  201651. - (void) applicationWillResignActive: (UIApplication*) application;
  201652. @end
  201653. @implementation JuceAppStartupDelegate
  201654. - (void) applicationDidFinishLaunching: (UIApplication*) application
  201655. {
  201656. String dummy;
  201657. if (! juce_intialisingApp->initialiseApp (dummy))
  201658. exit (0);
  201659. }
  201660. - (void) applicationWillResignActive: (UIApplication*) application
  201661. {
  201662. JUCEApplication::shutdownAppAndClearUp();
  201663. }
  201664. @end
  201665. BEGIN_JUCE_NAMESPACE
  201666. int juce_IPhoneMain (int argc, char* argv[], JUCEApplication* app)
  201667. {
  201668. juce_intialisingApp = app;
  201669. return UIApplicationMain (argc, argv, nil, @"JuceAppStartupDelegate");
  201670. }
  201671. ScopedAutoReleasePool::ScopedAutoReleasePool()
  201672. {
  201673. pool = [[NSAutoreleasePool alloc] init];
  201674. }
  201675. ScopedAutoReleasePool::~ScopedAutoReleasePool()
  201676. {
  201677. [((NSAutoreleasePool*) pool) release];
  201678. }
  201679. void PlatformUtilities::beep()
  201680. {
  201681. //xxx
  201682. //AudioServicesPlaySystemSound ();
  201683. }
  201684. void PlatformUtilities::addItemToDock (const File& file)
  201685. {
  201686. }
  201687. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  201688. END_JUCE_NAMESPACE
  201689. @interface JuceAlertBoxDelegate : NSObject
  201690. {
  201691. @public
  201692. bool clickedOk;
  201693. }
  201694. - (void) alertView: (UIAlertView*) alertView clickedButtonAtIndex: (NSInteger) buttonIndex;
  201695. @end
  201696. @implementation JuceAlertBoxDelegate
  201697. - (void) alertView: (UIAlertView*) alertView clickedButtonAtIndex: (NSInteger) buttonIndex
  201698. {
  201699. clickedOk = (buttonIndex == 0);
  201700. alertView.hidden = true;
  201701. }
  201702. @end
  201703. BEGIN_JUCE_NAMESPACE
  201704. // (This function is used directly by other bits of code)
  201705. bool juce_iPhoneShowModalAlert (const String& title,
  201706. const String& bodyText,
  201707. NSString* okButtonText,
  201708. NSString* cancelButtonText)
  201709. {
  201710. const ScopedAutoReleasePool pool;
  201711. JuceAlertBoxDelegate* callback = [[JuceAlertBoxDelegate alloc] init];
  201712. UIAlertView* alert = [[UIAlertView alloc] initWithTitle: juceStringToNS (title)
  201713. message: juceStringToNS (bodyText)
  201714. delegate: callback
  201715. cancelButtonTitle: okButtonText
  201716. otherButtonTitles: cancelButtonText, nil];
  201717. [alert retain];
  201718. [alert show];
  201719. while (! alert.hidden && alert.superview != nil)
  201720. [[NSRunLoop mainRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.01]];
  201721. const bool result = callback->clickedOk;
  201722. [alert release];
  201723. [callback release];
  201724. return result;
  201725. }
  201726. bool AlertWindow::showNativeDialogBox (const String& title,
  201727. const String& bodyText,
  201728. bool isOkCancel)
  201729. {
  201730. return juce_iPhoneShowModalAlert (title, bodyText,
  201731. @"OK",
  201732. isOkCancel ? @"Cancel" : nil);
  201733. }
  201734. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  201735. {
  201736. jassertfalse // no such thing on the iphone!
  201737. return false;
  201738. }
  201739. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  201740. {
  201741. jassertfalse // no such thing on the iphone!
  201742. return false;
  201743. }
  201744. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  201745. {
  201746. [[UIApplication sharedApplication] setIdleTimerDisabled: ! isEnabled];
  201747. }
  201748. bool Desktop::isScreenSaverEnabled() throw()
  201749. {
  201750. return ! [[UIApplication sharedApplication] isIdleTimerDisabled];
  201751. }
  201752. void juce_updateMultiMonitorInfo (Array <Rectangle <int> >& monitorCoords, const bool clipToWorkArea)
  201753. {
  201754. const ScopedAutoReleasePool pool;
  201755. monitorCoords.clear();
  201756. CGRect r = clipToWorkArea ? [[UIScreen mainScreen] applicationFrame]
  201757. : [[UIScreen mainScreen] bounds];
  201758. monitorCoords.add (Rectangle<int> ((int) r.origin.x,
  201759. (int) r.origin.y,
  201760. (int) r.size.width,
  201761. (int) r.size.height));
  201762. }
  201763. #endif
  201764. #endif
  201765. /*** End of inlined file: juce_iphone_MiscUtilities.mm ***/
  201766. #else
  201767. /*** Start of inlined file: juce_mac_MiscUtilities.mm ***/
  201768. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201769. // compiled on its own).
  201770. #if JUCE_INCLUDED_FILE
  201771. ScopedAutoReleasePool::ScopedAutoReleasePool()
  201772. {
  201773. pool = [[NSAutoreleasePool alloc] init];
  201774. }
  201775. ScopedAutoReleasePool::~ScopedAutoReleasePool()
  201776. {
  201777. [((NSAutoreleasePool*) pool) release];
  201778. }
  201779. void PlatformUtilities::beep()
  201780. {
  201781. NSBeep();
  201782. }
  201783. void PlatformUtilities::addItemToDock (const File& file)
  201784. {
  201785. // check that it's not already there...
  201786. if (! juce_getOutputFromCommand ("defaults read com.apple.dock persistent-apps")
  201787. .containsIgnoreCase (file.getFullPathName()))
  201788. {
  201789. 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>"
  201790. + file.getFullPathName() + "</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>\"");
  201791. juce_runSystemCommand ("osascript -e \"tell application \\\"Dock\\\" to quit\"");
  201792. }
  201793. }
  201794. int PlatformUtilities::getOSXMinorVersionNumber()
  201795. {
  201796. SInt32 versionMinor = 0;
  201797. OSErr err = Gestalt (gestaltSystemVersionMinor, &versionMinor);
  201798. (void) err;
  201799. jassert (err == noErr);
  201800. return (int) versionMinor;
  201801. }
  201802. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  201803. bool AlertWindow::showNativeDialogBox (const String& title,
  201804. const String& bodyText,
  201805. bool isOkCancel)
  201806. {
  201807. const ScopedAutoReleasePool pool;
  201808. return NSRunAlertPanel (juceStringToNS (title),
  201809. juceStringToNS (bodyText),
  201810. @"Ok",
  201811. isOkCancel ? @"Cancel" : nil,
  201812. nil) == NSAlertDefaultReturn;
  201813. }
  201814. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  201815. {
  201816. if (files.size() == 0)
  201817. return false;
  201818. Component* sourceComp = Component::getComponentUnderMouse();
  201819. if (sourceComp == 0)
  201820. {
  201821. jassertfalse // this method must be called in response to a
  201822. // component's mouseDrag event!
  201823. return false;
  201824. }
  201825. const ScopedAutoReleasePool pool;
  201826. NSView* view = (NSView*) sourceComp->getWindowHandle();
  201827. if (view == 0)
  201828. return false;
  201829. NSPasteboard* pboard = [NSPasteboard pasteboardWithName: NSDragPboard];
  201830. [pboard declareTypes: [NSArray arrayWithObject: NSFilenamesPboardType]
  201831. owner: nil];
  201832. NSMutableArray* filesArray = [NSMutableArray arrayWithCapacity: 4];
  201833. for (int i = 0; i < files.size(); ++i)
  201834. [filesArray addObject: juceStringToNS (files[i])];
  201835. [pboard setPropertyList: filesArray
  201836. forType: NSFilenamesPboardType];
  201837. NSPoint dragPosition = [view convertPoint: [[[view window] currentEvent] locationInWindow]
  201838. fromView: nil];
  201839. dragPosition.x -= 16;
  201840. dragPosition.y -= 16;
  201841. [view dragImage: [[NSWorkspace sharedWorkspace] iconForFile: juceStringToNS (files[0])]
  201842. at: dragPosition
  201843. offset: NSMakeSize (0, 0)
  201844. event: [[view window] currentEvent]
  201845. pasteboard: pboard
  201846. source: view
  201847. slideBack: YES];
  201848. return true;
  201849. }
  201850. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  201851. {
  201852. jassertfalse // not implemented!
  201853. return false;
  201854. }
  201855. bool Desktop::canUseSemiTransparentWindows() throw()
  201856. {
  201857. return true;
  201858. }
  201859. void Desktop::getMousePosition (int& x, int& y) throw()
  201860. {
  201861. const ScopedAutoReleasePool pool;
  201862. const NSPoint p ([NSEvent mouseLocation]);
  201863. x = roundToInt (p.x);
  201864. y = roundToInt ([[[NSScreen screens] objectAtIndex: 0] frame].size.height - p.y);
  201865. }
  201866. void Desktop::setMousePosition (int x, int y) throw()
  201867. {
  201868. // this rubbish needs to be done around the warp call, to avoid causing a
  201869. // bizarre glitch..
  201870. CGAssociateMouseAndMouseCursorPosition (false);
  201871. CGWarpMouseCursorPosition (CGPointMake (x, y));
  201872. CGAssociateMouseAndMouseCursorPosition (true);
  201873. }
  201874. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  201875. class ScreenSaverDefeater : public Timer,
  201876. public DeletedAtShutdown
  201877. {
  201878. public:
  201879. ScreenSaverDefeater() throw()
  201880. {
  201881. startTimer (10000);
  201882. timerCallback();
  201883. }
  201884. ~ScreenSaverDefeater() {}
  201885. void timerCallback()
  201886. {
  201887. if (Process::isForegroundProcess())
  201888. UpdateSystemActivity (UsrActivity);
  201889. }
  201890. };
  201891. static ScreenSaverDefeater* screenSaverDefeater = 0;
  201892. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  201893. {
  201894. if (isEnabled)
  201895. {
  201896. deleteAndZero (screenSaverDefeater);
  201897. }
  201898. else if (screenSaverDefeater == 0)
  201899. {
  201900. screenSaverDefeater = new ScreenSaverDefeater();
  201901. }
  201902. }
  201903. bool Desktop::isScreenSaverEnabled() throw()
  201904. {
  201905. return screenSaverDefeater == 0;
  201906. }
  201907. #else
  201908. static IOPMAssertionID screenSaverDisablerID = 0;
  201909. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  201910. {
  201911. if (isEnabled)
  201912. {
  201913. if (screenSaverDisablerID != 0)
  201914. {
  201915. IOPMAssertionRelease (screenSaverDisablerID);
  201916. screenSaverDisablerID = 0;
  201917. }
  201918. }
  201919. else
  201920. {
  201921. if (screenSaverDisablerID == 0)
  201922. {
  201923. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  201924. IOPMAssertionCreateWithName (kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn,
  201925. CFSTR ("Juce"), &screenSaverDisablerID);
  201926. #else
  201927. IOPMAssertionCreate (kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn,
  201928. &screenSaverDisablerID);
  201929. #endif
  201930. }
  201931. }
  201932. }
  201933. bool Desktop::isScreenSaverEnabled() throw()
  201934. {
  201935. return screenSaverDisablerID == 0;
  201936. }
  201937. #endif
  201938. void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords, const bool clipToWorkArea)
  201939. {
  201940. const ScopedAutoReleasePool pool;
  201941. monitorCoords.clear();
  201942. NSArray* screens = [NSScreen screens];
  201943. const CGFloat mainScreenBottom = [[[NSScreen screens] objectAtIndex: 0] frame].size.height;
  201944. for (unsigned int i = 0; i < [screens count]; ++i)
  201945. {
  201946. NSScreen* s = (NSScreen*) [screens objectAtIndex: i];
  201947. NSRect r = clipToWorkArea ? [s visibleFrame]
  201948. : [s frame];
  201949. monitorCoords.add (Rectangle<int> ((int) r.origin.x,
  201950. (int) (mainScreenBottom - (r.origin.y + r.size.height)),
  201951. (int) r.size.width,
  201952. (int) r.size.height));
  201953. }
  201954. jassert (monitorCoords.size() > 0);
  201955. }
  201956. #endif
  201957. #endif
  201958. /*** End of inlined file: juce_mac_MiscUtilities.mm ***/
  201959. #endif
  201960. /*** Start of inlined file: juce_mac_Debugging.mm ***/
  201961. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201962. // compiled on its own).
  201963. #if JUCE_INCLUDED_FILE
  201964. void Logger::outputDebugString (const String& text) throw()
  201965. {
  201966. std::cerr << (const char*) text.toUTF8() << std::endl;
  201967. }
  201968. void Logger::outputDebugPrintf (const tchar* format, ...) throw()
  201969. {
  201970. String text;
  201971. va_list args;
  201972. va_start (args, format);
  201973. text.vprintf (format, args);
  201974. outputDebugString (text);
  201975. }
  201976. bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger()
  201977. {
  201978. static char testResult = 0;
  201979. if (testResult == 0)
  201980. {
  201981. struct kinfo_proc info;
  201982. int m[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid() };
  201983. size_t sz = sizeof (info);
  201984. sysctl (m, 4, &info, &sz, 0, 0);
  201985. testResult = ((info.kp_proc.p_flag & P_TRACED) != 0) ? 1 : -1;
  201986. }
  201987. return testResult > 0;
  201988. }
  201989. bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
  201990. {
  201991. return juce_isRunningUnderDebugger();
  201992. }
  201993. #endif
  201994. /*** End of inlined file: juce_mac_Debugging.mm ***/
  201995. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  201996. #if JUCE_IPHONE
  201997. /*** Start of inlined file: juce_mac_Fonts.mm ***/
  201998. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201999. // compiled on its own).
  202000. #if JUCE_INCLUDED_FILE
  202001. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  202002. #define SUPPORT_10_4_FONTS 1
  202003. #define NEW_CGFONT_FUNCTIONS_UNAVAILABLE (CGFontCreateWithFontName == 0)
  202004. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  202005. #define SUPPORT_ONLY_10_4_FONTS 1
  202006. #endif
  202007. END_JUCE_NAMESPACE
  202008. @interface NSFont (PrivateHack)
  202009. - (NSGlyph) _defaultGlyphForChar: (unichar) theChar;
  202010. @end
  202011. BEGIN_JUCE_NAMESPACE
  202012. #endif
  202013. class MacTypeface : public Typeface
  202014. {
  202015. public:
  202016. MacTypeface (const Font& font)
  202017. : Typeface (font.getTypefaceName())
  202018. {
  202019. const ScopedAutoReleasePool pool;
  202020. renderingTransform = CGAffineTransformIdentity;
  202021. bool needsItalicTransform = false;
  202022. #if JUCE_IPHONE
  202023. NSString* fontName = juceStringToNS (font.getTypefaceName());
  202024. if (font.isItalic() || font.isBold())
  202025. {
  202026. NSArray* familyFonts = [UIFont fontNamesForFamilyName: juceStringToNS (font.getTypefaceName())];
  202027. for (NSString* i in familyFonts)
  202028. {
  202029. const String fn (nsStringToJuce (i));
  202030. const String afterDash (fn.fromFirstOccurrenceOf (T("-"), false, false));
  202031. const bool probablyBold = afterDash.containsIgnoreCase (T("bold")) || fn.endsWithIgnoreCase (T("bold"));
  202032. const bool probablyItalic = afterDash.containsIgnoreCase (T("oblique"))
  202033. || afterDash.containsIgnoreCase (T("italic"))
  202034. || fn.endsWithIgnoreCase (T("oblique"))
  202035. || fn.endsWithIgnoreCase (T("italic"));
  202036. if (probablyBold == font.isBold()
  202037. && probablyItalic == font.isItalic())
  202038. {
  202039. fontName = i;
  202040. needsItalicTransform = false;
  202041. break;
  202042. }
  202043. else if (probablyBold && (! probablyItalic) && probablyBold == font.isBold())
  202044. {
  202045. fontName = i;
  202046. needsItalicTransform = true; // not ideal, so carry on in case we find a better one
  202047. }
  202048. }
  202049. if (needsItalicTransform)
  202050. renderingTransform.c = 0.15f;
  202051. }
  202052. fontRef = CGFontCreateWithFontName ((CFStringRef) fontName);
  202053. const int ascender = abs (CGFontGetAscent (fontRef));
  202054. const float totalHeight = ascender + abs (CGFontGetDescent (fontRef));
  202055. ascent = ascender / totalHeight;
  202056. unitsToHeightScaleFactor = 1.0f / totalHeight;
  202057. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / totalHeight;
  202058. #else
  202059. nsFont = [NSFont fontWithName: juceStringToNS (font.getTypefaceName()) size: 1024];
  202060. if (font.isItalic())
  202061. {
  202062. NSFont* newFont = [[NSFontManager sharedFontManager] convertFont: nsFont
  202063. toHaveTrait: NSItalicFontMask];
  202064. if (newFont == nsFont)
  202065. needsItalicTransform = true; // couldn't find a proper italic version, so fake it with a transform..
  202066. nsFont = newFont;
  202067. }
  202068. if (font.isBold())
  202069. nsFont = [[NSFontManager sharedFontManager] convertFont: nsFont toHaveTrait: NSBoldFontMask];
  202070. [nsFont retain];
  202071. ascent = fabsf ((float) [nsFont ascender]);
  202072. float totalSize = ascent + fabsf ((float) [nsFont descender]);
  202073. ascent /= totalSize;
  202074. pathTransform = AffineTransform::identity.scale (1.0f / totalSize, 1.0f / totalSize);
  202075. if (needsItalicTransform)
  202076. {
  202077. pathTransform = pathTransform.sheared (-0.15f, 0.0f);
  202078. renderingTransform.c = 0.15f;
  202079. }
  202080. #if SUPPORT_ONLY_10_4_FONTS
  202081. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  202082. if (atsFont == 0)
  202083. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  202084. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  202085. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  202086. unitsToHeightScaleFactor = 1.0f / totalHeight;
  202087. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  202088. #else
  202089. #if SUPPORT_10_4_FONTS
  202090. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  202091. {
  202092. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  202093. if (atsFont == 0)
  202094. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  202095. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  202096. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  202097. unitsToHeightScaleFactor = 1.0f / totalHeight;
  202098. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  202099. }
  202100. else
  202101. #endif
  202102. {
  202103. fontRef = CGFontCreateWithFontName ((CFStringRef) [nsFont fontName]);
  202104. const int totalHeight = abs (CGFontGetAscent (fontRef)) + abs (CGFontGetDescent (fontRef));
  202105. unitsToHeightScaleFactor = 1.0f / totalHeight;
  202106. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / (float) totalHeight;
  202107. }
  202108. #endif
  202109. #endif
  202110. }
  202111. ~MacTypeface()
  202112. {
  202113. #if ! JUCE_IPHONE
  202114. [nsFont release];
  202115. #endif
  202116. if (fontRef != 0)
  202117. CGFontRelease (fontRef);
  202118. }
  202119. float getAscent() const
  202120. {
  202121. return ascent;
  202122. }
  202123. float getDescent() const
  202124. {
  202125. return 1.0f - ascent;
  202126. }
  202127. float getStringWidth (const String& text)
  202128. {
  202129. if (fontRef == 0 || text.isEmpty())
  202130. return 0;
  202131. const int length = text.length();
  202132. HeapBlock <CGGlyph> glyphs;
  202133. createGlyphsForString (text, length, glyphs);
  202134. float x = 0;
  202135. #if SUPPORT_ONLY_10_4_FONTS
  202136. HeapBlock <NSSize> advances (length);
  202137. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  202138. for (int i = 0; i < length; ++i)
  202139. x += advances[i].width;
  202140. #else
  202141. #if SUPPORT_10_4_FONTS
  202142. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  202143. {
  202144. HeapBlock <NSSize> advances (length);
  202145. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  202146. for (int i = 0; i < length; ++i)
  202147. x += advances[i].width;
  202148. }
  202149. else
  202150. #endif
  202151. {
  202152. HeapBlock <int> advances (length);
  202153. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  202154. for (int i = 0; i < length; ++i)
  202155. x += advances[i];
  202156. }
  202157. #endif
  202158. return x * unitsToHeightScaleFactor;
  202159. }
  202160. void getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array <float>& xOffsets)
  202161. {
  202162. xOffsets.add (0);
  202163. if (fontRef == 0 || text.isEmpty())
  202164. return;
  202165. const int length = text.length();
  202166. HeapBlock <CGGlyph> glyphs;
  202167. createGlyphsForString (text, length, glyphs);
  202168. #if SUPPORT_ONLY_10_4_FONTS
  202169. HeapBlock <NSSize> advances (length);
  202170. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  202171. int x = 0;
  202172. for (int i = 0; i < length; ++i)
  202173. {
  202174. x += advances[i].width;
  202175. xOffsets.add (x * unitsToHeightScaleFactor);
  202176. resultGlyphs.add (((NSGlyph*) glyphs)[i]);
  202177. }
  202178. #else
  202179. #if SUPPORT_10_4_FONTS
  202180. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  202181. {
  202182. HeapBlock <NSSize> advances (length);
  202183. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  202184. float x = 0;
  202185. for (int i = 0; i < length; ++i)
  202186. {
  202187. x += advances[i].width;
  202188. xOffsets.add (x * unitsToHeightScaleFactor);
  202189. resultGlyphs.add (((NSGlyph*) glyphs)[i]);
  202190. }
  202191. }
  202192. else
  202193. #endif
  202194. {
  202195. HeapBlock <int> advances (length);
  202196. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  202197. {
  202198. int x = 0;
  202199. for (int i = 0; i < length; ++i)
  202200. {
  202201. x += advances [i];
  202202. xOffsets.add (x * unitsToHeightScaleFactor);
  202203. resultGlyphs.add (glyphs[i]);
  202204. }
  202205. }
  202206. }
  202207. #endif
  202208. }
  202209. bool getOutlineForGlyph (int glyphNumber, Path& path)
  202210. {
  202211. #if JUCE_IPHONE
  202212. return false;
  202213. #else
  202214. if (nsFont == 0)
  202215. return false;
  202216. // we might need to apply a transform to the path, so it mustn't have anything else in it
  202217. jassert (path.isEmpty());
  202218. const ScopedAutoReleasePool pool;
  202219. NSBezierPath* bez = [NSBezierPath bezierPath];
  202220. [bez moveToPoint: NSMakePoint (0, 0)];
  202221. [bez appendBezierPathWithGlyph: (NSGlyph) glyphNumber
  202222. inFont: nsFont];
  202223. for (int i = 0; i < [bez elementCount]; ++i)
  202224. {
  202225. NSPoint p[3];
  202226. switch ([bez elementAtIndex: i associatedPoints: p])
  202227. {
  202228. case NSMoveToBezierPathElement:
  202229. path.startNewSubPath ((float) p[0].x, (float) -p[0].y);
  202230. break;
  202231. case NSLineToBezierPathElement:
  202232. path.lineTo ((float) p[0].x, (float) -p[0].y);
  202233. break;
  202234. case NSCurveToBezierPathElement:
  202235. 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);
  202236. break;
  202237. case NSClosePathBezierPathElement:
  202238. path.closeSubPath();
  202239. break;
  202240. default:
  202241. jassertfalse
  202242. break;
  202243. }
  202244. }
  202245. path.applyTransform (pathTransform);
  202246. return true;
  202247. #endif
  202248. }
  202249. juce_UseDebuggingNewOperator
  202250. CGFontRef fontRef;
  202251. float fontHeightToCGSizeFactor;
  202252. CGAffineTransform renderingTransform;
  202253. private:
  202254. float ascent, unitsToHeightScaleFactor;
  202255. #if JUCE_IPHONE
  202256. #else
  202257. NSFont* nsFont;
  202258. AffineTransform pathTransform;
  202259. #endif
  202260. void createGlyphsForString (const juce_wchar* const text, const int length, HeapBlock <CGGlyph>& glyphs)
  202261. {
  202262. #if SUPPORT_10_4_FONTS
  202263. #if ! SUPPORT_ONLY_10_4_FONTS
  202264. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  202265. #endif
  202266. {
  202267. glyphs.malloc (sizeof (NSGlyph) * length, 1);
  202268. NSGlyph* const g = (NSGlyph*) glyphs;
  202269. for (int i = 0; i < length; ++i)
  202270. g[i] = (NSGlyph) [nsFont _defaultGlyphForChar: text[i]];
  202271. return;
  202272. }
  202273. #endif
  202274. #if ! SUPPORT_ONLY_10_4_FONTS
  202275. if (charToGlyphMapper == 0)
  202276. charToGlyphMapper = new CharToGlyphMapper (fontRef);
  202277. glyphs.malloc (length);
  202278. for (int i = 0; i < length; ++i)
  202279. glyphs[i] = (CGGlyph) charToGlyphMapper->getGlyphForCharacter (text[i]);
  202280. #endif
  202281. }
  202282. #if ! SUPPORT_ONLY_10_4_FONTS
  202283. // Reads a CGFontRef's character map table to convert unicode into glyph numbers
  202284. class CharToGlyphMapper
  202285. {
  202286. public:
  202287. CharToGlyphMapper (CGFontRef fontRef)
  202288. : segCount (0), endCode (0), startCode (0), idDelta (0),
  202289. idRangeOffset (0), glyphIndexes (0)
  202290. {
  202291. CFDataRef cmapTable = CGFontCopyTableForTag (fontRef, 'cmap');
  202292. if (cmapTable != 0)
  202293. {
  202294. const int numSubtables = getValue16 (cmapTable, 2);
  202295. for (int i = 0; i < numSubtables; ++i)
  202296. {
  202297. if (getValue16 (cmapTable, i * 8 + 4) == 0) // check for platform ID of 0
  202298. {
  202299. const int offset = getValue32 (cmapTable, i * 8 + 8);
  202300. if (getValue16 (cmapTable, offset) == 4) // check that it's format 4..
  202301. {
  202302. const int length = getValue16 (cmapTable, offset + 2);
  202303. const int segCountX2 = getValue16 (cmapTable, offset + 6);
  202304. segCount = segCountX2 / 2;
  202305. const int endCodeOffset = offset + 14;
  202306. const int startCodeOffset = endCodeOffset + 2 + segCountX2;
  202307. const int idDeltaOffset = startCodeOffset + segCountX2;
  202308. const int idRangeOffsetOffset = idDeltaOffset + segCountX2;
  202309. const int glyphIndexesOffset = idRangeOffsetOffset + segCountX2;
  202310. endCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + endCodeOffset, segCountX2);
  202311. startCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + startCodeOffset, segCountX2);
  202312. idDelta = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idDeltaOffset, segCountX2);
  202313. idRangeOffset = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idRangeOffsetOffset, segCountX2);
  202314. glyphIndexes = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + glyphIndexesOffset, offset + length - glyphIndexesOffset);
  202315. }
  202316. break;
  202317. }
  202318. }
  202319. CFRelease (cmapTable);
  202320. }
  202321. }
  202322. ~CharToGlyphMapper()
  202323. {
  202324. if (endCode != 0)
  202325. {
  202326. CFRelease (endCode);
  202327. CFRelease (startCode);
  202328. CFRelease (idDelta);
  202329. CFRelease (idRangeOffset);
  202330. CFRelease (glyphIndexes);
  202331. }
  202332. }
  202333. int getGlyphForCharacter (const juce_wchar c) const
  202334. {
  202335. for (int i = 0; i < segCount; ++i)
  202336. {
  202337. if (getValue16 (endCode, i * 2) >= c)
  202338. {
  202339. const int start = getValue16 (startCode, i * 2);
  202340. if (start > c)
  202341. break;
  202342. const int delta = getValue16 (idDelta, i * 2);
  202343. const int rangeOffset = getValue16 (idRangeOffset, i * 2);
  202344. if (rangeOffset == 0)
  202345. return delta + c;
  202346. else
  202347. return getValue16 (glyphIndexes, 2 * ((rangeOffset / 2) + (c - start) - (segCount - i)));
  202348. }
  202349. }
  202350. // If we failed to find it "properly", this dodgy fall-back seems to do the trick for most fonts!
  202351. return jmax (-1, c - 29);
  202352. }
  202353. private:
  202354. int segCount;
  202355. CFDataRef endCode, startCode, idDelta, idRangeOffset, glyphIndexes;
  202356. static uint16 getValue16 (CFDataRef data, const int index)
  202357. {
  202358. return CFSwapInt16BigToHost (*(UInt16*) (CFDataGetBytePtr (data) + index));
  202359. }
  202360. static uint32 getValue32 (CFDataRef data, const int index)
  202361. {
  202362. return CFSwapInt32BigToHost (*(UInt32*) (CFDataGetBytePtr (data) + index));
  202363. }
  202364. };
  202365. ScopedPointer <CharToGlyphMapper> charToGlyphMapper;
  202366. #endif
  202367. };
  202368. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  202369. {
  202370. return new MacTypeface (font);
  202371. }
  202372. const StringArray Font::findAllTypefaceNames() throw()
  202373. {
  202374. StringArray names;
  202375. const ScopedAutoReleasePool pool;
  202376. #if JUCE_IPHONE
  202377. NSArray* fonts = [UIFont familyNames];
  202378. #else
  202379. NSArray* fonts = [[NSFontManager sharedFontManager] availableFontFamilies];
  202380. #endif
  202381. for (unsigned int i = 0; i < [fonts count]; ++i)
  202382. names.add (nsStringToJuce ((NSString*) [fonts objectAtIndex: i]));
  202383. names.sort (true);
  202384. return names;
  202385. }
  202386. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw()
  202387. {
  202388. #if JUCE_IPHONE
  202389. defaultSans = "Helvetica";
  202390. defaultSerif = "Times New Roman";
  202391. defaultFixed = "Courier New";
  202392. #else
  202393. defaultSans = "Lucida Grande";
  202394. defaultSerif = "Times New Roman";
  202395. defaultFixed = "Monaco";
  202396. #endif
  202397. }
  202398. #endif
  202399. /*** End of inlined file: juce_mac_Fonts.mm ***/
  202400. /*** Start of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  202401. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  202402. // compiled on its own).
  202403. #if JUCE_INCLUDED_FILE
  202404. class CoreGraphicsImage : public Image
  202405. {
  202406. public:
  202407. CoreGraphicsImage (const PixelFormat format_,
  202408. const int imageWidth_,
  202409. const int imageHeight_,
  202410. const bool clearImage)
  202411. : Image (format_, imageWidth_, imageHeight_, clearImage)
  202412. {
  202413. CGColorSpaceRef colourSpace = format == Image::SingleChannel ? CGColorSpaceCreateDeviceGray()
  202414. : CGColorSpaceCreateDeviceRGB();
  202415. context = CGBitmapContextCreate (imageData, imageWidth, imageHeight, 8, lineStride,
  202416. colourSpace, getCGImageFlags (*this));
  202417. CGColorSpaceRelease (colourSpace);
  202418. }
  202419. ~CoreGraphicsImage()
  202420. {
  202421. CGContextRelease (context);
  202422. }
  202423. LowLevelGraphicsContext* createLowLevelContext();
  202424. static CGImageRef createImage (const Image& juceImage, const bool forAlpha, CGColorSpaceRef colourSpace)
  202425. {
  202426. const CoreGraphicsImage* nativeImage = dynamic_cast <const CoreGraphicsImage*> (&juceImage);
  202427. if (nativeImage != 0 && (juceImage.getFormat() == Image::SingleChannel || ! forAlpha))
  202428. {
  202429. return CGBitmapContextCreateImage (nativeImage->context);
  202430. }
  202431. else
  202432. {
  202433. const Image::BitmapData srcData (juceImage, 0, 0, juceImage.getWidth(), juceImage.getHeight());
  202434. CGDataProviderRef provider = CGDataProviderCreateWithData (0, srcData.data, srcData.lineStride * srcData.height, 0);
  202435. CGImageRef imageRef = CGImageCreate (srcData.width, srcData.height,
  202436. 8, srcData.pixelStride * 8, srcData.lineStride,
  202437. colourSpace, getCGImageFlags (juceImage), provider,
  202438. 0, true, kCGRenderingIntentDefault);
  202439. CGDataProviderRelease (provider);
  202440. return imageRef;
  202441. }
  202442. }
  202443. #if JUCE_MAC
  202444. static NSImage* createNSImage (const Image& image)
  202445. {
  202446. const ScopedAutoReleasePool pool;
  202447. NSImage* im = [[NSImage alloc] init];
  202448. [im setSize: NSMakeSize (image.getWidth(), image.getHeight())];
  202449. [im lockFocus];
  202450. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  202451. CGImageRef imageRef = createImage (image, false, colourSpace);
  202452. CGColorSpaceRelease (colourSpace);
  202453. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  202454. CGContextDrawImage (cg, CGRectMake (0, 0, image.getWidth(), image.getHeight()), imageRef);
  202455. CGImageRelease (imageRef);
  202456. [im unlockFocus];
  202457. return im;
  202458. }
  202459. #endif
  202460. CGContextRef context;
  202461. private:
  202462. static CGBitmapInfo getCGImageFlags (const Image& image)
  202463. {
  202464. #if JUCE_BIG_ENDIAN
  202465. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Big) : kCGBitmapByteOrderDefault;
  202466. #else
  202467. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little) : kCGBitmapByteOrderDefault;
  202468. #endif
  202469. }
  202470. };
  202471. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  202472. {
  202473. #if USE_COREGRAPHICS_RENDERING
  202474. return new CoreGraphicsImage (format == RGB ? ARGB : format, imageWidth, imageHeight, clearImage);
  202475. #else
  202476. return new Image (format, imageWidth, imageHeight, clearImage);
  202477. #endif
  202478. }
  202479. class CoreGraphicsContext : public LowLevelGraphicsContext
  202480. {
  202481. public:
  202482. CoreGraphicsContext (CGContextRef context_, const float flipHeight_)
  202483. : context (context_),
  202484. flipHeight (flipHeight_),
  202485. numGradientLookupEntries (0)
  202486. {
  202487. CGContextRetain (context);
  202488. CGContextSaveGState(context);
  202489. CGContextSetShouldSmoothFonts (context, true);
  202490. CGContextSetShouldAntialias (context, true);
  202491. CGContextSetBlendMode (context, kCGBlendModeNormal);
  202492. rgbColourSpace = CGColorSpaceCreateDeviceRGB();
  202493. greyColourSpace = CGColorSpaceCreateDeviceGray();
  202494. gradientCallbacks.version = 0;
  202495. gradientCallbacks.evaluate = gradientCallback;
  202496. gradientCallbacks.releaseInfo = 0;
  202497. state = new SavedState();
  202498. }
  202499. ~CoreGraphicsContext()
  202500. {
  202501. CGContextRestoreGState (context);
  202502. CGContextRelease (context);
  202503. CGColorSpaceRelease (rgbColourSpace);
  202504. CGColorSpaceRelease (greyColourSpace);
  202505. }
  202506. bool isVectorDevice() const { return false; }
  202507. void setOrigin (int x, int y)
  202508. {
  202509. CGContextTranslateCTM (context, x, -y);
  202510. }
  202511. bool clipToRectangle (const Rectangle<int>& r)
  202512. {
  202513. CGContextClipToRect (context, CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight()));
  202514. return ! isClipEmpty();
  202515. }
  202516. bool clipToRectangleList (const RectangleList& clipRegion)
  202517. {
  202518. if (clipRegion.isEmpty())
  202519. {
  202520. CGContextClipToRect (context, CGRectMake (0, 0, 0, 0));
  202521. return false;
  202522. }
  202523. else
  202524. {
  202525. const int numRects = clipRegion.getNumRectangles();
  202526. HeapBlock <CGRect> rects (numRects);
  202527. for (int i = 0; i < numRects; ++i)
  202528. {
  202529. const Rectangle<int>& r = clipRegion.getRectangle(i);
  202530. rects[i] = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  202531. }
  202532. CGContextClipToRects (context, rects, numRects);
  202533. return ! isClipEmpty();
  202534. }
  202535. }
  202536. void excludeClipRectangle (const Rectangle<int>& r)
  202537. {
  202538. RectangleList remaining (getClipBounds());
  202539. remaining.subtract (r);
  202540. clipToRectangleList (remaining);
  202541. }
  202542. void clipToPath (const Path& path, const AffineTransform& transform)
  202543. {
  202544. createPath (path, transform);
  202545. CGContextClip (context);
  202546. }
  202547. void clipToImageAlpha (const Image& sourceImage, const Rectangle<int>& srcClip, const AffineTransform& transform)
  202548. {
  202549. if (! transform.isSingularity())
  202550. {
  202551. Image* singleChannelImage = createAlphaChannelImage (sourceImage);
  202552. CGImageRef image = CoreGraphicsImage::createImage (*singleChannelImage, true, greyColourSpace);
  202553. flip();
  202554. AffineTransform t (AffineTransform::scale (1.0f, -1.0f).translated (0, sourceImage.getHeight()).followedBy (transform));
  202555. applyTransform (t);
  202556. CGRect r = CGRectMake (0, 0, sourceImage.getWidth(), sourceImage.getHeight());
  202557. CGContextClipToMask (context, r, image);
  202558. applyTransform (t.inverted());
  202559. flip();
  202560. CGImageRelease (image);
  202561. deleteAlphaChannelImage (sourceImage, singleChannelImage);
  202562. }
  202563. }
  202564. bool clipRegionIntersects (const Rectangle<int>& r)
  202565. {
  202566. return getClipBounds().intersects (r);
  202567. }
  202568. const Rectangle<int> getClipBounds() const
  202569. {
  202570. CGRect bounds = CGRectIntegral (CGContextGetClipBoundingBox (context));
  202571. return Rectangle<int> (roundToInt (bounds.origin.x),
  202572. roundToInt (flipHeight - (bounds.origin.y + bounds.size.height)),
  202573. roundToInt (bounds.size.width),
  202574. roundToInt (bounds.size.height));
  202575. }
  202576. bool isClipEmpty() const
  202577. {
  202578. return CGRectIsEmpty (CGContextGetClipBoundingBox (context));
  202579. }
  202580. void saveState()
  202581. {
  202582. CGContextSaveGState (context);
  202583. stateStack.add (new SavedState (*state));
  202584. }
  202585. void restoreState()
  202586. {
  202587. CGContextRestoreGState (context);
  202588. SavedState* const top = stateStack.getLast();
  202589. if (top != 0)
  202590. {
  202591. state = top;
  202592. stateStack.removeLast (1, false);
  202593. }
  202594. else
  202595. {
  202596. jassertfalse // trying to pop with an empty stack!
  202597. }
  202598. }
  202599. void setFill (const FillType& fillType)
  202600. {
  202601. state->fillType = fillType;
  202602. if (fillType.isColour())
  202603. {
  202604. CGContextSetRGBFillColor (context, fillType.colour.getFloatRed(), fillType.colour.getFloatGreen(),
  202605. fillType.colour.getFloatBlue(), fillType.colour.getFloatAlpha());
  202606. CGContextSetAlpha (context, 1.0f);
  202607. }
  202608. }
  202609. void setOpacity (float newOpacity)
  202610. {
  202611. state->fillType.setOpacity (newOpacity);
  202612. setFill (state->fillType);
  202613. }
  202614. void setInterpolationQuality (Graphics::ResamplingQuality quality)
  202615. {
  202616. CGContextSetInterpolationQuality (context, quality == Graphics::lowResamplingQuality
  202617. ? kCGInterpolationLow
  202618. : kCGInterpolationHigh);
  202619. }
  202620. void fillRect (const Rectangle<int>& r, const bool replaceExistingContents)
  202621. {
  202622. CGRect cgRect = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  202623. if (replaceExistingContents)
  202624. {
  202625. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  202626. CGContextClearRect (context, cgRect);
  202627. #else
  202628. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  202629. if (CGContextDrawLinearGradient == 0) // (just a way of checking whether we're running in 10.5 or later)
  202630. CGContextClearRect (context, cgRect);
  202631. else
  202632. #endif
  202633. CGContextSetBlendMode (context, kCGBlendModeCopy);
  202634. #endif
  202635. fillRect (r, false);
  202636. CGContextSetBlendMode (context, kCGBlendModeNormal);
  202637. }
  202638. else
  202639. {
  202640. if (state->fillType.isColour())
  202641. {
  202642. CGContextFillRect (context, cgRect);
  202643. }
  202644. else if (state->fillType.isGradient())
  202645. {
  202646. CGContextSaveGState (context);
  202647. CGContextClipToRect (context, cgRect);
  202648. drawGradient();
  202649. CGContextRestoreGState (context);
  202650. }
  202651. else
  202652. {
  202653. CGContextSaveGState (context);
  202654. CGContextClipToRect (context, cgRect);
  202655. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  202656. CGContextRestoreGState (context);
  202657. }
  202658. }
  202659. }
  202660. void fillPath (const Path& path, const AffineTransform& transform)
  202661. {
  202662. CGContextSaveGState (context);
  202663. if (state->fillType.isColour())
  202664. {
  202665. flip();
  202666. applyTransform (transform);
  202667. createPath (path);
  202668. if (path.isUsingNonZeroWinding())
  202669. CGContextFillPath (context);
  202670. else
  202671. CGContextEOFillPath (context);
  202672. }
  202673. else
  202674. {
  202675. createPath (path, transform);
  202676. if (path.isUsingNonZeroWinding())
  202677. CGContextClip (context);
  202678. else
  202679. CGContextEOClip (context);
  202680. if (state->fillType.isGradient())
  202681. drawGradient();
  202682. else
  202683. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  202684. }
  202685. CGContextRestoreGState (context);
  202686. }
  202687. void drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  202688. const AffineTransform& transform, const bool fillEntireClipAsTiles)
  202689. {
  202690. jassert (sourceImage.getBounds().contains (srcClip));
  202691. CGImageRef fullImage = CoreGraphicsImage::createImage (sourceImage, false, rgbColourSpace);
  202692. CGImageRef image = fullImage;
  202693. if (srcClip != sourceImage.getBounds())
  202694. {
  202695. image = CGImageCreateWithImageInRect (fullImage, CGRectMake (srcClip.getX(), srcClip.getY(),
  202696. srcClip.getWidth(), srcClip.getHeight()));
  202697. CGImageRelease (fullImage);
  202698. }
  202699. CGContextSaveGState (context);
  202700. CGContextSetAlpha (context, state->fillType.getOpacity());
  202701. flip();
  202702. applyTransform (AffineTransform::scale (1.0f, -1.0f).translated (0, srcClip.getHeight()).followedBy (transform));
  202703. CGRect imageRect = CGRectMake (0, 0, srcClip.getWidth(), srcClip.getHeight());
  202704. if (fillEntireClipAsTiles)
  202705. {
  202706. #if JUCE_IPHONE || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5)
  202707. CGContextDrawTiledImage (context, imageRect, image);
  202708. #else
  202709. #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
  202710. // There's a bug in CGContextDrawTiledImage that makes it incredibly slow
  202711. // if it's doing a transformation - it's quicker to just draw lots of images manually
  202712. if (CGContextDrawTiledImage != 0 && transform.isOnlyTranslation())
  202713. CGContextDrawTiledImage (context, imageRect, image);
  202714. else
  202715. #endif
  202716. {
  202717. // Fallback to manually doing a tiled fill on 10.4
  202718. CGRect clip = CGRectIntegral (CGContextGetClipBoundingBox (context));
  202719. const int iw = srcClip.getWidth();
  202720. const int ih = srcClip.getHeight();
  202721. int x = 0, y = 0;
  202722. while (x > clip.origin.x) x -= iw;
  202723. while (y > clip.origin.y) y -= ih;
  202724. const int right = (int) (clip.origin.x + clip.size.width);
  202725. const int bottom = (int) (clip.origin.y + clip.size.height);
  202726. while (y < bottom)
  202727. {
  202728. for (int x2 = x; x2 < right; x2 += iw)
  202729. CGContextDrawImage (context, CGRectMake (x2, y, iw, ih), image);
  202730. y += ih;
  202731. }
  202732. }
  202733. #endif
  202734. }
  202735. else
  202736. {
  202737. CGContextDrawImage (context, imageRect, image);
  202738. }
  202739. CGImageRelease (image); // (This causes a memory bug in iPhone sim 3.0 - try upgrading to a later version if you hit this)
  202740. CGContextRestoreGState (context);
  202741. }
  202742. void drawLine (double x1, double y1, double x2, double y2)
  202743. {
  202744. CGContextSetLineCap (context, kCGLineCapSquare);
  202745. CGContextSetLineWidth (context, 1.0f);
  202746. CGContextSetRGBStrokeColor (context,
  202747. state->fillType.colour.getFloatRed(), state->fillType.colour.getFloatGreen(),
  202748. state->fillType.colour.getFloatBlue(), state->fillType.colour.getFloatAlpha());
  202749. CGPoint line[] = { { (float) x1 + 0.5f, flipHeight - ((float) y1 + 0.5f) },
  202750. { (float) x2 + 0.5f, flipHeight - ((float) y2 + 0.5f) } };
  202751. CGContextStrokeLineSegments (context, line, 1);
  202752. }
  202753. void drawVerticalLine (const int x, double top, double bottom)
  202754. {
  202755. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  202756. CGContextFillRect (context, CGRectMake (x, flipHeight - (float) bottom, 1.0f, (float) (bottom - top)));
  202757. #else
  202758. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  202759. // the x co-ord slightly to trick it..
  202760. CGContextFillRect (context, CGRectMake (x + 1.0f / 256.0f, flipHeight - (float) bottom, 1.0f + 1.0f / 256.0f, (float) (bottom - top)));
  202761. #endif
  202762. }
  202763. void drawHorizontalLine (const int y, double left, double right)
  202764. {
  202765. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  202766. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + 1.0f), (float) (right - left), 1.0f));
  202767. #else
  202768. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  202769. // the x co-ord slightly to trick it..
  202770. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + (1.0f + 1.0f / 256.0f)), (float) (right - left), 1.0f + 1.0f / 256.0f));
  202771. #endif
  202772. }
  202773. void setFont (const Font& newFont)
  202774. {
  202775. if (state->font != newFont)
  202776. {
  202777. state->fontRef = 0;
  202778. state->font = newFont;
  202779. MacTypeface* mf = dynamic_cast <MacTypeface*> ((Typeface*) state->font.getTypeface());
  202780. if (mf != 0)
  202781. {
  202782. state->fontRef = mf->fontRef;
  202783. CGContextSetFont (context, state->fontRef);
  202784. CGContextSetFontSize (context, state->font.getHeight() * mf->fontHeightToCGSizeFactor);
  202785. state->fontTransform = mf->renderingTransform;
  202786. state->fontTransform.a *= state->font.getHorizontalScale();
  202787. CGContextSetTextMatrix (context, state->fontTransform);
  202788. }
  202789. }
  202790. }
  202791. const Font getFont()
  202792. {
  202793. return state->font;
  202794. }
  202795. void drawGlyph (int glyphNumber, const AffineTransform& transform)
  202796. {
  202797. if (state->fontRef != 0 && state->fillType.isColour())
  202798. {
  202799. if (transform.isOnlyTranslation())
  202800. {
  202801. CGGlyph g = glyphNumber;
  202802. CGContextShowGlyphsAtPoint (context, transform.getTranslationX(),
  202803. flipHeight - roundToInt (transform.getTranslationY()), &g, 1);
  202804. }
  202805. else
  202806. {
  202807. CGContextSaveGState (context);
  202808. flip();
  202809. applyTransform (transform);
  202810. CGAffineTransform t = state->fontTransform;
  202811. t.d = -t.d;
  202812. CGContextSetTextMatrix (context, t);
  202813. CGGlyph g = glyphNumber;
  202814. CGContextShowGlyphsAtPoint (context, 0, 0, &g, 1);
  202815. CGContextSetTextMatrix (context, state->fontTransform);
  202816. CGContextRestoreGState (context);
  202817. }
  202818. }
  202819. else
  202820. {
  202821. Path p;
  202822. Font& f = state->font;
  202823. f.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  202824. fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight())
  202825. .followedBy (transform));
  202826. }
  202827. }
  202828. private:
  202829. CGContextRef context;
  202830. const float flipHeight;
  202831. CGColorSpaceRef rgbColourSpace, greyColourSpace;
  202832. CGFunctionCallbacks gradientCallbacks;
  202833. struct SavedState
  202834. {
  202835. SavedState()
  202836. : font (1.0f), fontRef (0), fontTransform (CGAffineTransformIdentity)
  202837. {
  202838. }
  202839. SavedState (const SavedState& other)
  202840. : fillType (other.fillType), font (other.font), fontRef (other.fontRef),
  202841. fontTransform (other.fontTransform)
  202842. {
  202843. }
  202844. ~SavedState()
  202845. {
  202846. }
  202847. FillType fillType;
  202848. Font font;
  202849. CGFontRef fontRef;
  202850. CGAffineTransform fontTransform;
  202851. };
  202852. ScopedPointer <SavedState> state;
  202853. OwnedArray <SavedState> stateStack;
  202854. HeapBlock <PixelARGB> gradientLookupTable;
  202855. int numGradientLookupEntries;
  202856. static void gradientCallback (void* info, const CGFloat* inData, CGFloat* outData)
  202857. {
  202858. const CoreGraphicsContext* const g = (const CoreGraphicsContext*) info;
  202859. const int index = roundToInt (g->numGradientLookupEntries * inData[0]);
  202860. PixelARGB colour (g->gradientLookupTable [jlimit (0, g->numGradientLookupEntries, index)]);
  202861. colour.unpremultiply();
  202862. outData[0] = colour.getRed() / 255.0f;
  202863. outData[1] = colour.getGreen() / 255.0f;
  202864. outData[2] = colour.getBlue() / 255.0f;
  202865. outData[3] = colour.getAlpha() / 255.0f;
  202866. }
  202867. CGShadingRef createGradient (const AffineTransform& transform, ColourGradient gradient)
  202868. {
  202869. numGradientLookupEntries = gradient.createLookupTable (transform, gradientLookupTable);
  202870. --numGradientLookupEntries;
  202871. CGShadingRef result = 0;
  202872. CGFunctionRef function = CGFunctionCreate ((void*) this, 1, 0, 4, 0, &gradientCallbacks);
  202873. CGPoint p1 (CGPointMake (gradient.x1, gradient.y1));
  202874. if (gradient.isRadial)
  202875. {
  202876. result = CGShadingCreateRadial (rgbColourSpace, p1, 0,
  202877. p1, hypotf (gradient.x1 - gradient.x2, gradient.y1 - gradient.y2),
  202878. function, true, true);
  202879. }
  202880. else
  202881. {
  202882. result = CGShadingCreateAxial (rgbColourSpace, p1,
  202883. CGPointMake (gradient.x2, gradient.y2),
  202884. function, true, true);
  202885. }
  202886. CGFunctionRelease (function);
  202887. return result;
  202888. }
  202889. void drawGradient()
  202890. {
  202891. flip();
  202892. applyTransform (state->fillType.transform);
  202893. CGContextSetInterpolationQuality (context, kCGInterpolationDefault); // (This is required for 10.4, where there's a crash if
  202894. // you draw a gradient with high quality interp enabled).
  202895. CGShadingRef shading = createGradient (state->fillType.transform, *(state->fillType.gradient));
  202896. CGContextSetAlpha (context, state->fillType.getOpacity());
  202897. CGContextDrawShading (context, shading);
  202898. CGShadingRelease (shading);
  202899. }
  202900. void createPath (const Path& path) const
  202901. {
  202902. CGContextBeginPath (context);
  202903. Path::Iterator i (path);
  202904. while (i.next())
  202905. {
  202906. switch (i.elementType)
  202907. {
  202908. case Path::Iterator::startNewSubPath:
  202909. CGContextMoveToPoint (context, i.x1, i.y1);
  202910. break;
  202911. case Path::Iterator::lineTo:
  202912. CGContextAddLineToPoint (context, i.x1, i.y1);
  202913. break;
  202914. case Path::Iterator::quadraticTo:
  202915. CGContextAddQuadCurveToPoint (context, i.x1, i.y1, i.x2, i.y2);
  202916. break;
  202917. case Path::Iterator::cubicTo:
  202918. CGContextAddCurveToPoint (context, i.x1, i.y1, i.x2, i.y2, i.x3, i.y3);
  202919. break;
  202920. case Path::Iterator::closePath:
  202921. CGContextClosePath (context); break;
  202922. default:
  202923. jassertfalse
  202924. break;
  202925. }
  202926. }
  202927. }
  202928. void createPath (const Path& path, const AffineTransform& transform) const
  202929. {
  202930. CGContextBeginPath (context);
  202931. Path::Iterator i (path);
  202932. while (i.next())
  202933. {
  202934. switch (i.elementType)
  202935. {
  202936. case Path::Iterator::startNewSubPath:
  202937. transform.transformPoint (i.x1, i.y1);
  202938. CGContextMoveToPoint (context, i.x1, flipHeight - i.y1);
  202939. break;
  202940. case Path::Iterator::lineTo:
  202941. transform.transformPoint (i.x1, i.y1);
  202942. CGContextAddLineToPoint (context, i.x1, flipHeight - i.y1);
  202943. break;
  202944. case Path::Iterator::quadraticTo:
  202945. transform.transformPoint (i.x1, i.y1);
  202946. transform.transformPoint (i.x2, i.y2);
  202947. CGContextAddQuadCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2);
  202948. break;
  202949. case Path::Iterator::cubicTo:
  202950. transform.transformPoint (i.x1, i.y1);
  202951. transform.transformPoint (i.x2, i.y2);
  202952. transform.transformPoint (i.x3, i.y3);
  202953. CGContextAddCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2, i.x3, flipHeight - i.y3);
  202954. break;
  202955. case Path::Iterator::closePath:
  202956. CGContextClosePath (context); break;
  202957. default:
  202958. jassertfalse
  202959. break;
  202960. }
  202961. }
  202962. }
  202963. static Image* createAlphaChannelImage (const Image& im)
  202964. {
  202965. if (im.getFormat() == Image::SingleChannel)
  202966. return const_cast <Image*> (&im);
  202967. return im.createCopyOfAlphaChannel();
  202968. }
  202969. static void deleteAlphaChannelImage (const Image& im, Image* const alphaIm)
  202970. {
  202971. if (im.getFormat() != Image::SingleChannel)
  202972. delete alphaIm;
  202973. }
  202974. void flip() const
  202975. {
  202976. CGContextConcatCTM (context, CGAffineTransformMake (1, 0, 0, -1, 0, flipHeight));
  202977. }
  202978. void applyTransform (const AffineTransform& transform) const
  202979. {
  202980. CGAffineTransform t;
  202981. t.a = transform.mat00;
  202982. t.b = transform.mat10;
  202983. t.c = transform.mat01;
  202984. t.d = transform.mat11;
  202985. t.tx = transform.mat02;
  202986. t.ty = transform.mat12;
  202987. CGContextConcatCTM (context, t);
  202988. }
  202989. float flipY (float y) const
  202990. {
  202991. return flipHeight - y;
  202992. }
  202993. };
  202994. LowLevelGraphicsContext* CoreGraphicsImage::createLowLevelContext()
  202995. {
  202996. return new CoreGraphicsContext (context, imageHeight);
  202997. }
  202998. #endif
  202999. /*** End of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  203000. /*** Start of inlined file: juce_iphone_UIViewComponentPeer.mm ***/
  203001. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203002. // compiled on its own).
  203003. #if JUCE_INCLUDED_FILE
  203004. class UIViewComponentPeer;
  203005. END_JUCE_NAMESPACE
  203006. #define JuceUIView MakeObjCClassName(JuceUIView)
  203007. @interface JuceUIView : UIView
  203008. {
  203009. @public
  203010. UIViewComponentPeer* owner;
  203011. }
  203012. - (JuceUIView*) initWithOwner: (UIViewComponentPeer*) owner withFrame: (CGRect) frame;
  203013. - (void) dealloc;
  203014. - (void) drawRect: (CGRect) r;
  203015. - (void) touchesBegan: (NSSet*) touches withEvent: (UIEvent*) event;
  203016. - (void) touchesMoved: (NSSet*) touches withEvent: (UIEvent*) event;
  203017. - (void) touchesEnded: (NSSet*) touches withEvent: (UIEvent*) event;
  203018. - (void) touchesCancelled: (NSSet*) touches withEvent: (UIEvent*) event;
  203019. - (BOOL) becomeFirstResponder;
  203020. - (BOOL) resignFirstResponder;
  203021. - (BOOL) canBecomeFirstResponder;
  203022. - (void) asyncRepaint: (id) rect;
  203023. @end
  203024. #define JuceUIWindow MakeObjCClassName(JuceUIWindow)
  203025. @interface JuceUIWindow : UIWindow
  203026. {
  203027. @private
  203028. UIViewComponentPeer* owner;
  203029. bool isZooming;
  203030. }
  203031. - (void) setOwner: (UIViewComponentPeer*) owner;
  203032. - (void) becomeKeyWindow;
  203033. @end
  203034. BEGIN_JUCE_NAMESPACE
  203035. class UIViewComponentPeer : public ComponentPeer
  203036. {
  203037. public:
  203038. UIViewComponentPeer (Component* const component,
  203039. const int windowStyleFlags,
  203040. UIView* viewToAttachTo);
  203041. ~UIViewComponentPeer();
  203042. void* getNativeHandle() const;
  203043. void setVisible (bool shouldBeVisible);
  203044. void setTitle (const String& title);
  203045. void setPosition (int x, int y);
  203046. void setSize (int w, int h);
  203047. void setBounds (int x, int y, int w, int h, const bool isNowFullScreen);
  203048. void getBounds (int& x, int& y, int& w, int& h, const bool global) const;
  203049. void getBounds (int& x, int& y, int& w, int& h) const;
  203050. int getScreenX() const;
  203051. int getScreenY() const;
  203052. void relativePositionToGlobal (int& x, int& y);
  203053. void globalPositionToRelative (int& x, int& y);
  203054. void setMinimised (bool shouldBeMinimised);
  203055. bool isMinimised() const;
  203056. void setFullScreen (bool shouldBeFullScreen);
  203057. bool isFullScreen() const;
  203058. bool contains (int x, int y, bool trueIfInAChildWindow) const;
  203059. const BorderSize getFrameSize() const;
  203060. bool setAlwaysOnTop (bool alwaysOnTop);
  203061. void toFront (bool makeActiveWindow);
  203062. void toBehind (ComponentPeer* other);
  203063. void setIcon (const Image& newIcon);
  203064. virtual void drawRect (CGRect r);
  203065. virtual bool canBecomeKeyWindow();
  203066. virtual bool windowShouldClose();
  203067. virtual void redirectMovedOrResized();
  203068. virtual CGRect constrainRect (CGRect r);
  203069. virtual void viewFocusGain();
  203070. virtual void viewFocusLoss();
  203071. bool isFocused() const;
  203072. void grabFocus();
  203073. void textInputRequired (int x, int y);
  203074. void repaint (int x, int y, int w, int h);
  203075. void performAnyPendingRepaintsNow();
  203076. juce_UseDebuggingNewOperator
  203077. UIWindow* window;
  203078. JuceUIView* view;
  203079. bool isSharedWindow, fullScreen, insideDrawRect;
  203080. };
  203081. END_JUCE_NAMESPACE
  203082. @implementation JuceUIView
  203083. - (JuceUIView*) initWithOwner: (UIViewComponentPeer*) owner_
  203084. withFrame: (CGRect) frame
  203085. {
  203086. [super initWithFrame: frame];
  203087. owner = owner_;
  203088. return self;
  203089. }
  203090. - (void) dealloc
  203091. {
  203092. [super dealloc];
  203093. }
  203094. - (void) drawRect: (CGRect) r
  203095. {
  203096. if (owner != 0)
  203097. owner->drawRect (r);
  203098. }
  203099. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  203100. {
  203101. return false;
  203102. }
  203103. static int currentModifiers = 0;
  203104. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  203105. {
  203106. return ModifierKeys (currentModifiers);
  203107. }
  203108. void ModifierKeys::updateCurrentModifiers() throw()
  203109. {
  203110. currentModifierFlags = currentModifiers;
  203111. }
  203112. static int getModifierForButtonNumber (const int num)
  203113. {
  203114. return num == 0 ? ModifierKeys::leftButtonModifier
  203115. : (num == 1 ? ModifierKeys::rightButtonModifier
  203116. : (num == 2 ? ModifierKeys::middleButtonModifier : 0));
  203117. }
  203118. static int64 getMouseTime (UIEvent* e)
  203119. {
  203120. return (Time::currentTimeMillis() - Time::getMillisecondCounter())
  203121. + (int64) ([e timestamp] * 1000.0);
  203122. }
  203123. int juce_lastMouseX = 0, juce_lastMouseY = 0;
  203124. - (void) touchesBegan: (NSSet*) touches withEvent: (UIEvent*) event
  203125. {
  203126. if (owner == 0)
  203127. return;
  203128. NSArray* const t = [[event touchesForView: self] allObjects];
  203129. switch ([t count])
  203130. {
  203131. case 1: // One finger..
  203132. {
  203133. CGPoint p = [[t objectAtIndex: 0] locationInView: self];
  203134. currentModifiers |= getModifierForButtonNumber (0);
  203135. int x, y, w, h;
  203136. owner->getBounds (x, y, w, h, true);
  203137. juce_lastMouseX = x + (int) p.x;
  203138. juce_lastMouseY = y + (int) p.y;
  203139. owner->handleMouseMove ((int) p.x, (int) p.y, getMouseTime (event));
  203140. if (owner != 0)
  203141. owner->handleMouseDown ((int) p.x, (int) p.y, getMouseTime (event));
  203142. }
  203143. default:
  203144. //xxx multi-touch..
  203145. break;
  203146. }
  203147. }
  203148. - (void) touchesMoved: (NSSet*) touches withEvent: (UIEvent*) event
  203149. {
  203150. if (owner == 0)
  203151. return;
  203152. NSArray* const t = [[event touchesForView: self] allObjects];
  203153. switch ([t count])
  203154. {
  203155. case 1: // One finger..
  203156. {
  203157. CGPoint p = [[t objectAtIndex: 0] locationInView: self];
  203158. int x, y, w, h;
  203159. owner->getBounds (x, y, w, h, true);
  203160. juce_lastMouseX = x + (int) p.x;
  203161. juce_lastMouseY = y + (int) p.y;
  203162. owner->handleMouseDrag ((int) p.x, (int) p.y, getMouseTime (event));
  203163. }
  203164. default:
  203165. //xxx multi-touch..
  203166. break;
  203167. }
  203168. }
  203169. - (void) touchesEnded: (NSSet*) touches withEvent: (UIEvent*) event
  203170. {
  203171. if (owner == 0)
  203172. return;
  203173. NSArray* const t = [[event touchesForView: self] allObjects];
  203174. switch ([t count])
  203175. {
  203176. case 1: // One finger..
  203177. {
  203178. CGPoint p = [[t objectAtIndex: 0] locationInView: self];
  203179. int x, y, w, h;
  203180. owner->getBounds (x, y, w, h, true);
  203181. juce_lastMouseX = x + (int) p.x;
  203182. juce_lastMouseY = y + (int) p.y;
  203183. const int oldMods = currentModifiers;
  203184. currentModifiers &= ~getModifierForButtonNumber (0);
  203185. owner->handleMouseUp (oldMods, (int) p.x, (int) p.y, getMouseTime (event));
  203186. }
  203187. default:
  203188. //xxx multi-touch..
  203189. break;
  203190. }
  203191. }
  203192. - (void) touchesCancelled: (NSSet*) touches withEvent: (UIEvent*) event
  203193. {
  203194. [self touchesEnded: touches withEvent: event];
  203195. }
  203196. - (BOOL) becomeFirstResponder
  203197. {
  203198. if (owner != 0)
  203199. owner->viewFocusGain();
  203200. return true;
  203201. }
  203202. - (BOOL) resignFirstResponder
  203203. {
  203204. if (owner != 0)
  203205. owner->viewFocusLoss();
  203206. return true;
  203207. }
  203208. - (BOOL) canBecomeFirstResponder
  203209. {
  203210. return owner != 0 && owner->canBecomeKeyWindow();
  203211. }
  203212. - (void) asyncRepaint: (id) rect
  203213. {
  203214. CGRect* r = (CGRect*) [((NSData*) rect) bytes];
  203215. [self setNeedsDisplayInRect: *r];
  203216. }
  203217. @end
  203218. @implementation JuceUIWindow
  203219. - (void) setOwner: (UIViewComponentPeer*) owner_
  203220. {
  203221. owner = owner_;
  203222. isZooming = false;
  203223. }
  203224. - (void) becomeKeyWindow
  203225. {
  203226. [super becomeKeyWindow];
  203227. if (owner != 0)
  203228. owner->grabFocus();
  203229. }
  203230. @end
  203231. BEGIN_JUCE_NAMESPACE
  203232. UIViewComponentPeer::UIViewComponentPeer (Component* const component,
  203233. const int windowStyleFlags,
  203234. UIView* viewToAttachTo)
  203235. : ComponentPeer (component, windowStyleFlags),
  203236. window (0),
  203237. view (0),
  203238. isSharedWindow (viewToAttachTo != 0),
  203239. fullScreen (false),
  203240. insideDrawRect (false)
  203241. {
  203242. CGRect r;
  203243. r.origin.x = 0;
  203244. r.origin.y = 0;
  203245. r.size.width = (float) component->getWidth();
  203246. r.size.height = (float) component->getHeight();
  203247. view = [[JuceUIView alloc] initWithOwner: this withFrame: r];
  203248. if (isSharedWindow)
  203249. {
  203250. window = [viewToAttachTo window];
  203251. [viewToAttachTo addSubview: view];
  203252. setVisible (component->isVisible());
  203253. }
  203254. else
  203255. {
  203256. r.origin.x = (float) component->getX();
  203257. r.origin.y = (float) component->getY();
  203258. r.origin.y = [[UIScreen mainScreen] bounds].size.height - (r.origin.y + r.size.height);
  203259. window = [[JuceUIWindow alloc] init];
  203260. window.frame = r;
  203261. window.opaque = component->isOpaque();
  203262. view.opaque = component->isOpaque();
  203263. window.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent: 0];
  203264. view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent: 0];
  203265. [((JuceUIWindow*) window) setOwner: this];
  203266. if (component->isAlwaysOnTop())
  203267. window.windowLevel = UIWindowLevelAlert;
  203268. [window addSubview: view];
  203269. view.frame = CGRectMake (0, 0, r.size.width, r.size.height);
  203270. view.hidden = ! component->isVisible();
  203271. window.hidden = ! component->isVisible();
  203272. }
  203273. setTitle (component->getName());
  203274. }
  203275. UIViewComponentPeer::~UIViewComponentPeer()
  203276. {
  203277. view->owner = 0;
  203278. [view removeFromSuperview];
  203279. [view release];
  203280. if (! isSharedWindow)
  203281. {
  203282. [((JuceUIWindow*) window) setOwner: 0];
  203283. [window release];
  203284. }
  203285. }
  203286. void* UIViewComponentPeer::getNativeHandle() const
  203287. {
  203288. return view;
  203289. }
  203290. void UIViewComponentPeer::setVisible (bool shouldBeVisible)
  203291. {
  203292. view.hidden = ! shouldBeVisible;
  203293. if (! isSharedWindow)
  203294. window.hidden = ! shouldBeVisible;
  203295. }
  203296. void UIViewComponentPeer::setTitle (const String& title)
  203297. {
  203298. // xxx is this possible?
  203299. }
  203300. void UIViewComponentPeer::setPosition (int x, int y)
  203301. {
  203302. setBounds (x, y, component->getWidth(), component->getHeight(), false);
  203303. }
  203304. void UIViewComponentPeer::setSize (int w, int h)
  203305. {
  203306. setBounds (component->getX(), component->getY(), w, h, false);
  203307. }
  203308. void UIViewComponentPeer::setBounds (int x, int y, int w, int h, const bool isNowFullScreen)
  203309. {
  203310. fullScreen = isNowFullScreen;
  203311. w = jmax (0, w);
  203312. h = jmax (0, h);
  203313. CGRect r;
  203314. r.origin.x = (float) x;
  203315. r.origin.y = (float) y;
  203316. r.size.width = (float) w;
  203317. r.size.height = (float) h;
  203318. if (isSharedWindow)
  203319. {
  203320. //r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  203321. if ([view frame].size.width != r.size.width
  203322. || [view frame].size.height != r.size.height)
  203323. [view setNeedsDisplay];
  203324. view.frame = r;
  203325. }
  203326. else
  203327. {
  203328. window.frame = r;
  203329. view.frame = CGRectMake (0, 0, r.size.width, r.size.height);
  203330. }
  203331. }
  203332. void UIViewComponentPeer::getBounds (int& x, int& y, int& w, int& h, const bool global) const
  203333. {
  203334. CGRect r = [view frame];
  203335. if (global && [view window] != 0)
  203336. {
  203337. r = [view convertRect: r toView: nil];
  203338. CGRect wr = [[view window] frame];
  203339. r.origin.x += wr.origin.x;
  203340. r.origin.y += wr.origin.y;
  203341. }
  203342. x = (int) r.origin.x;
  203343. y = (int) r.origin.y;
  203344. w = (int) r.size.width;
  203345. h = (int) r.size.height;
  203346. }
  203347. void UIViewComponentPeer::getBounds (int& x, int& y, int& w, int& h) const
  203348. {
  203349. getBounds (x, y, w, h, ! isSharedWindow);
  203350. }
  203351. int UIViewComponentPeer::getScreenX() const
  203352. {
  203353. int x, y, w, h;
  203354. getBounds (x, y, w, h, true);
  203355. return x;
  203356. }
  203357. int UIViewComponentPeer::getScreenY() const
  203358. {
  203359. int x, y, w, h;
  203360. getBounds (x, y, w, h, true);
  203361. return y;
  203362. }
  203363. void UIViewComponentPeer::relativePositionToGlobal (int& x, int& y)
  203364. {
  203365. int wx, wy, ww, wh;
  203366. getBounds (wx, wy, ww, wh, true);
  203367. x += wx;
  203368. y += wy;
  203369. }
  203370. void UIViewComponentPeer::globalPositionToRelative (int& x, int& y)
  203371. {
  203372. int wx, wy, ww, wh;
  203373. getBounds (wx, wy, ww, wh, true);
  203374. x -= wx;
  203375. y -= wy;
  203376. }
  203377. CGRect UIViewComponentPeer::constrainRect (CGRect r)
  203378. {
  203379. if (constrainer != 0)
  203380. {
  203381. CGRect current = [window frame];
  203382. current.origin.y = [[UIScreen mainScreen] bounds].size.height - current.origin.y - current.size.height;
  203383. r.origin.y = [[UIScreen mainScreen] bounds].size.height - r.origin.y - r.size.height;
  203384. Rectangle<int> pos ((int) r.origin.x, (int) r.origin.y,
  203385. (int) r.size.width, (int) r.size.height);
  203386. Rectangle<int> original ((int) current.origin.x, (int) current.origin.y,
  203387. (int) current.size.width, (int) current.size.height);
  203388. constrainer->checkBounds (pos, original,
  203389. Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(),
  203390. pos.getY() != original.getY() && pos.getBottom() == original.getBottom(),
  203391. pos.getX() != original.getX() && pos.getRight() == original.getRight(),
  203392. pos.getY() == original.getY() && pos.getBottom() != original.getBottom(),
  203393. pos.getX() == original.getX() && pos.getRight() != original.getRight());
  203394. r.origin.x = pos.getX();
  203395. r.origin.y = [[UIScreen mainScreen] bounds].size.height - r.size.height - pos.getY();
  203396. r.size.width = pos.getWidth();
  203397. r.size.height = pos.getHeight();
  203398. }
  203399. return r;
  203400. }
  203401. void UIViewComponentPeer::setMinimised (bool shouldBeMinimised)
  203402. {
  203403. // xxx
  203404. }
  203405. bool UIViewComponentPeer::isMinimised() const
  203406. {
  203407. return false;
  203408. }
  203409. void UIViewComponentPeer::setFullScreen (bool shouldBeFullScreen)
  203410. {
  203411. if (! isSharedWindow)
  203412. {
  203413. Rectangle<int> r (lastNonFullscreenBounds);
  203414. setMinimised (false);
  203415. if (fullScreen != shouldBeFullScreen)
  203416. {
  203417. if (shouldBeFullScreen)
  203418. r = Desktop::getInstance().getMainMonitorArea();
  203419. // (can't call the component's setBounds method because that'll reset our fullscreen flag)
  203420. if (r != getComponent()->getBounds() && ! r.isEmpty())
  203421. setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight(), shouldBeFullScreen);
  203422. }
  203423. }
  203424. }
  203425. bool UIViewComponentPeer::isFullScreen() const
  203426. {
  203427. return fullScreen;
  203428. }
  203429. bool UIViewComponentPeer::contains (int x, int y, bool trueIfInAChildWindow) const
  203430. {
  203431. if (((unsigned int) x) >= (unsigned int) component->getWidth()
  203432. || ((unsigned int) y) >= (unsigned int) component->getHeight())
  203433. return false;
  203434. CGPoint p;
  203435. p.x = (float) x;
  203436. p.y = (float) y;
  203437. UIView* v = [view hitTest: p withEvent: nil];
  203438. if (trueIfInAChildWindow)
  203439. return v != nil;
  203440. return v == view;
  203441. }
  203442. const BorderSize UIViewComponentPeer::getFrameSize() const
  203443. {
  203444. BorderSize b;
  203445. if (! isSharedWindow)
  203446. {
  203447. CGRect v = [view convertRect: [view frame] toView: nil];
  203448. CGRect w = [window frame];
  203449. b.setTop ((int) (w.size.height - (v.origin.y + v.size.height)));
  203450. b.setBottom ((int) v.origin.y);
  203451. b.setLeft ((int) v.origin.x);
  203452. b.setRight ((int) (w.size.width - (v.origin.x + v.size.width)));
  203453. }
  203454. return b;
  203455. }
  203456. bool UIViewComponentPeer::setAlwaysOnTop (bool alwaysOnTop)
  203457. {
  203458. if (! isSharedWindow)
  203459. window.windowLevel = alwaysOnTop ? UIWindowLevelAlert : UIWindowLevelNormal;
  203460. return true;
  203461. }
  203462. void UIViewComponentPeer::toFront (bool makeActiveWindow)
  203463. {
  203464. if (isSharedWindow)
  203465. [[view superview] bringSubviewToFront: view];
  203466. if (window != 0 && component->isVisible())
  203467. [window makeKeyAndVisible];
  203468. }
  203469. void UIViewComponentPeer::toBehind (ComponentPeer* other)
  203470. {
  203471. UIViewComponentPeer* o = (UIViewComponentPeer*) other;
  203472. if (isSharedWindow)
  203473. {
  203474. [[view superview] insertSubview: view belowSubview: o->view];
  203475. }
  203476. else
  203477. {
  203478. jassertfalse // don't know how to do this
  203479. }
  203480. }
  203481. void UIViewComponentPeer::setIcon (const Image& /*newIcon*/)
  203482. {
  203483. // to do..
  203484. }
  203485. static UIViewComponentPeer* currentlyFocusedPeer = 0;
  203486. void UIViewComponentPeer::viewFocusGain()
  203487. {
  203488. if (currentlyFocusedPeer != this)
  203489. {
  203490. if (ComponentPeer::isValidPeer (currentlyFocusedPeer))
  203491. currentlyFocusedPeer->handleFocusLoss();
  203492. currentlyFocusedPeer = this;
  203493. handleFocusGain();
  203494. }
  203495. }
  203496. void UIViewComponentPeer::viewFocusLoss()
  203497. {
  203498. if (currentlyFocusedPeer == this)
  203499. {
  203500. currentlyFocusedPeer = 0;
  203501. handleFocusLoss();
  203502. }
  203503. }
  203504. void juce_HandleProcessFocusChange()
  203505. {
  203506. if (UIViewComponentPeer::isValidPeer (currentlyFocusedPeer))
  203507. {
  203508. if (Process::isForegroundProcess())
  203509. {
  203510. currentlyFocusedPeer->handleFocusGain();
  203511. ComponentPeer::bringModalComponentToFront();
  203512. }
  203513. else
  203514. {
  203515. currentlyFocusedPeer->handleFocusLoss();
  203516. // turn kiosk mode off if we lose focus..
  203517. Desktop::getInstance().setKioskModeComponent (0);
  203518. }
  203519. }
  203520. }
  203521. bool UIViewComponentPeer::isFocused() const
  203522. {
  203523. return isSharedWindow ? this == currentlyFocusedPeer
  203524. : (window != 0 && [window isKeyWindow]);
  203525. }
  203526. void UIViewComponentPeer::grabFocus()
  203527. {
  203528. if (window != 0)
  203529. {
  203530. [window makeKeyWindow];
  203531. viewFocusGain();
  203532. }
  203533. }
  203534. void UIViewComponentPeer::textInputRequired (int /*x*/, int /*y*/)
  203535. {
  203536. }
  203537. void UIViewComponentPeer::drawRect (CGRect r)
  203538. {
  203539. if (r.size.width < 1.0f || r.size.height < 1.0f)
  203540. return;
  203541. CGContextRef cg = UIGraphicsGetCurrentContext();
  203542. if (! component->isOpaque())
  203543. CGContextClearRect (cg, CGContextGetClipBoundingBox (cg));
  203544. CGContextConcatCTM (cg, CGAffineTransformMake (1, 0, 0, -1, 0, view.bounds.size.height));
  203545. CoreGraphicsContext g (cg, view.bounds.size.height);
  203546. insideDrawRect = true;
  203547. handlePaint (g);
  203548. insideDrawRect = false;
  203549. }
  203550. bool UIViewComponentPeer::canBecomeKeyWindow()
  203551. {
  203552. return (getStyleFlags() & JUCE_NAMESPACE::ComponentPeer::windowIgnoresKeyPresses) == 0;
  203553. }
  203554. bool UIViewComponentPeer::windowShouldClose()
  203555. {
  203556. if (! isValidPeer (this))
  203557. return YES;
  203558. handleUserClosingWindow();
  203559. return NO;
  203560. }
  203561. void UIViewComponentPeer::redirectMovedOrResized()
  203562. {
  203563. handleMovedOrResized();
  203564. }
  203565. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  203566. {
  203567. }
  203568. class AsyncRepaintMessage : public CallbackMessage
  203569. {
  203570. public:
  203571. UIViewComponentPeer* const peer;
  203572. const Rectangle<int> rect;
  203573. AsyncRepaintMessage (UIViewComponentPeer* const peer_, const Rectangle<int>& rect_)
  203574. : peer (peer_), rect (rect_)
  203575. {
  203576. }
  203577. void messageCallback()
  203578. {
  203579. if (ComponentPeer::isValidPeer (peer))
  203580. peer->repaint (rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
  203581. }
  203582. };
  203583. void UIViewComponentPeer::repaint (int x, int y, int w, int h)
  203584. {
  203585. if (insideDrawRect || ! MessageManager::getInstance()->isThisTheMessageThread())
  203586. {
  203587. (new AsyncRepaintMessage (this, Rectangle<int> (x, y, w, h)))->post();
  203588. }
  203589. else
  203590. {
  203591. [view setNeedsDisplayInRect: CGRectMake ((float) x, (float) y, (float) w, (float) h)];
  203592. }
  203593. }
  203594. void UIViewComponentPeer::performAnyPendingRepaintsNow()
  203595. {
  203596. }
  203597. ComponentPeer* Component::createNewPeer (int styleFlags, void* windowToAttachTo)
  203598. {
  203599. return new UIViewComponentPeer (this, styleFlags, (UIView*) windowToAttachTo);
  203600. }
  203601. Image* juce_createIconForFile (const File& file)
  203602. {
  203603. return 0;
  203604. }
  203605. bool Desktop::canUseSemiTransparentWindows() throw()
  203606. {
  203607. return true;
  203608. }
  203609. void Desktop::getMousePosition (int& x, int& y) throw()
  203610. {
  203611. x = juce_lastMouseX;
  203612. y = juce_lastMouseY;
  203613. }
  203614. void Desktop::setMousePosition (int x, int y) throw()
  203615. {
  203616. }
  203617. const int KeyPress::spaceKey = ' ';
  203618. const int KeyPress::returnKey = 0x0d;
  203619. const int KeyPress::escapeKey = 0x1b;
  203620. const int KeyPress::backspaceKey = 0x7f;
  203621. const int KeyPress::leftKey = 0x1000;
  203622. const int KeyPress::rightKey = 0x1001;
  203623. const int KeyPress::upKey = 0x1002;
  203624. const int KeyPress::downKey = 0x1003;
  203625. const int KeyPress::pageUpKey = 0x1004;
  203626. const int KeyPress::pageDownKey = 0x1005;
  203627. const int KeyPress::endKey = 0x1006;
  203628. const int KeyPress::homeKey = 0x1007;
  203629. const int KeyPress::deleteKey = 0x1008;
  203630. const int KeyPress::insertKey = -1;
  203631. const int KeyPress::tabKey = 9;
  203632. const int KeyPress::F1Key = 0x2001;
  203633. const int KeyPress::F2Key = 0x2002;
  203634. const int KeyPress::F3Key = 0x2003;
  203635. const int KeyPress::F4Key = 0x2004;
  203636. const int KeyPress::F5Key = 0x2005;
  203637. const int KeyPress::F6Key = 0x2006;
  203638. const int KeyPress::F7Key = 0x2007;
  203639. const int KeyPress::F8Key = 0x2008;
  203640. const int KeyPress::F9Key = 0x2009;
  203641. const int KeyPress::F10Key = 0x200a;
  203642. const int KeyPress::F11Key = 0x200b;
  203643. const int KeyPress::F12Key = 0x200c;
  203644. const int KeyPress::F13Key = 0x200d;
  203645. const int KeyPress::F14Key = 0x200e;
  203646. const int KeyPress::F15Key = 0x200f;
  203647. const int KeyPress::F16Key = 0x2010;
  203648. const int KeyPress::numberPad0 = 0x30020;
  203649. const int KeyPress::numberPad1 = 0x30021;
  203650. const int KeyPress::numberPad2 = 0x30022;
  203651. const int KeyPress::numberPad3 = 0x30023;
  203652. const int KeyPress::numberPad4 = 0x30024;
  203653. const int KeyPress::numberPad5 = 0x30025;
  203654. const int KeyPress::numberPad6 = 0x30026;
  203655. const int KeyPress::numberPad7 = 0x30027;
  203656. const int KeyPress::numberPad8 = 0x30028;
  203657. const int KeyPress::numberPad9 = 0x30029;
  203658. const int KeyPress::numberPadAdd = 0x3002a;
  203659. const int KeyPress::numberPadSubtract = 0x3002b;
  203660. const int KeyPress::numberPadMultiply = 0x3002c;
  203661. const int KeyPress::numberPadDivide = 0x3002d;
  203662. const int KeyPress::numberPadSeparator = 0x3002e;
  203663. const int KeyPress::numberPadDecimalPoint = 0x3002f;
  203664. const int KeyPress::numberPadEquals = 0x30030;
  203665. const int KeyPress::numberPadDelete = 0x30031;
  203666. const int KeyPress::playKey = 0x30000;
  203667. const int KeyPress::stopKey = 0x30001;
  203668. const int KeyPress::fastForwardKey = 0x30002;
  203669. const int KeyPress::rewindKey = 0x30003;
  203670. #endif
  203671. /*** End of inlined file: juce_iphone_UIViewComponentPeer.mm ***/
  203672. /*** Start of inlined file: juce_iphone_MessageManager.mm ***/
  203673. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203674. // compiled on its own).
  203675. #if JUCE_INCLUDED_FILE
  203676. struct CallbackMessagePayload
  203677. {
  203678. MessageCallbackFunction* function;
  203679. void* parameter;
  203680. void* volatile result;
  203681. bool volatile hasBeenExecuted;
  203682. };
  203683. END_JUCE_NAMESPACE
  203684. using namespace JUCE_NAMESPACE;
  203685. @interface JuceAppDelegate : NSObject <UIApplicationDelegate>
  203686. {
  203687. }
  203688. - (JuceAppDelegate*) init;
  203689. - (void) dealloc;
  203690. - (BOOL) application: (UIApplication*) application handleOpenURL: (NSURL*) url;
  203691. - (void) applicationDidBecomeActive: (NSNotification*) aNotification;
  203692. - (void) applicationDidResignActive: (NSNotification*) aNotification;
  203693. - (void) applicationWillUnhide: (NSNotification*) aNotification;
  203694. - (void) customEvent: (id) data;
  203695. - (void) performCallback: (id) info;
  203696. @end
  203697. @implementation JuceAppDelegate
  203698. - (JuceAppDelegate*) init
  203699. {
  203700. [super init];
  203701. [[UIApplication sharedApplication] setDelegate: self];
  203702. return self;
  203703. }
  203704. - (void) dealloc
  203705. {
  203706. [[UIApplication sharedApplication] setDelegate: nil];
  203707. [super dealloc];
  203708. }
  203709. - (BOOL) application: (UIApplication*) application handleOpenURL: (NSURL*) url
  203710. {
  203711. if (JUCEApplication::getInstance() != 0)
  203712. {
  203713. JUCEApplication::getInstance()->anotherInstanceStarted (nsStringToJuce ([url absoluteString]));
  203714. return YES;
  203715. }
  203716. return NO;
  203717. }
  203718. - (void) applicationDidBecomeActive: (NSNotification*) aNotification
  203719. {
  203720. juce_HandleProcessFocusChange();
  203721. }
  203722. - (void) applicationDidResignActive: (NSNotification*) aNotification
  203723. {
  203724. juce_HandleProcessFocusChange();
  203725. }
  203726. - (void) applicationWillUnhide: (NSNotification*) aNotification
  203727. {
  203728. juce_HandleProcessFocusChange();
  203729. }
  203730. - (void) customEvent: (id) n
  203731. {
  203732. NSData* data = (NSData*) n;
  203733. void* message = 0;
  203734. [data getBytes: &message length: sizeof (message)];
  203735. [data release];
  203736. if (message != 0)
  203737. MessageManager::getInstance()->deliverMessage (message);
  203738. }
  203739. - (void) performCallback: (id) info
  203740. {
  203741. if ([info isKindOfClass: [NSData class]])
  203742. {
  203743. CallbackMessagePayload* pl = (CallbackMessagePayload*) [((NSData*) info) bytes];
  203744. if (pl != 0)
  203745. {
  203746. pl->result = (*pl->function) (pl->parameter);
  203747. pl->hasBeenExecuted = true;
  203748. }
  203749. }
  203750. else
  203751. {
  203752. jassertfalse // should never get here!
  203753. }
  203754. }
  203755. @end
  203756. BEGIN_JUCE_NAMESPACE
  203757. static JuceAppDelegate* juceAppDelegate = 0;
  203758. void MessageManager::runDispatchLoop()
  203759. {
  203760. jassert (isThisTheMessageThread()); // must only be called by the message thread
  203761. runDispatchLoopUntil (-1);
  203762. }
  203763. void MessageManager::stopDispatchLoop()
  203764. {
  203765. exit (0); // iPhone apps get no mercy..
  203766. }
  203767. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  203768. {
  203769. const ScopedAutoReleasePool pool;
  203770. jassert (isThisTheMessageThread()); // must only be called by the message thread
  203771. uint32 endTime = Time::getMillisecondCounter() + millisecondsToRunFor;
  203772. NSDate* endDate = [NSDate dateWithTimeIntervalSinceNow: millisecondsToRunFor * 0.001];
  203773. while (! quitMessagePosted)
  203774. {
  203775. const ScopedAutoReleasePool pool;
  203776. [[NSRunLoop currentRunLoop] runMode: NSDefaultRunLoopMode
  203777. beforeDate: endDate];
  203778. if (millisecondsToRunFor >= 0 && Time::getMillisecondCounter() >= endTime)
  203779. break;
  203780. }
  203781. return ! quitMessagePosted;
  203782. }
  203783. static CFRunLoopRef runLoop = 0;
  203784. static CFRunLoopSourceRef runLoopSource = 0;
  203785. static Array <void*, CriticalSection>* pendingMessages = 0;
  203786. static void runLoopSourceCallback (void*)
  203787. {
  203788. if (pendingMessages != 0)
  203789. {
  203790. int numDispatched = 0;
  203791. do
  203792. {
  203793. void* const nextMessage = pendingMessages->remove (0);
  203794. if (nextMessage == 0)
  203795. return;
  203796. const ScopedAutoReleasePool pool;
  203797. MessageManager::getInstance()->deliverMessage (nextMessage);
  203798. } while (++numDispatched <= 4);
  203799. CFRunLoopSourceSignal (runLoopSource);
  203800. CFRunLoopWakeUp (runLoop);
  203801. }
  203802. }
  203803. void MessageManager::doPlatformSpecificInitialisation()
  203804. {
  203805. pendingMessages = new Array <void*, CriticalSection>();
  203806. runLoop = CFRunLoopGetCurrent();
  203807. CFRunLoopSourceContext sourceContext;
  203808. zerostruct (sourceContext);
  203809. sourceContext.perform = runLoopSourceCallback;
  203810. runLoopSource = CFRunLoopSourceCreate (kCFAllocatorDefault, 1, &sourceContext);
  203811. CFRunLoopAddSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
  203812. if (juceAppDelegate == 0)
  203813. juceAppDelegate = [[JuceAppDelegate alloc] init];
  203814. }
  203815. void MessageManager::doPlatformSpecificShutdown()
  203816. {
  203817. CFRunLoopSourceInvalidate (runLoopSource);
  203818. CFRelease (runLoopSource);
  203819. runLoopSource = 0;
  203820. if (pendingMessages != 0)
  203821. {
  203822. while (pendingMessages->size() > 0)
  203823. delete ((Message*) pendingMessages->remove(0));
  203824. deleteAndZero (pendingMessages);
  203825. }
  203826. if (juceAppDelegate != 0)
  203827. {
  203828. [[NSRunLoop currentRunLoop] cancelPerformSelectorsWithTarget: juceAppDelegate];
  203829. [juceAppDelegate release];
  203830. juceAppDelegate = 0;
  203831. }
  203832. }
  203833. bool juce_postMessageToSystemQueue (void* message)
  203834. {
  203835. if (pendingMessages != 0)
  203836. {
  203837. pendingMessages->add (message);
  203838. CFRunLoopSourceSignal (runLoopSource);
  203839. CFRunLoopWakeUp (runLoop);
  203840. }
  203841. return true;
  203842. }
  203843. void MessageManager::broadcastMessage (const String& value) throw()
  203844. {
  203845. }
  203846. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
  203847. void* data)
  203848. {
  203849. if (isThisTheMessageThread())
  203850. {
  203851. return (*callback) (data);
  203852. }
  203853. else
  203854. {
  203855. // If a thread has a MessageManagerLock and then tries to call this method, it'll
  203856. // deadlock because the message manager is blocked from running, so can never
  203857. // call your function..
  203858. jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  203859. const ScopedAutoReleasePool pool;
  203860. CallbackMessagePayload cmp;
  203861. cmp.function = callback;
  203862. cmp.parameter = data;
  203863. cmp.result = 0;
  203864. cmp.hasBeenExecuted = false;
  203865. [juceAppDelegate performSelectorOnMainThread: @selector (performCallback:)
  203866. withObject: [NSData dataWithBytesNoCopy: &cmp
  203867. length: sizeof (cmp)
  203868. freeWhenDone: NO]
  203869. waitUntilDone: YES];
  203870. return cmp.result;
  203871. }
  203872. }
  203873. #endif
  203874. /*** End of inlined file: juce_iphone_MessageManager.mm ***/
  203875. /*** Start of inlined file: juce_mac_FileChooser.mm ***/
  203876. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203877. // compiled on its own).
  203878. #if JUCE_INCLUDED_FILE
  203879. #if JUCE_MAC
  203880. END_JUCE_NAMESPACE
  203881. using namespace JUCE_NAMESPACE;
  203882. #define JuceFileChooserDelegate MakeObjCClassName(JuceFileChooserDelegate)
  203883. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  203884. @interface JuceFileChooserDelegate : NSObject <NSOpenSavePanelDelegate>
  203885. #else
  203886. @interface JuceFileChooserDelegate : NSObject
  203887. #endif
  203888. {
  203889. StringArray* filters;
  203890. }
  203891. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_;
  203892. - (void) dealloc;
  203893. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename;
  203894. @end
  203895. @implementation JuceFileChooserDelegate
  203896. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_
  203897. {
  203898. [super init];
  203899. filters = filters_;
  203900. return self;
  203901. }
  203902. - (void) dealloc
  203903. {
  203904. delete filters;
  203905. [super dealloc];
  203906. }
  203907. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename
  203908. {
  203909. const File f (nsStringToJuce (filename));
  203910. for (int i = filters->size(); --i >= 0;)
  203911. if (f.getFileName().matchesWildcard ((*filters)[i], true))
  203912. return true;
  203913. return f.isDirectory();
  203914. }
  203915. @end
  203916. BEGIN_JUCE_NAMESPACE
  203917. void FileChooser::showPlatformDialog (Array<File>& results,
  203918. const String& title,
  203919. const File& currentFileOrDirectory,
  203920. const String& filter,
  203921. bool selectsDirectory,
  203922. bool selectsFiles,
  203923. bool isSaveDialogue,
  203924. bool warnAboutOverwritingExistingFiles,
  203925. bool selectMultipleFiles,
  203926. FilePreviewComponent* extraInfoComponent)
  203927. {
  203928. const ScopedAutoReleasePool pool;
  203929. StringArray* filters = new StringArray();
  203930. filters->addTokens (filter.replaceCharacters (T(",:"), T(";;")), T(";"), 0);
  203931. filters->trim();
  203932. filters->removeEmptyStrings();
  203933. JuceFileChooserDelegate* delegate = [[JuceFileChooserDelegate alloc] initWithFilters: filters];
  203934. [delegate autorelease];
  203935. NSSavePanel* panel = isSaveDialogue ? [NSSavePanel savePanel]
  203936. : [NSOpenPanel openPanel];
  203937. [panel setTitle: juceStringToNS (title)];
  203938. if (! isSaveDialogue)
  203939. {
  203940. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  203941. [openPanel setCanChooseDirectories: selectsDirectory];
  203942. [openPanel setCanChooseFiles: selectsFiles];
  203943. [openPanel setAllowsMultipleSelection: selectMultipleFiles];
  203944. }
  203945. [panel setDelegate: delegate];
  203946. if (isSaveDialogue || selectsDirectory)
  203947. [panel setCanCreateDirectories: YES];
  203948. String directory, filename;
  203949. if (currentFileOrDirectory.isDirectory())
  203950. {
  203951. directory = currentFileOrDirectory.getFullPathName();
  203952. }
  203953. else
  203954. {
  203955. directory = currentFileOrDirectory.getParentDirectory().getFullPathName();
  203956. filename = currentFileOrDirectory.getFileName();
  203957. }
  203958. if ([panel runModalForDirectory: juceStringToNS (directory)
  203959. file: juceStringToNS (filename)]
  203960. == NSOKButton)
  203961. {
  203962. if (isSaveDialogue)
  203963. {
  203964. results.add (File (nsStringToJuce ([panel filename])));
  203965. }
  203966. else
  203967. {
  203968. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  203969. NSArray* urls = [openPanel filenames];
  203970. for (unsigned int i = 0; i < [urls count]; ++i)
  203971. {
  203972. NSString* f = [urls objectAtIndex: i];
  203973. results.add (File (nsStringToJuce (f)));
  203974. }
  203975. }
  203976. }
  203977. [panel setDelegate: nil];
  203978. }
  203979. #else
  203980. void FileChooser::showPlatformDialog (Array<File>& results,
  203981. const String& title,
  203982. const File& currentFileOrDirectory,
  203983. const String& filter,
  203984. bool selectsDirectory,
  203985. bool selectsFiles,
  203986. bool isSaveDialogue,
  203987. bool warnAboutOverwritingExistingFiles,
  203988. bool selectMultipleFiles,
  203989. FilePreviewComponent* extraInfoComponent)
  203990. {
  203991. const ScopedAutoReleasePool pool;
  203992. jassertfalse //xxx to do
  203993. }
  203994. #endif
  203995. #endif
  203996. /*** End of inlined file: juce_mac_FileChooser.mm ***/
  203997. /*** Start of inlined file: juce_mac_OpenGLComponent.mm ***/
  203998. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203999. // compiled on its own).
  204000. #if JUCE_INCLUDED_FILE && JUCE_OPENGL
  204001. #if JUCE_MAC
  204002. END_JUCE_NAMESPACE
  204003. #define ThreadSafeNSOpenGLView MakeObjCClassName(ThreadSafeNSOpenGLView)
  204004. @interface ThreadSafeNSOpenGLView : NSOpenGLView
  204005. {
  204006. CriticalSection* contextLock;
  204007. bool needsUpdate;
  204008. }
  204009. - (id) initWithFrame: (NSRect) frameRect pixelFormat: (NSOpenGLPixelFormat*) format;
  204010. - (bool) makeActive;
  204011. - (void) makeInactive;
  204012. - (void) reshape;
  204013. @end
  204014. @implementation ThreadSafeNSOpenGLView
  204015. - (id) initWithFrame: (NSRect) frameRect
  204016. pixelFormat: (NSOpenGLPixelFormat*) format
  204017. {
  204018. contextLock = new CriticalSection();
  204019. self = [super initWithFrame: frameRect pixelFormat: format];
  204020. if (self != nil)
  204021. [[NSNotificationCenter defaultCenter] addObserver: self
  204022. selector: @selector (_surfaceNeedsUpdate:)
  204023. name: NSViewGlobalFrameDidChangeNotification
  204024. object: self];
  204025. return self;
  204026. }
  204027. - (void) dealloc
  204028. {
  204029. [[NSNotificationCenter defaultCenter] removeObserver: self];
  204030. delete contextLock;
  204031. [super dealloc];
  204032. }
  204033. - (bool) makeActive
  204034. {
  204035. const ScopedLock sl (*contextLock);
  204036. if ([self openGLContext] == 0)
  204037. return false;
  204038. [[self openGLContext] makeCurrentContext];
  204039. if (needsUpdate)
  204040. {
  204041. [super update];
  204042. needsUpdate = false;
  204043. }
  204044. return true;
  204045. }
  204046. - (void) makeInactive
  204047. {
  204048. const ScopedLock sl (*contextLock);
  204049. [NSOpenGLContext clearCurrentContext];
  204050. }
  204051. - (void) _surfaceNeedsUpdate: (NSNotification*) notification
  204052. {
  204053. const ScopedLock sl (*contextLock);
  204054. needsUpdate = true;
  204055. }
  204056. - (void) update
  204057. {
  204058. const ScopedLock sl (*contextLock);
  204059. needsUpdate = true;
  204060. }
  204061. - (void) reshape
  204062. {
  204063. const ScopedLock sl (*contextLock);
  204064. needsUpdate = true;
  204065. }
  204066. @end
  204067. BEGIN_JUCE_NAMESPACE
  204068. class WindowedGLContext : public OpenGLContext
  204069. {
  204070. public:
  204071. WindowedGLContext (Component* const component,
  204072. const OpenGLPixelFormat& pixelFormat_,
  204073. NSOpenGLContext* sharedContext)
  204074. : renderContext (0),
  204075. pixelFormat (pixelFormat_)
  204076. {
  204077. jassert (component != 0);
  204078. NSOpenGLPixelFormatAttribute attribs [64];
  204079. int n = 0;
  204080. attribs[n++] = NSOpenGLPFADoubleBuffer;
  204081. attribs[n++] = NSOpenGLPFAAccelerated;
  204082. attribs[n++] = NSOpenGLPFAMPSafe; // NSOpenGLPFAAccelerated, NSOpenGLPFAMultiScreen, NSOpenGLPFASingleRenderer
  204083. attribs[n++] = NSOpenGLPFAColorSize;
  204084. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.redBits,
  204085. pixelFormat.greenBits,
  204086. pixelFormat.blueBits);
  204087. attribs[n++] = NSOpenGLPFAAlphaSize;
  204088. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.alphaBits;
  204089. attribs[n++] = NSOpenGLPFADepthSize;
  204090. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.depthBufferBits;
  204091. attribs[n++] = NSOpenGLPFAStencilSize;
  204092. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.stencilBufferBits;
  204093. attribs[n++] = NSOpenGLPFAAccumSize;
  204094. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.accumulationBufferRedBits,
  204095. pixelFormat.accumulationBufferGreenBits,
  204096. pixelFormat.accumulationBufferBlueBits,
  204097. pixelFormat.accumulationBufferAlphaBits);
  204098. // xxx not sure how to do fullSceneAntiAliasingNumSamples..
  204099. attribs[n++] = NSOpenGLPFASampleBuffers;
  204100. attribs[n++] = (NSOpenGLPixelFormatAttribute) 1;
  204101. attribs[n++] = NSOpenGLPFAClosestPolicy;
  204102. attribs[n++] = NSOpenGLPFANoRecovery;
  204103. attribs[n++] = (NSOpenGLPixelFormatAttribute) 0;
  204104. NSOpenGLPixelFormat* format
  204105. = [[NSOpenGLPixelFormat alloc] initWithAttributes: attribs];
  204106. view = [[ThreadSafeNSOpenGLView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  204107. pixelFormat: format];
  204108. renderContext = [[[NSOpenGLContext alloc] initWithFormat: format
  204109. shareContext: sharedContext] autorelease];
  204110. const GLint swapInterval = 1;
  204111. [renderContext setValues: &swapInterval forParameter: NSOpenGLCPSwapInterval];
  204112. [view setOpenGLContext: renderContext];
  204113. [renderContext setView: view];
  204114. [format release];
  204115. viewHolder = new NSViewComponentInternal (view, component);
  204116. }
  204117. ~WindowedGLContext()
  204118. {
  204119. makeInactive();
  204120. [renderContext clearDrawable];
  204121. viewHolder = 0;
  204122. }
  204123. bool makeActive() const throw()
  204124. {
  204125. jassert (renderContext != 0);
  204126. [view makeActive];
  204127. return isActive();
  204128. }
  204129. bool makeInactive() const throw()
  204130. {
  204131. [view makeInactive];
  204132. return true;
  204133. }
  204134. bool isActive() const throw()
  204135. {
  204136. return [NSOpenGLContext currentContext] == renderContext;
  204137. }
  204138. const OpenGLPixelFormat getPixelFormat() const { return pixelFormat; }
  204139. void* getRawContext() const throw() { return renderContext; }
  204140. void updateWindowPosition (int x, int y, int w, int h, int outerWindowHeight)
  204141. {
  204142. }
  204143. void swapBuffers()
  204144. {
  204145. [renderContext flushBuffer];
  204146. }
  204147. bool setSwapInterval (const int numFramesPerSwap)
  204148. {
  204149. [renderContext setValues: (const GLint*) &numFramesPerSwap
  204150. forParameter: NSOpenGLCPSwapInterval];
  204151. return true;
  204152. }
  204153. int getSwapInterval() const
  204154. {
  204155. GLint numFrames = 0;
  204156. [renderContext getValues: &numFrames
  204157. forParameter: NSOpenGLCPSwapInterval];
  204158. return numFrames;
  204159. }
  204160. void repaint()
  204161. {
  204162. // we need to invalidate the juce view that holds this gl view, to make it
  204163. // cause a repaint callback
  204164. NSView* v = (NSView*) viewHolder->view;
  204165. NSRect r = [v frame];
  204166. // bit of a bodge here.. if we only invalidate the area of the gl component,
  204167. // it's completely covered by the NSOpenGLView, so the OS throws away the
  204168. // repaint message, thus never causing our paint() callback, and never repainting
  204169. // the comp. So invalidating just a little bit around the edge helps..
  204170. [[v superview] setNeedsDisplayInRect: NSInsetRect (r, -2.0f, -2.0f)];
  204171. }
  204172. void* getNativeWindowHandle() const { return viewHolder->view; }
  204173. juce_UseDebuggingNewOperator
  204174. NSOpenGLContext* renderContext;
  204175. ThreadSafeNSOpenGLView* view;
  204176. private:
  204177. OpenGLPixelFormat pixelFormat;
  204178. ScopedPointer <NSViewComponentInternal> viewHolder;
  204179. WindowedGLContext (const WindowedGLContext&);
  204180. const WindowedGLContext& operator= (const WindowedGLContext&);
  204181. };
  204182. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  204183. const OpenGLPixelFormat& pixelFormat,
  204184. const OpenGLContext* const contextToShareWith)
  204185. {
  204186. ScopedPointer <WindowedGLContext> c (new WindowedGLContext (component, pixelFormat,
  204187. contextToShareWith != 0 ? (NSOpenGLContext*) contextToShareWith->getRawContext() : 0));
  204188. return (c->renderContext != 0) ? c.release() : 0;
  204189. }
  204190. void* OpenGLComponent::getNativeWindowHandle() const
  204191. {
  204192. return context != 0 ? ((WindowedGLContext*) context)->getNativeWindowHandle()
  204193. : 0;
  204194. }
  204195. void juce_glViewport (const int w, const int h)
  204196. {
  204197. glViewport (0, 0, w, h);
  204198. }
  204199. void OpenGLPixelFormat::getAvailablePixelFormats (Component* /*component*/,
  204200. OwnedArray <OpenGLPixelFormat>& results)
  204201. {
  204202. /* GLint attribs [64];
  204203. int n = 0;
  204204. attribs[n++] = AGL_RGBA;
  204205. attribs[n++] = AGL_DOUBLEBUFFER;
  204206. attribs[n++] = AGL_ACCELERATED;
  204207. attribs[n++] = AGL_NO_RECOVERY;
  204208. attribs[n++] = AGL_NONE;
  204209. AGLPixelFormat p = aglChoosePixelFormat (0, 0, attribs);
  204210. while (p != 0)
  204211. {
  204212. OpenGLPixelFormat* const pf = new OpenGLPixelFormat();
  204213. pf->redBits = getAGLAttribute (p, AGL_RED_SIZE);
  204214. pf->greenBits = getAGLAttribute (p, AGL_GREEN_SIZE);
  204215. pf->blueBits = getAGLAttribute (p, AGL_BLUE_SIZE);
  204216. pf->alphaBits = getAGLAttribute (p, AGL_ALPHA_SIZE);
  204217. pf->depthBufferBits = getAGLAttribute (p, AGL_DEPTH_SIZE);
  204218. pf->stencilBufferBits = getAGLAttribute (p, AGL_STENCIL_SIZE);
  204219. pf->accumulationBufferRedBits = getAGLAttribute (p, AGL_ACCUM_RED_SIZE);
  204220. pf->accumulationBufferGreenBits = getAGLAttribute (p, AGL_ACCUM_GREEN_SIZE);
  204221. pf->accumulationBufferBlueBits = getAGLAttribute (p, AGL_ACCUM_BLUE_SIZE);
  204222. pf->accumulationBufferAlphaBits = getAGLAttribute (p, AGL_ACCUM_ALPHA_SIZE);
  204223. results.add (pf);
  204224. p = aglNextPixelFormat (p);
  204225. }*/
  204226. //jassertfalse //xxx can't see how you do this in cocoa!
  204227. }
  204228. #else
  204229. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  204230. const OpenGLPixelFormat& pixelFormat,
  204231. const OpenGLContext* const contextToShareWith)
  204232. {
  204233. return 0;
  204234. }
  204235. void juce_glViewport (const int w, const int h)
  204236. {
  204237. //glViewport (0, 0, w, h);
  204238. }
  204239. #endif
  204240. #endif
  204241. /*** End of inlined file: juce_mac_OpenGLComponent.mm ***/
  204242. /*** Start of inlined file: juce_mac_MouseCursor.mm ***/
  204243. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204244. // compiled on its own).
  204245. #if JUCE_INCLUDED_FILE
  204246. #if JUCE_MAC
  204247. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  204248. {
  204249. NSImage* im = CoreGraphicsImage::createNSImage (image);
  204250. NSCursor* c = [[NSCursor alloc] initWithImage: im
  204251. hotSpot: NSMakePoint (hotspotX, hotspotY)];
  204252. [im release];
  204253. return (void*) c;
  204254. }
  204255. static void* juce_cursorFromData (const unsigned char* data, const size_t size, float hx, float hy) throw()
  204256. {
  204257. ScopedPointer <Image> im (ImageFileFormat::loadFrom ((const char*) data, (int) size));
  204258. jassert (im != 0);
  204259. if (im == 0)
  204260. return 0;
  204261. return juce_createMouseCursorFromImage (*im,
  204262. (int) (hx * im->getWidth()),
  204263. (int) (hy * im->getHeight()));
  204264. }
  204265. static void* juce_cursorFromWebKitFile (const char* filename, float hx, float hy)
  204266. {
  204267. File f ("/System/Library/Frameworks/WebKit.framework/Frameworks/WebCore.framework/Resources");
  204268. MemoryBlock mb;
  204269. if (f.getChildFile (filename).loadFileAsData (mb))
  204270. return juce_cursorFromData ((const unsigned char*) mb.getData(), mb.getSize(), hx, hy);
  204271. return 0;
  204272. }
  204273. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  204274. {
  204275. const ScopedAutoReleasePool pool;
  204276. NSCursor* c = 0;
  204277. switch (type)
  204278. {
  204279. case MouseCursor::NormalCursor:
  204280. c = [NSCursor arrowCursor];
  204281. break;
  204282. case MouseCursor::NoCursor:
  204283. {
  204284. Image blank (Image::ARGB, 8, 8, true);
  204285. return juce_createMouseCursorFromImage (blank, 0, 0);
  204286. }
  204287. case MouseCursor::DraggingHandCursor:
  204288. c = [NSCursor openHandCursor];
  204289. break;
  204290. case MouseCursor::CopyingCursor:
  204291. return juce_cursorFromWebKitFile ("copyCursor.png", 0, 0);
  204292. case MouseCursor::WaitCursor:
  204293. c = [NSCursor arrowCursor]; // avoid this on the mac, let the OS provide the beachball
  204294. break;
  204295. //return juce_cursorFromWebKitFile ("waitCursor.png", 0.5f, 0.5f);
  204296. case MouseCursor::IBeamCursor:
  204297. c = [NSCursor IBeamCursor];
  204298. break;
  204299. case MouseCursor::PointingHandCursor:
  204300. c = [NSCursor pointingHandCursor];
  204301. break;
  204302. case MouseCursor::LeftRightResizeCursor:
  204303. c = [NSCursor resizeLeftRightCursor];
  204304. break;
  204305. case MouseCursor::LeftEdgeResizeCursor:
  204306. c = [NSCursor resizeLeftCursor];
  204307. break;
  204308. case MouseCursor::RightEdgeResizeCursor:
  204309. c = [NSCursor resizeRightCursor];
  204310. break;
  204311. case MouseCursor::UpDownResizeCursor:
  204312. case MouseCursor::TopEdgeResizeCursor:
  204313. case MouseCursor::BottomEdgeResizeCursor:
  204314. return juce_cursorFromWebKitFile ("northSouthResizeCursor.png", 0.5f, 0.5f);
  204315. case MouseCursor::TopLeftCornerResizeCursor:
  204316. case MouseCursor::BottomRightCornerResizeCursor:
  204317. return juce_cursorFromWebKitFile ("northWestSouthEastResizeCursor.png", 0.5f, 0.5f);
  204318. case MouseCursor::TopRightCornerResizeCursor:
  204319. case MouseCursor::BottomLeftCornerResizeCursor:
  204320. return juce_cursorFromWebKitFile ("northEastSouthWestResizeCursor.png", 0.5f, 0.5f);
  204321. case MouseCursor::UpDownLeftRightResizeCursor:
  204322. return juce_cursorFromWebKitFile ("moveCursor.png", 0.5f, 0.5f);
  204323. case MouseCursor::CrosshairCursor:
  204324. c = [NSCursor crosshairCursor];
  204325. break;
  204326. }
  204327. [c retain];
  204328. return (void*) c;
  204329. }
  204330. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw()
  204331. {
  204332. NSCursor* c = (NSCursor*) cursorHandle;
  204333. [c release];
  204334. }
  204335. void MouseCursor::showInAllWindows() const throw()
  204336. {
  204337. showInWindow (0);
  204338. }
  204339. void MouseCursor::showInWindow (ComponentPeer*) const throw()
  204340. {
  204341. NSCursor* const c = (NSCursor*) getHandle();
  204342. [c set];
  204343. }
  204344. #else
  204345. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw() { return 0; }
  204346. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw() { return 0; }
  204347. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw() {}
  204348. void MouseCursor::showInAllWindows() const throw() {}
  204349. void MouseCursor::showInWindow (ComponentPeer*) const throw() {}
  204350. #endif
  204351. #endif
  204352. /*** End of inlined file: juce_mac_MouseCursor.mm ***/
  204353. /*** Start of inlined file: juce_mac_WebBrowserComponent.mm ***/
  204354. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204355. // compiled on its own).
  204356. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  204357. #if JUCE_MAC
  204358. END_JUCE_NAMESPACE
  204359. #define DownloadClickDetector MakeObjCClassName(DownloadClickDetector)
  204360. @interface DownloadClickDetector : NSObject
  204361. {
  204362. JUCE_NAMESPACE::WebBrowserComponent* ownerComponent;
  204363. }
  204364. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent;
  204365. - (void) webView: (WebView*) webView decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  204366. request: (NSURLRequest*) request
  204367. frame: (WebFrame*) frame
  204368. decisionListener: (id<WebPolicyDecisionListener>) listener;
  204369. @end
  204370. @implementation DownloadClickDetector
  204371. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent_
  204372. {
  204373. [super init];
  204374. ownerComponent = ownerComponent_;
  204375. return self;
  204376. }
  204377. - (void) webView: (WebView*) sender decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  204378. request: (NSURLRequest*) request
  204379. frame: (WebFrame*) frame
  204380. decisionListener: (id <WebPolicyDecisionListener>) listener
  204381. {
  204382. NSURL* url = [actionInformation valueForKey: @"WebActionOriginalURLKey"];
  204383. if (ownerComponent->pageAboutToLoad (nsStringToJuce ([url absoluteString])))
  204384. [listener use];
  204385. else
  204386. [listener ignore];
  204387. }
  204388. @end
  204389. BEGIN_JUCE_NAMESPACE
  204390. class WebBrowserComponentInternal : public NSViewComponent
  204391. {
  204392. public:
  204393. WebBrowserComponentInternal (WebBrowserComponent* owner)
  204394. {
  204395. webView = [[WebView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  204396. frameName: @""
  204397. groupName: @""];
  204398. setView (webView);
  204399. clickListener = [[DownloadClickDetector alloc] initWithWebBrowserOwner: owner];
  204400. [webView setPolicyDelegate: clickListener];
  204401. }
  204402. ~WebBrowserComponentInternal()
  204403. {
  204404. [webView setPolicyDelegate: nil];
  204405. [clickListener release];
  204406. setView (0);
  204407. }
  204408. void goToURL (const String& url,
  204409. const StringArray* headers,
  204410. const MemoryBlock* postData)
  204411. {
  204412. NSMutableURLRequest* r
  204413. = [NSMutableURLRequest requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
  204414. cachePolicy: NSURLRequestUseProtocolCachePolicy
  204415. timeoutInterval: 30.0];
  204416. if (postData != 0 && postData->getSize() > 0)
  204417. {
  204418. [r setHTTPMethod: @"POST"];
  204419. [r setHTTPBody: [NSData dataWithBytes: postData->getData()
  204420. length: postData->getSize()]];
  204421. }
  204422. if (headers != 0)
  204423. {
  204424. for (int i = 0; i < headers->size(); ++i)
  204425. {
  204426. const String headerName ((*headers)[i].upToFirstOccurrenceOf (T(":"), false, false).trim());
  204427. const String headerValue ((*headers)[i].fromFirstOccurrenceOf (T(":"), false, false).trim());
  204428. [r setValue: juceStringToNS (headerValue)
  204429. forHTTPHeaderField: juceStringToNS (headerName)];
  204430. }
  204431. }
  204432. stop();
  204433. [[webView mainFrame] loadRequest: r];
  204434. }
  204435. void goBack()
  204436. {
  204437. [webView goBack];
  204438. }
  204439. void goForward()
  204440. {
  204441. [webView goForward];
  204442. }
  204443. void stop()
  204444. {
  204445. [webView stopLoading: nil];
  204446. }
  204447. void refresh()
  204448. {
  204449. [webView reload: nil];
  204450. }
  204451. private:
  204452. WebView* webView;
  204453. DownloadClickDetector* clickListener;
  204454. };
  204455. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  204456. : browser (0),
  204457. blankPageShown (false),
  204458. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  204459. {
  204460. setOpaque (true);
  204461. addAndMakeVisible (browser = new WebBrowserComponentInternal (this));
  204462. }
  204463. WebBrowserComponent::~WebBrowserComponent()
  204464. {
  204465. deleteAndZero (browser);
  204466. }
  204467. void WebBrowserComponent::goToURL (const String& url,
  204468. const StringArray* headers,
  204469. const MemoryBlock* postData)
  204470. {
  204471. lastURL = url;
  204472. lastHeaders.clear();
  204473. if (headers != 0)
  204474. lastHeaders = *headers;
  204475. lastPostData.setSize (0);
  204476. if (postData != 0)
  204477. lastPostData = *postData;
  204478. blankPageShown = false;
  204479. browser->goToURL (url, headers, postData);
  204480. }
  204481. void WebBrowserComponent::stop()
  204482. {
  204483. browser->stop();
  204484. }
  204485. void WebBrowserComponent::goBack()
  204486. {
  204487. lastURL = String::empty;
  204488. blankPageShown = false;
  204489. browser->goBack();
  204490. }
  204491. void WebBrowserComponent::goForward()
  204492. {
  204493. lastURL = String::empty;
  204494. browser->goForward();
  204495. }
  204496. void WebBrowserComponent::refresh()
  204497. {
  204498. browser->refresh();
  204499. }
  204500. void WebBrowserComponent::paint (Graphics& g)
  204501. {
  204502. }
  204503. void WebBrowserComponent::checkWindowAssociation()
  204504. {
  204505. if (isShowing())
  204506. {
  204507. if (blankPageShown)
  204508. goBack();
  204509. }
  204510. else
  204511. {
  204512. if (unloadPageWhenBrowserIsHidden && ! blankPageShown)
  204513. {
  204514. // when the component becomes invisible, some stuff like flash
  204515. // carries on playing audio, so we need to force it onto a blank
  204516. // page to avoid this, (and send it back when it's made visible again).
  204517. blankPageShown = true;
  204518. browser->goToURL ("about:blank", 0, 0);
  204519. }
  204520. }
  204521. }
  204522. void WebBrowserComponent::reloadLastURL()
  204523. {
  204524. if (lastURL.isNotEmpty())
  204525. {
  204526. goToURL (lastURL, &lastHeaders, &lastPostData);
  204527. lastURL = String::empty;
  204528. }
  204529. }
  204530. void WebBrowserComponent::parentHierarchyChanged()
  204531. {
  204532. checkWindowAssociation();
  204533. }
  204534. void WebBrowserComponent::resized()
  204535. {
  204536. browser->setSize (getWidth(), getHeight());
  204537. }
  204538. void WebBrowserComponent::visibilityChanged()
  204539. {
  204540. checkWindowAssociation();
  204541. }
  204542. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  204543. {
  204544. return true;
  204545. }
  204546. #else
  204547. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  204548. {
  204549. }
  204550. WebBrowserComponent::~WebBrowserComponent()
  204551. {
  204552. }
  204553. void WebBrowserComponent::goToURL (const String& url,
  204554. const StringArray* headers,
  204555. const MemoryBlock* postData)
  204556. {
  204557. }
  204558. void WebBrowserComponent::stop()
  204559. {
  204560. }
  204561. void WebBrowserComponent::goBack()
  204562. {
  204563. }
  204564. void WebBrowserComponent::goForward()
  204565. {
  204566. }
  204567. void WebBrowserComponent::refresh()
  204568. {
  204569. }
  204570. void WebBrowserComponent::paint (Graphics& g)
  204571. {
  204572. }
  204573. void WebBrowserComponent::checkWindowAssociation()
  204574. {
  204575. }
  204576. void WebBrowserComponent::reloadLastURL()
  204577. {
  204578. }
  204579. void WebBrowserComponent::parentHierarchyChanged()
  204580. {
  204581. }
  204582. void WebBrowserComponent::resized()
  204583. {
  204584. }
  204585. void WebBrowserComponent::visibilityChanged()
  204586. {
  204587. }
  204588. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  204589. {
  204590. return true;
  204591. }
  204592. #endif
  204593. #endif
  204594. /*** End of inlined file: juce_mac_WebBrowserComponent.mm ***/
  204595. /*** Start of inlined file: juce_iphone_Audio.cpp ***/
  204596. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204597. // compiled on its own).
  204598. #if JUCE_INCLUDED_FILE
  204599. class IPhoneAudioIODevice : public AudioIODevice
  204600. {
  204601. public:
  204602. IPhoneAudioIODevice (const String& deviceName)
  204603. : AudioIODevice (deviceName, T("Audio")),
  204604. audioUnit (0),
  204605. isRunning (false),
  204606. callback (0),
  204607. actualBufferSize (0),
  204608. floatData (1, 2)
  204609. {
  204610. numInputChannels = 2;
  204611. numOutputChannels = 2;
  204612. preferredBufferSize = 0;
  204613. AudioSessionInitialize (0, 0, interruptionListenerStatic, this);
  204614. updateDeviceInfo();
  204615. }
  204616. ~IPhoneAudioIODevice()
  204617. {
  204618. close();
  204619. }
  204620. const StringArray getOutputChannelNames()
  204621. {
  204622. StringArray s;
  204623. s.add ("Left");
  204624. s.add ("Right");
  204625. return s;
  204626. }
  204627. const StringArray getInputChannelNames()
  204628. {
  204629. StringArray s;
  204630. if (audioInputIsAvailable)
  204631. {
  204632. s.add ("Left");
  204633. s.add ("Right");
  204634. }
  204635. return s;
  204636. }
  204637. int getNumSampleRates()
  204638. {
  204639. return 1;
  204640. }
  204641. double getSampleRate (int index)
  204642. {
  204643. return sampleRate;
  204644. }
  204645. int getNumBufferSizesAvailable()
  204646. {
  204647. return 1;
  204648. }
  204649. int getBufferSizeSamples (int index)
  204650. {
  204651. return getDefaultBufferSize();
  204652. }
  204653. int getDefaultBufferSize()
  204654. {
  204655. return 1024;
  204656. }
  204657. const String open (const BitArray& inputChannels,
  204658. const BitArray& outputChannels,
  204659. double sampleRate,
  204660. int bufferSize)
  204661. {
  204662. close();
  204663. lastError = String::empty;
  204664. preferredBufferSize = (bufferSize <= 0) ? getDefaultBufferSize() : bufferSize;
  204665. // xxx set up channel mapping
  204666. activeOutputChans = outputChannels;
  204667. activeOutputChans.setRange (2, activeOutputChans.getHighestBit(), false);
  204668. numOutputChannels = activeOutputChans.countNumberOfSetBits();
  204669. monoOutputChannelNumber = activeOutputChans.findNextSetBit (0);
  204670. activeInputChans = inputChannels;
  204671. activeInputChans.setRange (2, activeInputChans.getHighestBit(), false);
  204672. numInputChannels = activeInputChans.countNumberOfSetBits();
  204673. monoInputChannelNumber = activeInputChans.findNextSetBit (0);
  204674. AudioSessionSetActive (true);
  204675. UInt32 audioCategory = kAudioSessionCategory_PlayAndRecord;
  204676. AudioSessionSetProperty (kAudioSessionProperty_AudioCategory, sizeof (audioCategory), &audioCategory);
  204677. AudioSessionAddPropertyListener (kAudioSessionProperty_AudioRouteChange, propertyChangedStatic, this);
  204678. fixAudioRouteIfSetToReceiver();
  204679. updateDeviceInfo();
  204680. Float32 bufferDuration = preferredBufferSize / sampleRate;
  204681. AudioSessionSetProperty (kAudioSessionProperty_PreferredHardwareIOBufferDuration, sizeof (bufferDuration), &bufferDuration);
  204682. actualBufferSize = preferredBufferSize;
  204683. prepareFloatBuffers();
  204684. isRunning = true;
  204685. propertyChanged (0, 0, 0); // creates and starts the AU
  204686. lastError = audioUnit != 0 ? String::empty
  204687. : T("Couldn't open the device");
  204688. return lastError;
  204689. }
  204690. void close()
  204691. {
  204692. if (isRunning)
  204693. {
  204694. isRunning = false;
  204695. AudioSessionSetActive (false);
  204696. if (audioUnit != 0)
  204697. {
  204698. AudioComponentInstanceDispose (audioUnit);
  204699. audioUnit = 0;
  204700. }
  204701. }
  204702. }
  204703. bool isOpen()
  204704. {
  204705. return isRunning;
  204706. }
  204707. int getCurrentBufferSizeSamples()
  204708. {
  204709. return actualBufferSize;
  204710. }
  204711. double getCurrentSampleRate()
  204712. {
  204713. return sampleRate;
  204714. }
  204715. int getCurrentBitDepth()
  204716. {
  204717. return 16;
  204718. }
  204719. const BitArray getActiveOutputChannels() const
  204720. {
  204721. return activeOutputChans;
  204722. }
  204723. const BitArray getActiveInputChannels() const
  204724. {
  204725. return activeInputChans;
  204726. }
  204727. int getOutputLatencyInSamples()
  204728. {
  204729. return 0; //xxx
  204730. }
  204731. int getInputLatencyInSamples()
  204732. {
  204733. return 0; //xxx
  204734. }
  204735. void start (AudioIODeviceCallback* callback_)
  204736. {
  204737. if (isRunning && callback != callback_)
  204738. {
  204739. if (callback_ != 0)
  204740. callback_->audioDeviceAboutToStart (this);
  204741. callbackLock.enter();
  204742. callback = callback_;
  204743. callbackLock.exit();
  204744. }
  204745. }
  204746. void stop()
  204747. {
  204748. if (isRunning)
  204749. {
  204750. callbackLock.enter();
  204751. AudioIODeviceCallback* const lastCallback = callback;
  204752. callback = 0;
  204753. callbackLock.exit();
  204754. if (lastCallback != 0)
  204755. lastCallback->audioDeviceStopped();
  204756. }
  204757. }
  204758. bool isPlaying()
  204759. {
  204760. return isRunning && callback != 0;
  204761. }
  204762. const String getLastError()
  204763. {
  204764. return lastError;
  204765. }
  204766. private:
  204767. CriticalSection callbackLock;
  204768. Float64 sampleRate;
  204769. int numInputChannels, numOutputChannels;
  204770. int preferredBufferSize;
  204771. int actualBufferSize;
  204772. bool isRunning;
  204773. String lastError;
  204774. AudioStreamBasicDescription format;
  204775. AudioUnit audioUnit;
  204776. UInt32 audioInputIsAvailable;
  204777. AudioIODeviceCallback* callback;
  204778. BitArray activeOutputChans, activeInputChans;
  204779. AudioSampleBuffer floatData;
  204780. float* inputChannels[3];
  204781. float* outputChannels[3];
  204782. bool monoInputChannelNumber, monoOutputChannelNumber;
  204783. void prepareFloatBuffers()
  204784. {
  204785. floatData.setSize (numInputChannels + numOutputChannels, actualBufferSize);
  204786. zerostruct (inputChannels);
  204787. zerostruct (outputChannels);
  204788. for (int i = 0; i < numInputChannels; ++i)
  204789. inputChannels[i] = floatData.getSampleData (i);
  204790. for (int i = 0; i < numOutputChannels; ++i)
  204791. outputChannels[i] = floatData.getSampleData (i + numInputChannels);
  204792. }
  204793. OSStatus process (AudioUnitRenderActionFlags* ioActionFlags, const AudioTimeStamp* inTimeStamp,
  204794. UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList* ioData)
  204795. {
  204796. OSStatus err = noErr;
  204797. if (audioInputIsAvailable)
  204798. err = AudioUnitRender (audioUnit, ioActionFlags, inTimeStamp, 1, inNumberFrames, ioData);
  204799. const ScopedLock sl (callbackLock);
  204800. if (callback != 0)
  204801. {
  204802. if (audioInputIsAvailable && numInputChannels > 0)
  204803. {
  204804. short* shortData = (short*) ioData->mBuffers[0].mData;
  204805. if (numInputChannels >= 2)
  204806. {
  204807. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204808. {
  204809. inputChannels[0][i] = *shortData++ * (1.0f / 32768.0f);
  204810. inputChannels[1][i] = *shortData++ * (1.0f / 32768.0f);
  204811. }
  204812. }
  204813. else
  204814. {
  204815. if (monoInputChannelNumber > 0)
  204816. ++shortData;
  204817. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204818. {
  204819. inputChannels[0][i] = *shortData++ * (1.0f / 32768.0f);
  204820. ++shortData;
  204821. }
  204822. }
  204823. }
  204824. else
  204825. {
  204826. for (int i = numInputChannels; --i >= 0;)
  204827. zeromem (inputChannels[i], sizeof (float) * inNumberFrames);
  204828. }
  204829. callback->audioDeviceIOCallback ((const float**) inputChannels, numInputChannels,
  204830. outputChannels, numOutputChannels,
  204831. (int) inNumberFrames);
  204832. short* shortData = (short*) ioData->mBuffers[0].mData;
  204833. int n = 0;
  204834. if (numOutputChannels >= 2)
  204835. {
  204836. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204837. {
  204838. shortData [n++] = (short) (outputChannels[0][i] * 32767.0f);
  204839. shortData [n++] = (short) (outputChannels[1][i] * 32767.0f);
  204840. }
  204841. }
  204842. else if (numOutputChannels == 1)
  204843. {
  204844. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204845. {
  204846. const short s = (short) (outputChannels[monoOutputChannelNumber][i] * 32767.0f);
  204847. shortData [n++] = s;
  204848. shortData [n++] = s;
  204849. }
  204850. }
  204851. else
  204852. {
  204853. zeromem (ioData->mBuffers[0].mData, 2 * sizeof (short) * inNumberFrames);
  204854. }
  204855. }
  204856. else
  204857. {
  204858. zeromem (ioData->mBuffers[0].mData, 2 * sizeof (short) * inNumberFrames);
  204859. }
  204860. return err;
  204861. }
  204862. void updateDeviceInfo()
  204863. {
  204864. UInt32 size = sizeof (sampleRate);
  204865. AudioSessionGetProperty (kAudioSessionProperty_CurrentHardwareSampleRate, &size, &sampleRate);
  204866. size = sizeof (audioInputIsAvailable);
  204867. AudioSessionGetProperty (kAudioSessionProperty_AudioInputAvailable, &size, &audioInputIsAvailable);
  204868. }
  204869. void propertyChanged (AudioSessionPropertyID inID, UInt32 inDataSize, const void* inPropertyValue)
  204870. {
  204871. if (! isRunning)
  204872. return;
  204873. if (inPropertyValue != 0)
  204874. {
  204875. CFDictionaryRef routeChangeDictionary = (CFDictionaryRef) inPropertyValue;
  204876. CFNumberRef routeChangeReasonRef = (CFNumberRef) CFDictionaryGetValue (routeChangeDictionary,
  204877. CFSTR (kAudioSession_AudioRouteChangeKey_Reason));
  204878. SInt32 routeChangeReason;
  204879. CFNumberGetValue (routeChangeReasonRef, kCFNumberSInt32Type, &routeChangeReason);
  204880. if (routeChangeReason == kAudioSessionRouteChangeReason_OldDeviceUnavailable)
  204881. fixAudioRouteIfSetToReceiver();
  204882. }
  204883. updateDeviceInfo();
  204884. createAudioUnit();
  204885. AudioSessionSetActive (true);
  204886. if (audioUnit != 0)
  204887. {
  204888. UInt32 formatSize = sizeof (format);
  204889. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &format, &formatSize);
  204890. Float32 bufferDuration = preferredBufferSize / sampleRate;
  204891. UInt32 bufferDurationSize = sizeof (bufferDuration);
  204892. AudioSessionGetProperty (kAudioSessionProperty_CurrentHardwareIOBufferDuration, &bufferDurationSize, &bufferDurationSize);
  204893. actualBufferSize = (int) (sampleRate * bufferDuration + 0.5);
  204894. AudioOutputUnitStart (audioUnit);
  204895. }
  204896. }
  204897. void interruptionListener (UInt32 inInterruption)
  204898. {
  204899. if (inInterruption == kAudioSessionEndInterruption)
  204900. {
  204901. isRunning = true;
  204902. AudioSessionSetActive (true);
  204903. AudioOutputUnitStart (audioUnit);
  204904. }
  204905. }
  204906. static OSStatus processStatic (void* inRefCon, AudioUnitRenderActionFlags* ioActionFlags, const AudioTimeStamp* inTimeStamp,
  204907. UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList* ioData)
  204908. {
  204909. return ((IPhoneAudioIODevice*) inRefCon)->process (ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, ioData);
  204910. }
  204911. static void propertyChangedStatic (void* inClientData, AudioSessionPropertyID inID, UInt32 inDataSize, const void* inPropertyValue)
  204912. {
  204913. ((IPhoneAudioIODevice*) inClientData)->propertyChanged (inID, inDataSize, inPropertyValue);
  204914. }
  204915. static void interruptionListenerStatic (void* inClientData, UInt32 inInterruption)
  204916. {
  204917. ((IPhoneAudioIODevice*) inClientData)->interruptionListener (inInterruption);
  204918. }
  204919. void resetFormat (const int numChannels)
  204920. {
  204921. memset (&format, 0, sizeof (format));
  204922. format.mFormatID = kAudioFormatLinearPCM;
  204923. format.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked;
  204924. format.mBitsPerChannel = 8 * sizeof (short);
  204925. format.mChannelsPerFrame = 2;
  204926. format.mFramesPerPacket = 1;
  204927. format.mBytesPerFrame = format.mBytesPerPacket = 2 * sizeof (short);
  204928. }
  204929. bool createAudioUnit()
  204930. {
  204931. if (audioUnit != 0)
  204932. {
  204933. AudioComponentInstanceDispose (audioUnit);
  204934. audioUnit = 0;
  204935. }
  204936. resetFormat (2);
  204937. AudioComponentDescription desc;
  204938. desc.componentType = kAudioUnitType_Output;
  204939. desc.componentSubType = kAudioUnitSubType_RemoteIO;
  204940. desc.componentManufacturer = kAudioUnitManufacturer_Apple;
  204941. desc.componentFlags = 0;
  204942. desc.componentFlagsMask = 0;
  204943. AudioComponent comp = AudioComponentFindNext (0, &desc);
  204944. AudioComponentInstanceNew (comp, &audioUnit);
  204945. if (audioUnit == 0)
  204946. return false;
  204947. const UInt32 one = 1;
  204948. AudioUnitSetProperty (audioUnit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input, 1, &one, sizeof (one));
  204949. AudioChannelLayout layout;
  204950. layout.mChannelBitmap = 0;
  204951. layout.mNumberChannelDescriptions = 0;
  204952. layout.mChannelLayoutTag = kAudioChannelLayoutTag_Stereo;
  204953. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_AudioChannelLayout, kAudioUnitScope_Input, 0, &layout, sizeof (layout));
  204954. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_AudioChannelLayout, kAudioUnitScope_Output, 0, &layout, sizeof (layout));
  204955. AURenderCallbackStruct inputProc;
  204956. inputProc.inputProc = processStatic;
  204957. inputProc.inputProcRefCon = this;
  204958. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, 0, &inputProc, sizeof (inputProc));
  204959. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &format, sizeof (format));
  204960. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &format, sizeof (format));
  204961. AudioUnitInitialize (audioUnit);
  204962. return true;
  204963. }
  204964. // If the routing is set to go through the receiver (i.e. the speaker, but quiet), this re-routes it
  204965. // to make it loud. Needed because by default when using an input + output, the output is kept quiet.
  204966. static void fixAudioRouteIfSetToReceiver()
  204967. {
  204968. CFStringRef audioRoute = 0;
  204969. UInt32 propertySize = sizeof (audioRoute);
  204970. if (AudioSessionGetProperty (kAudioSessionProperty_AudioRoute, &propertySize, &audioRoute) == noErr)
  204971. {
  204972. NSString* route = (NSString*) audioRoute;
  204973. //DBG ("audio route: " + nsStringToJuce (route));
  204974. if ([route hasPrefix: @"Receiver"])
  204975. {
  204976. UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
  204977. AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute, sizeof (audioRouteOverride), &audioRouteOverride);
  204978. }
  204979. CFRelease (audioRoute);
  204980. }
  204981. }
  204982. IPhoneAudioIODevice (const IPhoneAudioIODevice&);
  204983. const IPhoneAudioIODevice& operator= (const IPhoneAudioIODevice&);
  204984. };
  204985. class IPhoneAudioIODeviceType : public AudioIODeviceType
  204986. {
  204987. public:
  204988. IPhoneAudioIODeviceType()
  204989. : AudioIODeviceType (T("iPhone Audio"))
  204990. {
  204991. }
  204992. ~IPhoneAudioIODeviceType()
  204993. {
  204994. }
  204995. void scanForDevices()
  204996. {
  204997. }
  204998. const StringArray getDeviceNames (const bool wantInputNames) const
  204999. {
  205000. StringArray s;
  205001. s.add ("iPhone Audio");
  205002. return s;
  205003. }
  205004. int getDefaultDeviceIndex (const bool forInput) const
  205005. {
  205006. return 0;
  205007. }
  205008. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  205009. {
  205010. return device != 0 ? 0 : -1;
  205011. }
  205012. bool hasSeparateInputsAndOutputs() const { return false; }
  205013. AudioIODevice* createDevice (const String& outputDeviceName,
  205014. const String& inputDeviceName)
  205015. {
  205016. if (outputDeviceName.isNotEmpty() || inputDeviceName.isNotEmpty())
  205017. {
  205018. return new IPhoneAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  205019. : inputDeviceName);
  205020. }
  205021. return 0;
  205022. }
  205023. juce_UseDebuggingNewOperator
  205024. private:
  205025. IPhoneAudioIODeviceType (const IPhoneAudioIODeviceType&);
  205026. const IPhoneAudioIODeviceType& operator= (const IPhoneAudioIODeviceType&);
  205027. };
  205028. AudioIODeviceType* juce_createAudioIODeviceType_iPhoneAudio()
  205029. {
  205030. return new IPhoneAudioIODeviceType();
  205031. }
  205032. #endif
  205033. /*** End of inlined file: juce_iphone_Audio.cpp ***/
  205034. /*** Start of inlined file: juce_mac_CoreMidi.cpp ***/
  205035. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  205036. // compiled on its own).
  205037. #if JUCE_INCLUDED_FILE
  205038. #if JUCE_MAC
  205039. #undef log
  205040. #define log(a) Logger::writeToLog(a)
  205041. static bool logAnyErrorsMidi (const OSStatus err, const int lineNum)
  205042. {
  205043. if (err == noErr)
  205044. return true;
  205045. log (T("CoreMidi error: ") + String (lineNum) + T(" - ") + String::toHexString ((int)err));
  205046. jassertfalse
  205047. return false;
  205048. }
  205049. #undef OK
  205050. #define OK(a) logAnyErrorsMidi(a, __LINE__)
  205051. static const String getEndpointName (MIDIEndpointRef endpoint, bool isExternal)
  205052. {
  205053. String result;
  205054. CFStringRef str = 0;
  205055. MIDIObjectGetStringProperty (endpoint, kMIDIPropertyName, &str);
  205056. if (str != 0)
  205057. {
  205058. result = PlatformUtilities::cfStringToJuceString (str);
  205059. CFRelease (str);
  205060. str = 0;
  205061. }
  205062. MIDIEntityRef entity = 0;
  205063. MIDIEndpointGetEntity (endpoint, &entity);
  205064. if (entity == 0)
  205065. return result; // probably virtual
  205066. if (result.isEmpty())
  205067. {
  205068. // endpoint name has zero length - try the entity
  205069. MIDIObjectGetStringProperty (entity, kMIDIPropertyName, &str);
  205070. if (str != 0)
  205071. {
  205072. result += PlatformUtilities::cfStringToJuceString (str);
  205073. CFRelease (str);
  205074. str = 0;
  205075. }
  205076. }
  205077. // now consider the device's name
  205078. MIDIDeviceRef device = 0;
  205079. MIDIEntityGetDevice (entity, &device);
  205080. if (device == 0)
  205081. return result;
  205082. MIDIObjectGetStringProperty (device, kMIDIPropertyName, &str);
  205083. if (str != 0)
  205084. {
  205085. const String s (PlatformUtilities::cfStringToJuceString (str));
  205086. CFRelease (str);
  205087. // if an external device has only one entity, throw away
  205088. // the endpoint name and just use the device name
  205089. if (isExternal && MIDIDeviceGetNumberOfEntities (device) < 2)
  205090. {
  205091. result = s;
  205092. }
  205093. else if (! result.startsWithIgnoreCase (s))
  205094. {
  205095. // prepend the device name to the entity name
  205096. result = (s + T(" ") + result).trimEnd();
  205097. }
  205098. }
  205099. return result;
  205100. }
  205101. static const String getConnectedEndpointName (MIDIEndpointRef endpoint)
  205102. {
  205103. String result;
  205104. // Does the endpoint have connections?
  205105. CFDataRef connections = 0;
  205106. int numConnections = 0;
  205107. MIDIObjectGetDataProperty (endpoint, kMIDIPropertyConnectionUniqueID, &connections);
  205108. if (connections != 0)
  205109. {
  205110. numConnections = (int) (CFDataGetLength (connections) / sizeof (MIDIUniqueID));
  205111. if (numConnections > 0)
  205112. {
  205113. const SInt32* pid = reinterpret_cast <const SInt32*> (CFDataGetBytePtr (connections));
  205114. for (int i = 0; i < numConnections; ++i, ++pid)
  205115. {
  205116. MIDIUniqueID uid = EndianS32_BtoN (*pid);
  205117. MIDIObjectRef connObject;
  205118. MIDIObjectType connObjectType;
  205119. OSStatus err = MIDIObjectFindByUniqueID (uid, &connObject, &connObjectType);
  205120. if (err == noErr)
  205121. {
  205122. String s;
  205123. if (connObjectType == kMIDIObjectType_ExternalSource
  205124. || connObjectType == kMIDIObjectType_ExternalDestination)
  205125. {
  205126. // Connected to an external device's endpoint (10.3 and later).
  205127. s = getEndpointName (static_cast <MIDIEndpointRef> (connObject), true);
  205128. }
  205129. else
  205130. {
  205131. // Connected to an external device (10.2) (or something else, catch-all)
  205132. CFStringRef str = 0;
  205133. MIDIObjectGetStringProperty (connObject, kMIDIPropertyName, &str);
  205134. if (str != 0)
  205135. {
  205136. s = PlatformUtilities::cfStringToJuceString (str);
  205137. CFRelease (str);
  205138. }
  205139. }
  205140. if (s.isNotEmpty())
  205141. {
  205142. if (result.isNotEmpty())
  205143. result += (", ");
  205144. result += s;
  205145. }
  205146. }
  205147. }
  205148. }
  205149. CFRelease (connections);
  205150. }
  205151. if (result.isNotEmpty())
  205152. return result;
  205153. // Here, either the endpoint had no connections, or we failed to obtain names for any of them.
  205154. return getEndpointName (endpoint, false);
  205155. }
  205156. const StringArray MidiOutput::getDevices()
  205157. {
  205158. StringArray s;
  205159. const ItemCount num = MIDIGetNumberOfDestinations();
  205160. for (ItemCount i = 0; i < num; ++i)
  205161. {
  205162. MIDIEndpointRef dest = MIDIGetDestination (i);
  205163. if (dest != 0)
  205164. {
  205165. String name (getConnectedEndpointName (dest));
  205166. if (name.isEmpty())
  205167. name = "<error>";
  205168. s.add (name);
  205169. }
  205170. else
  205171. {
  205172. s.add ("<error>");
  205173. }
  205174. }
  205175. return s;
  205176. }
  205177. int MidiOutput::getDefaultDeviceIndex()
  205178. {
  205179. return 0;
  205180. }
  205181. static MIDIClientRef globalMidiClient;
  205182. static bool hasGlobalClientBeenCreated = false;
  205183. static bool makeSureClientExists()
  205184. {
  205185. if (! hasGlobalClientBeenCreated)
  205186. {
  205187. String name (T("JUCE"));
  205188. if (JUCEApplication::getInstance() != 0)
  205189. name = JUCEApplication::getInstance()->getApplicationName();
  205190. CFStringRef appName = PlatformUtilities::juceStringToCFString (name);
  205191. hasGlobalClientBeenCreated = OK (MIDIClientCreate (appName, 0, 0, &globalMidiClient));
  205192. CFRelease (appName);
  205193. }
  205194. return hasGlobalClientBeenCreated;
  205195. }
  205196. class MidiPortAndEndpoint
  205197. {
  205198. public:
  205199. MidiPortAndEndpoint (MIDIPortRef port_, MIDIEndpointRef endPoint_)
  205200. : port (port_), endPoint (endPoint_)
  205201. {
  205202. }
  205203. ~MidiPortAndEndpoint()
  205204. {
  205205. if (port != 0)
  205206. MIDIPortDispose (port);
  205207. if (port == 0 && endPoint != 0) // if port == 0, it means we created the endpoint, so it's safe to delete it
  205208. MIDIEndpointDispose (endPoint);
  205209. }
  205210. MIDIPortRef port;
  205211. MIDIEndpointRef endPoint;
  205212. };
  205213. MidiOutput* MidiOutput::openDevice (int index)
  205214. {
  205215. MidiOutput* mo = 0;
  205216. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfDestinations())
  205217. {
  205218. MIDIEndpointRef endPoint = MIDIGetDestination (index);
  205219. CFStringRef pname;
  205220. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  205221. {
  205222. log (T("CoreMidi - opening out: ") + PlatformUtilities::cfStringToJuceString (pname));
  205223. if (makeSureClientExists())
  205224. {
  205225. MIDIPortRef port;
  205226. if (OK (MIDIOutputPortCreate (globalMidiClient, pname, &port)))
  205227. {
  205228. mo = new MidiOutput();
  205229. mo->internal = (void*) new MidiPortAndEndpoint (port, endPoint);
  205230. }
  205231. }
  205232. CFRelease (pname);
  205233. }
  205234. }
  205235. return mo;
  205236. }
  205237. MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
  205238. {
  205239. MidiOutput* mo = 0;
  205240. if (makeSureClientExists())
  205241. {
  205242. MIDIEndpointRef endPoint;
  205243. CFStringRef name = PlatformUtilities::juceStringToCFString (deviceName);
  205244. if (OK (MIDISourceCreate (globalMidiClient, name, &endPoint)))
  205245. {
  205246. mo = new MidiOutput();
  205247. mo->internal = (void*) new MidiPortAndEndpoint (0, endPoint);
  205248. }
  205249. CFRelease (name);
  205250. }
  205251. return mo;
  205252. }
  205253. MidiOutput::~MidiOutput()
  205254. {
  205255. delete (MidiPortAndEndpoint*) internal;
  205256. }
  205257. void MidiOutput::reset()
  205258. {
  205259. }
  205260. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  205261. {
  205262. return false;
  205263. }
  205264. void MidiOutput::setVolume (float leftVol, float rightVol)
  205265. {
  205266. }
  205267. void MidiOutput::sendMessageNow (const MidiMessage& message)
  205268. {
  205269. MidiPortAndEndpoint* const mpe = (MidiPortAndEndpoint*) internal;
  205270. if (message.isSysEx())
  205271. {
  205272. const int maxPacketSize = 256;
  205273. int pos = 0, bytesLeft = message.getRawDataSize();
  205274. const int numPackets = (bytesLeft + maxPacketSize - 1) / maxPacketSize;
  205275. HeapBlock <MIDIPacketList> packets;
  205276. packets.malloc (32 * numPackets + message.getRawDataSize(), 1);
  205277. packets->numPackets = numPackets;
  205278. MIDIPacket* p = packets->packet;
  205279. for (int i = 0; i < numPackets; ++i)
  205280. {
  205281. p->timeStamp = 0;
  205282. p->length = jmin (maxPacketSize, bytesLeft);
  205283. memcpy (p->data, message.getRawData() + pos, p->length);
  205284. pos += p->length;
  205285. bytesLeft -= p->length;
  205286. p = MIDIPacketNext (p);
  205287. }
  205288. if (mpe->port != 0)
  205289. MIDISend (mpe->port, mpe->endPoint, packets);
  205290. else
  205291. MIDIReceived (mpe->endPoint, packets);
  205292. }
  205293. else
  205294. {
  205295. MIDIPacketList packets;
  205296. packets.numPackets = 1;
  205297. packets.packet[0].timeStamp = 0;
  205298. packets.packet[0].length = message.getRawDataSize();
  205299. *(int*) (packets.packet[0].data) = *(const int*) message.getRawData();
  205300. if (mpe->port != 0)
  205301. MIDISend (mpe->port, mpe->endPoint, &packets);
  205302. else
  205303. MIDIReceived (mpe->endPoint, &packets);
  205304. }
  205305. }
  205306. const StringArray MidiInput::getDevices()
  205307. {
  205308. StringArray s;
  205309. const ItemCount num = MIDIGetNumberOfSources();
  205310. for (ItemCount i = 0; i < num; ++i)
  205311. {
  205312. MIDIEndpointRef source = MIDIGetSource (i);
  205313. if (source != 0)
  205314. {
  205315. String name (getConnectedEndpointName (source));
  205316. if (name.isEmpty())
  205317. name = "<error>";
  205318. s.add (name);
  205319. }
  205320. else
  205321. {
  205322. s.add ("<error>");
  205323. }
  205324. }
  205325. return s;
  205326. }
  205327. int MidiInput::getDefaultDeviceIndex()
  205328. {
  205329. return 0;
  205330. }
  205331. struct MidiPortAndCallback
  205332. {
  205333. MidiInput* input;
  205334. MidiPortAndEndpoint* portAndEndpoint;
  205335. MidiInputCallback* callback;
  205336. MemoryBlock pendingData;
  205337. int pendingBytes;
  205338. double pendingDataTime;
  205339. bool active;
  205340. };
  205341. static CriticalSection callbackLock;
  205342. static VoidArray activeCallbacks;
  205343. static void processSysex (MidiPortAndCallback* const mpc, const uint8*& d, int& size, const double time)
  205344. {
  205345. if (*d == 0xf0)
  205346. {
  205347. mpc->pendingBytes = 0;
  205348. mpc->pendingDataTime = time;
  205349. }
  205350. mpc->pendingData.ensureSize (mpc->pendingBytes + size, false);
  205351. uint8* totalMessage = (uint8*) mpc->pendingData.getData();
  205352. uint8* dest = totalMessage + mpc->pendingBytes;
  205353. while (size > 0)
  205354. {
  205355. if (mpc->pendingBytes > 0 && *d >= 0x80)
  205356. {
  205357. if (*d >= 0xfa || *d == 0xf8)
  205358. {
  205359. mpc->callback->handleIncomingMidiMessage (mpc->input, MidiMessage (*d, time));
  205360. ++d;
  205361. --size;
  205362. }
  205363. else
  205364. {
  205365. if (*d == 0xf7)
  205366. {
  205367. *dest++ = *d++;
  205368. mpc->pendingBytes++;
  205369. --size;
  205370. }
  205371. break;
  205372. }
  205373. }
  205374. else
  205375. {
  205376. *dest++ = *d++;
  205377. mpc->pendingBytes++;
  205378. --size;
  205379. }
  205380. }
  205381. if (totalMessage [mpc->pendingBytes - 1] == 0xf7)
  205382. {
  205383. mpc->callback->handleIncomingMidiMessage (mpc->input, MidiMessage (totalMessage,
  205384. mpc->pendingBytes,
  205385. mpc->pendingDataTime));
  205386. mpc->pendingBytes = 0;
  205387. }
  205388. else
  205389. {
  205390. mpc->callback->handlePartialSysexMessage (mpc->input,
  205391. totalMessage,
  205392. mpc->pendingBytes,
  205393. mpc->pendingDataTime);
  205394. }
  205395. }
  205396. static void midiInputProc (const MIDIPacketList* pktlist,
  205397. void* readProcRefCon,
  205398. void* srcConnRefCon)
  205399. {
  205400. double time = Time::getMillisecondCounterHiRes() * 0.001;
  205401. const double originalTime = time;
  205402. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) readProcRefCon;
  205403. const ScopedLock sl (callbackLock);
  205404. if (activeCallbacks.contains (mpc) && mpc->active)
  205405. {
  205406. const MIDIPacket* packet = &pktlist->packet[0];
  205407. for (unsigned int i = 0; i < pktlist->numPackets; ++i)
  205408. {
  205409. const uint8* d = (const uint8*) (packet->data);
  205410. int size = packet->length;
  205411. while (size > 0)
  205412. {
  205413. time = originalTime;
  205414. if (mpc->pendingBytes > 0 || d[0] == 0xf0)
  205415. {
  205416. processSysex (mpc, d, size, time);
  205417. }
  205418. else
  205419. {
  205420. int used = 0;
  205421. const MidiMessage m (d, size, used, 0, time);
  205422. if (used <= 0)
  205423. {
  205424. jassertfalse // malformed midi message
  205425. break;
  205426. }
  205427. else
  205428. {
  205429. mpc->callback->handleIncomingMidiMessage (mpc->input, m);
  205430. }
  205431. size -= used;
  205432. d += used;
  205433. }
  205434. }
  205435. packet = MIDIPacketNext (packet);
  205436. }
  205437. }
  205438. }
  205439. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  205440. {
  205441. MidiInput* mi = 0;
  205442. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfSources())
  205443. {
  205444. MIDIEndpointRef endPoint = MIDIGetSource (index);
  205445. if (endPoint != 0)
  205446. {
  205447. CFStringRef pname;
  205448. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  205449. {
  205450. log (T("CoreMidi - opening inp: ") + PlatformUtilities::cfStringToJuceString (pname));
  205451. if (makeSureClientExists())
  205452. {
  205453. MIDIPortRef port;
  205454. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  205455. mpc->active = false;
  205456. if (OK (MIDIInputPortCreate (globalMidiClient, pname, midiInputProc, mpc, &port)))
  205457. {
  205458. if (OK (MIDIPortConnectSource (port, endPoint, 0)))
  205459. {
  205460. mpc->portAndEndpoint = new MidiPortAndEndpoint (port, endPoint);
  205461. mpc->callback = callback;
  205462. mpc->pendingBytes = 0;
  205463. mpc->pendingData.ensureSize (128);
  205464. mi = new MidiInput (getDevices() [index]);
  205465. mpc->input = mi;
  205466. mi->internal = (void*) mpc;
  205467. const ScopedLock sl (callbackLock);
  205468. activeCallbacks.add (mpc.release());
  205469. }
  205470. else
  205471. {
  205472. OK (MIDIPortDispose (port));
  205473. }
  205474. }
  205475. }
  205476. }
  205477. CFRelease (pname);
  205478. }
  205479. }
  205480. return mi;
  205481. }
  205482. MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
  205483. {
  205484. MidiInput* mi = 0;
  205485. if (makeSureClientExists())
  205486. {
  205487. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  205488. mpc->active = false;
  205489. MIDIEndpointRef endPoint;
  205490. CFStringRef name = PlatformUtilities::juceStringToCFString(deviceName);
  205491. if (OK (MIDIDestinationCreate (globalMidiClient, name, midiInputProc, mpc, &endPoint)))
  205492. {
  205493. mpc->portAndEndpoint = new MidiPortAndEndpoint (0, endPoint);
  205494. mpc->callback = callback;
  205495. mpc->pendingBytes = 0;
  205496. mpc->pendingData.ensureSize (128);
  205497. mi = new MidiInput (deviceName);
  205498. mpc->input = mi;
  205499. mi->internal = (void*) mpc;
  205500. const ScopedLock sl (callbackLock);
  205501. activeCallbacks.add (mpc.release());
  205502. }
  205503. CFRelease (name);
  205504. }
  205505. return mi;
  205506. }
  205507. MidiInput::MidiInput (const String& name_)
  205508. : name (name_)
  205509. {
  205510. }
  205511. MidiInput::~MidiInput()
  205512. {
  205513. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  205514. mpc->active = false;
  205515. callbackLock.enter();
  205516. activeCallbacks.removeValue (mpc);
  205517. callbackLock.exit();
  205518. if (mpc->portAndEndpoint->port != 0)
  205519. OK (MIDIPortDisconnectSource (mpc->portAndEndpoint->port, mpc->portAndEndpoint->endPoint));
  205520. delete mpc->portAndEndpoint;
  205521. delete mpc;
  205522. }
  205523. void MidiInput::start()
  205524. {
  205525. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  205526. const ScopedLock sl (callbackLock);
  205527. mpc->active = true;
  205528. }
  205529. void MidiInput::stop()
  205530. {
  205531. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  205532. const ScopedLock sl (callbackLock);
  205533. mpc->active = false;
  205534. }
  205535. #undef log
  205536. #else
  205537. MidiOutput::~MidiOutput()
  205538. {
  205539. }
  205540. void MidiOutput::reset()
  205541. {
  205542. }
  205543. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  205544. {
  205545. return false;
  205546. }
  205547. void MidiOutput::setVolume (float leftVol, float rightVol)
  205548. {
  205549. }
  205550. void MidiOutput::sendMessageNow (const MidiMessage& message)
  205551. {
  205552. }
  205553. const StringArray MidiOutput::getDevices()
  205554. {
  205555. return StringArray();
  205556. }
  205557. MidiOutput* MidiOutput::openDevice (int index)
  205558. {
  205559. return 0;
  205560. }
  205561. const StringArray MidiInput::getDevices()
  205562. {
  205563. return StringArray();
  205564. }
  205565. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  205566. {
  205567. return 0;
  205568. }
  205569. #endif
  205570. #endif
  205571. /*** End of inlined file: juce_mac_CoreMidi.cpp ***/
  205572. #else
  205573. /*** Start of inlined file: juce_mac_Fonts.mm ***/
  205574. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  205575. // compiled on its own).
  205576. #if JUCE_INCLUDED_FILE
  205577. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  205578. #define SUPPORT_10_4_FONTS 1
  205579. #define NEW_CGFONT_FUNCTIONS_UNAVAILABLE (CGFontCreateWithFontName == 0)
  205580. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  205581. #define SUPPORT_ONLY_10_4_FONTS 1
  205582. #endif
  205583. END_JUCE_NAMESPACE
  205584. @interface NSFont (PrivateHack)
  205585. - (NSGlyph) _defaultGlyphForChar: (unichar) theChar;
  205586. @end
  205587. BEGIN_JUCE_NAMESPACE
  205588. #endif
  205589. class MacTypeface : public Typeface
  205590. {
  205591. public:
  205592. MacTypeface (const Font& font)
  205593. : Typeface (font.getTypefaceName())
  205594. {
  205595. const ScopedAutoReleasePool pool;
  205596. renderingTransform = CGAffineTransformIdentity;
  205597. bool needsItalicTransform = false;
  205598. #if JUCE_IPHONE
  205599. NSString* fontName = juceStringToNS (font.getTypefaceName());
  205600. if (font.isItalic() || font.isBold())
  205601. {
  205602. NSArray* familyFonts = [UIFont fontNamesForFamilyName: juceStringToNS (font.getTypefaceName())];
  205603. for (NSString* i in familyFonts)
  205604. {
  205605. const String fn (nsStringToJuce (i));
  205606. const String afterDash (fn.fromFirstOccurrenceOf (T("-"), false, false));
  205607. const bool probablyBold = afterDash.containsIgnoreCase (T("bold")) || fn.endsWithIgnoreCase (T("bold"));
  205608. const bool probablyItalic = afterDash.containsIgnoreCase (T("oblique"))
  205609. || afterDash.containsIgnoreCase (T("italic"))
  205610. || fn.endsWithIgnoreCase (T("oblique"))
  205611. || fn.endsWithIgnoreCase (T("italic"));
  205612. if (probablyBold == font.isBold()
  205613. && probablyItalic == font.isItalic())
  205614. {
  205615. fontName = i;
  205616. needsItalicTransform = false;
  205617. break;
  205618. }
  205619. else if (probablyBold && (! probablyItalic) && probablyBold == font.isBold())
  205620. {
  205621. fontName = i;
  205622. needsItalicTransform = true; // not ideal, so carry on in case we find a better one
  205623. }
  205624. }
  205625. if (needsItalicTransform)
  205626. renderingTransform.c = 0.15f;
  205627. }
  205628. fontRef = CGFontCreateWithFontName ((CFStringRef) fontName);
  205629. const int ascender = abs (CGFontGetAscent (fontRef));
  205630. const float totalHeight = ascender + abs (CGFontGetDescent (fontRef));
  205631. ascent = ascender / totalHeight;
  205632. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205633. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / totalHeight;
  205634. #else
  205635. nsFont = [NSFont fontWithName: juceStringToNS (font.getTypefaceName()) size: 1024];
  205636. if (font.isItalic())
  205637. {
  205638. NSFont* newFont = [[NSFontManager sharedFontManager] convertFont: nsFont
  205639. toHaveTrait: NSItalicFontMask];
  205640. if (newFont == nsFont)
  205641. needsItalicTransform = true; // couldn't find a proper italic version, so fake it with a transform..
  205642. nsFont = newFont;
  205643. }
  205644. if (font.isBold())
  205645. nsFont = [[NSFontManager sharedFontManager] convertFont: nsFont toHaveTrait: NSBoldFontMask];
  205646. [nsFont retain];
  205647. ascent = fabsf ((float) [nsFont ascender]);
  205648. float totalSize = ascent + fabsf ((float) [nsFont descender]);
  205649. ascent /= totalSize;
  205650. pathTransform = AffineTransform::identity.scale (1.0f / totalSize, 1.0f / totalSize);
  205651. if (needsItalicTransform)
  205652. {
  205653. pathTransform = pathTransform.sheared (-0.15f, 0.0f);
  205654. renderingTransform.c = 0.15f;
  205655. }
  205656. #if SUPPORT_ONLY_10_4_FONTS
  205657. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205658. if (atsFont == 0)
  205659. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205660. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  205661. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  205662. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205663. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  205664. #else
  205665. #if SUPPORT_10_4_FONTS
  205666. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205667. {
  205668. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205669. if (atsFont == 0)
  205670. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205671. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  205672. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  205673. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205674. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  205675. }
  205676. else
  205677. #endif
  205678. {
  205679. fontRef = CGFontCreateWithFontName ((CFStringRef) [nsFont fontName]);
  205680. const int totalHeight = abs (CGFontGetAscent (fontRef)) + abs (CGFontGetDescent (fontRef));
  205681. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205682. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / (float) totalHeight;
  205683. }
  205684. #endif
  205685. #endif
  205686. }
  205687. ~MacTypeface()
  205688. {
  205689. #if ! JUCE_IPHONE
  205690. [nsFont release];
  205691. #endif
  205692. if (fontRef != 0)
  205693. CGFontRelease (fontRef);
  205694. }
  205695. float getAscent() const
  205696. {
  205697. return ascent;
  205698. }
  205699. float getDescent() const
  205700. {
  205701. return 1.0f - ascent;
  205702. }
  205703. float getStringWidth (const String& text)
  205704. {
  205705. if (fontRef == 0 || text.isEmpty())
  205706. return 0;
  205707. const int length = text.length();
  205708. HeapBlock <CGGlyph> glyphs;
  205709. createGlyphsForString (text, length, glyphs);
  205710. float x = 0;
  205711. #if SUPPORT_ONLY_10_4_FONTS
  205712. HeapBlock <NSSize> advances (length);
  205713. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  205714. for (int i = 0; i < length; ++i)
  205715. x += advances[i].width;
  205716. #else
  205717. #if SUPPORT_10_4_FONTS
  205718. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205719. {
  205720. HeapBlock <NSSize> advances (length);
  205721. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  205722. for (int i = 0; i < length; ++i)
  205723. x += advances[i].width;
  205724. }
  205725. else
  205726. #endif
  205727. {
  205728. HeapBlock <int> advances (length);
  205729. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  205730. for (int i = 0; i < length; ++i)
  205731. x += advances[i];
  205732. }
  205733. #endif
  205734. return x * unitsToHeightScaleFactor;
  205735. }
  205736. void getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array <float>& xOffsets)
  205737. {
  205738. xOffsets.add (0);
  205739. if (fontRef == 0 || text.isEmpty())
  205740. return;
  205741. const int length = text.length();
  205742. HeapBlock <CGGlyph> glyphs;
  205743. createGlyphsForString (text, length, glyphs);
  205744. #if SUPPORT_ONLY_10_4_FONTS
  205745. HeapBlock <NSSize> advances (length);
  205746. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  205747. int x = 0;
  205748. for (int i = 0; i < length; ++i)
  205749. {
  205750. x += advances[i].width;
  205751. xOffsets.add (x * unitsToHeightScaleFactor);
  205752. resultGlyphs.add (((NSGlyph*) glyphs)[i]);
  205753. }
  205754. #else
  205755. #if SUPPORT_10_4_FONTS
  205756. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205757. {
  205758. HeapBlock <NSSize> advances (length);
  205759. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  205760. float x = 0;
  205761. for (int i = 0; i < length; ++i)
  205762. {
  205763. x += advances[i].width;
  205764. xOffsets.add (x * unitsToHeightScaleFactor);
  205765. resultGlyphs.add (((NSGlyph*) glyphs)[i]);
  205766. }
  205767. }
  205768. else
  205769. #endif
  205770. {
  205771. HeapBlock <int> advances (length);
  205772. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  205773. {
  205774. int x = 0;
  205775. for (int i = 0; i < length; ++i)
  205776. {
  205777. x += advances [i];
  205778. xOffsets.add (x * unitsToHeightScaleFactor);
  205779. resultGlyphs.add (glyphs[i]);
  205780. }
  205781. }
  205782. }
  205783. #endif
  205784. }
  205785. bool getOutlineForGlyph (int glyphNumber, Path& path)
  205786. {
  205787. #if JUCE_IPHONE
  205788. return false;
  205789. #else
  205790. if (nsFont == 0)
  205791. return false;
  205792. // we might need to apply a transform to the path, so it mustn't have anything else in it
  205793. jassert (path.isEmpty());
  205794. const ScopedAutoReleasePool pool;
  205795. NSBezierPath* bez = [NSBezierPath bezierPath];
  205796. [bez moveToPoint: NSMakePoint (0, 0)];
  205797. [bez appendBezierPathWithGlyph: (NSGlyph) glyphNumber
  205798. inFont: nsFont];
  205799. for (int i = 0; i < [bez elementCount]; ++i)
  205800. {
  205801. NSPoint p[3];
  205802. switch ([bez elementAtIndex: i associatedPoints: p])
  205803. {
  205804. case NSMoveToBezierPathElement:
  205805. path.startNewSubPath ((float) p[0].x, (float) -p[0].y);
  205806. break;
  205807. case NSLineToBezierPathElement:
  205808. path.lineTo ((float) p[0].x, (float) -p[0].y);
  205809. break;
  205810. case NSCurveToBezierPathElement:
  205811. 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);
  205812. break;
  205813. case NSClosePathBezierPathElement:
  205814. path.closeSubPath();
  205815. break;
  205816. default:
  205817. jassertfalse
  205818. break;
  205819. }
  205820. }
  205821. path.applyTransform (pathTransform);
  205822. return true;
  205823. #endif
  205824. }
  205825. juce_UseDebuggingNewOperator
  205826. CGFontRef fontRef;
  205827. float fontHeightToCGSizeFactor;
  205828. CGAffineTransform renderingTransform;
  205829. private:
  205830. float ascent, unitsToHeightScaleFactor;
  205831. #if JUCE_IPHONE
  205832. #else
  205833. NSFont* nsFont;
  205834. AffineTransform pathTransform;
  205835. #endif
  205836. void createGlyphsForString (const juce_wchar* const text, const int length, HeapBlock <CGGlyph>& glyphs)
  205837. {
  205838. #if SUPPORT_10_4_FONTS
  205839. #if ! SUPPORT_ONLY_10_4_FONTS
  205840. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205841. #endif
  205842. {
  205843. glyphs.malloc (sizeof (NSGlyph) * length, 1);
  205844. NSGlyph* const g = (NSGlyph*) glyphs;
  205845. for (int i = 0; i < length; ++i)
  205846. g[i] = (NSGlyph) [nsFont _defaultGlyphForChar: text[i]];
  205847. return;
  205848. }
  205849. #endif
  205850. #if ! SUPPORT_ONLY_10_4_FONTS
  205851. if (charToGlyphMapper == 0)
  205852. charToGlyphMapper = new CharToGlyphMapper (fontRef);
  205853. glyphs.malloc (length);
  205854. for (int i = 0; i < length; ++i)
  205855. glyphs[i] = (CGGlyph) charToGlyphMapper->getGlyphForCharacter (text[i]);
  205856. #endif
  205857. }
  205858. #if ! SUPPORT_ONLY_10_4_FONTS
  205859. // Reads a CGFontRef's character map table to convert unicode into glyph numbers
  205860. class CharToGlyphMapper
  205861. {
  205862. public:
  205863. CharToGlyphMapper (CGFontRef fontRef)
  205864. : segCount (0), endCode (0), startCode (0), idDelta (0),
  205865. idRangeOffset (0), glyphIndexes (0)
  205866. {
  205867. CFDataRef cmapTable = CGFontCopyTableForTag (fontRef, 'cmap');
  205868. if (cmapTable != 0)
  205869. {
  205870. const int numSubtables = getValue16 (cmapTable, 2);
  205871. for (int i = 0; i < numSubtables; ++i)
  205872. {
  205873. if (getValue16 (cmapTable, i * 8 + 4) == 0) // check for platform ID of 0
  205874. {
  205875. const int offset = getValue32 (cmapTable, i * 8 + 8);
  205876. if (getValue16 (cmapTable, offset) == 4) // check that it's format 4..
  205877. {
  205878. const int length = getValue16 (cmapTable, offset + 2);
  205879. const int segCountX2 = getValue16 (cmapTable, offset + 6);
  205880. segCount = segCountX2 / 2;
  205881. const int endCodeOffset = offset + 14;
  205882. const int startCodeOffset = endCodeOffset + 2 + segCountX2;
  205883. const int idDeltaOffset = startCodeOffset + segCountX2;
  205884. const int idRangeOffsetOffset = idDeltaOffset + segCountX2;
  205885. const int glyphIndexesOffset = idRangeOffsetOffset + segCountX2;
  205886. endCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + endCodeOffset, segCountX2);
  205887. startCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + startCodeOffset, segCountX2);
  205888. idDelta = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idDeltaOffset, segCountX2);
  205889. idRangeOffset = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idRangeOffsetOffset, segCountX2);
  205890. glyphIndexes = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + glyphIndexesOffset, offset + length - glyphIndexesOffset);
  205891. }
  205892. break;
  205893. }
  205894. }
  205895. CFRelease (cmapTable);
  205896. }
  205897. }
  205898. ~CharToGlyphMapper()
  205899. {
  205900. if (endCode != 0)
  205901. {
  205902. CFRelease (endCode);
  205903. CFRelease (startCode);
  205904. CFRelease (idDelta);
  205905. CFRelease (idRangeOffset);
  205906. CFRelease (glyphIndexes);
  205907. }
  205908. }
  205909. int getGlyphForCharacter (const juce_wchar c) const
  205910. {
  205911. for (int i = 0; i < segCount; ++i)
  205912. {
  205913. if (getValue16 (endCode, i * 2) >= c)
  205914. {
  205915. const int start = getValue16 (startCode, i * 2);
  205916. if (start > c)
  205917. break;
  205918. const int delta = getValue16 (idDelta, i * 2);
  205919. const int rangeOffset = getValue16 (idRangeOffset, i * 2);
  205920. if (rangeOffset == 0)
  205921. return delta + c;
  205922. else
  205923. return getValue16 (glyphIndexes, 2 * ((rangeOffset / 2) + (c - start) - (segCount - i)));
  205924. }
  205925. }
  205926. // If we failed to find it "properly", this dodgy fall-back seems to do the trick for most fonts!
  205927. return jmax (-1, c - 29);
  205928. }
  205929. private:
  205930. int segCount;
  205931. CFDataRef endCode, startCode, idDelta, idRangeOffset, glyphIndexes;
  205932. static uint16 getValue16 (CFDataRef data, const int index)
  205933. {
  205934. return CFSwapInt16BigToHost (*(UInt16*) (CFDataGetBytePtr (data) + index));
  205935. }
  205936. static uint32 getValue32 (CFDataRef data, const int index)
  205937. {
  205938. return CFSwapInt32BigToHost (*(UInt32*) (CFDataGetBytePtr (data) + index));
  205939. }
  205940. };
  205941. ScopedPointer <CharToGlyphMapper> charToGlyphMapper;
  205942. #endif
  205943. };
  205944. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  205945. {
  205946. return new MacTypeface (font);
  205947. }
  205948. const StringArray Font::findAllTypefaceNames() throw()
  205949. {
  205950. StringArray names;
  205951. const ScopedAutoReleasePool pool;
  205952. #if JUCE_IPHONE
  205953. NSArray* fonts = [UIFont familyNames];
  205954. #else
  205955. NSArray* fonts = [[NSFontManager sharedFontManager] availableFontFamilies];
  205956. #endif
  205957. for (unsigned int i = 0; i < [fonts count]; ++i)
  205958. names.add (nsStringToJuce ((NSString*) [fonts objectAtIndex: i]));
  205959. names.sort (true);
  205960. return names;
  205961. }
  205962. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw()
  205963. {
  205964. #if JUCE_IPHONE
  205965. defaultSans = "Helvetica";
  205966. defaultSerif = "Times New Roman";
  205967. defaultFixed = "Courier New";
  205968. #else
  205969. defaultSans = "Lucida Grande";
  205970. defaultSerif = "Times New Roman";
  205971. defaultFixed = "Monaco";
  205972. #endif
  205973. }
  205974. #endif
  205975. /*** End of inlined file: juce_mac_Fonts.mm ***/
  205976. // (must go before juce_mac_CoreGraphicsContext.mm)
  205977. /*** Start of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  205978. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  205979. // compiled on its own).
  205980. #if JUCE_INCLUDED_FILE
  205981. class CoreGraphicsImage : public Image
  205982. {
  205983. public:
  205984. CoreGraphicsImage (const PixelFormat format_,
  205985. const int imageWidth_,
  205986. const int imageHeight_,
  205987. const bool clearImage)
  205988. : Image (format_, imageWidth_, imageHeight_, clearImage)
  205989. {
  205990. CGColorSpaceRef colourSpace = format == Image::SingleChannel ? CGColorSpaceCreateDeviceGray()
  205991. : CGColorSpaceCreateDeviceRGB();
  205992. context = CGBitmapContextCreate (imageData, imageWidth, imageHeight, 8, lineStride,
  205993. colourSpace, getCGImageFlags (*this));
  205994. CGColorSpaceRelease (colourSpace);
  205995. }
  205996. ~CoreGraphicsImage()
  205997. {
  205998. CGContextRelease (context);
  205999. }
  206000. LowLevelGraphicsContext* createLowLevelContext();
  206001. static CGImageRef createImage (const Image& juceImage, const bool forAlpha, CGColorSpaceRef colourSpace)
  206002. {
  206003. const CoreGraphicsImage* nativeImage = dynamic_cast <const CoreGraphicsImage*> (&juceImage);
  206004. if (nativeImage != 0 && (juceImage.getFormat() == Image::SingleChannel || ! forAlpha))
  206005. {
  206006. return CGBitmapContextCreateImage (nativeImage->context);
  206007. }
  206008. else
  206009. {
  206010. const Image::BitmapData srcData (juceImage, 0, 0, juceImage.getWidth(), juceImage.getHeight());
  206011. CGDataProviderRef provider = CGDataProviderCreateWithData (0, srcData.data, srcData.lineStride * srcData.height, 0);
  206012. CGImageRef imageRef = CGImageCreate (srcData.width, srcData.height,
  206013. 8, srcData.pixelStride * 8, srcData.lineStride,
  206014. colourSpace, getCGImageFlags (juceImage), provider,
  206015. 0, true, kCGRenderingIntentDefault);
  206016. CGDataProviderRelease (provider);
  206017. return imageRef;
  206018. }
  206019. }
  206020. #if JUCE_MAC
  206021. static NSImage* createNSImage (const Image& image)
  206022. {
  206023. const ScopedAutoReleasePool pool;
  206024. NSImage* im = [[NSImage alloc] init];
  206025. [im setSize: NSMakeSize (image.getWidth(), image.getHeight())];
  206026. [im lockFocus];
  206027. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  206028. CGImageRef imageRef = createImage (image, false, colourSpace);
  206029. CGColorSpaceRelease (colourSpace);
  206030. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  206031. CGContextDrawImage (cg, CGRectMake (0, 0, image.getWidth(), image.getHeight()), imageRef);
  206032. CGImageRelease (imageRef);
  206033. [im unlockFocus];
  206034. return im;
  206035. }
  206036. #endif
  206037. CGContextRef context;
  206038. private:
  206039. static CGBitmapInfo getCGImageFlags (const Image& image)
  206040. {
  206041. #if JUCE_BIG_ENDIAN
  206042. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Big) : kCGBitmapByteOrderDefault;
  206043. #else
  206044. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little) : kCGBitmapByteOrderDefault;
  206045. #endif
  206046. }
  206047. };
  206048. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  206049. {
  206050. #if USE_COREGRAPHICS_RENDERING
  206051. return new CoreGraphicsImage (format == RGB ? ARGB : format, imageWidth, imageHeight, clearImage);
  206052. #else
  206053. return new Image (format, imageWidth, imageHeight, clearImage);
  206054. #endif
  206055. }
  206056. class CoreGraphicsContext : public LowLevelGraphicsContext
  206057. {
  206058. public:
  206059. CoreGraphicsContext (CGContextRef context_, const float flipHeight_)
  206060. : context (context_),
  206061. flipHeight (flipHeight_),
  206062. numGradientLookupEntries (0)
  206063. {
  206064. CGContextRetain (context);
  206065. CGContextSaveGState(context);
  206066. CGContextSetShouldSmoothFonts (context, true);
  206067. CGContextSetShouldAntialias (context, true);
  206068. CGContextSetBlendMode (context, kCGBlendModeNormal);
  206069. rgbColourSpace = CGColorSpaceCreateDeviceRGB();
  206070. greyColourSpace = CGColorSpaceCreateDeviceGray();
  206071. gradientCallbacks.version = 0;
  206072. gradientCallbacks.evaluate = gradientCallback;
  206073. gradientCallbacks.releaseInfo = 0;
  206074. state = new SavedState();
  206075. }
  206076. ~CoreGraphicsContext()
  206077. {
  206078. CGContextRestoreGState (context);
  206079. CGContextRelease (context);
  206080. CGColorSpaceRelease (rgbColourSpace);
  206081. CGColorSpaceRelease (greyColourSpace);
  206082. }
  206083. bool isVectorDevice() const { return false; }
  206084. void setOrigin (int x, int y)
  206085. {
  206086. CGContextTranslateCTM (context, x, -y);
  206087. }
  206088. bool clipToRectangle (const Rectangle<int>& r)
  206089. {
  206090. CGContextClipToRect (context, CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight()));
  206091. return ! isClipEmpty();
  206092. }
  206093. bool clipToRectangleList (const RectangleList& clipRegion)
  206094. {
  206095. if (clipRegion.isEmpty())
  206096. {
  206097. CGContextClipToRect (context, CGRectMake (0, 0, 0, 0));
  206098. return false;
  206099. }
  206100. else
  206101. {
  206102. const int numRects = clipRegion.getNumRectangles();
  206103. HeapBlock <CGRect> rects (numRects);
  206104. for (int i = 0; i < numRects; ++i)
  206105. {
  206106. const Rectangle<int>& r = clipRegion.getRectangle(i);
  206107. rects[i] = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  206108. }
  206109. CGContextClipToRects (context, rects, numRects);
  206110. return ! isClipEmpty();
  206111. }
  206112. }
  206113. void excludeClipRectangle (const Rectangle<int>& r)
  206114. {
  206115. RectangleList remaining (getClipBounds());
  206116. remaining.subtract (r);
  206117. clipToRectangleList (remaining);
  206118. }
  206119. void clipToPath (const Path& path, const AffineTransform& transform)
  206120. {
  206121. createPath (path, transform);
  206122. CGContextClip (context);
  206123. }
  206124. void clipToImageAlpha (const Image& sourceImage, const Rectangle<int>& srcClip, const AffineTransform& transform)
  206125. {
  206126. if (! transform.isSingularity())
  206127. {
  206128. Image* singleChannelImage = createAlphaChannelImage (sourceImage);
  206129. CGImageRef image = CoreGraphicsImage::createImage (*singleChannelImage, true, greyColourSpace);
  206130. flip();
  206131. AffineTransform t (AffineTransform::scale (1.0f, -1.0f).translated (0, sourceImage.getHeight()).followedBy (transform));
  206132. applyTransform (t);
  206133. CGRect r = CGRectMake (0, 0, sourceImage.getWidth(), sourceImage.getHeight());
  206134. CGContextClipToMask (context, r, image);
  206135. applyTransform (t.inverted());
  206136. flip();
  206137. CGImageRelease (image);
  206138. deleteAlphaChannelImage (sourceImage, singleChannelImage);
  206139. }
  206140. }
  206141. bool clipRegionIntersects (const Rectangle<int>& r)
  206142. {
  206143. return getClipBounds().intersects (r);
  206144. }
  206145. const Rectangle<int> getClipBounds() const
  206146. {
  206147. CGRect bounds = CGRectIntegral (CGContextGetClipBoundingBox (context));
  206148. return Rectangle<int> (roundToInt (bounds.origin.x),
  206149. roundToInt (flipHeight - (bounds.origin.y + bounds.size.height)),
  206150. roundToInt (bounds.size.width),
  206151. roundToInt (bounds.size.height));
  206152. }
  206153. bool isClipEmpty() const
  206154. {
  206155. return CGRectIsEmpty (CGContextGetClipBoundingBox (context));
  206156. }
  206157. void saveState()
  206158. {
  206159. CGContextSaveGState (context);
  206160. stateStack.add (new SavedState (*state));
  206161. }
  206162. void restoreState()
  206163. {
  206164. CGContextRestoreGState (context);
  206165. SavedState* const top = stateStack.getLast();
  206166. if (top != 0)
  206167. {
  206168. state = top;
  206169. stateStack.removeLast (1, false);
  206170. }
  206171. else
  206172. {
  206173. jassertfalse // trying to pop with an empty stack!
  206174. }
  206175. }
  206176. void setFill (const FillType& fillType)
  206177. {
  206178. state->fillType = fillType;
  206179. if (fillType.isColour())
  206180. {
  206181. CGContextSetRGBFillColor (context, fillType.colour.getFloatRed(), fillType.colour.getFloatGreen(),
  206182. fillType.colour.getFloatBlue(), fillType.colour.getFloatAlpha());
  206183. CGContextSetAlpha (context, 1.0f);
  206184. }
  206185. }
  206186. void setOpacity (float newOpacity)
  206187. {
  206188. state->fillType.setOpacity (newOpacity);
  206189. setFill (state->fillType);
  206190. }
  206191. void setInterpolationQuality (Graphics::ResamplingQuality quality)
  206192. {
  206193. CGContextSetInterpolationQuality (context, quality == Graphics::lowResamplingQuality
  206194. ? kCGInterpolationLow
  206195. : kCGInterpolationHigh);
  206196. }
  206197. void fillRect (const Rectangle<int>& r, const bool replaceExistingContents)
  206198. {
  206199. CGRect cgRect = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  206200. if (replaceExistingContents)
  206201. {
  206202. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  206203. CGContextClearRect (context, cgRect);
  206204. #else
  206205. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206206. if (CGContextDrawLinearGradient == 0) // (just a way of checking whether we're running in 10.5 or later)
  206207. CGContextClearRect (context, cgRect);
  206208. else
  206209. #endif
  206210. CGContextSetBlendMode (context, kCGBlendModeCopy);
  206211. #endif
  206212. fillRect (r, false);
  206213. CGContextSetBlendMode (context, kCGBlendModeNormal);
  206214. }
  206215. else
  206216. {
  206217. if (state->fillType.isColour())
  206218. {
  206219. CGContextFillRect (context, cgRect);
  206220. }
  206221. else if (state->fillType.isGradient())
  206222. {
  206223. CGContextSaveGState (context);
  206224. CGContextClipToRect (context, cgRect);
  206225. drawGradient();
  206226. CGContextRestoreGState (context);
  206227. }
  206228. else
  206229. {
  206230. CGContextSaveGState (context);
  206231. CGContextClipToRect (context, cgRect);
  206232. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  206233. CGContextRestoreGState (context);
  206234. }
  206235. }
  206236. }
  206237. void fillPath (const Path& path, const AffineTransform& transform)
  206238. {
  206239. CGContextSaveGState (context);
  206240. if (state->fillType.isColour())
  206241. {
  206242. flip();
  206243. applyTransform (transform);
  206244. createPath (path);
  206245. if (path.isUsingNonZeroWinding())
  206246. CGContextFillPath (context);
  206247. else
  206248. CGContextEOFillPath (context);
  206249. }
  206250. else
  206251. {
  206252. createPath (path, transform);
  206253. if (path.isUsingNonZeroWinding())
  206254. CGContextClip (context);
  206255. else
  206256. CGContextEOClip (context);
  206257. if (state->fillType.isGradient())
  206258. drawGradient();
  206259. else
  206260. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  206261. }
  206262. CGContextRestoreGState (context);
  206263. }
  206264. void drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  206265. const AffineTransform& transform, const bool fillEntireClipAsTiles)
  206266. {
  206267. jassert (sourceImage.getBounds().contains (srcClip));
  206268. CGImageRef fullImage = CoreGraphicsImage::createImage (sourceImage, false, rgbColourSpace);
  206269. CGImageRef image = fullImage;
  206270. if (srcClip != sourceImage.getBounds())
  206271. {
  206272. image = CGImageCreateWithImageInRect (fullImage, CGRectMake (srcClip.getX(), srcClip.getY(),
  206273. srcClip.getWidth(), srcClip.getHeight()));
  206274. CGImageRelease (fullImage);
  206275. }
  206276. CGContextSaveGState (context);
  206277. CGContextSetAlpha (context, state->fillType.getOpacity());
  206278. flip();
  206279. applyTransform (AffineTransform::scale (1.0f, -1.0f).translated (0, srcClip.getHeight()).followedBy (transform));
  206280. CGRect imageRect = CGRectMake (0, 0, srcClip.getWidth(), srcClip.getHeight());
  206281. if (fillEntireClipAsTiles)
  206282. {
  206283. #if JUCE_IPHONE || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5)
  206284. CGContextDrawTiledImage (context, imageRect, image);
  206285. #else
  206286. #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
  206287. // There's a bug in CGContextDrawTiledImage that makes it incredibly slow
  206288. // if it's doing a transformation - it's quicker to just draw lots of images manually
  206289. if (CGContextDrawTiledImage != 0 && transform.isOnlyTranslation())
  206290. CGContextDrawTiledImage (context, imageRect, image);
  206291. else
  206292. #endif
  206293. {
  206294. // Fallback to manually doing a tiled fill on 10.4
  206295. CGRect clip = CGRectIntegral (CGContextGetClipBoundingBox (context));
  206296. const int iw = srcClip.getWidth();
  206297. const int ih = srcClip.getHeight();
  206298. int x = 0, y = 0;
  206299. while (x > clip.origin.x) x -= iw;
  206300. while (y > clip.origin.y) y -= ih;
  206301. const int right = (int) (clip.origin.x + clip.size.width);
  206302. const int bottom = (int) (clip.origin.y + clip.size.height);
  206303. while (y < bottom)
  206304. {
  206305. for (int x2 = x; x2 < right; x2 += iw)
  206306. CGContextDrawImage (context, CGRectMake (x2, y, iw, ih), image);
  206307. y += ih;
  206308. }
  206309. }
  206310. #endif
  206311. }
  206312. else
  206313. {
  206314. CGContextDrawImage (context, imageRect, image);
  206315. }
  206316. CGImageRelease (image); // (This causes a memory bug in iPhone sim 3.0 - try upgrading to a later version if you hit this)
  206317. CGContextRestoreGState (context);
  206318. }
  206319. void drawLine (double x1, double y1, double x2, double y2)
  206320. {
  206321. CGContextSetLineCap (context, kCGLineCapSquare);
  206322. CGContextSetLineWidth (context, 1.0f);
  206323. CGContextSetRGBStrokeColor (context,
  206324. state->fillType.colour.getFloatRed(), state->fillType.colour.getFloatGreen(),
  206325. state->fillType.colour.getFloatBlue(), state->fillType.colour.getFloatAlpha());
  206326. CGPoint line[] = { { (float) x1 + 0.5f, flipHeight - ((float) y1 + 0.5f) },
  206327. { (float) x2 + 0.5f, flipHeight - ((float) y2 + 0.5f) } };
  206328. CGContextStrokeLineSegments (context, line, 1);
  206329. }
  206330. void drawVerticalLine (const int x, double top, double bottom)
  206331. {
  206332. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  206333. CGContextFillRect (context, CGRectMake (x, flipHeight - (float) bottom, 1.0f, (float) (bottom - top)));
  206334. #else
  206335. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  206336. // the x co-ord slightly to trick it..
  206337. CGContextFillRect (context, CGRectMake (x + 1.0f / 256.0f, flipHeight - (float) bottom, 1.0f + 1.0f / 256.0f, (float) (bottom - top)));
  206338. #endif
  206339. }
  206340. void drawHorizontalLine (const int y, double left, double right)
  206341. {
  206342. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  206343. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + 1.0f), (float) (right - left), 1.0f));
  206344. #else
  206345. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  206346. // the x co-ord slightly to trick it..
  206347. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + (1.0f + 1.0f / 256.0f)), (float) (right - left), 1.0f + 1.0f / 256.0f));
  206348. #endif
  206349. }
  206350. void setFont (const Font& newFont)
  206351. {
  206352. if (state->font != newFont)
  206353. {
  206354. state->fontRef = 0;
  206355. state->font = newFont;
  206356. MacTypeface* mf = dynamic_cast <MacTypeface*> ((Typeface*) state->font.getTypeface());
  206357. if (mf != 0)
  206358. {
  206359. state->fontRef = mf->fontRef;
  206360. CGContextSetFont (context, state->fontRef);
  206361. CGContextSetFontSize (context, state->font.getHeight() * mf->fontHeightToCGSizeFactor);
  206362. state->fontTransform = mf->renderingTransform;
  206363. state->fontTransform.a *= state->font.getHorizontalScale();
  206364. CGContextSetTextMatrix (context, state->fontTransform);
  206365. }
  206366. }
  206367. }
  206368. const Font getFont()
  206369. {
  206370. return state->font;
  206371. }
  206372. void drawGlyph (int glyphNumber, const AffineTransform& transform)
  206373. {
  206374. if (state->fontRef != 0 && state->fillType.isColour())
  206375. {
  206376. if (transform.isOnlyTranslation())
  206377. {
  206378. CGGlyph g = glyphNumber;
  206379. CGContextShowGlyphsAtPoint (context, transform.getTranslationX(),
  206380. flipHeight - roundToInt (transform.getTranslationY()), &g, 1);
  206381. }
  206382. else
  206383. {
  206384. CGContextSaveGState (context);
  206385. flip();
  206386. applyTransform (transform);
  206387. CGAffineTransform t = state->fontTransform;
  206388. t.d = -t.d;
  206389. CGContextSetTextMatrix (context, t);
  206390. CGGlyph g = glyphNumber;
  206391. CGContextShowGlyphsAtPoint (context, 0, 0, &g, 1);
  206392. CGContextSetTextMatrix (context, state->fontTransform);
  206393. CGContextRestoreGState (context);
  206394. }
  206395. }
  206396. else
  206397. {
  206398. Path p;
  206399. Font& f = state->font;
  206400. f.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  206401. fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight())
  206402. .followedBy (transform));
  206403. }
  206404. }
  206405. private:
  206406. CGContextRef context;
  206407. const float flipHeight;
  206408. CGColorSpaceRef rgbColourSpace, greyColourSpace;
  206409. CGFunctionCallbacks gradientCallbacks;
  206410. struct SavedState
  206411. {
  206412. SavedState()
  206413. : font (1.0f), fontRef (0), fontTransform (CGAffineTransformIdentity)
  206414. {
  206415. }
  206416. SavedState (const SavedState& other)
  206417. : fillType (other.fillType), font (other.font), fontRef (other.fontRef),
  206418. fontTransform (other.fontTransform)
  206419. {
  206420. }
  206421. ~SavedState()
  206422. {
  206423. }
  206424. FillType fillType;
  206425. Font font;
  206426. CGFontRef fontRef;
  206427. CGAffineTransform fontTransform;
  206428. };
  206429. ScopedPointer <SavedState> state;
  206430. OwnedArray <SavedState> stateStack;
  206431. HeapBlock <PixelARGB> gradientLookupTable;
  206432. int numGradientLookupEntries;
  206433. static void gradientCallback (void* info, const CGFloat* inData, CGFloat* outData)
  206434. {
  206435. const CoreGraphicsContext* const g = (const CoreGraphicsContext*) info;
  206436. const int index = roundToInt (g->numGradientLookupEntries * inData[0]);
  206437. PixelARGB colour (g->gradientLookupTable [jlimit (0, g->numGradientLookupEntries, index)]);
  206438. colour.unpremultiply();
  206439. outData[0] = colour.getRed() / 255.0f;
  206440. outData[1] = colour.getGreen() / 255.0f;
  206441. outData[2] = colour.getBlue() / 255.0f;
  206442. outData[3] = colour.getAlpha() / 255.0f;
  206443. }
  206444. CGShadingRef createGradient (const AffineTransform& transform, ColourGradient gradient)
  206445. {
  206446. numGradientLookupEntries = gradient.createLookupTable (transform, gradientLookupTable);
  206447. --numGradientLookupEntries;
  206448. CGShadingRef result = 0;
  206449. CGFunctionRef function = CGFunctionCreate ((void*) this, 1, 0, 4, 0, &gradientCallbacks);
  206450. CGPoint p1 (CGPointMake (gradient.x1, gradient.y1));
  206451. if (gradient.isRadial)
  206452. {
  206453. result = CGShadingCreateRadial (rgbColourSpace, p1, 0,
  206454. p1, hypotf (gradient.x1 - gradient.x2, gradient.y1 - gradient.y2),
  206455. function, true, true);
  206456. }
  206457. else
  206458. {
  206459. result = CGShadingCreateAxial (rgbColourSpace, p1,
  206460. CGPointMake (gradient.x2, gradient.y2),
  206461. function, true, true);
  206462. }
  206463. CGFunctionRelease (function);
  206464. return result;
  206465. }
  206466. void drawGradient()
  206467. {
  206468. flip();
  206469. applyTransform (state->fillType.transform);
  206470. CGContextSetInterpolationQuality (context, kCGInterpolationDefault); // (This is required for 10.4, where there's a crash if
  206471. // you draw a gradient with high quality interp enabled).
  206472. CGShadingRef shading = createGradient (state->fillType.transform, *(state->fillType.gradient));
  206473. CGContextSetAlpha (context, state->fillType.getOpacity());
  206474. CGContextDrawShading (context, shading);
  206475. CGShadingRelease (shading);
  206476. }
  206477. void createPath (const Path& path) const
  206478. {
  206479. CGContextBeginPath (context);
  206480. Path::Iterator i (path);
  206481. while (i.next())
  206482. {
  206483. switch (i.elementType)
  206484. {
  206485. case Path::Iterator::startNewSubPath:
  206486. CGContextMoveToPoint (context, i.x1, i.y1);
  206487. break;
  206488. case Path::Iterator::lineTo:
  206489. CGContextAddLineToPoint (context, i.x1, i.y1);
  206490. break;
  206491. case Path::Iterator::quadraticTo:
  206492. CGContextAddQuadCurveToPoint (context, i.x1, i.y1, i.x2, i.y2);
  206493. break;
  206494. case Path::Iterator::cubicTo:
  206495. CGContextAddCurveToPoint (context, i.x1, i.y1, i.x2, i.y2, i.x3, i.y3);
  206496. break;
  206497. case Path::Iterator::closePath:
  206498. CGContextClosePath (context); break;
  206499. default:
  206500. jassertfalse
  206501. break;
  206502. }
  206503. }
  206504. }
  206505. void createPath (const Path& path, const AffineTransform& transform) const
  206506. {
  206507. CGContextBeginPath (context);
  206508. Path::Iterator i (path);
  206509. while (i.next())
  206510. {
  206511. switch (i.elementType)
  206512. {
  206513. case Path::Iterator::startNewSubPath:
  206514. transform.transformPoint (i.x1, i.y1);
  206515. CGContextMoveToPoint (context, i.x1, flipHeight - i.y1);
  206516. break;
  206517. case Path::Iterator::lineTo:
  206518. transform.transformPoint (i.x1, i.y1);
  206519. CGContextAddLineToPoint (context, i.x1, flipHeight - i.y1);
  206520. break;
  206521. case Path::Iterator::quadraticTo:
  206522. transform.transformPoint (i.x1, i.y1);
  206523. transform.transformPoint (i.x2, i.y2);
  206524. CGContextAddQuadCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2);
  206525. break;
  206526. case Path::Iterator::cubicTo:
  206527. transform.transformPoint (i.x1, i.y1);
  206528. transform.transformPoint (i.x2, i.y2);
  206529. transform.transformPoint (i.x3, i.y3);
  206530. CGContextAddCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2, i.x3, flipHeight - i.y3);
  206531. break;
  206532. case Path::Iterator::closePath:
  206533. CGContextClosePath (context); break;
  206534. default:
  206535. jassertfalse
  206536. break;
  206537. }
  206538. }
  206539. }
  206540. static Image* createAlphaChannelImage (const Image& im)
  206541. {
  206542. if (im.getFormat() == Image::SingleChannel)
  206543. return const_cast <Image*> (&im);
  206544. return im.createCopyOfAlphaChannel();
  206545. }
  206546. static void deleteAlphaChannelImage (const Image& im, Image* const alphaIm)
  206547. {
  206548. if (im.getFormat() != Image::SingleChannel)
  206549. delete alphaIm;
  206550. }
  206551. void flip() const
  206552. {
  206553. CGContextConcatCTM (context, CGAffineTransformMake (1, 0, 0, -1, 0, flipHeight));
  206554. }
  206555. void applyTransform (const AffineTransform& transform) const
  206556. {
  206557. CGAffineTransform t;
  206558. t.a = transform.mat00;
  206559. t.b = transform.mat10;
  206560. t.c = transform.mat01;
  206561. t.d = transform.mat11;
  206562. t.tx = transform.mat02;
  206563. t.ty = transform.mat12;
  206564. CGContextConcatCTM (context, t);
  206565. }
  206566. float flipY (float y) const
  206567. {
  206568. return flipHeight - y;
  206569. }
  206570. };
  206571. LowLevelGraphicsContext* CoreGraphicsImage::createLowLevelContext()
  206572. {
  206573. return new CoreGraphicsContext (context, imageHeight);
  206574. }
  206575. #endif
  206576. /*** End of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  206577. /*** Start of inlined file: juce_mac_NSViewComponentPeer.mm ***/
  206578. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  206579. // compiled on its own).
  206580. #if JUCE_INCLUDED_FILE
  206581. class NSViewComponentPeer;
  206582. END_JUCE_NAMESPACE
  206583. #define JuceNSView MakeObjCClassName(JuceNSView)
  206584. @interface JuceNSView : NSView
  206585. {
  206586. @public
  206587. NSViewComponentPeer* owner;
  206588. NSNotificationCenter* notificationCenter;
  206589. }
  206590. - (JuceNSView*) initWithOwner: (NSViewComponentPeer*) owner withFrame: (NSRect) frame;
  206591. - (void) dealloc;
  206592. - (BOOL) isOpaque;
  206593. - (void) drawRect: (NSRect) r;
  206594. - (void) mouseDown: (NSEvent*) ev;
  206595. - (void) asyncMouseDown: (NSEvent*) ev;
  206596. - (void) mouseUp: (NSEvent*) ev;
  206597. - (void) asyncMouseUp: (NSEvent*) ev;
  206598. - (void) mouseDragged: (NSEvent*) ev;
  206599. - (void) mouseMoved: (NSEvent*) ev;
  206600. - (void) mouseEntered: (NSEvent*) ev;
  206601. - (void) mouseExited: (NSEvent*) ev;
  206602. - (void) rightMouseDown: (NSEvent*) ev;
  206603. - (void) rightMouseDragged: (NSEvent*) ev;
  206604. - (void) rightMouseUp: (NSEvent*) ev;
  206605. - (void) otherMouseDown: (NSEvent*) ev;
  206606. - (void) otherMouseDragged: (NSEvent*) ev;
  206607. - (void) otherMouseUp: (NSEvent*) ev;
  206608. - (void) scrollWheel: (NSEvent*) ev;
  206609. - (BOOL) acceptsFirstMouse: (NSEvent*) ev;
  206610. - (void) frameChanged: (NSNotification*) n;
  206611. - (void) viewDidMoveToWindow;
  206612. - (void) keyDown: (NSEvent*) ev;
  206613. - (void) keyUp: (NSEvent*) ev;
  206614. - (void) flagsChanged: (NSEvent*) ev;
  206615. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206616. - (BOOL) performKeyEquivalent: (NSEvent*) ev;
  206617. #endif
  206618. - (BOOL) becomeFirstResponder;
  206619. - (BOOL) resignFirstResponder;
  206620. - (BOOL) acceptsFirstResponder;
  206621. - (void) asyncRepaint: (id) rect;
  206622. - (NSArray*) getSupportedDragTypes;
  206623. - (BOOL) sendDragCallback: (int) type sender: (id <NSDraggingInfo>) sender;
  206624. - (NSDragOperation) draggingEntered: (id <NSDraggingInfo>) sender;
  206625. - (NSDragOperation) draggingUpdated: (id <NSDraggingInfo>) sender;
  206626. - (void) draggingEnded: (id <NSDraggingInfo>) sender;
  206627. - (void) draggingExited: (id <NSDraggingInfo>) sender;
  206628. - (BOOL) prepareForDragOperation: (id <NSDraggingInfo>) sender;
  206629. - (BOOL) performDragOperation: (id <NSDraggingInfo>) sender;
  206630. - (void) concludeDragOperation: (id <NSDraggingInfo>) sender;
  206631. @end
  206632. #define JuceNSWindow MakeObjCClassName(JuceNSWindow)
  206633. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  206634. @interface JuceNSWindow : NSWindow <NSWindowDelegate>
  206635. #else
  206636. @interface JuceNSWindow : NSWindow
  206637. #endif
  206638. {
  206639. @private
  206640. NSViewComponentPeer* owner;
  206641. bool isZooming;
  206642. }
  206643. - (void) setOwner: (NSViewComponentPeer*) owner;
  206644. - (BOOL) canBecomeKeyWindow;
  206645. - (void) becomeKeyWindow;
  206646. - (BOOL) windowShouldClose: (id) window;
  206647. - (NSRect) constrainFrameRect: (NSRect) frameRect toScreen: (NSScreen*) screen;
  206648. - (NSSize) windowWillResize: (NSWindow*) window toSize: (NSSize) proposedFrameSize;
  206649. - (void) zoom: (id) sender;
  206650. @end
  206651. BEGIN_JUCE_NAMESPACE
  206652. class NSViewComponentPeer : public ComponentPeer
  206653. {
  206654. public:
  206655. NSViewComponentPeer (Component* const component,
  206656. const int windowStyleFlags,
  206657. NSView* viewToAttachTo);
  206658. ~NSViewComponentPeer();
  206659. void* getNativeHandle() const;
  206660. void setVisible (bool shouldBeVisible);
  206661. void setTitle (const String& title);
  206662. void setPosition (int x, int y);
  206663. void setSize (int w, int h);
  206664. void setBounds (int x, int y, int w, int h, const bool isNowFullScreen);
  206665. void getBounds (int& x, int& y, int& w, int& h, const bool global) const;
  206666. void getBounds (int& x, int& y, int& w, int& h) const;
  206667. int getScreenX() const;
  206668. int getScreenY() const;
  206669. void relativePositionToGlobal (int& x, int& y);
  206670. void globalPositionToRelative (int& x, int& y);
  206671. void setMinimised (bool shouldBeMinimised);
  206672. bool isMinimised() const;
  206673. void setFullScreen (bool shouldBeFullScreen);
  206674. bool isFullScreen() const;
  206675. bool contains (int x, int y, bool trueIfInAChildWindow) const;
  206676. const BorderSize getFrameSize() const;
  206677. bool setAlwaysOnTop (bool alwaysOnTop);
  206678. void toFront (bool makeActiveWindow);
  206679. void toBehind (ComponentPeer* other);
  206680. void setIcon (const Image& newIcon);
  206681. const StringArray getAvailableRenderingEngines() throw();
  206682. int getCurrentRenderingEngine() throw();
  206683. void setCurrentRenderingEngine (int index) throw();
  206684. virtual void redirectMouseDown (NSEvent* ev);
  206685. virtual void redirectMouseUp (NSEvent* ev);
  206686. virtual void redirectMouseDrag (NSEvent* ev);
  206687. virtual void redirectMouseMove (NSEvent* ev);
  206688. virtual void redirectMouseEnter (NSEvent* ev);
  206689. virtual void redirectMouseExit (NSEvent* ev);
  206690. virtual void redirectMouseWheel (NSEvent* ev);
  206691. bool handleKeyEvent (NSEvent* ev, bool isKeyDown);
  206692. virtual bool redirectKeyDown (NSEvent* ev);
  206693. virtual bool redirectKeyUp (NSEvent* ev);
  206694. virtual void redirectModKeyChange (NSEvent* ev);
  206695. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206696. virtual bool redirectPerformKeyEquivalent (NSEvent* ev);
  206697. #endif
  206698. virtual BOOL sendDragCallback (int type, id <NSDraggingInfo> sender);
  206699. virtual bool isOpaque();
  206700. virtual void drawRect (NSRect r);
  206701. virtual bool canBecomeKeyWindow();
  206702. virtual bool windowShouldClose();
  206703. virtual void redirectMovedOrResized();
  206704. virtual void viewMovedToWindow();
  206705. virtual NSRect constrainRect (NSRect r);
  206706. static void showArrowCursorIfNeeded();
  206707. virtual void viewFocusGain();
  206708. virtual void viewFocusLoss();
  206709. bool isFocused() const;
  206710. void grabFocus();
  206711. void textInputRequired (int x, int y);
  206712. void repaint (int x, int y, int w, int h);
  206713. void performAnyPendingRepaintsNow();
  206714. juce_UseDebuggingNewOperator
  206715. NSWindow* window;
  206716. JuceNSView* view;
  206717. bool isSharedWindow, fullScreen, insideDrawRect, usingCoreGraphics, recursiveToFrontCall;
  206718. };
  206719. END_JUCE_NAMESPACE
  206720. @implementation JuceNSView
  206721. - (JuceNSView*) initWithOwner: (NSViewComponentPeer*) owner_
  206722. withFrame: (NSRect) frame
  206723. {
  206724. [super initWithFrame: frame];
  206725. owner = owner_;
  206726. notificationCenter = [NSNotificationCenter defaultCenter];
  206727. [notificationCenter addObserver: self
  206728. selector: @selector (frameChanged:)
  206729. name: NSViewFrameDidChangeNotification
  206730. object: self];
  206731. if (! owner_->isSharedWindow)
  206732. {
  206733. [notificationCenter addObserver: self
  206734. selector: @selector (frameChanged:)
  206735. name: NSWindowDidMoveNotification
  206736. object: owner_->window];
  206737. }
  206738. [self registerForDraggedTypes: [self getSupportedDragTypes]];
  206739. return self;
  206740. }
  206741. - (void) dealloc
  206742. {
  206743. [notificationCenter removeObserver: self];
  206744. [super dealloc];
  206745. }
  206746. - (void) drawRect: (NSRect) r
  206747. {
  206748. if (owner != 0)
  206749. owner->drawRect (r);
  206750. }
  206751. - (BOOL) isOpaque
  206752. {
  206753. return owner == 0 || owner->isOpaque();
  206754. }
  206755. - (void) mouseDown: (NSEvent*) ev
  206756. {
  206757. // In some host situations, the host will stop modal loops from working
  206758. // correctly if they're called from a mouse event, so we'll trigger
  206759. // the event asynchronously..
  206760. if (JUCEApplication::getInstance() == 0)
  206761. [self performSelectorOnMainThread: @selector (asyncMouseDown:)
  206762. withObject: ev
  206763. waitUntilDone: NO];
  206764. else
  206765. [self asyncMouseDown: ev];
  206766. }
  206767. - (void) asyncMouseDown: (NSEvent*) ev
  206768. {
  206769. if (owner != 0)
  206770. owner->redirectMouseDown (ev);
  206771. }
  206772. - (void) mouseUp: (NSEvent*) ev
  206773. {
  206774. // In some host situations, the host will stop modal loops from working
  206775. // correctly if they're called from a mouse event, so we'll trigger
  206776. // the event asynchronously..
  206777. if (JUCEApplication::getInstance() == 0)
  206778. [self performSelectorOnMainThread: @selector (asyncMouseUp:)
  206779. withObject: ev
  206780. waitUntilDone: NO];
  206781. else
  206782. [self asyncMouseUp: ev];
  206783. }
  206784. - (void) asyncMouseUp: (NSEvent*) ev
  206785. {
  206786. if (owner != 0)
  206787. owner->redirectMouseUp (ev);
  206788. }
  206789. - (void) mouseDragged: (NSEvent*) ev
  206790. {
  206791. if (owner != 0)
  206792. owner->redirectMouseDrag (ev);
  206793. }
  206794. - (void) mouseMoved: (NSEvent*) ev
  206795. {
  206796. if (owner != 0)
  206797. owner->redirectMouseMove (ev);
  206798. }
  206799. - (void) mouseEntered: (NSEvent*) ev
  206800. {
  206801. if (owner != 0)
  206802. owner->redirectMouseEnter (ev);
  206803. }
  206804. - (void) mouseExited: (NSEvent*) ev
  206805. {
  206806. if (owner != 0)
  206807. owner->redirectMouseExit (ev);
  206808. }
  206809. - (void) rightMouseDown: (NSEvent*) ev
  206810. {
  206811. [self mouseDown: ev];
  206812. }
  206813. - (void) rightMouseDragged: (NSEvent*) ev
  206814. {
  206815. [self mouseDragged: ev];
  206816. }
  206817. - (void) rightMouseUp: (NSEvent*) ev
  206818. {
  206819. [self mouseUp: ev];
  206820. }
  206821. - (void) otherMouseDown: (NSEvent*) ev
  206822. {
  206823. [self mouseDown: ev];
  206824. }
  206825. - (void) otherMouseDragged: (NSEvent*) ev
  206826. {
  206827. [self mouseDragged: ev];
  206828. }
  206829. - (void) otherMouseUp: (NSEvent*) ev
  206830. {
  206831. [self mouseUp: ev];
  206832. }
  206833. - (void) scrollWheel: (NSEvent*) ev
  206834. {
  206835. if (owner != 0)
  206836. owner->redirectMouseWheel (ev);
  206837. }
  206838. - (BOOL) acceptsFirstMouse: (NSEvent*) ev
  206839. {
  206840. return YES;
  206841. }
  206842. - (void) frameChanged: (NSNotification*) n
  206843. {
  206844. if (owner != 0)
  206845. owner->redirectMovedOrResized();
  206846. }
  206847. - (void) viewDidMoveToWindow
  206848. {
  206849. if (owner != 0)
  206850. owner->viewMovedToWindow();
  206851. }
  206852. - (void) asyncRepaint: (id) rect
  206853. {
  206854. NSRect* r = (NSRect*) [((NSData*) rect) bytes];
  206855. [self setNeedsDisplayInRect: *r];
  206856. }
  206857. - (void) keyDown: (NSEvent*) ev
  206858. {
  206859. if (owner == 0 || ! owner->redirectKeyDown (ev))
  206860. [super keyDown: ev];
  206861. }
  206862. - (void) keyUp: (NSEvent*) ev
  206863. {
  206864. if (owner == 0 || ! owner->redirectKeyUp (ev))
  206865. [super keyUp: ev];
  206866. }
  206867. - (void) flagsChanged: (NSEvent*) ev
  206868. {
  206869. if (owner != 0)
  206870. owner->redirectModKeyChange (ev);
  206871. }
  206872. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206873. - (BOOL) performKeyEquivalent: (NSEvent*) ev
  206874. {
  206875. if (owner != 0 && owner->redirectPerformKeyEquivalent (ev))
  206876. return true;
  206877. return [super performKeyEquivalent: ev];
  206878. }
  206879. #endif
  206880. - (BOOL) becomeFirstResponder
  206881. {
  206882. if (owner != 0)
  206883. owner->viewFocusGain();
  206884. return true;
  206885. }
  206886. - (BOOL) resignFirstResponder
  206887. {
  206888. if (owner != 0)
  206889. owner->viewFocusLoss();
  206890. return true;
  206891. }
  206892. - (BOOL) acceptsFirstResponder
  206893. {
  206894. return owner != 0 && owner->canBecomeKeyWindow();
  206895. }
  206896. - (NSArray*) getSupportedDragTypes
  206897. {
  206898. return [NSArray arrayWithObjects: NSFilenamesPboardType, /*NSFilesPromisePboardType, NSStringPboardType,*/ nil];
  206899. }
  206900. - (BOOL) sendDragCallback: (int) type sender: (id <NSDraggingInfo>) sender
  206901. {
  206902. return owner != 0 && owner->sendDragCallback (type, sender);
  206903. }
  206904. - (NSDragOperation) draggingEntered: (id <NSDraggingInfo>) sender
  206905. {
  206906. if ([self sendDragCallback: 0 sender: sender])
  206907. return NSDragOperationCopy | NSDragOperationMove | NSDragOperationGeneric;
  206908. else
  206909. return NSDragOperationNone;
  206910. }
  206911. - (NSDragOperation) draggingUpdated: (id <NSDraggingInfo>) sender
  206912. {
  206913. if ([self sendDragCallback: 0 sender: sender])
  206914. return NSDragOperationCopy | NSDragOperationMove | NSDragOperationGeneric;
  206915. else
  206916. return NSDragOperationNone;
  206917. }
  206918. - (void) draggingEnded: (id <NSDraggingInfo>) sender
  206919. {
  206920. [self sendDragCallback: 1 sender: sender];
  206921. }
  206922. - (void) draggingExited: (id <NSDraggingInfo>) sender
  206923. {
  206924. [self sendDragCallback: 1 sender: sender];
  206925. }
  206926. - (BOOL) prepareForDragOperation: (id <NSDraggingInfo>) sender
  206927. {
  206928. return YES;
  206929. }
  206930. - (BOOL) performDragOperation: (id <NSDraggingInfo>) sender
  206931. {
  206932. return [self sendDragCallback: 2 sender: sender];
  206933. }
  206934. - (void) concludeDragOperation: (id <NSDraggingInfo>) sender
  206935. {
  206936. }
  206937. @end
  206938. @implementation JuceNSWindow
  206939. - (void) setOwner: (NSViewComponentPeer*) owner_
  206940. {
  206941. owner = owner_;
  206942. isZooming = false;
  206943. }
  206944. - (BOOL) canBecomeKeyWindow
  206945. {
  206946. return owner != 0 && owner->canBecomeKeyWindow();
  206947. }
  206948. - (void) becomeKeyWindow
  206949. {
  206950. [super becomeKeyWindow];
  206951. if (owner != 0)
  206952. owner->grabFocus();
  206953. }
  206954. - (BOOL) windowShouldClose: (id) window
  206955. {
  206956. return owner == 0 || owner->windowShouldClose();
  206957. }
  206958. - (NSRect) constrainFrameRect: (NSRect) frameRect toScreen: (NSScreen*) screen
  206959. {
  206960. if (owner != 0)
  206961. frameRect = owner->constrainRect (frameRect);
  206962. return frameRect;
  206963. }
  206964. - (NSSize) windowWillResize: (NSWindow*) window toSize: (NSSize) proposedFrameSize
  206965. {
  206966. if (isZooming)
  206967. return proposedFrameSize;
  206968. NSRect frameRect = [self frame];
  206969. frameRect.origin.y -= proposedFrameSize.height - frameRect.size.height;
  206970. frameRect.size = proposedFrameSize;
  206971. if (owner != 0)
  206972. frameRect = owner->constrainRect (frameRect);
  206973. return frameRect.size;
  206974. }
  206975. - (void) zoom: (id) sender
  206976. {
  206977. isZooming = true;
  206978. [super zoom: sender];
  206979. isZooming = false;
  206980. }
  206981. - (void) windowWillMove: (NSNotification*) notification
  206982. {
  206983. if (JUCE_NAMESPACE::Component::getCurrentlyModalComponent() != 0
  206984. && owner->getComponent()->isCurrentlyBlockedByAnotherModalComponent()
  206985. && (owner->getStyleFlags() & JUCE_NAMESPACE::ComponentPeer::windowHasTitleBar) != 0)
  206986. JUCE_NAMESPACE::Component::getCurrentlyModalComponent()->inputAttemptWhenModal();
  206987. }
  206988. @end
  206989. BEGIN_JUCE_NAMESPACE
  206990. static ComponentPeer* currentlyFocusedPeer = 0;
  206991. static VoidArray keysCurrentlyDown;
  206992. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  206993. {
  206994. if (keysCurrentlyDown.contains ((void*) keyCode))
  206995. return true;
  206996. if (keyCode >= 'A' && keyCode <= 'Z'
  206997. && keysCurrentlyDown.contains ((void*) (int) CharacterFunctions::toLowerCase ((tchar) keyCode)))
  206998. return true;
  206999. if (keyCode >= 'a' && keyCode <= 'z'
  207000. && keysCurrentlyDown.contains ((void*) (int) CharacterFunctions::toUpperCase ((tchar) keyCode)))
  207001. return true;
  207002. return false;
  207003. }
  207004. static int getKeyCodeFromEvent (NSEvent* ev)
  207005. {
  207006. const String unmodified (nsStringToJuce ([ev charactersIgnoringModifiers]));
  207007. int keyCode = unmodified[0];
  207008. if (keyCode == 0x19) // (backwards-tab)
  207009. keyCode = '\t';
  207010. else if (keyCode == 0x03) // (enter)
  207011. keyCode = '\r';
  207012. return keyCode;
  207013. }
  207014. static int currentModifiers = 0;
  207015. static void updateModifiers (NSEvent* e)
  207016. {
  207017. int m = currentModifiers & ~(ModifierKeys::shiftModifier | ModifierKeys::ctrlModifier
  207018. | ModifierKeys::altModifier | ModifierKeys::commandModifier);
  207019. if (([e modifierFlags] & NSShiftKeyMask) != 0)
  207020. m |= ModifierKeys::shiftModifier;
  207021. if (([e modifierFlags] & NSControlKeyMask) != 0)
  207022. m |= ModifierKeys::ctrlModifier;
  207023. if (([e modifierFlags] & NSAlternateKeyMask) != 0)
  207024. m |= ModifierKeys::altModifier;
  207025. if (([e modifierFlags] & NSCommandKeyMask) != 0)
  207026. m |= ModifierKeys::commandModifier;
  207027. currentModifiers = m;
  207028. }
  207029. static void updateKeysDown (NSEvent* ev, bool isKeyDown)
  207030. {
  207031. updateModifiers (ev);
  207032. int keyCode = getKeyCodeFromEvent (ev);
  207033. if (keyCode != 0)
  207034. {
  207035. if (isKeyDown)
  207036. keysCurrentlyDown.addIfNotAlreadyThere ((void*) keyCode);
  207037. else
  207038. keysCurrentlyDown.removeValue ((void*) keyCode);
  207039. }
  207040. }
  207041. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  207042. {
  207043. return ModifierKeys (currentModifiers);
  207044. }
  207045. void ModifierKeys::updateCurrentModifiers() throw()
  207046. {
  207047. currentModifierFlags = currentModifiers;
  207048. }
  207049. static int64 getMouseTime (NSEvent* e)
  207050. {
  207051. return (Time::currentTimeMillis() - Time::getMillisecondCounter())
  207052. + (int64) ([e timestamp] * 1000.0);
  207053. }
  207054. static void getMousePos (NSEvent* e, NSView* view, int& x, int& y)
  207055. {
  207056. NSPoint p = [view convertPoint: [e locationInWindow] fromView: nil];
  207057. x = roundToInt (p.x);
  207058. y = roundToInt ([view frame].size.height - p.y);
  207059. }
  207060. static int getModifierForButtonNumber (const NSInteger num)
  207061. {
  207062. return num == 0 ? ModifierKeys::leftButtonModifier
  207063. : (num == 1 ? ModifierKeys::rightButtonModifier
  207064. : (num == 2 ? ModifierKeys::middleButtonModifier : 0));
  207065. }
  207066. NSViewComponentPeer::NSViewComponentPeer (Component* const component_,
  207067. const int windowStyleFlags,
  207068. NSView* viewToAttachTo)
  207069. : ComponentPeer (component_, windowStyleFlags),
  207070. window (0),
  207071. view (0),
  207072. isSharedWindow (viewToAttachTo != 0),
  207073. fullScreen (false),
  207074. insideDrawRect (false),
  207075. #if USE_COREGRAPHICS_RENDERING
  207076. usingCoreGraphics (true),
  207077. #else
  207078. usingCoreGraphics (false),
  207079. #endif
  207080. recursiveToFrontCall (false)
  207081. {
  207082. NSRect r;
  207083. r.origin.x = 0;
  207084. r.origin.y = 0;
  207085. r.size.width = (float) component->getWidth();
  207086. r.size.height = (float) component->getHeight();
  207087. view = [[JuceNSView alloc] initWithOwner: this withFrame: r];
  207088. [view setPostsFrameChangedNotifications: YES];
  207089. if (isSharedWindow)
  207090. {
  207091. window = [viewToAttachTo window];
  207092. [viewToAttachTo addSubview: view];
  207093. setVisible (component->isVisible());
  207094. }
  207095. else
  207096. {
  207097. r.origin.x = (float) component->getX();
  207098. r.origin.y = (float) component->getY();
  207099. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - (r.origin.y + r.size.height);
  207100. unsigned int style = 0;
  207101. if ((windowStyleFlags & windowHasTitleBar) == 0)
  207102. style = NSBorderlessWindowMask;
  207103. else
  207104. style = NSTitledWindowMask;
  207105. if ((windowStyleFlags & windowHasMinimiseButton) != 0)
  207106. style |= NSMiniaturizableWindowMask;
  207107. if ((windowStyleFlags & windowHasCloseButton) != 0)
  207108. style |= NSClosableWindowMask;
  207109. if ((windowStyleFlags & windowIsResizable) != 0)
  207110. style |= NSResizableWindowMask;
  207111. window = [[JuceNSWindow alloc] initWithContentRect: r
  207112. styleMask: style
  207113. backing: NSBackingStoreBuffered
  207114. defer: YES];
  207115. [((JuceNSWindow*) window) setOwner: this];
  207116. [window orderOut: nil];
  207117. [window setDelegate: (JuceNSWindow*) window];
  207118. [window setOpaque: component->isOpaque()];
  207119. [window setHasShadow: ((windowStyleFlags & windowHasDropShadow) != 0)];
  207120. if (component->isAlwaysOnTop())
  207121. [window setLevel: NSFloatingWindowLevel];
  207122. [window setContentView: view];
  207123. [window setAutodisplay: YES];
  207124. [window setAcceptsMouseMovedEvents: YES];
  207125. // We'll both retain and also release this on closing because plugin hosts can unexpectedly
  207126. // close the window for us, and also tend to get cause trouble if setReleasedWhenClosed is NO.
  207127. [window setReleasedWhenClosed: YES];
  207128. [window retain];
  207129. [window setExcludedFromWindowsMenu: (windowStyleFlags & windowIsTemporary) != 0];
  207130. [window setIgnoresMouseEvents: (windowStyleFlags & windowIgnoresMouseClicks) != 0];
  207131. }
  207132. setTitle (component->getName());
  207133. }
  207134. NSViewComponentPeer::~NSViewComponentPeer()
  207135. {
  207136. view->owner = 0;
  207137. [view removeFromSuperview];
  207138. [view release];
  207139. if (! isSharedWindow)
  207140. {
  207141. [((JuceNSWindow*) window) setOwner: 0];
  207142. [window close];
  207143. [window release];
  207144. }
  207145. }
  207146. void* NSViewComponentPeer::getNativeHandle() const
  207147. {
  207148. return view;
  207149. }
  207150. void NSViewComponentPeer::setVisible (bool shouldBeVisible)
  207151. {
  207152. if (isSharedWindow)
  207153. {
  207154. [view setHidden: ! shouldBeVisible];
  207155. }
  207156. else
  207157. {
  207158. if (shouldBeVisible)
  207159. {
  207160. [window orderFront: nil];
  207161. handleBroughtToFront();
  207162. }
  207163. else
  207164. {
  207165. [window orderOut: nil];
  207166. }
  207167. }
  207168. }
  207169. void NSViewComponentPeer::setTitle (const String& title)
  207170. {
  207171. const ScopedAutoReleasePool pool;
  207172. if (! isSharedWindow)
  207173. [window setTitle: juceStringToNS (title)];
  207174. }
  207175. void NSViewComponentPeer::setPosition (int x, int y)
  207176. {
  207177. setBounds (x, y, component->getWidth(), component->getHeight(), false);
  207178. }
  207179. void NSViewComponentPeer::setSize (int w, int h)
  207180. {
  207181. setBounds (component->getX(), component->getY(), w, h, false);
  207182. }
  207183. void NSViewComponentPeer::setBounds (int x, int y, int w, int h, const bool isNowFullScreen)
  207184. {
  207185. fullScreen = isNowFullScreen;
  207186. w = jmax (0, w);
  207187. h = jmax (0, h);
  207188. NSRect r;
  207189. r.origin.x = (float) x;
  207190. r.origin.y = (float) y;
  207191. r.size.width = (float) w;
  207192. r.size.height = (float) h;
  207193. if (isSharedWindow)
  207194. {
  207195. r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  207196. if ([view frame].size.width != r.size.width
  207197. || [view frame].size.height != r.size.height)
  207198. [view setNeedsDisplay: true];
  207199. [view setFrame: r];
  207200. }
  207201. else
  207202. {
  207203. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - (r.origin.y + r.size.height);
  207204. [window setFrame: [window frameRectForContentRect: r]
  207205. display: true];
  207206. }
  207207. }
  207208. void NSViewComponentPeer::getBounds (int& x, int& y, int& w, int& h, const bool global) const
  207209. {
  207210. NSRect r = [view frame];
  207211. if (global && [view window] != 0)
  207212. {
  207213. r = [view convertRect: r toView: nil];
  207214. NSRect wr = [[view window] frame];
  207215. r.origin.x += wr.origin.x;
  207216. r.origin.y += wr.origin.y;
  207217. y = (int) ([[[NSScreen screens] objectAtIndex:0] frame].size.height - r.origin.y - r.size.height);
  207218. }
  207219. else
  207220. {
  207221. y = (int) ([[view superview] frame].size.height - r.origin.y - r.size.height);
  207222. }
  207223. x = (int) r.origin.x;
  207224. w = (int) r.size.width;
  207225. h = (int) r.size.height;
  207226. }
  207227. void NSViewComponentPeer::getBounds (int& x, int& y, int& w, int& h) const
  207228. {
  207229. getBounds (x, y, w, h, ! isSharedWindow);
  207230. }
  207231. int NSViewComponentPeer::getScreenX() const
  207232. {
  207233. int x, y, w, h;
  207234. getBounds (x, y, w, h, true);
  207235. return x;
  207236. }
  207237. int NSViewComponentPeer::getScreenY() const
  207238. {
  207239. int x, y, w, h;
  207240. getBounds (x, y, w, h, true);
  207241. return y;
  207242. }
  207243. void NSViewComponentPeer::relativePositionToGlobal (int& x, int& y)
  207244. {
  207245. int wx, wy, ww, wh;
  207246. getBounds (wx, wy, ww, wh, true);
  207247. x += wx;
  207248. y += wy;
  207249. }
  207250. void NSViewComponentPeer::globalPositionToRelative (int& x, int& y)
  207251. {
  207252. int wx, wy, ww, wh;
  207253. getBounds (wx, wy, ww, wh, true);
  207254. x -= wx;
  207255. y -= wy;
  207256. }
  207257. NSRect NSViewComponentPeer::constrainRect (NSRect r)
  207258. {
  207259. if (constrainer != 0)
  207260. {
  207261. NSRect current = [window frame];
  207262. current.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - current.origin.y - current.size.height;
  207263. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.origin.y - r.size.height;
  207264. Rectangle<int> pos ((int) r.origin.x, (int) r.origin.y,
  207265. (int) r.size.width, (int) r.size.height);
  207266. Rectangle<int> original ((int) current.origin.x, (int) current.origin.y,
  207267. (int) current.size.width, (int) current.size.height);
  207268. constrainer->checkBounds (pos, original,
  207269. Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(),
  207270. pos.getY() != original.getY() && pos.getBottom() == original.getBottom(),
  207271. pos.getX() != original.getX() && pos.getRight() == original.getRight(),
  207272. pos.getY() == original.getY() && pos.getBottom() != original.getBottom(),
  207273. pos.getX() == original.getX() && pos.getRight() != original.getRight());
  207274. r.origin.x = pos.getX();
  207275. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.size.height - pos.getY();
  207276. r.size.width = pos.getWidth();
  207277. r.size.height = pos.getHeight();
  207278. }
  207279. return r;
  207280. }
  207281. void NSViewComponentPeer::setMinimised (bool shouldBeMinimised)
  207282. {
  207283. if (! isSharedWindow)
  207284. {
  207285. if (shouldBeMinimised)
  207286. [window miniaturize: nil];
  207287. else
  207288. [window deminiaturize: nil];
  207289. }
  207290. }
  207291. bool NSViewComponentPeer::isMinimised() const
  207292. {
  207293. return window != 0 && [window isMiniaturized];
  207294. }
  207295. void NSViewComponentPeer::setFullScreen (bool shouldBeFullScreen)
  207296. {
  207297. if (! isSharedWindow)
  207298. {
  207299. Rectangle<int> r (lastNonFullscreenBounds);
  207300. setMinimised (false);
  207301. if (fullScreen != shouldBeFullScreen)
  207302. {
  207303. if (shouldBeFullScreen && (getStyleFlags() & windowHasTitleBar) != 0)
  207304. {
  207305. fullScreen = true;
  207306. [window performZoom: nil];
  207307. }
  207308. else
  207309. {
  207310. if (shouldBeFullScreen)
  207311. r = Desktop::getInstance().getMainMonitorArea();
  207312. // (can't call the component's setBounds method because that'll reset our fullscreen flag)
  207313. if (r != getComponent()->getBounds() && ! r.isEmpty())
  207314. setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight(), shouldBeFullScreen);
  207315. }
  207316. }
  207317. }
  207318. }
  207319. bool NSViewComponentPeer::isFullScreen() const
  207320. {
  207321. return fullScreen;
  207322. }
  207323. bool NSViewComponentPeer::contains (int x, int y, bool trueIfInAChildWindow) const
  207324. {
  207325. if (((unsigned int) x) >= (unsigned int) component->getWidth()
  207326. || ((unsigned int) y) >= (unsigned int) component->getHeight())
  207327. return false;
  207328. NSPoint p;
  207329. p.x = (float) x;
  207330. p.y = (float) y;
  207331. NSView* v = [view hitTest: p];
  207332. if (trueIfInAChildWindow)
  207333. return v != nil;
  207334. return v == view;
  207335. }
  207336. const BorderSize NSViewComponentPeer::getFrameSize() const
  207337. {
  207338. BorderSize b;
  207339. if (! isSharedWindow)
  207340. {
  207341. NSRect v = [view convertRect: [view frame] toView: nil];
  207342. NSRect w = [window frame];
  207343. b.setTop ((int) (w.size.height - (v.origin.y + v.size.height)));
  207344. b.setBottom ((int) v.origin.y);
  207345. b.setLeft ((int) v.origin.x);
  207346. b.setRight ((int) (w.size.width - (v.origin.x + v.size.width)));
  207347. }
  207348. return b;
  207349. }
  207350. bool NSViewComponentPeer::setAlwaysOnTop (bool alwaysOnTop)
  207351. {
  207352. if (! isSharedWindow)
  207353. {
  207354. [window setLevel: alwaysOnTop ? NSFloatingWindowLevel
  207355. : NSNormalWindowLevel];
  207356. }
  207357. return true;
  207358. }
  207359. void NSViewComponentPeer::toFront (bool makeActiveWindow)
  207360. {
  207361. if (isSharedWindow)
  207362. {
  207363. [[view superview] addSubview: view
  207364. positioned: NSWindowAbove
  207365. relativeTo: nil];
  207366. }
  207367. if (window != 0 && component->isVisible())
  207368. {
  207369. if (makeActiveWindow)
  207370. [window makeKeyAndOrderFront: nil];
  207371. else
  207372. [window orderFront: nil];
  207373. if (! recursiveToFrontCall)
  207374. {
  207375. recursiveToFrontCall = true;
  207376. handleBroughtToFront();
  207377. recursiveToFrontCall = false;
  207378. }
  207379. }
  207380. }
  207381. void NSViewComponentPeer::toBehind (ComponentPeer* other)
  207382. {
  207383. NSViewComponentPeer* o = (NSViewComponentPeer*) other;
  207384. if (isSharedWindow)
  207385. {
  207386. [[view superview] addSubview: view
  207387. positioned: NSWindowBelow
  207388. relativeTo: o->view];
  207389. }
  207390. else
  207391. {
  207392. [window orderWindow: NSWindowBelow
  207393. relativeTo: o->window != 0 ? [o->window windowNumber]
  207394. : nil ];
  207395. }
  207396. }
  207397. void NSViewComponentPeer::setIcon (const Image& /*newIcon*/)
  207398. {
  207399. // to do..
  207400. }
  207401. void NSViewComponentPeer::viewFocusGain()
  207402. {
  207403. if (currentlyFocusedPeer != this)
  207404. {
  207405. if (ComponentPeer::isValidPeer (currentlyFocusedPeer))
  207406. currentlyFocusedPeer->handleFocusLoss();
  207407. currentlyFocusedPeer = this;
  207408. handleFocusGain();
  207409. }
  207410. }
  207411. void NSViewComponentPeer::viewFocusLoss()
  207412. {
  207413. if (currentlyFocusedPeer == this)
  207414. {
  207415. currentlyFocusedPeer = 0;
  207416. handleFocusLoss();
  207417. }
  207418. }
  207419. void juce_HandleProcessFocusChange()
  207420. {
  207421. keysCurrentlyDown.clear();
  207422. if (NSViewComponentPeer::isValidPeer (currentlyFocusedPeer))
  207423. {
  207424. if (Process::isForegroundProcess())
  207425. {
  207426. currentlyFocusedPeer->handleFocusGain();
  207427. ComponentPeer::bringModalComponentToFront();
  207428. }
  207429. else
  207430. {
  207431. currentlyFocusedPeer->handleFocusLoss();
  207432. // turn kiosk mode off if we lose focus..
  207433. Desktop::getInstance().setKioskModeComponent (0);
  207434. }
  207435. }
  207436. }
  207437. bool NSViewComponentPeer::isFocused() const
  207438. {
  207439. return isSharedWindow ? this == currentlyFocusedPeer
  207440. : (window != 0 && [window isKeyWindow]);
  207441. }
  207442. void NSViewComponentPeer::grabFocus()
  207443. {
  207444. if (window != 0)
  207445. {
  207446. [window makeKeyWindow];
  207447. [window makeFirstResponder: view];
  207448. viewFocusGain();
  207449. }
  207450. }
  207451. void NSViewComponentPeer::textInputRequired (int /*x*/, int /*y*/)
  207452. {
  207453. }
  207454. bool NSViewComponentPeer::handleKeyEvent (NSEvent* ev, bool isKeyDown)
  207455. {
  207456. String unicode (nsStringToJuce ([ev characters]));
  207457. String unmodified (nsStringToJuce ([ev charactersIgnoringModifiers]));
  207458. int keyCode = getKeyCodeFromEvent (ev);
  207459. //DBG ("unicode: " + unicode + " " + String::toHexString ((int) unicode[0]));
  207460. //DBG ("unmodified: " + unmodified + " " + String::toHexString ((int) unmodified[0]));
  207461. if (unicode.isNotEmpty() || keyCode != 0)
  207462. {
  207463. if (isKeyDown)
  207464. {
  207465. bool used = false;
  207466. while (unicode.length() > 0)
  207467. {
  207468. juce_wchar textCharacter = unicode[0];
  207469. unicode = unicode.substring (1);
  207470. if (([ev modifierFlags] & NSCommandKeyMask) != 0)
  207471. textCharacter = 0;
  207472. used = handleKeyUpOrDown (true) || used;
  207473. used = handleKeyPress (keyCode, textCharacter) || used;
  207474. }
  207475. return used;
  207476. }
  207477. else
  207478. {
  207479. if (handleKeyUpOrDown (false))
  207480. return true;
  207481. }
  207482. }
  207483. return false;
  207484. }
  207485. bool NSViewComponentPeer::redirectKeyDown (NSEvent* ev)
  207486. {
  207487. updateKeysDown (ev, true);
  207488. bool used = handleKeyEvent (ev, true);
  207489. if (([ev modifierFlags] & NSCommandKeyMask) != 0)
  207490. {
  207491. // for command keys, the key-up event is thrown away, so simulate one..
  207492. updateKeysDown (ev, false);
  207493. used = (isValidPeer (this) && handleKeyEvent (ev, false)) || used;
  207494. }
  207495. // (If we're running modally, don't allow unused keystrokes to be passed
  207496. // along to other blocked views..)
  207497. if (Component::getCurrentlyModalComponent() != 0)
  207498. used = true;
  207499. return used;
  207500. }
  207501. bool NSViewComponentPeer::redirectKeyUp (NSEvent* ev)
  207502. {
  207503. updateKeysDown (ev, false);
  207504. return handleKeyEvent (ev, false)
  207505. || Component::getCurrentlyModalComponent() != 0;
  207506. }
  207507. void NSViewComponentPeer::redirectModKeyChange (NSEvent* ev)
  207508. {
  207509. keysCurrentlyDown.clear();
  207510. handleKeyUpOrDown (true);
  207511. updateModifiers (ev);
  207512. handleModifierKeysChange();
  207513. }
  207514. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  207515. bool NSViewComponentPeer::redirectPerformKeyEquivalent (NSEvent* ev)
  207516. {
  207517. if ([ev type] == NSKeyDown)
  207518. return redirectKeyDown (ev);
  207519. else if ([ev type] == NSKeyUp)
  207520. return redirectKeyUp (ev);
  207521. return false;
  207522. }
  207523. #endif
  207524. void NSViewComponentPeer::redirectMouseDown (NSEvent* ev)
  207525. {
  207526. updateModifiers (ev);
  207527. currentModifiers |= getModifierForButtonNumber ([ev buttonNumber]);
  207528. int x, y;
  207529. getMousePos (ev, view, x, y);
  207530. handleMouseDown (x, y, getMouseTime (ev));
  207531. }
  207532. void NSViewComponentPeer::redirectMouseUp (NSEvent* ev)
  207533. {
  207534. const int oldMods = currentModifiers;
  207535. updateModifiers (ev);
  207536. currentModifiers &= ~getModifierForButtonNumber ([ev buttonNumber]);
  207537. int x, y;
  207538. getMousePos (ev, view, x, y);
  207539. handleMouseUp (oldMods, x, y, getMouseTime (ev));
  207540. showArrowCursorIfNeeded();
  207541. }
  207542. void NSViewComponentPeer::redirectMouseDrag (NSEvent* ev)
  207543. {
  207544. updateModifiers (ev);
  207545. currentModifiers |= getModifierForButtonNumber ([ev buttonNumber]);
  207546. int x, y;
  207547. getMousePos (ev, view, x, y);
  207548. handleMouseDrag (x, y, getMouseTime (ev));
  207549. }
  207550. void NSViewComponentPeer::redirectMouseMove (NSEvent* ev)
  207551. {
  207552. updateModifiers (ev);
  207553. int x, y;
  207554. getMousePos (ev, view, x, y);
  207555. handleMouseMove (x, y, getMouseTime (ev));
  207556. showArrowCursorIfNeeded();
  207557. }
  207558. void NSViewComponentPeer::redirectMouseEnter (NSEvent* ev)
  207559. {
  207560. updateModifiers (ev);
  207561. int x, y;
  207562. getMousePos (ev, view, x, y);
  207563. handleMouseEnter (x, y, getMouseTime (ev));
  207564. }
  207565. void NSViewComponentPeer::redirectMouseExit (NSEvent* ev)
  207566. {
  207567. updateModifiers (ev);
  207568. int x, y;
  207569. getMousePos (ev, view, x, y);
  207570. handleMouseExit (x, y, getMouseTime (ev));
  207571. }
  207572. void NSViewComponentPeer::redirectMouseWheel (NSEvent* ev)
  207573. {
  207574. updateModifiers (ev);
  207575. handleMouseWheel (roundToInt ([ev deltaX] * 10.0f),
  207576. roundToInt ([ev deltaY] * 10.0f),
  207577. getMouseTime (ev));
  207578. }
  207579. void NSViewComponentPeer::showArrowCursorIfNeeded()
  207580. {
  207581. if (Component::getComponentUnderMouse() == 0)
  207582. {
  207583. int mx, my;
  207584. Desktop::getInstance().getMousePosition (mx, my);
  207585. if (Desktop::getInstance().findComponentAt (mx, my) == 0)
  207586. [[NSCursor arrowCursor] set];
  207587. }
  207588. }
  207589. BOOL NSViewComponentPeer::sendDragCallback (int type, id <NSDraggingInfo> sender)
  207590. {
  207591. NSString* bestType
  207592. = [[sender draggingPasteboard] availableTypeFromArray: [view getSupportedDragTypes]];
  207593. if (bestType == nil)
  207594. return false;
  207595. NSPoint p = [view convertPoint: [sender draggingLocation] fromView: nil];
  207596. int x = (int) p.x;
  207597. int y = (int) ([view frame].size.height - p.y);
  207598. StringArray files;
  207599. id list = [[sender draggingPasteboard] propertyListForType: bestType];
  207600. if (list == nil)
  207601. return false;
  207602. if ([list isKindOfClass: [NSArray class]])
  207603. {
  207604. NSArray* items = (NSArray*) list;
  207605. for (unsigned int i = 0; i < [items count]; ++i)
  207606. files.add (nsStringToJuce ((NSString*) [items objectAtIndex: i]));
  207607. }
  207608. if (files.size() == 0)
  207609. return false;
  207610. if (type == 0)
  207611. handleFileDragMove (files, x, y);
  207612. else if (type == 1)
  207613. handleFileDragExit (files);
  207614. else if (type == 2)
  207615. handleFileDragDrop (files, x, y);
  207616. return true;
  207617. }
  207618. bool NSViewComponentPeer::isOpaque()
  207619. {
  207620. if (! getComponent()->isValidComponent())
  207621. return true;
  207622. return getComponent()->isOpaque();
  207623. }
  207624. void NSViewComponentPeer::drawRect (NSRect r)
  207625. {
  207626. if (r.size.width < 1.0f || r.size.height < 1.0f)
  207627. return;
  207628. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  207629. if (! component->isOpaque())
  207630. CGContextClearRect (cg, CGContextGetClipBoundingBox (cg));
  207631. #if USE_COREGRAPHICS_RENDERING
  207632. if (usingCoreGraphics)
  207633. {
  207634. CoreGraphicsContext context (cg, (float) [view frame].size.height);
  207635. insideDrawRect = true;
  207636. handlePaint (context);
  207637. insideDrawRect = false;
  207638. }
  207639. else
  207640. #endif
  207641. {
  207642. Image temp (getComponent()->isOpaque() ? Image::RGB : Image::ARGB,
  207643. (int) (r.size.width + 0.5f),
  207644. (int) (r.size.height + 0.5f),
  207645. ! getComponent()->isOpaque());
  207646. LowLevelGraphicsSoftwareRenderer context (temp);
  207647. context.setOrigin (-roundToInt (r.origin.x),
  207648. -roundToInt ([view frame].size.height - (r.origin.y + r.size.height)));
  207649. const NSRect* rects = 0;
  207650. NSInteger numRects = 0;
  207651. [view getRectsBeingDrawn: &rects count: &numRects];
  207652. RectangleList clip;
  207653. for (int i = 0; i < numRects; ++i)
  207654. {
  207655. clip.addWithoutMerging (Rectangle<int> (roundToInt (rects[i].origin.x),
  207656. roundToInt ([view frame].size.height - (rects[i].origin.y + rects[i].size.height)),
  207657. roundToInt (rects[i].size.width),
  207658. roundToInt (rects[i].size.height)));
  207659. }
  207660. if (context.clipToRectangleList (clip))
  207661. {
  207662. insideDrawRect = true;
  207663. handlePaint (context);
  207664. insideDrawRect = false;
  207665. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  207666. CGImageRef image = CoreGraphicsImage::createImage (temp, false, colourSpace);
  207667. CGColorSpaceRelease (colourSpace);
  207668. CGContextDrawImage (cg, CGRectMake (r.origin.x, r.origin.y, temp.getWidth(), temp.getHeight()), image);
  207669. CGImageRelease (image);
  207670. }
  207671. }
  207672. }
  207673. const StringArray NSViewComponentPeer::getAvailableRenderingEngines() throw()
  207674. {
  207675. StringArray s;
  207676. s.add ("Software Renderer");
  207677. #if USE_COREGRAPHICS_RENDERING
  207678. s.add ("CoreGraphics Renderer");
  207679. #endif
  207680. return s;
  207681. }
  207682. int NSViewComponentPeer::getCurrentRenderingEngine() throw()
  207683. {
  207684. return usingCoreGraphics ? 1 : 0;
  207685. }
  207686. void NSViewComponentPeer::setCurrentRenderingEngine (int index) throw()
  207687. {
  207688. #if USE_COREGRAPHICS_RENDERING
  207689. if (usingCoreGraphics != (index > 0))
  207690. {
  207691. usingCoreGraphics = index > 0;
  207692. [view setNeedsDisplay: true];
  207693. }
  207694. #endif
  207695. }
  207696. bool NSViewComponentPeer::canBecomeKeyWindow()
  207697. {
  207698. return (getStyleFlags() & JUCE_NAMESPACE::ComponentPeer::windowIgnoresKeyPresses) == 0;
  207699. }
  207700. bool NSViewComponentPeer::windowShouldClose()
  207701. {
  207702. if (! isValidPeer (this))
  207703. return YES;
  207704. handleUserClosingWindow();
  207705. return NO;
  207706. }
  207707. void NSViewComponentPeer::redirectMovedOrResized()
  207708. {
  207709. handleMovedOrResized();
  207710. }
  207711. void NSViewComponentPeer::viewMovedToWindow()
  207712. {
  207713. if (isSharedWindow)
  207714. window = [view window];
  207715. }
  207716. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  207717. {
  207718. // Very annoyingly, this function has to use the old SetSystemUIMode function,
  207719. // which is in Carbon.framework. But, because there's no Cocoa equivalent, it
  207720. // is apparently still available in 64-bit apps..
  207721. if (enableOrDisable)
  207722. {
  207723. SetSystemUIMode (kUIModeAllSuppressed, allowMenusAndBars ? kUIOptionAutoShowMenuBar : 0);
  207724. kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));
  207725. }
  207726. else
  207727. {
  207728. SetSystemUIMode (kUIModeNormal, 0);
  207729. }
  207730. }
  207731. class AsyncRepaintMessage : public CallbackMessage
  207732. {
  207733. public:
  207734. NSViewComponentPeer* const peer;
  207735. const Rectangle<int> rect;
  207736. AsyncRepaintMessage (NSViewComponentPeer* const peer_, const Rectangle<int>& rect_)
  207737. : peer (peer_), rect (rect_)
  207738. {
  207739. }
  207740. void messageCallback()
  207741. {
  207742. if (ComponentPeer::isValidPeer (peer))
  207743. peer->repaint (rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
  207744. }
  207745. };
  207746. void NSViewComponentPeer::repaint (int x, int y, int w, int h)
  207747. {
  207748. if (insideDrawRect)
  207749. {
  207750. (new AsyncRepaintMessage (this, Rectangle<int> (x, y, w, h)))->post();
  207751. }
  207752. else
  207753. {
  207754. [view setNeedsDisplayInRect: NSMakeRect ((float) x, (float) ([view frame].size.height - (y + h)),
  207755. (float) w, (float) h)];
  207756. }
  207757. }
  207758. void NSViewComponentPeer::performAnyPendingRepaintsNow()
  207759. {
  207760. [view displayIfNeeded];
  207761. }
  207762. ComponentPeer* Component::createNewPeer (int styleFlags, void* windowToAttachTo)
  207763. {
  207764. return new NSViewComponentPeer (this, styleFlags, (NSView*) windowToAttachTo);
  207765. }
  207766. Image* juce_createIconForFile (const File& file)
  207767. {
  207768. const ScopedAutoReleasePool pool;
  207769. NSImage* image = [[NSWorkspace sharedWorkspace] iconForFile: juceStringToNS (file.getFullPathName())];
  207770. CoreGraphicsImage* result = new CoreGraphicsImage (Image::ARGB, (int) [image size].width, (int) [image size].height, true);
  207771. [NSGraphicsContext saveGraphicsState];
  207772. [NSGraphicsContext setCurrentContext: [NSGraphicsContext graphicsContextWithGraphicsPort: result->context flipped: false]];
  207773. [image drawAtPoint: NSMakePoint (0, 0)
  207774. fromRect: NSMakeRect (0, 0, [image size].width, [image size].height)
  207775. operation: NSCompositeSourceOver fraction: 1.0f];
  207776. [[NSGraphicsContext currentContext] flushGraphics];
  207777. [NSGraphicsContext restoreGraphicsState];
  207778. return result;
  207779. }
  207780. const int KeyPress::spaceKey = ' ';
  207781. const int KeyPress::returnKey = 0x0d;
  207782. const int KeyPress::escapeKey = 0x1b;
  207783. const int KeyPress::backspaceKey = 0x7f;
  207784. const int KeyPress::leftKey = NSLeftArrowFunctionKey;
  207785. const int KeyPress::rightKey = NSRightArrowFunctionKey;
  207786. const int KeyPress::upKey = NSUpArrowFunctionKey;
  207787. const int KeyPress::downKey = NSDownArrowFunctionKey;
  207788. const int KeyPress::pageUpKey = NSPageUpFunctionKey;
  207789. const int KeyPress::pageDownKey = NSPageDownFunctionKey;
  207790. const int KeyPress::endKey = NSEndFunctionKey;
  207791. const int KeyPress::homeKey = NSHomeFunctionKey;
  207792. const int KeyPress::deleteKey = NSDeleteFunctionKey;
  207793. const int KeyPress::insertKey = -1;
  207794. const int KeyPress::tabKey = 9;
  207795. const int KeyPress::F1Key = NSF1FunctionKey;
  207796. const int KeyPress::F2Key = NSF2FunctionKey;
  207797. const int KeyPress::F3Key = NSF3FunctionKey;
  207798. const int KeyPress::F4Key = NSF4FunctionKey;
  207799. const int KeyPress::F5Key = NSF5FunctionKey;
  207800. const int KeyPress::F6Key = NSF6FunctionKey;
  207801. const int KeyPress::F7Key = NSF7FunctionKey;
  207802. const int KeyPress::F8Key = NSF8FunctionKey;
  207803. const int KeyPress::F9Key = NSF9FunctionKey;
  207804. const int KeyPress::F10Key = NSF10FunctionKey;
  207805. const int KeyPress::F11Key = NSF1FunctionKey;
  207806. const int KeyPress::F12Key = NSF12FunctionKey;
  207807. const int KeyPress::F13Key = NSF13FunctionKey;
  207808. const int KeyPress::F14Key = NSF14FunctionKey;
  207809. const int KeyPress::F15Key = NSF15FunctionKey;
  207810. const int KeyPress::F16Key = NSF16FunctionKey;
  207811. const int KeyPress::numberPad0 = 0x30020;
  207812. const int KeyPress::numberPad1 = 0x30021;
  207813. const int KeyPress::numberPad2 = 0x30022;
  207814. const int KeyPress::numberPad3 = 0x30023;
  207815. const int KeyPress::numberPad4 = 0x30024;
  207816. const int KeyPress::numberPad5 = 0x30025;
  207817. const int KeyPress::numberPad6 = 0x30026;
  207818. const int KeyPress::numberPad7 = 0x30027;
  207819. const int KeyPress::numberPad8 = 0x30028;
  207820. const int KeyPress::numberPad9 = 0x30029;
  207821. const int KeyPress::numberPadAdd = 0x3002a;
  207822. const int KeyPress::numberPadSubtract = 0x3002b;
  207823. const int KeyPress::numberPadMultiply = 0x3002c;
  207824. const int KeyPress::numberPadDivide = 0x3002d;
  207825. const int KeyPress::numberPadSeparator = 0x3002e;
  207826. const int KeyPress::numberPadDecimalPoint = 0x3002f;
  207827. const int KeyPress::numberPadEquals = 0x30030;
  207828. const int KeyPress::numberPadDelete = 0x30031;
  207829. const int KeyPress::playKey = 0x30000;
  207830. const int KeyPress::stopKey = 0x30001;
  207831. const int KeyPress::fastForwardKey = 0x30002;
  207832. const int KeyPress::rewindKey = 0x30003;
  207833. #endif
  207834. /*** End of inlined file: juce_mac_NSViewComponentPeer.mm ***/
  207835. /*** Start of inlined file: juce_mac_MouseCursor.mm ***/
  207836. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  207837. // compiled on its own).
  207838. #if JUCE_INCLUDED_FILE
  207839. #if JUCE_MAC
  207840. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  207841. {
  207842. NSImage* im = CoreGraphicsImage::createNSImage (image);
  207843. NSCursor* c = [[NSCursor alloc] initWithImage: im
  207844. hotSpot: NSMakePoint (hotspotX, hotspotY)];
  207845. [im release];
  207846. return (void*) c;
  207847. }
  207848. static void* juce_cursorFromData (const unsigned char* data, const size_t size, float hx, float hy) throw()
  207849. {
  207850. ScopedPointer <Image> im (ImageFileFormat::loadFrom ((const char*) data, (int) size));
  207851. jassert (im != 0);
  207852. if (im == 0)
  207853. return 0;
  207854. return juce_createMouseCursorFromImage (*im,
  207855. (int) (hx * im->getWidth()),
  207856. (int) (hy * im->getHeight()));
  207857. }
  207858. static void* juce_cursorFromWebKitFile (const char* filename, float hx, float hy)
  207859. {
  207860. File f ("/System/Library/Frameworks/WebKit.framework/Frameworks/WebCore.framework/Resources");
  207861. MemoryBlock mb;
  207862. if (f.getChildFile (filename).loadFileAsData (mb))
  207863. return juce_cursorFromData ((const unsigned char*) mb.getData(), mb.getSize(), hx, hy);
  207864. return 0;
  207865. }
  207866. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  207867. {
  207868. const ScopedAutoReleasePool pool;
  207869. NSCursor* c = 0;
  207870. switch (type)
  207871. {
  207872. case MouseCursor::NormalCursor:
  207873. c = [NSCursor arrowCursor];
  207874. break;
  207875. case MouseCursor::NoCursor:
  207876. {
  207877. Image blank (Image::ARGB, 8, 8, true);
  207878. return juce_createMouseCursorFromImage (blank, 0, 0);
  207879. }
  207880. case MouseCursor::DraggingHandCursor:
  207881. c = [NSCursor openHandCursor];
  207882. break;
  207883. case MouseCursor::CopyingCursor:
  207884. return juce_cursorFromWebKitFile ("copyCursor.png", 0, 0);
  207885. case MouseCursor::WaitCursor:
  207886. c = [NSCursor arrowCursor]; // avoid this on the mac, let the OS provide the beachball
  207887. break;
  207888. //return juce_cursorFromWebKitFile ("waitCursor.png", 0.5f, 0.5f);
  207889. case MouseCursor::IBeamCursor:
  207890. c = [NSCursor IBeamCursor];
  207891. break;
  207892. case MouseCursor::PointingHandCursor:
  207893. c = [NSCursor pointingHandCursor];
  207894. break;
  207895. case MouseCursor::LeftRightResizeCursor:
  207896. c = [NSCursor resizeLeftRightCursor];
  207897. break;
  207898. case MouseCursor::LeftEdgeResizeCursor:
  207899. c = [NSCursor resizeLeftCursor];
  207900. break;
  207901. case MouseCursor::RightEdgeResizeCursor:
  207902. c = [NSCursor resizeRightCursor];
  207903. break;
  207904. case MouseCursor::UpDownResizeCursor:
  207905. case MouseCursor::TopEdgeResizeCursor:
  207906. case MouseCursor::BottomEdgeResizeCursor:
  207907. return juce_cursorFromWebKitFile ("northSouthResizeCursor.png", 0.5f, 0.5f);
  207908. case MouseCursor::TopLeftCornerResizeCursor:
  207909. case MouseCursor::BottomRightCornerResizeCursor:
  207910. return juce_cursorFromWebKitFile ("northWestSouthEastResizeCursor.png", 0.5f, 0.5f);
  207911. case MouseCursor::TopRightCornerResizeCursor:
  207912. case MouseCursor::BottomLeftCornerResizeCursor:
  207913. return juce_cursorFromWebKitFile ("northEastSouthWestResizeCursor.png", 0.5f, 0.5f);
  207914. case MouseCursor::UpDownLeftRightResizeCursor:
  207915. return juce_cursorFromWebKitFile ("moveCursor.png", 0.5f, 0.5f);
  207916. case MouseCursor::CrosshairCursor:
  207917. c = [NSCursor crosshairCursor];
  207918. break;
  207919. }
  207920. [c retain];
  207921. return (void*) c;
  207922. }
  207923. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw()
  207924. {
  207925. NSCursor* c = (NSCursor*) cursorHandle;
  207926. [c release];
  207927. }
  207928. void MouseCursor::showInAllWindows() const throw()
  207929. {
  207930. showInWindow (0);
  207931. }
  207932. void MouseCursor::showInWindow (ComponentPeer*) const throw()
  207933. {
  207934. NSCursor* const c = (NSCursor*) getHandle();
  207935. [c set];
  207936. }
  207937. #else
  207938. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw() { return 0; }
  207939. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw() { return 0; }
  207940. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw() {}
  207941. void MouseCursor::showInAllWindows() const throw() {}
  207942. void MouseCursor::showInWindow (ComponentPeer*) const throw() {}
  207943. #endif
  207944. #endif
  207945. /*** End of inlined file: juce_mac_MouseCursor.mm ***/
  207946. /*** Start of inlined file: juce_mac_NSViewComponent.mm ***/
  207947. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  207948. // compiled on its own).
  207949. #if JUCE_INCLUDED_FILE
  207950. class NSViewComponentInternal : public ComponentMovementWatcher
  207951. {
  207952. Component* const owner;
  207953. NSViewComponentPeer* currentPeer;
  207954. bool wasShowing;
  207955. public:
  207956. NSView* const view;
  207957. NSViewComponentInternal (NSView* const view_, Component* const owner_)
  207958. : ComponentMovementWatcher (owner_),
  207959. owner (owner_),
  207960. currentPeer (0),
  207961. wasShowing (false),
  207962. view (view_)
  207963. {
  207964. [view_ retain];
  207965. if (owner_->isShowing())
  207966. componentPeerChanged();
  207967. }
  207968. ~NSViewComponentInternal()
  207969. {
  207970. [view removeFromSuperview];
  207971. [view release];
  207972. }
  207973. void componentMovedOrResized (Component& comp, bool wasMoved, bool wasResized)
  207974. {
  207975. ComponentMovementWatcher::componentMovedOrResized (comp, wasMoved, wasResized);
  207976. // The ComponentMovementWatcher version of this method avoids calling
  207977. // us when the top-level comp is resized, but for an NSView we need to know this
  207978. // because with inverted co-ords, we need to update the position even if the
  207979. // top-left pos hasn't changed
  207980. if (comp.isOnDesktop() && wasResized)
  207981. componentMovedOrResized (wasMoved, wasResized);
  207982. }
  207983. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  207984. {
  207985. Component* const topComp = owner->getTopLevelComponent();
  207986. if (topComp->getPeer() != 0)
  207987. {
  207988. int x = 0, y = 0;
  207989. owner->relativePositionToOtherComponent (topComp, x, y);
  207990. NSRect r;
  207991. r.origin.x = (float) x;
  207992. r.origin.y = (float) y;
  207993. r.size.width = (float) owner->getWidth();
  207994. r.size.height = (float) owner->getHeight();
  207995. r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  207996. [view setFrame: r];
  207997. }
  207998. }
  207999. void componentPeerChanged()
  208000. {
  208001. NSViewComponentPeer* const peer = dynamic_cast <NSViewComponentPeer*> (owner->getPeer());
  208002. if (currentPeer != peer)
  208003. {
  208004. [view removeFromSuperview];
  208005. currentPeer = peer;
  208006. if (peer != 0)
  208007. {
  208008. [peer->view addSubview: view];
  208009. componentMovedOrResized (false, false);
  208010. }
  208011. }
  208012. [view setHidden: ! owner->isShowing()];
  208013. }
  208014. void componentVisibilityChanged (Component&)
  208015. {
  208016. componentPeerChanged();
  208017. }
  208018. juce_UseDebuggingNewOperator
  208019. private:
  208020. NSViewComponentInternal (const NSViewComponentInternal&);
  208021. const NSViewComponentInternal& operator= (const NSViewComponentInternal&);
  208022. };
  208023. NSViewComponent::NSViewComponent()
  208024. {
  208025. }
  208026. NSViewComponent::~NSViewComponent()
  208027. {
  208028. }
  208029. void NSViewComponent::setView (void* view)
  208030. {
  208031. if (view != getView())
  208032. {
  208033. if (view != 0)
  208034. info = new NSViewComponentInternal ((NSView*) view, this);
  208035. else
  208036. info = 0;
  208037. }
  208038. }
  208039. void* NSViewComponent::getView() const
  208040. {
  208041. return info == 0 ? 0 : info->view;
  208042. }
  208043. void NSViewComponent::paint (Graphics& g)
  208044. {
  208045. }
  208046. #endif
  208047. /*** End of inlined file: juce_mac_NSViewComponent.mm ***/
  208048. /*** Start of inlined file: juce_mac_AppleRemote.mm ***/
  208049. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208050. // compiled on its own).
  208051. #if JUCE_INCLUDED_FILE
  208052. AppleRemoteDevice::AppleRemoteDevice()
  208053. : device (0),
  208054. queue (0),
  208055. remoteId (0)
  208056. {
  208057. }
  208058. AppleRemoteDevice::~AppleRemoteDevice()
  208059. {
  208060. stop();
  208061. }
  208062. static io_object_t getAppleRemoteDevice()
  208063. {
  208064. CFMutableDictionaryRef dict = IOServiceMatching ("AppleIRController");
  208065. io_iterator_t iter = 0;
  208066. io_object_t iod = 0;
  208067. if (IOServiceGetMatchingServices (kIOMasterPortDefault, dict, &iter) == kIOReturnSuccess
  208068. && iter != 0)
  208069. {
  208070. iod = IOIteratorNext (iter);
  208071. }
  208072. IOObjectRelease (iter);
  208073. return iod;
  208074. }
  208075. static bool createAppleRemoteInterface (io_object_t iod, void** device)
  208076. {
  208077. jassert (*device == 0);
  208078. io_name_t classname;
  208079. if (IOObjectGetClass (iod, classname) == kIOReturnSuccess)
  208080. {
  208081. IOCFPlugInInterface** cfPlugInInterface = 0;
  208082. SInt32 score = 0;
  208083. if (IOCreatePlugInInterfaceForService (iod,
  208084. kIOHIDDeviceUserClientTypeID,
  208085. kIOCFPlugInInterfaceID,
  208086. &cfPlugInInterface,
  208087. &score) == kIOReturnSuccess)
  208088. {
  208089. HRESULT hr = (*cfPlugInInterface)->QueryInterface (cfPlugInInterface,
  208090. CFUUIDGetUUIDBytes (kIOHIDDeviceInterfaceID),
  208091. device);
  208092. (void) hr;
  208093. (*cfPlugInInterface)->Release (cfPlugInInterface);
  208094. }
  208095. }
  208096. return *device != 0;
  208097. }
  208098. bool AppleRemoteDevice::start (const bool inExclusiveMode)
  208099. {
  208100. if (queue != 0)
  208101. return true;
  208102. stop();
  208103. bool result = false;
  208104. io_object_t iod = getAppleRemoteDevice();
  208105. if (iod != 0)
  208106. {
  208107. if (createAppleRemoteInterface (iod, &device) && open (inExclusiveMode))
  208108. result = true;
  208109. else
  208110. stop();
  208111. IOObjectRelease (iod);
  208112. }
  208113. return result;
  208114. }
  208115. void AppleRemoteDevice::stop()
  208116. {
  208117. if (queue != 0)
  208118. {
  208119. (*(IOHIDQueueInterface**) queue)->stop ((IOHIDQueueInterface**) queue);
  208120. (*(IOHIDQueueInterface**) queue)->dispose ((IOHIDQueueInterface**) queue);
  208121. (*(IOHIDQueueInterface**) queue)->Release ((IOHIDQueueInterface**) queue);
  208122. queue = 0;
  208123. }
  208124. if (device != 0)
  208125. {
  208126. (*(IOHIDDeviceInterface**) device)->close ((IOHIDDeviceInterface**) device);
  208127. (*(IOHIDDeviceInterface**) device)->Release ((IOHIDDeviceInterface**) device);
  208128. device = 0;
  208129. }
  208130. }
  208131. bool AppleRemoteDevice::isActive() const
  208132. {
  208133. return queue != 0;
  208134. }
  208135. static void appleRemoteQueueCallback (void* const target, const IOReturn result, void*, void*)
  208136. {
  208137. if (result == kIOReturnSuccess)
  208138. ((AppleRemoteDevice*) target)->handleCallbackInternal();
  208139. }
  208140. bool AppleRemoteDevice::open (const bool openInExclusiveMode)
  208141. {
  208142. Array <int> cookies;
  208143. CFArrayRef elements;
  208144. IOHIDDeviceInterface122** const device122 = (IOHIDDeviceInterface122**) device;
  208145. if ((*device122)->copyMatchingElements (device122, 0, &elements) != kIOReturnSuccess)
  208146. return false;
  208147. for (int i = 0; i < CFArrayGetCount (elements); ++i)
  208148. {
  208149. CFDictionaryRef element = (CFDictionaryRef) CFArrayGetValueAtIndex (elements, i);
  208150. // get the cookie
  208151. CFTypeRef object = CFDictionaryGetValue (element, CFSTR (kIOHIDElementCookieKey));
  208152. if (object == 0 || CFGetTypeID (object) != CFNumberGetTypeID())
  208153. continue;
  208154. long number;
  208155. if (! CFNumberGetValue ((CFNumberRef) object, kCFNumberLongType, &number))
  208156. continue;
  208157. cookies.add ((int) number);
  208158. }
  208159. CFRelease (elements);
  208160. if ((*(IOHIDDeviceInterface**) device)
  208161. ->open ((IOHIDDeviceInterface**) device,
  208162. openInExclusiveMode ? kIOHIDOptionsTypeSeizeDevice
  208163. : kIOHIDOptionsTypeNone) == KERN_SUCCESS)
  208164. {
  208165. queue = (*(IOHIDDeviceInterface**) device)->allocQueue ((IOHIDDeviceInterface**) device);
  208166. if (queue != 0)
  208167. {
  208168. (*(IOHIDQueueInterface**) queue)->create ((IOHIDQueueInterface**) queue, 0, 12);
  208169. for (int i = 0; i < cookies.size(); ++i)
  208170. {
  208171. IOHIDElementCookie cookie = (IOHIDElementCookie) cookies.getUnchecked(i);
  208172. (*(IOHIDQueueInterface**) queue)->addElement ((IOHIDQueueInterface**) queue, cookie, 0);
  208173. }
  208174. CFRunLoopSourceRef eventSource;
  208175. if ((*(IOHIDQueueInterface**) queue)
  208176. ->createAsyncEventSource ((IOHIDQueueInterface**) queue, &eventSource) == KERN_SUCCESS)
  208177. {
  208178. if ((*(IOHIDQueueInterface**) queue)->setEventCallout ((IOHIDQueueInterface**) queue,
  208179. appleRemoteQueueCallback, this, 0) == KERN_SUCCESS)
  208180. {
  208181. CFRunLoopAddSource (CFRunLoopGetCurrent(), eventSource, kCFRunLoopDefaultMode);
  208182. (*(IOHIDQueueInterface**) queue)->start ((IOHIDQueueInterface**) queue);
  208183. return true;
  208184. }
  208185. }
  208186. }
  208187. }
  208188. return false;
  208189. }
  208190. void AppleRemoteDevice::handleCallbackInternal()
  208191. {
  208192. int totalValues = 0;
  208193. AbsoluteTime nullTime = { 0, 0 };
  208194. char cookies [12];
  208195. int numCookies = 0;
  208196. while (numCookies < numElementsInArray (cookies))
  208197. {
  208198. IOHIDEventStruct e;
  208199. if ((*(IOHIDQueueInterface**) queue)->getNextEvent ((IOHIDQueueInterface**) queue, &e, nullTime, 0) != kIOReturnSuccess)
  208200. break;
  208201. if ((int) e.elementCookie == 19)
  208202. {
  208203. remoteId = e.value;
  208204. buttonPressed (switched, false);
  208205. }
  208206. else
  208207. {
  208208. totalValues += e.value;
  208209. cookies [numCookies++] = (char) (pointer_sized_int) e.elementCookie;
  208210. }
  208211. }
  208212. cookies [numCookies++] = 0;
  208213. //DBG (String::toHexString ((uint8*) cookies, numCookies, 1) + " " + String (totalValues));
  208214. static const char buttonPatterns[] =
  208215. {
  208216. 0x1f, 0x14, 0x12, 0x1f, 0x14, 0x12, 0,
  208217. 0x1f, 0x15, 0x12, 0x1f, 0x15, 0x12, 0,
  208218. 0x1f, 0x1d, 0x1c, 0x12, 0,
  208219. 0x1f, 0x1e, 0x1c, 0x12, 0,
  208220. 0x1f, 0x16, 0x12, 0x1f, 0x16, 0x12, 0,
  208221. 0x1f, 0x17, 0x12, 0x1f, 0x17, 0x12, 0,
  208222. 0x1f, 0x12, 0x04, 0x02, 0,
  208223. 0x1f, 0x12, 0x03, 0x02, 0,
  208224. 0x1f, 0x12, 0x1f, 0x12, 0,
  208225. 0x23, 0x1f, 0x12, 0x23, 0x1f, 0x12, 0,
  208226. 19, 0
  208227. };
  208228. int buttonNum = (int) menuButton;
  208229. int i = 0;
  208230. while (i < numElementsInArray (buttonPatterns))
  208231. {
  208232. if (strcmp (cookies, buttonPatterns + i) == 0)
  208233. {
  208234. buttonPressed ((ButtonType) buttonNum, totalValues > 0);
  208235. break;
  208236. }
  208237. i += (int) strlen (buttonPatterns + i) + 1;
  208238. ++buttonNum;
  208239. }
  208240. }
  208241. #endif
  208242. /*** End of inlined file: juce_mac_AppleRemote.mm ***/
  208243. /*** Start of inlined file: juce_mac_OpenGLComponent.mm ***/
  208244. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208245. // compiled on its own).
  208246. #if JUCE_INCLUDED_FILE && JUCE_OPENGL
  208247. #if JUCE_MAC
  208248. END_JUCE_NAMESPACE
  208249. #define ThreadSafeNSOpenGLView MakeObjCClassName(ThreadSafeNSOpenGLView)
  208250. @interface ThreadSafeNSOpenGLView : NSOpenGLView
  208251. {
  208252. CriticalSection* contextLock;
  208253. bool needsUpdate;
  208254. }
  208255. - (id) initWithFrame: (NSRect) frameRect pixelFormat: (NSOpenGLPixelFormat*) format;
  208256. - (bool) makeActive;
  208257. - (void) makeInactive;
  208258. - (void) reshape;
  208259. @end
  208260. @implementation ThreadSafeNSOpenGLView
  208261. - (id) initWithFrame: (NSRect) frameRect
  208262. pixelFormat: (NSOpenGLPixelFormat*) format
  208263. {
  208264. contextLock = new CriticalSection();
  208265. self = [super initWithFrame: frameRect pixelFormat: format];
  208266. if (self != nil)
  208267. [[NSNotificationCenter defaultCenter] addObserver: self
  208268. selector: @selector (_surfaceNeedsUpdate:)
  208269. name: NSViewGlobalFrameDidChangeNotification
  208270. object: self];
  208271. return self;
  208272. }
  208273. - (void) dealloc
  208274. {
  208275. [[NSNotificationCenter defaultCenter] removeObserver: self];
  208276. delete contextLock;
  208277. [super dealloc];
  208278. }
  208279. - (bool) makeActive
  208280. {
  208281. const ScopedLock sl (*contextLock);
  208282. if ([self openGLContext] == 0)
  208283. return false;
  208284. [[self openGLContext] makeCurrentContext];
  208285. if (needsUpdate)
  208286. {
  208287. [super update];
  208288. needsUpdate = false;
  208289. }
  208290. return true;
  208291. }
  208292. - (void) makeInactive
  208293. {
  208294. const ScopedLock sl (*contextLock);
  208295. [NSOpenGLContext clearCurrentContext];
  208296. }
  208297. - (void) _surfaceNeedsUpdate: (NSNotification*) notification
  208298. {
  208299. const ScopedLock sl (*contextLock);
  208300. needsUpdate = true;
  208301. }
  208302. - (void) update
  208303. {
  208304. const ScopedLock sl (*contextLock);
  208305. needsUpdate = true;
  208306. }
  208307. - (void) reshape
  208308. {
  208309. const ScopedLock sl (*contextLock);
  208310. needsUpdate = true;
  208311. }
  208312. @end
  208313. BEGIN_JUCE_NAMESPACE
  208314. class WindowedGLContext : public OpenGLContext
  208315. {
  208316. public:
  208317. WindowedGLContext (Component* const component,
  208318. const OpenGLPixelFormat& pixelFormat_,
  208319. NSOpenGLContext* sharedContext)
  208320. : renderContext (0),
  208321. pixelFormat (pixelFormat_)
  208322. {
  208323. jassert (component != 0);
  208324. NSOpenGLPixelFormatAttribute attribs [64];
  208325. int n = 0;
  208326. attribs[n++] = NSOpenGLPFADoubleBuffer;
  208327. attribs[n++] = NSOpenGLPFAAccelerated;
  208328. attribs[n++] = NSOpenGLPFAMPSafe; // NSOpenGLPFAAccelerated, NSOpenGLPFAMultiScreen, NSOpenGLPFASingleRenderer
  208329. attribs[n++] = NSOpenGLPFAColorSize;
  208330. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.redBits,
  208331. pixelFormat.greenBits,
  208332. pixelFormat.blueBits);
  208333. attribs[n++] = NSOpenGLPFAAlphaSize;
  208334. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.alphaBits;
  208335. attribs[n++] = NSOpenGLPFADepthSize;
  208336. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.depthBufferBits;
  208337. attribs[n++] = NSOpenGLPFAStencilSize;
  208338. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.stencilBufferBits;
  208339. attribs[n++] = NSOpenGLPFAAccumSize;
  208340. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.accumulationBufferRedBits,
  208341. pixelFormat.accumulationBufferGreenBits,
  208342. pixelFormat.accumulationBufferBlueBits,
  208343. pixelFormat.accumulationBufferAlphaBits);
  208344. // xxx not sure how to do fullSceneAntiAliasingNumSamples..
  208345. attribs[n++] = NSOpenGLPFASampleBuffers;
  208346. attribs[n++] = (NSOpenGLPixelFormatAttribute) 1;
  208347. attribs[n++] = NSOpenGLPFAClosestPolicy;
  208348. attribs[n++] = NSOpenGLPFANoRecovery;
  208349. attribs[n++] = (NSOpenGLPixelFormatAttribute) 0;
  208350. NSOpenGLPixelFormat* format
  208351. = [[NSOpenGLPixelFormat alloc] initWithAttributes: attribs];
  208352. view = [[ThreadSafeNSOpenGLView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  208353. pixelFormat: format];
  208354. renderContext = [[[NSOpenGLContext alloc] initWithFormat: format
  208355. shareContext: sharedContext] autorelease];
  208356. const GLint swapInterval = 1;
  208357. [renderContext setValues: &swapInterval forParameter: NSOpenGLCPSwapInterval];
  208358. [view setOpenGLContext: renderContext];
  208359. [renderContext setView: view];
  208360. [format release];
  208361. viewHolder = new NSViewComponentInternal (view, component);
  208362. }
  208363. ~WindowedGLContext()
  208364. {
  208365. makeInactive();
  208366. [renderContext clearDrawable];
  208367. viewHolder = 0;
  208368. }
  208369. bool makeActive() const throw()
  208370. {
  208371. jassert (renderContext != 0);
  208372. [view makeActive];
  208373. return isActive();
  208374. }
  208375. bool makeInactive() const throw()
  208376. {
  208377. [view makeInactive];
  208378. return true;
  208379. }
  208380. bool isActive() const throw()
  208381. {
  208382. return [NSOpenGLContext currentContext] == renderContext;
  208383. }
  208384. const OpenGLPixelFormat getPixelFormat() const { return pixelFormat; }
  208385. void* getRawContext() const throw() { return renderContext; }
  208386. void updateWindowPosition (int x, int y, int w, int h, int outerWindowHeight)
  208387. {
  208388. }
  208389. void swapBuffers()
  208390. {
  208391. [renderContext flushBuffer];
  208392. }
  208393. bool setSwapInterval (const int numFramesPerSwap)
  208394. {
  208395. [renderContext setValues: (const GLint*) &numFramesPerSwap
  208396. forParameter: NSOpenGLCPSwapInterval];
  208397. return true;
  208398. }
  208399. int getSwapInterval() const
  208400. {
  208401. GLint numFrames = 0;
  208402. [renderContext getValues: &numFrames
  208403. forParameter: NSOpenGLCPSwapInterval];
  208404. return numFrames;
  208405. }
  208406. void repaint()
  208407. {
  208408. // we need to invalidate the juce view that holds this gl view, to make it
  208409. // cause a repaint callback
  208410. NSView* v = (NSView*) viewHolder->view;
  208411. NSRect r = [v frame];
  208412. // bit of a bodge here.. if we only invalidate the area of the gl component,
  208413. // it's completely covered by the NSOpenGLView, so the OS throws away the
  208414. // repaint message, thus never causing our paint() callback, and never repainting
  208415. // the comp. So invalidating just a little bit around the edge helps..
  208416. [[v superview] setNeedsDisplayInRect: NSInsetRect (r, -2.0f, -2.0f)];
  208417. }
  208418. void* getNativeWindowHandle() const { return viewHolder->view; }
  208419. juce_UseDebuggingNewOperator
  208420. NSOpenGLContext* renderContext;
  208421. ThreadSafeNSOpenGLView* view;
  208422. private:
  208423. OpenGLPixelFormat pixelFormat;
  208424. ScopedPointer <NSViewComponentInternal> viewHolder;
  208425. WindowedGLContext (const WindowedGLContext&);
  208426. const WindowedGLContext& operator= (const WindowedGLContext&);
  208427. };
  208428. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  208429. const OpenGLPixelFormat& pixelFormat,
  208430. const OpenGLContext* const contextToShareWith)
  208431. {
  208432. ScopedPointer <WindowedGLContext> c (new WindowedGLContext (component, pixelFormat,
  208433. contextToShareWith != 0 ? (NSOpenGLContext*) contextToShareWith->getRawContext() : 0));
  208434. return (c->renderContext != 0) ? c.release() : 0;
  208435. }
  208436. void* OpenGLComponent::getNativeWindowHandle() const
  208437. {
  208438. return context != 0 ? ((WindowedGLContext*) context)->getNativeWindowHandle()
  208439. : 0;
  208440. }
  208441. void juce_glViewport (const int w, const int h)
  208442. {
  208443. glViewport (0, 0, w, h);
  208444. }
  208445. void OpenGLPixelFormat::getAvailablePixelFormats (Component* /*component*/,
  208446. OwnedArray <OpenGLPixelFormat>& results)
  208447. {
  208448. /* GLint attribs [64];
  208449. int n = 0;
  208450. attribs[n++] = AGL_RGBA;
  208451. attribs[n++] = AGL_DOUBLEBUFFER;
  208452. attribs[n++] = AGL_ACCELERATED;
  208453. attribs[n++] = AGL_NO_RECOVERY;
  208454. attribs[n++] = AGL_NONE;
  208455. AGLPixelFormat p = aglChoosePixelFormat (0, 0, attribs);
  208456. while (p != 0)
  208457. {
  208458. OpenGLPixelFormat* const pf = new OpenGLPixelFormat();
  208459. pf->redBits = getAGLAttribute (p, AGL_RED_SIZE);
  208460. pf->greenBits = getAGLAttribute (p, AGL_GREEN_SIZE);
  208461. pf->blueBits = getAGLAttribute (p, AGL_BLUE_SIZE);
  208462. pf->alphaBits = getAGLAttribute (p, AGL_ALPHA_SIZE);
  208463. pf->depthBufferBits = getAGLAttribute (p, AGL_DEPTH_SIZE);
  208464. pf->stencilBufferBits = getAGLAttribute (p, AGL_STENCIL_SIZE);
  208465. pf->accumulationBufferRedBits = getAGLAttribute (p, AGL_ACCUM_RED_SIZE);
  208466. pf->accumulationBufferGreenBits = getAGLAttribute (p, AGL_ACCUM_GREEN_SIZE);
  208467. pf->accumulationBufferBlueBits = getAGLAttribute (p, AGL_ACCUM_BLUE_SIZE);
  208468. pf->accumulationBufferAlphaBits = getAGLAttribute (p, AGL_ACCUM_ALPHA_SIZE);
  208469. results.add (pf);
  208470. p = aglNextPixelFormat (p);
  208471. }*/
  208472. //jassertfalse //xxx can't see how you do this in cocoa!
  208473. }
  208474. #else
  208475. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  208476. const OpenGLPixelFormat& pixelFormat,
  208477. const OpenGLContext* const contextToShareWith)
  208478. {
  208479. return 0;
  208480. }
  208481. void juce_glViewport (const int w, const int h)
  208482. {
  208483. //glViewport (0, 0, w, h);
  208484. }
  208485. #endif
  208486. #endif
  208487. /*** End of inlined file: juce_mac_OpenGLComponent.mm ***/
  208488. /*** Start of inlined file: juce_mac_MainMenu.mm ***/
  208489. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208490. // compiled on its own).
  208491. #if JUCE_INCLUDED_FILE
  208492. class JuceMainMenuHandler;
  208493. END_JUCE_NAMESPACE
  208494. using namespace JUCE_NAMESPACE;
  208495. #define JuceMenuCallback MakeObjCClassName(JuceMenuCallback)
  208496. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  208497. @interface JuceMenuCallback : NSObject <NSMenuDelegate>
  208498. #else
  208499. @interface JuceMenuCallback : NSObject
  208500. #endif
  208501. {
  208502. JuceMainMenuHandler* owner;
  208503. }
  208504. - (JuceMenuCallback*) initWithOwner: (JuceMainMenuHandler*) owner_;
  208505. - (void) dealloc;
  208506. - (void) menuItemInvoked: (id) menu;
  208507. - (void) menuNeedsUpdate: (NSMenu*) menu;
  208508. @end
  208509. BEGIN_JUCE_NAMESPACE
  208510. class JuceMainMenuHandler : private MenuBarModelListener,
  208511. private DeletedAtShutdown
  208512. {
  208513. public:
  208514. static JuceMainMenuHandler* instance;
  208515. JuceMainMenuHandler()
  208516. : currentModel (0),
  208517. lastUpdateTime (0)
  208518. {
  208519. callback = [[JuceMenuCallback alloc] initWithOwner: this];
  208520. }
  208521. ~JuceMainMenuHandler()
  208522. {
  208523. setMenu (0);
  208524. jassert (instance == this);
  208525. instance = 0;
  208526. [callback release];
  208527. }
  208528. void setMenu (MenuBarModel* const newMenuBarModel)
  208529. {
  208530. if (currentModel != newMenuBarModel)
  208531. {
  208532. if (currentModel != 0)
  208533. currentModel->removeListener (this);
  208534. currentModel = newMenuBarModel;
  208535. if (currentModel != 0)
  208536. currentModel->addListener (this);
  208537. menuBarItemsChanged (0);
  208538. }
  208539. }
  208540. void addSubMenu (NSMenu* parent, const PopupMenu& child,
  208541. const String& name, const int menuId, const int tag)
  208542. {
  208543. NSMenuItem* item = [parent addItemWithTitle: juceStringToNS (name)
  208544. action: nil
  208545. keyEquivalent: @""];
  208546. [item setTag: tag];
  208547. NSMenu* sub = createMenu (child, name, menuId, tag);
  208548. [parent setSubmenu: sub forItem: item];
  208549. [sub setAutoenablesItems: false];
  208550. [sub release];
  208551. }
  208552. void updateSubMenu (NSMenuItem* parentItem, const PopupMenu& menuToCopy,
  208553. const String& name, const int menuId, const int tag)
  208554. {
  208555. [parentItem setTag: tag];
  208556. NSMenu* menu = [parentItem submenu];
  208557. [menu setTitle: juceStringToNS (name)];
  208558. while ([menu numberOfItems] > 0)
  208559. [menu removeItemAtIndex: 0];
  208560. PopupMenu::MenuItemIterator iter (menuToCopy);
  208561. while (iter.next())
  208562. addMenuItem (iter, menu, menuId, tag);
  208563. [menu setAutoenablesItems: false];
  208564. [menu update];
  208565. }
  208566. void menuBarItemsChanged (MenuBarModel*)
  208567. {
  208568. lastUpdateTime = Time::getMillisecondCounter();
  208569. StringArray menuNames;
  208570. if (currentModel != 0)
  208571. menuNames = currentModel->getMenuBarNames();
  208572. NSMenu* menuBar = [NSApp mainMenu];
  208573. while ([menuBar numberOfItems] > 1 + menuNames.size())
  208574. [menuBar removeItemAtIndex: [menuBar numberOfItems] - 1];
  208575. int menuId = 1;
  208576. for (int i = 0; i < menuNames.size(); ++i)
  208577. {
  208578. const PopupMenu menu (currentModel->getMenuForIndex (i, menuNames [i]));
  208579. if (i >= [menuBar numberOfItems] - 1)
  208580. addSubMenu (menuBar, menu, menuNames[i], menuId, i);
  208581. else
  208582. updateSubMenu ([menuBar itemAtIndex: 1 + i], menu, menuNames[i], menuId, i);
  208583. }
  208584. }
  208585. static void flashMenuBar (NSMenu* menu)
  208586. {
  208587. [menu retain];
  208588. const unichar f35Key = NSF35FunctionKey;
  208589. NSString* f35String = [NSString stringWithCharacters: &f35Key length: 1];
  208590. NSMenuItem* item = [[NSMenuItem alloc] initWithTitle: @"x"
  208591. action: nil
  208592. keyEquivalent: f35String];
  208593. [item setTarget: nil];
  208594. [menu insertItem: item atIndex: [menu numberOfItems]];
  208595. [item release];
  208596. NSEvent* f35Event = [NSEvent keyEventWithType: NSKeyDown
  208597. location: NSZeroPoint
  208598. modifierFlags: NSCommandKeyMask
  208599. timestamp: 0
  208600. windowNumber: 0
  208601. context: [NSGraphicsContext currentContext]
  208602. characters: f35String
  208603. charactersIgnoringModifiers: f35String
  208604. isARepeat: NO
  208605. keyCode: 0];
  208606. [menu performKeyEquivalent: f35Event];
  208607. if ([menu indexOfItem: item] >= 0)
  208608. [menu removeItem: item]; // (this throws if the item isn't actually in the menu)
  208609. [menu release];
  208610. }
  208611. static NSMenuItem* findMenuItem (NSMenu* const menu, const ApplicationCommandTarget::InvocationInfo& info)
  208612. {
  208613. for (NSInteger i = [menu numberOfItems]; --i >= 0;)
  208614. {
  208615. NSMenuItem* m = [menu itemAtIndex: i];
  208616. if ([m tag] == info.commandID)
  208617. return m;
  208618. if ([m submenu] != 0)
  208619. {
  208620. NSMenuItem* found = findMenuItem ([m submenu], info);
  208621. if (found != 0)
  208622. return found;
  208623. }
  208624. }
  208625. return 0;
  208626. }
  208627. void menuCommandInvoked (MenuBarModel*, const ApplicationCommandTarget::InvocationInfo& info)
  208628. {
  208629. NSMenuItem* item = findMenuItem ([NSApp mainMenu], info);
  208630. if (item != 0)
  208631. flashMenuBar ([item menu]);
  208632. }
  208633. void updateMenus()
  208634. {
  208635. if (Time::getMillisecondCounter() > lastUpdateTime + 500)
  208636. menuBarItemsChanged (0);
  208637. }
  208638. void invoke (const int commandId, ApplicationCommandManager* const commandManager, const int topLevelIndex) const
  208639. {
  208640. if (currentModel != 0)
  208641. {
  208642. if (commandManager != 0)
  208643. {
  208644. ApplicationCommandTarget::InvocationInfo info (commandId);
  208645. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  208646. commandManager->invoke (info, true);
  208647. }
  208648. currentModel->menuItemSelected (commandId, topLevelIndex);
  208649. }
  208650. }
  208651. MenuBarModel* currentModel;
  208652. uint32 lastUpdateTime;
  208653. void addMenuItem (PopupMenu::MenuItemIterator& iter, NSMenu* menuToAddTo,
  208654. const int topLevelMenuId, const int topLevelIndex)
  208655. {
  208656. NSString* text = juceStringToNS (iter.itemName.upToFirstOccurrenceOf (T("<end>"), false, true));
  208657. if (text == 0)
  208658. text = @"";
  208659. if (iter.isSeparator)
  208660. {
  208661. [menuToAddTo addItem: [NSMenuItem separatorItem]];
  208662. }
  208663. else if (iter.isSectionHeader)
  208664. {
  208665. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  208666. action: nil
  208667. keyEquivalent: @""];
  208668. [item setEnabled: false];
  208669. }
  208670. else if (iter.subMenu != 0)
  208671. {
  208672. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  208673. action: nil
  208674. keyEquivalent: @""];
  208675. [item setTag: iter.itemId];
  208676. [item setEnabled: iter.isEnabled];
  208677. NSMenu* sub = createMenu (*iter.subMenu, iter.itemName, topLevelMenuId, topLevelIndex);
  208678. [sub setDelegate: nil];
  208679. [menuToAddTo setSubmenu: sub forItem: item];
  208680. [sub release];
  208681. }
  208682. else
  208683. {
  208684. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  208685. action: @selector (menuItemInvoked:)
  208686. keyEquivalent: @""];
  208687. [item setTag: iter.itemId];
  208688. [item setEnabled: iter.isEnabled];
  208689. [item setState: iter.isTicked ? NSOnState : NSOffState];
  208690. [item setTarget: (id) callback];
  208691. NSMutableArray* info = [NSMutableArray arrayWithObject: [NSNumber numberWithUnsignedLongLong: (pointer_sized_int) (void*) iter.commandManager]];
  208692. [info addObject: [NSNumber numberWithInt: topLevelIndex]];
  208693. [item setRepresentedObject: info];
  208694. if (iter.commandManager != 0)
  208695. {
  208696. const Array <KeyPress> keyPresses (iter.commandManager->getKeyMappings()
  208697. ->getKeyPressesAssignedToCommand (iter.itemId));
  208698. if (keyPresses.size() > 0)
  208699. {
  208700. const KeyPress& kp = keyPresses.getReference(0);
  208701. juce_wchar key = kp.getTextCharacter();
  208702. if (kp.getKeyCode() == KeyPress::backspaceKey)
  208703. key = NSBackspaceCharacter;
  208704. else if (kp.getKeyCode() == KeyPress::deleteKey)
  208705. key = NSDeleteCharacter;
  208706. else if (key == 0)
  208707. key = (juce_wchar) kp.getKeyCode();
  208708. unsigned int mods = 0;
  208709. if (kp.getModifiers().isShiftDown())
  208710. mods |= NSShiftKeyMask;
  208711. if (kp.getModifiers().isCtrlDown())
  208712. mods |= NSControlKeyMask;
  208713. if (kp.getModifiers().isAltDown())
  208714. mods |= NSAlternateKeyMask;
  208715. if (kp.getModifiers().isCommandDown())
  208716. mods |= NSCommandKeyMask;
  208717. [item setKeyEquivalent: juceStringToNS (String::charToString (key))];
  208718. [item setKeyEquivalentModifierMask: mods];
  208719. }
  208720. }
  208721. }
  208722. }
  208723. JuceMenuCallback* callback;
  208724. private:
  208725. NSMenu* createMenu (const PopupMenu menu,
  208726. const String& menuName,
  208727. const int topLevelMenuId,
  208728. const int topLevelIndex)
  208729. {
  208730. NSMenu* m = [[NSMenu alloc] initWithTitle: juceStringToNS (menuName)];
  208731. [m setAutoenablesItems: false];
  208732. [m setDelegate: callback];
  208733. PopupMenu::MenuItemIterator iter (menu);
  208734. while (iter.next())
  208735. addMenuItem (iter, m, topLevelMenuId, topLevelIndex);
  208736. [m update];
  208737. return m;
  208738. }
  208739. };
  208740. JuceMainMenuHandler* JuceMainMenuHandler::instance = 0;
  208741. END_JUCE_NAMESPACE
  208742. @implementation JuceMenuCallback
  208743. - (JuceMenuCallback*) initWithOwner: (JuceMainMenuHandler*) owner_
  208744. {
  208745. [super init];
  208746. owner = owner_;
  208747. return self;
  208748. }
  208749. - (void) dealloc
  208750. {
  208751. [super dealloc];
  208752. }
  208753. - (void) menuItemInvoked: (id) menu
  208754. {
  208755. NSMenuItem* item = (NSMenuItem*) menu;
  208756. if ([[item representedObject] isKindOfClass: [NSArray class]])
  208757. {
  208758. // 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
  208759. // our own components, which may have wanted to intercept it. So, rather than dispatching directly, we'll feed it back
  208760. // into the focused component and let it trigger the menu item indirectly.
  208761. NSEvent* e = [NSApp currentEvent];
  208762. if ([e type] == NSKeyDown || [e type] == NSKeyUp)
  208763. {
  208764. if (JUCE_NAMESPACE::Component::getCurrentlyFocusedComponent()->isValidComponent())
  208765. {
  208766. JUCE_NAMESPACE::NSViewComponentPeer* peer = dynamic_cast <JUCE_NAMESPACE::NSViewComponentPeer*> (JUCE_NAMESPACE::Component::getCurrentlyFocusedComponent()->getPeer());
  208767. if (peer != 0)
  208768. {
  208769. if ([e type] == NSKeyDown)
  208770. peer->redirectKeyDown (e);
  208771. else
  208772. peer->redirectKeyUp (e);
  208773. return;
  208774. }
  208775. }
  208776. }
  208777. NSArray* info = (NSArray*) [item representedObject];
  208778. owner->invoke ((int) [item tag],
  208779. (ApplicationCommandManager*) (pointer_sized_int)
  208780. [((NSNumber*) [info objectAtIndex: 0]) unsignedLongLongValue],
  208781. (int) [((NSNumber*) [info objectAtIndex: 1]) intValue]);
  208782. }
  208783. }
  208784. - (void) menuNeedsUpdate: (NSMenu*) menu;
  208785. {
  208786. if (JuceMainMenuHandler::instance != 0)
  208787. JuceMainMenuHandler::instance->updateMenus();
  208788. }
  208789. @end
  208790. BEGIN_JUCE_NAMESPACE
  208791. static NSMenu* createStandardAppMenu (NSMenu* menu, const String& appName,
  208792. const PopupMenu* extraItems)
  208793. {
  208794. if (extraItems != 0 && JuceMainMenuHandler::instance != 0 && extraItems->getNumItems() > 0)
  208795. {
  208796. PopupMenu::MenuItemIterator iter (*extraItems);
  208797. while (iter.next())
  208798. JuceMainMenuHandler::instance->addMenuItem (iter, menu, 0, -1);
  208799. [menu addItem: [NSMenuItem separatorItem]];
  208800. }
  208801. NSMenuItem* item;
  208802. // Services...
  208803. item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString (@"Services", nil)
  208804. action: nil keyEquivalent: @""];
  208805. [menu addItem: item];
  208806. [item release];
  208807. NSMenu* servicesMenu = [[NSMenu alloc] initWithTitle: @"Services"];
  208808. [menu setSubmenu: servicesMenu forItem: item];
  208809. [NSApp setServicesMenu: servicesMenu];
  208810. [servicesMenu release];
  208811. [menu addItem: [NSMenuItem separatorItem]];
  208812. // Hide + Show stuff...
  208813. item = [[NSMenuItem alloc] initWithTitle: juceStringToNS ("Hide " + appName)
  208814. action: @selector (hide:) keyEquivalent: @"h"];
  208815. [item setTarget: NSApp];
  208816. [menu addItem: item];
  208817. [item release];
  208818. item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString (@"Hide Others", nil)
  208819. action: @selector (hideOtherApplications:) keyEquivalent: @"h"];
  208820. [item setKeyEquivalentModifierMask: NSCommandKeyMask | NSAlternateKeyMask];
  208821. [item setTarget: NSApp];
  208822. [menu addItem: item];
  208823. [item release];
  208824. item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString (@"Show All", nil)
  208825. action: @selector (unhideAllApplications:) keyEquivalent: @""];
  208826. [item setTarget: NSApp];
  208827. [menu addItem: item];
  208828. [item release];
  208829. [menu addItem: [NSMenuItem separatorItem]];
  208830. // Quit item....
  208831. item = [[NSMenuItem alloc] initWithTitle: juceStringToNS ("Quit " + appName)
  208832. action: @selector (terminate:) keyEquivalent: @"q"];
  208833. [item setTarget: NSApp];
  208834. [menu addItem: item];
  208835. [item release];
  208836. return menu;
  208837. }
  208838. // Since our app has no NIB, this initialises a standard app menu...
  208839. static void rebuildMainMenu (const PopupMenu* extraItems)
  208840. {
  208841. // this can't be used in a plugin!
  208842. jassert (JUCEApplication::getInstance() != 0);
  208843. if (JUCEApplication::getInstance() != 0)
  208844. {
  208845. const ScopedAutoReleasePool pool;
  208846. NSMenu* mainMenu = [[NSMenu alloc] initWithTitle: @"MainMenu"];
  208847. NSMenuItem* item = [mainMenu addItemWithTitle: @"Apple" action: nil keyEquivalent: @""];
  208848. NSMenu* appMenu = [[NSMenu alloc] initWithTitle: @"Apple"];
  208849. [NSApp performSelector: @selector (setAppleMenu:) withObject: appMenu];
  208850. [mainMenu setSubmenu: appMenu forItem: item];
  208851. [NSApp setMainMenu: mainMenu];
  208852. createStandardAppMenu (appMenu, JUCEApplication::getInstance()->getApplicationName(), extraItems);
  208853. [appMenu release];
  208854. [mainMenu release];
  208855. }
  208856. }
  208857. void MenuBarModel::setMacMainMenu (MenuBarModel* newMenuBarModel,
  208858. const PopupMenu* extraAppleMenuItems)
  208859. {
  208860. if (getMacMainMenu() != newMenuBarModel)
  208861. {
  208862. const ScopedAutoReleasePool pool;
  208863. if (newMenuBarModel == 0)
  208864. {
  208865. delete JuceMainMenuHandler::instance;
  208866. jassert (JuceMainMenuHandler::instance == 0); // should be zeroed in the destructor
  208867. jassert (extraAppleMenuItems == 0); // you can't specify some extra items without also supplying a model
  208868. extraAppleMenuItems = 0;
  208869. }
  208870. else
  208871. {
  208872. if (JuceMainMenuHandler::instance == 0)
  208873. JuceMainMenuHandler::instance = new JuceMainMenuHandler();
  208874. JuceMainMenuHandler::instance->setMenu (newMenuBarModel);
  208875. }
  208876. }
  208877. rebuildMainMenu (extraAppleMenuItems);
  208878. if (newMenuBarModel != 0)
  208879. newMenuBarModel->menuItemsChanged();
  208880. }
  208881. MenuBarModel* MenuBarModel::getMacMainMenu()
  208882. {
  208883. return JuceMainMenuHandler::instance != 0
  208884. ? JuceMainMenuHandler::instance->currentModel : 0;
  208885. }
  208886. void initialiseMainMenu()
  208887. {
  208888. if (JUCEApplication::getInstance() != 0) // only needed in an app
  208889. rebuildMainMenu (0);
  208890. }
  208891. #endif
  208892. /*** End of inlined file: juce_mac_MainMenu.mm ***/
  208893. /*** Start of inlined file: juce_mac_FileChooser.mm ***/
  208894. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208895. // compiled on its own).
  208896. #if JUCE_INCLUDED_FILE
  208897. #if JUCE_MAC
  208898. END_JUCE_NAMESPACE
  208899. using namespace JUCE_NAMESPACE;
  208900. #define JuceFileChooserDelegate MakeObjCClassName(JuceFileChooserDelegate)
  208901. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  208902. @interface JuceFileChooserDelegate : NSObject <NSOpenSavePanelDelegate>
  208903. #else
  208904. @interface JuceFileChooserDelegate : NSObject
  208905. #endif
  208906. {
  208907. StringArray* filters;
  208908. }
  208909. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_;
  208910. - (void) dealloc;
  208911. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename;
  208912. @end
  208913. @implementation JuceFileChooserDelegate
  208914. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_
  208915. {
  208916. [super init];
  208917. filters = filters_;
  208918. return self;
  208919. }
  208920. - (void) dealloc
  208921. {
  208922. delete filters;
  208923. [super dealloc];
  208924. }
  208925. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename
  208926. {
  208927. const File f (nsStringToJuce (filename));
  208928. for (int i = filters->size(); --i >= 0;)
  208929. if (f.getFileName().matchesWildcard ((*filters)[i], true))
  208930. return true;
  208931. return f.isDirectory();
  208932. }
  208933. @end
  208934. BEGIN_JUCE_NAMESPACE
  208935. void FileChooser::showPlatformDialog (Array<File>& results,
  208936. const String& title,
  208937. const File& currentFileOrDirectory,
  208938. const String& filter,
  208939. bool selectsDirectory,
  208940. bool selectsFiles,
  208941. bool isSaveDialogue,
  208942. bool warnAboutOverwritingExistingFiles,
  208943. bool selectMultipleFiles,
  208944. FilePreviewComponent* extraInfoComponent)
  208945. {
  208946. const ScopedAutoReleasePool pool;
  208947. StringArray* filters = new StringArray();
  208948. filters->addTokens (filter.replaceCharacters (T(",:"), T(";;")), T(";"), 0);
  208949. filters->trim();
  208950. filters->removeEmptyStrings();
  208951. JuceFileChooserDelegate* delegate = [[JuceFileChooserDelegate alloc] initWithFilters: filters];
  208952. [delegate autorelease];
  208953. NSSavePanel* panel = isSaveDialogue ? [NSSavePanel savePanel]
  208954. : [NSOpenPanel openPanel];
  208955. [panel setTitle: juceStringToNS (title)];
  208956. if (! isSaveDialogue)
  208957. {
  208958. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  208959. [openPanel setCanChooseDirectories: selectsDirectory];
  208960. [openPanel setCanChooseFiles: selectsFiles];
  208961. [openPanel setAllowsMultipleSelection: selectMultipleFiles];
  208962. }
  208963. [panel setDelegate: delegate];
  208964. if (isSaveDialogue || selectsDirectory)
  208965. [panel setCanCreateDirectories: YES];
  208966. String directory, filename;
  208967. if (currentFileOrDirectory.isDirectory())
  208968. {
  208969. directory = currentFileOrDirectory.getFullPathName();
  208970. }
  208971. else
  208972. {
  208973. directory = currentFileOrDirectory.getParentDirectory().getFullPathName();
  208974. filename = currentFileOrDirectory.getFileName();
  208975. }
  208976. if ([panel runModalForDirectory: juceStringToNS (directory)
  208977. file: juceStringToNS (filename)]
  208978. == NSOKButton)
  208979. {
  208980. if (isSaveDialogue)
  208981. {
  208982. results.add (File (nsStringToJuce ([panel filename])));
  208983. }
  208984. else
  208985. {
  208986. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  208987. NSArray* urls = [openPanel filenames];
  208988. for (unsigned int i = 0; i < [urls count]; ++i)
  208989. {
  208990. NSString* f = [urls objectAtIndex: i];
  208991. results.add (File (nsStringToJuce (f)));
  208992. }
  208993. }
  208994. }
  208995. [panel setDelegate: nil];
  208996. }
  208997. #else
  208998. void FileChooser::showPlatformDialog (Array<File>& results,
  208999. const String& title,
  209000. const File& currentFileOrDirectory,
  209001. const String& filter,
  209002. bool selectsDirectory,
  209003. bool selectsFiles,
  209004. bool isSaveDialogue,
  209005. bool warnAboutOverwritingExistingFiles,
  209006. bool selectMultipleFiles,
  209007. FilePreviewComponent* extraInfoComponent)
  209008. {
  209009. const ScopedAutoReleasePool pool;
  209010. jassertfalse //xxx to do
  209011. }
  209012. #endif
  209013. #endif
  209014. /*** End of inlined file: juce_mac_FileChooser.mm ***/
  209015. /*** Start of inlined file: juce_mac_QuickTimeMovieComponent.mm ***/
  209016. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209017. // compiled on its own).
  209018. #if JUCE_INCLUDED_FILE && JUCE_QUICKTIME
  209019. #define theMovie ((QTMovie*) movie)
  209020. QuickTimeMovieComponent::QuickTimeMovieComponent()
  209021. : movie (0)
  209022. {
  209023. setOpaque (true);
  209024. setVisible (true);
  209025. QTMovieView* view = [[QTMovieView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)];
  209026. setView (view);
  209027. }
  209028. QuickTimeMovieComponent::~QuickTimeMovieComponent()
  209029. {
  209030. closeMovie();
  209031. setView (0);
  209032. }
  209033. bool QuickTimeMovieComponent::isQuickTimeAvailable() throw()
  209034. {
  209035. return true;
  209036. }
  209037. static QTMovie* openMovieFromStream (InputStream* movieStream, File& movieFile)
  209038. {
  209039. // unfortunately, QTMovie objects can only be created on the main thread..
  209040. jassert (MessageManager::getInstance()->isThisTheMessageThread());
  209041. QTMovie* movie = 0;
  209042. FileInputStream* const fin = dynamic_cast <FileInputStream*> (movieStream);
  209043. if (fin != 0)
  209044. {
  209045. movieFile = fin->getFile();
  209046. movie = [QTMovie movieWithFile: juceStringToNS (movieFile.getFullPathName())
  209047. error: nil];
  209048. }
  209049. else
  209050. {
  209051. MemoryBlock temp;
  209052. movieStream->readIntoMemoryBlock (temp);
  209053. const char* const suffixesToTry[] = { ".mov", ".mp3", ".avi", ".m4a" };
  209054. for (int i = 0; i < numElementsInArray (suffixesToTry); ++i)
  209055. {
  209056. movie = [QTMovie movieWithDataReference: [QTDataReference dataReferenceWithReferenceToData: [NSData dataWithBytes: temp.getData()
  209057. length: temp.getSize()]
  209058. name: [NSString stringWithUTF8String: suffixesToTry[i]]
  209059. MIMEType: @""]
  209060. error: nil];
  209061. if (movie != 0)
  209062. break;
  209063. }
  209064. }
  209065. return movie;
  209066. }
  209067. bool QuickTimeMovieComponent::loadMovie (const File& movieFile_,
  209068. const bool isControllerVisible_)
  209069. {
  209070. return loadMovie ((InputStream*) movieFile_.createInputStream(), isControllerVisible_);
  209071. }
  209072. bool QuickTimeMovieComponent::loadMovie (InputStream* movieStream,
  209073. const bool controllerVisible_)
  209074. {
  209075. closeMovie();
  209076. if (getPeer() == 0)
  209077. {
  209078. // To open a movie, this component must be visible inside a functioning window, so that
  209079. // the QT control can be assigned to the window.
  209080. jassertfalse
  209081. return false;
  209082. }
  209083. movie = openMovieFromStream (movieStream, movieFile);
  209084. [theMovie retain];
  209085. QTMovieView* view = (QTMovieView*) getView();
  209086. [view setMovie: theMovie];
  209087. [view setControllerVisible: controllerVisible_];
  209088. setLooping (looping);
  209089. return movie != nil;
  209090. }
  209091. bool QuickTimeMovieComponent::loadMovie (const URL& movieURL,
  209092. const bool isControllerVisible_)
  209093. {
  209094. // unfortunately, QTMovie objects can only be created on the main thread..
  209095. jassert (MessageManager::getInstance()->isThisTheMessageThread());
  209096. closeMovie();
  209097. if (getPeer() == 0)
  209098. {
  209099. // To open a movie, this component must be visible inside a functioning window, so that
  209100. // the QT control can be assigned to the window.
  209101. jassertfalse
  209102. return false;
  209103. }
  209104. NSURL* url = [NSURL URLWithString: juceStringToNS (movieURL.toString (true))];
  209105. NSError* err;
  209106. if ([QTMovie canInitWithURL: url])
  209107. movie = [QTMovie movieWithURL: url error: &err];
  209108. [theMovie retain];
  209109. QTMovieView* view = (QTMovieView*) getView();
  209110. [view setMovie: theMovie];
  209111. [view setControllerVisible: controllerVisible];
  209112. setLooping (looping);
  209113. return movie != nil;
  209114. }
  209115. void QuickTimeMovieComponent::closeMovie()
  209116. {
  209117. stop();
  209118. QTMovieView* view = (QTMovieView*) getView();
  209119. [view setMovie: nil];
  209120. [theMovie release];
  209121. movie = 0;
  209122. movieFile = File::nonexistent;
  209123. }
  209124. bool QuickTimeMovieComponent::isMovieOpen() const
  209125. {
  209126. return movie != nil;
  209127. }
  209128. const File QuickTimeMovieComponent::getCurrentMovieFile() const
  209129. {
  209130. return movieFile;
  209131. }
  209132. void QuickTimeMovieComponent::play()
  209133. {
  209134. [theMovie play];
  209135. }
  209136. void QuickTimeMovieComponent::stop()
  209137. {
  209138. [theMovie stop];
  209139. }
  209140. bool QuickTimeMovieComponent::isPlaying() const
  209141. {
  209142. return movie != 0 && [theMovie rate] != 0;
  209143. }
  209144. void QuickTimeMovieComponent::setPosition (const double seconds)
  209145. {
  209146. if (movie != 0)
  209147. {
  209148. QTTime t;
  209149. t.timeValue = (uint64) (100000.0 * seconds);
  209150. t.timeScale = 100000;
  209151. t.flags = 0;
  209152. [theMovie setCurrentTime: t];
  209153. }
  209154. }
  209155. double QuickTimeMovieComponent::getPosition() const
  209156. {
  209157. if (movie == 0)
  209158. return 0.0;
  209159. QTTime t = [theMovie currentTime];
  209160. return t.timeValue / (double) t.timeScale;
  209161. }
  209162. void QuickTimeMovieComponent::setSpeed (const float newSpeed)
  209163. {
  209164. [theMovie setRate: newSpeed];
  209165. }
  209166. double QuickTimeMovieComponent::getMovieDuration() const
  209167. {
  209168. if (movie == 0)
  209169. return 0.0;
  209170. QTTime t = [theMovie duration];
  209171. return t.timeValue / (double) t.timeScale;
  209172. }
  209173. void QuickTimeMovieComponent::setLooping (const bool shouldLoop)
  209174. {
  209175. looping = shouldLoop;
  209176. [theMovie setAttribute: [NSNumber numberWithBool: shouldLoop]
  209177. forKey: QTMovieLoopsAttribute];
  209178. }
  209179. bool QuickTimeMovieComponent::isLooping() const
  209180. {
  209181. return looping;
  209182. }
  209183. void QuickTimeMovieComponent::setMovieVolume (const float newVolume)
  209184. {
  209185. [theMovie setVolume: newVolume];
  209186. }
  209187. float QuickTimeMovieComponent::getMovieVolume() const
  209188. {
  209189. return movie != 0 ? [theMovie volume] : 0.0f;
  209190. }
  209191. void QuickTimeMovieComponent::getMovieNormalSize (int& width, int& height) const
  209192. {
  209193. width = 0;
  209194. height = 0;
  209195. if (movie != 0)
  209196. {
  209197. NSSize s = [[theMovie attributeForKey: QTMovieNaturalSizeAttribute] sizeValue];
  209198. width = (int) s.width;
  209199. height = (int) s.height;
  209200. }
  209201. }
  209202. void QuickTimeMovieComponent::paint (Graphics& g)
  209203. {
  209204. if (movie == 0)
  209205. g.fillAll (Colours::black);
  209206. }
  209207. bool QuickTimeMovieComponent::isControllerVisible() const
  209208. {
  209209. return controllerVisible;
  209210. }
  209211. void QuickTimeMovieComponent::goToStart()
  209212. {
  209213. setPosition (0.0);
  209214. }
  209215. void QuickTimeMovieComponent::setBoundsWithCorrectAspectRatio (const Rectangle<int>& spaceToFitWithin,
  209216. const RectanglePlacement& placement)
  209217. {
  209218. int normalWidth, normalHeight;
  209219. getMovieNormalSize (normalWidth, normalHeight);
  209220. if (normalWidth > 0 && normalHeight > 0 && ! spaceToFitWithin.isEmpty())
  209221. {
  209222. double x = 0.0, y = 0.0, w = normalWidth, h = normalHeight;
  209223. placement.applyTo (x, y, w, h,
  209224. spaceToFitWithin.getX(), spaceToFitWithin.getY(),
  209225. spaceToFitWithin.getWidth(), spaceToFitWithin.getHeight());
  209226. if (w > 0 && h > 0)
  209227. {
  209228. setBounds (roundToInt (x), roundToInt (y),
  209229. roundToInt (w), roundToInt (h));
  209230. }
  209231. }
  209232. else
  209233. {
  209234. setBounds (spaceToFitWithin);
  209235. }
  209236. }
  209237. #if ! (JUCE_MAC && JUCE_64BIT)
  209238. bool juce_OpenQuickTimeMovieFromStream (InputStream* movieStream, Movie& result, Handle& dataHandle)
  209239. {
  209240. if (movieStream == 0)
  209241. return false;
  209242. File file;
  209243. QTMovie* movie = openMovieFromStream (movieStream, file);
  209244. if (movie != nil)
  209245. result = [movie quickTimeMovie];
  209246. return movie != nil;
  209247. }
  209248. #endif
  209249. #endif
  209250. /*** End of inlined file: juce_mac_QuickTimeMovieComponent.mm ***/
  209251. /*** Start of inlined file: juce_mac_AudioCDBurner.mm ***/
  209252. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209253. // compiled on its own).
  209254. #if JUCE_INCLUDED_FILE && JUCE_USE_CDBURNER
  209255. END_JUCE_NAMESPACE
  209256. #define OpenDiskDevice MakeObjCClassName(OpenDiskDevice)
  209257. @interface OpenDiskDevice : NSObject
  209258. {
  209259. DRDevice* device;
  209260. NSMutableArray* tracks;
  209261. }
  209262. - (OpenDiskDevice*) initWithDevice: (DRDevice*) device;
  209263. - (void) dealloc;
  209264. - (bool) isDiskPresent;
  209265. - (int) getNumAvailableAudioBlocks;
  209266. - (void) addSourceTrack: (JUCE_NAMESPACE::AudioSource*) source numSamples: (int) numSamples_;
  209267. - (void) burn: (JUCE_NAMESPACE::AudioCDBurner::BurnProgressListener*) listener errorString: (JUCE_NAMESPACE::String*) error
  209268. ejectAfterwards: (bool) shouldEject isFake: (bool) peformFakeBurnForTesting;
  209269. @end
  209270. #define AudioTrackProducer MakeObjCClassName(AudioTrackProducer)
  209271. @interface AudioTrackProducer : NSObject
  209272. {
  209273. JUCE_NAMESPACE::AudioSource* source;
  209274. int readPosition, lengthInFrames;
  209275. }
  209276. - (AudioTrackProducer*) init: (int) lengthInFrames;
  209277. - (AudioTrackProducer*) initWithAudioSource: (JUCE_NAMESPACE::AudioSource*) source numSamples: (int) lengthInSamples;
  209278. - (void) dealloc;
  209279. - (void) setupTrackProperties: (DRTrack*) track;
  209280. - (void) cleanupTrackAfterBurn: (DRTrack*) track;
  209281. - (BOOL) cleanupTrackAfterVerification:(DRTrack*)track;
  209282. - (uint64_t) estimateLengthOfTrack:(DRTrack*)track;
  209283. - (BOOL) prepareTrack:(DRTrack*)track forBurn:(DRBurn*)burn
  209284. toMedia:(NSDictionary*)mediaInfo;
  209285. - (BOOL) prepareTrackForVerification:(DRTrack*)track;
  209286. - (uint32_t) produceDataForTrack:(DRTrack*)track intoBuffer:(char*)buffer
  209287. length:(uint32_t)bufferLength atAddress:(uint64_t)address
  209288. blockSize:(uint32_t)blockSize ioFlags:(uint32_t*)flags;
  209289. - (uint32_t) producePreGapForTrack:(DRTrack*)track
  209290. intoBuffer:(char*)buffer length:(uint32_t)bufferLength
  209291. atAddress:(uint64_t)address blockSize:(uint32_t)blockSize
  209292. ioFlags:(uint32_t*)flags;
  209293. - (BOOL) verifyDataForTrack:(DRTrack*)track inBuffer:(const char*)buffer
  209294. length:(uint32_t)bufferLength atAddress:(uint64_t)address
  209295. blockSize:(uint32_t)blockSize ioFlags:(uint32_t*)flags;
  209296. - (uint32_t) producePreGapForTrack:(DRTrack*)track
  209297. intoBuffer:(char*)buffer length:(uint32_t)bufferLength
  209298. atAddress:(uint64_t)address blockSize:(uint32_t)blockSize
  209299. ioFlags:(uint32_t*)flags;
  209300. @end
  209301. @implementation OpenDiskDevice
  209302. - (OpenDiskDevice*) initWithDevice: (DRDevice*) device_
  209303. {
  209304. [super init];
  209305. device = device_;
  209306. tracks = [[NSMutableArray alloc] init];
  209307. return self;
  209308. }
  209309. - (void) dealloc
  209310. {
  209311. [tracks release];
  209312. [super dealloc];
  209313. }
  209314. - (bool) isDiskPresent
  209315. {
  209316. return [device isValid]
  209317. && [[[device status] objectForKey: DRDeviceMediaStateKey]
  209318. isEqualTo: DRDeviceMediaStateMediaPresent];
  209319. }
  209320. - (int) getNumAvailableAudioBlocks
  209321. {
  209322. return [[[[device status] objectForKey: DRDeviceMediaInfoKey]
  209323. objectForKey: DRDeviceMediaBlocksFreeKey] intValue];
  209324. }
  209325. - (void) addSourceTrack: (JUCE_NAMESPACE::AudioSource*) source_ numSamples: (int) numSamples_
  209326. {
  209327. AudioTrackProducer* p = [[AudioTrackProducer alloc] initWithAudioSource: source_ numSamples: numSamples_];
  209328. DRTrack* t = [[DRTrack alloc] initWithProducer: p];
  209329. [p setupTrackProperties: t];
  209330. [tracks addObject: t];
  209331. [t release];
  209332. [p release];
  209333. }
  209334. - (void) burn: (JUCE_NAMESPACE::AudioCDBurner::BurnProgressListener*) listener errorString: (JUCE_NAMESPACE::String*) error
  209335. ejectAfterwards: (bool) shouldEject isFake: (bool) peformFakeBurnForTesting
  209336. {
  209337. DRBurn* burn = [DRBurn burnForDevice: device];
  209338. if (! [device acquireExclusiveAccess])
  209339. {
  209340. *error = "Couldn't open or write to the CD device";
  209341. return;
  209342. }
  209343. [device acquireMediaReservation];
  209344. NSMutableDictionary* d = [[burn properties] mutableCopy];
  209345. [d autorelease];
  209346. [d setObject: [NSNumber numberWithBool: peformFakeBurnForTesting] forKey: DRBurnTestingKey];
  209347. [d setObject: [NSNumber numberWithBool: false] forKey: DRBurnVerifyDiscKey];
  209348. [d setObject: (shouldEject ? DRBurnCompletionActionEject : DRBurnCompletionActionMount)
  209349. forKey: DRBurnCompletionActionKey];
  209350. [burn setProperties: d];
  209351. [burn writeLayout: tracks];
  209352. for (;;)
  209353. {
  209354. JUCE_NAMESPACE::Thread::sleep (300);
  209355. float progress = [[[burn status] objectForKey: DRStatusPercentCompleteKey] floatValue];
  209356. if (listener != 0 && listener->audioCDBurnProgress (progress))
  209357. {
  209358. [burn abort];
  209359. *error = "User cancelled the write operation";
  209360. break;
  209361. }
  209362. if ([[[burn status] objectForKey: DRStatusStateKey] isEqualTo: DRStatusStateFailed])
  209363. {
  209364. *error = "Write operation failed";
  209365. break;
  209366. }
  209367. else if ([[[burn status] objectForKey: DRStatusStateKey] isEqualTo: DRStatusStateDone])
  209368. {
  209369. break;
  209370. }
  209371. NSString* err = (NSString*) [[[burn status] objectForKey: DRErrorStatusKey]
  209372. objectForKey: DRErrorStatusErrorStringKey];
  209373. if ([err length] > 0)
  209374. {
  209375. *error = JUCE_NAMESPACE::String::fromUTF8 ((JUCE_NAMESPACE::uint8*) [err UTF8String]);
  209376. break;
  209377. }
  209378. }
  209379. [device releaseMediaReservation];
  209380. [device releaseExclusiveAccess];
  209381. }
  209382. @end
  209383. @implementation AudioTrackProducer
  209384. - (AudioTrackProducer*) init: (int) lengthInFrames_
  209385. {
  209386. lengthInFrames = lengthInFrames_;
  209387. readPosition = 0;
  209388. return self;
  209389. }
  209390. - (void) setupTrackProperties: (DRTrack*) track
  209391. {
  209392. NSMutableDictionary* p = [[track properties] mutableCopy];
  209393. [p setObject:[DRMSF msfWithFrames: lengthInFrames] forKey: DRTrackLengthKey];
  209394. [p setObject:[NSNumber numberWithUnsignedShort:2352] forKey: DRBlockSizeKey];
  209395. [p setObject:[NSNumber numberWithInt:0] forKey: DRDataFormKey];
  209396. [p setObject:[NSNumber numberWithInt:0] forKey: DRBlockTypeKey];
  209397. [p setObject:[NSNumber numberWithInt:0] forKey: DRTrackModeKey];
  209398. [p setObject:[NSNumber numberWithInt:0] forKey: DRSessionFormatKey];
  209399. [track setProperties: p];
  209400. [p release];
  209401. }
  209402. - (AudioTrackProducer*) initWithAudioSource: (JUCE_NAMESPACE::AudioSource*) source_ numSamples: (int) lengthInSamples
  209403. {
  209404. AudioTrackProducer* s = [self init: (lengthInSamples + 587) / 588];
  209405. if (s != nil)
  209406. s->source = source_;
  209407. return s;
  209408. }
  209409. - (void) dealloc
  209410. {
  209411. if (source != 0)
  209412. {
  209413. source->releaseResources();
  209414. delete source;
  209415. }
  209416. [super dealloc];
  209417. }
  209418. - (void) cleanupTrackAfterBurn: (DRTrack*) track
  209419. {
  209420. }
  209421. - (BOOL) cleanupTrackAfterVerification: (DRTrack*) track
  209422. {
  209423. return true;
  209424. }
  209425. - (uint64_t) estimateLengthOfTrack: (DRTrack*) track
  209426. {
  209427. return lengthInFrames;
  209428. }
  209429. - (BOOL) prepareTrack: (DRTrack*) track forBurn: (DRBurn*) burn
  209430. toMedia: (NSDictionary*) mediaInfo
  209431. {
  209432. if (source != 0)
  209433. source->prepareToPlay (44100 / 75, 44100);
  209434. readPosition = 0;
  209435. return true;
  209436. }
  209437. - (BOOL) prepareTrackForVerification: (DRTrack*) track
  209438. {
  209439. if (source != 0)
  209440. source->prepareToPlay (44100 / 75, 44100);
  209441. return true;
  209442. }
  209443. - (uint32_t) produceDataForTrack: (DRTrack*) track intoBuffer: (char*) buffer
  209444. length: (uint32_t) bufferLength atAddress: (uint64_t) address
  209445. blockSize: (uint32_t) blockSize ioFlags: (uint32_t*) flags
  209446. {
  209447. if (source != 0)
  209448. {
  209449. const int numSamples = JUCE_NAMESPACE::jmin ((int) bufferLength / 4, (lengthInFrames * (44100 / 75)) - readPosition);
  209450. if (numSamples > 0)
  209451. {
  209452. JUCE_NAMESPACE::AudioSampleBuffer tempBuffer (2, numSamples);
  209453. JUCE_NAMESPACE::AudioSourceChannelInfo info;
  209454. info.buffer = &tempBuffer;
  209455. info.startSample = 0;
  209456. info.numSamples = numSamples;
  209457. source->getNextAudioBlock (info);
  209458. JUCE_NAMESPACE::AudioDataConverters::convertFloatToInt16LE (tempBuffer.getSampleData (0),
  209459. buffer, numSamples, 4);
  209460. JUCE_NAMESPACE::AudioDataConverters::convertFloatToInt16LE (tempBuffer.getSampleData (1),
  209461. buffer + 2, numSamples, 4);
  209462. readPosition += numSamples;
  209463. }
  209464. return numSamples * 4;
  209465. }
  209466. return 0;
  209467. }
  209468. - (uint32_t) producePreGapForTrack: (DRTrack*) track
  209469. intoBuffer: (char*) buffer length: (uint32_t) bufferLength
  209470. atAddress: (uint64_t) address blockSize: (uint32_t) blockSize
  209471. ioFlags: (uint32_t*) flags
  209472. {
  209473. zeromem (buffer, bufferLength);
  209474. return bufferLength;
  209475. }
  209476. - (BOOL) verifyDataForTrack: (DRTrack*) track inBuffer: (const char*) buffer
  209477. length: (uint32_t) bufferLength atAddress: (uint64_t) address
  209478. blockSize: (uint32_t) blockSize ioFlags: (uint32_t*) flags
  209479. {
  209480. return true;
  209481. }
  209482. @end
  209483. BEGIN_JUCE_NAMESPACE
  209484. AudioCDBurner::AudioCDBurner (const int deviceIndex)
  209485. : internal (0)
  209486. {
  209487. OpenDiskDevice* dev = [[OpenDiskDevice alloc] initWithDevice: [[DRDevice devices] objectAtIndex: deviceIndex]];
  209488. internal = (void*) dev;
  209489. }
  209490. AudioCDBurner::~AudioCDBurner()
  209491. {
  209492. OpenDiskDevice* dev = (OpenDiskDevice*) internal;
  209493. if (dev != 0)
  209494. [dev release];
  209495. }
  209496. AudioCDBurner* AudioCDBurner::openDevice (const int deviceIndex)
  209497. {
  209498. ScopedPointer <AudioCDBurner> b (new AudioCDBurner (deviceIndex));
  209499. if (b->internal == 0)
  209500. b = 0;
  209501. return b.release();
  209502. }
  209503. static NSArray* findDiskBurnerDevices()
  209504. {
  209505. NSMutableArray* results = [NSMutableArray array];
  209506. NSArray* devs = [DRDevice devices];
  209507. if (devs != 0)
  209508. {
  209509. int num = [devs count];
  209510. int i;
  209511. for (i = 0; i < num; ++i)
  209512. {
  209513. NSDictionary* dic = [[devs objectAtIndex: i] info];
  209514. NSString* name = [dic valueForKey: DRDeviceProductNameKey];
  209515. if (name != nil)
  209516. [results addObject: name];
  209517. }
  209518. }
  209519. return results;
  209520. }
  209521. const StringArray AudioCDBurner::findAvailableDevices()
  209522. {
  209523. NSArray* names = findDiskBurnerDevices();
  209524. StringArray s;
  209525. for (unsigned int i = 0; i < [names count]; ++i)
  209526. s.add (String::fromUTF8 ((JUCE_NAMESPACE::uint8*) [[names objectAtIndex: i] UTF8String]));
  209527. return s;
  209528. }
  209529. bool AudioCDBurner::isDiskPresent() const
  209530. {
  209531. OpenDiskDevice* dev = (OpenDiskDevice*) internal;
  209532. return dev != 0 && [dev isDiskPresent];
  209533. }
  209534. int AudioCDBurner::getNumAvailableAudioBlocks() const
  209535. {
  209536. OpenDiskDevice* dev = (OpenDiskDevice*) internal;
  209537. return [dev getNumAvailableAudioBlocks];
  209538. }
  209539. bool AudioCDBurner::addAudioTrack (AudioSource* source, int numSamps)
  209540. {
  209541. OpenDiskDevice* dev = (OpenDiskDevice*) internal;
  209542. if (dev != 0)
  209543. {
  209544. [dev addSourceTrack: source numSamples: numSamps];
  209545. return true;
  209546. }
  209547. return false;
  209548. }
  209549. const String AudioCDBurner::burn (JUCE_NAMESPACE::AudioCDBurner::BurnProgressListener* listener,
  209550. const bool ejectDiscAfterwards,
  209551. const bool peformFakeBurnForTesting)
  209552. {
  209553. String error ("Couldn't open or write to the CD device");
  209554. OpenDiskDevice* dev = (OpenDiskDevice*) internal;
  209555. if (dev != 0)
  209556. {
  209557. error = String::empty;
  209558. [dev burn: listener
  209559. errorString: &error
  209560. ejectAfterwards: ejectDiscAfterwards
  209561. isFake: peformFakeBurnForTesting];
  209562. }
  209563. return error;
  209564. }
  209565. void AudioCDReader::ejectDisk()
  209566. {
  209567. const ScopedAutoReleasePool p;
  209568. [[NSWorkspace sharedWorkspace] unmountAndEjectDeviceAtPath: juceStringToNS (volumeDir.getFullPathName())];
  209569. }
  209570. #endif
  209571. /*** End of inlined file: juce_mac_AudioCDBurner.mm ***/
  209572. /*** Start of inlined file: juce_mac_MessageManager.mm ***/
  209573. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209574. // compiled on its own).
  209575. #if JUCE_INCLUDED_FILE
  209576. struct CallbackMessagePayload
  209577. {
  209578. MessageCallbackFunction* function;
  209579. void* parameter;
  209580. void* volatile result;
  209581. bool volatile hasBeenExecuted;
  209582. };
  209583. class AppDelegateRedirector
  209584. {
  209585. public:
  209586. AppDelegateRedirector()
  209587. {
  209588. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_4
  209589. runLoop = CFRunLoopGetMain();
  209590. #else
  209591. runLoop = CFRunLoopGetCurrent();
  209592. #endif
  209593. CFRunLoopSourceContext sourceContext;
  209594. zerostruct (sourceContext);
  209595. sourceContext.info = this;
  209596. sourceContext.perform = runLoopSourceCallback;
  209597. runLoopSource = CFRunLoopSourceCreate (kCFAllocatorDefault, 1, &sourceContext);
  209598. CFRunLoopAddSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
  209599. }
  209600. virtual ~AppDelegateRedirector()
  209601. {
  209602. CFRunLoopRemoveSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
  209603. CFRunLoopSourceInvalidate (runLoopSource);
  209604. CFRelease (runLoopSource);
  209605. while (messages.size() > 0)
  209606. delete ((Message*) messages.remove(0));
  209607. }
  209608. virtual NSApplicationTerminateReply shouldTerminate()
  209609. {
  209610. if (JUCEApplication::getInstance() != 0)
  209611. {
  209612. JUCEApplication::getInstance()->systemRequestedQuit();
  209613. return NSTerminateCancel;
  209614. }
  209615. return NSTerminateNow;
  209616. }
  209617. virtual BOOL openFile (const NSString* filename)
  209618. {
  209619. if (JUCEApplication::getInstance() != 0)
  209620. {
  209621. JUCEApplication::getInstance()->anotherInstanceStarted (nsStringToJuce (filename));
  209622. return YES;
  209623. }
  209624. return NO;
  209625. }
  209626. virtual void openFiles (NSArray* filenames)
  209627. {
  209628. StringArray files;
  209629. for (unsigned int i = 0; i < [filenames count]; ++i)
  209630. {
  209631. String filename (nsStringToJuce ((NSString*) [filenames objectAtIndex: i]));
  209632. if (filename.containsChar (T(' ')))
  209633. filename = filename.quoted('"');
  209634. files.add (filename);
  209635. }
  209636. if (files.size() > 0 && JUCEApplication::getInstance() != 0)
  209637. {
  209638. JUCEApplication::getInstance()->anotherInstanceStarted (files.joinIntoString (T(" ")));
  209639. }
  209640. }
  209641. virtual void focusChanged()
  209642. {
  209643. juce_HandleProcessFocusChange();
  209644. }
  209645. virtual void performCallback (CallbackMessagePayload* pl)
  209646. {
  209647. pl->result = (*pl->function) (pl->parameter);
  209648. pl->hasBeenExecuted = true;
  209649. }
  209650. virtual void deleteSelf()
  209651. {
  209652. delete this;
  209653. }
  209654. void postMessage (void* m)
  209655. {
  209656. messages.add (m);
  209657. CFRunLoopSourceSignal (runLoopSource);
  209658. CFRunLoopWakeUp (runLoop);
  209659. }
  209660. private:
  209661. CFRunLoopRef runLoop;
  209662. CFRunLoopSourceRef runLoopSource;
  209663. Array <void*, CriticalSection> messages;
  209664. void runLoopCallback()
  209665. {
  209666. int numDispatched = 0;
  209667. do
  209668. {
  209669. void* const nextMessage = messages.remove (0);
  209670. if (nextMessage == 0)
  209671. return;
  209672. const ScopedAutoReleasePool pool;
  209673. MessageManager::getInstance()->deliverMessage (nextMessage);
  209674. } while (++numDispatched <= 4);
  209675. CFRunLoopSourceSignal (runLoopSource);
  209676. CFRunLoopWakeUp (runLoop);
  209677. }
  209678. static void runLoopSourceCallback (void* info)
  209679. {
  209680. ((AppDelegateRedirector*) info)->runLoopCallback();
  209681. }
  209682. };
  209683. END_JUCE_NAMESPACE
  209684. using namespace JUCE_NAMESPACE;
  209685. #define JuceAppDelegate MakeObjCClassName(JuceAppDelegate)
  209686. @interface JuceAppDelegate : NSObject
  209687. {
  209688. @private
  209689. id oldDelegate;
  209690. @public
  209691. AppDelegateRedirector* redirector;
  209692. }
  209693. - (JuceAppDelegate*) init;
  209694. - (void) dealloc;
  209695. - (BOOL) application: (NSApplication*) theApplication openFile: (NSString*) filename;
  209696. - (void) application: (NSApplication*) sender openFiles: (NSArray*) filenames;
  209697. - (NSApplicationTerminateReply) applicationShouldTerminate: (NSApplication*) app;
  209698. - (void) applicationDidBecomeActive: (NSNotification*) aNotification;
  209699. - (void) applicationDidResignActive: (NSNotification*) aNotification;
  209700. - (void) applicationWillUnhide: (NSNotification*) aNotification;
  209701. - (void) performCallback: (id) info;
  209702. - (void) dummyMethod;
  209703. @end
  209704. @implementation JuceAppDelegate
  209705. - (JuceAppDelegate*) init
  209706. {
  209707. [super init];
  209708. redirector = new AppDelegateRedirector();
  209709. NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
  209710. if (JUCEApplication::getInstance() != 0)
  209711. {
  209712. oldDelegate = [NSApp delegate];
  209713. [NSApp setDelegate: self];
  209714. }
  209715. else
  209716. {
  209717. oldDelegate = 0;
  209718. [center addObserver: self selector: @selector (applicationDidResignActive:)
  209719. name: NSApplicationDidResignActiveNotification object: NSApp];
  209720. [center addObserver: self selector: @selector (applicationDidBecomeActive:)
  209721. name: NSApplicationDidBecomeActiveNotification object: NSApp];
  209722. [center addObserver: self selector: @selector (applicationWillUnhide:)
  209723. name: NSApplicationWillUnhideNotification object: NSApp];
  209724. }
  209725. return self;
  209726. }
  209727. - (void) dealloc
  209728. {
  209729. if (oldDelegate != 0)
  209730. [NSApp setDelegate: oldDelegate];
  209731. redirector->deleteSelf();
  209732. [super dealloc];
  209733. }
  209734. - (NSApplicationTerminateReply) applicationShouldTerminate: (NSApplication*) app
  209735. {
  209736. return redirector->shouldTerminate();
  209737. }
  209738. - (BOOL) application: (NSApplication*) app openFile: (NSString*) filename
  209739. {
  209740. return redirector->openFile (filename);
  209741. }
  209742. - (void) application: (NSApplication*) sender openFiles: (NSArray*) filenames
  209743. {
  209744. return redirector->openFiles (filenames);
  209745. }
  209746. - (void) applicationDidBecomeActive: (NSNotification*) aNotification
  209747. {
  209748. redirector->focusChanged();
  209749. }
  209750. - (void) applicationDidResignActive: (NSNotification*) aNotification
  209751. {
  209752. redirector->focusChanged();
  209753. }
  209754. - (void) applicationWillUnhide: (NSNotification*) aNotification
  209755. {
  209756. redirector->focusChanged();
  209757. }
  209758. - (void) performCallback: (id) info
  209759. {
  209760. if ([info isKindOfClass: [NSData class]])
  209761. {
  209762. CallbackMessagePayload* pl = (CallbackMessagePayload*) [((NSData*) info) bytes];
  209763. if (pl != 0)
  209764. redirector->performCallback (pl);
  209765. }
  209766. else
  209767. {
  209768. jassertfalse // should never get here!
  209769. }
  209770. }
  209771. - (void) dummyMethod {} // (used as a way of running a dummy thread)
  209772. @end
  209773. BEGIN_JUCE_NAMESPACE
  209774. static JuceAppDelegate* juceAppDelegate = 0;
  209775. void MessageManager::runDispatchLoop()
  209776. {
  209777. if (! quitMessagePosted) // check that the quit message wasn't already posted..
  209778. {
  209779. const ScopedAutoReleasePool pool;
  209780. // must only be called by the message thread!
  209781. jassert (isThisTheMessageThread());
  209782. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  209783. @try
  209784. {
  209785. [NSApp run];
  209786. }
  209787. @catch (NSException* e)
  209788. {
  209789. // An AppKit exception will kill the app, but at least this provides a chance to log it.,
  209790. std::runtime_error ex (std::string ("NSException: ") + [[e name] UTF8String] + ", Reason:" + [[e reason] UTF8String]);
  209791. JUCEApplication::sendUnhandledException (&ex, __FILE__, __LINE__);
  209792. }
  209793. @finally
  209794. {
  209795. }
  209796. #else
  209797. [NSApp run];
  209798. #endif
  209799. }
  209800. }
  209801. void MessageManager::stopDispatchLoop()
  209802. {
  209803. quitMessagePosted = true;
  209804. [NSApp stop: nil];
  209805. [NSApp activateIgnoringOtherApps: YES]; // (if the app is inactive, it sits there and ignores the quit request until the next time it gets activated)
  209806. [NSEvent startPeriodicEventsAfterDelay: 0 withPeriod: 0.1];
  209807. }
  209808. static bool isEventBlockedByModalComps (NSEvent* e)
  209809. {
  209810. if (Component::getNumCurrentlyModalComponents() == 0)
  209811. return false;
  209812. NSWindow* const w = [e window];
  209813. if (w == 0 || [w worksWhenModal])
  209814. return false;
  209815. bool isKey = false, isInputAttempt = false;
  209816. switch ([e type])
  209817. {
  209818. case NSKeyDown:
  209819. case NSKeyUp:
  209820. isKey = isInputAttempt = true;
  209821. break;
  209822. case NSLeftMouseDown:
  209823. case NSRightMouseDown:
  209824. case NSOtherMouseDown:
  209825. isInputAttempt = true;
  209826. break;
  209827. case NSLeftMouseDragged:
  209828. case NSRightMouseDragged:
  209829. case NSLeftMouseUp:
  209830. case NSRightMouseUp:
  209831. case NSOtherMouseUp:
  209832. case NSOtherMouseDragged:
  209833. if (Component::getComponentUnderMouse() != 0)
  209834. return false;
  209835. break;
  209836. case NSMouseMoved:
  209837. case NSMouseEntered:
  209838. case NSMouseExited:
  209839. case NSCursorUpdate:
  209840. case NSScrollWheel:
  209841. case NSTabletPoint:
  209842. case NSTabletProximity:
  209843. break;
  209844. default:
  209845. return false;
  209846. }
  209847. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  209848. {
  209849. ComponentPeer* const peer = ComponentPeer::getPeer (i);
  209850. NSView* const compView = (NSView*) peer->getNativeHandle();
  209851. if ([compView window] == w)
  209852. {
  209853. if (isKey)
  209854. {
  209855. if (compView == [w firstResponder])
  209856. return false;
  209857. }
  209858. else
  209859. {
  209860. if (NSPointInRect ([compView convertPoint: [e locationInWindow] fromView: nil],
  209861. [compView bounds]))
  209862. return false;
  209863. }
  209864. }
  209865. }
  209866. if (isInputAttempt)
  209867. {
  209868. if (! [NSApp isActive])
  209869. [NSApp activateIgnoringOtherApps: YES];
  209870. Component* const modal = Component::getCurrentlyModalComponent (0);
  209871. if (modal != 0)
  209872. modal->inputAttemptWhenModal();
  209873. }
  209874. return true;
  209875. }
  209876. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  209877. {
  209878. const ScopedAutoReleasePool pool;
  209879. jassert (isThisTheMessageThread()); // must only be called by the message thread
  209880. uint32 endTime = Time::getMillisecondCounter() + millisecondsToRunFor;
  209881. while (! quitMessagePosted)
  209882. {
  209883. const ScopedAutoReleasePool pool2;
  209884. CFRunLoopRunInMode (kCFRunLoopDefaultMode, 0.001, true);
  209885. NSEvent* e = [NSApp nextEventMatchingMask: NSAnyEventMask
  209886. untilDate: [NSDate dateWithTimeIntervalSinceNow: 0.001]
  209887. inMode: NSDefaultRunLoopMode
  209888. dequeue: YES];
  209889. if (e != 0 && ! isEventBlockedByModalComps (e))
  209890. [NSApp sendEvent: e];
  209891. if (Time::getMillisecondCounter() >= endTime)
  209892. break;
  209893. }
  209894. return ! quitMessagePosted;
  209895. }
  209896. void MessageManager::doPlatformSpecificInitialisation()
  209897. {
  209898. if (juceAppDelegate == 0)
  209899. juceAppDelegate = [[JuceAppDelegate alloc] init];
  209900. // This launches a dummy thread, which forces Cocoa to initialise NSThreads
  209901. // correctly (needed prior to 10.5)
  209902. if (! [NSThread isMultiThreaded])
  209903. [NSThread detachNewThreadSelector: @selector (dummyMethod)
  209904. toTarget: juceAppDelegate
  209905. withObject: nil];
  209906. initialiseMainMenu();
  209907. }
  209908. void MessageManager::doPlatformSpecificShutdown()
  209909. {
  209910. if (juceAppDelegate != 0)
  209911. {
  209912. [[NSRunLoop currentRunLoop] cancelPerformSelectorsWithTarget: juceAppDelegate];
  209913. [[NSNotificationCenter defaultCenter] removeObserver: juceAppDelegate];
  209914. [juceAppDelegate release];
  209915. juceAppDelegate = 0;
  209916. }
  209917. }
  209918. bool juce_postMessageToSystemQueue (void* message)
  209919. {
  209920. juceAppDelegate->redirector->postMessage (message);
  209921. return true;
  209922. }
  209923. void MessageManager::broadcastMessage (const String& value) throw()
  209924. {
  209925. }
  209926. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
  209927. void* data)
  209928. {
  209929. if (isThisTheMessageThread())
  209930. {
  209931. return (*callback) (data);
  209932. }
  209933. else
  209934. {
  209935. // If a thread has a MessageManagerLock and then tries to call this method, it'll
  209936. // deadlock because the message manager is blocked from running, so can never
  209937. // call your function..
  209938. jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  209939. const ScopedAutoReleasePool pool;
  209940. CallbackMessagePayload cmp;
  209941. cmp.function = callback;
  209942. cmp.parameter = data;
  209943. cmp.result = 0;
  209944. cmp.hasBeenExecuted = false;
  209945. [juceAppDelegate performSelectorOnMainThread: @selector (performCallback:)
  209946. withObject: [NSData dataWithBytesNoCopy: &cmp
  209947. length: sizeof (cmp)
  209948. freeWhenDone: NO]
  209949. waitUntilDone: YES];
  209950. return cmp.result;
  209951. }
  209952. }
  209953. #endif
  209954. /*** End of inlined file: juce_mac_MessageManager.mm ***/
  209955. /*** Start of inlined file: juce_mac_WebBrowserComponent.mm ***/
  209956. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209957. // compiled on its own).
  209958. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  209959. #if JUCE_MAC
  209960. END_JUCE_NAMESPACE
  209961. #define DownloadClickDetector MakeObjCClassName(DownloadClickDetector)
  209962. @interface DownloadClickDetector : NSObject
  209963. {
  209964. JUCE_NAMESPACE::WebBrowserComponent* ownerComponent;
  209965. }
  209966. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent;
  209967. - (void) webView: (WebView*) webView decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  209968. request: (NSURLRequest*) request
  209969. frame: (WebFrame*) frame
  209970. decisionListener: (id<WebPolicyDecisionListener>) listener;
  209971. @end
  209972. @implementation DownloadClickDetector
  209973. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent_
  209974. {
  209975. [super init];
  209976. ownerComponent = ownerComponent_;
  209977. return self;
  209978. }
  209979. - (void) webView: (WebView*) sender decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  209980. request: (NSURLRequest*) request
  209981. frame: (WebFrame*) frame
  209982. decisionListener: (id <WebPolicyDecisionListener>) listener
  209983. {
  209984. NSURL* url = [actionInformation valueForKey: @"WebActionOriginalURLKey"];
  209985. if (ownerComponent->pageAboutToLoad (nsStringToJuce ([url absoluteString])))
  209986. [listener use];
  209987. else
  209988. [listener ignore];
  209989. }
  209990. @end
  209991. BEGIN_JUCE_NAMESPACE
  209992. class WebBrowserComponentInternal : public NSViewComponent
  209993. {
  209994. public:
  209995. WebBrowserComponentInternal (WebBrowserComponent* owner)
  209996. {
  209997. webView = [[WebView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  209998. frameName: @""
  209999. groupName: @""];
  210000. setView (webView);
  210001. clickListener = [[DownloadClickDetector alloc] initWithWebBrowserOwner: owner];
  210002. [webView setPolicyDelegate: clickListener];
  210003. }
  210004. ~WebBrowserComponentInternal()
  210005. {
  210006. [webView setPolicyDelegate: nil];
  210007. [clickListener release];
  210008. setView (0);
  210009. }
  210010. void goToURL (const String& url,
  210011. const StringArray* headers,
  210012. const MemoryBlock* postData)
  210013. {
  210014. NSMutableURLRequest* r
  210015. = [NSMutableURLRequest requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
  210016. cachePolicy: NSURLRequestUseProtocolCachePolicy
  210017. timeoutInterval: 30.0];
  210018. if (postData != 0 && postData->getSize() > 0)
  210019. {
  210020. [r setHTTPMethod: @"POST"];
  210021. [r setHTTPBody: [NSData dataWithBytes: postData->getData()
  210022. length: postData->getSize()]];
  210023. }
  210024. if (headers != 0)
  210025. {
  210026. for (int i = 0; i < headers->size(); ++i)
  210027. {
  210028. const String headerName ((*headers)[i].upToFirstOccurrenceOf (T(":"), false, false).trim());
  210029. const String headerValue ((*headers)[i].fromFirstOccurrenceOf (T(":"), false, false).trim());
  210030. [r setValue: juceStringToNS (headerValue)
  210031. forHTTPHeaderField: juceStringToNS (headerName)];
  210032. }
  210033. }
  210034. stop();
  210035. [[webView mainFrame] loadRequest: r];
  210036. }
  210037. void goBack()
  210038. {
  210039. [webView goBack];
  210040. }
  210041. void goForward()
  210042. {
  210043. [webView goForward];
  210044. }
  210045. void stop()
  210046. {
  210047. [webView stopLoading: nil];
  210048. }
  210049. void refresh()
  210050. {
  210051. [webView reload: nil];
  210052. }
  210053. private:
  210054. WebView* webView;
  210055. DownloadClickDetector* clickListener;
  210056. };
  210057. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  210058. : browser (0),
  210059. blankPageShown (false),
  210060. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  210061. {
  210062. setOpaque (true);
  210063. addAndMakeVisible (browser = new WebBrowserComponentInternal (this));
  210064. }
  210065. WebBrowserComponent::~WebBrowserComponent()
  210066. {
  210067. deleteAndZero (browser);
  210068. }
  210069. void WebBrowserComponent::goToURL (const String& url,
  210070. const StringArray* headers,
  210071. const MemoryBlock* postData)
  210072. {
  210073. lastURL = url;
  210074. lastHeaders.clear();
  210075. if (headers != 0)
  210076. lastHeaders = *headers;
  210077. lastPostData.setSize (0);
  210078. if (postData != 0)
  210079. lastPostData = *postData;
  210080. blankPageShown = false;
  210081. browser->goToURL (url, headers, postData);
  210082. }
  210083. void WebBrowserComponent::stop()
  210084. {
  210085. browser->stop();
  210086. }
  210087. void WebBrowserComponent::goBack()
  210088. {
  210089. lastURL = String::empty;
  210090. blankPageShown = false;
  210091. browser->goBack();
  210092. }
  210093. void WebBrowserComponent::goForward()
  210094. {
  210095. lastURL = String::empty;
  210096. browser->goForward();
  210097. }
  210098. void WebBrowserComponent::refresh()
  210099. {
  210100. browser->refresh();
  210101. }
  210102. void WebBrowserComponent::paint (Graphics& g)
  210103. {
  210104. }
  210105. void WebBrowserComponent::checkWindowAssociation()
  210106. {
  210107. if (isShowing())
  210108. {
  210109. if (blankPageShown)
  210110. goBack();
  210111. }
  210112. else
  210113. {
  210114. if (unloadPageWhenBrowserIsHidden && ! blankPageShown)
  210115. {
  210116. // when the component becomes invisible, some stuff like flash
  210117. // carries on playing audio, so we need to force it onto a blank
  210118. // page to avoid this, (and send it back when it's made visible again).
  210119. blankPageShown = true;
  210120. browser->goToURL ("about:blank", 0, 0);
  210121. }
  210122. }
  210123. }
  210124. void WebBrowserComponent::reloadLastURL()
  210125. {
  210126. if (lastURL.isNotEmpty())
  210127. {
  210128. goToURL (lastURL, &lastHeaders, &lastPostData);
  210129. lastURL = String::empty;
  210130. }
  210131. }
  210132. void WebBrowserComponent::parentHierarchyChanged()
  210133. {
  210134. checkWindowAssociation();
  210135. }
  210136. void WebBrowserComponent::resized()
  210137. {
  210138. browser->setSize (getWidth(), getHeight());
  210139. }
  210140. void WebBrowserComponent::visibilityChanged()
  210141. {
  210142. checkWindowAssociation();
  210143. }
  210144. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  210145. {
  210146. return true;
  210147. }
  210148. #else
  210149. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  210150. {
  210151. }
  210152. WebBrowserComponent::~WebBrowserComponent()
  210153. {
  210154. }
  210155. void WebBrowserComponent::goToURL (const String& url,
  210156. const StringArray* headers,
  210157. const MemoryBlock* postData)
  210158. {
  210159. }
  210160. void WebBrowserComponent::stop()
  210161. {
  210162. }
  210163. void WebBrowserComponent::goBack()
  210164. {
  210165. }
  210166. void WebBrowserComponent::goForward()
  210167. {
  210168. }
  210169. void WebBrowserComponent::refresh()
  210170. {
  210171. }
  210172. void WebBrowserComponent::paint (Graphics& g)
  210173. {
  210174. }
  210175. void WebBrowserComponent::checkWindowAssociation()
  210176. {
  210177. }
  210178. void WebBrowserComponent::reloadLastURL()
  210179. {
  210180. }
  210181. void WebBrowserComponent::parentHierarchyChanged()
  210182. {
  210183. }
  210184. void WebBrowserComponent::resized()
  210185. {
  210186. }
  210187. void WebBrowserComponent::visibilityChanged()
  210188. {
  210189. }
  210190. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  210191. {
  210192. return true;
  210193. }
  210194. #endif
  210195. #endif
  210196. /*** End of inlined file: juce_mac_WebBrowserComponent.mm ***/
  210197. /*** Start of inlined file: juce_mac_CoreAudio.cpp ***/
  210198. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  210199. // compiled on its own).
  210200. #if JUCE_INCLUDED_FILE
  210201. #ifndef JUCE_COREAUDIO_ERROR_LOGGING_ENABLED
  210202. #define JUCE_COREAUDIO_ERROR_LOGGING_ENABLED 1
  210203. #endif
  210204. #undef log
  210205. #if JUCE_COREAUDIO_LOGGING_ENABLED
  210206. #define log(a) Logger::writeToLog (a)
  210207. #else
  210208. #define log(a)
  210209. #endif
  210210. #undef OK
  210211. #if JUCE_COREAUDIO_ERROR_LOGGING_ENABLED
  210212. static bool logAnyErrors_CoreAudio (const OSStatus err, const int lineNum)
  210213. {
  210214. if (err == noErr)
  210215. return true;
  210216. Logger::writeToLog (T("CoreAudio error: ") + String (lineNum) + T(" - ") + String::toHexString ((int)err));
  210217. jassertfalse
  210218. return false;
  210219. }
  210220. #define OK(a) logAnyErrors_CoreAudio (a, __LINE__)
  210221. #else
  210222. #define OK(a) (a == noErr)
  210223. #endif
  210224. class CoreAudioInternal : public Timer
  210225. {
  210226. public:
  210227. CoreAudioInternal (AudioDeviceID id)
  210228. : inputLatency (0),
  210229. outputLatency (0),
  210230. callback (0),
  210231. #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
  210232. audioProcID (0),
  210233. #endif
  210234. inputDevice (0),
  210235. isSlaveDevice (false),
  210236. deviceID (id),
  210237. started (false),
  210238. sampleRate (0),
  210239. bufferSize (512),
  210240. numInputChans (0),
  210241. numOutputChans (0),
  210242. callbacksAllowed (true),
  210243. numInputChannelInfos (0),
  210244. numOutputChannelInfos (0)
  210245. {
  210246. jassert (deviceID != 0);
  210247. updateDetailsFromDevice();
  210248. AudioObjectPropertyAddress pa;
  210249. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  210250. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210251. pa.mElement = kAudioObjectPropertyElementWildcard;
  210252. AudioObjectAddPropertyListener (deviceID, &pa, deviceListenerProc, this);
  210253. }
  210254. ~CoreAudioInternal()
  210255. {
  210256. AudioObjectPropertyAddress pa;
  210257. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  210258. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210259. pa.mElement = kAudioObjectPropertyElementWildcard;
  210260. AudioObjectRemovePropertyListener (deviceID, &pa, deviceListenerProc, this);
  210261. stop (false);
  210262. delete inputDevice;
  210263. }
  210264. void allocateTempBuffers()
  210265. {
  210266. const int tempBufSize = bufferSize + 4;
  210267. audioBuffer.calloc ((numInputChans + numOutputChans) * tempBufSize);
  210268. tempInputBuffers.calloc (numInputChans + 2);
  210269. tempOutputBuffers.calloc (numOutputChans + 2);
  210270. int i, count = 0;
  210271. for (i = 0; i < numInputChans; ++i)
  210272. tempInputBuffers[i] = audioBuffer + count++ * tempBufSize;
  210273. for (i = 0; i < numOutputChans; ++i)
  210274. tempOutputBuffers[i] = audioBuffer + count++ * tempBufSize;
  210275. }
  210276. // returns the number of actual available channels
  210277. void fillInChannelInfo (const bool input)
  210278. {
  210279. int chanNum = 0;
  210280. UInt32 size;
  210281. AudioObjectPropertyAddress pa;
  210282. pa.mSelector = kAudioDevicePropertyStreamConfiguration;
  210283. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210284. pa.mElement = kAudioObjectPropertyElementMaster;
  210285. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210286. {
  210287. HeapBlock <AudioBufferList> bufList;
  210288. bufList.calloc (size, 1);
  210289. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, bufList)))
  210290. {
  210291. const int numStreams = bufList->mNumberBuffers;
  210292. for (int i = 0; i < numStreams; ++i)
  210293. {
  210294. const AudioBuffer& b = bufList->mBuffers[i];
  210295. for (unsigned int j = 0; j < b.mNumberChannels; ++j)
  210296. {
  210297. String name;
  210298. {
  210299. uint8 channelName [256];
  210300. zerostruct (channelName);
  210301. UInt32 nameSize = sizeof (channelName);
  210302. UInt32 channelNum = chanNum + 1;
  210303. pa.mSelector = kAudioDevicePropertyChannelName;
  210304. if (AudioObjectGetPropertyData (deviceID, &pa, sizeof (channelNum), &channelNum, &nameSize, channelName) == noErr)
  210305. name = String::fromUTF8 (channelName, nameSize);
  210306. }
  210307. if (input)
  210308. {
  210309. if (activeInputChans[chanNum])
  210310. {
  210311. inputChannelInfo [numInputChannelInfos].streamNum = i;
  210312. inputChannelInfo [numInputChannelInfos].dataOffsetSamples = j;
  210313. inputChannelInfo [numInputChannelInfos].dataStrideSamples = b.mNumberChannels;
  210314. ++numInputChannelInfos;
  210315. }
  210316. if (name.isEmpty())
  210317. name << "Input " << (chanNum + 1);
  210318. inChanNames.add (name);
  210319. }
  210320. else
  210321. {
  210322. if (activeOutputChans[chanNum])
  210323. {
  210324. outputChannelInfo [numOutputChannelInfos].streamNum = i;
  210325. outputChannelInfo [numOutputChannelInfos].dataOffsetSamples = j;
  210326. outputChannelInfo [numOutputChannelInfos].dataStrideSamples = b.mNumberChannels;
  210327. ++numOutputChannelInfos;
  210328. }
  210329. if (name.isEmpty())
  210330. name << "Output " << (chanNum + 1);
  210331. outChanNames.add (name);
  210332. }
  210333. ++chanNum;
  210334. }
  210335. }
  210336. }
  210337. }
  210338. }
  210339. void updateDetailsFromDevice()
  210340. {
  210341. stopTimer();
  210342. if (deviceID == 0)
  210343. return;
  210344. const ScopedLock sl (callbackLock);
  210345. Float64 sr;
  210346. UInt32 size = sizeof (Float64);
  210347. AudioObjectPropertyAddress pa;
  210348. pa.mSelector = kAudioDevicePropertyNominalSampleRate;
  210349. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210350. pa.mElement = kAudioObjectPropertyElementMaster;
  210351. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &sr)))
  210352. sampleRate = sr;
  210353. UInt32 framesPerBuf;
  210354. size = sizeof (framesPerBuf);
  210355. pa.mSelector = kAudioDevicePropertyBufferFrameSize;
  210356. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &framesPerBuf)))
  210357. {
  210358. bufferSize = framesPerBuf;
  210359. allocateTempBuffers();
  210360. }
  210361. bufferSizes.clear();
  210362. pa.mSelector = kAudioDevicePropertyBufferFrameSizeRange;
  210363. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210364. {
  210365. HeapBlock <AudioValueRange> ranges;
  210366. ranges.calloc (size, 1);
  210367. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, ranges)))
  210368. {
  210369. bufferSizes.add ((int) ranges[0].mMinimum);
  210370. for (int i = 32; i < 8192; i += 32)
  210371. {
  210372. for (int j = size / (int) sizeof (AudioValueRange); --j >= 0;)
  210373. {
  210374. if (i >= ranges[j].mMinimum && i <= ranges[j].mMaximum)
  210375. {
  210376. bufferSizes.addIfNotAlreadyThere (i);
  210377. break;
  210378. }
  210379. }
  210380. }
  210381. if (bufferSize > 0)
  210382. bufferSizes.addIfNotAlreadyThere (bufferSize);
  210383. }
  210384. }
  210385. if (bufferSizes.size() == 0 && bufferSize > 0)
  210386. bufferSizes.add (bufferSize);
  210387. sampleRates.clear();
  210388. const double possibleRates[] = { 44100.0, 48000.0, 88200.0, 96000.0, 176400.0, 192000.0 };
  210389. String rates;
  210390. pa.mSelector = kAudioDevicePropertyAvailableNominalSampleRates;
  210391. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210392. {
  210393. HeapBlock <AudioValueRange> ranges;
  210394. ranges.calloc (size, 1);
  210395. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, ranges)))
  210396. {
  210397. for (int i = 0; i < numElementsInArray (possibleRates); ++i)
  210398. {
  210399. bool ok = false;
  210400. for (int j = size / (int) sizeof (AudioValueRange); --j >= 0;)
  210401. if (possibleRates[i] >= ranges[j].mMinimum - 2 && possibleRates[i] <= ranges[j].mMaximum + 2)
  210402. ok = true;
  210403. if (ok)
  210404. {
  210405. sampleRates.add (possibleRates[i]);
  210406. rates << possibleRates[i] << T(" ");
  210407. }
  210408. }
  210409. }
  210410. }
  210411. if (sampleRates.size() == 0 && sampleRate > 0)
  210412. {
  210413. sampleRates.add (sampleRate);
  210414. rates << sampleRate;
  210415. }
  210416. log (T("sr: ") + rates);
  210417. inputLatency = 0;
  210418. outputLatency = 0;
  210419. UInt32 lat;
  210420. size = sizeof (lat);
  210421. pa.mSelector = kAudioDevicePropertyLatency;
  210422. pa.mScope = kAudioDevicePropertyScopeInput;
  210423. //if (AudioDeviceGetProperty (deviceID, 0, true, kAudioDevicePropertyLatency, &size, &lat) == noErr)
  210424. if (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &lat) == noErr)
  210425. inputLatency = (int) lat;
  210426. pa.mScope = kAudioDevicePropertyScopeOutput;
  210427. size = sizeof (lat);
  210428. if (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &lat) == noErr)
  210429. outputLatency = (int) lat;
  210430. log (T("lat: ") + String (inputLatency) + T(" ") + String (outputLatency));
  210431. inChanNames.clear();
  210432. outChanNames.clear();
  210433. inputChannelInfo.calloc (numInputChans + 2);
  210434. numInputChannelInfos = 0;
  210435. outputChannelInfo.calloc (numOutputChans + 2);
  210436. numOutputChannelInfos = 0;
  210437. fillInChannelInfo (true);
  210438. fillInChannelInfo (false);
  210439. }
  210440. const StringArray getSources (bool input)
  210441. {
  210442. StringArray s;
  210443. HeapBlock <OSType> types;
  210444. const int num = getAllDataSourcesForDevice (deviceID, input, types);
  210445. for (int i = 0; i < num; ++i)
  210446. {
  210447. AudioValueTranslation avt;
  210448. char buffer[256];
  210449. avt.mInputData = (void*) &(types[i]);
  210450. avt.mInputDataSize = sizeof (UInt32);
  210451. avt.mOutputData = buffer;
  210452. avt.mOutputDataSize = 256;
  210453. UInt32 transSize = sizeof (avt);
  210454. AudioObjectPropertyAddress pa;
  210455. pa.mSelector = kAudioDevicePropertyDataSourceNameForID;
  210456. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210457. pa.mElement = kAudioObjectPropertyElementMaster;
  210458. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &transSize, &avt)))
  210459. {
  210460. DBG (buffer);
  210461. s.add (buffer);
  210462. }
  210463. }
  210464. return s;
  210465. }
  210466. int getCurrentSourceIndex (bool input) const
  210467. {
  210468. OSType currentSourceID = 0;
  210469. UInt32 size = sizeof (currentSourceID);
  210470. int result = -1;
  210471. AudioObjectPropertyAddress pa;
  210472. pa.mSelector = kAudioDevicePropertyDataSource;
  210473. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210474. pa.mElement = kAudioObjectPropertyElementMaster;
  210475. if (deviceID != 0)
  210476. {
  210477. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &currentSourceID)))
  210478. {
  210479. HeapBlock <OSType> types;
  210480. const int num = getAllDataSourcesForDevice (deviceID, input, types);
  210481. for (int i = 0; i < num; ++i)
  210482. {
  210483. if (types[num] == currentSourceID)
  210484. {
  210485. result = i;
  210486. break;
  210487. }
  210488. }
  210489. }
  210490. }
  210491. return result;
  210492. }
  210493. void setCurrentSourceIndex (int index, bool input)
  210494. {
  210495. if (deviceID != 0)
  210496. {
  210497. HeapBlock <OSType> types;
  210498. const int num = getAllDataSourcesForDevice (deviceID, input, types);
  210499. if (((unsigned int) index) < (unsigned int) num)
  210500. {
  210501. AudioObjectPropertyAddress pa;
  210502. pa.mSelector = kAudioDevicePropertyDataSource;
  210503. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210504. pa.mElement = kAudioObjectPropertyElementMaster;
  210505. OSType typeId = types[index];
  210506. OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (typeId), &typeId));
  210507. }
  210508. }
  210509. }
  210510. const String reopen (const BitArray& inputChannels,
  210511. const BitArray& outputChannels,
  210512. double newSampleRate,
  210513. int bufferSizeSamples)
  210514. {
  210515. String error;
  210516. log ("CoreAudio reopen");
  210517. callbacksAllowed = false;
  210518. stopTimer();
  210519. stop (false);
  210520. activeInputChans = inputChannels;
  210521. activeInputChans.setRange (inChanNames.size(),
  210522. activeInputChans.getHighestBit() + 1 - inChanNames.size(),
  210523. false);
  210524. activeOutputChans = outputChannels;
  210525. activeOutputChans.setRange (outChanNames.size(),
  210526. activeOutputChans.getHighestBit() + 1 - outChanNames.size(),
  210527. false);
  210528. numInputChans = activeInputChans.countNumberOfSetBits();
  210529. numOutputChans = activeOutputChans.countNumberOfSetBits();
  210530. // set sample rate
  210531. AudioObjectPropertyAddress pa;
  210532. pa.mSelector = kAudioDevicePropertyNominalSampleRate;
  210533. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210534. pa.mElement = kAudioObjectPropertyElementMaster;
  210535. Float64 sr = newSampleRate;
  210536. if (! OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (sr), &sr)))
  210537. {
  210538. error = "Couldn't change sample rate";
  210539. }
  210540. else
  210541. {
  210542. // change buffer size
  210543. UInt32 framesPerBuf = bufferSizeSamples;
  210544. pa.mSelector = kAudioDevicePropertyBufferFrameSize;
  210545. if (! OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (framesPerBuf), &framesPerBuf)))
  210546. {
  210547. error = "Couldn't change buffer size";
  210548. }
  210549. else
  210550. {
  210551. // Annoyingly, after changing the rate and buffer size, some devices fail to
  210552. // correctly report their new settings until some random time in the future, so
  210553. // after calling updateDetailsFromDevice, we need to manually bodge these values
  210554. // to make sure we're using the correct numbers..
  210555. updateDetailsFromDevice();
  210556. sampleRate = newSampleRate;
  210557. bufferSize = bufferSizeSamples;
  210558. if (sampleRates.size() == 0)
  210559. error = "Device has no available sample-rates";
  210560. else if (bufferSizes.size() == 0)
  210561. error = "Device has no available buffer-sizes";
  210562. else if (inputDevice != 0)
  210563. error = inputDevice->reopen (inputChannels,
  210564. outputChannels,
  210565. newSampleRate,
  210566. bufferSizeSamples);
  210567. }
  210568. }
  210569. callbacksAllowed = true;
  210570. return error;
  210571. }
  210572. bool start (AudioIODeviceCallback* cb)
  210573. {
  210574. if (! started)
  210575. {
  210576. callback = 0;
  210577. if (deviceID != 0)
  210578. {
  210579. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  210580. if (OK (AudioDeviceAddIOProc (deviceID, audioIOProc, (void*) this)))
  210581. #else
  210582. if (OK (AudioDeviceCreateIOProcID (deviceID, audioIOProc, (void*) this, &audioProcID)))
  210583. #endif
  210584. {
  210585. if (OK (AudioDeviceStart (deviceID, audioIOProc)))
  210586. {
  210587. started = true;
  210588. }
  210589. else
  210590. {
  210591. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  210592. OK (AudioDeviceRemoveIOProc (deviceID, audioIOProc));
  210593. #else
  210594. OK (AudioDeviceDestroyIOProcID (deviceID, audioProcID));
  210595. audioProcID = 0;
  210596. #endif
  210597. }
  210598. }
  210599. }
  210600. }
  210601. if (started)
  210602. {
  210603. const ScopedLock sl (callbackLock);
  210604. callback = cb;
  210605. }
  210606. if (inputDevice != 0)
  210607. return started && inputDevice->start (cb);
  210608. else
  210609. return started;
  210610. }
  210611. void stop (bool leaveInterruptRunning)
  210612. {
  210613. callbackLock.enter();
  210614. callback = 0;
  210615. callbackLock.exit();
  210616. if (started
  210617. && (deviceID != 0)
  210618. && ! leaveInterruptRunning)
  210619. {
  210620. OK (AudioDeviceStop (deviceID, audioIOProc));
  210621. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  210622. OK (AudioDeviceRemoveIOProc (deviceID, audioIOProc));
  210623. #else
  210624. OK (AudioDeviceDestroyIOProcID (deviceID, audioProcID));
  210625. audioProcID = 0;
  210626. #endif
  210627. started = false;
  210628. callbackLock.enter();
  210629. callbackLock.exit();
  210630. // wait until it's definately stopped calling back..
  210631. for (int i = 40; --i >= 0;)
  210632. {
  210633. Thread::sleep (50);
  210634. UInt32 running = 0;
  210635. UInt32 size = sizeof (running);
  210636. AudioObjectPropertyAddress pa;
  210637. pa.mSelector = kAudioDevicePropertyDeviceIsRunning;
  210638. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210639. pa.mElement = kAudioObjectPropertyElementMaster;
  210640. OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &running));
  210641. if (running == 0)
  210642. break;
  210643. }
  210644. callbackLock.enter();
  210645. callbackLock.exit();
  210646. }
  210647. if (inputDevice != 0)
  210648. inputDevice->stop (leaveInterruptRunning);
  210649. }
  210650. double getSampleRate() const
  210651. {
  210652. return sampleRate;
  210653. }
  210654. int getBufferSize() const
  210655. {
  210656. return bufferSize;
  210657. }
  210658. void audioCallback (const AudioBufferList* inInputData,
  210659. AudioBufferList* outOutputData)
  210660. {
  210661. int i;
  210662. const ScopedLock sl (callbackLock);
  210663. if (callback != 0)
  210664. {
  210665. if (inputDevice == 0)
  210666. {
  210667. for (i = numInputChans; --i >= 0;)
  210668. {
  210669. const CallbackDetailsForChannel& info = inputChannelInfo[i];
  210670. float* dest = tempInputBuffers [i];
  210671. const float* src = ((const float*) inInputData->mBuffers[info.streamNum].mData)
  210672. + info.dataOffsetSamples;
  210673. const int stride = info.dataStrideSamples;
  210674. if (stride != 0) // if this is zero, info is invalid
  210675. {
  210676. for (int j = bufferSize; --j >= 0;)
  210677. {
  210678. *dest++ = *src;
  210679. src += stride;
  210680. }
  210681. }
  210682. }
  210683. }
  210684. if (! isSlaveDevice)
  210685. {
  210686. if (inputDevice == 0)
  210687. {
  210688. callback->audioDeviceIOCallback ((const float**) tempInputBuffers,
  210689. numInputChans,
  210690. tempOutputBuffers,
  210691. numOutputChans,
  210692. bufferSize);
  210693. }
  210694. else
  210695. {
  210696. jassert (inputDevice->bufferSize == bufferSize);
  210697. // Sometimes the two linked devices seem to get their callbacks in
  210698. // parallel, so we need to lock both devices to stop the input data being
  210699. // changed while inside our callback..
  210700. const ScopedLock sl2 (inputDevice->callbackLock);
  210701. callback->audioDeviceIOCallback ((const float**) inputDevice->tempInputBuffers,
  210702. inputDevice->numInputChans,
  210703. tempOutputBuffers,
  210704. numOutputChans,
  210705. bufferSize);
  210706. }
  210707. for (i = numOutputChans; --i >= 0;)
  210708. {
  210709. const CallbackDetailsForChannel& info = outputChannelInfo[i];
  210710. const float* src = tempOutputBuffers [i];
  210711. float* dest = ((float*) outOutputData->mBuffers[info.streamNum].mData)
  210712. + info.dataOffsetSamples;
  210713. const int stride = info.dataStrideSamples;
  210714. if (stride != 0) // if this is zero, info is invalid
  210715. {
  210716. for (int j = bufferSize; --j >= 0;)
  210717. {
  210718. *dest = *src++;
  210719. dest += stride;
  210720. }
  210721. }
  210722. }
  210723. }
  210724. }
  210725. else
  210726. {
  210727. for (i = jmin (numOutputChans, numOutputChannelInfos); --i >= 0;)
  210728. {
  210729. const CallbackDetailsForChannel& info = outputChannelInfo[i];
  210730. float* dest = ((float*) outOutputData->mBuffers[info.streamNum].mData)
  210731. + info.dataOffsetSamples;
  210732. const int stride = info.dataStrideSamples;
  210733. if (stride != 0) // if this is zero, info is invalid
  210734. {
  210735. for (int j = bufferSize; --j >= 0;)
  210736. {
  210737. *dest = 0.0f;
  210738. dest += stride;
  210739. }
  210740. }
  210741. }
  210742. }
  210743. }
  210744. // called by callbacks
  210745. void deviceDetailsChanged()
  210746. {
  210747. if (callbacksAllowed)
  210748. startTimer (100);
  210749. }
  210750. void timerCallback()
  210751. {
  210752. stopTimer();
  210753. log ("CoreAudio device changed callback");
  210754. const double oldSampleRate = sampleRate;
  210755. const int oldBufferSize = bufferSize;
  210756. updateDetailsFromDevice();
  210757. if (oldBufferSize != bufferSize || oldSampleRate != sampleRate)
  210758. {
  210759. callbacksAllowed = false;
  210760. stop (false);
  210761. updateDetailsFromDevice();
  210762. callbacksAllowed = true;
  210763. }
  210764. }
  210765. CoreAudioInternal* getRelatedDevice() const
  210766. {
  210767. UInt32 size = 0;
  210768. ScopedPointer <CoreAudioInternal> result;
  210769. AudioObjectPropertyAddress pa;
  210770. pa.mSelector = kAudioDevicePropertyRelatedDevices;
  210771. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210772. pa.mElement = kAudioObjectPropertyElementMaster;
  210773. if (deviceID != 0
  210774. && AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size) == noErr
  210775. && size > 0)
  210776. {
  210777. HeapBlock <AudioDeviceID> devs;
  210778. devs.calloc (size, 1);
  210779. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, devs)))
  210780. {
  210781. for (unsigned int i = 0; i < size / sizeof (AudioDeviceID); ++i)
  210782. {
  210783. if (devs[i] != deviceID && devs[i] != 0)
  210784. {
  210785. result = new CoreAudioInternal (devs[i]);
  210786. const bool thisIsInput = inChanNames.size() > 0 && outChanNames.size() == 0;
  210787. const bool otherIsInput = result->inChanNames.size() > 0 && result->outChanNames.size() == 0;
  210788. if (thisIsInput != otherIsInput
  210789. || (inChanNames.size() + outChanNames.size() == 0)
  210790. || (result->inChanNames.size() + result->outChanNames.size()) == 0)
  210791. break;
  210792. result = 0;
  210793. }
  210794. }
  210795. }
  210796. }
  210797. return result.release();
  210798. }
  210799. juce_UseDebuggingNewOperator
  210800. int inputLatency, outputLatency;
  210801. BitArray activeInputChans, activeOutputChans;
  210802. StringArray inChanNames, outChanNames;
  210803. Array <double> sampleRates;
  210804. Array <int> bufferSizes;
  210805. AudioIODeviceCallback* callback;
  210806. #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
  210807. AudioDeviceIOProcID audioProcID;
  210808. #endif
  210809. CoreAudioInternal* inputDevice;
  210810. bool isSlaveDevice;
  210811. private:
  210812. CriticalSection callbackLock;
  210813. AudioDeviceID deviceID;
  210814. bool started;
  210815. double sampleRate;
  210816. int bufferSize;
  210817. HeapBlock <float> audioBuffer;
  210818. int numInputChans, numOutputChans;
  210819. bool callbacksAllowed;
  210820. struct CallbackDetailsForChannel
  210821. {
  210822. int streamNum;
  210823. int dataOffsetSamples;
  210824. int dataStrideSamples;
  210825. };
  210826. int numInputChannelInfos, numOutputChannelInfos;
  210827. HeapBlock <CallbackDetailsForChannel> inputChannelInfo, outputChannelInfo;
  210828. HeapBlock <float*> tempInputBuffers, tempOutputBuffers;
  210829. CoreAudioInternal (const CoreAudioInternal&);
  210830. const CoreAudioInternal& operator= (const CoreAudioInternal&);
  210831. static OSStatus audioIOProc (AudioDeviceID inDevice,
  210832. const AudioTimeStamp* inNow,
  210833. const AudioBufferList* inInputData,
  210834. const AudioTimeStamp* inInputTime,
  210835. AudioBufferList* outOutputData,
  210836. const AudioTimeStamp* inOutputTime,
  210837. void* device)
  210838. {
  210839. ((CoreAudioInternal*) device)->audioCallback (inInputData, outOutputData);
  210840. return noErr;
  210841. }
  210842. static OSStatus deviceListenerProc (AudioDeviceID /*inDevice*/, UInt32 /*inLine*/, const AudioObjectPropertyAddress* pa, void* inClientData)
  210843. {
  210844. CoreAudioInternal* const intern = (CoreAudioInternal*) inClientData;
  210845. switch (pa->mSelector)
  210846. {
  210847. case kAudioDevicePropertyBufferSize:
  210848. case kAudioDevicePropertyBufferFrameSize:
  210849. case kAudioDevicePropertyNominalSampleRate:
  210850. case kAudioDevicePropertyStreamFormat:
  210851. case kAudioDevicePropertyDeviceIsAlive:
  210852. intern->deviceDetailsChanged();
  210853. break;
  210854. case kAudioDevicePropertyBufferSizeRange:
  210855. case kAudioDevicePropertyVolumeScalar:
  210856. case kAudioDevicePropertyMute:
  210857. case kAudioDevicePropertyPlayThru:
  210858. case kAudioDevicePropertyDataSource:
  210859. case kAudioDevicePropertyDeviceIsRunning:
  210860. break;
  210861. }
  210862. return noErr;
  210863. }
  210864. static int getAllDataSourcesForDevice (AudioDeviceID deviceID, const bool input, HeapBlock <OSType>& types)
  210865. {
  210866. AudioObjectPropertyAddress pa;
  210867. pa.mSelector = kAudioDevicePropertyDataSources;
  210868. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210869. pa.mElement = kAudioObjectPropertyElementMaster;
  210870. UInt32 size = 0;
  210871. if (deviceID != 0
  210872. && OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210873. {
  210874. types.calloc (size, 1);
  210875. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, types)))
  210876. return size / (int) sizeof (OSType);
  210877. }
  210878. return 0;
  210879. }
  210880. };
  210881. class CoreAudioIODevice : public AudioIODevice
  210882. {
  210883. public:
  210884. CoreAudioIODevice (const String& deviceName,
  210885. AudioDeviceID inputDeviceId,
  210886. const int inputIndex_,
  210887. AudioDeviceID outputDeviceId,
  210888. const int outputIndex_)
  210889. : AudioIODevice (deviceName, "CoreAudio"),
  210890. inputIndex (inputIndex_),
  210891. outputIndex (outputIndex_),
  210892. isOpen_ (false),
  210893. isStarted (false)
  210894. {
  210895. internal = 0;
  210896. CoreAudioInternal* device = 0;
  210897. if (outputDeviceId == 0 || outputDeviceId == inputDeviceId)
  210898. {
  210899. jassert (inputDeviceId != 0);
  210900. device = new CoreAudioInternal (inputDeviceId);
  210901. }
  210902. else
  210903. {
  210904. device = new CoreAudioInternal (outputDeviceId);
  210905. if (inputDeviceId != 0)
  210906. {
  210907. CoreAudioInternal* secondDevice = new CoreAudioInternal (inputDeviceId);
  210908. device->inputDevice = secondDevice;
  210909. secondDevice->isSlaveDevice = true;
  210910. }
  210911. }
  210912. internal = device;
  210913. AudioObjectPropertyAddress pa;
  210914. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  210915. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210916. pa.mElement = kAudioObjectPropertyElementWildcard;
  210917. AudioObjectAddPropertyListener (kAudioObjectSystemObject, &pa, hardwareListenerProc, internal);
  210918. }
  210919. ~CoreAudioIODevice()
  210920. {
  210921. AudioObjectPropertyAddress pa;
  210922. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  210923. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210924. pa.mElement = kAudioObjectPropertyElementWildcard;
  210925. AudioObjectRemovePropertyListener (kAudioObjectSystemObject, &pa, hardwareListenerProc, internal);
  210926. delete internal;
  210927. }
  210928. const StringArray getOutputChannelNames()
  210929. {
  210930. return internal->outChanNames;
  210931. }
  210932. const StringArray getInputChannelNames()
  210933. {
  210934. if (internal->inputDevice != 0)
  210935. return internal->inputDevice->inChanNames;
  210936. else
  210937. return internal->inChanNames;
  210938. }
  210939. int getNumSampleRates()
  210940. {
  210941. return internal->sampleRates.size();
  210942. }
  210943. double getSampleRate (int index)
  210944. {
  210945. return internal->sampleRates [index];
  210946. }
  210947. int getNumBufferSizesAvailable()
  210948. {
  210949. return internal->bufferSizes.size();
  210950. }
  210951. int getBufferSizeSamples (int index)
  210952. {
  210953. return internal->bufferSizes [index];
  210954. }
  210955. int getDefaultBufferSize()
  210956. {
  210957. for (int i = 0; i < getNumBufferSizesAvailable(); ++i)
  210958. if (getBufferSizeSamples(i) >= 512)
  210959. return getBufferSizeSamples(i);
  210960. return 512;
  210961. }
  210962. const String open (const BitArray& inputChannels,
  210963. const BitArray& outputChannels,
  210964. double sampleRate,
  210965. int bufferSizeSamples)
  210966. {
  210967. isOpen_ = true;
  210968. if (bufferSizeSamples <= 0)
  210969. bufferSizeSamples = getDefaultBufferSize();
  210970. lastError = internal->reopen (inputChannels, outputChannels, sampleRate, bufferSizeSamples);
  210971. isOpen_ = lastError.isEmpty();
  210972. return lastError;
  210973. }
  210974. void close()
  210975. {
  210976. isOpen_ = false;
  210977. internal->stop (false);
  210978. }
  210979. bool isOpen()
  210980. {
  210981. return isOpen_;
  210982. }
  210983. int getCurrentBufferSizeSamples()
  210984. {
  210985. return internal != 0 ? internal->getBufferSize() : 512;
  210986. }
  210987. double getCurrentSampleRate()
  210988. {
  210989. return internal != 0 ? internal->getSampleRate() : 0;
  210990. }
  210991. int getCurrentBitDepth()
  210992. {
  210993. return 32; // no way to find out, so just assume it's high..
  210994. }
  210995. const BitArray getActiveOutputChannels() const
  210996. {
  210997. return internal != 0 ? internal->activeOutputChans : BitArray();
  210998. }
  210999. const BitArray getActiveInputChannels() const
  211000. {
  211001. BitArray chans;
  211002. if (internal != 0)
  211003. {
  211004. chans = internal->activeInputChans;
  211005. if (internal->inputDevice != 0)
  211006. chans.orWith (internal->inputDevice->activeInputChans);
  211007. }
  211008. return chans;
  211009. }
  211010. int getOutputLatencyInSamples()
  211011. {
  211012. if (internal == 0)
  211013. return 0;
  211014. // this seems like a good guess at getting the latency right - comparing
  211015. // this with a round-trip measurement, it gets it to within a few millisecs
  211016. // for the built-in mac soundcard
  211017. return internal->outputLatency + internal->getBufferSize() * 2;
  211018. }
  211019. int getInputLatencyInSamples()
  211020. {
  211021. if (internal == 0)
  211022. return 0;
  211023. return internal->inputLatency + internal->getBufferSize() * 2;
  211024. }
  211025. void start (AudioIODeviceCallback* callback)
  211026. {
  211027. if (internal != 0 && ! isStarted)
  211028. {
  211029. if (callback != 0)
  211030. callback->audioDeviceAboutToStart (this);
  211031. isStarted = true;
  211032. internal->start (callback);
  211033. }
  211034. }
  211035. void stop()
  211036. {
  211037. if (isStarted && internal != 0)
  211038. {
  211039. AudioIODeviceCallback* const lastCallback = internal->callback;
  211040. isStarted = false;
  211041. internal->stop (true);
  211042. if (lastCallback != 0)
  211043. lastCallback->audioDeviceStopped();
  211044. }
  211045. }
  211046. bool isPlaying()
  211047. {
  211048. if (internal->callback == 0)
  211049. isStarted = false;
  211050. return isStarted;
  211051. }
  211052. const String getLastError()
  211053. {
  211054. return lastError;
  211055. }
  211056. int inputIndex, outputIndex;
  211057. juce_UseDebuggingNewOperator
  211058. private:
  211059. CoreAudioInternal* internal;
  211060. bool isOpen_, isStarted;
  211061. String lastError;
  211062. static OSStatus hardwareListenerProc (AudioDeviceID /*inDevice*/, UInt32 /*inLine*/, const AudioObjectPropertyAddress* pa, void* inClientData)
  211063. {
  211064. CoreAudioInternal* const intern = (CoreAudioInternal*) inClientData;
  211065. switch (pa->mSelector)
  211066. {
  211067. case kAudioHardwarePropertyDevices:
  211068. intern->deviceDetailsChanged();
  211069. break;
  211070. case kAudioHardwarePropertyDefaultOutputDevice:
  211071. case kAudioHardwarePropertyDefaultInputDevice:
  211072. case kAudioHardwarePropertyDefaultSystemOutputDevice:
  211073. break;
  211074. }
  211075. return noErr;
  211076. }
  211077. CoreAudioIODevice (const CoreAudioIODevice&);
  211078. const CoreAudioIODevice& operator= (const CoreAudioIODevice&);
  211079. };
  211080. class CoreAudioIODeviceType : public AudioIODeviceType
  211081. {
  211082. public:
  211083. CoreAudioIODeviceType()
  211084. : AudioIODeviceType (T("CoreAudio")),
  211085. hasScanned (false)
  211086. {
  211087. }
  211088. ~CoreAudioIODeviceType()
  211089. {
  211090. }
  211091. void scanForDevices()
  211092. {
  211093. hasScanned = true;
  211094. inputDeviceNames.clear();
  211095. outputDeviceNames.clear();
  211096. inputIds.clear();
  211097. outputIds.clear();
  211098. UInt32 size;
  211099. AudioObjectPropertyAddress pa;
  211100. pa.mSelector = kAudioHardwarePropertyDevices;
  211101. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211102. pa.mElement = kAudioObjectPropertyElementMaster;
  211103. if (OK (AudioObjectGetPropertyDataSize (kAudioObjectSystemObject, &pa, 0, 0, &size)))
  211104. {
  211105. HeapBlock <AudioDeviceID> devs;
  211106. devs.calloc (size, 1);
  211107. if (OK (AudioObjectGetPropertyData (kAudioObjectSystemObject, &pa, 0, 0, &size, devs)))
  211108. {
  211109. static bool alreadyLogged = false;
  211110. const int num = size / (int) sizeof (AudioDeviceID);
  211111. for (int i = 0; i < num; ++i)
  211112. {
  211113. char name [1024];
  211114. size = sizeof (name);
  211115. pa.mSelector = kAudioDevicePropertyDeviceName;
  211116. if (OK (AudioObjectGetPropertyData (devs[i], &pa, 0, 0, &size, name)))
  211117. {
  211118. const String nameString (String::fromUTF8 ((const uint8*) name, (int) strlen (name)));
  211119. if (! alreadyLogged)
  211120. log (T("CoreAudio device: ") + nameString);
  211121. const int numIns = getNumChannels (devs[i], true);
  211122. const int numOuts = getNumChannels (devs[i], false);
  211123. if (numIns > 0)
  211124. {
  211125. inputDeviceNames.add (nameString);
  211126. inputIds.add (devs[i]);
  211127. }
  211128. if (numOuts > 0)
  211129. {
  211130. outputDeviceNames.add (nameString);
  211131. outputIds.add (devs[i]);
  211132. }
  211133. }
  211134. }
  211135. alreadyLogged = true;
  211136. }
  211137. }
  211138. inputDeviceNames.appendNumbersToDuplicates (false, true);
  211139. outputDeviceNames.appendNumbersToDuplicates (false, true);
  211140. }
  211141. const StringArray getDeviceNames (const bool wantInputNames) const
  211142. {
  211143. jassert (hasScanned); // need to call scanForDevices() before doing this
  211144. if (wantInputNames)
  211145. return inputDeviceNames;
  211146. else
  211147. return outputDeviceNames;
  211148. }
  211149. int getDefaultDeviceIndex (const bool forInput) const
  211150. {
  211151. jassert (hasScanned); // need to call scanForDevices() before doing this
  211152. AudioDeviceID deviceID;
  211153. UInt32 size = sizeof (deviceID);
  211154. // if they're asking for any input channels at all, use the default input, so we
  211155. // get the built-in mic rather than the built-in output with no inputs..
  211156. AudioObjectPropertyAddress pa;
  211157. pa.mSelector = forInput ? kAudioHardwarePropertyDefaultInputDevice : kAudioHardwarePropertyDefaultOutputDevice;
  211158. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211159. pa.mElement = kAudioObjectPropertyElementMaster;
  211160. if (AudioObjectGetPropertyData (kAudioObjectSystemObject, &pa, 0, 0, &size, &deviceID) == noErr)
  211161. {
  211162. if (forInput)
  211163. {
  211164. for (int i = inputIds.size(); --i >= 0;)
  211165. if (inputIds[i] == deviceID)
  211166. return i;
  211167. }
  211168. else
  211169. {
  211170. for (int i = outputIds.size(); --i >= 0;)
  211171. if (outputIds[i] == deviceID)
  211172. return i;
  211173. }
  211174. }
  211175. return 0;
  211176. }
  211177. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  211178. {
  211179. jassert (hasScanned); // need to call scanForDevices() before doing this
  211180. CoreAudioIODevice* const d = dynamic_cast <CoreAudioIODevice*> (device);
  211181. if (d == 0)
  211182. return -1;
  211183. return asInput ? d->inputIndex
  211184. : d->outputIndex;
  211185. }
  211186. bool hasSeparateInputsAndOutputs() const { return true; }
  211187. AudioIODevice* createDevice (const String& outputDeviceName,
  211188. const String& inputDeviceName)
  211189. {
  211190. jassert (hasScanned); // need to call scanForDevices() before doing this
  211191. const int inputIndex = inputDeviceNames.indexOf (inputDeviceName);
  211192. const int outputIndex = outputDeviceNames.indexOf (outputDeviceName);
  211193. String deviceName (outputDeviceName);
  211194. if (deviceName.isEmpty())
  211195. deviceName = inputDeviceName;
  211196. if (index >= 0)
  211197. return new CoreAudioIODevice (deviceName,
  211198. inputIds [inputIndex],
  211199. inputIndex,
  211200. outputIds [outputIndex],
  211201. outputIndex);
  211202. return 0;
  211203. }
  211204. juce_UseDebuggingNewOperator
  211205. private:
  211206. StringArray inputDeviceNames, outputDeviceNames;
  211207. Array <AudioDeviceID> inputIds, outputIds;
  211208. bool hasScanned;
  211209. static int getNumChannels (AudioDeviceID deviceID, bool input)
  211210. {
  211211. int total = 0;
  211212. UInt32 size;
  211213. AudioObjectPropertyAddress pa;
  211214. pa.mSelector = kAudioDevicePropertyStreamConfiguration;
  211215. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  211216. pa.mElement = kAudioObjectPropertyElementMaster;
  211217. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  211218. {
  211219. HeapBlock <AudioBufferList> bufList;
  211220. bufList.calloc (size, 1);
  211221. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, bufList)))
  211222. {
  211223. const int numStreams = bufList->mNumberBuffers;
  211224. for (int i = 0; i < numStreams; ++i)
  211225. {
  211226. const AudioBuffer& b = bufList->mBuffers[i];
  211227. total += b.mNumberChannels;
  211228. }
  211229. }
  211230. }
  211231. return total;
  211232. }
  211233. CoreAudioIODeviceType (const CoreAudioIODeviceType&);
  211234. const CoreAudioIODeviceType& operator= (const CoreAudioIODeviceType&);
  211235. };
  211236. AudioIODeviceType* juce_createAudioIODeviceType_CoreAudio()
  211237. {
  211238. return new CoreAudioIODeviceType();
  211239. }
  211240. #undef log
  211241. #endif
  211242. /*** End of inlined file: juce_mac_CoreAudio.cpp ***/
  211243. /*** Start of inlined file: juce_mac_CoreMidi.cpp ***/
  211244. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  211245. // compiled on its own).
  211246. #if JUCE_INCLUDED_FILE
  211247. #if JUCE_MAC
  211248. #undef log
  211249. #define log(a) Logger::writeToLog(a)
  211250. static bool logAnyErrorsMidi (const OSStatus err, const int lineNum)
  211251. {
  211252. if (err == noErr)
  211253. return true;
  211254. log (T("CoreMidi error: ") + String (lineNum) + T(" - ") + String::toHexString ((int)err));
  211255. jassertfalse
  211256. return false;
  211257. }
  211258. #undef OK
  211259. #define OK(a) logAnyErrorsMidi(a, __LINE__)
  211260. static const String getEndpointName (MIDIEndpointRef endpoint, bool isExternal)
  211261. {
  211262. String result;
  211263. CFStringRef str = 0;
  211264. MIDIObjectGetStringProperty (endpoint, kMIDIPropertyName, &str);
  211265. if (str != 0)
  211266. {
  211267. result = PlatformUtilities::cfStringToJuceString (str);
  211268. CFRelease (str);
  211269. str = 0;
  211270. }
  211271. MIDIEntityRef entity = 0;
  211272. MIDIEndpointGetEntity (endpoint, &entity);
  211273. if (entity == 0)
  211274. return result; // probably virtual
  211275. if (result.isEmpty())
  211276. {
  211277. // endpoint name has zero length - try the entity
  211278. MIDIObjectGetStringProperty (entity, kMIDIPropertyName, &str);
  211279. if (str != 0)
  211280. {
  211281. result += PlatformUtilities::cfStringToJuceString (str);
  211282. CFRelease (str);
  211283. str = 0;
  211284. }
  211285. }
  211286. // now consider the device's name
  211287. MIDIDeviceRef device = 0;
  211288. MIDIEntityGetDevice (entity, &device);
  211289. if (device == 0)
  211290. return result;
  211291. MIDIObjectGetStringProperty (device, kMIDIPropertyName, &str);
  211292. if (str != 0)
  211293. {
  211294. const String s (PlatformUtilities::cfStringToJuceString (str));
  211295. CFRelease (str);
  211296. // if an external device has only one entity, throw away
  211297. // the endpoint name and just use the device name
  211298. if (isExternal && MIDIDeviceGetNumberOfEntities (device) < 2)
  211299. {
  211300. result = s;
  211301. }
  211302. else if (! result.startsWithIgnoreCase (s))
  211303. {
  211304. // prepend the device name to the entity name
  211305. result = (s + T(" ") + result).trimEnd();
  211306. }
  211307. }
  211308. return result;
  211309. }
  211310. static const String getConnectedEndpointName (MIDIEndpointRef endpoint)
  211311. {
  211312. String result;
  211313. // Does the endpoint have connections?
  211314. CFDataRef connections = 0;
  211315. int numConnections = 0;
  211316. MIDIObjectGetDataProperty (endpoint, kMIDIPropertyConnectionUniqueID, &connections);
  211317. if (connections != 0)
  211318. {
  211319. numConnections = (int) (CFDataGetLength (connections) / sizeof (MIDIUniqueID));
  211320. if (numConnections > 0)
  211321. {
  211322. const SInt32* pid = reinterpret_cast <const SInt32*> (CFDataGetBytePtr (connections));
  211323. for (int i = 0; i < numConnections; ++i, ++pid)
  211324. {
  211325. MIDIUniqueID uid = EndianS32_BtoN (*pid);
  211326. MIDIObjectRef connObject;
  211327. MIDIObjectType connObjectType;
  211328. OSStatus err = MIDIObjectFindByUniqueID (uid, &connObject, &connObjectType);
  211329. if (err == noErr)
  211330. {
  211331. String s;
  211332. if (connObjectType == kMIDIObjectType_ExternalSource
  211333. || connObjectType == kMIDIObjectType_ExternalDestination)
  211334. {
  211335. // Connected to an external device's endpoint (10.3 and later).
  211336. s = getEndpointName (static_cast <MIDIEndpointRef> (connObject), true);
  211337. }
  211338. else
  211339. {
  211340. // Connected to an external device (10.2) (or something else, catch-all)
  211341. CFStringRef str = 0;
  211342. MIDIObjectGetStringProperty (connObject, kMIDIPropertyName, &str);
  211343. if (str != 0)
  211344. {
  211345. s = PlatformUtilities::cfStringToJuceString (str);
  211346. CFRelease (str);
  211347. }
  211348. }
  211349. if (s.isNotEmpty())
  211350. {
  211351. if (result.isNotEmpty())
  211352. result += (", ");
  211353. result += s;
  211354. }
  211355. }
  211356. }
  211357. }
  211358. CFRelease (connections);
  211359. }
  211360. if (result.isNotEmpty())
  211361. return result;
  211362. // Here, either the endpoint had no connections, or we failed to obtain names for any of them.
  211363. return getEndpointName (endpoint, false);
  211364. }
  211365. const StringArray MidiOutput::getDevices()
  211366. {
  211367. StringArray s;
  211368. const ItemCount num = MIDIGetNumberOfDestinations();
  211369. for (ItemCount i = 0; i < num; ++i)
  211370. {
  211371. MIDIEndpointRef dest = MIDIGetDestination (i);
  211372. if (dest != 0)
  211373. {
  211374. String name (getConnectedEndpointName (dest));
  211375. if (name.isEmpty())
  211376. name = "<error>";
  211377. s.add (name);
  211378. }
  211379. else
  211380. {
  211381. s.add ("<error>");
  211382. }
  211383. }
  211384. return s;
  211385. }
  211386. int MidiOutput::getDefaultDeviceIndex()
  211387. {
  211388. return 0;
  211389. }
  211390. static MIDIClientRef globalMidiClient;
  211391. static bool hasGlobalClientBeenCreated = false;
  211392. static bool makeSureClientExists()
  211393. {
  211394. if (! hasGlobalClientBeenCreated)
  211395. {
  211396. String name (T("JUCE"));
  211397. if (JUCEApplication::getInstance() != 0)
  211398. name = JUCEApplication::getInstance()->getApplicationName();
  211399. CFStringRef appName = PlatformUtilities::juceStringToCFString (name);
  211400. hasGlobalClientBeenCreated = OK (MIDIClientCreate (appName, 0, 0, &globalMidiClient));
  211401. CFRelease (appName);
  211402. }
  211403. return hasGlobalClientBeenCreated;
  211404. }
  211405. class MidiPortAndEndpoint
  211406. {
  211407. public:
  211408. MidiPortAndEndpoint (MIDIPortRef port_, MIDIEndpointRef endPoint_)
  211409. : port (port_), endPoint (endPoint_)
  211410. {
  211411. }
  211412. ~MidiPortAndEndpoint()
  211413. {
  211414. if (port != 0)
  211415. MIDIPortDispose (port);
  211416. if (port == 0 && endPoint != 0) // if port == 0, it means we created the endpoint, so it's safe to delete it
  211417. MIDIEndpointDispose (endPoint);
  211418. }
  211419. MIDIPortRef port;
  211420. MIDIEndpointRef endPoint;
  211421. };
  211422. MidiOutput* MidiOutput::openDevice (int index)
  211423. {
  211424. MidiOutput* mo = 0;
  211425. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfDestinations())
  211426. {
  211427. MIDIEndpointRef endPoint = MIDIGetDestination (index);
  211428. CFStringRef pname;
  211429. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  211430. {
  211431. log (T("CoreMidi - opening out: ") + PlatformUtilities::cfStringToJuceString (pname));
  211432. if (makeSureClientExists())
  211433. {
  211434. MIDIPortRef port;
  211435. if (OK (MIDIOutputPortCreate (globalMidiClient, pname, &port)))
  211436. {
  211437. mo = new MidiOutput();
  211438. mo->internal = (void*) new MidiPortAndEndpoint (port, endPoint);
  211439. }
  211440. }
  211441. CFRelease (pname);
  211442. }
  211443. }
  211444. return mo;
  211445. }
  211446. MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
  211447. {
  211448. MidiOutput* mo = 0;
  211449. if (makeSureClientExists())
  211450. {
  211451. MIDIEndpointRef endPoint;
  211452. CFStringRef name = PlatformUtilities::juceStringToCFString (deviceName);
  211453. if (OK (MIDISourceCreate (globalMidiClient, name, &endPoint)))
  211454. {
  211455. mo = new MidiOutput();
  211456. mo->internal = (void*) new MidiPortAndEndpoint (0, endPoint);
  211457. }
  211458. CFRelease (name);
  211459. }
  211460. return mo;
  211461. }
  211462. MidiOutput::~MidiOutput()
  211463. {
  211464. delete (MidiPortAndEndpoint*) internal;
  211465. }
  211466. void MidiOutput::reset()
  211467. {
  211468. }
  211469. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  211470. {
  211471. return false;
  211472. }
  211473. void MidiOutput::setVolume (float leftVol, float rightVol)
  211474. {
  211475. }
  211476. void MidiOutput::sendMessageNow (const MidiMessage& message)
  211477. {
  211478. MidiPortAndEndpoint* const mpe = (MidiPortAndEndpoint*) internal;
  211479. if (message.isSysEx())
  211480. {
  211481. const int maxPacketSize = 256;
  211482. int pos = 0, bytesLeft = message.getRawDataSize();
  211483. const int numPackets = (bytesLeft + maxPacketSize - 1) / maxPacketSize;
  211484. HeapBlock <MIDIPacketList> packets;
  211485. packets.malloc (32 * numPackets + message.getRawDataSize(), 1);
  211486. packets->numPackets = numPackets;
  211487. MIDIPacket* p = packets->packet;
  211488. for (int i = 0; i < numPackets; ++i)
  211489. {
  211490. p->timeStamp = 0;
  211491. p->length = jmin (maxPacketSize, bytesLeft);
  211492. memcpy (p->data, message.getRawData() + pos, p->length);
  211493. pos += p->length;
  211494. bytesLeft -= p->length;
  211495. p = MIDIPacketNext (p);
  211496. }
  211497. if (mpe->port != 0)
  211498. MIDISend (mpe->port, mpe->endPoint, packets);
  211499. else
  211500. MIDIReceived (mpe->endPoint, packets);
  211501. }
  211502. else
  211503. {
  211504. MIDIPacketList packets;
  211505. packets.numPackets = 1;
  211506. packets.packet[0].timeStamp = 0;
  211507. packets.packet[0].length = message.getRawDataSize();
  211508. *(int*) (packets.packet[0].data) = *(const int*) message.getRawData();
  211509. if (mpe->port != 0)
  211510. MIDISend (mpe->port, mpe->endPoint, &packets);
  211511. else
  211512. MIDIReceived (mpe->endPoint, &packets);
  211513. }
  211514. }
  211515. const StringArray MidiInput::getDevices()
  211516. {
  211517. StringArray s;
  211518. const ItemCount num = MIDIGetNumberOfSources();
  211519. for (ItemCount i = 0; i < num; ++i)
  211520. {
  211521. MIDIEndpointRef source = MIDIGetSource (i);
  211522. if (source != 0)
  211523. {
  211524. String name (getConnectedEndpointName (source));
  211525. if (name.isEmpty())
  211526. name = "<error>";
  211527. s.add (name);
  211528. }
  211529. else
  211530. {
  211531. s.add ("<error>");
  211532. }
  211533. }
  211534. return s;
  211535. }
  211536. int MidiInput::getDefaultDeviceIndex()
  211537. {
  211538. return 0;
  211539. }
  211540. struct MidiPortAndCallback
  211541. {
  211542. MidiInput* input;
  211543. MidiPortAndEndpoint* portAndEndpoint;
  211544. MidiInputCallback* callback;
  211545. MemoryBlock pendingData;
  211546. int pendingBytes;
  211547. double pendingDataTime;
  211548. bool active;
  211549. };
  211550. static CriticalSection callbackLock;
  211551. static VoidArray activeCallbacks;
  211552. static void processSysex (MidiPortAndCallback* const mpc, const uint8*& d, int& size, const double time)
  211553. {
  211554. if (*d == 0xf0)
  211555. {
  211556. mpc->pendingBytes = 0;
  211557. mpc->pendingDataTime = time;
  211558. }
  211559. mpc->pendingData.ensureSize (mpc->pendingBytes + size, false);
  211560. uint8* totalMessage = (uint8*) mpc->pendingData.getData();
  211561. uint8* dest = totalMessage + mpc->pendingBytes;
  211562. while (size > 0)
  211563. {
  211564. if (mpc->pendingBytes > 0 && *d >= 0x80)
  211565. {
  211566. if (*d >= 0xfa || *d == 0xf8)
  211567. {
  211568. mpc->callback->handleIncomingMidiMessage (mpc->input, MidiMessage (*d, time));
  211569. ++d;
  211570. --size;
  211571. }
  211572. else
  211573. {
  211574. if (*d == 0xf7)
  211575. {
  211576. *dest++ = *d++;
  211577. mpc->pendingBytes++;
  211578. --size;
  211579. }
  211580. break;
  211581. }
  211582. }
  211583. else
  211584. {
  211585. *dest++ = *d++;
  211586. mpc->pendingBytes++;
  211587. --size;
  211588. }
  211589. }
  211590. if (totalMessage [mpc->pendingBytes - 1] == 0xf7)
  211591. {
  211592. mpc->callback->handleIncomingMidiMessage (mpc->input, MidiMessage (totalMessage,
  211593. mpc->pendingBytes,
  211594. mpc->pendingDataTime));
  211595. mpc->pendingBytes = 0;
  211596. }
  211597. else
  211598. {
  211599. mpc->callback->handlePartialSysexMessage (mpc->input,
  211600. totalMessage,
  211601. mpc->pendingBytes,
  211602. mpc->pendingDataTime);
  211603. }
  211604. }
  211605. static void midiInputProc (const MIDIPacketList* pktlist,
  211606. void* readProcRefCon,
  211607. void* srcConnRefCon)
  211608. {
  211609. double time = Time::getMillisecondCounterHiRes() * 0.001;
  211610. const double originalTime = time;
  211611. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) readProcRefCon;
  211612. const ScopedLock sl (callbackLock);
  211613. if (activeCallbacks.contains (mpc) && mpc->active)
  211614. {
  211615. const MIDIPacket* packet = &pktlist->packet[0];
  211616. for (unsigned int i = 0; i < pktlist->numPackets; ++i)
  211617. {
  211618. const uint8* d = (const uint8*) (packet->data);
  211619. int size = packet->length;
  211620. while (size > 0)
  211621. {
  211622. time = originalTime;
  211623. if (mpc->pendingBytes > 0 || d[0] == 0xf0)
  211624. {
  211625. processSysex (mpc, d, size, time);
  211626. }
  211627. else
  211628. {
  211629. int used = 0;
  211630. const MidiMessage m (d, size, used, 0, time);
  211631. if (used <= 0)
  211632. {
  211633. jassertfalse // malformed midi message
  211634. break;
  211635. }
  211636. else
  211637. {
  211638. mpc->callback->handleIncomingMidiMessage (mpc->input, m);
  211639. }
  211640. size -= used;
  211641. d += used;
  211642. }
  211643. }
  211644. packet = MIDIPacketNext (packet);
  211645. }
  211646. }
  211647. }
  211648. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  211649. {
  211650. MidiInput* mi = 0;
  211651. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfSources())
  211652. {
  211653. MIDIEndpointRef endPoint = MIDIGetSource (index);
  211654. if (endPoint != 0)
  211655. {
  211656. CFStringRef pname;
  211657. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  211658. {
  211659. log (T("CoreMidi - opening inp: ") + PlatformUtilities::cfStringToJuceString (pname));
  211660. if (makeSureClientExists())
  211661. {
  211662. MIDIPortRef port;
  211663. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  211664. mpc->active = false;
  211665. if (OK (MIDIInputPortCreate (globalMidiClient, pname, midiInputProc, mpc, &port)))
  211666. {
  211667. if (OK (MIDIPortConnectSource (port, endPoint, 0)))
  211668. {
  211669. mpc->portAndEndpoint = new MidiPortAndEndpoint (port, endPoint);
  211670. mpc->callback = callback;
  211671. mpc->pendingBytes = 0;
  211672. mpc->pendingData.ensureSize (128);
  211673. mi = new MidiInput (getDevices() [index]);
  211674. mpc->input = mi;
  211675. mi->internal = (void*) mpc;
  211676. const ScopedLock sl (callbackLock);
  211677. activeCallbacks.add (mpc.release());
  211678. }
  211679. else
  211680. {
  211681. OK (MIDIPortDispose (port));
  211682. }
  211683. }
  211684. }
  211685. }
  211686. CFRelease (pname);
  211687. }
  211688. }
  211689. return mi;
  211690. }
  211691. MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
  211692. {
  211693. MidiInput* mi = 0;
  211694. if (makeSureClientExists())
  211695. {
  211696. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  211697. mpc->active = false;
  211698. MIDIEndpointRef endPoint;
  211699. CFStringRef name = PlatformUtilities::juceStringToCFString(deviceName);
  211700. if (OK (MIDIDestinationCreate (globalMidiClient, name, midiInputProc, mpc, &endPoint)))
  211701. {
  211702. mpc->portAndEndpoint = new MidiPortAndEndpoint (0, endPoint);
  211703. mpc->callback = callback;
  211704. mpc->pendingBytes = 0;
  211705. mpc->pendingData.ensureSize (128);
  211706. mi = new MidiInput (deviceName);
  211707. mpc->input = mi;
  211708. mi->internal = (void*) mpc;
  211709. const ScopedLock sl (callbackLock);
  211710. activeCallbacks.add (mpc.release());
  211711. }
  211712. CFRelease (name);
  211713. }
  211714. return mi;
  211715. }
  211716. MidiInput::MidiInput (const String& name_)
  211717. : name (name_)
  211718. {
  211719. }
  211720. MidiInput::~MidiInput()
  211721. {
  211722. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  211723. mpc->active = false;
  211724. callbackLock.enter();
  211725. activeCallbacks.removeValue (mpc);
  211726. callbackLock.exit();
  211727. if (mpc->portAndEndpoint->port != 0)
  211728. OK (MIDIPortDisconnectSource (mpc->portAndEndpoint->port, mpc->portAndEndpoint->endPoint));
  211729. delete mpc->portAndEndpoint;
  211730. delete mpc;
  211731. }
  211732. void MidiInput::start()
  211733. {
  211734. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  211735. const ScopedLock sl (callbackLock);
  211736. mpc->active = true;
  211737. }
  211738. void MidiInput::stop()
  211739. {
  211740. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  211741. const ScopedLock sl (callbackLock);
  211742. mpc->active = false;
  211743. }
  211744. #undef log
  211745. #else
  211746. MidiOutput::~MidiOutput()
  211747. {
  211748. }
  211749. void MidiOutput::reset()
  211750. {
  211751. }
  211752. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  211753. {
  211754. return false;
  211755. }
  211756. void MidiOutput::setVolume (float leftVol, float rightVol)
  211757. {
  211758. }
  211759. void MidiOutput::sendMessageNow (const MidiMessage& message)
  211760. {
  211761. }
  211762. const StringArray MidiOutput::getDevices()
  211763. {
  211764. return StringArray();
  211765. }
  211766. MidiOutput* MidiOutput::openDevice (int index)
  211767. {
  211768. return 0;
  211769. }
  211770. const StringArray MidiInput::getDevices()
  211771. {
  211772. return StringArray();
  211773. }
  211774. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  211775. {
  211776. return 0;
  211777. }
  211778. #endif
  211779. #endif
  211780. /*** End of inlined file: juce_mac_CoreMidi.cpp ***/
  211781. /*** Start of inlined file: juce_mac_CameraDevice.mm ***/
  211782. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  211783. // compiled on its own).
  211784. #if JUCE_INCLUDED_FILE && JUCE_QUICKTIME && JUCE_USE_CAMERA
  211785. #define QTCaptureCallbackDelegate MakeObjCClassName(QTCaptureCallbackDelegate)
  211786. class QTCameraDeviceInteral;
  211787. END_JUCE_NAMESPACE
  211788. @interface QTCaptureCallbackDelegate : NSObject
  211789. {
  211790. @public
  211791. CameraDevice* owner;
  211792. QTCameraDeviceInteral* internal;
  211793. Time* firstRecordedTime;
  211794. }
  211795. - (QTCaptureCallbackDelegate*) initWithOwner: (CameraDevice*) owner internalDev: (QTCameraDeviceInteral*) d;
  211796. - (void) dealloc;
  211797. - (void) captureOutput: (QTCaptureOutput*) captureOutput
  211798. didOutputVideoFrame: (CVImageBufferRef) videoFrame
  211799. withSampleBuffer: (QTSampleBuffer*) sampleBuffer
  211800. fromConnection: (QTCaptureConnection*) connection;
  211801. - (void) captureOutput: (QTCaptureFileOutput*) captureOutput
  211802. didOutputSampleBuffer: (QTSampleBuffer*) sampleBuffer
  211803. fromConnection: (QTCaptureConnection*) connection;
  211804. @end
  211805. BEGIN_JUCE_NAMESPACE
  211806. class QTCameraDeviceInteral
  211807. {
  211808. public:
  211809. QTCameraDeviceInteral (CameraDevice* owner, int index)
  211810. {
  211811. const ScopedAutoReleasePool pool;
  211812. session = [[QTCaptureSession alloc] init];
  211813. NSArray* devs = [QTCaptureDevice inputDevicesWithMediaType: QTMediaTypeVideo];
  211814. device = (QTCaptureDevice*) [devs objectAtIndex: index];
  211815. input = 0;
  211816. audioInput = 0;
  211817. audioDevice = 0;
  211818. fileOutput = 0;
  211819. imageOutput = 0;
  211820. callbackDelegate = [[QTCaptureCallbackDelegate alloc] initWithOwner: owner
  211821. internalDev: this];
  211822. NSError* err = 0;
  211823. [device retain];
  211824. [device open: &err];
  211825. if (err == 0)
  211826. {
  211827. input = [[QTCaptureDeviceInput alloc] initWithDevice: device];
  211828. audioInput = [[QTCaptureDeviceInput alloc] initWithDevice: device];
  211829. [session addInput: input error: &err];
  211830. if (err == 0)
  211831. {
  211832. resetFile();
  211833. imageOutput = [[QTCaptureDecompressedVideoOutput alloc] init];
  211834. [imageOutput setDelegate: callbackDelegate];
  211835. if (err == 0)
  211836. {
  211837. [session startRunning];
  211838. return;
  211839. }
  211840. }
  211841. }
  211842. openingError = nsStringToJuce ([err description]);
  211843. DBG (openingError);
  211844. }
  211845. ~QTCameraDeviceInteral()
  211846. {
  211847. [session stopRunning];
  211848. [session removeOutput: imageOutput];
  211849. [session release];
  211850. [input release];
  211851. [device release];
  211852. [audioDevice release];
  211853. [audioInput release];
  211854. [fileOutput release];
  211855. [imageOutput release];
  211856. [callbackDelegate release];
  211857. }
  211858. void resetFile()
  211859. {
  211860. [fileOutput recordToOutputFileURL: nil];
  211861. [session removeOutput: fileOutput];
  211862. [fileOutput release];
  211863. fileOutput = [[QTCaptureMovieFileOutput alloc] init];
  211864. [session removeInput: audioInput];
  211865. [audioInput release];
  211866. audioInput = 0;
  211867. [audioDevice release];
  211868. audioDevice = 0;
  211869. [fileOutput setDelegate: callbackDelegate];
  211870. }
  211871. void addDefaultAudioInput()
  211872. {
  211873. NSError* err = nil;
  211874. audioDevice = [QTCaptureDevice defaultInputDeviceWithMediaType: QTMediaTypeSound];
  211875. if ([audioDevice open: &err])
  211876. [audioDevice retain];
  211877. else
  211878. audioDevice = nil;
  211879. if (audioDevice != 0)
  211880. {
  211881. audioInput = [[QTCaptureDeviceInput alloc] initWithDevice: audioDevice];
  211882. [session addInput: audioInput error: &err];
  211883. }
  211884. }
  211885. void addListener (CameraImageListener* listenerToAdd)
  211886. {
  211887. const ScopedLock sl (listenerLock);
  211888. if (listeners.size() == 0)
  211889. [session addOutput: imageOutput error: nil];
  211890. listeners.addIfNotAlreadyThere (listenerToAdd);
  211891. }
  211892. void removeListener (CameraImageListener* listenerToRemove)
  211893. {
  211894. const ScopedLock sl (listenerLock);
  211895. listeners.removeValue (listenerToRemove);
  211896. if (listeners.size() == 0)
  211897. [session removeOutput: imageOutput];
  211898. }
  211899. void callListeners (CIImage* frame, int w, int h)
  211900. {
  211901. CoreGraphicsImage image (Image::ARGB, w, h, false);
  211902. CIContext* cic = [CIContext contextWithCGContext: image.context options: nil];
  211903. [cic drawImage: frame inRect: CGRectMake (0, 0, w, h) fromRect: CGRectMake (0, 0, w, h)];
  211904. CGContextFlush (image.context);
  211905. const ScopedLock sl (listenerLock);
  211906. for (int i = listeners.size(); --i >= 0;)
  211907. {
  211908. CameraImageListener* l = (CameraImageListener*) listeners[i];
  211909. if (l != 0)
  211910. l->imageReceived (image);
  211911. }
  211912. }
  211913. QTCaptureDevice* device;
  211914. QTCaptureDeviceInput* input;
  211915. QTCaptureDevice* audioDevice;
  211916. QTCaptureDeviceInput* audioInput;
  211917. QTCaptureSession* session;
  211918. QTCaptureMovieFileOutput* fileOutput;
  211919. QTCaptureDecompressedVideoOutput* imageOutput;
  211920. QTCaptureCallbackDelegate* callbackDelegate;
  211921. String openingError;
  211922. VoidArray listeners;
  211923. CriticalSection listenerLock;
  211924. };
  211925. END_JUCE_NAMESPACE
  211926. @implementation QTCaptureCallbackDelegate
  211927. - (QTCaptureCallbackDelegate*) initWithOwner: (CameraDevice*) owner_
  211928. internalDev: (QTCameraDeviceInteral*) d
  211929. {
  211930. [super init];
  211931. owner = owner_;
  211932. internal = d;
  211933. firstRecordedTime = 0;
  211934. return self;
  211935. }
  211936. - (void) dealloc
  211937. {
  211938. delete firstRecordedTime;
  211939. [super dealloc];
  211940. }
  211941. - (void) captureOutput: (QTCaptureOutput*) captureOutput
  211942. didOutputVideoFrame: (CVImageBufferRef) videoFrame
  211943. withSampleBuffer: (QTSampleBuffer*) sampleBuffer
  211944. fromConnection: (QTCaptureConnection*) connection
  211945. {
  211946. if (internal->listeners.size() > 0)
  211947. {
  211948. const ScopedAutoReleasePool pool;
  211949. internal->callListeners ([CIImage imageWithCVImageBuffer: videoFrame],
  211950. CVPixelBufferGetWidth (videoFrame),
  211951. CVPixelBufferGetHeight (videoFrame));
  211952. }
  211953. }
  211954. - (void) captureOutput: (QTCaptureFileOutput*) captureOutput
  211955. didOutputSampleBuffer: (QTSampleBuffer*) sampleBuffer
  211956. fromConnection: (QTCaptureConnection*) connection
  211957. {
  211958. if (firstRecordedTime == 0)
  211959. {
  211960. const Time now (Time::getCurrentTime());
  211961. firstRecordedTime = new Time (now - RelativeTime (0.1));
  211962. }
  211963. }
  211964. @end
  211965. BEGIN_JUCE_NAMESPACE
  211966. class QTCaptureViewerComp : public NSViewComponent
  211967. {
  211968. public:
  211969. QTCaptureViewerComp (CameraDevice* const cameraDevice, QTCameraDeviceInteral* const internal)
  211970. {
  211971. const ScopedAutoReleasePool pool;
  211972. captureView = [[QTCaptureView alloc] init];
  211973. [captureView setCaptureSession: internal->session];
  211974. setSize (640, 480); // xxx need to somehow get the movie size - how?
  211975. setView (captureView);
  211976. }
  211977. ~QTCaptureViewerComp()
  211978. {
  211979. setView (0);
  211980. [captureView setCaptureSession: nil];
  211981. [captureView release];
  211982. }
  211983. QTCaptureView* captureView;
  211984. };
  211985. CameraDevice::CameraDevice (const String& name_, int index)
  211986. : name (name_)
  211987. {
  211988. isRecording = false;
  211989. QTCameraDeviceInteral* d = new QTCameraDeviceInteral (this, index);
  211990. internal = d;
  211991. }
  211992. CameraDevice::~CameraDevice()
  211993. {
  211994. stopRecording();
  211995. delete (QTCameraDeviceInteral*) internal;
  211996. internal = 0;
  211997. }
  211998. Component* CameraDevice::createViewerComponent()
  211999. {
  212000. return new QTCaptureViewerComp (this, (QTCameraDeviceInteral*) internal);
  212001. }
  212002. const String CameraDevice::getFileExtension()
  212003. {
  212004. return ".mov";
  212005. }
  212006. void CameraDevice::startRecordingToFile (const File& file)
  212007. {
  212008. stopRecording();
  212009. QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal;
  212010. deleteAndZero (d->callbackDelegate->firstRecordedTime);
  212011. file.deleteFile();
  212012. // In some versions of QT (e.g. on 10.5), if you record video without audio, the speed comes
  212013. // out wrong, so we'll put some audio in there too..,
  212014. d->addDefaultAudioInput();
  212015. [d->session addOutput: d->fileOutput error: nil];
  212016. NSEnumerator* connectionEnumerator = [[d->fileOutput connections] objectEnumerator];
  212017. for (;;)
  212018. {
  212019. QTCaptureConnection* connection = [connectionEnumerator nextObject];
  212020. if (connection == 0)
  212021. break;
  212022. QTCompressionOptions* options = 0;
  212023. NSString* mediaType = [connection mediaType];
  212024. if ([mediaType isEqualToString: QTMediaTypeVideo])
  212025. options = [QTCompressionOptions compressionOptionsWithIdentifier: @"QTCompressionOptionsSD480SizeH264Video"];
  212026. else if ([mediaType isEqualToString: QTMediaTypeSound])
  212027. options = [QTCompressionOptions compressionOptionsWithIdentifier: @"QTCompressionOptionsHighQualityAACAudio"];
  212028. [d->fileOutput setCompressionOptions: options forConnection: connection];
  212029. }
  212030. [d->fileOutput recordToOutputFileURL: [NSURL fileURLWithPath: juceStringToNS (file.getFullPathName())]];
  212031. isRecording = true;
  212032. }
  212033. const Time CameraDevice::getTimeOfFirstRecordedFrame() const
  212034. {
  212035. QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal;
  212036. if (d->callbackDelegate->firstRecordedTime != 0)
  212037. return *d->callbackDelegate->firstRecordedTime;
  212038. return Time();
  212039. }
  212040. void CameraDevice::stopRecording()
  212041. {
  212042. if (isRecording)
  212043. {
  212044. QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal;
  212045. d->resetFile();
  212046. isRecording = false;
  212047. }
  212048. }
  212049. void CameraDevice::addListener (CameraImageListener* listenerToAdd)
  212050. {
  212051. QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal;
  212052. if (listenerToAdd != 0)
  212053. d->addListener (listenerToAdd);
  212054. }
  212055. void CameraDevice::removeListener (CameraImageListener* listenerToRemove)
  212056. {
  212057. QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal;
  212058. if (listenerToRemove != 0)
  212059. d->removeListener (listenerToRemove);
  212060. }
  212061. const StringArray CameraDevice::getAvailableDevices()
  212062. {
  212063. const ScopedAutoReleasePool pool;
  212064. StringArray results;
  212065. NSArray* devs = [QTCaptureDevice inputDevicesWithMediaType: QTMediaTypeVideo];
  212066. for (int i = 0; i < (int) [devs count]; ++i)
  212067. {
  212068. QTCaptureDevice* dev = (QTCaptureDevice*) [devs objectAtIndex: i];
  212069. results.add (nsStringToJuce ([dev localizedDisplayName]));
  212070. }
  212071. return results;
  212072. }
  212073. CameraDevice* CameraDevice::openDevice (int index,
  212074. int minWidth, int minHeight,
  212075. int maxWidth, int maxHeight)
  212076. {
  212077. ScopedPointer <CameraDevice> d (new CameraDevice (getAvailableDevices() [index], index));
  212078. if (((QTCameraDeviceInteral*) (d->internal))->openingError.isEmpty())
  212079. return d.release();
  212080. return 0;
  212081. }
  212082. #endif
  212083. /*** End of inlined file: juce_mac_CameraDevice.mm ***/
  212084. #endif
  212085. #endif
  212086. END_JUCE_NAMESPACE
  212087. /*** End of inlined file: juce_mac_NativeCode.mm ***/
  212088. #endif
  212089. #endif